Debian Codegraph @

test-suite/success/destruct.v

raw
1 (* Submitted by Robert Schneck *)
2
3 Parameters A B C D : Prop.
4 Axiom X : A -> B -> C /\ D.
5
6 Lemma foo : A -> B -> C.
7 Proof.
8 intros.
9 destruct X. (* Should find axiom X and should handle arguments of X *)
10 assumption.
11 assumption.
12 assumption.
13 Qed.
14
15 (* Simplification of BZ#711 *)
16
17 Parameter f : true = false.
18 Goal let p := f in True.
19 intro p.
20 set (b := true) in *.
21 (* Check that it doesn't fail with an anomaly *)
22 (* Ultimately, adapt destruct to make it succeeding *)
23 try destruct b.
24 Abort.
25
26 (* Used to fail with error "n is used in conclusion" before revision 9447 *)
27
28 Goal forall n, n = S n.
29 induction S.
30 Abort.
31
32 (* Check that elimination with remaining evars do not raise an bad
33 error message *)
34
35 Theorem Refl : forall P, P <-> P. tauto. Qed.
36 Goal True.
37 case Refl || ecase Refl.
38 Abort.
39
40 (* Submitted by B. Baydemir (BZ#1882) *)
41
42 Definition alist R := list (nat * R)%type.
43
44 Section Properties.
45 Variable A : Type.
46 Variable a : A.
47 Variable E : alist A.
48
49 Lemma silly : E = E.
50 Proof.
51 clear. induction E. (* this fails. *)
52 Abort.
53
54 End Properties.
55
56 (* This used not to work before revision 11944 *)
57
58 Goal forall P:(forall n, 0=n -> Prop), forall H: 0=0, P 0 H.
59 destruct H.
60 Abort.
61
62 (* The calls to "destruct" below did not work before revision 12356 *)
63
64 Parameter A0:Type.
65 Parameter P:A0->Type.
66 Require Import TestSuite.jmeq.
67 Goal forall a b (p:P a) (q:P b),
68 forall H:a = b, eq_rect a P p b H = q -> JMeq (existT _ a p) (existT _ b q).
69 intros.
70 destruct H.
71 destruct H0.
72 reflexivity.
73 Qed.
74
75 (* These did not work before 8.4 *)
76
77 Goal (exists x, x=0) -> True.
78 destruct 1 as (_,_); exact I.
79 Abort.
80
81 Goal (exists x, x=0 /\ True) -> True.
82 destruct 1 as (_,(_,H)); exact H.
83 Abort.
84
85 Goal (exists x, x=0 /\ True) -> True.
86 destruct 1 as (_,(_,x)); exact x.
87 Abort.
88
89 Goal let T:=nat in forall (x:nat) (g:T -> nat), g x = 0.
90 intros.
91 destruct (g _). (* This was failing in at least r14571 *)
92 Abort.
93
94 (* Check that subterm selection does not solve existing evars *)
95
96 Goal exists x, S x = S 0.
97 eexists ?[x].
98 Show x. (* Incidentally test Show on a named goal *)
99 destruct (S _). (* Incompatible occurrences but takes the first one since Oct 2014 *)
100 change (0 = S 0).
101 Abort.
102
103 Goal exists x, S 0 = S x.
104 eexists ?[x].
105 destruct (S _). (* Incompatible occurrences but takes the first one since Oct 2014 *)
106 change (0 = S ?x).
107 [x]: exact 0. (* Incidentally test applying a tactic to a goal on the shelve *)
108 Abort.
109
110 Goal exists n p:nat, (S n,S n) = (S p,S p) /\ p = n.
111 eexists ?[n]; eexists ?[p].
112 destruct (_, S _). (* Was unifying at some time in trunk, now takes the first occurrence *)
113 change ((n, n0) = (S ?p, S ?p) /\ ?p = ?n).
114 Abort.
115
116 (* An example with incompatible but convertible occurrences *)
117
118 Goal id (id 0) = 0.
119 Fail destruct (id _) at 1 2.
120 Abort.
121
122 (* Avoid unnatural selection of a subterm larger than expected *)
123
124 Goal let g := fun x:nat => x in g (S 0) = 0.
125 intro.
126 destruct S.
127 (* Check that it is not the larger subterm "g (S 0)" which is
128 selected, as it was the case in 8.4 *)
129 unfold g at 1.
130 Abort.
131
132 (* Some tricky examples convenient to support *)
133
134 Goal forall x, nat_rect (fun _ => nat) O (fun x y => S x) x = nat_rect (fun _ => nat) O (fun x y => S x) x.
135 intros.
136 destruct (nat_rect _ _ _ _).
137 Abort.
138 (* Check compatibility in selecting what is open or "shelved" *)
139
140 Goal (forall x, x=0 -> nat) -> True.
141 intros.
142 Fail destruct H.
143 edestruct H.
144 - reflexivity.
145 - exact Logic.I.
146 - exact Logic.I.
147 Qed.
148
149 (* Check an example which was working with case/elim in 8.4 but not with
150 destruct/induction *)
151
152 Goal forall x, (True -> x = 0) -> 0=0.
153 intros.
154 destruct H.
155 - trivial.
156 - apply (eq_refl x).
157 Qed.
158
159 (* Check an example which was working with case/elim in 8.4 but not with
160 destruct/induction (not the different order between induction/destruct) *)
161
162 Goal forall x, (True -> x = 0) -> 0=0.
163 intros.
164 induction H.
165 - apply (eq_refl x).
166 - trivial.
167 Qed.
168
169 (* This test assumes that destruct/induction on non-dependent hypotheses behave the same
170 when using holes or not
171
172 Goal forall x, (True -> x = 0) -> 0=0.
173 intros.
174 destruct (H _).
175 - apply I.
176 - apply (eq_refl x).
177 Qed.
178 *)
179
180 (* Check destruct vs edestruct *)
181
182 Goal forall x, (forall y, y = 0 -> x = 0) -> 0=0.
183 intros.
184 Fail destruct H.
185 edestruct H.
186 - trivial.
187 - apply (eq_refl x).
188 Qed.
189
190 Goal forall x, (forall y, y = 0 -> x = 0) -> 0=0.
191 intros.
192 Fail destruct (H _ _).
193 (* Now a test which assumes that edestruct on non-dependent
194 hypotheses accept unresolved subterms in the induction argument.
195 edestruct (H _ _).
196 - trivial.
197 - apply (eq_refl x).
198 Qed.
199 *)
200 Abort.
201
202 (* Test selection when not in an inductive type *)
203 Parameter T:Type.
204 Axiom elim: forall P, T -> P.
205 Goal forall a:T, a = a.
206 induction a using elim.
207 Qed.
208
209 Goal forall a:nat -> T, a 0 = a 1.
210 intro a.
211 induction (a 0) using elim.
212 Qed.
213
214 (* From Oct 2014, a subterm is found, as if without "using"; in 8.4,
215 it did not find a subterm *)
216
217 Goal forall a:nat -> T, a 0 = a 1.
218 intro a.
219 induction a using elim.
220 Qed.
221
222 Goal forall a:nat -> T, forall b, a 0 = b.
223 intros a b.
224 induction a using elim.
225 Qed.
226
227 (* From Oct 2014, first subterm is found; in 8.4, it failed because it
228 found "a 0" and wanted to clear a *)
229
230 Goal forall a:nat -> nat, a 0 = a 1.
231 intro a.
232 destruct a.
233 change (0 = a 1).
234 Abort.
235
236 (* This example of a variable not fully applied in the goal was working in 8.4*)
237
238 Goal forall H : 0<>0, H = H.
239 destruct H.
240 reflexivity.
241 Qed.
242
243 (* Check that variables not fully applied in the goal are not erased
244 (this example was failing in 8.4 because of a forbidden "clear H" in
245 the code of "destruct H" *)
246
247 Goal forall H : True -> True, H = H.
248 destruct H.
249 - exact I.
250 - reflexivity.
251 Qed.
252
253 (* Check destruct on idents with maximal implicit arguments - which did
254 not work in 8.4 *)
255
256 Parameter g : forall {n:nat}, n=n -> nat.
257 Goal g (eq_refl 0) = 0.
258 destruct g.
259 Abort.
260
261 (* This one was working in 8.4 (because of full conv on closed arguments) *)
262
263 Class E.
264 #[export] Instance a:E := {}.
265 Goal forall h : E -> nat -> nat, h (id a) 0 = h a 0.
266 intros.
267 destruct (h _).
268 change (0=0).
269 Abort.
270
271 (* This one was not working in 8.4 because an occurrence of f was
272 remaining, blocking the "clear f" *)
273
274 Goal forall h : E -> nat -> nat, h a 0 = h a 1.
275 intros.
276 destruct h.
277 Abort.
278
279 (* This was not working in 8.4 *)
280
281 Section S1.
282 Variables x y : Type.
283 Variable H : x = y.
284 Goal True.
285 destruct H. (* Was not working in 8.4 *)
286 (* Now check that H statement has itself be subject of the rewriting *)
287 change (x=x) in H.
288 Abort.
289 End S1.
290
291 (* This was not working in 8.4 because of untracked dependencies *)
292 Goal forall y, forall h:forall x, x = y, h 0 = h 0.
293 intros.
294 destruct (h 0).
295 Abort.
296
297 (* Check absence of useless local definitions *)
298
299 Section S2.
300 Variable H : 1=1.
301 Goal 0=1.
302 destruct H.
303 Fail clear n. (* Check that there is no n as it was in Coq <= 8.4 *)
304 Abort.
305 End S2.
306
307 Goal forall x:nat, x=x->x=1.
308 intros x H.
309 destruct H.
310 Fail clear n. (* Check that there is no n as it was in Coq <= 8.4 *)
311 Fail clear H. (* Check that H has been removed *)
312 Abort.
313
314 (* Check support for induction arguments which do not expose an inductive
315 type rightaway *)
316
317 Definition U := nat -> nat.
318 Definition S' := S : U.
319 Goal forall n, S' n = 0.
320 intro.
321 destruct S'.
322 Abort.
323
324 (* This was working by chance in 8.4 thanks to "accidental" use of select
325 subterms _syntactically_ equal to the first matching one.
326
327 Parameter f2:bool -> unit.
328 Parameter r2:f2 true=f2 true.
329 Goal forall (P: forall b, b=b -> Prop), f2 (id true) = tt -> P (f2 true) r2.
330 intros.
331 destruct f2.
332 Abort.
333 *)
334
335 (* This did not work in 8.4, because of a clear failing *)
336
337 Inductive IND : forall x y:nat, x=y -> Type := CONSTR : IND 0 0 eq_refl.
338 Goal forall x y e (h:x=y -> y=x) (z:IND y x (h e)), e = e /\ z = z.
339 intros.
340 destruct z.
341 Abort.
342
343 (* The two following examples show how the variables occurring in the
344 term being destruct affects the generalization; don't know if these
345 behaviors are "good". None of them was working in 8.4. *)
346
347 Goal forall x y e (t:x=y) (z:x=y -> IND y x e), e = e.
348 intros.
349 destruct (z t).
350 change (0=0) in t. (* Generalization made *)
351 Abort.
352
353 Goal forall x y e (t:x=y) (z:x=y -> IND y x e), e = e /\ z t = z t.
354 intros.
355 destruct (z t).
356 change (0=0) in t. (* Generalization made *)
357 Abort.
358
359 (* Check that destruct on a scheme with a functional argument works *)
360
361 Goal (forall P:Prop, (nat->nat) -> P) -> forall h:nat->nat, h 0 = h 0.
362 intros.
363 destruct h using H.
364 Qed.
365
366 Goal (forall P:Prop, (nat->nat) -> P) -> forall h:nat->nat->nat, h 0 0 = h 1 0.
367 intros.
368 induction (h 1) using H.
369 Qed.
370
371 (* Check blocking generalization is not too strong (failed at some time) *)
372
373 Goal (E -> 0=1) -> 1=0 -> True.
374 intros.
375 destruct (H _).
376 change (0=0) in H0. (* Check generalization on H0 was made *)
377 Abort.
378
379 (* Check absence of anomaly (failed at some time) *)
380
381 Goal forall A (a:A) (P Q:A->Prop), (forall a, P a -> Q a) -> True.
382 intros.
383 Fail destruct H.
384 Abort.
385
386 (* Check keep option (BZ#3791) *)
387
388 Goal forall b:bool, True.
389 intro b.
390 destruct (b).
391 clear b. (* b has to be here *)
392 Abort.
393
394 (* Check clearing of names *)
395
396 Inductive IND2 : nat -> Prop := CONSTR2 : forall y, y = y -> IND2 y.
397 Goal forall x y z:nat, y = z -> x = y -> y = x -> x = y.
398 intros * Heq H Heq'.
399 destruct H.
400 Abort.
401
402 Goal 2=1 -> 1=0.
403 intro H. destruct H.
404 Fail (match goal with n:nat |- _ => unfold n end). (* Check that no let-in remains *)
405 Abort.
406
407 (* Check clearing of names *)
408
409 Inductive eqnat (x : nat) : nat -> Prop :=
410 reflnat : forall y, x = y -> eqnat x y.
411
412 Goal forall x z:nat, x = z -> eqnat x z -> True.
413 intros * H1 H.
414 destruct H.
415 Fail clear z. (* Should not be here *)
416 Abort.
417
418 (* Check ok in the presence of an equation *)
419
420 Goal forall b:bool, b = b.
421 intros.
422 destruct b eqn:H.
423 Abort.
424
425 (* Check natural instantiation behavior when the goal has already an evar *)
426
427 Goal exists x, S x = x.
428 eexists ?[x].
429 destruct (S _).
430 change (0 = ?x).
431 Abort.
432
433 Goal (forall P, P 0 -> True/\True) -> True.
434 intro H.
435 destruct (H (fun x => True)).
436 match goal with |- True => idtac end.
437 Abort.