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 GaussianIntegeradd(GaussianInteger b)GaussianIntegerconjugate()GaussianInteger[]divide(GaussianInteger b)Divide this by b.booleanequals(java.lang.Object o)GaussianIntegergcd(GaussianInteger b)Computes the gaussian integer gcd of this and b.inthashCode()java.math.BigIntegerimaginaryPart()booleanisDivisibleBy(GaussianInteger b)Divisibility test.booleanisUnit()booleanisZero()GaussianIntegermultiply(GaussianInteger b)GaussianIntegernegate()java.math.BigIntegernorm()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.BigIntegerrealPart()GaussianIntegersquare()GaussianIntegersubtract(GaussianInteger b)java.lang.StringtoString()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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-