# Section 8: upper bounds for Tr|S|, for the sign matrices S of order N. For N odd the bound is (N-1) sqrt(N-1) + sqrt(2N-1), # and for N = 2 modulo 4 it is (N-2) sqrt(N-2) + 2 sqrt(2N-2), in analogy with the bounds of Barba and of Ehlich and Wojtas for # the determinant. We compare these bounds with the best values that we know, we check in exact arithmetic that they are attained # at N = 5, 6, 10, 13, 14, we test the inequalities behind the proof, and we compare with the determinants at N = 7. # Usage: python3 bounds.py import numpy as np from optimal import charpoly, product, matrix, FIVE, SIX, SEVEN, NEXT from designs import incidence FOURTEEN = [[1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, -1, -1, -1], [-1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1], [-1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, 1, -1], [1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1], [1, 1, -1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, 1], [1, -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1], [-1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1], [1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1], [1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1], [1, 1, 1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, 1], [-1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1], [-1, 1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, 1], [-1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1], [-1, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1]] def bound(n): if n % 4 == 0: return n ** 1.5 if n % 2 == 1: return (n - 1) ** 1.5 + (2 * n - 1) ** .5 return (n - 2) ** 1.5 + 2 * (2 * n - 2) ** .5 def gram(S): return [[int(x) for x in row] for row in np.array(S) @ np.array(S).T] def norm(S): return np.linalg.svd(np.array(S, float), compute_uv=False).sum() if __name__ == "__main__": K = np.ones((5, 5), dtype=int) - 2 * np.eye(5, dtype=int) # the sign matrix of K_5: -1 on the diagonal, 1 outside TEN = np.kron(K, np.array([[1, 1], [1, -1]])) THIRTEEN = 2 * incidence(13, [0, 1, 3, 9]).astype(int) - 1 exact = {5: (K, [([1, -4], 4), ([1, -9], 1)]), 6: (np.array(matrix(SIX)), [([1, -4], 4), ([1, -10], 2)]), 10: (TEN, [([1, -8], 8), ([1, -18], 2)]), 13: (THIRTEEN, [([1, -12], 12), ([1, -25], 1)]), 14: (np.array(FOURTEEN), [([1, -12], 12), ([1, -26], 2)])} best = {3: 5.0, 5: 11.0, 6: 8 + 2 * 10 ** .5, 7: 1 + 12 * 2 ** .5, 9: 2 + 12 * 2 ** .5 + 57 ** .5, 10: 22 * 2 ** .5, 11: 35.700663, 13: 5 + 24 * 3 ** .5, 14: norm(FOURTEEN)} for n in sorted(best): line = "N=%d: upper bound %.6f, best value known %.6f, ratio %.6f" % (n, bound(n), best[n], best[n] / bound(n)) if n in exact: S, factors = exact[n] W, s, Vh = np.linalg.svd(S.astype(float)); U = W @ Vh line += "; bound attained, characteristic polynomial of S S^t as expected: %s, S is the sign matrix of its polar part: %s, |det S| = %d" % (charpoly(gram(S)) == product(factors), bool((np.sign(U) == S).all()), round(abs(np.linalg.det(S.astype(float))))) print(line) # the 2 inequalities behind the proof worst = 0 for (a, b) in [(n - 1, 2 * n - 1) for n in range(3, 40, 2)] + [(n - 2, n - 2 + 2 * m) for n in range(6, 40, 4) for m in range(2, n + 1)]: c = (b ** .5 - a ** .5 - (b - a) / (2 * a ** .5)) / (b - a) ** 2 x = np.linspace(0, b, 2001) worst = max(worst, float((np.sqrt(x) - (a ** .5 + (x - a) / (2 * a ** .5) + c * (x - a) ** 2)).max())) print("quadratic majorant of the square root on [0,b]: largest value of sqrt(x) - q(x) over all the cases tested: %.2e" % worst) np.random.seed(1); viol = 0; closest = 1.0 for n in (5, 6, 7, 9, 10, 11, 13, 14, 15, 18): S = np.sign(np.random.randn(200000 // n, n, n)); v = np.linalg.svd(S, compute_uv=False).sum(1) viol += int((v > bound(n) + 1e-9).sum()); closest = min(closest, float((bound(n) - v).min())) print("random sign matrices of orders 5 to 18: %d violations of the bounds, smallest distance to the bound %.3f" % (viol, abs(closest))) print("N=7: |det| of the sign matrix of the Fano plane: %d, of the matrix on the second level: %d" % (round(abs(np.linalg.det(np.array(matrix(SEVEN), float)))), round(abs(np.linalg.det(np.array(matrix(NEXT), float))))))