2#ifndef _aring_tower_hpp_
3#define _aring_tower_hpp_
166 const std::unique_ptr<ElementType[]>
mData;
172 for (
size_t i = 0; i <
mSize; i++)
mData[i] =
nullptr;
176 for (
size_t i = 0; i <
mSize; i++)
R.clear(
mData[i]);
191 const std::vector<std::string> &names,
192 const std::vector<ElementType> &extensions);
198 const std::vector<std::string> &names);
200 const std::vector<std::string> &new_names);
202 const std::vector<ElementType> &extensions);
335 else if (b ==
nullptr)
396 bool p_parens =
false)
const
442 bool p_parens)
const;
495 bool is_unit(ElementType f)
const;
496 bool is_zero(ElementType f)
const {
return f == 0; }
497 bool is_equal(ElementType f, ElementType g)
const {
return mRing.is_equal(mStartLevel, f, g); }
498 int compare_elems(ElementType f, ElementType g)
const {
return mRing.compare(mStartLevel, f, g); }
501 void init_set(ElementType &
result, ElementType a)
const {
result = a; }
504 void set(ElementType &
result, ElementType a)
const { mRing.remove(mStartLevel,
result);
result = a; }
507 void set_zero(ElementType &
result)
const {
result = 0; }
510 void set_from_long(ElementType &
result,
long r) {
511 r = r % mCharacteristic;
513 result = mRing.from_long(mStartLevel, r);
516 void set_from_int(ElementType &
result, mpz_ptr r);
518 bool set_from_mpq(ElementType &
result, mpq_srcptr r);
520 void set_random(ElementType &
result) {
result = mRing.random(mStartLevel); }
522 bool invert(ElementType &
result, ElementType a)
const
525 result = mRing.invert(mStartLevel, a);
529 void add(ElementType &
result, ElementType a, ElementType b)
const
532 else if (b == 0)
result = a;
535 ElementType a1 = mRing.copy(mStartLevel, a);
536 mRing.add_in_place(mStartLevel, a1, b);
541 void subtract(ElementType &
result, ElementType a, ElementType b)
const
543 ElementType a1 = mRing.copy(mStartLevel, a);
544 mRing.subtract_in_place(mStartLevel, a1, b);
550 if (a == 0 || b == 0)
return;
551 ElementType ab = mRing.mult(mStartLevel,a,b,
true);
552 mRing.subtract_in_place(mStartLevel,
result, ab);
555 void mult(ElementType &
result, ElementType a, ElementType b)
const
557 if (a == 0 || b == 0)
560 result = mRing.mult(mStartLevel, a, b,
true);
563 void divide(ElementType &
result, ElementType a, ElementType b)
const
565 if (a == 0 || b == 0)
569 ElementType a1 = mRing.copy(mStartLevel, a);
570 if (!mRing.division_in_place(mStartLevel, a1, b,
result))
572 mRing.dealloc_poly(a1);
576 void remainder(ElementType &
result, ElementType a, ElementType b)
const
578 if (a == 0 || b == 0)
582 result = mRing.copy(mStartLevel, a);
583 mRing.remainder(mStartLevel,
result, b);
589 ElementType h = mRing.copy(mStartLevel, a);
595 ElementType a1 =
reinterpret_cast<TowerPolynomial
>(a.
poly_val);
596 result = mRing.copy(mStartLevel, a1);
599 void swap(ElementType &a, ElementType &b)
const
606 void elem_text_out(
buffer &o,
610 bool p_parens)
const;
612 void gcd(ElementType &
result,
const ElementType f,
const ElementType g) {
result = mRing.gcd(mStartLevel,f,g); }
614 void gcd_coefficients(ElementType &result_gcd,
615 ElementType &result_u, ElementType &result_v,
616 const ElementType f,
const ElementType g)
618 result_gcd = mRing.gcd_coefficients(mStartLevel, f, g, result_u, result_v);
622 int degree(
int var,
const ElementType f)
const {
return mRing.degree(mStartLevel,var,f); }
623 void diff(
int var, ElementType &
result,
const ElementType f)
const {
result = mRing.diff(mStartLevel, var, f); }
624 int extension_degree(
int firstvar);
625 void power_mod(ElementType &
result,
const ElementType f, mpz_srcptr n,
const ElementType g)
const {
result = mRing.power_mod(mStartLevel, f, n, g); }
626 void lowerP(ElementType &
result,
const ElementType f) {
result = mRing.lowerP(mStartLevel, f); }
629 void extensions_text_out(
buffer &o)
const;
634 bool is_equal(
int level,
const ARingPolynomial f,
const ARingPolynomial g);
635 bool is_zero(ARingPolynomial f) {
return f == 0; }
648 void reset_degree_0(ARingPolynomial &f);
649 void reset_degree_n(
int level, ARingPolynomial &f);
651 void mult_by_coeff_0(ARingPolynomial &f,
long b);
652 void mult_by_coeff_n(
int level, ARingPolynomial &f, ARingPolynomial b);
655 void make_monic_0(ARingPolynomial & f,
long &result_multiplier);
656 void make_monic_n(
int level, ARingPolynomial & f, ARingPolynomial &result_multiplier);
658 bool make_monic3(
int level, ARingPolynomial & u1, ARingPolynomial &u2, ARingPolynomial &u3);
661 void add_in_place_0(ARingPolynomial &f,
const ARingPolynomial g);
662 void add_in_place_n(
int level, ARingPolynomial &f,
const ARingPolynomial g);
663 void add_in_place(
int level, ARingPolynomial &f,
const ARingPolynomial g);
665 void subtract_in_place_0(ARingPolynomial &f,
const ARingPolynomial g);
666 void subtract_in_place_n(
int level, ARingPolynomial &f,
const ARingPolynomial g);
667 void subtract_in_place(
int level, ARingPolynomial &f,
const ARingPolynomial g);
669 ARingPolynomial mult_0(
const ARingPolynomial f,
const ARingPolynomial g,
bool reduce_by_extension);
670 ARingPolynomial mult_n(
int level,
const ARingPolynomial f,
const ARingPolynomial g,
bool reduce_by_extension);
671 ARingPolynomial mult(
int level,
const ARingPolynomial f,
const ARingPolynomial g,
bool reduce_by_extension);
679 ARingPolynomial diff_n(
int level,
int whichvar,
const ARingPolynomial f);
682 ARingPolynomial mult_by_int_n(
int level,
long c,
const ARingPolynomial f);
683 ARingPolynomial mult_by_int(
int level,
long c,
const ARingPolynomial f);
688 void add_term(
int level, ARingPolynomial &
result,
long coeff,
exponents_t exp)
const;
exponents::Exponents exponents_t
Dense exponent-vector template [e_0, ..., e_{nvars-1}] for monomial operations.
M2::ARingZZpFFPACK — Z/p via FFLAS-FFPACK's Givaro::Modular<double> field.
Shared base of the aring framework (namespace M2) that unifies the engine's coefficient rings.
Single-level view of a tower-polynomial ring: a DPoly plus a fixed working level and a Tower-flavoure...
Element(const ARingTower &_R, const ElementType &value)
Element(const ARingTower &_R)
ElementType & operator[](size_t idx)
const std::unique_ptr< ElementType[]> mData
ElementArray(const ARingTower &_R, size_t size)
const ElementType & operator[](size_t idx) const
const ElementType * data() const
void text_out(buffer &o) const
ARingPolynomial ElementType
bool is_unit(ElementType f) const
void power_mpz(elem &result, elem a, mpz_srcptr n) const
void invert(elem &result, elem a) const
void divide(elem &result, elem a, elem b) const
ARingTower(const BaseRingType &baseRing, const std::vector< std::string > &names, const std::vector< ElementType > &extensions)
bool set_from_mpq(elem &result, mpq_srcptr a) const
void copy(elem &result, elem a) const
void swap(ElementType &a, ElementType &b) const
void set_from_long(elem &result, long a) const
void dealloc_poly(ARingPolynomial &f) const
static const RingID ringID
void reset_degree(ARingPolynomial &f) const
const ARingZZpFFPACK & baseRing() const
void to_ring_elem(ring_elem &result, const ElementType &a) const
void increase_capacity(int newdeg, ARingPolynomial &f) const
void syzygy(ElementType a, ElementType b, ElementType &x, ElementType &y) const
const std::vector< std::string > mVarNames
void set(elem &result, elem a) const
void eval(const RingMap *map, const elem f, int first_var, ring_elem &result) const
ARingZZpFFPACK BaseRingType
bool is_zero(ElementType f) const
ARingPolynomial alloc_poly_n(int deg) const
bool set_from_BigReal(elem &result, gmp_RR a) const
std::vector< ElementType > mExtensions
void subtract(elem &result, elem a, elem b) const
int compare_elems(ElementType f, ElementType g) const
bool is_equal(ElementType f, ElementType g) const
const std::vector< std::string > & varNames() const
ARingPolynomial alloc_poly_0(int deg) const
void mult_by_coeff(ARingPolynomial &f, const BaseCoefficientType &b) const
BaseRingType::ElementType BaseCoefficientType
void negate(elem &result, elem a) const
void negate_in_place(int level, ARingPolynomial &f) const
void mult(elem &result, elem a, elem b) const
void set_from_mpz(elem &result, mpz_srcptr a) const
void power(elem &result, elem a, int n) const
void clear(elem &f) const
bool is_one(int level, const ARingPolynomial f) const
void subtract_multiple(elem &result, elem a, elem b) const
ElementType from_ring_elem_const(const ring_elem &a) const
void from_ring_elem(ElementType &result, const ring_elem &a) const
void random(ElementType &result) const
void add_in_place(int level, ARingPolynomial &f, const ARingPolynomial g) const
const ARingZZpFFPACK & mBaseRing
friend class ARingTowerEvaluator
void add(elem &result, elem a, elem b) const
static ARingTower * create(const BaseRingType &baseRing, const std::vector< std::string > &names)
unsigned int computeHashValue(const elem &a) const
void elem_text_out(buffer &o, ElementType a, bool p_one=true, bool p_plus=false, bool p_parens=false) const
void set_var(elem &result, int v) const
unsigned long characteristic() const
void init_set(elem &result, elem a) const
ARingPolynomial var(int level, int v) const
void subtract_in_place(int level, ARingPolynomial &f, const ARingPolynomial g) const
void set_zero(elem &result) const
void extensions_text_out(buffer &o) const
void init(elem &result) const
FieldType::Element ElementType
wrapper for the FFPACK::ModularBalanced<double> field implementation
const ElementType & value() const
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
void subtract(int &result, int a, int b)
void subtract_multiple(int &result, int a, int b)
struct ARingPolynomialStruct * ARingPolynomial
VALGRIND_MAKE_MEM_DEFINED & result(result)
void set(DMat< RT > &A, MatrixWindow wA, const DMat< RT > &B, MatrixWindow wB)
void mult(const DMatZZpFFPACK &A, const DMatZZpFFPACK &B, DMatZZpFFPACK &C)
const mpreal remainder(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal random(unsigned int seed=0)
#define TOWER_RINGELEM(a)
ring_elem — the universal value type carried by every Ring* in the engine.
ARingZZpFFPACK::ElementType * coeffs
Heap-allocated node of an ARingTower polynomial: a dense degree-indexed coefficient array that recurs...
Singly linked-list node carrying one term of a polynomial-ring element.
Engine-wide stylistic constants: LT / EQ / GT codes, INTSIZE, GEOHEAP_SIZE.