Skip to content

Commit 615ece2

Browse files
committed
calculus
1 parent 1d2563f commit 615ece2

5 files changed

Lines changed: 122 additions & 209 deletions

File tree

Foundation/FirstOrder/Basic/Calculus.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ instance : Entailment.StrongCut (Theory L) (Theory L) where
574574
lemma compact' [L.DecidableEq] {T : Theory L} {φ : Sentence L}
575575
(b : T ⊢ φ) : ∃ (s : { s : Finset (Sentence L) // ↑s ⊆ T}), (∅ : Theory L) ⊢ s.val.conj ➝ φ := by
576576
let ⟨s, b⟩ := compact b
577-
let bc : ({s.val.conj} : Theory L) ⊢ s.val.conj := Axiomatized.provable_axm _ (by simp)
577+
let bc : ({s.val.conj} : Theory L) ⊢ s.val.conj := Axiomatized.provable_refl _ (by simp)
578578
have : {s.val.conj} ⊢ φ := StrongCut.cut! (fun {ψ} hψ ↦ Entailment.left_Fconj!_intro (by simpa) ⨀ bc) b
579579
have : (insert s.val.conj ∅ : Theory L) ⊢ φ := by simpa using this
580580
exact ⟨s, ⟨deduction this.get⟩⟩

Foundation/Logic/Calculus.lean

Lines changed: 72 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,39 @@ public import Foundation.Propositional.Entailment.Cl.Basic
88
This file defines a characterization of Tait style calculus and Gentzen style calculus.
99
1010
## Main Definitions
11-
* `LO.Tait`
12-
* `LO.Gentzen`
13-
11+
- `LO.OneSidedLK`
1412
-/
1513

1614
@[expose]
1715
public section
1816

1917
namespace LO
2018

21-
class OneSidedLK {F : Type*} [LogicalConnective F] [DeMorgan F] (𝔇 : List F → Type*) where
19+
/-! ## One-sided $\mathbf{LK}$ -/
20+
21+
class OneSidedLK {F : Type*} [LogicalConnective F] [DeMorgan F] [NegInvolutive F] (𝔇 : List F → Type*) where
2222
identity (φ) : 𝔇 [φ, ∼φ]
2323
wk : 𝔇 Δ → Δ ⊆ Γ → 𝔇 Γ
2424
verum : 𝔇 [⊤]
2525
and : 𝔇 (φ :: Γ) → 𝔇 (ψ :: Γ) → 𝔇 (φ ⋏ ψ :: Γ)
2626
or : 𝔇 (φ :: ψ :: Γ) → 𝔇 (φ ⋎ ψ :: Γ)
2727

2828
class OneSidedLK.Cut
29-
{F : Type*} [LogicalConnective F] [DeMorgan F] (𝔇 : List F → Type*) extends OneSidedLK 𝔇 where
30-
cut : 𝔇 (φ :: Γ) → 𝔇 (∼φ :: Γ) → 𝔇 Γ
31-
32-
class OneSidedLK.EquivEntailment
33-
{F : Type*} [LogicalConnective F] [DeMorgan F] (𝔇 : outParam (List F → Type*))
34-
(S : Type*) [Entailment S F] [AdjunctiveSet F S] where
35-
equiv {𝓢 : S} : (l : {l : List F // ∀ φ ∈ l, φ ∈ 𝓢}) × 𝔇 (φ :: ∼l) ≃ 𝓢 ⊢! φ
36-
37-
variable {F S K : Type*} [LogicalConnective F] [AdjunctiveSet F K]
29+
{F : Type*} [LogicalConnective F] [DeMorgan F] [NegInvolutive F] (𝔇 : List F → Type*) extends OneSidedLK 𝔇 where
30+
cut : 𝔇 (φ :: Γ) → 𝔇 (∼φ :: Δ) → 𝔇 (Γ ++ Δ)
3831

3932
namespace OneSidedLK
4033

41-
variable {F : Type*} [LogicalConnective F] [DeMorgan F] {𝔇 : List F → Type*} [OneSidedLK 𝔇]
34+
variable {F : Type*} [LogicalConnective F] [DeMorgan F] [NegInvolutive F] {𝔇 : List F → Type*} [OneSidedLK 𝔇]
4235

4336
def cast (b : 𝔇 Γ) (h : Γ = Δ := by simp) : 𝔇 Δ := h ▸ b
4437

4538
def close (φ : F) (hp : φ ∈ Γ := by simp) (hn : ∼φ ∈ Γ := by simp) : 𝔇 Γ := wk (identity φ) (by simp_all)
4639

4740
def verum' (h : ⊤ ∈ Γ := by simp) : 𝔇 Γ := wk verum (by simp [h])
4841

49-
def and' {φ ψ : F} (h : φ ⋏ ψ ∈ Γ) (dp : 𝔇 (φ :: Γ)) (dq : 𝔇 (ψ :: Γ)) : 𝔇 Γ :=
50-
wk (and dp dq) (by simp [h])
51-
52-
def or' {φ ψ : F} (h : φ ⋎ ψ ∈ Γ) (dpq : 𝔇 (φ :: ψ :: Γ)) : 𝔇 Γ :=
53-
wk (or dpq) (by simp [h])
42+
def tensor {φ ψ : F} (dφ : 𝔇 (φ :: Γ)) (dψ : 𝔇 (ψ :: Δ)) : 𝔇 (φ ⋏ ψ :: Γ ++ Δ) :=
43+
and (wk dφ (by simp)) (wk dψ (by simp))
5444

5545
def wkTail (d : 𝔇 Γ) : 𝔇 (φ :: Γ) := wk d (by simp)
5646

@@ -69,174 +59,93 @@ def rotate₃ (d : 𝔇 (φ₄ :: φ₁ :: φ₂ :: φ₃ :: Γ)) : 𝔇 (φ₁
6959

7060
alias cut := OneSidedLK.Cut.cut
7161

62+
protected class Entailment (𝔇 : outParam (List F → Type*)) (S : Type*) [Entailment S F] [AdjunctiveSet F S] where
63+
equiv {𝓢 : S} : 𝓢 ⊢! φ ≃ (l : {l : List F // ∀ φ ∈ l, φ ∈ 𝓢}) × 𝔇 (φ :: ∼l)
64+
7265
open Entailment
7366

74-
variable {S : Type*} [Entailment S F] [AdjunctiveSet F S]
67+
variable {S : Type*} [Entailment S F] [AdjunctiveSet F S] [OneSidedLK.Entailment 𝔇 S]
7568

76-
def ofAxiom [OneSidedLK.EquivEntailment 𝔇 S] {𝓢 : S} (h : φ ∈ 𝓢) : 𝓢 ⊢! φ :=
77-
OneSidedLK.EquivEntailment.equiv ⟨⟨[φ], by simp_all⟩, identity φ⟩
69+
def toProof (𝓢 : S) (d : 𝔇 [φ]) : 𝓢 ⊢! φ := OneSidedLK.Entailment.equiv.symm ⟨⟨[], by simp⟩, d⟩
7870

79-
def ofAxiomSubset [OneSidedLK.EquivEntailment 𝔇 S] {𝓢 𝓤 : S} : 𝓢 ⊢! φ → 𝓢 ⊆ 𝓤 → 𝓤 ⊢! φ := fun b h ↦
80-
have ⟨l, d⟩ := OneSidedLK.EquivEntailment.equiv.symm b
81-
OneSidedLK.EquivEntailment.equiv
71+
def ofAxiom {𝓢 : S} (h : φ ∈ 𝓢) : 𝓢 ⊢! φ :=
72+
OneSidedLK.Entailment.equiv.symm ⟨⟨[φ], by simp_all⟩, identity φ⟩
73+
74+
def ofAxiomSubset {𝓢 𝓤 : S} : 𝓢 ⊢! φ → 𝓢 ⊆ 𝓤 → 𝓤 ⊢! φ := fun b h ↦
75+
have ⟨l, d⟩ := OneSidedLK.Entailment.equiv b
76+
OneSidedLK.Entailment.equiv.symm
8277
⟨⟨l, fun φ hφ ↦ AdjunctiveSet.subset_iff.mp h _ (l.prop φ hφ)⟩, d⟩
8378

84-
instance [OneSidedLK.EquivEntailment 𝔇 S] : Entailment.Axiomatized S where
79+
instance : Entailment.Axiomatized S where
8580
prfAxm h := ofAxiom h
8681
weakening h d := ofAxiomSubset d h
8782

88-
lemma waekerThan_of_subset [OneSidedLK.EquivEntailment 𝔇 S] {𝓢 𝓤 : S} (h : 𝓢 ⊆ 𝓤) : 𝓢 ⪯ 𝓤 :=
89-
fun _ ↦ Entailment.Axiomatized.weakening! h⟩
90-
91-
instance [OneSidedLK.EquivEntailment 𝔇 S] : Entailment.StrongCut S S where
92-
cut {T U φ bs b} := by { }
93-
/--/
94-
lemma of_axiom_subset [Tait.Axiomatized F K] (h : 𝓚 ⊆ 𝓛) : 𝔇! Γ → 𝓛 ⟹! Γ := fun b ↦ ⟨ofAxiomSubset h b.get⟩
95-
96-
instance system : Entailment K F := ⟨(· ⟹. ·)⟩
97-
98-
99-
100-
lemma provable_bot_iff_derivable_nil [Cut F K] : 𝔇! [] ↔ 𝓚 ⊢ ⊥ :=
101-
⟨fun b ↦ wk! b (by simp), fun b ↦ cut! b (by simpa using verum! _ _)⟩
102-
103-
104-
105-
106-
107-
instance [Cut F K] : DeductiveExplosion K where
108-
dexp {𝓚 b φ} := wk (Tait.Cut.cut b (by simpa using verum _ _)) (by simp)
109-
110-
/-
111-
instance : Entailment.Deduction K where
112-
ofInsert {φ ψ 𝓚 b} := by { }
113-
inv {φ ψ 𝓚 b} :=
114-
let h : cons φ 𝔇 [∼φ ⋎ ψ, ψ] :=
115-
wk (show cons φ 𝔇 [∼φ ⋎ ψ] from ofEq (ofAxiomSubset (by simp) b) (by simp [DeMorgan.imply])) (by simp)
116-
let n : cons φ 𝔇 [∼(∼φ ⋎ ψ), ψ] :=
117-
let hp : cons φ 𝔇 [φ, ψ] := wk (show cons φ 𝓚 ⊢! φ from byAxm (by simp)) (by simp)
118-
let hq : cons φ 𝔇 [∼ψ, ψ] := em (φ := ψ) (by simp) (by simp)
119-
ofEq (and hp hq) (by simp)
120-
cut h n
121-
-/
122-
123-
lemma inconsistent_iff_provable [Cut F K] :
124-
Inconsistent 𝓚 ↔ 𝔇! [] :=
125-
⟨fun b ↦ ⟨cut (inconsistent_iff_provable_bot.mp b).get (by simpa using verum _ _)⟩,
126-
fun h ↦ inconsistent_iff_provable_bot.mpr (wk! h (by simp))⟩
127-
128-
lemma consistent_iff_unprovable [Tait.Axiomatized F K] [Cut F K] :
129-
Consistent 𝓚 ↔ IsEmpty (𝔇 []) :=
130-
not_iff_not.mp <| by simp [not_consistent_iff_inconsistent, inconsistent_iff_provable]
131-
132-
/-
133-
lemma provable_iff_inconsistent {φ} :
134-
𝓚 ⊢ φ ↔ Inconsistent (cons (∼φ) 𝓚) := by
135-
simp [inconsistent_iff_provable, deduction_iff, DeMorgan.imply]
136-
constructor
137-
· intro h; exact cut! (of_axiom_subset (by simp) h) (root! <| by simp)
138-
· rintro ⟨b⟩
139-
exact ⟨by simpa using Tait.Axiomatized.proofOfContra b⟩
140-
141-
lemma refutable_iff_inconsistent {φ} :
142-
𝓚 ⊢ ∼φ ↔ Inconsistent (cons φ 𝓚) := by simpa using provable_iff_inconsistent (𝓚 := 𝓚) (φ := ∼φ)
143-
144-
lemma consistent_insert_iff_not_refutable {φ} :
145-
Entailment.Consistent (cons φ 𝓚) ↔ 𝓚 ⊬ ∼φ := by
146-
simp [Entailment.Unprovable, refutable_iff_inconsistent, Entailment.not_inconsistent_iff_consistent]
147-
148-
lemma inconsistent_of_provable_and_refutable {φ} (bp : 𝓚 ⊢ φ) (br : 𝓚 ⊢ ∼φ) : Inconsistent 𝓚 :=
149-
inconsistent_iff_provable.mpr <| cut! bp br
150-
-/
151-
152-
instance [NegInvolutive F] [Cut F K] : Entailment.Cl 𝓚 where
153-
mdp {φ ψ dpq dp} :=
154-
let dpq : 𝔇 [∼φ ⋎ ψ, ψ] := wk dpq (by simp [DeMorgan.imply])
155-
let dnq : 𝔇 [∼(∼φ ⋎ ψ), ψ] :=
156-
let d : 𝔇 [φ ⋏ ∼ψ, ψ] := and (wk dp <| by simp) (close ψ)
157-
ofEq d (by simp)
158-
cut dpq dnq
159-
negEquiv {φ} := ofEq
160-
(show 𝓚 ⊢! (φ ⋎ ∼φ ⋎ ⊥) ⋏ (φ ⋏ ⊤ ⋎ ∼φ) from
161-
and (or <| rotate₁ <| or <| close φ) (or <| and (close φ) verum'))
83+
variable [OneSidedLK.Cut 𝔇] [OneSidedLK.Entailment 𝔇 S]
84+
85+
instance (𝓢 : S) : Entailment.ModusPonens 𝓢 where
86+
mdp {φ ψ} b₁ b₂ :=
87+
let ⟨Γ₁, b₁⟩ := OneSidedLK.Entailment.equiv b₁
88+
let ⟨Γ₂, b₂⟩ := OneSidedLK.Entailment.equiv b₂
89+
have : 𝔇 [∼(φ ➝ ψ), ∼φ, ψ] := cast (tensor (𝔇 := 𝔇) (identity φ) (identity (∼ψ))) (by simp [DeMorgan.imply])
90+
have : 𝔇 (∼φ :: ψ :: ∼↑Γ₁) := wk (cut b₁ this) (by simp)
91+
have : 𝔇 (ψ :: ∼↑Γ₁ ++ ∼↑Γ₂) := wk (cut b₂ this) (by simp)
92+
OneSidedLK.Entailment.equiv.symm ⟨⟨Γ₁ ++ Γ₂, by simp; grind⟩, cast this⟩
93+
94+
instance : Entailment.StrongCut S S where
95+
cut {T U φ bs b} :=
96+
let rec bl (l : List F) (hl : ∀ ψ ∈ l, ψ ∈ U) (χ) (d : 𝔇 (χ :: ∼l)) : T ⊢! χ :=
97+
match l with
98+
| [] => OneSidedLK.Entailment.equiv.symm ⟨⟨[], by simp⟩, d⟩
99+
| ψ :: l =>
100+
have bχ : T ⊢! ψ ➝ χ :=
101+
Entailment.cast (bl l (by simp at hl; grind) (∼ψ ⋎ χ) (OneSidedLK.or <| OneSidedLK.rotate₁ d))
102+
(by simp [DeMorgan.imply])
103+
have bψ : T ⊢! ψ := bs (show ψ ∈ U by simp at hl; grind)
104+
Entailment.mdp bχ bψ
105+
have ⟨l, hl⟩ := OneSidedLK.Entailment.equiv b
106+
bl l l.prop φ hl
107+
108+
instance (𝓢 : S) : Entailment.Cl 𝓢 where
109+
negEquiv {φ} := Entailment.cast
110+
(show 𝓢 ⊢! (φ ⋎ ∼φ ⋎ ⊥) ⋏ (φ ⋏ ⊤ ⋎ ∼φ) from
111+
toProof _ <| and (or <| rotate₁ <| or <| close φ) (or <| and (identity φ) verum'))
162112
(by simp [Axioms.NegEquiv, DeMorgan.imply, LogicalConnective.iff])
163-
verum := verum _ _
113+
verum := toProof _ <| verum
164114
implyK {φ ψ} :=
165-
have : 𝓚 ⊢! ∼φ ⋎ ∼ψ ⋎ φ := or <| rotate₁ <| or <| close φ
166-
ofEq this (by simp [DeMorgan.imply])
115+
have : 𝓢 ⊢! ∼φ ⋎ ∼ψ ⋎ φ := toProof _ <| or <| rotate₁ <| or <| close φ
116+
Entailment.cast this (by simp [DeMorgan.imply])
167117
implyS {φ ψ χ} :=
168-
have : 𝓚 ⊢! φ ⋏ ψ ⋏ ∼χ ⋎ φ ⋏ ∼ψ ⋎ ∼φ ⋎ χ :=
169-
or <| rotate₁ <| or <| rotate₁ <| or <| rotate₃ <| and
118+
have : 𝓢 ⊢! φ ⋏ ψ ⋏ ∼χ ⋎ φ ⋏ ∼ψ ⋎ ∼φ ⋎ χ :=
119+
toProof _ <| or <| rotate₁ <| or <| rotate₁ <| or <| rotate₃ <| and
170120
(close φ)
171121
(and (rotate₃ <| and (close φ) (close ψ)) (close χ))
172-
ofEq this (by simp [DeMorgan.imply])
122+
Entailment.cast this (by simp [DeMorgan.imply])
173123
and₁ {φ ψ} :=
174-
have : 𝓚 ⊢! (∼φ ⋎ ∼ψ) ⋎ φ := or <| or <| close φ
175-
ofEq this (by simp [DeMorgan.imply])
124+
have : 𝓢 ⊢! (∼φ ⋎ ∼ψ) ⋎ φ := toProof _ <|or <| or <| close φ
125+
Entailment.cast this (by simp [DeMorgan.imply])
176126
and₂ {φ ψ} :=
177-
have : 𝓚 ⊢! (∼φ ⋎ ∼ψ) ⋎ ψ := or <| or <| close ψ
178-
ofEq this (by simp [DeMorgan.imply])
127+
have : 𝓢 ⊢! (∼φ ⋎ ∼ψ) ⋎ ψ := toProof _ <| or <| or <| close ψ
128+
Entailment.cast this (by simp [DeMorgan.imply])
179129
and₃ {φ ψ} :=
180-
have : 𝓚 ⊢! ∼φ ⋎ ∼ψ ⋎ φ ⋏ ψ := or <| rotate₁ <| or <| rotate₁ <| and (close φ) (close ψ)
181-
ofEq this (by simp [DeMorgan.imply])
130+
have : 𝓢 ⊢! ∼φ ⋎ ∼ψ ⋎ φ ⋏ ψ := toProof _ <| or <| rotate₁ <| or <| rotate₁ <| and (close φ) (close ψ)
131+
Entailment.cast this (by simp [DeMorgan.imply])
182132
or₁ {φ ψ} :=
183-
have : 𝓚 ⊢! ∼φ ⋎ φ ⋎ ψ := or <| rotate₁ <| or <| close φ
184-
ofEq this (by simp [DeMorgan.imply])
133+
have : 𝓢 ⊢! ∼φ ⋎ φ ⋎ ψ := toProof _ <| or <| rotate₁ <| or <| close φ
134+
Entailment.cast this (by simp [DeMorgan.imply])
185135
or₂ {φ ψ} :=
186-
have : 𝓚 ⊢! ∼ψ ⋎ φ ⋎ ψ := or <| rotate₁ <| or <| close ψ
187-
ofEq this (by simp [DeMorgan.imply])
136+
have : 𝓢 ⊢! ∼ψ ⋎ φ ⋎ ψ := toProof _ <| or <| rotate₁ <| or <| close ψ
137+
Entailment.cast this (by simp [DeMorgan.imply])
188138
or₃ {φ ψ χ} :=
189-
have : 𝓚 ⊢! φ ⋏ ∼χ ⋎ ψ ⋏ ∼ χ ⋎ ∼φ ⋏ ∼ψ ⋎ χ :=
190-
or <| rotate₁ <| or <| rotate₁ <| or <| and
139+
have : 𝓢 ⊢! φ ⋏ ∼χ ⋎ ψ ⋏ ∼ χ ⋎ ∼φ ⋏ ∼ψ ⋎ χ :=
140+
toProof _ <| or <| rotate₁ <| or <| rotate₁ <| or <| and
191141
(rotate₃ <| and (close φ) (close χ))
192142
(rotate₂ <| and (close ψ) (close χ))
193-
ofEq this (by simp [DeMorgan.imply])
143+
Entailment.cast this (by simp [DeMorgan.imply])
194144
dne {φ} :=
195-
have : 𝓚 ⊢! ∼φ ⋎ φ := or <| close φ
196-
ofEq this (by simp [DeMorgan.imply])
197-
198-
lemma wkCut [Cut F K] (hp : 𝔇! φ :: Δ) (hn : 𝔇! ∼φ :: Δ) : 𝔇! Δ := ⟨cut hp.get hn.get⟩
199-
200-
def modusPonens [NegInvolutive F] [Cut F K] (b : 𝓚 ⊢! φ ➝ ψ) : 𝔇 φ :: Γ → 𝔇 ψ :: Γ := fun d ↦
201-
cut (φ := φ)
202-
(wk d <| by simp) <|
203-
cut (φ := φ ➝ ψ)
204-
(wk b <| by simp) <|
205-
have : 𝔇 φ ⋏ ∼ψ :: ∼φ :: ψ :: Γ := and (em' φ) (em' ψ)
206-
ofEq this <| by simp [DeMorgan.imply]
207-
208-
def modusPonens! [NegInvolutive F] [Cut F K] (b : 𝓚 ⊢ φ ➝ ψ) : 𝔇! φ :: Γ → 𝔇! ψ :: Γ := fun d ↦ ⟨modusPonens b.get d.get⟩
209-
210-
def cutFalsum [Cut F K] (d : 𝔇 ⊥ :: Γ) : 𝔇 Γ := Tait.cut (φ := ⊥) (Tait.wk d <| by simp) (ofEq (verum _ Γ) <| by simp)
211-
212-
def orReversion [Cut F K] (d : 𝔇 φ ⋎ ψ :: Γ) : 𝔇 φ :: ψ :: Γ :=
213-
Tait.cut (φ := φ ⋎ ψ)
214-
(wk d <| List.cons_subset_cons _ <| by simp)
215-
( have : 𝔇 ∼φ ⋏ ∼ψ :: φ :: ψ :: Γ := and (em' φ) (em' ψ)
216-
ofEq this (by simp) )
217-
218-
def disjConsOfAppend {Γ Δ} (d : 𝔇 Γ ++ Δ) : 𝔇 Γ.disj :: Δ :=
219-
match Γ with
220-
| [] => wk d (by simp)
221-
| φ :: Γ => or <|
222-
have : 𝔇 Γ ++ φ :: Δ := wk d <| by simp
223-
wk (disjConsOfAppend this) (by simp)
224-
225-
def proofOfDerivation (d : 𝔇 Γ) : 𝓚 ⊢! Γ.disj := disjConsOfAppend (Γ := Γ) (Δ := []) (ofEq d (by simp))
226-
227-
def AppendOfDisjCons [Cut F K] {Γ Δ} (d : 𝔇 Γ.disj :: Δ) : 𝔇 Γ ++ Δ :=
228-
match Γ with
229-
| [] => ofEq (cutFalsum d) (by simp)
230-
| φ :: Γ =>
231-
have : 𝔇 Γ.disj :: φ :: Δ := wk (orReversion d) (by simp)
232-
wk (AppendOfDisjCons this) (by simp)
233-
234-
def derivationOfProof [Cut F K] (d : 𝓚 ⊢! Γ.disj) : 𝔇 Γ := ofEq (AppendOfDisjCons d) (by simp)
235-
236-
lemma derivable_iff_provable_disj [Cut F K] : 𝔇! Γ ↔ 𝓚 ⊢ Γ.disj :=
237-
⟨fun h ↦ ⟨proofOfDerivation h.get⟩, fun h ↦ ⟨derivationOfProof h.get⟩⟩
145+
have : 𝓢 ⊢! ∼φ ⋎ φ := toProof _ <| or <| close φ
146+
Entailment.cast this (by simp [DeMorgan.imply])
238147

239-
end Tait
148+
end OneSidedLK
240149

241150
end LO
242151

0 commit comments

Comments
 (0)