Commit c9f1acd0 by Jean-Christophe Filliâtre

### moved Fact to library int, split fact.mlw into two files

parent 57af3d95
 (* 'Checking a large routine' Alan Mathison Turing, 1949 One of the earliest proof of program. The routine computes n! using only additions, with two nested loops. *) module CheckingALargeRoutine use import int.Fact use import module ref.Ref let routine (n: int) = { n >= 0 } let r = ref 0 in let u = ref 1 in while !r < n do invariant { 0 <= !r <= n /\ !u = fact !r } variant { n - !r } let s = ref 1 in let v = !u in while !s <= !r do invariant { 1 <= !s <= !r + 1 /\ !u = !s * fact !r } variant { !r - !s } u := !u + v; s := !s + 1 done; r := !r + 1 done; !u { result = fact n } end (* Local Variables: compile-command: "unset LANG; make -C ../.. examples/programs/checking_a_large_routine.gui" End: *)

 (* Various programs computing the factorial. *) theory Fact "Factorial" use export int.Int function fact int : int axiom fact0: fact 0 = 1 axiom factn: forall n:int. n >= 1 -> fact n = fact (n-1) * n end module FactRecursive use import Fact use import int.Int use import int.Fact let rec fact_rec (x:int) : int variant {x} = { x >= 0 } ... ... @@ -26,8 +14,7 @@ end module FactImperative use import Fact use import int.Int use import int.Fact use import module ref.Ref let fact_imp (x:int) : int = ... ... @@ -44,41 +31,6 @@ module FactImperative end (* 'Checking a large routine' Alan Mathison Turing, 1949 One of the earliest proof of program. The routine computes n! using only additions, with two nested loops. *) module CheckingALargeRoutine use import Fact use import int.Int use import module ref.Ref let routine (n: int) = { n >= 0 } let r = ref 0 in let u = ref 1 in while !r < n do invariant { 0 <= !r <= n /\ !u = fact !r } variant { n - !r } let s = ref 1 in let v = !u in while !s <= !r do invariant { 1 <= !s <= !r + 1 /\ !u = !s * fact !r } variant { !r - !s } u := !u + v; s := !s + 1 done; r := !r + 1 done; !u { result = fact n } end (* Local Variables: compile-command: "unset LANG; make -C ../.. examples/programs/fact.gui" ... ...
 ... ... @@ -2,56 +2,54 @@ ... ...
 ... ... @@ -216,6 +216,17 @@ theory NumOf end theory Fact "Factorial" use export Int function fact int : int axiom fact0: fact 0 = 1 axiom factn: forall n:int. n >= 1 -> fact n = n * fact (n-1) end (* number theory *) theory Divisibility ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!