import numpy as np

from common import alice_gates, branch, fidelity, rounded, share_pair
from qsim import X, Z, apply, make_state

psi = make_state(0.6, 0.8j)
state = alice_gates(share_pair(psi))

# Alice a lu 11 : Bob applique Z puis X, au lieu de X puis Z
_, bob = branch(state, 1, 1)
right = apply(apply(bob, X), Z)
swapped = apply(apply(bob, Z), X)
print("vecteurs égaux :", np.allclose(right, swapped))
print("opposés (phase globale −1) :", np.allclose(swapped, -right))
print(f"fidélité dans l'ordre inversé : {rounded(fidelity(psi, swapped)):.3f}")
