Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cslib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public import Cslib.Logics.LinearLogic.CLL.PhaseSemantics.Basic
public import Cslib.Logics.Modal.Basic
public import Cslib.Logics.Modal.Cube
public import Cslib.Logics.Modal.Denotation
public import Cslib.Logics.Modal.LogicalEquivalence
public import Cslib.Logics.Propositional.Defs
public import Cslib.Logics.Propositional.NaturalDeduction.Basic
public import Cslib.MachineLearning.PACLearning.Defs
Expand Down
30 changes: 19 additions & 11 deletions Cslib/Logics/Modal/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ inductive Proposition (Atom : Type u) : Type u where
/-- Atomic proposition. -/
| atom (p : Atom)
/-- Negation. -/
| neg (φ : Proposition Atom)
| not (φ : Proposition Atom)
/-- Conjunction. -/
| and (φ₁ φ₂ : Proposition Atom)
/-- Possibility. -/
| diamond (φ : Proposition Atom)

@[inherit_doc] scoped prefix:40 "¬" => Proposition.neg
@[inherit_doc] scoped prefix:40 "¬" => Proposition.not
@[inherit_doc] scoped infix:36 " ∧ " => Proposition.and
@[inherit_doc] scoped prefix:40 "◇" => Proposition.diamond

Expand Down Expand Up @@ -76,7 +76,7 @@ the proposition `φ`. -/
@[scoped grind]
def Satisfies (m : Model World Atom) (w : World) : Proposition Atom → Prop
| .atom p => m.v w p
| .neg φ => ¬Satisfies m w φ
| .not φ => ¬Satisfies m w φ
| .and φ₁ φ₂ => Satisfies m w φ₁ ∧ Satisfies m w φ₂
| .diamond φ => ∃ w', m.r w w' ∧ Satisfies m w' φ

Expand All @@ -101,13 +101,13 @@ instance : HasInferenceSystem (Judgement World Atom) := ⟨Satisfies.Bundled⟩

open scoped InferenceSystem Proposition

@[scoped grind =]
@[scoped grind =_]
theorem derivation_def {m : Model World Atom} {w : World} {φ : Proposition Atom} :
⇓Modal[m,w ⊨ φ] = Satisfies m w φ := rfl
Satisfies m w φ = ⇓Modal[m,w ⊨ φ] := rfl

/-- A world satisfies a proposition iff it does not satisfy the negation of the proposition. -/
@[scoped grind =]
theorem neg_satisfies : ⇓Modal[m,w ⊨ ¬φ] ↔ ¬⇓Modal[m,w ⊨ φ] := by
theorem not_satisfies : ⇓Modal[m,w ⊨ ¬φ] ↔ ¬⇓Modal[m,w ⊨ φ] := by
induction φ generalizing w <;> grind

/-- Characterisation of the `∨` connective.
Expand All @@ -127,6 +127,16 @@ This result proves that the definition is correct.
theorem Satisfies.impl_iff_impl {m : Model World Atom} :
⇓Modal[m,w ⊨ φ₁ → φ₂] ↔ (⇓Modal[m,w ⊨ φ₁] → ⇓Modal[m,w ⊨ φ₂]) := by grind [Proposition.impl]

/-- Characterisation of the `↔` connective.

Bi-implication is defined in terms of the more primitive connectives given in `Proposition`.
This result proves that the definition is correct. -/
@[scoped grind =]
theorem Satisfies.iff_iff_iff {m : Model World Atom} :
⇓Modal[m,w ⊨ φ₁ ↔ φ₂] ↔ (⇓Modal[m,w ⊨ φ₁] ↔ ⇓Modal[m,w ⊨ φ₂]) := by
simp only [Proposition.iff]
grind [= derivation_def]

/-- Characterisation of the `□` modality.

Necessity is defined in terms of the more primitive connectives given in `Proposition`.
Expand All @@ -152,7 +162,7 @@ theorem satisfies_theory (h : Satisfies m w φ) : φ ∈ theory m w := by grind

/-- If two worlds are not theory equivalent, there exists a distinguishing proposition. -/
lemma not_theoryEq_satisfies (h : ¬TheoryEq m w₁ w₂) :
∃ φ, (⇓Modal[m,w₁ ⊨ φ] ∧ ¬⇓Modal[m,w₂ ⊨ φ]) := by grind [=_ neg_satisfies]
∃ φ, (⇓Modal[m,w₁ ⊨ φ] ∧ ¬⇓Modal[m,w₂ ⊨ φ]) := by grind [=_ not_satisfies]

/-- If two worlds are theory equivalent and the former satisfies a proposition, the latter does as
well. -/
Expand All @@ -167,10 +177,8 @@ theorem Satisfies.k : ⇓Modal[m,w ⊨ □(φ₁ → φ₂) → (□φ₁ →
set_option linter.tacticAnalysis.verifyGrindOnly false in
/-- The dual axiom, valid for all models. -/
theorem Satisfies.dual : ⇓Modal[m,w ⊨ ◇φ ↔ ¬□¬φ] := by
constructor
· grind
· grind only [→ satisfies_theory, usr Set.mem_setOf_eq, = impl_iff_impl, = derivation_def,
= neg_satisfies, Satisfies, = box_iff_forall, = Set.setOf_true]
grind only [Satisfies.iff_iff_iff.mpr, → satisfies_theory, usr Set.mem_setOf_eq, = impl_iff_impl,
=_ derivation_def, = not_satisfies, Satisfies, = box_iff_forall, = Set.setOf_true]

/-- The T axiom, valid for all reflexive models. -/
theorem Satisfies.t {m : Model World Atom} [instRefl : Std.Refl m.r] {w : World}
Expand Down
4 changes: 2 additions & 2 deletions Cslib/Logics/Modal/Denotation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open scoped Proposition InferenceSystem
def Proposition.denotation (m : Model World Atom) :
Proposition Atom → Set World
| .atom p => {w | m.v w p}
| .neg φ => (φ.denotation m)ᶜ
| .not φ => (φ.denotation m)ᶜ
| .and φ₁ φ₂ => φ₁.denotation m ∩ φ₂.denotation m
| .diamond φ => {w | ∃ w', m.r w w' ∧ w' ∈ φ.denotation m}

Expand All @@ -38,7 +38,7 @@ theorem satisfies_mem_denotation {m : Model World Atom} {φ : Proposition Atom}
/-- A world is in the denotation of a proposition iff it is not in the denotation of the negation
of the proposition. -/
@[scoped grind =]
theorem neg_denotation {m : Model World Atom} (φ : Proposition Atom) :
theorem not_denotation {m : Model World Atom} (φ : Proposition Atom) :
w ∉ (¬φ).denotation m ↔ w ∈ φ.denotation m := by
grind [_=_ satisfies_mem_denotation]

Expand Down
132 changes: 132 additions & 0 deletions Cslib/Logics/Modal/LogicalEquivalence.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/-
Copyright (c) 2026 Fabrizio Montesi. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fabrizio Montesi
-/

module

public import Cslib.Logics.Modal.Basic
public import Cslib.Foundations.Logic.LogicalEquivalence

/-! # Logical Equivalence in Modal Logic

This module defines logical equivalence for modal propositions.
The definitions are parametric on the class of models under consideration.

We also instantiate `LogicalEquivalence` for Modal Logic K, i.e., equivalence
for the class of all models.
-/

@[expose] public section

namespace Cslib.Logic.Modal

open scoped InferenceSystem Proposition Satisfies

/-- The modal propositions `φ₁` and `φ₂` are equivalent in the class of models `S`. -/
def Proposition.Equiv (S : Set (Model World Atom)) (φ₁ φ₂ : Proposition Atom)
: Prop :=
∀ m ∈ S, ∀ w : World, ⇓Modal[m,w ⊨ φ₁ ↔ φ₂]

@[inherit_doc]
scoped notation φ₁ " ≡[" S "] " φ₂ => Proposition.Equiv S φ₁ φ₂

@[inherit_doc]
scoped notation φ₁ " ≡ " φ₂ => Proposition.Equiv Set.univ φ₁ φ₂

@[scoped grind =]
theorem Proposition.equiv_def (S : Set (Model World Atom)) (φ₁ φ₂ : Proposition Atom) :
Comment thread
fmontesi marked this conversation as resolved.
(φ₁ ≡[S] φ₂) ↔
(∀ m ∈ S, ∀ w : World, ⇓Modal[m,w ⊨ φ₁ ↔ φ₂]) := by rfl

@[scoped grind =]
theorem Proposition.equiv_iff (S : Set (Model World Atom)) (φ₁ φ₂ : Proposition Atom) :
(φ₁ ≡[S] φ₂) ↔
(∀ m ∈ S, ∀ w : World, ⇓Modal[m,w ⊨ φ₁] ↔ ⇓Modal[m,w ⊨ φ₂]) := by
simp [Proposition.equiv_def, Satisfies.iff_iff_iff]

theorem Proposition.equiv_valid (S : Set (Model World Atom))
(φ₁ φ₂ : Proposition Atom) (h : φ₁ ≡[S] φ₂) :
(φ₁.valid S ↔ φ₂.valid S) := by
grind

/-- Propositional contexts. -/
inductive Proposition.Context (Atom : Type u) : Type u where
| hole
| not (c : Context Atom)
| andL (c : Context Atom) (φ : Proposition Atom)
| andR (φ : Proposition Atom) (c : Context Atom)
| diamond (c : Context Atom)

/-- Replaces a hole in a propositional context with a proposition. -/
@[scoped grind =]
def Proposition.Context.fill (c : Context Atom) (φ : Proposition Atom) :=
match c with
| hole => φ
| not c => .not (c.fill φ)
| andL c φ' => (c.fill φ).and φ'
| andR φ' c => φ'.and (c.fill φ)
| diamond c => .diamond (c.fill φ)

instance : HasContext (Proposition Atom) := ⟨Proposition.Context Atom, Proposition.Context.fill⟩

@[scoped grind =_]
lemma Proposition.Context.fill_def {Γ : HasContext.Context (Proposition Atom)} :
Γ.fill φ = Γ<[φ] := rfl

open scoped Proposition Proposition.Context

/-- Logical equivalence is an equivalence relation. -/
instance {World Atom} (S : Set (Model World Atom)) :
IsEquiv (Proposition Atom) (Proposition.Equiv S) := by
rw [← equivalence_iff_isEquiv]
grind [Equivalence]

/-- Logical equivalence is a congruence. -/
instance {World Atom} (S : Set (Model World Atom)) :
Congruence (Proposition Atom) (Proposition.Equiv S) where
elim ctx φ₁ φ₂ heqv m hₘ w := by
induction ctx generalizing w
case hole => grind
case not c ih | andL c ih | andR c ih =>
specialize ih w
grind
case diamond c ih =>
rw [Satisfies.iff_iff_iff]
apply Iff.intro
all_goals
rintro ⟨w', h⟩
specialize ih w'
grind

/-- Judgemental contexts. -/
structure Satisfies.Context (World Atom : Type*) where
/-- The model to consider. -/
m : Model World Atom
/-- The world to check propositions against. -/
w : World

/-- Fills a judgemental context with a proposition. -/
def Satisfies.Context.fill (c : Satisfies.Context World Atom) (φ : Proposition Atom) :
Judgement World Atom := Modal[c.m, c.w ⊨ φ]

instance judgementalContext :
HasHContext (Judgement World Atom) (Proposition Atom) :=
⟨Satisfies.Context World Atom, Satisfies.Context.fill⟩

@[scoped grind =_]
lemma Satisfies.Context.fill_def {c : Satisfies.Context World Atom} :
Modal[c.m,c.w ⊨ φ] = c<[φ] := rfl

open scoped Satisfies.Context

/-- Logical equivalence for Modal Logic K. That is, no assumptions on models are made. -/
Comment thread
fmontesi marked this conversation as resolved.
instance : LogicalEquivalence
(Proposition Atom) (Judgement World Atom) Satisfies.Bundled where
eqv := Proposition.Equiv Set.univ
eqvFillValid heqv c h := by
specialize heqv c.m
grind

end Cslib.Logic.Modal
Loading