PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00014 //***************************************************************************** 00015 00016 #ifndef polybori_groebner_tables_h_ 00017 #define polybori_groebner_tables_h_ 00018 00019 // include basic definitions 00020 #include "groebner_defs.h" 00021 #include <stdexcept> 00022 #include <polybori/groebner/ZeroFunction.h> 00023 #include <polybori/groebner/SetBitUInt.h> 00024 00025 #define PBORI_HAVE_DLEX4_DATA 1 00026 00027 #ifdef PBORI_HAVE_DLEX4_DATA 00028 #include <polybori/groebner/dlex4data.h> 00029 #endif 00030 00031 #define PBORI_HAVE_LP4_DATA 1 00032 00033 #ifdef PBORI_HAVE_LP4_DATA 00034 #include <polybori/groebner/lp4data.h> 00035 #endif 00036 00037 #define PBORI_HAVE_DP_ASC4_DATA 1 00038 00039 #ifdef PBORI_HAVE_DP_ASC4_DATA 00040 #include <polybori/groebner/dp_asc4data.h> 00041 #endif 00042 00043 BEGIN_NAMESPACE_PBORIGB 00044 00045 00046 template<class value_type, class initializer, class set_bit> 00047 inline value_type 00048 p2code(Polynomial p, const std::vector<char> & ring_2_0123, int max_vars){ 00049 Polynomial::exp_iterator it_p=p.expBegin(); 00050 Polynomial::exp_iterator end_p=p.expEnd(); 00051 initializer init; 00052 value_type p_code=init(max_vars); 00053 PBORI_ASSERT(max_vars<sizeof(unsigned int)*8); 00054 set_bit bit_setter; 00055 while(it_p!=end_p){ 00056 Exponent curr_exp=*it_p; 00057 Exponent::const_iterator it_v=curr_exp.begin(); 00058 Exponent::const_iterator end_v=curr_exp.end(); 00059 unsigned int exp_code=0; 00060 //exp code is int between 0 and 15 00061 while(it_v!=end_v){ 00062 //cout<<"table value:"<<(int)ring_2_0123[(*it_v)]<<endl; 00063 exp_code|=(1<<ring_2_0123[(*it_v)]); 00064 //cout<<"exp_code:"<<exp_code<<endl; 00065 it_v++; 00066 } 00067 //cout<<"exp_code final:"<<exp_code<<endl; 00068 //p_code|=(1<<exp_code); 00069 bit_setter(p_code,exp_code); 00070 //so p code is 16-bit unsigned int 00071 //int is fastest 00072 it_p++; 00073 } 00074 return p_code; 00075 } 00076 00077 inline unsigned int 00078 p2code_4(Polynomial p, const std::vector<char> & ring_2_0123){ 00079 return p2code<unsigned int, ZeroFunction, SetBitUInt>(p,ring_2_0123, 4); 00080 } 00081 00082 inline unsigned int 00083 get_table_entry4(const BoolePolyRing& ring, int p_code, int pos){ 00084 switch(ring.ordering().getBaseOrderCode()){ 00085 #ifdef PBORI_HAVE_LP4_DATA 00086 case COrderEnums::lp: 00087 return lp4var_data[p_code][pos]; 00088 #endif 00089 #ifdef PBORI_HAVE_DLEX4_DATA 00090 case COrderEnums::dlex: 00091 return dlex4var_data[p_code][pos]; 00092 #endif 00093 #ifdef PBORI_HAVE_DP_ASC4_DATA 00094 case COrderEnums::dp_asc: 00095 return dp_asc4var_data[p_code][pos]; 00096 #endif 00097 default: 00098 throw std::runtime_error("Groebner tables used with forbidden order"); 00099 } 00100 return 0; 00101 } 00102 00103 00104 inline Monomial 00105 code_2_m_4(const BoolePolyRing& ring, 00106 unsigned int code, const std::vector<idx_type>& back_2_ring){ 00107 00108 Monomial result(ring); 00109 for(int idx = 3; idx >= 0; --idx){ 00110 if ((code & (1<<idx)) != 0){ 00111 result *= ring.variable(back_2_ring[idx]); 00112 } 00113 } 00114 return result; 00115 } 00116 00117 00118 inline Polynomial 00119 code_2_poly_4(const BoolePolyRing& ring, 00120 unsigned int code, const std::vector<idx_type>& back_2_ring){ 00121 00122 Polynomial result(ring); 00123 for(int idx = 15; idx >= 0; --idx){ 00124 if ((code & (1<<idx)) != 0){ 00125 result += code_2_m_4(ring, idx, back_2_ring); 00126 } 00127 } 00128 return result; 00129 } 00130 00131 inline bool 00132 have_ordering_for_tables(const int order_code) { 00133 #ifdef PBORI_HAVE_DLEX4_DATA 00134 if (order_code==COrderEnums::dlex) 00135 return true; 00136 #endif 00137 #ifdef PBORI_HAVE_LP4_DATA 00138 if (order_code==COrderEnums::lp) 00139 return true; 00140 #endif 00141 #ifdef PBORI_HAVE_DP_ASC4_DATA 00142 if (order_code==COrderEnums::dp_asc) 00143 return true; 00144 #endif 00145 return false; 00146 } 00147 00148 inline bool 00149 have_ordering_for_tables(const BoolePolyRing& ring){ 00150 return have_ordering_for_tables(ring.ordering().getOrderCode()); 00151 } 00152 00153 inline bool 00154 have_base_ordering_for_tables(const BoolePolyRing& ring){ 00155 return have_ordering_for_tables(ring.ordering().getBaseOrderCode()); 00156 } 00157 00158 00159 END_NAMESPACE_PBORIGB 00160 00161 #endif /* polybori_groebner_tables_h_ */