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

◆ get_terms()

ring_elem PolyRing::get_terms ( int nvars0,
const ring_elem f,
int lo,
int hi ) const
virtual

Implements PolynomialRing.

Definition at line 1919 of file poly.cpp.

1923{
1924 int nterms = n_logical_terms(nvars0, f);
1925 if (lo < 0) lo = nterms + lo;
1926 if (hi < 0) hi = nterms + hi;
1927
1928 Nterm *t = f;
1929 if (t == nullptr) return t;
1930 Nterm head;
1931 Nterm *result = &head;
1932
1933 exponents_t exp1 = newarray_atomic(int, n_vars());
1935 M_->to_expvector(t->monom, exp1);
1936 int n = 0;
1937 while (t != nullptr)
1938 {
1939 if (n > hi) break;
1940 if (n >= lo)
1941 {
1942 result->next = copy_term(t);
1943 result = result->next;
1944 }
1945 t = t->next;
1946 if (t == nullptr) break;
1947 M_->to_expvector(t->monom, exp2);
1948 if (EQ == exponents::lex_compare(nvars0, exp1, exp2)) continue;
1949 exponents_t temp = exp1;
1950 exp1 = exp2;
1951 exp2 = temp;
1952 n++;
1953 }
1954 result->next = nullptr;
1955 return head.next;
1956}
exponents::Exponents exponents_t
static int lex_compare(int nvars, ConstExponents a, ConstExponents b)
Nterm * copy_term(const Nterm *t) const
Definition poly.cpp:161
virtual int n_logical_terms(int nvars0, const ring_elem f) const
Definition poly.cpp:1764
const Monoid * M_
Definition polyring.hpp:124
int n_vars() const
Definition polyring.hpp:196
VALGRIND_MAKE_MEM_DEFINED & result(result)
const mpreal exp2(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition mpreal.h:2299
#define newarray_atomic(T, len)
Definition newdelete.hpp:91
Nterm * next
Definition ringelem.hpp:157
int monom[1]
Definition ringelem.hpp:160
const int EQ
Definition style.hpp:40

References copy_term(), EQ, ExponentVector< int, true >::lex_compare(), PolynomialRing::M_, Nterm::monom, n_logical_terms(), PolynomialRing::n_vars(), newarray_atomic, Nterm::next, and result().