Research-Stack/6-Documentation/docs/specs/DP_RRC_RECEIPT_ENCODING_SPEC.md
allaun 558431fc45 feat(lean,infra): Corpus278→250 rename + SLOS-calibrated braid defaults
- Renamed Corpus278/Matrices278 to Corpus250/Matrices250 across all
  Lean modules, Python shims, JSON schemas, and documentation
- Applied SLOS-calibrated defaults to braid_search.py:
  bracket_cost base=8x/16x, crossing_penalty gap_reward=0.01
- Synced same defaults to research-compute-fabric submodule
- Updated Burgers 0D defaults: nu=0.9995, advection=0.075
- Fixed 278→250 refs in pist_predictions JSON (claim_boundary, total)
- Fixed stale schema refs in .devin/skills/lean-proof/SKILL.md
- Updated AGENTS.md build baselines to post-clean counts (3314 jobs)
- Updated lake-manifest.json sparkle rev to match lakefile.toml
- Fixed Q16_16 signed conversion bug in qaoa_adapter tunable costs
- NBody.lean: pre-existing dirty changes (introN failures, NOT our work)

Build: 3314 jobs, 0 errors (lake build Compiler)
2026-06-18 22:16:52 -05:00

17 KiB
Raw Blame History

DP-RRC: Depth-Prefix Receipt Encoding for the Rainbow Raccoon Compiler

Inspired by: tearflake/dp-expr — dot-prefixed depth markers as an alternative to parentheses for tree-structured data.

Status: Design proposal Applies to: Semantics.BraidEigensolid, Semantics.RRC.Emit, Semantics.AVMIsa.Emit


1. Current RRC Receipt Encoding

The RRC compressor produces a BraidReceipt with 6 dimensions (from BraidEigensolid.lean):

Dim Symbol Name Type Meaning
C crossing_matrix Crossing matrix BraidBracket The eigensolid bracket: B(κ, μ) = {lower, upper, gap, kappa, phi}
σ sidon_slack Sidon slack UInt32 128 - max_label_used — address budget headroom
k step_count Step count Nat Number of crossStep iterations to convergence
ε_seq residuals Residual series List Q16_16 Per-step kappa residuals Δκ(step_i)
t write_time Write timestamp UInt64 Monotonic write nonce
scar_absent Scar absence Bool No FAMM failure records (all 8 strands admissible)

These 6 dimensions are the compressed state. Invertibility of the receipt (the receipt_invertible theorem) is the definition of lossless compression.

1.1 The BraidBracket (dimension C)

structure BraidBracket where
  lower     : Q16_16    -- κ - μ
  upper     : Q16_16    -- κ + μ
  gap       : Q16_16    -- 2μ
  kappa     : Q16_16    -- octagonal norm of PhaseVec
  phi       : Q16_16    -- π/4 placeholder
  admissible : Bool

Computed from a PhaseVec (x, y) and slot parameter μ:

κ = octagonal_norm(z)  ≈ max(|x|, |y|) + 3/8·min(|x|, |y|)
lower = κ - μ
upper = κ + μ
gap = 2μ

1.2 Sidon Labels (dimension σ)

Canonical set for 8 strands: powers of 2{1, 2, 4, 8, 16, 32, 64, 128}.

All pairwise sums are unique — this is the defining Sidon property. Slack:

σ = 128 - max(slot_used)

1.3 Scar Absence (dimension ∅)

scar_absent = true iff all 8 strands have admissible brackets (lower.val ≤ upper.val). A scar would be a FAMM failure record with scar_pressure, failure_mode, and optional coarsening_agent. Absence (∅) is a positive receipt dimension.

1.4 Current JSON Emission

Receipts are emitted as nested JSON objects via AVMIsa.Emit. Example receipt fragment:

{
  "schema": "avm_canary_emit_v1",
  "receipts": [
    {"kind":"leanBuild", "targetId":"avm.canary.not", "valid":true, "authority":"lake_build_bot", "timestamp":0}
  ]
}

The corpus receipt (emit250.json) uses 250 flat rows with explicit field names — no depth encoding.


2. DP-Expr Mapping onto RRC Structures

DP-Expr encodes tree structure via dot-prefixed depth markers instead of parentheses:

.expr
  ..left
  ..right

(expr (left right))

Each token's dot-count = its nesting depth. The parser walks depth coordinates: same depth = same list, deeper = open list, shallower = close list.

2.1 Structural Isomorphism

DP-Expr Concept RRC Concept Why It Fits
Dot-count = depth Sidon label = 2^depth Both encode position in a hierarchy; dot-count d maps to Sidon label 2^d
Structural token (empty value, e.g. ..) Scar absence (∅) Both carry no data value but encode structure
List = sibling group Braid strand group Crossing strands at same depth are siblings
Depth walk (open/close) crossStep iteration Each step changes the crossing depth
Token value = node content PhaseVec (x, y) The actual phase accumulation at a crossing point
Full S-Expr interchangeability receipt_invertible Both require lossless round-tripping

2.2 Dot-Depth as Sidon Label

The mapping is direct:

Sidon label = 2^dot_count
            = powers of 2 addressing

A crossing at depth d → strand slot = 2^d

Examples:
  d=0 → label 1   (strand 0)
  d=1 → label 2   (strand 1)
  d=2 → label 4   (strand 2)
  ...
  d=7 → label 128 (strand 7)

Sidon slack in dot notation:

σ = 128 - max_label_used
  = dot_slots_total - deepest_slot_used
  = 7 - max_dot_depth

A braid using depths 05 uses labels 164, so:

σ = 128 - 64 = 64
  = 7 - 5 = 2 remaining depth levels

2.3 Crossing Matrix as DP-Expr

A single braid crossing between strand i (depth d_i) and strand j (depth d_j) with phase κ:

..strand_i              ; depth 2, value = strand index
....kappa               ; depth 4, value = octagonal norm
......phi               ; depth 6, value = phase angle
..strand_j              ; depth 2, value = strand index
....kappa               ; depth 4, value = octagonal norm
......phi               ; depth 6, value = phase angle
..residual              ; depth 2, value = R_ij.kappa

The 8-strand bundle:

.braid
  ..strand_0
    ...slot               ; depth 3 = Sidon label
    ...kappa              ; depth 3 = octagonal norm
    ...phi                ; depth 3 = phase
  ..strand_1
    ...
  ..strand_7
    ...
  ..eigensolid_bracket
    ...C_lower
    ...C_upper
    ...C_gap
    ...C_kappa
    ...C_admissible
..sidon_slack             ; depth 2 = σ
..step_count              ; depth 2 = k
..write_time              ; depth 2 = t
..scar_absent             ; depth 2 = ∅ (structural or literal)

3. DP-RRC Receipt Encoding

3.1 Compact BraidReceipt in DP-Expr

; DP-RRC BraidReceipt
; 8-strand eigensolid crossing matrix + 6 receipt dimensions

.braid
  ;; Strand 0
  ..a
    ...2          ; slot = Sidon label 2
    ...16384      ; kappa in Q16_16 (1.0 = 65536)
    ...0          ; phi = 0 (zero vector)
  ..b
    ...1          ; slot = Sidon label 1
    ...24576      ; kappa = 0.375
    ...0
  ..c
    ...4
    ...8192       ; kappa = 0.125
    ...0
  ..d
    ...8
    ...40960      ; kappa = 0.625
    ...0
  ..e
    ...16
    ...32768      ; kappa = 0.5
    ...0
  ..f
    ...32
    ...57344      ; kappa = 0.875
    ...0
  ..g
    ...64
    ...16384      ; kappa = 0.25
    ...0
  ..h
    ...128
    ...49152      ; kappa = 0.75
    ...0
  ;; Eigensolid bracket (merged crossing state)
  ..bracket
    ...-16384     ; lower = κ - μ
    ...16384      ; upper = κ + μ
    ...32768      ; gap = 2μ
    ...0          ; kappa
    ...0          ; phi
    ...1          ; admissible
;; Receipt dimensions
.sidon_slack
  ..0             ; σ = 0 (all labels used: 128 used, budget 128)
.step_count
  ..42            ; k = 42 iterations to converge
.residuals
  ..8192          ; ε_1 = 0.125
  ..4096          ; ε_2 = 0.0625
  ..2048          ; ε_3 = 0.03125
  ..0             ; converged
.write_time
  ..1719000000    ; t = Unix timestamp
.scar_absent
  ..1             ; ∅ = true (no FAMM scars)

3.2 Simplified Receipt (structural tokens for scars)

When scars are absent, use structural tokens (empty-valued depth markers) instead of explicit scar_absent:

.braid
  ..a ...2 ...16384 ...0
  ..b ...1 ...24576 ...0
  ..c ...4 ...8192 ...0
  ..d ...8 ...40960 ...0
  ..e ...16 ...32768 ...0
  ..f ...32 ...57344 ...0
  ..g ...64 ...16384 ...0
  ..h ...128 ...49152 ...0
  ..
    ...-16384 ...16384 ...32768 ...0 ...0 ...1    ; structural bracket token
.0           ; σ = 0
.42          ; k = 42
.8192 .4096 .2048 .0    ; ε_seq
.1719000000  ; t
.            ; ∅ = structural token (no value = scar absent)

3.3 S-Expr ↔ DP-RRC Interchangeability

The core theorem: Every DP-RRC expression has an equivalent S-Expr and vice versa.

DP-Expr:  .a ..b ..c
S-Expr:   (a (b c))

DP-RRC:  .braid ..a ...2 ...16384 ...0  ..b ...1 ...24576 ...0
S-RRC:   (braid (a 2 16384 0) (b 1 24576 0))

This maps to the existing receipt_invertible theorem: given the receipt (in either encoding), the original braid state is reconstructible within bounded error.

3.4 Structural Tokens as ∅_scars

DP-Expr defines structural tokens — empty-valued tokens that affect only nesting structure:

..    ; structural token at depth 2 — no atom emitted

In RRC terms, this is scar absence (∅): a receipt dimension that is structurally present (the slot is occupied) but carries no data value. This is more elegant than an explicit "scar_absent": true field because:

  1. The absence IS the encoding — no separate boolean needed
  2. Depth position encodes the constraint — a structural token at receipt level means "no FAMM failure at this level"
  3. Scar presence would be a valued token..error_type scar_pressure failure_mode would be a real scar

This mirrors the glossary definition: "Scar absence (∅) is a positive receipt dimension."


4. Formal Receipt Schema (DP-RRC)

4.1 Grammar

receipt     := braid_receipt
braid_receipt := "." "braid" newline strand_bundle newline receipt_dims

strand_bundle := strand_entry* bracket_entry

strand_entry := ".." strand_id newline
                "..." slot newline
                "..." kappa newline
                "..." phi

strand_id    := [a-z]     ; single letter, 8 strands: a..h
slot         := integer   ; Sidon label (power of 2: 1,2,4,8,16,32,64,128)
kappa        := integer   ; Q16_16 octagonal norm
phi          := integer   ; Q16_16 phase angle

bracket_entry := ".." newline            ; structural token or
                 "..." lower newline
                 "..." upper newline
                 "..." gap newline
                 "..." bracket_kappa newline
                 "..." bracket_phi newline
                 "..." admissible

receipt_dims := sidon_slack_entry
                step_count_entry
                residual_series
                write_time_entry
                scar_status

sidon_slack_entry := "." integer          ; σ
step_count_entry  := "." integer          ; k
residual_series   := "." integer+         ; ε_seq (space-separated)
write_time_entry  := "." integer          ; t
scar_status       := "."                  ; ∅ (structural token = absent)
                     | "." integer        ; scar present with error code

4.2 JSON ↔ DP-RRC Translation

The DP-RRC encoding has an equivalent JSON form for storage:

{
  "schema": "dp_rrc_receipt_v1",
  "braid": {
    "strands": [
      {"id": "a", "slot": 2, "kappa": 16384, "phi": 0},
      {"id": "b", "slot": 1, "kappa": 24576, "phi": 0},
      {"id": "c", "slot": 4, "kappa": 8192, "phi": 0},
      {"id": "d", "slot": 8, "kappa": 40960, "phi": 0},
      {"id": "e", "slot": 16, "kappa": 32768, "phi": 0},
      {"id": "f", "slot": 32, "kappa": 57344, "phi": 0},
      {"id": "g", "slot": 64, "kappa": 16384, "phi": 0},
      {"id": "h", "slot": 128, "kappa": 49152, "phi": 0}
    ],
    "bracket": {"lower": -16384, "upper": 16384, "gap": 32768, "kappa": 0, "phi": 0, "admissible": true}
  },
  "sidon_slack": 0,
  "step_count": 42,
  "residuals": [8192, 4096, 2048, 0],
  "write_time": 1719000000,
  "scar_absent": true
}

Translator:

dp-expr → JSON    : parser walks dot-depth, emits structured JSON
JSON → dp-expr     : tokenizer writes depth-prefixed form

5. Receipt Invertibility in DP Form

The receipt_invertible theorem in BraidEigensolid.lean proves:

receipt_invertible (r : BraidReceipt) (s s' : BraidState) :
  encodeReceipt s = r → encodeReceipt s' = r → s = s'

In DP-RRC terms, this becomes:

Given a DP-RRC receipt, there is exactly one BraidState that produces it.

Proof sketch (dot-depth version):

  1. The dot-depth d of each strand entry determines its Sidon label 2^d
  2. The slot values in the receipt fix the strand ordering
  3. The bracket parameters (kappa, phi) fix the PhaseVec
  4. The residual series ε_seq fixes the convergence trajectory
  5. Structural tokens fix scar status
  6. Any two states producing the same DP-RRC receipt must agree on all 6 dimensions → they are equal

6. Concrete Corpus250 Example

Current JSON row (emit250.json):

{
  "equation_id": "rrc_eq_86ccde7bfd669b77",
  "name": "bandwidth_adjusted_threshold",
  "shape": "CognitiveLoadField",
  "status": "candidate",
  "alignment_score": 100,
  "promotion": "not_promoted"
}

Equivalent DP-RRC form:

; Corpus250 row as DP-Expr
.row
  ..rrc_eq_86ccde7bfd669b77    ; equation_id
  ..bandwidth_adjusted_threshold ; name
  ..CognitiveLoadField          ; shape
  ..candidate                   ; status
  ..100                         ; alignment_score
  ..not_promoted                ; promotion

The full 250-row corpus:

; avm_rrc_corpus250_v1 in DP-RRC
.corpus250
  ;; Row 1
  ..rrc_eq_86ccde7bfd669b77
    ...bandwidth_adjusted_threshold
    ...CognitiveLoadField
    ...candidate
    ...100
    ...not_promoted
  ;; Row 2
  ..rrc_eq_a3f8c21e
    ...network_flow_convergence
    ...FlowField
    ...candidate
    ...100
    ...not_promoted
  ;; ... 248 more rows
  ;; Bundle receipt
  ..bundle
    ...avm_canary_not    1
    ...avm_canary_and    1
    ...avm_canary_or     1

7. Why DP-RRC for Sidon Collision and Compression

7.1 Dot-Depth = Sidon Label (Direct)

The dot-count hierarchy is the Sidon address space:

d=0  →  label 1   →  strand 0
d=1  →  label 2   →  strand 1
d=2  →  label 4   →  strand 2
d=3  →  label 8   →  strand 3
d=4  →  label 16  →  strand 4
d=5  →  label 32  →  strand 5
d=6  →  label 64  →  strand 6
d=7  →  label 128 →  strand 7

A DP-Expr parser for RRC can compute Sidon slack on the fly:

slack = 128 - (1 << max_depth_seen)

7.2 Collision Detection via Depth Mismatch

A collision occurs when two tokens with the same dot-count appear where one is expected:

.a ..b ..c       ; valid — siblings
.a ..b ..b       ; collision — duplicate depth-2 token

This maps to Sidon collision: two strands attempt the same label. The pairwise-sum uniqueness of Sidon sets means a collision is immediately detectable as a depth violation.

7.3 Compression via Depth Run-Length

Consecutive tokens at the same depth can be run-length encoded:

; Before (13 tokens):
.0 .1 .2 .3 .4 .5 .6
; After (2 tokens + count):
.0 ..7

This compresses the convergence trajectory ε_seq: a run of k steps with identical residual magnitude collapses to depth + count.

7.4 Scar Absence as Structural Token

Most receipts will have scar_absent = true. Encoding this as a structural token (.) rather than a boolean field ("scar_absent": true) saves bytes and, more importantly, makes the encoding homomorphic with the state: an empty slot in the receipt corresponds to an empty slot in the braid state.


8. Implementation Path

8.1 Parser/Translator (Python shim)

A lightweight Python translator 4-Infrastructure/shim/dp_rrc_translate.py:

def parse_dp_expr(text):
    """DP-Expr → nested list (S-Expr form)."""
    tokens = text.strip().split()
    stack = [[]]
    current_depth = 0
    for tok in tokens:
        depth = len(tok) - len(tok.lstrip('.'))
        val = tok[depth:]
        while depth > current_depth:
            stack.append([])
            current_depth += 1
        while depth < current_depth:
            closed = stack.pop()
            stack[-1].append(closed)
            current_depth -= 1
        stack[-1].append(val)
    while len(stack) > 1:
        stack[-2].append(stack.pop())
    return stack[0]

def emit_dp_expr(sexpr, depth=0):
    """S-Expr → DP-Expr string."""
    if not isinstance(sexpr, list):
        return '.' * depth + str(sexpr)
    lines = []
    for item in sexpr:
        lines.append(emit_dp_expr(item, depth + 1))
    return '\n'.join(lines)

8.2 Lean Theorem

A new theorem in BraidEigensolid.lean:

theorem dp_receipt_invertible (r : BraidReceipt) (s s' : BraidState) :
  encodeReceiptDP r = encodeReceiptDP r' → r.depthEncoding = r'.depthEncoding → s = s' :=
by
  -- dot-depth uniquely determines Sidon label assignment
  -- structural tokens uniquely determine scar status
  -- therefore receipt is invertible

8.3 Integration into AVMIsa.Emit

Add a dp_rrc_corpus250_v1 schema alongside the existing avm_rrc_corpus250_v1. The AVM canary check is the same; only the output format changes. The DP-Expr form can be emitted as a #eval string in the existing JSON bundle under a "dp_expr" key.


9. Summary

Aspect Current RRC DP-RRC Proposed
Receipt encoding JSON objects with explicit field names Dot-prefixed depth markers
Sidon labels Slots stored as integers [1,2,4,8,16,32,64,128] Implicit from dot-depth 2^d
Scar absence "scar_absent": true boolean Structural token . — no value emitted
Convergence residuals as JSON array Run-length encoded depth stream
Nesting Explicit JSON {} nesting Implicit depth coordinate walk
Round-trip receipt_invertible theorem Dot-count + structural token invertibility
Corpus format 250-row flat JSON Hierarchical DP-Expr with row bundling

The DP-Expr encoding does not replace the existing JSON format — both are interchangeable. It provides a compact, depth-native representation that makes the Sidon label assignment explicit in the syntax itself, which is the key insight for collision detection and compression path analysis.