Consider the single-qubit Hamiltonian

The commutator is proportional to , and one can show by expanding the exponential as a Taylor series and rearranging odd- and even-power terms that

Let's write a function to compute the error : the norm of the difference between the Trotterized result and the exact result .

Complete the code for trotter_XandZ below to Trotterize evolution with the Hamiltonian . The exact result exact_result_XandZ is provided for you. Submitting will generate a plot of the error trotter_error_XandZ against the number of steps on a log-log scale for two different choices of and .

Note that the error is related to the number of steps via

or, in the logarithmic scale, Therefore, the log-log plot should be a line with slope . Is this what you see?

or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Apply the Zassenhaus formula to Trotterization errors and higher-order formulas.
  • Describe how the desired error size influences the gate count