Example 2: CPD and conditional expectation of random variable 'Count'
"This program ... counts the number of coin tosses that result in the value true, and stores this count in the variable count. The semantics of the program is the expected return value, conditioned by permitted executions. Once again, since conditioning by permitted executions yields Pr(c1=false, c2=false) = 0, and Pr(c1=false, c2=true) = Pr(c1=true, c2=false) = Pr(c1=true, c2=true) = 1/3, we have that the expected return value is 0 x0 + 1/3*1 + 1/3*1 + 1/3*2 = 4/3." (Gordon et al., 2014)
CHURCH-Code for P(Count | C1=1 v C2=1) and E(Count | C1=1 v C2=1) = 4/3
The PROB-code snippet from Gordon et al. is translated by us to a functional CHURCH program to clarify its semantics. The generative model is contained in the CHURCH function "take-a-sample". The number of samples taken was set to 10000 in this run. This number can be increased to get a better precision of estimates. The sampling method used is the simple-to-understand 'rejection sampling'. The screen-shot presented was generated by using the PlaySpace environment of WebCHURCH.