1 #ifndef GINAC_UPOLY_NORMALIZE_TCC
2 #define GINAC_UPOLY_NORMALIZE_TCC
4 #include "ring_traits.hpp"
10 /// Make the univariate polynomial @a a \in F[x] unit normal.
11 /// F should be a field.
12 /// Returns true if the polynomial @x is already unit normal, and false
14 static bool normalize_in_field(umodpoly& a, cln::cl_MI* content_ = 0)
18 if (lcoeff(a) == the_one(a[0])) {
20 *content_ = the_one(a[0]);
24 const cln::cl_MI lc_1 = recip(lcoeff(a));
25 for (std::size_t k = a.size(); k-- != 0; )
32 /// Make the univariate polynomial @a x unit normal. This version is used
33 /// for rings which are not fields.
34 /// Returns true if the polynomial @x is already unit normal, and false
36 template<typename T> bool
37 normalize_in_ring(T& x, typename T::value_type* content_ = 0, int* unit_ = 0)
39 typedef typename T::value_type ring_t;
40 static const ring_t one(1);
44 bool something_changed = false;
45 if (minusp(lcoeff(x))) {
46 something_changed = true;
49 for (std::size_t i = x.size(); i-- != 0; )
57 return something_changed;
59 return false; // initial polynomial was unit normal
62 // Compute the gcd of coefficients
63 ring_t content = lcoeff(x);
64 // We want this function to be fast when applied to unit normal
65 // polynomials. Hence we start from the leading coefficient.
66 for (std::size_t i = x.size() - 1; i-- != 0; ) {
70 return something_changed;
72 content = gcd(x[i], content);
78 return something_changed;
81 for (std::size_t i = x.size(); i-- != 0; )
82 x[i] = exquo(x[i], content);
86 return false; // initial polynomial was not unit normal
91 #endif // GINAC_UPOLY_NORMALIZE_TCC