Function of #cas

LegendreP

The Legendre polynomial Pn in monomials, proved at every real x, and its exact values at rational points.

#cas (LegendreP n x)
gives the Legendre polynomial Pn in the variable x, in monomials with exact rational coefficients, and proves the expansion at every real x.
#cas (LegendreP n q)
gives the exact value of Pn at the rational number q and proves it.
#cas [N d] (LegendreP n q)
gives the exact value of Pn at q with its first d significant digits, truncated toward zero, and proves their decimal bounds.

LegendreP writes a Legendre polynomial in powers of its argument, or gives its exact value at a rational point. Its coefficients are rational, and they come out as exact fractions. The theorem holds at every real x for SymLean’s CAS.Analysis.SpecialFunctions.legendre n, which we define as Mathlib’s shifted Legendre polynomial at (1−x)/2, so it is the classical Pn, with Pn(1)=1.

Details and Options

  • n is a natural number with n≤30, a literal or a closed integer expression.
  • The second argument is a variable or a rational number. The polynomial is written in the variable, which may have any name other than pi, π, Pi, e and E.
  • For the printed polynomial p the theorem is ∀ x : ℝ, (CAS.Analysis.SpecialFunctions.legendre n).eval x = p, from the coefficient formula CAS.Analysis.SpecialFunctions.legendre_eval_eq_sum_coeff. The kernel checks each coefficient, a closed rational computation.
  • legendre n is Mathlib’s shifted Legendre polynomial Polynomial.shiftedLegendre n at (1−x)/2, so Pn(1)=1.
  • At a rational q the theorem is (CAS.Analysis.SpecialFunctions.legendre n).eval q = v, by CAS.Analysis.SpecialFunctions.legendre_eval_ratCast. With [N d] it adds the first d significant digits of v, truncated toward zero, and their decimal bounds. The report prints v = digits when the digits are exact and v ≈ digits otherwise.
  • With [N d], 1≤d≤2000, as for N.
  • #cas [expand] (LegendreP n x) prints the same polynomial as #cas (LegendreP n x).
  • There are no options.

Examples (11)#

Basic Examples (2)

P3 in monomials, with the theorem at every real x:

In[1]:=
#cas (LegendreP 3 x)
Out[1]=

polynomial with exact rational coefficients

52x3−32x
5/2*x^3 - 3/2*x
Input (polynomial in x)
LegendreP 3 x

Checked by Lean’s kernel: Monomial expansion of the Legendre polynomial

∀ (x : ℝ), Polynomial.eval x (CAS.Analysis.SpecialFunctions.legendre 3) = 5 / 2 * x ^ 3 - 3 / 2 * x

from CAS.Analysis.SpecialFunctions.legendre_eval_eq_sum_coeff

The certificate: 1 checked step
  1. Monomial expansion of the Legendre polynomial

    ∀ (x : ℝ), Polynomial.eval x (CAS.Analysis.SpecialFunctions.legendre 3) = 5 / 2 * x ^ 3 - 3 / 2 * x

    Checked by Lean’s kernel · CAS.Analysis.SpecialFunctions.legendre_eval_eq_sum_coeff

The computation
  • Checked coefficients

    Coefficients of x^0, …, x^3: [0, -3/2, 0, 5/2]
    Guarantee: the displayed polynomial equals P_3 at every real x

The exact value at a rational point:

In[2]:=
#cas (LegendreP 2 (1/2))
Out[2]=

exact rational value

−18
-1/8
Domain
Legendre polynomial at a rational point

Checked by Lean’s kernel: Exact value of the Legendre polynomial

Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 2) = -(1 / 8)

from CAS.Analysis.SpecialFunctions.legendre_eval_ratCast

The certificate: 1 checked step
  1. Exact value of the Legendre polynomial

    Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 2) = -(1 / 8)

    Checked by Lean’s kernel · CAS.Analysis.SpecialFunctions.legendre_eval_ratCast

Scope (3)

A higher degree, with every coefficient in lowest terms:

In[3]:=
#cas (LegendreP 10 x)
Out[3]=

polynomial with exact rational coefficients

46189256x10−109395256x8+45045128x6−15015128x4+3465256x2−63256
46189/256*x^10 - 109395/256*x^8 + 45045/128*x^6 - 15015/128*x^4 + 3465/256*x^2 - 63/256
Input (polynomial in x)
LegendreP 10 x

Checked by Lean’s kernel: Monomial expansion of the Legendre polynomial

∀ (x : ℝ),
  Polynomial.eval x (CAS.Analysis.SpecialFunctions.legendre 10) =
    46189 / 256 * x ^ 10 - 109395 / 256 * x ^ 8 + 45045 / 128 * x ^ 6 - 15015 / 128 * x ^ 4 +
        3465 / 256 * x ^ 2 -
      63 / 256

from CAS.Analysis.SpecialFunctions.legendre_eval_eq_sum_coeff

The certificate: 1 checked step
  1. Monomial expansion of the Legendre polynomial

    ∀ (x : ℝ),
      Polynomial.eval x (CAS.Analysis.SpecialFunctions.legendre 10) =
        46189 / 256 * x ^ 10 - 109395 / 256 * x ^ 8 + 45045 / 128 * x ^ 6 - 15015 / 128 * x ^ 4 +
            3465 / 256 * x ^ 2 -
          63 / 256

    Checked by Lean’s kernel · CAS.Analysis.SpecialFunctions.legendre_eval_eq_sum_coeff

The computation
  • Checked coefficients

    Coefficients of x^0, …, x^10: [-63/256, 0, 3465/256, 0, -15015/128, 0, 45045/128, 0, -109395/256, 0, 46189/256]
    Guarantee: the displayed polynomial equals P_10 at every real x

#cas [expand] prints the same polynomial as #cas alone, here P5:

In[4]:=
#cas [expand] (LegendreP 5 x)
Out[4]=

polynomial with exact rational coefficients

638x5−354x3+158x
63/8*x^5 - 35/4*x^3 + 15/8*x
Input (polynomial in x)
LegendreP 5 x

Checked by Lean’s kernel: Monomial expansion of the Legendre polynomial

∀ (x : ℝ),
  Polynomial.eval x (CAS.Analysis.SpecialFunctions.legendre 5) = 63 / 8 * x ^ 5 - 35 / 4 * x ^ 3 + 15 / 8 * x

from CAS.Analysis.SpecialFunctions.legendre_eval_eq_sum_coeff

The certificate: 1 checked step
  1. Monomial expansion of the Legendre polynomial

    ∀ (x : ℝ),
      Polynomial.eval x (CAS.Analysis.SpecialFunctions.legendre 5) = 63 / 8 * x ^ 5 - 35 / 4 * x ^ 3 + 15 / 8 * x

    Checked by Lean’s kernel · CAS.Analysis.SpecialFunctions.legendre_eval_eq_sum_coeff

The computation
  • Checked coefficients

    Coefficients of x^0, …, x^5: [0, 15/8, 0, -35/4, 0, 63/8]
    Guarantee: the displayed polynomial equals P_5 at every real x

[N d] adds the first digits of the exact value, here exact:

In[5]:=
#cas [N 10] (LegendreP 2 (1/2))
Out[5]=

exact rational value and its first 10 significant digits, truncated

−18=−0.1250000000
-1/8 = -0.1250000000
Domain
Legendre polynomial at a rational point

Checked by Lean’s kernel: Exact value and digits of the Legendre polynomial

Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 2) = -(1 / 8) ∧
  -(1250000000 + 1) / 10 ^ 10 < Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 2) ∧
    Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 2) ≤ -1250000000 / 10 ^ 10

from CAS.Analysis.SpecialFunctions.legendre_eval_ratCast

The certificate: 1 checked step
  1. Exact value and digits of the Legendre polynomial

    Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 2) = -(1 / 8) ∧
      -(1250000000 + 1) / 10 ^ 10 < Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 2) ∧
        Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 2) ≤ -1250000000 / 10 ^ 10

    Checked by Lean’s kernel · CAS.Analysis.SpecialFunctions.legendre_eval_ratCast

Applications (1)

A proof can take the printed theorem as a hypothesis and specialize it, here at x=12. Only the three standard axioms are used:

In[6]:=
theorem legendre_three_at_half
    (h : ∀ x : ℝ,
      (CAS.Analysis.SpecialFunctions.legendre 3).eval x = 5 / 2 * x ^ 3 - 3 / 2 * x) :
    (CAS.Analysis.SpecialFunctions.legendre 3).eval (1 / 2) = -7 / 16 := by
  rw [h]
  norm_num

#print axioms legendre_three_at_half
Out[6]=

legendre_three_at_half depends on the axioms propext, Classical.choice, Quot.sound.

Properties and Relations (1)

The polynomial P3=52x3−32x at 12 is 516−34=−716, the value of the theorem above, and the call at the point agrees:

In[7]:=
#cas [N 5] (LegendreP 3 (1/2))
Out[7]=

exact rational value and its first 5 significant digits, truncated

−716=−0.43750
-7/16 = -0.43750
Domain
Legendre polynomial at a rational point

Checked by Lean’s kernel: Exact value and digits of the Legendre polynomial

Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 3) = -(7 / 16) ∧
  -(43750 + 1) / 10 ^ 5 < Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 3) ∧
    Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 3) ≤ -43750 / 10 ^ 5

from CAS.Analysis.SpecialFunctions.legendre_eval_ratCast

The certificate: 1 checked step
  1. Exact value and digits of the Legendre polynomial

    Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 3) = -(7 / 16) ∧
      -(43750 + 1) / 10 ^ 5 < Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 3) ∧
        Polynomial.eval (1 / 2) (CAS.Analysis.SpecialFunctions.legendre 3) ≤ -43750 / 10 ^ 5

    Checked by Lean’s kernel · CAS.Analysis.SpecialFunctions.legendre_eval_ratCast

Possible Issues (3)

The degree is at most 30. The bound keeps the rational coefficients short, and legendre n is defined at every degree:

In[8]:=
#cas (LegendreP 31 x)
Out[8]=

Error

LegendreP accepts degrees up to 30

A call computes with numbers of at most 10000 digits, and P2(105000)=3·1010000−12 is larger:

In[9]:=
#cas (LegendreP 2 (10 ^ 5000))
Out[9]=

Error

LegendreP: evaluating `LegendreP 2 (10 ^ 5000)` needs a number with more than 10000 digits, the most that a call computes

LegendreP is a call, not a mode, and the message lists its three forms:

In[10]:=
#cas [LegendreP 5]
Out[10]=

Error

`LegendreP` is no mode of `#cas`; write `#cas (LegendreP n x)`, `#cas [expand] (LegendreP n x)` or `#cas [N d] (LegendreP n x)`

Neat Examples (1)

P5 takes the value 13 at 13, a repeating decimal, so the report prints ≈:

In[11]:=
#cas [N 20] (LegendreP 5 (1 / 3))
Out[11]=

exact rational value and its first 20 significant digits, truncated

13≈0.33333333333333333333
1/3 ≈ 0.33333333333333333333
Domain
Legendre polynomial at a rational point

Checked by Lean’s kernel: Exact value and digits of the Legendre polynomial

Polynomial.eval (1 / 3) (CAS.Analysis.SpecialFunctions.legendre 5) = 1 / 3 ∧
  33333333333333333333 / 10 ^ 20 ≤ Polynomial.eval (1 / 3) (CAS.Analysis.SpecialFunctions.legendre 5) ∧
    Polynomial.eval (1 / 3) (CAS.Analysis.SpecialFunctions.legendre 5) < (33333333333333333333 + 1) / 10 ^ 20

from CAS.Analysis.SpecialFunctions.legendre_eval_ratCast

The certificate: 1 checked step
  1. Exact value and digits of the Legendre polynomial

    Polynomial.eval (1 / 3) (CAS.Analysis.SpecialFunctions.legendre 5) = 1 / 3 ∧
      33333333333333333333 / 10 ^ 20 ≤ Polynomial.eval (1 / 3) (CAS.Analysis.SpecialFunctions.legendre 5) ∧
        Polynomial.eval (1 / 3) (CAS.Analysis.SpecialFunctions.legendre 5) < (33333333333333333333 + 1) / 10 ^ 20

    Checked by Lean’s kernel · CAS.Analysis.SpecialFunctions.legendre_eval_ratCast

See Also

ChebyshevT · HermiteHe · BernoulliB · expand · N