algebra Package¶
algebra
Package¶
abstract_algebra
Module¶
Abstract Algebra¶
- The abstract algebra package provides a basic interface
- for defining custom Algebras.
See The Abstract Algebra module for more details.
-
exception
qnet.algebra.abstract_algebra.
AlgebraError
[source]¶ Bases:
qnet.algebra.abstract_algebra.AlgebraException
- Base class for all errors concerning the mathematical
- definitions and rules of an algebra.
-
exception
qnet.algebra.abstract_algebra.
AlgebraException
[source]¶ Bases:
Exception
- Base class for all errors concerning the mathematical
- definitions and rules of an algebra.
-
exception
qnet.algebra.abstract_algebra.
CannotSimplify
[source]¶ Bases:
qnet.algebra.abstract_algebra.AlgebraException
Raised when an expression cannot be further simplified
-
class
qnet.algebra.abstract_algebra.
Expression
[source]¶ Bases:
object
Basic class defining the basic methods any Expression object should implement.
-
all_symbols
()[source]¶ Returns: The set of all_symbols contained within the expression. Return type: set
-
-
class
qnet.algebra.abstract_algebra.
Match
[source]¶ Bases:
dict
Subclass of dict that overloads the + operator to create a new dictionary combining the entries. It fails when there are duplicate keys.
-
class
qnet.algebra.abstract_algebra.
NamedPattern
(name, pattern)[source]¶ Bases:
qnet.algebra.abstract_algebra.Operation
Create a named (sub-)pattern for later use in processing elements of a matched expression.:
NamedPattern(name, pattern)
Parameters: - name (str) – Pattern identifier
- pattern (Expression, PatternTuple) – Pattern expression
-
class
qnet.algebra.abstract_algebra.
OperandsTuple
[source]¶ Bases:
tuple
Specialized tuple to store expression operands for the purpose of matching them to patterns.
-
class
qnet.algebra.abstract_algebra.
Operation
(*operands)[source]¶ Bases:
qnet.algebra.abstract_algebra.Expression
Abstract base class for all operations, where the operands themselves are also expressions.
-
classmethod
create
(*operands)[source]¶ Instead of directly instantiating an instance of any subclass of Operation, it is advised to call the
create()
classmethod instead. This method takes the same arguments as the constructor, but can preprocess them and even return an object of a different type based on the operands.Parameters: operands – The operands for the operation.
-
operands
¶ Returns: The operands of the operation. Return type: tuple
-
classmethod
-
class
qnet.algebra.abstract_algebra.
PatternTuple
[source]¶ Bases:
tuple
Specialized tuple to store expression pattern operands.
-
class
qnet.algebra.abstract_algebra.
Wildcard
(name='', mode=1, head=None, condition=None)[source]¶ Bases:
qnet.algebra.abstract_algebra.Expression
Basic wildcard expression that can match a single expression or in the context of matching the operands of an Operation object one may match one_or_more or zero_or_more operands with the same wildcards. If the wildcard has a name, a successful match leads to a Match object in which the object that matched the wildcard is stored under that name. One can also restrict the type of the matched Expression by providing a head argument and the condition argument allows for passing a function that performs additional tests on a potential match.
-
condition
= None¶ extra condition for a successful match (default =
None
, corresponding to no restriction).
-
head
= None¶ head/type of the matched object (default =
None
, corresponding to no restriction).
-
mode
= 1¶ mode of the wildcard, i.e. how many operands it can match (default =
single
).
-
name
= ''¶ name/identifier of the wildcard (default = “”).
-
one_or_more
= 2¶ Value of
Wildcard.mode
for matching one or more operands/objects
-
single
= 1¶ Value of
Wildcard.mode
for matching single operands/objects
-
zero_or_more
= 3¶ Value of
Wildcard.mode
for matching zero or more operands/objects
-
-
exception
qnet.algebra.abstract_algebra.
WrongSignatureError
[source]¶ Bases:
qnet.algebra.abstract_algebra.AlgebraError
- Raise when an operation is instantiated
- with operands of the wrong signature.
-
qnet.algebra.abstract_algebra.
all_symbols
(expr)[source]¶ Return all all_symbols featured within an expression.
Parameters: expr – The expression to find all_symbols in. Returns: A set of all_symbols within expr. Return type: set
-
qnet.algebra.abstract_algebra.
assoc
(dcls)¶ Associatively expand out nested arguments of the flat class.
>>> @assoc >>> class Plus(Operation): >>> pass >>> Plus.create(1,Plus(2,3)) Plus(1,2,3)
Automatically generated class decorator based on the method
qnet.algebra.abstract_algebra._assoc()
usingpreprocess_create_with()
.
-
qnet.algebra.abstract_algebra.
check_signature
(dcls)¶ Check that the operands passed to the create classmethod of an Operation type conform to certain types. For each allowed argument/operand, provide a tuple of types (or one of
CLS, DCLS
, see extended_isinstance docs). E.g.>>> @check_signature >>> class X(Operation): >>> signature = str, (int, str) >>> >>> X.create("1", 2) X("1", 2) >>> X.create("1", "2") X("1", "2")
The following all raise
WrongSignatureError
exception.>>> X.create("1") >>> X.create(1, "1") >>> X.create("1", 2, 3)
Automatically generated class decorator based on the method
qnet.algebra.abstract_algebra._check_signature()
usingpreprocess_create_with()
.
-
qnet.algebra.abstract_algebra.
check_signature_assoc
(dcls)¶ Like
check_signature()
but forassoc()
-decorated Operations. In this case the signature need only contain a single entry.>>> @assoc >>> @check_signature >>> class X(Operation): >>> signature = str >>> X.create("hello", "you") X("hello", "you")
The following then raises a
WrongSignatureError
because the third argument is no string>>> X.create("hello", "you", 2)
Automatically generated class decorator based on the method
qnet.algebra.abstract_algebra._check_signature_assoc()
usingpreprocess_create_with()
.
-
qnet.algebra.abstract_algebra.
extended_isinstance
(obj, class_info, dcls, cls)[source]¶ Like isinstance but with two extra arguments to allow for placeholder objects
(DCLS, CLS)
to stand for the class objects passed as extra argumentsdcls
,cls
. This allows one to specify a self-referential signature class attribute to allow for recursive Operation signatures. E.g.>>> @check_signature >>> class X(Operation): >>> signature = str, X
will yield an exception, because X within the class body refers to a class object that has not been defined yet. Instead, one can do
>>> @check_signature >>> class X(Operation): >>> signature = str, CLS
to refer to the class of the object being instantiated (could be a subclass of
X
), or>>> @check_signature >>> class X(Operation): >>> signature = str, DCLS
to always refer to
X
itself and not a subclass.Parameters: - obj (object) – The instance
- class_info (type or tuple of type-objects) – A type,
DCLS
,CLS
, or a tuple of these - dcls (type) – The (super-)class that the signature is defined for.
- cls (type) – The concrete (sub-)class whose instance is being initialized.
-
qnet.algebra.abstract_algebra.
filter_neutral
(dcls)¶ Remove occurrences of a neutral element from the argument/operand list, if that list has at least two elements. To use this, one must also specify a neutral element, which can be anything that allows for an equality check with each argument. E.g.
>>> @filter_neutral >>> class X(Operation): >>> neutral_element = 1 >>> X.create(2,1,3,1) X(2,3)
Automatically generated class decorator based on the method
qnet.algebra.abstract_algebra._filter_neutral()
usingpreprocess_create_with()
.
-
qnet.algebra.abstract_algebra.
idem
(dcls)¶ Remove duplicate arguments and order them via the cls’s order_key key object/function. E.g.
>>> @idem >>> class Set(Operation): >>> pass >>> Set.create(1,2,3,1,3) Set(1,2,3)
Automatically generated class decorator based on the method
qnet.algebra.abstract_algebra._idem()
usingpreprocess_create_with()
.
-
qnet.algebra.abstract_algebra.
make_classmethod
(method, cls)[source]¶ Make a bound classmethod from an unbound method taking an additional first argument
cls
Parameters: - method (FunctionType) – The unbound method
- cls (type) – The class to bind it to
Returns: Bound class method
Return type: MethodType
-
qnet.algebra.abstract_algebra.
match
(pattern, expr)[source]¶ Match a pattern against an expression and return a Match object if successful or False, if not. Works recursively.
Parameters: - pattern (Expression or PatternTuple) – Pattern expression
- expr (Expression or OperandsTuple) – Expression to match against the pattern.
Returns: Match object or False
Return type: Match or False
-
qnet.algebra.abstract_algebra.
match_range
(pattern)[source]¶ Compute how many objects/operands a given pattern can minimally and maximally match.
Parameters: pattern – The pattern object Returns: min_number, max_number Return type: tuple Raise: ValueError, if unknown pattern mode for Wildcard object
-
qnet.algebra.abstract_algebra.
match_replace
(dcls)¶ Match and replace a full operand specification to a function that provides a replacement for the whole expression or raises a
CannotSimplify
exception. E.g.First define wildcards:
>>> A = wc("A") >>> A_float = wc("A", head = float)
Then an operation:
>>> @match_replace >>> class Invert(Operation): >>> _rules = []
Then some _rules:
>>> Invert._rules += [ >>> ((Invert(A),), lambda A: A), >>> ((A_float,), lambda A: 1./A), >>> ]
Check rule application:
>>> Invert.create("hallo") # matches no rule Invert("hallo") >>> Invert.create(Invert("hallo")) # matches first rule "hallo" >>> Invert.create(.2) # matches second rule 5.
A pattern can also have the same wildcard appear twice:
>>> @match_replace >>> class X(Operation): >>> _rules = [ >>> ((A, A), lambda A: A), >>> ]
>>> X.create(1,2) X(1,2)
>>> X.create(1,1) 1
Automatically generated class decorator based on the method
qnet.algebra.abstract_algebra._match_replace()
usingpreprocess_create_with()
.
-
qnet.algebra.abstract_algebra.
match_replace_binary
(dcls)¶ Similar to
match_replace()
, but for arbitrary length operations, such that each two pairs of subsequent operands are matched pairwise.>>> A = wc("A")
>>> @match_replace_binary >>> class FilterDupes(Operation): >>> _rules = [ >>> ((A,A), lambda A: A), >>> ]
>>> FilterDupes.create(1,2,3,4) # No subsequent duplicates present FilterDupes(1,2,3,4)
>>> FilterDupes.create(1,2,2,3,4) # Some duplicates FilterDupes(1,2,3,4)
Note that this only works for subsequent duplicate entries:
>>> FilterDupes.create(1,2,3,2,4) # Some duplicates, but not subsequent FilterDupes(1,2,3,2,4)
Automatically generated class decorator based on the method
qnet.algebra.abstract_algebra._match_replace_binary()
usingpreprocess_create_with()
.
-
qnet.algebra.abstract_algebra.
mathematica
(s)¶
-
qnet.algebra.abstract_algebra.
orderby
(dcls)¶ Re-order arguments via the class’s
order_key
key object/function. Use this for commutative operations: E.g.>>> @orderby >>> class Times(Operation): >>> pass >>> Times.create(2,1) Times(1,2)
Automatically generated class decorator based on the method
qnet.algebra.abstract_algebra._orderby()
usingpreprocess_create_with()
.
-
qnet.algebra.abstract_algebra.
preprocess_create_with
(method)[source]¶ This factory method allows for adding argument pre-processing decorators to a class’s
create
classmethod.Parameters: method (FunctionType) – A decorating create classmethod f()
with signature:f(decorated_class, decorated_method, cls, *args)
Returns: A class decorator function that decorates the ‘create’ classmethod of the decorated class. Return type: FunctionType
-
qnet.algebra.abstract_algebra.
prod
(sequence, neutral=1)[source]¶ Analog of the builtin sum() method. :param sequence: Sequence of objects that support being multiplied to each other. :type sequence: Any object that implements __mul__() :param neutral: The initial return value, which is also returned for zero-length sequence arguments. :type neutral: Any object that implements __mul__() :return: The product of the elements of sequence
-
qnet.algebra.abstract_algebra.
set_union
(*sets)[source]¶ Similar to
sum()
, but for sets. Generate the union of an arbitrary number of set arguments.Parameters: sets (set) – Sets to for the union of. Returns: Union set. Return type: set
-
qnet.algebra.abstract_algebra.
singleton
(cls)[source]¶ Singleton class decorator. Turns a class object into a unique instance.
Parameters: cls (type) – Class to decorate Returns: The singleton instance of that class Return type: cls
-
qnet.algebra.abstract_algebra.
substitute
(expr, var_map)[source]¶ (Safe) substitute, substitute objects for all symbols.
Parameters: - expr – The expression in which to perform the substitution
- var_map (dict) – The substitution dictionary. See
qnet.algebra.abstract_algebra.substitute()
documentation
-
qnet.algebra.abstract_algebra.
tex
(obj)[source]¶ Parameters: obj – Object to represent in LaTeX. Returns: Return a LaTeX string-representation of obj. Return type: str
-
qnet.algebra.abstract_algebra.
unequals
(x)¶
-
qnet.algebra.abstract_algebra.
update_pattern
(expr, match_obj)[source]¶ Replace all wildcards in the pattern expression with their matched values as specified in a Match object.
Parameters: - expr (Expression or PatternTuple) – Pattern expression
- match_obj (Match) – Match object
Returns: Expression with replaced wildcards
Return type:
-
qnet.algebra.abstract_algebra.
wc
(name_mode='_', head=None, condition=None)[source]¶ Helper function to create a Wildcard object.
Parameters: - name_mode (str) –
Combined name and mode (cf
Wildcard
) argument."A"
->name="A", mode = Wildcard.single
"A_"
->name="A", mode = Wildcard.single
"B__"
->name="B", mode = Wildcard.one_or_more
"B___"
->name="C", mode = Wildcard.zero_or_more
- head (tuple or ClassType or None) – See Wildcard doc
- condition (FunctionType or None) – See Wildcard doc
Returns: A Wildcard object
Return type: - name_mode (str) –
hilbert_space_algebra
Module¶
The Hilbert Space Algebra¶
This module defines some simple classes to describe simple and composite/tensor (i.e., multiple degree of freedom) Hilbert spaces of quantum systems.
For more details see Hilbert Space Algebra.
-
exception
qnet.algebra.hilbert_space_algebra.
BasisNotSetError
(local_space)[source]¶ Bases:
qnet.algebra.abstract_algebra.AlgebraError
Is raised when the basis states of a LocalSpace are requested before being defined.
Parameters: local_space –
-
class
qnet.algebra.hilbert_space_algebra.
HilbertSpace
[source]¶ Bases:
object
Basic Hilbert space class from which concrete classes are derived.
-
dimension
¶ Returns: The full dimension of the Hilbert space Return type: int
-
intersect
(other)[source]¶ Find the mutual tensor factors of two Hilbert spaces.
Parameters: other (HilbertSpace) – Other Hilbert space
-
is_strict_subfactor_of
(other)[source]¶ Test whether a Hilbert space occures as a strict sub-factor in (larger) Hilbert space :type other: HilbertSpace
-
is_strict_tensor_factor_of
(other)[source]¶ Test if a space is included within a larger tensor product space. Not
True
ifself == other
.Parameters: other (HilbertSpace) – Other Hilbert space Return type: bool
-
is_tensor_factor_of
(other)[source]¶ Test if a space is included within a larger tensor product space. Also
True
ifself == other
.Parameters: other (HilbertSpace) – Other Hilbert space Return type: bool
-
local_factors
()[source]¶ Returns: A sequence of LocalSpace objects that tensored together yield this Hilbert space. Return type: tuple of LocalSpace objects
-
remove
(other)[source]¶ Remove a particular factor from a tensor product space.
Parameters: other (HilbertSpace) – Space to remove Returns: Hilbert space for remaining degrees of freedom. Return type: HilbertSpace
-
tensor
(other)[source]¶ Tensor product between Hilbert spaces
Parameters: other (HilbertSpace) – Other Hilbert space Returns: Tensor product space. Return type: HilbertSpace
-
-
class
qnet.algebra.hilbert_space_algebra.
LocalSpace
(*operands)[source]¶ Bases:
qnet.algebra.hilbert_space_algebra.HilbertSpace
,qnet.algebra.abstract_algebra.Operation
Basic class to instantiate a local Hilbert space, i.e., for a single degree of freedom.
LocalSpace(name, namespace)
Parameters: - name (str) – The identifier of the local space / degree of freedom
- namespace (str) – The namespace for the degree of freedom, useful in hierarchical system models.
-
basis
¶ Returns: The set of basis states of the local Hilbert space Return type: sequence of int or str
-
classmethod
create
(*args)¶ Instead of directly instantiating an instance of any subclass of Operation, it is advised to call the
create()
classmethod instead. This method takes the same arguments as the constructor, but can preprocess them and even return an object of a different type based on the operands.param operands: The operands for the operation. – LocalSpace.create() preprocessed by _check_signature –
Check that the operands passed to the create classmethod of an Operation type conform to certain types. For each allowed argument/operand, provide a tuple of types (or one of
CLS, DCLS
, see extended_isinstance docs). E.g.>>> @check_signature >>> class X(Operation): >>> signature = str, (int, str) >>> >>> X.create("1", 2) X("1", 2) >>> X.create("1", "2") X("1", "2")
The following all raise
WrongSignatureError
exception.>>> X.create("1") >>> X.create(1, "1") >>> X.create("1", 2, 3)
-
dimension
¶ The local state space dimension.
-
signature
= (<class 'str'>, <class 'str'>)¶
-
class
qnet.algebra.hilbert_space_algebra.
ProductSpace
(*operands)[source]¶ Bases:
qnet.algebra.hilbert_space_algebra.HilbertSpace
,qnet.algebra.abstract_algebra.Operation
Tensor product space class for an arbitrary number of local space factors.
ProductSpace(*factor_spaces)
Parameters: factor_spaces (HilbertSpace) – The Hilbert spaces to be tensored together. -
classmethod
create
(*args)¶ None – ProductSpace.create() preprocessed by _filter_neutral –
Remove occurrences of a neutral element from the argument/operand list, if that list has at least two elements. To use this, one must also specify a neutral element, which can be anything that allows for an equality check with each argument. E.g.
>>> @filter_neutral >>> class X(Operation): >>> neutral_element = 1 >>> X.create(2,1,3,1) X(2,3)
– ProductSpace.create() preprocessed by _check_signature_assoc –
Like
check_signature()
but forassoc()
-decorated Operations. In this case the signature need only contain a single entry.>>> @assoc >>> @check_signature >>> class X(Operation): >>> signature = str >>> X.create("hello", "you") X("hello", "you")
The following then raises a
WrongSignatureError
because the third argument is no string>>> X.create("hello", "you", 2)
– ProductSpace.create() preprocessed by _idem –
Remove duplicate arguments and order them via the cls’s order_key key object/function. E.g.
>>> @idem >>> class Set(Operation): >>> pass >>> Set.create(1,2,3,1,3) Set(1,2,3)
– ProductSpace.create() preprocessed by convert_to_spaces_mtd –
For all operands that are merely of type str or int, substitute LocalSpace objects with corresponding labels: For a string, just itself, for an int, a string version of that int.– ProductSpace.create() preprocessed by _assoc –
Associatively expand out nested arguments of the flat class.
>>> @assoc >>> class Plus(Operation): >>> pass >>> Plus.create(1,Plus(2,3)) Plus(1,2,3)
-
neutral_element
= TrivialSpace¶
-
signature
= (<class 'qnet.algebra.hilbert_space_algebra.HilbertSpace'>,)¶
-
classmethod
-
qnet.algebra.hilbert_space_algebra.
convert_to_spaces_mtd
(dcls, clsmtd, cls, *ops)[source]¶ For all operands that are merely of type str or int, substitute LocalSpace objects with corresponding labels: For a string, just itself, for an int, a string version of that int.
-
qnet.algebra.hilbert_space_algebra.
local_space
(name, namespace='', dimension=None, basis=None)[source]¶ Create a LocalSpace with by default empty namespace string. If one also provides a set of basis states, these get stored via the BasisRegistry object. ALternatively, one may provide a dimension such that the states are simply labeled by a range of integers:
[0, 1, 2, ..., dimension -1]
Parameters: - name (str or int) – Local space identifier
- namespace (str) – Local space namespace, see LocalSpace documentation
- dimension (int) – Dimension of local space (optional)
- basis (sequence of int or sequence of str) – Basis state labels for local space
operator_algebra
Module¶
permutations
Module¶
-
exception
qnet.algebra.permutations.
BadPermutationError
[source]¶ Bases:
ValueError
Can be raised to signal that a permutation does not pass the :py:func:check_permutation test.
-
qnet.algebra.permutations.
block_perm_and_perms_within_blocks
(permutation, block_structure)[source]¶ Decompose a permutation into a block permutation and into permutations acting within each block.
Parameters: - permutation (tuple) – The overall permutation to be factored.
- block_structure (tuple) – The channel dimensions of the blocks
Returns: (block_permutation, permutations_within_blocks)
Whereblock_permutations
is an image tuple for a permutation of the block indices andpermutations_within_blocks
is a list of image tuples for the permutations of the channels within each blockReturn type: tuple
-
qnet.algebra.permutations.
check_permutation
(permutation)[source]¶ Verify that a tuple of permutation image points
(sigma(1), sigma(2), ..., sigma(n))
is a valid permutation, i.e. each number from 0 and n-1 occurs exactly once. I.e. the following set-equality must hold:{sigma(1), sigma(2), ..., sigma(n)} == {0, 1, 2, ... n-1}
Parameters: permutation (tuple) – Tuple of permutation image points Return type: bool
-
qnet.algebra.permutations.
compose_permutations
(alpha, beta)[source]¶ Find the composite permutation
\[\begin{split}\sigma := \alpha \cdot \beta \\ \Leftrightarrow \sigma(j) = \alpha\left(\beta(j)\right) \\\end{split}\]Parameters: - a – first permutation image tuple
- beta (tuple) – second permutation image tuple
Returns: permutation image tuple of the composition.
Return type: tuple
-
qnet.algebra.permutations.
concatenate_permutations
(a, b)[source]¶ - Concatenate two permutations:
- s = a [+] b
Parameters: - a (tuple) – first permutation image tuple
- b (tuple) – second permutation image tuple
Returns: permutation image tuple of the concatenation.
Return type: tuple
-
qnet.algebra.permutations.
full_block_perm
(block_permutation, block_structure)[source]¶ Extend a permutation of blocks to a permutation for the internal signals of all blocks. E.g., say we have two blocks of sizes (‘block structure’)
(2, 3)
, then a block permutation that switches the blocks would be given by the image tuple(1,0)
. However, to get a permutation of all 2+3 = 5 channels that realizes that block permutation we would need(2, 3, 4, 0, 1)
Parameters: - block_permutation (tuple) – permutation image tuple of block indices
- block_structure (tuple) – The block channel dimensions, block structure
Returns: A single permutation for all channels of all blocks.
Return type: tuple
-
qnet.algebra.permutations.
invert_permutation
(permutation)[source]¶ Compute the image tuple of the inverse permutation. :param permutation: A valid (cf. :py:func:check_permutation) permutation. :return: The inverse permutation tuple :rtype: tuple
-
qnet.algebra.permutations.
permutation_from_block_permutations
(permutations)[source]¶ Reverse operation to
permutation_to_block_permutations()
Compute the concatenation of permutations(1,2,0) [+] (0,2,1) --> (1,2,0,3,5,4)
Parameters: permutations (list of tuples) – A list of permutation tuples [t = (t_0,...,t_n1), u = (u_0,...,u_n2),..., z = (z_0,...,z_nm)]
Returns: permutation image tuple s = t [+] u [+] ... [+] z
Return type: tuple
-
qnet.algebra.permutations.
permutation_from_disjoint_cycles
(cycles, offset=0)[source]¶ Reconstruct a permutation image tuple from a list of disjoint cycles :param cycles: sequence of disjoint cycles :type cycles: list or tuple :param offset: Offset to subtract from the resulting permutation image points :type offset: int :return: permutation image tuple :rtype: tuple
-
qnet.algebra.permutations.
permutation_to_block_permutations
(permutation)[source]¶ If possible, decompose a permutation into a sequence of permutations each acting on individual ranges of the full range of indices. E.g.
(1,2,0,3,5,4) --> (1,2,0) [+] (0,2,1)
Parameters: permutation (tuple) – A valid permutation image tuple s = (s_0,...s_n)
withn > 0
Returns: A list of permutation tuples [t = (t_0,...,t_n1), u = (u_0,...,u_n2),..., z = (z_0,...,z_nm)]
such thats = t [+] u [+] ... [+] z
Return type: list of tuples Raise: ValueError
-
qnet.algebra.permutations.
permutation_to_disjoint_cycles
(permutation)[source]¶ Any permutation sigma can be represented as a product of cycles. A cycle (c_1, .. c_n) is a closed sequence of indices such that
sigma(c_1) == c_2, sigma(c_2) == sigma^2(c_1)== c_3, …, sigma(c_(n-1)) == c_n, sigma(c_n) == c_1Any single length-n cycle admits n equivalent representations in correspondence with which element one defines as c_1.
(0,1,2) == (1,2,0) == (2,0,1)A decomposition into disjoint cycles can be made unique, by requiring that the cycles are sorted by their smallest element, which is also the left-most element of each cycle. Note that permutations generated by disjoint cycles commute. E.g.,
(1, 0, 3, 2) == ((1,0),(3,2)) –> ((0,1),(2,3)) normal formParameters: permutation (tuple) – A valid permutation image tuple Returns: A list of disjoint cycles, that when comb Return type: list Raise: BadPermutationError
-
qnet.algebra.permutations.
permute
(sequence, permutation)[source]¶ Apply a permutation sigma({j}) to an arbitrary sequence.
Parameters: - sequence – Any finite length sequence
[l_1,l_2,...l_n]
. If it is a list, tuple or str, the return type will be the same. - permutation (tuple) – permutation image tuple
Returns: The permuted sequence
[l_sigma(1), l_sigma(2), ..., l_sigma(n)]
Raise: BadPermutationError or ValueError
- sequence – Any finite length sequence