'Returns the index of a permutation.
The index of a permutation is the sum of all subscripts j such
that p[j] is greater than p[j+1].
Examples
>>> from sympy.combinatorics.permutations import Permutation
>>> p = Permutation([3, 0, 2, 1, 4])
>>> p.index()
2'

def index(self):

    a = self.array_form
    return sum([j for j in range((len(a) - 1)) if (a[j] > a[(j + 1)])])
