Module: Finite Languages (fl)

Finite languages and related automata manipulation

Finite languages manipulation

Classes

FL

class FL(wordsList=None, Sigma=None)[source]

Finite Language Class

Variables
  • Words – the elements of the language

  • Sigma – the alphabet

MADFA()[source]

Generates the minimal acyclical DFA using specialized algorithm

New in version 1.3.3.

See also

Incremental Construction of Minimal Acyclic Finite-State Automata, J.Daciuk, s.Mihov, B.Watson and r.E.Watson

Return type

ADFA

addWord(word)[source]

Adds a word to a FL :type word: Word :rtype: FL

addWords(wList)[source]

Adds a list of words to a FL

Parameters

wList (list) – words to add

diff(other)[source]

Difference of FL: a - b

Parameters

other (FL) – right hand operand

Return type

FL

Raises

FAdoGeneralError – if both arguments are not FL

filter(automata)[source]

Separates a language in two other using a DFA of NFA as a filter

Parameters

automata (DFA|NFA) – the automata to be used as a filter

Returns

the accepted/unaccepted pair of languages

Return type

tuple of FL

intersection(other)[source]

Intersection of FL: a & b

Parameters

other (FL) – right hand operand

Raises

FAdoGeneralError – if both arguments are not FL

multiLineAutomaton()[source]

Generates the trivial linear ANFA equivalent to this language

Return type

ANFA

setSigma(Sigma, Strict=False)[source]

Sets the alphabet of a FL

Parameters
  • Sigma (set) – alphabet

  • Strict (bool) – behaviour

Attention

Unless Strict flag is set to True, alphabet can only be enlarged. The resulting alphabet is in fact the union of the former alphabet with the new one. If flag is set to True, the alphabet is simply replaced.

suffixClosedP()[source]

Tests if a language is suffix closed

Return type

bool

toDFA()[source]

Generates a DFA recognizing the language

Return type

ADFA

New in version 1.2.

toNFA()[source]

Generates a NFA recognizing the language

Return type

ANFA

New in version 1.2.

trieFA()[source]

Generates the trie automaton that recognises this language

Returns

the trie automaton

Return type

ADFA

union(other)[source]

union of FL: a | b

Parameters

other (FL) – right hand operand

Return type

FL

Raises

FAdoGeneralError – if both arguments are not FL

DCFA

class DFCA[source]

Deterministic Cover Automata class

Inheritance diagram of DFCA
property length

size of the longest word :rtype: int

Type

return

AFA

class AFA[source]

Base class for Acyclic Finite Automata

Inheritance diagram of AFA

note: This is just a container for some common methods. Not to be used directly!!

abstract addState(_)[source]
Return type

int

directRank()[source]

Compute rank function

Returns

ranf map

Return type

dict

ensureDead()[source]

Ensures that a state is defined as dead

evalRank()[source]

Evaluates the rank map of a automaton

Returns

pair of sets of states by rank map, reverse delta accessability map

Return type

tuple

getLeaves()[source]

The set of leaves, i.e. final states for last symbols of language words

Returns

set of leaves

Return type

set

ordered()[source]

Orders states names in its topological order

Returns

ordered list of state indexes

Return type

list of int

Note

one could use the FA.toposort() method, but special care must be taken with the dead state for the algorithms related with cover automata.

setDeadState(sti)[source]

Identifies the dead state

Parameters

sti (int) – index of the dead state

Attention

nothing is done to ensure that the state given is legitimate

Note

without dead state identified, most of the methods for acyclic automata can not be applied

ADFA

class ADFA[source]

Acyclic Deterministic Finite Automata class

Inheritance diagram of ADFA

Changed in version 1.3.3.

addSuffix(st, w)[source]

Adds a suffix starting in st

Parameters
  • st (int) – state

  • w (Word) – suffix

New in version 1.3.3.

Attention

in place transformation

complete(dead=None)[source]

Make the ADFA complete

Parameters

dead (int) – a state to be identified as dead state if one was not identified yet

Return type

ADFA

Attention

The object is modified in place

Changed in version 1.3.3.

diss()[source]

Evaluates the dissimilarity language

Return type

FL

New in version 1.2.1.

dissMin(witnesses=None)[source]

Evaluates the minimal dissimilarity language :param dict witnesses: optional witness dictionay :rtype: FL

New in version 1.2.1.

dup()[source]

Duplicate the basic structure into a new ADFA. Basically a copy.deep.

Return type

ADFA

forceToDFA()[source]

Conversion to DFA

Return type

DFA

forceToDFCA()[source]

Conversion to DFCA

Return type

DFA

level()[source]

Computes the level for each state

Returns

levels of states

Return type

dict

New in version 0.9.8.

minDFCA()[source]

Generates a minimal deterministic cover automata from a DFA

Return type

DFCA

New in version 0.9.8.

See also

Cezar Campeanu, Andrei Päun, and Sheng Yu, An efficient algorithm for constructing minimal cover automata for finite languages, IJFCS

minReversible()[source]

Returns the minimal reversible equivalent automaton

Return type

ADFA

minimal()[source]

Finds the minimal equivalent ADFA

See also

[TCS 92 pp 181-189] Minimisation of acyclic deterministic automata in linear time, Dominique Revuz

Changed in version 1.3.3.

Returns

the minimal equivalent ADFA

Return type

ADFA

minimalP(method=None)[source]

Tests if the DFA is minimal

Parameters

method – minimization algorithm (here void)

Return type

bool

Changed in version 1.3.3.

possibleToReverse()[source]

Tests if language is reversible

New in version 1.3.3.

statePairEquiv(s1, s2)[source]

Tests if two states of a ADFA are equivalent

Parameters
  • s1 (int) – state1

  • s2 (int) – state2

Return type

bool

New in version 1.3.3.

toANFA()[source]

Converts the ADFA in a equivalent ANFA

Return type

ANFA

toNFA()[source]

Converts the ADFA in a equivalent NFA

Return type

ANFA

New in version 1.2.

trim()[source]

Remove states that do not lead to a final state, or, inclusively, that can’t be reached from the initial state. Only useful states remain.

Attention

in place transformation

wordGenerator()[source]

Creates a random word generator

Returns

the random word generator

Return type

RndWGen

New in version 1.2.

ANFA

class ANFA[source]

Acyclic Nondeterministic Finite Automata class

Inheritance diagram of ANFA
mergeInitial()[source]

Merge initial states

Attention

object is modified in place

mergeLeaves()[source]

Merge leaves

Attention

object is modified in place

mergeStates(s1, s2)[source]

Merge state s2 into state s1

Parameters
  • s1 (int) – state

  • s2 (int) – state

Note

no attempt is made to check if the merging preserves the language of teh automaton

Attention

the object is modified in place

moveFinal(st, stf)[source]

Unsets a set as final transfering transition to another final :param int st: the state to be ‘moved’ :param int stf: the destination final state

Note

stf must be a ‘last’ final state, i.e., must have no out transitions to anywhere but to a possible dead state

Attention

the object is modified in place

RndWGen

class RndWGen(aut)[source]

Word random generator class

New in version 1.2.

Parameters

aut (ADFA) – automata recognizing the language

Functions

sigmaInitialSegment

sigmaInitialSegment(Sigma, l, exact=False)[source]

Generates the ADFA recognizing sigma^i for i<=l :param set Sigma: the alphabet :param int l: length :param bool exact: only the words with exactly that length? :returns: the automaton :rtype: ADFA

genRndTrieBalanced

genRndTrieBalanced(maxL, Sigma, safe=True)[source]

Generates a random trie automaton for a binary language of balanced words of a given leght for max word :param int maxL: length of the max word :param set Sigma: alphabet to be used :param bool safe: should a word of size maxl be present in every language? :return: the generated trie automaton :rtype: ADFA

genRndTrieUnbalanced

genRndTrieUnbalanced(maxL, Sigma, ratio, safe=True)[source]

Generates a random trie automaton for a binary language of balanced words of a given length for max word

Parameters
  • maxL (int) – length of the max word

  • Sigma (set) – alphabet to be used

  • ratio (int) – the ratio of the unbalance

  • safe (bool) – should a word of size maxl be present in every language?

Returns

the generated trie automaton

Return type

ADFA

genRandomTrie

genRandomTrie(maxL, Sigma, safe=True)[source]

Generates a random trie automaton for a finite language with a given length for max word :param int maxL: length of the max word :param set Sigma: alphabet to be used :param bool safe: should a word of size maxl be present in every language? :return: the generated trie automaton :rtype: ADFA

genRndTriePrefix

genRndTriePrefix(maxL, Sigma, ClosedP=False, safe=True)[source]

Generates a random trie automaton for a finite (either prefix free or prefix closed) language with a given length for max word :param int maxL: length of the max word :param set Sigma: alphabet to be used :param bool ClosedP: should it be a prefix closed language? :param bool safe: should a word of size maxl be present in every language? :return: the generated trie automaton :rtype: ADFA

DFAtoADFA

DFAtoADFA(aut)[source]

Transforms an acyclic DFA into a ADFA

Parameters

aut (DFA) – the automaton to be transformed

Raises

notAcyclic – if the DFA is not acyclic

Returns

the converted automaton

Return type

ADFA

stringToADFA

stringToADFA(s)[source]

Convert a canonical string representation of a ADFA to a ADFA :param list s: the string in its canonical order :returns: the ADFA :rtype: ADFA

See also

Marco Almeida, Nelma Moreira, and Rogério Reis. Exact generation of minimal acyclic deterministic finite automata. International Journal of Foundations of Computer Science, 19(4):751-765, August 2008.