% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved. % !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk. \newcommand{\ComplexXmpTitle}{Complex} \newcommand{\ComplexXmpNumber}{9.11} % % ===================================================================== \begin{page}{ComplexXmpPage}{9.11 Complex} % ===================================================================== \beginscroll % The \spadtype{Complex} constructor implements complex objects over a commutative ring \spad{R}. Typically, the ring \spad{R} is \spadtype{Integer}, \spadtype{Fraction Integer}, \spadtype{Float} or \spadtype{DoubleFloat}. \spad{R} can also be a symbolic type, like \spadtype{Polynomial Integer}. For more information about the numerical and graphical aspects of complex numbers, see \downlink{``\ugProblemNumericTitle''}{ugProblemNumericPage} in Section \ugProblemNumericNumber\ignore{ugProblemNumeric}. \xtc{ Complex objects are created by the \spadfunFrom{complex}{Complex} operation. }{ \spadpaste{a := complex(4/3,5/2) \bound{a}} } \xtc{ }{ \spadpaste{b := complex(4/3,-5/2) \bound{b}} } \xtc{ The standard arithmetic operations are available. }{ \spadpaste{a + b \free{a b}} } \xtc{ }{ \spadpaste{a - b \free{a b}} } \xtc{ }{ \spadpaste{a * b \free{a b}} } \xtc{ If \spad{R} is a field, you can also divide the complex objects. }{ \spadpaste{a / b \free{a b}\bound{adb}} } \xtc{ Use a conversion (\downlink{``\ugTypesConvertTitle''}{ugTypesConvertPage} in Section \ugTypesConvertNumber\ignore{ugTypesConvert}) to view the last object as a fraction of complex integers. }{ \spadpaste{\% :: Fraction Complex Integer \free{adb}} } \xtc{ The predefined macro \spad{\%i} is defined to be \spad{complex(0,1)}. }{ \spadpaste{3.4 + 6.7 * \%i} } \xtc{ You can also compute the \spadfunFrom{conjugate}{Complex} and \spadfunFrom{norm}{Complex} of a complex number. }{ \spadpaste{conjugate a \free{a}} } \xtc{ }{ \spadpaste{norm a \free{a}} } \xtc{ The \spadfunFrom{real}{Complex} and \spadfunFrom{imag}{Complex} operations are provided to extract the real and imaginary parts, respectively. }{ \spadpaste{real a \free{a}} } \xtc{ }{ \spadpaste{imag a \free{a}} } \xtc{ The domain \spadtype{Complex Integer} is also called the Gaussian integers. %-% \HDindex{Gaussian integer}{ComplexXmpPage}{9.11}{Complex} If \spad{R} is the integers (or, more generally, a \spadtype{EuclideanDomain}), you can compute greatest common divisors. }{ \spadpaste{gcd(13 - 13*\%i,31 + 27*\%i)} } \xtc{ You can also compute least common multiples. }{ \spadpaste{lcm(13 - 13*\%i,31 + 27*\%i)} } \xtc{ You can \spadfunFrom{factor}{Complex} Gaussian integers. }{ \spadpaste{factor(13 - 13*\%i)} } \xtc{ }{ \spadpaste{factor complex(2,0)} } \endscroll \autobuttons \end{page} %