Class AMultivariatePolynomial<Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>>
- java.lang.Object
-
- cc.redberry.rings.poly.multivar.AMultivariatePolynomial<Term,Poly>
-
- Type Parameters:
Term
- type of monomialsPoly
- type of this (self-type)
- All Implemented Interfaces:
Stringifiable<Poly>
,IPolynomial<Poly>
,Serializable
,Comparable<Poly>
,Iterable<Term>
- Direct Known Subclasses:
MultivariatePolynomial
,MultivariatePolynomialZp64
public abstract class AMultivariatePolynomial<Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>> extends Object implements IPolynomial<Poly>, Iterable<Term>
Parent class for multivariate polynomials.Variables:
The number of variables is invariant, which means that binary arithmetic operations on polynomials with different number of variables (see
nVariables
) are prohibited. Of course all exponents of particular variable may be zero, so e.g.MultivariatePolynomial.parse("x^2 + 2*x*y + y^3", "x", "y", "z")
Particular string names of variables are not stored in the polynomial data structure, instead the variables are treated as consequent integer numbers (0, 1, 2,...), where 0 states for the first variable, 1 for the second etc. Information about variables is accessible by the integer index of the variable. The mapping between the variable index and its string representation should be stored separately outside this class. For example:
// x is the first variable, y is the second String[] variables = {"x", "y"}; MultivariatePolynomial<BigInteger> poly = MultivariatePolynomial.parse("x^2 + 2*x*y + y^3", variables); // degree in x int xDegree = poly.degree(0); assert xDegree == 2; // degree in y int yDegree = poly.degree(1); assert yDegree == 3; // will use the specified mapping and print x^2 + 2*x*y + y^3 System.out.println(poly.toString(variables)); // will use the default mapping and print a^2 + 2*a*b + b^3 System.out.println(poly.toString());
Terms storage and ordering:
Terms of multivariate polynomial are stored in a sorted map
DegreeVector -> Monomial
(seeMonomialSet
). The order of monomials is defined by theComparator<DegreeVector>
which possible values areMonomialOrder.LEX
,MonomialOrder.ALEX
,MonomialOrder.GREVLEX
andMonomialOrder.GRLEX
. All operations on the instances of this will preserve the ordering of this. The leading term of the poly is defined with respect to this ordering.- Since:
- 1.0
- See Also:
IPolynomial
,MultivariatePolynomialZp64
,MultivariatePolynomial
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AMultivariatePolynomial.PolynomialCollector<Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>>
Collector which collects stream of element to a UnivariatePolynomial
-
Field Summary
Fields Modifier and Type Field Description IMonomialAlgebra<Term>
monomialAlgebra
Monomial algebraint
nVariables
The number of variablesComparator<DegreeVector>
ordering
The ordering
-
Method Summary
Modifier and Type Method Description Poly
add(Iterable<Term> monomials)
Adds monomials to this polynomialPoly
add(Poly oth)
Addsoth
tothis
.Poly
add(Term monomial)
Addsmonomial
to this polynomialPoly
add(Term... monomials)
Adds monomials to this polynomialIterator<Term>
ascendingIterator()
static <Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>>
PolyasMultivariate(IUnivariatePolynomial poly, int nVariables, int variable, Comparator<DegreeVector> ordering)
Converts univariate polynomial to multivariate.static <Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>>
PolyasMultivariate(UnivariatePolynomial<Poly> uPoly, int variable)
Convert univariate polynomial over multivariate polynomials to a normal multivariate polystatic <Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>>
PolyasMultivariate(UnivariatePolynomial<Poly> univariate, int uVariable, boolean join)
abstract MultivariatePolynomial<Poly>
asOverMultivariate(int... variables)
Converts this to a multivariate polynomial with coefficients being multivariate polynomials polynomials overvariables
that is polynomial in R[variables][other_variables]MultivariatePolynomial<Poly>
asOverMultivariateEliminate(int... variables)
Converts this to a multivariate polynomial with coefficients being multivariate polynomials polynomials overvariables
that is polynomial in R[variables][other_variables]abstract MultivariatePolynomial<Poly>
asOverMultivariateEliminate(int[] variables, Comparator<DegreeVector> ordering)
Converts this to a multivariate polynomial with coefficients being multivariate polynomials polynomials overvariables
that is polynomial in R[variables][other_variables]MultivariatePolynomial<Poly>
asOverPoly(Poly factory)
Consider coefficients of this as constant polynomials of the same type as a given factory polynomialabstract MultivariatePolynomial<? extends IUnivariatePolynomial>
asOverUnivariate(int variable)
Converts this to a multivariate polynomial with coefficients being univariate polynomials overvariable
abstract MultivariatePolynomial<? extends IUnivariatePolynomial>
asOverUnivariateEliminate(int variable)
Converts this to a multivariate polynomial with coefficients being univariate polynomials overvariable
, the resulting polynomial have (nVariable - 1) multivariate variables (specifiedvariable
is eliminated)abstract IUnivariatePolynomial
asUnivariate()
Converts this to univariate polynomial or throws exception if conversion is impossible (more than one variable have non zero exponents)UnivariatePolynomial<Poly>
asUnivariate(int variable)
Converts this polynomial to a univariate polynomial over specified variable with the multivariate coefficient ring.UnivariatePolynomial<Poly>
asUnivariateEliminate(int variable)
Converts this polynomial to a univariate polynomial over specified variable with the multivariate coefficient ring.abstract Poly
clone()
Deep copy of thisPoly
coefficientOf(int[] variables, int[] exponents)
Returns a coefficient beforevariables^exponents
as a multivariate polynomialPoly
coefficientOf(int variable, int exponent)
Returns a coefficient beforevariable^exponent
as a multivariate polynomialCollection<Term>
collection()
Poly
composition(int[] variables, Poly[] values)
Substitutes given polynomial instead of specified variable (that isthis(x_1, ..., value, ..., x_N)
, where value is on the place of specified variable)Poly
composition(int variable, Poly value)
Substitutes given polynomial instead of specified variable (that isthis(x_1, ..., value, ..., x_N)
, where value is on the place of specified variable)<sPoly extends IUnivariatePolynomial<sPoly>>
sPolycomposition(Ring<sPoly> uRing, sPoly... values)
Substitutes given polynomials instead of variables of this (that isthis(values_1, ..., values_N)
)Poly
composition(List<Poly> values)
Substitutes given polynomials instead of variables of this (that isthis(values_1, ..., values_N)
)Poly
composition(Poly... values)
Substitutes given polynomials instead of variables of this (that isthis(values_1, ..., values_N)
)<sPoly extends IUnivariatePolynomial<sPoly>>
sPolycomposition(sPoly... values)
Substitutes given polynomials instead of variables of this (that isthis(values_1, ..., values_N)
)Poly
content(int variable)
Gives the content of this considered as R[variable][other_variables]Poly
contentExcept(int variable)
Gives the content of this considered as R[other_variables][variable]abstract IUnivariatePolynomial
contentUnivariate(int variable)
Gives the content of this considered as R[variable][other_variables]Poly
create(DegreeVector term)
Creates multivariate polynomial over the same ring as this with the single monomialPoly
create(Iterable<Term> terms)
Creates multivariate polynomial over the same ring as this from the list of monomialsPoly
create(Term term)
Creates multivariate polynomial over the same ring as this with the single monomialPoly
create(Term... terms)
Creates multivariate polynomial over the same ring as this from the list of monomialsabstract Poly
createConstantFromTerm(Term term)
Creates multivariate polynomial over the same ring as this with the single constant element taken from given monomialPoly
createMonomial(int variable, int degree)
Creates monomial over the same ring as this of the formvariable ^ degree
int
degree()
Returns the total degree of this polynomial, that is the maximal total degree among all termsint
degree(int variable)
Returns the degree of this polynomial with respect to specified variableint
degree(int... variables)
Gives the degree in specified variablesint
degreeMax()
Returns the maximal degree of variables in this polynomialint[]
degrees()
Returns an array of degrees of all variables, so that is i-th element of the result is the polynomial degree with respect to i-th variableint[]
degrees(int variable)
Returns the array of exponents in whichvariable
occurs in this polynomialprotected int[]
degreesRef()
returns reference (content must not be modified)int
degreeSum()
Returns the sum ofdegrees()
Poly[]
derivative()
Gives the derivative vectorPoly
derivative(int variable)
Gives partial derivative with respect to specified variable (new instance created)abstract Poly
derivative(int variable, int order)
Gives partial derivative of specifiedorder
with respect to specified variable (new instance created)Iterator<Term>
descendingIterator()
Poly
divideDegreeVectorOrNull(DegreeVector monomial)
Divides this polynomial by amonomial
or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by themonomial
.abstract Poly
divideOrNull(Term monomial)
Divides this polynomial by amonomial
or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by themonomial
.Poly
dropCoefficientOf(int[] variables, int[] exponents)
Returns a coefficient beforevariables^exponents
as a multivariate polynomial and drops all such terms from thisPoly
dropSelectVariables(int... variables)
Makes a copy of this with all variables except specified ones replaced with the unitsPoly
dropVariable(int variable)
Makes a copy of this with the specified variable droppedPoly
dropVariables(int[] variables)
Makes a copy of this with the specified variable replaced with the unitint
ecart()
Returns degreeSum - lt().totalDegreeboolean
equals(Object o)
abstract Poly
evaluateAtRandom(int variable, org.apache.commons.math3.random.RandomGenerator rnd)
Evaluatespoly
at random pointabstract Poly
evaluateAtRandomPreservingSkeleton(int variable, org.apache.commons.math3.random.RandomGenerator rnd)
Evaluatespoly
at random point chosen in such way that the skeleton of evaluated version is the same as of the originalpoly
with respect to all exceptvariable
variablesPoly
evaluateAtZero(int variable)
Substitutes0
forvariable
(new instance created).Poly
evaluateAtZero(int[] variables)
Substitutes0
for all specifiedvariables
(new instance created).Term
first()
Set<DegreeVector>
getSkeleton()
Returns skeleton of this polySet<DegreeVector>
getSkeleton(int... variables)
Returns skeleton of this poly with respect to specifiedvariables
Set<DegreeVector>
getSkeletonDrop(int... variables)
Returns skeleton of this poly with respect to specifiedvariables
Set<DegreeVector>
getSkeletonExcept(int... variables)
Returns skeleton of this poly with respect to all except specifiedvariables
int
hashCode()
Poly
homogenize(int variable)
Homogenize poly by adding new (homogenizing) variablePoly
insertVariable(int variable)
Makes a copy of this by inserting new variable (the indexes will be shifted)Poly
insertVariable(int variable, int count)
Makes a copy of this by inserting new variables (the indexes will be shifted)boolean
isEffectiveUnivariate()
Returns whether this poly is effectively univariate (not more than one variable is non-unit)boolean
isHomogeneous()
Returns whether all terms have the same total degreeboolean
isLinearExactly()
Returns whether this polynomial is linear (i.e.boolean
isLinearOrConstant()
Returns whether this polynomial is linear (i.e.boolean
isMonomial()
Returnstrue
if this polynomial has only one monomial termboolean
isVariable()
Returns whether this is a plain variable (with no coefficient)boolean
isZero()
Returnstrue
if this is zeroboolean
isZeroCC()
Returns true if constant term is zeroIterator<Term>
iterator()
Poly
joinNewVariable()
Returns a copy of this withnVariables = nVariables + 1
Poly
joinNewVariables(int n)
Returns a copy of this withnVariables = nVariables + m
Term
last()
Poly
lc(int variable)
Returns the leading coefficient of this viewed as R[other_variables][variable]abstract Poly
lcAsPoly(Comparator<DegreeVector> ordering)
Returns the leading coefficient with respect to specified ordering as a constant polyTerm
lt()
Returns the leading term in this polynomial according to orderingTerm
lt(Comparator<DegreeVector> ordering)
Returns the leading term in this polynomial according to specified orderingPoly
ltAsPoly()
Returns the leading term in this polynomial according to orderingabstract <E> MultivariatePolynomial<E>
mapCoefficientsAsPolys(Ring<E> ring, Function<Poly,E> mapper)
Poly
mapVariables(int[] mapping)
Renames old variables to new according to mappingabstract Poly
monic(Comparator<DegreeVector> ordering)
Make this poly monic considering leading term with respect to given orderingabstract Poly
monicWithLC(Comparator<DegreeVector> ordering, Poly oth)
Setsthis
to its monic part multiplied by the leading coefficient ofother
with respect to given orderingTerm
monomialContent()
Returns the monomial content of this polynomialTerm
mt()
Returns the minimal term in this polynomial according to orderingint[]
multidegree()
Returns the multidegree of this polynomial i.e.abstract Poly
multiply(Term monomial)
Multipliesthis
by themonomial
Poly
multiplyByDegreeVector(DegreeVector dv)
Multipliesthis
by the degree vectorPoly
multiplyByMonomial(int variable, int exponent)
Multiplies this by variable^exponentPoly
negate()
Negates this and returnsint
nUsedVariables()
Returns the number of really used variables (those which are not units)abstract Poly
primitivePart(int variable)
Gives primitive part of this considered as R[variable][other_variables]Poly
put(Term monomial)
Putsmonomial
to this polynomial replacing the previous entry if wasprotected void
release()
release cachesstatic <T extends AMonomial<T>,P extends AMultivariatePolynomial<T,P>>
PrenameVariables(P poly, int[] newVariables)
Rename variables from [0,1,...N] to [newVariables[0], newVariables[1], ..., newVariables[N]] (new instance created)static <T extends AMonomial<T>,P extends AMultivariatePolynomial<T,P>>
PrenameVariables(P poly, int[] newVariables, Comparator<DegreeVector> newOrdering)
Rename variables from [0,1,...N] to [newVariables[0], newVariables[1], ..., newVariables[N]] (new instance created)static <T extends AMonomial<T>>
TrenameVariables(T e, int[] newVariables)
Rename variables from [0,1,...N] to [newVariables[0], newVariables[1], ..., newVariables[N]] (new instance created)boolean
sameSkeletonExceptQ(AMultivariatePolynomial oth, int... variables)
Tests whetherthis
andoth
have the same skeleton with respect all except specifiedvariables
boolean
sameSkeletonQ(AMultivariatePolynomial oth)
Tests whetherthis
andoth
have the same skeletonboolean
sameSkeletonQ(AMultivariatePolynomial oth, int... variables)
Tests whetherthis
andoth
have the same skeleton with respect to specifiedvariables
abstract Poly
seriesCoefficient(int variable, int order)
Gives (unevaluated) coefficient of Taylor series expansion for specified variable that isderivative(poly, variable, order) / order!
, where the derivative is formal derivative and calculated with arithmetic performed in Z ring (to overcome possible zeros in Zp).Poly
set(Poly oth)
Sets the content of this tooth
Poly
setAllCoefficientsToUnit()
Set all coefficients to unitsPoly
setLC(int variable, Poly lc)
Set the leading coefficient of specified variable to a specified value (this is considered as R[other_variables][variable])Poly
setNVariables(int newNVariables)
auxiliary methodPoly
setOrdering(Comparator<DegreeVector> newOrdering)
Makes a copy of this with the new orderingnewOrdering
int
size()
Returns the number of terms in this polynomialint
skeletonHashCode()
double
sparsity()
Sparsity level: size / (product of degrees)double
sparsity2()
Sparsity level:size / nDenseTerms
where nDenseTerms is a total number of possible distinct terms with total degree not larger than distinct total degrees presented in this.Poly
subtract(Poly oth)
Subtractsoth
fromthis
.Poly
subtract(Term monomial)
Subtractsmonomial
from this polynomialPoly
subtract(Term cf, Poly oth)
Subtractscf * oth
from this polynomialPoly
subtractLt()
Removes the leading term from this polynomialstatic <T extends AMonomial<T>,P extends AMultivariatePolynomial<T,P>>
PswapVariables(P poly, int i, int j)
Renames variablei
toj
andj
toi
(new instance created)Term[]
toArray()
String
toString()
int
totalDegree()
Returns the total degree, that is sum ofdegrees()
Poly
toZero()
Sets this to zeroint
univariateVariable()
Returns -1 if this poly is not effectively univariate or variable in which it is univariate-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface cc.redberry.rings.poly.IPolynomial
add, assertSameCoefficientRingWith, canonical, ccAsPoly, coefficientRingCardinality, coefficientRingCharacteristic, coefficientRingPerfectPowerBase, coefficientRingPerfectPowerExponent, coefficientRingToString, coefficientRingToString, contentAsPoly, copy, createArray, createArray, createArray, createArray, createArray2d, createArray2d, createConstant, createOne, createZero, decrement, divideByLC, increment, isConstant, isMonic, isOne, isOverField, isOverFiniteField, isOverPerfectPower, isOverZ, isUnitCC, lcAsPoly, monic, monicExact, monicWithLC, multiply, multiply, multiply, multiply, multiplyByBigInteger, multiplyByLC, parsePoly, primitivePart, primitivePartSameSign, sameCoefficientRingWith, setCoefficientRingFrom, setCoefficientRingFromOptional, signumOfLC, square, subtract, toPositiveLC, toString
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface cc.redberry.rings.io.Stringifiable
toString
-
-
-
-
Field Detail
-
nVariables
public final int nVariables
The number of variables
-
ordering
public final Comparator<DegreeVector> ordering
The ordering
-
monomialAlgebra
public final IMonomialAlgebra<Term extends AMonomial<Term>> monomialAlgebra
Monomial algebra
-
-
Method Detail
-
swapVariables
public static <T extends AMonomial<T>,P extends AMultivariatePolynomial<T,P>> P swapVariables(P poly, int i, int j)
Renames variablei
toj
andj
toi
(new instance created)- Parameters:
poly
- the polynomiali
- the first variablej
- the second variable- Returns:
- polynomial with variable
i
renamed toj
andj
renamed toi
-
renameVariables
public static <T extends AMonomial<T>,P extends AMultivariatePolynomial<T,P>> P renameVariables(P poly, int[] newVariables)
Rename variables from [0,1,...N] to [newVariables[0], newVariables[1], ..., newVariables[N]] (new instance created)- Parameters:
poly
- the polynomialnewVariables
- the new variables- Returns:
- renamed polynomial
-
renameVariables
public static <T extends AMonomial<T>> T renameVariables(T e, int[] newVariables)
Rename variables from [0,1,...N] to [newVariables[0], newVariables[1], ..., newVariables[N]] (new instance created)- Parameters:
e
- the termnewVariables
- the new variables- Returns:
- renamed term
-
renameVariables
public static <T extends AMonomial<T>,P extends AMultivariatePolynomial<T,P>> P renameVariables(P poly, int[] newVariables, Comparator<DegreeVector> newOrdering)
Rename variables from [0,1,...N] to [newVariables[0], newVariables[1], ..., newVariables[N]] (new instance created)- Parameters:
poly
- the polynomialnewVariables
- the new variablesnewOrdering
- the new ordering- Returns:
- renamed polynomial
-
asMultivariate
public static <Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>> Poly asMultivariate(IUnivariatePolynomial poly, int nVariables, int variable, Comparator<DegreeVector> ordering)
Converts univariate polynomial to multivariate. Example://convert (x^2 + 1) in Z[x] to multivariate polynomial (c^2 + 1) in Z[a,b,c] multivarPoly = asMultivariate(univarPoly, 3, 2, MonomialOrder.LEX)
- Type Parameters:
Term
- desired terms typePoly
- desired polynomial type- Parameters:
poly
- the univariate polynomialnVariables
- the total number of variables in the resultvariable
- the univariate variableordering
- the term order- Returns:
- the multivariate polynomial
-
asUnivariate
public abstract IUnivariatePolynomial asUnivariate()
Converts this to univariate polynomial or throws exception if conversion is impossible (more than one variable have non zero exponents)- Returns:
- univariate polynomial
- Throws:
IllegalArgumentException
- if this is not effectively a univariate polynomial
-
create
public final Poly create(Term... terms)
Creates multivariate polynomial over the same ring as this from the list of monomials- Parameters:
terms
- the monomials- Returns:
- multivariate polynomial
-
create
public final Poly create(Iterable<Term> terms)
Creates multivariate polynomial over the same ring as this from the list of monomials- Parameters:
terms
- the monomials- Returns:
- multivariate polynomial
-
create
public final Poly create(Term term)
Creates multivariate polynomial over the same ring as this with the single monomial- Parameters:
term
- the monomial- Returns:
- multivariate polynomial
-
createConstantFromTerm
public abstract Poly createConstantFromTerm(Term term)
Creates multivariate polynomial over the same ring as this with the single constant element taken from given monomial- Parameters:
term
- the monomial- Returns:
- multivariate polynomial
-
create
public final Poly create(DegreeVector term)
Creates multivariate polynomial over the same ring as this with the single monomial- Parameters:
term
- the monomial- Returns:
- multivariate polynomial
-
createMonomial
public final Poly createMonomial(int variable, int degree)
Creates monomial over the same ring as this of the formvariable ^ degree
- Parameters:
variable
- the variabledegree
- the monomial degree- Returns:
- monomial
variable ^ degree
-
setOrdering
public final Poly setOrdering(Comparator<DegreeVector> newOrdering)
Makes a copy of this with the new orderingnewOrdering
- Parameters:
newOrdering
- the new ordering- Returns:
- a copy of this with the new ordering
-
release
protected void release()
release caches
-
size
public final int size()
Returns the number of terms in this polynomial- Specified by:
size
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Returns:
- the number of terms
-
isZero
public final boolean isZero()
Description copied from interface:IPolynomial
Returnstrue
if this is zero- Specified by:
isZero
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Returns:
- whether
this
is zero
-
isLinearOrConstant
public boolean isLinearOrConstant()
Description copied from interface:IPolynomial
Returns whether this polynomial is linear (i.e. of the forma * X + b
)- Specified by:
isLinearOrConstant
in interfaceIPolynomial<Term extends AMonomial<Term>>
-
isLinearExactly
public boolean isLinearExactly()
Description copied from interface:IPolynomial
Returns whether this polynomial is linear (i.e. of the forma * X + b
with nonzeroa
)- Specified by:
isLinearExactly
in interfaceIPolynomial<Term extends AMonomial<Term>>
-
isZeroCC
public boolean isZeroCC()
Description copied from interface:IPolynomial
Returns true if constant term is zero- Specified by:
isZeroCC
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Returns:
- whether constant term is zero
-
first
public Term first()
-
last
public Term last()
-
collection
public final Collection<Term> collection()
-
toArray
public final Term[] toArray()
-
isMonomial
public final boolean isMonomial()
Description copied from interface:IPolynomial
Returnstrue
if this polynomial has only one monomial term- Specified by:
isMonomial
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Returns:
- whether
this
has only one monomial term
-
isVariable
public final boolean isVariable()
Returns whether this is a plain variable (with no coefficient)
-
toZero
public final Poly toZero()
Description copied from interface:IPolynomial
Sets this to zero- Specified by:
toZero
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Returns:
- this := zero
-
set
public final Poly set(Poly oth)
Description copied from interface:IPolynomial
Sets the content of this tooth
- Specified by:
set
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Parameters:
oth
- the polynomial- Returns:
- this := oth
-
dropVariable
public final Poly dropVariable(int variable)
Makes a copy of this with the specified variable dropped- Parameters:
variable
- the variable
-
dropVariables
public final Poly dropVariables(int[] variables)
Makes a copy of this with the specified variable replaced with the unit- Parameters:
variables
- the variables
-
dropSelectVariables
public final Poly dropSelectVariables(int... variables)
Makes a copy of this with all variables except specified ones replaced with the units- Parameters:
variables
- the variables
-
insertVariable
public final Poly insertVariable(int variable)
Makes a copy of this by inserting new variable (the indexes will be shifted)- Parameters:
variable
- the variable
-
insertVariable
public final Poly insertVariable(int variable, int count)
Makes a copy of this by inserting new variables (the indexes will be shifted)- Parameters:
variable
- the variablecount
- length of the insertion
-
setNVariables
public final Poly setNVariables(int newNVariables)
auxiliary method
-
mapVariables
public final Poly mapVariables(int[] mapping)
Renames old variables to new according to mapping- Parameters:
mapping
- mapping from old variables to new variables
-
joinNewVariable
public final Poly joinNewVariable()
Returns a copy of this withnVariables = nVariables + 1
- Returns:
- a copy of this with one additional (last) variable added
- See Also:
insertVariable(int)
-
joinNewVariables
public final Poly joinNewVariables(int n)
Returns a copy of this withnVariables = nVariables + m
- Returns:
- a copy of this with n additional (last) variables added
- See Also:
insertVariable(int)
-
nUsedVariables
public final int nUsedVariables()
Returns the number of really used variables (those which are not units)- Returns:
- the number of variables (those which are not units)
-
degree
public int degree()
Returns the total degree of this polynomial, that is the maximal total degree among all terms- Specified by:
degree
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Returns:
- the total degree of this polynomial, that is the maximal total degree among all terms
-
degree
public int degree(int... variables)
Gives the degree in specified variables
-
degreeMax
public int degreeMax()
Returns the maximal degree of variables in this polynomial- Returns:
- the maximal degree of variables in this polynomial
-
degree
public final int degree(int variable)
Returns the degree of this polynomial with respect to specified variable- Parameters:
variable
- the variable- Returns:
- the degree of this polynomial with respect to specified variable
-
degreesRef
protected int[] degreesRef()
returns reference (content must not be modified)
-
degrees
public final int[] degrees()
Returns an array of degrees of all variables, so that is i-th element of the result is the polynomial degree with respect to i-th variable- Returns:
- array of degrees
-
multidegree
public final int[] multidegree()
Returns the multidegree of this polynomial i.e. exponents of the leading term (without copying)- Returns:
- the multidegree of this polynomial i.e. exponents of the leading term (without copying)
-
degrees
public final int[] degrees(int variable)
Returns the array of exponents in whichvariable
occurs in this polynomial- Returns:
- the array of exponents in which
variable
occurs in this polynomial
-
totalDegree
public final int totalDegree()
Returns the total degree, that is sum ofdegrees()
-
sparsity
public double sparsity()
Sparsity level: size / (product of degrees)
-
sparsity2
public double sparsity2()
Sparsity level:size / nDenseTerms
where nDenseTerms is a total number of possible distinct terms with total degree not larger than distinct total degrees presented in this.
-
ecart
public final int ecart()
Returns degreeSum - lt().totalDegree
-
isHomogeneous
public final boolean isHomogeneous()
Returns whether all terms have the same total degree
-
homogenize
public final Poly homogenize(int variable)
Homogenize poly by adding new (homogenizing) variable- Parameters:
variable
- variable that will be inserted (homogenization variable)
-
isEffectiveUnivariate
public final boolean isEffectiveUnivariate()
Returns whether this poly is effectively univariate (not more than one variable is non-unit)- Returns:
- whether this poly is effectively univariate
-
univariateVariable
public final int univariateVariable()
Returns -1 if this poly is not effectively univariate or variable in which it is univariate- Returns:
- -1 if this poly is not effectively univariate or variable in which it is univariate
-
coefficientOf
public final Poly coefficientOf(int variable, int exponent)
Returns a coefficient beforevariable^exponent
as a multivariate polynomial- Parameters:
variable
- the variableexponent
- the exponent- Returns:
- coefficient before
variable^exponent
as a multivariate polynomial
-
coefficientOf
public final Poly coefficientOf(int[] variables, int[] exponents)
Returns a coefficient beforevariables^exponents
as a multivariate polynomial- Parameters:
variables
- the variablesexponents
- the exponents- Returns:
- coefficient before
variables^exponents
as a multivariate polynomial
-
dropCoefficientOf
public final Poly dropCoefficientOf(int[] variables, int[] exponents)
Returns a coefficient beforevariables^exponents
as a multivariate polynomial and drops all such terms from this- Parameters:
variables
- the variablesexponents
- the exponents- Returns:
- coefficient before
variables^exponents
as a multivariate polynomial
-
asUnivariate
public final UnivariatePolynomial<Poly> asUnivariate(int variable)
Converts this polynomial to a univariate polynomial over specified variable with the multivariate coefficient ring.- Parameters:
variable
- variable which will be treated as univariate variable- Returns:
- univariate polynomial over the ring of multivariate coefficients
- Throws:
IllegalArgumentException
- if this is not effectively a univariate polynomial
-
asUnivariateEliminate
public final UnivariatePolynomial<Poly> asUnivariateEliminate(int variable)
Converts this polynomial to a univariate polynomial over specified variable with the multivariate coefficient ring.- Parameters:
variable
- variable which will be treated as univariate variable- Returns:
- univariate polynomial over the ring of multivariate coefficients
- Throws:
IllegalArgumentException
- if this is not effectively a univariate polynomial
-
asMultivariate
public static <Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>> Poly asMultivariate(UnivariatePolynomial<Poly> univariate, int uVariable, boolean join)
-
asOverUnivariate
public abstract MultivariatePolynomial<? extends IUnivariatePolynomial> asOverUnivariate(int variable)
Converts this to a multivariate polynomial with coefficients being univariate polynomials overvariable
- Parameters:
variable
- variable- Returns:
- multivariate polynomial with coefficients being univariate polynomials over
variable
-
asOverUnivariateEliminate
public abstract MultivariatePolynomial<? extends IUnivariatePolynomial> asOverUnivariateEliminate(int variable)
Converts this to a multivariate polynomial with coefficients being univariate polynomials overvariable
, the resulting polynomial have (nVariable - 1) multivariate variables (specifiedvariable
is eliminated)- Parameters:
variable
- the variable- Returns:
- multivariate polynomial with coefficients being univariate polynomials over
variable
, the resulting polynomial have (nVariable - 1) multivariate variables
-
asOverMultivariate
public abstract MultivariatePolynomial<Poly> asOverMultivariate(int... variables)
Converts this to a multivariate polynomial with coefficients being multivariate polynomials polynomials overvariables
that is polynomial in R[variables][other_variables]- Parameters:
variables
- the variables to separate- Returns:
- multivariate polynomial with coefficients being multivariate polynomials polynomials over
variables
that is polynomial in R[variables][other_variables]
-
asOverMultivariateEliminate
public final MultivariatePolynomial<Poly> asOverMultivariateEliminate(int... variables)
Converts this to a multivariate polynomial with coefficients being multivariate polynomials polynomials overvariables
that is polynomial in R[variables][other_variables]- Parameters:
variables
- the variables to separate- Returns:
- multivariate polynomial with coefficients being multivariate polynomials polynomials over
variables
that is polynomial in R[variables][other_variables]
-
asOverMultivariateEliminate
public abstract MultivariatePolynomial<Poly> asOverMultivariateEliminate(int[] variables, Comparator<DegreeVector> ordering)
Converts this to a multivariate polynomial with coefficients being multivariate polynomials polynomials overvariables
that is polynomial in R[variables][other_variables]- Parameters:
variables
- the variables to separateordering
- monomial order to use for result- Returns:
- multivariate polynomial with coefficients being multivariate polynomials polynomials over
variables
that is polynomial in R[variables][other_variables]
-
asMultivariate
public static <Term extends AMonomial<Term>,Poly extends AMultivariatePolynomial<Term,Poly>> Poly asMultivariate(UnivariatePolynomial<Poly> uPoly, int variable)
Convert univariate polynomial over multivariate polynomials to a normal multivariate poly- Parameters:
uPoly
- univariate polynomial over multivariate polynomialsvariable
- the univariate variable- Returns:
- multivariate poly
-
primitivePart
public abstract Poly primitivePart(int variable)
Gives primitive part of this considered as R[variable][other_variables]- Parameters:
variable
- the variable- Returns:
- primitive part of this considered as R[variable][other_variables]
-
contentUnivariate
public abstract IUnivariatePolynomial contentUnivariate(int variable)
Gives the content of this considered as R[variable][other_variables]- Parameters:
variable
- the variable- Returns:
- the content of this considered as R[variable][other_variables]
-
monic
public abstract Poly monic(Comparator<DegreeVector> ordering)
Make this poly monic considering leading term with respect to given ordering
-
monicWithLC
public abstract Poly monicWithLC(Comparator<DegreeVector> ordering, Poly oth)
Setsthis
to its monic part multiplied by the leading coefficient ofother
with respect to given ordering
-
content
public final Poly content(int variable)
Gives the content of this considered as R[variable][other_variables]- Parameters:
variable
- the variable- Returns:
- the content of this considered as R[variable][other_variables]
-
contentExcept
public final Poly contentExcept(int variable)
Gives the content of this considered as R[other_variables][variable]- Parameters:
variable
- the variable- Returns:
- the content of this considered as R[other_variables][variable]
-
multiplyByMonomial
public final Poly multiplyByMonomial(int variable, int exponent)
Multiplies this by variable^exponent- Parameters:
variable
- the variableexponent
- the exponent- Returns:
- this multiplied by variable^exponent
-
lc
public final Poly lc(int variable)
Returns the leading coefficient of this viewed as R[other_variables][variable]- Parameters:
variable
- the variable- Returns:
- multivariate leading coefficient of this viewed as R[other_variables][variable]
-
setLC
public final Poly setLC(int variable, Poly lc)
Set the leading coefficient of specified variable to a specified value (this is considered as R[other_variables][variable])- Parameters:
variable
- the variablelc
- the leading coefficient of this viewed as R[other_variables][variable]
-
lt
public final Term lt(Comparator<DegreeVector> ordering)
Returns the leading term in this polynomial according to specified ordering- Returns:
- the leading term in this polynomial according to specified ordering
-
lt
public final Term lt()
Returns the leading term in this polynomial according to ordering- Returns:
- the leading term in this polynomial according to ordering
-
mt
public final Term mt()
Returns the minimal term in this polynomial according to ordering- Returns:
- the minimal term in this polynomial according to ordering
-
lcAsPoly
public abstract Poly lcAsPoly(Comparator<DegreeVector> ordering)
Returns the leading coefficient with respect to specified ordering as a constant poly
-
ltAsPoly
public final Poly ltAsPoly()
Returns the leading term in this polynomial according to ordering- Returns:
- the leading term in this polynomial according to ordering
-
monomialContent
public final Term monomialContent()
Returns the monomial content of this polynomial- Returns:
- the monomial content of this polynomial
-
divideDegreeVectorOrNull
public final Poly divideDegreeVectorOrNull(DegreeVector monomial)
Divides this polynomial by amonomial
or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by themonomial
. NOTE: ifnull
is returned, the content ofthis
is destroyed.- Parameters:
monomial
- monomial- Returns:
this
divided by thefactor * monomial
ornull
-
divideOrNull
public abstract Poly divideOrNull(Term monomial)
Divides this polynomial by amonomial
or returnsnull
(causing loss of internal data) if some of the elements can't be exactly divided by themonomial
. NOTE: ifnull
is returned, the content ofthis
is destroyed.- Parameters:
monomial
- monomial degrees- Returns:
this
divided by thefactor * monomial
ornull
-
add
public final Poly add(Poly oth)
Description copied from interface:IPolynomial
Addsoth
tothis
.- Specified by:
add
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Parameters:
oth
- the polynomial- Returns:
this + oth
-
subtract
public final Poly subtract(Poly oth)
Description copied from interface:IPolynomial
Subtractsoth
fromthis
.- Specified by:
subtract
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Parameters:
oth
- the polynomial- Returns:
this - oth
-
add
public final Poly add(Term monomial)
Addsmonomial
to this polynomial- Parameters:
monomial
- the monomial- Returns:
this + monomial
-
put
public final Poly put(Term monomial)
Putsmonomial
to this polynomial replacing the previous entry if was
-
subtract
public final Poly subtract(Term monomial)
Subtractsmonomial
from this polynomial- Parameters:
monomial
- the monomial- Returns:
this - monomial
-
negate
public final Poly negate()
Description copied from interface:IPolynomial
Negates this and returns- Specified by:
negate
in interfaceIPolynomial<Term extends AMonomial<Term>>
- Returns:
- this negated
-
add
public final Poly add(Iterable<Term> monomials)
Adds monomials to this polynomial- Parameters:
monomials
- terms- Returns:
this + monomials
-
add
public final Poly add(Term... monomials)
Adds monomials to this polynomial- Parameters:
monomials
- terms- Returns:
this + monomials
-
subtractLt
public final Poly subtractLt()
Removes the leading term from this polynomial- Returns:
- this - this.lt()
-
multiply
public abstract Poly multiply(Term monomial)
Multipliesthis
by themonomial
- Parameters:
monomial
- the monomial- Returns:
- this multiplied by the
monomial
-
multiplyByDegreeVector
public final Poly multiplyByDegreeVector(DegreeVector dv)
Multipliesthis
by the degree vector- Parameters:
dv
- the degree vector- Returns:
- this multiplied by the degree vector
-
getSkeleton
public final Set<DegreeVector> getSkeleton()
Returns skeleton of this poly- Returns:
- skeleton of this poly
-
setAllCoefficientsToUnit
public final Poly setAllCoefficientsToUnit()
Set all coefficients to units
-
getSkeleton
public final Set<DegreeVector> getSkeleton(int... variables)
Returns skeleton of this poly with respect to specifiedvariables
- Parameters:
variables
- the variables- Returns:
- skeleton of this poly with respect to specified
variables
-
getSkeletonDrop
public final Set<DegreeVector> getSkeletonDrop(int... variables)
Returns skeleton of this poly with respect to specifiedvariables
- Parameters:
variables
- the variables- Returns:
- skeleton of this poly with respect to specified
variables
-
getSkeletonExcept
public final Set<DegreeVector> getSkeletonExcept(int... variables)
Returns skeleton of this poly with respect to all except specifiedvariables
- Parameters:
variables
- the variables to exclude- Returns:
- skeleton of this poly with respect to all except specified
variables
-
sameSkeletonQ
public final boolean sameSkeletonQ(AMultivariatePolynomial oth)
Tests whetherthis
andoth
have the same skeleton- Parameters:
oth
- other multivariate polynomial- Returns:
true
ifthis
andoth
have the same skeleton andfalse
otherwise
-
sameSkeletonQ
public final boolean sameSkeletonQ(AMultivariatePolynomial oth, int... variables)
Tests whetherthis
andoth
have the same skeleton with respect to specifiedvariables
- Parameters:
oth
- other multivariate polynomialvariables
- variables to test- Returns:
true
ifthis
andoth
have the same skeleton with respect to specifiedvariables
andfalse
otherwise
-
sameSkeletonExceptQ
public final boolean sameSkeletonExceptQ(AMultivariatePolynomial oth, int... variables)
Tests whetherthis
andoth
have the same skeleton with respect all except specifiedvariables
- Parameters:
oth
- other multivariate polynomialvariables
- variables to exclude- Returns:
true
ifthis
andoth
have the same skeleton with respect to all except specifiedvariables
andfalse
otherwise
-
derivative
public final Poly derivative(int variable)
Gives partial derivative with respect to specified variable (new instance created)- Parameters:
variable
- the variable- Returns:
- partial derivative with respect to specified variable
-
derivative
public abstract Poly derivative(int variable, int order)
Gives partial derivative of specifiedorder
with respect to specified variable (new instance created)- Parameters:
variable
- the variableorder
- derivative order- Returns:
- partial derivative of specified
order
with respect to specified variable
-
seriesCoefficient
public abstract Poly seriesCoefficient(int variable, int order)
Gives (unevaluated) coefficient of Taylor series expansion for specified variable that isderivative(poly, variable, order) / order!
, where the derivative is formal derivative and calculated with arithmetic performed in Z ring (to overcome possible zeros in Zp).- Parameters:
variable
- the variableorder
- derivative order- Returns:
derivative(poly, variable, order) / order!
, where the derivative is formal derivative and calculated with arithmetic performed in Z ring (to overcome possible zeros in Zp)
-
evaluateAtZero
public final Poly evaluateAtZero(int variable)
Substitutes0
forvariable
(new instance created).- Parameters:
variable
- the variable- Returns:
- a new multivariate polynomial with
0
substituted forvariable
-
evaluateAtZero
public final Poly evaluateAtZero(int[] variables)
Substitutes0
for all specifiedvariables
(new instance created).- Parameters:
variables
- the variables- Returns:
- a new multivariate polynomial with
0
substituted for all specifiedvariables
-
derivative
public final Poly[] derivative()
Gives the derivative vector- Returns:
- derivative vector
-
asOverPoly
public final MultivariatePolynomial<Poly> asOverPoly(Poly factory)
Consider coefficients of this as constant polynomials of the same type as a given factory polynomial- Parameters:
factory
- factory polynomial
-
composition
public final Poly composition(Poly... values)
Substitutes given polynomials instead of variables of this (that isthis(values_1, ..., values_N)
)- Parameters:
values
- polynomial values (may have different nvars from this)
-
composition
public final <sPoly extends IUnivariatePolynomial<sPoly>> sPoly composition(sPoly... values)
Substitutes given polynomials instead of variables of this (that isthis(values_1, ..., values_N)
)- Parameters:
values
- polynomial values (may have different nvars from this)
-
composition
public final <sPoly extends IUnivariatePolynomial<sPoly>> sPoly composition(Ring<sPoly> uRing, sPoly... values)
Substitutes given polynomials instead of variables of this (that isthis(values_1, ..., values_N)
)- Parameters:
uRing
- ring of univariate polynomialsvalues
- polynomial values (may have different nvars from this)
-
composition
public final Poly composition(List<Poly> values)
Substitutes given polynomials instead of variables of this (that isthis(values_1, ..., values_N)
)- Parameters:
values
- polynomial values (may have different nvars from this)
-
composition
public final Poly composition(int variable, Poly value)
Substitutes given polynomial instead of specified variable (that isthis(x_1, ..., value, ..., x_N)
, where value is on the place of specified variable)
-
composition
public final Poly composition(int[] variables, Poly[] values)
Substitutes given polynomial instead of specified variable (that isthis(x_1, ..., value, ..., x_N)
, where value is on the place of specified variable)
-
skeletonHashCode
public int skeletonHashCode()
-
clone
public abstract Poly clone()
Description copied from interface:IPolynomial
Deep copy of this
-
evaluateAtRandom
public abstract Poly evaluateAtRandom(int variable, org.apache.commons.math3.random.RandomGenerator rnd)
Evaluatespoly
at random point
-
evaluateAtRandomPreservingSkeleton
public abstract Poly evaluateAtRandomPreservingSkeleton(int variable, org.apache.commons.math3.random.RandomGenerator rnd)
Evaluatespoly
at random point chosen in such way that the skeleton of evaluated version is the same as of the originalpoly
with respect to all exceptvariable
variables
-
mapCoefficientsAsPolys
public abstract <E> MultivariatePolynomial<E> mapCoefficientsAsPolys(Ring<E> ring, Function<Poly,E> mapper)
-
-