Manuscript En02-A@1 · En02-A-v1.tex · section · bb1319d5
Standalone computational specification
Standalone computational specification · lines 2600–2688
def witness(a, u, m): if not (0.0 < a < 1.0 and 0.0 < u < 1.0): raise ValueError("a and u must be in (0,1)") if not (a * u < m < a * u + 1.0 - a): raise ValueError("m outside exact open cocycle domain") w = (a * u, a * (1 - u), m - a * u, 1 - a - m + a * u) require(min(w) > 0.0, "nonpositive witness amplitude weight") require(abs(sum(w) - 1.0) < 1e-12, "witness is not normalized") return tuple(complex(sqrt(x)) for x in w)
def qubit_count(psi): length = len(psi) require(length >= 1 and length & (length - 1) == 0, "state length is not a power of two") return length.bit_length() - 1
def project_delete(psi, S, outcome): n = qubit_count(psi) S = tuple(S) require(len(S) == len(set(S)), "duplicate measured coordinate") require(all(0 <= i < n for i in S), "invalid measured coordinate") require(len(outcome) == len(S), "wrong outcome arity") survivors = tuple(i for i in range(n) if i not in S) out = [0j] * (1 << len(survivors)) for index, amp in enumerate(psi): bits = tuple((index >> (n - 1 - i)) & 1 for i in range(n)) if tuple(bits[i] for i in S) == tuple(outcome): target = 0 for i in survivors: target = 2 * target + bits[i] out[target] = complex(amp) p = sum(abs(z) ** 2 for z in out) if p == 0.0: return p, None return p, tuple(z / sqrt(p) for z in out)
def born_law(psi, S): return outcome: project_delete(psi, S, outcome)[0] for outcome in product((0, 1), repeat=len(S))
class BornStrategy: def P(self, psi, S): return born_law(psi, S)
def U(self, psi, S, outcome): p, residual = project_delete(psi, S, outcome) if p == 0.0: raise ValueError("zero branch has no residual") return residual
def diagonal_residual_defect(strategy, psi, S, outcome): p = strategy.P(psi, S)[tuple(outcome)] if p <= 0.0: return 0.0 b, projective = project_delete(psi, S, outcome) require(b > 0.0, "positive strategy branch violates nullity") residual = strategy.U(psi, S, outcome) require(len(residual) == len(projective), "residual has wrong dimension") return max(abs(abs(x) ** 2 - abs(y) ** 2) for x, y in zip(residual, projective))
def sample_rigidity_identities(strategy, samples=200, seed=0): """Sample necessary identities; this is not proof execution.""" rng = Random(seed)
def phi(x): return strategy.P(chi(x), (0,))[(0,)]
worst_df = 0.0 worst_cocycle = 0.0 worst_product = 0.0 worst_identity = 0.0
for x in (0.0, 0.5, 1.0): require(abs(phi(x) - x) < 1e-9, "anchor diagnostic failed")