carl  24.04
Computer ARithmetic Library
VarInfo.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace carl {
4 
5 template<typename CoeffType>
6 class VarInfo {
7 
8  /// Maximal degree variable occurs with.
9  std::size_t m_max_degree = 0;
10  /// Minimal non-zero degree variable occurs with.
11  std::size_t m_min_degree = 0;
12  /// Number of terms a variable occurs in.
13  std::size_t m_num_occurences = 0;
14  /// Coefficients of the variable. Maps from exponent to the coefficient.
15  std::map<std::size_t, CoeffType> m_coeffs;
16 
17 public:
18  VarInfo() = default;
19  // VarInfo(const VarInfo& varInfo) = default;
20  VarInfo(std::size_t maxDegree, std::size_t min_degree, std::size_t occurence, std::map<std::size_t, CoeffType>&& coeffs) : m_max_degree(maxDegree), m_min_degree(min_degree), m_num_occurences(occurence), m_coeffs(coeffs) {}
21 
22  bool has_coeff() const {
23  return !m_coeffs.empty();
24  }
25 
26  std::size_t max_degree() const {
27  return m_max_degree;
28  }
29 
30  std::size_t min_degree() const {
31  return m_min_degree;
32  }
33 
34  std::size_t num_occurences() const {
35  return m_num_occurences;
36  }
37 
38  const std::map<std::size_t, CoeffType>& coeffs() const {
39  return m_coeffs;
40  }
41 
42 
43  void raise_max_degree(std::size_t degree) {
44  if (m_max_degree < degree) {
45  m_max_degree = degree;
46  }
47  }
48 
49  void lower_min_degree(std::size_t degree) {
50  if (m_min_degree == 0 || m_min_degree > degree) {
51  m_min_degree = degree;
52  }
53  }
54 
57  }
58 
59  template<typename Term>
60  void update_coeff(std::size_t exponent, const Term& t) {
61  auto it = m_coeffs.find(exponent);
62  if (it == m_coeffs.end()) {
63  m_coeffs.emplace(exponent, CoeffType(t));
64  } else {
65  it->second += t;
66  }
67  }
68 
69 };
70 
71 template<typename CoeffType>
72 class VarsInfo {
73  std::map<Variable, VarInfo<CoeffType>> m_data;
74 
75 public:
77  if (m_data.find(var) == m_data.end()) {
78  m_data.emplace(var, VarInfo<CoeffType>());
79  }
80  return m_data[var];
81  }
83  return m_data.at(var);
84  }
85  bool occurs(Variable var) const {
86  return m_data.find(var) != m_data.end();
87  }
88 
89  auto& data() {
90  return m_data;
91  }
92 
93  auto cbegin() const {
94  return m_data.begin();
95  }
96 
97  auto cend() const {
98  return m_data.end();
99  }
100 
101  auto begin() {
102  return m_data.begin();
103  }
104 
105  auto end() {
106  return m_data.end();
107  }
108 };
109 
110 }
carl is the main namespace for the library.
std::size_t exponent
Type of an exponent.
Definition: Monomial.h:29
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
Represents a single term, that is a numeric coefficient and a monomial.
Definition: Term.h:23
std::size_t max_degree() const
Definition: VarInfo.h:26
VarInfo(std::size_t maxDegree, std::size_t min_degree, std::size_t occurence, std::map< std::size_t, CoeffType > &&coeffs)
Definition: VarInfo.h:20
std::size_t min_degree() const
Definition: VarInfo.h:30
bool has_coeff() const
Definition: VarInfo.h:22
void increase_num_occurences()
Definition: VarInfo.h:55
std::map< std::size_t, CoeffType > m_coeffs
Coefficients of the variable. Maps from exponent to the coefficient.
Definition: VarInfo.h:15
const std::map< std::size_t, CoeffType > & coeffs() const
Definition: VarInfo.h:38
std::size_t m_num_occurences
Number of terms a variable occurs in.
Definition: VarInfo.h:13
std::size_t num_occurences() const
Definition: VarInfo.h:34
VarInfo()=default
void update_coeff(std::size_t exponent, const Term &t)
Definition: VarInfo.h:60
std::size_t m_max_degree
Maximal degree variable occurs with.
Definition: VarInfo.h:9
void raise_max_degree(std::size_t degree)
Definition: VarInfo.h:43
void lower_min_degree(std::size_t degree)
Definition: VarInfo.h:49
std::size_t m_min_degree
Minimal non-zero degree variable occurs with.
Definition: VarInfo.h:11
auto cbegin() const
Definition: VarInfo.h:93
auto begin()
Definition: VarInfo.h:101
auto cend() const
Definition: VarInfo.h:97
auto & data()
Definition: VarInfo.h:89
VarInfo< CoeffType > & var(Variable var)
Definition: VarInfo.h:76
std::map< Variable, VarInfo< CoeffType > > m_data
Definition: VarInfo.h:73
const VarInfo< CoeffType > & var(Variable var) const
Definition: VarInfo.h:82
auto end()
Definition: VarInfo.h:105
bool occurs(Variable var) const
Definition: VarInfo.h:85