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

◆ list_form()

engine_RawArrayPairOrNull M2FreeAlgebra::list_form ( const Ring * coeffR,
const ring_elem f ) const
virtual

Definition at line 348 of file M2FreeAlgebra.cpp.

349{
350 // Either coeffR should be the actual coefficient ring (possible a "toField"ed ring)
351 // or a polynomial ring. If not, NULL is returned and an error given
352 // In the latter case, the last set of variables are part of
353 // the coefficients.
354
355 auto f = reinterpret_cast<const Poly*>(ff.get_Poly());
356 if (coeffR != coefficientRing())
357 {
358 ERROR("expected coefficient ring");
359 return nullptr;
360 }
361 int nterms = static_cast<int>(f->numTerms());
362 engine_RawMonomialArray monoms = GETMEM(engine_RawMonomialArray, sizeofarray(monoms,nterms));
363 engine_RawRingElementArray coeffs = GETMEM(engine_RawRingElementArray, sizeofarray(coeffs,nterms));
364 engine_RawArrayPair result = newitem(struct engine_RawArrayPair_struct);
365 monoms->len = nterms;
366 coeffs->len = nterms;
367 result->monoms = monoms;
368 result->coeffs = coeffs;
369
370 // fill result
371 std::vector<int> vp;
372 int next = 0;
373 for (auto i=f->cbegin(); i != f->cend(); ++i, ++next)
374 {
375 ring_elem c = coefficientRing()->copy(i.coeff());
376 vp.resize(0);
377 monoid().getMonomialReversed(i.monom(), vp); // should this instead reverse the monomial?
378 coeffs->array[next] = RingElement::make_raw(coeffR, c);
379 monoms->array[next] = EngineMonomial::make(vp); // reverses the monomial
380 }
381
382 return result;
383}
Polynomial< CoefficientRingType > Poly
static EngineMonomial * make(int v, int e)
Definition monomial.cpp:26
void getMonomialReversed(Monom monom, std::vector< int > &result) const
const Ring * coefficientRing() const
const FreeMonoid & monoid() const
virtual ring_elem copy(const ring_elem f) const =0
static RingElement * make_raw(const Ring *R, ring_elem f)
Definition relem.cpp:20
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define sizeofarray(s, len)
Definition m2-mem.h:129
struct engine_RawArrayPair_struct * engine_RawArrayPair
Definition m2-types.h:183
#define newitem(T)
Definition newdelete.hpp:86
#define GETMEM(T, size)

References coefficientRing(), Ring::copy(), ERROR, ring_elem::get_Poly(), GETMEM, FreeMonoid::getMonomialReversed(), EngineMonomial::make(), RingElement::make_raw(), monoid(), newitem, result(), Ring::Ring(), and sizeofarray.

Referenced by IM2_RingElement_list_form(), and M2FreeAlgebraQuotient::list_form().