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
writes the rational function e of one variable as a polynomial plus a sum of partial fractions and gives the conditions under which they agree.
#cas [apart x] e
does the same with x named as the variable.

apart 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 1/0=0, and they can differ. At x=1, for instance, the fraction 1/((x−1)(x+1)) is 0 in Lean, while 12(x−1)−12(x+1) is −14.

Details and Options

  • The theorem has the form ∀x,d1≠0→…→dm≠0→e=q+∑c/pk, where d1,…,dm are the divisors of e as written, q is a polynomial, each p is a factor of the denominator with integer coefficients, k runs up to its multiplicity and degc<degp. Each p divides one of the di, which ring shows, and field_simp and ring prove the identity.
  • The theorem does not state that the factors are irreducible.
  • The input is a rational function of one variable with rational coefficients. #cas [apart x] e names the variable.
  • The factors are those written in the input, refined by gcds: 1/((x - 1)*(x + 1)) splits, and a factor written as x^2 - 1 stays whole. When a factor of degree two or more remains, the label reads “partial fractions over the written factors, refined by gcds”.
  • When the denominator is one nonlinear factor with exponent 1, only the polynomial part is split off, and a proper fraction with such a denominator is refused.
  • The tactic cas proves these identities, with the conditions as hypotheses.

Examples (12)#

Basic Examples (2)

Two linear factors:

In[1]:=
#cas [apart] (1/((x - 1)*(x + 1)))
Out[1]=

partial fractions

12(x−1)−12(x+1)
1/(2*(x - 1)) - 1/(2*(x + 1))
Input (rational function)
(1/((x - 1)*(x + 1)))
Conditions
(x−1)(x+1)≠0

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
  1. 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))

    Checked by Lean’s kernel


A polynomial part, a quadratic factor and a triple pole:

In[2]:=
#cas [apart] (x^5/((x^2+1)*(x-1)^3))
Out[2]=

partial fractions over the written factors, refined by gcds

1+x+14(x2+1)+12(x−1)3+2(x−1)2+114(x−1)
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
(x2+1)(x−1)3≠0

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
  1. 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))

    Checked by Lean’s kernel

Scope (2)

Over one quadratic factor, the polynomial part is split off:

In[3]:=
#cas [apart] (x^3/(x^2+1))
Out[3]=

partial fractions over the written factors, refined by gcds

x−xx2+1
x - x/(x^2 + 1)
Input (rational function)
(x^3/(x^2+1))
Conditions
x2+1≠0

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
  1. Identity with the partial fraction decomposition

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

    Checked by Lean’s kernel

In[4]:=
#cas [apart] ((x^4 + 1)/(x^2 + 1))
Out[4]=

partial fractions over the written factors, refined by gcds

x2−1+2x2+1
x^2 - 1 + 2/(x^2 + 1)
Input (rational function)
((x^4 + 1)/(x^2 + 1))
Conditions
x2+1≠0

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
  1. Identity with the partial fraction decomposition

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

    Checked by Lean’s kernel


The written factors are refined by gcds. The common factor x2 of x4+x2 and x3+x2 comes out as the base of a power:

In[5]:=
#cas [apart] (1/((x^4 + x^2)*(x^3 + x^2)))
Out[5]=

partial fractions over the written factors, refined by gcds

−x−12(x2+1)+12(x+1)−x−1(x2)2
-(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
(x4+x2)(x3+x2)≠0

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
  1. 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

    Checked by Lean’s kernel

Options (1)

A variable after the mode name says which variable the function is in. Large roots are no trouble:

In[6]:=
#cas [apart x] (1 / ((x - 100000001) * (x - 2)))
Out[6]=

partial fractions

199999999(x−100000001)−199999999(x−2)
1/(99999999*(x - 100000001)) - 1/(99999999*(x - 2))
Input (rational function)
(1 / ((x - 100000001) * (x - 2)))
Conditions
(x−100000001)(x−2)≠0

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
  1. 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))

    Checked by Lean’s kernel

Applications (3)

The first example as a theorem, with the printed condition as hypothesis. Only the three standard axioms are used:

In[7]:=
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
Out[7]=

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


Without its condition the decomposition is false in Lean. At x=1 the left side is 1/0=0 and the right side is −14:

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

Lean accepts the proof.


Partial fractions are the first step in integrating a rational function. integrate splits x off this denominator:

In[9]:=
#cas [integrate x] (1/(x^3 + x))
Out[9]=

antiderivative

log(x)−12log(x2+1)
log(x) - 1/2*log(x^2 + 1)
Conditions
x≠0

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
  1. 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))

    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
          (𝕏[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))

    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
              (𝕏[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

    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
                (𝕏[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

    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
          (𝕏[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

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

  6. 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

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

  7. 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]))

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

  8. 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

    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 :=
                    𝕏[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

    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: 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:

In[10]:=
#cas [denominator] (1/(x-1) - 1/(x+1))
Out[10]=

denominator

(x - 1)*(x + 1)
Input (rational function)
(1/(x-1) - 1/(x+1))
Conditions
x−1≠0, x+1≠0

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
  1. Identity with the common-denominator form

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

    Checked by Lean’s kernel


factor finds the rational roots:

In[11]:=
#cas [factor] (x^4 - 5*x^2 + 4)
Out[11]=
(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
  1. Identity with the factored polynomial

    ∀ (x : ℝ), x ^ 4 - 5 * x ^ 2 + 4 = (x - 1) * (x + 1) * (x - 2) * (x + 2)

    Checked by Lean’s kernel

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:

In[12]:=
#cas [apart] (1/(x*y))
Out[12]=

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 x3+x−x is x3, and it stays the base of the power:

In[13]:=
#cas [apart] (1 / ((x^3 + x - x)^2))
Out[13]=

partial fractions over the written factors, refined by gcds

1(x3)2
1/(x^3)^2
Input (rational function)
(1 / ((x^3 + x - x)^2))
Conditions
(x3+x−x)2≠0

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
  1. Identity with the partial fraction decomposition

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

    Checked by Lean’s kernel

See Also

together · factor · integrate · denominator