Commit 0d9c1d4d authored by MARCHE Claude's avatar MARCHE Claude
Browse files

LCP: test1 fully proved

parent 2ba31cc1
......@@ -73,7 +73,9 @@ that it does so correctly.
*)
module LCP
module LCP "longest common prefix"
use import int.Int
use import array.Array
......@@ -96,6 +98,14 @@ predicate is_common_prefix (a:array int) (x y:int) (l:int) =
0 <= l /\ x+l <= a.length /\ y+l <= a.length /\
(forall i:int. 0 <= i < l -> a[x+i] = a[y+i])
lemma common_prefix_eq:
forall a:array int, x:int.
0 <= x < a.length -> is_common_prefix a x x (a.length - x)
lemma common_prefix_eq2:
forall a:array int, x:int.
0 <= x < a.length -> not (is_common_prefix a x x (a.length - x + 1))
lemma not_common_prefix_if_last_different:
forall a:array int, x y:int, l:int.
0 < l /\ x+l < a.length /\ y+l < a.length /\ a[x+(l-1)] <> a[y+(l-1)] ->
......@@ -109,6 +119,10 @@ axiom lcp_spec:
(l = longest_common_prefix a x y <->
is_common_prefix a x y l /\ not is_common_prefix a x y (l+1))
lemma lcp_eq :
forall a:array int, x:int.
0 <= x < a.length -> longest_common_prefix a x x = a.length - x
use import ref.Refint
......@@ -131,31 +145,41 @@ let test1 () =
let arr = Array.make 4 0 in
arr[0]<-1; arr[1]<-2; arr[2]<-2; arr[3]<-5;
let x = lcp arr 1 2 in
assert { is_common_prefix arr 1 2 1};
check { x = 1 };
(* int[] brr = {1,2,3,5}; *)
let brr = Array.make 4 0 in
brr[0]<-1; brr[1]<-2; brr[2]<-3; brr[3]<-5;
let x = lcp brr 1 2 in
assert { is_common_prefix brr 1 2 0};
check { x = 0 };
(* int[] crr = {1,2,3,5}; *)
let crr = Array.make 4 0 in
crr[0]<-1; crr[1]<-2; crr[2]<-3; crr[3]<-5;
let x = lcp crr 2 3 in
assert { is_common_prefix crr 2 3 0};
check { x = 0 };
(* int[] drr = {1,2,3,3}; *)
let drr = Array.make 4 0 in
drr[0]<-1; drr[1]<-2; drr[2]<-3; drr[3]<-3;
let x = lcp drr 2 3 in
assert { is_common_prefix drr 2 3 1};
check {x = 1}
(*
predicate le (a : array int) (x y:int) =
*)
let n = a.length in
let l = longest_common_prefix a x y in
x+l = n \/
(x+l < n /\ y+l < n /\ a[x+l] <= a[y+l])
lemma eq_le :
forall a:array int, x :int.
0 <= x < a.length -> le a x x
let compare (a:array int) (x y:int) : int
requires { 0 <= x < a.length }
requires { 0 <= y < a.length }
(* ensures { result <= 0 <-> le a x y } *)
ensures { result <= 0 <-> le a x y }
=
if x = y then 0 else
let n = a.length in
......@@ -197,6 +221,11 @@ let compare (a:array int) (x y:int) : int
end
module SuffixArray
use import int.Int
......@@ -263,6 +292,10 @@ let test2 () =
end
module LRS "longest repeated substring"
use import int.Int
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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