/usr/include/polybori/groebner/red_tail.h is in libpolybori-groebner-dev 0.8.3-5build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | // -*- c++ -*-
//*****************************************************************************
/** @file red_tail.h
*
* @author Michael Brickenstein
* @date 2011-07-01
*
* This file includes the definition of the @c red_tail functions.
*
* @par Copyright:
* (c) 2006-2011 by The PolyBoRi Team
*
**/
//*****************************************************************************
#ifndef polybori_groebner_red_tail_h_
#define polybori_groebner_red_tail_h_
// include basic definitions
#include "groebner_defs.h"
#include "LexHelper.h"
#include "DegOrderHelper.h"
#include "BlockOrderHelper.h"
#include "GroebnerStrategy.h"
BEGIN_NAMESPACE_PBORIGB
inline Polynomial
red_tail_general(const ReductionStrategy& strat, Polynomial p){
PBORI_ASSERT(!p.isZero());
// int deg_bound=p.deg(); /// @todo unused?
std::vector<Polynomial> res_vec;
Polynomial orig_p=p;
bool changed=false;
// assuming non-zero
Monomial lm=p.lead();
res_vec.push_back(lm);
p=Polynomial(p.diagram().diff(lm.diagram()));
while(!(p.isZero())){
//res+=lm;
//p-=lm;
std::vector<Monomial> irr;
Polynomial::ordered_iterator it=p.orderedBegin();
Polynomial::ordered_iterator end=p.orderedEnd();
while((it!=end)&& (irreducible_lead(*it,strat))){
irr.push_back(*it);
it++;
}
Monomial rest_lead(p.ring());
if PBORI_UNLIKELY((!(changed))&& (it==end)) return orig_p;
//@todo: if it==end irr_p=p, p=Polnomial(0)
Polynomial irr_p(p.ring());
if PBORI_LIKELY(it!=end) {
irr_p=add_up_generic(irr, p.ring().zero());
rest_lead=*it;
}
else irr_p=p;
int s;
s=irr.size();
PBORI_ASSERT(s==irr_p.length());
//if (s!=irr_p.length()) cout<<"ADDUP FAILED!!!!!!!!!!!!!!!!!!!!!!!!\n";
//for(i=0;i<s;i++){
// res_vec.push_back(irr[i]);
//}
res_vec.push_back(irr_p);
//p=p-irr_p;
p=Polynomial(p.diagram().diff(irr_p.diagram()));
if PBORI_UNLIKELY(p.isZero()) break;
//Monomial lm=p.lead();
//res_vec.push_back(lm);
//p=Polynomial(p.().diff(lm.diagram()));
if (!(p.ring().ordering().isDegreeOrder()))
p=nf3(strat,p, rest_lead);
else{
p=nf3_degree_order(strat,p,rest_lead);
}
changed=true;
}
//should use already added irr_p's
return add_up_polynomials(res_vec, p.ring().zero());
}
template <class Helper>
inline Polynomial
red_tail_generic(const ReductionStrategy& strat, Polynomial p){
PBORI_ASSERT(!p.isZero());
// int deg_bound=p.deg(); /// @todo unused?
std::vector<Polynomial> res_vec;
Polynomial orig_p=p;
bool changed=false;
// assuming non-zero
Monomial lm = p.lead();
res_vec.push_back(lm);
p = Polynomial(p.diagram().diff(lm.diagram()));
while(!(p.isZero())){
{
Polynomial p_bak=p;
p = cheap_reductions(strat, p);
if (p!=p_bak){
changed=true;
}
}
//p-=lm;
std::vector<Monomial> irr;
typename Helper::iterator_type it=Helper::begin(p);
typename Helper::iterator_type it_orig=it;
typename Helper::iterator_type end=Helper::end(p);
bool rest_is_irreducible=false;
//typedef (typename Helper::iterator_type) it_type;
//typedef (typename it_type::value_type) mon_type;
//Monomial mymon;
if PBORI_LIKELY(strat.canRewrite(p)){
Polynomial irreducible_part=mod_mon_set(p.diagram(),strat.minimalLeadingTerms);
if (!(irreducible_part.isZero())){
res_vec.push_back(irreducible_part);
Polynomial p2=p+irreducible_part;
it=Helper::begin(p2);
it_orig=it;
end=Helper::end(p2);
p=p2;
}
while((it!=end)&& (Helper::irreducible_lead(*it,strat))){
if PBORI_UNLIKELY(Helper::knowRestIsIrreducible(it,strat)){
rest_is_irreducible=true;
break;
} else{
irr.push_back(*it);
it++;
}
}
} else {
rest_is_irreducible=true;
}
Monomial rest_lead(p.ring());
if PBORI_UNLIKELY((!(changed))&& (it==end)) return orig_p;
//@todo: if it==end irr_p=p, p=Polnomial(0)
Polynomial irr_p(p.ring());
if PBORI_LIKELY((it!=end) &&(!(rest_is_irreducible))) {
irr_p=Helper::sum_range(irr,it_orig,it, p.ring().zero());//add_up_monomials(irr);
rest_lead=*it;
}
else irr_p=p;
size_t s;
s=irr.size();
PBORI_ASSERT((s==irr_p.length())||(rest_is_irreducible));
res_vec.push_back(irr_p);
p=Polynomial(p.diagram().diff(irr_p.diagram()));
if PBORI_UNLIKELY(p.isZero()) break;
p=Helper::nf(strat,p,rest_lead);
changed=true;
}
//should use already added irr_p's
return add_up_polynomials(res_vec, p.ring().zero());
}
inline Polynomial
red_tail(const ReductionStrategy& strat, Polynomial p){
if PBORI_UNLIKELY(p.isZero()) return p;
if (p.ring().ordering().isLexicographical())
return red_tail_generic<LexHelper>(strat,p);
if (p.ring().ordering().isDegreeOrder())
return red_tail_generic<DegOrderHelper>(strat,p);
if (p.ring().ordering().isBlockOrder())
return red_tail_generic<BlockOrderHelper>(strat,p);
return red_tail_general(strat,p);
}
inline Polynomial
red_tail_short(const ReductionStrategy& strat, Polynomial p){
Polynomial res(p.ring());
while(!(p.isZero())){
Polynomial lm=p.lead();
res+=lm;
p-=lm;
p=nf3_short(strat,p);
}
return res;
}
inline Polynomial
red_tail_in_last_block(const GroebnerStrategy& strat, Polynomial p){
Polynomial::navigator nav=p.navigation();
idx_type last=p.ring().ordering().lastBlockStart();
if ((*nav)>=last) //includes constant polynomials
return p;
while ((*nav)<last){
nav.incrementElse();
}
if (nav.isConstant()){
//we don't check for strat containing one at this point
return p;
}
Polynomial l1(nav, p.ring());
Polynomial l2=strat.nf(l1);
if (!(l2.isZero())) l2=red_tail(strat.generators,l2);
return p+(l1+l2);
}
END_NAMESPACE_PBORIGB
#endif /* polybori_groebner_red_tail_h_ */
|