context
.random_expression(specs,
identities
="default")
¶Generate a random rational expression.
Arguments:
specs
: string list operators of the generated expression, with associated densities (1 by default). The maximum length can also be set with length
(6 by default).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 "*
" has a probability of 1/2.
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'))