Skip to content

ltm: implicit WITH-LOOKUP gf application invisible to link polarity and runtime link scores #910

Closed

Description

@bpowers

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

Distinct from adjacent (closed) issues

Component(s) affected

  • src/simlin-engine/src/ltm/graph.rs (get_link_polarity)
  • src/simlin-engine/src/ltm/polarity.rs (analyze_link_polarity and the gf-polarity helpers)
  • src/simlin-engine/src/ltm_augment.rs (build_partial_equation_shaped and 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_polarity for the per-element case), exactly as the explicit-LOOKUP arm 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions