def _test(n_max, v_max): for n in range(n_max + 1): for v in range(1, v_max + 1): for lam1 in Partition.all(n): for lam2 in Partition.all(n): print() print() print('* v =', v, ', n =', n, ', mu =', lam1, ', nu =', lam2) print() print('Computing LHS . . .') print() s = Polynomial() for mu in Partition.all(n + max(sum(lam1), sum(lam2))): a = SymmetricPolynomial.stable_grothendieck_doublebar( v, mu, lam1).truncate(n).polynomial('x') b = SymmetricPolynomial.dual_stable_grothendieck( v, mu, lam2).truncate(n).polynomial('y') s += (a * b).truncate(n) print(' ', mu, ':', s, '|', a, '|', b) print() print('LHS =', s) print() print() print('Computing RHS . . .') print() f = Polynomial.one() x = Polynomial.x y = Polynomial.y for i in range(1, v + 1): for j in range(1, v + 1): a = x(i) * y(j) term = Polynomial.one() for e in range(1, n + 1): term += a**e f = (f * term).truncate(n) print(' ', ' :', f) print() t = Polynomial() for kappa in Partition.subpartitions(lam2): a = SymmetricPolynomial.stable_grothendieck_doublebar( v, lam2, kappa).truncate(n) b = SymmetricPolynomial.dual_stable_grothendieck( v, lam1, kappa).truncate(n) t += (f * a.polynomial('x') * b.polynomial('y')).truncate(n) print(' ', kappa, ':', t) print() print('RHS =', t) print() print() print('diff =', s - t) print() assert s == t
def test_gq_to_gp_expansion(): # noqa for mu in Partition.all(15, strict=True): print('mu =', mu) print() print(Partition.printable(mu, shifted=True)) print() n = len(mu) q = gq(n, mu) expansion = SymmetricPolynomial.gp_expansion(q) print(' mu =', mu, 'n =', n) print(' expansion =', expansion) assert all(len(nu) == len(mu) for nu in expansion) assert all(Partition.contains(mu, nu) for nu in expansion) # assert all(c % 2**(len(mu) - sum(nu) + sum(mu)) == 0 for nu, c in expansion.items()) expected = {} for a in zero_one_tuples(len(mu)): if not all(mu[i - 1] - a[i - 1] > mu[i] - a[i] for i in range(1, len(a))): continue if not all(mu[i] - a[i] > 0 for i in range(len(a))): continue nu = Partition.trim(tuple(mu[i] - a[i] for i in range(len(a)))) coeff = 2**(len(nu) - sum(a)) * sgn(nu, mu) * BETA**sum(a) assert coeff != 0 expected[nu] = coeff print(' expected =', expected) assert expansion == Vector(expected) print() print()
def test_refined_gq_to_gp_expansion(k=12): # noqa for mu in Partition.all(k, strict=True): print('mu =', mu) print() print(Partition.printable(mu, shifted=True)) print() n = len(mu) q = SymmetricPolynomial._slow_refined_dual_stable_grothendieck_q(n, mu) expected = {} for a in zero_one_tuples(len(mu)): if not all(mu[i - 1] - a[i - 1] > mu[i] - a[i] for i in range(1, len(a))): continue if not all(mu[i] - a[i] > 0 for i in range(len(a))): continue nu = Partition.trim(tuple(mu[i] - a[i] for i in range(len(a)))) coeff = 2**(len(nu) - sum(a)) * sgn(nu, mu) * BETA**sum(a) assert coeff != 0 expected[nu] = coeff print(' expected =', expected) expected = sum([ coeff * SymmetricPolynomial._slow_refined_dual_stable_grothendieck_p( n, nu) for (nu, coeff) in expected.items() ]) print(' =', expected) assert q == expected print() print()
def test_GQ_to_GP_expansion(): # noqa for mu in Partition.all(25, strict=True): print('mu =', mu) print() print(Partition.printable(mu, shifted=True)) print() n = len(mu) q = GQ(n, mu) expansion = SymmetricPolynomial.GP_expansion(q) normalized = Vector({ tuple(nu[i] - mu[i] for i in range(len(mu))): c * sgn(mu, nu) * BETA**(sum(nu) - sum(mu)) / 2**(len(mu) - sum(nu) + sum(mu)) for nu, c in expansion.items() }) unsigned = all(c > 0 for c in normalized.values()) print(' mu =', mu, 'n =', n) print(' expansion =', expansion) print(' normalized expansion =', normalized) assert all(len(nu) == 0 or max(nu) <= 1 for nu in normalized) assert all(len(nu) == len(mu) for nu in expansion) assert all(Partition.contains(nu, mu) for nu in expansion) assert all(c % 2**(len(mu) - sum(nu) + sum(mu)) == 0 for nu, c in expansion.items()) assert unsigned expected = { tuple(mu[i] + a[i] for i in range(len(a))) for a in zero_one_tuples(len(mu)) if all( mu[i - 1] + a[i - 1] > mu[i] + a[i] for i in range(1, len(a))) } print(' expected =', expected) assert set(expansion) == expected print() print()
def test_complement(): nu = () assert Partition.complement(0, nu) == () assert Partition.complement(1, nu) == (1, ) assert Partition.complement(2, nu) == (2, 1) nu = (6, 4, 2, 1) assert Partition.complement(6, nu) == (5, 3)
def skew(w): n = w.rank f = tuple(i for i in range(1, n + 1) if w(i) > i) r = len(f) lam = tuple(w(f[-1]) - r - f[i] + i + 1 for i in range(r)) mu = tuple(w(f[-1]) - r - w(f[i]) + i + 1 for i in range(r)) print(Partition.printable(lam)) print() print(Partition.printable(mu)) return lam, mu
def stable_grothendieck_doublebar(cls, num_variables, mu, nu=(), degree_bound=None): # noqa ans = SymmetricPolynomial() if Partition.contains(mu, nu): for x in Partition.remove_inner_corners(nu): ans += BETA**(sum(nu) - sum(x)) * cls._stable_grothendieck( num_variables, mu, x, degree_bound) return ans
def test_transpose(): mu = () assert Partition.transpose(mu) == mu mu = (1, ) assert Partition.transpose(mu) == mu mu = (2, ) assert Partition.transpose(mu) == (1, 1) mu = (5, 3, 3, 2, 2, 1, 1, 1, 1) assert Partition.transpose(mu) == (9, 5, 3, 1, 1)
def _test_shifted_p(n_max, v_max): for n in range(n_max + 1): for v in range(1, v_max + 1): for lam1 in Partition.all(n, strict=True): for lam2 in Partition.all(n, strict=True): print() print() print('* v =', v, ', n =', n, ', mu =', lam1, ', nu =', lam2) print() print('Computing LHS . . .') print() s = Polynomial() for mu in Partition.all(n + max(sum(lam1), sum(lam2)), strict=True): a = SymmetricPolynomial.stable_grothendieck_p_doublebar( v, mu, lam1).truncate(n).polynomial('x') b = SymmetricPolynomial.dual_stable_grothendieck_q( v, mu, lam2).truncate(n).polynomial('y') s += (a * b).truncate(n) print(' ', mu, ':', s, '|', a, '|', b) print() print('LHS =', s) print() print() print('Computing RHS . . .') print() f = kernel(n, v) print(' ', ' :', f) print() t = Polynomial() for kappa in Partition.subpartitions(lam2, strict=True): a = SymmetricPolynomial.stable_grothendieck_p_doublebar( v, lam2, kappa).truncate(n) b = SymmetricPolynomial.dual_stable_grothendieck_q( v, lam1, kappa).truncate(n) t += (f * a.polynomial('x') * b.polynomial('y')).truncate(n) print(' ', kappa, ':', t) print() print('RHS =', t) print() print() print('diff =', s - t) print() assert s == t
def _slow_vectorize(cls, n, tableaux, signs=None, check=True): dictionary = defaultdict(int) for tab in tableaux: dictionary[tab.weight(n)] += 1 if check: assert all(dictionary[Partition.sort(alpha)] == dictionary[alpha] for alpha in dictionary) return SymmetricPolynomial({ SymmetricMonomial(n, alpha): coeff * (signs if signs else 1)**sum(alpha) for alpha, coeff in dictionary.items() if Partition.is_partition(alpha) })
def test_subpartitions(): assert set(Partition.subpartitions(())) == {()} assert set(Partition.subpartitions([1])) == {(), (1, )} assert set(Partition.subpartitions([1, 1])) == {(), (1, ), (1, 1)} assert set(Partition.subpartitions([2, 1])) == {(), (1, ), (1, 1), (2, ), (2, 1)} assert len(list(Partition.subpartitions([2, 1]))) == 5 assert set(Partition.subpartitions((), True)) == {()} assert set(Partition.subpartitions([1], True)) == {(), (1, )} assert set(Partition.subpartitions([1, 1], True)) == {(), (1, )} assert set(Partition.subpartitions([2, 1], True)) == {(), (1, ), (2, ), (2, 1)} assert len(list(Partition.subpartitions([2, 1], True))) == 4
def test_generate_partitions(): assert set(Partition.generate(0)) == {()} assert set(Partition.generate(1)) == {(1, )} assert set(Partition.generate(2)) == {(1, 1), (2, )} assert set(Partition.generate(3)) == {(1, 1, 1), (2, 1), (3, )} assert set(Partition.generate(4)) == {(1, 1, 1, 1), (2, 1, 1), (2, 2), (3, 1), (4, )} assert set(Partition.generate(4, max_row=0)) == set() assert set(Partition.generate(4, max_row=1)) == {(4, )} assert set(Partition.generate(4, max_row=2)) == {(2, 2), (3, 1), (4, )} assert set(Partition.generate(4, max_row=3)) == {(2, 1, 1), (2, 2), (3, 1), (4, )} assert set(Partition.generate(4, max_row=4)) == {(1, 1, 1, 1), (2, 1, 1), (2, 2), (3, 1), (4, )}
def _slow_transposed_dual_stable_grothendieck_q(cls, num_variables, mu, nu=()): p = 0 for tab in Tableau.semistandard_shifted_marked(num_variables, mu, nu): m = 1 for i in range(1, num_variables + 1): r = len({x for x, y, v in tab if v[0] == i}) c = len({y for x, y, v in tab if v[0] == -i}) a = len({(x, y) for x, y, v in tab if abs(v[0]) == i}) x = Polynomial.x(i) m *= x**(r + c) * (x + 1)**(a - r - c) p += m dictionary = {} for e in p: tup = num_variables * [0] for i in e: tup[i - 1] = e[i] dictionary[tuple(tup)] = p[e] return SymmetricPolynomial({ SymmetricMonomial(num_variables, alpha): coeff * (-BETA**-1)**(sum(alpha)) for alpha, coeff in dictionary.items() if Partition.is_partition(alpha) }) * (-BETA)**(sum(mu) - sum(nu))
def test_skew_GP_positivity(): # noqa k = 10 for mu in Partition.all(k, strict=True): for nu in Partition.all(k, strict=True): if not Partition.contains(mu, nu): continue n = len(mu) f = GP(n, mu, nu) expansion = SymmetricPolynomial.GP_expansion(f) normalized = Vector({ lam: c * BETA**(sum(lam) - sum(mu) + sum(nu)) for lam, c in expansion.items() }) print('GP_{%s/%s}(x_%s) =' % (mu, nu, n), normalized) print() assert all(c > 0 for c in normalized.values())
def get_inv_grassmannian(cls, *mu): assert Partition.is_strict_partition(mu) ans = Permutation() for i in range(len(mu)): ans *= Permutation.transposition(1 + mu[0] - mu[i], i + 1 + mu[0]) w0 = Permutation.longest_element(len(mu) + (mu[0] if mu else 0)) ans = w0 * ans * w0 return ans
def test_staircase_grothendieck_GP_positivity(): # noqa r = 6 for k in range(r): delta = tuple(k - i for i in range(k)) for nu in Partition.all(sum(delta)): if not Partition.contains(delta, nu): continue n = len(delta) f = G(n, delta, nu) expansion = SymmetricPolynomial.GP_expansion(f) normalized = Vector({ lam: c * BETA**(sum(lam) - sum(delta) + sum(nu)) for lam, c in expansion.items() }) print('G_{%s/%s}(x_%s) =' % (delta, nu, n), normalized) print() assert all(c > 0 for c in normalized.values())
def test_find_shifted_corners(): mu = (3, 2, 1) assert Partition.find_shifted_inner_corner(mu, 0) == 3 assert Partition.find_shifted_inner_corner(mu, 1) is None assert Partition.find_shifted_inner_corner(mu, 2) is None assert Partition.find_shifted_outer_corner(mu, 0) is None assert Partition.find_shifted_outer_corner(mu, 1) is None assert Partition.find_shifted_outer_corner(mu, 2) is None assert Partition.find_shifted_outer_corner(mu, 3) == 1
def get_fpf_grassmannian(cls, *mu): assert Partition.is_strict_partition(mu) ans = Permutation() o = 1 if (mu and (len(mu) + 1 + mu[0]) % 2 != 0) else 0 for i in range(len(mu)): ans *= Permutation.transposition(o + 1 + mu[0] - mu[i], o + i + 2 + mu[0]) while not ans.is_fpf_involution(): f = [i for i in range(1, ans.rank + 2) if ans(i) == i] ans *= Permutation.transposition(f[0], f[1]) w0 = Permutation.longest_element(o + 1 + len(mu) + (mu[0] if mu else 0)) ans = w0 * ans * w0 return ans
def _expansion(n, function, expand, shifted=True, unsigned=True): # noqa for mu in Partition.all(n, strict=shifted): n = len(mu) p = function(n, mu) ansion = expand(p) if unsigned: expansion = { nu: coeff * (-1)**abs(sum(mu) - sum(nu)) for nu, coeff in ansion.items() } else: expansion = ansion print('mu =', mu) print() print(Partition.printable(mu, shifted=shifted)) print() print(' mu =', mu, 'n =', n) print(' expansion =', ansion) if unsigned: print(' unsigned expansion =', expansion) print() assert all(v > 0 for v in expansion.values())
def test_contains(): mu = (1, ) nu = () assert Partition.contains(mu, mu) assert Partition.contains(mu, nu) assert not Partition.contains(nu, mu) mu = (3, 2, 1) nu = (3, 2) assert Partition.contains(mu, mu) assert Partition.contains(mu, nu) assert not Partition.contains(nu, mu) mu = (3, 2, 1) nu = (1, 1, 1) assert Partition.contains(mu, nu) assert not Partition.contains(nu, mu) mu = (1, 1, 1, 1) nu = (1, 1, 1) assert Partition.contains(mu, nu) assert not Partition.contains(nu, mu)
def _multiply(cls, f, g): assert type(f) == type(g) == SymmetricMonomial assert f.order() == g.order() mu = f.mu nu = g.mu n = min(f.order(), len(mu) + len(nu)) if (mu, nu, n) not in MONOMIAL_PRODUCT_CACHE: ans = defaultdict(int) for alpha in cls._destandardize(n, mu): for blpha in cls._destandardize(n, nu): gamma = tuple(alpha[i] + blpha[i] for i in range(n)) if Partition.is_partition(gamma): while gamma and gamma[-1] == 0: gamma = gamma[:-1] ans[gamma] += 1 MONOMIAL_PRODUCT_CACHE[(mu, nu, n)] = ans return MONOMIAL_PRODUCT_CACHE[(mu, nu, n)]
def test_covers(): mu = () assert set(Partition.remove_inner_corners(mu)) == {()} assert set(Partition.remove_shifted_inner_corners(mu)) == {()} mu = (1, ) assert set(Partition.remove_inner_corners(mu)) == {(1, ), ()} assert set(Partition.remove_shifted_inner_corners(mu)) == {(1, ), ()} mu = (3, 2, 1) assert set(Partition.remove_inner_corners(mu)) == {(3, 2, 1), (2, 2, 1), (3, 1, 1), (3, 2), (2, 1, 1), (2, 2), (3, 1), (2, 1)} assert set(Partition.remove_shifted_inner_corners(mu)) == {(3, 2), (3, 2, 1)}
def test_symmetric_functions(): nn = 6 for mu in Partition.all(nn): for nu in Partition.all(nn, strict=True): for n in range(nn): print(n, mu, nu) print() f = SymmetricPolynomial.schur(n, mu, nu) g = SymmetricPolynomial.stable_grothendieck(n, mu, nu) h = SymmetricPolynomial.dual_stable_grothendieck(n, mu, nu) fs = SymmetricPolynomial._slow_schur(n, mu, nu) gs = SymmetricPolynomial._slow_stable_grothendieck(n, mu, nu) hs = SymmetricPolynomial._slow_dual_stable_grothendieck( n, mu, nu) if f != fs: print(f) print(fs) print() if g != gs: print(g) print(gs) print() if h != hs: print(h) print(hs) print() print() assert f == fs assert g == gs assert h == hs hh = SymmetricPolynomial.schur_s(n, mu, nu) kk = SymmetricPolynomial.stable_grothendieck_s(n, mu, nu) if mu == nu: assert f == 1 assert g == 1 assert h == 1 assert fs == 1 assert gs == 1 assert hs == 1 assert hh == 1 assert kk == 1 if not Partition.contains(mu, nu): assert f == 0 assert g == 0 assert h == 0 assert fs == 0 assert gs == 0 assert hs == 0 assert hh == 0 assert kk == 0 print(f) print(g) print() print(hh) print(kk) print() assert g.lowest_degree_terms() == f assert kk.lowest_degree_terms() == hh
def fpf_grassmannians(cls, rank): assert rank % 2 == 0 delta = tuple(range(rank - 2, 0, -2)) for mu in Partition.subpartitions(delta, strict=True): yield cls.get_fpf_grassmannian(*mu)
def inv_grassmannians(cls, rank): delta = tuple(range(rank - 1, 0, -2)) for mu in Partition.subpartitions(delta, strict=True): yield cls.get_inv_grassmannian(*mu)
def grassmannians(cls, rank): delta = tuple(range(rank - 1, 0, -1)) for mu in Partition.subpartitions(delta): yield cls.get_grassmannian(*mu)
def shape(self): return Partition.sort(self.inverse().code(), trim=True)
def all(cls, n, rank, excess, is_multisetvalued, is_symplectic): for mu in Partition.generate(n, strict=True): cg = cls(mu, rank, excess, is_multisetvalued, is_symplectic) if cg.edges: cg.generate()
def fpf_involution_shape(self): assert self.is_fpf_involution() mu = Partition.sort(self.fpf_involution_code(), trim=True) return Partition.transpose(mu)
def test_strict_symmetric_functions(): nn = 5 for mu in Partition.all(nn, strict=True): for nu in Partition.all(nn, strict=True): for n in range(nn): print(n, mu, nu) print() # Schur-P and GP f = SymmetricPolynomial.schur_p(n, mu, nu) g = SymmetricPolynomial.stable_grothendieck_p(n, mu, nu) h = SymmetricPolynomial.dual_stable_grothendieck_p(n, mu, nu) fs = SymmetricPolynomial._slow_schur_p(n, mu, nu) gs = SymmetricPolynomial._slow_stable_grothendieck_p(n, mu, nu) hs = SymmetricPolynomial._slow_dual_stable_grothendieck_p( n, mu, nu) if f != fs: print(f) print(fs) print() if g != gs: print(g) print(gs) print() if h != hs: print(h) print(hs) print() print() print() assert f == fs assert g == gs assert h == hs if mu == nu: assert f == 1 assert g == 1 assert h == 1 assert fs == 1 assert gs == 1 assert hs == 1 if not Partition.contains(mu, nu): assert f == 0 assert g == 0 assert h == 0 assert fs == 0 assert gs == 0 assert hs == 0 # Schur-Q and GQ f = SymmetricPolynomial.schur_q(n, mu, nu) g = SymmetricPolynomial.stable_grothendieck_q(n, mu, nu) h = SymmetricPolynomial.dual_stable_grothendieck_q(n, mu, nu) fs = SymmetricPolynomial._slow_schur_q(n, mu, nu) gs = SymmetricPolynomial._slow_stable_grothendieck_q(n, mu, nu) hs = SymmetricPolynomial._slow_dual_stable_grothendieck_q( n, mu, nu) if f != fs: print(f) print(fs) print() if g != gs: print(g) print(gs) print() if h != hs: print(h) print(hs) print() print() print() assert f == fs assert g == gs assert h == hs if mu == nu: assert f == 1 assert g == 1 assert h == 1 assert fs == 1 assert gs == 1 assert hs == 1 if not Partition.contains(mu, nu): assert f == 0 assert g == 0 assert h == 0 assert fs == 0 assert gs == 0 assert hs == 0