Witnessing a Poincar\'e recurrence with Mathematica

The often elusive Poincar\'e recurrence can be witnessed in a completely separable system. For such systems, the problem of recurrence reduces to the classic mathematical problem of simultaneous Diophantine approximation of multiple numbers. The latter problem then can be somewhat satisfactorily solved by using the famous Lenstra-Lenstra-Lov\'{a}sz (LLL) algorithm, which is implemented in the Mathematica built-in function \verb"LatticeReduce". The procedure is illustrated with a harmonic chain. The incredibly large recurrence times are obtained exactly. They follow the expected scaling law very well.


I. INTRODUCTION
The theorem established by Poincaré in 1890 is both stunning and intriguing. 1 It states that for any Hamiltonian system with a finite accessible phase space, the system will return to the proximity of a generic initial state infinitely many times. For instance, it would assert that if a cloud of gas initially confined in the left compartment of a vessel is released into the right empty compartment, then after a sufficiently long time, the gas molecules will reassemble in the left compartment. Moreover, they will do so again and again indefinitely.
The power of this paradoxical theorem lies in its generality. It results from the volume-preserving property (Liouville's theorem 2 ) of the Hamiltonian flow and the finiteness 3 of the phase space. The former is a common to any Hamiltonian system and the latter can be easily satisfied in many cases, say, the cloud of molecules in the scenario above. A key insight of Poincaré is that, because of the volume-preserving property, for any initial region V 0 , its time-evolved copies at times 0, τ , 2τ , . . ., denoted respectively as V 0 , V 1 , V 2 , . . ., are all of the same volume as V 0 , and since the total accessible phase space has a finite volume, two of these regions must overlap. Let V m V n = 0 (m < n), then we have V 0 V n−m = 0. That is, some points in V 0 come back into V 0 at (n − m)τ . Complete proofs and the rigorous statements can be found in the original paper by Poincaré and many books on dynamical systems and/or ergodic theory. 4 While the proof is not complicated and the conclusion inescapable, the predicted recurrence still seems elusive. The problem is that the proof is not constructive-It merely guarantees the existence of the recurrence, but does not tell us when it will occur. In a reply to Zermelo, who used the Poincaré recurrence to question the validity of the H-theorem, 5, 6 Boltzmann argued that, 7 as is widely accepted today, the recurrence time is extremely large. But how long exactly is it? Can we predict a Poincaré recurrence as we can predict the recurrence of Halley's comet? Although this is a question out of curiosity, it is not without pedagogical value. Usually, the recurrence time is estimated rudely, with the calculation based more on probability than on mechanical considerations. It is definitely more persuasive to do a rigorous calculation respecting all the mechanical laws and get the number exactly.
The task is apparently a difficult one for a generic system. However, as shown in previous works, for a special class of systems, completely integrable systems to be concrete, the problem is tractable. For such systems, the formidable problem of integrating the equation of motion can be bypassed, and the recurrence problem can be reduced to the classic problem of simultaneous Diophantine approximation of real numbers. [8][9][10] For this classic problem in number theory, there are tons of deep and beautiful theorems, 11 and on the computational side, there is the celebrated Lenstra-Lenstra-Lovász (LLL) algorithm. 12 Fortunately for our purpose, this algorithm is implemented in Mathematica in the function LatticeReduce. By invoking this function, we can obtain effortlessly the astronomically large recurrence times exactly.
Before proceeding, let us recall how the paper was motivated. In 2014, when the first author was a postdoc in the Max Planck Institute for the Physics of Complex Systems, out of curiosity he offered 100 Euro for a number t, such that t > 10 and the function (see Fig. 1) is close to 4 within 10 −6 , i.e., |h(t) − 4| ≤ 10 −6 . The question was posed because of its apparent relevance to the Poincaré recurrence. For h to be close to 4, each cosine term should be close to unity, or, the four numbers {t, √ 2t, √ 3t, √ 5t} should be close to integer multiples of 2π simultaneously, a condition essentially the same as that of Poincaré recurrence of a completely integrable system. By brute-force, a colleague found the huge num-  (1). Its initial value at t = 0 is 4, which is also the maximal value it can achieve. Because of dephasing of the different cosine terms, h can hardly return close to its initial value for a long time.
ber t = 2π × 10 458 943 416, and won the money. But the brute-force method apparently is out of the question if there are more cosine terms or if a much higher precision is required, and a more general and sophisticated approach was really what was wanted. Later, we learnt of the LLL algorithm.

II. POINCARÉ RECURRENCE OF COMPLETELY INTEGRABLE SYSTEMS
For a generic multi-degree-of-freedom system, its dynamics is chaotic, hence it is hard to follow its motion for a long time, let alone to predict the Poincaré recurrences in the extremely distant future.
More trackable is the motion of completely integrable systems. 2 For such a system executing a motion finite in all coordinates, the picture is very simple in terms of the action variables J i and angle variables θ i (1 ≤ i ≤ N ). The Hamiltonian depends only on the action variables, hence all the action variables are conserved, while all the angle variables increase linearly with time, As the angle variables are defined modulo 2π, the system evolves on a torus, the radiuses of which are determined by the actions and the surface of which is parametrized by the angle variables. Explicitly, the torus is The flow defined in (4) is volume-preserving and the total volume of the torus T N is finite, hence the two prerequisites for Poincaré recurrence are satisfied. For a recurrence, all the angle variables should return close to their initial values. In particular, the variable θ N should return close to its initial value. Since it has a period of T = 2π/ω N , we take the snapshots of the continuous evolution defined by (4) with a period of T , and consider the resulting discrete dynamical system defined on the torus namely, where the variables α i are defined as Apparently, f is also volume-preserving. Now take a small neighborhood of the origin with ǫ ≪ 1. Consider the images of Ω under the iterated action of f , i.e. , They are all of the same volume. Hence, for K = ⌊1/ǫ N −1 ⌋, where ⌊x⌋ denotes the largest integer no more than x, the K + 1 Hence there must be 0 ≤ m < n ≤ K such that Now by applying f −m to both sides, we get (q = n− m ≤ K) This means recurrence. Specifically, let (θ 1 , . . . ,θ N −1 ) ∈ Ω 0 Ω q . Since this point belongs to Ω q , there exists a point (θ 1 , . . . , θ N −1 ) ∈ Ω 0 which, when translated q times by f , arrives at (θ 1 , . . . ,θ N −1 ) ∈ Ω 0 , i.e., it comes back into Ω 0 . The relative error of recurrence is bounded by as {|θ i |, |θ i |} ≤ πǫ ≪ π. As f translates the torus as a whole rigidly, when one point returns to the proximity of its initial position, so do all other points. That is, the system not only recurs, but even recurs uniformly, or in other words, independent of the initial condition. We have thus not only proved the existence of recurrence, but also obtained an upper bound of the recurrence time in terms of the precision ǫ and the number of degrees of freedom. The scaling law anticipated is that the recurrence time is on the order of 1/ǫ N −1 for a completely integrable system with N degrees of freedom.
It is easily seen that the condition (12) is equivalent to the condition that for each 1 ≤ i ≤ N − 1. Here, ⌊x⌉ denotes the integer nearest to the real number x (for instance, ⌊2.4⌉ = 2 and ⌊2.7⌉ = 3), and x denotes the distance of x to ⌊x⌉. By definition, x ≤ 1/2 for an arbitrary x. Equation (14) is the sufficient condition for a recurrence with a prescribed precision of ǫ. The problem of looking for a Poincaré recurrence is then reduced to the problem of looking for an integer q such that (14) is satisfied simultaneously for all the numbers {α 1 , . . . , α N −1 }. It turns out that this is a classic problem termed simultaneous Diophantine approximation in number theory. 11 For this problem, there is the celebrated Dirichlet theorem, which states that for n arbitrary real numbers {α 1 , . . . , α n }, and any ǫ > 0, there exists a positive integer q ≤ 1/ǫ n , such that This is essentially the same as what is proven above.

III. LLL ALGORITHM
The problem is now to find a q such that (14) is satisfied for given ǫ, which will be arbitrarily small. For this purpose, a useful tool is the famous LLL algorithm, which is implemented in Mathematica by the function LatticeReduce. As the name suggests, the algorithm is about the lattice, a most basic concept in solid state physics. Suppose { u 1 , . . . , u n } are n linearly independent vectors in R n . The lattice determined by them is the subset of R n defined as The vectors { u 1 , . . . , u n } are called a basis of the lattice. We say they span the lattice. The point is that a basis determines a lattice, but not vice versa. In other words, for a given lattice, the basis is not unique. Actually, for any n × n matrix M , whose entries are all integral and whose determinant is ±1, the vectors constitute another basis of L. The proof is simple. By (17), the lattice spanned by the v's, denoted as L ′ , is contained in L. However, by construction, the inverse of M has the same property as M , and hence the u's are also integral linear combinations of the v's, which means that L is contained in L ′ . Therefore, they must be equal. For a lattice, a characteristic quantity is its determinant, which is defined as Here The physical or geometric meaning of d(L) is the volume of the parallelepiped subtended by the n basis vectors. Hence, we have the Hadamard's inequality 13 The equality is achieved if and only if u i are orthogonal to each other. Although all basis are equivalent in spanning the lattice, some basis is more preferable than others. For example, in Fig. 2, the lattice is spanned either by the basis or by the basis Apparently, the latter is more appealing as the basis vectors involved are shorter and more close to being orthogonal. We thus see that the defining basis of a lattice might be far from being optimal and generally there is room to reduce or simplify it, in the sense that B 2 is reduced compared to B 1 . This is exactly what the LLL algorithm is about.
There are numerous literature about the LLL algorithm. In particular, the original paper is very readable. 12 However, here for our purpose, we just need to know that the LLL algorithm, when fed with an original basis { a 1 , . . . , a n }, will return us in polynomial time a new basis { b 1 , . . . , b n } such that That the new basis is somehow reduced can be glimpsed by comparing (23) with (20). The determinant d(L) and the basis vector lengths swapped position. The way the LLL algorithm is used for simultaneous Diophantine approximation is as follows. Let {α 1 , . . . , α n } be the n real numbers. Construct the (n + 1) × (n + 1) matrix where Q is some large integer to be chosen according to the precision wanted. The (n + 1) rows are the basis of a lattice. The determinant of the lattice is apparently d(L) = Q n . The first vector b 1 in the reduced basis is of the form b 1 = (q, Q(qα 1 − p 1 ), . . . , Q(qα n − p n )), where q and p i (1 ≤ i ≤ n) are integers. By (23), we have Let Q = 2 n(n+1)/4 C n+1 , we have Hence, we have found a q such that (15) is satisfied with ǫ = 1/C. This q is not bounded by 1/ǫ n but is on the same order. In practice, the LLL algorithm is generally implemented with the components of the basis vectors being rational numbers. Hence, a small modification is necessary. 14 Instead of (24), we construct the matrix where the rounding function ⌊·⌉ is implemented in Mathematica with Round. In this case, By (23), we have As for |qα i − p i |, we have Here in the second line, we used the inequality |α i − ⌊α i ⌉| ≤ 1/2, and in the third line, we used the Cauchy-Schwarz inequality. Taking Q = ( √ 5 2 ) n+1 2 n(n+1)/4 C n+1 , we have similar to (27), The scaling law is unchanged. This is the very algorithm we shall use to search the exact recurrence times.

IV. A CASE STUDY
We now demonstrate the theory described above with a concrete model, which is illustrated in Fig. 3. The N point-masses are each of mass m and the springs are all of stiffness k = mω 2 (we shall set m = k = ω = 1 when it comes to numerics). The Hamiltonian is Here x ≡ (x 1 , x 2 , . . . , x N ) T denotes the displacements of the point-masses with respect to their equilibrium positions and p ≡ (p 1 , p 2 , . . . , p N ) T denotes their momenta.  The N × N matrix M is tridiagonal as It is symmetric and thus can be diagonalized. That is, we have with D being a diagonal matrix and U an orthogonal matrix. The explicit forms of D and U are with 1 ≤ i, j ≤ N . Substituting (35) and (36) into (33), we get Here we have introduced the new coordinates X ≡ (X 1 , X 2 , . . . , X N ) T and momenta P ≡ (P 1 , P 2 , . . . , P N ) T , The Hamiltonian is thus diagonalized as the sum of N independent harmonic oscillators, with the frequency of the ith oscillator being .
The evolution of the system is then simply that where the amplitude A i and the phase φ i are determined by the initial condition. We thus have the N -torus formalism and the algorithm can be applied directly. The procedure to get a recurrence time is then as follows. Let α i = ω i /ω N , 1 ≤ i ≤ N − 1. Choose a large integer Q, and construct the B matrix as in (28). Feed it into the function LatticeReduce, and get a reduced basis. The corresponding code is The new basis vectors are the rows of RB, and the integer q we want is the first component of the first basis vector, i.e.,

q = RB[[1,1]];
Once the q is obtained, the recurrence time is Here the subscript means Poincaré recurrence. How good the algorithm works can be checked with some concrete numbers. Let N = 15, and Q = 10 35 , we get The error is sufficiently small, hence an arbitrary initial state will recur after time T pr = 2πq/ω N to a good precision. Consider the initial state defined as Note that we have deliberately chosen an artificial state, in which only the kth point-mass is displaced and has a nonzero velocity. In Fig. 4, four snapshots of the coordinates and momenta of the point-masses are shown, with the corresponding times being t = T pr −200, t = T pr , and t = T pr ± 3. We see that at t = T pr − 200, almost all the point-masses are significantly displaced and have gained significant momenta. This is typical of the configuration of the system at an arbitrary time. The initially localized motion has spread over the whole system and the system remains so for a long time. However, around t = T pr , the system exhibits a recurrence. At t = T pr − 3, the tendency is clear, the motion regathers around the kth point-mass, and the point-masses far away have already returned to their initial positions and come to rest. Finally, at t = T pr , the system restores itself to its initial configuration to such good extent that the difference between the current values and the initial values of (x n , p n ) is hardly visible. Afterwards, as shown by the snapshots at t = T pr + 3, the motion disperses again and we have to wait yet another long time to witness a second recurrence. Now for each Q we can get a q and a corresponding error. By taking Q larger and larger, we get a series of pairs of (q, error). It is necessary and straightforward to check the scaling relation between them. This we do in Fig. 5. In Fig. 5(a), we have N = 15, and q scales with error as q ∝ error −14 . However, in Fig. 5(b), we have N = 5, and q scales with error not as q ∝ error −4 but as q ∝ error −3 . The reason is simply that for N = 5, the natural frequencies (39) of the normal modes are not linearly independent over the integers. To be specific, as can be easily verified, we have the equality, ω 5 = 2ω sin 5π 12 = 2ω sin π 12 + 2ω sin Hence, for an arbitrary integer q, q = qα 1 + qα 3 , which means, whenever qα 1 is less than ǫ, so is qα 3 automatically. Therefore, the problem of looking for a q such that max{ qα 1 , qα 2 , qα 3 , qα 4 } ≤ ǫ is actually equivalent to the problem of looking for a q such that max{ qα 1 , qα 2 , qα 4 } ≤ ǫ.

V. DISCUSSIONS
We have had the privilege to witness a Poincaré recurrence, which is a very improbable event-much rarer than the recurrence of Halley's comet for any realistic system actually. While this seems a hopeless task for a generic system, it is possible in the case of a completely integrable system, thanks to the fact that the problem can be reduced to the classic Diophantine approximation problem, for which mathematicians have already prepared many theorems, and in particular, algorithms, for us. We have thus here a case in which number theory plays a vital role in solving physical problems. Note that while analysis and algebra are routinely used in physics nowadays, number theory presents itself rarely in physics.
But frankly speaking, we have achieved only partial success. While the LLL algorithm is powerful, its insufficiency is also apparent. For given ǫ and for a generic set of numbers {α 1≤i≤n }, there are infinitely many q satisfying (15). Actually, collecting the appropriate q's in a sequence {q 1 , q 2 , . . . , }, Weyl's theorem states that 15 lim m→∞ q m m = 1 ǫ n .
That is, on average, the distance between two adjacent q's is 1/ǫ n . Physically, it means that recurrences with a precision on the order of ǫ will appear with a frequency on the order of ǫ n . However, the algorithm can get only one q for each ǫ. How to capture all the q's is thus a problem of interest. As far as we know, this problem has been completely solved only for n = 1. 16 For larger n, only partial success has been achieved. Moreover, the q returned by the algorithm is often not the smallest one, i.e., it is not smaller than 1/ǫ n , the bound given by the Dirichlet theorem, although it is on the same order. Historically, Poincaré recurrence was discovered in the context of classical mechanics. However, it can be generalized to quantum mechanics straightforwardly. [17][18][19] For the sake of simplicity, let us assume that the quantum system has a finite-dimensional Hilbert space, and the eigenstates and eigenvalues are {|m } and {E m }, respectively. The quantum Poincaré recurrence theorem then states that for any initial state the system, evolving as will come back close to |ψ 0 up to an arbitrary precision infinitely many times. Specifically, for any t > 0 and ǫ > 0, there exists a t r > t such that d(|ψ(t r ) , |ψ 0 ) ≡ ||ψ(t r ) − |ψ 0 | ≤ ǫ.
This is not surprising. As (50) shows, the wave function also evolves on an N -torus, and hence the formalism developed for a completely integrable system applies too. Quantitatively, we have For (51) to be satisfied for a generic initial state |ψ 0 , a sufficient condition is for all 1 ≤ m ≤ N . Let t = 2πq/E N with q a whole number, so that E N t/2π = 0 and (53) is satisfied already for m = N , we get the problem defined in (14) again, with α i = E i /E N . Therefore, the same algorithm applies for a quantum system too.