Close
Close window
structured - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.
Maplesoft logo
Maplesoft logo

Online Help

All Products Maple MapleSim


[フレーム] [フレーム]

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 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] (***)

| 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

>

withRandomTools&colon;

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

>

Generateintegerrange=3..10&comma;rationalrange=3..10&comma;denominator=13

7&comma;8413

(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.

>

Generatefintegerrange=3..10&comma;rationalrange=3..10&comma;denominator=17

f10&comma;5717

(2)

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 .

>

GenerateArraynegintrange=10..posintrange=10

0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;⋯ -9 .. 4 Array

(3)

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 2posintrange=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.

>

Generatelistposintrange=6+posintrange=6&comma;20

12&comma;10&comma;6&comma;2&comma;10&comma;4&comma;6&comma;4&comma;4&comma;8&comma;6&comma;6&comma;2&comma;4&comma;10&comma;8&comma;10&comma;12&comma;4&comma;6

(4)

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.

>

valueGeneratelist%+posint`=`range&comma;6&comma;posint`=`range&comma;6&comma;20

8&comma;5&comma;8&comma;7&comma;11&comma;7&comma;11&comma;8&comma;7&comma;5&comma;2&comma;8&comma;7&comma;4&comma;5&comma;6&comma;6&comma;5&comma;9&comma;5

(5)

See Also


Download Help Document

AltStyle によって変換されたページ (->オリジナル) /