Skip to content

Fix #354: t2s constant_mul keeps a symbolic scalar_wrapper factor - #406

Closed
petlenz wants to merge 2 commits into
fix-352-substitution-spacefrom
fix-354-t2s-constant-mul
Closed

petlenz wants to merge 2 commits into
fix-352-substitution-spacefrom
fix-354-t2s-constant-mul

Conversation

@petlenz

@petlenz petlenz commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #354. Stacked on #405.

wrapper(x) * (trace(A)*det(A))1*det(A)*tr(A) — the symbolic factor x vanished and the coefficient was reset. When try_numeric fails on the LHS wrapper, constant_mul::dispatch(tensor_to_scalar_mul) never inserted it. The promoted route (x * (f*g)) goes through mul_base and was correct, which is why the suite missed it.

Fix

Non-numeric wrappers insert as factors via push_or_combine (forward-declared; merging with an existing wrapper child through the existing unwrap-multiply-rewrap path). Numeric path unchanged.

Tests

Typed lock-in across all three dims (wrapper-first construction so the regression can't dodge through the promoted route). Full suite: 2445/2445 pass.

@petlenz
petlenz force-pushed the fix-354-t2s-constant-mul branch from f3cab22 to 5ec41ff Compare July 25, 2026 12:33
@petlenz
petlenz force-pushed the fix-354-t2s-constant-mul branch 2 times, most recently from cd9baf2 to a6794a3 Compare July 25, 2026 14:16
@petlenz
petlenz force-pushed the fix-354-t2s-constant-mul branch 2 times, most recently from f81b5a6 to ea880c0 Compare July 26, 2026 12:14
@petlenz
petlenz force-pushed the fix-354-t2s-constant-mul branch from ea880c0 to e3cbfae Compare July 26, 2026 12:43
@petlenz
petlenz force-pushed the fix-354-t2s-constant-mul branch from e3cbfae to 4f47221 Compare July 26, 2026 17:18
@petlenz
petlenz force-pushed the fix-354-t2s-constant-mul branch 2 times, most recently from 35453bf to 89df391 Compare July 26, 2026 18:16
@petlenz
petlenz force-pushed the fix-354-t2s-constant-mul branch from 89df391 to e5045a7 Compare July 26, 2026 18:40
petlenz added 2 commits July 26, 2026 20:58
constant_mul::dispatch(tensor_to_scalar_mul) handled a numeric LHS by
merging it into the coefficient, but a non-numeric scalar_wrapper LHS
fell through the same path: the factor was never inserted and the
coefficient was reset to the wrapped default, so
wrapper(x) * (trace(A)*det(A)) evaluated as if x were 1. The promoted
route (plain x * (f*g)) goes through mul_base and was correct, which
is why tests missed it - the bug fires whenever the wrapper is the
visitor's LHS.

Non-numeric wrappers are now inserted as factors via push_or_combine
(merging with an existing wrapper child through the unwrap-multiply-
rewrap path).

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
A single-shot find/combine threw 'duplicate child insertion' when the
combined factor collided with another existing child (w(x)*w(x) ->
w(x^2) meeting a stored w(x^2)) - the same pattern
merge_or_insert_mul already loops on. Pre-existing hole; #354's new
route made it easier to reach. Regression test builds the chained
collision explicitly.

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
@petlenz
petlenz force-pushed the fix-354-t2s-constant-mul branch from e5045a7 to 7a945d5 Compare July 26, 2026 19:03
@petlenz
petlenz added this pull request to stack #425 September 15, 2026 20:15
@petlenz

petlenz commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Landed in main via #409 (merge a5f5ce8), which contained this branch at head 7a945d5. Closing without a separate merge.

@petlenz petlenz closed this Sep 15, 2026
@petlenz
petlenz deleted the fix-354-t2s-constant-mul branch September 15, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant