Skip to content

feat: define the category of LTSs#391

Open
ayberkt wants to merge 36 commits intoleanprover:mainfrom
ayberkt:main
Open

feat: define the category of LTSs#391
ayberkt wants to merge 36 commits intoleanprover:mainfrom
ayberkt:main

Conversation

@ayberkt
Copy link

@ayberkt ayberkt commented Mar 2, 2026

This PR resolves #387.

@fmontesi
Copy link
Collaborator

fmontesi commented Mar 3, 2026

Not urgent, but please fix the title of the PR at some point to start with the required feat: prefix, or CI won't let us merge this.

@ayberkt ayberkt changed the title Define the category of LTSs feat: define the category of LTSs Mar 6, 2026
@ayberkt ayberkt requested review from chenson2018 and fmontesi March 6, 2026 18:47
Copy link
Collaborator

@chenson2018 chenson2018 left a comment

Choose a reason for hiding this comment

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

This looks much better! The theory now all lines up, there are some additional small style/technical issues I have pointed out below. Please also see the failures in CI now that it has made it to the linting step.

Comment on lines +32 to +33
def lift (trans : State → Label → State → Prop) :
State → (Option Label) → State → Prop :=
Copy link
Collaborator

Choose a reason for hiding this comment

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

This signature fits on one line now.

Comment on lines +68 to +82
def LTS.Morphism.comp {lts₁ lts₂ lts₃ : LTSCat} :
LTS.Morphism lts₁ lts₂ → LTS.Morphism lts₂ lts₃ → LTS.Morphism lts₁ lts₃ :=
fun ⟨f, μ, p⟩ ⟨g, ν, q⟩ =>
let r := by
intro s s' l h
have hp := p s s' l h
change ((μ l).bind ν).elim (g (f s) = g (f s')) _
cases hμ : μ l with
| none =>
rw [hμ] at hp
exact congrArg g hp
| some m =>
rw [hμ] at hp
exact q (f s) (f s') m hp
⟨g ∘ f, μ >=> ν, r⟩
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is more idiomatic/clear to use where to split this up. I would write:

Suggested change
def LTS.Morphism.comp {lts₁ lts₂ lts₃ : LTSCat} :
LTS.Morphism lts₁ lts₂ → LTS.Morphism lts₂ lts₃ → LTS.Morphism lts₁ lts₃ :=
fun ⟨f, μ, p⟩ ⟨g, ν, q⟩ =>
let r := by
intro s s' l h
have hp := p s s' l h
change ((μ l).bind ν).elim (g (f s) = g (f s')) _
cases hμ : μ l with
| none =>
rw [hμ] at hp
exact congrArg g hp
| some m =>
rw [hμ] at hp
exact q (f s) (f s') m hp
⟨g ∘ f, μ >=> ν, r⟩
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]

Comment on lines +86 to +88
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Easier to read if you eta reduce

Suggested change
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
Hom := LTS.Morphism
id := LTS.Morphism.id
comp := LTS.Morphism.comp

Comment on lines +89 to +93
id_comp := by
intro _ _ f
cases f
simp only [LTS.Morphism.comp, LTS.Morphism.id, Function.comp_id]
congr 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

This direction can be inferred

Suggested change
id_comp := by
intro _ _ f
cases f
simp only [LTS.Morphism.comp, LTS.Morphism.id, Function.comp_id]
congr 1


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

Choose a reason for hiding this comment

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

All modules should be in at least the Cslib namepsace, so this should move down below the @[expose] public section and become namespace Cslib. (As it is now below you are making LTS.Morphism etc. in a fresh namespace at the top level)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define the category of LTSs

4 participants