Farey Modular Residue Rings

An Interactive Visualization of Modular Arithmetic, Prime Structure, and the Farey Sequence

The Unit Circle & Its Many Faces

A unit circle is the set of points satisfying x² + y² = 1 — but the same parameters (radius = 1, circumference = 2π, rotation θ ∈ [0, 2π)) manifest in many different geometric shapes and coordinate systems. Think of it as the same mathematical object viewed through different lenses. The Farey modular residue rings visualized here are precisely one such lens: the classical circle becomes a discrete, modular shell system — and the structures below illuminate why this connection is so deep.

§ 1
Square / Wave Strip (Fourier View)
Unwrapping the angle parameter θ maps the circle into a rectangular strip. Plotting cos θ and sin θ against θ transforms the closed curve into two interleaved waves inside a bounded rectangle — exactly how Fourier analysis encodes periodicity. x = cos θ,  y = sin θ,  θ ∈ [0, 2π) Circle → sine/cosine waves in a strip.
§ 2
Complex Exponential
In the complex plane every number of magnitude 1 lies on the unit circle, forming the multiplicative group |z| = 1. The circle collapses into a single elegant formula that turns geometry into rotation algebra. z = e Circle → complex exponential rotation.
§ 3
Polygon Approximation
A circle is the limiting case of regular n-gons as n → ∞. Triangle, square, hexagon, 1000-gon — all with vertices on radius 1. This is a direct bridge to the discrete shells in the Farey residue visualizer. limn → ∞ regular n-gon = circle
§ 4
Diamond (L¹ / Manhattan Metric)
Changing the distance rule changes the shape of the unit "circle." Under the Manhattan (L¹) metric the locus of points at distance 1 from the origin is a square rotated 45° — a diamond. |x| + |y| = 1
§ 5
Square (L∞ / Chebyshev Metric)
Under the Chebyshev (L∞) metric — where distance is the maximum of the coordinate differences — the unit circle becomes an axis-aligned square. The geometry of distance determines the shape of roundness. max(|x|, |y|) = 1
§ 6
Cylinder / Rectangle (Unwrapped)
Cutting the circle at θ = 0 and unrolling it produces a line segment of length 2π. Adding a height dimension yields a cylinder. This is precisely the π × 2π rectangle picture — a circle with wrapped edges. Circle ↔ rectangle with identified edges
§ 7
Modular Number Line (ℝ/ℤ)
The real numbers modulo 1 wrap the number line into a circle: 0 and 1 become the same point, and every real number maps to an angle θ = 2πx. This is the algebraic foundation of the modular residue geometry shown here. ℝ/ℤ → unit circle,  θ = 2πx
§ 8
Real Line via Stereographic Projection
Stereographic projection from the north pole maps every point on the circle to a unique real number — except the pole itself, which corresponds to a "point at infinity." Used extensively in complex analysis. Circle ↔ ℝ ∪ {∞}
§ 9
Lattice Shell View
Scaling the unit circle by integer radii produces concentric shells of integer lattice solutions to x² + y² = r². Counting such representations connects to the Gauss circle problem and Dirichlet's divisor theory — and the modular shell work here is a discrete, modular version of exactly this. x² + y² = r²,  r ∈ ℤ
§ 10
Fourier Frequency Circle
In digital signal processing the unit circle in the z-plane represents all possible frequencies. Stability, filtering, and spectral analysis all read off the circle — connecting time-domain signals to circular frequency space. z = e,  ω ∈ [0, 2π)
Geometry / System Shape of "Unit Circle" Key Equation
EuclideanCirclex² + y² = 1
Manhattan (L¹)Diamond|x| + |y| = 1
Chebyshev (L∞)Squaremax(|x|,|y|) = 1
Polygon limitRegular n-gon → circlen → ∞
Complex / FourierExponential rotationz = e
Topology (mod 1)Wrapped number lineℝ/ℤ
Lattice shellsInteger ringsx² + y² = r²
Modular residuesDiscrete Farey ringsr/m ∈ Farey(N)
⭐ The Deeper Idea
A circle is fundamentally just a periodic parameter. Any mathematical structure with the periodicity θ ~ θ + 2π can be interpreted as — or placed in correspondence with — a unit circle. The Farey modular residue rings explored in this tool are a discrete, arithmetic instantiation of that same periodicity: the angle becomes a reduced fraction r/m, the ring becomes a modular shell, and the Farey sequence organises the shells in exactly the way that uniform angle spacing organises the classical circle. θ ~ θ + 2π  ⟺  r/m ~ r/m + 1
◆ Unit Circle Presets
: MOD N | GAP
|
■ View & Color
LABEL MODE
LABEL SCOPE
LABEL STYLE
LABEL SIZE
7
POINT COLOR MODE
gcd=1
gcd>1
CANVAS SIZE
Y
px
X
px
■ Ring Geometry
RING SPACING
RING SCALE
INNER RADIUS
Z
POINT SIZE
■ Connections
SHOW CHORDS
THICKNESS
ANGLE DIRECTION
■ Per-Ring Rotation
PER-RING CUMULATIVE ROTATION
STEP a/b
/ × 360°
DIRECTION
AUTO-ROTATE SPEED
100
DYNAMICS
CONTROLS
RING POLYGON
POINTS TO CONNECT
WHICH RINGS
SAME-MOD LINE COLOR
SAME-MOD THICKNESS
0.75
CROSS-MOD THICKNESS
3.0
LIFT LINE THICKNESS
1.2
gcd(r, m) = 1
gcd(r, m) > 1
■ Residue N-Body Orbits — prime or element bodies
Decimal Places 6 |
■ Ring Radii & Areas
■ GCD(R, M) = 1  ·  Coprime
■ GCD(R, M) > 1  ·  Non-Coprime
■ What This Shows

Each rational r/m with 0 ≤ r ≤ m, 1 ≤ m ≤ N is placed at angle 2πr/m on ring m. Blue points satisfy gcd(r,m)=1 — these are the Farey fractions. By the Franel-Landau theorem, if the Farey discrepancy DN fails to decay at the rate O(N−½ log N), then ζ(s) has a zero off the critical line. The observed near-uniformity at finite N is consistent with RH; it is not a proof of it. Red points (gcd(r,m)>1) are the composite residues; they sit at angles 2πr/m where r and m share a common factor, concentrating at rational multiples of 2π that correspond to the divisor structure of m.

The cross-mod connections follow residue r across rings N→1, tracing the channel each residue class cuts through the modular hierarchy. The ring polygon connects consecutive residues on a single ring: mod 4 with all points gives a square; gcd=1 only at mod 4 leaves r=1 and r=3, a diameter. At mod 8 with gcd=1, the units 1,3,5,7 form a square — the polygon degree drops from 8 to 4 because only the reduced residues remain.

The gap overlay marks the pairs (p mod N, (p+g) mod N) for primes with forward gap exactly g. Outer-ring chords show which residue classes carry twin, cousin, or sexy prime pairs. The inward spiral traces the full cross-mod ancestry of each endpoint back through rings N→1.

Rational Unit Circle

Roots of unity, coprimality, and Farey structure

§1 — Roots of Unity

Each rational r/m is placed on ring m at angle θ = 2πr/m, corresponding to the m-th roots of unity

These points form a regular m-gon on the unit circle. The full structure across all rings 1 ≤ m ≤ N is a modular lattice on concentric circles.

§2 — The Unit Group

The multiplicative units modulo m are the residues coprime to m:

Their count is Euler’s totient φ(m). These are the Farey fractions — the blue points in the visualiser. They define the primitive angular directions not eliminated by the divisibility structure of m.

§3 — Modular Hierarchy

Each modulus generates a regular polygon. The primorial sequence eliminates composite directions one prime at a time:

What remains after each step are exactly the angular rays where primes can occur. Use the hierarchy navigator below to walk through each level interactively.

§4 — Prime Residue Rays

All primes greater than p must lie on the unit-group rays of the primorial modulus M = 2·3·…·p:

For M=30 this gives 8 rays; for M=210, 48 rays. The gap overlay marks which pairs carry twin primes (gap=2), cousin primes (gap=4), or sexy primes (gap=6).

§5 — Twin Prime Geometry

Twin prime candidates (p, p+2) correspond to residue pairs (r, r+2) both coprime to M. Their angular separation on ring m is:

As M grows through primorial extensions, admissible twin-prime ray pairs lift to the refined lattice. The candidate directions are preserved through sieve refinement — visible as parallel chord pairs in the gap overlay.

§6 — Farey Discrepancy & RH

By the Franel–Landau theorem, the Riemann Hypothesis is equivalent to the Farey discrepancy satisfying:

The near-uniform angular distribution visible at finite N is consistent with RH. It is not a proof — only a geometric shadow of the analytic statement.

§7 — Density & Sieve Thinning

The proportion of primitive residues mod m decays to zero by the Euler product:

The lattice refines as m grows while allowed directions simultaneously thin — a precise quantification of prime sparsity. Averaged over all m ≤ N this density converges to 6/π² = 1/ζ(2). The hierarchy navigator tracks φ(N)/N live.

§8 — Laurent Annuli & Partial Fractions

The ring structure is the discrete skeleton of a Laurent series. For a rational function with poles at coprime prime residues r₁,r₂,… mod N, the complex plane splits into annular convergence regions — one per gap between consecutive pole radii.

gcd(r,m)=1 points are independent Laurent terms: irreducible partial fractions that generate new series coefficients. gcd(r,m)>1 points are reducible — they collapse to lower-denominator rings, contributing no new terms, exactly as reducible fractions cancel in partial fraction decomposition. The 6/π² coprime density is therefore also the fraction of independent Laurent basis elements across all rings.

The N-body panel uses these same rₖ as orbit positions — bodies in the annular band between poles. Use the explorer below to see the decomposition live as you change N.

■ Laurent Explorer — live with mod N slider
Poles — coprime primes mod N
Annuli (inner / annulus / outer)
Partial fraction decomposition

§9 — Riemann’s Explicit Formula

The exact prime counting function is given by the explicit formula, where each nontrivial zero ρ = ½ + iγn of ζ(s) contributes one oscillatory correction:

Each conjugate pair ρ, ρ¯ produces a real cosine wave of frequency γn log x. Your Farey discrepancy DN measures whether these oscillations stay bounded — the Franel–Landau equivalence to RH. The N-body panel places bodies at the residue positions rk = pk mod N, which are the discrete analog of the xρ phase evaluations. Each conjugate zero pair (γn, −γn) mirrors the (r, N−r) mirror involution on your coprime ring.

■ Explicit Formula Explorer
K zeros x =
First K zeros ρ = ½ + iγn
Formula terms at x
◆ Modular Hierarchy — click to navigate
φ(N)/N =
φ(N)/N
0