Documentation

CslibFrontier.Algorithms.WordRAM.ThreeSum.ChanHe.Parameters

Native parameters for Chan–He preprocessing #

Original native programs and proofs. The parameter meanings are the existing finite mathematical Chan–He definitions, with magnitude bound 2U after the distinct-position frontend. All loops and arithmetic are instructions; the program is fixed for each exponent κ.

Main definitions #

Main results #

References #

A bound covering arithmetic, unsuccessful loop tests, and all output words.

@[reducible, inline]

Unsigned input length.

@[reducible, inline]

Original magnitude bound U.

@[reducible, inline]

Label bits for magnitude bound 2U.

@[reducible, inline]

Recursion height.

@[reducible, inline]

Recursion fuel.

@[reducible, inline]

Number of desired primes.

@[reducible, inline]

Upper bound on candidate primes.

@[reducible, inline]

Common packed convolution length, 8m².

@[reducible, inline]

Magnitude of the padding for the doubled frontend bound, 4U+1.

@[reducible, inline]

Constant one.

@[reducible, inline]

Constant two.

@[reducible, inline]

Constant three.

@[reducible, inline]

Constant four.

@[reducible, inline]

Constant five.

@[reducible, inline]

Constant eight.

@[reducible, inline]

Input length plus two.

@[reducible, inline]

Consumed logarithm argument.

@[reducible, inline]

Floor logarithm of input length.

@[reducible, inline]

Integer square root of input length.

@[reducible, inline]

Number of desired primes plus one.

@[reducible, inline]

Arithmetic scratch.

@[reducible, inline]

Successor square-root counter.

@[reducible, inline]

Square of that counter.

@[reducible, inline]

Square-root test bound.

Exact mathematical outputs; every output is an ordinary unsigned word.

Unroll only the compile-time fixed exponent κ, never the input length or word width. Unlike WordRAM.Power.program, which loops over a runtime exponent register using counter and constant-one scratch registers, power κ emits κ + 1 straight-line instructions over magnitude and base alone and requires no Fits w (κ + 1) budget premise at empty input (n = 0).

Register selection for a floor/ceiling logarithm with output dst.

Register selection for successive squares.

Fixed 24-register native code for each fixed polynomial magnitude exponent.

An explicit charged bound, including all header reads, copies and setup. Halt adds one.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Parameters.exec {w : ℕ} (κ : ℕ) (x : WordRAM.Data 24) (hfit : WordRAM.Fits w (Math.budget (x.mem 0) ((x.mem 0 + 2) ^ κ))) :
∃ (y : WordRAM.Data 24), WordRAM.ExecWithin w (program κ) x y (time κ (x.mem 0) ((x.mem 0 + 2) ^ κ)) ∧ Output (x.mem 0) ((x.mem 0 + 2) ^ κ) y ∧ y.mem = x.mem

Read the native unsigned header and compute all parameters, preserving every memory cell. This local theorem is discharged from a logarithmic width in runs_input.

A polynomial scale for bounding every parameter intermediate.

A coarse polynomial bound; it also covers final unsuccessful root/log iterations.

A single polynomial bound, with exponent affine in the fixed magnitude exponent.

Positive logarithmic word-width threshold for the complete parameter computation.

The width requirement is satisfiable even at empty input and exponent zero.

Every local fit premise follows from the positive logarithmic width.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Parameters.inputFits {κ w : ℕ} (input : List ℤ) (hw : width κ input.length ≤ w) (hvalues : ∀ z ∈ input, |z| ≤ ↑((input.length + 2) ^ κ)) :

Signed-encoded inputs and the unsigned length header fit at the same width.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Parameters.time_bound (κ n : ℕ) :
time κ n ((n + 2) ^ κ) ≤ 5 * n.sqrt + (400 * κ + 3000) * Nat.clog 2 (n + 2)

Explicit Oκ(√n + log(n+2)) instruction bound, valid also at n = 0,1,2.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Parameters.runs_input {κ w : ℕ} (input : List ℤ) (hw : width κ input.length ≤ w) (hvalues : ∀ z ∈ input, |z| ≤ ↑((input.length + 2) ^ κ)) :
∃ (y : WordRAM.Data 24), ∃ t ≤ 5 * input.length.sqrt + (400 * κ + 3000) * Nat.clog 2 (input.length + 2), WordRAM.Runs w ((program κ).program packedLen) (WordRAM.State.init (List.map WordRAM.Signed.encode input)) { pc := (program κ).size, data := y } t ∧ Output input.length ((input.length + 2) ^ κ) y ∧ y.mem = (WordRAM.Data.init (List.map WordRAM.Signed.encode input)).mem ∧ WordRAM.Data.Bounded w y

Native run from actual signed input initialization. No parameters or arithmetic routines are supplied as advice. The returned state identifies all outputs and keeps all input memory. The flat program has 24 registers and depends only on κ; halting adds one instruction.

The number of native instructions in the finite structured code is affine in κ.

The code is the same at every word width.

A word at the canonical width has polynomial magnitude.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Parameters.intermediates_polynomial {κ : ℕ} (input : List ℤ) (hvalues : ∀ z ∈ input, |z| ≤ ↑((input.length + 2) ^ κ)) {s : WordRAM.State 24} {t : ℕ} (hr : WordRAM.Runs (width κ input.length) ((program κ).program packedLen) (WordRAM.State.init (List.map WordRAM.Signed.encode input)) s t) :
(∀ (i : Fin 24), s.data.regs i < (input.length + 2) ^ (40 * κ + 242)) ∧ ∀ (a : ℕ), s.data.mem a < (input.length + 2) ^ (40 * κ + 242)

Canonical-width executions use only polynomially bounded integers, including memory addresses, loop counters, and final unsuccessful tests.