fourier modes of a real scalar field coordinates for odd n, which are −(n − 1)/2 and (n −...

22
Fourier Modes of a Real Scalar Field Jorge L. deLyra Department of Mathematical Physics Physics Institute University of S˜ao Paulo Version 1, June 2006 We will consider here the technical questions of how to deal with the Fourier modes of a single-component real scalar field in numerical simulations. This includes how to organize them in order to avoid over-counting the degrees of freedom, how to index them into vectors and how to build the transformations from position space to momentum space and back in an efficient way, so that they can be executed very fast, for use in stochastic simulations. It is important to note that the type of implementation presented here is not what is usually known as the Fast Fourier Transform (FFT). It may be described rather as an Indexed Fourier Transform, and is meant specifically for the relatively small lattices used in the stochastic simulations of field-theoretical models in space-time dimensions ranging from d = 2 to d = 5. 1 Organizing the Degrees of Freedom Just as we can represent the field in position space as a N d -dimensional real vector, so we would like to do the same in momentum space. A real field ϕ on a N -lattice in d dimensions corresponds to N d degrees of freedom, that is, to N d independent real variables ϕ(n), one for each site of the lattice, which is described by the integer coordinates n. Since Fourier transformation is simply a change of basis in the space of functions on the lattice, from the position space representation ϕ(n) to the momentum-space representation ϕ( k), it follows that the Fourier components must also include exactly N d independent variables, one for each mode of the lattice, which is described by the integer coordinates k. However, in its usual representation the Fourier transform of a real scalar field is complex, ϕ( k)= 1 N d n e ı 2π N k·n ϕ(n), and therefore seems to include twice as many real variables. This is not really so because not all such variables are independent, due to the identity 1

Upload: others

Post on 24-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

Fourier Modes of a Real Scalar Field

Jorge L. deLyra

Department of Mathematical PhysicsPhysics Institute

University of Sao Paulo

Version 1, June 2006

We will consider here the technical questions of how to deal with the Fourier modesof a single-component real scalar field in numerical simulations. This includes howto organize them in order to avoid over-counting the degrees of freedom, how toindex them into vectors and how to build the transformations from position spaceto momentum space and back in an efficient way, so that they can be executedvery fast, for use in stochastic simulations. It is important to note that the typeof implementation presented here is not what is usually known as the Fast FourierTransform (FFT). It may be described rather as an Indexed Fourier Transform, andis meant specifically for the relatively small lattices used in the stochastic simulationsof field-theoretical models in space-time dimensions ranging from d = 2 to d = 5.

1 Organizing the Degrees of Freedom

Just as we can represent the field in position space as a Nd-dimensional real vector,so we would like to do the same in momentum space. A real field ϕ on a N -lattice ind dimensions corresponds to Nd degrees of freedom, that is, to Nd independent realvariables ϕ(~n), one for each site of the lattice, which is described by the integercoordinates ~n. Since Fourier transformation is simply a change of basis in thespace of functions on the lattice, from the position space representation ϕ(~n) to

the momentum-space representation ϕ(~k), it follows that the Fourier componentsmust also include exactly Nd independent variables, one for each mode of the lattice,which is described by the integer coordinates ~k. However, in its usual representationthe Fourier transform of a real scalar field is complex,

ϕ(~k) =1

Nd

~n

eı 2π

N~k·~nϕ(~n),

and therefore seems to include twice as many real variables. This is not really sobecause not all such variables are independent, due to the identity

1

Page 2: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

ϕ(−~k) = ϕ∗(~k),

or, using the decomposition ϕ(~k) = R(~k) + ıI(~k), the identities

R(−~k) = R(~k) and I(−~k) = −I(~k).

Besides, there are some modes for which the transform is real, such as ϕ(~0), for whichI(~0) = 0. So we see that counting and keeping the truly independent variables isnot so straightforward a task.

In order to keep just the Nd independent variables, we must first identify whichmodes are real and which modes are complex, and then adopt some standard formof keeping the real and imaginary parts in a unique way. A mode is real whenϕ(−~k) = ϕ(~k) identically, that is, for any field ϕ(~n), and is complex otherwise. Forexample, it is clear that ϕ(~0) is real, as one can easily verify by inspection of thedefinition of the transform. Since it is not true in general that ϕ(−~n) = −ϕ(~n), onecan also see from the definition that there are no purely imaginary modes. Hencewe have two classes of modes, purely real modes that contain a single independentreal variable each, and complex modes that contain two mutually independent realvariables each. These complex modes are related in pairs by the identity above, soif we keep all of them we will be double-counting the variables associated to them.For odd N these pairings can be illustrated by the diagram below, representing theconjugate lattice in dimension d = 1,

k1

−(N−1)/2 (N−1)/20

where every square represents a mode and one can see a vector ~k as well as thenegative of the same vector. In two dimensions we have the corresponding diagramin figure 1. In these diagrams one can see the limits of the range of the momentumcoordinates for odd N , which are −(N − 1)/2 and (N − 1)/2. The zero modeobviously maps to itself. We see now that for odd N there is a single real mode, thezero mode, because all other modes map to a different mode inside the conjugatelattice, by the inversion of the vector ~k, due to the fact that the extremes of therange are symmetrical. For even N the situation is more complicated, in the cased = 1 we have

2

Page 3: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

k2

k1

(N−1)/2−(N−1)/2

(N−1)/2

−(N−1)/2

0

0

Figure 1: Inversion of a vector ~k in the conjugate lattice for odd N and d = 2.

k1

0 N/2−N/2+1

length N

So we see that, because the extremes of the range of the variable are no longersymmetrical, there is a mode, the mode k1 = N/2, that maps to a point outside theconjugate lattice, so that we must then add to the inverted vector a period vector oflength N , as shown in the figure, in order to bring it back into the conjugate lattice.As a consequence of all this the mode k1 = N/2 also maps to itself, and is thereforea real mode, as one may check by direct inspection of the definition of the Fouriertransform. In the case d = 2 we have the diagram in figure 2, were we see thatin general many modes will map to points outside the conjugate lattice, namely allthose modes that have at least one component equal to N/2, and in such cases wemust add a period vector of length N along one of the directions of the lattice, asshown in the example depicted, with the period vector (N, 0). In some cases it maybe necessary to add several period vectors in different directions of the lattice, as inthe case of the mode (N/2, N/2) of this example, which needs two period vectors,

3

Page 4: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

k2

k1

−N/2+1 N/2

−N/2+1

0

0

N/2

length N

Figure 2: Inversion of a vector ~k in the conjugate lattice for even N and d = 2.

(0, N) and (N, 0). However, not all such modes are real, because most times theymap to a different mode on the border of the lattice, as shown in the example. Inthe case d = 2 we can see from the diagram that there will be four real modes:(0, 0), (0, N/2), (N/2, 0) and (N/2, N/2).

In general we have 2d real modes for even N , and just one for odd N . For oddN each complex mode is paired with the mode obtained by the inversion of ~k, butfor even N the pairings are not always so simple, as there are modes paired withinthe surfaces with one component equal to N/2. Nevertheless, all complex modesare dully paired in this way. The idea for the classification of the Nd independentvariables is that we leave the purely real modes alone and, for each pair of conjugatedcomplex modes, we keep only one real part and one imaginary part. In order to havea conjugate lattice with one real variable per site, just as have in position space forϕ(~n), we must classify the modes in conjugate pairs and keep only the real part ofone member of the pair, and only the imaginary part of the other member of thepair. As we do this we must also keep in mind that later on we will index all themodes into a single Nd-dimensional vector, just as we do in position space.

On order to describe the scheme we adopt for this classification of independentvariables, we must discuss one dimension at a time. Starting with d = 1, in this

4

Page 5: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

case we may simply keep the real parts of the modes with positive components, andthe imaginary parts of the modes with negative components. In the simpler odd-Ncase we represent this by the diagram

k1

−(N−1)/2 (N−1)/20

I R R R R RI I I

where the purely real modes are presented in a heavier shade, the complex modesof which we keep only the real parts in a lighter shade, and the complex modes ofwhich we keep only the imaginary parts in white. The algorithm for implementingthis is very simple,

−(N − 1)/2 ≤ k1 ≤ 1 −→ calculate and store I(~k),

k1 = 0 −→ calculate and store R(~k),

1 ≤ k1 ≤ (N − 1)/2 −→ calculate and store R(~k).

In the even-N case, still for d = 1, we have the diagram

k1

0 N/2−N/2+1

I RI I I R R R R R

and the algorithm is only slightly different,

−N/2 + 1 ≤ k1 ≤ 1 −→ calculate and store I(~k),

k1 = 0 −→ calculate and store R(~k),

1 ≤ k1 ≤ N/2 − 1 −→ calculate and store R(~k),

k1 = N/2 −→ calculate and store R(~k).

For d = 2, in the odd-N case, we adopt a scheme which is a generalization of theprevious one, and which is given by the diagram in figure 3. We start by scanningthe lattice vertically by row, and define the situation on all horizontal rows that donot contain a real mode. For each row that contains a real mode we must examinethe next coordinate. In this way we use the previous d = 1 scheme for the middlehorizontal row of modes. The algorithm in this case is a two-fold iteration of thealgorithm for d = 1,

5

Page 6: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

k2

k1

(N−1)/2−(N−1)/2

(N−1)/2

−(N−1)/2

0

0

R

I

RRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

RRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR

RRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR

RRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR

R R R R

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

III IIII IIII IIII IIII IIII IIII IIII IIII

III IIII IIII IIII IIII IIII IIII IIII IIII

III IIII IIII IIII IIII IIII IIII IIII IIII

III IIII IIII IIII IIII IIII IIII IIII IIII

I I I R

Figure 3: Classification of the momentum variables for odd N and d = 2.

−(N − 1)/2 ≤ k2 ≤ 1 −→ calculate and store I(~k),k2 = 0 −→ go to block for k1,

1 ≤ k2 ≤ (N − 1)/2 −→ calculate and store R(~k),

−(N − 1)/2 ≤ k1 ≤ 1 −→ calculate and store I(~k),

k1 = 0 −→ calculate and store R(~k),

1 ≤ k1 ≤ (N − 1)/2 −→ calculate and store R(~k).

Note that we start by checking k2, not k1, and only if it is zero we go on to check k1.In the even-N case, still for d = 2, we adopt a similar scheme, given by the diagramin figure 4. Note that in this case the d = 1 scheme is used for two horizontal rows,the middle one and the top one. The algorithm in this case is once more a two-folditeration of the algorithm for d = 1,

6

Page 7: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

k2

k1

−N/2+1 N/2

−N/2+1

0

0

N/2

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

R

RRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR

RRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR

RRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR

RRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

I

III IIII IIII IIII IIII IIII IIII IIII IIII IIII

III IIII IIII IIII IIII IIII IIII IIII IIII IIII

III IIII IIII IIII IIII IIII IIII IIII IIII IIII

III IIII IIII IIII IIII IIII IIII IIII IIII IIII

I

I RRR RRRR RRRR RRRR RRRR RRRR

RRR RRRR RRRR RRRR RRRR RRRR

III IIII IIII IIII

III IIII IIII IIII

Figure 4: Classification of the momentum variables for even N and d = 2.

−N/2 + 1 ≤ k2 ≤ 1 −→ calculate and store I(~k),k2 = 0 −→ go to block for k1,

1 ≤ k2 ≤ N/2 − 1 −→ calculate and store R(~k),k2 = N/2 −→ go to block for k1,

−N/2 + 1 ≤ k1 ≤ 1 −→ calculate and store I(~k),

k1 = 0 −→ calculate and store R(~k),

1 ≤ k1 ≤ N/2 − 1 −→ calculate and store R(~k),

k1 = N/2 −→ calculate and store R(~k).

Note that in this case both the value k2 = 0 and the value k2 = N/2 send us totest the next coordinate, so that there are two paths to get from one block to thenext block. Both the odd-N and the even-N algorithms can be easily generalizedto arbitrary dimensions. Here is the general algorithm for odd N ,

7

Page 8: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

−(N − 1)/2 ≤ kd ≤ 1 −→ calculate and store I(~k),kd = 0 −→ go to block for kd−1,

1 ≤ kd ≤ (N − 1)/2 −→ calculate and store R(~k),

−(N − 1)/2 ≤ kd−1 ≤ 1 −→ calculate and store I(~k),kd−1 = 0 −→ go to block for kd−2,

1 ≤ kd−1 ≤ (N − 1)/2 −→ calculate and store R(~k),

· · · · · · · · ·

−(N − 1)/2 ≤ k1 ≤ 1 −→ calculate and store I(~k),

k1 = 0 −→ calculate and store R(~k),

1 ≤ k1 ≤ (N − 1)/2 −→ calculate and store R(~k).

Similarly, for even N we have the general algorithm

−N/2 + 1 ≤ kd ≤ 1 −→ calculate and store I(~k),kd = 0 −→ go to block for kd−1,

1 ≤ kd ≤ N/2 − 1 −→ calculate and store R(~k),kd = N/2 −→ go to block for kd−1,

−N/2 + 1 ≤ kd−1 ≤ 1 −→ calculate and store I(~k),kd−1 = 0 −→ go to block for kd−2,

1 ≤ kd−1 ≤ N/2 − 1 −→ calculate and store R(~k),kd−1 = N/2 −→ go to block for kd−2,

· · · · · · · · ·

−N/2 + 1 ≤ k1 ≤ 1 −→ calculate and store I(~k),

k1 = 0 −→ calculate and store R(~k),

1 ≤ k1 ≤ N/2 − 1 −→ calculate and store R(~k),

k1 = N/2 −→ calculate and store R(~k).

Note that, except for the changes in the minimum and maximum values of eachmomentum coordinate, this algorithm includes the previous one, since for odd N amomentum coordinate will never have the value N/2. Hence, if we define kl to bekl = (N − 1)/2 for odd N and kl = N/2 − 1 for even N , and define also kL to bekL = (N + 1)//2 where the division indicated by the symbol // is integer division,with truncation, so that kL is in fact (N +1)/2 for odd N and N/2 for even N , thenwe have the general algorithm, valid for both odd and even N ,

8

Page 9: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

−kl ≤ kd ≤ 1 −→ calculate and store I(~k),kd = 0 −→ go to block for kd−1,

1 ≤ kd ≤ kl −→ calculate and store R(~k),kd = kL −→ go to block for kd−1,

−kl ≤ kd−1 ≤ 1 −→ calculate and store I(~k),kd−1 = 0 −→ go to block for kd−2,

1 ≤ kd−1 ≤ kl −→ calculate and store R(~k),kd−1 = kL −→ go to block for kd−2,

· · · · · · · · ·

−kl ≤ k1 ≤ 1 −→ calculate and store I(~k),

k1 = 0 −→ calculate and store R(~k),

1 ≤ k1 ≤ kl −→ calculate and store R(~k),

k1 = kL −→ calculate and store R(~k).

In the way of verification, one can count the number of modes which are classifiedin each case. For odd N we have, at each step of the algorithm,

−(N − 1)/2 ≤ kd ≤ 1 −→ Nd−1(N − 1)/2,kd = 0 −→ proceed to next block,

1 ≤ kd ≤ (N − 1)/2 −→ Nd−1(N − 1)/2,

−(N − 1)/2 ≤ kd−1 ≤ 1 −→ Nd−2(N − 1)/2,kd−1 = 0 −→ proceed to next block,

1 ≤ kd−1 ≤ (N − 1)/2 −→ Nd−2(N − 1)/2,

· · · · · · · · ·

−(N − 1)/2 ≤ k1 ≤ 1 −→ N0(N − 1)/2,k1 = 0 −→ 1,

1 ≤ k1 ≤ (N − 1)/2 −→ N0(N − 1)/2.

Adding up all the contributions one gets

Nd−1(N − 1) + Nd−2(N − 1) + . . . + (N − 1) + 1 =

(N − 1)(Nd−1 + Nd−2 + . . . + 1) + 1 =

(N − 1)Nd − 1

N − 1+ 1 =

Nd− 1 + 1 = Nd,

9

Page 10: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

so that this case checks out. For even N we have, at each step of the algorithm,

−N/2 + 1 ≤ kd ≤ 1 −→ 20Nd−1(N/2 − 1),kd = 0 −→ proceed to next block,

1 ≤ kd ≤ N/2 − 1 −→ 20Nd−1(N/2 − 1),kd = N/2 −→ proceed to next block,

−N/2 + 1 ≤ kd−1 ≤ 1 −→ 21Nd−2(N/2 − 1),kd−1 = 0 −→ proceed to next block,

1 ≤ kd−1 ≤ N/2 − 1 −→ 21Nd−2(N/2 − 1),kd−1 = N/2 −→ proceed to next block,

· · · · · · · · ·

−N/2 + 1 ≤ k1 ≤ 1 −→ 2d−1N0(N/2 − 1),k1 = 0 −→ 2d−1,

1 ≤ k1 ≤ N/2 − 1 −→ 2d−1N0(N/2 − 1),k1 = N/2 −→ 2d−1.

The factors of powers of 2 that appear are due to the fact that there are two waysto proceed from each block to the next one. Adding up all the contributions onegets

20Nd−1(N − 2) + 21Nd−2(N − 2) + . . . + 2d−1N0(N − 2) + 2d =

2d−1(N − 2)

[(N

2

)d−1

+

(N

2

)d−2

+ . . . +

(N

2

)0]

+ 2d =

2d−1(N − 2)

(N

2

)d

− 1

N

2− 1

+ 2d =

2d

[(N

2

)d

− 1

]+ 2d =

(Nd

− 2d)

+ 2d = Nd,

so that this case also checks out. Therefore, we have a completely well-definedalgorithm that can be used to organize the independent variables, in any dimension.This algorithm should be used both when we calculate the Fourier components, inorder to put them in their correct places in the conjugate lattice, and when onecalculates an inverse transform or use the Fourier components in any other way, inorder to get them from their correct places.

10

Page 11: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

2 Indexing in Momentum Space

For the position-space representation ϕ(~n) of the field, with 1 ≤ nµ ≤ N andµ = 1, . . . , d, one can index the field into a single N -dimensional vector, using thesingle index ι instead of all the position coordinates, where

ι = 1 + (n1 − 1)N0 + (n2 − 1)N1 + (n3 − 1)N2 + . . . + (nd − 1)Nd−1.

Defined in this way the index ι runs from 1 to Nd, thus enumerating all the sites ofthe lattice. There is also an algorithm to obtain the components of ~n back from thevalue of ι, as we will discuss later. We would like to do the same for the momentum-space representation ϕ(~k), with km ≤ nµ ≤ kM , µ = 1, . . . , d, where the extremes ofthe range are defined as

km = −(N − 1)/2, kM = (N − 1)/2,

for odd N , and as

km = −N/2 + 1, kM = N/2,

for even N . In order for the index value of 0 to correspond to the zero mode ~k = ~0,we would like to use the index κ given by

κ = k1N0 + k2N

1 + k3N2 + . . . + kdN

d−1.

In order to show that one can in fact do this, and to discover how to invert the rela-tion, getting the components of ~k out of κ, we start with a version of the momentum-space index just like the position-space one,

κ′ = 1 + (k1 − km)N0 + (k2 − km)N1 + (k3 − km)N2 + . . . + (kd − km)Nd−1,

which ranges from 1 to Nd and where 0 ≤ (kµ − km) ≤ N − 1, µ = 1, . . . , d, just likethe position-space index. Now, starting from this index we have

κ′ = 1 + k1N0 + k2N

1 + k3N2 + . . . + kdN

d−1

−(kmN0 + kmN1 + kmN2 + . . . + kmNd−1)

= k1N0 + k2N

1 + k3N2 + . . . + kdN

d−1

+1 − km(N0 + N1 + N2 + . . . + Nd−1)

= k1N0 + k2N

1 + k3N2 + . . . + kdN

d−1 + 1 − km

Nd− 1

N − 1,

where Nd − 1 is always divisible by N − 1, of course. Therefore, considering thedefinition of κ, we have

κ′ =

(1 − km

Nd− 1

N − 1

)+ κ.

11

Page 12: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

Since the two indices are related by an additive constant, either one can be used toindex the modes. Since κ′ ranges from 1 to Nd, we have for the extreme values of κ

(Nd− 1)

km

N − 1= κm ≤ κ ≤ κM = (Nd

− 1)

(1 +

km

N − 1

).

Note that km is negative, so that the lower extreme is negative. For odd N theextremes can be written explicitly as

−Nd

− 1

2≤ κ ≤

Nd− 1

2,

and the range is therefore symmetrical around 0. Note that since N is odd so is Nd,and therefore Nd − 1 is even and thus divisible by 2. For even N we get

−(N − 2)(Nd

− 1)

2(N − 1)≤ κ ≤

N(Nd− 1)

2(N − 1),

so that in this case the range is not symmetrical, and there are (Nd − 1)/(N − 1)more positive-index elements than negative-index elements. A little analysis willshow that the integer divisions are exact in this case also, without any truncation:since Nd − 1 is always divisible by N − 1, we are left with −(N − 2)/2 and N/2 tobe considered, and since N is even both N and N − 2 are divisible by 2.

If we recall our organization of real and imaginary parts as independent coordi-nates, as described in the previous section, it is interesting to observe that one canverify that for odd N the negative values of κ correspond to imaginary parts, thevalue 0 to the real mode, and the positive values to real parts. However, the same isnot true for even N , due to the modes with one or more components equal to N/2,some of which have their imaginary parts at positive values of the index. Due tothis, in general it will be necessary to implement an additional pair of indexing ar-rays in order to map real parts to the corresponding imaginary parts and vice-versa,whenever it becomes necessary to recover the two parts of one and the same mode.

It remains for us to discuss the inversion algorithm. The algorithm for extractingthe position coordinates ~n from the position-space index ι works by integer division,with truncation, and in d dimensions is given by

τ = ι − 1,nd = 1 + τ//Nd−1,τ = τ − (nd − 1)Nd−1,

nd−1 = 1 + τ//Nd−2,τ = τ − (nd−1 − 1)Nd−2,

nd−2 = 1 + τ//Nd−3,τ = τ − (nd−2 − 1)Nd−3,

· · · · · · · · ·

n2 = 1 + τ//N1,τ = τ − (n2 − 1)N1,

n1 = 1 + τ//N0,

12

Page 13: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

where τ is a temporary variable. It is therefore clear that we can use exactly thesame algorithm for extracting the d shifted momentum coordinates kµ−km +1 fromthe index κ′. Since κ and κ′ are related by an additive constant, we can also usethe algorithm for κ, so long as we start by adding to it the constant 1 − κm, andsubstitute nµ − 1 by kµ − km in the formulas, in order to get the components kµ of~k, and therefore we have the algorithm

τ = κ − κm,kd = km + τ//Nd−1,τ = τ − (kd − km)Nd−1,

kd−1 = km + τ//Nd−2,τ = τ − (kd−1 − km)Nd−2,

kd−2 = km + τ//Nd−3,τ = τ − (kd−2 − km)Nd−3,

· · · · · · · · ·

k2 = km + τ//N1,τ = τ − (k2 − km)N1,

k1 = km + τ//N0.

This completes the discussion of the indexing scheme in momentum space.

3 The Transform and its Inverse

Let us discuss now, in detail, how to implement numerically the finite Fourier trans-form and its inverse transform. The complete Fourier transform of a real scalar fieldis given by

ϕ(~k) =1

Nd

~n

eı 2π

N

~k·~nϕ(~n),

but we will only calculate and store the independent real and imaginary parts,ϕ(~k) = R(~k) + ıI(~k), which are given by

R(~k) =1

Nd

~n

cos

(2π

N~k · ~n

)ϕ(~n),

I(~k) =1

Nd

~n

sin

(2π

N~k · ~n

)ϕ(~n).

For use in the numerical programs we will implement these in matrix form, using asingle (usually very large) Nd × Nd transformation matrix,

ϕκ =1

Nd

Nd∑

ι=1

Fκιϕι,

13

Page 14: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

where ϕκ stands for either a real part or an imaginary part, depending on thevalue of the index κ, according to our classification of the independent variables inmomentum space, and where, accordingly,

Fκι = cos

(2π

N~k · ~n

)or Fκι = sin

(2π

N~k · ~n

),

where κ corresponds to ~k and ι to ~n via the respective indexation schemes. Since~k · ~n has a limited set of possible values, much smaller than the number of elementsN2d of Fκι, and which will be used repeatedly for many different modes, in order tosave both computation time and memory, we will calculate all necessary sine andcosine functions just once, beforehand, for future repeated use. We will store thesevalues in a relatively small array P (τ) indexed by the integer τ = ~k ·~n, and constructa very large indexing matrix Iκι, of size Nd × Nd, to pick up the necessary valuesof P (τ) for each combination of a mode in momentum space and a site in positionspace. Since this indexing matrix can be of 2-byte integers rather than of the 8-bytedouble-precision real numbers needed for the values of P (τ), in this way we save

memory at the ratio of almost four to one. The range of the integer ~k ·~n is given by

d kmN ≤ (~k · ~n) ≤ d kMN,

so that the size of the small double-precision array is given by d NkM − d Nkm + 1,where kM − km = N − 1 for either odd or even N , so that the size of this array isd N(N − 1) + 1, of the order of d N2, much smaller than N2d for the values of d ofmost interest, from d = 3 to d = 5. When we deal with the values of P (τ) usingthis array, not all values along the array are actually going to be used, because notall integers in the range can in fact be written as ~k · ~n. However, it can be verifiedthat the rate of useful occupation of the array is large for the dimensions of interest,in fact, it is over 90 % for dimensions from d = 3 to d = 5. Therefore, we have hereonly a very small waste of memory space, and in the interest of simplicity it is notworth while to try to improve this occupation rate.

Since we must store the values of both the sines and the cosines, we actuallyhave to double the size of the array as it was described above. In order to put thecosines at positive values of the index and the sines at negative values, we add andsubtract constants in order to use the ranges that follow,

−d N(N − 1) − 1 ≤

[~k · ~n − (d NkM + 1)

]≤ −1,

to be used for the sines, and

1 ≤

[~k · ~n + (−d Nkm + 1)

]≤ d N(N − 1) + 1,

to be used for the cosines, so that the total range is given by

−d N(N − 1) − 1 = τm ≤ τ ≤ τM = d N(N − 1) + 1,

14

Page 15: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

The total size of the array is now given by 2d N(N − 1) + 3, which is still muchsmaller than the indexing matrix. The indexing matrix Iκι will return the values ofτ in this range, and is to be used as the argument of P (τ), given values of κ and ι,so that we have

Fκι = P (Iκι),

and the transformation can now be written as

ϕκ =1

Nd

Nd∑

ι=1

P (Iκι)ϕι,

which includes all the independent real and imaginary parts, depending on the valuesof κ, in a single matrix operation, which is easy to implement efficiently.

Let us now examine the situation concerning the inverse transform. It is clearthat a similar scheme should be used for it. Since the indexing matrix Iκι is solarge, and considering the possibility that a single program might need to use boththe transform and its inverse, it is important to build the scheme for the inversetransform in such a way that it is able to use the same indexing matrix. As we willsee, it is possible to do this, but unfortunately not in a very efficient way. For speedof execution the order of the indices matters, and should in fact be Iικ for the directtransform and Iκι for the inverse transform. Hence, one can save memory only solong as one needs only one of the two matrices or so long as the program is notdependent on the performance of one of the two transforms. The inverse Fouriertransform is defined by

ϕ(~n) =∑

~k

e−ı 2π

N

~k·~nϕ(~k),

or, in Nd-dimensional matrix form,

ϕι =

κM∑

κ=κm

F−1ικ ϕκ,

where the limits of the sum over the momentum index are κm = (Nd−1)km/(N −1)and κM = (Nd − 1)(1 + km/(N − 1)). We must now deal explicitly with the factthat both the Fourier component of the field and the mode function are complex.Since we have the decomposition of the field ϕ(~k) = R(~k) + ıI(~k), as well as

e−ı 2π

N~k·~n = cos

(2π

N~k · ~n

)− ı sin

(2π

N~k · ~n

),

it follows that we have

ϕ(~n) =∑

~k

[cos

(2π

N~k · ~n

)R(~k) + sin

(2π

N~k · ~n

)I(~k)

]

+ı∑

~k

[− sin

(2π

N~k · ~n

)R(~k) + cos

(2π

N~k · ~n

)I(~k)

].

15

Page 16: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

Since the field ϕ(~n) is real, the sum giving its imaginary part must vanish, and weare left with

ϕ(~n) =∑

~k

[cos

(2π

N~k · ~n

)R(~k) + sin

(2π

N~k · ~n

)I(~k)

].

We must now consider separately the contributions to the sum from the real andcomplex modes. From the purely real modes we get the contributions

real ~k

cos

(2π

N~k · ~n

)R(~k),

while from the complex modes we get the contributions

complex ~k

[cos

(2π

N~k · ~n

)R(~k) + sin

(2π

N~k · ~n

)I(~k)

].

Since we keep only one copy of each independent R(~k) and one copy of each inde-

pendent I(~k), while the sum above runs over both parts on all the complex modes,in the case of these modes we must multiply the contribution by a factor of two.In this way we get the correct result when we run over the modes and use only thepart which is stored in each one. So in reality we will calculate this contribution as

complex ~k

[2 cos

(2π

N~k · ~n

)R(~k) + 2 sin

(2π

N~k · ~n

)I(~k)

].

These factors of two, which do not appear in the real modes, prevent us from im-plementing the inverse transform as a single matrix operation. The best way toimplement it will be to first perform a complete matrix operation with the factors oftwo for all modes, and then subtract back once the contributions of the real modes,

ϕ(~n) = 2∑

~k

[cos

(2π

N~k · ~n

)R(~k) + sin

(2π

N~k · ~n

)I(~k)

]

−∑

real ~k

cos

(2π

N~k · ~n

)R(~k).

This second sum runs over only either %M = 1 or %M = 2d elements, depending onthe parity of N , and is therefore much smaller than the first one, which runs over Nd

elements, specially for large lattices, representing therefore only a small additionalcomputational effort. In order to do this it will be necessary to construct a smallindexing array to pick the purely real modes out of the indexed vector of modes.Note that the first term of the inverse transformation matrix F−1

ικ , as decomposedabove, is equal to 2Fκι. In order to deal with the second term, consider an indexingarray λ(%) of dimension %M , which for each % = 1, . . . , %M , with %M = 1 for odd N

16

Page 17: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

and %M = 2d for even N , returns the value of the index κ of a purely real mode.Using it we can write the inverse transform as

ϕι = 2

κM∑

κ=κm

P (Iκι)ϕκ −

%M∑

%=1

P (Iλ(%)ι)ϕλ(%).

We have therefore the inverse transformation implemented by a large matrix oper-ation followed by a small correction, which is still easy to implement efficiently. Inthe computer code we will actually have two indexation matrices I

(t)κι and I

(i)ικ = I

(t)κι ,

differing only by the ordering of the indices, one for the direct transformation andone for the inverse transformation, so that both can be executed efficiently.

4 Fortran Routines

The technique described above for the implementation of the Fourier transformsimplies strong limitations for the lattice size, both due to addressing issues anddue to memory requirement issues. We will examine here these limitations, andwe will see that the technique is still usable for lattices with the usual sizes in theimportant cases d = 3 and d = 4. For these lattices a set of routines implementingthe transforms in the fastest possible way is supplied. For larger lattices a differentset of routines is supplied, in which the indexation matrices I

(t)κι and I

(i)ικ are not

implemented directly in memory, but rather by functions that dynamically calculateand return the index τ of the phases, appropriately shifted, given values of thecoordinate indices κ and ι. These routines are about 4 to 5 times slower, but canbe used for very large lattices, with much smaller memory requirements.

First of all, note that since the indexation matrices are defined as 2-byte signedintegers, they are limited to the range [−32767, 32767], that is, to 65535 differentvalues. Therefore this last number is the maximum size of the indexed array ofphases P (τ). This implies that there are limits to the possible lattice sizes N ineach dimension d, as shown in the following table:

d Nmax RAMmax

1 181 64 kB2 128 520 MB3 105 2497 GB4 91 8560 TB5 81 22 EB

Here the corresponding maximum required amounts of RAM are also shown andthe order of the unit multipliers is k, M, G, T, P and E, ranging from 210 to 260, sowe see that in the case of the higher dimensions the memory requirements are trulyenormous for the larger lattices still allowed by this indexing limitation. Specially fordimensions d = 4 and d = 5, these are larger lattices than one can possibly expectto run successfully on current computers. On 32-bit processors there is another type

17

Page 18: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

of limitation on the values of N , which is far more serious for the larger values ofd. The limitations of the signed 32-bit integer addressing of the indexation matriceslimits their size, and hence the size of the lattice, as shown in the following table:

d Nmax RAMmax

1 32767 2 GB2 181 2 GB3 31 2 GB4 13 2 GB5 7 2 GB

In this case the addressing limitations correspond to a fixed maximum requiredmemory, of course. In addition to this, the limitations of the signed 32-bit integeraddressing of the indexed array of phases also limits its size and the size of thelattice, but this one is a significant limitation only for the case d = 1, which isrelatively irrelevant to us, as shown in the following table:

d Nmax RAMmax

1 11585 2 GB2 8192 2 GB3 6689 2 GB4 5793 2 GB5 5181 2 GB

Therefore, we see that this last limitation can be safely ignored. The correspondinglimitations in the case of a 64-bit processor with 48-bit addressing are smaller, andnot so significant, since in this case the memory availability limitations becomerelevant much before the addressing limitations themselves. The limits due to the48-bit addressing of the indexation matrices are shown in the following table:

d Nmax RAMmax

1 8388607 128 TB2 2896 128 TB3 203 128 TB4 53 128 TB5 24 128 TB

The limits due to the 48-bit addressing of the indexed array of phases are shown inthe following table:

d Nmax RAMmax

1 2965821 128 TB2 2097152 128 TB3 1712317 128 TB4 1482910 128 TB5 1326355 128 TB

18

Page 19: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

If we consolidate all these indexing and addressing limitations in a single table, wesee that the limits on a 32-bit processor with 32-bit logical addressing are given bythe table below:

d Nmax RAMmax

1 181 64 kB2 128 520 MB3 31 2 GB4 13 2 GB5 7 2 GB

The same limits on a 64-bit processor with 48-bit logical addressing are given by thetable below:

d Nmax RAMmax

1 181 64 kB2 128 520 MB3 105 2497 GB4 53 128 TB5 24 128 TB

A typical larger lattice in d = 4 would have N = 10, and in this case the transformcan be used with reasonable memory requirements, about 200 MB for a single index-ation matrix, and about 400 MB for two indexation matrices. A lattice of N = 20in d = 3 can be used with memory requirements of about 128 MB for one matrixand of about 256 MB for two matrices. Therefore, we conclude that the fast versionof the transforms can be used in practice in most simulations. Whenever there isnot enough memory available, one can turn to the alternative routines.

There are Fortran routines available implementing the direct and inverse Fouriertransforms, as described in this paper. There are also a few test programs thatmay be useful as examples of how to use the routines. As they currently stand,these routines are written for use in either 32-bit or 64-bit processors. However,sufficiently large lattices may require a 64-bit processor, as well as lots of availablememory. The files described in what follows, containing the source code, are freelyavailable in a compressed tar file at the URL:

http://latt.if.usp.br/technical-pages/fmrsf/

There are files with the definition of the necessary data structures, as well as theinitialization routines and the transforms themselves. These modules are meant tobe integrated into larger programs at a source-code level. The files containing thedata structures are include files, meant to be included in the modules that needaccess to the data structures they contain. All interchange of data among modulesis made by means of common blocks. Each initialization routine defines the datain the common block in the corresponding include file. These initialization routines

19

Page 20: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

should be called once at the beginning of the program, one for each common blockthat is used in the program. Read the makefile or the source code in order to seewhich modules depend on which data structures.

Here are short explanations of the nature of each source-code file. First the fileswith the data structures:

fp def.f: an include file with the basic parameters defining the run; this is neededby all modules.

fp cal.f: an include file with other parameters, which are calculated using thebasic ones; this is needed by most modules.

cb param.f: an include file with a common block containing additional calculatedparameters.

cb flags.f: an include file with a common block containing the dimensionalityflags.

cb logic.f: an include file with a common block containing the logical array formarking the sites as carrying either their real parts or their imaginary parts.

cb field.f: an include file with a common block containing the field componentsin position space and in momentum space.

cb phase.f: an include file with a common block containing the indexed array forthe phases.

cb trans.f: an include file with a common block containing the large indexingmatrix for the direct transform.

cb trinv.f: an include file with a common block containing the large indexingmatrix for the inverse transform.

cb traux.f: an include file with a common block containing the auxiliary indexingarray for the inverse transform.

The files containing the main routines, including the initialization routines and thetransforms themselves:

check pars.f: a subroutine that verifies consistency of the basic parameters defin-ing the run.

check pars 32.f: a subroutine that verifies consistency of the basic parametersregarding indexation and addressing issues on a 32-bit machine with 32-bitaddressing capability.

check pars 48.f: a subroutine that verifies consistency of the basic parametersregarding indexation and addressing issues on a 64-bit machine with 48-bitaddressing capability.

20

Page 21: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

init param.f: a subroutine that initializes the common block in cb param.f.

init flags.f: a subroutine that initializes the common block in cb flags.f.

init logic.f: a subroutine that initializes the common block in cb logic.f.

init phase.f: a subroutine that initializes the common block in cb phase.f.

init trans.f: a subroutine that initializes the common block in cb trans.f.

init trinv.f: a subroutine that initializes the common block in cb trinv.f.

init traux.f: a subroutine that initializes the common block in cb traux.f.

indphtrn.f: a function that replaces the large indexing matrix in the commonblock in cb trans.f.

indphinv.f: a function that replaces the large indexing matrix in the commonblock in cb trinv.f.

fourier trans fast.f: a subroutine that implements the fast version of the directFourier transform.

fourier inver fast.f: a subroutine that implements the fast version of the in-verse Fourier transform.

fourier trans large.f: a subroutine that implements the direct Fourier trans-form with much smaller memory requirements, for use on large lattices.

fourier inver large.f: a subroutine that implements the inverse Fourier trans-form with much smaller memory requirements, for use on large lattices.

fourier trans slow.f: a subroutine that implements the fast version of the directFourier transform in a much slower but somewhat less memory-intensive way.

fourier inver slow.f: a subroutine that implements the fast version of the in-verse Fourier transform in a much slower but somewhat less memory-intensiveway.

Files containing the test programs and some auxiliary routines, including a coupleof C interfaces to system facilities:

test trans inver fast.f: a program that composes the fast versions of the trans-form and of the inverse, in this order, and measures the resulting average error.

test inver trans fast.f: a program that composes the fast versions of the in-verse and of the transform, in this order, and measures the resulting averageerror.

21

Page 22: Fourier Modes of a Real Scalar Field coordinates for odd N, which are −(N − 1)/2 and (N − 1)/2. The zero mode obviously maps to itself. We see now that for odd N there is a single

test trans inver large.f: a program that composes the large-lattice versions ofthe transform and of the inverse, in this order, and measures the resultingaverage error.

test inver trans large.f: a program that composes the large-lattice versions ofthe inverse and of the transform, in this order, and measures the resultingaverage error.

test trans inver slow.f: a program that composes the slow versions of the trans-form and of the inverse, in this order, and measures the resulting average error.

test inver trans slow.f: a program that composes the slow versions of the in-verse and the transform, in this order, and measures the resulting averageerror.

urandom ctof.c: a Fortran-callable C interface to the system libraries, to get arandom seed from the Linux kernel.

clock ctof.c: a Fortran-callable C interface to the system libraries, to get theCPU time of the current process from the system.

dranr-1.f: the first random number generator from the authors of the book “Nu-merical Recipes”.

dranr-2.f: the second random number generator from the authors of the book“Numerical Recipes”.

sdot.f: a simple function that returns the scalar product of two vectors.

22