Example 1a: Two Fair Coins
"The program in Example 1(a), tosses two fair coins (simulated by draws from a Bernoulli distribution with mean 0.5), and assigns the outcomes of these coin tosses to the Boolean variables c1 and c2 respectively, and returns (c1 , c2). The semantics of this program is the expectation of its return value. In this case, this is equal to (1/2, 1/2). Since we have that Pr(c1 = false, c2 = false) = Pr(c1 = false, c2 = true) = Pr(c1 = true, c2 = false) = Pr(c1 = true, c2 = true) = 1/4, we have that the expectation on the return value is given by 1/4x(0, 0) + 1/4x(0, 1) + 1/4x(1, 0) + 1/4x(1, 1) = (1/2, 1/2) (by treating true as 1 and false as 0)." (Gordon et al., ICSE-FoSE 2014, p.2)
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 1000 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.