"""Finite sign checks for the five-player equilibrium bound. Python 3.9+.""" from itertools import combinations, product def preferred_action(pattern, vertex, player): # Four signs per player, in binary order of the other two actions. opponents = (vertex & ((1 << player) - 1)) | ((vertex >> (player + 1)) << player) return (pattern >> (4 * player + opponents)) & 1 def greatest_face_weight(pattern): """Upper-bound c0 + 2*c2 + 6*c3 on a three-player restriction.""" vertices = range(8) pure_count = sum( all(preferred_action(pattern, v, i) == ((v >> i) & 1) for i in range(3)) for v in vertices ) positive_squares = negative_squares = 0 for fixed in range(3): i, j = (k for k in range(3) if k != fixed) for action in (0, 1): v = action << fixed i_up = preferred_action(pattern, v | (1 << j), i) j_up = preferred_action(pattern, v | (1 << i), j) if i_up == preferred_action(pattern, v, i) or j_up == preferred_action(pattern, v, j): continue # A strict best reply of the fixed player requires the correct # sign at some corner, by bilinear interpolation. corners = [v | (a << i) | (b << j) for a, b in product(range(2), repeat=2)] if all(preferred_action(pattern, corner, fixed) != action for corner in corners): continue if i_up == j_up: negative_squares += 1 else: positive_squares += 1 upper = 0 for pos in range(positive_squares + 1): for neg in range(negative_squares + 1): # The two interior equilibria, when both exist, have opposite indices. for interior, signed in ((0, 0), (1, 1), (1, -1), (2, 0)): if pure_count + pos - neg + signed == 1: upper = max(upper, pure_count + 2 * (pos + neg) + 6 * interior) return upper def count_nonconstant_squares(): """Count nonconstant square faces for each Boolean function of four bits.""" square_masks = [] for i, j in combinations(range(4), 2): for v in range(16): if v & ((1 << i) | (1 << j)): continue vertices = [v | (a << i) | (b << j) for a, b in product(range(2), repeat=2)] square_masks.append(sum(1 << w for w in vertices)) assert len(set(square_masks)) == 24 return min( sum((truth_table & square) not in (0, square) for square in square_masks) for truth_table in range(1, (1 << 16) - 1) ) if __name__ == "__main__": weights = [greatest_face_weight(pattern) for pattern in range(1 << 12)] assert max(weights) == 22 tight = [index for index, weight in enumerate(weights) if weight == 22] # The rows 0110 and 1001 are the two checkerboards on two bits. checkerboards = {a | (b << 4) | (c << 8) for a, b, c in product((6, 9), repeat=3)} assert set(tight) == checkerboards minimum = count_nonconstant_squares() assert minimum == 6 print("Tight sign patterns among 4096:", " ".join(f"{n:03x}" for n in tight)) print("Minimum nonconstant squares among 65534 nonconstant truth tables:", minimum)