Skip to main content
Ctrl+K

XlCalcNet Documentation

  • Preface

Getting started

  • Setup and general usage
    • Setting up XlCalcNet
    • General and user interface functions
    • Calling Python from C#
    • Using XlCalcNet with spreadsheet formulas
    • Mathematical functions based on Mpmath, Gmpy2 and Python-Flint (only Python)
    • Mathematical functions in fixed precision
    • Mathematical functions based on XlCalcNet2
    • A quick look at Numpy
    • A quick look at Matplotlib and related libraries
    • A quick look at Pandas and Xlxswriter
    • A quick look at Scipy
    • A quick look at R, RStudio and Rpy2
  • Basic floating point functions
    • Operator overloading, general real functions
    • Machine constants, general
    • Properties of numbers
    • Integer related functions
    • Floating point functions for real numbers
    • Fraction and remainder related functions
    • Functions related to mantissa width and exponent range
    • Mathematical Constants
  • Elementary scalar functions (real and complex)
    • Complex components
    • Roots and quadratic, cubic, and quartic equations
    • Exponential and related functions
    • Logarithms and related functions
    • Power functions
    • Trigonometric functions, in radians
    • Trigonometric functions, in multiples of \(\pi\)
    • Hyperbolic functions
    • Inverse trigonometric functions, in radians
    • Inverse hyperbolic functions
    • Factorials, Gamma and related functions
    • Miscellaneous functions
  • Statistical Distributions
    • Introduction to random variables and distributions
    • Base class for univariate distributions
    • Base class for continuous univariate distributions
    • Base class for discrete univariate distributions
    • Closed form distributions, based on elementary functions
      • Boost: Arcsine Distribution
      • Boost: Cauchy distribution
      • Boost: Exponential distribution
      • Boost: Gumbel (Generalized Extreme Value distribution Type-I) distribution
      • Boost: Hyperexponential Distribution
      • !!!Boost: Kumaraswamy distribution
      • Boost: Laplace distribution
      • Boost: Logistic distribution
      • Boost: Pareto distribution
      • Boost: Rayleigh distribution
      • Boost: Triangular Distribution
      • Boost: Uniform distribution
      • Boost: Weibull (Minimum-Type-III) distribution
      • Dagum (Burr Type III) distribution
      • Fisk (log-logistic) distribution
      • Fréchet (Maximum/Minimum-Type-II or Inverse Weibull) distribution
      • Generalized Extreme Value (Maximum) or GEV distribution
      • Generalized Pareto distribution
      • Gompertz-Makeham distribution
      • Lomax distribution
      • Shifted Gompertz distribution
      • Singh-Maddala (Burr Type XII) distribution
    • Closed form distributions, based on the error function
      • !!!Boost: Lévy distribution
      • Boost: Lognormal (Johnson \(S_L\)) distribution
      • !!!Boost: Moyal Distribution
      • Boost: Normal (Johnson \(S_N\)) distribution
      • Boost: Skew normal Distribution
      • Boost: Wald (or Inverse Gaussian) distribution
      • Birnbaum-Saunders Distribution
      • Exponentially Modified Gaussian (EMG) distribution
      • Folded normal distribution
      • Half-normal distribution
      • Johnson \(S_B\) distribution
      • Johnson \(S_U\) distribution
      • Normal maximum distribution, \(\rho_{ij, i \ne j} = 0\)
      • Normal maximum modulus distribution, \(\rho_{ij, i \ne j} = 0\)
      • Sinh-arcsinh normal distribution
      • Truncated normal distribution
    • Closed form distributions, based on the incomplete gamma function
      • !!!Boost: Chi Distribution
      • Boost: Chi-Squared distribution
      • Boost: Gamma (Pearson Type III, Erlang) distribution
      • Boost: Inverse chisquared distribution
      • Boost: Inverse Gamma (Pearson Type V) distribution
      • !!!Boost: Maxwell Distribution
      • !!!Boost: Nakagami distribution
      • Amoroso distribution
      • Distribution of the logarithm of a \(\chi^2\) random variable
      • Hypoexponential (Generalized Erlang) Distribution
      • Lindley distribution (generalized)
      • Skew exponential power distribution
      • Stacy (generalized gamma) distribution
    • Closed form distributions, based on the incomplete beta function
      • Boost: Beta (Pearson Type I and II) distribution
      • Boost: Central Fisher F distribution
      • Boost: Student \(t\) (Pearson Type VII) distribution
      • Distribution of the negative logarithm of a beta variable
      • Beta-prime (Pearson Type VI) distribution
      • Generalized Beta (Type 1) distribution
      • Generalized Beta (Type 2) distribution
      • Generalized logistic distribution (JKB Types I - IV)
      • Generalized beta-exponential distribution
      • Feller-Pareto distribution
      • Fisher \(z\) distribution
      • Skew t-distribution (Jones)
      • Pearson’s rho distribution (under \(H_0\))
    • Noncentral distributions
      • Boost: Noncentral \(\chi^2\) distribution
      • Boost: Noncentral Student \(t\) distribution
      • Boost: Noncentral Fisher \(F\) distribution
      • Boost: Noncentral Beta Type I distribution
      • Noncentral Chi distribution
      • Rice (Nakagami-n) distribution
      • Noncentral distribution of the sample correlation coefficient
      • Distribution of the logarithm of a noncentral Beta Type II variable
      • Noncentral distribution (Type I) of Fisher’s \(R^2\)
      • Distribution of the logarithm of a noncentral Fisher \(1-R^2\) variable
      • Doubly non-central Student \(t\) distribution
      • Doubly non-central Fisher \(F\) distribution
    • Distributions related to multiple comparisons of means
      • Overview and literature
      • Normal maximum distribution, \(\rho_{ij, i \ne j} = \rho\)
      • Normal maximum modulus distribution, \(\rho_{ij, i \ne j} = \rho\)
      • Normal maximum distribution, \(\rho_{ij, i \ne j} = \lambda_i \lambda_j\)
      • Normal maximum modulus distribution, \(\rho_{ij, i \ne j} = \lambda_i \lambda_j\)
      • Normal range distribution
      • Studentized maximum distribution
      • Studentized maximum modulus distribution
      • Distribution of Dunnett’s \(t\), one-sided
      • Distribution of Dunnett’s \(t\), two-sided
      • Nair’s \(t\)-distribution
      • Halperin’s \(t\)-distribution
      • Nelson’s \(h\)-distribution
      • Studentized range distribution
    • Distributions related to multivariate statistical analysis
      • Distribution of the sum of the negative logarithms of independent beta variables
      • Distribution of the product of independent beta variables
      • Distribution of Wilks’ \(\Lambda\)
      • Distribution of Wilks’ \(L_{vc}\)
      • Distribution of Wilks’ \(L_{vcm}\)
      • Distribution of Wilks’ test of independence of \(p\) variates
      • Distribution of Wilks’ test of independence of \(k\) groups of variates
      • Distribution of Mauchly’s test of sphericity vs general structure
      • Distribution of Box’s test of equality of covariance matrices, equal sample sizes
      • Distribution of Box’s test of equality of k covariance matrices, unequal sample sizes
      • Distribution of Box’s test for same multivariate normal distributions, unequal sample sizes
      • Distribution of the modified likelihood ratio test (LRT) for a given covariance matrix
      • Distribution of the modified likelihood ratio test (LRT) for a given covariance matrix and mean vector
      • Central distribution of Roy’s largest root
      • Central distribution of Pillai’s \(V\)
      • Central distribution of Hotelling’s \(T^2\)
      • Noncentral Distribution of Wilks’ \(\Lambda\): MANOVA
      • Noncentral Distribution of Wilks’ \(\Lambda\): Canonical Correlation
    • Miscellaneous continuous distributions
      • Boost: Kolmogorov-Smirnov distribution (limiting form)
      • Boost: Landau Distribution
      • Boost: Holtsmark distribution
      • Boost: Map-Airy distribution
      • Boost: Saspoint5 distribution
      • Lévy alpha-stable distribution
      • Pearson Type IV distribution
      • Meixner distribution
      • Voigt Profile Distribution
      • Wrapped Cauchy distribution
      • Wrapped normal distribution
      • Von Mises distribution
      • Generalized inverse Gaussian distribution
      • Harmonic distribution
      • Halphen A distribution
      • Halphen B distribution
      • Halphen IB distribution
      • Generalized hyperbolic distribution
      • Hyperbolic distribution
      • Variance-gamma distribution
    • Elementary discrete (lattice) distributions
      • Boost: Bernoulli distribution
      • Boost: Geometric distribution
      • Boost: Poisson distribution
      • Boost: Binomial distribution
      • Boost: Negative binomial distribution
      • Boost: Classical hypergeometric distribution
      • Log-series distribution
      • Zeta distribution
      • Skellam distribution
      • Delaporte distribution
      • Beta-Poisson distribution (Quinkert)
      • Beta-binomial distribution
      • Beta-negative binomial distribution (Waring)
      • Negative hypergeometric distribution
      • Pólya-Eggenberger distribution
      • General hypergeometric distribution
      • Noncentral hypergeometric distribution, Fisher alternatives
    • Discrete (lattice) distributions related to (stratified) rank tests
      • Wilcoxon signed rank T distribution, continuous data
      • Noncentral Wilcoxon signed rank T distribution, Bennett alternatives
      • Mann-Whitney U distribution, continuous data
      • Noncentral Mann-Whitney U distribution, Lehmann alternatives
      • Noncentral Mann-Whitney U distribution, Milton alternatives
      • Kendall’s tau distribution, continuous data
      • Jonckheere-Terpsta \(T\) distribution, continuous data
      • Generalized Page \(L\) distribution, continuous data
      • Noncentral generalized Page \(L\) distribution, Milton alternatives
    • Discrete (non-lattice) distributions related to rank tests
      • Cochran-Friedman-Quade distribution
      • Kruskal-Wallis distribution
  • Numerical calculus
    • Introduction
    • DAMath: Numerical Rootfinding and Minimization
    • Boost/Math: Root Finding and Minimization Algorithms
    • Mpmath: Rootfinding and optimization
    • DAMath: Numerical Quadrature
    • Boost/Math: Numerical integration
    • Mpmath: Numerical integration
    • Mpmath: Numerical inverse Laplace transform
    • Boost/Odeint: Ordinary differential equations
    • Mpmath: Numerical differentiation
    • Mpmath: Asymptotic expansions
    • Mpmath: Function approximation
    • Mpmath: Sums, products, limits and extrapolation
    • Mpmath: Number identification
    • Mpmath: Polynomials
    • Eigen: Polynomials
    • Eigen/MinPack: non linear optimization
    • Eigen/CppOptLib: multidimensional optimization
    • Flint/Functions for polynomials
    • Flint/Power series and Taylor arithmetic
    • Flint/Verified numerical differentiation
    • Flint/Verified numerical integration
  • Eigen: Dense and Sparse Matrices
    • Creating scalars and matrices
    • Read-only properties: information about a matrix
    • Accessing and setting parts of a matrix
    • Changing the shape of a matrix and/or the order of coefficients
    • Basic arithmetic operations
    • Descriptive Statistics
    • Standard decompositions and linear solving
    • Singular Value and Eigen (selfadjoint) decompositions
    • Eigen decompositions of general square matrices
    • Eigen: Functions of matrix argument
    • Eigen: Fast Fourier Transform
  • Numpy: use with multiprecision data types
    • Numpy array creation from shape or value
    • Numpy array creation from existing data
    • Building special arrays for numerical work
    • Numpy indexing
    • Numpy basic array manipulation routines
    • Numpy array manipulation: Transpose-like operations
    • Numpy array manipulation: Changing number of dimensions
    • Numpy array manipulation: Joining arrays
    • Numpy array manipulation: Splitting and tiling arrays
    • Numpy array manipulation: Adding and removing elements
    • Numpy array manipulation: Rearranging elements
    • Numpy array manipulation: Sorting
    • Numpy array manipulation: Searching
    • Numpy mathematical functions: Sums, products, differences
    • Numpy mathematical functions: Extrema Finding
    • Numpy mathematical functions: Arithmetic operations, elementwise
    • Numpy mathematical functions: Averages and variances
    • Numpy mathematical functions: Matrix and vector products
    • Numpy logical functions: Truth value testing
    • Numpy mathematical functions: Integer and fractional
    • Numpy mathematical functions: Miscellaneous
    • Summary and examples: Numpy utility functions
    • Arithmetic operations with scalars and iterables
    • Numerical transformations and descriptive statistics
    • Standard decompositions and linear solving
    • Singular Value and Eigen decompositions
    • Analytic functions of a matrix
    • Discrete Fourier transform (DFT)
    • Flint/Functions for matrices

Special Functions

  • Elliptic functions and related
    • Carlson symmetric elliptic integrals
    • Legendre elliptic integrals (elliptic parameter \(m\))
    • Legendre elliptic integrals (elliptic modulus \(k\)), and related functions
    • Jacobi elliptic functions
    • Jacobi theta functions and related functions
    • Conversions of parameters of Weierstrass \(\wp\)
    • Weierstrass elliptic functions, in terms of elliptic period ratio \(\tau\)
    • Modular forms, in terms of half-period \(\omega_1\) and elliptic period ratio \(\tau\)
  • Lerch’s phi and related
    • Lerch’s transcendent and Lerch’s zeta
    • Polygamma and related functions
    • Polylogarithm and related functions
    • Hurwitz zeta and related functions
    • Riemann zeta function, and related functions
  • Hypergeometric function \(\,_0F_1\) and related
    • Hypergeometric Limit Function \(\,_0F_1\)
    • Bessel functions
    • Modified Bessel functions
    • Spherical Bessel functions
    • Modified spherical Bessel functions
    • Hankel functions
    • Airy functions
    • Kelvin functions
  • Hypergeometric function \(\,_1F_1\) and related
    • Hypergeometric Functions \(\,_1F_1\) (Kummer) and \(U\) (Tricomi)
    • Incomplete gamma functions
    • Coulomb, Whittaker and parabolic cylinder function
    • Error function and related functions
    • Exponential integrals, and related functions
  • Hypergeometric functions \(\,_2F_1\) and \(\,_1F_2\) (and related functions)
    • Gauss Hypergeometric Function \(\,_2F_1\)
    • Chebyshev, Gegenbauer and Jacobi polynomials
    • Legendre polynomials and related
    • Incomplete beta functions
    • Hypergeometric function \({}_1F_2\)
    • Scorer functions
    • Struve functions
    • Anger, Weber and Lommel functions

Supporting Functions

  • Algebra with random variables
    • Probability density function (pdf)
    • Probability mass function (pmf)
    • Cumulative distribution function (cdf)
    • Quantile function
    • Characteristic function
    • Moment generating function
    • Cumulant generating function
    • Probability generating function
    • Factorial Moments
    • Raw Moments
    • Central Moments
    • Cumulants
  • Series and integrals
    • Finite series algorithms for selected distributions
    • Infinite series algorithms for selected functions and distributions
    • Finite series for lattice distributions, based on factorial moments
    • Efficient integration of bell-shaped functions
    • Verified numerical integration
  • Pmf vectors
    • Basic discrete (lattice) distribution functions
    • Discrete (lattice) distribution functions related to (stratified) rank tests
    • Discrete (non-lattice) distribution functions related to rank tests
  • Fast approximations
    • Approximations based on the normal distribution
    • Approximations based on the chi-squared distribution
    • Approximations based on the central \(t\), \(F\) or beta distribution
    • Approximations based on the noncentral chi-squared distribution
    • Approximations based on the noncentral F or beta distribution
    • Approximations based on hypergeometric functions of scalar argument

Gallery of Plots

  • Visualisation of datasets
    • Bar Charts
    • Line and lollipop charts
    • Area Plots
    • Boxplot, Violinplot and Raincloud plot
    • Correlation and regression
    • Financial plots (requires mplfinance)
    • Geographic data (requires cartopy)
    • Geographic data (requires geopandas)
    • Parts of a whole
    • Arcplots, dendrograms, heatmaps and clustermaps
    • PlotTable
    • Flow and connections
    • Circular plots and flows
    • Network data (requires networkx)
  • Visualisation of functions and curves (2D)
    • Introduction to 2D functions and curves
    • Basic curves
    • Spirals
    • Decorative curves
    • General curve families
    • Field lines
    • Contours
    • Complex functions rendered as contours
    • Streams, barbs and quivers (some require cartopy)
  • Bitmaps
    • Fractals: introduction
    • Fractals related to the Mandelbrot set
    • Fractals related to the Julia set
    • Newton Fractals
    • Domain coloring options
    • Domain coloring: Examples part 1
  • Matplotlib 3D Graphics
    • Introduction
    • Matplotlib: 3D Graphics, part 2
    • S3dlib: Basic geometric figures
    • S3dlib: Real functions
    • S3dlib: Parametric Surfaces
    • S3dlib: Image mapping and clipping
    • S3dlib: Edge-to-edge surface coloring
    • S3dlib: Decorative parametric surfaces
    • S3dlib: Geometric and color datagrid mapping (requires scipy)
    • S3dlib: Implicit surfaces (requires scikit-image)
  • Plotly
    • General surface plots in 3D
    • Geographical plots
    • Sankey plots

Interactive 3D Wpf Plots

  • Wpf: Altitude surfaces in 3D, real and complex functions
    • Special techniques for height surfaces, real and complex functions
    • Scatterplots and building 3D scenes
    • Height plots of general bivariate real functions
  • Wpf: Parametric surfaces
    • Surfaces of translation
    • Surfaces of revolution: spheres and related
    • Generalisations of common surfaces
    • Minimal surfaces
    • Nonorientable (one-sided) Surfaces
    • Decorative parametric surfaces
  • Wpf: Path surfaces in 3D
    • Introduction to path surfaces
    • Functions with real input and complex results
    • Characteristic functions of statistical distributions
    • Helices and related curves traced on cylinders, cones and spheres
    • Coil springs
    • General knots
    • Torus knots
    • Lissajous knots
    • Polynomial knots
  • Wpf: Built-in 3D objects
    • Builtin solids with support for textures
    • Builtin solids without support for textures
    • Platonic solids, and related solids

User library: numerical

  • Additional Classes
    • User defined functions based on multiple precision arithmetic (Python)
    • User defined functions based on fixed precision arithmetic (C#)
    • User defined functions based on arbitrary precision arithmetic (C#)
    • Scalar functions
  • Distribution functions
    • Distributions related to multiple comparisons of means
    • Discrete (lattice) distribution functions related to (stratified) rank tests
    • Discrete (non-lattice) distribution functions related to rank tests
  • Inferential statistics
    • Basic classical statistical tests (stratified)
    • Basic classical statistical tests for 2 independent samples (stratified)
    • Basic classical statistical tests for 2 correlated samples (stratified)
    • Analysis of variance (ANOVA), orthogonal polynomials, and analysis of means (AOM)
    • Multiple comparisons of means
    • Nonparametric statistical tests, 1 or 2 samples
    • Nonparametric statistical tests, k samples
    • Multivariate statistical tests
  • Addditional elementary functions (real arguments, double precision)
    • Additional root, exponential, logarithmic and power functions
    • Additional Trigonometric functions (real arguments only)
    • Additional real error functions (real arguments only)
    • Additional real gamma functions (real arguments only)
    • Additional real incomplete gamma functions (real arguments only)
  • Addditional special functions (real arguments, double precision)
    • Conversions of parameters of elliptic functions
    • Additional elliptic integrals
    • Bulirsch elliptic integrals
    • Maple style elliptic integrals
    • Jacobi theta functions at \(x=0\) for \(0 \le q <1\)
    • Inverse Jacobi elliptic functions
    • Lemniscate functions
    • Neville theta functions
    • Polygamma, and related functions
    • Polylogarithm, and related functions
    • Riemann zeta, and related functions
    • Bessel functions of integer order
    • Modified Bessel functions of integer order
    • Integrals of zero-order Bessel functions
    • Kelvin functions of order 0
    • Synchrotron functions
    • Error function, and related functions
    • Exponential integrals, and related functions
    • Coulomb, Whittaker and parabolic cylinder function
    • Hypergeometric pFq, and related functions
    • Miscellaneous functions
  • Addditional special functions (complex arguments, double precision)
    • Conversions of parameters of Weierstrass \(\wp\)
    • Weierstrass elliptic functions, in terms of (real) lattice invariants \(g_2, g_3\)
    • Weierstrass elliptic functions, in terms of (real) lattice roots \(e_1, e_2\)
    • Weierstrass elliptic functions, in terms of lattice half-periods \(\omega_1\) and \(\omega_2\)
  • Addditional special functions (Mpmath)
    • Mpmath: Conversions of parameters of elliptic functions
    • Related to Lerch’s phi
    • Additional numbertheoretic functions
    • Generalized hypergeometric functions
    • Appell Functions
    • Q Functions
    • Further generalizations of gamma and hypergeometric functions

Back matter

  • License and History
    • Mozilla Public License Version 2.0
    • History

Indices

  • General Index
  • .rst

Legendre polynomials and related

Contents

  • Legendre polynomial (or function) of the first kind, \(P_n(x)\)
    • ctx.legendre_p()
  • Associated Legendre function of the first kind, \(P^m_l(x)\)
    • ctx.legendre_plm()
  • Legendre function of the second kind, \(Q_l(x)\)
    • ctx.legendre_q()
  • Associated Legendre function of the second kind, \(Q^m_l(x)\)
    • ctx.legendre_qlm()
  • Spherical harmonics, \(Y_n^m(\theta, \phi)\)
    • ctx.spherical_harmonic()
  • Toroidal harmonics \(P^m_{l-1/2}(x)\)
    • math53.toroidal_plm()
  • Toroidal harmonics \(Q^m_{l-1/2}(x)\)
    • math53.toroidal_qlm()
  • Olver’s associated Legendre function \(Q^m_{l-1/2}(x)\)
    • math53.olver_qlm()

Legendre polynomials and related#

Legendre polynomial (or function) of the first kind, \(P_n(x)\)#

ctx.legendre_p(n, x)#

where ctx is math53, ctxboost or ctxflint.

Returns \(\displaystyle P_n(x) = \,_2F_1\left(-n, n+1, 1, \frac{1-x}{2}\right)\), the Legendre polynomial of degree \(n\). The Legendre polynomials are orthogonal on the interval \((-1, 1)\) with \(w(x) = 1\). If \(n \geq 0\) the function uses the following recurrence relation, with \(P_n(x) = P_{-n-1}(x)\):

\begin{eqnarray} P_0 (x) & = & 1 \\ P_1 (x) & = & x \nonumber \\ (n+1)P_{n+1} (x)& = & (2n+1) P_{n}(x) - n P_{n-1}(x). \nonumber \end{eqnarray}

See also Wikipedia [1420], MathWorld [1002], NIST [305], BoostMath [131], Ehrhardt [309] (3.7.13), Flint [825], Flint [821], Mpmath [666].

An example in Python

>>> from xlcalcnet import xreal
>>> xreal.LegendreP(3, 0.5)
xreal('5.2359877559829887307E-1')
>>> xreal.LegendreP(6, '0.51')
xreal('5.3518479027559984754E-1')

An example in Visual Basic

>>> from xlcalcnet import Gpr
>>> Gpr.LegendreP(3, 0.5)
Gpr('5.2359877559829887307E-1')
>>> Gpr.LegendreP(6, '0.51')
Gpr('5.3518479027559984754E-1')

An example with real input:

>>> from xlcalcnet import dec, mpm, gmp, fpm, apm
>>> mpm.dps = 40; n = '10'; x = '5.0'
>>> \mathrm{d}x = dec.legendre(n, x); mx = mpm.legendre(n, x); gx = gmp.legendre(n, x)
>>> fx = fpm.legendre(n, x); ax = apm.legendre(n, x)
>>> mpm.show([\mathrm{d}x, mx, gx, fx, ax])
dec:  1.600472677000000000000000000000000000000E+9
mpm:  1.600472677000000000000000000000000000000e+9
gmp:  1.600472677000000000000000000000000000000E+09
fpm:  1.60047267700000E+09
apm:  1.600472677000000000000000000000000000000e+9 (1.54e-39%)

An example with complex input:

>>> from xlcalcnet import dec, mpm, gmp, fpm, apm
>>> mpm.dps = 20; n = '10'; z = '5.0 + 3j'
>>> \mathrm{d}z = dec.legendre(n, z); mz = mpm.legendre(n, z); gz = gmp.legendre(n, z)
>>> fz = fpm.legendre(n, z); az = apm.legendre(n, z)
>>> mpm.show([\mathrm{d}z, mz, gz, fz, az],  aligned=True)
dec: 5.4324745448476562500E+9        - 5.7861538517578125000E+9j
mpm: 5.4324745448476562500e+9        - 5.7861538517578125000e+9j
gmp: 5.4324745448476562500E+09       - 5.7861538517578125000E+09j
fpm: 5.43247454484766E+09            - 5.78615385175781E+09j
apm: 5.4324745448476562500e+9 (0.0%) - 5.7861538517578125000e+9 (0.0%)j

Associated Legendre function of the first kind, \(P^m_l(x)\)#

ctx.legendre_plm(l, m, x)#

where ctx is math53, ctxboost or ctxflint.

Returns \(\displaystyle \frac{1}{\Gamma(1-m)} \frac{(1+z)^{m/2}}{(1-z)^{m/2}} \,_2F_1\left(-n, n+1, 1-m, \frac{1-z}{2}\right).\), the (associated) Legendre function of the first kind of degree \(n\) and order \(m\). Taking \(m = 0\) gives the ordinary Legendre function of the first kind, \(P_n(z)\).

See also Wikipedia [1401], MathWorld [1001], NIST [305], BoostMath [131], Ehrhardt [309] (3.7.14), Flint [825], Flint [821], Mpmath [654].

Many different branch cut conventions appear in the literature. If type is 0, the version

\[P_n^m(z) = \frac{(1+z)^{m/2}}{(1-z)^{m/2}} \mathbf{F}\left(-n, n+1, 1-m, \frac{1-z}{2}\right)\]

is computed, and if type is 1, the alternative version

\[{\mathcal P}_n^m(z) = \frac{(z+1)^{m/2}}{(z-1)^{m/2}} \mathbf{F}\left(-n, n+1, 1-m, \frac{1-z}{2}\right).\]

is computed. Type 0 and type 1 respectively correspond to type 2 and type 3 in Mathematica and mpmath.

An example in Python

>>> from xlcalcnet import xreal
>>> xreal.LegendrePlm(2, 3, 0.5)
xreal('5.2359877559829887307E-1')
>>> xreal.LegendrePlm(2, 6, '0.51')
xreal('5.3518479027559984754E-1')

An example in Visual Basic

>>> from xlcalcnet import Gpr
>>> Gpr.LegendrePlm(2, 3, 0.5)
Gpr('5.2359877559829887307E-1')
>>> Gpr.LegendrePlm(2, 6, '0.51')
Gpr('5.3518479027559984754E-1')

An example with real input:

>>> from xlcalcnet import dec, mpm, gmp, fpm, apm
>>> mpm.dps = 40; n = '10'; m = '7'; x = '0.5'
>>> \mathrm{d}x = dec.legenp(n, m, x); mx = mpm.legenp(n, m, x); gx = gmp.legenp(n, m, x)
>>> fx = fpm.legenp(n, m, x); ax = apm.legenp(n, m, x)
>>> mpm.show([\mathrm{d}x, mx, gx, fx, ax])
dec:  -1.836027792321961447325321009149754756328E+6
mpm:  -1.836027792321961447325321009149754756328e+6
gmp:  -1.836027792321961447325321009149754756328E+06
fpm:  -1.83602779232196E+06
apm:  -1.836027792321961447325321009149754756328e+6 (-6.556e-40%)

An example with complex input:

>>> from xlcalcnet import dec, mpm, gmp, fpm, apm
>>> mpm.dps = 20; n = '10 + 0j'; m = '7 + 1j'; z = '5.0 + 3j'
>>> \mathrm{d}z = dec.legenp(n, m, z); mz = mpm.legenp(n, m, z); gz = gmp.legenp(n, m, z)
>>> fz = fpm.legenp(n, m, z); az = apm.legenp(n, m, z)
>>> mpm.show([\mathrm{d}z, mz, gz, fz, az],  aligned=True)
dec: 5.1676243722757488933E+14              - 9.9095186680298524778E+14j
mpm: 5.1676243722757488933e+14              - 9.9095186680298524778e+14j
gmp: 5.1676243722757488933E+14              - 9.9095186680298524778E+14j
fpm: 5.16762437227575E+14                   - 9.90951866802985E+14j
apm: 5.1676243722757488933e+14 (2.768e-19%) - 9.9095186680298524778e+14 (-1.925e-19%)j

Legendre function of the second kind, \(Q_l(x)\)#

ctx.legendre_q(l, x)#

where ctx is math53, ctxboost or ctxflint.

See also: https://en.wikipedia.org/wiki/Legendre_polynomials

Returns \(\displaystyle Q_n(x) = \,_2F_1\left(\frac{l+1}{2}, \frac{l+2}{2}; l+\frac{3}{2}; \frac{1}{x^2}\right)\), the Legendre function of the second kind of degree \(l\). For integer \(l \geq 0\) and \(x \ne 1\), the following recurrence relations hold:

\begin{eqnarray} Q_0 (x) & = & \frac{1}{2} \log \left(\frac{1+x}{1-x}\right) \\ Q_1 (x) & = & \frac{x}{2} \log \left(\frac{1+x}{1-x}\right) -1 \nonumber \\ (k+1)Q_{k+1} (x)& = & (2k+1) Q_{k}(x) - k Q_{k-1}(x). \nonumber \end{eqnarray}

See also Wikipedia [1420], MathWorld [1002], NIST [305], BoostMath [131], Ehrhardt [309] (3.7.15), Flint [825], Flint [821], Mpmath [655].

This function returns \(Q^m_l (x)\), the associated Legendre functions of the second kind with \(l \geq 0\), \(l+m \geq 0\) and \(x \neq 1\), defined as

\[Q^m_l (x) = (-1)^m (1-x^2)^{m/2} \frac{d^m}{\mathrm{d}x^m} Q_{l} (x), \quad |x|<1,\]
\[Q^m_l (x) = (x^2-1)^{m/2} \frac{d^m}{\mathrm{d}x^m} Q_{l} (x), \quad |x|>1.\]

An example in Python

>>> from xlcalcnet import xreal
>>> xreal.LegendreQ(3, 0.5)
xreal('5.2359877559829887307E-1')
>>> xreal.LegendreQ(6, '0.51')
xreal('5.3518479027559984754E-1')

An example in Visual Basic

>>> from xlcalcnet import Gpr
>>> Gpr.LegendreQ(3, 0.5)
Gpr('5.2359877559829887307E-1')
>>> Gpr.LegendreQ(6, '0.51')
Gpr('5.3518479027559984754E-1')

An example with real input:

>>> from xlcalcnet import dec, mpm, gmp, fpm, apm
>>> mpm.dps = 40; n = '10'; m = '7'; x = '0.5'
>>> \mathrm{d}x = dec.legenq(n, m, x); mx = mpm.legenq(n, m, x); gx = gmp.legenq(n, m, x)
>>> fx = fpm.legenq(n, m, x); ax = apm.legenq(n, m, x)
>>> mpm.show([\mathrm{d}x, mx, gx, fx, ax])
dec:  2.716651409660037234094986783336728254923E+6
mpm:  2.716651409660037234094986783336728254923e+6
gmp:  2.716651409660037234094986783336728254923E+06
fpm:  2.71665140966004E+06
apm:  2.716651409660037234094986783336728254923e+6 (3.811e-38%)

An example with complex input:

>>> from xlcalcnet import dec, mpm, gmp, fpm, apm
>>> mpm.dps = 20; n = '10 + 0j'; m = '7 + 1j'; z = '5.0 + 3j'
>>> \mathrm{d}z = dec.legenq(n, m, z); mz = mpm.legenq(n, m, z); gz = gmp.legenq(n, m, z)
>>> fz = fpm.legenq(n, m, z); az = apm.legenq(n, m, z)
>>> mpm.show([\mathrm{d}z, mz, gz, fz, az],  aligned=True)
dec: 1.5565835524046748818E+15              + 8.1172853822265297587E+14j
mpm: 1.5565835524046748818e+15              + 8.1172853822265297587e+14j
gmp: 1.5565835524046748818E+15              + 8.1172853822265297587E+14j
fpm: 1.55658355240468E+15                   + 8.11728538222653E+14j
apm: 1.5565835524046748818e+15 (9.619e-18%) + 8.1172853822265297586e+14 (1.78e-17%)j

Associated Legendre function of the second kind, \(Q^m_l(x)\)#

ctx.legendre_qlm(l, m, x)#

where ctx is math53, ctxboost or ctxflint.

For generalization to hypergeometric functions, see https://en.wikipedia.org/wiki/Legendre_function#Solutions_of_the_differential_equation

and https://en.wikipedia.org/wiki/Associated_Legendre_polynomials#Generalization_via_hypergeometric_functions

Returns \(\displaystyle Q_l^m(z) = \frac{\pi}{2 \sin(\pi m)} \left( \cos(\pi m) P_l^m(z) - \frac{\Gamma(1+m+l)}{\Gamma(1-m+l)} P_l^{-m}(z)\right)\), the (associated) Legendre function of the second kind of degree \(l\) and order \(m\).

Here \(\displaystyle P_l^m(z)\) is the Legendre function of the first kind of degree \(l\) and order \(m\). The formula above should be understood as limit when \(m\) is an integer. Taking \(m = 0\) gives the ordinary Legendre function of the second kind, \(Q_n(z)\).

A different formula from Wikipedia:

\[Q_{\lambda}^{\mu}(z) = \frac{\sqrt{\pi}\ \Gamma(\lambda+\mu+1)}{2^{\lambda+1}\Gamma(\lambda+3/2)}\frac{1}{z^{\lambda+\mu+1}}(1-z^2)^{\mu/2} \,_2F_1 \left(\frac{\lambda+\mu+1}{2}, \frac{\lambda+\mu+2}{2}; \lambda+\frac{3}{2}; \frac{1}{z^2}\right)\]

For integer \(m\), \(l \geq 0\), \(l+m \geq 0\) and \(x \neq 1\), the function can be defined by

\[Q^m_l (x) = (-1)^m (1-x^2)^{m/2} \frac{d^m}{\mathrm{d}x^m} Q_{l} (x),\]
\[Q^{-m}_l (x) = (x^2-1)^{m/2} \frac{(l-m)!}{(l+m)!} Q_{l}^m (x).\]

The factor \((-1)^m\) is omitted if \(|x|>1\), see NIST [305] (14.9.14).

See also Wikipedia [1420], MathWorld [1002], NIST [305], BoostMath [131], Ehrhardt [309] (3.7.16), Mpmath [655].

Sets res to the associated Legendre function of the second kind evaluated for degree n, order m, and argument z. When m is zero, this reduces to the Legendre function \(Q_n(z)\).

Many different branch cut conventions appear in the literature. If type is 0, the version

\[Q_n^m(z) = \frac{\pi}{2 \sin(\pi m)} \left( \cos(\pi m) P_n^m(z) - \frac{\Gamma(1+m+n)}{\Gamma(1-m+n)} P_n^{-m}(z)\right)\]

is computed, and if type is 1, the alternative version

\[\mathcal{Q}_n^m(z) = \frac{\pi}{2 \sin(\pi m)} e^{\pi i m} \left( \mathcal{P}_n^m(z) - \frac{\Gamma(1+m+n)}{\Gamma(1-m+n)} \mathcal{P}_n^{-m}(z)\right)\]

is computed. Type 0 and type 1 respectively correspond to type 2 and type 3 in Mathematica and mpmath.

An example in Python

>>> from xlcalcnet import xreal
>>> xreal.LegendrePlm(2, 3, 0.5)
xreal('5.2359877559829887307E-1')
>>> xreal.LegendrePlm(2, 6, '0.51')
xreal('5.3518479027559984754E-1')

An example in Visual Basic

>>> from xlcalcnet import Gpr
>>> Gpr.LegendrePlm(2, 3, 0.5)
Gpr('5.2359877559829887307E-1')
>>> Gpr.LegendrePlm(2, 6, '0.51')
Gpr('5.3518479027559984754E-1')

Spherical harmonics, \(Y_n^m(\theta, \phi)\)#

ctx.spherical_harmonic(theta, phi, n, m)#

where ctx is math53, ctxboost or ctxflint.

Note: math53.spherHarm(theta, phi, n, m), ctxboost.SphericalHarmonicR(theta, phi, n, m), ctxboost.SphericalHarmonicI(theta, phi, n, m)

!!! n and m need to be integer !!!

Returns \(\displaystyle Y_l^m(\theta,\phi) = \sqrt{\frac{2l+1}{4\pi}\frac{(l-m)!}{(l+m)!}} P_l^m(\cos \theta) e^{i m \phi}\) the spherical harmonic, where \(\displaystyle P_l^m(z)\) is the Legendre function of the first kind of degree \(l\) and order \(m\), \(\theta \in [0, \pi]\) denotes the polar coordinate (ranging from the north pole to the south pole) and \(\phi \in [0, 2 \pi]\) denotes the azimuthal coordinate on a sphere. Care should be used since many different conventions for spherical coordinate variables are used.

See also Wikipedia [1423], MathWorld [1008], NIST [306], BoostMath [136], Ehrhardt [309] (3.7.17), Flint [821], Mpmath [667].

An example in Python

>>> from xlcalcnet import xreal
>>> xreal.SpherHarm(2, 3, 5, 4)
xreal('5.2359877559829887307E-1')
>>> xreal.SpherHarm(2.1, 3.1, 5.1, 4.1)
xreal('5.3518479027559984754E-1')

An example in Visual Basic

>>> from xlcalcnet import Gpr
>>> Gpr.SpherHarm(2, 3, 5, 4)
Gpr('5.2359877559829887307E-1')
>>> Gpr.SpherHarm(2.1, 3.1, 5.1, 4.1)
Gpr('5.3518479027559984754E-1')

An example with real input:

>>> from xlcalcnet import dec, mpm, gmp, fpm, apm
>>> mpm.dps = 20; l = '10'; m = '7'; theta = '0.1'; phi = '0.2'
>>> \mathrm{d}x = dec.spherharm(l, m, theta, phi); mx = mpm.spherharm(l, m, theta, phi);
>>> gx = gmp.spherharm(l, m, theta, phi)
>>> fx = fpm.spherharm(l, m, theta, phi); ax = apm.spherharm(l, m, theta, phi)
>>> mpm.show([\mathrm{d}x, mx, gx, fx, ax], aligned=True)
dec: -2.5484347403024134998E-7               - 1.4775528280770230150E-6j
mpm: -2.5484347403024134998e-7               - 1.4775528280770230150e-6j
gmp: -2.5484347403024134998E-07              - 1.4775528280770230150E-06j
fpm: -2.54843474030241E-07                   - 1.47755282807702E-06j
apm: -2.5484347403024134998e-7 (-9.509e-19%) - 1.4775528280770230150e-6 (-4.92e-19%)j

An example with complex input:

>>> from xlcalcnet import dec, mpm, gmp, fpm, apm
>>> mpm.dps = 20; n = '10'; m = '7'; theta = '0.1 + 03j'; phi = '0.2 + 04j'
>>> \mathrm{d}z = dec.spherharm(l, m, theta, phi); mz = mpm.spherharm(l, m, theta, phi);
>>> gz = gmp.spherharm(l, m, theta, phi)
>>> fz = fpm.spherharm(l, m, theta, phi); az = apm.spherharm(l, m, theta, phi)
>>> mpm.show([\mathrm{d}z, mz, gz, fz, az],  aligned=True)
dec: -5.0629719914753183582E-2               + 1.2051935898383241506E-1j
mpm: -5.0629719914753183582e-2               + 1.2051935898383241506e-1j
gmp: -5.0629719914753183582E-02              + 1.2051935898383241506E-01j
fpm: -5.06297199147532E-02                   + 1.20519358983832E-01j
apm: -5.0629719914753183582e-2 (-6.797e-19%) + 1.2051935898383241506e-1 (3.075e-19%)j

Toroidal harmonics \(P^m_{l-1/2}(x)\)#

math53.toroidal_plm(l, m, x)#

Returns the toroidal harmonic \(P^m_{l-1/2}(x)\), which is an associated Legendre function \(P^m_l(x)\) of the first kind with half-integer degree. The current implementation is based on Amath and is restricted to \(l,m=0,1; x>1\), using Legendre elliptic integrals or Bulirsch elliptic integrals for numerical evaluation.

See also: https://mathworld.wolfram.com/ToroidalFunction.html

See also: https://dlmf.nist.gov/14.19

See also: Ehrhardt [309] (3.7.18).

An example in Python

>>> from xlcalcnet import xreal
>>> xreal.ToroidalPlm(0, 0, 1.5)
xreal('5.2359877559829887307E-1')
>>> xreal.ToroidalPlm(0, 1, 1.5)
xreal('5.3518479027559984754E-1')
>>> xreal.ToroidalPlm(1, 0, 1.5)
xreal('5.2359877559829887307E-1')
>>> xreal.ToroidalPlm(1, 1, 1.5)
xreal('5.3518479027559984754E-1')

An example in Visual Basic

>>> from xlcalcnet import Gpr
>>> Gpr.ToroidalPlm(0, 0, 1.5)
Gpr('5.2359877559829887307E-1')
>>> Gpr.ToroidalPlm(0, 1, 1.5)
Gpr('5.3518479027559984754E-1')
>>> Gpr.ToroidalPlm(1, 0, 1.5)
Gpr('5.2359877559829887307E-1')
>>> Gpr.ToroidalPlm(1, 1, 1.5)
Gpr('5.3518479027559984754E-1')

Toroidal harmonics \(Q^m_{l-1/2}(x)\)#

math53.toroidal_qlm(l, m, x)#

Returns the toroidal harmonic \(Q^m_{l-1/2}(x)\), which is an associated Legendre function \(Q^m_l(x)\) of the second kind with half-integer degree. The current implementation is based on Amath and is restricted to \(l,m=0,1; x>1\), using Legendre elliptic integrals or Bulirsch elliptic integrals for numerical evaluation.

See also: Majic (2019), https://mathworld.wolfram.com/ToroidalFunction.html

See also: Ehrhardt [309] (3.7.18).

An example in Python

>>> from xlcalcnet import xreal
>>> xreal.ToroidalQlm(0, 0, 1.5)
xreal('5.2359877559829887307E-1')
>>> xreal.ToroidalQlm(0, 1, 1.5)
xreal('5.3518479027559984754E-1')
>>> xreal.ToroidalQlm(1, 0, 1.5)
xreal('5.2359877559829887307E-1')
>>> xreal.ToroidalQlm(1, 1, 1.5)
xreal('5.3518479027559984754E-1')

An example in Visual Basic

>>> from xlcalcnet import Gpr
>>> Gpr.ToroidalQlm(0, 0, 1.5)
Gpr('5.2359877559829887307E-1')
>>> Gpr.ToroidalQlm(0, 1, 1.5)
Gpr('5.3518479027559984754E-1')
>>> Gpr.ToroidalQlm(1, 0, 1.5)
Gpr('5.2359877559829887307E-1')
>>> Gpr.ToroidalQlm(1, 1, 1.5)
Gpr('5.3518479027559984754E-1')

Olver’s associated Legendre function \(Q^m_{l-1/2}(x)\)#

math53.olver_qlm(l, m, x)#

Defined as (see https://dlmf.nist.gov/14.3#E10)

\[\boldsymbol{Q}^{\mu}_{\nu}\left(x\right)=e^{-\mu\pi i}\frac{Q^{\mu}_{\nu}\left(x\right)}{\Gamma\left(\nu+\mu+1\right)}.\]

Can be calculated as

\[\boldsymbol{Q}^{\mu}_{\nu}\left(x\right)=\frac{2^{\nu}\Gamma\left(\nu+1\right)(x+1)^{\mu/2}}{(x-1)^{(\mu/2)+\nu+1}}\mathbf{F}\left(\nu+1,\nu+\mu+1;2\nu+2;\frac{2}{1-x}\right).\]

For hypergeometric representations of Ferrers function and associated Legendre function

see https://dlmf.nist.gov/14.3

previous

Chebyshev, Gegenbauer and Jacobi polynomials

next

Incomplete beta functions

Contents
  • Legendre polynomial (or function) of the first kind, \(P_n(x)\)
    • ctx.legendre_p()
  • Associated Legendre function of the first kind, \(P^m_l(x)\)
    • ctx.legendre_plm()
  • Legendre function of the second kind, \(Q_l(x)\)
    • ctx.legendre_q()
  • Associated Legendre function of the second kind, \(Q^m_l(x)\)
    • ctx.legendre_qlm()
  • Spherical harmonics, \(Y_n^m(\theta, \phi)\)
    • ctx.spherical_harmonic()
  • Toroidal harmonics \(P^m_{l-1/2}(x)\)
    • math53.toroidal_plm()
  • Toroidal harmonics \(Q^m_{l-1/2}(x)\)
    • math53.toroidal_qlm()
  • Olver’s associated Legendre function \(Q^m_{l-1/2}(x)\)
    • math53.olver_qlm()

By Dietrich Hadler

© Copyright 2026, Dietrich Hadler. .

Last updated on Aug 19, 2026.