expression
.derivation(
label
,
breaking
=False)
¶Compute the derivation of a weighted expression.
Arguments:
label
: the (non empty) string to derive the expression with.breaking
: whether to split the result.See also:
References:
The following function will prove handy: it takes a rational expression and a list of strings, and returns a $\LaTeX$ aligned
environment to display nicely the result.
import vcsn
from IPython.display import Latex
def diffs(e, ws):
eqs = []
for w in ws:
w = e.context().word(w)
eqs.append(r'\frac{{\partial}}{{\partial {0:x}}} {1:x}& = {2:x}'
.format(w, e, e.derivation(w)))
return Latex(r'''\begin{{aligned}}
{0}
\end{{aligned}}'''.format(r'\\'.join(eqs)))
In the classical case (labels are letters, and weights are Boolean), this is the construct as described by Antimirov.
b = vcsn.context('lal_char(ab), b')
e = b.expression('[ab]{3}')
e.derivation('a')
Or, using the diffs
function we defined above:
diffs(e, ['a', 'aa', 'aaa', 'aaaa'])
Of course, expressions can be weighted.
q = vcsn.context('lal_char(abc), q')
e = q.expression('(<1/6>a*+<1/3>b*)*')
diffs(e, ['a', 'aa', 'ab', 'b', 'ba', 'bb'])
And this is tightly connected with the construction of the derived-term automaton.
e.derived_term()
It is possible to compute the derivatives of a multitape expression.
c = vcsn.context('lat<lan(ab), lan(xy)>, q')
exp = c.expression
c
e = exp('(a{+}|x + b{+}|y)*')
e.derived_term()
The following expressions corresponds to the second state of the above automaton (reached from the initial state via $a|x$).
f = exp(r'a*|\e') * e
f
diffs(f, [r'\e|x', r'\e|y', r'a|\e', r'b|\e'])
diffs(e, ['a|x', 'a|y', 'b|x', 'b|y'])
The "breaking" derivation "splits" the polynomial at the end.
e = q.expression('[ab](<2>[ab])', 'associative')
e
e.derivation('a')
e.derivation('a', True)
e.derivation('a').split()
Again, this is tightly connected with both flavors of the derived-term automaton.
e.derived_term()
e.derived_term('breaking_derivation')