Thursday, September 4, 2025
HomeLanguagesPython | sympy.gcd() method

Python | sympy.gcd() method

The function gcd() provides the direct way to compute Greatest Common Divisor for polynomials.That is, for polynomials f and g, it computes GCD.

Syntax: sympy.gcd(f, g)

Return: GCD of given polynomials

Example #1:




# import sympy  
from sympy import * f = (12 * x + 12)*x
g = 32 * x**2
  
# Using sympy.gcd() method 
gfg = gcd(f, g)  
  
print(gfg)


Output:

4*x

Example #2:




# import sympy  
from sympy import * f = 3 * x**2 / 2
g = 9 * x / 4
  
# Using sympy.gcd() method 
gfg = gcd(f, g)  
  
print(gfg)


Output:

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

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS