Skip to content

Read a class's minimal basis in the core strategies - #215

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

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

Conversation

@ulfarsson

Copy link
Copy Markdown
Member

The core strategies now check a class's minimal basis, so a redundant pattern in the basis given no longer stops one from applying. CoreStrategy._applies_to_symmetry, in permuta/enumeration_strategies/core_strategies.py, checked every pattern given against its corollary's conditions, even one that contains another pattern of the basis:

>>> from permuta import Perm
>>> from permuta.enumeration_strategies.core_strategies import RuCuCoreStrategy
>>> ru, cu = Perm((1, 2, 0, 3)), Perm((2, 0, 1, 3))
>>> RuCuCoreStrategy([ru, cu, Perm((1, 2, 0, 3, 4))]).applies()
True

On develop this gives False, though 23145 contains 2314, so the class is Av(2314, 3124), which Corollary 4.3 enumerates. A basis now gets the same answer from every core strategy with or without redundant patterns, and so from find_strategies, which passes a caller's list through. On a minimal basis nothing changes.

Details

Why

A core strategy decides whether a class, in some symmetry, avoids the patterns its corollary needs and has every other basis pattern of the form the corollary allows. It read the basis as given, so a redundant pattern had to meet the corollary's conditions too, though it changes nothing in the class. Each extra pattern must start with 1 in every core strategy but Ru2143CoreStrategy, whose own fix is a separate pull request, so a redundant pattern without a leading 1 stopped them: RuCuCoreStrategy refused Av(2314, 3124, q) for each of the 28 patterns q of length 5 that contain 2314 or 3124 and do not start with 1, though each of these classes is Av(2314, 3124).

The minimal basis decides it exactly. Each corollary's condition is on one extra pattern alone, and a class has the form Av(N ∪ E), with each pattern of E allowed, exactly when it avoids the needed patterns N and every other pattern of its minimal basis is allowed: the minimal basis of Av(N ∪ E) is part of N ∪ E, and a class that avoids N is Av(N ∪ B) for its minimal basis B. So the answer now depends on the class alone, not on how its basis is written.

The fix is for anyone who passes a basis that is not minimal, to find_strategies or to a strategy, such as the patterns a search has collected.

What changes

  • CoreStrategy._applies_to_symmetry checks the patterns of Av.from_iterable(basis).basis, the class's minimal basis, which it already built, in place of the basis given. Its docstring, rewritten, says what it checks, with an example. basis keeps the patterns as given.
  • tests/enumeration_strategies/test_core_strategies.py gets three tests:
    • TestRuCu.test_a_redundant_pattern_is_ignored;
    • TestRuCu.test_a_pattern_redundant_through_an_extra_pattern_is_ignored, where 21345 is redundant through 1234 rather than through a needed pattern;
    • test_a_redundant_pattern_changes_no_core_strategy, run for each core strategy by name. It adds to the strategy's needed patterns a pattern that contains one of them and does not start with 1.
  • CHANGELOG.md: an entry under Unreleased, Fixed.

Checks

  • tox: flake8, mypy, pylint and black pass. On CPython 3.15 all 707 tests pass, the new doctest among them; on PyPy 3.12, 705 pass and 2 are skipped, which need CPython's reference counting and tracemalloc.
  • Against develop: the new tests fail, but for the third test's cases of RdCdCoreStrategy and Ru2143CoreStrategy: a symmetry lets the first take that redundant pattern, and the second does not yet ask for a leading 1. A tempting wrong fix, which skips each given pattern that contains a needed one in place of reading the minimal basis, fails the test of 21345.
  • Downstream: Tilings' 3,722 tests pass at its develop with this Permuta, on both Pythons.
  • By brute force, with bases and containment computed apart from Permuta: every core strategy on 2,111 minimal bases (its needed patterns with each pattern of length 1 to 5, and each single pattern of length 2 to 5), and on 79,746 cases of such a basis with a redundant pattern added. On a minimal basis the strategies answer as on develop; with a redundant pattern they give their answer on the minimal basis, always. develop differed only by refusing.
  • Faults: mutmut's 10 mutants of _applies_to_symmetry are killed, and so is each fault made by hand that is not equivalent: develop's line, the needed patterns not left out, any for all, the redundant patterns checked in place of the minimal ones, and the wrong fix above.
  • Speed: every core strategy on 7,920 bases, each class built afresh, is no slower than on develop: level or faster under CPython in every round, and faster under PyPy on 6 of 8 paired hash seeds.
  • Merges: none conflicts with Keep a copied PropertyBitmaps' labels apart from the original's #212, with bitmaps-memory-note, or with the separate fix to Ru2143CoreStrategy. With that fix merged too, Ru2143CoreStrategy agrees on every basis above, minimal or not, with the form Section 10 of Bean, Nadeau and Ulfarsson enumerates, but on Av(1). There the one-point pattern makes four core strategies raise AssertionError, RdCdCuCoreStrategy, RdCuCoreStrategy, Rd2134CoreStrategy and Ru2143CoreStrategy, on develop and with both fixes alike.

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 12:05
A core strategy checked every pattern of the basis given against its
corollary's conditions, so a redundant pattern, one that contains
another pattern of the basis, could stop it from applying, as 23145
did for RuCuCoreStrategy with 2314 and 3124. It now checks the minimal
basis of the class it already builds, so its answer depends on the
class alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tegy

21345 contains 1234 but neither needed pattern, so a check that skipped
only the patterns containing a needed one would refuse
Av(1234, 2314, 3124, 21345). The test over every core strategy now runs
once for each, under its name.

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