Manuscript En02-A@1 · En02-A-v1.tex · section · bb1319d5

Standalone computational specification

Standalone computational specification · lines 2228–2317

Back to manuscript

The following single-file Python listing uses only the standard library. It has no dependency on an unavailable -calculus package. Copy it to 02_a_checks.py and run:

python en02_a_checks.py

The exact arithmetic portions use integers and .Fraction. Floating-point portions are explicitly sampled diagnostics.

This listing has been statically revised to separate rejected legal guards from invariant failures, retain parallel link identifiers, reject cycles, reduce multiplicities, bound denominator enumeration from capacity, and check every cut of each finite test geometry. It is supplied without an execution log; no particular machine epsilon or generated session is asserted.

"""En02-A: finite regressions and sampled diagnostics.

This file is package evidence, not a proof certificate. No finite test establishes global operational admissibility. """

from __future__ import annotations

from dataclasses import dataclass, replace from fractions import Fraction as F from itertools import combinations, product from math import gcd, sqrt from functools import reduce from random import Random

class GuardFailure(Exception): """Expected refusal of an illegal operation."""

class InvariantError(Exception): """A bug or malformed geometry; never silently swallowed."""

def require(condition, message): if not condition: raise InvariantError(message)

@dataclass(frozen=True) class Geometry: # cap: ((region, nonnegative integer), ...) # active: ((identifier, source, target), ...) # latent: ((identifier, frozenset(u, v)), ...) cap: tuple active: tuple = () latent: tuple = ()

def __post_init__(self): regions = [v for v, _ in self.cap] require(len(regions) == len(set(regions)), "duplicate capacity region") require(all(isinstance(c, int) and c >= 0 for _, c in self.cap), "invalid capacity") V = set(regions) ids_a = [tid for tid, _, _ in self.active] ids_l = [tid for tid, _ in self.latent] require(len(ids_a) == len(set(ids_a)), "duplicate active identifier") require(len(ids_l) == len(set(ids_l)), "duplicate latent identifier") require(not (set(ids_a) & set(ids_l)), "identifier is both active and latent") require(all(u in V and v in V and u != v for _, u, v in self.active), "invalid active endpoint") require(all(len(ends) == 2 and set(ends) <= V for _, ends in self.latent), "invalid latent endpoint") require(self.acyclic(), "active graph contains a cycle")

def regions(self): return frozenset(v for v, _ in self.cap)

def capacity(self): return dict(self.cap)

Nearby in this section