Continued-fraction recovery from dyadic prefixes #
Arora and Barak, web draft 2007-01-08, Chapter 20, Exercise §11
(printed p. 432, PDF p. 448), asks for polynomial-time recovery of the unknown coprime pair
j, r ≤ N from the first 2 log N bits of j/r. The draft leaves rounding implicit.
For positive N, Nat.clog 2 (N ^ 2) gives the ceiling of twice the base-two logarithm:
it is the least fractional bit count with dyadic cell width at most 1 / N ^ 2.
We use half-open cells (terminating-zero expansions), with the integer part included in
the cell index for numbers at least one. The result encodes the reduced numerator and
denominator, available as Rat.num and Rat.den; the numerator may exceed N.
The original decoder uses 2 * Nat.clog 2 N fractional bits.
The decoder tests the included left endpoint
directly. Every interior point with denominator at most N satisfies Legendre's strict bound
at the midpoint, even when the bound at the left endpoint fails.
At scale M, write t = (2 * k + 1).size + (2 * M).size + 1 for the Euclidean step
budget. The search tests at most t + 2 candidates. At scale 2 ^ bits this is at most
k.size + bits + 6. Each convergent at index i takes i + 1 quotients and i rational updates.
The machine evaluates the recurrence from the innermost quotient outwards. It recomputes
the Euclidean pair from the midpoint for each quotient, keeping a unary index and one
reduced rational in the outer loop. Each intermediate reduced numerator and denominator
has at most (i + 1) * ((max (2 * k + 1) (2 * M)).size + 3) bits. The certificate
also charges construction of the candidate list and the denominator and endpoint comparisons.
Main definitions #
Rat.recoverDyadicLogSq: recovery using the ceiling of twice the base-two logarithm.Rat.recoverDyadic: recovery using twice the ceiling of the base-two logarithm.
Main results #
Rat.recoverDyadic_mem_cell: every returned rational satisfies the cell and denominator tests.Rat.recoverDyadic_eq_some: recovery of any promised rational in the cell.Rat.recoverDyadicLogSq_eq_someandRat.recoverDyadicLogSq_mem_cell: correctness forrecoverDyadicLogSq.Rat.recoverDyadic_polyTimeandRat.recoverDyadicLogSq_polyTime: native polynomial-time certificates on binary inputs.
Recover a fraction of denominator at most N from the dyadic cell indexed by k.
For a number in [0, 1), k is the natural represented by the first
2 * Nat.clog 2 N fractional bits, with leading zeros allowed. At a dyadic boundary, use the
expansion ending in zeros. More generally, add the integer part times the cell scale to k.
Return none when no fraction of denominator at most N lies in the cell.
Recover a reduced rational of denominator at most N using Nat.clog 2 (N ^ 2)
fractional bits. The index k uses the terminating-zero and integer-part conventions
of recoverDyadic. Return none if the cell contains no such rational.
The decoder recovers any reduced rational of denominator at most N in the half-open
cell specified by the prefix. Rat.num and Rat.den give its reduced numerator and denominator.
The decoder recovers any reduced rational of denominator at most N in the half-open
cell specified by the prefix. Rat.num and Rat.den give its reduced numerator and denominator.
Recover a reduced rational in polynomial time from the binary denominator bound and cell
index. The machine tests the included endpoint and the same midpoint convergents as
recoverDyadic, returning an optional signed binary numerator and binary denominator.
Polynomial-time recovery at the precision rounded after doubling, from the binary bound
and cell index to an optional reduced rational encoded as in recoverDyadic_polyTime.