Commit 80890a50 authored by Léon Gondelman's avatar Léon Gondelman
Browse files

random_access_list: added and proved 'set' and 'tail' operations (for rals...

random_access_list: added and proved 'set' and 'tail' operations (for rals with lists and sequences)
parent 2a216a5b
......@@ -74,6 +74,7 @@ module RandomAccessList
| Cons _ r -> if i > 0 then nth_flatten (i-1) r
end
let rec get (i: int) (l: ral 'a) : 'a
requires { 0 <= i < length (elements l) }
variant { i, l }
......@@ -85,6 +86,51 @@ module RandomAccessList
if mod i 2 = 0 then x0 else x1
end
let rec tail (l: ral 'a) : ral 'a
requires { elements l <> Nil }
variant { l }
ensures {let m = elements l in
match nth 0 m with
| None -> false
| Some x -> m = Cons x (elements result)
end }
= match l with
| Empty -> absurd
| One _ l1 -> Zero l1
| Zero l1 -> let (_, x1) = get 0 l1 in One x1 (tail l1)
end
let rec set (y: 'a) (i: int) (l: ral 'a) : ral 'a
requires { 0 <= i < length (elements l) }
variant { i, l}
ensures { nth i (elements result) = Some y}
ensures { forall j. 0 <= j < length (elements l) ->
j <> i -> nth j (elements result) = nth j (elements l) }
ensures { length (elements result) = length (elements l) }
ensures { match result, l with
| One _ _, One _ _ | Zero _, Zero _ -> true
| _ -> false
end }
= match l with
| Empty -> absurd
| One x l1 -> if i = 0 then One y l1 else
match set y (i-1) (Zero l1) with
| Empty | One _ _ -> absurd
| Zero l1 -> One x l1
end
| Zero l1 ->
let (x0, x1) = get (div i 2) l1 in
let l1' = set (if mod i 2 = 0 then (y,x1) else (x0,y)) (div i 2) l1 in
assert { forall j. 0 <= j < length (elements l) -> j <> i ->
match nth (div j 2) (elements l1) with
| None -> false
| Some (x0,_) -> Some x0 = nth (2 * (div j 2)) (elements l)
end
&& nth j (elements l) = nth j (elements (Zero l1')) };
Zero l1'
end
end
(** A straightforward encapsulation with a list ghost model
......@@ -167,7 +213,7 @@ module RandomAccessListWithSeq
| One y l1 -> Zero (add (x, y) l1)
end
let rec get (i: int) (l: ral 'a) : 'a
let rec get (i: int) (l: ral 'a) : 'a
requires { 0 <= i < length (elements l) }
variant { i, l }
ensures { (elements l)[i] = result }
......@@ -178,4 +224,30 @@ module RandomAccessListWithSeq
if mod i 2 = 0 then x0 else x1
end
let rec tail (l: ral 'a) : ral 'a
requires { not ((elements l) == empty) }
variant { l }
ensures { (elements l) == cons (elements l)[0] (elements result) }
= match l with
| Empty -> absurd
| One _ l1 -> Zero l1
| Zero l1 -> let (_, x1) = get 0 l1 in One x1 (tail l1)
end
let rec set (y: 'a) (i: int) (l: ral 'a) : ral 'a
requires { 0 <= i < length (elements l) }
variant { i, l}
ensures { elements result == set (elements l) i y}
= match l with
| Empty -> absurd
| One x l1 -> if i = 0 then One y l1 else
match set y (i-1) (Zero l1) with
| Empty | One _ _ -> absurd
| Zero l1 -> One x l1
end
| Zero l1 -> let (x0, x1) = get (div i 2) l1 in
Zero
(set (if mod i 2 = 0 then (y,x1) else (x0,y)) (div i 2) l1)
end
end
......@@ -4,10 +4,11 @@
<why3session shape_version="4">
<prover id="0" name="Alt-Ergo" version="0.99.1" timelimit="6" memlimit="1000"/>
<prover id="1" name="CVC4" version="1.4" timelimit="6" memlimit="1000"/>
<prover id="3" name="Z3" version="4.3.2" timelimit="6" memlimit="1000"/>
<prover id="4" name="Z3" version="4.3.1" timelimit="10" memlimit="1000"/>
<prover id="6" name="CVC4" version="1.3" timelimit="1" memlimit="1000"/>
<prover id="8" name="Alt-Ergo" version="0.95.2" timelimit="15" memlimit="1000"/>
<file name="../random_access_list.mlw" expanded="true">
<theory name="RandomAccessList" sum="d952bd09a31c38ca601c47b7856a5416" expanded="true">
<theory name="RandomAccessList" sum="10f317f24c1421f793cea88f1312650d" expanded="true">
<goal name="WP_parameter length_flatten" expl="VC for length_flatten">
<transf name="split_goal_wp">
<goal name="WP_parameter length_flatten.1" expl="1. variant decrease">
......@@ -42,7 +43,6 @@
<proof prover="6"><result status="valid" time="0.24"/></proof>
</goal>
<goal name="WP_parameter nth_flatten.5" expl="5. postcondition">
<proof prover="0"><result status="unknown" time="0.04"/></proof>
<proof prover="1"><result status="valid" time="0.07"/></proof>
</goal>
</transf>
......@@ -50,8 +50,88 @@
<goal name="WP_parameter get" expl="VC for get">
<proof prover="0"><result status="valid" time="0.34" steps="410"/></proof>
</goal>
<goal name="WP_parameter tail" expl="VC for tail">
<proof prover="8"><result status="valid" time="0.12" steps="271"/></proof>
</goal>
<goal name="WP_parameter set" expl="VC for set">
<transf name="split_goal_wp">
<goal name="WP_parameter set.1" expl="1. unreachable point">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="7"/></proof>
</goal>
<goal name="WP_parameter set.2" expl="2. postcondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="22"/></proof>
</goal>
<goal name="WP_parameter set.3" expl="3. postcondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="46"/></proof>
</goal>
<goal name="WP_parameter set.4" expl="4. postcondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="40"/></proof>
</goal>
<goal name="WP_parameter set.5" expl="5. postcondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="18"/></proof>
</goal>
<goal name="WP_parameter set.6" expl="6. variant decrease">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="4"/></proof>
</goal>
<goal name="WP_parameter set.7" expl="7. precondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.03" steps="31"/></proof>
</goal>
<goal name="WP_parameter set.8" expl="8. unreachable point">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="22"/></proof>
</goal>
<goal name="WP_parameter set.9" expl="9. unreachable point">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="23"/></proof>
</goal>
<goal name="WP_parameter set.10" expl="10. postcondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.03" steps="38"/></proof>
</goal>
<goal name="WP_parameter set.11" expl="11. postcondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.04" steps="99"/></proof>
</goal>
<goal name="WP_parameter set.12" expl="12. postcondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.03" steps="60"/></proof>
</goal>
<goal name="WP_parameter set.13" expl="13. postcondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="36"/></proof>
</goal>
<goal name="WP_parameter set.14" expl="14. precondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.07" steps="40"/></proof>
</goal>
<goal name="WP_parameter set.15" expl="15. variant decrease">
<proof prover="8" timelimit="5"><result status="valid" time="0.02" steps="42"/></proof>
</goal>
<goal name="WP_parameter set.16" expl="16. precondition">
<proof prover="8" timelimit="5"><result status="valid" time="0.01" steps="6"/></proof>
</goal>
<goal name="WP_parameter set.17" expl="17. assertion">
<transf name="split_goal_wp">
<goal name="WP_parameter set.17.1" expl="1. assertion">
<proof prover="8" timelimit="3"><result status="valid" time="0.87" steps="195"/></proof>
</goal>
<goal name="WP_parameter set.17.2" expl="2. assertion">
<proof prover="8" timelimit="10"><result status="valid" time="3.11" steps="572"/></proof>
</goal>
<goal name="WP_parameter set.17.3" expl="3. assertion">
<proof prover="4"><result status="valid" time="0.46"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter set.18" expl="18. postcondition">
<proof prover="8" timelimit="10"><result status="valid" time="0.87" steps="511"/></proof>
</goal>
<goal name="WP_parameter set.19" expl="19. postcondition">
<proof prover="8" timelimit="10"><result status="valid" time="0.02" steps="17"/></proof>
</goal>
<goal name="WP_parameter set.20" expl="20. postcondition">
<proof prover="8" timelimit="10"><result status="valid" time="0.03" steps="94"/></proof>
</goal>
<goal name="WP_parameter set.21" expl="21. postcondition">
<proof prover="8" timelimit="10"><result status="valid" time="0.03" steps="36"/></proof>
</goal>
</transf>
</goal>
</theory>
<theory name="RAL" sum="ef67f0d6811c1a4189d9e2bd83248eb7" expanded="true">
<theory name="RAL" sum="ef67f0d6811c1a4189d9e2bd83248eb7">
<goal name="WP_parameter empty" expl="VC for empty">
<proof prover="0"><result status="valid" time="0.01" steps="4"/></proof>
</goal>
......@@ -65,15 +145,128 @@
<proof prover="0"><result status="valid" time="0.01" steps="7"/></proof>
</goal>
</theory>
<theory name="RandomAccessListWithSeq" sum="2b4baed53359c844adc5f3be28250dd8" expanded="true">
<goal name="WP_parameter size" expl="VC for size" expanded="true">
<proof prover="0"><result status="valid" time="0.08" steps="78"/></proof>
<theory name="RandomAccessListWithSeq" sum="0a2ddaba4620ea7f427c7e1c523e87b5" expanded="true">
<goal name="WP_parameter size" expl="VC for size">
<transf name="split_goal_wp">
<goal name="WP_parameter size.1" expl="1. postcondition">
<proof prover="8"><result status="valid" time="0.01" steps="5"/></proof>
</goal>
<goal name="WP_parameter size.2" expl="2. variant decrease">
<proof prover="8"><result status="valid" time="0.02" steps="17"/></proof>
</goal>
<goal name="WP_parameter size.3" expl="3. postcondition">
<proof prover="8"><result status="valid" time="0.02" steps="8"/></proof>
</goal>
<goal name="WP_parameter size.4" expl="4. variant decrease">
<proof prover="8"><result status="valid" time="0.01" steps="18"/></proof>
</goal>
<goal name="WP_parameter size.5" expl="5. postcondition">
<proof prover="8"><result status="valid" time="0.02" steps="15"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter add" expl="VC for add">
<transf name="split_goal_wp">
<goal name="WP_parameter add.1" expl="1. postcondition">
<proof prover="8"><result status="valid" time="0.03" steps="49"/></proof>
</goal>
<goal name="WP_parameter add.2" expl="2. postcondition">
<proof prover="8"><result status="valid" time="0.02" steps="6"/></proof>
</goal>
<goal name="WP_parameter add.3" expl="3. variant decrease">
<proof prover="8"><result status="valid" time="0.02" steps="18"/></proof>
</goal>
<goal name="WP_parameter add.4" expl="4. postcondition">
<proof prover="8"><result status="valid" time="3.44" steps="427"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter add" expl="VC for add" expanded="true">
<proof prover="3"><result status="valid" time="1.34"/></proof>
<goal name="WP_parameter get" expl="VC for get">
<transf name="split_goal_wp">
<goal name="WP_parameter get.1" expl="1. unreachable point">
<proof prover="8"><result status="valid" time="0.02" steps="7"/></proof>
</goal>
<goal name="WP_parameter get.2" expl="2. postcondition">
<proof prover="8"><result status="valid" time="0.03" steps="14"/></proof>
</goal>
<goal name="WP_parameter get.3" expl="3. variant decrease">
<proof prover="8"><result status="valid" time="0.02" steps="4"/></proof>
</goal>
<goal name="WP_parameter get.4" expl="4. precondition">
<proof prover="8"><result status="valid" time="0.02" steps="22"/></proof>
</goal>
<goal name="WP_parameter get.5" expl="5. postcondition">
<proof prover="8"><result status="valid" time="0.02" steps="19"/></proof>
</goal>
<goal name="WP_parameter get.6" expl="6. variant decrease">
<proof prover="8"><result status="valid" time="0.05" steps="29"/></proof>
</goal>
<goal name="WP_parameter get.7" expl="7. precondition">
<proof prover="8"><result status="valid" time="0.06" steps="31"/></proof>
</goal>
<goal name="WP_parameter get.8" expl="8. postcondition">
<proof prover="8"><result status="valid" time="0.53" steps="151"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter get" expl="VC for get" expanded="true">
<proof prover="0"><result status="valid" time="1.62" steps="406"/></proof>
<goal name="WP_parameter tail" expl="VC for tail">
<transf name="split_goal_wp">
<goal name="WP_parameter tail.1" expl="1. unreachable point">
<proof prover="8"><result status="valid" time="0.03" steps="8"/></proof>
</goal>
<goal name="WP_parameter tail.2" expl="2. postcondition">
<proof prover="8"><result status="valid" time="0.05" steps="75"/></proof>
</goal>
<goal name="WP_parameter tail.3" expl="3. precondition">
<proof prover="8"><result status="valid" time="0.02" steps="26"/></proof>
</goal>
<goal name="WP_parameter tail.4" expl="4. variant decrease">
<proof prover="8"><result status="valid" time="0.03" steps="34"/></proof>
</goal>
<goal name="WP_parameter tail.5" expl="5. precondition">
<proof prover="8"><result status="valid" time="0.02" steps="7"/></proof>
</goal>
<goal name="WP_parameter tail.6" expl="6. postcondition">
<proof prover="8"><result status="valid" time="6.13" steps="521"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter set" expl="VC for set">
<transf name="split_goal_wp">
<goal name="WP_parameter set.1" expl="1. unreachable point">
<proof prover="8"><result status="valid" time="0.02" steps="7"/></proof>
</goal>
<goal name="WP_parameter set.2" expl="2. postcondition">
<proof prover="8"><result status="valid" time="0.04" steps="65"/></proof>
</goal>
<goal name="WP_parameter set.3" expl="3. variant decrease">
<proof prover="8"><result status="valid" time="0.02" steps="4"/></proof>
</goal>
<goal name="WP_parameter set.4" expl="4. precondition">
<proof prover="8"><result status="valid" time="0.02" steps="22"/></proof>
</goal>
<goal name="WP_parameter set.5" expl="5. unreachable point">
<proof prover="8"><result status="valid" time="0.02" steps="28"/></proof>
</goal>
<goal name="WP_parameter set.6" expl="6. unreachable point">
<proof prover="8"><result status="valid" time="0.04" steps="62"/></proof>
</goal>
<goal name="WP_parameter set.7" expl="7. postcondition">
<proof prover="8"><result status="valid" time="0.11" steps="117"/></proof>
</goal>
<goal name="WP_parameter set.8" expl="8. precondition">
<proof prover="8"><result status="valid" time="0.05" steps="31"/></proof>
</goal>
<goal name="WP_parameter set.9" expl="9. variant decrease">
<proof prover="8"><result status="valid" time="0.03" steps="38"/></proof>
</goal>
<goal name="WP_parameter set.10" expl="10. precondition">
<proof prover="8"><result status="valid" time="0.02" steps="6"/></proof>
</goal>
<goal name="WP_parameter set.11" expl="11. postcondition">
<proof prover="8"><result status="valid" time="2.39" steps="610"/></proof>
</goal>
</transf>
</goal>
</theory>
</file>
......
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