From 8b64d9a379badb2395591c10cb662f3345bfc272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 7 Oct 2025 11:56:43 +0200 Subject: [PATCH] implement the lattice of Baxter permutations --- src/doc/en/reference/references/index.rst | 5 +++ src/sage/combinat/baxter_permutations.py | 46 +++++++++++++++++------ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/doc/en/reference/references/index.rst b/src/doc/en/reference/references/index.rst index c01a2ab88f8..1f1cd007290 100644 --- a/src/doc/en/reference/references/index.rst +++ b/src/doc/en/reference/references/index.rst @@ -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 diff --git a/src/sage/combinat/baxter_permutations.py b/src/sage/combinat/baxter_permutations.py index 6cddccb1940..8face317a05 100644 --- a/src/sage/combinat/baxter_permutations.py +++ b/src/sage/combinat/baxter_permutations.py @@ -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 @@ -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:: @@ -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. @@ -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""" @@ -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:: @@ -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``. @@ -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. @@ -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. @@ -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