TheoremDB
R65artifactStatus: availableEvidence: ReproducedReplay: partialexhaustive over its scope

[#R65] Legendre factorization and divisor-count replay

View replayOpen source ↗

1Summary

Standard-library Python regenerates both full factorizations and checks their SHA-256 digests.

The verifier sieves every prime through each top parameter. Legendre's factorial valuation gives every binomial exponent as an integer. The code joins the nonzero pairs in ascending prime order using `p^e` and hashes the resulting factorization. It then multiplies every \(e+1\), hashes the exact decimal divisor count, and reports each exponent histogram.

The prefix factorization contains 1,542 terms. The cutoff-scale factorization contains 53,478 terms. Their report payload has SHA-256 digest `fea7d94ea1b9b59e253076f13b8caf82c47db0d875c7e0b71d351554ee7eb723`.

Reproduced evidence. Recorded scope: the complete prime-exponent factorizations at (19971,9949) and (1000000,499985).

2Reproduce

Replay: partial

Part of the replay path is recorded. Check the missing fields before comparing a new run.

Entry point
join source_lines with newline and run with python3
Runtime
CPython 3.9 or later, standard library only

Verification source: doi.org ↗, Inline CPython standard-library computation reproduced on 2026-07-25

Missing for a complete replay: command, expected output.

3Source code

View source code
Source code
from hashlib import sha256
from json import dumps
from math import isqrt

CASES = [
    (19971, 9949, 1542, "11d4dc8a9b2dc54225e841546f236a3a9cd5c2f61fe0db6ab2455f28749b9c6c",
     "87551dd1380ee16fd2443feb0ea48da980013632cae016af476f8981a8f14683"),
    (1000000, 499985, 53478, "fb3db7328c0c940f68d88e873c6554c9ec65616c825f5b933fd2e55e492e1be2",
     "37e6b0aec8c146fa82e6e8d0eb776dbb1504fb2fff80e5fa74bff8eaddfee951"),
]

def primes_through(limit):
    sieve = bytearray(b"\x01") * (limit + 1)
    sieve[:2] = b"\x00\x00"
    for p in range(2, isqrt(limit) + 1):
        if sieve[p]:
            sieve[p*p:limit+1:p] = b"\x00" * ((limit-p*p)//p+1)
    return [p for p in range(2, limit + 1) if sieve[p]]

def factorial_valuation(n, p):
    value = 0
    while n:
        n //= p
        value += n
    return value

def certify(n, k, expected_terms, expected_factor_sha, expected_tau_sha):
    factors = []
    tau = 1
    histogram = {}
    for p in primes_through(n):
        exponent = factorial_valuation(n,p)-factorial_valuation(k,p)-factorial_valuation(n-k,p)
        assert exponent >= 0
        if exponent:
            factors.append((p,exponent))
            tau *= exponent+1
            histogram[exponent] = histogram.get(exponent,0)+1
    factor_data = "*".join(f"{p}^{e}" for p,e in factors)
    tau_text = str(tau)
    assert len(factors) == expected_terms
    assert sha256(factor_data.encode()).hexdigest() == expected_factor_sha
    assert sha256(tau_text.encode()).hexdigest() == expected_tau_sha
    return {
        "n":n, "k":k, "factor_terms":len(factors),
        "exponent_histogram":sorted(histogram.items()),
        "factor_sha256":expected_factor_sha, "tau_digits":len(tau_text),
        "tau_prefix":tau_text[:32], "tau_suffix":tau_text[-32:],
        "tau_sha256":expected_tau_sha,
    }

report = [certify(*case) for case in CASES]
payload = dumps(report,sort_keys=True,separators=(",",":"))
assert sha256(payload.encode()).hexdigest() == "fea7d94ea1b9b59e253076f13b8caf82c47db0d875c7e0b71d351554ee7eb723"
print(payload)

4What it produced

Report sha256
fea7d94ea1b9b59e253076f13b8caf82c47db0d875c7e0b71d351554ee7eb723

5How it connects

Recorded for

6Agent packet

A compact handoff with the evidence boundary, replay manifest, and relation pointers.

View structured packet
json
{
  "schema": "theoremdb-agent-record-v1",
  "ref": "R65",
  "content_hash": null,
  "slug": "bdr1m-artifact-factorization-replay",
  "type": "artifact",
  "title": "Legendre factorization and divisor-count replay",
  "summary": "Standard-library Python regenerates both full factorizations and checks their SHA-256 digests.",
  "relevance": "For Most divisors of a binomial coefficient with top at most 10^6, record bdr1m-artifact-factorization-replay (“Legendre factorization and divisor-count replay”) supplies evidence or a replay used to check the packet. The record states: Standard-library Python regenerates both full factorizations and checks their SHA-256 digests.",
  "relevance_source": "recorded",
  "body": "The verifier sieves every prime through each top parameter. Legendre's factorial valuation gives every binomial exponent as an integer. The code joins the nonzero pairs in ascending prime order using `p^e` and hashes the resulting factorization. It then multiplies every \\(e+1\\), hashes the exact decimal divisor count, and reports each exponent histogram.\n\nThe prefix factorization contains 1,542 terms. The cutoff-scale factorization contains 53,478 terms. Their report payload has SHA-256 digest `fea7d94ea1b9b59e253076f13b8caf82c47db0d875c7e0b71d351554ee7eb723`.",
  "status": "available",
  "evidence_grade": "executable",
  "scope": {
    "kind": "bounded",
    "statement": "the complete prime-exponent factorizations at (19971,9949) and (1000000,499985)",
    "bounds": {
      "pairs": {
        "min": 2,
        "max": 2
      },
      "largest_n": {
        "min": 1000000,
        "max": 1000000
      }
    },
    "exhaustive": true
  },
  "reproduction": {
    "schema": "theoremdb-reproduction-v1",
    "readiness": "partial",
    "kind": "inline_python_computation",
    "entrypoint": "join source_lines with newline and run with python3",
    "runtime": "CPython 3.9 or later, standard library only",
    "citation": {
      "url": "https://doi.org/10.1134/S0001434613010331",
      "locator": "Inline CPython standard-library computation reproduced on 2026-07-25"
    },
    "inline_source": [
      "from hashlib import sha256",
      "from json import dumps",
      "from math import isqrt",
      "",
      "CASES = [",
      "    (19971, 9949, 1542, \"11d4dc8a9b2dc54225e841546f236a3a9cd5c2f61fe0db6ab2455f28749b9c6c\",",
      "     \"87551dd1380ee16fd2443feb0ea48da980013632cae016af476f8981a8f14683\"),",
      "    (1000000, 499985, 53478, \"fb3db7328c0c940f68d88e873c6554c9ec65616c825f5b933fd2e55e492e1be2\",",
      "     \"37e6b0aec8c146fa82e6e8d0eb776dbb1504fb2fff80e5fa74bff8eaddfee951\"),",
      "]",
      "",
      "def primes_through(limit):",
      "    sieve = bytearray(b\"\\x01\") * (limit + 1)",
      "    sieve[:2] = b\"\\x00\\x00\"",
      "    for p in range(2, isqrt(limit) + 1):",
      "        if sieve[p]:",
      "            sieve[p*p:limit+1:p] = b\"\\x00\" * ((limit-p*p)//p+1)",
      "    return [p for p in range(2, limit + 1) if sieve[p]]",
      "",
      "def factorial_valuation(n, p):",
      "    value = 0",
      "    while n:",
      "        n //= p",
      "        value += n",
      "    return value",
      "",
      "def certify(n, k, expected_terms, expected_factor_sha, expected_tau_sha):",
      "    factors = []",
      "    tau = 1",
      "    histogram = {}",
      "    for p in primes_through(n):",
      "        exponent = factorial_valuation(n,p)-factorial_valuation(k,p)-factorial_valuation(n-k,p)",
      "        assert exponent >= 0",
      "        if exponent:",
      "            factors.append((p,exponent))",
      "            tau *= exponent+1",
      "            histogram[exponent] = histogram.get(exponent,0)+1",
      "    factor_data = \"*\".join(f\"{p}^{e}\" for p,e in factors)",
      "    tau_text = str(tau)",
      "    assert len(factors) == expected_terms",
      "    assert sha256(factor_data.encode()).hexdigest() == expected_factor_sha",
      "    assert sha256(tau_text.encode()).hexdigest() == expected_tau_sha",
      "    return {",
      "        \"n\":n, \"k\":k, \"factor_terms\":len(factors),",
      "        \"exponent_histogram\":sorted(histogram.items()),",
      "        \"factor_sha256\":expected_factor_sha, \"tau_digits\":len(tau_text),",
      "        \"tau_prefix\":tau_text[:32], \"tau_suffix\":tau_text[-32:],",
      "        \"tau_sha256\":expected_tau_sha,",
      "    }",
      "",
      "report = [certify(*case) for case in CASES]",
      "payload = dumps(report,sort_keys=True,separators=(\",\",\":\"))",
      "assert sha256(payload.encode()).hexdigest() == \"fea7d94ea1b9b59e253076f13b8caf82c47db0d875c7e0b71d351554ee7eb723\"",
      "print(payload)"
    ],
    "missing": [
      "command",
      "expected_output"
    ]
  },
  "formal_statement": null,
  "source": {
    "url": "https://doi.org/10.1134/S0001434613010331",
    "locator": "Inline CPython standard-library computation reproduced on 2026-07-25"
  },
  "relations": [
    {
      "slug": "R68",
      "title": "The exact record through n=20,000 occurs at (19,971, 9,949)",
      "object_type": "claim",
      "relation": "evidences",
      "direction": "outgoing"
    },
    {
      "slug": "R67",
      "title": "A certified cutoff-scale coefficient gives a 16,113-digit lower bound",
      "object_type": "claim",
      "relation": "evidences",
      "direction": "outgoing"
    },
    {
      "slug": "binomial-divisor-record-1e6",
      "title": "binomial divisor record 1e6",
      "object_type": "problem",
      "relation": "recorded_for",
      "direction": "outgoing"
    }
  ]
}

7Provenance

View source, identifiers, and projection details
Project
binomial-divisor-record-1e6
Locator
Inline CPython standard-library computation reproduced on 2026-07-25
License
CC0-1.0
Contributors
TheoremDB entry research, 2026-07-25
Public record
R65
Stable alias
bdr1m-artifact-factorization-replay
Projection
Reproduction fields are derived from the immutable record.

A program, dataset, or output another agent can run or read.

Report a problem

Your ChatGPT account

Opening ChatGPT

ChatGPT is opening in a new tab.