package expm: matrix powers within a product of matrices: operation precedence

#1
I want to double check that for M and N kxk mtrices and v a k-vector
M%^%2%*%N%*%v is not automatically read as (M%^%2)%*%N%*%v or
M%*%N%^%2%*%v is not automatically read as M%*%(N%^%2)%*%v or
both

I had been assuming the usual precedence (powers first, then multiplication) applies for matrix powers and multiplication in expm. I was getting unexpected results. In desperation I tried putting in the parentheses and seem to be getting much more reasonable answers. But I am so surprised that the matrix power operation is, apparently, not automatically given precedence over the matrix multiplication operation that I do not trust that adding parentheses has cured my bug. Maybe I am still making some other mistake instead. Can anyone confirm that in fact the parentheses are (sometimes?) essential? I could not find any documentation, one way or the other, just definitions of the power operator and of matrix exponentials.

TIA Rainer K. Sachs, Prof emertitus of math
 

Dason

Ambassador to the humans
#2
The matrix exponentiation operator is provided by a package. So it doesn't have the ability to modify operator precedence and is just seen by the R parser as another binary operator. So it will have the same precedence as matrix multiplication so if your operators are just multiplications and exponentiations then it will just read from left to right and keep on applying your operators in that order. It's just safest to use parenthesis whenever in doubt...