Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346<?xml version="1.0" encoding="UTF-8"?>1<!-- $Id: aut-func.xml,v 1.13 Exp $ -->23<Chapter><Heading>Some functions involving automata</Heading>4This chapter describes some functions involving automata. It starts with functions to obtain equivalent automata of other type. Then the minimalization is considered.56<Section><Heading>From one type to another</Heading>7Recall that two automata are said to be equivalent when they recognize the same language.8Next we have functions which have as input automata of one type and as output equivalent automata of another type.910<ManSection>11<Func Name="EpsilonToNFA" Arg="A"/>12<Description>13<A>A</A> is an automaton with <M>\epsilon</M>-transitions. Returns a NFA14recognizing the same language.15<Example><![CDATA[16gap> x:=RandomAutomaton("epsilon",3,2);;Display(x);17| 1 2 318------------------------------------19a | [ 2 ] [ 3 ] [ 2 ]20b | [ 1, 2 ] [ 1, 2 ] [ 1, 3 ]21@ | [ 1, 2 ] [ 1, 2 ] [ 1, 2 ]22Initial states: [ 2, 3 ]23Accepting states: [ 1, 2, 3 ]24gap> Display(EpsilonToNFA(x));25| 1 2 326------------------------------------------27a | [ 1, 2 ] [ 1, 2, 3 ] [ 1, 2 ]28b | [ 1, 2 ] [ 1, 2 ] [ 1, 2, 3 ]29Initial states: [ 1, 2, 3 ]30Accepting states: [ 1, 2, 3 ]31]]></Example>32</Description>33</ManSection>343536<ManSection>37<Func Name="EpsilonToNFASet" Arg="A"/>38<Description>39<A>A</A> is an automaton with <M>\epsilon</M>-transitions. Returns a NFA40recognizing the same language. This function differs from <Ref Func="EpsilonToNFA"/>41in that it is faster for smaller automata, or automata with few42epsilon transitions, but slower in the really hard cases.43</Description>44</ManSection>45464748<ManSection>49<Func Name="EpsilonCompactedAut" Arg="A"/>50<Description>51<A>A</A> is an automaton with <M>\epsilon</M>-transitions. Returns an52<M>\epsilon</M>NFA with53each strongly-connected component of the54epsilon-transitions digraph of <A>A</A> identified with a single state and55recognizing the same language.56<Example><![CDATA[57gap> x:=RandomAutomaton("epsilon",3,2);;Display(x);58| 1 2 359------------------------------------60a | [ 1, 2 ] [ 1, 3 ] [ 1, 2 ]61b | [ 1, 2 ] [ 1, 2 ] [ 2, 3 ]62@ | [ 3 ] [ 2 ]63Initial state: [ 3 ]64Accepting states: [ 1, 3 ]65gap> Display(EpsilonCompactedAut(x));66| 1 267-------------------------68a | [ 1, 2 ] [ 1, 2 ]69b | [ 1, 2 ] [ 1, 2 ]70@ |71Initial state: [ 2 ]72Accepting states: [ 1, 2 ]73]]></Example>74</Description>75</ManSection>76777879<ManSection>80<Func Name="ReducedNFA" Arg="A"/>81<Description>82<A>A</A> is a non deterministic automaton (without <M>\epsilon</M>-transitions). Returns an83NFA accepting84the same language as its input but with possibly fewer states (it85quotients out86by the smallest right-invariant partition of the states). A paper describing87the algorithm is in preparation.88<Example><![CDATA[89gap> x:=RandomAutomaton("nondet",5,2);;Display(x);90| 1 2 3 4 591----------------------------------------------------------------------92a | [ 1, 5 ] [ 1, 2, 4, 5 ] [ 1, 3, 5 ] [ 3, 4, 5 ] [ 4 ]93b | [ 2, 3, 4 ] [ 3 ] [ 2, 3, 4 ] [ 2, 4, 5 ] [ 3 ]94Initial state: [ 4 ]95Accepting states: [ 1, 3, 4, 5 ]96gap> Display(ReducedNFA(x));97| 1 2 3 498--------------------------------------------------------99a | [ 1, 3 ] [ 1, 2, 3, 4 ] [ 4 ] [ 1, 3, 4 ]100b | [ 1, 2, 4 ] [ 1 ] [ 1 ] [ 2, 3, 4 ]101Initial state: [ 4 ]102Accepting states: [ 1, 3, 4 ]103]]></Example>104</Description>105</ManSection>106107108109<ManSection>110<Func Name="NFAtoDFA" Arg="A"/>111<Description>112Given an NFA, these synonym functions, compute the equivalent DFA, using the powerset construction,113according to the algorithm presented in the report of the AMoRE <Cite Key="AMORE:95"/> program.114The returned automaton is dense deterministic115<Example><![CDATA[116gap> x:=RandomAutomaton("nondet",3,2);;Display(x);117| 1 2 3118---------------------------119a | [ 2 ] [ 1, 3 ]120b | [ 2, 3 ]121Initial states: [ 1, 3 ]122Accepting states: [ 1, 2 ]123gap> Display(NFAtoDFA(x));124| 1 2 3125--------------126a | 2 2 1127b | 3 3 3128Initial state: [ 1 ]129Accepting states: [ 1, 2, 3 ]130]]></Example>131</Description>132</ManSection>133134135<ManSection>136<Func Name="FuseSymbolsAut" Arg="A, s1, s2"/>137<Description>138Given an automaton <A>A</A> and integers <A>s1</A> and <A>s2</A> which, returns an NFA139obtained by replacing all transitions through <A>s2</A> by transitions through <A>s1</A>.140<Example><![CDATA[141gap> x:=RandomAutomaton("det",3,2);;Display(x);142| 1 2 3143--------------144a | 2 3145b | 1146Initial state: [ 3 ]147Accepting states: [ 1, 2, 3 ]148gap> Display(FuseSymbolsAut(x,1,2));149| 1 2 3150---------------------------151a | [ 2 ] [ 1, 3 ]152Initial state: [ 3 ]153Accepting states: [ 1, 2, 3 ]154]]></Example>155</Description>156</ManSection>157158159160</Section>161162163<Section><Heading>Minimalization of an automaton</Heading>164The algorithm used to minimalize a dense deterministic automaton (i.e., to165compute a dense minimal166automaton recognizing the same language) is based on an algorithm due to167Hopcroft (see <Cite Key="AHU:74"/>). It is well known (see <Cite Key="HU:69"/>) that it suffices168to reduce the automaton given and remove the inaccessible states. Again, the169documentation for the computer program AMoRE <Cite Key="AMORE:95"/> has been very useful.170171<ManSection>172<Func Name="UsefulAutomaton" Arg="A"/>173<Description>174Given an automaton <A>A</A> (deterministic or not), outputs a dense DFA <A>B</A> whose states are all reachable and such that <A>A</A> and <A>B</A> are equivalent.175<Example><![CDATA[176gap> x:=RandomAutomaton("det",4,2);;Display(x);177| 1 2 3 4178-----------------179a | 3 4180b | 1 4181Initial state: [ 3 ]182Accepting states: [ 2, 3, 4 ]183gap> Display(UsefulAutomaton(x));184| 1 2 3185--------------186a | 2 3 3187b | 3 3 3188Initial state: [ 1 ]189Accepting states: [ 1, 2 ]190]]></Example>191</Description>192</ManSection>193194<ManSection>195<Func Name="MinimalizedAut" Arg="A"/>196<Description>197Returns the minimal automaton equivalent to <A>A</A>.198<Example><![CDATA[199gap> x:=RandomAutomaton("det",4,2);;Display(x);200| 1 2 3 4201-----------------202a | 3 4203b | 1 2 3204Initial state: [ 4 ]205Accepting states: [ 2, 3, 4 ]206gap> Display(MinimalizedAut(x));207| 1 2208-----------209a | 2 2210b | 2 2211Initial state: [ 1 ]212Accepting state: [ 1 ]213]]></Example>214</Description>215</ManSection>216217<ManSection>218<Attr Name=" MinimalAutomaton" Arg="A"/>219<Description>220Returns the minimal automaton equivalent to <A>A</A>, but stores it so that221future computations of this automaton just return the stored automaton.222<Example><![CDATA[223gap> x:=RandomAutomaton("det",4,2);;Display(x);224| 1 2 3 4225-----------------226a | 2 4227b | 3 4228Initial state: [ 4 ]229Accepting states: [ 1, 2, 3 ]230gap> Display(MinimalAutomaton(x));231| 1232--------233a | 1234b | 1235Initial state: [ 1 ]236Accepting state:237]]></Example>238</Description>239</ManSection>240241<ManSection>242<Func Name="AccessibleStates" Arg="aut [, p]"/>243<Description>244Computes the list of states of the automaton <A>aut</A>245which are accessible from state <A>p</A>. When <A>p</A> is not given, returns the states which are accessible from any initial state.246<Example><![CDATA[247gap> x:=RandomAutomaton("det",4,2);;Display(x);248| 1 2 3 4249-----------------250a | 1 2 4251b | 2 4252Initial state: [ 2 ]253Accepting states: [ 1, 2, 3 ]254gap> AccessibleStates(x,3);255[ 1, 2, 3, 4 ]256]]></Example>257</Description>258</ManSection>259260<ManSection>261<Func Name="AccessibleAutomaton" Arg="A"/>262<Description>263If <A>A</A> is a deterministic automaton, not necessarily dense, an264equivalent dense deterministic accessible automaton is returned.265(The function <C>UsefulAutomaton</C> is called.)266<P/>267If <A>A</A> is not deterministic with a single initial state, an equivalent268accessible automaton is returned.269270<Example><![CDATA[271gap> x:=RandomAutomaton("det",4,2);;Display(x);272| 1 2 3 4273-----------------274a | 1 3275b | 1 3 4276Initial state: [ 2 ]277Accepting states: [ 3, 4 ]278gap> Display(AccessibleAutomaton(x));279| 1 2 3 4280-----------------281a | 2 4 4 4282b | 2 3 4 4283Initial state: [ 1 ]284Accepting states: [ 2, 3 ]285]]></Example>286</Description>287</ManSection>288289<ManSection>290<Func Name="IntersectionLanguage" Arg="A1,A2"/>291<Func Name="IntersectionAutomaton" Arg="A1,A2"/>292<Description>293Computes an automaton that recognizes the intersection of the languages given (through automata or rational expressions by) <A>A1</A> and <A>A2</A>.294When the arguments are deterministic automata, is the same as ProductAutomaton, but works for all kinds of automata. Note that the language of the product of two automata is precisely the intersection of the languages of the automata.295<Example><![CDATA[296gap> x:=RandomAutomaton("det",3,2);;Display(x);297| 1 2 3298--------------299a | 2 3300b | 1301Initial state: [ 3 ]302Accepting states: [ 1, 2, 3 ]303gap> y:=RandomAutomaton("det",3,2);;Display(y);304| 1 2 3305--------------306a | 1307b | 1 3308Initial state: [ 3 ]309Accepting states: [ 1, 3 ]310gap> Display(IntersectionLanguage(x,y));311| 1 2312-----------313a | 2 2314b | 2 2315Initial state: [ 1 ]316Accepting state: [ 1 ]317]]></Example>318</Description>319</ManSection>320321322<ManSection>323<Func Name="AutomatonAllPairsPaths" Arg="A"/>324<Description>325Given an automaton <A>A</A>, with <C>n</C> states, outputs a <C>n</C> x <C>n</C> matrix P,326such that P[i][j] is the list of simple paths from state i to327state j in <A>A</A>.328<Example><![CDATA[329gap> a:=RandomAutomaton("det",3,2);330< deterministic automaton on 2 letters with 3 states >331gap> AutomatonAllPairsPaths(a);332[ [ [ [ 1, 1 ] ], [ ], [ ] ], [ [ [ 2, 1 ] ], [ [ 2, 2 ] ], [ ] ],333[ [ [ 3, 2, 1 ] ], [ [ 3, 2 ] ], [ [ 3, 3 ] ] ] ]334gap> Display(a);335| 1 2 3336--------------337a | 1 2338b | 1 2 3339Initial state: [ 3 ]340Accepting states: [ 1, 2 ]341]]></Example>342</Description>343</ManSection>344345346</Section>347</Chapter>348349350351352353354