Beispiel #1
0
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