Skip to content

Commit f1ea11b

Browse files
committed
feat(LTS/LTSCat): labelled transition systems as coalgebras
Adds Cslib/Foundations/Semantics/LTS/LTSCat/Coalgebra.lean, which exhibits labelled transition systems with a fixed label set as coalgebras of the Set-endofunctor F_L X = Set (L × X) on Type u. LTS.Endo Label is the endofunctor F_L. LTS.Coalgebra Label is the category of F_L-coalgebras, defined as Endofunctor.Coalgebra (Endo Label), reusing Mathlib's existing notion. LTS.Coalgebra.toLTS extracts the LTS underlying a coalgebra, and LTS.Coalgebra.toLTSCat is the functor from Coalgebra Label to LTSCat sending a functional bisimulation to its underlying simulation. LTS.Coalgebra.toLTSCat is faithful. The theorem graph_isBisimulation shows that every coalgebra morphism is, as the graph of its underlying state map, a functional bisimulation between the underlying LTSs. The dual construction homOfGraphBisim lifts every functional bisimulation to a coalgebra morphism, and graphBisimEquiv packages both directions into a bijection between coalgebra morphisms V ⟶ W and state maps V.V → W.V whose graph is a functional bisimulation. This is not an equivalence of categories, as LTSCat is strictly larger (objects can carry different label sets, morphisms can rename labels, drop them to silent steps, and need only be one-way simulations); graphBisimEquiv exhibits LTS.Coalgebra Label as a non-full subcategory of LTSCat, namely the label-preserving functional bisimulations between same-label LTSs. Cslib/Foundations/Semantics/LTS/LTSCat/Basic.lean is made universe polymorphic for LTS.Morphism, LTS.Morphism.id, LTS.Morphism.comp, and the Category LTSCat instance, and @[ext] is added on LTS.Morphism. references.bib adds the Rutten2000 entry. Cslib.lean imports the new file.
1 parent d780a2a commit f1ea11b

4 files changed

Lines changed: 207 additions & 4 deletions

File tree

Cslib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public import Cslib.Foundations.Semantics.LTS.Divergence
7878
public import Cslib.Foundations.Semantics.LTS.Execution
7979
public import Cslib.Foundations.Semantics.LTS.HasTau
8080
public import Cslib.Foundations.Semantics.LTS.LTSCat.Basic
81+
public import Cslib.Foundations.Semantics.LTS.LTSCat.Coalgebra
8182
public import Cslib.Foundations.Semantics.LTS.Notation
8283
public import Cslib.Foundations.Semantics.LTS.OmegaExecution
8384
public import Cslib.Foundations.Semantics.LTS.Relation

Cslib/Foundations/Semantics/LTS/LTSCat/Basic.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ A morphism between two labelled transition systems consists of (1) a function on
5353
states, (2) a partial function on labels, and a proof that (1) preserves each
5454
transition along (2).
5555
-/
56-
structure LTS.Morphism (lts₁ lts₂ : LTSCat) : Type where
56+
@[ext]
57+
structure LTS.Morphism (lts₁ lts₂ : LTSCat.{u, v}) : Type (max u v) where
5758
/-- Mapping of states of `lts₁` to states of `lts₂` -/
5859
stateMap : lts₁.State → lts₂.State
5960
/-- Mapping of labels of `lts₁` to labels of `lts₂` -/
@@ -63,7 +64,7 @@ structure LTS.Morphism (lts₁ lts₂ : LTSCat) : Type where
6364
lts₁.lts.Tr s l s' → (withIdle lts₂.lts).Tr (stateMap s) (labelMap l) (stateMap s')
6465

6566
/-- The identity LTS morphism. -/
66-
def LTS.Morphism.id (lts : LTSCat) : LTS.Morphism lts lts where
67+
def LTS.Morphism.id (lts : LTSCat.{u, v}) : LTS.Morphism lts lts where
6768
stateMap := _root_.id
6869
labelMap := pure
6970
labelMap_tr _ _ _ := _root_.id
@@ -72,7 +73,8 @@ def LTS.Morphism.id (lts : LTSCat) : LTS.Morphism lts lts where
7273
7374
We use Kleisli composition to define this.
7475
-/
75-
def LTS.Morphism.comp {lts₁ lts₂ lts₃} (f : LTS.Morphism lts₁ lts₂) (g : LTS.Morphism lts₂ lts₃) :
76+
def LTS.Morphism.comp {lts₁ lts₂ lts₃ : LTSCat.{u, v}}
77+
(f : LTS.Morphism lts₁ lts₂) (g : LTS.Morphism lts₂ lts₃) :
7678
LTS.Morphism lts₁ lts₃ where
7779
stateMap := g.stateMap ∘ f.stateMap
7880
labelMap := f.labelMap >=> g.labelMap
@@ -84,7 +86,7 @@ def LTS.Morphism.comp {lts₁ lts₂ lts₃} (f : LTS.Morphism lts₁ lts₂) (g
8486
cases hμ : μ l with grind
8587

8688
/-- Finally, we prove that these form a category. -/
87-
instance : CategoryTheory.Category LTSCat where
89+
instance : CategoryTheory.Category LTSCat.{u, v} where
8890
Hom := LTS.Morphism
8991
id := LTS.Morphism.id
9092
comp := LTS.Morphism.comp
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/-
2+
Copyright (c) 2026 Tanner Duve (Logical Intelligence). All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Tanner Duve
5+
-/
6+
7+
module
8+
9+
public import Cslib.Foundations.Semantics.LTS.Bisimulation
10+
public import Cslib.Foundations.Semantics.LTS.LTSCat.Basic
11+
public import Mathlib.CategoryTheory.Endofunctor.Algebra
12+
public import Mathlib.CategoryTheory.Types.Basic
13+
public import Mathlib.CategoryTheory.Functor.FullyFaithful
14+
15+
/-!
16+
# Labelled transition systems as coalgebras
17+
18+
For a label set `L`, a labelled transition system on `X` is the same datum as a
19+
coalgebra `α : X → Set (L × X)` for the `Set`-endofunctor `F_L X = Set (L × X)`.
20+
This file defines `F_L` as an endofunctor of `Type u`, exhibits LTSs as
21+
coalgebras via Mathlib's `CategoryTheory.Endofunctor.Coalgebra`, and proves
22+
that Mathlib's coalgebra morphisms coincide with functional bisimulations on
23+
the underlying LTSs.
24+
25+
## Main definitions
26+
27+
- `LTS.Endo`: the endofunctor `F_L X = Set (L × X)` on `Type u`.
28+
- `LTS.Coalgebra.toLTSCat`: the forgetful functor from coalgebras of `F_L` to
29+
`LTSCat` that maps a functional bisimulation to its underlying simulation.
30+
31+
## Main results
32+
33+
- `LTS.Coalgebra.instFaithful`: `toLTSCat` is faithful.
34+
35+
## References
36+
37+
* [J. Rutten, *Universal coalgebra: a theory of systems*][Rutten2000]
38+
* [G. Winskel and M. Nielsen, *Models for concurrency*][WinskelNielsen1995]
39+
-/
40+
41+
@[expose] public section
42+
43+
namespace Cslib
44+
45+
universe u
46+
47+
open CategoryTheory TypeCat Endofunctor
48+
49+
namespace LTS
50+
51+
/-- Action on morphisms of the LTS endofunctor: image of a set under
52+
`(l, x) ↦ (l, f x)`. -/
53+
def Endo.mapFn (Label : Type u) {X Y : Type u} (f : X → Y) (S : Set (Label × X)) :
54+
Set (Label × Y) :=
55+
{p | ∃ x : X, (p.1, x) ∈ S ∧ f x = p.2}
56+
57+
namespace Endo
58+
59+
variable {Label : Type u} {X Y Z : Type u}
60+
61+
@[simp] lemma mem_mapFn (f : X → Y) (S : Set (Label × X)) (p : Label × Y) :
62+
p ∈ mapFn Label f S ↔ ∃ x : X, (p.1, x) ∈ S ∧ f x = p.2 := Iff.rfl
63+
64+
lemma mapFn_id : mapFn Label (_root_.id : X → X) = _root_.id := by
65+
funext S
66+
ext ⟨l, x⟩
67+
refine ⟨?_, fun hx => ⟨x, hx, rfl⟩⟩
68+
rintro ⟨_, hw, rfl⟩
69+
exact hw
70+
71+
lemma mapFn_comp (f : X → Y) (g : Y → Z) :
72+
mapFn Label (g ∘ f) = mapFn Label g ∘ mapFn Label f := by
73+
funext S
74+
ext ⟨l, z⟩
75+
refine ⟨?_, ?_⟩
76+
· rintro ⟨x, hx, rfl⟩
77+
exact ⟨f x, ⟨x, hx, rfl⟩, rfl⟩
78+
· rintro ⟨y, ⟨x, hx, rfl⟩, rfl⟩
79+
exact ⟨x, hx, rfl⟩
80+
81+
end Endo
82+
83+
/-- The `Set`-endofunctor `F_L X = Set (L × X)` on `Type u`. -/
84+
@[reducible] def Endo (Label : Type u) : Type u ⥤ Type u where
85+
obj X := Set (Label × X)
86+
map {_ _} f := ofHom (Endo.mapFn Label f)
87+
map_id _ := by aesop
88+
map_comp f g := by aesop
89+
90+
/-- The category of LTS-coalgebras for a fixed label set, as Mathlib's
91+
`Endofunctor.Coalgebra` applied to `Endo Label`. Morphisms are the strict
92+
commuting-square coalgebra morphisms, which are precisely the functional
93+
bisimulations on the underlying LTSs (see `Coalgebra.graph_isBisimulation` and
94+
`Coalgebra.homOfGraphBisim`). -/
95+
abbrev Coalgebra (Label : Type u) : Type (u + 1) := Endofunctor.Coalgebra (Endo Label)
96+
97+
namespace Coalgebra
98+
99+
variable {Label : Type u}
100+
101+
/-- The LTS underlying a coalgebra of `Endo Label`. -/
102+
abbrev toLTS (V : Coalgebra Label) : LTS V.V Label where
103+
Tr s l s' := (l, s') ∈ (V.str : V.V → _) s
104+
105+
@[simp] lemma toLTS_Tr (V : Coalgebra Label) (s : V.V) (l : Label) (s' : V.V) :
106+
(toLTS V).Tr s l s' ↔ (l, s') ∈ (V.str : V.V → _) s := Iff.rfl
107+
108+
variable (Label) in
109+
/-- The forgetful functor `Coalgebra Label ⥤ LTSCat` mapping each functional
110+
bisimulation to its underlying simulation. -/
111+
def toLTSCat : Coalgebra Label ⥤ LTSCat.{u, u} where
112+
obj V := ({ State := V.V, Label := Label, lts := toLTS V } : LTSCat.{u, u})
113+
map {V W} f :=
114+
{ stateMap := (f.f : V.V → W.V)
115+
labelMap := pure
116+
labelMap_tr := by
117+
intro s s' l h
118+
have hcomm := ConcreteCategory.congr_hom f.h s
119+
simp_all only [types_comp_apply, Endo, ofHom_apply, withIdle, toLTS]
120+
rw [← hcomm]
121+
exact ⟨s', h, rfl⟩ }
122+
map_id _ := rfl
123+
map_comp _ _ := by
124+
apply Morphism.ext
125+
· rfl
126+
· exact (fish_pure pure).symm
127+
128+
/-- `toLTSCat` is faithful: a functional bisimulation is determined by its
129+
underlying state map. -/
130+
instance : (toLTSCat Label).Faithful where
131+
map_injective {_ _} _ _ h := by
132+
apply Endofunctor.Coalgebra.Hom.ext
133+
apply Hom.ext
134+
apply Fun.ext
135+
funext x
136+
exact congrFun (congrArg Morphism.stateMap h) x
137+
138+
/-- Mathlib's coalgebra morphisms are precisely the functional bisimulations of
139+
the underlying LTSs. Forward direction: every coalgebra morphism, viewed as the
140+
graph of its underlying state map, is an `LTS.IsBisimulation`. -/
141+
theorem graph_isBisimulation {V W : Coalgebra Label} (f : V ⟶ W) :
142+
LTS.IsBisimulation (toLTS V) (toLTS W) (fun s t => (f.f : V.V → W.V) s = t) := by
143+
intro s t hst l
144+
have hcomm := ConcreteCategory.congr_hom f.h s
145+
simp_all only [types_comp_apply, Endo, ofHom_apply]
146+
constructor
147+
· intro s' h
148+
exact ⟨(f.f : V.V → W.V) s', hcomm ▸ ⟨s', h, rfl⟩, rfl⟩
149+
· intro t' h
150+
obtain ⟨s', hs', rfl⟩ := hcomm ▸ h
151+
exact ⟨s', hs', rfl⟩
152+
153+
/-- Backward direction: any function whose graph is an LTS bisimulation is the
154+
underlying state map of a (unique) coalgebra morphism. -/
155+
def homOfGraphBisim {V W : Coalgebra Label} (f : V.V → W.V)
156+
(h : LTS.IsBisimulation (toLTS V) (toLTS W) (fun s t => f s = t)) : V ⟶ W where
157+
f := ofHom f
158+
h := by
159+
apply Hom.ext
160+
apply Fun.ext
161+
funext s
162+
ext ⟨l, t'⟩
163+
simp only [Endo]
164+
constructor
165+
· rintro ⟨s', hs', rfl⟩
166+
obtain ⟨_, ht₂, rfl⟩ := (h rfl l).1 _ hs'
167+
exact ht₂
168+
· intro ht'
169+
obtain ⟨s', hs', rfl⟩ := (h rfl l).2 _ ht'
170+
exact ⟨s', hs', rfl⟩
171+
172+
/-- Coalgebra morphisms `V ⟶ W` are in bijection with the state maps `V.V → W.V` whose graph is
173+
a functional bisimulation between the underlying LTSs. -/
174+
def graphBisimEquiv {V W : Coalgebra Label} :
175+
(V ⟶ W) ≃
176+
{ f : V.V → W.V //
177+
LTS.IsBisimulation (toLTS V) (toLTS W) (fun s t => f s = t) } where
178+
toFun φ := ⟨φ.f, graph_isBisimulation φ⟩
179+
invFun p := homOfGraphBisim p.1 p.2
180+
left_inv φ := by
181+
apply Endofunctor.Coalgebra.Hom.ext
182+
rfl
183+
right_inv _ := rfl
184+
185+
end Coalgebra
186+
187+
end LTS
188+
189+
end Cslib

references.bib

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@ @book{KearnsVazirani1994
358358
address = {Cambridge, MA, USA}
359359
}
360360

361+
@article{Rutten2000,
362+
author = {Rutten, J. J. M. M.},
363+
title = {Universal coalgebra: a theory of systems},
364+
journal = {Theoretical Computer Science},
365+
volume = {249},
366+
number = {1},
367+
pages = {3--80},
368+
year = {2000},
369+
doi = {10.1016/S0304-3975(00)00056-6}
370+
}
371+
361372
@incollection{WinskelNielsen1995,
362373
author = {Winskel, Glynn and Nielsen, Mogens},
363374
isbn = {9780198537809},

0 commit comments

Comments
 (0)