Example #1
0
    def to_pair_of_twin_binary_trees(self, p):
        r"""
        Apply a bijection between Baxter permutations of size ``self._n``
        and the set of pairs of twin binary trees with ``self._n`` nodes.

        INPUT:

        - ``p`` -- a Baxter permutation.

        OUTPUT:

        The pair of twin binary trees `(T_L, T_R)` where `T_L`
        (resp. `T_R`) is obtained by inserting the letters of ``p`` from
        left to right (resp. right to left) following the the binary search
        tree insertion algorithm. This is called the *Baxter P-symbol*
        in [Gir12]_ Definition 4.1.

        .. NOTE::

            This method only works when ``p`` is a permutation. For words
            with repeated letters, it would return two "right binary
            search trees" (in the terminology of [Gir12]_), which conflicts
            with the definition in [Gir12]_.

        EXAMPLES::

            sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([]))
            (., .)
            sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([1, 2, 3]))
            (1[., 2[., 3[., .]]], 3[2[1[., .], .], .])
            sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([3, 4, 1, 2]))
            (3[1[., 2[., .]], 4[., .]], 2[1[., .], 4[3[., .], .]])
        """
        from sage.combinat.binary_tree import LabelledBinaryTree

        left = LabelledBinaryTree(None)
        right = LabelledBinaryTree(None)
        for a in p:
            left = left.binary_search_insert(a)
        for a in reversed(p):
            right = right.binary_search_insert(a)
        return (left, right)
Example #2
0
    def to_pair_of_twin_binary_trees(self, p):
        r"""
        Apply a bijection between Baxter permutations of size ``self._n``
        and the set of pairs of twin binary trees with ``self._n`` nodes.

        INPUT:

        - ``p`` -- a Baxter permutation.

        OUTPUT:

        The pair of twin binary trees `(T_L, T_R)` where `T_L`
        (resp. `T_R`) is obtained by inserting the letters of ``p`` from
        left to right (resp. right to left) following the binary search
        tree insertion algorithm. This is called the *Baxter P-symbol*
        in [Gir2012]_ Definition 4.1.

        .. NOTE::

            This method only works when ``p`` is a permutation. For words
            with repeated letters, it would return two "right binary
            search trees" (in the terminology of [Gir2012]_), which conflicts
            with the definition in [Gir2012]_.

        EXAMPLES::

            sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([]))
            (., .)
            sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([1, 2, 3]))
            (1[., 2[., 3[., .]]], 3[2[1[., .], .], .])
            sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([3, 4, 1, 2]))
            (3[1[., 2[., .]], 4[., .]], 2[1[., .], 4[3[., .], .]])
        """
        from sage.combinat.binary_tree import LabelledBinaryTree
        left = LabelledBinaryTree(None)
        right = LabelledBinaryTree(None)
        for a in p:
            left = left.binary_search_insert(a)
        for a in reversed(p):
            right = right.binary_search_insert(a)
        return (left, right)