dfs example: equality and maps in programs

parent d8acfaa5
......@@ -32,16 +32,25 @@ module DFS
use import ref.Ref
type loc
constant null: loc
constant root: loc
val constant null: loc
val constant root: loc
function left loc: loc
function right loc: loc
val (==) (x y: loc) : bool
ensures { result <-> x = y }
val function left loc: loc
val function right loc: loc
type marks = map loc bool
val marked: ref marks
val ghost busy: ref marks
let set (m: ref marks) (l: loc) (b: bool) : unit
writes { m }
ensures { !m = (old !m)[l <- b] }
= let f = !m in
m := fun x -> if x == l then b else f x
predicate edge (x y: loc) = x <> null && (left x = y || right x = y)
inductive path (x y: loc) =
......@@ -66,18 +75,19 @@ module DFS
ensures { forall x: loc. !busy[x] = True -> (old !busy)[x] = True }
ensures { only_descendants_are_marked !marked }
=
if c <> null && not !marked[c] then begin
ghost busy := !busy[c <- True];
marked := !marked[c <- True];
if not (c == null) && not !marked[c] then begin
ghost set busy c True;
set marked c True;
dfs (left c);
dfs (right c);
busy := !busy[c <- False]
set busy c False
end
predicate all_descendants_are_marked (marked: marks) =
root <> null ->
marked[root] = True &&
forall x y: loc. edge x y -> marked[x] = True -> y <> null -> marked[y] = True
forall x y: loc.
edge x y -> marked[x] = True -> y <> null -> marked[y] = True
lemma reformulation:
forall marked: marks.
......
......@@ -2,107 +2,45 @@
<!DOCTYPE why3session PUBLIC "-//Why3//proof session v5//EN"
"http://why3.lri.fr/why3session.dtd">
<why3session shape_version="4">
<prover id="0" name="Alt-Ergo" version="1.01" timelimit="6" steplimit="1" memlimit="1000"/>
<prover id="13" name="Alt-Ergo" version="0.99.1" timelimit="6" steplimit="1" memlimit="1000"/>
<prover id="18" name="Z3" version="4.3.2" timelimit="15" steplimit="1" memlimit="1000"/>
<file name="../dfs.mlw" expanded="true">
<theory name="DFS" sum="f30cfdc8f980d8ec0f281573e7aff648" expanded="true">
<goal name="WP_parameter dfs" expl="VC for dfs">
<transf name="split_goal_wp">
<goal name="WP_parameter dfs.1" expl="1. precondition">
<proof prover="13"><result status="valid" time="0.01" steps="14"/></proof>
</goal>
<goal name="WP_parameter dfs.2" expl="2. precondition">
<proof prover="13"><result status="valid" time="0.01" steps="11"/></proof>
</goal>
<goal name="WP_parameter dfs.3" expl="3. precondition">
<proof prover="13"><result status="valid" time="0.00" steps="10"/></proof>
</goal>
<goal name="WP_parameter dfs.4" expl="4. precondition">
<proof prover="13"><result status="valid" time="0.02" steps="12"/></proof>
</goal>
<goal name="WP_parameter dfs.5" expl="5. precondition">
<proof prover="13"><result status="valid" time="0.01" steps="12"/></proof>
</goal>
<goal name="WP_parameter dfs.6" expl="6. precondition">
<proof prover="13"><result status="valid" time="0.02" steps="20"/></proof>
</goal>
<goal name="WP_parameter dfs.7" expl="7. postcondition">
<proof prover="13"><result status="valid" time="0.08" steps="140"/></proof>
</goal>
<goal name="WP_parameter dfs.8" expl="8. postcondition">
<proof prover="13"><result status="valid" time="0.02" steps="22"/></proof>
</goal>
<goal name="WP_parameter dfs.9" expl="9. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="20"/></proof>
</goal>
<goal name="WP_parameter dfs.10" expl="10. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="21"/></proof>
</goal>
<goal name="WP_parameter dfs.11" expl="11. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="16"/></proof>
</goal>
<goal name="WP_parameter dfs.12" expl="12. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="5"/></proof>
</goal>
<goal name="WP_parameter dfs.13" expl="13. postcondition">
<proof prover="13"><result status="valid" time="0.00" steps="5"/></proof>
</goal>
<goal name="WP_parameter dfs.14" expl="14. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="5"/></proof>
</goal>
<goal name="WP_parameter dfs.15" expl="15. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="4"/></proof>
</goal>
<goal name="WP_parameter dfs.16" expl="16. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="4"/></proof>
</goal>
<goal name="WP_parameter dfs.17" expl="17. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="4"/></proof>
</goal>
</transf>
<theory name="DFS" sum="ade623568557d965f5873680b9966d82" expanded="true">
<goal name="VC null" expl="VC for null" expanded="true">
<proof prover="0"><result status="valid" time="0.00" steps="0"/></proof>
</goal>
<goal name="VC root" expl="VC for root" expanded="true">
<proof prover="0"><result status="valid" time="0.00" steps="0"/></proof>
</goal>
<goal name="VC set" expl="VC for set" expanded="true">
<proof prover="0" steplimit="-1"><result status="valid" time="0.00" steps="4"/></proof>
</goal>
<goal name="VC dfs" expl="VC for dfs" expanded="true">
<proof prover="0"><result status="valid" time="0.07" steps="252"/></proof>
</goal>
<goal name="reformulation">
<transf name="induction_pr">
<goal name="reformulation.1" expl="1.">
<transf name="simplify_trivial_quantification">
<goal name="reformulation.1.1" expl="1.">
<proof prover="13"><result status="valid" time="0.00" steps="3"/></proof>
<proof prover="0"><result status="valid" time="0.00" steps="3"/></proof>
<proof prover="13" obsolete="true"><result status="valid" time="0.00" steps="3"/></proof>
</goal>
</transf>
</goal>
<goal name="reformulation.2" expl="2.">
<transf name="simplify_trivial_quantification">
<goal name="reformulation.2.1" expl="1.">
<proof prover="18"><result status="valid" time="0.00"/></proof>
<proof prover="0"><result status="valid" time="0.00" steps="10"/></proof>
<proof prover="18" obsolete="true"><result status="valid" time="0.00"/></proof>
</goal>
</transf>
</goal>
</transf>
</goal>
<goal name="WP_parameter traverse" expl="VC for traverse">
<transf name="split_goal_wp">
<goal name="WP_parameter traverse.1" expl="1. assertion">
<proof prover="13"><result status="valid" time="0.01" steps="8"/></proof>
</goal>
<goal name="WP_parameter traverse.2" expl="2. precondition">
<proof prover="13"><result status="valid" time="0.01" steps="1"/></proof>
</goal>
<goal name="WP_parameter traverse.3" expl="3. precondition">
<proof prover="13"><result status="valid" time="0.01" steps="5"/></proof>
</goal>
<goal name="WP_parameter traverse.4" expl="4. precondition">
<proof prover="13"><result status="valid" time="0.01" steps="2"/></proof>
</goal>
<goal name="WP_parameter traverse.5" expl="5. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="5"/></proof>
</goal>
<goal name="WP_parameter traverse.6" expl="6. postcondition">
<proof prover="13"><result status="valid" time="0.01" steps="28"/></proof>
</goal>
<goal name="WP_parameter traverse.7" expl="7. postcondition">
<proof prover="13"><result status="valid" time="0.00" steps="10"/></proof>
</goal>
</transf>
<goal name="VC traverse" expl="VC for traverse" expanded="true">
<proof prover="0"><result status="valid" time="0.00" steps="44"/></proof>
</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