1/2
110 Hz
3.12 m
A2
Audio Engine LIVE
880 Hz
100%
110 Hz
1/2 = A2
Wave Properties λ
78.0 cm
Wavelength (v=343 m/s)
Period: 2.27 ms
Angular ω: 2764 rad/s
Wavenumber k: 8.06 /m
Musical Intervals
Harmonic Mode
Consonant q ≤ 4
Unison q=1
Consonant q≤4
Complex q≤16
Dissonant q>16
Arnold Tongue
0.50
Harmonic Series
8
Options
Selected Fraction
Click any point to select
Keyboard:
Space = toggle play
←/→ = path direction
↑/↓ = sector direction
Esc = stop

Farey Sequence Summatory Function

Computational exploration of coprime pair distributions using classical summatory totient estimates

F(s, N) = 3N² / (π² s(s+1))

Mertens' totient formula applied to interval S_s = (1/(s+1), 1/s]

Exact
Hybrid
Formula
Exact enumeration
to
to
-
1.0000 = 1.0000 → Max sector: 500
Explorer
Analysis
Calculator
π Theory
Geometry
Connections
Advanced
References
Main View Error Analysis 🆕 Interactive Features
Farey Summatory Function
F(s,N) = 3N² / (π² s(s+1))
Sector Sₛ = (1/(s+1), 1/s]

Interactive Farey Sequence Explorer

This visualization explores coprime fractions r/m within Farey sequence intervals (sectors). Each sector Sₛ = (1/(s+1), 1/s] contains fractions arranged in a circular ring, with colors indicating various mathematical properties.

Ring Canvas: Points arranged by angle (r/m × 2π) and radius (denominator m). The coprime points of ring m are the primitive m-th roots of unity, and summing them as unit vectors gives exactly μ(m) — Ramanujan's sum cm(1). Page 12 measures that interference and accumulates it into the Mertens function.
Sector Tree: Stern-Brocot tree showing hierarchical fraction structure
Stats Panels: Real-time counts, formula predictions, and error analysis
Ring Display Controls
75%
C(n) — live value & survival ratios | depth n: Scope: 12% 1.5
Lift dynamics — prime spiral
p=2 PATH from 1/2:
100%
VIEW: POINTS:
Sector: range -
Play Range: Total: - Speed: ms 25 ms Zoom:
Ring Loop: Ring: -
Target Ratio Solver
Prime Residue Tracker
Word Art

Exact vs Predicted Scroll to zoom, drag to pan

Relative Error % Scroll to zoom, drag to pan

Higher error → higher pitch

Sector Data (click row to see details)

Page 1 / 1 Jump to sector: Rows:
sIntervalExactPredErr%P(m)C(m)P/C

Sector Tree Path (Stern-Brocot navigation - click nodes to play)

Go to Fraction: or click ring/tree
Zoom: 100% Pan: Scroll=zoom, Drag=pan
Click a point on the ring or tree to see its path and play its frequency
Tree nodes
Path to target
Target fraction
L (left)
R (right)
Sector Colors:
S1
S2
S3
S4
S5

📸 Screenshot Legend Information

The screenshot includes a comprehensive legend showing all visualization elements, statistics, and the Bisection Identity (Theorem 1) verification box. Note: The bisection identity requires all sectors included, i.e. Sector Bound constant = 1. That is the default, so this verifies PASS on load. Narrowing the bound (< 1) truncates the right hand side and the check will report FAIL.

Legend Font Size Control

px (default: 14)
px (default: 14)

Error Analysis

Computational analysis of deviations between exact enumeration and Mertens' asymptotic formula F(s,N) = 3N²/(π²s(s+1)) applied to intervals.

Analysis Range

Spectral Analysis

Periodicity diagnostic for the sector-residual sequence. Note this spectrum is indexed in cycles per sector index (range 0 to 0.5); it is not comparable to the imaginary parts of the zeta zeros, which are frequencies conjugate to log x. Detecting those would require log-spaced sampling, which this panel does not perform.

Möbius Function

Correlation between errors and μ(n) tests for arithmetic structure. Non-zero correlation suggests prime factorization affects error distribution.

Error Statistics
Mean: -
Std Dev: -
Skewness: -
Kurtosis: -
Prime sectors mean: -
Composite sectors mean: -
Möbius correlation: -
Autocorrelation (lag 1-20) Red = significant
Power Spectrum (FFT) cycles per sector index
Error Distribution
Prime vs Composite Sector Errors
Cumulative |Error| growth rate (cf. classical O(N log N) totient-sum error)
Dominant Spectral Peaks

Summatory Totient Formula Calculator

Calculate Σφ(k) for k=1 to N with detailed step-by-step breakdown and comprehensive data export

Input Parameters

!

Formula Clarification

This framework uses two related but distinct formulas:

SECTOR FORMULA (Main Page)
F(s,N) = 3N² / (π²s(s+1))
Counts fractions in one sector Sₛ
GLOBAL FORMULA (Calculator)
Σφ(k) = (3/π²)N² + O(N log N)
Sums totient over all k from 1 to N

Relationship: Summing F(s,N) over all sectors s ≈ Σφ(m) (total coprime count)

Summatory Function of Coprime Pairs in Farey Sequence Intervals

Wessen Getachew

Abstract

This work applies classical summatory totient estimates (Mertens, 1874) to Farey sequence intervals. We examine the distribution of coprime integer pairs (a,b) whose rational slope a/b lies in specific intervals S_s = (1/(s+1), 1/s]. The asymptotic count F(s,N) ~ (3/π²)N²/(s(s+1)) follows directly from applying Mertens' totient summation formula to the geometric constraint. This provides a computational framework for exploring interval-specific coprime density, complementing the well-known global density 6/π². We identify computational regimes where asymptotic estimates transition to discrete counting behavior.

1. Introduction and Motivation

The probability that two randomly chosen integers are coprime is 1/zeta(2) = 6/pi^2 approximately 0.6079, a classical result with interpretations in analytic number theory and geometry of numbers. Geometrically, this corresponds to the density of visible lattice points in Z^2.

Farey sequences organize rational numbers in [0,1] by increasing denominator and naturally partition rational directions into intervals. While global coprime density is well understood, we focus on directional coprime density - how primitive lattice points distribute across specific rational slope bands.

2. Definitions

Farey Sector
S_s = (1/(s+1), 1/s]

Intervals partitioning (0,1], bounded by consecutive Farey fractions.

Primitive Lattice Point
(a,b) in Z^2 where gcd(a,b) = 1, b >= 1

Pairs with coprime coordinates representing visible lattice points.

3. Main Result

Interval-Specific Application

Applying Mertens' summatory totient formula to Farey interval S_s = (1/(s+1), 1/s], we obtain:

F(s,N) ~ (3/π²) × N² / (s(s+1))

Where F(s,N) counts coprime pairs (a,b) with 1 ≤ b ≤ N, gcd(a,b)=1, and a/b in S_s. This follows from classical totient summation.

4. Derivation from Classical Results

Step 1: The geometric constraint a/b ∈ S_s = (1/(s+1), 1/s] translates to b/(s+1) < a ≤ b/n.

Step 2: For each denominator b, there are approximately b/(s(s+1)) integers a in this range.

Step 3: Restricting to coprime pairs: Σ_{b≤N} φ(b)/(s(s+1)) + O(N)

Step 4: Apply Mertens' classical summatory totient formula (1874):

Sum of phi(b) = (3/pi^2)N^2 + O(N log N)

Conclusion: F(s,N) = (1/(s(s+1))) * ((3/pi^2)N^2 + O(N log N))

5. Computational Verification

Sector sWidth 1/(s(s+1))Asymptotic Factor F(s,N)/N²Numeric Value
11/23/(2pi^2)approximately 0.1520
21/63/(6pi^2)approximately 0.0507
31/123/(12pi^2)approximately 0.0253
n1/(s(s+1))3/(pi^2 s(s+1))approximately 0.3040/(s(s+1))

Numerical experiments confirm convergence to predicted asymptotics at rates consistent with O(N log N) error decay. Interactive visualizations above display accumulation of primitive lattice points within each Farey sector.

6. Key Theoretical Connections

Euler and Coprime Density

Global density 1/zeta(2) = 6/pi^2 emerges as sum of sectoral contributions.

7. The Sector Boundary: Where the Predicted Count Drops Below 1

The Discreteness Threshold of the Farey Sequence

Computational analysis shows that for any fixed N, there exists a transition point s* ≈ (√3/π)N ≈ 0.5513N where the asymptotic formula transitions from useful density estimation to sparse discrete counting. This computational boundary represents where expected counts drop below 1, entering a regime where relative error becomes unstable.

s* ≈ (√3/π) · N ≈ 0.5513 · N

This is an elementary threshold, not a signal-processing result — "Nyquist limit" doesn't literally apply here. The only resemblance is qualitative: a fixed-N formula stops resolving individual sectors once predicted counts drop below 1, the same shape as sampling below a Nyquist rate, with no deeper connection than that shape.

7.1 Derivation of the Boundary Constant

Condition: The predicted count F(s,N) falls below unity when:

(3/π²) · N² / (s(s+1)) < 1

Solving for n: n² + n > (3/π²)N² implies n > (√3/π)N for large n

The Constant: √3/π ≈ 0.5513 emerges naturally from the interaction of:

  • The coprime density constant 3/π² (from Euler's totient asymptotics)
  • The geometric sector width 1/(s(s+1))

7.2 Behavioral Regimes

PropertyDense Regime (n < 0.55N)Boundary (n ≈ 0.55N)Sparse Regime (n > 0.55N)
Predicted CountF(s,N) >> 1F(s,N) ≈ 1F(s,N) < 1
Relative ErrorLow, stable (< 5%)Increasing noiseOscillatory, unbounded
Identity DistributionSpread across PP, PC, CP, CCConcentratingSingle category dominates
Mathematical RegimeAnalytic (Density)TransitionalDiscrete (Counting)

7.3 The Discrete-Counting Regime

Beyond the boundary, sectors enter a regime where (the name is descriptive only — no quantum mechanics involved):

Discrete Counting Dominates

The formula predicts fractional counts (0.4, 0.7) but actual counts must be integers (0 or 1), causing wild relative error oscillations.

Identity Collapse

When a sector contains exactly one fraction, that fraction occupies precisely one P/C category, trivially satisfying the identity: 0+0+0+1 = 1.

7.4 Physical Interpretation: A Resolution Map of the Primes

The boundary constant provides a "resolution limit" for prime distribution analysis:

  • Zooming In: Increasing N allows the asymptotic formula to penetrate deeper into higher-numbered sectors before encountering empty regions.
  • Exhaustion Point: For s > N/2 every sector contains exactly one fraction, namely 1/s — any numerator a ≥ 2 would need denominator b ≥ 2s > N. The predicted count crosses 1 near n ≈ 0.5513N and drifts slowly downward past this constant.
  • Not an accuracy guarantee: This is a resolution limit only. Relative error of the asymptotic is O(n²/N) and exceeds 15% well before n ≈ 0.55N; agreement at 0.55N looks better than the formula deserves because the exact count is pinned at 1 across that whole range. Note also that the high-s regime is fully deterministic and prime-independent — 1/s is present whether s is prime or composite.
Key Observation

The Prime/Composite identities (PP + PC + CP + CC = Total) hold exactly in all regimes, including at and beyond the boundary. This persistence demonstrates that while density estimates fail, the underlying arithmetic structure remains inviolate. The boundary thus separates where we can predict counts from where we can only verify identities.

8. Involution Pairing: ι(r/m) = (m−r)/m

Theorem (Involution)

The map ι: r/m ↦ (m−r)/m is an involution on the Farey fractions with the following properties. (Written ι, not φ — throughout this page φ is reserved for Euler's totient.)

  • Self-inverse: ι(ι(r/m)) = r/m (applying twice returns the original)
  • Sum identity: r/m + (m−r)/m = m/m = 1 (exactly, not approximately)
  • Fixed point: ι(1/2) = 1/2 is the unique fixed point (r = m−r ⟺ m = 2r ⟺ r/m = 1/2)
  • Coprimality preserved: If gcd(r,m) = 1 then gcd(m−r,m) = 1

8.1 Why the Sum is Exactly 1.0

The sum r/m + (m−r)/m = 1 is an exact algebraic identity, not an approximate numerical result:

r/m + (m−r)/m = (r + m − r)/m = m/m = 1

However, when computed in floating-point arithmetic, the sum may be displayed as 0.9999999... or 1.0000001... due to rounding errors in the binary representation. The tool displays 10 decimal digits and marks the sum with PASS (green check) if within 10⁻¹⁰ of 1.0, or FAIL (red X) if the error exceeds this tolerance (indicating a computational issue, not a mathematical violation).

9. Bisection Identity (Theorem 1)

Theorem 1 (Bisection Identity)

The first Farey sector S₁ = (1/2, 1] has exactly as many coprime fractions as the union of all remaining sectors S₂ ∪ S₃ ∪ S₄ ∪ ⋯ combined:

|S₁| = |S₂| + |S₃| + |S₄| + ⋯

9.0 Refined Form — S₁ Sector by Sector

Theorem 1′ (Refined Bisection)

Theorem 1 equates two totals. The involution in fact matches S₁ against the rest one sector at a time. Label each fraction of S₁ by the sector of its reflection, sub‑sector k = ⌊m/(m−r)⌋. Then:

|S₁,ₖ| = |Sₛ| for k ≥ 3   and   |S₁,₂| = |S₂| − 1

Summing these rows returns Theorem 1, so the refined form is strictly stronger: S₁ does not merely have the same total as the rest, it contains a piece matching every individual sector. The single deficit at k = 2 is the fixed point ι(1/2) = 1/2, which sits in S₂ and has no preimage in S₁ — the same orphan that makes Theorem 1 balance, now visible instead of cancelled.

Why the reflection index and not the second CF digit

Sector index is the first partial quotient a₁, so it is tempting to label sub‑sectors by the second, a₂. That is a different index: over all 24,338 coprime fractions of S₁ with m ≤ 400, ⌊m/(m−r)⌋ = a₂ + 1 in every case and the two are never equal. Indexing by a₂ shifts every row by one and the identity reads as |S₁,ₖ| = |Sk+1|, which looks like a mismatch. The reflection index is used here so sub‑sectors line up with sectors by name.

The subdivision is applied to S₁ only, at one level. Descending further would need a labelling convention for sub‑sectors of S₁,ₖ that has not been established, and no unverified index is put on the page.

Run a computation to populate the refined check.

9.1 Why the Identity Holds Exactly for gcd Pairs

The involution ι(r/m) = (m−r)/m pairs S₁ with the rest almost perfectly, and the two leftover points cancel exactly:

  • ι maps (1/2, 1) bijectively onto (0, 1/2), pairing every fraction in S₁ (other than the endpoint 1) with a fraction somewhere in S₂∪S₃∪⋯
  • The endpoint 1 = 1/1 ∈ S₁ has no partner: ι(1) = 0, which isn't a valid fraction in this range. That leaves S₁ with one unpaired element.
  • The fixed point ι(1/2) = 1/2 maps to itself. Since S₁ = (1/2, 1] is open at 1/2, the fraction 1/2 itself belongs to S₂ = (1/3, 1/2], not S₁. That leaves the rest (S₂∪S₃∪⋯) with one unpaired element too.
  • Both sides have exactly one leftover point — S₁'s unpaired "1" and the rest's unpaired "1/2" — so they cancel and the sizes come out exactly equal, with no net offset.

WARNING Important: Boundary Condition

This identity only holds when the boundary slider is set to 1 (all sectors S₁, S₂, S₃, ... included). When you enable the boundary control and set it to a value less than 1, the identity will show FAIL (fail) because some high-index sectors are excluded from the count. The screenshot will display PASS only when boundary = 1 (full dataset).

Note: This identity is exact for coprime (gcd=1) fractions in the Farey sequence. If non-coprime fractions r/m with gcd(r,m)>1 are included, the count changes because reducible fractions like 2/4, 3/6, etc. collapse to simpler forms, altering the balance. The tool verifies the identity with PASS when it holds for the current dataset.

10. Summary

This work provides a computational framework for exploring coprime pair distributions across Farey sequence intervals. By applying Mertens' classical summatory totient formula to specific rational slope ranges, we obtain explicit asymptotic counts for each interval. Computational analysis reveals a transition point near n ≈ 0.55N where asymptotic density estimates give way to discrete arithmetic behavior. The framework enables systematic study of prime/composite categorization, modular constraints, and the interplay between continuous approximation and discrete counting in number-theoretic distributions.

See References tab for foundational works and acknowledgments.

Interactive Theory Visualization

Visual exploration of classical totient estimates applied to Farey sequence intervals

Sector Partition of (0,1]

Density Cone: F(s,N) ~ (3/π²)N²/s(s+1)

Summatory Totient: Σφ(b) ~ 3N²/π²

Actual Σφ(b)
Asymptotic 3N²/π²

Visible Lattice Points by Direction

Visible (gcd=1)
Hidden (gcd>1)
Sector Boundary

Proof Visualization: Step-by-Step Accumulation

Cumulative count
Predicted asymptotic
φ(b)/(s(s+1)) contribution

Convergence Rate Analysis

Sector Density Heatmap: F(s,N) across parameters

Low density
Medium
High density
Summary: For fixed sector s, as N → ∞: F(s,N) = (3/π²) × N²/(s(s+1)) + O(N log N). This follows directly from applying Mertens' summatory totient formula Σφ(b) = (3/π²)N² + O(N log N) to the geometric constraint a/b ∈ (1/(s+1), 1/s].

Farey Gap Analysis

gap(a/b, c/d) = |c/d - a/b| = 1/(b*d)

For consecutive Farey fractions a/b and c/d, the gap between them equals exactly 1/(b*d). Gaps therefore decrease as denominators grow. The distribution reveals how fractions cluster and spread across the unit interval.

Gap Distribution (Color = Size)

Gap vs Denominator Product

Gap Position in [0,1]

Gap Size vs Position

Largest Gaps (sorted by gap size)

#Left FractionRight FractionActual GapTheoretical 1/(bd)Match
Key Insight: Every gap exactly equals 1/(bd) where b and d are the denominators of consecutive Farey fractions. This is a consequence of unimodularity (the Farey neighbor property): for neighbors a/b and c/d we have |ad - bc| = 1. Distinct from the mediant property, which concerns (a+c)/(b+d).
Ford Circles Connection: Each Farey fraction a/b corresponds to a Ford circle of radius 1/(2b²) tangent to the real line at x = a/b. Two Ford circles are tangent if and only if their fractions are Farey neighbors. The gap formula 1/(bd) emerges from the geometry of tangent Ford circles, connecting number theory to hyperbolic geometry.
Hear the gaps as intervals:

Dedekind Sums

s(h,k) = Σ_{j=1}^{k-1} ((j/k))((hj/k))

Dedekind sums are arithmetic functions encoding properties of coprime pairs (h,k). They satisfy reciprocity formulas: s(h,k) + s(k,h) = -1/4 + (1/12)(h/k + k/h + 1/(hk)). These sums connect to modular forms and are fundamental in algebraic number theory.

Dedekind Sums

Definition: s(h,k) = Σ_{j=1}^{k-1} ((j/k))((hj/k)) where ((x)) = x - floor(x) - 1/2 if x is not an integer, else 0

s(h,k) Heatmap

s(1,k) vs k

Distribution of s(h,k) Values

12k*s(h,k) Distribution

Dedekind Sum Table

hss(h,k)12k*s(h,k)gcd

Reciprocity Verification (s(h,k) + s(k,h) = -1/4 + (1/12)(h/k + k/h + 1/(hk)))

hss(h,k)s(k,h)SumRHSMatch
Reciprocity: s(h,k) + s(k,h) = -1/4 + (1/12)(h/k + k/h + 1/(hk))
Modular Forms Connection: Dedekind sums arise in the transformation formula for the Dedekind eta function η(τ) = e^(πiτ/12) Π(1-e^(2πinτ)). Under modular transformations, the eta function picks up factors involving Dedekind sums, making them essential in the theory of modular forms.

Continued Fractions

Stern-Brocot Encoding: With the walk used here (root 1/1, boundaries 0/1 and 1/0), a path with run-lengths L^{a₁} R^{a₂} L^{a₃}… encodes the CF [0; a₁, a₂, …, aₖ+1] — the last exponent is one short, because the walk halts on arrival. E.g. 2/5 → LLR → [0;2,2]; 7/10 → LRRLL → [0;1,2,3]. Every rational r/m has exactly two finite CF expansions ([…,aₖ] and […,aₖ−1,1]); it is unique once the last term is required to be ≥ 2. The convergents p_k/q_k satisfy |r/m - p_k/q_k| < 1/(q_k * q_{k+1}), giving best rational approximations.

Selected Fraction

Click a row in the table below to select a fraction

Continued Fraction Expansions (click row to select & play)

r/mCF [a0; a1, a2, ...]PathLengthSum(a_i)Max(a_i)FreqPlay

CF Length Distribution

First Partial Quotient a_1

Sum of Partial Quotients

Max Partial Quotient

Gauss-Kuzmin Distribution: For almost all real numbers, the probability that a partial quotient a_k equals n approaches −log₂(1 − 1/(n+1)²) = log₂(1 + 1/(n(n+2))) as k → ∞. For n=1, this is about 41.5%; for n=2, about 17.0%; for n=3, about 9.3%. Caveat: Farey fractions do approach this distribution, but convergence is logarithmic in N and visibly incomplete at usable sizes — at N=1000 the observed share of aₖ=2 is about 20.5% against the limiting 17.0%. A histogram that does not match is expected, not a bug.
Golden Ratio Connection: The golden ratio φ = [1; 1, 1, 1, ...] has all partial quotients equal to 1, making it the "most irrational" number - hardest to approximate by rationals. Fractions with small partial quotients are harmonically simple.

PSL(2,ℤ) Matrices & Ford Circles

Farey Neighbor Property: For consecutive Farey fractions a/b < c/d: bc − ad = 1, so the matrix [c,a; d,b] has determinant +1 and lies in SL(2,ℤ) (the column order [a,c; b,d] gives determinant −1, i.e. GL(2,ℤ)). Such matrices generate the modular group PSL(2,ℤ) = SL(2,ℤ)/{±I}.

Ford Circles

Tangency Graph

Neighbor Matrices (a/b → c/d with det = ad-bc)

Determinant Verification

Circle Radius Distribution

Ford Circle Geometry: Each fraction a/b corresponds to a Ford circle of radius 1/(2b²) tangent to the real line at x=a/b. Two Ford circles are tangent if and only if |ad − bc| = 1, i.e. their fractions are Farey neighbors in Fₘ for m = max(b,d); otherwise the circles are disjoint.
Modular Group Action: PSL(2,ℤ) acts on the upper half-plane by Möbius transformations: z → (az+b)/(cz+d). The fundamental domain is the "keyhole" region, and Ford circles visualize the orbit structure of this action on ℚ ∪ {∞}.

Euler Product for ζ(2) & Coprime Density

Euler's Identity: ζ(2) = Σ 1/n² = ∏_p 1/(1-1/p²) = π²/6, hence the coprime probability 6/π² = ∏_p (1-1/p²). This connects prime distribution to the geometry of coprime pairs.

Product Terms (1-1/p²) for each prime p

Partial Product ∏(1-1/p²) → 6/π²

Partial Sum Σ1/n² → π²/6

Product Error Decay

Sum Error Decay

Probabilistic Interpretation: The probability that a random integer is not divisible by prime p is (1-1/p). For coprimality of two integers, we need both to avoid sharing any prime factor, giving (1-1/p²) per prime. The infinite product over all primes yields 6/π² ≈ 0.6079.
Basel Problem: Euler's proof that Σ1/n² = π²/6 was a landmark result connecting number theory to analysis. The product formula ∏(1-1/p²)⁻¹ = ζ(2) encodes the fundamental theorem of arithmetic into an analytic identity.

Modular Arithmetic Analysis

Residue Class Distribution

Prime Channel Ownership

Farey Neighbors & Mediants

For each fraction, showing its left/right Farey neighbors and their mediant (the next fraction to appear between them as N increases).

3D Sector Cone

Visualizes the density distribution F(s,N) ~ (3/π²)N²/(s(s+1)) as a 3D cone surface. The vertical axis represents sector number s, the radial axis shows N, and the height indicates fraction count. The cone shape reveals how coprime density concentrates in lower sectors and decreases as 1/s².

°
°
°
Presets:
Third axis represents denominator m. Points at height m have coprime numerators r with r/m in the sector range. The cone structure shows density increasing with m².

Hyperbolic Plane / Poincaré Disk

Farey Tessellation: The hyperbolic plane is tessellated by ideal triangles with vertices at Farey fractions on ∂H.
Presets:
Hyperbolic Geometry: Geodesics in the Poincaré disk model are circular arcs perpendicular to the boundary. The Farey tessellation partitions the hyperbolic plane into ideal triangles of equal hyperbolic area π.

Farey Sequence Growth

Ready

Cayley Transform (same map used in Smith charts)

Global Phase Shift α: 90°
Phase Presets (a/b → primitive roots):
Custom a/b: /
Radius Scaling Mode:
Cayley Transform:
Γ = (z - 1)/(z + 1)
• Maps z = R·e^(iθ) → unit disk
• θ = 2πr/M + α (residue angle)
• R=1: pure imaginary axis
• R>1: Cayley-map arcs
• Conformal mapping preserves angles
Real part:
Re(Γ) = (AC + B²)/(C² + B²)
A = R·cos(θ) - 1, B = R·sin(θ)
C = R·cos(θ) + 1
Imaginary part:
Im(Γ) = B(C - A)/(C² + B²)
Special case (R=1):
Γ(θ) = i·tan(θ/2)
Presets:

Cayley Transform (Smith-chart-style map)

Transformed points
Prime moduli
Constant-R
Constant-X

Original z-plane (Pre-transform)

z = R·e^(iθ)
Unit circle

Transform Data

r/mθ (rad)Rz = Re^iθΓ = (z-1)/(z+1)|Γ|

Statistical Analysis

Random vs Actual Distribution

Cross-Sector Correlation

Error Term O(N log N)

Local Density Analysis

Correlation Matrix

Prime Analysis

Overview: This tab explores how prime numbers manifest within the Farey sequence structure. Primes play a special role: for prime p, we have φ(p) = p-1 coprime residues, giving primes maximal density. The distribution of prime denominators across sectors reveals deep connections to the Prime Number Theorem and twin prime conjectures.

Prime Density
π(x) ~ x/ln(x)
Twin Prime Gap
p, p+2 both prime
Euler's φ for prime p
φ(p) = p - 1

Twin Prime Gap Markers

Scatter plot showing Farey gaps where both neighboring denominators are twin primes (p, p+2). The x-axis shows the position in [0,1], y-axis shows gap size. Clusters indicate regions rich in twin prime structure.

Prime vs Composite Moduli

Compares count of fractions with prime denominators (orange) vs composite denominators (purple) in each sector. Prime moduli contribute more fractions per unit since φ(p)/p = 1-1/p is larger for primes.

Prime k-tuple Correlations

Counts prime constellations appearing in Farey denominators: Twin (p, p+2), Cousin (p, p+4), Sexy (p, p+6), and prime triplets. These patterns connect to the Hardy-Littlewood conjectures on prime gaps.

Prime Denominator Density

Shows φ(p) = p-1 for each prime denominator p. This linear growth demonstrates why primes contribute heavily to Farey sequences. The PNT reference line shows expected prime density π(x) ~ x/ln(x).

Twin Prime Gaps in Farey Sequence

Lists Farey neighbors where both denominators form a twin prime pair. Click any pair to hear the interval between them as frequencies. Twin primes create distinctive harmonic relationships due to their close denominators.

Mathematical Background: The distribution of primes among Farey denominators reflects the Prime Number Theorem: π(N) ~ N/ln(N). Twin primes (p, p+2) are conjectured to be infinite (unproven), with density governed by the twin prime constant C₂ ≈ 0.66. The Hardy-Littlewood conjecture predicts ~2C₂N/(ln N)² twin primes up to N. In harmonic terms, prime denominators produce "pure" frequency ratios with fewer overtone conflicts.

Harmonic Analysis & Arnold Tongues

Map Farey fractions to musical frequencies, explore consonance/dissonance, and visualize Arnold tongues

Frequency Ratio
f = f₀ × (p/q)
Consonance Principle
Small q = Pure intervals
Arnold Tongue Width
~ K^q for small K (plot shows schematic K/q)
Hz
Base Note: | Tuning:
PLAYBACK |

Arnold Tongues (Stern-Brocot)

0.60
Unison (q=1)
Consonant (q≤4)
Complex (q≤16)
Dissonant (q>16)

Frequency Spectrum

Frequency bars
Octave lines

Consonance Map

High consonance
Low consonance

Interval Circle (Pitch Class)

Fraction position
12-TET reference

Musical Intervals in Sector

FractionRatioFrequencyCentsClosest NoteInterval NameModePlay
Harmonic Theory: Fractions p/q with small denominators q produce consonant intervals. The ancient Greeks discovered that simple ratios like 2:1 (octave), 3:2 (fifth), and 4:3 (fourth) sound harmonious. Arnold tongues show how these ratios create stable "locking" regions in coupled oscillator systems - wider tongues indicate more robust synchronization.

Primorial Sieve & Farey Sector Connection

Exploring how primorial residue classes connect to Farey sector distribution

Primorial Density
φ(P_k)/P_k = ∏(1-1/p)
Unified Formula
F(s,N,a,k) = [3N²/(π²s(s+1))] · (1/φ(k)) · ∏p|k p/(p+1)
30×2ⁿ Density
φ(30×2ⁿ)/(30×2ⁿ) = 4/15

Sector × Residue Heatmap

Low
Medium
High

Density Constant Verification: φ(k×2ⁿ)/(k×2ⁿ)

Actual φ(m)/m
Constant = φ(P_k)/P_k

Lifting Tree: Residue Class Splitting

Residue class
In sector
Split children

Unified Formula Verification

Actual C(n,N,a,k) — exact count
Predicted [3N²/(π²s(s+1))]·(1/φ(k))·∏p|kp/(p+1)

Prime Distribution Across Residue Classes

Prime count
Expected (uniform)

Sector Uniformity Test

Actual per class
Expected (corrected per-class prediction)

Primorial Comparison: ∏(1−1/p²) → 6/π², φ(P_k)/P_k → 0

φ(P_k)/P_k
∏(1-1/p²) partial
6/π²

Coprime Residue Classes for Current Modulus

Sector × Residue Data Table

SectorTotal (exact)Per Class Avgχ² / χ²₀.₉₅Uniform?
Key Insight: The unified formula F(s,N,a,k) = [3N²/(π²s(s+1))] · (1/φ(k)) · ∏p|k p/(p+1) combines Farey sector distribution with primorial residue filtering. Within each sector the numerators r distribute uniformly across the φ(k) residue classes coprime to k — but not across all k classes, and not with weight F(s,N)/φ(k). Two corrections are needed and both are visible in the charts above. First, only a fraction ∏p|k p/(p+1) of numerators are coprime to k at all: conditioning on gcd(r,m)=1 already biases r away from divisibility, since P(p∤r | gcd(r,m)=1) = (1−1/p)/(1−1/p²) = p/(p+1). For k = 30 that factor is (2/3)(3/4)(5/6) = 5/12, so the naive F(s,N)/φ(k) overshoots by 2.4×. Second, the classes not coprime to k are neither empty nor uniform — their counts depend on gcd(a,k). The density φ(30×2ⁿ)/(30×2ⁿ) = 4/15 does remain constant under power-of-2 scaling, independently of the above.
Every count on this tab is an exact enumeration over 2 ≤ m ≤ N; the χ² column tests uniformity against the observed mean, so it cannot be satisfied by the prediction merely being correct.

Prime-Counting Engine (Lucy_Hedgehog)

Overview: This module implements sublinear algorithms for prime counting and totient summation. Sublinear prime counting. The Lucy_Hedgehog method used here runs in O(x^(3/4)); the O(x^(2/3)) bound belongs to Lagarias–Miller–Odlyzko (1985), a later refinement of Meissel (1870) and Lehmer (1959), and is not implemented on this page. All primality tests use a precomputed sieve for O(1) lookup.

Prime Counting Function pi(x)

Count of primes less than or equal to x using Lucy_Hedgehog/Meissel-Lehmer

Result:
-

Summatory Totient Sum(phi)

Sum of phi(k) for k=1 to n. Asymptotically 3n^2/pi^2

Sum of phi(1) + phi(2) + ... + phi(n):
-

Number Analysis

Analyze a single number: primality, totient, factorization

Enter a number to analyze

Nth Prime

pn = -

Primes in Range

Enter range to list primes

Sieve Statistics & Performance

Sieve Limit
0
Primes Cached
0
Phi Cache
0
Pi Cache
0
Meissel-Lehmer Algorithm

The classic prime counting function pi(x) counts primes up to x. While naive sieving takes O(x) time and space, the Meissel–Lehmer method is sublinear, and the Lagarias–Miller–Odlyzko refinement (1985) achieves O(x^(2/3+ε)) time. Both rest on the identity:

pi(x) = phi(x, a) + a - 1 - P2(x,a) - P3(x,a) - ...
where phi(x,a) counts numbers up to x not divisible by the first a primes, and P_k counts contributions from products of exactly k primes.

This implementation uses Lucy_Hedgehog - a simpler O(x^(3/4)) approach (slower than the full Meissel-Lehmer/LMO method above, which achieves O(x^(2/3))) that maintains running counts V[i] and V[n/i] during a modified sieve process.

Farey Horizon & Mediant Generation

The Mediant Operation

Given two Farey neighbors a/b and c/d, their mediant is:

med(a/b, c/d) = (a+c)/(b+d)

The mediant always lies strictly between its parents and is in lowest terms when the parents are Farey neighbors (|ad - bc| = 1).

Sector Boundaries

Sector Ss = (1/(s+1), 1/s] is bounded by:

  • Left boundary: 1/(s+1)
  • Right boundary: 1/s

The Gatekeeper 2/(2s+1) is the mediant of these boundaries.

Tree Confinement

Key insight: Mediants generated within a sector stay confined to that sector.

If a/b ∈ Ss and we take mediants with the sector boundaries, all descendants remain in Ss.

The Stern-Brocot subtree rooted at the Gatekeeper generates exactly the fractions strictly between the boundaries — that is, Ss ∩ FN minus the right endpoint 1/s, which belongs to Ss but sits on the boundary as an ancestor of the subtree.

Explorer Controls

Boundary
Gatekeeper
Mediant Children

Mediant Generation Tree

Select parameters and click Generate

Fractions in Sector (by value)

-

Research Tools

Custom Formula Tester

Custom vs Standard

Batch Parameter Sweep

N|F_N|Σ|δ|Σ|δ|/√NMax GapMean Gap

Publication Export

References & Acknowledgments

Foundational works and resources underlying this exploration

Classical Number Theory

Euler, Leonhard (1737, 1763)

"Variae observationes circa series infinitas" (1737) - The Euler product formula connecting ζ(s) to the primes. Euler later introduced the totient function φ(n) in "Theoremata arithmetica nova methodo demonstrata" (1763). The coprime-density result 6/π² itself came later, via Dirichlet (1849), Mertens (1874), and Cesàro (1881).

Mertens, Franz (1874)

"Ein Beitrag zur analytischen Zahlentheorie" - Asymptotic formula for the summatory totient function: Σφ(n) = (3/π²)N² + O(N log N). This classical result underlies the interval counting analyzed here.

Farey, John (1816)

Letter to Philosophical Magazine describing the mediant property of Farey sequences. The sequence F_N of fractions p/q with 0 ≤ p ≤ q ≤ N and gcd(p,q) = 1 forms the basis of interval analysis.

Cauchy, Augustin-Louis (1816)

First rigorous proof of the Farey sequence unimodularity (neighbour) property, establishing that between any two adjacent Farey fractions a/b and c/d we have |ad − bc| = 1. Distinct from the mediant property, which concerns (a+c)/(b+d).

Computational Number Theory

Meissel, Ernst (1870) & Lehmer, Derrick Henry (1959)

Development of the Meissel-Lehmer algorithm for computing π(x), the prime counting function, in sublinear time. This work enables efficient computation of prime distributions used in our P/C analysis.

Stern, Moritz (1858) & Brocot, Achille (1861)

Independent discovery of the Stern-Brocot tree, a binary tree structure that generates all positive rationals exactly once in lowest terms. Our tree path visualization and audio playback use this structure.

Harmonic Analysis & Music Theory

Pythagoras (c. 500 BCE)

Discovery that consonant musical intervals correspond to simple rational frequency ratios. The audio features in this tool map Farey fractions to harmonic intervals, connecting number theory to acoustic perception.

Dedekind, Richard (1877)

"Schreiben an Herrn Borchardt über die Theorie der elliptischen Modulfunktionen" - Introduction of the Dedekind eta function and Dedekind sums, connecting modular forms to number theory.

Modern References

Hardy, G.H. & Wright, E.M.

An Introduction to the Theory of Numbers (Oxford University Press) - Comprehensive treatment of Farey sequences, totient function, and continued fractions. Essential reference for theoretical foundations.

Graham, Knuth & Patashnik

Concrete Mathematics (Addison-Wesley) - Detailed treatment of the Stern-Brocot tree and its algorithmic applications.

Original Contributions

Getachew, Wessen (2024-2025)

Exploratory work and visualizations:

  • Interval-Based Analysis: Application of classical summatory function results F(s,N) ~ (3/π²)N²/(s(s+1)) to Farey sequence intervals, building on Mertens' totient summation.
  • Boundary Transition Point: Observation of j* ≈ (√3/π)N ≈ 0.5513N as the point where the predicted count per sector falls below one fraction. This is a resolution limit, not an accuracy boundary: relative error of the asymptotic is O(s²/N) and grows well before s*.
  • Involution Symmetry: The map ι(r/m) = (m−r)/m as a self-inverse pairing on Farey fractions fixing only 1/2, and the sector correspondence it induces.
  • Bisection Identity: |S₁| = |S₂| + |S₃| + … — the first sector contains exactly as many coprime fractions as all remaining sectors combined. An exact integer identity at every N, following from the involution.
  • Exhaustion Structure: For s > N/2 every sector contains exactly one fraction, 1/s, since any numerator a ≥ 2 requires denominator b ≥ 2s > N.
  • Prime/Composite Categorization: Four-way decomposition (PP, PC, CP, CC) with computational analysis of distributions across intervals.
  • Interactive Visualization Framework: Comprehensive tools for exploring interval structure, including ring visualization, tree paths, and harmonic sonification.
  • Computational Verification: Direct enumeration and comparison with classical asymptotic predictions across multiple interval ranges.

Software & Tools

This interactive explorer was developed using:

  • Pure JavaScript for computation and visualization
  • HTML5 Canvas for ring, tree, and chart rendering
  • Web Audio API for harmonic sonification
  • Chart.js for statistical visualizations
  • Custom implementations of Lucy_Hedgehog prime counting, Stern-Brocot tree traversal, and Farey sequence generation

"Mathematics is the music of reason." — James Joseph Sylvester

This work bridges the visual, auditory, and analytical dimensions of number theory.

Farey Sequence Main Explorer - Complete Guide

Comprehensive documentation for all features in the main visualization tool

What is This Tool?

The Farey Sequence Explorer visualizes coprime fractions r/m (where gcd(r,m)=1) organized into sectors based on their denominators. Each sector Sₛ contains fractions in the interval (1/(s+1), 1/s]. The tool computes exact counts, compares them to asymptotic predictions from the Basel problem (6/π²), and analyzes the distribution of prime/composite patterns in number theory.

1. Core Controls (Top Panel)

N Range Selection

  • N Min: Starting denominator (default: 2)
  • N Max: Maximum denominator (default: 100). Higher values = more points but slower computation
  • Compute Button: Generates all coprime fractions r/m where 2 ≤ m ≤ N and gcd(r,m)=1
  • Cancel: Stops long-running computations
  • Export All + 4K: Exports CSV data with high-resolution chart screenshots
  • Auto-play audio: When checked (default ON), clicking points plays their musical interval

Sector Bound Controls

  • Auto-bound: Limits sector analysis to s ≤ constant × N
  • Constants: √3/π ≈ 0.55 (computational boundary), √6/π ≈ 0.78, or 1/π ≈ 0.32
  • Why use it: Asymptotic formulas become less accurate for large n. Boundary=0.55 gives best predictions
  • Manual override: Slider lets you set custom boundary values

2. Main Ring Visualization

How to Read the Ring

  • Geometry: Each fraction r/m is plotted at angle 2π(r/m) on a ring at radius proportional to m
  • Inner rings: Small denominators (m=2,3,4...)
  • Outer rings: Large denominators (approaching N max)
  • Angular position: The fraction's value (e.g., 1/4 at 90°, 1/2 at 180°)
  • Density patterns: More points = more coprime fractions in that sector

Controls & Interaction

  • Sector selector: View individual sectors (1, 2, 3...) or all sectors at once
  • Color modes (30+ options): Basic (sector, prime/composite), Arithmetic (GCD, LCM, r+m), Number Theory (totient, divisor count), Music (harmonic ratios, cents), Pair Properties (PP/PC/CP/CC), Gradients (rainbow, viridis, etc.)
  • Show All Sectors: Toggle to see all fractions or just current sector
  • Point Size: Adjustable 0-20 (0=auto-scales with zoom)
  • Ring Spacing: Multiplier for distance between concentric rings
  • Canvas Size: 800×800 to 4096×4096 for high-resolution exports
  • Zoom/Pan: Scroll to zoom, drag to pan. Zoom controls in top-right corner
  • Click points: Plays audio (if enabled) and shows fraction in bottom-left with flashing effect

3. Advanced Controls (Expandable Panel)

Per-Ring Rotation (Gold Panel)

  • Enable checkbox: Activates rotation
  • Δθ slider: Rotation angle per ring (0-360°)
  • Fraction input: Set rotation as rational multiple of 2π (e.g., 1/12 for 30°)
  • Presets: Quick buttons for common angles (π/12, π/6, π/4, etc.)
  • Effect: Each ring m rotates by m×Δθ, creating spiral/helix patterns

Rendering Options (Blue Panel)

  • Show labels: Display r/m text on points
  • Label limit: Max number of labels to prevent clutter
  • Min denominator: Only label fractions with m ≥ threshold
  • Specific labels: Manually enter fractions like "1/2,3/5" to label exactly
  • Antialias: Smooth rendering (slight performance cost)
  • Background color: Picker for custom background

Filtering (Green Panel)

  • Point filters: Show only prime denominators, composite denominators, prime numerators, or twin prime denominators
  • Min/Max m: Display only fractions with denominators in range
  • Hide m≤5: Quick filter to remove small denominators
  • Reset button: Clear all filters

Animation (Red Panel)

  • Modes: Rotation (continuous spin), Growth (expand from center), Pulse (size oscillation), Wave (radial wave)
  • Speed slider: Animation speed control
  • Loop checkbox: Continuous vs one-shot animation

Audio Playback (Green Panel)

  • Enable Audio: Checkbox to activate (ON by default)
  • Base Frequency: 880 Hz (A5, one octave above A4 standard). Range: 100-1760 Hz
  • How it works: Clicking fraction r/m plays frequency = base × (r/m)
  • Duration slider: Tone length 100-2000ms
  • Musical theory: 1/2 = octave down, 2/3 = perfect fifth, 3/4 = perfect fourth, etc.
  • Visual feedback: Fraction flashes in bottom-left of ring when played

Connection Lines (Purple Panel)

  • Dyadic Powers (r×2ⁿ): Creates cardioid/epicycle patterns by connecting r→2r→4r (mod m)
  • Same Residue: Connects same numerator r across different denominators (vertical projection)
  • Prime Pairs: Links prime denominators separated by 2 (twin), 4 (cousin), or 6 (sexy)
  • Farey Neighbors: Connects fractions where |r₁m₂-r₂m₁|=1 (mediant property)
  • Curved Arcs: Toggle Bézier curves vs straight lines
  • Opacity slider: Line transparency control

Distance Measurement (Gold Panel)

  • Off: Disabled
  • Click Two Points: Click first, then second to display all metrics
  • Select & Hover: Click to anchor one point, hover others for real-time distance
  • Metrics displayed:
    • Euclidean distance on unit circle
    • Angular distance (degrees and radians)
    • Farey distance |r₁/m₁ - r₂/m₂|
    • Determinant |r₁m₂-r₂m₁| (=1 for neighbors)
    • Mediant (r₁+r₂)/(m₁+m₂) if neighbors

4. Statistical Charts

Exact vs Predicted Chart

  • Purpose: Compares actual coprime counts to asymptotic formula 3N²/(π²s(s+1))
  • Green bars: Exact counts from computation
  • Orange line: Predicted values from Mertens formula
  • Play button: Sonifies data (higher count = higher pitch). Shows representative fraction in top-right corner during playback
  • Crossover controls: Navigate/animate points where exact > predicted or vice versa
  • Zoom/Pan: Scroll to zoom, drag to pan chart. Reset button available

Relative Error % Chart

  • Formula: 100 × (Exact - Predicted) / Predicted
  • Positive error: Formula underestimates (green bars above zero)
  • Negative error: Formula overestimates (red bars below zero)
  • Play All: Sonifies error magnitude. Shows representative fraction in bottom-left corner during playback
  • Playback modes: Error magnitude, All fractions in sector, or Representative fraction
  • Click/drag selection: Select range of bars to play specific sectors
  • Zero crossings: Navigate/animate sign flips (over→under prediction transitions)

5. Sector Data Table

  • Click any row: Opens detailed sector analysis modal
  • Columns: Sector s, Interval (1/(s+1), 1/s], Exact count, Predicted count, Error %, P(m) prime denominators, C(m) composite denominators, PP/PC/CP/CC breakdown
  • Decimal precision: Dropdown to adjust display (0-4 decimals)
  • Color coding: Rows highlighted based on error magnitude and sign
  • Export: Button to download table as CSV

6. Mathematical Identities (Bottom Panel)

Sum Identity

  • Formula: Σ(r/m + (m-r)/m) = Total × 1.0
  • Meaning: Each coprime fraction pairs with its complement under involution ι(r/m) = (m-r)/m
  • Status indicator: Shows PASS (green) if sum = 1.0 within tolerance, FAIL (red) otherwise
  • Note: Only exact in floating-point if all sectors included (boundary = 1)

Bisection Identity

  • Formula: |S₁| = |S₂| + |S₃| + ... + |S_max|
  • Meaning: The involution's two unpaired points — the endpoint 1 in S₁ and the fixed point 1/2 in S₂ — sit one on each side, so they cancel and leave exact balance
  • Derivation: ι pairs every other fraction across the two halves. r/m = 1/2 lies in S₂ (S₁ = (1/2, 1] is open at 1/2), so both "loose ends" — 1 ∈ S₁ and 1/2 ∈ S₂ — land on opposite sides and cancel
  • Verification: Computed values shown with PASS/FAIL indicator
  • Boundary requirement: Must have boundary = 1 for identity to hold exactly

7. Screenshot System

  • Canvas size slider: Scale canvas 30-100% in screenshot (smaller = more legend visible)
  • Font controls: Separate paragraph and general font size (default 14px for both)
  • Screenshot button: Captures canvas + comprehensive legend showing all statistics
  • Legend includes: Active color mode, configuration, Basel problem context, visualized Farey pairs, GCD distribution, category definitions (PP/PC/CP/CC), identities, timestamp
  • Word wrapping: Legend text automatically wraps to fit width
  • High-resolution: Works with 4K canvas setting for publication-quality images

Pro Tips & Best Practices

  • Performance: Start with N=100. Use N=1000+ only if needed. Enable boundary slider to limit computation
  • Exploration: Try color mode "PP/PC/CP/CC" to see prime/composite patterns clearly
  • Audio experimentation: Enable Dyadic Powers connections + Audio, click points to see AND hear cardioid patterns
  • Distance verification: Use Farey Neighbors connections + Distance tool to verify mediant property mathematically
  • Boundary insight: Set boundary to 0.55 and compare error charts - formulas work best for n < 0.55N
  • Export workflow: Set canvas to 4K, configure desired visualization, click "Export All + 4K" for publication-ready materials
  • Zoom workflow: Zoom into specific sector, enable labels, screenshot for detailed fraction analysis

Screenshot Preview (with Legend)

📸 Select Canvases to Screenshot
Select canvases to include in screenshot