carl  24.04
Computer ARithmetic Library
MultivariatePolynomial_operators.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 namespace carl {
6 
7 /// @name Equality comparison operators
8 /// @{
9 /**
10  * Checks if the two arguments are equal.
11  * @param lhs First argument.
12  * @param rhs Second argument.
13  * @return `lhs == rhs`
14  */
15 template<typename C, typename O, typename P>
17  // Try to avoid sorting
18  if (&lhs == &rhs) return true;
19  if (lhs.nr_terms() != rhs.nr_terms()) return false;
20  if (lhs.nr_terms() == 0) return true;
21 #ifdef THREAD_SAFE
22  static std::mutex mutex;
23  std::lock_guard<std::mutex> lock(mutex);
24 #endif
25  static std::vector<const C*> coeffs;
26  coeffs.resize(MonomialPool::getInstance().largestID() + 1);
27  memset(&coeffs[0], 0, sizeof(typename std::vector<const C*>::value_type)*coeffs.size());
28  for (const auto& t: lhs) {
29  std::size_t id = 0;
30  if (t.monomial()) id = t.monomial()->id();
31  coeffs[id] = &t.coeff();
32  }
33  for (const auto& t: rhs) {
34  std::size_t id = 0;
35  if (t.monomial()) id = t.monomial()->id();
36  if ((coeffs[id] == nullptr) || *coeffs[id] != t.coeff()) return false;
37  }
38  return true;
39 }
40 template<typename C, typename O, typename P>
41 inline bool operator==(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
42  if (is_zero(lhs) && is_zero(rhs)) return true;
43  if (lhs.nr_terms() > 1) return false;
44  return lhs.lterm() == rhs;
45 }
46 template<typename C, typename O, typename P>
47 inline bool operator==(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
48  if (lhs.nr_terms() != 1) return false;
49  if (lhs.lmon() != rhs) return false;
50  return carl::is_one(lhs.lcoeff());
51 }
52 template<typename C, typename O, typename P>
53 inline bool operator==(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
54  if (lhs.nr_terms() != 1) return false;
55  if (lhs.lmon() != rhs) return false;
56  return carl::is_one(lhs.lcoeff());
57 }
58 template<typename C, typename O, typename P>
59 inline bool operator==(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
60  return lhs.is_constant() && lhs.constant_part() == rhs;
61 }
62 template<typename C, typename O, typename P, DisableIf<std::is_integral<C>> = dummy>
63 inline bool operator==(const MultivariatePolynomial<C,O,P>& lhs, int rhs) {
64  return lhs.is_constant() && lhs.constant_part() == rhs;
65 }
66 template<typename C, typename O, typename P>
67 inline bool operator==(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
68  return rhs == lhs;
69 }
70 template<typename C, typename O, typename P>
71 inline bool operator==(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
72  return rhs == lhs;
73 }
74 template<typename C, typename O, typename P>
75 inline bool operator==(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
76  return rhs == lhs;
77 }
78 template<typename C, typename O, typename P>
79 inline bool operator==(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
80  return rhs == lhs;
81 }
82 
83 template<typename C, typename O, typename P>
86  return MultivariatePolynomial<C,O,P>(lhs) == rhs;
87 }
88 template<typename C, typename O, typename P>
90  return rhs == lhs;
91 }
92 template<typename C, typename O, typename P>
95  return MultivariatePolynomial<C>(lhs) == rhs;
96 }
97 template<typename C, typename O, typename P>
99  return rhs == lhs;
100 }
101 /// @}
102 
103 /// @name Inequality comparison operators
104 /// @{
105 /**
106  * Checks if the two arguments are not equal.
107  * @param lhs First argument.
108  * @param rhs Second argument.
109  * @return `lhs != rhs`
110  */
111 template<typename C, typename O, typename P>
113  return !(lhs == rhs);
114 }
115 template<typename C, typename O, typename P>
116 inline bool operator!=(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
117  return !(lhs == rhs);
118 }
119 template<typename C, typename O, typename P>
120 inline bool operator!=(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
121  return !(lhs == rhs);
122 }
123 template<typename C, typename O, typename P>
124 inline bool operator!=(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
125  return !(lhs == rhs);
126 }
127 template<typename C, typename O, typename P>
128 inline bool operator!=(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
129  return !(lhs == rhs);
130 }
131 template<typename C, typename O, typename P>
132 inline bool operator!=(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
133  return !(lhs == rhs);
134 }
135 template<typename C, typename O, typename P>
136 inline bool operator!=(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
137  return !(lhs == rhs);
138 }
139 template<typename C, typename O, typename P>
140 inline bool operator!=(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
141  return !(lhs == rhs);
142 }
143 template<typename C, typename O, typename P>
144 inline bool operator!=(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
145  return !(lhs == rhs);
146 }
147 
148 template<typename C, typename O, typename P>
150  return !(lhs == rhs);
151 }
152 template<typename C, typename O, typename P>
154  return !(lhs == rhs);
155 }
156 template<typename C, typename O, typename P>
158  return !(lhs == rhs);
159 }
160 template<typename C, typename O, typename P>
162  return !(lhs == rhs);
163 }
164 /// @}
165 
166 /// @name Less than comparison operators
167 /// @{
168 /**
169  * Checks if the first arguments is less than the second.
170  * @param lhs First argument.
171  * @param rhs Second argument.
172  * @return `lhs < rhs`
173  */
174 template<typename C, typename O, typename P>
176  if (is_zero(lhs) && is_zero(rhs)) return false;
177  if (is_zero(lhs)) return true;
178  if (is_zero(rhs)) return false;
179  if (lhs.total_degree() != rhs.total_degree()) return lhs.total_degree() < rhs.total_degree();
180  if (lhs.total_degree() == 0) return lhs.constant_part() < rhs.constant_part();
181  if (lhs.lterm() < rhs.lterm()) return true;
182  if (lhs.lterm() > rhs.lterm()) return false;
183  // We have to sort now.
184  lhs.makeOrdered();
185  rhs.makeOrdered();
186  auto lit = lhs.rbegin();
187  auto rit = rhs.rbegin();
188  for (lit++, rit++; lit != lhs.rend(); lit++, rit++) {
189  if (rit == rhs.rend()) return false;
190  if (*lit < *rit) return true;
191  if (*lit > *rit) return false;
192  }
193  return rit != rhs.rend();
194 }
195 template<typename C, typename O, typename P>
196 inline bool operator<(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
197  if (is_zero(lhs)) return carl::constant_zero<C>().get() < rhs;
198  return lhs.lterm() < rhs;
199 }
200 template<typename C, typename O, typename P>
201 inline bool operator<(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
202  if (is_zero(lhs)) return true;
203  return lhs.lterm() < rhs;
204 }
205 template<typename C, typename O, typename P>
206 inline bool operator<(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
207  if (is_zero(lhs)) return true;
208  return lhs.lterm() < rhs;
209 }
210 template<typename C, typename O, typename P>
211 inline bool operator<(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
212  if (is_zero(lhs)) return true;
213  return lhs.lterm() < rhs;
214 }
215 template<typename C, typename O, typename P>
216 inline bool operator<(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
217  if (is_zero(rhs)) return lhs < carl::constant_zero<C>().get();
218  if (lhs < rhs.lterm()) return true;
219  if (lhs == rhs.lterm()) return rhs.nr_terms() > 1;
220  return false;
221 }
222 template<typename C, typename O, typename P>
223 inline bool operator<(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
224  if (is_zero(rhs)) return false;
225  if (lhs < rhs.lterm()) return true;
226  if (lhs == rhs.lterm()) return rhs.nr_terms() > 1;
227  return false;
228 }
229 template<typename C, typename O, typename P>
230 inline bool operator<(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
231  if (is_zero(rhs)) return false;
232  if (lhs < rhs.lterm()) return true;
233  if (lhs == rhs.lterm()) return rhs.nr_terms() > 1;
234  return false;
235 }
236 template<typename C, typename O, typename P>
237 inline bool operator<(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
238  if (is_zero(rhs)) return lhs < carl::constant_zero<C>().get();
239  return lhs < rhs.lterm();
240 }
241 /// @}
242 
243 /// @name Greater than comparison operators
244 /// @{
245 /**
246  * Checks if the first argument is greater than the second.
247  * @param lhs First argument.
248  * @param rhs Second argument.
249  * @return `lhs > rhs`
250  */
251 template<typename C, typename O, typename P>
253  return rhs < lhs;
254 }
255 template<typename C, typename O, typename P>
256 inline bool operator>(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
257  return rhs < lhs;
258 }
259 template<typename C, typename O, typename P>
260 inline bool operator>(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
261  return rhs < lhs;
262 }
263 template<typename C, typename O, typename P>
264 inline bool operator>(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
265  return rhs < lhs;
266 }
267 template<typename C, typename O, typename P>
268 inline bool operator>(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
269  return rhs < lhs;
270 }
271 template<typename C, typename O, typename P>
272 inline bool operator>(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
273  return rhs < lhs;
274 }
275 template<typename C, typename O, typename P>
276 inline bool operator>(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
277  return rhs < lhs;
278 }
279 template<typename C, typename O, typename P>
280 inline bool operator>(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
281  return rhs < lhs;
282 }
283 template<typename C, typename O, typename P>
284 inline bool operator>(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
285  return rhs < lhs;
286 }
287 
288 template<typename C, typename O, typename P>
290  return rhs < lhs;
291 }
292 template<typename C, typename O, typename P>
294  return rhs < lhs;
295 }
296 template<typename C, typename O, typename P>
298  return rhs < lhs;
299 }
300 template<typename C, typename O, typename P>
302  return rhs < lhs;
303 }
304 /// @}
305 
306 /// @name Less or equal comparison operators
307 /// @{
308 /**
309  * Checks if the first argument is less or equal than the second.
310  * @param lhs First argument.
311  * @param rhs Second argument.
312  * @return `lhs <= rhs`
313  */
314 template<typename C, typename O, typename P>
316  return !(rhs < lhs);
317 }
318 template<typename C, typename O, typename P>
319 inline bool operator<=(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
320  return !(rhs < lhs);
321 }
322 template<typename C, typename O, typename P>
323 inline bool operator<=(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
324  return !(rhs < lhs);
325 }
326 template<typename C, typename O, typename P>
327 inline bool operator<=(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
328  return !(rhs < lhs);
329 }
330 template<typename C, typename O, typename P>
331 inline bool operator<=(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
332  return !(rhs < lhs);
333 }
334 template<typename C, typename O, typename P>
335 inline bool operator<=(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
336  return !(rhs < lhs);
337 }
338 template<typename C, typename O, typename P>
339 inline bool operator<=(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
340  return !(rhs < lhs);
341 }
342 template<typename C, typename O, typename P>
343 inline bool operator<=(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
344  return !(rhs < lhs);
345 }
346 template<typename C, typename O, typename P>
347 inline bool operator<=(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
348  return !(rhs < lhs);
349 }
350 
351 template<typename C, typename O, typename P>
353  return !(rhs < lhs);
354 }
355 template<typename C, typename O, typename P>
357  return !(rhs < lhs);
358 }
359 template<typename C, typename O, typename P>
361  return !(rhs < lhs);
362 }
363 template<typename C, typename O, typename P>
365  return !(rhs < lhs);
366 }
367 /// @}
368 
369 /// @name Greater or equal comparison operators
370 /// @{
371 /**
372  * Checks if the first argument is greater or equal than the second.
373  * @param lhs First argument.
374  * @param rhs Second argument.
375  * @return `lhs >= rhs`
376  */
377 template<typename C, typename O, typename P>
379  return rhs <= lhs;
380 }
381 template<typename C, typename O, typename P>
382 inline bool operator>=(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
383  return rhs <= lhs;
384 }
385 template<typename C, typename O, typename P>
386 inline bool operator>=(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
387  return rhs <= lhs;
388 }
389 template<typename C, typename O, typename P>
390 inline bool operator>=(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
391  return rhs <= lhs;
392 }
393 template<typename C, typename O, typename P>
394 inline bool operator>=(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
395  return rhs <= lhs;
396 }
397 template<typename C, typename O, typename P>
398 inline bool operator>=(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
399  return rhs <= lhs;
400 }
401 template<typename C, typename O, typename P>
402 inline bool operator>=(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
403  return rhs <= lhs;
404 }
405 template<typename C, typename O, typename P>
406 inline bool operator>=(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
407  return rhs <= lhs;
408 }
409 template<typename C, typename O, typename P>
410 inline bool operator>=(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
411  return rhs <= lhs;
412 }
413 
414 template<typename C, typename O, typename P>
416  return rhs <= lhs;
417 }
418 template<typename C, typename O, typename P>
420  return rhs <= lhs;
421 }
422 template<typename C, typename O, typename P>
424  return rhs <= lhs;
425 }
426 template<typename C, typename O, typename P>
428  return rhs <= lhs;
429 }
430 /// @}
431 
432 /// @name Addition operators
433 /// @{
434 
435 /**
436  * Performs an addition involving a polynomial using `operator+=()`.
437  * @param lhs First argument.
438  * @param rhs Second argument.
439  * @return `lhs + rhs`
440  */
441 template<typename C, typename O, typename P>
443  return MultivariatePolynomial<C,O,P>(lhs) += rhs;
444 }
445 template<typename C, typename O, typename P>
446 inline auto operator+(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
447  return MultivariatePolynomial<C,O,P>(lhs) += rhs;
448 }
449 template<typename C, typename O, typename P>
450 inline auto operator+(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
451  return MultivariatePolynomial<C,O,P>(lhs) += rhs;
452 }
453 template<typename C, typename O, typename P>
454 inline auto operator+(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
455  return MultivariatePolynomial<C,O,P>(lhs) += rhs;
456 }
457 template<typename C, typename O, typename P>
458 inline auto operator+(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
459  return MultivariatePolynomial<C,O,P>(lhs) += rhs;
460 }
461 template<typename C, typename O, typename P>
462 inline auto operator+(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
463  return MultivariatePolynomial<C>(rhs) += lhs;
464 }
465 template<typename C>
466 inline auto operator+(const Term<C>& lhs, const Term<C>& rhs) {
467  return MultivariatePolynomial<C>(lhs) += rhs;
468 }
469 template<typename C>
470 inline auto operator+(const Term<C>& lhs, const Monomial::Arg& rhs) {
471  return MultivariatePolynomial<C>(lhs) += rhs;
472 }
473 template<typename C>
474 inline auto operator+(const Term<C>& lhs, Variable rhs) {
475  return MultivariatePolynomial<C>(lhs) += rhs;
476 }
477 template<typename C>
478 inline auto operator+(const Term<C>& lhs, const C& rhs) {
479  return MultivariatePolynomial<C>(lhs) += rhs;
480 }
481 template<typename C, typename O, typename P>
482 inline auto operator+(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
483  return MultivariatePolynomial<C>(rhs) += lhs;
484 }
485 template<typename C>
486 inline auto operator+(const Monomial::Arg& lhs, const Term<C>& rhs) {
487  return MultivariatePolynomial<C>(rhs) += lhs;
488 }
489 template<typename C, EnableIf<carl::is_number_type<C>> = dummy>
490 inline auto operator+(const Monomial::Arg& lhs, const C& rhs) {
491  return MultivariatePolynomial<C>(lhs) += rhs;
492 }
493 template<typename C, typename O, typename P>
494 inline auto operator+(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
495  return MultivariatePolynomial<C>(rhs) += lhs;
496 }
497 template<typename C>
498 inline auto operator+(Variable lhs, const Term<C>& rhs) {
499  return MultivariatePolynomial<C>(rhs) += lhs;
500 }
501 template<typename C, EnableIf<carl::is_number_type<C>> = dummy>
502 inline auto operator+(Variable lhs, const C& rhs) {
503  return MultivariatePolynomial<C>(lhs) += rhs;
504 }
505 template<typename C, typename O, typename P>
506 inline auto operator+(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
507  return MultivariatePolynomial<C>(rhs) += lhs;
508 }
509 template<typename C>
510 inline auto operator+(const C& lhs, const Term<C>& rhs) {
511  return MultivariatePolynomial<C>(rhs) += lhs;
512 }
513 template<typename C, EnableIf<carl::is_number_type<C>> = dummy>
514 inline auto operator+(const C& lhs, const Monomial::Arg& rhs) {
515  return MultivariatePolynomial<C>(rhs) += lhs;
516 }
517 template<typename C, EnableIf<carl::is_number_type<C>> = dummy>
518 inline auto operator+(const C& lhs, Variable rhs) {
519  return MultivariatePolynomial<C>(rhs) += lhs;
520 }
521 /// @}
522 
523 /// @name Subtraction operators
524 /// @{
525 /**
526  * Performs a subtraction involving a polynomial using `operator-=()`.
527  * @param lhs First argument.
528  * @param rhs Second argument.
529  * @return `lhs - rhs`
530  */
531 template<typename C, typename O, typename P>
533  return MultivariatePolynomial<C,O,P>(lhs) -= rhs;
534 }
535 template<typename C, typename O, typename P>
536 inline auto operator-(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
537  return MultivariatePolynomial<C,O,P>(lhs) -= rhs;
538 }
539 template<typename C, typename O, typename P>
540 inline auto operator-(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
541  return MultivariatePolynomial<C,O,P>(lhs) -= rhs;
542 }
543 template<typename C, typename O, typename P>
544 inline auto operator-(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
545  return MultivariatePolynomial<C,O,P>(lhs) -= rhs;
546 }
547 template<typename C, typename O, typename P>
548 inline auto operator-(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
549  return MultivariatePolynomial<C,O,P>(lhs) -= rhs;
550 }
551 template<typename C, typename O, typename P>
552 inline auto operator-(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
553  return -rhs + lhs;
554 }
555 template<typename C>
556 inline auto operator-(const Term<C>& lhs, const Term<C>& rhs) {
557  return MultivariatePolynomial<C>(lhs) -= rhs;
558 }
559 template<typename C>
560 inline auto operator-(const Term<C>& lhs, const Monomial::Arg& rhs) {
561  return MultivariatePolynomial<C>(lhs) -= rhs;
562 }
563 template<typename C>
564 inline auto operator-(const Term<C>& lhs, Variable rhs) {
565  return MultivariatePolynomial<C>(lhs) -= rhs;
566 }
567 template<typename C>
568 inline auto operator-(const Term<C>& lhs, const C& rhs) {
569  return MultivariatePolynomial<C>(lhs) -= rhs;
570 }
571 template<typename C, typename O, typename P>
572 inline auto operator-(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
573  return -rhs + lhs;
574 }
575 template<typename C>
576 inline auto operator-(const Monomial::Arg& lhs, const Term<C>& rhs) {
577  return -rhs + lhs;
578 }
579 template<typename C, EnableIf<carl::is_number_type<C>> = dummy>
580 inline auto operator-(const Monomial::Arg& lhs, const C& rhs) {
581  return MultivariatePolynomial<C>(lhs) -= rhs;
582 }
583 template<typename C, typename O, typename P>
584 inline auto operator-(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
585  return -rhs + lhs;
586 }
587 template<typename C>
588 inline auto operator-(Variable lhs, const Term<C>& rhs) {
589  return -rhs + lhs;
590 }
591 template<typename C, EnableIf<carl::is_number_type<C>> = dummy>
592 inline auto operator-(Variable lhs, const C& rhs) {
593  return MultivariatePolynomial<C>(lhs) -= rhs;
594 }
595 template<typename C, typename O, typename P>
596 inline auto operator-(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
597  return -rhs + lhs;
598 }
599 template<typename C>
600 inline auto operator-(const C& lhs, const Term<C>& rhs) {
601  return -rhs + lhs;
602 }
603 template<typename C, EnableIf<carl::is_number_type<C>> = dummy>
604 inline auto operator-(const C& lhs, const Monomial::Arg& rhs) {
605  return -MultivariatePolynomial<C>(rhs) + lhs;
606 }
607 template<typename C, EnableIf<carl::is_number_type<C>> = dummy>
608 inline auto operator-(const C& lhs, Variable rhs) {
609  return -MultivariatePolynomial<C>(rhs) + lhs;
610 }
611 /// @}
612 
613 /// @name Multiplication operators
614 /// @{
615 /**
616  * Perform a multiplication involving a polynomial using `operator*=()`.
617  * @param lhs Left hand side.
618  * @param rhs Right hand side.
619  * @return `lhs * rhs`
620  */
621 template<typename C, typename O, typename P>
623  return MultivariatePolynomial<C,O,P>(lhs) *= rhs;
624 }
625 template<typename C, typename O, typename P>
626 inline auto operator*(const MultivariatePolynomial<C,O,P>& lhs, const Term<C>& rhs) {
627  return MultivariatePolynomial<C,O,P>(lhs) *= rhs;
628 }
629 template<typename C, typename O, typename P>
630 inline auto operator*(const MultivariatePolynomial<C,O,P>& lhs, const Monomial::Arg& rhs) {
631  return MultivariatePolynomial<C,O,P>(lhs) *= rhs;
632 }
633 template<typename C, typename O, typename P>
634 inline auto operator*(const MultivariatePolynomial<C,O,P>& lhs, Variable rhs) {
635  return MultivariatePolynomial<C,O,P>(lhs) *= rhs;
636 }
637 template<typename C, typename O, typename P>
638 inline auto operator*(const MultivariatePolynomial<C,O,P>& lhs, const C& rhs) {
639  return MultivariatePolynomial<C,O,P>(lhs) *= rhs;
640 }
641 template<typename C, typename O, typename P>
642 inline auto operator*(const Term<C>& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
643  return MultivariatePolynomial<C,O,P>(rhs) *= lhs;
644 }
645 template<typename C, typename O, typename P>
646 inline auto operator*(const Monomial::Arg& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
647  return MultivariatePolynomial<C,O,P>(rhs) *= lhs;
648 }
649 template<typename C, typename O, typename P>
650 inline auto operator*(Variable lhs, const MultivariatePolynomial<C,O,P>& rhs) {
651  return MultivariatePolynomial<C,O,P>(rhs) *= lhs;
652 }
653 template<typename C, typename O, typename P>
654 inline auto operator*(const C& lhs, const MultivariatePolynomial<C,O,P>& rhs) {
655  return MultivariatePolynomial<C,O,P>(rhs) *= lhs;
656 }
657 /// @}
658 
659 
660 }
#define CARL_LOG_INEFFICIENT()
Definition: carl-logging.h:49
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)
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
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)
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
Definition: Interval.h:1462
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
static const T & get()
Definition: constants.h:42
This class represents a univariate polynomial with coefficients of an arbitrary type.
The general-purpose multivariate polynomial class.
void makeOrdered() const
Ensure that the terms are ordered.
bool is_constant() const
Check if the polynomial is constant.
const Term< Coeff > & lterm() const
The leading term.
const Coeff & constant_part() const
Retrieve the constant term of this polynomial or zero, if there is no constant term.
const Coeff & lcoeff() const
Returns the coefficient of the leading term.
const Monomial::Arg & lmon() const
The leading monomial.
std::size_t nr_terms() const
Calculate the number of terms.
std::size_t total_degree() const
Calculates the max.
std::shared_ptr< const Monomial > Arg
Definition: Monomial.h:62
Represents a single term, that is a numeric coefficient and a monomial.
Definition: Term.h:23
static MonomialPool & getInstance()
Returns the single instance of this class by reference.
Definition: Singleton.h:45