Package cc.redberry.rings.poly.univar
Class UnivariatePolynomial<E>
- java.lang.Object
-
- cc.redberry.rings.poly.univar.UnivariatePolynomial<E>
-
- All Implemented Interfaces:
Stringifiable<UnivariatePolynomial<E>>
,IPolynomial<UnivariatePolynomial<E>>
,IUnivariatePolynomial<UnivariatePolynomial<E>>
,Serializable
,Comparable<UnivariatePolynomial<E>>
,Iterable<E>
public final class UnivariatePolynomial<E> extends Object implements IUnivariatePolynomial<UnivariatePolynomial<E>>, Iterable<E>
Univariate polynomial over generic ring.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UnivariatePolynomial.PolynomialCollector<E>
Collector which collects stream of element to a UnivariatePolynomial
-
Method Summary
Modifier and Type Method Description UnivariatePolynomial<E>
add(UnivariatePolynomial<E> oth)
Addsoth
tothis
.UnivariatePolynomial<E>
add(E val)
Add constant to this.UnivariatePolynomial<E>
addMonomial(E coefficient, int exponent)
Addscoefficient*x^exponent
tothis
UnivariatePolynomial<E>
addMul(UnivariatePolynomial<E> oth, E factor)
Addsoth * factor
tothis
MultivariatePolynomial<E>
asMultivariate()
Convert to multivariate polynomialMultivariatePolynomial<E>
asMultivariate(Comparator<DegreeVector> ordering)
Convert to multivariate polynomialstatic UnivariatePolynomialZ64
asOverZ64(UnivariatePolynomial<BigInteger> poly)
Converts poly over BigIntegers to machine-sized polynomial in Zstatic UnivariatePolynomialZp64
asOverZp64(UnivariatePolynomial<BigInteger> poly)
Converts Zp[x] poly over BigIntegers to machine-sized polynomial in Zpstatic UnivariatePolynomialZp64
asOverZp64(UnivariatePolynomial<BigInteger> poly, IntegersZp64 ring)
Converts Zp[x] poly over BigIntegers to machine-sized polynomial in Zpstatic UnivariatePolynomialZp64
asOverZp64Q(UnivariatePolynomial<Rational<BigInteger>> poly, IntegersZp64 ring)
Converts Zp[x] poly over rationals to machine-sized polynomial in Zpstatic UnivariatePolynomial<BigInteger>
asPolyZSymmetric(UnivariatePolynomial<BigInteger> poly)
Converts Zp[x] polynomial to Z[x] polynomial formed from the coefficients of this represented in symmetric modular form (-modulus/2 <= cfx <= modulus/2
).E
cc()
Returns the constant coefficientUnivariatePolynomial<E>
ccAsPoly()
Returns the constant coefficient as a constant polyUnivariatePolynomial<E>
clone()
Deep copy of thisBigInteger
coefficientRingCardinality()
Returns cardinality of the coefficient ring of this polyBigInteger
coefficientRingCharacteristic()
Returns characteristic of the coefficient ring of this polyBigInteger
coefficientRingPerfectPowerBase()
Returnsbase
so thatcoefficientRingCardinality() == base^exponent
or null if cardinality is not finiteBigInteger
coefficientRingPerfectPowerExponent()
Returnsexponent
so thatcoefficientRingCardinality() == base^exponent
or null if cardinality is not finiteString
coefficientRingToString(IStringifier<UnivariatePolynomial<E>> stringifier)
String representation of the coefficient ring of thisint
compareTo(UnivariatePolynomial<E> o)
MultivariatePolynomial<E>
composition(AMultivariatePolynomial value)
Calculates the composition of this(oth)UnivariatePolynomial<E>
composition(UnivariatePolynomial<E> value)
Calculates the composition of this(oth) (new instance, so the content of this is not changed))static <E> UnivariatePolynomial<E>
constant(Ring<E> ring, E constant)
Creates constant polynomial over specified ringE
content()
Returns the content of the polyUnivariatePolynomial<E>
contentAsPoly()
Returns the content of this (gcd of coefficients) as a constant polystatic UnivariatePolynomial<BigInteger>
create(long... data)
Creates new univariate Z[x] polynomialstatic UnivariatePolynomial<BigInteger>
create(Ring<BigInteger> ring, long... data)
Creates univariate polynomial over specified ring (with integer elements) with the specified coefficientsstatic <E> UnivariatePolynomial<E>
create(Ring<E> ring, E... data)
Creates new univariate polynomial over specified ring with the specified coefficients.UnivariatePolynomial<E>[]
createArray(int length)
overcome Java generics...UnivariatePolynomial<E>[]
createArray(UnivariatePolynomial<E> a, UnivariatePolynomial<E> b)
overcome Java generics...UnivariatePolynomial<E>[][]
createArray2d(int length)
overcome Java generics...UnivariatePolynomial<E>[][]
createArray2d(int length1, int length2)
overcome Java generics...UnivariatePolynomial<E>
createConstant(E val)
Creates constant polynomial with specified value (over the same ring)UnivariatePolynomial<E>
createFromArray(E[] data)
Creates new poly with the specified coefficients (over the same ring)UnivariatePolynomial<E>
createLinear(E cc, E lc)
Creates linear polynomial of formcc + x * lc
(over the same ring)UnivariatePolynomial<E>
createMonomial(int degree)
Creates new monomialx^degree
(with the same coefficient ring)UnivariatePolynomial<E>
createMonomial(E coefficient, int degree)
Creates monomialcoefficient * x^degree
(over the same ring)UnivariatePolynomial<E>
createOne()
Returns the new instance of unit polynomial (with the same coefficient ring)static <E> UnivariatePolynomial<E>
createUnsafe(Ring<E> ring, E[] data)
skipsring.setToValueOf(data)
UnivariatePolynomial<E>
createZero()
Returns the new instance of zero polynomial (with the same coefficient ring)UnivariatePolynomial<E>
decrement()
Subtracts 1 from thisint
degree()
Returns the degree of this polynomialUnivariatePolynomial<E>
derivative()
Returns the formal derivative of this poly (new instance, so the content of this is not changed)UnivariatePolynomial<E>
divideByLC(UnivariatePolynomial<E> other)
Divides this polynomial by the leading coefficient ofother
or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by theother.lc()
.UnivariatePolynomial<E>
divideExact(E factor)
Divides this polynomial by afactor
or throws exception if exact division is not possibleUnivariatePolynomial<E>
divideOrNull(E factor)
Divides this polynomial by afactor
or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by thefactor
.void
ensureInternalCapacity(int desiredCapacity)
ensures that internal storage has enough size to storedesiredCapacity
elementsboolean
equals(Object obj)
E
evaluate(long point)
Evaluates this poly at a givenpoint
(via Horner method).E
evaluate(E point)
Evaluates this poly at a givenpoint
(via Horner method).int
firstNonZeroCoefficientPosition()
Returns position of the first non-zero coefficient, that is common monomial exponent (e.g.E
get(int i)
Returns i-th coefficient of this polyUnivariatePolynomial<E>
getAsPoly(int i)
Returns i-th coefficient of this as a constant polynomialE[]
getDataReferenceUnsafe()
internal APIUnivariatePolynomial<E>
getRange(int from, int to)
Creates polynomial formed from the coefficients of this starting fromfrom
(inclusive) toto
(exclusive)int
hashCode()
UnivariatePolynomial<E>
increment()
Adds 1 to thisboolean
isConstant()
Returnstrue
if this polynomial has only constant termboolean
isMonic()
Returnstrue
if this polynomial is monicboolean
isMonomial()
Returnstrue
if this polynomial has only one monomial termboolean
isOne()
Returnstrue
if this is oneboolean
isOverField()
Returns whether the coefficient ring of this polynomial is a fieldboolean
isOverFiniteField()
Returns whether the coefficient ring of this polynomial is a finite fieldboolean
isOverPerfectPower()
Returns whether thecoefficientRingCardinality()
is a perfect powerboolean
isOverZ()
Returns whether the coefficient ring of this polynomial is Zboolean
isUnitCC()
Returns true if constant term is equal to oneboolean
isZero()
Returnstrue
if this is zeroboolean
isZeroAt(int i)
Returns whether i-th coefficient of this is zeroIterator<E>
iterator()
E
lc()
Returns the leading coefficientUnivariatePolynomial<E>
lcAsPoly()
Returns the leading coefficient as a constant polyUnivariatePolynomialZp64
mapCoefficients(IntegersZp64 ring, ToLongFunction<E> mapper)
Applies transformation function to this and returns the result.<T> UnivariatePolynomial<T>
mapCoefficients(Ring<T> ring, Function<E,T> mapper)
Applies transformation function to this and returns the result.E
maxAbsCoefficient()
Returns max abs coefficient of the polystatic BigInteger
mignotteBound(UnivariatePolynomial<BigInteger> poly)
Returns Mignotte's bound (sqrt(n+1) * 2^n max |this|) of the polyUnivariatePolynomial<E>
monic()
Setsthis
to its monic part (that isthis
divided by its leading coefficient), or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by thelc()
.UnivariatePolynomial<E>
monic(E factor)
Setsthis
to its monic part multiplied by thefactor
.UnivariatePolynomial<E>
monicWithLC(UnivariatePolynomial<E> other)
Setsthis
to its monic part multiplied by the leading coefficient ofother
;UnivariatePolynomial<E>
multiply(long factor)
Multiplies this byfactor
UnivariatePolynomial<E>
multiply(UnivariatePolynomial<E> oth)
Multiplies this byoth
UnivariatePolynomial<E>
multiply(E factor)
Multipliesthis
by thefactor
UnivariatePolynomial<E>
multiplyByBigInteger(BigInteger factor)
Multiplies this byfactor
UnivariatePolynomial<E>
multiplyByLC(UnivariatePolynomial<E> other)
Multiply this by the leading coefficient ofother
UnivariatePolynomial<E>
negate()
Negates this and returnsstatic BigInteger
norm1(UnivariatePolynomial<BigInteger> poly)
Returns L1 norm of the polynomial, i.e.static BigInteger
norm2(UnivariatePolynomial<BigInteger> poly)
Returns L2 norm of the polynomial, i.e.static double
norm2Double(UnivariatePolynomial<BigInteger> poly)
Returns L2 norm of the poly, i.e.E
normMax()
static <E> UnivariatePolynomial<E>
one(Ring<E> ring)
Creates unit polynomial over specified ringstatic <E> UnivariatePolynomial<E>
parse(String string, Ring<E> ring)
Deprecated.static <E> UnivariatePolynomial<E>
parse(String string, Ring<E> ring, String var)
Parse string into polynomialUnivariatePolynomial<E>
parsePoly(String string)
UnivariatePolynomial<E>
primitivePart()
Reduces poly to its primitive part (primitive part will always have positive l.c.)UnivariatePolynomial<E>
primitivePartSameSign()
Reduces poly to its primitive part, so that primitive part will have the same signum as the initial polyUnivariatePolynomial<E>
reverse()
Reverses the coefficients of thisboolean
sameCoefficientRingWith(UnivariatePolynomial<E> oth)
Returns whetheroth
andthis
have the same coefficient ringUnivariatePolynomial<E>
scale(E scaling)
Replaces x -> scale * x and returns a copyUnivariatePolynomial<E>
set(int i, E el)
Sets i-th coefficient of this poly with specified valueUnivariatePolynomial<E>
set(UnivariatePolynomial<E> oth)
Sets the content of this tooth
UnivariatePolynomial<E>
setAndDestroy(UnivariatePolynomial<E> oth)
Sets the content of this withoth
and destroys othUnivariatePolynomial<E>
setCoefficientRingFrom(UnivariatePolynomial<E> poly)
Set the coefficient ring from specified polyUnivariatePolynomial<E>
setFrom(int indexInThis, UnivariatePolynomial<E> poly, int indexInPoly)
Sets i-th element of this by j-th element of other polyUnivariatePolynomial<E>
setLC(E lc)
Sets the leading coefficient of this polyUnivariatePolynomial<E>
setRing(Ring<E> newRing)
Returns a copy of this with elements reduced to a new coefficient ringUnivariatePolynomial<E>
setRingUnsafe(Ring<E> newRing)
internal APIUnivariatePolynomial<E>
setZero(int i)
Fills i-th element with zeroUnivariatePolynomial<E>
shift(E value)
Shifts variable x -> x + value and returns the result (new instance)UnivariatePolynomial<E>
shiftLeft(int offset)
Returns the quotientthis / x^offset
, it is polynomial with coefficient list formed by shifting coefficients ofthis
to the left byoffset
.UnivariatePolynomial<E>
shiftRight(int offset)
Multipliesthis
by thex^offset
.int
signumOfLC()
Gives signum of the leading coefficientSpliterator<E>
spliterator()
UnivariatePolynomial<E>
square()
Squaresthis
Stream<E>
stream()
Returns a sequentialStream
with coefficients of this as its source.Stream<UnivariatePolynomial<E>>
streamAsPolys()
Stream polynomial coefficients as constant polynomialsUnivariatePolynomial<E>
subtract(UnivariatePolynomial<E> oth)
Subtractsoth
fromthis
.UnivariatePolynomial<E>
subtract(UnivariatePolynomial<E> oth, E factor, int exponent)
Subtractsfactor * x^exponent * oth
fromthis
UnivariatePolynomial<E>
subtract(E val)
Subtract constant from this.String
toString()
String
toString(IStringifier<UnivariatePolynomial<E>> stringifier)
convert this to string with the use of stringifierUnivariatePolynomial<E>
toZero()
Sets this to zeroUnivariatePolynomial<E>
truncate(int newDegree)
Returns the remainderthis rem x^(newDegree + 1)
, it is polynomial formed by coefficients of this from zero tonewDegree
(both inclusive)static <E> UnivariatePolynomial<E>
zero(Ring<E> ring)
Creates zero polynomial over specified ring-
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, createConstant, 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
-
-
-
-
Method Detail
-
parse
public static <E> UnivariatePolynomial<E> parse(String string, Ring<E> ring, String var)
Parse string into polynomial- Parameters:
string
- string expressionring
- the ringvar
- variable string
-
parse
@Deprecated public static <E> UnivariatePolynomial<E> parse(String string, Ring<E> ring)
Deprecated.Parse string into polynomial
-
create
public static <E> UnivariatePolynomial<E> create(Ring<E> ring, E... data)
Creates new univariate polynomial over specified ring with the specified coefficients. Note: the arraydata
will not be copied.- Parameters:
ring
- the ringdata
- the coefficients- Returns:
- new univariate polynomial over specified ring with specified coefficients
-
createUnsafe
public static <E> UnivariatePolynomial<E> createUnsafe(Ring<E> ring, E[] data)
skipsring.setToValueOf(data)
-
create
public static UnivariatePolynomial<BigInteger> create(Ring<BigInteger> ring, long... data)
Creates univariate polynomial over specified ring (with integer elements) with the specified coefficients- Parameters:
ring
- the ringdata
- the coefficients- Returns:
- new univariate polynomial over specified ring with specified coefficients
-
create
public static UnivariatePolynomial<BigInteger> create(long... data)
Creates new univariate Z[x] polynomial- Parameters:
data
- the data- Returns:
- new univariate Z[x] polynomial with specified coefficients
-
constant
public static <E> UnivariatePolynomial<E> constant(Ring<E> ring, E constant)
Creates constant polynomial over specified ring- Parameters:
ring
- the ringconstant
- the value- Returns:
- constant polynomial over specified ring
-
zero
public static <E> UnivariatePolynomial<E> zero(Ring<E> ring)
Creates zero polynomial over specified ring- Parameters:
ring
- the ring- Returns:
- zero polynomial over specified ring
-
one
public static <E> UnivariatePolynomial<E> one(Ring<E> ring)
Creates unit polynomial over specified ring- Parameters:
ring
- the ring- Returns:
- unit polynomial over specified ring
-
asOverZ64
public static UnivariatePolynomialZ64 asOverZ64(UnivariatePolynomial<BigInteger> poly)
Converts poly over BigIntegers to machine-sized polynomial in Z- Parameters:
poly
- the polynomial over BigIntegers- Returns:
- machine-sized polynomial in Z
- Throws:
ArithmeticException
- if some of coefficients is out of long range
-
asOverZp64
public static UnivariatePolynomialZp64 asOverZp64(UnivariatePolynomial<BigInteger> poly)
Converts Zp[x] poly over BigIntegers to machine-sized polynomial in Zp- Parameters:
poly
- the Z/p polynomial over BigIntegers- Returns:
- machine-sized polynomial in Z/p
- Throws:
IllegalArgumentException
- ifpoly.ring
is notIntegersZp
ArithmeticException
- if some ofpoly
elements is out of long range
-
asOverZp64
public static UnivariatePolynomialZp64 asOverZp64(UnivariatePolynomial<BigInteger> poly, IntegersZp64 ring)
Converts Zp[x] poly over BigIntegers to machine-sized polynomial in Zp- Parameters:
poly
- the polynomial over BigIntegersring
- Zp64 ring- Returns:
- machine-sized polynomial in Z/p
- Throws:
IllegalArgumentException
- ifpoly.ring
is notIntegersZp
ArithmeticException
- if some ofpoly
elements is out of long range
-
asOverZp64Q
public static UnivariatePolynomialZp64 asOverZp64Q(UnivariatePolynomial<Rational<BigInteger>> poly, IntegersZp64 ring)
Converts Zp[x] poly over rationals to machine-sized polynomial in Zp- Parameters:
poly
- the polynomial over rationalsring
- Zp64 ring- Returns:
- machine-sized polynomial in Z/p
- Throws:
IllegalArgumentException
- ifpoly.ring
is notIntegersZp
ArithmeticException
- if some ofpoly
elements is out of long range
-
asPolyZSymmetric
public static UnivariatePolynomial<BigInteger> asPolyZSymmetric(UnivariatePolynomial<BigInteger> poly)
Converts Zp[x] polynomial to Z[x] polynomial formed from the coefficients of this represented in symmetric modular form (-modulus/2 <= cfx <= modulus/2
).- Parameters:
poly
- Zp polynomial- Returns:
- Z[x] version of the poly with coefficients represented in symmetric modular form (
-modulus/2 <= cfx <= modulus/2
). - Throws:
IllegalArgumentException
- ispoly.ring
is not aIntegersZp
-
degree
public int degree()
Description copied from interface:IPolynomial
Returns the degree of this polynomial- Specified by:
degree
in interfaceIPolynomial<E>
- Returns:
- the degree
-
get
public E get(int i)
Returns i-th coefficient of this poly
-
set
public UnivariatePolynomial<E> set(int i, E el)
Sets i-th coefficient of this poly with specified value
-
setLC
public UnivariatePolynomial<E> setLC(E lc)
Sets the leading coefficient of this poly
-
firstNonZeroCoefficientPosition
public int firstNonZeroCoefficientPosition()
Description copied from interface:IUnivariatePolynomial
Returns 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:
firstNonZeroCoefficientPosition
in interfaceIUnivariatePolynomial<E>
- Returns:
- position of the first non-zero coefficient or -1 if this is zero
-
setRing
public UnivariatePolynomial<E> setRing(Ring<E> newRing)
Returns a copy of this with elements reduced to a new coefficient ring- Parameters:
newRing
- the new ring- Returns:
- a copy of this with elements reduced to a new coefficient ring
-
setRingUnsafe
public UnivariatePolynomial<E> setRingUnsafe(Ring<E> newRing)
internal API
-
lc
public E lc()
Returns the leading coefficient- Returns:
- leading coefficient
-
lcAsPoly
public UnivariatePolynomial<E> lcAsPoly()
Description copied from interface:IPolynomial
Returns the leading coefficient as a constant poly- Specified by:
lcAsPoly
in interfaceIPolynomial<E>
-
ccAsPoly
public UnivariatePolynomial<E> ccAsPoly()
Description copied from interface:IPolynomial
Returns the constant coefficient as a constant poly- Specified by:
ccAsPoly
in interfaceIPolynomial<E>
-
getAsPoly
public UnivariatePolynomial<E> getAsPoly(int i)
Description copied from interface:IUnivariatePolynomial
Returns i-th coefficient of this as a constant polynomial- Specified by:
getAsPoly
in interfaceIUnivariatePolynomial<E>
- Parameters:
i
- index in this- Returns:
- i-th coefficient of this as a constant polynomial
-
cc
public E cc()
Returns the constant coefficient- Returns:
- constant coefficient
-
ensureInternalCapacity
public void ensureInternalCapacity(int desiredCapacity)
Description copied from interface:IUnivariatePolynomial
ensures that internal storage has enough size to storedesiredCapacity
elements- Specified by:
ensureInternalCapacity
in interfaceIUnivariatePolynomial<E>
-
getRange
public UnivariatePolynomial<E> getRange(int from, int to)
Description copied from interface:IUnivariatePolynomial
Creates polynomial formed from the coefficients of this starting fromfrom
(inclusive) toto
(exclusive)- Specified by:
getRange
in interfaceIUnivariatePolynomial<E>
- 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
-
createArray
public UnivariatePolynomial<E>[] createArray(int length)
Description copied from interface:IPolynomial
overcome Java generics...- Specified by:
createArray
in interfaceIPolynomial<E>
-
createArray
public UnivariatePolynomial<E>[] createArray(UnivariatePolynomial<E> a, UnivariatePolynomial<E> b)
Description copied from interface:IPolynomial
overcome Java generics...- Specified by:
createArray
in interfaceIPolynomial<E>
-
createArray2d
public UnivariatePolynomial<E>[][] createArray2d(int length)
Description copied from interface:IPolynomial
overcome Java generics...- Specified by:
createArray2d
in interfaceIPolynomial<E>
-
createArray2d
public UnivariatePolynomial<E>[][] createArray2d(int length1, int length2)
Description copied from interface:IPolynomial
overcome Java generics...- Specified by:
createArray2d
in interfaceIPolynomial<E>
-
sameCoefficientRingWith
public boolean sameCoefficientRingWith(UnivariatePolynomial<E> oth)
Description copied from interface:IPolynomial
Returns whetheroth
andthis
have the same coefficient ring- Specified by:
sameCoefficientRingWith
in interfaceIPolynomial<E>
- Parameters:
oth
- other polynomial- Returns:
- whether this and oth are over the same coefficient ring
-
setCoefficientRingFrom
public UnivariatePolynomial<E> setCoefficientRingFrom(UnivariatePolynomial<E> poly)
Description copied from interface:IPolynomial
Set the coefficient ring from specified poly- Specified by:
setCoefficientRingFrom
in interfaceIPolynomial<E>
- Parameters:
poly
- the polynomial- Returns:
- a copy of this with the coefficient ring taken from
poly
-
createFromArray
public UnivariatePolynomial<E> createFromArray(E[] data)
Creates new poly with the specified coefficients (over the same ring)- Parameters:
data
- the data- Returns:
- polynomial
-
createMonomial
public UnivariatePolynomial<E> createMonomial(int degree)
Description copied from interface:IUnivariatePolynomial
Creates new monomialx^degree
(with the same coefficient ring)- Specified by:
createMonomial
in interfaceIUnivariatePolynomial<E>
- Parameters:
degree
- monomial degree- Returns:
- new monomial
coefficient * x^degree
-
createLinear
public UnivariatePolynomial<E> createLinear(E cc, E lc)
Creates linear polynomial of formcc + x * lc
(over the same ring)- Parameters:
cc
- the constant coefficientlc
- the leading coefficient- Returns:
cc + x * lc
-
createMonomial
public UnivariatePolynomial<E> createMonomial(E coefficient, int degree)
Creates monomialcoefficient * x^degree
(over the same ring)- Parameters:
coefficient
- monomial coefficientdegree
- monomial degree- Returns:
coefficient * x^degree
-
createConstant
public UnivariatePolynomial<E> createConstant(E val)
Creates constant polynomial with specified value (over the same ring)- Parameters:
val
- the value- Returns:
- constant polynomial with specified value
-
createZero
public UnivariatePolynomial<E> createZero()
Description copied from interface:IPolynomial
Returns the new instance of zero polynomial (with the same coefficient ring)- Specified by:
createZero
in interfaceIPolynomial<E>
- Returns:
- new instance of 0
-
createOne
public UnivariatePolynomial<E> createOne()
Description copied from interface:IPolynomial
Returns the new instance of unit polynomial (with the same coefficient ring)- Specified by:
createOne
in interfaceIPolynomial<E>
- Returns:
- new instance of 1
-
isZeroAt
public boolean isZeroAt(int i)
Description copied from interface:IUnivariatePolynomial
Returns whether i-th coefficient of this is zero- Specified by:
isZeroAt
in interfaceIUnivariatePolynomial<E>
- Parameters:
i
- the position- Returns:
- whether i-th coefficient of this is zero
-
setZero
public final UnivariatePolynomial<E> setZero(int i)
Description copied from interface:IUnivariatePolynomial
Fills i-th element with zero- Specified by:
setZero
in interfaceIUnivariatePolynomial<E>
- Parameters:
i
- position- Returns:
- self
-
setFrom
public UnivariatePolynomial<E> setFrom(int indexInThis, UnivariatePolynomial<E> poly, int indexInPoly)
Description copied from interface:IUnivariatePolynomial
Sets i-th element of this by j-th element of other poly- Specified by:
setFrom
in interfaceIUnivariatePolynomial<E>
- Parameters:
indexInThis
- index in selfpoly
- other polynomialindexInPoly
- index in other polynomial- Returns:
- self
-
isZero
public boolean isZero()
Description copied from interface:IPolynomial
Returnstrue
if this is zero- Specified by:
isZero
in interfaceIPolynomial<E>
- Returns:
- whether
this
is zero
-
isOne
public boolean isOne()
Description copied from interface:IPolynomial
Returnstrue
if this is one- Specified by:
isOne
in interfaceIPolynomial<E>
- Returns:
- whether
this
is one
-
isMonic
public boolean isMonic()
Description copied from interface:IPolynomial
Returnstrue
if this polynomial is monic- Specified by:
isMonic
in interfaceIPolynomial<E>
- Returns:
- whether
this
is monic
-
isUnitCC
public boolean isUnitCC()
Description copied from interface:IPolynomial
Returns true if constant term is equal to one- Specified by:
isUnitCC
in interfaceIPolynomial<E>
- Returns:
- whether constant term is 1
-
isConstant
public boolean isConstant()
Description copied from interface:IPolynomial
Returnstrue
if this polynomial has only constant term- Specified by:
isConstant
in interfaceIPolynomial<E>
- Returns:
- whether
this
is constant
-
isMonomial
public boolean isMonomial()
Description copied from interface:IPolynomial
Returnstrue
if this polynomial has only one monomial term- Specified by:
isMonomial
in interfaceIPolynomial<E>
- Returns:
- whether
this
has only one monomial term
-
signumOfLC
public int signumOfLC()
Description copied from interface:IPolynomial
Gives signum of the leading coefficient- Specified by:
signumOfLC
in interfaceIPolynomial<E>
- Returns:
- signum of the leading coefficient
-
isOverField
public boolean isOverField()
Description copied from interface:IPolynomial
Returns whether the coefficient ring of this polynomial is a field- Specified by:
isOverField
in interfaceIPolynomial<E>
- Returns:
- whether the coefficient ring of this polynomial is a field
-
isOverFiniteField
public boolean isOverFiniteField()
Description copied from interface:IPolynomial
Returns whether the coefficient ring of this polynomial is a finite field- Specified by:
isOverFiniteField
in interfaceIPolynomial<E>
- Returns:
- whether the coefficient ring of this polynomial is a finite field
-
isOverZ
public boolean isOverZ()
Description copied from interface:IPolynomial
Returns whether the coefficient ring of this polynomial is Z- Specified by:
isOverZ
in interfaceIPolynomial<E>
- Returns:
- whether the coefficient ring of this polynomial is Z
-
coefficientRingCardinality
public BigInteger coefficientRingCardinality()
Description copied from interface:IPolynomial
Returns cardinality of the coefficient ring of this poly- Specified by:
coefficientRingCardinality
in interfaceIPolynomial<E>
- Returns:
- cardinality of the coefficient ring
-
coefficientRingCharacteristic
public BigInteger coefficientRingCharacteristic()
Description copied from interface:IPolynomial
Returns characteristic of the coefficient ring of this poly- Specified by:
coefficientRingCharacteristic
in interfaceIPolynomial<E>
- Returns:
- characteristic of the coefficient ring
-
isOverPerfectPower
public boolean isOverPerfectPower()
Description copied from interface:IPolynomial
Returns whether thecoefficientRingCardinality()
is a perfect power- Specified by:
isOverPerfectPower
in interfaceIPolynomial<E>
- Returns:
- whether the
coefficientRingCardinality()
is a perfect power
-
coefficientRingPerfectPowerBase
public BigInteger coefficientRingPerfectPowerBase()
Description copied from interface:IPolynomial
Returnsbase
so thatcoefficientRingCardinality() == base^exponent
or null if cardinality is not finite- Specified by:
coefficientRingPerfectPowerBase
in interfaceIPolynomial<E>
- Returns:
base
so thatcoefficientRingCardinality() == base^exponent
or null if cardinality is not finite
-
coefficientRingPerfectPowerExponent
public BigInteger coefficientRingPerfectPowerExponent()
Description copied from interface:IPolynomial
Returnsexponent
so thatcoefficientRingCardinality() == base^exponent
or null if cardinality is not finite- Specified by:
coefficientRingPerfectPowerExponent
in interfaceIPolynomial<E>
- Returns:
exponent
so thatcoefficientRingCardinality() == base^exponent
or null if cardinality is not finite
-
mignotteBound
public static BigInteger mignotteBound(UnivariatePolynomial<BigInteger> poly)
Returns Mignotte's bound (sqrt(n+1) * 2^n max |this|) of the poly
-
norm1
public static BigInteger norm1(UnivariatePolynomial<BigInteger> poly)
Returns L1 norm of the polynomial, i.e. sum of abs coefficients
-
norm2
public static BigInteger norm2(UnivariatePolynomial<BigInteger> poly)
Returns L2 norm of the polynomial, i.e. a square root of a sum of coefficient squares.
-
norm2Double
public static double norm2Double(UnivariatePolynomial<BigInteger> poly)
Returns L2 norm of the poly, i.e. a square root of a sum of coefficient squares.
-
maxAbsCoefficient
public E maxAbsCoefficient()
Returns max abs coefficient of the poly
-
normMax
public E normMax()
-
toZero
public UnivariatePolynomial<E> toZero()
Description copied from interface:IPolynomial
Sets this to zero- Specified by:
toZero
in interfaceIPolynomial<E>
- Returns:
- this := zero
-
set
public UnivariatePolynomial<E> set(UnivariatePolynomial<E> oth)
Description copied from interface:IPolynomial
Sets the content of this tooth
- Specified by:
set
in interfaceIPolynomial<E>
- Parameters:
oth
- the polynomial- Returns:
- this := oth
-
setAndDestroy
public final UnivariatePolynomial<E> setAndDestroy(UnivariatePolynomial<E> oth)
Description copied from interface:IUnivariatePolynomial
Sets the content of this withoth
and destroys oth- Specified by:
setAndDestroy
in interfaceIUnivariatePolynomial<E>
- Parameters:
oth
- the polynomial (will be destroyed)- Returns:
- this := oth
-
shiftLeft
public UnivariatePolynomial<E> shiftLeft(int offset)
Description copied from interface:IUnivariatePolynomial
Returns the quotientthis / x^offset
, it is polynomial with coefficient list formed by shifting coefficients ofthis
to the left byoffset
.- Specified by:
shiftLeft
in interfaceIUnivariatePolynomial<E>
- Parameters:
offset
- shift amount- Returns:
- the quotient
this / x^offset
-
shiftRight
public UnivariatePolynomial<E> shiftRight(int offset)
Description copied from interface:IUnivariatePolynomial
Multipliesthis
by thex^offset
.- Specified by:
shiftRight
in interfaceIUnivariatePolynomial<E>
- Parameters:
offset
- monomial exponent- Returns:
this * x^offset
-
truncate
public UnivariatePolynomial<E> truncate(int newDegree)
Description copied from interface:IUnivariatePolynomial
Returns the remainderthis rem x^(newDegree + 1)
, it is polynomial formed by coefficients of this from zero tonewDegree
(both inclusive)- Specified by:
truncate
in interfaceIUnivariatePolynomial<E>
- Parameters:
newDegree
- new degree- Returns:
- remainder
this rem x^(newDegree + 1)
-
reverse
public UnivariatePolynomial<E> reverse()
Description copied from interface:IUnivariatePolynomial
Reverses the coefficients of this- Specified by:
reverse
in interfaceIUnivariatePolynomial<E>
- Returns:
- reversed polynomial
-
content
public E content()
Returns the content of the poly- Returns:
- polynomial content
-
contentAsPoly
public UnivariatePolynomial<E> contentAsPoly()
Description copied from interface:IPolynomial
Returns the content of this (gcd of coefficients) as a constant poly- Specified by:
contentAsPoly
in interfaceIPolynomial<E>
-
primitivePart
public UnivariatePolynomial<E> primitivePart()
Description copied from interface:IPolynomial
Reduces poly to its primitive part (primitive part will always have positive l.c.)- Specified by:
primitivePart
in interfaceIPolynomial<E>
- Returns:
- primitive part (poly will be modified)
-
primitivePartSameSign
public UnivariatePolynomial<E> primitivePartSameSign()
Description copied from interface:IPolynomial
Reduces poly to its primitive part, so that primitive part will have the same signum as the initial poly- Specified by:
primitivePartSameSign
in interfaceIPolynomial<E>
- Returns:
- primitive part (poly will be modified)
-
evaluate
public E evaluate(long point)
Evaluates this poly at a givenpoint
(via Horner method).- Parameters:
point
-point
- Returns:
- value at
point
-
evaluate
public E evaluate(E point)
Evaluates this poly at a givenpoint
(via Horner method).- Parameters:
point
-point
- Returns:
- value at
point
-
composition
public UnivariatePolynomial<E> composition(UnivariatePolynomial<E> value)
Description copied from interface:IUnivariatePolynomial
Calculates the composition of this(oth) (new instance, so the content of this is not changed))- Specified by:
composition
in interfaceIUnivariatePolynomial<E>
- Parameters:
value
- polynomial- Returns:
- composition
this(oth)
-
composition
public MultivariatePolynomial<E> composition(AMultivariatePolynomial value)
Description copied from interface:IUnivariatePolynomial
Calculates the composition of this(oth)- Specified by:
composition
in interfaceIUnivariatePolynomial<E>
- Parameters:
value
- polynomial- Returns:
- composition
this(oth)
-
scale
public UnivariatePolynomial<E> scale(E scaling)
Replaces x -> scale * x and returns a copy
-
shift
public UnivariatePolynomial<E> shift(E 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
-
add
public UnivariatePolynomial<E> add(E val)
Add constant to this.- Parameters:
val
- some number- Returns:
- this + val
-
subtract
public UnivariatePolynomial<E> subtract(E val)
Subtract constant from this.- Parameters:
val
- some number- Returns:
- this + val
-
decrement
public UnivariatePolynomial<E> decrement()
Description copied from interface:IPolynomial
Subtracts 1 from this- Specified by:
decrement
in interfaceIPolynomial<E>
- Returns:
this - 1
-
increment
public UnivariatePolynomial<E> increment()
Description copied from interface:IPolynomial
Adds 1 to this- Specified by:
increment
in interfaceIPolynomial<E>
- Returns:
this + 1
-
add
public UnivariatePolynomial<E> add(UnivariatePolynomial<E> oth)
Description copied from interface:IPolynomial
Addsoth
tothis
.- Specified by:
add
in interfaceIPolynomial<E>
- Parameters:
oth
- the polynomial- Returns:
this + oth
-
addMonomial
public UnivariatePolynomial<E> addMonomial(E coefficient, int exponent)
Addscoefficient*x^exponent
tothis
- Parameters:
coefficient
- monomial coefficientexponent
- monomial exponent- Returns:
this + coefficient*x^exponent
-
addMul
public UnivariatePolynomial<E> addMul(UnivariatePolynomial<E> oth, E factor)
Addsoth * factor
tothis
- Parameters:
oth
- the polynomialfactor
- the factor- Returns:
this + oth * factor
modulomodulus
-
subtract
public UnivariatePolynomial<E> subtract(UnivariatePolynomial<E> oth)
Description copied from interface:IPolynomial
Subtractsoth
fromthis
.- Specified by:
subtract
in interfaceIPolynomial<E>
- Parameters:
oth
- the polynomial- Returns:
this - oth
-
subtract
public UnivariatePolynomial<E> subtract(UnivariatePolynomial<E> oth, E factor, int exponent)
Subtractsfactor * x^exponent * oth
fromthis
- Parameters:
oth
- the polynomialfactor
- the factorexponent
- the exponent- Returns:
this - factor * x^exponent * oth
-
negate
public UnivariatePolynomial<E> negate()
Description copied from interface:IPolynomial
Negates this and returns- Specified by:
negate
in interfaceIPolynomial<E>
- Returns:
- this negated
-
multiply
public UnivariatePolynomial<E> multiply(E factor)
Multipliesthis
by thefactor
- Parameters:
factor
- the factor- Returns:
- this multiplied by the
factor
-
multiplyByLC
public UnivariatePolynomial<E> multiplyByLC(UnivariatePolynomial<E> other)
Description copied from interface:IPolynomial
Multiply this by the leading coefficient ofother
- Specified by:
multiplyByLC
in interfaceIPolynomial<E>
- Parameters:
other
- polynomial- Returns:
- this * lc(other)
-
multiply
public UnivariatePolynomial<E> multiply(long factor)
Description copied from interface:IPolynomial
Multiplies this byfactor
- Specified by:
multiply
in interfaceIPolynomial<E>
- Parameters:
factor
- the factor- Returns:
this * factor
-
divideByLC
public UnivariatePolynomial<E> divideByLC(UnivariatePolynomial<E> other)
Description copied from interface:IPolynomial
Divides this polynomial by the leading coefficient ofother
or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by theother.lc()
. NOTE: ifnull
is returned, the content ofthis
is destroyed.- Specified by:
divideByLC
in interfaceIPolynomial<E>
- Parameters:
other
- the polynomial- Returns:
this
divided by theother.lc()
ornull
if exact division is not possible
-
divideOrNull
public UnivariatePolynomial<E> divideOrNull(E factor)
Divides this polynomial by afactor
or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by thefactor
. NOTE: ifnull
is returned, the content ofthis
is destroyed.- Parameters:
factor
- the factor- Returns:
this
divided by thefactor
ornull
-
divideExact
public UnivariatePolynomial<E> divideExact(E factor)
Divides this polynomial by afactor
or throws exception if exact division is not possible- Parameters:
factor
- the factor- Returns:
this
divided by thefactor
- Throws:
ArithmeticException
- if exact division is not possible
-
monic
public UnivariatePolynomial<E> monic()
Description copied from interface:IPolynomial
Setsthis
to its monic part (that isthis
divided by its leading coefficient), or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by thelc()
. NOTE: ifnull
is returned, the content ofthis
is destroyed.- Specified by:
monic
in interfaceIPolynomial<E>
- Returns:
- monic
this
ornull
-
monic
public UnivariatePolynomial<E> monic(E factor)
Setsthis
to its monic part multiplied by thefactor
.- Parameters:
factor
- the factor- Returns:
this
-
monicWithLC
public UnivariatePolynomial<E> monicWithLC(UnivariatePolynomial<E> other)
Description copied from interface:IPolynomial
Setsthis
to its monic part multiplied by the leading coefficient ofother
;- Specified by:
monicWithLC
in interfaceIPolynomial<E>
- Parameters:
other
- other polynomial- Returns:
- monic part multiplied by the leading coefficient of
other
or null if exact division by the reduced leading coefficient is not possible
-
multiplyByBigInteger
public UnivariatePolynomial<E> multiplyByBigInteger(BigInteger factor)
Description copied from interface:IPolynomial
Multiplies this byfactor
- Specified by:
multiplyByBigInteger
in interfaceIPolynomial<E>
- Parameters:
factor
- the factor- Returns:
this * factor
-
multiply
public UnivariatePolynomial<E> multiply(UnivariatePolynomial<E> oth)
Description copied from interface:IPolynomial
Multiplies this byoth
- Specified by:
multiply
in interfaceIPolynomial<E>
- Parameters:
oth
- the polynomial- Returns:
this * oth
-
square
public UnivariatePolynomial<E> square()
Description copied from interface:IPolynomial
Squaresthis
- Specified by:
square
in interfaceIPolynomial<E>
- Returns:
this * this
-
derivative
public UnivariatePolynomial<E> derivative()
Description copied from interface:IUnivariatePolynomial
Returns the formal derivative of this poly (new instance, so the content of this is not changed)- Specified by:
derivative
in interfaceIUnivariatePolynomial<E>
- Returns:
- the formal derivative
-
clone
public UnivariatePolynomial<E> clone()
Description copied from interface:IPolynomial
Deep copy of this- Specified by:
clone
in interfaceIPolynomial<E>
- Specified by:
clone
in interfaceIUnivariatePolynomial<E>
- Overrides:
clone
in classObject
- Returns:
- deep copy of this
-
parsePoly
public UnivariatePolynomial<E> parsePoly(String string)
- Specified by:
parsePoly
in interfaceIPolynomial<E>
-
stream
public Stream<E> stream()
Returns a sequentialStream
with coefficients of this as its source.- Returns:
- a sequential
Stream
over the coefficients in this polynomial
-
streamAsPolys
public Stream<UnivariatePolynomial<E>> streamAsPolys()
Description copied from interface:IUnivariatePolynomial
Stream polynomial coefficients as constant polynomials- Specified by:
streamAsPolys
in interfaceIUnivariatePolynomial<E>
-
spliterator
public Spliterator<E> spliterator()
- Specified by:
spliterator
in interfaceIterable<E>
-
mapCoefficients
public <T> UnivariatePolynomial<T> mapCoefficients(Ring<T> ring, Function<E,T> mapper)
Applies transformation function to this and returns the result. This method is equivalent ofstream().map(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
-
mapCoefficients
public UnivariatePolynomialZp64 mapCoefficients(IntegersZp64 ring, ToLongFunction<E> mapper)
Applies transformation function to this and returns the result. This method is equivalent ofstream().map(mapper).collect(new PolynomialCollector<>(ring))
.- 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
-
getDataReferenceUnsafe
public E[] getDataReferenceUnsafe()
internal API
-
asMultivariate
public MultivariatePolynomial<E> asMultivariate()
Description copied from interface:IUnivariatePolynomial
Convert to multivariate polynomial- Specified by:
asMultivariate
in interfaceIUnivariatePolynomial<E>
-
asMultivariate
public MultivariatePolynomial<E> asMultivariate(Comparator<DegreeVector> ordering)
Description copied from interface:IUnivariatePolynomial
Convert to multivariate polynomial- Specified by:
asMultivariate
in interfaceIUnivariatePolynomial<E>
-
compareTo
public int compareTo(UnivariatePolynomial<E> o)
- Specified by:
compareTo
in interfaceComparable<E>
-
coefficientRingToString
public String coefficientRingToString(IStringifier<UnivariatePolynomial<E>> stringifier)
Description copied from interface:IPolynomial
String representation of the coefficient ring of this- Specified by:
coefficientRingToString
in interfaceIPolynomial<E>
-
toString
public String toString(IStringifier<UnivariatePolynomial<E>> stringifier)
Description copied from interface:Stringifiable
convert this to string with the use of stringifier- Specified by:
toString
in interfaceStringifiable<E>
-
-