
% 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 domain constructor \spadtype{GeneralQuaternion} implements general
quaternions over commutative rings.
For information on related topics, see
%\menuxmpref{CliffordAlgebra}
\xmpref{Quaternion},
\xmpref{Complex} and
\xmpref{Octonion}.
You can also issue the system command
\spadcmd{)show GeneralQuaternion}
to display the full list of operations defined by
\spadtype{GeneralQuaternion}.

\xtc{
To use general quaternions we need to explicitely qualify
calls.  So first we assign initialize domain and assign
it to a variable.
}{
\spadcommand{Q2 := GeneralQuaternion(Fraction(Integer), 2, 3) \bound{Q2}}
}
\xtc{
The basic operation for creating quaternions is
\spadfunFrom{quatern}{GeneralQuaternion}.
}{
\spadcommand{i := quatern(0, 1, 0, 0)$Q2 \bound{i} \free{Q2}}
}
\xtc{
In \spad{GeneralQuaternion(Fraction(Integer), a, b)} squaring
\spad{i} gives \spad{a}.
}{
\spadcommand{i^2 \free{i}}
}
\xtc{
Similarly for \spad{b}.
}{
\spadcommand{( quatern(0, 0, 1, 0)$Q2)^2 \free{Q2}}
}
\xtc{
Yet another quaternion.
}{
\spadcommand{q := quatern(2/11,-8,3/4,1)$Q2 \bound{q} \free{Q2}}
}
\xtc{
Because \spad{q} is over the rationals (and nonzero), you can invert it.
}{
\spadcommand{iq := inv q \bound{iq}\free{q}}
}
\xtc{
Check the inverse.
}{
\spadcommand{iq*q \free{iq q}}
}
\xtc{
The usual arithmetic (ring) operations are available
}{
\spadcommand{q^6 \free{q}}
}
\xtc{
}{
\spadcommand{r := quatern(-2,3,23/9,-89)$Q2; q + r \bound{r}\free{q}}
}
%
\xtc{
In general, multiplication is not commutative.
}{
\spadcommand{q * r - r * q\free{q r}}
}
\xtc{
The norm is the quaternion times its conjugate.  Norm is rational,
but may be negative.
}{
\spadcommand{norm q \free{q}}
}
\xtc{
}{
\spadcommand{conjugate q \free{q} \bound{prev}}
}
\xtc{
}{
\spadcommand{q * \% \free{q prev}}
}
%
