back to table · edit · history · where entries came from · files · download
1362 bytes, as of the version from 2026-11-16 04:25 (current). Recorded here, not run.
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.matrix.constructor import matrix
from modular import smith_factors,integral_index_certificate
from pathlib import Path
import json,gzip,base64,time
cases=[[[6,2],[4,8]],[[2,4],[6,8]],[[1,3,2],[5,8,7],[2,7,13]],[[16,4,0],[4,32,0],[0,0,81]],[[1,0],[0,-1]]]
results=[]
for rows in cases:
A=matrix(ZZ,rows);expected=[int(x) for x in A.elementary_divisors()];actual,proof=smith_factors(A);assert actual==expected
results.append({'matrix':rows,'native_smith':expected,'local_smith':actual})
p=Path(__file__).parent
for d in [8,10,13]:
o=json.loads(gzip.decompress((p/f'certificate-2-{d}.json.gz').read_bytes()));K=matrix(ZZ,o['K']);t=time.monotonic();actual,proof=smith_factors(K)
assert actual==o['summary']['elementary_divisors'];results.append({'case':[2,d],'matched_saved_native_smith':True,'seconds':time.monotonic()-t});print('matched',d,results[-1]['seconds'],flush=True)
I=matrix(ZZ,2,2,1);assert integral_index_certificate(I,[0,1])['row_lattice_index']==1
try:integral_index_certificate(matrix(ZZ,[[2,0],[0,1]]),[0,1])
except AssertionError:bad=True
else:bad=False
assert bad
out={'known_answer_control':True,'negative_control_rejected':bad,'results':results}
print('ARTIFACT modular-controls.json '+base64.b64encode(json.dumps(out,indent=2).encode()).decode(),flush=True)