Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-183

Von Neumann Entropy (2x2)

Problem

Return the von Neumann entropy in bits of a 2x2 density matrix [[a, b], [b, d]]. Compute the eigenvalues from the trace and determinant:

lambda = (tr +/- sqrt(tr^2 - 4 * det)) / 2

Then H = -sum lambda * log2(lambda), skipping zero eigenvalues. Clamp negative discriminants to 0.

Hint

A maximally mixed qubit has entropy 1 bit; a pure state has entropy 0.

Test cases

case 1
in: [[[0.5,0],[0,0.5]]]
expected: 1
case 2
in: [[[1,0],[0,0]]]
expected: 0
case 3
in: [[[0.75,0],[0,0.25]]]
expected: 0.8112781244591328
case 4
in: [[[0.5,0.2],[0.2,0.5]]]
expected: 0.8812908992306927
Starter codePython
import math
def von_neumann_entropy_2x2(matrix):
    # Your code here
    pass

4 test cases · run your code against them in the editor