#!/usr/bin/env python3 """Reproduce exact compatibility-zero and damping-graph examples. Dimensionless ideal models; no experimental data or priority claims. Run: python3 verify_rigidity_graph.py Requires NumPy and SciPy. Writes results/rigidity_graph.json. """ from pathlib import Path import json import numpy as np from scipy.linalg import null_space ROOT = Path(__file__).resolve().parent (ROOT / "results").mkdir(exist_ok=True) def incidence(n, edges): b = np.zeros((len(edges), n)) for row, (i, j) in enumerate(edges): b[row, i], b[row, j] = 1., -1. return b def rigidity(): k = np.array([[1., 0., 1.], [0., 4., 1.], [1., 1., 3.]]) c = np.diag([0., 0., .4]) f = np.array([-2/3, 2/3, 1.]) expected = {2.: np.array([2/3, 1/3, 0.]), 3.: np.array([1/3, 2/3, 0.])} exact_errors = [] for lam, q in expected.items(): solution = np.linalg.solve(k-lam*np.eye(3)-1j*np.sqrt(lam)*c, f) exact_errors.append(float(np.linalg.norm(solution-q))) generic_lam = 2.5 generic = np.linalg.solve(k-generic_lam*np.eye(3)-1j*np.sqrt(generic_lam)*c, f) assert max(exact_errors) < 1e-13 assert abs(generic[2]) > 1e-3 assert np.linalg.eigvalsh(k).min() > 0 # A nonzero V can still leave the source-reachable subspace invariant. # The force drives coordinate 1; coordinates 2 and 3 remain unexcited. structural_errors = [] for stiffness in [3., 8., 20.]: ks = np.array([[1., 0., 0.], [0., 4., 1.], [0., 1., stiffness]]) for damping in [.01, 1., 30.]: cs = np.diag([0., 0., damping]) for lam in [.2, .5, 1.7, 2., 3., 4., 7.]: q = np.linalg.solve(ks-lam*np.eye(3)-1j*np.sqrt(lam)*cs, [1., 0., 0.]) target = np.array([1/(1-lam), 0., 0.]) structural_errors.append(float(np.linalg.norm(q-target))) assert max(structural_errors) < 1e-13 return { "compatible_space_dimension": 2, "isolated_compatible_squared_frequencies": [2., 3.], "maximum_exact_solution_error": max(exact_errors), "full_stiffness_minimum_eigenvalue": float(np.linalg.eigvalsh(k).min()), "generic_squared_frequency": generic_lam, "generic_relative_displacement_magnitude": float(abs(generic[2])), "polynomial_coefficients_descending": [1., -5., 6.], "structural_cases": len(structural_errors), "structural_maximum_solution_error": max(structural_errors), } def graph_check(): mass = np.array([1., 2., 1.5, 3.]) local_a = np.array([1., 1.4, .9, 1.8]) total = mass.sum() p = mass/total d = np.sqrt(p) w_basis = null_space(d[None, :]) b = incidence(4, [(0, 1), (1, 2), (2, 3), (0, 3)]) weights = np.array([.4, .7, .3, 1.1]) spring_weights = np.array([.2, .15, .45, .1]) lc = b.T @ np.diag(weights) @ b lk = b.T @ np.diag(spring_weights) @ b invroot = np.diag(1/np.sqrt(mass)) cfull = invroot @ lc @ invroot a_mean = p @ local_a h = (local_a-a_mean)*d injection = mass*(local_a-a_mean) variance = p @ (local_a-a_mean)**2 c_b = w_basis.T @ cfull @ w_basis k_b = w_basis.T @ (np.diag(local_a)+invroot @ lk @ invroot) @ w_basis v = (d @ np.diag(local_a) @ w_basis)[None, :] metric_mass = float(h @ np.linalg.pinv(cfull, hermitian=True) @ h) metric_graph = float(injection @ np.linalg.pinv(lc, hermitian=True) @ injection / total) assert abs(h@h-variance) < 1e-13 assert abs(metric_mass-metric_graph) < 1e-12 potential = np.linalg.pinv(lc, hermitian=True) @ injection flow = weights*(b@potential) flow_error = float(np.linalg.norm(b.T@flow-injection)) flow_energy = float(np.sum(flow**2/weights)) assert flow_error < 1e-12 assert abs(flow_energy-total*metric_graph) < 1e-12 worst_excess = 0. worst_ratio = 0. for omega in np.linspace(.1, 4., 200): bright = np.linalg.solve(k_b-omega**2*np.eye(3)-1j*omega*c_b, v.T) eff = float((bright.conj().T@c_b@bright)[0, 0].real) bound = metric_graph/omega**2 worst_excess = max(worst_excess, eff-bound) worst_ratio = max(worst_ratio, eff/bound) assert worst_excess < 1e-12 return { "masses": mass.tolist(), "restoring_ratios": local_a.tolist(), "mass_weighted_mean": float(a_mean), "variance": float(variance), "squared_coupling_norm": float(h@h), "inverse_damping_metric": metric_mass, "resistance_metric_divided_by_total_mass": metric_graph, "thomson_flow_constraint_error": flow_error, "thomson_flow_energy": flow_energy, "maximum_actual_to_bound_ratio_over_200_frequencies": worst_ratio, "maximum_bound_excess": worst_excess, } def disconnected_coverage(): mass = np.ones(4) d = np.ones(4)/2 b = incidence(4, [(0, 1), (2, 3)]) lc = b.T@np.diag([.7, 1.2])@b projection_range = lc@np.linalg.pinv(lc, hermitian=True) result = [] for label, local_a in [ ("covered_equal_component_means", np.array([1., 3., 1.5, 2.5])), ("uncovered_unequal_component_means", np.array([1., 3., 2., 3.])), ]: mean = local_a.mean() h = (local_a-mean)*d residual = float(np.linalg.norm(h-projection_range@h)) component_sums = [float(np.sum(local_a[:2]-mean)), float(np.sum(local_a[2:]-mean))] covered = residual < 1e-12 assert covered == (label == "covered_equal_component_means") result.append({ "case": label, "ratios": local_a.tolist(), "component_mismatch_sums": component_sums, "coverage_residual": residual, "covered": covered, "protection_cost": float(h@np.linalg.pinv(lc, hermitian=True)@h) if covered else "infinite; range condition fails", }) return result if __name__ == "__main__": output = { "status": "all assertions passed", "interpretation": "Exact ideal-model examples, not experimental evidence.", "rigidity": rigidity(), "connected_graph": graph_check(), "disconnected_graph": disconnected_coverage(), } path = ROOT/"results"/"rigidity_graph.json" path.write_text(json.dumps(output, indent=2)+"\n", encoding="utf-8") print(json.dumps(output, indent=2))