Objets/Documentation
contraste31.py
Conditionnels communs et contrôles · contraste31.py
Télécharger ↓"""A weighted one-dimensional contrast bound, attained when the other conditional is shared."""
from fractions import Fraction as F
from itertools import combinations_with_replacement
from pathlib import Path
import json
from rayon26 import Number,witness
from verifier26 import verify
def cell(laws,start):
ab=[(r[start],sum(r[start:start+2])) for r in laws]
active=[(a,p) for a,p in ab if p]
if not active:return F(0),[F(0),F(1)]
value=max(abs(q*a-p*b)/(q+p) for (a,p),(b,q) in combinations_with_replacement(active,2))
lo=max([F(0)]+[(a-value)/p for a,p in active]);hi=min([F(1)]+[(a+value)/p for a,p in active])
assert lo<=hi
return value,[lo,hi]