std::legend...d::legendrel(3)
π NAME π
okay so this is the manual page for std::legendre, std::legendref, and std::legendrel β the whole little trio, together. The header title is std::legend...d::legendrel(3), and the manual name folded in near the top is C++ Standard Libary (that spelling is straight from the source, bestie, Iβm not fixing it π
).
The NAME line itself is exactly:
std::legendre,std::legendref,std::legendrel - std::legendre,std::legendref,std::legendrel
πΈ SYNOPSIS πΈ
Hereβs the whole cast, no cap:
double legendre( unsigned int n, double x );
double legendre( unsigned int n, float x );
double legendre( unsigned int n, long double x ); (1)
float legendref( unsigned int n, float x );
long double legendrel( unsigned int n, long double x );
double legendre( unsigned int n, IntegralType x ); (2)
- (1) computes the unassociated Legendre polynomials of the degree
nand argumentx. - (2) is a set of overloads or a function template accepting an argument of any integral type. Itβs equivalent to
(1)after casting the argument todouble.
Availability tea β: as all special functions, legendre is only guaranteed to be available in <cmath> if __STDCPP_MATH_SPEC_FUNCS__ is defined by the implementation to a value at least 201003L and if the user defines __STDCPP_WANT_MATH_SPEC_FUNCS__ before including any standard library headers.
bestie, those macro names are long and dramatic, but they are not optional if you want the guarantee. copy them exactly. periodt.
π PARAMETERS π
nβ the degree of the polynomial.xβ the argument, a value of a floating-point or integral type.
β¨ RETURN VALUE β¨
If no errors occur, you get the value of the order-n unassociated Legendre polynomial of x, that is:
1
2n
n!
dn
dxn
(x2
- 1)n
β¦and that is what gets returned. yes, the formula is giving very βstacked symbols on purpose.β I preserved it as-is so nobody comes for me.
π ERROR HANDLING π
Errors may be reported as specified in math_errhandling.
- If the argument is
NaN,NaNis returned and domain error is not reported. - The function is not required to be defined for
|x| > 1. - If
nis greater or equal than128, the behavior is implementation-defined.
warning bestie:|x| > 1is not required to be defined, andn >= 128goes straight into implementation-defined mystery land. do not act surprised when it gets weird π
π¦ NOTES π¦
- Implementations that do not support TR 29124 but support TR 19768 provide this function in the header
tr1/cmathand namespacestd::tr1. - An implementation of this function is also available in
boost.math. - The first few Legendre polynomials are:
legendre(0, x) = 1.legendre(1, x) = x.legendre(2, x) = (1/2) (3x2 - 1).legendre(3, x) = (1/2) (5x3 - 3x).legendre(4, x) = (1/8) (35x4 - 30x2 + 3).
π EXAMPLE π
(works as shown with gcc 6.0)
// Run this code
#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
#include <cmath>
#include <iostream>
double P3(double x)
{
return 0.5 * (5 * std::pow(x, 3) - 3 * x);
}
double P4(double x)
{
return 0.125 * (35 * std::pow(x, 4) - 30 * x * x + 3);
}
int main()
{
// spot-checks
std::cout << std::legendre(3, 0.25) << '=' << P3(0.25) << '\n'
<< std::legendre(4, 0.25) << '=' << P4(0.25) << '\n';
}
π OUTPUT π
-0.335938=-0.335938
0.157715=0.157715
π SEE ALSO π
laguerreβ Laguerre polynomialslaguerrefβ (function)laguerrelhermiteβ Hermite polynomialshermitefβ (function)hermitel
π EXTERNAL LINKS π
Weisstein, Eric W. "Legendre Polynomial." From MathWorld β A Wolfram Web Resource.
and thatβs the whole page, bestie β¨ source/version and date from the footer: http://cppreference.com, dated 2024.06.10, with std::legend...d::legendrel(3) doing its little footer cameo. bye ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms