Skip to content

chart: forest-equality differential against V1's pipeline (toys, seeds 4 and 44) - #658

Merged
perigrin merged 8 commits into
pufrom
chart/w4-forest-equality-harness
Nov 26, 2026
Merged

perigrin merged 8 commits into
pufrom
chart/w4-forest-equality-harness

Conversation

@perigrin

Copy link
Copy Markdown
Owner

Summary

This adds the forest-equality differential for chart-perly-w4. It compares production's forest before resolve with V1's pipeline, which is the unjudged recognizer, then LibraryOperators, Build and Constrain. The comparison runs over the toys and seeds 4 and 44, plus a fixture that exercises V1's union shortcut.

  • ForestDiff compares the verdict first, then the reachable nodes by (symbol, rule position, span), then the kept alternatives in order.
  • The V1 side is exported as V1Recognizer, V1Forest and V1ToyForest, so later differentials reuse it. Its LibraryOperators and Constrain go through hooks that tests count.
  • The candidate side is the swappable CandidateForest and CandidateToyForest. A test requires that the candidates never enter V1's hooked stages, so a differential cannot compare V1 with itself.
  • parseStream is split at resolve into constrainedStream. Its behaviour is unchanged, and resolved-forest-digest.golden is byte-identical.
  • README: the forest-equality bullet in the precedence section of internal/chart/README.md, committed first.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7

Gate

The gate ran at Tier 2, with alignment, architecture and review applied inline.

  • Pass 1 reopened the issue at 7661a9f5. The candidate variables could be redefined as the V1 side and stay green (F1), and one README sentence overstated what the tests log (F2).
  • Pass 2 passed at d6fe1e08. The reviewer's mutations went red at candidates-are-not-v1, and the runner's 12 commands, criteria plus make test, all exited 0.

Out-of-scope findings are carried by later issues:

  • the judged candidate must not run Constrain (3282 and d218);
  • ForestDiff duplicate keys (01a217d4-9769).

Test plan

  • All 11 acceptance criteria pass at d6fe1e08.
  • T1_CORPUS=/opt/corpora/PerlOnJava/src/test/resources/unit make test passes.
  • A mutation check shows the differential detects renumbering, unreachable nodes, rule-position changes, dropped or reordered alternatives, a flipped verdict, and a V1-side candidate.

Generated by Claude Code

The precedence section gains a bullet naming ForestDiff, the V1 side
and the candidate, and the tests that show the comparison can fail
before the recognizer changes, ahead of the code (live document first).
The shared section is rewritten whole by the milestone's docs issue.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDSkrXBzd3pd6nDkewof8N
ForestDiff compares a candidate's forest with V1's: the verdict, the
nodes reachable from the root, matched by symbol, rule position and
span rather than by index, and each reachable node's kept alternatives
in order. TestForestEqualityDetectsPerturbation shows a dropped
alternative, reordered alternatives, an added and a removed reachable
node, a flipped verdict and a changed rule or dot each reported by the
comparison that owns it, and equal forests, a renumbered forest and an
added unreachable node reported by none. Each comparison was disabled
in turn and its subtest went red.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDSkrXBzd3pd6nDkewof8N
…nizer

V1Forest and V1ToyForest are V1's pipeline: the recognizer V1Recognizer
builds, which only ever judges no precedence, then Build,
LibraryOperators for a source, then Constrain, each stage entered
through the V1 side's own hooks. The V1 side's chart accepts
print $fh [];, $a <=> $b <=> $c; and 1 .. 2 .. 3; and its Constrain
refuses each, so a V1 side running the judged recognizer fails; and it
enters its own LibraryOperators and Constrain once per input, so a V1
side wired to production's output fails. Each was shown red by
mutation: Constrain skipped, the chart refusing, the side wired to
ParseWith, and either hook bypassed.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDSkrXBzd3pd6nDkewof8N
…seeds 4 and 44

CandidateForest is production's forest before resolve: parseStream now
ends at constrainedStream, which resolve and the readings count follow,
so the candidate is what ParseWith judges with nothing taken away.
CandidateToyForest is production's recognizer, Build and Constrain over
a toy's own precedence. Both are variables a later issue can point at
the judged recognizer.

TestForestEqualityToys compares 4395 of 4395 toy sentences and
TestForestEqualityGeneratedSentences 20083 of 20083 seed-4 and 15000 of
15000 seed-44 sentences, each requiring both verdicts among them; the
seed generators are now functions both differentials share.
TestForestEqualityHarnessesUseCandidate swaps in a candidate that
refuses everything and requires both loops to report it, so neither
compares V1 with itself. empty-input and both-refuse join the
perturbation subtests. Shown red by mutation: each loop comparing V1
with itself, compared counting only accepted inputs, and either
candidate skipping Constrain.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDSkrXBzd3pd6nDkewof8N
…erential

No corpus file takes Constrain's shortcut: (C5), so the differential
gains a constructed input, STDOUT isa my $m | 1;, on which V1's
judgement keeps the term over isa my $m | 1 under two contexts with two
different non-empty alternative sets, {35} and {34 35}, and keeps
their union. contextAltSets reads each context's set apart by mark's
own loop without marking; the test logs and requires
contexts: 2, distinct non-empty alternative sets: 2, holds the
measurement to Constrain's kept set as a union on every node of 2413
accepted inputs (the toys, the 83 handcrafted sentences,
_ - $h{1} - $fh; and TestPrecedenceMarkFirstFilter's toy), and requires
the candidate's forest to equal V1's. Shown red by mutation: contexts
merged, mark's first-terminal filter or reduce check dropped, V1
skipping Constrain, the candidate skipping Constrain, and an input that
takes no shortcut.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDSkrXBzd3pd6nDkewof8N
The simplify pass inlines a single-use lexer helper and computes each
subtest's reachable nodes once. The README's differential bullet names
TestForestEqualityHarnessesUseCandidate, which holds that neither loop
compares V1 with itself. make test passes with T1_CORPUS set.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDSkrXBzd3pd6nDkewof8N
… differentials

Gate finding F2: TestForestEqualityUnionShortcut logs one input, not a
compared-of-loaded count, so the README's claim names the two
differentials that make it. The bullet also says the harness test holds
that the candidates never enter the V1 side's stages (F1), ahead of the
test.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDSkrXBzd3pd6nDkewof8N
… side

Gate finding F1: TestForestEqualityHarnessesUseCandidate proved the
loops call the candidate variables but not what those variables are, so
CandidateForest = V1Forest (M15) or CandidateToyForest = V1ToyForest
(M16) left every TestForestEquality test green. The new subtest
candidates-are-not-v1 wraps the V1 side's LibraryOperators and Constrain
hooks to count, runs CandidateForest on three sources and
CandidateToyForest on twenty ladder sentences, and requires no entry.
Under M15 and M16 it goes red, entered 6 times each; green as committed.

Implements: 01a21447-d0ba-7afb-8ead-01525fd151d7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDSkrXBzd3pd6nDkewof8N
@perigrin
perigrin merged commit 7ae358d into pu Nov 26, 2026
6 of 7 checks passed
@perigrin
perigrin deleted the chart/w4-forest-equality-harness branch November 26, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants