Datasets:
Formats:
csv
Languages:
English
Size:
1K - 10K
Tags:
mathematics
inverse-problems
observability
noncommutative-algebra
symbolic-computation
calibration-rigidity
Download tests/test_boundaries.py from PureOne/AELYRION-NOULITH-III: direct link, hf CLI and curl.
- Browser
- Download file 2.47 kB
-
https://huggingface.co/datasets/PureOne/AELYRION-NOULITH-III/resolve/main/tests/test_boundaries.py
- Command line
-
hf download hf://datasets/PureOne/AELYRION-NOULITH-III/tests/test_boundaries.py
-
curl -L -o test_boundaries.py https://huggingface.co/datasets/PureOne/AELYRION-NOULITH-III/resolve/main/tests/test_boundaries.py
2.47 kB
| from itertools import product | |
| import numpy as np | |
| import sympy as sp | |
| def test_nonnegative_word_expansion_has_no_cancellation(): | |
| # Positive states cannot exhibit exact cancellation. Differences still can. | |
| A=sp.Matrix([[0,1],[1,0]]) | |
| B=sp.Matrix([[1,0],[0,0]]) | |
| C=sp.Matrix([[1,1]]) | |
| x=sp.Matrix([1,0]) | |
| for u,v in product(range(3),repeat=2): | |
| lhs=(C*(u*A+v*B)**2*x)[0] | |
| rhs=u*u*(C*A*A*x)[0]+u*v*(C*(A*B+B*A)*x)[0]+v*v*(C*B*B*x)[0] | |
| assert lhs==rhs and lhs>=0 | |
| def test_dual_rail_lift_preserves_every_short_word(): | |
| matrices=[sp.Matrix([[0,-2],[1,0]]),sp.Matrix([[3,1],[-1,2]])] | |
| lifts=[] | |
| for A in matrices: | |
| plus=A.applyfunc(lambda z:max(z,0)); minus=A.applyfunc(lambda z:max(-z,0)) | |
| lifts.append(plus.row_join(minus).col_join(minus.row_join(plus))) | |
| D=sp.eye(2).row_join(-sp.eye(2)) | |
| for A,L in zip(matrices,lifts): | |
| assert D*L==A*D | |
| assert all(v>=0 for v in L) | |
| z=sp.Matrix([2,0,0,3]) | |
| for n in range(5): | |
| for word in product(range(2),repeat=n): | |
| state=z; direct=D*z | |
| for index in word: | |
| state=lifts[index]*state; direct=matrices[index]*direct | |
| assert D*state==direct | |
| def test_bounded_nonanalytic_cross_recovery_on_valid_data(): | |
| for a,b,x in product([-2.,-.1,.2,1.],[-3.,-.3,.4,2.],[-2.,0.,3.]): | |
| y1,y2=a*a*x,b*b*x | |
| weights=np.array([a*b*a*a,a*b*b*b])/(a**4+b**4) | |
| assert np.isclose(weights@np.array([y1,y2]),a*b*x) | |
| assert np.linalg.norm(weights)<=1/np.sqrt(2)+1e-12 | |
| def test_positive_substochastic_lift_separates_two_uniformly_indistinguishable_states(): | |
| from noulith import TwistedAlgebra | |
| algebra=TwistedAlgebra(2,{(0,1):sp.Integer(-1)}) | |
| lifts=[] | |
| for i in range(2): | |
| A=algebra.right_matrix(i) | |
| plus=A.applyfunc(lambda x:max(x,0)); minus=A.applyfunc(lambda x:max(-x,0)) | |
| lift=plus.row_join(minus).col_join(minus.row_join(plus)) | |
| assert all(x>=0 for x in lift) | |
| assert all(sum(lift[:,j])<=1 for j in range(8)) | |
| lifts.append(lift) | |
| zplus=sp.zeros(8,1); zplus[0]=1 | |
| zminus=sp.zeros(8,1); zminus[4]=1 | |
| C=sp.zeros(1,8); C[0,3]=1 | |
| u,v=sp.symbols('u v') | |
| mixture=u*lifts[0]+v*lifts[1] | |
| for d in range(5): | |
| assert sp.expand((C*mixture**d*(zplus-zminus))[0])==0 | |
| assert sp.expand((C*mixture**2*zplus)[0])==u*v | |
| assert (C*lifts[1]*lifts[0]*zplus)[0]==1 | |
| assert (C*lifts[1]*lifts[0]*zminus)[0]==0 | |