Skip to content

Commit

Permalink
use sets and defaultdict
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCremona committed Mar 6, 2023
1 parent ccea429 commit d83aa3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
21 changes: 8 additions & 13 deletions src/sage/schemes/elliptic_curves/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,23 +784,22 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
# global hDf_dict, only including those (D,f) for which |D|*f**2
# <= B if B was provided:

T = hDf_dict.copy()

if not count:
for h in T:
T[h] = [Df for Df in T[h] if Df[0].abs()*Df[1]**2<=B]

# h_dict caches the class number h of all discriminants previously
# encountered; we will use the function OrderClassNumber() to
# quicky compute the class number of non-fundamental discriminants
# from the fundamental ones. Note that in the initialisation, the
# keys of h_dict include nonfundamental discriminants, but we only
# update it with fundamental ones.

from collections import defaultdict
T = defaultdict(set)
h_dict = {}
for h, Dflist in hDf_dict.items():
for D0,f in Dflist:
h_dict[D0*f**2] = h
if not count:
Dflist = [Df for Df in Dflist if Df[0].abs()*Df[1]**2<=B]
T[h] = set(Dflist)

# We do not need to certify the class number from :pari:`qfbclassno` for discriminants under 2*10^10
if B < 2*10**10:
Expand All @@ -827,16 +826,12 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):

# If the class number of this order is within the range, then store (D0,f)
if h <= hmax:
z = (D0, f)
if h in T:
if z not in T[h]:
T[h].append(z)
else:
T[h] = [z]
T[h].add((D0,f))

# sort each list of (D,f) pairs by (|D|,f)

for h in T:
T[h] = list(T[h])
T[h].sort(key=lambda Df: (Df[0].abs(), Df[1]))

# count is None precisely when the user provided a value of B
Expand All @@ -846,7 +841,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
if len(T[h]) != count[h]:
raise RuntimeError("number of discriminants inconsistent with Watkins's table")
# 2. Update the global dict
hDf_dict.update(T)
hDf_dict.update(dict(T))

return T

Expand Down
6 changes: 3 additions & 3 deletions src/sage/schemes/elliptic_curves/ell_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ def height_above_floor(self, ell, e):
valuation of the conductor of the order generated by the
Frobenius `\pi_E`; the height of `j(E)` on its
ell-volcano is the `\ell`-adic valuation of the conductor
of the order `\End(E)`.
of the order `\text{End}(E)`.
ALGORITHM:
Expand Down Expand Up @@ -1515,8 +1515,8 @@ def endomorphism_discriminant_from_class_number(self, h):
OUTPUT:
(integer) The discriminant of the endomorphism ring `\End(E)`, if
this has class number ``h``. If `\End(E)` does not have class
(integer) The discriminant of the endomorphism ring `\text{End}(E)`, if
this has class number ``h``. If `\text{End}(E)` does not have class
number ``h``, a ``ValueError`` is raised.
ALGORITHM:
Expand Down

0 comments on commit d83aa3a

Please sign in to comment.