generate.py

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

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

"""T824: congruent hyperball packing densities in regular truncated cells.

Install numberdb in SageMath: sage -pip install numberdb. Then run
  sage -python generate.py             # preview the 74 default arguments
  sage -python generate.py --verify    # reproduce all stored entries
  sage -python generate.py --publish   # fill the authorized private draft
NUMBERDB_API_KEY supplies private-draft access. --publish writes entries;
it does not publish the draft or offer it for review. Set session provenance
in the calling environment, never in this reusable generator.

Curvature -1; ordered chamber [p,q,r] with A3 polar-truncated. The quantity
is occupied volume divided by cell volume for the equal-height inward
half-hyperballs, h = half the least polar-plane distance. There is no
optimization over noncongruent or arbitrary packings. Szirmai 1405.0248v2
Theorem 4.2/section 5, 1803.04948v1 Theorem 2.2/sections 3.1,3.3, and
1510.03208v1 equation (2.4) supply the formulas.

Arb encloses all inputs and operations: inverse Gram matrix for h,
Kellerhals' dilogarithm formula for chamber volume v, and Bolyai's
piece-volume ratio. At 100 digits use 512 bits; extensions use at least
digits converted to bits plus 176 guard bits. certification.json records
measured accuracy and containment in the actual stored decimal interval.
"""
import argparse
import os
import sys
import numberdb.sage as numberdb
import sage.rings.polynomial.laurent_polynomial_ring
from sage.matrix.constructor import matrix
from sage.rings.real_arb import RealBallField
from sage.rings.complex_arb import ComplexBallField

FAMILIES = {'tetrahedron': (3, 3, 7), 'cube': (3, 4, 7),
            'octahedron': (4, 3, 5)}


def packing_components(cell, p, digits=100):
    q, r, first = FAMILIES[cell]
    if str(p).strip() != str(int(p)) or int(p) < first:
        raise ValueError('p must be an integer in the natural tiling domain')
    p = int(p)
    precision = max(512, numberdb.bits(digits, losing=176))
    R, C = RealBallField(precision), ComplexBallField(precision)
    pi = R.pi()
    a, b, g = pi/p, pi/q, pi/r
    ca, cb, cg = a.cos(), b.cos(), g.cos()
    G = matrix(R, [[1, -ca, 0, 0], [-ca, 1, -cb, 0],
                   [0, -cb, 1, -cg], [0, 0, -cg, 1]])
    H = G.inverse()
    assert H[2, 2] < 0 and H[3, 3] > 0
    u = 1-H[2, 3]**2/(H[2, 2]*H[3, 3])
    assert u > 1
    h = u.sqrt().arccosh()
    radicand = cb**2-a.sin()**2*g.sin()**2
    assert radicand > 0 and ca*cg > 0
    theta = (radicand.sqrt()/(ca*cg)).arctan()
    assert 0 < theta < pi/2

    def lob(x):
        return (C(0, 2)*C(x)).exp().polylog(2).imag()/2

    v = (lob(a+theta)-lob(a-theta)+lob(pi/2+b-theta)
         +lob(pi/2-b-theta)+lob(g+theta)-lob(g-theta)
         +2*lob(pi/2-theta))/4
    base_chamber_area = pi/2-a-b
    assert h > 0 and v > 0 and base_chamber_area > 0
    density = base_chamber_area*((2*h).sinh()+2*h)/(4*v)
    for x in (h, v, density):
        assert x.is_finite() and x.accuracy() > numberdb.bits(digits)
    assert 0 < density < 1
    return density, h, v


class HyperballDensities(numberdb.Generator):
    table = 'T824'
    parameters = ('cell', 'p')
    type = 'R'
    digits = 100
    rigour = 'proven'

    def enumerate(self, limit=30):
        for cell, (_, _, first) in FAMILIES.items():
            for p in range(first, int(limit)+1):
                yield {'cell': cell, 'p': p}

    def value(self, params, digits):
        return packing_components(str(params['cell']), params['p'], digits)[0]


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--publish', action='store_true')
    parser.add_argument('--verify', action='store_true')
    args = parser.parse_args()
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
        os.environ['NUMBERDB_API_KEY'] = sys.stdin.read().strip()
    generator = HyperballDensities()
    if args.publish or os.environ.get('NUMBERDB_PUBLISH') == '1':
        print(generator.publish())
    elif args.verify:
        print(generator.verify(sample=None))
    else:
        print(generator.preview())