def from_bounce_pair(dyck, alpha): r""" Returns an LAC-tree in bijection with the given bounce pair. A check is performed for validity. INPUT: - ``dyck``: a Dyck path in the 0,1 format - ``alpha``: a composition indicating the bounce path OUTPUT: An LAC-tree in bijection with this bounce pair """ n = sum(alpha) if n * 2 != len(dyck): raise ValueError('Inconsistent sizes of parameters') bounce = [] for a in alpha: bounce += ([1] * a) + ([0] * a) dwa = DyckWord(dyck) dwb = DyckWord(bounce) area_a = dwa.to_area_sequence() area_b = dwb.to_area_sequence() if not all(area_a[i] >= area_b[i] for i in range(n)): raise ValueError('Incompatible parameters') # count children number by counting north steps on each x-coordinate vsteps = [0] * (n + 1) cur = 0 x = 0 while cur < len(dyck): while 1 == dyck[cur]: cur += 1 vsteps[x] += 1 cur += 1 x += 1 # construct tree l = len(alpha) dyckpost = n - alpha[l - 1] actives = [OrderedTree([]) for i in range(alpha[l - 1])] for region in range(l - 2, -1, -1): newactives = [] for i in range(alpha[region]): newnode = OrderedTree(actives[:vsteps[dyckpost]]) actives = actives[vsteps[dyckpost]:] newactives.append(newnode) dyckpost -= 1 actives = newactives + actives T = OrderedTree(actives) # coloring with existent function return LACTree(T, alpha)
def from_labelled_dyck_word(LDW): r""" Return the parking function corresponding to the labelled Dyck word. INPUT: - ``LDW`` -- labelled Dyck word OUTPUT: - the parking function corresponding to the labelled Dyck word that is half the size of ``LDW`` EXAMPLES:: sage: from sage.combinat.parking_functions import from_labelled_dyck_word sage: LDW = [2, 6, 0, 4, 5, 0, 0, 0, 3, 7, 0, 1, 0, 0] sage: from_labelled_dyck_word(LDW) [6, 1, 5, 2, 2, 1, 5] :: sage: from_labelled_dyck_word([2, 3, 0, 0, 1, 0, 4, 0]) [3, 1, 1, 4] sage: from_labelled_dyck_word([2, 3, 4, 0, 0, 0, 1, 0]) [4, 1, 1, 1] sage: from_labelled_dyck_word([2, 4, 0, 1, 0, 0, 3, 0]) [2, 1, 4, 1] """ L = [ell for ell in LDW if ell != 0] D = DyckWord(map(lambda x: Integer(not x.is_zero()), LDW)) return from_labelling_and_area_sequence(L, D.to_area_sequence())
def from_labelled_dyck_word(LDW): r""" Returns the parking function corresponding to the labelled Dyck word. INPUT: - ``LDW`` -- labelled Dyck word OUTPUT: - returns the parking function corresponding to the labelled Dyck word that is half the size of ``LDW`` EXAMPLES:: sage: from sage.combinat.parking_functions import from_labelled_dyck_word sage: LDW = [2, 6, 0, 4, 5, 0, 0, 0, 3, 7, 0, 1, 0, 0] sage: from_labelled_dyck_word(LDW) [6, 1, 5, 2, 2, 1, 5] :: sage: from_labelled_dyck_word([2, 3, 0, 0, 1, 0, 4, 0]) [3, 1, 1, 4] sage: from_labelled_dyck_word([2, 3, 4, 0, 0, 0, 1, 0]) [4, 1, 1, 1] sage: from_labelled_dyck_word([2, 4, 0, 1, 0, 0, 3, 0]) [2, 1, 4, 1] """ L = [ell for ell in LDW if ell!=0] D = DyckWord(map(lambda x: Integer(not x.is_zero()), LDW)) return from_labelling_and_area_sequence(L, D.to_area_sequence())