Repository navigation
Description
Summary
expand_same_element in src/simlin-engine/src/db_analysis.rs (~lines 335-463) -- the helper that projects a same-element / shared-dims LTM element-graph edge into per-element edges -- matches source and target dimensions by name only (to_dim_positions: HashMap<&str, usize> keyed on to_dims.iter().map(|d| d.name()), then from_to_target_pos = from_dims.iter().map(|d| to_dim_positions.get(d.name()))). When the element-graph edge runs from a source over one dimension to a target over a differently-named but mapped dimension -- e.g. source over Region={a,b}, target over State={s1,s2,s3} with a State→Region mapping (the AC3.5 case in Phase 3 of the LTM arrays hardening epic, where an x[State] reference inside an A2A target[State] equation now classifies RefShape::Bare via classify_iterated_dim_shape) -- Region and State are different names, so from_to_target_pos records None for the source dimension, all_mapped is false, and the broadcast branch (lines 423-461) fires: it emits the full Region × State cross-product of element edges (x[a]→target[s1], x[a]→target[s2], x[a]→target[s3], x[b]→target[s1], ...) rather than the positional-mapping diagonal the State→Region mapping defines (s1↦a, s2↦a, s3↦b or whatever the mapping says ⇒ x[a]→target[s1], x[a]→target[s2], x[b]→target[s3]).
This is pre-existing -- not introduced by Phase 3. Phase 3's element_graph_mapped_iterated_dim_matches_bare_baseline test (src/simlin-engine/src/db_element_graph_tests.rs:~906) deliberately asserts only that the new iterated-dim-subscript form (target[State] = x[State] * c) produces the same element edges as the old bare-reference form (target[State] = x * c) -- i.e. no regression -- and its doc comment explicitly notes: "expand_same_element matches dimension names, so a disjoint-named pair like Region/State is the broadcast case (every source element feeds every target element) for both the subscripted and the bare form; the assertion below pins 'subscripted iterated == bare', not the projection shape." So the over-conservatism is on record in a test comment but not in an issue.
Why it matters
Low impact. Over-conservative element edges mean a few extra spurious causal edges in the element graph for mapped-dimension models -- which can slightly inflate which loops/edges get enumerated and scored -- but it is not a correctness violation of the LTM contract: more edges than necessary, never fewer (every emitted edge for a true cross-product would have a real link score; the spurious ones get effectively-zero runtime scores, the same way pre-#448 FixedIndex N×N over-approximation did before that was fixed). Only models that actually use dimension mappings (a <dimension ... maps_to> / simlin:mapping) between the source and target of a same-element LTM edge are affected.
Components affected
src/simlin-engine/src/db_analysis.rs--expand_same_element(~lines 335-463; the by-nameto_dim_positionslookup and theall_mapped-false broadcast fallback), and its callers inemit_edges_for_reference(theRefShape::Barearrayed arm, ~lines 214-250)src/simlin-engine/src/dimensions.rs--DimensionsContext::has_mapping_to/SubdimensionRelation(the element-level mapping data a mapping-aware projection would consult)src/simlin-engine/src/db_element_graph_tests.rs--element_graph_mapped_iterated_dim_matches_bare_baseline(~line 906; would gain a stronger assertion once the projection is mapping-aware)
Possible approaches
- Make
expand_same_elementmapping-aware: when a source dimension has no same-name target dimension, check whether some target dimension maps to it (or it maps to some target dimension) via theDimensionsContext, and if so project along the mapping's element correspondence instead of broadcasting. This would needexpand_same_element(andemit_edges_for_reference) to take a&DimensionsContext-- whichdb_ltm_ir'sclassify_iterated_dim_shapealready threads in for the AC3.5 recognition, so the data is available at the call site. - Once mapping-aware, strengthen the
element_graph_mapped_iterated_dim_matches_bare_baselinetest (and/ordb_ltm_ir_tests::ir_mapped_iterated_dim_subscript_is_bare's downstream edge check) to assert the diagonal edge set, not just "subscripted == bare".
Discovery context
Identified during the Phase 3 code review of the LTM arrays hardening epic (#488; design plan and per-phase tasks under docs/implementation-plans/2026-05-11-ltm-arrays-hardening/, see phase_03.md AC3.5 and the element_graph_mapped_iterated_dim_matches_bare_baseline test). Pre-existing on main -- not a regression; Phase 3's element_graph_mapped_iterated_dim_matches_bare_baseline test correctly asserts the new iterated-dim form is no worse than the existing bare form.
Tracking
Part of LTM tracking epic #488. Related to #448 (FixedIndex N×N over-approximation -- closed; the analogous fix replaced an all-pairs expansion with a per-reference RefShape emitter; this is the same flavor of over-approximation but for the mapped-dimension same-element projection rather than FixedIndex), #511/#525 (iterated-dim subscript handling), and the LTM array-support umbrella #273.
Activity
bpowers commentedon Jun 10, 2026
Note for e2e testing: simulating a different-cardinality element-mapped model (e.g. State{s1,s2,s3} -> Region{a,b} many-to-one) currently fails at engine compile with
failed to compile fragments-- a pre-existing engine gap, not LTM. The element graph handles the shape correctly. Tracked in #753; until it's fixed, e2e coverage of the diagonal is limited to same-cardinality (incl. permuted) mappings.engine: gate mapped link-score dims on a bare-classified site
engine: ltm describes the executed read
engine: ltm describes the executed read
engine: one ordinal fallback for undeclared dimension pairs