Commit 37ff1dfb authored by MARCHE Claude's avatar MARCHE Claude

Stdlib: more lemmas on sets

parent a652866a
......@@ -2,8 +2,8 @@
theory ConvexSet
use import int.Int
use import real.RealInfix
use export int.Int
use export real.RealInfix
type pt = { x : real ; y : real }
......@@ -14,29 +14,139 @@ predicate colinear (p1 p2 p3:pt) = crossproduct p1 p2 p3 = 0.0
predicate turns_left (p1 p2 p3:pt) = crossproduct p1 p2 p3 >. 0.0
lemma knuth1:
forall p1 p2 p3:pt. turns_left p1 p2 p3 -> turns_left p2 p3 p1
lemma knuth2:
forall p1 p2 p3:pt. turns_left p1 p2 p3 -> not (turns_left p2 p1 p3)
lemma knuth4:
forall p1 p2 p3 p4:pt.
turns_left p1 p2 p4 ->
turns_left p2 p3 p4 ->
turns_left p3 p1 p4 ->
turns_left p1 p2 p3
lemma knuth5:
forall p1 p2 p3 p4 p5:pt.
turns_left p1 p2 p3 ->
turns_left p1 p2 p4 ->
turns_left p1 p2 p5 ->
turns_left p3 p2 p4 ->
turns_left p4 p2 p5 ->
turns_left p3 p2 p5
lemma knuth3:
forall p1 p2 p3:pt.
not (colinear p1 p2 p3) -> turns_left p1 p2 p3 \/ turns_left p1 p3 p2
(* test: p1 = (0,0), p2 = (1,0) p3 = (1,1) *)
goal test1 :
turns_left {x=0.0;y=0.0} {x=1.0;y=0.0} {x=1.0;y=1.0}
use import list.List
use import list.Length
use import list.NthNoOpt
type path = list pt
predicate is_ccw_convex (p:path) =
let l = length p in
predicate is_inside_convex_hull (p:pt) (pa:path) =
let l = length pa in
forall i:int. 0 <= i < l ->
let i' = if i = l-1 then 0 else i+1 in
let p0 = nth i pa in
let p1 = nth i' pa in
turns_left p0 p1 p
predicate is_ccw_convex (pa:path) =
let l = length pa in
forall i:int. 0 <= i < l ->
let i' = if i = l-1 then 0 else i+1 in
let p0 = nth i p in
let p1 = nth i' p in
let p0 = nth i pa in
let p1 = nth i' pa in
forall j:int. 0 <= j < l /\ j <> i /\ j <> i' ->
turns_left p0 p1 (nth j p)
turns_left p0 p1 (nth j pa)
end
module Incremental
end
module Jarvis
(*
on calcule le point p d'ordonnee minimale, et d'abscisse minimale
parmi ceux-ci
on recherche le point q minimum pour la relation R x y = turns_left p x y
p0 = p
p1 = q
si q = p0: fini
sinon
recommencer avec p := q
*)
use import ConvexSet
use import set.Fset
use import ref.Ref
predicate lower (p q:pt) =
p.y <. q.y \/ (p.y = q.y /\ p.x <=. q.x)
let lowest_pt (s:set pt) : (pt, set pt)
requires { not (is_empty s) }
ensures { let (p,r) = result in
s = add p r /\ forall q:pt. mem q r -> lower p q }
=
let p = ref (choose s) in
let r = ref (remove !p s) in
while not (is_empty !r) do
invariant { mem !p s }
invariant { subset !r s }
invariant { forall q:pt. mem q s /\ not (mem q !r) -> lower !p q }
let q = choose !r in
if lower q !p then p := q;
r := remove q !r
done;
(!p,remove !p s)
(*
let rightest_pt (p:pt) (s:set pt) : (pt, set pt)
requires { not (is_empty s) }
ensures { let (p,r) = result in
s = add p r /\ forall q:pt. mem q r -> lower p q }
=
let p = ref (choose s) in
let r = ref (remove !p s) in
while not (is_empty !r) do
invariant { mem !p s }
invariant { subset !r s }
invariant { forall q:pt. mem q s /\ not (mem q !r) -> lower !p q }
let q = choose !r in
if lower q !p then p := q;
r := remove q !r
done;
(!p,remove !p s)
let jarvis (s:set pt) : list pt =
let p0 = lowest_pt s in
*)
end
module Graham
......@@ -46,8 +156,14 @@ use import ConvexSet
(*
let convex_hull (l:path) : path =
(* all pts of the result are points of the input *)
ensures { forall p:pt. List.mem p result -> List.mem p l }
(* the output forms a ccw convex circuit *)
ensures { is_ccw_convex result }
(* all pt of the input are inside the convex hull of the output *)
ensures { forall p:pt. List.mem p l /\ not List.mem p result ->
is_inside_convex_hull p result
}
let min,rem = find_minimum_pt l in
let sorted = sorted_increasing_angle min rem in
match sorted with
......
......@@ -5,6 +5,14 @@
id="0"
name="Alt-Ergo"
version="0.95.1"/>
<prover
id="1"
name="CVC3"
version="2.4.1"/>
<prover
id="2"
name="Z3"
version="4.3.1"/>
<file
name="../convex_hull.mlw"
verified="true"
......@@ -14,29 +22,542 @@
locfile="../convex_hull.mlw"
loclnum="3" loccnumb="7" loccnume="16"
verified="true"
expanded="true">
expanded="false">
<goal
name="knuth1"
locfile="../convex_hull.mlw"
loclnum="17" loccnumb="6" loccnume="12"
sum="04ed37fb14d15689b8a066df0a57727d"
proved="true"
expanded="false"
shape="aturns_leftV1V2V0Iaturns_leftV0V1V2F">
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.10"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.00"/>
</proof>
</goal>
<goal
name="knuth2"
locfile="../convex_hull.mlw"
loclnum="20" loccnumb="6" loccnume="12"
sum="0dcea91acbfb5680952c0303f45224b7"
proved="true"
expanded="false"
shape="Naturns_leftV1V0V2Iaturns_leftV0V1V2F">
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.12"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.03"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.00"/>
</proof>
</goal>
<goal
name="knuth4"
locfile="../convex_hull.mlw"
loclnum="23" loccnumb="6" loccnume="12"
sum="f54bd987811111a578c11d2d4e0a832e"
proved="true"
expanded="false"
shape="aturns_leftV0V1V2Iaturns_leftV2V0V3Iaturns_leftV1V2V3Iaturns_leftV0V1V3F">
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.99"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.18"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.00"/>
</proof>
</goal>
<goal
name="knuth5"
locfile="../convex_hull.mlw"
loclnum="30" loccnumb="6" loccnume="12"
sum="cb81dbb91b1b18b769af30ceb7298504"
proved="true"
expanded="false"
shape="aturns_leftV2V1V4Iaturns_leftV3V1V4Iaturns_leftV2V1V3Iaturns_leftV0V1V4Iaturns_leftV0V1V3Iaturns_leftV0V1V2F">
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="1.08"/>
</proof>
</goal>
<goal
name="knuth3"
locfile="../convex_hull.mlw"
loclnum="39" loccnumb="6" loccnume="12"
sum="47992c815049fd61b202636f29092c3f"
proved="true"
expanded="false"
shape="aturns_leftV0V2V1Oaturns_leftV0V1V2INacolinearV0V1V2F">
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.04"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.00"/>
</proof>
</goal>
<goal
name="test1"
locfile="../convex_hull.mlw"
loclnum="19" loccnumb="5" loccnume="10"
sum="c9d9f8369aae9598819ebfa27b05e177"
loclnum="46" loccnumb="5" loccnume="10"
sum="950b4f9d4c78ea6eb16eb9a4e6945e03"
proved="true"
expanded="true"
expanded="false"
shape="aturns_leftamk ptc0.0c0.0amk ptc1.0c0.0amk ptc1.0c1.0">
<proof
prover="0"
timelimit="60"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.00"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.00"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.00"/>
</proof>
</goal>
</theory>
<theory
name="Incremental"
locfile="../convex_hull.mlw"
loclnum="76" loccnumb="7" loccnume="18"
verified="true"
expanded="true">
</theory>
<theory
name="Jarvis"
locfile="../convex_hull.mlw"
loclnum="83" loccnumb="7" loccnume="13"
verified="true"
expanded="false">
<goal
name="WP_parameter lowest_pt"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="VC for lowest_pt"
sum="0076781f3750e770bb1f378d7788c993"
proved="true"
expanded="false"
shape="ialowerV4V8IamemV8V5Lamk ptV6V7FAainfix =V0aaddV4V5Laremoveamk ptV2V3V0Lamk ptV2V3ialoweramk ptV2V3V13INamemV13V10AamemV13V0Lamk ptV11V12FAasubsetV10V0Aamemamk ptV2V3V0Iainfix =V10aremoveV9V1Faloweramk ptV14V15V19INamemV19V16AamemV19V0Lamk ptV17V18FAasubsetV16V0Aamemamk ptV14V15V0Iainfix =V16aremoveV9V1FIainfix =amk ptV14V15V9FalowerV9amk ptV2V3LachooseV1Nais_emptyV1Ialoweramk ptV2V3V22INamemV22V1AamemV22V0Lamk ptV20V21FAasubsetV1V0Aamemamk ptV2V3V0FAalowerachooseV0V25INamemV25aremoveachooseV0V0AamemV25V0Lamk ptV23V24FAasubsetaremoveachooseV0V0V0AamemachooseV0V0INais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<transf
name="split_goal_wp"
proved="true"
expanded="false">
<goal
name="WP_parameter lowest_pt.1"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="1. loop invariant init"
sum="72f355820178b33eaa32ca60c46de3ec"
proved="true"
expanded="false"
shape="loop invariant initamemachooseV0V0INais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.2"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="2. loop invariant init"
sum="7cf89e2eba94d75bebfdcc1041ae9b5e"
proved="true"
expanded="false"
shape="loop invariant initasubsetaremoveachooseV0V0V0INais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.01"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.3"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="3. loop invariant init"
sum="f6be5cf7f30e61b4af9e41f1d526b0e9"
proved="true"
expanded="false"
shape="loop invariant initalowerachooseV0V3INamemV3aremoveachooseV0V0AamemV3V0Lamk ptV1V2FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.03"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.03"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.4"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="4. loop invariant preservation"
sum="22214a4174c23eeee57e09dd50351d1e"
proved="true"
expanded="false"
shape="loop invariant preservationamemamk ptV5V6V0Iainfix =V7aremoveV4V1FIainfix =amk ptV5V6V4FIalowerV4amk ptV2V3LachooseV1INais_emptyV1Ialoweramk ptV2V3V10INamemV10V1AamemV10V0Lamk ptV8V9FAasubsetV1V0Aamemamk ptV2V3V0FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.03"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.03"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.5"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="5. loop invariant preservation"
sum="e9f6c57504db57c1f8f39e8432706764"
proved="true"
expanded="false"
shape="loop invariant preservationasubsetV7V0Iainfix =V7aremoveV4V1FIainfix =amk ptV5V6V4FIalowerV4amk ptV2V3LachooseV1INais_emptyV1Ialoweramk ptV2V3V10INamemV10V1AamemV10V0Lamk ptV8V9FAasubsetV1V0Aamemamk ptV2V3V0FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.04"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.6"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="6. loop invariant preservation"
sum="69e3f41c31e740ecef0e8c3ea5dcd66a"
proved="true"
expanded="false"
shape="loop invariant preservationaloweramk ptV5V6V10INamemV10V7AamemV10V0Lamk ptV8V9FIainfix =V7aremoveV4V1FIainfix =amk ptV5V6V4FIalowerV4amk ptV2V3LachooseV1INais_emptyV1Ialoweramk ptV2V3V13INamemV13V1AamemV13V0Lamk ptV11V12FAasubsetV1V0Aamemamk ptV2V3V0FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.04"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.07"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.7"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="7. loop invariant preservation"
sum="525fac0e5ca43b38c09a05f3c31032fe"
proved="true"
expanded="false"
shape="loop invariant preservationamemamk ptV2V3V0Iainfix =V5aremoveV4V1FINalowerV4amk ptV2V3LachooseV1INais_emptyV1Ialoweramk ptV2V3V8INamemV8V1AamemV8V0Lamk ptV6V7FAasubsetV1V0Aamemamk ptV2V3V0FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.8"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="8. loop invariant preservation"
sum="73b7396bf0cced28c2ffb4aef6346cb2"
proved="true"
expanded="false"
shape="loop invariant preservationasubsetV5V0Iainfix =V5aremoveV4V1FINalowerV4amk ptV2V3LachooseV1INais_emptyV1Ialoweramk ptV2V3V8INamemV8V1AamemV8V0Lamk ptV6V7FAasubsetV1V0Aamemamk ptV2V3V0FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.9"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="9. loop invariant preservation"
sum="d7a073bffcd54acdf55d147c275db398"
proved="true"
expanded="false"
shape="loop invariant preservationaloweramk ptV2V3V8INamemV8V5AamemV8V0Lamk ptV6V7FIainfix =V5aremoveV4V1FINalowerV4amk ptV2V3LachooseV1INais_emptyV1Ialoweramk ptV2V3V11INamemV11V1AamemV11V0Lamk ptV9V10FAasubsetV1V0Aamemamk ptV2V3V0FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.04"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.03"/>
</proof>
</goal>
<goal
name="WP_parameter lowest_pt.10"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="10. postcondition"
sum="fbd53a936c9610d33f84fe7424d13495"
proved="true"
expanded="false"
shape="postconditionalowerV4V8IamemV8V5Lamk ptV6V7FAainfix =V0aaddV4V5Laremoveamk ptV2V3V0Lamk ptV2V3INNais_emptyV1Ialoweramk ptV2V3V11INamemV11V1AamemV11V0Lamk ptV9V10FAasubsetV1V0Aamemamk ptV2V3V0FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<transf
name="split_goal_wp"
proved="true"
expanded="false">
<goal
name="WP_parameter lowest_pt.10.1"
locfile="../convex_hull.mlw"
loclnum="107" loccnumb="4" loccnume="13"
expl="1. postcondition"
sum="347c0bb9afee98053e46181e2bb0d4dc"
proved="true"
expanded="false"
shape="postconditionainfix =V0aaddV4V5Laremoveamk ptV2V3V0Lamk ptV2V3INNais_emptyV1Ialoweramk ptV2V3V8INamemV8V1AamemV8V0Lamk ptV6V7FAasubsetV1V0Aamemamk ptV2V3V0FINais_emptyV0F">
<label
name="expl:VC for lowest_pt"/>
<proof
prover="0"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.04"/>
</proof>
<proof
prover="1"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>
</proof>
<proof
prover="2"
timelimit="3"
memlimit="1000"
obsolete="false"
archived="false">
<result status="valid" time="0.02"/>