Repository navigation
nested-membership rewrite rule: nested-Cardinality O(n²) → single-Cardinality O(n) - #5438
Closed
gunbai-bot[bot] wants to merge 7 commits into
Closed
gunbai-bot[bot] wants to merge 7 commits into
gunbai-bot[bot] wants to merge 7 commits into
Conversation
Pins the compose_child_cost AlternativeCost fix from the WIP commit: (1) bug-fix: Disj([Atom, Atom]) -> unit_cost() (was zero_cost() without floor) (2) control: symbolic_max(0, 0) == 0 — fixes the compose layer, not symbolic_max itself. Two checks together uniquely identify the correct fix vs wrong-fix alternatives. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Factors out the four-stage COMPREP pipeline chain (wave-1 producers all duplicate it) into a single parameterised fn comprep_source_resolved_root(source_text, parse_root, production_name, file) -> Outcome<Node>. Grammar validation is fail-closed before any tokenize work. D2 seed-rule test-subject producers will call this directly — no new pipeline fork. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nality rewrite rule Adds Rule 1 (nested-membership → set) D2 seed rule with full witness coverage: (a) rewrite fires on nested Cardinality input (b) class drop confirmed: ClassPolynomial(2) → ClassLinear (c) rewrite correctness: output children equal inner.children exactly (d) non-firing control: Named edge on outer → Absent (e) pipeline guard: comprep bridge resolves MVP1 loop source (bridge proved live) Grammar gap logged (nested-loop source not parseable in MVP1); dissolve-on marker attached. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lCost (unmodeled) Records that Instantiation currently maps to unit_cost() with SequentialCost, so complexity_lens cannot produce ClassExponential for naive recursive functions. This blocks the naive-recursion→memoize rewrite detection. Dissolve-on: new modeling that grounds Instantiation base cost in recursion depth (needs own runway). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3 tasks
…st_inner_cardinality `inner` from list_at_optional was staying generic T at the `match inner.kind` site, causing `no field 'kind' on type 'T'`. Extract the inner.kind check into a typed helper fn try_hoist_inner_cardinality(inner: Node) — passing `inner` to a Node-typed parameter forces T = Node unification, same pattern as node_is_callee_reference in node_query.dag. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
Paused, relocated to §5 post-stability per operator §3 reframe; branch session/proud-ferret-16-rule1 preserves nested_membership + the Instantiation→ExponentialCost gap marker for §5 pickup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Follow-up to #5437 (cost-lens AlternativeCost floor + comprep bridge). Depends on that PR for
comprep_source_resolved_root(the pipeline bridge). Rule 1 of the D2 complexity-reduction catalog.What this adds
Rule:
nested_membership(src/v2/lens/rewrite/nested_membership.dag)Rewrites a nested
Cardinality(outer wraps inner — O(n·m)) to a singleCardinalitywith the inner node's children hoisted directly (O(n)). Models: precompute the membership set once; replace the inner O(n) scan with O(1) lookup.Precondition: outer has exactly one positional child (= inner Cardinality) and no Named children (no mutation coordinate in outer body — required for safe hoisting).
Test file:
src/v2/lens/rewrite/nested_membership_test.dag— 4-witness matrix + pipeline guard:try_nested_membership_rewrite(nested_slow_input)=PresentClassPolynomial(degree=2)→ClassLinear(cost_lens + complexity_lens both checked)children == inner_card.childrenexactlyAbsent🟡gap marker insrc/v2/lens/cost.dag— records thatInstantiation → unit_cost()(SequentialCost) meanscomplexity_lenscannot produceClassExponentialfor naive recursive functions. Blocks the naive-recursion→memoize rule detection. Dissolve-on: Instantiation base cost models recursion depth (new modeling, own runway).Test polarities
try_nested_membership_rewritefunction itself.cost_lensdoes not fold nested Cardinality toProductCost(Linear, Linear).Grammar gap (documented)
MVP1 grammar cannot parse nested-loop source text (e.g.,
fn outer() -> Int { loop loop 1 }). Witnesses (a)-(d) use hand-constructed Node trees. Dissolve-on marker attached; grammar follow-up deferred.Test plan
cargo test --workspacepassescargo clippy --all-targets -- -D warningscleantest fns enrolled by CI floor naming convention (nested_membership_test.dag)comprep_source_resolved_root)🤖 Generated with Claude Code