Friday, August 29, 2025
HomeLanguagesPython | sympy.cancel() method

Python | sympy.cancel() method

With the help of sympy.cancel() method, we are able to any rational function and put it into a standard canonical form i.e p/q.

Syntax : sympy.cancel()
Return : Return the canonical expression of any rational function.

Example #1 :
In the given example, we can see that by using sympy.cancel() method, we can find the canonical form of any rational number i.e (p/q).




# import sympy
from sympy import * x, y, z = symbols('x y z')
gfg_exp = (x**2 + 2 * x + 1)/(x**2 + x)
   
# Using sympy.collect() method
gfg_exp = cancel(gfg_exp)
   
print(gfg_exp)


Output :

(x + 1)/x

Example #2 :




# import sympy
from sympy import * x, y, z = symbols('x y z')
gfg_exp = 1 / x + (3 * x / 2 - 2)/(x - 4)
   
# Using sympy.collect() method
gfg_exp = cancel(gfg_exp)
   
print(gfg_exp)


Output :

(3*x**2 – 2*x – 8)/(2*x**2 – 8*x)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11789 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7011 POSTS0 COMMENTS
Thapelo Manthata
6688 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS