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

Add test if quaternion order is maximal #37111

Merged
merged 5 commits into from
Feb 2, 2024

Conversation

syndrakon
Copy link

Add a method to sage.algebras.quatalg.quaternion_algebra.QuaternionOrder which allows to check whether the order is maximal.
This method compares the discriminant of the order to the discriminant of the algebra. According to Voight's book on quaternion algebras (chapter 15), this test is valid in number fields (but not over any field), so the method fails with a notImplementedError in other cases.

Currently, there is no method to test maximality of orders, so implementing it for quaternion algebras over number fields is some progress.

#sd123

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

a few comments on the coding style

@@ -1758,9 +1759,48 @@ def discriminant(self):

return (MatrixSpace(QQ, 4, 4)(L)).determinant().sqrt()

def is_maximal(self):
r"""
Return ``True`` if the order is maximal in the ambient quaternion algebra, ``False`` otherwise
Copy link
Contributor

Choose a reason for hiding this comment

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

The first line should be short and usually we start such description with Check whether...

-        Return ``True`` if the order is maximal in the ambient quaternion algebra, ``False`` otherwise
-        Only works in quaternion algebras over number fields
+        Check whether the order of ``self`` is maximal in the ambient
+        quaternion algebra.
+
+        Only works in quaternion algebras over number fields

....: print("This should fail")
....: except NotImplementedError:
....: print("ok")
....:
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this line

Copy link
Author

Choose a reason for hiding this comment

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

Without object now since the test was completely rewritten following @pjbruin's remarks.

....:
ok
"""
if not(self.quaternion_algebra().base_ring() in NumberFields()):
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to use "X not in Y". Furthermore, we don't start error messages with capital letters and the dot at the end is not needed.

-        if not(self.quaternion_algebra().base_ring() in NumberFields()):
-            raise NotImplementedError("Check for maximality is only implemented for quaternion algebras over number fields).")
-        return(self.discriminant() == self.quaternion_algebra().discriminant())
+        if self.quaternion_algebra().base_ring() not in NumberFields():
+            raise NotImplementedError("check for maximality is only implemented for "
+                                      "quaternion algebras over number fields")
+        return self.discriminant() == self.quaternion_algebra().discriminant()

def left_ideal(self, gens, check=True, *, is_basis=False):
r"""
Return the left ideal of this order generated by the given generators.
Only works in quaternion algebras over number fields.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an empty line after the first sentence of the docstring (see dcoudert's comment above).

sage: i,j,k = B.gens()
sage: O0_basis = (1,i,j, k)
sage: O0 = B.quaternion_order(O0_basis)
sage: try:
Copy link
Contributor

Choose a reason for hiding this comment

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

The recommended way to write doctests for error messages is

sage: O0.is_maximal()
Traceback (most recent call last):
...
NotImplementedError: check for maximality is only implemented for quaternion algebras over number fields

sage: p = 11
sage: B = QuaternionAlgebra(QQ,-1,-p)
sage: i,j,k = B.gens()
sage: O0_basis = (1,i,(i+j)/2, (1+i*j)/2)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix spacing (after each comma there should be a space except in some specific cases)

Copy link
Author

Choose a reason for hiding this comment

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

I tried, hopefully I did not miss any comma and never met such a specific case.

Copy link
Contributor

Choose a reason for hiding this comment

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

The main example is in one-element tuples, such as (1,). I also tend to omit spaces when declaring multiple symbolic variables (var('x,y')), but I'm not sure if this is generally accepted.

syndrakon added 3 commits February 1, 2024 10:30
Also remove accidental change to documentation of unrelated function from previous commit
@syndrakon
Copy link
Author

I hopefully followed all of your suggestions. Thank you for the explanations, and please tell me if I missed something.

Copy link

github-actions bot commented Feb 1, 2024

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

@vbraun vbraun merged commit b720abc into sagemath:develop Feb 2, 2024
16 of 23 checks passed
@mkoeppe mkoeppe added this to the sage-10.3 milestone Mar 7, 2024
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.

None yet

6 participants