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

More info: https://reference.wolfram.com/language/Combinatorica/ref/Inversions.html

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

How to use it correctly?

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

1 Answer 1


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}}];

(* returns: {4, 3, 2, 0} *)

(* returns: 9 *)
  • $\begingroup$ 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. $\endgroup$ Jun 15, 2020 at 19:53
  • 2
    $\begingroup$ 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. $\endgroup$
    – flinty
    Jun 15, 2020 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.