<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 expression.derivation(label,breaking=False)
Compute the derivation of a weighted expression.
Arguments
Step1:  Classical expressions
In the classical case (labels are letters, and weights are Boolean), this is the construct as described by Antimirov.
Step2:  Or, using the diffs function we defined above
Step3:  Weighted Expressions
Of course, expressions can be weighted.
Step4:  And this is tightly connected with the construction of the derived-term automaton.
Step5:  Breaking derivation
The "breaking" derivation "splits" the polynomial at the end.
Step6:  Again, this is tightly connected with both flavors of the derived-term automaton.
<ASSISTANT_TASK:>
Python Code:
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)))
Explanation: 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:
- expression.derived_term
- expression.expansion
- polynomial.split
References:
- lombardy.2005.tcs defines the derivation
- angrand.2010.jalc defines the breaking derivation
Examples
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.
End of explanation
b = vcsn.context('lal_char(ab), b')
r = b.expression('[ab]{3}')
r.derivation('a')
Explanation: Classical expressions
In the classical case (labels are letters, and weights are Boolean), this is the construct as described by Antimirov.
End of explanation
diffs(r, ['a', 'aa', 'aaa', 'aaaa'])
Explanation: Or, using the diffs function we defined above:
End of explanation
q = vcsn.context('lal_char(abc), q')
r = q.expression('(<1/6>a*+<1/3>b*)*')
diffs(r, ['a', 'aa', 'ab', 'b', 'ba', 'bb'])
Explanation: Weighted Expressions
Of course, expressions can be weighted.
End of explanation
r.derived_term()
Explanation: And this is tightly connected with the construction of the derived-term automaton.
End of explanation
r = q.expression('[ab](<2>[ab])', 'associative')
r
r.derivation('a')
r.derivation('a', True)
r.derivation('a').split()
Explanation: Breaking derivation
The "breaking" derivation "splits" the polynomial at the end.
End of explanation
r.derived_term()
r.derived_term('breaking_derivation')
Explanation: Again, this is tightly connected with both flavors of the derived-term automaton.
End of explanation
<END_TASK>