carl  24.04
Computer ARithmetic Library
Complexity.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../MultivariatePolynomial.h"
4 #include "../UnivariatePolynomial.h"
5 
6 namespace carl {
7 
8 /**
9  * @return An approximation of the complexity of this monomial.
10  */
11 inline std::size_t complexity(const Monomial& m) {
12  return m.tdeg();
13 }
14 
15 /**
16  * @return An approximation of the complexity of this term.
17  */
18 template<typename Coeff>
19 std::size_t complexity(const Term<Coeff>& t) {
20  if (!t.monomial()) return 1;
21  return complexity(*t.monomial()) + 1;
22 }
23 
24 /**
25  * @return An approximation of the complexity of this polynomial.
26  */
27 template<typename Coeff, typename Ordering, typename Policies>
29  return std::accumulate(p.begin(), p.end(), static_cast<std::size_t>(0),
30  [](std::size_t cur, const auto& t){ return cur + complexity(t); }
31  );
32 }
33 
34 /**
35 * @return An approximation of the complexity of this polynomial.
36 */
37 template<typename Coeff>
38 std::size_t complexity(const UnivariatePolynomial<Coeff>& p) {
39  std::size_t result = 0;
40  for (std::size_t deg = 0; deg <= p.degree(); ++deg) {
41  if (carl::is_zero(p.coefficients()[deg])) continue;
42  result += complexity(p.coefficients()[deg]) + deg;
43  }
44  return result;
45 }
46 
47 }
carl is the main namespace for the library.
std::size_t complexity(const BasicConstraint< Poly > &c)
Definition: Complexity.h:11
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
This class represents a univariate polynomial with coefficients of an arbitrary type.
const std::vector< Coefficient > & coefficients() const &
Retrieves the coefficients defining this polynomial.
uint degree() const
Get the maximal exponent of the main variable.
The general-purpose multivariate polynomial class.
The general-purpose monomials.
Definition: Monomial.h:59
exponent tdeg() const
Gives the total degree, i.e.
Definition: Monomial.h:185
Monomial::Arg & monomial()
Get the monomial.
Definition: Term.h:91