PolyBoRi
tables.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
14 //*****************************************************************************
15 
16 #ifndef polybori_groebner_tables_h_
17 #define polybori_groebner_tables_h_
18 
19 // include basic definitions
20 #include "groebner_defs.h"
21 #include <stdexcept>
24 
25 #define PBORI_HAVE_DLEX4_DATA 1
26 
27 #ifdef PBORI_HAVE_DLEX4_DATA
29 #endif
30 
31 #define PBORI_HAVE_LP4_DATA 1
32 
33 #ifdef PBORI_HAVE_LP4_DATA
35 #endif
36 
37 #define PBORI_HAVE_DP_ASC4_DATA 1
38 
39 #ifdef PBORI_HAVE_DP_ASC4_DATA
41 #endif
42 
44 
45 
46 template<class value_type, class initializer, class set_bit>
47 inline value_type
48 p2code(Polynomial p, const std::vector<char> & ring_2_0123, int max_vars){
51  initializer init;
52  value_type p_code=init(max_vars);
53  PBORI_ASSERT(max_vars<sizeof(unsigned int)*8);
54  set_bit bit_setter;
55  while(it_p!=end_p){
56  Exponent curr_exp=*it_p;
57  Exponent::const_iterator it_v=curr_exp.begin();
58  Exponent::const_iterator end_v=curr_exp.end();
59  unsigned int exp_code=0;
60  //exp code is int between 0 and 15
61  while(it_v!=end_v){
62  //cout<<"table value:"<<(int)ring_2_0123[(*it_v)]<<endl;
63  exp_code|=(1<<ring_2_0123[(*it_v)]);
64  //cout<<"exp_code:"<<exp_code<<endl;
65  it_v++;
66  }
67  //cout<<"exp_code final:"<<exp_code<<endl;
68  //p_code|=(1<<exp_code);
69  bit_setter(p_code,exp_code);
70  //so p code is 16-bit unsigned int
71  //int is fastest
72  it_p++;
73  }
74  return p_code;
75 }
76 
77 inline unsigned int
78 p2code_4(Polynomial p, const std::vector<char> & ring_2_0123){
79  return p2code<unsigned int, ZeroFunction, SetBitUInt>(p,ring_2_0123, 4);
80 }
81 
82 inline unsigned int
83 get_table_entry4(const BoolePolyRing& ring, int p_code, int pos){
84  switch(ring.ordering().getBaseOrderCode()){
85  #ifdef PBORI_HAVE_LP4_DATA
86  case COrderEnums::lp:
87  return lp4var_data[p_code][pos];
88  #endif
89  #ifdef PBORI_HAVE_DLEX4_DATA
90  case COrderEnums::dlex:
91  return dlex4var_data[p_code][pos];
92  #endif
93  #ifdef PBORI_HAVE_DP_ASC4_DATA
95  return dp_asc4var_data[p_code][pos];
96  #endif
97  default:
98  throw std::runtime_error("Groebner tables used with forbidden order");
99  }
100  return 0;
101 }
102 
103 
104 inline Monomial
106  unsigned int code, const std::vector<idx_type>& back_2_ring){
107 
108  Monomial result(ring);
109  for(int idx = 3; idx >= 0; --idx){
110  if ((code & (1<<idx)) != 0){
111  result *= ring.variable(back_2_ring[idx]);
112  }
113  }
114  return result;
115 }
116 
117 
118 inline Polynomial
120  unsigned int code, const std::vector<idx_type>& back_2_ring){
121 
122  Polynomial result(ring);
123  for(int idx = 15; idx >= 0; --idx){
124  if ((code & (1<<idx)) != 0){
125  result += code_2_m_4(ring, idx, back_2_ring);
126  }
127  }
128  return result;
129 }
130 
131 inline bool
132 have_ordering_for_tables(const int order_code) {
133  #ifdef PBORI_HAVE_DLEX4_DATA
134  if (order_code==COrderEnums::dlex)
135  return true;
136  #endif
137  #ifdef PBORI_HAVE_LP4_DATA
138  if (order_code==COrderEnums::lp)
139  return true;
140  #endif
141  #ifdef PBORI_HAVE_DP_ASC4_DATA
142  if (order_code==COrderEnums::dp_asc)
143  return true;
144  #endif
145  return false;
146 }
147 
148 inline bool
151 }
152 
153 inline bool
156 }
157 
158 
160 
161 #endif /* polybori_groebner_tables_h_ */