-
Notifications
You must be signed in to change notification settings - Fork 96
feat: classes for inference systems and logical equivalence #398
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
Open
fmontesi
wants to merge
20
commits into
main
Choose a base branch
from
logic-classes
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.
+596
−65
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d0d6cde
feat: change context notation to <[]
fmontesi 3c97c1f
feat: contexts for CLL
fmontesi 7d27758
feat: class for logical equivalence. Almost there!
fmontesi ec6392b
forgot some files
fmontesi 5b433ab
logical equivalence for HML
fmontesi d276131
minor fixes
fmontesi 0b4a0cc
parr1
fmontesi 91e8f59
some cases of congruence for logical equivalence in CLL
fmontesi 869e910
done with congruence cases for logical equivalence in CLL
fmontesi 44d95ae
fix: type hint
fmontesi d5d4d16
remove unnecessary unit
fmontesi cc75b32
separate characterisation theorem for logical equivalence in HML
fmontesi 7ee600c
fix errors
fmontesi e882e71
line lengths
fmontesi b51c654
abbrev for HasContext
chenson2018 874396a
forgot docstring
chenson2018 8b2ae24
def should be a theorem
fmontesi 0c959a5
mk_all
fmontesi 8e3d6da
docstrings
fmontesi fdf4d5c
Merge branch 'main' into logic-classes
fmontesi 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
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) 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.Init | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Cslib.Logic | ||
|
|
||
| /-- | ||
| The notation typeclass for inference systems. | ||
| This enables the notation `⇓a`, where `a : α` is a derivable value. | ||
| -/ | ||
| class InferenceSystem (α : Type u) where | ||
| /-- | ||
| `⇓a` is a derivation of `a`, that is, a witness that `a` is derivable. | ||
| The meaning of this notation is type-dependent. | ||
| -/ | ||
| derivation (s : α) : Sort v | ||
|
|
||
| namespace InferenceSystem | ||
|
|
||
| @[inherit_doc] scoped notation "⇓" a:90 => InferenceSystem.derivation a | ||
|
|
||
| /-- Rewrites the conclusion of a proof into an equal one. -/ | ||
| @[scoped grind =] | ||
| def rwConclusion [InferenceSystem α] {Γ Δ : α} (h : Γ = Δ) (p : ⇓Γ) : ⇓Δ := h ▸ p | ||
|
|
||
| /-- `a` is derivable if it is the conclusion of some derivation. -/ | ||
| def Derivable [InferenceSystem α] (a : α) := Nonempty (⇓a) | ||
|
|
||
| /-- Shows derivability from a derivation. -/ | ||
| theorem Derivable.fromDerivation [InferenceSystem α] {a : α} (d : ⇓a) : Derivable a := | ||
| Nonempty.intro d | ||
|
|
||
| instance [InferenceSystem α] {a : α} : Coe (⇓a) (Derivable a) := ⟨Derivable.fromDerivation⟩ | ||
|
|
||
| /-- Extracts (noncomputably) a derivation from the fact that a conclusion is derivable. -/ | ||
| noncomputable def Derivable.toDerivation [InferenceSystem α] {a : α} (d : Derivable a) : ⇓a := | ||
| Classical.choice d | ||
|
|
||
| noncomputable instance [InferenceSystem α] {a : α} : Coe (Derivable a) (⇓a) := | ||
| ⟨Derivable.toDerivation⟩ | ||
|
|
||
| end InferenceSystem | ||
|
|
||
| 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,33 @@ | ||
| /- | ||
| 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.Foundations.Syntax.Context | ||
| public import Cslib.Foundations.Syntax.Congruence | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Cslib.Logic | ||
|
|
||
| /-- A logical equivalence for a given type of `Judgement`s is a congruence on propositions that | ||
| preserves validity of judgements under any judgemental context. -/ | ||
| class LogicalEquivalence | ||
| (Proposition : Type u) [HasContext Proposition] | ||
| (Judgement : Type v) [HasHContext Judgement Proposition] | ||
| (Valid : Judgement → Sort w) where | ||
| /-- The logical equivalence relation. -/ | ||
| eqv (a b : Proposition) : Prop | ||
| /-- Proof that `eqv` is a congruence. -/ | ||
| [congruence : Congruence Proposition eqv] | ||
| /-- Validity is preserved for any judgemental context. -/ | ||
| eqv_fill_valid (heqv : eqv a b) (c : HasHContext.Context Judgement Proposition) | ||
| (h : Valid (c<[a])) : Valid (c<[b]) | ||
|
|
||
| @[inherit_doc] | ||
| scoped infix:29 " ≡ " => LogicalEquivalence.eqv | ||
|
|
||
| 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
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
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
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,115 @@ | ||
| /- | ||
| 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.HML.Basic | ||
| public import Cslib.Foundations.Logic.LogicalEquivalence | ||
|
|
||
| @[expose] public section | ||
|
|
||
| /-! # Logical Equivalence in HML | ||
|
|
||
| This module defines logical equivalence for HML propositions and instantiates `LogicalEquivalence`. | ||
| -/ | ||
|
|
||
| namespace Cslib.Logic.HML | ||
|
|
||
| /-- Logical equivalence for HML propositions. -/ | ||
| def Proposition.Equiv {State : Type u} {Label : Type v} (a b : Proposition Label) : Prop := | ||
| ∀ lts : LTS State Label, a.denotation lts = b.denotation lts | ||
|
|
||
| @[scoped grind =] | ||
| theorem Proposition.equiv_def {State : Type u} {Label : Type v} (a b : Proposition Label) : | ||
| Equiv (State := State) a b ↔ | ||
| (∀ lts : LTS State Label, a.denotation lts = b.denotation lts) := by rfl | ||
|
|
||
| /-- Propositional contexts. -/ | ||
| inductive Proposition.Context (Label : Type u) : Type u where | ||
| | hole | ||
| | andL (c : Context Label) (φ : Proposition Label) | ||
| | andR (φ : Proposition Label) (c : Context Label) | ||
| | orL (c : Context Label) (φ : Proposition Label) | ||
| | orR (φ : Proposition Label) (c : Context Label) | ||
| | diamond (μ : Label) (c : Context Label) | ||
| | box (μ : Label) (c : Context Label) | ||
|
|
||
| /-- Replaces a hole in a propositional context with a proposition. -/ | ||
| @[scoped grind =] | ||
| def Proposition.Context.fill (c : Context Label) (φ : Proposition Label) := | ||
| match c with | ||
| | hole => φ | ||
| | andL c φ' => (c.fill φ).and φ' | ||
| | andR φ' c => φ'.and (c.fill φ) | ||
| | orL c φ' => (c.fill φ).or φ' | ||
| | orR φ' c => φ'.or (c.fill φ) | ||
| | diamond μ c => .diamond μ (c.fill φ) | ||
| | box μ c => .box μ (c.fill φ) | ||
|
|
||
| instance : HasContext (Proposition Label) := ⟨Proposition.Context Label, Proposition.Context.fill⟩ | ||
|
|
||
| open scoped Proposition Proposition.Context | ||
|
|
||
| instance : IsEquiv (Proposition Label) (Proposition.Equiv (State := State) (Label := Label)) where | ||
| refl := by grind | ||
| symm := by grind | ||
| trans := by grind | ||
|
|
||
| instance {State : Type u} {Label : Type v} : | ||
| Congruence (Proposition Label) (Proposition.Equiv (State := State) (Label := Label)) where | ||
| elim : | ||
| Covariant (Proposition.Context Label) (Proposition Label) (Proposition.Context.fill) | ||
| Proposition.Equiv := by | ||
| intro ctx a b hab lts | ||
| specialize hab lts | ||
| induction ctx | ||
| <;> simp only [Proposition.Context.fill, Proposition.denotation] | ||
| <;> grind | ||
chenson2018 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /-- Bundled version of a judgement for `Satisfy`. -/ | ||
| structure Satisfies.Judgement (State : Type u) (Label : Type v) where | ||
| /-- The state transition system to consider. -/ | ||
| lts : LTS State Label | ||
| /-- The state to check the proposition against. -/ | ||
| state : State | ||
| /-- The proposition to check. -/ | ||
| φ : Proposition Label | ||
|
|
||
| /-- `Satisfies` variant using bundled judgements. -/ | ||
| def Satisfies.Bundled (j : Satisfies.Judgement State Label) := Satisfies j.lts j.state j.φ | ||
|
|
||
| @[scoped grind =] | ||
| theorem Satisfies.bundled_char : Satisfies.Bundled j ↔ Satisfies j.lts j.state j.φ := by rfl | ||
|
|
||
| /-- Judgemental contexts. -/ | ||
| structure Satisfies.Context (State : Type u) (Label : Type v) where | ||
| /-- The state transition system to consider. -/ | ||
| lts : LTS State Label | ||
| /-- The state to check propositions against. -/ | ||
| state : State | ||
|
|
||
| /-- Fills a judgemental context with a proposition. -/ | ||
| def Satisfies.Context.fill (c : Satisfies.Context State Label) (φ : Proposition Label) : | ||
fmontesi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Satisfies.Judgement State Label where | ||
| lts := c.lts | ||
| state := c.state | ||
| φ := φ | ||
|
|
||
| instance judgementalContext : | ||
| HasHContext (Satisfies.Judgement State Label) (Proposition Label) := | ||
| ⟨Satisfies.Context State Label, Satisfies.Context.fill⟩ | ||
|
|
||
| instance : LogicalEquivalence | ||
| (Proposition Label) (Satisfies.Judgement State Label) (Satisfies.Bundled) where | ||
| eqv := Proposition.Equiv | ||
| eqv_fill_valid {a b : Proposition Label} (heqv : a.Equiv (State := State) b) | ||
| (c : HasHContext.Context (Satisfies.Judgement State Label) (Proposition Label)) | ||
| (h : Satisfies.Bundled c<[a]) : Satisfies.Bundled c<[b] := by | ||
| simp only [Satisfies.bundled_char, HasHContext.fill, Satisfies.Context.fill] | ||
| simp only [Satisfies.bundled_char, HasHContext.fill, Satisfies.Context.fill] at h | ||
| grind | ||
|
|
||
| end Cslib.Logic.HML | ||
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.
Uh oh!
There was an error while loading. Please reload this page.