generate.py

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

5371 bytes, as of the version from 2026-11-25 23:04 (current). Recorded here, not run.

"""T802: Longitudinal adjoint Reidemeister torsions of hyperbolic twist knots.

Dependencies: SageMath (tested 10.9), numberdb, selection.json alongside this file.
sage -pip install numberdb
sage -python generate.py --offline   # exact model and all enclosures, no network
sage -python generate.py             # verify all stored entries, no writes
sage -python generate.py --publish   # authenticated additive entry submission

This evaluates DHY Theorem 19 in the exact Riley field and uses the preferred
zero-linking longitude. DHY equation (12) fixes the geometric Riley embedding.
The result is a sign class; its
representative has positive real part, or positive imaginary part if exactly
pure imaginary. No modulus is taken. Exact figure-eight value 3 is returned as a Sage integer.
The embedding indices in selection.json were identified from certified
complete holonomy of the frozen KnotInfo braids; see embedding-proof.md and
geometry-evidence.json. They are not selected by an imaginary-part heuristic.

The default finite selection is all seven hyperbolic twist knots through ten
crossings and six distinct chiral mirrors. The cutoff is practical, not a
mathematical domain restriction. Every algebraic result is evaluated in Arb
at max(768, bits(digits)+128) bits, with finite widths checked before return.
See argument-selection.md, build-checks.json and the archived skill manifest.
There is no offer or publication action in this generator.
"""
import numberdb.sage as numberdb
import json, argparse, os, sys
from functools import lru_cache
from fractions import Fraction
from pathlib import Path
from sage.rings.rational_field import QQ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.number_field.number_field import NumberField
from sage.rings.qqbar import QQbar
from sage.rings.complex_arb import ComplexBallField
from sage.rings.real_mpfi import RealIntervalField
import sage.rings.polynomial.laurent_polynomial_ring
from sage.matrix.constructor import matrix, identity_matrix
P=PolynomialRing(QQ,'u');u=P.gen()
def T(n):
    if n<0:return -T(-n)
    a,b=P(0),P(1)
    for i in range(n):a,b=b,(u*u+2)*b-a
    return a

def E(n):
    a,b=P(2),u*u+2
    for i in range(n):a,b=b,(u*u+2)*b-a
    return a

def poly(m):return ((1-u)*T(m)-T(m-1)).monic()

def exact_model(m):
    p=poly(m);F=NumberField(p,'a');a=F.gen();one=identity_matrix(F,2)
    X=matrix(F,[[1,1],[0,1]]);Y=matrix(F,[[1,0],[-a,1]])
    W=Y*X**-1*Y**-1*X; V=X*Y**-1*X**-1*Y
    assert W**m*X==Y*W**m
    L=V**m*W**m
    assert L[0,0]==-1 and L[1,1]==-1 and L[1,0]==0
    c=2+4/a;assert -L[0,1]==c
    n=abs(m);t=F(T(n)); e=F(E(n)); eprev=F(E(n-1 if m>0 else n+1))
    num=((4 if m>0 else -4)+n*(a*a-4*a+8))*t*e+(t*eprev+(-1 if m>0 else 1))*(a*a-4)*n+(-5*a*a-8*a+4)*t*t
    lam=num/(a*a+4)
    return p,F,a,c,lam,lam/c


@lru_cache(None)
def selection():
    return json.loads(Path(__file__).with_name('selection.json').read_text())

@lru_cache(None)
def exact_value(n,k,knot):
    row=next(r for r in selection() if r['name']==f'{n}_{k}' and r['knot']==knot)
    p,F,a,c,lam,tau=exact_model(row['m'])
    roots=p.roots(QQbar)
    assert all(mult==1 for root,mult in roots)
    root=roots[row['root_index']][0]
    value=F.hom([root],QQbar)(lam)
    if value.real()<0 or (value.real()==0 and value.imag()<0):value=-value
    assert value.real()>0 or (value.real()==0 and value.imag()>0)
    if row['m']==-1:
        assert value==3
    return value

def wire_interval(part):
    interval=RealIntervalField(part.parent().precision())(part)
    return numberdb.RealInterval(Fraction(str(interval.lower().exact_rational())),
                                 Fraction(str(interval.upper().exact_rational())))

class TwistTorsion(numberdb.Generator):
    table='T802'
    parameters=('n','k','knot')
    type='C'
    digits=100
    rigour='proven'
    files=('generate.py','selection.json')

    def enumerate(self):
        for row in selection():
            n,k=map(int,row['name'].split('_'))
            yield {'n':n,'k':k,'knot':row['knot']}

    def value(self,params,digits):
        exact=exact_value(int(params['n']),int(params['k']),str(params['knot']))
        if exact == 3:
            from sage.rings.integer_ring import ZZ
            return ZZ(3)
        C=ComplexBallField(max(768,numberdb.bits(digits,losing=128)))
        value=C(exact)
        assert value.real().is_finite() and value.imag().is_finite()
        bound=QQ(1)/10**(digits+20)
        assert value.real().rad()<bound and value.imag().rad()<bound
        if exact.real()==0:
            return numberdb.ComplexInterval(Fraction(0),wire_interval(value.imag()))
        if exact.imag()==0:
            return numberdb.ComplexInterval(wire_interval(value.real()),Fraction(0))
        return value

if __name__=='__main__':
    parser=argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--offline',action='store_true')
    parser.add_argument('--publish',action='store_true')
    args=parser.parse_args()
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1':
        numberdb.configure(api_key=sys.stdin.read().strip())
    g=TwistTorsion()
    if args.offline:
        for params in g.enumerate():print(params,numberdb.to_text(g.value(params,100),digits=100))
    elif args.publish:g.publish(removing=False)
    else:print(g.verify(sample=None))