/ Stream
build 2026.12.03 · --:--:-- UTC · RSS

BabbTools for the frontier.

mascot mascot
All materials

Reader A vs Reader B — skeletons, run and compared

READERS-COMPARISON.md View the source file

Stage D prep, local only. No GitHub writes, no Lab tool work. Python standard library only. Sources: babbworks/stream main 5d18970 (notes 15, 16b, 18; experiments/mark-boundary/), prep package ~/workspace/stream-unfolding-lab-prep/01-stage-c-and-readers.md, Stage C report ~/workspace/stream-stage-c/STAGE-C-REPORT.md.

What runs

~/workspace/stream-unfolding-work/readers/
  transcript.py               shared data only: bundles F + D, L:1–L:16 records,
                              mark-boundary fixture, state formatting
  reader_a.py                 Reader A: finite relational closure
  reader_b.py                 Reader B: finite derived expressions / forest traversal
  run_readers.py              driver: runs both on the same inputs, writes the logs
  test_readers.py             15 stdlib-unittest tests (both readers, same assertions)
  reader-a-transcript.txt     full run log, Reader A
  reader-b-transcript.txt     full run log, Reader B
  metrics.json                measured numbers behind the table below
  READERS-COMPARISON.md       this report

Run: python3 run_readers.py (rewrites both logs + metrics.json); python3 test_readers.py — 15 tests, all pass (0.073 s).

Both readers run (a) the note-16b L:1–L:16 bootstrap transcript with a GENESIS record first, reporting Kn/Bn/Cn after every step, and (b) the mark-boundary entry/exit fixture. Both also run the same probes (pre-activation invoke, second GENESIS, pending-definition invoke, unsafe rule at proposal, same-key retry, scope refusal, cycle refusal) and the same Books paired-transfer checks.

Headline: on these two inputs the readers agree on every observable outcome. All 6 transcript checks pass in both; the mark-boundary spellings are * → *() → (*) → *() in both; all refusal probes refuse in both; the Books transfer conserves in both. Where they differ is what they accept as a definition and how they explain — which is exactly the difference note 18 says not to silently exchange.

The one deliberate asymmetry (read this first)

The two readers share admission, activation, authentication, atomic commit and idempotency machinery (proposal → activation effective next position; steward C0 as supplied trust premise; exact occurrence addressing; staged post-state checks; identical-retry receipts). They differ only in derivation — that is the comparison's point, and the shared shape is stated here rather than hidden.

  • Reader A admits the bundle's rules as written, including the recursive in rules, and derives by least-fixed-point closure.
  • Reader B refuses recursive rules as rules at proposal time and requires a covering derived definition supplied in the same bundle: in becomes an ancestor-walk, within a reflexive-or check, principal a conjunction check. The translation is recorded in the run log (translation F: in-trans (in) -- recursive: refused as rule, translated to derived definition). A recursive rule with no covering derived definition is refused outright (tested).
  • Grant shape: A stores note 16's 5-tuple grant(g, holder, action, scope, remaining) with remaining = 1; B stores note 18's reduction one_use_grant(holder, action, scope) with the occurrence itself as the token, no counter, no separate grant id. Same observable behaviour (one use, then spent), different stored definition.

Transcript run — L:1–L:16 (both readers, identical outcomes)

Refs are birth occurrence addresses: R=1, B=3, A=5, C=7, P=9. Parent occurrences: L:8 → #11, L:9 → #12 (q9), L:10 → #13. Grant occurrence: L:14 → #15 (q14). L:15 emits #16 parent(A,C).

StepRecordOutcome (both)Cn after (both)
GENESISC0 genesisaccepted, pos 1empty
L:1propose Faccepted; F inactiveempty
L:2activate Faccepted; usable from L:3empty
L:3make_node → Raccepted, occ #1–2within={(1,1)}
L:4make_node → Baccepted, occ #3–4within+={(3,3)}
L:5make_node → Aaccepted, occ #5–6within+={(5,5)}
L:6make_node → Caccepted, occ #7–8within+={(7,7)}
L:7make_node → Paccepted, occ #9–10principal still absent
L:8attach(B,R)accepted, occ #11in={(3,1)}
L:9attach(A,B)accepted, occ #12 (q9)in={(3,1),(5,1),(5,3)}
L:10attach(C,B)accepted, occ #13in+={(7,1),(7,3)}
L:11propose Daccepted; D inactiveunchanged
L:12attest_binding(P,CP)accepted, occ #14principal still absent
L:13activate Daccepted; usable from L:14principal={(9,)}
L:14issue(P,move,B,1)accepted, occ #15 (q14)unchanged
L:15CP move(P,A,B,C,q14,q9)accepted; retired #12,#15; emitted #16in={(3,1),(5,1),(5,3),(5,7),(7,1),(7,3)}
L:16CP retry, new key, spent refsREFUSED [unknown_occurrence] — occurrence #15 is not live; no domain changeidentical to L:15

Final Bn (both): #11 parent(3,1), #13 parent(7,3), #16 parent(5,7) plus the ten entity/boundary occurrences and #14 binding_verified(9,CP). This matches note 16 §6 exactly: parent set {(B,R),(C,B),(A,C)}, closure in(A,C), in(A,B), in(A,R), in(C,B), in(C,R), in(B,R).

Checks (both readers, all true): in-set after L:9; principal absent after L:12; principal(P) present after L:13; final parent set; final in set; L:16 left the parent set unchanged.

Two real bugs were caught by these checks while building, and are worth recording because they are the kind of silent exchange the notes warn about: (1) Reader B first evaluated principal from base evidence regardless of activation, so it derived principal(P) at L:12 while D was dormant — fixed by gating every derived query on the definition being active; (2) the shared bundle data first defined principal inside F, contradicting note 16 §4 (F declares principal with no defining rules) — fixed by moving the definition into D only.

Probes (both readers, all refuse as expected)

ProbeResult (both)
P0 invoke make_node before any activationREFUSED [unknown_action] — no active action; Bn empty
P1 second GENESISREFUSED [second_genesis]
P2 invoke make_node while F only proposedREFUSED [inactive_definition] — proposed but not active
P3 unsafe rule (head $z bound by no body atom) at proposalA: REFUSED [Unsupported] unsafe rule; B: REFUSED [Unsupported] no covering derived definition
Same-key retry of L:15 (key k15)original receipt returned, replay: True, no new event, Bn unchanged
Scope refusal: grant scoped to B, move A C→RREFUSED [target_outside_scope] — target 1 is not within scope 3
Cycle refusal: attach would put target inside itemREFUSED [cycle] via guard (exercised in both readers' guards)
Recursive rule with no covering derived definitionB: REFUSED [Unsupported]; A: admitted (general recursion is A's point)

Refusal precedence is deterministic and reported, but note 16 §7's point stands: the precedence itself is unspecified by the notes. In these skeletons the grant-occurrence liveness check fires before the parent-occurrence check, so L:16 reports the spent grant, not the stale parent. A canonical order still needs deciding if refusal bytes are ever hashed.

Mark-boundary entry/exit fixture (both readers)

Fixture: experiments/mark-boundary/examples/entry-exit.json (profile mark-boundary-v1): mark → enclose [] → relocate 1 null→2 → relocate 1 2→null.

StepA (relational rendering)B (native forest)
1 markspelling *, inside(1,2)=undefinedspelling *, inside(1,2)=undefined
2 enclose []spelling *(), inside(1,2)=Falsespelling *(), inside(1,2)=False
3 relocate 1→2spelling (*), inside(1,2)=True (delta +1)spelling (*), inside(1,2)=True (delta +1)
4 relocate 1→nullspelling *(), inside(1,2)=False (delta −1)spelling *(), inside(1,2)=False (delta −1)

Expected spellings ['*', '*()', '(*)', '*()'] and inside values ['undefined', False, True, False] — OK in both.

Representation difference: A renders the forest relationally with a distinguished ROOT terminator fact (parent(x, ROOT) = "x is a root"); B's parent-slot map has no slot at all for a root. A therefore translates the fixture's JSON null source/target to ROOT at the boundary — a small, visible adapter, not a semantic change. B needs no adapter here: the fixture is a forest.

Books (both readers)

Paired transfer, harness-seeded balances (the skeleton has no balance-seeding action; seeding is marked as harness, not a log event): balance(i,USD,1000) + balance(j,USD,250) → transfer 400 → balance(i,USD,600) + balance(j,USD,650), total 1250 conserved, (x−q)+(y+q) = x+y checked on the staged delta. Failure modes, each on a fresh pair so the intended guard fires:

CaseResult (both)
insufficient funds (1000 < 2000)REFUSED [insufficient_funds]
self-transferREFUSED [self_transfer] — explicit policy required
overflow (2⁶² + 2⁶² > 2⁶³−1)REFUSED [overflow]
unit mismatch USD vs EURREFUSED [unit_mismatch]

Not done: no aggregate sums (note 15 §11), no reservations / conversions / partial settlement, no overdraft policy beyond refusal.

Comparison on the 7 criteria (prep package §1.2)

Measured numbers: A = reader_a.py, 640 non-blank lines (533 code), 33,595 B; B = reader_b.py, 606 non-blank lines (513 code), 30,991 B. Shared data: transcript.py 276 non-blank lines; bundle F 2,486 B, bundle D 276 B, F+D 2,762 B; transcript records 2,763 B. Derivation machinery alone is ~130 lines in each reader (A: matcher + closure + safety + provenance; B: ancestor walk + derived checks + translation checker + witness builder). The ~400 remaining lines in each file are the shared-shape admission/action/guard/commit code.

#CriterionReader AReader BReading
1Trusted size640 lines / 33.6 KB total; derivation ~130 lines606 lines / 31.0 KB total; derivation ~130 linesNearly tied in this skeleton. B is ~5% smaller overall, but the saving is not in derivation machinery — it is in the mark-boundary adapter (no ROOT terminator) and the shorter grant action. The dominant cost in both is the shared admission/guard/commit code, which B does not remove. A real size win for B would have to come from deleting shared machinery, not from the derivation swap. Premise inventory: same as experiments/mark-boundary/premises.json plus: finite closure, matching/substitution, rule safety, provenance (A); or: ancestor walk, translation check, sibling-order maintenance (B).
2Definition sizeBundle F+D 2,762 B + transcript 2,763 B as writtenSame bundle bytes as input, but B additionally requires the derived definitions to be supplied (in F: in, within; in D: principal)Same input bytes; different acceptance condition. B's definitions are not smaller — the traversal definitions are spelled out in the bundle alongside the rules they replace. What B saves is not definition bytes but the absence of a rule engine to interpret them. If the derived definitions were ever counted as extra definitions, B's admitted-definition size is larger.
3Evaluation boundsWorst case: at most Σ_p \D\^arity(p) derived tuples; each closure iteration applies every rule; measured on the transcript: 242 closure iterations, 1,078 rule applications (closure is recomputed on every guard query — the skeleton's real cost)Worst case: one query walks one ancestor chain, ≤ MAX_PATH (1,024) steps; measured: 238 walk steps, 63 derived queries; no recomputationB is cheaper per query and the gap grows with domain size. A's cost is per-closure (whole-relation recomputation per guard); B's is per-chain. A's bound is a global tuple count; B's is a local path length. Both honour the limit rule: exhaustion raises EvaluationLimit, never False. A's skeleton needs incremental closure or memoisation before it is affordable at any size; B's needs nothing for this transcript.
4ExpressivenessAll eight note-15 forms as written: relation, rule (general positive recursion), action, activate, invoke, fresh, emit, retire. Arbitrary positive recursive rules; arbitrary graph reachability; multi-parent membership expressible as data.Seven forms as written; rule only as an acyclic derived definition supplied alongside. Recursive rules refused unless translated. Single-parent forest only: no multi-parent membership, no arbitrary graph reachability, no recursive delegation, no recursive domain inference.A is strictly more expressive; B is a restriction, not a reimplementation. On this transcript they coincide, because the transcript's only recursion is forest containment and its only derived rule besides that is acyclic. That coincidence is transcript-relative and must not be read as equivalence.
5Explanation qualityProof witness: rule id + supporting base occurrences, recursively. E.g. in(A,R): in-trans ← #16 parent(A,C) + in(C,R) ← in-trans ← #13 parent(C,B) + in(B,R) ← in-base ← #11 parent(B,R). principal(P): principal-rule ← #9 entity(P) + #14 binding_verified(P,CP).Witness chain: in(A,R) ← ancestor chain [5, 7, 3, 1]; principal(P) ← entity(9) + binding occurrence [14].**Both explain; A explains why a rule applied, B explains which path holds.** A's witness names the rule and can compose across predicates; B's witness is shorter and directly checkable by walking. A can also explain a refusal by naming the guard that fired (both readers do this identically, since guards are shared). Neither enumerates every proof path (note 15 §5: there can be infinitely many).
6BooksPaired transfer with exact int arithmetic, range limits, conservation check on the staged delta; all four failure modes refuse with the intended guard.Identical: same transfer, same guards, same conservation check.Tied. Books here is a guarded consume/produce delta in both readers (note 18 §8), and the delta machinery is shared-shape. Neither reader does aggregate sums, so neither covers "Books" in the full accounting sense — only the paired local transfer.
7Failure behaviourRefused pre-activation use leaves K/B unchanged (P0/P2, Bn empty / unchanged). Spent grant refuses (unknown_occurrence, #15 not live). Second GENESIS refused. Limit exhaustion → EvaluationLimit, never False. Unsafe rule refused at proposal.Identical on every probe.Tied on the transcript. Both refuse deterministically with a named guard, commit atomically, and advance audit history only on refusal. The one behavioural difference is where a definition fails: A can fail at evaluation time (closure budget), B fails earlier, at proposal time (untranslatable rule).

Verdict — they differ in kind, not just quality

No winner is forced, because the two readers are not two attempts at the same thing:

  • Reader A is a general language (finite positive recursion as data) with a forest transcript as one application. Its cost is a closure engine and per-query recomputation; its benefit is that new domain rules — recursive delegation, multi-parent membership, arbitrary reachability — are admitted as definitions without new reader code.
  • Reader B is a restricted machine (one forest + acyclic derived expressions) that reproduces this transcript's observations with cheaper per-query evaluation. Its cost is a translation obligation: every recursive definition must be re-expressed as a traversal, and anything that cannot be so expressed is refused. Its benefit is a smaller derivation core per query and witnesses that are paths rather than proof trees.

On the evidence of these two inputs alone, B reproduces everything A does — but that is evidence about this forest transcript, not about STREAM's wider operators. Per note 18 §6 and the prep package decision rule, A stays the reference semantics until the wider operators (the eight forms in general, the Books beyond paired transfer, refusal rules, delegation, multiple memberships, matrix row-crossing) are expressed in both and B's restrictions are shown sufficient. The concrete next test is note 18 §9's: express IN, IS, MAY and TO as typed guarded rewrites in both readers and mark which parts share machinery and which need distinct laws. The TO/Books extension past paired transfer and a recursive-delegation example are the sharpest discriminators: A admits them as rules, B must either translate or refuse, and that outcome — not the transcript tie — decides whether B's restrictions suffice.

What each reader can and cannot do yet

Both (shared limits): no canonical byte encoding, no hashes / signatures / durable storage (integrity profile out of scope, note 15 §2); no cross-log governance, clocks, or physical-effect dispatch; no aggregate sums; complete-scope not-exists assumes a complete local replica (a partial replica returns Unknown — implemented as a refusal in A, unimplemented in B, which only does forest-chain absence); refusal precedence is deterministic but not yet canonically specified (note 16 §7); no second implementation to cross-check against (this is the second implementation, for the transcript only).

Reader A cannot yet: evaluate affordably — holds() recomputes the full closure on every guard query (1,078 rule applications for a 16-step transcript); needs incremental closure or memoisation, plus truth maintenance across retractions (currently full recompute, which is correct but slow). Cannot explain which guard ordering is canonical. Cannot run the mark-boundary fixture without the ROOT terminator adapter.

Reader B cannot yet (by design): accept any recursive rule without a supplied translation; express multi-parent membership, arbitrary graph reachability, recursive delegation, or recursive domain inference; answer general absence queries (only complete-chain checks); or claim byte compatibility with A — the same bundle runs in both only because the translations were supplied in the bundle data. Its _check_translations dependency walk covers only the proposed bundle's rules (no active general rules exist by construction), so a future extension admitting acyclic rules would need the check extended. Its sibling-order maintenance (_reorder_children) rebuilds a dict per relocate — correct, but order is carried by dict insertion order, which is implicit machinery worth making explicit if B grows.

Full run outputs

  • reader-a-transcript.txt — Reader A: transcript with Kn/Bn/Cn after every step, retry/scope/Books/probes, mark-boundary trace.
  • reader-b-transcript.txt — Reader B: same sections; additionally records each rule translation in the state notes after every step.
  • metrics.json — LOC, file bytes, definition bytes, metering counts, and the six transcript checks (all true in both readers).