#!/usr/bin/env python3 r""" Exact Q and Q(sqrt(5)) verification of rank-4 real/rational geometric lattices: - Coxeter root systems A_4, D_4, B_4, F_4, H_4 (60 roots in Q(sqrt(5))^4) - Reye configuration (12 points, 16 lines of size 3, 12 planes of size 6) - 3D affine grids [2]^3, [3]^3, [4]^3 and generic extensions of F_4 Checks exact Sturm real-rootedness and Melchior ratio f_{123} / f_{23} < 3. """ from fractions import Fraction from itertools import product from matroid_lab import is_real_rooted_sturm def norm_vec_Q(v): fr = [Fraction(x) for x in v] first = next((i for i, x in enumerate(fr) if x != 0), None) if first is None: return None inv = Fraction(1) / fr[first] return tuple(x * inv for x in fr) def rank4_stats_from_vectors_Q(vecs, name): pts = sorted(set(filter(None, (norm_vec_Q(v) for v in vecs)))) n = len(pts) def plucker(u, v): return norm_vec_Q(( u[0]*v[1] - u[1]*v[0], u[0]*v[2] - u[2]*v[0], u[0]*v[3] - u[3]*v[0], u[1]*v[2] - u[2]*v[1], u[1]*v[3] - u[3]*v[1], u[2]*v[3] - u[3]*v[2], )) def normal_3(u, v, w): def det3(a, b, c): return (a[0]*(b[1]*c[2] - b[2]*c[1]) - a[1]*(b[0]*c[2] - b[2]*c[0]) + a[2]*(b[0]*c[1] - b[1]*c[0])) return norm_vec_Q(( det3((u[1], u[2], u[3]), (v[1], v[2], v[3]), (w[1], w[2], w[3])), -det3((u[0], u[2], u[3]), (v[0], v[2], v[3]), (w[0], w[2], w[3])), det3((u[0], u[1], u[3]), (v[0], v[1], v[3]), (w[0], w[1], w[3])), -det3((u[0], u[1], u[2]), (v[0], v[1], v[2]), (w[0], w[1], w[2])), )) lines_map = {} for i in range(n): for j in range(i + 1, n): pl = plucker(pts[i], pts[j]) if pl not in lines_map: lines_map[pl] = {i, j} else: lines_map[pl].add(i) lines_map[pl].add(j) lines = list(lines_map.values()) planes_map = {} for l_idx, lset in enumerate(lines): it = iter(lset) i1, i2 = next(it), next(it) u, v = pts[i1], pts[i2] seen_normals = set() for k in range(n): if k in lset: continue nm = normal_3(u, v, pts[k]) if nm is None or nm in seen_normals: continue seen_normals.add(nm) if nm not in planes_map: pset = {idx for idx, p in enumerate(pts) if sum(nm[t]*p[t] for t in range(4)) == 0} planes_map[nm] = (pset, set()) planes_map[nm][1].add(l_idx) W1, W2, W3 = n, len(lines), len(planes_map) f12 = sum(len(ls) for ls in lines) f13 = sum(len(ps) for ps, _ in planes_map.values()) f23 = sum(len(ls) for _, ls in planes_map.values()) f123 = sum(sum(len(lines[li]) for li in ls) for _, ls in planes_map.values()) c1, c2, c3 = W1 + W2 + W3, f12 + f13 + f23, f123 cp = [1, c1, c2, c3] assert f123 <= 3 * f23 - 3 * W3 assert c2 * c2 > 2 * c1 * c3 rr, _, _ = is_real_rooted_sturm(cp) assert rr lc = (c2 * c2) / (c1 * c3) print(f" {name:24s} n={n:3d} W=({W1:3d},{W2:4d},{W3:4d}) f123/f23={f123/f23:.4f} LC={lc:.4f} ULC={lc/3:.4f} RR={rr} c={cp}") return cp, rr def main(): print("=== CLASSICAL Q-REPRESENTABLE & REALIZABLE RANK-4 ARRANGEMENTS ===") a4 = [] for i in range(5): for j in range(i + 1, 5): v = [0]*5 v[i], v[j] = 1, -1 a4.append(v[:4]) rank4_stats_from_vectors_Q(a4, "Coxeter A_4") d4 = [] for i in range(4): for j in range(i + 1, 4): for s in (-1, 1): v = [0]*4 v[i], v[j] = 1, s d4.append(v) rank4_stats_from_vectors_Q(d4, "Coxeter D_4") b4 = list(d4) + [[1 if k == i else 0 for k in range(4)] for i in range(4)] rank4_stats_from_vectors_Q(b4, "Coxeter B_4") f4 = list(b4) + [list(t) for t in product((-1, 1), repeat=4)] rank4_stats_from_vectors_Q(f4, "Coxeter F_4 (24)") reye = [[1 if k == i else 0 for k in range(4)] for i in range(4)] + [list(t) for t in product((-1, 1), repeat=4)] rank4_stats_from_vectors_Q(reye, "Reye config (12)") for k in [2, 3, 4]: grid = [(1, x, y, z) for x in range(k) for y in range(k) for z in range(k)] rank4_stats_from_vectors_Q(grid, f"Affine grid [{k}]^3") gen = [(1, 2, 3, 5), (1, 7, 11, 13), (1, 17, 19, 23), (1, 29, 31, 37)] for g in [1, 2, 4]: rank4_stats_from_vectors_Q(f4 + gen[:g], f"F_4 + {g} generic") print("\n=== COXETER H_4 (60 ROOTS IN R^4, EXACT Q(sqrt(5)) ARITHMETIC) ===") def add_p(x, y): return (x[0] + y[0], x[1] + y[1]) def sub_p(x, y): return (x[0] - y[0], x[1] - y[1]) def mul_p(x, y): return (x[0]*y[0] + x[1]*y[1], x[0]*y[1] + x[1]*y[0] + x[1]*y[1]) def inv_p(x): a, b = x den = a*a + a*b - b*b return ((a + b) / den, -b / den) Z = (Fraction(0), Fraction(0)) O = (Fraction(1), Fraction(0)) M = (Fraction(-1), Fraction(0)) H = (Fraction(1, 2), Fraction(0)) PHIH = (Fraction(0), Fraction(1, 2)) IPHIH = (Fraction(-1, 2), Fraction(1, 2)) def norm_vec_P(v): first = next((i for i, x in enumerate(v) if x != Z), None) if first is None: return None iv = inv_p(v[first]) return tuple(mul_p(x, iv) for x in v) h4_raw = [] for i in range(4): v = [Z]*4 v[i] = O h4_raw.append(tuple(v)) for s in product((M, O), repeat=4): h4_raw.append(tuple((x[0] / 2, x[1] / 2) for x in s)) even_perms = [ (0, 1, 2, 3), (0, 2, 3, 1), (0, 3, 1, 2), (1, 0, 3, 2), (1, 2, 0, 3), (1, 3, 2, 0), (2, 0, 1, 3), (2, 1, 3, 0), (2, 3, 0, 1), (3, 0, 2, 1), (3, 1, 0, 2), (3, 2, 1, 0), ] for p in even_perms: for s1 in (1, -1): for s2 in (1, -1): for s3 in (1, -1): vals = [ Z, (H[0]*s1, H[1]*s1), (PHIH[0]*s2, PHIH[1]*s2), (IPHIH[0]*s3, IPHIH[1]*s3), ] h4_raw.append(tuple(vals[p[k]] for k in range(4))) h4_pts = sorted(set(filter(None, (norm_vec_P(v) for v in h4_raw)))) assert len(h4_pts) == 60 def plucker_P(u, v): pairs = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] return norm_vec_P(tuple(sub_p(mul_p(u[a], v[b]), mul_p(u[b], v[a])) for a, b in pairs)) def det3_P(a, b, c): t0 = mul_p(a[0], sub_p(mul_p(b[1], c[2]), mul_p(b[2], c[1]))) t1 = mul_p(a[1], sub_p(mul_p(b[0], c[2]), mul_p(b[2], c[0]))) t2 = mul_p(a[2], sub_p(mul_p(b[0], c[1]), mul_p(b[1], c[0]))) return add_p(sub_p(t0, t1), t2) def normal_3_P(u, v, w): n0 = det3_P((u[1], u[2], u[3]), (v[1], v[2], v[3]), (w[1], w[2], w[3])) n1 = sub_p(Z, det3_P((u[0], u[2], u[3]), (v[0], v[2], v[3]), (w[0], w[2], w[3]))) n2 = det3_P((u[0], u[1], u[3]), (v[0], v[1], v[3]), (w[0], w[1], w[3])) n3 = sub_p(Z, det3_P((u[0], u[1], u[2]), (v[0], v[1], v[2]), (w[0], w[1], w[2]))) return norm_vec_P((n0, n1, n2, n3)) lines_map = {} for i in range(60): for j in range(i + 1, 60): pl = plucker_P(h4_pts[i], h4_pts[j]) if pl not in lines_map: lines_map[pl] = {i, j} else: lines_map[pl].add(i) lines_map[pl].add(j) lines = list(lines_map.values()) planes_map = {} for l_idx, lset in enumerate(lines): it = iter(lset) i1, i2 = next(it), next(it) u, v = h4_pts[i1], h4_pts[i2] seen_n = set() for k in range(60): if k in lset: continue nm = normal_3_P(u, v, h4_pts[k]) if nm is None or nm in seen_n: continue seen_n.add(nm) if nm not in planes_map: pset = set() for idx, p in enumerate(h4_pts): dot = Z for t in range(4): dot = add_p(dot, mul_p(nm[t], p[t])) if dot == Z: pset.add(idx) planes_map[nm] = (pset, set()) planes_map[nm][1].add(l_idx) W1, W2, W3 = 60, len(lines), len(planes_map) f12 = sum(len(ls) for ls in lines) f13 = sum(len(ps) for ps, _ in planes_map.values()) f23 = sum(len(ls) for _, ls in planes_map.values()) f123 = sum(sum(len(lines[li]) for li in ls) for _, ls in planes_map.values()) c1, c2, c3 = W1 + W2 + W3, f12 + f13 + f23, f123 cp = [1, c1, c2, c3] assert f123 <= 3 * f23 - 3 * W3 assert c2 * c2 > 2 * c1 * c3 rr, _, _ = is_real_rooted_sturm(cp) assert rr and cp == [1, 2102, 17640, 21600] lc = (c2 * c2) / (c1 * c3) print(f" {'Coxeter H_4 (60)':24s} n= 60 W=({W1:3d},{W2:4d},{W3:4d}) f123/f23={f123/f23:.4f} LC={lc:.4f} ULC={lc/3:.4f} RR={rr} c={cp}") print("\nALL COXETER / REALIZABLE RANK-4 CERTIFICATIONS PASSED 100%!") if __name__ == "__main__": main()