[f4adfcb] | 1 | #ifndef TGB_INTERNAL_H |
---|
| 2 | #define TGB_INTERNAL_H |
---|
[b553e5] | 3 | //!\file tgb_internal.h |
---|
[6b9532] | 4 | /**************************************** |
---|
| 5 | * Computer Algebra System SINGULAR * |
---|
| 6 | ****************************************/ |
---|
[4b7049] | 7 | /* $Id: tgb_internal.h,v 1.41 2006-06-08 06:06:51 bricken Exp $ */ |
---|
[6b9532] | 8 | /* |
---|
| 9 | * ABSTRACT: tgb internal .h file |
---|
| 10 | */ |
---|
[f4adfcb] | 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" |
---|
[2fd387d] | 20 | //#define HAVE_BOOST 1 |
---|
[4b7049] | 21 | #define USE_STDVECBOOL 1 |
---|
[26914c] | 22 | #ifdef HAVE_BOOST |
---|
| 23 | #include "boost/dynamic_bitset.hpp" |
---|
| 24 | #include <vector> |
---|
| 25 | using boost::dynamic_bitset; |
---|
| 26 | using std::vector; |
---|
| 27 | #endif |
---|
[4b7049] | 28 | #ifdef USE_STDVECBOOL |
---|
| 29 | #include <vector> |
---|
| 30 | using std::vector; |
---|
| 31 | #endif |
---|
[f4adfcb] | 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 |
---|
[b055de9] | 51 | |
---|
[f4adfcb] | 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 |
---|
[c72471] | 57 | wlen_type expected_length; |
---|
| 58 | poly lcm_of_lm; |
---|
[f4adfcb] | 59 | int i; |
---|
| 60 | int j; |
---|
| 61 | int deg; |
---|
[c72471] | 62 | |
---|
| 63 | |
---|
[f4adfcb] | 64 | }; |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | //static ideal debug_Ideal; |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | struct poly_list_node{ |
---|
| 71 | poly p; |
---|
| 72 | poly_list_node* next; |
---|
| 73 | }; |
---|
[bddc9d] | 74 | |
---|
[f4adfcb] | 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 | }; |
---|
[b055de9] | 89 | |
---|
| 90 | |
---|
[f4adfcb] | 91 | struct poly_array_list{ |
---|
| 92 | poly* p; |
---|
| 93 | int size; |
---|
| 94 | poly_array_list* next; |
---|
| 95 | }; |
---|
[9cbb7a3] | 96 | class slimgb_alg |
---|
[f4adfcb] | 97 | { |
---|
[9cbb7a3] | 98 | public: |
---|
[625767] | 99 | slimgb_alg(ideal I, int syz_comp,BOOLEAN F4); |
---|
[68ae61] | 100 | virtual ~slimgb_alg(); |
---|
[4b7049] | 101 | #ifndef HAVE_BOOST |
---|
| 102 | #ifdef USE_STDVECBOOL |
---|
| 103 | vector<vector<bool> > states; |
---|
| 104 | #else |
---|
[f4adfcb] | 105 | char** states; |
---|
[4b7049] | 106 | #endif |
---|
| 107 | #else |
---|
[26914c] | 108 | vector<dynamic_bitset<> > states; |
---|
[4b7049] | 109 | #endif |
---|
[ca086f] | 110 | ideal add_later; |
---|
[f4adfcb] | 111 | ideal S; |
---|
| 112 | ring r; |
---|
| 113 | int* lengths; |
---|
[6b4fbf7] | 114 | wlen_type* weighted_lengths; |
---|
[f4adfcb] | 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; |
---|
[c72471] | 126 | #if 0 |
---|
[f4adfcb] | 127 | BOOLEAN* modifiedS; |
---|
[c72471] | 128 | #endif |
---|
[c481b8] | 129 | #ifdef TGB_RESORT_PAIRS |
---|
[c72471] | 130 | bool* replaced; |
---|
[c481b8] | 131 | #endif |
---|
[f4adfcb] | 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; |
---|
[6d7605] | 143 | //! array_lengths should be greater equal n; |
---|
[625767] | 144 | int syz_comp; |
---|
[6d7605] | 145 | int array_lengths; |
---|
[f4adfcb] | 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; |
---|
[c57134] | 155 | BOOLEAN isDifficultField; |
---|
[a60a21] | 156 | BOOLEAN completed; |
---|
[f4adfcb] | 157 | BOOLEAN is_homog; |
---|
[c57134] | 158 | |
---|
| 159 | BOOLEAN eliminationProblem; |
---|
[f4adfcb] | 160 | BOOLEAN F4_mode; |
---|
[d491e3] | 161 | BOOLEAN nc; |
---|
[c481b8] | 162 | #ifdef TGB_RESORT_PAIRS |
---|
[c72471] | 163 | BOOLEAN used_b; |
---|
[c481b8] | 164 | #endif |
---|
[f4adfcb] | 165 | }; |
---|
| 166 | class red_object{ |
---|
| 167 | public: |
---|
| 168 | kBucket_pt bucket; |
---|
| 169 | poly p; |
---|
| 170 | unsigned long sev; |
---|
| 171 | void flatten(); |
---|
| 172 | void validate(); |
---|
[470dd9] | 173 | wlen_type initial_quality; |
---|
[f4adfcb] | 174 | void adjust_coefs(number c_r, number c_ac_r); |
---|
[9cd599] | 175 | wlen_type guess_quality(slimgb_alg* c); |
---|
[f4adfcb] | 176 | int clear_to_poly(); |
---|
| 177 | void canonicalize(); |
---|
| 178 | }; |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | enum calc_state |
---|
| 182 | { |
---|
| 183 | UNCALCULATED, |
---|
[113bb8] | 184 | HASTREP//, |
---|
| 185 | //UNIMPORTANT, |
---|
[6b4fbf7] | 186 | //SOONTREP |
---|
[f4adfcb] | 187 | }; |
---|
[8492cb9] | 188 | static BOOLEAN pair_cmp(sorted_pair_node* a,sorted_pair_node* b); |
---|
[25061a] | 189 | template <class len_type, class set_type> int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set); |
---|
[4c80eb] | 190 | static int add_to_reductors(slimgb_alg* c, poly h, int len, BOOLEAN simplified=FALSE); |
---|
[f4adfcb] | 191 | static int bucket_guess(kBucket* bucket); |
---|
| 192 | static poly redNFTail (poly h,const int sl,kStrategy strat, int len); |
---|
[9cbb7a3] | 193 | static poly redNF2 (poly h,slimgb_alg* c , int &len, number& m,int n=0); |
---|
[b75d13] | 194 | void free_sorted_pair_node(sorted_pair_node* s, ring r); |
---|
[9cbb7a3] | 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); |
---|
[f4adfcb] | 199 | //ideal t_rep_gb(ring r,ideal arg_I); |
---|
[9cbb7a3] | 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); |
---|
[f4adfcb] | 205 | static int pLcmDeg(poly a, poly b); |
---|
[25061a] | 206 | static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen); |
---|
[9cbb7a3] | 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); |
---|
[8492cb9] | 214 | static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, slimgb_alg* c=NULL); |
---|
[b75d13] | 215 | static int tgb_pair_better_gen(const void* ap,const void* bp); |
---|
[f4adfcb] | 216 | static poly redTailShort(poly h, kStrategy strat); |
---|
| 217 | static poly gcd_of_terms(poly p, ring r); |
---|
[9cbb7a3] | 218 | static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c); |
---|
[f4adfcb] | 219 | static poly kBucketGcd(kBucket* b, ring r); |
---|
[9cbb7a3] | 220 | static void multi_reduction(red_object* los, int & losl, slimgb_alg* c); |
---|
[e9f4c9] | 221 | int slim_nsize(number n, ring r); |
---|
[9cbb7a3] | 222 | sorted_pair_node* quick_pop_pair(slimgb_alg* c); |
---|
| 223 | sorted_pair_node* top_pair(slimgb_alg* c); |
---|
[0f2374] | 224 | sorted_pair_node** add_to_basis_ideal_quotient(poly h, slimgb_alg* c, int* ip);//, BOOLEAN new_pairs=TRUE); |
---|
[9cbb7a3] | 225 | sorted_pair_node** spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c); |
---|
[b75d13] | 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); |
---|
[9cbb7a3] | 229 | //static int quality(poly p, int len, slimgb_alg* c); |
---|
[f4adfcb] | 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(); |
---|
[9cbb7a3] | 240 | slimgb_alg* c; |
---|
[f4adfcb] | 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; |
---|
[9cbb7a3] | 248 | simple_reducer(poly p, int p_len, slimgb_alg* c =NULL){ |
---|
[f4adfcb] | 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 | |
---|
[bddc9d] | 258 | |
---|
[d2d842] | 259 | virtual void do_reduce(red_object & ro); |
---|
[f4adfcb] | 260 | }; |
---|
[36b1aa] | 261 | |
---|
[f4adfcb] | 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 | |
---|
[9cbb7a3] | 275 | static void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c); |
---|
[f4adfcb] | 276 | static void finalize_reduction_step(reduction_step* r); |
---|
[b055de9] | 277 | |
---|
[25061a] | 278 | template <class len_type, class set_type> int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set){ |
---|
[9cd599] | 279 | //Print("POSHELER:%d",sizeof(wlen_type)); |
---|
[25061a] | 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 | } |
---|
[b055de9] | 306 | |
---|
| 307 | |
---|
[2fd387d] | 308 | static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c); |
---|
[e65be8e] | 309 | wlen_type pELength(poly p, ring r); |
---|
[b055de9] | 310 | |
---|
[f4adfcb] | 311 | #endif |
---|