Package edu.jas.arith

Class ModInt

java.lang.Object
edu.jas.arith.ModInt
All Implemented Interfaces:
Modular, AbelianGroupElem<ModInt>, Element<ModInt>, GcdRingElem<ModInt>, MonoidElem<ModInt>, RingElem<ModInt>, Serializable, Comparable<ModInt>

public final class ModInt extends Object implements GcdRingElem<ModInt>, Modular
ModInt class with RingElem interface. Objects of this class are immutable.
See Also:
  • Field Details

    • ring

      public final ModIntRing ring
      ModIntRing reference.
    • val

      public final int val
      Value part of the element data structure.
  • Constructor Details

    • ModInt

      public ModInt(ModIntRing m, BigInteger a)
      The constructor creates a ModInt object from a ModIntRing and a value part.
      Parameters:
      m - ModIntRing.
      a - math.BigInteger.
    • ModInt

      public ModInt(ModIntRing m, int a)
      The constructor creates a ModInt object from a ModIntRing and a int value part.
      Parameters:
      m - ModIntRing.
      a - int.
    • ModInt

      public ModInt(ModIntRing m, long a)
      The constructor creates a ModInt object from a ModIntRing and a long value part.
      Parameters:
      m - ModIntRing.
      a - long.
    • ModInt

      public ModInt(ModIntRing m, Integer a)
      The constructor creates a ModInt object from a ModIntRing and a Int value part.
      Parameters:
      m - ModIntRing.
      a - Int.
    • ModInt

      public ModInt(ModIntRing m, Long a)
      The constructor creates a ModInt object from a ModIntRing and a Long value part.
      Parameters:
      m - ModIntRing.
      a - long.
    • ModInt

      public ModInt(ModIntRing m, String s)
      The constructor creates a ModInt object from a ModIntRing and a String value part.
      Parameters:
      m - ModIntRing.
      s - String.
    • ModInt

      public ModInt(ModIntRing m)
      The constructor creates a 0 ModInt object from a given ModIntRing.
      Parameters:
      m - ModIntRing.
  • Method Details

    • getVal

      public int getVal()
      Get the value part.
      Returns:
      val.
    • getModul

      public int getModul()
      Get the module part.
      Returns:
      modul.
    • factory

      public ModIntRing factory()
      Get the corresponding element factory.
      Specified by:
      factory in interface Element<ModInt>
      Returns:
      factory for this Element.
      See Also:
    • getSymmetricVal

      public int getSymmetricVal()
      Get the symmetric value part.
      Returns:
      val with -modul/2 ≤ val < modul/2.
    • getInteger

      public BigInteger getInteger()
      Return a BigInteger from this Element.
      Specified by:
      getInteger in interface Modular
      Returns:
      a BigInteger of this.
    • getSymmetricInteger

      public BigInteger getSymmetricInteger()
      Return a symmetric BigInteger from this Element.
      Specified by:
      getSymmetricInteger in interface Modular
      Returns:
      a symmetric BigInteger of this.
    • copy

      public ModInt copy()
      Clone this.
      Specified by:
      copy in interface Element<ModInt>
      Returns:
      Creates and returns a copy of this Element.
      See Also:
    • isZERO

      public boolean isZERO()
      Is ModInt number zero.
      Specified by:
      isZERO in interface AbelianGroupElem<ModInt>
      Returns:
      If this is 0 then true is returned, else false.
      See Also:
    • isONE

      public boolean isONE()
      Is ModInt number one.
      Specified by:
      isONE in interface MonoidElem<ModInt>
      Returns:
      If this is 1 then true is returned, else false.
      See Also:
    • isUnit

      public boolean isUnit()
      Is ModInt number a unit.
      Specified by:
      isUnit in interface MonoidElem<ModInt>
      Returns:
      If this is a unit then true is returned, else false.
      See Also:
    • toString

      public String toString()
      Get the String representation.
      Overrides:
      toString in class Object
      See Also:
    • toScript

      public String toScript()
      Get a scripting compatible string representation.
      Specified by:
      toScript in interface Element<ModInt>
      Returns:
      script compatible representation for this Element.
      See Also:
    • toScriptFactory

      public String toScriptFactory()
      Get a scripting compatible string representation of the factory.
      Specified by:
      toScriptFactory in interface Element<ModInt>
      Returns:
      script compatible representation for this ElemFactory.
      See Also:
    • compareTo

      public int compareTo(ModInt b)
      ModInt comparison.
      Specified by:
      compareTo in interface Comparable<ModInt>
      Specified by:
      compareTo in interface Element<ModInt>
      Parameters:
      b - ModInt.
      Returns:
      sign(this-b).
    • equals

      public boolean equals(Object b)
      Comparison with any other object.
      Specified by:
      equals in interface Element<ModInt>
      Overrides:
      equals in class Object
      Parameters:
      b -
      Returns:
      true if this is equal to b, else false.
      See Also:
    • hashCode

      public int hashCode()
      Hash code for this ModInt.
      Specified by:
      hashCode in interface Element<ModInt>
      Overrides:
      hashCode in class Object
      Returns:
      the hashCode.
      See Also:
    • abs

      public ModInt abs()
      ModInt absolute value.
      Specified by:
      abs in interface AbelianGroupElem<ModInt>
      Returns:
      the absolute value of this.
      See Also:
    • negate

      public ModInt negate()
      ModInt negative.
      Specified by:
      negate in interface AbelianGroupElem<ModInt>
      Returns:
      -this.
      See Also:
    • signum

      public int signum()
      ModInt signum.
      Specified by:
      signum in interface AbelianGroupElem<ModInt>
      Returns:
      signum(this).
      See Also:
    • subtract

      public ModInt subtract(ModInt S)
      ModInt subtraction.
      Specified by:
      subtract in interface AbelianGroupElem<ModInt>
      Parameters:
      S - ModInt.
      Returns:
      this-S.
    • divide

      public ModInt divide(ModInt S)
      ModInt divide.
      Specified by:
      divide in interface MonoidElem<ModInt>
      Parameters:
      S - ModInt.
      Returns:
      this/S.
    • inverse

      public ModInt inverse()
      ModInt inverse.
      Specified by:
      inverse in interface MonoidElem<ModInt>
      Returns:
      S with S=1/this if defined.
      Throws:
      NotInvertibleException - if the element is not invertible.
      See Also:
    • remainder

      public ModInt remainder(ModInt S)
      ModInt remainder.
      Specified by:
      remainder in interface MonoidElem<ModInt>
      Parameters:
      S - ModInt.
      Returns:
      remainder(this,S).
    • multiply

      public ModInt multiply(ModInt S)
      ModInt multiply.
      Specified by:
      multiply in interface MonoidElem<ModInt>
      Parameters:
      S - ModInt.
      Returns:
      this*S.
    • sum

      public ModInt sum(ModInt S)
      ModInt summation.
      Specified by:
      sum in interface AbelianGroupElem<ModInt>
      Parameters:
      S - ModInt.
      Returns:
      this+S.
    • gcd

      public ModInt gcd(ModInt S)
      ModInteger greatest common divisor.
      Specified by:
      gcd in interface RingElem<ModInt>
      Parameters:
      S - ModInteger.
      Returns:
      [ gcd(this,S), a, b ] with a*this + b*S = gcd(this,S).
    • egcd

      public ModInt[] egcd(ModInt S)
      ModInteger extended greatest common divisor.
      Specified by:
      egcd in interface RingElem<ModInt>
      Parameters:
      S - ModInteger.
      Returns:
      [ gcd(this,S), a, b ] with a*this + b*S = gcd(this,S).
    • gcd

      public int gcd(int T, int S)
      Int greatest common divisor.
      Parameters:
      T - int.
      S - int.
      Returns:
      gcd(T,S).
    • hegcd

      public int[] hegcd(int T, int S)
      Int half extended greatest common divisor.
      Parameters:
      T - int.
      S - int.
      Returns:
      [ gcd(T,S), a ] with a*T + b*S = gcd(T,S).
    • modInverse

      public int modInverse(int T, int m)
      Int modular inverse.
      Parameters:
      T - int.
      m - int.
      Returns:
      a with with a*T = 1 mod m.
    • bitLength

      public int bitLength()
      Returns the number of bits in the representation of this ModInt, including a sign bit.
      Returns:
      number of bits in the representation of this ModInt, including a sign bit.