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