Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 5e1854624d3bc613bdd0dd13d1ef9ac7 > files > 3648

gap-system-4.4.12-5mdv2010.0.i586.rpm

% This file was created automatically from rational.msk.
% DO NOT EDIT!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%A  rational.msk                GAP documentation            Martin Schoenert
%%
%A  @(#)$Id: rational.msk,v 1.8 2003/09/05 07:54:50 gap Exp $
%%
%Y  (C) 1998 School Math and Comp. Sci., University of St.  Andrews, Scotland
%Y  Copyright (C) 2002 The GAP Group
%%
\Chapter{Rational Numbers}

The *rationals* form a very important field.  On the one hand it is the
quotient field of the integers (see chapter~"Integers").
On the other hand it is the prime field of the fields of characteristic zero
(see chapter~"Abelian Number Fields").

The former comment suggests the representation actually used.
A rational is represented as a pair of integers, called  *numerator* and
*denominator*.
Numerator and denominator are *reduced*, i.e., their greatest common divisor
is 1.
If the denominator is 1, the rational is in fact an integer and is
represented as such.
The numerator holds the sign of the rational,
thus the denominator is always positive.

Because the underlying integer arithmetic can compute with arbitrary size
integers, the  rational arithmetic is always exact, even for rationals
whose numerators and denominators have thousands of digits.

\beginexample
gap> 2/3;
2/3
gap> 66/123;  # numerator and denominator are made relatively prime
22/41
gap> 17/-13;  # the numerator carries the sign;
-17/13
gap> 121/11;  # rationals with denominator 1 (after cancelling) are integers
11
\endexample

\>`Rationals' V
\>IsRationals( <obj> ) P

`Rationals' is the field $\Q$ of rational integers,
as a set of cyclotomic numbers,
see Chapter~"Cyclotomic Numbers" for basic operations,
Functions for the field `Rationals' can be found in the
chapters~"Fields and Division Rings" and~"Abelian Number Fields".

`IsRationals' returns `true' for a prime field that consists of
cyclotomic numbers --for example the {\GAP} object `Rationals'--
and `false' for all other {\GAP} objects.


\beginexample
gap> Size( Rationals ); 2/3 in Rationals;
infinity
true
\endexample


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Elementary Operations for Rationals}

\>IsRat( <obj> ) C

Every rational number lies in the category `IsRat',
which is a subcategory of `IsCyc' (see~"Cyclotomic Numbers").


\index{test!for a rational}
\beginexample
gap> IsRat( 2/3 );
true
gap> IsRat( 17/-13 );
true
gap> IsRat( 11 );
true
gap> IsRat( IsRat );  # `IsRat' is a function, not a rational
false
\endexample

\>IsPosRat( <obj> ) C

Every positive rational number lies in the category `IsPosRat'.


\>IsNegRat( <obj> ) C

Every negative rational number lies in the category `IsNegRat'.



\>NumeratorRat( <rat> ) F

`NumeratorRat' returns the numerator of the rational <rat>.
Because the numerator holds the sign of the rational it may be any
integer.
Integers are rationals with denominator $1$, thus `NumeratorRat' is the
identity function for integers.


\index{numerator!of a rational}
\beginexample
gap> NumeratorRat( 2/3 );
2
gap> NumeratorRat( 66/123 );  # numerator and denominator are made relatively prime
22
gap> NumeratorRat( 17/-13 );  # the numerator holds the sign of the rational
-17
gap> NumeratorRat( 11 );      # integers are rationals with denominator 1
11
\endexample


\>DenominatorRat( <rat> ) F

`DenominatorRat' returns the denominator of the rational <rat>.
Because the numerator holds the  sign of the rational the denominator is
always a positive integer.
Integers are rationals with the denominator 1, thus `DenominatorRat'
returns 1 for integers.


\index{denominator!of a rational}
\beginexample
gap> DenominatorRat( 2/3 );
3
gap> DenominatorRat( 66/123 );  # numerator and denominator are made relatively prime
41
gap> DenominatorRat( 17/-13 );  # the denominator holds the sign of the rational
13
gap> DenominatorRat( 11 );      # integers are rationals with denominator 1
1
\endexample

\>Rat( <elm> ) A

`Rat' returns a rational number <rat> whose meaning depends on the type
of <elm>.

If <elm> is a string consisting of digits `{'0'}', `{'1'}', $\ldots$,
`{'9'}' and `{'-'}' (at the first position), `{'/'}' and the decimal dot
`{'.'}' then <rat> is the rational described by this string.
The operation `String' (see~"String") can be used to compute a string for
rational numbers, in fact for all cyclotomics.

\beginexample
gap> Rat( "1/2" );  Rat( "35/14" );  Rat( "35/-27" );  Rat( "3.14159" );
1/2
5/2
-35/27
314159/100000
\endexample



\>Random( Rationals )!{for rationals}

`Random' for rationals returns pseudo random rationals which are the
quotient of two random integers. See the description of `Random' for integers
("Random!for integers") for details. (Also see~"Random".)