forked from plclub/metalib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FSetWeakNotin.v
271 lines (216 loc) · 6.17 KB
/
FSetWeakNotin.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
(* This file is distributed under the terms of the MIT License, also
known as the X11 Licence. A copy of this license is in the README
file that accompanied the original distribution of this file.
Based on code written by:
Brian Aydemir
Arthur Charg\'eraud *)
(** Lemmas and tactics for working with and solving goals related to
non-membership in finite sets. The main tactic of interest here
is [solve_notin].
Implicit arguments are declared by default in this library. *)
Require Import Coq.FSets.FSetInterface.
Require Import CoqFSetDecide.
(* *********************************************************************** *)
(** * Implementation *)
Module Notin_fun
(E : DecidableType) (Import X : FSetInterface.WSfun E).
Module Import D := CoqFSetDecide.WDecide_fun E X.
(* *********************************************************************** *)
(** * Facts about set non-membership *)
Section Lemmas.
Variables x y : elt.
Variable s s' : X.t.
Lemma notin_empty_1 :
~ In x empty.
Proof. fsetdec. Qed.
Lemma notin_add_1 :
~ In y (add x s) ->
~ E.eq x y.
Proof. fsetdec. Qed.
Lemma notin_add_1' :
~ In y (add x s) ->
x <> y.
Proof. fsetdec. Qed.
Lemma notin_add_2 :
~ In y (add x s) ->
~ In y s.
Proof. fsetdec. Qed.
Lemma notin_add_3 :
~ E.eq x y ->
~ In y s ->
~ In y (add x s).
Proof. fsetdec. Qed.
Lemma notin_singleton_1 :
~ In y (singleton x) ->
~ E.eq x y.
Proof. fsetdec. Qed.
Lemma notin_singleton_1' :
~ In y (singleton x) ->
x <> y.
Proof. fsetdec. Qed.
Lemma notin_singleton_2 :
~ E.eq x y ->
~ In y (singleton x).
Proof. fsetdec. Qed.
Lemma notin_remove_1 :
~ In y (remove x s) ->
E.eq x y \/ ~ In y s.
Proof. fsetdec. Qed.
Lemma notin_remove_2 :
~ In y s ->
~ In y (remove x s).
Proof. fsetdec. Qed.
Lemma notin_remove_3 :
E.eq x y ->
~ In y (remove x s).
Proof. fsetdec. Qed.
Lemma notin_remove_3' :
x = y ->
~ In y (remove x s).
Proof. fsetdec. Qed.
Lemma notin_union_1 :
~ In x (union s s') ->
~ In x s.
Proof. fsetdec. Qed.
Lemma notin_union_2 :
~ In x (union s s') ->
~ In x s'.
Proof. fsetdec. Qed.
Lemma notin_union_3 :
~ In x s ->
~ In x s' ->
~ In x (union s s').
Proof. fsetdec. Qed.
Lemma notin_inter_1 :
~ In x (inter s s') ->
~ In x s \/ ~ In x s'.
Proof. fsetdec. Qed.
Lemma notin_inter_2 :
~ In x s ->
~ In x (inter s s').
Proof. fsetdec. Qed.
Lemma notin_inter_3 :
~ In x s' ->
~ In x (inter s s').
Proof. fsetdec. Qed.
Lemma notin_diff_1 :
~ In x (diff s s') ->
~ In x s \/ In x s'.
Proof. fsetdec. Qed.
Lemma notin_diff_2 :
~ In x s ->
~ In x (diff s s').
Proof. fsetdec. Qed.
Lemma notin_diff_3 :
In x s' ->
~ In x (diff s s').
Proof. fsetdec. Qed.
End Lemmas.
(* *********************************************************************** *)
(** * Hints *)
Hint Resolve
@notin_empty_1 @notin_add_3 @notin_singleton_2 @notin_remove_2
@notin_remove_3 @notin_remove_3' @notin_union_3 @notin_inter_2
@notin_inter_3 @notin_diff_2 @notin_diff_3.
(* *********************************************************************** *)
(** * Tactics for non-membership *)
(** [destruct_notin] decomposes all hypotheses of the form [~ In x s]. *)
Ltac destruct_notin :=
match goal with
| H : In ?x ?s -> False |- _ =>
change (~ In x s) in H;
destruct_notin
| |- In ?x ?s -> False =>
change (~ In x s);
destruct_notin
| H : ~ In _ empty |- _ =>
clear H;
destruct_notin
| H : ~ In ?y (add ?x ?s) |- _ =>
let J1 := fresh "NotInTac" in
let J2 := fresh "NotInTac" in
pose proof H as J1;
pose proof H as J2;
apply notin_add_1 in H;
apply notin_add_1' in J1;
apply notin_add_2 in J2;
destruct_notin
| H : ~ In ?y (singleton ?x) |- _ =>
let J := fresh "NotInTac" in
pose proof H as J;
apply notin_singleton_1 in H;
apply notin_singleton_1' in J;
destruct_notin
| H : ~ In ?y (remove ?x ?s) |- _ =>
let J := fresh "NotInTac" in
apply notin_remove_1 in H;
destruct H as [J | J];
destruct_notin
| H : ~ In ?x (union ?s ?s') |- _ =>
let J := fresh "NotInTac" in
pose proof H as J;
apply notin_union_1 in H;
apply notin_union_2 in J;
destruct_notin
| H : ~ In ?x (inter ?s ?s') |- _ =>
let J := fresh "NotInTac" in
apply notin_inter_1 in H;
destruct H as [J | J];
destruct_notin
| H : ~ In ?x (diff ?s ?s') |- _ =>
let J := fresh "NotInTac" in
apply notin_diff_1 in H;
destruct H as [J | J];
destruct_notin
| _ =>
idtac
end.
(** [solve_notin] decomposes hypotheses of the form [~ In x s] and
then tries some simple heuristics for solving the resulting
goals. *)
Ltac solve_notin :=
intros;
destruct_notin;
repeat first [ apply notin_union_3
| apply notin_add_3
| apply notin_singleton_2
| apply notin_empty_1
];
auto;
try tauto;
fail "Not solvable by [solve_notin]; try [destruct_notin]".
(* *********************************************************************** *)
(** * Examples and test cases *)
(** These examples and test cases are not meant to be exhaustive. *)
Lemma test_solve_notin_1 : forall x E F G,
~ In x (union E F) ->
~ In x G ->
~ In x (union E G).
Proof. solve_notin. Qed.
Lemma test_solve_notin_2 : forall x y E F G,
~ In x (union E (union (singleton y) F)) ->
~ In x G ->
~ In x (singleton y) /\ ~ In y (singleton x).
Proof. split. solve_notin. solve_notin. Qed.
Lemma test_solve_notin_3 : forall x y,
~ E.eq x y ->
~ In x (singleton y) /\ ~ In y (singleton x).
Proof. split. solve_notin. solve_notin. Qed.
Lemma test_solve_notin_4 : forall x y E F G,
~ In x (union E (union (singleton x) F)) ->
~ In y G.
Proof. solve_notin. Qed.
Lemma test_solve_notin_5 : forall x y E F,
~ In x (union E (union (singleton y) F)) ->
~ In y E ->
~ E.eq y x /\ ~ E.eq x y.
Proof. split. solve_notin. solve_notin. Qed.
Lemma test_solve_notin_6 : forall x y E,
~ In x (add y E) ->
~ E.eq x y /\ ~ In x E.
Proof. split. solve_notin. solve_notin. Qed.
Lemma test_solve_notin_7 : forall x,
~ In x (singleton x) ->
False.
Proof. solve_notin. Qed.
End Notin_fun.