2
$\begingroup$

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?

$\endgroup$
2
  • 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

5
$\begingroup$

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 *)
$\endgroup$
2
  • $\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, privacy policy and cookie policy

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