source: git/Singular/tgb.h @ 5f775a

spielwiese
Last change on this file since 5f775a was 5f775a, checked in by Michael Brickenstein <bricken@…>, 20 years ago
*bricken: simple_gauss optimized git-svn-id: file:///usr/local/Singular/svn/trunk@7545 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.4 KB
Line 
1#ifndef TGB_H
2#define TGB_H
3//#define OM_CHECK 3
4//#define OM_TRACK 5
5#include "mod2.h"
6#include <omalloc.h>
7#include "p_polys.h"
8
9#include "ideals.h"
10#include "ring.h"
11#include "febase.h"
12#include "structs.h"
13#include "polys.h"
14#include "stdlib.h"
15
16
17#include "kutil.h"
18#include "kInline.cc"
19#include "kstd1.h"
20#include "kbuckets.h"
21#include "tok.h"
22//#define TGB_DEBUG
23#define FULLREDUCTIONS
24#define HANS_IDEA
25//#define HALFREDUCTIONS
26//#define HEAD_BIN
27//#define HOMOGENEOUS_EXAMPLE
28#define REDTAIL_S
29#define PAR_N 100
30#define PAR_N_F4 5000
31#define AC_NEW_MIN 2
32#define AC_FLATTEN 1
33//#define FIND_DETERMINISTIC
34//#define REDTAIL_PROT
35//#define QUICK_SPOLY_TEST
36struct sorted_pair_node{
37  //criterium, which is stable 0. small lcm 1. small i 2. small j
38  int i;
39  int j;
40  int deg;
41  int expected_length;
42  poly lcm_of_lm;
43};
44
45ideal t_rep_gb(ring r,ideal arg_I, BOOLEAN F4_mode=FALSE);
46//static ideal debug_Ideal;
47/**
48    reduction_accumulators are objects which are shared by several sums
49 **/
50
51class reduction_accumulator{
52 
53 public:
54  /// (1/multiplied)*bucket=reduced original data
55  number multiplied;
56  ///the polynomial data
57  kBucket_pt bucket;
58  /// the short exponent vector
59  unsigned long sev;
60  /// the reference counter
61  int counter;
62  /// decrease the reference counter, at 0 it deletes the object
63  void decrease_counter(){ 
64    if((--counter)==0)
65      {
66        delete this; //self destruction
67      }
68  }
69  int last_reduction_id;
70  reduction_accumulator(poly p, int p_len, poly high_to);
71  ~reduction_accumulator(){
72    nDelete(&multiplied);
73    kBucketDeleteAndDestroy(&bucket);
74  } 
75
76 
77};
78struct poly_list_node{
79  poly p;
80  poly_list_node* next;
81};
82struct formal_sum_descriptor{
83  number c_my;
84  number c_ac;
85  reduction_accumulator* ac;
86};
87struct int_pair_node{
88  int_pair_node* next;
89  int a;
90  int b;
91};
92struct monom_poly{
93  poly m;
94  poly f;
95};
96struct mp_array_list{
97  monom_poly* mp;
98  int size;
99  mp_array_list* next;
100};
101class tgb_matrix{
102 private:
103  number** n;
104  int columns;
105  int rows;
106  BOOLEAN free_numbers;
107 public:
108  tgb_matrix(int i, int j);
109  ~tgb_matrix();
110  int get_rows();
111  int get_columns();
112  void print();
113  void perm_rows(int i, int j);
114  void set(int i, int j, number n);
115  number get(int i, int j);
116  BOOLEAN is_zero_entry(int i, int j);
117  void free_row(int row, BOOLEAN free_non_zeros=TRUE);
118  int min_col_not_zero_in_row(int row);
119  int next_col_not_zero(int row,int pre);
120  BOOLEAN zero_row(int row);
121  void mult_row(int row,number factor);
122  void add_lambda_times_row(int add_to,int summand,number factor);
123  int non_zero_entries(int row);
124};
125class mac_poly_r{
126public:
127  number coef;
128  mac_poly_r* next;
129  int exp;
130  mac_poly_r():next(NULL){}
131};
132//mac_polys exp are smaller iff they are greater by monomial ordering
133//corresponding to solving linear equations notation
134
135typedef mac_poly_r* mac_poly;
136class tgb_sparse_matrix{
137 private:
138  mac_poly* mp;
139  int columns;
140  int rows;
141  BOOLEAN free_numbers;
142 public:
143  void sort_rows();
144  friend poly free_row_to_poly(tgb_sparse_matrix* mat, int row, poly* monoms, int monom_index);
145  friend void init_with_mac_poly(tgb_sparse_matrix* mat, int row, mac_poly m);
146  tgb_sparse_matrix(int i, int j);
147  ~tgb_sparse_matrix();
148  int get_rows();
149  int get_columns();
150  void print();
151  //  void perm_rows(int i, int j);
152  void perm_rows(int i, int j){
153  mac_poly h;
154  h=mp[i];
155  mp[i]=mp[j];
156  mp[j]=h;
157  }
158  void set(int i, int j, number n);
159  number get(int i, int j);
160  BOOLEAN is_zero_entry(int i, int j);
161  void free_row(int row, BOOLEAN free_non_zeros=TRUE);
162  int min_col_not_zero_in_row(int row);
163  int next_col_not_zero(int row,int pre);
164  BOOLEAN zero_row(int row);
165  void mult_row(int row,number factor);
166  void add_lambda_times_row(int add_to,int summand,number factor);
167  int non_zero_entries(int row);
168};
169struct poly_array_list{
170  poly* p;
171  int size;
172  poly_array_list* next;
173};
174struct calc_dat
175{
176  int* rep;
177  char** states;
178  ideal S;
179  ring r;
180  int* lengths;
181  long* short_Exps;
182  kStrategy strat;
183  int* T_deg;
184  poly tmp_lm;
185  poly* tmp_pair_lm;
186  poly* expandS;
187  poly* gcd_of_terms;
188  int_pair_node* soon_free;
189  sorted_pair_node** apairs;
190  BOOLEAN* modifiedS;
191  poly_list_node* to_destroy;
192  //for F4
193  mp_array_list* F;
194  poly_array_list* F_minus;
195
196  //end for F4
197#ifdef HEAD_BIN
198  struct omBin_s*   HeadBin;
199#endif
200  unsigned int reduction_steps;
201  int n;
202  int normal_forms;
203  int current_degree;
204  int Rcounter;
205  int last_index;
206  int max_pairs;
207  int pair_top;
208  int easy_product_crit;
209  int extended_product_crit;
210  int average_length;
211  BOOLEAN is_char0;
212  BOOLEAN is_homog;
213  BOOLEAN F4_mode;
214};
215class red_object{
216 public:
217  kBucket_pt bucket;
218  poly p;
219  formal_sum_descriptor* sum;
220  unsigned long sev;
221  void flatten();
222  void validate();
223  void adjust_coefs(number c_r, number c_ac_r);
224  int guess_quality(calc_dat* c);
225  int clear_to_poly();
226  void canonicalize();
227};
228
229
230enum calc_state
231  {
232    UNCALCULATED,
233    HASTREP,
234    UNIMPORTANT,
235    SOONTREP
236  };
237
238static int add_to_reductors(calc_dat* c, poly h, int len);
239static int bucket_guess(kBucket* bucket);
240static poly redNFTail (poly h,const int sl,kStrategy strat, int len);
241static poly redNF2 (poly h,calc_dat* c , int &len, number&  m,int n=0);
242static void free_sorted_pair_node(sorted_pair_node* s, ring r);
243static void shorten_tails(calc_dat* c, poly monom);
244static void replace_pair(int & i, int & j, calc_dat* c);
245static sorted_pair_node** add_to_basis(poly h, int i, int j,calc_dat* c, int* ip=NULL);
246static void do_this_spoly_stuff(int i,int j,calc_dat* c);
247//ideal t_rep_gb(ring r,ideal arg_I);
248static BOOLEAN has_t_rep(const int & arg_i, const int & arg_j, calc_dat* state);
249static int* make_connections(int from, poly bound, calc_dat* c);
250static int* make_connections(int from, int to, poly bound, calc_dat* c);
251static void now_t_rep(const int & arg_i, const int & arg_j, calc_dat* c);
252static void soon_t_rep(const int & arg_i, const int & arg_j, calc_dat* c);
253static int pLcmDeg(poly a, poly b);
254static int simple_posInS (kStrategy strat, poly p,int len, BOOLEAN is_char0);
255static BOOLEAN find_next_pair(calc_dat* c, BOOLEAN go_higher=TRUE);
256
257static sorted_pair_node* pop_pair(calc_dat* c);
258static BOOLEAN no_pairs(calc_dat* c);
259static void clean_top_of_pair_list(calc_dat* c);
260static void super_clean_top_of_pair_list(calc_dat* c);
261static BOOLEAN state_is(calc_state state, const int & i, const int & j, calc_dat* c);
262static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, calc_dat* c);
263static int pair_better_gen(const void* ap,const void* bp);
264static poly redTailShort(poly h, kStrategy strat);
265static poly gcd_of_terms(poly p, ring r);
266static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, calc_dat* c);
267static poly kBucketGcd(kBucket* b, ring r);
268static void multi_reduction(red_object* los, int & losl, calc_dat* c);
269static sorted_pair_node* quick_pop_pair(calc_dat* c);
270static sorted_pair_node* top_pair(calc_dat* c);
271static int quality(poly p, int len, calc_dat* c);
272/**
273   makes on each red_object in a region a single_step
274 **/
275class reduction_step{
276 public:
277  /// we assume hat all occuring red_objects have same lm, and all
278  /// occ. lm's in r[l...u] are the same, only reductor does not occur
279  virtual void reduce(red_object* r, int l, int u);
280  //int reduction_id;
281  virtual ~reduction_step();
282  calc_dat* c;
283  int reduction_id;
284};
285class simple_reducer:public reduction_step{
286 public:
287  poly p;
288  kBucket_pt fill_back;
289  int p_len;
290  simple_reducer(poly p, int p_len, calc_dat* c =NULL){
291    this->p=p;
292    this->p_len=p_len;
293    this->c=c;
294  }
295  virtual void pre_reduce(red_object* r, int l, int u);
296  virtual void reduce(red_object* r, int l, int u);
297  ~simple_reducer();
298
299  virtual void target_is_a_sum_reduce(red_object & ro);
300  virtual void target_is_no_sum_reduce(red_object & ro);
301};
302class join_simple_reducer:public simple_reducer{
303 public:
304  join_simple_reducer(poly p, int p_len, poly high_to):simple_reducer(p,p_len){
305    ac=new reduction_accumulator( p, p_len, high_to);
306   
307   
308  }
309    ~join_simple_reducer();
310   void pre_reduce(red_object* r, int l, int u);
311  void target_is_no_sum_reduce(red_object & ro);
312  reduction_accumulator* ac;
313};
314//class sum_canceling_reducer:public reduction_step {
315//  void reduce(red_object* r, int l, int u);
316//};
317struct find_erg{
318  poly expand;
319  int expand_length;
320  int to_reduce_u;
321  int to_reduce_l;
322  int reduce_by;//index of reductor
323  BOOLEAN fromS;//else from los
324
325};
326
327static void multi_reduce_step(find_erg & erg, red_object* r, calc_dat* c);
328static void finalize_reduction_step(reduction_step* r);
329
330#endif
Note: See TracBrowser for help on using the repository browser.