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.Magicmagicmagiccc.redberry.libdivide4j.FastDivision.Magicmagic32MulModmagiclongmodulusthe modulusbooleanmodulusFits32whether 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longadd(long a, long b)Add mod operationIntegersZpasGenericRing()Converts this to a generic ring over big integersvoidbuildCachedReciprocals()builds a table of cached reciprocalslongdivide(long a, long b)Subtract mod operationbooleanequals(Object o)longfactorial(int value)Gives value!inthashCode()booleanisPerfectPower()Returns whether the modulus is a perfect powerlongmodulus(long val)Returnsval % this.modulusvoidmodulus(long[] data)Inplace sets elements ofdatatodata % this.moduluslongmodulus(BigInteger val)Returnsval % this.moduluslongmultiply(long a, long b)Multiply mod operationlongnegate(long val)Negate mod operationlongperfectPowerBase()Returnsbaseifmodulus == base^exponent, and-1otherwisecIntegersZp64perfectPowerBaseDomain()Returns ring forperfectPowerBase()orthisif modulus is not a perfect powerlongperfectPowerExponent()Returnsexponentifmodulus == base^exponent, and-1otherwiseclongpowMod(long base, long exponent)Returnsbasein a power of non-negativeemodulomagic.moduluslongrandomElement()Returns a random element from this ringlongrandomElement(org.apache.commons.math3.random.RandomGenerator rnd)Returns a random element from this ringlongrandomNonZeroElement(org.apache.commons.math3.random.RandomGenerator rnd)Returns a random non zero element from this ringlongreciprocal(long val)Returns modular inverse ofvallongsubtract(long a, long b)Subtract mod operationlongsymmetricForm(long value)to symmetric modulusStringtoString()
-
-
-
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)
-
-
Method Detail
-
modulus
public long modulus(long val)
Returnsval % this.modulus
-
modulus
public long modulus(BigInteger val)
Returnsval % this.modulus
-
modulus
public void modulus(long[] data)
Inplace sets elements ofdatatodata % 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
public IntegersZp asGenericRing()
Converts this to a generic ring over big integers- Returns:
- generic ring
-
powMod
public long powMod(long base, long exponent)Returnsbasein a power of non-negativeemodulomagic.modulus- Parameters:
base- the baseexponent- the non-negative exponent- Returns:
basein 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()
Returnsbaseifmodulus == base^exponent, and-1otherwisec- Returns:
baseifmodulus == base^exponent, and-1otherwisec
-
perfectPowerExponent
public long perfectPowerExponent()
Returnsexponentifmodulus == base^exponent, and-1otherwisec- Returns:
exponentifmodulus == base^exponent, and-1otherwisec
-
perfectPowerBaseDomain
public IntegersZp64 perfectPowerBaseDomain()
Returns ring forperfectPowerBase()orthisif modulus is not a perfect power- Returns:
- ring for
perfectPowerBase()orthisif modulus is not a perfect power
-
-