Download src/verify_exact.py from PureOne/Unxei-XII-Resolution-Actuation-Law: direct link, hf CLI and curl.
- Browser
- Download file 6.44 kB
-
https://huggingface.co/datasets/PureOne/Unxei-XII-Resolution-Actuation-Law/resolve/main/src/verify_exact.py
- Command line
-
hf download hf://datasets/PureOne/Unxei-XII-Resolution-Actuation-Law/src/verify_exact.py
-
curl -L -o verify_exact.py https://huggingface.co/datasets/PureOne/Unxei-XII-Resolution-Actuation-Law/resolve/main/src/verify_exact.py
6.44 kB
| """Exact rational and algebraic certificates. No floating-point pass criteria.""" | |
| import json | |
| from pathlib import Path | |
| import sympy as sp | |
| ROOT = Path(__file__).resolve().parents[1] | |
| x, y, e = sp.symbols('x y epsilon', real=True) | |
| checks = [] | |
| def check(name, condition, detail=None): | |
| if condition is not True and condition != sp.true: | |
| raise AssertionError(name + ': ' + str(condition)) | |
| checks.append({'name':name, 'passed':True, 'detail':detail}) | |
| def valuation(f, var): | |
| f = sp.cancel(f) | |
| if f == 0: | |
| return sp.oo | |
| p,q = sp.fraction(f) | |
| def order(poly): | |
| return min(k[0] for k,c in sp.Poly(poly,var).terms() if c != 0) | |
| return order(p)-order(q) | |
| def analytic_energy_certificate(G, data, var): | |
| """Exact pivoted analytic Schur elimination for rational matrix families. | |
| Positivity and full rank near the puncture are THEOREM HYPOTHESES. | |
| This function checks even pivot orders and positive leading coefficients, | |
| but is not a global positivity verifier for arbitrary user matrices. | |
| """ | |
| G, data = sp.Matrix(G), sp.Matrix(data) | |
| terms, pivots = [], [] | |
| while G.rows: | |
| k = min(range(G.rows),key=lambda j:valuation(G[j,j],var)) | |
| if G[k,k] == 0: | |
| raise ValueError('Identically singular family') | |
| if k: | |
| G.row_swap(0,k); G.col_swap(0,k); data.row_swap(0,k) | |
| p, z = sp.factor(G[0,0]), sp.factor(data[0]) | |
| vp, vz = valuation(p,var), valuation(z,var) | |
| a = sp.limit(p/var**vp,var,0) | |
| if vp % 2 or a <= 0: | |
| raise ValueError('Failed positive analytic Gramian pivot hypothesis') | |
| terms.append(sp.cancel(z*z/p)) | |
| pivots.append({'pivot':str(p),'pivot_order':int(vp), | |
| 'target':str(z),'target_order':None if vz is sp.oo else int(vz), | |
| 'leading_pivot':str(a)}) | |
| if G.rows == 1: | |
| break | |
| cross = G[1:,0] | |
| ratios = cross/p | |
| if any(valuation(v,var)<0 for v in ratios): | |
| raise ValueError('Nonanalytic elimination ratio') | |
| data = (data[1:,0]-cross*z/p).applyfunc(sp.cancel) | |
| G = (G[1:,1:]-cross*cross.T/p).applyfunc(sp.cancel) | |
| energy = sp.factor(sum(terms)) | |
| ve = valuation(energy,var) | |
| leading = sp.limit(energy/var**ve,var,0) if energy != 0 else 0 | |
| return energy, pivots, ve, leading | |
| def main(): | |
| polynomials = [] | |
| for m in range(7): | |
| invB = sp.factorial(2*m+1)/sp.factorial(m)**2 | |
| H = sp.expand(1-2*invB*sp.integrate((x*(1-x))**m,(x,0,y))) | |
| check(f'flat_m{m}_left_value', H.subs(y,0)==1) | |
| check(f'flat_m{m}_right_value', H.subs(y,1)==-1) | |
| for k in range(1,m+1): | |
| check(f'flat_m{m}_jet{k}_both_nodes', | |
| sp.diff(H,y,k).subs(y,0)==0 and sp.diff(H,y,k).subs(y,1)==0) | |
| check(f'flat_m{m}_leading_coefficient', | |
| H.coeff(y,2*m+1)==(-1)**(m+1)*2*sp.binomial(2*m,m)) | |
| r=sp.symbols('r', nonnegative=True) | |
| outer=sp.expand(2*invB*sp.integrate((x*(1+x))**m,(x,0,r))) | |
| check(f'flat_m{m}_outer_error',sp.expand((H.subs(y,-r)-1)-(-1)**m*outer)==0) | |
| polynomials.append({'m':m,'H':str(H),'outer_error':str(outer)}) | |
| rc=(sp.sqrt(2)-1)/2 | |
| check('critical_radius_exact',sp.simplify(4*rc*(1+rc)-1)==0) | |
| # An exact constrained cubic minimax solution on r=1/4 bands. | |
| P=(32*x**3-26*x)/9 | |
| check('cubic_nominal_values',P.subs(x,-sp.Rational(1,2))==1 and P.subs(x,sp.Rational(1,2))==-1) | |
| check('cubic_outer_and_inner_equalization', | |
| P.subs(x,sp.Rational(1,4))+1==sp.Rational(1,3) and | |
| P.subs(x,sp.Rational(3,4))+1==sp.Rational(1,3)) | |
| c=sp.symbols('c',real=True) | |
| Q=-2*x+c*x*(x*x-sp.Rational(1,4)) | |
| EB=1+Q.subs(x,sp.Rational(1,4)); EA=1+Q.subs(x,sp.Rational(3,4)) | |
| check('cubic_universal_lower_certificate',sp.simplify((5*EB+EA)/6)==sp.Rational(1,3)) | |
| xmin=sp.sqrt(sp.Rational(13,48)) | |
| check('cubic_only_positive_critical_point',sp.simplify(sp.diff(P,x).subs(x,xmin))==0) | |
| minimum=sp.simplify(1+P.subs(x,xmin)) | |
| check('cubic_interior_error_within_bound',bool(minimum>=-sp.Rational(1,3)) and bool(minimum<=sp.Rational(1,3))) | |
| check('cubic_energy_ratio',sp.simplify((sp.Rational(32,9)/4)**2)==sp.Rational(64,81)) | |
| H1=4*x**3-3*x | |
| check('flat_cubic_outer_error',H1.subs(x,sp.Rational(3,4))+1==sp.Rational(7,16)) | |
| # Multiscale collision: two of three nodes are separated only by epsilon^2. | |
| nodes=[0,e,e+e**2] | |
| multi=[] | |
| for target,expected in [([0,0,1],3),([1,0,0],2),([1,1,1],0)]: | |
| H=sp.interpolate(list(zip(nodes,target)),x) | |
| poles=max(-valuation(co,e) for co in sp.Poly(H,x).all_coeffs()) | |
| check('multiscale_target_'+''.join(map(str,target)),poles==expected) | |
| multi.append({'targets':target,'polynomial':str(sp.factor(H)),'energy_exponent':2*expected}) | |
| L=sp.Matrix([[1,0,0],[1+e,1,0],[e**2,2-e,1]]) | |
| D=sp.diag(1,e**2,e**6) | |
| G=L*D*L.T | |
| tests=[(sp.Matrix([1,0,0]),0),(sp.Matrix([0,1,0]),-2), | |
| (sp.Matrix([0,0,1]),-6),(sp.Matrix([0,0,e**2]),-2), | |
| (sp.Matrix([0,0,e**3]),0),(sp.Matrix([e,e**2,e**4]),2)] | |
| analytic=[] | |
| for j,(z,order) in enumerate(tests): | |
| data=L*z | |
| energy,pivots,ve,leading=analytic_energy_certificate(G,data,e) | |
| check(f'analytic_case{j}_exact_energy',sp.cancel(energy-(z.T*D.inv()*z)[0])==0) | |
| check(f'analytic_case{j}_valuation',ve==order) | |
| analytic.append({'target':str(data),'energy':str(energy),'order':int(ve),'leading':str(leading),'pivots':pivots}) | |
| for a in [1,2,3,4,5]: | |
| Gweak=sp.diag(1,e**2,e**6+e**(2*a)) | |
| energy,pivots,ve,leading=analytic_energy_certificate(Gweak,sp.Matrix([0,0,1]),e) | |
| check(f'weak_analytic_power_{a}',ve==-2*min(a,3)) | |
| # A hidden zero shared coupling is a true feasibility obstruction. | |
| check('zero_coupling_nonzero_target_obstruction',sp.Matrix([[1,0],[0,0]]).rank()==1) | |
| report={'status':'PASS','arithmetic':'SymPy exact rational/algebraic', | |
| 'assertions':len(checks),'checks':checks,'flat_polynomials':polynomials, | |
| 'critical_radius':str(rc),'constrained_cubic':str(P), | |
| 'cubic_minimum_error_value':str(minimum),'multiscale':multi,'analytic_cases':analytic} | |
| path=ROOT/'results/exact_certificates.json' | |
| path.write_text(json.dumps(report,indent=2),encoding='utf-8') | |
| print(f'PASS: {len(checks)} exact assertions; {path.name}') | |
| if __name__=='__main__': | |
| main() | |