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

expression.constant_term()

Compute the "constant term" of an expression, i.e., the weight associated with the empty word.

Preconditions:

  • The expression is valid

Algorithm:

  • Based on a simple bottom-up traversal of the tree of the expression: ParseError: KaTeX parse error: \newcommand{\bra} attempting to redefine \bra; use \renewcommand

See also:

Examples

The following function allows to display nicely expressions and their constant term.

import vcsn from IPython.display import Latex def c(*es): eqs = [] for e in es: e = vcsn.Q.expression(e) eqs.append(r'{e:x} &\Rightarrow {c:x}' .format(e=e, c=e.constant_term())) return Latex(r'''\begin{{aligned}} {eqs} \end{{aligned}}'''.format(eqs=r'\\'.join(eqs)))
c('a', r'\e', r'<2>\e', 'a*', '(<1/6>a)*', '<1/6>a*', '<1/6>a*+<1/3>b*', '(<1/6>a*+<1/3>b*)*')
a0ε12ε2a1(16a)116a1616a+13b12(16a+13b)2\begin{aligned} a &\Rightarrow 0\\\varepsilon &\Rightarrow 1\\ \left\langle 2 \right\rangle \,\varepsilon &\Rightarrow 2\\{a}^{*} &\Rightarrow 1\\\left( \left\langle \frac{1}{6} \right\rangle \,a\right)^{*} &\Rightarrow 1\\ \left\langle \frac{1}{6} \right\rangle \,{a}^{*} &\Rightarrow \frac{1}{6}\\ \left\langle \frac{1}{6} \right\rangle \,{a}^{*} + \left\langle \frac{1}{3} \right\rangle \,{b}^{*} &\Rightarrow \frac{1}{2}\\\left( \left\langle \frac{1}{6} \right\rangle \,{a}^{*} + \left\langle \frac{1}{3} \right\rangle \,{b}^{*}\right)^{*} &\Rightarrow 2 \end{aligned}