Halo Spin from Primordial Inner Motions

We reexamine how angular momentum arises in dark-matter haloes. The standard tidal-torque theory (TTT), in which an ellipsoidal protohalo is torqued up by the tidal field, is an approximation to a mechanism which is more accurate, and that we find to be more pedagogically appealing. In the initial conditions, within a collapsing protohalo, there is a random gravitysourced velocity field; the spin from it largely cancels out, but with some excess. Velocities grow linearly, giving a sort of conservation of angular momentum (in a particular comoving linear-theory way) until collapse. Then, angular momentum is conserved in physical coordinates. This picture is more accurate in detail than the TTT, which is not literally valid, although it is useful for many predictions. Protohaloes do not uniformly torque up; instead, their inner velocity fields retain substantial dispersion. We also discuss how this picture is applicable to rotating filaments, and the relation between halo mass and spin. We also explain that an aspherical protohalo in an irrotational flow generally has nonzero angular momentum, entirely from its aspherical outskirts.


INTRODUCTION
The question of how galaxies and the dark-matter haloes that host them come to be spinning is fundamental in astronomy. The standard explanation is the tidal torque theory (Peebles 1969;Doroshkevich 1970;White 1984, TTT,): as a protohalo collapses to form a halo, it does so embedded in a tidal field, produced by the surrounding arrangement of matter. Generally, the protohalo is aspherical, with a moment of inertia not perfectly aligned with tidal field, and thus the tidal field produces a torque on it.
Some of the above papers also mention 'primeval turbulence,' including vorticity, as a possible source of galaxy spin. Indeed, it is subtle how halo rotation arises from an irrotational (vorticityfree) flow. Usually, the primordial velocity field is thought to be irrotational, because perturbatively, expansion dampens vorticity. At later epochs, vorticity arises in patches with multiple collisionless dark-matter streams (Pichon & Bernardeau 1999;Hahn et al. 2015); see also Wang et al. (2014) for a discussion of vorticity generation. But of course, the accumulation of angular momentum in a finite patch is different from vorticity generation, as we discuss further in Section 6. White (1984, W84) states that by that time, the TTT idea had 'come to be accepted,' and W84 pushed its acceptance further. Here we briefly review W84's arguments. Following Doroshkevich (1970), the full expression of a protohalo's physical-coordinates an-gular momentum (which we often call 'spin' for brevity) is (1) Here, x is the comoving Eulerian coordinate, a function of q, the initial, Lagrangian coordinate, ρ0 is the mean density at the present epoch, a is the scale factor, and V is the protohalo in Lagrangian space.
To first order, the velocities will be ballistic as in the Zel'dovich (1970) approximation (ZA), v = ∇φ(q). Neglecting displacements from the initial conditions (i.e. replacing x with q), As Porciani et al. (2002, P02) note, the approximation a 2Ḋ ∝ D 3/2 holds well in all flat cosmologies. In a matter-dominated epoch, this is a factor of a 3/2 , as used by W84. One factor of a can be thought to come from the scaling from comoving to physical coordinates. Another factor of a 1/2 gives the physical-coordinates velocity scaling in the linear regime. This a 1/2 is well-known to users of GADGET (Springel 2005) particle velocities; in code units, GADGET velocities are constant in the linear regime. So, this linearregime L scaling involves no additional scalings in GADGET, a suggestion of its naturalness.
Expanding the potential to second order in q (see W84) even-tually gives the TTT expression, where Li is the ith component of L, T is the Hessian of the potential, and I is the inertia tensor. But obviously, the TTT is just an approximation. It works rather well (e.g. Catelan & Theuns 1996;Sugerman et al. 2000), but there are subtleties, e.g. care must be taken to smooth the tidal field at the appropriate scale (P02). Also, there are conceptual problems with taking the TTT too literally. The idea that an ellipsoid uniformly spins up in a non-rotating background of about the same density would involve awkwardness (collisions in some locations, and evacuation in others) at the interface. An example of multistreaming is in the 'tetrahedral collapse model' (Neyrinck 2016b), in which a halo is a tetrahedron that uniformly twists, with overlaps but no gaps. This idea of uniformly rotating tetrahedra is perhaps even further from reality than uniformly rotating ellipsoids, but it was intended as a toy model to understand mutual rotations of cosmic web components. Protohaloes are not delineated by any physical boundary, tetrahedral or ellipsoidal, in the initial conditions; instead, seen in Lagrangian space, haloes grow inside out.
Although Peebles (1969) applied the TTT to the now-standard picture of galaxies arising from initial small perturbations, it was originally proposed in the steady-state theory (Hoyle 1949;Sciama 1955), in which a literal interpretation of the TTT may have been more applicable. And, in our subjective opinion, the idea of a misaligned tidal tensor and moment-of-inertia tensor is abstract and hard to visualize. This is unfortunate for a textbook-level explanation of the fundamental physical process of generating galaxy spin. It is doubtful that experts in the field would agree in detail with this perfectly literal interpretation of the TTT as described here, but some may conceive of it more literally, and it is important to point out its inaccuracies.
We advocate another approximation, which we call 'Spin from Linearly Evolving Inner Motions' (SPIM) to predict the primary spin of a halo, following Eq. (2). By 'primary' we mean before non-linear interactions and exchanges of angular momentum. The SPIM prescription is as follows: sum up the angular momentum from the velocity field inside a protohalo in the initial conditions. Extrapolate it according to the growth factor for halo spin until collapse, L(a) ∝ a 3/2 . This L(a) ∝ a 3/2 describes a sort of comoving conservation of angular momentum, which holds well in the median. After collapse, treat L(a) as conserved in physical coordinates. This is pedagogically appealing since it involves only the initial velocity field, more readily conceived of than the tidal field smoothed at some particular scale, and its relation to the inertia tensor. But it should be kept in mind that the SPIM inner motions ultimately come from gravity and tidal fields, as well -the initial velocity field and tidal field are linked, with the same ultimate source. Jones & van de Weygaert (2009) point out the importance of shear in generating angular momentum, present in both fields.
This approach would be useful for predicting final spins in approximate cosmological realizations, if the patches that collapse are known, using e.g. the adhesion model (e.g. Gurbatov et al. 2012;Hidding et al. 2012;Neyrinck et al. 2018;. Indeed, a similar prescription appears to be used in the PINOCCHIO algorithm; Monaco et al. (2002) do point out, however, the sensitivity of the final halo spin to small changes in the protohalo boundary.
This straightforward idea has been tried before, but to our knowledge has not been explicitly advocated as a conceptual framework. P02 tested the TTT against what appears to be SPIM, advanc-ing particle velocities according to the ZA. They found that it was better at predicting halo spins than the TTT, not surprising since the TTT is an approximation to SPIM. They found even better agreement with the full ZA (not only advancing velocities, as in SPIM, but also positions). However, they still found substantial scatter between halo spin directions and the TTT prediction.
Secondary processes (e.g. orbital angular momentum in mergers) can substantially contribute to spin; indeed, accretion of spin via satellites has even been proposed as a source of halo spin (Vitvitska et al. 2002). This sort of picture is appropriate if one wants to track a collapsed object as it grows and merges with smaller objects in time. But if we track the protohalo in time, i.e. all the matter that ends up in the final halo, for large haloes investigated here (with M > 10 13−14 M ), below we find that primary (SPIM) processes dominate. Of course, the spin of galaxies, including dissipative processes in the gas and star-formation feedback processes (Efstathiou & Jones 1980), often differs from halo spin, another complication (e.g., Liao et al. 2017;Ganeshaiah Veena et al. 2019).
Correlations of the velocity field are simpler than correlations of the tidal field, so this SPIM picture may be useful to study spinspin correlations and intrinsic galaxy alignments (e.g., Joachimi et al. 2015). We also expect it to be useful to investigate how the cosmic web influences galaxy halo spin (e.g., Aragón-Calvo et al. 2007;Codis et al. 2012;Libeskind et al. 2012;Stewart et al. 2013;Trowland et al. 2013;Aragon-Calvo & Yang 2014;Ganeshaiah Veena et al. 2018;Codis et al. 2018;Kraljic et al. 2019).
This SPIM idea is somewhat reminiscent of vortical primeval cosmic turbulence (von Weizsäcker 1951;Gamow 1952), a oncecompetitor with the gravitational condensation theory, that Peebles (1969) argued against when first proposing the TTT. See Jones (1976) for more information on this. But the 'irregular motions ("initial" angular momentum)' neglected by Peebles (1969) that we use are just the irrotational, gravity-sourced motions usually present in the current theory of structure formation. They are not the envisioned compressible, vortical gas eddies of primeval turbulence, but do carry some randomness.
The structure of this paper is as follows. In §2, we start with an investigation in 2D, convenient for building intuition because the spin is simply a scalar. It also is relevant to investigating spin of 3D filaments. In §3, we look at how individual particles contribute to halo spins. In §4, we look at the behavior of total halo spin with time. In §5, we show how considering particle contributions individually helps to understand the scaling of spin with mass in the initial conditions. In §6, before concluding, we describe how rotation can arise in an aspherical object from an irrotational flow; we show that all of the angular momentum comes from the object's outskirts.

TWO DIMENSIONS
We start in 2D, in which spin is a simple scalar. To further physically simplify the problem, we truncate small scales of the initial power spectrum.
The 2D simulation has 1024 2 particles, and a box size of 32 Mpc/h. The initial conditions are a 2D slice of particles from a 1024 3 grid generated via the ZA with a BBKS (Bardeen et al. 1986) initial power spectrum, with modes of wavelength < 1 Mpc/h. The (x-y) plane of particles was replicated along the z-axis to match the number of slices in the original particle grid. However, we reduce the mass resolution of the replicated planes with increasing distance from the (central) plane in a similar way as done in zoom- (Lagrangian) Particle's contrib. to halo spin (Eulerian) Figure 1. In initial (left) and final (right) coordinates of a 2D N -body simulation, the contributions of each halo particle to the angular momentum of its halo, at three snapshots of time. Red, counterclockwise particles contribute positively; blue, clockwise particles contribute negatively. We use a nonlinear colorscale to enhance small deviations from zero (white). In greyscale, blue appears darker than red. Black particles are not in haloes above the mass cut, 20 particles. Notice that for particles in halo outskirts in the middle panels, the colors are similar as in the top panels. Time advances from top to bottom; the snapshots are at a = 0.09, 0.3, and 1. Viewing the entire animation at https://www.youtube.com/watch?v=7KjesL hP7c& autoplay=0&rel=0 is strongly recommended.
in simulations in order to reduce the computational cost. It was run using a version of GADGET2 (Springel 2005) modified to calculate forces and update positions only in the x and y directions. Because of this replication along the z-axis, each particle represents a cylinder, interacting with other cylinders effectively with a 2D version of gravity. For the initial power spectrum and expansion history, we used a generic ΛCDM(ΩM = 0.3, ΩΛ = 0.7, σ8 = 0.8, h = 0.7) set of cosmological parameters. We detect haloes in the 2D simulation using the ORIGAMI algorithm (Falck et al. (2012), first introduced in Knebe et al. (2011)). In ORIGAMI, a particle is classified as a halo particle if, going from the initial to final conditions, it has 'folded' (crossed some other particle) along two (in 2D) initial orthogonal axes. We then join to-(Lagrangian space) Halo spin (Eulerian space) Figure 2. As in Fig. 1, coloring by the total angular momentum of a particle's halo. Viewing the entire animation at https://www.youtube.com/ watch?v=dmqJX rSnKE&autoplay=0&rel=0 is recommended.
gether groups of particles adjacent on the initial Lagrangian square grid to form haloes 1 . Fig. 1 shows the contribution Li/mpart = (xi−x)×(vi−v) of each halo particle i to the spin of its halo, where m is the particle mass. To get a physical spin, the quantity shown should be scaled by a 3/2 . To clearly see both extreme and low-amplitude fluctuations, we use a sinh −1 -scaled variable, L colorscale = L sinh sinh −1 (Li/L sinh ), where L sinh /m = 10 3 km/s Mpc/h. This responds linearly for |Li| L sinh , and logarithmically for |Li| L sinh . There is a characteristic quadrupolar alternating pattern in 1 Several haloes returned in this process were actually groups of haloes apparently distinct by eye, joined by small bridges of halo particles. The spurious fragmentation in N -body simulations with truncated initial power (Wang & White 2007) likely contributed to this. Applying a mathematical morphology erosion operator cut these bridges, returning haloes that in almost all cases corresponded to visual expectation. Erosion, used e.g. by (Platen et al. 2007), shaves off cells within a specified distance (here, 1 grid spacing) of a boundary from all contiguous blobs. We computed the erosion by smoothing the Lagrangian 'halo' (1) and 'not-halo' (0) field with a circular top-hat filter of radius 1; after smoothing, we classified as 'halo' particles all corresponding pixels with a value > 0.99. most of the haloes. The animation suggests that, in many haloes, it is mainly driven by collapse along the first axis of the halo. Flows toward the first axis of collapse show up as contributing clockwise or counter-clockwise spin; one of these wins out, somewhat randomly. This pattern is strikingly similar to those seen by Laigle et al. (2015) in the vorticity in cross-sections of filaments. The two quadrupolar patterns may arise from flows of similar characters. But here, the vorticity is zero. As discussed in §6, the irrotational flow should guarantee that the spin contributed from inside a maximal circle fitting inside a halo should vanish. In particular, the area centroid of each halo has to have L = 0, on a white contour in Fig.  1, whatever the velocity there is. Another thing to keep in mind is the truncated small-scale power, which simplifies the figure.
The 'haloes' in this 2D simulation can be thought of essentially as cross-sections of filaments in a 3D simulation. This implies that we should generically expect that filaments have some net rotation along the axis, as suggested by Laigle et al. (2015), and also as generically happens in an origami, or tetrahedral-collapse approximation (Neyrinck 2016a,b). But there are computational ambiguities in measuring a rotation in a patch of a filament in an N -body simulation; these are simplified in a formalism such as adhesion, in which a linear segment of a filament collapses from a well-defined disc-like patch of the initial conditions. In this patch, there would generally be some spin in the protofilament of Lagrangian space, aligned with the axis of the filament.
What happens when we sum up these particle-by-particle contributions? Fig. 2 shows the same, but coloring each halo particle by its halo's total angular momentum. Most haloes retain their color with time. Fig. 3 shows trajectories in angular momentum, L(a), for haloes of at least 100 particles. There is a substantial spread in behavior, but in the median, the particles behave as in linear theory, with L(a) ∝ a 3/2 up to a ∼ 0.3. Then, spin is conserved in physical coordinates, giving constant L(a) (∝ a −3/2 , in this plot). This general behavior was already found by W84, and it will appear below in the 3D results, as well.

PARTICLE CONTRIBUTIONS TO 3D SPIN
In 3D, the behavior of halo spins is similar as above. We analyze a random simulation, 201, from the Indra suite of simulations (Falck et al., in prep), a set of 512 independent simulations with 1024 3 particles and box size 1 h −1 Gpc. It uses a WMAP7 ΛCDM set of cosmological parameters (ΩM = 0.272, ΩΛ = 0.728, h = 0.704, σ8 = 0.81, ns = 0.967), not truncating its smallest-scale modes at all (Falck et al. 2017). The 3D haloes we analyze had at least 100 particles, found with the Friends of Friends (FOF Davis et al. 1985) algorithm, using a standard linking length of 0.2 times the initial grid spacing. The a = 1/128 initial conditions were generated with second-order Lagrangian perturbation theory. We give masses below in terms of the number of particles, of mass mpart = 7.031 × 10 10 M /h.  The median behavior, after dividing by a 3/2 , is constant at early times, transitioning at a ∼ 0.3 to a constant in physical coordinates, i.e. following a line ∝ a −3/2 . 14% of halo spins switch sign from the initial to final snapshot. cise quantities and colors being shown are not so important; we are mainly trying to show their persistence in time. One notable feature is that left-hand panels become more grey with time; this decay in a particle's contribution is also shown below in Fig. 7. As in the 2D case, a particle's contribution to its halo's eventual spin largely persists until it participates in halo collapse, after which it becomes rather random. Importantly for our conclusions, also particles' cos θ, where θ is the angle between a particle's contribution to its halo's spin, and its halo's total spin, is largely preserved with time, again until orbits become rather chaotic at late times. Fig. 7 shows trajectories of L(a) · Linit/(a 3/2 L 2 init ) for random particles from a 1024 2 slice. L here is a particle's contribution to its halo's spin. Fig. 7 also shows percentiles of these quantities (L sinh , Lmax) = (500, 1424) and (10 5 , 4 × 10 5 ) km/sec mpart Mpc/h. G and B values come in the same way from y and z coordinates. L is divided by a 3/2 . The bottom-right panel shows a scalar: the dot product of the spin contributed by each particle with the total spin of its halo. In the other panels, colors show 3D vectors L. Vectors with high magnitude L have high or low luminance, and the hue indicates the direction. Grey pixels indicate a zero vector. Top panels show each particle's contribution to its halo's spin in Lagrangian and Eulerian coordinates, and the bottom-left panel shows its halo's spin. All angular momenta L are normalized by a 3/2 . Viewing the entire animation at https://www.youtube.com/ watch?v=ZlxCbbiChTo&autoplay=0&rel=0 is recommended.  over all particles in the slice, computed for each snapshot separately.
As shown at top, particles typically follow the median L(a) ∝ a 3/2 curve at early times, but some of them veer systematically above or below that; this may be driven by different effective velocity growth rates in different regions. Eventually, most halo particles experience a spike in this quantity (as indicated by short dotted lines in the plot). This may happen when the particle actually enters the halo. Fig. 8 shows the distribution of the alignment between particles' contribution to their haloes' spin with the total spin. In a literal interpretation of the TTT, in which particles in the protohalo torque up together, this quantity would be 1 for all particles. In the simulation, on the contrary, particles contribute very differently (even almost half negatively) to the halo's total spin. It is striking how close to uniform the distribution is, nearly random (in complete randomness, colored curves would coincide with the dashed lines), only ramping upward a bit at late times, perhaps as many haloes settle into their z = 0 forms, as dynamical friction acts. As the top panel shows, many particles oscillate in this quantity, after they enter their haloes, but curiously, the total distribution of cos θ changes only a bit.
A simple measure of the anisotropy of cos θ is cos θ = 0.07 (initial), and 0.12 (final). Below, we will use this in units of the standard deviation of cos θ; cos θ /σ cos θ = 0.12 (initial), and 0.19 (final).

HALO SPIN IN 3D
As shown in the previous section, the behavior of particles within haloes is not according to a naive, literal interpretation of the TTT. Nonetheless, many authors have found general agreement with its predictions, for whole haloes. these results in the Indra simulation, for three halo bins. Low-, middle-, and high-mass bins include haloes in the bottom, middle two, and top mass quartiles; the bin edges are at 100, 132, 361, and 46383 particles, i.e. masses of 7.0 × 10 12 , 9.3 × 10 12 , 2.5 × 10 13 , and 3.3 × 10 15 M /h (the highest halo mass in the box). As shown in the top panel, the haloes in our sample remain quite aligned with their initial protohalo's spin, misaligned by ∼ 30 • at z = 0 even in the low-mass sample. P02 found more misalignment using the ZA, typically ∼ 40 • at z = 0, likely because of the smaller haloes analyzed there. The second panel shows the fraction of haloes in each sample flipping their spin directions by > 90 • compared to the initial conditions; less than 10% of them flip at a = 1, even in the low-mass sample.
The third panel addresses spin amplitudes, as well, and shows essentially what was already shown by W84, with much better statistics. In the median, spins evolve as though intra-halo velocities grow with linear theory, until a characteristic time when the spin is roughly conserved in physical coordinates. Although we call this characteristic time for the halo sample the collapse time, we have not actually checked that haloes tend to 'collapse' (a word subject to definition details) then. It would be interesting to compare the time at which individual haloes depart from the linear-theory trajectory different possible definitions of collapse, in later work.
Note that small haloes begin their constant-L phase (decay, in the middle panel of Fig. 9)  the total spins of their haloes. The trajectories, from random halo particles, begin equally spaced in the rank of the initial cos θ init , and remain colored according to that quantity. While there are wild oscillations at late times, note that the eye is drawn preferentially to these, and many particles behave more calmly, as well. Bottom: Percentiles of cos θ with time. Dashed lines show where nearby colored curves would be if the distribution were entirely uniform. It is remarkable how small this deviation is, and how similar its distribution remains with time.
sense; large haloes collapse later, and have larger spin, so that initial spin persists longer. Secondary interactions and angular momentum exchanges also contribute to this downturn; these preferentially affect smaller haloes. These effects may be related to the slightly steeper than L =const slope in the median. While by default we assume a L ∼ a 3/2 scaling, most relevant for a matter-dominated universe, it is also interesting to test an L ∼ D 3/2 scaling, mentioned by P02, for the linear-regime evolution of L. The downturns coincide roughly with the epoch where dark energy starts to be substantial, and would change D. The last panel shows the result of normalizing by D 3/2 instead of a 3/2 . The curves do not change qualitatively, but using D does extend the regime where the curves are nearly 1, and softens the downturns.

SCALING OF SPIN WITH MASS FROM A CORRELATED RANDOM WALK
Our interpretation of the source of halo spin carries arguable qualitative and conceptual advantages, but can it help to make quantitative predictions? Many early papers (e.g. Efstathiou & Jones 1979;Heavens & Peacock 1988;Catelan & Theuns 1996), have found that for a finally collapsed halo, typically L ∝ M 5/3 , where M is the total halo mass. It may be a coincidence, but this relationship even  The median (and ±1σ percentiles) scaling of halo spin with time, in units of its initial value. It grows as a 3/2 (constant, here) until a ≈ 0.4, and then becomes constant with time (∝ a −3/2 here). For clarity, the ±1σ percentiles are only shown for the high-and low-mass bins. Bottom: The same, normalizing by D 3/2 instead of a 3/2 . seems to hold within the errors for total stellar mass and angular momentum across a wide range of galaxies (Fall & Romanowsky 2018). As Fig. 10 shows, we also find that this relationship holds rather well for final haloes in the simulation. The best fit has L ∝ M 4.85/3 , a simple least-squares linear fit in log space. But the relationship is different for initial protohaloes, which typically have a shallower slope, closer to L ∝ M 4/3 (with best fit M 4.33/3 ).
Why the change in slope from the initial to final conditions? It is because L/a 3/2 stays almost constant for large haloes, but decays for small haloes. The largest haloes stay above 10 7 , but for the smallest haloes, the best-fitting line goes down by about a factor of 3 from initial to final conditions. This is as in the middle panel of Fig. 9: large haloes tend to retain their initial spin longer than small haloes do. Consider a toy model of initial protohalo angular momentum as coming from a correlated random velocity field; this will help us make sense of the scaling found in the initial conditions. We choose the z-axis to align with the total spin, and v φ to be the azimuthal component of the velocity.
In the completely correlated extreme that v φ is a constant, where R is an effective radius of the (nearly spherical) protohalo, giving L ∝ M 4/3 . In the opposite extreme, v φ is an uncorrelated Gaussian random number at each particle. The angular momentum is a sum over particles of rv φ . The contribution Lz(r)dr from a shell at radius r and thickness dr will be a sum over particles, r 4πr 2 nvrdr, where n is the number density of particles. If at each particle, v φ ∼ G(0, σv), where σv is the dispersion of a single component of the initial velocity, Lz(r)dr will be the expected displacement of a random walk, i.e. the square root of the number of random contributions, ∝ rdr. In that case, the power of r is reduced by one in the integrand of Eq. (4), so Lz ∝ r 3 , and L ∝ M . We checked this scaling numerically by recomputing halo spins as in the top panel of Fig. 10, and setting v φ at each particle to an uncorrelated Gaussian random number. This is not the observed behavior.
The reality can be approximated to be between these extremes; a correlated random walk. To crudely approximate the effect of velocity correlations, let us assume that v φ ∼ G(0.12σv, σv), i.e. with a mean 0.12 times the standard deviation, as measured above from the distribution of cos θ, the alignment of the total halo spin to each particle's contribution. (cos θ is a uniform, not Gaussian variate, but the Gaussian-distributed velocity gets multiplied by this.) For the bottom panel of Fig. 10, we kept fixed the positions of all particles in protohaloes to be the same as in the actual simulation, but set v φ at each particle according to v φ ∼ G(0.12σv, σv). We set σv = 180/a 1/2 km/sec, the average of σ(vx), σ(vy) and σ(vz) for all particles in the initial conditions.
As this shows, setting v φ /σv = 0.12 is enough to give this relation, L ∝ M 4/3 , as well. The scatter about the mean is inaccurate, however; a more accurate treatment of the distribution of v φ is needed for this. Notice that the dispersion in the top and bottom panels looks rather comparable at a mass of 1000 particles, the lower mass limit of the measurement used to estimate σv/ v φ . If  Figure 10. 2D histograms of halo mass M vs. spin L, for initial protohaloes and final haloes (first two panels). In calculating L, particles were considered to have unit mass, as indicated in the x-axis label. Note the factor of a 3/2 in the top panel; with this factor, if all haloes evolved according to linear theory, the top and middle panels would be identical. We also show the results of a toy model of a correlated random walk (see text), with each particle contributing one random variate to its halo in its initial conditions. The color (with logarithmic colorbar at right) shows the number of haloes in a pixel of the histogram. The orange lines are of the form L ∝ M α , tied to coincide for the highest mass in the sample; the legend shows α.
this quantity were measured separately for each mass, we would expect the scatter to match better in the top and bottom panels.

ROTATION FROM AN IRROTATIONAL FLOW
Before concluding, it is helpful to clarify how something could come to rotate from random motions in an irrotational velocity field. Judging from the words without their precise physical meaning, it seems impossible. It is possible; 'irrotational' means zerovorticity, which pertains to infinitesimal volume elements, whereas rotation (in the sense of angular momentum or spin) is an integrated quantity.
But the concepts are closely related. A spherical patch of an irrotational, homogeneous-density velocity field must have vanishing spin. Returning to Eq. 4, for a spherical patch of radius R, putting the origin at the center of the sphere, and choosing an arbitrary directionẑ, where C(r, θ) = (r,θ) v · ds is the circulation in the circular ring at radius r and altitude θ. By Kelvin's circulation theorem, since the vorticity is zero inside the ring, C(r, θ) = 0, so Lz = 0. Note that this argument that Lz = 0 in an irrotational flow depends on circulation paths being circular and azimuthal; otherwise, the component of v summed up over the path would not be purely v φ . Also, Lz = 0 in an irrotational flow for some aspherical shapes; the argument applies to any cylindrically symmetric shape that is a sum of azimuthal rings, e.g. an ellipsoid. However, for an ellipsoid that has only one axis of cylindrical symmetry, the argument only applies for the component of L along that axis. To ensure L = 0, the shape has to have spherical symmetry.
For an aspherical patch, there can be contributions to the angular momentum from outside a maximal sphere that fits in the patch, with center at the volume centroid. Fig. 11 shows this, for the most massive haloes in our simulation. The angular momentum, cumulatively added in spherical shells of center at protohalo volume centroids, is zero (except for some small noise) as long as M (r) ∝ r 3 , i.e. inside a maximal sphere. But the magnitude L > 0 outside this region. Fig. 12 shows the same, in another way; it shows the same 2D patch from Fig. 4, with spin cumulatively added from the center of each halo. The key thing to note is that the regions inside maximal spheres are grey, i.e. have zero cumulative spin.
This recalls the TTT, in which a spherical patch, with vanishing moment of inertia, cannot spin up. This is why ellipsoidal patches are considered. But again, in a naive literal interpretation of the TTT, one would expect an entire ellipsoid to be torqued up; what actually happens is that the velocity field outside the maximal sphere determines the angular momentum of the halo.
This interpretation also sheds light on why the angular momentum of a growing halo evolves rather stochastically with time (e.g., Contreras et al. 2017). It is obvious that as haloes grow, newly accreted matter contributes with some randomness to their angular momentum. But not only that; it is only the last-accreted outskirts of the halo, outside the maximal Lagrangian sphere, that contribute to its linear-theory angular momentum.
The maximal-sphere finding is related to our other results. For example, within the maximal sphere of a protohalo in the initial conditions, the distribution of cos θ in Fig. 8 is likely consistent with uniform; the excess cos θ = 0.12 coming only from regions outside the protohalo's maximal sphere.
This discussion is also relevant to currently popular investi- . Top: Magnitudes of protohalo (initial-conditions) angular momenta, summed cumulatively in spherical shells from protohalo volume centroids, for the 20 most massive haloes in the simulation. These are normalized by the total angular momentum magnitude, tying all curves at 1 at r = rmax, the distance to the farthest particle. Bottom: The mass inside radius r divided by r 3 for these 20 haloes, colored the same as at top, normalized to be ∼ 1 for low r. The curves are horizontal until r/rmax ∼ 0.4-0.6, but turn down after that, meaning that the haloes are filled spheres inside this radius, but become aspherical thereafter. Curves at top turn up at about the same radius where curves at bottom turn down.
gations of wave, or fuzzy, dark matter (ψDM) (e.g., Schive et al. 2014;Marsh 2016), because the dark-matter velocity field in this model must be irrotational at all redshifts (since it is defined via a gradient). Du et al. (2018) found that subhalo ψDM solitonic cores resemble irrotational Riemann S-ellipsoids (see also Rindler-Daller & Shapiro 2012). Here, confusingly, 'irrotational' refers only to the velocity field; any spherically symmetric patch has zero angular momentum. But the cores do rotate, in the sense of having nonzero angular momentum if summed up to the ellipsoidal boundary, and this rotation can be thought to reside outside a core's maximal sphere.

CONCLUSIONS
We advocate a SPIM (Spin from Primordial Inner Motions) picture of halo spin, arising from gravity-sourced motions within each protohalo. The usual tidal torque theory (TTT) is an approximation to this, but differs in detail. As we show, protohaloes do not uniformly torque up, as in a literal reading of the TTT. The SPIM prescription is as follows: to obtain the lineartheory angular momentum of a halo, measure the angular momentum imprinted onto the initial fluctuations within its protohalo, and propagate that according to linear theory, L ∝ a 3/2 , until collapse. After collapse, treat L as constant. The median behavior of haloes is consistent with this. However, individual haloes can fluctuate substantially, and we leave vague what 'collapse' physically  Fig. 4, except summing particles' contribution to protohaloes' angular momenta cumulatively, starting from the center. Note the grey centers of almost all haloes. Each protohalo has a maximal grey sphere, centered at its centroid, that can fit in the protohalo. The total contribution to halo angular momentum within this sphere is zero, by Kelvin's circulation theorem. But regions outside this sphere contribute. Note that a halo center in this slice may not be grey if the 2D slice is far from the halo's 3D center. means, besides the turning point in this plot; this is something to investigate in future work.
The initial velocity field is a lower-order quantity than the tidal field, relatively easy to visualize. We find the idea of conservation (and linear-theory growth) of angular momentum within a collapsing body to be more intuitive than considering the tidal field, smoothed differently based on the scale of the protohalo, and its misalignment with the inertia tensor. This idea is more accurate, as well; as we show, the velocity field within each halo is rather random and retains much dispersion, but its sum still carries some net angular momentum. We also show how this picture can be used to understand the scaling of protohalo spin with mass, in terms of a correlated random walk.
This prescription can be applied to filaments and other elements of the cosmic web as well. We analyze a 2D simulation, in which the 'haloes' correspond at some level to cross-sections of 3D filaments. As is perhaps not widely appreciated, filaments do generically spin, according to this analysis. Filamentary (2D halo) spin grows with a 3/2 , just like 3D haloes.
Also, connecting halo spin directly to the velocity field, instead of the tidal field, may make spins easier to use to infer initial conditions from observations, as in Bayesian reconstruction methods (e.g., Kitaura & Enßlin 2008;Jasche & Lavaux 2015). Clusters spin particularly faithfully compared to the initial conditions, and occupy large volumes of Lagrangian space. In principle, it could be powerful to include these constraints on the velocity field.
Another possible application of this idea is to estimate the contribution to halo spin from initial vorticity. Vortical velocities inside collapsing protohaloes can be added up in the same fashion as from potential-flow velocities. Initial vorticity is usually thought not to have survived inflation, since a Fourier-space analysis predicts it to decay in linear theory. But what if some initial vorticity did exist? Suppose that the irrotational and vortical components of the velocity field had the same magnitude in the initial conditions. The spin from irrotational motions cancels out within a protohalo's maximal sphere, but not the spin from vortical motions. So, assuming modest asphericity, vortical motions would typically dominate the spin, surprising given that vorticity perturbatively decays not only in inflation, but also in the regime of an N -body simulation. The amplitude or degree of correlation of halo spin may be a test of primordial vortical, or vector modes, from inflation. It would be interesting to study halo and filament spin to see how much primordial vorticity might be hiding there.