Datasets:
File size: 2,432 Bytes
0dd9df7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | """Cross-check the lower-threshold algorithm against two-sided principal minors."""
from fractions import Fraction
from itertools import combinations, product
import json
from low_threshold import count_below_limit
def determinant(matrix):
if not matrix:
return 1
return sum(
(-1)**j * entry * determinant([r[:j] + r[j+1:] for r in matrix[1:]])
for j, entry in enumerate(matrix[0])
)
def brute(order, edges, threshold):
subsets = [subset for size in range(1, order + 1)
for subset in combinations(range(order), size)]
def all_minors(signs, direction):
matrix = [[threshold.numerator * (u == v) for v in range(order)] for u in range(order)]
for (u, v), sign in zip(edges, signs):
matrix[u][v] = matrix[v][u] = direction * sign * threshold.denominator
for subset in subsets:
if determinant([[matrix[i][j] for j in subset] for i in subset]) < 0:
return False
return True
return sum(
all(all_minors(signs, direction) for direction in (-1, 1))
for signs in product((-1, 1), repeat=len(edges))
)
def main():
all_pairs = list(combinations(range(4), 2))
checked = unknown = 0
for mask in range(1 << len(all_pairs)):
edges = [p for j, p in enumerate(all_pairs) if mask >> j & 1]
for t in map(Fraction, ('0', '1', '3/2', '2', '21/10')):
value = count_below_limit(4, edges, t)
if value is None:
unknown += 1
else:
assert value == brute(4, edges, t)
checked += 1
triangle = [(0, 1), (1, 2), (2, 0)]
# Every signed triangle has radius two regardless of its cycle product.
assert count_below_limit(3, triangle, Fraction(3, 2)) == 0
assert count_below_limit(3, triangle, Fraction(2)) == 8
theta = []
cursor = 2
for _ in range(3):
route = [0, *range(cursor, cursor+13), 1]
cursor += 13
theta.extend(zip(route, route[1:]))
assert count_below_limit(cursor, theta, Fraction(21, 10)) == 0
print(json.dumps(dict(exact_small_counts=checked, outside_structural_test=unknown,
signed_triangle={"at_3/2": 0, "at_2": 8},
large_girth_theta=dict(girth=28, threshold="21/10", count=0)),
indent=2, sort_keys=True))
if __name__ == "__main__":
main()
|