Research-Stack/docs/experiment_compression_metric.md
Allaun Silverfox 13a1683b8e experiment(radial): 5-domain expert design — self-finding on S⁷
The experiment: use the Φ-corkscrew system to search its own manifold
for the direction that maximizes compression ratio. 5 domain experts
designed their components in parallel.

EXPERIMENT: EXPERIMENT_RADIAL_SELF_FIND.md
  - Hypothesis: ∃ d* on S⁷: walking γ_{d*} monotonically increases C(n)
  - Method: Self-referential geodesic search with radial exploration
  - Predictions: gradient exists, ascent converges, self-encoding helps

AGENT 1 — GeometricPhysicist: experiment_geodesic_search.md
  - Geodesic: γ_d(t) = cos(t)·x + sin(t)·d (great circles on S⁷)
  - Gradient ascent: exponential map + parallel transport
  - Direction sampling: uniform, Φ-guided, gradient-biased
  - 3 core functions: geodesic_search, gradient_ascent_step, sample_directions

AGENT 2 — InformationTheorist: experiment_compression_metric.md
  - C(n) = L_S / |RLE(DNA(phinary(n)))|
  - Bounds: Ω(L_S/log n) ≤ C(n) ≤ O(L_S/log log n)
  - Key insight: phinary constraint inherently favors compressibility
  - Entropy H(n), Kolmogorov K(n), spectral radius analysis

AGENT 3 — SystemsEngineer: experiment_feedback_loop.md (2,033 lines!)
  - 12-state, 15-transition state machine
  - 3-layer strange loop containment (bounded, contractive, depth cap)
  - Radial exploration: OUTWARD/INWARD/OSCILLATE modes
  - Full FAMM-DAG integration with meltdown recovery
  - 7 convergence criteria

AGENT 4 — FormalVerifier: experiment_formal_verification.md
  - 8 Lean 4 theorems + master theorem
  - Key: Bijection Preservation (search transform preserves injectivity)
  - Paradox Prevention theorem (self-referential safety)
  - 10 invariants, 5 verification conditions
  - Integrates with ChentsovFinite.lean, quine.py proofs

AGENT 5 — MetaMathematician: experiment_meta_analysis.md
  - Strange loop converges (C(n) is Lyapunov function, S⁷ compact)
  - Fixed points exist (Brouwer + Kleene recursion theorem)
  - Gödel boundary is epistemological, not ontological
  - System finds itself but cannot prove global optimality
  - 12 formal theorems

Total: 6 files, ~6,000 lines of experiment design

Refs: PHI_CORKSCREW_PERFECT_RECOVERY.md, PROOF_SELFSIGHT.md,
ChentsovFinite.lean, GoldenSpiralManifold.lean
2026-06-23 02:13:42 -05:00

31 KiB
Raw Blame History

COMPRESSION METRIC C(n) — Formal Specification

for the Radial Self-Finding Experiment


1. Notation and Preliminaries

Symbol Definition
φ Golden ratio = (1 + √5) / 2 ≈ 1.6180339887...
ψ Golden angle = 2π / φ² rad ≈ 2.39996 rad = 137.5077...°
Natural numbers {0, 1, 2, ...}
Σ_DNA DNA alphabet = {A, B, C, G, P, S, T, Z}, |Σ_DNA| = 8
n Spiral index ∈ , the integer being encoded
r = √n Spiral depth (radial coordinate)
L_S Original state size in bits (e.g., 30 GB × 8 = 240 Gbit for LLM KV cache)

Phinary Representation

Definition 1.1 (Phinary / Base-φ). The phinary representation of a positive integer n is the unique sequence P(n) = (p₀, p₁, ..., p_{k-1}) with pᵢ ∈ {0, 1} such that:

n = Σᵢ pᵢ · φⁱ     (value equation)
pᵢ · pᵢ₊₁ = 0      ∀ i     (no consecutive 1s — standard form)

Lemma 1.2 (Uniqueness). The phinary standard form is unique for every n ∈ . Proof. This is the well-known uniqueness theorem for base-φ representations. The absence of consecutive 1s eliminates the identity φⁱ = φⁱ⁻¹ + φⁱ⁻² (Fibonacci relation), ensuring no two distinct digit strings evaluate to the same integer. ∎

Lemma 1.3 (Length bound). The length of P(n) satisfies:

⌊log_φ(n)⌋ ≤ |P(n)| ≤ ⌈log_φ(n)⌉ + 1

Proof. Since φᵏ ≤ n < φᵏ⁺¹ implies k ≤ log_φ(n) < k+1, and the highest non-zero digit is at position ⌊log_φ(n)⌋. The +1 accounts for the standard-form constraint which may push the representation one digit longer. ∎

Corollary 1.4. |P(n)| = Θ(log n) with base φ.


2. The Compression Pipeline

The compression pipeline is a composition of four functions:

C(n) = L_S / |RLE(DNA(phinary(n)))|

Pipeline:  n ──phinary──► P(n) ──dna_encode──► D(n) ──rle──► R(n)
                           {0,1}*            Σ_DNA*        compressed

2.1 Step 1: phinary(n) → P(n)

Function: phinary: → {0, 1}*

Input: integer n ≥ 0 Output: phinary digit string P(n) = (p₀, p₁, ..., p_{k-1})

Algorithm (greedy standard form):

def phinary(n: int) -> list[int]:
    """Convert n to phinary standard form (digits 0 or 1, no consecutive 1s)."""
    if n == 0:
        return [0]
    
    # Precompute Fibonacci numbers F[2]=1, F[3]=2, F[4]=3, F[5]=5, ...
    fib = [1, 2]  # F[2], F[3]
    while fib[-1] <= n:
        fib.append(fib[-1] + fib[-2])
    fib.pop()  # remove overflow
    
    digits = []
    remaining = n
    for f in reversed(fib):
        if remaining >= f:
            digits.append(1)
            remaining -= f
        else:
            digits.append(0)
    
    return digits   # most-significant-digit first

Key property: phinary(n) uses the Fibonacci number system (Zeckendorf representation), which is isomorphic to phinary standard form via the substitution φⁱ ↔ F_{i+2}.

Output properties:

  • P(n) ∈ {0, 1}ᵏ where k = |P(n)|
  • No two consecutive 1s
  • P(n) is a prefix code (self-delimiting by construction)

2.2 Step 2: dna_encode(P(n)) → D(n)

Function: dna_encode: {0, 1}* → Σ_DNA*

Maps binary phinary digits to the 8-symbol DNA alphabet by grouping bits.

Algorithm:

DNA_ALPHABET = ['A', 'B', 'C', 'G', 'P', 'S', 'T', 'Z']  # 8 bases

def dna_encode(phinary_digits: list[int]) -> str:
    """Map phinary digit string to DNA sequence."""
    # Pad to multiple of 3 bits
    padded = phinary_digits.copy()
    while len(padded) % 3 != 0:
        padded.append(0)
    
    dna = []
    for i in range(0, len(padded), 3):
        triplet = (padded[i] << 2) | (padded[i+1] << 1) | padded[i+2]
        dna.append(DNA_ALPHABET[triplet])
    
    return ''.join(dna)

Output: D(n) ∈ Σ_DNA^L where L = ⌈|P(n)| / 3⌉.

Mapping table:

Triplet (b₂b₁b₀) DNA Base Name
000 A Adenine-like
001 B Bromouracil-like
010 C Cytosine-like
011 G Guanine-like
100 P Purine-like
101 S Strong-binding
110 T Thymine-like
111 Z Zero/depth

2.3 Step 3: rle(D(n)) → R(n)

Function: rle: Σ_DNA* → ({0, 1} × Σ_DNA × )*

Run-length encoding with adaptive format selection.

Algorithm:

def rle(dna: str) -> list[tuple[str, int]]:
    """Run-length encode DNA sequence.
    
    Format: sequence of (base, run_length) pairs.
    Uses flag bit: if run_length == 1, omit length (save 1 bit).
    """
    if not dna:
        return []
    
    runs = []
    current_base = dna[0]
    current_run = 1
    
    for base in dna[1:]:
        if base == current_base:
            current_run += 1
        else:
            runs.append((current_base, current_run))
            current_base = base
            current_run = 1
    runs.append((current_base, current_run))
    
    return runs

def rle_bit_size(runs: list[tuple[str, int]], max_run_length: int) -> int:
    """Compute bit size of RLE encoding."""
    bits = 0
    for base, length in runs:
        bits += 3   # base identifier (3 bits for 8 bases)
        if length == 1:
            bits += 1   # flag: single (0)
        else:
            bits += 1   # flag: run (1)
            bits += ceil(log2(max_run_length + 1))  # run length
    return bits

Smart RLE (only compress when beneficial):

def smart_rle(dna: str) -> tuple[list, bool]:
    """Apply RLE only if it reduces size."""
    runs = rle(dna)
    rle_bits = rle_bit_size(runs, len(dna))
    raw_bits = len(dna) * 3  # 3 bits per base
    
    if rle_bits < raw_bits:
        return (runs, True)   # compressed
    else:
        return (dna, False)   # raw (no benefit)

2.4 Full Pipeline (Pseudocode)

def compression_ratio(n: int, original_size_bits: int) -> float:
    """Compute C(n) = compression ratio for spiral index n."""
    
    # Step 1: Phinary representation
    P = phinary(n)                          # list of {0,1}
    
    # Step 2: DNA encoding (3 bits → 1 base)
    D = dna_encode(P)                       # string over Σ_DNA
    
    # Step 3: Smart run-length encoding
    R, was_compressed = smart_rle(D)        # compressed representation
    
    # Step 4: Compute sizes
    compressed_bits = rle_bit_size(R, len(D)) if was_compressed else len(D) * 3
    
    # Step 5: Compression ratio
    C = original_size_bits / compressed_bits
    
    return C

3. Formal Definition of C(n)

3.1 Component Functions

Definition 3.1 (Phinary length).

_P(n) := |phinary(n)| = number of phinary digits of n

Definition 3.2 (DNA sequence length).

_D(n) := ⌈_P(n) / 3⌉ = number of DNA bases

Definition 3.3 (Run count). Let D(n) = d₀ d₁ ... d_{_D-1}. Define the run count:

r(n) := 1 + |{i ∈ {0, ..., _D-2} : dᵢ ≠ dᵢ₊₁}|
       = number of maximal runs of identical bases in D(n)

Definition 3.4 (Compressed size). Let r(n) be the number of runs and let L_max(n) = max run length. The compressed size in bits is:

|rle(D(n))| = r(n) · [3 + 1 + ⌈log₂(L_max(n) + 1)⌉]   if RLE beneficial
            = 3 · _D(n)                                otherwise (raw)

Simplifying (using the smart RLE convention):

|rle(D(n))| = min( 3·_D(n),  r(n)·[4 + ⌈log₂(_D(n) + 1)⌉] )

Definition 3.5 (Compression metric).

                    L_S                          L_S
C(n) := ──────────────────────── = ─────────────────────────────
        |rle(DNA(phinary(n)))|     min(3·_D, r(n)·[4 + ⌈log₂(_D+1)⌉])

where L_S is the original state size in bits (a constant for the experiment).


4. Proof of Bounds: C_min ≤ C(n) ≤ C_max

4.1 Upper Bound (Maximum Compression)

Theorem 4.1 (C_max). For any spiral index n ≥ 0:

                    L_S
C(n) ≤ ──────────────────────────
       4 + ⌈log₂(_D(n) + 1)⌉

with equality when r(n) = 1 (all DNA bases identical).

Proof. The minimum compressed size occurs when all DNA bases are the same, giving exactly one run: r(n) = 1. Each run costs 4 + ⌈log₂(_D+1)⌉ bits (3 for base + 1 flag + log for length). With one run:

|rle(D(n))| = 4 + ⌈log₂(_D(n) + 1)⌉

This is the smallest possible non-trivial encoding. Therefore:

         L_S                           L_S
C(n) ≤ ─────────────── ≤ ──────────────────────────
         |rle|_min        4 + ⌈log₂(_D(n) + 1)⌉

For large n, _D(n) ~ log_φ(n)/3, so:

C_max(n) ~ L_S / log₂(log_φ n) = L_S / O(log log n)

This is extremely large but finite for any finite n. ∎

Corollary 4.2. For the LLM KV cache (L_S = 240 Gbit):

  • If _D = 10⁶: C_max ≈ 240×10⁹ / 24 ≈ 10¹⁰
  • If _D = 10¹²: C_max ≈ 240×10⁹ / 40 ≈ 6×10⁹

4.2 Lower Bound (Minimum Compression)

Theorem 4.3 (C_min). For any spiral index n ≥ 0:

           L_S
C(n) ≥ ───────────
       3 · _D(n)

with equality when RLE provides no benefit (all runs of length 1, or smart RLE falls back to raw).

Proof. The maximum compressed size (minimum compression) occurs when every DNA base differs from its neighbors, giving r(n) = _D(n) runs of length 1. In this case, smart RLE falls back to raw encoding at 3 bits per base:

|rle(D(n))| = 3 · _D(n)

Therefore:

         L_S                L_S
C(n) ≥ ─────────── = ───────────────────
       3·_D(n)      3·⌈_P(n)/3⌉

Using _P(n) ≤ ⌈log_φ(n)⌉ + 1 from Lemma 1.3:

           L_S
C(n) ≥ ──────────────────────
       log_φ(n) + O(1)

This lower bound decreases as n increases. ∎

4.3 Combined Bound Theorem

Theorem 4.4 (Bounds on C(n)). For all n ≥ 2:

           L_S                                 L_S
─────────────────────────  ≤  C(n)  ≤  ──────────────────────────
3 · ⌈(⌈log_φ(n)⌉ + 1) / 3⌉            4 + ⌈log₂(⌈log_φ(n)/3⌉ + 1)⌉

Or more compactly:

      Ω(L_S / log n)  ≤  C(n)  ≤  O(L_S / log log n)

Proof. Direct combination of Theorems 4.1 and 4.3 with Lemma 1.3 for _P(n). ∎

4.4 Asymptotic Behavior

Theorem 4.5 (Asymptotic envelope). As n → ∞:

C(n) ∈ [ L_S / Θ(log n),  L_S / Θ(log log n) ]

The exact value depends on the run structure of D(n), not just its length.

Corollary 4.6. For a "random" spiral index (uniform in [0, N]):

  • Expected r(n) ≈ _D(n) · (7/8) (since 7/8 of transitions change the base)
  • Expected C(n) ≈ L_S / Θ(log n) (near the lower bound)

Proof sketch. For random _D bases from 8 symbols, the probability that dᵢ = dᵢ₊₁ is 1/8. So expected runs = _D · (7/8) + O(1), giving near-worst-case compression. ∎


5. Gradient Analysis: ∇_n C(n)

5.1 What Makes C(n) Increase?

Since C(n) = L_S / |R(n)|, maximizing C(n) is equivalent to minimizing |R(n)|, the compressed size.

The compressed size is:

|R(n)| = min( 3·_D(n),  r(n)·[4 + ⌈log₂(_D(n)+1)⌉] )

Therefore C(n) increases when:

Factor Effect on C(n) Mechanism
r(n) ↓ (fewer runs) ↑ C(n) Longer runs → better RLE
_D(n) ↓ (shorter DNA) ↑ C(n) Fewer bases to encode
Run lengths become more uneven ↑ C(n) One very long run + many short ones is better than uniform runs
r(n) = 1 (single run) ↑↑ C(n) Maximum: one base repeated _D times

5.2 Discrete Gradient

Define the forward difference:

ΔC(n) := C(n + 1) - C(n)

Lemma 5.1 (Gradient sign from run changes). Let Δr = r(n+1) - r(n) and Δℓ = _D(n+1) - _D(n). Then:

ΔC(n) > 0  ⟺  |R(n+1)| < |R(n)|
           ⟺  the encoding of n+1 has better compressibility

Cases:

  1. If _D(n+1) = _D(n) and r(n+1) < r(n): then C(n+1) > C(n)
  2. If _D(n+1) > _D(n) but r(n+1) ≪ r(n): C may still increase
  3. If _D(n+1) = _D(n) and r(n+1) > r(n): then C(n+1) < C(n)

5.3 Continuous Relaxation (for Gradient Ascent)

To make C(n) differentiable, define a soft version on ℝ⁺:

Definition 5.2 (Soft compression metric). For x ∈ ℝ⁺:

C̃(x) = L_S / |R̃(x)|

where |R̃(x)| is a smoothed approximation using sigmoid transitions:

̃_D(x) = ⌈log_φ(x)⌉ / 3                         (interpolate between integer lengths)

r̃(x) = ̃_D(x) / L̄_run(x)                        (estimated run count)

L̄_run(x) = 1 + Σᵢ₌₁^{̃_D-1} σ(δ · sim(dᵢ, dᵢ₊₁))   (soft run count)

where σ(z) = 1 / (1 + e⁻ᶻ) is the sigmoid
      sim(dᵢ, dⱼ) = 1 if dᵢ = dⱼ, 0 otherwise
      δ > 0 is a steepness parameter

Theorem 5.3 (Differentiability). C̃(x) is differentiable on ℝ⁺ {φᵏ : k ∈ } (all points except phinary length boundaries).

Proof. ̃_D(x) is piecewise constant with jumps at x = φᵏ. Between jumps, ̃_D is constant and r̃(x) depends smoothly on the digit similarities. The sigmoid σ is C^∞, so the composition is differentiable. ∎

5.4 Gradient on the Manifold

In the experiment, we optimize over directions d on S⁷, not directly over n. The chain rule gives:

∇_d C = ∂C/∂n · ∂n/∂d

where:

  • ∂C/∂n is the discrete derivative (or ∂C̃/∂x for the soft version)
  • ∂n/∂d comes from the spiral index mapping:
n(d) = argminₙ ||f(n) - γ_d(t)||²

∂n/∂d ≈ - (∂²/∂n² ||f(n) - γ_d(t)||²)⁻¹ · (∂/∂n ∂/∂d ||f(n) - γ_d(t)||²)

Practical gradient ascent:

def gradient_ascent_step(S_current, directions, step_size, original_size):
    n_current = spiral_index(S_current)
    C_current = compression_ratio(n_current, original_size)
    
    best_direction = None
    best_gradient = 0
    
    for d in directions:
        # Walk a small step along geodesic
        S_next = geodesic_step(S_current, d, epsilon)
        n_next = spiral_index(S_next)
        C_next = compression_ratio(n_next, original_size)
        
        # Estimate directional derivative
        grad_d = (C_next - C_current) / epsilon
        
        if grad_d > best_gradient:
            best_gradient = grad_d
            best_direction = d
    
    return best_direction, best_gradient

6. Information-Theoretic Measures

6.1 Shannon Entropy H(n)

Definition 6.1 (Empirical entropy of DNA encoding). For spiral index n with DNA encoding D(n) = (d₀, ..., d_{_D-1}):

H(n) = - Σ_{b ∈ Σ_DNA} p_b · log₂(p_b)     bits/symbol

where p_b = (1/_D) · |{i : dᵢ = b}| is the empirical frequency of base b.

Properties:

  • 0 ≤ H(n) ≤ log₂(8) = 3 bits/symbol
  • H(n) = 0 iff D(n) uses only one base (r(n) = 1)
  • H(n) = 3 iff all 8 bases appear equally often

Connection to compression:

H(n) ≈ 3   →  poor compressibility  →  C(n) ≈ C_min
H(n) ≈ 0   →  excellent compressibility →  C(n) ≈ C_max

6.2 Kolmogorov Complexity K(n)

Definition 6.2 (Kolmogorov complexity). K(n) is the length of the shortest program (in a fixed universal language) that outputs n and halts.

Upper bound via compression pipeline:

K(n) ≤ |RLE(DNA(phinary(n)))| + |decoder| + O(1)

where |decoder| is the constant size of the decompression program (~few hundred bytes).

Theorem 6.3 (Compression pipeline as upper bound).

K(n) ≤ r(n) · [4 + ⌈log₂(_D(n) + 1)⌉] + O(1)

This means the RLE-compressed DNA encoding is a valid upper bound on Kolmogorov complexity. When C(n) is large, the encoding captures significant structure in n (low K(n) relative to log n).

6.3 Self-Delimiting Code Length

Definition 6.4 (Prefix-free encoding length). The self-delimiting length:

L*(n) = |phinary(n)| + 2·log₂|phinary(n)| + O(1)

This is the length when encoding n with a prefix-free code (prepend the length of the phinary representation, encoded in prefix-free form).

Theorem 6.5 (Expected K(n) for random n). For n uniformly random in [1, N]:

E[K(n)] = log₂ N + O(1)

and with high probability, K(n) ≈ log₂ N (incompressible).

6.4 Mutual Information with Spiral Structure

Definition 6.6 (Spiral-phase information). The golden angle ψ creates structure in the mapping n → (r, θ). Define the phase of n:

θ(n) = n·ψ mod 2π

The mutual information between n and its phase:

I(n : θ(n)) = H(θ(n)) - H(θ(n) | n)

Since θ(n) is deterministic given n, H(θ(n) | n) = 0, so I(n : θ(n)) = H(θ(n)).

For large n, θ(n) is uniformly distributed on [0, 2π) (by Weyl's equidistribution theorem, since ψ/2π is irrational). Thus H(θ(n)) → log₂(2π) in the continuous limit.


7. Spiral Depth vs. Compressibility

7.1 The r = √n Relationship

The spiral depth r = √n determines how "far out" on the corkscrew the index lies. The relationship between depth and compressibility is nuanced:

Depth regime        r range           _P(n) ~ log_φ(n)      Compressibility
─────────────────────────────────────────────────────────────────────────────
Shallow             r < 10            < 10 digits           Low (too short)
                    (n < 100)

Structured          10 ≤ r < 10⁶      1050 digits          HIGH (best regime)
                    (100 ≤ n < 10¹²)                       Phinary patterns emerge

Deep                r ≥ 10⁶           > 50 digits           Medium
                    (n ≥ 10¹²)                               Randomness dominates

Extreme             r ≥ 10²⁵          > 150 digits          Low (near-random)
                    (n ≥ 10⁵⁰)                               Shannon limit

7.2 Why the Structured Regime is Optimal

Theorem 7.1 (Optimal compression depth). There exists a depth r* = √n* such that C(n*) is maximal within a local neighborhood.

Proof sketch. Consider C(n) as a function of n:

  • For small n: _D(n) is small, so even perfect compression (r(n)=1) gives limited absolute benefit. C(n) is bounded by L_S / O(1) = O(L_S).
  • For intermediate n: _D(n) is large enough for RLE to be powerful, but n has enough structure (from the phinary constraint of no consecutive 1s) to create long runs. C(n) can approach L_S / O(log log n).
  • For large n: The phinary representation approaches randomness (by normality). Runs become short (r(n) ≈ 7_D(n)/8). C(n) approaches L_S / O(log n).

By continuity of the soft metric C̃(x), there must exist local maxima in the structured regime. ∎

7.3 The Phinary Run-Length Property

Theorem 7.2 (Phinary run structure). In standard phinary form, the maximum run of consecutive 0s between 1s is unbounded, but the expected run length between 1s is φ² ≈ 2.618.

Proof. In phinary standard form, each 1 must be followed by a 0 (no consecutive 1s). The pattern is a sequence of the form:

...0 1 0^{k₁} 1 0^{k₂} 1 0^{k₃} ...

where kᵢ ≥ 1. For "random" phinary representations, the kᵢ are geometrically distributed with mean φ, giving average gap between 1s of φ + 1 = φ². ∎ n Corollary 7.3 (DNA run structure). When grouped into DNA triplets, the phinary structure creates correlations between consecutive triplets. Triplets that differ by one bit are more likely to be adjacent, creating natural clustering in the 8-base DNA alphabet.

This means the DNA encoding of phinary(n) has more structure than a truly random base-8 sequence, leading to:

E[r(n)] < 7_D(n)/8   (fewer runs than random)
E[C(n)] > C_min       (better compression than random)

8. Differentiable Approximation for Gradient Ascent

8.1 Smooth Run Count

To enable gradient ascent on the manifold, replace the discrete run count with a smooth approximation:

r̃_δ(n) = 1 + Σᵢ₌₁^{_D-1} [1 - tanh²(δ · (dᵢ - dᵢ₊₁))]

where δ > 0 controls steepness. As δ → ∞, r̃_δ → r (the discrete run count).

8.2 Smooth Compression Metric

         L_S
C̃_δ(n) = ──────────────────────────────────────────
         min( 3·_D(n),  r̃_δ(n)·[4 + log₂(_D(n)+1)] )

Theorem 8.1 (Gradient existence). For δ < ∞, C̃_δ is differentiable at all n where _D(n) is constant (i.e., between phinary length boundaries).

Proof. tanh is C^∞. _D(n) is piecewise constant. The minimum of differentiable functions is differentiable except at crossing points. ∎

8.3 Numerical Gradient (Practical)

For the experiment, use finite differences:

def compute_gradient(n, epsilon=1.0, original_size=L_S):
    """Compute ∂C/∂n via central differences."""
    C_plus = compression_ratio(n + epsilon, original_size)
    C_minus = compression_ratio(n - epsilon, original_size)
    dC_dn = (C_plus - C_minus) / (2 * epsilon)
    return dC_dn

9. Summary: The Compression Metric

9.1 Final Definition

┌─────────────────────────────────────────────────────────────────────┐
│                                                                     │
│   C(n) = L_S / |RLE(DNA(phinary(n)))|                              │
│                                                                     │
│   where:                                                            │
│   • phinary(n)  = standard base-φ representation (digits 0,1)       │
│   • DNA(P)      = group phinary digits in 3s → 1 of 8 bases       │
│   • RLE(D)      = run-length encoding, smart fallback to raw      │
│   • L_S         = original state size in bits (constant)          │
│                                                                     │
│   Bounds:                                                           │
│   L_S / Θ(log n)  ≤  C(n)  ≤  L_S / Θ(log log n)                  │
│                                                                     │
│   Gradient:                                                         │
│   ∇_d C = (∂C/∂n) · (∂n/∂d)  via chain rule on S⁷                │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

9.2 Key Properties

Property Statement
Bounded C_min(n) ≤ C(n) ≤ C_max(n) for all n (Theorem 4.4)
Scale-dependent Optimal compression at intermediate spiral depth (Theorem 7.1)
Structure-seeking C(n) is maximized when D(n) has few long runs
Phinary advantage No-consecutive-1s constraint creates natural DNA runs (Corollary 7.3)
Differentiable Soft version C̃_δ is differentiable for gradient ascent (Theorem 8.1)
Information-theoretic K(n) ≤ |RLE(D(n))| + O(1) — compression upper-bounds Kolmogorov complexity

9.3 Pseudocode: Full Measurement

class CompressionMetric:
    """Compression metric C(n) for the Radial Self-Finding Experiment."""
    
    # Constants
    PHI = (1 + 5**0.5) / 2
    PSI = 2 * math.pi / (PHI**2)  # golden angle in radians
    DNA_ALPHABET = ['A', 'B', 'C', 'G', 'P', 'S', 'T', 'Z']
    DNA_BITS = 3  # log2(8)
    
    def __init__(self, original_size_bits: int):
        self.L_S = original_size_bits
    
    # ─── Pipeline Components ─────────────────────────────────────
    
    def phinary(self, n: int) -> list[int]:
        """Convert n to phinary standard form (Zeckendorf)."""
        if n == 0:
            return [0]
        fib = [1, 2]
        while fib[-1] <= n:
            fib.append(fib[-1] + fib[-2])
        fib.pop()
        digits = []
        rem = n
        for f in reversed(fib):
            digits.append(1 if rem >= f else 0)
            if rem >= f:
                rem -= f
        return digits
    
    def dna_encode(self, phinary_digits: list[int]) -> str:
        """3 phinary bits → 1 DNA base (8 possibilities)."""
        padded = phinary_digits + [0] * ((-len(phinary_digits)) % 3)
        dna = []
        for i in range(0, len(padded), 3):
            triplet = (padded[i] << 2) | (padded[i+1] << 1) | padded[i+2]
            dna.append(self.DNA_ALPHABET[triplet])
        return ''.join(dna)
    
    def rle_encode(self, dna: str) -> list[tuple[str, int]]:
        """Run-length encode DNA sequence."""
        if not dna:
            return []
        runs = []
        curr, count = dna[0], 1
        for b in dna[1:]:
            if b == curr:
                count += 1
            else:
                runs.append((curr, count))
                curr, count = b, 1
        runs.append((curr, count))
        return runs
    
    def compressed_size(self, runs: list[tuple[str, int]], raw_len: int) -> int:
        """Smart RLE: use compressed only if beneficial."""
        max_run = max((r[1] for r in runs), default=1)
        run_len_bits = max(1, math.ceil(math.log2(max_run + 1)))
        rle_bits = len(runs) * (self.DNA_BITS + 1 + run_len_bits)
        raw_bits = raw_len * self.DNA_BITS
        return min(rle_bits, raw_bits)
    
    # ─── Main Metric ─────────────────────────────────────────────
    
    def C(self, n: int) -> dict:
        """Compute full compression metric for spiral index n.
        
        Returns dict with all component values.
        """
        P = self.phinary(n)
        D = self.dna_encode(P)
        runs = self.rle_encode(D)
        
        comp_size = self.compressed_size(runs, len(D))
        ratio = self.L_S / comp_size if comp_size > 0 else float('inf')
        
        # Entropy
        freq = Counter(D)
        lD = len(D)
        entropy = -sum((c/lD) * math.log2(c/lD) for c in freq.values()) if lD > 0 else 0
        
        # Information-theoretic measures
        k_upper = comp_size  # Kolmogorov upper bound
        
        return {
            'C': ratio,                           # compression ratio
            'phinary_digits': P,                  # phinary representation
            'dna_sequence': D,                    # DNA encoding
            'phinary_length': len(P),             # _P(n)
            'dna_length': len(D),                 # _D(n)
            'run_count': len(runs),               # r(n)
            'compressed_bits': comp_size,         # |R(n)|
            'entropy_bits': entropy,              # H(n) in bits/symbol
            'entropy_total': entropy * len(D),    # total entropy in bits
            'kolmogorov_upper': k_upper,          # K(n) upper bound
            'spiral_depth': n**0.5,               # r = √n
            'is_locally_optimal': None,           # filled by optimizer
        }
    
    # ─── Gradient ────────────────────────────────────────────────
    
    def gradient(self, n: int, epsilon: float = 1.0) -> float:
        """Compute ∂C/∂n via central differences."""
        if n <= epsilon:
            return (self.C(int(n + epsilon))['C'] - self.C(int(n))['C']) / epsilon
        c_plus = self.C(int(n + epsilon))['C']
        c_minus = self.C(int(n - epsilon))['C']
        return (c_plus - c_minus) / (2 * epsilon)

10. Receipt

{
  "receiptID": "compression_metric_radial_self_finding",
  "expression": "C(n) = L_S / |RLE(DNA(phinary(n)))|",
  "components": {
    "phinary": "n → {0,1}* (base-φ, standard form, no consecutive 1s)",
    "dna_encode": "3 binary bits → 1 of 8 DNA bases {A,B,C,G,P,S,T,Z}",
    "rle": "Run-length encoding with smart fallback to raw"
  },
  "bounds": {
    "lower": "C(n) ≥ L_S / Θ(log n)  (worst: all runs length 1)",
    "upper": "C(n) ≤ L_S / Θ(log log n)  (best: single run)",
    "theorem": "4.4"
  },
  "gradient": {
    "discrete": "ΔC(n) = C(n+1) - C(n) via finite differences",
    "continuous": "C̃_δ(n) with soft run count r̃_δ for differentiability",
    "manifold": "∇_d C = (∂C/∂n) · (∂n/∂d) via chain rule on S⁷"
  },
  "information_theory": {
    "entropy": "H(n) = -Σ p_b log₂ p_b  ∈ [0, 3] bits/symbol",
    "kolmogorov": "K(n) ≤ |RLE(D(n))| + O(1)",
    "depth_relation": "Optimal C(n) at intermediate spiral depth r = √n"
  },
  "status": "SPECIFIED",
  "verified": false
}

Appendix A: Phinary-to-DNA Example

Example: n = 42

Step 1: phinary(42)
  42 = 34 + 8 = F₉ + F₆  (Fibonacci: 1, 2, 3, 5, 8, 13, 21, 34, 55...)
  P(42) = [1, 0, 0, 1, 0, 0, 0, 1, 0]  (length 9)
  Check: 34 + 5 + 2 = 41... recalculate:
  42 = 34 + 8 → positions: F₉=34, F₆=8
  P(42) = [1, 0, 0, 1, 0, 0, 0, 1]  (reading F₈ down to F₂)
  = [1(F₈=21? no, 34= F₉=34)] ... 
  
  Correct Zeckendorf: 42 = 34 + 8 → F₉ + F₆
  Digits (F₉ to F₂): [1, 0, 0, 1, 0, 0, 0, 0] (length 8)
  Wait, need to recheck Fibonacci indexing.
  
  F₂=1, F₃=2, F₄=3, F₅=5, F₆=8, F₇=13, F₈=21, F₉=34
  42 = 34 + 8 = F₉ + F₆ ✓
  P(42) = [1(F₉), 0(F₈), 0(F₇), 1(F₆), 0(F₅), 0(F₄), 0(F₃), 0(F₂)]
        = [1, 0, 0, 1, 0, 0, 0, 0]  (length 8)

Step 2: Pad to multiple of 3
  P(42) → [1, 0, 0, 1, 0, 0, 0, 0, 0] (padded with one 0, length 9)

Step 3: Group into triplets
  [1,0,0] → triplet 4 → 'P'
  [1,0,0] → triplet 4 → 'P'  (same!)
  [0,0,0] → triplet 0 → 'A'
  
  D(42) = "PPA"

Step 4: RLE
  runs = [('P', 2), ('A', 1)]
  rle_bits = 2 × (3 + 1 + 3) = 14 bits  (3 for base, 1 flag, 3 for length)
  raw_bits = 3 × 3 = 9 bits
  
  Smart RLE: raw is smaller → use raw (9 bits)

Step 5: Compression ratio
  If L_S = 240 Gbit:
  C(42) = 240×10⁹ / 9 ≈ 2.67 × 10¹⁰

Note: This example shows a case where RLE doesn't help (sequence too short). For larger n with longer runs, RLE provides significant benefit.


Appendix B: Glossary

Term Meaning
Phinary Base-φ numeral system using digits {0, 1}
Zeckendorf Unique representation of integers as sums of non-consecutive Fibonacci numbers
Hachimoji Extended 8-letter DNA alphabet (A, B, C, G, P, S, T, Z)
RLE Run-Length Encoding — compress repeated symbols
Fisher-Rao Information geometry metric on probability simplex
S⁷ 7-sphere — the Fisher manifold for 8-state distributions
Φ-corkscrew Golden spiral encoding f(n) = (√n·cos(nψ), √n·sin(nψ))
K(n) Kolmogorov complexity — shortest program producing n
H(n) Shannon entropy — measure of randomness in encoding
Self-finding System encoding its own search process as state