-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtactics.v
185 lines (159 loc) · 4.34 KB
/
tactics.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
Require Import LibTactics.
Tactic Notation "remember_simple" constr(t) :=
let h := fresh "H"
in remember t as h;
match goal with
| H' : h = _ |- _ => clear H'
end.
Tactic Notation "remember_simple" constr(t) "as" ident(h) :=
remember t as h;
match goal with
| H' : h = _ |- _ => clear H'
end.
Ltac is_not_imp :=
match goal with
[H: _ -> _ |- _] => fail 1
| [H: _ |- _] => idtac
end.
Ltac decompose_ex H :=
repeat match type of H with
| ex (fun x => _) =>
let x := fresh x in
destruct H as [x H]
| sig (fun x => _) =>
let x := fresh x in
destruct H as [x H]
end.
Ltac super_destruct :=
repeat
match goal with
[H: exists _, _ |- _] =>
decompose_ex H
| [H: { _ | _} |- _] =>
decompose_ex H
| [ H : context [ _ /\ _ ] |- _ ] =>
destruct H
end.
Ltac super_destruct' :=
repeat
match goal with
[H: exists _, _ |- _] =>
decompose_ex H
| [H: { _ | _} |- _] =>
decompose_ex H
| [ H : _ /\ _ |- _ ] =>
destruct H
end.
Tactic Notation "injects" :=
match goal with
[H: _ = _ |- _] => injects H
end.
Ltac destruct_exists :=
repeat match goal with
[H: exists _, _ |- _] =>
decompose_ex H; try subst
end.
Ltac specialize_gen:=
match goal with
| [ H : ?F -> _ ,
H' : ?F |- _] =>
specialize (H H')
| [ H : ?X = ?X -> _ |- _ ] =>
let h := fresh "H"
in
assert (X = X) by auto;
specialize (H h);
clear h
| [H : ?X <> ?Y -> _ |- _] =>
let h := fresh "H"
in assert (X <> Y) as h by (intro H_absurd; discriminate H_absurd);
specialize (H h); clear h
end.
Ltac rewrite_inj :=
repeat match goal with
| [H1: ?X = ?Y, H2: ?X = ?Z |- _] =>
rewrite -> H1 in H2
| [H: Some _ = Some _ |- _] =>
injects H
end;
repeat match goal with
[H: ?X = ?X |- _] => clear H
end.
Ltac deep_rewrite :=
match goal with
[H1: ?X = ?Y, H2: context[?X] |- _] =>
rewrite -> H1 in H2
end.
Ltac decide_exist :=
match goal with
[H: ?X = _ |- context[match ?X with _ => _ end]] =>
rewrite -> H
| [H: ?X <> _ |- context[match ?X with _ => _ end]] =>
destruct X; try solve[exfalso; eauto]
end.
Ltac decide_if :=
match goal with
[H: ?X = _ |- context[if ?X then _ else _]] =>
rewrite -> H
end.
Tactic Notation "decide_exist" "in" "*" :=
match goal with
[H: ?X = _, H2: context[match ?X with _ => _ end] |- _] =>
rewrite -> H in H2
end.
Tactic Notation "decide_if" "in" "*" :=
match goal with
[H: ?X = _, H2: context[if ?X then _ else _] |- _] =>
rewrite -> H in H2
end.
Tactic Notation "_rewrite" "->" uconstr(H) "in" "*" :=
match goal with
[H2: _ |- _] =>
rewrite -> H in H2
end.
Tactic Notation "_rewrite" "<-" uconstr(H) "in" "*" :=
match goal with
[H2: _ |- _] =>
rewrite <- H in H2
end.
Tactic Notation "_rewrite" "->" uconstr(H1) "in" "*" "by" tactic(t) :=
match goal with
[H3: _ |- _] =>
rewrite -> H1 in H3 by t
end.
Tactic Notation "_rewrite" "<-" uconstr(H) "in" "*" "by" tactic(t) :=
match goal with
[H2: _ |- _] =>
rewrite <- H in H2 by t
end.
Tactic Notation "_apply " uconstr(H) "in" "*" :=
repeat match goal with
[H2: _ |- _] =>
apply H in H2
end.
Ltac edestructs_conjunction_tactic N T :=
match N with
| 2 => edestruct T as [? ?]
| 3 => edestruct T as [? [? ?]] | 4 => edestruct T as [? [? [? ?]]] | 5 => edestruct T as [? [? [? [? ?]]]] | 6 => edestruct T as [? [? [? [? [? ?]]]]] | 7 => edestruct T as [? [? [? [? [? [? ?]]]]]] end.
Tactic Notation "edestructs" constr(T) :=
let TT := type of T in
let N := get_term_conjunction_arity TT in
edestructs_conjunction_tactic N T.
Ltac break_match_hyp :=
match goal with
| [ H : context [ match ?X with _ => _ end ] |- _] =>
match type of X with
| sumbool _ _ => destruct X
| _ => destruct X eqn:?
end
end.
Ltac break_match_goal :=
match goal with
| [ |- context [ match ?X with _ => _ end ] ] =>
match type of X with
| sumbool _ _ => destruct X
| _ => destruct X eqn:?
end
end.
Ltac break_match := break_match_goal || break_match_hyp.
Ltac constructors_dont_have_fixed_points t := induction t ; inversion 1 ; auto ; try congruence.