Skip to content

scurvyhund/bi-quad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bi-quad — Bi-Quadratic Emirps & Prime Palindromes on 2n²+2n+1

A long-running number theory search (part of the BigFermat project) on the curve

p(n) = 2n² + 2n + 1 = n² + (n+1)² — the sum of two consecutive squares —

for two kinds of rare prime: bi-quadratic emirps and prime palindromes (palindromic primes). Every value on the curve is a sum of two consecutive squares, n² + (n+1)² — the tightest special case of the sum-of-two-squares primes in Fermat's two-square theorem (the primes ≡ 1 mod 4). Hence the name.

That consecutive-squares structure pins every value to one of just six two-digit endings — {01, 13, 21, 41, 61, 81} (and, reversed, six leading patterns {10, 12, 14, 16, 18, 31}). It's the cheap first/last-digit filter that discards ≈ 89% of p/q candidates instantly (~9× speedup) — roughly 19.9 trillion of the ~22.4 trillion candidates through 27 digits — before any primality test — a proof by construction.

The curve and its findings: prime palindromes cluster at small d; the emirp obstruction landscape


The objects of the hunt

  • Bi-quadratic emirp — a prime p = 2n²+2n+1 whose digit-reversal q = rev(p) is also prime and also of the form 2m²+2m+1, with q ≠ p. Both ends prime, both on the same quadratic curve — that is what "bi-quadratic" means: two numbers, one curve. Exactly one is known: 12641 ⟷ 14621 (d=5) — the only one through 27 digits.
  • Prime palindrome on the curve — a prime p = 2n²+2n+1 that reads the same forwards and backwards. Four are known: 5, 181, 313, 3187813.

These two searches turn out to be the same sieve: a palindrome is just the m = n case of the emirp relation, so any obstruction kills both.


Results

12641 ⟷ 14621 is the only bi-quadratic emirp through 27 digits

There is exactly one bi-quadratic emirp in this range — 12641 ⟷ 14621 (d=5; 79²+80² ⟷ 85²+86², both prime). Established by exhaustive hunt.c brute force (every n, GMP-exact, d=5–27), cross-checked against the modular sieve:

d = 5                          : EMIRP — 12641 ⟷ 14621  (both prime, both on curve)   ← the only one
d = 6, 10, 18, 20, 22          : OBSTRUCTION — no curve-reversal survivor at all
d = 17, 19                     : only palindromic survivors → no emirp candidate
d = 7,8,9,11–16,21,23–27       : emirp candidates exist, all composite → no emirp

(An "emirp candidate" is a non-palindrome n with both p and rev(p) on the curve; palindromes — including the prime 3187813 — are a separate object, shown in gold in the figure.) Apart from 12641 ⟷ 14621, every emirp candidate through 27 digits has p and/or q composite. So 12641 ⟷ 14621 is the smallest — and, so far, the only — bi-quadratic emirp. The next one, if any, has ≥ 28 digits.

Prime palindromes: a 27-year conjecture

The only prime palindromes on the curve through 27 digits — confirmed exhaustively — are 5, 181, 313, 3187813, all at ≤ 7 digits. (d ≤ 21 via the modular sieve; d = 8…27 independently re-confirmed by a direct GMP-certified huntpalhunt_gmp, every n, all found = 0.) At d = 27 the emirp brute (hunt.c) independently corroborates this: it flags exactly 3 palindromic values, all composite (verified by quadratic sieve) — so found = 0 stands from a second, unrelated tool. The standing conjecture (Jim, since ~1997):

3187813 is the largest prime palindrome on the curve.

Structural limits (what can't work)

Two roads were rigorously ruled out by measurement (see docs/structural_attacks_2026-06-04.md):

  • No faster search. A meet-in-the-middle attack gives no √-speedup — the digit-reversal of a quadratic entangles the middle digits irreducibly. Search is ~10^(d/2)-bound (brute force reaches ~d=27).
  • No congruence proof. A sweep of 50 base-aligned / 2-power / 5-power moduli found zero obstructions: the real obstructions are non-congruential (sporadic). A non-existence theorem, if any, needs new mathematics.

Heuristic

A coin-flip density argument predicts bi-quadratic emirps are finite (expected ≈ C/d² per length, sum converges → total ≈ 1 across all integers), while prime palindromes may be infinite (≈ C′/d, sum diverges). The single extra primality condition for emirps is what tips the balance — and an expected total of ≈ 1 is consistent with 12641 ⟷ 14621 being the only one that exists.


Tools

All C99 + OpenMP; the GMP ones use arbitrary precision for large p.

file what it does
mod_obstruct.c Modular obstruction sieve — proves whole digit-lengths impossible via first-k/last-k digit feasibility mod 10^k (exact for d ≤ 2k).
hunt.c Exhaustive emirp brute force (GMP) — enumerates every n, tests rev(p) on-curve + both prime. The trustworthy tool for d ≥ 21.
palhunt.c Prime-palindrome hunter (64-bit, ≤ 19 digits).
palhunt_gmp.c Prime-palindrome hunter past the 64-bit wall (uint64 n, __int128 p, GMP-certified; reaches ~d=27).
palfirst.py Palindrome-first verifier — independent cross-check of hunt.c (loops palindromes, tests 2P−1 a perfect square).
generate_graph.py Renders the findings figure (pure Pillow — no matplotlib).
gen_ending_figure.py Renders the palindrome ending-distribution figure (Pillow).

Archived in git history (commit 7f33475): mitm_probe.c, mitm_probeB.c, congru_probe.c — the probes behind the ruled-out structural attacks.


Build & run

Requires gcc, libgmp, OpenMP. The Makefile targets AMD Zen2 (-march=znver2); use -march=native elsewhere.

make                      # or build individually:
gcc hunt.c        -o hunt        -O3 -march=native -std=c99 -Wall -fopenmp -lgmp
gcc palhunt_gmp.c -o palhunt_gmp -O3 -march=native -std=c99 -Wall -fopenmp -lgmp
gcc mod_obstruct.c -o mod_obstruct -O3 -march=native -std=c99 -Wall -fopenmp -lgmp

# emirp brute force, digit-lengths 13..17
./hunt 13 17

# modular sieve: max_d max_k min_k min_d   (e.g. k=10, d=17..21)
./mod_obstruct 21 10 10 17

# prime palindromes on the curve, digit-lengths 21..27
./palhunt_gmp 21 27

# regenerate the figure
python3 generate_graph.py

mod_obstruct checkpoints to mod_obstruct.ckpt and resumes with ./mod_obstruct <max_d> <max_k>.


Documentation

  • docs/PROJECT_OVERVIEW.mdstart here: goal, glossary, the algorithms (pseudocode), bug-history, and the live landscape.
  • docs/palindrome_insights.md — a summation of what we know about palindromes on the curve (÷11 dodge, the 9/√10 Poisson count, the …13 ending signature, the Fermat confluence).
  • docs/structural_attacks_2026-06-04.md — the MITM (meet in the middle) + congruence foray and why neither cracks it.
  • docs/session_2026-06-04_*.md — session records (the ≤22 proof, the cliff fix, the palindrome unification).
  • docs/modular_obstruction_design.md — the sieve's original design notes.

Origins

bi-quad grew out of cvpipe, an earlier pipeline implementation of the same search. The zone-skip breakthrough (62.8M× speedup) was achieved in cvpipe before the project was restructured and renamed. See cvpipe for the original development history.

Related projects

  • cvpipe — the original converse prime pipeline; zone-skip optimization and fast Miller-Rabin search.
  • bigint-mul — arbitrary- precision big integer multiplication in C (__uint128_t and schoolbook).
  • bigdec2hex — arbitrary- precision decimal-to-hexadecimal converter.

Acknowledgements

  • C-Quadratic-Sieve by Michel Léonard — a self-contained, public-domain SIQS integer factorizer. Used here to certify the compositeness of large candidate values (the three d=27 palindromic curve-values were all shown composite this way). Full note: CREDITS.md.

Why "BigFermat"

The hobby…

The hunt began after Simon Singh's Fermat's Enigma (1997) — a book about Fermat's Last Theorem that sent the search into Fermat's other famous result, the two-square theorem: every prime ≡ 1 (mod 4) is a sum of two squares (and no prime ≡ 3 (mod 4) is). The curve 2n²+2n+1 = n² + (n+1)² is the tightest case — a sum of two consecutive squares. Its two rare prizes are prime palindromes (read the same both ways — largest known: 3187813) and bi-quadratic emirps (reverse to a different curve-prime — only known: 12641 ⟷ 14621). The first champion — the palindrome 3187813 — was found on a 386 by bending the x87 FPU's 80-bit registers into a 64-bit integer engine. The project has been chasing that curve ever since.

About

Exhaustive search for prime palindromes & bi-quadratic emirps on the curve 2n^2+2n+1 = n^2+(n+1)^2 (sums of two consecutive squares). GMP + OpenMP; home of a 27-year prime-palindrome conjecture.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors