Mode of #cas
apart
Writes a rational function of one variable as a polynomial plus partial fractions, with the conditions of the identity.
#cas [apart] e#cas [apart x] eapart writes a rational function as a polynomial plus partial fractions. It undoes together, and it plays the part of Mathematica’s Apart. Partial fractions are worth having for two reasons: they show the poles of a function at a glance, and they often make it easier to integrate.
The thing to watch is the poles themselves. The theorem holds where the divisors of the input are nonzero, and it has to say so, because Lean’s division is total. At a pole both sides are computed with , and they can differ. At , for instance, the fraction is in Lean, while is .
Examples (12)#
Basic Examples (2)
Two linear factors:
#cas [apart] (1/((x - 1)*(x + 1)))
partial fractions
1/(2*(x - 1)) - 1/(2*(x + 1))- Input (rational function)
(1/((x - 1)*(x + 1)))- Conditions
Checked by Lean’s kernel: Identity with the partial fraction decomposition
∀ (x : ℝ), (x - 1) * (x + 1) ≠ 0 → 1 / ((x - 1) * (x + 1)) = 1 / (2 * (x - 1)) - 1 / (2 * (x + 1))
The certificate: 1 checked step
Identity with the partial fraction decomposition
∀ (x : ℝ), (x - 1) * (x + 1) ≠ 0 → 1 / ((x - 1) * (x + 1)) = 1 / (2 * (x - 1)) - 1 / (2 * (x + 1))
A polynomial part, a quadratic factor and a triple pole:
#cas [apart] (x^5/((x^2+1)*(x-1)^3))
partial fractions over the written factors, refined by gcds
1 + (x + 1)/(4*(x^2 + 1)) + 1/(2*(x - 1)^3) + 2/(x - 1)^2 + 11/(4*(x - 1))- Input (rational function)
(x^5/((x^2+1)*(x-1)^3))- Conditions
Checked by Lean’s kernel: Identity with the partial fraction decomposition
∀ (x : ℝ), (x ^ 2 + 1) * (x - 1) ^ 3 ≠ 0 → x ^ 5 / ((x ^ 2 + 1) * (x - 1) ^ 3) = 1 + (x + 1) / (4 * (x ^ 2 + 1)) + 1 / (2 * (x - 1) ^ 3) + 2 / (x - 1) ^ 2 + 11 / (4 * (x - 1))
The certificate: 1 checked step
Identity with the partial fraction decomposition
∀ (x : ℝ), (x ^ 2 + 1) * (x - 1) ^ 3 ≠ 0 → x ^ 5 / ((x ^ 2 + 1) * (x - 1) ^ 3) = 1 + (x + 1) / (4 * (x ^ 2 + 1)) + 1 / (2 * (x - 1) ^ 3) + 2 / (x - 1) ^ 2 + 11 / (4 * (x - 1))
Scope (2)
Over one quadratic factor, the polynomial part is split off:
#cas [apart] (x^3/(x^2+1))
partial fractions over the written factors, refined by gcds
x - x/(x^2 + 1)- Input (rational function)
(x^3/(x^2+1))- Conditions
Checked by Lean’s kernel: Identity with the partial fraction decomposition
∀ (x : ℝ), x ^ 2 + 1 ≠ 0 → x ^ 3 / (x ^ 2 + 1) = x - x / (x ^ 2 + 1)
The certificate: 1 checked step
Identity with the partial fraction decomposition
∀ (x : ℝ), x ^ 2 + 1 ≠ 0 → x ^ 3 / (x ^ 2 + 1) = x - x / (x ^ 2 + 1)
#cas [apart] ((x^4 + 1)/(x^2 + 1))
partial fractions over the written factors, refined by gcds
x^2 - 1 + 2/(x^2 + 1)- Input (rational function)
((x^4 + 1)/(x^2 + 1))- Conditions
Checked by Lean’s kernel: Identity with the partial fraction decomposition
∀ (x : ℝ), x ^ 2 + 1 ≠ 0 → (x ^ 4 + 1) / (x ^ 2 + 1) = x ^ 2 - 1 + 2 / (x ^ 2 + 1)
The certificate: 1 checked step
Identity with the partial fraction decomposition
∀ (x : ℝ), x ^ 2 + 1 ≠ 0 → (x ^ 4 + 1) / (x ^ 2 + 1) = x ^ 2 - 1 + 2 / (x ^ 2 + 1)
The written factors are refined by gcds. The common factor of and comes out as the base of a power:
#cas [apart] (1/((x^4 + x^2)*(x^3 + x^2)))
partial fractions over the written factors, refined by gcds
-(x - 1)/(2*(x^2 + 1)) + 1/(2*(x + 1)) - (x - 1)/(x^2)^2- Input (rational function)
(1/((x^4 + x^2)*(x^3 + x^2)))- Conditions
Checked by Lean’s kernel: Identity with the partial fraction decomposition
∀ (x : ℝ), (x ^ 4 + x ^ 2) * (x ^ 3 + x ^ 2) ≠ 0 → 1 / ((x ^ 4 + x ^ 2) * (x ^ 3 + x ^ 2)) = -((x - 1) / (2 * (x ^ 2 + 1))) + 1 / (2 * (x + 1)) - (x - 1) / (x ^ 2) ^ 2
The certificate: 1 checked step
Identity with the partial fraction decomposition
∀ (x : ℝ), (x ^ 4 + x ^ 2) * (x ^ 3 + x ^ 2) ≠ 0 → 1 / ((x ^ 4 + x ^ 2) * (x ^ 3 + x ^ 2)) = -((x - 1) / (2 * (x ^ 2 + 1))) + 1 / (2 * (x + 1)) - (x - 1) / (x ^ 2) ^ 2
Options (1)
A variable after the mode name says which variable the function is in. Large roots are no trouble:
#cas [apart x] (1 / ((x - 100000001) * (x - 2)))
partial fractions
1/(99999999*(x - 100000001)) - 1/(99999999*(x - 2))- Input (rational function)
(1 / ((x - 100000001) * (x - 2)))- Conditions
Checked by Lean’s kernel: Identity with the partial fraction decomposition
∀ (x : ℝ), (x - 100000001) * (x - 2) ≠ 0 → 1 / ((x - 100000001) * (x - 2)) = 1 / (99999999 * (x - 100000001)) - 1 / (99999999 * (x - 2))
The certificate: 1 checked step
Identity with the partial fraction decomposition
∀ (x : ℝ), (x - 100000001) * (x - 2) ≠ 0 → 1 / ((x - 100000001) * (x - 2)) = 1 / (99999999 * (x - 100000001)) - 1 / (99999999 * (x - 2))
Applications (3)
The first example as a theorem, with the printed condition as hypothesis. Only the three standard axioms are used:
theorem apart_two_linear (x : ℝ) (h : (x - 1) * (x + 1) ≠ 0) : 1 / ((x - 1) * (x + 1)) = 1 / (2 * (x - 1)) - 1 / (2 * (x + 1)) := by cas #print axioms apart_two_linear
apart_two_linear depends on the axioms propext, Classical.choice, Quot.sound.
Without its condition the decomposition is false in Lean. At the left side is and the right side is :
example : ¬ ∀ x : ℝ, 1 / (x ^ 2 - 1) = 1 / (2 * (x - 1)) - 1 / (2 * (x + 1)) := by intro h have := h 1 norm_num at this
Lean accepts the proof.
Partial fractions are the first step in integrating a rational function. integrate splits off this denominator:
#cas [integrate x] (1/(x^3 + x))
antiderivative
log(x) - 1/2*log(x^2 + 1)- Conditions
Checked by Lean’s kernel: Integral of the input
∀ (a b : ℝ), (∀ x ∈ Set.uIcc a b, x ≠ 0) → ∫ (x : ℝ) in a..b, 1 / (x ^ 3 + x) = Real.log b - 1 / 2 * Real.log (b ^ 2 + 1) - (Real.log a - 1 / 2 * Real.log (a ^ 2 + 1))
from CAS.IntegrationCheck.AntiderivativeCert.intervalIntegral_eq_sub_of_line
The certificate: 9 checked steps
Integral of the input
∀ (a b : ℝ), (∀ x ∈ Set.uIcc a b, x ≠ 0) → ∫ (x : ℝ) in a..b, 1 / (x ^ 3 + x) = Real.log b - 1 / 2 * Real.log (b ^ 2 + 1) - (Real.log a - 1 / 2 * Real.log (a ^ 2 + 1))
Primitive derivative in x: indexed rules compute Expr.diff
(CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log))).rawDerivative = CAS.Verified.Expr.diff 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log))
Primitive derivative in x: normalization preserves evaluation
∀ (ρ : Fin 1 → ℝ), CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log))).simplifiedDerivative = CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log))).rawDerivative
Primitive derivative in x: side-conditioned display normalization
∀ (ρ : Fin 1 → ℝ), CAS.Verified.Expr.Alg.SideHolds ρ (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log)))).nonzero → CAS.Verified.Expr.eval ρ (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log)))).rhs = CAS.Verified.Expr.eval ρ (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log))).simplifiedDerivative
Primitive derivative in x: analytic semantics of the displayed result
∀ (x : ℝ^1), CAS.Verified.Expr.ValidAt x.ofLp (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log)) → CAS.Verified.Expr.Alg.SideHolds x.ofLp (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log)))).nonzero → (fderiv ℝ (fun y ↦ CAS.Verified.Expr.eval y.ofLp (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log))) x) (EuclideanSpace.single 0 1) = CAS.Verified.Expr.eval x.ofLp (CAS.Command.displayDerivativeRoute (CAS.Verified.Expr.DiffDerivation.build 0 (𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log)))).rhs
Residual route reaches zero
(CAS.IntegrationCheck.route 0 ((CAS.Verified.Expr.nat 1).div ((𝕏[0].pow 3).add 𝕏[0])) { candidate := 𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log), routeZero := ⋯ }.candidate).rhs = 0
Symbolic antiderivative identity under the displayed requirements
∀ (x : ℝ^1), { candidate := 𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log), routeZero := ⋯ }.requirements.Holds x.ofLp → CAS.Verified.Expr.eval x.ofLp (CAS.Verified.Expr.diff 0 { candidate := 𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log), routeZero := ⋯ }.candidate) = CAS.Verified.Expr.eval x.ofLp ((CAS.Verified.Expr.nat 1).div ((𝕏[0].pow 3).add 𝕏[0]))
Coordinate-line derivative theorem
∀ (x : ℝ^1) (t : ℝ), { candidate := 𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log), 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 := 𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log), routeZero := ⋯ }.candidate) (CAS.Verified.Expr.eval (x + t • EuclideanSpace.single 0 1).ofLp ((CAS.Verified.Expr.nat 1).div ((𝕏[0].pow 3).add 𝕏[0]))) t
Coordinate-line fundamental theorem of calculus
∀ (x : ℝ^1) (a b : ℝ), (∀ t ∈ Set.uIcc a b, { candidate := 𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log), 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 ((CAS.Verified.Expr.nat 1).div ((𝕏[0].pow 3).add 𝕏[0])) = CAS.Verified.Expr.eval (x + b • EuclideanSpace.single 0 1).ofLp { candidate := 𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log), routeZero := ⋯ }.candidate - CAS.Verified.Expr.eval (x + a • EuclideanSpace.single 0 1).ofLp { candidate := 𝕏[0].log.add ((CAS.Verified.Expr.rat (-1) 2).mul ((𝕏[0].pow 2).add (CAS.Verified.Expr.nat 1)).log), routeZero := ⋯ }.candidate
The computation
Variables: x
Checked antiderivative computation
1. Differentiate the proposed primitive
Raw derivative: 1/x + 0*log(x^2 + 1) - 1/2*(2*x^1*1 + 0)/(x^2 + 1)
2. Form the derivative residual
Raw residual: 1/x + 0*log(x^2 + 1) - 1/2*(2*x^1*1 + 0)/(x^2 + 1) - 1/(x^3 + x) 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): x^2 + 1, x Certificate positivity requirements (compacted): (none)
Properties and Relations (2)
denominator goes back: it recovers the factored denominator of a sum of partial fractions:
#cas [denominator] (1/(x-1) - 1/(x+1))
denominator
(x - 1)*(x + 1)- Input (rational function)
(1/(x-1) - 1/(x+1))- Conditions
- ,
Checked by Lean’s kernel: Identity with the common-denominator form
∀ (x : ℝ), x - 1 ≠ 0 → x + 1 ≠ 0 → 1 / (x - 1) - 1 / (x + 1) = 2 / ((x - 1) * (x + 1))
The certificate: 1 checked step
Identity with the common-denominator form
∀ (x : ℝ), x - 1 ≠ 0 → x + 1 ≠ 0 → 1 / (x - 1) - 1 / (x + 1) = 2 / ((x - 1) * (x + 1))
factor finds the rational roots:
#cas [factor] (x^4 - 5*x^2 + 4)
(x - 1)*(x + 1)*(x - 2)*(x + 2)Checked by Lean’s kernel: Identity with the factored polynomial
∀ (x : ℝ), x ^ 4 - 5 * x ^ 2 + 4 = (x - 1) * (x + 1) * (x - 2) * (x + 2)
The certificate: 1 checked step
Identity with the factored polynomial
∀ (x : ℝ), x ^ 4 - 5 * x ^ 2 + 4 = (x - 1) * (x + 1) * (x - 2) * (x + 2)
The computation
Ranked candidates (proposals, not proof)
factored polynomial: (x - 1)*(x + 1)*(x - 2)*(x + 2) [leafCount 15, conditions 0] input: x^4 - 5*x^2 + 4 [leafCount 11, conditions 0]
Possible Issues (2)
The mode works in one variable:
#cas [apart] (1/(x*y))
Error
apart: expected a rational function of one variable, found the variables x, y
The factors are those written, refined by gcds, and they need not be irreducible. Here the written factor is , and it stays the base of the power:
#cas [apart] (1 / ((x^3 + x - x)^2))
partial fractions over the written factors, refined by gcds
1/(x^3)^2- Input (rational function)
(1 / ((x^3 + x - x)^2))- Conditions
Checked by Lean’s kernel: Identity with the partial fraction decomposition
∀ (x : ℝ), (x ^ 3 + x - x) ^ 2 ≠ 0 → 1 / (x ^ 3 + x - x) ^ 2 = 1 / (x ^ 3) ^ 2
The certificate: 1 checked step
Identity with the partial fraction decomposition
∀ (x : ℝ), (x ^ 3 + x - x) ^ 2 ≠ 0 → 1 / (x ^ 3 + x - x) ^ 2 = 1 / (x ^ 3) ^ 2
See Also
together · factor · integrate · denominator
