Order of calculation in all math equations

You are exactly right that the expression in J.M.'s (original) answer contains ambiguity. Mathematicians can distinguish the correct meaning easily because we are used to seeing things written this way, but it can be difficult for the uninitiated. Let me break it down for you.

$$\mathbf I+\sin\,\varphi\mathbf W+2\sin^2\frac{\varphi}{2}\mathbf W^2$$

  1. To begin with, often when people do linear algebra (arithmetic with matrices and vectors), they will bold the symbol for a matrix (an array) or a vector (a tuple) to distinguish it from a scalar (a number). In this case, J.M. was distinguishing that I and W are matrices. (Conventionally capital bolded letters like ${\bf A}$ denote matrices, while lower case bolded letters like ${\bf v}$ denote vectors.) In particular, I refers to the identity matrix, which is the matrix with diagonal entries $1$ and all other entries $0$. Sometimes we write this as ${\bf I_n}$ instead to distinguish the dimensions of that particular matrix. $$\mathbf{I}_n =\underbrace{\left.\left(\begin{array}{ccccc}1&0&0&\cdots &0\\0&1&0&\cdots &0\\0&0&1&\cdots &0\\ \vdots&&&\ddots &\\0&0&0&\cdots &1\end{array}\right)\right\}}_{n\text{ columns}}\,n\text{ rows}$$

  2. As you learned in the last post, $\sin$ is a trigonometric function. Generally we write $\sin(\theta)$ to denote the $\sin$ of $\theta$, but we sometimes leave the parenthesis out when we believe the meaning is unambiguous. $\sin\varphi {\bf W}$ appears ambiguous because you don't know whether you should be $\sin$'ing $\varphi$ or $\varphi{\bf W}$. However, you can't $\sin$ a matrix, so now that you know the convention that matrices are bolded, it should be clear that $\sin{\varphi}{\bf W}$ denotes a scalar $\sin(\varphi)$ multiplied by a matrix ${\bf W}$. A scalar multiplied by a matrix is simply the scalar applied to each entry in the matrix, so $$\begin{eqnarray*}\sin\varphi {\bf W}&=&\sin\varphi \left(\begin{array}{ccc} W_{11} & W_{12} & \cdots & W_{1n} \\ W_{21} & W_{22} & \cdots & W_{2n} \\ \vdots & & \ddots & \\ W_{m1} & W_{m2} & \cdots & W_{mn} \end{array}\right)\\&=&\left(\begin{array}{ccc}\sin(\varphi) W_{11} &\sin(\varphi) W_{12} & \cdots & \sin(\varphi) W_{1n} \\ \sin(\varphi) W_{21} &\sin(\varphi) W_{22} & \cdots & \sin(\varphi) W_{2n} \\ \vdots & & \ddots & \\\sin(\varphi) W_{m1} & \sin(\varphi) W_{m2} & \cdots & \sin(\varphi)W_{mn} \end{array}\right).\end{eqnarray*}$$

  3. There is another weird notation here. $\sin^2\theta$, for whatever reason, is how we write $(\sin(\theta))^2$. (I honestly don't know how this originated. Usually when you have a function $f$ and you write $f^2(x)$, it means $f(f(x))$, not $(f(x))^2$, but for trigonometric functions this is different.) So in the expression $2\sin^2\frac{\varphi}{2}{\bf W^2}$, you would first evaluate the scalar $2\sin^2\frac{\varphi}{2}$: first divide $\varphi$ by $2$, then compute the $\sin$, then square it, then multiply by $2$. Set the result aside (let's call it $\alpha$), compute ${\bf W}^2={\bf W}\cdot{\bf W}$ with matrix multiplication, and then multiply each entry of ${\bf W}^2$ by $\alpha$ term by term.

  4. The very last thing you do is add the three matrices $I$, $\sin\varphi {\bf W}$, and $2\sin^2\frac{\varphi}{2}{\bf W}^2$ together. Addition of matrices is simply term by term, i.e. $$A+B=\left(\begin{array}{ccc} A_{11} & A_{12} & \cdots & A_{1n} \\ A_{21} & A_{22} & \cdots & A_{2n} \\ \vdots & & \ddots & \\ A_{m1} & A_{m2} & \cdots & A_{mn} \end{array}\right)+\left(\begin{array}{ccc} B_{11} & B_{12} & \cdots & B_{1n} \\ B_{21} & B_{22} & \cdots & B_{2n} \\ \vdots & & \ddots & \\ B_{m1} & B_{m2} & \cdots & B_{mn} \end{array}\right)=\left(\begin{array}{ccc} A_{11}+B_{11} & A_{12}+B_{12} & \cdots & A_{1n}+B_{1n} \\ A_{21}+B_{21} & A_{22}+B_{22} & \cdots &A_{2n}+ B_{2n} \\ \vdots & & \ddots & \\ A_{m1}+B_{m1} &A_{m2}+ B_{m2} & \cdots & A_{mn}+B_{mn} \end{array}\right).$$ Note that $A+B$ is only defined when $A$ and $B$ have the same dimensions - if $A$ is an $m\times n$ matrix, $B$ has to be too.

Hope this helps! It may help to compute a small example (with $2\times 2$ matrices) with pen and paper.


There are many conventions here which need to be learned. Parentheses override anything. Horizontal fraction bars (but not diagonal ones) come with parentheses around the stuff above and below them. Then exponents come before multiplication/division, which come before addition/subtraction. We just got (again) the question of how to parse $6/2(1+2)$ which computers know is $9$ but many people think is $1$ and we see similar forms with both intents.

The particular form you reference $2 \sin^2 \frac \varphi 2$ is special. Because trigonometry functions often need squaring we write them this way instead of $2(\sin \frac \varphi 2)^2$, which is equivalent. Aside from trigonometry, you rarely see $f^2(x)$ and if you do, it is sometimes the square of $f(x)$ and sometimes $f(f(x))$-the author owes you an explanation. Usually only one of these makes sense. Another trouble is arguments of trigonometry functions-we sometimes write $\sin x$ without parentheses, but is $\sin 2 \pi \omega t$ supposed to be $\sin (2) \pi \omega t$ or $\sin (2\pi \omega t)$? I would bet heavily on the latter.