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(r, ss):
eqs = []
for s in ss:
eqs.append(r'\frac{{\partial}}{{\partial {0}}} {1}& = {2}'
.format(s,
r.format('latex'),
r.derivation(s).format('latex')))
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')
r = b.expression('[ab]{3}')
r.derivation('a')
Or, using the diffs
function we defined above:
diffs(r, ['a', 'aa', 'aaa', 'aaaa'])
Of course, expressions can be weighted.
q = vcsn.context('lal_char(abc), q')
r = q.expression('(<1/6>a*+<1/3>b*)*')
diffs(r, ['a', 'aa', 'ab', 'b', 'ba', 'bb'])
And this is tightly connected with the construction of the derived-term automaton.
r.derived_term()
The "breaking" derivation "splits" the polynomial at the end.
r = q.expression('[ab](<2>[ab])', 'associative')
r
r.derivation('a')
r.derivation('a', True)
r.derivation('a').split()
Again, this is tightly connected with both flavors of the derived-term automaton.
r.derived_term()
r.derived_term('breaking_derivation')