Download verify_relational.py from PureOne/qaenthrix-eve: direct link, hf CLI and curl.
- Browser
- Download file 12.9 kB
-
https://huggingface.co/datasets/PureOne/qaenthrix-eve/resolve/main/verify_relational.py
- Command line
-
hf download hf://datasets/PureOne/qaenthrix-eve/verify_relational.py
-
curl -L -o verify_relational.py https://huggingface.co/datasets/PureOne/qaenthrix-eve/resolve/main/verify_relational.py
12.9 kB
| """Independent finite checks of NØWÆ constructions and adverse cases. | |
| Universal claims, particularly Borsuk-Ulam, are proved in MANUSCRIPT.md. | |
| Synthetic sampling and numerical integration are consistency checks only. | |
| """ | |
| import itertools | |
| import json | |
| import numpy as np | |
| from eve_reserve import analyse | |
| from relational_geometry import ( | |
| ray, global_factor, anchor_section, anchor_factor, recognition_margin, | |
| select_reference, pair_transport, cycle_holonomy, relational_direction, | |
| relational_factor, relational_event, | |
| ) | |
| def run(): | |
| rng = np.random.default_rng(26100429) | |
| maxima = {'factor': 0., 'distance': 0., 'pair': 0., 'decode': 0., 'vectorization': 0.} | |
| counts = {} | |
| def unit(n): | |
| z = rng.normal(size=n)+1j*rng.normal(size=n) | |
| return z/np.linalg.norm(z) | |
| def random_unitary(n): | |
| return np.linalg.qr(rng.normal(size=(n, n))+1j*rng.normal(size=(n, n)))[0] | |
| def check(name, residual, tolerance=2e-10): | |
| value = float(residual) | |
| maxima[name] = max(maxima[name], value) | |
| assert value < tolerance, (name, value) | |
| # Dense global factors and an explicit forced-zero family with known witnesses. | |
| for _ in range(192): | |
| n = int(rng.integers(2, 9)); m = int(rng.integers(1, n)) | |
| p = ray(unit(n)); lam = float(rng.uniform(.2, 2.)); mu = .15*lam | |
| g = lam*p+mu*(np.eye(n)-p) | |
| c = global_factor(p, lam, mu) | |
| check('factor', np.linalg.norm(c.conj().T@c-g, 2)) | |
| b = rng.normal(size=(m, n))+1j*rng.normal(size=(m, n)) | |
| b /= np.linalg.norm(b, 2) | |
| witness = np.linalg.svd(b, full_matrices=True)[2][-1].conj() | |
| p0 = ray(witness) | |
| d = rng.normal(size=(m, n))+1j*rng.normal(size=(m, n)) | |
| # C(P)=B P + D(P)(I-P), with a genuinely parameter-dependent D. | |
| d0 = d*(1+.2*p0[0, 0].real) | |
| c0 = b@p0+d0@(np.eye(n)-p0) | |
| assert np.linalg.norm(c0@witness) < 2e-12 | |
| error = np.linalg.norm(c0.conj().T@c0-(lam*p0+mu*(np.eye(n)-p0)), 2) | |
| assert error >= lam-2e-10 | |
| counts['global_factor_and_blind_witness_cases'] = 192 | |
| # Closest blind projectors, exact anchor factors, and noise inequalities. | |
| noise_cases = 0 | |
| for _ in range(384): | |
| n = int(rng.integers(2, 9)); u = unit(n); w = unit(n); p = ray(u) | |
| delta = recognition_margin(p, w) | |
| a = anchor_section(p, w); lam = float(rng.uniform(.2, 2.)) | |
| c = anchor_factor(p, w, lam) | |
| check('factor', np.linalg.norm(c.conj().T@c-lam*p, 2)) | |
| assert abs(np.vdot(w, a)-delta) < 2e-12 | |
| v = u-w*np.vdot(w, u) | |
| v /= np.linalg.norm(v); blind = ray(v) | |
| check('distance', abs(np.linalg.norm(p-blind, 2)-delta)) | |
| assert np.linalg.norm(blind@w) < 2e-12 | |
| try: | |
| anchor_section(blind, w) | |
| except ValueError: | |
| pass | |
| else: | |
| raise AssertionError('blind anchor must reject') | |
| new = ray(u+float(rng.uniform(1e-4, .08))*unit(n)) | |
| eta = np.linalg.norm(new-p, 2) | |
| if eta < delta: | |
| noise_cases += 1 | |
| anew = anchor_section(new, w) | |
| assert np.linalg.norm(a-anew) <= 2*eta/delta+2e-12 | |
| counts['anchor_and_exact_breakdown_cases'] = 384 | |
| counts['recognized_perturbation_cases'] = noise_cases | |
| sensitivity = 0 | |
| w = np.array([1., 0.]); v = np.array([0., 1.]) | |
| for delta in [.01, .02, .05, .1, .2, .4, .7, .9]: | |
| for phi in np.linspace(.05, 2.8, 12): | |
| u0 = np.sqrt(1-delta**2)*v+delta*w | |
| u1 = np.sqrt(1-delta**2)*v+delta*np.exp(1j*phi)*w | |
| p0, p1 = ray(u0), ray(u1) | |
| quotient = np.linalg.norm(anchor_section(p1, w)-anchor_section(p0, w))/np.linalg.norm(p1-p0, 2) | |
| assert abs(quotient-1/delta) < 2e-8 | |
| sensitivity += 1 | |
| counts['sharp_inverse_margin_examples'] = sensitivity | |
| # Reference-atlas optimality: constructive sign-vector witnesses. | |
| atlas_cases = 0 | |
| for n in range(2, 9): | |
| basis = random_unitary(n) | |
| balanced = basis@np.exp(1j*rng.uniform(0, 2*np.pi, n))/np.sqrt(n) | |
| overlaps = np.linalg.norm(ray(balanced)@basis, axis=0)**2 | |
| assert np.allclose(overlaps, 1/n, atol=2e-12) | |
| for _ in range(12): | |
| refs = np.column_stack([unit(n) for _ in range(n)]) | |
| a = refs.conj().T | |
| inv = np.linalg.inv(a) | |
| signs = np.array(list(itertools.product([-1., 1.], repeat=n))) | |
| inverse_signs = inv@signs.T | |
| distances = np.sum(np.abs(inverse_signs)**2, axis=0) | |
| mean = float(np.mean(distances)) | |
| assert mean >= n-1e-9 | |
| j = int(np.argmax(distances)); witness = inverse_signs[:, j]/np.sqrt(distances[j]) | |
| tau = np.abs(a@witness)**2 | |
| assert max(tau) <= 1/n+2e-10 | |
| assert np.allclose(tau, 1/distances[j], atol=2e-10) | |
| index, section, margin = select_reference(ray(witness), refs) | |
| assert index in range(n) and margin > 0 and np.isclose(np.linalg.norm(section), 1) | |
| lower = np.linalg.eigvalsh(refs@refs.conj().T)[0]/n | |
| assert margin**2 >= lower-2e-10 | |
| atlas_cases += 1 | |
| deficient = np.column_stack([unit(n) for _ in range(n-1)]) | |
| blind = np.linalg.svd(deficient.conj().T, full_matrices=True)[2][-1].conj() | |
| assert np.linalg.norm(deficient.conj().T@blind) < 2e-12 | |
| try: | |
| select_reference(ray(blind), deficient) | |
| except ValueError: | |
| pass | |
| else: | |
| raise AssertionError('deficient atlas must have a blind ray') | |
| counts['nonorthogonal_atlas_witness_cases'] = atlas_cases | |
| counts['orthonormal_atlas_and_deficient_atlas_dimensions'] = 7 | |
| # Partial-isometry identities, covariance, perturbation bounds, and loop phases. | |
| for _ in range(256): | |
| n = int(rng.integers(2, 8)); p, q = ray(unit(n)), ray(unit(n)) | |
| t = pair_transport(p, q) | |
| check('pair', np.linalg.norm(t.conj().T@t-q, 'fro')) | |
| check('pair', np.linalg.norm(t@t.conj().T-p, 'fro')) | |
| u = random_unitary(n) | |
| transformed = pair_transport(u@p@u.conj().T, u@q@u.conj().T) | |
| check('pair', np.linalg.norm(transformed-u@t@u.conj().T, 'fro')) | |
| pp, qq = ray(unit(n)), ray(unit(n)) | |
| tp = pair_transport(pp, qq) | |
| delta = min(np.linalg.norm(p@q, 'fro'), np.linalg.norm(pp@qq, 'fro')) | |
| assert np.linalg.norm(t-tp, 'fro') <= 2/delta*(np.linalg.norm(p-pp, 'fro')+np.linalg.norm(q-qq, 'fro'))+2e-12 | |
| vectors = [unit(n) for _ in range(int(rng.integers(3, 8)))] | |
| phases = [np.vdot(vectors[i], vectors[(i+1)%len(vectors)]) for i in range(len(vectors))] | |
| expected = np.prod([z/abs(z) for z in phases]) | |
| h = cycle_holonomy([ray(v) for v in vectors]) | |
| check('pair', abs(h-expected)) | |
| assert abs(abs(h)-1) < 2e-10 | |
| counts['pair_transport_and_cycle_cases'] = 256 | |
| triangle = [ray(np.array([1., 0.])), ray(np.array([1., 1.])), ray(np.array([1., 1j]))] | |
| triangle_phase = cycle_holonomy(triangle) | |
| assert abs(triangle_phase-np.exp(1j*np.pi/4)) < 2e-12 | |
| positive_triangle = [ray(np.array([np.cos(t), np.sin(t)])) for t in [.1, .5, .9]] | |
| assert abs(cycle_holonomy(positive_triangle)-1) < 2e-12 | |
| # Relational inputs are arbitrary complex matrices, not just paired rank-one states. | |
| for _ in range(192): | |
| n = int(rng.integers(2, 8)); u = unit(n); p = ray(u); r = relational_direction(p) | |
| x = rng.normal(size=(n, n))+1j*rng.normal(size=(n, n)) | |
| z = x.reshape(-1, order='F') | |
| alpha = np.array([.5, .25]); total = float(sum(alpha)) | |
| factor = relational_factor(p, total) | |
| check('factor', np.linalg.norm(factor.conj().T@factor-total*np.outer(r, r.conj()), 2)) | |
| visible_matrix = x+(np.sqrt(1-total)-1)*np.trace(p@x)*p | |
| memories = np.sqrt(alpha)*np.trace(p@x) | |
| decoded_matrix = visible_matrix+(np.sqrt(1-total)-1)*np.trace(p@visible_matrix)*p | |
| decoded_matrix += np.dot(np.sqrt(alpha), memories)*p | |
| check('decode', np.linalg.norm(decoded_matrix-x, 'fro')) | |
| assert abs(np.linalg.norm(x, 'fro')**2-np.linalg.norm(visible_matrix, 'fro')**2-np.linalg.norm(memories)**2) < 2e-10 | |
| events = [relational_event(p, 1/np.sqrt(2), 0), relational_event(p, 1/np.sqrt(2), 1)] | |
| prefix = analyse(events, n*n)[-1] | |
| check('vectorization', np.linalg.norm(prefix['product']@z-visible_matrix.reshape(-1, order='F'))) | |
| for weight, g in zip(alpha, prefix['grams']): | |
| check('factor', np.linalg.norm(g-weight*np.outer(r, r.conj()), 2)) | |
| transport = random_unitary(n) | |
| event = relational_event(p, .6, 0, transport) | |
| retained = x+(.6-1)*np.trace(p@x)*p | |
| transported = transport@retained@transport.conj().T | |
| check('vectorization', np.linalg.norm(analyse([event], n*n)[0]['product']@z-transported.reshape(-1, order='F'))) | |
| a, b = complex(*rng.normal(size=2)), complex(*rng.normal(size=2)) | |
| paired = np.outer(a*u, (b*u).conj()) | |
| assert np.allclose(paired, a*b.conjugate()*p) | |
| assert np.allclose(paired/np.trace(paired), p) | |
| phase = np.exp(1j*float(rng.uniform(-np.pi, np.pi))) | |
| assert np.allclose(np.outer(phase*a*u, (phase*b*u).conj()), paired) | |
| counts['relational_matrix_completion_cases'] = 192 | |
| # Nonlinear energy equality must not be mistaken for complex amplitude retention. | |
| p = ray(np.array([1., 0.])); active = np.array([1.+2j, 0.]) | |
| readout = lambda x: np.sqrt(np.vdot(x, p@x).real) | |
| assert readout(active) == readout(1j*active) | |
| counts['nonlinear_phase_loss_counterexamples'] = 1 | |
| # Nontrivial quantitative blind-region checks with C(P)=B P. | |
| for _ in range(192): | |
| n = int(rng.integers(2, 9)); m = int(rng.integers(1, n)); lam = float(rng.uniform(.2, 2.)) | |
| b = rng.normal(size=(m, n))+1j*rng.normal(size=(m, n)); b /= np.linalg.norm(b, 2) | |
| u0 = np.linalg.svd(b, full_matrices=True)[2][-1].conj() | |
| v = unit(n); v -= u0*np.vdot(u0, v); v /= np.linalg.norm(v) | |
| aconstant = 1+np.sqrt(2) # K=L=1 | |
| radius = min(1., np.sqrt(.5*lam)/aconstant) | |
| d = float(rng.uniform(0, radius)) | |
| u = np.sqrt(1-d*d)*u0+d*v; p = ray(u); c = b@p | |
| error = np.linalg.norm(c.conj().T@c-lam*p, 2) | |
| assert error >= lam-aconstant**2*d*d-2e-12 | |
| assert error >= .5*lam-2e-12 | |
| counts['quantitative_blind_region_cases'] = 192 | |
| # Haar ball formula checked by reproducible synthetic sampling, never used as a proof. | |
| haar_checks = [] | |
| for n in range(2, 9): | |
| samples = 12000; r = .25**(1/(2*(n-1))) | |
| raw = rng.normal(size=(samples, n))+1j*rng.normal(size=(samples, n)) | |
| fidelity = np.abs(raw[:, 0])**2/np.sum(np.abs(raw)**2, axis=1) | |
| count = int(np.count_nonzero(fidelity >= 1-r*r)) | |
| predicted = r**(2*(n-1)); measured = count/samples | |
| assert abs(measured-predicted) < 6*np.sqrt(predicted*(1-predicted)/samples)+2/samples | |
| haar_checks.append({'n': n, 'samples': samples, 'count': count, 'predicted_fraction': predicted, 'sampled_fraction': measured}) | |
| counts['synthetic_haar_rays'] = sum(x['samples'] for x in haar_checks) | |
| # Integrate Kato's ODE; doubling resolution must exhibit second-order convergence. | |
| path_results = [] | |
| for theta in [.3, np.pi/4, 1.1]: | |
| v0 = np.array([np.cos(theta), np.sin(theta)], dtype=complex) | |
| expected = np.exp(-2j*np.pi*np.sin(theta)**2)*v0 | |
| errors = [] | |
| for steps in [512, 1024]: | |
| h = 2*np.pi/steps; value = v0.copy() | |
| for j in range(steps): | |
| t = (j+.5)*h | |
| v = np.array([np.cos(theta), np.exp(1j*t)*np.sin(theta)]) | |
| dv = np.array([0., 1j*np.exp(1j*t)*np.sin(theta)]) | |
| p = np.outer(v, v.conj()); dp = np.outer(dv, v.conj())+np.outer(v, dv.conj()) | |
| k = dp@p-p@dp | |
| value = np.linalg.solve(np.eye(2)-h*k/2, (np.eye(2)+h*k/2)@value) | |
| err = float(np.linalg.norm(value-expected)); errors.append(err) | |
| assert abs(np.linalg.norm(value)-1) < 3e-12 | |
| assert err < 5e-5 | |
| ratio = errors[0]/errors[1] | |
| assert 3.9 < ratio < 4.1 | |
| path_results.append({'theta': float(theta), 'errors_512_1024': errors, 'convergence_ratio': ratio}) | |
| counts['integrated_path_steps'] = 3*(512+1024) | |
| counts['path_resolution_comparisons'] = 3 | |
| return { | |
| 'seed': 26100429, 'counts': counts, 'maximum_residuals': maxima, | |
| 'triangle_phase_radians': float(np.angle(triangle_phase)), | |
| 'haar_ball_checks': haar_checks, 'path_integration_checks': path_results, | |
| 'scope': 'Finite and synthetic checks support explicit constructions; proofs establish universal bounds. No empirical science or proof-assistant certification is claimed.', | |
| } | |
| if __name__ == '__main__': | |
| print(json.dumps(run(), indent=2)) | |