"""Compute the minimum nonnegative mass for rational last-copy twins on N=2,3,4,6. The support lemma in proof.txt reduces N=4 and 6 to the shapes below. At fixed mass the second deck of such a shape is determined by its sum of squares. So compare dihedral classes with that same sum of squares. """ from itertools import combinations_with_replacement, product def canonical(t): return min(q[i:] + q[:i] for q in (t,t[::-1]) for i in range(len(t))) def rings(n, mass): if n <= 3: # D2 and D3 are the full permutation groups. yield from (t for t in combinations_with_replacement(range(mass+1), n) if sum(t) == mass) elif n == 4 and mass % 2 == 0: p = mass // 2 for a,b in product(range(p+1), repeat=2): yield (a,b,p-a,p-b) elif n == 6 and mass % 6 == 0: c = mass // 6 for u,v in product(range(-c,c+1), repeat=2): if abs(v-u) <= c: yield (c+u,c+v,c+v-u,c-u,c-v,c+u-v) def collisions(n, mass): bins = {} for t in rings(n,mass): key = sum(w*w for w in t) if n>=3 else 0 bins.setdefault(key,set()).add(canonical(t)) return [tuple(sorted(group)) for group in bins.values() if len(group)>1] def first(n, cap): for mass in range(cap+1): twins = collisions(n, mass) if twins: return mass, twins return None if __name__ == '__main__': for n, cap, A, B in [(2,2,(0,2),(1,1)), (3,6,(0,3,3),(1,1,4)), (4,14,(0,3,7,4),(1,1,6,6)), (6,48,(1,1,8,15,15,8),(0,3,11,16,13,5))]: mass, pairs = first(n,cap) assert (mass,pairs) == (cap,[tuple(sorted(map(canonical,(A,B))))]) print(f'N={n}: minimum mass {mass}; positive minimum {mass+n}; {pairs[0]}') assert [m for m in range(15) if collisions(3,m)] == [6,9,12,13,14] for m, A, B in [(13,(0,5,8),(2,2,9)), (14,(0,7,7),(1,4,9))]: assert any({A,B} <= set(pair) for pair in collisions(3,m)) assert [m for m in range(21) if collisions(4,m)] == [14,18,20] print('N=3 and N=4: finite mass-spectrum base cases pass')