Skip to content

Conversation

fmontesi
Copy link
Collaborator

@fmontesi fmontesi commented Oct 6, 2025

No description provided.

@fmontesi fmontesi requested a review from chenson2018 as a code owner October 6, 2025 10:44
import Cslib.Foundations.Semantics.Lts.Bisimulation
import Cslib.Foundations.Semantics.Lts.TraceEq
import Cslib.Foundations.Semantics.LTS.Basic
import Cslib.Foundations.Semantics.LTS.Bisimulation
Copy link

Choose a reason for hiding this comment

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

[imports (comment with "bot fix style" to have the bot commit all style suggestions)] reported by reviewdog 🐶

Suggested change
import Cslib.Foundations.Semantics.LTS.Bisimulation
import Cslib.Computability.Automata.DA
import Cslib.Computability.Automata.DFA
import Cslib.Computability.Automata.DFAToNFA
import Cslib.Computability.Automata.EpsilonNFA
import Cslib.Computability.Automata.EpsilonNFAToNFA
import Cslib.Computability.Automata.NA
import Cslib.Computability.Automata.NFA
import Cslib.Computability.Automata.NFAToDFA
import Cslib.Foundations.Control.Monad.Free
import Cslib.Foundations.Control.Monad.Free.Effects
import Cslib.Foundations.Control.Monad.Free.Fold
import Cslib.Foundations.Data.FinFun
import Cslib.Foundations.Data.HasFresh
import Cslib.Foundations.Data.Relation
import Cslib.Foundations.Semantics.LTS.Bisimulation

import Cslib.Foundations.Semantics.LTS.Basic
import Cslib.Foundations.Semantics.LTS.Bisimulation
import Cslib.Foundations.Semantics.LTS.TraceEq
import Cslib.Foundations.Data.Relation
Copy link

Choose a reason for hiding this comment

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

[imports (comment with "bot fix style" to have the bot commit all style suggestions)] reported by reviewdog 🐶

Suggested change
import Cslib.Foundations.Data.Relation
import Cslib.Foundations.Semantics.LTS.Simulation
import Cslib.Foundations.Data.Relation

Comment on lines 5 to 6
import Cslib.Languages.CombinatoryLogic.Defs
import Cslib.Languages.CombinatoryLogic.Basic
Copy link

Choose a reason for hiding this comment

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

[imports (comment with "bot fix style" to have the bot commit all style suggestions)] reported by reviewdog 🐶

Suggested change
import Cslib.Languages.CombinatoryLogic.Defs
import Cslib.Languages.CombinatoryLogic.Basic
import Cslib.Foundations.Semantics.ReductionSystem.Basic
import Cslib.Foundations.Syntax.HasAlphaEquiv
import Cslib.Foundations.Syntax.HasSubstitution
import Cslib.Foundations.Syntax.HasWellFormed
import Cslib.Languages.CCS.Basic
import Cslib.Languages.CCS.BehaviouralTheory
import Cslib.Languages.CCS.Semantics

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.

I think we should settle early on a style preference for explicit and scoped grind.

I made several grind suggestions, but I am still bothered by a few places where grind fails unexpectedly, as noted in your TODO. As I note in a comment, I think at least some of it it is because of failure to how structures extend each other.

A Deterministic Automaton (DA) is an automaton defined by a transition function.
-/
structure DA (State : Type _) (Symbol : Type _) where
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
structure DA (State : Type _) (Symbol : Type _) where
structure DA (State Symbol : Type*) where

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I still don't get what the advantage of Type* is given that Type _ (even by listing the identifiers before it) does the same thing and seems native?

Copy link
Collaborator

Choose a reason for hiding this comment

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

My opinion is that it is more readable and as a side benefit more compact. As is, you have to twice interpret an annotation and _, whereas with Type* you get one piece of syntax that says "all these types are in arbitrary universes". As this is a very stable piece of Mathlib syntax, I do not find an advantage in the native spelling.

Not a deal breaker for me, this can be considered personal preference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see what you mean, although I still find (State : Type _) (Symbol : Type _) to be less ambiguous. I'll mull over it.

/-- A Deterministic Finite Automaton (DFA) consists of a labelled transition function
`tr` over finite sets of states and labels (called symbols), a starting state `start` and a finite
set of accepting states `accept`. -/
structure DFA (State : Type _) (Symbol : Type _) extends DA State Symbol where
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
structure DFA (State : Type _) (Symbol : Type _) extends DA State Symbol where
structure DFA (State Symbol : Type*) extends DA State Symbol where

@fmontesi
Copy link
Collaborator Author

fmontesi commented Oct 6, 2025

I think we should settle early on a style preference for explicit and scoped grind.

I made several grind suggestions, but I am still bothered by a few places where grind fails unexpectedly, as noted in your TODO. As I note in a comment, I think at least some of it it is because of failure to how structures extend each other.

Yeah, I've been putting grind annotations in many places because we haven't got a convention yet. Let's settle on explicit and scoped then, I've been using that in another project and seems to work well.

fmontesi and others added 10 commits October 6, 2025 20:26
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
@fmontesi
Copy link
Collaborator Author

fmontesi commented Oct 6, 2025

Thanks @chenson2018, I think I'm done with all the changes that make immediate sense. :-)

Comment on lines 16 to 17
/-- The set of accepting states of the automaton. -/
accept : Set State
Copy link

Choose a reason for hiding this comment

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

Could you move the accept condition to DFA? I want to define (for example) deterministic Muller automata by extending DA, but such automata have an acceptance condition of type: accept : Set (Set State).

structure NA (State : Type _) (Symbol : Type _) extends LTS State Symbol where
/-- The set of initial states of the automaton. -/
start : Set State
/-- The set of accepting states of the automaton. -/
Copy link

Choose a reason for hiding this comment

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

Could you move the accept condition to NFA and \epsilonNFA? Automata on infinite words have acceptance conditions of types like Set (Set State) (Muller condition) and Set (Set State × Set State)) (Rabin condition).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!


/-- Converts an `NFA` into a `DFA` using the subset construction. -/
@[grind]
def toDFA (nfa : NFA State Symbol) : DFA (Set State) Symbol := {
Copy link

Choose a reason for hiding this comment

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

Perhaps you can separate out the start and tr components to a NAtoDA.lean, so that other extensions of NA and DA for omega-automata can also use the results? Note that all the heavy-lifting in the proof of the subset construction involve only the start and tr components anyway.

Internally, ε (`Option.none`) is treated as the `τ` label of the underlying transition system,
allowing for reusing the definitions and results on saturated transitions of `LTS` to deal with
ε-closure. -/
structure εNFA (State : Type _) (Symbol : Type _) extends NA State (Option Symbol) where
Copy link

Choose a reason for hiding this comment

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

Instead of extending NA to obtain εNFA, it may be cleaner to have an εNA (namely, an NA that supports ε-transitions) and extend εNA to obtain εNFA. My comments about separating out the main part of the subset construction from NFA to NA also applies, mutatis mutandis, here. I think such a design would be more orthogonal than the current one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree with both comments, though I'd have to test grind (seems to be obstructed a bit by structure extensions sometimes). I'll implement them in a separate PR when I have some time for this again, since it seems like a backwards compatible extension to what is here. (Or, if you like, feel free to submit one.)

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.

Changes look good to me, what is remains is minor. I will leave approval to you all since it looks like you're still settling on where certain fields go.

@fmontesi fmontesi merged commit e9cfac9 into main Oct 7, 2025
4 checks passed
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.

3 participants