# Simulate hamiltonian evolution

I'm trying to figure out how to simulate the evolution of qubits under the interaction of Hamiltonians with terms written as a tensor product of Pauli matrices in a quantum computer. I have found the following trick in Nielsen and Chuang's book which is explained in this post for a Hamiltonian of the form

$$H = Z_1 \otimes Z_2 \otimes ... \otimes Z_n$$.

But it is not explained in detail how would the simulation for a Hamiltonian with terms including Pauli matrices $$X$$ or $$Y$$ would work. I understand that you can transform these Pauli's into Z's by considering that $$HZH = X$$ where $$H$$ is the Hadamard gate and also $$S^{\dagger}HZHS =Y$$ where $$S$$ is the phase $$i$$ gate. How exactly should I use this to implement for example $$H= X \otimes Y$$

What if now the Hamiltonian contains the sum of terms with Pauli matrices? For example

$$H = X_1 \otimes Y_2 + Z_2 \otimes Y_3$$

Let's say you have a Hamiltonian of the form $$H=\sigma_1\otimes\sigma_2\otimes\sigma_2\otimes\ldots\otimes\sigma_n$$ There's a straightforward circuit construction that lets you implement its time evolution $$e^{-iHt}$$. The trick is basically to decompose the state that you're evolving into the components that are in the $$\pm 1$$ eigenspaces of $$H$$. Then, you apply the phase $$e^{-it}$$ to the $$+1$$ eigenspace, and the phase $$e^{-it}$$ to the $$-1$$ eigenspace. The following circuit does that job (and uncomputes the decomposition at the end). I'm assuming the phase gate element in the middle to be applying the unitary $$\left(\begin{array}{cc} e^{it} & 0 \\ 0 & e^{-it} \end{array}\right).$$
In general, if you want to evolve some Hamiltonian $$H=H_1+H_2$$ where $$H_1$$ and $$H_2$$ are of the previous form, then by far the easiest is to decompose the evolution as $$e^{-iHt}\approx \left(e^{-iH_1t/M}e^{-iH_2t/M}\right)^M$$ for some large $$M$$ (although there are algorithms with much better scaling behaviour), and each of those small steps $$e^{-iH_1t/M}$$ can be implemented with the previous circuit.
That said, sometimes there are smarter things that you can do. Your extra example, $$H=X\otimes Y\otimes\mathbb{I}+Z\otimes\mathbb{I}\otimes Y$$ is one such case. I'd start by apply the unitary rotation $$U=\frac{Z+Y}{\sqrt{2}}$$ to qubits 2 and 3. This is the equivalent to the Hadamard gate, but converts $$Y$$ into $$Z$$ instead of $$X$$. Now stop for a moment and think. If qubits 2 and 3 are in 00, then we're applying $$(X+Z)$$ to qubit 1. For 01, it's $$(X-Z)$$, for 10 it's $$(Z-X)$$, and for 11 it's $$-(X+Z)$$. Next, let's apply controlled-not from qubit 2 to qubit 3. This just permutes the basis elements slightly. It now says that we have to apply the Hamiltonian $$(-1)^{x_2}(X+(-1)^{x_3}Z)$$ to the state of qubit 1, if qubits 2 and 3 are in the states $$x_2x_3$$. Next, remember that $$X+Z=\sqrt{2}H$$ (Hadamard, not Hamiltonian), and that $$X\sqrt{2}HX=X-Z$$. So, that gives us an easy way to convert between the two bits of Hamiltonian. We'll just replace those two $$X$$s with controlled-nots controlled by qubit 3. Similarly, we can use a circuit identity where this time we'll replace the $$X$$s with controlled-nots controlled off qubit 2.
In general, this problem is not very simple, ultimately it comes down to taking a Hamiltonian as you've written and somehow forming the appropriate sequence of gates that implements $$e^{-\Delta t H}$$. From my understanding, this is usually accomplished by using the Trotter-Suzuki approximation and gate decompositions.