Elastic Collisions of Particles on a One Dimensional Domain with

Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
Joshua Brach #100 789 120
[email protected]
COMP 4905 Honours Project
for Dr.
Evangelos Kranakis
S.C.S. Carleton U.
21st April, 2014
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
Abstract
Given a system of n perfectly elastic point-like particles on an infinite one-dimensional
frictionless domain with masses, initial positions, and initial velocities the system will
—after a finite time— reach a steady-state wherein no more collisions occur. The particles
are assumed to have no acceleration nor control over their motion, and the collisions
are taken to be instantaneous, governed by the classical principles of conservation of
momentum and kinetic energy, and involving exactly two particles. A natural question
is to ask: for arbitrary initial masses, positions, and velocities of n particles, what is the
finite number of collisions required to reach this steady state.
This question has been the subject of much research for at least a decade and while
n2 has been found to be an upper bound under certain conditions, no sub-exponential
bound has been found for the general case. This paper uses experimental methods to find
that in the general case the maximal number of collisions is in fact not bounded above by
a quadratic, though the average number of collisions over many simulations for a given
value of n follows a quadratic function of n.
1
Introduction
1.1
Problem
Consider n particles on an infinite one-dimensional domain. Each particle (i ∈ [1, n]) has
a mass mi , an initial position xi , and an initial velocity vi . The particles are assumed to be
point-like and indestructible. The latter assumption, along with the fact that the domain
has only one degree of freedom, means that particles cannot pass one another and thus the
ordering defined by the initial positions of the particles is preserved throughout the simulation.
Without loss of generality then, assume that the particles are numbered in increasing order of
initial position, i.e. assign i s.t. x1 < x2 < . . . < xn . Positions and velocities are represented
as real scalars and masses are assumed to be positive reals, i.e. xi ∈ R, vi ∈ R, mi ∈ R+ .
Moreover, initial positions are assumed to be unique and masses are assumed to be unchanged
by collisions or time. Particles are assumed to have no inherent acceleration and the domain
is assumed to be frictionless.
1 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
If the system is allowed to evolve, then the particles will collide. These collisions are
assumed to be instantaneous and governed by the kinematics for perfectly elastic collisions.
Specifically, for a collision between particles labelled 1 and 2 the velocities after the collision
vi0 are given by:
v10 =
v1 (m1 − m2 ) + v2 (2m2 )
m1 + m2
v20 =
v2 (m2 − m1 ) + v1 (2m1 )
m1 + m2
as derived from the principals of conservation of momentum and conservation of kinetic energy
(see appendix A). These equations are, of course, symmetric in the choice of labelling. In the
special case where the masses are equal, the equations simplify to v10 = v2 , v20 = v1 i.e. the
velocities of the particles are swapped. The considerations that must be made if the collisions
are allowed to be between three or more particles simultaneously are non-trivial. Thus in
this paper it will be assumed that individual collisions are only ever between two particles,
and initial conditions which would lead to such a non-binary collision will be excluded from
analysis. (E.g. n = 3; ~x = h−1, 0, +1i; ~v = h+1, 0, −1i will result in a three-particle collision
at the origin after one time unit.)
Such a physical system is guaranteed to reach steady-state after a finite number of collisions. This is easiest seen in the case where all masses are equal: eventually the velocities
of largest magnitude in both directions will ‘reach’ the final particle in their respective directions. At this point no other particle will be able to reach them again and thus they will
participate in no more collisions; they can be said to have ‘escaped’. This argument is then
repeated with all other velocities in each direction until all particles have escaped. Hence, by
induction, there is a final collision. The argument remains much the same in the case where
masses are unequal, except that velocities are not simply exchanged. Eventually the particles
on the edge of the un-escaped portion will each take on a velocity such that no other particle
will overtake them. A reader who is unconvinced that such a velocity will arise should consider the implications of the fact that —as a closed system— the total kinetic energy of the
system is constant (i.e. velocities in the centre cannot be spontaneously increasing) and that
entropy must increase. To detect this steady-state one needs only verify that the velocities of
2 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
the particles are sorted in increasing order relative to position, i.e. such that:
∀ i, j ∈ [1, n], i 6= j ∧ xi < xj =⇒ vi ≤ vj
(which, when numbered as described above, is more compactly stated as i < j =⇒ vi ≤ vj ).
The question then arises: What is the number of collisions that will occur in such a system
of n particles? It will be seen in section 1.3 below that in some cases this number can be
found exactly, but in the general case the number of collisions is not a function of n only
(in fact there most likely does not exist such a closed-form function for the exact value, even
with all of the initial conditions supplied as parameters). Therefore an upper bound and an
expectation value are desired instead (the lower bound is trivial since the system can begin
in a steady-state). The same question is equivalently asked when posed as: How many steps
are required to sort the list of velocities?
In this paper and others (esp. [11]) this problem is referred to in the context of elastic
collisions of particles. In others still (esp. [3] & [2]) refer to this problem in the context of
hard-ball systems on an n dimensional billiards table. The problem can also be expressed
(esp. [4] & [5]) in context of mobile robots, as particles are essentially mobile robots which
have no control over their motion. All of these contexts address the same underlying problem.
1.2
Preliminaries
A system as described above in section 1.1 is denoted as an ordered pair S = (n, m,
~ ~x, ~v )
where m
~ = hm1 , . . . mn i is the vector of given masses, ~x = hx1 , . . . xn i is the vector of given
initial positions, and ~v = hv1 , . . . vn i is the vector of given initial velocities. The actual number
of collisions that occur in such a system is denoted N (S) and the number of collisions that
occur in a system of n particles is denoted N (n). In general, N (n) is a random variable.
In this paper units have been omitted for all physical quantities, as the absolute values
are irrelevant. It can be assumed that masses are expressed in kilograms, positions in meters,
velocities in meters per second, and time in seconds. Nevertheless, interpreting the values
3 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
as grams, kilometres, kilometres per hour, and hours respectively will have no affect on the
results of this paper. (This is true for any combination such that the unit of velocity is the
unit of position divided by the unit of time, as all other units cancel in each physical formula
applied in this paper.)
The following definitions and notation are used for number systems. The Integral Numbers,
also referred to as the Integers, are denoted Z. The various partitions of the Integers are
referred to by specific terms: the positive Integers, also referred to as the Natural Numbers,
are denoted Z+ ; the non-negative Integers, also referred to as the Whole Numbers, are denoted
Z≥0 = Z+ ∪ {0}; the negative Integers are denoted Z− ; and the non-positive Integers are
denoted Z≤0 = Z− ∪ {0}. Similarly, the Real Numbers, also referred to as the Reals, are
denoted R, and the positive Reals, negative Reals, non-positive Reals, and non-negative Reals
are denoted by R+ , R− , R≥0 , R≤0 respectively.
Arrays are denoted in vector notation (e.g. ~•) and delimited by angle brackets (e.g. h. . .i).
Array accessors are denoted with square brackets (e.g. ~a[•]) when the array is not in its original
sorted order (i.e. it may be that ~a[i] 6= ai ), that is to say subscripts represent individual
elements whereas accessors represent elements at a position in an array. The binary relations
• < • and • ≤ • compare element values (‘less-than’ and ‘less-or-equal’ respectively) whereas
the relation • ≺ • compares element positions in an array (‘precedes’). All arrays are onebased arrays.
Ranges are denoted in interval notation, where ‘z ∈ [a, . . .’ denotes a closed lower bound
(i.e. z ≥ a), ‘z ∈ (a, . . .’ denotes an open lower bound (i.e. z > a), ‘z ∈ . . . , b]’ denotes a closed
upper bound (i.e. z ≤ b), and ‘z ∈ . . . , b)’ denotes an open upper bound (i.e. z < b).
An inversion in a list ~a = ha1 , . . . , an i is defined to be any pair of elements ai , aj such that
ai ≺ aj ∧ aj < ai . Note that this definition includes all such pairs, rather than counting each
‘out of order’ element only once. The number of inversions in a list is used in this paper as
the measure of ‘sortedness’ in that list. Since the only list discussed herein for which that
matters is the list of velocities (in order of increasing position as described above and taken
at any instant as the system evolves) the word inversion is often used in place of the term
4 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
velocity inversion or equivalently inversion in the list of velocities. In the steady-state the
number of inversions is zero since the velocities are sorted in increasing order. The number
of inversions is bounded below by zero (when the list is sorted in increasing order) and above
by n(n − 1)/2 ∈ O n2 (when the list is sorted in decreasing order).
1.3
Related Work
It has been shown by Chen [3] that the number of collisions is quadratic in n under the
restriction that the mass of every internal particle is greater than or equal to the geometric
mean of its immediate neighbours. Specifically:
∀ i ∈ (1, n), mi ≥
n(n + 1)
√
∈ O n2
mi−1 · mi+1 =⇒ N (n) ≤
2
This is in fact an improvement on an earlier restriction [10] requiring that the mass of
every internal particle be no less than the arithmetic mean of its immediate neighbours.
(The geometric condition is a lesser restriction, i.e. favourable, due to the inequality of
√
the means: (a + b)/2 ≥ 2 a · b) Naı̈vely, this restriction does not seem significant, being a
lower bound. However, since masses are restricted to non-zero positive numbers, this restricts each neighbour of each internal mass to be no greater than the square of the internal
mass divided by the other neighbours. For example, three consecutive particles with masses
mi−1 = mi+1 = 2mi would not satisfy the geometric condition. It is therefore still desirable
to find an upper bound on the number of collisions for systems without this condition.
Burago et al. provide a complex analysis of the general case [2] and prove that the number
of collisions is finite by arriving at the conclusion:

N (n, m)
~ ≤ 400n2
max
i∈[1,n](mi )
min
i∈[1,n](mi )
2n4

4
∈ O n4n · mmax /mmin
Sevryuk has provided a loose upper bound [11] which is an improvement, though still
5 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
exponential in n. Using hypergeometric arguments the explicit estimate is found to be:

N (n, m)
~ ≤ 2 8n2 (n − 1)
max
i∈[1,n](mi )
min
i∈[1,n](mi )
n−2

∈ O n3n · mmax /mmin
The problem has also been analyzed with specific values for n in two dimensions by Murphy
[9] in depth and by Sevryuk [11] briefly. To the best of my knowledge the literature does not
contain an upper bound on the number of collisions in the general case of unrestricted masses
with n particles.
The remainder of this report is laid out as follows. Section 2.1 contains a description of the
simulation which was developed to analyze this problem, including the core algorithm 2.1.1
and analysis of the integrity of the simulation 2.1.2. Section 2.2 provides a statistical analysis
of the maximal number of collisions found by repeatedly running the simulation versus the
number of particles simulated. The analysis is done including all simulations, and then is
repeated with only those which have masses satisfying the geometric condition, and then only
those which have masses that do not satisfy the geometric condition. The later two are done
to test the statistical methodology and to isolate the unrestricted condition. The paper is
concluded in section 3.
2
Contributions
It appears from the survey of the literature that existing methods for deducing a closed
form (that is to say, a precise and certain) upper bound fall short of producing a tight upper
bound. Therefore rather than pursuing a hypergeometric or algebraic method, this paper
attempts a statistical method. As this problem has at its core a physical scenario, it lends
itself easily to simulation. Specifically, since the number of collisions is both the unknown
quantity and the determinant of the running time of any such simulation, this problem lends
itself easily to a ‘Las Vegas’ simulation (i.e. one for which the running time is probabilistic
but the result is correct with certainty). Such a simulation was developed for this paper and
is described here in section 2.1. An analysis of the upper bound on, and the average case of,
6 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
the number of collisions is presented in section 2.2 from amalgamated results over many runs
of the simulation.
2.1
Simulation
A Las Vegas simulation was developed in the Processing [6] dialect of the Java programing
language. Development, testing, and execution was done on Apple’s OS X 10.8.5 environment using Intel Xeon processors, however, as Processing is a cross-platform environment the
program will compile for all major modern operating systems. Processing is very useful for
rapid, iterative development and prototyping. After prototyping the simulation in Processing
and analyzing its performance it was determined that developing the production version in
C++ or C would not offer significant performance gains. Complete source code and documentation can be found at http://people.scs.carleton.ca/~jbrach/honours/ both for
browsing over http and archived (in file ./complete.tar) for downloading.
One disadvantage to using Java in a computation-intensive simulation is that garbage collection runs non-deterministically and can take a disproportional amount of time. This problem is exacerbated when small objects are rapidly created and destroyed, known as ‘thrashing
the heap’. To avoid this, the classes were written with reset() methods, which the constructors call, to allow for object reuse rather than rapid construction/destruction cycles.
The simulation program has various parameters to configure the number and properties
of simulations to run. At this time the parameters are compile-time settings rather than
run-time settings, as this is most suitable for the rapid iterative style of Processing development. It would be a minor modification to allow command line arguments to specify these
settings at run-time. The program runs in a batch style by default: it runs NUM EXPERIMENTS
simulations each for every value of n from MIN PARTICLES (nmin ) to MAX PARTICLES (nmax )
incrementing by PARTICLES INC (ninc ). To configure the program to run a single simulation,
the parameters nmin and nmin should be set to the same value, and the number of simulations per number of particles should be set to 1. The number of simulations per number of
particles (parameter NUM EXPERIMENTS) allows for control over the statistical significance of
7 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
the consolidated results, as discussed further in section 2.2.
The randomly generated initial conditions can be configured via the parameters MAX MASS
(mmax ), POSITION INTERVAL (xmax ), and VELOCITY INTERVAL (vmax ). The masses shall be
selected uniformly from the half-open real interval (0, mmax ] and the initial positions and
velocities shall be selected uniformly from the closed, symmetric real intervals [−xmax , +xmax ]
and [−vmax , +vmax ] respectively. All randomly generated quantities are chosen from the
uniform distribution. Random selection is represented in the pseudocode of this section by
the keyword select.
The simulation can run with one of three characteristics for the mass vectors: all masses
equal, all masses equal except for one randomly chosen, or all masses randomized. These
modes are selected via the Boolean parameters ALL MASSES EQUAL and ALL MASSES RANDOM.
Only one of these parameters can be set to true for any execution of the program. If neither
of these parameters is set to true, then exactly one mass (at a random index in the original
array) will be randomized and the rest will be set to equal values.
There are a small number of error conditions which indicate that the initial conditions
for the current simulation were invalid. For statistical purposes, when such a condition is
encountered the simulation terminates prematurely and it does not count against the number
of simulations run for that number of particles. This immediate termination is represented in
the pseudocode of this section by the keyword report.
The final non-standard keyword used in this section is the keyword sort. In the Processing
implementation sorting is done via insertion sort, which takes O n2 time but runs in place
and iteratively. In a future version this may be replaced with e.g. quicksort which may provide
a moderate performance increase as it runs in O(n lg n) time. Since sorting is done only once
per simulation, the simplicity of insertion sort was preferable.
8 / 26
21st April, 2014
2.1.1
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
Algorithm
Rather than have an algorithm which advances by a fixed quantum of time, the standard
for graphically modelling a kinematic scenario, the algorithm employed by this simulator was
designed to calculate the time until the next collision at each iteration and advance by that
amount of simulation time. This is favourable in this situation because the simulation is
not animated as (nor after) it unfolds, and it is obviously beneficial to the total running
time. Since there are no external forces, the system evolves in a precise and constant manner
between collisions, described by the simplest kinematic equation: x0 = x + t · v. The only
phenomena that are not adequately described by this formula are the collisions themselves,
hence the only computation that needs to occur is that of the collisions. Thus an iteration of
the algorithm is as follows: time between collisions is skipped, the particle positions are each
advanced to the time of the next collision according to their current position and velocity,
and then collisions are calculated. The running time is therefore directly proportional to the
number of collisions which must occur to reach the velocity-sorted state, i.e. the result.
The high-level algorithm that the simulator object runs (algorithm RunSimulation)
is described in pseudocode below. The iteration step has been factored out into its own
pseudocode listing (algorithm AdvanceSimulationState) below that for readability and
to emphasize that process, which is the essence of the simulator. The finer points of the
pseudocode are also described below each algorithm.
9 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
Algorithm: RunSimulation
Input: n ∈ Z+
Output: N ∈ Z≥0
[1]
begin
[2]
select m
~ = hm1 , . . . , mn i s.t. mi ∈ (0, 2] ⊂ R+
[3]
select ~x = hx1 , . . . , xn i s.t. xi ∈ [−1, 1] ⊂ R
[4]
select ~v = hv1 , . . . , vn i s.t. vi ∈ [−2, 2] ⊂ R
[5]
if ∃ i, j ∈ [1, n] s.t. i 6= j ∧ xi = xj then report error
[6]
sort ~x, m,
~ ~v s.t. ∀ i, j ∈ [1, n], i < j =⇒ ~x[i] < ~x[j]
[7]
N := 0
[8]
while ∃ i, j ∈ [1, n] s.t. i < j ∧ ~v [i] > ~v [j] do
[9]
[10]
AdvanceSimulationState(N,m,~
~ x,~v )
return N
The algorithm RunSimulation takes as input only the number of particles to simulate,
n, and provides as output the total, finite number of collisions which take place, N . As
only n is provided, on lines
[2], [3],
&
[4]
the masses, initial positions, and initial velocities
(respectively) of each of the n particles is randomly generated. Selection is done randomly
and independently from the uniform distribution over the specified ranges.
The condition on line
[5]
tests for the uniqueness of initial positions, and enforces it by
reporting an error and terminating if the initial positions are not unique. In the Processing
implementation this is handled by recursively invoking the reset() method (which implements lines [2] through [7] of this pseudocode) to regenerate the arrays. Since the probability
of generating two or more identical double-precision positions is very small, the probability of
doing so multiple times is vanishingly so. Therefore the recursion will terminate with almost
certainty.
The sorting of the vectors on line
[6]
is done to all three vectors concurrently. That is to
say, it preserves correspondence of elements between the three vectors. This is simply done by
sorting the positions as per the sort criterion, and swapping the elements of the masses and
10 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
velocities at the same indices any time a swap is carried out on the position vector. Therefore
after the sorting on line
[6]
the elements mi , xi , & vi may no longer be in their original
positions, but it must be the case that ~x[j] = xi ⇐⇒ m
~ [j] = mi ⇐⇒ ~v [j] = vi .
The condition on line [8] is a test to determine whether the list of velocities is in increasing
order (i.e. strictly non-decreasing, velocities may be equal). Therefore the end-condition of
the simulator run algorithm is that in which the velocities are sorted in order relative to their
respective positions (as the velocities were originally sorted on line
[6]
and particles cannot
pass one another as explained above in section 1.1). This is equivalent to the state in which
no further collisions will occur as explained in that same section.
The simulation step subroutine invoked on line
[9]
takes as parameters the number of
collisions thus far, the list of masses, the list of current positions, and the list of current
velocities. It updates the values of the number of collisions, the values of each of the positions,
and the values of a (generally) small subset of the velocities. For simplicity’s sake, these are
denoted implicitly as if using a ‘pass-by-reference’ invocation strategy rather than a ‘multiplereturn’ strategy. This algorithm is described in pseudocode next and explained below.
11 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
Algorithm: AdvanceSimulationState
Input: N , m,
~ ~x, ~v
Output: N , ~x, ~v
[1]
begin
[2]
C := ∅
[3]
t := +∞
/* determine time until next collision...
[4]
[5]
[6]
foreach i ∈ [1, n) do
xi − xi+1
ti :=
vi+1 − vi
min (t s.t. t > 0)
t := i∈[1,n)
i
i
/* determine left particle of each collision...
[7]
foreach i ∈ [1, n] do
[11]
~x[i] := ~x[i] + t · ~v [i]
else report error
/* calculate post-collision velocities...
[13]
[14]
[15]
[16]
[17]
*/
if t ∈ (0, ∞) then
[10]
[12]
*/
if ∃ i ∈ [1, n) s.t. i ∈ C ∧ i + 1 ∈ C then report error
/* advance positions to those at the determined time...
[9]
*/
C := {i s.t. ti = t}
/* check for triple collisions
[8]
*/
*/
foreach i ∈ C do
ui
:= ~v [i]
ui+1 := ~v [i+1]
~v [i] · (m
~ [i] − m
~ [i+1]) + ~v [i+1] · (2m
~ [i+1])
~v [i] :=
m
~ [i] + m
~ [i+1]
~v [i+1] := u1 + ~v [i] − u2
/* increment number of collisions...
[18]
N := N + |C|
[19]
return
12 / 26
*/
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
The algorithm AdvanceSimulationState takes as input the number of collisions thus
far, the lists of masses, current positions, and current velocities i.e. the current simulator
state. The output of this algorithm is in the form of updating these parameters (though
masses remain unchanged). The algorithm first calculates the time until the next collision
between each pair of particles. Note that since particles are sorted in order of position, a
particle can only collide with either of its immediate neighbours. Therefore a simple single
pass iteration over the particles is sufficient. This is the main advantage to sorting the
particles at initialization (the other being testing for the simulation end-condition). The
values ti calculated on line
[5]
represent the time until the particle i and the particle i + 1 are
collocated. This value will be negative if the intersection of the particles’ current trajectories
is in the past, since particles travelling in straight lines (as these are, between collisions) will
collide only once. Therefore when determining the minimum time-until-next-collision (on line
[6])
it must be taken into account that the ‘next’ collision must be in the future i.e. t > 0 (the
case of t = 0 is discussed below in section 2.1.2). This means that the minimum operator may
fail to find an adequate value; in this case it is assumed that the previous value (t initialized
to positive infinity on line
[3])
remains unchanged i.e. the assignment simply fails to update
the value. The set C, representing the indices of the left particle of each pair colliding at the
determined time, is populated with any and all such indices on line
[7].
In the Processing
implementation, both the minimum operator and the set population are each O(n) operations
(being linear searches) and are in fact determined as each ti value is calculated.
The use of a collision set makes allowances for the fact that there may be concurrent
collisions between distinct pairs of particles. This algorithm advances to the time of the
next collision and performs all collisions which take place at that time. It also allows for
a simple means by which non-trivial collisions (i.e. those between three or more particles)
can be detected. The condition on line
[8]
once again uses the fact that the particles are
in sorted order by enforcing that no two consecutive particles may each be the leftmost
particle in a concurrent collision. (If i ∈ C then there is a collision between particles i and
i+1, and if i+1 ∈ C then there is a collision between particles i+1 and i+2. Therefore if
i ∈ C ∧ i+1 ∈ C on the same step then there is a concurrent non-binary collision between
13 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
particles i, i+1, and i+2. Compare this with i ∈ C ∧ i+2 ∈ C which implies two distinct
collisions.) As discussed in section 1.1, this occurrence implies that the initial conditions
for this simulation are not included in this study and so an error is simply reported. The
Processing implementation handles the tripple-collision failure by resetting and restarting the
simulation without incrementing its counter for number of simulations executed.
If the determined time-until-next-collision is a valid (i.e. future and finite) time, then
the position of each particle is advanced by that time according to the simple kinematic
equation on line
[11],
otherwise an error is reported (line
[12])
since the next collision has
been determined to be in the past (i.e. there are no more future collisions, or equivalently the
steady-state has already been reached but the simulation has failed to terminate). This error
is handled by the Processing implementation in the same way as the tripple-collision error.
Finally, for each collision pair the current velocities (stored temporarily on lines
[14]
and
[15])
are convoluted according to the kinematic equation for a perfectly elastic collision on
lines
[16]
and
[17].
To reduce the computational load, once one of the velocities has been
computed according to the equation the second can be obtained from the relation of the sums
of initial and final velocities of each particle (i.e. the sum of the velocities before and after for
one particle is equal to that of the other particle, see appendix A) as is done on line [17]. The
number of particles is incremented by the number of collision pairs which were computed in
this step, and the algorithm terminates.
A final note about this later algorithm is that, while it is overall necessarily sequential,
it has embarrassingly parallelizable components. Specifically, the three foreach loops are
all single instruction, multiple data (SIMD) parallelizable candidates, since each relies only
on two consecutive values of two arrays and none rely on the result of a previous iteration
of that loop. Since it is expected that the number of concurrent collisions at any instant is
most likely one, |C| is most likely small and so there is likely little benefit to employing SIMD
parallelization to the loop on line [13]. However, the loops on lines [4] and [10] must necessarily
iterate over every element in the arrays, and so as n becomes very large, parallelization of
these loops becomes increasingly beneficial. Preliminary analysis shows that as much as 40%
of CPU time may be spent in the loop on line
[4].
14 / 26
While the Processing implementation
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
does not take advantage of this fact, a future version could leverage general purpose GPU
technologies such as OpenCL to gain a significant performance increase.
The running time of the algorithms presented above are analyzed as follows. Computations
are assumed to be constant time operations. Search operations and existence conditions are
assumed to be linear time operations. Membership tests are assumed to be constant time
operations. Each random generation of a single element is assumed to be constant time.
Therefore the running time of the algorithm AdvanceSimulationState is given by the sum
of a linear factor for each of: the loop on line
the existence condition on line
[8],
[4],
the loop on line
the search operations on line
[6]
[10],
(since |C| is
and the loop on line
bounded above by n) as well as a constant factor on lines
[2], [3],
and
[18].
[13]
and
[7],
Critically: since
none of the loops contain operations of greater than constant time, the total running time of
the algorithm AdvanceSimulationState is bounded above by O(n). The running time of
the algorithm RunSimulation is given by the sum of a linear factor for each of three random
selections of n items on lines [2], [3], and [4]; a linear factor for the existence condition on line
[5];
a (best implementation) log-linear factor for the sorting on line
[6];
and a term for the
while loop on line [8], which repeats N times and consists of a linear time existence condition
and an invocation of the linear time algorithm AdvanceSimulationState, for a total time
of O(N · n) for the while loop. Therefore the running time of the algorithm RunSimulation
is bounded above by O(N · n + n lg n) ⊆ O(N · n) if N ≥ lg n. In fact, even with a quadratic
time sorting algorithm, the running time will still be O(N · n + n · n) ⊆ O(N · n) if N ≥ n.
2.1.2
Integrity
The pseudo-random number generator for the simulation was chosen to be the MersenneTwister algorithm [8] first presented by Matsumoto & Nishimura. Specifically, the Java
implementation MersenneTwisterFast [7] was used.
This algorithm is a research-grade
pseudo-random generator with a very large period, which makes it suitable for random sampling of a large parameter space. The default Java random number generator is wholly
insufficient and is, in fact, slower than the implementation incorporated here. An additional
benefit to the use of the MersenneTwister algorithm is that, given the same seed, it will
15 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
deterministically produce an identical sequence on any implementation of the Java VM on any
platform. Thus to allow for repeatability tests the random seed is output in the results file of
the simulation, and can be specified using a compile time parameter. (In the multi-core code,
a ‘master seed’ is used to generate a deterministic sequence of adequately pseudo-random
seeds for each simulator which executes concurrently, thus in principle the multi-core code
maintains this repeatability property from the single-core code. In practice, since the order in
which simulations are assigned to simulators is dependent on the relative speed of each thread
which in turn is sensitive to such simple things as other processes running on the CPU, the
multi-core code is non-deterministic. This is not a critical property in this paper, but if the
simulation is reused for other research in which it is necessary then either the single-core code
can be used, or the multi-core code could be made to synchronize on assignment of simulations
to simulators which would be a simple modification with a small impact on performance.)
Do to the nature of floating-point numbers, it is possible that the positions of two particles
which are colliding in a given step may have up to 5 (as found in testing) ‘units-in-the-lastplace’ (ulps) difference. That is, despite the fact that the time until the next collision was
computed from the previous positions and velocities of the two particles that are now colliding,
it may be the case that when the calculations were (independently) carried out to advance
the position by that amount of time the calculated positions were not in fact identical. This
error could be in either direction, i.e. a particle may advance to a position a few ulps short of
the actual point of collision or it may be that a particle advances to a position a few ulps past
the actual point of collision, and each particle could make either error independently. The
concept of measuring in ulps is to address the fact that the absolute difference in values of
consecutive representable floating-point numbers depends on the order of magnitude of those
values. The IEEE floating-point encoding was designed such that the binary representation of
consecutive values differ by binary addition of a single unit in the least significant bit. Hence
the best measurement of the difference between close floating-point numbers is the number
of ulps i.e. the number of representable values between the numbers. Since many of the tests
and computations carried out by the algorithm rely critically on the fact that the particles
are in sorted order with respect to position, if the simulation is permitted to enter a state in
16 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
which the positions are out of order (as may be the case if the simulation advances after the
positions of two particles are inverted by a difference of a few ulps in the wrong direction)
then the internal state of the simulation is very quickly corrupted and an unrecoverable error
occurs. Therefore at the time of collision the actual positions are compared and, if they differ
by any number of ulps, they are set to be identical. The actual point of collision is determined
by either the average, or if that fails by arbitrarily selecting one particle to have the correct
position.
Another implication of the use of double precision floating-point numbers is that it is
possible that two collisions which physically would occur sequentially must be performed
concurrently, if the time between collisions is less than one ulp. For this reason a simple
comparison with zero is insufficient to determine if a collision has just occurred. This is
addressed by the inclusion of a Boolean flag in the particles’ state which is set to true if
and only if that particle has just collided in the step immediately prior. This also adds to
the likelihood that multiple binary collisions occur concurrently, necessitating the use of the
collision set as described above.
2.2
Statistical Analysis of Unrestricted Case
The simulator program described above in section 2.1 was used to run an experiment in an
attempt to determine a statistically significant upper bound to the number of collisions for a
system (as described above in section 1.1) with n particles. Based on preliminary simulations
with arbitrary masses, this experiment was designed to test the following hypothesis. If a
statistically significant number of simulations are run with arbitrary masses for each of a
large range of n values, then the maximal results will follow a quadratic distribution. That
is, while the literature review did not reveal an analytic proof that N (n) ∈ O n2 in the
general case, it is hypothesized that this is indeed the upper bound if the geometric condition
is removed entirely. Therefore the simulator was run 100 times with each even n ∈ [100, 1000].
The choice to increment by two was influenced by the needs for both speed and density of
data points.
17 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
The 100 results for each value of n were ‘consolidated’ into a data points according to two
functions: the maximal result was taken to be one data point and the (rounded) arithmetic
average of the results was taken to be another. These data points were then amalgamated into
the two series seen in figure 1 below. A few representative histograms showing the probability
distribution of simulation output for single data points are presented in appendix C
It was chosen that, when randomly generating initial conditions for any given run of the
simulation, the masses shall be selected uniformly from the real interval (0, 2] and the initial
positions and velocities shall be selected uniformly from the closed real intervals [−1, +1]
and [−2, +2] respectively. This obviously does not cover all possible combinations of initial
conditions, but it does cover a comprehensive range of ratios between various components of
the initial conditions. Given the nature of the problem the ratios of masses and speeds are
much more significant than their absolute values. Moreover, given that the simulation must
represent the values by double-precision floating-point numbers, a large (but finite) number
of ratios can be represented from these intervals without the risk of loss of precision that may
occur when evaluating a binary operation on floating-point numbers of very different orders
of magnitude. All randomly generated quantities are chosen from the uniform distribution.
In general, there is no reason to assume the distributions of masses, positions, or velocities
would be anything else, however, given a specific domain it might become useful and more
accurate to model e.g. the masses by a normal distribution.
18 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
×103
Number of Collisions which Occurred (N)
1800
Maximal Num. Collisions per 100 Simulations
Average Num. Collisions per 100 Simulations
1600
N = 0.378 · n2 + 0.093 · n + −90.768
1400
1200
1000
800
600
400
200
0
0
200
400
600
Number of Particles Simulated (n)
800
1000
Figure 1: Consolidated Number of Collisions Per Number of Particles
Figure 1 shows the relation between maximal number of collisions versus number of particles in red and the relation between average number of collisions versus number of particles in
blue. It can clearly be seen from the figure that the maximal results are not in fact bounded by
a quadratic. The design of the simulation is such that it gives a one-sided error with regards
to the maximum number of collisions possible: the result obtained on any given run may
—conditional on the random initial conditions— be less than the maximum, but it cannot
be greater than the maximum by its nature. Therefore the outlying data points can not be
dismissed. While evidently rare, it is certainly possible for a system (as described in section
1.1) to require many more collisions to reach the steady-state than the surrounding quadratic
average would suggest. Of course, a quadratic function could be parametrized such that all
of the data points are bounded, by setting the highest order co-factor to an obscenely large
value, but that would undermine the validity of the statistical motivation. Therefore the
hypothesis that the maximal number of collisions will be quadratic bounded is rejected.
The outliers notwithstanding, the average results are almost perfectly quadratic. The
average series in figure 1 has been fit to a quadratic distribution (N (n) = a2 · n2 + a1 · n + a0 )
19 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
by the ROOT framework, and the fit was plotted in green. It resulted in the parametrization
.
.
.
a2 = (0.378 ± 0.001), a1 = (0.09 ± 1.41), and a0 = (−90.77 ± 310.26) with a χ-squared value
.
of χ2 = 2.4 · 109 with 493 degrees of freedom. Qualitatively this is a perfect fit. Therefore it
should be noted that while the maximal case may not be bounded by a quadratic, the average
case almost certainly is.
It should be noted that absolutely none of the uniformly distributed mass vectors generated
while collecting the data for figure 1 satisfied either geometric condition nor the arithmetic
condition. This was not expected, but lends credibility to the qualitatively quadratic results
displayed in the figure as none of the results can be attributed to the already proven quadratic
nature of systems which satisfy the conditions. It also validates the search for a more general
bound, as the well understood case is apparently vanishingly rare.
3
Conclusions
A simulation of the physical scenario at the core of the problem was developed and used to
generate a statistically significant quantity of data. This data was analyzed and it was found
that while most of the data fit a quadratic distribution, there existed a small but compelling
number of outliers which could not be dismissed and which were clearly not bounded by any
reasonable quadratic in n. Nevertheless it was found that in the average case the number of
collisions for a given number of particles obeys a quadratic function with leading term 0.38,
i.e. N (n) ≈ 0.38n2 .
This line of work suggests a number of areas of future research. To perform a more
comprehensive search of the parameter space the simulation performance could be improved,
for example by taking advantage of the embarrassingly parallelizable SIMD loops pointed out
in section 2.1.1. A widened search of the parameter space would also be interesting, especially
if a region could be found in which systems which satisfy one or both of the geometric and
arithmetic conditions were relatively common. The results found here suggest that searching
for an analytic proof of N (n) ∈ O n2 is futile, but they fail to suggest that no such sub
exponential bound exists. However, an analytic proof for the average case i.e. N (n) ∈ Θ n2
20 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
may be a worthwhile pursuit.
The knowledge of the finite behaviour in the average case could be used to moderately
extend the work of Kranakis et al. in (for example) [4] & [5]. Specifically, their results can
be generalized to arbitrary masses with the caveat that their subsequent results would then
be average case results. Given the rarity of the outlying cases, it seems that the practical
implications of an average case result for the real-world applications described in both [4] &
[5] would be negligent. Given the rarity of systems in the parameter space which satisfy the
conditions required for the analytic upper bound, such a generalization may be necessary for
the results to apply to those same real-world applications, unless the restriction is arbitrarily
enforced by some outside entity (e.g. if the robots were specifically manufactured with equal
masses).
This work would not have been possible without Dr. Evangelos Kranakis, who both introduced the problem to me and was an invaluable source of guidance and inspiration. I am
indebted to him for his assistance.
21 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
Appendices
Appendix A
Derivation of Kinematic Equations
Derivation of equality of the sum of pre- and post- collision velocities per particle for
perfectly elastic collision between two particles (as used on line
[17]
of algorithm AdvanceS-
imulationState) from conservation of kinetic energy and conservation of momentum:


 m1 v1 + m2 v2 = m1 v10 + m2 v20
by conservation of momentum

 m1 v 2 + m2 v 2 = m1 v 0 2 + m2 v 0 2
1
2
1
2


 m1 (v1 − v10 ) = m2 (v20 − v2 )
by conservation of K.E.

 m1 (v 2 − v 0 2 ) = m2 (v 0 2 − v 2 )
1
∴
1
2
2
v1 − v10
m2
v12 − v10 2
=
=
v20 − v2
m1
v20 2 − v22
v1 − v10
(v1 + v10 )(v1 − v10 )
=
v20 − v2
(v20 + v2 )(v20 − v2 )
v1 + v10
1= 0
v2 + v2
by diff. of squares
∴ v20 = v1 + v10 − v2
Derivation of velocity convolution for perfectly elastic collision between two particles (as
used on line
[16]
of algorithm AdvanceSimulationState) from previous result and conser-
vation of momentum:


 m1 v1 + m2 v2 = m1 v10 + m2 v20


v20 = v1 + v10 − v2
by conservation of momentum
from above
∴ m1 v1 + m2 v2 = m1 v10 + m2 (v1 + v10 − v2 )
m1 v1 + m2 v2 = (m1 + m2 )v10 + m2 v1 − m2 v2
(m1 + m2 )v10 = m1 v1 + m2 v2 − m2 v1 + m2 v2
v10 =
v1 (m1 − m2 ) + v2 (2m2 )
m1 + m2
22 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
Derivation of the time of collision for two particles with constant velocity (as used on line
[5]
of algorithm AdvanceSimulationState) from kinematic formula for the position of a
body with no acceleration:
x0i = xi + vi · t
x1 + v1 · t = x01 = x02 = x2 + v2 · t
by kinematic formula
by def. of collision
x1 − x2 = (v2 − v1 ) · t
∴ t=
Appendix B
x1 − x2
v2 − v1
Source Code
Source code can be downloaded either at
people.scs.carleton.ca/~jbrach/honours/complete.tar
or from the mirror
josh.brach.ca/honours-project/complete.tar
The source code is also available on those servers for browsing via http.
Appendix C
Distributions of Simulator Results
The following figures are histograms showing the distribution of the 100 results obtained
by individual runs of the simulation for certain values of n. The data has been binned for
ease of reading. Figures 2a, 2b, & 2d represent arbitrary selections from three regions of the
range. Recall that nmin = 100 and nmax = 1000. The value n = 400 was chosen to be in
region where the maximal results where still qualitatively ‘well-behaved’ (see the Maximal
data set in figure 1). These three plots are presented over a domain of 6 units with 10 bins
in each unit for a total of 60 bins. Note that the abscissa is scaled by a factor of 103 . Figure
2c shows the distribution of the results obtained for n = 670, which is one of the outliers in
figure 1. This figure is interesting in particular because it shows that the maximal value is
indeed an outlier even within the ‘unconsolidated’ data. It is presented over a domain of 20
23 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
units with 50 bins in each unit for a total of 1000 bins, the larger number of bins is to achieve
a comparable resolution while displaying the entire domain.
100
3759
706.1
Entries
Mean
RMS
12
10
100
5.96e+04
RMS
6483
12
Frequency of Result
Frequency of Result
Mean
Entries
14
8
6
10
8
6
4
4
2
2
0
2000
3000
4000
5000
6000
Number of Collisions (N)
7000
0
8000
(a) Distribution for N (n) = N (100)
Mean
1.872e+05
RMS
1.712e+05
70
Number of Collisions (N)
80
×103
100
90
16
7
14
6
5
4
Mean
3.861e+05
RMS
4.21e+04
12
10
8
3
6
2
4
1
100
Entries
18
Frequency of Result
Frequency of Result
60
(b) Distribution for N (n) = N (400)
8
0
50
100
Entries
9
40
2
0
200
400
600
800
1000
1200
Number of Collisions (N)
1400
1600
1800
×103
2000
(c) Distribution for N (n) = N (670)
0
200
300
400
500
600
Number of Collisions (N)
700
×103
800
(d) Distribution for N (n) = N (1000)
Figure 2: Distribution of Results from Simulations Consolidated in figure 1
Additionally, the simulator was executed with slightly altered parameters to produce a
higher resolution distribution for a single value of n. Figure 3 shows the resultant histogram of
1000 values obtained for N (600). The value n = 600 was chosen arbitrarily as a representative
of the region of figure 1 in which the outliers were present, i.e. a candidate to produce such
an outlier. It is interesting to note that no such outlier manifested during this execution.
The distribution has asymmetric tails which qualitatively appear to match those of a Gamma
Distribution, however an attempt to fit that distribution to the histogram failed to result in
a quantitative match. Therefore the best conclusion to draw from this distribution is the
qualitative observation that it has a sharp peak with a relatively small full-width-at-halfheight, a short left tail, and a long asymptotic right tail.
24 / 26
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
21st April, 2014
J. Brach
10000
Entries
100
Mean
1.366e+05
RMS
1.383e+04
280
×103
300
Frequency of Result
80
60
40
20
0
100
120
140
160
180
200
220
Number of Collisions (N)
240
260
Figure 3: Distribution of Results for 1000 Simulations run with n = 600
References
[1] Brun, René & Fons Rademakers. “ROOT - An Object Oriented Data Analysis Framework.” Nucl. Instr. Meth. Phys. Res. A, 389 (1997): 81-86. http://root.cern.ch/
[2] Burago, D., S. Ferleger, & A. Kononenko. “Collisions in semi-dispersing billiard on Riemannian manifold.” Topology and its Applications, 122(12) (2002): 87-103.
[3] Chen, Lizhou. “Proof of Murphy-Cohen Conjecture on One-Dimensional Hard Ball Systems.” Chinese Annals of Mathematics, Series B 28.3 (2007): 293-298.
[4] Czyzowicz, Jurek, Evangelos Kranakis, & Eduardo Pacheco. “Localization for a system of
colliding robots.” Automata, Languages, and Programming. Springer Berlin Heidelberg,
(2013): 508-519.
[5] Czyzowicz, Jurek, S. Dobrev, Evangelos Kranakis, & Eduardo Pacheco. “Survivability of
Swarms of Bouncing Robots.” Latin American Theoretical INformatics. (2014): 622-633.
25 / 26
21st April, 2014
Elastic Collisions of Particles
on a One Dimensional Domain
with Unrestricted Masses
J. Brach
[6] Fry, Ben & Casey Reas. Processing 2. The Processing Foundation. (2013) v2.1.1
https://processing.org/
[7] Luke, Sean & Michael Lecuyer. “The Mersenne Twister in Java.” (2003) http://www.cs.
gmu.edu/~sean/research/mersenne/MersenneTwisterFast.java
[8] Matsumoto, Makoto and Takuji Nishimura. “Mersenne Twister: A 623-Dimensionally
Equidistributed Uniform Pseudo-Random Number Generator.” ACM Transactions on
Modeling and Computer Simulation, Vol. 8, No. 1. (1998): 3-30.
[9] Murphy,T.J. & E.G.D. Cohen. “Maximum number of collisions among identical hard
spheres.” J. Statist. Phys. 71(56) (1993): 10631080.
[10] Murphy,T.J. & E.G.D. Cohen. “On the sequences of collisions among hard spheres in
infinite space.” Hard Ball Systems and the Lorentz Gas. Springer Berlin Heidelberg, (2000):
29-49.
[11] Sevryuk, Mikhail Borisovich. “Estimate of the number of collisions of n elastic particles
on a line.” Theoretical and Mathematical Physics 96.1 (1993): 818-826.
26 / 26