51#define abs(x) (((x) < 0) ? -(x) : (x))
52#define max(a, b) (((a) > (b)) ? (a) : (b))
59 const Ring *R =
p->get_ring();
63 ERROR(
"expected a polynomial ring");
67 ERROR(
"expected a univariate polynomial ring");
71 ERROR(
"expected a nonzero polynomial");
80 mps_context *
s = mps_context_new ();
81 mps_monomial_poly *mps_p = mps_monomial_poly_new (
s, hideg);
82 mps_context_select_algorithm(
s, MPS_ALGORITHM_SECULAR_GA);
84 const auto ID = K->
ringID();
85 for (
Nterm *t =
p->get_value(); t !=
nullptr; t = t->next) {
91 cc.
re = t->coeff.get_double();
93 }
else cc = *t->coeff.get_cc_doubles();
94 mps_monomial_poly_set_coefficient_d (
s, mps_p, deg, cc.
re, cc.
im);
99 mpfr_get_f(mpc_cc->r,t->coeff.get_mpfr(),MPFR_RNDN);
101 mpfr_get_f(mpc_cc->r,&t->coeff.get_cc()->re,MPFR_RNDN);
102 mpfr_get_f(mpc_cc->i,&t->coeff.get_cc()->im,MPFR_RNDN);
104 mps_monomial_poly_set_coefficient_f (
s, mps_p, deg, mpc_cc);
111 mpq_set(q, t->coeff.get_mpq());
112 else mpq_set_z(q, t->coeff.get_mpz());
113 mps_monomial_poly_set_coefficient_q(
s, mps_p, deg, q,
zero);
117 ERROR(
"'roots' expects coefficients in ZZ, QQ, RR or CC");
123 mps_context_set_input_poly (
s, MPS_POLYNOMIAL (mps_p));
124 mps_context_set_output_prec (
s, prec);
125 mps_context_set_output_goal (
s, MPS_OUTPUT_GOAL_APPROXIMATE);
133 result->len =
static_cast<int>(hideg);
138 cplx_t *result_mps = cplx_valloc (hideg);
141 mps_context_get_roots_d (
s, &result_mps,
nullptr);
153 for (
int i = 0; i < hideg; i++) {
154 auto& mps_root = result_mps[i];
163 mpc_t *roots =
nullptr;
164 rdpe_t *radii =
nullptr;
166 mps_context_get_roots_m (
s, &roots, &radii);
177 M2::ARingCCC::Element cc (C0);
178 for (
int i = 0; i < hideg; i++) {
179 auto& mps_root = roots[i];
180 mpfr_set_f(&cc.value().re,mpc_Re(mps_root),MPFR_RNDN);
181 mpfr_set_f(&cc.value().im,mpc_Im(mps_root),MPFR_RNDN);
191 mps_monomial_poly_free(
s, (mps_polynomial *)mps_p);
M2::ARingCCC — arbitrary-precision complex numbers (pair of MPFR floats).
Shared base of the aring framework (namespace M2) that unifies the engine's coefficient rings.
void to_ring_elem(ring_elem &result, const ElementType &a) const
aring-style adapter for arbitrary-precision complex numbers, stored as (MPFR, MPFR) pairs.
void to_expvector(const_monomial m, exponents_t result_exp) const
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
virtual const Monoid * getMonoid() const
virtual const Ring * getCoefficients() const
virtual void degree_of_var(int n, const ring_elem a, int &lo, int &hi) const =0
Abstract base for the engine's polynomial-ring hierarchy.
virtual bool is_ZZ() const
virtual M2::RingID ringID() const
virtual unsigned long get_precision() const
virtual const PolynomialRing * cast_to_PolynomialRing() const
virtual bool from_complex_double(double re, double im, ring_elem &result) const
static RingElement * make_raw(const Ring *R, ring_elem f)
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
Engine-boundary C API for polynomial GCD, factorisation, and root finding.
@ ring_old
refers to all rings which are not ConcreteRing's.
const Ring * IM2_Ring_CCC(unsigned long prec)
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define getmemarraytype(S, len)
engine_RawRingElementArray engine_RawRingElementArrayOrNull
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
PolynomialRing — abstract polynomial-ring base, the engine's most-reused class.
engine_RawRingElementArrayOrNull rawRoots(const RingElement *p, long prec, int unique)
RingElement — tagged (Ring*, ring_elem) pair, the engine's universal element type.
Engine-boundary C API for the legacy Ring hierarchy — coefficient, polynomial, and composite rings.
Ring — the legacy abstract base class for every coefficient and polynomial ring.
ring_elem — the universal value type carried by every Ring* in the engine.
Singly linked-list node carrying one term of a polynomial-ring element.