Prime-Likeness Landscape Theory
Abstract
This document develops the mathematical theory behind the **Prime-Likeness Landscape** visualizer. The central idea is to treat each integer not only as a candidate for primality, but as a point in a geometric landscape determined by how strongly it resists collapse under trial-divisor alignment. In the visual interpretation, **valleys** correspond to clear divisor structure, while **ridges** correspond to relative stability against small-divisor collapse. The framework began with trigonometric branch comparisons involving upper and lower perturbations of \(\pi\), then simplified into a direct and computationally clearer distance-to-integer score. The resulting reverse score
\[ G(n)=\min_{2\le d\le D} d\,\mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right) \]
provides a practical way to visualize prime-like behaviour over an interval of integers. This is **not** a competitive primality test in the algorithmic sense, but it is a useful structural and visual model for understanding how primes sit in a divisor-avoidance field.
---
1. Conceptual starting point
The original line of thought came from comparing **mixed perturbation branches** built from upper and lower approximations of \(\pi\). The idea was that if one writes
\[ \pi_m^- = \frac{\lfloor 10^m\pi\rfloor}{10^m}, \qquad \pi_m^+ = \frac{\lceil 10^m\pi\rceil}{10^m}, \]
then same-branch differences cancel exactly, while mixed-branch differences produce a small residual. For integer harmonics \(I\), one has the mixed branch residual
\[ Y_m(I)=\sin(I\pi_m^+) - \sin(I\pi_m^-), \]
which satisfies, for small bracket width,
\[ Y_m(I)\approx (-1)^I I10^{-m}. \]
This creates an alternating sign-and-magnitude signal. That led naturally to the idea of using branch residuals to detect arithmetic structure.
The first major attempt was to use these residuals directly as a form of prime detector. That route turned out to be too weak: the trigonometric signal was excellent at detecting **integer phase restoration**, but it could be fooled by **near-integer phase**. In other words, numbers that were not truly divisible could still produce strong false resonances.
This failure was actually useful, because it revealed what the trigonometric experiment was really measuring:
\[ \text{distance of } \frac{n}{d} \text{ from an integer.} \]
That observation led to the simpler and clearer landscape score.
---
2. Integer phase restoration
Let \(n\) be the integer under investigation, and let \(d\) be a trial divisor. Define
\[ x=\frac{n}{d}. \]
If \(d\mid n\), then \(x\in\mathbb{Z}\). If not, then \(x\) is non-integer.
The key arithmetic distinction is therefore not mysterious:
\[ d\mid n \iff \frac{n}{d}\in\mathbb{Z}. \]
From the trigonometric perspective, integer values of \(x\) restore the clean phase law because
\[ \sin(x\pi)=0 \quad \text{whenever } x\in\mathbb{Z}. \]
So divisibility can be reinterpreted as **exact integer phase restoration**.
This leads to the natural distance measure
\[ \Delta(n,d)=\mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right), \]
where
\[ \mathrm{dist}(x,\mathbb{Z}) = \min_{k\in\mathbb{Z}} |x-k|. \]
Thus:
- if \(d\mid n\), then \(\Delta(n,d)=0\); - if \(d\nmid n\), then \(\Delta(n,d)>0\).
This distance is the core mathematical object behind the landscape.
---
3. Why multiply by \(d\)?
If one used \(\Delta(n,d)\) alone, the scale would shrink automatically as \(d\) grows, even for nondivisors. To normalize this, we multiply by \(d\) and define
\[ J(n,d)=d\,\mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right). \]
Now suppose \(n=qd+r\) with remainder \(r\), where
\[ 0\le r<d. \]
Then
\[ \frac{n}{d}=q+\frac{r}{d}, \]
so the distance to the nearest integer is
\[ \mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right)=\min\!\left(\frac{r}{d},1-\frac{r}{d}\right). \]
Multiplying by \(d\) gives
\[ J(n,d)=\min(r,d-r). \]
This is a very revealing formula.
Consequences
1. **Exact divisibility**: if \(r=0\), then \[ J(n,d)=0. \]
2. **Nondivisibility**: if \(r\ne 0\), then \[ J(n,d)\ge 1. \]
So in exact arithmetic,
\[ \boxed{d\mid n \iff J(n,d)=0,\qquad d\nmid n \iff J(n,d)\ge 1.} \]
This is the sharp separation that the earlier resonance score was only approximating.
---
4. Reverse score and the landscape view
For a fixed candidate integer \(n\), we consider all trial divisors up to some cutoff \(D\). The visualizer uses the score
\[ G_D(n)=\min_{2\le d\le D} J(n,d) = \min_{2\le d\le D} d\,\mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right). \]
In practice the code also caps \(D\) at \(\lfloor\sqrt n\rfloor\), because divisibility beyond that point is redundant for primality testing.
The interpretation is:
- **small \(G_D(n)\)** means some trial divisor aligns strongly with \(n\), producing a valley; - **large \(G_D(n)\)** means no small trial divisor aligns well with \(n\), producing a ridge.
This is why the visualizer describes the quantity as a **reverse prime-likeness field**.
The word “reverse” matters: instead of directly proving primality, the score measures **avoidance of divisor collapse**.
---
5. Prime-likeness interpretation
Suppose \(n\) is composite. Then there exists a divisor \(d\le \sqrt n\), and therefore
\[ G_D(n)=0 \]
as soon as the cutoff includes that divisor.
Suppose instead that \(n\) is prime. Then no divisor \(d\) in the trial range divides \(n\), so every term in the minimum is at least \(1\), and therefore
\[ G_D(n)\ge 1 \]
provided all divisors up to \(\sqrt n\) are included.
Thus, in exact arithmetic with full cutoff,
\[ \boxed{n\text{ composite }\Rightarrow G(n)=0,\qquad n\text{ prime }\Rightarrow G(n)\ge 1.} \]
This is the cleanest theoretical form.
However, the visualizer is also useful with **partial cutoff** \(D\), in which case a composite may still appear ridge-like if its smallest divisor exceeds the chosen cutoff. That is not a bug: it is part of the landscape idea. The field answers the question
\[ \text{how strongly does } n \text{ resist collapse under the currently visible divisor range?} \]
So the landscape is not merely a primality indicator; it is a **scale-dependent arithmetic terrain**.
---
6. From trigonometric residuals to distance scores
The current visualizer uses the direct score
\[ J(n,d)=d\,\mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right), \]
but it is worth recording how this emerged from the earlier \(\pi^-/\pi^+\) branch logic.
Consider the average of the two branches,
\[ A_m(x)=\frac{1}{2}\bigl(\sin(x\pi_m^-)+\sin(x\pi_m^+)\bigr). \]
For small decimal bracket width, this behaves like
\[ A_m(x)\approx \sin(\pi x). \]
This suggests estimating the distance to the nearest integer using
\[ \widehat{\Delta}_m(x)=\frac{1}{\pi}\arcsin(|A_m(x)|). \]
Then one may define
\[ J_m(n,d)=d\,\widehat{\Delta}_m\!\left(\frac{n}{d}\right). \]
Numerically, this was found to separate divisors and nondivisors extremely well. In the present file, that trigonometric mechanism has been simplified into the exact direct arithmetic version using nearest-integer distance.
So the landscape should be understood as the **clean distilled form** of the earlier branch experiments.
---
7. Binary sequence derived from the landscape
The visualizer produces not only a continuous-looking landscape, but also a binary sequence. Once each number \(n\) has been assigned a landscape score \(G_D(n)\), a threshold \(\tau\) is chosen and the binary map is defined by
\[ B_\tau(n)= \begin{cases} 1, & G_D(n)\ge \tau,\\ 0, & G_D(n)<\tau. \end{cases} \]
This yields a bit string over the chosen viewing window.
Interpretation of bits
- **1-bit**: ridge-like, meaning the number avoids collapse under the chosen divisor cutoff and threshold. - **0-bit**: valley-like, meaning the number exhibits clear divisor alignment or near-alignment.
The associated subsequences are:
- the **ridge sequence** \[ \{n : B_\tau(n)=1\}, \] - the **valley sequence** \[ \{n : B_\tau(n)=0\}. \]
This binary layer does not claim to be “the prime sequence.” Instead, it is the binary output of the landscape under a chosen scale and threshold. Depending on \(D\) and \(\tau\), it may approximate primality, or it may capture a broader notion of prime-likeness.
---
8. Geometry of ridges and valleys
The landscape metaphor is more than visual decoration.
Valleys
A valley occurs when some divisor \(d\) makes \(n/d\) land very close to an integer. In the exact divisor case this produces
\[ G_D(n)=0. \]
These are the deepest valleys. Near-divisors create shallower valleys.
Ridges
A ridge occurs when every divisor channel in the chosen range stays far from integer alignment. Then the minimum distance remains high, and so does the landscape score.
Primes often sit on ridges because they have no nontrivial divisor channels in the tested range.
Cutoff dependence
The terrain changes as \(D\) changes.
- Increasing \(D\) introduces more divisor channels. - New channels can only keep the score the same or lower it. - Therefore the landscape becomes more deeply carved as \(D\) increases.
This is why some composites appear ridge-like at low cutoff and then collapse into valleys when the cutoff is raised.
---
9. Why this is interesting even if it is not algorithmically optimal
From a computational number theory standpoint, ordinary modular arithmetic is the standard way to test divisibility, and modern primality tests vastly outperform this style of geometric scoring. So the present framework is **not** proposed as a superior algorithm.
Its value is different.
Structural value
It gives a continuous or quasi-continuous picture of a discrete arithmetic property.
Visual value
It lets one see primality and compositeness not merely as labels, but as terrain.
Conceptual value
It links: - integer phase restoration, - branch residual logic, - distance to nearest integer, - binary thresholding, - and prime-likeness.
In that sense the theory is a bridge between trigonometric intuition and integer arithmetic.
---
10. Relation to the code in the current visualizer
The current visualizer implements the simplified exact form.
Core helper
```ts function nearestIntegerDistance(x: number) { return Math.abs(x - Math.round(x)); } ```
This computes
\[ \mathrm{dist}(x,\mathbb{Z}). \]
Reverse score
```ts function primeGuessScore(n: number, maxD: number) { if (n < 3 || n % 2 === 0) return 0; const upper = Math.min(maxD, Math.floor(Math.sqrt(n))); if (upper < 2) return 1;
let best = Number.POSITIVE_INFINITY; for (let d = 2; d <= upper; d++) { const x = n / d; const dist = nearestIntegerDistance(x); const score = d * dist; if (score < best) best = score; } return best; } ```
This is precisely the finite-cutoff landscape score
\[ G_D(n)=\min_{2\le d\le D} d\,\mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right). \]
Binary map
```ts function bitFromScore(score: number, threshold: number) { return score >= threshold ? 1 : 0; } ```
This implements the threshold rule
\[ B_\tau(n)=1 \iff G_D(n)\ge \tau. \]
So the code and the theory line up directly.
---
11. Limits and cautions
Several limits should be stated clearly.
11.1 Not a new primality test in the practical sense
The method still scans trial divisors. It therefore does not outperform standard prime-testing algorithms.
11.2 Threshold dependence
The binary sequence depends on the chosen threshold \(\tau\). Different thresholds yield different ridge/valley encodings.
11.3 Cutoff dependence
The field depends strongly on the chosen divisor cutoff \(D\). A number may appear ridge-like under a small cutoff and then collapse later.
11.4 Prime-likeness is not identical to primality
Ridges often indicate primes, but not always. Some composites hide as ridges until the relevant divisor channel is included.
11.5 Visual utility exceeds algorithmic utility
The main contribution is explanatory and structural, not computational efficiency.
---
12. Extensions
Several extensions suggest themselves.
12.1 Local peak binary mode
Instead of thresholding the raw score, one could mark a 1 only when a number is a **local ridge peak** relative to its neighbors. This would create a sparser and more structural binary sequence.
12.2 Multiscale cutoff landscape
One could track
\[ G_D(n) \]
as \(D\) varies, creating a two-dimensional field where one axis is the number \(n\) and the other is the divisor scale.
12.3 Trigonometric reconstruction mode
A future version could restore the explicit \(\pi^-/\pi^+\) branch machinery and show the direct relation between branch averages, branch differences, and the exact arithmetic score.
12.4 Sequence analysis
The ridge and valley sequences can themselves be studied as number sequences. One might examine gap distributions, binary compressibility, or correlation with genuine prime gaps.
---
13. Conclusion
The Prime-Likeness Landscape began as a trigonometric investigation of mixed perturbation branches around \(\pi\), but its clearest form emerges as a direct arithmetic score based on divisor-aligned distance to the integers. The fundamental quantity is
\[ J(n,d)=d\,\mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right), \]
and the landscape field is the cutoff minimum
\[ G_D(n)=\min_{2\le d\le D} J(n,d). \]
This field creates a natural topography: - divisibility produces valleys, - resistance to small-divisor alignment produces ridges, - thresholding produces a binary sequence, - and varying the cutoff changes the shape of the terrain.
The framework is best viewed as a theory of **arithmetic terrain** rather than a replacement for efficient primality testing. Its strength lies in turning a discrete divisor property into a geometric object that can be explored visually, structurally, and experimentally.
---
Appendix A. Core definitions
\[ \mathrm{dist}(x,\mathbb{Z})=\min_{k\in\mathbb{Z}}|x-k| \]
\[ J(n,d)=d\,\mathrm{dist}\!\left(\frac{n}{d},\mathbb{Z}\right) \]
\[ G_D(n)=\min_{2\le d\le D} J(n,d) \]
\[ B_\tau(n)= \begin{cases} 1, & G_D(n)\ge \tau,\\ 0, & G_D(n)<\tau \end{cases} \]
---
Appendix B. Divisor remainder form
If
\[ n=qd+r, \qquad 0\le r<d, \]
then
\[ \frac{n}{d}=q+\frac{r}{d} \]
and therefore
\[ J(n,d)=\min(r,d-r). \]
Hence
\[ J(n,d)=0 \iff d\mid n. \]
This is the arithmetic heart of the landscape.