Compute the star normal form of a (Boolean) expression: an equivalent expression where the star operator is applied only on proper expressions (i.e., expressions whose constant term is null).
Preconditions:
Postconditions:
See also:
Caveat:
exp
.standard().expression()
.The following function allows to display nicely expressions and their star-normal form.
In [1]:
import vcsn
from IPython.display import Latex
def snf(*rs):
eqs = []
for r in rs:
r = vcsn.b.expression(r)
eqs.append(r'{r} &\Rightarrow {snf}'
.format(r = r.format('latex'),
snf = r.star_normal_form().format('latex')))
return Latex(r'''\begin{{aligned}}
{eqs}
\end{{aligned}}'''.format(eqs = r'\\'.join(eqs)))
In [2]:
snf('a**', 'a?{+}', '(a+b*)*', '(a*+b*)*', '(ab)*', '(ab?)*', '(a?b?)*', '(a*b*c*)**')
Out[2]:
Of course, expressions already in star-normal form are returned unmodified.
In [3]:
snf('a*', '(a+b+c)*')
Out[3]:
An expression and its star-normal form have the same standard automaton.
In [4]:
r = vcsn.b.expression('(a*b*)*')
r.standard()
Out[4]:
In [5]:
r.star_normal_form().standard()
Out[5]: