Use the remainder form of the Euclidean algorithm to compute the greatest common divisor, then divide both components of the fraction by it:The loop invariant is , , and . Initially it holds by symmetry of the greatest common divisor. For , the integer division identity , with , shows that and have exactly the same common integer divisors. Thus the update preserves the loop invariant. The loop variant is the nonnegative integer , which strictly decreases on each iteration. At exit , so . Dividing by preserves the rational number and makes the returned components coprime. In particular, zero is returned as . No multiplication is needed, and all remainders remain within the original nonnegative
def Reduce(num: Int, den: Int): (Int, Int) = {
require(0 <= num && num < den)
var a = den
var b = num
while (b != 0) {
val r = a % b
a = b
b = r
}
(num / a, den / a)
}Int range.The Euclidean algorithm givesso . Since , the criterion for a linear congruence guarantees a solution. One can also exhibit it directly: , or in the original coefficients,Thus is a solution, with an explicit Bézout coefficient certificate.
The Euclidean algorithm givesThe last nonzero remainder is . Back-substitution produces its Bézout coefficients:Thus is a requested pair. The final equality independently checks the calculation.
The Euclidean algorithm repeatedly replaces by , where the new remainder lies between and . Common divisors are unchanged by this subtraction, and decreasing positive remainders ensure termination. The last nonzero remainder is the greatest common divisor.
The extended Euclidean algorithm also tracks coefficients , beginning with coefficient pairs and and applying the same subtraction to the pairs. This invariant produces Bézout coefficients for the last nonzero remainder. Here the divisions areBack substitution givesThus , with and in Bézout's identity.
Pollard's p-1 algorithm 2026-10-31
For an integer to be factored, John Pollard's method chooses an integer coprime to and an exponent divisible by many small prime powers. Compute by modular exponentiation and the Euclidean algorithm. If , it is a proper factor. If a prime divisor of has , Fermat's little theorem ensures ; success requires some other prime divisor not to divide . Common choices are and . The method exploits a smooth , rather than a small factor itself.
Polynomial division Created 2026-09-24 Updated 2026-10-18
Polynomial division separates a polynomial into a multiple of a chosen divisor and a smaller polynomial remainder. Given over a field , with , there are unique polynomials satisfyingHere is the polynomial quotient. The bound concerns polynomial degree, rather than the sizes of the coefficients.[ref]
Fields and Galois Theory by James S. Milne. Fields and Galois Theory, version 5.10, Chapter 1, p. 10, §1.6: division algorithm, zero remainder alternative and uniqueness
For an original example over the rational numbers, takePolynomial long division first cancels by subtracting :Subtracting one more copy of cancels :ThusThe final polynomial remainder has polynomial degree one, below the divisor's polynomial degree two. Multiplying out the last identity checks every coefficient, including the constant term .
The polynomial degree bound makes this decomposition useful: it replaces a potentially long polynomial with a short polynomial remainder whenever multiples of can be discarded. At any root of a polynomial of , those multiples vanish under polynomial evaluation. Repeated polynomial division also drives the Euclidean algorithm for finding a greatest common divisor of polynomials.
The coefficient setting matters. Over a commutative ring, the same existence and uniqueness hold when the divisor's leading coefficient is a unit in a ring. A monic polynomial therefore works over the integers, even though they do not form a field; monic polynomial division over a ring explains why zero divisors cause no difficulty in that case.[ref]
Chapter 3 Ring theory. Abstract Algebra, Chapter 3 Ring theory, §3.9, Theorem 3.9.1: division with a unit leading coefficient
A nonzero divisor alone is insufficient over the integers. Dividing by with an integer polynomial quotient and a constant polynomial remainder would require for an integer , which is impossible. Over the rational numbers the division instead givesThe obstruction is the nonunit leading coefficient . This example separates existence from uniqueness: over an integral domain, the polynomial degree argument still makes any admissible pair unique, if it exists.
Polynomial greatest common divisor 2026-10-20
A polynomial greatest common divisor of two polynomials over a field divides both and is divisible by every common polynomial divisor. It is unique after requiring it to be monic, and the polynomial Euclidean algorithm computes it.
Quotient by an irreducible polynomial is a field Created 2026-10-06 Updated 2026-10-31
If is an irreducible polynomial over a field , then a nonzero residue modulo has . The Euclidean algorithm supplies , giving inverse for . Thus the quotient ring is a field. If and has elements, polynomial division supplies exactly residue classes.
