E.V.E
v2023.02.15

◆ legendre

eve::legendre = {}
inlineconstexpr

Computes the value of the Legendre and associated Legendre polynomials of order n at x:

  • The Legendre polynomial of order n is given by \(\displaystyle \mbox{L}_{n}(x) = \frac{e^x}{n!}\frac{d^n}{dx^n}(x^ne^{-x})\).
  • The associated legendre polynomial is given by \(\displaystyle \mbox{L}_{n}^{m} = (-1)^m\frac{d^m}{dx^m}\mbox{L}_{n+m}(x)\).

Defined in header

#include <eve/module/polynomial.hpp>

Callable Signatures

namespace eve
{
template< eve::integral_value N, eve::floating_ordered_value T >
eve::as_wide_as<T, N> legendre(N n, T x) noexcept; //1
template< eve::integral_value N, eve::integral_value M, eve::floating_ordered_value T >
eve::as_wide_as<T, N> legendre(N n, M m, T x) noexcept; //2
}
constexpr callable_legendre_ legendre
Computes the value of the Legendre and associated Legendre polynomials of order n at x:
Definition: legendre.hpp:115
Definition: abi.hpp:18
  1. Legendre polynomial of order n
  2. Associated Legendre polynomial of orders m, n

Parameters

Return value

The value of the polynomial at x is returned.

Example

#include <eve/module/polynomial.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_ft xd = {-0.1, -0.2, -0.3, -0.5, 0.0, 0.2, 0.3, 2.0};
wide_it n = {0, 1, 2, 3, 4, 5, 6, 7};
wide_ft x(0.5);
std::cout << "---- simd" << '\n'
<< "<- xd = " << xd << '\n'
<< "<- n = " << n << '\n'
<< "<- x = " << x << '\n'
<< "-> legendre(n, xd) = " << eve::legendre(n, xd) << '\n'
<< "-> legendre(3, xd) = " << eve::legendre(3, xd) << '\n'
<< "-> legendre(n, 0.5) = " << eve::legendre(n, 0.5) << '\n'
<< "-> legendre(n, x) = " << eve::legendre(n, x) << '\n'
;
double xs = 0.1;
std::cout << "---- scalar" << '\n'
<< "<- xs = " << xs << '\n'
<< "-> legendre(4, xs) = " << eve::legendre(4, xs) << '\n';
return 0;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • eve::p_kind, eve::q_kind

    The expression p_kind(legendre)(n,x) is equivalent to legendre(n,x).

    The expression q_kind(legendre)(n,x) return the value at x of the second kind legendre function of order n.

    Example

    #include <eve/module/polynomial.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft xd = {-0.1, -0.2, -0.3, -0.5, 0.0, 0.2, 0.3, 2.0};
    wide_it n = {0, 1, 2, 3, 4, 5, 6, 7};
    wide_ft x(0.5);
    std::cout << "---- simd" << '\n'
    << "<- xd = " << xd << '\n'
    << "<- n = " << n << '\n'
    << "<- x = " << x << '\n'
    << "-> q_kind(legendre)(n, xd) = " << eve::q_kind(eve::legendre)(n, xd) << '\n'
    << "-> q_kind(legendre)(3, xd) = " << eve::q_kind(eve::legendre)(3, xd) << '\n'
    << "-> q_kind(legendre)(n, 0.5) = " << eve::q_kind(eve::legendre)(n, 0.5) << '\n'
    << "-> q_kind(legendre)(n, x) = " << eve::q_kind(eve::legendre)(n, x) << '\n'
    ;
    double xs = 0.1;
    std::cout << "---- scalar" << '\n'
    << "<- xs = " << xs << '\n'
    << "-> eve::q_kind(eve::legendre)(4, xs) = " << eve::q_kind(eve::legendre)(4, xs) << '\n';
    return 0;
    }
    constexpr q_kind_type const q_kind
    Higher-order Callable Object imbuing q_kind behaviour onto other Callable Objects.
    Definition: kind.hpp:68
  • eve::successor

    The expression successor(legendre)(l, x, ln, lnm1) (or successor(legendre)(l, m, x, ln, lnm1)) implements the three term recurrence relation for the (associated) Legendre polynomials, \(\displaystyle \mbox{P}^m_{l+1} = \left((2l+1)\mbox{P}^m_{l}(x)-l\mbox{P}^m_{l-1}(x)\right)/(l+m+1)\) These functions can be used to create a sequence of values evaluated at the same x and for rising l. ( \(m = 0\) and no \(m\) in call are equivalent here).

    Example

    #include <eve/module/polynomial.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft xd = {0.5, -1.5, 0.1, -1.0, 19.0, 25.0, 21.5, 10000.0};
    wide_it n = {0, 1, 2, 3, 4, 5, 6, 7};
    std::cout << "---- simd" << '\n'
    << "<- xd = " << xd << '\n'
    << "<- n = " << n << '\n';
    std::array<wide_ft, 8> h;
    h[0] = eve::legendre(0, xd);
    std::cout << "-> h[0] = " << h[0] << '\n';
    std::cout << "-> legendre(" << 0 << ", xd) = " << eve::legendre(0, xd) << '\n';
    h[1] = eve::legendre(1, xd);
    std::cout << "-> legendre(" << 1 << ", xd) = " << eve::legendre(1, xd) << '\n';
    std::cout << "-> h[1] = " << h[1] << '\n';
    for(int i = 2; i <= 7; ++i)
    {
    h[i] = eve::successor(eve::legendre)(i-1, xd, h[i-1], h[i-2]);
    std::cout << "-> h[" << i << "] = " << h[i] << '\n';
    std::cout << "-> legendre(" << i << ", xd) = " << eve::legendre(i, xd) << '\n';
    }
    return 0;
    }
    constexpr callable_i_ i
    Callable object computing the pure imaginary ( ) value.
    Definition: i.hpp:52
    constexpr successor_type const successor
    Higher-order Callable Object imbuing incrementation behaviour onto other Callable Objects.
    Definition: successor.hpp:42
  • eve::condon_shortley

    The expression condon_shortley(legendre)(l, m, x) multiplies the associated legendre polynomial value by the Condon-Shortley phase \((-1)^m\) to match the definition given by Abramowitz and Stegun (8.6.6). This is currently the version implemented in boost::math 1.79.

    Example

    #include <eve/module/polynomial.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft xd = {-0.1, -0.2, -0.3, -0.5, 0.0, 0.2, 0.3, 2.0};
    wide_it n = {0, 1, 2, 3, 4, 5, 6, 7};
    wide_it z(0);
    std::cout << "---- simd" << '\n'
    << "<- xd = " << xd << '\n'
    << "<- n = " << n << '\n'
    << "-> condon_shortey(legendre)(n, z, xd) = " << eve::condon_shortey(eve::legendre)(n, z, xd) << '\n';
    double xs = 0.1;
    std::cout << "---- scalar" << '\n'
    << "<- xs = " << xs << '\n'
    << "-> eve::condon_shortey(eve::legendre)(4, xs) = " << eve::condon_shortey(eve::legendre)(4, 0, xs) << '\n';
    return 0;
    }
  • eve::sph

    The expression sph(legendre)(l, m, theta) returns the spherical associated Legendre function of degree l, order m, and polar angle theta in radian (that is the classical spherical harmonic with \(\phi = 0\)), i.e. \(\displaystyle (-1)^mfrac{(2l+1)(l-m)!}{4\pi(l+m)!}\mbox{P}^m_{l}(\cos\theta)\)

    Example

    #include <eve/module/polynomial.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft xd = {-0.1, -0.2, -0.3, -0.5, 0.0, 0.2, 0.3, 2.0};
    wide_it n = {0, 1, 2, 3, 4, 5, 6, 7};
    wide_it z(0);
    std::cout << "---- simd" << '\n'
    << "<- xd = " << xd << '\n'
    << "<- n = " << n << '\n'
    << "-> sph(legendre)(n, z, xd) = " << eve::sph(eve::legendre)(n, z, xd) << '\n';
    double xs = 0.1;
    std::cout << "---- scalar" << '\n'
    << "<- xs = " << xs << '\n'
    << "-> eve::sph(eve::legendre)(4, xs) = " << eve::sph(eve::legendre)(4, 0, xs) << '\n';
    return 0;
    }
    constexpr sph_type const sph
    Higher-order Callable Object imbuing spherical semantic onto other Callable Objects.
    Definition: sph.hpp:55