Debian Codegraph @

test-suite/success/specialize.v

raw
1
2 Goal forall a b c : nat, a = b -> b = c -> forall d, a+d=c+d.
3 intros.
4
5 (* "compatibility" mode: specializing a global name
6 means a kind of generalize *)
7
8 specialize eq_trans. intros _.
9 specialize eq_trans with (1:=H)(2:=H0). intros _.
10 specialize eq_trans with (x:=a)(y:=b)(z:=c). intros _.
11 specialize eq_trans with (1:=H)(z:=c). intros _.
12 specialize eq_trans with nat a b c. intros _.
13 specialize (@eq_trans nat). intros _.
14 specialize (@eq_trans _ a b c). intros _.
15 specialize (eq_trans (x:=a)). intros _.
16 specialize (eq_trans (x:=a)(y:=b)). intros _.
17 specialize (eq_trans H H0). intros _.
18 specialize (eq_trans H0 (z:=b)). intros _.
19
20 (* incomplete bindings: y is left quantified and z is instantiated. *)
21 specialize eq_trans with (x:=a)(z:=c).
22 intro h.
23 (* y can be instantiated now *)
24 specialize h with (y:=b).
25 (* z was instantiated above so this must fail. *)
26 Fail specialize h with (z:=c).
27 clear h.
28
29 (* incomplete bindings: 1st dep hyp is instantiated thus A, x and y
30 instantiated too. *)
31 specialize eq_trans with (1:=H).
32 intro h.
33 (* 2nd dep hyp can be instantiated now, which instatiates z too. *)
34 specialize h with (1:=H0).
35 (* checking that there is no more products in h. *)
36 match type of h with
37 | _ = _ => idtac
38 | _ => fail "specialize test failed: hypothesis h should be an equality at this point"
39 end.
40 clear h.
41
42
43 (* local "in place" specialization *)
44 assert (Eq:=eq_trans).
45
46 specialize Eq.
47 specialize Eq with (1:=H)(2:=H0). Undo.
48 specialize Eq with (x:=a)(y:=b)(z:=c). Undo.
49 specialize Eq with (1:=H)(z:=c). Undo.
50 specialize Eq with nat a b c. Undo.
51 specialize (Eq nat). Undo.
52 specialize (Eq _ a b c). Undo.
53 (* no implicit argument for Eq, hence no (Eq (x:=a)) *)
54 specialize (Eq _ _ _ _ H H0). Undo.
55 specialize (Eq _ _ _ b H0). Undo.
56
57 (* incomplete binding *)
58 specialize Eq with (y:=b).
59 (* A and y have been instantiated so this works *)
60 specialize (Eq _ _ H H0).
61 Undo 2.
62
63 (* incomplete binding (dependent) *)
64 specialize Eq with (1:=H).
65 (* A, x and y have been instantiated so this works *)
66 specialize (Eq _ H0).
67 Undo 2.
68
69 (* incomplete binding (dependent) *)
70 specialize Eq with (1:=H) (2:=H0).
71 (* A, x and y have been instantiated so this works *)
72 match type of Eq with
73 | _ = _ => idtac
74 | _ => fail "specialize test failed: hypothesis Eq should be an equality at this point"
75 end.
76 Undo 2.
77
78 (*
79 (** strange behavior to inspect more precisely *)
80
81 (* 1) proof aspect : let H:= ... in (fun H => ..) H
82 presque ok... *)
83
84 (* 2) echoue moins lorsque zero premise de mangé *)
85 specialize eq_trans with (1:=Eq). (* mal typé !! *)
86
87 (* 3) Seems fixed.*)
88 specialize eq_trans with _ a b c. intros _.
89 (* Anomaly: Evar ?88 was not declared. Please report. *)
90 *)
91
92 Abort.
93
94 (* Test use of pose proof and assert as a specialize *)
95
96 Goal True -> (True -> 0=0) -> False -> 0=0.
97 intros H0 H H1.
98 pose proof (H I) as H.
99 (* Check that the hypothesis is in 2nd position by removing the top one *)
100 match goal with H:_ |- _ => clear H end.
101 match goal with H:_ |- _ => exact H end.
102 Qed.
103
104 Goal True -> (True -> 0=0) -> False -> 0=0.
105 intros H0 H H1.
106 assert (H:=H I).
107 (* Check that the hypothesis is in 2nd position by removing the top one *)
108 match goal with H:_ |- _ => clear H end.
109 match goal with H:_ |- _ => exact H end.
110 Qed.
111
112
113 (* let ins should be supported int he type of the specialized hypothesis *)
114 Axiom foo: forall (m1:nat) (m2: nat), let n := 2 * m1 in (m1 = m2 -> False).
115 Goal False.
116 pose proof foo as P.
117 assert (2 = 2) as A by reflexivity.
118 (* specialize P with (m2:= 2). *)
119 specialize P with (1 := A).
120 match type of P with
121 | let n := 2 * 2 in False => idtac
122 | _ => fail "test failed"
123 end.
124 assumption.
125 Qed.
126
127 (* Another more subtle test on letins: they should not interfere with foralls. *)
128 Goal forall (P: forall a c:nat,
129 let b := c in
130 let d := 1 in
131 forall n : a = d, a = c+1),
132 True.
133 intros P.
134 specialize P with (1:=eq_refl).
135 match type of P with
136 | forall c : nat, let f := c in let d := 1 in 1 = c + 1 => idtac
137 | _ => fail "test failed"
138 end.
139 constructor.
140 Qed.
141
142
143 (* Test specialize as *)
144
145 Goal (forall x, x=0) -> 1=0.
146 intros.
147 specialize (H 1) as ->.
148 reflexivity.
149 Qed.
150
151 (* A test from corn *)
152
153 Goal (forall x y, x=0 -> y=0 -> True) -> True.
154 intros.
155 specialize (fun z => H 0 z eq_refl).
156 exact (H 0 eq_refl).
157 Qed.
158
159 Module bug_17322.
160
161 Axiom key : Type.
162 Axiom value : Type.
163 Axiom eqb : key -> key -> bool.
164 Axiom remove : list value -> key -> list value.
165 Axiom sorted : list value -> bool.
166 Axiom lookup : list value -> key -> value.
167
168 Goal forall (l : list value) (k : key),
169 (sorted l = true -> forall k' : key, eqb k k' = false ->
170 lookup (remove l k') k = lookup l k) ->
171 sorted l = true -> False
172 .
173 Proof.
174 intros l k IHl ST.
175 specialize IHl with (1 := ST).
176 Abort.
177
178 End bug_17322.
179
180 Module bug_17322_2.
181
182 Axiom tuple : Type.
183 Axiom mem : Type.
184 Axiom unchecked_store_bytes : tuple -> mem.
185 Axiom load_bytes : mem -> Prop.
186
187 Goal forall
188 (IHn : forall (m' : mem) (w : tuple),
189 unchecked_store_bytes w = m' -> load_bytes m' -> True),
190 True.
191 Proof.
192 intros.
193 Fail specialize IHn with (1 := eq_refl).
194 (* After #17322 this fails with
195
196 In environment
197 IHn : forall (m' : mem) (w : tuple), unchecked_store_bytes w = m' -> load_bytes m' -> True
198 m' : mem
199 w : tuple
200 Unable to unify "?t" with "w" (cannot instantiate "?t" because "w" is not in its scope:
201 available arguments are "IHn").
202
203 Previously it was leaving w as an unresolved evar, producing the hypothesis
204
205 IHn : load_bytes (unchecked_store_bytes ?w) -> True
206
207 The correct behaviour should probably to requantify on w as
208
209 IHn : forall w, load_bytes (unchecked_store_bytes w) -> True
210
211 *)
212 Abort.
213
214 End bug_17322_2.