petsc-3.13.6 2020-09-29
Report Typos and Errors

PetscDTEnumPerm

Get a permutation of n integers from its encoding into the integers [0, n!) as a sequence of swaps. 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}.

Input Arguments

n - a non-negative integer (see note about limits below)
k - an integer in [0, n!)

Output Arguments

perm - the permuted list of the integers [0, ..., n-1]
isOdd - if not NULL, returns wether the permutation used an even or odd number of swaps.

Note: this is 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.

Level

beginner

Location

src/dm/dt/dualspace/../../../../include/petscdt.h
Index of all DUALSPACE routines
Table of Contents for all manual pages
Index of all manual pages