Mode of #cas
cancel
Cancels common factors in each summand of a rational expression, with the conditions under which the result equals the input.
#cas [cancel] ecancel reduces each fraction in a sum on its own and keeps the terms apart, which is what I want when a sum reads better term by term. together would make one fraction of it.
The catch is the factor you cancel. Cancelling a factor is valid only where , and in Lean this matters, because division is total. At the quotient is , while is . So the theorem has a condition for each divisor of the input.
Examples (9)#
Basic Examples (1)
The first summand reduces to , and stays:
#cas [cancel] ((x^2-1)/(x-1) + 1/x)
cancelled
x + 1 + 1/x- Input (rational function)
((x^2-1)/(x-1) + 1/x)- Conditions
- ,
Checked by Lean’s kernel: Identity with the cancelled form
∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = x + 1 + 1 / x
The certificate: 1 checked step
Identity with the cancelled form
∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = x + 1 + 1 / x
Scope (2)
Two variables:
#cas [cancel] ((x^3 - y^3)/(x - y) + 1/y)
cancelled
x^2 + x*y + y^2 + 1/y- Input (rational function)
((x^3 - y^3)/(x - y) + 1/y)- Conditions
- ,
Checked by Lean’s kernel: Identity with the cancelled form
∀ (x y : ℝ), x - y ≠ 0 → y ≠ 0 → (x ^ 3 - y ^ 3) / (x - y) + 1 / y = x ^ 2 + x * y + y ^ 2 + 1 / y
The certificate: 1 checked step
Identity with the cancelled form
∀ (x y : ℝ), x - y ≠ 0 → y ≠ 0 → (x ^ 3 - y ^ 3) / (x - y) + 1 / y = x ^ 2 + x * y + y ^ 2 + 1 / y
A difference of two quotients, each reduced on its own:
#cas [cancel] ((x^2 - y^2)/(x - y) - (x^3 - 1)/(x - 1))
cancelled
x + y - (x^2 + x + 1)- Input (rational function)
((x^2 - y^2)/(x - y) - (x^3 - 1)/(x - 1))- Conditions
- ,
Checked by Lean’s kernel: Identity with the cancelled form
∀ (x y : ℝ), x - y ≠ 0 → x - 1 ≠ 0 → (x ^ 2 - y ^ 2) / (x - y) - (x ^ 3 - 1) / (x - 1) = x + y - (x ^ 2 + x + 1)
The certificate: 1 checked step
Identity with the cancelled form
∀ (x y : ℝ), x - y ≠ 0 → x - 1 ≠ 0 → (x ^ 2 - y ^ 2) / (x - y) - (x ^ 3 - 1) / (x - 1) = x + y - (x ^ 2 + x + 1)
Applications (2)
The first example as a theorem. Only is needed, since is on both sides, and only the three standard axioms are used:
theorem cancel_then_add (x : ℝ) (h : x - 1 ≠ 0) : (x ^ 2 - 1) / (x - 1) + 1 / x = x + 1 + 1 / x := by cas #print axioms cancel_then_add
cancel_then_add depends on the axioms propext, Classical.choice, Quot.sound.
Without that condition the cancellation is false in Lean. At the left side is and the right side is :
example : ¬ ∀ x : ℝ, (x ^ 2 - 1) / (x - 1) = x + 1 := by intro h have := h 1 norm_num at this
Lean accepts the proof.
Properties and Relations (2)
together makes one fraction of the same sum:
#cas [together] ((x^2-1)/(x-1) + 1/x)
common denominator
(x^2 + x + 1)/x- Input (rational function)
((x^2-1)/(x-1) + 1/x)- Conditions
- ,
Checked by Lean’s kernel: Identity with the common-denominator form
∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = (x ^ 2 + x + 1) / x
The certificate: 1 checked step
Identity with the common-denominator form
∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = (x ^ 2 + x + 1) / x
simplify cancels a quotient as well:
#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
Possible Issues (2)
A function other than the field operations is refused:
#cas [cancel] (sin x / x)
Error
cancel: the expression is not a rational function: it has a function other than the field operations and natural powers
simplify cancels 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
See Also
together · simplify · factor · polynomialGCD
