I need to see an example of how Hamiltonian, i.e. any Hermitian matrix, can be decomposed into a linear combination of Pauli matrices.

I would prefer an option to do this in larger than 2 dimensions, if that is possible.

  • $\begingroup$ Hi and welcome to Quantum computing SE. There is probably missing figure or equation because there is written What I have tried so far is this: but then there is nothing. $\endgroup$ May 7, 2020 at 21:57
  • 3
    $\begingroup$ Please clarify what exactly you are asking for. Right now, H = qutip.sigmax() seems like it would be a possible answer to your question: it's an Hermitian matrix decomposed into a linear combination of Pauli matrices, written in python. I'm guessing you are asking for something more specific? $\endgroup$
    – glS
    May 8, 2020 at 12:30
  • $\begingroup$ The user accepted my answer. What they want is clear. Please re-open or choose a close reason different from "needs details for clarity". $\endgroup$ Feb 27, 2021 at 21:23
  • $\begingroup$ related: quantumcomputing.stackexchange.com/q/2703/55 $\endgroup$
    – glS
    Jul 26, 2021 at 23:02
  • $\begingroup$ I wrote an ipython script to perform this decomposition for a general matrix. It can be found here: github.com/trahancj/quantum_algorithms.git There are examples as well. $\endgroup$
    – Corey
    Jan 25, 2022 at 23:31

1 Answer 1


I call this the "Paulinomial decomposition" as you are writing the matrix $H$ as a polynomial of Pauli matrices:

$H=a_{XX}X_1X_2 + a_{XY}X_1Y_2 +a_{XZ}X_1Z_2 + a_{XI}X_1 + a_{YY}Y_1Y_2 + \cdots $ (for the 2-qubit case).

To get the coefficients, you can use this formula:

$a_{AB}=\frac{1}{4}\textrm{tr}\left((A_1\otimes B_2)H\right)$

For example, here is a 2-qubit gate (the square root of the SWAP gate) written as a polynomial of Pauli matrices:

You can even do this for a $2^n \times 2^n$ Hamiltonian, for example an 8x8 Hamiltonian can be done like this:

$a_{ABC}=\frac{1}{8}\textrm{tr}((A_1\otimes B_2\otimes C_3))H)$

I have a code that can also do it for arbitrary matrices (not only $2^n \times 2^n$, but I haven't touched it for 2 years and might need to test it again). If it would be helpful, I can try to dig it up and polish it for you to use.

  • $\begingroup$ To correct my notation -- every term appears to power 0 or 1, so it is really a linear decomposition. You can of course call this a polynomial, but it is really a linear decomposition. $\endgroup$ May 8, 2020 at 21:40
  • $\begingroup$ @NorbertSchuch Again, it is not linear either. The multi-variable function $xy+x+y-2$ is considered a quadratic, not a linear function, and it is not a monomial because it has multiple terms. For example this is a quadratic function: en.wikipedia.org/wiki/… even if $A$ and $B$ are 0 but $E\ne0$. When you have a product of two variables, you can't for example use linear programming (for optimization) because the problem is considered "non-linear". $\endgroup$ May 8, 2020 at 21:48
  • 2
    $\begingroup$ Multilinear? ... $\endgroup$ May 8, 2020 at 22:25
  • $\begingroup$ That might be another way to describe it. In the definition of a "quadratic form" for example, it's okay for $a_{ij}=0$ whenever $i=j$. I suppose if we consider $X_1$ and $X_2$ to be different "variables" since they act on different qubits (one of them is the matrix $I \otimes X$ and the other one is $X \otimes I$), we could call this linear, but in the AQC community, and also in the Operations Research community, we definitely call XX terms quadratic and X terms linear. There is an entire field called "quadratization" which is about turning k-local Hamiltonians into "quadratics" exactly like $\endgroup$ May 8, 2020 at 23:32
  • $\begingroup$ the first equation in my answer. I did not come up with this term, it might have been Endre Boros, Aritanan Gruber, Yves Crama, and Martin Anthony who came up with the term, but it might have been around even earlier. In any case, minimizing $b_1b_2 + b_1 - b_2$ where $b_1,b_2\in \{0,1\}$ is most definitely called QUBO (quadratic unconstrained boolean optimization). That literature is too big for us not to accept these functions as quadratic! P.S. when I talked about "quadratic forms" I meant to include this: en.wikipedia.org/wiki/Quadratic_form#Definitions. $\endgroup$ May 8, 2020 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.