New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
note added about Cycle and Permutation application of non-disjoint cycles #12510
Conversation
ping @siefkenj |
I'm finding this pretty hard to follow...The functionality I need is the following: A call |
Here's a demo:
|
Okay. I still don't think this can be used for my purposes, though. If someone gives me a list of numbers, it is an explicit permutation, and if someone gives me a list of pairs, it is a list of swaps when evaluated left to right. So, if someone gives me |
See point (2) in the OP. With that you could do In the meanwhile, I think |
It is often confusing that there are two different ways of composing permutations. This is how the product of permutations is defined in SymPy:
However, permutations are also mappings and, when considered as mappings, the composed mapping whose value at i is b(a(i)) is denoted b°a (with degree sign emulating the proper \circ sign). Hence 'left to right' using one composition means 'right to left' with the other composition. So the ordering of cycles in this example
is opposite to that of composed permutations
|
Thanks, @jksuom . And if you have any feedback on what should or shouldn't be added here, I would appreciate it. We could disallow multiple-list input to Permutation so as not to create an ambiguous situation (the single-list instantiation of a permutation with a permutation vs the multi-list instantiation with 2 or more cycles). But I like the symmetry of being able to do L to R instantiation with both as Currently we have entry options of My suggested addition is to add But I wonder if a method named |
I'm afraid that having two methods of composing permutations would lead to confusion and coding errors. The definition currently used in SymPy is prevalent in the literature, and it is the one that those working in this area are expecting. That is also the order in which permutations are returned by some matrix methods. The alternative order does not seem to be used in SymPy. Hence I would prefer keeping a single order as in calls like |
Glad for that reassurance. OK, then, perhaps just adding a docstring example of the
In this comment I already demonstrate how the result for @siefkenj 's case can be handled. |
I completely agree with this. |
I will simply add a note in the docstring about the ordering issue and that it only matters when the cycles are not disjoint. Or maybe the docs would be a better place for this? Here is a workaround for @siefkenj 👍
|
If someone can see if this added note is clear, then this is done. |
Reverse-order multiplication is available with the rmul method. A helper function like this can give reverse order application of cycles when a list of lists is given or else provide the permutation as given by a list of ints: >>> def LRPerm(w): ... from sympy.utilities.iterables import is_sequence ... return Permutation(w if not (w and is_sequence(w[0])) else ... Permutation.rmul(*[Permutation(*i) for i in w])) ... >>> Permutation(1,2)(2,3) Permutation(1, 3, 2) >>> Permutation([(1,2), (2,3)]) Permutation(1, 3, 2) LRPerm will apply cycles from left to right: >>> LRPerm([(1,2), (2,3)]) Permutation(1, 2, 3) LRPerm gives the same result when a single list is given: >>> LRPerm([0,1,3,2])==Permutation([0,1,3,2]) True
Old notes hidden in the comments of this OP.
No change has been made other than to put a note of caution in the docstring of permutation.
closes #12487