def print_query(query, families=False, pad=1): if type(query) in (sqlite3.Cursor, list): longest = "" results = [] for q in query: results.append(q) longest = max((q[1], longest), key=len) # to ensure proper padding for r in results: print_query(r, families=families, pad=len(longest)) return n, p_str, sol = query family = "" if families: _p = Partition(*map(int, p_str.split(","))) if _p.is_one_dimensional(): family = "[1D]" if _p.is_hook(): family = "[HOOK]" elif _p.is_self_conjugate(): family = "[SELF-CONJ]" print u"{:{pad}} \u22a2 {:2}: solution {} {}".format("(" + p_str + ")", n, sol, family, pad=pad + 2).encode("utf-8")
def find_solution(shape, verbose=False, skip_known_families=True, return_matrix=False): if type(shape) is Partition: shape = shape.vals if skip_known_families: p = Partition(*shape) if p.is_one_dimensional(): if verbose: print "Skipping 1D partition" return 1 elif p.is_self_conjugate(): if verbose: print "Skipping self-conjugate partition" return 0 elif p.is_hook(): if verbose: print "Skipping hook partition" i = sum(p.vals) r = p.vals[1:].count(1) choose = factorial(i - 1) / (factorial(r) * factorial(i - 1 - r)) if (i % 2, r % 2, choose % 2) == (1, 0, 1): return 1 else: return 0 if shape == (1, ): # isolate this case to avoid numpy exception when building matrix return 1 if verbose: print "Generating all standard {}-tableaux...\n".format(shape) polys = [] if verbose: print "-" * 20 for t in [t for t in total_order(shape)][::-1]: standards = [t] #if verbose: # print "Next tableaux:\n{}\n".format(t) poly = set([tab for tab in t.polytabloid() if tab != t]) if len(poly) > 1: for s in poly: if s.vals != t.vals: print "{} --> {}".format(t.vals, s.vals) standards.append(s) polys.append(standards) columns = [] if verbose: print "Creating matrix from polytabloids." for i, poly in enumerate(polys): vec = [0] * len(polys) vec[i] = 1 if len(poly) > 1: for s in poly: #find the index of the standard tableaux x = [l[0] for l in polys].index(s) vec[x] = 1 columns.append(vec) matrix = column_stack(columns) if return_matrix: print matrix return matrix if verbose: print matrix solution = map(int, linalg.solve(matrix, [1] * len(polys))) if verbose: print "Solution vector: {}".format(solution) print "Sum of standard coefficients is congruent to {} (mod 2).".format( sum(solution) % 2) return sum(solution)