def from_steep_pair(steep, path): r""" Returns an LAC-tree in bijection with the given steep pair. A check is performed for validity. INPUT: - ``steep``: a steep path in the 0,1 format - ``path``: a Dyck path in the 0,1 format OUTPUT: An LAC-tree in bijection with this steep pair """ if len(steep) != len(path): raise ValueError('Inconsistent sizes of parameters') n = len(path) // 2 a1 = DyckWord(steep).to_area_sequence() a2 = DyckWord(path).to_area_sequence() for i in range(len(a1)): if a1[i] < a2[i]: raise ValueError('Incompatible parameters: not nested') Tc = DyckWord(path).to_ordered_tree().left_right_symmetry() Tc = Tc.canonical_labelling().left_right_symmetry() # extract marks from steep, 2 means marked north step marks = [True] for i in range(1, len(steep)): if steep[i] != 0: marks.append(0 != steep[i - 1]) marked = list(path) curptr = 0 for i in range(len(marked)): if marked[i] != 0: marked[i] = 2 if marks[curptr] else 1 curptr += 1 # coloring colorlist = [-1 for i in range(n + 2)] colorstack = [-1] colorptr = 0 curcolor = -1 curlabel = 0 colorlast = {} colorcount = {} labellist = [x.label() for x in Tc.pre_order_traversal_iter()] for x in marked: if 2 == x: curcolor += 1 colorptr += 1 colorstack.insert(colorptr, curcolor) curlabel += 1 colorlist[curlabel] = curcolor colorlast[curcolor] = labellist[curlabel] colorcount[curcolor] = 1 elif 1 == x: colorptr += 1 curlabel += 1 mycolor = colorstack[colorptr] colorlist[curlabel] = mycolor colorlast[mycolor] = labellist[curlabel] colorcount[mycolor] += 1 else: colorptr -= 1 alpha = sorted(colorlast.items(), key=lambda x: x[1]) alpha = list(map(lambda x: colorcount[x[0]], alpha)) return LACTree(Tc.shape().left_right_symmetry(), alpha)