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