% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\GeneralQuaternionXmpTitle}{GeneralQuaternion}
\newcommand{\GeneralQuaternionXmpNumber}{9.31}
%
% =====================================================================
\begin{page}{GeneralQuaternionXmpPage}{9.31 GeneralQuaternion}
% =====================================================================
\beginscroll

%
%
%
%
%


The domain constructor \spadtype{GeneralQuaternion} implements general
quaternions over commutative rings.
For information on related topics, see
%\menuxmpref{CliffordAlgebra}
\downlink{`Quaternion'}{QuaternionXmpPage}\ignore{Quaternion},
\downlink{`Complex'}{ComplexXmpPage}\ignore{Complex} and
\downlink{`Octonion'}{OctonionXmpPage}\ignore{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.
}{
\spadpaste{Q2 := GeneralQuaternion(Fraction(Integer), 2, 3) \bound{Q2}}
}
\xtc{
The basic operation for creating quaternions is
\spadfunFrom{quatern}{GeneralQuaternion}.
}{
\spadpaste{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}.
}{
\spadpaste{i^2 \free{i}}
}
\xtc{
Similarly for \spad{b}.
}{
\spadpaste{( quatern(0, 0, 1, 0)$Q2)^2 \free{Q2}}
}
\xtc{
Yet another quaternion.
}{
\spadpaste{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.
}{
\spadpaste{iq := inv q \bound{iq}\free{q}}
}
\xtc{
Check the inverse.
}{
\spadpaste{iq*q \free{iq q}}
}
\xtc{
The usual arithmetic (ring) operations are available
}{
\spadpaste{q^6 \free{q}}
}
\xtc{
}{
\spadpaste{r := quatern(-2,3,23/9,-89)$Q2; q + r \bound{r}\free{q}}
}
%
\xtc{
In general, multiplication is not commutative.
}{
\spadpaste{q * r - r * q\free{q r}}
}
\xtc{
The norm is the quaternion times its conjugate.  Norm is rational,
but may be negative.
}{
\spadpaste{norm q \free{q}}
}
\xtc{
}{
\spadpaste{conjugate q \free{q} \bound{prev}}
}
\xtc{
}{
\spadpaste{q * \% \free{q prev}}
}
%
\endscroll
\autobuttons
\end{page}
%
