21 #include "../typetraits.h"
27 template<
typename Coefficient>
class UnivariatePolynomial;
29 template<
typename Coefficient>
class IntRepRealAlgebraicNumber;
31 template<
typename Coefficient>
34 template<
typename Coefficient>
60 template<
typename Coefficient>
135 template<typename C = Coefficient, DisableIf<std::is_same<C, typename UnderlyingNumberType<C>::type>> =
dummy>
166 [[deprecated(
"use carl::is_zero(p) instead.")]]
176 [[deprecated(
"use carl::is_one(p) instead.")]]
222 [[deprecated(
"use carl::is_constant(p) instead.")]]
259 return tcoeff().constant_part();
272 if (!c.is_number())
return false;
295 [[deprecated(
"use carl::total_degree(p) instead.")]]
302 for (std::size_t deg = 0; deg <
mCoefficients.size(); deg++) {
305 if (tdeg > max) max = tdeg;
317 this->mCoefficients.resize(this->mCoefficients.size()-1);
354 if (c.has(v))
return true;
367 template<
typename C = Coefficient, EnableIf<is_subset_of_rationals_type<C>> = dummy>
369 template<
typename C = Coefficient, DisableIf<is_subset_of_rationals_type<C>> = dummy>
378 template<
typename C = Coefficient, EnableIf<is_subset_of_rationals_type<C>> = dummy>
381 template<
typename C = Coefficient, DisableIf<is_subset_of_rationals_type<C>> = dummy>
385 template<
typename C = Coefficient, EnableIf<is_subset_of_rationals_type<C>> = dummy>
388 template<
typename C = Coefficient, DisableIf<is_subset_of_rationals_type<C>> = dummy>
421 for (std::size_t deg = 0; deg < res.
coefficients().size(); deg++) {
465 [[deprecated(
"Use carl::pow() instead.")]]
468 [[deprecated(
"Use carl::evaluate() instead.")]]
469 Coefficient
evaluate(
const Coefficient& value)
const;
476 [[deprecated(
"Use carl::sgn(carl::evaluate()) instead.")]]
481 template<
typename SubstitutionType,
typename C = Coefficient, EnableIf<is_instantiation_of<MultivariatePolynomial, C>> = dummy>
486 template<
typename SubstitutionType,
typename C = Coefficient, DisableIf<is_instantiation_of<MultivariatePolynomial, C>> = dummy>
493 template<
typename T = Coefficient, EnableIf<has_normalize<T>> = dummy>
496 static_assert(std::is_same<T,Coefficient>::value,
"No template parameters should be given");
503 template<
typename T = Coefficient, DisableIf<has_normalize<T>> = dummy>
506 static_assert(std::is_same<T,Coefficient>::value,
"No template parameters should be given");
514 template<
typename C=Coefficient, EnableIf<is_instantiation_of<GFNumber, C>> = dummy>
516 template<
typename C=Coefficient, DisableIf<is_instantiation_of<GFNumber, C>> = dummy>
524 template<
typename C=Coefficient, DisableIf<is_number_type<C>> = dummy>
527 template<
typename NewCoeff>
529 template<
typename NewCoeff>
543 return this->mCoefficients[i];
545 return this->mCoefficients[i].numeric_content();
561 return this->
lcoeff().numeric_unit();
577 template<
typename N=NumberType, EnableIf<is_subset_of_rationals_type<N>> = dummy>
585 template<
typename C=Coefficient, EnableIf<is_number_type<C>> = dummy>
587 template<
typename C=Coefficient, DisableIf<is_number_type<C>> = dummy>
701 template<
typename C=Coefficient, EnableIf<is_number_type<C>> = dummy>
703 template<
typename C=Coefficient, DisableIf<is_number_type<C>> = dummy>
706 template<
typename I = Coefficient, DisableIf<std::is_same<Coefficient, I>>...>
733 template<
typename C,
typename O,
typename P>
735 template<
typename C,
typename O,
typename P>
746 template<
typename C = Coefficient, EnableIf<is_field_type<C>> = dummy>
748 template<
typename C = Coefficient, DisableIf<is_field_type<C>> = dummy>
770 template <
typename C>
780 template<
typename C=Coefficient, EnableIf<is_number_type<C>> = dummy>
791 template<
typename C=Coefficient, DisableIf<is_number_type<C>> = dummy>
807 template<
typename Coefficient>
816 template<
typename Coefficient>
822 template<
typename Coeff>
847 template<
typename Coefficient>
848 struct hash<
carl::UnivariatePolynomial<Coefficient>> {
862 template<
typename Coefficient>
863 struct less<
carl::UnivariatePolynomial<Coefficient>> {
873 return lhs.
less(rhs, order);
882 if (lhs ==
nullptr)
return rhs !=
nullptr;
883 if (rhs ==
nullptr)
return true;
884 return lhs->
less(*rhs, order);
893 return (*
this)(lhs.get(), rhs.get());
A small wrapper that configures logging for carl.
#define CARL_LOG_WARN(channel, msg)
#define CARL_LOG_NOTIMPLEMENTED()
Gives the underlying number type of a complex object.
carl is the main namespace for the library.
bool is_constant(const ContextPolynomial< Coeff, Ordering, Policies > &p)
Sign
This class represents the sign of a number .
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::map< UnivariatePolynomial< Coefficient >, uint > FactorMap
PolynomialComparisonOrder
typename std::enable_if<!std::is_same< C, typename IntegralType< C >::type >::value, typename IntegralType< C >::type >::type IntegralTypeIfDifferent
Sign sgn(const Number &n)
Obtain the sign of the given number.
std::size_t hash_all(Args &&... args)
Hashes an arbitrary number of values.
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
std::shared_ptr< UnivariatePolynomial< Coefficient > > UnivariatePolynomialPtr
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
UnivariatePolynomial< Coefficient > reverse(UnivariatePolynomial< Coefficient > &&p)
Reverses the order of the coefficients of this polynomial.
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.
UnivariatePolynomial< NewCoeff > convert(const std::function< NewCoeff(const Coefficient &)> &f) const
UnivariatePolynomial & operator+=(const Coefficient &rhs)
Add something to this polynomial and return the changed polynomial.
UnivariatePolynomial(Variable mainVar, const std::map< uint, Coefficient > &coefficients)
Construct polynomial with the given coefficients.
UnivariatePolynomial(Variable mainVar, std::vector< Coefficient > &&coefficients)
Construct polynomial with the given coefficients, moving the coefficients.
UnivariatePolynomial< Coefficient > coprime_coefficients_sign_preserving() const
friend UnivariatePolynomial< C > operator*(const UnivariatePolynomial< C > &lhs, const IntegralTypeIfDifferent< C > &rhs)
Perform a multiplication involving a polynomial.
bool is_constant() const
Checks whether the polynomial is constant with respect to the main variable.
UnivariatePolynomial & mod(const Coefficient &modulus)
Replaces every coefficient c by c mod modulus.
bool is_number() const
Checks whether the polynomial is only a number.
friend UnivariatePolynomial< C > operator*(const IntegralTypeIfDifferent< C > &lhs, const UnivariatePolynomial< C > &rhs)
Perform a multiplication involving a polynomial.
UnivariatePolynomial(Variable mainVar, std::initializer_list< Coefficient > coefficients)
Construct polynomial with the given coefficients.
friend UnivariatePolynomial< C > operator-(const C &lhs, const UnivariatePolynomial< C > &rhs)
Performs a subtraction involving a polynomial.
bool less(const UnivariatePolynomial< Coefficient > &rhs, const PolynomialComparisonOrder &order=PolynomialComparisonOrder::Default) const
UnivariatePolynomial one() const
Creates a polynomial of value one with the same main variable.
UnivariatePolynomial< typename IntegralType< Coefficient >::type > coprime_coefficients() const
Constructs a new polynomial that is scaled such that the coefficients are coprime.
friend bool operator!=(const UnivariatePolynomial< C > &lhs, const UnivariatePolynomial< C > &rhs)
Checks if the two arguments are not equal.
bool is_normal() const
Checks whether the polynomial is unit normal.
bool is_linear_in_main_var() const
UnivariatePolynomial & operator=(UnivariatePolynomial &&p) noexcept
Move assignment operator.
UnivariatePolynomial(Variable mainVar)
Construct a zero polynomial with the given main variable.
Coefficient coprime_factor() const
Calculates a factor that would make the coefficients of this polynomial coprime integers.
const std::vector< Coefficient > & coefficients() const &
Retrieves the coefficients defining this polynomial.
Variable mMainVar
The main variable.
Variable main_var() const
Retrieves the main variable of this polynomial.
friend bool operator!=(const UnivariatePolynomialPtr< C > &lhs, const UnivariatePolynomialPtr< C > &rhs)
Checks if the two arguments are not equal.
UnivariatePolynomial(Variable mainVar, const std::vector< Coefficient > &coefficients)
Construct polynomial with the given coefficients.
const Coefficient & lcoeff() const
Returns the leading coefficient.
~UnivariatePolynomial()=default
Destructor.
const Coefficient & tcoeff() const
Returns the trailing coefficient.
friend bool operator==(const UnivariatePolynomial< C > &lhs, const UnivariatePolynomial< C > &rhs)
Checks if the two arguments are equal.
friend UnivariatePolynomial< C > operator*(const UnivariatePolynomial< C > &lhs, Variable rhs)
Perform a multiplication involving a polynomial.
friend UnivariatePolynomial< C > operator*(Variable lhs, const UnivariatePolynomial< C > &rhs)
Perform a multiplication involving a polynomial.
UnivariatePolynomial(Variable mainVar, const Coefficient &coeff, std::size_t degree=0)
Construct .
friend UnivariatePolynomial< C > operator*(const UnivariatePolynomial< C > &lhs, const C &rhs)
Perform a multiplication involving a polynomial.
NumberType numeric_unit() const
Returns the numeric unit part of the polynomial.
friend UnivariatePolynomial< C > operator+(const C &lhs, const UnivariatePolynomial< C > &rhs)
Performs an addition involving a polynomial.
std::vector< Coefficient > && coefficients() &&
Returns the coefficients as rvalue. The polynomial may be in an undefined state afterwards!
Coefficient synthetic_division(const Coefficient &zeroOfDivisor)
bool is_consistent() const
Asserts that this polynomial over numeric coefficients complies with the requirements and assumptions...
bool has(Variable v) const
Checks if the given variable occurs in the polynomial.
UnivariatePolynomial & operator*=(const UnivariatePolynomial &rhs)
Multiply this polynomial with something and return the changed polynomial.
bool is_zero() const
Checks if the polynomial is equal to zero.
UnivariatePolynomial & operator*=(const Coefficient &rhs)
Multiply this polynomial with something and return the changed polynomial.
UnivariatePolynomial & operator-=(const UnivariatePolynomial &rhs)
Subtract something from this polynomial and return the changed polynomial.
friend UnivariatePolynomial< C > operator*(const C &lhs, const UnivariatePolynomial< C > &rhs)
Perform a multiplication involving a polynomial.
friend UnivariatePolynomial< C > operator-(const UnivariatePolynomial< C > &lhs, const C &rhs)
Performs a subtraction involving a polynomial.
UnivariatePolynomial & operator*=(const typename IntegralType< Coefficient >::type &rhs)
Multiply this polynomial with something and return the changed polynomial.
UnivariatePolynomial & operator-=(const Coefficient &rhs)
Subtract something from this polynomial and return the changed polynomial.
bool is_one() const
Checks if the polynomial is equal to one.
UnivariatePolynomial< NewCoeff > convert() const
UnivariatePolynomial & operator+=(const UnivariatePolynomial &rhs)
Add something to this polynomial and return the changed polynomial.
carl::Sign sgn(const Coefficient &value) const
Calculates the sign of the polynomial at some point.
bool divides(const UnivariatePolynomial &divisor) const
Checks if this polynomial is divisible by the given divisor, that is if the remainder is zero.
friend UnivariatePolynomial< C > operator*(const UnivariatePolynomial< C > &lhs, const UnivariatePolynomial< C > &rhs)
Perform a multiplication involving a polynomial.
friend class UnivariatePolynomial
Declare all instantiations of univariate polynomials as friends.
friend UnivariatePolynomial< C > operator+(const UnivariatePolynomial< C > &lhs, const C &rhs)
Performs an addition involving a polynomial.
UnivariatePolynomial()=delete
Default constructor shall not exist.
IntNumberType main_denom() const
Compute the main denominator of all numeric coefficients of this polynomial.
UnderlyingNumberType< Coefficient >::type numeric_content() const
Obtains the numeric content part of this polynomial.
UnivariatePolynomial(Variable mainVar, std::initializer_list< typename UnderlyingNumberType< C >::type > coefficients)
Construct polynomial with the given coefficients from the underlying number type of the coefficient t...
UnivariatePolynomial & normalizeCoefficients()
uint total_degree() const
Returns the total degree of the polynomial, that is the maximum degree of any monomial.
Coefficient unit_part() const
The unit part of a polynomial over a field is its leading coefficient for nonzero polynomials,...
friend std::ostream & operator<<(std::ostream &os, const UnivariatePolynomial< C > &rhs)
Streaming operator for univariate polynomials.
friend UnivariatePolynomial< MultivariatePolynomial< C, O, P > > operator*(const C &lhs, const UnivariatePolynomial< MultivariatePolynomial< C, O, P >> &rhs)
Perform a multiplication involving a polynomial.
UnivariatePolynomial & operator=(const UnivariatePolynomial &p)
Copy assignment operator.
UnivariatePolynomial operator-() const
UnivariatePolynomial< Coefficient > evaluateCoefficient(const std::map< Variable, SubstitutionType > &) const
UnderlyingNumberType< Coefficient >::type coprime_factor() const
void truncate()
Removes the leading term from the polynomial.
friend bool operator==(const C &lhs, const UnivariatePolynomial< C > &rhs)
Checks if the two arguments are equal.
UnivariatePolynomial(UnivariatePolynomial &&p) noexcept
Move constructor.
friend bool operator==(const UnivariatePolynomial< C > &lhs, const C &rhs)
Checks if the two arguments are equal.
UnivariatePolynomial & operator*=(Variable rhs)
Multiply this polynomial with something and return the changed polynomial.
void strip_leading_zeroes()
std::vector< Coefficient > mCoefficients
The coefficients.
typename UnderlyingNumberType< Coefficient >::type NumberType
The number type that is ultimately used for the coefficients.
UnivariatePolynomial mod(const Coefficient &modulus) const
Constructs a new polynomial where every coefficient c is replaced by c mod modulus.
std::vector< Coefficient > & coefficients() &
Returns the coefficients as non-const reference.
friend bool operator==(const UnivariatePolynomialPtr< C > &lhs, const UnivariatePolynomialPtr< C > &rhs)
Checks if the two arguments are equal.
UnivariatePolynomial(const UnivariatePolynomial &p)
Copy constructor.
NumberType numeric_content(std::size_t i) const
Returns the numeric content part of the i'th coefficient.
UnivariatePolynomial reverse_coefficients() const
Reverse coefficients safely.
uint degree() const
Get the maximal exponent of the main variable.
NumberType constant_part() const
Returns the constant part of this polynomial.
Coefficient evaluate(const Coefficient &value) const
UnivariatePolynomial pow(std::size_t exp) const
Returns this polynomial to the given power.
friend UnivariatePolynomial< MultivariatePolynomial< C, O, P > > operator*(const UnivariatePolynomial< MultivariatePolynomial< C, O, P >> &lhs, const C &rhs)
Perform a multiplication involving a polynomial.
friend bool operator<(const UnivariatePolynomial< C > &lhs, const UnivariatePolynomial< C > &rhs)
bool zero_is_root() const
Checks if zero is a real root of this polynomial.
UnivariatePolynomial negate_variable() const
Constructs a new polynomial q such that where p is this polynomial.
UnivariatePolynomial & operator/=(const Coefficient &rhs)
Divide this polynomial by something and return the changed polynomial.
UnivariatePolynomial< NumberType > toNumberCoefficients() const
Asserts that is_univariate() is true.
UnivariatePolynomial< typename IntegralType< Coefficient >::type > to_integer_domain() const
Works only from rationals, if the numbers are already integers.
friend UnivariatePolynomial< C > operator/(const UnivariatePolynomial< C > &lhs, const C &rhs)
Perform a division involving a polynomial.
UnivariatePolynomial< Coefficient > coprime_coefficients() const
friend UnivariatePolynomial< C > operator+(const UnivariatePolynomial< C > &lhs, const UnivariatePolynomial< C > &rhs)
Performs an addition involving a polynomial.
bool is_univariate() const
Checks if the polynomial is univariate, that means if only one variable occurs.
UnivariatePolynomial normalized() const
The normal part of a polynomial is the polynomial divided by the unit part.
UnivariatePolynomial< typename IntegralType< Coefficient >::type > coprime_coefficients_sign_preserving() const
friend UnivariatePolynomial< C > operator-(const UnivariatePolynomial< C > &lhs, const UnivariatePolynomial< C > &rhs)
Performs a subtraction involving a polynomial.
UnivariatePolynomial< GFNumber< typename IntegralType< Coefficient >::type > > toFiniteDomain(const GaloisField< typename IntegralType< Coefficient >::type > *galoisField) const
typename IntegralType< NumberType >::type IntNumberType
The integral type that belongs to the number type.
The general-purpose multivariate polynomial class.
States if a type is a number type.
std::size_t operator()(const carl::UnivariatePolynomial< Coefficient > &p) const
Calculates the hash of univariate polynomial.
carl::PolynomialComparisonOrder order
bool operator()(const carl::UnivariatePolynomialPtr< Coefficient > &lhs, const carl::UnivariatePolynomialPtr< Coefficient > &rhs) const
Compares two shared pointers to univariate polynomials.
bool operator()(const carl::UnivariatePolynomial< Coefficient > &lhs, const carl::UnivariatePolynomial< Coefficient > &rhs) const
Compares two univariate polynomials.
bool operator()(const carl::UnivariatePolynomial< Coefficient > *lhs, const carl::UnivariatePolynomial< Coefficient > *rhs) const
Compares two pointers to univariate polynomials.
less(carl::PolynomialComparisonOrder _order=carl::PolynomialComparisonOrder::Default) noexcept