Notes

Chapter 5: Two Dimensions and Beyond

Section 7: Systems Based on Constraints


Diophantine equations

Any algebraic equation—such as x^3 + x + 1 == 0—can readily be solved if one allows the variables to have any numerical value. But if one insists that the variables are whole numbers, then the problem is more analogous to the discrete constraints in the main text, and becomes much more difficult. And in fact, even though such so-called Diophantine equations have been studied since well before the time of Diophantus around perhaps 250 AD, only limited results about them are known.

Linear Diophantine equations such as a x == b y + c yield simple repetitive results, as in the pictures below, and can be handled essentially just by knowing ExtendedGCD[a, b].

Even the simplest quadratic Diophantine equations can already show much more complex behavior. The equation x^2 == a y^2 has no solution except when a is a perfect square. But the Pell equation x^2 == a y^2 + 1 (already studied in antiquity) has infinitely many solutions whenever a is positive and not a perfect square. The smallest solution for x is given by

Numerator[FromContinuedFraction[ContinuedFraction[Sqrt[a], If[EvenQ[#],#,2#]&[Length[Last[ContinuedFraction[Sqrt[a]]]]]]]]

This is plotted below; complicated variation and some very large values are seen (with a=61 for example x==1766319049).

In three variables, the equation x^2 + y^2 == z^2 yields so-called Pythagorean triples {3, 4, 5}, {5, 12, 13}, etc. And even in this case the set of possible solutions for x and y in the pictures below looks fairly complicated—though after removing common factors, they are in fact just given by {x == r^2 - s^2, y == 2 r s, z == r^2 + s^2}. (See page 1078.)

The pictures below show the possible solutions for x and y in various Diophantine equations. As in other systems based on numbers, nested patterns are not common—though page 1160 shows how they can in principle be achieved with an equation whose solutions satisfy Mod[Binomial[x, y],2]==1. (The equation (2x+1)y==z also for example has solutions only when z is not of the form 2^j.)

Many Diophantine equations have at most very sparse solutions. And indeed for example Fermat's Last Theorem states that x^n + y^n == z^n can never be satisfied for n > 2. With four variables one has for example 3^3 + 4^3 + 5^3 == 6^3, 1^3 + 6^3 + 8^3 == 9^3—but with fourth powers the smallest result is 95800^4 + 217519^4 + 414560^4 == 422481^4.

(See pages 791 and 1164.)


From Stephen Wolfram: A New Kind of Science [citation]