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.
In [1]:
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.
In [2]:
b = vcsn.context('lal_char(ab), b')
r = b.expression('[ab]{3}')
r.derivation('a')
Out[2]:
Or, using the diffs
function we defined above:
In [3]:
diffs(r, ['a', 'aa', 'aaa', 'aaaa'])
Out[3]:
Of course, expressions can be weighted.
In [4]:
q = vcsn.context('lal_char(abc), q')
r = q.expression('(<1/6>a*+<1/3>b*)*')
diffs(r, ['a', 'aa', 'ab', 'b', 'ba', 'bb'])
Out[4]:
And this is tightly connected with the construction of the derived-term automaton.
In [5]:
r.derived_term()
Out[5]:
The "breaking" derivation "splits" the polynomial at the end.
In [6]:
r = q.expression('[ab](<2>[ab])', 'associative')
r
Out[6]:
In [7]:
r.derivation('a')
Out[7]:
In [8]:
r.derivation('a', True)
Out[8]:
In [9]:
r.derivation('a').split()
Out[9]:
Again, this is tightly connected with both flavors of the derived-term automaton.
In [10]:
r.derived_term()
Out[10]:
In [11]:
r.derived_term('breaking_derivation')
Out[11]: