
% 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.


%%
%% pfr.htex
%%

A {\it partial fraction} is a decomposition of a quotient into
\index{partial fraction}
a sum
\index{fraction!partial}
of quotients where the denominators of the summands are powers of
primes.\footnote{Most people first encounter partial fractions when they
are learning integral calculus.
For a technical discussion of partial fractions, see, for example, Lang's {\it
Algebra.}} For example, the rational number \spad{1/6} is decomposed into
\spad{1/2 -1/3}.
You can compute partial fractions of quotients of objects from domains
belonging to the category \spadtype{EuclideanDomain}.
For example, \spadtype{Integer}, \spadtype{Complex Integer}, and
\spadtype{UnivariatePolynomial(x, Fraction Integer)} all belong to
\spadtype{EuclideanDomain}.
In the examples following, we demonstrate how to decompose quotients of
each of these kinds of object into partial fractions.
Issue the system command
\spadcmd{)show PartialFraction}
to display the full list of operations defined by \spadtype{PartialFraction}.

It is necessary that we know how to factor the denominator when we want to
compute a partial fraction.
Although the interpreter can often do this automatically, it may be
necessary for you to include a call to \spadfun{factor}.
In these examples, it is not necessary to factor the
denominators explicitly.
%
\xtc{
The main operation for computing partial fractions is called
\spadfunFrom{partialFraction}{PartialFraction} and we use this to
compute a decomposition of \spad{1 / 10!}.
The first argument to \spadfunFrom{partialFraction}{PartialFraction} is
the numerator of the quotient and the second argument is the factored
denominator.
}{
\spadcommand{partialFraction(1,factorial 10) \bound{prev1}}
}
\xtc{
Since the denominators are powers of primes, it may be possible
to expand the numerators further with respect to those primes. Use the
operation \spadfunFrom{padicFraction}{PartialFraction} to do this.
}{
\spadcommand{f := padicFraction(\%) \free{prev1}\bound{f}}
}
%
%
\xtc{
The operation \spadfunFrom{compactFraction}{PartialFraction} returns an
expanded fraction into the usual form.
The compacted version is used internally for computational efficiency.
}{
\spadcommand{compactFraction(f) \free{f}}
}
%
\xtc{
You can add, subtract, multiply
and divide partial fractions.  In addition, you can extract the parts
of the decomposition.
\spadfunFrom{numberOfFractionalTerms}{PartialFraction} computes
the number of terms in the fractional part.
This does not include the whole part of the fraction,
which you get by calling \spadfunFrom{wholePart}{PartialFraction}.
In this example, the whole part is just \spad{0}.
}{
\spadcommand{numberOfFractionalTerms(f) \free{f}}
}
\xtc{
The operation
\spadfunFrom{fractionalTerms}{PartialFraction} returns the individual terms
in the decomposition.
Notice that the object returned is a list of
\spadtype{Record(num : R, den : Factored(R))}, you can extract the numerator
and denominator from this object.
}{
\spadcommand{fractionalTerms(f).3 \free{f}}
}
%

%
\xtc{
Given two gaussian integers (see \xmpref{Complex}), you can
decompose their quotient into a partial fraction.
}{
\spadcommand{partialFraction(1,- 13 + 14 * \%i) \bound{prev2}}
}
%
\xtc{
To convert back to a quotient, simply use a conversion.
}{
\spadcommand{\% :: Fraction Complex Integer \free{prev2}}
}

To conclude this section, we compute the decomposition of
\texht{\narrowDisplay{1 \over {{(x + 1)}{(x + 2)}^2{(x + 3)}^3{(x + 4)}^4}}}{
\begin{verbatim}
                   1
     -------------------------------
                   2       3       4
     (x + 1)(x + 2) (x + 3) (x + 4)
\end{verbatim}
}
The polynomials in this object have type
\spadtype{UnivariatePolynomial(x, Fraction Integer)}.
%
\xtc{
We use the \spadfunFrom{primeFactor}{Factored} operation (see
\xmpref{Factored}) to create the denominator in factored form directly.
}{
\spadcommand{u : FR UP(x, FRAC INT) := reduce(*,[primeFactor(x+i,i) for i in 1..4]) \bound{u}}
}
%
%
\xtc{
These are the compact and expanded partial fractions for the quotient.
}{
\spadcommand{partialFraction(1,u) \free{u}\bound{prev3}}
}
\xtc{
}{
\spadcommand{padicFraction \% \free{prev3}}
}

All see \xmpref{FullPartialFractionExpansion} for examples of
factor-free conversion of quotients to full partial fractions.
