carl  24.04
Computer ARithmetic Library
VarInfo.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../VarInfo.h"
4 #include "../MultivariatePolynomial.h"
5 
6 namespace carl {
7 
8 namespace detail {
9 
10 template<typename CoeffType>
11 inline void var_info_term(VarInfo<CoeffType>& info, const typename CoeffType::TermType& term, const Variable var, bool collect_coeff) {
12  if (term.has(var)) {
13  exponent exp = term.monomial()->exponent_of_variable(var);
15  info.raise_max_degree(exp);
16  info.lower_min_degree(exp);
17  if (collect_coeff) {
18  typename CoeffType::MonomType::Arg m = term.monomial()->drop_variable(var);
19  if(m == nullptr) {
20  info.update_coeff(exp, typename CoeffType::TermType(term.coeff()));
21  } else {
22  info.update_coeff(exp, typename CoeffType::TermType(term.coeff(), m));
23  }
24  }
25  } else {
26  if (collect_coeff) {
27  info.update_coeff(0, term);
28  }
29  }
30 }
31 
32 template<typename Coeff, typename Ordering, typename Policies>
34  for (const auto& ve : *term.monomial()) {
35  auto& info = infos.var(ve.first);
36 
37  info.increase_num_occurences();
38  info.raise_max_degree(ve.second);
39  info.lower_min_degree(ve.second);
40  if (collect_coeff) {
41  typename MultivariatePolynomial<Coeff,Ordering,Policies>::MonomType::Arg m = term.monomial()->drop_variable(ve.first);
42  if(m == nullptr) {
43  info.update_coeff(ve.second, typename MultivariatePolynomial<Coeff,Ordering,Policies>::TermType(term.coeff()));
44  } else {
45  info.update_coeff(ve.second, typename MultivariatePolynomial<Coeff,Ordering,Policies>::TermType(term.coeff(), m));
46  }
47  }
48  }
49 }
50 
51 }
52 
53 template<typename Coeff, typename Ordering, typename Policies>
56  for (const auto& term : poly) {
57  detail::var_info_term(res, term, var, collect_coeff);
58  }
59  return res;
60 }
61 
62 template<typename Coeff, typename Ordering, typename Policies>
64  //VarsInfo<MultivariatePolynomial<Coeff,Ordering,Policies>> res;
65  //for (const auto& term : poly) {
66  // detail::vars_info_term(res, term, collect_coeff);
67  //}
68  //return res;
70  for (const auto& var : variables(poly)) {
71  res.data().emplace(var, var_info(poly, var, collect_coeff));
72  }
73  return res;
74 }
75 
76 
77 
78 }
carl is the main namespace for the library.
std::size_t exponent
Type of an exponent.
Definition: Monomial.h:29
Interval< Number > exp(const Interval< Number > &i)
Definition: Exponential.h:10
VarInfo< MultivariatePolynomial< Coeff, Ordering, Policies > > var_info(const MultivariatePolynomial< Coeff, Ordering, Policies > &poly, const Variable var, bool collect_coeff=false)
Definition: VarInfo.h:54
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
VarsInfo< MultivariatePolynomial< Coeff, Ordering, Policies > > vars_info(const MultivariatePolynomial< Coeff, Ordering, Policies > &poly, bool collect_coeff=false)
Definition: VarInfo.h:63
void vars_info_term(VarsInfo< MultivariatePolynomial< Coeff, Ordering, Policies >> &infos, const typename MultivariatePolynomial< Coeff, Ordering, Policies >::TermType &term, bool collect_coeff)
Definition: VarInfo.h:33
void var_info_term(VarInfo< CoeffType > &info, const typename CoeffType::TermType &term, const Variable var, bool collect_coeff)
Definition: VarInfo.h:11
TermType
Definition: term.h:7
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
The general-purpose multivariate polynomial class.
std::shared_ptr< const Monomial > Arg
Definition: Monomial.h:62
Coefficient & coeff()
Get the coefficient.
Definition: Term.h:80
Monomial::Arg & monomial()
Get the monomial.
Definition: Term.h:91
void increase_num_occurences()
Definition: VarInfo.h:55
void update_coeff(std::size_t exponent, const Term &t)
Definition: VarInfo.h:60
void raise_max_degree(std::size_t degree)
Definition: VarInfo.h:43
void lower_min_degree(std::size_t degree)
Definition: VarInfo.h:49
auto & data()
Definition: VarInfo.h:89