# Données de la figure « H puis CNOT, pas à pas » : jamais affiché comme extrait.
# Même calcul que 04-superposition.py : les quatre amplitudes (00, 01, 10, 11) au départ, après H sur le
# qubit 0, puis après le CNOT (contrôle 0, cible 1).
import json

import numpy as np
from qsim.etape2_portes import H, I

CNOT = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])
zero = np.array([1, 0])


def rounded(state):
    return [round(float(x), 3) + 0.0 for x in state]


start = np.kron(zero, zero)          # |00⟩
after_h = np.kron(H, I) @ start      # H sur le qubit 0
after_cnot = CNOT @ after_h          # CNOT, contrôle 0, cible 1

print(json.dumps({
    "labels": ["00", "01", "10", "11"],
    "states": [rounded(start), rounded(after_h), rounded(after_cnot)],
}))
