Structured Flavors in Maple
Description
Examples
A structured flavor is any Maple expression other than a symbol that can be interpreted as a description of a random flavor. A typical example would be integer,integer. This expression describes a list that contains two elements, each of which is an integer.
Such flavors can be used with the command RandomTools[Generate].
The following table gives a formal grammatical description of the valid structured flavors in Maple. The table uses the following notation: "::=" means "is defined to be", "|" means "or", and "*" means "zero or more occurrences of".
Syntax
Matches
flavor ::=
[ flavor ]
a list of values generated according to the given flavors
| complex(numeric)
generate the given complex numerical constant
| string
generate the given string
| flavor = flavor
an equation where the two sides are generated according to the given flavors
| flavor <> flavor
an inequation where the two sides are generated according to the given flavors
| flavor < flavor
a less-than relation where the two sides are generated according to the given flavors
| flavor <= flavor
a less-than-or-equal relation where the two sides are generated according to the given flavors
| flavor > flavor
a greater-than relation where the two sides are generated according to the given flavors
| flavor >= flavor
a greater-than-or-equal relation where the two sides are generated according to the given flavors
| flavor .. flavor
a range where the two sides are generated according to the given flavors
| flavor and flavor
an and expression where the two sides are generated according to the given flavors
| flavor or flavor
an or expression where the two sides are generated according to the given flavors
| not flavor
a not expression where the argument is generated according to the given flavor
| flavor + flavor
an addition where the operands are generated according to the given flavors (**)
| flavor %+ flavor
an inert addition where the operands are generated according to the given flavors (**)
| flavor * flavor
a multiplication where the operands are generated according to the given flavors (**)
| flavor %* flavor
an inert multiplication where the operands are generated according to the given flavors (**)
| flavor ^ flavor
a power expression where the operands are generated according to the given flavors
| foo(flavor*)
a predefined flavor foo, or a flavor defined by a procedure added with RandomTools[AddFlavor] (***)
the function foo with arguments generated by the given flavors
(*): There can be more than one occurence of these entries in a structured flavor.
(**): For the sum or product flavors, note that you cannot use the same flavor more than once in a sum or product. See the example with the two six-sided dice below.
(***): The predefined flavors are listed in the table below.
choose
complex
distribution
exprseq
float
identical
integer
list
listlist
Matrix
negative
negint
nonnegative
nonnegint
nonposint
nonpositive
nonzero
nonzeroint
polynom
posint
positive
rational
set
string
structured
truefalse
variable
Vector
with⁡RandomTools:
Maple generates a list with two elements: an integer in the range 3..10, and a rational in the same range with denominator 13.
Generate⁡integer⁡range=3..10,rational⁡range=3..10,denominator=13
7,8413
In this case, we instruct Maple to generate the unevaluated function f, with two arguments; the first is an integer in the range 3..10, and the second is a rational in the same range with denominator 17.
Generate⁡f⁡integer⁡range=3..10,rational⁡range=3..10,denominator=17
f⁡10,5717
In this case, we generate a function call to the function Array, with as its arguments a range of which the left and right hand sides are randomly generated. The function call is evaluated when it is returned, yielding an actual Array.
Generate⁡Array⁡negint⁡range=−10..posint⁡range=10
For this example, we try to generate the sum of two independent rolls of a six-sided die. You might try to use the flavor posintrange=6⁢+⁢posintrange=6 but Maple automatically simplifies that to 2⁢posint⁡range=6 before the RandomTools[Generate] command is run. As a consequence, you get a single die roll, multiplied by two. This is shown here by generating a list of 20 such values; note they are all even.
Generate⁡list⁡posint⁡range=6+posint⁡range=6,20
12,10,6,2,10,4,6,4,4,8,6,6,2,4,10,8,10,12,4,6
In such a situation, a better solution is to use inert form operators to specify the flavor, and apply the value command after generating the result to combine the values.
value⁡Generate⁡list⁡`%+`⁡posint⁡`=`⁡range,6,posint⁡`=`⁡range,6,20
8,5,8,7,11,7,11,8,7,5,2,8,7,4,5,6,6,5,9,5
See Also
RandomTools
Download Help Document