home *** CD-ROM | disk | FTP | other *** search
/ Math Solutions 1995 October / Math_Solutions_CD-ROM_Walnut_Creek_October_1995.iso / pc / mac / discrete / doc / rational.tex < prev    next >
Encoding:
Text File  |  1993-05-05  |  9.3 KB  |  262 lines

  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%
  3. %A  rational.tex                GAP documentation            Martin Schoenert
  4. %%
  5. %A  @(#)$Id: rational.tex,v 3.6 1993/02/19 10:48:42 gap Exp $
  6. %%
  7. %Y  Copyright 1990-1992,  Lehrstuhl D fuer Mathematik,  RWTH Aachen,  Germany
  8. %%
  9. %%  This file describes the rational datatype,  its operations and functions.
  10. %%
  11. %H  $Log: rational.tex,v $
  12. %H  Revision 3.6  1993/02/19  10:48:42  gap
  13. %H  adjustments in line length and spelling
  14. %H
  15. %H  Revision 3.5  1992/04/06  16:40:34  martin
  16. %H  fixed some more typos
  17. %H
  18. %H  Revision 3.4  1992/04/02  21:06:23  martin
  19. %H  changed *domain functions* to *set theoretic functions*
  20. %H
  21. %H  Revision 3.3  1992/03/19  15:57:34  martin
  22. %H  renamed chapter "Number Fields" to "Subfields of Cyclotomic Fields"
  23. %H
  24. %H  Revision 3.2  1991/12/27  16:07:04  martin
  25. %H  revised everything for GAP 3.1 manual
  26. %H
  27. %H  Revision 3.1  1991/07/25  16:16:59  martin
  28. %H  fixed some minor typos
  29. %H
  30. %H  Revision 3.0  1991/04/11  11:33:12  martin
  31. %H  Initial revision under RCS
  32. %H
  33. %%
  34. \Chapter{Rationals}%
  35. \index{type!rationals}
  36.  
  37. The *rationals*  form  a very important field.  On the one hand it is the
  38. quotient field of the integers (see "Integers").  On the other hand it is
  39. the prime field of the fields of characteristic zero  (see "Subfields  of
  40. Cyclotomic Fields").
  41.  
  42. The former comment suggests the representation actually used.  A rational
  43. is  represented   as   a   pair   of  integers,  called  *numerator*  and
  44. *denominator*.   Numerator  and  denominator are  *reduced*, i.e.,  their
  45. greatest common divisor is 1.  If  the denominator  is 1, the rational is
  46. in fact an integer and is represented as such.   The numerator holds  the
  47. sign of the rational, thus the denominator is always positive.
  48.  
  49. Because the underlying integer arithmetic can compute with arbitrary size
  50. integers, the  rational arithmetic is  always  exact, even  for rationals
  51. whose numerators and denominators have thousands of digits.
  52.  
  53. |    gap> 2/3;
  54.     2/3
  55.     gap> 66/123;
  56.     22/41    # numerator and denominator are made relatively prime
  57.     gap> 17/-13;
  58.     -17/13    # the numerator carries the sign
  59.     gap> 121/11;
  60.     11    # rationals with denominator 1 (after cancelling) are integers|
  61.  
  62. The first sections of  this chapter  describe  the  functions  that  test
  63. whether an object  is a rational (see "IsRat"), and select the  numerator
  64. and denominator of a rational (see "Numerator", "Denominator").
  65.  
  66. The next sections describe  the rational operations (see "Comparisons  of
  67. Rationals", and "Operations for Rationals").
  68.  
  69. The {\GAP} object 'Rationals' is the field domain  of all rationals.  All
  70. set  theoretic  functions  are applicable  to  this  domain (see  chapter
  71. "Domains"  and "Set  Functions for  Rationals").  Since 'Rationals' is  a
  72. field all  field  functions are also  applicable  to this domain  and its
  73. elements (see chapter "Fields" and "Field Functions for Rationals").
  74.  
  75. All external functions are defined in the file '\"LIBNAME/rational.g\"'.
  76.  
  77. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  78. \Section{IsRat}%
  79. \index{test!for a rational}
  80.  
  81. 'IsRat( <obj> )'
  82.  
  83. 'IsRat' returns 'true' if <obj>,  which can be  an arbitrary object, is a
  84. rational and 'false' otherwise.   Integers are rationals with denominator
  85. 1,   thus 'IsRat' returns  'true' for  integers.   'IsRat' will signal an
  86. error if <obj> is an unbound variable or a procedure call.
  87.  
  88. |    gap> IsRat( 2/3 );
  89.     true
  90.     gap> IsRat( 17/-13 );
  91.     true
  92.     gap> IsRat( 11 );
  93.     true
  94.     gap> IsRat( IsRat );
  95.     false    # 'IsRat' is a function, not a rational |
  96.  
  97. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  98. \Section{Numerator}%
  99. \index{numerator!of a rational}
  100.  
  101. 'Numerator( <rat> )'
  102.  
  103. 'Numerator'  returns  the numerator of the rational <rat>.   Because  the
  104. numerator holds the sign of the rational it may be any integer.  Integers
  105. are rationals  with  denominator  1, thus  'Numerator'  is  the  identity
  106. function for integers.
  107.  
  108. |    gap> Numerator( 2/3 );
  109.     2
  110.     gap> Numerator( 66/123 );
  111.     22    # numerator and denominator are made relatively prime
  112.     gap> Numerator( 17/-13 );
  113.     -17    # the numerator holds the sign of the rational
  114.     gap> Numerator( 11 );
  115.     11    # integers are rationals with denominator 1 |
  116.  
  117. 'Denominator' (see "Denominator") is the counterpart to 'Numerator'.
  118.  
  119. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  120. \Section{Denominator}%
  121. \index{denominator!of a rational}
  122.  
  123. 'Denominator( <rat> )'
  124.  
  125. 'Denominator' returns the denominator of the rational <rat>.  Because the
  126. numerator  holds the  sign of  the rational  the denominator  is always a
  127. positive integer.   Integers are rationals  with  the denominator 1, thus
  128. 'Denominator' returns 1 for integers.
  129.  
  130. |    gap> Denominator( 2/3 );
  131.     3
  132.     gap> Denominator( 66/123 );
  133.     41    # numerator and denominator are made relatively prime
  134.     gap> Denominator( 17/-13 );
  135.     13    # the denominator holds the sign of the rational
  136.     gap> Denominator( 11 );
  137.     1    # integers are rationals with denominator 1 |
  138.  
  139. 'Numerator' (see "Numerator") is the counterpart to 'Denominator'.
  140.  
  141. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  142. \Section{Comparisons of Rationals}%
  143. \index{comparisons!of rationals}
  144.  
  145. '<q1> = <q2>' \\
  146. '<q1> \<> <q2>'
  147.  
  148. The  equality operator '=' evaluates to  'true' if the two rationals <q1>
  149. and <q2> are  equal  and to 'false'  otherwise.  The  inequality operator
  150. '\<>' evaluates to   'true' if the  two rationals  <q1> and  <q2> are not
  151. equal and to 'false' otherwise.
  152.  
  153. |    gap> 2/3 = -4/-6;
  154.     true
  155.     gap> 66/123 <> 22/41;
  156.     false
  157.     gap> 17/13 = 11;
  158.     false |
  159.  
  160. '<q1> \<\ <q2>' \\
  161. '<q1> \<= <q2>' \\
  162. '<q1> > <q2>'   \\
  163. '<q1> >= <q2>'
  164.  
  165. The operators  '\<',  '\<=', '>',  and  '=>' evaluate  to  'true' if  the
  166. rational  <q1> is  less  than, less than or equal to,  greater than,  and
  167. greater than or equal to the rational <q2> and to 'false' otherwise.
  168.  
  169. One rational $q_1 = n_1/d_1$ is less than  another $q_2 = n_2/d_2$ if and
  170. only if  $n_1 d_2 \< n_2 d_2$.  This  definition is of  course only valid
  171. because the  denominator of rationals  is always  defined to be positive.
  172. This   definition   also extends   to the comparison   of  rationals with
  173. integers, which are   interpreted   as  rationals with    denominator  1.
  174. Rationals can also  be compared  with objects of  other  types.  They are
  175. smaller than objects of any other type by definition.
  176.  
  177. |    gap> 2/3 < 22/41;
  178.     false
  179.     gap> -17/13 < 11;
  180.     true |
  181.  
  182. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  183. \Section{Operations for Rationals}%
  184. \index{operations!for rationals}
  185.  
  186. '<q1> + <q2>'   \\
  187. '<q1> - <q2>'   \\
  188. '<q1> \*\ <q2>' \\
  189. '<q1> / <q2>'
  190.  
  191. The operators '+',  '-',  '\*' and '/' evaluate to the  sum,  difference,
  192. product, and  quotient  of  the  two  rationals  <q1>  and <q2>.  For the
  193. quotient  '/'  <q2>  must of course be  nonzero, otherwise  an  error  is
  194. signalled.   Either  operand  may  also  be  an  integer  <i>,  which  is
  195. interpreted  as a  rational  with  denominator  1.   The result of  those
  196. operations is always reduced.  If, after  the  reduction, the denominator
  197. is 1, the rational is in fact an integer, and is represented as such.
  198.  
  199. |    gap> 2/3 + 4/5;
  200.     22/15
  201.     gap> 7/6 * 2/3;
  202.     7/9    # note how the result is cancelled
  203.     gap> 67/6 - 1/6;
  204.     11    # the result is an integer |
  205.  
  206. '<q> \^\ <i>'
  207.  
  208. The powering operator '\^' returns the <i>-th power  of the rational <q>.
  209. <i> must  be an integer.   If the  exponent <i>  is  zero, '<q>\^<i>'  is
  210. defined as 1; if <i>  is positive, '<q>\^<i>' is  defined as the <i>-fold
  211. product '<q>\*<q>\*..\*<q>'; finally, if  <i> is negative, '<q>\^<i>'  is
  212. defined as '(1/<q>)\^-<i>'.  In this case <q> must of course be nonzero.
  213.  
  214. |    gap> (2/3) ^ 3;
  215.     8/27
  216.     gap> (-17/13) ^ -1;
  217.     -13/17    # note how the sign switched
  218.     gap> (1/2) ^ -2;
  219.     4 |
  220.  
  221. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  222. \Section{Set Functions for Rationals}%
  223.  
  224. As  was already mentioned in the introduction of this  chapter the {\GAP}
  225. object 'Rationals' is the  domain of all  rationals.  All  set  theoretic
  226. functions,  e.g.,  'Intersection'  and  'Size',  are  applicable to  this
  227. domain.
  228.  
  229. |    gap> Intersection( Rationals, [ E(4)^0, E(4)^1, E(4)^2, E(4)^3 ] );
  230.     [ -1, 1 ]    # 'E(4)' is the complex square root of -1
  231.     gap> Size( Rationals );
  232.     "infinity" |
  233.  
  234. This does not seem to be very useful.
  235.  
  236. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  237. \Section{Field Functions for Rationals}%
  238.  
  239. As was already mentioned  in the introduction  of this chapter the {\GAP}
  240. object 'Rationals'  is the field of all  rationals.  All field functions,
  241. e.g., 'Norm' and 'MinPol' are applicable to this domain and its elements.
  242. However, since  the field of  rationals  is the  prime  field, all  those
  243. functions are trivial.  Therefore, 'Conjugates( Rationals, <q> )' returns
  244. '[ <q> ]', 'Norm( Rationals, <q> )' and 'Trace(  Rationals, <q> )' return
  245. <q>, and 'CharPol( Rationals, <q> )' and  'MinPol( Rationals, <q> )' both
  246. return '[ -<q>, 1 ]'.
  247.  
  248. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  249. %%
  250. %E  Emacs . . . . . . . . . . . . . . . . . . . . . local Emacs variables
  251. %%
  252. %%  Local Variables:
  253. %%  mode:               outline
  254. %%  outline-regexp:     "\\\\Chapter\\|\\\\Section"
  255. %%  fill-column:        73
  256. %%  eval:               (hide-body)
  257. %%  End:
  258. %%
  259.  
  260.  
  261.  
  262.