carl  25.02
Computer ARithmetic Library
LPPolynomial.cpp
Go to the documentation of this file.
1 #include "LPPolynomial.h"
2 #include "helper.h"
3 #include <poly/variable_list.h>
4 
5 #include <carl-common/config.h>
6 #ifdef USE_LIBPOLY
7 
8 namespace carl {
9 
10 LPPolynomial::LPPolynomial(const LPPolynomial& rhs)
11  : m_internal(lp_polynomial_new_copy(rhs.m_internal)), m_context(rhs.m_context) {
12  assert(lp_polynomial_check_order(get_internal()));
13 }
14 
15 LPPolynomial::LPPolynomial(LPPolynomial&& rhs)
16  : m_internal(rhs.m_internal), m_context(std::move(rhs.m_context)) {
17  rhs.m_internal = 0;
18  assert(lp_polynomial_check_order(get_internal()));
19 }
20 
21 LPPolynomial& LPPolynomial::operator=(const LPPolynomial& rhs) {
22  m_internal = lp_polynomial_new_copy(rhs.m_internal);
23  m_context = rhs.m_context;
24  assert(lp_polynomial_check_order(get_internal()));
25  return *this;
26 }
27 
28 LPPolynomial& LPPolynomial::operator=(LPPolynomial&& rhs) {
29  if (m_internal) lp_polynomial_delete(m_internal);
30  m_internal = rhs.m_internal;
31  m_context = std::move(rhs.m_context);
32  rhs.m_internal = 0;
33  assert(lp_polynomial_check_order(get_internal()));
34  return *this;
35 }
36 
37 LPPolynomial::LPPolynomial(const LPContext& context)
38  : m_internal(lp_polynomial_new(context.lp_context())), m_context(context) {
39  //lp_polynomial_set_external(get_internal());
40  assert(lp_polynomial_check_order(get_internal()));
41 }
42 
43 LPPolynomial::LPPolynomial(lp_polynomial_t* p, const LPContext& context)
44  : m_internal(p), m_context(context) {
45  //lp_polynomial_set_external(get_internal());
46  assert(lp_polynomial_check_order(get_internal()));
47  assert(context.lp_context() == lp_polynomial_get_context(get_internal()));
48 }
49 
50 LPPolynomial::LPPolynomial(const LPContext& context, long val)
51  : m_internal(lp_polynomial_alloc()), m_context(context) {
52  lp_polynomial_construct_simple(get_internal(), context.lp_context(), mpz_class(val).get_mpz_t(), 0, 0);
53  //lp_polynomial_set_external(get_internal());
54  assert(lp_polynomial_check_order(get_internal()));
55 }
56 
57 LPPolynomial::LPPolynomial(const LPContext& context, const mpz_class& val)
58  : m_internal(lp_polynomial_alloc()), m_context(context) {
59  lp_polynomial_construct_simple(get_internal(), context.lp_context(), val.get_mpz_t(), lp_variable_null, 0) ;
60  //lp_polynomial_set_external(get_internal());
61  assert(lp_polynomial_check_order(get_internal()));
62 }
63 
64 LPPolynomial::LPPolynomial(const LPContext& context, const mpq_class& val) : LPPolynomial(context, carl::get_num(val)) {}
65 
66 LPPolynomial::LPPolynomial(const LPContext& context, const Variable& var, const mpz_class& coeff, unsigned int degree)
67  : m_internal(lp_polynomial_alloc()), m_context(context) {
68  lp_polynomial_construct_simple(get_internal(), context.lp_context(), mpz_class(coeff).get_mpz_t(), context.lp_variable(var), degree);
69  //lp_polynomial_set_external(get_internal());
70  assert(lp_polynomial_check_order(get_internal()));
71 }
72 
73 LPPolynomial::LPPolynomial(const LPContext& context, const Variable& var)
74  : m_internal(lp_polynomial_alloc()), m_context(context) {
75  lp_polynomial_construct_simple(get_internal(), context.lp_context(), mpz_class(1).get_mpz_t(), context.lp_variable(var), 1);
76  //lp_polynomial_set_external(get_internal());
77  assert(lp_polynomial_check_order(get_internal()));
78 }
79 
80 LPPolynomial::LPPolynomial(const LPContext& context, const Variable& mainVar, const std::initializer_list<mpz_class>& coefficients)
81  : LPPolynomial(context) {
82 
83  auto var = context.lp_variable(mainVar);
84  auto pow = coefficients.size();
85 
86  for (const mpz_class& coeff : coefficients) {
87  pow--;
88  if (is_zero(coeff)) continue;
89  lp_monomial_t t;
90  lp_monomial_construct(context.lp_context(), &t);
91  lp_monomial_set_coefficient(context.lp_context(), &t, mpz_class(coeff).get_mpz_t());
92  if (pow>0)
93  lp_monomial_push(&t, var, (unsigned int)pow);
94  lp_polynomial_add_monomial(get_internal(), &t);
95  lp_monomial_destruct(&t);
96  }
97  //lp_polynomial_set_external(get_internal());
98 }
99 
100 LPPolynomial::LPPolynomial(const LPContext& context, const Variable& mainVar, const std::vector<mpz_class>& coefficients)
101  : LPPolynomial(context) {
102 
103  auto var = context.lp_variable(mainVar);
104  auto pow = coefficients.size();
105 
106  for (const mpz_class& coeff : coefficients) {
107  pow--;
108  if (is_zero(coeff)) continue;
109  lp_monomial_t t;
110  lp_monomial_construct(context.lp_context(), &t);
111  lp_monomial_set_coefficient(context.lp_context(), &t, mpz_class(coeff).get_mpz_t());
112  if (pow>0)
113  lp_monomial_push(&t, var, (unsigned int)pow);
114  lp_polynomial_add_monomial(get_internal(), &t);
115  lp_monomial_destruct(&t);
116  }
117  //lp_polynomial_set_external(get_internal());
118 }
119 
120 LPPolynomial::LPPolynomial(const LPContext& context, const Variable& mainVar, std::vector<mpz_class>&& coefficients)
121  : LPPolynomial(context) {
122 
123  auto var = context.lp_variable(mainVar);
124  auto pow = coefficients.size();
125 
126  for (const mpz_class& coeff : coefficients) {
127  pow--;
128  if (is_zero(coeff)) continue;
129  lp_monomial_t t;
130  lp_monomial_construct(context.lp_context(), &t);
131  lp_monomial_set_coefficient(context.lp_context(), &t, mpz_class(coeff).get_mpz_t());
132  if (pow>0)
133  lp_monomial_push(&t, var, (unsigned int)pow);
134  lp_polynomial_add_monomial(get_internal(), &t);
135  lp_monomial_destruct(&t);
136  }
137  //lp_polynomial_set_external(get_internal());
138 }
139 
140 LPPolynomial::LPPolynomial(const LPContext& context, const Variable& mainVar, const std::map<unsigned int, mpz_class>& coefficients)
141  : LPPolynomial(context) {
142 
143  auto var = context.lp_variable(mainVar);
144 
145  for (const auto& coeff : coefficients) {
146  if (is_zero(coeff.second)) continue;
147  lp_monomial_t t;
148  lp_monomial_construct(context.lp_context(), &t);
149  lp_monomial_set_coefficient(context.lp_context(), &t, mpz_class(coeff.second).get_mpz_t());
150  if (coeff.first>0)
151  lp_monomial_push(&t, var, (unsigned int)coeff.first);
152  lp_polynomial_add_monomial(get_internal(), &t);
153  lp_monomial_destruct(&t);
154  }
155  //lp_polynomial_set_external(get_internal());
156 }
157 
158 LPPolynomial::~LPPolynomial() {
159  // std::cout << ">>>>>>>>>>> K : " << m_context.lp_context()->K << "\n";
160  if (m_internal) lp_polynomial_delete(m_internal);
161 }
162 
163 bool LPPolynomial::has(const Variable& var) const {
164  lp_variable_list_t varList;
165  lp_variable_list_construct(&varList);
166  lp_polynomial_get_variables(get_internal(), &varList);
167  auto lp_variable = context().lp_variable_opt(var);
168  if (!lp_variable) return false;
169  bool contains = lp_variable_list_contains(&varList, *lp_variable);
170  lp_variable_list_destruct(&varList);
171  return contains;
172 }
173 
174 bool operator==(const LPPolynomial& lhs, const LPPolynomial& rhs) {
175  return lp_polynomial_eq(lhs.get_internal(), rhs.get_internal());
176 }
177 bool operator==(const LPPolynomial& lhs, const mpz_class& rhs) {
178  if (!is_number(lhs)) {
179  return false;
180  }
181  return lhs.constant_part() == rhs;
182 }
183 bool operator==(const mpz_class& lhs, const LPPolynomial& rhs) {
184  return rhs == lhs;
185 }
186 
187 bool operator!=(const LPPolynomial& lhs, const LPPolynomial& rhs) {
188  return !(lhs == rhs);
189 }
190 bool operator!=(const LPPolynomial& lhs, const mpz_class& rhs) {
191  return !(lhs == rhs);
192 }
193 bool operator!=(const mpz_class& lhs, const LPPolynomial& rhs) {
194  return !(lhs == rhs);
195 }
196 
197 inline auto cmp_util(const LPPolynomial& lhs, const mpz_class& rhs) {
198  lp_polynomial_t* tmp = poly_helper::construct_lp_poly(lp_polynomial_get_context(lhs.get_internal()), rhs);
199  auto res = lp_polynomial_cmp(lhs.get_internal(), tmp);
200  lp_polynomial_delete(tmp);
201  return res;
202 }
203 
204 bool operator<(const LPPolynomial& lhs, const LPPolynomial& rhs) {
205  return lp_polynomial_cmp(lhs.get_internal(), rhs.get_internal()) < 0;
206 }
207 bool operator<(const LPPolynomial& lhs, const mpz_class& rhs) {
208  return cmp_util(lhs,rhs) < 0;
209 }
210 bool operator<(const mpz_class& lhs, const LPPolynomial& rhs) {
211  return cmp_util(rhs,lhs) > 0;
212 }
213 
214 bool operator<=(const LPPolynomial& lhs, const LPPolynomial& rhs) {
215  return lp_polynomial_cmp(lhs.get_internal(), rhs.get_internal()) <= 0;
216 }
217 bool operator<=(const LPPolynomial& lhs, const mpz_class& rhs) {
218  return cmp_util(lhs,rhs) <= 0;
219 }
220 bool operator<=(const mpz_class& lhs, const LPPolynomial& rhs) {
221  return cmp_util(rhs,lhs) >= 0;
222 }
223 
224 bool operator>(const LPPolynomial& lhs, const LPPolynomial& rhs) {
225  return lp_polynomial_cmp(lhs.get_internal(), rhs.get_internal()) > 0;
226 }
227 bool operator>(const LPPolynomial& lhs, const mpz_class& rhs) {
228  return cmp_util(lhs,rhs) > 0;
229 }
230 bool operator>(const mpz_class& lhs, const LPPolynomial& rhs) {
231  return cmp_util(rhs,lhs) < 0;
232 }
233 
234 bool operator>=(const LPPolynomial& lhs, const LPPolynomial& rhs) {
235  return lp_polynomial_cmp(lhs.get_internal(), rhs.get_internal()) >= 0;
236 }
237 bool operator>=(const LPPolynomial& lhs, const mpz_class& rhs) {
238  return cmp_util(lhs,rhs) >= 0;
239 }
240 bool operator>=(const mpz_class& lhs, const LPPolynomial& rhs) {
241  return cmp_util(rhs,lhs) <= 0;
242 }
243 
244 LPPolynomial operator+(const LPPolynomial& lhs, const LPPolynomial& rhs) {
245  assert(rhs.context() == lhs.context());
246  assert(lp_polynomial_context_equal(lp_polynomial_get_context(lhs.get_internal()), lp_polynomial_get_context(rhs.get_internal())));
247  LPPolynomial result(lhs.context());
248  lp_polynomial_add(result.get_internal(), lhs.get_internal(), rhs.get_internal());
249  return result;
250 }
251 LPPolynomial operator+(const LPPolynomial& lhs, const mpz_class& rhs) {
252  return lhs + LPPolynomial(lhs.context(), rhs);
253 }
254 LPPolynomial operator+(const mpz_class& lhs, const LPPolynomial& rhs) {
255  return rhs + lhs;
256 }
257 
258 LPPolynomial operator-(const LPPolynomial& lhs, const LPPolynomial& rhs) {
259  assert(rhs.context() == lhs.context());
260  assert(lp_polynomial_context_equal(lp_polynomial_get_context(lhs.get_internal()), lp_polynomial_get_context(rhs.get_internal())));
261  LPPolynomial result(lhs.context());
262  lp_polynomial_sub(result.get_internal(), lhs.get_internal(), rhs.get_internal());
263  return result;
264 }
265 LPPolynomial operator-(const LPPolynomial& lhs, const mpz_class& rhs) {
266  return lhs - LPPolynomial(lhs.context(), rhs);
267 }
268 LPPolynomial operator-(const mpz_class& lhs, const LPPolynomial& rhs) {
269  return LPPolynomial(rhs.context(), lhs) - rhs;
270 }
271 
272 LPPolynomial operator*(const LPPolynomial& lhs, const LPPolynomial& rhs) {
273  assert(lhs.context() == rhs.context());
274  assert(lp_polynomial_context_equal(lp_polynomial_get_context(lhs.get_internal()), lp_polynomial_get_context(rhs.get_internal())));
275  LPPolynomial result(lhs.context());
276  lp_polynomial_mul(result.get_internal(), lhs.get_internal(), rhs.get_internal());
277  return result;
278 }
279 LPPolynomial operator*(const LPPolynomial& lhs, const mpz_class& rhs) {
280  return lhs * LPPolynomial(lhs.context(), rhs);
281 }
282 LPPolynomial operator*(const mpz_class& lhs, const LPPolynomial& rhs) {
283  return rhs * lhs;
284 }
285 
286 LPPolynomial& operator+=(LPPolynomial& lhs, const LPPolynomial& rhs) {
287  assert(rhs.context() == lhs.context());
288  assert(lp_polynomial_context_equal(lp_polynomial_get_context(lhs.get_internal()), lp_polynomial_get_context(rhs.get_internal())));
289  lp_polynomial_add(lhs.get_internal(), lhs.get_internal(), rhs.get_internal());
290  return lhs;
291 }
292 LPPolynomial& operator+=(LPPolynomial& lhs, const mpz_class& rhs) {
293  lp_polynomial_t* tmp = poly_helper::construct_lp_poly(lp_polynomial_get_context(lhs.get_internal()), rhs);
294  lp_polynomial_add(lhs.get_internal(), lhs.get_internal(), tmp);
295  lp_polynomial_delete(tmp);
296  return lhs;
297 }
298 
299 LPPolynomial& operator-=(LPPolynomial& lhs, const LPPolynomial& rhs) {
300  assert(rhs.context() == lhs.context());
301  assert(lp_polynomial_context_equal(lp_polynomial_get_context(lhs.get_internal()), lp_polynomial_get_context(rhs.get_internal())));
302  lp_polynomial_sub(lhs.get_internal(), lhs.get_internal(), rhs.get_internal());
303  return lhs;
304 }
305 LPPolynomial& operator-=(LPPolynomial& lhs, const mpz_class& rhs) {
306  lp_polynomial_t* tmp = poly_helper::construct_lp_poly(lp_polynomial_get_context(lhs.get_internal()), rhs);
307  lp_polynomial_sub(lhs.get_internal(), lhs.get_internal(), tmp);
308  lp_polynomial_delete(tmp);
309  return lhs;
310 }
311 
312 LPPolynomial& operator*=(LPPolynomial& lhs, const LPPolynomial& rhs) {
313  assert(rhs.context() == lhs.context());
314  assert(lp_polynomial_context_equal(lp_polynomial_get_context(lhs.get_internal()), lp_polynomial_get_context(rhs.get_internal())));
315  lp_polynomial_mul(lhs.get_internal(), lhs.get_internal(), rhs.get_internal());
316  return lhs;
317 }
318 LPPolynomial& operator*=(LPPolynomial& lhs, const mpz_class& rhs) {
319  lp_polynomial_t* tmp = poly_helper::construct_lp_poly(lp_polynomial_get_context(lhs.get_internal()), rhs);
320  lp_polynomial_mul(lhs.get_internal(), lhs.get_internal(), tmp);
321  lp_polynomial_delete(tmp);
322  return lhs;
323 }
324 
325 mpz_class LPPolynomial::coprime_factor() const {
326  // TODO: can this be done with content/primitive part?
327  struct coprime_factor_travers {
328  std::vector<mpz_class> coefficients; // coefficients of the polynomial
329  };
330 
331  auto getCoeffs = [](const lp_polynomial_context_t* /*ctx*/,
332  lp_monomial_t* m,
333  void* d) {
334  coprime_factor_travers& v = *static_cast<coprime_factor_travers*>(d);
335  v.coefficients.push_back(*reinterpret_cast<mpz_class*>(&m->a));
336  };
337 
338  // first get the coefficients of every monomial
339  coprime_factor_travers travers;
340  lp_polynomial_traverse(get_internal(), getCoeffs, &travers);
341 
342  if (travers.coefficients.size() == 0) {
343  return 0;
344  }
345  mpz_class res = travers.coefficients[0];
346  for (size_t i = 1; i < travers.coefficients.size(); i++) {
347  res = gcd(res, travers.coefficients[i]);
348  }
349 
350  return res;
351 }
352 
353 LPPolynomial LPPolynomial::coprime_coefficients() const {
354  mpz_class g = coprime_factor();
355  if (g == 1) return *this;
356  lp_polynomial_t* temp = poly_helper::construct_lp_poly(lp_polynomial_get_context(get_internal()), g);
357  lp_polynomial_t* res = lp_polynomial_new(context().lp_context());
358  lp_polynomial_div(res, get_internal(), temp);
359  lp_polynomial_delete(temp);
360  return LPPolynomial(res, context());
361 }
362 
363 std::size_t LPPolynomial::total_degree() const {
364 
365  struct degree_travers {
366  std::size_t degree = 0;
367  };
368 
369  auto getDegree = [](const lp_polynomial_context_t* /*ctx*/,
370  lp_monomial_t* m,
371  void* d) {
372  degree_travers& v = *static_cast<degree_travers*>(d);
373 
374  size_t current_degree = 0;
375  // iterate over the number of variables and add up their degrees
376  for (size_t i = 0; i < m->n; i++) {
377  current_degree += m->p[i].d;
378  }
379  v.degree = std::max(v.degree, current_degree);
380  };
381 
382  degree_travers travers;
383  lp_polynomial_traverse(get_internal(), getDegree, &travers);
384 
385  return travers.degree;
386 }
387 
388 std::size_t LPPolynomial::degree(Variable::Arg var) const {
389  struct degree_travers {
390  std::size_t degree = 0;
391  lp_variable_t var; // the variable we are looking for
392  };
393 
394  auto getDegree = [](const lp_polynomial_context_t* /*ctx*/,
395  lp_monomial_t* m,
396  void* d) {
397  degree_travers& v = *static_cast<degree_travers*>(d);
398 
399  size_t current_degree = 0;
400  // iterate over the number of variables and add up their degrees
401  for (size_t i = 0; i < m->n; i++) {
402  if (m->p[i].x == v.var) {
403  current_degree = m->p[i].d;
404  break;
405  }
406  }
407  v.degree = std::max(v.degree, current_degree);
408  };
409 
410  degree_travers travers;
411  travers.var = context().lp_variable(var);
412  lp_polynomial_traverse(get_internal(), getDegree, &travers);
413 
414  return travers.degree;
415 }
416 
417 std::vector<std::size_t> LPPolynomial::monomial_total_degrees() const {
418  struct degree_travers {
419  std::vector<std::size_t> degree;
420  };
421 
422  auto getDegree = [](const lp_polynomial_context_t* /*ctx*/,
423  lp_monomial_t* m,
424  void* d) {
425  degree_travers& v = *static_cast<degree_travers*>(d);
426 
427  size_t current_degree = 0;
428  // iterate over the number of variables and add up their degrees
429  for (size_t i = 0; i < m->n; i++) {
430  current_degree += m->p[i].d;
431  }
432  v.degree.push_back(current_degree);
433  };
434 
435  degree_travers travers;
436  lp_polynomial_traverse(get_internal(), getDegree, &travers);
437 
438  return travers.degree;
439 }
440 
441 std::vector<std::size_t> LPPolynomial::monomial_degrees(Variable::Arg var) const {
442  struct degree_travers {
443  std::vector<std::size_t> degree;
444  lp_variable_t var; // the variable we are looking for
445  };
446 
447  auto getDegree = [](const lp_polynomial_context_t* /*ctx*/,
448  lp_monomial_t* m,
449  void* d) {
450  degree_travers& v = *static_cast<degree_travers*>(d);
451 
452  size_t current_degree = 0;
453  // iterate over the number of variables and add up their degrees
454  for (size_t i = 0; i < m->n; i++) {
455  if (m->p[i].x == v.var) {
456  current_degree = m->p[i].d;
457  break;
458  }
459  }
460  v.degree.push_back(current_degree);
461  };
462 
463  degree_travers travers;
464  travers.var = context().lp_variable(var);
465  lp_polynomial_traverse(get_internal(), getDegree, &travers);
466 
467  return travers.degree;
468 }
469 
470 mpz_class LPPolynomial::unit_part() const {
471  //As we can only have integer coefficients, they do not form a field
472  //Thus the unit part is the sign of the leading coefficient, if it is not zero
473  //Is the Poly is zero unit part is one
474  if(is_zero(*this)) {
475  return 1 ;
476  }
477  return lp_polynomial_lc_sgn(get_internal()) ;
478 }
479 
480 LPPolynomial LPPolynomial::normalized() const {
481  auto res = coprime_coefficients();
482  auto unit = res.unit_part() ;
483  assert(!is_zero(unit)) ;
484  return res * unit ;
485 
486  /*
487  auto unit = unit_part() ;
488  assert(!is_zero(unit)) ;
489  return (*this) * unit ;
490  */
491 }
492 
493 LPPolynomial LPPolynomial::coeff(Variable::Arg var, std::size_t exp) const {
494  struct coeff_travers {
495  std::vector<lp_monomial_t> coeff;
496  const lp_polynomial_context_t* ctx; // context for the newly created monomials
497  lp_variable_t var; // the variable we are looking for
498  std::size_t exp; // the exponent we are looking for
499  };
500 
501 
502  auto getCoeff = [](const lp_polynomial_context_t* /*ctx*/,
503  lp_monomial_t* m,
504  void* d) {
505  coeff_travers& v = *static_cast<coeff_travers*>(d);
506 
507  bool found = false;
508  // iterate each monomials, and add the ones to add
509  for (size_t i = 0; i < m->n; i++) {
510  if (m->p[i].x == v.var && m->p[i].d == v.exp) {
511  found = true;
512  break;
513  }
514  }
515 
516  if (!found) {
517  return;
518  }
519 
520  // Make a copy (without var^exp) of each monomial and add it to the vector
521  lp_monomial_t new_monomial;
522  lp_monomial_construct(v.ctx, &new_monomial);
523  new_monomial.n = m->n -1 ; // copy the number of variables (-1 because we remove var^exp)
524  new_monomial.capacity = m->capacity ; // copy the capacity
525  lp_integer_assign(v.ctx->K, &new_monomial.a ,&m->a); // copy the coefficient
526  new_monomial.p = (power_t*)realloc(new_monomial.p, sizeof(power_t) * new_monomial.capacity); //allocate the memory for the power array
527 
528  size_t current_counter = 0 ;
529  for(size_t i = 0; i < m->n; i++){
530  if(m->p[i].x == v.var && m->p[i].d == v.exp){
531  continue;
532  }
533  new_monomial.p[current_counter].x = m->p[i].x;
534  new_monomial.p[current_counter].d = m->p[i].d;
535  current_counter++;
536  }
537  assert(current_counter == new_monomial.n);
538  v.coeff.push_back(std::move(new_monomial));
539  };
540 
541  coeff_travers travers;
542  travers.var = context().lp_variable(var);
543  travers.exp = exp;
544  travers.ctx = lp_polynomial_get_context(get_internal());
545  lp_polynomial_traverse(get_internal(), getCoeff, &travers);
546 
547  LPPolynomial res(context());
548  for (auto m : travers.coeff) {
549  lp_polynomial_add_monomial(res.get_internal(), &m);
550  }
551 
552  //free the memory allocated for the monomials
553  for(auto& m : travers.coeff){
554  lp_monomial_destruct(&m);
555  }
556 
557  return res;
558 }
559 
560 bool LPPolynomial::is_normal() const {
561  return carl::is_one(this->unit_part()) ;
562  //return carl::is_one(carl::abs(this->unit_part())) ;
563 }
564 
565 std::ostream& operator<<(std::ostream& os, const LPPolynomial& p) {
566  os << lp_polynomial_to_string(p.get_internal());
567  return os;
568 }
569 
570 void LPPolynomial::set_context(const LPContext& c) {
571  for (auto& v : variables(*this)) assert(c.has(v));
572  if (context() == c) return;
573 
574  bool reorder = !(c.is_extension_of(context()) || context().is_extension_of(c));
575  m_context = c;
576  lp_polynomial_set_context(get_internal(), m_context.lp_context());
577  if (reorder) {
578  lp_polynomial_ensure_order(get_internal());
579  }
580  assert(lp_polynomial_check_order(get_internal()));
581 }
582 
583 } // namespace carl
584 
585 #endif
std::ostream & operator<<(std::ostream &os, const GbBenchmark< C, O, P > &b)
carl is the main namespace for the library.
bool operator>(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
Interval< Number > operator+(const Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the addition of two intervals.
Definition: operators.h:261
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
cln::cl_I gcd(const cln::cl_I &a, const cln::cl_I &b)
Calculate the greatest common divisor of two integers.
Definition: operations.h:310
Interval< Number > exp(const Interval< Number > &i)
Definition: Exponential.h:10
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
Interval< Number > operator*(const Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the multiplication of two intervals.
Definition: operators.h:386
cln::cl_I get_num(const cln::cl_RA &n)
Extract the numerator from a fraction.
Definition: operations.h:60
Interval< Number > & operator*=(Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the multiplication of an interval and a number with assignment.
Definition: operators.h:425
Interval< Number > & operator+=(Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the addition of an interval and a number with assignment.
Definition: operators.h:295
Interval< Number > operator-(const Interval< Number > &rhs)
Unary minus.
Definition: operators.h:318
bool operator!=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator<=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator>=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
Interval< Number > & operator-=(Interval< Number > &lhs, const Interval< Number > &rhs)
Operator for the subtraction of two intervals with assignment.
Definition: operators.h:362
bool is_number(double d)
Definition: operations.h:54
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
Interval< Number > pow(const Interval< Number > &i, Integer exp)
Definition: Power.h:11
auto total_degree(const Monomial &m)
Gives the total degree, i.e.
Definition: Degree.h:24
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
Definition: Interval.h:1462
lp_polynomial_t * construct_lp_poly(const lp_polynomial_context_t *c, lp_variable_t v)
Definition: helper.h:11