RandomTools Flavor: rational - Maple Programming Help

Home : Support : Online Help : Programming : Random Objects : RandomTools package : Flavors : RandomTools/flavor/rational

RandomTools Flavor: rational

describe a flavor of a random rational number

 Calling Sequence rational rational(opts)

Parameters

 opts - equation(s) of the form option = value where option is one of range, character, or denominator; specify options for the random rational number

Description

 • The flavor rational describes a random rational number in a particular range.
 To describe a flavor of a random rational number, use either rational or rational(opts) (where opts is described following) as the argument to RandomTools[Generate] or as part of a structured flavor.
 • By default, the flavor rational describes a random rational number in the range $-1..1$, inclusive, with a denominator that is a factor of $499999999994$.
 • You can modify the properties of a random rational number by using the rational(opts) form of this flavor. The opts argument can contain one or more of the following equations.
 range = a..b
 This option describes the range from which the random rational number is chosen. The endpoints must be of type rational and they describe a random rational number in the interval $a..b$. The inclusiveness of a and b are determined by the character option.
 If the left-hand endpoint of the range is greater than the right-hand endpoint, an exception is raised.
 character = boundary definition
 This option specifies whether to include the endpoints of the range from which the random rational number is chosen. Six boundary definitions are valid: open, closed, open..open, open..closed, closed..open, and closed..closed. The default value for this option is open.
 The definitions open and closed are abbreviations for open..open and closed..closed, respectively.
 denominator = posint
 This option specifies the positive integer to use as the denominator for the random rational number that is generated.
 The default denominator for a rational flavor is related to $999999999989$. (It depends on whether the endpoints are open or closed and the length of the interval.) The default denominator is $499999999994$.
 In the case of the closed interval $-1..1$, the denominator has only $4$ factors ($2$, $11$, $124847$, $182041$) only two of which are under $100000$. Therefore, a result of $\frac{1}{3}$ cannot occur. Instead, you can specify a denominator that is highly composite. For example, $720720$.

Examples

 > $\mathrm{with}\left(\mathrm{RandomTools}\right):$
 > $\mathrm{Generate}\left(\mathrm{rational}\right)$
 ${-}\frac{{104281139459}}{{499999999994}}$ (1)
 > $\mathrm{Generate}\left(\mathrm{rational}\left(\mathrm{range}=-2..5\right)\right)$
 $\frac{{1112405903299}}{{249999999997}}$ (2)
 > $\mathrm{Generate}\left(\mathrm{rational}\left(\mathrm{range}=-5..\frac{1}{2},\mathrm{denominator}=720720\right)\right)$
 ${-}\frac{{691783}}{{144144}}$ (3)
 > $\mathrm{Generate}\left(\mathrm{rational}\left(\mathrm{denominator}=10\right)\right)$
 ${-}\frac{{2}}{{5}}$ (4)
 > $\mathrm{sort}\left(\left[\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{rational}\left(\mathrm{denominator}=6,\mathrm{character}=\mathrm{open}..\mathrm{closed}\right)\right),i=1..10\right)\right],'\mathrm{numeric}'\right)$
 $\left[{-}\frac{{5}}{{6}}{,}{-}\frac{{2}}{{3}}{,}{-}\frac{{1}}{{3}}{,}{-}\frac{{1}}{{6}}{,}{-}\frac{{1}}{{6}}{,}{0}{,}\frac{{1}}{{3}}{,}\frac{{5}}{{6}}{,}\frac{{5}}{{6}}{,}{1}\right]$ (5)
 > $\mathrm{Generate}\left(\mathrm{list}\left(\mathrm{rational}\left(\mathrm{range}=\frac{7}{2}..\frac{13}{2}\right),10\right)\right)$
 $\left[\frac{{1617959967603}}{{249999999997}}{,}\frac{{2444607189245}}{{499999999994}}{,}\frac{{2523012980003}}{{499999999994}}{,}\frac{{1240308146463}}{{249999999997}}{,}\frac{{1856507053637}}{{499999999994}}{,}\frac{{2146412722983}}{{499999999994}}{,}\frac{{89133474041}}{{22727272727}}{,}\frac{{227279279289}}{{45454545454}}{,}\frac{{1589678109779}}{{249999999997}}{,}\frac{{107533275874}}{{22727272727}}\right]$ (6)
 > $\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{rational}\left(\mathrm{range}=0..7,\mathrm{denominator}=720720\right)\right),i=1..10\right)$
 $\frac{{4238413}}{{720720}}{,}\frac{{857911}}{{360360}}{,}\frac{{1074583}}{{180180}}{,}\frac{{430957}}{{240240}}{,}\frac{{886631}}{{360360}}{,}\frac{{579803}}{{102960}}{,}\frac{{91609}}{{102960}}{,}\frac{{913459}}{{720720}}{,}\frac{{39779}}{{180180}}{,}\frac{{972275}}{{144144}}$ (7)
 > $\mathrm{Matrix}\left(3,3,\mathrm{Generate}\left(\mathrm{rational}\left(\mathrm{denominator}=24\right)\mathrm{identical}\left(x\right)+\mathrm{rational}\left(\mathrm{denominator}=16\right),\mathrm{makeproc}=\mathrm{true}\right)\right)$
 $\left[\begin{array}{ccc}\frac{{2}}{{3}}{}{x}{+}\frac{{5}}{{8}}& {-}\frac{{7}}{{8}}{}{x}{+}\frac{{1}}{{16}}& {-}\frac{{7}}{{8}}{}{x}{-}\frac{{11}}{{16}}\\ \frac{{13}}{{24}}{}{x}{-}\frac{{3}}{{8}}& \frac{{1}}{{12}}{}{x}{-}\frac{{3}}{{8}}& \frac{{1}}{{8}}{}{x}{-}\frac{{7}}{{8}}\\ {-}\frac{{2}}{{3}}{}{x}{+}\frac{{1}}{{4}}& \frac{{23}}{{24}}{}{x}{-}\frac{{7}}{{8}}& {-}\frac{{5}}{{8}}{}{x}{+}\frac{{5}}{{16}}\end{array}\right]$ (8)