## Mathematics Category Archive

Below you will find the most recent posts tagged “Mathematics”, arranged in reverse chronological order.

Below you will find the most recent posts tagged “Mathematics”, arranged in reverse chronological order.

Posted in Mathematics
Leave a comment

On 19 March I gave a talk at the 32nd Automorphic Forms Workshop, which ishosted by Tufts this year. The content of the talk concerned counting points on hyperboloids, and inparticular counting points on the three dimensional hyperboloid

$$\begin{equation}

X^2 + Y^2 = Z^2 + h

\end{equation}$$

for any fixed integer $h$. But thematically, I wanted to give another concrete example of using modularforms to compute some sort of arithmetic data, and to mention how the perhapsapparently unrelated topic of spectral theory appears even in such an arithmeticapplication.

Somehow, starting from counting points on $X^2 + Y^2 = Z^2 + h$ (which appearssimple enough on its own that I could probably put this in front of anelementary number theory class and they would feel comfortable experimentingaway on the topic), one gets to very scary-looking expressions like

$$\begin{equation}

\sum_{t_j}

\langle P_h^k, \mu_j \rangle

\langle \theta^2 \overline{\theta} y^{3/4}, \mu_j \rangle +

\sum_{\mathfrak{a}}\int_{(1/2)}

\langle P_h^k, E_h^k(\cdot, u) \rangle

\langle \theta^2 \overline{\theta} y^{3/4}, E_h^k(\cdot, u) \rangle du,

\end{equation}$$

which is full of lots of non-obvious symbols and is generically intimidating.

Part of the theme of this talk is to give a very direct idea of how one gets tothe very complicated spectral expansion from the original lattice-countingproblem. Stated differently, perhaps part of the theme is to describe a simple-lookingnail and a scary-looking hammer, and show that the hammer actually works quitewell in this case.

The slides for this talk are available here.

Posted in Expository, Math.NT, Mathematics
Leave a comment

[This note is more about modeling some of the mathematics behind political events than politics themselves. And there are pretty pictures.]

Gerrymandering has become a recurring topic in the news. The Supreme Court of the US, as well as more state courts and supreme courts, is hearing multiple cases on partisan gerrymandering (all beginning with a case in Wisconsin).

Intuitively, it is clear that gerrymandering is bad. It allows politicians to choose their voters, instead of the other way around. And it allows the majority party to quash minority voices.

But how can one identify a gerrymandered map? To quote Justice Kennedy in his Concurrence the 2004 Supreme Court case Vieth v. Jubelirer:

When presented with a claim of injury from partisan gerrymandering, courts confront two obstacles. First is the lack of comprehensive and neutral principles for drawing electoral boundaries. No substantive definition of fairness in districting seems to command general assent. Second is the absence of rules to limit and confine judicial intervention. With uncertain limits, intervening courts–even when proceeding with best intentions–would risk assuming political, not legal, responsibility for a process that often produces ill will and distrust.

Later, he adds to the first obstacle, saying:

The object of districting is to establish “fair and effective representation for all citizens.” Reynolds v. Sims, 377 U.S. 533, 565—568 (1964). At first it might seem that courts could determine, by the exercise of their own judgment, whether political classifications are related to this object or instead burden representational rights. The lack, however, of any agreed upon model of fair and effective representation makes this analysis difficult to pursue.

From Justice Kennedy’s Concurrence emerges a theme — a “workable standard” of identifying gerrymandering would open up the possibility of limiting partisan gerrymandering through the courts. Indeed, at the core of the Wisconsin gerrymandering case is a proposed “workable standard”, based around the **efficiency gap.**

In 1971, American economist Thomas Schelling (who later won the Nobel Prize in Economics in 2005) published *Dynamic Models of Segregation* (Journal of Mathematical Sociology, 1971, Vol 1, pp 143–186). He sought to understand why racial segregation in the United States seems so difficult to combat.

He introduced a simple model of segregation suggesting that even if each individual person doesn’t mind living with others of a different race, they might still *choose* to segregate themselves through mild preferences. As each individual makes these choices, overall segregation increases.

I write this post because I wondered what happens if we adapt Schelling’s model to instead model a state and its district voting map. In place of racial segregation, I consider political segregation. Supposing the district voting map does not change, I wondered how the efficiency gap will change over time as people further segregate themselves.

It seemed intuitive to me that political segregation (where people who had the same political beliefs stayed largely together and separated from those with different political beliefs) might correspond to more egregious cases of gerrymandering. But to my surprise, I was (mostly) wrong.

Let’s set up and see the model.

Posted in Expository, Mathematics, Politics, Programming, Python
Tagged gerrymandering, python, Thomas Schelling
Leave a comment

I’m in San Diego, and it’s charming here. (It’s certainly much nicer outside than the feet of snow in Boston. I’ve apparently brought some British rain with me, though).

Today I give a talk on counting lattice points on one-sheeted hyperboloids. These are the shapes described by

$$ X_1^2 + \cdots + X_{d-1}^2 = X_d^2 + h,$$

where $h > 0$ is a positive integer. The question is: how many lattice points $x$ are on such a hyperboloid with $| x |^2 \leq R$; or equivalently, how many lattice points are on such a hyperboloid and contained within a ball of radius $\sqrt R$ centered at the origin?

I describe my general approach of transforming this into a question about the behavior of modular forms, and then using spectral techniques from the theory of modular forms to understand this behavior. This becomes a question of understanding the shifted convolution Dirichlet series

$$ \sum_{n \geq 0} \frac{r_{d-1}(n+h)r_1(n)}{(2n + h)^s}.$$

Ultimately this comes from the modular form $\theta^{d-1}(z) \overline{\theta(z)}$, where

$$ \theta(z) = \sum_{m \in \mathbb{Z}} e^{2 \pi i m^2 z}.$$

Here are the slides for this talk. Note that this talk is based on chapter 5 of my thesis, and (hopefully) soon a preprint of this chapter ready for submission will appear on the arXiv.

Posted in Math.NT, Mathematics
Leave a comment

This is a very short post in my collection working through this year’s Advent of Code challenges. Unlike the previous ones, this has no mathematical comments, as it was a very short exercise. This notebook is available in its original format on my github.

Given a list of strings, determine how many strings have no duplicate words.

This is a classic problem, and it’s particularly easy to solve this in python. Some might use `collections.Counter`

, but I think it’s more straightforward to use sets.

The key idea is that the set of words in a sentence will not include duplicates. So if taking the set of a sentence reduces its length, then there was a duplicate word.

In [1]:

```
with open("input.txt", "r") as f:
lines = f.readlines()
def count_lines_with_unique_words(lines):
num_pass = 0
for line in lines:
s = line.split()
if len(s) == len(set(s)):
num_pass += 1
return num_pass
count_lines_with_unique_words(lines)
```

Out[1]:

I think this is the first day where I would have had a shot at the leaderboard if I’d been gunning for it.

Let’s add in another constraint. Determine how many strings have no duplicate words, even after anagramming. Thus the string

```
abc bac
```

is not valid, since the second word is an anagram of the first. There are many ways to tackle this as well, but I will handle anagrams by sorting the letters in each word first, and then running the bit from part 1 to identify repeated words.

In [2]:

```
with open("input.txt", "r") as f:
lines = f.readlines()
sorted_lines = []
for line in lines:
sorted_line = ' '.join([''.join(l) for l in map(sorted, line.split())])
sorted_lines.append(sorted_line)
sorted_lines[:2]
```

Out[2]:

In [3]:

```
count_lines_with_unique_words(sorted_lines)
```

Out[3]:

This is the third notebook in my posts on the Advent of Code challenges. The notebook in its original format can be found on my github.

Numbers are arranged in a spiral

```
17 16 15 14 13
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
21 22 23---> ...
```

Given an integer n, what is its Manhattan Distance from the center (1) of the spiral? For instance, the distance of 3 is $2 = 1 + 1$, since it’s one space to the right and one space up from the center.

Here’s my idea. The bottom right corner of the $k$th layer is the integer $(2k+1)^2$, since that’s how many integers are contained within that square. The other three corners in that layer are $(2k+1)^2 – 2k, (2k+1)^2 – 4k$, and $(2k+1)^2 – 6k$. Finally, the closest spot on the $k$th layer to the origin is at distance $k$: these are the four “axis locations” halfway between the corners, at $(2k+1)^2 – k, (2k+1)^2 – 3k, (2k+1)^2 – 5k$, and $(2k+1)^2 – 7k$.

For instance when $k = 1$, the bottom right is $(2 + 1)^2 = 9$, and the four “axis locations” are $9 – 1, 9 – 3, 9-5$, and $9-7$. The “axis locations” are $k$ away, and the corners are $2k$ away.

So I will first find which layer the number is on. Then I’ll figure out which side it’s on, and then how far away it is from the nearest “axis location” or “corner”.

My given number happens to be 289326.

In [1]:

```
import math
def find_lowest_larger_odd_square(n):
upper = math.ceil(n**.5)
if upper %2 == 0:
upper += 1
return upper
```

In [2]:

```
assert find_lowest_larger_odd_square(39) == 7
assert find_lowest_larger_odd_square(26) == 7
assert find_lowest_larger_odd_square(25) == 5
```

In [3]:

```
find_lowest_larger_odd_square(289326)
```

Out[3]:

In [4]:

```
539**2 - 289326
```

Out[4]:

It happens to be that our integer is very close to an odd square.

The square is $539^2$, and the distance to that square is $538$ from the center.

Note that $539 = 2(269) + 1$, so this is the $269$th layer of the square.

The previous corner to $539^2$ is $539^2 – 538$, and the previous corner to that is $539^2 – 2\cdot538 = 539^2 – 1076$.

This is the nearest corner.

How far away from the square is this corner?

Posted in Expository, Programming, Python
Tagged advent of code, number spiral, python
Leave a comment

This is the second notebook in my posts on the Advent of Code challenges. This notebook in its original format can be found on my github.

You are given a table of integers. Find the difference between the maximum and minimum of each row, and add these differences together.

There is not a lot to say about this challenge. The plan is to read the file linewise, compute the difference on each line, and sum them up.

In [1]:

```
with open("input.txt", "r") as f:
lines = f.readlines()
lines[0]
```

Out[1]:

In [2]:

```
l = lines[0]
l = l.split()
l
```

Out[2]:

In [3]:

```
def max_minus_min(line):
'''Compute the difference between the largest and smallest integer in a line'''
line = list(map(int, line.split()))
return max(line) - min(line)
def sum_differences(lines):
'''Sum the value of `max_minus_min` for each line in `lines`'''
return sum(max_minus_min(line) for line in lines)
```

In [4]:

```
testcase = ['5 1 9 5','7 5 3', '2 4 6 8']
assert sum_differences(testcase) == 18
```

In [5]:

```
sum_differences(lines)
```

Out[5]:

In line with the first day’s challenge, I’m inclined to ask what we should “expect.” But what we should expect is not well-defined in this case. Let us rephrase the problem in a randomized sense.

Suppose we are given a table, $n$ lines long, where each line consists of $m$ elements, that are each uniformly randomly chosen integers from $1$ to $10$. We might ask what is the expected value of this operation, of summing the differences between the maxima and minima of each row, on this table. What should we expect?

As each line is independent of the others, we are really asking what is the expected value across a single row. So given $m$ integers uniformly randomly chosen from $1$ to $10$, what is the expected value of the maximum, and what is the expected value of the minimum?

Let’s begin with the minimum. The minimum is $1$ unless all the integers are greater than $2$. This has probability

$$ 1 – \left( \frac{9}{10} \right)^m = \frac{10^m – 9^m}{10^m}$$

of occurring. We rewrite it as the version on the right for reasons that will soon be clear.

The minimum is $2$ if all the integers are at least $2$ (which can occur in $9$ different ways for each integer), but not all the integers are at least $3$ (each integer has $8$ different ways of being at least $3$). Thus this has probability

$$ \frac{9^m – 8^m}{10^m}.$$

Continuing to do one more for posterity, the minimum is $3$ if all the integers are at least $3$ (each integer has $8$ different ways of being at least $3$), but not all integers are at least $4$ (each integer has $7$ different ways of being at least $4$). Thus this has probability

$$ \frac{8^m – 7^m}{10^m}.$$

And so on.

Recall that the expected value of a random variable is

$$ E[X] = \sum x_i P(X = x_i),$$

so the expected value of the minimum is

$$ \frac{1}{10^m} \big( 1(10^m – 9^m) + 2(9^m – 8^m) + 3(8^m – 7^m) + \cdots + 9(2^m – 1^m) + 10(1^m – 0^m)\big).$$

This simplifies nicely to

$$ \sum_ {k = 1}^{10} \frac{k^m}{10^m}. $$

The same style of thinking shows that the expected value of the maximum is

$$ \frac{1}{10^m} \big( 10(10^m – 9^m) + 9(9^m – 8^m) + 8(8^m – 7^m) + \cdots + 2(2^m – 1^m) + 1(1^m – 0^m)\big).$$

This simplifies to

$$ \frac{1}{10^m} \big( 10 \cdot 10^m – 9^m – 8^m – \cdots – 2^m – 1^m \big) = 10 – \sum_ {k = 1}^{9} \frac{k^m}{10^m}.$$

Subtracting, we find that the expected difference is

$$ 9 – 2\sum_ {k=1}^{9} \frac{k^m}{10^m}. $$

From this we can compute this for each list-length $m$. It is good to note that as $m \to \infty$, the expected value is $9$. Does this make sense? Yes, as when there are lots of values we should expect one to be a $10$ and one to be a $1$. It’s also pretty straightforward to see how to extend this to values of integers from $1$ to $N$.

Looking at the data, it does not appear that the integers were randomly chosen. Instead, there are very many relatively small integers and some relatively large integers. So we shouldn’t expect this toy analysis to accurately model this problem — the distribution is definitely not uniform random.

But we can try it out anyway.

Posted in Expository, Programming, Python
Tagged advent of code, Programming, python
Leave a comment

I thoroughly enjoyed reading through Peter Norvig’s extraordinarily clean and nice solutions to the Advent of Code challenge last year. Inspired by his clean, literate programming style and the convenience of jupyter notebook demonstrations, I will look at several of these challenges in my own jupyter notebooks.

My background and intentions aren’t the same as Peter Norvig’s: his expertise dwarfs mine. And timezones are not kind to those of us in the UK, and thus I won’t be competing for a position on the leaderboards. These are to be fun. And sometimes there are tidbits of math that want to come out of the challenges.

Enough of that. Let’s dive into the first day.

In [1]:

```
with open('input.txt', 'r') as f:
seq = f.read()
seq = seq.strip()
seq[:10]
```

Out[1]:

In [2]:

```
def sum_matched_digits(s):
"Sum of digits which match following digit, and first digit if it matches last digit"
total = 0
for a,b in zip(s, s[1:]+s[0]):
if a == b:
total += int(a)
return total
```

They provide a few test cases which we use to test our method against.

In [3]:

```
assert sum_matched_digits('1122') == 3
assert sum_matched_digits('1111') == 4
assert sum_matched_digits('1234') == 0
assert sum_matched_digits('91212129') == 9
```

For fun, this is a oneline version.

I gave an introduction to sage tutorial at the University of Warwick Computational Group seminar today, 2 November 2017. Below is a conversion of the sage/jupyter notebook I based the rest of the tutorial on. I said many things which are not included in the notebook, and during the seminar we added a few additional examples and took extra consideration to a few different calls. But for reference, the notebook is here.

The notebook itself (as a jupyter notebook) can be found and viewed on my github (link to jupyter notebook). When written, this notebook used a Sage 8.0.0.rc1 backend kernel and ran fine on the standard Sage 8.0 release , though I expect it to work fine with any recent official version of sage. The last cell requires an active notebook to be seen (or some way to export jupyter widgets to standalone javascript or something; this either doesn’t yet exist, or I am not aware of it).

I will also note that I converted the notebook for display on this website using jupyter’s nbconvert package. I have some CSS and syntax coloring set up that affects the display.

Good luck learning sage, and happy hacking.

Sage (also known as SageMath) is a general purpose computer algebra system written on top of the python language. In Mathematica, Magma, and Maple, one writes code in the mathematica-language, the magma-language, or the maple-language. Sage is python.

But no python background is necessary for the rest of today’s guided tutorial. The purpose of today’s tutorial is to give an indication about how one really *uses* sage, and what might be available to you if you want to try it out.

I will spoil the surprise by telling you upfront the two main points I hope you’ll take away from this tutorial.

- With tab-completion and documentation, you can do many things in sage without ever having done them before.
- The ecosystem of libraries and functionality available in sage is tremendous, and (usually) pretty easy to use.

Let’s first get a small feel for sage by seeing some standard operations and what typical use looks like through a series of trivial, mostly unconnected examples.

In [1]:

```
# Fundamental manipulations work as you hope
2+3
```

Out[1]:

You can also subtract, multiply, divide, exponentiate…

```
>>> 3-2
1
>>> 2*3
6
>>> 2^3
8
>>> 2**3 # (also exponentiation)
8
```

There is an order of operations, but these things work pretty much as you want them to work. You might try out several different operations.

Sage includes a lot of functionality, too. For instance,

In [2]:

```
factor(-1008)
```

Out[2]:

In [3]:

```
list(factor(1008))
```

Out[3]:

Sage knows many functions and constants, and these are accessible.

Posted in Expository, Mathematics, sage, sagemath
Tagged ipython, jupyter, notebook, sage, sagemath, tutorial
Leave a comment

The primary purpose of this note is to collect a few hitherto unnoticed or unpublished results concerning gaps between powers of consecutive primes. The study of gaps between primes has attracted many mathematicians and led to many deep realizations in number theory. The literature is full of conjectures, both open and closed, concerning the nature of primes.

In a series of stunning developments, Zhang, Maynard, and Tao^{1}^{2} made the first major progress towards proving the prime $k$-tuple conjecture, and successfully proved the existence of infinitely many pairs of primes differing by a fixed number. As of now, the best known result is due to the massive collaborative Polymath8 project,^{3} which showed that there are infinitely many pairs of primes of the form $p, p+246$. In the excellent expository article, ^{4} Granville describes the history and ideas leading to this breakthrough, and also discusses some of the potential impact of the results. This note should be thought of as a few more results following from the ideas of Zhang, Maynard, Tao, and the Polymath8 project.

Throughout, $p_n$ will refer to the $n$th prime number. In a paper, ^{5} Andrica conjectured that

\begin{equation}\label{eq:Andrica_conj}

\sqrt{p_{n+1}} – \sqrt{p_n} < 1

\end{equation}

holds for all $n$. This conjecture, and related statements, is described in Guy’s Unsolved Problems in Number Theory.

^{6} It is quickly checked that this holds for primes up to $4.26 \cdot 10^{8}$ in sagemath

```
# Sage version 8.0.rc1
# started with `sage -ipython`
# sage has pari/GP, which can generate primes super quickly
from sage.all import primes_first_n
# import izip since we'll be zipping a huge list, and sage uses python2 which has
# non-iterable zip by default
from itertools import izip
# The magic number 23150000 appears because pari/GP can't compute
# primes above 436273290 due to fixed precision arithmetic
ps = primes_first_n(23150000) # This is every prime up to 436006979
# Verify Andrica's Conjecture for all prime pairs = up to 436006979
gap = 0
for a,b in izip(ps[:-1], ps[1:]):
if b**.5 - a**.5 > gap:
A, B, gap = a, b, b**.5 - a**.5
print(gap)
print("")
print(A)
print(B)
```

In approximately 20 seconds on my machine (so it would not be harder to go much higher, except that I would have to go beyond pari/GP to generate primes), this completes and prints out the following output.

```
0.317837245196
0.504017169931
0.670873479291
7
11
```

Thus the largest value of $\sqrt{p_{n+1}} – \sqrt{p_n}$ was merely $0.670\ldots$, and occurred on the gap between $7$ and $11$.

So it appears very likely that the conjecture is true. However it is also likely that new, novel ideas are necessary before the conjecture is decided.

Andrica’s Conjecture can also be stated in terms of prime gaps. Let $g_n = p_{n+1} – p_n$ be the gap between the $n$th prime and the $(n+1)$st prime. Then Andrica’s Conjecture is equivalent to the claim that $g_n < 2 \sqrt{p_n} + 1$. In this direction, the best known result is due to Baker, Harman, and Pintz, ^{7} who show that $g_n \ll p_n^{0.525}$.

In 1985, Sandor ^{8} proved that \begin{equation}\label{eq:Sandor} \liminf_{n \to \infty} \sqrt[4]{p_n} (\sqrt{p_{n+1}} – \sqrt{p_n}) = 0. \end{equation} The close relation to Andrica’s Conjecture \eqref{eq:Andrica_conj} is clear. The first result of this note is to strengthen this result.

TheoremLet $\alpha, \beta \geq 0$, and $\alpha + \beta < 1$. Then

\begin{equation}\label{eq:main}

\liminf_{n \to \infty} p_n^\beta (p_{n+1}^\alpha – p_n^\alpha) = 0.

\end{equation}

We prove this theorem below. Choosing $\alpha = \frac{1}{2}, \beta = \frac{1}{4}$ verifies Sandor’s result \eqref{eq:Sandor}. But choosing $\alpha = \frac{1}{2}, \beta = \frac{1}{2} – \epsilon$ for a small $\epsilon > 0$ gives stronger results.

This theorem leads naturally to the following conjecture.

ConjectureFor any $0 \leq \alpha < 1$, there exists a constant $C(\alpha)$ such that

\begin{equation}

p_{n+1}^\alpha – p_{n}^\alpha \leq C(\alpha)

\end{equation}

for all $n$.

A simple heuristic argument, given in the last section below, shows that this Conjecture follows from Cramer’s Conjecture.

It is interesting to note that there are generalizations of Andrica’s Conjecture. One can ask what the smallest $\gamma$ is such that

\begin{equation}

p_{n+1}^{\gamma} – p_n^{\gamma} = 1

\end{equation}

has a solution. This is known as the Smarandache Conjecture, and it is believed that the smallest such $\gamma$ is approximately

\begin{equation}

\gamma \approx 0.5671481302539\ldots

\end{equation}

The digits of this constant, sometimes called “the Smarandache constant,” are the contents of sequence A038458 on the OEIS. It is possible to generalize this question as well.

Open QuestionFor any fixed constant $C$, what is the smallest $\alpha = \alpha(C)$ such that

\begin{equation}

p_{n+1}^\alpha – p_n^\alpha = C

\end{equation}

has solutions? In particular, how does $\alpha(C)$ behave as a function of $C$?

This question does not seem to have been approached in any sort of generality, aside from the case when $C = 1$.

The idea of the proof is very straightforward. We estimate \eqref{eq:main} across prime pairs $p, p+246$, relying on the recent proof from Polymath8 that infinitely many such primes exist.

Fix $\alpha, \beta \geq 0$ with $\alpha + \beta < 1$. Applying the mean value theorem of calculus on the function $x \mapsto x^\alpha$ shows that

\begin{align}

p^\beta \big( (p+246)^\alpha – p^\alpha \big) &= p^\beta \cdot 246 \alpha q^{\alpha – 1} \\\

&\leq p^\beta \cdot 246 \alpha p^{\alpha – 1} = 246 \alpha p^{\alpha + \beta – 1}, \label{eq:bound}

\end{align}

for some $q \in [p, p+246]$. Passing to the inequality in the second line is done by realizing that $q^{\alpha – 1}$ is a decreasing function in $q$. As $\alpha + \beta – 1 < 0$, as $p \to \infty$ we see that\eqref{eq:bound} goes to zero.

Therefore

\begin{equation}

\liminf_{n \to \infty} p_n^\beta (p_{n+1}^\alpha – p_n^\alpha) = 0,

\end{equation}

as was to be proved.

Cramer’s Conjecture states that there exists a constant $C$ such that for all sufficiently large $n$,

\begin{equation}

p_{n+1} – p_n < C(\log n)^2.

\end{equation}

Thus for a sufficiently large prime $p$, the subsequent prime is at most $p + C (\log p)^2$. Performing a similar estimation as above shows that

\begin{equation}

(p + C (\log p)^2)^\alpha – p^\alpha \leq C (\log p)^2 \alpha p^{\alpha – 1} =

C \alpha \frac{(\log p)^2}{p^{1 – \alpha}}.

\end{equation}

As the right hand side vanishes as $p \to \infty$, we see that it is natural to expect that the main Conjecture above is true. More generally, we should expect the following, stronger conjecture.

Conjecture’For any $\alpha, \beta \geq 0$ with $\alpha + \beta < 1$, there exists a constant $C(\alpha, \beta)$ such that

\begin{equation}

p_n^\beta (p_{n+1}^\alpha – p_n^\alpha) \leq C(\alpha, \beta).

\end{equation}

I wrote this note in between waiting in never-ending queues while I sort out my internet service and other mundane activities necessary upon moving to another country. I had just read some papers on the arXiv, and I noticed a paper which referred to unknown statuses concerning Andrica’s Conjecture. So then I sat down and wrote this up.

I am somewhat interested in qualitative information concerning the Open Question in the introduction, and I may return to this subject unless someone beats me to it.

This note is (mostly, minus the code) available as a pdf and (will shortly) appears on the arXiv. This was originally written in LaTeX and converted for display on this site using a set of tools I’ve written based around latex2jax, which is available on my github.

Posted in Math.NT, Mathematics, sage
Tagged Andrica's Conjecture, mathematics, primes, Zhang-Maynard-Tao
1 Comment

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/sage2lmfdb

Let’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.

th

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

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

## Now let’s describe what’s going on under the hood a little bit¶

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

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/issues**

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 like

```
http://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]:

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

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 argument `base_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

Generically, documentation and introspection on objects from this class should work. Much of sage’s documentation carries through directly.

`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__)
```

Thank you, and if you have any questions, comments, or concerns, please find me/email me/raise an issue on LMFDB’s github.

Posted in Expository, LMFDB, Math.NT, Mathematics, Programming, Python, sagemath
Tagged interface, ipython, jupyter notebook, lmfdb, sage, sage days 87, sagemath, sd87
Leave a comment