Mode of #cas

limit

A limit at a rational point, from one side, or at ±∞, with a theorem about Mathlib’s Filter.Tendsto.

#cas [limit x → a] e
computes the limit of e, finite or infinite, as x tends to the rational number a, and proves it with the filter 𝓝 a, or 𝓝[≠] a when e is a quotient whose denominator vanishes at a.
#cas [limit x → a from above] e
gives the limit from the right, with the filter 𝓝[>] a. With from below it gives the limit from the left, with 𝓝[<] a.
#cas [limit x → ∞] e
gives the limit as x tends to ∞, with the filter atTop.
#cas [limit x → -∞] e
gives the limit as x tends to −∞, with the filter atBot.

limit computes a limit and proves it as a Filter.Tendsto statement, which is how Mathlib states limits. A statement Tendsto f l (𝓝 L) says that f tends to L along the filter l, which is 𝓝 a for x→a, 𝓝[≠] a for x→a with x≠a, 𝓝[>] a and 𝓝[<] a from the right and from the left, and atTop and atBot for x→∞ and x→−∞. Where the expression is defined, the answer is simple: the limit is its value. The interesting case is a quotient whose denominator vanishes. There SymLean does what you would do by hand with l’Hôpital’s rule. It takes the first derivatives of the numerator and the denominator that don’t vanish, and their values have to be exact rational numbers.

At ±∞ the expression is rewritten in t=1/x and expanded at t=0. Expressions with exp, log, sqrt, atan, π or e first go through a comparison of growth rates, and when that comparison proves the limit, the label of the answer says “limit from the dominant term”.

Details and Options

  • At a point where e is valid, the limit is the value L and the theorem is Tendsto (fun x ↦ e) (𝓝 a) (𝓝 L). The theorem can leave L as e at a: under Scope it has √(1 / 10000) where the report prints 1/100.
  • For a quotient g / h with h(a)=0, the theorem is Tendsto (fun x ↦ g / h) (𝓝[≠] a) (𝓝 L). The derivatives of g and h at a must have exact rational values. Exact values are known for sin, cos, exp, atan and asin at the argument 0, for log at the argument 1, and for square roots of rational squares. The first derivative of h that does not vanish at a must have order at most 12.
  • At a pole the theorem has atTop or atBot in place of 𝓝 L, for the limits ∞ and −∞. At a pole of odd order the two sides differ, the answer is Indeterminate, and the theorem is the conjunction of the two one-sided limits.
  • The point a is a closed expression with a rational value, built from integers, fractions and decimals by +, -, *, / and integer powers, such as 1/10000, -1/2 or 0.25. A function value such as sqrt 4 is refused, even when its value is rational, and so is π.
  • e uses the functions of derive. The domain checker certifies that e, or the numerator and the denominator of a quotient, are defined at a, and the proof extends this to a neighborhood of a.
  • There are no options. In a proof, cas proves these limits as goals, with all six filters.

Examples (20)#

Basic Examples (3)

The classical one, with the theorem on the punctured neighborhood of 0:

In[1]:=
#cas [limit x → 0] (sin x / x)
Out[1]=

exact limit

1
Domain
x → 0, x ≠ 0

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

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

    Filter.Tendsto (fun x ↦ Real.sin x / x) (nhdsWithin 0 {0}ᶜ) (nhds 1)

    Checked by Lean’s kernel

The computation
  • Leading terms

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

A rational function at ∞. The terms of order 0 in t=1/x give the limit:

In[2]:=
#cas [limit x → ∞] ((x^2 + 1) / (2*x^2 - 3))
Out[2]=

exact limit from the terms of order 0

12
1/2
Domain
x → ∞

Checked by Lean’s kernel: Limit

Filter.Tendsto (fun x ↦ (x ^ 2 + 1) / (2 * x ^ 2 - 3)) Filter.atTop (nhds (1 / 2))
The certificate: 1 checked step
  1. Limit

    Filter.Tendsto (fun x ↦ (x ^ 2 + 1) / (2 * x ^ 2 - 3)) Filter.atTop (nhds (1 / 2))

    Checked by Lean’s kernel


A one-sided infinite limit:

In[3]:=
#cas [limit x → 0 from above] (1 / x)
Out[3]=

infinite limit at a pole of order 1

∞
∞
Domain
x → 0⁺

Checked by Lean’s kernel: Limit

Filter.Tendsto (fun x ↦ 1 / x) (nhdsWithin 0 (Set.Ioi 0)) Filter.atTop
The certificate: 1 checked step
  1. Limit

    Filter.Tendsto (fun x ↦ 1 / x) (nhdsWithin 0 (Set.Ioi 0)) Filter.atTop

    Checked by Lean’s kernel

Scope (7)

A quotient whose denominator vanishes. The first derivatives that do not vanish give the limit. They have order 1 in the first example and order 2 in the second:

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

exact limit

2
Domain
x → 1, x ≠ 1

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

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

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

    Checked by Lean’s kernel

The computation
  • Leading terms

    Numerator 2 (x - a)^1, denominator 1 (x - a)^1 (not proof)
In[5]:=
#cas [limit x → 0] ((1 - cos x) / x^2)
Out[5]=

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 ↦ (1 - Real.cos 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 ↦ (1 - Real.cos 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)

Where the expression is defined, the limit is its value. Here the point is close to the edge of the domain of the square root:

In[6]:=
#cas [limit x → 1/10000] (sqrt x)
Out[6]=

limit, the value at the point

1100
1/100
Domain
x → 1/10000

Checked by Lean’s kernel: Continuity at a point of validity

Filter.Tendsto (fun x ↦ √x) (nhds (1 / 10000)) (nhds √(1 / 10000))
The certificate: 1 checked step
  1. Continuity at a point of validity

    Filter.Tendsto (fun x ↦ √x) (nhds (1 / 10000)) (nhds √(1 / 10000))

    Checked by Lean’s kernel


At ∞, xsin(1/x) is sint/t in t=1/x:

In[7]:=
#cas [limit x → ∞] (x * sin (1 / x))
Out[7]=

exact limit from the terms of order 1

1
Domain
x → ∞

Checked by Lean’s kernel: Limit

Filter.Tendsto (fun x ↦ x * Real.sin (1 / x)) Filter.atTop (nhds 1)
The certificate: 1 checked step
  1. Limit

    Filter.Tendsto (fun x ↦ x * Real.sin (1 / x)) Filter.atTop (nhds 1)

    Checked by Lean’s kernel


An infinite limit at ∞. In t=1/x the expression has a pole of order 2:

In[8]:=
#cas [limit x → ∞] (x^3 / (x + 1))
Out[8]=

infinite limit at a pole of order 2

∞
∞
Domain
x → ∞

Checked by Lean’s kernel: Limit

Filter.Tendsto (fun x ↦ x ^ 3 / (x + 1)) Filter.atTop Filter.atTop
The certificate: 1 checked step
  1. Limit

    Filter.Tendsto (fun x ↦ x ^ 3 / (x + 1)) Filter.atTop Filter.atTop

    Checked by Lean’s kernel


Exponentials and arctangents at ±∞, by the dominant term:

In[9]:=
#cas [limit x → ∞] (x^2 * exp (-x))
Out[9]=

limit from the dominant term

0
Domain
x → ∞

Checked by Lean’s kernel: Limit by asymptotic comparison

Filter.Tendsto (fun x ↦ x ^ 2 * Real.exp (-x)) Filter.atTop (nhds 0)
The certificate: 1 checked step
  1. Limit by asymptotic comparison

    Filter.Tendsto (fun x ↦ x ^ 2 * Real.exp (-x)) Filter.atTop (nhds 0)

    Checked by Lean’s kernel

The computation
  • Asymptotic equivalent

    f ~ c x^2 e^(-1 x) (log x)^0
In[10]:=
#cas [limit x → ∞] (atan x)
Out[10]=

limit from the dominant term

π2
pi/2
Domain
x → ∞

Checked by Lean’s kernel: Limit by asymptotic comparison

Filter.Tendsto (fun x ↦ Real.arctan x) Filter.atTop (nhds (Real.pi / 2))
The certificate: 1 checked step
  1. Limit by asymptotic comparison

    Filter.Tendsto (fun x ↦ Real.arctan x) Filter.atTop (nhds (Real.pi / 2))

    Checked by Lean’s kernel

The computation
  • Asymptotic equivalent

    f ~ c x^0 e^(0 x) (log x)^0
In[11]:=
#cas [limit x → -∞] (x * exp x)
Out[11]=

limit from the dominant term

0
Domain
x → -∞

Checked by Lean’s kernel: Limit by asymptotic comparison

Filter.Tendsto (fun x ↦ x * Real.exp x) Filter.atBot (nhds 0)
The certificate: 1 checked step
  1. Limit by asymptotic comparison

    Filter.Tendsto (fun x ↦ x * Real.exp x) Filter.atBot (nhds 0)

    Checked by Lean’s kernel

The computation
  • Asymptotic equivalent

    f ~ c x^1 e^(-1 x) (log x)^0 in t = -x

A difference of two terms that both grow:

In[12]:=
#cas [limit x → ∞] (sqrt (x^2 + 1) - x)
Out[12]=

limit from the dominant term

0
Domain
x → ∞

Checked by Lean’s kernel: Limit by asymptotic comparison

Filter.Tendsto (fun x ↦ √(x ^ 2 + 1) - x) Filter.atTop (nhds 0)
The certificate: 1 checked step
  1. Limit by asymptotic comparison

    Filter.Tendsto (fun x ↦ √(x ^ 2 + 1) - x) Filter.atTop (nhds 0)

    Checked by Lean’s kernel

The computation
  • Asymptotic equivalent

    f ~ c x^-1 e^(0 x) (log x)^0

At a pole of even order both sides agree. At a pole of odd order they differ, and the answer gives both:

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

infinite limit at a pole of order 2

∞
∞
Domain
x → 0, x ≠ 0

Checked by Lean’s kernel: Limit

Filter.Tendsto (fun x ↦ 1 / x ^ 2) (nhdsWithin 0 {0}ᶜ) Filter.atTop
The certificate: 1 checked step
  1. Limit

    Filter.Tendsto (fun x ↦ 1 / x ^ 2) (nhdsWithin 0 {0}ᶜ) Filter.atTop

    Checked by Lean’s kernel

In[14]:=
#cas [limit x → 0] (1 / x)
Out[14]=

no two-sided limit: a pole of order 1

Indeterminate (∞ from above, -∞ from below)
Domain
x → 0, x ≠ 0

Checked by Lean’s kernel: Limit

Filter.Tendsto (fun x ↦ 1 / x) (nhdsWithin 0 (Set.Ioi 0)) Filter.atTop ∧
  Filter.Tendsto (fun x ↦ 1 / x) (nhdsWithin 0 (Set.Iio 0)) Filter.atBot
The certificate: 1 checked step
  1. Limit

    Filter.Tendsto (fun x ↦ 1 / x) (nhdsWithin 0 (Set.Ioi 0)) Filter.atTop ∧
      Filter.Tendsto (fun x ↦ 1 / x) (nhdsWithin 0 (Set.Iio 0)) Filter.atBot

    Checked by Lean’s kernel

Applications (2)

A limit in a proof. cas proves it, and only the three standard axioms are used:

In[15]:=
open Filter Topology in
theorem limit_sinc : Tendsto (fun x : ℝ ↦ Real.sin x / x) (𝓝[≠] 0) (𝓝 1) := by
  cas

#print axioms limit_sinc
Out[15]=

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


A one-sided infinite limit as a goal:

In[16]:=
open Filter Topology in
example : Tendsto (fun x : ℝ ↦ 1 / x) (𝓝[>] 0) atTop := by
  cas
Out[16]=

Lean accepts the proof.

Properties and Relations (1)

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

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

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]
In[18]:=
#cas [limit x → 0] ((exp x - 1 - x) / x^2)
Out[18]=

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)

Possible Issues (4)

The point must be a rational number, ∞ or −∞:

In[19]:=
#cas [limit x → π] (sin x)
Out[19]=

Error

limit: expected a rational number

sin(1/x) is not defined at 0, and it has no limit there. For a quotient whose denominator vanishes, the message asks for a single quotient g / h:

In[20]:=
#cas [limit x → 0] (sin (1 / x))
Out[20]=

Error

limit: the domain checker did not certify that the expression is defined at 0; for a quotient whose denominator vanishes at 0, write it as a single quotient

Away from 0, 1/(x+x/x) is 1/(x+1), but x / x is not valid at 0, so the domain checker refuses the denominator:

In[21]:=
#cas [limit x → 0] (1 / (x + x / x))
Out[21]=

Error

limit: the domain checker did not certify that the denominator and its derivatives through order 1 are defined at 0

Some limits at ∞ are out of reach of both routes, and the message lists why each one stopped:

In[22]:=
#cas [limit x → ∞] (log (exp x + 1) - x)
Out[22]=

Error

limit: no route proved the limit at ∞.
Asymptotic comparison:
  limit: log of an argument that is not equivalent to a positive power
Substitution x = 1 / t:
  limit: the expression is not built from x by field operations and functions of arguments with a finite limit

Neat Examples (3)

Two terms that grow like x, and a difference of 3/2:

In[23]:=
#cas [limit x → ∞] (sqrt (x^2 + 3 * x) - x)
Out[23]=

limit from the dominant term

32
3/2
Domain
x → ∞

Checked by Lean’s kernel: Limit by asymptotic comparison

Filter.Tendsto (fun x ↦ √(x ^ 2 + 3 * x) - x) Filter.atTop (nhds (3 / 2))
The certificate: 1 checked step
  1. Limit by asymptotic comparison

    Filter.Tendsto (fun x ↦ √(x ^ 2 + 3 * x) - x) Filter.atTop (nhds (3 / 2))

    Checked by Lean’s kernel

The computation
  • Asymptotic equivalent

    f ~ c x^0 e^(0 x) (log x)^0

The exponential dominates both the numerator and the denominator:

In[24]:=
#cas [limit x → ∞] ((x^2 + exp x) / (exp x + 1))
Out[24]=

limit from the dominant term

1
Domain
x → ∞

Checked by Lean’s kernel: Limit by asymptotic comparison

Filter.Tendsto (fun x ↦ (x ^ 2 + Real.exp x) / (Real.exp x + 1)) Filter.atTop (nhds 1)
The certificate: 1 checked step
  1. Limit by asymptotic comparison

    Filter.Tendsto (fun x ↦ (x ^ 2 + Real.exp x) / (Real.exp x + 1)) Filter.atTop (nhds 1)

    Checked by Lean’s kernel

The computation
  • Asymptotic equivalent

    f ~ c x^0 e^(0 x) (log x)^0

A quotient of logarithms:

In[25]:=
#cas [limit x → ∞] (log (x^2 + 1) / log x)
Out[25]=

limit from the dominant term

2
Domain
x → ∞

Checked by Lean’s kernel: Limit by asymptotic comparison

Filter.Tendsto (fun x ↦ Real.log (x ^ 2 + 1) / Real.log x) Filter.atTop (nhds 2)
The certificate: 1 checked step
  1. Limit by asymptotic comparison

    Filter.Tendsto (fun x ↦ Real.log (x ^ 2 + 1) / Real.log x) Filter.atTop (nhds 2)

    Checked by Lean’s kernel

The computation
  • Asymptotic equivalent

    f ~ c x^0 e^(0 x) (log x)^0

See Also

series · derive · sum · cas