-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPA.v
473 lines (350 loc) · 14.8 KB
/
PA.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
Require Import FOL.
Require Import Deduction.
Require Import Tarski.
Require Import VectorTech.
Require Import List.
Require Import Lia.
(* I follow the treatment of Peter Smith in "Introduction to Gödel's Theorems"
(page 37) *)
(* Define the non-logical symbols used in the language of PA *)
Inductive PA_funcs : Type :=
Zero : PA_funcs
| Succ : PA_funcs
| Plus : PA_funcs
| Mult : PA_funcs.
Definition PA_funcs_ar (f : PA_funcs ) :=
match f with
| Zero => 0
| Succ => 1
| Plus => 2
| Mult => 2
end.
Inductive PA_preds : Type :=
Eq : PA_preds.
Definition PA_preds_ar (P : PA_preds) :=
match P with
| Eq => 2
end.
Instance PA_funcs_signature : funcs_signature :=
{| syms := PA_funcs ; ar_syms := PA_funcs_ar |}.
Instance PA_preds_signature : preds_signature :=
{| preds := PA_preds ; ar_preds := PA_preds_ar |}.
Arguments Vector.cons {_} _ {_} _, _ _ _ _.
Definition zero := func Zero (Vector.nil term).
Notation "'σ' x" := (@func PA_funcs_signature Succ (Vector.cons x (Vector.nil term))) (at level 37).
Notation "x '⊕' y" := (@func PA_funcs_signature Plus (Vector.cons x (Vector.cons y (Vector.nil term))) ) (at level 39).
Notation "x '⊗' y" := (@func PA_funcs_signature Mult (Vector.cons x (Vector.cons y (Vector.nil term))) ) (at level 38).
Notation "x '==' y" := (@atom PA_funcs_signature PA_preds_signature _ Eq (Vector.cons term x 1 (Vector.cons term y 0 (Vector.nil term))) ) (at level 40).
Fixpoint num n :=
match n with
O => zero
| S x => σ (num x)
end.
(* formulate axioms of PA (see page 92) *)
Definition ax_zero_succ := ∀ zero == σ $0 --> fal.
Definition ax_succ_inj := ∀ ∀ σ $1 == σ $0 --> $1 == $0.
Definition ax_add_zero := ∀ zero ⊕ $0 == $0.
Definition ax_add_rec := ∀ ∀ (σ $0) ⊕ $1 == σ ($0 ⊕ $1).
Definition ax_mult_zero := ∀ zero ⊗ $0 == zero.
Definition ax_mult_rec := ∀ ∀ σ $1 ⊗ $0 == $0 ⊕ $1 ⊗ $0.
Definition PA_induction (phi : form) :=
phi[zero..] --> (∀ phi --> phi[σ $0 .: S >> var]) --> ∀ phi.
Definition phi := $0 == $1.
Compute (phi[zero..]).
Compute (phi[zero .: S >> var]).
(* substitutes t for the variable $0 and leaves all other variables unchanged *)
Definition var0_subst (t : term) : nat -> term :=
fun n => match n with 0 => t | S n => var (S n) end.
(* var0_subst can be expressed with scons and funcomp *)
Lemma var0_subst_spec t n :
var0_subst t n = (t .: S >> var) n.
Proof.
now destruct n as [].
Qed.
(*** Working in models of PA ***)
Section Models.
Variable D : Type.
Variable I : interp D.
Definition Equality := forall v, @i_P _ _ D I Eq v <-> Vector.hd v = Vector.hd (Vector.tl v).
Hypothesis equality : forall v, @i_P _ _ D I Eq v <-> Vector.hd v = Vector.hd (Vector.tl v).
(* The following predicate expresses that a model satisfies the minimal axioms of PA i.e. all axioms except S x <> 0 *)
Definition sat_PA_minimal_axioms :=
forall rho,
rho ⊨_FOL ax_succ_inj
/\ rho ⊨_FOL ax_add_zero
/\ rho ⊨_FOL ax_add_rec
/\ rho ⊨_FOL ax_mult_zero
/\ rho ⊨_FOL ax_mult_rec
/\ (forall phi, rho ⊨_FOL (PA_induction phi) ).
Definition sat_PA_axioms :=
sat_PA_minimal_axioms /\ forall rho, rho ⊨_FOL ax_zero_succ.
Lemma PAeq_sym : forall rho a b, rho ⊨_FOL (a == b) -> rho ⊨_FOL (b == a).
Proof.
intros rho a b H. apply equality; cbn. apply equality in H; cbn in H. auto.
Qed.
Lemma PAeq_trans : forall rho a b c, rho ⊨_FOL (a == b) /\ rho ⊨_FOL (b == c) -> rho ⊨_FOL (a == c).
Proof.
intros rho a b c. cbn. rewrite !equality. cbn. intros [C B]. now rewrite C, B.
Qed.
Definition iO := i_f (f:=Zero) (Vector.nil D).
Notation "'iσ' d" := (i_f (f:=Succ) (Vector.cons d (Vector.nil D))) (at level 37).
Notation "x 'i⊕' y" := (i_f (f:=Plus) (Vector.cons x (Vector.cons y (Vector.nil D)))) (at level 39).
Notation "x 'i⊗' y" := (i_f (f:=Mult) (Vector.cons x (Vector.cons y (Vector.nil D)))) (at level 38).
Definition iμ k := iter (fun x => iσ x) k iO.
(* provide all axioms in a more useful form *)
Theorem succ_inj:
(forall rho, rho ⊨_FOL ax_succ_inj) -> forall n d, iσ d = iσ n -> d = n.
Proof.
intros H n d. specialize (H (fun _ => iO) d n).
cbn in H. rewrite !equality in H; now cbn in H.
Qed.
Theorem add_zero :
(forall rho, rho ⊨_FOL ax_add_zero) -> forall d, iO i⊕ d = d.
Proof.
intros H d. specialize (H (fun _ => iO) d).
cbn in H. rewrite equality in H; now cbn in H.
Qed.
Theorem add_rec :
(forall rho, rho ⊨_FOL ax_add_rec) -> forall n d, (iσ n) i⊕ d = iσ (n i⊕ d).
Proof.
intros H n d.
specialize (H (fun _ => iO) d n).
cbn in H. rewrite !equality in H; now cbn in H.
Qed.
Theorem mult_zero :
(forall rho, rho ⊨_FOL ax_mult_zero) -> forall d, iO i⊗ d = iO.
Proof.
intros H d. specialize (H (fun _ => iO) d).
cbn in H. rewrite !equality in H. now cbn in H.
Qed.
Theorem mult_rec :
(forall rho, rho ⊨_FOL ax_mult_rec) -> forall n d, (iσ d) i⊗ n = n i⊕ (d i⊗ n).
Proof.
intros H n d. specialize (H (fun _ => iO) d n).
cbn in H. rewrite !equality in H; now cbn in H.
Qed.
Variable AX : sat_PA_minimal_axioms.
Theorem PAinduction_weak (phi : form) rho :
rho ⊨_FOL phi[zero..] -> rho ⊨_FOL (∀ phi --> phi[σ $ 0 .: S >> var]) -> rho ⊨_FOL (∀ phi).
Proof.
destruct (AX rho) as (_&_&_&_&_&H). cbn. apply (H phi).
Qed.
Definition null := (fun _ : nat => iO).
Definition representable (P : D -> Prop) := exists phi rho, forall d, P d <-> (d.:rho) ⊨_FOL phi.
Lemma sat_single (rho : nat -> D) (Phi : form) (t : term) :
(eval rho t .: rho) ⊨_FOL Phi <-> rho ⊨_FOL subst_form (t..) Phi.
Proof.
rewrite sat_comp. apply sat_ext. now intros [].
Qed.
(** Useful induction principle *)
Theorem PAinduction (P : D -> Prop) :
representable P -> P iO -> (forall d, P d -> P (iσ d)) -> forall d, P d.
Proof.
intros (phi & rho & repr) P0 IH. intros d. rewrite repr.
apply PAinduction_weak.
- apply sat_single. apply repr. apply P0.
- cbn. intros d' H. apply repr, IH, repr in H.
apply sat_comp. eapply sat_ext; try apply H. now intros [].
Qed.
(** Examples *)
Lemma add_exists : forall (phi : form) rho, rho ⊨_FOL phi -> exists sigma, sigma ⊨_FOL (∃ phi).
Proof.
intros phi rho H; cbn. exists (fun n => match n with
| O => rho 1
| S m => rho (S n)
end); exists (rho 0).
unfold scons. eapply sat_ext; try apply H. now intros [|[|]].
Qed.
Definition exist_times n (phi : form) := iter (fun psi => ∃ psi) n phi.
Lemma add_n_exists : forall n,
forall (phi : form) rho, rho ⊨_FOL phi -> exists sigma, sigma ⊨_FOL (exist_times n phi).
Proof.
induction n; intros phi rho H.
- exists rho. auto.
- destruct (IHn _ _ H) as [s Hs]. now refine (add_exists _ s _).
Qed.
Lemma zero_or_succ : forall rho, rho ⊨_FOL (∀ zero == $0 ∨ ∃ $1 == σ $0).
Proof.
intros rho. apply PAinduction_weak.
- left. now apply equality.
- intros d _. right. exists d; now apply equality.
Qed.
Goal forall d, iO = d \/ exists x, d = iσ x.
Proof.
enough (forall rho, rho ⊨_FOL (∀ zero == $0 ∨ ∃ $1 == σ $0)) as H. intros d.
specialize (H null). cbn in H. specialize (H d). revert H.
rewrite equality. cbn.
intros [<- | [x H]]. now left. right. rewrite equality in H. now exists x.
apply zero_or_succ.
Qed.
Goal forall d, iO = d \/ exists x, d = iσ x.
Proof.
apply PAinduction.
pose (phi := zero == $0 ∨ ∃ $1 == σ $0).
- exists phi, (fun _ => iO). split.
+ intros [<- | [x ->]].
* left. cbn. now rewrite equality.
* right. exists x. cbn. now rewrite equality.
+ intros [H | [x H]].
* left. cbn in H. now rewrite equality in H.
* right. exists x. cbn in H. now rewrite equality in H.
- now left.
- intros d [<- |]; right. now exists iO. now exists d.
Qed.
Lemma add_rec_right :
forall d n, n i⊕ (iσ d) = iσ (n i⊕ d).
Proof.
intros n. apply PAinduction.
- pose (phi := ∀ $0 ⊕ σ $1 == σ ($0 ⊕ $1) ).
exists phi, (fun _ => iO). admit.
- rewrite !add_zero; try reflexivity. all: firstorder.
- intros d IH. rewrite !add_rec. now rewrite IH. all: firstorder.
Admitted.
Section TrivialModel.
Variable Bot : iμ 0 = iμ 1.
Lemma ModelHasOnlyZero' rho : rho ⊨_FOL (∀ $0 == zero).
Proof.
apply PAinduction_weak.
- cbn; now apply equality.
- cbn. fold iO. intros d. rewrite !equality; cbn. intros IH.
now rewrite IH.
Qed.
Fact ModelHasOnlyZero : forall d, d = iO.
Proof.
apply PAinduction.
pose (phi := $0 == zero).
- exists phi, (fun _ => iO). split.
+ intros ->. cbn. now rewrite equality.
+ intros H. cbn in H. now rewrite equality in H.
- reflexivity.
- intros d. now intros ->.
Qed.
Lemma trivial_induction' rho phi : rho ⊨_FOL (phi[zero..] --> ∀ phi).
Proof.
cbn. intros H0. apply PAinduction_weak.
- exact H0.
- cbn. intros d IH. apply sat_comp.
refine (@sat_ext' _ _ _ _ (d.:rho) _ phi _ _).
destruct x; cbn; rewrite ModelHasOnlyZero; apply ModelHasOnlyZero.
exact IH.
Qed.
Fact trivial_induction : forall P, representable P -> P iO -> forall d, P d.
Proof.
intros P Rep P0. apply PAinduction; try auto.
intros. now rewrite ModelHasOnlyZero.
Qed.
End TrivialModel.
End Models.
(*** Working with a Deduction System ***)
Section ND.
Variable p : peirce.
Definition FA' := ax_add_zero::ax_add_rec::ax_mult_zero::ax_mult_rec::nil.
Definition ax_refl := (∀ $0 == $0).
Definition ax_sym := (∀ ∀ $0 == $1 --> $1 == $0).
Definition ax_trans := (∀∀∀ $0 == $1 --> $1 == $2 --> $0 == $2).
Definition ax_eq_succ := (∀∀ $0 == $1 --> σ $0 == σ $1).
Definition ax_eq_add := (∀∀∀∀ $0 == $1 --> $2 == $3 --> $0 ⊕ $2 == $1 ⊕ $3).
Definition ax_eq_mult := (∀∀∀∀ $0 == $1 --> $2 == $3 --> $0 ⊗ $2 == $1 ⊗ $3).
Definition FA := ax_refl::ax_sym::ax_trans::ax_eq_succ::ax_eq_add::ax_eq_mult::FA'.
Lemma numeral_subst_invariance : forall n rho, subst_term rho (num n) = num n.
Proof.
induction n.
- reflexivity.
- intros rho. cbn. now rewrite IHn.
Qed.
Lemma term_subst_invariance t : forall rho,
bound_term 0 t = true -> subst_term rho t = t.
Proof.
induction t.
- intros ? H. inversion H.
- intros rho HB. cbn. f_equal.
enough ( Vector.map (subst_term rho) v = Vector.map id v ) as eq.
cbn in eq. rewrite eq at 1. now rewrite (Vector.map_id _ _).
apply Vector.map_ext_in.
intros x Hx. cbv [id]. apply IH.
assumption. refine (bound_term_parts _ _).
apply HB. now apply vec_map_In.
Qed.
Lemma FA_refl t :
FA ⊢_MSFOL (t == t).
Proof.
assert (FA ⊢_MSFOL ax_refl). apply Ctx. firstorder.
eapply AllE in H. cbn in H. apply H.
Qed.
Lemma FA_sym t t' :
FA ⊢_MSFOL (t == t') -> FA ⊢_MSFOL (t' == t).
Proof.
intros H. assert (H' : FA ⊢_MSFOL ax_sym). apply Ctx. firstorder.
eapply (AllE _ t') in H'. cbn in H'. apply (AllE _ t) in H'. cbn in H'.
change (FA ⊢_MSFOL (t == t'`[↑]`[t..] --> t'`[↑]`[t..] == t)) in H'.
rewrite subst_term_shift in H'. apply (IE _ _ _ H'), H.
Qed.
Lemma FA_sym' t t' :
FA ⊢_MSFOL (t == t') -> FA ⊢_MSFOL (t' == t).
Proof.
intros H. assert (H' : FA ⊢_MSFOL ax_sym). apply Ctx. firstorder.
eapply (AllE _ t') in H'. cbn in H'.
change (FA ⊢_MSFOL (∀ $0 == t'`[↑] --> t'`[↑] == $0)) in H'.
apply (AllE _ t) in H'.
change (FA ⊢_MSFOL (t == t'`[↑]`[t..] --> t'`[↑]`[t..] == t)) in H'.
rewrite subst_term_shift in H'. apply (IE _ _ _ H'), H.
Qed.
Lemma FA_tran a b c :
FA ⊢_MSFOL (a == b) -> FA ⊢_MSFOL (b == c) -> FA ⊢_MSFOL (a == c).
Proof.
intros H1 H2. assert (H : FA ⊢_MSFOL ax_trans). apply Ctx. firstorder.
apply (AllE _ c) in H. cbn in H.
change (FA ⊢_MSFOL ∀∀ $0 == $1 --> $1 == c`[↑]`[↑] --> $0 == c`[↑]`[↑]) in H.
apply (AllE _ b) in H. cbn in H.
change (FA ⊢_MSFOL ∀ $0 == b`[↑] --> b`[↑] == c`[↑]`[↑]`[up b..] --> $0 == c`[↑]`[↑]`[up b..]) in H.
apply (AllE _ a) in H. cbn in H.
change (FA ⊢_MSFOL (a == b`[↑]`[a..] --> b`[↑]`[a..] == c`[↑]`[↑]`[up b..]`[a..] --> a == c`[↑]`[↑]`[up b..]`[a..])) in H.
rewrite (up_term (c`[↑])) in H. rewrite !subst_term_shift in H.
enough (FA ⊢_MSFOL (b == c --> a == c)) as H'. apply (IE _ _ _ H'), H2.
apply (IE _ _ _ H), H1.
Qed.
(*
Definition ax_zero_succ := ∀ zero == σ var 0 --> fal.
Definition ax_succ_inj := ∀ ∀ σ $1 == σ $0 --> $1 == $0.
Definition ax_add_zero := ∀ zero ⊕ $0 == $0.
Definition ax_add_rec := ∀ ∀ (σ $0) ⊕ $1 == σ ($0 ⊕ $1).
Definition ax_mult_zero := ∀ zero ⊗ $0 == zero.
Definition ax_mult_rec := ∀ ∀ σ $1 ⊗ $0 == $0 ⊕ $1 ⊗ $0.
Definition ax_refl := (∀ $0 == $0).
Definition ax_sym := (∀ ∀ $0 == $1 --> $1 == $0).
Definition ax_trans := (∀∀∀ $0 == $1 --> $1 == $2 --> $0 == $2).
Definition ax_eq_succ := (∀∀ $0 == $1 --> σ $0 == σ $1).
Definition ax_eq_add := (∀∀∀∀ $0 == $1 --> $2 == $3 --> $0 ⊕ $2 == $1 ⊕ $3).
Definition ax_eq_mult := (∀∀∀∀ $0 == $1 --> $2 == $3 --> $0 ⊗ $2 == $1 ⊗ $3).
*)
Lemma num_add_homomorphism x y :
FA ⊢_MSFOL (num x ⊕ num y == num (x + y)).
Proof.
induction x.
- cbn. assert (H : FA ⊢_MSFOL ax_add_zero). apply Ctx. firstorder.
eapply AllE in H. apply H.
- cbn. assert (H1 : FA ⊢_MSFOL ax_add_rec). apply Ctx. firstorder.
eapply (AllE _ (num y)) in H1.
eapply (AllE _ (num x)) in H1.
cbn in H1. rewrite !numeral_subst_invariance in H1.
eapply FA_tran. exact H1.
assert (H2 : FA ⊢_MSFOL ax_eq_succ). apply Ctx. firstorder.
eapply (AllE _ ?[b]) in H2. eapply (AllE _ ?[a]) in H2. cbn in H2.
change (FA ⊢_MSFOL (?a == ?b`[↑]`[?a..] --> σ ?a == σ ?b`[↑]`[?a..])) in H2.
rewrite subst_term_shift in H2.
eapply IE. exact H2. exact IHx.
Qed.
(* Lemma num_mult_homomorphism x y : FA ⊢_MSFOL ( num x ⊗ num y == num (x * y) ).
Proof.
induction x.
- cbn. assert (H : FA ⊢_MSFOL ax_mult_zero). apply Ctx. firstorder.
eapply AllE in H. apply H.
- cbn.
Admitted.
Lemma leibniz phi t t' :
FA ⊢_MSFOL (t == t') -> FA ⊢_MSFOL phi[t..] -> FA ⊢_MSFOL phi[t'..].
Proof.
intros H1 H2. induction H2 in |-*.
-
Admitted. *)
End ND.