# walshcheck.py -- brute force check of Proposition 7.3 (Walsh matrix W_16 with the rows of a set S deleted): the number # R(H) of sign rows orthogonal to the remaining rows, and the number C(H) of ordered completions, for several S. import numpy as np, itertools from functools import lru_cache d=4; N=2**d X=np.array([[(-1)**bin(a&x).count('1') for x in range(N)] for a in range(N)]) V=np.array(list(itertools.product((1,-1),repeat=N))) @lru_cache(maxsize=None) def R(rows): return V[np.all(V @ X[list(rows)].T == 0, axis=1)] if rows else V @lru_cache(maxsize=None) def C(rows,depth): if depth==0: return 1 tot=0 for v in R(rows): k=next(a for a in range(N) if abs(X[a]@v)==N) tot+=C(tuple(sorted(rows+(k,))),depth-1) return tot for S in ([1,2,4,8],[1,2,3],[0,5,10],[1,2,4,7]): rest=tuple(a for a in range(N) if a not in S) sums=[a^b for a,b in itertools.combinations(S,2)]; sidon=len(sums)==len(set(sums)) r=len(R(rest)); c=C(rest,len(S)) if sidon else None if sidon: assert r == 2*len(S) assert c == 2**len(S)*int(np.prod(range(1,len(S)+1))) else: assert r == 16 print(f"S = {S}: distinct pair sums {sidon}, R(H) = {r} (2|S| = {2*len(S)})" + (f", C(H) = {c} (2^|S| |S|! = {2**len(S)*int(np.prod(range(1,len(S)+1)))})" if sidon else ""))