# Short shoulder matching

• Transfer
James Tanton scatters puzzles in number theory with the same generosity with which John D. Rockefeller handed out dimes. I already wrote about one of Tanton's tasks. A few weeks later, this tweet about factorials and squares attracted my attention and did not give me rest: “4! +1 = 25, the square of the number. 5! +1 = 121, also the square of a number. Can you give another example? Two more examples? ”

With a pen and paper, it’s easy to show thatnot suitable. Factorial- this ; adding , we get the number , which is not a square. (It is factorized as ) On the other hand,equally , and adding , we will get , which is equal . This gives us a very nice equation:



Continuing further, we find out that  , and are not squares of numbers. But to continue the search, we need mechanized assistance. Here is a function onJuliathat does the obvious work - calculating consecutive factorials and checking if they are on less than square:

function search_fac_sqr(maxn)
fac = big(1)                      # большие целые нужны для n > 20
for n in 1:maxn
fac *= n                        # инкрементный факториал
r = isqrt(fac + 1)              # округление sqrt в меньшую сторону
if r * r == fac + 1
println(n, "! + 1 = ", r, "^2 = ", r^2)
end
end
println("Вот и всё, ребята!")
end

Armed with this tool, let's check  for everyone from to . Here is what the program tells us:

search_fac_sqr(100)
4! + 1 = 5^2 = 25
5! + 1 = 11^2 = 121
7! + 1 = 71^2 = 5041
Вот и всё, ребята!

These are the same three cases that we have already discovered with a pen and paper - and there is nothing else on the list. In other words, among all the meanings up to only , and give squares of numbers. When I continued searching until , I got exactly the same result. The same thing happened with and . It is worth mentioning that factorial is a fairly large number of decimal places. At this point in the search, I began to run out of steam; moreover, I began to lose hope. When sequential values fails to get a single square, it is difficult to continue to hope that success can wait for us around the corner. However, I continued to persist. I got to , the factorial of which contains decimal places. In the whole set, not a single square came across.

What can we learn from this evidence - or lack thereof? Are 4, 5, and 7 the only valueswhich on square integer? Or is there somewhere else on the number line, perhaps right after my interval? Can there be infinitely many? And if so, where are they? If they are not, then why?

For my taste, the most satisfactory way to resolve these issues will be to find some principle of number theory, which guarantees that  for . I could not find such a principle, but in my dreams I can roughly imagine what the proof might look like. Suppose we get rid of part of the formula " ", and begin the search for integers such that . It turns out that this equation has only one solution, for . You should not burden your laptop with a search for greater solutions - there is simple evidence that they do not exist. In any square of an integer, all prime divisors must be present an even number of times, for example, as in . In a factorial, at least one simple divisor - the largest - is always present only once. (If you don’t understand why, readBertrand’s postulate / Chebyshev’s theorem.)

Of course, when we substitute " "into the formula, then the whole chain of reasoning falls apart. In the general case, factorizationand completely different. But maybe there is some other property , which conflicts with squareness. It may be somehow connected with congruence classes or with square remnants. From the definition of factorial, we know thatdivisible by all positive integers less than or equal to , which means that cannot bedivisible by any of these numbers (except ). This observation excludes certain types of squares, namely those that have small primes in the factorization. But for everyone square rootfar superior , therefore, there is enough space for larger divisors, as is the case with .

Here is another way worth exploring. The decimal representation of any large factorial ends with a line from created as works and among the divisors of the number. In this way, should look like



Where  stands for any decimal digit, and the next row of ends with a single . Can we find a way to prove that a number like this is never a square? Well, if the last digit would be different from , or , then the proof would be simple, but many squares end with , for example,  . If there is any algebraic consideration showing that can not be a square, then it is more subtle.

All of the above is fictional math. I mixed a few ingredients that should turn into a delicious dough, but I have no idea how to bake a pie. Maybe someone else will help me with the recipe. In the meantime, I want to have fun with an alternative hypothesis: nothing bothers be a square, besides improbability.

The pattern observed in the task  - several matches among the smallest elements of sequences, and then not a single match in many thousands of elements - is not unique to factorials and squares. Other pairs of sequences exhibit similar behavior. Triangular numbers starting with , are given by the formula . If we look for factorials that are also triangular, we get , then and finally . No more examples before does not occur.

What about factorials that are on less than a triangular number satisfying the equation ? I know the only such case: . Expanding my search a bit, I found that triangular for , after which again there are no matches until .

For another experiment, we can return to the squares of numbers and abandon factorials, replacing them with the ever-popular Fibonacci series , defined by recursion , where . Since the 1960s it was knownthat and are the only positive integer numbers that are both Fibonacci numbers and squares of integers. Looking for the Fibonacci numbers that are on less than a square, I found out that and , and there are no other cases before .

We can do the same withCatalan numbers, , one more next to a huge fan club. I found out that among the Catalan numbers there are no other squares except up to ; I do not know if anyone has proven that they do not exist. Search for cases in which , also does not give results, but there are several correspondences with low values ​​for for .

Finding similar behavior in all of these different sequences, in my opinion, changes the complexity of the task. If we discover some mysterious special property , explaining why it never corresponds to squares (for large values ), will we need to reinvent another mechanism for Fibonacci numbers and another one for Catalan numbers? Does it not seem more convincing that behind all these observations is the only common reason?

But this reason cannot betoogeneral. This is not the case when you can take any two numerical sequences and expect to see the same pattern at their intersections. Consider factorials and primes. By the very nature of factorials, not one of them is 2! = 2 cannot be a prime, but there are no obvious reasons why cannot be a prime. And indeed, for simple are nine values . Extending the boundaries of the search to , we will find seven more. Here is acomplete set of known numbersfor which is simple:



With increasing  they are found less and less, but there are no signs of a sharp limit, as in the cases considered earlier. Does this series go on indefinitely? This seems like a logical hypothesis. (For more information on this sequence, including reference materials, seeChris Caldwell'sfactorial primepage.)

My question is this: can we perceive these curious patterns as pure coincidence? Values form an infinite sequence of integers distributed along all the number line, densely located near the beginning, but becoming extremely sparse with increasing . Values form another infinite sequence, also with decreasing density, although not with such a sharp decline. It is possible that factorials coincide with squares among the smallest integers, simply because these integers are not enough to “go wild,” and some of them have to do double work. But in vast open spaces, a numerical direct factorial can wander for years - perhaps forever - without ever meeting a square.

Let me state this idea more clearly. Insofar ascannot be a square, then we know that it is somewhere between two squares; the location on the number line looks like . The distance between the endpoints of this interval is . Now choose a random number from the interval and ask whether . Exactly one value must satisfy this condition. , i.e., the probability of coincidence is , or approximately. Insofar asgrows very fast, this probability instantly tends to zero with increasing . In the chart below, this is indicated by a purple line. Notice that to purple curve almost reached . The green curve indicates the probability of a match between Fibonacci numbers and squares; the form is similar, but it "dives" from the "cliff" a little later. The Fibonacci-squares curve is approximately equal to the negative exponential function: the probability is proportional where. The factorial-squares curve is even sharper because the factorial function issuperexponential:growing faster than , for any constant .

The blue curve fixing the probability of coincidences between factorials and primes has a completely different shape. In the surrounding areathe average distance between consecutive primes is approximately equalthat grows a little faster than itself and much slower than. The probability of a match between factorials and primes is approximately equal. A continuous blue curve corresponds to this smooth approximation. The blue dots scattered next to the line are probability values ​​based on real distances between consecutive primes.

What can be done with these curves? Is it permissible to apply probability theory to these absolutely determinate sequences of numbers? I don’t know for sure. Before posing this question directly, I prefer to take a few steps back and consider a simpler model in which probability has every right to use.

Let's borrow one of the famous Jacob Bernoulli urns, which has enough space to store an infinite number of ping-pong balls. Let's start with one black and one white ball in the ballot box, then we will pull the balls randomly. Obviously, the probability of choosing black is . Put the selected ball back in the ballot box, and also add another white ball. Now there are three balls and only one of them is black, so the probability of drawing black is . Add the fourth ball, and the probability of black drops to . Continuing in the same way, we get that the probability of black on pull should be equal .

If we continue this process indefinitely - always choose a random ball, return it back and add another white ball - then what is the likelihood that we will see the black ball at least once? It will be easier to answer the corollary of this question - to calculate the probability ofneverseeing a black ball. This is an endless work, or:



If a  tends to infinity, the product tends to zero. In other words, in an endless series of attempts, the probability of never pulling out a black ball is ; this means that the probability of meeting black at least once is . ("Probability "is not exactly the same as" certainty ", but incredibly close.)

Now let's put another experiment. Again we start with one black and one white balls, but after the first pull-back cycle we add two white balls, then four white balls, and so on, so that the total number of balls in the ballot box at the stage is equal ; During this process, all but one of the balls will be white. Now the probability of never seeing a black ball is equal, or:



This product does not tend to zero, regardless of the magnitude . Nor does it seek to . The product convergesto a constant with anapproximate value  . This is strange, isn't it? Even with an endless series of pulls from the urn, we cannot be sure whether a black ball will appear or not.

These two urn experiments are not directly related to any of the matching tasks described above; they simply illustrate the range of possible outcomes. But we can create a process with an urn that imitates a probabilistic approach to the problem of factorials and squares. On stage of the urn containsballs, only one of which is black. The probability of never seeing a black ball even with an endless series of attempts is equal to



This expression converges to a value approximately equal to  . It follows that the probability of seeing a black ball at least once is , or . (No, this number is not , although close to it.) A

process with an urn reminiscent of the problem of factorials and primes gives a rather different result. Here the number of balls in the ballot box at the stage is equalagain with only one black ball. The infinite product governing the total probability is



In the numerical proof, it seems that this expression tends to zero as  to infinity (although I'm not 100% sure about this). If itreallystrives for , until the additional probability that the black ball appears sooner or later should be equal to .

Some of these results made me feel fooled, and even a little annoyed. You can call me old-fashioned, but I always thought that an infinite number of bone rolls should be enough to eliminate any doubts as to whether the pattern will appear or not. In the cruel light of infinity, I would say, everything is either forbidden or obligatory; when tends to infinity, probability or tends to , or tends to . But obviously this is not so. In the factorial urn model, the probability of never seeing a black ball is neither equal to nor and is located somewhere near . What does this mean? How should I make sure the number is correct or even check its first few digits? Performing an endless series of attempts is not enough; it is necessary to collect a statistically significant sample of endless experiments. For an accurate result, you need to conduct an endless series of endless experiments. Alas.

The urn model naturally correlates with a randomized version of the factorial-square problem, in which we look at  and choose random from the corresponding range of values. What about the original problem ? In this case, there is no random variable, and therefore it makes no sense to perform many experiments for each value . The system is deterministic. For each factorial has an exact value and it is close, or not close to the square of an integer. There are no "maybe."

However, there is a workaround that can add probabilities here. To do this, we must assume that factorials and squares constitute a kind of ergodic system in which observing a chain of events over a long period of time is similar to observing a lot of shorter chains. Suppose that factorials and squares are not related to their location on the number line — that when a factorial is between two squares, then the distance to the larger square can be considered a random variable and each possible distance has the same probability. If we adhere to this assumption, then instead of considering one valueand checking many random values we can take a single value (namely ) and considerfor many values .

Is such an ergodic assumption reasoned? Not really. It is known that some distances betweenand more likely than others, and some distances are impossible at all. However, empirical evidence indicates that such deviations should be negligible. The graph below shows the distance distribution between the factorial and the next larger square for the first values. Distances are normalized in the interval and are classified into columns. Obvious signs of displacement are imperceptible. The calculation of the mean and standard deviation of the same relative distances result in values ​​within percent of those expected with a uniform random distribution. (Expected values ​​are equal and ). If such a probabilistic approach can be taken seriously, then I can make some numerical judgments about the prospects of finding a large factorial adjacent to the square of an integer. As mentioned above, the overall probability that one or more values equal to squares, approximately equal . Thus, we should not be too surprised that three such cases are already known, namely, examples with , and . Now we can apply the same method to calculate the probability of finding at least one more case with . Let's make the question more general: “Regardless of whether we saw squares among the first values , what are the chances that we will see them after? ”To answer this question, we can simply remove the first elements from an endless product:



At  answer is approximately equal . At approximately equal . We go down the steep slope of the purple curve.

From a practical point of view, further searches for another pair of factorial squares do not look like a promising way to waste time and processor cycles. The probability of success is quickly reduced to ridiculously small numbers, such as . And yet, from a mathematical point of view, probability never disappears. Removing a finite number of terms from the front of an infinite product cannot change its convergence properties. If the original product converged to a nonzero value, the shortened version will behave the same way. Thus, we found ourselves in a canyon of maximum disappointment, in which there is no realistic way to find a reward, but the probabilities still tell us that it can exist.

I conclude this awkward essay by looking at yet another example (very advanced). Suppose we apply probabilistic reasoning to find a cube that less than a square. If we consider the exact correspondence between cubes and squares, then there are quite a lot of them - these are six degrees: . But whole solutions to the equation not so frequent. One low-value example is easy to find: , but when after and can we expect to see consecutive cube and square?

The probabilistic approach suggests that we have reasons for optimism. Compared to factorials and Fibonacci numbers, cubes grow much more slowly; their speed is polynomial, not exponential and not superexponential. As a result, the probability of finding the cube at a given distance from the square decreases much less sharply than it does foror . In the chart below is the orange curve. Notice that the orange curve lies directly below the blue, which represents the probability that is next to a prime number. The proximity of these two curves suggests that two problems — factorials adjacent to primes, cubes adjacent to squares — may belong to the same class. We already know that factorial-simple arise over and over again, possibly ad infinitum. This analogy leads us to a hunch: perhaps the coincidence of square cubes is also unlimited. If we continue to observe, we will see many more, except and .

But such a conjecture is completely false. This task has a very long history. In 1844, Eugene Catalan suggested that and are the only consecutive power values ​​among integers; this assumption wasfinally provedin 2004 by Preda Mihailescu. Euler decided the special case of squares and cubes in the eighteenth century. Thus, the probabilities have nothing to do with it.

All the questions considered in the article belong to the category of Diophantine analysis — studies of equations whose solutions must be integers. This area of ​​mathematics is notorious for problems that are easy to set but hard to solve. The Catalan hypothesis is one of the most famous examples, along with Fermat's great theorem. When the Diophantine problems are finally solved, the proofs are usually very non-elementary, they use sophisticated tools from deep areas of mathematics - algebraic geometry in the proof of the great theorem of Fermat by Andrew Wiles and Richard Taylor, circular fields in the proof of the Mihailesco hypothesis of Catalan. As far as I know, probability theory did not play a central role in any such evidence.

When I began to deal with these issues a few weeks ago, I did not expect to find a concrete solution. And my expectations were fully met! In fact, in my head the situation has become even more confusing than at the beginning. The realization that even an endless series of experiments does not necessarily provide answers to some questions deeply upsets me and makes me wonder how well I really understand probability theory. But this situation is unlikely to be rare in mathematics. I think I should get used to it already.

Update:thanks to another tip from Tanton, I realized that this task has a long history and even its name: Brokar's task, named after Henri Brokar, who published publications about it in 1876 and 1885. Ramanujan mentioned it in 1913. Erdös suggested that there are no more solutions. Marius Overholt associated it with the abc hypothesis. Bruce Berndt and William Galway find that there are no solutions before . All this I learned from anarticle about the Brokar problem on Wikipedia. This article also mentions that solutions are called Brownian numbers [approx. transl.: the origin of the name is unknown, it is unclear whether they are associated with Robert Brown].

So I still have something to read.