context
.random_expression(params, length=6, identities="default")
Generate a random rational expression.
Arguments:
params
: string list operators of the generated expression, with associated densities (1 by default).length
: the maximum length (defaults to 6).identities
: the identities of the resulting expression.
Supported operators:
nullary:
\e
,\z
unary:
!
(prefix),{c}
,*
,w.
,.w
binary:
&
,&:
,:
,.
,<+
,%
,+
,{/}
,{\}
,{T}
See also:
Expressions – the documentation about expressions (and identities)
Examples
Densities are expressed with Bernoulli distribution if the operator is the only one, and discrete distribution otherwise.
The default coefficient is 1, therefore in the following example "+
" is twice more likely to appear than ".
", and "*
" is twice less.
Weighted Expressions
Weighted expressions can be generated. Use the keys w.
and .w
to control the probability of left and right product by a weight. Use the key w
to pass parameters to the random weight generator.
Note that because of the identities, some weights might escape the specified range.