For two Hermitian operators a in the Hilbert space , we define the trace distance as half of the -distance between and :

Equivalenty, if has eigendecomposition , we can calculate the trace distance as

With this in mind, let us build a function that calculates the trace distance.

Fill in the code to calculate the trace distance between two operators.

Hint

The function np.linalg.eigvals may be helpful.

def trace_distance(A,B):
"""Compute the trace distance of two operators with
same dimension.
Args:
A (tensor[complex]): The matrix representation of a quantum operator.
B (tensor[complex]): The matrix representation of a quantum operator.
Returns:
(float): A number that represents the trace distance.
"""

##################
# YOUR CODE HERE #
##################

# RETURN THE TRACE DISTANCE
pass

or to submit your code

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

Learning Objectives:

  • Define and calculate the trace distance between two probability distributions.
  • State important properties of the trace distance.