Class IntegersZp64

java.lang.Object
cc.redberry.rings.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)  
  • Method Summary

    Modifier and Type Method Description
    long add​(long a, long b)
    Add mod operation
    IntegersZp asGenericRing()
    Converts this to a generic ring over big integers
    void buildCachedReciprocals()
    builds a table of cached reciprocals
    long divide​(long a, long b)
    Subtract mod operation
    boolean equals​(Object o)  
    long factorial​(int value)
    Gives value!
    int hashCode()  
    boolean isPerfectPower()
    Returns whether the modulus is a perfect power
    long modulus​(long val)
    Returns val % this.modulus
    void modulus​(long[] data)
    Inplace sets elements of data to data % this.modulus
    long modulus​(BigInteger val)
    Returns val % this.modulus
    long multiply​(long a, long b)
    Multiply mod operation
    long negate​(long val)
    Negate mod operation
    long perfectPowerBase()
    Returns base if modulus == base^exponent, and -1 otherwisec
    IntegersZp64 perfectPowerBaseDomain()
    Returns ring for perfectPowerBase() or this if modulus is not a perfect power
    long perfectPowerExponent()
    Returns exponent if modulus == base^exponent, and -1 otherwisec
    long powMod​(long base, long exponent)
    Returns base in a power of non-negative e modulo magic.modulus
    long randomElement()
    Returns a random element from this ring
    long randomElement​(org.apache.commons.math3.random.RandomGenerator rnd)
    Returns a random element from this ring
    long randomNonZeroElement​(org.apache.commons.math3.random.RandomGenerator rnd)
    Returns a random non zero element from this ring
    long reciprocal​(long val)
    Returns modular inverse of val
    long subtract​(long a, long b)
    Subtract mod operation
    long symmetricForm​(long value)
    to symmetric modulus
    String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

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

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

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

      public IntegersZp64 perfectPowerBaseDomain()
      Returns ring for perfectPowerBase() or this if modulus is not a perfect power
      Returns:
      ring for perfectPowerBase() or this if modulus is not a perfect power
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object