% pyth0805.tex For Jour. Int. Seq. Sept 1,2001 \documentclass{amsart} \usepackage[colorlinks=true, linkcolor=webgreen, filecolor=webbrown, citecolor=webgreen]{hyperref} \usepackage{psfig,epsf} \newtheorem{theorem}{Theorem}[section] \newtheorem{lemma}[theorem]{Lemma} \theoremstyle{definition} \newtheorem{definition}[theorem]{Definition} \newtheorem{example}[theorem]{Example} \newtheorem{xca}[theorem]{Exercise} \theoremstyle{remark} \newtheorem{remark}[theorem]{Remark} \numberwithin{equation}{section} % Absolute value notation \newcommand{\abs}[1]{\lvert#1\rvert} % Blank box placeholder for figures (to avoid requiring any % particular graphics capabilities for printing this document). \newcommand{\blankbox}[2]{% \parbox{\columnwidth}{\centering % Set fboxsep to 0 so that the actual size of the box will match the % given measurements more closely. \setlength{\fboxsep}{0pt}% \fbox{\raisebox{0pt}[#2]{\hspace{#1}}}% }% } \begin{document} %For submitting manuscript add next 2 lines %\hoffset -.5 in %\hsize 6 in \begin{center} \epsfxsize=4in \leavevmode\epsffile{logo23.eps} \vskip 1cm {\LARGE\bf Prime Pythagorean triangles} \vskip 1.5cm \large Harvey Dubner \\ \smallskip 449 Beverly Road, Ridgewood, New Jersey 07450 \\ \medskip Tony Forbes \\ \smallskip Department of Pure Mathematics, The Open University, Walton Hall, Milton Keynes MK7 6AA, United Kingdom \\ \medskip Email addresses: \href{mailto:hdubner1@compuserve.com}{hdubner1@compuserve.com} and \href{mailto:tonyforbes@ltkz.demon.co.uk}{tonyforbes@ltkz.demon.co.uk} \vskip2.5cm {\bf Abstract} \end{center} {\em A prime Pythagorean triangle has three integer sides of which the hypotenuse and one leg are primes. In this article we investigate their properties and distribution. We are also interested in finding chains of such triangles, where the hypotenuse of one triangle is the leg of the next in the sequence. We exhibit a chain of seven prime Pythagorean triangles and we include a brief discussion of primality proofs for the larger elements (up to 2310 digits) of the associated set of eight primes. } \vspace*{+.1in} \noindent 1991 {\it Mathematics Subject Classification}: Primary 11A41 \noindent {\it Keywords}: Pythagorean triangles, prime numbers, primality proving \section{Introduction} While investigating the distribution of special forms of primes, the first author accidently came across a conjecture about Pythagorean triangles (right triangles with integral sides). The conjecture, based on the famous Conjecture (H) of Sierpi\'nski and Schinzel, states that there is an infinite number of Pythagorean triangles which have a leg and hypotenuse both prime \cite[page 408]{Rib95}. Pythagorean triangles have been the subject of much recreational material \cite{AB66} as well as the basis of some of the most important and fundamental topics in number theory. However, we could not find any significant references to such two-prime Pythagorean triangles, and hoping that we had found a new topic to study we enthusiastically started \begin{enumerate} \item developing appropriate theory and computer programs; \item searching for large two-prime triangles; \item searching for sequences of two-prime triangles where the hypotenuse of the previous triangle becomes the leg of the next one. \end{enumerate} The largest two-prime Pythagorean triangle that was found had a leg of 5357 digits and an hypotenuse of 10713 digits. It soon became apparent that finding sequences of triangles was exceptionally interesting and challenging. Eventually a sequence of seven triangles was found. More significant than the seven triangles is the improvement by the second author of the general method, APRCL, for primality proving so that the seventh hypotenuse of 2310 digits could be proved prime. \section{Theory} A two-prime Pythagorean triangle, $A^2+B^2=C^2$, must be primitive, so that \begin{equation*} A=u^2-v^2, \qquad B=2uv, \qquad C=u^2+v^2, \end{equation*} with $\gcd(u,v)=1$, and $u,v$ of different parity. Since $A=(u+v)(u-v)$, for $A$ to be prime it is necessary that $(u-v)=1$ so that \begin{equation*} A=2v+1, \qquad B=2v^2+2v, \qquad C=2v^2+2v+1. \end{equation*} Thus \begin{equation} C=\frac{A^2+1}{2}. \end{equation} Note that the even leg is only one less than the hypotenuse. The triangles get quite thin as $A$ increases. To find two-prime Pythagorean triangles it is necessary to find pairs of primes $A,C$ that satisfy the above equation. Table 1 lists the smallest two-prime Pythagorian triangles. \begin{table}[htb] \caption{Pythagorean triangles with two prime sides} \label{tab:1} \begin{tabular}{|r|*3{r}|} \hline rank& prime leg& even leg& hypotenuse\\ \hline 1& 3& 4& 5\\ 2& 5& 12& 13\\ 3& 11& 60& 61\\ 4& 19& 180& 181\\ 5& 29& 420& 421 \\ 6& 59& 1740& 1741\\ 7& 61& 1860& 1861 \\ 8& 71& 2520& 2521\\ 9& 79& 3120& 3121\\ 10& 101& 5100& 5101\\ \hline 100& 4289& 9197760& 9197761\\ \hline 1000& 91621& 4197203820& 4197203821 \\ \hline \end{tabular} \end{table} Small triangles are easy to find by a simple search, but finding large triangles with thousands of digits is complicated by the difficulty of proving true primality of the hypotenuse, $C$. However, if $(C-1)$ has many factors then it is easy to prove primality using \cite{BLS75}, assuming that the factored part of $(C-1)$ exceeds $\root 3 \of C$. Since \begin{equation} C-1=\frac{A^2+1}{2}-1=(A^2-1)/2=(A-1)(A+1)/2, \end{equation} by picking an appropriate form for $A$, then $(A-1)$ can be completely factored so that $(C-1)$ will be about 50\% factored. Using the form $A=k\cdot 10^n +1$, a computer search of a few days gave the following large triangle: \begin{equation*} A=491140 \cdot 10^{1300}+1, \text{\quad 1306 digits,\qquad $C=2612$ digits.} \end{equation*} A few days after this result was posted to the NMBRTHRY list we received a message from Iago Camboa announcing a much larger triangle: \begin{equation*} A=1491 \cdot 2^{17783}+1, \text {\quad 5357 digits, \qquad $C=10713$ digits.} \end{equation*} He cleverly used a previously computed list of primes as a source for $A$ thus eliminating the large amount of time required to find the first prime. \section{Two-prime Pythagorean triangle sequences} It is possible to find a series of primes, $P_0, P_1, P_2, ..., P_k, ..., P_n$ such that \begin{equation} P_{k+1}=\frac{P_k^2+1}{2}. \end{equation} This represents a sequence of $n$ two-prime triangles where $P_k$ is the hypotenuse of the $k$-th triangle and the leg of the $(k+1)$-th triangle. Each $P$ has about twice the number of digits as the previous $P$. Table 2 is a list of the smallest sets of two sequential prime Pythagorean triangles. \begin{table}[htb] \caption{Two sequential prime Pythagorean triangles} \label{tab:2} \begin{tabular}{|r|*3{r}|*3{r}|} \hline & \multicolumn{3}{c|}{triangle 1} & \multicolumn{3}{c|}{triangle 2}\\ \hline 1& 3& 4& 5& 5& 12& 13\\ 2& 11& 60& 61& 61& 1860& 1861\\ 3& 19& 180& 181& 181& 16380& 16381\\ 4& 59& 1740& 1741& 1741& 1515540& 1515541\\ 5& 271& 36720& 36721& 36721& 674215920& 674215921\\ 6& 349& 60900& 60901& 60901& 1854465900& 1854465901\\ 7& 521& 135720& 135721& 135721& 9210094920& 9210094921\\ 8& 929& 431520& 431521& 431521& 93105186720& 93105186721\\ \hline \end{tabular} \end{table} Table 3 is a list of the starting primes for the smallest prime Pythagorean sequences for two, three, four and five triangles. These were found by straight forward unsophisticated searching and took about 10 computer-days (Pentium/200), mostly for finding five triangles. \begin{table}[htb] \caption{Starting prime for smallest prime Pythagorean sequences} \label{tab:3} \begin{tabular}{|r|r|r|r|r|} \hline &2 triangles& 3 triangles& 4 triangles& 5 triangles\\ \hline 1& 3& 271& 169219& 356498179 \\ \hline 2& 11& 349& 1370269& 432448789\\ \hline 3& 19& 3001& 5965699& 5380300469 \\ \hline 4& 59& 10099& 15227879& 10667785241 \\ \hline 5& 271& 11719& 17750981& 11238777509\\ \hline 6& 349& 12281& 19342559& 12129977791\\ \hline 7& 521& 25889& 21828601& 23439934621\\ \hline 8& 929& 39901& 24861761& 28055887949\\ \hline 9& 1031& 46399& 27379621& 33990398249\\ \hline 10& 1051& 63659& 34602049& 34250028521\\ \hline 11& 1171& 169219& 39844619& 34418992099\\ \hline 12& 2381& 250361& 48719711& 34773959159\\ \hline 13& 2671& 264169& 50049281& 34821663421\\ \hline 14& 2711& 287629& 51649019& 36624331189\\ \hline 15& 2719& 289049& 52187371& 40410959231\\ \hline 16& 3001& 312581& 52816609& 43538725229\\ \hline 17& 3499& 353081& 58026659& 47426774869\\ \hline 18& 3691& 440681& 73659239& 48700811941\\ \hline 19& 4349& 473009& 79782821& 49177751131\\ \hline 20& 4691& 502501& 86569771& 59564407571\\ \hline \end{tabular} \end{table} Finding the starting prime for the smallest prime sequence of six triangles took about 120 computer days.\\ \qquad \qquad $P_0$ for 6 triangles $=2500282512131$.\\ Next, we attempted to derive the number of $n$ triangle sequences that could be expected. If the $(n+1)$ numbers that make up the $n$ triangles were selected randomly but were of the proper size then the probability that $P$ is the start of $n$ triangles is \begin{equation} Q(P,n)=\prod_0^n \frac{1}{\log P_i}=\prod_0^n \frac{1}{2^i(\log P)} =\frac{1}{2^{n(n+1)/2}(\log P)^{n+1}}. \end{equation} However, there are correlations between the primes that affect the prime probabilities. It is easy to show from equation (2.1) that $P_0$ can only end in 1 or 9, which elininates half the possible $P_0$'s, and assures that all subsequent potential primes cannot be divisible by 2, 3 or 5. Thus, the probability of each subsequent number being prime is increased by the factor $(2/1)(3/2)(5/4)=3.75$. The probability that $P$ is the start of $n$ prime triangles now becomes, \begin{equation} Q(P,n)=\frac{0.5(3.75)^n}{2^{n(n+1)/2}(\log P)^{n+1}}. \end{equation} The expected number of prime triangles up to a given $P_0$ is \begin{equation} E(P_0,n)=\sum_{P=3}^{P_0} Q(P,N) =\frac{0.5(3.75)^n}{2^{n(n+1)/2}} \sum_{P=3}^{P_0}\frac{1}{(\log P)^{n+1}}. \end{equation} The last summation can be approximated by an integral, which after integrating by parts becomes, \begin{equation*} R(P,n)=\frac{1}{n!}Li(P) -\frac{1}{n!}\frac{P}{\log P}-\dots-\frac{1}{n(n-1)}\frac{P}{(\log P)^{(n-1)}} -\frac{1}{n}\frac{P}{(\log P)^n}, \end{equation*} where $Li(P)$ is the logarithmic integral. Equation (3.4) now becomes \begin{equation} E(P_0,n)=\frac{0.5(3.75)^n}{2^{n(n+1)/2}}R(P_0,n)(1.3)^n \ . \end{equation} Note the inclusion of a correction factor, $(1.3)^n$. As is discussed in the following section on sieving, there are other correlations between the primes which affect the expectation. These are difficult to derive theoretically so we determined it empirically. Table 4 compares the estimated and actual number of triangles found. The corrected estimate appears adequate to assist in estimating the search time for seven prime Pythagorean triangles. \begin{table}[htb] \caption{Estimated and actual number of prime Pythagorean triangles} \label{tab:4} \begin{tabular}{|c|r{r}{r}r|} \hline triangles& & & & corrected\\ $n$& $P_0 \quad $& actual& estimate& estimate\\ \hline 1& 130000& 1302& 1090& 1420\\ 2& 1980000& 1005& 741& 1252\\ 3& $10^8$& 953& 469& 1030\\ 4& $18\cdot 10^8$& 205& 53& 151\\ 5& $63\cdot 10^9$& 21& 4& 15\\ 6& $28\cdot 10^{12}$& 1& 0.14& 0.7\\ \hline \end{tabular} \end{table} Next, we use equation (3.5) to estimate the smallest $P_0$ that will give seven triangles. The following table shows we can expect that $P_0$ for seven triangles will be about 6700 times larger than $P_0$ for six triangles. Using performance data from the search for six triangles, this means that the search for the smallest sequence of seven prime Pythagorean triangles could be expected to take about 200 computer-years! \begin{center} \begin{tabular}{|c|l|l|} \hline $n$ & $P_0$ for expectation=1 & actual $P_0$\\ \hline 2 & 28 & 3\\ 3 & 1,350 & 271\\ 4& 1,000,000& 169, 219\\ 5& $1.5\cdot 10^9$& $3.5\cdot 10^8$ \\ 6& $4.0\cdot 10^{12}$& $2.5\cdot 10^{12}$\\ 7& $2.7\cdot 10^{16}$& \\ \hline \end{tabular} \end{center} It was clear that the search for the smallest sequence of seven triangles as presently constituted was impractical. For every $P_0$ the search method included testing by division to see if each of the $(n+1)$ potential primes was free of small factors. The second author then proposed an efficient sieving method that limited the search to sequences that had a high probability of success. This made a search for seven triangles reasonable. \section{The Sieve} A set of seven Pythagorean triangles with the desired properties is equivalent to a chain of eight primes, $P_{0}, P_{1}, \dotsc, P_{7}$, linked by the condition $P_{i+1}= ( P_{i}^{2}+1 )/2$, $i = 0, 1, \dotsc, 6$. The purpose of the sieve is to eliminate from further consideration numbers $P_{0}$ for which either $P_{0}$ itself or one of the numbers $P_{i}$, $i = 1, 2, \dotsc, 7$, is divisible by a small prime. Let $q$ be an odd prime and suppose $P$ is to be considered as a possible value of $P_{0}$. Clearly, we can reject $P$ if $P \equiv 0 \pmod q$. Furthermore, we can reject $P$ if $P_{1}$ is divisible by $q$, that is, if \begin{equation*} P \equiv \sqrt{-1}\pmod q , \end{equation*} on the assumption that $\left(\frac{-1}{q}\right) = 1$. Continuing in this way, we can reject $P$ if \begin{equation*} P \equiv \sqrt{2\sqrt{-1}-1} \pmod q \end{equation*} (for then $P_{2}$ is divisible by $q$), or if \begin{equation*} P \equiv \sqrt{2\sqrt{2\sqrt{-1}-1}-1} \pmod q, \end{equation*} and so on, provided that the various square roots $\pmod q$ exist. In each case, where there is a square root $\pmod q$ there are two possible values and hence two extra residues $\pmod q$ that can be eliminated. For prime $q$, we compute the set $E(q)$ of forbidden residues $\pmod q$ as follows. Start with $E_{0}(q) = \{0\}$. Given $E_{i}(q)$, let \begin{equation*} E_{i+1} = \left\{ \pm\sqrt{2e-1}\pmod q: e \in E_{i} \: {\rm and} \: \left( \frac{2e-1}{q} \right) = 1 \right\}. \end{equation*} Then $E(q)$ is the union of $E_{0}(q)$, $E_{1}(q)$, $\dotsc$, $E_{7}(q)$. In Table~\ref{tab:eq} we list $E(q)$ for the first few primes $q \equiv 1 \pmod 4$. \begin{table}[htb] \caption{$E(q)$} \label{tab:eq} \begin{tabular}{|r|c|} \hline $q$ & $E(q)$\\ \hline 5 & \{0, 2, 3\} \\ \hline 13 & \{0, 3, 5, 8, 10\} \\ \hline 17 & \{0, 3, 4, 5, 12, 13, 14\} \\ \hline 29 & \{0, 2, 3, 5, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 24, 26, 27\} \\ \hline 37 & \{0, 6, 8, 14, 23, 29, 31\} \\ \hline 41 & \{0, 9, 32\} \\ \hline 53 & \{0, 4, 14, 16, 17, 18, 19, 22, 23, 30, 31, 34, 35, 36, 37, 39, 49\} \\ \hline 61 & \{0, 11, 50\} \\ \hline 73 & \{0, 23, 27, 46, 50\} \\ \hline 89 & \{0, 9, 26, 27, 30, 34, 37, 38, 39, 40, 41, 44, 45, 48, 49, 50, 51, 52, \\ & 55, 59, 62, 63, 80\} \\ \hline 97 & \{0, 7, 22, 25, 72, 75, 90\} \\ \hline 101 & \{0, 7, 10, 12, 15, 16, 22, 23, 25, 26, 34, 35, 37, 38, 50, 51, 63, 64, \\ & 66, 67, 75, 76, 78, 79, 85, 86, 89, 91, 94\} \\ \hline 109 & \{0, 33, 76\} \\ \hline 113 & \{0, 2, 15, 46, 54, 59, 67, 98, 111\} \\ \hline 137 & \{0, 22, 37, 100, 115\} \\ \hline 149 & \{0, 44, 105\} \\ \hline 157 & \{0, 10, 28, 31, 126, 129, 147\} \\ \hline 173 & \{0, 32, 80, 93, 141\} \\ \hline 181 & \{0, 2, 9, 19, 30, 33, 41, 47, 54, 56, 64, 78, 80, 88, 93, 101, 103, 117, \\ & 125, 127, 134, 140, 148, 151, 162, 172, 179\} \\ \hline 193 & \{0, 57, 81, 112, 136\} \\ \hline 197 & \{0, 14, 37, 94, 103, 160, 183\} \\ \hline 229 & \{0, 18, 19, 30, 48, 54, 59, 69, 91, 107, 110, 119, 122, 138, 160, 170, \\ & 175, 181, 199, 210, 211\} \\ \hline 233 & \{0, 3, 5, 7, 12, 13, 16, 21, 25, 27, 30, 42, 43, 44, 48, 52, 53, 55, 61, \\ & 67, 71, 80, 85, 89, 101, 104, 115, 118, 129, 132, 144, 148, 153, 162, 166, \\ & 172, 178, 180, 181, 185, 189, 190, 191, 203, 206, 208, 212, 217, 220, 221, \\ & 226, 228, 230\} \\ \hline 241 & \{0, 64, 177\} \\ \hline 257 & \{0, 16, 51, 206, 241\} \\ \hline 269 & \{0, 82, 187\} \\ \hline 277 & \{0, 8, 52, 60, 106, 171, 217, 225, 269\} \\ \hline 281 & \{0, 53, 228\} \\ \hline 293 & \{0, 4, 121, 138, 155, 172, 289\} \\ \hline 313 & \{0, 7, 21, 25, 92, 221, 288, 292, 306\} \\ \hline 317 & \{0, 17, 23, 24, 31, 44, 50, 52, 56, 74, 97, 114, 115, 126, 130, 134, \\ & 141, 142, 145, 153, 164, 172, 175, 176, 183, 187, 191, 202, 203, 220, 243, \\ & 261, 265, 267, 273, 286, 293, 294, 300\} \\ \hline 337 & \{0, 21, 31, 34, 50, 71, 73, 90, 110, 114, 116, 144, 148, 153, 157, 162, \\ & 175, 180, 184, 189, 193, 221, 223, 227, 247, 264, 266, 287, 303, 306, 316\} \\ %\hline %349 & \{0, 8, 10, 12, 16, 18, 20, 23, 26, 27, 39, 46, 57, 63, 74, 80, 84, 102, \\ % & 108, 109, 111, 115, 120, 121, 124, 133, 135, 136, 139, 142, 152, 163, 164, \\ % & 185, 186, 197, 207, 210, 213, 214, 216, 225, 228, 229, 234, 238, 240, 241, \\ % & 247, 265, 269, 275, 286, 292, 303, 310, 322, 323, 326, 329, 331, 333, 337, \\ % & 339, 341\} \\ %\hline %353 & \{0, 14, 18, 29, 35, 42, 57, 68, 78, 89, 93, 140, 141, 212, 213, \\ % & 260, 264, 275, 285, 296, 311, 318, 324, 335, 339\} \\ %\hline %373 & \{0, 4, 10, 22, 56, 58, 61, 104, 110, 136, 178, 195, 237, 263, 269, \\ % & 312, 315 317 351 363 369\} \\ %\hline %389 & \{0, 115, 274\} \\ %\hline %397 & \{0, 42, 51, 63, 103, 110, 120, 144, 152, 155, 159, 238, 242, 245, \\ % & 253 277 287 294 334 346 355\} \\ \hline \end{tabular} \end{table} Now let \begin{equation*} P = NQ+H, \end{equation*} where $Q$ is the product of small primes and $H$ is allowed to run through all the permitted residues $\pmod Q$. We sieve the numbers $N$. That is, we start with an interval $N_{0} \leq N < N_{1}$ and for each sieving prime $q$, $\gcd (q, Q) = 1$, we remove all those $N \in [ N_{0} , N_{1})$ for which $NQ+H$ is divisible by $q$. We split $Q$ into pairwise coprime divisors $m_{0}$, $m_{1}$, $\dotsc$, $m_{r}$. For each divisor $m_{j}$ of $Q$, $j = 0, 1, \dotsc, r$, we make a list of the permitted residues $\pmod{m_j}$; $h$ is a permitted residue $\pmod{m_j}$ if $h$ is not zero $\pmod{m_j}$ and if the function $h \rightarrow (h^{2}+1)/2 \pmod{m_j}$ does not produce zero $\pmod{m_j}$ during the first seven iterations. The permitted residues $H \pmod Q$ are constructed from permitted residues $h \pmod{m_j}$ using the Chinese Remainder Theorem. It works well if $Q$ is the product of primes which have small percentages of permitted residues. From this perspective the best primes, in descending order of merit, turn out to be: 29 (34\%), 5 (40\%), 2 (50\%), 17 (59\%), 13 (62\%), 3 (67\%), 53 (68\%), 101 (71\%), 89 (74\%) and 233 (77\%). For the actual search we chose $Q=21342962305470$, with divisors 6630 = $2 \cdot 3 \cdot 5 \cdot 13 \cdot 17$, 29, 89, 101, 53, and 233. The number of values of $H \pmod Q$ turns out to be $320 \cdot 10 \cdot 66 \cdot 72 \cdot 36 \cdot 180$ = 98537472000, the indicated factors of this product being the numbers of permitted residues modulo the corresponding factors of $Q$. The construction of the sieve and the method of computing $H \pmod Q$ were based on computer programs designed for finding prime $k$-tuplets; see \cite{Forbes99} for the details. We set up a table of sieving primes $q$ together with pre-computed values of $-1/Q \pmod q$ as well as, for $q \equiv 1 \pmod 4$, $e/Q \pmod q$ for each pair $e$, $q-e$ in $E(q)$. We can then rapidly calculate the index of the first $N$ to be removed from the sieve array for $P \equiv e \pmod q$: $e/Q - H/Q - N_{0} \pmod q$. The program also allows us to limit the size of primes $q \equiv 3 \pmod 4$ used by the sieve. One reason for doing so would be to give priority to primes $q \equiv 1 \pmod 4$; they have more residues for sieving and therefore one would expect them to be in some sense more efficient. In fact it was found by experiment that if $P$ has about 19 digits, a sieve limit $L_{0} = 20000$ for $q \equiv 3 \pmod 4$ and 480000 for $q \equiv 1 \pmod 4$ was approximately optimal. Further performance improvements are possible by limiting the influence of primes $q \equiv 1 \pmod 4$. For each $P$ that survives the sieve we do a probable-primality test, $2^{P} \equiv 2 \pmod P$, on $P$ as well as, if $P$ turns out to be a probable-prime, the numbers that follow $P$ in the chain, stopping as soon as a composite is found. The effort required to perform the probable-primality test increases by a factor of about eight as we move from $P_{i}$ to $P_{i+1}$. Therefore it might be better if priority were given to sieving primes $q$ and residues $e \pmod q$ which would eliminate composite numbers from the larger elements of the chain. For controlling the effect of primes $q \equiv 1 \pmod 4$ we provided a set of parameters $L_{1}$, $L_{2}$, $\dotsc$. If $q \equiv 1 \pmod 4$ is a sieving prime and $e \in E_{i}(q)$ then we do not use residue $e \pmod q$ for sieving unless $q