# La fonction h (porte H) lit l'axe x : P(0 après h) = (1 + x)/2
import cmath

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

s = 1 / np.sqrt(2)
for name, state in [
    ("|0⟩", ZERO),
    ("|+⟩", make_state(s, s)),
    ("|−⟩", make_state(s, -s)),
    ("|+i⟩", make_state(s, 1j * s)),
    ("(0,6 ; 0,8)", make_state(0.6, 0.8)),
    ("(0,6 ; 0,8 e^(i))", make_state(0.6, 0.8 * cmath.exp(1j))),
]:
    x = bloch_vector(state)[0]
    p0 = probabilities(h(state))[0]
    print(f"{name:<18} x = {x:+.3f}   P(0 après h) = {p0:.3f}   (1 + x)/2 = {(1 + x) / 2:.3f}")
