Tactic

cas using

Proves the goal as cas does, with your hypotheses as evidence for the conditions that the routes need.

cas using h
proves the goal as cas does, with h as evidence for the conditions that the routes need, such as x≠0 for logx.
cas using [h₁, h₂]
the same with a list of complete proofs, added as local facts.

Many statements about real functions are true only where the functions are defined. The derivative of xlogx is logx+1 for x≠0, but at x=0 Lean’s deriv is 0, while the right side is log0+1=1, since Mathlib sets log0=0. cas never assumes a condition like that. You give it one with using, and the proof uses exactly what you gave.

Details and Options

  • On a derivative or an integral, h is the domain evidence: a nonzero, positivity or branch hypothesis, such as hx : x ≠ 0 or hx : 0 < 1 - x ^ 2.
  • For an integral from a to b, the condition holds on the whole interval and is stated as ∀ t ∈ Set.uIcc a b, ….
  • h is any proof term: an applied hypothesis such as h 0, a fact proved in place with show … from …, or And.intro h₁ h₂ for two conditions.
  • On an ordinary equation, h rewrites the goal when its left side occurs in it. Otherwise the denominators of h are cleared and it enters a linear combination.
  • cas using [h₁, h₂] adds each proof as a local fact. Inequalities and other propositions help with arithmetic and domain conditions, and equalities also go to the search for polynomial consequences.
  • The list holds proofs, not simp lemmas. For lemmas and definitions to unfold, cas has cas [l₁, l₂].
  • A missing condition is reported, never added.
  • The options are those of cas.

Examples (19)#

Basic Examples (3)

A derivative that needs x≠0:

In[1]:=
example (x : ℝ) (hx : x ≠ 0) :
    deriv (fun t : ℝ ↦ t * Real.log t) x = Real.log x + 1 := by
  cas using hx
Out[1]=

Lean accepts the proof.


An integral that needs the integrand to be defined on the whole interval:

In[2]:=
example (a b : ℝ) (hpositive : ∀ t ∈ Set.uIcc a b, 0 < t) :
    (∫ t in a..b, 1 / t) = Real.log b - Real.log a := by
  cas using hpositive
Out[2]=

Lean accepts the proof.


Two equations as facts, over any commutative ring:

In[3]:=
theorem mul_minor_eq_zero {R : Type*} [CommRing R] (a b c d e f : R)
    (h₁ : a * d = b * c) (h₂ : c * f = e * d) :
    c * (a * f - b * e) = 0 := by
  cas using [h₁, h₂]
Out[3]=

Lean accepts the proof.

Scope (6)

One-sided evidence settles the sign inside an absolute value:

In[4]:=
example (x : ℝ) (hpositive : 0 < 2 * x + 1) :
    deriv (fun t : ℝ ↦ |2 * t + 1|) x = 2 := by
  cas using hpositive
Out[4]=

Lean accepts the proof.


An inverse function, inside its domain:

In[5]:=
example (x : ℝ) (hinside : 0 < 1 - x ^ 2) :
    HasDerivAt Real.arcsin (1 / Real.sqrt (1 - x ^ 2)) x := by
  cas using hinside
Out[5]=

Lean accepts the proof.


Negative powers, and a nested derivative:

In[6]:=
example (x : ℝ) (hx : x ≠ 0) :
    deriv (fun t : ℝ ↦ t ^ (-2 : ℤ)) x = -2 / x ^ 3 := by
  cas using hx
Out[6]=

Lean accepts the proof.

In[7]:=
example (x : ℝ) (hx : x ≠ 0) :
    deriv (deriv (fun t : ℝ ↦ Real.log (2 * t))) x = -(x ^ 2)⁻¹ := by
  cas using hx
Out[7]=

Lean accepts the proof.


Positivity evidence covers a nonzero condition, here 4πs≠0:

In[8]:=
example (s : ℝ) (h : 0 < 4 * Real.pi * s) :
    deriv (fun t : ℝ ↦ Real.log (4 * Real.pi * t)) s = 1 / s := by
  cas using h
Out[8]=

Lean accepts the proof.


A real power with a symbolic exponent. The interval may contain 0, since r>−1:

In[9]:=
example (r a b : ℝ) (hr : -1 < r) :
    (∫ t : ℝ in a..b, t ^ r) = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by
  cas using hr
Out[9]=

Lean accepts the proof.


An equation with a quotient as the hypothesis. Its denominators are cleared, with q≠0 from the context:

In[10]:=
example (p q : ℝ) (hq : q ≠ 0) (h : p / q = p - 1) : p = q * (p - 1) := by
  cas using h
Out[10]=

Lean accepts the proof.

Options (3)

Evidence proved in place. Here r+1>0 is what I know, and the route wants −1<r:

In[11]:=
example (r a b : ℝ) (hr : 0 < r + 1) :
    (∫ t : ℝ in a..b, t ^ r) = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by
  cas using (show -1 < r from by linarith)
Out[11]=

Lean accepts the proof.


Two conditions at once, with And.intro:

In[12]:=
example (r a b : ℝ) (hr : r ≠ -1) (hab : (0 : ℝ) ∉ Set.uIcc a b) :
    (∫ t : ℝ in a..b, t ^ r) = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by
  cas using And.intro hr hab
Out[12]=

Lean accepts the proof.


Applied hypotheses, in a list and alone:

In[13]:=
example (x : ℝ) (hlower : ∀ t : ℝ, t = x → 1 ≤ t) (hupper : ∀ t : ℝ, t = x → t ≤ 2) :
    x ^ 2 ≤ 4 := by
  cas using [hlower x rfl, hupper x rfl]
Out[13]=

Lean accepts the proof.

In[14]:=
example (f : ℝ → ℝ) (h : ∀ t, (1 : ℝ) ≤ f t) : 0 ≤ f 0 := by
  cas using (h 0)
Out[14]=

Lean accepts the proof.

Applications (1)

An integral with two parameters. The only condition is that a and b are not both zero, and only the three standard axioms are used:

In[15]:=
theorem exp_mul_sin_over_unit (a b : ℝ) (h : a ^ 2 + b ^ 2 ≠ 0) :
    ∫ x in (0 : ℝ)..1, Real.exp (a * x) * Real.sin (b * x) =
      (Real.exp a * (a * Real.sin b - b * Real.cos b) + b) / (a ^ 2 + b ^ 2) := by
  cas using h

#print axioms exp_mul_sin_over_unit
Out[15]=

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

Properties and Relations (2)

derive prints the same derivative together with the condition it needs:

In[16]:=
#cas [derive x] (x * log x)
Out[16]=
log(x)+1
log(x) + 1
Conditions
x≠0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), x ≠ 0 → HasDerivAt (fun x ↦ x * Real.log x) (Real.log x + 1) x

from CAS.Command.hasDerivAt_of_displayRoute

The certificate: 5 checked steps
  1. Derivative of the input

    ∀ (x : ℝ), x ≠ 0 → HasDerivAt (fun x ↦ x * Real.log x) (Real.log x + 1) x

    Checked by Lean’s kernel · CAS.Command.hasDerivAt_of_displayRoute

  2. Partial derivative in x: indexed rules compute Expr.diff

    (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].mul 𝕏[0].log)).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].mul 𝕏[0].log)

    Checked by Lean’s kernel · CAS.Verified.Expr.DiffDerivation.rawDerivative_eq_diff

  3. Partial derivative in x: normalization preserves evaluation

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].mul 𝕏[0].log)).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].mul 𝕏[0].log)).rawDerivative

    Checked by Lean’s kernel · CAS.Verified.Expr.DiffDerivation.eval_simplifiedDerivative_eq_rawDerivative

  4. Partial derivative in x: side-conditioned display normalization

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          (CAS.Command.displayDerivativeRoute
              (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].mul 𝕏[0].log))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].mul 𝕏[0].log))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].mul 𝕏[0].log)).simplifiedDerivative

    Checked by Lean’s kernel · CAS.Command.displayDerivativeRoute_sound

  5. Partial derivative in x: analytic semantics of the displayed result

    ∀ (x : ℝ^1),
      CAS.Verified.Expr.ValidAt x.ofLp (𝕏[0].mul 𝕏[0].log) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].mul 𝕏[0].log))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp (𝕏[0].mul 𝕏[0].log)) x) (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].mul 𝕏[0].log))).rhs

    Checked by Lean’s kernel · CAS.Command.fderiv_apply_single_eq_eval_displayDerivative

The computation
  • Variables: x
  • Analytic domain conditions

    Raw checked nonzero requirements: x, x
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: 1*log(x) + x*1/x
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: log(x) + x/x
    • 3. Apply checked side-conditioned cleanup

      displayed result: log(x) + 1
      additional nonzero requirements: x

cas? accepts the same evidence and suggests the call to keep:

In[17]:=
example (x : ℝ) (hx : 0 < x) :
    deriv (fun t : ℝ ↦ t ^ (3 / 2 : ℝ)) x = (3 / 2 : ℝ) * x ^ (1 / 2 : ℝ) := by
  cas? using hx
Out[17]=

Try this

cas using hx

Lean checked the suggested replacement against the original goal. Selected route: CAS route: checked symbolic derivative.

Possible Issues (2)

Without the condition, cas refuses. At x=0 this statement is false in Lean:

In[18]:=
example (x : ℝ) : deriv (fun t : ℝ ↦ t * Real.log t) x = Real.log x + 1 := by
  cas
Out[18]=

Error

cas could not prove the real analytic domain conditions.
A denominator or logarithm argument may need to be nonzero, a square-root argument may need to be positive, or an inverse-trigonometric argument may need to avoid a branch endpoint. Supply the relevant ordinary hypothesis with `cas using h`.
Unproved conditions:
  x ≠ 0

Evidence that is too weak is refused in the same way. 0≤x still allows x=0:

In[19]:=
example (x : ℝ) (hx : 0 ≤ x) :
    deriv (fun t : ℝ ↦ t * Real.log t) x = Real.log x + 1 := by
  cas using hx
Out[19]=

Error

cas could not prove the real analytic domain conditions.
A denominator or logarithm argument may need to be nonzero, a square-root argument may need to be positive, or an inverse-trigonometric argument may need to avoid a branch endpoint. Supply the relevant ordinary hypothesis with `cas using h`.
Unproved conditions:
  x ≠ 0

Neat Examples (2)

The second derivative of |t| is 0 at every x≠0:

In[20]:=
theorem deriv_deriv_abs (x : ℝ) (hx : x ≠ 0) : deriv (deriv (fun t : ℝ ↦ |t|)) x = 0 := by
  cas using hx
Out[20]=

Lean accepts the proof.


Conjugate exponents. From p/q=p−1 it follows that 1/q=1−1/p:

In[21]:=
example (p q : ℝ) (hp : p ≠ 0) (hq : q ≠ 0) (h : p / q = p - 1) : 1 / q = 1 - 1 / p := by
  cas using h
Out[21]=

Lean accepts the proof.

See Also

cas · cas? · cas_nf · derive · integrate