Function
Static Public Summary | ||
public |
Apply a given sequence (in the given order) of transpositions (given as
index tuples) to the identity permutation over input |
|
public |
bitreversal(n: number): Array Returns a newly allocated array containing the bitreversal permutation for
input |
|
public |
Compose two input permutations. |
|
public |
Make a copy of the input permutation. |
|
public |
Computes a cycle decomposition of the input permutation. |
|
public |
Returns the identity permutation of a given size. |
|
public |
Computes the inverse |
|
public |
itranspositions(sigma: Array): IterableIterator Computes the sequence of transpositions that if applied to
|
|
public |
Computes the permutation that follows the input permutation. |
|
public |
permutation(n: number): Array Allocates a new permutation of given input size. |
|
public |
* permutations(n: number): IterableIterator Generate all permutations on |
|
public |
Reverses input permutation in-place. |
|
public |
Outputs a new permutation that is the reverse of the input permutation. |
|
public |
Creates a copy of the input permutation, applies an input transpose, then returns the result. |
|
public |
transposition(n: number, a: number, b: number): undefined Outputs the permutation on input |
|
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 |
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
|
|
private |
Compose two input permutations. |
|
private |
Copy an input permutation to an output array. |
|
private |
Computes a cycle decomposition of an input permutation. |
|
private |
Fills an input array with the identity permutation on input |
|
private |
Fills an input array with the inverse |
|
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
|
|
private |
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 |
Reverses input permutation in-place from input index |
|
private |
_transpose(a: number, b: number, sigma: Array) Transpose elements of input index |
|
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 |
For a given size |
Static Public
public apply(n: number, transpositions: Iterable): Array source
import {apply} from '@combinatorics/permutation/src/apply.js'
Apply a given sequence (in the given order) of transpositions (given as
index tuples) to the identity permutation over input n
elements.
Params:
Name | Type | Attribute | Description |
n | number | The size of the identity permutation to apply the transpositions to. |
|
transpositions | Iterable | The given transpositions to apply. |
public bitreversal(n: number): Array source
import {bitreversal} from '@combinatorics/permutation/src/bitreversal.js'
Returns a newly allocated array containing the bitreversal permutation for
input n
items. Note that n
MUST be a power of
2
.
Params:
Name | Type | Attribute | Description |
n | number | The size of the permutation, must be a power of
|
public compose(sigma: Array, tau: Array): Array source
import {compose} from '@combinatorics/permutation/src/compose.js'
Compose two input permutations. The resulting permutation is output as an array of indices.
public copy(sigma: Array): Array source
import {copy} from '@combinatorics/permutation/src/copy.js'
Make a copy of the input permutation.
Params:
Name | Type | Attribute | Description |
sigma | Array | The input permutation. |
public cycles(sigma: Array): IterableIterator source
import {cycles} from '@combinatorics/permutation/src/cycles.js'
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:
Name | Type | Attribute | Description |
sigma | Array | The input permutation. |
Return:
IterableIterator | The cycles |
public identity(n: number): Array source
import {identity} from '@combinatorics/permutation/src/identity.js'
Returns the identity permutation of a given size.
Params:
Name | Type | Attribute | Description |
n | number | The size of the permutation to return. |
public invert(sigma: Array): Array source
import {invert} from '@combinatorics/permutation/src/invert.js'
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:
Name | Type | Attribute | Description |
sigma | Array | The input permutation. |
public itranspositions(sigma: Array): IterableIterator source
import {itranspositions} from '@combinatorics/permutation/src/itranspositions.js'
Computes the sequence of transpositions that if applied to
sigma
result in invert(sigma)
. Uses
_itranspositions as the underlying implementation.
Params:
Name | Type | Attribute | Description |
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
import {next} from '@combinatorics/permutation/src/next.js'
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:
Name | Type | Attribute | Description |
sigma | Array | The input permutation. |
public permutation(n: number): Array source
import {permutation} from '@combinatorics/permutation/src/permutation.js'
Allocates a new permutation of given input size.
Params:
Name | Type | Attribute | Description |
n | number | The size of the permutation to allocate. |
public * permutations(n: number): IterableIterator source
import {permutations} from '@combinatorics/permutation/src/permutations.js'
Generate all permutations on n
elements.
Params:
Name | Type | Attribute | Description |
n | number | The size of the permutations to generate. |
Return:
IterableIterator | Iterator that yields all permutations on |
public reverse(sigma: Array) source
import {reverse} from '@combinatorics/permutation/src/reverse.js'
Reverses input permutation in-place.
Params:
Name | Type | Attribute | Description |
sigma | Array | The input permutation to reverse (modified in-place). |
public reversed(sigma: Array): Array source
import {reversed} from '@combinatorics/permutation/src/reversed.js'
Outputs a new permutation that is the reverse of the input permutation.
Params:
Name | Type | Attribute | Description |
sigma | Array | The input permutation. |
public transpose(sigma: Array, a: number, b: number): Array source
import {transpose} from '@combinatorics/permutation/src/transpose.js'
Creates a copy of the input permutation, applies an input transpose, then returns the result.
public transposition(n: number, a: number, b: number): undefined source
import {transposition} from '@combinatorics/permutation/src/transposition.js'
Outputs the permutation on input n
numbers that only transposes
two input elements a
and b
.
public transpositions(sigma: Array): IterableIterator source
import {transpositions} from '@combinatorics/permutation/src/transpositions.js'
Computes the transposition decomposition of the input permutation as an Iterator.
Params:
Name | Type | Attribute | Description |
sigma | Array | The input permutation. |
Return:
IterableIterator | The transposition decomposition of |
public used(n: number): Array source
import {used} from '@combinatorics/permutation/src/used.js'
Generates an helper array of given size (used in _cycle, cycle).
Params:
Name | Type | Attribute | Description |
n | number | The given size. |
Static Private
private _apply(transpositions: Iterable, sigma: Array) source
import {_apply} from '@combinatorics/permutation/src/_apply.js'
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:
Name | Type | Attribute | Description |
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
import {_bitreversal} from '@combinatorics/permutation/src/_bitreversal.js'
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
.
private * _compose(sigma: Array, tau: Array): IterableIterator source
import {_compose} from '@combinatorics/permutation/src/_compose.js'
Compose two input permutations. The resulting permutation is output as an iterator of indices instead of an array of indices.
Return:
IterableIterator | An iterator over the items of the resulting permutation. |
private _copy(sigma: Array, n: number, tau: Array) source
import {_copy} from '@combinatorics/permutation/src/_copy.js'
Copy an input permutation to an output array.
private * _cycles(sigma: Array, used: Array): IterableIterator source
import {_cycles} from '@combinatorics/permutation/src/_cycles.js'
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.
Return:
IterableIterator | The cycles |
private _identity(sigma: Array, n: number) source
import {_identity} from '@combinatorics/permutation/src/_identity.js'
Fills an input array with the identity permutation on input n
elements.
private _invert(sigma: Array, n: number, tau: Array) source
import {_invert} from '@combinatorics/permutation/src/_invert.js'
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.
private _invertcycles(cycles: Iterable, tau: Array) source
import {_invertcycles} from '@combinatorics/permutation/src/_invertcycles.js'
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:
Name | Type | Attribute | Description |
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
import {_itranspositions} from '@combinatorics/permutation/src/_itranspositions.js'
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.
Return:
IterableIterator | Iterator over the transpositions. |
private _next(sigma: Array, n: number): Boolean source
import {_next} from '@combinatorics/permutation/src/_next.js'
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.
private * _permutations(sigma: Array, n: number): IterableIterator source
import {_permutations} from '@combinatorics/permutation/src/_permutations.js'
Yields all permutations starting from a given one and ending at the last 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
import {_reverse} from '@combinatorics/permutation/src/_reverse.js'
Reverses input permutation in-place from input index i
(include) to input index j
(excluded).
private _transpose(a: number, b: number, sigma: Array) source
import {_transpose} from '@combinatorics/permutation/src/_transpose.js'
Transpose elements of input index a
and b
in the
input permutation.
private _transposition(a: number, b: number, sigma: Array) source
import {_transposition} from '@combinatorics/permutation/src/_transposition.js'
Helper method for transposition.
Transposes a
with b
in sigma
provided
sigma[a] === a
and sigma[b] === b
.
private * _transpositions(cycles: Iterable): IterableIterator source
import {_transpositions} from '@combinatorics/permutation/src/_transpositions.js'
Computes the transposition decomposition of some permutation given its cycle decomposition.
Params:
Name | Type | Attribute | Description |
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
import {_used} from '@combinatorics/permutation/src/_used.js'