Repository navigation
Description
Summary
The mixed-loop branch in build_element_level_loops (src/simlin-engine/src/db_ltm.rs:2247-2320) handles cross-element circuits — those that arise when a wildcard reducer like SUM(pop[*]) connects array elements through a scalar aggregate. The current treatment scores such loops as scalar loops whose links reference the diagonal A2A link score values (the {from}->{to} Bare-shape variable), on the rationale that "the wildcard reducer already encodes the cross-element contribution as a single A2A link-score value per neighbour."
A truly principled treatment would normalize the cross-element link score against the change in the aggregate (e.g., SUM(pop[*])), not against per-element Δsource. The diagonal A2A score asks "how much of Δshare[NYC] came from Δpop[NYC]" but a cross-element link pop[Boston] -> share[NYC] (via SUM(pop[*])) is asking "how much of Δshare[NYC] came from Δpop[Boston]" — these are different quantities.
Why this matters
For models where wildcard reducers aggregate magnitudes that don't differ wildly per element, the approximation is reasonable — relative loop scores are still in the right ballpark and dominance ordering is usually preserved. For models with highly heterogeneous element magnitudes (e.g., a large-population region dominating SUM(pop[*])), the diagonal link score systematically over-counts each element's individual contribution and under-counts cross-element coupling.
The implementation acknowledges this explicitly in shape_aware_source_ref (src/simlin-engine/src/ltm_augment.rs:732-738):
- `Wildcard` / `DynamicIndex` -> `from` (TODO: the truly principled
denominator would be the change in the aggregate
`SUM(from[*])` / `from[expr]` referenced live in the partial,
but that requires re-parsing partial_eq or threading the AST
subtree through. For now we keep the variable-level Δfrom; the
resulting under/over-counting is the same documented edge-
aliasing limitation already pinned by integration tests).
Locations
- Comment documenting the approximation:
src/simlin-engine/src/ltm_augment.rs:732-738 - Cross-element circuit treatment:
src/simlin-engine/src/db_ltm.rs:2247-2320 - Test fixture:
test/cross_element_ltm - Related design plan:
docs/design-plans/2026-04-25-ltm-per-ref-elem-graph.md
Suggested fix
- When generating a link score for a
Wildcard/DynamicIndexshape, thread the actual aggregate expression (e.g.,SUM(from[*])as it appears in the target's AST) through toshape_aware_source_refso the SAFEDIV denominator can be(aggregate - PREVIOUS(aggregate))instead of(from - PREVIOUS(from)). - Cross-element loop scoring in
build_element_level_loopsshould then reference the wildcard-shaped link score (suffixed with\u{205A}wildcard) directly rather than collapsing to the Bare diagonal. - Validate against
test/cross_element_ltmand add a fixture with heterogeneous element magnitudes to exercise the discrepancy.
Paper reference
Schoenberg, Hayward, Eberlein 2023 "Improving Loops that Matter," Eq. 3 establishes the link score's denominator semantics. The cross-element / aggregate-reducer case is not covered in the literature, which is why this is a Simlin-specific extension that should match Eq. 3's spirit.
Severity
medium (silent correctness — under/over-counting in a documented edge case; relative ordering of dominant loops typically preserved on homogeneous arrays, but breaks down on heterogeneous element magnitudes)
Discovery context
Identified during a deep design review of the Loops That Matter implementation against the reference papers, examining the gap between the documented TODO in shape_aware_source_ref and the cross-element handling in build_element_level_loops.
Tracking
Part of LTM tracking epic: #488. Sister issue to #487 (rel_loop_score partition normalisation), which addresses a different normalization gap (cross-loop partition lookup) using the same Loop-level machinery this issue would also touch.
Activity
doc: add LTM cross-element aggregate scoring design plan
bpowers commentedon May 9, 2026
Resolved by commits a05c921..4ff1ab4 on branch ltm-503-cross-element-agg (key commits: 44527d1
enumerate_agg_nodes, 3eca55f element-graph reroute through agg nodes, 9a59777 $⁚ltm⁚agg auxiliaries, fdaa06b agg-node link scores, c252286 recover cross-element loops through agg nodes, d14c978 score cross-element loops on the element-level path, 49be92d retire the wildcard/dynamic per-shape link-score path).Implemented via the aggregate-node approach rather than the threading-
SUM(from[*])-through-shape_aware_source_refapproach this issue originally sketched: each maximal inlined reducer subexpression is hoisted into a synthetic $⁚ltm⁚agg⁚{n} auxiliary (mirroring how the LTM papers handle DELAY3/SMOOTH internal structure), causality is routedpop[d] → agg → target, the two halves are scored with real per-element link scores and composed by the chain rule (so each source element's fractional contribution to the aggregate's velocity is recovered -- exactly the missing factor for heterogeneous element magnitudes), the agg node is trimmed from the user-facing loop list, cross-element loops are scored on the element-level path with subscripted link-score refs, and the⁚wildcard/⁚dynamicper-shape link-score machinery (and theshape_aware_source_refTODO this issue quotes) was retired.See docs/design-plans/2026-05-09-ltm-503-cross-element-agg.md and the 'Aggregate Nodes' section of docs/design/ltm--loops-that-matter.md. Two follow-ups remain tracked: GH #514 (sliced reducer sub-expressions not yet hoisted), GH #515 (MAX_AGG_PETALS cap on cross-agg loop recovery), GH #516 (agg-hop link polarity Undetermined).
engine: LTM cross-element aggregate scoring (aggregate nodes) (#519)