Package cc.redberry.rings
Class IntegersZp
- java.lang.Object
-
- cc.redberry.rings.ARing<BigInteger>
-
- cc.redberry.rings.IntegersZp
-
- All Implemented Interfaces:
IParser<BigInteger>,Stringifiable<BigInteger>,Ring<BigInteger>,Serializable,Iterable<BigInteger>,Comparator<BigInteger>
public final class IntegersZp extends ARing<BigInteger>
Ring of integers modulo somemodulus.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description BigIntegermodulusThe modulus.
-
Constructor Summary
Constructors Constructor Description IntegersZp(long modulus)Creates Zp ring for specified modulus.IntegersZp(BigInteger modulus)Creates Zp ring for specified modulus.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BigIntegeradd(BigInteger a, BigInteger b)Add two elementsIntegersZp64asMachineRing()Converts to aIntegersZp64IntegersZp64asZp64()Returns machine integer ring or null if modulus is larger thanlongBigIntegercardinality()Returns the number of elements in this ring (cardinality) or null if ring is infiniteBigIntegercharacteristic()Returns characteristic of this ringintcompare(BigInteger o1, BigInteger o2)BigIntegercopy(BigInteger element)Makes a deep copy of the specified element (for immutable instances the same reference returned).BigInteger[]createArray(int length)Creates generic array of ring elements of specified lengthBigInteger[][]createArray2d(int length)Creates 2d array of ring elements of specified lengthBigInteger[][]createArray2d(int m, int n)Creates 2d array of ring elements of specified shapeBigIntegerdivide(BigInteger a, BigInteger b)BigInteger[]divideAndRemainder(BigInteger a, BigInteger b)Returns quotient and remainder ofdividend / dividerbooleanequals(Object o)FactorDecomposition<BigInteger>factor(BigInteger element)Factor specified elementFactorDecomposition<BigInteger>factorSquareFree(BigInteger element)Square-free factorization of specified elementBigIntegergetOne()Returns unit element of this ring (one)BigIntegergetZero()Returns zero element of this ringinthashCode()booleanisEuclideanRing()Returns whether this ring is a Euclidean ringbooleanisField()Returns whether this ring is a fieldbooleanisOne(BigInteger element)Tests whether specified element is one (exactly)booleanisUnit(BigInteger element)Tests whether specified element is a ring unitbooleanisZero(BigInteger element)Tests whether specified element is zeroIterator<BigInteger>iterator()Returns iterator over ring elements (for finite rings, otherwise throws exception)BigIntegermodulus(BigInteger val)Returnsval mod this.modulusBigIntegermultiply(BigInteger a, BigInteger b)Multiplies two elementsBigIntegernegate(BigInteger element)Negates the given elementBigIntegerparse(String string)Parse string into ring elementIntegersZpperfectPowerBaseDomain()Returns ring forARing.perfectPowerBase()orthisif modulus is not a perfect powerBigIntegerrandomElement(org.apache.commons.math3.random.RandomGenerator rnd)Returns a random element from this ringBigIntegerreciprocal(BigInteger element)Gives the inverse elementelement ^ (-1)BigIntegerremainder(BigInteger a, BigInteger b)Returns the remainder ofdividend / dividerBigIntegersubtract(BigInteger a, BigInteger b)SubtractsbfromaBigIntegersymmetricForm(BigInteger value)Convertsvalueto a symmetric representation of ZpStringtoString()BigIntegervalueOf(long val)Returns ring element associated with specifiedlongBigIntegervalueOf(BigInteger val)Converts a value from other ring to this ring.BigIntegervalueOfBigInteger(BigInteger val)Returns ring element associated with specified integer-
Methods inherited from class cc.redberry.rings.ARing
isPerfectPower, perfectPowerBase, perfectPowerExponent
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface cc.redberry.rings.Ring
abs, add, addMutable, createArray, createArray, createArray, createZeroesArray, createZeroesArray2d, decrement, divideExact, divideExactMutable, divideOrNull, extendedGCD, factorial, fillZeros, firstBezoutCoefficient, gcd, gcd, gcd, getNegativeOne, increment, isFinite, isFiniteField, isMinusOne, isUnitOrZero, lcm, lcm, lcm, max, min, multiply, multiply, multiply, multiplyMutable, negateMutable, pow, pow, pow, quotient, randomElement, randomElementTree, randomElementTree, randomNonZeroElement, setToValueOf, signum, subtractMutable, valueOf
-
Methods inherited from interface cc.redberry.rings.io.Stringifiable
toString
-
-
-
-
Field Detail
-
modulus
public final BigInteger modulus
The modulus.
-
-
Constructor Detail
-
IntegersZp
public IntegersZp(BigInteger modulus)
Creates Zp ring for specified modulus.- Parameters:
modulus- the modulus
-
IntegersZp
public IntegersZp(long modulus)
Creates Zp ring for specified modulus.- Parameters:
modulus- the modulus
-
-
Method Detail
-
isField
public boolean isField()
Description copied from interface:RingReturns whether this ring is a field- Returns:
- whether this ring is a field
-
isEuclideanRing
public boolean isEuclideanRing()
Description copied from interface:RingReturns whether this ring is a Euclidean ring- Returns:
- whether this ring is a Euclidean ring
-
cardinality
public BigInteger cardinality()
Description copied from interface:RingReturns the number of elements in this ring (cardinality) or null if ring is infinite- Returns:
- the number of elements in this ring (cardinality) or null if ring is infinite
-
characteristic
public BigInteger characteristic()
Description copied from interface:RingReturns characteristic of this ring- Returns:
- characteristic of this ring
-
isUnit
public boolean isUnit(BigInteger element)
Description copied from interface:RingTests whether specified element is a ring unit- Parameters:
element- the ring element- Returns:
- whether specified element is a ring unit
- See Also:
Ring.isOne(Object)
-
modulus
public BigInteger modulus(BigInteger val)
Returnsval mod this.modulus- Parameters:
val- the integer- Returns:
val mod this.modulus
-
symmetricForm
public BigInteger symmetricForm(BigInteger value)
Convertsvalueto a symmetric representation of Zp- Parameters:
value- field element- Returns:
valuein a symmetric representation of Zp
-
asMachineRing
public IntegersZp64 asMachineRing()
Converts to aIntegersZp64
-
add
public BigInteger add(BigInteger a, BigInteger b)
Description copied from interface:RingAdd two elements- Parameters:
a- the first elementb- the second element- Returns:
- a + b
-
subtract
public BigInteger subtract(BigInteger a, BigInteger b)
Description copied from interface:RingSubtractsbfroma- Parameters:
a- the first elementb- the second element- Returns:
- a - b
-
negate
public BigInteger negate(BigInteger element)
Description copied from interface:RingNegates the given element- Parameters:
element- the ring element- Returns:
- -val
-
multiply
public BigInteger multiply(BigInteger a, BigInteger b)
Description copied from interface:RingMultiplies two elements- Parameters:
a- the first elementb- the second element- Returns:
- a * b
-
divideAndRemainder
public BigInteger[] divideAndRemainder(BigInteger a, BigInteger b)
Description copied from interface:RingReturns quotient and remainder ofdividend / divider- Parameters:
a- the dividendb- the divider- Returns:
{quotient, remainder}
-
divide
public BigInteger divide(BigInteger a, BigInteger b)
-
remainder
public BigInteger remainder(BigInteger a, BigInteger b)
Description copied from interface:RingReturns the remainder ofdividend / divider- Parameters:
a- the dividendb- the divider- Returns:
- the remainder of
dividend / divider
-
reciprocal
public BigInteger reciprocal(BigInteger element)
Description copied from interface:RingGives the inverse elementelement ^ (-1)- Parameters:
element- the element- Returns:
element ^ (-1)
-
factorSquareFree
public FactorDecomposition<BigInteger> factorSquareFree(BigInteger element)
Description copied from interface:RingSquare-free factorization of specified element
-
factor
public FactorDecomposition<BigInteger> factor(BigInteger element)
Description copied from interface:RingFactor specified element
-
valueOf
public BigInteger valueOf(BigInteger val)
Description copied from interface:RingConverts a value from other ring to this ring. The result is not guarantied to be a new instance (i.e.val == valueOf(val)is possible).- Parameters:
val- some element from any ring- Returns:
- this ring element associated with specified
val
-
valueOf
public BigInteger valueOf(long val)
Description copied from interface:RingReturns ring element associated with specifiedlong- Parameters:
val- machine integer- Returns:
- ring element associated with specified
long
-
randomElement
public BigInteger randomElement(org.apache.commons.math3.random.RandomGenerator rnd)
Description copied from interface:RingReturns a random element from this ring- Parameters:
rnd- the source of randomness- Returns:
- random element from this ring
-
iterator
public Iterator<BigInteger> iterator()
Description copied from interface:RingReturns iterator over ring elements (for finite rings, otherwise throws exception)
-
perfectPowerBaseDomain
public IntegersZp perfectPowerBaseDomain()
Returns ring forARing.perfectPowerBase()orthisif modulus is not a perfect power- Returns:
- ring for
ARing.perfectPowerBase()orthisif modulus is not a perfect power
-
asZp64
public IntegersZp64 asZp64()
Returns machine integer ring or null if modulus is larger thanlong- Returns:
- machine integer ring or null if modulus is larger than
long
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceComparator<BigInteger>- Overrides:
equalsin classObject
-
getZero
public final BigInteger getZero()
Description copied from interface:RingReturns zero element of this ring- Returns:
- 0
-
getOne
public final BigInteger getOne()
Description copied from interface:RingReturns unit element of this ring (one)- Returns:
- 1
-
isZero
public final boolean isZero(BigInteger element)
Description copied from interface:RingTests whether specified element is zero- Parameters:
element- the ring element- Returns:
- whether specified element is zero
-
isOne
public final boolean isOne(BigInteger element)
Description copied from interface:RingTests whether specified element is one (exactly)- Parameters:
element- the ring element- Returns:
- whether specified element is exactly one
- See Also:
Ring.isUnit(Object)
-
parse
public final BigInteger parse(String string)
Description copied from interface:RingParse string into ring element- Parameters:
string- string- Returns:
- ring element
- See Also:
Coder
-
compare
public final int compare(BigInteger o1, BigInteger o2)
-
createArray
public final BigInteger[] createArray(int length)
Description copied from interface:RingCreates generic array of ring elements of specified length- Parameters:
length- array length- Returns:
- array of ring elements of specified
length
-
createArray2d
public final BigInteger[][] createArray2d(int length)
Description copied from interface:RingCreates 2d array of ring elements of specified length- Parameters:
length- array length- Returns:
- 2d array of ring elements of specified
length
-
createArray2d
public final BigInteger[][] createArray2d(int m, int n)
Description copied from interface:RingCreates 2d array of ring elements of specified shape- Parameters:
m- result lengthn- length of each array in the result- Returns:
- 2d array E[m][n]
-
valueOfBigInteger
public final BigInteger valueOfBigInteger(BigInteger val)
Description copied from interface:RingReturns ring element associated with specified integer- Parameters:
val- integer- Returns:
- ring element associated with specified integer
-
copy
public BigInteger copy(BigInteger element)
Description copied from interface:RingMakes a deep copy of the specified element (for immutable instances the same reference returned).- Parameters:
element- the element- Returns:
- deep copy of specified element
-
-