Catalytic equality tests #
Two equality tests that borrow memory with arbitrary contents, use it, and give it back exactly.
addSqDist and keyTest each visit their two operands alternately, four times in all: they see
only one operand at a time, so the operands never have to be stored together. Between visits they
keep only their phase and the value they are accumulating. Arbitrary initial contents of the
borrowed memory cancel, because everything added to it is subtracted again and its contributions
to the result cancel in pairs. The equality test eqTest runs addSqDist twice, so it makes eight
visits.
This file proves what the tests compute and that they restore the borrowed memory. It has no machine model, and no theorem bounds the number of visits or the storage.
The registers are those of the Cook–Mertz procedure (Cslib.TreeEval.proc): a register file
S : ι → Fin ℓ → R, whose registers hold ℓ ring elements and are updated with Function.update.
A test borrows one register r of the file, for instance a register of Cslib.TreeEval.State
(the case ι = Fin 3 over a field). As there, a call carries a coefficient c, and the call with
-c undoes it.
The sum-of-squares test. addSqDist c r x y adds c · ⟨x - y, x - y⟩ = c · ∑ᵢ (xᵢ - yᵢ)²
to an accumulator z, whatever the contents of S and z, and leaves S unchanged
(addSqDist_eq). Visiting x masks register r with x and adds c ⟨x, x⟩; visiting y adds
c (⟨y, y⟩ - 2 ⟨S r, y⟩); visiting x again unmasks r; visiting y again adds 2c ⟨S r, y⟩.
The two inner products with y see S r + x and S r, so the unknown contents of S r cancel
and -2c ⟨x, y⟩ remains. eqTest runs this with c = 1, observes whether the accumulator
changed, and runs it with c = -1, which restores the registers and the accumulator
(eqTest_snd).
This four-visit test follows the construction in OpenAI's Lean formalization accompanying
[OAI26e], the file
CatalyticComparison.lean
at revision 7ef5c0cc: its fair (composed of first, second, pointR and pointZ)
is addSqDist with the same split of terms across the visits, and its lemmas pupils, back,
test_eye, paw and small correspond to addSqDist_eq, addSqDist_neg_addSqDist
(with eqTest_snd), eqTest_fst_iff_sqDist (with eqTest_eq) and natCast_sqDist_eq_zero_iff.
The construction is re-proved independently here: registers are vectors over a commutative ring
with the dot product, where that file uses digit-encoded natural numbers, and the names,
statements and proofs are our own.
The flag reports whether ⟨x - y, x - y⟩ = 0 (eqTest_fst_iff_sqDist), so it is
decide (x = y) when the squared distance detects equality (eqTest_eq). Over ℤ it always does
(eqTest_eq_int). Over ZMod m it can fail by wraparound: in ZMod 5, 1² + 2² = 0. It holds
for vectors of naturals below b when ℓ · (b - 1)² < m (natCast_sqDist_eq_zero_iff,
eqTest_eq_natCast).
Cost. eqTest compares the accumulator with its initial value, so a realization keeps that
value or starts the accumulator at zero. With k = size ℓ + 2 · size b bits, that is over
ZMod (2 ^ k), the test is exact for ℓ digits below b (mul_sq_lt_two_pow_size,
eqTest_eq_two_pow): the clean storage is this k-bit accumulator, a copy of its initial value
(unnecessary if it starts at zero), a phase among eight and the flag, and the borrowed register of
ℓ elements of ZMod (2 ^ k) is restored.
The key test. keyTest c a b compares two indices a b : κ with a borrowed table
V : κ → M: it adds c to V a, adds V b to a result, subtracts c from V a and subtracts
V b from the result. The table is restored and the result gains c if a = b and 0
otherwise (keyTest_eq). Over ZMod 2 with c = 1 this is the exclusive-or test of
[OAI26e]. Here the clean storage is the phase and the result.
Main definitions #
Cslib.Catalytic.addSqDist: addctimes the squared distance of two vectors to an accumulator, borrowing a register.Cslib.Catalytic.eqTest: the restoring equality test by the squared distance.Cslib.Catalytic.keyTest: the restoring equality test of two indices into a borrowed table.
Main results #
Cslib.Catalytic.addSqDist_eq: the accumulator gainsc · ⟨x - y, x - y⟩and the registers are unchanged, whatever their contents.Cslib.Catalytic.addSqDist_neg_addSqDist: the call with-cundoes the call withc.Cslib.Catalytic.eqTest_snd: the equality test restores the registers and the accumulator.Cslib.Catalytic.eqTest_fst_iff_sqDist: its flag reports whether the squared distance vanishes.Cslib.Catalytic.eqTest_eq: for any contents of the registers and the accumulator, the test returnsdecide (x = y)and restores them, when the squared distance detects equality.Cslib.Catalytic.eqTest_eq_int: so overℤ.Cslib.Catalytic.natCast_sqDist_eq_zero_iff: the squared distance of digit vectors belowbdetects equality inZMod mwhenℓ · (b - 1)² < m.Cslib.Catalytic.eqTest_eq_natCast: so overZMod munder that bound.Cslib.Catalytic.mul_sq_lt_two_pow_size:ℓ · (b - 1)² < 2 ^ (size ℓ + 2 · size b).Cslib.Catalytic.eqTest_eq_two_pow: the test is exact with asize ℓ + 2 · size b-bit accumulator.Cslib.Catalytic.keyTest_eq: the key test restores the table and addscexactly when the keys agree.
References #
- M. Ben-Or and R. Cleve, Computing algebraic formulas using a constant number of registers: background, registers with arbitrary initial contents whose contributions cancel.
- H. Buhrman, R. Cleve, M. Koucký, B. Loff and F. Speelman, Computing with a full memory: catalytic space: background, transparent programs.
- OpenAI, Exact Derandomization of Logarithmic Space: L = RL = BPL,
Lemma 9.9 (the key test over
ZMod 2; preprint, not peer reviewed), and the accompanying Lean fileCatalyticComparison.lean(revision7ef5c0cc) for the sum-of-squares test.
Add c · ⟨x - y, x - y⟩ to the accumulator, borrowing register r of the register file. The
four visits see x, y, x, y in turn.
The sum-of-squares test adds the squared distance. Whatever the contents of the registers
and the accumulator, the accumulator gains c · ⟨x - y, x - y⟩ and the registers are unchanged.
The restoring equality test. Add the squared distance of x and y to the accumulator,
observe whether the accumulator changed, and subtract the squared distance again. The result is
the flag together with the registers and the accumulator.
The equality test restores the registers and the accumulator.
The flag of the equality test reports whether the squared distance vanishes.
The restoring equality test is exact whenever the squared distance detects equality: for
any contents of the registers and the accumulator, the flag is decide (x = y) and the registers
and the accumulator are restored.
No wraparound for small digits. For vectors of naturals below b, the squared distance of
their images in ZMod m vanishes only if they are equal, provided ℓ · (b - 1)² < m.
Over ZMod m, the restoring equality test of digit vectors below b is exact when
ℓ · (b - 1)² < m.
The equality test with a size ℓ + 2 · size b-bit accumulator. Over
ZMod (2 ^ (size ℓ + 2 · size b)), the restoring equality test of ℓ digits below b is exact
for any contents of the registers and the accumulator.
The key test. Add c to the entry of the borrowed table at a, add the entry at b to
the result, subtract c from the entry at a, and subtract the entry at b from the result. The
four visits see a, b, a, b in turn.
The key test restores the table and adds c to the result exactly when the keys agree,
whatever the contents of the table.