# 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 :
import vcsn

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

Out:
In :
a.evaluate('b')

Out:
$\bot$
In :
a.evaluate('bbabb')

Out:
$\top$

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

In :
a('bbabb')

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

Out:
$\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 :
a.evaluate('Closing')

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

Out:
$0$

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

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

Out:
In :
a.evaluate('abcdef')

Out:
$30$
In :
a.evaluate('abcdcdef')

Out:
$90$

Polynomials are also supported:

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

Out:
$150$

Spontaneous transitions are allowed:

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

In :
a.evaluate("cd")

Out:
$30$
In :
a.evaluate("")

Out:
$10$

Tuplesets are fully supported:

In :
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:
In :
a.evaluate("aaa|ab")

Out:
$3$
In :
a.evaluate("aba|ab")

Out:
$1$