
% Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
%     - Redistributions of source code must retain the above copyright
%       notice, this list of conditions and the following disclaimer.
%
%     - Redistributions in binary form must reproduce the above copyright
%       notice, this list of conditions and the following disclaimer in
%       the documentation and/or other materials provided with the
%       distribution.
%
%     - Neither the name of The Numerical ALgorithms Group Ltd. nor the
%       names of its contributors may be used to endorse or promote products
%       derived from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
% IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
% TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
% OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES-- LOSS OF USE, DATA, OR
% PROFITS-- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
% LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


%

The \spadtype{Fraction} domain implements quotients.
\index{fraction}
The elements must belong to a domain of category \spadtype{IntegralDomain}:
multiplication must be commutative and the product of two non-zero
elements must not be zero.
This allows you to make fractions of most things you would think of,
but don't expect to create a fraction of two matrices!
The abbreviation for \spadtype{Fraction} is \spadtype{FRAC}.

\xtc{
Use \spadopFrom{/}{Fraction} to create a fraction.
}{
\spadcommand{a := 11/12 \bound{a}}
}
\xtc{
}{
\spadcommand{b := 23/24 \bound{b}}
}
\xtc{
The standard arithmetic operations are available.
}{
\spadcommand{3 - a*b^2 + a + b/a \free{a}\free{b}}
}
\xtc{
Extract the numerator and denominator by using
\index{numerator}
\spadfunFrom{numer}{Fraction} and \spadfunFrom{denom}{Fraction},
\index{denominator}
respectively.
}{
\spadcommand{numer(a) \free{a}}
}
\xtc{
}{
\spadcommand{denom(b) \free{b}}
}
Operations like \spadfunFrom{max}{Fraction}, \spadfunFrom{min}{Fraction},
\spadfunFrom{negative?}{Fraction}, \spadfunFrom{positive?}{Fraction} and
\spadfunFrom{zero?}{Fraction} are all available if they are provided for
the numerators and denominators.
See \xmpref{Integer} for examples.

Don't expect a useful answer from \spadfunFrom{factor}{Fraction},
\spadfunFrom{gcd}{Fraction} or \spadfunFrom{lcm}{Fraction} if you apply
them to fractions.
\xtc{
}{
\spadcommand{r := (x^2 + 2*x + 1)/(x^2 - 2*x + 1) \bound{r}}
}
\xtc{
Since all non-zero fractions are invertible, these operations have trivial
definitions.
}{
\spadcommand{factor(r) \free{r}}
}
\xtc{
Use \spadfunFrom{map}{Fraction} to apply \spadfunFrom{factor}{Fraction} to
the numerator and denominator, which is probably what you mean.
}{
\spadcommand{map(factor,r) \free{r}}
}

\xtc{
Other forms of fractions are available.
\index{fraction!continued}
Use \spadfun{continuedFraction} to create a continued fraction.
\index{continued fraction}
}{
\spadcommand{continuedFraction(7/12)}
}
\xtc{
Use \spadfun{partialFraction} to create a partial fraction.
\index{fraction!partial}
See \xmpref{ContinuedFraction} and \xmpref{PartialFraction} for
additional information and examples.
\index{partial fraction}
}{
\spadcommand{partialFraction(7,12)}
}

\xtc{
Use conversion to create alternative views of fractions with objects
moved in and out of the numerator and denominator.
}{
\spadcommand{g := 2/3 + 4/5*\%i \bound{g}}
}
\xtc{
Conversion is discussed in detail in \spadref{ugTypesConvert}.
}{
\spadcommand{g :: FRAC COMPLEX INT \free{g}}
}
