PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00014 //***************************************************************************** 00015 00016 #ifndef polybori_groebner_PolynomialSugar_h_ 00017 #define polybori_groebner_PolynomialSugar_h_ 00018 00019 // include basic definitions 00020 #include "groebner_defs.h" 00021 00022 BEGIN_NAMESPACE_PBORIGB 00023 00028 class PolynomialSugar{ 00029 public: 00030 PolynomialSugar(const Polynomial& poly): lm(poly.ring()), p(poly), exp(){ 00031 sugar=p.deg(); 00032 if (!(p.isZero())){ 00033 this->lm=p.boundedLead(sugar); 00034 this->exp=lm.exp(); 00035 PBORI_ASSERT(lm==p.lead()); 00036 PBORI_ASSERT(exp==p.leadExp()); 00037 } 00038 00039 length=p.length(); 00040 } 00041 PolynomialSugar(const Polynomial& poly, int sugar, len_type length): 00042 lm(poly.ring()), p(poly), exp() { 00043 00044 PBORI_ASSERT(length>=0); 00045 00046 //sugar=p.deg(); 00047 this->sugar=sugar; 00048 this->length=length; 00049 PBORI_ASSERT(sugar>=p.deg()); 00050 PBORI_ASSERT(length>=p.length()); 00051 if (!(p.isZero())){ 00052 this->lm=p.boundedLead(sugar); 00053 this->exp=lm.exp(); 00054 PBORI_ASSERT(lm==p.lead()); 00055 PBORI_ASSERT(exp==p.leadExp()); 00056 } 00057 } 00058 const BooleMonomial& lead() const{ 00059 return this->lm; 00060 } 00061 const Exponent& leadExp() const{ 00062 return this->exp; 00063 } 00064 deg_type getSugar() const{ 00065 return sugar; 00066 } 00067 wlen_type getLengthEstimation() const { 00068 return length; 00069 } 00070 bool isZero() const{ 00071 return p.isZero(); 00072 } 00073 void add(const Polynomial p2, deg_type sugar2, wlen_type length){ 00074 PBORI_ASSERT(p2.leadExp()==exp); 00075 PBORI_ASSERT(length>=0); 00076 PBORI_ASSERT(length>=p2.length()); 00077 this->p=p+p2; 00078 this->sugar=std::max(sugar2,this->sugar); 00079 00080 if (!(p.isZero())){ 00081 this->lm=this->p.boundedLead(sugar); 00082 this->exp=this->lm.exp(); 00083 } else { 00084 lm=Monomial(p2.ring()); 00085 exp=Exponent(); 00086 } 00087 this->length+=length; 00088 this->length-=2; 00089 if (p2.ring().ordering().isTotalDegreeOrder()) this->sugar=this->lm.deg(); 00090 00091 PBORI_ASSERT((p.isZero())|| (lm==p.lead())); 00092 PBORI_ASSERT((p.isZero())||(exp==p.leadExp())); 00093 } 00094 void adjustSugar(){ 00095 sugar=p.deg(); 00096 } 00097 bool isOne(){ 00098 return p.isOne(); 00099 } 00100 Polynomial value() const{ 00101 return p; 00102 } 00103 wlen_type eliminationLength() const{ 00105 wlen_type res=1; 00106 if (isZero()) return 0; 00107 res=res+(sugar-exp.deg()+1)*(length-1); 00108 PBORI_ASSERT(res>=p.eliminationLengthWithDegBound(sugar)); 00109 return res; 00110 //return p.eliminationLengthWithDegBound(sugar); 00111 } 00112 void adjustLm(){ 00113 this->lm=this->p.lead(); 00114 exp=lm.exp(); 00115 PBORI_ASSERT(lm==p.lead()); 00116 PBORI_ASSERT(exp==p.leadExp()); 00117 } 00118 protected: 00119 Monomial lm; 00120 len_type length; 00121 deg_type sugar; 00122 Polynomial p; 00123 Exponent exp; 00124 }; 00125 00126 END_NAMESPACE_PBORIGB 00127 00128 #endif /* polybori_PolynomialSugar_h_ */