diff --git a/lib/Monads/NonDetMonad_Sat.thy b/lib/Monads/NonDetMonad_Sat.thy index d34b8df2d..ced68f50f 100644 --- a/lib/Monads/NonDetMonad_Sat.thy +++ b/lib/Monads/NonDetMonad_Sat.thy @@ -20,13 +20,36 @@ definition exs_valid :: "('a \ bool) \ ('a, 'b) nondet_monad \ ('b \ 'a \ bool) \ bool" ("\_\ _ \\_\") where "\P\ f \\Q\ \ \s. P s \ (\(rv, s') \ fst (f s). Q rv s')" - text \The above for the exception monad\ definition ex_exs_validE :: "('a \ bool) \ ('a, 'e + 'b) nondet_monad \ ('b \ 'a \ bool) \ ('e \ 'a \ bool) \ bool" ("\_\ _ \\_\, \_\") where "\P\ f \\Q\, \E\ \ \P\ f \\\rv. case rv of Inl e \ E e | Inr v \ Q v\" +text \ + Seen as predicate transformer, @{const exs_valid} is the so-called conjugate wp in the literature, + i.e. with + @{term "wp f Q \ \s. fst (f s) \ {(rv,s). Q rv s}"} and + @{term "cwp f Q \ not (wp f (not Q))"}, we get + @{prop "valid P f Q = (\s. P s \ wp f Q s)"} and + @{prop "exs_valid P f Q = (\s. P s \ cwp f Q s)"}. + + See also "Predicate Calculus and Program Semantics" by E. W. Dijkstra and C. S. Scholten.\ +experiment +begin + +definition + "wp f Q \ \s. fst (f s) \ {(rv,s). Q rv s}" + +definition + "cwp f Q \ not (wp f (not Q))" + +lemma + "exs_valid P f Q = (\s. P s \ cwp f Q s)" + unfolding exs_valid_def cwp_def wp_def by auto + +end + subsection \Set up for @{method wp}\ @@ -73,6 +96,10 @@ lemma exs_valid_select[wp]: "\\s. \r \ S. Q r s\ select S \\Q\" by (clarsimp simp: exs_valid_def select_def) +lemma exs_valid_alt[wp]: + "\ \P\ f \\Q\; \P'\ g \\Q\ \ \ \P or P'\ f \ g \\Q\" + by (fastforce simp: exs_valid_def alternative_def) + lemma exs_valid_get[wp]: "\\s. Q s s\ get \\ Q \" by (clarsimp simp: exs_valid_def get_def)