Geometry

The remainders that count the roots

Run Euclid's algorithm on a polynomial and its derivative, flipping the sign of each remainder, and write down the signs of the whole chain at any point. The number of sign changes drops by exactly one each time the point passes a real root — so the roots in any interval can be counted, exactly, without finding a single one.
22 min read 6 figures The same thing twiceSmall cases lie

Worth reading first: The oldest algorithm, drawn as a tiling · What the coefficients already know.

How many real solutions does x55x3+x2+3x1=0x^5 - 5x^3 + x^2 + 3x - 1 = 0 have? A graph suggests an answer, and the answer a graph suggests is exactly what cannot be trusted: a curve that dips to touch the axis and a curve that dips just past it look the same at any resolution coarse enough to see the whole curve. What the coefficients already know found one exact answer for cubics, the sign of the discriminant, and no such single number works beyond degree three.

In 1829 Charles Sturm found a procedure that works for every degree and every interval, and it is Euclid’s algorithm. Divide the polynomial by its derivative, keep the remainder with its sign reversed, divide the derivative by that, and so on down to a constant. Evaluate the signs of the whole chain at a point and count how often they change. That count drops by one exactly when the point crosses a real root, and at no other time, so the difference between the counts at two ends of an interval is the number of real roots inside it.

Counting the real roots of x⁵ − 5x³ + x² + 3x − 1 with Euclid's algorithm. Above, the graph of a polynomial over an interval with its real roots marked; below, a step function counting sign changes in the polynomial's Sturm chain, which drops by one at each root; beside them the chain of polynomials listed.
Fig. 1 Top: p(x)=x55x3+x2+3x1p(x) = x^5 - 5x^3 + x^2 + 3x - 1 on [2.5,2.5][-2.5, 2.5]. Bottom: the number of sign changes along its Sturm chain — pp, pp', and the remainders of Euclid’s algorithm on them with their signs flipped — evaluated exactly at 400 points. The count falls from 5 to 0, one step at each real root and nowhere else, so the interval holds exactly 5 real roots; the roots were found separately, all five complex roots at once, and all five lie on the real line.

The chain, built like a tiling

The construction is the one the oldest algorithm performs on two lengths, applied to two polynomials. Write p0=pp_0 = p and p1=pp_1 = p'. Divide p0p_0 by p1p_1, getting a quotient and a remainder of lower degree; call the negative of the remainder p2p_2. Divide p1p_1 by p2p_2 and call the negative of that remainder p3p_3. Continue until the remainder is zero. Each step lowers the degree by at least one, so for a polynomial of degree 5 the chain has at most six members.

The only change from Euclid’s own algorithm is the sign. The remainders are the same polynomials, up to that reversal, and the last non-zero one is the greatest common divisor of pp and pp', exactly as the last non-zero remainder of two whole numbers is theirs. Dividing each member by a positive number changes no signs, so the chain can be kept in whole numbers:

p210x33x212x+5,p3171x226x45,p414,026x6,741,p51.p_2 \propto 10x^3 - 3x^2 - 12x + 5, \quad p_3 \propto 171x^2 - 26x - 45, \quad p_4 \propto 14{,}026x - 6{,}741, \quad p_5 \propto 1.

The coefficients grow as the degree falls — 14,026 from a polynomial whose largest coefficient was 5 — because each division by a fraction multiplies out its denominators. That growth is the practical cost of the method, and it is why computer algebra systems use a refinement, the subresultant chain, that keeps them in check. The idea is unchanged.

The Sturm chain of x⁵ − 5x³ + x² + 3x − 1, and its sign changes. A table with the polynomials of a Sturm chain down the side, sample points across the top including minus and plus infinity, a plus or minus sign in each cell, and the number of sign changes in each column along the bottom.
Fig. 2 The Sturm chain of x55x3+x2+3x1x^5 - 5x^3 + x^2 + 3x - 1 — the polynomial, its derivative, and each remainder of Euclid’s algorithm with its sign reversed, scaled by positive numbers to whole coefficients — and the sign of each at -\infty, at 3,2,1,0,1,2,3-3, -2, -1, 0, 1, 2, 3 and at ++\infty, with the number of sign changes down each column counted along the bottom. The count falls from 5 at -\infty to 0 at ++\infty, so pp has exactly 5 real roots, and reading along the row says which gaps they sit in.

The table is the whole method. At -\infty each polynomial has the sign of its leading term times (1)(-1) to its degree, and the column reads ,+,,+,,+-, +, -, +, -, + — five changes. At ++\infty every leading coefficient is positive and the column is all ++, no changes. So the quintic has exactly five real roots: it has no complex ones at all. The columns in between say where they are: the count drops from 5 to 4 between 3-3 and 2-2, from 4 to 3 between 1-1 and 0, from 3 to 1 between 0 and 1 — two roots there — and from 1 to 0 between 1 and 2.

One entry in the table is 0: p2p_2 vanishes at x=1x = 1, since 10312+5=010 - 3 - 12 + 5 = 0. A zero is simply skipped when counting changes, and the next section explains why that is always safe for the members after the first.

Why the count moves only at roots

There are two things to show: the count does not change when xx crosses a root of one of the later members, and it drops by exactly one when xx crosses a root of pp itself.

The first comes from the division that defined the chain. Each step says pk1=qkpkpk+1p_{k-1} = q_k\,p_k - p_{k+1}. At a root of pkp_k this reads pk1=pk+1p_{k-1} = -p_{k+1}: the two neighbours of the vanishing member have opposite signs. Just before the root and just after it, the triple (pk1,pk,pk+1)(p_{k-1}, p_k, p_{k+1}) reads (+,?,)(+, ?, -) or (,?,+)(-, ?, +), and whatever pkp_k’s sign, the triple contains exactly one change. So crossing a root of a middle member leaves the count where it was. That is why the sign reversal is there: with Euclid’s plain remainders the neighbours would have the same sign at such a point, and the count would jump.

The second is a fact about derivatives. Near a simple root of pp, the function is increasing if p>0p' > 0 and decreasing if p<0p' < 0. Either way pp and pp' have opposite signs just before the root and the same sign just after it. The first pair in the chain loses a sign change as xx crosses the root, and nothing else changes, so the count drops by exactly one.

Two consecutive members never vanish at the same point, because a common root of pkp_k and pk+1p_{k+1} would, by the same division identity, be a root of every member back to pp and pp', and so of their greatest common divisor. When the gcd is a constant that cannot happen. The count is therefore a staircase that steps down by one at each real root of pp, flat everywhere else — the blue line under the graph above, which the figure evaluated exactly, in whole-number arithmetic, at four hundred points.

Two roots the graph cannot separate

Counting the real roots of 10,000x⁴ − 40,001x² + 40,002 with Euclid's algorithm. Above, the graph of a polynomial over an interval with its real roots marked; below, a step function counting sign changes in the polynomial's Sturm chain, which drops by one at each root; beside them the chain of polynomials listed.
Fig. 3 The same two panels for 10,000x440,001x2+40,00210{,}000x^4 - 40{,}001x^2 + 40{,}002 on [1.3,1.5][1.3, 1.5]. The count falls from 2 to 0 at what looks like a single point, because two of the roots lie 3.5×1053.5 \times 10^{-5} apart, closer than the 400 sample points can separate — the graph shows one touching point and the count says two crossings. The roots were found separately, all four complex roots at once, and two lie on the real line inside the interval.

The polynomial 10,000x440,001x2+40,00210{,}000x^4 - 40{,}001x^2 + 40{,}002 factors as (x22)(10,000x220,001)(x^2 - 2)(10{,}000x^2 - 20{,}001), so its positive roots are 21.414214\sqrt 2 \approx 1.414214 and 2.00011.414249\sqrt{2.0001} \approx 1.414249. On the interval from 1.3 to 1.5 its graph looks like a parabola resting on the axis at one point. It is not. It crosses the axis, dips below it by 0.000025, and crosses back, all within a stretch of 0.000035.

No plot at a sensible scale can show that, and a program that looks for sign changes of pp on a grid of four hundred points misses it too, because both crossings fall between the same two grid points, where pp is positive at each. The Sturm count at the two ends of the interval says 2 and 0, two roots, not one and not none — and it says so from the signs of five polynomials at two points, with no resolution involved at all.

That is the sense in which the count is exact and the graph is not. A tangency, a pair of close crossings and a near miss look the same from a distance, and they are three different answers to the question of how many roots there are. Sturm’s chain tells them apart at any distance.

Counting the real roots of x⁴ − 2x² + x + 3 with Euclid's algorithm. Above, the graph of a polynomial over an interval with its real roots marked; below, a step function counting sign changes in the polynomial's Sturm chain, which drops by one at each root; beside them the chain of polynomials listed.
Fig. 4 The same panels for x42x2+x+3x^4 - 2x^2 + x + 3 on [2.5,2.5][-2.5, 2.5]: the count stays at 2 across the whole interval, so there is no real root in it at all, although the graph comes within 0.94 of the axis. The roots were found separately, all four complex roots at once, and none is real.

The third case is the near miss, and x42x2+x+3x^4 - 2x^2 + x + 3 is a mild one: its graph sags towards the axis near x=1x = -1 but stays about 0.94 above it. The chain’s count is 2 at both ends of the interval, and indeed at -\infty and ++\infty, so there is no real root anywhere. The two sign changes that never go away are the two conjugate pairs of complex roots, which the chain counts as nothing: Sturm’s theorem sees only the real line, and says nothing about where the complex roots are, only that they are not real.

When the chain stops early

The Sturm chain of x³ − 3x + 2, and its sign changes. A table with the polynomials of a Sturm chain down the side, sample points across the top including minus and plus infinity, a plus or minus sign in each cell, and the number of sign changes in each column along the bottom.
Fig. 5 The Sturm chain of x33x+2x^3 - 3x + 2 and its signs at -\infty, 3-3, 00, 22 and ++\infty. The chain ends on x1x - 1, not a constant: that is the greatest common divisor of pp and pp', and it means pp has a repeated root. The count still falls by one at each distinct real root, 2 to 0, so pp has two distinct real roots.

Euclid’s algorithm on x33x+2x^3 - 3x + 2 and its derivative 3x233x^2 - 3 stops after one division. The derivative, scaled, is x21x^2 - 1; the remainder of x33x+2x^3 - 3x + 2 on division by it is 2x+2-2x + 2, which reversed and scaled is x1x - 1; and x1x - 1 divides x21x^2 - 1 exactly. The chain ends on a polynomial of degree one, not a constant.

That ending is information. The last member is the greatest common divisor of pp and pp', and a polynomial shares a factor with its derivative exactly when it has a repeated root: here x33x+2=(x1)2(x+2)x^3 - 3x + 2 = (x - 1)^2(x + 2), and 1 is a double root. So the first thing Sturm’s chain reports is whether any root repeats, and it reports it by the same test that tells two whole numbers whether they share a factor.

The count still works, with one change in what it counts. Every member of the chain is divisible by the gcd, and dividing it out produces a chain for (x1)(x+2)(x - 1)(x + 2), whose roots are the distinct roots of pp; dividing by the gcd flips all the signs together on one side of 1, which leaves the number of changes unchanged. So the drop from 2 to 0 says two distinct real roots, 2-2 and 1, with the double one counted once.

Finding them by counting them

Isolating the real roots of x⁵ − 5x³ + x² + 3x − 1 by counting. Rows of intervals, each row halving the intervals of the row above that contain two or more roots, every interval labelled with its root count from Sturm's theorem, ending with each root alone in its own interval.
Fig. 6 Isolating the real roots of x55x3+x2+3x1x^5 - 5x^3 + x^2 + 3x - 1: every real root lies in [8,8][-8, 8], and each interval is labelled with the number of roots Sturm’s theorem counts in it, V(left)V(right)V(\text{left}) - V(\text{right}). An interval holding two or more is halved, and one holding 0 or 1 is left alone. After 5 halvings every root sits alone in an interval of its own — (4,2)(-4, -2), (2,0)(-2, 0), (0,0.5)(0, 0.5), (0.5,1)(0.5, 1) and (1,2)(1, 2) — and each was checked against the roots found by a separate method.

A count in any interval is enough to find every root. Start with an interval guaranteed to contain all of them — Cauchy’s bound says no root of x55x3+x^5 - 5x^3 + \cdots is larger in size than 1 plus the largest coefficient after the first, which is 6, so [8,8][-8, 8] will do. Count; halve any interval whose count is two or more; count the halves; repeat. After five rounds each root is alone in an interval with rational endpoints, and the two close roots near 0.4 and 0.7 were the last to be separated.

From there any method will do. Bisection on a sign change of pp is now safe, because each interval contains exactly one simple root; Newton’s method, which can wander into another root’s basin when started carelessly, has nowhere else to go once its starting interval holds one root and pp' keeps a sign on it. This is how computer algebra systems isolate real roots with certainty, and the certainty is the point: no root was computed to do the isolating, only counted, so the result does not depend on how accurately anything was computed.

A continued fraction of polynomials

The chain has a second reading that ties it back to the rectangle. Euclid’s algorithm on two whole numbers is the continued fraction of their ratio, as a fraction that never closes showed. On two polynomials it is the continued fraction of their ratio too:

pp=q11q21q3,\frac{p}{p'} = q_1 - \cfrac{1}{q_2 - \cfrac{1}{q_3 - \cdots}},

with the minus signs coming from the reversed remainders. The quotients qkq_k are polynomials, usually of degree one, and the sign changes in the chain count how often the rational function p/pp'/p jumps from -\infty to ++\infty as xx increases — which is once at each real root of pp, because near a root p/pp'/p behaves like 1/(xr)1/(x - r). Cauchy called that number the index of the function over the interval.

The same index, computed for a different pair of polynomials, answers a question engineers ask every day: does a system described by a polynomial have all its roots in the left half of the complex plane, so that it settles rather than blowing up? Routh’s criterion of 1876 and Hurwitz’s of 1895 decide it by exactly this kind of chain, built from the polynomial’s even and odd parts, and a sign-change count along it. A test for the stability of a feedback loop is Euclid’s algorithm with its signs reversed, and it is taught to control engineers under Routh’s name without mention of Sturm or Euclid.

The coarser count that came first

Sturm’s count has an older, cheaper cousin that reads signs too, but the signs of the coefficients rather than of a chain. Descartes’ rule of signs, from 1637, says that the number of positive roots is at most the number of sign changes in the list of coefficients, and differs from it by an even number. For x55x3+x2+3x1x^5 - 5x^3 + x^2 + 3x - 1 the coefficients run +,,+,+,+, -, +, +, - once the zero is dropped: three changes, so three positive roots or one. Replacing xx by x-x gives x5+5x3+x23x1-x^5 + 5x^3 + x^2 - 3x - 1, with two changes, so two negative roots or none.

On this quintic Descartes happens to be exact — three positive roots and two negative — but only because every root is real. On x2x+1x^2 - x + 1 the rule allows two positive roots, and there are none; it can only ever offer an upper bound and a parity. The difference between the two methods is the difference between a count of changes in a fixed list and a count that moves as xx moves: Descartes reads one column, at the point where every power of xx is compared, and Sturm reads a column at every point, with a chain designed so that the columns can only differ at roots.

The derivative is in the chain for the reason Rolle’s theorem gives. Between two real roots of pp there is always a root of pp', so the real roots of the derivative interleave with those of the polynomial; the roots of the slope stay inside proves the complex version, where the derivative’s roots lie in the convex hull of the polynomial’s. Sturm’s chain is built so that only that first relationship can ever move the count: wherever the later members’ roots fall, the neighbours of a vanishing member disagree in sign, and the bookkeeping of the whole chain reduces to what pp and pp' do at a root of pp.

What the steps and the table cannot show

The step function is sampled. The blue staircases are evaluated exactly, in whole numbers, but at four hundred points, and between two samples the count could in principle do anything. The theorem says it does not — it steps down only at roots — and the figures were checked against every root found by an independent method, but a picture of a staircase is still a picture of four hundred values.

The chain says nothing about complex roots. The two sign changes that persist for x42x2+x+3x^4 - 2x^2 + x + 3 at every point are not a count of anything; its four complex roots are simply absent from the difference the theorem takes, and the chain does not say where they are. Locating complex roots needs a different argument, the argument principle, which counts how often a closed curve winds round zero.

And the whole-number coefficients grow. The chain for a quintic with coefficients below 6 ends in a member with coefficients over fourteen thousand, and for polynomials of degree 50 the plain chain is hopeless in practice. The refinements that tame it are not drawn here, and the method’s success on the examples is a statement about small degree.

Still open: how many real roots a system with few terms can have

Descartes’ rule of signs, the older and coarser count, says that a polynomial with kk non-zero terms has at most k1k - 1 positive roots, whatever its degree — x1003x57+1x^{100} - 3x^{57} + 1 has at most two, however high the powers. The bound depends on the number of terms, not on the degree, and it is sharp.

For systems of polynomial equations in several unknowns, the analogous question is open. Kushnirenko conjectured in the 1970s that the number of positive solutions of nn equations in nn unknowns is bounded by a product of term counts, as in one variable; the conjecture was disproved in 2003 by Haas, with a pair of equations in two unknowns having more solutions than it allowed. Khovanskii’s theorem gives an upper bound that depends only on the number of terms, but it is astronomically large, and nobody knows whether the true bound grows polynomially or exponentially in the number of terms. The one-variable case has an exact count and a sharp bound; the several-variable case has neither.

The gap matters in practice. Problems in robotics, chemistry and the design of mechanisms reduce to systems whose equations have few terms and high degree, and the number of real solutions is the number of physically possible configurations. Sturm’s chain has no counterpart that counts them exactly, and the bounds available are too large to be useful — so those problems are solved by numerical homotopy methods that find every complex solution and then check which are real, the method this essay’s figures used as their independent check.

Counting where locating was expected

Sturm’s theorem answers “how many” by never asking “where”. It evaluates signs of polynomials at a handful of points and reads off a count that no plot could guarantee. The method is Euclid’s, run on polynomials instead of lengths, with one sign changed so that the middle of the chain can never move the count.

The same division that decides who wins Euclid’s game by the parity of its runs decides here how many times a curve crosses a line, and where two roots run into each other is the moment the chain’s last member stops being a constant.

When the objects are hard to find, count them first — and look for an invariant that changes by exactly one each time one of them is passed. Here the invariant is a number of sign changes, the objects are real roots, and the counting turns into finding by halving intervals until each holds one. The same move counts the lattice points on a circle by a formula that never lists them, and it counts crossings in the linking of two loops by adding signs; Sturm’s version is the one where the sum is taken down a chain of remainders.

What links here

Computed from the collection, not written here: the essays that point at this one.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A dashed tag is an object no other essay names yet.

DerivativeEuclidean algorithmExact arithmeticGreatest common divisorPolynomialRootsSign