-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimplMatch.v
81 lines (73 loc) · 2.25 KB
/
SimplMatch.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(** ** Simplify matches when possible *)
Ltac simpl_match :=
let repl_match_goal d d' :=
replace d with d';
lazymatch goal with
| [ |- context[match d' with _ => _ end] ] => fail
| _ => idtac
end in
let repl_match_hyp H d d' :=
replace d with d' in H;
lazymatch type of H with
| context[match d' with _ => _ end] => fail
| _ => idtac
end in
match goal with
| [ Heq: ?d = ?d' |- context[match ?d with _ => _ end] ] =>
repl_match_goal d d'
| [ Heq: ?d' = ?d |- context[match ?d with _ => _ end] ] =>
repl_match_goal d d'
| [ Heq: ?d = ?d', H: context[match ?d with _ => _ end] |- _ ] =>
repl_match_hyp H d d'
| [ Heq: ?d' = ?d, H: context[match ?d with _ => _ end] |- _ ] =>
repl_match_hyp H d d'
end.
(** ** Find and destruct matches *)
Ltac destruct_matches_in e :=
lazymatch e with
| context[match ?d with | _ => _ end] =>
destruct_matches_in d
| _ => destruct e eqn:?; intros
end.
Ltac destruct_all_matches :=
repeat (try simpl_match;
try match goal with
| [ |- context[match ?d with | _ => _ end] ] =>
destruct_matches_in d
| [ H: context[match ?d with | _ => _ end] |- _ ] =>
destruct_matches_in d
end);
subst;
try congruence;
auto.
Ltac destruct_nongoal_matches :=
repeat (try simpl_match;
try match goal with
| [ H: context[match ?d with | _ => _ end] |- _ ] =>
destruct_matches_in d
end);
subst;
try congruence;
auto.
Ltac destruct_goal_matches :=
repeat (try simpl_match;
match goal with
| [ |- context[match ?d with | _ => _ end] ] =>
destruct_matches_in d
end);
try congruence;
auto.
Ltac destruct_tuple :=
match goal with
| [ H: context[let '(a, b) := ?p in _] |- _ ] =>
let a := fresh a in
let b := fresh b in
destruct p as [a b]
| [ |- context[let '(a, b) := ?p in _] ] =>
let a := fresh a in
let b := fresh b in
destruct p as [a b]
end.
Tactic Notation "destruct" "matches" "in" "*" := destruct_all_matches.
Tactic Notation "destruct" "matches" "in" "*|-" := destruct_nongoal_matches.
Tactic Notation "destruct" "matches" := destruct_goal_matches.