Function reference · Algebra

gcd

Returns the greatest common divisor of two polynomials or numbers.

It finds common numeric factors, monomials, and polynomial factors in one or more variables, including factors with symbolic coefficients.

Notation

gcd(x, y)

Write it in an expression: nerdamer('gcd(6*(x-1)*(x+2),15*(x-1)*(x^3+1))'), or in the Playground.

nerdamer.gcd

nerdamer.gcd(x: ExpressionInput, y: ExpressionInput): Expression

A method on the default import. Arguments can be strings, as in Notation.

import { gcd }

import { gcd } from 'nerdamer/algebra';
gcd(x: ExpressionInput, y: ExpressionInput): Expression

Import only this function, from nerdamer/algebra.

Examples

A common number and polynomial factor.

gcd(6*(x-1)*(x+2),15*(x-1)*(x^3+1))
// → -3+3*x
Open in Playground

A common monomial in two variables.

gcd(x*y*(x+y+1),x*y*(x^2-y+3))
// → x*y
Open in Playground

A common factor with symbolic coefficients.

gcd((x^2+a)*(x^3+1),(x^2+a)*(x^4+b*x+1))
// → a+x^2
Open in Playground

Expressions with no common polynomial factor give 1.

gcd(sin(x),cos(x))
// → 1
Open in Playground

← Back to Function reference