binomial_heap: more efficient implementation (with rank now stored)

parent f5535c5e
......@@ -19,6 +19,7 @@ module BinomialHeap
type tree = {
elem: elt;
children: list tree;
rank: int;
}
(* [e] is no greater than the roots of the trees in [l] *)
......@@ -41,14 +42,14 @@ module BinomialHeap
lemma heaps_reverse:
forall h. heaps h -> heaps (reverse h)
function rank (t: tree) : int =
length t.children
(* function rank (t: tree) : int = *)
(* length t.children *)
function link (t1 t2: tree) : tree =
if le t1.elem t2.elem then
{ t1 with children = Cons t2 t1.children }
{ elem = t1.elem; rank = t1.rank + 1; children = Cons t2 t1.children }
else
{ t2 with children = Cons t1 t2.children }
{ elem = t2.elem; rank = t2.rank + 1; children = Cons t1 t2.children }
function occ (x: elt) (l: list tree) : int =
match l with
......@@ -86,7 +87,8 @@ module BinomialHeap
end
predicate binomial_tree (t: tree) =
has_order (rank t) t.children
t.rank = length t.children &&
has_order t.rank t.children
(* a binomial heap is a list of trees *)
type heap = list tree
......@@ -96,7 +98,7 @@ module BinomialHeap
predicate inv (m: int) (h: heap) =
match h with
| Nil -> true
| Cons t r -> let k = rank t in m <= k && binomial_tree t && inv (k + 1) r
| Cons t r -> let k = t.rank in m <= k && binomial_tree t && inv (k + 1) r
end
lemma inv_reverse:
......@@ -166,7 +168,7 @@ module BinomialHeap
ensures { occ x result = occ x h + 1 }
ensures { forall e. e <> x -> occ e result = occ e h }
=
add_tree { elem = x; children = Nil } h
add_tree { elem = x; rank = 0; children = Nil } h
let rec merge (ghost k: int) (h1 h2: heap)
requires { heaps h1 }
......
......@@ -6,28 +6,30 @@
<prover id="1" name="Alt-Ergo" version="1.01" timelimit="6" steplimit="0" memlimit="1000"/>
<prover id="2" name="Eprover" version="1.8-001" timelimit="6" steplimit="0" memlimit="1000"/>
<file name="../binomial_heap.mlw" expanded="true">
<theory name="BinomialHeap" sum="129ba3e361754e4b52388d22424142ee" expanded="true">
<theory name="BinomialHeap" sum="0b4cf8ddb9d3580c11d55bf59ef6dc13" expanded="true">
<goal name="le_roots_trans">
<proof prover="0" obsolete="true"><result status="unknown" time="0.01"/></proof>
<proof prover="0"><result status="unknown" time="0.01"/></proof>
<proof prover="1"><result status="unknown" time="0.02"/></proof>
</goal>
<goal name="heaps_reverse">
<proof prover="0" obsolete="true"><result status="timeout" time="6.98"/></proof>
<proof prover="0"><result status="timeout" time="6.98"/></proof>
<proof prover="1"><result status="unknown" time="0.03"/></proof>
</goal>
<goal name="occ_nonneg">
<proof prover="0" obsolete="true"><result status="timeout" time="6.01"/></proof>
<proof prover="0"><result status="timeout" time="6.01"/></proof>
<proof prover="1"><result status="unknown" time="0.03"/></proof>
</goal>
<goal name="occ_reverse">
<proof prover="0" obsolete="true"><result status="timeout" time="6.01"/></proof>
<proof prover="0"><result status="timeout" time="6.01"/></proof>
<proof prover="1"><result status="unknown" time="0.06"/></proof>
</goal>
<goal name="heaps_mem">
<proof prover="0" obsolete="true"><result status="timeout" time="6.02"/></proof>
<proof prover="0"><result status="timeout" time="6.02"/></proof>
<proof prover="1"><result status="unknown" time="0.05"/></proof>
</goal>
<goal name="inv_reverse" expanded="true">
<goal name="inv_reverse">
<proof prover="0" obsolete="true"><result status="timeout" time="6.02"/></proof>
<proof prover="1" obsolete="true"><result status="unknown" time="0.07"/></proof>
</goal>
<goal name="WP_parameter empty" expl="VC for empty">
<proof prover="1"><result status="valid" time="0.01" steps="4"/></proof>
......@@ -50,16 +52,16 @@
<proof prover="1"><result status="valid" time="0.00" steps="11"/></proof>
</goal>
<goal name="WP_parameter get_min.5" expl="5. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="23"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="24"/></proof>
</goal>
<goal name="WP_parameter get_min.6" expl="6. postcondition">
<proof prover="1"><result status="valid" time="0.01" steps="27"/></proof>
</goal>
<goal name="WP_parameter get_min.7" expl="7. postcondition">
<proof prover="1"><result status="valid" time="0.00" steps="36"/></proof>
<proof prover="0"><result status="valid" time="0.06"/></proof>
</goal>
<goal name="WP_parameter get_min.8" expl="8. postcondition">
<proof prover="0"><result status="valid" time="0.06"/></proof>
<proof prover="0"><result status="valid" time="0.07"/></proof>
</goal>
<goal name="WP_parameter get_min.9" expl="9. precondition">
<proof prover="2"><result status="valid" time="0.01"/></proof>
......@@ -78,60 +80,60 @@
<proof prover="1"><result status="valid" time="0.01" steps="6"/></proof>
</goal>
<goal name="WP_parameter add_tree.2" expl="2. postcondition">
<proof prover="0"><result status="valid" time="0.01"/></proof>
<proof prover="1"><result status="valid" time="0.00" steps="11"/></proof>
<proof prover="1" timelimit="21"><result status="valid" time="0.01" steps="12"/></proof>
</goal>
<goal name="WP_parameter add_tree.3" expl="3. postcondition">
<proof prover="1"><result status="valid" time="0.00" steps="8"/></proof>
<proof prover="1"><result status="valid" time="0.00" steps="9"/></proof>
</goal>
<goal name="WP_parameter add_tree.4" expl="4. postcondition">
<proof prover="0"><result status="valid" time="0.02"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="57"/></proof>
</goal>
<goal name="WP_parameter add_tree.5" expl="5. postcondition">
<proof prover="1"><result status="valid" time="0.01" steps="42"/></proof>
<proof prover="1" timelimit="21"><result status="valid" time="0.01" steps="42"/></proof>
</goal>
<goal name="WP_parameter add_tree.6" expl="6. postcondition">
<proof prover="1"><result status="valid" time="0.01" steps="26"/></proof>
<proof prover="0"><result status="valid" time="0.14"/></proof>
</goal>
<goal name="WP_parameter add_tree.7" expl="7. assertion">
<transf name="compute_in_goal">
<goal name="WP_parameter add_tree.7.1" expl="1. assertion">
<proof prover="1"><result status="valid" time="0.05" steps="145"/></proof>
<proof prover="1"><result status="valid" time="0.05" steps="52"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter add_tree.8" expl="8. variant decrease">
<proof prover="1"><result status="valid" time="0.01" steps="13"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="14"/></proof>
</goal>
<goal name="WP_parameter add_tree.9" expl="9. precondition">
<proof prover="0"><result status="valid" time="0.14"/></proof>
<proof prover="0"><result status="valid" time="0.23"/></proof>
</goal>
<goal name="WP_parameter add_tree.10" expl="10. precondition">
<transf name="compute_in_goal">
<goal name="WP_parameter add_tree.10.1" expl="1. precondition">
<proof prover="1"><result status="valid" time="0.52" steps="1189"/></proof>
<proof prover="1"><result status="valid" time="0.21" steps="1046"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter add_tree.11" expl="11. precondition">
<proof prover="1"><result status="valid" time="0.02" steps="64"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="70"/></proof>
</goal>
<goal name="WP_parameter add_tree.12" expl="12. precondition">
<proof prover="0"><result status="valid" time="0.07"/></proof>
</goal>
<goal name="WP_parameter add_tree.13" expl="13. postcondition">
<proof prover="1"><result status="valid" time="0.01" steps="14"/></proof>
<proof prover="0"><result status="valid" time="0.02"/></proof>
</goal>
<goal name="WP_parameter add_tree.14" expl="14. postcondition">
<proof prover="0"><result status="valid" time="0.13"/></proof>
<proof prover="0"><result status="valid" time="0.01"/></proof>
</goal>
<goal name="WP_parameter add_tree.15" expl="15. postcondition">
<proof prover="0"><result status="valid" time="0.14"/></proof>
<proof prover="0"><result status="valid" time="0.10"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter add" expl="VC for add">
<proof prover="0"><result status="valid" time="0.04"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="157"/></proof>
</goal>
<goal name="WP_parameter merge" expl="VC for merge">
<transf name="split_goal_wp">
......@@ -163,6 +165,7 @@
<transf name="compute_in_goal">
<goal name="WP_parameter merge.9.1" expl="1. postcondition">
<proof prover="0"><result status="valid" time="0.02"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="51"/></proof>
</goal>
</transf>
</goal>
......@@ -170,25 +173,26 @@
<proof prover="1"><result status="valid" time="0.01" steps="13"/></proof>
</goal>
<goal name="WP_parameter merge.11" expl="11. precondition">
<proof prover="1"><result status="valid" time="0.02" steps="62"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="57"/></proof>
</goal>
<goal name="WP_parameter merge.12" expl="12. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="26"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="22"/></proof>
</goal>
<goal name="WP_parameter merge.13" expl="13. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="8"/></proof>
</goal>
<goal name="WP_parameter merge.14" expl="14. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="50"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="41"/></proof>
</goal>
<goal name="WP_parameter merge.15" expl="15. postcondition">
<proof prover="0"><result status="valid" time="0.03"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="121"/></proof>
</goal>
<goal name="WP_parameter merge.16" expl="16. postcondition">
<proof prover="1"><result status="valid" time="0.02" steps="63"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="51"/></proof>
</goal>
<goal name="WP_parameter merge.17" expl="17. postcondition">
<proof prover="1"><result status="valid" time="0.07" steps="161"/></proof>
<proof prover="1"><result status="valid" time="0.07" steps="159"/></proof>
</goal>
<goal name="WP_parameter merge.18" expl="18. variant decrease">
<proof prover="1"><result status="valid" time="0.01" steps="18"/></proof>
......@@ -197,19 +201,24 @@
<proof prover="1"><result status="valid" time="0.01" steps="9"/></proof>
</goal>
<goal name="WP_parameter merge.20" expl="20. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="51"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="42"/></proof>
</goal>
<goal name="WP_parameter merge.21" expl="21. precondition">
<proof prover="1"><result status="valid" time="0.00" steps="60"/></proof>
<transf name="compute_in_goal">
<goal name="WP_parameter merge.21.1" expl="1. precondition">
<proof prover="1"><result status="valid" time="0.03" steps="451"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter merge.22" expl="22. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="27"/></proof>
<proof prover="1"><result status="valid" time="0.00" steps="23"/></proof>
</goal>
<goal name="WP_parameter merge.23" expl="23. postcondition">
<proof prover="0"><result status="valid" time="0.02"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="122"/></proof>
</goal>
<goal name="WP_parameter merge.24" expl="24. postcondition">
<proof prover="1"><result status="valid" time="0.02" steps="64"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="52"/></proof>
</goal>
<goal name="WP_parameter merge.25" expl="25. postcondition">
<proof prover="1"><result status="valid" time="0.06" steps="149"/></proof>
......@@ -218,25 +227,22 @@
<proof prover="1"><result status="valid" time="0.01" steps="14"/></proof>
</goal>
<goal name="WP_parameter merge.27" expl="27. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="65"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="61"/></proof>
</goal>
<goal name="WP_parameter merge.28" expl="28. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="27"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="23"/></proof>
</goal>
<goal name="WP_parameter merge.29" expl="29. precondition">
<transf name="compute_in_goal">
<goal name="WP_parameter merge.29.1" expl="1. precondition">
<proof prover="1"><result status="valid" time="0.03" steps="450"/></proof>
</goal>
</transf>
<proof prover="1"><result status="valid" time="0.00" steps="61"/></proof>
</goal>
<goal name="WP_parameter merge.30" expl="30. precondition">
<proof prover="1"><result status="valid" time="0.00" steps="27"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="23"/></proof>
</goal>
<goal name="WP_parameter merge.31" expl="31. precondition">
<transf name="compute_in_goal">
<goal name="WP_parameter merge.31.1" expl="1. precondition">
<proof prover="0"><result status="valid" time="0.65"/></proof>
<proof prover="0"><result status="valid" time="0.16"/></proof>
<proof prover="1"><result status="valid" time="2.62" steps="9363"/></proof>
</goal>
</transf>
</goal>
......@@ -245,7 +251,7 @@
<goal name="WP_parameter merge.32.1" expl="1. precondition">
<transf name="compute_in_goal">
<goal name="WP_parameter merge.32.1.1" expl="1. precondition">
<proof prover="1"><result status="valid" time="0.04" steps="245"/></proof>
<proof prover="1"><result status="valid" time="0.04" steps="339"/></proof>
</goal>
</transf>
</goal>
......@@ -256,15 +262,18 @@
</goal>
<goal name="WP_parameter merge.34" expl="34. precondition">
<proof prover="0"><result status="valid" time="0.08"/></proof>
<proof prover="1" obsolete="true"><result status="timeout" time="5.99"/></proof>
</goal>
<goal name="WP_parameter merge.35" expl="35. postcondition">
<proof prover="1"><result status="valid" time="0.01" steps="20"/></proof>
</goal>
<goal name="WP_parameter merge.36" expl="36. postcondition">
<proof prover="0"><result status="valid" time="0.10"/></proof>
<proof prover="1" obsolete="true"><result status="timeout" time="5.99"/></proof>
</goal>
<goal name="WP_parameter merge.37" expl="37. postcondition">
<proof prover="0"><result status="valid" time="0.11"/></proof>
<proof prover="1" obsolete="true"><result status="timeout" time="5.99"/></proof>
</goal>
</transf>
</goal>
......@@ -274,20 +283,20 @@
<proof prover="1"><result status="valid" time="0.01" steps="4"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.2" expl="2. postcondition">
<proof prover="1"><result status="valid" time="0.01" steps="43"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="42"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.3" expl="3. variant decrease">
<proof prover="1"><result status="valid" time="0.00" steps="16"/></proof>
<proof prover="1"><result status="valid" time="0.00" steps="17"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.4" expl="4. precondition">
<transf name="compute_in_goal">
<goal name="WP_parameter extract_min_tree.4.1" expl="1. precondition">
<proof prover="1"><result status="valid" time="0.02" steps="221"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="243"/></proof>
</goal>
</transf>
</goal>
<goal name="WP_parameter extract_min_tree.5" expl="5. precondition">
<proof prover="1"><result status="valid" time="0.02" steps="46"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="24"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.6" expl="6. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="7"/></proof>
......@@ -296,40 +305,44 @@
<transf name="split_goal_wp">
<goal name="WP_parameter extract_min_tree.7.1" expl="1. VC for extract_min_tree">
<proof prover="0"><result status="valid" time="0.03"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="107"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.2" expl="2. VC for extract_min_tree">
<proof prover="1"><result status="valid" time="0.00" steps="16"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.3" expl="3. VC for extract_min_tree">
<proof prover="1"><result status="valid" time="0.01" steps="111"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="108"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.4" expl="4. VC for extract_min_tree">
<proof prover="1"><result status="valid" time="0.01" steps="69"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="65"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.5" expl="5. VC for extract_min_tree">
<proof prover="1"><result status="valid" time="0.01" steps="48"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="49"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.6" expl="6. VC for extract_min_tree">
<proof prover="0"><result status="valid" time="0.02"/></proof>
<proof prover="0"><result status="valid" time="0.06"/></proof>
<proof prover="1"><result status="valid" time="0.09" steps="299"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.7" expl="7. VC for extract_min_tree">
<proof prover="1"><result status="valid" time="0.01" steps="15"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.8" expl="8. VC for extract_min_tree">
<proof prover="0"><result status="valid" time="0.03"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="160"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.9" expl="9. VC for extract_min_tree">
<proof prover="1"><result status="valid" time="0.01" steps="79"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="74"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.10" expl="10. VC for extract_min_tree">
<proof prover="1"><result status="valid" time="0.01" steps="52"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="47"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.11" expl="11. VC for extract_min_tree">
<proof prover="0"><result status="valid" time="0.02"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="18"/></proof>
</goal>
<goal name="WP_parameter extract_min_tree.7.12" expl="12. VC for extract_min_tree">
<proof prover="0"><result status="valid" time="0.06"/></proof>
<proof prover="0"><result status="valid" time="0.02"/></proof>
<proof prover="1"><result status="valid" time="0.06" steps="533"/></proof>
</goal>
</transf>
</goal>
......@@ -348,16 +361,16 @@
<proof prover="1"><result status="valid" time="0.01" steps="4"/></proof>
</goal>
<goal name="WP_parameter extract_min.4" expl="4. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="30"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="32"/></proof>
</goal>
<goal name="WP_parameter extract_min.5" expl="5. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="60"/></proof>
<proof prover="1"><result status="valid" time="0.00" steps="61"/></proof>
</goal>
<goal name="WP_parameter extract_min.6" expl="6. precondition">
<proof prover="1"><result status="valid" time="0.01" steps="9"/></proof>
</goal>
<goal name="WP_parameter extract_min.7" expl="7. precondition">
<proof prover="1"><result status="valid" time="0.00" steps="9"/></proof>
<proof prover="1"><result status="valid" time="0.01" steps="9"/></proof>
</goal>
<goal name="WP_parameter extract_min.8" expl="8. postcondition">
<transf name="split_goal_wp">
......@@ -368,10 +381,10 @@
<proof prover="1"><result status="valid" time="0.01" steps="13"/></proof>
</goal>
<goal name="WP_parameter extract_min.8.3" expl="3. VC for extract_min">
<proof prover="1"><result status="valid" time="0.02" steps="103"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="59"/></proof>
</goal>
<goal name="WP_parameter extract_min.8.4" expl="4. VC for extract_min">
<proof prover="1"><result status="valid" time="0.02" steps="120"/></proof>
<proof prover="1"><result status="valid" time="0.02" steps="174"/></proof>
</goal>
</transf>
</goal>
......
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