-
Notifications
You must be signed in to change notification settings - Fork 104
feat: define the category of LTSs #391
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
ayberkt
wants to merge
55
commits into
leanprover:main
Choose a base branch
from
ayberkt:main
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.
Open
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
99efff2
Write down the structure of the category of LTSs
ayberkt ec7b48e
Prove that these form a category
ayberkt 28840c2
Replace unused variable names with underscores
ayberkt 33d6785
Improve cosmetics
ayberkt 528040d
Add comment
ayberkt 691b443
Add Markdown sections
ayberkt 3a7993f
Improve naming
ayberkt dc216e3
Re-order variables
ayberkt 2d068c3
Put `LTSMorphism` under the `LTS` namespace
ayberkt 487c4f3
Fix the definition of the category of LTSs
ayberkt c942d95
Use the notion of `BundledLTS` everywhere
ayberkt dc6ba49
Tweak
ayberkt f8a6c32
Change name from `BundledLTS` to `LTSCat`
ayberkt 33aec96
Propagate name change
ayberkt d24bfbf
Unalign code
ayberkt 3b06814
Unalign code
ayberkt aca5ea3
Remove critique of Lean/CSLib naming conventions
ayberkt 687e74a
Use `where` with `def`
ayberkt 270fbbf
Unalign
ayberkt 1d026fe
Generalize universes
ayberkt d38dc1a
Chang name `toFun` to `stateMap`
ayberkt 7ccee71
Rename `fun_preserves_transitions` to `labelMap_tr`
ayberkt af1435b
Make universe explicit
ayberkt 3424e83
Avoid a separate `CategoryStruct` instance
ayberkt f5991cf
Improve cosmetics of type
ayberkt c5b6427
rename Category.lean -> LTSCat/Basic.lean
ayberkt ad87aaf
Define the category like Winskel and Nielsen do
ayberkt 4021718
Add reference to the handbook chapter
ayberkt 5598696
Update comment and add reference
ayberkt be34cae
Update comments
ayberkt 3cdb022
Merge remote-tracking branch 'upstream/main'
ayberkt b631a2a
Clean up
ayberkt c0e8fad
Fix the definition of `lift`
ayberkt 628147f
Propagate change to proofs
ayberkt 9aae6b4
Wrap up cleaning
ayberkt 2e516b0
lake exe mk_all --module
chenson2018 5d2a411
Improve cosmetics of type
ayberkt e229112
Eta reduce definition
ayberkt 66473c2
Simplify proof
ayberkt ade5fe5
Simplify proof
ayberkt 3269cf7
Simplify proof
ayberkt b8805fe
Use `unfold` instead of `simp`
ayberkt 7fb81a2
Implement @chenson2018’s suggestion
ayberkt 2c1d984
Fix preamble and use `Cslib` namespace
ayberkt 1deab70
Merge branch 'main' of github.com:ayberkt/cslib
ayberkt d1e143e
Add doc strings
ayberkt fcf30a1
Add doc strings
ayberkt 9a44e4c
Add copyright notice
ayberkt 338acc0
Mention employer
ayberkt bcd9a65
Merge remote-tracking branch 'origin/main' into ayberkt/main
chenson2018 c98f004
remove some change
chenson2018 1c1489a
use _root_.id consistently
chenson2018 b5814a1
nolint checkUnivs (not 100% sure, but it's not uncommon in category t…
chenson2018 621931d
Rename `lift` to `LTS.lift`
ayberkt bd289fb
Merge branch 'main' of github.com:ayberkt/cslib
ayberkt 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,99 @@ | ||
| /- | ||
| Copyright (c) 2026 Ayberk Tosun (Zeroth Research). All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Ayberk Tosun | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Mathlib.CategoryTheory.Category.Basic | ||
| public import Cslib.Foundations.Semantics.LTS.Basic | ||
| public import Mathlib.Control.Basic | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Cslib | ||
|
|
||
| variable {State Label : Type*} | ||
|
|
||
| /-! # Category of Labelled Transition Systems | ||
|
|
||
| This file contains the definition of the category of labelled transition systems | ||
| as defined in Winskel and Nielsen's handbook chapter [WinskelNielsen1995]. | ||
|
|
||
| ## References | ||
|
|
||
| * [N. Winskel and M. Nielsen, *Models for concurrency*][WinskelNielsen1995] | ||
| -/ | ||
|
|
||
| /-- | ||
| We first define what is denoted Tran* in [WinskelNielsen1995]: the extension of | ||
| a transition relation with idle transitions. | ||
| -/ | ||
| def LTS.lift (trans : State → Label → State → Prop) : State → (Option Label) → State → Prop := | ||
| fun s l s' => l.elim (s = s') (trans s · s') | ||
|
|
||
| /-! ## LTSs and LTS morphisms form a category -/ | ||
|
|
||
| /-- | ||
| The definition of labelled transition system (with the type of states and the | ||
| type of labels as part of the structure). | ||
| -/ | ||
| @[nolint checkUnivs] | ||
| structure LTSCat : Type (max u v + 1) where | ||
| /-- Type of states of an LTS -/ | ||
| State : Type u | ||
| /-- Type of labels of an LTS -/ | ||
| Label : Type v | ||
| /-- Transition relation of an LTS -/ | ||
| lts : LTS State Label | ||
|
|
||
| /-- | ||
| A morphism between two labelled transition systems consists of (1) a function on | ||
| states, (2) a partial function on labels, and a proof that (1) preserves each | ||
| transition along (2). | ||
| -/ | ||
| structure LTS.Morphism (lts₁ lts₂ : LTSCat) : Type where | ||
| /-- Mapping of states of `lts₁` to states of `lts₂` -/ | ||
| stateMap : lts₁.State → lts₂.State | ||
| /-- Mapping of labels of `lts₁` to labels of `lts₂` -/ | ||
| labelMap : lts₁.Label → Option lts₂.Label | ||
| /-- Stipulation that `stateMap` preserve transitions -/ | ||
| labelMap_tr (s s' : lts₁.State) (l : lts₁.Label) : | ||
| lts₁.lts.Tr s l s' → lift lts₂.lts.Tr (stateMap s) (labelMap l) (stateMap s') | ||
|
|
||
| /-- The identity LTS morphism. -/ | ||
| def LTS.Morphism.id (lts : LTSCat) : LTS.Morphism lts lts where | ||
| stateMap := _root_.id | ||
| labelMap := pure | ||
| labelMap_tr _ _ _ := _root_.id | ||
|
|
||
| /-- Composition of LTS morphisms. | ||
|
|
||
| We use Kleisli composition to define this. | ||
| -/ | ||
| def LTS.Morphism.comp {lts₁ lts₂ lts₃} (f : LTS.Morphism lts₁ lts₂) (g : LTS.Morphism lts₂ lts₃) : | ||
| LTS.Morphism lts₁ lts₃ where | ||
| stateMap := g.stateMap ∘ f.stateMap | ||
| labelMap := f.labelMap >=> g.labelMap | ||
| labelMap_tr s s' l h := by | ||
| obtain ⟨f, μ, p⟩ := f | ||
| obtain ⟨g, ν, q⟩ := g | ||
| change ((μ l).bind ν).elim (g (f s) = g (f s')) _ | ||
| cases hμ : μ l with grind [lift] | ||
|
|
||
| /-- Finally, we prove that these form a category. -/ | ||
| instance : CategoryTheory.Category LTSCat where | ||
| Hom := LTS.Morphism | ||
| id := LTS.Morphism.id | ||
| comp := LTS.Morphism.comp | ||
| comp_id _ := by | ||
| simp only [LTS.Morphism.comp, LTS.Morphism.id] | ||
| congr 1 | ||
| rw [fish_pure] | ||
| assoc _ _ _ := by | ||
| simp only [LTS.Morphism.comp] | ||
| congr 1 | ||
| rw [fish_assoc] | ||
|
|
||
| end Cslib | ||
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
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.