carl  24.04
Computer ARithmetic Library
ContextPolynomial.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Context.h"
4 #include "../umvpoly/UnivariatePolynomial.h"
5 #include "../umvpoly/MultivariatePolynomial.h"
6 
7 namespace carl {
8 
9 template<typename Coeff, typename Ordering = GrLexOrdering, typename Policies = StdMultivariatePolynomialPolicies<>>
11 public:
13  /// Number type within the coefficients.
15  // RAN type
17 
18 private:
21 
23  auto pvars = carl::variables(p).as_vector();
24  if (pvars.empty()) return carl::Variable::NO_VARIABLE;
25  for (const auto& v : pvars) assert(std::find(ctx.variable_ordering().begin(), ctx.variable_ordering().end(), v) != ctx.variable_ordering().end());
26  std::sort(pvars.begin(), pvars.end());
27  for (auto it = ctx.variable_ordering().rbegin(); it != ctx.variable_ordering().rend(); it++) {
28  if (binary_search(pvars.begin(), pvars.end(), *it)) return *it;
29  }
30  assert(false);
32  }
33 
34 public:
36 
38 
40 
42 
45  }
46 
48  return m_content;
49  }
50 
52  return m_content;
53  }
54 
56  return m_content;
57  }
58 
61  }
62 
63  const Context& context() const {
64  return m_context;
65  }
66 
67  auto main_var() const {
68  return m_content.main_var();
69  }
70 
71  auto degree() const {
72  return m_content.degree();
73  }
74 
75  auto total_degree() const {
76  return total_degree(m_content);
77  }
78 
79  auto coefficients() const {
80  std::vector<ContextPolynomial<Coeff, Ordering, Policies>> coeffs;
81  for (const auto& coeff : m_content.coefficients()) {
82  coeffs.emplace_back(m_context, coeff);
83  }
84  return coeffs;
85  }
86 
87  auto lcoeff() const {
89  }
90 
91  auto normalized() const {
93  }
94 
95  auto constant_part() const {
96  return m_content.constant_part();
97  }
98 };
99 
100 template<typename Coeff, typename Ordering, typename Policies>
101 struct needs_context_type<ContextPolynomial<Coeff, Ordering, Policies>> : std::true_type {};
102 
103 template<typename Coeff, typename Ordering, typename Policies>
104 struct is_polynomial_type<ContextPolynomial<Coeff, Ordering, Policies>>: std::true_type {};
105 
106 template<typename Coeff, typename Ordering, typename Policies>
108  return is_constant(p.content());
109 }
110 
111 template<typename Coeff, typename Ordering, typename Policies>
113  return is_zero(p.content());
114 }
115 
116 template<typename Coeff, typename Ordering, typename Policies>
118  return is_linear(p.content());
119 }
120 
121 template<typename Coeff, typename Ordering, typename Policies>
123  return is_constant(p);
124 }
125 
126 template<typename Coeff, typename Ordering, typename Policies>
128  if (is_number(p)) return 0;
129  auto it = std::find(p.context().variable_ordering().begin(), p.context().variable_ordering().end(), p.main_var());
130  assert(it != p.context().variable_ordering().end());
131  return std::distance(p.context().variable_ordering().begin(), it)+1;
132 }
133 
134 template<typename Coeff, typename Ordering, typename Policies>
136  variables(p.content(), vars);
137 }
138 
139 template<typename Coeff, typename Ordering, typename Policies>
141  return lhs.content() < rhs.content();
142 }
143 
144 template<typename Coeff, typename Ordering, typename Policies>
146  return lhs.content() == rhs.content();
147 }
148 
149 template<typename Coeff, typename Ordering, typename Policies>
150 std::ostream& operator<<(std::ostream& os, const ContextPolynomial<Coeff, Ordering, Policies>& rhs) {
151  return operator<<(os, rhs.content());
152 }
153 
154 
155 
156 }
157 
158 namespace std {
159 template<typename Coeff, typename Ordering, typename Policies>
160 struct hash<carl::ContextPolynomial<Coeff, Ordering, Policies>> {
162  return std::hash<carl::UnivariatePolynomial<carl::MultivariatePolynomial<Coeff, Ordering, Policies>>>()(p.content());
163  }
164 };
165 
166 } // namespace std
carl is the main namespace for the library.
UnivariatePolynomial< C > to_univariate_polynomial(const MultivariatePolynomial< C, O, P > &p)
Convert a univariate polynomial that is currently (mis)represented by a 'MultivariatePolynomial' into...
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool is_constant(const ContextPolynomial< Coeff, Ordering, Policies > &p)
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
typename UnderlyingNumberType< P >::type Coeff
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool is_number(double d)
Definition: operations.h:54
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
std::size_t level_of(const ContextPolynomial< Coeff, Ordering, Policies > &p)
bool is_linear(const ContextPolynomial< Coeff, Ordering, Policies > &p)
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
static const Variable NO_VARIABLE
Instance of an invalid variable.
Definition: Variable.h:203
T type
A type associated with the type.
Definition: typetraits.h:77
This class represents a univariate polynomial with coefficients of an arbitrary type.
The general-purpose multivariate polynomial class.
const std::vector< Variable > & variable_ordering() const
Definition: Context.h:26
static Variable main_var(const Context &ctx, const MultivariatePolynomial< Coeff, Ordering, Policies > &p)
const UnivariatePolynomial< MultivariatePolynomial< Coeff, Ordering, Policies > > & content() const
const Context & context() const
ContextPolynomial(const Context &context, const MultivariatePolynomial< Coeff, Ordering, Policies > &p)
ContextPolynomial(const Context &context, const Coeff &c)
ContextPolynomial(const Context &context, const UnivariatePolynomial< MultivariatePolynomial< Coeff, Ordering, Policies >> &p)
ContextPolynomial(Context &&context, UnivariatePolynomial< MultivariatePolynomial< Coeff, Ordering, Policies >> &&p)
typename UnivariatePolynomial< NumberType >::RootType RootType
typename UnderlyingNumberType< Coeff >::type NumberType
Number type within the coefficients.
UnivariatePolynomial< MultivariatePolynomial< Coeff, Ordering, Policies > > m_content
MultivariatePolynomial< Coeff, Ordering, Policies > as_multivariate() const
std::size_t operator()(const carl::ContextPolynomial< Coeff, Ordering, Policies > &p) const