Home Manual Reference Source

Function

Static Public Summary
public

apply(n: number, transpositions: Iterable): Array

Apply a given sequence (in the given order) of transpositions (given as index tuples) to the identity permutation over input n elements.

public

Returns a newly allocated array containing the bitreversal permutation for input n items.

public

compose(sigma: Array, tau: Array): Array

Compose two input permutations.

public

copy(sigma: Array): Array

Make a copy of the input permutation.

public

cycles(sigma: Array): IterableIterator

Computes a cycle decomposition of the input permutation.

public

Returns the identity permutation of a given size.

public

invert(sigma: Array): Array

Computes the inverse tau of the input permutation sigma, that is, the permutation such that compose(sigma, tau) returns identity(sigma.length).

public

itranspositions(sigma: Array): IterableIterator

Computes the sequence of transpositions that if applied to sigma result in invert(sigma).

public

next(sigma: Array): Array

Computes the permutation that follows the input permutation.

public

Allocates a new permutation of given input size.

public

* permutations(n: number): IterableIterator

Generate all permutations on n elements.

public

reverse(sigma: Array)

Reverses input permutation in-place.

public

reversed(sigma: Array): Array

Outputs a new permutation that is the reverse of the input permutation.

public

transpose(sigma: Array, a: number, b: number): Array

Creates a copy of the input permutation, applies an input transpose, then returns the result.

public

Outputs the permutation on input n numbers that only transposes two input elements a and b.

public

transpositions(sigma: Array): IterableIterator

Computes the transposition decomposition of the input permutation as an Iterator.

public

Generates an helper array of given size (used in _cycle, cycle).

Static Private Summary
private

_apply(transpositions: Iterable, sigma: Array)

Applies a given sequence (in the given order) of transpositions (given as index tuples) to a given permutation.

private

_bitreversal(array: Array, n: number)

Fills an input array with the bitreversal permutation for input n items.

private

* _compose(sigma: Array, tau: Array): IterableIterator

Compose two input permutations.

private

_copy(sigma: Array, n: number, tau: Array)

Copy an input permutation to an output array.

private

* _cycles(sigma: Array, used: Array): IterableIterator

Computes a cycle decomposition of an input permutation.

private

_identity(sigma: Array, n: number)

Fills an input array with the identity permutation on input n elements.

private

_invert(sigma: Array, n: number, tau: Array)

Fills an input array with the inverse tau of the input permutation sigma, that is, the permutation such that compose(sigma, tau) returns identity(sigma.length).

private

_invertcycles(cycles: Iterable, tau: Array)

Inverts given cycles in a given permutation in-place.

private

* _itranspositions(sigma: Array, used: Array): IterableIterator

Computes the sequence of transpositions that if applied to sigma result in invert(sigma).

private

_next(sigma: Array, n: number): Boolean

Updates the input permutation to the next one in-place.

private

* _permutations(sigma: Array, n: number): IterableIterator

Yields all permutations starting from a given one and ending at the last permutation.

private

_reverse(sigma: Array, i: number, j: number)

Reverses input permutation in-place from input index i (include) to input index j (excluded).

private

_transpose(a: number, b: number, sigma: Array)

Transpose elements of input index a and b in the input permutation.

private

_transposition(a: number, b: number, sigma: Array)

Helper method for transposition.

private

* _transpositions(cycles: Iterable): IterableIterator

Computes the transposition decomposition of some permutation given its cycle decomposition.

private

_used(n: number, array: Array)

For a given size n, fills an input array with false.

Static Public

public apply(n: number, transpositions: Iterable): Array source

Apply a given sequence (in the given order) of transpositions (given as index tuples) to the identity permutation over input n elements.

Params:

NameTypeAttributeDescription
n number

The size of the identity permutation to apply the transpositions to.

transpositions Iterable

The given transpositions to apply.

Return:

Array

The resulting permutation.

public bitreversal(n: number): Array source

Returns a newly allocated array containing the bitreversal permutation for input n items. Note that n MUST be a power of 2.

Params:

NameTypeAttributeDescription
n number

The size of the permutation, must be a power of 2.

Return:

Array

The bitreversal permutation of size n.

public compose(sigma: Array, tau: Array): Array source

Compose two input permutations. The resulting permutation is output as an array of indices.

Params:

NameTypeAttributeDescription
sigma Array

The first input permutation.

tau Array

The second input permutation.

Return:

Array

The resulting permutation as an array.

public copy(sigma: Array): Array source

Make a copy of the input permutation.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

Return:

Array

The copy.

public cycles(sigma: Array): IterableIterator source

Computes a cycle decomposition of the input permutation. For a given input, the algorithm used will always yield the same cycle decomposition. See _cycles for implementation.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

Return:

IterableIterator

The cycles [a, [b, c, ...]] for sigma.

public identity(n: number): Array source

Returns the identity permutation of a given size.

Params:

NameTypeAttributeDescription
n number

The size of the permutation to return.

Return:

Array

The identity permutation on n elements.

public invert(sigma: Array): Array source

Computes the inverse tau of the input permutation sigma, that is, the permutation such that compose(sigma, tau) returns identity(sigma.length). Alternatives include using _invertcycles and itranspositions.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

Return:

Array

The inverse of the input permutation.

public itranspositions(sigma: Array): IterableIterator source

Computes the sequence of transpositions that if applied to sigma result in invert(sigma). Uses _itranspositions as the underlying implementation.

Params:

NameTypeAttributeDescription
sigma Array

Input permutation.

Return:

IterableIterator

Iterator over the transpositions.

Example:

const invert = sigma => apply( sigma.length , itranspositions( sigma ) ) ;

public next(sigma: Array): Array source

Computes the permutation that follows the input permutation. If the input permutation is the last for its elements, return the first for its elements. The input permutation is not altered.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

Return:

Array

The next permutation.

public permutation(n: number): Array source

Allocates a new permutation of given input size.

Params:

NameTypeAttributeDescription
n number

The size of the permutation to allocate.

Return:

Array

The allocated permutation.

public * permutations(n: number): IterableIterator source

Generate all permutations on n elements.

Params:

NameTypeAttributeDescription
n number

The size of the permutations to generate.

Return:

IterableIterator

Iterator that yields all permutations on n elements.

public reverse(sigma: Array) source

Reverses input permutation in-place.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation to reverse (modified in-place).

public reversed(sigma: Array): Array source

Outputs a new permutation that is the reverse of the input permutation.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

Return:

Array

The reverse of the input permutation.

public transpose(sigma: Array, a: number, b: number): Array source

Creates a copy of the input permutation, applies an input transpose, then returns the result.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

a number

The first index of the transpose.

b number

The second index of the transpose.

Return:

Array

The result.

public transposition(n: number, a: number, b: number): undefined source

Outputs the permutation on input n numbers that only transposes two input elements a and b.

Params:

NameTypeAttributeDescription
n number

The size of the permutation to output.

a number

The first index to swap.

b number

The second index to swap.

Return:

undefined

public transpositions(sigma: Array): IterableIterator source

Computes the transposition decomposition of the input permutation as an Iterator.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

Return:

IterableIterator

The transposition decomposition of sigma.

public used(n: number): Array source

Generates an helper array of given size (used in _cycle, cycle).

Params:

NameTypeAttributeDescription
n number

The given size.

Return:

Array

The helper array of prescribed size.

Static Private

private _apply(transpositions: Iterable, sigma: Array) source

Applies a given sequence (in the given order) of transpositions (given as index tuples) to a given permutation. The permutation is modified in-place.

Params:

NameTypeAttributeDescription
transpositions Iterable

The given transpositions to apply.

sigma Array

The permutation to apply the transpositions to (modified in-place).

private _bitreversal(array: Array, n: number) source

Fills an input array with the bitreversal permutation for input n items. The array is filled starting at index 0 and ending at index n-1. Note that n MUST be a power of 2.

Params:

NameTypeAttributeDescription
array Array

The array to fill.

n number

The size of the permutation, must be a power of 2.

private * _compose(sigma: Array, tau: Array): IterableIterator source

Compose two input permutations. The resulting permutation is output as an iterator of indices instead of an array of indices.

Params:

NameTypeAttributeDescription
sigma Array

The first input permutation.

tau Array

The second input permutation.

Return:

IterableIterator

An iterator over the items of the resulting permutation.

private _copy(sigma: Array, n: number, tau: Array) source

Copy an input permutation to an output array.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

n number

The size of the input permutation to copy.

tau Array

The output array.

private * _cycles(sigma: Array, used: Array): IterableIterator source

Computes a cycle decomposition of an input permutation. This algorithm is deterministic; the algorithm will procedes in a sequential manner, first yielding the cycle containing the first (in input order) index of the permutation, then yielding the cycle containing the first (in input order) index of the permutation that is not in the first cycle, etc. The output is in the form of an iterator over cycles [a, [b, c, ...]] where a is the first element of the cycle and the list [b, c, ...] contains the second, third, etc. elements of the cycle. The algorithm uses an helper array to remember which elements have already been encountered.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

used Array

The helper array.

Return:

IterableIterator

The cycles [a, [b, c, ...]] for sigma.

See:

private _identity(sigma: Array, n: number) source

Fills an input array with the identity permutation on input n elements.

Params:

NameTypeAttributeDescription
sigma Array

The input array.

n number

The size to use for the permutation.

private _invert(sigma: Array, n: number, tau: Array) source

Fills an input array with the inverse tau of the input permutation sigma, that is, the permutation such that compose(sigma, tau) returns identity(sigma.length). See invert for the higher level API.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation.

n number

The size of the input permutation.

tau Array

The array where to put the inverse of the input permutation.

private _invertcycles(cycles: Iterable, tau: Array) source

Inverts given cycles in a given permutation in-place. Can be used as an alternative way of inverting an entire permutation by inverting all of its cycles in the identity permutation.

Params:

NameTypeAttributeDescription
cycles Iterable

The cycles to invert.

tau Array

The given permutation (modified in-place).

Example:

const invert = sigma => {
  const tau = identity( sigma.length ) ;
  const cycles_sigma = cycles( sigma ) ;
  _invertcycles( cycles_sigma , tau ) ;
  return tau ;
} ;

private * _itranspositions(sigma: Array, used: Array): IterableIterator source

Computes the sequence of transpositions that if applied to sigma result in invert(sigma). Needs an helper array to keep track of processed elements. See itranspositions for higher level API.

Params:

NameTypeAttributeDescription
sigma Array

Input permutation.

used Array

Helper array.

Return:

IterableIterator

Iterator over the transpositions.

private _next(sigma: Array, n: number): Boolean source

Updates the input permutation to the next one in-place. Returns true unless the input permutation is the last for its elements. In that case, the input permutation remains untouched.

Params:

NameTypeAttributeDescription
sigma Array

The input permutation (modified in-place).

n number

The size of the input permutation.

Return:

Boolean

Whether the input permutation is NOT the last for its elements.

private * _permutations(sigma: Array, n: number): IterableIterator source

Yields all permutations starting from a given one and ending at the last permutation.

Params:

NameTypeAttributeDescription
sigma Array

The starting permutation.

n number

The size of the permutation.

Return:

IterableIterator

Iterator over all permutations between the starting one and the last permutation on its elements.

private _reverse(sigma: Array, i: number, j: number) source

Reverses input permutation in-place from input index i (include) to input index j (excluded).

Params:

NameTypeAttributeDescription
sigma Array

The input permutation to reverse (modified in-place).

i number

The left bound (included).

j number

The right bound (excluded).

private _transpose(a: number, b: number, sigma: Array) source

Transpose elements of input index a and b in the input permutation.

Params:

NameTypeAttributeDescription
a number

The first input index.

b number

The second input index.

sigma Array

The input permutation.

private _transposition(a: number, b: number, sigma: Array) source

Helper method for transposition. Transposes a with b in sigma provided sigma[a] === a and sigma[b] === b.

Params:

NameTypeAttributeDescription
a number

First index.

b number

Second index.

sigma Array

Input permutation.

private * _transpositions(cycles: Iterable): IterableIterator source

Computes the transposition decomposition of some permutation given its cycle decomposition.

Params:

NameTypeAttributeDescription
cycles Iterable

The cycle decomposition of some permutation.

Return:

IterableIterator

The transposition decomposition of the permutation defined by the input cycles.

private _used(n: number, array: Array) source

For a given size n, fills an input array with false. Starting at index 0, ending at index n-1. This array is used as a helper in other function. For example, for computing the cycle decomposition of an input permutation (see _cycles, cycles).

Params:

NameTypeAttributeDescription
n number

The given size.

array Array

The input array.