cplint on SWISH is a web application for probabilistic logic programming  About  Help  LIFTCOVER-Help  PHIL-Help  PASCAL-Help  Credits  Dismiss

Latest: Threads and Python in LIFTCOVER, course, PHIL examples, book

  
    ? users online
  • Logout
    • Open hangout
    • Open chat for current file
<div class="notebook">

<div class="nb-cell html">
<h2>
Monty Hall Puzzle
</h2>
<p>From [1]:</p>
<blockquote cite="http://www.public.asu.edu/~cbaral/papers/plogJune20-08.pdf" style="font-size: inherit;"><p>
</p><p>the Monty Hall puzzle ... gets its name from the TV game
show hosted by Monty Hall... A player is given the opportunity to
select one of three closed doors, behind one of which there is a prize.
Behind the other two doors are empty rooms.
Once the player has made a selection, Monty is obligated to open one of the
remaining closed doors which does not contain the prize, showing that the room
behind it is empty. He then asks the player if he would like to switch
his selection to the other unopened door, or stay with his original choice.
Here is the problem: Does it matter if he switches?</p>
</blockquote>
<h3>Code</h3>
<p>
We use the predicates:
</p><ul>
<li> <code>prize(A)</code>: the prize is behind door <code>A</code>,
with <code>A</code> in {1,2,3}
</li>
<li> <code>open_door(A)</code>: Monty opens door <code>A</code>
</li>
<li>
<code>win_keep</code>: the player wins in case he keeps his selection
</li>
<li> <code>win_switch</code>: the player wins in case he switches door
</li>
</ul>
<p></p>
<p>We assume that the player selected door 1. For a more general version of the
program see <a href="monty_general.swinb">monty_general.swinb</a>.
For an even simpler program see <a href="monty_simple.pl">monty_simple.pl</a>.
</p>
</div>

<div class="nb-cell program" data-background="true">
:- use_module(library(pita)).

:- if(current_predicate(use_rendering/1)).
:- use_rendering(c3).
:- endif.

:- pita.

:- begin_lpad.

prize(1):1/3; prize(2):1/3; prize(3):1/3.
% the prize is behind each door with probability 1/3


% Monty opens door 2 with probability 0.5 and door 3 with probability 0.5 if
% the prize is behind door 1.
open_door(2):0.5 ; open_door(3):0.5:-
  prize(1).
% Monty opens door 2 if the prize is behind door 3.
open_door(2):-
  prize(3).
% Monty opens door 3 if the prize is behind door 2.
open_door(3):-
  prize(2).

% the player keeps his choice and wins if he has selected a door with the prize
win_keep:-
  prize(1).

% the player switches and wins if the prize is behind the door that he has
% not selected and that Monty did not open
win_switch:-
  prize(2),
  open_door(3).

win_switch:-
  prize(3),
  open_door(2).

:- end_lpad.
</div>

<div class="nb-cell html">
<p>What is the probability that the player wins if he keeps his choice?
</p>
</div>

<div class="nb-cell query">
prob(win_keep,Prob).
</div>

<div class="nb-cell html">
<p>What is the probability that the player wins if he switches door?
</p>
</div>

<div class="nb-cell query">
prob(win_switch,Prob).
</div>

<div class="nb-cell html">
<p>The probability if the player switches grows from 1/3 to 2/3.
</p>
<p>Note that if you change the probability distribution of Monty selecting
a door to open when the prize is behind the door selected by the player,
then the probability of winning by switching remains the same.
You can try it by modifying
the third clause and rerunning the queries.
</p>
<p>You can also visualize these values with:
</p>
</div>

<div class="nb-cell query">
prob(win_keep,Prob),bar(Prob,C).
</div>

<div class="nb-cell query">
prob(win_switch,Prob),bar(Prob,C).
</div>

<div class="nb-cell html">
<p>The puzzle is also explained in this nice video by Numberphile:</p>
<div><iframe src="https://www.youtube.com/embed/4Lb-6rxZxx0?ecver=2" width="640" height="360" frameborder="0" allowfullscreen=""></iframe>
</div>

<h3>References</h3>
<p>[1] Chitta Baral, Michael Gelfond, and Nelson Rushton. "Probabilistic reasoning with answer sets." Theory and Practice of Logic Programming 9.01 (2009): 57-144.
<a href="http://www.public.asu.edu/~cbaral/papers/plogJune20-08.pdf">http://www.public.asu.edu/~cbaral/papers/plogJune20-08.pdf</a>
</p>
</div>
</div>