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).

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :

(x + 1)/x

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.