gr_special.h
#include <flint/gr_special.h>This module gives generic access to mathematical constants, elementary and special functions and combinatorial numbers. Each function is a method of the ring: it computes in the context ctx, with arguments and result in that ring, and returns a status code (gr). The same call therefore evaluates in real or complex ball arithmetic, in floating-point arithmetic, as a power series, or returns an exact value: gr_fac_ui gives exactly in , modulo in and as a ball in .
Which rings implement which functions:
- Real and complex balls (
gr_ctx_init_real_arb,gr_ctx_init_complex_acb) implement nearly all functions, through thearb,acb,arb_hypgeom,acb_hypgeom,acb_modular,acb_ellipticandacb_dirichletmodules, with rigorous error bounds (Evaluating special functions). Over the reals, a function whose value is not real returnsGR_DOMAIN(for example ) orGR_UNABLEwhen this cannot be decided. - Floating-point contexts (
arf,acf,nfloat,dfloat,decimal) implement the elementary functions and many special functions, with approximate results. - Exact real and complex numbers (
ca,qqbar) implement the elementary functions where the result is exact (qqbarfor roots of unity and algebraic values such asgr_sin_piof a rational number). - Power series rings (
gr_series) implement the functions of power series, viagr_poly(for example_gr_poly_exp_series). - , , and finite fields implement the combinatorial numbers, many through the generic implementations documented at the end, which work in any ring.
A function that is not implemented for a ring returns GR_UNABLE. The defaults of the elementary functions handle only trivial arguments (, , , ...) and reduce some functions to others ( with gr_pow, ).
Arguments that are parameters of a function precede the main argument, in the same order as in the corresponding arb and acb functions: gr_bessel_j(res, nu, z, ctx) computes . In the prototypes, x and y are the first and second argument in this order.
Mathematical constants#
int gr_catalan(gr_ptr res, gr_ctx_t ctx)int gr_khinchin(gr_ptr res, gr_ctx_t ctx)int gr_glaisher(gr_ptr res, gr_ctx_t ctx)Exponentials and logarithms#
Set res to , (accurate for small ), or .
int gr_exp_pi_i(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Sets res to . For rational this is a root of unity, computed exactly by qqbar.
Set res to the principal natural logarithm , to (accurate for small ), or to the logarithms in base 2 and 10. GR_DOMAIN for .
int gr_log_pi_i(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Sets res to , the inverse of gr_exp_pi_i on the principal branch.
int gr_lambertw(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_lambertw_fmpz(gr_ptr res, gr_srcptr x, const fmpz_t k, gr_ctx_t ctx)Trigonometric and hyperbolic functions#
int gr_sin_cos(gr_ptr res1, gr_ptr res2, gr_srcptr x, gr_ctx_t ctx)Set res to , , both at once (gr_sin_cos sets res1 to the sine and res2 to the cosine), , , or . Poles give GR_DOMAIN.
int gr_sin_cos_pi(gr_ptr res1, gr_ptr res2, gr_srcptr x, gr_ctx_t ctx)The same functions evaluated at : and so on. They are exact at integers and half-integers in ball arithmetic, and algebraic for rational , which qqbar and ca compute exactly.
int gr_sinc_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Set res to , respectively , with the value 1 at .
int gr_sinh_cosh(gr_ptr res1, gr_ptr res2, gr_srcptr x, gr_ctx_t ctx)Set res to the hyperbolic functions , (both at once for gr_sinh_cosh), , , and .
Inverse trigonometric and hyperbolic functions#
All functions use the principal branches of DLMF chapter 4.
Set res to , , , , and .
Sets res to , the argument of the point , where the first argument is and the second , as in C. Defined for real rings.
int gr_asin_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_acos_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_atan_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_acot_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_asec_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_acsc_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)The inverse functions divided by : and so on, which are rational for many algebraic .
Set res to the inverse hyperbolic functions.
Factorials and the gamma function#
int gr_fac_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)int gr_fac_vec(gr_ptr res, slong len, gr_ctx_t ctx)Set res to the factorial . The vec version writes the first len factorials to the array res.
int gr_rfac_ui(gr_ptr res, ulong x, gr_ctx_t ctx)int gr_rfac_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)int gr_rfac_vec(gr_ptr res, slong len, gr_ctx_t ctx)Set res to the reciprocal factorial , and the vec version to ; GR_DOMAIN if a factorial is not invertible in the ring.
int gr_bin_uiui(gr_ptr res, ulong x, ulong y, gr_ctx_t ctx)int gr_bin_vec(gr_ptr res, gr_srcptr x, slong len, gr_ctx_t ctx)int gr_bin_ui_vec(gr_ptr res, ulong x, slong len, gr_ctx_t ctx)Set res to the binomial coefficient . The vec versions write to res. For a two-dimensional table (Pascal's triangle), gr_mat_pascal is faster than repeated calls.
int gr_rising_ui(gr_ptr res, gr_srcptr x, ulong y, gr_ctx_t ctx)int gr_falling(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_falling_ui(gr_ptr res, gr_srcptr x, ulong y, gr_ctx_t ctx)Set res to the rising factorial and the falling factorial , or their extensions and to non-integer .
int gr_gamma_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)int gr_gamma_fmpq(gr_ptr res, const fmpq_t x, gr_ctx_t ctx)int gr_digamma(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Set res to the gamma function , its reciprocal (entire, zero at the poles of ), the log-gamma function (the principal branch continuous away from the negative real axis) or the digamma function . gr_gamma returns GR_DOMAIN at the poles . See The gamma function.
int gr_barnes_g(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_log_barnes_g(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Set res to the Barnes G-function , respectively its logarithm .
int gr_doublefac(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_doublefac_ui(gr_ptr res, ulong x, gr_ctx_t ctx)Set res to the double factorial , ending at 1 or 2.
int gr_harmonic(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_harmonic_ui(gr_ptr res, ulong x, gr_ctx_t ctx)Set res to the harmonic number , or for non-integer .
Combinatorial numbers#
The vec functions for a sequence write the len values to the array res. Exact rings receive exact values (or GR_DOMAIN if a denominator is not invertible), rings with a real precision receive numerical values.
int gr_bernoulli_ui(gr_ptr res, ulong x, gr_ctx_t ctx)int gr_bernoulli_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)int gr_bernoulli_vec(gr_ptr res, slong len, gr_ctx_t ctx)Set res to the Bernoulli number (with ). See bernoulli and Bernoulli numbers.
int gr_eulernum_ui(gr_ptr res, ulong x, gr_ctx_t ctx)int gr_eulernum_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)int gr_eulernum_vec(gr_ptr res, slong len, gr_ctx_t ctx)Set res to the Euler number (the coefficients of ).
int gr_bernpoly_ui(gr_ptr res, ulong n, gr_srcptr x, gr_ctx_t ctx)int gr_eulerpoly_ui(gr_ptr res, ulong n, gr_srcptr x, gr_ctx_t ctx)Set res to the Bernoulli polynomial or the Euler polynomial . These methods are implemented for real and complex balls (arb_bernoulli_poly_ui, acb_bernoulli_poly_ui); other rings return GR_UNABLE.
int gr_fib_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)int gr_fib_vec(gr_ptr res, slong len, gr_ctx_t ctx)Set res to the Fibonacci number , with and ; gr_fib_fmpz accepts negative , with .
int gr_stirling_s1u_uiui(gr_ptr res, ulong x, ulong y, gr_ctx_t ctx)int gr_stirling_s1_uiui(gr_ptr res, ulong x, ulong y, gr_ctx_t ctx)int gr_stirling_s2_uiui(gr_ptr res, ulong x, ulong y, gr_ctx_t ctx)Set res to the unsigned Stirling number of the first kind , the signed Stirling number of the first kind , or the Stirling number of the second kind (Stirling and Bell numbers).
int gr_stirling_s1u_ui_vec(gr_ptr res, ulong x, slong len, gr_ctx_t ctx)int gr_stirling_s1_ui_vec(gr_ptr res, ulong x, slong len, gr_ctx_t ctx)int gr_stirling_s2_ui_vec(gr_ptr res, ulong x, slong len, gr_ctx_t ctx)Write the row of the respective Stirling numbers to res. For a two-dimensional table, gr_mat_stirling is faster than repeated calls.
int gr_bellnum_ui(gr_ptr res, ulong x, gr_ctx_t ctx)int gr_bellnum_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)int gr_bellnum_vec(gr_ptr res, slong len, gr_ctx_t ctx)Set res to the Bell number , the number of partitions of a set of elements (Stirling and Bell numbers).
int gr_partitions_ui(gr_ptr res, ulong x, gr_ctx_t ctx)int gr_partitions_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)int gr_partitions_vec(gr_ptr res, slong len, gr_ctx_t ctx)Set res to the number of partitions of the integer (Computing the partition function).
Error functions and exponential integrals#
For balls, the algorithms are described in Error functions, incomplete gamma functions and exponential integrals.
Set res to the error function , the complementary error function , the scaled complementary error function , or the imaginary error function .
int gr_erfcinv(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Set res to the inverse error function and the inverse complementary error function, for real arguments in , respectively .
int gr_fresnel_s(gr_ptr res, gr_srcptr x, int normalized, gr_ctx_t ctx)int gr_fresnel_c(gr_ptr res, gr_srcptr x, int normalized, gr_ctx_t ctx)int gr_fresnel(gr_ptr res1, gr_ptr res2, gr_srcptr x, int normalized, gr_ctx_t ctx)Set res to the Fresnel integral or if normalized is nonzero, and to the unnormalised integrals and otherwise; gr_fresnel sets res1 to and res2 to .
int gr_gamma_upper(gr_ptr res, gr_srcptr x, gr_srcptr y, int regularized, gr_ctx_t ctx)int gr_gamma_lower(gr_ptr res, gr_srcptr x, gr_srcptr y, int regularized, gr_ctx_t ctx)Set res to the incomplete gamma functions with parameter and argument : if regularized is 0, the upper function and the lower function ; if 1, the regularized versions and ; if 2, and , as for acb_hypgeom_gamma_upper and acb_hypgeom_gamma_lower.
Sets res to the incomplete beta function with , , or to the regularized version if regularized is nonzero.
int gr_exp_integral(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_exp_integral_ei(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Set res to the generalised exponential integral with and , respectively the exponential integral .
int gr_sin_integral(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_cos_integral(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_sinh_integral(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_cosh_integral(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Set res to the sine integral , the cosine integral , the hyperbolic sine integral or the hyperbolic cosine integral .
int gr_log_integral(gr_ptr res, gr_srcptr x, int offset, gr_ctx_t ctx)Sets res to the logarithmic integral , or to the offset logarithmic integral if offset is nonzero.
Bessel, Airy and Coulomb functions#
For balls, the algorithms are described in Bessel, Airy and Coulomb wave functions.
int gr_bessel_j(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_bessel_y(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_bessel_i(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_bessel_k(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)Set res to the Bessel functions , , or of order and argument ; gr_bessel_j_y sets res1 to and res2 to .
int gr_bessel_i_scaled(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_bessel_k_scaled(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)Set res to the scaled Bessel functions and , which do not overflow for large .
Sets res to the first len Taylor coefficients of at , that is, for (the jet of at ). This is a generic function, not a method: it computes and and then the higher coefficients by a three-term recurrence (https://fungrim.org/entry/9b2f38/), and uses the series expansion at for integer .
int gr_airy_ai(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_airy_bi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_airy_ai_prime(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_airy_bi_prime(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Set res to the Airy functions , and their derivatives; gr_airy sets res1, res2, res3, res4 to , , , (as acb_hypgeom_airy).
int gr_airy_ai_zero(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_airy_bi_zero(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_airy_ai_prime_zero(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_airy_bi_prime_zero(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)Set res to the -th real zero , , or of , , or , counted from and ordered by decreasing value; GR_DOMAIN for .
int gr_coulomb(gr_ptr res1, gr_ptr res2, gr_ptr res3, gr_ptr res4, gr_srcptr x, gr_srcptr y, gr_srcptr z, gr_ctx_t ctx)Set res to the Coulomb wave functions , , and with , and argument ; gr_coulomb computes all four (as acb_hypgeom_coulomb).
Orthogonal polynomials#
int gr_chebyshev_t(gr_ptr res, gr_srcptr n, gr_srcptr x, gr_ctx_t ctx)int gr_chebyshev_t_fmpz(gr_ptr res, const fmpz_t n, gr_srcptr x, gr_ctx_t ctx)int gr_chebyshev_u(gr_ptr res, gr_srcptr n, gr_srcptr x, gr_ctx_t ctx)int gr_chebyshev_u_fmpz(gr_ptr res, const fmpz_t n, gr_srcptr x, gr_ctx_t ctx)Set res to the Chebyshev polynomials and , for an integer (the _fmpz versions, which work in any ring) or in the ring (as hypergeometric functions in ball arithmetic).
int gr_hermite_h(gr_ptr res, gr_srcptr n, gr_srcptr z, gr_ctx_t ctx)Set res to the Jacobi polynomial , the Gegenbauer polynomial , the associated Laguerre polynomial or the Hermite polynomial , extended to non-integer as hypergeometric functions (as the corresponding acb_hypgeom functions).
Set res to the associated Legendre functions of the first and second kind and ; type selects the branch cut convention: 0 for Ferrers' functions on and 1 for the functions on (types 2 and 3 of Mathematica), as in acb_hypgeom_legendre_p.
Sets res to the spherical harmonic for integers and .
Sets root to the root of index of the Legendre polynomial , with and the roots ordered by decreasing value, and, if weight is not NULL, weight to the corresponding weight of Gauss–Legendre quadrature (as arb_hypgeom_legendre_p_ui_root). GR_DOMAIN if .
Hypergeometric functions#
The flags argument is passed to the acb_hypgeom functions: bit 0 (flags = 1) selects the regularized function, which divides by (by for ) and is entire in the lower parameters. For the other bits are those of acb_hypgeom_2f1. See Hypergeometric functions and The Gauss hypergeometric function.
int gr_hypgeom_0f1(gr_ptr res, gr_srcptr a, gr_srcptr z, int flags, gr_ctx_t ctx)int gr_hypgeom_2f1(gr_ptr res, gr_srcptr a, gr_srcptr b, gr_srcptr c, gr_srcptr z, int flags, gr_ctx_t ctx)Set res to the hypergeometric functions , (Kummer's function ) and , or to their regularized versions.
Sets res to the confluent hypergeometric function of the second kind (Tricomi's function). flags is ignored.
int gr_hypgeom_pfq(gr_ptr res, const gr_vec_t a, const gr_vec_t b, gr_srcptr z, int flags, gr_ctx_t ctx)Sets res to the generalised hypergeometric function with the parameters given by the vectors a and b, or its regularized version.
GR_PFQ_OP(ctx, NAME)The method of gr_hypgeom_pfq, cast to its signature (gr_method_pfq_op_op).
Zeta and L-functions#
int gr_zeta_ui(gr_ptr res, ulong x, gr_ctx_t ctx)Set res to the Riemann zeta function ; GR_DOMAIN at the pole . The method of gr_zeta_ui is implemented for real and complex balls (arb_zeta_ui); other rings return GR_UNABLE, and gr_zeta with an integer argument can be used instead.
int gr_hurwitz_zeta(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)Sets res to the Hurwitz zeta function with , (Zeta functions, polylogarithms and L-functions).
int gr_polylog(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)Sets res to the polylogarithm with , .
int gr_polygamma(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)Sets res to the polygamma function with , , extended to complex as in acb_polygamma.
Sets res to the Lerch transcendent with , , .
int gr_stieltjes(gr_ptr res, const fmpz_t x, gr_srcptr y, gr_ctx_t ctx)Sets res to the generalised Stieltjes constant , the coefficients of the Laurent expansion of at .
int gr_dirichlet_eta(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_dirichlet_beta(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Set res to the Dirichlet eta function and the Dirichlet beta function . gr_dirichlet_beta is implemented for real and complex balls, as the Dirichlet L-function of the nontrivial character modulo 4 (acb_dirichlet_l).
int gr_riemann_xi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Sets res to the Riemann xi function .
int gr_zeta_zero(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_zeta_zero_vec(gr_ptr res, const fmpz_t n, slong len, gr_ctx_t ctx)int gr_zeta_nzeros(gr_ptr res, gr_srcptr t, gr_ctx_t ctx)Set res to the -th nontrivial zero of in the upper half-plane, counted from by increasing height; to the len consecutive zeros ; or to the number of zeros with imaginary part in . The ball implementations return GR_UNABLE for and for non-real or non-finite .
int gr_dirichlet_chi_fmpz(gr_ptr res, const dirichlet_group_t G, const dirichlet_char_t chi, const fmpz_t n, gr_ctx_t ctx)int gr_dirichlet_chi_vec(gr_ptr res, const dirichlet_group_t G, const dirichlet_char_t chi, slong len, gr_ctx_t ctx)int gr_dirichlet_l(gr_ptr res, const dirichlet_group_t G, const dirichlet_char_t chi, gr_srcptr s, gr_ctx_t ctx)Sets res to the Dirichlet L-function for the character chi of the group G, in complex balls, in real balls (GR_UNABLE unless the value is real), or as a power series in gr_series rings (gr_series_dirichlet_l); GR_UNABLE in other rings.
int gr_dirichlet_hardy_theta(gr_ptr res, const dirichlet_group_t G, const dirichlet_char_t chi, gr_srcptr t, gr_ctx_t ctx)int gr_dirichlet_hardy_z(gr_ptr res, const dirichlet_group_t G, const dirichlet_char_t chi, gr_srcptr t, gr_ctx_t ctx)Set res to the Hardy theta function and Hardy Z-function of the character chi, defined so that is real for real , with the same rings as gr_dirichlet_l.
Modular forms and theta functions#
Here is in the upper half-plane and , with the conventions of acb_modular.
int gr_jacobi_theta(gr_ptr res1, gr_ptr res2, gr_ptr res3, gr_ptr res4, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)int gr_jacobi_theta_1(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)int gr_jacobi_theta_2(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)int gr_jacobi_theta_3(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)int gr_jacobi_theta_4(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)Set res to the Jacobi theta functions , with the argument scaled by as in acb_modular_theta (for example ); gr_jacobi_theta computes all four.
int gr_modular_j(gr_ptr res, gr_srcptr tau, gr_ctx_t ctx)int gr_modular_lambda(gr_ptr res, gr_srcptr tau, gr_ctx_t ctx)int gr_modular_delta(gr_ptr res, gr_srcptr tau, gr_ctx_t ctx)Set res to the modular -invariant , the modular lambda function or the modular discriminant .
int gr_dedekind_eta(gr_ptr res, gr_srcptr tau, gr_ctx_t ctx)int gr_dedekind_eta_q(gr_ptr res, gr_srcptr q, gr_ctx_t ctx)Set res to the Dedekind eta function . gr_dedekind_eta_q takes the nome instead and computes without the leading factor , that is, (as acb_modular_eta_sum does), which is a single-valued function of for . It returns GR_DOMAIN if , and is implemented for real and complex balls.
int gr_hilbert_class_poly(gr_ptr res, slong D, gr_srcptr x, gr_ctx_t ctx)Sets res to the value of the Hilbert class polynomial for the discriminant at x. If ctx is a gr_poly ring and x its generator, the polynomial itself is returned. GR_DOMAIN if is not a negative discriminant. The default computes with acb_modular_hilbert_class_poly and evaluates it, so it works in any ring.
int gr_eisenstein_e(gr_ptr res, ulong n, gr_srcptr tau, gr_ctx_t ctx)int gr_eisenstein_g(gr_ptr res, ulong n, gr_srcptr tau, gr_ctx_t ctx)int gr_eisenstein_g_vec(gr_ptr res, gr_srcptr tau, slong len, gr_ctx_t ctx)Set res to the Eisenstein series or its normalisation , for even (GR_DOMAIN for odd or ); gr_eisenstein_g_vec writes .
Elliptic integrals and functions#
The conventions are those of acb_elliptic: the parameter , and the lattice for the elliptic functions.
Set res to the arithmetic-geometric mean , respectively .
int gr_elliptic_k(gr_ptr res, gr_srcptr m, gr_ctx_t ctx)int gr_elliptic_e(gr_ptr res, gr_srcptr m, gr_ctx_t ctx)int gr_elliptic_pi(gr_ptr res, gr_srcptr n, gr_srcptr m, gr_ctx_t ctx)Set res to the complete elliptic integrals of the first, second and third kind , and .
int gr_elliptic_f(gr_ptr res, gr_srcptr phi, gr_srcptr m, int pi, gr_ctx_t ctx)int gr_elliptic_e_inc(gr_ptr res, gr_srcptr phi, gr_srcptr m, int pi, gr_ctx_t ctx)Set res to the incomplete elliptic integrals , and ; if pi is nonzero, the amplitude is instead of .
int gr_carlson_rc(gr_ptr res, gr_srcptr x, gr_srcptr y, int flags, gr_ctx_t ctx)int gr_carlson_rj(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_srcptr z, gr_srcptr w, int flags, gr_ctx_t ctx)Set res to the Carlson symmetric elliptic integrals , , , and . flags is passed to acb_elliptic_rf and acb_elliptic_rj and should be 0.
int gr_elliptic_invariants(gr_ptr res1, gr_ptr res2, gr_srcptr tau, gr_ctx_t ctx)Set res1, res2 to the lattice invariants , , respectively res1, res2, res3 to the roots , , of , of the lattice .
int gr_weierstrass_p(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)int gr_weierstrass_p_prime(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)int gr_weierstrass_p_inv(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)int gr_weierstrass_zeta(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)int gr_weierstrass_sigma(gr_ptr res, gr_srcptr z, gr_srcptr tau, gr_ctx_t ctx)Set res to the Weierstrass elliptic function , its derivative , its inverse (an elliptic integral), the Weierstrass zeta function or the Weierstrass sigma function for the lattice .
Generic implementations#
These are the defaults installed in every method table (gr_generic). They work in any ring, using the arithmetic of the ring and, where useful, exact computation in or followed by conversion, or computation with balls followed by conversion in rings with a real precision.
int gr_generic_exp(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_log(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_sin(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_cos(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_sin_cos(gr_ptr res1, gr_ptr res2, gr_srcptr x, gr_ctx_t ctx)int gr_generic_tan(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_tanh(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_asin(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_asinh(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_atan(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_atanh(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Handle the trivial argument (, or for the logarithm) exactly and return GR_UNABLE otherwise.
int gr_generic_expm1(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_exp2(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_exp10(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_log1p(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_log2(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_log10(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_sec_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_csc_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Compute and .
int gr_generic_asin_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_acos_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_atan_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_acot_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_asec_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_acsc_pi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Compute the inverse function and divide by .
int gr_generic_acot(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_asec(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_acsc(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_acoth(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_asech(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_acsch(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)Compute , , and the hyperbolic analogues; the inversion fails for even where the function has a finite value.
int gr_generic_fac(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_fac_ui(gr_ptr res, ulong n, gr_ctx_t ctx)int gr_generic_fac_fmpz(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_generic_fac_vec(gr_ptr res, slong len, gr_ctx_t ctx)Factorials: fmpz_fac_ui in ; a table for small ; in rings of finite characteristic, products of several consecutive integers per multiplication, and n_factorial_fast_mod2_preinv for nmod; numerically with arb_fac_ui in rings with a real precision; otherwise exactly in and converted. gr_generic_fac uses gr_fac_ui for integer arguments and otherwise.
int gr_generic_rfac(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_rfac_ui(gr_ptr res, ulong n, gr_ctx_t ctx)int gr_generic_rfac_fmpz(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_generic_rfac_vec(gr_ptr res, slong len, gr_ctx_t ctx)Reciprocal factorials, computed as inverses of factorials.
int gr_generic_rising(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_generic_rising_ui(gr_ptr res, gr_srcptr x, ulong y, gr_ctx_t ctx)int gr_generic_falling(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_generic_falling_ui(gr_ptr res, gr_srcptr x, ulong y, gr_ctx_t ctx)Rising factorials by binary splitting of the product , with a basecase of 16 factors; falling factorials as rising factorials of . Non-integer gives GR_UNABLE.
int gr_generic_bin(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)int gr_generic_bin_ui(gr_ptr res, gr_srcptr x, ulong y, gr_ctx_t ctx)int gr_generic_bin_uiui(gr_ptr res, ulong x, ulong y, gr_ctx_t ctx)int gr_generic_bin_vec(gr_ptr res, gr_srcptr x, slong len, gr_ctx_t ctx)int gr_generic_bin_ui_vec(gr_ptr res, ulong x, slong len, gr_ctx_t ctx)Binomial coefficients: gr_generic_bin_uiui uses fmpz_bin_uiui in , and in other rings computes the integer exactly and converts it when or the ring is exact of characteristic zero, and otherwise divides a falling factorial by a factorial in the ring (falling back to the exact integer if the division fails). gr_generic_bin_ui divides the falling factorial by ; gr_generic_bin requires an integer . The vec versions use recurrences between consecutive coefficients, taking care in rings of finite characteristic where divisions may not be possible.
int gr_generic_doublefac(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_doublefac_ui(gr_ptr res, ulong n, gr_ctx_t ctx)Double factorials: and ; for non-integer the extension .
int gr_generic_harmonic(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_harmonic_ui(gr_ptr res, ulong n, gr_ctx_t ctx)Harmonic numbers: exactly with fmpq_harmonic_ui and converted, or numerically in rings with a real precision.
int gr_generic_beta(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_ctx_t ctx)Computes .
int gr_generic_fib2_fmpz(gr_ptr v, gr_ptr u, const fmpz_t n, gr_ctx_t ctx)int gr_generic_fib_fmpz(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_generic_fib_ui(gr_ptr res, ulong n, gr_ctx_t ctx)int gr_generic_fib_vec(gr_ptr res, slong len, gr_ctx_t ctx)Fibonacci numbers by a table for small and otherwise the doubling formulas , along the binary expansion of . gr_generic_fib2_fmpz sets v to and u to . The vec version uses the recurrence.
int gr_generic_bellnum_fmpz(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_generic_bellnum_ui(gr_ptr res, ulong n, gr_ctx_t ctx)int gr_generic_bellnum_vec(gr_ptr res, slong len, gr_ctx_t ctx)Bell numbers: exactly in with the functions of arith, numerically in rings with a real precision, directly modulo for nmod (arith_bell_number_nmod and arith_bell_number_nmod_vec), and otherwise exactly in and converted.
int gr_generic_partitions_fmpz(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)int gr_generic_partitions_ui(gr_ptr res, ulong n, gr_ctx_t ctx)int gr_generic_partitions_vec(gr_ptr res, slong len, gr_ctx_t ctx)Partition numbers: partitions_fmpz_ui (the Hardy–Ramanujan–Rademacher formula [Joh2012]) in , numerically in rings with a real precision, and otherwise exactly and converted. The vec version uses arith_number_of_partitions_vec in and arith_number_of_partitions_nmod_vec for nmod (power series inversion of ), numerical values in rings with a real precision, and otherwise exact values converted.
int gr_generic_chebyshev_t_fmpz(gr_ptr y, const fmpz_t n, gr_srcptr x, gr_ctx_t ctx)int gr_generic_chebyshev_u_fmpz(gr_ptr y, const fmpz_t n, gr_srcptr x, gr_ctx_t ctx)Chebyshev polynomials and for by the doubling formulas and (and analogues for ) along the binary expansion of , using multiplications. The 2 versions set a to and b to (respectively ). Negative gives GR_UNABLE.
int gr_generic_erfcx(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)int gr_generic_hilbert_class_poly(gr_ptr res, slong D, gr_srcptr x, gr_ctx_t ctx)Computes with acb_modular_hilbert_class_poly and evaluates it at x (or returns it in a polynomial ring); GR_DOMAIN if is not a negative discriminant.
References#
- [Joh2017b] F. Johansson, "Computing the Lambert W function in arbitrary-precision complex interval arithmetic", preprint (2017), https://arxiv.org/abs/1705.03266
- [Joh2012] F. Johansson, "Efficient implementation of the Hardy-Ramanujan-Rademacher formula", LMS Journal of Computation and Mathematics, Volume 15 (2012), 341-359, http://journals.cambridge.org/action/displayAbstract?fromPage=online&aid=8710297
The FLINT team, “gr_special.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/gr_special/index.html (generated 2026-11-02).
@misc{flint-doc-gr-special-index,
author = {{The FLINT team}},
title = {{gr\_special.h (module overview)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/gr_special/index.html},
note = {Generated 2026-11-02}
}