Skip to content

Require Ru2143CoreStrategy's extra basis patterns to start with 1 - #214

Open
ulfarsson wants to merge 2 commits into
developfrom
ru2143-leading-one
Open

ulfarsson wants to merge 2 commits into
developfrom
ru2143-leading-one

Conversation

@ulfarsson

Copy link
Copy Markdown
Member

Ru2143CoreStrategy now applies only when each extra basis pattern starts with 1, as the result it cites requires. Its is_valid_extension, in permuta/enumeration_strategies/core_strategies.py, removed a leading 1 before checking a pattern but never required one, so the strategy claimed classes the paper does not enumerate, such as Av(213):

>>> from permuta import Perm
>>> from permuta.enumeration_strategies.core_strategies import Ru2143CoreStrategy
>>> ru, p2143 = Perm((1, 2, 0, 3)), Perm((1, 0, 3, 2))
>>> Ru2143CoreStrategy([ru, p2143, Perm((2, 1, 0, 3))]).applies()
False
>>> Ru2143CoreStrategy([Perm((1, 0, 2))]).applies()
False
>>> Ru2143CoreStrategy([ru, p2143, Perm((0, 2, 1, 3))]).applies()
True

On develop the first two give True, though neither Av(2143, 2314, 3214) nor Av(213) is of the form the paper enumerates. The third, Av(1324, 2143, 2314), where 1324 is 1 ⊕ 213, is of that form and still applies. Rd2134CoreStrategy and the other six core strategies already require the leading 1.

Details

Why

Section 10 of "Enumeration of Permutation Classes and Weighted Labelled Independent Sets" (Bean, Nadeau and Ulfarsson, arXiv 1912.07503) enumerates the classes Av(2314, 2143, 1 ⊕ P) in which each π in P avoids a mesh pattern and does not end in an increasing skew component. is_valid_extension tested those two conditions on fstrip(patt), which removes a leading 1 when there is one, so it accepted a pattern without a leading 1 that met the two conditions as it stood. Its sibling for Section 9, Rd2134CoreStrategy, requires patt[0] == 0, and the other six core strategies require the leading 1 through zero_plus_perm, zero_plus_skewind and zero_plus_sumind.

The fix is for anyone who asks Permuta which known results enumerate a class, as find_strategies does. On develop it names Corollary 10.5 for Av(213) and its symmetries Av(132), Av(231) and Av(312). The corollary does not enumerate them. For Av(213), whose counts are the Catalan numbers, the corollary with the P that develop reads, P = {213}, gives 1, 1, 2, 6, 21, 77, 287 , the counts of Av(1324, 2143, 2314).

The paper's statement of Corollary 10.5 names Av(2134, 2413, 1 ⊕ P), as Corollary 9.5 does, while the sentence before it and its B(x) are about Av(2314, 2143, …). So the new docstring cites Section 10, whose opening states the class.

What changes

  • Ru2143CoreStrategy.is_valid_extension returns False for a pattern that does not start with its minimum, before it strips the 1. Its docstring, new, says what it checks, with two examples.
  • tests/enumeration_strategies/test_core_strategies.py: TestRu2143 gets test_applies_only_if_each_extra_pattern_starts_with_1, on Av(2143, 2314, 3214) and Av(213), refused, and Av(1324, 2143, 2314), accepted. test_is_valid_extension gets 3214 and 1324.
  • CHANGELOG.md: an entry under Unreleased, Fixed.

A basis given with a redundant pattern that does not start with 1 is now refused too, as every other core strategy refuses it: none of them reduces the basis to its minimal one first.

Checks

  • tox: flake8, mypy, pylint and black pass. On CPython 3.15 all 698 tests pass, the new doctest among them; on PyPy 3.12, 696 pass and 2 are skipped, which need CPython's reference counting and tracemalloc.
  • Against develop: both changed tests fail at their new lines, on both Pythons.
  • Downstream: Tilings' 3,722 tests pass at its develop with this Permuta, on both Pythons.
  • Against the paper, by counts: a separate implementation of Section 10's form, with no Permuta, over the eight symmetries of each basis, compared with the strategy on every basis of one pattern up to length 6, and of 2314, 2143 and one or two more patterns. Where the form holds, Corollary 10.5's generating function was checked against brute-force counts to length 8. The strategy now agrees with the form on every basis, and the corollary counts every class it accepts correctly. Every class that only develop accepted is miscounted by the corollary with the P develop reads.
  • Faults: mutmut's 9 mutants of is_valid_extension are killed, and so is each fault made by hand that is not equivalent: the check skipped, forced, made on the last entry, or made after the 1 is stripped.
  • Speed: the strategy is no slower on either Python; it is faster on classes it refuses, which it now refuses before the mesh pattern is checked.

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 10:46
Section 10 of the paper enumerates Av(2314, 2143, 1 + P), but
is_valid_extension removed a leading 1 without requiring one, so the
strategy applied to classes it does not cover, such as Av(213) and
Av(2314, 2143, 3214). It now returns False for a pattern that does not
start with its minimum, as Rd2134CoreStrategy does, and a docstring
says what it checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Av(2143, 2314, 3214) lists its patterns by length and then by their
entries, as classes are written elsewhere.

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