Skip to content

Size-aware base-case weights + RecAwareGradedScore#53

Open
segevem wants to merge 5 commits into
mainfrom
size-aware-base-weights
Open

Size-aware base-case weights + RecAwareGradedScore#53
segevem wants to merge 5 commits into
mainfrom
size-aware-base-weights

Conversation

@segevem

@segevem segevem commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds RecAwareGradedScore: a scorer that distinguishes direct recursion (Source.Rec) from same-inductive cross-mode calls (Source.NonRec targeting the same inductive with different output indices or derive sort), preferring direct recursion as the simpler pattern
  • Passes runtime size' to non-recursive constructor weight functions/modifiers in the size>0 branch (literal 0 in size=0), enabling modifiers that scale base-case probability with depth
  • Refactors compileWeightedProducer into compileSubProducer + wrapWithWeight — compiles the sub-producer body once and wraps it with different weight terms per size branch
  • Adds inverseScaleBase weight modifier to BoundedBuffer: max 1 (baseWeight / (size + 1))
  • Adds generator quality regression tests for SafeBBTrace and EveryBBTrace

Context

Switching BoundedBuffer to RecAwareGradedScore exposed a latent issue with balancedCtorWeight: EveryBBTrace.All_Empty has a trivially perfect schedule (density=Total, badness=0.0) which gets quality=4 → base weight 16. The recursive All_Op (badness=0.91) gets quality=1 → weight=size. At size=10: P(base)=62%, producing 668/1000 empty traces.

The fix passes runtime size to weight modifiers so they can reduce base-case weight as depth increases. With inverseScaleBase, empty traces drop to ~95/1000 and both SafeBBTrace and EveryBBTrace produce comparable trace lengths.

Test plan

  • lake build passes
  • #guard_msgs quality tests pass (>2000 ops, <20% empty, >100 successful gets per 1000 samples)
  • Existing differential tests and backwardOnlySizeOps still pass
  • No regression in other test files (codegen is backwards-compatible — built-in weight functions ignore size for non-rec ctors)

Segev Elazar-Mittelman added 5 commits July 10, 2026 18:40
Non-recursive constructors now receive the actual `size'` in the size>0
branch (and literal 0 in the size=0 branch) instead of always getting 0.
This lets weight modifiers scale base-case probability as a function of
recursion depth.

Refactors compileWeightedProducer into compileSubProducer + wrapWithWeight
so the sub-producer body is compiled once and wrapped with different weight
terms for each size branch.

Adds `inverseScaleBase` modifier to BoundedBuffer that smoothly reduces
base-case dominance as size grows: `max 1 (baseWeight / (size + 1))`.
Without this, EveryBBTrace.All_Empty (badness=0 → weight 16) produced
668/1000 empty traces; with it, only ~95/1000 are empty.

Adds generator quality regression tests for SafeBBTrace and EveryBBTrace.
…mode calls

Instead of relying on inProgress memo state (which depends on
derivation order), detect mutual recursion structurally: a NonRec dep
that targets the same inductive as the current key but with different
output indices or deriveSort is a cross-mode call that will become
mutual recursion at codegen time. This is reliably visible during
scoring regardless of derivation order.
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.

1 participant