PolynomialGCD[poly1,poly2,…]
gives the greatest common divisor of the polynomials polyi.
PolynomialGCD[poly1,poly2,…,Modulusp]
evaluates the GCD modulo the prime p.
PolynomialGCD
PolynomialGCD[poly1,poly2,…]
gives the greatest common divisor of the polynomials polyi.
PolynomialGCD[poly1,poly2,…,Modulusp]
evaluates the GCD modulo the prime p.
Details and Options
- In PolynomialGCD[poly1,poly2,…], all symbolic parameters are treated as variables.
- PolynomialGCD[poly1,poly2,…] will by default treat algebraic numbers that appear in the polyi as independent variables.
- PolynomialGCD takes the following options:
-
Extension None generators for the algebraic number field to be used Modulus 0 modulus to assume for integers Trig False whether to do trigonometric as well as algebraic transformations - PolynomialGCD[poly1,poly2,…,Extension->Automatic] extends the coefficient field to include algebraic numbers that appear in the polyi.
Examples
open all close allBasic Examples (3)
Compute the greatest common divisor of polynomials:
PolynomialGCD[(1 + x) ^ 2(2 + x)(4 + x), (1 + x)(2 + x)(3 + x)]Compute the GCD of multivariate polynomials:
PolynomialGCD[(x + y) ^ 2(y + z), (x + y)(y + z) ^ 3]Show that polynomials are relatively prime:
PolynomialGCD[x ^ 2 + 4x + 4, x ^ 2 + 2x + 1]Scope (10)
Basic Uses (4)
The GCD of univariate polynomials:
PolynomialGCD[x ^ 4 - 4, x ^ 4 + 4 x ^ 2 + 4]The GCD of multivariate polynomials:
PolynomialGCD[x ^ 2 + 2 x y + y ^ 2, x ^ 3 + y ^ 3]The GCD of more than two polynomials:
PolynomialGCD[x ^ 2 - 1, x ^ 3 - 1, x ^ 4 - 1, x ^ 5 - 1, x ^ 6 - 1, x ^ 7 - 1]The GCD of polynomials with complex coefficients:
PolynomialGCD[x ^ 2 + 1, x ^ 3 + 3I x ^ 2 - 3x - I]Advanced Uses (6)
With Extension->Automatic, PolynomialGCD detects algebraically dependent coefficients:
PolynomialGCD[x ^ 2 - 3, x - Sqrt[3], Extension -> Automatic]Compute the GCD of polynomials over the integers modulo
:
PolynomialGCD[(x ^ 2 - 1) ^ 2, x ^ 3 - 1, Modulus -> 3]Compute the GCD of polynomials over a finite field:
ℱ = FiniteField[17, 3];PolynomialGCD[ℱ[1]x ^ 2 + ℱ[246]x + ℱ[4436], ℱ[3]x ^ 2 + ℱ[1771]]With Trig->True, PolynomialGCD recognizes dependencies between trigonometric functions:
PolynomialGCD[Sin[2x], 1 - Cos[x] ^ 2, Trig -> True]The GCD of rational functions:
PolynomialGCD[(x - 1)(x - 2) / ((x - 3)(x - 4)), (x - 1)(x - 5) / ((x - 3)(x - 6))]Compute the GCD of two polynomials of degree
:
rpoly[n_] := RandomInteger[{-2 ^ 10, 2 ^ 10}, {n + 1}].x ^ Range[0, n]
SeedRandom[1234];
p = rpoly[10000]; q = rpoly[10000]; r = rpoly[10000];
pp = Expand[p r]; qq = Expand[q r];(d = PolynomialGCD[pp, qq]);//AbsoluteTimingExponent[d, x]Options (3)
Extension (1)
By default, algebraic numbers are treated as independent variables:
PolynomialGCD[x ^ 2 - 2, x - Sqrt[2]]With Extension->Automatic, PolynomialGCD detects algebraically dependent coefficients:
PolynomialGCD[x ^ 2 - 2, x - Sqrt[2], Extension -> Automatic]Modulus (1)
Trig (1)
By default, PolynomialGCD treats trigonometric functions as independent variables:
PolynomialGCD[Sin[2x], 1 - Cos[x] ^ 2]With Trig->True, PolynomialGCD recognizes dependencies between trigonometric functions:
PolynomialGCD[Sin[2x], 1 - Cos[x] ^ 2, Trig -> True]Applications (2)
Find common roots of univariate polynomials:
f = x ^ 7 - 2x ^ 5 - x ^ 4 + 5x ^ 3 + 4x ^ 2 - 12x + 5;
g = x ^ 7 - 9x ^ 5 + x ^ 4 + 17x ^ 3 - 7x ^ 2 - 6x + 3;
d = PolynomialGCD[f, g]x /. Solve[d == 0, x]Intersection[x /. Solve[f == 0, x], x /. Solve[g == 0, x]]Find multiple roots of univariate polynomials:
f = x ^ 9 - 7x ^ 8 + 19x ^ 7 - 27x ^ 6 + 35x ^ 5 - 77x ^ 4 + 145x ^ 3 - 157x ^ 2 + 88x - 20;
d = PolynomialGCD[f, D[f, x]]x /. Solve[d == 0, x]N[x /. Solve[f == 0, x]]Properties & Relations (3)
The GCD of polynomials divides the polynomials; use PolynomialMod to prove it:
f = x ^ 7 - 2x ^ 5 - x ^ 4 + 5x ^ 3 + 4x ^ 2 - 12x + 5;
g = x ^ 7 - 9x ^ 5 + x ^ 4 + 17x ^ 3 - 7x ^ 2 - 6x + 3;
d = PolynomialGCD[f, g]PolynomialMod[{f, g}, d]Cancel divides the numerator and the denominator of a rational function by their GCD:
Cancel[f / g]PolynomialLCM finds the least common multiple of polynomials:
PolynomialLCM[f, g]% - (f g) / d //TogetherResultant of two polynomials is zero if and only if their GCD has a nonzero degree:
Resultant[x ^ 2 - 4, x ^ 2 + 4x + 4, x]PolynomialGCD[x ^ 2 - 4, x ^ 2 + 4x + 4]Resultant[3 x + 9, 6x ^ 3 - 3x + 12, x]PolynomialGCD[3 x + 9, 6x ^ 3 - 3x + 12]Discriminant of a polynomial f is zero if and only if the degree of GCD(f,f') is nonzero:
f = x ^ 3 - 3x + 2;
g = x ^ 3 - 2x + 1;Discriminant[f, x]PolynomialGCD[f, D[f, x]]Discriminant[g, x]PolynomialGCD[g, D[g, x], x]Discriminant of a polynomial f is zero if and only if the polynomial has multiple roots:
x /. Solve[f == 0, x]x /. Solve[g == 0, x]Tech Notes
Related Guides
History
Introduced in 1991 (2.0) | Updated in 1996 (3.0) ▪ 2022 (13.2) ▪ 2023 (13.3)
Text
Wolfram Research (1991), PolynomialGCD, Wolfram Language function, https://reference.wolfram.com/language/ref/PolynomialGCD.html (updated 2023).
CMS
Wolfram Language. 1991. "PolynomialGCD." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/PolynomialGCD.html.
APA
Wolfram Language. (1991). PolynomialGCD. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PolynomialGCD.html
BibTeX
@misc{reference.wolfram_2026_polynomialgcd, author="Wolfram Research", title="{PolynomialGCD}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/PolynomialGCD.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_polynomialgcd, organization={Wolfram Research}, title={PolynomialGCD}, year={2023}, url={https://reference.wolfram.com/language/ref/PolynomialGCD.html}, note=[Accessed: 13-June-2026]}