Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'u/pbruin/16680-elliptic_curve_cardinality_doctest' of t…
Browse files Browse the repository at this point in the history
…rac.sagemath.org:sage into u/tscrim/16680-elliptic_curve_cardinality_doctest
  • Loading branch information
Travis Scrimshaw committed Jul 19, 2014
2 parents f5e92ea + 654c680 commit 0262f93
Show file tree
Hide file tree
Showing 15 changed files with 533 additions and 422 deletions.
2 changes: 1 addition & 1 deletion src/sage/categories/homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def __hash__(self):
sage: E = EllipticCurve('37a')
sage: H = E(0).parent(); H
Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
sage: hash(H)
sage: hash(H) # random output
-1145411691 # 32-bit
-8446824869798451307 # 64-bit
"""
Expand Down
177 changes: 121 additions & 56 deletions src/sage/databases/cremona.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,123 @@ def curves(self, N):
ret['h3'] = [[1,-1,1,-1568,-4669],int(1),int(6)]
return ret

def coefficients_and_data(self, label):
"""
Return the Weierstrass coefficients and other data for the
curve with given label.
EXAMPLES::
sage: c, d = CremonaDatabase().coefficients_and_data('144b1')
sage: c
[0, 0, 0, 6, 7]
sage: d['conductor']
144
sage: d['cremona_label']
'144b1'
sage: d['rank']
0
sage: d['torsion_order']
2
"""
# There are two possible strings: the Cremona label and the LMFDB label.
# They are distinguished by the presence of a period.
if label.find('.') == -1:
cremona_label = label
lmfdb_label = None
else:
cremona_label = lmfdb_to_cremona(label)
lmfdb_label = label

N, iso, num = parse_cremona_label(cremona_label)
label = str(N)+iso+str(num)
if self.get_skeleton() == _miniCremonaSkeleton:
q = self.__connection__.cursor().execute("SELECT eqn,rank,tors " \
+ 'FROM t_curve,t_class USING(class) WHERE curve=?', (label,))
else:
q = self.__connection__.cursor().execute("SELECT eqn,rank,tors," \
+ "deg,gens,cp,om,L,reg,sha FROM t_curve,t_class " \
+ "USING(class) WHERE curve=?",(label,))
try:
c = q.next()
except StopIteration:
if N < self.largest_conductor():
message = "There is no elliptic curve with label " + label \
+ " in the database"
elif is_package_installed('database_cremona_ellcurve'):
message = "There is no elliptic curve with label " + label \
+ " in the currently available databases"
else:
message = "There is no elliptic curve with label " \
+ label + " in the default database; try installing " \
+ "the optional package database_cremona_ellcurve which " \
+ "contains the complete Cremona database"
raise ValueError(message)
ainvs = eval(c[0])
data = {'cremona_label': label,
'rank': c[1],
'torsion_order': c[2],
'conductor': N}
if lmfdb_label:
data['lmfdb_label'] = lmfdb_label
if len(c) > 3:
if num == 1:
data['modular_degree'] = (c[3])
data['gens'] = eval(c[4])
data['db_extra'] = list(c[5:])
elif c[1] == 0:
# we know the rank is 0, so the gens are empty
data['gens'] = []
return ainvs, data

def data_from_coefficients(self, ainvs):
"""
Return elliptic curve data for the curve with given
Weierstrass coefficients.
EXAMPLES::
sage: d = CremonaDatabase().data_from_coefficients([1, -1, 1, 31, 128])
sage: d['conductor']
1953
sage: d['cremona_label']
'1953c1'
sage: d['rank']
1
sage: d['torsion_order']
2
"""
ainvs = str(list(ainvs))
if self.get_skeleton() == _miniCremonaSkeleton:
q = self.__connection__.cursor().execute("SELECT curve,rank,tors "
+ 'FROM t_curve,t_class USING(class) WHERE eqn=?',
(ainvs.replace(' ', ''),))
else:
q = self.__connection__.cursor().execute("SELECT curve,rank,tors,"
+ "deg,gens,cp,om,L,reg,sha FROM t_curve,t_class "
+ "USING(class) WHERE eqn=?",
(ainvs.replace(' ', ''),))
try:
c = q.next()
except StopIteration:
raise RuntimeError("There is no elliptic curve with coefficients "
+ ainvs + " in the database")
label = str(c[0])
N, iso, num = parse_cremona_label(label)
data = {'cremona_label': label,
'rank': c[1],
'torsion_order': c[2],
'conductor': N}
if len(c) > 3:
if num == 1:
data['modular_degree'] = (c[3])
data['gens'] = eval(c[4])
data['db_extra'] = list(c[5:])
elif c[1] == 0:
# we know the rank is 0, so the gens are empty
data['gens'] = []
return data

def elliptic_curve_from_ainvs(self, ainvs):
"""
Returns the elliptic curve in the database of with minimal
Expand Down Expand Up @@ -804,13 +921,8 @@ def elliptic_curve_from_ainvs(self, ainvs):
...
ValueError: There is no elliptic curve with label 10a1 in the database
"""
q = self.__connection__.cursor().execute("SELECT curve FROM t_curve " \
+ "WHERE eqn=?",(str(ainvs).replace(' ',''),))
try:
return self.elliptic_curve(q.next()[0])
except StopIteration:
raise RuntimeError("No elliptic curve with ainvs (=%s) "%ainvs \
+ "in the database.")
data = self.data_from_coefficients(ainvs)
return elliptic.EllipticCurve(ainvs, **data)

def elliptic_curve(self, label):
"""
Expand Down Expand Up @@ -846,55 +958,8 @@ def elliptic_curve(self, label):
sage: c.elliptic_curve('462.f3')
Elliptic Curve defined by y^2 + x*y = x^3 - 363*x + 1305 over Rational Field
"""
# There are two possible strings: the Cremona label and the LMFDB label.
# They are distinguished by the presence of a period.
if label.find('.') == -1:
cremona_label = label
lmfdb_label = None
else:
cremona_label = lmfdb_to_cremona(label)
lmfdb_label = label

N, iso, num = parse_cremona_label(cremona_label)
label = str(N)+iso+str(num)
if self.get_skeleton() == _miniCremonaSkeleton:
q = self.__connection__.cursor().execute("SELECT eqn,rank,tors " \
+ 'FROM t_curve,t_class USING(class) WHERE curve=?', (label,))
else:
q = self.__connection__.cursor().execute("SELECT eqn,rank,tors," \
+ "deg,gens,cp,om,L,reg,sha FROM t_curve,t_class " \
+ "USING(class) WHERE curve=?",(label,))
try:
c = q.next()
F = elliptic.EllipticCurve(eval(c[0]))
F._set_cremona_label(label)
F._set_rank(c[1])
F._set_torsion_order(c[2])
F._set_conductor(N)
if lmfdb_label:
F._lmfdb_label = lmfdb_label
if len(c) > 3:
if num == 1:
F._set_modular_degree(c[3])
F._set_gens(eval(c[4]))
F.db_extra = list(c[5:])
elif c[1] == 0:
# we know the rank is 0, so the gens are empty
F._set_gens([])
return F
except StopIteration:
if N < self.largest_conductor():
message = "There is no elliptic curve with label " + label \
+ " in the database"
elif is_package_installed('database_cremona_ellcurve'):
message = "There is no elliptic curve with label " + label \
+ " in the currently available databases"
else:
message = "There is no elliptic curve with label " \
+ label + " in the default database; try installing " \
+ "the optional package database_cremona_ellcurve which " \
+ "contains the complete Cremona database"
raise ValueError(message)
ainvs, data = self.coefficients_and_data(label)
return elliptic.EllipticCurve(ainvs, **data)

def iter(self, conductors):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,13 +1205,13 @@ def report_unexpected_exception(self, out, test, example, exc_info):
sage: _ = sage0.eval("DTR = sdf.SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)")
sage: sage0._prompt = r"\(Pdb\) "
sage: sage0.eval("DTR.run(DT, clear_globs=False)") # indirect doctest
'... ArithmeticError("Invariants %s define a singular curve."%ainvs)'
'... ArithmeticError("invariants " + str(ainvs) + " define a singular curve")'
sage: sage0.eval("l")
'...if self.discriminant() == 0:...raise ArithmeticError...'
sage: sage0.eval("u")
'...EllipticCurve_field.__init__(self, [field(x) for x in ainvs])'
'...EllipticCurve_field.__init__(self, K, ainvs)'
sage: sage0.eval("p ainvs")
'[0, 0]'
'(0, 0, 0, 0, 0)'
sage: sage0._prompt = "sage: "
sage: sage0.eval("quit")
'TestResults(failed=1, attempted=1)'
Expand Down
Loading

0 comments on commit 0262f93

Please sign in to comment.