Mode of #cas

series

A Taylor or Laurent expansion at a rational point, with exact coefficients and a little-o remainder theorem.

#cas [series x a n] e
gives the Taylor polynomial of e of degree n at the rational point a, with exact coefficients, and proves that the remainder is o((x−a)n). When e is a quotient whose denominator vanishes at a, it gives the Laurent series instead.

series computes the first terms of an expansion from the derivatives at the expansion point, with exact rational coefficients. The theorem is a little-o statement about Mathlib’s Asymptotics.IsLittleO. It is the precise form of what we usually write as “e=c0+c1(x−a)+…+cn(x−a)n+o((x−a)n)”.

Details and Options

  • For the printed coefficients ck the theorem is (fun x ↦ e - ∑ k ∈ Finset.range (n + 1), c k * (x - a) ^ k) =o[𝓝 a] fun x ↦ (x - a) ^ n, with the sum written out.
  • For a quotient g/h whose denominator vanishes at a to order m, the sum runs over the powers from −m to n, and the remainder holds on the punctured neighborhood 𝓝[≠] a. When the singularity is removable, the answer is a Taylor series again.
  • The order n is at most 12, and so is the order m to which a denominator vanishes. e uses the functions of derive and no other variable.
  • The center a is a rational literal such as 1/2, -1/2 or 1/10000, or a closed expression in parentheses with a rational value, such as (1/2 - 1/3). A function value such as (sqrt 4) is refused, even when it is rational.
  • The coefficients are exact, so every function must sit at a point where its value is rational: sin, cos, exp, atan and asin at 0, log at 1, and square roots of rational squares. acos has the value 0 at 1 but no derivative there, so it is not expanded at 1.
  • There are no options. The tactic cas does not prove the little-o statement, so a proof takes the printed theorem as a hypothesis.

Examples (18)#

Basic Examples (2)

The exponential at 0, with the theorem about the remainder:

In[1]:=
#cas [series x 0 6] (exp x)
Out[1]=

Taylor polynomial with exact coefficients

1+x+12x2+16x3+124x4+1120x5+1720x6+o(x6)
1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + o(x^6)
Domain
x → 0

Checked by Lean’s kernel: Taylor expansion with a little-o remainder

(fun x ↦
    Real.exp x -
      (1 + x + 1 / 2 * x ^ 2 + 1 / 6 * x ^ 3 + 1 / 24 * x ^ 4 + 1 / 120 * x ^ 5 + 1 / 720 * x ^ 6)) =o[nhds 0]
  fun x ↦ x ^ 6
The certificate: 1 checked step
  1. Taylor expansion with a little-o remainder

    (fun x ↦
        Real.exp x -
          (1 + x + 1 / 2 * x ^ 2 + 1 / 6 * x ^ 3 + 1 / 24 * x ^ 4 + 1 / 120 * x ^ 5 + 1 / 720 * x ^ 6)) =o[nhds 0]
      fun x ↦ x ^ 6

    Checked by Lean’s kernel

The computation
  • Checked coefficients

    Coefficients of (x - 0)^0, …, ^6: [1, 1, 1/2, 1/6, 1/24, 1/120, 1/720]

A Laurent series. 1/sinx has a pole of order 1 at 0:

In[2]:=
#cas [series x 0 3] (1 / sin x)
Out[2]=

Laurent series with a pole of order 1

1x+16x+7360x3+o(x3)
1/x + 1/6*x + 7/360*x^3 + o(x^3)
Domain
x → 0, x ≠ 0

Checked by Lean’s kernel: Laurent expansion with a little-o remainder

(fun x ↦ 1 / Real.sin x - (x⁻¹ + 1 / 6 * x + 7 / 360 * x ^ 3)) =o[nhdsWithin 0 {0}ᶜ] fun x ↦ x ^ 3
The certificate: 1 checked step
  1. Laurent expansion with a little-o remainder

    (fun x ↦ 1 / Real.sin x - (x⁻¹ + 1 / 6 * x + 7 / 360 * x ^ 3)) =o[nhdsWithin 0 {0}ᶜ] fun x ↦ x ^ 3

    Checked by Lean’s kernel

The computation
  • Series division

    the denominator vanishes to order 1; numerator coefficients [1,
     0,
     0,
     0,
     0], denominator coefficients [0, 1, 0, -1/6, 0, 1/120]

Scope (8)

The sine, to order 7:

In[3]:=
#cas [series x 0 7] (sin x)
Out[3]=

Taylor polynomial with exact coefficients

x−16x3+1120x5−15040x7+o(x7)
x - 1/6*x^3 + 1/120*x^5 - 1/5040*x^7 + o(x^7)
Domain
x → 0

Checked by Lean’s kernel: Taylor expansion with a little-o remainder

(fun x ↦ Real.sin x - (x - 1 / 6 * x ^ 3 + 1 / 120 * x ^ 5 - 1 / 5040 * x ^ 7)) =o[nhds 0] fun x ↦
  x ^ 7
The certificate: 1 checked step
  1. Taylor expansion with a little-o remainder

    (fun x ↦ Real.sin x - (x - 1 / 6 * x ^ 3 + 1 / 120 * x ^ 5 - 1 / 5040 * x ^ 7)) =o[nhds 0] fun x ↦
      x ^ 7

    Checked by Lean’s kernel

The computation
  • Checked coefficients

    Coefficients of (x - 0)^0, …, ^7: [0, 1, 0, -1/6, 0, 1/120, 0, -1/5040]

The logarithm at 1, where its value is rational:

In[4]:=
#cas [series x 1 4] (log x)
Out[4]=

Taylor polynomial with exact coefficients

x−1−12(x−1)2+13(x−1)3−14(x−1)4+o((x−1)4)
x - 1 - 1/2*(x - 1)^2 + 1/3*(x - 1)^3 - 1/4*(x - 1)^4 + o((x - 1)^4)
Domain
x → 1

Checked by Lean’s kernel: Taylor expansion with a little-o remainder

(fun x ↦
    Real.log x - (x - 1 - 1 / 2 * (x - 1) ^ 2 + 1 / 3 * (x - 1) ^ 3 - 1 / 4 * (x - 1) ^ 4)) =o[nhds 1]
  fun x ↦ (x - 1) ^ 4
The certificate: 1 checked step
  1. Taylor expansion with a little-o remainder

    (fun x ↦
        Real.log x - (x - 1 - 1 / 2 * (x - 1) ^ 2 + 1 / 3 * (x - 1) ^ 3 - 1 / 4 * (x - 1) ^ 4)) =o[nhds 1]
      fun x ↦ (x - 1) ^ 4

    Checked by Lean’s kernel

The computation
  • Checked coefficients

    Coefficients of (x - 1)^0, …, ^4: [0, 1, -1/2, 1/3, -1/4]

A composition:

In[5]:=
#cas [series x 0 6] (exp (sin x))
Out[5]=

Taylor polynomial with exact coefficients

1+x+12x2−18x4−115x5−1240x6+o(x6)
1 + x + 1/2*x^2 - 1/8*x^4 - 1/15*x^5 - 1/240*x^6 + o(x^6)
Domain
x → 0

Checked by Lean’s kernel: Taylor expansion with a little-o remainder

(fun x ↦
    Real.exp (Real.sin x) -
      (1 + x + 1 / 2 * x ^ 2 - 1 / 8 * x ^ 4 - 1 / 15 * x ^ 5 - 1 / 240 * x ^ 6)) =o[nhds 0]
  fun x ↦ x ^ 6
The certificate: 1 checked step
  1. Taylor expansion with a little-o remainder

    (fun x ↦
        Real.exp (Real.sin x) -
          (1 + x + 1 / 2 * x ^ 2 - 1 / 8 * x ^ 4 - 1 / 15 * x ^ 5 - 1 / 240 * x ^ 6)) =o[nhds 0]
      fun x ↦ x ^ 6

    Checked by Lean’s kernel

The computation
  • Checked coefficients

    Coefficients of (x - 0)^0, …, ^6: [1, 1, 1/2, 0, -1/8, -1/15, -1/240]

A negative rational center:

In[6]:=
#cas [series x -1/2 2] (1 / (1 - x))
Out[6]=

Taylor polynomial with exact coefficients

23+49(x+12)+827(x+12)2+o((x+12)2)
2/3 + 4/9*(x + 1/2) + 8/27*(x + 1/2)^2 + o((x + 1/2)^2)
Domain
x → -1/2

Checked by Lean’s kernel: Taylor expansion with a little-o remainder

(fun x ↦ 1 / (1 - x) - (2 / 3 + 4 / 9 * (x + 1 / 2) + 8 / 27 * (x + 1 / 2) ^ 2)) =o[nhds (-1 / 2)]
  fun x ↦ (x + 1 / 2) ^ 2
The certificate: 1 checked step
  1. Taylor expansion with a little-o remainder

    (fun x ↦ 1 / (1 - x) - (2 / 3 + 4 / 9 * (x + 1 / 2) + 8 / 27 * (x + 1 / 2) ^ 2)) =o[nhds (-1 / 2)]
      fun x ↦ (x + 1 / 2) ^ 2

    Checked by Lean’s kernel

The computation
  • Checked coefficients

    Coefficients of (x + 1/2)^0, …, ^2: [2/3, 4/9, 8/27]

A center close to the singularity of the square root. The theorem only needs the derivatives at the point:

In[7]:=
#cas [series x 1/10000 2] (sqrt x)
Out[7]=

Taylor polynomial with exact coefficients

1100+50(x−110000)−125000(x−110000)2+o((x−110000)2)
1/100 + 50*(x - 1/10000) - 125000*(x - 1/10000)^2 + o((x - 1/10000)^2)
Domain
x → 1/10000

Checked by Lean’s kernel: Taylor expansion with a little-o remainder

(fun x ↦ √x - (1 / 100 + 50 * (x - 1 / 10000) - 125000 * (x - 1 / 10000) ^ 2)) =o[nhds (1 / 10000)]
  fun x ↦ (x - 1 / 10000) ^ 2
The certificate: 1 checked step
  1. Taylor expansion with a little-o remainder

    (fun x ↦ √x - (1 / 100 + 50 * (x - 1 / 10000) - 125000 * (x - 1 / 10000) ^ 2)) =o[nhds (1 / 10000)]
      fun x ↦ (x - 1 / 10000) ^ 2

    Checked by Lean’s kernel

The computation
  • Checked coefficients

    Coefficients of (x - 1/10000)^0, …, ^2: [1/100, 50, -125000]

A pole of order 2:

In[8]:=
#cas [series x 0 2] (1 / sin x ^ 2)
Out[8]=

Laurent series with a pole of order 2

1x2+13+115x2+o(x2)
1/x^2 + 1/3 + 1/15*x^2 + o(x^2)
Domain
x → 0, x ≠ 0

Checked by Lean’s kernel: Laurent expansion with a little-o remainder

(fun x ↦ 1 / Real.sin x ^ 2 - ((x ^ 2)⁻¹ + 1 / 3 + 1 / 15 * x ^ 2)) =o[nhdsWithin 0 {0}ᶜ] fun x ↦
  x ^ 2
The certificate: 1 checked step
  1. Laurent expansion with a little-o remainder

    (fun x ↦ 1 / Real.sin x ^ 2 - ((x ^ 2)⁻¹ + 1 / 3 + 1 / 15 * x ^ 2)) =o[nhdsWithin 0 {0}ᶜ] fun x ↦
      x ^ 2

    Checked by Lean’s kernel

The computation
  • Series division

    the denominator vanishes to order 2; numerator coefficients [1,
     0,
     0,
     0,
     0], denominator coefficients [0, 0, 1, 0, -1/3, 0, 2/45]

A pole away from 0. The answer is in powers of x−1:

In[9]:=
#cas [series x 1 2] (1 / (x^2 - 1))
Out[9]=

Laurent series with a pole of order 1

12(x−1)−14+18(x−1)−116(x−1)2+o((x−1)2)
1/(2*(x - 1)) - 1/4 + 1/8*(x - 1) - 1/16*(x - 1)^2 + o((x - 1)^2)
Domain
x → 1, x ≠ 1

Checked by Lean’s kernel: Laurent expansion with a little-o remainder

(fun x ↦
    1 / (x ^ 2 - 1) -
      (1 / 2 * (x - 1)⁻¹ - 1 / 4 + 1 / 8 * (x - 1) - 1 / 16 * (x - 1) ^ 2)) =o[nhdsWithin 1 {1}ᶜ]
  fun x ↦ (x - 1) ^ 2
The certificate: 1 checked step
  1. Laurent expansion with a little-o remainder

    (fun x ↦
        1 / (x ^ 2 - 1) -
          (1 / 2 * (x - 1)⁻¹ - 1 / 4 + 1 / 8 * (x - 1) - 1 / 16 * (x - 1) ^ 2)) =o[nhdsWithin 1 {1}ᶜ]
      fun x ↦ (x - 1) ^ 2

    Checked by Lean’s kernel

The computation
  • Series division

    the denominator vanishes to order 1; numerator coefficients [1, 0, 0, 0], denominator coefficients [0, 2, 1, 0, 0]

A removable singularity gives a Taylor series:

In[10]:=
#cas [series x 0 4] (sin x / x)
Out[10]=

Taylor series of a removable singularity

1−16x2+1120x4+o(x4)
1 - 1/6*x^2 + 1/120*x^4 + o(x^4)
Domain
x → 0, x ≠ 0

Checked by Lean’s kernel: Laurent expansion with a little-o remainder

(fun x ↦ Real.sin x / x - (1 - 1 / 6 * x ^ 2 + 1 / 120 * x ^ 4)) =o[nhdsWithin 0 {0}ᶜ] fun x ↦
  x ^ 4
The certificate: 1 checked step
  1. Laurent expansion with a little-o remainder

    (fun x ↦ Real.sin x / x - (1 - 1 / 6 * x ^ 2 + 1 / 120 * x ^ 4)) =o[nhdsWithin 0 {0}ᶜ] fun x ↦
      x ^ 4

    Checked by Lean’s kernel

The computation
  • Series division

    the denominator vanishes to order 1; numerator coefficients [0,
     1,
     0,
     -1/6,
     0,
     1/120], denominator coefficients [0, 1, 0, 0, 0, 0, 0]

Applications (1)

The little-o statement in a proof. From the printed theorem for sinx to order 3, the quotient by x3 tends to 0. Only the three standard axioms are used:

In[11]:=
open Filter Topology in
theorem series_sin_remainder
    (h : (fun x : ℝ ↦ Real.sin x - (x - 1 / 6 * x ^ 3)) =o[𝓝 0] fun x ↦ x ^ 3) :
    Tendsto (fun x : ℝ ↦ (Real.sin x - (x - 1 / 6 * x ^ 3)) / x ^ 3) (𝓝 0) (𝓝 0) :=
  h.tendsto_div_nhds_zero

#print axioms series_sin_remainder
Out[11]=

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

Properties and Relations (2)

The coefficient of x2 in the series of ex is the limit of (ex−1−x)/x2 at 0, which limit proves:

In[12]:=
#cas [limit x → 0] ((exp x - 1 - x) / x^2)
Out[12]=

exact limit

12
1/2
Domain
x → 0, x ≠ 0

Checked by Lean’s kernel: Limit from the leading terms of order 2

Filter.Tendsto (fun x ↦ (Real.exp x - 1 - x) / x ^ 2) (nhdsWithin 0 {0}ᶜ) (nhds (1 / 2))
The certificate: 1 checked step
  1. Limit from the leading terms of order 2

    Filter.Tendsto (fun x ↦ (Real.exp x - 1 - x) / x ^ 2) (nhdsWithin 0 {0}ᶜ) (nhds (1 / 2))

    Checked by Lean’s kernel

The computation
  • Leading terms

    Numerator 1/2 (x - a)^2, denominator 1 (x - a)^2 (not proof)

The series of 1/(1−x) at 0 is the geometric series:

In[13]:=
#cas [series x 0 5] (1 / (1 - x))
Out[13]=

Taylor polynomial with exact coefficients

1+x+x2+x3+x4+x5+o(x5)
1 + x + x^2 + x^3 + x^4 + x^5 + o(x^5)
Domain
x → 0

Checked by Lean’s kernel: Taylor expansion with a little-o remainder

(fun x ↦ 1 / (1 - x) - (1 + x + x ^ 2 + x ^ 3 + x ^ 4 + x ^ 5)) =o[nhds 0] fun x ↦ x ^ 5
The certificate: 1 checked step
  1. Taylor expansion with a little-o remainder

    (fun x ↦ 1 / (1 - x) - (1 + x + x ^ 2 + x ^ 3 + x ^ 4 + x ^ 5)) =o[nhds 0] fun x ↦ x ^ 5

    Checked by Lean’s kernel

The computation
  • Checked coefficients

    Coefficients of (x - 0)^0, …, ^5: [1, 1, 1, 1, 1, 1]

Possible Issues (3)

The expression must be smooth at the center. |x| has no derivative at 0:

In[14]:=
#cas [series x 0 3] (abs x)
Out[14]=

Error

series: the domain checker did not certify that the expression and its derivatives through order 3 are defined at 0

The coefficients must be exact, and the logarithm has a known value at 1, not at 0. The message lists the known values:

In[15]:=
#cas [series x 0 3] (log x)
Out[15]=

Error

series: the derivative of order 0 at 0 is not an exact rational number (exact values are known for sin, cos, exp, atan, asin at 0, log at 1, and square roots of rational squares)

The order is at most 12:

In[16]:=
#cas [series x 0 13] (sin x)
Out[16]=

Error

series accepts orders up to 12

Neat Examples (2)

The coefficients of 1/(ex−1) are the Bernoulli numbers divided by factorials:

In[17]:=
#cas [series x 0 3] (1 / (exp x - 1))
Out[17]=

Laurent series with a pole of order 1

1x−12+112x−1720x3+o(x3)
1/x - 1/2 + 1/12*x - 1/720*x^3 + o(x^3)
Domain
x → 0, x ≠ 0

Checked by Lean’s kernel: Laurent expansion with a little-o remainder

(fun x ↦ 1 / (Real.exp x - 1) - (x⁻¹ - 1 / 2 + 1 / 12 * x - 1 / 720 * x ^ 3)) =o[nhdsWithin 0 {0}ᶜ]
  fun x ↦ x ^ 3
The certificate: 1 checked step
  1. Laurent expansion with a little-o remainder

    (fun x ↦ 1 / (Real.exp x - 1) - (x⁻¹ - 1 / 2 + 1 / 12 * x - 1 / 720 * x ^ 3)) =o[nhdsWithin 0 {0}ᶜ]
      fun x ↦ x ^ 3

    Checked by Lean’s kernel

The computation
  • Series division

    the denominator vanishes to order 1; numerator coefficients [1,
     0,
     0,
     0,
     0], denominator coefficients [0, 1, 1/2, 1/6, 1/24, 1/120]

The cotangent:

In[18]:=
#cas [series x 0 3] (cos x / sin x)
Out[18]=

Laurent series with a pole of order 1

1x−13x−145x3+o(x3)
1/x - 1/3*x - 1/45*x^3 + o(x^3)
Domain
x → 0, x ≠ 0

Checked by Lean’s kernel: Laurent expansion with a little-o remainder

(fun x ↦ Real.cos x / Real.sin x - (x⁻¹ - 1 / 3 * x - 1 / 45 * x ^ 3)) =o[nhdsWithin 0 {0}ᶜ]
  fun x ↦ x ^ 3
The certificate: 1 checked step
  1. Laurent expansion with a little-o remainder

    (fun x ↦ Real.cos x / Real.sin x - (x⁻¹ - 1 / 3 * x - 1 / 45 * x ^ 3)) =o[nhdsWithin 0 {0}ᶜ]
      fun x ↦ x ^ 3

    Checked by Lean’s kernel

The computation
  • Series division

    the denominator vanishes to order 1; numerator coefficients [1,
     0,
     -1/2,
     0,
     1/24], denominator coefficients [0, 1, 0, -1/6, 0, 1/120]

See Also

limit · derive · sum · integrate