Repository navigation
Description
Summary
LTM analysis is blind to the IMPLICIT graphical-function application on value-bearing, tables-carrying variables (the WITH LOOKUP shape: a variable that has a gf AND a real input equation). At compile time, apply_implicit_with_lookup in src/simlin-engine/src/compiler/mod.rs lowers such a variable to LOOKUP(self, input), so the simulated value has the gf applied. LTM, however, works from the variable's raw Expr2 AST / equation text, where the gf is invisible. Two concrete consequences:
1. Structural link polarity ignores the gf
ltm/graph.rs::get_link_polarity -> ltm/polarity.rs::analyze_link_polarity analyzes only the target's Expr2 AST -- the raw input equation. The gf-polarity machinery (analyze_graphical_function_polarity, fold_per_element_table_polarity, lookup_table_polarity) only fires for EXPLICIT LOOKUP(table, x) calls in the equation text. For a with-lookup variable whose gf is monotone DECREASING, the polarity of every input -> target link should be flipped (composed with the gf's polarity), but it is not -- the link is classified from the raw input equation alone. This misclassifies link polarity and hence loop polarity (R/B loop IDs) for a very common SD idiom.
2. Runtime link scores compare mismatched quantities
The ceteris-paribus partial (ltm_augment.rs::build_partial_equation_shaped, sourced from scalar_or_a2a_target_equation_text and the arrayed equivalents) re-evaluates the target's RAW input equation with selected references held at PREVIOUS(). That partial is in "gf input" units. The target's actual simulated value HAS the gf applied (post-lowering), so it is in "gf output" units. The link score therefore ratios a partial delta and an actual delta that live on different scales / through a nonlinear map, producing wrong link scores (and downstream loop scores) for with-lookup variables.
Scope / history
- This is PRE-EXISTING for scalar with-lookup variables -- it predates engine: graphical function not auto-applied to value-bearing arrayed variables (Stella divergence) #909 and the conveyor-engine branch.
- The engine: graphical function not auto-applied to value-bearing arrayed variables (Stella divergence) #909 fix (applying the implicit wrap per element on arrayed variables, matching Stella) extends the set of variables whose simulated values include the implicit gf, so the LTM blind spot now covers arrayed with-lookup shapes too.
Distinct from adjacent (closed) issues
- ltm: support per-element graphical functions in static link polarity analysis #502 covered EXPLICIT
LOOKUP(table[elem], x)subscripted-table polarity; here the equation text contains noLOOKUPcall at all. - ltm: synthetic-fragment compilation uses an empty tables map, so link scores into graphical-function targets stub to 0 #546 covered the empty
tablesmap in LTM synthetic-fragment compilation; fragments compile fine here -- they just encode the wrong (un-wrapped) partial.
Component(s) affected
src/simlin-engine/src/ltm/graph.rs(get_link_polarity)src/simlin-engine/src/ltm/polarity.rs(analyze_link_polarityand the gf-polarity helpers)src/simlin-engine/src/ltm_augment.rs(build_partial_equation_shapedand the target-equation-text sources)- Downstream: loop polarity classification and every link/loop score through a with-lookup variable
Possible fix directions
- Polarity: when the link target is a value-bearing tables-carrying variable, compose the equation-derived polarity with the gf's monotonicity (reusing
analyze_graphical_function_polarity/fold_per_element_table_polarityfor the per-element case), exactly as the explicit-LOOKUParm already does. - Runtime scores: build the partial from the LOWERED equation shape -- i.e. wrap the partial's raw-input expression in the same
LOOKUP(self, ...)application the compiler performs -- so partial and actual deltas are commensurable. Alternatively, perform the implicit-with-lookup lowering earlier (at a stage LTM also consumes) so both the VM and LTM see the same AST.
Discovery context
Identified while fixing #909 (implicit WITH LOOKUP application for arrayed variables) on branch conveyor-engine. Part of the LTM epic #488.
Activity
engine: apply the implicit WITH-LOOKUP wrap to arrayed variables
engine: apply the implicit WITH-LOOKUP wrap to arrayed variables