I am defining a linear associative multiplication operation Mult[]:
ClearAll[Mult]
SetAttributes[Mult, {Flat, OneIdentity}];
Mult[A___, a_, B___] := a Mult[A, B] /; NumberQ[a]
Then I try to evaluate a simple expression, which (I believe) does not match the rule written above:
Mult[X, Y]
I got the error Recursion depth of 1024 exceeded. It is definitely related to the attribute Flat, but I do not see how. What am I doing wrong?
Flatto begin with? Doesn't an actual solution need to preserve that pattern-matching behavior? (I am assuming that this is a toy example and not the actual, complete problem.) – Mr.Wizard Sep 24 '18 at 14:53Mult[a, Mult[b, c]]still evaluates toMult[a, b, c]. – Carl Woll Sep 24 '18 at 14:58