Package edu.jas.arith
Class BigDecimalComplex
- java.lang.Object
-
- edu.jas.arith.BigDecimalComplex
-
- All Implemented Interfaces:
AbelianGroupElem<BigDecimalComplex>
,AbelianGroupFactory<BigDecimalComplex>
,Element<BigDecimalComplex>
,ElemFactory<BigDecimalComplex>
,GcdRingElem<BigDecimalComplex>
,MonoidElem<BigDecimalComplex>
,MonoidFactory<BigDecimalComplex>
,RingElem<BigDecimalComplex>
,RingFactory<BigDecimalComplex>
,StarRingElem<BigDecimalComplex>
,java.io.Serializable
,java.lang.Comparable<BigDecimalComplex>
public final class BigDecimalComplex extends java.lang.Object implements StarRingElem<BigDecimalComplex>, GcdRingElem<BigDecimalComplex>, RingFactory<BigDecimalComplex>
BigComplex class based on BigDecimal implementing the RingElem respectively the StarRingElem interface. Objects of this class are immutable.- Author:
- Heinz Kredel
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static BigDecimalComplex
I
The constant i.BigDecimal
im
Imaginary part of the data structure.static BigDecimalComplex
ONE
The constant 1.BigDecimal
re
Real part of the data structure.static BigDecimalComplex
ZERO
The constant 0.
-
Constructor Summary
Constructors Constructor Description BigDecimalComplex()
The constructor creates a BigDecimalComplex object with real part 0 and imaginary part 0.BigDecimalComplex(long r)
The constructor creates a BigDecimalComplex object from a long element as real part, the imaginary part is set to 0.BigDecimalComplex(long r, long i)
The constructor creates a BigDecimalComplex object from a long element as real part and the imaginary part.BigDecimalComplex(BigComplex a)
The constructor creates a BigDecimalComplex object from a BigComplex object.BigDecimalComplex(BigDecimal r)
The constructor creates a BigDecimalComplex object from a BigDecimal object as real part, the imaginary part is set to 0.BigDecimalComplex(BigDecimal r, BigDecimal i)
The constructor creates a BigDecimalComplex object from two BigDecimal objects real and imaginary part.BigDecimalComplex(java.lang.String s)
The constructor creates a BigDecimalComplex object from a String representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BigDecimalComplex
abs()
Complex number absolute value.long
bitLength()
Returns the number of bits in the representation of this BigDecimalComplex, including a sign bit.static BigDecimal
CABS(BigDecimalComplex A)
Complex number absolute value.static BigDecimalComplex
CCON(BigDecimalComplex A)
Complex number conjugate.static BigDecimalComplex
CDIF(BigDecimalComplex A, BigDecimalComplex B)
Complex number difference.java.math.BigInteger
characteristic()
Characteristic of this ring.static BigDecimalComplex
CINV(BigDecimalComplex A)
Complex number inverse.static BigDecimalComplex
CNEG(BigDecimalComplex A)
Complex number negative.int
compareTo(BigDecimalComplex b)
Since complex numbers are unordered, we use lexicographical order of re and im.BigDecimalComplex
conjugate()
Complex number conjugate.BigDecimalComplex
copy()
Clone this.BigDecimalComplex
copy(BigDecimalComplex c)
Copy BigDecimalComplex element c.static BigDecimalComplex
CPROD(BigDecimalComplex A, BigDecimalComplex B)
Complex number product.static BigDecimalComplex
CQ(BigDecimalComplex A, BigDecimalComplex B)
Complex number quotient.static BigDecimalComplex
CRAND(int n)
Complex number, random.static BigDecimalComplex
CSUM(BigDecimalComplex A, BigDecimalComplex B)
Complex number sum.BigDecimalComplex
divide(BigDecimalComplex B)
Complex number divide.BigDecimalComplex[]
egcd(BigDecimalComplex S)
BigDecimalComplex extended greatest common divisor.boolean
equals(java.lang.Object b)
Comparison with any other object.BigDecimalComplex
factory()
Get the corresponding element factory.BigDecimalComplex
fromInteger(long a)
Get a BigDecimalComplex element from a long.BigDecimalComplex
fromInteger(java.math.BigInteger a)
Get a BigDecimalComplex element from a BigInteger.BigDecimalComplex
gcd(BigDecimalComplex S)
Complex number greatest common divisor.java.util.List<BigDecimalComplex>
generators()
Get a list of the generating elements.BigDecimal
getIm()
Get the imaginary part.BigDecimalComplex
getIMAG()
Get the i element.BigDecimalComplex
getONE()
Get the one element.BigDecimal
getRe()
Get the real part.BigDecimalComplex
getZERO()
Get the zero element.int
hashCode()
Hash code for this BigDecimalComplex.BigDecimalComplex
inverse()
Complex number inverse.boolean
isAssociative()
Query if this ring is associative.boolean
isCommutative()
Query if this ring is commutative.static boolean
isCONE(BigDecimalComplex A)
Complex number one.static boolean
isCZERO(BigDecimalComplex A)
Complex number zero.boolean
isField()
Query if this ring is a field.boolean
isFinite()
Is this structure finite or infinite.boolean
isIMAG()
Is Complex imaginary one.boolean
isONE()
Is Complex number one.boolean
isUnit()
Is Complex unit element.boolean
isZERO()
Is Complex number zero.BigDecimalComplex
multiply(BigDecimalComplex B)
Complex number product.BigDecimalComplex
negate()
Complex number negative.BigDecimalComplex
norm()
Complex number norm.BigDecimalComplex
parse(java.io.Reader r)
Parse complex number from Reader.BigDecimalComplex
parse(java.lang.String s)
Parse complex number from string.BigDecimalComplex[]
quotientRemainder(BigDecimalComplex S)
Quotient and remainder by division of this by S.BigDecimalComplex
random(int n)
Complex number, random.BigDecimalComplex
random(int n, java.util.Random rnd)
Complex number, random.BigDecimalComplex
remainder(BigDecimalComplex S)
Complex number inverse.int
signum()
Since complex numbers are unordered, we use lexicographical order of re and im.BigDecimalComplex
subtract(BigDecimalComplex B)
Complex number subtract.BigDecimalComplex
sum(BigDecimalComplex 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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface edu.jas.structure.ElemFactory
valueOf
-
Methods inherited from interface edu.jas.structure.MonoidElem
leftDivide, leftRemainder, power, rightDivide, rightRemainder, twosidedDivide, twosidedRemainder
-
-
-
-
Field Detail
-
re
public final BigDecimal re
Real part of the data structure.
-
im
public final BigDecimal im
Imaginary part of the data structure.
-
ZERO
public static final BigDecimalComplex ZERO
The constant 0.
-
ONE
public static final BigDecimalComplex ONE
The constant 1.
-
I
public static final BigDecimalComplex I
The constant i.
-
-
Constructor Detail
-
BigDecimalComplex
public BigDecimalComplex(BigDecimal r, BigDecimal i)
The constructor creates a BigDecimalComplex object from two BigDecimal objects real and imaginary part.- Parameters:
r
- real part.i
- imaginary part.
-
BigDecimalComplex
public BigDecimalComplex()
The constructor creates a BigDecimalComplex object with real part 0 and imaginary part 0.
-
BigDecimalComplex
public BigDecimalComplex(BigDecimal r)
The constructor creates a BigDecimalComplex object from a BigDecimal object as real part, the imaginary part is set to 0.- Parameters:
r
- real part.
-
BigDecimalComplex
public BigDecimalComplex(long r)
The constructor creates a BigDecimalComplex object from a long element as real part, the imaginary part is set to 0.- Parameters:
r
- real part.
-
BigDecimalComplex
public BigDecimalComplex(long r, long i)
The constructor creates a BigDecimalComplex object from a long element as real part and the imaginary part.- Parameters:
r
- real part.i
- imaginary part.
-
BigDecimalComplex
public BigDecimalComplex(java.lang.String s) throws java.lang.NumberFormatException
The constructor creates a BigDecimalComplex object from a String representation.- Parameters:
s
- string of a BigDecimalComplex.- Throws:
java.lang.NumberFormatException
-
BigDecimalComplex
public BigDecimalComplex(BigComplex a)
The constructor creates a BigDecimalComplex object from a BigComplex object.- Parameters:
a
- rational BigComplex.
-
-
Method Detail
-
factory
public BigDecimalComplex factory()
Get the corresponding element factory.- Specified by:
factory
in interfaceElement<BigDecimalComplex>
- Returns:
- factory for this Element.
- See Also:
Element.factory()
-
generators
public java.util.List<BigDecimalComplex> generators()
Get a list of the generating elements.- Specified by:
generators
in interfaceElemFactory<BigDecimalComplex>
- Returns:
- list of generators for the algebraic structure.
- See Also:
ElemFactory.generators()
-
isFinite
public boolean isFinite()
Is this structure finite or infinite.- Specified by:
isFinite
in interfaceElemFactory<BigDecimalComplex>
- Returns:
- true if this structure is finite, else false.
- See Also:
ElemFactory.isFinite()
-
copy
public BigDecimalComplex copy()
Clone this.- Specified by:
copy
in interfaceElement<BigDecimalComplex>
- Returns:
- Creates and returns a copy of this Element.
- See Also:
Object.clone()
-
copy
public BigDecimalComplex copy(BigDecimalComplex c)
Copy BigDecimalComplex element c.- Specified by:
copy
in interfaceElemFactory<BigDecimalComplex>
- Parameters:
c
- BigDecimalComplex.- Returns:
- a copy of c.
-
getZERO
public BigDecimalComplex getZERO()
Get the zero element.- Specified by:
getZERO
in interfaceAbelianGroupFactory<BigDecimalComplex>
- Returns:
- 0 as BigDecimalComplex.
-
getONE
public BigDecimalComplex getONE()
Get the one element.- Specified by:
getONE
in interfaceMonoidFactory<BigDecimalComplex>
- Returns:
- 1 as BigDecimalComplex.
-
getIMAG
public BigDecimalComplex getIMAG()
Get the i element.- Returns:
- i as BigDecimalComplex.
-
isCommutative
public boolean isCommutative()
Query if this ring is commutative.- Specified by:
isCommutative
in interfaceMonoidFactory<BigDecimalComplex>
- Returns:
- true.
-
isAssociative
public boolean isAssociative()
Query if this ring is associative.- Specified by:
isAssociative
in interfaceMonoidFactory<BigDecimalComplex>
- Returns:
- true.
-
isField
public boolean isField()
Query if this ring is a field.- Specified by:
isField
in interfaceRingFactory<BigDecimalComplex>
- Returns:
- true.
-
characteristic
public java.math.BigInteger characteristic()
Characteristic of this ring.- Specified by:
characteristic
in interfaceRingFactory<BigDecimalComplex>
- Returns:
- characteristic of this ring.
-
fromInteger
public BigDecimalComplex fromInteger(java.math.BigInteger a)
Get a BigDecimalComplex element from a BigInteger.- Specified by:
fromInteger
in interfaceElemFactory<BigDecimalComplex>
- Parameters:
a
- BigInteger.- Returns:
- a BigDecimalComplex.
-
fromInteger
public BigDecimalComplex fromInteger(long a)
Get a BigDecimalComplex element from a long.- Specified by:
fromInteger
in interfaceElemFactory<BigDecimalComplex>
- Parameters:
a
- long.- Returns:
- a BigDecimalComplex.
-
getRe
public BigDecimal getRe()
Get the real part.- Returns:
- re.
-
getIm
public BigDecimal getIm()
Get the imaginary part.- Returns:
- im.
-
toString
public java.lang.String toString()
Get the String representation.- Overrides:
toString
in classjava.lang.Object
-
toScript
public java.lang.String toScript()
Get a scripting compatible string representation.- Specified by:
toScript
in interfaceElement<BigDecimalComplex>
- Specified by:
toScript
in interfaceElemFactory<BigDecimalComplex>
- 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 interfaceElement<BigDecimalComplex>
- Returns:
- script compatible representation for this ElemFactory.
- See Also:
Element.toScriptFactory()
-
isCZERO
public static boolean isCZERO(BigDecimalComplex A)
Complex number zero.- Parameters:
A
- is a complex number.- Returns:
- If A is 0 then true is returned, else false.
-
isZERO
public boolean isZERO()
Is Complex number zero.- Specified by:
isZERO
in interfaceAbelianGroupElem<BigDecimalComplex>
- Returns:
- If this is 0 then true is returned, else false.
- See Also:
AbelianGroupElem.isZERO()
-
isCONE
public static boolean isCONE(BigDecimalComplex A)
Complex number one.- Parameters:
A
- is a complex number.- Returns:
- If A is 1 then true is returned, else false.
-
isONE
public boolean isONE()
Is Complex number one.- Specified by:
isONE
in interfaceMonoidElem<BigDecimalComplex>
- 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 interfaceMonoidElem<BigDecimalComplex>
- 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 interfaceElement<BigDecimalComplex>
- Overrides:
equals
in classjava.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 BigDecimalComplex.- Specified by:
hashCode
in interfaceElement<BigDecimalComplex>
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hashCode.
- See Also:
Object.hashCode()
-
compareTo
public int compareTo(BigDecimalComplex b)
Since complex numbers are unordered, we use lexicographical order of re and im.- Specified by:
compareTo
in interfacejava.lang.Comparable<BigDecimalComplex>
- Specified by:
compareTo
in interfaceElement<BigDecimalComplex>
- 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 interfaceAbelianGroupElem<BigDecimalComplex>
- 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 BigDecimalComplex sum(BigDecimalComplex B)
Complex number summation.- Specified by:
sum
in interfaceAbelianGroupElem<BigDecimalComplex>
- Parameters:
B
- a BigDecimalComplex number.- Returns:
- this+B.
-
CSUM
public static BigDecimalComplex CSUM(BigDecimalComplex A, BigDecimalComplex B)
Complex number sum.- Parameters:
A
- and B are complex numbers.- Returns:
- A+B.
-
CDIF
public static BigDecimalComplex CDIF(BigDecimalComplex A, BigDecimalComplex B)
Complex number difference.- Parameters:
A
- and B are complex numbers.- Returns:
- A-B.
-
subtract
public BigDecimalComplex subtract(BigDecimalComplex B)
Complex number subtract.- Specified by:
subtract
in interfaceAbelianGroupElem<BigDecimalComplex>
- Parameters:
B
- a BigDecimalComplex number.- Returns:
- this-B.
-
CNEG
public static BigDecimalComplex CNEG(BigDecimalComplex A)
Complex number negative.- Parameters:
A
- is a complex number.- Returns:
- -A
-
negate
public BigDecimalComplex negate()
Complex number negative.- Specified by:
negate
in interfaceAbelianGroupElem<BigDecimalComplex>
- Returns:
- -this.
- See Also:
AbelianGroupElem.negate()
-
CCON
public static BigDecimalComplex CCON(BigDecimalComplex A)
Complex number conjugate.- Parameters:
A
- is a complex number.- Returns:
- the complex conjugate of A.
-
conjugate
public BigDecimalComplex conjugate()
Complex number conjugate.- Specified by:
conjugate
in interfaceStarRingElem<BigDecimalComplex>
- Returns:
- the complex conjugate of this.
-
norm
public BigDecimalComplex norm()
Complex number norm.- Specified by:
norm
in interfaceStarRingElem<BigDecimalComplex>
- Returns:
- ||this||.
- See Also:
StarRingElem.norm()
-
abs
public BigDecimalComplex abs()
Complex number absolute value.- Specified by:
abs
in interfaceAbelianGroupElem<BigDecimalComplex>
- Returns:
- |this|.
- See Also:
AbelianGroupElem.abs()
-
CABS
public static BigDecimal CABS(BigDecimalComplex A)
Complex number absolute value.- Parameters:
A
- is a complex number.- Returns:
- the absolute value of A, a rational number. Note: The square root is not jet implemented.
-
CPROD
public static BigDecimalComplex CPROD(BigDecimalComplex A, BigDecimalComplex B)
Complex number product.- Parameters:
A
- and B are complex numbers.- Returns:
- A*B.
-
multiply
public BigDecimalComplex multiply(BigDecimalComplex B)
Complex number product.- Specified by:
multiply
in interfaceMonoidElem<BigDecimalComplex>
- Parameters:
B
- is a complex number.- Returns:
- this*B.
-
CINV
public static BigDecimalComplex CINV(BigDecimalComplex A)
Complex number inverse.- Parameters:
A
- is a non-zero complex number.- Returns:
- S with S*A = 1.
-
inverse
public BigDecimalComplex inverse()
Complex number inverse.- Specified by:
inverse
in interfaceMonoidElem<BigDecimalComplex>
- Returns:
- S with S*this = 1.
- See Also:
MonoidElem.inverse()
-
remainder
public BigDecimalComplex remainder(BigDecimalComplex S)
Complex number inverse.- Specified by:
remainder
in interfaceMonoidElem<BigDecimalComplex>
- Parameters:
S
- is a complex number.- Returns:
- 0.
-
CQ
public static BigDecimalComplex CQ(BigDecimalComplex A, BigDecimalComplex B)
Complex number quotient.- Parameters:
A
- and B are complex numbers, B non-zero.- Returns:
- A/B.
-
divide
public BigDecimalComplex divide(BigDecimalComplex B)
Complex number divide.- Specified by:
divide
in interfaceMonoidElem<BigDecimalComplex>
- Parameters:
B
- is a complex number, non-zero.- Returns:
- this/B.
-
quotientRemainder
public BigDecimalComplex[] quotientRemainder(BigDecimalComplex S)
Quotient and remainder by division of this by S.- Specified by:
quotientRemainder
in interfaceMonoidElem<BigDecimalComplex>
- Parameters:
S
- a complex number- Returns:
- [this/S, this - (this/S)*S].
-
random
public BigDecimalComplex random(int n)
Complex number, random. Random rational numbers A and B are generated using random(n). Then R is the complex number with real part A and imaginary part B.- Specified by:
random
in interfaceElemFactory<BigDecimalComplex>
- Parameters:
n
- such that 0 ≤ A, B ≤ (2n-1).- Returns:
- R.
-
random
public BigDecimalComplex random(int n, java.util.Random rnd)
Complex number, random. Random rational numbers A and B are generated using random(n). Then R is the complex number with real part A and imaginary part B.- Specified by:
random
in interfaceElemFactory<BigDecimalComplex>
- Parameters:
n
- such that 0 ≤ A, B ≤ (2n-1).rnd
- is a source for random bits.- Returns:
- R.
-
CRAND
public static BigDecimalComplex CRAND(int n)
Complex number, random. Random rational numbers A and B are generated using random(n). Then R is the complex number with real part A and imaginary part B.- Parameters:
n
- such that 0 ≤ A, B ≤ (2n-1).- Returns:
- R.
-
parse
public BigDecimalComplex parse(java.lang.String s)
Parse complex number from string.- Specified by:
parse
in interfaceElemFactory<BigDecimalComplex>
- Parameters:
s
- String.- Returns:
- BigDecimalComplex from s.
-
parse
public BigDecimalComplex parse(java.io.Reader r)
Parse complex number from Reader.- Specified by:
parse
in interfaceElemFactory<BigDecimalComplex>
- Parameters:
r
- Reader.- Returns:
- next BigDecimalComplex from r.
-
gcd
public BigDecimalComplex gcd(BigDecimalComplex S)
Complex number greatest common divisor.- Specified by:
gcd
in interfaceRingElem<BigDecimalComplex>
- Parameters:
S
- BigDecimalComplex.- Returns:
- gcd(this,S).
-
egcd
public BigDecimalComplex[] egcd(BigDecimalComplex S)
BigDecimalComplex extended greatest common divisor.- Specified by:
egcd
in interfaceRingElem<BigDecimalComplex>
- Parameters:
S
- BigDecimalComplex.- Returns:
- [ gcd(this,S), a, b ] with a*this + b*S = gcd(this,S).
-
bitLength
public long bitLength()
Returns the number of bits in the representation of this BigDecimalComplex, including a sign bit. It is equivalent tore.bitLength() + im.bitLength()
.)- Returns:
- number of bits in the representation of this BigDecimalComplex, including a sign bit.
-
-