Read the complete Python source
#!/usr/bin/env python3
"""Small exact and numerical examples accompanying C439–C462.
Run: python3 benchmarks.py
Python 3.9+; only the standard library is used. All inputs below are illustrative.
These calculations reproduce conditional model statements, not measured constants.
"""
import json
import math
from fractions import Fraction
def retained_records(continuation_labels, depth):
if not isinstance(continuation_labels, int) or continuation_labels < 1:
raise ValueError('continuation_labels must be a positive integer')
if not isinstance(depth, int) or depth < 0:
raise ValueError('depth must be a nonnegative integer')
levels = [0]
for d in range(1, depth + 1):
levels.append((2**d - 1) + continuation_labels * levels[-1])
return levels
def refinement(branching, contraction):
if branching <= 1 or not 0 < contraction < 1:
raise ValueError('Require branching > 1 and 0 < contraction < 1')
activity = math.log(branching)
clock = math.log(1 / contraction)
return {'counting_exponent': activity / clock,
'selected_clock_ratio': activity / clock,
'alternative_clock_ratio': activity / (activity + clock)}
def susceptibility(a, b, d):
a, b, d = map(Fraction, (a, b, d))
if d <= 0 or a * d <= b * b:
raise ValueError('The symmetric quadratic form must be positive definite')
return 1 / (a - b * b / d)
def receiver_probabilities(dimension, probability):
p = Fraction(probability)
if not isinstance(dimension, int) or dimension < 2 or not 0 <= p <= 1:
raise ValueError('Require integer dimension >= 2 and 0 <= probability <= 1')
spectrum = [p] + [(1-p)/(dimension-1)] * (dimension-1)
return {'dimension': dimension, 'probe_probability': str(spectrum[0]),
'trace': str(sum(spectrum)), 'nonnegative': all(x >= 0 for x in spectrum)}
def main():
counts10 = retained_records(10, 3)
counts4 = retained_records(4, 3)
geometry = refinement(8, 0.5)
coupled = susceptibility(2, 1, 2)
uncoupled = susceptibility(2, 0, 2)
receivers = [receiver_probabilities(137, p) for p in (Fraction(1,137), Fraction(1,2), Fraction(9,10))]
theta = math.pi / 6
phase = math.pi / 2
transition = math.sin(2 * theta)**2 * math.sin(phase)**2
result = {
'scope': 'Reproducible toy calculations with explicitly chosen inputs; no empirical fit or new physical constant is asserted.',
'retention_grammar': {'depth':3, 'q10':counts10, 'q4':counts4},
'geometry_and_clocks': {'branching':8, 'contraction':0.5, **geometry},
'static_response': {'coupled_matrix':[[2,1],[1,2]], 'coupled_susceptibility':str(coupled), 'uncoupled_matrix':[[2,0],[0,2]], 'uncoupled_susceptibility':str(uncoupled)},
'same_dimension_different_preparations': receivers,
'two_flavour_phase_example': {'mixing_angle_radians':theta, 'oscillation_phase_radians':phase, 'transition_probability':transition, 'survival_probability':1-transition},
'checks': {
'grammar_counts': counts10 == [0,1,13,137] and counts4 == [0,1,7,35],
'clock_ratios': math.isclose(geometry['counting_exponent'],3) and math.isclose(geometry['alternative_clock_ratio'],0.75),
'response_values': coupled == Fraction(2,3) and uncoupled == Fraction(1,2),
'normalized_receiver_states': all(r['trace']=='1' and r['nonnegative'] for r in receivers),
'oscillation_probability': math.isclose(transition,0.75) and 0 <= transition <= 1,
}
}
print(json.dumps(result,ensure_ascii=False,indent=2))
if not all(result['checks'].values()): raise SystemExit('A benchmark check failed')
if __name__ == '__main__': main()