-
Notifications
You must be signed in to change notification settings - Fork 22
feat (Computability/Automata): Automata theory based on LTS, including DFA, NFA, EpsilonNFA, and translations between them, plus supporting theorems generalised to LTS #83
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
Conversation
…lication to automata theory to prove the subset construction correct
import Cslib.Foundations.Semantics.Lts.Bisimulation | ||
import Cslib.Foundations.Semantics.Lts.TraceEq | ||
import Cslib.Foundations.Semantics.LTS.Basic | ||
import Cslib.Foundations.Semantics.LTS.Bisimulation |
There was a problem hiding this comment.
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 🐶
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 |
There was a problem hiding this comment.
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 🐶
import Cslib.Foundations.Data.Relation | |
import Cslib.Foundations.Semantics.LTS.Simulation | |
import Cslib.Foundations.Data.Relation |
import Cslib.Languages.CombinatoryLogic.Defs | ||
import Cslib.Languages.CombinatoryLogic.Basic |
There was a problem hiding this comment.
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 🐶
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 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
structure DA (State : Type _) (Symbol : Type _) where | |
structure DA (State Symbol : Type*) where |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
structure DFA (State : Type _) (Symbol : Type _) extends DA State Symbol where | |
structure DFA (State Symbol : Type*) extends DA State Symbol where |
Yeah, I've been putting |
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>
Thanks @chenson2018, I think I'm done with all the changes that make immediate sense. :-) |
Cslib/Computability/Automata/DA.lean
Outdated
/-- The set of accepting states of the automaton. -/ | ||
accept : Set State |
There was a problem hiding this comment.
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).
Cslib/Computability/Automata/NA.lean
Outdated
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. -/ |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 := { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
…ata in the future
There was a problem hiding this 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.
No description provided.