Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions permuta/patterns/perm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -2468,15 +2468,17 @@ 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]]
"""
perm = self
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.
Expand Down
7 changes: 3 additions & 4 deletions tests/patterns/test_perm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,15 +1966,15 @@ 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
assert Perm((2, 0, 1)).count_rtlmax_ltrmin_layers() == 1
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
Expand Down Expand Up @@ -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],
Expand Down