automaton
.multiply
This function is overloaded, it supports multiple different signatures:
automaton
.multiply(
aut
)
The product (i.e., the concatenation) of two automata.
Precondition:
aut
has to be standardautomaton
.multiply(
num
)
The repeated multiplication (concatenation) of an automaton with itself. Exponent -1
denotes the infinity: the Kleene star.
Precondition:
automaton
has to be standardautomaton
.multiply((
min
,
max
))
The sum of repeated multiplications of an automaton.
Precondition:
min
<=
max
automaton
has to be standardAnother parameter can be added to precise on which kind of automaton we want the operation to be applied.
automaton
.multiply(
aut
,
algorithm
)
automaton
.multiply(
num
,
algorithm
)
automaton
.multiply((
min
,
max
)
,
algorithm)
The algorithm has to be one of these:
"auto"
: default parameter, same as "standard"
if parameters fit the standard preconditions, "general"
otherwise."general"
: general multiplication, no additional preconditions."standard"
: standard multiplication.Postconditions:
"standard"
: the result automaton is standard."general"
: the context of the result automaton is nullable.See also:
In [1]:
import vcsn
ctx = vcsn.context('lal_char, q')
def aut(e):
return ctx.expression(e).standard()
In [2]:
aut('ab') * aut('cd')
Out[2]:
This multiplication is standard because the right hand side automaton is standard.
If you want to force the execution of the general algorithm you can do it this way.
In [3]:
aut('ab').multiply(aut('cd'), "general")
Out[3]:
In order to satisfy any kind of input automaton, the general algorithm inserts a transition labelled by one
,
from each final transition of the left hand side automaton to each initial transition of the right hand side one.
In [4]:
%%automaton -s a
$ -> 0
$ -> 1
1 -> 2 b
0 -> 2 a
2 -> $
In [5]:
b = aut('b+a')
b
Out[5]:
a * b
is standard.
In [6]:
a * b
Out[6]:
b * a
is not.
In [7]:
b * a
Out[7]:
In [8]:
aut('ab') ** 3
Out[8]:
In [9]:
aut('a*') * 3
Out[9]:
Use the exponent -1 to mean infinity
. Alternatively, you may invoke a.star
instead of a ** -1
.
In [10]:
aut('ab') ** -1
Out[10]:
In [11]:
aut('ab').star()
Out[11]:
In [12]:
aut('ab') ** (2, 2)
Out[12]:
In [13]:
aut('ab') ** (2, 4)
Out[13]:
In [14]:
aut('ab') ** (2, -1)
Out[14]:
In [15]:
aut('ab') ** (-1, 3)
Out[15]:
In some cases applying proper to the result automaton of the general algorithm will give you the result of the standard algorithm.
In [16]:
aut('ab').multiply((-1, 3), "general")
Out[16]:
In [17]:
aut('ab').multiply((-1, 3), "general").proper()
Out[17]: