# Exercice 3 : séparer (1, i)/√2 et (1, -i)/√2
import cmath

import numpy as np
from common import h
from qsim.etape1_un_qubit import make_state, probabilities


def shift(state, theta):
    """Fait tourner l'amplitude de |1⟩ seule de l'angle theta (une porte de phase, leçon 4.4)."""
    a, b = state
    return make_state(a, b * cmath.exp(1j * theta))


s = 1 / np.sqrt(2)
for name, state in [("(1, i)/√2", make_state(s, 1j * s)), ("(1, -i)/√2", make_state(s, -1j * s))]:
    only_h = np.round(probabilities(h(state)), 3)
    shift_then_h = np.round(probabilities(h(shift(state, -np.pi / 2))), 3)
    print(f"{name:<11} h seule : {only_h}   rotation de -π/2 puis h : {shift_then_h}")
