source: git/kernel/tgb_internal.h @ cc4d094

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