offline_check.py

back to table · edit · history · where entries came from · files · download

6218 bytes, as of the version from 2026-11-27 14:56 (current). Recorded here, not run.

"""Independent exact recurrence and saturated literal-matrix elimination.

sage -python offline_check.py
Prints one JSON checkpoint per n, followed by the complete result JSON.
The recurrence is transcribed from Petersen (2015), printed p.868, Thm 7.2.
The matrix check constructs the group relation and preferred longitude directly
from Mathews, pp.1450044-2--3. It does not use the summation or the recurrence.
Saturation is implemented by adjoining 1-s*L*(trace(commutator)-2).
The coefficient field QQ(M) already inverts M. Each representation relation
reduces to one polynomial monic in Z, with Laurent-polynomial coefficients.
Therefore its nonzero-M fibers have finitely many Z, and the longitude fixes L;
there are no vertical peripheral curves lost by working over QQ(M).
"""
import json,time,sys
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
import sage.rings.polynomial.laurent_polynomial_ring
from sage.matrix.constructor import matrix
import generate as g

def emit(kind,data):print(kind+' '+json.dumps(data,sort_keys=True),flush=True)

def recurrence():
    L,M=g.L,g.M
    X=(1-L)*M**8+2*L*M**6+(L+1)**2*M**4+2*L*M**2+L**2-L
    D=M**2*(L+M**2)**2
    r={0:g.R(1),1:L+M**6,-1:M**4*L**2+(-M**8+M**6+2*M**4+M**2-1)*L+M**4,
       2:(1-L)*M**14+2*L*M**12+(L**2+2*L)*M**10-M**8*L**2-L*M**6+(2*L**2+L)*M**4+2*M**2*L**2+L**3-L**2}
    for n in (3,4):r[n]=X*r[n-1]-D**2*r[n-2]
    for n in (-2,-3,-4):r[n]=X*r[n+1]-D**2*r[n+2]
    return {n:g.normalize(p) for n,p in r.items()}

def literal_elimination(n):
    T=PolynomialRing(QQ,'m');m=T.gen();K=T.fraction_field()
    U=PolynomialRing(K,names=('z',));z=U.gen();UF=U.fraction_field()
    a=matrix(UF,[[m,1],[0,1/m]]);b=matrix(UF,[[m,0],[z,1/m]])
    w=a*b.inverse()*a.inverse()*b
    wb=b*a.inverse()*b.inverse()*a
    wn=w**n;relation=a*wn-wn*b;longitude=wn*(wb**n)
    rs=[U(x) for x in relation.list() if x]
    r=rs[0]
    for q in rs[1:]:r=r.gcd(q)
    r=r.monic()
    assert all((q%r)==0 for q in rs)
    # Exact verification that the four literal equations define r=0 over
    # QQ[M,M^-1], and not only over its fraction field.
    r_from_word=U((m-1/m)*wn[0,1]+wn[1,1])
    assert r_from_word/r in K
    assert r_from_word.leading_coefficient() in (1,-1)
    assert all(c.denominator().is_monomial() for c in r_from_word.coefficients())
    assert any(q/r_from_word in K and (q/r_from_word).numerator().is_monomial()
               and (q/r_from_word).denominator().is_monomial() for q in rs)
    irr=U((a*b*a.inverse()*b.inverse()).trace()-2)
    P=PolynomialRing(K,names=('s','z','l'),order='lex');s,zp,l=P.gens()
    def lift(q):return P(U(q)(zp))
    eq=[lift(q) for q in rs]
    eq += [lift(longitude[0,0])-l,lift(longitude[1,0]),l*lift(longitude[1,1])-1]
    eq += [1-s*l*lift(irr)]
    basis=P.ideal(eq).groebner_basis()
    eliminated=[q for q in basis if q and q.degree(s)==0 and q.degree(zp)==0]
    assert eliminated
    V=PolynomialRing(K,'l');v=V.gen()
    polys=[V({e[2]:c for e,c in q.dict().items()}) for q in eliminated]
    result=polys[0]
    for q in polys[1:]:result=result.gcd(q)
    result=result.squarefree_part().monic()
    target=V(g.source_polynomial(n)(v,m)).monic()
    assert result==target,(n,result,target)
    return {'n':n,'relation_Z_degree':int(r.degree()),'elimination_L_degree':int(result.degree()),'groebner_size':len(basis),'equal':True,'no_vertical_curve_check':True}

def main():
    start=time.time();rec=recurrence();results=[];records=[]
    for n in (1,-1,2,-2,3,-3,4,-4):
        t=time.time();assert g.source_polynomial(n)==rec[n]
        result=literal_elimination(n);result['seconds']=time.time()-t
        results.append(result);emit('CHECKPOINT',result)
    L,M=g.L,g.M
    assert rec[1]==L+M**6
    assert rec[-1]==M**4*L**2+(-M**8+M**6+2*M**4+M**2-1)*L+M**4
    # CCGLS, printed pp.73-74: row i, column j is M^(2i)*L^j.
    # Appendix matrices give A' (the L-1 factor omitted), as on p.72.
    ccgls_trefoil=[[0,1],[0,0],[0,0],[1,0]]
    ccgls_figure8=[[0,1,0],[0,-1,0],[-1,-2,-1],[0,-1,0],[0,1,0]]
    def from_matrix(rows):return sum(c*M**(2*i)*L**j for i,row in enumerate(rows) for j,c in enumerate(row))
    assert g.normalize(from_matrix(ccgls_trefoil))==rec[1]
    assert g.normalize(from_matrix(ccgls_figure8))==rec[-1]
    assert g.normalize(L-1)==L-1 # unknot control, not a stored row
    controls=[]
    for params in g.APolynomials().enumerate():
        n=g.knot_index(params['knot']);p=g.APolynomials().value(params,100)
        expected=rec[n]
        if params['hand']=='mirror':expected=g.mirrored(expected)
        if params['form']=='with-abelian':expected=g.normalize((L-1)*expected)
        assert p==expected
        assert all(type(c).__name__=='Integer' for c in p.coefficients())
        assert p==g.normalize(p) and p.gcd(p.derivative(L)).gcd(p.derivative(M))==1
        assert g.mirrored(g.mirrored(p))==p
        abelian_order=0;q=p
        while q% (L-1)==0:abelian_order+=1;q=q//(L-1)
        assert abelian_order==(1 if params['form']=='with-abelian' else 0)
        records.append({'params':params,'number':str(p),'L_degree':int(p.degree(L)),'M_degree':int(p.degree(M)),'terms':len(p.dict())})
    for n,p in rec.items():
        if not n:continue
        assert (p==g.mirrored(p))==(n==-1)
    p=rec[-1]
    controls=[p+1,p(L,M**2),p(M,L)]
    assert all(q!=p for q in controls)
    assert g.normalize((L-1)*p)!=p
    assert g.normalize((L-1)**2*p)!=g.normalize((L-1)*p)
    # Specifically catch the uncorrected 2014 theorem at n=-1, M=2, L=3.
    uncorrected=196+273-234;correct=int(p(3,2));assert uncorrected==235 and correct==-311
    emit('RESULT',{'checked_entries':len(records),'total_entries':30,'failures':[],
       'known_answer_control':True,'negative_control_rejected':True,
       'controls':{'changed_coefficient':True,'M_squared':True,'swapped_peripheral_variables':True,'missing_abelian':True,'doubled_abelian':True,'uncorrected_negative_sum_rejected':True},
       'matrix_eliminations':results,'records':records,'seconds':time.time()-start})

if __name__=='__main__':main()