# E124: Klauber triangle structure **size 101: 10,201 numbers and 1,252 primes** ```{figure} ../_static/experiments/e124_hero_101.png :width: 80% :alt: Klauber triangle preview (size 101) ``` **size 201: 40,401 numbers and 4,236 primes** ```{figure} ../_static/experiments/e124_hero_201.png :width: 80% :alt: Klauber triangle preview (size 201) ``` **size 301: 90,601 numbers and 8,769 primes** ```{figure} ../_static/experiments/e124_hero_301.png :width: 80% :alt: Klauber triangle preview (size 301) ``` **size 401: 160,801 numbers and 14,752 primes** ```{figure} ../_static/experiments/e124_hero_401.png :width: 80% :alt: Klauber triangle preview (size 401) ``` **size 999: 998,001 numbers and 78,359 primes** ```{figure} ../_static/experiments/e124_hero_999.png :width: 80% :alt: Klauber triangle preview (size 999) ``` *Prime counts shown are $\pi(\text{size}^2)$, i.e., the number of primes $\le \text{size}^2$.* **Tags:** `number-theory`, `quantitative-exploration`, `visualization` See: {doc}`../tags`. ## Highlights - A triangular “prime map” where row $m$ contains the integers from $(m-1)^2+1$ to $m^2$. - Parameterizable run: vary `--size` from the command line (default: `301`). - Writes reproducible artifacts (`params.json`, `report.md`, and figures) into `out/e124/`. ## Goal Render the **Klauber triangle** (a square-number-based triangular arrangement) and highlight primes to reveal linear “streaks” and other geometric structures, then compare how that structure changes as `size` increases. ## Background (quick refresher) ### What is the Klauber triangle? The **Klauber triangle** arranges the natural numbers into rows indexed by $m=1,2,3,\dots$ such that row $m$ contains the consecutive integers $$(m-1)^2+1,\ (m-1)^2+2,\dots,\ m^2.$$ Each row has $2m-1$ entries, and the triangle up to row `size` contains the integers $1,\dots,\text{size}^2$. When primes are highlighted, surprisingly strong visual streaks can appear. See {cite}`Hill2016KlauberTriangle`. ### Optional background pages - {doc}`../background/prime-numbers` - {doc}`../background/quadratic-polynomials` - {doc}`../background/eulers-prime-generating-polynomial` ## Research question Which prime-rich streaks are visible in the Klauber triangle for a given `size`, and how do those structures change as `size` increases? ## Why this qualifies as a mathematical experiment - **Finite procedure:** build a finite triangle window containing integers $1,\dots,\text{size}^2$ and run a deterministic primality test. - **Observable(s):** streaks/lines, local clustering, and how visibility changes with `size`. - **Parameter space:** `size` (and, if you extend it, rendering/annotation choices). - **Outcome:** figures and a short report capturing the key observation and caveats. - **Reproducibility:** outputs saved to `out/e124/` with a parameter snapshot. ## Experiment design - **Computation:** place integers $1,\dots,\text{size}^2$ into the Klauber triangle row rule; mark primes. - **Coordinates:** x is the integer column offset from the center column (0 at the center); the vertical axis is the row index $n$ with $n=1$ at the top. - **Prime classification:** primes are computed using a sieve up to $\text{size}^2$. - **Outputs:** one or more figures showing prime positions in the triangle. - **Artifacts written:** - `figures/fig_01_klauber_triangle*.png` (main figure) and `figures/e124_hero_.png` (published hero) - `params.json` - `report.md` ### Plot axes and coordinate conventions The triangle is indexed by a row number and a horizontal offset within that row: - **y-axis:** the row index $m\in\{1,\dots,\text{size}\}$ (with $m=1$ at the top) - **x-axis:** the integer column offset from the center of the row: $$x\in\{-(m-1),\dots,(m-1)\}$$ For a given row $m$ and offset $x$, the corresponding integer in the Klauber triangle is: $$ n(m,x)=(m-1)^2 + \bigl(x+(m-1)\bigr) + 1. $$ This formula matches the construction “odd squares on the left edge”: the leftmost entry in row $m$ is $n(m,-(m-1))=(m-1)^2+1$, and the row increases by 1 as $x$ moves to the right. If the implementation renders the triangle as a 2D array with Matplotlib `imshow`, the `extent` should be chosen so that tick labels correspond to the displayed $(x,m)$ values. When `origin="upper"` is used, $m$ increases downward visually; in that case, interpret the y-axis tick labels accordingly (or flip the axis via the `extent`). ## How to run ```bash make run EXP=e124 ``` Override the triangle size: ```bash make run EXP=e124 ARGS="--size 501" ``` Direct invocation (always works): ```bash uv run --extra dev python -m mathxlab.experiments.e124 --out out/e124 --size 501 ``` ## Notes / pitfalls - Larger `size` means more numbers ($\text{size}^2$) and a longer run time. - “Looks-true” trap: visual regularity suggests hypotheses but does not prove theorems about primes. - Rendering choices (marker size, interpolation) can hide or exaggerate streaks. ## Extensions - Quantify streaks: compute prime density along selected triangle-aligned lines and plot the densities. - Highlight the square boundaries ($m^2$) or row indices to relate features to the row rule. - Compare multiple sizes side-by-side (same styling and axis conventions). ## Published run snapshot If this experiment is included in the docs gallery, include the published snapshot (report + params). ```{include} ../reports/e124.md :start-after: "" :end-before: "" ``` ::: {dropdown} params.json (snapshot) :open: ```{literalinclude} ../params/e124.json :language: json ``` ::: ## References - Klauber triangle definition and examples: {cite}`Hill2016KlauberTriangle`. - Exposition connecting multiple prime visualizations (includes Klauber and Sacks): {cite}`Brockmann2019PrimeTime`. - Recreational-math context and “pattern traps”: {cite}`gardner1983martin`, {cite}`hoffman1989archimedes`. See also {doc}`../references`. ## Related experiments - {doc}`e024` (Ulam spiral structure) - {doc}`e125` (Sacks spiral structure) - {doc}`e126` (Hexagonal number spiral structure) - {doc}`e127` (Quadratic prime-run atlas ($n^2 + a n + b$)) - {doc}`e128` (Quadratic modular obstructions (Euler-type)) - {doc}`e129` (Euler lucky constants for $n^2 + n + b$) ## Parameters (example) - size: `301` (triangle rows: 301, integers `1..90,601`) ### Recommended `size` range The Klauber triangle up to row `size` contains $\text{size}^2$ integers, so runtime and memory scale roughly with $\text{size}^2$. A practical range that works well for most runs: - **Minimum (still meaningful):** `size = 101` - **Default / recommended:** `size = 301` - **Comfortable upper range on typical laptops (varies):** `size = 999` - **Above ~`size = 1501`:** expect noticeably higher runtime (and potentially memory pressure), depending on the machine and the primality implementation. **Rule of thumb:** start with `301`, then try `501`, `701`, `901`. Increase further only if runtime remains acceptable. ## Summary We render the Klauber triangle containing the first 90,601 positive integers and highlight primes. Even at this moderate scale, visually prominent streaks appear: some triangle-aligned lines contain noticeably more primes than nearby lines. ## Key observations - Several streaks stand out strongly against a background that still looks relatively “noise-like”. - The most visible structures shift as `size` increases; some streaks weaken while others become clearer. ## Interpretation The Klauber triangle is a structured re-indexing of the integers where many visually straight features correspond to simple polynomial or arithmetic progressions in the underlying index. This makes it a useful “pattern detector” for prime-rich sequences, but it is not evidence of a global rule. ## Caveats - Finite window: patterns can look stronger/weaker depending on the chosen `size` and zoom level. - Visualization choices matter: marker size and interpolation can hide or exaggerate streaks. - Different triangle conventions (if you change the row rule) change which streaks appear.