Skip to content
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

Directly convert PermutationGroup element into sized Permutation #37288

Merged
merged 12 commits into from
Mar 25, 2024

Conversation

RuchitJagodara
Copy link
Contributor

This patch fixes #37284 by converting the input into a Permutation class object if
it is the object of another class.


📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.

⌛ Dependencies

@RuchitJagodara
Copy link
Contributor Author

Does anybody know any better way so that we can avoid try except block here ?

@tscrim
Copy link
Collaborator

tscrim commented Feb 12, 2024

Does anybody know any better way so that we can avoid try except block here ?

See my comment. Checking for specific types is usually better than checking for not a specific type when trying to apply methods.

@grhkm21
Copy link
Contributor

grhkm21 commented Feb 12, 2024

Oops, learned something myself. I will keep that in mind too :)

RuchitJagodara and others added 2 commits February 12, 2024 19:33
Co-authored-by: Travis Scrimshaw <clfrngrown@aol.com>
Co-authored-by: grhkm21 <83517584+grhkm21@users.noreply.github.com>
@RuchitJagodara
Copy link
Contributor Author

I have done all necessary changes that you suggested, thank you for your suggestions ! : )

@tscrim
Copy link
Collaborator

tscrim commented Feb 14, 2024

Thank you. However, your test is not good because that was working before from the coercion map defined using P5._from_permutation_group_element. It would probably be better to go through that method here as well. (Yes, it does the same thing with going back through the _element_constructor_, but it might do something smarter/faster in the future. It also makes the code easier to debug should a problem arise later.) Sorry I missed that before.

@mantepse
Copy link
Collaborator

Is #37318 related?

@tscrim
Copy link
Collaborator

tscrim commented Feb 14, 2024

Is #37318 related?

From a quick look, doesn’t seem related.

@RuchitJagodara
Copy link
Contributor Author

Then, should I change _coerce_map_from function and redirect the flow to the _from_permutation_group_element whenever G is a PermutationGroup, but I don't know what to include in isinstance function to check wether the group is permutation group or not ?

if isinstance(G, SymmetricGroup):
D = G.domain()

Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is not that good (it is better to not depend on the ordering of the group, and a slightly more general group on, say, 4 letters would be better), but it is sufficient. Hence, we can merge this as-is, but it would be nice to have a slightly better test.

@RuchitJagodara
Copy link
Contributor Author

Should I change the test? (Just confirming because @tscrim approved the changes but there is still a 'needs work' label on this PR.)

@tscrim
Copy link
Collaborator

tscrim commented Feb 17, 2024

@RuchitJagodara I’ve left the decision up to you, but it would be better to have a more generic test.

@RuchitJagodara
Copy link
Contributor Author

I have updated the test, @tscrim can you please review that ?

@tscrim
Copy link
Collaborator

tscrim commented Feb 18, 2024

That is essentially the same test. The point is to have a more interesting group than something (trivially) isomorphic to the symmetric group. So something like the group generated by [(1,2)(2,3), (4,5)].

@RuchitJagodara
Copy link
Contributor Author

RuchitJagodara commented Feb 25, 2024

Sorry, because of my mid-term exams, I was not able to make these changes earlier. But I have changed the test and it is not dependent on ordering of the group, and is not trivial, also.

@RuchitJagodara
Copy link
Contributor Author

That is essentially the same test. The point is to have a more interesting group than something (trivially) isomorphic to the symmetric group. So something like the group generated by [(1,2)(2,3), (4,5)].

When I try to create a permutation group using the generators [(1,2)(2,3), (4,5)], it gives me a ValueError, saying 'invalid data to initialize a permutation.' I am a bit confused as to why that error is occurring.

@tscrim
Copy link
Collaborator

tscrim commented Feb 26, 2024

That is essentially the same test. The point is to have a more interesting group than something (trivially) isomorphic to the symmetric group. So something like the group generated by [(1,2)(2,3), (4,5)].

When I try to create a permutation group using the generators [(1,2)(2,3), (4,5)], it gives me a ValueError, saying 'invalid data to initialize a permutation.' I am a bit confused as to why that error is occurring.

Sorry, there was a typo on my part. I meant

sage: G = PermutationGroup([[(1,2),(3,4)], [(4,5)]])
sage: G.isomorphism_to(DihedralGroup(6))
Permutation group morphism:
  From: Permutation Group with generators [(4,5), (1,2)(3,4)]
  To:   Dihedral group of order 12 as a permutation group
  Defn: [(4,5), (1,2)(3,4)] -> [(1,2)(3,6)(4,5), (1,3)(4,6)]

Although you could interpret it as

sage: G = PermutationGroup([[(1,2,3)], [(4,5)]])  # = Z3 x Z2

Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyways, the test is better now. Thank you. Just a few details left.

src/sage/combinat/permutation.py Outdated Show resolved Hide resolved
RuchitJagodara and others added 2 commits February 26, 2024 18:08
Co-authored-by: Travis Scrimshaw <clfrngrown@aol.com>
@RuchitJagodara
Copy link
Contributor Author

I have updated the test. Thank you for your suggestions.

Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. LGTM now.

Copy link

Documentation preview for this PR (built with commit 54747b6; changes) is ready! 🎉

@vbraun vbraun merged commit 31a08e0 into sagemath:develop Mar 25, 2024
16 checks passed
@mkoeppe mkoeppe added this to the sage-10.4 milestone Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot convert PermutationGroup element into sized Permutation
6 participants