Here is a natural question. You have two polynomials p(x) and q(x), and you check three inputs. You find that p(1) = q(1), p(2) = q(2), and p(3) = q(3). Three agreements. Must p and q be the same polynomial?

The honest answer is: it depends on the degree.

If both p and q are quadratic (or linear, or constant), then yes — they are forced to be the same polynomial. Every coefficient must match.

If either p or q is cubic or higher, then no. Three matches are not enough. You can construct two genuinely different cubics that agree at any three points you pick and still disagree everywhere else.

The rule is clean once you see it. Let us build it up.

The theorem

Here is the statement that governs this entire question.

If two polynomials of degree at most n agree at n+1 distinct points, they are identically equal — same coefficients, same polynomial.

Let that sink in. The number of agreement-points you need is tied to the degree:

The +1 matters. A quadratic is not pinned down by two points — infinitely many parabolas pass through any pair of points. You need that third point to lock the shape.

The proof

The proof is one of those short arguments that feels like magic the first time you see it.

Suppose p and q are polynomials of degree at most n, and they agree at n+1 distinct points r_1, r_2, ..., r_{n+1}. Look at the difference:

d(x) = p(x) - q(x)

Two facts about d(x):

  1. d(x) has degree at most n, because subtracting two polynomials of degree at most n cannot raise the degree.
  2. d(x) has at least n+1 roots, namely r_1, r_2, ..., r_{n+1}, because at each of these points p and q agree, so their difference is zero.

Here is the crunch. A non-zero polynomial of degree at most n can have at most n roots. That is the fundamental theorem of algebra doing its job. So if d(x) has n+1 roots and only degree n, something has to give — and the only way out is that d(x) is not really a polynomial of degree n at all. It must be the zero polynomial.

So d(x) = 0 for every x, which means p(x) = q(x) for every x. They are the same polynomial.

Why three points isn't enough for cubics

This is where the degree restriction bites. Let us cook up a counterexample.

Let p(x) = x^3 and q(x) = x^3 + (x-1)(x-2)(x-3).

Check at x = 1:

Check at x = 2:

Check at x = 3:

Three agreements. Now look at x = 4:

So p and q agree at exactly the three points you tested, but they are genuinely different polynomials. p is a clean cubic; q has an extra (x-1)(x-2)(x-3) term. Expand that extra term and you see q(x) = 2x^3 - 6x^2 + 11x - 6, whereas p(x) = x^3. Different coefficients.

The construction that produced q

The trick was not random. Suppose you have some polynomial p that passes through three specific points r_1, r_2, r_3. You can always produce a different polynomial with the same behaviour at those points by adding any multiple of (x - r_1)(x - r_2)(x - r_3):

q(x) = p(x) + c \cdot (x - r_1)(x - r_2)(x - r_3)

The added term vanishes at x = r_1, x = r_2, x = r_3, because one of the factors becomes zero. So q and p agree at exactly those three points, no matter what c is. For any non-zero c, you get a genuinely different polynomial.

This is the general mechanism. If you only know k point-agreements, you have (x - r_1)(x - r_2)...(x - r_k) worth of wiggle room you can add, and that wiggle room is a polynomial of degree k. So agreement at k points does not constrain the coefficients of x^k, x^{k+1}, and higher. You need n+1 points to pin down a polynomial of degree n.

Lagrange interpolation — the positive result

The positive version of this is beautiful.

Given n+1 points (x_0, y_0), (x_1, y_1), ..., (x_n, y_n) with distinct x_i, there is exactly one polynomial of degree at most n passing through all of them.

Existence is guaranteed by the Lagrange interpolation formula, which explicitly writes that polynomial down. Uniqueness is guaranteed by the theorem above: if two such polynomials existed, they would agree at n+1 points and therefore be identical.

This is why we say "n+1 points uniquely determine a degree-n polynomial". The "determine" is exact — not approximate, not "up to rounding". Exact.

Worked example

Find the quadratic passing through (0, 1), (1, 4), and (2, 9).

Set p(x) = ax^2 + bx + c. Three point conditions give three equations in three unknowns.

From p(0) = 1: c = 1.

From p(1) = 4: a + b + c = 4, so a + b = 3.

From p(2) = 9: 4a + 2b + c = 9, so 4a + 2b = 8, which simplifies to 2a + b = 4.

Subtract the second from the third: a = 1. Then b = 3 - 1 = 2.

So p(x) = x^2 + 2x + 1 = (x+1)^2.

Check: p(0) = 1, p(1) = 4, p(2) = 9. All three match.

This is the unique quadratic passing through those three points. Try to find another one of degree at most 2 — you cannot. The three conditions have pinned down all three coefficients.

When agreement at "many" points matters

In algebra you often use a stronger fact: if p(x) = q(x) for all x, then p and q are the same polynomial. This is what lets you "compare coefficients" on both sides of an algebraic identity. It is the same theorem in disguise, because "agreement everywhere" certainly includes "agreement at n+1 points" for any n.

In fact, agreement at infinitely many values of x is enough, regardless of degree. The difference p - q would have infinitely many roots, and no non-zero polynomial has infinitely many roots. So the difference must be zero everywhere.

Applications

This is not a classroom curiosity. It underlies serious technology.

Numerical analysis. If you sample a function at n+1 points, you can reconstruct a polynomial of degree at most n that fits exactly. This is how polynomial interpolation works in engineering — curve-fitting satellite data, reconstructing signal samples, approximating complicated functions.

Cryptography — Shamir's Secret Sharing. Adi Shamir's scheme uses exactly this uniqueness. You hide a secret as the constant term of a random polynomial of degree n, and hand out points on the polynomial as "shares". With n+1 shares, the polynomial is uniquely reconstructable and the secret recovers. With only n shares, infinitely many polynomials fit — the secret is information-theoretically hidden.

Coding theory — Reed-Solomon codes. Error-correcting codes used in CDs, DVDs, QR codes, and deep-space communication with ISRO and NASA probes encode data as evaluations of a polynomial. The "extra" evaluations are redundancy: if a few samples get corrupted, the polynomial can still be recovered because the uniqueness property tolerates a controlled number of errors.

Common confusions

"Two polynomials that agree at infinitely many points are the same." True. Their difference has infinitely many roots, and only the zero polynomial has that.

"Agreement at 3 points is enough for any polynomial." False. It is enough for quadratics and lower, but a cubic has four coefficients — you need four points.

"Polynomial interpolation is approximate." False. With n+1 distinct x-values, the interpolating polynomial of degree at most n passes through every given point exactly, not approximately.

"If I have more points than I need, there is still a unique polynomial." Yes — if the extra points are consistent with the same polynomial. If they are not consistent, no polynomial of that degree fits, and you need to either raise the degree or accept an approximation.

The deeper principle

Here is the framing that makes all of this obvious.

A polynomial of degree n has exactly n+1 coefficients: a_0, a_1, ..., a_n. Those n+1 numbers are the polynomial's degrees of freedom. Each point condition p(x_i) = y_i imposes one linear equation on those coefficients. To pin down n+1 unknowns, you need n+1 independent equations — that is, n+1 point conditions with distinct x-values.

Fewer conditions leave you under-determined: many polynomials fit. More conditions risk over-determining: only polynomials that match across all of them survive.

Closing

Polynomials are rigid. They are over-determined by enough points — n+1 points completely pin down every coefficient of a polynomial of degree at most n. And they are under-determined by too few — three points do not pin down a cubic, because a cubic has one more degree of freedom than a quadratic.

So whenever someone asks whether two polynomials that agree somewhere are the same polynomial, the right response is a counter-question: what are their degrees? Answer that, and you know exactly how many agreements you need.