Class IntegersZp64

  • All Implemented Interfaces:
    Serializable

    public final class IntegersZp64
    extends Object
    implements Serializable
    Zp ring over machine numbers which provides fast modular arithmetic.
    Since:
    1.0
    See Also:
    FastDivision, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      cc.redberry.libdivide4j.FastDivision.Magic magic
      magic
      cc.redberry.libdivide4j.FastDivision.Magic magic32MulMod
      magic
      long modulus
      the modulus
      boolean modulusFits32
      whether modulus less then 2^32 (if so, faster mulmod available)
    • Constructor Summary

      Constructors 
      Constructor Description
      IntegersZp64​(long modulus)
      Creates the ring.
      IntegersZp64​(long modulus, cc.redberry.libdivide4j.FastDivision.Magic magic, cc.redberry.libdivide4j.FastDivision.Magic magic32MulMod, boolean modulusFits32)  
    • Field Detail

      • modulus

        public final long modulus
        the modulus
      • magic

        public final cc.redberry.libdivide4j.FastDivision.Magic magic
        magic
      • magic32MulMod

        public final cc.redberry.libdivide4j.FastDivision.Magic magic32MulMod
        magic
      • modulusFits32

        public final boolean modulusFits32
        whether modulus less then 2^32 (if so, faster mulmod available)
    • Constructor Detail

      • IntegersZp64

        public IntegersZp64​(long modulus,
                            cc.redberry.libdivide4j.FastDivision.Magic magic,
                            cc.redberry.libdivide4j.FastDivision.Magic magic32MulMod,
                            boolean modulusFits32)
      • IntegersZp64

        public IntegersZp64​(long modulus)
        Creates the ring.
        Parameters:
        modulus - the modulus
    • Method Detail

      • modulus

        public long modulus​(long val)
        Returns val % this.modulus
      • modulus

        public long modulus​(BigInteger val)
        Returns val % this.modulus
      • modulus

        public void modulus​(long[] data)
        Inplace sets elements of data to data % this.modulus
      • multiply

        public long multiply​(long a,
                             long b)
        Multiply mod operation
      • add

        public long add​(long a,
                        long b)
        Add mod operation
      • subtract

        public long subtract​(long a,
                             long b)
        Subtract mod operation
      • divide

        public long divide​(long a,
                           long b)
        Subtract mod operation
      • buildCachedReciprocals

        public void buildCachedReciprocals()
        builds a table of cached reciprocals
      • reciprocal

        public long reciprocal​(long val)
        Returns modular inverse of val
      • negate

        public long negate​(long val)
        Negate mod operation
      • symmetricForm

        public long symmetricForm​(long value)
        to symmetric modulus
      • asGenericRing

        public IntegersZp asGenericRing()
        Converts this to a generic ring over big integers
        Returns:
        generic ring
      • powMod

        public long powMod​(long base,
                           long exponent)
        Returns base in a power of non-negative e modulo magic.modulus
        Parameters:
        base - the base
        exponent - the non-negative exponent
        Returns:
        base in a power of e
      • randomElement

        public long randomElement​(org.apache.commons.math3.random.RandomGenerator rnd)
        Returns a random element from this ring
        Parameters:
        rnd - the source of randomness
        Returns:
        random element from this ring
      • randomElement

        public long randomElement()
        Returns a random element from this ring
        Returns:
        random element from this ring
      • randomNonZeroElement

        public long randomNonZeroElement​(org.apache.commons.math3.random.RandomGenerator rnd)
        Returns a random non zero element from this ring
        Parameters:
        rnd - the source of randomness
        Returns:
        random non zero element from this ring
      • factorial

        public long factorial​(int value)
        Gives value!
        Parameters:
        value - the number
        Returns:
        value!
      • isPerfectPower

        public boolean isPerfectPower()
        Returns whether the modulus is a perfect power
        Returns:
        whether the modulus is a perfect power
      • perfectPowerBase

        public long perfectPowerBase()
        Returns base if modulus == base^exponent, and -1 otherwisec
        Returns:
        base if modulus == base^exponent, and -1 otherwisec
      • perfectPowerExponent

        public long perfectPowerExponent()
        Returns exponent if modulus == base^exponent, and -1 otherwisec
        Returns:
        exponent if modulus == base^exponent, and -1 otherwisec
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object