1 (* This file is generated by Why3
's Coq driver *)
2 (* Beware! Only edit allowed sections below *)
3 Require Import BuiltIn.
11 Require set.SetAppInt.
14 Inductive ref (a:Type) :=
15 | ref'mk : a -> ref a.
16 Axiom ref_WhyType : forall (a:Type) {a_WT:WhyType a}, WhyType (ref a).
17 Existing Instance ref_WhyType.
21 Definition contents {a:Type} {a_WT:WhyType a} (v:ref a) : a :=
26 Parameter n: Numbers.BinNums.Z.
29 Definition solution := Numbers.BinNums.Z -> Numbers.BinNums.Z.
32 Definition eq_prefix {a:Type} {a_WT:WhyType a} (t:Numbers.BinNums.Z -> a)
33 (u:Numbers.BinNums.Z -> a) (i:Numbers.BinNums.Z) : Prop :=
34 forall (k:Numbers.BinNums.Z), (0%Z <= k)%Z /\ (k < i)%Z -> ((t k) = (u k)).
37 Definition partial_solution (k:Numbers.BinNums.Z)
38 (s:Numbers.BinNums.Z -> Numbers.BinNums.Z) : Prop :=
39 forall (i:Numbers.BinNums.Z), (0%Z <= i)%Z /\ (i < k)%Z ->
40 ((0%Z <= (s i))%Z /\ ((s i) < n)%Z) /\
41 (forall (j:Numbers.BinNums.Z), (0%Z <= j)%Z /\ (j < i)%Z ->
43 ~ (((s i) - (s j))%Z = (i - j)%Z) /\ ~ (((s i) - (s j))%Z = (j - i)%Z)).
45 Axiom partial_solution_eq_prefix :
46 forall (u:Numbers.BinNums.Z -> Numbers.BinNums.Z)
47 (t:Numbers.BinNums.Z -> Numbers.BinNums.Z) (k:Numbers.BinNums.Z),
48 partial_solution k t -> eq_prefix t u k -> partial_solution k u.
51 Definition lt_sol (s1:Numbers.BinNums.Z -> Numbers.BinNums.Z)
52 (s2:Numbers.BinNums.Z -> Numbers.BinNums.Z) : Prop :=
53 exists i:Numbers.BinNums.Z,
54 ((0%Z <= i)%Z /\ (i < n)%Z) /\ eq_prefix s1 s2 i /\ ((s1 i) < (s2 i))%Z.
57 Definition solutions :=
58 Numbers.BinNums.Z -> Numbers.BinNums.Z -> Numbers.BinNums.Z.
62 (s:Numbers.BinNums.Z -> Numbers.BinNums.Z -> Numbers.BinNums.Z)
63 (a:Numbers.BinNums.Z) (b:Numbers.BinNums.Z) : Prop :=
64 forall (i:Numbers.BinNums.Z) (j:Numbers.BinNums.Z),
65 (a <= i)%Z /\ (i < j)%Z /\ (j < b)%Z -> lt_sol (s i) (s j).
68 forall (s:Numbers.BinNums.Z -> Numbers.BinNums.Z -> Numbers.BinNums.Z)
69 (a:Numbers.BinNums.Z) (b:Numbers.BinNums.Z),
70 sorted s a b -> forall (i:Numbers.BinNums.Z) (j:Numbers.BinNums.Z),
71 (a <= i)%Z /\ (i < j)%Z /\ (j < b)%Z -> ~ eq_prefix (s i) (s j) n.
77 forall (col
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
) (k
:Numbers.BinNums.Z
)
78 (sol
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
-> Numbers.BinNums.Z
)
79 (s
:Numbers.BinNums.Z
),
80 forall (a
:set.SetAppInt.set
) (b
:set.SetAppInt.set
) (c
:set.SetAppInt.set
),
82 ((k
+ (set.Fset.
cardinal (set.SetAppInt.to_fset a
)))%Z
= n
) ->
84 (forall (i
:Numbers.BinNums.Z
),
85 set.Fset.mem
i (set.SetAppInt.to_fset a
) <->
86 ((0%Z
<= i
)%Z
/\
(i
< n
)%Z
) /\
87 (forall (j
:Numbers.BinNums.Z
), (0%Z
<= j
)%Z
/\
(j
< k
)%Z
->
89 (forall (i
:Numbers.BinNums.Z
), (0%Z
<= i
)%Z
->
90 ~ set.Fset.mem
i (set.SetAppInt.to_fset b
) <->
91 (forall (j
:Numbers.BinNums.Z
), (0%Z
<= j
)%Z
/\
(j
< k
)%Z
->
92 ~ ((col j
) = ((i
+ j
)%Z
- k
)%Z
))) ->
93 (forall (i
:Numbers.BinNums.Z
), (0%Z
<= i
)%Z
->
94 ~ set.Fset.mem
i (set.SetAppInt.to_fset c
) <->
95 (forall (j
:Numbers.BinNums.Z
), (0%Z
<= j
)%Z
/\
(j
< k
)%Z
->
96 ~ ((col j
) = ((i
+ k
)%Z
- j
)%Z
))) ->
97 partial_solution k col
-> ~ set.Fset.
is_empty (set.SetAppInt.to_fset a
) ->
98 forall (o
:set.SetAppInt.set
),
99 ((set.SetAppInt.to_fset o
) =
100 (set.Fset.
diff (set.SetAppInt.to_fset a
) (set.SetAppInt.to_fset b
))) ->
101 forall (o1
:set.SetAppInt.set
),
102 ((set.SetAppInt.to_fset o1
) =
103 (set.Fset.
diff (set.SetAppInt.to_fset o
) (set.SetAppInt.to_fset c
))) ->
104 (forall (u
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
),
105 partial_solution n u
/\ eq_prefix col u k
->
106 set.Fset.
mem (u k
) (set.SetAppInt.to_fset o1
)) ->
107 forall (f
:Numbers.BinNums.Z
) (e
:set.SetAppInt.set
) (s1
:Numbers.BinNums.Z
)
108 (sol1
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
-> Numbers.BinNums.Z
)
109 (k1
:Numbers.BinNums.Z
) (col1
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
),
110 (f
= (s1
- s
)%Z
) -> (0%Z
<= (s1
- s
)%Z
)%Z
-> (k1
= k
) ->
111 set.Fset.
subset (set.SetAppInt.to_fset e
)
113 (set.Fset.
diff (set.SetAppInt.to_fset a
) (set.SetAppInt.to_fset b
))
114 (set.SetAppInt.to_fset c
)) ->
115 partial_solution k1 col1
-> sorted sol1 s s1
->
116 (forall (i
:Numbers.BinNums.Z
) (j
:Numbers.BinNums.Z
),
118 (set.Fset.
diff (set.SetAppInt.to_fset o1
) (set.SetAppInt.to_fset e
)) ->
119 set.Fset.mem
j (set.SetAppInt.to_fset e
) -> (i
< j
)%Z
) ->
120 (forall (i
:Numbers.BinNums.Z
), (s
<= i
)%Z
/\
(i
< s1
)%Z
->
121 partial_solution
n (sol1 i
) /\
122 eq_prefix
col1 (sol1 i
) k1
/\
123 set.Fset.
mem (sol1 i k1
)
124 (set.Fset.
diff (set.SetAppInt.to_fset o1
) (set.SetAppInt.to_fset e
))) ->
125 (forall (t
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
),
126 partial_solution n t
/\
127 eq_prefix col1 t k1
/\
129 (set.Fset.
diff (set.SetAppInt.to_fset o1
) (set.SetAppInt.to_fset e
)) ->
130 set.Fset.
mem (t k1
) (set.SetAppInt.to_fset o1
) /\
131 ~ set.Fset.
mem (t k1
) (set.SetAppInt.to_fset e
) /\
132 (exists i
:Numbers.BinNums.Z
,
133 ((s
<= i
)%Z
/\
(i
< s1
)%Z
) /\ eq_prefix
t (sol1 i
) n
)) ->
134 eq_prefix col col1 k1
-> eq_prefix sol sol1 s
->
135 ~ set.Fset.
is_empty (set.SetAppInt.to_fset e
) ->
136 let d
:= set.FsetInt.
min_elt (set.SetAppInt.to_fset e
) in
137 forall (col2
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
),
138 (col2
= (map.Map.set col1 k1 d
)) -> forall (k2
:Numbers.BinNums.Z
),
139 (k2
= (k1
+ 1%Z
)%Z
) -> forall (o2
:set.SetAppInt.set
),
140 ((set.SetAppInt.to_fset o2
) = (set.Fset.add
d (set.SetAppInt.to_fset c
))) ->
141 set.Fset.mem
d (set.SetAppInt.to_fset c
) /\
142 ((set.Fset.
cardinal (set.SetAppInt.to_fset o2
)) =
143 (set.Fset.
cardinal (set.SetAppInt.to_fset c
))) \
/
144 ~ set.Fset.mem
d (set.SetAppInt.to_fset c
) /\
145 ((set.Fset.
cardinal (set.SetAppInt.to_fset o2
)) =
146 ((set.Fset.
cardinal (set.SetAppInt.to_fset c
)) + 1%Z
)%Z
) ->
147 forall (o3
:set.SetAppInt.set
),
148 (forall (i
:Numbers.BinNums.Z
),
149 set.Fset.mem
i (set.SetAppInt.to_fset o3
) <->
150 (0%Z
<= i
)%Z
/\ set.Fset.
mem (i
+ 1%Z
)%Z (set.SetAppInt.to_fset o2
)) ->
151 forall (o4
:set.SetAppInt.set
),
152 ((set.SetAppInt.to_fset o4
) = (set.Fset.add
d (set.SetAppInt.to_fset b
))) ->
153 set.Fset.mem
d (set.SetAppInt.to_fset b
) /\
154 ((set.Fset.
cardinal (set.SetAppInt.to_fset o4
)) =
155 (set.Fset.
cardinal (set.SetAppInt.to_fset b
))) \
/
156 ~ set.Fset.mem
d (set.SetAppInt.to_fset b
) /\
157 ((set.Fset.
cardinal (set.SetAppInt.to_fset o4
)) =
158 ((set.Fset.
cardinal (set.SetAppInt.to_fset b
)) + 1%Z
)%Z
) ->
159 forall (o5
:set.SetAppInt.set
),
160 (forall (i
:Numbers.BinNums.Z
),
161 set.Fset.mem
i (set.SetAppInt.to_fset o5
) <->
162 (1%Z
<= i
)%Z
/\ set.Fset.
mem (i
- 1%Z
)%Z (set.SetAppInt.to_fset o4
)) ->
163 forall (o6
:set.SetAppInt.set
),
164 ((set.SetAppInt.to_fset o6
) =
165 (set.Fset.remove
d (set.SetAppInt.to_fset a
))) ->
166 set.Fset.mem
d (set.SetAppInt.to_fset a
) /\
167 ((set.Fset.
cardinal (set.SetAppInt.to_fset o6
)) =
168 ((set.Fset.
cardinal (set.SetAppInt.to_fset a
)) - 1%Z
)%Z
) \
/
169 ~ set.Fset.mem
d (set.SetAppInt.to_fset a
) /\
170 ((set.Fset.
cardinal (set.SetAppInt.to_fset o6
)) =
171 (set.Fset.
cardinal (set.SetAppInt.to_fset a
))) ->
172 forall (s2
:Numbers.BinNums.Z
)
173 (sol2
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
-> Numbers.BinNums.Z
)
174 (k3
:Numbers.BinNums.Z
) (col3
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
),
175 (0%Z
<= (s2
- s1
)%Z
)%Z
-> (k3
= k2
) -> sorted sol2 s1 s2
->
176 (forall (t
:Numbers.BinNums.Z
-> Numbers.BinNums.Z
),
177 partial_solution n t
/\ eq_prefix col3 t k3
<->
178 (exists i
:Numbers.BinNums.Z
,
179 ((s1
<= i
)%Z
/\
(i
< s2
)%Z
) /\ eq_prefix
t (sol2 i
) n
)) ->
180 eq_prefix col2 col3 k3
-> eq_prefix sol1 sol2 s1
->
181 forall (f1
:Numbers.BinNums.Z
), (f1
= (f
+ (s2
- s1
)%Z
)%Z
) ->
182 forall (k4
:Numbers.BinNums.Z
), (k4
= (k3
- 1%Z
)%Z
) ->
183 forall (e1
:set.SetAppInt.set
),
184 ((set.SetAppInt.to_fset e1
) =
185 (set.Fset.remove
d (set.SetAppInt.to_fset e
))) ->
186 set.Fset.mem
d (set.SetAppInt.to_fset e
) /\
187 ((set.Fset.
cardinal (set.SetAppInt.to_fset e1
)) =
188 ((set.Fset.
cardinal (set.SetAppInt.to_fset e
)) - 1%Z
)%Z
) \
/
189 ~ set.Fset.mem
d (set.SetAppInt.to_fset e
) /\
190 ((set.Fset.
cardinal (set.SetAppInt.to_fset e1
)) =
191 (set.Fset.
cardinal (set.SetAppInt.to_fset e
))) ->
193 (* Why3 intros col k sol s a b c h1 h2 h3 h4 h5 h6 h7 h8 o h9 o1 h10 h11 f e
194 s1 sol1 k1 col1 h12 h13 h14 h15 h16 h17 h18 h19 h20 h21 h22 h23 d
195 col2 h24 k2 h25 o2 h26 h27 o3 h28 o4 h29 h30 o5 h31 o6 h32 h33 s2
196 sol2 k3 col3 h34 h35 h36 h37 h38 h39 f1 h40 k4 h41 e1 h42 h43.
*)
198 intros col k sol s a b c h1 h2 h3 h4 h5 h6 h7 h8 o h9 o1 h10 h11 f e
199 s1 sol1 k1 col1 h12 h13 h14 h15 h16 h17 h18 h19 h20 h21 h22 h23 d
200 col2 h24 k2 h25 o2 h26 h27 o3 h28 o4 h29 h30 o5 h31 o6 h32 h33 s2
201 sol2 k3 col3 h34 h35 h36 h37 h38 h39 f1 h40 k4 h41 e1 h42 h43.
203 assert (case: (j
< s1 \
/ s1
<= j
)%Z
) by lia. destruct
case.
204 do
2 (rewrite
<- h39
; try lia
).
206 assert (case: (s1
<= i \
/ i
< s1
)%Z
) by lia. destruct
case.
208 (* s1
<= i
< s2
<= j
< s3
*)
210 subst k1.
(* rename k1 into k.
*)
212 generalize (Fset.
cardinal_nonneg (SetAppInt.to_fset a
)).
213 generalize (Fset.
cardinal_empty (SetAppInt.to_fset a
)).
215 assert (case: (Fset.
cardinal (SetAppInt.to_fset a
) = 0 \
/
216 Fset.
cardinal (SetAppInt.to_fset a
) > 0)%Z
) by lia. destruct
case.
217 absurd (Fset.
is_empty (SetAppInt.to_fset a
)). auto. intuition.
220 assert (ha
: eq_prefix
col1 (sol1 i
) k
/\
221 Fset.
mem (sol1 i k
) (Fset.
diff (SetAppInt.to_fset o1
) (SetAppInt.to_fset e
))).
224 destruct ha
as (ha
,hb
).
226 destruct (h37 (sol2 j
)) as (_
,hj
).
237 rewrite
<- h39
; try lia.
240 rewrite
<- H3
; try lia.
241 rewrite
<- h38
; try lia.
243 generalize (Map.set
'def col1 k d l
).
248 (* s
[i
][k
] < s
[j
][k
] *)
250 rewrite
<- h39
; try lia.
252 rewrite
<- H3
; try lia.
253 rewrite
<- h38
; try lia.
255 generalize (Map.set
'def col1 k d k
).
258 generalize (set.FsetInt.
min_elt_def (SetAppInt.to_fset e
)); intuition.