Datasets:
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
Tags:
mathematics
harmonic-analysis
inverse-problems
arithmetic-matroids
flat-tori
finite-jet-reconstruction
License:
Download release/tests/test_arithmetic.py from PureOne/Eves-Impossible-Complex-Frequencies-v5.0.0: direct link, hf CLI and curl.
- Browser
- Download file 4.1 kB
-
https://huggingface.co/datasets/PureOne/Eves-Impossible-Complex-Frequencies-v5.0.0/resolve/main/release/tests/test_arithmetic.py
- Command line
-
hf download hf://datasets/PureOne/Eves-Impossible-Complex-Frequencies-v5.0.0/release/tests/test_arithmetic.py
-
curl -L -o test_arithmetic.py https://huggingface.co/datasets/PureOne/Eves-Impossible-Complex-Frequencies-v5.0.0/resolve/main/release/tests/test_arithmetic.py
4.1 kB
| from fractions import Fraction as F | |
| from itertools import combinations,product | |
| from math import gcd | |
| import pytest | |
| from evefreq.arithmetic import * | |
| from evefreq.quantization import * | |
| from evefreq.examples import * | |
| def test_integer_left_inverse(A): | |
| C=left_inverse(A); d=len(A[0]); assert matmul(C,A)==[[int(i==j) for j in range(d)] for i in range(d)] | |
| def test_invalid_faithful_model(A): | |
| with pytest.raises(ValueError): validate(A) | |
| def test_bareiss_fraction_and_swaps(): | |
| assert det([[0,2],[3,4]])==-6 | |
| assert det([[F(1,2),F(1,3)],[F(1,3),F(2,3)]])==F(2,9) | |
| assert det([])==1 | |
| def test_maximal_unimodular_not_total_unimodular(): | |
| A=[[2,1],[3,2],[5,3]] | |
| assert unimodular(A) | |
| assert max(abs(v) for row in A for v in row)>1 | |
| assert all(set(c['character'])<={-1,0,1} for c in cocircuits(A)) | |
| def test_bad_primes(A,expected): | |
| assert bad_primes(A)==expected | |
| def test_unimodular_exact_distance_and_kissing(q): | |
| for A,w in [([[1,0],[0,1],[1,-1]],[1,1,1]), | |
| ([[1,0],[0,1],[1,-1]],[F(1,2),F(3,2),2]), | |
| ([[2,1],[3,2],[5,3]],[1,2,3]), | |
| (cographic_complete_five(),[1]*10)]: | |
| lam,cc=cogirth(A,w); result=exact_minimum(A,w,q) | |
| assert result['squared_distance']==ENERGY[q][1]*lam | |
| assert len(result['winners'])==(1 if q==2 else 2)*len(cc) | |
| def test_unsafe_modulus_constructive_witness(q): | |
| A=[[1,0],[0,1],[2,3]]; cert=unsafe_witness(A,q) | |
| assert cert is not None | |
| assert cert['energy_upper']<cert['predicted_lower'] | |
| assert any(cert['x']) | |
| assert all(cert['residues'][i]==0 for i in cert['basis']) | |
| if q in ENERGY: | |
| out=exact_minimum(A,cert['weights'],q) | |
| assert out['squared_distance']<ENERGY[q][1]*cert['cogirth'] | |
| def test_safe_modulus_not_necessarily_exact(q): | |
| A=[[2],[3]]; assert modulus_safe(A,q) | |
| out=numeric_minimum(A,[1,1],q) | |
| import math | |
| lower=8*math.sin(math.pi/q)**2 | |
| assert out['squared_distance']>=lower-1e-12 | |
| if q==7: assert out['squared_distance']>lower+1 | |
| def test_smith_all_subsets(q): | |
| A=[[2,0],[0,3],[1,1]] | |
| for r in range(4): | |
| for ii in combinations(range(3),r): | |
| rows=[A[i] for i in ii] | |
| count=sum(all(z%q==0 for z in apply(rows,x)) for x in product(range(q),repeat=2)) | |
| assert kernel_count(rows,q,d=2)==count | |
| def test_smith_nonprimitive(): | |
| assert smith_invariants([[2,0],[0,3]])==(1,6) | |
| assert kernel_count([[2,0],[0,3]],6)==6 | |
| def test_cographic_beyond_graph_incidence(): | |
| A=cographic_complete_five() | |
| assert len(bases(A))==125 | |
| assert det(gram(A,[1]*10))==125 | |
| s,cc=cogirth(A,[1]*10) | |
| assert s==3 and len(cc)==10 | |
| ss,short,_=shortest_vectors(A,[1]*10) | |
| assert ss==3 and len(short)==20 | |
| def test_exact_cauchy_binet(): | |
| A=[[1,0],[0,1],[2,3]]; w=[F(1,2),3,F(4,5)] | |
| expansion=sum(detval**2*__import__('functools').reduce(lambda a,b:a*b,(w[i] for i in ii),F(1)) for ii,detval in bases(A)) | |
| assert det(gram(A,w))==expansion | |
| def test_state_budget_and_float_matrix_rejected(): | |
| with pytest.raises(ValueError): exact_minimum([[1,0],[0,1]],[1,1],6,max_states=1) | |
| with pytest.raises(TypeError): validate([[1.0]]) | |
| with pytest.raises(ValueError): weights([0],1) | |
| def test_every_rational_metric_realization(G): | |
| cert=realize_rational_metric(G) | |
| assert gram(cert['A'],cert['weights'])==G | |
| assert primitive(cert['A']) | |
| assert len(cert['A'])==2*len(G) | |
| assert matmul(cert['left_inverse'],cert['A'])==[[int(i==j) for j in range(len(G))] for i in range(len(G))] | |
| def test_indefinite_metric_rejected(): | |
| with pytest.raises(ValueError): realize_rational_metric([[1,2],[2,1]]) | |