carl  24.04
Computer ARithmetic Library
Content.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../MultivariatePolynomial.h"
4 #include "../UnivariatePolynomial.h"
5 
6 namespace carl {
7  template<typename Coeff>
8  Coeff content(const UnivariatePolynomial<Coeff>& p);
9 }
10 
11 #include "GCD.h"
12 
13 namespace carl {
14 
15 /**
16  * The content of a polynomial is the gcd of the coefficients of the normal part of a polynomial.
17  * The content of zero is zero.
18  * @see @cite GCL92, page 53, definition 2.18
19  * @return The content of the polynomial.
20  */
21 template<typename Coeff>
23  if (is_zero(p)) {
24  // By definition
25  return Coeff(0);
26  }
27  assert(p.is_normal());
28  if constexpr (is_field_type<Coeff>::value) {
29  // For fields, content(p) = 1
30  return Coeff(1);
31  }
32  auto it = p.coefficients().rbegin();
33  Coeff gcd = *it;
34  for (++it; it != p.coefficients().rend(); ++it) {
35  if (is_one(gcd)) {
36  break;
37  }
38  if (is_zero(*it)) {
39  continue;
40  }
41  gcd = carl::gcd(gcd, *it);
42  }
43  return gcd;
44 }
45 
46 }
States if a type is a field.
Definition: typetraits.h:132
carl is the main namespace for the library.
Coeff content(const UnivariatePolynomial< Coeff > &p)
The content of a polynomial is the gcd of the coefficients of the normal part of a polynomial.
Definition: Content.h:22
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
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 is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
Definition: Interval.h:1462
This class represents a univariate polynomial with coefficients of an arbitrary type.
bool is_normal() const
Checks whether the polynomial is unit normal.
const std::vector< Coefficient > & coefficients() const &
Retrieves the coefficients defining this polynomial.