From 489fd4f780db1deba3ed453f2800fe69d4f0e5a8 Mon Sep 17 00:00:00 2001 From: sjunges Date: Thu, 20 Oct 2016 01:42:00 +0200 Subject: [PATCH] Die and TwoDie as in the Qapl talk Former-commit-id: 93f21ffea34b8fff4fae4ae6a41c2bb8f67b0ae1 [formerly 88343ceb7b65aeb964dbccc0765eae51faadc683] Former-commit-id: 1595b7eaac1932190e96f023350f97254cc52099 --- examples/pdtmc/die.pm | 35 ++++++++++++++++++++++++++++++++ examples/pdtmc/twodie.pm | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 examples/pdtmc/die.pm create mode 100644 examples/pdtmc/twodie.pm diff --git a/examples/pdtmc/die.pm b/examples/pdtmc/die.pm new file mode 100644 index 000000000..31290bd69 --- /dev/null +++ b/examples/pdtmc/die.pm @@ -0,0 +1,35 @@ +// Knuth's model of a fair die using only fair coins +dtmc + +const double p; +const double q; + +module die + + // local state + s : [0..7] init 0; + // value of the dice + d : [0..6] init 0; + + [] s=0 -> p : (s'=1) + 1-p : (s'=2); + [] s=1 -> q : (s'=3) + 1-q : (s'=4); + [] s=2 -> q : (s'=5) + 1-q : (s'=6); + [] s=3 -> p : (s'=1) + 1-p : (s'=7) & (d'=1); + [] s=4 -> p : (s'=7) & (d'=3) + 1-p : (s'=7) & (d'=2); + [] s=5 -> p : (s'=2) + 1-p : (s'=7) & (d'=6); + [] s=6 -> p : (s'=7) & (d'=6) + 1-p : (s'=7) & (d'=5); + [] s=7 -> 1: (s'=7); + +endmodule + +rewards "coin_flips" + [] s<7 : 1; +endrewards + +label "one" = s=7&d=1; +label "two" = s=7&d=2; +label "three" = s=7&d=3; +label "four" = s=7&d=4; +label "five" = s=7&d=5; +label "six" = s=7&d=6; +label "end" = s=7; diff --git a/examples/pdtmc/twodie.pm b/examples/pdtmc/twodie.pm new file mode 100644 index 000000000..d38f75496 --- /dev/null +++ b/examples/pdtmc/twodie.pm @@ -0,0 +1,44 @@ +// Knuth's model of a fair die using only fair coins +dtmc + +const double p; +const double q; + +module die1 + + // local state + s1 : [0..7] init 0; + // value of the dice + d1 : [0..6] init 0; + + [] s1=0 -> p : (s1'=1) + 1-p : (s1'=2); + [] s1=1 -> q : (s1'=3) + 1-q : (s1'=4); + [] s1=2 -> q : (s1'=5) + 1-q : (s1'=6); + [] s1=3 -> p : (s1'=1) + 1-p : (s1'=7) & (d1'=1); + [] s1=4 -> p : (s1'=7) & (d1'=3) + 1-p : (s1'=7) & (d1'=2); + [] s1=5 -> p : (s1'=2) + 1-p : (s1'=7) & (d1'=4); + [] s1=6 -> p : (s1'=7) & (d1'=6) + 1-p : (s1'=7) & (d1'=5); + [] s1=7 -> 1: (s1'=7); + +endmodule + +module die2 = die1 [ s1=s2, s2=s1, d1=d2 ] endmodule + +rewards "coin_flips" + [] s1<7 | s2<7 : 1; +endrewards + +label "two" = s1=7 & s2=7 & d1+d2=2; +label "three" = s1=7 & s2=7 & d1+d2=3; +label "four" = s1=7 & s2=7 & d1+d2=4; +label "five" = s1=7 & s2=7 & d1+d2=5; +label "six" = s1=7 & s2=7 & d1+d2=6; +label "seven" = s1=7 & s2=7 & d1+d2=7; +label "eight" = s1=7 & s2=7 & d1+d2=8; +label "nine" = s1=7 & s2=7 & d1+d2=9; +label "ten" = s1=7 & s2=7 & d1+d2=10; +label "eleven" = s1=7 & s2=7 & d1+d2=11; +label "twelve" = s1=7 & s2=7 & d1+d2=12; +label "same" = s1=7 & s2=7 & d1=d2; + +label "end" = s1=7 & s2=7;