Path: blob/main/GeneratingDiagonalsViaShift/multiplihedra.py
1017 views
'''1Code for comparing SU and LA diagonal of multiplehdra.2The multipledra filter is code of Guillaume's from,3https://cocalc.com/projects/4ffaeb4c-c563-4526-8bbc-3d75298931c9/files/Multiplihedron_diagonal.ipynb#id=9291484'''5from itertools import combinations67from diagonals_via_shift import SU_diag, LA_diag8910def ordered_partitions(a, k):11'''Splits a into k ordered partitions'''12n = len(a)13assert 1 <= k <= n, (n, k)1415def split_at(js):16i = 01718for j in js:19yield a[i:j]20i = j2122yield a[i:]2324for separations in combinations(range(1, n), k - 1):25yield list(split_at(separations))2627def all_to_right(element,j):28m = []29for x in element[j+1:]:30m = m + x31return m3233def op_mult_filter(n, element):34'''35return: True if the ordered partition hits, False if not36'''37for j in range(len(element)-1):#for each block in the ordered partition / chosen face38if len(element[j])==1 or (n in element[j]):39continue4041que = all_to_right(element,j)4243OSP=list(ordered_partitions(element[j],2)) #all ordered partitions of this block into two pieces44for k in range(len(OSP)):#for each block bipartition45for x in que: #for each element in the queue46if min(element[j]) < x and x < max(element[j]):47#if ((max(OSP[k][0]) < x) and (x < min(OSP[k][1]))) or ((max(OSP[k][1]) < x) and (x < min(OSP[k][0]))):48#print(OSP[k][0],OSP[k][1])49return False5051return True525354def LA_Mult_diag(n):55valid = []56for p in LA_diag(n):57if op_mult_filter(n, p[0]) and op_mult_filter(n, p[1]):58valid.append(p)5960return valid6162def SU_Mult_diag(n):63valid = []64for p in SU_diag(n):65if op_mult_filter(n, p[0]) and op_mult_filter(n, p[1]):66valid.append(p)6768return valid6970def compare(n):71LA = sorted(LA_Mult_diag(n))72SU = sorted(SU_Mult_diag(n))7374LA_only = []75SU_only = []76shared = []77for x in LA:78if x in SU:79shared.append(x)80else:81LA_only.append(x)82for x in SU:83if x not in LA:84SU_only.append(x)8586return LA, LA_only, shared, SU_only, SU878889def iso1(p):90'''91Applies the iso t(s x s)92'''93return [p[1][::-1],p[0][::-1]]9495def iso2(p,n):96'''97Applies the iso t(r x r)98'''99def r(op,n):100rev = []101for block in op:102revblock = []103for x in block:104revblock.append(n-x+1)105rev.append(sorted(revblock))106return rev107108return [r(p[1],n),r(p[0],n)]109110if __name__ == '__main__':111112print(iso2([[[1,3],[2,4]],[[1,3],[2,4]]],4))113114for n in range(1,7):115print("\nn={}".format(n))116LA, LA_only, shared, SU_only, SU = compare(n)117118print("|LA|={}, |LA only|={}, |shared|={}, |SU only|={}, |SU|={}".format(119len(LA), len(LA_only), len(shared), len(SU_only), len(SU)))120121'''122#ILA = [iso1(x) for x in LA]123ILA = [iso2(x,n) for x in LA]124125ILA_only = []126SU_only = []127shared = []128for x in ILA:129if x in SU:130shared.append(x)131else:132ILA_only.append(x)133for x in SU:134if x not in ILA:135SU_only.append(x)136137print(len(ILA_only),len(shared),len(SU_only))138'''139140