Skip to content

Fix IntegerVectorsModPermutationGroup caching for different domains - #43088

Merged
vbraun merged 1 commit into
sagemath:developfrom
dimpase:fix/integer-vector-domain-cache
Nov 8, 2026
Merged

vbraun merged 1 commit into
sagemath:developfrom
dimpase:fix/integer-vector-domain-cache

Conversation

@dimpase

@dimpase dimpase commented Oct 30, 2026

Copy link
Copy Markdown
Member

IntegerVectorsModPermutationGroup can reuse a cached parent for a permutation group with a different domain. For example, constructing the parents for (1,2) acting on [1,2] and [1,2,3], both with sum 3, currently makes both return two-coordinate vectors. Reversing construction order changes which incorrect result is obtained.

Include tuple(G.domain()) in the UniqueRepresentation cache key of both concrete parent classes. This preserves caching and pickle identity while distinguishing different domains. The tuple retains the domain order because that order determines vector coordinates. Constructor normalization also covers direct calls to the concrete classes and .subset(), and recomputes the internal domain argument when unpickling.

The reported example now returns:

[[3, 0], [2, 1]]
[[3, 0, 0], [2, 1, 0], [2, 0, 1], [1, 1, 1], [1, 0, 2], [0, 0, 3]]

Replace the workaround warning with regression tests for the original example, reversed construction order, unconstrained parents, subsets, trivial actions and empty domains, repeat construction, and pickling. Retain UniqueRepresentation, avoiding the pickle-equality problem reported when removing it. This is a local fix; permutation-group equality and ordering remain the subject of #36912.

Fixes #36527.

Validation:

  • All 248 module doctests passed, including long tests and the new regressions.
  • A separate local check compared 220 constrained cases against independent brute-force orbit enumeration in both construction orders, using natural, labeled and reordered domains and explicit/default strong generating systems. Also checked unconstrained and maximum-part-only parents, repeated construction, parent pickle identity, and TestSuite on nonempty domains.
  • Both Ruff modes and git diff --check passed.

The tests loaded the modified Python module into the installed Homebrew Sage 11.0.beta1 environment; this was not a full rebuild of the current source tree. Broader checks also reproduced existing empty-domain bugs (an_element() returning [0], and bounded enumeration calling max([])); those are outside this cache-key fix. Empty-domain enumeration without a bound and parent pickle identity are covered here.

@mantepse mantepse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable, thank you!

vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 31, 2026
…ifferent domains

`IntegerVectorsModPermutationGroup` can reuse a cached parent for a
permutation group with a different domain. For example, constructing the
parents for `(1,2)` acting on `[1,2]` and `[1,2,3]`, both with sum 3,
currently makes both return two-coordinate vectors. Reversing
construction order changes which incorrect result is obtained.

Include `tuple(G.domain())` in the `UniqueRepresentation` cache key of
both concrete parent classes. This preserves caching and pickle identity
while distinguishing different domains. The tuple retains the domain
order because that order determines vector coordinates. Constructor
normalization also covers direct calls to the concrete classes and
`.subset()`, and recomputes the internal domain argument when
unpickling.

The reported example now returns:

```text
[[3, 0], [2, 1]]
[[3, 0, 0], [2, 1, 0], [2, 0, 1], [1, 1, 1], [1, 0, 2], [0, 0, 3]]
```

Replace the workaround warning with regression tests for the original
example, reversed construction order, unconstrained parents, subsets,
trivial actions and empty domains, repeat construction, and pickling.
Retain `UniqueRepresentation`, avoiding the pickle-equality problem
reported when removing it. This is a local fix; permutation-group
equality and ordering remain the subject of sagemath#36912.

Fixes sagemath#36527.

Validation:

- All 248 module doctests passed, including long tests and the new
regressions.
- A separate local check compared 220 constrained cases against
independent brute-force orbit enumeration in both construction orders,
using natural, labeled and reordered domains and explicit/default strong
generating systems. Also checked unconstrained and maximum-part-only
parents, repeated construction, parent pickle identity, and `TestSuite`
on nonempty domains.
- Both Ruff modes and `git diff --check` passed.

The tests loaded the modified Python module into the installed Homebrew
Sage 11.0.beta1 environment; this was not a full rebuild of the current
source tree. Broader checks also reproduced existing empty-domain bugs
(`an_element()` returning `[0]`, and bounded enumeration calling
`max([])`); those are outside this cache-key fix. Empty-domain
enumeration without a bound and parent pickle identity are covered here.

URL: sagemath#43088
Reported by: Dima Pasechnik
Reviewer(s): Martin Rubey
@vbraun
vbraun merged commit 12e2655 into sagemath:develop Nov 8, 2026
24 of 25 checks passed
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.

IntegerVectorsModPermutationGroup confuses groups whose domains are different

3 participants