expression.automaton(algo="auto")

Generate an automaton from an expression.

The algo can be:

Precondition:

  • "standard", "thompson", "zpc", "zpc_compact": the expression is not extended

See also:

Examples

In [1]:
import vcsn
from IPython.display import display
e = vcsn.Q.expression('\e+<2>a+<3>b')
e
Out[1]:
$\varepsilon + \left\langle 2 \right\rangle \,a + \left\langle 3 \right\rangle \,b$
In [2]:
e.automaton('derived_term')
Out[2]:
%3 I0 0 0 I0->0 F0 F1 0->F0 1 1 0->1 ⟨2⟩a, ⟨3⟩b 1->F1
In [3]:
e.automaton('inductive')
Out[3]:
%3 I0 0 0 I0->0 F0 F1 F2 0->F0 1 1 0->1 ⟨2⟩a 2 2 0->2 ⟨3⟩b 1->F1 2->F2
In [4]:
e.automaton('standard')
Out[4]:
%3 I0 0 0 I0->0 F0 F2 F3 0->F0 2 2 0->2 ⟨2⟩a 3 3 0->3 ⟨3⟩b 2->F2 3->F3
In [5]:
e.automaton('thompson')
Out[5]:
%3 I0 0 0 I0->0 F1 2 2 0->2 ε 4 4 0->4 ε 6 6 0->6 ε 1 1 1->F1 3 3 2->3 ε 3->1 ε 5 5 4->5 ⟨2⟩a 5->1 ε 7 7 6->7 ⟨3⟩b 7->1 ε
In [6]:
e.automaton('zpc')
Out[6]:
%3 I0 0 0 I0->0 F0 F5 0->F0 1 1 0->1 ε 3 3 0->3 ε 2 2 1->2 ⟨2⟩a 5 5 2->5 ε 4 4 3->4 ⟨3⟩b 4->5 ε 5->F5
In [7]:
e.automaton('zpc_compact')
Out[7]:
%3 I0 0 0 I0->0 F0 F4 0->F0 1 1 0->1 ε 2 2 1->2 ⟨2⟩a 3 3 1->3 ε 4 4 2->4 ε 3->4 ⟨3⟩b 4->F4

Trimming

The automata are guaranteed to be trim, even if the algorithm used by automaton generated useless states.

In [8]:
e = vcsn.Q.expression('abc&abd')
e.derived_term()
Out[8]:
%3 I0 0 abc&abd I0->0 1 bc&bd 0->1 a 2 1->2 b
In [9]:
e.automaton('derived_term')
Out[9]:
%3
In [10]:
e = vcsn.Q.expression('a?')
e.zpc()
Out[10]:
%3 I0 0 0 I0->0 F0 F5 0->F0 1 1 0->1 ε 3 3 0->3 ε 2 2 5 5 2->5 ε 4 4 3->4 a 4->5 ε 5->F5
In [11]:
e.automaton('zpc')
Out[11]:
%3 I0 0 0 I0->0 F0 F3 0->F0 1 1 0->1 ε 2 2 1->2 a 3 3 2->3 ε 3->F3

Extended Rational Expressions

The derived-term based algorithms and "inductive" support extended expressions.

In [12]:
def aut(e):
    e = vcsn.context('lan, q').expression(e)
    for a in ['expansion', 'inductive']:
        print(a)
        display(e.automaton(a))
    
aut('(ab*c){T}')
expansion
%3 I0 0 0 I0->0 F2 1 1 0->1 c 2 2 1->2 a 3 3 1->3 b 2->F2 3->2 a 3->3 b
inductive
%3 I3 3 3 I3->3 F0 0 0 0->F0 1 1 1->0 a 2 2 2->1 b 2->2 b 3->1 c 3->2 c
In [13]:
aut('[ab]*a[ab]{1} & [ab]*a[ab]{2} & [ab]*a[ab]{3}')
expansion
%3 I0 0 0 I0->0 F4 0->0 a, b 1 1 0->1 a 2 2 1->2 a 3 3 2->3 a 4 4 3->4 a, b 4->F4
inductive
%3 I0 0 0 I0->0 F6 F7 1 1 0->1 a 2 2 0->2 a 3 3 0->3 b 1->1 a 1->2 a 1->3 b 4 4 2->4 a 3->1 a 3->2 a 3->3 b 5 5 4->5 a 6 6 5->6 a 7 7 5->7 b 6->F6 7->F7
In [14]:
aut('(a*b*){c}')
expansion
%3 I0 0 0 I0->0 F2 0->0 a 1 1 0->1 b 1->1 b 2 2 1->2 a 2->F2 2->2 a, b
inductive
%3 I0 0 0 I0->0 F3 1 1 0->1 a 2 2 0->2 b 1->1 a 1->2 b 2->2 b 3 3 2->3 a 3->F3 3->3 a, b