# Explain matrix multiplication math operations of a Hadamard gate after a phase gate

Starting with $$|0\rangle$$, I would like to understand how the probability values of 85.4% $$|0\rangle$$ and 14.6% $$|1\rangle$$ are derived from the payload circuit below?

After applying the 45 degree phase gate, I get:

And after applying the second Hadamard, I get the original $$|0\rangle$$ value. I am interested in the specific math operations involved in the matrix multiplications.

$$H T H |0\rangle = \frac{1}{\sqrt2} \begin{bmatrix} 1 & 1 \\ 1 & -1\end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & e^{i\pi/4}\end{bmatrix} \frac{1}{\sqrt2} \begin{bmatrix} 1 & 1 \\ 1 & -1\end{bmatrix} \begin{bmatrix} 1 \\ 0\end{bmatrix}$$
Alternatively, if you prefer Dirac notation you can apply the gates to the $$|0\rangle$$ state in order:
$$|0\rangle \xrightarrow{\text{H}} \frac{1}{\sqrt2}(|0\rangle + |1\rangle) \xrightarrow{\text{T}} \frac{1}{\sqrt2}(|0\rangle + e^{i\pi/4} |1\rangle) \xrightarrow{\text{H}} \frac{1}{2}\big(|0\rangle + |1\rangle + e^{i\pi/4} (|0\rangle - |1\rangle)\big) = \frac{1}{2}\big( 1 + e^{i\pi/4} \big)|0\rangle + \frac{1}{2}\big( 1 - e^{i\pi/4} \big)|0\rangle$$
To get the probabilities of measuring 0 and 1 in this state, you have to simplify the amplitudes further using the fact that $$e^{i\pi/4} = \frac{1 + i}{\sqrt2}$$:
$$P(0) = \frac{|1 + e^{i\pi/4}|^2}{|1 + e^{i\pi/4}|^2 + |1 - e^{i\pi/4}|^2} = \frac{2 + \sqrt2}{(2 + \sqrt2) + (2 - \sqrt2)} = \frac{2+\sqrt2}{4} \approx 0.8536$$