English

Range Algebra for Safe Array Splits

Programming Languages 2025-10-22 v7

Abstract

We present a language-agnostic range algebra that derives correct index intervals for splitting arrays and implementing binary search, eliminating off-by-one and empty-range bugs. From two primitives -- n/2\lfloor n/2\rfloor and n/2=(n+1)/2\lceil n/2\rceil = \lfloor (n + 1)/2\rfloor -- we obtain four canonical splits (Natural, Left+, Right+, Center-cut) with proofs of coverage and balance for all n0n \ge 0 and any base index bZb \in \mathbb{Z}. We record invariants (normalization to left-closed/right-open intervals [u,w)[u, w) with len =wu= w - u), document cross-language division quirks, and give drop-in code patterns and property tests. The result is a small, memorable spec that can be copied verbatim into C/C++/Java/C\#/Go/Rust/Swift/JS/Python.

Cite

@article{arxiv.1402.4843,
  title  = {Range Algebra for Safe Array Splits},
  author = {Aleksandar Perisic},
  journal= {arXiv preprint arXiv:1402.4843},
  year   = {2025}
}

Comments

After I compressed the previous, much longer version, this one became an array of tautologies, which is difficult to justify as an article in any sense. The value is no different from a Boolean algebra, which is nonsensical to restate these days. It was even difficult to actually write in LaTeX without repeating the same symbols. It is not working as an article

R2 v1 2026-06-22T03:12:00.930Z