|
| 1 | +"""Certify a useful binary64 REMESH class at ``alpha=1/2``. |
| 2 | +
|
| 3 | +On a two-node antisymmetric history ``(a, -a)``, binary64 division by two, |
| 4 | +addition, and a symmetric hard clamp preserve oddness. The class is therefore |
| 5 | +REMESH-forward-invariant and has the sharp uniform relative-defect bound |
| 6 | +``eta=135/124`` once the represented radius contains ``4*2**-1074``. |
| 7 | +
|
| 8 | +Composing this bound with a schedule disagreement gain ``q`` gives |
| 9 | +``q_eff=q*(1+eta)``. The example uses ``q=4/9``, for which |
| 10 | +``q_eff=259/279<1`` and the normalized block margin is ``20/279``. It also |
| 11 | +shows the zero-margin boundary and two excluded generalizations: arbitrary |
| 12 | +metric-centered rows and an unrestricted fixed lattice. |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +from fractions import Fraction |
| 18 | +import json |
| 19 | +import math |
| 20 | +from typing import Any |
| 21 | + |
| 22 | +from tnfr.physics import ( |
| 23 | + certify_half_alpha_antisymmetric_hard_clip_remesh_class, |
| 24 | + observe_binary64_remesh_pair_relative_defect, |
| 25 | +) |
| 26 | + |
| 27 | + |
| 28 | +def _weighted_center(pair: tuple[float, float]) -> Fraction: |
| 29 | + left, right = (Fraction.from_float(value) for value in pair) |
| 30 | + return (left + 3 * right) / 4 |
| 31 | + |
| 32 | + |
| 33 | +def _fraction_text(value: Fraction) -> str: |
| 34 | + return f"{value.numerator}/{value.denominator}" |
| 35 | + |
| 36 | + |
| 37 | +def run_protocol() -> dict[str, Any]: |
| 38 | + """Build the class, its schedule compositions, and scope falsifiers.""" |
| 39 | + |
| 40 | + certificate = certify_half_alpha_antisymmetric_hard_clip_remesh_class( |
| 41 | + ("left", "right"), |
| 42 | + (1.0, 3.0), |
| 43 | + tau_local=2, |
| 44 | + tau_global=3, |
| 45 | + epi_bound=1.0, |
| 46 | + ) |
| 47 | + strict_policy = certificate.certify_schedule_relative_defect_stability( |
| 48 | + Fraction(4, 9) |
| 49 | + ) |
| 50 | + boundary_policy = certificate.certify_schedule_relative_defect_stability( |
| 51 | + Fraction(124, 259) |
| 52 | + ) |
| 53 | + |
| 54 | + smallest = math.ulp(0.0) |
| 55 | + sharpness_witness = observe_binary64_remesh_pair_relative_defect( |
| 56 | + (-3 * smallest, 3 * smallest), |
| 57 | + (-2 * smallest, 2 * smallest), |
| 58 | + (-3 * smallest, 3 * smallest), |
| 59 | + alpha=0.5, |
| 60 | + epi_min=-4 * smallest, |
| 61 | + epi_max=4 * smallest, |
| 62 | + clip_mode="hard", |
| 63 | + ) |
| 64 | + |
| 65 | + amplitudes = ( |
| 66 | + float.fromhex("0x1.37b40d1c51f86p-29"), |
| 67 | + float.fromhex("0x1.2be8875fa6dd8p-29"), |
| 68 | + float.fromhex("-0x1.0994982458cc8p-28"), |
| 69 | + ) |
| 70 | + centered_inputs = tuple((3 * value, -value) for value in amplitudes) |
| 71 | + centered_falsifier = observe_binary64_remesh_pair_relative_defect( |
| 72 | + *centered_inputs, |
| 73 | + alpha=0.5, |
| 74 | + epi_min=-1.0, |
| 75 | + epi_max=1.0, |
| 76 | + clip_mode="hard", |
| 77 | + ) |
| 78 | + lattice_falsifier = observe_binary64_remesh_pair_relative_defect( |
| 79 | + (1.0, -1.0), |
| 80 | + (0.0, -0.0), |
| 81 | + (0.0, -0.0), |
| 82 | + alpha=0.5, |
| 83 | + epi_min=-1.0, |
| 84 | + epi_max=1.0, |
| 85 | + clip_mode="hard", |
| 86 | + ) |
| 87 | + return { |
| 88 | + "certificate": certificate, |
| 89 | + "strict_policy": strict_policy, |
| 90 | + "boundary_policy": boundary_policy, |
| 91 | + "sharpness_witness": sharpness_witness, |
| 92 | + "centered_inputs": centered_inputs, |
| 93 | + "centered_falsifier": centered_falsifier, |
| 94 | + "lattice_falsifier": lattice_falsifier, |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | +def build_report(protocol: dict[str, Any]) -> dict[str, Any]: |
| 99 | + """Return the exact class result and its explicit boundaries.""" |
| 100 | + |
| 101 | + certificate = protocol["certificate"] |
| 102 | + strict = protocol["strict_policy"] |
| 103 | + boundary = protocol["boundary_policy"] |
| 104 | + sharp = protocol["sharpness_witness"] |
| 105 | + centered_inputs = protocol["centered_inputs"] |
| 106 | + centered = protocol["centered_falsifier"] |
| 107 | + lattice = protocol["lattice_falsifier"] |
| 108 | + return { |
| 109 | + "claim": ( |
| 110 | + "the alpha=1/2 antisymmetric P2 hard-clip REMESH class has a " |
| 111 | + "sharp uniform binary64 relative-defect bound" |
| 112 | + ), |
| 113 | + "class": { |
| 114 | + "certificate_valid": ( |
| 115 | + certificate |
| 116 | + .half_alpha_antisymmetric_hard_clip_class_certificate_certified |
| 117 | + ), |
| 118 | + "alpha": _fraction_text(certificate.alpha), |
| 119 | + "interval": [ |
| 120 | + _fraction_text(certificate.epi_min), |
| 121 | + _fraction_text(certificate.epi_max), |
| 122 | + ], |
| 123 | + "metric": [ |
| 124 | + _fraction_text(value) |
| 125 | + for value in certificate.exact_normalized_metric |
| 126 | + ], |
| 127 | + "uniform_eta": _fraction_text( |
| 128 | + certificate.exact_uniform_relative_defect_upper_bound |
| 129 | + ), |
| 130 | + "strict_q_threshold": _fraction_text( |
| 131 | + certificate.exact_strict_schedule_gain_threshold |
| 132 | + ), |
| 133 | + "global_bound_proof": { |
| 134 | + "large_norm_tail_bound": _fraction_text( |
| 135 | + certificate.exact_tail_relative_defect_upper_bound |
| 136 | + ), |
| 137 | + "large_norm_tail_is_strict": ( |
| 138 | + certificate.exact_tail_relative_defect_upper_bound |
| 139 | + < certificate.exact_uniform_relative_defect_upper_bound |
| 140 | + ), |
| 141 | + "finite_core_candidates": ( |
| 142 | + certificate.finite_core_candidate_count |
| 143 | + ), |
| 144 | + "finite_core_admissible": ( |
| 145 | + certificate.finite_core_admissible_count |
| 146 | + ), |
| 147 | + "finite_core_maximizer": list( |
| 148 | + certificate.finite_core_maximizer_amplitudes |
| 149 | + ), |
| 150 | + }, |
| 151 | + "antisymmetry_preserved": ( |
| 152 | + certificate.binary64_antisymmetry_preserved_certified |
| 153 | + ), |
| 154 | + "remesh_forward_invariant": ( |
| 155 | + certificate.remesh_class_forward_invariant_certified |
| 156 | + ), |
| 157 | + "repeated_binary64_runtime": ( |
| 158 | + certificate.repeated_binary64_stability_certified |
| 159 | + ), |
| 160 | + "future_execution": ( |
| 161 | + certificate.future_binary64_execution_certified |
| 162 | + ), |
| 163 | + "full_tnfr_stability": certificate.full_tnfr_stability_certified, |
| 164 | + }, |
| 165 | + "strict_schedule_composition": { |
| 166 | + "q": _fraction_text(strict.schedule_energy_gain_upper_bound), |
| 167 | + "q_effective": _fraction_text( |
| 168 | + strict.exact_effective_head_energy_gain_upper_bound |
| 169 | + ), |
| 170 | + "normalized_block_margin": _fraction_text( |
| 171 | + strict.exact_uniform_normalized_block_margin_lower_bound |
| 172 | + ), |
| 173 | + "geometric_spatial_disagreement_convergence": ( |
| 174 | + strict.geometric_spatial_disagreement_convergence_certified |
| 175 | + ), |
| 176 | + }, |
| 177 | + "threshold_boundary": { |
| 178 | + "q": _fraction_text(boundary.schedule_energy_gain_upper_bound), |
| 179 | + "q_effective": _fraction_text( |
| 180 | + boundary.exact_effective_head_energy_gain_upper_bound |
| 181 | + ), |
| 182 | + "normalized_block_margin": _fraction_text( |
| 183 | + boundary.exact_uniform_normalized_block_margin_lower_bound |
| 184 | + ), |
| 185 | + "geometric_spatial_disagreement_convergence": ( |
| 186 | + boundary.geometric_spatial_disagreement_convergence_certified |
| 187 | + ), |
| 188 | + }, |
| 189 | + "sharp_subnormal_witness": { |
| 190 | + "current_in_smallest_subnormal_units": [-3, 3], |
| 191 | + "local_in_smallest_subnormal_units": [-2, 2], |
| 192 | + "global_in_smallest_subnormal_units": [-3, 3], |
| 193 | + "ideal_left_in_smallest_subnormal_units": "-11/4", |
| 194 | + "runtime_hex": [value.hex() for value in sharp.runtime_bounded_pair], |
| 195 | + "observed_eta": _fraction_text( |
| 196 | + sharp.exact_minimum_nonnegative_relative_defect_bound |
| 197 | + ), |
| 198 | + "attains_uniform_bound": ( |
| 199 | + sharp.exact_minimum_nonnegative_relative_defect_bound |
| 200 | + == certificate.exact_uniform_relative_defect_upper_bound |
| 201 | + ), |
| 202 | + }, |
| 203 | + "excluded_generalizations": { |
| 204 | + "general_metric_centered_input_centers": [ |
| 205 | + _fraction_text(_weighted_center(pair)) |
| 206 | + for pair in centered_inputs |
| 207 | + ], |
| 208 | + "general_metric_centered_output_center": _fraction_text( |
| 209 | + _weighted_center(centered.runtime_bounded_pair) |
| 210 | + ), |
| 211 | + "general_metric_centering_forward_invariant": False, |
| 212 | + "unit_lattice_runtime_output": [ |
| 213 | + value.hex() for value in lattice.runtime_bounded_pair |
| 214 | + ], |
| 215 | + "unit_lattice_forward_invariant": False, |
| 216 | + }, |
| 217 | + } |
| 218 | + |
| 219 | + |
| 220 | +def main() -> None: |
| 221 | + print(json.dumps(build_report(run_protocol()), indent=2, allow_nan=False)) |
| 222 | + |
| 223 | + |
| 224 | +if __name__ == "__main__": |
| 225 | + main() |
0 commit comments