# La formule du chaos v6 : verification (R10). Bibliotheque standard seulement.
import sys, math
from fractions import Fraction as F
src=open(sys.argv[1],encoding='utf-8').read()
corps=src.split('## Notes de révision')[0]
ok=True
def c(l,v):
    global ok; print(('[OK] ' if v else '[ECHEC] ')+l); ok=ok and v
c("aucun tiret cadratin ni demi-cadratin", '—' not in src and '–' not in src)
for ph in ["crée l'imprécision, il ne crée pas","non coupable","Gauss seul produit","ε₀ = 0","78 572","ne diverge jamais","Poonen"]:
    c(f"phrase retiree absente du corps : {ph}", ph not in corps)
e=F(1,3)-F(3333,10000); c("formule I : eps0 = 1/30 000", e==F(1,30000))
c("formule I : 3^100 x eps0 ~ 1,7 x 10^43", round(float(3**100*e)/1e43,1)==1.7)
a,b=F(1,5),F(1,5)+F(1,256)
for n in range(8): a,b=2*a,2*b
c("formule II sans pli : ecart exact 1 au pas 8", b-a==1)
c("formule II avec pli : meme position 1/5, tours 51 et 52", (a%1,b%1,a//1,b//1)==(F(1,5),F(1,5),51,52))
c("pli : 1/5 et 7/10 ont la meme image 2/5", (2*F(1,5))%1==(2*F(7,10))%1==F(2,5))
x=F(1,3)
for n in range(15): x=2*x
c("1/3 double quinze fois sans pli = 32 768/3", x==F(32768,3))
x0=F(1,3); x=x0; w=0
for n in range(8): x=2*x; w=w*2+int(x); x=x-int(x)
c("les tours gardes rendent le depart : x0 = (x8 + w8)/2^8", (x+w)/256==x0)
c("seuil : n = p/log10 f et p/log2 f sont la meme formule", abs(16/math.log10(2)-(16*math.log2(10))/math.log2(2))<1e-9)
print("VERDICT :", "TOUTES LES VERIFICATIONS PASSENT" if ok else "AU MOINS UN ECHEC")
