"""Exact arithmetic checks for the five-partition theorem. Run with Python 3.8+ (standard library). A site's bit word records its side on each of the five cuts. A five-dimensional Gram system constructs the contraction between the two regular-simplex spaces. """ from fractions import Fraction as Q from math import isqrt from functools import lru_cache from itertools import permutations, product ORDERS = tuple(permutations(range(5))) EXCEPTION = ((0, 3, 5, 25), (10, 12, 15, 22)) def site_words(size, columns): return tuple(sorted(sum((i in subset) << j for j, subset in enumerate(columns)) for i in range(size))) def basic_shapes(size): if size == 5: return {site_words(5, [(i,) for i in range(5)])} shapes = {site_words(size, [(i,) for i in indices]) for indices in product(range(size), repeat=5) if len(set(indices)) == size} if size == 4: for j in range(5): for order in permutations(range(4)): for partner in (1, 2, 3): columns = [(i,) for i in order] columns.insert(j, (0, partner)) shapes.add(site_words(4, columns)) return shapes def flip(words, mask): return tuple(sorted(x ^ mask for x in words)) @lru_cache(None) def reorder(words, order): return tuple(sorted(sum(((x >> i) & 1) << j for j, i in enumerate(order)) for x in words)) def representatives(k, l): first = {flip(a, s) for a in basic_shapes(k) for s in range(32)} second = {flip(b, s) for b in basic_shapes(l) for s in range(32)} while first: a = min(first) images = {(order, s): flip(reorder(a, order), s) for order in ORDERS for s in range(32)} first.difference_update(images.values()) stabilizer = [g for g in images if images[g] == a] remaining = second.copy() while remaining: b = min(remaining) yield a, b remaining.difference_update(flip(reorder(b, order), s) for order, s in stabilizer) def deletable(a, b): for j in range(5): for side in (0, 1): retained = [[x for x in block if (x >> j) & 1 == side] for block in (a, b)] if all(0 < sum((x >> i) & 1 for x in block) < len(block) for block in retained for i in range(5) if i != j): return True return False def determinant(rows): if not rows: return 1 return sum((-1)**j * x * determinant([r[:j]+r[j+1:] for r in rows[1:]]) for j, x in enumerate(rows[0])) def cut_vector(words, j): bits = [(x >> j) & 1 for x in words] count = sum(bits) return [len(bits)*value-count for value in bits] def dot(x, y): return sum(a*b for a, b in zip(x, y)) def uniform_contraction(a, b): k, l = len(a), len(b) x = [cut_vector(a, j) for j in range(5)] y = [cut_vector(b, j) for j in range(5)] offset = [Q(8*dot(u, u), k**4) + Q(8*dot(v, v), l**4) for u, v in zip(x, y)] scale = Q(16, (k*l)**2) rhs = [(Q(101, 100)-s)/scale for s in offset] system = [[int(i == j) + dot(x[i], x[j])*dot(y[i], y[j]) for j in range(5)] for i in range(5)] denominator = determinant(system) # Cramer's rule for the identity plus the Gram matrix. weights = [determinant([row[:j] + [d] + row[j+1:] for row, d in zip(system, rhs)]) / denominator for j in range(5)] matrix = [[sum(w*u[i]*v[j] for w, u, v in zip(weights, x, y)) for j in range(l)] for i in range(k)] residual = [[int(i == j)-dot(row, other) for j, other in enumerate(matrix)] for i, row in enumerate(matrix)] if any(determinant([row[:m] for row in residual[:m]]) <= 0 for m in range(1, k+1)): return False return all(s + scale*dot(u, [dot(row, v) for row in matrix]) > Q(201, 200) for s, u, v in zip(offset, x, y)) def root_lower(q): k = 10**8 return Q(isqrt(k*k*q.numerator // q.denominator), k) def check_pair_and_three_blocks(): threshold = 1 + Q(1, 20000) assert Q(49, 50)**2 * Q(256, 243) > threshold**2 assert 1 + Q(32, 125*50**2) > threshold**2 triangle_sq, tetra_sq = Q(16, 27), Q(3, 8) assert 2*triangle_sq > Q(117, 100) # One split triangle with the tetrahedron. mixed = root_lower(triangle_sq*tetra_sq) assert triangle_sq + tetra_sq + mixed/10 > Q(101, 100) # Two split triangles, without or with a contribution from the tetrahedron. both = 2*triangle_sq*Q(99, 100) assert both > Q(117, 100) margin = both + tetra_sq - Q(13, 10) assert margin > 0 and margin**2 > Q(4, 10)**2 * triangle_sq/2 def check_exception(): # Ordinary vertices 0,1,2 of A match vertices 2,1,0 of B. # Vertex 3 is the distinguished vertex of each block. spoke = 4*Q(1, 3)*Q(2, 9) edge = 4*Q(2, 9)**2 axial = spoke*Q(4, 5) transverse = edge*root_lower(Q(3)) + spoke*Q(3, 5) a_words, b_words = EXCEPTION for j in range(5): a = [(word >> j) & 1 for word in a_words] b = [(word >> j) & 1 for word in b_words] coeff = [a[i] - b[2-i] for i in range(3)] # The triangle directions have pairwise inner product -1/2. planar_sq = Q(3*dot(coeff, coeff) - sum(coeff)**2, 2) axis_a = 3*a[3] - sum(a[:3]) axis_b = 3*b[3] - sum(b[:3]) assert planar_sq*transverse**2 + (axis_a**2 + axis_b**2)*axial**2 > Q(101, 100) def check_three_four(): x, u = Q(652,1000), Q(1455,10000) yA, yB, c = Q(885,1000), Q(695,1000), Q(43,100) sA, sB = 2*x*(1-x), 4*u*(1-u)/3 a, b = sA*yA, sB*yB T = x*x + sA*root_lower(1-yA*yA) H = root_lower(Q(3))*4*(1-u)**2/9 + sB*root_lower(1-yB*yB) As = [(4*a*a, 2*a), (T*T+a*a, -a)] Bs = [(9*b*b, 3*b), (H*H+b*b, -b), (H*H+4*b*b, -2*b)] rows = [] for a2, au in As: for b2, bv in Bs: rows.append([int(10000*(a2+b2+sign*2*au*bv*c)) for sign in (1,-1)]) assert rows == [[10033,5258], [10429,12021], [10032,13215], [5663,8051], [10834,10038], [11630,10039]] def main(): check_pair_and_three_blocks() check_three_four() check_exception() print('Verified the geometric bounds for a retained pair, three blocks, and the exceptional pair.') for (k, l), expected in [((3, 5), (24, 14, 10, 0)), ((4, 4), (248, 189, 58, 1)), ((4, 5), (21, 17, 4, 0)), ((5, 5), (6, 5, 1, 0))]: counts = [0, 0, 0, 0] for a, b in representatives(k, l): counts[0] += 1 if deletable(a, b): counts[1] += 1 elif uniform_contraction(a, b): counts[2] += 1 else: assert (a, b) == EXCEPTION counts[3] += 1 assert tuple(counts) == expected print((k, l), tuple(counts)) print('All 73 Gram constructions verified over the rationals.') if __name__ == '__main__': main()