Skip to content

Commit e14e5cf

Browse files
committed
REPred
1 parent c18de4b commit e14e5cf

File tree

2 files changed

+144
-8
lines changed

2 files changed

+144
-8
lines changed

Foundation/FirstOrder/Basic/Coding.lean

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ lemma ofNat_toNat {n : ℕ} : ∀ t : Semiterm L ξ n, ofNat n (toNat t) = some
4545
| &x => by simp [toNat, ofNat]
4646
| func f v => by
4747
suffices (Matrix.getM fun i ↦ ofNat n (v i).toNat) = some v by
48-
simp only [toNat, ofNat, Nat.unpair_pair, Option.pure_def, Option.bind_eq_bind]
48+
simp only [toNat, ofNat, Nat.unpair_pair]
4949
rw [Nat.unpair_pair, Nat.unpair_pair, Nat.unpair_pair, Nat.natToVec_vecToNat]
5050
simpa
5151
have : (fun i ↦ ofNat n (toNat (v i))) = (fun i ↦ pure (v i)) := funext <| fun i ↦ ofNat_toNat (v i)
52-
simp [this, Matrix.getM_pure]
52+
simp [this]
5353

5454
instance encodable : Encodable (Semiterm L ξ n) where
5555
encode := toNat
@@ -68,6 +68,36 @@ lemma toNat_func {k} (f : L.Func k) (v : Fin k → Semiterm L ξ n) :
6868
· contradiction
6969
· simp [Rew.func, toNat_func, *]
7070

71+
variable (L ξ)
72+
73+
def ofNat.isSemiterm (n : ℕ) : ℕ → Bool
74+
| 0 => false
75+
| e + 1 =>
76+
match e.unpair.1 with
77+
| 0 => if e.unpair.2 < n then true else false
78+
| 1 => (decode e.unpair.2 : Option ξ).isSome
79+
| 2 =>
80+
let arity := e.unpair.2.unpair.1
81+
let ef := e.unpair.2.unpair.2.unpair.1
82+
let ev := e.unpair.2.unpair.2.unpair.2
83+
match hv : ev.natToVec arity with
84+
| some v' =>
85+
have : ∀ i, v' i < e + 1 := fun i ↦
86+
Nat.lt_succ.mpr
87+
<| le_trans (le_of_lt <| Nat.lt_of_eq_natToVec hv i)
88+
<| le_trans (Nat.unpair_right_le _)
89+
<| le_trans (Nat.unpair_right_le _)
90+
<| Nat.unpair_right_le _
91+
(decode ef : Option (L.Func arity)).isSome && (∀ i, ofNat.isSemiterm n (v' i))
92+
| none => false
93+
| _ => false
94+
decreasing_by
95+
· exact this _
96+
· exact this _
97+
· exact this _
98+
99+
100+
71101
end Semiterm
72102

73103
namespace Semiformula
@@ -140,13 +170,13 @@ def ofNat : (n : ℕ) → ℕ → Option (Semiformula L ξ n)
140170

141171
lemma ofNat_toNat {n : ℕ} : ∀ φ : Semiformula L ξ n, ofNat n (toNat φ) = some φ
142172
| rel R v => by
143-
simp only [toNat, ofNat, Nat.unpair_pair, Option.pure_def, Option.bind_eq_bind]
173+
simp only [toNat, ofNat, Nat.unpair_pair]
144174
rw [Nat.unpair_pair, Nat.unpair_pair]
145-
simp [Matrix.getM_pure]
175+
simp
146176
| nrel R v => by
147-
simp only [toNat, ofNat, Nat.unpair_pair, Option.pure_def, Option.bind_eq_bind]
177+
simp only [toNat, ofNat, Nat.unpair_pair]
148178
rw [Nat.unpair_pair, Nat.unpair_pair]
149-
simp [Matrix.getM_pure]
179+
simp
150180
| ⊤ => by simp [toNat, ofNat]
151181
| ⊥ => by simp [toNat, ofNat]
152182
| φ ⋎ ψ => by simp [toNat, ofNat, ofNat_toNat φ, ofNat_toNat ψ]

Foundation/FirstOrder/Incompleteness/Church.lean

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@ import Mathlib.Computability.Reduce
55
# Church's Undecidability of First-Order Logic Theorem
66
-/
77

8+
section
9+
10+
lemma Iff.of_not_not {p q : Prop} (hp : ¬p) (hq : ¬q) : p ↔ q := by {
11+
exact (iff_false_right hq).mpr hp
12+
}
13+
14+
end
815

916
section
1017

11-
variable {α β} [Primcodable α] [Primcodable β]
18+
lemma Part.cases (p : Part α) : p = Part.none ∨ ∃ a, a ∈ p := by
19+
by_cases h : p.Dom
20+
· right; exact Part.dom_iff_mem.mp h
21+
· left; exact Part.eq_none_iff'.mpr h
22+
23+
variable {α β γ σ} [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ]
1224

1325
lemma ComputablePred.range_subset {f : α → β} (hf : Computable f) {A} (hA : ComputablePred A) : ComputablePred { x | A (f x) } := by
1426
apply computable_iff.mpr;
@@ -18,8 +30,88 @@ lemma ComputablePred.range_subset {f : α → β} (hf : Computable f) {A} (hA :
1830
. apply Computable.comp <;> assumption;
1931
. rfl;
2032

21-
end
33+
open Computable
34+
35+
lemma Computable.of₁ {f : α → γ} (hf : Computable f) : Computable₂ fun (a : α) (_ : β) ↦ f a := Computable.to₂ (hf.comp fst)
36+
37+
lemma Computable.of₂ {f : β → γ} (hf : Computable f) : Computable₂ fun (_ : α) (b : β) ↦ f b := Computable.to₂ (hf.comp snd)
38+
39+
lemma Partrec.of₁ {f : α →. γ} (hf : Partrec f) : Partrec₂ fun (a : α) (_ : β) ↦ f a := Partrec.to₂ (hf.comp Computable.fst)
40+
41+
lemma Partrec.of₂ {f : β →. γ} (hf : Partrec f) : Partrec₂ fun (_ : α) (b : β) ↦ f b := Partrec.to₂ (hf.comp Computable.snd)
42+
43+
theorem Partrec.optionCasesOn {o : α → Option β} {f : α →. σ} {g : α → β →. σ} (ho : Computable o)
44+
(hf : Partrec f) (hg : Partrec₂ g) :
45+
Partrec fun a ↦ Option.casesOn (o a) (f a) (g a) := by
46+
let optToSum : Option β → Unit ⊕ β := fun o ↦ Option.casesOn o (Sum.inl ()) Sum.inr
47+
have hOptToSum : Computable optToSum :=
48+
Computable.option_casesOn Computable.id (Computable.const (Sum.inl ())) (Computable.of₂ Computable.sumInr)
49+
exact (Partrec.sumCasesOn (hOptToSum.comp ho) (Partrec.of₁ hf) hg).of_eq <| by
50+
intro a
51+
rcases o a <;> simp [optToSum]
52+
53+
theorem Partrec.rfindOpt_unique {α} {f : ℕ → Option α}
54+
(H : ∀ {a n}, a ∈ f n → ∀ {b m}, b ∈ f m → a = b) {a} :
55+
a ∈ Nat.rfindOpt f ↔ ∃ n, a ∈ f n := by
56+
constructor
57+
· exact Nat.rfindOpt_spec
58+
· rintro ⟨n, h⟩
59+
have h' := Nat.rfindOpt_dom.2 ⟨_, _, h⟩
60+
obtain ⟨k, hk⟩ := Nat.rfindOpt_spec ⟨h', rfl⟩
61+
rcases H h hk
62+
exact Part.get_mem h'
63+
64+
lemma ComputablePred.eq {f g : α → β}
65+
(hf : Computable f) (hg : Computable g) : ComputablePred fun a : α ↦ f a = g a := by
66+
have : DecidableEq β := Encodable.decidableEqOfEncodable β
67+
apply ComputablePred.computable_iff.mpr ⟨fun a ↦ f a = g a, ?_, ?_⟩
68+
· exact (Primrec.eq (α := β)).to_comp.comp hf hg
69+
· ext a; simp
70+
71+
lemma ComputablePred.ne {f g : α → β}
72+
(hf : Computable f) (hg : Computable g) : ComputablePred fun a : α ↦ f a ≠ g a :=
73+
(ComputablePred.eq hf hg).not
74+
75+
private lemma REPred.toComputable_func {f : α → β} (h : REPred fun p : α × β ↦ f p.1 = p.2) :
76+
ComputablePred fun p : α × β ↦ f p.1 = p.2 := by
77+
apply ComputablePred.computable_iff_re_compl_re'.mpr ⟨h, ?_⟩
78+
have : REPred fun p : (α × β) × β ↦ f p.1.1 = p.2 ∧ p.2 ≠ p.1.2 :=
79+
REPred.and
80+
(h.comp (α := (α × β) × β) ((fst.comp fst).pair snd))
81+
(ComputablePred.ne snd (snd.comp fst)).to_re
82+
exact this.projection.of_eq <| by
83+
rintro ⟨a, b⟩
84+
simp
85+
86+
lemma REPred.toComputable {f : α → β} (h : REPred fun p : α × β ↦ f p.1 = p.2) : Computable f := by
87+
have h : ComputablePred fun p : α × β ↦ f p.1 = p.2 := REPred.toComputable_func h
88+
rcases ComputablePred.computable_iff.mp h with ⟨c, hc, ec⟩
89+
replace ec : ∀ p : α × β, c p = true ↔ f p.1 = p.2 := fun p ↦ by symm; simpa using congr_fun ec p
90+
let g : α → ℕ → Option β := fun a n ↦ (Encodable.decode n : Option β).bind fun b ↦ bif c ⟨a, b⟩ then .some b else .none
91+
have hg : Computable₂ g := by
92+
have : Computable₂ fun (p : α × ℕ) (b : β) ↦ bif c ⟨p.1, b⟩ then some b else none :=
93+
(cond (hc.comp (pair (fst.comp fst) snd))
94+
(option_some.comp snd) (const none)).to₂ (α := α × ℕ) (β := β)
95+
exact (Computable.option_bind (Computable.comp Computable.decode Computable.snd) this).to₂
96+
have := Partrec.rfindOpt hg
97+
exact this.of_eq <| by
98+
intro a
99+
refine Part.eq_some_iff.mpr ?_
100+
refine (Partrec.rfindOpt_unique ?_).mpr ?_
101+
· unfold g
102+
intro b₁ n₁
103+
rcases (Encodable.decode n₁ : Option β) with (_ | v₁)
104+
· simp
105+
intro h₁ b₂ n₂
106+
rcases (Encodable.decode n₂ : Option β) with (_ | v₂)
107+
· simp
108+
revert h₁
109+
suffices f a = v₁ → v₁ = b₁ → f a = v₂ → v₂ = b₂ → b₁ = b₂ by simpa [Bool.cond_eq_if, ec]
110+
grind
111+
· use Encodable.encode (f a)
112+
simp [g, ec, Bool.cond_eq_if]
22113

114+
end
23115

24116
namespace LO.ISigma1
25117

@@ -103,6 +195,20 @@ theorem firstorder_undecidability : ¬ComputablePred (fun n : ℕ ↦ ∃ σ : S
103195
apply @not_computable_theorems (T := 𝐏𝐀⁻) (by sorry) inferInstance inferInstance;
104196
sorry;
105197

198+
/-
199+
open LO.Entailment FirstOrder Arithmetic R0 PeanoMinus IOpen ISigma0 ISigma1 Metamath InternalArithmetic
200+
201+
private lemma theory_provability_undecidable : ¬ComputablePred fun n : ℕ ↦ ∃ σ : Sentence ℒₒᵣ, n = ⌜σ⌝ ∧ T ⊢!. σ := by {
202+
intro hC
203+
let U : ℕ → Prop := fun n : ℕ ↦ ∀ σ : Sentence ℒₒᵣ, n = ⌜σ⌝ → T ⊬. σ
204+
have U_re : REPred U := by simpa using hC.not.to_re
205+
let υ : Semisentence ℒₒᵣ 1 := codeOfREPred U
206+
have hυ : ∀ n : ℕ, U n ↔ T ⊢!. υ/[↑n] := fun n ↦ by
207+
simpa [Semiformula.coe_substs_eq_substs_coe₁, Axiom.provable_iff] using re_complete U_re
208+
let δ : Semisentence ℒₒᵣ 1 := “σ. ∃ τ, !ssnum τ σ σ ∧ ”
209+
}
210+
-/
211+
106212
end Arithmetic
107213

108214
end LO.FirstOrder

0 commit comments

Comments
 (0)