/
partial_fractions.qmd
526 lines (298 loc) · 13.9 KB
/
partial_fractions.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# Partial Fractions
{{< include ../_common_code.qmd >}}
```{julia}
using CalculusWithJulia
using SymPy
```
---
Integration is facilitated when an antiderivative for $f$ can be found, as then definite integrals can be evaluated through the fundamental theorem of calculus.
However, despite integration being an algorithmic procedure, integration is not. There are "tricks" to try, such as substitution and integration by parts. These work in some cases. However, there are classes of functions for which algorithms exist. For example, the `SymPy` `integrate` function mostly implements an algorithm that decides if an elementary function has an antiderivative. The [elementary](http://en.wikipedia.org/wiki/Elementary_function) functions include exponentials, their inverses (logarithms), trigonometric functions, their inverses, and powers, including $n$th roots. Not every elementary function will have an antiderivative comprised of (finite) combinations of elementary functions. The typical example is $e^{x^2}$, which has no simple antiderivative, despite its ubiquitousness.
There are classes of functions where an (elementary) antiderivative can always be found. Polynomials provide a case. More surprisingly, so do their ratios, *rational functions*.
## Partial fraction decomposition
Let $f(x) = p(x)/q(x)$, where $p$ and $q$ are polynomial functions with real coefficients. Further, we assume without comment that $p$ and $q$ have no common factors. (If they did, we can divide them out, an act which has no effect on the integrability of $f(x)$.
The function $q(x)$ will factor over the real numbers. The fundamental theorem of algebra can be applied to say that $q(x)=q_1(x)^{n_1} \cdots q_k(x)^{n_k}$ where $q_i(x)$ is a linear or quadratic polynomial and $n_k$ a positive integer.
> **Partial Fraction Decomposition**: There are unique polynomials $a_{ij}$ with degree $a_{ij} <$ degree $q_i$ such that
>
> $$
> \frac{p(x)}{q(x)} = a(x) + \sum_{i=1}^k \sum_{j=1}^{n_i} \frac{a_{ij}(x)}{q_i(x)^j}.
> $$
The method is attributed to John Bernoulli, one of the prolific Bernoulli brothers who put a stamp on several areas of math. This Bernoulli was a mentor to Euler.
This basically says that each factor $q_i(x)^{n_i}$ contributes a term like:
$$
\frac{a_{i1}(x)}{q_i(x)^1} + \frac{a_{i2}(x)}{q_i(x)^2} + \cdots + \frac{a_{in_i}(x)}{q_i(x)^{n_i}},
$$
where each $a_{ij}(x)$ has degree less than the degree of $q_i(x)$.
The value of this decomposition is that the terms $a_{ij}(x)/q_i(x)^j$ each have an antiderivative, and so the sum of them will also have an antiderivative.
:::{.callout-note}
## Note
Many calculus texts will give some examples for finding a partial fraction decomposition. We push that work off to `SymPy`, as for all but the easiest cases - a few are in the problems - it can be a bit tedious.
:::
In `SymPy`, the `apart` function will find the partial fraction decomposition when a factorization is available. For example, here we see $n_i$ terms for each power of $q_i$
```{julia}
@syms a::real b::real c::real A::real B::real x::real
```
```{julia}
apart((x-2)*(x-3) / (x*(x-1)^2*(x^2 + 2)^3))
```
### Sketch of proof
A standard proof uses two facts of number systems: the division algorithm and a representation of the greatest common divisor in terms of sums, extended to polynomials. Our sketch shows how these are used.
Take one of the factors of the denominators, and consider this representation of the rational function $P(x)/(q(x)^k Q(x))$ where there are no common factors to any of the three polynomials.
Since $q(x)$ and $Q(x)$ share no factors, [Bezout's](http://tinyurl.com/kd6prns) identity says there exists polynomials $a(x)$ and $b(x)$ with:
$$
a(x) Q(x) + b(x) q(x) = 1.
$$
Then dividing by $q(x)^kQ(x)$ gives the decomposition
$$
\frac{1}{q(x)^k Q(x)} = \frac{a(x)}{q(x)^k} + \frac{b(x)}{q(x)^{k-1}Q(x)}.
$$
So we get by multiplying the $P(x)$:
$$
\frac{P(x)}{q(x)^k Q(x)} = \frac{A(x)}{q(x)^k} + \frac{B(x)}{q(x)^{k-1}Q(x)}.
$$
This may look more complicated, but what it does is peel off one term (The first) and leave something which is smaller, in this case by a factor of $q(x)$. This process can be repeated pulling off a power of a factor at a time until nothing is left to do.
What remains is to establish that we can take $A(x) = a(x)\cdot P(x)$ with a degree less than that of $q(x)$.
In Proposition 3.8 of [Bradley](http://www.m-hikari.com/imf/imf-2012/29-32-2012/cookIMF29-32-2012.pdf) and Cook we can see how. Recall the division algorithm, for example, says there are $q_k$ and $r_k$ with $A=q\cdot q_k + r_k$ where the degree of $r_k$ is less than that of $q$, which is linear or quadratic. This is repeatedly applied below:
\begin{align*}
\frac{A}{q^k} &= \frac{q\cdot q_k + r_k}{q^k}\\
&= \frac{r_k}{q^k} + \frac{q_k}{q^{k-1}}\\
&= \frac{r_k}{q^k} + \frac{q \cdot q_{k-1} + r_{k-1}}{q^{k-1}}\\
&= \frac{r_k}{q^k} + \frac{r_{k-1}}{q^{k-1}} + \frac{q_{k-1}}{q^{k-2}}\\
&= \frac{r_k}{q^k} + \frac{r_{k-1}}{q^{k-1}} + \frac{q\cdot q_{k-2} + r_{k-2}}{q^{k-2}}\\
&= \cdots\\
&= \frac{r_k}{q^k} + \frac{r_{k-1}}{q^{k-1}} + \cdots + q_1.
\end{align*}
So the term $A(x)/q(x)^k$ can be expressed in terms of a sum where the numerators or each term have degree less than $q(x)$, as expected by the statement of the theorem.
## Integrating the terms in a partial fraction decomposition
We discuss, by example, how each type of possible term in a partial fraction decomposition has an antiderivative. Hence, rational functions will *always* have an antiderivative that can be computed.
### Linear factors
For $j=1$, if $q_i$ is linear, then $a_{ij}/q_i^j$ must look like a constant over a linear term, or something like:
```{julia}
p = a/(x-c)
```
This has a logarithmic antiderivative:
```{julia}
integrate(p, x)
```
For $j > 1$, we have powers.
```{julia}
@syms j::positive
integrate(a/(x-c)^j, x)
```
### Quadratic factors
When $q_i$ is quadratic, it looks like $ax^2 + bx + c$. Then $a_{ij}$ can be a constant or a linear polynomial. The latter can be written as $Ax + B$.
The integral of the following general form is presented below:
$$
\frac{Ax +B }{(ax^2 + bx + c)^j},
$$
With `SymPy`, we consider a few cases of the following form, which results from a shift of `x`
$$
\frac{Ax + B}{((ax)^2 \pm 1)^j}
$$
This can be done by finding a $d$ so that $a(x-d)^2 + b(x-d) + c = dx^2 + e = e((\sqrt{d/e}x)^2 \pm 1)$.
The integrals of the type $Ax/((ax)^2 \pm 1)$ can completed by $u$-substitution, with $u=(ax)^2 \pm 1$.
For example,
```{julia}
integrate(A*x/((a*x)^2 + 1)^4, x)
```
The integrals of the type $B/((ax)^2\pm 1)$ are completed by trigonometric substitution and various reduction formulas. They can get involved, but are tractable. For example:
```{julia}
integrate(B/((a*x)^2 + 1)^4, x)
```
and
```{julia}
integrate(B/((a*x)^2 - 1)^4, x)
```
---
In [Bronstein](http://www-sop.inria.fr/cafe/Manuel.Bronstein/publications/issac98.pdf) this characterization can be found - "This method, which dates back to Newton, Leibniz and Bernoulli, should not be used in practice, yet it remains the method found in most calculus texts and is often taught. Its major drawback is the factorization of the denominator of the integrand over the real or complex numbers." We can also find the following formulas which formalize the above exploratory calculations ($j>1$ and $b^2 - 4c < 0$ below):
\begin{align*}
\int \frac{A}{(x-a)^j} &= \frac{A}{1-j}\frac{1}{(x-a)^{j-1}}\\
\int \frac{A}{x-a} &= A\log(x-a)\\
\int \frac{Bx+C}{x^2 + bx + c} &= \frac{B}{2} \log(x^2 + bx + c) + \frac{2C-bB}{\sqrt{4c-b^2}}\cdot \arctan\left(\frac{2x+b}{\sqrt{4c-b^2}}\right)\\
\int \frac{Bx+C}{(x^2 + bx + c)^j} &= \frac{B' x + C'}{(x^2 + bx + c)^{j-1}} + \int \frac{C''}{(x^2 + bx + c)^{j-1}}
\end{align*}
The first returns a rational function; the second yields a logarithm term; the third yields a logarithm and an arctangent term; while the last, which has explicit constants available, provides a reduction that can be recursively applied;
That is integrating $f(x)/g(x)$, a rational function, will yield an output that looks like the following, where the functions are polynomials:
$$
\int f(x)/g(x) = P(x) + \frac{C(x)}{D{x}} + \sum v_i \log(V_i(x)) + \sum w_j \arctan(W_j(x))
$$
(Bronstein also sketches the modern method which is to use a Hermite reduction to express $\int (f/g) dx = p/q + \int (g/h) dx$, where $h$ is square free (the "`j`" are all $1$). The latter can be written over the complex numbers as logarithmic terms of the form $\log(x-a)$, the "`a`s"found following a method due to Trager and Lazard, and Rioboo, which is mentioned in the SymPy documentation as the method used.)
#### Examples
Find an antiderivative for $1/(x\cdot(x^2+1)^2)$.
We have a partial fraction decomposition is:
```{julia}
q = (x * (x^2 + 1)^2)
apart(1/q)
```
We see three terms. The first and second will be done by $u$-substitution, the third by a logarithm:
```{julia}
integrate(1/q, x)
```
---
Find an antiderivative of $1/(x^2 - 2x-3)$.
We again just let `SymPy` do the work. A partial fraction decomposition is given by:
```{julia}
𝒒 = (x^2 - 2x - 3)
apart(1/𝒒)
```
We see what should yield two logarithmic terms:
```{julia}
integrate(1/𝒒, x)
```
:::{.callout-note}
## Note
`SymPy` will find $\log(x)$ as an antiderivative for $1/x$, but more generally, $\log(\lvert x\rvert)$ is one.
:::
##### Example
The answers found can become quite involved. [Corless](https://arxiv.org/pdf/1712.01752.pdf), Moir, Maza, and Xie use this example which at first glance seems tame enough:
```{julia}
ex = (x^2 - 1) / (x^4 + 5x^2 + 7)
```
But the integral is something best suited to a computer algebra system:
```{julia}
integrate(ex, x)
```
## Questions
###### Question
The partial fraction decomposition of $1/(x(x-1))$ must be of the form $A/x + B/(x-1)$.
What is $A$? (Use `SymPy` or just put the sum over a common denominator and solve for $A$ and $B$.)
```{julia}
#| hold: true
#| echo: false
val = -1
numericq(val)
```
What is $B$?
```{julia}
#| hold: true
#| echo: false
val = 1
numericq(val)
```
###### Question
The following gives the partial fraction decomposition for a rational expression:
$$
\frac{3x+5}{(1-2x)^2} = \frac{A}{1-2x} + \frac{B}{(1-2x)^2}.
$$
Find $A$ (being careful with the sign):
```{julia}
#| hold: true
#| echo: false
numericq(-3/2)
```
Find $B$:
```{julia}
#| hold: true
#| echo: false
numericq(13/2)
```
###### Question
The following specifies the general partial fraction decomposition for a rational expression:
$$
\frac{1}{(x+1)(x-1)^2} = \frac{A}{x+1} + \frac{B}{x-1} + \frac{C}{(x-1)^2}.
$$
Find $A$:
```{julia}
#| hold: true
#| echo: false
numericq(1/4)
```
Find $B$:
```{julia}
#| hold: true
#| echo: false
numericq(-1/4)
```
Find $C$:
```{julia}
#| hold: true
#| echo: false
numericq(1/2)
```
###### Question
Compute the following exactly:
$$
\int_0^1 \frac{(x-2)(x-3)}{(x-4)^2\cdot(x-5)} dx
$$
Is $-6\log(5) - 5\log(3) - 1/6 + 11\log(4)$ the answer?
```{julia}
#| hold: true
#| echo: false
yesnoq("yes")
```
###### Question
In the assumptions for the partial fraction decomposition is the fact that $p(x)$ and $q(x)$ share no common factors. Suppose, this isn't the case and in fact we have:
$$
\frac{p(x)}{q(x)} = \frac{(x-c)^m s(x)}{(x-c)^n t(x)}.
$$
Here $s$ and $t$ are polynomials such that $s(c)$ and $t(c)$ are non-zero.
If $m > n$, then why can we cancel out the $(x-c)^n$ and not have a concern?
```{julia}
#| hold: true
#| echo: false
choices = [
"`SymPy` allows it.",
L"The value $c$ is a removable singularity, so the integral will be identical.",
L"The resulting function has an identical domain and is equivalent for all $x$."
]
answ = 2
radioq(choices, answ, keep_order=true)
```
If $m = n$, then why can we cancel out the $(x-c)^n$ and not have a concern?
```{julia}
#| hold: true
#| echo: false
choices = [
"`SymPy` allows it.",
L"The value $c$ is a removable singularity, so the integral will be identical.",
L"The resulting function has an identical domain and is equivalent for all $x$."
]
answ = 2
radioq(choices, answ, keep_order=true)
```
If $m < n$, then why can we cancel out the $(x-c)^n$ and not have a concern?
```{julia}
#| hold: true
#| echo: false
choices = [
"`SymPy` allows it.",
L"The value $c$ is a removable singularity, so the integral will be identical.",
L"The resulting function has an identical domain and is equivalent for all $x$."
]
answ = 3
radioq(choices, answ, keep_order=true)
```
###### Question
The partial fraction decomposition, as presented, factors the denominator polynomial into linear and quadratic factors over the real numbers. Alternatively, factoring over the complex numbers is possible, resulting in terms like:
$$
\frac{a + ib}{x - (\alpha + i \beta)} + \frac{a - ib}{x - (\alpha - i \beta)}
$$
How to see that these give rise to real answers on integration is the point of this question.
Breaking the terms up over $a$ and $b$ we have:
\begin{align*}
I &= \frac{a}{x - (\alpha + i \beta)} + \frac{a}{x - (\alpha - i \beta)} \\
II &= i\frac{b}{x - (\alpha + i \beta)} - i\frac{b}{x - (\alpha - i \beta)}
\end{align*}
Integrating $I$ leads to two logarithmic terms, which are combined to give:
$$
\int I dx = a\cdot \log((x-(\alpha+i\beta)) \cdot (x - (\alpha-i\beta)))
$$
This involves no complex numbers, as:
```{julia}
#| hold: true
#| echo: false
choices = ["The complex numbers are complex conjugates, so the term in the logarithm will simply be ``x - 2\\alpha x + \\alpha^2 + \\beta^2``",
"The ``\\beta`` are ``0``, as the polynomials in question are real"]
radioq(choices, 1)
```
The term $II$ benefits from this computation (attributed to Rioboo by [Corless et. al](https://arxiv.org/pdf/1712.01752.pdf))
$$
\frac{d}{dx} i \log(\frac{X+iY}{X-iY}) = 2\frac{d}{dx}\arctan(\frac{X}{Y})
$$
Applying this with $X=x - \alpha$ and $Y=-\beta$ shows that $\int II dx$ will be
```{julia}
#| hold: true
#| echo: false
choices = ["``-2b\\arctan((x - \\alpha)/(\\beta))``",
"``2b\\sec^2(-(x-\\alpha)/(-\\beta))``"]
radioq(choices, 1)
```