Skip to content

Commit

Permalink
switch from qfbclassno() to quadclassunit() for large discriminants
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyyx4 committed Nov 3, 2023
1 parent 7c0a6c7 commit 4797a51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/sage/quadratic_forms/bqf_class_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def order(self):
r"""
Return the order of this form class group (the *class number*).
ALGORITHM: :pari:`qfbclassno`
ALGORITHM: :func:`sage.rings.number_field.order.quadratic_order_class_number`.
EXAMPLES::
Expand All @@ -272,7 +272,12 @@ def order(self):
sage: BQFClassGroup(-99999).order()
224
"""
return ZZ(pari.qfbclassno(self._disc))
# Beware: If this code is ever generalized to positive
# discriminants, care must be taken to use the correct
# notion of class number. We may need the *narrow* class
# number here; see PARI's documentation for qfbclassno().
from sage.rings.number_field.order import quadratic_order_class_number
return quadratic_order_class_number(self._disc)

cardinality = order

Expand Down
25 changes: 24 additions & 1 deletion src/sage/rings/number_field/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@
from sage.libs.pari.all import pari


def quadratic_order_class_number(disc):
r"""
Return the class number of the quadratic order of given discriminant.
EXAMPLES::
sage: from sage.rings.number_field.order import quadratic_order_class_number
sage: quadratic_order_class_number(-419)
9
sage: quadratic_order_class_number(60)
2
ALGORITHM: Either :pari:`qfbclassno` or :pari:`quadclassunit`,
depending on the size of the discriminant.
"""
# cutoffs from PARI documentation
if disc < -10**25 or disc > 10**10:
h = pari.quadclassunit(disc)[0]
else:
h = pari.qfbclassno(disc)
return ZZ(h)


class OrderFactory(UniqueFactory):
r"""
Abstract base class for factories creating orders, such as
Expand Down Expand Up @@ -1096,7 +1119,7 @@ def class_number(self, proof=None):
K = self.number_field()
if K.degree() != 2:
raise NotImplementedError("computation of class numbers of non-maximal orders not in quadratic fields is not implemented")
return ZZ(pari.qfbclassno(self.discriminant()))
return quadratic_order_class_number(self.discriminant())
return self.number_field().class_number(proof=proof)

def class_group(self, proof=None, names='c'):
Expand Down

0 comments on commit 4797a51

Please sign in to comment.