Monday, November 17, 2025
HomeLanguagesPython | sympy.apart() method

Python | sympy.apart() method

With the help of sympy.apart() method, we can performs a partial fraction decomposition on a rational mathematical expression.

Syntax: apart(expression)

Parameters:
expression – It is a rational mathematical expression.

Returns: Returns an expression after the partial decomposition.

Example #1:
In this example we can see that by using sympy.apart() method, we can get a partial fraction decomposition of a given mathematical expression.




# import sympy
from sympy import *
  
x = symbols('x')
expr = (4 * x**3 + 21 * x**2 + 10 * x + 12) / (x**4 + 5 * x**3 + 5 * x**2 + 4 * x)
  
print("Mathematical expression : {}".format(expr))
    
# Use sympy.apart() method
pd = apart(expr) 
    
print("After Partial Decomposition : {}".format(pd)) 


Output:

Mathematical expression : (4*x**3 + 21*x**2 + 10*x + 12)/(x**4 + 5*x**3 + 5*x**2 + 4*x)
After Partial Decomposition : (2*x - 1)/(x**2 + x + 1) - 1/(x + 4) + 3/x

Example #2:




# import sympy
from sympy import * 
  
x = symbols('x')
expr = 1/(x + 3)(x + 2)
  
print("Mathematical expression : {}".format(expr))
    
# Use sympy.factor_list() method
pd = apart(expr) 
    
print("After Partial Decomposition : {}".format(pd)) 


Output:

Mathematical expression : 1/((x + 2)*(x + 3))
After Partial Decomposition : -1/(x + 3) + 1/(x + 2)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32402 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6770 POSTS0 COMMENTS
Nicole Veronica
11920 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11990 POSTS0 COMMENTS
Shaida Kate Naidoo
6899 POSTS0 COMMENTS
Ted Musemwa
7153 POSTS0 COMMENTS
Thapelo Manthata
6852 POSTS0 COMMENTS
Umr Jansen
6843 POSTS0 COMMENTS