Skip to content

Permutations gives each distinct permutation once, as WMA does - #2087

Merged
rocky merged 4 commits into
masterfrom
fix-permutations-repeated
Oct 31, 2026
Merged

rocky merged 4 commits into
masterfrom
fix-permutations-repeated

Conversation

@tombouctou

Copy link
Copy Markdown
Collaborator

Found while running the examples of Skiena and Pemmaraju's Computational Discrete Mathematics with the Combinatorica package and comparing every result with WMA 15.

Permutations[{a, b, b}] listed {a, b, b} twice, because permutations were taken by position. WMA gives the permutations that differ as lists, in the order of their first positional occurrence:

Permutations[{b, a, b}]   (* {{b, a, b}, {b, b, a}, {a, b, b}} *)

Only the distinct ones are built now. This keeps Combinatorica's ListGraphs[6, 3] from asking for all 15! orderings of a 0/1 vector, which ran out of memory; it has 455 distinct ones. Elements are told apart with SameQ, so 1 and 1. stay different, as in WMA. The doc example that showed the duplicates is updated.

All the fixes from this series together, merged on one branch: full pytest 4336 passed, 0 failed; doctests 4679 passed, 0 failed.

🤖 Generated with Claude Code

tombouctou and others added 4 commits October 30, 2026 10:00
Permutations[{a, b, b}] listed {a, b, b} twice: permutations were taken
by position. WMA gives the permutations that differ as lists, in the
order of their first positional occurrence. Building only those also
keeps Combinatorica's ListGraphs[6, 3] from asking for all 15! orderings
of a 0/1 vector (455 distinct), which ran out of memory.

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

rocky commented Oct 31, 2026

Copy link
Copy Markdown
Member

LGTM

@rocky
rocky merged commit ff5dce9 into master Oct 31, 2026
15 checks passed
@rocky
rocky deleted the fix-permutations-repeated branch October 31, 2026 14:29
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.

2 participants