Skip to content

SortingIndex ​

The total distance the entries move in selection sort.

✓ checked against that system · ! checked, with disagreements (hover a chip)FindStatSt000224via Permutation✓
SortingIndex(p)The total distance the entries move in selection sort.
Typed signatures
TypePackageApplies
(permutation) -> numbercombinatoricsalways

Domain: Permutation statistics

Details
  • Defined over Permutation as an expression in _x, evaluated by compute-engine — the definition IS the implementation.
  • Takes a Permutation and nothing else — it reads values against their positions, or walks the orbits, so it needs the bijection. Applying it to a bare list is a type error, not a wrong answer.
  • Selection sort swaps n into place, then n - 1, and so on; the fold carries the total and the word.

Definition

Epsil, as the implementation runs it.

on Permutation, over _x

0 if Length(_x) < 1 else Fold(Function(Apply(
                                              Function((
                                                         a[1] + (b - t),
                                                         ReplaceAt(ReplaceAt(
                                                                              a[2],
                                                                              t,
                                                                              a[2][b],
                                                                            ), b, b),
                                                       ), t),
                                              Sum(Map(
                                                       Function(j if a[2][j] ==
                                                                     b else 0, j),
                                                       Range(1, Length(_x)),
                                                     )),
                                            ), a, b), (0, _x), Range(
                                                                     Length(_x),
                                                                     1,
                                                                     -1,
                                                                   ))[1]

Examples

Basic #

the one-line word 312312

live ↗
InSortingIndex(Permutation⁡([3,1,2]))\mathrm{SortingIndex}({\operatorname{Permutation}}([3, 1, 2]))Out33

the one-line word 24132413

live ↗
InSortingIndex(Permutation⁡([2,4,1,3]))\mathrm{SortingIndex}({\operatorname{Permutation}}([2, 4, 1, 3]))Out44
Properties #

FindStat's value for [1]

live ↗
InCombinatorialStat(Permutation⁡([1]),SortingIndex)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([1]), \text{SortingIndex})Out00

Known value · FindStat St000224

FindStat's value for [1,2]

live ↗
InCombinatorialStat(Permutation⁡([1,2]),SortingIndex)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([1, 2]), \text{SortingIndex})Out00

Known value · FindStat St000224

FindStat's value for [2,1]

live ↗
InCombinatorialStat(Permutation⁡([2,1]),SortingIndex)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([2, 1]), \text{SortingIndex})Out11

Known value · FindStat St000224

About
Examples5
CrosswalkFindStat