std::legend...d::legendrel(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ 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. (1) computes the unassociated Legendre polynomials of the degree n and argument x.
  2. (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 to double.

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, NaN is returned and domain error is not reported.
  • The function is not required to be defined for |x| > 1.
  • If n is greater or equal than 128, the behavior is implementation-defined.
warning bestie: |x| > 1 is not required to be defined, and n >= 128 goes 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/cmath and namespace std::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 polynomials
  • laguerref β€” (function)
  • laguerrel
  • hermite β€” Hermite polynomials
  • hermitef β€” (function)
  • hermitel

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