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

◆ addScalarMultipleOf()

void FreeAlgebra::addScalarMultipleOf ( Poly & result,
Poly::const_iterator fBegin,
Poly::const_iterator fEnd,
Poly::const_iterator gBegin,
Poly::const_iterator gEnd,
ring_elem coeff ) const

Definition at line 315 of file FreeAlgebra.cpp.

321{
322 auto& outcoeff = result.getCoeffInserter();
323 auto& outmonom = result.getMonomInserter();
324
325 // loop over the iterators for f and g, adding the bigger of the two to
326 // the back of the monomial and coefficient vectors of the result. If a tie, add the coefficients.
327 while ((fBegin != fEnd) && (gBegin != gEnd))
328 {
329 auto fMon = fBegin.monom();
330 auto gMon = gBegin.monom();
331 auto fCoeff = fBegin.coeff();
332 auto gCoeff = gBegin.coeff();
333 ring_elem coeffResult;
334 switch(monoid().compare(fMon,gMon))
335 {
336 case LT:
337 coeffResult = coefficientRing()->mult(coeff,gCoeff);
338 if (!coefficientRing()->is_zero(coeffResult))
339 {
340 outcoeff.push_back(coeffResult);
341 monoid().copy(gMon, outmonom);
342 }
343 gBegin++;
344 break;
345 case GT:
346 outcoeff.push_back(fCoeff);
347 monoid().copy(fMon, outmonom);
348 fBegin++;
349 break;
350 case EQ:
351 ring_elem tempResult = coefficientRing()->mult(coeff,gCoeff);
352 coeffResult = coefficientRing()->add(fCoeff,tempResult);
353 if (!coefficientRing()->is_zero(coeffResult))
354 {
355 outcoeff.push_back(coeffResult);
356 monoid().copy(gMon, outmonom);
357 }
358 fBegin++;
359 gBegin++;
360 }
361 }
362 if (fBegin == fEnd)
363 {
364 for ( ; gBegin != gEnd; gBegin++)
365 {
366 auto gMon = gBegin.monom();
367 auto gCoeff = gBegin.coeff();
368 ring_elem coeffResult = coefficientRing()->mult(coeff,gCoeff);
369 if (!coefficientRing()->is_zero(coeffResult))
370 {
371 outcoeff.push_back(coeffResult);
372 monoid().copy(gMon, outmonom);
373 }
374 }
375 }
376 if (gBegin == gEnd)
377 {
378 for ( ; fBegin != fEnd; fBegin++)
379 {
380 auto fMon = fBegin.monom();
381 auto fCoeff = fBegin.coeff();
382 outcoeff.push_back(fCoeff);
383 monoid().copy(fMon, outmonom);
384 }
385 }
386}
const Ring * coefficientRing() const
const FreeMonoid & monoid() const
bool is_zero(const Poly &f) const
void copy(const Monom &m, MonomialInserter &result) const
virtual ring_elem add(const ring_elem f, const ring_elem g) const =0
virtual ring_elem mult(const ring_elem f, const ring_elem g) const =0
static int compare(const vecterm *t, const vecterm *s)
Definition geovec.hpp:112
VALGRIND_MAKE_MEM_DEFINED & result(result)
const int EQ
Definition style.hpp:40
const int GT
Definition style.hpp:41
const int LT
Definition style.hpp:39

References Ring::add(), coefficientRing(), compare(), FreeMonoid::copy(), EQ, GT, is_zero(), LT, monoid(), Ring::mult(), and result().

Referenced by add(), add(), subtract(), and subtractScalarMultipleOf().