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



% lodo1.htex
\spadtype{LinearOrdinaryDifferentialOperator1(A)} is the domain of linear
\index{operator!linear ordinary differential}
ordinary differential operators with coefficients in the differential ring
\spad{A}.
%This includes the cases of operators which are polynomials in \spad{D}
%acting upon scalar or vector expressions of a single variable.
%The coefficients of the operator polynomials can be integers, rational
%functions, matrices or elements of other domains.
\showBlurb{LinearOrdinaryDifferentialOperator1}

\head{subsection}{Differential Operators with Rational Function Coefficients}{ugxLinearOrdinaryDifferentialOperatorOneRat}
% ----------------------------------------------------------------------

This example shows differential operators with rational function
coefficients.  In this case operator multiplication is non-commutative and,
since the coefficients form a field, an operator division algorithm exists.

\labelSpace{2pc}
\xtc{
We begin by defining \spad{RFZ} to be the rational functions in
\spad{x} with integer coefficients and \spad{Dx} to be the differential
operator for \spad{d/dx}.
}{
\spadcommand{RFZ := Fraction UnivariatePolynomial('x, Integer) \bound{RFZ0}}
}
\xtc{
}{
\spadcommand{x : RFZ := 'x \free{RFZ0}\bound{RFZ}}
}
\xtc{
}{
\spadcommand{Dx : LODO1 RFZ := D()\bound{Dx}\free{RFZ}}
}
\xtc{
Operators are created using the usual arithmetic operations.
}{
\spadcommand{b : LODO1 RFZ := 3*x^2*Dx^2 + 2*Dx + 1/x  \free{Dx}\bound{b}}
}
\xtc{
}{
\spadcommand{a : LODO1 RFZ := b*(5*x*Dx + 7)             \free{b Dx}\bound{a}}
}
\xtc{
Operator multiplication corresponds to functional composition.
}{
\spadcommand{p := x^2 + 1/x^2 \bound{p}\free{RFZ}}
}
\xtc{
Since operator coefficients depend on \spad{x}, the multiplication is
not commutative.
}{
\spadcommand{(a*b - b*a) p \free{a b p}}
}

When the coefficients of operator polynomials come from a field, as in this
case, it is possible to define operator division.
Division on the left and division on the right yield different results when
the multiplication is non-commutative.

The results of \spadfunFrom{leftDivide}{LinearOrdinaryDifferentialOperator1} and
\spadfunFrom{rightDivide}{LinearOrdinaryDifferentialOperator1} are
quotient-remainder pairs satisfying: \newline
%
\spad{leftDivide(a,b) = [q, r]} such that  \spad{a = b*q + r} \newline
\spad{rightDivide(a,b) = [q, r]} such that  \spad{a = q*b + r} \newline
%
\xtc{
In both cases, the \spadfunFrom{degree}{LinearOrdinaryDifferentialOperator1}
of the remainder, \spad{r}, is less than
the degree of \spad{b}.
}{
\spadcommand{ld := leftDivide(a,b) \bound{ld}\free{a b}}
}
\xtc{
}{
\spadcommand{a = b * ld.quotient + ld.remainder \free{a b ld}}
}
\xtc{
The operations of left and right division
are so-called because the quotient is obtained by dividing
\spad{a} on that side by \spad{b}.
}{
\spadcommand{rd := rightDivide(a,b) \bound{rd}\free{a b}}
}
\xtc{
}{
\spadcommand{a = rd.quotient * b + rd.remainder \free{a b rd}}
}

\xtc{
Operations \spadfunFrom{rightQuotient}{LinearOrdinaryDifferentialOperator1}
and \spadfunFrom{rightRemainder}{LinearOrdinaryDifferentialOperator1}
are available if only one of the quotient or remainder are of
interest to you.
This is the quotient from right division.
}{
\spadcommand{rightQuotient(a,b) \free{a b}}
}
\xtc{
This is the remainder from right division.
The corresponding ``left'' functions
\spadfunFrom{leftQuotient}{LinearOrdinaryDifferentialOperator1} and
\spadfunFrom{leftRemainder}{LinearOrdinaryDifferentialOperator1}
are also available.
}{
\spadcommand{rightRemainder(a,b) \free{a b}}
}

\xtc{
For exact division, the operations
\spadfunFrom{leftExactQuotient}{LinearOrdinaryDifferentialOperator1} and
\spadfunFrom{rightExactQuotient}{LinearOrdinaryDifferentialOperator1} are supplied.
These return the quotient but only if the remainder is zero.
The call \spad{rightExactQuotient(a,b)} would yield an error.
}{
\spadcommand{leftExactQuotient(a,b) \free{a b}}
}

\xtc{
The division operations allow the computation of left and right greatest
common divisors (\spadfunFrom{leftGcd}{LinearOrdinaryDifferentialOperator1} and
\spadfunFrom{rightGcd}{LinearOrdinaryDifferentialOperator1}) via remainder
sequences, and consequently the computation of left and right least common
multiples (\spadfunFrom{rightLcm}{LinearOrdinaryDifferentialOperator1} and
\spadfunFrom{leftLcm}{LinearOrdinaryDifferentialOperator1}).
}{
\spadcommand{e := leftGcd(a,b) \bound{e}\free{a b}}
}
\xtc{
Note that a greatest common divisor doesn't necessarily divide \spad{a} and
\index{greatest common divisor}
\spad{b} on both sides.
Here the left greatest common divisor does not divide \spad{a} on the right.
}{
\spadcommand{leftRemainder(a, e) \free{a e}}
}
\xtc{
}{
\spadcommand{rightRemainder(a, e) \free{a e}}
}

\xtc{
Similarly, a least common multiple
\index{least common multiple}
is not necessarily divisible from both sides.
}{
\spadcommand{f := rightLcm(a,b) \bound{f}\free{a b}}
}
\xtc{
}{
\spadcommand{rightRemainder(f, b) \free{f b}}
}
\xtc{
}{
\spadcommand{leftRemainder(f, b) \free{f b}}
}
