Commit 93fd5d65 by Mário Pereira

### Code extraction (wip)

`Some examples from the gallery adapted for extraction purposes`
parent c60caecb
 ... ... @@ -158,15 +158,15 @@ module Euler001 use import SumMultiple use import int.Int use import int.ComputerDivision use import mach.int.Int let solve n requires { n >= 1 } ensures { result = sum_multiple_3_5_lt n } = let n3 = div (n-1) 3 in let n5 = div (n-1) 5 in let n15 = div (n-1) 15 in div (3 * n3 * (n3+1) + 5 * n5 * (n5+1) - 15 * n15 * (n15+1)) 2 = let n3 = (n-1) / 3 in let n5 = (n-1) / 5 in let n15 = (n-1) / 15 in (3 * n3 * (n3+1) + 5 * n5 * (n5+1) - 15 * n15 * (n15+1)) / 2 (** Small test. Run it with ... ...
 ... ... @@ -53,7 +53,7 @@ end module NewtonMethod use import int.Int use import int.ComputerDivision use import mach.int.Int use import ref.Ref use import Square ... ... @@ -63,7 +63,7 @@ module NewtonMethod = if x = 0 then 0 else if x <= 3 then 1 else let y = ref x in let z = ref (div (1 + x) 2) in let z = ref ((1 + x) / 2) in while !z < !y do variant { !y } invariant { !z > 0 } ... ... @@ -72,7 +72,7 @@ module NewtonMethod invariant { x < sqr (!y + 1) } invariant { x < sqr (!z + 1) } y := !z; z := div (div x !z + !z) 2; z := (x / !z + !z) / 2; (* A few hints to prove preservation of the last invariant *) assert { x < sqr (!z + 1) by let a = div x !y in ... ...
 ... ... @@ -412,7 +412,7 @@ module KodaRuskey use import int.Int use import ref.Ref val map_of_array (a: array 'a) : M.map int 'a val ghost map_of_array (a: array 'a) : M.map int 'a ensures { result = a.elts } val ghost visited: ref visited ... ...
 ... ... @@ -9,7 +9,7 @@ What is the largest prime factor of the number 600851475143 ? module PrimeFactor use import int.ComputerDivision use import mach.int.Int use import number.Divisibility use import number.Prime use import number.Coprime ... ... @@ -29,14 +29,12 @@ module PrimeFactor i >= d && let u = div n i in u * i = n && divides u n && u * i = n && (u >= d -> n >= d * i >= d * d && false) && u >= 2 && u < n && false } ; n end else if d >= 2 && mod n d = 0 then d else end else if d >= 2 && n % d = 0 then d else smallest_divisor (d+1) n use import ref.Ref use import list.List val factors : ref (list int) let largest_prime_factor (n:int) : int requires { 2 <= n } ensures { prime result } ... ... @@ -44,8 +42,7 @@ module PrimeFactor ensures { forall i:int. result < i <= n -> not (prime i /\ divides i n) } = let d = smallest_divisor 2 n in let factor = ref d in let target = ref (div n d) in factors := Cons d Nil; let target = ref (n / d) in assert { !target * d = n && divides !target n } ; assert { forall i:int. prime i /\ divides i n /\ i > d -> coprime d i && divides i !target }; ... ... @@ -59,14 +56,13 @@ module PrimeFactor invariant { forall i:int. prime i /\ divides i n /\ i > !factor -> divides i !target } variant { !target } let ghost oldt = !target in let oldt = ghost !target in let ghost oldf = !factor in assert { divides !target !target && !target >= 2 && !target >= !factor }; let d = smallest_divisor !factor !target in assert { prime d }; factor := d; factors := Cons d !factors; target := div !target d; target := !target / d; assert { !target * d = oldt && divides !target oldt } ; assert { forall i:int. prime i /\ divides i n /\ i > d -> i > oldf && divides i oldt && 1 <= d < i ... ...
 ... ... @@ -2,230 +2,112 @@ ... ...
No preview for this file type
 ... ... @@ -9,8 +9,9 @@ module HeightCPS use import bintree.Tree use import bintree.Height function height_cps (t: tree 'a) (k: int -> 'b) : 'b = match t with let rec function height_cps (t: tree 'a) (k: int -> 'b) : 'b variant { t } = match t with | Empty -> k 0 | Node l _ r -> height_cps l (fun hl -> ... ... @@ -18,7 +19,7 @@ module HeightCPS k (1 + max hl hr))) end function height1 (t: tree 'a) : int = height_cps t (fun h -> h) let function height1 (t: tree 'a) : int = height_cps t (fun h -> h) lemma height_cps_correct: forall t: tree 'a, k: int -> 'b. height_cps t k = k (height t) ... ...
 ... ... @@ -3,23 +3,69 @@ "http://why3.lri.fr/why3session.dtd"> ... ... @@ -31,160 +77,28 @@