"""Replay the algebraic ingredients of the rank-seven mean-growth lower bound.""" from collections import Counter from fractions import Fraction as F from itertools import product import json from math import prod import random def determinant(a): return a[0]*a[3] - a[1]*a[2] def mm(a, b): return tuple(a[2*i]*b[j] + a[2*i+1]*b[2+j] for i,j in product(range(2),repeat=2)) def inverse(a): return tuple(x/determinant(a) for x in (a[3],-a[1],-a[2],a[0])) def norm(a): return sum(map(abs,a)) def tensor_check(terms): # Coefficient matrices are in cyclic trace order, including transposed output. for i,j,h in product(range(4),repeat=3): target = int(i%2==j//2 and j%2==h//2 and h%2==i//2) assert sum(u[i]*v[j]*w[h] for u,v,w in terms)==target def canonical_line(v): return tuple(-x for x in v) if next(x for x in v if x)<0 else tuple(v) def lines(a): i = next(k for k,x in enumerate(a) if x) r,c = divmod(i,2) col = [a[c],a[2+c]] row = [a[2*r+j]/a[i] for j in range(2)] assert tuple(x*y for x in col for y in row)==a return canonical_line(col),canonical_line(row) def triangle_mass(a): u = (a[0],a[2]) v = (a[1],a[3]) return norm(u)*norm(v)*norm([u[0]-v[0],u[1]-v[1]]) def run(): raw = [[[1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1]], [[0, 0, 1, 1], [1, 0, 0, 0], [0, 1, 0, -1]], [[1, 0, 0, 0], [0, 1, 0, -1], [0, 0, 1, 1]], [[0, 0, 0, 1], [-1, 0, 1, 0], [1, 1, 0, 0]], [[1, 1, 0, 0], [0, 0, 0, 1], [-1, 0, 1, 0]], [[-1, 0, 1, 0], [1, 1, 0, 0], [0, 0, 0, 1]], [[0, 1, 0, -1], [0, 0, 1, 1], [1, 0, 0, 0]]] terms = [tuple(tuple(map(F, factor)) for factor in triple) for triple in raw] tensor_check(terms) identity=(F(1),F(0),F(0),F(1)) assert terms[0]==(identity,)*3 ex,ey=(1,0),(0,1) for site in range(3): col=Counter(lines(term[site])[0] for term in terms[1:]) row=Counter(lines(term[(site-1)%3])[1] for term in terms[1:]) assert col==Counter({ex:2,ey:2,(1,-1):2}) assert row==Counter({ex:2,ey:2,(1,1):2}) rng=random.Random(93201) def frame(): while True: a=tuple(F(rng.randint(-6,6),rng.randint(1,5)) for _ in range(4)) if determinant(a):return a for case in range(101): bases=[identity]*3 if case==0 else [frame() for _ in range(3)] inv=[inverse(a) for a in bases] changed=[tuple(mm(mm(bases[i],term[i]),inv[(i+1)%3]) for i in range(3)) for term in terms] tensor_check(changed) mass=[prod(norm(a) for a in term) for term in changed] scale=prod(triangle_mass(a)**4/determinant(a)**6 for a in bases) assert prod(mass[1:])==scale and scale>=16**3 and mass[0]>=8 and sum(mass)>=32 if case==0: assert mass==[8,4,4,4,4,4,4] b=[[norm(u)*norm(v)*abs(w[2*(i%2)+i//2]) for u,v,w in changed] for i in range(4)] assert [sum(row) for row in b]==[12,4,4,12] and max(map(max,b))==4 return dict(tensor_identities=101,nonidentity_rational_orbits=100, rank_one_product_floor=16**3,rank_one_sum_floor=24, full_rank_term_floor=8,attained_mass=32,attained_mean=8,largest_single_weight=4) if __name__=='__main__': print(json.dumps(run(),indent=2))