Commit 119e2920 by MARCHE Claude

### Examples fibonacci and edit_distance updated

parent 4a5df15c
 ... @@ -21,6 +21,10 @@ theory Word ... @@ -21,6 +21,10 @@ theory Word use export list.Length use export list.Length type char type char val eq (c1 c2:char) : bool ensures { result <-> c1 = c2 } type word = list char type word = list char inductive dist word word int = inductive dist word word int = ... @@ -158,7 +162,7 @@ module EditDistance ... @@ -158,7 +162,7 @@ module EditDistance invariant { min_suffix w1 w2 (i+1) (j+1) !oldt } invariant { min_suffix w1 w2 (i+1) (j+1) !oldt } let temp = !oldt in let temp = !oldt in oldt := t[j]; oldt := t[j]; if w1[i] = w2[j] then if eq w1[i] w2[j] then t[j] <- temp t[j] <- temp else else t[j] <- (min t[j] t[j + 1]) + 1 t[j] <- (min t[j] t[j + 1]) + 1 ... ...
 ... @@ -283,18 +283,19 @@ module FibonacciLogarithmic ... @@ -283,18 +283,19 @@ module FibonacciLogarithmic use import int.Int use import int.Int use import int.Fibonacci use import int.Fibonacci use import int.EuclideanDivision use import int.ComputerDivision use import Mat22 use import Mat22 constant m1110 : t = { a11 = 1; a12 = 1; val constant m1110 : t a21 = 1; a22 = 0 } ensures { result = { a11 = 1; a12 = 1; a21 = 1; a22 = 0 } } (* computes ((1 1) (1 0))^n in O(log(n)) time (* computes ((1 1) (1 0))^n in O(log(n)) time since it is a matrix of the shape ((a+b b) (b a)), since it is a matrix of the shape ((a+b b) (b a)), we only return the pair (a, b) *) we only return the pair (a, b) *) let rec logfib n variant { n } let rec logfib (n:int) variant { n } requires { n >= 0 } requires { n >= 0 } ensures { let a, b = result in ensures { let a, b = result in power m1110 n = { a11 = a+b; a12 = b; a21 = b; a22 = a } } power m1110 n = { a11 = a+b; a12 = b; a21 = b; a22 = a } } ... @@ -317,9 +318,11 @@ module FibonacciLogarithmic ... @@ -317,9 +318,11 @@ module FibonacciLogarithmic thus, we can compute F(n) in O(log(n)) using funtion logfib above thus, we can compute F(n) in O(log(n)) using funtion logfib above *) *) lemma fib_m : let rec lemma fib_m (n: int) forall n: int. n >= 0 -> requires { n >= 0 } let p = power m1110 n in fib (n+1) = p.a11 /\ fib n = p.a21 variant { n } ensures { let p = power m1110 n in fib (n+1) = p.a11 /\ fib n = p.a21 } = if n = 0 then () else fib_m (n-1) let fibo n requires { n >= 0 } ensures { result = fib n } = let fibo n requires { n >= 0 } ensures { result = fib n } = let _, b = logfib n in b let _, b = logfib n in b ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!