# E127: Quadratic prime-run atlas ($n^2 + a n + b$) ```{figure} ../_static/experiments/e127_hero.png :width: 80% :alt: Preview figure for E127 ``` ```{figure} ../_static/experiments/e127_hero_2.png :width: 80% :alt: Preview figure for E127 ``` **Tags:** `number-theory`, `quantitative-exploration`, `visualization`, `primes`, `optimization` See: {doc}`../tags`. ## Highlights - Heatmap of “how long primes last” for $f(n)=n^2+an+b$ across a small (a,b) grid. - Euler’s $(a,b)=(1,41)$ appears as a visible peak, but it is not unique. - Turns a folklore fact into a reproducible, parameterized sweep with saved artifacts. ## Goal Explore how sensitive **initial prime streaks** are to the coefficients of a quadratic polynomial. We measure, for each (a,b), the largest $L$ such that $f(0),f(1),\dots,f(L-1)$ are all prime. ## Background (quick refresher) - {doc}`../background/quadratic-polynomials` - {doc}`../background/eulers-prime-generating-polynomial` - {doc}`../background/prime-numbers` ## Research question Within a bounded coefficient grid, which quadratic polynomials produce the **longest initial prime runs**, and where does Euler’s polynomial sit in that landscape? ## Method - Sweep integers $a\in[a_{\min},a_{\max}]$ and $b\in[b_{\min},b_{\max}]$. - For each pair, evaluate $f(n)$ for $n=0..N$ and record the initial prime-run length. - Visualize run length as a heatmap and summarize the top candidates in the report. ### Plot axes and coordinate conventions The heatmap uses a 2D grid over the integer coefficients $(a,b)$: - **x-axis:** the coefficient $a$ (horizontal direction) - **y-axis:** the coefficient $b$ (vertical direction) If the sweep uses unit steps (the default), then each heatmap cell corresponds directly to an integer pair: $$(a,b) \in \{a_{\min},\dots,a_{\max}\} \times \{b_{\min},\dots,b_{\max}\}.$$ More generally, if the heatmap array is indexed by $(i,j)$ with $i=0,\dots,n_a-1$ (columns) and $j=0,\dots,n_b-1$ (rows), then the coefficients shown at that cell are: - $$x = a = a_{\min} + i\,\Delta a$$ - $$y = b = b_{\min} + j\,\Delta b$$ For Matplotlib `imshow`, this is typically implemented via an `extent` so that tick labels match the coefficient values (e.g. `extent=(a_min-0.5, a_max+0.5, b_min-0.5, b_max+0.5)` for unit steps). If you flip the image origin (`origin="upper"`), the y-axis is inverted visually; in that case, interpret the y-axis tick labels accordingly. ## How to run ```bash make run EXP=e127 ``` or: ```bash uv run python -m mathxlab.experiments.e127 ``` ## Outputs This experiment follows the standard output contract: - `out/e127/figures/` — generated figures (PNG) - `out/e127/report.md` — short narrative report - `out/e127/params.json` — run parameters (stable JSON) - `out/e127/logs/` — run logs (created by the runner/Makefile) ## Published run snapshot If this experiment is included in the docs gallery, include the published snapshot (report + params). ```{include} ../reports/e127.md :start-after: "" :end-before: "" ``` ::: {dropdown} params.json (snapshot) :open: ```{literalinclude} ../params/e127.json :language: json ``` ::: ## References - Euler’s quadratic and “lucky numbers”: {cite:t}`WikipediaContributors2025LuckyNumbersOfEuler`, {cite:t}`Weisstein2025EulerPrimeMathWorld`. - Quadratic basics (discriminant, roots): {cite:t}`WikipediaContributors2026QuadraticEquation`. ## Related experiments - {doc}`e013` (Euler’s polynomial: first counterexample witness) - {doc}`e024` (Ulam spiral: prime-rich diagonals explained by quadratic forms) - {doc}`e031` (modular obstructions and admissibility) - {doc}`e125` (Sacks spiral prime structure) - {doc}`e126` (hex-grid spiral prime structure)