Pythagorean Modular Prime Sieve – C++ Reference Implementation

Read full text
Authors: Roberto Amato
Cited by: 0

Abstract

C++ reference implementation of the Pythagorean modular prime sieve operating on the inradius index r, with optional OpenMP parallelism and batch or pure streaming APIs. The software is designed for memory-efficient prime generation and direct access to distant prime ranges. This repository provides an industrial-grade C++ implementation of the **Pythagorean modular prime sieve**, a novel prime generation method introduced by Roberto Amato. The algorithm is based on a modular reformulation of divisibility arising from Pythagorean geometry. Odd integers are parametrized as $$x = 2r + 1,$$ and composite values are excluded through a single congruence condition on the index $r$. For any odd divisor $d \geq 3$, one has $$x \text{ divisible by } d\;\Longleftrightarrow\;r \equiv \frac{d - 1}{2} \pmod{d}.$$ Each odd divisor eliminates exactly one residue class modulo $d$, yielding a sparse modular sieve with reduced memory requirements. This formulation naturally supports segmentation, parallel execution, and streaming prime generation, and enables direct access to primes located far from the origin without storing all preceding values. The original C++ Core backend tests each candidate in a finite odd window against the relevant base divisors using the Pythagorean modular rule. The repository now includes a validated native C++ bit-packed r-segment backend. It represents finite odd-window candidates by their r indices and uses one bit per candidate in the selected window. The existing Core backend tests candidates individually against base divisors. As start_x grows, the number of relevant base divisors grows, and the cost per candidate increases. The native C++ r_bitpacked backend instead marks the forbidden residue classes inside the window directly. This makes it especially effective for distant finite windows such as those starting near 10^12 and 10^15. Further public information is available at https://www.tetraso.com/.

Fields of Study & Subjects

Analytic Number Theory Research Cryptography and Residue Arithmetic Mathematical and Computational Methods

Publication details

Journal / source
Zenodo (CERN European Organization for Nuclear Research)
Publication date
27 January 2026