Skip to content

Conversation

user202729
Copy link
Contributor

@user202729 user202729 commented Jun 21, 2025

Currently, hermite_form can be randomly very slow (#33418, flintlib/flint#389)

When rank()==ncols(), the solution is uniquely determined, so that an alternative algorithm is to solve the system over the fraction field, then convert it back to the ring. And computing rank is much faster — the current default algorithm for ℤ picks a random prime p and compute rank modulo p.

This PR detects the full-rank case and implement the alternative algorithm.

📝 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

Copy link

Documentation preview for this PR (built with commit c71f7c9; changes) is ready! 🎉
This preview will update shortly after each push to this 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.

LGTM.

@user202729
Copy link
Contributor Author

Thanks for the reviews 🙂
Actually a caveat is Hermite form might become faster than solve linear equations over ℚ in the future (there are fast algorithms in the literature, although I don't know how fast they can be in practice)

@tscrim
Copy link
Collaborator

tscrim commented Jun 27, 2025

Well, once the code is implemented, we can revisit the comparison. ;)

vbraun pushed a commit to vbraun/sage that referenced this pull request Jun 27, 2025
sagemathgh-40276: Avoid hermite_form in solve_right if possible
    
Currently, hermite_form can be randomly very slow
(sagemath#33418,
flintlib/flint#389)

When `rank()==ncols()`, the solution is uniquely determined, so that an
alternative algorithm is to solve the system over the fraction field,
then convert it back to the ring. And computing rank is much faster —
the current default algorithm for ℤ picks a random prime p and compute
rank modulo p.

This PR detects the full-rank case and implement the alternative
algorithm.

### 📝 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.
- [x] I have linked a relevant issue or discussion.
- [x] 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#40276
Reported by: user202729
Reviewer(s): Travis Scrimshaw
@vbraun vbraun merged commit dfb0821 into sagemath:develop Jul 6, 2025
23 of 25 checks passed
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 1, 2025
sagemathgh-40497: Actually avoid hermite_form in solve_right if possible
    
I tried to speed this up in sagemath#40276
, but there was some error in logic which makes it fail.


### 📝 Checklist

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

- [ ] 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

<!-- 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#40497
Reported by: user202729
Reviewer(s): user202729
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants