set - Maple Help

RandomTools Flavor: set

describe a set of random objects

 Calling Sequence set(flav, n) set(flav, n, opt)

Parameters

 flav - random flavor n - non-negative integer opt - (optional) one or more keyword options of the form keyword = value, where the keyword is either exact or limit

Description

 • The flavor set describes a set containing n entries where the entries of this set are described by the given random flavor flav.
 • By default, the final set can contain fewer than n entries if the same object is generated more than once. If the exact = true option is given, either as the keyword or as the equation exact = true, then a set of exactly n values is returned. For this to succeed, the number of possible values generated by the given flavor has to be at least n. This can be detected reliably for some flavors such as integer or choose, but not for all flavors. The option exact = true can also be specified as just exact; the default can be specified explicitly as exact = false.
 • If Maple cannot detect whether the flavor supports at least n values and the exact option is set to true, then it will try to generate sufficiently many values. However, this may fail. In this situation, if Maple runs a certain limit number of iterations, it will error out. By default, this limit is 100 iterations; it can be set to any positive number using the limit option, or to infinity to disable the limit. If the exact option is not set to true, the limit option is ignored.
 This flavor can be used as an argument to RandomTools[Generate] or as part of a structured flavor.

Examples

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

The following sets have fewer than 10 entries, because some entries were generated twice.

 > $\mathrm{Generate}\left(\mathrm{set}\left(\mathrm{posint}\left(\mathrm{range}=10\right),10\right)\right)$
 $\left\{{1}{,}{2}{,}{4}{,}{5}{,}{6}{,}{7}{,}{8}{,}{10}\right\}$ (1)
 > $\mathrm{Generate}\left(\mathrm{set}\left(\mathrm{rational}\left(\mathrm{denominator}=6\right),10\right)\right)$
 $\left\{{-}\frac{{2}}{{3}}{,}{-}\frac{{1}}{{2}}{,}{-}\frac{{1}}{{3}}{,}\frac{{1}}{{2}}{,}\frac{{1}}{{3}}{,}\frac{{2}}{{3}}{,}\frac{{5}}{{6}}\right\}$ (2)

This is corrected with the exact option.

 > $\mathrm{Generate}\left(\mathrm{set}\left(\mathrm{rational}\left(\mathrm{denominator}=6\right),10,\mathrm{exact}\right)\right)$
 $\left\{{0}{,}{-}\frac{{5}}{{6}}{,}{-}\frac{{2}}{{3}}{,}{-}\frac{{1}}{{2}}{,}{-}\frac{{1}}{{6}}{,}\frac{{1}}{{2}}{,}\frac{{1}}{{3}}{,}\frac{{1}}{{6}}{,}\frac{{2}}{{3}}{,}\frac{{5}}{{6}}\right\}$ (3)

The following will fail, because there are only 11 values that can be generated.

 > $\mathrm{Generate}\left(\mathrm{set}\left(\mathrm{rational}\left(\mathrm{denominator}=6\right),100,\mathrm{exact}\right)\right)$

The following should eventually succeed, because there are 15625 possible lists of the given flavor. However, Maple does not have specialized code to detect this case. Trying to generate almost all possible entries by random chance is likely to take a large number of iterations, so it will most probably fail in this case.

 > $\mathrm{Generate}\left(\mathrm{set}\left(\mathrm{list}\left(\mathrm{integer}\left(\mathrm{range}=1..5\right),6\right),15600,\mathrm{exact}\right)\right)$

If we set the limiting number of iterations sufficiently high, we do get the correct result.

 > $\mathrm{result}≔\mathrm{Generate}\left(\mathrm{set}\left(\mathrm{list}\left(\mathrm{integer}\left(\mathrm{range}=1..5\right),6\right),15600,\mathrm{exact},\mathrm{limit}=\mathrm{\infty }\right)\right):$
 > $\mathrm{numelems}\left(\mathrm{result}\right)$
 ${15600}$ (4)

Compatibility

 • The RandomTools Flavor: set command was updated in Maple 2019.
 • The exact and limit options were introduced in Maple 2019.