expression.is_valid

Whether all the starred sub-expressions have a constant-term that admits a star value.

Postconditions:

  • expression.constant_term does not throw an exception.

See also:

Examples

The following funtion will help display the result of is_valid.

In [1]:
import vcsn
from IPython.display import Latex

def valid(ctx, *rs):
    eqs = []
    for r in rs:
        r = ctx.expression(r)
        eqs.append(r'{0} &: \mathrm{{{1}}}'
                   .format(r.format('latex'),
                           "valid" if r.is_valid() else "invalid"))
    return Latex(r'''\begin{{aligned}}
        {0}
    \end{{aligned}}'''.format(r'\\'.join(eqs)))

In $\mathbb{B}$ all the values have a star-power, so expressions are always valid.

In [2]:
b = vcsn.context('lal_char(ab), b')
valid(b, '\e*')
Out[2]:
\begin{aligned} {\varepsilon}^{*} &: \mathrm{valid} \end{aligned}

In $\mathbb{Z}$, $0$ is the only weight that admits a star.

In [3]:
z = vcsn.context('lal_char(ab), z')
valid(z, '(<0>\e)*', '(<1>\e)*', '(<42>\e)*')
Out[3]:
\begin{aligned} \varepsilon &: \mathrm{valid}\\{\varepsilon}^{*} &: \mathrm{invalid}\\\left( \left\langle 42 \right\rangle \,\varepsilon\right)^{*} &: \mathrm{invalid} \end{aligned}

In $\mathbb{Q}$ (and $\mathbb{R}$), only weights $w$ such that $|w| < 1$ admit a star.

In [4]:
q = vcsn.context('lal_char(ab), q')
valid(q, '(<1/2>\e)*', '(<99/100>\e)*', '(<-99/100>\e)*', '(<101/100>\e)*', '(<-101/100>\e)*')
Out[4]:
\begin{aligned} \left( \left\langle \frac{1}{2} \right\rangle \,\varepsilon\right)^{*} &: \mathrm{valid}\\\left( \left\langle \frac{99}{100} \right\rangle \,\varepsilon\right)^{*} &: \mathrm{valid}\\\left( \left\langle \frac{-99}{100} \right\rangle \,\varepsilon\right)^{*} &: \mathrm{valid}\\\left( \left\langle \frac{101}{100} \right\rangle \,\varepsilon\right)^{*} &: \mathrm{invalid}\\\left( \left\langle \frac{-101}{100} \right\rangle \,\varepsilon\right)^{*} &: \mathrm{invalid} \end{aligned}