# Cross-Layer Structural Isomorphisms
# The deep connections that make a single grammar span all three layers

thesis: >
  The same structural patterns — tiling, dispatch, fusion, decomposition,
  and reduction — recur at every level, from silicon to synapse to
  subjective experience.

layers:
  backend:
    project: TileGym
    domain: CUDA Tile kernels, GPU tiling
    role: Computational substrate
    grammar_summary: "decompose → dispatch → tile → fuse → reduce"

  interface:
    project: Chaos Hearing
    domain: Auditory science, nonlinear dynamics, spectral cognition
    role: Scientific model
    grammar_summary: "transduce → decompose → infer → group → predict"

  frontend:
    project: McDermott Lab Demos
    domain: Auditory illusions, scene analysis, generative listening
    role: Perceptual surface
    grammar_summary: "stimulate → analyze → group → bind → perceive"

isomorphism_table:
  - concept: Primitive
    backend: "Tile T(M,N)"
    interface: "Oscillator O(μ,ω₀)"
    frontend: "Illusion Ψ(stim,percept)"

  - concept: Decomposition
    backend: "Tile blocking"
    interface: "Cochlear frequency analysis"
    frontend: "Auditory scene analysis"

  - concept: Dispatch
    backend: "Backend selector"
    interface: "Frequency-place mapping"
    frontend: "Perceptual frame selection"

  - concept: Fusion
    backend: "Kernel fusion F(∘)"
    interface: "Spectral mixture kernel"
    frontend: "Texture perception"

  - concept: Reduction
    backend: "Split-K merge"
    interface: "Scene integration"
    frontend: "Source segregation"

  - concept: Attention
    backend: "A(Q,K,V)"
    interface: "Bayesian prediction P"
    frontend: "Grouping cues G"

  - concept: Normalization
    backend: "RMS/LayerNorm"
    interface: "Cochlear compression"
    frontend: "Perceptual continuity"

  - concept: Self-Supervision
    backend: "Student-Teacher EMA alignment"
    interface: "Learnable filterbank"
    frontend: "Illusory restoration"

  - concept: Causal Uncertainty
    backend: "Objective function optimization (minimize target distance)"
    interface: "Precision-weighting (balancing prior vs. likelihood)"
    frontend: "Ambiguity resolution (hearing voices in noise)"

  - concept: Spectral Filtering
    backend: "Fixed Hankel eigenvector convolution (no gradient)"
    interface: "Cochlear tonotopic map (physically fixed resonance)"
    frontend: "Absolute pitch perception (fixed internal template)"

  - concept: Failure Mode
    backend: "Wrong dispatch"
    interface: "Hallucination"
    frontend: "Illusion"

  - concept: Uncertainty
    backend: "Backend fallback"
    interface: "Posterior variance"
    frontend: "Causal ambiguity"

  - concept: Improvisation
    backend: "Autoregressive decode"
    interface: "Jazz solo over changes"
    frontend: "Generative listening (BASS)"

deep_analogies:
  - name: "The Dispatch-Tuning Correspondence"
    description: >
      TileGym's @dispatch decorator selects the right kernel implementation
      for an operation. The cochlea's tonotopic map selects the right
      oscillator for a frequency. The perceptual system selects the right
      interpretive frame for a stimulus. All three are instances of
      selective routing to specialized processors.
    backend_code: |
      @dispatch("fmha")
      def fmha(q, k, v, scaling=None, is_causal=True):
          ...
    interface_equation: "dz/dt = (μ + iω₀)z - (a + i/3)|z|²z + n_z(t)"
    frontend_demo: "Inharmonic Speech Segregation"

  - name: "The Fusion-Texture Correspondence"
    description: >
      Kernel fusion combines multiple operations into a single pass,
      eliminating intermediate materializations. Spectral mixture kernels
      combine multiple frequency components into a single probabilistic
      model. Texture perception combines multiple acoustic statistics
      into a single perceptual quality. All three eliminate intermediate
      representations in favor of holistic processing.
    backend_code: "F(linear ∘ silu ∘ mul) → SwiGLU_fused"
    interface_model: "K(ω) = Σᵢ wᵢ exp(-2π²ℓᵢ²τ²) cos(2πωᵢτ)"
    frontend_demo: "Model-Matched Sounds"

  - name: "The Split-K / Cocktail Party Correspondence"
    description: >
      Split-K reduction divides a large computation into independent
      parallel chunks, then merges results. The cocktail party problem
      requires the auditory system to process a mixture in parallel
      frequency bands, then merge the results into segregated sources.
      Both are instances of parallel decomposition followed by
      coherent recomposition.
    backend_code: "R(attn_splitk_out, lse_splitk_out) → attn_out"
    interface_model: "Σ(mixed) → S₁ + S₂ + … + Sₙ"
    frontend_demo: "Cocktail Party"

  - name: "The Autoregressive / Jazz Improvisation Correspondence"
    description: >
      LLM autoregressive decoding generates tokens one at a time,
      each conditioned on the full accumulated context (KV cache)
      and shaped by learned weights (the prior). Jazz improvisation
      generates notes one at a time, each conditioned on the harmonic
      context (chord changes + what's been played) and shaped by
      musical knowledge (the prior). Generative listening (BASS)
      infers scene decompositions conditioned on the acoustic mixture
      and shaped by learned source priors. All three are real-time
      sequential generation under constraints. Inspired by Stephon
      Alexander's "The Jazz of Physics" (2016), which identifies
      the group-theoretic structure of Coltrane's harmonic
      substitutions (Z₃ on Z₁₂) as a production rule on pitch space.
    backend_code: "fmha_decode(q, k, v) → next token logits"
    interface_model: "P(noteₜ | chord_context, melodic_prior) → play noteₜ"
    frontend_demo: "Listening with Generative Models (BASS)"
    reference: "Alexander, S. (2016). The Jazz of Physics. Basic Books."

  - name: "The Self-Supervision / Learned Cochlea / Predictive Restoration Correspondence"
    description: >
      In deep learning backends, self-supervised representation learning aligns
      a Student network's predictions with a Teacher network's representations
      (updated via weight EMA, centered and sharpened to prevent representation
      collapse). In the audition interface, the Audio Transformer learns its
      own adaptable time-frequency front-end (sinusoids, windowing, onsets)
      directly from raw waveforms, replacing fixed spectrograms. In the perceptual
      frontend, listeners perform part-whole inference, restoring missing fragments
      of sound masked by noise (illusory continuation). All three represent the
      system adapting its internal filters to predict global, coherent representations
      from local, partial observations.
    backend_code: "align(student, teacher_ema) ∘ prevent_collapse(centering, sharpening)"
    interface_model: "dense(waveform) → filterbank(sinusoids, windowing, onsets)"
    frontend_demo: "Illusory Continuation / Spectral Completion"
    reference: "Verma & Berger (2021)"

  - name: "The Hankel Eigendecomposition / Cochlear Resonance / Absolute Pitch Correspondence"
    description: >
      The Spectral STU uses fixed convolutional filters derived from the
      eigendecomposition of a Hankel matrix — filters that are never trained
      but capture the mathematical structure of sequences themselves. The
      cochlea's basilar membrane provides a physically fixed tonotopic map:
      its resonant modes are determined by structural mechanics (stiffness
      gradients, mass distribution), not by neural learning. In perception,
      absolute pitch — the rare ability to identify frequencies without a
      reference — suggests the existence of a fixed internal frequency
      template that is not learned but structurally given. All three represent
      processing through invariant, structurally determined spectral bases
      rather than through adaptive, learned representations.
    backend_code: "eig_vals, eig_vecs = eigh(Hankel(n)); conv(eig_vecs, input)"
    interface_model: "h(t) = e^{-γt} sin(2πf_c t), f_c determined by basilar membrane position"
    frontend_demo: "Absolute Pitch / Tonotopic Invariance"
    reference: "Agarwal et al. (2024); Eguíluz et al. (2000)"

  - name: "The Objective Optimization / Precision Weighting / Free Energy Correspondence"
    description: >
      In the YAMNet optimization loop, the system modifies sound parameters to minimize
      the distance between current prediction entropy ($H_{cu}$) and a target entropy.
      In computational psychiatry (Predictive Coding), the brain precision-weights
      sensory evidence against internal priors to minimize surprise (Free Energy).
      If sensory evidence is artificially made ambiguous (high entropy), a neurotypical
      brain remains uncertain, but a maladaptive brain with overly precise priors
      (e.g., schizophrenia) hallucinates a cause to resolve the uncertainty.
      In all three cases, the system attempts to resolve a mismatch between expected
      and actual distributions by either altering the internal model or the external state.
    backend_code: "loss = |H_cu(θ) - target_H_cu|; minimize(loss, θ)"
    interface_model: "μ_post = (π_lik μ_lik + π_prior μ_prior) / (π_lik + π_prior)"
    frontend_demo: "Auditory Hallucinations in Noise"
    reference: "Boger et al. (2021); Friston (2010)"


