Commit 4a782ded by Jean-Christophe Filliâtre

### word_common_factor: simplified proof

parent 79f53fcf
 (** {2 Common factor of two words} (** {2 Common factor of two words} If `a ++ b = b ++ a` then `a` and `b` are powers of a common word. *) If `a ++ b = b ++ a` then `a` and `b` are powers of a common word. Authors: Jean-Christophe Filliâtre (CNRS) Andrei Paskevich (Univ Paris-Sud) *) use int.Int use int.Int use seq.Seq use seq.Seq ... @@ -21,21 +26,17 @@ let rec lemma power_add (w: word) (n1 n2: int) ... @@ -21,21 +26,17 @@ let rec lemma power_add (w: word) (n1 n2: int) ensures { power w (n1 + n2) == power w n1 ++ power w n2 } ensures { power w (n1 + n2) == power w n1 ++ power w n2 } = if n1 > 0 then power_add w (n1 - 1) n2 = if n1 > 0 then power_add w (n1 - 1) n2 let rec remove_prefix (a b: word) : word requires { length a <= length b && b[0 .. length a] == a } ensures { b = a ++ result } variant { length a } = if length a = 0 then b else remove_prefix a[1..] b[1..] let rec common_factor (a b: word) : (w: word, ka: int, kb: int) let rec common_factor (a b: word) : (w: word, ka: int, kb: int) requires { a ++ b == b ++ a } requires { a ++ b == b ++ a } ensures { ka >= 0 /\ a == power w ka /\ kb >= 0 /\ b == power w kb } ensures { ka >= 0 /\ a == power w ka } ensures { kb >= 0 /\ b == power w kb } variant { length a, length b } variant { length a, length b } = if length a = 0 then b, 0, 1 = if length a = 0 then b, 0, 1 else if length b = 0 then a, 1, 0 else if length b = 0 then a, 1, 0 else if length a <= length b then begin else if length a <= length b then begin let c = remove_prefix a b in let c = b[length a ..] ensures { b == a ++ result } in let w, ka, kc = common_factor a c in let w, ka, kc = common_factor a c in w, ka, ka + kc w, ka, ka + kc end else end else let w, ka, kb = common_factor b a in w, kb, ka let w, ka, kb = common_factor b a in w, kb, ka
 ... @@ -14,51 +14,54 @@ ... @@ -14,51 +14,54 @@ ... ...
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment