Skip to content
84 changes: 84 additions & 0 deletions Cslib/Foundations/Semantics/LTS/Category.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/-
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ayberk Tosun
-/

module

public import Cslib.Foundations.Semantics.LTS.Basic
public import Mathlib.CategoryTheory.Category.Basic
open Cslib

universe u v

@[expose] public section

variable {State Label : Type}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see below, you don't need these lts variables that much? Consider removing them maybe?

/-!
# Category of Labelled Transition Systems
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add a reference.

-/

/-! ## LTSs and LTS morphisms form a category -/

/-- The notion of labelled transition system -/
structure BundledLTS where
State : Type u
Label : Type v
lts : LTS State Label

/- Remark: I do not like the name 'bundled LTS'; and LTS is already the bundled notion. The name
`LTS` for the transition relation on a fixed set of states and labels is what is confusing here.
I propose to change that to `LTS-Structure` and call the above `LTS`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope not. LTS is used in many, many places already. We should keep its short name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest assured we will not change this name. As I say above, in alignment with Mathlib it should be LTSCat. (And will not affect any of your existing work)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also

LTS is already the bundled notion

makes me think we have a mismatch in terminology that might be a Lean colloquialism. Could you clarify what you mean by this @ayberkt?

-/

/-! ## Definition of LTS morphism -/

/--
A morphism between two labelled transition systems consists of a function on
states, a function on labels, and a proof that transitions are preserved.
-/
structure LTS.Morphism (lts₁ lts₂ : BundledLTS) : Type where
toFun : lts₁.State → lts₂.State
labelMap : lts₁.Label → lts₂.Label
fun_preserves_transitions : (s s' : lts₁.State)
→ (l : lts₁.Label)
→ lts₁.lts.Tr s l s'
→ lts₂.lts.Tr (toFun s) (labelMap l) (toFun s')

/-- The identity LTS morphism. -/
def LTS.Morphism.id (lts : BundledLTS) : LTS.Morphism lts lts :=
{ toFun := _root_.id
, labelMap := _root_.id
, fun_preserves_transitions := fun _ _ _ h => h
}

/-- Composition of LTS morphisms. -/
def LTS.Morphism.comp {lts₁ lts₂ lts₃ : BundledLTS} :
LTS.Morphism lts₁ lts₂ → LTS.Morphism lts₂ lts₃ → LTS.Morphism lts₁ lts₃ :=
fun ⟨f, μ, p⟩ ⟨g, ν, q⟩ =>
let r := by intros _ _ _ h
apply q
apply p
exact h
⟨g ∘ f, ν ∘ μ, r⟩

/-- `LTS.Morphism` provides a category structure on bundled LTSs. -/
instance : CategoryTheory.CategoryStruct BundledLTS where
Hom lts₁ lts₂ := LTS.Morphism lts₁ lts₂
id lts := LTS.Morphism.id lts
comp {lts₁} {lts₂} {lts₃} f g := @LTS.Morphism.comp lts₁ lts₂ lts₃ f g

/-- Proof that the above structure actually forms a category. -/
instance : CategoryTheory.Category BundledLTS where
id_comp := by intro _ _ f
cases f
rfl
comp_id := by intro _ _ f
cases f
rfl
assoc := by intro _ _ _ _ f g h
cases f
cases g
cases h
rfl