-
Notifications
You must be signed in to change notification settings - Fork 143
feat(Foundations/Logic): Notation typeclasses and models #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
thomaskwaring
wants to merge
4
commits into
leanprover:main
Choose a base branch
from
thomaskwaring:models
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /- | ||
| Copyright (c) 2025 Thomas Waring. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Thomas Waring | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Init | ||
| public import Mathlib.Order.Notation | ||
|
|
||
| /-! # Notation classes for logical connectives -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Cslib.Logic | ||
|
|
||
| /-- Class for implication. -/ | ||
| class HasImpl (α : Type*) where | ||
| /-- Implication. -/ | ||
| impl : α → α → α | ||
|
|
||
| @[inherit_doc] scoped infixr:25 " → " => HasImpl.impl | ||
|
|
||
| /-- Class for conjunction. -/ | ||
| class HasAnd (α : Type*) where | ||
| /-- Conjunction. -/ | ||
| and : α → α → α | ||
|
|
||
| @[inherit_doc] scoped infixr:35 " ∧ " => HasAnd.and | ||
|
|
||
| /-- Class for disjunction. -/ | ||
| class HasOr (α : Type*) where | ||
| /-- Disjunction. -/ | ||
| or : α → α → α | ||
|
|
||
| @[inherit_doc] scoped infixr:30 " ∨ " => HasOr.or | ||
|
|
||
| /-- Class for negation. -/ | ||
| class HasNot (α : Type*) where | ||
| /-- Negation. -/ | ||
| not : α → α | ||
|
|
||
| @[inherit_doc] scoped notation:max "¬" a:40 => HasNot.not a | ||
|
|
||
| /-- Instantiate negation for types with implication and a bottom element. NB: this has a lower | ||
| instance priority to account for proposition types with inbuilt negation. Possibly it should be | ||
| a `def` instead? -/ | ||
| instance (priority := 900) instNotImplBot (α : Type*) [HasImpl α] [Bot α] : HasNot α where | ||
| not a := a → ⊥ | ||
|
|
||
| end Cslib.Logic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| /- | ||
| Copyright (c) 2025 Thomas Waring. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Thomas Waring | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Foundations.Logic.Connectives | ||
| public import Cslib.Foundations.Logic.InferenceSystem | ||
| public import Cslib.Logics.Modal.Basic | ||
| public import Cslib.Logics.Propositional.NaturalDeduction.Basic | ||
|
|
||
| /-! # Semantics for logical systems -/ | ||
|
|
||
| public section | ||
|
|
||
| namespace Cslib.Logic | ||
|
|
||
| /-- Objects of type `β` carry a forcing relation with the proposition type `α`. -/ | ||
| class Models (α : outParam Type*) (β : Type*) where | ||
| /-- `Satisfies b a` has the intended semantics "`a` is valid in the model `b`". -/ | ||
| Satisfies : β → α → Prop | ||
|
|
||
| scoped notation "⊨[" b "] " a => Models.Satisfies b a | ||
|
|
||
| /-- Objects of type `β` carry a forcing relation worlds of type `γ` and the proposition type `α`. -/ | ||
| class ParamModels (α : outParam Type*) (β : Type*) where | ||
| Param : β → Type* | ||
| /-- Forcing relation associated to each parameter. -/ | ||
| SatisfiesAt (b : β) : (Param b) → α → Prop | ||
|
|
||
| scoped notation w " ⊨[" b "] " a => ParamModels.SatisfiesAt b w a | ||
|
|
||
| instance ParamModels.toModels {α β : Type*} [ParamModels α β] : Models α β where | ||
| Satisfies M A := ∀ w : ParamModels.Param M, w ⊨[M] A | ||
|
|
||
| /-- Bundled interpretation function. -/ | ||
| class HasInterp (α : outParam Type*) (β : Type*) where | ||
| /-- Type carrying interpretation. -/ | ||
| Ground : β → Type* | ||
| /-- Interpret a proposition in a model. -/ | ||
| interp : (b : β) → α → Ground b | ||
|
|
||
| /-- An `InterpModel` consists of an interpretation function, and a set specifying which | ||
| interpretations are considered valid. -/ | ||
| class InterpModels (α : outParam (Type*)) (β : Type*) extends HasInterp α β where | ||
| /-- The set of valid interpretations. -/ | ||
| filter (b : β) : Set (Ground b) | ||
|
|
||
| instance InterpModels.instModels {α β : Type*} [InterpModels α β] : Models α β where | ||
| Satisfies b a := HasInterp.interp b a ∈ filter b | ||
|
|
||
| namespace HasInterp | ||
|
|
||
| class AlgebraicAnd (α β : Type*) [HasInterp α β] [HasAnd α] [∀ b : β, Min (Ground b)] where | ||
| interp_and_eq (M : β) (x y : α) : interp M (x ∧ y) = interp M x ⊓ interp M y | ||
|
|
||
| class AlgebraicOr (α β : Type*) [HasInterp α β] [HasOr α] [∀ b : β, Max (Ground b)] where | ||
| interp_or_eq (M : β) (x y : α) : interp M (x ∨ y) = interp M x ⊔ interp M y | ||
|
|
||
| class AlgebraicImpl (α β : Type*) [HasInterp α β] [HasImpl α] [∀ b : β, HImp (Ground b)] where | ||
| interp_impl_eq (M : β) (x y : α) : interp M (x → y) = interp M x ⇨ interp M y | ||
|
|
||
| class AlgebraicNot (α β : Type*) [HasInterp α β] [HasNot α] [∀ b : β, Compl (Ground b)] where | ||
| interp_not_eq (M : β) (x y : α) : interp M (¬ x) = (interp M x)ᶜ | ||
|
|
||
| end HasInterp | ||
|
|
||
| open Models ParamModels InferenceSystem | ||
|
|
||
| variable {α β T} [Models α β] [InferenceSystem T α] | ||
|
|
||
| def SoundFor (α β T) [Models α β] [InferenceSystem T α] (S : Set β) : Prop := | ||
| ∀ (A : α), DerivableIn T A → ∀ M ∈ S, ⊨[M] A | ||
|
|
||
| lemma SoundFor.subset {S S' : Set β} (hS : S ⊆ S') : SoundFor α β T S' → SoundFor α β T S := | ||
| fun h A hA M hM => h A hA M (hS hM) | ||
|
|
||
| def CompleteFor (α β T : Type*) [Models α β] [InferenceSystem T α] (S : Set β) : Prop := | ||
| ∀ A : α, (∀ M ∈ S, ⊨[M] A) → DerivableIn T A | ||
|
|
||
| lemma CompleteFor.supset {S S' : Set β} (hS : S ⊆ S') : | ||
| CompleteFor α β T S → CompleteFor α β T S' := fun h A hA => h A (fun M hM => hA M (hS hM)) | ||
|
|
||
| def IsCompleteModel (α β T) [Models α β] [InferenceSystem T α] (M : β) : Prop := | ||
| ∀ (A : α), (⊨[M] A) → DerivableIn T A | ||
|
|
||
| def ParamModels.theory {α β : Type*} [ParamModels α β] {M : β} (w : Param M) : Set α := | ||
| {A : α | w ⊨[M] A} | ||
|
|
||
| def Models.logic {α β : Type*} [Models α β] (S : Set β) : Set α := {A | ∀ b ∈ S, ⊨[b] A} | ||
|
|
||
| namespace Modal | ||
|
|
||
| structure BundledModel (Atom : Type*) where | ||
| World : Type* | ||
| model : Model World Atom | ||
|
|
||
| def Model.toBundledModel {World Atom : Type*} (M : Model World Atom) : BundledModel Atom := | ||
| {World := World, model := M} | ||
|
|
||
| instance {Atom : Type*} : ParamModels (Proposition Atom) (BundledModel Atom) where | ||
| Param M := M.World | ||
| SatisfiesAt M w A := Satisfies M.model w A | ||
|
|
||
| example {World Atom : Type*} (S : Set (Model World Atom)) : | ||
| logic S = Models.logic (Model.toBundledModel '' S) := by | ||
| simp [Models.logic] | ||
| rfl | ||
|
|
||
| example {World Atom : Type*} (m : Model World Atom) (w : World) : | ||
| theory m w = ParamModels.theory (M := m.toBundledModel) w := by | ||
| simp [theory, ParamModels.theory] | ||
| rfl | ||
|
|
||
| end Modal | ||
|
|
||
| namespace PL | ||
|
|
||
| variable {Atom : Type*} | ||
|
|
||
| instance : HasAnd (Proposition Atom) := ⟨Proposition.and⟩ | ||
| instance : HasOr (Proposition Atom) := ⟨Proposition.or⟩ | ||
| instance : HasImpl (Proposition Atom) := ⟨Proposition.impl⟩ | ||
| instance [Bot Atom] : HasNot (Proposition Atom) := ⟨Proposition.neg⟩ | ||
|
|
||
| structure HeytingModel (Atom : Type*) where | ||
| H : Type* | ||
| [inst : GeneralizedHeytingAlgebra H] | ||
| v : Atom → H | ||
|
|
||
| instance (M : HeytingModel Atom) : GeneralizedHeytingAlgebra M.H := M.inst | ||
|
|
||
| def HeytingModel.interp (M : HeytingModel Atom) : Proposition Atom → M.H | ||
| | Proposition.atom x => M.v x | ||
| | Proposition.and A B => M.interp A ⊓ M.interp B | ||
| | Proposition.or A B => M.interp A ⊔ M.interp B | ||
| | Proposition.impl A B => M.interp A ⇨ M.interp B | ||
|
|
||
| instance : InterpModels (Proposition Atom) (HeytingModel Atom) where | ||
| Ground M := M.H | ||
| interp := HeytingModel.interp | ||
| filter _ := {⊤} | ||
|
|
||
| instance (M : HeytingModel Atom) : GeneralizedHeytingAlgebra (HasInterp.Ground M) := M.inst | ||
|
|
||
| instance : HasInterp.AlgebraicAnd (Proposition Atom) (HeytingModel Atom) where | ||
| interp_and_eq _ _ _ := rfl | ||
|
|
||
| instance : HasInterp.AlgebraicOr (Proposition Atom) (HeytingModel Atom) where | ||
| interp_or_eq _ _ _ := rfl | ||
|
|
||
| instance : HasInterp.AlgebraicImpl (Proposition Atom) (HeytingModel Atom) where | ||
| interp_impl_eq _ _ _ := rfl | ||
|
|
||
| theorem HeytingModel.sound [DecidableEq Atom] {T : Theory Atom} : | ||
| SoundFor (Proposition Atom) (HeytingModel Atom) T {M | ∀ A ∈ T, interp M A = ⊤} := | ||
| sorry -- i have this in a branch | ||
|
|
||
| def Theory.lindenbaum [DecidableEq Atom] (T : Theory Atom) : HeytingModel Atom := | ||
| sorry -- usual Heyting-algebra of propositions modulo equivalence | ||
|
|
||
| theorem Theory.lindenbaum_complete [DecidableEq Atom] {T : Theory Atom} : | ||
| IsCompleteModel (Proposition Atom) (HeytingModel Atom) T T.lindenbaum := | ||
| sorry -- also in a branch | ||
|
|
||
| abbrev Valuation (Atom : Type*) := Atom → Prop | ||
|
|
||
| def Valuation.interp (v : Valuation Atom) : Proposition Atom → Prop | ||
| | .atom x => v x | ||
| | .and A B => v.interp A ∧ v.interp B | ||
| | .or A B => v.interp A ∨ v.interp B | ||
| | .impl A B => v.interp A → v.interp B | ||
|
|
||
| instance : InterpModels (Proposition Atom) (Valuation Atom) where | ||
| Ground _ := Prop | ||
| interp v A := v.interp A | ||
| filter _ := {True} | ||
|
|
||
| end PL | ||
|
|
||
| end Cslib.Logic | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still find this notation unintuitive:
wdepends onband yet it appears to the left ofb.For that matter, why does the model
bappear in a bracket to the right of the turnstile⊨in this and the notation forModels/Satisfies? It seems to me standard for the model to appear to the left of the⊨.