Mode of #cas
simplify
Simplifies a real expression by checked rewrites, with the conditions under which the result equals it.
#cas [simplify] esimplify 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. simplifies to under , for example, and the two agree at as well.
The conditions are there because Lean’s division is total: . At the quotient is in Lean, while is . So the identity holds where , 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.
Examples (18)#
Basic Examples (3)
A quotient that cancels, with the condition that makes the cancellation valid:
#cas [simplify] ((x ^ 4 - 1) / (x ^ 2 - 1))
x^2 + 1- Conditions
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
Identity with the simplified form
∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
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
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:
#cas [simplify] (x + x)
2*xChecked 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
Identity with the simplified form
∀ (x : ℝ), x + x = 2 * x
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
The computation
Variables: x
Checked symbolic computation
Raw checked nonzero requirements: (none) Guarantee: these assumptions justify conditional rewrites and preserve real evaluation
In Mathlib is , so where the product is , not . The condition says so:
#cas [simplify] (tan x * cos x)
sin(x)- Conditions
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
Identity with the simplified form
∀ (x : ℝ), Real.cos x ≠ 0 → Real.tan x * Real.cos x = Real.sin x
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
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:
#cas [simplify] (exp ((x^2 - y^2)/(x - y)))
exp(x + y)- Conditions
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
Identity with the simplified form
∀ (x y : ℝ), x - y ≠ 0 → Real.exp ((x ^ 2 - y ^ 2) / (x - y)) = Real.exp (x + y)
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
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:
#cas [simplify] (a ^ p * a * sqrt a / a ^ q)
a^(p - q + 3/2)- Conditions
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
Identity with the simplified form
∀ (a p q : ℝ), 0 < a → a ^ p * a * √a / a ^ q = a ^ (p - q + 3 / 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
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 both sides are , so this identity holds for every :
#cas [simplify] (tan x + sin 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
Identity with the simplified form
∀ (x : ℝ), Real.tan x + Real.sin x / Real.cos x = 2 * Real.sin x / Real.cos x
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
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:
set_option cas.suggest true in #cas [simplify] (x + x)
2*xChecked 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
Identity with the simplified form
∀ (x : ℝ), x + x = 2 * x
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
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:
example (x : ℝ) : x + x = 2 * x := by cas
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:
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
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:
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
Lean accepts the proof.
The tangent example, with its condition as a hypothesis:
example (x : ℝ) (h : Real.cos x ≠ 0) : Real.tan x * Real.cos x = Real.sin x := by cas
Lean accepts the proof.
Properties and Relations (2)
A bare #cas with no mode simplifies too, with the same report:
#cas ((x ^ 4 - 1) / (x ^ 2 - 1))
x^2 + 1- Conditions
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
Identity with the simplified form
∀ (x : ℝ), x * x - 1 ≠ 0 → (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1
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
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 :
#cas [fullSimplify] (log (x*y) - log x - log y)
0- Conditions
- ,
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
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 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:
#cas [simplify] (x y)
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 only where and (at it is , since ), so the condition keeps the form of the input:
#cas [simplify] ((1 / (1/x + 1/(1-x)) - 1) / (1 / (1/x + 1/(1-x)) - 1))
1- Conditions
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
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
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
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
is , not , and simplify leaves it as it is. fullSimplify finds the absolute value of a square under a root:
#cas [simplify] (sqrt (x ^ 2))
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
Identity with the simplified form
∀ (x : ℝ), √(x ^ 2) = √(x * x)
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
The computation
Variables: x
Checked symbolic computation
Raw checked nonzero requirements: (none) Guarantee: these assumptions justify conditional rewrites and preserve real evaluation
#cas [fullSimplify] (sqrt (x^2 + 2*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
Identity with the square root of a square
∀ (x : ℝ), √(x ^ 2 + 2 * x + 1) = |x + 1|
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 the left side is and the right side is :
example : ¬ ∀ x : ℝ, (x ^ 4 - 1) / (x ^ 2 - 1) = x ^ 2 + 1 := by intro h have := h 1 norm_num at this
Lean accepts the proof.
Neat Examples (1)
An exponent that is itself a real power. Since , the result is for every real , negative ones included:
#cas [simplify] (x ^ ((4 : ℝ) ^ (1 / 2 : ℝ)))
x^2Checked 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
Identity with the simplified form
∀ (x : ℝ), x ^ ((4 : ℝ) ^ (1 / 2 : ℝ) : ℝ) = x ^ 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
The computation
Variables: x
Checked symbolic computation
Raw checked nonzero requirements: (none) Guarantee: these assumptions justify conditional rewrites and preserve real evaluation
example (x : ℝ) : x ^ ((4 : ℝ) ^ (1 / 2 : ℝ) : ℝ) = x ^ 2 := by cas
Lean accepts the proof.
