How does a computer calculate matrix scalar multiplication order of operations (flops)

36 Views Asked by At

I am trying to understand the number of flops in the Householder QR factorization. In one line of the algorithm, it says \begin{gather*} v = v / \lVert v \rVert_2 \end{gather*} I was wondering what the order of operations for a computer was. In other words, does it compute the norm first, so for an $n$ length vector we have $$ \lVert v \rVert_2 = \sqrt{v_1^2 + ... + v_n^2} \Rightarrow v = \frac{1}{ \sqrt{v_1^2 + ... + v_{n}^2}}\begin{bmatrix}v_1, & ... &, v_{n}\end{bmatrix}^T $$ taking I believe $3n$ flops, or is it re-computing the norm at each entry of the vector, ie $$ v = \begin{bmatrix}v_1 / \sqrt{v_1^2 + ... + v_{n}^2}, & ... &, v_{n} / \sqrt{v_1^2 + ... + v_{n}^2}\end{bmatrix}^T $$ taking $2n^2$ flops?