WOLSTENHOLME AND VANDIVER PRIMES

SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

2p 4 Abstract. A prime p is a Wolstenholme prime if p ≡ 2 mod p , or, equiv- alently, if p divides the numerator of the Bp−3; a Vandiver prime p is one that divides the Euler number Ep−3. Only two Wolstenholme primes and eight Vandiver primes are known. We increase the search range in the first case by a factor of 6, and show that no additional Wolstenholme primes exist up to 60 billion, and in the second case by a factor of 8, proving that no additional Vandiver primes occur up to 40 billion. To facilitate this, we develop a number of new congruences for Bernoulli and mod p that are favorable for computation, and we implement some highly parallel searches using GPUs.

1. Introduction In 1862, Wolstenholme [34] established that the following three congruences hold for every prime p ≥ 5: X X 2p − 1 k−2 ≡ 0 mod p, k−1 ≡ 0 mod p2, ≡ 1 mod p3. p − 1 0

Date: January 28, 2021. 2000 Mathematics Subject Classification. Primary: 11B68, 11Y40; Secondary: 11A41, 11B65. Key words and phrases. Wolstenholme primes, Vandiver primes, Bernoulli numbers, Euler numbers, irregular primes, E-irregular primes. Supported by Australian Research Council Future Fellowship FT160100094. 1 2 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

Recall the Bernoulli numbers Bk may be defined by their exponential generating function, z X zk = B . ez − 1 k k! k≥0

These are rational numbers, and B2k+1 = 0 for k ≥ 1. An important connection between certain binomial coefficients and Bernoulli numbers was established by Glaisher in 1900 (combining [10, §39] and [11, §8]), who proved that hp − 1 h(h − 1) ≡ 1 − p3B mod p4 (1.2) p − 1 3 p−3 for any prime p ≥ 5 and any positive integer h. Thus, p is a Wolstenholme prime if and only if p divides the numerator of the Bernoulli number Bp−3. This condition provides the first observation toward a more computationally attractive test for Wolstenholme primes, since it requires computation of a residue mod p, rather than a higher power of p. Glaisher’s observation implies that a Wolstenholme prime is a particular type of irregular prime. Recall that a prime p is said to be regular if p does not divide 2πi/p the class number of the cyclotomic field Q(ζp), where ζp = e . Equivalently, p is regular if p does not divide the numerator of any of the Bernoulli numbers B2k with 0 < 2k ≤ p − 3. Regular primes were first defined in the context of work on Fermat’s Last Theorem, as Kummer proved in 1847 that no nontrivial solutions with exponent p exist in this famous problem if p is a . The smallest irregular prime is 37, and while it is known that there exist infinitely many irregular primes (see for instance [4,17]), it remains unknown if the number of regular primes is infinite. We refer the reader to [6,33] for more information on regular primes and their connections to various topics in number theory. The Euler numbers Ek may also be defined by their exponential generating function,1 X zk sec z = E . k k! k≥0 Like the Bernoulli numbers, the Euler numbers with odd index are 0 (including E1 this time), but unlike the Bk, the Euler numbers are all integers. A prime p is said to be E-regular if p does not divide any of the Euler numbers E2k with 0 < 2k ≤ p − 3. The smallest E-irregular prime is 19, as 19 | E10, and while it is known that there exist infinitely many E-irregular primes [4, 17], it is also not known if the number of E-regular primes is infinite. E-irregular primes first arose in the study of Fermat’s Last Theorem as well, and they are pertinent in other problems in number theory too, including the topic of class numbers of cyclotomic fields. For example, Gut [13] proved that p does not divide the class number of the cyclotomic field Q(ζ4p) if and only if B2k 6≡ 0 and E2k 6≡ 0 mod p for 0 < 2k ≤ p−3. The extremal case Ep−3 ≡ 0 mod p has witnessed particular interest. In 1940, Vandiver [31] showed that any solution with exponent p in the first case of Fermat’s Last Theorem (so a nontrivial solution in positive integers to xp + yp = zp where

z 1Some authors instead use the series for the hyperbolic secant, sech z = 2e , to define the e2z +1 Euler numbers; this alters the sign of the terms with index congruent to 2 mod 4. Results cited from the literature that employ that formulation are suitably translated here to comport with the definition we employ. WOLSTENHOLME AND VANDIVER PRIMES 3 p - xyz) necessarily has p | Ep−3. More recently, Z.-H. Sun [25] and Z.-W. Sun [26] established a number of congruences regarding Bernoulli and Euler numbers, in many of which the residues of Bp−3 and Ep−3 mod p play an important role, and several of these congruences become stronger in the case of a Wolstenholme or Vandiver prime. If p is irregular, and B2r ≡ 0 mod p for an even integer 2r ≤ p − 3, then (p, 2r) is known as an irregular pair. A Wolstenholme prime is thus the extremal case where (p, p − 3) forms an irregular pair. Only two Wolstenholme primes are known, and both were discovered during broader searches for irregular primes. The smallest Wolstenholme prime is p1 = 16843. This seems to have been first discovered by Selfridge and Pollack, who spoke on their work searching for irregular primes up to 25000 at a meeting of the American Mathematical Society in 1964 [23]. While details from their search are not readily available, in 1975 Johnson [15] reported on an extension of the work of Selfridge and Pollack, verifying their work, and noted in particular that p1 was the only prime less than 30000 where (p, p − 3) forms an irregular pair. The second Wolstenholme prime is p2 = 2124679, and was discovered in 1993 by Buhler et al. [3] during a search for irregular primes p < 4 · 106. In 1995 McIntosh [18] reported finding no additional examples with p < 2 · 108, after more extensive searches that targeted Wolstenholme primes in particular, and then (with Roettger) extended this search in 2007 [20] to p < 109. More recently, McIntosh continued this search to cover p < 1010 [19] and found no additional examples. Broader searches for irregular primes have continued as well, culminating most recently in the work of Hart, Harvey, and Ong [14] of 2017, who determined all irregular primes p < 231, along with their index of irregularity, that is, the number of irregular pairs attached to each such prime. They found for instance that the maximum index of irregularity over this range is 9, attained by the single prime p = 1767218027. We likewise say (p, 2r) is an E-irregular pair if E2r ≡ 0 mod p, so that a Vandiver prime has the property that (p, p − 3) forms an E-irregular pair. It appears that the last census of E-irregular primes and indices of E-irregularity was performed in 1978 by Ernvall and Mets¨ankyl¨a[7, 8], who checked primes p < 104, motivated by questions regarding Iwasawa invariants of the cyclotomic field Q(ζ4p). They found for example that the maximum index of E-irregularity over this range was 5, attained by p = 5783 alone. A number of Vandiver primes were known prior to this work. The first two, p = 149 and 241, were first noted by Ernvall and Mets¨ankyl¨a[8] (and later rediscovered by Z.-W. Sun [26]). Three more Vandiver primes, p = 2124679, 16467631, and 17613227, were found by Cosgrave and Dilcher in 2013 [5] (who called these integers E-primes), using a congruence from [16] to search up to 5 · 107. They showed that these primes arise in a natural way in a problem regarding modular sums of certain reciprocals, proving that X k−2 ≡ 0 mod n 0

2. Congruences for Bernoulli numbers The Bernoulli numbers are known to satisfy a number of congruences involv- ing sums of powers of consecutive integers, beginning with Voronoi’s well-known

2We remark that some structure does appear in a similar problem. The Ankeny–Artin–Chowla conjecture asserts that p - B(p−1)/2 for every prime p ≡ 1 mod 4. While this problem is open in general (and has been verified computationally for p < 2 · 1011 [29]), this conjecture is known to hold for primes of the form p = n2 + 1 or n2 + 4 [2]. WOLSTENHOLME AND VANDIVER PRIMES 5 congruence of 1889 (see [28, Chap. IX]). Some of these congruences have been par- ticularly instrumental in calculations involving Bernoulli numbers. We review some of the more important relations. For real numbers x < y in [0, 1], an integer `, and a prime p, let X ` S`(x, y) = S`,p(x, y) = s mod p, (2.1) xp

1 1 Ck(3, 4, 6)B2k ≡ S2k−1( 6 , 4 ) mod p (2.2) whenever p ≥ 5 and p − 1 - 2k. Note that this allows computing the residue of B2k mod p using a sum with approximately p/12 terms. Also, in 1937, Vandiver [30, eq. (18)] proved that

1 1 1 2 Ck(2, 5, 6)B2k ≡ S2k−1( 6 , 5 ) + S2k−1( 3 , 5 ) mod p (2.3) when p ≥ 7 and p−1 - 2k. For convenience, we define the cost of a congruence such as (2.2) or (2.3), where in general the right side consists of a linear combination of sums S`(x1, y1), . . . , S`(xm, ym), as m X p (yi − xi), i=1 as this is the approximate number of terms in the sums comprising the right side of 1 1 2 1 the congruence. The cost of Vandiver’s congruence (2.3) is thus p( 5 − 6 + 5 − 3 ) = p/10, and the cost of (2.2) is p/12. However, it transpires that (2.3) is more important for our application. In 1987, Tanner and Wagstaff [27] developed a number of new congruences for Bernoulli numbers. They proved for example that

bb/2c X  m m C (2, b, b + 1)B ≡ S , mod p (2.4) k 2k 2k−1 b + 1 b m=1 whenever p is prime, b ≥ 2, p > b + 1, k ≥ 1, and p − 1 - 2k. This rule has cost bb/2c(bb/2c+1) 2b(b+1) p, so asymptotically p/8, and we note that the case b = 5 recovers (2.3). Tanner and Wagstaff also noted three simple transformations that preserve the value of S`(x, y) mod p, which we summarize here, in a slightly generalized form. Proposition 2.1 (Tanner and Wagstaff [27]). The following three properties hold for S`(x, y), defined in (2.1). (a) Separation: If 0 ≤ x < y < z ≤ 1 and yp is not an integer, then

S`(x, z) = S`(x, y) + S`(y, z).

` (b) Reflection: S`(x, y) ≡ (−1) S`(1 − y, 1 − x) mod p. 6 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

(c) Subdivision: If d is a positive integer and p - d, then d−1 X x + i y + i S (x, y) ≡ d` S , mod p. ` ` d d i=0 We include the short proof here for the convenience of the reader.

Proof. The first two properties are immediate from the definition of S`(x, y). For the third, since p - d, every integer s can be expressed in a unique way as s = qd−ip for some integer i ∈ [0, d). Therefore, d−1 X X ` S`(x, y) = (qd − ip) i=0 xp 1/2, then one obtains 1 1 2k−1 1 1 2 7  Ck(2, 5, 6)B2k ≡ S2k−1( , ) + 2 S2k−1( , ) + S2k−1( , ) 6 5 6 5 3 10 (2.5) 2k−1 1 1 2k−1 3 1 ≡ (1 + 2 )S2k−1( 6 , 5 ) − 2 S2k−1( 10 , 3 ) mod p, provided p ≥ 7 and p − 1 - 2k. This new expression has two sums, each now pos- sessing modestly more complicated coefficients, but the cost of this congruence has dropped to p/15. Tanner and Wagstaff also derived a more complicated congruence for Bernoulli numbers with more sums and lower cost. By starting with (2.4) in the case b = 9, and employing five prescribed subdivision steps in sequence, using reflection and separation as appropriate for simplification, they found a congruence for B2k mod p having seven sums with cost p/18. They also reported that begin- ning with the congruence (2.5) and applying two particular subdivision operations, together with appropriate simplifications, produces an expression with cost p/19.2. While the resulting congruence is not reported, we find that it has eight sums. Finally, it is mentioned in the same article that the authors could construct a more complicated congruence with approximate cost p/22, but its construction is not specified. We use Proposition 2.1 to search for congruences for Bernoulli numbers mod p that are particularly favorable for computations. Certainly, it is advantageous to employ a congruence with small cost, but one must also be concerned with the number of sums appearing in the expressions, as well as the size and complexity of their coefficients, as each of these contributes to overhead costs in computations. It may also be helpful for each sum in a congruence to have a comparable number WOLSTENHOLME AND VANDIVER PRIMES 7 of elements, for balancing loads in parallel environments. In addition, for larger primes we may be able to tolerate greater overhead costs, so we therefore seek a family of congruences for Bernoulli numbers mod p: for a range of small positive integers m, we would like an expression for B2k having exactly m sums with cost p/rm, with rm as large as possible. The case m = 1 was the subject of a search by Wagstaff [32], who found nothing better than the value r1 = 12 exhibited by (2.2), as well as by the well-known relation (see, e.g., [28, ex. IX.6])

1 1 Ck(2, 3, 4)B2k ≡ S2k−1( 4 , 3 ) mod p, (2.6) valid for primes p ≥ 5 when p − 1 - 2k. This latter relation follows from Voronoi’s congruence, and in fact is the case b = 3 in (2.4). We searched for improved values for some larger m by using Proposition 2.1, with a number of starting relations. We employed two strategies in searching for useful congruences: exhaustive searches, and heuristic searches. We describe each of these below, along with its principal results.

2.1. Exhaustive searches. In an exhaustive search, we supply a starting congru- ence such as (2.2), along with a list of positive integers d1, . . . , d`, and we construct all possible congruences that can be formed with a sequence of at most ` subdivision operations starting from our initial congruence, where the ith subdivision employs a value of d satisfying 2 ≤ d ≤ di. We make a number of runs with this method using different initial lists d1, . . . , d`, some with a small value of ` like ` = 4 and larger values for the di such as 6 or 8, and some with a larger value of ` like ` = 7, where we limit the di to smaller values such as 2 or 3. After each subdivision, we use the reflection and separation properties to simplify our expressions as much as possible. Over several runs with different parameters we maintain a list that stores for each m the smallest cost of a congruence having m sums that was constructed from the given starting relation, along with information on how to construct it. For starting relations, we employed each of the congruences (2.2), (2.3), (2.4) with b ≤ 13, (2.6), as well as the well-known relation

1 1 3 2 Ck(4, 5, 8)B2k ≡ S2k−1( 8 , 5 ) + S2k−1( 8 , 5 ) mod p, (2.7) which is valid for p ≥ 7 and p − 1 - 2k and has cost p/10. This last expression also follows from Voronoi’s congruence [28, ex. IX.6]. In addition, in order to search more effectively at larger values of m, we would start this procedure at a favorable congruence observed at a smaller value of m. For example, many improved values for m ≥ 18 were found by starting a search at the best known congruence at m = 16. Table 1 summarizes the results of our searches using this strategy, displaying the minimal cost discovered among congruences having exactly m sums, for a range of values of m. In each case, the best example we found was constructed using Vandiver’s congruence (2.3) as its starting point. We therefore assume p ≥ 7 and p − 1 - 2k in all congruences displayed in the remainder of this section. We provide details only on the congruences from Table 1 that were employed in our searches for Wolstenholme primes, described in Section 3. For m = 2, the best example we find is in fact (2.5), where r2 = 15. For m = 6, we find a congruence with cost p/19.2, so this requires two fewer sums than the congruence with the same cost reported in [27]. To obtain this, starting 8 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

Table 1. For m ≤ 24, the smallest known cost for a congruence for Bernoulli numbers mod p having exactly m sums is p/rm. For m > 1, each was constructed using the method of Section 2.1 using (2.3) as the initial congruence.

m rm m rm m rm 1080 1 12 9 20 17 43 = 25.11 ... 1200 180 2 15 10 59 = 20.33 ... 18 7 = 25.71 ... 360 180 3 15 11 17 = 21.17 ... 19 7 = 25.71 ... 120 108 810 4 7 = 17.14 ... 12 5 = 21.6 20 31 = 26.12 ... 240 45 1080 5 13 = 18.46 ... 13 2 = 22.5 21 41 = 26.34 ... 96 1080 80 6 5 = 19.2 14 47 = 22.97 ... 22 3 = 26.66 ... 960 540 3240 7 49 = 19.59 ... 15 23 = 23.47 ... 23 121 = 26.77 ... 1920 1620 8 97 = 19.79 ... 16 24 24 59 = 27.45 ...

with (2.5) one subdivides the S2k−1(3/10, 1/3) term with d = 2, simplifies appro- priately, then subdivides S2k−1(1/3, 7/20) using d = 2, then the S2k−1(13/40, 1/3) term with d = 2, and finally subdivides the resulting sum S2k−1(1/3, 27/80) with d = 2. Writing t = 2k − 1 for economy, this produces the six-term congruence 2t 3 13 2t 4t 13 1 Ck(2, 5, 6)B2k ≡ −2 St( 20 , 80 ) − (2 + 2 )St( 80 , 6 ) t 3t 5t 1 27 t 3t 27 7 + (1 + 2 + 2 + 2 )St( 6 , 160 ) + (1 + 2 + 2 )St( 160 , 40 ) (2.8) t 7 1 5t 53 1 + (1 + 2 )St( 40 , 5 ) − 2 St( 160 , 3 ) mod p. Here, the cost of each sum is respectively p/80, p/240, p/480, p/160, p/40, and p/480, so this example has r6 = 96/5. We remark that intermediate expressions generated when creating (2.8) in this way produce two more of the entries in Table 1. Applying just the first two sub- divisions described above to (2.5) produces our congruence with m = 4 sums and cost 7p/120; applying the third subdivision to this manufactures our example at m = 5 with cost 13p/240. We also find a particularly well-balanced example with small cost at m = 9. Again starting with Vandiver’s congruence (2.3), we first subdivide St(1/6, 1/5) with d = 3, then subdivide the resulting sums St(4/15, 5/18) and St(7/18, 2/5) using d = 2, and finally subdivide St(11/36, 1/3) with d = 5. This produces the nine-term congruence t t 1 11 t t t 11 1 Ck(2, 5, 6)B2k ≡ (3 + 6 )St( 18 , 180 ) + (3 + 6 − 10 )St( 180 , 15 ) t t t 2 5 t t 7 1 − (6 − 10 + 12 )St( , ) + (6 + 12 )St( , ) 15 36 36 5 (2.9) t 47 4 t t t 3 11 t 1 61 − 10 St( 180 , 15 ) − (2 + 6 + 12 )St( 10 , 36 ) + 10 St( 3 , 180 ) t t 13 11 t 83 7 + (6 + 12 )St( 36 , 30 ) − 10 St( 180 , 15 ) mod p, where again we write t for 2k − 1. Each sum here has the same cost, p/180, so this expression achieves r9 = 20. Figure 3 in Section 6 depicts the transformation of (2.3) into (2.9). WOLSTENHOLME AND VANDIVER PRIMES 9

We provide details on two additional congruences from Table 1, which are em- ployed in the searches described in the next section. For an expression with m = 16 sums and cost p/24, starting from (2.9) we subdivide both the St(7/36, 1/5) and the St(3/10, 11/36) sums using d = 3, then subdivide St(47/180, 4/15) with d = 2, and finally subdivide the resulting sums St(47/360, 2/15) and St(83/180, 7/15) with d = 2. This yields

t t 1 11 t t t 11 7 Ck(2, 5, 6)B2k ≡ (3 + 6 )St( 18 , 180 ) + (3 + 6 − 10 )St( 180 , 108 ) t t t t t 7 47 + (3 + 6 − 10 + 18 + 36 )St( 108 , 720 ) t t t t t t 47 1 + (3 + 6 − 10 + 18 + 36 − 40 )St( 720 , 15 ) t t t 1 11 t t t 2 5 − (6 + 18 + 36 )St( 10 , 108 ) − (6 − 10 + 12 )St( 15 , 36 ) t 83 25 t t t t 25 7 − 20 St( 360 , 108 ) + (6 + 18 − 20 + 36 )St( 108 , 30 ) (2.10) t t t 4 29 t 29 97 − (18 − 20 + 36 )St( 15 , 108 ) + 20 St( 108 , 360 ) t 1 61 t t 13 11 t 11 133 + 10 St( 3 , 180 ) + (6 + 12 )St( 36 , 30 ) + 20 St( 30 , 360 ) t t 43 2 t t t t 13 313 + (18 + 36 )St( 108 , 5 ) − (6 + 18 + 36 − 40 )St( 30 , 720 ) t t t 313 47 − (6 + 18 + 36 )St( 720 , 108 ) mod p.

Here, while the costs of the individual sums vary considerably, from p/2160 to p/180, the cost of the entire rule is just p/24, so exactly half that of (2.2). We also record the derivation of the 22-term congruence referenced in Table 1. Starting from (2.10), subdivide St(1/3, 61/180) with d = 3, and then subdivide each of St(1/9, 61/540), St(4/15, 29/108), St(29/108, 97/360), and St(479/1080, 4/9) in turn using d = 2. This yields

t t t 1 61 t t 61 11 Ck(2, 5, 6)B2k ≡ (3 + 6 + 60 )St( 18 , 1080 ) + (3 + 6 )St( 1080 , 180 ) t t t 11 7 t t t t t 7 47 + (3 + 6 − 10 )St( 180 , 108 ) + (3 + 6 − 10 + 18 + 36 )St( 108 , 720 ) t t t t t t 47 1 + (3 + 6 − 10 + 18 + 36 − 40 )St( 720 , 15 ) t t t 1 11 − (6 + 18 + 36 )St( 10 , 108 ) t t t t t t 2 29 − (6 − 10 + 12 + 36 − 40 + 72 )St( 15 , 216 ) t t t t 29 97 − (6 − 10 + 12 − 40 )St( , ) 216 720 (2.11) t t t 97 5 t 119 479 t t 479 2 − (6 − 10 + 12 )St( 720 , 36 ) − 30 St( 540 , 2160 ) − (30 + 120 )St( 2160 , 9 ) t 83 25 t t t t 25 7 t 5 601 − 20 St( 360 , 108 ) + (6 + 18 − 20 + 36 )St( 108 , 30 ) + 120 St( 18 , 2160 ) t t 13 263 t t t 263 79 + (6 + 12 )St( 36 , 720 ) + (6 + 12 − 40 )St( 720 , 216 ) t t t t t 79 11 t 11 133 + (6 + 12 + 36 − 40 + 72 )St( 216 , 30 ) + 20 St( 30 , 360 ) t t 43 2 t t t t 13 313 + (18 + 36 )St( 108 , 5 ) − (6 + 18 + 36 − 40 )St( 30 , 720 ) t t t 313 47 t 4 241 − (6 + 18 + 36 )St( 720 , 108 ) + 30 St( 9 , 540 ) mod p, which has cost 3p/80. Finally, we describe an additional congruence for Bernoulli numbers with 30 sums that is employed in some of our searches: from (2.11), subdivide St(43/108, 2/5) us- ing d = 6, and then apply this transformation with d = 2 to each of St(4/15, 173/648), 10 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

St(4/9, 241/540), and St(299/1080, 5/18) in turn. This produces

t t t 1 61 t t 61 11 t t t 11 7 Ck(2,5,6)B2k≡(3 +6 +60 )St( 18 , 1080 )+(3 +6 )St( 1080 , 180 )+(3 +6 −10 )St( 180 , 108 ) t t t t t 7 47 t t t t t t 47 43 +(3 +6 −10 +18 +36 )St( 108 , 720 )+(3 +6 −10 +18 +36 −40 )St( 720 , 648 ) t t t t t t t t 43 1 t t t t t 1 65 +(3 +6 −10 +18 +36 −40 +108 +216 )St( 648 , 15 )−(6 +18 +36 +108 +216 )St( 10 , 648 ) t t t 65 11 t t t t t t t t 2 173 −(6 +18 +36 )St( 648 , 108 )−(6 −10 +12 +36 −40 +72 +216 +432 )St( 15 , 1296 ) t t t t t t 173 29 t t t t 29 97 −(6 −10 +12 +36 −40 +72 )St( 1296 , 216 )−(6 −10 +12 −40 )St( 216 , 720 ) t t t 97 299 t t t t 299 5 t 119 479 −(6 −10 +12 )St( , )−(6 −10 +12 +120 )St( , )−30 St( , ) 720 2160 2160 36 540 2160 (2.12) t t 479 2 t 2 241 t 83 25 t t t t 25 151 −(30 +120 )St( 2160 , 9 )+60 St( 9 , 1080 )−20 St( 360 , 108 )+(6 +18 −20 +36 )St( 108 , 648 ) t t t t t t 151 7 t 5 601 t t t 13 781 +(6 +18 −20 +36 +108 +216 )St( 648 , 30 )+120 St( 18 , 2160 )+(6 +12 +120 )St( 36 , 2160 ) t t 781 263 t t t 263 79 t t t t t 79 475 +(6 +12 )St( 2160 , 720 )+(6 +12 −40 )St( 720 , 216 )+(6 +12 +36 −40 +72 )St( 216 , 1296 ) t t t t t t t 475 11 t 11 133 t t 259 2 +(6 +12 +36 −40 +72 +216 +432 )St( 1296 , 30 )+20 St( 30 , 360 )+(108 +216 )St( 648 , 5 ) t t t t t t 13 281 t t t t 281 313 −(6 +18 +36 −40 +108 +216 )St( 30 , 648 )−(6 +18 +36 −40 )St( 648 , 720 ) t t t 313 47 −(6 +18 +36 )St( 720 , 108 ) mod p, with cost 227p/6480 < p/28.5.

2.2. Heuristic searches. Our second strategy looks for congruences with small cost, without regard to the number of sums or the complexity of the coefficients in the resulting expression. This search is designed to investigate the question raised by Tanner and Wagstaff [27] of whether there exist congruences with cost less than p for arbitrarily small  > 0. We also provide a few basic bounds in relation to this question in Section 6. In our heuristic searches, we begin with an initial congruence C0 and positive integers D and λ. We then construct all possible congruences using λ subdivision operations, each using a value d ≤ D. We select a congruence C1 of minimal cost from this set, and recursively invoke the algorithm using this as our starting congruence. This continues for a number of rounds. We keep λ small, often starting with λ = 2, then switching to λ = 1 after a particular number of steps. We typically select D = 6 or D = 8. This method thus makes locally optimal choices to construct congruences with very low cost. Beginning with Vandiver’s congruence (2.3), we use this method to construct a congruence for Bernoulli numbers mod p having cost 5970989p p < . 241920000 40.5 The expression we constructed contains 546 sums, but there is no reason to believe this is optimal. However, this appears to lend some heuristic evidence for the existence of congruences for Bernoulli numbers with cost less than p with  > 0 arbitrarily small.

3. Searching for Wolstenholme primes Using Glaisher’s congruence (1.2), we have that p ≥ 5 is a Wolstenholme prime if and only if p | Bp−3. We employ the congruences from the prior section to compute the residue of Bp−3 mod p for primes p ≥ 7, using k = (p − 3)/2. In this case, 3 3 3 Ck(a, b, c) ≡ (c − a − b + 1)/6 mod p, so for example (2.5) becomes p−4 1 1 p−4 3 1 14Bp−3 ≡ (1 + 2 )Sp−4( 6 , 5 ) − 2 Sp−4( 10 , 3 ), WOLSTENHOLME AND VANDIVER PRIMES 11 that is,

1 1 3 1 112Bp−3 ≡ 9Sp−4( 6 , 5 ) − Sp−4( 10 , 3 ). (3.1)

Here and throughout this section, all congruences are understood to be taken mod p. In the same way, the congruences (2.2), (2.8), (2.9), (2.10), (2.11), and (2.12) pro- duce respectively (writing S(x, y) for Sp−4(x, y) throughout for economy of space)

1 1 21Bp−3 ≡ S( 6 , 4 ), (3.2)

3 13 13 1 1 27 458752Bp−3 ≡ − 512S( 20 , 80 ) − 520S( 80 , 6 ) + 36929S( 6 , 160 ) 27 7 7 1 53 1 (3.3) + 36928S( 160 , 40 ) + 36864S( 40 , 5 ) − S( 160 , 3 ),

1 11 11 1 2 5 336000Bp−3 ≡ 1000S( 18 , 180 ) + 976S( 180 , 15 ) − 101S( 15 , 36 ) 7 1 47 4 3 11 + 125S( 36 , 5 ) − 24S( 180 , 15 ) − 3125S( 10 , 36 ) (3.4) 1 61 13 11 83 7 + 24S( 3 , 180 ) + 125S( 36 , 30 ) − 24S( 180 , 15 ),

1 11 11 7 72576000Bp−3 ≡ 216000S( 18 , 180 ) + 210816S( 180 , 108 ) 7 47 47 1 + 211816S( 108 , 720 ) + 211735S( 720 , 15 ) 1 11 2 5 83 25 − 25000S( 10 , 108 ) − 21816S( 15 , 36 ) − 648S( 360 , 108 ) 25 7 4 29 29 97 (3.5) + 24352S( 108 , 30 ) − 352S( 15 , 108 ) + 648S( 108 , 360 ) 1 61 13 11 11 133 + 5184S( 3 , 180 ) + 27000S( 36 , 30 ) + 648S( 30 , 360 ) 43 2 13 313 313 47 + 1000S( 108 , 5 ) − 24919S( 30 , 720 ) − 25000S( 720 , 108 ),

1 61 61 11 72576000Bp−3 ≡ 216024S( 18 , 1080 ) + 216000S( 1080 , 180 ) 11 7 7 47 47 1 + 210816S( 180 , 108 ) + 211816S( 108 , 720 ) + 211735S( 720 , 15 ) 1 11 2 29 29 97 97 5 − 25000S( 10 , 108 ) − 21860S( 15 , 216 ) − 21735S( 216 , 720 ) − 21816S( 720 , 36 ) 119 479 479 2 83 25 25 7 − 192S( 540 , 2160 ) − 195S( 2160 , 9 ) − 648S( 360 , 108 ) + 24352S( 108 , 30 ) (3.6) 5 601 13 263 263 79 79 11 + 3S( 18 , 2160 ) + 27000S( 36 , 720 ) + 26919S( 720 , 216 ) + 27044S( 216 , 30 ) 11 133 43 2 13 313 313 47 + 648S( 30 , 360 ) + 1000S( 108 , 5 ) − 24919S( 30 , 720 ) − 25000S( 720 , 108 ) 4 241 + 192S( 9 , 540 ), and

1 61 61 11 11 7 15676416000Bp−3≡46661184S( 18 , 1080 )+46656000S( 1080 , 180 )+45536256S( 180 , 108 ) 7 47 47 43 43 1 1 65 +45752256S( 108 , 720 )+45734760S( 720 , 648 )+45735760S( 648 , 15 )−5401000S( 10 , 648 ) 65 11 2 173 173 29 29 97 −5400000S( 648 , 108 )−4721885S( 15 , 1296 )−4721760S( 1296 , 216 )−4694760S( 216 , 720 ) −4712256S( 97 , 299 )−4712904S( 299 , 5 )−41472S( 119 , 479 )−42120S( 479 , 2 ) 720 2160 2160 36 540 2160 2160 9 (3.7) 2 241 83 25 25 151 151 7 +5184S( 9 , 1080 )−139968S( 360 , 108 )+5260032S( 108 , 648 )+5261032S( 648 , 30 ) 5 601 13 781 781 263 263 79 +648S( 18 , 2160 )+5832648S( 36 , 2160 )+5832000S( 2160 , 720 )+5814504S( 720 , 216 ) 79 475 475 11 11 133 259 2 +5841504S( 216 , 1296 )+5841629S( 1296 , 30 )+139968S( 30 , 360 )+1000S( 648 , 5 ) 13 281 281 313 313 47 −5383504S( 30 , 648 )−5382504S( 648 , 720 )−5400000S( 720 , 108 ). 12 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

It remains to describe how to calculate these sums efficiently. For this, we first note that X p−4 X −3 Sp−4(x, y) = s ≡ s mod p. xp

c0 ← 1, c1 ← 0 For each integer s ∈ (xp, yp): 3 (3.8) c1 ← c1s + c0 mod p 3 c0 ← c0s mod p We use Nvidia Tesla V100 GPUs to compute these sums. Each GPU consists of 80 streaming multiprocessors (SMs), each of which can execute up to 2048 threads concurrently, although in our computation this needs to reduce to 1024 threads per SM, owing to our need to work with 64-bit arithmetic. Each GPU works in concert with an attached CPU. The CPU is tasked with a range of integers to check. For each prime p within its assigned interval, the CPU invokes the GPU once for each sum in the congruence being employed. Given p, dxpe, and bypc, the GPU divides the integers in (xp, yp) into 80 · 1024 arithmetic progressions of approximately equal size, one progression for each thread. Each thread θ uses the strategy of (3.8), replacing the interval (xp, yp) with an appropriate arithmetic progression Pθ, to compute the constant coefficient c0 and the linear coefficient c1 mod p for the polynomial Y (z + s3).

s∈Pθ

The GPU then reduces these 81920 pairs of values (c0, c1) down to 80 pairs with ten further rounds of parallel calculations. Each round halves the number of current 0 0 pairs by combining two pairs (c0, c1) and (c0, c1) via 0 0 0 0 0 2 (c1z + c0)(c1z + c0) ≡ (c0c1 + c1c0)z + c0c0 mod z , (3.9) computing the coefficients mod p. This process ends after ten rounds because only the threads operating in the same block, that is, executing within the same SM, can share memory easily. After this, the CPU handles the final reduction, using (3.9) iteratively to combine the remaining 80 pairs into a single pair, which represents the values of c0 and c1 for the entire sum mod p. Once all the sums in the congru- ence have been computed, the CPU then combines their values, incorporates the appropriate coefficients, and computes the appropriate inverse mod p, to determine the residue of Bp−3. It remains to select the congruence employed at each stage of the computation. While more complicated congruences like (3.4) and (3.5) have smaller cost than simpler congruences like (3.1) and (3.2), the congruences with a larger number of sums require greater computational overhead in invoking the GPU multiple times WOLSTENHOLME AND VANDIVER PRIMES 13 and combining the results of these calls, so the more complex methods are only economical for larger values of p. For example, we found that the nine-term con- gruence (3.4) did not offer any savings over the six-term congruence (3.3) for primes near 1.6 · 1010, even though the nominal cost of the former congruence is slightly better. Consequently, we employed different congruences over our computation. We employed the simple congruence (3.2), with cost p/12, for primes p < 1.6 · 1010. We then switched to the six-term congruence (3.3), with cost p/19.2, for p < 2 · 1010. After this, we used the nine-term congruence (3.4), with cost p/20, for p < 2.8·1010, then the 16-term expression (3.5), with cost p/24, up to 3.6 · 1010, followed by the 22-term congruence (3.6), with cost 3p/80 up to 5 · 1010, and finally the 30-term congruence (3.7) with cost 227p/6480 < p/28.5 for p > 5 · 1010. This strategy was not optimal: certainly we would have saved time by employing the two-term congruence (3.1), which features cost p/15, at an appropriate stage. Employing GPUs allowed for much faster calculations compared to prior searches. The congruence (3.2) was employed in prior searches for Wolstenholme primes [18–20], and in [20] it was reported that determining whether Bp−3 ≡ 0 mod p using this congruence for a single prime near 109 required about 4.3 seconds of CPU time, using MIPS R12000 processors. Using the same congruence, our GPU implementation requires approximately 3.15 milliseconds per prime near 109 to compute Bp−3 mod p on a CPU-GPU pair. The contrast remains stark when we compare our CPU-GPU implementation with a CPU-only implementation that em- ploys the more modern Intel Xeon Cascade Lake processors: these require about 1.98 seconds per prime in that range to compute Bp−3 mod p. We remark also that the GPU method with the slightly more complicated congruence (3.1) computes 9 Bp−3 mod p for primes near 10 in an average of just 2.73 milliseconds per prime, so this two-term congruence is advantageous compared to (3.2), even for p near 109. We employed native arithmetic whenever possible. For p < 232, each multipli- cation operation mod p produces an intermediate result that fits in a 64-bit long word, so each such operation required one multiplication instruction and one mod- ular reduction operation. Larger primes required more care. In the general case, 32 in order to multiply a and b mod p, with 0 ≤ a, b < p, we write a = a0 + a12 and 32 b = b0 + b12 , so that 32 32 64 ab = a0b0 + a1b02 + b1(a02 + a12 ). (3.10) This allows us to compute this product without arithmetic overflow. We note that for a given prime p we compute 264 mod p just once, using one modular reduction and one addition, so that the amortized cost of computing the expression (3.10) mod p is four multiplications, four modular reductions, two bit shifts, and three additions, plus two bitwise “and” operations and two additional bit shifts used to create the operands from a and b. We took advantage of certain optimizations that are available over particular 34 ranges. For example, when computing a sum Sp−4(x, y) with y ≤ 1/4 when p < 2 , then for xp < s < yp the quantity s2 mod p can be calculated natively. For p > 234 we typically needed to use (3.10) in its full generality. 10 For a prime p near 6 · 10 , our implementation computes the value of Bp−3 mod p using the 30-term congruence (3.7) in approximately 253 milliseconds. Our search found that no Wolstenholme primes p with 2124679 < p < 6 · 1010 exist. We record here some “near misses”: let hrip denote the unique representative 14 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

9 10 Table 2. Primes p ∈ (10 , 6 · 10 ) for which |hBp−3ip| < 50.

p hBp−3ip p hBp−3ip 1025793739 −9 16425136499 7 1029113299 −7 21861395221 −11 1939582759 −19 22855335949 33 2139716869 2 23345427659 −27 3803691517 13 23543635009 −21 8208762073 24 27827984099 34 9267199079 −22 40306537633 42 13581221947 40 44718258259 −6 14211360143 −41 56604583391 −25 15744104053 −2

10 Figure 1. Histogram for hBp−3ip/p for p < 6 · 10 .

�������

�������

�������

�������

�������

-��� -��� ��� ��� ���

of r mod p lying in (−p/2, p/2]. Table 2 records the primes p with 109 < p < 6·1010 where |hBp−3ip| < 50; a Wolstenholme prime p would of course have hBp−3ip = 0. All computations were performed on Gadi, a high-performance computer man- aged by NCI Australia. Using our method, the primes p < 109 can be checked on a single GPU in about nine hours, to confirm the computations in [20]. Over larger ranges, we often ran multiple GPUs simultaneously, each handling an interval of size 5 · 106. We discern no particular bias among the values of Bp−3 mod p. Figure 1 dis- plays a histogram with 2000 bins of equal size for the values of hBp−3ip/p over the 2524038153 primes p with 5 ≤ p < 6 · 1010; a perfectly uniform distribution would display as a horizontal line at 0.0005.

4. Congruences for Euler numbers In 1902, Glaisher [12, §34] established a formula for the residue of Euler numbers modulo a prime p. Using our S`(x, y) notation, this is p−1 2 −k 2k−1 1 (−1) 4 Ep−1−2k ≡ Sp−1−2k(0, 4 ) mod p (4.1) when p ≥ 5, 2k ≤ p − 3 is a positive even integer, and p − 1 - 2k. Special cases of this congruence also appear in [16, p. 359] and [25, Cor. 3.7]. This congruence WOLSTENHOLME AND VANDIVER PRIMES 15 has cost p/4, and was employed in prior searches for Vandiver primes [19]. We apply the exhaustive search strategy from Section 2.1, using similar parameters, to determine some congruences equivalent to (4.1) with smaller cost. We describe the derivation of four favorable congruences having m = 3, 5, 9, and 16 terms respectively, which stem from (4.1), and which were employed in our calculations. We assume p ≥ 5 and p − 1 - 2k throughout. For our congruence with m = 3, apply subdivision with d = 2 to St(0, 1/4) in (4.1), and then the same transformation to the resulting term St(0, 1/8). After simplifying using reflection and separation as required, we obtain

k 2k−1 t 1 t 3 7 t t 7 1 (−1) 4 Et ≡ 4 St(0, 16 ) + 2 St( 8 , 16 ) + (2 + 4 )St( 16 , 2 ) mod p, (4.2) where we write t for p − 1 − 2k for brevity. This congruence has cost 3p/16. For m = 5, we apply two more subdivision transformations on (4.2) with d = 2, on St(0, 1/16) and then on St(0, 1/32), to produce our congruence with cost 9p/64:

k 2k−1 t 1 t 3 7 t t 7 15 (−1) 4 Et ≡ 16 St(0, ) + 2 St( , ) + (2 + 4 )St( , ) 64 8 16 16 32 (4.3) t t t 15 31 t t t t 31 1 + (2 + 4 + 8 )St( 32 , 64 ) + (2 + 4 + 8 + 16 )St( 64 , 2 ) mod p.

Next, for m = 9, we subdivide the St(0, 1/128) term from (4.3) with d = 2 and St(3/8, 7/16) using d = 3 to produce

k 2k−1 t 1 t 1 7 t 3 5 (−1) 4 Et ≡ 32 St(0, 128 ) + 6 St( 8 , 48 ) + 6 St( 16 , 24 ) t t 7 11 t t t 11 15 + (2 + 4 )St( 16 , 24 ) + (2 + 4 + 6 )St( 24 , 32 ) t t t t 15 23 t t t 23 31 + (2 + 4 + 6 + 8 )St( 32 , 48 ) + (2 + 4 + 8 )St( 48 , 64 ) (4.4) t t t t 31 63 + (2 + 4 + 8 + 16 )St( 64 , 128 ) t t t t t 63 1 + (2 + 4 + 8 + 16 + 32 )St( 128 , 2 ) mod p, which has cost 43p/384 = p/8.93 ... , so less than half that of (4.1). For m = 16, we subdivide the St(3/16, 5/24) and St(7/16, 11/24) terms from (4.4) with d = 3, and St(0, 1/128), St(1/8, 7/48), and St(11/24, 15/32) with d = 2 to yield

k 2k−1 t 1 t t 1 5 t 5 7 (−1) 4 Et ≡ 64 St(0, 256 ) + (12 + 18 )St( 16 , 72 ) + 12 St( 72 , 96 ) t t 7 11 t t 13 3 + (6 + 12 )St( 48 , 72 ) + (6 + 12 )St( 72 , 16 ) t t t 11 15 t 19 17 + (4 + 8 + 12 )St( 48 , 64 ) + 18 St( 72 , 64 ) t t t t 17 13 t 19 29 t 41 7 + (4 + 8 + 12 + 18 )St( , ) + 18 St( , ) + 12 St( , ) 64 48 48 72 96 16 (4.5) t t t t 15 23 t t t t t 23 31 + (2 + 4 + 6 + 8 )St( 32 , 48 ) + (2 + 4 + 6 + 8 + 12 )St( 48 , 64 ) t t t t t t 31 35 + (2 + 4 + 6 + 8 + 12 + 16 )St( 64 , 72 ) t t t t 35 63 t t t t t 63 127 + (2 + 4 + 8 + 16 )St( 72 , 128 ) + (2 + 4 + 8 + 16 + 32 )St( 128 , 256 ) t t t t t t 127 1 + (2 + 4 + 8 + 16 + 32 + 64 )St( 256 , 2 ) mod p, for a cost of 205p/2304 = p/11.23 ... . Last, for our relation with m = 24, we 1 1 5 41 7 subdivide the terms St(0, 256 ), St( 16 , 72 ), and St( 96 , 16 ) in (4.5) using d = 2, 4, 41 7 15 137 and 3 respectively, and then subdivide St( 288 , 48 ) and St( 32 , 288 ) in the resulting 16 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN expression with d = 2 to obtain

k 2k−1 t 1 t t 1 5 t 5 41 t t 41 7 (−1) 4 Et≡128 St(0, 512 )+(48 +72 )St( 64 , 288 )+12 St( 72 , 576 )+(12 +72 )St( 576 , 96 ) t t 7 11 t t 13 3 t 3 55 t t t 11 67 +(6 +12 )St( 48 , 72 )+(6 +12 )St( 72 , 16 )+36 St( 16 , 288 )+(4 +8 +12 )St( 48 , 288 ) t t t t t 67 15 t t t t 15 137 +(4 +8 +12 +48 +72 )St( 288 , 64 )+(4 +8 +12 +16 )St( 64 , 576 ) t t t t 151 19 t t t t t 19 17 +(4 +8 +12 +16 )St( 576 , 72 )+(4 +8 +12 +16 +18 )St( 72 , 64 ) t t t t t t 17 77 t t t t 77 13 t 19 29 +(4 +8 +12 +18 +48 +72 )St( 64 , 288 )+(4 +8 +12 +18 )St( 288 , 48 )+18 St( 48 , 72 ) (4.6) t 41 247 t t t t t 137 23 t t t t t 23 139 +72 St( 96 , 576 )+(2 +4 +6 +8 +36 )St( 288 , 48 )+(2 +4 +6 +8 +12 )St( 48 , 288 ) t t t t t t t 139 31 t t t t t t 31 35 +(2 +4 +6 +8 +12 +48 +72 )St( 288 , 64 )+(2 +4 +6 +8 +12 +16 )St( 64 , 72 ) t t t t 35 63 t t t t t 63 127 +(2 +4 +8 +16 )St( 72 , 128 )+(2 +4 +8 +16 +32 )St( 128 , 256 ) t t t t t t 127 255 t t t t t t t 255 1 +(2 +4 +8 +16 +32 +64 )St( 256 , 512 )+(2 +4 +8 +16 +32 +64 +128 )St( 512 , 2 ) mod p, which has cost 115p/1536 = p/13.35 ... . We also find that we can derive some better congruences by using another start- ing relation. In [19], McIntosh proved that

k k−1 k 1 (−1) 4 (9 + 1)Ep−1−2k ≡ Sep−1−2k(0, 6 ), (4.7) provided p ≥ 5 and p - (9k + 1), where

X s ` Se`(x, y) = (−1) s mod p. xp

We apply a subdivision operation with d = 2 to the Se`(x, y) expression in (4.7), producing (writing t for p − 2k − 1)

k k−1 k t 1 5 1  (−1) 4 (9 + 1)Et ≡ 2 St(0, 12 ) − St( 12 , 2 ) . (4.8) After this we may apply the transformations of Proposition 2.1 in the usual way. Using this strategy, we obtain congruences with costs lower than those we could construct using (4.1) as our base. We record just one such congruence here, as it is employed in our searches. Starting with (4.8) and applying the sixteen subdivision steps

1 d = 2 on (0, 2k·3 ), 2 ≤ k ≤ 8, 5 11 11 17 17 23 23 35 d = 3 on ( 12 , 24 ), ( 24 , 36 ), ( 36 , 48 ), ( 48 , 72 ), 5 11 5 11 d = 2 on ( 36 , 72 ), ( 72 , 144 ), 61 31 133 67 205 103 d = 3 on ( 144 , 72 ), ( 288 , 144 ), ( 432 , 216 ) in sequence, and simplifying appropriately using reflection and separation after each step, we obtain the following congruence for Euler numbers with cost 27p/512 < WOLSTENHOLME AND VANDIVER PRIMES 17 p/18.96, which holds for p ≥ 5 and p - (9k + 1):

k k−1 k t 1 t 5 11 t 61 31 t t 11 133 (−1) 4 (9 +1)Et≡256 St(0, 1536 )−24 St( 144 , 288 )−36 St( 432 , 216 )−(6 −12 )St( 72 , 864 ) t t t 133 67 t t 67 17 t t t 17 205 −(6 −12 +72 )St( 864 , 432 )−(6 −12 )St( 432 , 108 )−(6 −12 +18 )St( 108 , 1296 ) t t t t 205 103 t t t 103 23 t t t t 23 35 −(6 −12 +18 +108 )St( 1296 , 648 )−(6 −12 +18 )St( 648 , 144 )−(6 −12 +18 −24 )St( 144 , 216 ) t t t t 37 25 t t t 25 113 t t t t 113 227 −(6 −12 +18 −24 )St( 216 , 144 )−(6 −12 +18 )St( 144 , 648 )−(6 −12 +18 +108 )St( 648 , 1296 ) t t t 227 19 t t 19 77 t t t 77 155 −(6 −12 +18 )St( 1296 , 108 )−(6 −12 )St( 108 , 432 )−(6 −12 +72 )St( 432 , 864 ) t t 155 13 t 13 41 t t 41 83 t 83 7 −(6 −12 )St( 864 , 72 )−6 St( 72 , 216 )−(6 +36 )St( 216 , 432 )−6 St( 432 , 36 ) t t t t t 35 421 t t t t t t 421 211 −(2 −4 +6 −8 −12 )St( 72 , 864 )−(2 −4 +6 −8 −12 +72 )St( 864 , 432 ) t t t t t 211 47 t t t t t t 47 53 −(2 −4 +6 −8 −12 )St( 432 , 96 )−(2 −4 +6 −8 −16 −12 )St( 96 , 108 ) t t t t t t t 53 637 t t t t t t t t 637 319 −(2 −4 +6 −8 −16 −12 +18 )St( 108 , 1296 )−(2 −4 +6 −8 −16 −12 +18 +108 )St( 1296 , 648 ) t t t t t t t 319 71 t t t t t t t t 71 95 −(2 −4 +6 −8 −12 −16 +18 )St( 648 , 144 )−(2 −4 +6 −8 −16 −12 +18 −24 )St( 144 , 192 ) t t t t t t t t t 95 107 t t t t t 107 191 −(2 −4 +6 −8 −12 −16 +18 −24 −32 )St( 192 , 216 )−(2 −4 −8 −16 −32 )St( 216 , 384 ) t t t t t t 191 383 t t t t t t t 383 767 −(2 −4 −8 −16 −32 −64 )St( 384 , 768 )−(2 −4 −8 −16 −32 −64 −128 )St( 768 , 1536 ) t t t t t t t t 767 1 −(2 −4 −8 −16 −32 −64 −128 −256 )St( 1536 , 2 ) mod p. (4.9)

Finally, we remark that using the heuristic optimization method of Section 2.2, with only modest effort we can construct more complicated congruences with cost less than p/30.4. We produced one such congruence having 438 terms with a greedy search beginning at (4.8) and using λ = 1 and D = 8, iterating over 100 rounds. A similar search beginning with (4.1) produced a congruence with 416 terms and cost near p/23.6. The question of the existence of congruences for Euler numbers with cost less than p for arbitrarily small  > 0 is of course also of interest here.

5. Searching for Vandiver primes In order to search for Vandiver primes, we require the case k = 1 in the congru- ences of the prior section. Since Sp−3(x, y) ≡ S−2(x, y) mod p, we use t = −2 in (4.2), (4.3), (4.4), (4.5), (4.6), and (4.9) to obtain the following congruences. Here, we omit the subscript on the St(x, y) terms for brevity, and naturally each of these congruences is understood to be taken modulo p. We assume p ≥ 7 throughout.

1 3 7 7 1 −64Ep−3 ≡ S(0, 16 ) + 4S( 8 , 16 ) + 5S( 16 , 2 ), (5.1)

1 3 7 7 15 −1024Ep−3 ≡ S(0, 64 ) + 64S( 8 , 16 ) + 80S( 16 , 32 ) 15 31 31 1 (5.2) + 84S( 32 , 64 ) + 85S( 64 , 2 ),

1 1 7 3 5 −36864Ep−3 ≡ 9S(0, 128 ) + 256S( 8 , 48 ) + 256S( 16 , 24 ) 7 11 11 15 15 23 + 2880S( 16 , 24 ) + 3136S( 24 , 32 ) + 3280S( 32 , 48 ) (5.3) 23 31 31 63 63 1 + 3024S( 48 , 64 ) + 3060S( 64 , 128 ) + 3069S( 128 , 2 ), 18 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

1 1 5 5 7 −1327104Ep−3 ≡ 81S(0, 256 ) + 3328S( 16 , 72 ) + 2304S( 72 , 96 ) 7 11 13 3 11 15 19 17 + 11520S( 48 , 72 ) + 11520S( 72 , 16 ) + 28224S( 48 , 64 ) + 1024S( 72 , 64 ) 17 13 19 29 41 7 15 23 + 29248S( 64 , 48 ) + 1024S( 48 , 72 ) + 2304S( 96 , 16 ) + 118080S( 32 , 48 ) (5.4) 23 31 31 35 35 63 + 120384S( 48 , 64 ) + 121680S( 64 , 72 ) + 110160S( 72 , 128 ) 63 127 127 1 + 110484S( 128 , 256 ) + 110565S( 256 , 2 ),

1 1 5 5 41 −5308416Ep−3 ≡ 81S(0, 512 ) + 832S( 64 , 288 ) + 9216S( 72 , 576 ) 41 7 7 11 13 3 3 55 + 9472S( 576 , 96 ) + 46080S( 48 , 72 ) + 46080S( 72 , 16 ) + 1024S( 16 , 288 ) 11 67 67 15 15 137 + 112896S( 48 , 288 ) + 113728S( 288 , 64 ) + 118080S( 64 , 576 ) 151 19 19 17 17 77 + 118080S( 576 , 72 ) + 122176S( 72 , 64 ) + 117824S( 64 , 288 ) 77 13 19 29 41 247 137 23 (5.5) + 116992S( 288 , 48 ) + 4096S( 48 , 72 ) + 256S( 96 , 576 ) + 473344S( 288 , 48 ) 23 139 139 31 31 35 + 481536S( 48 , 288 ) + 482368S( 288 , 64 ) + 486720S( 64 , 72 ) 35 63 63 127 127 255 + 440640S( 72 , 128 ) + 441936S( 128 , 256 ) + 442260S( 256 , 512 ) 255 1 + 442341S( 512 , 2 ),

1 5 11 61 31 11 133 477757440Ep−3≡−729S(0, 1536 )+82944S( 144 , 288 )+36864S( 432 , 216 )+995328S( 72 , 864 ) 133 67 67 17 17 205 205 103 +1004544S( 864 , 432 )+995328S( 432 , 108 )+1142784S( 108 , 1296 )+1146880S( 1296 , 648 ) 103 23 23 35 37 25 25 113 +1142784S( 648 , 144 )+1059840S( 144 , 216 )+1059840S( 216 , 144 )+1142784S( 144 , 648 ) 113 227 227 19 19 77 77 155 +1146880S( 648 , 1296 )+1142784S( 1296 , 108 )+995328S( 108 , 432 )+1004544S( 432 , 864 ) 155 13 13 41 41 83 83 7 +995328S( 864 , 72 )+1327104S( 72 , 216 )+1363968S( 216 , 432 )+1327104S( 432 , 36 ) (5.6) 35 421 421 211 211 47 47 53 +9206784S( 72 , 864 )+9216000S( 864 , 432 )+9206784S( 432 , 96 )+9020160S( 96 , 108 ) 53 637 637 319 319 71 71 95 +9167616S( 108 , 1296 )+9171712S( 1296 , 648 )+9167616S( 648 , 144 )+9084672S( 144 , 192 ) 95 107 107 191 191 383 383 767 +9038016S( 192 , 216 )+7978176S( 216 , 384 )+7966512S( 384 , 768 )+7963596S( 768 , 1536 ) 767 1 +7962867S( 1536 , 2 ).

We may compute each sum Sp−3(x, y) in the same manner as the Wolstenholme search, employing the same polynomial method by computing the linear and con- Q 2 stant coefficients of the polynomial xp 2 · 1010. Our searches found no new Vandiver primes larger than p = 1062232319. Table 3 9 10 records the primes p with 10 < p < 4·10 where |hEp−3ip| < 50; a Vandiver prime p has hEp−3ip = 0. Computations were again completed at NCI Australia, where near 4 · 1010 a single prime can be tested using this method in approximately 195 milliseconds using (5.6). As with the Bernoulli numbers, we observe no particular bias among the values of Ep−3 mod p. Figure 2 displays a histogram with 2000 equal-sized bins for the 10 values of hEp−3ip/p over the 1711955431 primes p with 5 ≤ p < 4 · 10 . WOLSTENHOLME AND VANDIVER PRIMES 19

9 10 Table 3. Primes p ∈ (10 , 4 · 10 ) for which |hEp−3ip| < 50.

p hEp−3ip p hEp−3ip 1062232319 0 10158743171 −49 1348936931 17 10179358499 −12 1352698411 −17 14884379297 −40 1836806681 −15 17380814081 5 2114780851 2 18044797027 −10 2161739347 −32 18642203467 34 2264214119 38 23177794127 −48 2978890751 35 36830964851 6 3700821251 23 36652898767 −9

10 Figure 2. Histogram for hEp−3ip/p for p < 4 · 10 .

�������

�������

�������

�������

�������

-��� -��� ��� ��� ���

6. The transformation graph While not directly applicable to the search for Wolstenholme and Vandiver primes, this section is devoted to developing ideas of the Tanner and Wagstaff machinery that generates new congruence relations for Bernoulli numbers and Eu- ler numbers. These congruence relations are crucial to the aforementioned search and any insight into their derivation could be useful in future work. We define a derived congruence relation as one that is generated from another congruence relation of the type (2.4) using the transformations of Proposition 2.1— separation, reflection, and subdivision. To conveniently represent these transforma- tions, we will denote separation by σf , where 0 ≤ f ≤ 1 denotes the fraction by which we split the interval into two, i.e., if 0 ≤ x < y ≤ 1, then a transformation σf applied on S`(x, y) will result in

S`(x, y) = S` (x, x + f · (y − x)) + S` (x + f · (y − x), y) .

Similarly, reflection is denoted by ρ and subdivision into d terms is denoted by τd. We will also use ι to denote the identity transformation which will be used only to indicate termination of a chain of transformations. Starting from (2.4), we can draw a tree of transformations corresponding to each of the β := bb/2c terms, where identity/terminal (ι), separation (σf ), reflection (ρ), and subdivision (τd) result in one, two, one, and d branches, respectively. The 20 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

Figure 3. The transformation graph for (2.9). 1 1 1 2 ( 6 , 5 ) ( 3 , 5 ) τ3 τ2

( 1 , 1 ) 7 2 3 11 2 7 18 15 ( 18 , 5 ) ( 18 , 15 ) 1 1 ( 3 , 10 ) ( 6 , 5 ) σ1/2 τ2 ρ ρ

1 11 11 1 7 1 ( 25 , 7 ) 4 5 ( 3 , 1 ) ( 18 , 180 ) ( 180 , 15 ) ( 36 , 5 ) 36 10 ( 15 , 18 ) 10 3 ι ι ι ρ τ2 σ1/6

3 11 2 5 ( 19 , 23 ) 3 11 11 1 ( 10 , 36 ) ( 5 , 36 ) 30 36 ( 10 , 36 ) ( 36 , 3 ) ι ι ρ ι τ5

13 11 11 1 47 4 83 7 ( 119 , 2 ) ( 155 , 13 ) ( 36 , 30 ) ( 180 , 15 ) ( 180 , 15 ) ( 180 , 15 ) 180 3 180 15 ι ι ι ι ρ ρ

1 61 2 5 ( 3 , 180 ) ( 15 , 36 ) ι ι union of the β trees will be referred to as a transformation graph. This graph can be traversed in a depth-first-search manner, sequentially from the first tree to the βth tree, to give a unique string identifying the series of transformations. For example, Figure 3 depicts the transformations needed to derive (2.9) from (2.4) with b = 5 in the form of a graph with two trees corresponding to the two terms in the original congruence relation. The string of transformations corresponding to this is     τ3σ 1 ιιτ2ιριρτ2ιρι τ2τ3σ 1 ιιτ2ιριρτ2ιριρσ 1 ιτ5ιιιριρι . 2 2 6 The final congruence (2.9) can be obtained by merging the leaf nodes, after multi- plying them by the appropriate coefficients. Using the idea of a transformation graph, we can now prove a basic bound relating to the question posed by Tanner and Wagstaff in [27] on the existence of congruences with cost less than p. Assume that the desired cost of a derived congruence is less than or equal to p and the least number of terms possible for such a congruence is T . Here, a term is an expression of the form αS`(x, y) in the derived congruence, α being the appropriate coefficient generated during the transformations. Let the total number of leaf nodes (which are then merged into T terms) in the transformation graph be T 0. The derived congruence has the form

T X Ck(2, b, b + 1)B2k ≡ αiS2k−1(xi, yi) mod p. i=1 1 PT Since the desired cost is at most p, we have i=1(yi − xi) ≤  and therefore,

yi − xi ≤  (6.1) for each i and  y − x ≤ (6.2) j j T for some j. Trivially, T 0 ≥ β. The cost of each term in (2.4) is mp/b(b + 1). If mp/b(b + 1) > p, we need to apply a string of transformations to obtain terms with reduced cost. Among the various transformations, only separation and subdivision yield terms with lower cost than the original. To reduce the cost of each term while generating the least number of extra terms, it is clear that one cannot do better than applying WOLSTENHOLME AND VANDIVER PRIMES 21 a single subdivision operation, τd(m), such that (from (6.1)) mp ≤ p, b(b + 1)n(m) where d(m) is an integer depending on m. The value d(m) might be interpreted as the number of leaf nodes in the mth tree corresponding to the mth term of (2.4). Note that other sequences of transformations might exist that generate the same number of terms with the required cost but for our purposes, this assumption is sufficient. Therefore, we obtain d(m) ≥ m/b(b + 1). In other words, dm/b(b + 1)e is a lower bound on the number of branches (and hence, leaf nodes) that need to be generated in each tree in order to satisfy (6.1). Therefore, β X  m   β(β + 1)  T 0 ≥ ≥ max β, . (6.3) b(b + 1) 2b(b + 1) m=1

From (6.2), we know that for some m0, we have d(m0) ≥ m0T/b(b + 1), or d(m )b(b + 1) T ≤ 0 ≤ Nb(b + 1) (6.4) m0 where N := max{d(m)} is the maximum number of leaf nodes in any tree in the m graph. In fact, we can refine (6.3) slightly:  β(β − 1)  T 0 ≥ max β − 1 + N, + N . (6.5) 2b(b + 1) Combining (6.4) and (6.5) yields the following result. T Nb(b + 1) Proposition 6.1. ≤ . T 0 n β(β−1) o max β − 1 + N, 2b(b+1) + N The fraction T/T 0 is the ratio of distinct leaf nodes to all leaf nodes, so Proposi- tion 6.1 implies that, depending on b, N, and , a certain proportion of leaf nodes must occur more than once. In particular, for fixed b and N, as  → 0+ the ratio T/T 0 approaches 0.

Acknowledgements We thank Karl Dilcher, Lars Hesselholt, and Richard McIntosh for helpful corre- spondence. We also thank NCI Australia and UNSW Canberra for computational resources. This research was undertaken with the assistance of resources and ser- vices from the National Computational Infrastructure (NCI), which is supported by the Australian Government.

References [1] C. Aebi and G. Cairns, Wolstenholme again, Elem. Math. 70 (2015), no. 3, 125–130. MR3372069 [2] T. Agoh, Congruences related to the Ankeny-Artin-Chowla conjecture, Integers 16 (2016), paper no. A12, 30 pp. MR3475253 [3] J. Buhler, R. Crandall, R. Ernvall, and T. Mets¨ankyl¨a, Irregular primes and cyclotomic invariants to four million, Math. Comp. 61 (1993), no. 203, 151–153. MR1197511 [4] L. Carlitz, Note on irregular primes, Proc. Amer. Math. Soc. 5 (1954), 329–331. MR61124 [5] J. B. Cosgrave and K. Dilcher, On a congruence of Emma Lehmer related to Euler numbers, Acta Arith. 161 (2013), no. 1, 47–67. MR3125151 22 SHEHZAD HATHI, MICHAEL J. MOSSINGHOFF, AND TIMOTHY S. TRUDGIAN

[6] H. M. Edwards, Fermat’s Last Theorem: A Genetic Introduction to Algebraic Number The- ory, Grad. Texts in Math., vol. 50, Springer, New York, 1996. MR1416327 [7] R. Ernvall, Corrigenda: “Cyclotomic invariants and E-irregular primes”, Math. Comp. 33 (1979), no. 145, 433. MR514840 [8] R. Ernvall and T. Mets¨ankyl¨a, Cyclotomic invariants and E-irregular primes, Math. Comp. 32 (1978), no. 142, 617–629. MR482273 [9] A. Gardiner, Four problems on divisibility, Amer. Math. Monthly 95 (1988), no. 10, 926–931. MR1581615 [10] J. W. L. Glaisher, Congruences relating to the sums of products of the first n numbers and to other sums of products, Quart. J. Pure Appl. Math. 31 (1900), 1–35. [11] , On the residues of the sums of products of the first p − 1 numbers, and their powers, to modulus p2 or p3, Quart. J. Pure Appl. Math. 31 (1900), 321–353. [12] , On the residues of the sums of the inverse powers of numbers in arithmetic progres- sion, Quart. J. Pure Appl. Math. 32 (1901), 271–305. [13] M. Gut, Euler’sche Zahlen und Klassenanzahl des K¨orpers der 4`-ten Einheitswurzeln, Com- ment. Math. Helv. 25 (1951), 43–63. MR41173 [14] W. Hart, D. Harvey, and W. Ong, Irregular primes to two billion, Math. Comp. 86 (2017), no. 308, 3031–3049. MR3667037 [15] W. Johnson, Irregular primes and cyclotomic invariants, Math. Comp. 29 (1975), 113–120. MR376606 [16] E. Lehmer, On congruences involving Bernoulli numbers and the quotients of Fermat and Wilson, Ann. of Math. (2) 39 (1938), no. 2, 350–360. MR1503412 [17] F. Luca, A. Pizarro-Madariaga, and C. Pomerance, On the counting function of irregular primes, Indag. Math. (N.S.) 26 (2015), no. 1, 147–161. MR3281697 [18] R. J. McIntosh, On the converse of Wolstenholme’s theorem, Acta Arith. 71 (1995), no. 4, 381–389. MR1339137 [19] , Congruences involving Euler numbers and power sums, Fibonacci Quart. 58 (2020), no. 4, 328–333. [20] R. J. McIntosh and E. L. Roettger, A search for Fibonacci-Wieferich and Wolstenholme primes, Math. Comp. 76 (2007), no. 260, 2087–2094. MR2336284 [21] R. Meˇstrovi´c, Wolstenholme’s theorem: its generalizations and extensions in the last hundred and fifty years (1862–2012) (25 Dec. 2011), 31 pp. arXiv.1111.3057v2. [22] R. Meˇstrovi´c, A search for primes p such that the Euler number Ep−3 is divisible by p, Math. Comp. 83 (2014), no. 290, 2967–2976. MR3246818 [23] J. L. Selfridge and B. W. Pollack, Fermat’s last theorem is true for any exponent up to 25,000, Notices Amer. Math. Soc. 11 (1964), no. 1, 97. Abstract no. 608-138, Annual Meeting in Miami and Coral Gables, FL, Jan. 23-26, 1964. [24] E. T. Stafford and H. S. Vandiver, Determination of some properly irregular cyclotomic fields, Proc. Natl. Acad. Sci. USA 16 (1930), no. 2, 139–150. [25] Z.-H. Sun, Congruences involving Bernoulli and Euler numbers, J. Number Theory 128 (2008), no. 2, 280–312, DOI 10.1016/j.jnt.2007.03.003. MR2380322 [26] Z.-W. Sun, Super congruences and Euler numbers, Sci. China Math. 54 (2011), no. 12, 2509– 2535. MR2861289 [27] J. W. Tanner and S. S. Wagstaff Jr., New congruences for the Bernoulli numbers, Math. Comp. 48 (1987), no. 177, 341–350. MR866120 [28] J. V. Uspensky and M. A. Heaslet, Elementary Number Theory, McGraw-Hill, New York, 1939. MR0000236 [29] A. J. Van Der Poorten, H. J. J. te Riele, and H. C. Williams, Computer verification of the Ankeny-Artin-Chowla conjecture for all primes less than 100 000 000 000, Math. Comp. 70 (2001), no. 235, 1311–1328. Corrigenda and addition, ibid. 72 (2003), no. 241, 521–523. MR1709160 and MR1933835 [30] H. S. Vandiver, On Bernoulli’s numbers and Fermat’s last theorem, Duke Math. J. 3 (1937), no. 4, 569–584. MR1546011 [31] , Note on Euler number criteria for the first case of Fermat’s last theorem, Amer. J. Math. 62 (1940), 79–82. MR1231 [32] S. S. Wagstaff Jr., The irregular primes to 125000, Math. Comp. 32 (1978), no. 142, 583–591. MR491465 WOLSTENHOLME AND VANDIVER PRIMES 23

[33] L. C. Washington, Introduction to Cyclotomic Fields, 2nd ed., Grad. Texts in Math., vol. 83, Springer, New York, 1997. MR1421575 [34] J. Wolstenholme, On certain properties of prime numbers, Quart. J. Pure Appl. Math. 5 (1862), 35–39.

School of Science, The University of New South Wales, Canberra, Australia Email address: [email protected]

Center for Communications Research, Princeton, NJ, USA Email address: [email protected]

School of Science, The University of New South Wales, Canberra, Australia Email address: [email protected]