# Demystifying Quantum Gate Fidelity for Electronics Engineers
## 4 Quantum Gate Fidelity in Matrix Form  
Calculating the fidelity from Equation (11) is not a trivial task, as it involves a multi-dimensional integral. The aim of this section is to formulate Equation (11) in a more practical matrix form, to make it easy to calculate the quantum fidelity once the operators \(A_{I}\) and \(A_{R}\) are provided in the matrix form. It is worth emphasizing that, once a basis for the Hilbert space is provided, an operator is mathematically represented by a matrix [40]; in this way, an operator enjoys all the properties of the matrix. In particular, the application of the Toeplitz decomposition [41] to the \(A_{TOT}=A_{I}^{\intercal}A_{R}\) total operator makes it possible to decompose \(A_{TOT}\) into the sum of a Hermitian \(H\) and an anti-Hermitian \(A\) operator. Equation (11) can thus be rewritten as follows:  
\[F=\int_{S^{2n-1}}\lvert\langle\psi_{IN}|A_{TOT}|\psi_{IN}\rangle\rvert^{2}dV= \int_{S^{2n-1}}\lvert\langle\psi_{IN}|H+A|\psi_{IN}\rangle\rvert^{2}dV \tag{12}\]  
Because of linearity, Equation (12) can be reformulated as follows:  
\[F=\int_{S^{2n-1}}\lvert\langle\psi_{IN}|H|\psi_{IN}\rangle+\langle\psi_{IN}|A| \psi_{IN}\rangle\rvert^{2}dV \tag{13}\]  
By assuming that the state \(|\psi_{IN}\rangle\) is normalized, the quantities \(\langle\psi_{IN}|H|\psi_{IN}\rangle\) and \(\langle\psi_{IN}|A|\psi_{IN}\rangle\) are the expectation values of the operators \(H\) and \(A\), respectively [42; 43]. Since the expectation value of an operator is the average values of its eigenvalues [42; 43], you can write:  
\[ \begin{array}{l}\langle\psi_{IN}|H|\psi_{IN}\rangle=\sum\limits_{i}|\alpha_{i }|^{2}h_{i}\\ \langle\psi_{IN}|A|\psi_{IN}\rangle=\sum\limits_{i}|\alpha_{i}|^{2}a_{i}\end{array}  \tag{14}\]  
where \(\alpha_{i}\) is the components of the state vector \(|\psi_{IN}\rangle\) and \(h_{i}\) (\(a_{i}\)) are the eigenvalues of the operator \(H\) (\(A\)). By emphasizing that the eigenvalues of a Hermitian operator are real numbers while the eigenvalues of an anti-Hermitian operator are pure imaginary numbers [42], you can state that \(h_{i}\) are real numbers while \(a_{i}\) are imaginary numbers. In addition, since \(|\alpha_{i}|^{2}\) are real numbers, you can conclude, from Equation (14), that \(\langle\psi_{IN}|H|\psi_{IN}\rangle\) is real while \(\langle\psi_{IN}|A|\psi_{IN}\rangle\) is purely imaginary. The argument of the integral in Equation (13) is therefore of the general form \(\lvert x+y\rvert^{2}\), with \(x\) and \(y\) real numbers. By emphasizing that \(\lvert x+y\rvert^{2}=\lvert x\rvert^{2}+\lvert y\rvert^{2}\), Equation (13) can be split into two contributions:  
\[F=\int_{S^{2n-1}}\lvert\langle\psi_{IN}|H|\psi_{IN}\rangle\rvert^{2}dV+\int_{ S^{2n-1}}\lvert\langle\psi_{IN}|A|\psi_{IN}\rangle\rvert^{2}dV \tag{15}\]  
It is now also worth emphasizing that the Hermitian and anti-Hermitian operators are normal operators [44]. They therefore enjoy the spectral theorem from the matrix analysis [41], which states that every normal operator is unitarily similar to a diagonal operator, which is an operator represented by a diagonal matrix [44]. In particular, the matrix entries on the main diagonal are exactly the eigenvalues \(d_{Hi}\) for the diagonal operator \(D_{H}\), which is similar to the operator \(H\), and \(d_{Ai}\) for the diagonal operator \(D_{A}\), which is similar to the operator \(A\). Since similar operators exhibit the same eigenvalues, \(h_{i}=d_{Hi}\) and \(a_{i}=d_{Ai}\). Thus:  
\[ \begin{array}{l}\langle\psi_{IN}|D_{H}|\psi_{IN}\rangle=\sum\limits_{i}| \alpha_{i}|^{2}d_{Hi}=\sum\limits_{i}|\alpha_{i}|^{2}h_{i}\\ \langle\psi_{IN}|D_{A}|\psi_{IN}\rangle=\sum\limits_{i}|\alpha_{i}|^{2}d_{Ai} =\sum\limits_{i}|\alpha_{i}|^{2}a_{i}\end{array}  \tag{16}\]Of course, with \(h_{i}\) (\(a_{i}\)) being real (imaginary) numbers, \(d_{Hi}\) (\(d_{Ai}\)) are also real (imaginary) numbers.