| 1 |
(** * Machinery for reimplementing some bits of [rewrite_strat] with open pattern databases *) |
| 2 |
Require Import Crypto.Util.Notations. |
| 3 |
(** We build classes for rewriting in each direction, and pick lemmas |
| 4 |
by resolving on tags and the term to be rewritten. *) |
| 5 |
(** Base class, for bidirectional rewriting. *) |
| 6 |
Class rewrite_eq {tagT} (tag : tagT) {A} (x y : A) |
| 7 |
:= by_rewrite : x = y. |
| 8 |
Arguments by_rewrite {tagT} tag {A} _ _ {_}. |
| 9 |
Infix "<~=~>" := (rewrite_eq _) : type_scope. |
| 10 |
|
| 11 |
Class rewrite_right_to_left_eq {tagT} (tag : tagT) {A} (x y : A) |
| 12 |
:= by_rewrite_right_to_left : rewrite_eq tag x y. |
| 13 |
Arguments by_rewrite_right_to_left {tagT} tag {A} _ _ {_}. |
| 14 |
Global Instance unfold_rewrite_right_to_left_eq {tagT tag A x y} (H : @rewrite_eq tagT tag A x y) |
| 15 |
: @rewrite_right_to_left_eq tagT tag A x y := H. |
| 16 |
Infix "<~=" := (rewrite_right_to_left_eq _) : type_scope. |
| 17 |
|
| 18 |
Class rewrite_left_to_right_eq {tagT} (tag : tagT) {A} (x y : A) |
| 19 |
:= by_rewrite_left_to_right : rewrite_eq tag x y. |
| 20 |
Arguments by_rewrite_left_to_right {tagT} tag {A} _ _ {_}. |
| 21 |
Global Instance unfold_rewrite_left_to_right_eq {tagT tag A x y} (H : @rewrite_eq tagT tag A x y) |
| 22 |
: @rewrite_left_to_right_eq tagT tag A x y := H. |
| 23 |
Infix "=~>" := (rewrite_left_to_right_eq _) : type_scope. |
| 24 |
|
| 25 |
Ltac typeclass_do_left_to_right tag from tac := |
| 26 |
let lem := constr:(by_rewrite_left_to_right tag from _ : from = _) in tac lem. |
| 27 |
Ltac typeclass_do_right_to_left tag from tac := |
| 28 |
let lem := constr:(by_rewrite_right_to_left tag _ from : _ = from) in tac lem. |
| 29 |
|
| 30 |
|
| 31 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" open_constr(from) "->" := |
| 32 |
typeclass_do_left_to_right tag from ltac:(fun lem => rewrite -> lem). |
| 33 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" open_constr(from) "->" "in" "*" := |
| 34 |
typeclass_do_left_to_right tag from ltac:(fun lem => rewrite -> lem in * ). |
| 35 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" open_constr(from) "->" "in" hyp_list(H) := |
| 36 |
typeclass_do_left_to_right tag from ltac:(fun lem => rewrite -> lem in H). |
| 37 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" open_constr(from) "->" "in" hyp_list(H) "|-" "*" := |
| 38 |
typeclass_do_left_to_right tag from ltac:(fun lem => rewrite -> lem in H |- *). |
| 39 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" open_constr(from) "->" "in" "*" "|-" "*" := |
| 40 |
typeclass_do_left_to_right tag from ltac:(fun lem => rewrite -> lem in * |- * ). |
| 41 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" open_constr(from) "->" "in" "*" "|-" := |
| 42 |
typeclass_do_left_to_right tag from ltac:(fun lem => rewrite -> lem in * |- ). |
| 43 |
|
| 44 |
|
| 45 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" "<-" open_constr(from) := |
| 46 |
typeclass_do_right_to_left tag from ltac:(fun lem => rewrite <- lem). |
| 47 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" "<-" open_constr(from) "in" "*" := |
| 48 |
typeclass_do_right_to_left tag from ltac:(fun lem => rewrite <- lem in * ). |
| 49 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" "<-" open_constr(from) "in" hyp_list(H) := |
| 50 |
typeclass_do_right_to_left tag from ltac:(fun lem => rewrite <- lem in H). |
| 51 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" "<-" open_constr(from) "in" hyp_list(H) "|-" "*" := |
| 52 |
typeclass_do_right_to_left tag from ltac:(fun lem => rewrite <- lem in H |- *). |
| 53 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" "<-" open_constr(from) "in" "*" "|-" "*" := |
| 54 |
typeclass_do_right_to_left tag from ltac:(fun lem => rewrite <- lem in * |- * ). |
| 55 |
Tactic Notation "tc_rewrite" "(" open_constr(tag) ")" "<-" open_constr(from) "in" "*" "|-" := |
| 56 |
typeclass_do_right_to_left tag from ltac:(fun lem => rewrite <- lem in * |- ). |