FAdo.codes

Code theory module

New in version 1.0.

class CodeProperty(name, alph)[source]
See: K. Dudzinski and s. Konstantinidis: Formal descriptions of code properties: decidability, complexity,

implementation. International Journal of Foundations of Computer Science 23:1 (2012), 67–85.

Variables:

Sigma – the alphabet

abstract maximalP(aut, U=None)[source]

Tests if the language is maximal w.r.t. the property

Parameters:
  • U (DFA|NFA) – Universe of permitted words (sigma^* as default)

  • aut (DFA|NFA) – the automaton

Return type:

bool

abstract notMaximalW(aut, U=None)[source]

Witness of non maximality

Parameters:
  • aut (DFA|NFA) – the automaton

  • U (DFA|NFA) – Universe of permitted words (sigma^* as default)

Returns:

a witness

Return type:

str

abstract notSatisfiesW(aut)[source]

Return a witness of non-satisfaction of the property by the automaton language

Parameters:

aut (DFA|NFA) – the automaton

Returns:

word witness tuple

Return type:

tuple

abstract satisfiesP(aut)[source]

Satisfaction of the property by the automaton language

Parameters:

aut (NFA|DFA) – the automaton

Return type:

bool

class ErrCorrectProp(t)[source]

Error Correcting Property

Inheritance diagram of ErrCorrectProp

Constructor :param SFT aut: Input preserving transducer

notMaximalW(aut, U=None)[source]

Tests if the language is maximal w.r.t. the property

Parameters:
  • aut (DFA|NFA) – the automaton

  • U (DFA|NFA) – Universe of permitted words (sigma^* as default)

Return type:

bool

notSatisfiesW(aut)[source]

Satisfaction of the code property by the automaton language

Parameters:

aut (DFA|NFA) – the automaton

Return type:

tuple

satisfiesP(aut)[source]

Satisfaction of the property by the automaton language

See also

s. Konstantinidis: Transducers and the Properties of Error-Detection, Error-Correction and Finite-Delay Decodability. Journal Of Universal Computer Science 8 (2002), 278-291.

Parameters:

aut (DFA|NFA) – the automaton

Return type:

bool

ErrDetectProp

alias of IPTProp

class FixedProp(name, alph)[source]

Abstract class for fixed properties

abstract maximalP(aut, U=None)[source]

Tests if the language is maximal w.r.t. the property

Parameters:
  • U (DFA|NFA) – Universe of permitted words (sigma^* as default)

  • aut (DFA|NFA) – the automaton

Return type:

bool

abstract notMaximalW(aut, U=None)[source]

Witness of non maximality

Parameters:
  • aut (DFA|NFA) – the automaton

  • U (DFA|NFA) – Universe of permitted words (sigma^* as default)

Returns:

a witness

Return type:

str

abstract notSatisfiesW(aut)[source]

Test whether the language is a code.

Parameters:

aut (DFA|NFA) – the automaton

Returns:

two different factorizations of the same word

Return type:

tuple of list

abstract satisfiesP(aut)[source]

Satisfaction of the property by the automaton language

Parameters:

aut (NFA|DFA) – the automaton

Return type:

bool

class HypercodeProp(t)[source]

Hypercode Property

Inheritance diagram of PrefixProp

Constructor

Parameters:
  • aut (DFA|NFA) – regular expression over {0,1}

  • Sigma (set) – the alphabet

class IATProp(aut, name=None)[source]

Input Altering Transducer Property

Inheritance diagram of IATProp

Constructor :param SFT aut: Input preserving transducer

notSatisfiesW(aut)[source]

Return a witness of non-satisfaction of the property by the automaton language

Parameters:

aut (DFA|NFA) – the automaton

Returns:

word witness pair

Return type:

tuple

class IPTProp(aut, name=None)[source]

Input Preserving Transducer Property

Inheritance diagram of IPTProp
Variables:
  • Aut (SFT) – the transducer defining the property

  • sigma (set) – alphabet

Constructor :param SFT aut: Input preserving transducer

addToCode(aut, N, n=2000)[source]

Returns an NFA and a list W of up to N words of length ell, such that the NFA accepts L(aut) union W, which is an error-detecting language. ell is computed from aut

Parameters:
  • aut (NFA) – the automaton

  • N (int) – the number of words to construct

  • n (int) – number of tries when needing a new word

Returns:

an automaton and a list of strings

Return type:

tuple

makeCode(N, ell, s, n=2000, ov_free=False)[source]

Returns an NFA and a list W of up to N words of length ell, such that the NFA accepts W, which is an error-detecting language. The alphabet to use is {0,1,…,s-1}. where s <= 10.

Parameters:
  • N (int) – the number of words to construct

  • ell (int) – the codeword length

  • s (int) – the alphabet size (must be <= 10)

  • n (int) – number of tries when needing a new word

Returns:

an automaton and a list of strings

Return type:

tuple

makeCodeO(N, ell, s, n=2000, end=None, ov_free=False)[source]

Returns an NFA and a list W of up to N words of length ell, such that the NFA accepts W, which is an error-detecting language. The alphabet to use is {0,1,…,s-1}. where s <= 10.

Parameters:
  • N (int) – the number of words to construct

  • ell (int) – the codeword length

  • s (int) – the alphabet size (must be <= 10)

  • n (int) – number of tries when needing a new word

  • end (Word) – a Word or None that should much the end of code words

  • ov_free (Boolean) – if True code words much be overlap free

Returns:

an automaton and a list of strings

Return type:

tuple

Note: not ov_free and end defined simultaneously Note: end should be a Word

maximalP(aut, U=None)[source]

Tests if the language is maximal w.r.t. the property

Parameters:
  • aut (NFA) – the automaton

  • U (NFA) – Universe of permitted words (sigma^* as default)

Return type:

bool

notMaxStatW(aut, ell, n=2000, ov_free=False)[source]

Returns a word of length ell to add into aut or None; simpler version of function nonMaxStatFEpsW

Parameters:
  • aut (NFA) – the automaton

  • ell (int) – the length of the words in aut

  • n (int) – number of words to try

Returns:

a string or None

Return type:

str

notMaximalW(aut, U=None)[source]

Tests if the language is maximal w.r.t. the property

Parameters:
  • aut (DFA|NFA) – the automaton

  • U (DFA|NFA) – Universe of permitted words (sigma^* as default)

Return type:

bool

Raises:

PropertyNotSatisfied – if not satisfied

notSatisfiesW(aut)[source]

Return a witness of non-satisfaction of the property by the automaton language

Parameters:

aut (DFA|NFA) – the automaton

Returns:

word witness pair

Return type:

tuple

satisfiesP(aut)[source]

Satisfaction of the property by the automaton language

Parameters:

aut (DFA|NFA) – the automaton

Return type:

bool

class InfixProp(t)[source]

Infix Property

Inheritance diagram of InfixProp

Constructor

Parameters:
  • aut (DFA|NFA) – regular expression over {0,1}

  • Sigma (set) – the alphabet

class OutfixProp(t)[source]

Outfix Property

Inheritance diagram of PrefixProp

Constructor

Parameters:
  • aut (DFA|NFA) – regular expression over {0,1}

  • Sigma (set) – the alphabet

class PrefixProp(t)[source]

Prefix Property

Inheritance diagram of PrefixProp

Constructor

Parameters:
  • aut (DFA|NFA) – regular expression over {0,1}

  • Sigma (set) – the alphabet

satisfiesPrefixP(aut)[source]

Satisfaction of property by the automaton language: faster than satisfiesP

Parameters:

aut (DFA|NFA) – the automaton

Return type:

bool

class SuffixProp(t)[source]

Suffix Property

Inheritance diagram of SuffixProp

Constructor

Parameters:
  • aut (DFA|NFA) – regular expression over {0,1}

  • Sigma (set) – the alphabet

class TrajProp(aut, Sigma)[source]

Class of trajectoty properties

Inheritance diagram of TrajProp

Constructor

Parameters:
  • aut (DFA|NFA) – regular expression over {0,1}

  • Sigma (set) – the alphabet

static trajToTransducer(traj, Sigma)[source]

Input Altering Tranducer corresponding to a Trajectory

Parameters:
  • traj (NFA) – trajectory language

  • Sigma (set) – alphabet

Return type:

SFT

class UDCodeProp(alphabet)[source]

Uniquely decodable Code Property

Inheritance diagram of UDCodeProp
maximalP(aut, U=None)[source]

Tests if the language is maximal w.r.t. the property :param DFA|NFA aut: the automaton :param DFA|NFA U: Universe of permitted words (sigma^* as default) :rtype: bool

notSatisfiesW(aut)[source]

Test whether the language is a code.

Parameters:

aut (DFA|NFA) – the automaton

Returns:

two different factorizations of the same word

Return type:

tuple of list

satisfiesP(aut)[source]

Satisfaction of the code property by the automaton language

Parameters:

aut (DFA|NFA) – the automaton

Return type:

bool

buildErrorCorrectPropF(fname)[source]

Builds an Error Correcting Property

Parameters:

fname (str) – file name

Return type:

ErrCorrectProp

buildErrorCorrectPropS(s)[source]

Builds an Error Correcting Property from string

Parameters:

s (str) – transducer string

Return type:

ErrCorrectProp

buildErrorDetectPropF(fname)[source]

Builds an Error Detecting Property

Parameters:

fname (str) – file name

Return type:

ErrDetectProp

buildErrorDetectPropS(s)[source]

Builds an Error Detecting Property from string

Parameters:

s (str) – transducer string

Return type:

ErrDetectProp

buildHypercodeProperty(alphabet)[source]

Builds a Hypercode Property

Parameters:

alphabet (set) – alphabet

Return type:

PrefixProp

buildIATPropF(fname)[source]

Builds a IATProp from a FAdo SFT file

Parameters:

fname (str) – file name

Return type:

IATProp

buildIATPropS(s)[source]

Builds a IATProp from a FAdo SFT string

Parameters:

s (str) – string containing SFT

Return type:

IATProp

buildIPTPropF(fname)[source]

Builds a IPTProp from a FAdo SFT file

Parameters:

fname (str) – file name

Return type:

IPTProp

buildIPTPropS(s)[source]

Builds a IPTProp from a FAdo SFT string

Parameters:

s (str) – file name

Return type:

IPTProp

buildInfixProperty(alphabet)[source]

Builds a Suffix Code Property

Parameters:

alphabet (set) – alphabet

Return type:

PrefixProp

buildOutfixProperty(alphabet)[source]

Builds a Outfix Code Property

Parameters:

alphabet (set) – alphabet

Return type:

PrefixProp

buildPrefixProperty(alphabet)[source]

Builds a Prefix Code Property

Parameters:

alphabet (set) – alphabet

Return type:

PrefixProp

buildSuffixProperty(alphabet)[source]

Builds a Suffix Code Property

Parameters:

alphabet (set) – alphabet

Return type:

PrefixProp

buildTrajPropS(regex, sigma)[source]

Builds a TrajProp from a string RegExp

Parameters:
  • regex (str) – the regular expression

  • sigma (set) – alphabet

Return type:

TrajProp

buildUDCodeProperty(alphabet)[source]

Builds a UDCodeProp (from thin air ;-)

Parameters:

alphabet (set) – alphabet

Return type:

UDCodeProp

constructCode(n, l, p, ipt=False, seed=None)[source]
Returns up to n words of length l satisfying the property p, the first one being seed.

If ipt is True, the property is assumed to be input-preserving transducer type

Return type:

list

createInputAlteringSIDTrans(n, sigmaSet)[source]

Create an input-altering SID transducer based

Parameters:
  • n (int) – max number of errors

  • sigmaSet (set) – alphabet

Returns:

a transducer representing the SID channel

Return type:

SFT

editDistanceW(auto)[source]

Compute the edit distance of a given regular language accepted by the NFA via Input-altering transducer.

Parameters:

auto (NFA) – language recogniser

Returns:

The edit distance of the given regular language plus a witness pair

Return type:

tuple

Attention

language should have at least two words

See also

Lila Kari, Stavros Konstantinidis, Steffen Kopecki, Meng Yang. An efficient algorithm for computing the edit distance of a regular language via input-altering transducers. arXiv:1406.1041 [cs.FL]

exponentialDensityP(aut)[source]
Checks if language density is exponential

Using breadth first search (BFS)

Parameters:

aut (NFA) – the representation of the language

Return type:

bool

Attention

aut should not have Epsilon transitions

fixedHierSubset(x, y)[source]

Returns whether x==y, or the fixed property with name x is a subset of y Currently (Jan 2015) the fixed properties names are ‘UD_codes’, ‘Prefix_codes’, ‘Suffix_codes’, ‘Infix_codes’, ‘Outfix_codes’, ‘Hypercodes’

Parameters:
  • x (tuple) – first argument

  • y (tuple) – second argument

Return type:

bool

isSubclass(p1, p2)[source]
Which property (language class) is a subclass of the other (if any).

It returns 1 if p1 is a subclass of p2; 2 if p2 is a subclass of p1; 3 if they are equal; 0 otherwise

Parameters:
  • p1 (IPTProp) – an input preserving transducer property

  • p2 (IPTProp) – an input preserving transducer property

Return type:

int

list2string(lt, dy)[source]
Parameters:
  • lt (list) – list of nonnegative integers from some set {0,1,…,q-1}

  • dy (dict) – mapping from {0,1,…,q-1} to some alphabet symbols

Returns:

string of symbols corresponding to the integers in lt

Return type:

str

long2base(n, q)[source]

Maps n to a list of digits corresponding to the base q representation of n in reverse order

Parameters:
  • n (int) – a positive integer

  • q (int) – base to represent n

Returns:

list of q-ary ‘digits’, that is, elements of {0,1,..,q-1}

Return type:

list

notUniversalStatW(a, l, maxIter=20000)[source]

Tests statistically whether the NFA a is l-non-universal, by evaluating a on <= maxIter randomly chosen words of length l

Parameters:

l (int) – nonnegative integer

Returns:

(w,i) where w is the word found at i-th try; or (None, i) after i tries

Return type:

tuple

pickFrom(s, ell)[source]

Returns a random string of length ell over {0,1,…,s-1}

Parameters:
  • s (int) – the size of the alphabet (should be <= 10)

  • ell (int) – the length of the desired string

Returns:

a string

Return type:

str

symmAndRefl(t, ipt=False)[source]
Return the transducer t | t.inverse, if ipt is True;

return the transducer t | t.inverse | id, otherwise

Return type:

SFT

unionOfIDs(first, second)[source]

Returns the “union” of the two sets: property ID X and propoerty ID Y. The result is the set union minus any element in one set that names a property containing a property named in the other set

Parameters:
  • first (set) – first argument

  • second (set) – second argument

Return type:

set