-
Notifications
You must be signed in to change notification settings - Fork 95
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
base: main
Are you sure you want to change the base?
Changes from all commits
d0d6cde
3c97c1f
7d27758
ec6392b
5b433ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /- | ||
| Copyright (c) 2026 Fabrizio Montesi. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Fabrizio Montesi | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| @[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. -/ | ||
| def 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 |
| 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 |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,107 @@ | ||||||||||
| /- | ||||||||||
| 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. -/ | ||||||||||
| @[scoped grind =] | ||||||||||
| def Proposition.Equiv {State : Type u} {Label : Type v} (a b : Proposition Label) : Prop := | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get the impression that part of fixing the performance issues in LTS can start with being more strict about |
||||||||||
| ∀ lts : LTS State Label, a.denotation lts = b.denotation lts | ||||||||||
|
|
||||||||||
| /-- 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 | ||||||||||
|
Comment on lines
+64
to
+66
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's okay to write
Suggested change
because |
||||||||||
|
|
||||||||||
| /-- Bundled version of a judgement for `Satisfy`. -/ | ||||||||||
| structure Satisfies.Judgement (State : Type u) (Label : Type v) where | ||||||||||
| lts : LTS State Label | ||||||||||
| state : State | ||||||||||
| φ : 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 | ||||||||||
| lts : LTS State Label | ||||||||||
| state : State | ||||||||||
|
|
||||||||||
| /-- Fills a judgemental context with a proposition. -/ | ||||||||||
| def Satisfies.Context.fill (c : Satisfies.Context State Label) (φ : Proposition Label) : | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a reminder, you can use |
||||||||||
| Satisfies.Judgement State Label := { | ||||||||||
| 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 | ||||||||||
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.
We should be consistent within a single declaration of
Type*versus explicit universes. I'd write