Function Repository Resource:

PermutationAscents

Source Notebook

Give the indices of a permutation where there is an immediate ascent

Contributed by: Wolfram Staff

ResourceFunction["PermutationAscents"][p]

gives the indices i where pi<pi+1, where the permutation p={p1,p2,,pn} is written as a list.

Details and Options

List notation for a permutation is also called one-line notation.

Examples

Basic Examples (3) 

Consider the permutation:

In[1]:=
p = {2, 8, 1, 5, 4, 7, 6, 3, 9};

Its ascents are at the indices 1, 3, 5, 8, corresponding to 2 < 8, 1 < 5, 4 < 7, 3 < 9:

In[2]:=
ResourceFunction["PermutationAscents"]@p
Out[2]=

The descents follow easily:

In[3]:=
Reverse[Length@p - ResourceFunction["PermutationAscents"]@Reverse@p]
Out[3]=

Possible Issues (4) 

A permutation in cycle form:

In[4]:=
c = Cycles[{{3, 2}, {1, 6, 7}}];

This does not work:

In[5]:=
ResourceFunction["PermutationAscents"]@c
Out[5]=

Convert from cycle to list form:

In[6]:=
q = PermutationList[Cycles[{{3, 2}, {1, 6, 7}}]]
Out[6]=

Now this finds the ascents:

In[7]:=
ResourceFunction["PermutationAscents"]@q
Out[7]=

Publisher

George Beck

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 15 March 2019

Related Resources

License Information