Mode of #cas

derive

The derivative of an expression, with the conditions it needs and a theorem about Mathlib’s HasDerivAt.

#cas [derive x] e
gives the derivative ∂e/∂x of e with respect to x, with the conditions under which it holds. Every other variable of e is a parameter.
#cas [derive] e
differentiates e in its only variable, or a function fun x ↦ e in its parameter.

derive computes a derivative and gives its HasDerivAt statement. You get the derivative printed the way you would write it, and under it the theorem SymLean proved: a statement about Mathlib’s HasDerivAt for the real functions, with every condition it needs as a hypothesis. For me those conditions are as much a part of the answer as the derivative. The derivative of 2x+2 is claimed only where 2x+2>0, and the derivative of 1/x only where x≠0.

Details and Options

  • The theorem has the form ∀x,c1→…→ck→HasDerivAt(λx.e)e′x, where e′ is the printed derivative and c1,…,ck are the conditions. HasDerivAt f f' x is Mathlib’s statement that f has the derivative f′ at x. Lean’s kernel checks its proof before the report appears.
  • The functions are abs, sin, cos, tan, sinh, cosh, tanh, atan, asin, acos (also written arctan, arcsin, arccos), exp, log and sqrt, with +, -, *, / and powers. A power with a variable exponent, such as x ^ y, is a real power.
  • The error function erf is differentiated only in sums and differences of at most eight terms c * erf (A * x + B), where c, A and B do not contain x: numbers such as 2, 1/2 or sqrt 2, π, or parameters such as a, for all of whose real values the theorem holds. The theorem is about SymLean’s CAS.erf (see erf), since Mathlib v4.36.0 has no error function.
  • A square root contributes a condition a>0 and a quotient a condition d≠0. A logarithm contributes a≠0 (Mathlib’s real logarithm is total, and its derivative theorem holds on both sides of 0), the base of a real power a>0, and asin and acos the conditions a≠−1 and a≠1. Lean’s division is total (1/0=0), so a derivative of 1/x is only claimed where x≠0.
  • The “Conditions” line of the report prints the conditions in a display form, which can differ from the hypothesis of the theorem. For sqrt (2 * x + 2) the line reads x+1>0, and the theorem has 0 < 2 * x + 2.
  • For the functions other than erf, “The certificate” shows the theorem first, followed by the steps for SymLean’s internal expressions, from which it is transported. When the proof of the theorem takes more than its own budget of maxHeartbeats heartbeats, the report leaves the theorem out and keeps only the internal steps.
  • A function fun t ↦ e is differentiated in its parameter. Name it, as in #cas [derive t], or leave the name out.
  • set_option cas.verbose true adds the tree of differentiation rules to the report: each rule with its input and its raw derivative.
  • set_option cas.suggest true adds the theorem as an example you can paste into your file in place of the command.
  • The tactic cas proves the same HasDerivAt and deriv goals, so a derivative you found here can go straight into a proof.
  • Mathlib’s deriv is total: at a point where the function is not differentiable it is 0. For the bare functions abs, Real.log, Real.sinh, Real.cosh and Real.tan, cas applies Mathlib’s deriv lemmas, which hold at every point, so it proves equalities such as deriv Real.log 0 = 0⁻¹ (both sides are 0) without a validity check. A HasDerivAt goal, by contrast, states differentiability.

Examples (24)#

Basic Examples (3)

The derivative of x2sinx:

In[1]:=
#cas [derive x] (x ^ 2 * sin x)
Out[1]=
x(2sin(x)+xcos(x))
x*(2*sin(x) + x*cos(x))

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), HasDerivAt (fun x ↦ x ^ 2 * Real.sin x) (x * (2 * Real.sin x + x * Real.cos x)) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), HasDerivAt (fun x ↦ x ^ 2 * Real.sin x) (x * (2 * Real.sin x + x * Real.cos x)) 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].pow 2).mul 𝕏[0].sin)).rawDerivative =
      CAS.Verified.Expr.diff 0 ((𝕏[0].pow 2).mul 𝕏[0].sin)

    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].pow 2).mul 𝕏[0].sin)).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 2).mul 𝕏[0].sin)).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].pow 2).mul 𝕏[0].sin))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 2).mul 𝕏[0].sin))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 2).mul 𝕏[0].sin)).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].pow 2).mul 𝕏[0].sin) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 2).mul 𝕏[0].sin))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp ((𝕏[0].pow 2).mul 𝕏[0].sin)) x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0 ((𝕏[0].pow 2).mul 𝕏[0].sin))).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: (none)
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: 2*x^1*1*sin(x) + x^2*cos(x)*1
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 2*x*sin(x) + x^2*cos(x)
    • 3. Apply checked side-conditioned cleanup

      displayed result: x*(2*sin(x) + x*cos(x))
      additional nonzero requirements: (none)

A square root needs a positive argument, and the report says so. Its “Conditions” line prints the hypothesis 0 < 2 * x + 2 of the theorem as x+1>0:

In[2]:=
#cas [derive x] (sqrt (2 * x + 2))
Out[2]=
12x+2
1/sqrt(2*x + 2)
Conditions
x+1>0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), 0 < 2 * x + 2 → HasDerivAt (fun x ↦ √(2 * x + 2)) (1 / √(2 * x + 2)) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), 0 < 2 * x + 2 → HasDerivAt (fun x ↦ √(2 * x + 2)) (1 / √(2 * x + 2)) 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
          (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt).rawDerivative =
      CAS.Verified.Expr.diff 0 (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt

    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
              (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0
              (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt).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
                (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0
                (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt).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 (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)).nonzero →
          (fderiv ℝ
                (fun y ↦
                  CAS.Verified.Expr.eval y.ofLp
                    (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)
                x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0
                    (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)).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: (none)
    Raw checked positivity requirements: 2*x + 2
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

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

      normalized result: 1/sqrt(2*x + 2)
    • 3. Apply checked side-conditioned cleanup

      displayed result: 1/sqrt(2*x + 2)
      additional nonzero requirements: (none)

With one variable you can leave its name out:

In[3]:=
#cas [derive] (x ^ 3)
Out[3]=
3x2
3*x^2

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), HasDerivAt (fun x ↦ x ^ 3) (3 * x ^ 2) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), HasDerivAt (fun x ↦ x ^ 3) (3 * x ^ 2) 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].pow 3)).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].pow 3)

    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].pow 3)).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 3)).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].pow 3))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 3))).rhs =
          CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 3)).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].pow 3) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 3))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp (𝕏[0].pow 3)) x) (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 3))).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: (none)
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: 3*x^2*1
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 3*x^2
    • 3. Apply checked side-conditioned cleanup

      displayed result: 3*x^2
      additional nonzero requirements: (none)

Scope (6)

Every variable other than the one you name is a parameter:

In[4]:=
#cas [derive x] (sin (x * y))
Out[4]=
cos(xy)y
cos(x*y)*y

Checked by Lean’s kernel: Derivative of the input

∀ (x y : ℝ), HasDerivAt (fun x ↦ Real.sin (x * y)) (Real.cos (x * y) * y) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x y : ℝ), HasDerivAt (fun x ↦ Real.sin (x * y)) (Real.cos (x * y) * y) 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 𝕏[1]).sin).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].mul 𝕏[1]).sin

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

  3. Partial derivative in x: normalization preserves evaluation

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

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

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

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

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

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

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

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

The computation
  • Variables: x, y
  • Analytic domain conditions

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

    • 1. Apply symbolic differentiation rules

      raw result: cos(x*y)*(1*y + x*0)
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: cos(x*y)*y
    • 3. Apply checked side-conditioned cleanup

      displayed result: cos(x*y)*y
      additional nonzero requirements: (none)

The trigonometric, hyperbolic and inverse functions come with the conditions Mathlib’s theorems need:

In[5]:=
#cas [derive x] (tan x)
Out[5]=
1cos2(x)
1/cos(x)^2
Conditions
cos(x)≠0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), Real.cos x ≠ 0 → HasDerivAt (fun x ↦ Real.tan x) (1 / Real.cos x ^ 2) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), Real.cos x ≠ 0 → HasDerivAt (fun x ↦ Real.tan x) (1 / Real.cos x ^ 2) 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].sin.div 𝕏[0].cos)).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].sin.div 𝕏[0].cos)

    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].sin.div 𝕏[0].cos)).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos)).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].sin.div 𝕏[0].cos))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos)).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].sin.div 𝕏[0].cos) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp (𝕏[0].sin.div 𝕏[0].cos)) x) (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos))).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: cos(x)
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: (cos(x)*1*cos(x) - sin(x)*-sin(x)*1)/cos(x)^2
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 1/cos(x)^2
    • 3. Apply checked side-conditioned cleanup

      displayed result: 1/cos(x)^2
      additional nonzero requirements: (none)
In[6]:=
#cas [derive x] (arcsin x)
Out[6]=
11−x2
1/sqrt(1 - x^2)
Conditions
x+1≠0, x−1≠0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), x + 1 ≠ 0 → x - 1 ≠ 0 → HasDerivAt (fun x ↦ Real.arcsin x) (1 / √(1 - x ^ 2)) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), x + 1 ≠ 0 → x - 1 ≠ 0 → HasDerivAt (fun x ↦ Real.arcsin x) (1 / √(1 - x ^ 2)) 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].asin).rawDerivative =
      CAS.Verified.Expr.diff 0 𝕏[0].asin

    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].asin).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 𝕏[0].asin).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].asin)).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 𝕏[0].asin)).rhs =
          CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 𝕏[0].asin).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].asin →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 𝕏[0].asin)).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp 𝕏[0].asin) x) (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 𝕏[0].asin)).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 + 1, x - 1
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: 1/sqrt(1 - x^2)
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 1/sqrt(1 - x^2)
    • 3. Apply checked side-conditioned cleanup

      displayed result: 1/sqrt(1 - x^2)
      additional nonzero requirements: (none)
In[7]:=
#cas [derive x] (sinh x)
Out[7]=
12(ex+e−x)
1/2*(exp(x) + exp(-x))

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), HasDerivAt (fun x ↦ Real.sinh x) (1 / 2 * (Real.exp x + Real.exp (-x))) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), HasDerivAt (fun x ↦ Real.sinh x) (1 / 2 * (Real.exp x + Real.exp (-x))) 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].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2))).rawDerivative =
      CAS.Verified.Expr.diff 0 ((𝕏[0].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2))

    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].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2))).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0
              ((𝕏[0].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2))).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].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2)))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  ((𝕏[0].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2)))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0
                ((𝕏[0].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2))).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].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2)) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  ((𝕏[0].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2)))).nonzero →
          (fderiv ℝ
                (fun y ↦ CAS.Verified.Expr.eval y.ofLp ((𝕏[0].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2)))
                x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0
                    ((𝕏[0].exp.sub 𝕏[0].neg.exp).div (CAS.Verified.Expr.nat 2)))).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: 2
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: ((exp(x)*1 - exp(-x)*-1)*2 - (exp(x) - exp(-x))*0)/2^2
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 1/2*(exp(x) + exp(-x))
    • 3. Apply checked side-conditioned cleanup

      displayed result: 1/2*(exp(x) + exp(-x))
      additional nonzero requirements: (none)

The absolute value is differentiable away from 0. The condition is stated as x2>0:

In[8]:=
#cas [derive x] (|x|)
Out[8]=
x|x|
x/|x|
Conditions
x2>0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), 0 < x ^ 2 → HasDerivAt (fun x ↦ |x|) (x / |x|) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), 0 < x ^ 2 → HasDerivAt (fun x ↦ |x|) (x / |x|) 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].pow 2).sqrt).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].pow 2).sqrt

    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].pow 2).sqrt).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 2).sqrt).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].pow 2).sqrt)).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 2).sqrt)).rhs =
          CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 2).sqrt).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].pow 2).sqrt →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 2).sqrt)).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp (𝕏[0].pow 2).sqrt) x) (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].pow 2).sqrt)).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: (none)
    Raw checked positivity requirements: x^2
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

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

      normalized result: x/|x|
    • 3. Apply checked side-conditioned cleanup

      displayed result: x/|x|
      additional nonzero requirements: (none)

Powers with a real or a negative exponent. A negative integer exponent is read as the reciprocal of a natural power, so the second theorem is about 1 / x ^ 2:

In[9]:=
#cas [derive x] (x ^ (3/2 : ℝ))
Out[9]=
32x
3/2*sqrt(x)
Conditions
x>0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), 0 < x → HasDerivAt (fun x ↦ x ^ (3 / 2 : ℝ)) (3 / 2 * √x) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), 0 < x → HasDerivAt (fun x ↦ x ^ (3 / 2 : ℝ)) (3 / 2 * √x) 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].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2)))).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2)))

    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].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2)))).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0
              (𝕏[0].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2)))).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].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2))))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  (𝕏[0].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2))))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0
                (𝕏[0].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2)))).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].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2))) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  (𝕏[0].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2))))).nonzero →
          (fderiv ℝ
                (fun y ↦
                  CAS.Verified.Expr.eval y.ofLp
                    (𝕏[0].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2))))
                x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0
                    (𝕏[0].rpow ((CAS.Verified.Expr.nat 3).div (CAS.Verified.Expr.nat 2))))).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: 2
    Raw checked positivity requirements: x
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

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

      normalized result: 3/2*x^(1/2)
    • 3. Apply checked side-conditioned cleanup

      displayed result: 3/2*sqrt(x)
      additional nonzero requirements: (none)
In[10]:=
#cas [derive x] (x ^ (-2))
Out[10]=
−2x3
-(2/x^3)
Conditions
x≠0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), x ^ 2 ≠ 0 → HasDerivAt (fun x ↦ 1 / x ^ 2) (-2 / x ^ 3) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), x ^ 2 ≠ 0 → HasDerivAt (fun x ↦ 1 / x ^ 2) (-2 / x ^ 3) 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
          ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2))).rawDerivative =
      CAS.Verified.Expr.diff 0 ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2))

    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
              ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2))).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2))).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 ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2)))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2)))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0
                ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2))).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 ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2)) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2)))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2))) x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div (𝕏[0].pow 2)))).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^2
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: (0*x^2 - 1*2*x^1*1)/(x^2)^2
    • 2. Normalize the symbolic derivative unconditionally

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

      displayed result: -(2/x^3)
      additional nonzero requirements: (none)
In[11]:=
#cas [derive x] (x ^ y)
Out[11]=
yxy−1
y*x^(y - 1)
Conditions
x>0

Checked by Lean’s kernel: Derivative of the input

∀ (x y : ℝ), 0 < x → HasDerivAt (fun x ↦ x ^ y) (y * x ^ (y - 1)) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x y : ℝ), 0 < x → HasDerivAt (fun x ↦ x ^ y) (y * x ^ (y - 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].rpow 𝕏[1])).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].rpow 𝕏[1])

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

  3. Partial derivative in x: normalization preserves evaluation

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

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

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

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

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

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

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

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

The computation
  • Variables: x, y
  • Analytic domain conditions

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

    • 1. Apply symbolic differentiation rules

      raw result: 1*y*x^(y - 1) + 0*x^y*log(x)
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: y*x^(y - 1)
    • 3. Apply checked side-conditioned cleanup

      displayed result: y*x^(y - 1)
      additional nonzero requirements: (none)

The error function, whose derivative is a Gaussian. The theorem is about SymLean’s CAS.erf:

In[12]:=
#cas [derive x] (erf x)
Out[12]=

derivative

2πe−x2
2/sqrt(pi)*exp(-x^2)
Input (sum of c * erf (A x + B))
(erf x)

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), HasDerivAt (fun x ↦ CAS.erf x) (2 / √Real.pi * Real.exp (-x ^ 2)) x

from CAS.hasDerivAt_erf

The certificate: 1 checked step
  1. Derivative of the input

    ∀ (x : ℝ), HasDerivAt (fun x ↦ CAS.erf x) (2 / √Real.pi * Real.exp (-x ^ 2)) x

    Checked by Lean’s kernel · CAS.hasDerivAt_erf


A function is differentiated in its parameter:

In[13]:=
#cas [derive] (fun x ↦ a * x + b)
Out[13]=
a

Checked by Lean’s kernel: Derivative of the input

∀ (x a b : ℝ), HasDerivAt (fun x ↦ a * x + b) a x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x a b : ℝ), HasDerivAt (fun x ↦ a * x + b) a 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 ((𝕏[1].mul 𝕏[0]).add 𝕏[2])).rawDerivative =
      CAS.Verified.Expr.diff 0 ((𝕏[1].mul 𝕏[0]).add 𝕏[2])

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

  3. Partial derivative in x: normalization preserves evaluation

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

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

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

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

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

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

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

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

The computation
  • Variables: x, a, b
  • Analytic domain conditions

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

    • 1. Apply symbolic differentiation rules

      raw result: 0*x + a*1 + 0
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: a
    • 3. Apply checked side-conditioned cleanup

      displayed result: a
      additional nonzero requirements: (none)

Options (3)

With cas.suggest, the report ends with the theorem as an example, ready to paste:

In[14]:=
set_option cas.suggest true in
#cas [derive x] (tan x)
Out[14]=
1cos2(x)
1/cos(x)^2
Conditions
cos(x)≠0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), Real.cos x ≠ 0 → HasDerivAt (fun x ↦ Real.tan x) (1 / Real.cos x ^ 2) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), Real.cos x ≠ 0 → HasDerivAt (fun x ↦ Real.tan x) (1 / Real.cos x ^ 2) 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].sin.div 𝕏[0].cos)).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].sin.div 𝕏[0].cos)

    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].sin.div 𝕏[0].cos)).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos)).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].sin.div 𝕏[0].cos))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos)).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].sin.div 𝕏[0].cos) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp (𝕏[0].sin.div 𝕏[0].cos)) x) (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].sin.div 𝕏[0].cos))).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: cos(x)
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: (cos(x)*1*cos(x) - sin(x)*-sin(x)*1)/cos(x)^2
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 1/cos(x)^2
    • 3. Apply checked side-conditioned cleanup

      displayed result: 1/cos(x)^2
      additional nonzero requirements: (none)

Try this

example (x : ℝ) (h : Real.cos x ≠ 0) :
      HasDerivAt (fun x ↦ Real.tan x) (1 / Real.cos x ^ 2) x := by
    cas

Here it is pasted, and cas proves it:

In[15]:=
example (x : ℝ) (h : Real.cos x ≠ 0) :
    HasDerivAt (fun x ↦ Real.tan x) (1 / Real.cos x ^ 2) x := by
  cas
Out[15]=

Lean accepts the proof.


With cas.verbose, “The computation” shows every differentiation rule that was applied:

In[16]:=
set_option cas.verbose true in
#cas [derive x] (sqrt (2 * x + 2))
Out[16]=
12x+2
1/sqrt(2*x + 2)
Conditions
x+1>0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), 0 < 2 * x + 2 → HasDerivAt (fun x ↦ √(2 * x + 2)) (1 / √(2 * x + 2)) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), 0 < 2 * x + 2 → HasDerivAt (fun x ↦ √(2 * x + 2)) (1 / √(2 * x + 2)) 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
          (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt).rawDerivative =
      CAS.Verified.Expr.diff 0 (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt

    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
              (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0
              (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt).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
                (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0
                (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt).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 (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)).nonzero →
          (fderiv ℝ
                (fun y ↦
                  CAS.Verified.Expr.eval y.ofLp
                    (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)
                x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0
                    (((CAS.Verified.Expr.nat 2).mul 𝕏[0]).add (CAS.Verified.Expr.nat 2)).sqrt)).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: (none)
    Raw checked positivity requirements: 2*x + 2
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: (0*x + 2*1 + 0)/(2*sqrt(2*x + 2))
      • square-root chain rule

        input: sqrt(2*x + 2)
        raw derivative: (0*x + 2*1 + 0)/(2*sqrt(2*x + 2))
        representation: indexed DiffDerivation node
        • sum rule

          input: 2*x + 2
          raw derivative: 0*x + 2*1 + 0
          representation: indexed DiffDerivation node
          • product rule

            input: 2*x
            raw derivative: 0*x + 2*1
            representation: indexed DiffDerivation node
            • constant rule

              input: 2
              raw derivative: 0
              representation: indexed DiffDerivation node
            • variable rule

              input: x
              raw derivative: 1
              representation: indexed DiffDerivation node
          • constant rule

            input: 2
            raw derivative: 0
            representation: indexed DiffDerivation node
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 1/sqrt(2*x + 2)
    • 3. Apply checked side-conditioned cleanup

      displayed result: 1/sqrt(2*x + 2)
      additional nonzero requirements: (none)

Applications (2)

A derivative in a proof. The tactic cas proves the statement, and only the three standard axioms are used:

In[17]:=
theorem derive_product (x : ℝ) :
    HasDerivAt (fun x ↦ x ^ 2 * Real.sin x) (2 * x * Real.sin x + x ^ 2 * Real.cos x) x := by
  cas

#print axioms derive_product
Out[17]=

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


The critical points of x3−3x: differentiate, then solve f′(x)=0:

In[18]:=
#cas [derive x] (x ^ 3 - 3 * x)
Out[18]=
3x2−3
3*x^2 - 3

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), HasDerivAt (fun x ↦ x ^ 3 - 3 * x) (3 * x ^ 2 - 3) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), HasDerivAt (fun x ↦ x ^ 3 - 3 * x) (3 * x ^ 2 - 3) 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].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0]))).rawDerivative =
      CAS.Verified.Expr.diff 0 ((𝕏[0].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0]))

    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].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0]))).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0
              ((𝕏[0].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0]))).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].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0])))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  ((𝕏[0].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0])))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0
                ((𝕏[0].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0]))).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].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0])) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  ((𝕏[0].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0])))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp ((𝕏[0].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0])))
                x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0
                    ((𝕏[0].pow 3).sub ((CAS.Verified.Expr.nat 3).mul 𝕏[0])))).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: (none)
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: 3*x^2*1 - 0*x - 3*1
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: 3*x^2 - 3
    • 3. Apply checked side-conditioned cleanup

      displayed result: 3*x^2 - 3
      additional nonzero requirements: (none)
In[19]:=
#cas [solve x] (3 * x ^ 2 - 3 = 0)
Out[19]=

equivalent real solution predicate

x=1∨x=−1
x = 1 ∨ x = -1
Input (real relation)
(3 * x ^ 2 - 3 = 0)

Checked by Lean’s kernel: Complete solution predicate for every real value

∀ (x : ℝ), 3 * x ^ 2 - 3 = 0 ↔ x = 1 ∨ x = -1
The certificate: 1 checked step
  1. Complete solution predicate for every real value

    ∀ (x : ℝ), 3 * x ^ 2 - 3 = 0 ↔ x = 1 ∨ x = -1

    Checked by Lean’s kernel

The computation
  • Guarantee: the input and output are equivalent for every real value

Properties and Relations (2)

The gradient collects the partial derivatives:

In[20]:=
#cas [grad x, y] (x ^ 2 * y + y ^ 3)
Out[20]=

vector ℝ^2; order x, y

(2xy, x2+3y2)
(2*x*y, x^2 + 3*y^2)

Checked by Lean’s kernel: Gradient of the input

∀ (x y : ℝ),
  HasGradientAt (fun p ↦ p.ofLp 0 ^ 2 * p.ofLp 1 + p.ofLp 1 ^ 3) !₂[2 * x * y, x ^ 2 + 3 * y ^ 2] !₂[x, y]

from CAS.Verified.Expr.hasGradientAt_of_closedGradient

The certificate: 10 checked steps
  1. Gradient of the input

    ∀ (x y : ℝ),
      HasGradientAt (fun p ↦ p.ofLp 0 ^ 2 * p.ofLp 1 + p.ofLp 1 ^ 3) !₂[2 * x * y, x ^ 2 + 3 * y ^ 2] !₂[x, y]

    Checked by Lean’s kernel · CAS.Verified.Expr.hasGradientAt_of_closedGradient

  2. Gradient component ∂_x: indexed rules compute Expr.diff

    (CAS.Verified.Expr.DiffDerivation.build 0
          (((𝕏[0].pow 2).mul 𝕏[1]).add (𝕏[1].pow 3))).rawDerivative =
      CAS.Verified.Expr.diff 0 (((𝕏[0].pow 2).mul 𝕏[1]).add (𝕏[1].pow 3))

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

  3. Gradient component ∂_x: normalization preserves evaluation

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

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

  4. Gradient component ∂_x: side-conditioned display normalization

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

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

  5. Gradient component ∂_x: analytic semantics of the displayed result

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

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

  6. Gradient component ∂_y: indexed rules compute Expr.diff

    (CAS.Verified.Expr.DiffDerivation.build 1
          (((𝕏[0].pow 2).mul 𝕏[1]).add (𝕏[1].pow 3))).rawDerivative =
      CAS.Verified.Expr.diff 1 (((𝕏[0].pow 2).mul 𝕏[1]).add (𝕏[1].pow 3))

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

  7. Gradient component ∂_y: normalization preserves evaluation

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

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

  8. Gradient component ∂_y: side-conditioned display normalization

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

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

  9. Gradient component ∂_y: analytic semantics of the displayed result

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

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

  10. Analytic gradient assembly

    ∀ (x : ℝ^2),
      CAS.Verified.Expr.ValidAt x.ofLp (((𝕏[0].pow 2).mul 𝕏[1]).add (𝕏[1].pow 3)) →
        (WithLp.toLp 2 fun i ↦ CAS.Verified.Expr.eval x.ofLp ((∇ₛ (((𝕏[0].pow 2).mul 𝕏[1]).add (𝕏[1].pow 3))) i)) =
          gradient (fun y ↦ CAS.Verified.Expr.eval y.ofLp (((𝕏[0].pow 2).mul 𝕏[1]).add (𝕏[1].pow 3))) x

    Checked by Lean’s kernel · CAS.Verified.Expr.closedGradient_eval_eq_gradient

The computation
  • Variables and component order: x, y
  • Analytic domain conditions

    Raw checked nonzero requirements: (none)
    Raw checked positivity requirements: (none)
  • Checked gradient computation

    • Gradient component ∂_x

      Output: 2*x*y
      • Partial derivative in x

        • 1. Apply symbolic differentiation rules

          raw result: 2*x^1*1*y + x^2*0 + 3*y^2*0
        • 2. Normalize the symbolic derivative unconditionally

          normalized result: 2*x*y
        • 3. Apply checked side-conditioned cleanup

          displayed result: 2*x*y
          additional nonzero requirements: (none)
    • Gradient component ∂_y

      Output: x^2 + 3*y^2
      • Partial derivative in y

        • 1. Apply symbolic differentiation rules

          raw result: 2*x^1*0*y + x^2*1 + 3*y^2*1
        • 2. Normalize the symbolic derivative unconditionally

          normalized result: x^2 + 3*y^2
        • 3. Apply checked side-conditioned cleanup

          displayed result: x^2 + 3*y^2
          additional nonzero requirements: (none)
In[21]:=
#cas [derive y] (x ^ 2 * y + y ^ 3)
Out[21]=
x2+3y2
x^2 + 3*y^2

Checked by Lean’s kernel: Derivative of the input

∀ (y x : ℝ), HasDerivAt (fun y ↦ x ^ 2 * y + y ^ 3) (x ^ 2 + 3 * y ^ 2) y

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (y x : ℝ), HasDerivAt (fun y ↦ x ^ 2 * y + y ^ 3) (x ^ 2 + 3 * y ^ 2) y

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

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

    (CAS.Verified.Expr.DiffDerivation.build 0
          (((𝕏[1].pow 2).mul 𝕏[0]).add (𝕏[0].pow 3))).rawDerivative =
      CAS.Verified.Expr.diff 0 (((𝕏[1].pow 2).mul 𝕏[0]).add (𝕏[0].pow 3))

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

  3. Partial derivative in y: normalization preserves evaluation

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

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

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

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

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

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

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

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

The computation
  • Variables: y, x
  • Analytic domain conditions

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

    • 1. Apply symbolic differentiation rules

      raw result: 2*x^1*0*y + x^2*1 + 3*y^2*1
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: x^2 + 3*y^2
    • 3. Apply checked side-conditioned cleanup

      displayed result: x^2 + 3*y^2
      additional nonzero requirements: (none)

Differentiating an antiderivative gives back the integrand:

In[22]:=
#cas [integrate x] (x * sin (x ^ 2))
Out[22]=

antiderivative

−12cos(x2)
-(1/2*cos(x^2))

Checked by Lean’s kernel: Integral of the input

∀ (a b : ℝ),
  ∫ (x : ℝ) in a..b, x * Real.sin (x ^ 2) = -(1 / 2 * Real.cos (b ^ 2)) + 1 / 2 * Real.cos (a ^ 2)

from CAS.IntegrationCheck.AntiderivativeCert.intervalIntegral_eq_sub_of_line

The certificate: 9 checked steps
  1. Integral of the input

    ∀ (a b : ℝ),
      ∫ (x : ℝ) in a..b, x * Real.sin (x ^ 2) = -(1 / 2 * Real.cos (b ^ 2)) + 1 / 2 * Real.cos (a ^ 2)

    Checked by Lean’s kernel · CAS.IntegrationCheck.AntiderivativeCert.intervalIntegral_eq_sub_of_line

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

    (CAS.Verified.Expr.DiffDerivation.build 0
          ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg).rawDerivative =
      CAS.Verified.Expr.diff 0 ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg

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

  3. Primitive derivative in x: normalization preserves evaluation

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

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

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

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

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

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

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

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

  6. Residual route reaches zero

    (CAS.IntegrationCheck.route 0 (𝕏[0].mul (𝕏[0].pow 2).sin)
          { candidate := ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg, routeZero := ⋯ }.candidate).rhs =
      0

    Checked by Lean’s kernel · CAS.IntegrationCheck.AntiderivativeCert.routeZero

  7. Symbolic antiderivative identity under the displayed requirements

    ∀ (x : ℝ^1),
      { candidate := ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg, routeZero := ⋯ }.requirements.Holds
          x.ofLp →
        CAS.Verified.Expr.eval x.ofLp
            (CAS.Verified.Expr.diff 0
              { candidate := ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg, routeZero := ⋯ }.candidate) =
          CAS.Verified.Expr.eval x.ofLp (𝕏[0].mul (𝕏[0].pow 2).sin)

    Checked by Lean’s kernel · CAS.IntegrationCheck.AntiderivativeCert.eval_diff_eq

  8. Coordinate-line derivative theorem

    ∀ (x : ℝ^1) (t : ℝ),
      { candidate := ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg, routeZero := ⋯ }.requirements.Holds
          (x.ofLp + t • (EuclideanSpace.single 0 1).ofLp) →
        HasDerivAt
          (fun s ↦
            CAS.Verified.Expr.eval (x + s • EuclideanSpace.single 0 1).ofLp
              { candidate := ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg, routeZero := ⋯ }.candidate)
          (CAS.Verified.Expr.eval (x + t • EuclideanSpace.single 0 1).ofLp (𝕏[0].mul (𝕏[0].pow 2).sin)) t

    Checked by Lean’s kernel · CAS.IntegrationCheck.AntiderivativeCert.hasDerivAt_eval_add_smul_single

  9. Coordinate-line fundamental theorem of calculus

    ∀ (x : ℝ^1) (a b : ℝ),
      (∀ t ∈ Set.uIcc a b,
          { candidate := ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg, routeZero := ⋯ }.requirements.Holds
            (x.ofLp + t • (EuclideanSpace.single 0 1).ofLp)) →
        ∫ (t : ℝ) in a..b,
            CAS.Verified.Expr.eval (x + t • EuclideanSpace.single 0 1).ofLp (𝕏[0].mul (𝕏[0].pow 2).sin) =
          CAS.Verified.Expr.eval (x + b • EuclideanSpace.single 0 1).ofLp
              { candidate := ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg, routeZero := ⋯ }.candidate -
            CAS.Verified.Expr.eval (x + a • EuclideanSpace.single 0 1).ofLp
              { candidate := ((CAS.Verified.Expr.rat 1 2).mul (𝕏[0].pow 2).cos).neg, routeZero := ⋯ }.candidate

    Checked by Lean’s kernel · CAS.IntegrationCheck.AntiderivativeCert.intervalIntegral_eq_sub_eval_add_smul_single

The computation
  • Variables: x
  • Checked antiderivative computation

    • 1. Differentiate the proposed primitive

      Raw derivative: -(0*cos(x^2) + 1/2*-sin(x^2)*2*x^1*1)
    • 2. Form the derivative residual

      Raw residual: -(0*cos(x^2)) - 1/2*-sin(x^2)*2*x^1*1 - x*sin(x^2)
      Definition: CAS.IntegrationCheck.residual
    • 3. Check the residual normal form

      Checked residual normal form: 0
      Certificate condition: checked residual normal form = 0
    • 4. Record analytic domain requirements

      Certificate nonzero requirements (compacted): (none)
      Certificate positivity requirements (compacted): (none)
In[23]:=
#cas [derive x] (-(1/2) * cos (x ^ 2))
Out[23]=
xsin(x2)
x*sin(x^2)

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), HasDerivAt (fun x ↦ -(1 / 2) * Real.cos (x ^ 2)) (x * Real.sin (x ^ 2)) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), HasDerivAt (fun x ↦ -(1 / 2) * Real.cos (x ^ 2)) (x * Real.sin (x ^ 2)) 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
          (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos)).rawDerivative =
      CAS.Verified.Expr.diff 0 (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos)

    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
              (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul
                (𝕏[0].pow 2).cos)).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0
              (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos)).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
                (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0
                (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul
                  (𝕏[0].pow 2).cos)).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
          (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos))).nonzero →
          (fderiv ℝ
                (fun y ↦
                  CAS.Verified.Expr.eval y.ofLp
                    (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos))
                x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0
                    (((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)).neg.mul (𝕏[0].pow 2).cos))).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: 2
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: -((0*2 - 1*0)/2^2)*cos(x^2) - 1/2*-sin(x^2)*2*x^1*1
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: -(-1/2*sin(x^2)*2*x)
    • 3. Apply checked side-conditioned cleanup

      displayed result: x*sin(x^2)
      additional nonzero requirements: (none)

Possible Issues (5)

Only the functions listed above are differentiated. The Gamma function is not one of them:

In[24]:=
#cas [derive x] (gamma x)
Out[24]=

Error

unsupported symbolic function 'gamma'; expected abs, sin, cos, tan, sinh, cosh, tanh, atan/arctan, asin/arcsin, acos/arccos, exp, log, or sqrt. `gamma x` is evaluated as the whole input of `#cas (gamma x)`

The error function is differentiated only in the sums described above. A product with it is refused:

In[25]:=
#cas [derive x] (x * erf x)
Out[25]=

Error

unsupported symbolic function 'erf'; expected abs, sin, cos, tan, sinh, cosh, tanh, atan/arctan, asin/arcsin, acos/arccos, exp, log, or sqrt. `erf x` is evaluated as the whole input of `#cas [N d] (erf x)`

The name in brackets has to be the parameter of the function:

In[26]:=
#cas [derive x] (fun t : ℝ ↦ t ^ 2)
Out[26]=

Error

coordinate 'x' does not match the function parameter 't'; use the parameter name or omit the coordinate

Without a name, the expression must have exactly one variable:

In[27]:=
#cas [derive] (x * y)
Out[27]=

Error

the expression has multiple variables: x, y; use [derive x] for a partial derivative or [grad x, y] for a gradient

A condition is part of the answer. Here the theorem says nothing at x=0, where Lean’s 1/0=0 makes 1/x a function with no derivative:

In[28]:=
#cas [derive x] (1 / x)
Out[28]=
−1x2
-(1/x^2)
Conditions
x≠0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ), x ≠ 0 → HasDerivAt (fun x ↦ 1 / x) (-1 / x ^ 2) x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), x ≠ 0 → HasDerivAt (fun x ↦ 1 / x) (-1 / x ^ 2) 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 ((CAS.Verified.Expr.nat 1).div 𝕏[0])).rawDerivative =
      CAS.Verified.Expr.diff 0 ((CAS.Verified.Expr.nat 1).div 𝕏[0])

    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 ((CAS.Verified.Expr.nat 1).div 𝕏[0])).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div 𝕏[0])).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 ((CAS.Verified.Expr.nat 1).div 𝕏[0]))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div 𝕏[0]))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div 𝕏[0])).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 ((CAS.Verified.Expr.nat 1).div 𝕏[0]) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div 𝕏[0]))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp ((CAS.Verified.Expr.nat 1).div 𝕏[0])) x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0 ((CAS.Verified.Expr.nat 1).div 𝕏[0]))).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
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: (0*x - 1^2)/x^2
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: -(1/x^2)
    • 3. Apply checked side-conditioned cleanup

      displayed result: -(1/x^2)
      additional nonzero requirements: (none)

Neat Examples (3)

A rational function with a degree 6 denominator:

In[29]:=
#cas [derive x] (1 / (x ^ 6 + 3 * x ^ 4 + 4 * x ^ 3 + 2 * x ^ 2 + 5 * x + 3))
Out[29]=
−6x5+12x3+12x2+4x+5(x6+3x4+4x3+2x2+5x+3)2
-((6*x^5 + 12*x^3 + 12*x^2 + 4*x + 5)/(x^6 + 3*x^4 + 4*x^3 + 2*x^2 + 5*x + 3)^2)
Conditions
x6+3x4+4x3+2x2+5x+3≠0

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ),
  x ^ 6 + 3 * x ^ 4 + 4 * x ^ 3 + 2 * x ^ 2 + 5 * x + 3 ≠ 0 →
    HasDerivAt (fun x ↦ 1 / (x ^ 6 + 3 * x ^ 4 + 4 * x ^ 3 + 2 * x ^ 2 + 5 * x + 3))
      (-((6 * x ^ 5 + 12 * x ^ 3 + 12 * x ^ 2 + 4 * x + 5) /
          (x ^ 6 + 3 * x ^ 4 + 4 * x ^ 3 + 2 * x ^ 2 + 5 * x + 3) ^ 2))
      x

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ),
      x ^ 6 + 3 * x ^ 4 + 4 * x ^ 3 + 2 * x ^ 2 + 5 * x + 3 ≠ 0 →
        HasDerivAt (fun x ↦ 1 / (x ^ 6 + 3 * x ^ 4 + 4 * x ^ 3 + 2 * x ^ 2 + 5 * x + 3))
          (-((6 * x ^ 5 + 12 * x ^ 3 + 12 * x ^ 2 + 4 * x + 5) /
              (x ^ 6 + 3 * x ^ 4 + 4 * x ^ 3 + 2 * x ^ 2 + 5 * x + 3) ^ 2))
          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
          ((CAS.Verified.Expr.nat 1).div
            ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                          ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                      ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                  ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
              (CAS.Verified.Expr.nat 3)))).rawDerivative =
      CAS.Verified.Expr.diff 0
        ((CAS.Verified.Expr.nat 1).div
          ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                        ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                    ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
            (CAS.Verified.Expr.nat 3)))

    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
              ((CAS.Verified.Expr.nat 1).div
                ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                              ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                          ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                      ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
                  (CAS.Verified.Expr.nat 3)))).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ
          (CAS.Verified.Expr.DiffDerivation.build 0
              ((CAS.Verified.Expr.nat 1).div
                ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                              ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                          ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                      ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
                  (CAS.Verified.Expr.nat 3)))).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
                ((CAS.Verified.Expr.nat 1).div
                  ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                                ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                            ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                        ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
                    (CAS.Verified.Expr.nat 3))))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  ((CAS.Verified.Expr.nat 1).div
                    ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                                  ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                              ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                          ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
                      (CAS.Verified.Expr.nat 3))))).rhs =
          CAS.Verified.Expr.eval ρ
            (CAS.Verified.Expr.DiffDerivation.build 0
                ((CAS.Verified.Expr.nat 1).div
                  ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                                ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                            ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                        ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
                    (CAS.Verified.Expr.nat 3)))).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
          ((CAS.Verified.Expr.nat 1).div
            ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                          ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                      ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                  ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
              (CAS.Verified.Expr.nat 3))) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0
                  ((CAS.Verified.Expr.nat 1).div
                    ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                                  ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                              ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                          ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
                      (CAS.Verified.Expr.nat 3))))).nonzero →
          (fderiv ℝ
                (fun y ↦
                  CAS.Verified.Expr.eval y.ofLp
                    ((CAS.Verified.Expr.nat 1).div
                      ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                                    ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                                ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                            ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
                        (CAS.Verified.Expr.nat 3))))
                x)
              (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute
                  (CAS.Verified.Expr.DiffDerivation.build 0
                    ((CAS.Verified.Expr.nat 1).div
                      ((((((𝕏[0].pow 6).add ((CAS.Verified.Expr.nat 3).mul (𝕏[0].pow 4))).add
                                    ((CAS.Verified.Expr.nat 4).mul (𝕏[0].pow 3))).add
                                ((CAS.Verified.Expr.nat 2).mul (𝕏[0].pow 2))).add
                            ((CAS.Verified.Expr.nat 5).mul 𝕏[0])).add
                        (CAS.Verified.Expr.nat 3))))).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^6 + 3*x^4 + 4*x^3 + 2*x^2 + 5*x + 3
    Raw checked positivity requirements: (none)
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

      raw result: (0*(x^6 + 3*x^4 + 4*x^3 + 2*x^2 + 5*x + 3) - 1*(6*x^5*1 + 0*x^4 + 3*4*x^3*1 + 0*x^3 + 4*3*x^2*1 + 0*x^2 + 2*2*x^1*1 + 0*x + 5*1 + 0))/(x^6 + 3*x^4 + 4*x^3 + 2*x^2 + 5*x + 3)^2
    • 2. Normalize the symbolic derivative unconditionally

      normalized result: -((6*x^5 + 12*x^3 + 12*x^2 + 4*x + 5)/(x^6 + 3*x^4 + 4*x^3 + 2*x^2 + 5*x + 3)^2)
    • 3. Apply checked side-conditioned cleanup

      displayed result: -((6*x^5 + 12*x^3 + 12*x^2 + 4*x + 5)/(x^6 + 3*x^4 + 4*x^3 + 2*x^2 + 5*x + 3)^2)
      additional nonzero requirements: (none)

A combination of error functions:

In[30]:=
#cas [derive x] (2 * erf (3 * x + 1) - erf (x / 2))
Out[30]=

derivative

12πe−(3x+1)2−e−(x2)2π
12/sqrt(pi)*exp(-(3*x + 1)^2) - exp(-(x/2)^2)/sqrt(pi)
Input (sum of c * erf (A x + B))
(2 * erf (3 * x + 1) - erf (x / 2))

Checked by Lean’s kernel: Derivative of the input

∀ (x : ℝ),
  HasDerivAt (fun x ↦ 2 * CAS.erf (3 * x + 1) - CAS.erf (x / 2))
    (12 / √Real.pi * Real.exp (-(3 * x + 1) ^ 2) - Real.exp (-(x / 2) ^ 2) / √Real.pi) x

from CAS.hasDerivAt_erf

The certificate: 1 checked step
  1. Derivative of the input

    ∀ (x : ℝ),
      HasDerivAt (fun x ↦ 2 * CAS.erf (3 * x + 1) - CAS.erf (x / 2))
        (12 / √Real.pi * Real.exp (-(3 * x + 1) ^ 2) - Real.exp (-(x / 2) ^ 2) / √Real.pi) x

    Checked by Lean’s kernel · CAS.hasDerivAt_erf


The function xx:

In[31]:=
#cas [derive x] (x ^ x)
Out[31]=
xx(1+log(x))
x^x*(1 + log(x))
Conditions
x>0

Checked by Lean’s kernel: Derivative of the input

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

from CAS.Command.hasDerivAt_of_displayRoute

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

    ∀ (x : ℝ), 0 < x → HasDerivAt (fun x ↦ x ^ x) (x ^ x * (1 + Real.log x)) 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].rpow 𝕏[0])).rawDerivative =
      CAS.Verified.Expr.diff 0 (𝕏[0].rpow 𝕏[0])

    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].rpow 𝕏[0])).simplifiedDerivative =
        CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].rpow 𝕏[0])).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].rpow 𝕏[0]))).nonzero →
        CAS.Verified.Expr.eval ρ
            (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].rpow 𝕏[0]))).rhs =
          CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].rpow 𝕏[0])).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].rpow 𝕏[0]) →
        CAS.Verified.Expr.Alg.SideHolds x.ofLp
            (CAS.Command.displayDerivativeRoute
                (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].rpow 𝕏[0]))).nonzero →
          (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp (𝕏[0].rpow 𝕏[0])) x) (EuclideanSpace.single 0 1) =
            CAS.Verified.Expr.eval x.ofLp
              (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].rpow 𝕏[0]))).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: sqrt(x)
    Raw checked positivity requirements: x
  • Partial derivative in x

    • 1. Apply symbolic differentiation rules

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

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

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

See Also

grad · integrate · series · limit · cas