edu.jas.poly
Class Complex<C extends RingElem<C>>

java.lang.Object
  extended by edu.jas.poly.Complex<C>
Type Parameters:
C - base type.
All Implemented Interfaces:
AbelianGroupElem<Complex<C>>, Element<Complex<C>>, GcdRingElem<Complex<C>>, MonoidElem<Complex<C>>, RingElem<Complex<C>>, StarRingElem<Complex<C>>, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Complex<C>>

public class Complex<C extends RingElem<C>>
extends java.lang.Object
implements StarRingElem<Complex<C>>, GcdRingElem<Complex<C>>

Generic Complex class implementing the RingElem interface. Objects of this class are immutable.

Author:
Heinz Kredel
See Also:
Serialized Form

Field Summary
protected  C im
          Imaginary part of the data structure.
protected  C re
          Real part of the data structure.
 ComplexRing<C> ring
          Complex class factory data structure.
 
Constructor Summary
Complex(ComplexRing<C> ring)
          The constructor creates a Complex object with real part 0 and imaginary part 0.
Complex(ComplexRing<C> ring, C r)
          The constructor creates a Complex object from a C object as real part, the imaginary part is set to 0.
Complex(ComplexRing<C> ring, C r, C i)
          The constructor creates a Complex object from two C objects as real and imaginary part.
Complex(ComplexRing<C> ring, long r)
          The constructor creates a Complex object from a long element as real part, the imaginary part is set to 0.
Complex(ComplexRing<C> ring, java.lang.String s)
          The constructor creates a Complex object from a String representation.
 
Method Summary
 Complex<C> abs()
          Complex number absolute value.
 Complex<C> clone()
          Clone this.
 int compareTo(Complex<C> b)
          Since complex numbers are unordered, we use lexicographical order of re and im.
 Complex<C> conjugate()
          Complex number conjugate.
 Complex<C> divide(Complex<C> B)
          Complex number divide.
 Complex<C>[] divideAndRemainder(Complex<C> S)
          Deprecated. use quotientRemainder()
 Complex<C>[] egcd(Complex<C> S)
          Complex extended greatest common divisor.
 boolean equals(java.lang.Object b)
          Comparison with any other object.
 ComplexRing<C> factory()
          Get the corresponding element factory.
 Complex<C> gcd(Complex<C> S)
          Complex number greatest common divisor.
 C getIm()
          Get the imaginary part.
 C getRe()
          Get the real part.
 int hashCode()
          Hash code for this Complex.
 Complex<C> inverse()
          Complex number inverse.
 boolean isIMAG()
          Is Complex imaginary one.
 boolean isONE()
          Is Complex number one.
 boolean isUnit()
          Is Complex unit element.
 boolean isZERO()
          Is Complex number zero.
 Complex<C> multiply(Complex<C> B)
          Complex number product.
 Complex<C> negate()
          Complex number negative.
 Complex<C> norm()
          Complex number norm.
 Complex<C>[] quotientRemainder(Complex<C> S)
          Complex number quotient and remainder.
 Complex<C> remainder(Complex<C> S)
          Complex number remainder.
 int signum()
          Since complex numbers are unordered, we use lexicographical order of re and im.
 Complex<C> subtract(Complex<C> B)
          Complex number subtract.
 Complex<C> sum(Complex<C> B)
          Complex number summation.
 java.lang.String toScript()
          Get a scripting compatible string representation.
 java.lang.String toScriptFactory()
          Get a scripting compatible string representation of the factory.
 java.lang.String toString()
          Get the String representation.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ring

public final ComplexRing<C extends RingElem<C>> ring
Complex class factory data structure.


re

protected final C extends RingElem<C> re
Real part of the data structure.


im

protected final C extends RingElem<C> im
Imaginary part of the data structure.

Constructor Detail

Complex

public Complex(ComplexRing<C> ring,
               C r,
               C i)
The constructor creates a Complex object from two C objects as real and imaginary part.

Parameters:
ring - factory for Complex objects.
r - real part.
i - imaginary part.

Complex

public Complex(ComplexRing<C> ring,
               C r)
The constructor creates a Complex object from a C object as real part, the imaginary part is set to 0.

Parameters:
r - real part.

Complex

public Complex(ComplexRing<C> ring,
               long r)
The constructor creates a Complex object from a long element as real part, the imaginary part is set to 0.

Parameters:
r - real part.

Complex

public Complex(ComplexRing<C> ring)
The constructor creates a Complex object with real part 0 and imaginary part 0.


Complex

public Complex(ComplexRing<C> ring,
               java.lang.String s)
        throws java.lang.NumberFormatException
The constructor creates a Complex object from a String representation.

Parameters:
s - string of a Complex.
Throws:
java.lang.NumberFormatException
Method Detail

factory

public ComplexRing<C> factory()
Get the corresponding element factory.

Specified by:
factory in interface Element<Complex<C extends RingElem<C>>>
Returns:
factory for this Element.
See Also:
Element.factory()

getRe

public C getRe()
Get the real part.

Returns:
re.

getIm

public C getIm()
Get the imaginary part.

Returns:
im.

clone

public Complex<C> clone()
Clone this.

Overrides:
clone in class java.lang.Object
See Also:
Object.clone()

toString

public java.lang.String toString()
Get the String representation.

Overrides:
toString in class java.lang.Object

toScript

public java.lang.String toScript()
Get a scripting compatible string representation.

Specified by:
toScript in interface Element<Complex<C extends RingElem<C>>>
Returns:
script compatible representation for this Element.
See Also:
Element.toScript()

toScriptFactory

public java.lang.String toScriptFactory()
Get a scripting compatible string representation of the factory.

Specified by:
toScriptFactory in interface Element<Complex<C extends RingElem<C>>>
Returns:
script compatible representation for this ElemFactory.
See Also:
Element.toScriptFactory()

isZERO

public boolean isZERO()
Is Complex number zero.

Specified by:
isZERO in interface AbelianGroupElem<Complex<C extends RingElem<C>>>
Returns:
If this is 0 then true is returned, else false.
See Also:
AbelianGroupElem.isZERO()

isONE

public boolean isONE()
Is Complex number one.

Specified by:
isONE in interface MonoidElem<Complex<C extends RingElem<C>>>
Returns:
If this is 1 then true is returned, else false.
See Also:
MonoidElem.isONE()

isIMAG

public boolean isIMAG()
Is Complex imaginary one.

Returns:
If this is i then true is returned, else false.

isUnit

public boolean isUnit()
Is Complex unit element.

Specified by:
isUnit in interface MonoidElem<Complex<C extends RingElem<C>>>
Returns:
If this is a unit then true is returned, else false.
See Also:
MonoidElem.isUnit()

equals

public boolean equals(java.lang.Object b)
Comparison with any other object.

Specified by:
equals in interface Element<Complex<C extends RingElem<C>>>
Overrides:
equals in class java.lang.Object
Returns:
true if this is equal to b, else false.
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Hash code for this Complex.

Specified by:
hashCode in interface Element<Complex<C extends RingElem<C>>>
Overrides:
hashCode in class java.lang.Object
Returns:
the hashCode.
See Also:
Object.hashCode()

compareTo

public int compareTo(Complex<C> b)
Since complex numbers are unordered, we use lexicographical order of re and im.

Specified by:
compareTo in interface Element<Complex<C extends RingElem<C>>>
Specified by:
compareTo in interface java.lang.Comparable<Complex<C extends RingElem<C>>>
Returns:
0 if this is equal to b; 1 if re > b.re, or re == b.re and im > b.im; -1 if re < b.re, or re == b.re and im < b.im

signum

public int signum()
Since complex numbers are unordered, we use lexicographical order of re and im.

Specified by:
signum in interface AbelianGroupElem<Complex<C extends RingElem<C>>>
Returns:
0 if this is equal to 0; 1 if re > 0, or re == 0 and im > 0; -1 if re < 0, or re == 0 and im < 0
See Also:
AbelianGroupElem.signum()

sum

public Complex<C> sum(Complex<C> B)
Complex number summation.

Specified by:
sum in interface AbelianGroupElem<Complex<C extends RingElem<C>>>
Parameters:
B - a Complex number.
Returns:
this+B.

subtract

public Complex<C> subtract(Complex<C> B)
Complex number subtract.

Specified by:
subtract in interface AbelianGroupElem<Complex<C extends RingElem<C>>>
Parameters:
B - a Complex number.
Returns:
this-B.

negate

public Complex<C> negate()
Complex number negative.

Specified by:
negate in interface AbelianGroupElem<Complex<C extends RingElem<C>>>
Returns:
-this.
See Also:
AbelianGroupElem.negate()

conjugate

public Complex<C> conjugate()
Complex number conjugate.

Specified by:
conjugate in interface StarRingElem<Complex<C extends RingElem<C>>>
Returns:
the complex conjugate of this.

norm

public Complex<C> norm()
Complex number norm.

Specified by:
norm in interface StarRingElem<Complex<C extends RingElem<C>>>
Returns:
||this||.
See Also:
StarRingElem.norm()

abs

public Complex<C> abs()
Complex number absolute value.

Specified by:
abs in interface AbelianGroupElem<Complex<C extends RingElem<C>>>
Returns:
|this|^2. Note: The square root is not jet implemented.
See Also:
AbelianGroupElem.abs()

multiply

public Complex<C> multiply(Complex<C> B)
Complex number product.

Specified by:
multiply in interface MonoidElem<Complex<C extends RingElem<C>>>
Parameters:
B - is a complex number.
Returns:
this*B.

inverse

public Complex<C> inverse()
Complex number inverse.

Specified by:
inverse in interface MonoidElem<Complex<C extends RingElem<C>>>
Returns:
S with S*this = 1, if it is defined.
See Also:
MonoidElem.inverse()

remainder

public Complex<C> remainder(Complex<C> S)
Complex number remainder.

Specified by:
remainder in interface MonoidElem<Complex<C extends RingElem<C>>>
Parameters:
S - is a complex number.
Returns:
0.

divide

public Complex<C> divide(Complex<C> B)
Complex number divide.

Specified by:
divide in interface MonoidElem<Complex<C extends RingElem<C>>>
Parameters:
B - is a complex number, non-zero.
Returns:
this/B.

quotientRemainder

public Complex<C>[] quotientRemainder(Complex<C> S)
Complex number quotient and remainder.

Parameters:
S - Complex.
Returns:
Complex[] { q, r } with q = this/S and r = rem(this,S).

divideAndRemainder

@Deprecated
public Complex<C>[] divideAndRemainder(Complex<C> S)
Deprecated. use quotientRemainder()

Complex number quotient and remainder.

Parameters:
S - Complex.
Returns:
Complex[] { q, r } with q = this/S and r = rem(this,S).

gcd

public Complex<C> gcd(Complex<C> S)
Complex number greatest common divisor.

Specified by:
gcd in interface RingElem<Complex<C extends RingElem<C>>>
Parameters:
S - Complex.
Returns:
gcd(this,S).

egcd

public Complex<C>[] egcd(Complex<C> S)
Complex extended greatest common divisor.

Specified by:
egcd in interface RingElem<Complex<C extends RingElem<C>>>
Parameters:
S - Complex.
Returns:
[ gcd(this,S), a, b ] with a*this + b*S = gcd(this,S).