"""Drawing partition basis diagrams [pi] of S_t. Boundary points: bottom b1..bm at x = 0..m-1 (y = 0), top t1..tn at x = j + (m-n)/2 (y = H). Blocks of size 2 are strands, blocks of size 3 are the trivalent vertex (black dot), blocks of size >= 4 are hollow nodes. Strands of different blocks may cross; such a crossing is the crossing c. """ from diag import fmt def pt(lbl, m, n, H): if lbl[0] == "b": return (int(lbl[1:]) - 1, 0.0) j = int(lbl[1:]) - 1 return (j + (m - n) / 2.0, H) def part_tikz(m, n, blocks, H=1.9, scale=0.5, vpos=None, yscale=None): vpos = vpos or {} cmds = [] ys = yscale or scale def P(x, y): return "(%s,%s)" % (fmt(x), fmt(y)) for bi, blk in enumerate(blocks): pts = [pt(l, m, n, H) for l in blk] if len(blk) == 2: (x1, y1), (x2, y2) = pts if y1 == y2: d = abs(x2 - x1) h = min(0.32 + 0.22 * (d - 1), 0.75) * H yy = h if y1 == 0 else H - h cmds.append("\\draw %s .. controls %s and %s .. %s;" % (P(x1, y1), P(x1, yy), P(x2, yy), P(x2, y2))) else: if y1 > y2: (x1, y1), (x2, y2) = (x2, y2), (x1, y1) cmds.append("\\draw %s .. controls %s and %s .. %s;" % (P(x1, 0), P(x1, H / 2), P(x2, H / 2), P(x2, H))) else: if bi in vpos: vx, vy = vpos[bi] vy = vy * H else: vx = sum(p[0] for p in pts) / len(pts) nb = sum(1 for p in pts if p[1] == 0) vy = H * (0.5 + 0.12 * (len(pts) - 2 * nb) / max(1, len(pts) - 2)) for (x, y) in pts: cy = y + (0.3 * H if y == 0 else -0.3 * H) cmds.append("\\draw %s .. controls %s .. %s;" % (P(x, y), P(x, cy), P(vx, vy))) if len(blk) == 3: cmds.append("\\fill %s circle (1.5pt);" % P(vx, vy)) else: cmds.append("\\draw[fill=white] %s circle (2.2pt);" % P(vx, vy)) body = "\n".join(cmds) return ("\\begin{tikzpicture}[x=%scm,y=%scm,baseline={([yshift=-0.55ex]current bounding box.center)},line width=0.6pt]\n" % (fmt(scale), fmt(ys)) + body + "\n\\end{tikzpicture}") def to_cyclic_blocks(m, n, blocks): """labels -> cyclic positions (b1..bm, tn..t1)""" def pos(l): if l[0] == "b": return int(l[1:]) - 1 j = int(l[1:]) return m + (n - j) from deligne import canon return canon([[pos(l) for l in b] for b in blocks])