The same set of points has infinitely many bases, they are all correct, and they are not equally useful. One measurement separates them — the product of the vectors' lengths over the lattice determinant — and the determinant is the invariant the reduction may not change, which is what makes the reduction checkable.
A lattice is the set of integer combinations of some vectors. The vectors are a basis; the lattice is
the set of points; and unlike a vector space over the reals, where any two bases of the same subspace
are related by an invertible matrix, here the relation has to be unimodular — integer entries,
integer inverse, determinant ±1 — because the integer combinations have to land on the same points
either way.
That leaves a great deal of freedom, and it is freedom to describe a very simple object extremely
badly.
Fig. 1 The dots are the lattice generated by (1, 0) and (7, 1) — all of ℤ², since the second vector’s second
coordinate is 1. The long pair of arrows is that basis. The short pair is what an exact reduction
returns, and the dots do not move.
The lattice in the figure is all of ℤ² — the integer points of the plane, the simplest lattice there
is. The basis it is handed describes those points as combinations of (1, 0) and (7, 1), which is
true, and which makes the coefficient of a point like (0, 1) equal to (−7, 1) rather than to anything
obvious. Nothing is wrong. Every point is reachable, uniquely, with integer coefficients. The
description is simply seven times worse than it has to be, and at a skew of 10²⁰ it would be 10²⁰
times worse without ever becoming incorrect.
The quantity that separates two bases of one lattice #
Any basis of a lattice spans a fundamental cell, and every basis of the same lattice spans a cell of
the same volume, because the determinant of a unimodular change is ±1. So the volume — the lattice
determinant — is an invariant: it belongs to the lattice and not to the description.
What varies is the shape. Hadamard’s inequality says the product of the basis vectors’ lengths is at
least the volume they enclose, with equality exactly when they are mutually orthogonal, so the ratio
orthogonality defect = (Π ‖bᵢ‖) / |det B|
is at least one for every basis, equal to one only for an orthogonal one, and larger the more skewed
the description is. It is a single number and it is exactly the thing a reduction reduces.
That is the same inequality the modular route budgets primes
with, used the other way round: there it bounds a
determinant from above by row lengths, here it bounds row lengths from below by a determinant. It is
one theorem doing two jobs in one field, which is worth noticing because the two look unrelated.
Reduced in exact arithmetic, and why that is not fussiness #
The reduction here runs in exact rational arithmetic: the Gram–Schmidt coefficients are fractions, the
size-reduction rounds an exact rational to the nearest integer, and the exchange condition is decided
by comparing two exact rationals.
That is not a purity gesture. A lattice reduction is a discrete algorithm whose decisions are
comparisons — swap or do not swap, subtract this integer multiple or that one — and a comparison
decided by a float that is a rounding away from the boundary is a different algorithm on some inputs.
It is the same shape of failure as
a partition decided in the last digit: the output is
not a number that could be slightly wrong, it is a basis that is either this one or that one.
The rounding inside is the part most likely to be got wrong quietly. The coefficient being rounded can
exceed 2⁵³ on a basis with long vectors, and Math.round(Number(q)) then rounds the wrong integer —
which leaves the basis unreduced without failing anything, because the algorithm’s postcondition is
about sizes rather than about that particular step. So the rounding here is written on the numerator
and denominator directly, and the reduced basis is asserted to be integral before it is returned.
Every step of the reduction is a unimodular operation: subtract an integer multiple of one basis
vector from another, or exchange two. So the lattice determinant must be unchanged at the end, exactly
— not to a tolerance, as an integer.
That is the check, and it is a good one because it is sensitive to precisely the mistakes an
implementation makes. A size reduction with the wrong rounding still preserves it. A swap implemented
as an overwrite does not. A coefficient computed as a float and truncated does not. The determinant is
1 before and 1 after on the hero’s lattice, and the assertion compares integers.
The defect, meanwhile, is asserted to have gone down rather than up — which sounds trivial and is the
other half of the pair. A reduction that preserved the determinant and made the basis worse would be
a correct unimodular transformation and a useless one.
Fig. 2 A skew of forty, where the starting basis has a defect of 40.0125 and the reduction returns one at
exactly 1. The lattice determinant is 1 in both cases and the picture is the same set of points.
What the reduction actually does here, in one step #
On this family the algorithm is short enough to follow completely, and following it makes the two
halves of a reduction visible separately.
The basis is (1, 0) and (k, 1). The Gram–Schmidt coefficient of the second against the first is
exactly k — a rational whose denominator is 1 — so the size-reduction step subtracts k times the
first vector from the second and leaves (0, 1). The exchange condition is then satisfied, the loop
ends, and the returned basis is the standard one.
One step, at every skew from 2 to 40. The defect falls from a little over k to exactly 1, the
determinant is 1 throughout, and the number of steps does not grow with the skew at all — which is
worth noticing, because the size of the coefficient does. A size reduction on a basis with a skew of
10²⁰ is one step whose coefficient has sixty-seven bits in it, and it is the arithmetic on that
coefficient rather than the number of steps that costs.
That is the field’s usual observation arriving in a new place: the operation count is one and the
price is the length of the operand. It is also why the exact rounding matters. A coefficient of 10²⁰
does not survive a round-trip through a double, and the step that should have cleared the basis in one
move would leave it skewed by whatever the rounding lost.
Two connections, and the first is that this essay is a generalisation of one already written.
Rational reconstruction recovers n/d from a
residue by running the Euclidean algorithm and stopping early. The set of pairs (a, b) with
a ≡ b·u (mod m) is a two-dimensional lattice of determinant m; the answer is its shortest vector; and
the Euclidean algorithm is lattice reduction in two dimensions, where it is exact, terminating, and
two thousand years older than the problem. Everything in that essay — the uniqueness of the short
vector, the bound at √(m/2), the cliff rather than the slope — is a statement about a lattice with a
determinant, read in the smallest case.
The second connection is that a lattice is what the Smith normal
form describes. An integer matrix’s rows generate a
lattice; the Hermite normal form is a canonical basis for it; the Smith form describes the quotient.
So this field has three descriptions of one object — a canonical basis, a quotient decomposition, and
a short basis — and only the third is not canonical, because shortness does not determine a basis
uniquely. Which is the reverse of the usual situation here, where the canonical object is the
expensive one and the practical routine returns something non-unique: a Hermite form is unique and
costly, a reduced basis is cheap and is one of many, and both are correct answers to different
questions about the same set of points.
There is one thing about the algorithm that is genuinely surprising and is worth a paragraph, because
it is the only part of the whole construction that is not immediate.
The loop alternates between size reduction, which does not change any Gram–Schmidt length, and
exchanges, which do. A basis could in principle be swapped back and forth for ever. What prevents it
is a quantity that strictly decreases: the product of the Gram–Schmidt lengths raised to descending
powers, which is a positive integer for an integral basis and which an exchange multiplies by at most
δ = 3/4. A positive integer that shrinks by a quarter each time cannot do so many times.
So termination rests on the basis being integral, which is why the routine asserts that the
returned vectors have denominator 1 rather than assuming it, and why a reduction implemented over the
reals needs an entirely different argument. The guard in the code is a step cap with an assertion
attached; on every lattice drawn here the cap is never approached, and if it were the figure would
fail rather than silently return a basis the loop had abandoned.
Reduction is worth doing because a skewed basis makes easy questions hard.
Is a given point in the lattice? With an orthogonal basis it is division. With the hero’s skewed
basis the coefficients are large and alternate in sign, and rounding to the nearest lattice point by
rounding each coefficient is simply wrong — the nearest point in coefficient space is not the nearest
point in the plane when the basis is skewed. That failure is the same one
the essay on a basis of a subspace
describes in the continuous setting, where two spans of one null space behave differently under
exactly the operations that are supposed not to care.
How short is the shortest vector? The reduced basis’s first vector is within a factor of
2(n−1)/2 of it, which is a bound rather than an answer and is the property the whole algorithm is
named for. In two dimensions the reduction finds the shortest vector exactly, which is why
reconstruction can be said to find rather than approximate — and it is the reason the previous
essay could assert a cliff rather than a trend.
And the conditioning of the basis matrix. The defect and the condition number are different
quantities and they move together: a defect of 40 on the hero’s lattice comes with a basis matrix
whose two-norm condition number is about 40 as well. The relation is not exact — the defect is a
product of lengths over a determinant, the condition number is a ratio of singular values — but they
are both measuring the same skew, from the two directions this site usually measures things from. It
is the one place in this field where a condition number is still doing work: not amplifying an error,
since there is none, but describing how badly a description was chosen.
Fig. 3 A skew of two, where the defect is 2.24 and one size reduction is enough.
Where a badly chosen description turns up elsewhere on this site #
The general complaint — the object is fine and the description is terrible — is one this collection
has made in four other places, and collecting them is the fastest way to see what is particular about
the lattice case.
A basis that is the same subspace and not the same thing
is the continuous version: three spans of one null space, identical as subspaces, behaving differently
under a projection because their bases are conditioned differently.
The units the matrix is measured in is the same
complaint about a scaling: one problem, many descriptions, and a condition number that reports the
description rather than the problem.
A condition number scaling cannot move is the
counterweight — the part of the difficulty that survives every rescaling and therefore does belong to
the object.
And the ordering a sparse elimination is given is a
description whose choice changes the cost by orders of magnitude with the answer untouched.
What is unusual here is that the badness has a number with a floor, and the floor is attained. A
condition number has no natural best value for a given problem; the orthogonality defect’s best value
is 1, it is 1 exactly when the description is as good as descriptions get, and there is a theorem
saying so. That is a rarity on this site, where most quantities are compared against a bound nobody
reaches.
The refusal, which is a bound rather than a preference #
The claim worth breaking is that a reduced basis is orthogonal. It is not, and cannot be in general:
most lattices have no orthogonal basis at all, and the reduction returns the best it can find in
polynomial time rather than the best that exists.
The defect after reduction on the hero’s lattice is exactly 1, because ℤ² does have an orthogonal
basis and the reduction finds it. On a lattice that does not, the defect after reduction is above 1
and stays there — and the assertion that a reduced basis achieves a defect below one is fed the
reduced basis and has to reject it, because Hadamard’s inequality forbids it for every basis of every
lattice.
That is a refusal of a different kind from most on this site. Usually the claim being broken is one
somebody might reasonably hold; this one is broken by a theorem, and the assertion exists to make sure
the code’s notion of the defect is the one the theorem is about. A defect computed with a determinant
of the wrong sign, or with lengths rather than squared lengths, would sail below one and nothing else
in the routine would notice.
Higher dimensions, and what is not measured here #
Everything above is drawn in two dimensions, where the reduction finds the genuinely shortest vector
and the picture can show the lattice. That is a real limitation and it is worth stating what it
hides.
In dimension n the algorithm guarantees only that its first vector is within 2(n−1)/2 of the
shortest — a bound that is exponential in n and is nearly attained on constructed examples. So
“reduced” means something much weaker than it does here: a basis whose defect has been improved by a
provable factor rather than a basis that is as good as the lattice allows. Finding the shortest vector
exactly is believed to be hard, and a great deal of modern cryptography rests on its being so.
The implementation here is the original algorithm with δ = 3/4, in exact rationals, which means it is
correct and it is not fast: a full Gram–Schmidt is recomputed after every step rather than updated,
and the coefficients are exact fractions rather than floating point with a controlled error. Both
choices are deliberate — the whole point of this field is that the comparisons are decided exactly —
and both would be wrong in a routine meant for the dimensions where the algorithm is actually used.
What the two-dimensional case does give is the complete picture: a conserved quantity, a reduced
quantity, a bound relating them, and a reduction that attains the bound. The n-dimensional case has
all four objects and attains nothing, and the honest way to introduce it is with the case where the
arithmetic can be watched.
Fig. 4 A skew of five: defect 5.10 before, 1 after, determinant unchanged.Fig. 5 Twelve, where the arrows have left the drawn window and the dots have not moved.Fig. 6 Twenty, where the defect before is 20.03 and one size reduction still clears it.Fig. 7 The two-dimensional case, where the short vector is a fraction and the bound is the cliff.Fig. 8 And a lattice whose short vector has one very small coordinate.Fig. 9 The other description of a lattice: the invariant factors of the map that generates it.Fig. 10 Three-digit entries, where the Hermite transform’s growth is visible against the Smith form’s.Fig. 11 The lattice determinant, computed three exact ways.Fig. 12 Orthogonality as a measured number in the continuous setting, which the defect is the discrete
analogue of.Fig. 13 Loss of orthogonality during a factorisation, which a lattice reduction cannot suffer because it
never rounds.Fig. 14 The lengths a lattice computation has to carry, in the field’s usual unit.Fig. 15 And the growth that exact rational Gram–Schmidt would suffer without reduction.Fig. 16 A skew of three, where one size reduction returns the standard basis.Fig. 17 Eight, where the defect before is 8.06 and after is exactly 1.Fig. 18 Thirty, where the arrows leave the frame and the dots do not move.Fig. 19 The same reduction in the case where the short vector is a fraction.Fig. 20 The quotient of the lattice by the image of an integer map.Fig. 21 A unimodular map, which changes a description and not a lattice.Fig. 22 The determinant that every unimodular step preserves.Fig. 23 Hadamard used the other way round, bounding a determinant by lengths.Fig. 24 The invariant factors read modulo a prime.Fig. 25 The lengths an exact Gram–Schmidt has to carry.Fig. 26 A skew of four.Fig. 27 Sixteen, where the defect before is 16.03.Fig. 28 And twenty-five.Fig. 29 The two-dimensional reduction with a large numerator.Fig. 30 The invariant factors of a map on the same lattice.Fig. 31 The lattice determinant, computed three ways.Fig. 32 Its rank, read in three rings.Fig. 33 Hadamard, whose equality case is an orthogonal basis.