Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

BSP block

Proved
DetANN.HPIM.build_block

by milia · Nov 17, 2026 · Mathlib 0df444a (Lean v4.33.1)

approximate-nearest-neighborcomputational-geometrydata-structures

There are a block blk\mathrm{blk}blk of fixed length LLL (definition DetANN_HPIMPreBlocks) and a constant CCC such that the following holds in every host program that embeds blk(o)\mathrm{blk}(o)blk(o) at ooo.

Assume:

  • m,n≥1m,n\ge1m,n≥1, and the local points P0,…,Pn−1∈RmP_0,\dots,P_{n-1}\in\mathbb R^mP0​,…,Pn−1​∈Rm are stored (LocalPts);
  • real registers 11,1211,1211,12 hold a radius rrr and a factor ccc;
  • a box [lo,hi][lo,hi][lo,hi] is stored at the real address in pointer 171717, which is ≥0\ge0≥0;
  • the scratch tops Z,ZRZ,Z_RZ,ZR​ (pointers 13,1413,1413,14) are ≤0\le0≤0;
  • the recursion of build (definition DetANN_HPIMBuild) does not starve with fuel fff.

Then the run reaches pc=o+Lpc=o+Lpc=o+L without halting, and:

  • it stores the BSP T=build(P,r,c,f,lo,hi)T=\mathrm{build}(P,r,c,f,lo,hi)T=build(P,r,c,f,lo,hi) in scratch (BSPAt), with its root in pointer 171717;
  • the new tops Z′,ZR′Z',Z_R'Z′,ZR′​ lie below the stored tree and at most C B (m+1)C\,B\,(m+1)CB(m+1) below the old tops, where B=∣paths(T)∣+1B=|\mathrm{paths}(T)|+1B=∣paths(T)∣+1;
  • the host registers <40<40<40 other than pointers 13,14,1713,14,1713,14,17 are unchanged;
  • it writes only scratch cells in those windows;
  • its work is at most C B2(n+1)(m+1)2C\,B^2(n+1)(m+1)^2CB2(n+1)(m+1)2.
Preamble
import Mathlib
import Definitions.Def_DetANN_HPIMPreBlocks
import Definitions.Def_DetANN_HPIMLayout
Formal statement
namespace DetANN.HPIM

open PNormReg PNormRegLib

/-- **BSP block.** On `n` local points, a radius `r` and a factor `c` (real registers `11`, `12`), and
a box `[lo, hi]` stored at real address `p17 ≥ 0`, when `build` does not starve with fuel `f`, it
stores `build pts r c f lo hi` in scratch and returns its root in pointer `17`. The new scratch tops
`Z'`, `ZR'` (pointers `13`, `14`) lie below the stored tree. With `B = paths.card + 1`, it writes only
scratch cells within `C B (m+1)` below the old tops, and its work is at most
`C B² (n+1) (m+1)²`. -/
theorem build_block :
    ∃ blk : ℕ → Program, ∃ L C : ℕ, IsBlock blk L ∧
      ∀ (off : ℕ) (Q : Program), Embeds Q (blk off) off →
      ∀ (m n f : ℕ) (pts : Fin n → Fin m → ℝ) (r c : ℝ) (lo hi : Fin m → ℝ) (s : State),
        1 ≤ m → 1 ≤ n → s.core.pc = off → s.halted = false → LocalPts s pts →
        s.core.regs 11 = r → s.core.regs 12 = c → 0 ≤ s.core.ptrs 17 →
        (∀ j : Fin m, s.core.mem (s.core.ptrs 17 + j) = lo j) →
        (∀ j : Fin m, s.core.mem (s.core.ptrs 17 + m + j) = hi j) →
        s.core.ptrs 13 ≤ 0 → s.core.ptrs 14 ≤ 0 → ¬ Starves pts r c f lo hi →
        ∃ t, (run Q s detTape t).core.pc = off + L ∧ (run Q s detTape t).halted = false ∧
          BSPAt m (run Q s detTape t) ((run Q s detTape t).core.ptrs 13) (s.core.ptrs 13)
            ((run Q s detTape t).core.ptrs 14) (s.core.ptrs 14) ((run Q s detTape t).core.ptrs 17)
            (build pts r c f lo hi) ∧
          KeepsLow s (run Q s detTape t) [13, 14, 17] [] ∧
          s.core.ptrs 13 - C * ((build pts r c f lo hi).paths.card + 1) * (m + 1) ≤
            (run Q s detTape t).core.ptrs 13 ∧
          s.core.ptrs 14 - C * ((build pts r c f lo hi).paths.card + 1) * (m + 1) ≤
            (run Q s detTape t).core.ptrs 14 ∧
          WritesOnly Q s t (fun w =>
            (if w.1 then s.core.ptrs 14 else s.core.ptrs 13) -
                C * ((build pts r c f lo hi).paths.card + 1) * (m + 1) ≤ w.2 ∧
              w.2 < (if w.1 then s.core.ptrs 14 else s.core.ptrs 13)) ∧
          (run Q s detTape t).work ≤ s.work +
            C * ((build pts r c f lo hi).paths.card + 1) ^ 2 * (n + 1) * (m + 1) ^ 2 := by sorry

end DetANN.HPIM
Source
Original, written for the mission 'Deterministic Approximate Nearest Neighbors in High Dimensions' as part of a floor-free proof of DetANN.lemma_3_3 (Feng, Indyk, STOC 2027 submission, Lemma 3.3, p.7): the preprocessing program of DetANN.HPIM.hpim_preprocessing is assembled from these blocks. The machine is PNormReg (definition PNormReg_Machine) with the conventions of DetANN_DataStructure.

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me