Macaulay2 Engine
Loading...
Searching...
No Matches
montableZZ.hpp
Go to the documentation of this file.
1#ifndef __montableZZ_h
2#define __montableZZ_h
3
40
41#include <vector>
42#include <memory>
43#include <algorithm>
44#include <stdio.h>
45#include <stddef.h>
46
47#include "ExponentVector.hpp"
48#include "buffer.hpp"
49#include "newdelete.hpp"
50#include "style.hpp"
51
52/* "Tricks" used in this implementation */
53/*
54 1. exponent vectors: these look like: [e1, ..., en],
55 where n is the number of variables. HOWEVER, these
56 exponents are never created or freed by these routines,
57 so if they have more entries (e.g. a "sugar" homogenization)
58 then that (those) value(s) are ignored.
59 2. comparison routine: elements are kept in (increasing?) lex order.
60 Is this really an OK idea?
61 */
62
78{
79 public:
91 struct mon_term : public our_new_delete
92 {
95 exponents_t _lead; /* Who owns this? */
96 unsigned long _mask;
97 int _val;
98 mpz_srcptr _coeff; /* If not given, this is NULL. Ig given, it points to data elsewhere (e.g. a GB) which will outlive this data */
99 };
100
101 static MonomialTableZZ *make(int nvars);
102 /* Create a zero element table */
103
105
106 void insert(mpz_srcptr coeff, exponents_t exp, int comp, int id);
107 /* Insert [coeff,exp,comp,id] into the table. If there is already
108 an element which is <= [exp,comp], this triple is still
109 inserted. If that is not desired, use find_divisors.
110 */
111
112 bool is_weak_member(mpz_srcptr c, exponents_t exp, int comp) const;
113 // Is [c,exp,comp] in the submodule generated by the terms in 'this'?
114 // Maybe a gbvector should be returned?
115
116 bool is_strong_member(mpz_srcptr c, exponents_t exp, int comp) const;
117 // Is [c,exp,comp] divisible by one of the terms in 'this'?
118
119 int find_smallest_coeff_divisor(exponents_t exp, int comp) const;
120 // Of all of the elements which divide exp*comp, return the index of the
121 // smallest coefficient one, or return -1, if no element divides exp*comp.
122
123 int find_term_divisors(int max,
124 mpz_srcptr coeff,
125 exponents_t exp,
126 int comp,
127 VECTOR(mon_term *) *result = nullptr) const;
128 /* max: the max number of divisors to find.
129 exp: the monomial whose divisors we seek.
130 result: an array of mon_term's.
131 return value: length of this array, i.e. the number of matches found */
132
134 exponents_t exp,
135 int comp,
136 VECTOR(mon_term *) *result = nullptr) const;
137
138 mon_term *find_exact(mpz_srcptr coeff, exponents_t exp, int comp) const;
139 /* If this returns non-NULL, it is valid to grab the 'val' field, and/or to
140 assign to it.
141 All other fields should be considered read only */
142
143 mon_term *find_exact_monomial(exponents_t exp, int comp, int first_val) const;
144 // Is there an element 'exp*comp' with _val >= first_val? If so, return the
145 // mon_term.
146 // Otherwise return 0.
147
148 void change_coefficient(mon_term *t, mpz_srcptr new_coeff, int new_id);
149
150 static void find_weak_generators(int nvars,
151 const VECTOR(mpz_srcptr) & coeffs,
152 const VECTOR(exponents_t) & exps,
153 const VECTOR(int) & comps,
154 VECTOR(int) & result_positions,
155 bool use_stable_sort = true);
156
157 static void find_strong_generators(int nvars,
158 const VECTOR(mpz_srcptr) & coeffs,
159 const VECTOR(exponents_t) & exps,
160 const VECTOR(int) & comps,
161 VECTOR(int) & result_positions);
162
163 void show_mon_term(FILE *fil, mon_term *t) const; /* Only for debugging */
164 void show_mon_term(buffer &o, mon_term *t) const; /* Only for debugging */
165 void show_mon_term(buffer &o,
166 mpz_srcptr coeff,
167 exponents_t lead,
168 int comp) const; /* Only for debugging */
169 void show(FILE *fil) const; /* Only for debugging */
170 void showmontable();
171 void show_weak(FILE *fil,
172 mpz_srcptr coeff,
173 exponents_t exp,
174 int comp,
175 int val) const; /* Debugging */
176
177 private:
180 VECTOR(mon_term *) _head; /* One per component */
181
182 static mon_term *make_list_head();
183};
184
185#endif
186
187// Local Variables:
188// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
189// indent-tabs-mode: nil
190// End:
exponents::Exponents exponents_t
Dense exponent-vector template [e_0, ..., e_{nvars-1}] for monomial operations.
Append-only GC-backed byte buffer used throughout the engine for text output.
bool is_strong_member(mpz_srcptr c, exponents_t exp, int comp) const
mon_term * find_exact_monomial(exponents_t exp, int comp, int first_val) const
static mon_term * make_list_head()
void insert(mpz_srcptr coeff, exponents_t exp, int comp, int id)
VECTOR(mon_term *) _head
static MonomialTableZZ * make(int nvars)
void show_mon_term(FILE *fil, mon_term *t) const
void change_coefficient(mon_term *t, mpz_srcptr new_coeff, int new_id)
bool is_weak_member(mpz_srcptr c, exponents_t exp, int comp) const
static void find_strong_generators(int nvars, const VECTOR(mpz_srcptr) &coeffs, const VECTOR(exponents_t) &exps, const VECTOR(int) &comps, VECTOR(int) &result_positions)
void show(FILE *fil) const
int find_smallest_coeff_divisor(exponents_t exp, int comp) const
int find_monomial_divisors(int max, exponents_t exp, int comp, VECTOR(mon_term *) *result=nullptr) const
static void find_weak_generators(int nvars, const VECTOR(mpz_srcptr) &coeffs, const VECTOR(exponents_t) &exps, const VECTOR(int) &comps, VECTOR(int) &result_positions, bool use_stable_sort=true)
mon_term * find_exact(mpz_srcptr coeff, exponents_t exp, int comp) const
void show_weak(FILE *fil, mpz_srcptr coeff, exponents_t exp, int comp, int val) const
int find_term_divisors(int max, mpz_srcptr coeff, exponents_t exp, int comp, VECTOR(mon_term *) *result=nullptr) const
MonomialTable analogue for monomials carrying a ZZ coefficient.
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define VECTOR(T)
Definition newdelete.hpp:78
our_new_delete — per-class opt-in routing of new / delete through bdwgc.
#define max(a, b)
Definition polyroots.cpp:52
MonomialTable::mon_term plus an _coeff slot pointing at the entry's leading ZZ coefficient (or nullpt...
Engine-wide stylistic constants: LT / EQ / GT codes, INTSIZE, GEOHEAP_SIZE.