From ec3114459ee5a4074dd84956d30b507133ce3c0a Mon Sep 17 00:00:00 2001 From: Mike Stillman Date: Tue, 1 Jun 2021 21:00:24 -0400 Subject: [PATCH] This commit renames some types: poly, poly_iter, poly_constructor, some of which occur in 2-3 different, distinct classes. e.g. poly has become GBF4Polynomial, ResPolynomial, TowerPolynomial, ARingTowerPolynomial. This hopefully addresses git issue #2108 --- M2/Macaulay2/e/aring-tower.cpp | 54 +-- M2/Macaulay2/e/aring-tower.hpp | 104 +++--- M2/Macaulay2/e/dpoly.cpp | 312 +++++++++--------- M2/Macaulay2/e/dpoly.hpp | 222 ++++++------- M2/Macaulay2/e/f4/f4-m2-interface.cpp | 6 +- M2/Macaulay2/e/f4/f4-m2-interface.hpp | 8 +- M2/Macaulay2/e/f4/f4-types.hpp | 4 +- M2/Macaulay2/e/f4/f4.cpp | 4 +- M2/Macaulay2/e/gb-default.cpp | 2 + M2/Macaulay2/e/gb-test1.cpp | 2 + M2/Macaulay2/e/ringelem.hpp | 2 +- .../res-f4-computation.cpp | 6 +- .../res-f4-m2-interface.cpp | 22 +- .../res-f4-m2-interface.hpp | 6 +- M2/Macaulay2/e/schreyer-resolution/res-f4.cpp | 6 +- .../e/schreyer-resolution/res-poly-ring.cpp | 20 +- .../e/schreyer-resolution/res-poly-ring.hpp | 54 +-- .../res-schreyer-frame.cpp | 8 +- .../res-schreyer-frame.hpp | 6 +- M2/Macaulay2/e/tower.cpp | 120 +++---- 20 files changed, 487 insertions(+), 481 deletions(-) diff --git a/M2/Macaulay2/e/aring-tower.cpp b/M2/Macaulay2/e/aring-tower.cpp index 75ba38bbfd3..3a14db0b367 100644 --- a/M2/Macaulay2/e/aring-tower.cpp +++ b/M2/Macaulay2/e/aring-tower.cpp @@ -65,20 +65,20 @@ const ARingTower *ARingTower::create(const ARingTower &R, // Allocation ///// /////////////////// // TODO: what is the contract here???!! -poly ARingTower::alloc_poly_n(int deg) const +ARingPolynomial ARingTower::alloc_poly_n(int deg) const // if elems == 0, then set all coeffs to 0. { - poly result = new poly_struct; - result->polys = new poly[deg + 1]; + ARingPolynomial result = new ARingPolynomialStruct; + result->polys = new ARingPolynomial[deg + 1]; result->deg = deg; result->len = deg + 1; for (int i = 0; i <= deg; i++) result->polys[i] = 0; return result; } -poly ARingTower::alloc_poly_0(int deg) const +ARingPolynomial ARingTower::alloc_poly_0(int deg) const { - poly result = new poly_struct; + ARingPolynomial result = new ARingPolynomialStruct; result->coeffs = new ARingZZpFFPACK::ElementType[deg + 1]; result->deg = deg; result->len = deg + 1; @@ -86,7 +86,7 @@ poly ARingTower::alloc_poly_0(int deg) const return result; } -void ARingTower::dealloc_poly(poly &f) const +void ARingTower::dealloc_poly(ARingPolynomial &f) const // only f is freed, not any pointers in the array of f { if (f == 0) return; @@ -95,7 +95,7 @@ void ARingTower::dealloc_poly(poly &f) const f = 0; } -void ARingTower::clear(int level, poly &f) const +void ARingTower::clear(int level, ARingPolynomial &f) const // free all space associated to f, set f to 0. { if (f == 0) return; @@ -113,7 +113,7 @@ void ARingTower::clear(int level, poly &f) const f = 0; } -void ARingTower::reset_degree(poly &f) const +void ARingTower::reset_degree(ARingPolynomial &f) const { if (f == 0) return; int fdeg = f->deg; @@ -127,10 +127,10 @@ void ARingTower::reset_degree(poly &f) const dealloc_poly(f); // sets f to 0 } -poly ARingTower::copy(int level, const poly f) const +ARingPolynomial ARingTower::copy(int level, const ARingPolynomial f) const { if (f == 0) return 0; - poly result = alloc_poly_n(f->deg); + ARingPolynomial result = alloc_poly_n(f->deg); if (level == 0) for (int i = 0; i <= f->deg; i++) result->coeffs[i] = f->coeffs[i]; else @@ -140,13 +140,13 @@ poly ARingTower::copy(int level, const poly f) const } // TODO: should increase_capacity set the degree?? I don't think so... -void ARingTower::increase_capacity(int newdeg, poly &f) const +void ARingTower::increase_capacity(int newdeg, ARingPolynomial &f) const { assert(f != 0); if (f->len <= newdeg) { - poly *newelems = newarray(poly, newdeg + 1); - poly *fp = f->polys; + ARingPolynomial *newelems = newarray(ARingPolynomial, newdeg + 1); + ARingPolynomial *fp = f->polys; for (int i = 0; i <= f->deg; i++) newelems[i] = fp[i]; for (int i = f->deg + 1; i < newdeg + 1; i++) newelems[i] = 0; delete[] fp; @@ -182,7 +182,7 @@ void ARingTower::extensions_text_out(buffer &o) const } namespace { - int n_nonzero_terms(int level, poly f) + int n_nonzero_terms(int level, ARingPolynomial f) { if (f == 0) return 0; int nterms = 0; @@ -200,7 +200,7 @@ namespace { } }; -bool ARingTower::is_one(int level, const poly f) const +bool ARingTower::is_one(int level, const ARingPolynomial f) const { if (f == 0) return false; if (f->deg != 0) return false; @@ -212,7 +212,7 @@ bool ARingTower::is_one(int level, const poly f) const void ARingTower::elem_text_out(buffer &o, int level, - const poly f, + const ARingPolynomial f, bool p_one, bool p_plus, bool p_parens) const @@ -286,25 +286,25 @@ void ARingTower::elem_text_out(buffer &o, } } -poly ARingTower::var(int level, int v) const +ARingPolynomial ARingTower::var(int level, int v) const // make the variable v (but at level 'level') { if (v > level) return 0; int which = (v == 0 ? 1 : 0); - poly result = + ARingPolynomial result = alloc_poly_0(which); // TODO: check that this initializes elements to 0 result->coeffs[which] = 1; for (int i = 1; i <= level; i++) { which = (i == v ? 1 : 0); - poly a = result; + ARingPolynomial a = result; result = alloc_poly_n(which); result->polys[which] = a; } return result; } -bool ARingTower::is_equal(int level, const poly f, const poly g) const +bool ARingTower::is_equal(int level, const ARingPolynomial f, const ARingPolynomial g) const { if (f == 0) { @@ -321,14 +321,14 @@ bool ARingTower::is_equal(int level, const poly f, const poly g) const return true; } // level > 0 - poly *fp = f->polys; - poly *gp = g->polys; + ARingPolynomial *fp = f->polys; + ARingPolynomial *gp = g->polys; for (int i = 0; i <= f->deg; i++) if (!is_equal(level - 1, fp[i], gp[i])) return false; return true; } -void ARingTower::add_in_place(int level, poly &f, const poly g) const +void ARingTower::add_in_place(int level, ARingPolynomial &f, const ARingPolynomial g) const { if (g == 0) return; if (f == 0) @@ -353,7 +353,7 @@ void ARingTower::add_in_place(int level, poly &f, const poly g) const reset_degree(f); } -void ARingTower::negate_in_place(int level, poly &f) const +void ARingTower::negate_in_place(int level, ARingPolynomial &f) const { if (f == 0) return; int deg = f->deg; @@ -369,7 +369,7 @@ void ARingTower::negate_in_place(int level, poly &f) const } } -void ARingTower::subtract_in_place(int level, poly &f, const poly g) const +void ARingTower::subtract_in_place(int level, ARingPolynomial &f, const ARingPolynomial g) const { if (g == 0) return; if (f == 0) @@ -396,7 +396,7 @@ void ARingTower::subtract_in_place(int level, poly &f, const poly g) const } void ARingTower::mult_by_coeff(int level, - poly &f, + ARingPolynomial &f, const BaseCoefficientType &b) const { assert(!mBaseRing.is_zero(b)); @@ -415,7 +415,7 @@ void ARingTower::mult_by_coeff(int level, } } -void ARingTower::mult_by_coeff(poly &f, const BaseCoefficientType &b) const +void ARingTower::mult_by_coeff(ARingPolynomial &f, const BaseCoefficientType &b) const { if (f == 0) return; if (mBaseRing.is_zero(b)) diff --git a/M2/Macaulay2/e/aring-tower.hpp b/M2/Macaulay2/e/aring-tower.hpp index 8adfea596ad..e7a5a11ef20 100644 --- a/M2/Macaulay2/e/aring-tower.hpp +++ b/M2/Macaulay2/e/aring-tower.hpp @@ -16,9 +16,9 @@ namespace M2 { /** * \ingroup polynomialrings */ -typedef struct poly_struct *poly; +typedef struct ARingPolynomialStruct *ARingPolynomial; -struct poly_struct +struct ARingPolynomialStruct { int deg; int len; @@ -26,7 +26,7 @@ struct poly_struct { ARingZZpFFPACK::ElementType *coeffs; // long* ints; // array of integers. at level == 0 - poly *polys; // array of more ptrs to poly structs, at level > 0 + ARingPolynomial *polys; // array of more ptrs to poly structs, at level > 0 }; }; @@ -47,7 +47,7 @@ class ARingTower : public RingInterface typedef BaseRingType::ElementType BaseCoefficientType; static const RingID ringID = ring_tower_ZZp; - typedef poly ElementType; + typedef ARingPolynomial ElementType; typedef ElementType elem; ////////////////////////////// @@ -162,7 +162,7 @@ class ARingTower : public RingInterface result = a; else { - poly a1 = copy(mStartLevel, a); + ARingPolynomial a1 = copy(mStartLevel, a); add_in_place(mStartLevel, a1, b); result = a1; } @@ -209,7 +209,7 @@ class ARingTower : public RingInterface } // TODO: write this // f *= b, where b is an element in mBaseRing - void mult_by_coeff(poly &f, const BaseCoefficientType &b) const; + void mult_by_coeff(ARingPolynomial &f, const BaseCoefficientType &b) const; private: void extensions_text_out(buffer &o) const; // TODO: write this @@ -222,40 +222,40 @@ class ARingTower : public RingInterface bool p_parens) const; private: - bool is_one(int level, const poly f) const; // TODO: write this - bool is_equal(int level, const poly f, const poly g) const; + bool is_one(int level, const ARingPolynomial f) const; // TODO: write this + bool is_equal(int level, const ARingPolynomial f, const ARingPolynomial g) const; - poly alloc_poly_n(int deg) const; - poly alloc_poly_0(int deg) const; - void dealloc_poly(poly &f) const; + ARingPolynomial alloc_poly_n(int deg) const; + ARingPolynomial alloc_poly_0(int deg) const; + void dealloc_poly(ARingPolynomial &f) const; - poly copy(int level, const poly f) const; + ARingPolynomial copy(int level, const ARingPolynomial f) const; // possibly increase the capacity of 'f', to accommodate polynomials of degree // 'newdeg' - void increase_capacity(int newdeg, poly &f) const; + void increase_capacity(int newdeg, ARingPolynomial &f) const; // sets the (top level) degree of f to be correct. If f is the 0 poly, then f // is deallocated - void reset_degree(poly &f) const; + void reset_degree(ARingPolynomial &f) const; // Create a polynomial at level 'level', representing the variable 'v' // v should be in the range 0..mNumVars-1. If not, then the 0 elem is // returned. // ASSUMPTION: level >= v. If not, 0 is returned. - poly var(int level, int v) const; + ARingPolynomial var(int level, int v) const; // f += g. f and g should both be of level 'level' - void add_in_place(int level, poly &f, const poly g) const; + void add_in_place(int level, ARingPolynomial &f, const ARingPolynomial g) const; - void subtract_in_place(int level, poly &f, const poly g) const; + void subtract_in_place(int level, ARingPolynomial &f, const ARingPolynomial g) const; - void negate_in_place(int level, poly &f) const; + void negate_in_place(int level, ARingPolynomial &f) const; - void mult_by_coeff(int level, poly &f, const BaseCoefficientType &b) const; + void mult_by_coeff(int level, ARingPolynomial &f, const BaseCoefficientType &b) const; // free all space associated to f, set f to 0. - void clear(int level, poly &f) const; + void clear(int level, ARingPolynomial &f) const; private: const ARingZZpFFPACK &mBaseRing; @@ -372,7 +372,7 @@ class ARingTower : public RingInterface void from_ring_elem(ElementType &result, const ring_elem &a) const { - ElementType a1 = TOWER_VAL(a); + ElementType a1 = reinterpret_cast(a.poly_val); result = mRing.copy(mStartLevel, a1); } @@ -411,61 +411,61 @@ class ARingTower : public RingInterface ///////////////////////////////////// // Predicates /////////////////////// ///////////////////////////////////// - bool is_equal(int level, const poly f, const poly g); - bool is_zero(poly f) { return f == 0; } + bool is_equal(int level, const ARingPolynomial f, const ARingPolynomial g); + bool is_zero(ARingPolynomial f) { return f == 0; } ///////////////////////////////////// // Construction of new elements ///// ///////////////////////////////////// - poly copy(int level, const_poly f); - poly var(int level, int v); // make the variable v (but at level 'level') - poly from_long(int level, long c); // c should be reduced mod p + ARingPolynomial copy(int level, const_poly f); + ARingPolynomial var(int level, int v); // make the variable v (but at level 'level') + ARingPolynomial from_long(int level, long c); // c should be reduced mod p ///////////////////////////////////// // Private routines for arithmetic // ///////////////////////////////////// - void reset_degree_0(poly &f); // possibly sets f to 0 - void reset_degree_n(int level, poly &f); // ditto + void reset_degree_0(ARingPolynomial &f); // possibly sets f to 0 + void reset_degree_n(int level, ARingPolynomial &f); // ditto - void mult_by_coeff_0(poly &f, long b); - void mult_by_coeff_n(int level, poly &f, poly b); + void mult_by_coeff_0(ARingPolynomial &f, long b); + void mult_by_coeff_n(int level, ARingPolynomial &f, ARingPolynomial b); // f *= b. b should have level 'level-1'. - void make_monic_0(poly & f, long &result_multiplier); - void make_monic_n(int level, poly & f, poly &result_multiplier); + void make_monic_0(ARingPolynomial & f, long &result_multiplier); + void make_monic_n(int level, ARingPolynomial & f, ARingPolynomial &result_multiplier); - bool make_monic3(int level, poly & u1, poly &u2, poly &u3); + bool make_monic3(int level, ARingPolynomial & u1, ARingPolynomial &u2, ARingPolynomial &u3); - void add_in_place_0(poly &f, const poly g); - void add_in_place_n(int level, poly &f, const poly g); - void add_in_place(int level, poly &f, const poly g); + void add_in_place_0(ARingPolynomial &f, const ARingPolynomial g); + void add_in_place_n(int level, ARingPolynomial &f, const ARingPolynomial g); + void add_in_place(int level, ARingPolynomial &f, const ARingPolynomial g); - void subtract_in_place_0(poly &f, const poly g); - void subtract_in_place_n(int level, poly &f, const poly g); - void subtract_in_place(int level, poly &f, const poly g); + void subtract_in_place_0(ARingPolynomial &f, const ARingPolynomial g); + void subtract_in_place_n(int level, ARingPolynomial &f, const ARingPolynomial g); + void subtract_in_place(int level, ARingPolynomial &f, const ARingPolynomial g); - poly mult_0(const poly f, const poly g, bool reduce_by_extension); - poly mult_n(int level, const poly f, const poly g, bool reduce_by_extension); - poly mult(int level, const poly f, const poly g, bool reduce_by_extension); + ARingPolynomial mult_0(const ARingPolynomial f, const ARingPolynomial g, bool reduce_by_extension); + ARingPolynomial mult_n(int level, const ARingPolynomial f, const ARingPolynomial g, bool reduce_by_extension); + ARingPolynomial mult(int level, const ARingPolynomial f, const ARingPolynomial g, bool reduce_by_extension); - poly random_0(int deg); - poly random_n(int level, int deg); - poly random(int level, int deg); - poly random(int level); // obtains a random element, using only variables which are algebraic over the base + ARingPolynomial random_0(int deg); + ARingPolynomial random_n(int level, int deg); + ARingPolynomial random(int level, int deg); + ARingPolynomial random(int level); // obtains a random element, using only variables which are algebraic over the base - poly diff_0(const poly f); - poly diff_n(int level, int whichvar, const poly f); + ARingPolynomial diff_0(const ARingPolynomial f); + ARingPolynomial diff_n(int level, int whichvar, const ARingPolynomial f); - poly mult_by_int_0(long c, const poly f); - poly mult_by_int_n(int level, long c, const poly f); - poly mult_by_int(int level, long c, const poly f); + ARingPolynomial mult_by_int_0(long c, const ARingPolynomial f); + ARingPolynomial mult_by_int_n(int level, long c, const ARingPolynomial f); + ARingPolynomial mult_by_int(int level, long c, const ARingPolynomial f); ///////////////////////////////////// // Translation to/from other rings // ///////////////////////////////////// - void add_term(int level, poly &result, long coeff, exponents exp) const; // modifies result. + void add_term(int level, ARingPolynomial &result, long coeff, exponents exp) const; // modifies result. #endif // Local Variables: diff --git a/M2/Macaulay2/e/dpoly.cpp b/M2/Macaulay2/e/dpoly.cpp index f90e5ede9db..ffb68be2ab9 100644 --- a/M2/Macaulay2/e/dpoly.cpp +++ b/M2/Macaulay2/e/dpoly.cpp @@ -77,12 +77,12 @@ void ZZp_RANDOM(long charac, long &result) result = rawRandomInt(static_cast(charac)); } -void DPoly::initialize(long p, int nvars0, const_poly *ext0) +void DPoly::initialize(long p, int nvars0, const TowerPolynomial* ext0) { charac = p; nvars = nvars0; nlevels = nvars0; - extensions = newarray(poly, nlevels); + extensions = newarray(TowerPolynomial, nlevels); if (ext0 == 0) for (int i = 0; i < nlevels; i++) extensions[i] = 0; else @@ -92,7 +92,7 @@ void DPoly::initialize(long p, int nvars0, const_poly *ext0) down_level(i, nlevels - 1, extensions[i]); } } -DPoly::DPoly(long p, int nvars0, const_poly *ext0) +DPoly::DPoly(long p, int nvars0, const TowerPolynomial* ext0) { initialize(p, nvars0, ext0); } @@ -101,12 +101,12 @@ int DPoly::degree_of_extension(int level) { // if negative, then that variable is transcendental over lower vars if (level < 0 || level >= nlevels) return -1; - poly f = extensions[level]; + TowerPolynomial f = extensions[level]; if (f == 0) return -1; return f->deg; } -bool DPoly::down_level(int newlevel, int oldlevel, poly &f) +bool DPoly::down_level(int newlevel, int oldlevel, TowerPolynomial& f) { if (f == 0) return true; for (int i = oldlevel; i > newlevel; i--) @@ -116,7 +116,7 @@ bool DPoly::down_level(int newlevel, int oldlevel, poly &f) dealloc_poly(f); return false; } - poly g = f->arr.polys[0]; + TowerPolynomial g = f->arr.polys[0]; f->arr.polys[0] = 0; dealloc_poly(f); f = g; @@ -124,7 +124,7 @@ bool DPoly::down_level(int newlevel, int oldlevel, poly &f) return true; } -static int n_nonzero_terms(int level, const_poly f) +static int n_nonzero_terms(int level, const TowerPolynomial f) { if (f == 0) return 0; int nterms = 0; @@ -143,7 +143,7 @@ static int n_nonzero_terms(int level, const_poly f) void DPoly::elem_text_out(buffer &o, int level, - const poly f, + const TowerPolynomial f, bool p_one, bool p_plus, bool p_parens, @@ -230,7 +230,7 @@ void DPoly::extensions_text_out(buffer &o, M2_ArrayString names) const } } -void DPoly::increase_size_0(int newdeg, poly &f) +void DPoly::increase_size_0(int newdeg, TowerPolynomial& f) { assert(f != 0); if (f->len <= newdeg) @@ -246,13 +246,13 @@ void DPoly::increase_size_0(int newdeg, poly &f) } } -void DPoly::increase_size_n(int newdeg, poly &f) +void DPoly::increase_size_n(int newdeg, TowerPolynomial& f) { assert(f != 0); if (f->len <= newdeg) { - poly *newelems = newarray(poly, newdeg + 1); - poly *fp = f->arr.polys; + TowerPolynomial *newelems = newarray(TowerPolynomial, newdeg + 1); + TowerPolynomial *fp = f->arr.polys; for (int i = 0; i <= f->deg; i++) newelems[i] = fp[i]; for (int i = f->deg + 1; i < newdeg + 1; i++) newelems[i] = 0; deletearray(fp); @@ -262,11 +262,11 @@ void DPoly::increase_size_n(int newdeg, poly &f) } } -poly DPoly::alloc_poly_n(int deg, poly *elems) +TowerPolynomial DPoly::alloc_poly_n(int deg, TowerPolynomial *elems) // if elems == 0, then set all coeffs to 0. { - poly result = new poly_struct; - result->arr.polys = newarray(poly, deg + 1); + TowerPolynomial result = new TowerPolynomialStruct; + result->arr.polys = newarray(TowerPolynomial, deg + 1); result->deg = deg; result->len = deg + 1; if (elems == 0) @@ -276,9 +276,9 @@ poly DPoly::alloc_poly_n(int deg, poly *elems) return result; } -poly DPoly::alloc_poly_0(int deg, long *elems) +TowerPolynomial DPoly::alloc_poly_0(int deg, long *elems) { - poly result = new poly_struct; + TowerPolynomial result = new TowerPolynomialStruct; result->arr.ints = newarray_atomic(long, deg + 1); result->deg = deg; result->len = deg + 1; @@ -289,7 +289,7 @@ poly DPoly::alloc_poly_0(int deg, long *elems) return result; } -void DPoly::dealloc_poly(poly &f) +void DPoly::dealloc_poly(TowerPolynomial &f) // only f is freed, not any pointers in the array of f { if (f == 0) return; @@ -298,11 +298,11 @@ void DPoly::dealloc_poly(poly &f) f = 0; } -poly DPoly::read_poly_n(char *&str, int level) +TowerPolynomial DPoly::read_poly_n(char *&str, int level) { int len = 0; - poly *elems = newarray(poly, 100); - poly this_elem = 0; + TowerPolynomial *elems = newarray(TowerPolynomial, 100); + TowerPolynomial this_elem = 0; if (*str != '[') { fprintf(stderr, "expected '[', got %s\n", str); @@ -333,12 +333,12 @@ poly DPoly::read_poly_n(char *&str, int level) } // the only way to get here is if *str == ']'. Eat that char. str++; - poly result = DPoly::alloc_poly_n(len - 1, elems); + TowerPolynomial result = DPoly::alloc_poly_n(len - 1, elems); deletearray(elems); return result; } -poly DPoly::read_poly_0(char *&str) +TowerPolynomial DPoly::read_poly_0(char *&str) { int len = 0; long *elems = newarray_atomic(long, 100); @@ -375,18 +375,18 @@ poly DPoly::read_poly_0(char *&str) } // the only way to get here is if *str == ']'. Eat that char. str++; - poly result = DPoly::alloc_poly_0(len - 1, elems); + TowerPolynomial result = DPoly::alloc_poly_0(len - 1, elems); deletearray(elems); return result; } -poly DPoly::read_poly(char *&str, int level) +TowerPolynomial DPoly::read_poly(char *&str, int level) { if (level > 0) return read_poly_n(str, level); return read_poly_0(str); } -std::ostream &DPoly::append_to_stream(std::ostream &o, int level, const poly f) +std::ostream &DPoly::append_to_stream(std::ostream &o, int level, const TowerPolynomial f) { if (f == 0) o << "0"; @@ -403,7 +403,7 @@ std::ostream &DPoly::append_to_stream(std::ostream &o, int level, const poly f) } else { - poly *p = f->arr.polys; + TowerPolynomial *p = f->arr.polys; o << "["; for (int i = 0; i <= f->deg; i++) { @@ -414,7 +414,7 @@ std::ostream &DPoly::append_to_stream(std::ostream &o, int level, const poly f) } return o; } -char *DPoly::to_string(int level, const poly f) +char *DPoly::to_string(int level, const TowerPolynomial f) { std::ostringstream o; append_to_stream(o, level, f); @@ -425,7 +425,7 @@ char *DPoly::to_string(int level, const poly f) return result; } -void DPoly::display_poly(FILE *fil, int level, const poly f) +void DPoly::display_poly(FILE *fil, int level, const TowerPolynomial f) { if (f == 0) fprintf(fil, "0"); @@ -443,7 +443,7 @@ void DPoly::display_poly(FILE *fil, int level, const poly f) } else { - poly *p = f->arr.polys; + TowerPolynomial *p = f->arr.polys; // fprintf(fil, "[(%ld)", f->deg); fprintf(fil, "["); for (int i = 0; i <= f->deg; i++) @@ -455,8 +455,8 @@ void DPoly::display_poly(FILE *fil, int level, const poly f) } } -void dpoly(int level, const poly f) { DPoly::display_poly(stdout, level, f); } -bool DPoly::is_equal(int level, const poly f, const poly g) +void dpoly(int level, const TowerPolynomial f) { DPoly::display_poly(stdout, level, f); } +bool DPoly::is_equal(int level, const TowerPolynomial f, const TowerPolynomial g) { if (f == 0) { @@ -473,17 +473,17 @@ bool DPoly::is_equal(int level, const poly f, const poly g) return true; } // level > 0 - poly *fp = f->arr.polys; - poly *gp = g->arr.polys; + TowerPolynomial *fp = f->arr.polys; + TowerPolynomial *gp = g->arr.polys; for (int i = 0; i <= f->deg; i++) if (!is_equal(level - 1, fp[i], gp[i])) return false; return true; } -poly DPoly::copy(int level, const_poly f) +TowerPolynomial DPoly::copy(int level, const TowerPolynomial f) { if (f == 0) return 0; - poly result; + TowerPolynomial result; if (level == 0) { result = alloc_poly_0(f->deg); @@ -498,66 +498,66 @@ poly DPoly::copy(int level, const_poly f) return result; } -poly DPoly::from_long(int level, long c) +TowerPolynomial DPoly::from_long(int level, long c) { if (c == 0) return 0; - poly result = alloc_poly_0(0); + TowerPolynomial result = alloc_poly_0(0); result->arr.ints[0] = c; for (int i = 1; i <= level; i++) { - poly a = result; + TowerPolynomial a = result; result = alloc_poly_n(0); result->arr.polys[0] = a; } return result; } -poly DPoly::var(int level, int v) +TowerPolynomial DPoly::var(int level, int v) // make the variable v (but at level 'level') { if (v > level) return 0; int which = (v == 0 ? 1 : 0); - poly result = + TowerPolynomial result = alloc_poly_0(which); // TODO: check that this initializes elements to 0 result->arr.ints[which] = 1; for (int i = 1; i <= level; i++) { which = (i == v ? 1 : 0); - poly a = result; + TowerPolynomial a = result; result = alloc_poly_n(which); result->arr.polys[which] = a; } return result; } -poly DPoly::random_0(int deg) +TowerPolynomial DPoly::random_0(int deg) { if (deg < 0) deg = 3; // Take a random element of degree 0. - poly f = alloc_poly_0(deg); + TowerPolynomial f = alloc_poly_0(deg); for (int i = 0; i <= deg; i++) ZZp_RANDOM(charac, f->arr.ints[i]); reset_degree_0(f); // possibly modifies f, if it is zero. return f; } -poly DPoly::random_n(int level, int deg) +TowerPolynomial DPoly::random_n(int level, int deg) { if (deg < 0) deg = 3; // Take a random element of degree 0. - poly f = alloc_poly_n(deg); + TowerPolynomial f = alloc_poly_n(deg); for (int i = 0; i <= deg; i++) f->arr.polys[i] = random(level - 1); reset_degree_n(level, f); // possibly modifies f, if it is zero. return f; } -poly DPoly::random(int level, int deg) +TowerPolynomial DPoly::random(int level, int deg) { if (deg < 0) deg = 0; // Take a random element of degree 0. if (level == 0) return random_0(deg); return random_n(level, deg); } -poly DPoly::random(int level) +TowerPolynomial DPoly::random(int level) { return random(level, degree_of_extension(level)); } -int DPoly::compare(int level, poly f, poly g) +int DPoly::compare(int level, TowerPolynomial f, TowerPolynomial g) // returns -1 if f < g, 0 if f == g, and 1 if f > g // order used: first degree, then compare elements 0..charac-1 // 0 is the lowest @@ -592,7 +592,7 @@ int DPoly::compare(int level, poly f, poly g) return 0; } -bool DPoly::is_one(int level, poly f) +bool DPoly::is_one(int level, TowerPolynomial f) { if (f == 0) return false; if (f->deg != 0) return false; @@ -601,7 +601,7 @@ bool DPoly::is_one(int level, poly f) else return is_one(level - 1, f->arr.polys[0]); } -void DPoly::negate_in_place(int level, poly &f) +void DPoly::negate_in_place(int level, TowerPolynomial &f) { if (f == 0) return; if (level == 0) @@ -614,13 +614,13 @@ void DPoly::negate_in_place(int level, poly &f) else { int deg = f->deg; - poly *p = f->arr.polys; + TowerPolynomial *p = f->arr.polys; for (int i = 0; i <= deg; i++) if (p[i] != 0) negate_in_place(level - 1, p[i]); } } -void DPoly::reset_degree_0(poly &f) +void DPoly::reset_degree_0(TowerPolynomial &f) { int fdeg = f->deg; for (int j = fdeg; j >= 0; --j) @@ -632,7 +632,7 @@ void DPoly::reset_degree_0(poly &f) // at this point, everything is 0! dealloc_poly(f); // sets f to 0 } -void DPoly::reset_degree_n(int level, poly &f) +void DPoly::reset_degree_n(int level, TowerPolynomial &f) { int fdeg = f->deg; for (int j = fdeg; j >= 0; --j) @@ -645,7 +645,7 @@ void DPoly::reset_degree_n(int level, poly &f) dealloc_poly(f); // sets f to 0 } -void DPoly::add_term(int level, poly &result, long coeff, exponents exp) const +void DPoly::add_term(int level, TowerPolynomial &result, long coeff, exponents exp) const { // modifies result. // exp is an array [0..level-1] of exponent values for each variable @@ -666,7 +666,7 @@ void DPoly::add_term(int level, poly &result, long coeff, exponents exp) const add_term(level - 1, result->arr.polys[e], coeff, exp + 1); } -void DPoly::add_in_place_0(poly &f, const poly g) +void DPoly::add_in_place_0(TowerPolynomial &f, const TowerPolynomial g) { int i; if (g == 0) return; @@ -687,7 +687,7 @@ void DPoly::add_in_place_0(poly &f, const poly g) reset_degree_0(f); } -void DPoly::add_in_place_n(int level, poly &f, const poly g) +void DPoly::add_in_place_n(int level, TowerPolynomial &f, const TowerPolynomial g) { int i; if (g == 0) return; @@ -718,7 +718,7 @@ void DPoly::add_in_place_n(int level, poly &f, const poly g) } } -void DPoly::add_in_place(int level, poly &f, const poly g) +void DPoly::add_in_place(int level, TowerPolynomial &f, const TowerPolynomial g) { if (level == 0) add_in_place_0(f, g); @@ -726,7 +726,7 @@ void DPoly::add_in_place(int level, poly &f, const poly g) add_in_place_n(level, f, g); } -void DPoly::subtract_in_place_0(poly &f, const poly g) +void DPoly::subtract_in_place_0(TowerPolynomial &f, const TowerPolynomial g) { int i; if (g == 0) return; @@ -758,7 +758,7 @@ void DPoly::subtract_in_place_0(poly &f, const poly g) } } -void DPoly::subtract_in_place_n(int level, poly &f, const poly g) +void DPoly::subtract_in_place_n(int level, TowerPolynomial &f, const TowerPolynomial g) { int i; if (g == 0) return; @@ -790,7 +790,7 @@ void DPoly::subtract_in_place_n(int level, poly &f, const poly g) } } -void DPoly::subtract_in_place(int level, poly &f, const poly g) +void DPoly::subtract_in_place(int level, TowerPolynomial &f, const TowerPolynomial g) { if (level == 0) subtract_in_place_0(f, g); @@ -798,10 +798,10 @@ void DPoly::subtract_in_place(int level, poly &f, const poly g) subtract_in_place_n(level, f, g); } -poly DPoly::mult_0(const poly f, const poly g, bool reduce_by_extension) +TowerPolynomial DPoly::mult_0(const TowerPolynomial f, const TowerPolynomial g, bool reduce_by_extension) { if (f == 0 || g == 0) return 0; - poly result = alloc_poly_0(f->deg + g->deg); + TowerPolynomial result = alloc_poly_0(f->deg + g->deg); for (int i = 0; i <= f->deg; i++) { @@ -814,22 +814,22 @@ poly DPoly::mult_0(const poly f, const poly g, bool reduce_by_extension) remainder(0, result, extensions[0]); return result; } -poly DPoly::mult_n(int level, - const poly f, - const poly g, +TowerPolynomial DPoly::mult_n(int level, + const TowerPolynomial f, + const TowerPolynomial g, bool reduce_by_extension) { if (f == 0 || g == 0) return 0; - poly result = alloc_poly_n(f->deg + g->deg); + TowerPolynomial result = alloc_poly_n(f->deg + g->deg); for (int i = 0; i <= f->deg; i++) { - poly a = f->arr.polys[i]; + TowerPolynomial a = f->arr.polys[i]; if (a != 0) for (int j = 0; j <= g->deg; j++) { - poly b = g->arr.polys[j]; - poly c = mult(level - 1, a, b, true); + TowerPolynomial b = g->arr.polys[j]; + TowerPolynomial c = mult(level - 1, a, b, true); if (c != 0) { add_in_place(level - 1, result->arr.polys[i + j], c); @@ -842,23 +842,23 @@ poly DPoly::mult_n(int level, remainder(level, result, extensions[level]); return result; } -poly DPoly::mult(int level, - const poly f, - const poly g, +TowerPolynomial DPoly::mult(int level, + const TowerPolynomial f, + const TowerPolynomial g, bool reduce_by_extension) { if (level == 0) return mult_0(f, g, reduce_by_extension); return mult_n(level, f, g, reduce_by_extension); } -poly DPoly::invert(int level, const poly a) +TowerPolynomial DPoly::invert(int level, const TowerPolynomial a) { // plan: compute the extended gcd of a and extensions[level] // as univariate polynomials (at level 'level'). // either return 0, if the gcd returned was not 1, or return // result_u. - poly u, v; - poly g = gcd_coefficients(level, a, extensions[level], u, v); + TowerPolynomial u, v; + TowerPolynomial g = gcd_coefficients(level, a, extensions[level], u, v); if (!is_one(level, g)) { dealloc_poly(u); @@ -868,7 +868,7 @@ poly DPoly::invert(int level, const poly a) return u; } -void DPoly::mult_by_coeff_0(poly &f, long b) +void DPoly::mult_by_coeff_0(TowerPolynomial &f, long b) { if (f == 0) return; long *p = f->arr.ints; @@ -882,10 +882,10 @@ void DPoly::mult_by_coeff_0(poly &f, long b) p++; } } -void DPoly::mult_by_coeff_n(int level, poly &f, poly b) +void DPoly::mult_by_coeff_n(int level, TowerPolynomial &f, TowerPolynomial b) { if (f == 0) return; - poly *p = f->arr.polys; + TowerPolynomial *p = f->arr.polys; long deg = f->deg; if (b == 0) { @@ -898,7 +898,7 @@ void DPoly::mult_by_coeff_n(int level, poly &f, poly b) p++; } } -void DPoly::make_monic_0(poly &f, long &result_multiplier) +void DPoly::make_monic_0(TowerPolynomial &f, long &result_multiplier) { if (f == 0) return; long *p = f->arr.ints; @@ -908,17 +908,17 @@ void DPoly::make_monic_0(poly &f, long &result_multiplier) mult_by_coeff_0(f, b); result_multiplier = b; } -void DPoly::make_monic_n(int level, poly &f, poly &result_multiplier) +void DPoly::make_monic_n(int level, TowerPolynomial &f, TowerPolynomial &result_multiplier) { if (f == 0) return; - poly *p = f->arr.polys; - poly a = p[f->deg]; - poly b = invert(level - 1, a); + TowerPolynomial *p = f->arr.polys; + TowerPolynomial a = p[f->deg]; + TowerPolynomial b = invert(level - 1, a); mult_by_coeff_n(level, f, b); result_multiplier = b; } -void DPoly::make_monic(int level, poly &f) +void DPoly::make_monic(int level, TowerPolynomial &f) { if (f == 0) return; if (level == 0) @@ -928,13 +928,13 @@ void DPoly::make_monic(int level, poly &f) } else { - poly not_used; + TowerPolynomial not_used; make_monic_n(level, f, not_used); dealloc_poly(not_used); } } -bool DPoly::make_monic3(int level, poly &u1, poly &u2, poly &u3) +bool DPoly::make_monic3(int level, TowerPolynomial &u1, TowerPolynomial &u2, TowerPolynomial &u3) // let c be the inverse of the lead coefficient of u3. // return false if this lead coeff is not invertible // else return true @@ -952,7 +952,7 @@ bool DPoly::make_monic3(int level, poly &u1, poly &u2, poly &u3) } else { - poly c = 0; + TowerPolynomial c = 0; make_monic_n(level, u3, c); if (c == 0) return false; mult_by_coeff_n(level, u1, c); @@ -962,7 +962,7 @@ bool DPoly::make_monic3(int level, poly &u1, poly &u2, poly &u3) return true; } -poly DPoly::division_in_place_monic(int level, poly &f, const poly g) +TowerPolynomial DPoly::division_in_place_monic(int level, TowerPolynomial &f, const TowerPolynomial g) { // ASSUMPTION: g is MONIC, non-zero if (f == 0) return 0; @@ -971,7 +971,7 @@ poly DPoly::division_in_place_monic(int level, poly &f, const poly g) return 0; } int shift = f->deg - g->deg; - poly quot = alloc_poly_n(shift); + TowerPolynomial quot = alloc_poly_n(shift); if (level == 0) { @@ -992,17 +992,17 @@ poly DPoly::division_in_place_monic(int level, poly &f, const poly g) } else { - poly *p = f->arr.polys; - poly *q = g->arr.polys; + TowerPolynomial *p = f->arr.polys; + TowerPolynomial *q = g->arr.polys; for (int d = f->deg; shift >= 0; d--, shift--) { - poly a = p[d]; + TowerPolynomial a = p[d]; if (a != 0) { quot->arr.polys[shift] = copy(level - 1, a); for (int j = 0; j <= g->deg; j++) { - poly b = mult(level - 1, a, q[j], true); + TowerPolynomial b = mult(level - 1, a, q[j], true); subtract_in_place(level - 1, p[j + shift], b); } } @@ -1012,9 +1012,9 @@ poly DPoly::division_in_place_monic(int level, poly &f, const poly g) return quot; } bool DPoly::division_in_place(int level, - poly &f, - const poly g, - poly &result_quot) + TowerPolynomial &f, + const TowerPolynomial g, + TowerPolynomial &result_quot) // returns false if the lead coeff is not invertible { assert(g != 0); @@ -1055,10 +1055,10 @@ bool DPoly::division_in_place(int level, else { // TODO: this code seems completely wrong!??!! - poly *p = f->arr.polys; - poly *q = g->arr.polys; - poly leadcoeff = q[g->deg]; - poly invlead; + TowerPolynomial *p = f->arr.polys; + TowerPolynomial *q = g->arr.polys; + TowerPolynomial leadcoeff = q[g->deg]; + TowerPolynomial invlead; if (is_one(level - 1, leadcoeff)) invlead = leadcoeff; else @@ -1068,10 +1068,10 @@ bool DPoly::division_in_place(int level, } for (int d = f->deg; shift >= 0; d--, shift--) { - poly a = p[d]; + TowerPolynomial a = p[d]; if (a != 0) { - poly b = mult(level - 1, invlead, a, true); + TowerPolynomial b = mult(level - 1, invlead, a, true); result_quot->arr.polys[shift] = copy(level - 1, b); for (int j = 0; j <= g->deg; j++) { @@ -1085,40 +1085,40 @@ bool DPoly::division_in_place(int level, } } -void DPoly::remainder(int level, poly &f, const poly g) +void DPoly::remainder(int level, TowerPolynomial &f, const TowerPolynomial g) { if (g == 0) return; - poly quot = 0; + TowerPolynomial quot = 0; division_in_place(level, f, g, quot); dealloc_poly(quot); } -void DPoly::pseudo_remainder(int level, poly &f, const poly g) +void DPoly::pseudo_remainder(int level, TowerPolynomial &f, const TowerPolynomial g) { if (g == 0) return; // TODO: write } -poly DPoly::pseudo_division(int level, poly &f, const poly g) +TowerPolynomial DPoly::pseudo_division(int level, TowerPolynomial &f, const TowerPolynomial g) { if (g == 0) return 0; // TODO: write return 0; } -poly DPoly::resultant(int level, poly f, poly g) +TowerPolynomial DPoly::resultant(int level, TowerPolynomial f, TowerPolynomial g) { // TODO: write return 0; } -static void swap_poly(poly &f, poly &g) +static void swap_poly(TowerPolynomial &f, TowerPolynomial &g) { - poly a = f; + TowerPolynomial a = f; f = g; g = a; } -poly DPoly::gcd(int level, const poly f, const poly g) +TowerPolynomial DPoly::gcd(int level, const TowerPolynomial f, const TowerPolynomial g) { - poly F = copy(level, f); - poly G = copy(level, g); + TowerPolynomial F = copy(level, f); + TowerPolynomial G = copy(level, g); if (G == 0) { G = F; @@ -1148,17 +1148,17 @@ poly DPoly::gcd(int level, const poly f, const poly g) } } -poly DPoly::gcd_coefficients(int level, - const poly f, - const poly g, - poly &result_u, - poly &result_v) +TowerPolynomial DPoly::gcd_coefficients(int level, + const TowerPolynomial f, + const TowerPolynomial g, + TowerPolynomial &result_u, + TowerPolynomial &result_v) { // Assumption: // f and g are non-zero - poly v1, v2, v3; - poly u1, u2, u3; - poly q = 0; + TowerPolynomial v1, v2, v3; + TowerPolynomial u1, u2, u3; + TowerPolynomial q = 0; v1 = 0; v2 = from_long(level, 1); @@ -1223,8 +1223,8 @@ poly DPoly::gcd_coefficients(int level, #endif negate_in_place(level, q); - poly a = mult(level, q, v1, false); - poly b = mult(level, q, v2, false); + TowerPolynomial a = mult(level, q, v1, false); + TowerPolynomial b = mult(level, q, v2, false); add_in_place(level, u1, a); add_in_place(level, u2, b); @@ -1263,7 +1263,7 @@ poly DPoly::gcd_coefficients(int level, return u3; } -int DPoly::degree(int level, int whichvar, const poly f) const +int DPoly::degree(int level, int whichvar, const TowerPolynomial f) const { if (f == 0) return -1; if (whichvar == 0) return f->deg; @@ -1271,7 +1271,7 @@ int DPoly::degree(int level, int whichvar, const poly f) const int deg = -1; for (int i = 0; i <= f->deg; i++) { - poly g = f->arr.polys[i]; + TowerPolynomial g = f->arr.polys[i]; if (g != 0) { int d = degree(level - 1, whichvar - 1, g); @@ -1281,9 +1281,9 @@ int DPoly::degree(int level, int whichvar, const poly f) const return deg; } -poly DPoly::mult_by_int_0(long a, const poly f) +TowerPolynomial DPoly::mult_by_int_0(long a, const TowerPolynomial f) { - poly result = alloc_poly_0(f->deg); + TowerPolynomial result = alloc_poly_0(f->deg); for (int i = 0; i <= f->deg; i++) { long c = f->arr.ints[i]; @@ -1296,29 +1296,29 @@ poly DPoly::mult_by_int_0(long a, const poly f) reset_degree_0(result); return result; } -poly DPoly::mult_by_int_n(int level, long a, const poly f) +TowerPolynomial DPoly::mult_by_int_n(int level, long a, const TowerPolynomial f) { - poly result = alloc_poly_n(f->deg); + TowerPolynomial result = alloc_poly_n(f->deg); for (int i = 0; i <= f->deg; i++) { - poly c = f->arr.polys[i]; + TowerPolynomial c = f->arr.polys[i]; if (c != 0) result->arr.polys[i] = mult_by_int(level - 1, a, c); } reset_degree_n(level, result); return result; } -poly DPoly::mult_by_int(int level, long a, const poly f) +TowerPolynomial DPoly::mult_by_int(int level, long a, const TowerPolynomial f) { if (f == 0) return 0; if (level == 0) return mult_by_int_0(a, f); return mult_by_int_n(level, a, f); } -poly DPoly::diff_0(const poly f) +TowerPolynomial DPoly::diff_0(const TowerPolynomial f) { if (f == 0 || f->deg == 0) return 0; - poly result = alloc_poly_0(f->deg - 1); + TowerPolynomial result = alloc_poly_0(f->deg - 1); for (int i = 1; i <= f->deg; i++) { long c = f->arr.ints[i]; @@ -1332,15 +1332,15 @@ poly DPoly::diff_0(const poly f) return result; } -poly DPoly::diff_n(int level, int whichvar, const poly f) +TowerPolynomial DPoly::diff_n(int level, int whichvar, const TowerPolynomial f) { - poly result; + TowerPolynomial result; if (whichvar == 0) { result = alloc_poly_0(f->deg - 1); for (int i = 1; i <= f->deg; i++) { - poly c = f->arr.polys[i]; + TowerPolynomial c = f->arr.polys[i]; if (c != 0) result->arr.polys[i - 1] = mult_by_int(level - 1, i, c); } } @@ -1349,7 +1349,7 @@ poly DPoly::diff_n(int level, int whichvar, const poly f) result = alloc_poly_0(f->deg); for (int i = 0; i <= f->deg; i++) { - poly c = f->arr.polys[i]; + TowerPolynomial c = f->arr.polys[i]; if (c != 0) result->arr.polys[i] = diff(level - 1, whichvar - 1, c); } } @@ -1357,22 +1357,22 @@ poly DPoly::diff_n(int level, int whichvar, const poly f) return result; } -poly DPoly::diff(int level, int whichvar, const poly f) +TowerPolynomial DPoly::diff(int level, int whichvar, const TowerPolynomial f) { if (f == 0) return 0; if (level == 0) return diff_0(f); return diff_n(level, whichvar, f); } -poly DPoly::power_mod(int level, const poly f, mpz_srcptr m, const poly g) +TowerPolynomial DPoly::power_mod(int level, const TowerPolynomial f, mpz_srcptr m, const TowerPolynomial g) // f^m mod g { // We assume that m > 0. THIS IS NOT CHECKED!! mpz_t n; mpz_init_set(n, m); - poly prod = from_long(level, 1); - poly base = copy(level, f); - poly tmp; + TowerPolynomial prod = from_long(level, 1); + TowerPolynomial base = copy(level, f); + TowerPolynomial tmp; for (;;) { @@ -1410,10 +1410,10 @@ poly DPoly::power_mod(int level, const poly f, mpz_srcptr m, const poly g) } } -poly DPoly::lowerP(int level, const poly f) +TowerPolynomial DPoly::lowerP(int level, const TowerPolynomial f) { int i, j; - poly result; + TowerPolynomial result; if (f == 0) return 0; int charac_as_int = static_cast(charac); int newdeg = f->deg / charac_as_int; // should be exact... @@ -1436,8 +1436,8 @@ poly DPoly::lowerP(int level, const poly f) { // need p-th roots of the coefficients. So we take p^(n-1) // power (if coefficients are in field of size p^n) - poly a = f->arr.polys[j]; - poly b = power_mod(level - 1, a, order, extensions[level - 1]); + TowerPolynomial a = f->arr.polys[j]; + TowerPolynomial b = power_mod(level - 1, a, order, extensions[level - 1]); result->arr.polys[i] = b; } mpz_clear(order); @@ -1445,7 +1445,7 @@ poly DPoly::lowerP(int level, const poly f) return result; } -int DPoly::index_of_var(int level, const poly f) const +int DPoly::index_of_var(int level, const TowerPolynomial f) const { if (f == 0 or level < 0 or f->deg >= 2) return -1; if (level == 0) @@ -1467,7 +1467,7 @@ int DPoly::index_of_var(int level, const poly f) const } void DPoly::degrees_of_vars(int level, - const poly f, + const TowerPolynomial f, std::vector &result_maxdegs) const { // Set the values of result_maxdegs at indices: 0..level @@ -1478,17 +1478,17 @@ void DPoly::degrees_of_vars(int level, degrees_of_vars(level - 1, f->arr.polys[i], result_maxdegs); } -DRing::DRing(long charac, int nvars, const_poly *exts) +DRing::DRing(long charac, int nvars, const TowerPolynomial *exts) : level(nvars - 1), D(charac, nvars, exts), P(charac) { } -DRing *DRing::create(long p, int nvars0, const_poly *ext0) +DRing *DRing::create(long p, int nvars0, const TowerPolynomial *ext0) { return new DRing(p, nvars0, ext0); } -void DRing::set_from_int(poly &result, mpz_srcptr r) +void DRing::set_from_int(TowerPolynomial &result, mpz_srcptr r) { mpz_t a; mpz_init(a); @@ -1499,7 +1499,7 @@ void DRing::set_from_int(poly &result, mpz_srcptr r) result = D.from_long(level, c); } -bool DRing::set_from_mpq(poly &result, mpq_srcptr r) +bool DRing::set_from_mpq(TowerPolynomial &result, mpq_srcptr r) { // returns false if r doesn't lift mpz_t a; @@ -1536,7 +1536,7 @@ int DRing::extension_degree(int firstvar) // returns -1 if infinite } void DRing::elem_text_out(buffer &o, - const poly f, + const TowerPolynomial f, bool p_one, bool p_plus, bool p_parens, @@ -1553,7 +1553,7 @@ void DRing::add_term(elem &result, long coeff, exponents exp) const D.add_term(level, result, c, exp); } -void DPolyTraverser::traverse(const_poly f) +void DPolyTraverser::traverse(const TowerPolynomial f) { exponents exp = new int[D->nvars]; for (size_t i = 0; i < D->nvars; i++) exp[i] = 0; @@ -1563,7 +1563,7 @@ void DPolyTraverser::traverse(const_poly f) delete[] exp; } -bool DPolyTraverser::traverse1(int level, const_poly f, exponents exp) +bool DPolyTraverser::traverse1(int level, const TowerPolynomial f, exponents exp) { if (level == 0) { @@ -1578,7 +1578,7 @@ bool DPolyTraverser::traverse1(int level, const_poly f, exponents exp) } else { - poly *cfs = f->arr.polys; + TowerPolynomial *cfs = f->arr.polys; for (int i = f->deg; i >= 0; --i) if (cfs[i] != 0) { diff --git a/M2/Macaulay2/e/dpoly.hpp b/M2/Macaulay2/e/dpoly.hpp index 092f8e5f352..04f32eb431a 100644 --- a/M2/Macaulay2/e/dpoly.hpp +++ b/M2/Macaulay2/e/dpoly.hpp @@ -18,21 +18,21 @@ class Tower; class DPolyTraverser; typedef int *exponents; // used only in add_term -typedef struct poly_struct *poly; -typedef const struct poly_struct *const_poly; +typedef struct TowerPolynomialStruct *TowerPolynomial; +//typedef const struct TowerPolynomialStruct *const_poly; /** * \ingroup polynomialrings */ -struct poly_struct : public our_new_delete +struct TowerPolynomialStruct : public our_new_delete { int deg; int len; union { long *ints; // array of integers. at level == 0 - poly *polys; // array of more ptrs to poly structs, at level > 0 + TowerPolynomial *polys; // array of more ptrs to poly structs, at level > 0 } arr; }; @@ -44,81 +44,81 @@ class DPoly friend class DPolyTraverser; int nvars; int nlevels; // #vars is nlevels+1 - poly *extensions; + TowerPolynomial *extensions; long charac; private: - void initialize(long p, int nvars0, const_poly *ext0); + void initialize(long p, int nvars0, const TowerPolynomial* ext0); - void reset_degree_0(poly &f); // possibly sets f to 0 - void reset_degree_n(int level, poly &f); // ditto + void reset_degree_0(TowerPolynomial &f); // possibly sets f to 0 + void reset_degree_n(int level, TowerPolynomial &f); // ditto - void mult_by_coeff_0(poly &f, long b); - void mult_by_coeff_n(int level, poly &f, poly b); + void mult_by_coeff_0(TowerPolynomial &f, long b); + void mult_by_coeff_n(int level, TowerPolynomial &f, TowerPolynomial b); // f *= b. b should have level 'level-1'. - void make_monic_0(poly &f, long &result_multiplier); - void make_monic_n(int level, poly &f, poly &result_multiplier); + void make_monic_0(TowerPolynomial &f, long &result_multiplier); + void make_monic_n(int level, TowerPolynomial &f, TowerPolynomial &result_multiplier); - bool make_monic3(int level, poly &u1, poly &u2, poly &u3); + bool make_monic3(int level, TowerPolynomial &u1, TowerPolynomial &u2, TowerPolynomial &u3); - static poly read_poly_0(char *&str); - static poly read_poly_n(char *&str, int level); + static TowerPolynomial read_poly_0(char *&str); + static TowerPolynomial read_poly_n(char *&str, int level); - void add_in_place_0(poly &f, const poly g); - void add_in_place_n(int level, poly &f, const poly g); + void add_in_place_0(TowerPolynomial &f, const TowerPolynomial g); + void add_in_place_n(int level, TowerPolynomial &f, const TowerPolynomial g); - void subtract_in_place_0(poly &f, const poly g); - void subtract_in_place_n(int level, poly &f, const poly g); + void subtract_in_place_0(TowerPolynomial &f, const TowerPolynomial g); + void subtract_in_place_n(int level, TowerPolynomial &f, const TowerPolynomial g); - poly mult_0(const poly f, const poly g, bool reduce_by_extension); - poly mult_n(int level, const poly f, const poly g, bool reduce_by_extension); + TowerPolynomial mult_0(const TowerPolynomial f, const TowerPolynomial g, bool reduce_by_extension); + TowerPolynomial mult_n(int level, const TowerPolynomial f, const TowerPolynomial g, bool reduce_by_extension); - poly random_0(int deg); - poly random_n(int level, int deg); + TowerPolynomial random_0(int deg); + TowerPolynomial random_n(int level, int deg); - poly diff_0(const poly f); - poly diff_n(int level, int whichvar, const poly f); + TowerPolynomial diff_0(const TowerPolynomial f); + TowerPolynomial diff_n(int level, int whichvar, const TowerPolynomial f); - poly mult_by_int_0(long c, const poly f); - poly mult_by_int_n(int level, long c, const poly f); + TowerPolynomial mult_by_int_0(long c, const TowerPolynomial f); + TowerPolynomial mult_by_int_n(int level, long c, const TowerPolynomial f); public: int degree_of_extension(int level); // if negative, then that variable is // transcendental over lower vars - bool down_level(int newlevel, int oldlevel, poly &f); + bool down_level(int newlevel, int oldlevel, TowerPolynomial &f); - static void increase_size_0(int newdeg, poly &f); - static void increase_size_n(int newdeg, poly &f); - static poly alloc_poly_n(int deg, poly *elems = 0); - static poly alloc_poly_0(int deg, long *elems = 0); - static void dealloc_poly(poly &f); + static void increase_size_0(int newdeg, TowerPolynomial &f); + static void increase_size_n(int newdeg, TowerPolynomial &f); + static TowerPolynomial alloc_poly_n(int deg, TowerPolynomial *elems = 0); + static TowerPolynomial alloc_poly_0(int deg, long *elems = 0); + static void dealloc_poly(TowerPolynomial &f); - static void display_poly(FILE *fil, int level, const poly f); - static poly read_poly(char *&str, int level); + static void display_poly(FILE *fil, int level, const TowerPolynomial f); + static TowerPolynomial read_poly(char *&str, int level); static std::ostream &append_to_stream(std::ostream &o, int level, - const poly f); - static char *to_string(int level, const poly f); + const TowerPolynomial f); + static char *to_string(int level, const TowerPolynomial f); - static bool is_equal(int level, const poly f, const poly g); - static poly copy(int level, const_poly f); + static bool is_equal(int level, const TowerPolynomial f, const TowerPolynomial g); + static TowerPolynomial copy(int level, const TowerPolynomial f); - static poly from_long(int level, long c); // c should be reduced mod p + static TowerPolynomial from_long(int level, long c); // c should be reduced mod p - static bool is_zero(poly f) { return f == 0; } - void remove(int level, poly &f); + static bool is_zero(TowerPolynomial f) { return f == 0; } + void remove(int level, TowerPolynomial &f); - int compare(int level, const poly f, const poly g); // this is a total order + int compare(int level, const TowerPolynomial f, const TowerPolynomial g); // this is a total order - poly random(int level, int deg); - poly random(int level); // obtains a random element, using only variables + TowerPolynomial random(int level, int deg); + TowerPolynomial random(int level); // obtains a random element, using only variables // which are algebraic over the base - poly var(int level, int v); // make the variable v (but at level 'level') + TowerPolynomial var(int level, int v); // make the variable v (but at level 'level') void add_term(int level, - poly &result, + TowerPolynomial &result, long coeff, exponents exp) const; // modifies result. // exp is an array [0..level-1] of exponent values for each variable @@ -126,37 +126,37 @@ class DPoly // the outer variable is at index 0. // coeff is an already normalized coefficient. - void negate_in_place(int level, poly &f); - void add_in_place(int level, poly &f, const poly g); - void subtract_in_place(int level, poly &f, const poly g); - poly mult_by_int(int level, long c, const poly f); - poly mult(int level, const poly f, const poly g, bool reduce_by_extension); - void remainder(int level, poly &f, const poly g); - poly division_in_place_monic(int level, poly &f, const poly g); - bool division_in_place(int level, poly &f, const poly g, poly &result_quot); - - void pseudo_remainder(int level, poly &f, const poly g); - poly pseudo_division(int level, poly &f, const poly g); - - poly gcd(int level, const poly f, const poly g); - poly gcd_coefficients(int level, - const poly f, - const poly g, - poly &result_u, - poly &result_v); - poly resultant(int level, poly f, poly g); - - void make_monic(int level, poly &f); - poly invert(int level, const poly a); + void negate_in_place(int level, TowerPolynomial &f); + void add_in_place(int level, TowerPolynomial &f, const TowerPolynomial g); + void subtract_in_place(int level, TowerPolynomial &f, const TowerPolynomial g); + TowerPolynomial mult_by_int(int level, long c, const TowerPolynomial f); + TowerPolynomial mult(int level, const TowerPolynomial f, const TowerPolynomial g, bool reduce_by_extension); + void remainder(int level, TowerPolynomial &f, const TowerPolynomial g); + TowerPolynomial division_in_place_monic(int level, TowerPolynomial &f, const TowerPolynomial g); + bool division_in_place(int level, TowerPolynomial &f, const TowerPolynomial g, TowerPolynomial &result_quot); + + void pseudo_remainder(int level, TowerPolynomial &f, const TowerPolynomial g); + TowerPolynomial pseudo_division(int level, TowerPolynomial &f, const TowerPolynomial g); + + TowerPolynomial gcd(int level, const TowerPolynomial f, const TowerPolynomial g); + TowerPolynomial gcd_coefficients(int level, + const TowerPolynomial f, + const TowerPolynomial g, + TowerPolynomial &result_u, + TowerPolynomial &result_v); + TowerPolynomial resultant(int level, TowerPolynomial f, TowerPolynomial g); + + void make_monic(int level, TowerPolynomial &f); + TowerPolynomial invert(int level, const TowerPolynomial a); void normal_form(int level, - poly &f); // hmmm, I need to think this one through... + TowerPolynomial &f); // hmmm, I need to think this one through... - void subtract_multiple_to(int level, poly &f, long a, int i, poly g); + void subtract_multiple_to(int level, TowerPolynomial &f, long a, int i, TowerPolynomial g); void elem_text_out(buffer &o, int level, - const poly f, + const TowerPolynomial f, bool p_one, bool p_plus, bool p_parens, @@ -164,20 +164,20 @@ class DPoly void extensions_text_out(buffer &o, M2_ArrayString names) const; - int degree(int level, int var, const poly f) const; - poly diff(int level, int var, const poly f); - poly power_mod(int level, const poly f, mpz_srcptr n, const poly g); // f^n mod g - poly lowerP(int level, const poly f); + int degree(int level, int var, const TowerPolynomial f) const; + TowerPolynomial diff(int level, int var, const TowerPolynomial f); + TowerPolynomial power_mod(int level, const TowerPolynomial f, mpz_srcptr n, const TowerPolynomial g); // f^n mod g + TowerPolynomial lowerP(int level, const TowerPolynomial f); - static bool is_one(int level, const poly f); - int index_of_var(int level, const poly f) const; + static bool is_one(int level, const TowerPolynomial f); + int index_of_var(int level, const TowerPolynomial f) const; void degrees_of_vars(int level, - const poly f, + const TowerPolynomial f, std::vector &result_max_degs) const; // DPoly management ~DPoly() {} - DPoly(long p, int nvars0, const_poly *extensions = 0); + DPoly(long p, int nvars0, const TowerPolynomial* extensions = 0); }; /** @@ -189,14 +189,14 @@ class DRing : public our_new_delete mutable DPoly D; long P; - DRing(long charac, int nvars, const_poly *exts); + DRing(long charac, int nvars, const TowerPolynomial *exts); public: typedef Tower ring_type; - typedef poly elem; + typedef TowerPolynomial elem; DPoly *getDPoly() const { return &D; } - static DRing *create(long p, int nvars0, const_poly *ext0); + static DRing *create(long p, int nvars0, const TowerPolynomial *ext0); // ext0 should be an array of poly's of level 'nvars0'? 0..nvars0-1 void init_set(elem &result, elem a) const { result = a; } @@ -226,7 +226,7 @@ class DRing : public our_new_delete result = a; else { - poly a1 = D.copy(level, a); + TowerPolynomial a1 = D.copy(level, a); D.add_in_place(level, a1, b); result = a1; } @@ -234,7 +234,7 @@ class DRing : public our_new_delete void subtract(elem &result, elem a, elem b) const { - poly a1 = D.copy(level, a); + TowerPolynomial a1 = D.copy(level, a); D.subtract_in_place(level, a1, b); result = a1; } @@ -279,13 +279,13 @@ class DRing : public our_new_delete void to_ring_elem(ring_elem &result, const elem a) const { - poly h = D.copy(level, a); + TowerPolynomial h = D.copy(level, a); result = TOWER_RINGELEM(h); } void from_ring_elem(elem &result, const ring_elem &a) const { - poly a1 = TOWER_VAL(a); + TowerPolynomial a1 = reinterpret_cast(a.poly_val); result = D.copy(level, a1); } @@ -296,46 +296,46 @@ class DRing : public our_new_delete b = tmp; } - bool is_one(const poly f) { return D.is_one(level, f); } - bool is_equal(const poly f, const poly g) { return D.is_equal(level, f, g); } - bool compare(const poly f, const poly g) { return D.compare(level, f, g); } - bool is_unit(const poly g); // what does this really do? + bool is_one(const TowerPolynomial f) { return D.is_one(level, f); } + bool is_equal(const TowerPolynomial f, const TowerPolynomial g) { return D.is_equal(level, f, g); } + bool compare(const TowerPolynomial f, const TowerPolynomial g) { return D.compare(level, f, g); } + bool is_unit(const TowerPolynomial g); // what does this really do? - void set_var(poly &result, int n) + void set_var(TowerPolynomial &result, int n) { // n from 0..nvars-1, sets result to 0 f n is out of range result = D.var(level, n); } - void set_from_long(poly &result, long r) + void set_from_long(TowerPolynomial &result, long r) { r = r % P; if (r < 0) r += P; result = D.from_long(level, r); } - void set_from_int(poly &result, mpz_srcptr r); // written + void set_from_int(TowerPolynomial &result, mpz_srcptr r); // written - bool set_from_mpq(poly &result, mpq_srcptr r); // written + bool set_from_mpq(TowerPolynomial &result, mpq_srcptr r); // written - void set_random(poly &result) { result = D.random(level); } + void set_random(TowerPolynomial &result) { result = D.random(level); } void elem_text_out(buffer &o, - const poly f, + const TowerPolynomial f, bool p_one, bool p_plus, bool p_parens, M2_ArrayString names) const; - void gcd(poly &result, const poly f, const poly g) + void gcd(TowerPolynomial &result, const TowerPolynomial f, const TowerPolynomial g) { result = D.gcd(level, f, g); } - void gcd_coefficients(poly &result_gcd, - poly &result_u, - poly &result_v, - const poly f, - const poly g) + void gcd_coefficients(TowerPolynomial &result_gcd, + TowerPolynomial &result_u, + TowerPolynomial &result_v, + const TowerPolynomial f, + const TowerPolynomial g) { result_gcd = D.gcd_coefficients(level, f, g, result_u, result_v); } @@ -345,19 +345,19 @@ class DRing : public our_new_delete D.extensions_text_out(o, names); } - int degree(int var, const poly f) const { return D.degree(level, var, f); } - void diff(int var, poly &result, const poly f) const + int degree(int var, const TowerPolynomial f) const { return D.degree(level, var, f); } + void diff(int var, TowerPolynomial &result, const TowerPolynomial f) const { result = D.diff(level, var, f); } int extension_degree(int firstvar); // returns -1 if infinite - void power_mod(poly &result, const poly f, mpz_srcptr n, const poly g) const + void power_mod(TowerPolynomial &result, const TowerPolynomial f, mpz_srcptr n, const TowerPolynomial g) const { result = D.power_mod(level, f, n, g); } // f^n mod g - void lowerP(poly &result, const poly f) { result = D.lowerP(level, f); } - int index_of_var(const poly f) const { return D.index_of_var(level, f); } - void degrees_of_vars(const poly f, std::vector &result) const + void lowerP(TowerPolynomial &result, const TowerPolynomial f) { result = D.lowerP(level, f); } + int index_of_var(const TowerPolynomial f) const { return D.index_of_var(level, f); } + void degrees_of_vars(const TowerPolynomial f, std::vector &result) const { result.resize(level + 1); for (size_t i = 0; i <= level; i++) result[i] = 0; @@ -372,7 +372,7 @@ class DPolyTraverser : public our_new_delete { const DPoly *D; - bool traverse1(int level, const_poly g, exponents exp); + bool traverse1(int level, const TowerPolynomial g, exponents exp); protected: virtual bool viewTerm(long coeff, const exponents exp) = 0; @@ -380,7 +380,7 @@ class DPolyTraverser : public our_new_delete public: DPolyTraverser(const DRing *D0) : D(D0->getDPoly()) {} virtual ~DPolyTraverser() {} - void traverse(const_poly f); + void traverse(const TowerPolynomial f); }; // Format for polynomials in a file: diff --git a/M2/Macaulay2/e/f4/f4-m2-interface.cpp b/M2/Macaulay2/e/f4/f4-m2-interface.cpp index 7964af7dd4b..bf856ba7700 100644 --- a/M2/Macaulay2/e/f4/f4-m2-interface.cpp +++ b/M2/Macaulay2/e/f4/f4-m2-interface.cpp @@ -21,7 +21,7 @@ void F4toM2Interface::from_M2_vec(const VectorArithmetic* VA, const MonomialInfo *MI, const FreeModule *F, vec v, - poly &result) + GBF4Polynomial &result) { const PolynomialRing *R = F->get_ring()->cast_to_PolynomialRing(); const Monoid *M = R->getMonoid(); @@ -59,7 +59,7 @@ void F4toM2Interface::from_M2_vec(const VectorArithmetic* VA, void F4toM2Interface::poly_set_degrees(const VectorArithmetic* VA, const MonomialInfo *MI, const M2_arrayint wts, - const poly &f, + const GBF4Polynomial &f, int °_result, int &alpha) { @@ -95,7 +95,7 @@ void F4toM2Interface::from_M2_matrix(const VectorArithmetic* VA, vec F4toM2Interface::to_M2_vec(const VectorArithmetic* VA, const MonomialInfo *MI, - const poly &f, + const GBF4Polynomial &f, const FreeModule *F) { const PolynomialRing *R = F->get_ring()->cast_to_PolynomialRing(); diff --git a/M2/Macaulay2/e/f4/f4-m2-interface.hpp b/M2/Macaulay2/e/f4/f4-m2-interface.hpp index 58e64f33a12..851ea5c5983 100644 --- a/M2/Macaulay2/e/f4/f4-m2-interface.hpp +++ b/M2/Macaulay2/e/f4/f4-m2-interface.hpp @@ -2,7 +2,7 @@ #define __F4toM2interface_h_ #include "engine-exports.h" // for M2_arrayint -#include "f4/f4-types.hpp" // for gb_array, poly (ptr only), coefficient_m... +#include "f4/f4-types.hpp" // for gb_array, GBF4Polynomial (ptr only), coefficient_m... #include "ringelem.hpp" // for vec class FreeModule; @@ -17,7 +17,7 @@ class F4toM2Interface static void poly_set_degrees(const VectorArithmetic* VA, const MonomialInfo *MI, const M2_arrayint wts, - const poly &f, + const GBF4Polynomial &f, int °, int &alpha); @@ -25,11 +25,11 @@ class F4toM2Interface const MonomialInfo *MI, const FreeModule *F, vec v, - poly &result); + GBF4Polynomial &result); static vec to_M2_vec(const VectorArithmetic* VA, const MonomialInfo *MI, - const poly &f, + const GBF4Polynomial &f, const FreeModule *F); static void from_M2_matrix(const VectorArithmetic* VA, diff --git a/M2/Macaulay2/e/f4/f4-types.hpp b/M2/Macaulay2/e/f4/f4-types.hpp index 2ffe21aa9cd..221196cffdc 100644 --- a/M2/Macaulay2/e/f4/f4-types.hpp +++ b/M2/Macaulay2/e/f4/f4-types.hpp @@ -31,7 +31,7 @@ enum spair_type { F4_SPAIR_ELEM }; -struct poly : public our_new_delete +struct GBF4Polynomial : public our_new_delete { int len; CoeffVector coeffs; @@ -59,7 +59,7 @@ struct spair : public our_new_delete struct gbelem : public our_new_delete { - poly f; + GBF4Polynomial f; int deg; int alpha; // the homogenizing degree gbelem_type minlevel; diff --git a/M2/Macaulay2/e/f4/f4.cpp b/M2/Macaulay2/e/f4/f4.cpp index 18ecf298b28..3696e7aebb7 100644 --- a/M2/Macaulay2/e/f4/f4.cpp +++ b/M2/Macaulay2/e/f4/f4.cpp @@ -159,7 +159,7 @@ int F4GB::mult_monomials(packed_monomial m, packed_monomial n) void F4GB::load_gen(int which) { - poly &g = gens[which]->f; + GBF4Polynomial &g = gens[which]->f; row_elem r{}; r.monom = nullptr; // This says that this element corresponds to a generator @@ -181,7 +181,7 @@ void F4GB::load_gen(int which) void F4GB::load_row(packed_monomial monom, int which) { - poly &g = gb[which]->f; + GBF4Polynomial &g = gb[which]->f; row_elem r{}; r.monom = monom; diff --git a/M2/Macaulay2/e/gb-default.cpp b/M2/Macaulay2/e/gb-default.cpp index 8c355920686..b8714ee8ab8 100644 --- a/M2/Macaulay2/e/gb-default.cpp +++ b/M2/Macaulay2/e/gb-default.cpp @@ -672,6 +672,7 @@ gbA::spairs::iterator gbA::choose_pair(gbA::spairs::iterator first, return first; /* MES: really do something here... */ } +namespace { struct spair_sorter : public std::binary_function { @@ -699,6 +700,7 @@ struct spair_sorter return result; } }; +}; // unnamed namespace class SPolySorter { diff --git a/M2/Macaulay2/e/gb-test1.cpp b/M2/Macaulay2/e/gb-test1.cpp index 9ee101f4279..e88e10f032f 100644 --- a/M2/Macaulay2/e/gb-test1.cpp +++ b/M2/Macaulay2/e/gb-test1.cpp @@ -567,6 +567,7 @@ gbB::spairs::iterator gbB::choose_pair(gbB::spairs::iterator first, return first; /* MES: really do something here... */ } +namespace { struct spair_sorter : public std::binary_function { @@ -594,6 +595,7 @@ struct spair_sorter return result; } }; +}; // unnamed namespace class SPolySorterB { diff --git a/M2/Macaulay2/e/ringelem.hpp b/M2/Macaulay2/e/ringelem.hpp index e39f5df6215..38f45bfc482 100644 --- a/M2/Macaulay2/e/ringelem.hpp +++ b/M2/Macaulay2/e/ringelem.hpp @@ -116,7 +116,7 @@ struct vecterm : public our_new_delete #define BIGCC_RE(f) (&(f).get_cc()->re) // TODO: these need to be replaced... no casting, need new slot in ring_elem union type -#define TOWER_VAL(f) (reinterpret_cast((f).poly_val)) +#define TOWER_VAL(f) (reinterpret_cast((f).poly_val)) #define TOWER_RINGELEM(a) (ring_elem(reinterpret_cast(a))) #endif diff --git a/M2/Macaulay2/e/schreyer-resolution/res-f4-computation.cpp b/M2/Macaulay2/e/schreyer-resolution/res-f4-computation.cpp index 7e95e5cf058..a70b5fb27dd 100644 --- a/M2/Macaulay2/e/schreyer-resolution/res-f4-computation.cpp +++ b/M2/Macaulay2/e/schreyer-resolution/res-f4-computation.cpp @@ -136,10 +136,10 @@ ResolutionComputation* createF4Res(const Matrix* groebnerBasisMatrix, M2_arrayint pos = leadterms->sort(1 /* ascending degree */, -1 /* descending monomial order */); - std::vector input_polys; + std::vector input_polys; for (int i = 0; i < groebnerBasisMatrix->n_cols(); i++) { - poly f; + ResPolynomial f; ResF4toM2Interface::from_M2_vec(*R, F, groebnerBasisMatrix->elem(i), f); input_polys.emplace_back(std::move(f)); } @@ -151,7 +151,7 @@ ResolutionComputation* createF4Res(const Matrix* groebnerBasisMatrix, for (int i = 0; i < pos->len; i++) { int loc = pos->array[i]; - poly& f = input_polys[loc]; + ResPolynomial& f = input_polys[loc]; if (f.len == 0) continue; if (MI->get_component(f.monoms.data()) != j) continue; res_packed_monomial elem = diff --git a/M2/Macaulay2/e/schreyer-resolution/res-f4-m2-interface.cpp b/M2/Macaulay2/e/schreyer-resolution/res-f4-m2-interface.cpp index 29ec9a3343d..e9edd75773f 100644 --- a/M2/Macaulay2/e/schreyer-resolution/res-f4-m2-interface.cpp +++ b/M2/Macaulay2/e/schreyer-resolution/res-f4-m2-interface.cpp @@ -32,7 +32,7 @@ #include "schreyer-resolution/res-gausser.hpp" // for ResGausser #include "schreyer-resolution/res-moninfo.hpp" // for ResMonoid #include "schreyer-resolution/res-monomial-types.hpp" // for res_monomia... -#include "schreyer-resolution/res-poly-ring.hpp" // for poly_iter +#include "schreyer-resolution/res-poly-ring.hpp" // for ResPolynomialIterator #include "schreyer-resolution/res-schreyer-frame.hpp" // for SchreyerFrame #include "schreyer-resolution/res-schreyer-order.hpp" // for ResSchreyer... #include "timing.hpp" // for timer, seconds @@ -201,7 +201,7 @@ void ResGausserQQHybrid::from_ring_elem(CoefficientVector& result, void ResF4toM2Interface::from_M2_vec(const ResPolyRing& R, const FreeModule* F, vec v, - poly& result) + ResPolynomial& result) { const PolynomialRing* origR = F->get_ring()->cast_to_PolynomialRing(); const Monoid* M = origR->getMonoid(); @@ -244,13 +244,13 @@ void ResF4toM2Interface::from_M2_vec(const ResPolyRing& R, n++; } - poly_constructor::setPolyFromArrays(result, n, coeffs, monoms); + ResPolynomialConstructor::setPolyFromArrays(result, n, coeffs, monoms); GR->gbvector_remove(f); delete[] exp; } vec ResF4toM2Interface::to_M2_vec(const ResPolyRing& R, - const poly& f, + const ResPolynomial& f, const FreeModule* F) { const PolynomialRing* origR = F->get_ring()->cast_to_PolynomialRing(); @@ -435,7 +435,7 @@ MutableMatrix* ResF4toM2Interface::to_M2_MutableMatrix(SchreyerFrame& C, { // Now we create the polynomials for column j // into 'comps', 'last'. - const poly& f = (*j1).mSyzygy; + const ResPolynomial& f = (*j1).mSyzygy; for (int i = 0; i < nrows; i++) { comps[i] = nullptr; @@ -511,8 +511,8 @@ MutableMatrix* ResF4toM2Interface::to_M2_MutableMatrix(SchreyerFrame& C, { if (p->mDegree != degree) continue; auto& f = p->mSyzygy; - auto end = poly_iter(C.ring(), f, 1); - auto i = poly_iter(C.ring(), f); + auto end = ResPolynomialIterator(C.ring(), f, 1); + auto i = ResPolynomialIterator(C.ring(), f); for (; i != end; ++i) { long comp = C.monoid().get_component(i.monomial()); @@ -582,8 +582,8 @@ class DegreeZeroMapGenerator { if (p->mDegree != mDegree) continue; auto& f = p->mSyzygy; - auto end = poly_iter(mSchreyerFrame.ring(), f, 1); - auto i = poly_iter(mSchreyerFrame.ring(), f); + auto end = ResPolynomialIterator(mSchreyerFrame.ring(), f, 1); + auto i = ResPolynomialIterator(mSchreyerFrame.ring(), f); for (; i != end; ++i) { @@ -646,8 +646,8 @@ class DegreeZeroMapGenerator if (mIter->mDegree == mGenerator.mDegree) break; } auto& f = mIter->mSyzygy; - auto end = poly_iter(mGenerator.mSchreyerFrame.ring(), f, 1); - auto i = poly_iter(mGenerator.mSchreyerFrame.ring(), f); + auto end = ResPolynomialIterator(mGenerator.mSchreyerFrame.ring(), f, 1); + auto i = ResPolynomialIterator(mGenerator.mSchreyerFrame.ring(), f); for (; i != end; ++i) { diff --git a/M2/Macaulay2/e/schreyer-resolution/res-f4-m2-interface.hpp b/M2/Macaulay2/e/schreyer-resolution/res-f4-m2-interface.hpp index f723c183c08..f5785ba5fad 100644 --- a/M2/Macaulay2/e/schreyer-resolution/res-f4-m2-interface.hpp +++ b/M2/Macaulay2/e/schreyer-resolution/res-f4-m2-interface.hpp @@ -10,7 +10,7 @@ class PolynomialRing; class ResPolyRing; class Ring; class SchreyerFrame; -class poly; +class ResPolynomial; template class DMat; class ResF4toM2Interface @@ -19,10 +19,10 @@ class ResF4toM2Interface static void from_M2_vec(const ResPolyRing& R, const FreeModule* F, vec v, - poly& result); + ResPolynomial& result); static vec to_M2_vec(const ResPolyRing& R, - const poly& f, + const ResPolynomial& f, const FreeModule* F); static FreeModule* to_M2_freemodule(const PolynomialRing* R, diff --git a/M2/Macaulay2/e/schreyer-resolution/res-f4.cpp b/M2/Macaulay2/e/schreyer-resolution/res-f4.cpp index 95322105d0f..3db7d9f9105 100644 --- a/M2/Macaulay2/e/schreyer-resolution/res-f4.cpp +++ b/M2/Macaulay2/e/schreyer-resolution/res-f4.cpp @@ -258,8 +258,8 @@ void F4Res::loadRow(Row& r) return; } auto& p = thiselement.mSyzygy; - auto end = poly_iter(mRing, p, 1); - auto i = poly_iter(mRing, p); + auto end = ResPolynomialIterator(mRing, p, 1); + auto i = ResPolynomialIterator(mRing, p); for (; i != end; ++i) { ComponentIndex val = @@ -498,7 +498,7 @@ void F4Res::gaussReduce() // Reduce spair #i // fill in dense row with this element. - poly_constructor result(mRing); + ResPolynomialConstructor result(mRing); Row& r = mSPairs[i]; // row to be reduced. long comp = mSPairComponents[i]; diff --git a/M2/Macaulay2/e/schreyer-resolution/res-poly-ring.cpp b/M2/Macaulay2/e/schreyer-resolution/res-poly-ring.cpp index 888ad3aea10..8690bd5cbc6 100644 --- a/M2/Macaulay2/e/schreyer-resolution/res-poly-ring.cpp +++ b/M2/Macaulay2/e/schreyer-resolution/res-poly-ring.cpp @@ -4,11 +4,11 @@ #include "schreyer-resolution/res-monomial-sorter.hpp" // for ResMonomialSorter struct ResSchreyerOrder; -long poly::npoly_destructor = 0; -long poly_constructor::ncalls = 0; -long poly_constructor::ncalls_fromarray = 0; +long ResPolynomial::npoly_destructor = 0; +long ResPolynomialConstructor::ncalls = 0; +long ResPolynomialConstructor::ncalls_fromarray = 0; -void ResPolyRing::memUsage(const poly& f, +void ResPolyRing::memUsage(const ResPolynomial& f, long& nterms, long& bytes_used, long& bytes_alloc) const @@ -23,14 +23,14 @@ void ResPolyRing::memUsage(const poly& f, #if 0 bool check_poly(const ResPolyRing& R, - const poly& f, + const ResPolynomial& f, const ResSchreyerOrder& ord) { // We loop through each monomial, checking it against the one before // The order used is the Schreyer order given. auto& M = R.monoid(); - poly_iter i(R, f); - poly_iter end(R, f, 1); + ResPolynomialIterator i(R, f); + ResPolynomialIterator end(R, f, 1); res_const_packed_monomial prev = nullptr; for (; i != end; ++i) { @@ -59,12 +59,12 @@ bool check_poly(const ResPolyRing& R, #endif bool check_poly(const ResPolyRing& R, - const poly& f, + const ResPolynomial& f, const ResSchreyerOrder& ord) { std::vector monoms; - auto end = poly_iter(R,f,1); - for (auto i=poly_iter(R,f); i != end; ++i) + auto end = ResPolynomialIterator(R,f,1); + for (auto i = ResPolynomialIterator(R,f); i != end; ++i) { monoms.push_back(const_cast(i.monomial())); } diff --git a/M2/Macaulay2/e/schreyer-resolution/res-poly-ring.hpp b/M2/Macaulay2/e/schreyer-resolution/res-poly-ring.hpp index 9149a681c28..fe02189cf4d 100644 --- a/M2/Macaulay2/e/schreyer-resolution/res-poly-ring.hpp +++ b/M2/Macaulay2/e/schreyer-resolution/res-poly-ring.hpp @@ -17,11 +17,11 @@ class Monoid; class SkewMultiplication; struct ResSchreyerOrder; -class poly +class ResPolynomial { friend class ResPolyRing; - friend class poly_constructor; - friend class poly_iter; + friend class ResPolynomialConstructor; + friend class ResPolynomialIterator; public: static long npoly_destructor; @@ -33,17 +33,17 @@ class poly // std::unique_ptr monoms; public: - poly() : len(0), coeffs() {} - ~poly() + ResPolynomial() : len(0), coeffs() {} + ~ResPolynomial() { if (!coeffs.isNull()) npoly_destructor++; // std::cout << "Calling ~poly()" << std::endl << std::flush; } - poly(const poly& other) = default; - poly(poly&& other) = default; - poly& operator=(const poly& other) = default; - poly& operator=(poly&& other) = default; + ResPolynomial(const ResPolynomial& other) = default; + ResPolynomial(ResPolynomial&& other) = default; + ResPolynomial& operator=(const ResPolynomial& other) = default; + ResPolynomial& operator=(ResPolynomial&& other) = default; }; class ResPolyRing : public our_new_delete @@ -66,7 +66,7 @@ class ResPolyRing : public our_new_delete const Monoid& originalMonoid() const { return *mOriginalMonoid; } bool isSkewCommutative() const { return mSkew != nullptr; } const SkewMultiplication* skewInfo() const { return mSkew; } - void memUsage(const poly& f, + void memUsage(const ResPolynomial& f, long& nterms, long& bytes_used, long& bytes_alloc) const; @@ -78,7 +78,7 @@ class ResPolyRing : public our_new_delete const SkewMultiplication* mSkew; }; -class poly_constructor +class ResPolynomialConstructor { private: std::vector monoms; @@ -90,12 +90,12 @@ class poly_constructor static long ncalls; static long ncalls_fromarray; - poly_constructor(const ResPolyRing& R) : mRing(R) + ResPolynomialConstructor(const ResPolyRing& R) : mRing(R) { coeffs = R.resGausser().allocateCoefficientVector(); } - ~poly_constructor() { mRing.resGausser().deallocate(coeffs); } + ~ResPolynomialConstructor() { mRing.resGausser().deallocate(coeffs); } void appendMonicTerm(res_packed_monomial monom) { monoms.push_back(monom); // a pointer @@ -108,7 +108,7 @@ class poly_constructor } CoefficientVector& coefficientInserter() { return coeffs; } - void setPoly(poly& result) + void setPoly(ResPolynomial& result) { ncalls++; result.len = static_cast(mRing.resGausser().size(coeffs)); @@ -124,7 +124,7 @@ class poly_constructor } } - static void setPolyFromArrays(poly& result, + static void setPolyFromArrays(ResPolynomial& result, int len, CoefficientVector& coeffs, std::vector& monoms) @@ -136,23 +136,23 @@ class poly_constructor } }; -class poly_iter +class ResPolynomialIterator { const ResPolyRing& mRing; - const poly& elem; + const ResPolynomial& elem; long coeff_index; long monom_index; public: - friend bool operator==(const poly_iter& a, const poly_iter& b); - friend bool operator!=(const poly_iter& a, const poly_iter& b); + friend bool operator==(const ResPolynomialIterator& a, const ResPolynomialIterator& b); + friend bool operator!=(const ResPolynomialIterator& a, const ResPolynomialIterator& b); - poly_iter(const ResPolyRing& R, const poly& elem0) + ResPolynomialIterator(const ResPolyRing& R, const ResPolynomial& elem0) : mRing(R), elem(elem0), coeff_index(0), monom_index(0) { } - poly_iter(const ResPolyRing& R, const poly& elem0, int) // end + ResPolynomialIterator(const ResPolyRing& R, const ResPolynomial& elem0, int) // end : mRing(R), elem(elem0), coeff_index(elem.len), @@ -174,20 +174,20 @@ class poly_iter } }; -inline bool operator==(const poly_iter& a, const poly_iter& b) +inline bool operator==(const ResPolynomialIterator& a, const ResPolynomialIterator& b) { return a.coeff_index == b.coeff_index; } -inline bool operator!=(const poly_iter& a, const poly_iter& b) +inline bool operator!=(const ResPolynomialIterator& a, const ResPolynomialIterator& b) { return a.coeff_index != b.coeff_index; } -inline void display_poly(std::ostream& o, const ResPolyRing& R, const poly& f) +inline void display_poly(std::ostream& o, const ResPolyRing& R, const ResPolynomial& f) { - auto end = poly_iter(R, f, 1); // end + auto end = ResPolynomialIterator(R, f, 1); // end int i = 0; - for (auto it = poly_iter(R, f); it != end; ++it, ++i) + for (auto it = ResPolynomialIterator(R, f); it != end; ++it, ++i) { R.resGausser().out(o, f.coeffs, i); res_const_packed_monomial mon = it.monomial(); @@ -195,7 +195,7 @@ inline void display_poly(std::ostream& o, const ResPolyRing& R, const poly& f) } } -bool check_poly(const ResPolyRing& R, const poly& f, const ResSchreyerOrder& O); +bool check_poly(const ResPolyRing& R, const ResPolynomial& f, const ResSchreyerOrder& O); #endif // Local Variables: diff --git a/M2/Macaulay2/e/schreyer-resolution/res-schreyer-frame.cpp b/M2/Macaulay2/e/schreyer-resolution/res-schreyer-frame.cpp index 6e942751363..cb4c05d5447 100644 --- a/M2/Macaulay2/e/schreyer-resolution/res-schreyer-frame.cpp +++ b/M2/Macaulay2/e/schreyer-resolution/res-schreyer-frame.cpp @@ -195,10 +195,10 @@ BettiDisplay SchreyerFrame::minimalBettiNumbers(bool stop_after_degree, std::cout << "displaying stats" << std::endl; showMemoryUsage(); monoid().show(); - std::cout << "total setPoly: " << poly_constructor::ncalls << std::endl; + std::cout << "total setPoly: " << ResPolynomialConstructor::ncalls << std::endl; std::cout << "total setPolyFromArray: " - << poly_constructor::ncalls_fromarray << std::endl; - std::cout << "total ~poly: " << poly::npoly_destructor << std::endl; + << ResPolynomialConstructor::ncalls_fromarray << std::endl; + std::cout << "total ~ResPolynomial: " << ResPolynomial::npoly_destructor << std::endl; std::cout << "total time for make matrix: " << timeMakeMatrix << std::endl; @@ -590,7 +590,7 @@ void SchreyerFrame::insertLevelZero(res_packed_monomial monom, } bool SchreyerFrame::insertLevelOne(res_packed_monomial monom, int deg, - poly& syzygy) + ResPolynomial& syzygy) { insertBasic(1, monom, deg); // deg is the actual degree of this element. component_index comp = monoid().get_component(monom); diff --git a/M2/Macaulay2/e/schreyer-resolution/res-schreyer-frame.hpp b/M2/Macaulay2/e/schreyer-resolution/res-schreyer-frame.hpp index 70a73c28e88..3c09cdcedcd 100644 --- a/M2/Macaulay2/e/schreyer-resolution/res-schreyer-frame.hpp +++ b/M2/Macaulay2/e/schreyer-resolution/res-schreyer-frame.hpp @@ -29,7 +29,7 @@ #include "schreyer-resolution/res-memblock.hpp" // for MemoryBlock #include "schreyer-resolution/res-moninfo.hpp" // for ResMonoid #include "schreyer-resolution/res-monomial-types.hpp" // for component_index -#include "schreyer-resolution/res-poly-ring.hpp" // for ResPolyRing, poly +#include "schreyer-resolution/res-poly-ring.hpp" // for ResPolyRing, ResPolynomial #include "schreyer-resolution/res-schreyer-order.hpp" // for ResSchreyerOrder #include // for pair @@ -52,7 +52,7 @@ struct FrameElement int mDegree; // actual degree, not slanted degree component_index mBegin; // points into next level's elements component_index mEnd; - poly mSyzygy; + ResPolynomial mSyzygy; FrameElement() {} FrameElement(res_packed_monomial monom) : mMonom(monom), mDegree(0), mBegin(-1), mEnd(-1) @@ -107,7 +107,7 @@ class SchreyerFrame bool insertLevelOne(res_packed_monomial monom, int degree, - poly& syzygy); // grabs syzygy + ResPolynomial& syzygy); // grabs syzygy // insertLevelOne: insert element. If the elements are not in order, then // false is returned. diff --git a/M2/Macaulay2/e/tower.cpp b/M2/Macaulay2/e/tower.cpp index bbe5c51a7ce..c5a964d691e 100644 --- a/M2/Macaulay2/e/tower.cpp +++ b/M2/Macaulay2/e/tower.cpp @@ -9,6 +9,8 @@ #include "polyring.hpp" #include "monoid.hpp" +#define TOWER_POLYNOMIAL_VAL(f) reinterpret_cast((f).poly_val) + Tower::~Tower() {} bool Tower::initialize(long charac0, M2_ArrayString names0, @@ -28,9 +30,9 @@ bool Tower::initialize(long charac0, } else { - const_poly *exts = new const_poly[extensions.size()]; + TowerPolynomial* exts = new TowerPolynomial[extensions.size()]; for (int i = 0; i < extensions.size(); i++) - exts[i] = TOWER_VAL(extensions[i]); + exts[i] = reinterpret_cast(extensions[i].poly_val); D = DRing::create(charac0, nvars, exts); delete[] exts; } @@ -79,13 +81,13 @@ void Tower::text_out(buffer &o) const int Tower::index_of_var(const ring_elem a) const { - poly f1 = TOWER_VAL(a); + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(a); return D->index_of_var(f1); } M2_arrayint Tower::support(const ring_elem a) const { - poly f1 = TOWER_VAL(a); + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(a); std::vector max_degs; D->degrees_of_vars(f1, max_degs); int nelems = 0; @@ -100,21 +102,21 @@ M2_arrayint Tower::support(const ring_elem a) const ring_elem Tower::from_long(long n) const { - poly f; + TowerPolynomial f; D->set_from_long(f, n); return TOWER_RINGELEM(f); } ring_elem Tower::from_int(mpz_srcptr n) const { - poly f; + TowerPolynomial f; D->set_from_int(f, n); return TOWER_RINGELEM(f); } bool Tower::from_rational(mpq_srcptr q, ring_elem &result) const { - poly f; + TowerPolynomial f; if (not D->set_from_mpq(f, q)) return false; result = TOWER_RINGELEM(f); return true; @@ -122,7 +124,7 @@ bool Tower::from_rational(mpq_srcptr q, ring_elem &result) const ring_elem Tower::var(int v) const { - poly f; + TowerPolynomial f; D->set_var(f, v); return TOWER_RINGELEM(f); } @@ -135,23 +137,23 @@ bool Tower::is_unit(const ring_elem f) const bool Tower::is_zero(const ring_elem f) const { - poly f1 = TOWER_VAL(f); + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); return D->is_zero(f1); } bool Tower::is_equal(const ring_elem f, const ring_elem g) const { - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); return D->is_equal(f1, g1); } int Tower::compare_elems(const ring_elem f, const ring_elem g) const { - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); return D->compare(f1, g1); } @@ -169,9 +171,9 @@ void Tower::remove(ring_elem &) const ring_elem Tower::negate(const ring_elem g) const { - poly f1; - poly g1 = TOWER_VAL(g); - poly h; + TowerPolynomial f1; + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); + TowerPolynomial h; D->set_zero(h); D->set_zero(f1); D->subtract(h, f1, g1); @@ -180,9 +182,9 @@ ring_elem Tower::negate(const ring_elem g) const ring_elem Tower::add(const ring_elem f, const ring_elem g) const { - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); - poly h; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); + TowerPolynomial h; D->set_zero(h); D->add(h, f1, g1); return TOWER_RINGELEM(h); @@ -190,9 +192,9 @@ ring_elem Tower::add(const ring_elem f, const ring_elem g) const ring_elem Tower::subtract(const ring_elem f, const ring_elem g) const { - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); - poly h; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); + TowerPolynomial h; D->set_zero(h); D->subtract(h, f1, g1); return TOWER_RINGELEM(h); @@ -200,9 +202,9 @@ ring_elem Tower::subtract(const ring_elem f, const ring_elem g) const ring_elem Tower::mult(const ring_elem f, const ring_elem g) const { - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); - poly h; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); + TowerPolynomial h; D->set_zero(h); D->mult(h, f1, g1); return TOWER_RINGELEM(h); @@ -210,8 +212,8 @@ ring_elem Tower::mult(const ring_elem f, const ring_elem g) const ring_elem Tower::invert(const ring_elem f) const { - poly f1 = TOWER_VAL(f); - poly h; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial h; D->set_zero(h); if (!D->invert(h, f1)) ERROR("element not invertible"); return TOWER_RINGELEM(h); @@ -219,9 +221,9 @@ ring_elem Tower::invert(const ring_elem f) const ring_elem Tower::divide(const ring_elem f, const ring_elem g) const { - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); - poly h; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); + TowerPolynomial h; D->set_zero(h); D->divide(h, f1, g1); return TOWER_RINGELEM(h); @@ -229,9 +231,9 @@ ring_elem Tower::divide(const ring_elem f, const ring_elem g) const ring_elem Tower::remainder(const ring_elem f, const ring_elem g) const { - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); - poly h; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); + TowerPolynomial h; D->set_zero(h); D->remainder(h, f1, g1); return TOWER_RINGELEM(h); @@ -239,7 +241,7 @@ ring_elem Tower::remainder(const ring_elem f, const ring_elem g) const ring_elem Tower::random() const { - poly f; + TowerPolynomial f; D->set_zero(f); D->set_random(f); return TOWER_RINGELEM(f); @@ -251,7 +253,7 @@ void Tower::elem_text_out(buffer &o, bool p_plus, bool p_parens) const { - D->elem_text_out(o, TOWER_VAL(f), p_one, p_plus, p_parens, names); + D->elem_text_out(o, TOWER_POLYNOMIAL_VAL(f), p_one, p_plus, p_parens, names); } class TowerEvaluator : public DPolyTraverser @@ -260,7 +262,7 @@ class TowerEvaluator : public DPolyTraverser const Ring *K; SumCollector *H; - poly f; + TowerPolynomial f; int first_var; const Ring *target; intarray vp; @@ -287,7 +289,7 @@ class TowerEvaluator : public DPolyTraverser int first_var0) : DPolyTraverser(T->D), map(map0), - f(TOWER_VAL(f0)), + f(TOWER_POLYNOMIAL_VAL(f0)), first_var(first_var0), nvars(T->n_vars()) { @@ -335,9 +337,9 @@ void Tower::syzygy(const ring_elem a, ring_elem Tower::gcd(const ring_elem f, const ring_elem g) const { - poly h; - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); + TowerPolynomial h; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); D->gcd(h, f1, g1); return TOWER_RINGELEM(h); } @@ -347,9 +349,9 @@ ring_elem Tower::gcd_extended(const ring_elem f, ring_elem &u, ring_elem &v) const { - poly h, u1, v1; - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); + TowerPolynomial h, u1, v1; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); D->gcd_coefficients(h, u1, v1, f1, g1); u = TOWER_RINGELEM(u1); v = TOWER_RINGELEM(v1); @@ -358,14 +360,14 @@ ring_elem Tower::gcd_extended(const ring_elem f, int Tower::degreeInVariable(int whichvar, const ring_elem f) const { - poly f1 = TOWER_VAL(f); + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); return D->degree(whichvar, f1); } ring_elem Tower::differentiate(int whichvar, const ring_elem f) const { - poly f1 = TOWER_VAL(f); - poly h = 0; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial h = 0; D->diff(whichvar, h, f1); return TOWER_RINGELEM(h); } @@ -380,17 +382,17 @@ ring_elem Tower::power_mod(const ring_elem f, mpz_srcptr n, const ring_elem g) const // f^n mod g { - poly f1 = TOWER_VAL(f); - poly g1 = TOWER_VAL(g); - poly h = 0; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial g1 = TOWER_POLYNOMIAL_VAL(g); + TowerPolynomial h = 0; D->power_mod(h, f1, n, g1); return TOWER_RINGELEM(h); } ring_elem Tower::lowerP(const ring_elem f) const { - poly f1 = TOWER_VAL(f); - poly h = 0; + TowerPolynomial f1 = TOWER_POLYNOMIAL_VAL(f); + TowerPolynomial h = 0; D->lowerP(h, f1); return TOWER_RINGELEM(h); } @@ -441,12 +443,12 @@ const RingElement *towerExtendedGCD(const RingElement *F, ring_elem Tower::translate(const PolynomialRing *R, ring_elem fR) const { - // create a poly in the Tower T, return it. + // create a TowerPolynomial in the Tower T, return it. const Monoid *M = R->getMonoid(); const Ring *K = R->getCoefficients(); int nvars = R->n_vars(); - poly result = 0; + TowerPolynomial result = 0; exponents exp = new int[nvars]; for (Nterm *t = fR; t != 0; t = t->next) { @@ -463,7 +465,7 @@ ring_elem Tower::translate(const PolynomialRing *R, ring_elem fR) const } #if 0 -ring_elem DPoly::translateFromTower(int level, const PolynomialRing *P, poly f) const +ring_elem DPoly::translateFromTower(int level, const PolynomialRing *P, TowerPolynomial f) const { if (f == 0) return 0; if (level == 0) @@ -487,17 +489,17 @@ ring_elem DPoly::translateFromTower(int level, const PolynomialRing *P, poly f) } } -ring_elem DRing::translateFromTower(const PolynomialRing *P, poly f) const +ring_elem DRing::translateFromTower(const PolynomialRing *P, TowerPolynomial f) const { - // create a polynomial in P from the tower poly fT - poly f = TOWER_VAL(fT); + // create a polynomial in P from the tower TowerPolynomial fT + TowerPolynomial f = TOWER_POLYNOMIAL_VAL(fT); return D.translateFromTower(level, P, f); } ring_elem Tower::translateFromTower(const PolynomialRing *P, ring_elem fT) const { - // create a polynomial in P from the tower poly fT - poly f = TOWER_VAL(fT); + // create a polynomial in P from the tower TowerPolynomial fT + TowerPolynomial f = TOWER_POLYNOMIAL_VAL(fT); return D->translateFromTower(P, f); } #endif