Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 45894
Kernel: Python 3

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

import vcsn
a = vcsn.context('lal(ab), b').de_bruijn(2) a
Image in a Jupyter notebook
a.evaluate('b')

\bot

a.evaluate('bbabb')

\top

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

a('bbabb')

\top

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

24Closed6Closes12closed3closes2Closingclosing\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}

a.evaluate('Closing')

22

a.evaluate('close') # but not enough

00

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

a = vcsn.context('law,q').expression('<2>(ab(<3>cd)*(ef))<5>', "associative").automaton() a
Image in a Jupyter notebook
a.evaluate('abcdef')

3030

a.evaluate('abcdcdef')

9090

Polynomials are also supported:

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

150150

Spontaneous transitions are allowed:

%%automaton -s a context = "wordset<char_letters(abcdef)>, q" $ -> 0 <2> 0 -> 1 \e 1 -> 1 <3>cd 1 -> 2 \e 2 -> $ <5>
Image in a Jupyter notebook
a.evaluate("cd")

3030

a.evaluate("")

1010

Tuplesets are fully supported:

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
Image in a Jupyter notebook
a.evaluate("aaa|ab")

33

a.evaluate("aba|ab")

11