source: git/kernel/tgb_internal.h @ b16a613

spielwiese
Last change on this file since b16a613 was b16a613, checked in by Michael Brickenstein <bricken@…>, 17 years ago
*bricken: continue work on noro git-svn-id: file:///usr/local/Singular/svn/trunk@9837 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.4 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.52 2007-02-09 12:30:50 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#ifdef NORO_CACHE
23//#include <map>
24#include <vector>
25#endif
26#ifdef HAVE_BOOST_DYNAMIC_BITSET_HPP
27#define  HAVE_BOOST 1
28#endif
29//#define HAVE_BOOST 1
30//#define USE_STDVECBOOL 1
31#ifdef HAVE_BOOST
32#include "boost/dynamic_bitset.hpp"
33#include <vector>
34using boost::dynamic_bitset;
35using std::vector;
36#endif
37#ifdef USE_STDVECBOOL
38#include <vector>
39using std::vector;
40#endif
41#include "kutil.h"
42#include "kInline.cc"
43#include "kstd1.h"
44#include "kbuckets.h"
45
46
47
48
49//#define TGB_DEBUG
50#define FULLREDUCTIONS
51#define HANS_IDEA
52//#define HALFREDUCTIONS
53//#define HEAD_BIN
54//#define HOMOGENEOUS_EXAMPLE
55#define REDTAIL_S
56#define PAR_N 100
57#define PAR_N_F4 5000
58#define AC_NEW_MIN 2
59#define AC_FLATTEN 1
60
61//#define FIND_DETERMINISTIC
62//#define REDTAIL_PROT
63//#define QUICK_SPOLY_TEST
64class PolySimple{
65public:
66  PolySimple(poly p){
67    impl=p;
68  }
69  PolySimple(){
70    impl=NULL;
71  }
72  PolySimple(const PolySimple& a){
73    //impl=p_Copy(a.impl,currRing);
74    impl=a.impl;
75  }
76  PolySimple& operator=(const PolySimple& p2){
77    //p_Delete(&impl,currRing);
78    //impl=p_Copy(p2.impl,currRing);
79    impl=p2.impl;
80    return *this;
81  }
82  ~PolySimple(){
83    //p_Delete(&impl,currRing);
84  }
85  bool operator< (const PolySimple& other) const{
86    return pLmCmp(impl,other.impl)<0;
87  }
88  bool operator==(const PolySimple& other){
89    return pLmEqual(impl,other.impl);
90  }
91  poly impl;
92 
93};
94class DataNoroCacheNode;
95class MonRedRes{
96public:
97  poly p;
98  number coef;
99  BOOLEAN changed;
100  int len;
101  BOOLEAN onlyBorrowed;
102  bool operator<(const MonRedRes& other) const{
103    int cmp=p_LmCmp(p,other.p,currRing);
104    if ((cmp<0)||((cmp==0)&&((onlyBorrowed)&&(!(other.onlyBorrowed))))){
105      return true;
106    } else return false;
107  }
108  DataNoroCacheNode* ref;
109  MonRedRes(){
110    ref=NULL;
111    p=NULL;
112  }
113};
114struct sorted_pair_node{
115  //criterium, which is stable 0. small lcm 1. small i 2. small j
116  wlen_type expected_length;
117  poly lcm_of_lm;
118  int i;
119  int j;
120  int deg;
121 
122 
123};
124
125
126class NoroPlaceHolder{
127public:
128  DataNoroCacheNode* ref;
129  number coef;
130};
131
132//static ideal debug_Ideal;
133
134
135struct poly_list_node{
136  poly p;
137  poly_list_node* next;
138};
139
140struct int_pair_node{
141  int_pair_node* next;
142  int a;
143  int b;
144};
145struct monom_poly{
146  poly m;
147  poly f;
148};
149struct mp_array_list{
150  monom_poly* mp;
151  int size;
152  mp_array_list* next;
153};
154
155
156struct poly_array_list{
157  poly* p;
158  int size;
159  poly_array_list* next;
160};
161class slimgb_alg
162{
163  public:
164    slimgb_alg(ideal I, int syz_comp,BOOLEAN F4);
165                void introduceDelayedPairs(poly* pa,int s);
166    virtual ~slimgb_alg();
167    void cleanDegs(int lower, int upper);
168#ifndef HAVE_BOOST
169#ifdef USE_STDVECBOOL
170  vector<vector<bool> > states;
171#else
172  char** states;
173#endif
174#else
175  vector<dynamic_bitset<> > states;
176#endif
177  ideal add_later;
178  ideal S;
179  ring r;
180  int* lengths;
181  wlen_type* weighted_lengths;
182  long* short_Exps;
183  kStrategy strat;
184  int* T_deg;
185  int* T_deg_full;
186  poly tmp_lm;
187  poly* tmp_pair_lm;
188  sorted_pair_node** tmp_spn;
189  poly* expandS;
190  poly* gcd_of_terms;
191  int_pair_node* soon_free;
192  sorted_pair_node** apairs;
193  #if 0
194  BOOLEAN* modifiedS;
195  #endif
196  #ifdef TGB_RESORT_PAIRS
197  bool* replaced;
198  #endif
199  poly_list_node* to_destroy;
200  //for F4
201  mp_array_list* F;
202  poly_array_list* F_minus;
203
204  //end for F4
205#ifdef HEAD_BIN
206  struct omBin_s*   HeadBin;
207#endif
208  unsigned int reduction_steps;
209  int n;
210  //! array_lengths should be greater equal n;
211  int syz_comp;
212  int array_lengths; 
213  int normal_forms;
214  int current_degree;
215  int Rcounter;
216  int last_index;
217  int max_pairs;
218  int pair_top;
219  int easy_product_crit;
220  int extended_product_crit;
221  int average_length;
222  int lastDpBlockStart;
223  int lastCleanedDeg;
224  BOOLEAN isDifficultField;
225  BOOLEAN completed;
226  BOOLEAN is_homog;
227  BOOLEAN tailReductions;
228  BOOLEAN eliminationProblem;
229  BOOLEAN F4_mode;
230  BOOLEAN nc;
231  #ifdef TGB_RESORT_PAIRS
232  BOOLEAN used_b;
233  #endif
234};
235class red_object{
236 public:
237  kBucket_pt bucket;
238  poly p;
239  unsigned long sev;
240  int sugar;
241  void flatten();
242  void validate();
243  wlen_type initial_quality;
244  void adjust_coefs(number c_r, number c_ac_r);
245  wlen_type guess_quality(slimgb_alg* c);
246  int clear_to_poly();
247  void canonicalize();
248};
249
250
251enum calc_state
252  {
253    UNCALCULATED,
254    HASTREP//,
255    //UNIMPORTANT,
256    //SOONTREP
257  };
258static BOOLEAN pair_cmp(sorted_pair_node* a,sorted_pair_node* b);
259template <class len_type, class set_type>  int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set);
260static int add_to_reductors(slimgb_alg* c, poly h, int len, int ecart, BOOLEAN simplified=FALSE);
261static int bucket_guess(kBucket* bucket);
262static poly redNFTail (poly h,const int sl,kStrategy strat, int len);
263static poly redNF2 (poly h,slimgb_alg* c , int &len, number&  m,int n=0);
264void free_sorted_pair_node(sorted_pair_node* s, ring r);
265static void shorten_tails(slimgb_alg* c, poly monom);
266static void replace_pair(int & i, int & j, slimgb_alg* c);
267//static sorted_pair_node** add_to_basis(poly h, int i, int j,slimgb_alg* c, int* ip=NULL);
268static void do_this_spoly_stuff(int i,int j,slimgb_alg* c);
269//ideal t_rep_gb(ring r,ideal arg_I);
270static BOOLEAN has_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* state);
271static int* make_connections(int from, poly bound, slimgb_alg* c);
272static int* make_connections(int from, int to, poly bound, slimgb_alg* c);
273void now_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c);
274static void soon_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c);
275static int pLcmDeg(poly a, poly b);
276static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen);
277static BOOLEAN find_next_pair(slimgb_alg* c, BOOLEAN go_higher=TRUE);
278
279static sorted_pair_node* pop_pair(slimgb_alg* c);
280static BOOLEAN no_pairs(slimgb_alg* c);
281void clean_top_of_pair_list(slimgb_alg* c);
282static void super_clean_top_of_pair_list(slimgb_alg* c);
283static BOOLEAN state_is(calc_state state, const int & i, const int & j, slimgb_alg* c);
284static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, slimgb_alg* c=NULL);
285static int tgb_pair_better_gen(const void* ap,const void* bp);
286static poly redTailShort(poly h, kStrategy strat);
287static poly gcd_of_terms(poly p, ring r);
288static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c);
289static poly kBucketGcd(kBucket* b, ring r);
290static void multi_reduction(red_object* los, int & losl, slimgb_alg* c);
291int slim_nsize(number n, ring r);
292sorted_pair_node* quick_pop_pair(slimgb_alg* c);
293sorted_pair_node* top_pair(slimgb_alg* c);
294sorted_pair_node** add_to_basis_ideal_quotient(poly h, slimgb_alg* c, int* ip);//, BOOLEAN new_pairs=TRUE);
295sorted_pair_node**  spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c);
296int kFindDivisibleByInS_easy(kStrategy strat,const red_object & obj);
297int tgb_pair_better_gen2(const void* ap,const void* bp);
298int kFindDivisibleByInS_easy(kStrategy strat,poly p, long sev);
299//static int quality(poly p, int len, slimgb_alg* c);
300/**
301   makes on each red_object in a region a single_step
302 **/
303class reduction_step{
304 public:
305  /// we assume hat all occuring red_objects have same lm, and all
306  /// occ. lm's in r[l...u] are the same, only reductor does not occur
307  virtual void reduce(red_object* r, int l, int u);
308  //int reduction_id;
309  virtual ~reduction_step();
310  slimgb_alg* c;
311  int reduction_id;
312};
313class simple_reducer:public reduction_step{
314 public:
315  poly p;
316  kBucket_pt fill_back;
317  int p_len;
318  int reducer_deg;
319  simple_reducer(poly p, int p_len,int reducer_deg, slimgb_alg* c =NULL){
320    this->p=p;
321    this->reducer_deg=reducer_deg;
322    assume(p_len==pLength(p));
323    this->p_len=p_len;
324    this->c=c;
325  }
326  virtual void pre_reduce(red_object* r, int l, int u);
327  virtual void reduce(red_object* r, int l, int u);
328  ~simple_reducer();
329
330
331  virtual void do_reduce(red_object & ro);
332};
333
334//class sum_canceling_reducer:public reduction_step {
335//  void reduce(red_object* r, int l, int u);
336//};
337struct find_erg{
338  poly expand;
339  int expand_length;
340  int to_reduce_u;
341  int to_reduce_l;
342  int reduce_by;//index of reductor
343  BOOLEAN fromS;//else from los
344
345};
346
347static void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c);
348static void finalize_reduction_step(reduction_step* r);
349
350template <class len_type, class set_type>  int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set){
351  //Print("POSHELER:%d",sizeof(wlen_type));
352  int length=strat->sl;
353  int i;
354  int an = 0;
355  int en= length;
356
357  if ((len>setL[length])
358      || ((len==setL[length]) && (pLmCmp(set[length],p)== -1)))
359    return length+1;
360
361  loop
362  {
363    if (an >= en-1)
364    {
365      if ((len<setL[an])
366          || ((len==setL[an]) && (pLmCmp(set[an],p) == 1))) return an;
367      return en;
368    }
369    i=(an+en) / 2;
370    if ((len<setL[i])
371        || ((len==setL[i]) && (pLmCmp(set[i],p) == 1))) en=i;
372    //else if ((len>setL[i])
373    //|| ((len==setL[i]) && (pLmCmp(set[i],p) == -1))) an=i;
374    else an=i;
375  }
376
377}
378
379
380static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c);
381wlen_type pELength(poly p, ring r);
382
383#endif
Note: See TracBrowser for help on using the repository browser.