# automaton.evaluate(w)¶

Evaluates the weight of the given word through the automata.

Preconditions:

• w must be a valid word in the labelset.
• automaton must not have spontaneous cycles.

## Examples¶

In [1]:
import vcsn

In [2]:
a = vcsn.context('lal(ab), b').de_bruijn(2)
a

Out[2]:
In [3]:
a.evaluate('b')

Out[3]:
$\bot$
In [4]:
a.evaluate('bbabb')

Out[4]:
$\top$

You can also write automaton('word') to evaluate a word:

In [5]:
a('bbabb')

Out[5]:
$\top$
In [6]:
a = vcsn.Z.expression('(<2>C+c)los(<3>e(s+<4>d)+ing)').standard()
a.shortest(10)

Out[6]:
$\left\langle 24\right\rangle \mathit{Closed} \oplus \left\langle 6\right\rangle \mathit{Closes} \oplus \left\langle 12\right\rangle \mathit{closed} \oplus \left\langle 3\right\rangle \mathit{closes} \oplus \left\langle 2\right\rangle \mathit{Closing} \oplus \mathit{closing}$
In [7]:
a.evaluate('Closing')

Out[7]:
$2$
In [8]:
a.evaluate('close') # but not enough

Out[8]:
$0$

All automaton types are supported, evaluate is not limited to free labelsets. For instance, with word-labeled automata:

In [9]:
a = vcsn.context('law,q').expression('<2>(ab(<3>cd)*(ef))<5>', "associative").automaton()
a

Out[9]:
In [10]:
a.evaluate('abcdef')

Out[10]:
$30$
In [11]:
a.evaluate('abcdcdef')

Out[11]:
$90$

Polynomials are also supported:

In [12]:
p = vcsn.context('law,q').polynomial('<2>abcdef+abcdcdef')
a.evaluate(p)

Out[12]:
$150$

Spontaneous transitions are allowed:

In [13]:
%%automaton -s a
context = "wordset<char_letters(abcdef)>, q"
$-> 0 <2> 0 -> 1 \e 1 -> 1 <3>cd 1 -> 2 \e 2 ->$ <5>

In [14]:
a.evaluate("cd")

Out[14]:
$30$
In [15]:
a.evaluate("")

Out[15]:
$10$

Tuplesets are fully supported:

In [16]:
ctx = vcsn.context('lat<lan, lan>, zmin')
a = ctx.expression('(<0>(a|a+b|b))* (<1>[^]|\e + <1>\e|[^] + <2>(a|[^a]+b|[^b])){*}').automaton()
a #Compute the LCS distance between two words

Out[16]:
In [17]:
a.evaluate("aaa|ab")

Out[17]:
$3$
In [18]:
a.evaluate("aba|ab")

Out[18]:
$1$