Skip to content

Refuse a basis holding the pattern 1 in every core strategy - #216

Open
ulfarsson wants to merge 2 commits into
developfrom
core-strategies-one-point-basis
Open

ulfarsson wants to merge 2 commits into
developfrom
core-strategies-one-point-basis

Conversation

@ulfarsson

@ulfarsson ulfarsson commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Every core strategy now refuses a basis that holds the one-point pattern 1, such as [Perm((0,))], whose class Av(1) holds only the empty permutation. Before, four of them, RdCdCuCoreStrategy, RdCuCoreStrategy, Rd2134CoreStrategy and Ru2143CoreStrategy, raised an AssertionError, and so did find_strategies. The other four applied, though no corollary of the paper covers Av(1). The fix is in each strategy's is_valid_extension, in permuta/enumeration_strategies/core_strategies.py, which now returns False for the pattern 1:

>>> from permuta import Perm
>>> from permuta.enumeration_strategies import find_strategies
>>> [type(s).__name__ for s in find_strategies([Perm((0,))])]
['InsertionEncodingStrategy', 'FinitelyManySimplesStrategy']

On develop this raises an AssertionError. The two strategies left are right to apply, as Av(1) is finite. Every pattern of two or more points gets the same answer as before.

Details

Why

A core strategy checks a class against a corollary of Bean, Nadeau and Ulfarsson, "Enumeration of Permutation Classes and Weighted Labelled Independent Sets" (arXiv:1912.07503). Each corollary's class is Av(N, 1 ⊕ P), for the strategy's needed patterns N and a set P with the corollary's conditions, in Sections 4 to 10 alike. At the end of Section 3 the paper assumes throughout that the empty permutation is not in P. So each such class contains the permutation 1, none is Av(1), and 1 = 1 ⊕ ε is never an extra basis pattern.

is_valid_extension did not check this. Four strategies strip the pattern 1 down to the empty permutation, with bstrip or fstrip, and hand it to a helper that asserts its input is not empty (zero_plus_sumind, last_sum_component or last_skew_component), so they raised. find_strategies raised too, when it reached the first of them. The other four accepted 1, as the empty permutation is neither sum- nor skew-decomposable, and RuCuRdCdCoreStrategy checks only the leading 1.

The fix is for anyone who passes a basis that may hold 1 to find_strategies or to a core strategy, such as a basis a program builds.

What changes

  • Each of the eight is_valid_extension methods returns False for the pattern 1 before it reaches a helper that would fail on the empty permutation. Six do so with len(patt) > 1 and …. Rd2134CoreStrategy returns early for fewer than two points, before its first line takes the last sum component of the stripped pattern. Ru2143CoreStrategy checks that the pattern fstrip leaves is not empty, before taking its last skew component.
  • The check is on the pattern given, not in the helpers. RdCdCuCoreStrategy and RdCuCoreStrategy pass 1 to zero_plus_sumind for the extra pattern 12, which they accept on develop and which Corollaries 7.4 and 8.3 allow: 1^× is the empty permutation, sum-indecomposable as the paper defines it. So zero_plus_sumind must keep accepting 1.
  • CoreStrategy.is_valid_extension's docstring now says what an extra pattern is and why 1 is never one, with examples.
  • Tests:
    • test_no_core_strategy_applies_to_av_1 in tests/enumeration_strategies/test_core_strategies.py, run for each core strategy by name. The pattern 1 is not a valid extension, and the strategy applies neither to [1] nor to its needed patterns with 1.
    • test_a_two_point_pattern_is_judged_as_before, beside it, also for each core strategy, which pins the guard at two points: 12 stays an extra pattern for every strategy but Ru2143CoreStrategy, 21 for none, and each strategy applies to Av(12) and Av(21) as before.
    • test_find_strategies_for_av_1 in tests/enumeration_strategies/test_enumeration_strategies.py, the example above.
  • CHANGELOG.md: an entry under Unreleased, Fixed.

Checks

  • tox: flake8, mypy, pylint and black pass. On CPython 3.15 all 714 tests pass, the new doctest among them; on PyPy 3.12, 712 pass and 2 are skipped, which need CPython's reference counting and tracemalloc.
  • Against develop: the nine tests of the pattern 1 fail: four strategies raise, four apply, and find_strategies raises. The test of 12 and 21 passes there, as it should, and so do the other 37 tests in the two files.
  • Downstream: Tilings' 3,722 tests pass at its develop with this Permuta, on both Pythons.
  • Nothing else changes. For every core strategy, is_valid_extension on every pattern of length 0 to 7, and applies() on [q] and on its needed patterns with q for every q of length 1 to 5, and on [1, q] and its needed patterns with 1 and q for every q of length 2 to 4, were compared with develop. Every answer that differs is on a pattern or basis holding a pattern of at most one point, and goes from raising or True to False. On this branch no core strategy applies to a basis holding 1. The empty permutation, which no basis can hold (Av refuses it), still makes Ru2143CoreStrategy.is_valid_extension raise, as on develop.
  • Faults: mutmut's 54 mutants of the eight methods are killed but two that are equivalent. The guard's faults made by hand are killed too, and so is a one-point check in zero_plus_sumind in place of the guard, which the test of 12 and 21 catches.
  • Speed: every core strategy's applies() on 7,920 bases, each class built afresh, is no slower than on develop: level or faster under CPython in every round, and level under PyPy over 8 paired hash seeds, within the spread of two copies of develop. is_valid_extension called alone pays for its one comparison, about 0.1 µs a call under CPython.
  • Merges: none conflicts with Keep a copied PropertyBitmaps' labels apart from the original's #212, Document the memory cost of reading PropertyBitmaps.bitmaps #213, Require Ru2143CoreStrategy's extra basis patterns to start with 1 #214 or Read a class's minimal basis in the core strategies #215, one at a time or all together. With Require Ru2143CoreStrategy's extra basis patterns to start with 1 #214 and Read a class's minimal basis in the core strategies #215 merged too, the core strategies' tests and doctests pass, and no core strategy applies to Av(1).

AI assistance: written with Claude Code (Opus 5.5) as the Permuta developer, and reviewed before submission by Claude Code (Opus 5.5) as an automated reviewer; Henning Ulfarsson checked and opened it.

ulfarsson and others added 2 commits November 26, 2026 14:10
Four core strategies raised an AssertionError on a basis holding the
one-point pattern, and so did find_strategies, as they passed the empty
permutation to helpers that assert a non-empty input. The other four
applied. The paper's corollaries add patterns 1 + p with p non-empty,
so each of their classes contains 1 and none is Av(1). Each
is_valid_extension now returns False for a pattern of fewer than two
points, before any helper sees it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests gave only the pattern 1, so a guard one point too wide, or a
one-point check in zero_plus_sumind in place of the guard, passed them
all. The new test checks that 12 stays an extra pattern for every core
strategy but Ru2143CoreStrategy, that 21 is one for none, and that each
strategy applies to Av(12) and Av(21) as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant