File size: 6,384 Bytes
81a3ea5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | """Analytic claims are proved in MANUSCRIPT.md; these are independent checks."""
import json
import platform
from pathlib import Path
import numpy as np
from eve_reserve import Event, analyse, encode, gram_factor
from verify_exact import run as exact_run
from verify_relational import run as relational_run
from verify_continuous import run as continuous_run
def run():
rng = np.random.default_rng(704107)
cases = 400
prefixes = 0
largest_error = 0.
for _ in range(cases):
n = int(rng.integers(1, 8))
steps = int(rng.integers(2, 12))
events = []
for t in range(steps):
u = rng.normal(size=n) + 1j*rng.normal(size=n)
u /= np.linalg.norm(u)
z = rng.normal(size=(n, n)) + 1j*rng.normal(size=(n, n))
unitary, _ = np.linalg.qr(z)
c = float(rng.uniform(.55, .99))
if t == 0 and rng.random() < .15:
c = 0.
if rng.random() < .1:
c = 1.
events.append(Event(u, c, int(rng.integers(2)), unitary))
history = analyse(events, n)
previous = [0, 0]
for h in history:
prefixes += 1
p = h['product']
total = sum(h['grams'])
err = np.linalg.norm(total + p.conj().T@p - np.eye(n), 2)
largest_error = max(largest_error, float(err))
assert err < 1e-10
factors = [gram_factor(g) for g in h['grams']]
r = [c.shape[0] for c in factors]
pooled = gram_factor(total).shape[0]
active_rank = np.linalg.matrix_rank(h['active_normals'], tol=1e-8)
assert pooled == active_rank
assert 0 <= sum(r)-pooled <= pooled <= n
assert all(a >= b for a, b in zip(r, previous))
previous = r
for c, s, g in zip(factors, h['transcripts'], h['grams']):
assert np.allclose(c.conj().T@c, g, atol=1e-10)
assert np.allclose(s.conj().T@s, g, atol=1e-10)
# Transcript recovery from the colour's minimal factor.
assert np.allclose(s@np.linalg.pinv(c)@c, s, atol=1e-8)
x = rng.normal(size=n) + 1j*rng.normal(size=n)
visible, memories, decoded = encode(h, x)
assert np.allclose(decoded, x, atol=1e-9)
assert abs(np.vdot(x, x) - np.vdot(visible, visible)
- sum(np.vdot(m, m) for m in memories)) < 1e-8
# Non-unitary coordinate charts carry the transported metric.
f0 = np.diag(rng.uniform(.5, 2., n))
ft = np.diag(rng.uniform(.5, 2., n))
inv0, invt = np.linalg.inv(f0), np.linalg.inv(ft)
chart_product = ft@p@inv0
chart_total = inv0.conj().T@total@inv0
metric0, metrict = inv0.conj().T@inv0, invt.conj().T@invt
assert np.allclose(chart_total + chart_product.conj().T@metrict@chart_product,
metric0, atol=1e-10)
# Exact scanner factorization on the active subspace.
hscan = gram_factor(total)
hp = np.linalg.pinv(hscan)
for g in h['grams']:
k = hp.conj().T@g@hp
assert np.allclose(hscan.conj().T@k@hscan, g, atol=1e-8)
# Spectral truncation reaches the proved optimum for every k.
values, vectors = np.linalg.eigh(total)
order = np.argsort(values)[::-1]
values, vectors = values[order], vectors[:, order]
for k in range(n+1):
approximation = (vectors[:, :k]*values[:k])@vectors[:, :k].conj().T
optimum = max(0., float(values[k])) if k < n else 0.
assert abs(np.linalg.norm(total-approximation, 2)-optimum) < 1e-9
# Local rank-one unitary completion and topological chart transition.
local_error = 0.
for _ in range(96):
n = 3
u = rng.normal(size=n)+1j*rng.normal(size=n)
u /= np.linalg.norm(u)
c = float(rng.random()); s = np.sqrt(1-c*c)
a = np.eye(n)+(c-1)*np.outer(u, u.conj())
j = np.block([[a, -s*u[:, None]], [s*u.conj()[None, :], np.array([[c]])]])
error = float(np.linalg.norm(j.conj().T@j-np.eye(n+1), 2))
local_error = max(local_error, error)
assert error < 1e-10
phases = np.linspace(0, 2*np.pi, 513)
transition = []
for phase in phases:
z = np.exp(1j*phase)
un = np.array([1, z])/np.sqrt(2)
us = np.array([1/z, 1])/np.sqrt(2)
assert np.allclose(us, np.exp(-1j*phase)*un)
projector = np.outer(un, un.conj())
a, b = .5, .25
# Continuous redundant global factors, in two fixed coordinates per colour.
for g, factor in [(a*projector, np.sqrt(a)*projector),
(b*projector, np.sqrt(b)*projector)]:
assert np.allclose(factor.conj().T@factor, g)
transition.append(np.vdot(un, us))
winding = (np.unwrap(np.angle(transition))[-1]-np.unwrap(np.angle(transition))[0])/(2*np.pi)
assert abs(winding+1) < 1e-10
# Deliberate counterexample to the incorrect, untransported colour-rank shortcut.
e1 = np.array([1., 0.]); u = np.array([3/5, 4/5])
chronology = analyse([Event(e1, .6, 0, np.eye(2)), Event(u, .6, 1, np.eye(2)),
Event(e1, .6, 0, np.eye(2))], 2)[-1]
assert gram_factor(chronology['grams'][0]).shape[0] == 2
assert np.linalg.matrix_rank(np.stack([e1, e1])) == 1
return {
**exact_run(), "complex_words": cases, "complex_prefixes": prefixes,
"local_unitary_cases": 96, "topological_transition_samples": 513,
"sampled_transition_winding": float(winding),
"maximum_balance_error": largest_error,
"maximum_local_unitarity_error": local_error,
"python": platform.python_version(), "numpy": np.__version__,
"seed": 704107,
"version": "3.0.0",
"relational_extension": relational_run(),
"continuous_factorization_extension": continuous_run(),
"scope": "finite checks support the analytic proofs; topology is not proved by sampling",
}
if __name__ == '__main__':
result = run()
target = Path(__file__).with_name('VERIFICATION.json')
target.write_text(json.dumps(result, indent=2)+'\n', encoding='utf-8')
print(json.dumps(result, indent=2))
|