FAdo.fa¶
Finite automata manipulation.
Deterministic and non-deterministic automata manipulation, conversion and evaluation.
- class DFA[source]¶
Class for Deterministic Finite Automata.
- Variables:
- HKeqP(other, strict=True)[source]¶
Tests the DFA’s equivalence using Hopcroft and Karp’s state equivalence algorithm
- Parameters:
other –
strict –
- Returns:
bool
See also
J. E. Hopcroft and r. M. Karp.A Linear Algorithm for Testing Equivalence of Finite Automata.TR 71–114. U. California. 1971
Attention
The automaton must be complete.
- MyhillNerodePartition()[source]¶
Myhill-Nerode partition, Moore’s way
New in version 1.3.5.
Attention
No state should be named with DeadName. This states is removed from the obtained partition.
See also
F.Bassino, J.David and C.Nicaud, On the Average Complexity of Moores’s State Minimization Algorihm, Symposium on Theoretical Aspects of Computer Science
- aEquiv()[source]¶
Computes almost equivalence, used by hyperMinimial
- Returns:
partition of states
- Return type:
Note
may be optimized to avoid dupped
- addTransition(sti1, sym, sti2)[source]¶
Adds a new transition from sti1 to sti2 consuming symbol sym.
- addTransitionIfNeeded(sti1: int, sym, sti2: int) int [source]¶
Adds a new transition from sti1 to sti2 consuming symbol sym, creating states if needed
- complete(dead='DeaD')[source]¶
Transforms the automata into a complete one. If sigma is empty nothing is done.
Note
Adds a dead state (if necessary) so that any word can be processed with the automata. The new state is named
dead
, so this name should never be used for other purposes.Attention
The object is modified in place.
Changed in version 1.0.
- completeMinimal()[source]¶
Completes a DFA assuming it is a minimal and avoiding de destruction of its minimality If the automaton is not complete, all the non-final states are checked to see if tey are not already a dead state. Only in the negative case a new (dead) state is added to the automaton.
- Return type:
Attention
The object is modified in place. If the alphabet is empty nothing is done
- computeKernel()[source]¶
The Kernel of a ICDFA is the set of states that accept a non-finite language.
- Returns:
triple (comp, center , mark) where comp are the strongly connected components, center the set of center states and mark the kernel states
- Return type:
- concat(fa2, strict=False)[source]¶
Concatenation of two DFAs. If DFAs are not complete, they are completed.
- Parameters:
- Returns:
the result of the concatenation
- Return type:
- Raises:
DFAdifferentSigma – if alphabet are not equal
- concatI(fa2, strict=False)[source]¶
Concatenation of two DFAs.
- Parameters:
- Returns:
the result of the concatenation
- Return type:
- Raises:
DFAdifferentSigma – if alphabet are not equal
New in version 0.9.5.
Note
this is to be used with non-complete DFAs
- delTransition(sti1, sym, sti2, _no_check=False)[source]¶
Remove a transition if existing and perform cleanup on the transition function’s internal data structure.
- Parameters:
Note
Unused alphabet symbols will be discarded from sigma.
- deleteStates(del_states)[source]¶
Delete given iterable collection of states from the automaton.
- Parameters:
del_states – collection of state indexes
Note
in-place action
Note
delta function will always be rebuilt, regardless of whether the states list to remove is a suffix, or a sublist, of the automaton’s states list.
- dist()[source]¶
Evaluate the distinguishability language for a DFA
- Return type:
See also
Cezar Câmpeanu, Nelma Moreira, Rogério Reis: The distinguishability operation on regular languages. NCMA 2014: 85-100
New in version 0.9.8.
- distMin()[source]¶
Evaluates the list of minimal words that distinguish each pair of states
New in version 0.9.8.
Attention
If the DFA is not minimal, the method loops forever
- distR()[source]¶
Evaluate the right distinguishability language for a DFA
- Return type:
- ..seealso:: Cezar Câmpeanu, Nelma Moreira, Rogério Reis:
The distinguishability operation on regular languages. NCMA 2014: 85-100
- distRMin()[source]¶
Compute distRMin for DFA
- Return type:
- ..seealso:: Cezar Câmpeanu, Nelma Moreira, Rogério Reis:
The distinguishability operation on regular languages. NCMA 2014: 85-100
- distTS()[source]¶
Evaluate the two-sided distinguishability language for a DFA
- Return type:
- ..seealso:: Cezar Câmpeanu, Nelma Moreira, Rogério Reis:
The distinguishability operation on regular languages. NCMA 2014: 85-100
- enumDFA(n=None)[source]¶
returns the set of words of words of length up to n accepted by self :param int n: highest length or all words if finite
- Return type:
list of strings or None
- equal(other)[source]¶
Verify if the two automata are equivalent. Both are verified to be minimum and complete, and then one is matched against the other… Doesn’t destroy either dfa…
- evalSymbol(init, sym)[source]¶
Returns the state reached from given state through a given symbol.
- Parameters:
- Returns:
reached state
- Return type:
- Raises:
DFAsymbolUnknown – if symbol not in alphabet
DFAstopped – if transition function is not defined for the given input
- evalSymbolI(init, sym)[source]¶
Returns the state reached from a given state.
- Parameters:
init (init) – current state
sym (str) – symbol to be consumed
- Returns:
reached state or -1
- Return type:
- Raises:
DFAsymbolUnknown – if symbol not in alphabet
New in version 0.9.5.
Note
this is to be used with non-complete DFAs
- evalSymbolL(ls, sym)[source]¶
Returns the set of states reached from a given set of states through a given symbol
- evalSymbolLI(ls, sym)[source]¶
Returns the set of states reached from a given set of states through a given symbol
- Parameters:
- Returns:
set of reached states
- Return type:
New in version 0.9.5.
Note
this is to be used with non-complete DFAs
- finalCompP(s)[source]¶
Verifies if there is a final state in strongly connected component containing
s
.- Parameters:
s (int) – state
- Returns:
1 if yes, 0 if no
- hasTrapStateP()[source]¶
Tests if the automaton has a dead trap state
- Return type:
New in version 1.1.
- hxState(st: int) str [source]¶
A hash value for the transition of a state. The automaton needs to be complete.
- hyperMinimal(strict=False)[source]¶
Hyperminization of a minimal DFA
- Parameters:
strict (bool) – if strict=True it first minimizes the DFA
- Returns:
an hyperminimal DFA
- Return type:
See also
M. Holzer and A. Maletti, An nlogn Algorithm for Hyper-Minimizing a (Minimized) Deterministic Automata, TCS 411(38-39): 3404-3413 (2010)
Note
if strict=False minimality is assumed
- joinStates(lst)[source]¶
Merge a list of states.
- Parameters:
lst (iterable of state indexes.) – set of equivalent states
- makeReversible()[source]¶
Make a DFA reversible (if possible)
See also
M.Holzer, s. Jakobi, M. Kutrib ‘Minimal Reversible Deterministic Finite Automata’
- Return type:
- make_prefix_free()[source]¶
Turns a DFA in a prefix-free automaton deleting all outgoing transitions from final states
- Return type:
New in version 2.0.3.
- markNonEquivalent(s1, s2, data)[source]¶
Mark states with indexes s1 and s2 in given map as non-equivalent states. If any back-effects exist, apply them.
- mergeStates(f, t)[source]¶
Merge the first given state into the second. If the first state is an initial state the second becomes the initial state.
Attention
It is up to the caller to remove the disconnected state. This can be achieved with
`trim()
.
- minimal(method='minimalMooreSq', complete=True)[source]¶
Evaluates the equivalent minimal complete DFA
- minimalHopcroft()[source]¶
Evaluates the equivalent minimal complete DFA using Hopcroft algorithm
- Returns:
equivalent minimal DFA
- Return type:
See also
John Hopcroft,An n log{n} algorithm for minimizing states in a finite automaton.The Theory of Machines and Computations.AP. 1971
- minimalIncremental(minimal_test=False, one_cicle=False)[source]¶
Minimizes the DFA with an incremental method using the Union-Find algorithm and Memoized non-equivalence intermediate results
- Parameters:
minimal_test (bool) – starts by verifying that the automaton is not minimal?
- Returns:
equivalent minimal DFA
- Return type:
See also
M. Almeida and N. Moreira and and r. Reis.Incremental DFA minimisation. CIAA 2010. LNCS 6482. pp 39-48. 2010
- minimalMoore()[source]¶
Evaluates the equivalent minimal automata with Moore’s algorithm
See also
John E. Hopcroft and Jeffrey D. Ullman, Introduction to Automata Theory, Languages, and Computation, AW, 1979
- Returns:
minimal complete DFA
- Return type:
- minimalMooreSq()[source]¶
Evaluates the equivalent minimal complete DFA using Moore’s (quadratic) algorithm
See also
John E. Hopcroft and Jeffrey D. Ullman, Introduction to Automata Theory, Languages, and Computation, AW, 1979
- Returns:
equivalent minimal DFA
- Return type:
- minimalMooreSqP()[source]¶
Tests if a DFA is minimal using the quadratic version of Moore’s algorithm
- Return type:
- minimalNCompleteP()[source]¶
Tests if a non necessarely complete DFA is minimal, i.e., if the DFA is non-complete, if the minimal complete has only one more state.
- Returns:
True if not minimal
- Return type:
Attention
obsolete: use minimalP
- minimalNotEquivP()[source]¶
Tests if the DFA is minimal by computing the set of distinguishable (not equivalent) pairs of states
- Return type:
- minimalP(method='minimalMooreSq')[source]¶
Tests if the DFA is minimal
- Parameters:
method – the minimization algorithm to be used
- Return type:
..note: if DFA non-complete test if complete minimal has one more state
- minimalWatson(test_only=False)[source]¶
Evaluates the equivalent minimal complete DFA using Waton’s incremental algorithm
- Parameters:
test_only (bool) – is it only to test minimality
- Returns:
equivalent minimal DFA
- Return type:
- Raises:
DFAnotComplete – if automaton is not complete
- ..attention::
automaton must be complete
- minimalWatsonP()[source]¶
Tests if a DFA is minimal using Watson’s incremental algorithm
- Return type:
- orderedStrConnComponents()[source]¶
Topological ordered list of strong components
New in version 1.3.3.
- Return type:
- pairGraph()[source]¶
Returns pair graph
- Return type:
DiGraphVM
See also
A graph theoretic apeoach to automata minimality. Antonio Restivo and Roberto Vaglica. Theoretical Computer Science, 429 (2012) 282-291. doi:10.1016/j.tcs.2011.12.049 Theoretical Computer Science, 2012 vol. 429 (C) pp. 282-291. http://dx.doi.org/10.1016/j.tcs.2011.12.049
- print_data(data)[source]¶
Prints table of compatibility (in the context of the minimalization algorithm).
- Parameters:
data – data to print
- product(other)[source]¶
Returns a DFA resulting of the simultaneous execution of two DFA. No final states set.
Note
this is a fast version of the method. The resulting state names are not meaningfull.
- Parameters:
other – the other DFA
- Return type:
- productSlow(other, complete=True)[source]¶
Returns a DFA resulting of the simultaneous execution of two DFA. No final states set.
Note
this is a slow implementation for those that need meaningfull state names
New in version 1.3.3.
- reorder(dicti)[source]¶
Reorders states according to given dictionary. Given a dictionary (not necessarily complete)… reorders states accordingly.
- Parameters:
dicti (dict) – reorder dictionary
- reverseTransitions(rev)[source]¶
Evaluate reverse transition function.
- Parameters:
rev (DFA) – DFA in which the reverse function will be stored
- sSemigroup()[source]¶
Evaluation of the syntactic semigroup of a DFA
- Returns:
the semigroup
- Return type:
- shuffle(other, strict=False)[source]¶
CShuffle of two languages: L1 W L2
- Parameters:
- Return type:
See also
C. Câmpeanu, K. Salomaa and s. Yu, Tight lower bound for the state complexity of CShuffle of regular languages. J. Autom. Lang. Comb. 7 (2002) 303–310.
- sop(other)[source]¶
Strange operation
See also
Nelma Moreira, Giovanni Pighizzini, and Rogério Reis. Universal disjunctive concatenation and star. In Jeffrey Shallit and Alexander Okhotin, editors, Proceedings of the 17th Int. Workshop on Descriptional Complexity of Formal Systems (DCFS15), number 9118 in LNCS, pages 197–208. Springer, 2015.
New in version 1.2b2.
- star(flag=False)[source]¶
Star of a DFA. If the DFA is not complete, it is completed.
..versionchanged: 0.9.6
- stronglyConnectedComponents()[source]¶
Dummy method that uses the NFA conterpart
New in version 1.3.3.
- Return type:
- succintTransitions()[source]¶
Collects the transition information in a compact way suitable for graphical representation.
- Returns:
list of tupples
- Return type:
New in version 0.9.8.
- syncPower()[source]¶
Evaluates the Power automata for the action of each symbol
- Returns:
The Power automata being the set of all states the initial state and all singleton states final
- Return type:
- toADFA()[source]¶
Try to convert DFA to ADFA
- Returns:
the same automaton as a ADFA
- Return type:
- Raises:
notAcyclic – if this is not an acyclic DFA
New in version 1.2.
Changed in version 1.2.1.
- uniqueRepr()[source]¶
Normalise unique string for the string icdfa’s representation. .. seealso:: TCS 387(2):93-102, 2007 https://www.dcc.fc.up.pt/~nam/publica/tcsamr06.pdf
- Returns:
normalised representation
- Return type:
- Raises:
DFAnotComplete – if DFA is not complete
- unmark()[source]¶
Unmarked NFA that corresponds to a marked DFA: in which each alfabetic symbol is a tuple (symbol, index)
- Returns:
a NFA
- Return type:
- usefulStates(initial_states=None)[source]¶
Set of states reacheable from the given initial state(s) that have a path to a final state.
- witnessDiff(other)[source]¶
Returns a witness for the difference of two DFAs and:
0
if the witness belongs to the other language
1
if the witness belongs to the self language
- Parameters:
other (DFA) – the other DFA
- Returns:
a witness word
- Return type:
list of symbols
- Raises:
DFAequivalent – if automata are equivalent
- class EnumDFA(aut, store=False)[source]¶
Class for enumerating languages defined by DFAs
- fillStack(w)[source]¶
Computes S_1,…,S_n-1 where S_i is the set of (n-i)-complete states reachable from S_i-1
- Parameters:
w – word
- class EnumL(aut, store=False)[source]¶
- Class for enumerate FA languages
See: Efficient enumeration of words in regular languages, M. Ackerman and J. Shallit, Theor. Comput. Sci. 410, 37, pp 3461-3470. 2009. http://dx.doi.org/10.1016/j.tcs.2009.03.018
- Variables:
New in version 0.9.8.
- enum(m)[source]¶
Enumerates the first m words of L(A) according to the lexicographic order if there are at least m words. Otherwise, enumerates all words accepted by A.
- Parameters:
m (int) – max number of words
- enumCrossSection(n)[source]¶
Enumerates the nth cross-section of L(A)
- Parameters:
n (int) – nonnegative integer
- class EnumNFA(aut, store=False)[source]¶
Class for enumerating languages defined by NFAs
- fillStack(w)[source]¶
Computes S_1,…,S_n-1 where S_i is the set of (n-i)-complete states reachable from S_i-1
- Parameters:
w – word
- class FA[source]¶
- Base class for Finite Automata.
This is just an abstract class. Not to be used directly!!
- Variables:
- addFinal(stateindex)[source]¶
A new state is added to the already defined set of final states.
- Parameters:
stateindex (int) – index of the new final state.
- addSigma(sym)[source]¶
Adds a new symbol to the alphabet.
- Parameters:
sym (str) – symbol to be added
- Raises:
DFAepsilonRedefinition – if sym is Epsilon
Note
There is no problem with duplicate symbols because sigma is a Set.
No symbol Epsilon can be added.
- addState(name=None) int [source]¶
Adds a new state to an FA. If no name is given a new name is created.
- Parameters:
name (
Object
, optional) – Name of the state to be added.- Returns:
Current number of states (the new state index).
- Return type:
- Raises:
DuplicateName – if a state with that name already exists
- changeSigma(subst: dict)[source]¶
Change the alphabet of an automaton by means of a sunstitution subst
- Parameters:
subst (dict) – substitution
- Raises:
FASiseMismatch – if substitution has a size different from existing alphabet
- conjunction(other)[source]¶
A simple literate invocation of __and__
- Parameters:
other (FA) – right-hand operand.
- Returns:
Intersection of self and other.
- Return type:
New in version 0.9.6.
- countTransitions()[source]¶
Evaluates the size of FA transitionwise
- Returns:
the number of transitions
- Return type:
Changed in version 1.0.
- delFinal(st)[source]¶
Deletes a state from the final states list
- Parameters:
st (int) – state to be marked as not final.
- dotFormat(size='20,20', filename=None, direction='LR', strict=False, maxlblsz=6, sep='\n') str [source]¶
A dot representation
- Parameters:
- Returns:
the dot representation
- Return type:
New in version 0.9.6.
Changed in version 1.2.1.
- eliminateDeadName()[source]¶
Eliminates dead state name (common.DeadName) renaming the state
- Returns:
self
- Return type:
Attention
works inplace
New in version 1.2.
- eliminateStout(st)[source]¶
Eliminate all transitions outgoing from a given state
- Parameters:
st (int) – the state index to lose all outgoing transitions
Attention
performs in place alteration of the automata
New in version 0.9.6.
- finalsP(states: set) bool [source]¶
Tests if al the states in a set are final
- Parameters:
states (set) – set of state indexes.
- Returns:
are all the states final?
- Return type:
New in version 1.0.
- indexList(lstn)[source]¶
Converts a list of stateNames into a set of stateIndexes.
- Parameters:
lstn (list) – list of names
- Returns:
the list of state indexes
- Return type:
- Raises:
DFAstateUnknown – if a state name is unknown
- initialP(state: int) bool [source]¶
Tests if a state is initial
- Parameters:
state – state index
- Returns:
is the state initial?
- Return type:
- noBlankNames()[source]¶
Eliminates blank names
- Returns:
self
- Return type:
Attention
in place transformation
- renameState(st, name)[source]¶
Rename a given state.
Note
Deals gracefully both with int and str names in the case of name collision.
Attention
the object is modified in place
- renameStates(name_list=None)[source]¶
Renames all states using a new list of names.
- Parameters:
name_list (list) – list of new names.
- Returns:
self.
- Return type:
- Raises:
DFAerror – if provided list is too short.
Note
If no list of names is given, state indexes are used.
Attention
the object is modified in place
- reversal()[source]¶
Returns a NFA that recognizes the reversal of the language
- Returns:
NFA recognizing reversal language
- Return type:
- same_nullability(s1: int, s2: int) bool [source]¶
Tests if this two states have the same nullability
- setFinal(statelist)[source]¶
Sets the final states of the FA
Caution
Erases any previous definition of the final state set.
- setInitial(stateindex)[source]¶
Sets the initial state of a FA
- Parameters:
stateindex (int) – index of the initial state.
- stateIndex(name, auto_create=False)[source]¶
Index of given state name.
- Parameters:
- Returns:
state index
- Return type:
- Raises:
DFAstateUnknown – if the state name is unknown and autoCreate==False
Note
Replaces stateName
Note
If the state name is not known and flag is set creates it on the fly
New in version 1.0.
- stateName(name, auto_create=False)[source]¶
Index of given state name.
- Parameters:
- Returns:
state index
- Return type:
- Raises:
DFAstateUnknown – if the state name is unknown and autoCreate==False
Deprecated since version 1.0: Use:
stateIndex()
insteadDeprecated since version 1.0: Use the stateIndex() method instead
- class NFA[source]¶
Class for Non-deterministic Finite Automata (epsilon-transitions allowed).
- Variables:
- HKeqP(other, strict=True)[source]¶
Test NFA equivalence with extended Hopcroft-Karp method
See also
J. E. Hopcroft and r. M. Karp. A Linear Algorithm for Testing Equivalence of Finite Automata.TR 71–114. U. California. 1971
- addEpsilonLoops()[source]¶
Add epsilon loops to every state
Attention
in-place modification
New in version 1.0.
- addInitial(stateindex)[source]¶
Add a new state to the set of initial states.
- Parameters:
stateindex (int) – index of new initial state
- addTransition(sti1, sym, sti2)[source]¶
Adds a new transition. Transition is from
sti1
tosti2
consuming symbolsym
.sti2
is a unique state, not a set of them.
- addTransitionQ(srci, dest, symb, qfuture, qpast)[source]¶
Add transition to the new transducer instance.
- Parameters:
New in version 1.0.
- addTransitionStar(sti1, sti2, exception=())[source]¶
Adds a new transition from sti1 to sti2 consuming any symbol
- Parameters:
New in version 2.1.
- autobisimulation()[source]¶
Largest right invariant equivalence between states of the NFA
- Returns:
Incomplete equivalence relation (transitivity, and reflexivity not calculated) as a set of unordered pairs of states
- Return type:
See also
Ilie and S. Yu, Follow automata Inf. Comput. 186 - 1, pp 140-162, 2003
- autobisimulation2() list [source]¶
Alternative space-efficient definition of NFA.autobisimulation.
- Returns:
Incomplete equivalence relation (reflexivity, symmetry, and transitivity not calculated) as a set of pairs of states
- Return type:
- closeEpsilon(st)[source]¶
Add all non epsilon transitions from the states in the epsilon closure of given state to given state.
- Parameters:
st (int) – state index
Attention
in-place modification
- delTransition(sti1, sym, sti2, _no_check=False)[source]¶
Remove a transition if existing and perform cleanup on the transition function’s internal data structure.
- Parameters:
Note
unused alphabet symbols will be discarded from sigma.
- deleteStates(del_states)[source]¶
Delete given iterable collection of states from the automaton.
Note
delta function will always be rebuilt, regardless of whether the states list to remove is a suffix, or a sublist, of the automaton’s states list.
- detSet(generic=False)[source]¶
Computes the determination uppon a followFromPosition result
- Return type:
- dotFormat(size='20,20', filename=None, direction='LR', strict=False, maxlblsz=6, sep='\n') str [source]¶
A dot representation
- Parameters:
- Returns:
the dot representation
- Return type:
New in version 0.9.6.
Changed in version 1.2.1.
- elimEpsilon()[source]¶
Eliminate epsilon-transitions from this automaton.
:rtype : NFA
Attention
performs in place modification of automaton
Changed in version 1.1.1.
- eliminateEpsilonTransitions()[source]¶
Eliminates all epslilon-transitions with no state addition
Attention
in-place modification
- eliminateTSymbol(symbol)[source]¶
Delete all trasitions through a given symbol
- Parameters:
symbol (str) – the symbol to be excluded from delta
Attention
in-place modification
New in version 0.9.6.
- epsilonClosure(st)[source]¶
Returns the set of states epsilon-connected to from given state or set of states.
- Parameters:
- Returns:
the list of state indexes epsilon connected to
st
- Return type:
Attention
st
must exist beforehand.
- epsilonPaths(start: int, end: int) set[int] [source]¶
All states in all paths (DFS) through empty words from a given starting state to a given ending state.
- equivReduced(equiv_classes: UnionFind)[source]¶
Equivalent NFA reduced according to given equivalence classes.
- Parameters:
equiv_classes (UnionFind) – Equivalence classes
- Returns:
Equivalent NFA
- Return type:
- evalSymbol(stil, sym)[source]¶
Set of states reacheable from given states through given symbol and epsilon closure.
- Parameters:
- Returns:
set of reached state indexes
- Return type:
- Raises:
DFAsymbolUnknown – if symbol is not in alphabet
- finalCompP(s)[source]¶
Verify whether there is a final state in strongly connected component containing given state.
- hasTransitionP(state, symbol=None, target=None)[source]¶
Whether there’s a transition from given state, optionally through given symbol, and optionally to a specific target.
- homogeneousFinalityP() bool [source]¶
Tests if states have incoming transitions froms states with different finalities
- Return type:
- homogenousP(x)[source]¶
Whether this NFA is homogenous; that is, for all states, whether all incoming transitions to that state are through the same symbol.
- Parameters:
x – dummy parameter to agree with the method in DFAr
- Return type:
- lEquivNFA()[source]¶
Equivalent NFA obtained from merging equivalent states from autobisimulation of this NFA’s reversal.
- Return type:
Note
returns copy of self if autobisimulation renders no equivalent states.
- lrEquivNFA()[source]¶
Equivalent NFA obtained from merging equivalent states from autobisimulation of this NFA, and from autobisimulation of its reversal; i.e., merges all states that are equivalent w.r.t. the largest right invariant and largest left invariant equivalence relations.
- Return type:
Note
returns copy of self if autobisimulations render no equivalent states.
- minimal()[source]¶
Evaluates the equivalent minimal DFA
- Returns:
equivalent minimal DFA
- Return type:
- minimalDFA()[source]¶
Evaluates the equivalent minimal complete DFA
- Returns:
equivalent minimal DFA
- Return type:
- product(other)[source]¶
Returns a NFA (skeletom) resulting of the simultaneous execution of two DFA.
- Parameters:
other (NFA) – the other automata
- Return type:
- Raises:
NFAerror – if any argument has epsilon-transitions
Note
No final states are set.
Attention
operands cannot have epsilon-transitions
the name
EmptySet
is used in a unique special state namethe method uses 3 internal functions for simplicity of code (really!)
- rEquivNFA()[source]¶
Equivalent NFA obtained from merging equivalent states from autobisimulation of this NFA.
- Return type:
Note
returns copy of self if autobisimulation renders no equivalent states.
- renameStatesFromPosition()[source]¶
Rename states of a Glushkov automaton using the positions of the marked RE
- Return type:
- reorder(dicti)[source]¶
Reorder states indexes according to given dictionary.
- Parameters:
dicti (dict) – state name reorder
Attention
in-place modification
Note
dictionary does not have to be complete
- reversal()[source]¶
Returns a NFA that recognizes the reversal of the language
- Returns:
NFA recognizing reversal language
- Return type:
- reverseTransitions(rev)[source]¶
Evaluate reverse transition function.
- Parameters:
rev (NFA) – NFA in which the reverse function will be stored
- succintTransitions()[source]¶
Collects the transition information in a compact way suitable for graphical representation. :rtype: list
- toDFA()[source]¶
Construct a DFA equivalent to this NFA, by the subset construction method.
- Return type:
Note
valid to epsilon-NFA
- toNFAr()[source]¶
NFA with the reverse mapping of the delta function.
- Returns:
shallow copy with reverse delta function added
- Return type:
- class NFAr[source]¶
- Class for Non-deterministic Finite Automata with reverse delta function added by construction.
Includes efficient methods for merging states.
- addTransition(sti1, sym, sti2)[source]¶
Adds a new transition. Transition is from
sti1
tosti2
consuming symbolsym
.sti2
is a unique state, not a set of them. Reversed transition function is also computed
- delTransition(sti1, sym, sti2, _no_check=False)[source]¶
Remove a transition if existing and perform cleanup on the transition function’s internal data structure and in the reversal transition function
- deleteStates(del_states)[source]¶
Delete given iterable collection of states from the automaton. Performe deletion in the transition function and its reversal.
- elimEpsilonO()[source]¶
Eliminate epsilon-transitions from this automaton, with reduction of states through elimination of Epsilon-cycles, and single epsilon-transition cases.
- Return type:
Attention
performs inplace modification of automaton
- homogenousP(inplace=False)[source]¶
Checks is the automaton is homogenous, i.e.the transitions that reaches a state have all the same label.
- mergeStates(f, t)[source]¶
Merge the first given state into the second. If first state is an initial or final state, the second becomes respectively an initial or final state.
Attention
It is up to the caller to remove the disconnected state. This can be achieved with
`trim()
.
- mergeStatesSet(tomerge, target=None)[source]¶
Merge a set of states with a target merge state. If the states in the set have transitions among them, those transitions will be directly merged into the target state.
Note
if target state is not given, the minimal index with be considered.
Attention
The states of the list will become unreacheable, but won’t be removed. It is up to the caller to remove them. That can be achieved with
trim()
.
- toNFA()[source]¶
Turn into an instance of NFA, and remove the reverse mapping of the delta function.
- Returns:
shallow copy without reverse delta function
- Return type:
- unlinkSoleIncoming(state)[source]¶
If given state has only one incoming transition (indegree is one), and it’s through epsilon, then remove such transition and return the source state.
Note
if conditions aren’t met, returned source state is None, and automaton remains unmodified.
- class OFA[source]¶
Base class for one-way automata
- Variables:
- acyclicP(strict=True)[source]¶
Checks if the FA is acyclic
- Parameters:
strict (bool) – if not True loops are allowed
- Returns: True if the FA is acyclic
bool: True if the FA is acyclic
- dump()[source]¶
Returns a python representation of the object
- Returns:
the python representation (Tags,States,sigma,delta,Initial,Final)
- Return type:
- leftQuotient(other)[source]¶
Returns the quotient (NFA) of a language by another language, both given by FA.
- minimalBrzozowski()[source]¶
Constructs the equivalent minimal DFA using Brzozowski’s algorithm
- Returns:
equivalent minimal DFA
- Return type:
- rightQuotient(other)[source]¶
Returns the quotient (NFA) of a language by another language, both given by FA.
- topoSort()[source]¶
Topological order for the FA
- Returns:
List of state indexes
- Return type:
Note
self loops are taken in consideration
- class SemiDFA[source]¶
Class of automata without initial or final states
- Variables:
- static dotDrawTransition(st1: str, lbl1: str, st2, sep='\n') str [source]¶
Draw a transition in dot format
- emptyDFA(sigma=None)[source]¶
Given an alphabet returns the minimal DFA for the empty language
New in version 1.3.4.2.
- reduce_size(aut: DFA, maxIter=None) DFA [source]¶
A smaller (if possible) DFA. To use with huge automata.
- saveToString(aut: FA, sep='&') str [source]¶
Finite automata definition as a string using the input format.
New in version 0.9.5.
Changed in version 0.9.6: Names are now used instead of indexes.
Changed in version 0.9.7: New format with quotes and alphabet
- sigmaStarDFA(sigma=None) DFA [source]¶
Given a alphabet s returns the minimal DFA for s*
New in version 1.2.