| 1 |
From Corelib Require Import BinNums IntDef NatDef. |
| 2 |
Open Scope Z_scope. |
| 3 |
|
| 4 |
Module First. |
| 5 |
Lemma foo: forall (a b: nat), |
| 6 |
b < a -> |
| 7 |
a - b + b = a. |
| 8 |
Admitted. |
| 9 |
|
| 10 |
Axiom leb_spec : forall x y, (Nat.leb (S x) y) = true -> x < y. |
| 11 |
Ltac solve_leb := |
| 12 |
match goal with |
| 13 |
| [ |- ?x < ?y ] => apply leb_spec; exact eq_refl |
| 14 |
end. |
| 15 |
Hint Rewrite foo using solve_leb : foo_db. |
| 16 |
|
| 17 |
Goal (4 - 5 + 5) + (3 - 2 + 2) + (1 - 3 + 3) + 1 = (6 - 4 + 4) + (5 - 6 + 6). |
| 18 |
Proof. |
| 19 |
(* I want to simplify (3 - 2 + 2) and (6 - 4 + 4), and leave the rest unchanged. *) |
| 20 |
|
| 21 |
(* This does not work because rewrite does not backtrack: *) |
| 22 |
repeat rewrite foo by solve_leb. |
| 23 |
match goal with |
| 24 |
| [ |- 4 - 5 + 5 + 3 + (1 - 3 + 3) + 1 = 6 + (5 - 6 + 6) ] => fail |
| 25 |
| _ => idtac |
| 26 |
end. |
| 27 |
|
| 28 |
(* This works! (but "rewrite*" is not documented) *) |
| 29 |
repeat rewrite* foo by solve_leb. |
| 30 |
match goal with |
| 31 |
| [ |- 4 - 5 + 5 + 3 + (1 - 3 + 3) + 1 = 6 + (5 - 6 + 6) ] => idtac |
| 32 |
end. |
| 33 |
|
| 34 |
Restart. |
| 35 |
|
| 36 |
(* autorewrite does not work: *) |
| 37 |
autorewrite with foo_db. |
| 38 |
match goal with |
| 39 |
| [ |- 4 - 5 + 5 + 3 + (1 - 3 + 3) + 1 = 6 + (5 - 6 + 6) ] => fail |
| 40 |
| _ => idtac |
| 41 |
end. |
| 42 |
Restart. |
| 43 |
|
| 44 |
(* Analogously, autorewrite* should work, but it does not! |
| 45 |
FEATURE REQUEST: Make this work *) |
| 46 |
autorewrite* with foo_db. |
| 47 |
match goal with |
| 48 |
| [ |- 4 - 5 + 5 + 3 + (1 - 3 + 3) + 1 = 6 + (5 - 6 + 6) ] => idtac |
| 49 |
end. |
| 50 |
Restart. |
| 51 |
|
| 52 |
(* For the record, a verbose workaround: *) |
| 53 |
repeat match goal with |
| 54 |
| |- context [?a - ?b + ?b] => rewrite (foo a b) by solve_leb |
| 55 |
end. |
| 56 |
match goal with |
| 57 |
| [ |- 4 - 5 + 5 + 3 + (1 - 3 + 3) + 1 = 6 + (5 - 6 + 6) ] => idtac |
| 58 |
end. |
| 59 |
reflexivity. |
| 60 |
Qed. |
| 61 |
End First. |
| 62 |
Module Second. |
| 63 |
Axiom cond : Z -> Prop. |
| 64 |
Axiom rewrite : forall z, cond z -> z = Z0. |
| 65 |
|
| 66 |
Global Hint Rewrite |
| 67 |
rewrite |
| 68 |
using assumption |
| 69 |
: max. |
| 70 |
|
| 71 |
Axiom have_cond: forall j, cond j. |
| 72 |
|
| 73 |
Goal forall i j, cond i -> Z.max i j = Z.max i Z0. |
| 74 |
Proof. |
| 75 |
intros. |
| 76 |
autorewrite with max. (* works as expected *) |
| 77 |
autorewrite* with max. (* works as expected *) |
| 78 |
pose proof (have_cond j). |
| 79 |
autorewrite* with max. |
| 80 |
reflexivity. |
| 81 |
Qed. |
| 82 |
End Second. |