Package edu.jas.arith

Class ModInt

    • Field Detail

      • ring

        public final ModIntRing ring
        ModIntRing reference.
      • val

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

      • ModInt

        public ModInt​(ModIntRing m,
                      java.math.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,
                      java.lang.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,
                      java.lang.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,
                      java.lang.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 Detail

      • getVal

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

        public int getModul()
        Get the module part.
        Returns:
        modul.
      • 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:
        Object.clone()
      • 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:
        MonoidElem.isUnit()
      • toString

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

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

        public java.lang.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:
        Element.toScriptFactory()
      • compareTo

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

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

        public int hashCode()
        Hash code for this ModInt.
        Specified by:
        hashCode in interface Element<ModInt>
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hashCode.
        See Also:
        Object.hashCode()
      • 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.