FLINT3.7.0-dev
Module · 293 functions

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 Γ(x)\Gamma(x) in real or complex ball arithmetic, in floating-point arithmetic, as a power series, or returns an exact value: gr_fac_ui gives 10!10! exactly in Z\mathbb{Z}, modulo nn in Z/nZ\mathbb{Z}/n\mathbb{Z} and as a ball in R\mathbb{R}.

Which rings implement which functions:

  • Real and complex balls (gr_ctx_init_real_arb, gr_ctx_init_complex_acb) implement nearly all functions, through the arb, acb, arb_hypgeom, acb_hypgeom, acb_modular, acb_elliptic and acb_dirichlet modules, with rigorous error bounds (Evaluating special functions). Over the reals, a function whose value is not real returns GR_DOMAIN (for example log⁡(−1)\log(-1)) or GR_UNABLE when 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 (qqbar for roots of unity and algebraic values such as gr_sin_pi of a rational number).
  • Power series rings (gr_series) implement the functions of power series, via gr_poly (for example _gr_poly_exp_series).
  • Z\mathbb{Z}, Q\mathbb{Q}, Z/nZ\mathbb{Z}/n\mathbb{Z} 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 (exp⁡(0)=1\exp(0) = 1, log⁡(1)=0\log(1) = 0, sin⁡(0)=0\sin(0) = 0, ...) and reduce some functions to others (exp⁡2(x)=2x\exp_2(x) = 2^x with gr_pow, acot⁡(x)=atan⁡(1/x)\operatorname{acot}(x) = \operatorname{atan}(1/x)).

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 Jν(z)J_\nu(z). In the prototypes, x and y are the first and second argument in this order.

Mathematical constants#

int gr_pi(gr_ptr res, gr_ctx_t ctx)
int gr_euler(gr_ptr res, gr_ctx_t ctx)
int gr_catalan(gr_ptr res, gr_ctx_t ctx)

Set res to π\pi, Euler's constant γ\gamma, Catalan's constant GG, Khinchin's constant KK or Glaisher's constant AA. Rings that do not contain the constant return GR_DOMAIN (gr_pi in Q\mathbb{Q}) or GR_UNABLE.

Exponentials and logarithms#

int gr_exp(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_exp2(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)

Set res to exe^x, ex−1e^x - 1 (accurate for small xx), 2x2^x or 10x10^x.

Sets res to eπixe^{\pi i x}. For rational xx this is a root of unity, computed exactly by qqbar.

int gr_log(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_log2(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)

Set res to the principal natural logarithm log⁡x\log x, to log⁡(1+x)\log(1 + x) (accurate for small xx), or to the logarithms in base 2 and 10. GR_DOMAIN for x=0x = 0.

Sets res to log⁡(x)/(πi)\log(x) / (\pi i), the inverse of gr_exp_pi_i on the principal branch.

int gr_lambertw_fmpz(gr_ptr res, gr_srcptr x, const fmpz_t k, gr_ctx_t ctx)

Set res to the principal branch W0(x)W_0(x) of the Lambert W function, or to the branch Wk(x)W_k(x) with index kk given by the fmpz_t argument [Joh2017b].

Trigonometric and hyperbolic functions#

int gr_sin(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_cos(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_sin_cos(gr_ptr res1, gr_ptr res2, gr_srcptr x, gr_ctx_t ctx)
int gr_tan(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_cot(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_sec(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_csc(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)

Set res to sin⁡x\sin x, cos⁡x\cos x, both at once (gr_sin_cos sets res1 to the sine and res2 to the cosine), tan⁡x\tan x, cot⁡x\cot x, sec⁡x=1/cos⁡x\sec x = 1/\cos x or csc⁡x=1/sin⁡x\csc x = 1/\sin x. 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 πx\pi x: sin⁡(πx)\sin(\pi x) and so on. They are exact at integers and half-integers in ball arithmetic, and algebraic for rational xx, which qqbar and ca compute exactly.

int gr_sinc(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)

Set res to sinc⁡(x)=sin⁡(x)/x\operatorname{sinc}(x) = \sin(x)/x, respectively sin⁡(πx)/(πx)\sin(\pi x)/(\pi x), with the value 1 at x=0x = 0.

int gr_sinh(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_cosh(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_sinh_cosh(gr_ptr res1, gr_ptr res2, gr_srcptr x, gr_ctx_t ctx)
int gr_tanh(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_coth(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_sech(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_csch(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)

Set res to the hyperbolic functions sinh⁡x\sinh x, cosh⁡x\cosh x (both at once for gr_sinh_cosh), tanh⁡x\tanh x, coth⁡x\coth x, sech⁡x\operatorname{sech} x and csch⁡x\operatorname{csch} x.

Inverse trigonometric and hyperbolic functions#

All functions use the principal branches of DLMF chapter 4.

int gr_asin(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_acos(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_atan(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_acot(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_asec(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_acsc(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)

Set res to asin⁡x\operatorname{asin} x, acos⁡x\operatorname{acos} x, atan⁡x\operatorname{atan} x, acot⁡x=atan⁡(1/x)\operatorname{acot} x = \operatorname{atan}(1/x), asec⁡x=acos⁡(1/x)\operatorname{asec} x = \operatorname{acos}(1/x) and acsc⁡x=asin⁡(1/x)\operatorname{acsc} x = \operatorname{asin}(1/x).

Sets res to atan2⁡(y,x)\operatorname{atan2}(y, x), the argument of the point (x,y)(x, y), where the first argument is yy and the second xx, as in C. Defined for real rings.

The inverse functions divided by π\pi: asin⁡(x)/π\operatorname{asin}(x)/\pi and so on, which are rational for many algebraic xx.

Set res to the inverse hyperbolic functions.

Factorials and the gamma function#

int gr_fac(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_fac_ui(gr_ptr res, ulong x, gr_ctx_t ctx)
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 x!=Γ(x+1)x! = \Gamma(x + 1). The vec version writes the first len factorials 0!,1!,…,(len−1)!0!, 1!, \ldots, (\mathit{len} - 1)! to the array res.

Full documentation
int gr_rfac(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
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 1/x!=1/Γ(x+1)1/x! = 1/\Gamma(x+1), and the vec version to 1/0!,…,1/(len−1)!1/0!, \ldots, 1/(\mathit{len} - 1)!; 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 (xy)\binom{x}{y}. The vec versions write (x0),(x1),…,(xlen−1)\binom{x}{0}, \binom{x}{1}, \ldots, \binom{x}{\mathit{len}-1} to res. For a two-dimensional table (Pascal's triangle), gr_mat_pascal is faster than repeated calls.

Set res to the rising factorial x(x+1)⋯(x+y−1)x (x+1) \cdots (x+y-1) and the falling factorial x(x−1)⋯(x−y+1)x (x-1) \cdots (x-y+1), or their extensions Γ(x+y)/Γ(x)\Gamma(x+y)/\Gamma(x) and Γ(x+1)/Γ(x−y+1)\Gamma(x+1)/\Gamma(x-y+1) to non-integer yy.

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)

Set res to the gamma function Γ(x)\Gamma(x), its reciprocal 1/Γ(x)1/\Gamma(x) (entire, zero at the poles of Γ\Gamma), the log-gamma function log⁡Γ(x)\log \Gamma(x) (the principal branch continuous away from the negative real axis) or the digamma function ψ(x)=Γ′(x)/Γ(x)\psi(x) = \Gamma'(x)/\Gamma(x). gr_gamma returns GR_DOMAIN at the poles 0,−1,−2,…0, -1, -2, \ldots. See The gamma function.

Full documentation

Sets res to the beta function B(x,y)=Γ(x)Γ(y)/Γ(x+y)B(x, y) = \Gamma(x) \Gamma(y) / \Gamma(x + y).

Set res to the Barnes G-function G(x)G(x), respectively its logarithm log⁡G(x)\log G(x).

Set res to the double factorial x!!=x(x−2)(x−4)⋯x!! = x (x - 2) (x - 4) \cdots, ending at 1 or 2.

Set res to the harmonic number Hx=∑k=1x1/kH_x = \sum_{k=1}^{x} 1/k, or ψ(x+1)+γ\psi(x+1) + \gamma for non-integer xx.

Combinatorial numbers#

The vec functions for a sequence cnc_n write the len values c0,c1,…,clen−1c_0, c_1, \ldots, c_{\mathit{len}-1} 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_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)

Set res to the Bernoulli number BnB_n (with B1=−1/2B_1 = -1/2). See bernoulli and Bernoulli numbers.

int gr_eulernum_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)

Set res to the Euler number EnE_n (the coefficients of sech⁡(t)=∑Entn/n!\operatorname{sech}(t) = \sum E_n t^n / n!).

Set res to the Bernoulli polynomial Bn(x)B_n(x) or the Euler polynomial En(x)E_n(x). These methods are implemented for real and complex balls (arb_bernoulli_poly_ui, acb_bernoulli_poly_ui); other rings return GR_UNABLE.

More
int gr_fib_ui(gr_ptr res, ulong x, gr_ctx_t ctx)
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 FnF_n, with F0=0F_0 = 0 and F1=1F_1 = 1; gr_fib_fmpz accepts negative nn, with F−n=(−1)n+1FnF_{-n} = (-1)^{n+1} F_n.

Set res to the unsigned Stirling number of the first kind [xy]\left[{x \atop y}\right], the signed Stirling number of the first kind s(x,y)s(x, y), or the Stirling number of the second kind {xy}\left\{{x \atop y}\right\} (Stirling and Bell numbers).

Write the row S(x,0),S(x,1),…,S(x,len−1)S(x, 0), S(x, 1), \ldots, S(x, \mathit{len} - 1) of the respective Stirling numbers to res. For a two-dimensional table, gr_mat_stirling is faster than repeated calls.

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 BnB_n, the number of partitions of a set of nn elements (Stirling and Bell numbers).

int gr_partitions_fmpz(gr_ptr res, const fmpz_t x, gr_ctx_t ctx)

Set res to the number of partitions p(n)p(n) of the integer nn (Computing the partition function).

Error functions and exponential integrals#

For balls, the algorithms are described in Error functions, incomplete gamma functions and exponential integrals.

int gr_erf(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_erfc(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_erfi(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)

Set res to the error function erf⁡(x)\operatorname{erf}(x), the complementary error function erfc⁡(x)=1−erf⁡(x)\operatorname{erfc}(x) = 1 - \operatorname{erf}(x), the scaled complementary error function erfcx⁡(x)=ex2erfc⁡(x)\operatorname{erfcx}(x) = e^{x^2} \operatorname{erfc}(x), or the imaginary error function erfi⁡(x)=−ierf⁡(ix)\operatorname{erfi}(x) = -i \operatorname{erf}(ix).

Set res to the inverse error function and the inverse complementary error function, for real arguments in (−1,1)(-1, 1), respectively (0,2)(0, 2).

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 S(x)=∫0xsin⁡(πt2/2) dtS(x) = \int_0^x \sin(\pi t^2 / 2) \, dt or C(x)=∫0xcos⁡(πt2/2) dtC(x) = \int_0^x \cos(\pi t^2 / 2) \, dt if normalized is nonzero, and to the unnormalised integrals ∫0xsin⁡(t2) dt\int_0^x \sin(t^2) \, dt and ∫0xcos⁡(t2) dt\int_0^x \cos(t^2) \, dt otherwise; gr_fresnel sets res1 to SS and res2 to CC.

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 s=xs = x and argument z=yz = y: if regularized is 0, the upper function Γ(s,z)=∫z∞ts−1e−t dt\Gamma(s, z) = \int_z^\infty t^{s-1} e^{-t} \, dt and the lower function γ(s,z)=∫0zts−1e−t dt\gamma(s, z) = \int_0^z t^{s-1} e^{-t} \, dt; if 1, the regularized versions Q(s,z)=Γ(s,z)/Γ(s)Q(s, z) = \Gamma(s,z)/\Gamma(s) and P(s,z)=γ(s,z)/Γ(s)P(s,z) = \gamma(s,z)/\Gamma(s); if 2, z−sΓ(s,z)z^{-s} \Gamma(s, z) and γ∗(s,z)=z−sP(s,z)\gamma^*(s, z) = z^{-s} P(s, z), as for acb_hypgeom_gamma_upper and acb_hypgeom_gamma_lower.

int gr_beta_lower(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_srcptr z, int regularized, gr_ctx_t ctx)

Sets res to the incomplete beta function B(a,b;z)=∫0zta−1(1−t)b−1 dtB(a, b; z) = \int_0^z t^{a-1} (1-t)^{b-1} \, dt with a=xa = x, b=yb = y, or to the regularized version I(a,b;z)=B(a,b;z)/B(a,b)I(a, b; z) = B(a, b; z)/B(a, b) if regularized is nonzero.

Set res to the generalised exponential integral Es(z)=∫1∞e−ztt−s dtE_s(z) = \int_1^\infty e^{-zt} t^{-s} \, dt with s=xs = x and z=yz = y, respectively the exponential integral Ei⁡(x)\operatorname{Ei}(x).

Set res to the sine integral Si⁡(x)\operatorname{Si}(x), the cosine integral Ci⁡(x)\operatorname{Ci}(x), the hyperbolic sine integral Shi⁡(x)\operatorname{Shi}(x) or the hyperbolic cosine integral Chi⁡(x)\operatorname{Chi}(x).

int gr_log_integral(gr_ptr res, gr_srcptr x, int offset, gr_ctx_t ctx)

Sets res to the logarithmic integral li⁡(x)=∫0xdt/log⁡t\operatorname{li}(x) = \int_0^x dt / \log t, or to the offset logarithmic integral Li⁡(x)=li⁡(x)−li⁡(2)\operatorname{Li}(x) = \operatorname{li}(x) - \operatorname{li}(2) if offset is nonzero.

Sets res to the dilogarithm Li⁡2(x)\operatorname{Li}_2(x).

Bessel, Airy and Coulomb functions#

For balls, the algorithms are described in Bessel, Airy and Coulomb wave functions.

Set res to the Bessel functions Jν(z)J_\nu(z), Yν(z)Y_\nu(z), Iν(z)I_\nu(z) or Kν(z)K_\nu(z) of order ν=x\nu = x and argument z=yz = y; gr_bessel_j_y sets res1 to Jν(z)J_\nu(z) and res2 to Yν(z)Y_\nu(z).

Set res to the scaled Bessel functions e−zIν(z)e^{-z} I_\nu(z) and ezKν(z)e^{z} K_\nu(z), which do not overflow for large zz.

Sets res to the first len Taylor coefficients of Jν(z+t)J_\nu(z + t) at t=0t = 0, that is, Jν(k)(z)/k!J_\nu^{(k)}(z) / k! for 0≤k<len0 \le k < \mathit{len} (the jet of JνJ_\nu at zz). This is a generic function, not a method: it computes Jν(z)J_\nu(z) and Jν+1(z)J_{\nu+1}(z) and then the higher coefficients by a three-term recurrence (https://fungrim.org/entry/9b2f38/), and uses the series expansion at z=0z = 0 for integer ν\nu.

int gr_airy(gr_ptr res1, gr_ptr res2, gr_ptr res3, gr_ptr res4, gr_srcptr x, gr_ctx_t ctx)

Set res to the Airy functions Ai⁡(x)\operatorname{Ai}(x), Bi⁡(x)\operatorname{Bi}(x) and their derivatives; gr_airy sets res1, res2, res3, res4 to Ai⁡(x)\operatorname{Ai}(x), Ai⁡′(x)\operatorname{Ai}'(x), Bi⁡(x)\operatorname{Bi}(x), Bi⁡′(x)\operatorname{Bi}'(x) (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)

Set res to the nn-th real zero ana_n, bnb_n, an′a_n' or bn′b_n' of Ai⁡\operatorname{Ai}, Bi⁡\operatorname{Bi}, Ai⁡′\operatorname{Ai}' or Bi⁡′\operatorname{Bi}', counted from n=1n = 1 and ordered by decreasing value; GR_DOMAIN for n<1n < 1.

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 Fℓ(η,z)F_\ell(\eta, z), Gℓ(η,z)G_\ell(\eta, z), Hℓ+(η,z)H^{+}_\ell(\eta, z) and Hℓ−(η,z)H^{-}_\ell(\eta, z) with ℓ=x\ell = x, η=y\eta = y and argument zz; gr_coulomb computes all four (as acb_hypgeom_coulomb).

Orthogonal polynomials#

Set res to the Chebyshev polynomials Tn(x)T_n(x) and Un(x)U_n(x), for an integer nn (the _fmpz versions, which work in any ring) or nn in the ring (as hypergeometric functions in ball arithmetic).

Set res to the Jacobi polynomial Pn(a,b)(z)P_n^{(a,b)}(z), the Gegenbauer polynomial Cn(m)(z)C_n^{(m)}(z), the associated Laguerre polynomial Ln(m)(z)L_n^{(m)}(z) or the Hermite polynomial Hn(z)H_n(z), extended to non-integer nn as hypergeometric functions (as the corresponding acb_hypgeom functions).

int gr_legendre_p(gr_ptr res, gr_srcptr n, gr_srcptr m, gr_srcptr z, int type, gr_ctx_t ctx)
int gr_legendre_q(gr_ptr res, gr_srcptr n, gr_srcptr m, gr_srcptr z, int type, gr_ctx_t ctx)

Set res to the associated Legendre functions of the first and second kind Pnm(z)P_n^m(z) and Qnm(z)Q_n^m(z); type selects the branch cut convention: 0 for Ferrers' functions on (−1,1)(-1, 1) and 1 for the functions on C∖(−∞,1]\mathbb{C} \setminus (-\infty, 1] (types 2 and 3 of Mathematica), as in acb_hypgeom_legendre_p.

Sets res to the spherical harmonic Ynm(θ,ϕ)Y_n^m(\theta, \phi) for integers nn and mm.

int gr_legendre_p_root_ui(gr_ptr root, gr_ptr weight, ulong n, ulong k, gr_ctx_t ctx)

Sets root to the root of index kk of the Legendre polynomial Pn(x)P_n(x), with 0≤k<n0 \le k < n 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 k≥nk \ge n.

Hypergeometric functions#

The flags argument is passed to the acb_hypgeom functions: bit 0 (flags = 1) selects the regularized function, which divides by Γ(b)\Gamma(b) (by ∏Γ(bi)\prod \Gamma(b_i) for pFq{}_pF_q) and is entire in the lower parameters. For 2F1{}_2F_1 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_1f1(gr_ptr res, gr_srcptr a, gr_srcptr b, 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 0F1(a;z){}_0F_1(a; z), 1F1(a;b;z){}_1F_1(a; b; z) (Kummer's function M(a,b,z)M(a, b, z)) and 2F1(a,b;c;z){}_2F_1(a, b; c; z), or to their regularized versions.

int gr_hypgeom_u(gr_ptr res, gr_srcptr a, gr_srcptr b, gr_srcptr z, int flags, gr_ctx_t ctx)

Sets res to the confluent hypergeometric function of the second kind U(a,b,z)U(a, b, z) (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 pFq(a1,…,ap;b1,…,bq;z){}_pF_q(a_1, \ldots, a_p; b_1, \ldots, b_q; z) 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(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)
int gr_zeta_ui(gr_ptr res, ulong x, gr_ctx_t ctx)

Set res to the Riemann zeta function ζ(s)\zeta(s); GR_DOMAIN at the pole s=1s = 1. 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.

Sets res to the Hurwitz zeta function ζ(s,a)=∑k≥0(k+a)−s\zeta(s, a) = \sum_{k \ge 0} (k + a)^{-s} with s=xs = x, a=ya = y (Zeta functions, polylogarithms and L-functions).

Sets res to the polylogarithm Li⁡s(z)\operatorname{Li}_s(z) with s=xs = x, z=yz = y.

Sets res to the polygamma function ψ(s)(z)\psi^{(s)}(z) with s=xs = x, z=yz = y, extended to complex ss as in acb_polygamma.

Sets res to the Lerch transcendent Φ(z,s,a)=∑k≥0zk(k+a)−s\Phi(z, s, a) = \sum_{k \ge 0} z^k (k + a)^{-s} with z=xz = x, s=ys = y, a=za = z.

int gr_stieltjes(gr_ptr res, const fmpz_t x, gr_srcptr y, gr_ctx_t ctx)

Sets res to the generalised Stieltjes constant γn(a)\gamma_n(a), the coefficients of the Laurent expansion of ζ(s,a)\zeta(s, a) at s=1s = 1.

Set res to the Dirichlet eta function η(s)=(1−21−s)ζ(s)\eta(s) = (1 - 2^{1-s}) \zeta(s) and the Dirichlet beta function β(s)=∑k≥0(−1)k(2k+1)−s\beta(s) = \sum_{k \ge 0} (-1)^k (2k+1)^{-s}. gr_dirichlet_beta is implemented for real and complex balls, as the Dirichlet L-function of the nontrivial character modulo 4 (acb_dirichlet_l).

Sets res to the Riemann xi function ξ(s)=12s(s−1)π−s/2Γ(s/2)ζ(s)\xi(s) = \tfrac{1}{2} s (s-1) \pi^{-s/2} \Gamma(s/2) \zeta(s).

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)

Set res to the nn-th nontrivial zero ρn=1/2+itn\rho_n = 1/2 + i t_n of ζ(s)\zeta(s) in the upper half-plane, counted from n=1n = 1 by increasing height; to the len consecutive zeros ρn,ρn+1,…\rho_n, \rho_{n+1}, \ldots; or to the number N(t)N(t) of zeros with imaginary part in (0,t](0, t]. The ball implementations return GR_UNABLE for n<1n < 1 and for non-real or non-finite tt.

Set res to the value χ(n)\chi(n) of the Dirichlet character chi of the group G, respectively the values χ(0),…,χ(len−1)\chi(0), \ldots, \chi(\mathit{len}-1), as complex numbers. These are not methods: they are implemented for complex balls (acb) only and return GR_UNABLE otherwise. Declared only if dirichlet.h is included first.

Sets res to the Dirichlet L-function L(s,χ)L(s, \chi) 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.

Set res to the Hardy theta function θ(t)\theta(t) and Hardy Z-function Z(t)Z(t) of the character chi, defined so that Z(t)=eiθ(t)L(1/2+it,χ)Z(t) = e^{i \theta(t)} L(1/2 + it, \chi) is real for real tt, with the same rings as gr_dirichlet_l.

Modular forms and theta functions#

Here τ\tau is in the upper half-plane and q=eπiτq = e^{\pi i \tau}, 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)

Set res to the Jacobi theta functions θj(z,τ)\theta_j(z, \tau), with the argument scaled by π\pi as in acb_modular_theta (for example θ3(z,τ)=∑n∈Zqn2e2πinz\theta_3(z, \tau) = \sum_{n \in \mathbb{Z}} q^{n^2} e^{2\pi i n z}); gr_jacobi_theta computes all four.

Set res to the modular jj-invariant j(τ)j(\tau), the modular lambda function λ(τ)\lambda(\tau) or the modular discriminant Δ(τ)\Delta(\tau).

Set res to the Dedekind eta function η(τ)\eta(\tau). gr_dedekind_eta_q takes the nome q=e2πiτq = e^{2 \pi i \tau} instead and computes η\eta without the leading factor q1/24q^{1/24}, that is, q−1/24η(τ)=∏k≥1(1−qk)q^{-1/24} \eta(\tau) = \prod_{k \ge 1} (1 - q^k) (as acb_modular_eta_sum does), which is a single-valued function of qq for ∣q∣<1|q| < 1. It returns GR_DOMAIN if ∣q∣≥1|q| \ge 1, and is implemented for real and complex balls.

More

Sets res to the value HD(x)H_D(x) of the Hilbert class polynomial for the discriminant DD at x. If ctx is a gr_poly ring and x its generator, the polynomial itself is returned. GR_DOMAIN if DD is not a negative discriminant. The default computes HDH_D with acb_modular_hilbert_class_poly and evaluates it, so it works in any ring.

Set res to the Eisenstein series Gk(τ)=∑(m,n)≠(0,0)(m+nτ)−kG_k(\tau) = \sum_{(m,n) \ne (0,0)} (m + n\tau)^{-k} or its normalisation Ek(τ)=Gk(τ)/(2ζ(k))E_k(\tau) = G_k(\tau) / (2 \zeta(k)), for even k≥2k \ge 2 (GR_DOMAIN for odd kk or k=0k = 0); gr_eisenstein_g_vec writes G4,G6,…,G2len+2G_4, G_6, \ldots, G_{2\mathit{len}+2}.

Elliptic integrals and functions#

The conventions are those of acb_elliptic: the parameter m=k2m = k^2, and the lattice (1,τ)(1, \tau) for the elliptic functions.

int gr_agm1(gr_ptr res, gr_srcptr x, gr_ctx_t ctx)

Set res to the arithmetic-geometric mean M(x,y)M(x, y), respectively M(1,x)M(1, x).

Set res to the complete elliptic integrals of the first, second and third kind K(m)K(m), E(m)E(m) and Π(n,m)\Pi(n, m).

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 F(ϕ,m)F(\phi, m), E(ϕ,m)E(\phi, m) and Π(n,ϕ,m)\Pi(n, \phi, m); if pi is nonzero, the amplitude is πϕ\pi \phi instead of ϕ\phi.

int gr_carlson_rf(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_srcptr z, int flags, gr_ctx_t ctx)
int gr_carlson_rc(gr_ptr res, gr_srcptr x, gr_srcptr y, int flags, gr_ctx_t ctx)
int gr_carlson_rd(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_srcptr z, int flags, gr_ctx_t ctx)
int gr_carlson_rg(gr_ptr res, gr_srcptr x, gr_srcptr y, gr_srcptr z, 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 RF(x,y,z)R_F(x, y, z), RC(x,y)=RF(x,y,y)R_C(x, y) = R_F(x, y, y), RD(x,y,z)=RJ(x,y,z,z)R_D(x, y, z) = R_J(x, y, z, z), RG(x,y,z)R_G(x, y, z) and RJ(x,y,z,w)R_J(x, y, z, w). flags is passed to acb_elliptic_rf and acb_elliptic_rj and should be 0.

int gr_elliptic_roots(gr_ptr res1, gr_ptr res2, gr_ptr res3, gr_srcptr tau, gr_ctx_t ctx)

Set res1, res2 to the lattice invariants g2g_2, g3g_3, respectively res1, res2, res3 to the roots e1e_1, e2e_2, e3e_3 of 4t3−g2t−g34t^3 - g_2 t - g_3, of the lattice (1,τ)(1, \tau).

Set res to the Weierstrass elliptic function ℘(z,τ)\wp(z, \tau), its derivative ℘′(z,τ)\wp'(z, \tau), its inverse ℘−1(z,τ)\wp^{-1}(z, \tau) (an elliptic integral), the Weierstrass zeta function ζ(z,τ)\zeta(z, \tau) or the Weierstrass sigma function σ(z,τ)\sigma(z, \tau) for the lattice (1,τ)(1, \tau).

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 Z\mathbb{Z} or Q\mathbb{Q} followed by conversion, or computation with balls followed by conversion in rings with a real precision.

Handle the trivial argument (00, or 11 for the logarithm) exactly and return GR_UNABLE otherwise.

Reduce to other functions: ex−1e^x - 1, 2x2^x and 10x10^x with gr_pow, log⁡(1+x)\log(1+x), and log⁡(x)/log⁡(2)\log(x)/\log(2) or log⁡(x)/log⁡(10)\log(x)/\log(10) (any failure of the latter two is reported as GR_UNABLE).

Compute 1/cos⁡(πx)1/\cos(\pi x) and 1/sin⁡(πx)1/\sin(\pi x).

Compute the inverse function and divide by π\pi.

Compute atan⁡(1/x)\operatorname{atan}(1/x), acos⁡(1/x)\operatorname{acos}(1/x), asin⁡(1/x)\operatorname{asin}(1/x) and the hyperbolic analogues; the inversion fails for x=0x = 0 even where the function has a finite value.

int gr_generic_fac_fmpz(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)

Factorials: fmpz_fac_ui in Z\mathbb{Z}; a table for small nn; 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 Z\mathbb{Z} and converted. gr_generic_fac uses gr_fac_ui for integer arguments and Γ(x+1)\Gamma(x + 1) otherwise.

Reciprocal factorials, computed as inverses of factorials.

Rising factorials by binary splitting of the product x(x+1)⋯(x+n−1)x (x+1) \cdots (x+n-1), with a basecase of 16 factors; falling factorials as rising factorials of x−n+1x - n + 1. Non-integer yy gives GR_UNABLE.

Binomial coefficients: gr_generic_bin_uiui uses fmpz_bin_uiui in Z\mathbb{Z}, and in other rings computes the integer exactly and converts it when n≤100n \le 100 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 x(x−1)⋯(x−k+1)x (x-1) \cdots (x-k+1) by k!k!; gr_generic_bin requires an integer yy. The vec versions use recurrences between consecutive coefficients, taking care in rings of finite characteristic where divisions may not be possible.

Double factorials: (2k)!!=2kk!(2k)!! = 2^k k! and (2k+1)!!=(2k+1)!/(2k)!!(2k+1)!! = (2k+1)!/(2k)!!; for non-integer xx the extension 2x/2(π/2)(cos⁡(πx)−1)/4Γ(1+x/2)2^{x/2} (\pi/2)^{(\cos(\pi x) - 1)/4} \Gamma(1 + x/2).

Harmonic numbers: exactly with fmpq_harmonic_ui and converted, or numerically in rings with a real precision.

Computes B(x,y)=Γ(x)Γ(y)/Γ(x+y)B(x, y) = \Gamma(x) \Gamma(y) / \Gamma(x + y).

int gr_generic_fib_fmpz(gr_ptr res, const fmpz_t n, gr_ctx_t ctx)

Fibonacci numbers by a table for small nn and otherwise the doubling formulas F2k−1=Fk2+Fk−12F_{2k-1} = F_k^2 + F_{k-1}^2, F2k+1=4Fk2−Fk−12+2(−1)kF_{2k+1} = 4F_k^2 - F_{k-1}^2 + 2(-1)^k along the binary expansion of nn. gr_generic_fib2_fmpz sets v to FnF_n and u to Fn−1F_{n-1}. The vec version uses the recurrence.

Bell numbers: exactly in Z\mathbb{Z} with the functions of arith, numerically in rings with a real precision, directly modulo nn for nmod (arith_bell_number_nmod and arith_bell_number_nmod_vec), and otherwise exactly in Z\mathbb{Z} and converted.

Partition numbers: partitions_fmpz_ui (the Hardy–Ramanujan–Rademacher formula [Joh2012]) in Z\mathbb{Z}, numerically in rings with a real precision, and otherwise exactly and converted. The vec version uses arith_number_of_partitions_vec in Z\mathbb{Z} and arith_number_of_partitions_nmod_vec for nmod (power series inversion of ∏(1−xk)\prod (1 - x^k)), numerical values in rings with a real precision, and otherwise exact values converted.

Chebyshev polynomials Tn(x)T_n(x) and Un(x)U_n(x) for n≥0n \ge 0 by the doubling formulas T2k=2Tk2−1T_{2k} = 2T_k^2 - 1 and T2k+1=2TkTk+1−xT_{2k+1} = 2 T_k T_{k+1} - x (and analogues for UU) along the binary expansion of nn, using O(log⁡n)O(\log n) multiplications. The 2 versions set a to Tn(x)T_n(x) and b to Tn−1(x)T_{n-1}(x) (respectively UU). Negative nn gives GR_UNABLE.

Computes ex2erfc⁡(x)e^{x^2} \operatorname{erfc}(x) directly from gr_exp and gr_erfc, which is not numerically stable for large xx; failures are reported as GR_UNABLE.

Computes HDH_D with acb_modular_hilbert_class_poly and evaluates it at x (or returns it in a polynomial ring); GR_DOMAIN if DD is not a negative discriminant.

References#

Cite this page

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).