"""Hosts obtained by attaching one generator to two adjacent legs of a pattern.""" from pmap import PMap, from_word from rewrite import glue def attach(L, i, gen): """glue generator gen ('cap','T','X') onto legs i,i+1 (cyclic) of map L. Implemented by building the 'outer' map and gluing L into it.""" k = L.k # Build host as: a word realizing gen on positions i,i+1 of a k-box drawn as Hom(k,?): # we rotate L so that legs i,i+1 become positions 0,1 (bottom), apply gen at the bottom, # i.e. compose L (as Hom(0,k)... ) -- easier: construct directly. Lr = L.rotated(-i) # old position i -> new position 0 # view Lr as a k-box; new map = gen applied to positions 0,1. import itertools off = Lr.maxdart() + 1 nodes = dict(Lr.nodes) alpha = dict(Lr.alpha) b0, b1 = Lr.bdry[0], Lr.bdry[1] rest = Lr.bdry[2:] a0, a1 = alpha[b0], alpha[b1] del alpha[b0], alpha[b1] if gen == "cap": alpha[a0] = a1; alpha[a1] = a0 newb = rest elif gen == "T": # vertex with darts: (to a0), (to a1), (new boundary) ccw. # boundary ccw order is ... rest..., then legs 0,1. The new vertex sits # outside the disk; its ccw order: dart to leg1, dart to leg0, outer dart. d0, d1, dn, bn = off, off+1, off+2, off+3 nodes[("ext",)] = ("T", [d1, d0, dn]) alpha[d0]=a0; alpha[a0]=d0; alpha[d1]=a1; alpha[a1]=d1 alpha[dn]=bn; alpha[bn]=dn newb = [bn] + rest elif gen == "X": d0, d1, e0, e1, c0, c1 = off, off+1, off+2, off+3, off+4, off+5 # ccw at X (outside the disk): to leg1, to leg0, outer0, outer1 nodes[("ext",)] = ("X", [d1, d0, e0, e1]) alpha[d0]=a0; alpha[a0]=d0; alpha[d1]=a1; alpha[a1]=d1 alpha[e0]=c0; alpha[c0]=e0; alpha[e1]=c1; alpha[c1]=e1 newb = [c0, c1] + rest M = PMap(nodes, newb, alpha, Lr.loops) return M