Datasets:
Formats:
csv
Languages:
English
Size:
1K - 10K
Tags:
mathematics
inverse-problems
observability
noncommutative-algebra
symbolic-computation
calibration-rigidity
Download tests/test_third_deficit.py from PureOne/AELYRION-NOULITH-III: direct link, hf CLI and curl.
- Browser
- Download file 6.49 kB
-
https://huggingface.co/datasets/PureOne/AELYRION-NOULITH-III/resolve/main/tests/test_third_deficit.py
- Command line
-
hf download hf://datasets/PureOne/AELYRION-NOULITH-III/tests/test_third_deficit.py
-
curl -L -o test_third_deficit.py https://huggingface.co/datasets/PureOne/AELYRION-NOULITH-III/resolve/main/tests/test_third_deficit.py
6.49 kB
| from itertools import combinations, permutations | |
| from math import comb, ceil | |
| import random | |
| import pytest | |
| import sympy as sp | |
| from noulith.algebra import TwistedAlgebra | |
| from noulith.third import ( | |
| all_components, component_membership, component_equations, intersection_dimension, | |
| certify_scalar, predicted_rank, direct_block_rank, calibration_classes, | |
| optimal_calibration_subfamily, example_point, q_from_exponents, complete_multipartite_parts, | |
| multipartite_matching, pairs, | |
| ) | |
| KINDS=['origin','star','triangle','twin','uniform_star','star_twin','edge','double_star','generic'] | |
| def test_rank_by_independent_all_subset_enumeration(m,kind): | |
| q=example_point(m,kind) | |
| expected={'origin':2**m-1-m-comb(m,2),'star':2**m-m-1, | |
| 'triangle':2**m-4,'twin':2**m-4,'uniform_star':2**m-2*m, | |
| 'star_twin':2**m-m-2,'edge':2**m-2*m,'double_star':2**m-1,'generic':2**m}[kind] | |
| assert direct_block_rank(m,q,m-3)==expected==predicted_rank(m,q) | |
| def test_relabeling_and_witnesses(seed): | |
| m=6; p=list(range(m));random.Random(seed).shuffle(p) | |
| kind=KINDS[seed%len(KINDS)];q=example_point(m,kind,p) | |
| c=certify_scalar(m,q) | |
| assert c.visible==(not bool(component_membership(m,q))) | |
| assert predicted_rank(m,q)==direct_block_rank(m,q,m-3) | |
| if c.visible: | |
| alg=TwistedAlgebra(m,q); blocks=c.full_partition(m) | |
| assert len(blocks)==m-3 | |
| assert alg.isolated_response(blocks)==alg.isolated_unit(blocks)*c.normalized_response !=0 | |
| def test_component_counts_dimensions_and_spanning(m): | |
| cs=all_components(m) | |
| assert len(cs)==m+comb(m+1,3) | |
| for c in [('star',(0,)),('triangle',(0,1,2)),('twin',(0,m-1))]: | |
| assert comb(m,2)-component_equations(m,c).rank()==(m-1 if c[0]=='star' else 3) | |
| def test_intersection_lattice(m): | |
| cases=[([('star',(0,)),('star',(1,))],1), | |
| ([('star',(0,)),('triangle',(0,1,2))],2), | |
| ([('star',(5,)),('triangle',(0,1,2))],0), | |
| ([('star',(0,)),('twin',(0,1))],2), | |
| ([('star',(2,)),('twin',(0,1))],0), | |
| ([('triangle',(0,1,2)),('twin',(0,1))],1), | |
| ([('triangle',(0,1,2)),('twin',(3,4))],0), | |
| ([('twin',(0,1)),('twin',(0,2))],1), | |
| ([('twin',(0,1)),('twin',(2,3))],0), | |
| ([('twin',(0,1)),('twin',(0,2)),('twin',(0,3))],1), | |
| ([('twin',(0,1)),('twin',(0,2)),('twin',(1,2))],0)] | |
| for cs,d in cases: assert intersection_dimension(m,cs)==d | |
| def test_sharp_calibration_construction(m): | |
| E=optimal_calibration_subfamily(m) | |
| assert len(E)==ceil(2*(m-1)/3) | |
| assert len(calibration_classes(m,E))==1 | |
| assert len(calibration_classes(m,pairs(m)))==1 | |
| assert len(calibration_classes(m,()))==comb(m,2) | |
| def test_a_star_of_constraints_does_not_synchronize_all_scales(m): | |
| E=tuple((0,j) for j in range(1,m)) | |
| assert len(calibration_classes(m,E))==2 | |
| def test_generic_twin_core_rank_for_all_core_sizes(m,r): | |
| if r>m: return | |
| for c in range(1,m+1): | |
| d=[[0]*m for _ in range(m)] | |
| for i,j in pairs(m): | |
| if not (i<c and j<c): d[i][j]=1;d[j][i]=-1 | |
| q=q_from_exponents(d) | |
| predicted=2**(m-c)*sum(comb(c,j) for j in range(min(c,r)+1)) | |
| assert direct_block_rank(m,q,r)==predicted | |
| def test_five_channel_counterexample_is_exact(): | |
| m=5;h=[sp.Rational(i,1000) for i in range(m)] | |
| q={(i,j):-1+(h[j]-h[i])/(1-h[i]+h[i]*h[j]) for i,j in pairs(m)} | |
| alg=TwistedAlgebra(m,q);P=alg.shuffle_table() | |
| assert all(q[e]!=-1 for e in pairs(m)) | |
| assert all(P[s]==0 for s in range(1,1<<m) if s.bit_count()>=3) | |
| assert direct_block_rank(m,q,2)<2**m | |
| with pytest.raises(ValueError):certify_scalar(5,q) | |
| def test_fourth_power_pairing_decomposition(): | |
| m=4; f=sp.symbols('f01 f02 f03 f12 f13 f23') | |
| q={e:-1+x for e,x in zip(pairs(m),f)};alg=TwistedAlgebra(m,q) | |
| formula=0 | |
| for A,B in [((0,1),(2,3)),((0,2),(1,3)),((0,3),(1,2))]: | |
| a=sum(1<<i for i in A);b=sum(1<<i for i in B) | |
| chi1=alg.monomial_product(a,b)[1];chi2=alg.monomial_product(b,a)[1] | |
| formula+=(1+q[A])*(1+q[B])*(chi1+chi2) | |
| assert sp.expand(formula-alg.shuffle_bruteforce(15))==0 | |
| def test_triangle_with_one_edge_and_twin_identity(): | |
| a,b=sp.symbols('a b') | |
| alg=TwistedAlgebra(3,{(0,1):-1,(0,2):a,(1,2):b}) | |
| assert sp.expand(alg.shuffle_bruteforce(7))==b-a | |
| def test_nonquartet_witness_routes(m): | |
| # Dense exact triangle-flat data: quartet powers vanish, but a size-three matching is a witness. | |
| h=[sp.Rational(i,1000) for i in range(m)] | |
| q={(i,j):-1+(h[j]-h[i])/(1-h[i]+h[i]*h[j]) for i,j in pairs(m)} | |
| c=certify_scalar(m,q) | |
| assert c.visible and sorted(map(len,c.motif))==[2,2,2] | |
| alg=TwistedAlgebra(m,q);blocks=c.full_partition(m) | |
| assert alg.isolated_response(blocks)==alg.isolated_unit(blocks)*c.normalized_response !=0 | |
| def test_validation_rejects_unproved_numeric_domain(): | |
| q=example_point(6,'generic');q[(0,1)]=sp.Rational(1,2) | |
| with pytest.raises(ValueError):certify_scalar(6,q) | |
| q=example_point(6,'generic');q[(0,1)]=sp.Float(-1.001) | |
| with pytest.raises(ValueError):certify_scalar(6,q) | |
| def test_isolate_route_returns_triple_pair(): | |
| m=6;h=[sp.Rational(i,1000) for i in range(4)] | |
| q={e:sp.S.NegativeOne for e in pairs(m)} | |
| for i,j in combinations(range(4),2):q[i,j]=-1+(h[j]-h[i])/(1-h[i]+h[i]*h[j]) | |
| c=certify_scalar(m,q) | |
| assert c.visible and sorted(map(len,c.motif))==[2,3] | |
| alg=TwistedAlgebra(m,q);b=c.full_partition(m) | |
| assert alg.isolated_response(b)==alg.isolated_unit(b)*c.normalized_response !=0 | |
| def test_unequal_core_route_returns_triple_pair(): | |
| m=6;d=[[0]*m for _ in range(m)] | |
| for i in range(m-2): | |
| for p in (m-2,m-1):d[i][p]=i+1;d[p][i]=-i-1 | |
| q=q_from_exponents(d);alg=TwistedAlgebra(m,q) | |
| assert all(alg.shuffle_bruteforce(sum(1<<i for i in four))==0 | |
| for four in combinations(range(m),4)) | |
| c=certify_scalar(m,q) | |
| assert c.visible and sorted(map(len,c.motif))==[2,3] | |
| b=c.full_partition(m) | |
| assert alg.isolated_response(b)==alg.isolated_unit(b)*c.normalized_response !=0 | |
| def test_analytic_feedback_freezes_first_order_controls(): | |
| a,b,z=sp.symbols('a b z') | |
| # Each frozen-control sensor is R(z,u)=(z^2, u*z^3). | |
| y1=z**2*a+z**3*b | |
| y2=z**2*a+(1+y1+y1**2)*z**3*b | |
| row=sp.Matrix([y2]).jacobian([a,b]).subs({a:0,b:0}) | |
| assert row==sp.Matrix([[z**2,z**3]]) | |
| # Complete-frame outputs X=z^2*a and Y=z^3*b simulate the whole transcript. | |
| X,Y=sp.symbols('X Y');F=X+(1+(X+Y)+(X+Y)**2)*Y | |
| assert sp.expand(F.subs({X:z**2*a,Y:z**3*b})-y2)==0 | |