Exact division on the integer lattice, Bézout coefficients, and sums of two squares.
gaussian-integers-le.le · output · proof · check · playground
The question
What divides both 19 + 8i and 3 − 5i when divisors can themselves be complex? And how can the same algorithm turn 2029 into a sum of two squares?
Historical background
Gauss used integers of the form a + bi in his work on biquadratic residues. In the second memoir, published in 1832, divisibility extends from the number line to the integer lattice. Division with a shrinking remainder lets Euclid’s algorithm work there too. Gauss’s second memoir, ETH Library
Dividing on the lattice
A Gaussian integer has integer real and imaginary parts. The program writes
19 + 8i as [19, 8]. To divide two Gaussian integers, it multiplies by the
divisor’s conjugate and rounds each component of the quotient to the nearest
integer. For a component M / N, with N > 0, the expression
(2 * M + N) // (2 * N) does the rounding with exact integers. At a tie it
chooses the greater integer, so −½ rounds to 0.
The squared modulus of [A, B] is A * A + B * B. Since each component of the
rounding error has magnitude at most ½, the remainder’s squared modulus is
at most half the divisor’s. The remainder becomes the next divisor, so its
squared modulus decreases until the remainder is zero.
What eyemind concludes
% query divisors with scenario lattice
the pair [19, 8] and [3, -5] has Gaussian gcd [1, 4] with coefficients [0, -1] and [-4, 1].
the pair [1, 0] and [-1, 1] has Gaussian gcd [1, 0] with coefficients [1, 0] and [0, 0].
% query squares with scenario lattice
1009 is the sum of the squares of 15 and 28.
2029 is the sum of the squares of 2 and 45.
The check report records the same answers as Logic Script terms.
struct('le:answer', 'divisors', 'lattice', [19, 8], [3, -5], [1, 4], [0, -1], [-4, 1])
struct('le:answer', 'squares', 'lattice', 2029, 2, 45)
The coefficients give (−i)(19 + 8i) + (−4 + i)(3 − 5i) = 1 + 4i. The
rules build that identity on the way back from the last division. If the
recursive call gives G = U*B + V*R and division gives R = A − Q*B, the
coefficients of A and B are V and U − Q*V. Multiplying the gcd and
both coefficients by the same unit gives the representative with positive
real part and nonnegative imaginary part.
How 2029 splits
The scenario supplies 992 as a candidate square root of −1 modulo 2029. The program checks the congruence, then computes the Gaussian gcd of 2029 and 992 + i.
| Dividend | Divisor | Rounded quotient | Remainder |
|---|---|---|---|
| 2029 | 992 + i | 2 | 45 − 2i |
| 992 + i | 45 − 2i | 22 + i | 0 |
Multiplying the last nonzero remainder by i gives 2 + 45i. The final rule checks that its squared modulus is 2029, giving the two squares.
What the proof establishes
The saved proof is checked against the compiled Logic Script program.
The checker follows each recursive call to the zero remainder and checks
the quotient rounding, coefficient updates and rotation on the way back.
--explain shows those steps in Logical English.
Try it
node bin/eyemind.js examples/gaussian-integers-le.le
node bin/eyemind.js --explain examples/gaussian-integers-le.le
node bin/eyemind.js --check-proof examples/proof/gaussian-integers-le.js examples/gaussian-integers-le.le
