Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Give the incomplete partial fraction decomposition of a rational function
| ResourceFunction["IncompletePFD"][num,den,x] returns the incomplete partial fraction decomposition of  | 
 in the variable x, where den factors as d1e1…dmem, the incomplete partial fraction decomposition is the unique way of rewriting as a sum
 in the variable x, where den factors as d1e1…dmem, the incomplete partial fraction decomposition is the unique way of rewriting as a sum  , where den is factored into a product of powers of irreducible polynomials.
, where den is factored into a product of powers of irreducible polynomials.Find the incomplete partial fraction decomposition for  :
:
| In[1]:= | ![ResourceFunction["IncompletePFD"][x, (x - 1)^2*(x - 2)^3, x]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/1bfbfec1caee8aac.png) | 
| Out[1]= |  | 
Find the incomplete partial fraction decomposition for  modulo 5:
 modulo 5:
| In[2]:= | ![incMod = ResourceFunction["IncompletePFD"][x, (x - 1)^2*(x - 2)^3, x, Modulus -> 5]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/34cb691c14e66109.png) | 
| Out[2]= |  | 
Check the result is equivalent to the rational function:
| In[3]:= | ![Together[incMod - \!\(TraditionalForm\`
\*FractionBox[\(x\), \(
\*SuperscriptBox[\((x - 1)\), \(2\)] 
\*SuperscriptBox[\((x - 2)\), \(3\)]\)]\), Modulus -> 5]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/574c3a7f8eba7d99.png) | 
| Out[3]= |  | 
The rational function  does not have a nontrivial decomposition over the rationals:
 does not have a nontrivial decomposition over the rationals:
| In[4]:= | ![ResourceFunction["IncompletePFD"][x, x^2 + 4, x]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/2e7684dd01d1b02c.png) | 
| Out[4]= |  | 
The denominator factors over the Gaussian integers, so providing that as an extension gives a decomposition over linear denominators:
| In[5]:= | ![ResourceFunction["IncompletePFD"][x, x^2 + 4, x, Extension -> I]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/7ee56897dafd46b4.png) | 
| Out[5]= |  | 
Apart is similar to IncompletePFD, but it does a full decomposition over the rationals. First define a numerator and denominator:
| In[6]:= | ![randPoly[max_, deg_, x_] := x^deg + RandomInteger[{-max, max}, deg] . x^Range[0, deg - 1]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/1fa620ab644f3c4f.png) | 
| In[7]:= | ![SeedRandom[1234]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/27b5605f22d78c45.png) | 
| In[8]:= | ![den = randPoly[20, 4, x]*randPoly[20, 3, x]^2*randPoly[20, 2, x]*
  randPoly[20, 1, x]^3](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/0a2b274d6ba90c00.png) | 
| Out[8]= |  | 
| In[9]:= | ![num = randPoly[20, 5, x]^3*randPoly[20, 6, x]*randPoly[20, 7, x]*
  randPoly[20, 4, x]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/680b8511a74a7de4.png) | 
| Out[9]= |  | 
Compute the incomplete partial fraction decomposition:
| In[10]:= | ![res = ResourceFunction["IncompletePFD"][num, den, x]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/0a3993b0d713c55f.png) | 
| Out[10]= |  | 
Apart gives a mathematically equivalent result :
| In[11]:= | ![Together[res - Apart[num/den]]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/3884087ebca3d419.png) | 
| Out[11]= |  | 
For high degrees, IncompletePFD can be notably faster than Apart:
| In[12]:= | ![SeedRandom[1234]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/61fb20170a5df4b7.png) | 
| In[13]:= | ![den = randPoly[100, 8, x]^2*randPoly[100, 7, x]^3*
  randPoly[100, 6, x]^4*randPoly[100, 5, x]^4](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/60b37411a4bbc9a9.png) | 
| Out[13]= |  | 
| In[14]:= | ![num = 4*randPoly[100, 8, x]^3*randPoly[100, 7, x]*randPoly[100, 9, x]*
  randPoly[100, 8, x]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/59691d2b380514be.png) | 
| Out[14]= |  | 
| In[15]:= | ![Timing[aaa = Apart[num/den, x];]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/615a63731aea95dc.png) | 
| Out[15]= |  | 
| In[16]:= | ![Timing[bbb = ResourceFunction["IncompletePFD"][num, den, x];]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/001e3dc73919ac40.png) | 
| Out[16]= |  | 
Check that the denominators are the expected factors to the correct powers:
| In[17]:= | ![Map[Denominator, List @@ bbb]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/1639bc4a5a37eed5.png) | 
| Out[17]= |  | 
Check that the result is equivalent to the rational function num/den:
| In[18]:= | ![Together[bbb - num/den]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/08a01d6f34413115.png) | 
| Out[18]= |  | 
IncompletePFD is intended for polynomials with exact coefficients and may give a result that is deficient due to numerical instability of the method when given input with approximate coefficients:
| In[19]:= | ![SeedRandom[1234]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/5689cbdf7c98958e.png) | 
| In[20]:= | ![den = randPoly[20, 4, x]*randPoly[20, 3, x]^2*randPoly[20, 2, x]*
  randPoly[20, 1, x]^3](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/2a72aea8f0b1d6b6.png) | 
| Out[20]= |  | 
| In[21]:= | ![num = randPoly[20, 5, x]^3*randPoly[20, 6, x]*randPoly[20, 7, x]*
  randPoly[20, 4, x]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/6971a9f465b8eef2.png) | 
| Out[21]= |  | 
| In[22]:= | ![ResourceFunction["IncompletePFD"][num, N@den, x]](https://www.wolframcloud.com/obj/resourcesystem/images/4f9/4f981feb-86a9-40fa-a86a-313c64d509da/0c9afd43e7a0b95b.png) | 
| Out[22]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License