5  Partial Fractions

SageMath Spotlight

  • Algebraic manipulation (Section 2.5)
    • f(x).factor()
    • solve([eq1, eq2], [var1, var2])
    • f(x).partial_fraction(x) (Section 2.5.2)
  • Integration (Section 2.8)
    • integral(f(x), x)
    • integral(f(x), x, a, b)

5.1 Introduction

A rational function is a ratio of two polynomials, \(\frac{f(x)}{g(x)}\). While polynomials are easy to integrate, rational functions can be quite stubborn! In this section, we review a few algebraic techniques to break complicated rational functions apart into simpler, integrable pieces.

5.2 Proper Fractions and Polynomial Division

Just as \(\frac{17}{5}\) is an improper fraction (the numerator is larger than the denominator) that can be rewritten as the mixed number \(3 + \frac{2}{5}\) via long division, a rational function is considered improper if the degree of its numerator is greater than or equal to the degree of its denominator.

Before we can use advanced calculus techniques on a rational function, we must first ensure it is a proper fraction. If it is not, we use polynomial long division (Stewart et al. 2020, 7.4, pp. 507) to extract the polynomial part, leaving behind a proper rational remainder.

Example 5.1 (\(\int \frac{4x^2-2x-5}{x-1} \mathop{}\!\mathrm{d}x\)) Since the numerator (degree 2) is larger than the denominator (degree 1), we perform polynomial long division.

  • How many times does \(x\) go into \(4x^2\)? \(4x\) times. Multiply \(4x(x-1) = 4x^2 - 4x\) and subtract from the numerator, leaving \(2x - 5\).
  • How many times does \(x\) go into \(2x\)? \(2\) times. Multiply \(2(x-1) = 2x - 2\) and subtract from the remainder, leaving a final remainder of \(-3\).

Thus, we can rewrite the integrand: \[ \frac{4x^2-2x-5}{x-1} = 4x + 2 - \frac{3}{x-1}. \] Now the integral is trivial to evaluate: \[ \int \left( 4x + 2 - \frac{3}{x-1} \right) \mathop{}\!\mathrm{d}x = 2x^2 + 2x - 3\ln\vert{}x-1\vert{} + C. \]

Example 5.2 (\(\int \frac{x^4-10x^2+3x+6}{x^2-9} \mathop{}\!\mathrm{d}x\)) Here, a degree 4 polynomial is divided by a degree 2 polynomial. 1. \(x^2\) goes into \(x^4\) exactly \(x^2\) times. Subtracting \(x^2(x^2 - 9) = x^4 - 9x^2\) leaves \(-x^2 + 3x + 6\). 2. \(x^2\) goes into \(-x^2\) exactly \(-1\) times. Subtracting \(-1(x^2 - 9) = -x^2 + 9\) leaves a remainder of \(3x - 3\).

We can rewrite the function as: \[ \frac{x^4-10x^2+3x+6}{x^2-9} = x^2 - 1 + \frac{3x-3}{x^2-9}. \] The polynomial piece (\(x^2 - 1\)) is easy to integrate, but what about the remainder? It is now a proper fraction, but the denominator is not linear. We need another tool!

5.3 Reversing the Common Denominator

In algebra, we add rational functions together by finding a common denominator: \[ \frac{4}{x-2} - \frac{3}{x+1} = \frac{4(x+1)}{(x-2)(x+1)} - \frac{3(x-2)}{(x-2)(x+1)} = \frac{x+10}{x^2-x-2}. \] In calculus, we often need to run this process in reverse. Integrating a rational function like \(\frac{x+10}{x^2-x-2}\) directly is difficult, but integrating \(\frac{4}{x-2} - \frac{3}{x+1}\) is straightforward—it just evaluates to a pair of logarithms! This reverse process is partial fraction decomposition (Stewart et al. 2020, 7.4, pp. 508).

As in several other aspects of this course, the difficulty lies in the algebra—not the calculus!!

When a proper rational function has a denominator \(Q(x)\) that can be factored into distinct linear pieces—like \((x-2)(x+1)\)—we can always decompose the fraction into a sum of simpler terms with constant numerators. We given an example of this method here and discuss a more general theory in class.

Example 5.3 Let us verify the algebra we did above by computing \(\int \frac{2x-1}{x^2-3x+2} \mathop{}\!\mathrm{d}x\). Firstly, we need to break down the integrand. The denominator factors as \(x^2-3x+2 = (x-1)(x-2)\), so we know that it can be decomposed into the following form: \[ \frac{2x-1}{(x-1)(x-2)} = \frac{A}{x-1} + \frac{B}{x-2} \tag{5.1}\] We have to solve for \(A\) and \(B\). Cross multiplying by the common denominator \((x-1)(x-2)\) gives \[ \frac{A(x-2) + B(x-1)}{(x-1)(x-2)} = \frac{(A+B)x - (2A+B)}{(x-1)(x-2)}. \] We compare the resulting numerator with that of Equation 5.1’s left hand side: \[ 2x-1 = (A+B)x - (2A+B) \implies \left\{ \begin{array}{c} A+B = 2 \\ -2A-B = -1. \end{array} \right. \] To solve a system like this (two linear equations, two unknowns), it is often easiest to solve for one of the variables with one equation, then substitute into the other. For example: \[ A+B = 2 \implies A = 2-B \implies -2(2-B)-B = -1. \] The latter equation simplifies to \(-4+B = -1\), i.e., \(B = 3\), and we substitute back into the first \(A = 2-(3) = -1\) to conclude. We have shown that \[ \frac{2x-1}{(x-1)(x-2)} = \frac{-1}{x-1} + \frac{3}{x-2}. \] Now we are prepared to compute the integral: \[ \begin{aligned} \int \frac{2x-1}{x^2-3x+2} \mathop{}\!\mathrm{d}x & = 3 \int \frac{1}{x-2} \mathop{}\!\mathrm{d}x - \int \frac{1}{x-1} \mathop{}\!\mathrm{d}x \\ & = 3 \ln\vert{}x-2\vert{} - \ln\vert{}x-1\vert{} + C. \end{aligned} \]

Depending on which parts of the process we find challenging, we can check our work in several ways!

We can check our work on the whole integral:

integral((2*x-1)/(x^2-3*x+2), x)
-log(x - 1) + 3*log(x - 2)

We can check our work on factoring the denominator:

(x^2-3*x+2).factor()
(x - 1)*(x - 2)

We can check our work on the fraction decomposition:

((2*x-1)/(x^2-3*x+2)).partial_fraction(x)
-1/(x - 1) + 3/(x - 2)

We can even check our work on solving for the coefficients!

var('a b')
solve( [a+b==2, -2*a-b==-1], [a, b] )
[[a == -1, b == 3]]

Note that, like many programming languages, the \(\ln(x)\) is written as log(x) in SageMath. The meaning of \(\log(x)\) changes from discipline to discipline! Computer scientists often use \(\log_{2}(x)\); many physical scientists, engineers, and technicians use \(\log_{10}(x)\); and mathematicians, economists, and some subdisciplines of physics and biology stick to \(\ln(x)\). In this course, both \(\ln(x)\) and \(\log(x)\) both refer to the natural logarithm (recall §3.6, exercise 1, from Homework 0), and any other logarithm base will be explicitly denoted using the notation \(\log_b(x)\).

5.4 Bringing it All Together

Given an integral of rational functions to evaluate, \(\int \frac{f(x)}{g(x)} \mathop{}\!\mathrm{d}x\), we take the following approach:

  • Firstly, if \(\frac{f(x)}{g(x)}\) is improper, use polynomial long division to write it as a proper fraction added to a polynomial. Integrate the polynomial, then focus on the proper fraction.

Now we are interested in a proper fraction \(\frac{f(x)}{g(x)}\):

  • Factor \(g(x)\). For our purposes, we can expect it to factor like \((x-r_1) \cdots (x-r_n)\).
  • Set up the system. We know that a proper fraction of this form decomposes as \[ \frac{f(x)}{(x-r_1) \cdots (x-r_n)} = \frac{A_1}{x-r_1} + \cdots + \frac{A_n}{x-r_n}. \]
  • Cross multiply and equate numerators.
  • Solve the system of equations for the \(A_i\) coefficients.
  • Integrate. \(\int \left( \frac{A_1}{x-r_1} + \cdots + \frac{A_n}{x-r_n} \right) \mathop{}\!\mathrm{d}x = A_1 \ln\vert{}x-r_1\vert{} + \cdots + A_r \ln\vert{}x-r_n\vert{} + C.\)

Beyond Distinct Linear Roots

Things become more complicated algebraically if the denominator contains repeated roots (e.g., \((x-1)^2\)) or irreducible quadratics (e.g., \(x^2+1\))—see (Stewart et al. 2020, 7.4, pp. 510–514). While dealing with these situations requires modifying our template (using terms like \(\frac{Ax+B}{x^2+1}\)), we will not need them for the applications in this course. For the differential equations we are building toward, distinct linear roots are all we need!