Repository navigation
Description
Summary
analyze_graphical_function_polarity in src/simlin-engine/src/ltm.rs (around ltm.rs:2341, currently lines ~2378-2404) uses a strict EPSILON = 1e-10 to classify a graphical function as monotonically increasing, decreasing, or constant. Any per-segment slope inside [-EPSILON, +EPSILON] is treated as a plateau (which by itself is fine), but a single segment that crosses the threshold in the wrong direction collapses the whole table to Unknown.
In practice, lookup tables imported from Vensim/XMILE often carry round-trip numeric noise on the order of 1e-7 to 1e-3 (rounding during XML serialisation, conversion through float32 in legacy formats, manual data entry). With the current 1e-10 threshold, a table that is monotonically non-decreasing modulo noise -- e.g. y values [0.0, 0.5000001, 0.4999999, 1.0, 1.5] -- gets classified Unknown because of the second segment, even though the function is unambiguously increasing in spirit and in every other measure.
This is the second half of #480; the array-reducer half is being fixed in PR #491 and the polarity-analyzer reducer cases are already addressed there. This issue tracks the GF-monotonicity epsilon concern separately, so it can be picked up without re-investigating reducer behaviour.
Why this matters
Monotonic table-based relationships are very common in SD modelling (smooth dose-response curves, demand schedules, learning curves, allocation profiles). Misclassifying any of them as Unknown propagates through analyze_link_polarity and produces Undetermined loop classifications for any loop that crosses the lookup -- exactly the failure mode the rest of the LTM polarity analysis is trying to avoid.
Locations
src/simlin-engine/src/ltm.rs::analyze_graphical_function_polarity(around line 2341 in ltm: polarity analysis returns Unknown for all array reducers #480's reference; currently~2378-2404after PR engine: handle array reducer polarity in ltm analyzer #491 lands).
Suggested fix
A plateau-tolerant monotonicity check that ignores noise below a configurable epsilon rather than the strict 1e-10. Two reasonable approaches:
- Relative threshold: scale epsilon by the maximum y-range of the table, e.g.
EPSILON = max(1e-6 * (y_max - y_min), 1e-12). Tables with unit-scale y values get1e-6tolerance; tables with very-small or very-large absolute y values still get a sensible relative tolerance. - Counted violations: allow up to N segments to violate strict monotonicity without flipping the verdict, where N scales with the number of segments and the magnitude of the violation (so a single tiny dip in a 50-segment increasing table is forgiven, but a real direction change is not).
Option 1 is simpler and probably enough; option 2 is more robust but harder to tune. A unit test should cover: (a) clean monotone tables retain their polarity, (b) noisy-but-monotone tables now retain their polarity, (c) genuinely non-monotone tables still return Unknown.
Severity
medium
References
- Original report: ltm: polarity analysis returns Unknown for all array reducers #480
- Tech-debt item:
docs/tech-debt.mdfix new user creation flow #21 - LTM tracking epic: epic: Loops that Matter (LTM) -- open work #488
Activity
doc: add LTM arrays hardening design plan
bpowers commentedon May 13, 2026
Resolved by ee07c93 (test coverage hardened in 25a303d) — Phase 7 of the LTM arrays hardening plan (docs/design-plans/2026-05-11-ltm-arrays-hardening.md). The graphical-function strict-monotonicity check uses a y-range-relative epsilon —
max(EPSILON, range_rel * (y_max - y_min))— so numeric-import noise on a near-flat lookup arm no longer flips an otherwise-monotone curve toUnknown. (The residual nuance that the check compares the y-delta rather than the slope dy/dx — non-uniform x-spacing — is tracked separately as GH #536.)engine: classify GF monotonicity by slope, not y-delta
engine: fix #536 slope tolerance regression on finely-sampled tables