import numpy as np

from common import I, S, T, X, Y, Z, rx, ry, rz

# Les portes de 4.4 sont des rotations, à une phase globale près
print("RX(π)   = −i·X          :", np.allclose(rx(np.pi), -1j * X))
print("RY(π)   = −i·Y          :", np.allclose(ry(np.pi), -1j * Y))
print("RZ(π)   = −i·Z          :", np.allclose(rz(np.pi), -1j * Z))
print("RZ(π/2) = e^(−iπ/4)·S   :", np.allclose(rz(np.pi / 2), np.exp(-1j * np.pi / 4) * S))
print("RZ(π/4) = e^(−iπ/8)·T   :", np.allclose(rz(np.pi / 4), np.exp(-1j * np.pi / 8) * T))

# La forme générale, vérifiée sur un angle quelconque
theta = 0.7
print("RX(θ) = cos(θ/2)·I − i·sin(θ/2)·X :", np.allclose(rx(theta), np.cos(theta / 2) * I - 1j * np.sin(theta / 2) * X))
print("RY(θ) = cos(θ/2)·I − i·sin(θ/2)·Y :", np.allclose(ry(theta), np.cos(theta / 2) * I - 1j * np.sin(theta / 2) * Y))
print("RZ(θ) = cos(θ/2)·I − i·sin(θ/2)·Z :", np.allclose(rz(theta), np.cos(theta / 2) * I - 1j * np.sin(theta / 2) * Z))
