Macaulay2 Engine
Loading...
Searching...
No Matches

◆ twoSidedReduction() [2/2]

auto NCGroebner::twoSidedReduction ( const Poly * reducee) const->Poly *

Definition at line 254 of file NCGroebner.cpp.

255{
256 // stats for benchmarking, debug only...
257 size_t loop_count = 0;
258 size_t nterms = 0; // number of terms added in to the heap
259
260 // easy access to variables in the class
261 const FreeAlgebra& A{ freeAlgebra() };
262 const PolyList& reducers{ currentValue() };
263 const WordTable& W{ mWordTable };
264 //const SuffixTree& W{ mWordTable };
265
266 // pair will be (i,j) where the ith word in wordtable appears in word in position j
267 std::pair<int,int> subwordPos;
268 Word leftWord, rightWord;
269
270 Poly* remainder = new Poly;
271 Poly tmp; // temp polynomial for seeing what is being added to heap.
272
273 mHeap->clear();
274 nterms += reducee->numTerms();
275 mHeap->addPolynomial(*reducee);
276
278
279 while (not mHeap->isZero())
280 {
281 loop_count++;
282
283 // Find (left, right, index) s.t. left*reducers[index]*right == leadMonomial(reduceeSoFar).
284 Word reduceeLeadWord;
285 std::pair<Monom, ring_elem> LT { mHeap->viewLeadTerm() };
286
287 A.monoid().wordFromMonom(reduceeLeadWord, LT.first);
288
289 if (W.subword(reduceeLeadWord,subwordPos))
290 {
291 // If there is one, perform reduceeSoFar -= coef * left * reducers[index] * right
292 A.monoid().wordPrefixFromMonom(leftWord, LT.first, subwordPos.second);
293 A.monoid().wordSuffixFromMonom(rightWord, LT.first, W[subwordPos.first].size()+subwordPos.second);
294
295 ring_elem c = A.coefficientRing()->negate(LT.second);
296 ring_elem d = reducers[subwordPos.first]->cbegin().coeff();
297 // TODO: Check to see if d is a unit before inverting.
298 auto coeffNeeded = A.coefficientRing()->divide(c,d);
299
300 A.clear(tmp);
302 *reducers[subwordPos.first],
303 coeffNeeded,
304 leftWord,
305 rightWord);
306 nterms += tmp.numTerms();
307 mHeap->addPolynomial(tmp);
308 }
309 else
310 {
311 // If none, copy that term to the remainder (use add_to_end)
312 // and subtract that term
313 A.add_to_end(*remainder, LT.second, LT.first);
314 mHeap->removeLeadTerm();
315 }
316 }
317 if (M2_gbTrace >= 5)
318 {
319 std::cout << "reduction: " << "#steps: " << loop_count << " " << FreeMonoidLogger() << std::endl;
320 std::cout << " " << "#terms: " << nterms << std::endl;
321 std::cout << " " << AllocLogger() << std::endl;
322 }
323 return remainder;
324}
Polynomial< CoefficientRingType > Poly
gc_vector< Poly * > PolyList
const Ring * coefficientRing() const
void add_to_end(Poly &f, const Poly &g) const
void clear(Poly &f) const
const FreeMonoid & monoid() const
void mult_by_term_left_and_right(Poly &result, const Poly &f, const ring_elem c, const Monom leftM, const Monom rightM) const
void wordFromMonom(Word &result, const Monom &m) const
void wordPrefixFromMonom(Word &result, const Monom &m, int endIndex) const
void wordSuffixFromMonom(Word &result, const Monom &m, int beginIndex) const
static void reset()
std::unique_ptr< PolynomialHeap > mHeap
const PolyList & currentValue() const
const FreeAlgebra & freeAlgebra() const
WordTable mWordTable
virtual ring_elem divide(const ring_elem f, const ring_elem g) const =0
virtual ring_elem negate(const ring_elem f) const =0
bool subword(Word word, std::pair< int, int > &output) const
int M2_gbTrace
Definition m2-types.cpp:52
const mpreal remainder(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
Definition mpreal.h:2504
const int LT
Definition style.hpp:39

References FreeAlgebra::add_to_end(), FreeAlgebra::clear(), FreeAlgebra::coefficientRing(), currentValue(), Ring::divide(), freeAlgebra(), LT, M2_gbTrace, mHeap, FreeAlgebra::monoid(), FreeAlgebra::mult_by_term_left_and_right(), mWordTable, Ring::negate(), FreeMonoidLogger::reset(), WordTable::subword(), FreeMonoid::wordFromMonom(), FreeMonoid::wordPrefixFromMonom(), and FreeMonoid::wordSuffixFromMonom().