1 | #ifndef TGB_INTERNAL_H |
---|
2 | #define TGB_INTERNAL_H |
---|
3 | //!\file tgb_internal.h |
---|
4 | /**************************************** |
---|
5 | * Computer Algebra System SINGULAR * |
---|
6 | ****************************************/ |
---|
7 | /* $Id: tgb_internal.h,v 1.54 2007-02-20 10:47:46 bricken Exp $ */ |
---|
8 | /* |
---|
9 | * ABSTRACT: tgb internal .h file |
---|
10 | */ |
---|
11 | #include <omalloc.h> |
---|
12 | #include "p_polys.h" |
---|
13 | |
---|
14 | #include "ideals.h" |
---|
15 | #include "ring.h" |
---|
16 | #include "febase.h" |
---|
17 | #include "structs.h" |
---|
18 | #include "polys.h" |
---|
19 | #include "stdlib.h" |
---|
20 | //#define USE_NORO 1 |
---|
21 | //#define NORO_CACHE 1 |
---|
22 | #define NORO_SPARSE_ROWS_PRE 1 |
---|
23 | #ifdef NORO_CACHE |
---|
24 | //#include <map> |
---|
25 | #include <vector> |
---|
26 | #endif |
---|
27 | #ifdef HAVE_BOOST_DYNAMIC_BITSET_HPP |
---|
28 | #define HAVE_BOOST 1 |
---|
29 | #endif |
---|
30 | //#define HAVE_BOOST 1 |
---|
31 | //#define USE_STDVECBOOL 1 |
---|
32 | #ifdef HAVE_BOOST |
---|
33 | #include "boost/dynamic_bitset.hpp" |
---|
34 | #include <vector> |
---|
35 | using boost::dynamic_bitset; |
---|
36 | using std::vector; |
---|
37 | #endif |
---|
38 | #ifdef USE_STDVECBOOL |
---|
39 | #include <vector> |
---|
40 | using std::vector; |
---|
41 | #endif |
---|
42 | #include "kutil.h" |
---|
43 | #include "kInline.cc" |
---|
44 | #include "kstd1.h" |
---|
45 | #include "kbuckets.h" |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | //#define TGB_DEBUG |
---|
51 | #define FULLREDUCTIONS |
---|
52 | #define HANS_IDEA |
---|
53 | //#define HALFREDUCTIONS |
---|
54 | //#define HEAD_BIN |
---|
55 | //#define HOMOGENEOUS_EXAMPLE |
---|
56 | #define REDTAIL_S |
---|
57 | #define PAR_N 100 |
---|
58 | #define PAR_N_F4 5000 |
---|
59 | #define AC_NEW_MIN 2 |
---|
60 | #define AC_FLATTEN 1 |
---|
61 | |
---|
62 | //#define FIND_DETERMINISTIC |
---|
63 | //#define REDTAIL_PROT |
---|
64 | //#define QUICK_SPOLY_TEST |
---|
65 | class PolySimple{ |
---|
66 | public: |
---|
67 | PolySimple(poly p){ |
---|
68 | impl=p; |
---|
69 | } |
---|
70 | PolySimple(){ |
---|
71 | impl=NULL; |
---|
72 | } |
---|
73 | PolySimple(const PolySimple& a){ |
---|
74 | //impl=p_Copy(a.impl,currRing); |
---|
75 | impl=a.impl; |
---|
76 | } |
---|
77 | PolySimple& operator=(const PolySimple& p2){ |
---|
78 | //p_Delete(&impl,currRing); |
---|
79 | //impl=p_Copy(p2.impl,currRing); |
---|
80 | impl=p2.impl; |
---|
81 | return *this; |
---|
82 | } |
---|
83 | ~PolySimple(){ |
---|
84 | //p_Delete(&impl,currRing); |
---|
85 | } |
---|
86 | bool operator< (const PolySimple& other) const{ |
---|
87 | return pLmCmp(impl,other.impl)<0; |
---|
88 | } |
---|
89 | bool operator==(const PolySimple& other){ |
---|
90 | return pLmEqual(impl,other.impl); |
---|
91 | } |
---|
92 | poly impl; |
---|
93 | |
---|
94 | }; |
---|
95 | class DataNoroCacheNode; |
---|
96 | class MonRedRes{ |
---|
97 | public: |
---|
98 | poly p; |
---|
99 | number coef; |
---|
100 | BOOLEAN changed; |
---|
101 | int len; |
---|
102 | BOOLEAN onlyBorrowed; |
---|
103 | bool operator<(const MonRedRes& other) const{ |
---|
104 | int cmp=p_LmCmp(p,other.p,currRing); |
---|
105 | if ((cmp<0)||((cmp==0)&&((onlyBorrowed)&&(!(other.onlyBorrowed))))){ |
---|
106 | return true; |
---|
107 | } else return false; |
---|
108 | } |
---|
109 | DataNoroCacheNode* ref; |
---|
110 | MonRedRes(){ |
---|
111 | ref=NULL; |
---|
112 | p=NULL; |
---|
113 | } |
---|
114 | }; |
---|
115 | class MonRedResNP{ |
---|
116 | public: |
---|
117 | number coef; |
---|
118 | |
---|
119 | |
---|
120 | DataNoroCacheNode* ref; |
---|
121 | MonRedResNP(){ |
---|
122 | ref=NULL; |
---|
123 | } |
---|
124 | }; |
---|
125 | struct sorted_pair_node{ |
---|
126 | //criterium, which is stable 0. small lcm 1. small i 2. small j |
---|
127 | wlen_type expected_length; |
---|
128 | poly lcm_of_lm; |
---|
129 | int i; |
---|
130 | int j; |
---|
131 | int deg; |
---|
132 | |
---|
133 | |
---|
134 | }; |
---|
135 | |
---|
136 | |
---|
137 | class NoroPlaceHolder{ |
---|
138 | public: |
---|
139 | DataNoroCacheNode* ref; |
---|
140 | number coef; |
---|
141 | }; |
---|
142 | |
---|
143 | //static ideal debug_Ideal; |
---|
144 | |
---|
145 | |
---|
146 | struct poly_list_node{ |
---|
147 | poly p; |
---|
148 | poly_list_node* next; |
---|
149 | }; |
---|
150 | |
---|
151 | struct int_pair_node{ |
---|
152 | int_pair_node* next; |
---|
153 | int a; |
---|
154 | int b; |
---|
155 | }; |
---|
156 | struct monom_poly{ |
---|
157 | poly m; |
---|
158 | poly f; |
---|
159 | }; |
---|
160 | struct mp_array_list{ |
---|
161 | monom_poly* mp; |
---|
162 | int size; |
---|
163 | mp_array_list* next; |
---|
164 | }; |
---|
165 | |
---|
166 | |
---|
167 | struct poly_array_list{ |
---|
168 | poly* p; |
---|
169 | int size; |
---|
170 | poly_array_list* next; |
---|
171 | }; |
---|
172 | class slimgb_alg |
---|
173 | { |
---|
174 | public: |
---|
175 | slimgb_alg(ideal I, int syz_comp,BOOLEAN F4); |
---|
176 | void introduceDelayedPairs(poly* pa,int s); |
---|
177 | virtual ~slimgb_alg(); |
---|
178 | void cleanDegs(int lower, int upper); |
---|
179 | #ifndef HAVE_BOOST |
---|
180 | #ifdef USE_STDVECBOOL |
---|
181 | vector<vector<bool> > states; |
---|
182 | #else |
---|
183 | char** states; |
---|
184 | #endif |
---|
185 | #else |
---|
186 | vector<dynamic_bitset<> > states; |
---|
187 | #endif |
---|
188 | ideal add_later; |
---|
189 | ideal S; |
---|
190 | ring r; |
---|
191 | int* lengths; |
---|
192 | wlen_type* weighted_lengths; |
---|
193 | long* short_Exps; |
---|
194 | kStrategy strat; |
---|
195 | int* T_deg; |
---|
196 | int* T_deg_full; |
---|
197 | poly tmp_lm; |
---|
198 | poly* tmp_pair_lm; |
---|
199 | sorted_pair_node** tmp_spn; |
---|
200 | poly* expandS; |
---|
201 | poly* gcd_of_terms; |
---|
202 | int_pair_node* soon_free; |
---|
203 | sorted_pair_node** apairs; |
---|
204 | #if 0 |
---|
205 | BOOLEAN* modifiedS; |
---|
206 | #endif |
---|
207 | #ifdef TGB_RESORT_PAIRS |
---|
208 | bool* replaced; |
---|
209 | #endif |
---|
210 | poly_list_node* to_destroy; |
---|
211 | //for F4 |
---|
212 | mp_array_list* F; |
---|
213 | poly_array_list* F_minus; |
---|
214 | |
---|
215 | //end for F4 |
---|
216 | #ifdef HEAD_BIN |
---|
217 | struct omBin_s* HeadBin; |
---|
218 | #endif |
---|
219 | unsigned int reduction_steps; |
---|
220 | int n; |
---|
221 | //! array_lengths should be greater equal n; |
---|
222 | int syz_comp; |
---|
223 | int array_lengths; |
---|
224 | int normal_forms; |
---|
225 | int current_degree; |
---|
226 | int Rcounter; |
---|
227 | int last_index; |
---|
228 | int max_pairs; |
---|
229 | int pair_top; |
---|
230 | int easy_product_crit; |
---|
231 | int extended_product_crit; |
---|
232 | int average_length; |
---|
233 | int lastDpBlockStart; |
---|
234 | int lastCleanedDeg; |
---|
235 | BOOLEAN isDifficultField; |
---|
236 | BOOLEAN completed; |
---|
237 | BOOLEAN is_homog; |
---|
238 | BOOLEAN tailReductions; |
---|
239 | BOOLEAN eliminationProblem; |
---|
240 | BOOLEAN F4_mode; |
---|
241 | BOOLEAN nc; |
---|
242 | #ifdef TGB_RESORT_PAIRS |
---|
243 | BOOLEAN used_b; |
---|
244 | #endif |
---|
245 | }; |
---|
246 | class red_object{ |
---|
247 | public: |
---|
248 | kBucket_pt bucket; |
---|
249 | poly p; |
---|
250 | unsigned long sev; |
---|
251 | int sugar; |
---|
252 | void flatten(); |
---|
253 | void validate(); |
---|
254 | wlen_type initial_quality; |
---|
255 | void adjust_coefs(number c_r, number c_ac_r); |
---|
256 | wlen_type guess_quality(slimgb_alg* c); |
---|
257 | int clear_to_poly(); |
---|
258 | void canonicalize(); |
---|
259 | }; |
---|
260 | |
---|
261 | |
---|
262 | enum calc_state |
---|
263 | { |
---|
264 | UNCALCULATED, |
---|
265 | HASTREP//, |
---|
266 | //UNIMPORTANT, |
---|
267 | //SOONTREP |
---|
268 | }; |
---|
269 | static BOOLEAN pair_cmp(sorted_pair_node* a,sorted_pair_node* b); |
---|
270 | template <class len_type, class set_type> int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set); |
---|
271 | static int add_to_reductors(slimgb_alg* c, poly h, int len, int ecart, BOOLEAN simplified=FALSE); |
---|
272 | static int bucket_guess(kBucket* bucket); |
---|
273 | static poly redNFTail (poly h,const int sl,kStrategy strat, int len); |
---|
274 | static poly redNF2 (poly h,slimgb_alg* c , int &len, number& m,int n=0); |
---|
275 | void free_sorted_pair_node(sorted_pair_node* s, ring r); |
---|
276 | static void shorten_tails(slimgb_alg* c, poly monom); |
---|
277 | static void replace_pair(int & i, int & j, slimgb_alg* c); |
---|
278 | //static sorted_pair_node** add_to_basis(poly h, int i, int j,slimgb_alg* c, int* ip=NULL); |
---|
279 | static void do_this_spoly_stuff(int i,int j,slimgb_alg* c); |
---|
280 | //ideal t_rep_gb(ring r,ideal arg_I); |
---|
281 | static BOOLEAN has_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* state); |
---|
282 | static int* make_connections(int from, poly bound, slimgb_alg* c); |
---|
283 | static int* make_connections(int from, int to, poly bound, slimgb_alg* c); |
---|
284 | void now_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c); |
---|
285 | static void soon_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c); |
---|
286 | static int pLcmDeg(poly a, poly b); |
---|
287 | static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen); |
---|
288 | static BOOLEAN find_next_pair(slimgb_alg* c, BOOLEAN go_higher=TRUE); |
---|
289 | |
---|
290 | static sorted_pair_node* pop_pair(slimgb_alg* c); |
---|
291 | static BOOLEAN no_pairs(slimgb_alg* c); |
---|
292 | void clean_top_of_pair_list(slimgb_alg* c); |
---|
293 | static void super_clean_top_of_pair_list(slimgb_alg* c); |
---|
294 | static BOOLEAN state_is(calc_state state, const int & i, const int & j, slimgb_alg* c); |
---|
295 | static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, slimgb_alg* c=NULL); |
---|
296 | static int tgb_pair_better_gen(const void* ap,const void* bp); |
---|
297 | static poly redTailShort(poly h, kStrategy strat); |
---|
298 | static poly gcd_of_terms(poly p, ring r); |
---|
299 | static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c); |
---|
300 | static poly kBucketGcd(kBucket* b, ring r); |
---|
301 | static void multi_reduction(red_object* los, int & losl, slimgb_alg* c); |
---|
302 | int slim_nsize(number n, ring r); |
---|
303 | sorted_pair_node* quick_pop_pair(slimgb_alg* c); |
---|
304 | sorted_pair_node* top_pair(slimgb_alg* c); |
---|
305 | sorted_pair_node** add_to_basis_ideal_quotient(poly h, slimgb_alg* c, int* ip);//, BOOLEAN new_pairs=TRUE); |
---|
306 | sorted_pair_node** spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c); |
---|
307 | int kFindDivisibleByInS_easy(kStrategy strat,const red_object & obj); |
---|
308 | int tgb_pair_better_gen2(const void* ap,const void* bp); |
---|
309 | int kFindDivisibleByInS_easy(kStrategy strat,poly p, long sev); |
---|
310 | //static int quality(poly p, int len, slimgb_alg* c); |
---|
311 | /** |
---|
312 | makes on each red_object in a region a single_step |
---|
313 | **/ |
---|
314 | class reduction_step{ |
---|
315 | public: |
---|
316 | /// we assume hat all occuring red_objects have same lm, and all |
---|
317 | /// occ. lm's in r[l...u] are the same, only reductor does not occur |
---|
318 | virtual void reduce(red_object* r, int l, int u); |
---|
319 | //int reduction_id; |
---|
320 | virtual ~reduction_step(); |
---|
321 | slimgb_alg* c; |
---|
322 | int reduction_id; |
---|
323 | }; |
---|
324 | class simple_reducer:public reduction_step{ |
---|
325 | public: |
---|
326 | poly p; |
---|
327 | kBucket_pt fill_back; |
---|
328 | int p_len; |
---|
329 | int reducer_deg; |
---|
330 | simple_reducer(poly p, int p_len,int reducer_deg, slimgb_alg* c =NULL){ |
---|
331 | this->p=p; |
---|
332 | this->reducer_deg=reducer_deg; |
---|
333 | assume(p_len==pLength(p)); |
---|
334 | this->p_len=p_len; |
---|
335 | this->c=c; |
---|
336 | } |
---|
337 | virtual void pre_reduce(red_object* r, int l, int u); |
---|
338 | virtual void reduce(red_object* r, int l, int u); |
---|
339 | ~simple_reducer(); |
---|
340 | |
---|
341 | |
---|
342 | virtual void do_reduce(red_object & ro); |
---|
343 | }; |
---|
344 | |
---|
345 | //class sum_canceling_reducer:public reduction_step { |
---|
346 | // void reduce(red_object* r, int l, int u); |
---|
347 | //}; |
---|
348 | struct find_erg{ |
---|
349 | poly expand; |
---|
350 | int expand_length; |
---|
351 | int to_reduce_u; |
---|
352 | int to_reduce_l; |
---|
353 | int reduce_by;//index of reductor |
---|
354 | BOOLEAN fromS;//else from los |
---|
355 | |
---|
356 | }; |
---|
357 | |
---|
358 | static void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c); |
---|
359 | static void finalize_reduction_step(reduction_step* r); |
---|
360 | |
---|
361 | template <class len_type, class set_type> int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set){ |
---|
362 | //Print("POSHELER:%d",sizeof(wlen_type)); |
---|
363 | int length=strat->sl; |
---|
364 | int i; |
---|
365 | int an = 0; |
---|
366 | int en= length; |
---|
367 | |
---|
368 | if ((len>setL[length]) |
---|
369 | || ((len==setL[length]) && (pLmCmp(set[length],p)== -1))) |
---|
370 | return length+1; |
---|
371 | |
---|
372 | loop |
---|
373 | { |
---|
374 | if (an >= en-1) |
---|
375 | { |
---|
376 | if ((len<setL[an]) |
---|
377 | || ((len==setL[an]) && (pLmCmp(set[an],p) == 1))) return an; |
---|
378 | return en; |
---|
379 | } |
---|
380 | i=(an+en) / 2; |
---|
381 | if ((len<setL[i]) |
---|
382 | || ((len==setL[i]) && (pLmCmp(set[i],p) == 1))) en=i; |
---|
383 | //else if ((len>setL[i]) |
---|
384 | //|| ((len==setL[i]) && (pLmCmp(set[i],p) == -1))) an=i; |
---|
385 | else an=i; |
---|
386 | } |
---|
387 | |
---|
388 | } |
---|
389 | |
---|
390 | |
---|
391 | static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c); |
---|
392 | wlen_type pELength(poly p, ring r); |
---|
393 | void simplest_gauss_modp(number* a, int nrows,int ncols); |
---|
394 | // a: a[0,0],a[0,1]....a[nrows-1,ncols-1] |
---|
395 | // assume: field is Zp |
---|
396 | #endif |
---|