/* Cond exponential in Picat. From PSI test/condExponential.psi """ https://www.quora.com/If-X-and-Y-are-independent-exponential-random-variables-with-parameter-1-What-is-E-X+Y-2-X- 1-Y-1 """ $ psi --expectation condExponential.psi E(r_) = 18 Mathematica: """ Expectation((x + y)^2 | x > 1 && y > 1, (x ~ ExponentialDistribution(1), y ~ ExponentialDistribution(1))) -> 18 """ Cf my Gamble model gamble_cond_exponential.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. import util. % import ordset. main => go. /* var : x Probabilities (truncated): 10.458674778932023: 0.0000732869182851 9.741258141887297: 0.0000732869182851 9.331421016111529: 0.0000732869182851 9.218613748610844: 0.0000732869182851 ......... 1.000248735022779: 0.0000732869182851 1.000240738281864: 0.0000732869182851 1.000230484163171: 0.0000732869182851 1.00008038395312: 0.0000732869182851 mean = 1.99013 Percentiles: (0.001 1.0011430298309627) (0.01 1.0115147165239149) (0.025 1.0261410797202217) (0.05 1.0537522199211702) (0.1 1.1087811182724303) (0.25 1.2875960828329089) (0.5 1.6830550336993473) (0.75 2.3627690056699646) (0.84 2.8066994186532175) (0.9 3.2999533871859019) (0.95 3.9828527379093508) (0.975 4.6760468619803115) (0.99 5.6542213797328529) (0.999 7.8589254291574147) (0.9999 9.5919134932544488) (0.99999 10.360790452973482) HPD intervals: HPD interval (0.94): 1.00023048416317..3.79280909703750 Histogram (total 13645) 1.000: 1489 ################################## (0.109 / 0.109) 1.237: 2623 ############################################################ (0.192 / 0.301) 1.473: 2053 ############################################### (0.150 / 0.452) 1.709: 1653 ###################################### (0.121 / 0.573) 1.946: 1236 ############################ (0.091 / 0.664) 2.182: 971 ###################### (0.071 / 0.735) 2.419: 763 ################# (0.056 / 0.791) 2.655: 601 ############## (0.044 / 0.835) 2.892: 453 ########## (0.033 / 0.868) 3.128: 357 ######## (0.026 / 0.894) 3.365: 326 ####### (0.024 / 0.918) 3.601: 237 ##### (0.017 / 0.935) 3.838: 184 #### (0.013 / 0.949) 4.074: 149 ### (0.011 / 0.960) 4.311: 119 ### (0.009 / 0.968) 4.547: 85 ## (0.006 / 0.975) 4.784: 70 ## (0.005 / 0.980) 5.020: 64 # (0.005 / 0.984) 5.256: 37 # (0.003 / 0.987) 5.493: 29 # (0.002 / 0.989) 5.729: 30 # (0.002 / 0.991) 5.966: 20 (0.001 / 0.993) 6.202: 18 (0.001 / 0.994) 6.439: 17 (0.001 / 0.996) 6.675: 13 (0.001 / 0.996) 6.912: 10 (0.001 / 0.997) 7.148: 16 (0.001 / 0.998) 7.385: 2 (0.000 / 0.999) 7.621: 3 (0.000 / 0.999) 7.858: 4 (0.000 / 0.999) 8.094: 2 (0.000 / 0.999) 8.330: 1 (0.000 / 0.999) 8.567: 1 (0.000 / 0.999) 8.803: 2 (0.000 / 0.999) 9.040: 3 (0.000 / 1.000) 9.276: 2 (0.000 / 1.000) 9.513: 0 (0.000 / 1.000) 9.749: 1 (0.000 / 1.000) 9.986: 0 (0.000 / 1.000) 10.222: 1 (0.000 / 1.000) var : y Probabilities (truncated): 12.235696478087963: 0.0000732869182851 10.852813531687913: 0.0000732869182851 9.850951550613418: 0.0000732869182851 9.656889104299482: 0.0000732869182851 ......... 1.000298852849474: 0.0000732869182851 1.000216476237139: 0.0000732869182851 1.000208734232785: 0.0000732869182851 1.000174576440229: 0.0000732869182851 mean = 1.99944 Percentiles: (0.001 1.001170034111404) (0.01 1.0099553947827891) (0.025 1.0240061448070423) (0.05 1.0485770067355893) (0.1 1.1016981976280136) (0.25 1.2803267965381455) (0.5 1.6850034829724552) (0.75 2.3835749343413033) (0.84 2.8269187838533312) (0.9 3.3290296511786561) (0.95 4.026129530068677) (0.975 4.7448081684554335) (0.99 5.6376282938885085) (0.999 8.0796212990391449) (0.9999 10.487735025783978) (0.99999 12.047015928880835) HPD intervals: HPD interval (0.94): 1.00017457644023..3.81589459637343 Histogram (total 13645) 1.000: 1797 #################################### (0.132 / 0.132) 1.281: 2991 ############################################################ (0.219 / 0.351) 1.562: 2139 ########################################### (0.157 / 0.508) 1.843: 1665 ################################# (0.122 / 0.630) 2.124: 1196 ######################## (0.088 / 0.717) 2.405: 938 ################### (0.069 / 0.786) 2.686: 734 ############### (0.054 / 0.840) 2.966: 503 ########## (0.037 / 0.877) 3.247: 393 ######## (0.029 / 0.906) 3.528: 319 ###### (0.023 / 0.929) 3.809: 247 ##### (0.018 / 0.947) 4.090: 168 ### (0.012 / 0.959) 4.371: 130 ### (0.010 / 0.969) 4.652: 99 ## (0.007 / 0.976) 4.933: 70 # (0.005 / 0.981) 5.213: 68 # (0.005 / 0.986) 5.494: 50 # (0.004 / 0.990) 5.775: 27 # (0.002 / 0.992) 6.056: 27 # (0.002 / 0.994) 6.337: 17 (0.001 / 0.995) 6.618: 19 (0.001 / 0.996) 6.899: 13 (0.001 / 0.997) 7.180: 8 (0.001 / 0.998) 7.461: 6 (0.000 / 0.998) 7.741: 5 (0.000 / 0.999) 8.022: 3 (0.000 / 0.999) 8.303: 2 (0.000 / 0.999) 8.584: 4 (0.000 / 0.999) 8.865: 2 (0.000 / 1.000) 9.146: 1 (0.000 / 1.000) 9.427: 0 (0.000 / 1.000) 9.708: 1 (0.000 / 1.000) 9.989: 1 (0.000 / 1.000) 10.269: 0 (0.000 / 1.000) 10.550: 0 (0.000 / 1.000) 10.831: 1 (0.000 / 1.000) 11.112: 0 (0.000 / 1.000) 11.393: 0 (0.000 / 1.000) 11.674: 0 (0.000 / 1.000) 11.955: 1 (0.000 / 1.000) var : e Probabilities (truncated): 313.833887091627105: 0.0000732869182851 156.784154036652268: 0.0000732869182851 150.784958377668886: 0.0000732869182851 148.299412292468958: 0.0000732869182851 ......... 4.094869176375066: 0.0000732869182851 4.092644792364408: 0.0000732869182851 4.081501246029122: 0.0000732869182851 4.070100897756674: 0.0000732869182851 mean = 17.9489 Percentiles: (0.001 4.1788574022693892) (0.01 4.6313235528700059) (0.025 5.0431770456038603) (0.05 5.5211325933440074) (0.1 6.3768104048027983) (0.25 8.6641353860461088) (0.5 13.395601039715507) (0.75 21.759632488453537) (0.84 27.6571755179455) (0.9 34.828090008607333) (0.95 45.60638099956882) (0.975 58.208508799752884) (0.99 76.127418894332763) (0.999 125.49739836923098) (0.9999 154.59804713851639) (0.99999 292.40602151357166) HPD intervals: HPD interval (0.94): 4.07010089775667..42.83379513779088 Histogram (total 13645) 4.070: 2785 ################################ (0.204 / 0.204) 11.814: 5251 ############################################################ (0.385 / 0.589) 19.558: 2635 ############################## (0.193 / 0.782) 27.302: 1257 ############## (0.092 / 0.874) 35.046: 657 ######## (0.048 / 0.922) 42.791: 420 ##### (0.031 / 0.953) 50.535: 234 ### (0.017 / 0.970) 58.279: 114 # (0.008 / 0.979) 66.023: 102 # (0.007 / 0.986) 73.767: 57 # (0.004 / 0.990) 81.511: 41 (0.003 / 0.993) 89.255: 25 (0.002 / 0.995) 96.999: 22 (0.002 / 0.997) 104.743: 16 (0.001 / 0.998) 112.487: 9 (0.001 / 0.999) 120.232: 4 (0.000 / 0.999) 127.976: 6 (0.000 / 0.999) 135.720: 4 (0.000 / 1.000) 143.464: 2 (0.000 / 1.000) 151.208: 2 (0.000 / 1.000) 158.952: 1 (0.000 / 1.000) 166.696: 0 (0.000 / 1.000) 174.440: 0 (0.000 / 1.000) 182.184: 0 (0.000 / 1.000) 189.928: 0 (0.000 / 1.000) 197.672: 0 (0.000 / 1.000) 205.417: 0 (0.000 / 1.000) 213.161: 0 (0.000 / 1.000) 220.905: 0 (0.000 / 1.000) 228.649: 0 (0.000 / 1.000) 236.393: 0 (0.000 / 1.000) 244.137: 0 (0.000 / 1.000) 251.881: 0 (0.000 / 1.000) 259.625: 0 (0.000 / 1.000) 267.369: 0 (0.000 / 1.000) 275.113: 0 (0.000 / 1.000) 282.858: 0 (0.000 / 1.000) 290.602: 0 (0.000 / 1.000) 298.346: 0 (0.000 / 1.000) 306.090: 1 (0.000 / 1.000) */ go ?=> reset_store, run_model(100_000,$model,[show_probs_trunc,mean,show_percentiles, show_hpd_intervals,hpd_intervals=[0.94], show_histogram]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => X = exponential_dist(1), Y = exponential_dist(1), observe((X > 1, Y > 1)), E = (X+Y)**2, if observed_ok then add("x",X), add("y",Y), add("e",E), end.