def _cross(sd, start1, end1, start2, end2): """Cross the two strands (start1, end1) and (start2, end2) of the strand diagram on the given side of start_gen. """ strand_lst = list(sd.strands) strand_lst.remove((start1, end1)) strand_lst.remove((start2, end2)) if start1 != end2: strand_lst.append((start1, end2)) if start2 != end1: strand_lst.append((start2, end1)) result_sd = StrandDiagram(sd.parent, sd.getLeftIdem(), strand_lst) assert sd in result_sd.diff() return result_sd
def _factor(sd, a, b): """Try to factor off a strand (a, b) (from the left) from sd. Returns the new strand diagram if successful. Otherwise returns None. """ strand_lst = list(sd.strands) for p, q in [(p, q) for p,q in strand_lst if p == a and q >= b]: strand_lst.remove((p, q)) if q > b: strand_lst.append((b, q)) result = StrandDiagram(sd.parent, None, strand_lst, sd.getRightIdem()) to_mult = StrandDiagram(sd.parent, None, [(a, b)], result.getLeftIdem()) if to_mult * result == 1 * sd: return result else: return None
def __init__(self, parent, left_idem, strands, right_idem=None): """Be sure to use MinusStrands to convert strands.""" if not isinstance(strands, MinusStrands): strands = MinusStrands(parent.pmc, strands) StrandDiagram.__init__(self, parent, left_idem, strands, right_idem)