Description
In db_analysis.rs, fixed-index subscript references like source[NYC] in A2A (array-to-array) equations are classified as CrossElement, which creates a full NxN cross-product of edges in the element-level causal graph. This is an over-approximation -- the correct behavior would be to create edges only from the specifically referenced element(s) to all target elements.
For example, if variable x is dimensioned over Cities (NYC, LA, CHI) and its equation references source[NYC], the current code creates edges from all 3 elements of source to all 3 elements of x (9 edges). The correct result would be 3 edges: from source[NYC] to each of x[NYC], x[LA], x[CHI].
Why it matters
- Correctness: The false edges could theoretically merge otherwise independent stock partitions in cycle analysis, leading to spurious feedback loops being reported.
- Precision: The element-level causal graph carries unnecessary edges that reduce the analytical value of the graph.
- Maintainability: The current behavior has been flagged in code review 3 times as P1 but deferred each time because the practical impact is minimal.
The practical impact today is minimal because the false edges receive zero link scores and do not affect loop scoring. However, as the LTM analysis matures and is used for more downstream purposes, the imprecision could become material.
Component(s) affected
src/simlin-engine/src/db_analysis.rs -- classify_in_expr function and ElementDependencyKind enum
Proposed approach
- Add a
FixedElement variant to ElementDependencyKind that carries the specific element index/indices being referenced.
- Thread dimension context through
classify_in_expr so it can resolve subscript names to element indices.
- When building element-level edges,
FixedElement would create edges only from the specified source element(s) to the target elements, rather than the full cross-product.
Context
Identified during code review of LTM array support on the ltm-arrays branch. The issue has been flagged in review 3 times as P1 but deferred due to the zero-link-score mitigation making the practical impact negligible for current use cases.
Description
In
db_analysis.rs, fixed-index subscript references likesource[NYC]in A2A (array-to-array) equations are classified asCrossElement, which creates a full NxN cross-product of edges in the element-level causal graph. This is an over-approximation -- the correct behavior would be to create edges only from the specifically referenced element(s) to all target elements.For example, if variable
xis dimensioned overCities(NYC, LA, CHI) and its equation referencessource[NYC], the current code creates edges from all 3 elements ofsourceto all 3 elements ofx(9 edges). The correct result would be 3 edges: fromsource[NYC]to each ofx[NYC],x[LA],x[CHI].Why it matters
The practical impact today is minimal because the false edges receive zero link scores and do not affect loop scoring. However, as the LTM analysis matures and is used for more downstream purposes, the imprecision could become material.
Component(s) affected
src/simlin-engine/src/db_analysis.rs--classify_in_exprfunction andElementDependencyKindenumProposed approach
FixedElementvariant toElementDependencyKindthat carries the specific element index/indices being referenced.classify_in_exprso it can resolve subscript names to element indices.FixedElementwould create edges only from the specified source element(s) to the target elements, rather than the full cross-product.Context
Identified during code review of LTM array support on the
ltm-arraysbranch. The issue has been flagged in review 3 times as P1 but deferred due to the zero-link-score mitigation making the practical impact negligible for current use cases.