source: git/kernel/tgb_internal.h @ 8492cb9

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