import numpy as np

n, k = 4, 5
print("pire cas déterministe :", 2 ** (n - 1) + 1, "appels")
print(f"probabilité d'erreur avec {k} appels au hasard, en théorie : 2^(1−k) = {round(2 ** (1 - k), 4):.4f}")

# Vérification par simulation
rng = np.random.default_rng(42)
trials, errors = 20_000, 0
for _ in range(trials):
    table = np.array([0] * 8 + [1] * 8)
    rng.shuffle(table)
    values = table[rng.integers(0, 2**n, size=k)]
    errors += int(values.min() == values.max())
print(f"taux d'erreur mesuré sur {trials} fonctions équilibrées : {round(errors / trials, 4):.4f}")
