-
Notifications
You must be signed in to change notification settings - Fork 111
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
base: main
Are you sure you want to change the base?
Changes from 52 commits
99efff2
ec7b48e
28840c2
33d6785
528040d
691b443
3a7993f
dc216e3
2d068c3
487c4f3
c942d95
dc6ba49
f8a6c32
33aec96
d24bfbf
3b06814
aca5ea3
687e74a
270fbbf
1d026fe
d38dc1a
7ccee71
af1435b
3424e83
f5991cf
c5b6427
ad87aaf
4021718
5598696
be34cae
3cdb022
b631a2a
c0e8fad
628147f
9aae6b4
2e516b0
5d2a411
e229112
66473c2
ade5fe5
3269cf7
b8805fe
7fb81a2
2c1d984
1deab70
d1e143e
fcf30a1
9a44e4c
338acc0
bcd9a65
c98f004
1c1489a
b5814a1
621931d
bd289fb
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,100 @@ | ||
| /- | ||
| 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 | ||
|
|
||
| universe u v | ||
|
|
||
| variable {State : Type u} {Label : Type v} | ||
|
|
||
| /-! # 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 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). | ||
| -/ | ||
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.