In trying to answer to the question Symbolic Expectation Value Evaluation, I have written the following piece of code
m /: m[x_] = If[Attributes[x] == Constant, x, m[x]];
m /: m[x_ + y_] = m[x] + m[y];
m /: m[x_ y_] =
Which[Attributes[x][[1]] == Constant, x m[y],
Attributes[y][[1]] == Constant, y m[x],
Attributes[x][[1]] == Constant || Attributes[y][[1]] == Constant,
x y, Attributes[x][[1]] ! == Constant ||
Attributes[y][[1]] ! == Constant, m[ x y]];
to begin with.
Then I have tried this
SetAttributes[{α, β}, Constant]
m[α x + β]
which returns
If[{} == Constant, x α, m[x α]] + If[{} == Constant, β, m[β]]
I do not know where is the problem perhaps the head of m[α x + β] which is Plus ????
===, does that work better? – Marius Ladegård Meyer Oct 24 '16 at 08:18=!=then – Marius Ladegård Meyer Oct 24 '16 at 08:21==in the first def ofm[x_]... The thing is, when you use==, stuff like{} == Constantis notFalse, it just does not evaluate, as you have seen from your output. With===it's eitherTrueorFalse. – Marius Ladegård Meyer Oct 24 '16 at 09:16