| 1 |
(* Check that dependent rewrite applies on arbitrary terms *) |
| 2 |
|
| 3 |
Inductive listn : nat -> Set := |
| 4 |
| niln : listn 0 |
| 5 |
| consn : forall n : nat, nat -> listn n -> listn (S n). |
| 6 |
|
| 7 |
Axiom |
| 8 |
ax : |
| 9 |
forall (n n' : nat) (l : listn (n + n')) (l' : listn (n' + n)), |
| 10 |
existT _ (n + n') l = existT _ (n' + n) l'. |
| 11 |
|
| 12 |
Lemma lem : |
| 13 |
forall (n n' : nat) (l : listn (n + n')) (l' : listn (n' + n)), |
| 14 |
n + n' = n' + n /\ existT _ (n + n') l = existT _ (n' + n) l'. |
| 15 |
Proof. |
| 16 |
intros n n' l l'. |
| 17 |
dependent rewrite (ax n n' l l'). |
| 18 |
split; reflexivity. |
| 19 |
Qed. |
| 20 |
|
| 21 |
(* Used to raise an anomaly instead of an error in 8.1 *) |
| 22 |
(* Submitted by Y. Makarov *) |
| 23 |
|
| 24 |
Parameter N : Set. |
| 25 |
Parameter E : N -> N -> Prop. |
| 26 |
|
| 27 |
Axiom e : forall (A : Set) (EA : A -> A -> Prop) (a : A), EA a a. |
| 28 |
|
| 29 |
Theorem th : forall x : N, E x x. |
| 30 |
intro x. try rewrite e. |
| 31 |
Abort. |
| 32 |
|
| 33 |
(* Behavior of rewrite wrt conversion *) |
| 34 |
|
| 35 |
Require Import TestSuite.arith. |
| 36 |
|
| 37 |
Goal forall n, 0 + n = n -> True. |
| 38 |
intros n H. |
| 39 |
rewrite Nat.add_0_l in H. |
| 40 |
Abort. |
| 41 |
|
| 42 |
(* Rewrite dependent proofs from left-to-right *) |
| 43 |
|
| 44 |
Lemma l1 : |
| 45 |
forall x y (H:x = y:>nat) (P:forall x y, x=y -> Type), P x y H -> P x y H. |
| 46 |
intros x y H P H0. |
| 47 |
rewrite H. |
| 48 |
rewrite H in H0. |
| 49 |
assumption. |
| 50 |
Qed. |
| 51 |
|
| 52 |
(* Rewrite dependent proofs from right-to-left *) |
| 53 |
|
| 54 |
Lemma l2 : |
| 55 |
forall x y (H:x = y:>nat) (P:forall x y, x=y -> Type), P x y H -> P x y H. |
| 56 |
intros x y H P H0. |
| 57 |
rewrite <- H. |
| 58 |
rewrite <- H in H0. |
| 59 |
assumption. |
| 60 |
Qed. |
| 61 |
|
| 62 |
(* Check rewriting dependent proofs with non-symmetric equalities *) |
| 63 |
|
| 64 |
Lemma l3:forall x (H:eq_true x) (P:forall x, eq_true x -> Type), P x H -> P x H. |
| 65 |
intros x H P H0. |
| 66 |
rewrite H. |
| 67 |
rewrite H in H0. |
| 68 |
assumption. |
| 69 |
Qed. |
| 70 |
|
| 71 |
(* Dependent rewrite *) |
| 72 |
|
| 73 |
Require Import TestSuite.jmeq. |
| 74 |
|
| 75 |
Goal forall A B (a:A) (b:B), JMeq a b -> JMeq b a -> True. |
| 76 |
inversion 1; (* Goal is now [JMeq a a -> True] *) dependent rewrite H3. |
| 77 |
Undo. |
| 78 |
intros; inversion H; dependent rewrite H4 in H0. |
| 79 |
Undo. |
| 80 |
intros; inversion H; dependent rewrite <- H4 in H0. |
| 81 |
Abort. |
| 82 |
|
| 83 |
(* Test conversion between terms with evars that both occur in K-redexes and |
| 84 |
are elsewhere solvable. |
| 85 |
|
| 86 |
This is quite an artificial example, but it used to work in 8.2. |
| 87 |
|
| 88 |
Since rewrite supports conversion on terms without metas, it |
| 89 |
was successively unifying (id 0 ?y) and 0 where ?y was not a |
| 90 |
meta but, because coming from a "_", an evar. |
| 91 |
|
| 92 |
After commit r12440 which unified the treatment of metas and |
| 93 |
evars, it stopped to work. Chung-Kil Hur's Heq package used |
| 94 |
this feature. Solved in r13... |
| 95 |
*) |
| 96 |
|
| 97 |
Parameter g : nat -> nat -> nat. |
| 98 |
Definition K (x y:nat) := x. |
| 99 |
|
| 100 |
Goal (forall y, g y (K 0 y) = 0) -> g 0 0 = 0. |
| 101 |
intros. |
| 102 |
rewrite (H _). |
| 103 |
reflexivity. |
| 104 |
Qed. |
| 105 |
|
| 106 |
Goal (forall y, g (K 0 y) y = 0) -> g 0 0 = 0. |
| 107 |
intros. |
| 108 |
rewrite (H _). |
| 109 |
reflexivity. |
| 110 |
Qed. |
| 111 |
|
| 112 |
(* Example of rewriting of a degenerated pattern using the right-most |
| 113 |
argument of the goal. This is sometimes used in contribs, even if |
| 114 |
ad hoc. Here, we have the extra requirement that checking types |
| 115 |
needs delta-conversion *) |
| 116 |
|
| 117 |
Axiom s : forall (A B : Type) (p : A * B), p = (fst p, snd p). |
| 118 |
Definition P := (nat * nat)%type. |
| 119 |
Goal forall x:P, x = x. |
| 120 |
intros. rewrite s. |
| 121 |
Abort. |
| 122 |
|
| 123 |
(* Test second-order unification and failure of pattern-unification *) |
| 124 |
|
| 125 |
Goal forall (P: forall Y, Y -> Prop) Y a, Y = nat -> (True -> P Y a) -> False. |
| 126 |
intros. |
| 127 |
(* The next line used to succeed between June and November 2011 *) |
| 128 |
(* causing ill-typed rewriting *) |
| 129 |
Fail rewrite H in H0. |
| 130 |
Abort. |
| 131 |
|
| 132 |
(* Test subst in the presence of a dependent let-in *) |
| 133 |
(* Was not working prior to May 2014 *) |
| 134 |
|
| 135 |
Goal forall x y, x=y+0 -> let z := x+1 in x+1=y -> z=z -> z=x. |
| 136 |
intros. |
| 137 |
subst x. (* was failing *) |
| 138 |
subst z. |
| 139 |
rewrite H0. |
| 140 |
rewrite Nat.add_0_r. |
| 141 |
reflexivity. |
| 142 |
Qed. |
| 143 |
|
| 144 |
(* Check that evars are instantiated when the term to rewrite is |
| 145 |
closed, like in the case it is open *) |
| 146 |
|
| 147 |
Goal exists x, S 0 = 0 -> S x = 0. |
| 148 |
eexists. intro H. |
| 149 |
rewrite H. |
| 150 |
reflexivity. |
| 151 |
Abort. |
| 152 |
|
| 153 |
(* Check that rewriting within evars still work (was broken in 8.5beta1) *) |
| 154 |
|
| 155 |
Goal forall (a: unit) (H: a = tt), exists x y:nat, x = y. |
| 156 |
intros; eexists; eexists. |
| 157 |
rewrite H. |
| 158 |
Undo. |
| 159 |
subst. |
| 160 |
Abort. |
| 161 |
|
| 162 |
(* Check that iterated rewriting does not rewrite in the side conditions *) |
| 163 |
(* Example from Sigurd Schneider, extracted from contrib containers *) |
| 164 |
|
| 165 |
Lemma EQ |
| 166 |
: forall (e e' : nat), True -> e = e'. |
| 167 |
Admitted. |
| 168 |
|
| 169 |
Lemma test (v1 v2 v3: nat) (v' : v1 = v2) : v2 = v1. |
| 170 |
Proof. |
| 171 |
rewrite <- (EQ v1 v2) in *. |
| 172 |
exact v'. |
| 173 |
(* There should be only two side conditions *) |
| 174 |
exact I. |
| 175 |
exact I. |
| 176 |
Qed. |
| 177 |
|
| 178 |
(* test that "try rewrite" / "rewrite ?h" catches the error from mssing-scheme *) |
| 179 |
Set Warnings "+missing-scheme". |
| 180 |
|
| 181 |
Inductive myeq A x : A -> Prop := myrefl : myeq A x x. |
| 182 |
|
| 183 |
Goal forall x y, myeq nat x y -> x = y. |
| 184 |
Proof. |
| 185 |
intros x y H. |
| 186 |
Fail rewrite H. |
| 187 |
try rewrite H. |
| 188 |
rewrite ?H. |
| 189 |
Abort. |