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

◆ getSmallIntegerCoefficients() [2/2]

bool RingElement::getSmallIntegerCoefficients ( std::vector< long > & result_coeffs) const

Definition at line 421 of file relem.cpp.

423{
424 const PolynomialRing *R = get_ring()->cast_to_PolynomialRing();
425 const Ring *K = R->getCoefficientRing();
426 if (R == nullptr || R->n_vars() != 1)
427 {
428 throw exc::engine_error(
429 "Expected a polynomial in a univariate polynomial ring");
430 return false; // Should not be needed
431 }
432
433 if (is_zero())
434 {
435 result_coeffs.resize(0);
436 return true;
437 }
438 int lo, deg; // ignore lo, and deg == degree of the univariate polynomial f.
439 R->degree_of_var(0, get_value(), lo, deg);
440 result_coeffs.resize(deg + 1);
441 for (int i = 0; i <= deg; i++) result_coeffs[i] = 0;
442 int exp[1];
443 for (Nterm& t : get_value())
444 {
445 std::pair<bool, long> res = K->coerceToLongInteger(t.coeff);
446 if (not res.first)
447 {
448 // At this point, the answer is meaningless
449 result_coeffs.resize(0);
450 return false;
451 }
452 long coeff = res.second;
453
454 R->getMonoid()->to_expvector(t.monom, exp);
455 assert(exp[0] >= 0);
456 assert(exp[0] <= deg);
457 result_coeffs[exp[0]] = coeff;
458 }
459 return true;
460}
virtual std::pair< bool, long > coerceToLongInteger(ring_elem a) const
Definition ring.cpp:236
virtual const PolynomialRing * cast_to_PolynomialRing() const
Definition ring.hpp:243
ring_elem get_value() const
Definition relem.hpp:79
bool is_zero() const
Definition relem.hpp:167
const Ring * R
Definition relem.hpp:68
const Ring * get_ring() const
Definition relem.hpp:81
const mpreal exp(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition mpreal.h:2298

References Ring::cast_to_PolynomialRing(), Ring::coerceToLongInteger(), get_ring(), get_value(), is_zero(), and R.

Referenced by M2::ARingGFFlint::ARingGFFlint(), M2::ARingGFFlintBig::ARingGFFlintBig(), getGFRepresentation(), M2::ARingGFFlint::promote(), M2::ARingGFFlintBig::promote(), and M2::ARingGFM2::promote().