How to resolve the algorithm Sleeping Beauty problem step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sleeping Beauty problem step by step in the CLU programming language

Table of Contents

Problem Statement

In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows:
Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin toss. If this coin toss comes up heads, Sleeping Beauty wakes once (on Monday) and is asked to estimate the probability that the coin toss was heads. Her estimate is recorded and she is then put back to sleep for 2 days until Wednesday, at which time the experiment's results are tallied.

If instead the coin toss is tails, Sleeping Beauty wakes as before on Monday and asked to estimate the probability the coin toss was heads, but is then given a drug which makes her forget that she had been woken on Monday before being put back to sleep again. She then wakes only 1 day later, on Tuesday. She is then asked (on Tuesday) again to guess the probability that the coin toss was heads or tails. She is then put back to sleep and awakes as before 1 day later, on Wednesday.

Some decision makers have argued that since the coin toss was fair Sleeping Beauty should always estimate the probability of heads as 1/2, since she does not have any additional information. Others have disagreed, saying that if Sleeping Beauty knows the study design she also knows that she is twice as likely to wake up and be asked to estimate the coin flip on tails than on heads, so the estimate should be 1/3 heads. Given the above problem, create a Monte Carlo estimate of the actual results. The program should find the proportion of heads on waking and asking Sleeping Beauty for an estimate, as a credence or as a percentage of the times Sleeping Beauty is asked the question.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sleeping Beauty problem step by step in the CLU programming language

Source code in the clu programming language

% This program needs to be merged with PCLU's "misc" library
% to use the random number generator.

experiment = cluster is run
    rep = null
    
    own awake: int := 0
    own awake_heads: int := 0
    
    % Returns true if heads, false if tails
    coin_toss = proc () returns (bool) 
        return(random$next(2)=1)
    end coin_toss

    % Do the experiment once
    do_experiment = proc ()
        heads: bool := coin_toss()
        
        % monday - wake up
        awake := awake + 1
        if heads then
            awake_heads := awake_heads + 1
            return
        end 
        
        % tuesday - wake up if tails
        awake := awake + 1
    end do_experiment
    
    % Run the experiment N times
    run = proc (n: int) returns (real) 
        awake := 0
        awake_heads := 0
        
        for i: int in int$from_to(1,n) do
            do_experiment()
        end
        
        return(real$i2r(awake_heads) / real$i2r(awake))
    end run
end experiment

start_up = proc () 
    N = 1000000
    
    po: stream := stream$primary_output()
    stream$puts(po, "Chance of waking up with heads: ")
    
    chance: real := experiment$run(N)
    stream$putl(po, f_form(chance, 1, 6))
end start_up

  

You may also check:How to resolve the algorithm Cantor set step by step in the BASIC programming language
You may also check:How to resolve the algorithm Trigonometric functions step by step in the Raku programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the IWBASIC programming language
You may also check:How to resolve the algorithm Recaman's sequence step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Accumulator factory step by step in the Octave programming language