carl  24.04
Computer ARithmetic Library
GCD_Term.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "GCD_Monomial.h"
4 
5 #include "../Term.h"
6 
7 namespace carl {
8 
9 /**
10  * Calculates the gcd of (t1, t2).
11  * If t1 or t2 is zero, undefined.
12  * @param t1 first term
13  * @param t2 second term
14  * @return gcd of t1 and t2.
15  */
16 template<typename Coeff>
17 Term<Coeff> gcd(const Term<Coeff>& t1, const Term<Coeff>& t2) {
18  static_assert(is_field_type<Coeff>::value, "Not yet defined for other coefficients");
19  assert(!carl::is_zero(t1));
20  assert(!carl::is_zero(t2));
21  if (t1.is_constant() || t2.is_constant()) {
22  return Term<Coeff>(Coeff(carl::gcd(t1.coeff(), t2.coeff())));
23  }
24  return Term<Coeff>(
25  Coeff(carl::gcd(t1.coeff(), t2.coeff())),
26  carl::gcd(t1.monomial(), t2.monomial())
27  );
28 }
29 }
30 
31 }
States if a type is a field.
Definition: typetraits.h:132
carl is the main namespace for the library.
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
Coefficient & coeff()
Get the coefficient.
Definition: Term.h:80
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