diff --git a/CHANGELOG.md b/CHANGELOG.md index fb2be60..50ecb90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed +- Fixed bug in `Perm.rtlmax_ltrmin_decomposition` and fixed associated tests. + ## 2.3.1 - 2025-06-13 ### Changed - Migrated from setup.py to modern pyproject.toml packaging with hatchling backend diff --git a/permuta/patterns/perm.py b/permuta/patterns/perm.py index 1020f0a..f6e3c12 100644 --- a/permuta/patterns/perm.py +++ b/permuta/patterns/perm.py @@ -2451,7 +2451,7 @@ def count_rtlmax_ltrmin_layers(self) -> int: Examples: >>> Perm((2, 7, 3, 1, 4, 8, 6, 0, 5)).count_rtlmax_ltrmin_layers() - 3 + 2 >>> Perm((5, 4, 3, 0, 2, 1)).count_rtlmax_ltrmin_layers() 1 """ @@ -2468,7 +2468,7 @@ def rtlmax_ltrmin_decomposition(self) -> Iterator[List[int]]: Examples: >>> list(Perm((2, 7, 3, 1, 4, 8, 6, 0, 5)).rtlmax_ltrmin_decomposition()) - [[0, 3, 5, 6, 7, 8], [0, 2], [0]] + [[0, 3, 5, 6, 7, 8], [0, 1, 2]] >>> list(Perm((5, 4, 3, 0, 2, 1)).rtlmax_ltrmin_decomposition()) [[0, 1, 2, 3, 4, 5]] """ @@ -2476,7 +2476,9 @@ def rtlmax_ltrmin_decomposition(self) -> Iterator[List[int]]: while len(perm) > 0: pos_set = set(itertools.chain(perm.rtlmax(), perm.ltrmin())) yield sorted(pos_set) - perm = Perm(perm[i] for i in range(len(perm)) if i not in pos_set) + perm = Perm.to_standard( + perm[i] for i in range(len(perm)) if i not in pos_set + ) def contains(self, *patts: "Patt") -> bool: """Check if self contains patts. diff --git a/tests/patterns/test_perm.py b/tests/patterns/test_perm.py index 44f8f34..4917138 100644 --- a/tests/patterns/test_perm.py +++ b/tests/patterns/test_perm.py @@ -1966,7 +1966,7 @@ def test_count_rtlmax_ltrmin_layers(): assert Perm((2, 1, 3, 0)).count_rtlmax_ltrmin_layers() == 1 assert Perm((2, 0, 1, 3)).count_rtlmax_ltrmin_layers() == 2 assert Perm((1, 3, 2, 7, 6, 5, 8, 0, 4)).count_rtlmax_ltrmin_layers() == 2 - assert Perm((0, 8, 2, 4, 5, 6, 3, 7, 1)).count_rtlmax_ltrmin_layers() == 4 + assert Perm((0, 8, 2, 4, 5, 6, 3, 7, 1)).count_rtlmax_ltrmin_layers() == 3 assert Perm((1, 0, 2)).count_rtlmax_ltrmin_layers() == 1 assert Perm((1, 2, 0, 3)).count_rtlmax_ltrmin_layers() == 2 assert Perm((3, 0, 2, 1)).count_rtlmax_ltrmin_layers() == 1 @@ -1974,7 +1974,7 @@ def test_count_rtlmax_ltrmin_layers(): assert Perm((1, 3, 2, 0)).count_rtlmax_ltrmin_layers() == 1 assert Perm(()).count_rtlmax_ltrmin_layers() == 0 assert Perm((5, 3, 7, 4, 2, 0, 6, 1)).count_rtlmax_ltrmin_layers() == 2 - assert Perm((0, 2, 1, 6, 4, 3, 5, 7, 8)).count_rtlmax_ltrmin_layers() == 4 + assert Perm((0, 2, 1, 6, 4, 3, 5, 7, 8)).count_rtlmax_ltrmin_layers() == 3 assert Perm((2, 1, 0)).count_rtlmax_ltrmin_layers() == 1 assert Perm((0, 2, 1)).count_rtlmax_ltrmin_layers() == 1 assert Perm((0, 8, 3, 5, 7, 4, 2, 6, 1)).count_rtlmax_ltrmin_layers() == 2 @@ -2003,8 +2003,7 @@ def test_rtlmax_ltrmin_decomposition(): ] assert list(Perm((2, 3, 0, 4, 1, 5)).rtlmax_ltrmin_decomposition()) == [ [0, 2, 5], - [1, 2], - [0], + [0, 1, 2], ] assert list(Perm((4, 0, 2, 5, 3, 1)).rtlmax_ltrmin_decomposition()) == [ [0, 1, 3, 4, 5],