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

◆ homogenize() [2/2]

ring_elem PolyRing::homogenize ( const ring_elem f,
int v,
int deg,
const std::vector< int > & wts ) const
virtual

Implements PolynomialRing.

Definition at line 603 of file poly.cpp.

607{
608 // assert(wts[v] != 0);
609 // If an error occurs, then return 0, and set gError.
610
612 Nterm head;
613 Nterm *result = &head;
614 for (Nterm& a : f)
615 {
616 M_->to_expvector(a.monom, exp);
617 auto e = exponents::weight(n_vars(), exp, wts);
618 if (((d - e) % wts[v]) != 0)
619 {
620 // We cannot homogenize, so clean up and exit.
621 result->next = nullptr;
622 ERROR("homogenization impossible");
623 result = nullptr;
624 return result;
625 }
626 exp[v] += (d - e) / wts[v];
627 if (is_skew_ && skew_.is_skew_var(v) && exp[v] > 1) continue;
628 result->next = new_term();
629 result = result->next;
630 result->coeff = K_->copy(a.coeff);
631 M_->from_expvector(exp, result->monom);
632 }
633 result->next = nullptr;
634 sort(head.next); // The monomial order, etc. might all have changed.
635 // Some terms might even drop out
636 freemem(exp);
637 return head.next;
638}
exponents::Exponents exponents_t
static Exponent weight(int nvars, ConstExponents a, const std::vector< Exponent > &wts)
Nterm * new_term() const
Definition poly.cpp:146
void sort(Nterm *&f) const
Definition poly.cpp:2077
SkewMultiplication skew_
Definition polyring.hpp:104
const Ring * K_
Definition polyring.hpp:123
const Monoid * M_
Definition polyring.hpp:124
int n_vars() const
Definition polyring.hpp:196
void freemem(void *s)
Definition m2-mem.cpp:103
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
const mpreal exp(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition mpreal.h:2298
#define newarray_atomic(T, len)
Definition newdelete.hpp:91
Nterm * next
Definition ringelem.hpp:157

References ERROR, freemem(), PolynomialRing::is_skew_, PolynomialRing::K_, PolynomialRing::M_, PolynomialRing::n_vars(), new_term(), newarray_atomic, Nterm::next, PolynomialRing::nvars_, result(), PolynomialRing::skew_, sort(), and ExponentVector< int, true >::weight().

Referenced by homogenize().