"""Counterexample to an unrestricted equal-edge/equal-diagonal 96% cap.

This is a skew quadrilateral in R^3, not a planar square. All four consecutive
edges have length 1; both opposite diagonals have length d=2**(-1/6).
Under J_ij = distance_ij**(-6), edge couplings are 1 and diagonal couplings 2.
H=-J transfers site 0 to site 2 exactly at t=pi/2, within [0,2.5].
The exact proof is in diagonal-counterexample.md; floating-point verification
below checks the construction independently using a 4x4 eigendecomposition.
"""
import json
import math
import numpy as np

d = 2**(-1/6)
a = d/2
h = math.sqrt((1-2*a*a)/4)
points = np.array([[a, 0, h], [0, a, -h], [-a, 0, h], [0, -a, -h]])
distances = np.linalg.norm(points[:, None] - points[None, :], axis=-1)
edges = [float(distances[i, (i+1) % 4]) for i in range(4)]
diagonals = [float(distances[0, 2]), float(distances[1, 3])]
J = np.zeros((4, 4))
off_diagonal = ~np.eye(4, dtype=bool)
J[off_diagonal] = distances[off_diagonal]**-6
expected = np.array([[0,1,2,1], [1,0,1,2], [2,1,0,1], [1,2,1,0]])
assert np.allclose(edges, 1, atol=1e-14, rtol=0)
assert np.allclose(diagonals, d, atol=1e-14, rtol=0)
assert np.allclose(J, expected, atol=1e-14, rtol=0)
w, V = np.linalg.eigh(-J)
t = math.pi/2
amplitude = (V[0] * np.exp(-1j*w*t)) @ V[2]
probability = float(abs(amplitude)**2)
assert abs(probability-1)<1e-13
print(json.dumps({"points": points.tolist(), "edges": edges, "diagonals": diagonals,
                  "J": J.tolist(), "time": t, "opposite_site_probability": probability}, indent=2))
