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

Tests to see if ideal in quaternion algebra is primitive (cyclic) #37112

Merged
merged 8 commits into from
Feb 2, 2024

Conversation

giacomoborin
Copy link
Contributor

@giacomoborin giacomoborin commented Jan 19, 2024

New methods for QuaternionFractionalIdeal_rational:

  • QuaternionFractionalIdeal_rational.is_integral()
  • QuaternionFractionalIdeal_rational.is_primitive()
  • QuaternionFractionalIdeal_rational.primitive_decomposition()

These methods verify if an ideal in quaternion rational algebra is integral, primitive (cyclic) and decompose it as a primitive ideal. Part of the code came from https://learningtosqi.github.io.
Also added the Quaternion Algebras book by J. Voight in the bibliography.

Done with @gioella

#sd123

@grhkm21
Copy link
Contributor

grhkm21 commented Jan 20, 2024

Your docstrings are not formatted properly. I have reformatted your is_integral here, check it out and try to follow it for the other two functions. Most importantly,

  • The docstring should be left aligned with the r""", and wrapped at (I think) 80 character width
  • "EXAMPLES::" must have two colons at the end, it is a special keyword for test cases

@grhkm21
Copy link
Contributor

grhkm21 commented Jan 20, 2024

Also if you look at the tests ^, and in particular "Lint / lint (pull_request)", it fails for several formatting reasons. Please also edit them :) It's simple things like "blank line contains whitespace" and "trailing whitespace".

PS: This indicates your editor is messed up - it should remove these for you.

O_basis = self.left_order().basis_matrix()

# Write I in the basis of its left order via rref
M = block_matrix(1,2,[O_basis.transpose(),I_basis.transpose()]).rref()[:,4:]
Copy link
Member

Choose a reason for hiding this comment

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

I believe this is just M = O_basis.solve_left(I_basis)?


# Write I in the basis of its left order via rref
M = block_matrix(1,2,[O_basis.transpose(),I_basis.transpose()]).rref()[:,4:]
g = Integer(gcd((gcd(M_row) for M_row in M)))
Copy link
Member

Choose a reason for hiding this comment

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

Shorter way: g = Integer(gcd(M.list())).

g = Integer(gcd((gcd(M_row) for M_row in M)))

# If g is 1 then the ideal is primitive
if g == 1:
Copy link
Member

Choose a reason for hiding this comment

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

The test g.is_one() is significantly faster than g == 1, since the latter goes through the type coercion system to find a common parent type to do the comparison in.

Comment on lines 3046 to 3052
if self.__left_order is not None:
return all([b in self.left_order() for b in self.basis()])
elif self.__right_order is not None:
return all([b in self.right_order() for b in self.basis()])
else:
self_square = self**2
return all([b in self for b in self_square.basis()])
Copy link
Member

Choose a reason for hiding this comment

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

Each of these tests should be equivalent to one of the form A.free_module() <= B.free_module(). (See also #37113.)


"""
_,g = self.primitive_decomposition()
return 1 == g
Copy link
Member

Choose a reason for hiding this comment

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

Same here, using .is_one() is faster.

giacomoborin and others added 3 commits January 28, 2024 17:27
In this small commit I inserted all the improvements pointed out previously by @yyyyx4 (many thanks!)
@giacomoborin
Copy link
Contributor Author

In the last two commits I should have fixed the problems with the format pointed out by @grhkm21 and @yyyyx4 reviews. Thanks for the comments and sorry for the lacks in the pull request.

Comment on lines 3113 to 3115
TESTS::

Checks on random crafted ideals that they decompose as expected.
Copy link
Member

Choose a reason for hiding this comment

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

One more linter failure:

Suggested change
TESTS::
Checks on random crafted ideals that they decompose as expected.
TESTS:
Checks on random crafted ideals that they decompose as expected::

(The :: syntax only indicates that an indented block is about to follow, so here it should be moved down as indicated instead of sticking to the TESTS: header.)

@@ -56,7 +56,7 @@
from sage.structure.category_object import normalize_names
from sage.structure.parent import Parent
from sage.matrix.matrix_space import MatrixSpace
from sage.matrix.constructor import diagonal_matrix, matrix
from sage.matrix.constructor import diagonal_matrix, matrix, block_matrix
Copy link
Member

Choose a reason for hiding this comment

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

The import of block_matrix is now unused and can be removed.

Copy link

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

@yyyyx4
Copy link
Member

yyyyx4 commented Feb 1, 2024

Looks good to me, thanks!

@vbraun vbraun merged commit 2c6ebe5 into sagemath:develop Feb 2, 2024
21 of 22 checks passed
@amanmoon amanmoon mentioned this pull request Feb 10, 2024
3 tasks
@mkoeppe mkoeppe added this to the sage-10.3 milestone Mar 7, 2024
vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 18, 2024
    
I have implemented the `automatic size labeler`, which now assigns
labels to pull requests based on the number of lines changed

**Minimal**
Typically involves very small changes, bug fixes, or updates that
require only a few lines of code, often less than 50.
sagemath#37208 sagemath#37146 sagemath#37043

**Small**
Involves more substantial changes than minimal, potentially adding new
features or making modifications to existing ones. The range is usually
between 50 to 100 lines of code.
sagemath#37152 sagemath#37132

**Moderate**
Represents a significant portion of the codebase being modified, such as
adding new features, refactoring, or making extensive changes to
existing functionalities. This might involve between 100 to 300 lines of
code.
sagemath#36919 sagemath#37112

**Large**
Involves substantial and complex changes across various parts of the
codebase. This could include major architectural changes, the
introduction of new modules, or a significant overhaul of existing
features, often exceeding 300 lines of code.
sagemath#37125 sagemath#36977 sagemath#36972

### 📝 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.
- [x] I have linked a relevant issue or discussion.

Fixes: sagemath#37254
    
URL: sagemath#37262
Reported by: Aman Moon
Reviewer(s): Sebastian Oehms
vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 20, 2024
    
I have implemented the `automatic size labeler`, which now assigns
labels to pull requests based on the number of lines changed

**Minimal**
Typically involves very small changes, bug fixes, or updates that
require only a few lines of code, often less than 50.
sagemath#37208 sagemath#37146 sagemath#37043

**Small**
Involves more substantial changes than minimal, potentially adding new
features or making modifications to existing ones. The range is usually
between 50 to 100 lines of code.
sagemath#37152 sagemath#37132

**Moderate**
Represents a significant portion of the codebase being modified, such as
adding new features, refactoring, or making extensive changes to
existing functionalities. This might involve between 100 to 300 lines of
code.
sagemath#36919 sagemath#37112

**Large**
Involves substantial and complex changes across various parts of the
codebase. This could include major architectural changes, the
introduction of new modules, or a significant overhaul of existing
features, often exceeding 300 lines of code.
sagemath#37125 sagemath#36977 sagemath#36972

### 📝 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.
- [x] I have linked a relevant issue or discussion.

Fixes: sagemath#37254
    
URL: sagemath#37262
Reported by: Aman Moon
Reviewer(s): Sebastian Oehms
vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 25, 2024
    
I have implemented the `automatic size labeler`, which now assigns
labels to pull requests based on the number of lines changed

**Minimal**
Typically involves very small changes, bug fixes, or updates that
require only a few lines of code, often less than 50.
sagemath#37208 sagemath#37146 sagemath#37043

**Small**
Involves more substantial changes than minimal, potentially adding new
features or making modifications to existing ones. The range is usually
between 50 to 100 lines of code.
sagemath#37152 sagemath#37132

**Moderate**
Represents a significant portion of the codebase being modified, such as
adding new features, refactoring, or making extensive changes to
existing functionalities. This might involve between 100 to 300 lines of
code.
sagemath#36919 sagemath#37112

**Large**
Involves substantial and complex changes across various parts of the
codebase. This could include major architectural changes, the
introduction of new modules, or a significant overhaul of existing
features, often exceeding 300 lines of code.
sagemath#37125 sagemath#36977 sagemath#36972

### 📝 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.
- [x] I have linked a relevant issue or discussion.

Fixes: sagemath#37254
    
URL: sagemath#37262
Reported by: Aman Moon
Reviewer(s): Sebastian Oehms
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.

6 participants