This repository was archived by the owner on Jul 2, 2026. It is now read-only.
forked from gotrevor/Foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic.lean
More file actions
396 lines (276 loc) · 13.3 KB
/
Copy pathBasic.lean
File metadata and controls
396 lines (276 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
module
public import Foundation.Propositional.Formula.Basic
public import Foundation.Propositional.Entailment.Cl.Basic
public import Foundation.Vorspiel.Rel.Basic
@[expose] public section
namespace LO.Propositional
namespace Kripke
structure Frame where
World : Type
Rel : Rel World World
[world_nonempty : Nonempty World]
[rel_partial_order : IsPartialOrder _ Rel]
instance : CoeSort Frame (Type) := ⟨Frame.World⟩
instance : CoeFun Frame (λ F => _root_.Rel F.World F.World) := ⟨Frame.Rel⟩
instance {F : Frame} : Nonempty F.World := F.world_nonempty
instance {F : Frame} : IsPartialOrder F.World F.Rel := F.rel_partial_order
abbrev Frame.Rel' {F : Frame} (x y : F.World) := F.Rel x y
infix:45 " ≺ " => Frame.Rel'
namespace Frame
variable {F : Frame} {x y z : F.World}
@[mk_iff]
class IsFinite (F : Frame) : Prop where [world_finite : Finite F.World]
attribute [instance] Frame.IsFinite.world_finite
instance [Finite F.World] : F.IsFinite := ⟨⟩
@[simp, refl] lemma refl {x : F.World} : x ≺ x := F.rel_partial_order.refl x
@[trans] lemma trans {x y z : F.World} : x ≺ y → y ≺ z → x ≺ z := F.rel_partial_order.trans x y z
lemma antisymm {x y : F.World} : x ≺ y → y ≺ x → x = y := F.rel_partial_order.antisymm x y
end Frame
section
abbrev whitepoint : Frame where
World := Unit
Rel := fun _ _ => True
rel_partial_order := ⟨⟩
instance : whitepoint.IsFinite := inferInstance
end
abbrev FrameClass := Set (Frame)
structure Valuation (F : Frame) where
Val : ℕ → F.World → Prop
hereditary : ∀ {w₁ w₂ : F.World}, (w₁ ≺ w₂) → ∀ {a}, (Val a w₁) → (Val a w₂)
instance {F : Frame} : CoeFun (Valuation F) (λ _ => ℕ → F.World → Prop) := ⟨Valuation.Val⟩
structure Model extends Frame where
Val : Valuation toFrame
instance : CoeSort (Model) (Type) := ⟨λ M => M.World⟩
instance : CoeFun (Model) (λ M => ℕ → M.World → Prop) := ⟨fun m => m.Val⟩
end Kripke
open Kripke
open Formula
namespace Formula.Kripke
def Satisfies (M : Kripke.Model) (w : M.World) : Formula ℕ → Prop
| atom a => M a w
| ⊥ => False
| φ ⋏ ψ => Satisfies M w φ ∧ Satisfies M w ψ
| φ ⋎ ψ => Satisfies M w φ ∨ Satisfies M w ψ
| φ 🡒 ψ => ∀ {w' : M.World}, (w ≺ w') → (Satisfies M w' φ → Satisfies M w' ψ)
namespace Satisfies
instance semantics (M : Kripke.Model) : Semantics M (Formula ℕ) := ⟨fun w ↦ Formula.Kripke.Satisfies M w⟩
variable {M : Kripke.Model} {w w' : M.World} {a : ℕ} {φ ψ χ : Formula ℕ}
@[simp] protected lemma iff_models : w ⊧ φ ↔ Formula.Kripke.Satisfies M w φ := iff_of_eq rfl
@[simp] lemma atom_def : w ⊧ atom a ↔ M a w := by simp [Satisfies];
@[simp] lemma top_def : w ⊧ ⊤ ↔ True := by simp [Satisfies];
@[simp] lemma bot_def : w ⊧ ⊥ ↔ False := by simp [Satisfies];
@[simp] lemma and_def : w ⊧ φ ⋏ ψ ↔ w ⊧ φ ∧ w ⊧ ψ := by simp [Satisfies];
@[simp] lemma or_def : w ⊧ φ ⋎ ψ ↔ w ⊧ φ ∨ w ⊧ ψ := by simp [Satisfies];
@[simp] lemma imp_def : w ⊧ φ 🡒 ψ ↔ ∀ {w' : M.World}, (w ≺ w') → (w' ⊧ φ → w' ⊧ ψ) := by simp [Satisfies, imp_iff_not_or];
@[simp] lemma neg_def : w ⊧ ∼φ ↔ ∀ {w' : M.World}, (w ≺ w') → ¬(w' ⊧ φ) := by simp [Satisfies];
lemma not_of_neg : w ⊧ ∼φ → ¬w ⊧ φ := fun h hC ↦ h (refl w) hC
instance : Semantics.Top M.World where
models_verum := by simp [Satisfies];
instance : Semantics.Bot M.World where
models_falsum := by simp [Semantics.NotModels, Satisfies];
instance : Semantics.And M.World where
models_and := by simp [Satisfies];
instance : Semantics.Or M.World where
models_or := by simp [Satisfies];
lemma formula_hereditary
(hw : w ≺ w') : w ⊧ φ → w' ⊧ φ := by
induction φ with
| hatom => apply M.Val.hereditary hw;
| himp =>
intro hpq v hv;
exact hpq $ M.trans hw hv;
| hor => simp_all; tauto;
| _ => simp_all;
lemma formula_hereditary_not (hw : w ≺ w') : ¬w' ⊧ φ → ¬w ⊧ φ := by
contrapose!;
exact formula_hereditary hw;
lemma negEquiv : w ⊧ ∼φ ↔ w ⊧ φ 🡒 ⊥ := by simp_all [Satisfies];
lemma iff_subst_self {F : Frame} {V : Valuation F} {x : F.World} (s) :
letI U : Kripke.Valuation F := ⟨
λ a w => Satisfies ⟨F, V⟩ w ((.atom a)⟦s⟧),
fun {_ _} Rwv {_} => formula_hereditary Rwv
⟩;
Satisfies ⟨F, U⟩ x φ ↔ Satisfies ⟨F, V⟩ x (φ⟦s⟧) := by
induction φ generalizing x with
| hatom a => simp [Satisfies];
| hfalsum => simp [Satisfies];
| himp φ ψ ihφ ihψ =>
constructor;
. intro hφψ y Rxy hφs;
apply ihψ.mp;
apply hφψ Rxy;
apply ihφ.mpr hφs;
. intro hφψs y Rxy hφ;
apply ihψ.mpr;
apply hφψs Rxy;
apply ihφ.mp hφ;
| hand φ ψ ihφ ihψ =>
constructor;
. rintro ⟨hφ, hψ⟩;
constructor;
. apply ihφ.mp hφ;
. apply ihψ.mp hψ;
. rintro ⟨hφ, hψ⟩;
apply Satisfies.and_def.mpr;
constructor;
. apply ihφ.mpr hφ;
. apply ihψ.mpr hψ;
| hor φ ψ ihφ ihψ =>
constructor;
. rintro (hφ | hψ);
. left; apply ihφ.mp hφ;
. right; apply ihψ.mp hψ;
. rintro (hφ | hψ);
. left; apply ihφ.mpr hφ;
. right; apply ihψ.mpr hψ;
end Satisfies
open Satisfies
def ValidOnModel (M : Kripke.Model) (φ : Formula ℕ) := ∀ w : M.World, w ⊧ φ
namespace ValidOnModel
instance semantics : Semantics Model (Formula ℕ) := ⟨fun M ↦ Formula.Kripke.ValidOnModel M⟩
variable {M : Model} {φ ψ χ : Formula ℕ}
@[simp] protected lemma iff_models : M ⊧ φ ↔ Formula.Kripke.ValidOnModel M φ := iff_of_eq rfl
protected lemma verum : M ⊧ ⊤ := by simp [ValidOnModel];
instance : Semantics.Top (Model) := ⟨λ _ => ValidOnModel.verum⟩
protected lemma bot : ¬M ⊧ ⊥ := by simp [ValidOnModel];
instance : Semantics.Bot (Model) := ⟨λ _ => ValidOnModel.bot⟩
lemma iff_not_exists_world {M : Kripke.Model} : (¬M ⊧ φ) ↔ (∃ x : M.World, ¬x ⊧ φ) := by
apply not_iff_not.mp;
push Not;
tauto;
alias ⟨exists_world_of_not, not_of_exists_world⟩ := iff_not_exists_world
protected lemma andElim₁ : M ⊧ φ ⋏ ψ 🡒 φ := by simp_all [ValidOnModel, Satisfies];
protected lemma andElim₂ : M ⊧ φ ⋏ ψ 🡒 ψ := by simp_all [ValidOnModel, Satisfies];
protected lemma andInst₃ : M ⊧ φ 🡒 ψ 🡒 φ ⋏ ψ := by
intro x y _ hp z Ryz hq;
replace hp : Satisfies M z φ := formula_hereditary Ryz hp;
exact ⟨hp, hq⟩;
protected lemma orInst₁ : M ⊧ φ 🡒 φ ⋎ ψ := by simp_all [ValidOnModel, Satisfies];
protected lemma orInst₂ : M ⊧ ψ 🡒 φ ⋎ ψ := by simp_all [ValidOnModel, Satisfies];
protected lemma orElim : M ⊧ (φ 🡒 χ) 🡒 (ψ 🡒 χ) 🡒 (φ ⋎ ψ 🡒 χ) := by
intro w₁ w₂ _ hpr w₃ hw₂₃ hqr w₄ hw₃₄ hpq;
cases hpq with
| inl hp => exact hpr (M.trans hw₂₃ hw₃₄) hp;
| inr hq => exact hqr hw₃₄ hq;
protected lemma implyK : M ⊧ φ 🡒 ψ 🡒 φ := by
intro x y _ hp z Ryz _;
exact formula_hereditary Ryz hp;
protected lemma implyS : M ⊧ (φ 🡒 ψ 🡒 χ) 🡒 (φ 🡒 ψ) 🡒 φ 🡒 χ := by
intro x y _ hpqr z Ryz hpq w Rzw hp;
have Ryw : y ≺ w := M.trans Ryz Rzw;
have Rww : w ≺ w := M.refl;
exact hpqr Ryw hp Rww (hpq Rzw hp);
protected lemma mdp (hpq : M ⊧ φ 🡒 ψ) (hp : M ⊧ φ) : M ⊧ ψ := by
intro w;
exact hpq w M.refl $ hp w;
protected lemma efq : M ⊧ Axioms.EFQ φ := by simp [ValidOnModel, Satisfies];
end ValidOnModel
def ValidOnFrame (F : Frame) (φ : Formula ℕ) := ∀ V, (⟨F, V⟩ : Kripke.Model) ⊧ φ
namespace ValidOnFrame
instance semantics : Semantics Frame (Formula ℕ) := ⟨fun F ↦ Formula.Kripke.ValidOnFrame F⟩
variable {F : Frame} {φ ψ χ : Formula ℕ}
@[simp] protected lemma models_iff : F ⊧ φ ↔ ValidOnFrame F φ := iff_of_eq rfl
protected lemma top : F ⊧ ⊤ := by tauto;
instance : Semantics.Top (Frame) := ⟨λ _ => ValidOnFrame.top⟩
protected lemma bot : ¬F ⊧ ⊥ := by
simp [ValidOnFrame.models_iff, ValidOnFrame];
exact ⟨(λ _ _ => True), by tauto⟩;
instance : Semantics.Bot (Frame) := ⟨λ _ => ValidOnFrame.bot⟩
lemma iff_not_exists_valuation : (¬F ⊧ φ) ↔ (∃ V : Kripke.Valuation F, ¬(⟨F, V⟩ : Kripke.Model) ⊧ φ) := by
simp [ValidOnFrame];
alias ⟨exists_valuation_of_not, not_of_exists_valuation⟩ := iff_not_exists_valuation
lemma iff_not_exists_valuation_world : (¬F ⊧ φ) ↔ (∃ V : Kripke.Valuation F, ∃ x : (⟨F, V⟩ : Kripke.Model).World, ¬Satisfies _ x φ) := by
simp [ValidOnFrame, ValidOnModel, Semantics.Models];
alias ⟨exists_valuation_world_of_not, not_of_exists_valuation_world⟩ := iff_not_exists_valuation_world
lemma iff_not_exists_model_world : (¬F ⊧ φ) ↔ (∃ M : Kripke.Model, ∃ x : M.World, M.toFrame = F ∧ ¬(x ⊧ φ)) := by
constructor;
. intro h;
obtain ⟨V, x, h⟩ := iff_not_exists_valuation_world.mp h;
use ⟨F, V⟩, x;
tauto;
. rintro ⟨M, x, rfl, h⟩;
exact iff_not_exists_valuation_world.mpr ⟨M.Val, x, h⟩;
alias ⟨exists_model_world_of_not, not_of_exists_model_world⟩ := iff_not_exists_model_world
protected lemma subst (h : F ⊧ φ) : F ⊧ φ⟦s⟧ := by
by_contra hC;
obtain ⟨V, ⟨x, hx⟩⟩ := exists_valuation_world_of_not hC;
apply Satisfies.iff_subst_self s |>.not.mpr hx;
apply h;
protected lemma andElim₁ : F ⊧ φ ⋏ ψ 🡒 φ := fun _ => ValidOnModel.andElim₁
protected lemma andElim₂ : F ⊧ φ ⋏ ψ 🡒 ψ := fun _ => ValidOnModel.andElim₂
protected lemma andInst₃ : F ⊧ φ 🡒 ψ 🡒 φ ⋏ ψ := fun _ => ValidOnModel.andInst₃
protected lemma orInst₁ : F ⊧ φ 🡒 φ ⋎ ψ := fun _ => ValidOnModel.orInst₁
protected lemma orInst₂ : F ⊧ ψ 🡒 φ ⋎ ψ := fun _ => ValidOnModel.orInst₂
protected lemma orElim : F ⊧ (φ 🡒 χ) 🡒 (ψ 🡒 χ) 🡒 (φ ⋎ ψ 🡒 χ) := fun _ => ValidOnModel.orElim
protected lemma implyK : F ⊧ φ 🡒 ψ 🡒 φ := fun _ => ValidOnModel.implyK
protected lemma implyS : F ⊧ (φ 🡒 ψ 🡒 χ) 🡒 (φ 🡒 ψ) 🡒 φ 🡒 χ := fun _ => ValidOnModel.implyS
protected lemma mdp (hpq : F ⊧ φ 🡒 ψ) (hp : F ⊧ φ) : F ⊧ ψ := fun V x => ValidOnModel.mdp (hpq V) (hp V) x
protected lemma efq : F ⊧ Axioms.EFQ φ := fun _ => ValidOnModel.efq
attribute [simp, grind .]
ValidOnFrame.andElim₁
ValidOnFrame.andElim₂
ValidOnFrame.andInst₃
ValidOnFrame.orInst₁
ValidOnFrame.orInst₂
ValidOnFrame.orElim
ValidOnFrame.implyK
ValidOnFrame.implyS
ValidOnFrame.efq
end ValidOnFrame
end Formula.Kripke
namespace Kripke
section
variable {C : Kripke.FrameClass} {φ ψ χ : Formula ℕ}
lemma iff_not_validOnFrameClass_exists_frame : (¬C ⊧ φ) ↔ (∃ F ∈ C, ¬F ⊧ φ) := by
apply not_iff_not.mp;
push Not;
tauto;
alias ⟨exists_frame_of_not_validOnFrameClass, not_validOnFrameClass_of_exists_frame⟩ := iff_not_validOnFrameClass_exists_frame
lemma iff_not_validOnFrameClass_exists_model : (¬C ⊧ φ) ↔ (∃ M : Kripke.Model, M.toFrame ∈ C ∧ ¬M ⊧ φ) := by
apply not_iff_not.mp;
push Not;
tauto;
alias ⟨exists_model_of_not_validOnFrameClass, not_validOnFrameClass_of_exists_model⟩ := iff_not_validOnFrameClass_exists_model
lemma iff_not_validOnFrameClass_exists_model_world : (¬C ⊧ φ) ↔ (∃ M : Kripke.Model, ∃ x : M.World, M.toFrame ∈ C ∧ ¬(x ⊧ φ)) := by
apply not_iff_not.mp;
push Not;
tauto;
alias ⟨exists_model_world_of_not_validOnFrameClass, not_validOnFrameClass_of_exists_model_world⟩ := iff_not_validOnFrameClass_exists_model_world
end
section
open Formula (atom)
namespace FrameClass
def Validates (C : FrameClass) (Γ : FormulaSet ℕ) := ∀ F ∈ C, ∀ φ ∈ Γ, F ⊧ φ
abbrev ValidatesFormula (C : FrameClass) (φ : Formula ℕ) := Validates C {φ}
variable {C C₁ C₂ : FrameClass} {Γ Γ₁ Γ₂ : FormulaSet ℕ} {φ φ₁ φ₂ : Formula ℕ}
lemma Validates.inter_of (h₁ : C₁.Validates Γ₁) (h₂ : C₂.Validates Γ₂) : (C₁ ∩ C₂).Validates (Γ₁ ∪ Γ₂) := by
rintro F;
rintro ⟨hF₁, hF₂⟩ φ (hφ₁ | hφ₂);
. exact h₁ F hF₁ _ hφ₁;
. exact h₂ F hF₂ _ hφ₂;
lemma ValidatesFormula.inter_of (h₁ : C₁.ValidatesFormula φ₁) (h₂ : C₂.ValidatesFormula φ₂) : (C₁ ∩ C₂).Validates {φ₁, φ₂}
:= Validates.inter_of h₁ h₂
protected abbrev all : FrameClass := Set.univ
@[simp]
lemma all.IsNonempty : FrameClass.all.Nonempty := by use whitepoint; tauto;
lemma all.validates_AxiomEFQ : FrameClass.all.ValidatesFormula (Axioms.EFQ (.atom 0)) := by
suffices ∀ (F : Frame), Formula.Kripke.ValidOnFrame F (Axioms.EFQ (.atom 0)) by simpa [Validates];
intro F;
exact Formula.Kripke.ValidOnFrame.efq;
lemma Validates.withAxiomEFQ (hV : C.Validates Γ) : C.Validates (insert (Axioms.EFQ (.atom 0)) Γ) := by
intro F hF φ hφ;
rcases hφ with rfl | hφ;
· exact Formula.Kripke.ValidOnFrame.efq;
· exact hV F hF φ hφ;
protected abbrev finite_all : FrameClass := { F | F.IsFinite }
@[simp]
lemma finite_all.nonempty : FrameClass.finite_all.Nonempty := by use whitepoint; tauto;
lemma finite_all.validates_AxiomEFQ : FrameClass.finite_all.ValidatesFormula (Axioms.EFQ (.atom 0)) := by
suffices ∀ (F : Frame), F.IsFinite → Formula.Kripke.ValidOnFrame F (Axioms.EFQ (.atom 0)) by simpa [Validates];
intro F _;
exact Formula.Kripke.ValidOnFrame.efq;
end FrameClass
end
end Kripke
end LO.Propositional
end