Interfacing sage and the LMFDB — a prototype¶
The lmfdb and sagemath are both great things, but they don't currently talk to each other. Much of the lmfdb calls sage, but the lmfdb also includes vast amounts of data on $L$-functions and modular forms (hence the name) that is not accessible from within sage. This is an example prototype of an interface to the lmfdb from sage. Keep in mind that this is a prototype and every aspect can change. But we hope to show what may be possible in the future. If you have requests, comments, or questions, please request/comment/ask either now, or at my email:david@lowryduda.com
.
Note that this notebook is available on http://davidlowryduda.com or https://gist.github.com/davidlowryduda/deb1f88cc60b6e1243df8dd8f4601cde, and the code is available at https://github.com/davidlowryduda/sage2lmfdbLet's dive into an example.
In [1]:
# These names will change
from sage.all import *
import LMFDB2sage.elliptic_curves as lmfdb_ecurve
In [2]:
lmfdb_ecurve.search(rank=1)
Out[2]:
This returns 10 elliptic curves of rank 1. But these are a bit different than sage's elliptic curves.
In [3]:
Es = lmfdb_ecurve.search(rank=1)
E = Es[0]
print(type(E))
Note that the class of an elliptic curve is an lmfdb ElliptcCurve. But don't worry, this is a subclass of a normal elliptic curve. So we can call the normal things one might call on an elliptic curve.
In [4]:
# Try autocompleting the following. It has all the things!
print(dir(E))
This gives quick access to some data that is not stored within the LMFDB, but which is relatively quickly computable. For example,
In [5]:
E.defining_ideal()
Out[5]:
But one of the great powers is that there are some things which are computed and stored in the LMFDB, and not in sage. We can now immediately give many examples of rank 3 elliptic curves with:
In [6]:
Es = lmfdb_ecurve.search(conductor=11050, torsion_order=2)
print("There are {} curves returned.".format(len(Es)))
E = Es[0]
print(E)
And for these curves, the lmfdb contains data on its rank, generators, regulator, and so on.
In [7]:
print(E.gens())
print(E.rank())
print(E.regulator())
In [8]:
res = []
%time for E in Es: res.append(E.gens()); res.append(E.rank()); res.append(E.regulator())
That's pretty fast, and this is because all of this was pulled from the LMFDB when the curves were returned by the
search()
function.
In this case, elliptic curves over the rationals are only an okay example, as they're really well studied and sage can compute much of the data very quickly. On the other hand, through the LMFDB there are millions of examples and corresponding data at one's fingertips.
This is where we're really looking for input.¶
Think of what you might want to have easy access to through an interface from sage to the LMFDB, and tell us. We're actively seeking comments, suggestions, and requests. Elliptic curves over the rationals are a prototype, and the LMFDB has lots of (much more challenging to compute) data. There is data on the LMFDB that is simply not accessible from within sage. email: david@lowryduda.com, or post an issue on https://github.com/LMFDB/lmfdb/issuesNow let's describe what's going on under the hood a little bit¶
There is an API for the LMFDB at http://beta.lmfdb.org/api/. This API is a bit green, and we will change certain aspects of it to behave better in the future. A call to the API looks likehttp://beta.lmfdb.org/api/elliptic_curves/curves/?rank=i1&conductor=i11050
The result is a large mess of data, which can be exported as json and parsed.
But that's hard, and the resulting data are not sage objects. They are just strings or ints, and these require time and thought to parse.
So we created a module in sage that writes the API call and parses the output back into sage objects. The 22 curves given by the above API call are the same 22 curves returned by this call:
In [9]:
Es = lmfdb_ecurve.search(rank=1, conductor=11050, max_items=25)
print(len(Es))
E = Es[0]
The total functionality of this search function is visible from its current documentation.
In [10]:
# Execute this cell for the documentation
print(lmfdb_ecurve.search.__doc__)
In [11]:
# So, for instance, one could perform the following search, finding a unique elliptic curve
lmfdb_ecurve.search(rank=2, torsion_order=3, degree=4608)
Out[11]:
What if there are no curves?¶
If there are no curves satisfying the search criteria, then a message is displayed and that's that. These searches may take a couple of seconds to complete. For example, no elliptic curve in the database has rank 5.In [12]:
lmfdb_ecurve.search(rank=5)
How does one step through the data?¶
Right now, at most 100 curves are returned in a single API call. This is the limit even from directly querying the API. But one can pass in the argumentbase_item
(the name will probably change... to skip
? or perhaps to offset
?) to start returning at the base_item
th element.
In [13]:
from pprint import pprint
pprint(lmfdb_ecurve.search(rank=1, max_items=3)) # The last item in this list
print('')
pprint(lmfdb_ecurve.search(rank=1, max_items=3, base_item=2)) # should be the first item in this list
Included in the documentation is also a bit of hopefulness. Right now, the LMFDB API does not actually accept
max_conductor
or min_conductor
(or arguments of that type). But it will sometime. (This introduces a few extra difficulties on the server side, and so it will take some extra time to decide how to do this).
In [14]:
lmfdb_ecurve.search(rank=1, min_conductor=500, max_conductor=10000) # Not implemented
Our
EllipticCurve_rational_field_lmfdb
class constructs a sage elliptic curve from the json and overrides (somem of the) the default methods in sage if there is quicker data available on the LMFDB. In principle, this new object is just a sage object with some slightly different methods.
Generically, documentation and introspection on objects from this class should work. Much of sage's documentation carries through directly.
In [15]:
print(E.gens.__doc__)
Modified methods should have a note indicating that the data comes from the LMFDB, and then give sage's documentation. This is not yet implemented. (So if you examine the current version, you can see some incomplete docstrings like
regulator()
.)
In [16]:
print(E.regulator.__doc__)
Info on how to comment
To make a comment, please send an email using the button below. Your email address won't be shared (unless you include it in the body of your comment). If you don't want your real name to be used next to your comment, please specify the name you would like to use. If you want your name to link to a particular url, include that as well.
bold, italics, and plain text are allowed in comments. A reasonable subset of markdown is supported, including lists, links, and fenced code blocks. In addition, math can be formatted using
$(inline math)$
or$$(your display equation)$$
.Please use plaintext email when commenting. See Plaintext Email and Comments on this site for more. Note also that comments are expected to be open, considerate, and respectful.