carl  24.04
Computer ARithmetic Library
Quotient.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "../MultivariatePolynomial.h"
6 #include "../UnivariatePolynomial.h"
7 
8 namespace carl {
9 
10 /**
11  * Calculates the quotient of a polynomial division.
12  */
13 template<typename C, typename O, typename P>
15  assert(!carl::is_zero(divisor));
16  if (dividend == divisor) {
18  }
19  if (carl::is_one(divisor)) {
20  return dividend;
21  }
22  //static_assert(is_field_type<C>::value, "Division only defined for field coefficients");
25  auto id = tam.getId(p.nr_terms());
26  while(!carl::is_zero(p))
27  {
28  Term<C> factor;
29  if (p.lterm().divide(divisor.lterm(), factor)) {
30  //p -= factor * divisor;
31  p.subtractProduct(factor, divisor);
32  tam.template addTerm<true>(id, factor);
33  }
34  else
35  {
36  p.strip_lterm();
37  }
38  }
40  tam.readTerms(id, result.terms());
41  result.reset_ordered();
42  result.template makeMinimallyOrdered<false, true>();
43  assert(result.is_consistent());
44  assert(dividend.is_consistent());
45  return result;
46 }
47 
48 }
carl is the main namespace for the library.
Interval< Number > quotient(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division with remainder.
Definition: Interval.h:1488
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
Definition: Interval.h:1462
The general-purpose multivariate polynomial class.
const TermsType & terms() const
bool is_consistent() const
Asserts that this polynomial complies with the requirements and assumptions for MultivariatePolynomia...
MultivariatePolynomial & strip_lterm()
Drops the leading term.
const Term< Coeff > & lterm() const
The leading term.
void subtractProduct(const Term< Coeff > &factor, const MultivariatePolynomial &p)
Subtract a term times a polynomial from this polynomial.
std::size_t nr_terms() const
Calculate the number of terms.
Represents a single term, that is a numeric coefficient and a monomial.
Definition: Term.h:23
Term divide(const Coefficient &c) const