 structured - Maple Help

Structured Flavors in Maple Description

 • 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 $\left[\mathrm{integer},\mathrm{integer}\right]$. 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] (***) | foo(flavor*) 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. Examples

 > $\mathrm{with}\left(\mathrm{RandomTools}\right):$

Maple generates a list with two elements: an integer in the range $3..10$, and a rational in the same range with denominator 13.

 > $\mathrm{Generate}\left(\left[\mathrm{integer}\left(\mathrm{range}=3..10\right),\mathrm{rational}\left(\mathrm{range}=3..10,\mathrm{denominator}=13\right)\right]\right)$
 $\left[{7}{,}\frac{{84}}{{13}}\right]$ (1)

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.

 > $\mathrm{Generate}\left(f\left(\mathrm{integer}\left(\mathrm{range}=3..10\right),\mathrm{rational}\left(\mathrm{range}=3..10,\mathrm{denominator}=17\right)\right)\right)$
 ${f}{}\left({10}{,}\frac{{57}}{{17}}\right)$ (2)

In this case, we generate a function call to the function $\mathrm{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.

 > $\mathrm{Generate}\left('\mathrm{Array}'\left(\mathrm{negint}\left(\mathrm{range}=-10\right)..\mathrm{posint}\left(\mathrm{range}=10\right)\right)\right)$ 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 $\mathrm{posint}\left(\mathrm{range}=6\right)+\mathrm{posint}\left(\mathrm{range}=6\right)$ but Maple automatically simplifies that to $2\mathrm{posint}\left(\mathrm{range}=6\right)$ 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.

 > $\mathrm{Generate}\left(\mathrm{list}\left(\mathrm{posint}\left(\mathrm{range}=6\right)+\mathrm{posint}\left(\mathrm{range}=6\right),20\right)\right)$
 $\left[{12}{,}{10}{,}{6}{,}{2}{,}{10}{,}{4}{,}{6}{,}{4}{,}{4}{,}{8}{,}{6}{,}{6}{,}{2}{,}{4}{,}{10}{,}{8}{,}{10}{,}{12}{,}{4}{,}{6}\right]$ (3)

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.

 > $\mathrm{value}\left(\mathrm{Generate}\left(\mathrm{list}\left(\mathrm{%+}\left(\mathrm{posint}\left(\mathrm{range}=6\right),\mathrm{posint}\left(\mathrm{range}=6\right)\right),20\right)\right)\right)$
 $\left[{8}{,}{5}{,}{8}{,}{7}{,}{11}{,}{7}{,}{11}{,}{8}{,}{7}{,}{5}{,}{2}{,}{8}{,}{7}{,}{4}{,}{5}{,}{6}{,}{6}{,}{5}{,}{9}{,}{5}\right]$ (4)