Mathematics & Fractals
April 2026 · 15 min read · Number Theory · Procedural Generation · Canvas 2D

Golden Ratio & Fibonacci: Phyllotaxis, Continued Fractions & Optimal Spirals

The golden ratio φ ≈ 1.618 appears throughout mathematics, nature, and visual art — not because of mystical properties, but because it is the most irrational number, and irrationality turns out to be exactly what plants need to maximise seed packing. This article explains the deep connections between Fibonacci numbers, continued fractions, phyllotaxis, and logarithmic spirals — and builds an interactive sunflower seed generator.

1. The Fibonacci Sequence

The Fibonacci sequence is defined by the linear recurrence:

F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, ...

Leonardo of Pisa ("Fibonacci") introduced the sequence in 1202 through a rabbit-breeding problem, but the sequence appears in Sanskrit prosody (Virahanka, c. 700 AD) and Pingala's combinatorial analysis (c. 200 BC) more than a millennium earlier. The West rediscovered a pattern that nature had been exploiting for hundreds of millions of years.

Growth Rate

The ratio of consecutive terms converges to φ:

F(n+1) / F(n) → φ as n → ∞ Convergents: 1/1, 2/1, 3/2, 5/3, 8/5, 13/8, 21/13, 34/21, ...

The convergents are alternately above and below φ, oscillating closer with each step. The error is bounded by:

|F(n+1)/F(n) − φ| < 1 / (F(n) · F(n+1)) ≈ φ^(−2n)

This exponential convergence — and the specific error formula — follows directly from the theory of continued fractions developed in the next section.

Identities

Cassini's identity has a beautiful geometric proof via the Fibonacci rectangle dissection: cut a square off a (n+1)×n rectangle, leaving an n×(n−1) rectangle. The identity measures the area mismatch in a 2×2 determinant, and the (−1)ⁿ alternating sign corresponds to the alternating-chirality spiral constructed this way.

2. The Golden Ratio: Algebraic Definition

The golden ratio φ is defined as the positive root of the equation:

φ² = φ + 1 → φ = (1 + √5) / 2 ≈ 1.6180339887...

This equation says that a rectangle with sides φ and 1 remains "golden" (same aspect ratio) after removing a unit square — the defining property of self-similarity. The conjugate root is ψ = (1 − √5)/2 ≈ −0.618, which satisfies ψ² = ψ + 1 as well.

Useful algebraic identities following from φ² = φ + 1:

1/φ = φ − 1 ≈ 0.618... φ² = φ + 1 ≈ 2.618... φ³ = 2φ + 1 ≈ 4.236... φⁿ = F(n)·φ + F(n-1) (in general)

Geometric Mean / Ratio Partition

Dividing a line segment of length 1 + φ into segments of length φ and 1 gives:

(1 + φ) / φ = φ / 1 = φ

This is the "extreme and mean ratio" known to Euclid: the whole is to the larger part as the larger part is to the smaller. This self-referential definition is the key to φ's appearance wherever self-similar growth occurs.

3. Continued Fractions & the Most Irrational Number

Every real number can be represented as a continued fraction:

x = a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + ...))) = [a₀; a₁, a₂, a₃, ...]

Rational numbers have finite continued fractions. Irrational numbers have infinite ones. The convergents (truncated approximations) are the best rational approximations to x with denominator ≤ qₙ.

The golden ratio has the simplest possible continued fraction:

φ = [1; 1, 1, 1, 1, ...] = 1 + 1/(1 + 1/(1 + 1/(1 + ...)))

This follows directly from φ = 1 + 1/φ. Since all partial quotients are 1 (the smallest possible integer > 0), the convergents F(n+1)/F(n) improve as slowly as possible — φ is the hardest real number to approximate by rationals. This is the formal meaning of "most irrational".

Hurwitz's Theorem and Proximity Bound

Hurwitz's theorem states that for any irrational x, infinitely many rational fractions p/q satisfy:

|x − p/q| < 1 / (√5 · q²)

The constant √5 is tight — it cannot be replaced by anything larger while still holding for all irrationals. The only number for which √5 is the precise best constant is φ (and related equivalents). Every other irrational can be approximated to a better constant. This is why φ is the worst case for rational approximation, and why rotation by 1/φ revolutions is the ideal angle for distributing growth on a spiral — no rational sub-harmonics can concentrate density.

4. Binet's Formula & Fast Fibonacci

The closed-form expression for F(n) (Binet 1843, though known to Euler and de Moivre earlier):

F(n) = (φⁿ − ψⁿ) / √5 where φ = (1+√5)/2 and ψ = (1−√5)/2 ≈ −0.618

Since |ψ| < 1, ψⁿ → 0, and F(n) is simply the nearest integer to φⁿ/√5:

F(n) = round(φⁿ / √5) for all n ≥ 0

This allows direct O(1) computation — but only in exact arithmetic. In IEEE 754 double precision the rounding trick fails around n ≈ 75 (when F(75) ≈ 2.1 × 10¹⁵ exceeds the 53-bit mantissa). For large n, the matrix-exponentiation method is exact:

[ F(n+1) ] [ 1 1 ]^n [ F(1) ] [ F(n) ] = [ 1 0 ] · [ F(0) ] // Matrix exponentiation by squaring: O(log n) multiplications

JavaScript Fast Fibonacci (BigInt)

// Fast Fibonacci via doubling identity (O(log n), exact integers)
// F(2n)   = F(n) * (2*F(n+1) - F(n))
// F(2n+1) = F(n)^2 + F(n+1)^2
function fibBig(n) {
  if (n == 0n) return [0n, 1n];           // returns [F(n), F(n+1)]
  const [a, b] = fibBig(n >> 1n);
  const c = a * (2n * b - a);
  const d = a * a + b * b;
  return (n & 1n) === 0n ? [c, d] : [d, c + d];
}

// Usage:
const [f100, _] = fibBig(100n);
console.log(f100.toString());  // 354224848179261915075 (exact)
    

5. Phyllotaxis: Why Plants Count in Fibonacci

Phyllotaxis is the study of the arrangement of leaves, seeds, and petals on a plant. In a sunflower head, seeds are arranged in interlocking spirals. Counting the spirals going clockwise and counterclockwise invariably yields consecutive Fibonacci numbers — typically 34 and 55, or 55 and 89 for large heads.

Why? Each new seed primordia emerges at the tip of the growing meristem and is positioned at an angle from the previous one determined by the divergence angle. The optimal angle — which maximises the minimum distance between any two seeds for all n — turns out to be the golden angle:

golden angle = 2π · (1 − 1/φ) = 2π · (2 − φ) ≈ 137.508° = 360° / φ² ≈ 137.508°

This is not biological speculation: it is a consequence of Hurwitz's theorem. Any rational fraction p/q as a divergence angle would clump seeds into q straight lines (q-fold symmetry). The most irrational angle (1/φ of a full turn) avoids all rational resonances and produces the most uniform filling.

Hofmeister's Hypothesis

The simplest mechanism that produces the golden angle is Hofmeister's rule (1868): each new primordium forms in the largest gap available in the current configuration. Computer simulations (Douady & Couder, 1992) show that this rule, applied iteratively to a disc with radially expanding elements, spontaneously generates the Fibonacci spiral pattern without any pre-programming of Fibonacci numbers — the sequence emerges from the physics of packing.

Fibonacci Spirals in Nature

Myth correction: The nautilus shell's growth ratio is approximately 1.33 per quarter turn, not φ ≈ 1.618. The "golden spiral" drawn over a nautilus photo simply does not fit — the spirals differ. Real golden spirals appear in phyllotaxis, where the mathematics firmly requires them; the nautilus is a coincidence of aesthetic labelling.

6. The Golden Angle & Sunflower Generator

The canonical sunflower seed arrangement: seed n is placed at angle n × 137.508° and radius proportional to √n (uniform area per seed):

θₙ = n · 2π / φ² (radians) rₙ = c · √n (c = scaling constant) x = rₙ · cos(θₙ) y = rₙ · sin(θₙ)
// Sunflower phyllotaxis — Canvas 2D
function drawSunflower(canvas, N = 1000) {
  const ctx   = canvas.getContext('2d');
  const cx    = canvas.width  / 2;
  const cy    = canvas.height / 2;
  const c     = canvas.width  / (2.2 * Math.sqrt(N));
  const PHI   = (1 + Math.sqrt(5)) / 2;
  const angle = 2 * Math.PI / (PHI * PHI);   // golden angle ≈ 2.399 rad

  ctx.fillStyle = '#0a0a14';
  ctx.fillRect(0, 0, canvas.width, canvas.height);

  for (let n = 0; n < N; n++) {
    const theta = n * angle;
    const r     = c * Math.sqrt(n);
    const x     = cx + r * Math.cos(theta);
    const y     = cy + r * Math.sin(theta);

    // Colour by angle fraction for visual spiral reveal
    const hue = (n / N * 360 + 200) % 360;
    ctx.beginPath();
    ctx.arc(x, y, Math.max(1, c * 0.45), 0, Math.PI * 2);
    ctx.fillStyle = `hsl(${hue}, 75%, 60%)`;
    ctx.fill();
  }
}
    

Effect of Divergence Angle

Changing the angle away from 137.508° reveals why it is optimal:

This sensitivity illustrates the extremal property: the golden angle is a narrow optimum, and biological selection pressure has found it reliably across hundreds of millions of years of plant evolution.

7. Logarithmic Spirals & Self-Similarity

A logarithmic spiral (also: equiangular spiral) has the polar equation:

r = a · e^(b·θ) // In Cartesian form: x(t) = a · e^(b·t) · cos(t) y(t) = a · e^(b·t) · sin(t)

Its defining property: the angle between the tangent at any point and the radial line is constant (the "equiangular" property). This angle α satisfies tan(α) = 1/b.

The Golden Spiral

The golden spiral grows by a factor of φ per quarter turn (90°). It arises from the Fibonacci rectangle dissection: each rectangle can be split into a square and a smaller golden rectangle, and a quarter-circle arc in each square approximates the spiral. The exact spiral has:

b = (2/π) · ln(φ) ≈ 0.3063 (growth rate per radian) α = arctan(π / (2·ln(φ))) ≈ 72.97° (equiangular property)

Each complete revolution multiplies the radius by e^(2πb) = φ⁴ ≈ 6.854. A half-revolution multiplies it by φ² ≈ 2.618. A quarter-revolution multiplies it by φ ≈ 1.618 — hence "golden".

Self-Similarity

The logarithmic spiral is the only planar curve that is self-similar under rotation. Rotating by angle θ₀ is identical to scaling by e^(b·θ₀). This means zooming into a logarithmic spiral at the origin while simultaneously rotating produces a stationary image — a property exploited in computer graphics for infinite-zoom fractal animations.

The golden spiral's self-similarity under 90° rotation (scaling by φ per quarter turn) is the reason the Fibonacci rectangle dissection works: each nested square contributes a quarter-turn of the spiral, and the rectangles tile perfectly because consecutive Fibonacci ratios converge to φ.

8. Zeckendorf's Theorem & Fibonacci Coding

Zeckendorf's Theorem

Every positive integer has a unique representation as a sum of non-consecutive Fibonacci numbers (Zeckendorf, 1972):

// Greedy algorithm: repeatedly subtract the largest Fibonacci ≤ remaining 100 = 89 + 8 + 3 ( = F(11) + F(6) + F(4) ) 42 = 34 + 8 ( = F(9) + F(6) ) 19 = 13 + 5 + 1 ( = F(7) + F(5) + F(2) )

The proof of uniqueness relies on the Fibonacci identity F(n) = F(n−1) + F(n−2): if two consecutive F numbers appear in a representation, they can always be merged into the next F — so any representation with consecutive terms can be simplified to one without. Existence follows by induction using the greedy algorithm.

Fibonacci Coding (Data Compression)

Zeckendorf representations enable a universal code for integers:

// Encode n: write its Zeckendorf representation as a bit string // LSB = F(2) bit, MSB = largest Fibonacci used, append a terminator '1' 1 → 1 1 (F(2)=1, plus terminator) 2 → 01 1 (F(3)=2, plus terminator) 4 → 101 1 (F(4)=3? No: 4 = F(5)+F(2) = 3+1, so bits = 1001, terminator = 10011)

Fibonacci coding has the property that it is a self-synchronising code: any occurrence of "11" in the bit stream marks either a codeword boundary or the terminator sequence. After a single bit error, the decoder resynchronises at the next "11" occurrence — a fault-tolerance property not shared by Huffman or arithmetic coding. This makes Fibonacci codes useful for database index compression (used in some versions of PostgreSQL's TOAST compression) and network protocol headers where stream synchronisation matters.

Fibonacci Search

The Fibonacci search algorithm is an alternative to binary search that uses Fibonacci numbers to partition the array, avoiding division and working better on media with non-uniform access costs (e.g. magnetic tape, some SSD layouts):

// Fibonacci search (sorted array arr, target value)
function fibSearch(arr, target) {
  const n = arr.length;
  let fibM2 = 0, fibM1 = 1, fib = 1;        // F(k-2), F(k-1), F(k)
  while (fib < n) { fibM2 = fibM1; fibM1 = fib; fib = fibM1 + fibM2; }

  let offset = -1;
  while (fib > 1) {
    const i = Math.min(offset + fibM2, n - 1);
    if (arr[i] < target)      { fib = fibM1; fibM1 = fibM2; fibM2 = fib - fibM1; offset = i; }
    else if (arr[i] > target) { fib = fibM2; fibM1 -= fibM2; fibM2 = fib - fibM1; }
    else return i;
  }
  if (fibM1 && arr[offset + 1] === target) return offset + 1;
  return -1;
}
    
The bigger picture: The connections in this article — Hurwitz's theorem → golden angle → Fibonacci spirals → Zeckendorf coding — are not coincidences. They all trace back to the single fact that φ is the simplest continued fraction [1;1,1,1,...]. The mathematics of optimal packing, number theory, and data compression share a common root in the irrationality of φ.