Package cc.redberry.rings.poly.univar
Class UnivariatePolynomialZp64
- java.lang.Object
-
- cc.redberry.rings.poly.univar.UnivariatePolynomialZp64
-
- All Implemented Interfaces:
Stringifiable<UnivariatePolynomialZp64>,IPolynomial<UnivariatePolynomialZp64>,IUnivariatePolynomial<UnivariatePolynomialZp64>,Serializable,Comparable<UnivariatePolynomialZp64>
public final class UnivariatePolynomialZp64 extends Object
Univariate polynomial over Zp ring with modulus in the range of[2, 2^62)(the last value is specified byMachineArithmetic.MAX_SUPPORTED_MODULUS_BITS. Fast methods fromIntegersZp64are used to perform all arithmetic operations.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description IntegersZp64ringThe coefficient ring
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description lPolyadd(long val)Add constant to this.lPolyadd(lPoly oth)Addsothtothis.lPolyaddMonomial(long coefficient, int exponent)Addscoefficient*x^exponenttothislPolyaddMul(lPoly oth, long factor)Addsoth * factortothisMultivariatePolynomialZp64asMultivariate()Convert to multivariate polynomialMultivariatePolynomialZp64asMultivariate(Comparator<DegreeVector> ordering)Convert to multivariate polynomialUnivariatePolynomialZ64asPolyZ(boolean copy)Returns Z[x] polynomial formed from the coefficients of this.UnivariatePolynomialZ64asPolyZSymmetric()Returns Z[x] polynomial formed from the coefficients of this represented in symmetric modular form (-modulus/2 <= cfx <= modulus/2).longcc()Returns the constant coefficient of this polylPolyccAsPoly()Returns the constant coefficient as a constant polyUnivariatePolynomialZp64clone()Deep copy of thisBigIntegercoefficientRingCardinality()Returns cardinality of the coefficient ring of this polyBigIntegercoefficientRingCharacteristic()Returns characteristic of the coefficient ring of this polyBigIntegercoefficientRingPerfectPowerBase()Returnsbaseso thatcoefficientRingCardinality() == base^exponentor null if cardinality is not finiteBigIntegercoefficientRingPerfectPowerExponent()Returnsexponentso thatcoefficientRingCardinality() == base^exponentor null if cardinality is not finiteStringcoefficientRingToString(IStringifier<UnivariatePolynomialZp64> stringifier)String representation of the coefficient ring of thisintcompareTo(lPoly o)MultivariatePolynomialZp64composition(AMultivariatePolynomial value)Calculates the composition of this(oth)lPolycomposition(lPoly value)Calculates the composition of this(oth) (new instance, so the content of this is not changed))static UnivariatePolynomialZp64constant(long modulus, long value)Creates constant polynomial with specified valuestatic UnivariatePolynomialZp64constant(IntegersZp64 ring, long value)Creates constant polynomial with specified valuelongcontent()Returns the content of this poly (gcd of its coefficients)lPolycontentAsPoly()Returns the content of this (gcd of coefficients) as a constant polystatic UnivariatePolynomialZp64create(long modulus, long[] data)Creates poly with specified coefficients represented as signed integers reducing them modulomodulusstatic UnivariatePolynomialZp64create(IntegersZp64 ring, long[] data)Creates poly with specified coefficients represented as signed integers reducing them modulomodulusUnivariatePolynomialZp64[]createArray(int length)overcome Java generics...UnivariatePolynomialZp64[]createArray(UnivariatePolynomialZp64 a, UnivariatePolynomialZp64 b)overcome Java generics...UnivariatePolynomialZp64[][]createArray2d(int length)overcome Java generics...UnivariatePolynomialZp64[][]createArray2d(int length1, int length2)overcome Java generics...lPolycreateConstant(long val)Creates constant polynomial with specified value (with the same coefficient ring)UnivariatePolynomialZp64createFromArray(long[] newData)Creates new poly with the specified coefficients (over the same ring)lPolycreateLinear(long cc, long lc)Creates linear polynomial of formcc + x * lc(with the same coefficient ring)lPolycreateMonomial(int degree)Creates new monomialx^degree(with the same coefficient ring)UnivariatePolynomialZp64createMonomial(long coefficient, int newDegree)Creates monomialcoefficient * x^degree(with the same coefficient ring)lPolycreateOne()Returns the new instance of unit polynomial (with the same coefficient ring)static UnivariatePolynomialZp64createUnsafe(long modulus, long[] data)data is not reduced modulo modulusstatic UnivariatePolynomialZp64createUnsafe(IntegersZp64 ring, long[] data)data is not reduced modulo moduluslPolycreateZero()Returns the new instance of zero polynomial (with the same coefficient ring)lPolydecrement()Subtracts 1 from thisintdegree()Returns the degree of this polynomialUnivariatePolynomialZp64derivative()Returns the formal derivative of this poly (new instance, so the content of this is not changed)UnivariatePolynomialZp64divide(long val)Divide by specified valueUnivariatePolynomialZp64divideByLC(UnivariatePolynomialZp64 other)Divides this polynomial by the leading coefficient ofotheror returnsnull(causing loss of internal data) if some of the elements can't be exactly divided by theother.lc().voidensureInternalCapacity(int desiredCapacity)ensures that internal storage has enough size to storedesiredCapacityelementsbooleanequals(Object obj)longevaluate(long point)Evaluates this poly at a givenpoint(via Horner method).intfirstNonZeroCoefficientPosition()Returns position of the first non-zero coefficient, that is common monomial exponent (e.g.longget(int i)Returns the i-th coefficient of this poly (coefficient before x^i)lPolygetAsPoly(int i)Returns i-th coefficient of this as a constant polynomiallong[]getDataReferenceUnsafe()internal API >>> direct unsafe access to internal storageUnivariatePolynomialZp64getRange(int from, int to)Creates polynomial formed from the coefficients of this starting fromfrom(inclusive) toto(exclusive)inthashCode()lPolyincrement()Adds 1 to thisbooleanisConstant()Returnstrueif this polynomial has only constant termbooleanisMonic()Returnstrueif this polynomial is monicbooleanisMonomial()Returnstrueif this polynomial has only one monomial termbooleanisOne()Returnstrueif this is onebooleanisOverField()Returns whether the coefficient ring of this polynomial is a fieldbooleanisOverFiniteField()Returns whether the coefficient ring of this polynomial is a finite fieldbooleanisOverPerfectPower()Returns whether thecoefficientRingCardinality()is a perfect powerbooleanisOverZ()Returns whether the coefficient ring of this polynomial is ZbooleanisUnitCC()Returns true if constant term is equal to onebooleanisZero()Returnstrueif this is zerobooleanisZeroAt(int i)Returns whether i-th coefficient of this is zerolonglc()Returns the leading coefficient of this polylPolylcAsPoly()Returns the leading coefficient as a constant polystatic UnivariatePolynomialZp64linear(long cc, long lc, long modulus)Creates linear polynomial of formcc + x * lc<T> UnivariatePolynomial<T>mapCoefficients(Ring<T> ring, LongFunction<T> mapper)Applies transformation function to this and returns the result.longmaxAbsCoefficient()Returns max coefficient (by absolute value) of this polylongmodulus()Returns the modulusUnivariatePolynomialZp64monic()Setsthisto its monic part (that isthisdivided by its leading coefficient), or returnsnull(causing loss of internal data) if some of the elements can't be exactly divided by thelc().UnivariatePolynomialZp64monic(long factor)Setsthisto its monic part multiplied by thefactor(that ismonic(modulus).multiply(factor)).lPolymonicWithLC(lPoly other)Setsthisto its monic part multiplied by the leading coefficient ofother;static UnivariatePolynomialZp64monomial(long modulus, long coefficient, int exponent)Creates monomialcoefficient * x^exponentlPolymultiply(long factor)Multiplies this byfactorUnivariatePolynomialZp64multiply(UnivariatePolynomialZp64 oth)Multiplies this byothUnivariatePolynomialZp64multiplyByBigInteger(BigInteger factor)Multiplies this byfactorlPolymultiplyByLC(lPoly other)Multiply this by the leading coefficient ofotherlPolynegate()Negates this and returnsdoublenorm1()Returns L1 norm of this polynomial, i.e.doublenorm2()Returns L2 norm of this polynomial, i.e.doublenormMax()Returns max coefficient (by absolute value) of this polystatic UnivariatePolynomialZp64one(long modulus)Creates unit polynomialstatic UnivariatePolynomialZp64one(IntegersZp64 ring)Creates unit polynomialstatic UnivariatePolynomialZp64parse(String string, long modulus)Deprecated.static UnivariatePolynomialZp64parse(String string, IntegersZp64 modulus)Deprecated.static UnivariatePolynomialZp64parse(String string, IntegersZp64 modulus, String variable)Parse string into polynomialUnivariatePolynomialZp64parsePoly(String string)lPolyprimitivePart()Reduces poly to its primitive part (primitive part will always have positive l.c.)lPolyprimitivePartSameSign()Reduces poly to its primitive part, so that primitive part will have the same signum as the initial polylPolyreverse()Reverses the coefficients of thisbooleansameCoefficientRingWith(UnivariatePolynomialZp64 oth)Returns whetherothandthishave the same coefficient ringlPolyset(int i, long el)Sets i-th element of this poly with the specified valuelPolyset(lPoly oth)Sets the content of this toothlPolysetAndDestroy(lPoly oth)Sets the content of this withothand destroys othUnivariatePolynomialZp64setCoefficientRingFrom(UnivariatePolynomialZp64 univariatePolynomialZp64)Set the coefficient ring from specified polylPolysetFrom(int indexInThis, lPoly poly, int indexInPoly)Sets i-th element of this by j-th element of other polylPolysetLC(long lc)Sets hte leading coefficient of this poly with specified valueUnivariatePolynomialZp64setModulus(long newModulus)Creates new Zp[x] polynomial by coping the coefficients of this and reducing them modulo new modulus.UnivariatePolynomialZp64setModulus(IntegersZp64 newDomain)Creates new Zp[x] polynomial by coping the coefficients of this and reducing them modulo new modulus.UnivariatePolynomialZp64setModulusUnsafe(long newModulus)does not copy the data and does not reduce the data with new modulusUnivariatePolynomialZp64setModulusUnsafe(IntegersZp64 newModulus)does not copy the data and does not reduce the data with new moduluslPolysetZero(int i)Fills i-th element with zerolPolyshift(long value)Shifts variable x -> x + value and returns the result (new instance)lPolyshiftLeft(int offset)Returns the quotientthis / x^offset, it is polynomial with coefficient list formed by shifting coefficients ofthisto the left byoffset.lPolyshiftRight(int offset)Multipliesthisby thex^offset.intsignumOfLC()Gives signum of the leading coefficientUnivariatePolynomialZp64square()SquaresthisLongStreamstream()Returns a sequentialStreamwith coefficients of this as its source.Stream<lPoly>streamAsPolys()Stream polynomial coefficients as constant polynomialslPolysubtract(long val)Subtract constant from this.lPolysubtract(lPoly oth)Subtractsothfromthis.lPolysubtract(lPoly oth, long factor, int exponent)Subtractsfactor * x^exponent * othfromthisUnivariatePolynomial<BigInteger>toBigPoly()Converts this to a polynomial over BigIntegersStringtoString()StringtoString(IStringifier<lPoly> stringifier)convert this to string with the use of stringifierStringtoStringForCopy()lPolytoZero()Sets this to zerolPolytruncate(int newDegree)Returns the remainderthis rem x^(newDegree + 1), it is polynomial formed by coefficients of this from zero tonewDegree(both inclusive)static UnivariatePolynomialZp64zero(long modulus)Creates zero polynomialstatic UnivariatePolynomialZp64zero(IntegersZp64 ring)Creates zero polynomial-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface cc.redberry.rings.poly.IPolynomial
add, assertSameCoefficientRingWith, canonical, coefficientRingToString, copy, createArray, createArray, monicExact, multiply, multiply, setCoefficientRingFromOptional, subtract, toPositiveLC, toString
-
Methods inherited from interface cc.redberry.rings.poly.univar.IUnivariatePolynomial
composition, exponents, isLinearExactly, isLinearOrConstant, isZeroCC, mapCoefficientsAsPolys, nNonZeroTerms, size
-
-
-
-
Field Detail
-
ring
public final IntegersZp64 ring
The coefficient ring
-
-
Method Detail
-
parse
@Deprecated public static UnivariatePolynomialZp64 parse(String string, long modulus)
Deprecated.Parse string into polynomial
-
parse
@Deprecated public static UnivariatePolynomialZp64 parse(String string, IntegersZp64 modulus)
Deprecated.Parse string into polynomial
-
parse
public static UnivariatePolynomialZp64 parse(String string, IntegersZp64 modulus, String variable)
Parse string into polynomial
-
create
public static UnivariatePolynomialZp64 create(long modulus, long[] data)
Creates poly with specified coefficients represented as signed integers reducing them modulomodulus- Parameters:
modulus- the modulusdata- coefficients- Returns:
- the polynomial
-
create
public static UnivariatePolynomialZp64 create(IntegersZp64 ring, long[] data)
Creates poly with specified coefficients represented as signed integers reducing them modulomodulus- Parameters:
ring- the ringdata- coefficients- Returns:
- the polynomial
-
linear
public static UnivariatePolynomialZp64 linear(long cc, long lc, long modulus)
Creates linear polynomial of formcc + x * lc- Parameters:
cc- the constant coefficientlc- the leading coefficientmodulus- the modulus- Returns:
cc + x * lc
-
createUnsafe
public static UnivariatePolynomialZp64 createUnsafe(long modulus, long[] data)
data is not reduced modulo modulus
-
createUnsafe
public static UnivariatePolynomialZp64 createUnsafe(IntegersZp64 ring, long[] data)
data is not reduced modulo modulus
-
monomial
public static UnivariatePolynomialZp64 monomial(long modulus, long coefficient, int exponent)
Creates monomialcoefficient * x^exponent- Parameters:
modulus- the moduluscoefficient- monomial coefficientexponent- monomial exponent- Returns:
coefficient * x^exponent
-
constant
public static UnivariatePolynomialZp64 constant(long modulus, long value)
Creates constant polynomial with specified value- Parameters:
modulus- the modulusvalue- the value- Returns:
- constant polynomial
-
constant
public static UnivariatePolynomialZp64 constant(IntegersZp64 ring, long value)
Creates constant polynomial with specified value- Parameters:
ring- the ringvalue- the value- Returns:
- constant polynomial
-
zero
public static UnivariatePolynomialZp64 zero(long modulus)
Creates zero polynomial- Parameters:
modulus- the modulus- Returns:
- zero polynomial
-
zero
public static UnivariatePolynomialZp64 zero(IntegersZp64 ring)
Creates zero polynomial- Parameters:
ring- the ring- Returns:
- zero polynomial
-
one
public static UnivariatePolynomialZp64 one(long modulus)
Creates unit polynomial- Parameters:
modulus- the modulus- Returns:
- unit polynomial
-
one
public static UnivariatePolynomialZp64 one(IntegersZp64 ring)
Creates unit polynomial- Parameters:
ring- the ring- Returns:
- unit polynomial
-
setCoefficientRingFrom
public UnivariatePolynomialZp64 setCoefficientRingFrom(UnivariatePolynomialZp64 univariatePolynomialZp64)
Description copied from interface:IPolynomialSet the coefficient ring from specified poly- Parameters:
univariatePolynomialZp64- the polynomial- Returns:
- a copy of this with the coefficient ring taken from
poly
-
modulus
public long modulus()
Returns the modulus
-
setModulusUnsafe
public UnivariatePolynomialZp64 setModulusUnsafe(long newModulus)
does not copy the data and does not reduce the data with new modulus
-
setModulusUnsafe
public UnivariatePolynomialZp64 setModulusUnsafe(IntegersZp64 newModulus)
does not copy the data and does not reduce the data with new modulus
-
setModulus
public UnivariatePolynomialZp64 setModulus(long newModulus)
Creates new Zp[x] polynomial by coping the coefficients of this and reducing them modulo new modulus.- Parameters:
newModulus- the new modulus- Returns:
- the copy of this reduced modulo new modulus
-
setModulus
public UnivariatePolynomialZp64 setModulus(IntegersZp64 newDomain)
Creates new Zp[x] polynomial by coping the coefficients of this and reducing them modulo new modulus.- Parameters:
newDomain- the new domain- Returns:
- the copy of this reduced modulo new modulus
-
asPolyZSymmetric
public UnivariatePolynomialZ64 asPolyZSymmetric()
Returns Z[x] polynomial formed from the coefficients of this represented in symmetric modular form (-modulus/2 <= cfx <= modulus/2).- Returns:
- Z[x] version of this with coefficients represented in symmetric modular form (
-modulus/2 <= cfx <= modulus/2).
-
asPolyZ
public UnivariatePolynomialZ64 asPolyZ(boolean copy)
Returns Z[x] polynomial formed from the coefficients of this.- Parameters:
copy- whether to copy the internal data- Returns:
- Z[x] version of this
-
createArray
public UnivariatePolynomialZp64[] createArray(int length)
Description copied from interface:IPolynomialovercome Java generics...
-
createArray
public UnivariatePolynomialZp64[] createArray(UnivariatePolynomialZp64 a, UnivariatePolynomialZp64 b)
Description copied from interface:IPolynomialovercome Java generics...
-
createArray2d
public UnivariatePolynomialZp64[][] createArray2d(int length)
Description copied from interface:IPolynomialovercome Java generics...
-
createArray2d
public UnivariatePolynomialZp64[][] createArray2d(int length1, int length2)
Description copied from interface:IPolynomialovercome Java generics...
-
getRange
public UnivariatePolynomialZp64 getRange(int from, int to)
Description copied from interface:IUnivariatePolynomialCreates polynomial formed from the coefficients of this starting fromfrom(inclusive) toto(exclusive)- Parameters:
from- the initial index of the range to be copied, inclusiveto- the final index of the range to be copied, exclusive.- Returns:
- polynomial formed from the range of coefficients of this
-
sameCoefficientRingWith
public boolean sameCoefficientRingWith(UnivariatePolynomialZp64 oth)
Description copied from interface:IPolynomialReturns whetherothandthishave the same coefficient ring- Parameters:
oth- other polynomial- Returns:
- whether this and oth are over the same coefficient ring
-
createFromArray
public UnivariatePolynomialZp64 createFromArray(long[] newData)
Creates new poly with the specified coefficients (over the same ring)- Parameters:
newData- the data- Returns:
- polynomial
-
createMonomial
public UnivariatePolynomialZp64 createMonomial(long coefficient, int newDegree)
Creates monomialcoefficient * x^degree(with the same coefficient ring)- Parameters:
coefficient- monomial coefficientnewDegree- monomial degree- Returns:
coefficient * x^degree
-
isOverField
public boolean isOverField()
Description copied from interface:IPolynomialReturns whether the coefficient ring of this polynomial is a field- Returns:
- whether the coefficient ring of this polynomial is a field
-
isOverFiniteField
public boolean isOverFiniteField()
Description copied from interface:IPolynomialReturns whether the coefficient ring of this polynomial is a finite field- Returns:
- whether the coefficient ring of this polynomial is a finite field
-
isOverZ
public boolean isOverZ()
Description copied from interface:IPolynomialReturns whether the coefficient ring of this polynomial is Z- Returns:
- whether the coefficient ring of this polynomial is Z
-
coefficientRingCardinality
public BigInteger coefficientRingCardinality()
Description copied from interface:IPolynomialReturns cardinality of the coefficient ring of this poly- Returns:
- cardinality of the coefficient ring
-
coefficientRingCharacteristic
public BigInteger coefficientRingCharacteristic()
Description copied from interface:IPolynomialReturns characteristic of the coefficient ring of this poly- Returns:
- characteristic of the coefficient ring
-
isOverPerfectPower
public boolean isOverPerfectPower()
Description copied from interface:IPolynomialReturns whether thecoefficientRingCardinality()is a perfect power- Returns:
- whether the
coefficientRingCardinality()is a perfect power
-
coefficientRingPerfectPowerBase
public BigInteger coefficientRingPerfectPowerBase()
Description copied from interface:IPolynomialReturnsbaseso thatcoefficientRingCardinality() == base^exponentor null if cardinality is not finite- Returns:
baseso thatcoefficientRingCardinality() == base^exponentor null if cardinality is not finite
-
coefficientRingPerfectPowerExponent
public BigInteger coefficientRingPerfectPowerExponent()
Description copied from interface:IPolynomialReturnsexponentso thatcoefficientRingCardinality() == base^exponentor null if cardinality is not finite- Returns:
exponentso thatcoefficientRingCardinality() == base^exponentor null if cardinality is not finite
-
content
public long content()
Returns the content of this poly (gcd of its coefficients)- Returns:
- polynomial content
-
monic
public UnivariatePolynomialZp64 monic()
Description copied from interface:IPolynomialSetsthisto its monic part (that isthisdivided by its leading coefficient), or returnsnull(causing loss of internal data) if some of the elements can't be exactly divided by thelc(). NOTE: ifnullis returned, the content ofthisis destroyed.- Returns:
- monic
thisornull
-
monic
public UnivariatePolynomialZp64 monic(long factor)
Setsthisto its monic part multiplied by thefactor(that ismonic(modulus).multiply(factor)).- Parameters:
factor- the factor- Returns:
this
-
divideByLC
public UnivariatePolynomialZp64 divideByLC(UnivariatePolynomialZp64 other)
Description copied from interface:IPolynomialDivides this polynomial by the leading coefficient ofotheror returnsnull(causing loss of internal data) if some of the elements can't be exactly divided by theother.lc(). NOTE: ifnullis returned, the content ofthisis destroyed.- Parameters:
other- the polynomial- Returns:
thisdivided by theother.lc()ornullif exact division is not possible
-
divide
public UnivariatePolynomialZp64 divide(long val)
Divide by specified value- Parameters:
val- the value- Returns:
this / val
-
multiplyByBigInteger
public UnivariatePolynomialZp64 multiplyByBigInteger(BigInteger factor)
Description copied from interface:IPolynomialMultiplies this byfactor- Parameters:
factor- the factor- Returns:
this * factor
-
multiply
public UnivariatePolynomialZp64 multiply(UnivariatePolynomialZp64 oth)
Description copied from interface:IPolynomialMultiplies this byoth- Parameters:
oth- the polynomial- Returns:
this * oth
-
square
public UnivariatePolynomialZp64 square()
Description copied from interface:IPolynomialSquaresthis- Returns:
this * this
-
derivative
public UnivariatePolynomialZp64 derivative()
Description copied from interface:IUnivariatePolynomialReturns the formal derivative of this poly (new instance, so the content of this is not changed)- Returns:
- the formal derivative
-
toBigPoly
public UnivariatePolynomial<BigInteger> toBigPoly()
Converts this to a polynomial over BigIntegers. The ring of the result will be exactly those returned bythis.ring.asGenericRing()- Returns:
- polynomial over BigIntegers
-
clone
public UnivariatePolynomialZp64 clone()
Description copied from interface:IPolynomialDeep copy of this- Specified by:
clonein interfaceIPolynomial<UnivariatePolynomialZp64>- Specified by:
clonein interfaceIUnivariatePolynomial<UnivariatePolynomialZp64>- Returns:
- deep copy of this
-
parsePoly
public UnivariatePolynomialZp64 parsePoly(String string)
-
coefficientRingToString
public String coefficientRingToString(IStringifier<UnivariatePolynomialZp64> stringifier)
Description copied from interface:IPolynomialString representation of the coefficient ring of this
-
composition
public MultivariatePolynomialZp64 composition(AMultivariatePolynomial value)
Description copied from interface:IUnivariatePolynomialCalculates the composition of this(oth)- Parameters:
value- polynomial- Returns:
- composition
this(oth)
-
asMultivariate
public MultivariatePolynomialZp64 asMultivariate()
Description copied from interface:IUnivariatePolynomialConvert to multivariate polynomial
-
asMultivariate
public MultivariatePolynomialZp64 asMultivariate(Comparator<DegreeVector> ordering)
Description copied from interface:IUnivariatePolynomialConvert to multivariate polynomial
-
degree
public final int degree()
Description copied from interface:IPolynomialReturns the degree of this polynomial- Specified by:
degreein interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- the degree
-
get
public final long get(int i)
Returns the i-th coefficient of this poly (coefficient before x^i)
-
set
public final lPoly set(int i, long el)Sets i-th element of this poly with the specified value
-
setLC
public final lPoly setLC(long lc)
Sets hte leading coefficient of this poly with specified value
-
firstNonZeroCoefficientPosition
public final int firstNonZeroCoefficientPosition()
Description copied from interface:IUnivariatePolynomialReturns position of the first non-zero coefficient, that is common monomial exponent (e.g. 2 for x^2 + x^3 + ...). In the case of zero polynomial, -1 returned- Specified by:
firstNonZeroCoefficientPositionin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- position of the first non-zero coefficient or -1 if this is zero
-
lc
public final long lc()
Returns the leading coefficient of this poly- Returns:
- leading coefficient
-
lcAsPoly
public final lPoly lcAsPoly()
Description copied from interface:IPolynomialReturns the leading coefficient as a constant poly- Specified by:
lcAsPolyin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>
-
ccAsPoly
public final lPoly ccAsPoly()
Description copied from interface:IPolynomialReturns the constant coefficient as a constant poly- Specified by:
ccAsPolyin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>
-
getAsPoly
public lPoly getAsPoly(int i)
Description copied from interface:IUnivariatePolynomialReturns i-th coefficient of this as a constant polynomial- Specified by:
getAsPolyin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
i- index in this- Returns:
- i-th coefficient of this as a constant polynomial
-
cc
public final long cc()
Returns the constant coefficient of this poly- Returns:
- constant coefficient
-
ensureInternalCapacity
public final void ensureInternalCapacity(int desiredCapacity)
Description copied from interface:IUnivariatePolynomialensures that internal storage has enough size to storedesiredCapacityelements- Specified by:
ensureInternalCapacityin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>
-
createMonomial
public final lPoly createMonomial(int degree)
Description copied from interface:IUnivariatePolynomialCreates new monomialx^degree(with the same coefficient ring)- Specified by:
createMonomialin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
degree- monomial degree- Returns:
- new monomial
coefficient * x^degree
-
createLinear
public final lPoly createLinear(long cc, long lc)Creates linear polynomial of formcc + x * lc(with the same coefficient ring)- Parameters:
cc- the constant coefficientlc- the leading coefficient- Returns:
cc + x * lc
-
createConstant
public final lPoly createConstant(long val)
Creates constant polynomial with specified value (with the same coefficient ring)- Specified by:
createConstantin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
val- the value- Returns:
- constant polynomial with specified value
-
createZero
public final lPoly createZero()
Description copied from interface:IPolynomialReturns the new instance of zero polynomial (with the same coefficient ring)- Specified by:
createZeroin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- new instance of 0
-
createOne
public final lPoly createOne()
Description copied from interface:IPolynomialReturns the new instance of unit polynomial (with the same coefficient ring)- Specified by:
createOnein interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- new instance of 1
-
isZeroAt
public final boolean isZeroAt(int i)
Description copied from interface:IUnivariatePolynomialReturns whether i-th coefficient of this is zero- Specified by:
isZeroAtin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
i- the position- Returns:
- whether i-th coefficient of this is zero
-
setZero
public final lPoly setZero(int i)
Description copied from interface:IUnivariatePolynomialFills i-th element with zero- Specified by:
setZeroin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
i- position- Returns:
- self
-
setFrom
public final lPoly setFrom(int indexInThis, lPoly poly, int indexInPoly)Description copied from interface:IUnivariatePolynomialSets i-th element of this by j-th element of other poly- Specified by:
setFromin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
indexInThis- index in selfpoly- other polynomialindexInPoly- index in other polynomial- Returns:
- self
-
isZero
public final boolean isZero()
Description copied from interface:IPolynomialReturnstrueif this is zero- Specified by:
isZeroin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- whether
thisis zero
-
isOne
public final boolean isOne()
Description copied from interface:IPolynomialReturnstrueif this is one- Specified by:
isOnein interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- whether
thisis one
-
isMonic
public final boolean isMonic()
Description copied from interface:IPolynomialReturnstrueif this polynomial is monic- Specified by:
isMonicin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- whether
thisis monic
-
isUnitCC
public final boolean isUnitCC()
Description copied from interface:IPolynomialReturns true if constant term is equal to one- Specified by:
isUnitCCin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- whether constant term is 1
-
isConstant
public final boolean isConstant()
Description copied from interface:IPolynomialReturnstrueif this polynomial has only constant term- Specified by:
isConstantin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- whether
thisis constant
-
isMonomial
public final boolean isMonomial()
Description copied from interface:IPolynomialReturnstrueif this polynomial has only one monomial term- Specified by:
isMonomialin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- whether
thishas only one monomial term
-
signumOfLC
public final int signumOfLC()
Description copied from interface:IPolynomialGives signum of the leading coefficient- Specified by:
signumOfLCin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- signum of the leading coefficient
-
norm1
public final double norm1()
Returns L1 norm of this polynomial, i.e. sum of abs coefficients- Returns:
- L1 norm of
this
-
norm2
public final double norm2()
Returns L2 norm of this polynomial, i.e. a square root of a sum of coefficient squares.- Returns:
- L2 norm of
this
-
normMax
public final double normMax()
Returns max coefficient (by absolute value) of this poly- Returns:
- max coefficient (by absolute value)
-
maxAbsCoefficient
public final long maxAbsCoefficient()
Returns max coefficient (by absolute value) of this poly- Returns:
- max coefficient (by absolute value)
-
toZero
public final lPoly toZero()
Description copied from interface:IPolynomialSets this to zero- Specified by:
toZeroin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- this := zero
-
set
public final lPoly set(lPoly oth)
Description copied from interface:IPolynomialSets the content of this tooth- Specified by:
setin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
oth- the polynomial- Returns:
- this := oth
-
setAndDestroy
public final lPoly setAndDestroy(lPoly oth)
Description copied from interface:IUnivariatePolynomialSets the content of this withothand destroys oth- Specified by:
setAndDestroyin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
oth- the polynomial (will be destroyed)- Returns:
- this := oth
-
shiftLeft
public final lPoly shiftLeft(int offset)
Description copied from interface:IUnivariatePolynomialReturns the quotientthis / x^offset, it is polynomial with coefficient list formed by shifting coefficients ofthisto the left byoffset.- Specified by:
shiftLeftin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
offset- shift amount- Returns:
- the quotient
this / x^offset
-
shiftRight
public final lPoly shiftRight(int offset)
Description copied from interface:IUnivariatePolynomialMultipliesthisby thex^offset.- Specified by:
shiftRightin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
offset- monomial exponent- Returns:
this * x^offset
-
truncate
public final lPoly truncate(int newDegree)
Description copied from interface:IUnivariatePolynomialReturns the remainderthis rem x^(newDegree + 1), it is polynomial formed by coefficients of this from zero tonewDegree(both inclusive)- Specified by:
truncatein interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
newDegree- new degree- Returns:
- remainder
this rem x^(newDegree + 1)
-
reverse
public final lPoly reverse()
Description copied from interface:IUnivariatePolynomialReverses the coefficients of this- Specified by:
reversein interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- reversed polynomial
-
contentAsPoly
public final lPoly contentAsPoly()
Description copied from interface:IPolynomialReturns the content of this (gcd of coefficients) as a constant poly- Specified by:
contentAsPolyin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>
-
primitivePart
public final lPoly primitivePart()
Description copied from interface:IPolynomialReduces poly to its primitive part (primitive part will always have positive l.c.)- Specified by:
primitivePartin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- primitive part (poly will be modified)
-
primitivePartSameSign
public final lPoly primitivePartSameSign()
Description copied from interface:IPolynomialReduces poly to its primitive part, so that primitive part will have the same signum as the initial poly- Specified by:
primitivePartSameSignin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- primitive part (poly will be modified)
-
evaluate
public final long evaluate(long point)
Evaluates this poly at a givenpoint(via Horner method).- Parameters:
point-point- Returns:
- value at
point
-
composition
public final lPoly composition(lPoly value)
Description copied from interface:IUnivariatePolynomialCalculates the composition of this(oth) (new instance, so the content of this is not changed))- Specified by:
compositionin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
value- polynomial- Returns:
- composition
this(oth)
-
shift
public final lPoly shift(long value)
Shifts variable x -> x + value and returns the result (new instance)- Parameters:
value- shift amount- Returns:
- a copy of this with x -> x + value
-
monicWithLC
public lPoly monicWithLC(lPoly other)
Description copied from interface:IPolynomialSetsthisto its monic part multiplied by the leading coefficient ofother;- Specified by:
monicWithLCin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
other- other polynomial- Returns:
- monic part multiplied by the leading coefficient of
otheror null if exact division by the reduced leading coefficient is not possible
-
add
public final lPoly add(long val)
Add constant to this.- Parameters:
val- some number- Returns:
- this + val
-
subtract
public final lPoly subtract(long val)
Subtract constant from this.- Parameters:
val- some number- Returns:
- this + val
-
decrement
public final lPoly decrement()
Description copied from interface:IPolynomialSubtracts 1 from this- Specified by:
decrementin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
this - 1
-
increment
public final lPoly increment()
Description copied from interface:IPolynomialAdds 1 to this- Specified by:
incrementin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
this + 1
-
add
public final lPoly add(lPoly oth)
Description copied from interface:IPolynomialAddsothtothis.- Specified by:
addin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
oth- the polynomial- Returns:
this + oth
-
addMonomial
public final lPoly addMonomial(long coefficient, int exponent)Addscoefficient*x^exponenttothis- Parameters:
coefficient- monomial coefficientexponent- monomial exponent- Returns:
this + coefficient*x^exponent
-
addMul
public final lPoly addMul(lPoly oth, long factor)Addsoth * factortothis- Parameters:
oth- the polynomialfactor- the factor- Returns:
this + oth * factormodulomodulus
-
subtract
public final lPoly subtract(lPoly oth)
Description copied from interface:IPolynomialSubtractsothfromthis.- Specified by:
subtractin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
oth- the polynomial- Returns:
this - oth
-
subtract
public final lPoly subtract(lPoly oth, long factor, int exponent)Subtractsfactor * x^exponent * othfromthis- Parameters:
oth- the polynomialfactor- the factorexponent- the exponent- Returns:
this - factor * x^exponent * oth
-
negate
public final lPoly negate()
Description copied from interface:IPolynomialNegates this and returns- Specified by:
negatein interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Returns:
- this negated
-
multiplyByLC
public lPoly multiplyByLC(lPoly other)
Description copied from interface:IPolynomialMultiply this by the leading coefficient ofother- Specified by:
multiplyByLCin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
other- polynomial- Returns:
- this * lc(other)
-
multiply
public final lPoly multiply(long factor)
Description copied from interface:IPolynomialMultiplies this byfactor- Specified by:
multiplyin interfaceIPolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>- Parameters:
factor- the factor- Returns:
this * factor
-
getDataReferenceUnsafe
public final long[] getDataReferenceUnsafe()
internal API >>> direct unsafe access to internal storage
-
compareTo
public final int compareTo(lPoly o)
- Specified by:
compareToin interfaceComparable<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>
-
toString
public String toString(IStringifier<lPoly> stringifier)
Description copied from interface:Stringifiableconvert this to string with the use of stringifier- Specified by:
toStringin interfaceStringifiable<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>
-
toStringForCopy
public String toStringForCopy()
-
streamAsPolys
public Stream<lPoly> streamAsPolys()
Description copied from interface:IUnivariatePolynomialStream polynomial coefficients as constant polynomials- Specified by:
streamAsPolysin interfaceIUnivariatePolynomial<lPoly extends cc.redberry.rings.poly.univar.AUnivariatePolynomial64<lPoly>>
-
stream
public final LongStream stream()
Returns a sequentialStreamwith coefficients of this as its source.- Returns:
- a sequential
Streamover the coefficients in this polynomial
-
mapCoefficients
public final <T> UnivariatePolynomial<T> mapCoefficients(Ring<T> ring, LongFunction<T> mapper)
Applies transformation function to this and returns the result. This method is equivalent ofstream().mapToObj(mapper).collect(new PolynomialCollector<>(ring)).- Type Parameters:
T- result elements type- Parameters:
ring- ring of the new polynomialmapper- function that maps coefficients of this to coefficients of the result- Returns:
- a new polynomial with the coefficients obtained from this by applying
mapper
-
-