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 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

      public GaussianInteger conjugate()
    • negate

      public GaussianInteger 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

      public GaussianInteger add​(GaussianInteger b)
    • subtract

      public GaussianInteger subtract​(GaussianInteger b)
    • multiply

      public GaussianInteger multiply​(GaussianInteger b)
    • square

      public GaussianInteger square()
    • isDivisibleBy

      public boolean isDivisibleBy​(GaussianInteger b) throws java.lang.ArithmeticException
      Divisibility test.
      Parameters:
      b - GaussianInteger
      Returns:
      true if b divides this, false otherwise.
      Throws:
      java.lang.ArithmeticException - if b is zero
    • divide

      public GaussianInteger[] divide​(GaussianInteger b)
      Divide this by b.
      Parameters:
      b -
      Returns:
      [quotient, remainder]
    • gcd

      public GaussianInteger gcd​(GaussianInteger b)
      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 class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object