cancel.h
1 #ifndef SYMENGINE_CANCEL_H
2 #define SYMENGINE_CANCEL_H
3 
4 #include <symengine/basic.h>
5 #include <symengine/polys/basic_conversions.h>
6 
7 namespace SymEngine
8 {
9 // Declaration of cancel function
10 template <typename Poly>
11 inline void cancel(const RCP<const Basic> &numer, const RCP<const Basic> &denom,
12  const Ptr<RCP<const Poly>> &result_numer,
13  const Ptr<RCP<const Poly>> &result_denom,
14  const Ptr<RCP<const Poly>> &common)
15 {
16  // Converting basic to Poly
17  umap_basic_num numer_gens = _find_gens_poly(numer);
18  umap_basic_num denom_gens = _find_gens_poly(denom);
19 
20  if (numer_gens.size() != 1 && denom_gens.size() != 1) {
21  // only considering univariate here
22  return;
23  }
24  RCP<const Basic> numer_var = numer_gens.begin()->first;
25  RCP<const Basic> denom_var = denom_gens.begin()->first;
26 
27  RCP<const Poly> numer_poly = from_basic<Poly>(numer, numer_var);
28  RCP<const Poly> denom_poly = from_basic<Poly>(denom, denom_var);
29 
30  // Finding common factors of numer_poly and denom_poly
31  RCP<const Poly> gcd_poly = gcd_upoly(*numer_poly, *denom_poly);
32 
33  // Dividing both by common factors
34  divides_upoly(*gcd_poly, *numer_poly, outArg(*result_numer));
35  divides_upoly(*gcd_poly, *denom_poly, outArg(*result_denom));
36  *common = gcd_poly;
37 }
38 } // namespace SymEngine
39 #endif // SYMENGINE_CANCEL_H
The base class for SymEngine.
Main namespace for SymEngine package.
Definition: add.cpp:19