Skip to content

Commit 0ba2305

Browse files
committed
soundness
1 parent e77ef25 commit 0ba2305

3 files changed

Lines changed: 69 additions & 70 deletions

File tree

Foundation/FirstOrder/Basic/Calculus.lean

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,19 @@ end Derivation
249249

250250
/-! ## Classical proof system -/
251251

252-
inductive LK.Symbol (L : Language)
252+
inductive LK (L : Language)
253253
| symbol
254254

255-
notation "𝐋𝐊¹" => LK.Symbol.symbol
255+
notation "𝐋𝐊¹" => LK.symbol
256256

257-
notation "𝐋𝐊¹[" L "]" => LK.Symbol.symbol (L := L)
257+
notation "𝐋𝐊¹[" L "]" => LK.symbol (L := L)
258258

259-
abbrev LK (φ : Proposition L) := ⊢ᴸᴷ¹ [φ]
259+
abbrev LK.Proof (φ : Proposition L) := ⊢ᴸᴷ¹ [φ]
260260

261-
instance : Entailment (LK.Symbol L) (Proposition L) where
262-
Prf _ := LK
261+
instance : Entailment (LK L) (Proposition L) where
262+
Prf _ := LK.Proof
263263

264-
namespace LK
264+
namespace LK.Proof
265265

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

@@ -270,10 +270,10 @@ lemma provable_def (φ : Proposition L) : 𝐋𝐊¹ ⊢ φ ↔ Nonempty (⊢ᴸ
270270
lemma unprovable_def (φ : Proposition L) : 𝐋𝐊¹ ⊬ φ ↔ IsEmpty (⊢ᴸᴷ¹ [φ]) := by
271271
unfold Entailment.Unprovable; simp [provable_def]
272272

273-
instance : OneSidedLK.PrincipalEntailment (Derivation (L := L)) (𝐋𝐊¹ : LK.Symbol L) where
273+
instance : OneSidedLK.PrincipalEntailment (Derivation (L := L)) (𝐋𝐊¹ : LK L) where
274274
equiv := Equiv.refl _
275275

276-
instance classical : Entailment.Cl (𝐋𝐊¹ : LK.Symbol L) := inferInstance
276+
instance classical : Entailment.Cl (𝐋𝐊¹ : LK L) := inferInstance
277277

278278
lemma all (φ : Semiproposition L 1) : 𝐋𝐊¹ ⊢ φ.free → 𝐋𝐊¹ ⊢ ∀⁰ φ := fun h ↦ ⟨Derivation.all h.get⟩
279279

@@ -285,21 +285,21 @@ lemma allClosure_fixitr {φ : Proposition L} (dp : 𝐋𝐊¹ ⊢ φ) : (m : ℕ
285285

286286
lemma univCl' {φ : Proposition L} (b : 𝐋𝐊¹ ⊢ φ) : 𝐋𝐊¹ ⊢ φ.univCl' := allClosure_fixitr b φ.fvSup
287287

288-
end LK
288+
end LK.Proof
289289

290-
structure Theory.LK (T : Theory L) (σ : Sentence L) where
290+
structure Theory.Proof (T : Theory L) (σ : Sentence L) where
291291
axioms : List (Sentence L)
292292
axioms_mem : ∀ ψ ∈ axioms, ψ ∈ T
293293
derivation : OneSidedLK.Pullback Derivation Rewriting.emb (σ :: ∼axioms)
294294

295-
namespace Theory
295+
namespace Theory.Proof
296296

297297
instance : Entailment (Theory L) (Sentence L) where
298-
Prf := Theory.LK
298+
Prf := Theory.Proof
299299

300300
variable {T : Theory L}
301301

302-
attribute [simp] LK.axioms_mem
302+
attribute [simp] Theory.Proof.axioms_mem
303303

304304
instance : Entailment.Compact (Theory L) where
305305
core b := {φ | φ ∈ b.axioms}
@@ -314,6 +314,8 @@ instance : OneSidedLK.ContextualEntailment (OneSidedLK.Pullback Derivation Rewri
314314

315315
instance : Entailment.Cl T := OneSidedLK.ContextualEntailment.cl T
316316

317+
instance : Entailment.Axiomatized (Theory L) := inferInstance
318+
317319
lemma weakerThan_of_le {T U : Theory L} (h : T ⊆ U) : T ⪯ U := Entailment.Axiomatized.weakerThanOfSubset h
318320

319321
instance (T U : Theory L) : T ⪯ T ∪ U := weakerThan_of_le (by simp)
@@ -334,14 +336,14 @@ open Entailment Derivation
334336
(∅ : Theory L) ⊢ φ ↔ 𝐋𝐊¹ ⊢ (φ : Proposition L) := by
335337
simpa using OneSidedLK.ContextualEntailment.empty_provable_iff_eprovable
336338
(S := Theory L)
337-
(𝓟 := pullback 𝐋𝐊¹[L] (Rewriting.emb : Sentence L → Proposition L))
339+
(𝓟 := pullback (𝐋𝐊¹[L]) (Rewriting.emb : Sentence L → Proposition L))
338340
(φ := φ)
339341

340342
lemma iff_context {T : Theory L} :
341343
T ⊢ φ ↔ T *⊢[pullback 𝐋𝐊¹[L] (Rewriting.emb : _ → Proposition L)] φ :=
342344
OneSidedLK.ContextualEntailment.iff_context
343345

344-
end Theory
346+
end Theory.Proof
345347

346348
namespace Theory
347349

@@ -359,10 +361,10 @@ end Theory
359361

360362
/-! ### Theory -/
361363

362-
def Theory.theory (T : Theory L) : Theory L := {σ | T ⊢ σ}
364+
def Theory.theory (T : Theory L) : Theory L := {σ | T ⊢ σ}
363365

364366
@[simp] lemma Theory.mem_theory {T : Theory L} :
365-
σ ∈ T.theory ↔ T ⊢ σ := by simp [Theory.theory]
367+
σ ∈ T.theory ↔ T ⊢ σ := by simp [Theory.theory]
366368

367369
end FirstOrder
368370

Foundation/FirstOrder/Basic/Semantics/Semantics.lean

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module
22

3-
public import Foundation.FirstOrder.Basic.Syntax.Schema
3+
public import Foundation.FirstOrder.Basic.Syntax.Rew
44
public import Foundation.Vorspiel.IsEmpty
55
public import Foundation.Vorspiel.Empty
66

@@ -238,7 +238,7 @@ abbrev Evalf [s : Structure L M] (f : ξ → M) : Formula L ξ →ˡᶜ Prop :=
238238
abbrev Evalb [s : Structure L M] (b : Fin n → M) :
239239
Semiformula L Empty n →ˡᶜ Prop := Eval b Empty.elim
240240

241-
abbrev Eval₀ (M : Type*) [s : Structure L M] :
241+
abbrev Realize (M : Type*) [s : Structure L M] :
242242
Sentence L →ˡᶜ Prop := Eval (s := s) ![] Empty.elim
243243

244244
abbrev Models (s : Structure L M) : Formula L M →ˡᶜ Prop := Eval ![] id
@@ -447,7 +447,7 @@ lemma eval_toEmpty [DecidableEq ξ] {n} {φ : Semiformula L ξ n} (hp : φ.freeV
447447
intro x hx; simp [Rew.fixitr_fvar, lt_fvSup_of_fvar? hx]
448448

449449
@[simp] lemma eval_univCl [Nonempty M] (φ : Proposition L) :
450-
Eval₀ M φ.univCl ↔ ∀ f : ℕ → M, Evalf f φ := by
450+
Realize M φ.univCl ↔ ∀ f : ℕ → M, Evalf f φ := by
451451
haveI : Inhabited M := Classical.inhabited_of_nonempty inferInstance
452452
simp [Semiformula.univCl, ←eval_toEmpty (f := default)]
453453

@@ -491,7 +491,7 @@ end
491491
end Structure
492492

493493
instance : Semantics (Struc L) (Sentence L) where
494-
Models := fun str ↦ Semiformula.Eval₀ str.Dom
494+
Models := fun str ↦ Semiformula.Realize str.Dom
495495

496496
instance : Semantics.Tarski (Struc L) where
497497
models_verum := by simp [Semantics.Models]
@@ -521,15 +521,12 @@ variable {M}
521521

522522
lemma struc_models_iff_models {s : Struc L} : s ⊧ σ ↔ s.Dom↓[L] ⊧ σ := by rfl
523523

524-
lemma models_iff : M↓[L] ⊧ σ ↔ σ.Eval₀ M := by rfl
524+
lemma models_iff : M↓[L] ⊧ σ ↔ σ.Realize M := by rfl
525525

526526
lemma models_iff_proposition {φ : Proposition L} : M↓[L] ⊧ φ.univCl ↔ ∀ f : ℕ → M, φ.Evalf f := by
527527
simp [models_iff]
528528

529-
lemma models_theory_iff : M↓[L] ⊧* T ↔ (∀ {φ}, φ ∈ T → M↓[L] ⊧ φ) := Semantics.modelsSet_iff
530-
531-
lemma models_schema_iff {𝔖 : Schema L} : M↓[L] ⊧* (𝔖 : Theory L) ↔ (∀ {φ : Proposition L}, φ ∈ 𝔖 → ∀ f : ℕ → M, φ.Evalf f) := by
532-
simp [models_theory_iff, models_iff]
529+
lemma models_theory_iff : M↓[L] ⊧* T ↔ ∀ φ ∈ T, M↓[L] ⊧ φ := Semantics.modelsSet_iff
533530

534531
lemma models_of_mem {T : Theory L} [M↓[L] ⊧* T] {φ} (h : φ ∈ T) : M↓[L] ⊧ φ := Semantics.ModelsSet.models _ h
535532

@@ -592,7 +589,7 @@ lemma consequence_iff_unsatisfiable {σ : Sentence L} :
592589
intro hT; simpa using models_iff.mp (h hT)
593590
· intro h; apply consequence_iff.mpr
594591
intro M _ s hT
595-
have : σ.Eval₀ M := by
592+
have : σ.Realize M := by
596593
have := by simpa only [Semantics.ModelsSet.insert_iff, not_and', models_iff] using unsatisfiable_iff.mp h M inferInstance s
597594
simpa using this hT
598595
apply models_iff.mpr (by simpa using this)
@@ -619,7 +616,7 @@ end lMap
619616

620617
end Semiformula
621618

622-
section schema
619+
section theory
623620

624621
variable (M) [Nonempty M] [Structure L M]
625622

@@ -628,19 +625,19 @@ variable {M}
628625
lemma models_of_ss {T U : Theory L} (h : M↓[L] ⊧* U) (ss : T ⊆ U) : M↓[L] ⊧* T :=
629626
Semantics.ModelsSet.of_subset h ss
630627

631-
lemma models_of_le {𝔖₁ 𝔖₂ : Schema L} (h : M↓[L] ⊧* ↑↑𝔖₂) (le : 𝔖₁ ≤ 𝔖₂) : M↓[L] ⊧* ↑↑𝔖₁ :=
632-
Semantics.ModelsSet.of_subset h (Schema.coe_subset_coe_of_le le)
628+
lemma models_of_le {T₁ T₂ : Theory L} (h : M↓[L] ⊧* T₂) (le : T₁ ⊆ T₂) : M↓[L] ⊧* T₁ :=
629+
Semantics.ModelsSet.of_subset h le
633630

634-
instance models_schema_sup (𝔖₁ 𝔖₂ : Schema L) [M↓[L] ⊧* ↑↑𝔖₁] [M↓[L] ⊧* ↑↑𝔖₂] : M↓[L] ⊧* ↑↑(𝔖₁ ∪ 𝔖₂) := by
635-
simp only [Schema.coe_sup, Semantics.ModelsSet.union_iff]
631+
instance models_theory_sup (T₁ T₂ : Theory L) [M↓[L] ⊧* T₁] [M↓[L] ⊧* T₂] : M↓[L] ⊧* T₁ ∪ T₂ := by
632+
simp only [Semantics.ModelsSet.union_iff]
636633
constructor
637634
· infer_instance
638635
· infer_instance
639636

640-
lemma modelsUnivCl_of_mem_schema {𝔖 : Schema L} [h : M↓[L] ⊧* ↑↑𝔖] (hf : φ ∈ 𝔖) : M↓[L] ⊧ φ.univCl :=
641-
h.models _ <| by simp; grind
637+
lemma models_of_mem_theory {T : Theory L} [h : M↓[L] ⊧* T] (hf : φ ∈ T) : M↓[L] ⊧ φ :=
638+
h.models _ hf
642639

643-
end schema
640+
end theory
644641

645642
namespace Structure
646643

Foundation/FirstOrder/Basic/Soundness.lean

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,53 +72,53 @@ end Derivation
7272
theorem Provable.sound {M : Type*} [s : Structure L M] [Nonempty M] {φ : Proposition L} (f : ℕ → M) :
7373
𝐋𝐊¹ ⊢ φ → φ.Evalf f := fun b ↦ by simpa using Derivation.sound f b.get
7474

75-
variable {𝔖 : Schema L}
76-
77-
theorem Schema.sound_proposition {M : Type*} [s : Structure L M] [Nonempty M] :
78-
𝔖 ⊢ φ → M↓[L] ⊧* ↑↑𝔖 → ∀ f : ℕ → M, φ.Evalf f := fun b H f ↦ by
79-
rcases Schema.provable_iff.mp b with ⟨Γ, hΓ, ⟨b⟩⟩
80-
have : φ.Evalf f ∨ ∃ ψ, ∼ψ ∈ Γ ∧ ψ.Evalf f := by simpa using b.sound f
75+
variable {T : Theory L}
76+
77+
theorem Theory.Proof.sound_proposition {M : Type*} [s : Structure L M] [Nonempty M] :
78+
T ⊢ φ → M↓[L] ⊧* T → φ.Realize M := fun b H ↦ by
79+
rcases Theory.Proof.provable_iff.mp b with ⟨Γ, hΓ, ⟨b⟩⟩
80+
have : Inhabited M := Classical.inhabited_of_nonempty inferInstance
81+
let f : ℕ → M := fun _ ↦ default
82+
have : φ.Realize M ∨ ∃ ψ, ∼ψ ∈ Sequent.embed Γ ∧ ψ.Evalf f := by simpa using b.sound f
8183
rcases this with (h | ⟨ψ, hψ, h⟩)
8284
· assumption
83-
· have : ¬ψ.Evalf f := by
84-
have := by simpa [models_iff] using H.models _ (φ := (∼ψ).univCl) (by grind only [Schema.mem_uniClosure])
85-
exact this f
85+
· have : ∃ χ, ∼χ ∈ Γ ∧ ↑χ = ψ := by
86+
have : ∃ χ ∈ Γ, χ = ∼ψ := by simpa [Sequent.embed] using
87+
rcases this with ⟨χ, hχ, e⟩
88+
refine ⟨∼χ, by simpa using hχ, by simp [e]⟩
89+
rcases this with ⟨χ, hχ, rfl⟩
90+
have : χ.Realize M := by simpa using h
91+
have : ¬χ.Realize M := by
92+
simpa [models_iff] using H.models _ (hΓ _ hχ)
8693
contradiction
8794

88-
theorem Schema.sound_proposition' :
89-
𝔖 ⊢ φ → (𝔖 : Theory L) ⊨[Struc.{v, u} L] φ.univCl := fun b s hS ↦ by
95+
theorem Theory.Proof.sound {φ : Sentence L} :
96+
T ⊢ φ → T ⊨[Struc.{v, u} L] φ := fun b s hS ↦ by
9097
simpa [struc_models_iff_models (s := s), models_iff]
91-
using Schema.sound_proposition b hS
92-
93-
theorem Schema.sound_sentence {σ : Sentence L} :
94-
𝔖 ⊢ ↑σ → (𝔖 : Theory L) ⊨[Struc.{v, u} L] σ := fun b ↦ by
95-
simpa using Schema.sound_proposition' b
98+
using Theory.Proof.sound_proposition b hS
9699

97-
theorem Schema.smallSound_sentence {σ : Sentence L} : 𝔖 ⊢ ↑σ(𝔖 : Theory L) ⊨ σ := Schema.sound_sentence
100+
theorem Theory.Proof.sound_small : T ⊢ φT ⊨ φ := Theory.Proof.sound
98101

99-
instance sound (𝔖 : Schema L) :
100-
Sound (Entailment.pullback 𝔖 ((↑·) : Sentence L → Proposition L)) (Semantics.models (Struc.{v, u} L) 𝔖) :=
101-
⟨Schema.sound_sentence⟩
102+
instance sound (T : Theory L) : Sound T (Semantics.models (Struc.{v, u} L) T) := ⟨Theory.Proof.sound⟩
102103

103-
lemma models_of_subtheory {𝔖 𝔗 : Schema L} [𝔖 ⪯ 𝔗] {M : Type*} [Structure L M] [Nonempty M] : M↓[L] ⊧* ↑↑𝔗 → M↓[L] ⊧* ↑↑𝔖 :=
104-
fun hM ↦ ⟨fun {σ} hσ ↦ by
105-
rcases show ∃ φ ∈ 𝔖, univCl φ = σ by simpa usingwith ⟨φ, hφ, rfl⟩
106-
have : 𝔖 ⪯ 𝔗 := inferInstance
107-
have : 𝔗 ⊢ φ := this.pbl (Entailment.by_axm hφ)
108-
exact Schema.sound_proposition' this hM⟩
104+
lemma models_of_subtheory {T U : Theory L} [T ⪯ U] {M : Type*} [Structure L M] [Nonempty M] : M↓[L] ⊧* U → M↓[L] ⊧* T :=
105+
fun hM ↦ ⟨fun {φ} hφ ↦ by
106+
have : T ⪯ U := inferInstance
107+
have : U ⊢ φ := this.pbl (Entailment.by_axm hφ)
108+
exact Theory.Proof.sound this hM⟩
109109

110-
lemma consistent_of_satisfiable (h : Semantics.Satisfiable (Struc.{v, u} L) ↑↑𝔖) : Entailment.Consistent 𝔖 :=
111-
Entailment.Pullback.consistent <| Sound.consistent_of_satisfiable (𝓢 := Entailment.pullback 𝔖 ((↑·) : Sentence L → Proposition L)) h
110+
lemma consistent_of_satisfiable (h : Semantics.Satisfiable (Struc.{v, u} L) T) : Entailment.Consistent T :=
111+
Sound.consistent_of_satisfiable h
112112

113-
lemma consistent_of_model (𝔖 : Schema L) (M : Type*) [Structure L M] [Nonempty M] [hM : M↓[L] ⊧* ↑↑𝔖] :
114-
Entailment.Consistent 𝔖 := consistent_of_satisfiable ⟨M↓[L], hM⟩
113+
lemma consistent_of_model (T : Theory L) (M : Type*) [Structure L M] [Nonempty M] [hM : M↓[L] ⊧* T] :
114+
Entailment.Consistent T := consistent_of_satisfiable ⟨M↓[L], hM⟩
115115

116-
lemma unprovable_of_countermodel {M : Type*} [Structure L M] [Nonempty M] [hM : M↓[L] ⊧* ↑↑𝔖] {σ} : M↓[L] ⊭ σ𝔖↑σ := by
116+
lemma unprovable_of_countermodel {M : Type*} [Structure L M] [Nonempty M] [hM : M↓[L] ⊧* T] {φ} : M↓[L] ⊭ φTφ := by
117117
contrapose!; intro h
118-
exact Schema.sound_sentence h hM
118+
exact Theory.Proof.sound h hM
119119

120-
lemma models_of_provable {M : Type*} [Nonempty M] [Structure L M] (hT : M↓[L] ⊧* ↑↑𝔖) {σ : Sentence L} (h : 𝔖↑σ) :
121-
M↓[L] ⊧ σ := consequence_iff.mp (Schema.sound_sentence h) M inferInstance
120+
lemma models_of_provable {M : Type*} [Nonempty M] [Structure L M] (hT : M↓[L] ⊧* ↑↑T) {φ : Sentence L} (h : Tφ) :
121+
M↓[L] ⊧ φ := consequence_iff.mp (Theory.Proof.sound h) M inferInstance
122122

123123
end sound
124124

0 commit comments

Comments
 (0)