import numpy as np

from common import grover, rounded, success

n, marked = 3, ["101"]
theta = np.arcsin(np.sqrt(len(marked) / 2**n))  # angle de départ : sin θ = √(M/N)
print(f"θ = {theta:.4f} rad")

for k in range(7):
    p = success(grover(marked, n, k), marked, n)
    formula = np.sin((2 * k + 1) * theta) ** 2
    print(f"{k} itération(s) : P(101) = {rounded(p):.3f}   (formule sin²((2k+1)θ) : {rounded(formula):.3f})")
