Class GaussianInteger
java.lang.Object
de.tilman_neumann.jml.gaussianInteger.GaussianInteger
public class GaussianInteger
extends java.lang.Object
The Gaussian integers are the set Z[i] = {x + iy : x, y ∈ Z} of complex numbers whose real and imaginary parts are both integers.
-
Constructor Summary
Constructors Constructor Description GaussianInteger(java.math.BigInteger x, java.math.BigInteger y)
-
Method Summary
Modifier and Type Method Description GaussianInteger
add(GaussianInteger b)
GaussianInteger
conjugate()
GaussianInteger[]
divide(GaussianInteger b)
Divide this by b.boolean
equals(java.lang.Object o)
GaussianInteger
gcd(GaussianInteger b)
Computes the gaussian integer gcd of this and b.int
hashCode()
java.math.BigInteger
imaginaryPart()
boolean
isDivisibleBy(GaussianInteger b)
Divisibility test.boolean
isUnit()
boolean
isZero()
GaussianInteger
multiply(GaussianInteger b)
GaussianInteger
negate()
java.math.BigInteger
norm()
The norm of a Gaussian integer is its product with its conjugate: N(a+ib) = (a+ib)*(a-ib) = a^2 + b^2
It has the following useful properties:
1.java.math.BigInteger
realPart()
GaussianInteger
square()
GaussianInteger
subtract(GaussianInteger b)
java.lang.String
toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
GaussianInteger
public GaussianInteger(java.math.BigInteger x, java.math.BigInteger y)
-
-
Method Details
-
realPart
public java.math.BigInteger realPart() -
imaginaryPart
public java.math.BigInteger imaginaryPart() -
conjugate
-
negate
-
norm
public java.math.BigInteger norm()The norm of a Gaussian integer is its product with its conjugate: N(a+ib) = (a+ib)*(a-ib) = a^2 + b^2
It has the following useful properties:
1. (Multiplicativity) N(αβ) = N(α)N(β): this holds for any complex numbers α, β.
2. (Units) α is a unit if and only if N(α) = 1, whence Z[i] has precisely four units: ±1, ±i.
3. The norm of a Gaussian integer is the square of its absolute value as a complex number.
4. As a sum of two squares, the norm of a Gaussian integer cannot be of the form 4k + 3, with k integer.- Returns:
- the norm of this
-
isZero
public boolean isZero() -
isUnit
public boolean isUnit()- Returns:
- true if this is one of the four units: ±1, ±i, otherwise false.
-
add
-
subtract
-
multiply
-
square
-
isDivisibleBy
Divisibility test.- Parameters:
b
- GaussianInteger- Returns:
- true if b divides this, false otherwise.
- Throws:
java.lang.ArithmeticException
- if b is zero
-
divide
Divide this by b.- Parameters:
b
-- Returns:
- [quotient, remainder]
-
gcd
Computes the gaussian integer gcd of this and b. A gcd multiplied by one of the four units +-1, +-i is a valid gcd, too. Here we return the single solution with real part > 0 and imaginary part >=0.- Parameters:
b
-- Returns:
- gcd(this, b)
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-