13 #include <type_traits>
20 #include "../typetraits.h"
26 template<
typename Coeff>
27 class UnivariatePolynomial;
41 template<
typename Coeff,
typename Ordering = GrLexOrdering,
typename Policies = StdMultivariatePolynomialPolicies<>>
44 template<
typename Polynomial,
typename Order>
70 template<
typename C,
typename T>
71 using EnableIfNotSame =
typename std::enable_if<!std::is_same<C,T>::value,T>::type;
101 template<
typename C = Coeff>
103 template<
typename C = Coeff>
111 template<
class OtherPolicies, DisableIf<std::is_same<Policies,OtherPolicies>> = dummy>
139 [](
const auto& lhs,
const auto& rhs){
return Ordering::less(lhs, rhs); }
207 for (
const auto& t:
mTerms) {
208 if (t.monomial() ==
nullptr)
continue;
209 std::size_t c = t.monomial()->exponent_of_variable(var);
210 if (c > max) max = c;
223 for (
const auto& t:
mTerms) {
224 if (t.monomial() ==
nullptr) {
226 }
else if (t.monomial()->exponent_of_variable(var) ==
exp) {
239 [[deprecated(
"use carl::is_zero(p) instead.")]]
247 [[deprecated(
"use carl::is_one(p) instead.")]]
301 [](
const auto& t){
return t.integer_valued(); }
389 [](
const auto& t){
return t.is_square(); }
399 [v](
const auto& t){
return t.has(v); }
435 template<
typename C = Coeff, EnableIf<is_subset_of_rationals_type<C>> = dummy>
461 assert(index <
mTerms.size());
467 template<
typename C=Coeff, EnableIf<is_number_type<C>> = dummy>
469 template<
typename C=Coeff, DisableIf<is_number_type<C>> = dummy>
472 template<
typename C=Coeff, EnableIf<is_number_type<C>> = dummy>
543 template<
typename C,
typename O,
typename P>
546 template<
typename C,
typename O,
typename P>
553 return Ordering::less(p1.
lterm(), p2.
lterm());
565 template<
bool findConstantTerm=true,
bool findLeadingTerm=true>
588 template<
typename C,
typename O,
typename P>
592 template<
typename C,
typename O,
typename P>
611 template<
typename C,
typename O,
typename P, EnableIf<carl::is_number_type<C>> = dummy>
616 template<
typename C,
typename O,
typename P>
617 std::pair<MultivariatePolynomial<C,O,P>,
MultivariatePolynomial<C,O,P>>
lazyDiv(
const MultivariatePolynomial<C,O,P>& _polyA,
const MultivariatePolynomial<C,O,P>& _polyB )
620 return std::make_pair( _polyA/g, _polyB/g );
629 template<
typename C,
typename O,
typename P>
631 if (
is_zero(rhs))
return os <<
"0";
636 template<
typename Coeff,
typename Ordering,
typename Policies>
638 for (
const auto& t : p) {
643 template<
typename T,
typename O,
typename P>
649 template<
typename C,
typename O,
typename P>
662 template<
typename C,
typename O,
typename P>
663 struct hash<
carl::MultivariatePolynomial<C,O,P>> {
673 if (mpoly.
nr_terms() == 0)
return 0;
675 std::size_t seed = 0;
677 for (std::size_t i = 1; i < mpoly.
nr_terms() - 1; ++i) {
684 return std::accumulate(mpoly.
begin(), mpoly.
end(),
static_cast<std::size_t
>(0),
685 [](std::size_t seed,
const auto& t){ carl::hash_add(seed, t); return seed; }
#define CARL_LOG_ASSERT(channel, condition, msg)
Gives the underlying number type of a complex object.
carl is the main namespace for the library.
Interval< Number > operator/(const Interval< Number > &lhs, const Number &rhs)
Operator for the division of an interval and a number.
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
cln::cl_I gcd(const cln::cl_I &a, const cln::cl_I &b)
Calculate the greatest common divisor of two integers.
Interval< Number > exp(const Interval< Number > &i)
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
std::pair< MultivariatePolynomial< C, O, P >, MultivariatePolynomial< C, O, P > > lazyDiv(const MultivariatePolynomial< C, O, P > &_polyA, const MultivariatePolynomial< C, O, P > &_polyB)
typename UnderlyingNumberType< P >::type Coeff
auto stream_joined(const std::string &glue, const T &v)
Allows to easily output some container with all elements separated by some string.
std::size_t hash_all(Args &&... args)
Hashes an arbitrary number of values.
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
void hash_add(std::size_t &seed, const T &value)
Add hash of the given value to the hash seed.
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
A Variable represents an algebraic variable that can be used throughout carl.
This template is designed to provide types that are related to other types.
T type
A type associated with the type.
This class represents a univariate polynomial with coefficients of an arbitrary type.
The general-purpose multivariate polynomial class.
MultivariatePolynomial(const std::shared_ptr< const Monomial > &m)
MultivariatePolynomial & operator/=(const MultivariatePolynomial &rhs)
Divide this polynomial by something and return the changed polynomial.
IntNumberType main_denom() const
MultivariatePolynomial & operator=(MultivariatePolynomial &&p) noexcept
MultivariatePolynomial & operator+=(const std::shared_ptr< const TermType > &rhs)
Add something to this polynomial and return the changed polynomial.
MultivariatePolynomial & operator*=(const MultivariatePolynomial &rhs)
Multiply this polynomial with something and return the changed polynomial.
typename UnivariatePolynomial< NumberType >::RootType RootType
UnderlyingNumberType< C >::type numeric_content() const
void makeOrdered() const
Ensure that the terms are ordered.
MultivariatePolynomial(const TermsType &terms, bool duplicates=true, bool ordered=false)
const CoeffType & coefficient() const
friend MultivariatePolynomial< C, O, P > operator/(const MultivariatePolynomial< C, O, P > &lhs, const MultivariatePolynomial< C, O, P > &rhs)
Perform a division involving a polynomial.
const TermsType & terms() const
bool is_consistent() const
Asserts that this polynomial complies with the requirements and assumptions for MultivariatePolynomia...
MultivariatePolynomial(const UnivariatePolynomial< Coeff > &p)
MultivariatePolynomial(const MultivariatePolynomial< Coeff, Ordering, OtherPolicies > &p)
const Term< Coeff > & trailingTerm() const
Give the last term according to Ordering.
void makeMinimallyOrdered() const
Make sure that the terms are at least minimally ordered.
bool divides(const MultivariatePolynomial &b) const
typename std::enable_if<!std::is_same< C, T >::value, T >::type EnableIfNotSame
auto erase_term(typename TermsType::iterator pos)
Coeff numeric_content() const
bool is_constant() const
Check if the polynomial is constant.
MultivariatePolynomial coprime_coefficients() const
void CACHE
The type of the cache. Multivariate polynomials do not need a cache, we set it to something.
MultivariatePolynomial(const std::pair< ConstructorOperation, std::vector< MultivariatePolynomial >> &p)
MultivariatePolynomial & strip_lterm()
Drops the leading term.
std::size_t degree(Variable::Arg var) const
Calculates the degree of this polynomial with respect to the given variable.
MultivariatePolynomial(const std::initializer_list< Term< Coeff >> &terms)
MultivariatePolynomial(MultivariatePolynomial< Coeff, Ordering, Policies > &&p)
MultivariatePolynomial & operator+=(const Coeff &rhs)
Add something to this polynomial and return the changed polynomial.
MultivariatePolynomial tail(bool makeFullyOrdered=false) const
For the polynomial p, the function calculates a polynomial p - lt(p).
MultivariatePolynomial & operator-=(Variable::Arg rhs)
Subtract something from this polynomial and return the changed polynomial.
bool is_zero() const
Check if the polynomial is zero.
MultivariatePolynomial lcoeff(Variable::Arg var) const
Returns the leading coefficient with respect to the given variable.
const Term< Coeff > & lterm() const
The leading term.
~MultivariatePolynomial() noexcept=default
MultivariatePolynomial(ConstructorOperation op, const std::vector< MultivariatePolynomial > &operands)
const Coeff & constant_part() const
Retrieve the constant term of this polynomial or zero, if there is no constant term.
MultivariatePolynomial(const Coeff &c)
bool is_univariate() const
Checks whether only one variable occurs.
typename UnderlyingNumberType< Coeff >::type NumberType
Number type within the coefficients.
Coeff coprime_factor_without_constant() const
void subtractProduct(const Term< Coeff > &factor, const MultivariatePolynomial &p)
Subtract a term times a polynomial from this polynomial.
bool is_number() const
Check if the polynomial is a number, i.e., a constant.
MultivariatePolynomial< typename IntegralType< Coeff >::type, Ordering, Policies > to_integer_domain() const
bool is_reducible_identity() const
void reset_ordered() const
typename IntegralType< NumberType >::type IntNumberType
Integer type associated with the number type.
MultivariatePolynomial & operator+=(const MultivariatePolynomial &rhs)
Add something to this polynomial and return the changed polynomial.
bool sqrt(MultivariatePolynomial &res) const
Calculates the square of this multivariate polynomial if it is a square.
MultivariatePolynomial & operator+=(const Monomial::Arg &rhs)
Add something to this polynomial and return the changed polynomial.
const Coeff & lcoeff() const
Returns the coefficient of the leading term.
TermsType mTerms
A vector of all terms.
MultivariatePolynomial & operator*=(Variable::Arg rhs)
Multiply this polynomial with something and return the changed polynomial.
bool has_constant_term() const
Check if the polynomial has a constant term that is not zero.
const Monomial::Arg & lmon() const
The leading monomial.
MultivariatePolynomial normalize() const
For a polynomial p, returns p/lc(p)
Policies Policy
Policies for this monomial.
bool is_tsos() const
Checks whether the polynomial is a trivial sum of squares.
MultivariatePolynomial & operator=(const MultivariatePolynomial &p)
const Term< Coeff > & operator[](std::size_t index) const
MultivariatePolynomial & operator/=(const Coeff &rhs)
Divide this polynomial by something and return the changed polynomial.
MultivariatePolynomial(Variable::Arg v)
MultivariatePolynomial & operator*=(const Term< Coeff > &rhs)
Multiply this polynomial with something and return the changed polynomial.
MultivariatePolynomial & operator/=(const Term< Coeff > &rhs)
Divide this polynomial by something and return the changed polynomial.
bool mOrdered
Flag that indicates if the terms are ordered.
std::vector< Term< Coeff > > TermsType
Type our terms vector.f.
MultivariatePolynomial mod(const typename IntegralType< Coeff >::type &modulo) const
MultivariatePolynomial(const MultivariatePolynomial< Coeff, Ordering, Policies > &p)
MultivariatePolynomial & operator*=(const Monomial::Arg &rhs)
Multiply this polynomial with something and return the changed polynomial.
MultivariatePolynomial & operator/=(Variable::Arg rhs)
Divide this polynomial by something and return the changed polynomial.
Coeff coprime_factor() const
MultivariatePolynomial & operator-=(const Coeff &rhs)
Subtract something from this polynomial and return the changed polynomial.
Ordering OrderedBy
The ordering of the terms.
MultivariatePolynomial coprime_coefficients_sign_preserving() const
friend std::ostream & operator<<(std::ostream &os, ConstructorOperation op)
bool integer_valued() const
MultivariatePolynomial(const std::initializer_list< Variable > &terms)
bool has_single_variable() const
bool is_linear() const
Check if the polynomial is linear.
static bool compareByLeadingTerm(const MultivariatePolynomial &p1, const MultivariatePolynomial &p2)
MultivariatePolynomial operator-() const
MultivariatePolynomial(const UnivariatePolynomial< MultivariatePolynomial< Coeff, Ordering, Policy >> &pol)
MultivariatePolynomial & operator-=(const Term< Coeff > &rhs)
Subtract something from this polynomial and return the changed polynomial.
Variable single_variable() const
For terms with exactly one variable, get this variable.
std::size_t nr_terms() const
Calculate the number of terms.
MultivariatePolynomial & operator+=(Variable rhs)
Add something to this polynomial and return the changed polynomial.
friend MultivariatePolynomial< C, O, P > operator/(const MultivariatePolynomial< C, O, P > &lhs, unsigned long rhs)
Perform a division involving a polynomial.
static bool compareByNrTerms(const MultivariatePolynomial &p1, const MultivariatePolynomial &p2)
bool isOrdered() const
Check if the terms are ordered.
MultivariatePolynomial coeff(Variable::Arg var, std::size_t exp) const
Calculates the coefficient of var^exp.
MultivariatePolynomial & operator+=(const TermType &rhs)
Add something to this polynomial and return the changed polynomial.
MultivariatePolynomial(EnableIfNotSame< C, sint > c)
void addTerm(const Term< Coeff > &term)
Adds a single term without using a TermAdditionManager or changing the ordering status.
MultivariatePolynomial(int c)
bool has(Variable v) const
MultivariatePolynomial & operator-=(const Monomial::Arg &rhs)
Subtract something from this polynomial and return the changed polynomial.
static TermAdditionManager< MultivariatePolynomial, Ordering > mTermAdditionManager
Term< Coeff > & trailingTerm()
MultivariatePolynomial & operator*=(const Coeff &rhs)
Multiply this polynomial with something and return the changed polynomial.
MultivariatePolynomial(EnableIfNotSame< C, uint > c)
Term< Coeff > TermType
Type of the terms.
MultivariatePolynomial(TermsType &&terms, bool duplicates=true, bool ordered=false)
void makeMinimallyOrdered(typename TermsType::iterator <erm, typename TermsType::iterator &cterm) const
Make sure that the terms are at least minimally ordered.
const PolyType & polynomial() const
std::size_t total_degree() const
Calculates the max.
MultivariatePolynomial(const Term< Coeff > &t)
Coeff CoeffType
Type of the coefficients.
MultivariatePolynomial & operator/=(const Monomial::Arg &rhs)
Divide this polynomial by something and return the changed polynomial.
MultivariatePolynomial & operator-=(const MultivariatePolynomial &rhs)
Subtract something from this polynomial and return the changed polynomial.
The general-purpose monomials.
std::shared_ptr< const Monomial > Arg
std::size_t operator()(const carl::MultivariatePolynomial< C, O, P > &mpoly) const
Calculates the hash of a MultivariatePolynomial.
Coefficient & coeff()
Get the coefficient.
bool is_single_variable() const
Variable single_variable() const
For terms with exactly one variable, get this variable.
bool is_constant() const
Checks whether the monomial is a constant.
Monomial::Arg & monomial()
Get the monomial.