Roots of Legendre polynomials and Gauss–Legendre nodes
#include <flint/arb_hypgeom.h>Sets res to the -th root of the Legendre polynomial , with the roots in decreasing order , and, if weight is not NULL, sets weight to the corresponding weight of Gauss–Legendre quadrature on . Requires . See Roots of Legendre polynomials and Gauss–Legendre nodes.
For and a precision of at least 128 bits, the positive roots are computed by _arb_hypgeom_legendre_p_ui_root_bitburst when the precision is between and and by _arb_hypgeom_legendre_p_ui_root_taylor otherwise; for smaller or precision, or if their certification fails, by Newton iteration with evaluations of . See Gauss–Legendre nodes and weights.
int _arb_hypgeom_legendre_p_ui_root_bitburst(arb_t res, arb_t weight, ulong n, ulong k, slong prec)sourceint _arb_hypgeom_legendre_p_ui_root_taylor(arb_t res, arb_t weight, ulong n, ulong k, slong prec)sourceComputes the root of and, if weight is not NULL, its weight as arb_hypgeom_legendre_p_ui_root, for a positive root, and ( on 32-bit systems), by bit-burst Newton steps with Taylor transfers (efficient when prec is comparable to ) or by Newton–Taylor steps from a lower-precision enclosure (efficient when prec is much larger or much smaller than ). Returns 1 on success, and 0 if the arguments are out of range or a certification step failed, in which case res and weight are undefined. See Bit-burst Newton steps and Newton–Taylor steps.
arb_hypgeom_legendre_p_ui_root computes an enclosure of the -th root of the Legendre polynomial and, optionally, the weight , so that
is the -point Gauss–Legendre quadrature rule, exact for polynomials of degree less than . The roots are numbered in decreasing order, , which is the order of increasing for the roots of . Only the roots with need to be computed, since and ; the function uses this symmetry itself. An index raises an exception. The function is the one used by acb_calc_integrate to generate its quadrature rules (Rigorous numerical integration). The algorithms are described in Gauss–Legendre nodes and weights.
Example#
The 20-point rule integrates over to more than 30 digits; the error of the rule itself is about :
#include <flint/arb.h>
#include <flint/arb_hypgeom.h>
int main(void)
{
arb_t x, w, s, t, wsum;
ulong n = 20, k;
slong prec = 128;
arb_init(x);
arb_init(w);
arb_init(s);
arb_init(t);
arb_init(wsum);
for (k = 0; k < n; k++)
{
arb_hypgeom_legendre_p_ui_root(x, w, n, k, prec);
if (k == 0)
{
flint_printf("x_0 = "); arb_printn(x, 30, 0); flint_printf("\n");
flint_printf("w_0 = "); arb_printn(w, 30, 0); flint_printf("\n");
}
/* s += w_k exp(x_k) */
arb_exp(t, x, prec);
arb_addmul(s, w, t, prec);
arb_add(wsum, wsum, w, prec);
}
flint_printf("sum of weights = "); arb_printn(wsum, 30, 0); flint_printf("\n");
flint_printf("quadrature = "); arb_printn(s, 30, 0); flint_printf("\n");
/* exact value e - 1/e */
arb_const_e(t, prec);
arb_inv(x, t, prec);
arb_sub(t, t, x, prec);
flint_printf("e - 1/e = "); arb_printn(t, 30, 0); flint_printf("\n");
arb_clear(x);
arb_clear(w);
arb_clear(s);
arb_clear(t);
arb_clear(wsum);
flint_cleanup();
return 0;
}x_0 = [0.993128599185094924786122388471 +/- 3.21e-31] w_0 = [0.0176140071391521183118619623519 +/- 4.72e-32] sum of weights = [2.00000000000000000000000000000 +/- 1.08e-37] quadrature = [2.35040238728760291376476370119 +/- 1.21e-30] e - 1/e = [2.35040238728760291376476370119 +/- 1.21e-30]
The enclosure of the quadrature sum is rigorous for the sum, but it does not include the error of the quadrature rule. For an integral with a proved error bound, use acb_calc_integrate, which bounds the quadrature error using the analyticity of the integrand [Joh2018a].
References#
- [Joh2018a] F. Johansson, "Numerical integration in arbitrary-precision ball arithmetic", preprint (2018), https://arxiv.org/abs/1802.07942
The FLINT team, “Roots of Legendre polynomials and Gauss–Legendre nodes (arb_hypgeom.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/arb_hypgeom/legendre-roots.html (generated 2026-11-20).
@misc{flint-doc-arb-hypgeom-legendre-roots,
author = {{The FLINT team}},
title = {{Roots of Legendre polynomials and Gauss–Legendre nodes (arb\_hypgeom.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/arb_hypgeom/legendre-roots.html},
note = {Generated 2026-11-20}
}