Datasets:
Formats:
csv
Languages:
English
Size:
1K - 10K
Tags:
mathematics
inverse-problems
observability
noncommutative-algebra
symbolic-computation
calibration-rigidity
Download tests/test_algebra.py from PureOne/AELYRION-NOULITH-III: direct link, hf CLI and curl.
- Browser
- Download file 2.82 kB
-
https://huggingface.co/datasets/PureOne/AELYRION-NOULITH-III/resolve/main/tests/test_algebra.py
- Command line
-
hf download hf://datasets/PureOne/AELYRION-NOULITH-III/tests/test_algebra.py
-
curl -L -o test_algebra.py https://huggingface.co/datasets/PureOne/AELYRION-NOULITH-III/resolve/main/tests/test_algebra.py
2.82 kB
| from itertools import product | |
| import sympy as sp | |
| import pytest | |
| from noulith import TwistedAlgebra, bits, partitions | |
| def test_associativity_exhaustive_four_channels(): | |
| alg = TwistedAlgebra(4, {(0,1):-1,(0,2):2,(0,3):-3,(1,2):5,(1,3):-2,(2,3):7}) | |
| for a,b,c in product(range(16), repeat=3): | |
| ab,w1=alg.monomial_product(a,b); abc,w2=alg.monomial_product(ab,c) | |
| bc,w3=alg.monomial_product(b,c); abc2,w4=alg.monomial_product(a,bc) | |
| assert abc==abc2 and w1*w2==w3*w4 | |
| def test_shuffle_independent_permutation_oracle(m): | |
| q={(i,j):sp.Symbol(f'q{i}{j}') for i in range(m) for j in range(i+1,m)} | |
| alg=TwistedAlgebra(m,q) | |
| table=alg.shuffle_table() | |
| for mask in range(1<<m): | |
| assert sp.expand(table[mask]-alg.shuffle_bruteforce(mask))==0 | |
| def test_uniform_q_factorial(m,phase): | |
| alg=TwistedAlgebra.uniform(m,phase) | |
| table=alg.shuffle_table() | |
| for mask in range(1<<m): | |
| d=mask.bit_count() | |
| expected=sp.prod(sum(phase**j for j in range(k)) for k in range(1,d+1)) | |
| assert table[mask]==expected | |
| def test_isolated_rows_by_actual_multiplication(): | |
| a,b,c=sp.symbols('a b c') | |
| alg=TwistedAlgebra(3,{(0,1):a,(0,2):b,(1,2):c}) | |
| sh=alg.shuffle_table() | |
| for mask in range(8): | |
| for part in partitions(mask,3): | |
| predicted=alg.isolated_unit(part)*sp.prod(sh[B] for B in part) | |
| assert sp.expand(alg.isolated_response(part)-predicted)==0 | |
| for initial in range(8): | |
| if initial != (7^mask): | |
| assert alg.isolated_response(part,initial)==0 | |
| def test_mixed_relations_on_right_matrices(): | |
| alg=TwistedAlgebra(3,{(0,1):2,(0,2):-3,(1,2):5}) | |
| t=[alg.right_matrix(i) for i in range(3)] | |
| for i in range(3): | |
| assert t[i]*t[i]==sp.zeros(8) | |
| for j in range(i+1,3): | |
| # Right multiplication reverses composition order. | |
| assert t[i]*t[j]==alg.q[i,j]*t[j]*t[i] | |
| def test_three_channel_formula_and_nonhereditary_visibility(): | |
| a,b,c=sp.symbols('a b c') | |
| alg=TwistedAlgebra(3,{(0,1):a,(0,2):b,(1,2):c}) | |
| assert sp.expand(alg.shuffle_table()[7]-(1+a+c+a*b+b*c+a*b*c))==0 | |
| table=TwistedAlgebra(3,{(0,1):-1,(0,2):1,(1,2):-1}).shuffle_table() | |
| assert table[3]==0 and table[6]==0 and table[7]==-2 | |
| assert sum(p!=0 for p in table)==6 | |
| def test_invalid_algebra_inputs(): | |
| with pytest.raises(ValueError): TwistedAlgebra(0,{}) | |
| with pytest.raises(ValueError): TwistedAlgebra(2,{}) | |
| with pytest.raises(ValueError): TwistedAlgebra(2,{(0,1):0}) | |
| alg=TwistedAlgebra.uniform(2,-1) | |
| with pytest.raises(ValueError): alg.monomial_product(-1,0) | |
| with pytest.raises(ValueError): alg.isolated_response((1,1)) | |