#!/usr/bin/env python3 """Numerical check of two forms of the circular complement identity. Spacing form (the repo's statement): for a cyclic word of D positive integer gaps with total W, max over i of the sum of m consecutive gaps plus min over j of the sum of D-m consecutive gaps equals W, for every m in 1..D-1. Count form (the parametrisation used in Cressie, J. Appl. Probab. 14 (1977) p. 278): for N points on the unit circle and any window length h in (0,1), max over x of N_c(x,h) plus min over x of N_c(x,1-h) equals N, where N_c(x,h) is the number of points in the arc (x, x+h] mod 1. A script output is a measurement, never a proof. """ import random, itertools, hashlib, sys def spacing_form(gaps): D = len(gaps); W = sum(gaps); ok = True for m in range(1, D): mx = max(sum(gaps[(i + t) % D] for t in range(m)) for i in range(D)) mn = min(sum(gaps[(i + t) % D] for t in range(D - m)) for i in range(D)) ok &= (mx + mn == W) return ok def count_form(points, h): # arcs (x, x+h] mod 1; the count only changes at x = p - h or x = p, so test those x plus midpoints N = len(points) xs = sorted(set([(p - h) % 1 for p in points] + [p for p in points] + [(p - h + 1e-9) % 1 for p in points] + [(p + 1e-9) % 1 for p in points])) def cnt(x, h): return sum(1 for p in points if 0 < ((p - x) % 1) <= h) mx = max(cnt(x, h) for x in xs) mn = min(cnt(x, 1 - h) for x in xs) return mx + mn == N random.seed(47) sp_ok = all(spacing_form([random.randint(1, 9) for _ in range(random.randint(2, 12))]) for _ in range(2000)) ct_ok = all(count_form([random.random() for _ in range(random.randint(2, 15))], random.random()) for _ in range(2000)) print("spacing form, 2000 random cyclic integer gap words, D in 2..12, all m: ", "all equal" if sp_ok else "COUNTEREXAMPLE") print("count form, 2000 random point sets on the circle, N in 2..15, random h: ", "all equal" if ct_ok else "COUNTEREXAMPLE")