Skip to content

Add cache keys for combinations#42458

Open
Ap4sh wants to merge 1 commit into
sagemath:developfrom
Ap4sh:combinations-cache-key
Open

Add cache keys for combinations#42458
Ap4sh wants to merge 1 commit into
sagemath:developfrom
Ap4sh:combinations-cache-key

Conversation

@Ap4sh

@Ap4sh Ap4sh commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

This adds _cache_key() to the finite Combinations parents so they can be used by cached constructions such as cartesian_product

The issue was that Combinations(...) parents define equality but are not hashable, and they also did not provide _cache_key(). That made cartesian_product([Combinations([1,2,3], 2), Combinations([1,2,3], 2)]) fail while building the cached Cartesian product parent

The change keeps the parents unhashable and only adds cache keys for the existing cache machinery. The key includes the concrete class, the multiset data, k when present, and the as_tuples output mode

Fixes #39004
Related to #19986

Checks:

  • reproduced the failure on the current dev image before the patch
  • ./sage -t --long src/sage/combinat/combination.py
  • ./sage -tox -e relint -- src/sage/combinat/combination.py
  • ./sage -tox -e rst -- src/sage/combinat/combination.py
  • manual checks for set, multiset, fixed-length, and as_tuples combinations inside cartesian_product

📝 Checklist

  • The title is concise and informative
  • The description explains in detail what this PR is about
  • I have linked a relevant issue or discussion
  • I have created tests covering the changes
  • I have updated the documentation and checked the documentation preview

⌛ Dependencies

None

@github-actions

Copy link
Copy Markdown

Documentation preview for this PR (built with commit a97f106; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@Ap4sh Ap4sh marked this pull request as ready for review June 30, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cartesian product of Combinations fails

1 participant