context
.random_expression(specs, length=6, identities="default")
¶Generate a random rational expression.
Arguments:
specs
: string list operators of the generated expression, with associated densities (1 by default).length
: the maximum length.identities
: the identities of the resulting expressionThe list of every operators:
\\e
, \\z
!
(prefix), {c}
, *
&
, &:
, :
, .
, <+
, %
, +
, {/}
, {\\}
, {T}
See also:
import os
# This trick ensures that we always use the same random seed,
# hence running this documentation always gives the same result.
os.environ['VCSN_SEED'] = '1'
import vcsn
from IPython.display import display
ctx = vcsn.context('lal_char(abc), b')
Densities are expressed with Bernoulli distribution if the operator is the only one, and discrete distribution otherwise.
Here "+
" is twice more likely to appear than ".
", and "*
" twice less.
for _ in range(3):
display(ctx.random_expression('+=2,.=1,*=0.5'))
for _ in range(3):
display(ctx.random_expression('.=2,+=2,&=1,*=0.5', length=20, identities='none'))