ForHosting KIT · Math

Polynomial GCD calculator

Find the factor two polynomials share: x² − 3x + 2 and x − 1 have greatest common divisor x − 1, found in 1 Euclidean step and always scaled to lead with 1. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon

Runs in your browser. Free, unlimited — your data never leaves this page.

This polynomial GCD calculator finds the greatest common divisor of two polynomials given as dense coefficient arrays with the highest degree first. It runs the classical Euclidean algorithm: replace the pair with the second polynomial and the remainder of the first modulo the second until the remainder is zero, then scale the last non-zero remainder so its leading coefficient is one (a monic GCD). Shared linear factors, exact division checks, and coprimality tests all reduce to this one primitive. Small checks you may already know include x squared minus three x plus two and x minus one sharing the factor x minus one, and x squared minus one with x minus one again yielding x minus one. The engine uses only deterministic floating-point arithmetic on coefficient vectors: no network calls, no sampling, and no date-dependent shortcuts.

What polynomial GCD returns and how monic normalization works

The greatest common divisor of two polynomials is a polynomial of highest degree that divides both, unique up to a non-zero scalar over the coefficient field. This calculator returns a monic representative: after the Euclidean loop finishes, every coefficient is divided by the leading coefficient so the answer always starts with one when the GCD is non-zero. Inputs and outputs use dense coefficient arrays highest degree first; for example one, negative three, two means x squared minus three x plus two, and one, negative one means x minus one.

If exactly one input is zero, the monic form of the other is returned, matching the usual convention that gcd of f and zero is a unit multiple of f. There is no symbolic CAS path and no random sampling of roots: the engine either finishes the Euclidean reductions inside the supported degree and magnitude limits or rejects the input.

How coefficients are read and how the Euclidean loop stays reproducible

String coefficients that parse as finite decimals, including optional scientific notation, are allowed; embedded spaces, hex prefixes, and non-numeric tokens are rejected with a clear message so a bad cell does not become a wrong divisor. Leading zero coefficients are trimmed before reduction so that zero, one, two and one, two represent the same linear polynomial.

Each Euclidean step computes the remainder of the current dividend modulo the current divisor by long division of coefficient vectors, then swaps: the old divisor becomes the new dividend and the remainder becomes the new divisor, exactly as for integer GCD. A small epsilon strips near-zero leading terms so floating-point noise does not invent fake high-degree remainders. When the loop ends, monic scaling forces the leading coefficient to one, which makes goldens and caches independent of arbitrary scalar multiples that algebra allows.

Where polynomial GCD fits in study, code, and teaching

Students meet polynomial GCD when a textbook introduces the Euclidean algorithm over the polynomial ring, when they cancel common factors in a rational expression, or when they check whether two cubics share a linear factor before applying partial fractions. Teachers can pre-generate answer keys for modest degrees without trusting opaque calculator apps that hide intermediate remainders or silently rescale by non-monic contents.

Developers call the same contract from scripts to seed deterministic test vectors for computer-algebra modules, to simplify ratios of user-entered polynomials, or to satisfy programming-challenge statements that demand a monic GCD coefficient array rather than a hand-waved factor list. Contest practice often needs a fast, offline source of polynomial GCD results so solutions can be checked without graphing calculators under time pressure.

Homework and shared-factor checks

Find monic polynomial GCDs for textbook Euclidean-algorithm exercises and cancel common factors in rational expressions.

Tutoring and CAS front-ends

Normalize two user-entered polynomials into a monic GCD with degrees, coprime flag, and readable poly strings for lessons.

What does the polynomial GCD calculator cost?

It is free in your browser on this page.

How is the GCD defined?

It is a monic polynomial of highest degree that divides both inputs, obtained by the Euclidean algorithm (repeated polynomial remainder) and leading-coefficient normalization.

How should I encode polynomials?

Pass dense coefficient arrays highest degree first, e.g. [1, -3, 2] for x² − 3x + 2 and [1, -1] for x − 1.

What does the coprime flag mean?

When the monic GCD is the constant 1, the polynomials share no common root factor of positive degree and coprime is true.

What if one of the two polynomials is zero?

You get the other polynomial scaled so its leading coefficient is 1, because every polynomial divides zero. If both are zero, the calculation is refused, since their greatest common divisor is undefined.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/algebra/polynomial-gcd

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/algebra/polynomial-gcd \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":[1,-3,2],"b":[1,-1]}'
{
  "a": [
    1,
    -3,
    2
  ],
  "b": [
    1,
    -1
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "algebra.polynomial_gcd",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_degree64
max_abs_coeff1000000000000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

What polynomial GCD returns and how monic normalization works

The response echoes the normalized inputs after stripping leading zeros, returns the monic gcd array rounded to the requested precision, reports the degrees of both inputs and of the gcd, sets a coprime flag when the monic gcd is the constant one, builds human-readable strings such as x^2 - 3x + 2 for worksheets and UIs, and records how many remainder steps the Euclidean algorithm performed. Degree of a non-zero polynomial is one less than the length of its trimmed coefficient array; the zero polynomial is reported with degree zero and the single coefficient zero so JSON consumers never need empty arrays. Both polynomials zero is rejected with invalid_input because gcd of zero and zero is undefined in this contract.

How coefficients are read and how the Euclidean loop stays reproducible

The preferred fields are a and b, each a non-empty array of finite numbers from highest degree down to the constant term. Aliases p, poly1, f, and first for the first polynomial and q, poly2, g, and second for the second are accepted so spreadsheets, query strings, and typed forms can reuse the same contract. An optional precision field, with aliases decimals and dp, chooses how many decimal places to expose for every coefficient in the response, defaulting to ten and capped at fifteen so JSON goldens stay stable across runs. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline.

Where polynomial GCD fits in study, code, and teaching

Education products use the rewrite when a learner types two coefficient lists and the UI must show a_poly, b_poly, and gcd_poly together with the coprime flag and Euclidean step count. On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result. Pair it with polynomial long division when you need quotients as well as remainders, with integer coprime tools when the objects are numbers rather than polynomials, and with other algebra endpoints when you are building a small lab of free, deterministic helpers for homework and software tests.

Deterministic test fixtures

Generate reproducible monic GCD coefficient arrays and poly strings for unit tests, property checks, and CI assertions.

What happens if both polynomials are zero?

The input is rejected with invalid_input. gcd(0, 0) is undefined in this contract.

Read the full KIT documentation →