carl  24.04
Computer ARithmetic Library
GCD.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../MultivariatePolynomial.h"
4 #include "../UnivariatePolynomial.h"
6 #include "VarInfo.h"
7 
8 namespace carl {
9  template<typename C, typename O, typename P>
10  MultivariatePolynomial<C,O,P> gcd(const MultivariatePolynomial<C,O,P>& a, const MultivariatePolynomial<C,O,P>& b);
11 
12  template<typename Coeff>
13  UnivariatePolynomial<Coeff> gcd(const UnivariatePolynomial<Coeff>& a, const UnivariatePolynomial<Coeff>& b);
14 }
15 
16 #include "GCD_multivariate.h"
17 #include "GCD_univariate.h"
18 #include "PrimitiveEuclidean.h"
19 
20 namespace carl {
21 
22 template<typename C, typename O, typename P>
24  static_assert(is_field_type<C>::value, "Only implemented for field coefficients");
25  assert(!is_zero(a));
26  assert(!is_zero(b));
27  if (b.is_constant()) return Term<C>(C(1));
28  return Term<C>(C(1), gcd(a, b.monomial()));
29 }
30 
31 template<typename C, typename O, typename P>
33  return gcd(b, a);
34 }
35 
36 template<typename C, typename O, typename P>
38  if (!b) return nullptr;
39  assert(!is_zero(a));
40  auto varinfo = carl::vars_info(a,false);
41  std::vector<std::pair<Variable, exponent>> vepairs;
42  for (const auto& ve : *b) {
43  if (varinfo.var(ve.first)->num_occurences() == a.nr_terms()) {
44  vepairs.push_back(ve.first, std::min(varinfo.var(ve.first)->min_degree(), ve.second));
45  }
46  }
47  return createMonomial(std::move(vepairs));
48 }
49 
50 template<typename C, typename O, typename P>
52  return gcd(b, a);
53 }
54 
55 }
States if a type is a field.
Definition: typetraits.h:132
carl is the main namespace for the library.
Monomial::Arg createMonomial(T &&... t)
Definition: MonomialPool.h:168
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
VarsInfo< MultivariatePolynomial< Coeff, Ordering, Policies > > vars_info(const MultivariatePolynomial< Coeff, Ordering, Policies > &poly, bool collect_coeff=false)
Definition: VarInfo.h:63
The general-purpose multivariate polynomial class.
std::size_t nr_terms() const
Calculate the number of terms.
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
bool is_constant() const
Checks whether the monomial is a constant.
Definition: Term.h:127
Monomial::Arg & monomial()
Get the monomial.
Definition: Term.h:91