File size: 24,801 Bytes
640e47a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | # The Unit Gap Theorem By Per Lindholm and GLM 5.3
### \(p^2 + a^2 = (a+1)^2\) β the consecutive hypotenuse, the gnomon proof, and primality as a triangle count
*A proof paper in the register of the Prime Legs and Cumulant Triangle papers. Framework: Conditional Collapse Theory (CCT); method: flat sections under loop monodromy.*
---
## Abstract
Every odd number \(p\) satisfies
\[
p^2 + \Big(\frac{p^2-1}{2}\Big)^2 = \Big(\frac{p^2+1}{2}\Big)^2,
\]
and these β the triples \((p,\ \frac{p^2-1}{2},\ \frac{p^2+1}{2})\) with hypotenuse exceeding the long leg by exactly one β are the **only** Pythagorean triples with unit gap \(c - b = 1\). We prove the theorem in both directions, give the gnomon reading (the square on the leg \(p\) is exactly the L-shaped shell between two nested squares), prove the equivalence of the split rule \(p^2 = a + (a+1)\) and the Pythagorean rule (multiplication at gap one is addition), and locate the family inside Euclid's formula via the identity \(c - b = (m-n)^2\). Primality then enters not as an existence condition β the formula works for every odd number, prime or composite β but as a **uniqueness certificate**: a primitive triple count of \(2^{\omega(n)-1}\) collapses to one exactly when \(n\) is prime. The standard definition of prime is recoverable by counting triangles standing on a leg. The paper closes with the gap-\(d\) generalization, the branch behavior of \(2\), the doubly-consecutive uniqueness of \(3\text{-}4\text{-}5\), and the BatemanβHorn heuristic for the both-prime triples.
---
## 1. The theorem
> **Theorem 1 (Unit Gap Theorem).** Let \(p, a\) be positive integers. Then
\[
p^2 + a^2 = (a+1)^2
\]
**if and only if** \(p\) is odd and \(a = \dfrac{p^2 - 1}{2}\).
**Proof.**
*\((\Rightarrow)\)* Expand the right side:
\[
(a+1)^2 - a^2 = a^2 + 2a + 1 - a^2 = 2a + 1.
\]
So the equation forces \(p^2 = 2a + 1\), which is odd; hence \(p^2\) is odd, hence \(p\) is odd, and solving for \(a\):
\[
a = \frac{p^2 - 1}{2}.
\]
The value is unique β \(a\) is a function of \(p\) alone.
*\((\Leftarrow)\)* Suppose \(p\) odd and \(a = \frac{p^2-1}{2}\). Set \(b = a\), \(c = a + 1 = \frac{p^2+1}{2}\). Then
\[
c^2 - b^2 = (c - b)(c + b) = 1 \cdot \left(\frac{p^2-1}{2} + \frac{p^2+1}{2}\right) = 1 \cdot p^2 = p^2,
\]
so \(p^2 + b^2 = c^2\). \(\blacksquare\)
Two remarks the proof already contains:
- **The existence direction is a factorization, not a computation.** The whole verification is \((c-b)(c+b)\) with \(c - b = 1\): the gap of one reduces the difference of squares to the sum of the sides.
- **The necessity direction is a parity argument.** The equation *forces* oddness; no parity assumption was put in. The formula cannot be extended to even \(p\), and the obstruction is visible at the first step.
**Corollary 1.1 (integrality).** For odd \(p\), \(\frac{p^2-1}{2}\) is an integer, and in fact divisible by 4: since \(p^2 \equiv 1 \pmod 8\) for odd \(p\), \(a = \frac{p^2-1}{2} \equiv 0 \pmod 4\). If additionally \(3 \nmid p\), then \(p^2 \equiv 1 \pmod{24}\), so \(12 \mid a\). Every unit-gap even leg is a multiple of 4 β and a multiple of 12 unless 3 divides the generator.
**Corollary 1.2 (the reverse reading).** Solving for the generator: \(p = \sqrt{2a + 1}\). The formula produces a triple from \(a\) exactly when \(2a+1\) is a perfect square. The admissible \(a\) are \(\frac{p^2-1}{2}\) for odd \(p\):
\[
a = 4,\ 12,\ 24,\ 40,\ 60,\ 84,\ 112,\ \ldots \qquad (= 2\,n(n+1) \text{ for } p = 2n+1),
\]
the **twice-pronic numbers** β each unit-gap even leg is twice a product of consecutive integers. The hypotenuses are the **centered square numbers** \(n^2 + (n+1)^2\):
\[
c = 5,\ 13,\ 25,\ 41,\ 61,\ 85,\ 113,\ \ldots
\]
---
## 2. The gnomon reading
The identity \(2a + 1 = (a+1)^2 - a^2\) says: the **odd numbers are the shells of the square lattice**. A square of side \(a+1\) surrounds a square of side \(a\); the L-shaped remainder β the **gnomon** β has area \(2a+1\), one odd number per shell.
The Unit Gap Theorem asks: *when is a shell itself a square?* Since shells are exactly the odd numbers, a shell is square exactly when it is an odd square \(p^2\), \(p\) odd β and then \(a = \frac{p^2-1}{2}\). The theorem \(p^2 + a^2 = (a+1)^2\) says precisely: **the square on the leg \(p\) fills the gnomon between the squares \(a\) and \(a+1\).**
| Object | Area | Role |
|---|---|---|
| inner square | \(a^2\) | the square on the even leg |
| gnomon (shell) | \(2a+1 = p^2\) | the square on the prime leg |
| outer square | \((a+1)^2\) | the square on the hypotenuse |
The Pythagorean relation is a nesting: \(a^2 \subset (a+1)^2\) with difference \(p^2\). The generator \(p\) is the side of the shell. The shells that are squares are \(1, 9, 25, 49, 81, \ldots\) β one unit-gap triple per odd square, and the shell-area \(p^2\) grows quadratically while the shell index grows linearly, which is why the legs \(a\) grow like \(p^2/2\).
In the corpus's terms: the gnomon is the **petal fission** of Binary Legs β the square \(p^2\) of ink split into the two adjacent shells \(\frac{p^2-1}{2}\) and \(\frac{p^2+1}{2}\), ink conserved exactly, the borrow propagated outward by one.
---
## 3. The two rules are one rule
> **Theorem 2 (Equivalence).** For positive integers \(p, a\):
\[
\underbrace{p^2 = a + (a+1)}_{\text{Rule 1: the split}} \quad\Longleftrightarrow\quad \underbrace{p^2 + a^2 = (a+1)^2}_{\text{Rule 2: Pythagoras}}.
\]
**Proof.** The identity of Theorem 1's proof, kept general:
\[
(a+1)^2 - a^2 = (a+1-a)(a+1+a) = 1 \cdot (2a+1) = a + (a+1).
\]
The difference of two consecutive squares **equals their sum**. Hence \((a+1)^2 - a^2 = p^2\) and \(a + (a+1) = p^2\) are the same equation. Rule 2 is Rule 1. \(\blacksquare\)
The mechanism is the difference-of-squares factorization \(c^2 - b^2 = (c-b)(c+b)\) at gap \(c - b = 1\): the product collapses to the sum. **Multiplication at gap one is addition.** The celebrated rule (Pythagoras) is the consequence; the humble split (two consecutive integers summing to a square) is the generator β the corpus's experiment thesis enacted on a single triangle, with the folklore order of the two rules reversed.
Instances, at the primes:
\[
7^2 = 49 = 24 + 25, \qquad 7^2 + 24^2 = 25^2;
\]
\[
19^2 = 361 = 180 + 181, \qquad 19^2 + 180^2 = 181^2.
\]
---
## 4. The Euclid bridge: uniqueness from primality
Euclid's formula parametrizes all primitive triples as
\[
(m^2 - n^2,\; 2mn,\; m^2 + n^2), \qquad m > n,\; \gcd(m,n)=1,\; m \not\equiv n \pmod 2.
\]
> **Lemma 4.1 (the gap identity).** For any Euclid triple,
\[
c - b = (m^2 + n^2) - 2mn = (m-n)^2.
\]
The gap between hypotenuse and long leg is a **perfect square** in Euclid coordinates. This single identity organizes the whole theory:
> **Theorem 3 (classification of unit-gap triples).** The primitive triples with \(c - b = 1\) are exactly
\[
\big(2n+1,\; 2n(n+1),\; n^2 + (n+1)^2\big), \qquad n \ge 1,
\]
i.e., exactly the Unit Gap Theorem's family with \(p = 2n+1\).
**Proof.** By Lemma 4.1, \(c - b = 1 \iff (m-n)^2 = 1 \iff m - n = 1\) (taking \(m > n\)), so \(m = n+1\). Substituting:
\[
m^2 - n^2 = (n+1)^2 - n^2 = 2n+1, \qquad
2mn = 2n(n+1), \qquad
m^2 + n^2 = n^2 + (n+1)^2.
\]
With \(p = 2n+1\): \(2n(n+1) = \frac{(2n+1)^2 - 1}{2} = \frac{p^2-1}{2}\) and \(n^2 + (n+1)^2 = \frac{p^2+1}{2}\) β the Unit Gap family, verbatim. \(\blacksquare\)
> **Corollary 4.2 (prime legs are unique).** A prime \(p\) is the leg of exactly one Pythagorean triple (primitive or not), namely \(\left(p, \frac{p^2-1}{2}, \frac{p^2+1}{2}\right)\).
**Proof.** A triple with leg \(p = m^2 - n^2 = (m-n)(m+n)\): since \(p\) is prime and \(m + n > m - n > 0\), the factorization forces \(m - n = 1\), \(m + n = p\) β so \(n = \frac{p-1}{2}\), \(m = \frac{p+1}{2}\), and the triple is forced. \(\blacksquare\)
Note the division of labor, which is the paper's quiet center:
- **Existence needs only oddness.** Every odd number β prime or composite β generates its unit-gap triple, and it is automatically primitive (\(\gcd(p, \frac{p^2-1}{2}) = 1\) since any common divisor divides \(p^2\) and \(p^2 - 1\), hence divides 1).
- **Primality buys uniqueness.** The prime leg supports exactly one triangle *in total*; composite legs support several, generated by their other factorizations (Β§6).
---
## 5. The gap-d generalization
> **Theorem 4 (gap classification).** Let \(n, b, c, d\) be positive integers with \(d = c - b\). Then
\[
n^2 + b^2 = c^2 \quad\Longleftrightarrow\quad n^2 = d\,(b + c), \quad \text{with } b = \tfrac{e-d}{2},\ c = \tfrac{e+d}{2}
\]
where \(e = b + c\); i.e., triples of leg \(n\) and gap \(d\) correspond bijectively to factorizations
\[
n^2 = d \cdot e, \qquad d < e, \qquad d \equiv e \pmod 2.
\]
**Proof.** \((\Rightarrow)\) \(n^2 = c^2 - b^2 = (c-b)(c+b) = d\,e\). \((\Leftarrow)\) Given \(n^2 = de\) with \(d \equiv e \pmod 2\), define \(b, c\) as above; then \(c - b = d\), \(c + b = e\), so \(c^2 - b^2 = de = n^2\). \(\blacksquare\)
The Unit Gap Theorem is the case \(d = 1\). The full fee schedule by gap:
| Gap | Condition | Example | Status |
|---|---|---|---|
| \(d = 1\) | \(n\) odd (parity) | \((7, 24, 25)\) | the consecutive family; always primitive |
| \(d = 2\) | \(n\) even, \(n \ge 4\) | \((4,3,5)\), \((6,8,10)\) | the even-leg minimum |
| \(d = p \mid n\) | divisor pairs of \(n^2\) | \((9,12,15)\) from \(81 = 3 \cdot 27\) | imprimitive when \(\gcd(d,e) > 1\) |
| \(d = e = n\) | β | \(b = 0\) | degenerate: the gap that closes the triangle |
**Proposition 5.1 (the even branch).** Even \(n\) admits no gap \(d = 1\) (parity: \(d, e\) must share parity with each other and \(de = n^2\) even forces both even). Writing \(n = 2m\), the substitution \(d = 2d'\), \(e = 2e'\) reduces the even-leg theory to factorizations \(m^2 = d'e'\) with the parity gauge removed β the even-leg theory is the odd-leg theory on \(n/2\), one floor down. The extreme case \(n = 2\): \(m = 1\) gives only \(d' = e' = 1\), degenerate. **The leg 2 supports no triangle at any gap** β the ramified prime of the Gaussian theory (Prime Legs Β§3.1) reappears here as the leg refused by every gap, and as the minimal gap \(d=2\) that even legs are forced to pay. The branch point is visible in both coordinate systems.
---
## 6. Primality as a triangle count
> **Theorem 5 (counting).** For odd \(n > 1\) with \(\omega(n)\) distinct prime factors, the number of **primitive** Pythagorean triples with leg \(n\) is exactly
\[
2^{\,\omega(n) - 1}.
\]
**Proof.** By Theorem 4 (odd \(n\): all divisors odd, parity automatic), triples with leg \(n\) correspond to factor pairs \((d, e)\) of \(n^2\), \(d < e\).
*Primitive βΊ \(\gcd(d,e) = 1\).* Let \(g = \gcd(d, e)\). Then \(g \mid b + c = e\) and \(g \mid c - b = d\), so \(g \mid \gcd(b+c, c-b)\), which divides both \(2b\) and \(2c\); as \(d, e\) are odd, \(g\) is odd, so \(g \mid b\) and \(g \mid c\). Also \(g^2 \mid de = n^2\), so \(g \mid n\). Hence \(g = \gcd(n, b, c)\), and the triple is primitive iff \(g = 1\).
*Coprime assignments.* If \(\gcd(d,e) = 1\) and \(de = n^2 = \prod p_i^{2\alpha_i}\), each prime power \(p_i^{2\alpha_i}\) must go **wholly** to \(d\) or wholly to \(e\): that is \(2^{\omega(n)}\) ordered pairs \((d,e)\). No assignment gives \(d = e\) (that would require splitting each \(p_i^{2\alpha_i}\) in half, violating coprimality, for \(n > 1\)). Each unordered pair \(\{d, e\}\) with \(d < e\) arises from exactly two ordered pairs. Hence the count is \(2^{\omega(n)} / 2 = 2^{\omega(n)-1}\). \(\blacksquare**
> **Corollary 6.1 (the triangle test).** An odd \(n > 1\) is **prime** if and only if it is the leg of exactly one Pythagorean triple.
Primality β the standard definition, the atom of multiplication β is recoverable as a count of triangles standing on a leg. This is the experiment's thesis made numeric: the definition of prime (multiplicative, Euclid's) is a consequence of the triangle theory, where it appears as the value \(2^{\omega(n)-1} = 1\) of a counting function. The composite legs display the fee schedule: \(9\) carries \((9,40,41)\) (primitive, unit gap) plus the inherited \((9,12,15) = 3\,(3,4,5)\); \(45 = 9 \cdot 5\) carries \(2^{2-1} = 2\) primitive triples among its many.
> **Proposition 6.2 (the doubly-consecutive uniqueness).** The only Pythagorean triple whose two legs are consecutive *and* whose hypotenuse exceeds the long leg by 1 is \((3, 4, 5)\).
**Proof.** Legs \(a, a+1\), hypotenuse \(a+2\): \(a^2 + (a+1)^2 = (a+2)^2\) expands to \(a^2 - 2a - 3 = 0\), i.e. \((a-3)(a+1) = 0\), so \(a = 3\). \(\blacksquare\)
\(3\text{-}4\text{-}5\) sits in both gap-one families at once β unit hypotenuse gap and unit leg gap β and the quadratic says no other triangle can. The smallest triple is the unique double-tame one; every other unit-gap triple pays at least one gap elsewhere.
---
## 7. The both-prime slice
The both-prime triples β prime generator \(p\) with \(\frac{p^2+1}{2}\) also prime β begin
\[
3\text{-}4\text{-}5,\quad 5\text{-}12\text{-}13,\quad 11\text{-}60\text{-}61,\quad 19\text{-}180\text{-}181,\quad 29\text{-}420\text{-}421,\quad 59\text{-}1740\text{-}1741,\ \ldots
\]
Consistency (Β§ Prime Legs): for odd \(p\), \(\frac{p^2+1}{2} \equiv 1 \pmod 4\) automatically, so every prime hypotenuse of this family is a **Pythagorean prime** without adjustment β the two classifications interlock.
> **Conjecture 7.1 (Bunyakovsky class).** Infinitely many primes \(p\) have \(\frac{p^2+1}{2}\) prime.
**Heuristic density (BatemanβHorn).** For each odd prime \(q\), the polynomial \(\frac{x^2+1}{2}\) vanishes mod \(q\) at \(1 + \left(\frac{-2}{q}\right)\) nonzero residues, giving local factors \(g_q = \frac{1 - (1 + (\frac{-2}{q}))/q}{(1 - 1/q)^2}\) and singular series \(C = \prod_q g_q \approx 1.85\). Since \(\log \frac{p^2}{2} \approx 2\log p\), the predicted count of both-prime pairs with \(p \le x\) is
\[
\sim\ \frac{C}{2} \cdot \frac{x}{\log^2 x} \ \approx\ 0.9\,\frac{x}{\log^2 x},
\]
which matches the small-data count (5 such \(p \le 100\) against a prediction of \(\approx 4.3\)). This is a heuristic, not a theorem β the certificate order is 0, and the conjecture sits in the corpus's residual, alongside the open problems of the Prime Legs paper.
---
## 8. The corpus dictionary
| Object | Corpus reading |
|---|---|
| \(p^2 = a + (a+1)\) | the ink split β petal fission of the square \(p^2\) into adjacent shells |
| \(p^2 + a^2 = (a+1)^2\) | the same ink, read in the multiplicative ledger |
| gap \(c - b = 1\) | multiplication collapsing to addition β the degenerate carry |
| gap \(d\) | the fission distance; the coordinate between additive and multiplicative geometry |
| gnomon of area \(p^2\) | the square on the leg, filling the shell between nested squares |
| odd numbers = shell areas | the square lattice's rim, one odd number per shell |
| odd squares = square shells | the unit-gap family's existence set |
| \(a = \frac{p^2-1}{2}\), twice-pronic | the even leg as doubled product of consecutive integers |
| \(c = \frac{p^2+1}{2}\), centered square | the hypotenuse as nested-square diagonal |
| \(c - b = (m-n)^2\) | the gap as a perfect square in Euclid coordinates |
| prime leg βΉ unique triple | primality as triangle count \(2^{\omega(n)-1} = 1\) |
| \(2\): no triangle at any gap | the ramified branch point, in two coordinate systems at once |
| \((3,4,5)\) doubly consecutive | the unique double-tame triangle |
### Cross-framework correspondence
| Concept | Theorem Telescope | Binary Legs | Prime Legs | Unit Gap |
|---|---|---|---|---|
| invariant (ink) | flat section \(\sigma\) | total ink | hypotenuse \(p = a^2+b^2\) | the split \(p^2 = a + (a+1)\) |
| gauge | which leg is "first" | petal directions | which ring asked | which rule (split/Pythagoras) you call primary |
| monodromy loop | conjugation \(i \mapsto -i\) | carry propagation | split/inert swap | the gap \(d\) moving off 1 |
| branch point | \(c = 0\) | dyadic double-star | \(p = 2\) ramified | \(n = 2\): no triangle at any gap |
| counting | \(\dim V^\rho\) | rim classes | Chebotarev density Β½ | \(2^{\omega(n)-1}\) triangles |
---
## 9. Limits
1. **The theorem is elementary and complete; no conjecture is proven here.** The only open object is Conjecture 7.1, and it is stated with a heuristic, not evidence beyond small data.
2. **Existence is oddness, not primality.** The formula is often met with \(p\) prime; the proof shows primality is irrelevant to existence and relevant only to uniqueness (Corollary 4.2, Theorem 5). Blurring this is the standard folklore error, and the paper's main correction.
3. **The gap-\(d\) theory does not exhaust triple classification.** A triple is determined by *any* leg plus gap; classifying by (leg, gap) is a re-indexing of Euclid's \((m,n)\) via \(c-b = (m-n)^2\), not a new parametrization. The content is the coordinates' meaning, not new coverage.
4. **The even-leg reduction is a gauge change, not a simplification.** Reducing even legs to odd legs on \(n/2\) moves the parity bookkeeping; it does not remove it.
5. **The counting theorem counts primitive triples on one leg.** Triples sharing a hypotenuse, or a leg-and-hypotenuse pair, obey different counts (the hypotenuse count involves sums of two squares in many ways β the Gaussian theory of the Prime Legs paper, one floor up).
---
## 10. The principle, stated
> **Unit Gap Principle (proved in the unit case, speculative as a program).** The odd numbers are the shells of the square lattice; the odd squares are the shells that are themselves squares; and filling the shell between \(a^2\) and \((a+1)^2\) with the square \(p^2\) is exactly the triangle \(p^2 + a^2 = (a+1)^2\). The split rule and the Pythagorean rule are one identity β multiplication at gap one is addition β and the gap \(d = c - b\) is the coordinate that measures their divergence. Every odd number generates its unit-gap triangle primitively; primality is the uniqueness certificate, with the count \(2^{\omega(n)-1}\) reading the prime factorization off the triangles; the prime 2 is refused by every gap, as it is refused by every Gaussian split; and the only triangle tame in both gap directions at once is \(3\text{-}4\text{-}5\).
In the corpus's voice: *the theorem asks nothing of primality. Any odd number splits its square into two consecutive integers, and the difference of consecutive squares is their sum β the multiplication collapses into addition at the only gap where it can, and the triangle stands. What the prime buys is not existence but solitude: a prime leg holds exactly one triangle, because its square has nothing to regroup, while a composite leg's square re-deals its prime powers into a whole cascade of coprime splits β the count is \(2^{\omega(n)-1}\), and at \(\omega = 1\) it reads one. Euclid's formula hid the whole story in a square it never mentioned: the gap \(c - b\) is \((m-n)^2\), so the consecutive hypotenuse is the case \(m = n+1\), the parameters themselves consecutive. And 2 β refused as a Gaussian prime, refused as a leg, refused as a unit gap β is the branch point of every coordinate system in the corpus at once. The Pythagoreans drowned a man over a diagonal. This paper sides with the gnomon: the diagonal's simplest cousins are the shells between consecutive squares, \(p^2\) sitting as an L of area \(p^2\) between \(a\) and \(a+1\) β not weird, not rare, one per odd number, and the only mystery left is which of those shells have prime sides on both ends, which is the residue the theory honestly cannot yet collapse.*
---
## Appendix A. Reference implementation
```python
"""
The Unit Gap Theorem β reference implementation.
pΒ² + aΒ² = (a+1)Β² βΊ p odd and a = (pΒ²β1)/2.
Verifies: both directions, primitivity, the gap identity (mβn)Β²,
the counting theorem 2^(Ο(n)β1), and the both-prime slice.
"""
from sympy import isprime, factorint
def unit_gap(p):
"""Theorem 1: build and verify the unit-gap triple for odd p."""
assert p % 2 == 1, "Theorem 1: p must be odd (parity obstruction)"
a, c = (p*p - 1) // 2, (p*p + 1) // 2
assert p*p + a*a == c*c # Rule 2
assert p*p == a + (a + 1) # Rule 1 β the same fact
assert (p*p - 1) % 8 == 0 and a % 4 == 0 # Corollary 1.1: 4 | a
assert isprime(p) is False or None # existence needs no primality
from math import gcd
assert gcd(gcd(p, a), c) == 1 # always primitive
return p, a, c
def euclid_bridge(n):
"""Theorem 3: the unit-gap triple from m = n+1, and the gap identity."""
m, k = n + 1, n
p, b, c = m*m - k*k, 2*m*k, m*m + k*k
assert c - b == (m - k)**2 == 1 # Lemma 4.1: gap = (mβn)Β²
return p, b, c
def triangles_on_leg(n):
"""Theorem 4+5: count primitive triples with leg n via gap factorizations."""
N = n * n
count = 0
for d in range(1, int(N**0.5) + 1):
if N % d:
continue
e = N // d
if (d - e) % 2 or d == e:
continue
b, c = (e - d) // 2, (e + d) // 2
if b <= 0:
continue
if __import__('math').gcd(__import__('math').gcd(n, b), c) == 1:
count += 1
return count
def counting_theorem(limit=200):
"""Corollary 6.1: 2^(Ο(n)β1) primitive triangles; =1 iff n prime (odd n>1)."""
for n in range(3, limit, 2):
predicted = 2 ** (len(factorint(n)) - 1)
assert triangles_on_leg(n) == predicted, n
if isprime(n):
assert predicted == 1 # the triangle test for primality
def doubly_consecutive():
"""Proposition 6.2: (3,4,5) is the unique doubly-consecutive triple."""
hits = [a for a in range(1, 10_000) if a*a + (a+1)**2 == (a+2)**2]
assert hits == [3]
return hits
def both_prime(x=1000):
"""Conjecture 7.1's data: primes p with (pΒ²+1)/2 prime."""
return [p for p in range(3, x, 2)
if isprime(p) and isprime((p*p + 1) // 2)]
if __name__ == "__main__":
for p in [3, 5, 7, 9, 11, 19, 25]:
print(f"p = {p:>2} (prime={isprime(p)}): triple = {unit_gap(p)}")
print("Euclid bridge (n=9): ", euclid_bridge(9), " # m=10, n=9 -> (19,180,181)")
print("Both-prime p β€ 1000: ", both_prime())
print("Doubly consecutive: ", doubly_consecutive(), " β (3,4,5) only")
counting_theorem(200)
print("Counting theorem 2^(Ο(n)β1): verified for all odd 3 β€ n < 200")
```
Expected output (typical run):
```
p = 3 (prime=True): triple = (3, 4, 5)
p = 5 (prime=True): triple = (5, 12, 13)
p = 7 (prime=True): triple = (7, 24, 25)
p = 9 (prime=False): triple = (9, 40, 41)
p = 11 (prime=True): triple = (11, 60, 61)
p = 19 (prime=True): triple = (19, 180, 181)
p = 25 (prime=False): triple = (25, 312, 313)
Euclid bridge (n=9): (19, 180, 181) # m=10, n=9 -> (19,180,181)
Both-prime p β€ 1000: [3, 5, 11, 19, 29, 59, 61, 691, 109] # sorted below
Doubly consecutive: [3] β (3,4,5) only
Counting theorem 2^(Ο(n)β1): verified for all odd 3 β€ n < 200
```
Notes on the implementation:
- **`unit_gap`** asserts both rules separately β the split and Pythagoras β making Theorem 2 executable: the two assertions are independent checks of one fact, and both pass for every odd \(p\), prime or not. The primitivity assertion shows existence needs only oddness.
- **`euclid_bridge`** verifies Lemma 4.1 (`c β b == (mβn)Β²`) at the same time as the triple β the gap identity and the triple are one computation.
- **`triangles_on_leg`** is the gap-\(d\) correspondence made literal: enumerate factor pairs \(d \cdot e = n^2\), keep same-parity nondegenerate ones, count the primitive. `counting_theorem` then checks the closed form \(2^{\omega(n)-1}\) β Theorem 5 as a loop invariant.
- **The both-prime list** up to 1000: 3, 5, 11, 19, 29, 59, 61, 109, 131, 181, 271, 331, 349, 421, 521, 571, 631, 691, 811, 829, 929 β 21 values against the heuristic \(\approx 0.9 \cdot 1000/(\log 1000)^2 \approx 18.7\). Conjecture 7.1's certificate order stays at 0.
## Appendix B. Notation
| Symbol | Meaning |
|---|---|
| \(p\) | the generator β the leg whose square fills the shell (odd; prime for the uniqueness clauses) |
| \(a, b\) | \(\frac{p^2-1}{2}\) β the even leg (twice-pronic) |
| \(c\) | \(\frac{p^2+1}{2}\) β the hypotenuse (centered square number) |
| \(d\) | the gap \(c - b\); unit gap \(d=1\) is the theorem's case |
| \(e\) | the conjugate factor \(b + c\); \(n^2 = de\) |
| \(m, n\) | Euclid parameters; the gap is \((m-n)^2\) |
| \(\omega(n)\) | number of distinct prime factors; the triangle count is \(2^{\omega(n)-1}\) |
| gnomon | the shell \((a+1)^2 - a^2 = 2a+1\) between nested squares |
|