Skip to content

Speed up fundamental group computations#41691

Open
enriqueartal wants to merge 19 commits intosagemath:developfrom
enriqueartal:zvk2
Open

Speed up fundamental group computations#41691
enriqueartal wants to merge 19 commits intosagemath:developfrom
enriqueartal:zvk2

Conversation

@enriqueartal
Copy link
Contributor

The computation of plane curve complements uses mapping class group computations and this operation can be very long if attacked directly. Some changes were applied in #36768, but some computations take forever without the changes in this PR.

Note. A previous version of this PR did not use the right branch

📝 Checklist

  • The title is concise and informative.
  • 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.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@enriqueartal enriqueartal changed the title The computation of plane curve complements uses mapping class group computations and this operation can be very long if attacked directly. Some changes were applied in #36768, but some computations take forever without the changes in this PR. Speed up fundamental group computations Feb 24, 2026
@github-actions
Copy link

github-actions bot commented Feb 24, 2026

Documentation preview for this PR (built with commit 7f13f67; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@enriqueartal
Copy link
Contributor Author

What is behind this PR is the following problem. If we have an element g of FreeGroup(n) and a braid b of BraidGroup(n), obtaining g * b (mapping class group action) can be very long if the length of the words is very long. The use of the normal forms and the fact that there are explicit formulas when the braid g is a power of the Delta element, can be used to speed up the computations.
I wonder if this could be done directly on the definition of g * b, but I do not know how to do it. Maybe it is work for another PR.

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.

I don't fully understand the computation, but I'm willing to accept it on faith and passing doctests. Here's some comments based on the code though.

Comment on lines +1675 to +1679
for gen in F.gens():
j0 = gen.Tietze()[0]
rl = (l1,) + (gen * br).Tietze() + (-l1, -j0)
gen0 = gen
for m in rnf[: -1]:
gen0 = gen0 * B(m)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not factor out elt = prod(B(m) for m in rnf[:-1]) from the for gen in F.gens(): loop? In which case, you would do here gen0 = gen0 * elt.

Actually, is there an easy way to know what rnf[-1] is without computing the entire right normal form? If so, then you could get everything you want by having elt = br * ~rnf[-1]. Although rather than the above product, simply doing elt = br * ~rnf[-1] might be faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the first question you are right. I was copying a former strategy where breaking the braid was crucial to speed the computations, it is not so clear in this case. Nevertheless, to find the relevant power of delta involved in the braid I think one must use a normal form, which is quite a fast operation.

I will add this proposed change and explain the real reasons of these changes; I am not sure if they should be added to the documentation, maybe it is a good idea.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the description, just to the PR will likely be sufficient.

enriqueartal and others added 3 commits February 26, 2026 08:00
Thanks for the suggestion!

Co-authored-by: Travis Scrimshaw <clfrngrown@aol.com>
OK

Co-authored-by: Travis Scrimshaw <clfrngrown@aol.com>
small lint change
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.

[Edit: GH was stupid and brought over partial version of my previous PR comment...Sorry for the noise.]

Comment on lines +1675 to +1679
for gen in F.gens():
j0 = gen.Tietze()[0]
rl = (l1,) + (gen * br).Tietze() + (-l1, -j0)
gen0 = gen
for m in rnf[: -1]:
gen0 = gen0 * B(m)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the description, just to the PR will likely be sufficient.

simplify a product
@enriqueartal
Copy link
Contributor Author

enriqueartal commented Feb 26, 2026

I try to explain the reasons for these changes. The fundamental groups computed are the quotient of a free group by some relations. For some of them, we need to compute $g\cdot b$ where $g$ is a generator of a free group $\mathbb{F}_n$ and $b$ is a braid in $n$ strands. The action is already implemented in sage.

If the length of the word defining $b$ is too big, the computation of $g\cdot b$ can take forever. In some cases, maybe the braid is too big and there is no solution. But in some cases the following solution works. First,
there are some (positive permutation) braids $b_1,\dots,b_r$ and an integer $m\in\mathbb{Z}$ such that two different words defining the same braid produce the same $(b_1,\dots,b_r,m)$. Moreover $b=b_1\cdot\ldots\cdot b_r\cdot\Delta^m$ where $\Delta$ is a special braid; moreover the word $c:=b_1\cdot\ldots\cdot b_r$ is usually much shorter than $b$. Hence the computation of $h:=g\cdot c$ is much faster.

There are closed formulas for $x_i\cdot\Delta$, when $x_i$ is a generator of $\Delta$. Moreover,

$g\cdot(\Delta)^2=(x_1\cdot\ldots\cdot x_n)\cdot g (x_1\cdot\ldots\cdot x_n)^{-1}.$

If $r=r_1 + 2 r_2$, $r_1=0,1$, then,

$g\cdot b = c\cdot \Delta^r = (c\cdot \Delta^{r_1})\cdot(\Delta^2)^{r_2}$

and the closed formulas are much faster than running along the words defined by the powers of $\Delta$.

@enriqueartal
Copy link
Contributor Author

Some mistakes produced errors in the text. In particular when the right normal form has only a power of the delta element of the braid group, the product of an empty list gave one instead of a braid. On the other side a simplification of the code concerning cnja and cnjb gave a wrong result. The tests passed locally. Waiting to check if they pass here.

@tscrim
Copy link
Collaborator

tscrim commented Mar 6, 2026

Thank you for the details. Seems like the tests pass here. So I should finish the review then?

@enriqueartal
Copy link
Contributor Author

For me it is OK

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.

Then positive review.

vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 15, 2026
sagemathgh-41691: Speed up fundamental group computations
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

The computation of plane curve complements uses mapping class group
computations and this operation can be very long if attacked directly.
Some changes were applied in
sagemath#36768, but some computations take
forever without the changes in this PR.

Note. A previous version of this PR did not use the right branch

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [X] The title is concise and informative.
- [X] 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.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#41691
Reported by: Enrique Manuel Artal Bartolo
Reviewer(s): Enrique Manuel Artal Bartolo, Travis Scrimshaw
vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 18, 2026
sagemathgh-41691: Speed up fundamental group computations
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

The computation of plane curve complements uses mapping class group
computations and this operation can be very long if attacked directly.
Some changes were applied in
sagemath#36768, but some computations take
forever without the changes in this PR.

Note. A previous version of this PR did not use the right branch

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [X] The title is concise and informative.
- [X] 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.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#41691
Reported by: Enrique Manuel Artal Bartolo
Reviewer(s): Enrique Manuel Artal Bartolo, Travis Scrimshaw
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.

3 participants