carl  24.04
Computer ARithmetic Library
evaluation.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "FactorizedPolynomial.h"
5 
6 namespace carl {
7 
8 /**
9  * Like substitute, but expects substitutions for all variables.
10  * @return For a polynomial p, the function value p(x_1,...,x_n).
11  */
12 template<typename Coeff, typename Subst>
13 Subst evaluate(const FactorizedPolynomial<Coeff>& p, const std::map<Variable, Subst>& substitutions) {
14  if (!existsFactorization(p)) {
15  return p.coefficient();
16  }
17  if (p.factorizedTrivially()) {
18  return Subst(p.coefficient()) * carl::evaluate(p.polynomial(), substitutions);
19  } else {
20  Subst result = p.coefficient();
21  for (const auto& factor : p.factorization()) {
22  Subst subResult = carl::evaluate(factor.first, substitutions);
23  if (carl::is_zero(subResult)) {
25  }
26  result *= carl::pow(subResult, factor.second);
27  }
28  assert(result == carl::evaluate(computePolynomial(p), substitutions));
29  return result;
30  }
31 }
32 
33 template<typename P, typename Numeric>
35 {
36  if( !existsFactorization( p ) )
37  return Interval<Numeric>( p.coefficient() );
38  if( p.factorizedTrivially() )
39  {
40  return evaluate( p.polynomial(), map ) * Interval<Numeric>( p.coefficient() );
41  }
42  else
43  {
44  Interval<Numeric> result( p.coefficient() );
45  for( const auto& factor : p.factorization() )
46  {
47  Interval<Numeric> factorEvaluated = evaluate( factor.first, map );
48  if( factorEvaluated.is_zero() )
49  return factorEvaluated;
50  result *= factorEvaluated.pow( factor.second );
51  }
52  return std::move( result );
53  }
54 }
55 
56 }
carl is the main namespace for the library.
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
bool evaluate(const BasicConstraint< Poly > &c, const Assignment< Number > &m)
Definition: Evaluation.h:10
P computePolynomial(const FactorizedPolynomial< P > &_fpoly)
Obtains the polynomial (representation) of this factorized polynomial.
Interval< Number > pow(const Interval< Number > &i, Integer exp)
Definition: Power.h:11
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
The class which contains the interval arithmetic including trigonometric functions.
Definition: Interval.h:134
bool is_zero() const
Function which determines, if the interval is the zero interval.
Definition: Interval.h:1101
static const T & get()
Definition: constants.h:42
const Factorization< P > & factorization() const
const CoeffType & coefficient() const