uratpoly.cpp
2 
3 namespace SymEngine
4 {
5 
6 URatPoly::URatPoly(const RCP<const Basic> &var, URatDict &&dict)
8  var, std::move(dict)){SYMENGINE_ASSIGN_TYPEID()
9  SYMENGINE_ASSERT(is_canonical(get_poly()))}
10 
11  hash_t URatPoly::__hash__() const
12 {
13  hash_t seed = SYMENGINE_URATPOLY;
14 
15  seed += get_var()->hash();
16  for (const auto &it : get_poly().dict_) {
17  hash_t temp = SYMENGINE_URATPOLY;
18  hash_combine<unsigned int>(temp, it.first);
19  hash_combine<long long int>(temp, mp_get_si(get_num(it.second)));
20  hash_combine<long long int>(temp, mp_get_si(get_den(it.second)));
21  seed += temp;
22  }
23  return seed;
24 }
25 
26 bool divides_upoly(const URatPoly &a, const URatPoly &b,
27  const Ptr<RCP<const URatPoly>> &out)
28 {
29  if (!(a.get_var()->__eq__(*b.get_var())))
30  throw SymEngineException("Error: variables must agree.");
31 
32  auto a_poly = a.get_poly();
33  auto b_poly = b.get_poly();
34  if (a_poly.size() == 0)
35  return false;
36 
37  map_uint_mpq res;
38  URatDict tmp;
39  rational_class q, r;
40  unsigned int a_deg, b_deg;
41 
42  while (b_poly.size() >= a_poly.size()) {
43  a_deg = a_poly.degree();
44  b_deg = b_poly.degree();
45  q = b_poly.get_lc() / a_poly.get_lc();
46  res[b_deg - a_deg] = q;
47  URatDict tmp = URatDict(map_uint_mpq{{b_deg - a_deg, q}});
48  b_poly -= (a_poly * tmp);
49  }
50 
51  if (b_poly.empty()) {
52  *out = URatPoly::from_dict(a.get_var(), std::move(res));
53  return true;
54  } else {
55  return false;
56  }
57 }
58 
59 } // namespace SymEngine
hash_t __hash__() const override
Definition: uratpoly.cpp:11
URatPoly(const RCP< const Basic > &var, URatDict &&dict)
Constructor of URatPoly class.
Definition: uratpoly.cpp:6
T move(T... args)
Main namespace for SymEngine package.
Definition: add.cpp:19
STL namespace.