Repository navigation
Description
Summary
is_other_dep_iterated_dim_subscript in src/simlin-engine/src/ltm_augment.rs (~lines 105-138) is the recognition predicate the LTM partial-equation builder uses to decide that an iterated-dimension subscript on a non-live-source array dependency -- e.g. arr[D1,D2] inside an apply-to-all equation over D1xD2 -- can be safely collapsed to a bare PREVIOUS(arr) (instead of the codegen-rejected PREVIOUS(Subscript(arr, ...))) when wrapping it in wrap_non_matching_in_previous. This was added in Phase 3 of the LTM arrays hardening epic (#488, see docs/implementation-plans/2026-05-11-ltm-arrays-hardening/phase_03.md) alongside the #511 iterated-dim live-source recognizer.
The predicate is deliberately more permissive than the live-source recognizer (is_iterated_dim_live_ref, ~lines 60-103, which checks position-and-mapping correspondence against the source's declared dimension order). is_other_dep_iterated_dim_subscript fires on any subscript whose indices are all bare Vars naming dimension-names-that-are-target-iterated-dims, with indices.len() <= target_iterated_dims.len() -- it does not check that the indices appear in the same order the dep declares its dimensions. So a transposed reference arr[D2,D1] inside an apply-to-all equation over D1xD2 (where arr is declared over D1xD2) matches, and wrap_non_matching_in_previous collapses it to PREVIOUS(arr). In slot (d1,d2) that freezes arr[d1,d2]_prev instead of the correct arr[d2,d1]_prev -- a magnitude error in the resulting link score. (The SIGN factor is preserved as long as arr is positive, so the link polarity stays correct; only the magnitude is wrong.) Same story for a "position-mismatched mapped" dep (arr over D1, dep referenced as arr[D2] where D2 maps to D1 but the position doesn't line up).
The doc comment on the function already acknowledges this: "the pathological case (dep[D2] where dep is over D1 and D2 maps to D1) would over-collapse, but such a model is already not statically scoreable in pre-#511 LTM and is out of scope here."
Why it matters
Low impact. It never produces a codegen error and never crashes -- it's conservative-by-design (collapse to bare rather than emit something codegen rejects). The imprecision is extremely niche: it requires a #511-style iterated-dim live source and a transposed (or position-mismatched-mapped) non-live array dep in the same equation, and it produces only a magnitude error in the link score for that one edge (sign preserved). Not exercised by any current model or test fixture. Worth tracking so the imprecision is on record rather than silently relied upon.
Components affected
src/simlin-engine/src/ltm_augment.rs--is_other_dep_iterated_dim_subscript(~lines 105-138),wrap_non_matching_in_previous(~lines 402+, theSubscriptarm at ~line 460 that calls the predicate then collapses to the bareVar(dep)),IteratedDimCtx- (For contrast: the live-source recognizer
is_iterated_dim_live_refat ~lines 60-103 does check position-and-mapping correspondence; this issue is that the non-live-dep recognizer intentionally does not.)
Possible approaches
- Thread the non-live dep's declared dimension order into
IteratedDimCtx(the way the source's order is already available for the live-source path) and tightenis_other_dep_iterated_dim_subscriptto require position-and-mapping correspondence -- i.e. only collapsearr[D1,D2](matching order) toPREVIOUS(arr), and for a transposed/mismatched ref either emit a properly-permutedPREVIOUSreference (aPREVIOUSof a transposed view, which would need codegen support) or fall back to a more careful per-slot treatment (synthesize a scalar "previous of this element" helper per slot, the same trick ltm-augment: subscripted-A2A-reference link-score partial fails to compile (PREVIOUS arg must be Var) #511's "Alternative" approach proposes). - At minimum, if the construct can't be scored precisely, emit a compile-time
Warningnaming the edge (mirroring the AC3.4 unscoreable-edge warning patterntry_disjoint_dim_arrayed_link_scoresalready uses) instead of silently freezing the wrong element.
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). Pre-existing-by-design as of that phase -- not a regression; the Phase 3 fixtures use natural-position references and don't trip it.
Tracking
Part of LTM tracking epic #488. Related to #511 (the iterated-dim live-source recognizer this sits next to -- but distinct: #511 is the live-reference codegen fix, this is a deliberate over-permissiveness in the non-live-dep collapse), #525 (partially-iterated arrayed subscript breaking codegen -- a different shape and a hard error, not a magnitude imprecision), and the LTM array-support umbrella #273.
Activity
engine: prove the LTM test occurrence axes against the IR