Companion to "Pfaffian Point Processes for Two Classes of Random Plane Partitions"
from itertools import combinations1from itertools import product2load('mat_to_list.sage')345############################################################6#### Conversion Tools7############################################################8910def array_to_tsscpp(A):11"""12array_to_tsscpp(A)1314Takes a TSSCPP array (see Section 6.2 of "Proofs and15Confirmations" by David M. Bressoud), and returns the16encoded TSSCPP in the form of a 2n-by-2n "bird's-eye17view" matrix1819Inputs20A: An n-by-n integer matrix encoding a TSSCPP array2122Output23M: a 2n-by-2n bird's-eye view matrix of the TSSCPP24encoded in A25"""26n = A.ncols()27M = matrix(ZZ, 2*n, 2*n)2829# set the top-left quadrant30M[0:n, 0:n] = n31for i in [0..n-1]:32# fill in blocks belonging to ith shell33for j in [0..n-1]:34a = A[i,j]35k = (a-1)/236if a != 0:37M[j,j] = M[j,j] + 138for l in [1..k]:39M[j+l,j] = M[j+l,j] + 140M[j,j+l] = M[j,j+l] + 141# fill in blocks belonging to previous shells42for l in [0..n-1]:43for m in [0..n-1]:44if l <= i-1 or m <= i-1:45M[l,m] = M[l,m] + 14647# set diagonal48for l in [0..2*n-1]:49M[l,2*n-1-l] = n5051# set bottom-right quadrant52for l in [0..n-1]:53for m in [0..n-1]:54M[n+l,n+m] = 2*n - M[n-1-l,n-1-m]5556# set remaining off-diagonal entries57for l in [0..n-2]:58for m in [0..n-l-2]:59c = 060for r in [0..n-1]:61if M[2*n-r-1, n+m] <= l:62c = c + 163else:64break65M[l, n+m] = 2*n - c66M[n+m, l] = 2*n - c67M[n-m-1, 2*n-l-1] = c68M[2*n-l-1, n-m-1] = c69return(M)7071def tsscpp_to_array(M):72"""73tsscpp_to_array(M)7475Takes a TSSCPP in the form of a bird's-eye view matrix76M and returns the TSSCPP array that encodes M. Is the77inverse of function array_to_tsscpp(A)7879Arguments80M: A 2n-by-2n bird's-eye view matrix of the TSSCPP8182Outputs83A: An n-by-n TSSCPP array encoding M84"""8586n = M.nrows()/287A = Matrix(ZZ, n, n)8889for i in [0..n-1]:90partial_shell = Matrix(ZZ, n-i, n-i)91for l in [0..n-i-1]:92for m in [0..n-i-1]:93if M[l+i,m+i] >= 2*n - i:94partial_shell[l,m] = 19596for l in [0..n-i-1]:97if partial_shell[l,l] == 1:98counter = 199for m in [l+1..n-i-1]:100if partial_shell[l,m] == 1:101counter = counter + 1102else:103break104A[i,i+l] = 2*counter - 1105return(A)106107def plot_tsscpp(M, color_1='ghostwhite', color_2='lightsteelblue', color_3='slategrey'):108"""109plot_tsscpp(M)110111Takes a TSSCPP in the form of a bird's-eye-view matrix M112and prints a plot of the TSSCPP113114Inputs:115M: A 2n-by-2n bird's-eye view matrix of the TSSCPP116color_1: Color of lozenge 1117color_2: Color of lozenge 2118color_3: Color of lozenge 3119120Output:121(None; prints graphics object)122"""123124PPlist = mat_to_list(M)125PP = PlanePartition(PPlist)126return(PP.plot(show_box=True, colors=[color_1, color_2, color_3]))127128def array_to_nilp(A, line_color='blue'):129"""130array_to_nilp(A)131132Takes a TSSCPP array and returns a plot (as a graphics133object) of the nest of NILP's associated to the TSSCPP134135Inputs:136A: An n-by-n integer matrix encoding a TSSCPP array137line_color: Name of the color of the paths138139Output:140plot_frame: plot of the nest of NILP's141"""142143n = A.nrows()144if 2*n-2 <= 12:145step = 2146else:147step = 5148149verts = [[0,0], [n-1,2*n-2], [2*n-2,2*n-2]]150marks = [1 .. 2*n-2]151labels = ['${0}$'.format(i) if i % step == 0 else '' for i in [1 .. 2*n-2]]152153plot_frame = polygon(verts, color='black', fill=False, gridlines='major',154ticks=[marks, marks], tick_formatter=[labels, labels])155line_weight = 2156157for ii in [1 .. n-1]:158num_entries = 0159for kk in [ii .. n-1]:160if A[ii-1, kk] != 0:161num_entries += 1162else:163break164165x_start = n-ii166y_start = 2*(n-ii)167line_points = [(x_start, y_start)]168169if num_entries == 0:170line_points.append((y_start, y_start))171else:172for kk in [1 .. num_entries]:173entry = A[ii-1, ii-1+kk]174dist = (entry + 1)/2175x_upper = 2*x_start - (kk-1) - dist176y_upper = 2*x_start - (kk-1)177line_points.append((x_upper, y_upper))178line_points.append((x_upper, y_upper-1))179if kk == num_entries and x_upper != y_upper-1:180line_points.append((y_upper-1, y_upper-1))181182plot_line = line(line_points, color=line_color, thickness=line_weight, alpha=1.0)183plot_frame += plot_line184return(plot_frame)185186187############################################################188#### Creation Tools189############################################################190191192def powerset_ordered(S):193"""194Produces the power set (the collection of all subsets)195of a set S196197Inputs:198S: A finite set, as a list of integers199200Output:201powerset: The power set of S, as a list whose elements202are the subsets of S, also as lists203"""204powerset = []205206size = len(S)207for n_elems in [0..size]:208if n_elems == 0:209powerset.append([])210else:211combs = list(combinations(S, n_elems))212n_combs = binomial(size, n_elems)213for i in [0..n_combs-1]:214combs[i] = list(combs[i])215powerset.extend(combs)216return(powerset)217218def make_tsscpp_row(n, i):219"""220make_tsscpp_row(n,i)221222Intermediate generator used in finding all TSSCPP's223of order n. This function takes the order of a TSSCPP224and a row number i and uses an iterator whose elements225are all possibilities for row i+1 of an n-by-n TSSCPP226array227228Inputs229n: Order of the TSSCPP230i: Row number minus 1 (for purposes of looping)231232Generates233r: Possible row i+1 for a TSSCPP array of order234n235"""236237if i == n-1:238r = [0 for j in [1..n]]239r[i] = 2*n - 2*i - 1240yield(r)241return242243trailing_vals = [-1 + 2*j for j in [1..n-i-1]]244P = powerset_ordered(trailing_vals)245P.reverse()246for subset in P:247subset.reverse()248r = [0 for j in [1..n]]249r[i] = 2*n - 2*i - 1250m = len(subset)251if m == 0:252yield(r)253else:254for k in [1..m]:255r[i+k] = subset[k-1]256yield(r)257258def make_all_rows(n):259"""260make_all_rows(n)261262Intermediate function that combines all lists of263possible rows for the TSCPP's of order n264265Inputs266n: Order of the TSSCPP267268Outputs269all_rows: A list where each element i (i from 0 to n-1)270is a list of all possible rows for row i+1 of271a TSSCPP array of order n272"""273274all_rows = []275for i in [0 .. n-1]:276all_rows.append(list(make_tsscpp_row(n, i)))277return(all_rows)278279def make_all_tsscpp_arrays(n):280"""281make_all_tsscpp_arrays(n):282283Creates a list of all TSSCPP arrays of order n284285Inputs286n: Order of the TSSCPP array287288Outputs289all_mats: List of all TSSCPP arrays of order n290"""291292all_mats = []293R = make_all_rows(n)294raw_mats = list(product(*R))295296for M in raw_mats:297mat = []298for i in [0..n-1]:299mat.append(M[i])300301i=1302while 1 <= i and i <= n-1:303j=i304while i <= j and j <= n-1:305if mat[i-1][j] != 0 and mat[i][j] == 0:306i = n307j = n308break309if mat[i-1][j] > mat[i][j]:310i = n311j = n312break313if i == n-1 and j == n-1:314all_mats.append(Matrix(ZZ, mat))315j = j+1316i = i+1317return(all_mats)318319