Skip to content

Commit e77ef25

Browse files
committed
calc
1 parent 930e594 commit e77ef25

9 files changed

Lines changed: 277 additions & 284 deletions

File tree

Foundation/FirstOrder/Basic/Calculus.lean

Lines changed: 84 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module
33
/- public import Foundation.Logic.Calculus -/
44
public import Foundation.Logic.Calculus
55
public import Foundation.Propositional.Entailment.AxiomEFQ
6-
public import Foundation.FirstOrder.Basic.Syntax.Schema
6+
public import Foundation.FirstOrder.Basic.Syntax.Rew
77
public import Mathlib.Data.List.MinMax
88

99
/-! # One-sided sequent calculus for first-order classical logic -/
@@ -27,11 +27,22 @@ def newVar (Γ : Sequent L) : ℕ := (Γ.map Semiformula.fvSup).foldr max 0
2727
lemma not_fvar?_newVar {φ : Proposition L} {Γ : Sequent L} (h : φ ∈ Γ) : ¬FVar? φ Γ.newVar :=
2828
not_fvar?_of_lt_fvSup φ (by simpa [newVar] using List.le_max_of_le (List.mem_map_of_mem h) (by simp))
2929

30-
@[simp] lemma rew_neg_comm {Γ : Sequent L} (ω : Rew L 00) :
31-
(∼Γ).map (ω ▹ ·) = ∼Γ.map (ω ▹ ·) := by simp [List.tilde_def]
30+
@[simp] lemma lcHom_comm {Γ : List (Formula L ξ)} (f : Formula L ξ →ˡᶜ Proposition L) :
31+
(∼Γ).map f = ∼Γ.map f := by simp [List.tilde_def]
3232

3333
def IsClosed (Γ : Sequent L) : Prop := ∃ φ ∈ Γ, ∼φ ∈ Γ
3434

35+
def embed (Γ : List (Sentence L)) : Sequent L := List.map Rewriting.emb Γ
36+
37+
@[simp] lemma embed_nil : embed ([] : List (Sentence L)) = [] := rfl
38+
39+
@[simp] lemma embed_cons {φ : Sentence L} {Γ : List (Sentence L)} :
40+
embed (φ :: Γ) = (↑φ :: embed Γ) := rfl
41+
42+
@[simp] lemma embed_shift (Γ : List (Sentence L)) :
43+
(embed Γ)⁺ = embed Γ := by
44+
simp [embed, Rewriting.shifts]
45+
3546
end Sequent
3647

3748
/-! ## Derivation for one-sided $\mathbf{LK}$ -/
@@ -164,7 +175,7 @@ protected def shift {Δ : Sequent L} (d : ⊢ᴸᴷ¹ Δ) : ⊢ᴸᴷ¹ Δ⁺ :=
164175

165176
section Hom
166177

167-
variable {L₁ : Language} {L₂ : Language} {𝔖₁ : Schema L₁} {Δ₁ : Sequent L₁}
178+
variable {L₁ : Language} {L₂ : Language} {Δ₁ : Sequent L₁}
168179

169180
lemma shifts_image (Φ : L₁ →ᵥ L₂) {Δ : List (Proposition L₁)} :
170181
(Δ.map <| Semiformula.lMap Φ)⁺ = (Δ⁺.map <| Semiformula.lMap Φ) := by
@@ -238,172 +249,120 @@ end Derivation
238249

239250
/-! ## Classical proof system -/
240251

241-
inductive Proof.Symbol (L : Language)
252+
inductive LK.Symbol (L : Language)
242253
| symbol
243254

244-
notation "𝐋𝐊¹" => Proof.Symbol.symbol
255+
notation "𝐋𝐊¹" => LK.Symbol.symbol
245256

246-
abbrev Proof (φ : Proposition L) := ⊢ᴸᴷ¹ [φ]
257+
notation "𝐋𝐊¹[" L "]" => LK.Symbol.symbol (L := L)
247258

248-
instance : Entailment (Proof.Symbol L) (Proposition L) where
249-
Prf _ := Proof
259+
abbrev LK (φ : Proposition L) := ⊢ᴸᴷ¹ [φ]
250260

251-
namespace Proof
261+
instance : Entailment (LK.Symbol L) (Proposition L) where
262+
Prf _ := LK
263+
264+
namespace LK
252265

253266
lemma def_eq (φ : Proposition L) : (𝐋𝐊¹ ⊢! φ) = (⊢ᴸᴷ¹ [φ]) := rfl
254267

255-
instance : OneSidedLK.EmptyEntailment (Derivation (L := L)) (𝐋𝐊¹ : Proof.Symbol L) where
268+
lemma provable_def (φ : Proposition L) : 𝐋𝐊¹ ⊢ φ ↔ Nonempty (⊢ᴸᴷ¹ [φ]) := by rfl
269+
270+
lemma unprovable_def (φ : Proposition L) : 𝐋𝐊¹ ⊬ φ ↔ IsEmpty (⊢ᴸᴷ¹ [φ]) := by
271+
unfold Entailment.Unprovable; simp [provable_def]
272+
273+
instance : OneSidedLK.PrincipalEntailment (Derivation (L := L)) (𝐋𝐊¹ : LK.Symbol L) where
256274
equiv := Equiv.refl _
257275

258-
instance classical : Entailment.Cl (𝐋𝐊¹ : Proof.Symbol L) := inferInstance
276+
instance classical : Entailment.Cl (𝐋𝐊¹ : LK.Symbol L) := inferInstance
277+
278+
lemma all (φ : Semiproposition L 1) : 𝐋𝐊¹ ⊢ φ.free → 𝐋𝐊¹ ⊢ ∀⁰ φ := fun h ↦ ⟨Derivation.all h.get⟩
259279

260-
end Proof
280+
lemma allClosure_fixitr {φ : Proposition L} (dp : 𝐋𝐊¹ ⊢ φ) : (m : ℕ) → 𝐋𝐊¹ ⊢ ∀⁰* Rew.fixitr 0 m ▹ φ
281+
| 0 => by simpa
282+
| m + 1 => by
283+
simp only [LawfulSyntacticRewriting.allClosure_fixitr]
284+
apply all; simpa using allClosure_fixitr dp m
261285

262-
structure Schema.Proof (𝔖 : Schema L) (φ : Proposition L) where
263-
axioms : List (Proposition L)
264-
axioms_mem : ∀ ψ ∈ axioms, ψ ∈ 𝔖
265-
derivation : ⊢ᴸᴷ¹ φ :: ∼axioms
286+
lemma univCl' {φ : Proposition L} (b : 𝐋𝐊¹ ⊢ φ) : 𝐋𝐊¹ ⊢ φ.univCl' := allClosure_fixitr b φ.fvSup
266287

267-
namespace Schema
288+
end LK
268289

269-
instance : Entailment (Schema L) (Proposition L) where
270-
Prf := Schema.Proof
290+
structure Theory.LK (T : Theory L) (σ : Sentence L) where
291+
axioms : List (Sentence L)
292+
axioms_mem : ∀ ψ ∈ axioms, ψ ∈ T
293+
derivation : OneSidedLK.Pullback Derivation Rewriting.emb (σ :: ∼axioms)
271294

272-
variable {𝔖 : Schema L}
295+
namespace Theory
273296

274-
attribute [simp] Proof.axioms_mem
297+
instance : Entailment (Theory L) (Sentence L) where
298+
Prf := Theory.LK
275299

276-
def equiv (𝔖 : Schema L) (φ) :
277-
(𝔖 ⊢! φ) ≃ (Γ : {Γ : Sequent L // ∀ ψ ∈ Γ, ψ ∈ 𝔖}) × ⊢ᴸᴷ¹ φ :: ∼Γ where
278-
toFun b := ⟨⟨b.axioms, b.axioms_mem⟩, b.derivation⟩
279-
invFun := fun ⟨⟨Γ, hΓ⟩, d⟩ ↦ ⟨Γ, hΓ, d⟩
300+
variable {T : Theory L}
280301

281-
instance : Entailment.Compact (Schema L) where
302+
attribute [simp] LK.axioms_mem
303+
304+
instance : Entailment.Compact (Theory L) where
282305
core b := {φ | φ ∈ b.axioms}
283306
corePrf b := ⟨b.axioms, by simp, b.derivation⟩
284307
core_finite b := by simp [AdjunctiveSet.Finite, AdjunctiveSet.set]
285308
core_subset b := by simpa [AdjunctiveSet.subset_iff] using b.axioms_mem
286309

287-
instance : OneSidedLK.Entailment (Derivation (L := L)) (Schema L) where
288-
equiv {𝔖 φ} := equiv 𝔖 φ
310+
instance : OneSidedLK.ContextualEntailment (OneSidedLK.Pullback Derivation Rewriting.emb) (Theory L) where
311+
equiv {T φ} :=
312+
{ toFun b := ⟨⟨b.axioms, b.axioms_mem⟩, b.derivation⟩
313+
invFun := fun ⟨⟨Γ, hΓ⟩, d⟩ ↦ ⟨Γ, hΓ, d⟩ }
289314

290-
instance : Entailment.Cl 𝔖 := inferInstance
315+
instance : Entailment.Cl T := OneSidedLK.ContextualEntailment.cl T
291316

292-
lemma weakerThan_of_le {𝔖 𝔘 : Schema L} (h : 𝔖 ≤ 𝔘) : 𝔖𝔘 := Entailment.Axiomatized.weakerThanOfSubset h
317+
lemma weakerThan_of_le {T U : Theory L} (h : T ⊆ U) : TU := Entailment.Axiomatized.weakerThanOfSubset h
293318

294-
instance (𝔖 𝔘 : Schema L) : 𝔖𝔖 ⊔ 𝔘 := weakerThan_of_le (by simp)
319+
instance (T U : Theory L) : TT ∪ U := weakerThan_of_le (by simp)
295320

296-
instance (𝔖 𝔘 : Schema L) : 𝔘𝔖 ⊔ 𝔘 := weakerThan_of_le (by simp)
321+
instance (T U : Theory L) : UT ∪ U := weakerThan_of_le (by simp)
297322

298323
lemma provable_iff :
299-
𝔖 ⊢ φ ↔ ∃ Γ : Sequent L, (∀ ψ ∈ Γ, ψ ∈ 𝔖) ∧ Nonempty (⊢ᴸᴷ¹ φ :: ∼Γ) :=
300-
OneSidedLK.Entailment.provable_iff
324+
T ⊢ φ ↔ ∃ Γ : List (Sentence L), (∀ ψ ∈ Γ, ψ ∈ T) ∧ Nonempty (⊢ᴸᴷ¹ φ :: ∼Sequent.embed Γ) := by
325+
simpa using OneSidedLK.ContextualEntailment.provable_iff (𝓢 := T) (φ := φ)
301326

302327
lemma inconsistent_iff :
303-
Entailment.Inconsistent 𝔖 ↔ ∃ Γ : Sequent L, (∀ ψ ∈ Γ, ψ ∈ 𝔖) ∧ Nonempty (⊢ᴸᴷ¹ ∼Γ) :=
304-
OneSidedLK.Entailment.inconsistent_iff
305-
306-
def rewrite [𝔖.IsClosed] (b : 𝔖 ⊢! φ) (f : ℕ → SyntacticTerm L) :
307-
𝔖 ⊢! Rew.rewrite f ▹ φ where
308-
axioms := b.axioms.map (Rew.rewrite f ▹ ·)
309-
axioms_mem := by
310-
suffices ∀ ψ ∈ b.axioms, Rew.rewrite f ▹ ψ ∈ 𝔖 by simpa
311-
intro ψ hψ
312-
exact Schema.IsClosed.closed (Rew.rewrite f) _ (b.axioms_mem ψ hψ)
313-
derivation := b.derivation.rewrite f |>.cast
314-
315-
@[simp] lemma empty_provable_iff_eprovable :
316-
(⊥ : Schema L) ⊢ φ ↔ 𝐋𝐊¹ ⊢ φ :=
317-
OneSidedLK.Entailment.empty_provable_iff_eprovable 𝐋𝐊¹
328+
Entailment.Inconsistent T ↔ ∃ Γ : List (Sentence L), (∀ ψ ∈ Γ, ψ ∈ T) ∧ Nonempty (⊢ᴸᴷ¹ ∼Sequent.embed Γ) := by
329+
simpa using OneSidedLK.ContextualEntailment.inconsistent_iff (𝓢 := T)
318330

319-
end Schema
331+
open Entailment Derivation
320332

321-
namespace Derivation
333+
@[simp] lemma empty_provable_iff_eprovable :
334+
(∅ : Theory L) ⊢ φ ↔ 𝐋𝐊¹ ⊢ (φ : Proposition L) := by
335+
simpa using OneSidedLK.ContextualEntailment.empty_provable_iff_eprovable
336+
(S := Theory L)
337+
(𝓟 := pullback 𝐋𝐊¹[L] (Rewriting.emb : Sentence L → Proposition L))
338+
(φ := φ)
322339

323-
open Entailment
324-
325-
variable {Γ Δ : Sequent L}
326-
327-
def eCut (d₁ : ⊢ᴸᴷ¹ φ :: Γ) (d₂ : ⊢ᴸᴷ¹ ψ :: Δ) (e : ∼φ = ψ := by simp) : ⊢ᴸᴷ¹ Γ ++ Δ := cut d₁ (d₂.cast (by simp [e]))
328-
329-
def disj₂ {Γ Δ : Sequent L} : ⊢ᴸᴷ¹ Γ ++ Δ → ⊢ᴸᴷ¹ ⋁Γ :: Δ := fun d ↦
330-
match Γ with
331-
| [] => d.weakening
332-
| [φ] => d
333-
| [φ, ψ] => d.or
334-
| φ :: ψ :: χ :: Γ =>
335-
let Φ := ⋁(χ :: Γ)
336-
have : ⊢ᴸᴷ¹ (φ ⋎ ψ :: χ :: Γ) ++ Δ := d.or
337-
have d₁ : ⊢ᴸᴷ¹ (φ ⋎ ψ) ⋎ Φ :: Δ := this.disj₂
338-
have d₂ : ⊢ᴸᴷ¹ [(∼φ ⋏ ∼ψ) ⋏ ∼Φ, φ ⋎ ψ ⋎ Φ] :=
339-
have : ⊢ᴸᴷ¹ [φ, ψ ⋎ Φ, (∼φ ⋏ ∼ψ) ⋏ ∼Φ] :=
340-
((eta φ).rotate.tensor (eta ψ).rotate).tensor
341-
(eta Φ).rotate |>.rotate.rotate.or.weakening
342-
this.or.rotate
343-
d₂.eCut d₁
344-
termination_by _ => Γ.length
345-
346-
def conj₂ {Γ Δ : Sequent L} (d : (φ : Proposition L) → φ ∈ Γ → ⊢ᴸᴷ¹ φ :: Δ) : ⊢ᴸᴷ¹ ⋀Γ :: Δ :=
347-
match Γ with
348-
| [] => verum.weakening
349-
| [φ] => d φ (by simp)
350-
| φ :: ψ :: Γ =>
351-
have : ⊢ᴸᴷ¹ ⋀(ψ :: Γ) :: Δ := conj₂ (Γ := ψ :: Γ) (fun χ h ↦ d χ (by simp_all))
352-
(d φ (by simp)).and this
353-
354-
def disjClosure : ⊢ᴸᴷ¹ Γ → 𝐋𝐊¹ ⊢! ⋁Γ := fun d ↦
355-
have : ⊢ᴸᴷ¹ Γ ++ [] := d.cast
356-
this.disj₂
357-
358-
def disjClosureInv : 𝐋𝐊¹ ⊢! ⋁Γ → ⊢ᴸᴷ¹ Γ := fun d ↦
359-
have d₁ : ⊢ᴸᴷ¹ [⋁Γ] := d
360-
have d₂ : ⊢ᴸᴷ¹ ⋀(∼Γ) :: Γ := conj₂ fun φ h ↦ close φ (by simp) (by simp_all)
361-
d₁.eCut d₂
362-
363-
lemma nonempty_iff_provable_disj : Nonempty (⊢ᴸᴷ¹ Γ) ↔ 𝐋𝐊¹ ⊢ ⋁Γ :=
364-
by rintro ⟨d⟩; exact ⟨d.disjClosure⟩, by rintro ⟨d⟩; exact ⟨d.disjClosureInv⟩⟩
340+
lemma iff_context {T : Theory L} :
341+
T ⊢ φ ↔ T *⊢[pullback 𝐋𝐊¹[L] (Rewriting.emb : _ → Proposition L)] φ :=
342+
OneSidedLK.ContextualEntailment.iff_context
365343

366-
end Derivation
344+
end Theory
367345

368-
namespace Schema
346+
namespace Theory
369347

370348
open Entailment Derivation
371349

372-
lemma iff_context {𝔖 : Schema L} : 𝔖 ⊢ φ ↔ 𝔖 *⊢[𝐋𝐊¹] φ := by
373-
constructor
374-
· rintro ⟨d⟩
375-
have : 𝐋𝐊¹ ⊢! ⋀d.axioms 🡒 φ :=
376-
have : ⊢ᴸᴷ¹ ∼d.axioms ++ [φ] := d.derivation.weakening
377-
this.disj₂.or.cast <| by simp [Semiformula.imp_eq]
378-
refine ⟨⟨d.axioms, by simpa using d.axioms_mem, this⟩⟩
379-
· rintro ⟨Γ, h, d⟩
380-
have d : ⊢ᴸᴷ¹ [⋁(∼Γ) ⋎ φ] := d.cast (by simp [Semiformula.imp_eq])
381-
have : ⊢ᴸᴷ¹ ⋀Γ ⋏ ∼φ :: φ :: ∼Γ :=
382-
have : ⊢ᴸᴷ¹ ⋀Γ :: ∼Γ := Derivation.conj₂ fun φ h ↦ close φ (by simp) (by simp [h])
383-
this.tensor (eta φ).rotate |>.weakening
384-
refine ⟨⟨Γ, h, (d.eCut this).cast⟩⟩
350+
lemma of_LK_provable {T : Theory L} {φ : Sentence L} : 𝐋𝐊¹ ⊢ (φ : Proposition L) → T ⊢ φ := fun h ↦
351+
have : pullback 𝐋𝐊¹[L] (Rewriting.emb : Sentence L → Proposition L) ⊢ φ := h
352+
OneSidedLK.ContextualEntailment.of_principal_provable this
385353

386354
open Classical in
355+
noncomputable instance : Entailment.Deduction (Theory L) :=
356+
OneSidedLK.ContextualEntailment.deduction (pullback 𝐋𝐊¹[L] (Rewriting.emb : Sentence L → Proposition L))
387357

388-
noncomputable instance : Entailment.Deduction (Schema L) where
389-
ofInsert {φ ψ 𝔖 b} :=
390-
have : insert φ ↑𝔖 *⊢[𝐋𝐊¹] ψ := iff_context.mp ⟨b⟩
391-
have : ↑𝔖 *⊢[𝐋𝐊¹] φ 🡒 ψ := Context.deduct! this
392-
(iff_context.mpr this).get
393-
inv {φ ψ 𝔖 b} :=
394-
have : ↑(adjoin φ 𝔖) *⊢[𝐋𝐊¹] ψ := Context.deductInv! (iff_context.mp ⟨b⟩)
395-
(iff_context.mpr this).get
396-
397-
end Schema
358+
end Theory
398359

399-
/-!
400-
### Theory
401-
-/
360+
/-! ### Theory -/
402361

403-
def Schema.theory (𝔖 : Schema L) : Theory L := {σ | 𝔖 ⊢ ↑σ}
362+
def Theory.theory (T : Theory L) : Theory L := {σ | T ⊢ ↑σ}
404363

405-
@[simp] lemma Schema.mem_theory {𝔖 : Schema L} :
406-
σ ∈ 𝔖.theory ↔ 𝔖 ⊢ ↑σ := by simp [Schema.theory]
364+
@[simp] lemma Theory.mem_theory {T : Theory L} :
365+
σ ∈ T.theory ↔ T ⊢ ↑σ := by simp [Theory.theory]
407366

408367
end FirstOrder
409368

Foundation/FirstOrder/Basic/Syntax/Formula.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ end enumarateFVar
582582

583583
end Semiformula
584584

585+
abbrev Theory (L : Language) := Set (Sentence L)
586+
587+
abbrev ArithmeticTheory := Theory ℒₒᵣ
588+
585589
end LO.FirstOrder
586590

587591
end

0 commit comments

Comments
 (0)