3 * Function to calculate the pseudo-remainder. */
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_POLYNOMIAL_PREM_H
24 #define GINAC_POLYNOMIAL_PREM_H
28 #include "remainder.h"
32 /// Compute the pseudo-remainder of univariate polynomials @a a and @a b
33 /// Pseudo remainder \f$r(x)\f$ is defined as
34 /// \f$\beta^l a(x) = b(x) q(x) + r(x) \f$, where \f$\beta\f$ is leading
35 /// coefficient of \f$b(x)\f$ and \f$l = degree(a) - degree(b) + 1\f$
36 /// FIXME: this implementation is extremely dumb.
37 template<typename T> bool pseudoremainder(T& r, const T& a, const T& b)
39 typedef typename T::value_type ring_t;
40 bug_on(b.size() == 0, "division by zero");
41 if (a.size() == 1 && b.size() == 1) {
49 if (degree(b) > degree(a)) {
54 const ring_t one = get_ring_elt(b[0], 1);
55 const std::size_t l = degree(a) - degree(b) + 1;
56 const ring_t blcoeff = lcoeff(b);
57 const ring_t b_lth = expt_pos(blcoeff, l);
59 return remainder_in_ring(r, a, b);
63 return remainder_in_ring(r, a_, b);
68 #endif // GINAC_POLYNOMIAL_PREM_H