"""One-diagram factors and direct Gram checks for the sharp bistochastic groups.""" from fractions import Fraction from math import prod from verify import blocks, chebyshev, gram_det, insertion_shape, join_size, noncrossing, partitions def sharp_factor(word, x, free): parts = blocks(word) pairs = [p for p in parts if len(p) == 2] singletons = len(word) - 2*len(pairs) if len(word) % 2 or any(len(p) > 2 for p in parts) or any((a-b)%2 == 0 for a,b in pairs): raise ValueError("Not a sharp diagram") if free and not noncrossing(word): raise ValueError("Crossing in free sharp diagram") if not free: partners = dict(p if p[0]%2 == 0 else p[::-1] for p in pairs) shape = insertion_shape([partners[a] for a in sorted(partners)]) return x**singletons * prod(x-1+j-i for i,row in enumerate(shape) for j in range(row)) ends = sorted(a for p in pairs for a in p) colors = {a:(a-i)%2 for i,a in enumerate(ends)} stack = [] result = Fraction(x**singletons) for a in ends: if not stack or word[a] != stack[-1][0]: run = stack[-1][2]+1 if stack and colors[a] == stack[-1][1] else 1 stack.append((word[a],colors[a],run)) else: _,_,run = stack.pop() result *= Fraction(chebyshev(run,x-1),chebyshev(run-1,x-1)) return result def direct_mod(words, x, p): rows = [[pow(x,join_size(a,b),p) for b in words] for a in words] result = 1 for i, row in enumerate(rows): if not row[i]: j = next((h for h in range(i+1,len(rows)) if rows[h][i]),None) if j is None: return 0 rows[i], rows[j] = rows[j], row row = rows[i] result = -result result = result*row[i]%p inverse = pow(row[i],-1,p) for h in range(i+1,len(rows)): scale = rows[h][i]*inverse%p if scale: for j in range(i+1,len(rows)): rows[h][j] = (rows[h][j]-scale*row[j])%p return result if __name__ == "__main__": for k in (0,2,4,6,8): allowed = [w for w in partitions(k) if all(len(p)==1 or (len(p)==2 and (p[0]-p[1])%2) for p in blocks(w))] for free in (False,True): words = [w for w in allowed if not free or noncrossing(w)] for x in (4,7): predicted = Fraction(prod(sharp_factor(w,x,free) for w in words)) assert predicted.denominator == 1 if k < 8: assert predicted == gram_det(words,x) else: for p in (1009,1013): assert predicted.numerator%p == direct_mod(words,x,p) print("B#"+("+" if free else "*"), "degree",k,"diagrams",len(words), "verified at 4 and 7", "over Z" if k<8 else "modulo 1009 and 1013")