* Chinese remainder algorithm. */
/*
- * GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <numeric> // std::accumulate
#include <cln/integer.h>
+#include <cln/integer_ring.h>
+#include <cln/rational.h>
+#include <cln/rational_ring.h>
namespace GiNaC {
{
static const cln::cl_I n1(1);
const numeric icont_ = A.integer_content();
- const cln::cl_I icont = cln::the<cln::cl_I>(icont_.to_cl_N());
- if (icont != 1) {
- Apr = (A/icont_).expand();
- return icont;
+ GINAC_ASSERT(cln::instanceof(icont_.to_cl_N(), cln::cl_RA_ring));
+ if (cln::instanceof(icont_.to_cl_N(), cln::cl_I_ring)) {
+ const cln::cl_I icont = cln::the<cln::cl_I>(icont_.to_cl_N());
+ if (icont != 1) {
+ Apr = (A/icont_).expand();
+ return icont;
+ } else {
+ Apr = A;
+ return n1;
+ }
} else {
- Apr = A;
+ Apr = (A/icont_).expand();
+ // A is a polynomial over rationals, so GCD is defined
+ // up to arbitrary rational number.
return n1;
}
}
const cln::cl_I b_lc = integer_lcoeff(B, vars);
const cln::cl_I g_lc = cln::gcd(a_lc, b_lc);
- const ex& x(vars.back());
exp_vector_t n = std::min(degree_vector(A, vars), degree_vector(B, vars));
const int nTot = std::accumulate(n.begin(), n.end(), 0);
const cln::cl_I A_max_coeff = to_cl_I(A.max_coefficient());
Cp = (Cp*numeric(nlc)).expand().smod(pnum);
exp_vector_t cp_deg = degree_vector(Cp, vars);
if (zerop(cp_deg))
- return numeric(g_lc);
+ return numeric(c);
if (zerop(q)) {
H = Cp;
n = cp_deg;