Skip to content

Improvements to the construction of subalgebras#41602

Merged
vbraun merged 5 commits intosagemath:developfrom
tscrim:algebras/improve_subalgebra
Mar 22, 2026
Merged

Improvements to the construction of subalgebras#41602
vbraun merged 5 commits intosagemath:developfrom
tscrim:algebras/improve_subalgebra

Conversation

@tscrim
Copy link
Copy Markdown
Collaborator

@tscrim tscrim commented Feb 6, 2026

This speeds up the construction of subalgebras by only applying generators to newly created elements (i.e., not in the span of the previous iteration). We also take into account the basis order (which also works for things that are indexed by objects that do not have natural comparisons).

📝 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

@orlitzky
Copy link
Copy Markdown
Contributor

orlitzky commented Feb 8, 2026

Tangential, but it would be nice to have the category and order arguments documented.

@tscrim
Copy link
Copy Markdown
Collaborator Author

tscrim commented Feb 10, 2026

@orlitzky Good point, done.

@tscrim
Copy link
Copy Markdown
Collaborator Author

tscrim commented Feb 10, 2026

I refactored it slightly so that ideals can also use the same implementation (grow and expand only using the newly discovered elements).

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 10, 2026

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

@tscrim
Copy link
Copy Markdown
Collaborator Author

tscrim commented Mar 3, 2026

@orlitzky @fchapoton Can one of you review this fully? This gets quite a good speedup on this construction.

@orlitzky
Copy link
Copy Markdown
Contributor

orlitzky commented Mar 3, 2026

I'm not that familiar with FiniteDimensionalAlgebrasWithBasis, but I don't see anything unusual. Since I can't really follow what the implementation is doing at a low level, I would feel better if there were some tests for _build_basis_by_generators that e.g. pass in a random set of generators for a random algebra, and check that the result is actually a basis satisfying the stated properties.

I'd also like to check that both ideal algorithms work in all cases by tweaking the default algorithm= parameter, but I can do that myself. At that point I'm willing to trust you.

@orlitzky
Copy link
Copy Markdown
Contributor

orlitzky commented Mar 3, 2026

I tried setting both generators and basis as the default algorithm and it didn't hurt the CI.

One more idea though. In the ideal example, you could add an extra test to ensure that both algorithms return the same submodule (they should, right?). For example:

sage: MS = MatrixSpace(QQ, 5)
sage: gens = [MS.random_element() for _ in range(ZZ.random_element(5))]
sage: I = MS.ideal_submodule(gens, algorithm="generators")
sage: J = MS.ideal_submodule(gens, algorithm="basis")
sage: I.is_equal_subspace(J)
True

@tscrim tscrim force-pushed the algebras/improve_subalgebra branch from 4e581fe to 77ddb5f Compare March 4, 2026 08:59
@tscrim
Copy link
Copy Markdown
Collaborator Author

tscrim commented Mar 4, 2026

Thank you. I've added the doctest and some others to demonstrate the correct properties. I had to work around an issue with the submodule __contains__ not being specific enough, and I didn't want to change that here for a doctest (but I will fix it on a followup PR).

@orlitzky
Copy link
Copy Markdown
Contributor

orlitzky commented Mar 4, 2026

OK, I'm convinced, thanks.

@tscrim
Copy link
Copy Markdown
Collaborator Author

tscrim commented Mar 5, 2026

Thank you!

vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 6, 2026
sagemathgh-41602: Improvements to the construction of subalgebras
    
<!-- ^ 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". -->

This speeds up the construction of subalgebras by only applying
generators to newly created elements (i.e., not in the span of the
previous iteration). We also take into account the basis order (which
also works for things that are indexed by objects that do not have
natural comparisons).

### 📝 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#41602
Reported by: Travis Scrimshaw
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 15, 2026
sagemathgh-41602: Improvements to the construction of subalgebras
    
<!-- ^ 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". -->

This speeds up the construction of subalgebras by only applying
generators to newly created elements (i.e., not in the span of the
previous iteration). We also take into account the basis order (which
also works for things that are indexed by objects that do not have
natural comparisons).

### 📝 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#41602
Reported by: Travis Scrimshaw
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 18, 2026
sagemathgh-41602: Improvements to the construction of subalgebras
    
<!-- ^ 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". -->

This speeds up the construction of subalgebras by only applying
generators to newly created elements (i.e., not in the span of the
previous iteration). We also take into account the basis order (which
also works for things that are indexed by objects that do not have
natural comparisons).

### 📝 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#41602
Reported by: Travis Scrimshaw
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 21, 2026
sagemathgh-41602: Improvements to the construction of subalgebras
    
<!-- ^ 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". -->

This speeds up the construction of subalgebras by only applying
generators to newly created elements (i.e., not in the span of the
previous iteration). We also take into account the basis order (which
also works for things that are indexed by objects that do not have
natural comparisons).

### 📝 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#41602
Reported by: Travis Scrimshaw
Reviewer(s):
@vbraun vbraun merged commit 9c3b295 into sagemath:develop Mar 22, 2026
22 of 23 checks passed
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