예제 #1
0
파일: qu.py 프로젝트: punkdit/bruhat
def test():

    n = 9
    G = Group.symmetric(n)
    t = Young(G, (4, 3, 1, 1))
    assert t.rows == [[0, 1, 2, 3], [4, 5, 6], [7], [8]]
    assert t.cols == [[0, 4, 7, 8], [1, 5], [2, 6], [3]]

    G = t.get_rowperms()
    assert len(G) == factorial(4) * factorial(3)
예제 #2
0
def h2(x1, x2):
    x1 %= p
    x2 %= p
    total = 0
    for r1 in range(p):
        for r2 in range(p):
            if r1 + r2 != p:
                continue
            total += -div((x1**r1) * (x2**r2) % p,
                          factorial(r1) * factorial(r2) % p)
    return total % p
예제 #3
0
def test():

    for n in [2, 3, 4]:

        ops = build_An(n)
        assert len(mulclose(ops))==factorial(n)
    
        ops = build_Bn(n)
        assert len(mulclose(ops))==2**n*factorial(n)
    
        ops = build_Dn(n)
        assert len(mulclose(ops))==2**(n-1)*factorial(n)
    

    from numpy import kron as tensor

    def allclose(A, B):
        return numpy.abs(A - B).sum()==0

    for A in ops:
      for B in ops:

        assert (A==B) == (hash(A)==hash(B))
        assert (A!=B) != (A==B)

        lhs = (A*B).todense()
        rhs = ((numpy.dot(A.todense(), B.todense())))
        assert allclose(lhs, rhs)

        lhs = (A.tensor(B)).todense()
        rhs = ((tensor(A.todense(), B.todense())))
        assert allclose(lhs, rhs)

    for A in ops:
        assert allclose(A.transpose().todense(), A.todense().transpose()), str(A)

    ops = mulclose(build_Bn(2))
    tops = []
    for A in ops:
      for B in ops:
        C = Tensor([A, B])
        tops.append(C)

    #print(len(tops))
    for A in tops:
        assert A.get_canonical() == A

    for A in tops:
      for B in tops:
        assert (A==B) == allclose(A.todense(), B.todense())
        assert (A==B) == (A.get_canonical()==B.get_canonical())
        assert (A==B) == (hash(A)==hash(B))

    print("OK")
예제 #4
0
파일: lie.py 프로젝트: punkdit/bruhat
def test_hilbert_sl3():
    # ---------------------------------------------------------------
    # Here we work out the coefficients of a Hilbert polynomial
    # given by the rational function top/bot.
    # These coefficients give the dimension of irreps of SL(3).
    # See also test_graded_sl3 below.

    ring = Q
    zero = Poly({}, ring)
    one = Poly({():1}, ring)
    x = Poly("x", ring)
    y = Poly("y", ring)
    z = Poly("z", ring)

    top = one - x*y
    bot = ((one-x)**3) * ((one-y)**3)

    def diff(top, bot, var):
        top, bot = top.diff(var)*bot - bot.diff(var)*top, bot*bot
        return top, bot

    fracs = {}
    fracs[0,0] = (top, bot)

    N = 3
    for i in range(N):
      for j in range(N):
        top, bot = fracs[i, j]
        top, bot = diff(top, bot, 'x')
        fracs[i, j+1] = top, bot

        top, bot = fracs[i, j]
        top, bot = diff(top, bot, 'y')
        fracs[i+1, j] = top, bot
        print(".", end="", flush=True)
    print()

    for i in range(N+1):
      for j in range(N+1):
        if (i, j) not in fracs:
            continue
        top, bot = fracs[i, j]
        t = top.get_const()
        b = bot.get_const()
        val = t//b//factorial(i)//factorial(j)
        assert val == dim_sl3(i, j)
        print(val, end=" ")
      print()
예제 #5
0
파일: poly.py 프로젝트: punkdit/bruhat
 def getitem(self, idx):
     name = self.get_name(idx)
     p = Poly(name, Q)
     p = self.subs.get(name, p)
     #p = Poly({((name, 1),) : Q.one//factorial(idx)}, Q)
     p = Q.one // factorial(idx) * p
     return p
예제 #6
0
파일: lie.py 프로젝트: punkdit/bruhat
 def Adim(*xs):
     if len(xs)==1:
         x = xs[0]
         return x+1
     #print("Adim", xs)
     n = len(xs)
     value = Adim(*xs[:-1])
     #print("value =", value)
     for i in range(n):
         rhs = sum(xs[i:]) + n-i
         #print("   *= sum(%s) + %s"%(xs[i:], n-i))
         value *= rhs
     div = factorial(n)
     assert value%div == 0
     value //= factorial(n)
     #print("  =", value)
     return value
예제 #7
0
파일: gset.py 프로젝트: punkdit/bruhat
 def symmetric(cls, n):
     assert n > 0
     gen = []
     items = list(range(n))
     for i in range(n - 1):
         perm = list(items)
         perm[i] = i + 1
         perm[i + 1] = i
         gen.append(Perm(perm))
     G = Group(gen=gen)
     assert len(G) == factorial(n)
     return G
예제 #8
0
파일: gset.py 프로젝트: punkdit/bruhat
 def alternating(cls, n):
     assert n > 0
     gen = []
     items = list(range(n))
     for i in range(n - 2):
         perm = list(items)
         perm[i] = i + 1
         perm[i + 1] = i + 2
         perm[i + 2] = i
         gen.append(Perm(perm))
     G = Group(gen=gen)
     assert len(G) == factorial(n) // 2
     return G
예제 #9
0
파일: species.py 프로젝트: punkdit/bruhat
 def __getitem__(self, idx):
     U = Set(idx)
     FU = self.species[U]
     FU = list(FU)
     return self.ring.one * len(FU) / factorial(idx)
예제 #10
0
파일: rational.py 프로젝트: punkdit/bruhat
def tpl_factorial(idxs):
    r = 1
    for i in idxs:
        r *= factorial(i)
    return r
예제 #11
0
파일: rational.py 프로젝트: punkdit/bruhat
def choose(m, n):
    assert m>=n>=0
    value = factorial(m) // (factorial(n) * factorial(m-n))
    assert value > 0
    return value
예제 #12
0
def test(n):

    G = Weyl.build_A(n)

    #    print "%d roots" % len(G.roots)
    #    print G.roots
    #    for g in G.gen:
    #        print [g(root) for root in G.roots]

    gen = G.gen
    for i in range(n):
        for j in range(n):
            gi = gen[i]
            gj = gen[j]
            if i == j:
                assert gi * gj == G.identity
            elif abs(i - j) == 1:
                assert gi * gj != G.identity
                assert (gi * gj)**2 != G.identity
                assert (gi * gj)**3 == G.identity
            else:
                assert gi * gj != G.identity
                assert (gi * gj)**2 == G.identity

    if n < 5:
        assert len(mulclose(G.gen)) == factorial(n + 1)

    # ---------------------------------------------------------

    G = Weyl.build_B(n)

    gen = G.gen
    for g in gen:
        assert g * g == G.identity

    for i in range(n - 1):
        for j in range(i + 1, n - 1):
            gi = gen[i]
            gj = gen[j]
            if abs(i - j) == 1:
                assert gi * gj != G.identity
                assert (gi * gj)**2 != G.identity
                assert (gi * gj)**3 == G.identity
            else:
                assert gi * gj != G.identity
                assert (gi * gj)**2 == G.identity
            if i < n - 1:
                gj = gen[n - 1]
                assert gi * gj != G.identity
                assert (gi * gj)**2 == G.identity

    if n > 2:
        gi = gen[n - 2]
        gj = gen[n - 1]
        assert (gi * gj) != G.identity
        assert (gi * gj)**2 != G.identity
        assert (gi * gj)**3 != G.identity
        assert (gi * gj)**4 == G.identity

    if n < 5:
        assert len(mulclose(G.gen)) == (2**n) * factorial(n)

    # ---------------------------------------------------------
    G = Weyl.build_C(n)

    # ---------------------------------------------------------

    if n < 3:
        return  # <---------------------- return

    G = Weyl.build_D(n)

    gen = G.gen
    for i in range(n - 1):
        gi = gen[i]
        for j in range(i + 1, n - 1):
            gj = gen[j]
            if abs(i - j) == 1:
                assert gi * gj != G.identity
                assert (gi * gj)**2 != G.identity
                assert (gi * gj)**3 == G.identity
            else:
                assert gi * gj != G.identity
                assert (gi * gj)**2 == G.identity

        gj = gen[n - 1]
        if i < n - 3 or i == n - 2:
            assert gi * gj != G.identity
            assert (gi * gj)**2 == G.identity
        elif i == n - 3:
            assert gi * gj != G.identity
            assert (gi * gj)**2 != G.identity
            assert (gi * gj)**3 == G.identity

    if n < 5:
        assert len(mulclose(G.gen)) == (2**(n - 1)) * factorial(n)
예제 #13
0
def main():

    X, Z = build_Bn(2)
    I = Op.identity(2)

    l = argv.get("l", 2)
    if argv.B2:
        #toric(X, Z)
        code = Toric(l, X, Z)
        print("OK")
        return

    #print(I)
    #print(X)
    #print(Z)

    II = Op.identity(4)

    P2 = [X.tensor(I), Z.tensor(I), I.tensor(X), I.tensor(Z)]
    P2 = mulclose(P2)

    assert len(P2) == 32
    assert II in P2

    errors = []
    for A in P2:
        if A == II or A == -II or -A in errors:
            continue
        errors.append(A)
    assert len(errors) == 15

    if 0:
        G = mulclose(P2)
        for g in G:
            A = g.todense()
            vals = numpy.linalg.eigvals(A)
            print(vals)  # all +1, -1

    d = argv.get("d", 4)
    gen = build_Bn(d)
    n = (2**d) * factorial(d)
    assert len(mulclose(gen)) == n  # slow...
    G = mulclose(gen, n)

    H = [g for g in G if g not in P2]

    for ops in all_quads(H):
        X1, X2, Z1, Z2 = ops
        ss = set()
        print("quad")  # no quads found ...
        for E in errors:
            #s = tuple(order(E*A) for A in ops)
            #ss.append(s)
            ss.add(tuple(E * A * inverse(E) * inverse(A) for A in ops))
            #ss.add(tuple(order(E*A) for A in ops))
        #print(len(set(ss)))
        if len(set(ss)) == len(errors):
            write("/")
            toric([X1, X2], [Z1, Z2])
        else:
            write("\\")
예제 #14
0
파일: species.py 프로젝트: punkdit/bruhat
 def r(n):
     result = 0
     for d in divisors(n):
         result += factorial(n) // (factorial(d) * factorial(n // d))
     return result
예제 #15
0
def test():

    # triangle:
    g = Geometry("aB aC bA bC cB cA".split(), {
        'a': 'p',
        'b': 'p',
        'c': 'p',
        'A': 'l',
        'B': 'l',
        'C': 'l'
    })

    assert len(g.items) == 6
    #print g.flags_type('l')
    #print g.flags_type('p')

    #g = g.residue(["a"])

    for n in range(2, 7):
        g = Geometry.polygon(n)
        assert len(g.items) == 2 * n
        assert len(g.maximal_flags()) == 2 * n

        assert len(g.flags_type(['p'])) == n
        assert len(g.flags_type(['l'])) == n
        assert len(g.flags_type(['p', 'l'])) == 2 * n
        if n > 3:
            assert not g.is_projective_plane()

    g = Geometry.simplex(2)
    h = g.residue([(0, ), (0, 1)])
    assert len(h.items) == 1
    assert len(g.flags_type([0, 1])) == 6

    for dim in range(4):
        g = Geometry.simplex(dim)
        assert len(g.items) == 2**(dim + 1) - 1
        assert len(g.maximal_flags()) == factorial(dim + 1)

        h = g.residue([(0, )])

        if dim > 0:
            g.residue([(0, ), (0, 1)])

    g = Geometry.cube()
    d = g.get_diagram()
    #assert d == [('e', 'v'), ('f', 'e')], repr(d)
    assert d == [('e', 'f'), ('e', 'v')]

    assert Geometry.simplex(4).get_diagram() == [(0, 1), (1, 2), (2, 3)
                                                 ]  # A_4 Dynkin diagram !

    #g = tesellate_3d()

    g = fano()
    assert g.get_diagram() == [('l', 'p')]

    n = argv.get("n", 3)
    assert n >= 3
    g = projective(n)

    assert len(g.tplookup[0]) == qbinomial(n, 1)
    assert len(g.tplookup[1]) == qbinomial(n, 2)

    if argv.cube:
        g = Geometry.cube()
    elif argv.simplex:
        g = Geometry.simplex(2)
    elif argv.triangle:
        g = Geometry.polygon(3)
    elif argv.projective:
        dim = argv.get("dim", 2)
        g = projective(n, dim)

        if dim > 2:
            assert len(g.tplookup[2]) == qbinomial(n, 3)
    elif argv.bruhat:
        if argv.A_2:
            monoid = BruhatMonoid("LP", {("L", "P"): 3})
        elif argv.A_3:
            monoid = BruhatMonoid("LPS", {("L", "P"): 3, ("L", "S"): 3})
        elif argv.A_4:
            monoid = BruhatMonoid("LPSH", {
                ("L", "P"): 3,
                ("L", "S"): 3,
                ("S", "H"): 3
            })
        elif argv.B_2:
            monoid = BruhatMonoid("LP", {("L", "P"): 4})
        elif argv.B_3:
            monoid = BruhatMonoid("LPS", {("L", "P"): 3, ("P", "S"): 4})
        elif argv.D_4:
            monoid = BruhatMonoid("LPSH", {
                ("L", "P"): 3,
                ("L", "S"): 3,
                ("L", "H"): 3
            })
        else:
            return
        monoid.build()
        system = MonoidSystem(monoid)
        magnitude_homology(system=system)

    else:
        return

    if argv.system:
        system = System(g)
        return

    if argv.magnitude:
        magnitude_homology(g)

    if argv.hecke:
        hecke(g)
        #print g.get_symmetry()
        #s = g.get_system()
        #s.get_symmetry()
        return

    print("OK")
예제 #16
0
def main():

    X, Z = build(2)
    I = dot(X, X)

    #print(I)
    #print(X)
    #print(Z)

    II = tensor(I, I)

    P2 = [tensor(X, I), tensor(Z, I), tensor(I, X), tensor(I, Z)]
    found = set()
    for g in mulclose(P2):
        s = shortstr(g)
        found.add(s)
    assert len(found) == 32
    assert shortstr(II) in found

    if 0:
        G = mulclose(P2)
        for g in G:
            A = numpy.array(g, dtype=numpy.float)
            vals = numpy.linalg.eigvals(A)
            print(vals)  # all +1, -1

    d = argv.get("d", 4)
    gen = build(d)
    n = (2**d) * factorial(d)
    assert len(mulclose(gen)) == n  # slow...
    G = mulclose(gen, n)

    print("orders:")
    for g in G:
        print(order(g), end=' ')
    print()

    if 0:
        for g in G:
            A = numpy.array(g, dtype=numpy.float)
            vals = numpy.linalg.eigvals(A)
            print(vals)  # all kinds of stuff..

    if d == 4:
        assert len([g for g in G if shortstr(g) in found]) == 32

    pairs = []

    c_comm = 0
    c_anti = 0
    total = 0
    for i in range(len(G)):
        for j in range(len(G)):
            g = G[i]
            h = G[j]

            gh = dot(g, h)
            hg = dot(h, g)

            total += 1
            if eq(gh, -hg):
                c_anti += 1
            elif eq(gh, hg):
                c_comm += 1

            if shortstr(g) in found or shortstr(h) in found:
                continue

            if eq(gh, -hg) and i < j:

                #assert order(g)==2
                print(order(g), end=' ')
                #print(g)
                #print(h)
                #print(eq(g, g.transpose()), end=' ')
                #print(eq(h, h.transpose()))
                if eq(g, g.transpose()) and eq(h, h.transpose()) and i < j:
                    pairs.append((g, h))

            #print(".", end='')
    #print()
    #print(c_comm, c_anti, total)

    print("pairs:", len(pairs))

    ops = {}
    for (g, h) in pairs:
        ops[shortstr(g)] = g
        ops[shortstr(h)] = h
    ops = list(ops.values())
    print(len(ops))

    for g in ops:
        for h in ops:
            a = eq(dot(g, h), dot(h, g))
            b = eq(dot(g, h), -dot(h, g))
            if a == b == False:
                s = '  '
            elif a:
                s = '+ '
            elif b:
                s = '- '
            print(s, end=' ')
        print()

    return

    A, B, C, D = gen
    pairs = [
        s.split() for s in ("ABDA CBDC", "BACB DCDA", "BACB DCDC",
                            "BACDBCBADCBC DCABDCDABACD")
    ]
    for l, r in pairs:
        left = [eval(s) for s in l]
        right = [eval(s) for s in r]
        left = dotx(*left)
        right = dotx(*right)

        if 1:
            print(shortstr(left))
            print(shortstr(left) in found)
            print()
            print(shortstr(right))
            print(shortstr(right) in found)
            print()
            print(shortstr(dotx(left, right)))
            print()
            print()
        assert eq((dotx(right, left)), -(dotx(left, right)))
예제 #17
0
파일: series.py 프로젝트: punkdit/bruhat
 def getitem(self, idx):
     ring = self.ring
     return ring.one // factorial(idx)