Function Repository Resource:

IndexedOrderedTuple

Source Notebook

Give the index of an ordered tuple or return the ordered tuple with that index

Contributed by: Ed Pegg Jr

ResourceFunction["IndexedOrderedTuple"][choose,index]

returns an ordered tuple of length choose with given index.

ResourceFunction["IndexedOrderedTuple"][list]

gives the index of ordered tuple list.

Details and Options

For any positive integers n and k, n can be uniquely represented as k binomials, , where the aj terms are strictly increasing.

Examples

Basic Examples (3) 

Generate a list of the first ten 3-tuples:

In[1]:=
Table[ResourceFunction["IndexedOrderedTuple"][3, index], {index, 1, 10}]
Out[1]=

The function can return ordered tuples of a large index:

In[2]:=
sub3 = Table[
  ResourceFunction["IndexedOrderedTuple"][3, index], {index, 182101, 182110}]
Out[2]=

Applying the function to an ordered tuple returns the index:

In[3]:=
ResourceFunction["IndexedOrderedTuple"] /@ sub3
Out[3]=

Any increasing list of integers can be considered as a ordered tuple with a unique index:

In[4]:=
index = ResourceFunction[
  "IndexedOrderedTuple"][{182101, 182102, 182103, 182104, 182105, 182106, 182107, 182108, 182109, 182110}]
Out[4]=

The index above generates a unique ordered 10-tuple:

In[5]:=
ResourceFunction["IndexedOrderedTuple"][10, index]
Out[5]=

Scope (3) 

Here are some ordered 2-tuples with their indices to show their structure:

In[6]:=
doubles = # - {0, 1} & /@ SortBy[Subsets[Range[0, 5], {2}], Reverse];
Graphics[{Text[
     Style[Column[{StringJoin[ToString /@ #], ResourceFunction["IndexedOrderedTuple"][#]},
       Alignment -> Center], 20], #] & /@ doubles, Blue, Line[doubles]}]
Out[6]=

The ordered 2-tuple {4,4} has an index of :

In[7]:=
Binomial[4 + 0, 1] + Binomial[4 + 1, 2] + 1
Out[7]=

Recover the same information with IndexedOrderedTuple:

In[8]:=
ResourceFunction["IndexedOrderedTuple"][2, 15]
Out[8]=

The structure of ordered 3-tuples in 3D:

In[9]:=
triples = # - {0, 1, 2} & /@ SortBy[Subsets[Range[0, 5], {3}], Reverse];
Graphics3D[{Text[
     Style[Column[{StringJoin[ToString /@ #], ResourceFunction["IndexedOrderedTuple"][#]},
       Alignment -> Center], 20], #] & /@ triples, Blue, Line[triples]}]
Out[9]=

Properties and Relations (3) 

Use Tuples to produce ordered 3-tuples:

In[10]:=
SortBy[Union[Sort /@ Tuples[Range[0, 2], {3}]], Reverse]
Out[10]=

The same sequence of ordered 3-tuples can be obtained from ordered Subsets:

In[11]:=
# - {0, 1, 2} & /@ SortBy[Subsets[Range[0, 4], {3}], Reverse]
Out[11]=

IndexedOrderedTuple returns the same ordered tuples in the same sequence:

In[12]:=
Table[ResourceFunction["IndexedOrderedTuple"][3, index], {index, 1, 10}]
Out[12]=

Version History

  • 1.0.0 – 07 November 2019

Related Resources

License Information