3 * Functions to normalize polynomials in a field. */
6 * GiNaC Copyright (C) 1999-2022 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef GINAC_UPOLY_NORMALIZE_H
24 #define GINAC_UPOLY_NORMALIZE_H
27 #include "ring_traits.h"
32 bool normalize_in_field(umodpoly& a, cln::cl_MI* content_ = nullptr);
34 /// Make the univariate polynomial @a x unit normal. This version is used
35 /// for rings which are not fields.
36 /// Returns true if the polynomial @x is already unit normal, and false
38 template<typename T> bool
39 normalize_in_ring(T& x, typename T::value_type* content_ = nullptr, int* unit_ = nullptr)
41 typedef typename T::value_type ring_t;
42 static const ring_t one(1);
46 bool something_changed = false;
47 if (minusp(lcoeff(x))) {
48 something_changed = true;
51 for (std::size_t i = x.size(); i-- != 0; )
59 return something_changed;
61 return false; // initial polynomial was unit normal
64 // Compute the gcd of coefficients
65 ring_t content = lcoeff(x);
66 // We want this function to be fast when applied to unit normal
67 // polynomials. Hence we start from the leading coefficient.
68 for (std::size_t i = x.size() - 1; i-- != 0; ) {
72 return something_changed;
74 content = gcd(x[i], content);
80 return something_changed;
83 for (std::size_t i = x.size(); i-- != 0; )
84 x[i] = exquo(x[i], content);
88 return false; // initial polynomial was not unit normal
93 #endif // GINAC_UPOLY_NORMALIZE_H