def __init__(self, spec=None): self.dict = dict() if spec is None: spec = PerfectMatching([]) if isinstance(spec, dict): self.dict = spec if isinstance(spec, PerfectMatching): assert spec.is_noncrossing() self.dict[spec] = R.one()
def cap_off(matching, i): """ Merge i and i + 1 with a cap. Returns a new matching and whether or not a circle was created. >>> m = PerfectMatching([(0, 5), (1, 4), (2, 3)]) >>> cap_off(m, 2) ([(0, 3), (1, 2)], True) >>> cap_off(m, 3) ([(0, 3), (1, 2)], False) """ def shift(a): return a if a < i else a - 2 def follow(a): b = matching.partner(a) if b == i: b = matching.partner(i + 1) elif b == i + 1: b = matching.partner(i) return b n = len(matching.base_set()) circle = matching.partner(i) == i + 1 new_match = set() for a in range(n): if not a in {i, i + 1}: u, v = shift(a), shift(follow(a)) if u > v: u, v = v, u new_match.add((u, v)) return PerfectMatching(new_match), circle
def kauffman_bracket(link): """ >>> L = Link('T(2, 3)') >>> kauffman_bracket(L) q^-2 + 1 + q^2 - q^6 """ ans = VElement() if isinstance(link, exhaust.MorseEncoding): encoded = link else: exhaustion = exhaust.MorseExhaustion(link) encoded = exhaust.MorseEncoding(exhaustion) for event in encoded: if event.kind == 'cup': ans = ans.insert_cup(event.min) elif event.kind == 'cap': ans = ans.cap_off(event.min) else: assert event.kind == 'cross' if event.a < event.b: ans = ans.add_positive_crossing(event.min) else: ans = ans.add_negative_crossing(event.min) assert ans.is_multiple_of_empty_pairing() return ans.dict[PerfectMatching([])]
def insert_cup(matching, i): """ Insert a new adjacent matching which joins i and i + 1. >>> m = PerfectMatching([(0, 1), (2, 5), (3, 4)]) >>> insert_cup(m, 0) [(0, 1), (2, 3), (4, 7), (5, 6)] >>> insert_cup(m, 1) [(0, 3), (1, 2), (4, 7), (5, 6)] >>> insert_cup(m, 6) [(0, 1), (2, 5), (3, 4), (6, 7)] """ assert len(matching.base_set()) >= i def shift(pair): return [a if a < i else a + 2 for a in pair] return PerfectMatching([shift(pair) for pair in matching] + [(i, i + 1)])
def is_multiple_of_empty_pairing(self): return len(self.dict) == 1 and (PerfectMatching([]) in self.dict)