Commit ebcdf083 authored by Andrei Paskevich's avatar Andrei Paskevich

whyml: require all raised exceptions to be listed

also, require to list all write/read effects whenever
at least one is listed

fix hashtbl_impl, mergesort_queue, and unraveling_a_card_trick
parent 1245c8f7
......@@ -10,6 +10,19 @@ version 0.81, March ??, 2013
o [prover] support for CVC4
o [prover] support for mathematica
o [prover] support for MathSAT5
o [logic] accept type expressions in clone substitutions
o [whyml] support for relation chains (e.g., "e1 = e2 < e3")
* [whyml] every exception raised in a function must be listed
in as "raises { ... }" clause. A postcondition may be omitted
and equals to "true" by default.
* [whyml] if a function definition contains a "writes { ... }"
clause, then every write effect must be listed. If a function
definition contains a "reads { ... }" clause, then every read
_and_ write effect must be listed.
* [drivers] syntax rules, metas, and preludes are inherited
through cloning. Keyword "cloned" becomes unnecessary and
is not accepted anymore.
version 0.80, Oct 31, 2012
==========================
......
......@@ -94,8 +94,7 @@ module HashtblImpl
| None -> forall v: 'a. not (mem (k, v) l)
| Some v -> mem (k, v) l
end }
=
match l with
= match l with
| Nil -> None
| Cons (k', v) r -> if k = k' then Some v else list_find k r
end
......@@ -109,9 +108,8 @@ module HashtblImpl
let rec list_remove (k: key) (l: list (key, 'a)) : list (key, 'a)
variant { l }
ensures { forall k': key, v: 'a.
mem (k',v) result <-> mem (k',v) l /\ k' <> k }
=
match l with
mem (k',v) result <-> mem (k',v) l /\ k' <> k }
= match l with
| Nil -> Nil
| Cons ((k', _) as p) r ->
if k = k' then list_remove k r else Cons p (list_remove k r)
......@@ -121,9 +119,8 @@ module HashtblImpl
writes { h.data.elts, h.view, h.size }
ensures { Map.get h.view k = None }
ensures { forall k': key. k' <> k ->
Map.get h.view k' = Map.get (old h.view) k' }
=
let i = bucket k (length h.data) in
Map.get h.view k' = Map.get (old h.view) k' }
= let i = bucket k (length h.data) in
let l = h.data[i] in
match list_find k l with
| None ->
......@@ -135,12 +132,12 @@ module HashtblImpl
end
let add (h: t 'a) (k: key) (v: 'a) : unit
writes { h.data.elts, h.view, h.size }
writes { h, h.data.elts }
ensures { Map.get h.view k = Some v }
ensures { forall k': key. k' <> k ->
Map.get h.view k' = Map.get (old h.view) k' }
Map.get h.view k' = Map.get (old h.view) k' }
=
abstract if h.size = length h.data then resize h;
abstract (if h.size = length h.data then resize h);
remove h k;
let i = bucket k (length h.data) in
h.data[i] <- Cons (k, v) h.data[i];
......
......@@ -849,7 +849,7 @@
<goal
name="WP_parameter find"
locfile="../hashtbl_impl.mlw"
loclnum="103" loccnumb="6" loccnume="10"
loclnum="102" loccnumb="6" loccnume="10"
expl="VC for find"
sum="6aef7b0de2137003bc799cdaf8ba7c70"
proved="true"
......@@ -864,7 +864,7 @@
<goal
name="WP_parameter find.1"
locfile="../hashtbl_impl.mlw"
loclnum="103" loccnumb="6" loccnume="10"
loclnum="102" loccnumb="6" loccnume="10"
expl="1. precondition"
sum="78badfe134698557511bf18d87fd08a4"
proved="true"
......@@ -884,7 +884,7 @@
<goal
name="WP_parameter find.2"
locfile="../hashtbl_impl.mlw"
loclnum="103" loccnumb="6" loccnume="10"
loclnum="102" loccnumb="6" loccnume="10"
expl="2. postcondition"
sum="94a19ed52328768f01cb67595780f35d"
proved="true"
......@@ -907,7 +907,7 @@
<goal
name="WP_parameter list_remove"
locfile="../hashtbl_impl.mlw"
loclnum="109" loccnumb="10" loccnume="21"
loclnum="108" loccnumb="10" loccnume="21"
expl="VC for list_remove"
sum="e00c5a61c8e3d7d73df35dd58978bf0f"
proved="true"
......@@ -922,7 +922,7 @@
<goal
name="WP_parameter list_remove.1"
locfile="../hashtbl_impl.mlw"
loclnum="109" loccnumb="10" loccnume="21"
loclnum="108" loccnumb="10" loccnume="21"
expl="1. postcondition"
sum="3ba2f529ed3b1dbaf142c81f79e81217"
proved="true"
......@@ -942,7 +942,7 @@
<goal
name="WP_parameter list_remove.2"
locfile="../hashtbl_impl.mlw"
loclnum="109" loccnumb="10" loccnume="21"
loclnum="108" loccnumb="10" loccnume="21"
expl="2. variant decrease"
sum="b90c0f3bff7af69cc7c9032559a977b9"
proved="true"
......@@ -962,7 +962,7 @@
<goal
name="WP_parameter list_remove.3"
locfile="../hashtbl_impl.mlw"
loclnum="109" loccnumb="10" loccnume="21"
loclnum="108" loccnumb="10" loccnume="21"
expl="3. postcondition"
sum="435b0c6b8f8c09dd3f987fb0ebb8b084"
proved="true"
......@@ -982,7 +982,7 @@
<goal
name="WP_parameter list_remove.4"
locfile="../hashtbl_impl.mlw"
loclnum="109" loccnumb="10" loccnume="21"
loclnum="108" loccnumb="10" loccnume="21"
expl="4. variant decrease"
sum="0c9789366e195e920d894c8bbc646d2e"
proved="true"
......@@ -1002,7 +1002,7 @@
<goal
name="WP_parameter list_remove.5"
locfile="../hashtbl_impl.mlw"
loclnum="109" loccnumb="10" loccnume="21"
loclnum="108" loccnumb="10" loccnume="21"
expl="5. postcondition"
sum="c8e6aa8abe7867533c639a8fa59a5876"
proved="true"
......@@ -1024,7 +1024,7 @@
<goal
name="WP_parameter remove"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="VC for remove"
sum="fd864153f60a7406a705b595503777ba"
proved="true"
......@@ -1039,7 +1039,7 @@
<goal
name="WP_parameter remove.1"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="1. precondition"
sum="cc3d49325272107a8b9934744e6fa365"
proved="true"
......@@ -1075,7 +1075,7 @@
<goal
name="WP_parameter remove.2"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="2. postcondition"
sum="242132218ad6ee0f1a57842e94557a48"
proved="true"
......@@ -1096,7 +1096,7 @@
<goal
name="WP_parameter remove.3"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="3. postcondition"
sum="010e23a6d9c4d7bb162b2ddf4b676656"
proved="true"
......@@ -1116,7 +1116,7 @@
<goal
name="WP_parameter remove.4"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="4. precondition"
sum="b08f4cc9355b0492779e73624caa0bae"
proved="true"
......@@ -1152,7 +1152,7 @@
<goal
name="WP_parameter remove.5"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="5. type invariant"
sum="cd84fa08461a7c68a23623930c2b6bbc"
proved="true"
......@@ -1188,7 +1188,7 @@
<goal
name="WP_parameter remove.6"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="6. type invariant"
sum="2be4baff808000d9a64f0202caec3ff0"
proved="true"
......@@ -1203,7 +1203,7 @@
<goal
name="WP_parameter remove.6.1"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="1. type invariant"
sum="42418c6de3a295df7599f060b6279481"
proved="true"
......@@ -1225,7 +1225,7 @@
<goal
name="WP_parameter remove.7"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="7. type invariant"
sum="0dcb6d53b8ef99774eb74bc333db2950"
proved="true"
......@@ -1240,7 +1240,7 @@
<goal
name="WP_parameter remove.7.1"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="1. type invariant"
sum="48348cd89a0c48b84682afd1c72ca528"
proved="true"
......@@ -1262,7 +1262,7 @@
<goal
name="WP_parameter remove.8"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="8. type invariant"
sum="ec711b648e9bf91015ef04d77eb25efe"
proved="true"
......@@ -1298,7 +1298,7 @@
<goal
name="WP_parameter remove.9"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="9. postcondition"
sum="4d6df5ceaa5f24306977edbc48b63eaf"
proved="true"
......@@ -1334,7 +1334,7 @@
<goal
name="WP_parameter remove.10"
locfile="../hashtbl_impl.mlw"
loclnum="120" loccnumb="6" loccnume="12"
loclnum="118" loccnumb="6" loccnume="12"
expl="10. postcondition"
sum="53ff39cfc5b38ac00611311aaa93ec44"
proved="true"
......@@ -1356,7 +1356,7 @@
<goal
name="WP_parameter add"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="VC for add"
sum="5e773205ee8042e7a48ce2cd11636201"
proved="true"
......@@ -1371,7 +1371,7 @@
<goal
name="WP_parameter add.1"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="1. precondition"
sum="666b9b3ab7dab7f24fd65ccd1cc9cc2a"
proved="true"
......@@ -1399,7 +1399,7 @@
<goal
name="WP_parameter add.2"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="2. precondition"
sum="15b98a3f37e742015452c754ba38e2e1"
proved="true"
......@@ -1427,7 +1427,7 @@
<goal
name="WP_parameter add.3"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="3. type invariant"
sum="430783c03c3e4b5fbd0f204d037d857f"
proved="true"
......@@ -1455,11 +1455,11 @@
<goal
name="WP_parameter add.4"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="4. type invariant"
sum="f9271cb2da0e8c150fc0e52bbb6e6b4e"
proved="true"
expanded="true"
expanded="false"
shape="agood_hashamk arrayV5V10V13Iainfix &lt;V13V5Aainfix &lt;=c0V13FIainfix =V12asetV7V0aSomeV1FIainfix =V11ainfix +V9c1FIainfix =V10asetV8abucketV0V5aConsaTuple2V0V1agetV8abucketV0V5Aainfix &lt;=c0V5FIainfix &lt;abucketV0V5V5Aainfix &lt;=c0abucketV0V5Iainfix &lt;abucketV0V5V5Aainfix &lt;=c0abucketV0V5Iainfix =agetV7V14agetV2V14Iainfix =V14V0NFAainfix =agetV7V0aNoneAainfix &lt;=c0V5Aagood_dataV15V16V7amk arrayV5V8FAagood_hashamk arrayV5V8V17Iainfix &lt;V17V5Aainfix &lt;=c0V17FAainfix &lt;c0V5FIainfix &lt;=c0V5Aagood_dataV18V19V2amk arrayV5V6FAagood_hashamk arrayV5V6V20Iainfix &lt;V20V5Aainfix &lt;=c0V20FAainfix &lt;c0V5FIainfix &lt;=c0V3Aagood_dataV21V22V2amk arrayV3V4FAagood_hashamk arrayV3V4V23Iainfix &lt;V23V3Aainfix &lt;=c0V23FAainfix &lt;c0V3FF">
<label
name="expl:VC for add"/>
......@@ -1476,7 +1476,7 @@
<goal
name="WP_parameter add.5"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="5. type invariant"
sum="f8c0fe7b7f7e09146102c04e89414436"
proved="true"
......@@ -1491,7 +1491,7 @@
<goal
name="WP_parameter add.5.1"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="1. type invariant"
sum="ed72a448e60a0d009d3cc9e938613982"
proved="true"
......@@ -1506,7 +1506,7 @@
<goal
name="WP_parameter add.5.1.1"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="1. type invariant"
sum="e02543ad4e7121e2b81a1e14756a4745"
proved="true"
......@@ -1526,7 +1526,7 @@
<goal
name="WP_parameter add.5.1.2"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="2. type invariant"
sum="93fa4a4153a4999f4be6da8d2a2976c0"
proved="true"
......@@ -1550,7 +1550,7 @@
<goal
name="WP_parameter add.6"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="6. type invariant"
sum="141bb36c0c7d0d52e5110d046a5fcb0a"
proved="true"
......@@ -1578,7 +1578,7 @@
<goal
name="WP_parameter add.7"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="7. postcondition"
sum="4a8a1ff4cadd693cef1624e070b87343"
proved="true"
......@@ -1593,7 +1593,7 @@
<goal
name="WP_parameter add.7.1"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="1. postcondition"
sum="858f6ad637571ed4f17f97b80c1c00de"
proved="true"
......@@ -1615,7 +1615,7 @@
<goal
name="WP_parameter add.8"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="8. postcondition"
sum="d8123c8d02d5c24fc8cddc76134b337a"
proved="true"
......@@ -1630,7 +1630,7 @@
<goal
name="WP_parameter add.8.1"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="1. postcondition"
sum="2d8840a55677b5d5091921c8b6fc695d"
proved="true"
......@@ -1645,7 +1645,7 @@
<goal
name="WP_parameter add.8.1.1"
locfile="../hashtbl_impl.mlw"
loclnum="137" loccnumb="6" loccnume="9"
loclnum="134" loccnumb="6" loccnume="9"
expl="1. postcondition"
sum="1911c53aa245c12cbb7de6454bc659b0"
proved="true"
......
......@@ -24,15 +24,18 @@ module MergesortQueue
while length q1 > 0 || length q2 > 0 do
invariant { permut (q.elts ++ q1.elts ++ q2.elts)
(at q1.elts 'L ++ at q2.elts 'L) }
variant { length q1.elts + length q2.elts }
variant { length q1 + length q2 }
if length q1 = 0 then
push (pop q2) q
push (safe_pop q2) q
else if length q2 = 0 then
push (pop q1) q
push (safe_pop q1) q
else
let x1 = peek q1 in
let x2 = peek q2 in
if le x1 x2 then push (pop q1) q else push (pop q2) q
let x1 = safe_peek q1 in
let x2 = safe_peek q2 in
if le x1 x2 then
push (safe_pop q1) q
else
push (safe_pop q2) q
done
(*
......
......@@ -64,86 +64,63 @@ Axiom mem_decomp : forall {a:Type} {a_WT:WhyType a}, forall (x:a) (l:(list
a)), (mem x l) -> exists l1:(list a), exists l2:(list a),
(l = (infix_plpl l1 (Cons x l2))).
(* Why3 assumption *)
Fixpoint reverse {a:Type} {a_WT:WhyType a} (l:(list a)) {struct l}: (list
a) :=
Parameter num_occ: forall {a:Type} {a_WT:WhyType a}, a -> (list a) -> Z.
Axiom num_occ_def : forall {a:Type} {a_WT:WhyType a}, forall (x:a) (l:(list
a)),
match l with
| Nil => (Nil :(list a))
| (Cons x r) => (infix_plpl (reverse r) (Cons x (Nil :(list a))))
| Nil => ((num_occ x l) = 0%Z)
| (Cons y r) => ((x = y) -> ((num_occ x l) = (1%Z + (num_occ x r))%Z)) /\
((~ (x = y)) -> ((num_occ x l) = (0%Z + (num_occ x r))%Z))
end.
Axiom reverse_append : forall {a:Type} {a_WT:WhyType a}, forall (l1:(list a))
(l2:(list a)) (x:a), ((infix_plpl (reverse (Cons x l1))
l2) = (infix_plpl (reverse l1) (Cons x l2))).
Axiom reverse_reverse : forall {a:Type} {a_WT:WhyType a}, forall (l:(list
a)), ((reverse (reverse l)) = l).
Axiom Mem_Num_Occ : forall {a:Type} {a_WT:WhyType a}, forall (x:a) (l:(list
a)), (mem x l) <-> (0%Z < (num_occ x l))%Z.
Axiom Reverse_length : forall {a:Type} {a_WT:WhyType a}, forall (l:(list a)),
((length (reverse l)) = (length l)).
Axiom Append_Num_Occ : forall {a:Type} {a_WT:WhyType a}, forall (x:a)
(l1:(list a)) (l2:(list a)), ((num_occ x (infix_plpl l1 l2)) = ((num_occ x
l1) + (num_occ x l2))%Z).
(* Why3 assumption *)
Inductive option
(a:Type) {a_WT:WhyType a} :=
| None : option a
| Some : a -> option a.
Axiom option_WhyType : forall (a:Type) {a_WT:WhyType a}, WhyType (option a).
Existing Instance option_WhyType.
Implicit Arguments None [[a] [a_WT]].
Implicit Arguments Some [[a] [a_WT]].
Definition permut {a:Type} {a_WT:WhyType a} (l1:(list a)) (l2:(list
a)): Prop := forall (x:a), ((num_occ x l1) = (num_occ x l2)).
Parameter nth: forall {a:Type} {a_WT:WhyType a}, Z -> (list a) -> (option a).
Axiom Permut_refl : forall {a:Type} {a_WT:WhyType a}, forall (l:(list a)),
(permut l l).
Axiom nth_def : forall {a:Type} {a_WT:WhyType a}, forall (n:Z) (l:(list a)),
match l with
| Nil => ((nth n l) = (None :(option a)))
| (Cons x r) => ((n = 0%Z) -> ((nth n l) = (Some x))) /\ ((~ (n = 0%Z)) ->
((nth n l) = (nth (n - 1%Z)%Z r)))
end.
Axiom Permut_sym : forall {a:Type} {a_WT:WhyType a}, forall (l1:(list a))
(l2:(list a)), (permut l1 l2) -> (permut l2 l1).
Parameter m: Z.
Axiom Permut_trans : forall {a:Type} {a_WT:WhyType a}, forall (l1:(list a))
(l2:(list a)) (l3:(list a)), (permut l1 l2) -> ((permut l2 l3) -> (permut
l1 l3)).
Axiom m_positive : (0%Z < m)%Z.
Axiom Permut_cons : forall {a:Type} {a_WT:WhyType a}, forall (x:a) (l1:(list
a)) (l2:(list a)), (permut l1 l2) -> (permut (Cons x l1) (Cons x l2)).
Parameter n: Z.
Axiom Permut_swap : forall {a:Type} {a_WT:WhyType a}, forall (x:a) (y:a)
(l:(list a)), (permut (Cons x (Cons y l)) (Cons y (Cons x l))).
Axiom n_nonnegative : (0%Z <= n)%Z.
Axiom Permut_cons_append : forall {a:Type} {a_WT:WhyType a}, forall (x:a)
(l1:(list a)) (l2:(list a)), (permut (infix_plpl (Cons x l1) l2)
(infix_plpl l1 (Cons x l2))).
(* Why3 assumption *)
Inductive shuffle{a:Type} {a_WT:WhyType a} : (list a) -> (list a) -> (list
a) -> Prop :=
| Shuffle_nil_left : forall (l:(list a)), (shuffle l (Nil :(list a)) l)
| Shuffle_nil_right : forall (l:(list a)), (shuffle (Nil :(list a)) l l)
| Shuffle_cons_left : forall (x:a) (a1:(list a)) (b:(list a)) (c:(list a)),
(shuffle a1 b c) -> (shuffle (Cons x a1) b (Cons x c))
| Shuffle_cons_right : forall (x:a) (a1:(list a)) (b:(list a)) (c:(list
a)), (shuffle a1 b c) -> (shuffle a1 (Cons x b) (Cons x c)).
Axiom Permut_assoc : forall {a:Type} {a_WT:WhyType a}, forall (l1:(list a))
(l2:(list a)) (l3:(list a)), (permut (infix_plpl (infix_plpl l1 l2) l3)
(infix_plpl l1 (infix_plpl l2 l3))).
Axiom shuffle_nil_nil_nil : forall {a:Type} {a_WT:WhyType a}, (shuffle
(Nil :(list a)) (Nil :(list a)) (Nil :(list a))).
Axiom Permut_append : forall {a:Type} {a_WT:WhyType a}, forall (l1:(list a))
(l2:(list a)) (k1:(list a)) (k2:(list a)), (permut l1 k1) -> ((permut l2
k2) -> (permut (infix_plpl l1 l2) (infix_plpl k1 k2))).
Axiom shuffle_sym : forall {a:Type} {a_WT:WhyType a}, forall (a1:(list a))
(b:(list a)) (c:(list a)), (shuffle a1 b c) -> (shuffle b a1 c).
Axiom Permut_append_swap : forall {a:Type} {a_WT:WhyType a}, forall (l1:(list
a)) (l2:(list a)), (permut (infix_plpl l1 l2) (infix_plpl l2 l1)).
Axiom shuffle_length : forall {a:Type} {a_WT:WhyType a}, forall (a1:(list a))
(b:(list a)) (c:(list a)), (shuffle a1 b c) ->
(((length a1) + (length b))%Z = (length c)).
Axiom Permut_mem : forall {a:Type} {a_WT:WhyType a}, forall (x:a) (l1:(list
a)) (l2:(list a)), (permut l1 l2) -> ((mem x l1) -> (mem x l2)).
(* Why3 assumption *)
Definition suit_ordered (l:(list Z)): Prop := forall (i:Z) (j:Z),
((0%Z <= i)%Z /\ (i < n)%Z) -> (((0%Z <= j)%Z /\ (j < m)%Z) ->
((nth ((i * m)%Z + j)%Z l) = (Some j))).
(* Why3 assumption *)
Definition suit_sorted (l:(list Z)): Prop := (forall (i:Z) (v:Z), ((nth i
l) = (Some v)) -> ((0%Z <= v)%Z /\ (v < m)%Z)) /\ forall (i:Z) (j1:Z)
(j2:Z), ((0%Z <= i)%Z /\ (i < n)%Z) -> (((0%Z <= j1)%Z /\ (j1 < m)%Z) ->
(((0%Z <= j2)%Z /\ (j2 < m)%Z) -> ~ ((nth ((i * m)%Z + j1)%Z
l) = (nth ((i * m)%Z + j2)%Z l)))).
Axiom gilbreath_card_trick : forall (a:(list Z)), ((length a) = (n * m)%Z) ->
((suit_ordered a) -> forall (c:(list Z)) (d:(list Z)), (a = (infix_plpl c
d)) -> forall (b:(list Z)), (shuffle c (reverse d) b) -> (suit_sorted b)).
Axiom Permut_length : forall {a:Type} {a_WT:WhyType a}, forall (l1:(list a))
(l2:(list a)), (permut l1 l2) -> ((length l1) = (length l2)).
(* Why3 assumption *)
Inductive t (a:Type) {a_WT:WhyType a} :=
......@@ -159,31 +136,65 @@ Definition elts {a:Type} {a_WT:WhyType a} (v:(t a)): (list a) :=
end.
(* Why3 assumption *)
Definition length1 {a:Type} {a_WT:WhyType a} (s:(t a)): Z :=
(length (elts s)).
Definition length1 {a:Type} {a_WT:WhyType a} (q:(t a)): Z :=
(length (elts q)).
Axiom elt : Type.
Parameter elt_WhyType : WhyType elt.
Existing Instance elt_WhyType.
Parameter le: elt -> elt -> Prop.
Require Import Why3.
Axiom total_preorder1 : forall (x:elt) (y:elt), (le x y) \/ (le y x).
Axiom total_preorder2 : forall (x:elt) (y:elt) (z:elt), (le x y) -> ((le y
z) -> (le x z)).
(* Why3 assumption *)
Inductive sorted : (list elt) -> Prop :=
| Sorted_Nil : (sorted (Nil :(list elt)))
| Sorted_One : forall (x:elt), (sorted (Cons x (Nil :(list elt))))
| Sorted_Two : forall (x:elt) (y:elt) (l:(list elt)), (le x y) -> ((sorted
(Cons y l)) -> (sorted (Cons x (Cons y l)))).
Axiom sorted_mem : forall (x:elt) (l:(list elt)), ((forall (y:elt), (mem y
l) -> (le x y)) /\ (sorted l)) <-> (sorted (Cons x l)).
(* Why3 goal *)
Theorem WP_parameter_shuffle : forall (b:(list Z)) (a:(list Z)),
forall (c:(list Z)), (c = (Nil :(list Z))) -> forall (c1:(list Z))
(b1:(list Z)) (a1:(list Z)), (exists a':(list Z), (exists b':(list Z),
((reverse a) = (infix_plpl (reverse a1) a')) /\
(((reverse b) = (infix_plpl (reverse b1) b')) /\ (shuffle a' b' c1)))) ->
forall (result:bool), ((result = true) <-> (a1 = (Nil :(list Z)))) ->
((~ (result = true)) -> forall (o:bool), ((o = true) <-> (a1 = (Nil :(list
Z)))) -> ((~ (o = true)) -> forall (result1:bool), ((result1 = true) <->
(b1 = (Nil :(list Z)))) -> ((result1 = true) -> forall (a2:(list Z)),
forall (o1:Z),