Skip to content

Successor ​

The element after xx in the collection's own order.

✓ checked against that system · ! checked, with disagreements (hover a chip)Combinatorica
Successor(collection, x)the element of collection that follows x, that is At(collection,k+1)At(collection, k + 1) where x is the kk-th element.
CombinatoricaModule[{c = collection, x = x, n, m, ind, refl}, n = Round[Log[2, Length[c]]]; m = Max[Append[Flatten[c], 0]]; ind[s_] := Table[Boole[MemberQ[s, i]], {i, n}]; refl[s_] := Sort[n + 1 - s]; Which[c === Permutations[Range[Length[x]]], NextPermutation[x], c === Partitions[Total[x]], NextPartition[x], c === Compositions[Total[x], Length[x]], NextComposition[x], c === Flatten[Map[Tableaux, Partitions[Length[Flatten[x]]]], 1], NextTableau[x], c === Subsets[Range[n]], NextSubset[Range[n], x], c === KSubsets[Range[m], Length[x]], NextKSubset[Range[m], x], c === Map[ind, BinarySubsets[Range[n]]], ind[NextBinarySubset[Range[n], Flatten[Position[x, 1]]]], c === Map[refl, GrayCodeSubsets[Range[n]]], NextGrayCodeSubset[Range[n], x], True, Missing["NotCombinatorica"]]]
Typed signatures
TypePackageApplies
(indexed_collection<any>, any) -> unknowncombinatoricsalways

Domain: Collections

Details
  • The next element in the collection's order, by rank: Successor(c,x)=At(c,k+1)Successor(c, x) = At(c, k + 1) where kk is the position of xx in cc. Families rank by arithmetic, so the call never builds the collection: the successor of the second-to-last permutation of twelve things is immediate.
  • Past the last element it stays unevaluated, and so does an xx that is not an element of cc. There is no wraparound: write it with At and Mod, as in At(c,Mod(IndexOf(c,x),Count(c))+1)At(c, Mod(IndexOf(c, x), Count(c)) + 1).
  • Defined in Epsil as At at the position IndexOf finds, one on; a declared family answers by its rank kernel, and tests/successor.test.ts holds the two together at every element of several small families.
  • The order is the collection's own: lexicographic for KSubsets and SymmetricGroup, largest part first for IntegerPartitions, and each family's record says the rest. Combinatorica's nine Next* functions are this one head over its listing orders; they wrap at the end, and NextTableau stays inside one shape where StandardTableaux goes on to the next.
  • Also reads a plain list: Successor(5,7,9,7)Successor({5, 7, 9}, 7) is 99.
  • Not a Wolfram head: Wolfram has no successor of a collection element.

Examples

Basic #

the permutation after 14321432 in lexicographic order

live ↗
InSuccessor(SymmetricGroup(4),Permutation⁡([1,4,3,2]))\mathrm{Successor}(\mathrm{SymmetricGroup}(4), {\operatorname{Permutation}}([1, 4, 3, 2]))OutPermutation⁡([2,1,3,4]){\operatorname{Permutation}}([2, 1, 3, 4])

partitions of 6 run largest part first, so 4+24 + 2 is followed by 4+1+14 + 1 + 1

live ↗
InSuccessor(IntegerPartitions(6),IntegerPartition⁡([4,2]))\mathrm{Successor}(\mathrm{IntegerPartitions}(6), {\operatorname{IntegerPartition}}([4, 2]))OutIntegerPartition⁡([4,1,1]){\operatorname{IntegerPartition}}([4, 1, 1])

the first weak composition of 3 into 3 parts is followed by 0+1+20 + 1 + 2

live ↗
InSuccessor(WeakCompositions(3,3),[0,0,3])\mathrm{Successor}(\mathrm{WeakCompositions}(3, 3), \bigl\lbrack0, 0, 3\bigr\rbrack)Out[0,1,2]\bigl\lbrack0, 1, 2\bigr\rbrack

within the shape (4,1)(4, 1)

live ↗
InSuccessor(StandardTableaux(5),StandardTableau⁡([[1,3,4,5],[2]]))\mathrm{Successor}(\mathrm{StandardTableaux}(5), {\operatorname{StandardTableau}}([[1, 3, 4, 5], [2]]))OutStandardTableau⁡([[1,2,4,5],[3]]){\operatorname{StandardTableau}}([[1, 2, 4, 5], [3]])

subsets run by size, then lexicographically

live ↗
InSuccessor(Subsets(3),Finset⁡(Tuple⁡(3,[1,2])))\mathrm{Successor}(\mathrm{Subsets}(3), \operatorname{Finset}(\operatorname{Tuple}(3,\bigl\lbrack1, 2\bigr\rbrack)))OutFinset⁡(Tuple⁡(3,[1,3]))\operatorname{Finset}(\operatorname{Tuple}(3,\bigl\lbrack1, 3\bigr\rbrack))

the 2-subsets of {1,…,5}\{1, \dots, 5\} in lexicographic order

live ↗
InSuccessor(KSubsets(5,2),Finset⁡(Tuple⁡(5,[2,5])))\mathrm{Successor}(\mathrm{KSubsets}(5, 2), \operatorname{Finset}(\operatorname{Tuple}(5,\bigl\lbrack2, 5\bigr\rbrack)))OutFinset⁡(Tuple⁡(5,[3,4]))\operatorname{Finset}(\operatorname{Tuple}(5,\bigl\lbrack3, 4\bigr\rbrack))

binary counting: 011011 is followed by 100100

live ↗
InSuccessor(BinaryStrings(3),[0,1,1])\mathrm{Successor}(\mathrm{BinaryStrings}(3), \bigl\lbrack0, 1, 1\bigr\rbrack)Out[1,0,0]\bigl\lbrack1, 0, 0\bigr\rbrack

consecutive subsets in Gray-code order differ by one element

live ↗
InSuccessor(GrayCodeSubsets(3),[1,2])\mathrm{Successor}(\mathrm{GrayCodeSubsets}(3), \bigl\lbrack1, 2\bigr\rbrack)Out[2]\bigl\lbrack2\bigr\rbrack
Scope #

a list is ordered by its positions

live ↗
InSuccessor([5,7,9],7)\mathrm{Successor}(\bigl\lbrack5, 7, 9\bigr\rbrack, 7)Out99

found by rank, without building the 479001600 permutations of 12

live ↗
InSuccessor(SymmetricGroup(12),SymmetricGroup(12)[479 001 599])\mathrm{Successor}(\mathrm{SymmetricGroup}(12), \mathrm{SymmetricGroup}(12)[479\,001\,599])OutPermutation⁡([12,11,10,9,8,7,6,5,4,3,2,1]){\operatorname{Permutation}}([12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1])
Properties #

weak compositions are not in lexicographic order: 0+1+20 + 1 + 2 is followed by 1+0+21 + 0 + 2, not 0+2+10 + 2 + 1

live ↗
InSuccessor(WeakCompositions(3,3),[0,1,2])\mathrm{Successor}(\mathrm{WeakCompositions}(3, 3), \bigl\lbrack0, 1, 2\bigr\rbrack)Out[1,0,2]\bigl\lbrack1, 0, 2\bigr\rbrack

the last tableau of one shape is followed by the first of the next

live ↗
InSuccessor(StandardTableaux(4),StandardTableau⁡([[1,2,3],[4]]))\mathrm{Successor}(\mathrm{StandardTableaux}(4), {\operatorname{StandardTableau}}([[1, 2, 3], [4]]))OutStandardTableau⁡([[1,3],[2,4]]){\operatorname{StandardTableau}}([[1, 3], [2, 4]])

the sixth subset in Gray-code order is followed by {1,3}\{1, 3\}

live ↗
InSuccessor(GrayCodeSubsets(3),[1,2,3])\mathrm{Successor}(\mathrm{GrayCodeSubsets}(3), \bigl\lbrack1, 2, 3\bigr\rbrack)Out[1,3]\bigl\lbrack1, 3\bigr\rbrack

the last element has no successor; the call is left as written

live ↗
InSuccessor(KSubsets(5,2),Finset⁡(Tuple⁡(5,[4,5])))\mathrm{Successor}(\mathrm{KSubsets}(5, 2), \operatorname{Finset}(\operatorname{Tuple}(5,\bigl\lbrack4, 5\bigr\rbrack)))OutSuccessor(KSubsets(5,2),Finset⁡(Tuple⁡(5,[4,5])))\mathrm{Successor}(\mathrm{KSubsets}(5, 2), \operatorname{Finset}(\operatorname{Tuple}(5,\bigl\lbrack4, 5\bigr\rbrack)))

a 3-subset is no element of the 2-subsets

live ↗
InSuccessor(KSubsets(5,2),Finset⁡(Tuple⁡(5,[1,2,3])))\mathrm{Successor}(\mathrm{KSubsets}(5, 2), \operatorname{Finset}(\operatorname{Tuple}(5,\bigl\lbrack1, 2, 3\bigr\rbrack)))OutSuccessor(KSubsets(5,2),Finset⁡(Tuple⁡(5,[1,2,3])))\mathrm{Successor}(\mathrm{KSubsets}(5, 2), \operatorname{Finset}(\operatorname{Tuple}(5,\bigl\lbrack1, 2, 3\bigr\rbrack)))

wrapping around is AtAt and ModMod: after the last 2-subset comes the first

live ↗
InKSubsets(5,2)[IndexOf(KSubsets(5,2),Finset⁡(Tuple⁡(5,[4,5]))) mod Count(KSubsets(5,2))+1]\mathrm{KSubsets}(5, 2)[\mathrm{IndexOf}(\mathrm{KSubsets}(5, 2), \operatorname{Finset}(\operatorname{Tuple}(5,\bigl\lbrack4, 5\bigr\rbrack)))\bmod\mathrm{Count}(\mathrm{KSubsets}(5, 2))+1]OutFinset⁡(Tuple⁡(5,[1,2]))\operatorname{Finset}(\operatorname{Tuple}(5,\bigl\lbrack1, 2\bigr\rbrack))
About
Examples16
Checked againstCombinatorica 9 agree4 differ2 unevaluated1 error
CrosswalkCombinatorica ×10

Implementation

mappedcombinatoricapackages/oracle/src/mappings.ts

One head for Combinatorica's Next* functions. The template recognizes the collection by its Combinatorica listing and calls the matching function, which wraps around at the last element where ours stays unevaluated; the collection and element are otherwise read as the family bindings read them.

See also: At, IndexOf, Count, Mod, KSubsets, SymmetricGroup, IntegerPartitions