# How to use the Inversions function?

The Inversions function counts the number of inversions in permutation p.

When I try it, I didn't got a number as the result.

How to use it correctly?

• In the future, please post your code as text, rather than as images. Jun 15, 2020 at 19:49
• OK, thank you for the suggestion. I'll follow it. @MarcoB Jun 15, 2020 at 19:50

## 1 Answer

You need to convert your permutation from a cycles form into a positional form, and note that you need to provide the missing 3, which I've put in a separate cycle because it's unchanged by the permutation:

perm = FromCycles[{{1, 4, 2, 5}, {3}}];

ToInversionVector[perm]
(* returns: {4, 3, 2, 0} *)

Inversions[perm]
(* returns: 9 *)

• Thank you for the answer! Btw, where can I learn more about cycles form and positional form? I searched around and not sure if I'm on the correct documentation page. Jun 15, 2020 at 19:53
• The Combinatorica documentation isn't too detailed, but it has a ToCycles[p] function, so I guessed that the permutations were like this. Also, if you have a cycles expressed permutation with no other cycles like for example {1,2}, make sure to do FromCycles[{{1,2}}] with a double pair of {} to get the positional form. Jun 15, 2020 at 20:01