Skip to content

Commit

Permalink
Language.Theory.TDerivation
Browse files Browse the repository at this point in the history
  • Loading branch information
iehality committed Jul 15, 2024
1 parent 4188d7c commit 2a9a357
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 71 deletions.
6 changes: 6 additions & 0 deletions Arithmetization/ISigmaOne/HFS/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ lemma lt_of_mem_dom {x y m : V} (h : ⟪x, y⟫ ∈ m) : x < m := lt_of_le_of_lt

lemma lt_of_mem_rng {x y m : V} (h : ⟪x, y⟫ ∈ m) : y < m := lt_of_le_of_lt (by simp) (lt_of_mem h)

lemma insert_subset_insert_of_subset {a b : V} (x : V) (h : a ⊆ b) : insert x a ⊆ insert x b := by
intro z hz
rcases mem_bitInsert_iff.mp hz with (rfl | hz)
· simp
· simp [h hz]

section under

@[simp] lemma under_subset_under_of_le {i j : V} : under i ⊆ under j ↔ i ≤ j :=
Expand Down
4 changes: 3 additions & 1 deletion Arithmetization/ISigmaOne/Metamath/Formula/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,11 @@ lemma Language.UFormula.pos {p : V} (h : L.UFormula p) : 0 < p := by
⟨_, _, _, _, _, rfl⟩ | ⟨_, _, _, _, _, rfl⟩ | ⟨_, _, _, rfl⟩ | ⟨_, _, _, rfl⟩) <;>
simp [qqRel, qqNRel, qqVerum, qqFalsum, qqAnd, qqOr, qqAll, qqEx]

lemma Language.Semiformula.pos {n p : V} (h : L.Semiformula n p) : 0 < p := h.1.pos

@[simp] lemma Language.UFormula.not_zero : ¬L.UFormula (0 : V) := by intro h; simpa using h.pos

lemma Language.Semiformula.pos {n p : V} (h : L.Semiformula n p) : 0 < p := h.1.pos
@[simp] lemma Language.Semiformula.not_zero (m : V) : ¬L.Semiformula m (0 : V) := by intro h; simpa using h.pos

@[simp] lemma Language.Semiformula.rel {n k r v : V} :
L.Semiformula n (^rel n k r v) ↔ L.Rel k r ∧ L.SemitermVec k n v := by simp [Language.Semiformula]
Expand Down
49 changes: 39 additions & 10 deletions Arithmetization/ISigmaOne/Metamath/Formula/Functions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,45 @@ variable {m w : V}
@[simp] lemma substs_ex {n p} (hp : L.Semiformula (n + 1) p) :
L.substs m w (^∃[n] p) = ^∃[m] (L.substs (m + 1) (L.qVec n m w) p) := by simp [Language.substs, hp, construction]

lemma uformula_subst_induction {P : V → V → V → V → Prop} (hP : 𝚺₁-Relation₄ P)
(hRel : ∀ n m w k R v, L.Rel k R → L.SemitermVec k n v → P m w (^rel n k R v) (^rel m k R (L.termSubstVec k n m w v)))
(hNRel : ∀ n m w k R v, L.Rel k R → L.SemitermVec k n v → P m w (^nrel n k R v) (^nrel m k R (L.termSubstVec k n m w v)))
(hverum : ∀ n m w, P m w (^⊤[n]) (^⊤[m]))
(hfalsum : ∀ n m w, P m w (^⊥[n]) (^⊥[m]))
(hand : ∀ n m w p q, L.Semiformula n p → L.Semiformula n q →
P m w p (L.substs m w p) → P m w q (L.substs m w q) → P m w (p ^⋏[n] q) (L.substs m w p ^⋏[m] L.substs m w q))
(hor : ∀ n m w p q, L.Semiformula n p → L.Semiformula n q →
P m w p (L.substs m w p) → P m w q (L.substs m w q) → P m w (p ^⋎[n] q) (L.substs m w p ^⋎[m] L.substs m w q))
(hall : ∀ n m w p, L.Semiformula (n + 1) p →
P (m + 1) (L.qVec n m w) p (L.substs (m + 1) (L.qVec n m w) p) →
P m w (^∀[n] p) (^∀[m] (L.substs (m + 1) (L.qVec n m w) p)))
(hex : ∀ n m w p, L.Semiformula (n + 1) p →
P (m + 1) (L.qVec n m w) p (L.substs (m + 1) (L.qVec n m w) p) →
P m w (^∃[n] p) (^∃[m] (L.substs (m + 1) (L.qVec n m w) p))) :
∀ {p m w}, L.UFormula p → P m w p (L.substs m w p) := by
suffices ∀ param p, L.UFormula p → P (π₁ param) (π₂ param) p ((construction L).result param p) by
intro p m w hp; simpa using this ⟪m, w⟫ p hp
apply (construction L).uformula_result_induction (P := fun param p y ↦ P (π₁ param) (π₂ param) p y)
· apply Definable.comp₄'
(DefinableFunction.comp₁ (DefinableFunction.var _))
(DefinableFunction.comp₁ (DefinableFunction.var _))
(DefinableFunction.var _)
(DefinableFunction.var _)
· intro param n k R v hkR hv; simpa using hRel n (π₁ param) (π₂ param) k R v hkR hv
· intro param n k R v hkR hv; simpa using hNRel n (π₁ param) (π₂ param) k R v hkR hv
· intro param n; simpa using hverum n (π₁ param) (π₂ param)
· intro param n; simpa using hfalsum n (π₁ param) (π₂ param)
· intro param n p q hp hq ihp ihq
simpa [Language.substs] using
hand n (π₁ param) (π₂ param) p q hp hq (by simpa [Language.substs] using ihp) (by simpa [Language.substs] using ihq)
· intro param n p q hp hq ihp ihq
simpa [Language.substs] using
hor n (π₁ param) (π₂ param) p q hp hq (by simpa [Language.substs] using ihp) (by simpa [Language.substs] using ihq)
· intro param n p hp ihp
simpa using hall n (π₁ param) (π₂ param) p hp (by simpa [construction] using ihp)
· intro param n p hp ihp
simpa using hex n (π₁ param) (π₂ param) p hp (by simpa [construction] using ihp)

lemma semiformula_subst_induction {P : V → V → V → V → V → Prop} (hP : 𝚺₁-Relation₅ P)
(hRel : ∀ n m w k R v, L.Rel k R → L.SemitermVec k n v → P n m w (^rel n k R v) (^rel m k R (L.termSubstVec k n m w v)))
(hNRel : ∀ n m w k R v, L.Rel k R → L.SemitermVec k n v → P n m w (^nrel n k R v) (^nrel m k R (L.termSubstVec k n m w v)))
Expand Down Expand Up @@ -481,16 +520,6 @@ lemma semiformula_subst_induction {P : V → V → V → V → V → Prop} (hP :
lemma substs_not_uformula {m w x} (h : ¬L.UFormula x) :
L.substs m w x = 0 := (construction L).result_prop_not _ h

@[simp] lemma Language.Semiformula.substs_iff {n p m w : V} (hw : L.SemitermVec n m w) :
L.Semiformula m (L.substs m w p) ↔ L.Semiformula n p := by
constructor
· intro hp
have h : L.UFormula p := by
by_contra A; simp [substs_not_uformula A] at hp
exact ⟨h, by { }⟩


/--/
end substs

namespace Formalized
Expand Down
24 changes: 17 additions & 7 deletions Arithmetization/ISigmaOne/Metamath/Proof/Derivation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def Language.setShift (s : V) : V := Classical.choose! (setShift_existsUnique L

variable {L}

section setShift

lemma mem_setShift_iff {s y : V} : y ∈ L.setShift s ↔ ∃ x ∈ s, y = L.shift x :=
Classical.choose!_spec (setShift_existsUnique L s) y

Expand All @@ -135,6 +137,19 @@ lemma shift_mem_setShift {p s : V} (h : p ∈ s) : L.shift p ∈ L.setShift s :=
L.FormulaSet (L.setShift s) ↔ L.FormulaSet s :=
by intro h p hp; simpa using h (L.shift p) (shift_mem_setShift hp), Language.FormulaSet.setShift⟩

@[simp] lemma mem_setShift_union {s t : V} : L.setShift (s ∪ t) = L.setShift s ∪ L.setShift t := mem_ext <| by
simp [mem_setShift_iff]; intro x
constructor
· rintro ⟨z, (hz | hz), rfl⟩
· left; exact ⟨z, hz, rfl⟩
· right; exact ⟨z, hz, rfl⟩
· rintro (⟨z, hz, rfl⟩ | ⟨z, hz, rfl⟩)
exact ⟨z, Or.inl hz, rfl⟩
exact ⟨z, Or.inr hz, rfl⟩

@[simp] lemma mem_setShift_insert {x s : V} : L.setShift (insert x s) = insert (L.shift x) (L.setShift s) := mem_ext <| by
simp [mem_setShift_iff]

section

private lemma setShift_graph (t s : V) :
Expand Down Expand Up @@ -163,6 +178,8 @@ lemma setShift_defined : 𝚺₁-Function₁ L.setShift via pL.setShiftDef := by

end

end setShift

def axL (s p : V) : V := ⟪s, 0, p⟫ + 1

def verumIntro (s : V) : V := ⟪s, 1, 0⟫ + 1
Expand Down Expand Up @@ -698,13 +715,6 @@ lemma cut {s : V} (p) (hd₁ : L.Derivable (insert p s)) (hd₂ : L.Derivable (i
rcases hd₁ with ⟨d₁, hd₁⟩; rcases hd₂ with ⟨d₂, hd₂⟩
exact ⟨cutRule s p d₁ d₂, by simp, Language.Derivation.cutRule hd₁ hd₂⟩

/-- TODO: move-/
lemma insert_subset_insert_of_subset {a b : V} (x : V) (h : a ⊆ b) : insert x a ⊆ insert x b := by
intro z hz
rcases mem_bitInsert_iff.mp hz with (rfl | hz)
· simp
· simp [h hz]

lemma and {s p q : V} (hp : L.Derivable (insert p s)) (hq : L.Derivable (insert q s)) :
L.Derivable (insert (p ^⋏ q) s) :=
and_m (p := p) (q := q) (by simp)
Expand Down
195 changes: 195 additions & 0 deletions Arithmetization/ISigmaOne/Metamath/Proof/Theory.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import Arithmetization.ISigmaOne.Metamath.Formula.Typed
import Arithmetization.ISigmaOne.Metamath.Proof.Derivation

/-!
# Formalized Theory
-/

noncomputable section

namespace LO.Arith

open FirstOrder FirstOrder.Arith

variable {V : Type*} [Zero V] [One V] [Add V] [Mul V] [LT V] [V ⊧ₘ* 𝐈𝚺₁]

variable {L : Arith.Language V} {pL : LDef} [Arith.Language.Defined L pL]

section FVFree

variable (L)

def Language.IsFVFreeSemiterm (n t : V) : Prop := L.termShift n t = t

def Language.IsFVFree (p : V) : Prop := L.Formula p ∧ L.shift p = p

variable {L}

@[simp] lemma neg_iff : L.IsFVFree (L.neg p) ↔ L.IsFVFree p := by
constructor
· intro h
have hp : L.Formula p := Language.Semiformula.neg_iff.mp h.1
have : L.shift (L.neg p) = L.neg p := h.2
simp [shift_neg hp, neg_inj_iff hp.shift hp] at this
exact ⟨hp, this⟩
· intro h; exact ⟨by simp [h.1], by rw [shift_neg h.1, h.2]⟩


end FVFree

section theory

variable (L)

structure _root_.LO.FirstOrder.Arith.LDef.TDef (pL : LDef) where
ch : HSemisentence ℒₒᵣ 1 𝚺₁

protected structure Language.Theory where
set : Set V
set_fvFree : ∀ p ∈ set, L.IsFVFree p

instance : Membership V L.Theory := ⟨fun x T ↦ x ∈ T.set⟩

variable {L}

namespace Language.Theory

protected class Defined (T : L.Theory) (pT : outParam pL.TDef) where
defined : 𝚺₁-Predicate (· ∈ T.set) via pT.ch

variable (T : L.Theory) {pT : pL.TDef} [T.Defined pT]

instance mem_defined : 𝚺₁-Predicate (· ∈ T) via pT.ch := Defined.defined

instance mem_definable : 𝚺₁-Predicate (· ∈ T) := Defined.defined.to_definable

variable {T}

lemma fvFree_neg_of_mem {p} (hp : p ∈ T) : L.IsFVFree (L.neg p) := by simpa using T.set_fvFree p hp

lemma fvFree_of_neg_mem {p} (hp : L.neg p ∈ T) : L.IsFVFree p := by simpa using T.set_fvFree _ hp

end Language.Theory

end theory

section derivableWithTheory

def Language.Theory.Derivable (T : L.Theory) (s : V) : Prop :=
∃ antecedents : V, (∀ p ∈ antecedents, L.neg p ∈ T) ∧ L.Derivable (antecedents ∪ s)

def Language.Theory.Provable (T : L.Theory) (p : V) : Prop := T.Derivable {p}

section

def _root_.LO.FirstOrder.Arith.LDef.TDef.derivableDef {pL : LDef} (pT : pL.TDef) : 𝚺₁-Semisentence 1 := .mkSigma
“s | ∃ a, (∀ p ∈' a, ∃ np, !pL.negDef np p ∧ !pT.ch np) ∧ ∃ uni, !unionDef uni a s ∧ !pL.derivableDef uni” (by simp)

variable (T : L.Theory) {pT : pL.TDef} [T.Defined pT]

protected lemma Language.Theory.derivable_defined : 𝚺₁-Predicate T.Derivable via pT.derivableDef := by
intro v; simp [LDef.TDef.derivableDef, (neg_defined L).df.iff,
(T.mem_defined).df.iff, (derivable_defined L).df.iff, Language.Theory.Derivable]

instance Language.Theory.derivable_definable : 𝚺₁-Predicate T.Derivable := Defined.to_definable _ T.derivable_defined

/-- instance for definability tactic-/
@[simp] instance Language.Theory.derivable_definable' : (𝚺, 0 + 1)-Predicate T.Derivable := T.derivable_definable

def _root_.LO.FirstOrder.Arith.LDef.TDef.prv {pL : LDef} (pT : pL.TDef) : 𝚺₁-Semisentence 1 := .mkSigma
“p | ∃ s, !insertDef s p 0 ∧ !pT.derivableDef s” (by simp)

protected lemma Language.Theory.provable_defined : 𝚺₁-Predicate T.Provable via pT.prv := by
intro v; simp [LDef.TDef.prv, (T.derivable_defined).df.iff, Language.Theory.Provable, singleton_eq_insert, emptyset_def]

instance Language.Theory.provable_definable : 𝚺₁-Predicate T.Provable := Defined.to_definable _ T.provable_defined

/-- instance for definability tactic-/
@[simp] instance Language.Theory.provable_definable' : (𝚺, 0 + 1)-Predicate T.Provable := T.provable_definable

end

namespace Language.Theory.Derivable

variable {T : L.Theory} {pT : pL.TDef} [T.Defined pT]

lemma by_axm (hs : L.FormulaSet s) {p} (hpT : p ∈ T) (hp : p ∈ s) : T.Derivable s :=
⟨{L.neg p}, by simp [neg_neg (hs p hp), hpT], Language.Derivable.em (p := p) (by simp [hs, hs p hp]) (by simp [hp]) (by simp)⟩

lemma verum (hs : L.FormulaSet s) (h : ^⊤ ∈ s) : T.Derivable s :=
⟨∅, by simp, Language.Derivable.verum (by simp [hs]) (by simp [h])⟩

lemma em (hs : L.FormulaSet s) (p : V) (h : p ∈ s) (hn : L.neg p ∈ s) : T.Derivable s :=
⟨∅, by simp, Language.Derivable.em (p := p) (by simpa) (by simp [h]) (by simp [hn])⟩

lemma and {p q : V} (dp : T.Derivable (insert p s)) (dq : T.Derivable (insert q s)) : T.Derivable (insert (p ^⋏ q) s) := by
rcases dp with ⟨Γ, hΓ, dp⟩
rcases dq with ⟨Δ, hΔ, dq⟩
exact ⟨Γ ∪ Δ, by intro x hx; rcases mem_cup_iff.mp hx with (hx | hx); { exact hΓ x hx }; { exact hΔ x hx },
Language.Derivable.and_m (p := p) (q := q) (by simp)
(Language.Derivable.wk (by simp [by simpa using dp.formulaSet, by simpa using dq.formulaSet])
(by intro x; simp; tauto) dp)
(Language.Derivable.wk (by simp [by simpa using dp.formulaSet, by simpa using dq.formulaSet])
(by intro x; simp; tauto) dq)⟩

lemma or {p q : V} (dpq : T.Derivable (insert p (insert q s))) : T.Derivable (insert (p ^⋎ q) s) := by
rcases dpq with ⟨Γ, hΓ, d⟩
exact ⟨Γ, hΓ, Language.Derivable.or_m (p := p) (q := q) (by simp)
(d.wk (by simp [by simpa using d.formulaSet]) <| by intro x; simp; tauto)⟩

lemma all {p : V} (hp : L.Semiformula 1 p) (dp : T.Derivable (insert (L.free p) (L.setShift s))) : T.Derivable (insert (^∀ p) s) := by
rcases dp with ⟨Γ, hΓ, d⟩
have hs : L.setShift Γ = Γ := mem_ext <| by
simp only [mem_setShift_iff]; intro x
constructor
· rintro ⟨x, hx, rfl⟩; simpa [fvFree_of_neg_mem (hΓ x hx) |>.2] using hx
· intro hx; exact ⟨x, hx, by simp [fvFree_of_neg_mem (hΓ x hx) |>.2]⟩
exact ⟨Γ, hΓ,
Language.Derivable.all_m (p := p) (by simp)
(Language.Derivable.wk (by simp [by simpa using d.formulaSet, hp])
(by intro x; simp [hs]; tauto) d)⟩

lemma ex {p t : V} (hp : L.Semiformula 1 p) (ht : L.Term t)
(dp : T.Derivable (insert (L.substs₁ t p) s)) : T.Derivable (insert (^∃ p) s) := by
rcases dp with ⟨Γ, hΓ, d⟩
exact ⟨Γ, hΓ, Language.Derivable.ex_m (p := p) (by simp) ht
(Language.Derivable.wk (by simp [by simpa using d.formulaSet, hp]) (by intro x; simp; tauto) d)⟩

lemma wk {s s' : V} (h : L.FormulaSet s) (hs : s' ⊆ s) (d : T.Derivable s') : T.Derivable s := by
rcases d with ⟨Γ, hΓ, d⟩
exact ⟨Γ, hΓ, Language.Derivable.wk (by simp [by simpa using d.formulaSet, h]) (by intro x; simp; tauto) d⟩

lemma cut {s : V} (p : V) (d : T.Derivable (insert p s)) (dn : T.Derivable (insert (L.neg p) s)) : T.Derivable s := by
rcases d with ⟨Γ, hΓ, d⟩; rcases dn with ⟨Δ, hΔ, b⟩
exact ⟨Γ ∪ Δ, fun p hp ↦ by rcases mem_cup_iff.mp hp with (h | h); { exact hΓ p h }; { exact hΔ p h },
Language.Derivable.cut p
(Language.Derivable.wk
(by simp [by simpa using d.formulaSet, by simpa using b.formulaSet]) (by intro x; simp; tauto) d)
(Language.Derivable.wk
(by simp [by simpa using d.formulaSet, by simpa using b.formulaSet]) (by intro x; simp; tauto) b)⟩

/-- Crucial inducion for formalized $\Sigma_1$-completeness. -/
lemma conj (ps : V) {s} (hs : L.FormulaSet s)
(ds : ∀ i < len ps, T.Derivable (insert ps.[i] s)) : T.Derivable (insert (^⋀ ps) s) := by
have : ∀ k ≤ len ps, T.Derivable (insert (^⋀ (takeLast ps k)) s) := by
intro k hk
induction k using induction_iSigmaOne
· definability
case zero => simpa using verum (by simp [hs]) (by simp)
case succ k ih =>
simp [takeLast_succ_of_lt (succ_le_iff_lt.mp hk)]
have ih : T.Derivable (insert (^⋀ takeLast ps k) s) := ih (le_trans le_self_add hk)
have : T.Derivable (insert ps.[len ps - (k + 1)] s) := ds (len ps - (k + 1)) ((tsub_lt_iff_left hk).mpr (by simp))
exact this.and ih
simpa using this (len ps) (by rfl)

end Language.Theory.Derivable


end derivableWithTheory



end LO.Arith
Loading

0 comments on commit 2a9a357

Please sign in to comment.