Beispiel #1
0
def main():

    desc = argv.next()
    assert desc

    print("constructing %s" % desc)
    assert "_" in desc, repr(desc)

    name, idx = desc.split("_")
    idx = int(idx)
    attr = getattr(Weyl, "build_%s" % name)
    G = attr(idx)

    print(G)

    e = G.identity
    gen = G.gen
    roots = G.roots
    els = G.generate()
    G = Group(els, roots)
    print("order:", len(els))

    ring = element.Z
    value = zero = Poly({}, ring)
    q = Poly("q", ring)
    for g in els:
        #print(g.word)
        value = value + q**(len(g.word))
    print(value.qstr())

    n = len(gen)
    Hs = []
    for idxs in all_subsets(n):
        print(idxs, end=" ")
        gen1 = [gen[i] for i in idxs] or [e]
        H = Group(mulclose(gen1), roots)
        Hs.append(H)
        gHs = G.left_cosets(H)
        value = zero
        for gH in gHs:
            items = list(gH)
            items.sort(key=lambda g: len(g.word))
            #for g in items:
            #    print(g.word, end=" ")
            #print()
            g = items[0]
            value = value + q**len(g.word)
        #print(len(gH))
        print(value.qstr())

    G = Group(els, roots)
    burnside(G, Hs)
Beispiel #2
0
def show_qpoly(G):
    gen = G.gen
    roots = G.roots
    els = G.generate()
    e = G.identity
    G = Group(els, roots)
    print("order:", len(els))

    ring = element.Z
    value = zero = Poly({}, ring)
    q = Poly("q", ring)
    for g in els:
        #print(g.word)
        value = value + q**(len(g.word))
    print(value.qstr())

    lookup = dict((g, g) for g in G)  # remember canonical word

    n = len(gen)
    for i in range(n):
        gen1 = gen[:i] + gen[i + 1:]
        H = mulclose_short([e] + gen1)
        eH = Coset(H, roots)
        H = Group(H, roots)
        #gHs = G.left_cosets(H)

        cosets = set([eH])
        bdy = set(cosets)
        while bdy:
            _bdy = set()
            for coset in bdy:
                for g in gen:
                    gH = Coset([g * h for h in coset], roots)
                    if gH not in cosets:
                        cosets.add(gH)
                        _bdy.add(gH)
            bdy = _bdy

        value = zero
        for gH in cosets:
            items = list(gH)
            items.sort(key=lambda g: len(g.word))
            #for g in items:
            #    print(g.word, end=" ")
            #print()
            g = items[0]
            value = value + q**len(g.word)
        #print(len(gH))
        print(value.qstr())
Beispiel #3
0
def test_hom():

    ring = element.Q
    n = argv.get("n", 3)

    V = Space(ring, n)

    # build action of symmetric group on the space V
    items = list(range(n))
    gen1 = []
    gen2 = []
    for i in range(n - 1):
        perm = dict((item, item) for item in items)
        perm[items[i]] = items[i + 1]
        perm[items[i + 1]] = items[i]
        g = Perm(perm, items)
        gen1.append(g)
        A = elim.zeros(ring, n, n)
        for k, v in perm.items():
            A[v, k] = ring.one
        lin = Lin(V, V, A)
        gen2.append(lin)

    perms = mulclose(gen1)
    G = Group(perms, items)

    #print(G)

    action = mulclose_hom(gen1, gen2)
    for g in G:
        for h in G:
            assert action[g *
                          h] == action[g] * action[h]  # check it's a group hom
Beispiel #4
0
def orbiplex(G, k=4):

    #import numpy
    #from gelim import zeros, dotx, rank, nullity

    print("orbiplex: |G|=%d" % len(G))
    items = G.items

    k = argv.get("k", k)
    for n in range(k):

        write("|C_%d| ="%n)
        #if n > len(items):
        #    break

        tpls = list(uniqtuples(items, n))

        perms = []
        for perm in G:
            _perm = {}
            for key in tpls:
                value = tuple(perm[i] for i in key)
                _perm[key] = value
            _perm = Perm(_perm, tpls)
            perms.append(_perm)

        G2 = Group(perms, tpls)

        orbits = list(G2.orbits())
        d = len(orbits)
        write("%d,"%d)
Beispiel #5
0
def get_autos(nxgraph):
    graph0 = mkgraph(nxgraph)
    graph1 = mkgraph(nxgraph)

    items = [point.idx for point in graph0]
    perms = []
    for f in isomorph.search(graph0, graph1):
        perm = Perm(f, items)
        perms.append(perm)
        #print perm
    G = Group(perms, items)
    return G
Beispiel #6
0
 def get_isoms(self):
     "find the graph autos that act by isometries (on the layout)"
     nodes = self.nodes
     edges = self.edges
     G = get_autos(nodes, edges)
     A0 = self.get_metric()
     perms = []
     for g in G:
         graph = self.permute(g)
         A1 = graph.get_metric()
         if numpy.allclose(A0, A1):
             perms.append(g)
     G = Group(perms, g.items)
     return G
Beispiel #7
0
def make_group(ops):
    ops = list(ops)
    lookup = dict((numrepr(A), i) for (i, A) in enumerate(ops))
    #for A in ops:
    #    print(repr(numrepr(A)))
    items = list(range(len(ops)))
    perms = []
    for i, A in enumerate(ops):
        perm = {}
        for j, B in enumerate(ops):
            C = dot(A, B)
            k = lookup[numrepr(C)]
            perm[j] = k
        perm = Perm(perm, items)
        perms.append(perm)
    G = Group(perms, items)
    return G
Beispiel #8
0
def specht(n, space):

    assert n >= 2
    d = len(space)
    ring = space.ring

    items = list(range(n))
    gen1 = []
    for i in range(n - 1):
        perm = dict((item, item) for item in items)
        perm[items[i]] = items[i + 1]
        perm[items[i + 1]] = items[i]
        perm = Perm(perm, items)
        gen1.append(perm)
    perms = mulclose(gen1)
    G = Group(perms, items)

    #I = space.ident

    # tensor power of the space
    tensor = lambda x, y: x @ y
    tspace = reduce(tensor, [space] * n)

    # build action of symmetric group on the tensor power
    thom = Hom(tspace, tspace)
    gen2 = []
    for g in gen1:
        items = []
        for idxs in tspace.gen:
            jdxs = tuple(idxs[g[i]] for i in range(len(idxs)))
            items.append(((idxs, jdxs), ring.one))
            #print(idxs, "->", jdxs)
        #print()
        swap = Map(items, thom)
        gen2.append(swap)

    action = mulclose_hom(gen1, gen2)
    for g in G:
        for h in G:
            assert action[g *
                          h] == action[g] * action[h]  # check it's a group hom

    tp = Cat(G, ring)

    rep = Rep(action, tspace, tp)
    return rep
Beispiel #9
0
def cayley(elements):
    "build the regular permutation representation"
    elements = list(elements)
    lookup = {}
    for idx, e in enumerate(elements):
        lookup[e] = idx
    items = list(range(len(elements)))
    perms = []
    for i, e in enumerate(elements):
        perm = {}
        for j, f in enumerate(elements):
            g = e*f
            k = lookup[g]
            perm[j] = k
        perm = Perm(perm, items)
        perms.append(perm)
    G = Group(perms, items)
    return G
Beispiel #10
0
def main():
    name = argv.next() or "icosahedron"
    geometry = make_geometry(name)

    graph = geometry.get_bag()
    graph1 = geometry.get_bag()
    #print graph
    n = len(graph)
    items = [i for i in range(n) if graph[i].desc=="vert"]
    #print items

    perms = []
    for f in isomorph.search(graph, graph1):
        #print f
        f = dict((i, f[i]) for i in items)
        perm = Perm(f, items)
        perms.append(perm)
        write('.')
    print("symmetry:", len(perms))
    assert len(set(perms)) == len(perms)

    G = Group(perms, items)

    orbiplex(G)
Beispiel #11
0
def hecke(self):

    bag0 = self.get_bag()
    bag1 = self.get_bag()

    points = [p for p in bag0 if p.desc == '0']
    lines = [p for p in bag0 if p.desc == '1']
    print(points)
    print(lines)
    flags = []
    for p in points:
        ls = [l for l in p.nbd if l != p]
        print(p, ls)
        for l in ls:
            flags.append((p, l))

    print("flags:", len(flags))

    #    for point in bag0:
    #        print point, repr(point.desc)

    #items = [(point.idx, line.idx) for point in points for line in lines]
    #items = [(a.idx, b.idx) for a in points for b in points]
    items = [(a, b) for a in flags for b in flags]

    # fixing two points gives the Klein four group, Z_2 x Z_2:
    #for f in isomorph.search(bag0, bag1):
    #    if f[0]==0 and f[1]==1:
    #        print f

    perms = []
    for f in isomorph.search(bag0, bag1):
        #print f
        g = dict((bag0[idx], bag0[f[idx]]) for idx in list(f.keys()))
        perm = {}
        for a, b in items:
            a1 = (g[a[0]], g[a[1]])
            b1 = (g[b[0]], g[b[1]])
            assert (a1, b1) in items
            perm[a, b] = a1, b1
        perm = Perm(perm, items)
        perms.append(perm)
        write('.')
    print()

    g = Group(perms, items)
    print("group:", len(g))

    orbits = g.orbits()
    #print orbits
    print("orbits:", len(orbits))

    eq = numpy.allclose
    dot = numpy.dot

    n = len(flags)
    basis = []
    gen = []
    I = identity2(n)
    for orbit in orbits:
        A = zeros2(n, n)
        #print orbits
        for a, b in orbit:
            A[flags.index(a), flags.index(b)] = 1
        print(shortstr(A))
        print(A.sum())
        #print

        basis.append(A)
        if A.sum() == 42:
            gen.append(A)

    assert len(gen) == 2
    L = gen[0]
    P = gen[1]
    q = 2

    assert eq(dot(L, L), L + q * I)
    assert eq(dot(P, P), P + q * I)
    assert eq(dot(L, dot(P, L)), dot(P, dot(L, P)))
Beispiel #12
0
def make_random_homogeneous():
    # use rotation group

    #seed(1)

    ngens = 6
    a, ai, b, bi, c, ci = range(ngens)
    i_rels = [
        (ai, a),
        (bi, b),
        (ci, c),
        (a, ) * 5,
        (b, ) * 2,
        (c, ) * 4,
        (a, b, c),
    ]

    while 1:
        rels = []
        for i in range(argv.get("nwords", 2)):
            gen = tuple(
                choice([a, b, c]) for k in range(argv.get("wordlen", 100)))
            rels.append(gen)
            gen = (ci, ) + gen + (c, )
            rels.append(gen)
            gen = (ci, ) + gen + (c, )
            rels.append(gen)

        rels = [reduce_word(i_rels, rel) for rel in rels]

        graph = Schreier(ngens, i_rels)
        if not graph.build(rels, maxsize=10400):
            print(choice("/\\"), end="", flush=True)
            continue

        n = len(graph)
        if n <= argv.get("minsize", 12):
            print('.', end="", flush=True)
            continue

        print("[%d]" % n, flush=True, end="")

        # how big did the graph get? compare with maxsize above
        print("(%d) " % len(graph.neighbors), flush=True, end="")

        try:
            gens = graph.get_gens()
        except AssertionError:
            print("** FAIL **")
            continue

        items = list(range(n))
        print()
        break

        N = argv.get("N", 10000)
        perms = mulclose(gens, maxsize=N)
        if len(perms) >= N:
            #print("|G| = ?")
            continue

        print()
        print(rels)
        G = Group(perms, items)
        G.gens = gens
        print("|G| =", len(G))

        rels = [reduce(mul, [gens[i] for i in rel]) for rel in rels]
        H = Coset(mulclose(rels), items)
        print("|H| =", len(H))
        assert len(G) % len(H) == 0
        print("[H:G] = ", len(G) // len(H))

        N = []
        for g in G:
            lhs = g * H
            rhs = H * g
            if lhs == rhs:
                N.append(g)
        assert len(N) % len(H) == 0
        print("[H:N(H)] =", len(N) // len(H))

    print(rels)

    a, ai, b, bi, c, ci = gens
    assert (a**5).is_identity()
    assert (b**2).is_identity()
    assert (c**4).is_identity()
    assert (a * b * c).is_identity()

    print(a.fixed())
    print(b.fixed())
    print(c.fixed())

    print(a.orbits())
    print(b.orbits())
    print(c.orbits())
Beispiel #13
0
    def __init__(self, n, space):
        assert n >= 2
        d = len(space)
        ring = space.ring

        items = list(range(n))
        gen1 = []
        for i in range(n - 1):
            perm = dict((item, item) for item in items)
            perm[items[i]] = items[i + 1]
            perm[items[i + 1]] = items[i]
            perm = Perm(perm, items)
            gen1.append(perm)

        perms = mulclose(gen1)
        G = Group(perms, items)

        #I = space.ident

        # tensor power of the space
        tensor = lambda x, y: x @ y
        tspace = reduce(tensor, [space] * n)

        # build action of symmetric group on the tensor power
        thom = Hom(tspace, tspace)
        gen2 = []
        for g in gen1:
            items = []
            for idxs in tspace.gen:
                jdxs = tuple(idxs[g[i]] for i in range(len(idxs)))
                items.append(((idxs, jdxs), ring.one))
                #print(idxs, "->", jdxs)
            #print()
            swap = Map(items, thom)
            gen2.append(swap)

        action = mulclose_hom(gen1, gen2)
        for g in G:
            for h in G:
                assert action[
                    g * h] == action[g] * action[h]  # check it's a group hom

        # Build the young symmetrizers
        projs = []
        parts = []
        for part in partitions(n):
            if len(part) > d:
                continue
            parts.append(part)
            t = Young(G, part)

            rowG = t.get_rowperms()
            colG = t.get_colperms()
            horiz = None
            for g in rowG:
                P = action[g]
                horiz = P if horiz is None else (horiz + P)

            vert = None
            for g in colG:
                P = action[g]
                s = g.sign()
                P = s * P
                vert = P if vert is None else (vert + P)
            A = vert * horiz + horiz * vert
            #A = horiz * vert

            assert vert * vert == len(colG) * vert
            assert horiz * horiz == len(rowG) * horiz
            #A = A.transpose()
            projs.append(A)

            #print(part)
            #print(t)
            #print(A)

        self.projs = projs
        self.parts = parts
Beispiel #14
0
def make_cyclic(n, check=False):

    R = PolynomialRing(Z)

    p = cyclotomic(R, n)
    #print(p)
    #print(p(R.x*2))

    ring = R / p
    zeta = ring.x
    #print("zeta: %r"%zeta)
    izeta = zeta**(n - 1)  # inverse

    #print(zeta, izeta)
    #print(zeta.conj())

    #G = mulclose([zeta])
    #for g in G:
    #    print(g, end=" ")
    #print()
    #G = cayley(G)

    items = list(range(n))
    perms = []
    e = Perm(dict((i, i) for i in range(n)), items)
    a = Perm(dict((i, (i + 1) % n) for i in range(n)), items)
    perms = [e, a]
    for i in range(2, n):
        b = perms[-1] * a
        perms.append(b)

    G = Group(perms, items, check=True)

    # complex characters  --------------------------------------------------
    c_chars = []
    for k in range(n):
        chi = dict((perms[i], zeta**(i * k)) for i in range(n))
        chi = CFunc(G, chi)
        c_chars.append(chi)

    G.c_chars = c_chars

    for f in c_chars:
        for g in c_chars:
            r = f.dot(g)
            assert (f == g) == (r == 1)
            #print(f.dot(g), end=" ")
        #print()

    # real characters  --------------------------------------------------
    r_chars = [c_chars[0]]  # triv
    if n % 2:
        for k in range(1, (n + 1) // 2):
            a = c_chars[k] + c_chars[n - k]
            r_chars.append(a)
    else:
        chi = dict((perms[i], (-1)**i) for i in range(n))
        chi = CFunc(G, chi)
        r_chars.append(chi)
        for k in range(1, n // 2):
            #print("a = c_chars[k] + c_chars[n-k]")
            a = c_chars[k] + c_chars[n - k]
            r_chars.append(a)

    for f in r_chars:
        for g in r_chars:
            r = f.dot(g)
            assert (f == g) == (r != 0)
            #print(f.dot(g), end=" ")
        #print()
    G.r_chars = r_chars

    return G
Beispiel #15
0
 def build_group(self):
     perms = self.generate()
     G = Group(perms, self.roots)
     return G
Beispiel #16
0
def make_random_homogeneous_refl():

    seed(1)

    ngens = 6
    a, ai, b, bi, c, ci = range(ngens)
    i_rels = [
        (ai, a),
        (bi, b),
        (ci, c),
        (a, ) * 2,
        (b, ) * 2,
        (c, ) * 2,
        (a, b) * 5,
        (b, c) * 5,
        (a, c) * 2,
    ]

    while 1:
        rels = []
        for i in range(4):
            gen = ()
            for k in range(20):
                gen += choice([(a, b), (a, c), (b, c)])
            rels.append(gen)

        # G/H = 720/24 = 30, N(H)=24
        _rels = [(0, 2, 2, 4, 0, 4, 2, 4, 2, 4, 0, 4, 0, 4, 2, 4, 0, 2, 0, 4,
                  2, 4, 0, 4, 2, 4, 0, 2, 0, 2, 0, 2, 2, 4, 2, 4, 2, 4, 2, 4),
                 (0, 2, 2, 4, 0, 4, 2, 4, 0, 2, 0, 4, 0, 2, 0, 4, 0, 4, 0, 2,
                  0, 2, 0, 2, 0, 4, 0, 4, 2, 4, 0, 4, 0, 2, 0, 2, 2, 4, 0, 2),
                 (0, 2, 2, 4, 2, 4, 2, 4, 2, 4, 0, 2, 0, 4, 0, 4, 0, 4, 0, 4,
                  0, 2, 0, 2, 0, 4, 0, 2, 0, 2, 2, 4, 0, 4, 0, 2, 0, 4, 0, 2),
                 (0, 2, 0, 4, 0, 4, 2, 4, 0, 4, 0, 2, 0, 2, 2, 4, 0, 4, 0, 4,
                  0, 2, 0, 4, 0, 2, 0, 2, 2, 4, 0, 2, 2, 4, 2, 4, 0, 4, 0, 2)]

        # G/H = 9720/324 = 30, N(H)=1944
        _rels = [(0, 4, 0, 2, 0, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 0, 4, 0, 2,
                  0, 2, 0, 4, 2, 4, 0, 2, 0, 2, 0, 2, 2, 4, 0, 2, 0, 4, 0, 4),
                 (0, 4, 2, 4, 0, 2, 0, 2, 0, 2, 2, 4, 0, 2, 0, 2, 2, 4, 2, 4,
                  0, 4, 2, 4, 0, 4, 2, 4, 0, 4, 0, 2, 2, 4, 0, 2, 2, 4, 0, 2),
                 (0, 4, 0, 4, 0, 4, 0, 2, 0, 4, 0, 4, 2, 4, 0, 4, 0, 2, 0, 2,
                  0, 4, 0, 2, 0, 2, 0, 2, 0, 4, 0, 4, 0, 4, 2, 4, 0, 2, 2, 4),
                 (2, 4, 2, 4, 0, 4, 2, 4, 0, 2, 0, 4, 0, 4, 2, 4, 2, 4, 2, 4,
                  2, 4, 2, 4, 0, 4, 0, 4, 2, 4, 2, 4, 2, 4, 0, 4, 0, 2, 2, 4)]

        graph = Schreier(ngens, i_rels)
        if not graph.build(rels, maxsize=10400):
            print(choice("/\\"), end="", flush=True)
            continue

        n = len(graph)
        if n <= 24:
            continue

        print("\n[%d]" % n)  #, flush=True, end="")
        print(len(graph.neighbors)
              )  # how big did the graph get? compare with maxsize above

        try:
            gens = graph.get_gens()
        except AssertionError:
            print("** FAIL **")
            continue

        N = 10000
        perms = mulclose(gens, maxsize=N)
        if len(perms) >= N:
            print("|G| = ?")
            continue

        print(rels)
        items = list(range(n))
        G = Group(perms, items)
        G.gens = gens
        print("|G| =", len(G))
        print()

        break

    rels = [reduce(mul, [gens[i] for i in rel]) for rel in rels]
    H = Coset(mulclose(rels), items)
    print(len(H))
    print(len(G) / len(H))

    N = []
    for g in G:
        lhs = g * H
        rhs = H * g
        if lhs == rhs:
            N.append(g)
    print(len(N))
Beispiel #17
0
from bruhat.action import Perm, Group
from bruhat.util import factorial
from bruhat.argv import argv

p = argv.get("p", 5)

if 0:
    items = [i for i in range(1, p**2) if i % p]
    print(items)

    perms = []
    for i in items:
        perm = dict((j, (j * i) % p**2) for j in items)
        perms.append(Perm(perm, items))

    G = Group(perms, items)

    print(len(G))
    print(G.is_cyclic())


def div(a, b):
    # a/b = c mod p
    # a = c*b mod p
    assert 0 <= a < p
    assert 0 < b < p
    for c in range(p):
        if a == (c * b) % p:
            return c
    assert 0
Beispiel #18
0
def test_young0():
    ring = element.Q

    n = argv.get("n", 3)
    part = argv.get("part", (1, 1, 1))
    assert sum(part) == n

    V = Space(ring, n)

    # build action of symmetric group on the space V
    items = list(range(n))
    gen1 = []
    gen2 = []
    for i in range(n - 1):
        perm = dict((item, item) for item in items)
        perm[items[i]] = items[i + 1]
        perm[items[i + 1]] = items[i]
        g = Perm(perm, items)
        gen1.append(g)
        A = elim.zeros(ring, n, n)
        for k, v in perm.items():
            A[v, k] = ring.one
        lin = Lin(V, V, A)
        gen2.append(lin)

    perms = mulclose(gen1)
    G = Group(perms, items)

    #print(G)

    action = mulclose_hom(gen1, gen2)
    for g in G:
        for h in G:
            assert action[g *
                          h] == action[g] * action[h]  # check it's a group hom

    young = Young(G, part)
    rowG = young.get_rowperms()
    print("rowG", len(rowG))
    colG = young.get_colperms()
    print("colG", len(colG))

    horiz = None
    for g in rowG:
        P = action[g]
        horiz = P if horiz is None else (horiz + P)

    vert = None
    for g in colG:
        P = action[g]
        s = g.sign()
        P = ring.promote(s) * P
        vert = P if vert is None else (vert + P)
    A = horiz * vert

    assert vert * vert == len(colG) * vert
    assert horiz * horiz == len(rowG) * horiz

    print("part:", part)
    print(young)
    print("rank:", A.rank())
    print("is_zero:", A.is_zero())
    print(A)
    #if not A.is_zero():
    #    print(A)

    print()
Beispiel #19
0
def test_young():
    # code ripped from qu.py

    d = argv.get("d", 2)
    n = argv.get("n", 3)
    p = argv.get("p")

    if p is None:
        ring = element.Q
    else:
        ring = element.FiniteField(p)
    print("ring:", ring)

    space = Space(ring, d)

    # tensor power of the space
    tspace = reduce(matmul, [space] * n)

    # build action of symmetric group on the tensor power
    items = list(range(n))
    gen1 = []
    gen2 = []
    for i in range(n - 1):
        perm = dict((item, item) for item in items)
        perm[items[i]] = items[i + 1]
        perm[items[i + 1]] = items[i]
        g = Perm(perm, items)
        gen1.append(g)
        lin = tspace.get_swap([g[i] for i in items])
        #print(lin.hom)
        gen2.append(lin)

    perms = mulclose(gen1)
    G = Group(perms, items)

    #print(G)

    action = mulclose_hom(gen1, gen2)
    for g in G:
        for h in G:
            assert action[g *
                          h] == action[g] * action[h]  # check it's a group hom

    # Build the young symmetrizers
    projs = []
    part = argv.get("part")
    parts = list(partitions(n)) if part is None else [part]
    for part in parts:
        assert sum(part) == n

        t = Young(G, part)

        rowG = t.get_rowperms()
        colG = t.get_colperms()
        horiz = None
        for g in rowG:
            P = action[g]
            horiz = P if horiz is None else (horiz + P)

        vert = None
        for g in colG:
            P = action[g]
            s = g.sign()
            P = ring.promote(s) * P
            vert = P if vert is None else (vert + P)
        A = horiz * vert

        assert vert * vert == len(colG) * vert
        assert horiz * horiz == len(rowG) * horiz
        #A = A.transpose()
        projs.append(A)

        print("part:", part)
        print(t)
        print("rank:", A.rank())
        print("is_zero:", A.is_zero())
        #if not A.is_zero():
        #    print(A)

        print()