source: git/kernel/tgb_internal.h @ e01da4

jengelh-datetimespielwiese
Last change on this file since e01da4 was e01da4, checked in by Michael Brickenstein <bricken@…>, 16 years ago
*bricken: sparse works now git-svn-id: file:///usr/local/Singular/svn/trunk@9869 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.6 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.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>
35using boost::dynamic_bitset;
36using std::vector;
37#endif
38#ifdef USE_STDVECBOOL
39#include <vector>
40using 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
65class PolySimple{
66public:
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};
95class DataNoroCacheNode;
96class MonRedRes{
97public:
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};
115class MonRedResNP{
116public:
117  number coef;
118
119
120  DataNoroCacheNode* ref;
121  MonRedResNP(){
122    ref=NULL;
123  }
124};
125struct 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
137class NoroPlaceHolder{
138public:
139  DataNoroCacheNode* ref;
140  number coef;
141};
142
143//static ideal debug_Ideal;
144
145
146struct poly_list_node{
147  poly p;
148  poly_list_node* next;
149};
150
151struct int_pair_node{
152  int_pair_node* next;
153  int a;
154  int b;
155};
156struct monom_poly{
157  poly m;
158  poly f;
159};
160struct mp_array_list{
161  monom_poly* mp;
162  int size;
163  mp_array_list* next;
164};
165
166
167struct poly_array_list{
168  poly* p;
169  int size;
170  poly_array_list* next;
171};
172class 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};
246class 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
262enum calc_state
263  {
264    UNCALCULATED,
265    HASTREP//,
266    //UNIMPORTANT,
267    //SOONTREP
268  };
269static BOOLEAN pair_cmp(sorted_pair_node* a,sorted_pair_node* b);
270template <class len_type, class set_type>  int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set);
271static int add_to_reductors(slimgb_alg* c, poly h, int len, int ecart, BOOLEAN simplified=FALSE);
272static int bucket_guess(kBucket* bucket);
273static poly redNFTail (poly h,const int sl,kStrategy strat, int len);
274static poly redNF2 (poly h,slimgb_alg* c , int &len, number&  m,int n=0);
275void free_sorted_pair_node(sorted_pair_node* s, ring r);
276static void shorten_tails(slimgb_alg* c, poly monom);
277static 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);
279static void do_this_spoly_stuff(int i,int j,slimgb_alg* c);
280//ideal t_rep_gb(ring r,ideal arg_I);
281static BOOLEAN has_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* state);
282static int* make_connections(int from, poly bound, slimgb_alg* c);
283static int* make_connections(int from, int to, poly bound, slimgb_alg* c);
284void now_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c);
285static void soon_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c);
286static int pLcmDeg(poly a, poly b);
287static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen);
288static BOOLEAN find_next_pair(slimgb_alg* c, BOOLEAN go_higher=TRUE);
289
290static sorted_pair_node* pop_pair(slimgb_alg* c);
291static BOOLEAN no_pairs(slimgb_alg* c);
292void clean_top_of_pair_list(slimgb_alg* c);
293static void super_clean_top_of_pair_list(slimgb_alg* c);
294static BOOLEAN state_is(calc_state state, const int & i, const int & j, slimgb_alg* c);
295static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, slimgb_alg* c=NULL);
296static int tgb_pair_better_gen(const void* ap,const void* bp);
297static poly redTailShort(poly h, kStrategy strat);
298static poly gcd_of_terms(poly p, ring r);
299static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c);
300static poly kBucketGcd(kBucket* b, ring r);
301static void multi_reduction(red_object* los, int & losl, slimgb_alg* c);
302int slim_nsize(number n, ring r);
303sorted_pair_node* quick_pop_pair(slimgb_alg* c);
304sorted_pair_node* top_pair(slimgb_alg* c);
305sorted_pair_node** add_to_basis_ideal_quotient(poly h, slimgb_alg* c, int* ip);//, BOOLEAN new_pairs=TRUE);
306sorted_pair_node**  spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c);
307int kFindDivisibleByInS_easy(kStrategy strat,const red_object & obj);
308int tgb_pair_better_gen2(const void* ap,const void* bp);
309int 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 **/
314class 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};
324class 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//};
348struct 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
358static void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c);
359static void finalize_reduction_step(reduction_step* r);
360
361template <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
391static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c);
392wlen_type pELength(poly p, ring r);
393void 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
Note: See TracBrowser for help on using the repository browser.