Package cc.redberry.rings
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
magiccc.redberry.libdivide4j.FastDivision.Magic
magic32MulMod
magiclong
modulus
the modulusboolean
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 operationIntegersZp
asGenericRing()
Converts this to a generic ring over big integersvoid
buildCachedReciprocals()
builds a table of cached reciprocalslong
divide(long a, long b)
Subtract mod operationboolean
equals(Object o)
long
factorial(int value)
Gives value!int
hashCode()
boolean
isPerfectPower()
Returns whether the modulus is a perfect powerlong
modulus(long val)
Returnsval % this.modulus
void
modulus(long[] data)
Inplace sets elements ofdata
todata % this.modulus
long
modulus(BigInteger val)
Returnsval % this.modulus
long
multiply(long a, long b)
Multiply mod operationlong
negate(long val)
Negate mod operationlong
perfectPowerBase()
Returnsbase
ifmodulus == base^exponent
, and-1
otherwisecIntegersZp64
perfectPowerBaseDomain()
Returns ring forperfectPowerBase()
orthis
if modulus is not a perfect powerlong
perfectPowerExponent()
Returnsexponent
ifmodulus == base^exponent
, and-1
otherwiseclong
powMod(long base, long exponent)
Returnsbase
in a power of non-negativee
modulomagic.modulus
long
randomElement()
Returns a random element from this ringlong
randomElement(org.apache.commons.math3.random.RandomGenerator rnd)
Returns a random element from this ringlong
randomNonZeroElement(org.apache.commons.math3.random.RandomGenerator rnd)
Returns a random non zero element from this ringlong
reciprocal(long val)
Returns modular inverse ofval
long
subtract(long a, long b)
Subtract mod operationlong
symmetricForm(long value)
to symmetric modulusString
toString()
-
Field Details
-
modulus
public final long modulusthe modulus -
magic
public final cc.redberry.libdivide4j.FastDivision.Magic magicmagic -
magic32MulMod
public final cc.redberry.libdivide4j.FastDivision.Magic magic32MulModmagic -
modulusFits32
public final boolean modulusFits32whether 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)Returnsval % this.modulus
-
modulus
Returnsval % this.modulus
-
modulus
public void modulus(long[] data)Inplace sets elements ofdata
todata % 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 ofval
-
negate
public long negate(long val)Negate mod operation -
symmetricForm
public long symmetricForm(long value)to symmetric modulus -
asGenericRing
Converts this to a generic ring over big integers- Returns:
- generic ring
-
powMod
public long powMod(long base, long exponent)Returnsbase
in a power of non-negativee
modulomagic.modulus
- Parameters:
base
- the baseexponent
- the non-negative exponent- Returns:
base
in a power ofe
-
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()Returnsbase
ifmodulus == base^exponent
, and-1
otherwisec- Returns:
base
ifmodulus == base^exponent
, and-1
otherwisec
-
perfectPowerExponent
public long perfectPowerExponent()Returnsexponent
ifmodulus == base^exponent
, and-1
otherwisec- Returns:
exponent
ifmodulus == base^exponent
, and-1
otherwisec
-
perfectPowerBaseDomain
Returns ring forperfectPowerBase()
orthis
if modulus is not a perfect power- Returns:
- ring for
perfectPowerBase()
orthis
if modulus is not a perfect power
-
equals
-
toString
-
hashCode
public int hashCode()
-