back to table · edit · history · where entries came from · files · download
15064 bytes, as of the version from 2026-09-27 17:26 (current). Recorded here, not run.
"""Assemble a candidate and hash-bound evidence, entirely offline.
Place this file, channel_check.py, and generate.py beside baseline.json, then:
sage -python channel_prepare.py --probe
sage -python channel_prepare.py --prepare
Repository normalization tools must be on PYTHONPATH. Every run
has a 120-second numerical budget; a timeout is not permission to escalate
the shared AWS compute slot. No credentials or website clients are used.
"""
import argparse
import copy
import hashlib
import json
import signal
import time
from collections import Counter
from datetime import datetime, timezone
from pathlib import Path
try:
import generate as generator
except ModuleNotFoundError:
import channel_generate as generator
from channel_check import (
SOURCE_URL, certify_written, exact_endpoints, matrix_certificate, transition_matrix,
)
from numberdb._compare import EXACT, digits_of
from numberdb._generate import _stored_entries
from sage.rings.rational_field import QQ
from sage.rings.real_mpfi import RealIntervalField
LIMITATIONS = (
'Candidate only: no website writes, attachment uploads, leases, review requests or publication. '
'Human review of selection and prose, an artifact-bound technical critique, and a fresh live '
'baseline guard remain required before application. Coverage is a curated 26-channel selection, '
'not all rational probabilities; no binary-erasure family or decimal grid is added. '
'Certificates cover every selected row, not every possible extension of value(). '
'Both rigorous computations depend on the installed Sage/Arb and MPFI libraries; '
'this is not a formal proof-assistant verification. No Blahut-Arimoto run is claimed. '
'The historical shared-file collision is reconstructed from timestamped session events; '
'the live revision/attachment inventory was supplied by the coordinator.'
)
def timeout_handler(signum, frame):
raise TimeoutError('120-second numerical budget exceeded; coordinate before a heavier run')
def controls():
field = RealIntervalField(525)
cases = [
('noiseless binary', [[1, 0], [0, 1]], field(2).log()),
('identical rows with absent output', [[1, 0], [1, 0]], field(0)),
('binary erasure half', [[QQ(1) / 2, 0, QQ(1) / 2],
[0, QQ(1) / 2, QQ(1) / 2]], field(2).log() / 2),
('Z half', [[1, 0], [QQ(1) / 2, QQ(1) / 2]], field(QQ(5) / 4).log()),
]
result = []
for name, matrix, expected in cases:
certificate, metadata = matrix_certificate(matrix)
lower, upper = exact_endpoints(certificate)
expected_lower, expected_upper = exact_endpoints(expected)
if (upper < expected_lower or expected_upper < lower
or upper - lower >= QQ(1) / 10**110):
raise AssertionError('Independent control failed: ' + name)
result.append({'control': name, 'passed': True, **metadata})
return result
def corrected_document(baseline, records):
if _stored_entries(baseline) or tuple(baseline['Parameters']) != generator.PARAMETERS:
raise ValueError('Expected the empty T342 baseline in its original parameter order')
candidate = copy.deepcopy(baseline)
candidate['Numbers'] = records
candidate['Comments']['omitted-erasure'] = (
'The binary erasure channel has capacity $1-\\epsilon$ bits. It is recorded '
'by Formula CITE{formula-erasure}, not as a fifth channel family. '
'Noiseless and input-independent capacities are used as exact validation '
'controls rather than repeated as table entries.')
candidate['Comments']['boundary-conventions'] = (
'Probabilities lie in $[0,1]$, and the alphabet size $q$ of the symmetric '
'channel is an integer at least $2$. Terms $0\\log 0$ are interpreted as '
'$0$. The Z-channel has capacity $1$ bit at $p=0$ and $0$ at $p=1$. '
'A $q$-ary symmetric channel has capacity $0$ at $p=(q-1)/q$; at '
'$p=1$ its capacity is $\\log_2(q/(q-1))$, which is not zero.')
candidate['Comments']['exact-ternary-capacity'] = (
'For $\\operatorname{QSC}(3,1/3)$, each conditional output distribution '
'is a permutation of $(2/3,1/6,1/6)$ and has entropy '
'$\\log_2 3-1/3$. Its capacity is therefore exactly $1/3$ bit '
'or $(\\log 2)/3$ nats.')
candidate['Formulas']['formula-bac'] = candidate['Formulas']['formula-bac'].replace(
'the two input rows are equal after relabelling', 'the two input rows are equal')
for key in ('Request43', 'Request54', 'Request55', 'Request56'):
candidate['Links'].pop(key, None)
program = candidate['Programs']['program-sage']
program['code'] = '\n'.join(
line.replace('QQ(1) / QQ(10)', 'QQ(1) / QQ(4)')
for line in program['code'].splitlines() if not line.lstrip().startswith('#'))
properties = candidate['Data properties']
properties['rigour'] = 'proven'
properties['complete'] = 'no'
properties['complete-note'] = (
'it holds both logarithmic units for BSC probabilities $1/4,1/3$ '
'and Z-channel probabilities $1/4,1/3,1/2,2/3,3/4$. Halves, thirds and '
'quarters are a small selection of simple binary randomizations; the '
'Z-channel keeps the complementary probabilities because its direction '
'makes their capacities different. For each $q\\in\\{3,4,8,16\\}$, it holds '
'QSC probabilities $1/4,1/3,1/2,1$, adding the informative never-correct '
'limit; $3$ is the smallest nonbinary alphabet and '
'$4,8,16$ encode two, three and four bits per symbol. BAC pairs are '
'$(1/4,1/3),(1/4,1/2),(1/3,1/2)$, unequal mixtures of the same simple '
'binary randomizations. Noiseless and input-independent channels are '
'controls only. These are selected reference points, not a decimal '
'grid or an exhaustive range')
properties['rigour details'] = (
'Approximate entries have 100 significant decimal digits, enclosed by '
'Sage Arb real-ball evaluation of the closed forms with 128 guard bits. '
'The exact $1/3$-bit QSC entry is proved independently from row '
'permutations, equal column sums and rational prime-log coefficients. '
'Zero capacities and noiseless integer bit capacities are identified '
'algebraically for the controls, not inferred from rounded digits. '
'Every written entry is independently '
'checked from its exact rational transition matrix using MPFI interval '
'arithmetic: achievable mutual information gives a lower bound and the '
'maximum row divergence from the induced output law gives an upper bound. '
'Binary input weights are selected by sign-certified rational bisection; '
'the symmetric channels use a uniform input, accepted only when the two '
'bounds agree to the required precision. Each approximate written '
'interval contains the entire independent capacity enclosure; all '
'MPFR endpoints are preserved by exact rational conversion. The '
'matrix checker first passes noiseless, input-independent, binary-erasure '
'and Z-channel controls. Run measurements and hashes accompany the generator.')
return candidate
def relative_accuracy_bits(value):
enclosure = RealIntervalField(value.parent().precision())(value)
lower, upper = exact_endpoints(enclosure)
if lower <= 0 or upper <= lower:
raise AssertionError('Accuracy measurement requires a positive nonexact enclosure')
relative_width = (upper - lower) / lower
return (relative_width.denominator().nbits()
- relative_width.numerator().nbits() - 1)
def prepare(directory):
from agents.precision_queue import digest, normalize
started = time.monotonic()
control_results = controls()
baseline = json.loads((directory / 'baseline.json').read_text())
records = generator.records()
candidate = corrected_document(baseline, records)
certificates = {}
checked = []
minimum_accuracy_bits = None
numeric_generator = generator.ChannelCapacities()
for record in records:
params, written = record['params'], record['number']
shape_key = params['channel'], params['shape']
matrix = transition_matrix(*shape_key)
if shape_key not in certificates:
certificates[shape_key] = matrix_certificate(matrix)
certificate, metadata = certificates[shape_key]
evidence = certify_written(matrix, params['unit'], written, certificate)
computed = numeric_generator.value(params, 100)
if digits_of(written) != EXACT:
if digits_of(written) != 100:
raise AssertionError('Expected exactly 100 significant digits')
accuracy = int(relative_accuracy_bits(computed))
minimum_accuracy_bits = (accuracy if minimum_accuracy_bits is None
else min(minimum_accuracy_bits, accuracy))
checked.append({'params': params, **evidence, **metadata})
if len(checked) != 52 or len(_stored_entries(candidate)) != 52 or len(certificates) != 26:
raise AssertionError('Coverage or unique-identity count changed')
exact_records = [row for row in records if digits_of(row['number']) == EXACT]
if exact_records != [{'params': {'channel': 'qsc', 'shape': '3,1/3', 'unit': 'bits'},
'number': '1/3'}]:
raise AssertionError('Expected 51 approximate rows and the exact ternary 1/3-bit row')
if (candidate['Definition'] != baseline['Definition']
or candidate['Parameters'] != baseline['Parameters']
or list(candidate['Parameters']) != list(baseline['Parameters'])):
raise AssertionError('Protected definitions or parameter identity changed')
source = directory / 'generate.py'
proof = {
'table': 'T342', 'status': 'candidate_only_requires_independent_review',
'generated_at_utc': datetime.now(timezone.utc).isoformat(),
'generator_sha256': hashlib.sha256(source.read_bytes()).hexdigest(),
'candidate_sha256': digest(normalize(candidate)),
'entries_sha256': digest(_stored_entries(candidate)),
'baseline_sha256': hashlib.sha256((directory / 'baseline.json').read_bytes()).hexdigest(),
'baseline_normalized_sha256': digest(normalize(baseline)),
'all_entries_checked': True,
'entries': len(checked), 'channel_matrices': len(certificates),
'approximate_entries': sum(digits_of(row['number']) != EXACT for row in records),
'exact_entries': sum(digits_of(row['number']) == EXACT for row in records),
'entries_by_channel': dict(Counter(row['params']['channel'] for row in records)),
'minimum_significant_digits': 100,
'minimum_arb_relative_accuracy_bits': minimum_accuracy_bits,
'accuracy_measurement': 'Conservative bit bound using MPFR exact_rational() on outward MPFI endpoints',
'endpoint_conversion': 'exact_rational() preserves dyadic MPFR endpoints; QQ(MPFR) is forbidden',
'endpoint_api_reference': (
'https://doc.sagemath.org/html/en/reference/rings_numerical/'
'sage/rings/real_mpfr.html#sage.rings.real_mpfr.RealNumber.exact_rational'),
'resolved_critique_findings': ['channel-exact-qsc-third', 'channel-endpoints-not-exact'],
'supersedes_rejected_verification_sha256':
'59245e29221bdef888a13a9fa27bd1e3560645c1d8a0d4e634f276ff7450a419',
'rejected_artifact_archive': 'channel-rejected-20260927 (private, not an attachment)',
'guard_bits': generator.WORKING_GUARD,
'working_precision_bits': generator.numberdb.bits(100, losing=generator.WORKING_GUARD),
'matrix_precision_bits': generator.numberdb.bits(100, losing=192),
'matrix_absolute_gap_target_nats': '1e-112',
'independent_checks': [{
'method': 'Rational transition matrices; MPFI primal/dual capacity enclosures',
'source': {'url': SOURCE_URL, 'location': 'Sections 4.4-4.5; Corollaries 4.2-4.3',
'web_verified_on': '2026-09-27'},
'controls': control_results, 'all_rows': checked,
'scope': 'All 52 rows, with additional exact structural matrix controls; not Blahut-Arimoto',
}],
'attachment_sha256': {
name: hashlib.sha256((directory / name).read_bytes()).hexdigest()
for name in ('channel_check.py', 'channel_prepare.py')
},
'environment': numeric_generator.environment(),
'parameter_order_preserved': True, 'definition_preserved': True,
'schema_validation': 'Requires the coordinator full-repository guard; precision snapshot lacks validator',
'changed_sections': ['Numbers', 'Comments', 'Formulas/formula-bac', 'Data properties',
'Links (four issue bookkeeping links removed)', 'Programs/program-sage'],
'historical_cause': {
'mechanism': 'Concurrent overwrite of shared /tmp/create_numberdb_draft.py',
'w2_session': '01a0bb86-04be-7173-8618-69df83052544',
'w4_session': '01a0bb87-f41d-7732-ae45-316a9a539125',
'w2_helper_created': '2026-09-19T21:23:02.741Z',
'w4_helper_overwritten': '2026-09-19T21:23:03.112Z',
'sole_live_revision': '2536, 2026-09-19T21:23:06Z (coordinator-confirmed)',
'result': 'KL worker created channel draft; channel worker stopped on title conflict',
'no_historical_capacity_generator_or_numerical_check_found': True,
},
'limitations': LIMITATIONS,
'numerical_elapsed_seconds': time.monotonic() - started,
}
for name, document in [('candidate.json', candidate), ('verification.json', proof)]:
(directory / name).write_text(json.dumps(document, indent=2, ensure_ascii=False) + '\n')
print(json.dumps({key: proof[key] for key in (
'status', 'entries', 'exact_entries', 'minimum_arb_relative_accuracy_bits',
'numerical_elapsed_seconds', 'candidate_sha256', 'entries_sha256', 'generator_sha256')}, indent=2))
def main():
parser = argparse.ArgumentParser(description=__doc__)
mode = parser.add_mutually_exclusive_group(required=True)
mode.add_argument('--probe', action='store_true')
mode.add_argument('--prepare', action='store_true')
args = parser.parse_args()
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(120)
if args.probe:
started = time.monotonic()
control_results = controls()
for params in list(generator.selected_parameters())[:6]:
value = generator.ChannelCapacities().value(params, 100)
print(params, value)
print(json.dumps({'controls': control_results, 'seconds': time.monotonic() - started}))
else:
prepare(Path(__file__).resolve().parent)
signal.alarm(0)
if __name__ == '__main__':
main()