Package edu.jas.arith

Class ModLong

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

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

    • ring

      public final ModLongRing ring
      ModLongRing reference.
    • val

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

    • ModLong

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

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

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

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

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

    • getVal

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

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

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

      public long 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 ModLong copy()
      Clone this.
      Specified by:
      copy in interface Element<ModLong>
      Returns:
      Creates and returns a copy of this Element.
      See Also:
    • isZERO

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

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

      public boolean isUnit()
      Is ModLong number a unit.
      Specified by:
      isUnit in interface MonoidElem<ModLong>
      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<ModLong>
      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<ModLong>
      Returns:
      script compatible representation for this ElemFactory.
      See Also:
    • compareTo

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

      public boolean equals(Object b)
      Comparison with any other object.
      Specified by:
      equals in interface Element<ModLong>
      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 ModLong.
      Specified by:
      hashCode in interface Element<ModLong>
      Overrides:
      hashCode in class Object
      Returns:
      the hashCode.
      See Also:
    • abs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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