## Name:

gcd Computes the greatest common divisor of polynomials or numbers.

## Library name:

sollya_obj_t sollya_lib_gcd(sollya_obj_t, sollya_obj_t)

## Usage:

gcd(p, q) : (function, function) -> function

## Parameters:

• p is a constant or a polynomial.
• q is a constant or a polynomial.

## Description:

• When both p and q are integers, gcd(p,q) computes the greatest common divisor of these two integers, i.e. the greatest non-negative integer dividing both p and q.
• When both p and q are rational numbers, say a/b and c/d, gcd(p,q) computes the greatest common divisor of a * d and b * c, divided by the product of the denominators, b * d.
• When both p and q are constants but at least one of them is no rational number, gcd(p,q) returns 1.
• When both p and q are polynomials with at least one being non-constant, gcd(p,q) returns the polynomial of greatest degree dividing both p and q, and whose leading coefficient is the greatest common divisor of the leading coefficients of p and q.
• Similarly to the cases documented for div and mod, gcd may fail to return the unique polynomial of largest degree dividing both p and q in cases when certain coefficients of either p or q are constant expressions for which the tool is unable to determine whether they are zero or not. These cases typically involve polynomials whose leading coefficient is zero but the tool is unable to detect this fact.
• When at least one of p or q is a function that is no polynomial, gcd(p,q) returns 1.

## Example 1:

> gcd(1001, 231);
77
> gcd(13, 17);
1
> gcd(-210, 462);
42

## Example 2:

> rationalmode = on!;
> gcd(6/7, 33/13);
3 / 91

## Example 3:

> gcd(exp(13),sin(17));
1

## Example 4:

> gcd(24 + 68 * x + 74 * x^2 + 39 * x^3 + 10 * x^4 + x^5, 480 + 776 * x + 476 * x^2 + 138 * x^3 + 19 * x^4 + x^5);
4 + x * (4 + x)
> gcd(1001 * x^2, 231 * x);
x * 77

## Example 5:

> gcd(exp(x), x^2);
1
See also: bezout, div, mod, numberroots
Go back to the list of commands