Skip to content

Reference nested abstractions instead of skipping them - #377

Open
kavigupta wants to merge 1 commit into
ns-abstraction-lambda-fusionfrom
ns-abstraction-nested-refs
Open

Reference nested abstractions instead of skipping them#377
kavigupta wants to merge 1 commit into
ns-abstraction-lambda-fusionfrom
ns-abstraction-nested-refs

Conversation

@kavigupta

Copy link
Copy Markdown
Owner

PR 3 of 4. Stacks on #376.

What

When one abstraction is defined in terms of another, DreamCoder inlines the inner one as a nested #(lambda ...). The converter descended into it and failed, skipping the outer abstraction.

Each abstraction is added to the DSL under its full #(lambda ...) string as its symbol. So we build a stitch name_mapping from the abstractions already in the DSL and rewrite inlined occurrences to opaque placeholders (longest first, so a nested-in-nested invention isn't mangled) before the de Bruijn conversion — then map each placeholder back to the referenced production and emit a reference.

Composes with lambda fusion: a referenced abstraction inside a fused multi-argument lambda is remapped correctly. If the referent isn't in the DSL yet, the outer abstraction is still skipped.

Reproducing test

tests/s_exp/dreamcoder_abstractions_test.py::TestNestedAbstractionReferences

  • outer applies inner #(lambda (gt? 1 (sum $0))): None before inner is added, [i] -> b (body references the inner production) after
  • referenced abstraction inside a fused mapi_3 lambda → [[i]] -> [b]

🤖 Generated with Claude Code

When one abstraction is defined in terms of another, DreamCoder inlines the
inner one as a nested `#(lambda ...)`. Previously the converter descended into
it and failed, skipping the outer abstraction.

Each abstraction is added to the DSL under its full `#(lambda ...)` string as
its symbol, so build a stitch name_mapping from the abstractions already in the
DSL and rewrite inlined occurrences to opaque placeholders (longest first)
before the de Bruijn conversion -- then map each placeholder back to the
referenced production and emit a reference to it. Composes with lambda fusion:
a referenced abstraction inside a fused multi-argument lambda is remapped
correctly. If the referenced abstraction is not (yet) in the DSL, the outer one
is still skipped.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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