I have a matrix in complex exponential form. I want to factor out the complex exponential form and then express the inside in the a+i*b form.
For example:
\begin{bmatrix} e^{i \frac{\pi}{4}} & 0 \\ 0 & e^{-i \frac{\pi}{4}} \end{bmatrix}
becomes $ \begin{bmatrix} e^{i \frac{\pi}{4}} & 0 \\ 0 & e^{-i \frac{\pi}{4}} \end{bmatrix} \rightarrow e^{i \frac{\pi}{4}} \begin{bmatrix} 1 & 0 \\ 0 & e^{-i \frac{\pi}{2}} \end{bmatrix} \rightarrow e^{i \frac{\pi}{4}} \begin{bmatrix} 1 & 0 \\ 0 & -i \end{bmatrix} $
I found a helpful similar question here, but the most upvoted choice involves notation I don't know. And because the symbols are just question marks and underscores it's impossible to google. Here is code that turns a number into complex form (the inverse of part of what I want to do):
polarForm = Expand[# /. z_?NumericQ :> Abs[z] Exp[I Arg[z]]] &;
I know about pure functions (using # and &) and replacement (using /.), but I have no idea a what "z_?NumericQ" is, and only half-understand what :> does.
I understand that using this fancy notation is not necessary, and that I could just look at the other upvoted posts and learn from their code - but I would like to learn to be a better Mathematica coder, and I'm thinking learning this notation would help me.
In summary, I'm looking for help in understanding what the syntax in this "polarform" is doing (and maybe how I can write something similar for my code).



?and:>have documentation pages which can be searched using just those symbols. The former is a pattern test; here it is applying the functionNumericQto the patternz_, which is useful for pattern matching to a number. The latter is a delayed version of->, the difference is that the RHS of:>is not evaluated until occurrences ofzhave been replaced. – IPoiler Nov 30 '15 at 20:16