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.41 2006-06-08 06:06:51 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 HAVE_BOOST 1 |
---|
21 | #define USE_STDVECBOOL 1 |
---|
22 | #ifdef HAVE_BOOST |
---|
23 | #include "boost/dynamic_bitset.hpp" |
---|
24 | #include <vector> |
---|
25 | using boost::dynamic_bitset; |
---|
26 | using std::vector; |
---|
27 | #endif |
---|
28 | #ifdef USE_STDVECBOOL |
---|
29 | #include <vector> |
---|
30 | using std::vector; |
---|
31 | #endif |
---|
32 | #include "kutil.h" |
---|
33 | #include "kInline.cc" |
---|
34 | #include "kstd1.h" |
---|
35 | #include "kbuckets.h" |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | //#define TGB_DEBUG |
---|
41 | #define FULLREDUCTIONS |
---|
42 | #define HANS_IDEA |
---|
43 | //#define HALFREDUCTIONS |
---|
44 | //#define HEAD_BIN |
---|
45 | //#define HOMOGENEOUS_EXAMPLE |
---|
46 | #define REDTAIL_S |
---|
47 | #define PAR_N 100 |
---|
48 | #define PAR_N_F4 5000 |
---|
49 | #define AC_NEW_MIN 2 |
---|
50 | #define AC_FLATTEN 1 |
---|
51 | |
---|
52 | //#define FIND_DETERMINISTIC |
---|
53 | //#define REDTAIL_PROT |
---|
54 | //#define QUICK_SPOLY_TEST |
---|
55 | struct sorted_pair_node{ |
---|
56 | //criterium, which is stable 0. small lcm 1. small i 2. small j |
---|
57 | wlen_type expected_length; |
---|
58 | poly lcm_of_lm; |
---|
59 | int i; |
---|
60 | int j; |
---|
61 | int deg; |
---|
62 | |
---|
63 | |
---|
64 | }; |
---|
65 | |
---|
66 | |
---|
67 | //static ideal debug_Ideal; |
---|
68 | |
---|
69 | |
---|
70 | struct poly_list_node{ |
---|
71 | poly p; |
---|
72 | poly_list_node* next; |
---|
73 | }; |
---|
74 | |
---|
75 | struct int_pair_node{ |
---|
76 | int_pair_node* next; |
---|
77 | int a; |
---|
78 | int b; |
---|
79 | }; |
---|
80 | struct monom_poly{ |
---|
81 | poly m; |
---|
82 | poly f; |
---|
83 | }; |
---|
84 | struct mp_array_list{ |
---|
85 | monom_poly* mp; |
---|
86 | int size; |
---|
87 | mp_array_list* next; |
---|
88 | }; |
---|
89 | |
---|
90 | |
---|
91 | struct poly_array_list{ |
---|
92 | poly* p; |
---|
93 | int size; |
---|
94 | poly_array_list* next; |
---|
95 | }; |
---|
96 | class slimgb_alg |
---|
97 | { |
---|
98 | public: |
---|
99 | slimgb_alg(ideal I, int syz_comp,BOOLEAN F4); |
---|
100 | virtual ~slimgb_alg(); |
---|
101 | #ifndef HAVE_BOOST |
---|
102 | #ifdef USE_STDVECBOOL |
---|
103 | vector<vector<bool> > states; |
---|
104 | #else |
---|
105 | char** states; |
---|
106 | #endif |
---|
107 | #else |
---|
108 | vector<dynamic_bitset<> > states; |
---|
109 | #endif |
---|
110 | ideal add_later; |
---|
111 | ideal S; |
---|
112 | ring r; |
---|
113 | int* lengths; |
---|
114 | wlen_type* weighted_lengths; |
---|
115 | long* short_Exps; |
---|
116 | kStrategy strat; |
---|
117 | int* T_deg; |
---|
118 | int* T_deg_full; |
---|
119 | poly tmp_lm; |
---|
120 | poly* tmp_pair_lm; |
---|
121 | sorted_pair_node** tmp_spn; |
---|
122 | poly* expandS; |
---|
123 | poly* gcd_of_terms; |
---|
124 | int_pair_node* soon_free; |
---|
125 | sorted_pair_node** apairs; |
---|
126 | #if 0 |
---|
127 | BOOLEAN* modifiedS; |
---|
128 | #endif |
---|
129 | #ifdef TGB_RESORT_PAIRS |
---|
130 | bool* replaced; |
---|
131 | #endif |
---|
132 | poly_list_node* to_destroy; |
---|
133 | //for F4 |
---|
134 | mp_array_list* F; |
---|
135 | poly_array_list* F_minus; |
---|
136 | |
---|
137 | //end for F4 |
---|
138 | #ifdef HEAD_BIN |
---|
139 | struct omBin_s* HeadBin; |
---|
140 | #endif |
---|
141 | unsigned int reduction_steps; |
---|
142 | int n; |
---|
143 | //! array_lengths should be greater equal n; |
---|
144 | int syz_comp; |
---|
145 | int array_lengths; |
---|
146 | int normal_forms; |
---|
147 | int current_degree; |
---|
148 | int Rcounter; |
---|
149 | int last_index; |
---|
150 | int max_pairs; |
---|
151 | int pair_top; |
---|
152 | int easy_product_crit; |
---|
153 | int extended_product_crit; |
---|
154 | int average_length; |
---|
155 | BOOLEAN isDifficultField; |
---|
156 | BOOLEAN completed; |
---|
157 | BOOLEAN is_homog; |
---|
158 | |
---|
159 | BOOLEAN eliminationProblem; |
---|
160 | BOOLEAN F4_mode; |
---|
161 | BOOLEAN nc; |
---|
162 | #ifdef TGB_RESORT_PAIRS |
---|
163 | BOOLEAN used_b; |
---|
164 | #endif |
---|
165 | }; |
---|
166 | class red_object{ |
---|
167 | public: |
---|
168 | kBucket_pt bucket; |
---|
169 | poly p; |
---|
170 | unsigned long sev; |
---|
171 | void flatten(); |
---|
172 | void validate(); |
---|
173 | wlen_type initial_quality; |
---|
174 | void adjust_coefs(number c_r, number c_ac_r); |
---|
175 | wlen_type guess_quality(slimgb_alg* c); |
---|
176 | int clear_to_poly(); |
---|
177 | void canonicalize(); |
---|
178 | }; |
---|
179 | |
---|
180 | |
---|
181 | enum calc_state |
---|
182 | { |
---|
183 | UNCALCULATED, |
---|
184 | HASTREP//, |
---|
185 | //UNIMPORTANT, |
---|
186 | //SOONTREP |
---|
187 | }; |
---|
188 | static BOOLEAN pair_cmp(sorted_pair_node* a,sorted_pair_node* b); |
---|
189 | template <class len_type, class set_type> int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set); |
---|
190 | static int add_to_reductors(slimgb_alg* c, poly h, int len, BOOLEAN simplified=FALSE); |
---|
191 | static int bucket_guess(kBucket* bucket); |
---|
192 | static poly redNFTail (poly h,const int sl,kStrategy strat, int len); |
---|
193 | static poly redNF2 (poly h,slimgb_alg* c , int &len, number& m,int n=0); |
---|
194 | void free_sorted_pair_node(sorted_pair_node* s, ring r); |
---|
195 | static void shorten_tails(slimgb_alg* c, poly monom); |
---|
196 | static void replace_pair(int & i, int & j, slimgb_alg* c); |
---|
197 | //static sorted_pair_node** add_to_basis(poly h, int i, int j,slimgb_alg* c, int* ip=NULL); |
---|
198 | static void do_this_spoly_stuff(int i,int j,slimgb_alg* c); |
---|
199 | //ideal t_rep_gb(ring r,ideal arg_I); |
---|
200 | static BOOLEAN has_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* state); |
---|
201 | static int* make_connections(int from, poly bound, slimgb_alg* c); |
---|
202 | static int* make_connections(int from, int to, poly bound, slimgb_alg* c); |
---|
203 | void now_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c); |
---|
204 | static void soon_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c); |
---|
205 | static int pLcmDeg(poly a, poly b); |
---|
206 | static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen); |
---|
207 | static BOOLEAN find_next_pair(slimgb_alg* c, BOOLEAN go_higher=TRUE); |
---|
208 | |
---|
209 | static sorted_pair_node* pop_pair(slimgb_alg* c); |
---|
210 | static BOOLEAN no_pairs(slimgb_alg* c); |
---|
211 | void clean_top_of_pair_list(slimgb_alg* c); |
---|
212 | static void super_clean_top_of_pair_list(slimgb_alg* c); |
---|
213 | static BOOLEAN state_is(calc_state state, const int & i, const int & j, slimgb_alg* c); |
---|
214 | static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, slimgb_alg* c=NULL); |
---|
215 | static int tgb_pair_better_gen(const void* ap,const void* bp); |
---|
216 | static poly redTailShort(poly h, kStrategy strat); |
---|
217 | static poly gcd_of_terms(poly p, ring r); |
---|
218 | static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c); |
---|
219 | static poly kBucketGcd(kBucket* b, ring r); |
---|
220 | static void multi_reduction(red_object* los, int & losl, slimgb_alg* c); |
---|
221 | int slim_nsize(number n, ring r); |
---|
222 | sorted_pair_node* quick_pop_pair(slimgb_alg* c); |
---|
223 | sorted_pair_node* top_pair(slimgb_alg* c); |
---|
224 | sorted_pair_node** add_to_basis_ideal_quotient(poly h, slimgb_alg* c, int* ip);//, BOOLEAN new_pairs=TRUE); |
---|
225 | sorted_pair_node** spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c); |
---|
226 | int kFindDivisibleByInS_easy(kStrategy strat,const red_object & obj); |
---|
227 | int tgb_pair_better_gen2(const void* ap,const void* bp); |
---|
228 | int kFindDivisibleByInS_easy(kStrategy strat,poly p, long sev); |
---|
229 | //static int quality(poly p, int len, slimgb_alg* c); |
---|
230 | /** |
---|
231 | makes on each red_object in a region a single_step |
---|
232 | **/ |
---|
233 | class reduction_step{ |
---|
234 | public: |
---|
235 | /// we assume hat all occuring red_objects have same lm, and all |
---|
236 | /// occ. lm's in r[l...u] are the same, only reductor does not occur |
---|
237 | virtual void reduce(red_object* r, int l, int u); |
---|
238 | //int reduction_id; |
---|
239 | virtual ~reduction_step(); |
---|
240 | slimgb_alg* c; |
---|
241 | int reduction_id; |
---|
242 | }; |
---|
243 | class simple_reducer:public reduction_step{ |
---|
244 | public: |
---|
245 | poly p; |
---|
246 | kBucket_pt fill_back; |
---|
247 | int p_len; |
---|
248 | simple_reducer(poly p, int p_len, slimgb_alg* c =NULL){ |
---|
249 | this->p=p; |
---|
250 | assume(p_len==pLength(p)); |
---|
251 | this->p_len=p_len; |
---|
252 | this->c=c; |
---|
253 | } |
---|
254 | virtual void pre_reduce(red_object* r, int l, int u); |
---|
255 | virtual void reduce(red_object* r, int l, int u); |
---|
256 | ~simple_reducer(); |
---|
257 | |
---|
258 | |
---|
259 | virtual void do_reduce(red_object & ro); |
---|
260 | }; |
---|
261 | |
---|
262 | //class sum_canceling_reducer:public reduction_step { |
---|
263 | // void reduce(red_object* r, int l, int u); |
---|
264 | //}; |
---|
265 | struct find_erg{ |
---|
266 | poly expand; |
---|
267 | int expand_length; |
---|
268 | int to_reduce_u; |
---|
269 | int to_reduce_l; |
---|
270 | int reduce_by;//index of reductor |
---|
271 | BOOLEAN fromS;//else from los |
---|
272 | |
---|
273 | }; |
---|
274 | |
---|
275 | static void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c); |
---|
276 | static void finalize_reduction_step(reduction_step* r); |
---|
277 | |
---|
278 | template <class len_type, class set_type> int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set){ |
---|
279 | //Print("POSHELER:%d",sizeof(wlen_type)); |
---|
280 | int length=strat->sl; |
---|
281 | int i; |
---|
282 | int an = 0; |
---|
283 | int en= length; |
---|
284 | |
---|
285 | if ((len>setL[length]) |
---|
286 | || ((len==setL[length]) && (pLmCmp(set[length],p)== -1))) |
---|
287 | return length+1; |
---|
288 | |
---|
289 | loop |
---|
290 | { |
---|
291 | if (an >= en-1) |
---|
292 | { |
---|
293 | if ((len<setL[an]) |
---|
294 | || ((len==setL[an]) && (pLmCmp(set[an],p) == 1))) return an; |
---|
295 | return en; |
---|
296 | } |
---|
297 | i=(an+en) / 2; |
---|
298 | if ((len<setL[i]) |
---|
299 | || ((len==setL[i]) && (pLmCmp(set[i],p) == 1))) en=i; |
---|
300 | //else if ((len>setL[i]) |
---|
301 | //|| ((len==setL[i]) && (pLmCmp(set[i],p) == -1))) an=i; |
---|
302 | else an=i; |
---|
303 | } |
---|
304 | |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c); |
---|
309 | wlen_type pELength(poly p, ring r); |
---|
310 | |
---|
311 | #endif |
---|