Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/doc/en/reference/references/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4427,6 +4427,11 @@ REFERENCES:
modular forms*, LMS J. of Comput. Math. 14 (2011),
214-231.

.. [Law2011] Shirley Law and Nathan Reading,
*The Hopf algebra of diagonal rectangulations*,
\J. Comb. Theory, Ser. A 119, No. 3, 788-824 (2012).
:doi:`10.1016/j.jcta.2011.09.006`

.. [Laz1992] Daniel Lazard, *Solving Zero-dimensional Algebraic
Systems*, in Journal of Symbolic Computation (1992)
vol\. 13, pp\. 117-131
Expand Down
46 changes: 34 additions & 12 deletions src/sage/combinat/baxter_permutations.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"""
Baxter permutations
"""
from typing import Iterator

from sage.combinat.permutation import Permutations
from sage.combinat.posets.lattices import LatticePoset
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.sets.disjoint_union_enumerated_sets import (
DisjointUnionEnumeratedSets
)
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation

Expand Down Expand Up @@ -68,8 +73,7 @@ class BaxterPermutations_size(BaxterPermutations):
sage: BaxterPermutations_size(5)
Baxter permutations of size 5
"""

def __init__(self, n):
def __init__(self, n) -> None:
"""
EXAMPLES::

Expand Down Expand Up @@ -145,7 +149,7 @@ def __contains__(self, x) -> bool:
return False
return True

def __iter__(self):
def __iter__(self) -> Iterator:
r"""
Efficient generation of Baxter permutations.

Expand Down Expand Up @@ -234,6 +238,24 @@ def cardinality(self):
n.binomial(k + 2)) // (n * n.binomial(2))
for k in range(self._n))

def lattice(self):
"""
Return the lattice of Baxter permutations.

This is defined by restriction of the weak order.

EXAMPLES::

sage: L = BaxterPermutations(4).lattice(); L
Finite lattice containing 22 elements

REFERENCES:

- [Law2011]_
"""
return LatticePoset([list(self), lambda a, b: a.weak_le(b)],
check=False)


class BaxterPermutations_all(DisjointUnionEnumeratedSets, BaxterPermutations):
r"""
Expand All @@ -248,8 +270,7 @@ class BaxterPermutations_all(DisjointUnionEnumeratedSets, BaxterPermutations):
sage: BaxterPermutations_all()
Baxter permutations
"""

def __init__(self, n=None):
def __init__(self, n=None) -> None:
r"""
EXAMPLES::

Expand All @@ -265,7 +286,7 @@ def __init__(self, n=None):
BaxterPermutations_size),
facade=False, keepkey=False)

def _repr_(self):
def _repr_(self) -> str:
r"""
Return a string representation of ``self``.

Expand All @@ -277,7 +298,7 @@ def _repr_(self):
"""
return "Baxter permutations"

def __contains__(self, x):
def __contains__(self, x) -> bool:
r"""
Return ``True`` if and only if ``x`` is a Baxter permutation.

Expand All @@ -301,7 +322,7 @@ def __contains__(self, x):
return False
return x in BaxterPermutations(len(x))

def to_pair_of_twin_binary_trees(self, p):
def to_pair_of_twin_binary_trees(self, p) -> tuple:
r"""
Apply a bijection between Baxter permutations of size ``self._n``
and the set of pairs of twin binary trees with ``self._n`` nodes.
Expand All @@ -327,12 +348,13 @@ def to_pair_of_twin_binary_trees(self, p):

EXAMPLES::

sage: # needs sage.graphs
sage: BP = BaxterPermutations()
sage: BP.to_pair_of_twin_binary_trees(Permutation([])) # needs sage.graphs
sage: BP.to_pair_of_twin_binary_trees(Permutation([]))
(., .)
sage: BP.to_pair_of_twin_binary_trees(Permutation([1, 2, 3])) # needs sage.graphs
sage: BP.to_pair_of_twin_binary_trees(Permutation([1, 2, 3]))
(1[., 2[., 3[., .]]], 3[2[1[., .], .], .])
sage: BP.to_pair_of_twin_binary_trees(Permutation([3, 4, 1, 2])) # needs sage.graphs
sage: BP.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
Expand Down
Loading