FLINT3.7.0-dev

gr_generic_set_str_expr, gr_generic_set_str, gr_generic_set_str_balance_additions, gr_generic_set_str_ring_exponents

Synopsis#include <flint/gr_generic.h>
int gr_generic_set_str_expr(gr_ptr res, const char * s, int flags, gr_ctx_t ctx)source
int gr_generic_set_str(gr_ptr res, const char * s, gr_ctx_t ctx)source
int gr_generic_set_str_balance_additions(gr_ptr res, const char * s, gr_ctx_t ctx)source
int gr_generic_set_str_ring_exponents(gr_ptr res, const char * s, gr_ctx_t ctx)source

Parse the expression s and evaluate it in the ring. gr_generic_set_str is gr_generic_set_str_expr with no flags and the default of gr_set_str; the other two set one flag each.

The grammar has integer literals, decimal literals with an optional exponent (1.25e-3, evaluated with gr_set_fmpz_10exp_fmpz), the binary operators +, -, *, / and ^, unary minus, parentheses, and:

  • the generators of the ring and of its base rings, by the names given by gr_gens_recursive and gr_ctx_gen_name;
  • the constants pi, i, inf and nan (also Pi, I, Inf, NaN), when the ring has them;
  • the functions abs, sgn, arg, inv, sqrt, rsqrt, floor, ceil, nint, re, im, conj, fac, log, exp, sin, cos, tan, asin, acos, atan, sinpi, cospi, tanpi, gamma and zeta of one argument;
  • the ball notation m +/- r, evaluated with gr_set_interval_mid_rad, and m +/- inf with gr_set_interval_mid_inf, which does not require inf to be an element;
  • O(x^n), evaluated with gr_big_o_base_fmpz without forming x^n.

Exponents are nonnegative integer literals unless GR_PARSE_RING_EXPONENTS is set. The status of every operation is propagated, so "1/2" in \mathbb{Z} returns GR_DOMAIN; a syntax error returns GR_UNABLE.

Cite this page

The FLINT team, “gr_generic_set_str_expr, gr_generic_set_str, gr_generic_set_str_balance_additions, gr_generic_set_str_ring_exponents (gr_generic.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/gr_generic/gr_generic_set_str_expr.html (generated 2026-10-20).