-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheories.v
340 lines (265 loc) · 9.68 KB
/
Theories.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
Require Import FOL.
Require Import Deduction.
Require Import Tarski.
Require Import List.
Require Import Arith.PeanoNat.
From Equations Require Import Equations.
Require Import Coq.Logic.Eqdep_dec.
Definition subset_T `{funcs_signature, preds_signature} (T1 T2 : theory) := forall (phi : form), phi t∈ T1 -> phi t∈ T2.
Infix "⊑" := subset_T (at level 20).
Definition extend `{funcs_signature, preds_signature} T (phi : form) := fun psi => T psi \/ psi = phi.
Infix "⋄" := extend (at level 20).
Section Theories.
Context {Σ_funcs : funcs_signature}.
Context {Σ_preds : preds_signature}.
Context {p : peirce}.
Definition mapT (f : form -> form) (T : theory) : theory := fun phi => exists psi, T psi /\ f psi = phi.
(** Equality deciders *)
Context {eq_dec_Funcs : EqDec syms}.
Context {eq_dec_Preds : EqDec preds}.
Instance eqdec_vec X {DX : EqDec X} n : EqDec (Vector.t X n).
Proof.
intros x y. apply Vector.eq_dec with (A_beq := fun a b => if DX a b then true else false). intros a b. now destruct (DX a b).
Qed.
Lemma eqdec_vec_in X n (v : vec X n) :
(forall x, vec_in x v -> forall y, {x = y} + {x <> y}) -> forall v', {v = v'} + {v <> v'}.
Proof.
intros Hv. induction v.
- intros v'. dependent elimination v'. now left.
- intros v'. dependent elimination v'. destruct (Hv h (vec_inB h v) h0) as [->|].
destruct ((IHv (fun x H => Hv x (vec_inS x h0 v H))) t) as [->|]. now left.
right. intros [=]. apply inj_pair2_eq_dec in H0. auto. intros x y. decide equality.
right. congruence.
Qed.
Global Instance eqdec_term : EqDec term.
Proof.
intros x. induction x.
- destruct y. destruct (eq_dec x n) as [->|]. now left. right. congruence.
right. congruence.
- destruct y. right. congruence. destruct (eq_dec F f) as [->|].
assert ({v = v0} + {v <> v0}) as [->|]. { apply eqdec_vec_in. exact X. }
now left. right. intros [=]. apply inj_pair2_eq_dec in H0. auto. exact eq_dec.
right. congruence.
Qed.
Global Instance eqdec_form : EqDec form.
Proof.
intros x. induction x; destruct y; try (right; congruence).
- now left.
- destruct (eq_dec P P0) as [->|]. destruct (eq_dec v v0) as [->|].
now left. right. intros [=]. apply inj_pair2_eq_dec in H0. auto. exact eq_dec.
right. congruence.
- destruct b, b0; try (right; congruence);
destruct (IHx1 y1) as [->|], (IHx2 y2) as [->|]; try (now left); try (right; congruence).
- destruct q, q0; try (right; congruence);
destruct (IHx y) as [->|]; try (now left); try (right; congruence).
Qed.
(* Now we can define removal from formula lists *)
Definition rem := @remove form eq_dec.
(* Inductive unused_term (n : nat) : term -> Prop :=
| uft_var m : n <> m -> unused_term n ($m)
| uft_Func F v : (forall t, vec_in t v -> unused_term n t) -> unused_term n (func F v).
Inductive unused (n : nat) : form -> Prop :=
| uf_Fal : unused n fal
| uf_Pred P v : (forall t, vec_in t v -> unused_term n t) -> unused n (atom P v)
| uf_Bin op phi psi : unused n phi -> unused n psi -> unused n (bin op phi psi)
| uf_Quant op phi : unused (S n) phi -> unused n (quant op phi).
Definition closed_theory (T : theory) := forall phi, phi t∈ T -> closed phi = true.
Lemma subst_closed s phi :
closed phi = true -> phi[s] = phi.
Proof.
Admitted. *)
Theorem WeakT A B phi :
A ⊩ phi -> A ⊑ B -> B ⊩ phi.
Proof.
intros H. revert B.
induction H; intros B HB; try unshelve (solve [econstructor; intuition]); try now econstructor.
Qed.
Lemma contains_nil T :
List.nil ⊏ T.
Proof. intuition. now exfalso. Qed.
Lemma contains_cons a A T :
a t∈ T -> A ⊏ T -> (a :: A) ⊏ T.
Proof. intros ? ? ? []; subst; intuition. Qed.
Lemma contains_cons2 a A T :
(a :: A) ⊏ T -> A ⊏ T.
Proof. firstorder. Qed.
Lemma contains_app A B T :
A ⊏ T -> B ⊏ T -> (A ++ B) ⊏ T.
Proof. intros ? ? ? [] % in_app_or; intuition. Qed.
Lemma contains_extend1 phi T :
phi t∈ (T ⋄ phi).
Proof. now right. Qed.
Lemma contains_extend2 phi psi T :
phi t∈ T -> phi t∈ (T ⋄ psi).
Proof. intros ?. now left. Qed.
Lemma contains_extend3 A T phi :
A ⊏ T -> A ⊏ (T ⋄ phi).
Proof.
intros ? ? ?. left. intuition.
Qed.
Lemma subset_refl T :
T ⊑ T.
Proof.
firstorder.
Qed.
Lemma subset_trans T1 T2 T3 :
T1 ⊑ T2 -> T2 ⊑ T3 -> T1 ⊑ T3.
Proof.
firstorder.
Qed.
Lemma contains_rem A T phi :
A ⊏ T ⋄ phi -> rem phi A ⊏ T.
Proof.
intros H1. induction A. firstorder. cbn. destruct (eq_dec phi a) as [->|H2].
- apply IHA. eapply contains_cons2, H1.
- apply contains_cons. destruct (H1 a) as [| ->]; firstorder.
apply IHA. eapply contains_cons2, H1.
Qed.
Lemma incl_rem1 A phi :
rem phi A <<= A.
Proof.
induction A. firstorder. cbn. destruct (eq_dec phi a) as [-> |]; firstorder.
Qed.
Lemma incl_rem2 A phi :
A <<= phi :: rem phi A.
Proof.
induction A. firstorder. cbn. destruct (eq_dec phi a) as [-> |]; firstorder.
Qed.
Definition shift_down := fun n => match n with 0 => $0 | S n => $n end.
Lemma map_shift_up_down_contains A T :
(A ⊏ mapT (subst_form ↑) T) -> map (subst_form shift_down) A ⊏ T.
Proof.
intros H1. induction A. easy. intros f H. destruct H as [<-|].
- destruct (H1 a) as [f [H2 <-]]. now left. change (f[↑][shift_down] t∈ T).
enough (f[↑][shift_down] = f) as -> by easy.
rewrite subst_comp. now apply subst_id.
- firstorder.
Qed.
Lemma map_shift_up_down_eq A T :
A ⊏ mapT (subst_form ↑) T -> map (subst_form ↑) (map (subst_form shift_down) A) = A.
Proof.
intros H1. induction A. reflexivity. cbn. f_equal.
- destruct (H1 a) as [f [H2 <-]]. now left.
enough (f[↑ >> subst_term shift_down][↑] = f[↑]) as X by now rewrite <- subst_comp in X.
f_equal. now apply subst_id.
- firstorder.
Qed.
(** Prv translations *)
Lemma T_II T phi psi :
T ⋄ phi ⊩ psi -> T ⊩ (phi --> psi).
Proof.
intros [A[H1 H2]]. exists (rem phi A). split.
intros ? ?%in_remove. firstorder.
apply II. eapply Weak. apply H2. apply incl_rem2.
Qed.
Lemma T_IE T phi psi :
T ⊩ (phi --> psi) -> T ⊩ phi -> T ⊩ psi.
Proof.
intros [A[A1 A2]] [B[B1 B2]]. exists (A++B). split.
now apply contains_app. apply IE with phi.
eapply Weak. apply A2. now apply incl_appl.
eapply Weak. apply B2. now apply incl_appr.
Qed.
Lemma T_AllI T phi :
mapT (subst_form ↑) T ⊩ phi -> T ⊩ ∀ phi.
Proof.
intros [A[H1 H2]].
exists (map (subst_form shift_down) A). split.
- now apply map_shift_up_down_contains.
- apply AllI. erewrite map_shift_up_down_eq; auto.
Qed.
Lemma T_AllE T t phi :
(T ⊩ ∀ phi) -> T ⊩ phi[t..].
Proof.
intros [A[H1 H2]]. exists A. split. firstorder. now apply AllE.
Qed.
Lemma T_ExI T t phi :
T ⊩ phi[t..] -> T ⊩ ∃ phi.
Proof.
intros [A[A1 A2]]. exists A. split. firstorder. now apply ExI with t.
Qed.
Lemma T_ExE T phi psi :
(T ⊩ ∃ phi) -> (mapT (subst_form ↑) T) ⋄ phi ⊩ psi[↑] -> T ⊩ psi.
Proof.
intros [A[A1 A2]] [B[B1 B2]].
exists (A ++ map (subst_form shift_down) (rem phi B)). split.
- apply contains_app. assumption. apply map_shift_up_down_contains.
now apply contains_rem.
- eapply ExE.
+ eapply Weak. apply A2. now apply incl_appl.
+ eapply Weak. apply B2. rewrite map_app. erewrite map_shift_up_down_eq with (T := T).
eapply incl_tran with (m := phi :: rem phi B). apply incl_rem2.
apply incl_cons. now left. apply incl_tl. now apply incl_appr.
clear B2. induction B. firstorder. cbn. destruct (eq_dec phi a) as [-> |].
* firstorder.
* apply contains_cons. destruct (B1 a) as [| ->]. now left. assumption.
apply IHB. eapply contains_cons2, B1. easy. firstorder.
Qed.
Lemma T_Exp T phi :
T ⊩ ⊥ -> T ⊩ phi.
Proof.
intros [A[H1 H2]]. exists A. split. firstorder. now apply Exp.
Qed.
Lemma T_Ctx T phi :
phi t∈ T -> T ⊩ phi.
Proof.
intros H. exists (phi::nil). split.
intros psi H2. now assert (phi = psi) as -> by firstorder.
apply Ctx. now left.
Qed.
Lemma T_CI T phi psi :
T ⊩ phi -> T ⊩ psi -> T ⊩ (phi ∧ psi).
Proof.
intros [A[A1 A2]] [B[B1 B2]]. exists (A++B). split.
now apply contains_app. apply CI.
eapply Weak. apply A2. now apply incl_appl.
eapply Weak. apply B2. now apply incl_appr.
Qed.
Lemma T_CE1 T phi psi :
T ⊩ (phi ∧ psi) -> T ⊩ phi.
Proof.
intros [A[H1 H2]]. exists A. split. assumption. eapply CE1. apply H2.
Qed.
Lemma T_CE2 T phi psi :
T ⊩ (phi ∧ psi) -> T ⊩ psi.
Proof.
intros [A[H1 H2]]. exists A. split. assumption. eapply CE2. apply H2.
Qed.
Lemma T_DI1 T phi psi :
T ⊩ phi -> T ⊩ (phi ∨ psi).
Proof.
intros [A[H1 H2]]. exists A. split. assumption. eapply DI1. apply H2.
Qed.
Lemma T_DI2 T phi psi :
T ⊩ psi -> T ⊩ (phi ∨ psi).
Proof.
intros [A[H1 H2]]. exists A. split. assumption. eapply DI2. apply H2.
Qed.
Lemma T_DE T phi psi theta :
T ⊩ (phi ∨ psi) -> T ⋄ phi ⊩ theta -> T ⋄ psi ⊩ theta -> T ⊩ theta.
Proof.
intros [A[A1 A2]] [B[B1 B2]] [C[C1 C2]].
exists (A ++ (rem phi B) ++ (rem psi C)). split.
- apply contains_app. assumption. apply contains_app.
intros ? ?%in_remove. firstorder. intros ? ?%in_remove. firstorder.
- eapply DE. eapply Weak. apply A2. now apply incl_appl.
+ eapply Weak. apply B2. apply incl_tran with (m := phi::rem phi B).
apply incl_rem2. apply incl_cons. now left.
now apply incl_tl, incl_appr, incl_appl.
+ eapply Weak. apply C2. apply incl_tran with (m := psi::rem psi C).
apply incl_rem2. apply incl_cons. now left.
now apply incl_tl, incl_appr, incl_appr.
Qed.
Lemma T_Pc T phi psi :
T ⊩C (((phi --> psi) --> phi) --> phi).
Proof.
exists nil. split. firstorder. apply Pc.
Qed.
Lemma switch_imp_T T alpha phi : T ⊩ (alpha --> phi) <-> (T ⋄ alpha) ⊩ phi.
Proof.
split.
- intros H. eapply T_IE. 2: apply T_Ctx. eapply WeakT.
exact H. all : firstorder.
- apply T_II.
Qed.
End Theories.