Commit 5998cb1b by Jean-Christophe

### new examples from Dijkstra's papers 650 and 673

parent e9a542f8
 (* EWD 650: A Theorem About Odd Powers of Odd Integers *) module EWD673 use import int.Int use import int.Power use import number.Parity use import number.Divisibility use import module ref.Refint let theorem (p: int) (k: int) (r: int) = { p >= 1 /\ odd p /\ k >= 1 /\ 1 <= r < power 2 k /\ odd r } let x = ref 1 in let d = ref 2 in for i = 1 to k do invariant { !d = power 2 i /\ 1 <= !x < !d /\ divides !d (power !x p - r) /\ odd !x } if not (divides (2 * !d) (power !x p - r)) then x := !x + !d; d := 2 * !d done; !x { 1 <= result < power 2 k /\ divides (power 2 k) (power result p - r) /\ odd result } end (* Local Variables: compile-command: "unset LANG; make -C ../.. examples/programs/ewd650.gui" End: *)
 (* EWD 673: On Weak and Strong Termination *) module EWD673 use import bool.Bool use import int.Int use import int.Lex2 use import module ref.Refint val any_bool: unit -> {} bool {} val any_nat: unit -> {} int { result >= 0 } let s (x: ref int) (y: ref int) = { !x >= 0 /\ !y >= 0 } while !x > 0 || !y > 0 do invariant { !x >= 0 /\ !y >= 0 } variant { (!x, !y) } with lex if !x > 0 then begin decr x; y := any_nat () end; (* else *) if !y > 0 then decr y done {} end (* Local Variables: compile-command: "unset LANG; make -C ../.. examples/programs/ewd673.gui" End: *)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!