Types
Variables
MultivariatePolynomials.AbstractVariable
— TypeAbstractVariable <: AbstractMonomialLike
Abstract type for a variable.
MultivariatePolynomials.variable
— Functionvariable(p::AbstractPolynomialLike)
Converts p
to a variable. Throws InexactError
if it is not possible.
Examples
Calling variable(x^2 + x - x^2)
should return the variable x
and calling variable(1.0y)
should return the variable y
however calling variable(2x)
or variable(x + y)
should throw InexactError
.
Note
This operation is not type stable for the TypedPolynomials implementation if nvariables(p) > 1
but is type stable for DynamicPolynomials.
MultivariatePolynomials.name
— Functionname(v::AbstractVariable)::AbstractString
Returns the name of a variable.
MultivariatePolynomials.name_base_indices
— Functionname_base_indices(v::AbstractVariable)
Returns the name of the variable (as a String
or Symbol
) and its indices as a Vector{Int}
or tuple of Int
s.
MultivariatePolynomials.variable_union_type
— Functionvariable_union_type(p::AbstractPolynomialLike)
Return the supertype for variables of p
. If p
is a variable, it should not be the type of p
but the supertype of all variables that could be created.
Examples
For TypedPolynomials
, a variable of name x
has type Variable{:x}
so variable_union_type
should return Variable
. For DynamicPolynomials
, all variables have the same type Variable{C}
where C
is true
for commutative variables and false
for non-commutative ones so variable_union_type
should return Variable{C}
.
MultivariatePolynomials.similar_variable
— Functionsimilar_variable(p::AbstractPolynomialLike, variable::Type{Val{V}})
Creates a new variable V
based upon the the given source polynomial.
similar_variable(p::AbstractPolynomialLike, v::Symbol)
Creates a new variable based upon the given source polynomial and the given symbol v
. Note that this can lead to type instabilities.
Examples
Calling similar_variable(typedpoly, Val{:x})
on a polynomial created with TypedPolynomials
results in TypedPolynomials.Variable{:x}
.
MultivariatePolynomials.@similar_variable
— Macro@similar_variable(p::AbstractPolynomialLike, variable)
Calls similar_variable(p, Val{variable})
and binds the result to a variable with the same name.
Examples
Calling @similar_variable typedpoly x
on a polynomial created with TypedPolynomials
binds TypedPolynomials.Variable{:x}
to the variable x
.
Base.conj
— Methodconj(x::AbstractVariable)
Return the complex conjugate of a given variable if it was declared as a complex variable; else return the variable unchanged.
Base.real
— Methodreal(x::AbstractVariable)
Return the real part of a given variable if it was declared as a complex variable; else return the variable unchanged.
See also imag
.
Base.imag
— Methodimag(x::AbstractVariable)
Return the imaginary part of a given variable if it was declared as a complex variable; else return zero.
See also isreal
, isimagpart
, real
.
Base.isreal
— Methodisreal(x::AbstractVariable)
Return whether a given variable was declared as a real-valued or complex-valued variable (also their conjugates are complex, but their real and imaginary parts are not). By default, all variables are real-valued.
MultivariatePolynomials.isrealpart
— Functionisrealpart(x::AbstractVariable)
Return whether the given variable is the real part of a complex-valued variable.
See also isreal
, isimagpart
, isconj
.
MultivariatePolynomials.isimagpart
— Functionisimagpart(x::AbstractVariable)
Return whether the given variable is the imaginary part of a complex-valued variable.
See also isreal
, isrealpart
, isconj
.
MultivariatePolynomials.isconj
— Functionisconj(x::AbstractVariable)
Return whether the given variable is obtained by conjugating a user-defined complex-valued variable.
See also isreal
, isrealpart
, isimagpart
.
MultivariatePolynomials.ordinary_variable
— Functionordinary_variable(x::Union{AbstractVariable, AbstractVector{<:AbstractVariable}})
Given some (complex-valued) variable that was transformed by conjugation, taking its real part, or taking its imaginary part, return the original variable as it was defined by the user.
Monomials
MultivariatePolynomials.AbstractMonomialLike
— TypeAbstractMonomialLike
Abstract type for a value that can act like a monomial. For instance, an AbstractVariable
is an AbstractMonomialLike
since it can act as a monomial of one variable with degree 1
.
MultivariatePolynomials.AbstractMonomial
— TypeAbstractMonomial <: AbstractMonomialLike
Abstract type for a monomial, i.e. a product of variables elevated to a nonnegative integer power.
MultivariatePolynomials.monomial_type
— Functionmonomial_type(p::AbstractPolynomialLike)
Return the type of the monomials of p
.
term_type(::Type{PT}) where PT<:AbstractPolynomialLike
Returns the type of the monomials of a polynomial of type PT
.
MultivariatePolynomials.variables
— Functionvariables(p::AbstractPolynomialLike)
Returns the tuple of the variables of p
in decreasing order. It could contain variables of zero degree, see the example section.
Examples
Calling variables(x^2*y)
should return (x, y)
and calling variables(x)
should return (x,)
. Note that the variables of m
does not necessarily have nonzero degree. For instance, variables([x^2*y, y*z][1])
is usually (x, y, z)
since the two monomials have been promoted to a common type.
MultivariatePolynomials.effective_variables
— Functioneffective_variables(p::AbstractPolynomialLike)
Return a vector of eltype
variable_union_type(p)
(see variable_union_type
), containing all the variables that has nonzero degree in at least one term. That is, return all the variables v
such that maxdegree(p, v)
is not zero. The returned vector is sorted in decreasing order.
MultivariatePolynomials.nvariables
— Functionnvariables(p::AbstractPolynomialLike)
Returns the number of variables in p
, i.e. length(variables(p))
. It could be more than the number of variables with nonzero degree (see the Examples section of variables
).
Examples
Calling nvariables(x^2*y)
should return at least 2 and calling nvariables(x)
should return at least 1.
MultivariatePolynomials.exponents
— Functionexponents(t::AbstractTermLike)
Returns the exponent of the variables in the monomial of the term t
.
Examples
Calling exponents(x^2*y)
should return (2, 1)
.
MultivariatePolynomials.degree
— Functiondegree(t::AbstractTermLike)
Returns the total degree of the monomial of the term t
, i.e. sum(exponents(t))
.
degree(t::AbstractTermLike, v::AbstractVariable)
Returns the exponent of the variable v
in the monomial of the term t
.
Examples
Calling degree(x^2*y)
should return 3 which is $2 + 1$. Calling degree(x^2*y, x)
should return 2 and calling degree(x^2*y, y)
should return 1.
MultivariatePolynomials.isconstant
— Functionisconstant(t::AbstractTermLike)
Returns whether the monomial of t
is constant.
MultivariatePolynomials.powers
— Functionpowers(t::AbstractTermLike)
Returns an iterator over the powers of the monomial of t
.
Examples
Calling powers(3x^4*y) should return
((x, 4), (y, 1))`.
MultivariatePolynomials.constant_monomial
— Functionconstant_monomial(p::AbstractPolynomialLike)
Returns a constant monomial of the monomial type of p
with the same variables as p
.
constant_monomial(::Type{PT}) where {PT<:AbstractPolynomialLike}
Returns a constant monomial of the monomial type of a polynomial of type PT
.
MultivariatePolynomials.map_exponents
— Functionmap_exponents(f, m1::AbstractMonomialLike, m2::AbstractMonomialLike)
If $m_1 = \prod x^{\alpha_i}$ and $m_2 = \prod x^{\beta_i}$ then it returns the monomial $m = \prod x^{f(\alpha_i, \beta_i)}$.
Examples
The multiplication m1 * m2
is equivalent to map_exponents(+, m1, m2)
, the unsafe division div_multiple(m1, m2)
is equivalent to map_exponents(-, m1, m2)
, gcd(m1, m2)
is equivalent to map_exponents(min, m1, m2)
, lcm(m1, m2)
is equivalent to map_exponents(max, m1, m2)
.
MultivariatePolynomials.multiplication_preserves_monomial_order
— Functionmultiplication_preserves_monomial_order(P::Type{<:AbstractPolynomialLike})
Returns a Bool
indicating whether the order is preserved in the multiplication of monomials of type monomial_type(P)
. That is, if a < b
then a * c < b * c
for any monomial c
. This returns true
by default. This is used by Polynomial
so a monomial type for which the multiplication does not preserve the monomial order can still be used with Polynomial
if it implements a method for this function that returns false
.
Ordering
MultivariatePolynomials.AbstractMonomialOrdering
— Typeabstract type AbstractMonomialOrdering end
Abstract type for monomial ordering as defined in [CLO13, Definition 2.2.1, p. 55]
[CLO13] Cox, D., Little, J., & OShea, D. Ideals, varieties, and algorithms: an introduction to computational algebraic geometry and commutative algebra. Springer Science & Business Media, 2013.
MultivariatePolynomials.ordering
— Functionordering(p::AbstractPolynomialLike)
Returns the AbstractMonomialOrdering
used for the monomials of p
.
MultivariatePolynomials.compare
— Functioncompare(a, b, order::Type{<:AbstractMonomialOrdering})
Returns a negative number if a < b
, a positive number if a > b
and zero if a == b
. The comparison is done according to order
.
MultivariatePolynomials.LexOrder
— Typestruct LexOrder <: AbstractMonomialOrdering end
Lexicographic (Lex for short) Order often abbreviated as lex order as defined in [CLO13, Definition 2.2.3, p. 56]
The Graded
version is often abbreviated as grlex order and is defined in [CLO13, Definition 2.2.5, p. 58]
[CLO13] Cox, D., Little, J., & OShea, D. Ideals, varieties, and algorithms: an introduction to computational algebraic geometry and commutative algebra. Springer Science & Business Media, 2013.
MultivariatePolynomials.InverseLexOrder
— Typestruct InverseLexOrder <: AbstractMonomialOrdering end
Inverse Lex Order defined in [CLO13, Exercise 2.2.6, p. 61] where it is abbreviated as invlex. It corresponds to LexOrder
but with the variables in reverse order.
The Graded
version can be abbreviated as grinvlex order. It is defined in [BDD13, Definition 2.1] where it is called Graded xel order.
[CLO13] Cox, D., Little, J., & OShea, D. Ideals, varieties, and algorithms: an introduction to computational algebraic geometry and commutative algebra. Springer Science & Business Media, 2013. [BDD13] Batselier, K., Dreesen, P., & De Moor, B. The geometry of multivariate polynomial division and elimination. SIAM Journal on Matrix Analysis and Applications, 34(1), 102-125, 2013.
MultivariatePolynomials.Graded
— Typestruct Graded{O<:AbstractMonomialOrdering} <: AbstractMonomialOrdering
same_degree_ordering::O
end
Monomial ordering defined by:
degree(a) == degree(b)
then the ordering is determined bysame_degree_ordering
,- otherwise, it is the ordering between the integers
degree(a)
anddegree(b)
.
MultivariatePolynomials.Reverse
— Typestruct Reverse{O<:AbstractMonomialOrdering} <: AbstractMonomialOrdering
reverse_order::O
end
Monomial ordering defined by compare(a, b, ::Type{Reverse{O}}) where {O} = compare(b, a, O)
.
Reverse Lex Order defined in [CLO13, Exercise 2.2.9, p. 61] where it is abbreviated as rinvlex. can be obtained as Reverse{InverseLexOrder}
.
The Graded Reverse Lex Order often abbreviated as grevlex order defined in [CLO13, Definition 2.2.6, p. 58] can be obtained as Graded{Reverse{InverseLexOrder}}
.
[CLO13] Cox, D., Little, J., & OShea, D. Ideals, varieties, and algorithms: an introduction to computational algebraic geometry and commutative algebra. Springer Science & Business Media, 2013.
Terms
MultivariatePolynomials.AbstractTermLike
— TypeAbstractTermLike{T}
Abstract type for a value that can act like a term. For instance, an AbstractMonomial
is an AbstractTermLike{Int}
since it can act as a term with coefficient 1
.
MultivariatePolynomials.AbstractTerm
— TypeAbstractTerm{T} <: AbstractTermLike{T}
Abstract type for a term of coefficient type T
, i.e. the product between a value of type T
and a monomial.
MultivariatePolynomials.Term
— Typestruct Term{CoeffType,M<:AbstractMonomial} <: AbstractTerm{CoeffType}
coefficient::CoeffType
monomial::M
end
A representation of the multiplication between a coefficient
and a monomial
.
The coefficient
does not need to be a Number
. It can be for instance a multivariate polynomial. When computing a multivariate gcd
, it is actually reformulated as a univariate gcd
in one of the variable with coefficients being multivariate polynomials in the other variables. To create such a term, use term
instead of *
. For instance, if p
is a polynomial and m
is a monomial, p * m
will multiply each term of p
with m
but term(p, m)
will create a term with p
as coefficient and m
as monomial.
MultivariatePolynomials.term
— Functionterm(coef, mono::AbstractMonomialLike)
Returns a term with coefficient coef
and monomial mono
. There are two key difference between this and coef * mono
:
term(coef, mono)
does not copycoef
andmono
so modifying this term with MutableArithmetics may modifying the input of this function. To avoid this, callterm(MA.copy_if_mutable(coef), MA.copy_if_mutable(mono))
whereMA = MutableArithmetics
.Suppose that
coef = (x + 1)
andmono = x^2
,coef * mono
gives the polynomial with integer coefficientsx^3 + x^2
whichterm(x + 1, x^2)
gives a term with polynomial coefficientx + 1
.term(p::AbstractPolynomialLike)
Converts the polynomial p
to a term. When applied on a polynomial, it throws an InexactError
if it has more than one term. When applied to a term, it is the identity and does not copy it. When applied to a monomial, it create a term of type AbstractTerm{Int}
.
MultivariatePolynomials.term_type
— Functionterm_type(p::AbstractPolynomialLike)
Returns the type of the terms of p
.
term_type(::Type{PT}) where PT<:AbstractPolynomialLike
Returns the type of the terms of a polynomial of type PT
.
term_type(p::AbstractPolynomialLike, ::Type{T}) where T
Returns the type of the terms of p
but with coefficient type T
.
term_type(::Type{PT}, ::Type{T}) where {PT<:AbstractPolynomialLike, T}
Returns the type of the terms of a polynomial of type PT
but with coefficient type T
.
MultivariatePolynomials.coefficient
— Functioncoefficient(t::AbstractTermLike)
Returns the coefficient of the term t
.
coefficient(p::AbstractPolynomialLike, m::AbstractMonomialLike)
Returns the coefficient of the monomial m
in p
.
Examples
Calling coefficient
on $4x^2y$ should return $4$. Calling coefficient(2x + 4y^2 + 3, y^2)
should return $4$. Calling coefficient(2x + 4y^2 + 3, x^2)
should return $0$.
MultivariatePolynomials.coefficient_type
— Functioncoefficient_type(p::AbstractPolynomialLike)
Returns the coefficient type of p
.
coefficient_type(::Type{PT}) where PT
Returns the coefficient type of a polynomial of type PT
.
Examples
Calling coefficient_type
on $(4//5)x^2y$ should return Rational{Int}
, calling coefficient_type
on $1.0x^2y + 2.0x$ should return Float64
and calling coefficient_type
on $xy$ should return Int
.
MultivariatePolynomials.monomial
— Functionmonomial(t::AbstractTermLike)
Returns the monomial of the term t
.
Examples
Calling monomial
on $4x^2y$ should return $x^2y$.
MultivariatePolynomials.constant_term
— Functionconstant_term(α, p::AbstractPolynomialLike)
Creates a constant term with coefficient α and the same variables as p.
constant_term(α, ::Type{PT} where {PT<:AbstractPolynomialLike}
Creates a constant term of the term type of a polynomial of type PT
.
MultivariatePolynomials.zero_term
— Functionzero_term(p::AbstractPolynomialLike{T}) where T
Equivalent to constant_term(zero(T), p)
.
zero_term(α, ::Type{PT} where {T, PT<:AbstractPolynomialLike{T}}
Equivalent to constant_term(zero(T), PT)
.
MultivariatePolynomials.degree_complex
— Functiondegree_complex(t::AbstractTermLike)
Return the total complex degree of the monomial of the term t
, i.e., the maximum of the total degree of the declared variables in t
and the total degree of the conjugate variables in t
. To be well-defined, the monomial must not contain real parts or imaginary parts of variables. If x₁
and x₂
are real-valued variables and z₁
and z₂
are complex-valued,
degree_complex(x₁^2 * x₂^3) = 5
degree_complex(z₁^3 * conj(z₁)^4) = max(3, 4) = 4
anddegree_complex(z₁^4 * conj(z₁)^3) = max(4, 3) = 4
degree_complex(z₁^3 * z₂ * conj(z₁)^2 * conj(z₂)^4) = max(4, 6) = 6
anddegree_complex(z₁^4 * z₂ * conj(z₁) * conj(z₂)^3) = max(5, 4) = 5
degree_complex(x₁^2 * x₂^3 * z₁^3 * z₂ * conj(z₁)^2 * conj(z₂)^4) = 5 + max(4, 6) = 11
degree_complex(t::AbstractTermLike, v::AbstractVariable)
Returns the exponent of the variable v
or its conjugate in the monomial of the term t
, whatever is larger.
See also isconj
.
MultivariatePolynomials.halfdegree
— Functionhalfdegree(t::AbstractTermLike)
Return the equivalent of ceil(degree(t)/2)
for real-valued terms or
degree_complex(t)for terms with only complex variables; however, respect any mixing between complex and real-valued variables. To be well-defined, the monomial must not contain real parts or imaginary parts of variables. If
x₁and
x₂are real-valued variables and
z₁and
z₂` are complex-valued,
halfdegree(x₁^2 * x₂^3) = ⌈5/2⌉ = 3
halfdegree(z₁^3 * conj(z₁)^4) = max(3, 4) = 4
andhalfdegree(z₁^4 * conj(z₁)^3) = max(4, 3) = 4
halfdegree(z₁^3 * z₂ * conj(z₁)^2 * conj(z₂)^4) = max(4, 6) = 6
andhalfdegree(z₁^4 * z₂ * conj(z₁) * conj(z₂)^3) = max(5, 4) = 5
halfdegree(x₁^2 * x₂^3 * z₁^3 * z₂ * conj(z₁)^2 * conj(z₂)^4) = ⌈5/2⌉ + max(4, 6) = 9
Polynomials
MultivariatePolynomials.AbstractPolynomialLike
— TypeAbstractPolynomialLike{T}
Abstract type for a value that can act like a polynomial. For instance, an AbstractTerm{T}
is an AbstractPolynomialLike{T}
since it can act as a polynomial of only one term.
MultivariatePolynomials.AbstractPolynomial
— TypeAbstractPolynomial{T} <: AbstractPolynomialLike{T}
Abstract type for a polynomial of coefficient type T
, i.e. a sum of AbstractTerm{T}
s.
MultivariatePolynomials.Polynomial
— Typestruct Polynomial{CoeffType,T<:AbstractTerm{CoeffType},V<:AbstractVector{T}} <: AbstractPolynomial{CoeffType}
terms::V
end
Representation of a multivariate polynomial as a vector of nonzero terms sorted in ascending monomial order.
MultivariatePolynomials.polynomial
— Functionpolynomial(p::AbstractPolynomialLike)
Converts p
to a value with polynomial type.
polynomial(p::AbstractPolynomialLike, ::Type{T}) where T
Converts p
to a value with polynomial type with coefficient type T
.
polynomial(a::AbstractVector, mv::AbstractVector{<:AbstractMonomialLike})
Creates a polynomial equal to dot(a, mv)
.
polynomial(terms::AbstractVector{<:AbstractTerm}, s::ListState=MessyState())
Creates a polynomial equal to sum(terms)
where terms
are guaranteed to be in state s
.
polynomial(f::Function, mv::AbstractVector{<:AbstractMonomialLike})
Creates a polynomial equal to sum(f(i) * mv[i] for i in 1:length(mv))
.
Examples
Calling polynomial([2, 4, 1], [x, x^2*y, x*y])
should return $4x^2y + xy + 2x$.
MultivariatePolynomials.polynomial_type
— Functionpolynomial_type(p::AbstractPolynomialLike)
Returns the type that p
would have if it was converted into a polynomial.
polynomial_type(::Type{PT}) where PT<:AbstractPolynomialLike
Returns the same as polynomial_type(::PT)
.
polynomial_type(p::AbstractPolynomialLike, ::Type{T}) where T
Returns the type that p
would have if it was converted into a polynomial of coefficient type T
.
polynomial_type(::Type{PT}, ::Type{T}) where {PT<:AbstractPolynomialLike, T}
Returns the same as polynomial_type(::PT, ::Type{T})
.
MultivariatePolynomials.terms
— Functionterms(p::AbstractPolynomialLike)
Returns an iterator over the nonzero terms of the polynomial p
sorted in the decreasing monomial order.
Examples
Calling terms
on $4x^2y + xy + 2x$ should return an iterator of $[4x^2y, xy, 2x]$.
MultivariatePolynomials.nterms
— Functionnterms(p::AbstractPolynomialLike)
Returns the number of nonzero terms in p
, i.e. length(terms(p))
.
Examples
Calling nterms
on $4x^2y + xy + 2x$ should return 3.
MultivariatePolynomials.coefficients
— Functioncoefficients(p::AbstractPolynomialLike)
Returns an iterator over the coefficients of p
of the nonzero terms of the polynomial sorted in the decreasing monomial order.
coefficients(p::AbstractPolynomialLike, X::AbstractVector)
Returns an iterator over the coefficients of the monomials of X
in p
where X
is a monomial vector not necessarily sorted but with no duplicate entry.
Examples
Calling coefficients
on $4x^2y + xy + 2x$ should return an iterator of $[4, 1, 2]$. Calling coefficients(4x^2*y + x*y + 2x + 3, [x, 1, x*y, y])
should return an iterator of $[2, 3, 1, 0]$.
MultivariatePolynomials.coefficient
— Methodcoefficient(p::AbstractPolynomialLike, m::AbstractMonomialLike, vars)::AbstractPolynomialLike
Returns the coefficient of the monomial m
of the polynomial p
considered as a polynomial in variables vars
.
Example
Calling coefficient((a+b)x^2+2x+y*x^2, x^2, [x,y])
should return a+b
. Calling coefficient((a+b)x^2+2x+y*x^2, x^2, [x])
should return a+b+y
.
MultivariatePolynomials.monomials
— Functionmonomials(p::AbstractPolynomialLike)
Returns an iterator over the monomials of p
of the nonzero terms of the polynomial sorted in the decreasing order.
monomials(vars::Tuple, degs::AbstractVector{Int}, filter::Function = m -> true)
Builds the vector of all the monomial_vector m
with variables vars
such that the degree degree(m)
is in degs
and filter(m)
is true
.
Examples
Calling monomials
on $4x^2y + xy + 2x$ should return an iterator of $[x^2y, xy, x]$.
Calling monomials((x, y), [1, 3], m -> degree(m, y) != 1)
should return [x^3, x*y^2, y^3, x]
where x^2*y
and y
have been excluded by the filter.
MultivariatePolynomials.mindegree
— Functionmindegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractPolynomialLike}})
Returns the minimal total degree of the monomials of p
, i.e. minimum(degree, terms(p))
.
mindegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractPolynomialLike}}, v::AbstractVariable)
Returns the minimal degree of the monomials of p
in the variable v
, i.e. minimum(degree.(terms(p), v))
.
Examples
Calling mindegree
on on $4x^2y + xy + 2x$ should return 1, mindegree(4x^2y + xy + 2x, x)
should return 1 and mindegree(4x^2y + xy + 2x, y)
should return 0.
MultivariatePolynomials.maxdegree
— Functionmaxdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}})
Returns the maximal total degree of the monomials of p
, i.e. maximum(degree, terms(p))
.
maxdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}}, v::AbstractVariable)
Returns the maximal degree of the monomials of p
in the variable v
, i.e. maximum(degree.(terms(p), v))
.
Examples
Calling maxdegree
on $4x^2y + xy + 2x$ should return 3, maxdegree(4x^2y + xy + 2x, x)
should return 2 and maxdegree(4x^2y + xy + 2x, y)
should return 1.
MultivariatePolynomials.extdegree
— Functionextdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractPolynomialLike}})
Returns the extremal total degrees of the monomials of p
, i.e. (mindegree(p), maxdegree(p))
.
extdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractPolynomialLike}}, v::AbstractVariable)
Returns the extremal degrees of the monomials of p
in the variable v
, i.e. (mindegree(p, v), maxdegree(p, v))
.
Examples
Calling extdegree
on $4x^2y + xy + 2x$ should return (1, 3)
, extdegree(4x^2y + xy + 2x, x)
should return (1, 2)
and maxdegree(4x^2y + xy + 2x, y)
should return (0, 1)
.
MultivariatePolynomials.leading_term
— Functionleading_term(p::AbstractPolynomialLike)
Returns the leading term, i.e. last(terms(p))
.
Examples
Calling leading_term
on $4x^2y + xy + 2x$ should return $4x^2y$.
MultivariatePolynomials.leading_coefficient
— Functionleading_coefficient(p::AbstractPolynomialLike)
Returns the coefficient of the leading term of p
, i.e. coefficient(leading_term(p))
.
Examples
Calling leading_coefficient
on $4x^2y + xy + 2x$ should return $4$ and calling it on $0$ should return $0$.
MultivariatePolynomials.leading_monomial
— Functionleading_monomial(p::AbstractPolynomialLike)
Returns the monomial of the leading term of p
, i.e. monomial(leading_term(p))
or last(monomials(p))
.
Examples
Calling leading_monomial
on $4x^2y + xy + 2x$ should return $x^2y$.
MultivariatePolynomials.deg_num_leading_terms
— Functiondeg_num_leading_terms(p::AbstractPolynomialLike, var)
Return deg, num
where deg = maxdegree(p, var)
and num
is the number of terms t
such that degree(t, var) == deg
.
MultivariatePolynomials.remove_leading_term
— Functionremove_leading_term(p::AbstractPolynomialLike)
Returns a polynomial with the leading term removed in the polynomial p
.
Examples
Calling remove_leading_term
on $4x^2y + xy + 2x$ should return $xy + 2x$.
MultivariatePolynomials.remove_monomials
— FunctionReturns a polynomial with the terms having their monomial in the monomial vector mv
removed in the polynomial p
.
Examples
Calling remove_monomials(4x^2*y + x*y + 2x, [x*y])
should return $4x^2*y + 2x$.
MultivariatePolynomials.filter_terms
— Functionfunction filter_terms(f::Function, p::AbstractPolynomialLike)
Filter the polynomial p
by only keep the terms t
such that f(p)
is true
.
See also OfDegree
.
Examples
julia> p = 1 - 2x + x * y - 3y^2 + x^2 * y
1 - 2x - 3y² + xy + x²y
julia> filter_terms(OfDegree(2), p)
-3y² + xy
julia> filter_terms(!OfDegree(2), p)
1 - 2x + x²y
julia> filter_terms(!OfDegree(0:2), p)
x²y
julia> filter_terms(iseven ∘ coefficient, p)
-2x
MultivariatePolynomials.OfDegree
— Typestruct OfDegree{D} <: Function
degree::D
end
A function d::OfDegree
is such that d(t)
returns degree(t) == d.degree
. Note that !d
creates the negation. See also filter_terms
.
MultivariatePolynomials.monic
— Functionmonic(p::AbstractPolynomialLike)
Returns p / leading_coefficient(p)
where the leading coefficient of the returned polynomials is made sure to be exactly one to avoid rounding error.
MultivariatePolynomials.map_coefficients
— Functionmap_coefficients(f::Function, p::AbstractPolynomialLike, nonzero = false)
Returns a polynomial with the same monomials as p
but each coefficient α
is replaced by f(α)
. The function may return zero in which case the term is dropped. If the function is known to never return zero for a nonzero input, nonzero
can be set to true
to get a small speedup.
See also map_coefficients!
and map_coefficients_to!
.
Examples
Calling map_coefficients(α -> mod(3α, 6), 2x*y + 3x + 1)
should return 3x + 3
.
MultivariatePolynomials.map_coefficients!
— Functionmap_coefficients!(f::Function, p::AbstractPolynomialLike, nonzero = false)
Mutate p
by replacing each coefficient α
by f(α)
. The function may return zero in which case the term is dropped. If the function is known to never return zero for a nonzero input, nonzero
can be set to true
to get a small speedup. The function returns p
, which is identically equal to the second argument.
See also map_coefficients
and map_coefficients_to!
.
Examples
Let p = 2x*y + 3x + 1
, after map_coefficients!(α -> mod(3α, 6), p)
, p
is equal to 3x + 3
.
MultivariatePolynomials.map_coefficients_to!
— Functionmap_coefficients_to!(output::AbstractPolynomialLike, f::Function, p::AbstractPolynomialLike, nonzero = false)
Mutate output
by replacing each coefficient α
of p
by f(α)
. The function may return zero in which case the term is dropped. If the function is known to never returns zero for a nonzero input, nonzero
can be set to true
to get a small speedup. The function returns output
, which is identically equal to the first argument.
See also map_coefficients!
and map_coefficients
.
Base.conj
— Methodconj(x::AbstractPolynomialLike)
Return the complex conjugate of x
by applying conjugation to all coefficients and variables.
Base.real
— Methodreal(x::AbstractPolynomialLike)
Return the real part of x
by applying real
to all coefficients and variables; for this purpose, every complex-valued variable is decomposed into its real- and imaginary parts.
See also imag
.
Base.imag
— Methodimag(x::AbstractPolynomialLike)
Return the imaginary part of x
by applying imag
to all coefficients and variables; for this purpose, every complex-valued variable is decomposed into its real- and imaginary parts.
See also real
.
Base.isreal
— Methodisreal(p::AbstractPolynomialLike)
Returns true
if and only if no single variable in p
was declared as a complex variable (in the sense that isreal
applied on them would be true
) and no coefficient is complex-valued.
MultivariatePolynomials.mindegree_complex
— Functionmindegree_complex(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}})
Return the minimal total complex degree of the monomials of p
, i.e., minimum(degree_complex, terms(p))
.
mindegree_complex(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}}, v::AbstractVariable)
Return the minimal complex degree of the monomials of p
in the variable v
, i.e., minimum(degree_complex.(terms(p), v))
.
MultivariatePolynomials.minhalfdegree
— Functionminhalfdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}})
Return the minmal half degree of the monomials of p
, i.e., minimum(halfdegree, terms(p))
MultivariatePolynomials.maxdegree_complex
— Functionmaxdegree_complex(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}})
Return the maximal total complex degree of the monomials of p
, i.e., maximum(degree_complex, terms(p))
.
maxdegree_complex(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}}, v::AbstractVariable)
Return the maximal complex degree of the monomials of p
in the variable v
, i.e., maximum(degree_complex.(terms(p), v))
.
MultivariatePolynomials.maxhalfdegree
— Functionmaxhalfdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}})
Return the maximal half degree of the monomials of p
, i.e., maximum(halfdegree, terms(p))
MultivariatePolynomials.extdegree_complex
— Functionextdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}})
Returns the extremal total complex degrees of the monomials of p
, i.e., (mindegree_complex(p), maxdegree_complex(p))
.
extdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}}, v::AbstractVariable)
Returns the extremal complex degrees of the monomials of p
in the variable v
, i.e., (mindegree_complex(p, v), maxdegree_complex(p, v))
.
MultivariatePolynomials.exthalfdegree
— Functionexthalfdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTermLike}})
Return the extremal half degree of the monomials of p
, i.e., (minhalfdegree(p), maxhalfdegree(p))
Rational Polynomial Function
A rational polynomial function can be constructed with the /
operator. Common operations such as +
, -
, *
, -
have been implemented between rational functions. The numerator and denominator polynomials can be retrieved by the numerator
and denominator
functions.
Monomial Vectors
MultivariatePolynomials.monomial_vector
— Functionmonomial_vector(X::AbstractVector{MT}) where {MT<:AbstractMonomialLike}
Returns the vector of monomials X
in increasing order and without any duplicates.
Examples
Calling monomial_vector
on $[xy, x, xy, x^2y, x]$ should return $[x^2y, xy, x]$.
monomial_vector(a, X::AbstractVector{MT}) where {MT<:AbstractMonomialLike}
Returns b, Y
where Y
is the vector of monomials of X
in increasing order and without any duplicates and b
is the vector of corresponding coefficients in a
, where coefficients of duplicate entries are summed together.
Examples
Calling monomial_vector
on $[2, 1, 4, 3, -1], [xy, x, xy, x^2y, x]$ should return $[3, 6, 0], [x^2y, xy, x]$.
MultivariatePolynomials.monomial_vector_type
— Functionmonomial_vector_type(X::AbstractVector{MT}) where {MT<:AbstractMonomialLike}
Returns the return type of monomial_vector
.
MultivariatePolynomials.empty_monomial_vector
— Functionempty_monomial_vector(p::AbstractPolynomialLike)
Returns an empty collection of the type of monomials(p)
.
MultivariatePolynomials.sort_monomial_vector
— Functionsort_monomial_vector(X::AbstractVector{MT}) where {MT<:AbstractMonomialLike}
Returns σ
, the orders in which one must take the monomials in X
to make them sorted and without any duplicate and the sorted vector of monomials, i.e. it returns (σ, X[σ])
.
Examples
Calling sort_monomial_vector
on $[xy, x, xy, x^2y, x]$ should return $([4, 1, 2], [x^2y, xy, x])$.
MultivariatePolynomials.merge_monomial_vectors
— Functionmerge_monomial_vectors{MT<:AbstractMonomialLike, MVT<:AbstractVector{MT}}(X::AbstractVector{MVT}}
Returns the vector of monomials in the entries of X
in increasing order and without any duplicates, i.e. monomial_vector(vcat(X...))
Examples
Calling merge_monomial_vectors
on $[[xy, x, xy], [x^2y, x]]$ should return $[x^2y, xy, x]$.
Base.conj
— Methodconj(x::AbstractVector{<:AbstractMonomial})
Return the complex conjugate of x
by applying conjugation to monomials.
Base.real
— Methodreal(x::AbstractVector{<:AbstractMonomial})
Return the real part of x
by applying real
to all monomials; for this purpose, every complex-valued variable is decomposed into its real- and imaginary parts. Note that the result will no longer be a monomial vector.
See also imag
.
Base.imag
— Methodimag(x::AbstractVector{<:AbstractMonomial})
Return the imaginary part of x
by applying imag
to all monomials; for this purpose, every complex-valued variable is decomposed into its real- and imaginary parts. Note that the result will no longer be a monomial vector.
See also real
.
Base.isreal
— Methodisreal(p::AbstractVector{<:AbstractMonomial})
Returns true
if and only if every single monomial in p
would is real-valued.