import numpy as np

from common import show
from qsim.etape1_un_qubit import make_state

H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
U = np.array([[0.6, 0.8j], [0.8j, 0.6]])


def dagger(matrix):
    return matrix.conj().T


circuit = U @ H                   # le circuit « H puis U »
undo = dagger(H) @ dagger(U)      # « U† puis H† » : on défait la dernière porte d'abord

state = make_state(0.6, 0.8)
print("état de départ          =", show(state))
print("après le circuit        =", show(circuit @ state))
print("après circuit puis undo =", show(undo @ circuit @ state))

# Défaire dans le mauvais ordre ne marche pas
wrong = dagger(U) @ dagger(H)
print("avec le mauvais ordre   =", show(wrong @ circuit @ state))
