Repository navigation
Description
Summary
A bare arrayed reference that shares a reducer with a SLICED co-source is executed with a redundant extra iteration of its (already-bound) dimension: the reducer's result is multiplied by the cardinality of the bare ref's dimension. This is an ENGINE EXECUTION bug (LTM disabled; no synthetic variables involved), producing silent wrong simulation results for a legal, natural XMILE shape.
Fixture (reproduced at commit ef91194d with a TestProject fixture)
D1 = {a, b}, D2 = {c, d}
base[D1] = {a: 1, b: 100}
w[D2] = {c: 1, d: 2}
matrix[D1, D2] = base[D1] * w[D2]
frac[D1] = {a: 10, b: 1000}
growth[D1] = SUM(matrix[D1, *] * frac)
Expected per XMILE A2A semantics: the bare frac denotes the active element frac[r]; the SUM iterates the wildcard D2 only. So growth[a] = (1 + 2) * 10 = 30.
Engine computes growth[a] = 60 = |D1| * rowsum(a) * frac[a], and growth[b] = 600000 = 2 * 300 * 1000. The bare frac appears to add a redundant iteration of the already-bound D1 to the SUM's iteration space, while both matrix's D1 index and frac still resolve to the active slot -- so each row's correct term is counted |D1| times.
Relationship to GH #779
This is the execution side of GH #779's fixture. #779's issue text described the executed behavior as "broadcasts across all D1 rows (growth_0 = 10 = the sum of all 2x2 terms)" -- on #779's symmetric all-ones fixture that observation is numerically indistinguishable from the x|D1| factor confirmed here (2x2 all-ones: rowsum * |D1| = 2 * 2 * frac... both readings give 10 with frac frozen at 1). The asymmetric fixture above discriminates: the engine does NOT sum all 2x2 terms; it multiplies the correct per-row result by |D1|. Either way the executed value disagrees with XMILE A2A semantics, and #779 (an LTM issue) treats execution as ground truth rather than tracking this engine defect.
Note: the bare-arrayed-ref-ALONE-in-a-reducer shape (SUM(other) with no sliced co-source) executes per-slot as expected (no extra factor); the bug requires the sliced co-source alongside the bare ref.
Why it matters
Silent wrong simulation results (not a compile error, not a diagnostic) for the natural spelling "per-row total = SUM(row * shared per-row coefficient)" with the coefficient written bare. Severity: medium -- silent numeric miscomputation in the core engine.
Components affected
src/simlin-engine/src/compiler/-- the wildcard-preservation / iteration-context machinery (likelycontext.rspreserve_wildcards_for_iterationand/orsubscript.rsexpansion): the bare arrayed ref under an active A2A dimension inside a reducer whose co-source pins that dimension as iterated appears to re-enter the iteration space instead of staying bound to the active slot.
Possible approach
Trace the lowering of SUM(matrix[D1,*] * frac) under the active A2A dimension D1: the reducer's iteration-space derivation presumably unions the bare ref's dims into the iterated set even though D1 is already bound by the A2A context, while the loads themselves stay slot-resolved (hence x|D1|, not a true cross-product). A fix should gate on a regression test with the exact asymmetric fixture above (expected growth = {a: 30, b: 600}) plus the no-co-source control (SUM(frac) per-slot) to pin both behaviors.
Related
- engine: no test for SUM(m[*]) on a 2-D array in apply-to-all #781 -- mixed-arity multi-source reducer hard compile failure (different shape, same compiler region)
- compiler/context: preserve_wildcards flag conflates reducer and vector builtin semantics for ActiveDimRef #365 / engine: SUM(VECTOR ELM MAP(...)) in A2A context evaluates per-element rather than reducing the full array #366 (closed) -- earlier preserve_wildcards conflation issues in the same machinery
- ltm: bare-spelled feeder of un-hoisted multi-source reducer gets silent wrong changed-last loop score (per-element partial vs broadcast execution) #779 -- the LTM-side issue whose fixture exposed this; its fix (commit
ef91194d) is unaffected
Discovery context
Empirically confirmed during the adversarial review of commit ef91194d ("engine: decline bare-spelled feeder of un-hoisted reducer loudly", GH #779, branch ltm-phase1-residuals), reproduced at that commit with TestProject fixtures and LTM disabled. Pre-existing, not a regression from that commit.
Activity
engine: ltm describes the executed read
engine: ltm describes the executed read
engine: one ordinal fallback for undeclared dimension pairs