| 1 |
Module ListTest. |
| 2 |
(* The "?" of cons and eq should be inferred *) |
| 3 |
Parameter list : Set -> Set. |
| 4 |
Parameter cons : forall T : Set, T -> list T -> list T. |
| 5 |
Check (forall n : list nat, exists l : _, (exists x : _, n = cons _ x l)). |
| 6 |
End ListTest. |
| 7 |
|
| 8 |
(* Examples provided by Eduardo Gimenez *) |
| 9 |
|
| 10 |
Definition c A (Q : (nat * A -> Prop) -> Prop) P := |
| 11 |
Q (fun p : nat * A => let (i, v) := p in P i v). |
| 12 |
|
| 13 |
(* What does this test ? *) |
| 14 |
Require Import TestSuite.list. |
| 15 |
Definition list_forall_bool (A : Set) (p : A -> bool) |
| 16 |
(l : list A) : bool := |
| 17 |
fold_right (fun a r => if p a then r else false) true l. |
| 18 |
|
| 19 |
(* Checks that solvable ? in the lambda prefix of the definition are harmless*) |
| 20 |
Parameter A1 A2 F B C : Set. |
| 21 |
Parameter f : F -> A1 -> B. |
| 22 |
Definition f1 frm0 a1 : B := f frm0 a1. |
| 23 |
|
| 24 |
(* Checks that solvable ? in the type part of the definition are harmless *) |
| 25 |
Definition f2 frm0 a1 : B := f frm0 a1. |
| 26 |
|
| 27 |
(* Checks that sorts that are evars are handled correctly (BZ#705) *) |
| 28 |
|
| 29 |
Fixpoint build (nl : list nat) : |
| 30 |
match nl with |
| 31 |
| nil => True |
| 32 |
| _ => False |
| 33 |
end -> unit := |
| 34 |
match nl return (match nl with |
| 35 |
| nil => True |
| 36 |
| _ => False |
| 37 |
end -> unit) with |
| 38 |
| nil => fun _ => tt |
| 39 |
| cons n rest => |
| 40 |
match n with |
| 41 |
| O => fun _ => tt |
| 42 |
| S m => fun a => build rest (False_ind _ a) |
| 43 |
end |
| 44 |
end. |
| 45 |
|
| 46 |
|
| 47 |
(* Checks that disjoint contexts are correctly set by restrict_hyp *) |
| 48 |
(* Bug de 1999 corrigé en déc 2004 *) |
| 49 |
|
| 50 |
Check |
| 51 |
(let p := |
| 52 |
fun (m : nat) f (n : nat) => |
| 53 |
match f m n with |
| 54 |
| exist _ a b => exist _ a b |
| 55 |
end in |
| 56 |
p |
| 57 |
:forall x : nat, |
| 58 |
(forall y n : nat, {q : nat | y = q * n}) -> |
| 59 |
forall n : nat, {q : nat | x = q * n}). |
| 60 |
|
| 61 |
(* Check instantiation of nested evars (BZ#1089) *) |
| 62 |
|
| 63 |
Check (fun f:(forall (v:Type->Type), v (v nat) -> nat) => f _ (Some (Some O))). |
| 64 |
|
| 65 |
(* This used to fail with anomaly (Pp.str "evar was not declared.") in V8.0pl3 *) |
| 66 |
|
| 67 |
Theorem contradiction : forall p, ~ p -> p -> False. |
| 68 |
Proof. trivial. Qed. |
| 69 |
#[export] Hint Resolve contradiction. |
| 70 |
Goal False. |
| 71 |
eauto. |
| 72 |
Abort. |
| 73 |
|
| 74 |
(* This used to fail in V8.1beta because first-order unification was |
| 75 |
used before using type information *) |
| 76 |
|
| 77 |
Check (exist _ O (refl_equal 0) : {n:nat|n=0}). |
| 78 |
Check (exist _ O I : {n:nat|True}). |
| 79 |
|
| 80 |
(* An example (initially from Marseille/Fairisle) that involves an evar with |
| 81 |
different solutions (Input, Output or bool) that may or may not be |
| 82 |
considered distinct depending on which kind of conversion is used *) |
| 83 |
|
| 84 |
Section A. |
| 85 |
Definition STATE := (nat * bool)%type. |
| 86 |
Let Input := bool. |
| 87 |
Let Output := bool. |
| 88 |
Parameter Out : STATE -> Output. |
| 89 |
Check fun (s : STATE) (reg : Input) => reg = Out s. |
| 90 |
End A. |
| 91 |
|
| 92 |
(* The return predicate found should be: "in _=U return U" *) |
| 93 |
(* (feature already available in V8.0) *) |
| 94 |
|
| 95 |
Definition g (T1 T2:Type) (x:T1) (e:T1=T2) : T2 := |
| 96 |
match e with |
| 97 |
| refl_equal => x |
| 98 |
end. |
| 99 |
|
| 100 |
(* An example extracted from FMapAVL which (may) test restriction on |
| 101 |
evars problems of the form ?n[args1]=?n[args2] with distinct args1 |
| 102 |
and args2 *) |
| 103 |
|
| 104 |
Set Implicit Arguments. |
| 105 |
Parameter t:Set->Set. |
| 106 |
Parameter map:forall elt elt' : Set, (elt -> elt') -> t elt -> t elt'. |
| 107 |
Parameter avl: forall elt : Set, t elt -> Prop. |
| 108 |
Parameter bst: forall elt : Set, t elt -> Prop. |
| 109 |
Parameter map_avl: forall (elt elt' : Set) (f : elt -> elt') (m : t elt), |
| 110 |
avl m -> avl (map f m). |
| 111 |
Parameter map_bst: forall (elt elt' : Set) (f : elt -> elt') (m : t elt), |
| 112 |
bst m -> bst (map f m). |
| 113 |
Record bbst (elt:Set) : Set := |
| 114 |
Bbst {this :> t elt; is_bst : bst this; is_avl: avl this}. |
| 115 |
Definition t' := bbst. |
| 116 |
Section B. |
| 117 |
Variables elt elt': Set. |
| 118 |
Definition map' f (m:t' elt) : t' elt' := |
| 119 |
Bbst (map_bst f m.(is_bst)) (map_avl f m.(is_avl)). |
| 120 |
End B. |
| 121 |
Unset Implicit Arguments. |
| 122 |
|
| 123 |
(* An example from Lexicographic_Exponentiation that tests the |
| 124 |
contraction of reducible fixpoints in type inference *) |
| 125 |
|
| 126 |
Check (fun (A:Set) (a b x:A) (l:list A) |
| 127 |
(H : app l (cons x nil) = cons b (cons a nil)) => |
| 128 |
app_inj_tail l (cons b nil) _ _ H). |
| 129 |
|
| 130 |
(* An example from NMake (simplified), that uses restriction in solve_refl *) |
| 131 |
|
| 132 |
Parameter h:(nat->nat)->(nat->nat). |
| 133 |
Fixpoint G p cont {struct p} := |
| 134 |
h (fun n => match p with O => cont | S p => G p cont end n). |
| 135 |
|
| 136 |
(* An example from Bordeaux/Cantor that applies evar restriction |
| 137 |
below a binder *) |
| 138 |
|
| 139 |
Require Import TestSuite.relationclasses. |
| 140 |
Parameter lex : forall (A B : Set), (forall (a1 a2:A), {a1=a2}+{a1<>a2}) |
| 141 |
-> relation A -> relation B -> A * B -> A * B -> Prop. |
| 142 |
Check |
| 143 |
forall (A B : Set) eq_A_dec o1 o2, |
| 144 |
antisymmetric A o1 -> transitive A o1 -> transitive B o2 -> |
| 145 |
transitive _ (lex _ _ eq_A_dec o1 o2). |
| 146 |
|
| 147 |
(* Another example from Julien Forest that tests unification below binders *) |
| 148 |
|
| 149 |
Set Implicit Arguments. |
| 150 |
Parameter |
| 151 |
merge : forall (A B : Set) (eqA : forall (a1 a2 : A), {a1=a2}+{a1<>a2}) |
| 152 |
(eqB : forall (b1 b2 : B), {b1=b2}+{b1<>b2}) |
| 153 |
(partial_res l : list (A*B)), option (list (A*B)). |
| 154 |
Axiom merge_correct : |
| 155 |
forall (A B : Set) eqA eqB (l1 l2 : list (A*B)), |
| 156 |
(forall a2 b2 c2, In (a2,b2) l2 -> In (a2,c2) l2 -> b2 = c2) -> |
| 157 |
match merge eqA eqB l1 l2 with _ => True end. |
| 158 |
Unset Implicit Arguments. |
| 159 |
|
| 160 |
(* An example from Bordeaux/Additions that tests restriction below binders *) |
| 161 |
|
| 162 |
Section Additions_while. |
| 163 |
|
| 164 |
Variable A : Set. |
| 165 |
Variables P Q : A -> Prop. |
| 166 |
Variable le : A -> A -> Prop. |
| 167 |
Hypothesis Q_dec : forall s : A, P s -> {Q s} + {~ Q s}. |
| 168 |
Hypothesis le_step : forall s : A, ~ Q s -> P s -> {s' | P s' /\ le s' s}. |
| 169 |
Hypothesis le_wf : well_founded le. |
| 170 |
|
| 171 |
Lemma loopexec : forall s : A, P s -> {s' : A | P s' /\ Q s'}. |
| 172 |
refine |
| 173 |
(well_founded_induction_type le_wf (fun s => _ -> {s' : A | _ /\ _}) |
| 174 |
(fun s hr i => |
| 175 |
match Q_dec s i with |
| 176 |
| left _ => _ |
| 177 |
| right _ => |
| 178 |
match le_step s _ _ with |
| 179 |
| exist _ s' h' => |
| 180 |
match hr s' _ _ with |
| 181 |
| exist _ s'' _ => exist _ s'' _ |
| 182 |
end |
| 183 |
end |
| 184 |
end)). |
| 185 |
Abort. |
| 186 |
|
| 187 |
End Additions_while. |
| 188 |
|
| 189 |
(* Two examples from G. Melquiond (BZ#1878 and BZ#1884) *) |
| 190 |
|
| 191 |
Parameter F1 G1 : nat -> Prop. |
| 192 |
Goal forall x : nat, F1 x -> G1 x. |
| 193 |
refine (fun x H => proj2 (_ x H)). |
| 194 |
Abort. |
| 195 |
|
| 196 |
Goal forall x : nat, F1 x -> G1 x. |
| 197 |
refine (fun x H => proj2 (_ x H) _). |
| 198 |
Abort. |
| 199 |
|
| 200 |
(* An example from y-not that was failing in 8.2rc1 *) |
| 201 |
|
| 202 |
Fixpoint filter (A:nat->Set) (l:list (sigT A)) : list (sigT A) := |
| 203 |
match l with |
| 204 |
| nil => nil |
| 205 |
| cons (existT _ k v) l' => (existT _ k v):: (filter A l') |
| 206 |
end. |
| 207 |
|
| 208 |
(* BZ#2000: used to raise Out of memory in 8.2 while it should fail by |
| 209 |
lack of information on the conclusion of the type of j *) |
| 210 |
|
| 211 |
Goal True. |
| 212 |
set (p:=fun j => j (or_intror _ (fun a:True => j (or_introl _ a)))) || idtac. |
| 213 |
Abort. |
| 214 |
|
| 215 |
(* Remark: the following example stopped succeeding at some time in |
| 216 |
the development of 8.2 but it works again (this was because 8.2 |
| 217 |
algorithm was more general and did not exclude a solution that it |
| 218 |
should have excluded for typing reason; handling of types and |
| 219 |
backtracking is still to be done) *) |
| 220 |
|
| 221 |
Section S. |
| 222 |
Variables A B : nat -> Prop. |
| 223 |
Goal forall x : nat, A x -> B x. |
| 224 |
refine (fun x H => proj2 (_ x H) _). |
| 225 |
Abort. |
| 226 |
End S. |
| 227 |
|
| 228 |
(* Check that constraints are taken into account by tactics that instantiate *) |
| 229 |
|
| 230 |
Lemma inj : forall n m, S n = S m -> n = m. |
| 231 |
intros n m H. |
| 232 |
eapply f_equal with (* should fail because ill-typed *) |
| 233 |
(f := fun n => |
| 234 |
match n return match n with S _ => nat | _ => unit end with |
| 235 |
| S n => n |
| 236 |
| _ => tt |
| 237 |
end) in H |
| 238 |
|| injection H. |
| 239 |
Abort. |
| 240 |
|
| 241 |
(* A legitimate simple eapply that was failing in coq <= 8.3. |
| 242 |
Cf. in Unification.w_merge the addition of an extra pose_all_metas_as_evars |
| 243 |
on 30/9/2010 |
| 244 |
*) |
| 245 |
|
| 246 |
Lemma simple_eapply_was_failing : |
| 247 |
(forall f:nat->nat, exists g, f = g) -> True. |
| 248 |
Proof. |
| 249 |
assert (modusponens : forall P Q, P -> (P->Q) -> Q) by auto. |
| 250 |
intros. |
| 251 |
eapply modusponens. |
| 252 |
simple eapply H. |
| 253 |
(* error message with V8.3 : |
| 254 |
Impossible to unify "?18" with "fun g : nat -> nat => ?6 = g". *) |
| 255 |
Abort. |
| 256 |
|
| 257 |
(* Regression test *) |
| 258 |
|
| 259 |
Definition fo : option nat -> nat := option_rec _ (fun a => 0) 0. |
| 260 |
|
| 261 |
(* This example revealed an incorrect evar restriction at some time |
| 262 |
around October 2011 *) |
| 263 |
|
| 264 |
Goal forall (A:Type) (a:A) (P:forall A, A -> Prop), (P A a) /\ (P A a). |
| 265 |
intros. |
| 266 |
refine ((fun H => conj (proj1 H) (proj2 H)) _). |
| 267 |
Abort. |
| 268 |
|
| 269 |
(* The argument of e below failed to be inferred from r14219 (Oct 2011) to *) |
| 270 |
(* r14753 after the restrictions made on detecting Miller's pattern in the *) |
| 271 |
(* presence of alias, only the second-order unification procedure was *) |
| 272 |
(* able to solve this problem but it was deactivated for 8.4 in r14219 *) |
| 273 |
|
| 274 |
Definition k0 |
| 275 |
(e:forall P : nat -> Prop, (exists n : nat, P n) -> nat) |
| 276 |
(j : forall a, exists n : nat, n = a) o := |
| 277 |
match o with (* note: match introduces an alias! *) |
| 278 |
| Some a => e _ (j a) |
| 279 |
| None => O |
| 280 |
end. |
| 281 |
|
| 282 |
Definition k1 |
| 283 |
(e:forall P : nat -> Prop, (exists n : nat, P n) -> nat) |
| 284 |
(j : forall a, exists n : nat, n = a) a (b:=a) := e _ (j a). |
| 285 |
|
| 286 |
Definition k2 |
| 287 |
(e:forall P : nat -> Prop, (exists n : nat, P n) -> nat) |
| 288 |
(j : forall a, exists n : nat, n = a) a (b:=a) := e _ (j b). |
| 289 |
|
| 290 |
(* Other examples about aliases involved in pattern unification *) |
| 291 |
|
| 292 |
Definition k3 |
| 293 |
(e:forall P : nat -> Prop, (exists n : nat, P n) -> nat) |
| 294 |
(j : forall a, exists n : nat, let a' := a in n = a') a (b:=a) := e _ (j b). |
| 295 |
|
| 296 |
Definition k4 |
| 297 |
(e:forall P : nat -> Prop, (exists n : nat, P n) -> nat) |
| 298 |
(j : forall a, exists n : nat, let a' := S a in n = a') a (b:=a) := e _ (j b). |
| 299 |
|
| 300 |
Definition k5 |
| 301 |
(e:forall P : nat -> Prop, (exists n : nat, P n) -> nat) |
| 302 |
(j : forall a, let a' := S a in exists n : nat, n = a') a (b:=a) := e _ (j b). |
| 303 |
|
| 304 |
Definition k6 |
| 305 |
(e:forall P : nat -> Prop, (exists n : nat, P n) -> nat) |
| 306 |
(j : forall a, exists n : nat, let n' := S n in n' = a) a (b:=a) := e _ (j b). |
| 307 |
|
| 308 |
Definition k7 |
| 309 |
(e:forall P : nat -> Prop, (exists n : nat, let n' := n in P n') -> nat) |
| 310 |
(j : forall a, exists n : nat, n = a) a (b:=a) := e _ (j b). |
| 311 |
|
| 312 |
(* An example that uses materialize_evar under binders *) |
| 313 |
(* Extracted from bigop.v in the mathematical components library *) |
| 314 |
|
| 315 |
Section Bigop. |
| 316 |
|
| 317 |
Variable bigop : forall R I: Type, |
| 318 |
R -> (R -> R -> R) -> list I -> (I->Prop) -> (I -> R) -> R. |
| 319 |
|
| 320 |
Hypothesis eq_bigr : |
| 321 |
forall (R : Type) (idx : R) (op : R -> R -> R) |
| 322 |
(I : Type) (r : list I) (P : I -> Prop) (F1 F2 : I -> R), |
| 323 |
(forall i : I, P i -> F1 i = F2 i) -> |
| 324 |
bigop R I idx op r (fun i : I => P i) (fun i : I => F1 i) = idx. |
| 325 |
|
| 326 |
Hypothesis big_tnth : |
| 327 |
forall (R : Type) (idx : R) (op : R -> R -> R) |
| 328 |
(I : Type) (r : list I) (P : I -> Prop) (F : I -> R), |
| 329 |
bigop R I idx op r (fun i : I => P i) (fun i : I => F i) = idx. |
| 330 |
|
| 331 |
Hypothesis big_tnth_with_letin : |
| 332 |
forall (R : Type) (idx : R) (op : R -> R -> R) |
| 333 |
(I : Type) (r : list I) (P : I -> Prop) (F : I -> R), |
| 334 |
bigop R I idx op r (fun i : I => let i:=i in P i) (fun i : I => F i) = idx. |
| 335 |
|
| 336 |
Variable R : Type. |
| 337 |
Variable idx : R. |
| 338 |
Variable op : R -> R -> R. |
| 339 |
Variable I : Type. |
| 340 |
Variable J : Type. |
| 341 |
Variable rI : list I. |
| 342 |
Variable rJ : list J. |
| 343 |
Variable xQ : J -> Prop. |
| 344 |
Variable P : I -> Prop. |
| 345 |
Variable Q : I -> J -> Prop. |
| 346 |
Variable F : I -> J -> R. |
| 347 |
|
| 348 |
(* Check unification under binders *) |
| 349 |
|
| 350 |
Check (eq_bigr _ _ _ _ _ _ _ _ (fun _ _ => big_tnth _ _ _ _ rI _ _)) |
| 351 |
: (bigop R J idx op rJ |
| 352 |
(fun j : J => let k:=j in xQ k) |
| 353 |
(fun j : J => let k:=j in |
| 354 |
bigop R I idx |
| 355 |
op rI |
| 356 |
(fun i : I => P i /\ Q i k) (fun i : I => let k:=j in F i k))) = idx. |
| 357 |
|
| 358 |
(* Check also with let-in *) |
| 359 |
|
| 360 |
Check (eq_bigr _ _ _ _ _ _ _ _ (fun _ _ => big_tnth_with_letin _ _ _ _ rI _ _)) |
| 361 |
: (bigop R J idx op rJ |
| 362 |
(fun j : J => let k:=j in xQ k) |
| 363 |
(fun j : J => let k:=j in |
| 364 |
bigop R I idx |
| 365 |
op rI |
| 366 |
(fun i : I => P i /\ Q i k) (fun i : I => let k:=j in F i k))) = idx. |
| 367 |
|
| 368 |
End Bigop. |
| 369 |
|
| 370 |
(* Check the use of (at least) an heuristic to solve problems of the form |
| 371 |
"?x[t] = ?y" where ?y occurs in t without easily knowing if ?y can |
| 372 |
eventually be erased in t *) |
| 373 |
|
| 374 |
Section evar_evar_occur. |
| 375 |
Variable id : nat -> nat. |
| 376 |
Variable f : forall x, id x = 0 -> id x = 0 -> x = 1 /\ x = 2. |
| 377 |
Variable g : forall y, id y = 0 /\ id y = 0. |
| 378 |
(* Still evars in the resulting type, but constraints should be solved *) |
| 379 |
Check match g _ with conj a b => f _ a b end. |
| 380 |
End evar_evar_occur. |
| 381 |
|
| 382 |
(* Eta expansion (BZ#2936) *) |
| 383 |
Record iffT (X Y:Type) : Type := mkIff { iffLR : X->Y; iffRL : Y->X }. |
| 384 |
Record tri (R:Type->Type->Type) (S:Type->Type->Type) (T:Type->Type->Type) := mkTri { |
| 385 |
tri0 : forall a b c, R a b -> S a c -> T b c |
| 386 |
}. |
| 387 |
Arguments mkTri [R S T]. |
| 388 |
Definition tri_iffT : tri iffT iffT iffT := |
| 389 |
(mkTri |
| 390 |
(fun X0 X1 X2 E01 E02 => |
| 391 |
(mkIff _ _ (fun x1 => iffLR _ _ E02 (iffRL _ _ E01 x1)) |
| 392 |
(fun x2 => iffLR _ _ E01 (iffRL _ _ E02 x2))))). |
| 393 |
|
| 394 |
(* Check that local defs names are preserved if possible during unification *) |
| 395 |
|
| 396 |
Goal forall x (x':=x) (f:forall y, y=y:>nat -> Prop), f _ (eq_refl x'). |
| 397 |
intros. |
| 398 |
unfold x' at 2. (* A way to check that there are indeed 2 occurrences of x' *) |
| 399 |
Abort. |
| 400 |
|
| 401 |
(* A simple example we would like not to fail (it used to fail because of |
| 402 |
not strict enough evar restriction) *) |
| 403 |
|
| 404 |
Check match Some _ with None => _ | _ => _ end. |
| 405 |
|
| 406 |
(* Used to fail for a couple of days in Nov 2014 *) |
| 407 |
|
| 408 |
Axiom test : forall P1 P2, P1 = P2 -> P1 -> P2. |
| 409 |
|
| 410 |
(* Check use of candidates *) |
| 411 |
|
| 412 |
Import EqNotations. |
| 413 |
Definition test2 {A B:Type} {H:A=B} (a:A) : B := rew H in a. |
| 414 |
|
| 415 |
(* Check that pre-existing evars are not counted as newly undefined in "set" *) |
| 416 |
(* Reported by Théo *) |
| 417 |
|
| 418 |
Goal exists n : nat, n = n -> True. |
| 419 |
eexists. |
| 420 |
set (H := _ = _). |
| 421 |
Abort. |
| 422 |
|
| 423 |
(* Check interpretation of default evar instance in pretyping *) |
| 424 |
(* (reported as bug #7356) *) |
| 425 |
|
| 426 |
Check fun (P : nat -> Prop) (x:nat) (h:P x) => exist _ ?[z] (h : P ?z). |
| 427 |
|
| 428 |
(* A printing check in passing *) |
| 429 |
|
| 430 |
Axiom abs : forall T, T. |
| 431 |
Fail Type let x := _ in |
| 432 |
ltac:( |
| 433 |
let t := type of x in |
| 434 |
unify x (abs t); |
| 435 |
exact 0). |
| 436 |
|
| 437 |
(* Check that evars are instantiated with least unfolded terms *) |
| 438 |
Module TestFold. |
| 439 |
Structure S := {T : Type}. |
| 440 |
Definition nat' : Type := nat. |
| 441 |
Canonical nat'_S := {| T := nat' |}. |
| 442 |
Check (eq_refl : (fun x => (id x, x)) _ = (nat', T _)). |
| 443 |
End TestFold. |