Ejemplo n.º 1
0
    def __init__(self, graph):
        bc = graph.boundary_cycles
        n = len(bc)  # == graph.num_boundary_cycles
        orientable = True

        ## Find out which automorphisms permute the boundary cycles among
        ## themselves.
        P = []  #: permutation of boundary cycles induced by `a \in Aut(G)`
        A = [
        ]  #: corresponding graph automorphisms: `P[i]` is induced by `A[i]`
        automorphisms = []  #: `NumberedFatgraph` automorphisms
        for a in graph.automorphisms():
            p = Permutation()
            for src in xrange(n):
                dst_cy = a.transform_boundary_cycle(bc[src])
                try:
                    dst = bc.index(dst_cy)
                except ValueError:
                    # `dst_cy` not in `bc`
                    break  # continue with next `a`
                p[src] = dst
            if len(p) != n:  # not all `src` were mapped to a `dst`
                continue  # with next `a`
            if p.is_identity():
                # `a` preserves the boundary cycles pointwise,
                # so it induces an automorphism of the numbered graph
                automorphisms.append(a)
                if a.compare_orientations() == -1:
                    orientable = False
            if (p not in P):
                # `a` induces permutation `p` on the set `bc`
                P.append(p)
                A.append(a)
        assert len(P) > 0  # XXX: should verify that `P` is a group!

        ## There will be as many distinct numberings as there are cosets
        ## of `P` in `Sym(n)`.
        if len(P) > 1:
            numberings = []
            for candidate in itertools.permutations(range(n)):
                if NumberedFatgraphPool._unseen(candidate, P, numberings):
                    numberings.append(list(candidate))
        else:
            # if `P` is the one-element group, then all orbits are trivial
            numberings = [list(p) for p in itertools.permutations(range(n))]

        # things to remember
        self.graph = graph
        self.is_orientable = orientable
        self.numberings = numberings
        self.P = P
        self.A = A
        self.num_automorphisms = len(automorphisms)
Ejemplo n.º 2
0
    def __init__(self, graph):
        bc = graph.boundary_cycles
        n = len(bc) # == graph.num_boundary_cycles
        orientable = True

        ## Find out which automorphisms permute the boundary cycles among
        ## themselves.
        P = []  #: permutation of boundary cycles induced by `a \in Aut(G)`
        A = []  #: corresponding graph automorphisms: `P[i]` is induced by `A[i]`
        automorphisms = [] #: `NumberedFatgraph` automorphisms
        for a in graph.automorphisms():
            p = Permutation()
            for src in xrange(n):
                dst_cy = a.transform_boundary_cycle(bc[src])
                try:
                    dst = bc.index(dst_cy)
                except ValueError:
                    # `dst_cy` not in `bc`
                    break # continue with next `a`
                p[src] = dst
            if len(p) != n: # not all `src` were mapped to a `dst`
                continue # with next `a`
            if p.is_identity():
                # `a` preserves the boundary cycles pointwise,
                # so it induces an automorphism of the numbered graph
                automorphisms.append(a)
                if a.compare_orientations() == -1:
                    orientable = False
            if (p not in P):
                # `a` induces permutation `p` on the set `bc`
                P.append(p)
                A.append(a)
        assert len(P) > 0 # XXX: should verify that `P` is a group!

        ## There will be as many distinct numberings as there are cosets
        ## of `P` in `Sym(n)`.
        if len(P) > 1:
            numberings = []
            for candidate in itertools.permutations(range(n)):
                if NumberedFatgraphPool._unseen(candidate, P, numberings):
                    numberings.append(list(candidate))
        else:
            # if `P` is the one-element group, then all orbits are trivial
            numberings = [ list(p) for p in itertools.permutations(range(n)) ]

        # things to remember
        self.graph = graph
        self.is_orientable = orientable
        self.numberings = numberings
        self.P = P
        self.A = A
        self.num_automorphisms = len(automorphisms)
Ejemplo n.º 3
0
def cycle_type_to_perm(cycle_type):
    d = {}
    cur = 0
    for k in cycle_type:
        for i in range(0, k):
            d[cur + i] = cur + (i + 1) % k
        cur += k
    return Permutation(d)
Ejemplo n.º 4
0
    def facets(self, edge, other):
        """Iterate over facets obtained by contracting `edge` and
        projecting onto `other`.

        Each returned item is a triple `(j, k, s)`, where:
          - `j` is the index of a `NumberedFatgraph` in `self`;
          - `k` is the index of a `NumberedFatgraph` in `other`;
          - `s` is the sign by which `self[j].contract(edge)` projects onto `other[k]`.
        Only triples for which `s != 0` are returned.

        Examples::
        
          >>> p0 = NumberedFatgraphPool(Fatgraph([Vertex([1, 2, 0, 1, 0]), Vertex([3, 3, 2])]))
          >>> p1 = NumberedFatgraphPool(Fatgraph([Vertex([0, 1, 0, 1, 2, 2])]))
          >>> list(NumberedFatgraphPool.facets(p0, 2, p1))
          [(0, 0, 1), (1, 1, 1)]
        """
        assert not self.graph.is_loop(edge)
        assert self.is_orientable
        assert other.is_orientable

        g0 = self.graph
        g1 = g0.contract(edge)
        g2 = other.graph
        assert len(g1.boundary_cycles) == len(g2.boundary_cycles)

        # compute isomorphism map `f1` from `g1` to `g2`: if there is
        # no such isomorphisms, then stop iteration (do this first so
        # then we do not waste time on computing if we need to abort
        # anyway)
        f1 = Fatgraph.isomorphisms(g1, g2).next()

        ## 1. compute map `phi0` induced on `g0.boundary_cycles` from the
        ##    graph map `f0` which contracts `edge`.
        ##
        (e1, e2) = g0.endpoints(edge)
        assert set(g1.boundary_cycles) == set([g0.contract_boundary_cycle(bcy, e1, e2)
                                               for bcy in g0.boundary_cycles]), \
            "NumberedFatgraphPool.facets():" \
            " Boundary cycles of contracted graph are not the same" \
            " as contracted boundary cycles of parent graph:" \
            " `%s` vs `%s`" % (g1.boundary_cycles,
                               [g0.contract_boundary_cycle(bcy, e1, e2)
                                for bcy in g0.boundary_cycles])
        phi0_inv = Permutation((i1, i0) for (i0, i1) in enumerate(
            g1.boundary_cycles.index(g0.contract_boundary_cycle(bc0, e1, e2))
            for bc0 in g0.boundary_cycles))
        ## 2. compute map `phi1` induced by isomorphism map `f1` on
        ##    the boundary cycles of `g1` and `g2`.
        ##
        phi1_inv = Permutation((i1, i0) for (i0, i1) in enumerate(
            g2.boundary_cycles.index(f1.transform_boundary_cycle(bc1))
            for bc1 in g1.boundary_cycles))
        assert len(phi1_inv) == len(g1.boundary_cycles)
        assert len(phi1_inv) == len(g2.boundary_cycles)
        ## 3. Compute the composite map `f1^(-1) * f0`.
        ##

        ## For every numbering `nb` on `g0`, compute the (index of)
        ## corresponding numbering on `g2` (under the composition map
        ## `f1^(-1) * f0`) and return a triple `(index of nb, index of
        ## push-forward, sign)`.
        ##
        ## In the following:
        ##
        ## - `j` is the index of a numbering `nb` in `self.numberings`;
        ## - `k` is the index of the corresponding numbering in `other.numberings`,
        ##   under the composition map `f1^(-1) * f0`;
        ## - `a` is the the unique automorphism `a` of `other.graph` such that::
        ##
        ##       self.numberings[j] = pull_back(<permutation induced by `a` applied to> other.numberings[k])
        ##
        ## - `s` is the pull-back sign (see below).
        ##
        ## The pair `k`,`a` is computed using the
        ## `NumberedFatgraphPool._index` (which see), applied to each
        ## of `self.numberings`, rearranged according to the
        ## permutation of boundary cycles induced by `f1^(-1) * f0`.
        ##
        for (j, (k, a)) in enumerate(
                other._index(phi1_inv.rearranged(phi0_inv.rearranged(nb)))
                for nb in self.numberings):
            ## there are three components to the sign `s`:
            ##   - the sign given by the ismorphism `f1`
            ##   - the sign of the automorphism of `g2` that transforms the
            ##     push-forward numbering into the chosen representative in the same orbit
            ##   - the alternating sign from the homology differential
            s = f1.compare_orientations() \
                * a.compare_orientations() \
                * minus_one_exp(g0.edge_numbering[edge])
            yield (j, k, s)
Ejemplo n.º 5
0
    def facets(self, edge, other):
        """Iterate over facets obtained by contracting `edge` and
        projecting onto `other`.

        Each returned item is a triple `(j, k, s)`, where:
          - `j` is the index of a `NumberedFatgraph` in `self`;
          - `k` is the index of a `NumberedFatgraph` in `other`;
          - `s` is the sign by which `self[j].contract(edge)` projects onto `other[k]`.
        Only triples for which `s != 0` are returned.

        Examples::
        
          >>> p0 = NumberedFatgraphPool(Fatgraph([Vertex([1, 2, 0, 1, 0]), Vertex([3, 3, 2])]))
          >>> p1 = NumberedFatgraphPool(Fatgraph([Vertex([0, 1, 0, 1, 2, 2])]))
          >>> list(NumberedFatgraphPool.facets(p0, 2, p1))
          [(0, 0, 1), (1, 1, 1)]
        """
        assert not self.graph.is_loop(edge)
        assert self.is_orientable
        assert other.is_orientable
        
        g0 = self.graph
        g1 = g0.contract(edge)
        g2 = other.graph
        assert len(g1.boundary_cycles) == len(g2.boundary_cycles)

        # compute isomorphism map `f1` from `g1` to `g2`: if there is
        # no such isomorphisms, then stop iteration (do this first so
        # then we do not waste time on computing if we need to abort
        # anyway)
        f1 = Fatgraph.isomorphisms(g1,g2).next()
        
        ## 1. compute map `phi0` induced on `g0.boundary_cycles` from the
        ##    graph map `f0` which contracts `edge`.
        ##
        (e1, e2) = g0.endpoints(edge)
        assert set(g1.boundary_cycles) == set([ g0.contract_boundary_cycle(bcy, e1, e2)
                                                for bcy in g0.boundary_cycles ]), \
               "NumberedFatgraphPool.facets():" \
               " Boundary cycles of contracted graph are not the same" \
               " as contracted boundary cycles of parent graph:" \
               " `%s` vs `%s`" % (g1.boundary_cycles,
                                  [ g0.contract_boundary_cycle(bcy, e1, e2)
                                    for bcy in g0.boundary_cycles ])
        phi0_inv = Permutation((i1,i0) for (i0,i1) in enumerate(
            g1.boundary_cycles.index(g0.contract_boundary_cycle(bc0, e1, e2))
            for bc0 in g0.boundary_cycles
            ))
        ## 2. compute map `phi1` induced by isomorphism map `f1` on
        ##    the boundary cycles of `g1` and `g2`.
        ##
        phi1_inv = Permutation((i1,i0) for (i0,i1) in enumerate(
            g2.boundary_cycles.index(f1.transform_boundary_cycle(bc1))
            for bc1 in g1.boundary_cycles
            ))
        assert len(phi1_inv) == len(g1.boundary_cycles)
        assert len(phi1_inv) == len(g2.boundary_cycles)
        ## 3. Compute the composite map `f1^(-1) * f0`.
        ##

        ## For every numbering `nb` on `g0`, compute the (index of)
        ## corresponding numbering on `g2` (under the composition map
        ## `f1^(-1) * f0`) and return a triple `(index of nb, index of
        ## push-forward, sign)`.
        ##
        ## In the following:
        ##
        ## - `j` is the index of a numbering `nb` in `self.numberings`;
        ## - `k` is the index of the corresponding numbering in `other.numberings`,
        ##   under the composition map `f1^(-1) * f0`;
        ## - `a` is the the unique automorphism `a` of `other.graph` such that::
        ##
        ##       self.numberings[j] = pull_back(<permutation induced by `a` applied to> other.numberings[k])
        ##
        ## - `s` is the pull-back sign (see below).
        ##
        ## The pair `k`,`a` is computed using the
        ## `NumberedFatgraphPool._index` (which see), applied to each
        ## of `self.numberings`, rearranged according to the
        ## permutation of boundary cycles induced by `f1^(-1) * f0`.
        ##
        for (j, (k, a)) in enumerate(other._index(phi1_inv.rearranged(phi0_inv.rearranged(nb)))
                                     for nb in self.numberings):
            ## there are three components to the sign `s`:
            ##   - the sign given by the ismorphism `f1`
            ##   - the sign of the automorphism of `g2` that transforms the
            ##     push-forward numbering into the chosen representative in the same orbit
            ##   - the alternating sign from the homology differential
            s = f1.compare_orientations() \
                * a.compare_orientations() \
                * minus_one_exp(g0.edge_numbering[edge])
            yield (j, k, s)