27 mpz_tdiv_q_2exp(mn_half, mn, 1);
29 if (mpz_cmp(
result, mn_half) > 0)
44 mpz_gcdext(g, result_um, result_vn, m, n);
45 if (0 != mpz_cmp_si(g, 1))
return false;
46 mpz_mul(result_mn, m, n);
47 mpz_mul(result_um, result_um, m);
48 mpz_mul(result_vn, result_vn, n);
62 mpz_init(result_coeff);
69 mpz_tdiv_q_2exp(mn_half, mn, 1);
79 for (; f !=
nullptr; f = f->
next)
86 mpz_mod(result_coeff, result_coeff, mn);
87 if (mpz_cmp(result_coeff, mn_half) > 0)
89 mpz_sub(result_coeff, result_coeff, mn);
98 for (; g !=
nullptr; g = g->
next)
105 mpz_mod(result_coeff, result_coeff, mn);
106 if (mpz_cmp(result_coeff, mn_half) > 0)
108 mpz_sub(result_coeff, result_coeff, mn);
155 mpz_clear(result_coeff);
196 for (; f !=
nullptr; f = f->next)
201 result->coeff =
CRA(R, f->coeff,
nullptr, um, vn, mn);
209 for (; g !=
nullptr; g = g->next)
214 result->coeff =
CRA(R,
nullptr, g->coeff, um, vn, mn);
219 if (f->comp < g->comp)
224 result->coeff =
CRA(R,
nullptr, g->coeff, um, vn, mn);
228 else if (f->comp > g->comp)
233 result->coeff =
CRA(R, f->coeff,
nullptr, um, vn, mn);
242 result->coeff =
CRA(R, f->coeff, g->coeff, um, vn, mn);
261 ERROR(
"matrices have different base rings");
267 ERROR(
"matrices have different shapes");
274 ERROR(
"expected polynomial ring over ZZ");
289 deg = R->degree_monoid()->make_one();
292 for (
int i = 0; i < f->
n_cols(); i++)
294 vec u =
CRA(S, f->
elem(i), g->
elem(i), um, vn, mn);
302 mpz_t a1, a2, u1, u2, q, h, mhalf, u2sqr, a2sqr;
306 mpz_init_set_si(u1, 0);
307 mpz_init_set_si(u2, 1);
308 mpz_init_set_si(q, 0);
309 mpz_init_set_si(h, 0);
314 mpz_tdiv_q_2exp(mhalf, m, 1);
318 mpz_mul(u2sqr, u2, u2);
320 if (mpz_cmp(u2sqr, mhalf) >= 0)
327 mpz_mul(a2sqr, a2, a2);
329 if (mpz_cmp(a2sqr, mhalf) < 0)
338 mpz_fdiv_q(q, a1, a2);
339 mpz_submul(a1, q, a2);
340 mpz_submul(u1, q, u2);
364 mpq_init(result_coeff);
372 for (; f !=
nullptr; f = f->
next)
385 mpq_clear(result_coeff);
394 for (; f !=
nullptr; f = f->next)
static bool computeMultipliers(mpz_srcptr m, mpz_srcptr n, mpz_t result_um, mpz_t result_vn, mpz_t result_mn)
static bool ratConversion(mpz_srcptr a, mpz_srcptr m, mpq_t result)
static ring_elem CRA(const PolyRing *R, const ring_elem f, const ring_elem g, mpz_srcptr um, mpz_srcptr vn, mpz_srcptr mn)
static void CRA0(mpz_srcptr a, mpz_srcptr b, mpz_srcptr um, mpz_srcptr vn, mpz_srcptr mn, mpz_t result)
bool is_equal(const FreeModule *F) const
Engine-side free module R^n over a Ring.
const_monomial degree_shift() const
const Ring * get_ring() const
ring_elem elem(int i, int j) const
const FreeModule * rows() const
const FreeModule * cols() const
void set_column(int c, vec v)
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
int compare(int nslots, const_monomial m, const_monomial n) const
void copy(const_monomial m, monomial result) const
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
virtual const PolyRing * cast_to_PolyRing() const
Concrete PolyRingFlat subclass implementing ordinary commutative polynomial rings K[x_1,...
const Ring * getCoefficientRing() const
virtual const Monoid * getMonoid() const
virtual FreeModule * make_FreeModule() const
virtual ring_elem from_int(mpz_srcptr n) const =0
virtual bool from_rational(const mpq_srcptr q, ring_elem &result) const =0
vec new_vec() const
vector operations ////////////////////
ChineseRemainder — CRT lifting and rational reconstruction primitives.
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
FreeModule — finite-rank free module R^n, the type-level anchor for every Matrix.
VALGRIND_MAKE_MEM_DEFINED & result(result)
MatrixConstructor — the mutable builder that produces an immutable Matrix.
Matrix — the engine's immutable homomorphism F -> G between free modules.
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
Concrete commutative PolyRing — standard polynomial ring inheriting from PolyRingFlat.
Ring — the legacy abstract base class for every coefficient and polynomial ring.
Singly linked-list node carrying one term of a polynomial-ring element.
Engine-wide stylistic constants: LT / EQ / GT codes, INTSIZE, GEOHEAP_SIZE.
mpz_srcptr get_mpz() const