General proofs, by algebra
A check tests a theorem on one figure. A proof here covers every figure at once: the coordinates are letters, the hypotheses and the conclusion are polynomials, and the proof is a single polynomial identity that you can multiply out yourself.
From a figure to polynomials
Take Thales' theorem: an angle inscribed in a semicircle is a right angle. Put the centre at the origin and the diameter along the x-axis, from to . Nothing is lost by this choice of axes. The third point is on the circle, and that is the one hypothesis:
The conclusion is that and are perpendicular, so their dot product vanishes:
Here , so the conclusion follows from the hypothesis for every , and . That one line is a complete proof of the theorem. Most theorems need more algebra, but the shape is the same.
The coordinates come in three kinds. Some are numbers, fixed by the choice of axes. Some are parameters: and above, free to take any value, so that the figure is a general one. The rest are unknowns, tied to the earlier coordinates by the hypotheses: above. Each unknown comes with one hypothesis.
import { configuration } from "@ratmath/geo";
const T = configuration("Thales");
const O = T.at("O", 0, 0);
const r = T.parameter("r");
const A = T.at("A", r.neg(), 0);
const B = T.at("B", r, 0);
const C = T.on("C", (P) => T.onCircle(P, O, A)); // x free, y tied down by the circle
const proof = T.prove(T.rightAngle(A, C, B));
proof.proved; // true
proof.method; // "wu"
proof.replay(); // true: the identity was multiplied out again
What counts as a proof
Let be the hypotheses and the conclusion. A proof is an identity between polynomials
with a multiplier that is not the zero polynomial. At any figure where every is zero the right side is zero, so , and wherever that forces . The identity can be checked by expanding both sides. Nothing about how it was found needs to be trusted, and proof.replay() does that expansion each time it is called.
The multiplier matters. Its factors are the degenerate cases, the figures the proof does not cover: a triangle whose corners are in a line, two points that coincide, two lines that were supposed to meet but are parallel. A textbook proof assumes these away silently. Here they are computed, and proof.conditions lists them with a geometric reading where one is recognised.
import { proofs } from "@ratmath/geo";
const p = proofs.eulerLine().parts[0]; // O, G, H are collinear
String(p.identity.multiplier); // "b·d" for A = (0, 0), B = (b, 0), C = (c, d)
p.identity.cofactors.map(String); // the six cᵢ
p.conditions.map((c) => c.meaning); // ["A, B, C are not collinear"]
p.explain(); // the whole proof as text
So the Euler line theorem is proved for every triangle that is not flat, which is every triangle.
Wu's method
Build the figure one point at a time, and each new unknown coordinate arrives with the hypothesis that pins it down. The hypotheses are then in triangular form: involves the first unknown, the first two, and so on. Wu Wen-tsün's method divides the conclusion by the hypotheses in reverse order, each time treating the hypothesis as a polynomial in the unknown it introduced.
Division by a polynomial whose leading coefficient is itself a polynomial needs pseudo-division: multiply by that leading coefficient first, so that no fractions appear.
where is the leading coefficient of as a polynomial in . If after dividing by every hypothesis the remainder is zero, the pieces assemble into the identity above, with a product of leading coefficients. The method is fast, because it never does more than follow the construction backwards. Every theorem in the list on this page is proved this way in a few milliseconds, except Desargues' theorem, which takes about a third of a second.
When a point is given by two conditions that both involve both of its coordinates (the intersection of two lines, say), the library first eliminates one coordinate between them, again by pseudo-division, and keeps track of how the new polynomials are built from the original hypotheses, so that the final identity is still in terms of those.
The Gröbner method
The second method follows Kapur. Treat the parameters as constants, that is, work with polynomials in the unknowns whose coefficients are rational functions of the parameters. The conclusion follows from the hypotheses, for general values of the parameters, exactly when
for a new variable . (If the hypotheses hold and , the last generator is 1; if they hold and , choose . So the generators have no common zero exactly when vanishes wherever the hypotheses do. This is Rabinowitsch's trick, the same one that proves the Nullstellensatz.) A Gröbner basis decides the question, and its cofactors, with denominators cleared and replaced by , are the identity. The multiplier is then a polynomial in the parameters alone, so the degenerate cases are conditions on the given points only.
const w = proofs.simson({ method: "wu" });
const k = proofs.simson({ method: "groebner" });
[w.proved, k.proved]; // [true, true]
k.conditions.map((c) => c.meaning); // ["A, B, C are not collinear", "A ≠ C", "B ≠ C"]
[w.size.cofactorTerms, k.size.cofactorTerms]; // the two certificates differ, and both multiply out
The Gröbner method is complete where Wu's simple form is not: it finds a proof whenever the statement holds for general parameters. It is also much slower when the hypotheses are not linear in the unknowns, since it computes with fractions of polynomials. With method: "auto" (the default) Wu's method goes first; if it fails, one figure with random whole-number parameters is tried; and only if the conclusion holds at every solution of that figure is the Gröbner method run, with a time limit.
What algebra cannot see
Polynomial equations do not distinguish inside from outside or one side of a line from the other. Three consequences are worth knowing.
- Bisectors. The condition "equal angles" describes the internal and the external bisector together. A point on a bisector at A and a bisector at B is the incentre or one of the three excentres;
tritangentCentermeans all four. Theorems true of all four (the third bisector passes through, the distances to the sides are equal) are proved. Theorems true only of the incentre are not, and the report says at how many of the solutions the conclusion held. - Second intersections. "A point on this line and on this circle" has two solutions, and if one of them is already in the figure, the algebra allows the new point to be the old one. Use
otherIntersection, which asks for the second point by a linear condition. The butterfly theorem is proved when stated that way and fails when stated loosely, as it should. - Complex figures. The identity holds for complex coordinates too. That is usually harmless, but it means a statement can be true of all real figures and still not provable this way, if it fails for complex ones.
When no proof exists the result has proved: false and an instance: the parameters tried, the number of solutions of the hypotheses there, and at how many the conclusion holds. A statement that is simply false shows 0.
const T = configuration("a false statement");
const A = T.at("A", 0, 0), B = T.at("B", "b", 0), C = T.at("C", "c", "d");
const M = T.midpoint("M", B, C);
const no = T.prove(T.perpendicular(A, M, B, C)); // "every median is an altitude"
no.proved; // false
no.instance; // { parameters: { b: 14, c: 13, d: 22 }, solutions: 1, holdsAt: 0 }
Stating your own theorem
A configuration is built from points. The predicates return polynomials, and serve both as conditions on a new point and as conclusions.
| Points | meaning |
|---|---|
| T.at(name, x, y) | given coordinates: numbers, names of parameters (made on first use), or expressions |
| T.free(name) | both coordinates are parameters |
| T.on(name, P => condition, { free }) | one coordinate free, the other tied down by one condition |
| T.where(name, P => [c1, c2]) | both coordinates tied down by two conditions |
| T.parameter(name), T.unknown(name, v => condition) | a free number; a number defined by an equation, such as s with s² = 3 |
| midpoint, intersection, foot, reflection, parallelogram | constructions: T.intersection("P", [A, B], [C, D]) |
| circumcenter, orthocenter, centroid, tritangentCenter | triangle centres |
| onLine, onCircumcircle, otherIntersection | points on a line or circle |
| Predicates and quantities | vanishes when |
|---|---|
| collinear(A, B, C), concurrent(l1, l2, l3) | three points on a line; three lines through a point |
| parallel(A, B, C, D), perpendicular(A, B, C, D) | AB ∥ CD; AB ⊥ CD |
| equidistant(P, A, B), equalLength(A, B, C, D) | |PA| = |PB|; |AB| = |CD| |
| onCircle(P, O, A), concyclic(A, B, C, D), tangent(l, O, P) | circles |
| rightAngle(A, B, C), equalAngle(A, B, C, D, E, F) | angles, as angles between lines |
| isMidpoint(M, A, B) | two polynomials |
| distance2, area2, dot, cross, equal(a, b) | build your own: T.equal(T.distance2(A, B), T.distance2(C, D).mul(4)) |
The theorems proved
provable lists them, and proofs.<id>(options) proves one. proofs.setup(id) hands back the configuration and conclusion for inspection.
| proofs.… | statement |
|---|
@ratmath/geo and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.