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
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/sage/algebras/quatalg/quaternion_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
from sage.misc.cachefunc import cached_method

from sage.categories.algebras import Algebras
from sage.categories.number_fields import NumberFields

########################################################
# Constructor
Expand Down Expand Up @@ -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

Only works in quaternion algebras over number fields

OUTPUT: Boolean

EXAMPLES::

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.

sage: O0 = B.quaternion_order(O0_basis)
sage: O0.is_maximal()
True
sage: O1 = B.quaternion_order([1,i,j,i*j])
sage: O1.is_maximal()
False

TESTS::

sage: B = QuaternionAlgebra(GF(13),-1,-11)
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

....: O0.is_maximal()
....: 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()

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).


INPUT:

Expand Down
Loading