-
-
Notifications
You must be signed in to change notification settings - Fork 519
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
Some improvements for braids computations #35214
Conversation
""" | ||
Return the right normal form of the braid. | ||
r""" | ||
A tuple of simple generators in the right normal form. The last |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could leave the original "Return the right normal form" and have your additions on the next line after a blank line.
@@ -1620,21 +1644,31 @@ def conjugating_braid(self, other): | |||
|
|||
sage: B = BraidGroup(3) | |||
sage: a = B([2, 2, -1, -1]) | |||
sage: b = B([2, 1, 2, 1]) | |||
sage: b = B([2, 2, 2, 2, 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm not understanding something, but you could leave the already existing tests and just add to them below.
sage: c = B([1]) | ||
sage: c.left_normal_form() | ||
(1, s0) | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might consider adding tests for trivial examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comments. I completed the descriptions and added more examples.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #35214 +/- ##
===========================================
- Coverage 88.62% 88.60% -0.02%
===========================================
Files 2148 2148
Lines 398855 398894 +39
===========================================
- Hits 353480 353452 -28
- Misses 45375 45442 +67
... and 23 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Fixes #35213 |
It would be good to have full coverage. Is it easy to see which of your additions don't have a test associated to them? |
For |
… the left normal form was a power of Delta to ensure all the factors of a product are braids - In pure_conjugating_braid, check if the permutation of the conjugating braid is in the subgroup generated by the permutations of the centralizing braids of self; return None if not.
Commit 690c5d5 solves a couple of problems. When the conjugating braid was trivial, as coded I multiplied a braid and an integer yielding an error. For |
I won't be able to get to this until next week. If I haven't given any comments by the end of next week, please ping me again :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not hide other computational methods but expose both through an, e.g., algorithm
argument. This is not just good for testing purposes (which you should do a more systematic comparison between the two methods), but also gives additional options to the user.
src/sage/groups/braid.py
Outdated
if p3 not in G.subgroup(LP): | ||
return None | ||
P = p3.word_problem(LP, display = False, as_list = True) | ||
b1 = prod(LB[LP.index(G(a))] ** b for a,b in P) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if P
is empty? Add a doctest checking for this corner case (if it can occur).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, if you make LP
a dict
from permutations to braids, this becomes faster and you can still pass it off to G.subgroup()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the first question a previous if
makes impossible to have P
empty. I could not pass the dict to subgroup
and even if it would be possible, I think I cannot pass it to word_problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the first question a previous
if
makes impossible to haveP
empty.
I might say also the previous p3.is_one()
also makes that the case. However, again this case should have a doctest.
I could not pass the dict to
subgroup
and even if it would be possible, I think I cannot pass it toword_problem
You can pass a dict
to subgroup
:
sage: G = groups.permutation.Symmetric(5)
sage: d = {G.random_element(): i for i in range(5)}
sage: d
{(1,5,2,4): 0, (1,5)(2,3): 1, (1,3,5,2): 2, (1,5,3,2): 3, (1,5)(2,4,3): 4}
sage: G.subgroup(d)
Subgroup generated by [(1,3,5,2), (1,5,3,2), (1,5)(2,3), (1,5)(2,4,3), (1,5,2,4)] of (Symmetric group of order 5! as a permutation group)
Indeed for word_problem
, you cannot pass the dict
, but you can do list(d)
, which will have a list in the same order the dict
d
was constructed (Python3 guarantees this).
def pure_conjugating_braid(self, other): | ||
r""" | ||
Return a pure conjugating braid, if it exists. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a more detailed description; in particular, including the definition of a pure conjugating braid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be part of the one-line description. Spend a little bit of time/mathematical notation spelling it out a bit more.
src/sage/groups/braid.py
Outdated
|
||
INPUT: | ||
|
||
- ``other`` -- the other braid to look for conjugating braid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/sage/groups/braid.py
Outdated
n = B.strands() | ||
k = int(l[0][0] % 2) | ||
b0 = B.delta() ** k * B(prod(B(a) for a in l[1:])) | ||
return b0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n = B.strands() | |
k = int(l[0][0] % 2) | |
b0 = B.delta() ** k * B(prod(B(a) for a in l[1:])) | |
return b0 | |
l[0][0] %= 2 | |
return B._element_from_libbraiding(l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/sage/groups/braid.py
Outdated
sage: b = B([2, 2, 2, 2, 1]) | ||
sage: c = b * a / b | ||
sage: d1 = a.conjugating_braid(c) | ||
sage: print (len(d1.Tietze())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8
sage: print (len(d1.Tietze())) | |
sage: print(len(d1.Tietze())) |
and similar below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/sage/groups/braid.py
Outdated
sage: a1=B([1]) | ||
sage: a2=B([2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8
sage: a1=B([1]) | |
sage: a2=B([2]) | |
sage: a1 = B([1]) | |
sage: a2 = B([2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/sage/groups/braid.py
Outdated
B = self.parent() | ||
n = B.strands() | ||
G = SymmetricGroup(n) | ||
p1 = G(self.permutation()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would only convert to G
when it becomes necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I move the definition of G
few lines below, and eliminate some conversions
src/sage/groups/braid.py
Outdated
if p1 != p2: | ||
return None | ||
b0 = self.conjugating_braid(other) | ||
if not b0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not b0: | |
if b0 is not None: |
It is better to check explicitly against None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done but putting if b0 is None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, whoops. Thanks.
Simplify code for conjugating_braid Co-authored-by: Travis Scrimshaw <clfrngrown@aol.com>
Done, with longer explanations for the commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. LGTM.
…l, TL_representation and links_gould_polynomial
I found some small typos in the documentation, @trevorkarn, could you take a look? |
@enriqueartal You need to take care of the invalid escape sequence by making the start of the doc string |
Documentation preview for this PR is ready! 🎉 |
A conjugating braid. | ||
|
||
More precisely, if the output is `d`, `o` equals ``other``, and `s` equals ``self`` | ||
then `o = d^{-1} \cdot s \cdot d`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last trivial thing: This needs a blankline after it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and also style spaces all around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of those were not PEP8 violations (higher precedence operators do not need the same spacing, which include []
and ()
), and some of them actually makes the code harder to read. However, the rule was not applied consistently. I would actually just revert those additional PEP8 spacing changes as it makes the patch larger for minimal (at best) gain. Better separation of ticket purpose.
Done. I found curious that rules were not applied consistently even in the same line, but I just kept the required line. Unless some changes are asked by you or by some other person, I stop working in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I think this is ready to go in!
@tscrim thanks for your help! |
…ations, and a 2-generator presentation <!-- Describe your changes here in detail --> This PR is a continuation of sagemath#35214. - Given an element of a symmetric group, the associated permutation braid can be constructed, added in `_element_constructor`. - The method `_standard_lift_Tietze` has been simplified (for a permutation) and now it gives a shortest word for the lift but not necesarily the smallest for the lexicographic order. The former code has been commented. - The method `presentation2gens` provides a presentation of the braid group with two generators. The general method `epimorphism` has been adapted to braid groups using this presentation and it is much faster. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#35985 Reported by: Enrique Manuel Artal Bartolo Reviewer(s): Enrique Manuel Artal Bartolo, Travis Scrimshaw
📚 Description
Fasten the computation of the left normal form of a braid, produce a shorter conjugating braid and if possible a pure conjugating braid
left_normal_form
for braids was modified to be part of the general method for Artin groups. I propose to come back to the former method, it produces the same result but much faster. I addedleft_normal_form
as a method for braid group and kept_left_normal_form_coxeter
though it is not used any more for braids.conjugating_braid
produces a braid in left normal form with high powers ofDelta
, which can be reduce to 0 or 1.conjugating_braid
a simple computation produces such a pure braid.There are mild improvements for the treatment of braid groups.
Resolves #35213
📝 Checklist
⌛ Dependencies