Successor
The element after 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 where x is the -th element.Combinatorica
Module[{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
| Type | Package | Applies |
|---|---|---|
(indexed_collection<any>, any) -> unknown | combinatorics | always |
Details
- The next element in the collection's order, by rank: where is the position of in . 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 that is not an element of . There is no wraparound: write it with At and Mod, as in .
- Defined in Epsil as
Atat the positionIndexOffinds, one on; a declared family answers by its rank kernel, andtests/successor.test.tsholds 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, andNextTableaustays inside one shape where StandardTableaux goes on to the next. - Also reads a plain list: is .
- Not a Wolfram head: Wolfram has no successor of a collection element.
Examples
Basic #
Scope #
Properties #
About
| Examples | 16 |
|---|---|
| Checked against | Combinatorica 9 agree4 differ2 unevaluated1 error |
| Crosswalk | Combinatorica ×10 |
Implementation
mapped
combinatoricapackages/oracle/src/mappings.tsOne 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