# How to tell Mathematica that my variable is a scalar

In my calculations I have these combinations

PauliMatrix[1].f PauliMatrix[2]


where f is a scalar function. The result is as if Mathematica assumes f to be a matrix:

{{0, -I {{0, 1}, {1, 0}}.f}, {I {{0, 1}, {1, 0}}.f, 0}}


I tried to attach a unit matrix to f:

PauliMatrix[1]  .f PauliMatrix[0] .PauliMatrix[2]


The result is the same.

Does anyone see a way to get the same output as from

In[131]:= f PauliMatrix[1]. PauliMatrix[2]

Out[131]= {{I f, 0}, {0, -I f}}

• Put parantheses around f PauliMatrix[2]'. It's interpreting the expression as dotting PauliMatrix[1] with f and then multiplying element-wise with PauliMatrix[2], due to order-of-operations. Jun 27, 2015 at 21:19

In Mathematica, the type of variable is interpreted based on the context, and if there are no values associated with the variable, then often nothing is done. When you write PauliMatrix[1].f, since there are no values/rules associated with f, this just returns

{{0, 1}, {1, 0}}.f


because the function Dot doesn't evaluate unless the arguments are vectors, matrices, or tensors (essentially, Lists, I think).

When you then write

PauliMatrix[1].f PauliMatrix[2]


it interprets {{0, 1}, {1, 0}}.f as a single object and multiplies this object as a scalar by {{0, -I}, {I, 0}}, yielding

{{0, -I {{0, 1}, {1, 0}}.f}, {I {{0, 1}, {1, 0}}.f, 0}}


The problem is order of operations, essentially: your expression Dots before it multiplies. Therefore, all you really need is a set of parantheses:

PauliMatrix[1].(f PauliMatrix[2])


which yields

{{I f, 0}, {0, -I f}}
`