expression.automaton(algo="auto")

Generate an automaton from an expression.

The algo can be:

See also:

Examples


In [1]:
import vcsn
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('standard')


Out[3]:
%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 [4]:
e.automaton('thompson')


Out[4]:
%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 [5]:
e.automaton('zpc')


Out[5]:
%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 [6]:
e.automaton('zpc_compact')


Out[6]:
%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 [7]:
e = vcsn.Q.expression('abc&abd')
e.derived_term()


Out[7]:
%3 I0 0 abc&abd I0->0 1 bc&bd 0->1 a 2 1->2 b

In [8]:
e.automaton('derived_term')


Out[8]:
%3

In [9]:
e = vcsn.Q.expression('a?')
e.zpc()


Out[9]:
%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 [10]:
e.automaton('zpc')


Out[10]:
%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