|
constexpr | Perm () |
| Creates the identity permutation. More...
|
|
constexpr | Perm (int a, int b) |
| Creates the transposition of a and b. More...
|
|
constexpr | Perm (const std::array< int, 2 > &image) |
| Creates a permutation mapping i to image[i] for each i = 0,1. More...
|
|
constexpr | Perm (const Perm< 2 > &cloneMe)=default |
| Creates a permutation that is a clone of the given permutation. More...
|
|
constexpr Code | permCode () const |
| Returns the internal code representing this permutation. More...
|
|
void | setPermCode (Code code) |
| Sets this permutation to that represented by the given internal code. More...
|
|
Perm< 2 > & | operator= (const Perm< 2 > &cloneMe)=default |
| Sets this permutation to be equal to the given permutation. More...
|
|
constexpr Perm< 2 > | operator* (const Perm< 2 > &q) const |
| Returns the composition of this permutation with the given permutation. More...
|
|
constexpr Perm< 2 > | inverse () const |
| Finds the inverse of this permutation. More...
|
|
constexpr Perm< 2 > | pow (long exp) const |
| Computes the given power of this permutation. More...
|
|
constexpr int | order () const |
| Returns the order of this permutation. More...
|
|
constexpr Perm< 2 > | reverse () const |
| Finds the reverse of this permutation. More...
|
|
constexpr int | sign () const |
| Determines the sign of this permutation. More...
|
|
constexpr int | operator[] (int source) const |
| Determines the image of the given integer under this permutation. More...
|
|
constexpr int | pre (int image) const |
| Determines the preimage of the given integer under this permutation. More...
|
|
constexpr bool | operator== (const Perm< 2 > &other) const |
| Determines if this is equal to the given permutation. More...
|
|
constexpr bool | operator!= (const Perm< 2 > &other) const |
| Determines if this differs from the given permutation. More...
|
|
constexpr int | compareWith (const Perm< 2 > &other) const |
| Lexicographically compares the images of (0,1) under this and the given permutation. More...
|
|
constexpr bool | isIdentity () const |
| Determines if this is the identity permutation. More...
|
|
Perm< 2 > & | operator++ () |
| A preincrement operator that changes this to be the next permutation in the array Perm<2>::Sn. More...
|
|
constexpr Perm< 2 > | operator++ (int) |
| A postincrement operator that changes this to be the next permutation in the array Perm<2>::Sn. More...
|
|
constexpr bool | operator< (const Perm< 2 > &rhs) const |
| Determines if this appears earlier than the given permutation in the array Perm<2>::Sn. More...
|
|
std::string | str () const |
| Returns a string representation of this permutation. More...
|
|
std::string | trunc (int len) const |
| Returns a prefix of the string representation of this permutation, containing only the images of the first len integers. More...
|
|
void | tightEncode (std::ostream &out) const |
| Writes the tight encoding of this permutation to the given output stream. More...
|
|
std::string | tightEncoding () const |
| Returns the tight encoding of this permutation. More...
|
|
void | clear (unsigned from) |
| Resets the images of all integers from from onwards to the identity map. More...
|
|
constexpr Index | SnIndex () const |
| Returns the index of this permutation in the Perm<2>::Sn array. More...
|
|
constexpr Index | S2Index () const |
| Returns the index of this permutation in the Perm<2>::S2 array. More...
|
|
constexpr Index | orderedSnIndex () const |
| Returns the lexicographical index of this permutation. More...
|
|
constexpr Index | orderedS2Index () const |
| Returns the lexicographical index of this permutation. More...
|
|
constexpr bool | isConjugacyMinimal () const |
| Is this permutation minimal in its conjugacy class? More...
|
|
template<class URBG > |
Perm< 2 > | rand (URBG &&gen, bool even) |
|
template<typename iterator > |
Perm< 2 > | tightDecode (iterator start, iterator limit, bool noTrailingData) |
|
|
static constexpr Perm< 2 > | fromPermCode (Code code) |
| Creates a permutation from the given internal code. More...
|
|
static constexpr bool | isPermCode (Code code) |
| Determines whether the given integer is a valid internal permutation code. More...
|
|
static constexpr Perm | rot (int i) |
| Returns the ith rotation. More...
|
|
static Perm | rand (bool even=false) |
| Returns a random permutation on two elements. More...
|
|
template<class URBG > |
static Perm | rand (URBG &&gen, bool even=false) |
| Returns a random permutation on two elements, using the given uniform random bit generator. More...
|
|
static Perm | tightDecoding (const std::string &enc) |
| Reconstructs a permutation from its given tight encoding. More...
|
|
static Perm | tightDecode (std::istream &input) |
| Reconstructs a permutation from its given tight encoding. More...
|
|
template<int k> |
static constexpr Perm< 2 > | contract (Perm< k > p) |
| Restricts a k-element permutation to an 2-element permutation, where k > 2. More...
|
|
|
static constexpr PermCodeType | codeType = PERM_CODE_INDEX |
| Indicates what type of internal permutation code is used by this instance of the Perm class template. More...
|
|
static constexpr Index | nPerms = 2 |
| The total number of permutations on two elements. More...
|
|
static constexpr Index | nPerms_1 = 1 |
| The total number of permutations on one element. More...
|
|
static constexpr S2Lookup | Sn {} |
| Gives array-like access to all possible permutations of two elements. More...
|
|
static constexpr S2Lookup | S2 {} |
| Gives array-like access to all possible permutations of two elements. More...
|
|
static constexpr S2Lookup | orderedSn {} |
| Gives array-like access to all possible permutations of two elements in lexicographical order. More...
|
|
static constexpr S2Lookup | orderedS2 {} |
| Gives array-like access to all possible permutations of two elements in lexicographical order. More...
|
|
static constexpr S2Lookup | Sn_1 {} |
| Gives array-like access to all possible permutations of one element. More...
|
|
static constexpr S2Lookup | S1 {} |
| Gives array-like access to all possible permutations of one element. More...
|
|
Represents a permutation of {0,1}.
This is a specialisation of the generic Perm template: it is highly optimised, but also somewhat trivial (since there are only two possible permutations). It is provided simply to optimise the general Perm<n> template for this trivial case.
As with all Perm template classes, these objects are small enough to pass by value and swap with std::swap(), with no need for any specialised move operations or swap functions. Moreover, Perm<2> in particular is extremely fast to work with.
Each permutation has an internal code, which is a single native integer that is sufficient to reconstruct the permutation. Thus the internal code may be a useful means for passing permutation objects to and from the engine. For Perm<2>, the internal code is 0 for the identity permutation, or 1 for the (unique) non-identity permutation. This is consistent with the second-generation codes used in classes Perm<4>,...,Perm<7>.
To use this class, simply include the main permutation header maths/perm.h.
- Warning
- Every permutation class Perm<n> provides a transposition (i.e., pair swap) constructor
Perm<n>(a,b).
In addition, the specialised classes Perm<3>, Perm<4> and Perm<5> provide "list of images" constructors Perm<3>(a,b,c)
, Perm<4>(a,b,c,d)
and Perm<5>(a,b,c,d,e)
. For Perm<2>, these two constructors would be indistinguishable (since both would take two integer arguments). Here Perm<2> takes an approach that is consistent with the generic Perm<n> class: Perm<2>(a,b)
is interpreted as the transposition of a and b. In particular, Perm(0,1)
is not the identity permutation.
- Python
- Since Python does not support templates, this class is made available under the name Perm2.
Reconstructs a permutation from its given tight encoding.
See the page on tight encodings for details.
The tight encoding will be read from the given input stream. If the input stream contains leading whitespace then it will be treated as an invalid encoding (i.e., this routine will throw an exception). The input routine may contain further data: if this routine is successful then the input stream will be left positioned immediately after the encoding, without skipping any trailing whitespace.
Tight encodings are fast to work with for small permutation classes (n ≤ 7), but slower for larger permutation classes (8 ≤ n ≤ 16). See tightEncoding() for further details.
- Exceptions
-
InvalidInput | the given input stream does not begin with a tight encoding of a 2-element permutation. |
- Python
- Not present; use tightDecoding() instead, which takes a string as its argument.
- Parameters
-
input | an input stream that begins with the tight encoding for a 2-element permutation. |
- Returns
- the permutation represented by the given tight encoding.
Reconstructs a permutation from its given tight encoding.
See the page on tight encodings for details.
The tight encoding will be given as a string. If this string contains leading whitespace or any trailing characters at all (including trailing whitespace), then it will be treated as an invalid encoding (i.e., this routine will throw an exception).
Tight encodings are fast to work with for small permutation classes (n ≤ 7), but slower for larger permutation classes (8 ≤ n ≤ 16). See tightEncoding() for further details.
- Exceptions
-
InvalidArgument | the given string is not a tight encoding of a 2-element permutation. |
- Parameters
-
enc | the tight encoding for a 2-element permutation. |
- Returns
- the permutation represented by the given tight encoding.
Gives array-like access to all possible permutations of two elements in lexicographical order.
To access the permutation at index i, you simply use the square bracket operator: orderedSn[i]
. The index i must be between 0 and 1 inclusive.
Lexicographical ordering treats each permutation p as the ordered pair (p[0], p[1]). Therefore the identity permutation has index 0, and the (unique) non-identity permutation has index 1.
In Regina 6.0.1 and earlier, this was a hard-coded C-style array; since Regina 7.0 it has changed type, but accessing elements as described above remains extremely fast. The object that is returned is lightweight and is defined in the headers only; in particular, you cannot make a reference to it (but you can always make a copy).
This ordered array is identical to Perm<2>::Sn. Note however that for n ≥ 3, the arrays Perm<n>::Sn and Perm<n>::orderedSn are different: Sn alternates between even and odd permutations, whereas orderedSn stores permutations in lexicographical order.
Gives array-like access to all possible permutations of two elements.
This is a dimension-specific alias for Perm<2>::Sn; see that member for further information. In general, for every n there will be a static member Perm<n>::Sn; however, these numerical aliases Perm<2>::S2, ..., Perm<5>::S5 are only available for small n.
Note that all small permutation classes (Perm<2>, ..., Perm<5>) have an S2 array: these all store the same two permutations in the same order (but of course using different data types).
Gives array-like access to all possible permutations of two elements.
To access the permutation at index i, you simply use the square bracket operator: Sn[i]
. The index i must be between 0 and 1 inclusive.
In Regina 6.0.1 and earlier, this was a hard-coded C-style array; since Regina 7.0 it has changed type, but accessing elements as described above remains extremely fast. The object that is returned is lightweight and is defined in the headers only; in particular, you cannot make a reference to it (but you can always make a copy).
The identity permutation has index 0, and the non-identity permutation has index 1. As a result, Sn[i] is an even permutation if and only if i is even.
This ordered array is identical to Perm<2>::orderedSn. Note however that for n ≥ 3, the arrays Perm<n>::Sn and Perm<n>::orderedSn are different: Sn alternates between even and odd permutations, whereas orderedSn stores permutations in lexicographical order.
Gives array-like access to all possible permutations of one element.
Of course, this array is trivial: it contains just the identity permutation. This array is provided for consistency with larger permutation classes Perm<n>.
To access the permutation at index i, you simply use the square bracket operator: Sn_1[i]
. The index i must be 0.
In Regina 6.0.1 and earlier, this was a hard-coded C-style array; since Regina 7.0 it has changed type, but accessing elements as described above remains extremely fast. The object that is returned is lightweight and is defined in the headers only; in particular, you cannot make a reference to it (but you can always make a copy).