Debian Codegraph @

test-suite/success/unification.v

raw
1 #[local] Definition test_stack_unification_interaction_with_delta A
2 : (if negb _ then true else false) = if orb false (negb A) then true else false
3 := eq_refl.
4
5 (* Test patterns unification *)
6
7 Lemma l1 : (forall P, (exists x:nat, P x) -> False)
8 -> forall P, (exists x:nat, P x /\ P x) -> False.
9 Proof.
10 intros; apply (H _ H0).
11 Qed.
12
13 Lemma l2 : forall A:Set, forall Q:A->Set,
14 (forall (P: forall x:A, Q x -> Prop),
15 (exists x:A, exists y:Q x, P x y) -> False)
16 -> forall (P: forall x:A, Q x -> Prop),
17 (exists x:A, exists y:Q x, P x y /\ P x y) -> False.
18 Proof.
19 intros; apply (H _ H0).
20 Qed.
21
22 Lemma l3 : (forall P, ~(exists x:nat, P x))
23 -> forall P:nat->Prop, ~(exists x:nat, P x -> P x).
24 Proof.
25 intros; apply H.
26 Qed.
27
28 (* Feature introduced June 2011 *)
29
30 Lemma l7 : forall x (P:nat->Prop), (forall f, P (f x)) -> P (x+x).
31 Proof.
32 intros x P H; apply H.
33 Qed.
34
35 (* Example submitted for Zenon *)
36
37 Axiom zenon_noteq : forall T : Type, forall t : T, ((t <> t) -> False).
38 Axiom zenon_notall : forall T : Type, forall P : T -> Prop,
39 (forall z : T, (~(P z) -> False)) -> (~(forall x : T, (P x)) -> False).
40
41 (* Must infer "P := fun x => x=x" in zenon_notall *)
42 Check (fun _h1 => (zenon_notall nat _ (fun _T_0 =>
43 (fun _h2 => (zenon_noteq _ _T_0 _h2))) _h1)).
44
45
46 (* Core of an example submitted by Ralph Matthes (BZ#849)
47
48 It used to fail because of the K-variable x in the type of "sum_rec ..."
49 which was not in the scope of the evar ?B. Solved by a head
50 beta-reduction of the type "(fun _ : unit + unit => L unit) x" of
51 "sum_rec ...". Shall we used more reduction when solving evars (in
52 real_clean)?? Is there a risk of starting too long reductions?
53
54 Note that the example originally came from a non re-typable
55 pretty-printed term (the checked term is actually re-printed the
56 same form it is checked).
57 *)
58
59 Set Implicit Arguments.
60 Inductive L (A:Set) : Set := c : A -> L A.
61 Parameter f: forall (A:Set)(B:Set), (A->B) -> L A -> L B.
62 Parameter t: L (unit + unit).
63
64 Check (f (fun x : unit + unit =>
65 sum_rec (fun _ : unit + unit => L unit)
66 (fun y => c y) (fun y => c y) x) t).
67
68
69 (* Test patterns unification in apply *)
70
71 Require Import TestSuite.arith.
72 Parameter x y : nat.
73 Parameter G:x=y->x=y->Prop.
74 Parameter K:x<>y->x<>y->Prop.
75 Lemma l4 : (forall f:x=y->Prop, forall g:x<>y->Prop,
76 match eq_nat_dec x y with left a => f a | right a => g a end)
77 -> match eq_nat_dec x y with left a => G a a | right a => K a a end.
78 Proof.
79 intros.
80 apply H.
81 Qed.
82
83
84 (* Test unification modulo eta-expansion (if possible) *)
85
86 (* In this example, two instances for ?P (argument of hypothesis H) can be
87 inferred (one is by unifying the type [Q true] and [?P true] of the
88 goal and type of [H]; the other is by unifying the argument of [f]);
89 we need to unify both instances up to allowed eta-expansions of the
90 instances (eta is allowed if the meta was applied to arguments)
91
92 This used to fail before revision 9389 in trunk
93 *)
94
95 Lemma l5 :
96 forall f : (forall P, P true), (forall P, f P = f P) ->
97 forall Q, f (fun x => Q x) = f (fun x => Q x).
98 Proof.
99 intros.
100 apply H.
101 Qed.
102
103 (* Feature deactivated in commit 14189 (see commit log)
104 (* Test instantiation of evars by unification *)
105
106 Goal (forall x, 0 + x = 0 -> True) -> True.
107 intros; eapply H.
108 rewrite <- plus_n_Sm. (* should refine ?x with S ?x' *)
109 Abort.
110 *)
111
112 (* Check handling of identity equation between evars *)
113 (* The example failed to pass until revision 10623 *)
114
115 Lemma l6 :
116 (forall y, (forall x, (forall z, y = 0 -> y + z = 0) -> y + x = 0) -> True)
117 -> True.
118 intros.
119 eapply H.
120 intros.
121 apply H0. (* Check that equation ?n[H] = ?n[H] is correctly considered true *)
122 reflexivity.
123 Qed.
124
125 (* Check treatment of metas erased by K-redexes at the time of turning
126 them to evas *)
127
128 Inductive nonemptyT (t : Type) : Prop := nonemptyT_intro : t -> nonemptyT t.
129 Goal True.
130 try case nonemptyT_intro. (* check that it fails w/o anomaly *)
131 Abort.
132
133 (* Test handling of return type and when it is decided to make the
134 predicate dependent or not - see "bug" BZ#1851 *)
135
136 Goal forall X (a:X) (f':nat -> X), (exists f : nat -> X, True).
137 intros.
138 exists (fun n => match n with O => a | S n' => f' n' end).
139 constructor.
140 Qed.
141
142 (* Check use of types in unification (see Andrej Bauer's mail on
143 coq-club, June 1 2009; it did not work in 8.2, probably started to
144 work after Sozeau improved support for the use of types in unification) *)
145
146 Goal (forall (A B : Set) (f : A -> B), (fun x => f x) = f) ->
147 forall (A B C : Set) (g : (A -> B) -> C) (f : A -> B), g (fun x => f x) = g f.
148 Proof.
149 intros.
150 rewrite H with (f:=f0).
151 Abort.
152
153 (* Three tests provided by Dan Grayson as part of a custom patch he
154 made for a more powerful "destruct" for handling Voevodsky's
155 Univalent Foundations. The test checks if second-order matching in
156 tactic unification is able to guess by itself on which dependent
157 terms to abstract so that the elimination predicate is well-typed *)
158
159 Definition test1 (X : Type) (x : X) (fxe : forall x1 : X, identity x1 x1) :
160 identity (fxe x) (fxe x).
161 Proof. destruct (fxe x). apply identity_refl. Defined.
162
163 (* a harder example *)
164
165 Definition UU := Type .
166 Inductive paths {T:Type}(t:T): T -> UU := idpath: paths t t.
167 Inductive foo (X0:UU) (x0:X0) : forall (X:UU)(x:X), UU := newfoo : foo x0 x0.
168 Definition idonfoo {X0:UU} {x0:X0} {X1:UU} {x1:X1} : foo x0 x1 -> foo x0 x1.
169 Proof. intros t. exact t. Defined.
170
171 Lemma test2 (T:UU) (t:T) (k : foo t t) : paths k (idonfoo k).
172 Proof.
173 destruct k.
174 apply idpath.
175 Defined.
176
177 (* an example with two constructors *)
178
179 Inductive foo' (X0:UU) (x0:X0) : forall (X:UU)(x:X), UU :=
180 | newfoo1 : foo' x0 x0
181 | newfoo2 : foo' x0 x0 .
182 Definition idonfoo' {X0:UU} {x0:X0} {X1:UU} {x1:X1} :
183 foo' x0 x1 -> foo' x0 x1.
184 Proof. intros t. exact t. Defined.
185 Lemma test3 (T:UU) (t:T) (k : foo' t t) : paths k (idonfoo' k).
186 Proof.
187 destruct k.
188 apply idpath.
189 apply idpath.
190 Defined.
191
192 (* An example where it is necessary to evar-normalize the instance of
193 an evar to evaluate if it is a pattern *)
194
195 Check
196 let a := ?[P] in
197 fun (H : forall y (P : nat -> Prop), y = 0 -> P y)
198 x (p:x=0) =>
199 H ?[y] a p : x = 0.
200 (* We have to solve "?P ?y[x] == x = 0" knowing from
201 "p : (x=0) == (?y[x] = 0)" that "?y := x" *)
202
203 (* An example involving SProp *)
204
205 Check fun (A:SProp) (f g:A->A) (P:A->Type) a (x : P (f a)) => x : P (g _).