Mode of #cas

simplify

Simplifies a real expression by checked rewrites, with the conditions under which the result equals it.

#cas [simplify] e
simplifies the real expression e by exact rewrites and gives the conditions under which the result equals e.

simplify reduces an expression and tells you when the result equals it. Every rewrite is checked, and the theorem under the answer proves the equality wherever the printed conditions hold. The conditions are sufficient, not necessary, so the result can also equal the input where they fail. x2 simplifies to x under x>0, for example, and the two agree at x=0 as well.

The conditions are there because Lean’s division is total: 1/0=0. At x=1 the quotient (x4−1)/(x2−1) is 0/0=0 in Lean, while x2+1 is 2. So the identity holds where x2−1≠0, and that is the condition the theorem carries. Without that condition the identity is false in Lean, and that is easy to miss when you copy an answer from a computer algebra system into a proof.

Details and Options

  • The theorem has the form ∀x1,…,xn,c1→…→ck→e=e′ about Mathlib’s real functions, where e′ is the printed result and c1,…,ck are the printed conditions. For x + x it is ∀ (x : ℝ), x + x = 2 * x. The report prints the result and the conditions in a display form, so the theorem may have x * x - 1 ≠ 0 where the report prints x2−1≠0.
  • “The certificate” shows two steps: that theorem, and the same statement for SymLean’s internal expressions, from which it is transported. When the proof of the first takes more than its own budget of maxHeartbeats heartbeats, the report keeps only the internal statement.
  • The variables are real. The functions are abs, sin, cos, tan, sinh, cosh, tanh, atan, asin, acos, exp, log and sqrt, with +, -, *, / and powers. A power with a variable exponent is a real power.
  • Cancelling a divisor d adds the condition d≠0, and combining real powers of a adds the condition a>0.
  • A condition is printed as a polynomial only when it equals that polynomial for every value of its variables. Otherwise it keeps the form it has in the input.
  • set_option cas.suggest true adds the theorem as an example to paste in place of the command, when that example elaborates in your file to the same statement.
  • A bare #cas e with no mode also simplifies (see #cas). fullSimplify tries many more forms and keeps the simplest.
  • The tactic cas proves the same identities, with the conditions as hypotheses.

Examples (18)#

Basic Examples (3)

A quotient that cancels, with the condition that makes the cancellation valid:

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

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div
                ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ
            (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div
                  ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ
            (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div
                  ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: x^2 - 1
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

Like terms are collected. No condition is needed:

In[2]:=
#cas [simplify] (x + x)
Out[2]=
2*x

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ), x + x = 2 * x

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ), x + x = 2 * x

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ (𝕏[0].add 𝕏[0]).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ (𝕏[0].add 𝕏[0]).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ (𝕏[0].add 𝕏[0]).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: (none)
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

In Mathlib tanx is sinx/cosx, so where cosx=0 the product tanxcosx is 0, not sinx. The condition says so:

In[3]:=
#cas [simplify] (tan x * cos x)
Out[3]=
sin(x)
sin(x)
Conditions
cos(x)≠0

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ), Real.cos x ≠ 0 → Real.tan x * Real.cos x = Real.sin x

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ), Real.cos x ≠ 0 → Real.tan x * Real.cos x = Real.sin x

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ ((𝕏[0].sin.div 𝕏[0].cos).mul 𝕏[0].cos).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ ((𝕏[0].sin.div 𝕏[0].cos).mul 𝕏[0].cos).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ ((𝕏[0].sin.div 𝕏[0].cos).mul 𝕏[0].cos).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: cos(x)
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

Scope (3)

The rewrites reach inside functions:

In[4]:=
#cas [simplify] (exp ((x^2 - y^2)/(x - y)))
Out[4]=
ex+y
exp(x + y)
Conditions
x−y≠0

Checked by Lean’s kernel: Identity with the simplified form

∀ (x y : ℝ), x - y ≠ 0 → Real.exp ((x ^ 2 - y ^ 2) / (x - y)) = Real.exp (x + y)

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x y : ℝ), x - y ≠ 0 → Real.exp ((x ^ 2 - y ^ 2) / (x - y)) = Real.exp (x + y)

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 2 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          (((𝕏[0].pow 2).sub (𝕏[1].pow 2)).div (𝕏[0].sub 𝕏[1])).exp.simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ
            (((𝕏[0].pow 2).sub (𝕏[1].pow 2)).div (𝕏[0].sub 𝕏[1])).exp.simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ
            (((𝕏[0].pow 2).sub (𝕏[1].pow 2)).div (𝕏[0].sub 𝕏[1])).exp.simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x, y
  • Checked symbolic computation

    Raw checked nonzero requirements: x - y
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

Real powers of one base are combined, for a positive base:

In[5]:=
#cas [simplify] (a ^ p * a * sqrt a / a ^ q)
Out[5]=
ap−q+32
a^(p - q + 3/2)
Conditions
a>0

Checked by Lean’s kernel: Identity with the simplified form

∀ (a p q : ℝ), 0 < a → a ^ p * a * √a / a ^ q = a ^ (p - q + 3 / 2)

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (a p q : ℝ), 0 < a → a ^ p * a * √a / a ^ q = a ^ (p - q + 3 / 2)

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 3 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          ((((𝕏[0].rpow 𝕏[1]).mul 𝕏[0]).mul 𝕏[0].sqrt).div (𝕏[0].rpow 𝕏[2])).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ
            ((((𝕏[0].rpow 𝕏[1]).mul 𝕏[0]).mul 𝕏[0].sqrt).div (𝕏[0].rpow 𝕏[2])).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ
            ((((𝕏[0].rpow 𝕏[1]).mul 𝕏[0]).mul 𝕏[0].sqrt).div (𝕏[0].rpow 𝕏[2])).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: a, p, q
  • Checked symbolic computation

    Raw checked nonzero requirements: sqrt(a)
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

A division does not always need a condition. Where cosx=0 both sides are 0, so this identity holds for every x:

In[6]:=
#cas [simplify] (tan x + sin x / cos x)
Out[6]=
2sin(x)cos(x)
2*sin(x)/cos(x)

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ), Real.tan x + Real.sin x / Real.cos x = 2 * Real.sin x / Real.cos x

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ), Real.tan x + Real.sin x / Real.cos x = 2 * Real.sin x / Real.cos x

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          ((𝕏[0].sin.div 𝕏[0].cos).add (𝕏[0].sin.div 𝕏[0].cos)).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ ((𝕏[0].sin.div 𝕏[0].cos).add (𝕏[0].sin.div 𝕏[0].cos)).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ ((𝕏[0].sin.div 𝕏[0].cos).add (𝕏[0].sin.div 𝕏[0].cos)).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: (none)
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

Options (2)

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

In[7]:=
set_option cas.suggest true in
#cas [simplify] (x + x)
Out[7]=
2*x

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ), x + x = 2 * x

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ), x + x = 2 * x

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ (𝕏[0].add 𝕏[0]).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ (𝕏[0].add 𝕏[0]).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ (𝕏[0].add 𝕏[0]).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: (none)
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

Try this

example (x : ℝ) : x + x = 2 * x := by cas

Here it is pasted, and cas proves it:

In[8]:=
example (x : ℝ) : x + x = 2 * x := by cas
Out[8]=

Lean accepts the proof.

Applications (3)

The first example as a theorem in a proof. The hypothesis is the printed condition, and only the three standard axioms are used:

In[9]:=
theorem quartic_over_quadratic (x : ℝ) (h : x ^ 2 - 1 ≠ 0) :
    (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1 := by
  cas

#print axioms quartic_over_quadratic
Out[9]=

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


A quotient under a square root. One hypothesis is enough for the cancellation:

In[10]:=
example (x y : ℝ) (h : x ^ 2 - y ^ 2 ≠ 0) :
    Real.sqrt ((x ^ 4 - y ^ 4) / (x ^ 2 - y ^ 2)) = Real.sqrt (x ^ 2 + y ^ 2) := by
  cas
Out[10]=

Lean accepts the proof.


The tangent example, with its condition as a hypothesis:

In[11]:=
example (x : ℝ) (h : Real.cos x ≠ 0) : Real.tan x * Real.cos x = Real.sin x := by
  cas
Out[11]=

Lean accepts the proof.

Properties and Relations (2)

A bare #cas with no mode simplifies too, with the same report:

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

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div
                ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ
            (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div
                  ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ
            (((𝕏[0].pow 4).sub (CAS.Verified.Expr.nat 1)).div
                  ((𝕏[0].pow 2).sub (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: x^2 - 1
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

fullSimplify tries many forms, the logarithm rules among them, and keeps the simplest. Here it finds that the expression is 0:

In[13]:=
#cas [fullSimplify] (log (x*y) - log x - log y)
Out[13]=
0
Conditions
x≠0, y≠0

Checked by Lean’s kernel: Identity with the logarithm expansion and simplification

∀ (x y : ℝ), x ≠ 0 → y ≠ 0 → Real.log (x * y) - Real.log x - Real.log y = 0
The certificate: 1 checked step
  1. Identity with the logarithm expansion and simplification

    ∀ (x y : ℝ), x ≠ 0 → y ≠ 0 → Real.log (x * y) - Real.log x - Real.log y = 0

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    logarithm expansion and simplification: 0  [leafCount 1, conditions 2]
    input: log(x*y) - log(x) - log(y)  [leafCount 10, conditions 0]
    configured simplification: -log(x) - log(y) + log(x*y)  [leafCount 12, conditions 0]
    exact passes: log(x*y) + -log(x) - log(y)  [leafCount 12, conditions 0]

Possible Issues (4)

An identifier applied to an argument is read as a function. Write a product as x * y:

In[14]:=
#cas [simplify] (x y)
Out[14]=

Error

unsupported symbolic function 'x'; expected abs, sin, cos, tan, sinh, cosh, tanh, atan/arctan, asin/arcsin, acos/arccos, exp, log, or sqrt. If multiplication was intended, write it explicitly with `*`

The divisor here equals −(x2−x+1) only where x≠0 and x≠1 (at x=0 it is 0, since 1/0=0), so the condition keeps the form of the input:

In[15]:=
#cas [simplify] ((1 / (1/x + 1/(1-x)) - 1) / (1 / (1/x + 1/(1-x)) - 1))
Out[15]=
1
Conditions
11x+11−x−1≠0

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ),
  1 / (1 / x + 1 / (1 - x)) - 1 ≠ 0 → (1 / (1 / x + 1 / (1 - x)) - 1) / (1 / (1 / x + 1 / (1 - x)) - 1) = 1

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ),
      1 / (1 / x + 1 / (1 - x)) - 1 ≠ 0 → (1 / (1 / x + 1 / (1 - x)) - 1) / (1 / (1 / x + 1 / (1 - x)) - 1) = 1

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          ((((CAS.Verified.Expr.nat 1).div
                        (((CAS.Verified.Expr.nat 1).div 𝕏[0]).add
                          ((CAS.Verified.Expr.nat 1).div ((CAS.Verified.Expr.nat 1).sub 𝕏[0])))).sub
                    (CAS.Verified.Expr.nat 1)).div
                (((CAS.Verified.Expr.nat 1).div
                      (((CAS.Verified.Expr.nat 1).div 𝕏[0]).add
                        ((CAS.Verified.Expr.nat 1).div ((CAS.Verified.Expr.nat 1).sub 𝕏[0])))).sub
                  (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ
            ((((CAS.Verified.Expr.nat 1).div
                          (((CAS.Verified.Expr.nat 1).div 𝕏[0]).add
                            ((CAS.Verified.Expr.nat 1).div ((CAS.Verified.Expr.nat 1).sub 𝕏[0])))).sub
                      (CAS.Verified.Expr.nat 1)).div
                  (((CAS.Verified.Expr.nat 1).div
                        (((CAS.Verified.Expr.nat 1).div 𝕏[0]).add
                          ((CAS.Verified.Expr.nat 1).div ((CAS.Verified.Expr.nat 1).sub 𝕏[0])))).sub
                    (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ
            ((((CAS.Verified.Expr.nat 1).div
                          (((CAS.Verified.Expr.nat 1).div 𝕏[0]).add
                            ((CAS.Verified.Expr.nat 1).div ((CAS.Verified.Expr.nat 1).sub 𝕏[0])))).sub
                      (CAS.Verified.Expr.nat 1)).div
                  (((CAS.Verified.Expr.nat 1).div
                        (((CAS.Verified.Expr.nat 1).div 𝕏[0]).add
                          ((CAS.Verified.Expr.nat 1).div ((CAS.Verified.Expr.nat 1).sub 𝕏[0])))).sub
                    (CAS.Verified.Expr.nat 1))).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: 1/(1/x + 1/(1 - x)) - 1
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation

x2 is |x|, not x, and simplify leaves it as it is. fullSimplify finds the absolute value of a square under a root:

In[16]:=
#cas [simplify] (sqrt (x ^ 2))
Out[16]=
x2
sqrt(x^2)

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ), √(x ^ 2) = √(x * x)

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ), √(x ^ 2) = √(x * x)

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ (𝕏[0].pow 2).sqrt.simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ (𝕏[0].pow 2).sqrt.simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ (𝕏[0].pow 2).sqrt.simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: (none)
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation
In[17]:=
#cas [fullSimplify] (sqrt (x^2 + 2*x + 1))
Out[17]=
|x+1|
|x + 1|

Checked by Lean’s kernel: Identity with the square root of a square

∀ (x : ℝ), √(x ^ 2 + 2 * x + 1) = |x + 1|
The certificate: 1 checked step
  1. Identity with the square root of a square

    ∀ (x : ℝ), √(x ^ 2 + 2 * x + 1) = |x + 1|

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    square root of a square: |x + 1|  [leafCount 4, conditions 0]
    input: sqrt(x^2 + 2*x + 1)  [leafCount 10, conditions 0]
    configured simplification: sqrt(x^2 + 2*(x + 1/2))  [leafCount 12, conditions 0]

Without its condition the first identity is false in Lean. At x=1 the left side is 0/0=0 and the right side is 2:

In[18]:=
example : ¬ ∀ x : ℝ, (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1 := by
  intro h
  have := h 1
  norm_num at this
Out[18]=

Lean accepts the proof.

Neat Examples (1)

An exponent that is itself a real power. Since 41/2=2, the result is x2 for every real x, negative ones included:

In[19]:=
#cas [simplify] (x ^ ((4 : ℝ) ^ (1 / 2 : ℝ)))
Out[19]=
x2
x^2

Checked by Lean’s kernel: Identity with the simplified form

∀ (x : ℝ), x ^ ((4 : ℝ) ^ (1 / 2 : ℝ) : ℝ) = x ^ 2

from CAS.Command.eq_of_simplifyFinDisplayRoute

The certificate: 2 checked steps
  1. Identity with the simplified form

    ∀ (x : ℝ), x ^ ((4 : ℝ) ^ (1 / 2 : ℝ) : ℝ) = x ^ 2

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

  2. Simplification under generated rewrite assumptions

    ∀ (ρ : Fin 1 → ℝ),
      CAS.Verified.Expr.Alg.SideHolds ρ
          (𝕏[0].rpow
                ((CAS.Verified.Expr.nat 4).rpow
                  ((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)))).simplifyFinDisplayRoute.nonzero →
        CAS.Verified.Expr.eval ρ
            (𝕏[0].rpow
                  ((CAS.Verified.Expr.nat 4).rpow
                    ((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)))).simplifyFinDisplayRoute.rhs =
          CAS.Verified.Expr.eval ρ
            (𝕏[0].rpow
                  ((CAS.Verified.Expr.nat 4).rpow
                    ((CAS.Verified.Expr.nat 1).div (CAS.Verified.Expr.nat 2)))).simplifyFinDisplayRoute.lhs

    Checked by Lean’s kernel · CAS.Verified.Expr.SideClaimRoute.sound

The computation
  • Variables: x
  • Checked symbolic computation

    Raw checked nonzero requirements: (none)
    Guarantee: these assumptions justify conditional rewrites and preserve real evaluation
In[20]:=
example (x : ℝ) : x ^ ((4 : ℝ) ^ (1 / 2 : ℝ) : ℝ) = x ^ 2 := by cas
Out[20]=

Lean accepts the proof.

See Also

fullSimplify · together · cancel · factor · #cas · cas