source: git/kernel/tgb_internal.h @ e01da4

spielwiese
Last change on this file since e01da4 was e01da4, checked in by Michael Brickenstein <bricken@…>, 17 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
RevLine 
[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****************************************/
[e01da4]7/* $Id: tgb_internal.h,v 1.54 2007-02-20 10:47:46 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"
[cc4d094]20//#define USE_NORO 1
[b16a613]21//#define NORO_CACHE 1
[e01da4]22#define NORO_SPARSE_ROWS_PRE 1
[89b59f]23#ifdef NORO_CACHE
[cc4d094]24//#include <map>
[89b59f]25#include <vector>
26#endif
[1cddd8]27#ifdef HAVE_BOOST_DYNAMIC_BITSET_HPP
[542228]28#define  HAVE_BOOST 1
[1cddd8]29#endif
[2fd387d]30//#define HAVE_BOOST 1
[1cddd8]31//#define USE_STDVECBOOL 1
[26914c]32#ifdef HAVE_BOOST
33#include "boost/dynamic_bitset.hpp"
34#include <vector>
35using boost::dynamic_bitset;
36using std::vector;
37#endif
[4b7049]38#ifdef USE_STDVECBOOL
39#include <vector>
40using std::vector;
41#endif
[f4adfcb]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
[b055de9]61
[f4adfcb]62//#define FIND_DETERMINISTIC
63//#define REDTAIL_PROT
64//#define QUICK_SPOLY_TEST
[89b59f]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};
[b16a613]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};
[e01da4]115class MonRedResNP{
116public:
117  number coef;
118
119
120  DataNoroCacheNode* ref;
121  MonRedResNP(){
122    ref=NULL;
123  }
124};
[f4adfcb]125struct sorted_pair_node{
126  //criterium, which is stable 0. small lcm 1. small i 2. small j
[c72471]127  wlen_type expected_length;
128  poly lcm_of_lm;
[f4adfcb]129  int i;
130  int j;
131  int deg;
[c72471]132 
133 
[f4adfcb]134};
135
136
[b16a613]137class NoroPlaceHolder{
138public:
139  DataNoroCacheNode* ref;
140  number coef;
141};
142
[f4adfcb]143//static ideal debug_Ideal;
144
145
146struct poly_list_node{
147  poly p;
148  poly_list_node* next;
149};
[bddc9d]150
[f4adfcb]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};
[b055de9]165
166
[f4adfcb]167struct poly_array_list{
168  poly* p;
169  int size;
170  poly_array_list* next;
171};
[9cbb7a3]172class slimgb_alg
[f4adfcb]173{
[9cbb7a3]174  public:
[625767]175    slimgb_alg(ideal I, int syz_comp,BOOLEAN F4);
[6e08ad]176                void introduceDelayedPairs(poly* pa,int s);
[68ae61]177    virtual ~slimgb_alg();
[9108d3]178    void cleanDegs(int lower, int upper);
[4b7049]179#ifndef HAVE_BOOST
180#ifdef USE_STDVECBOOL
181  vector<vector<bool> > states;
182#else
[f4adfcb]183  char** states;
[4b7049]184#endif
185#else
[26914c]186  vector<dynamic_bitset<> > states;
[4b7049]187#endif
[ca086f]188  ideal add_later;
[f4adfcb]189  ideal S;
190  ring r;
191  int* lengths;
[6b4fbf7]192  wlen_type* weighted_lengths;
[f4adfcb]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;
[c72471]204  #if 0
[f4adfcb]205  BOOLEAN* modifiedS;
[c72471]206  #endif
[c481b8]207  #ifdef TGB_RESORT_PAIRS
[c72471]208  bool* replaced;
[c481b8]209  #endif
[f4adfcb]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;
[6d7605]221  //! array_lengths should be greater equal n;
[625767]222  int syz_comp;
[6d7605]223  int array_lengths; 
[f4adfcb]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;
[bfcd46]233  int lastDpBlockStart;
[9108d3]234  int lastCleanedDeg;
[c57134]235  BOOLEAN isDifficultField;
[a60a21]236  BOOLEAN completed;
[f4adfcb]237  BOOLEAN is_homog;
[9108d3]238  BOOLEAN tailReductions;
[c57134]239  BOOLEAN eliminationProblem;
[f4adfcb]240  BOOLEAN F4_mode;
[d491e3]241  BOOLEAN nc;
[c481b8]242  #ifdef TGB_RESORT_PAIRS
[c72471]243  BOOLEAN used_b;
[c481b8]244  #endif
[f4adfcb]245};
246class red_object{
247 public:
248  kBucket_pt bucket;
249  poly p;
250  unsigned long sev;
[d64382]251  int sugar;
[f4adfcb]252  void flatten();
253  void validate();
[470dd9]254  wlen_type initial_quality;
[f4adfcb]255  void adjust_coefs(number c_r, number c_ac_r);
[9cd599]256  wlen_type guess_quality(slimgb_alg* c);
[f4adfcb]257  int clear_to_poly();
258  void canonicalize();
259};
260
261
262enum calc_state
263  {
264    UNCALCULATED,
[113bb8]265    HASTREP//,
266    //UNIMPORTANT,
[6b4fbf7]267    //SOONTREP
[f4adfcb]268  };
[8492cb9]269static BOOLEAN pair_cmp(sorted_pair_node* a,sorted_pair_node* b);
[25061a]270template <class len_type, class set_type>  int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set);
[321283]271static int add_to_reductors(slimgb_alg* c, poly h, int len, int ecart, BOOLEAN simplified=FALSE);
[f4adfcb]272static int bucket_guess(kBucket* bucket);
273static poly redNFTail (poly h,const int sl,kStrategy strat, int len);
[9cbb7a3]274static poly redNF2 (poly h,slimgb_alg* c , int &len, number&  m,int n=0);
[b75d13]275void free_sorted_pair_node(sorted_pair_node* s, ring r);
[9cbb7a3]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);
[f4adfcb]280//ideal t_rep_gb(ring r,ideal arg_I);
[9cbb7a3]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);
[f4adfcb]286static int pLcmDeg(poly a, poly b);
[25061a]287static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen);
[9cbb7a3]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);
[8492cb9]295static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, slimgb_alg* c=NULL);
[b75d13]296static int tgb_pair_better_gen(const void* ap,const void* bp);
[f4adfcb]297static poly redTailShort(poly h, kStrategy strat);
298static poly gcd_of_terms(poly p, ring r);
[9cbb7a3]299static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c);
[f4adfcb]300static poly kBucketGcd(kBucket* b, ring r);
[9cbb7a3]301static void multi_reduction(red_object* los, int & losl, slimgb_alg* c);
[e9f4c9]302int slim_nsize(number n, ring r);
[9cbb7a3]303sorted_pair_node* quick_pop_pair(slimgb_alg* c);
304sorted_pair_node* top_pair(slimgb_alg* c);
[0f2374]305sorted_pair_node** add_to_basis_ideal_quotient(poly h, slimgb_alg* c, int* ip);//, BOOLEAN new_pairs=TRUE);
[9cbb7a3]306sorted_pair_node**  spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c);
[b75d13]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);
[9cbb7a3]310//static int quality(poly p, int len, slimgb_alg* c);
[f4adfcb]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();
[9cbb7a3]321  slimgb_alg* c;
[f4adfcb]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;
[321283]329  int reducer_deg;
330  simple_reducer(poly p, int p_len,int reducer_deg, slimgb_alg* c =NULL){
[f4adfcb]331    this->p=p;
[321283]332    this->reducer_deg=reducer_deg;
[f4adfcb]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
[bddc9d]341
[d2d842]342  virtual void do_reduce(red_object & ro);
[f4adfcb]343};
[36b1aa]344
[f4adfcb]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
[9cbb7a3]358static void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c);
[f4adfcb]359static void finalize_reduction_step(reduction_step* r);
[b055de9]360
[25061a]361template <class len_type, class set_type>  int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set){
[9cd599]362  //Print("POSHELER:%d",sizeof(wlen_type));
[25061a]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}
[b055de9]389
390
[2fd387d]391static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c);
[e65be8e]392wlen_type pELength(poly p, ring r);
[44103a2]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
[f4adfcb]396#endif
Note: See TracBrowser for help on using the repository browser.