Skip to main content
`Ctrl`+`K`

# PetscDTEnumPerm

Get a permutation of `n` integers from its encoding into the integers [0, n!) as a sequence of swaps.

## Input Parameters

- n - a non-negative integer (see note about limits below)

- k - an integer in [0, n!)

## Output Parameters

- perm - the permuted list of the integers [0, …, n-1]

- isOdd - if not `NULL`, returns whether the permutation used an even or odd number of swaps.

## Notes

A permutation can be described by the operations that convert the lists [0, 1, …, n-1] into the permutation, by a sequence of swaps, where the ith step swaps whatever number is in ith position with a number that is in some position j >= i. This swap is encoded as the difference (j - i). The difference d_i at step i is less than (n - i). This sequence of n-1 differences [d_0, …, d_{n-2}] is encoded as the number (n-1)! * d_0 + (n-2)! * d_1 + … + 1! * d_{n-2}.

Limited to `n` such that `n`! can be represented by `PetscInt`, which is 12 if `PetscInt` is a signed 32-bit integer and 20 if `PetscInt` is a signed 64-bit integer.

## See Also

`PetscDTFactorial()`, `PetscDTFactorialInt()`, `PetscDTBinomial()`, `PetscDTBinomialInt()`, `PetscDTPermIndex()`

## Level

intermediate

## Location

include/petscdt.h

Index of all DT routines
Table of Contents for all manual pages
Index of all manual pages