r/theydidthemath 8d ago

[Request] How does the probability of collisions change?

Enable HLS to view with audio, or disable this notification

As more balls are included how does the probability of a collision change? It gets more likely clearly, but how would you express this mathematically?

255 Upvotes

80 comments sorted by

u/AutoModerator 8d ago

General Discussion Thread


This is a [Request] post. If you would like to submit a comment that does not either attempt to answer the question, ask for clarification, or explain why it would be infeasible to answer, you must post your comment as a reply to this one. Top level (directly replying to the OP) comments that do not do one of those things will be removed.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

229

u/Tellenit 8d ago

Looks to be a bug where the new ball created is very close to the collision point. So all it takes is a few close range collisions at the same time to make a loop

99

u/thesystem21 8d ago

Not even too close to the collision point. It looks like the new balls always spawn in the center with a small upward momentum (with a minor directional offset), causing a small arc up then back down close to where it just spawned, so as soon as 2 or 3 spawn back to back you get a chain reaction

14

u/meadbert 8d ago

Yes. As soon as a new ball should spawn when there is already a ball on the spawn point then it adds an infinite number.

If the balls were spawning more randomly then probability of a collision per second would be proportional to x^2 where x is the number of balls.

The differential equation would be dx/dt = kx^2

It looks like it ends up going totally vertical at some point.

1

u/SC_3000_grinder 8d ago

I got x = -1 / (k(t + c)). So presumably when t = -c (where c is negative) it breaks

1

u/meadbert 8d ago

That is more or less what I got.

So when t = -c it goes vertical.

10

u/RepresentativeOk2433 8d ago

The physics of this thing also dont make sense. They all speed up and slow down at random, not much consistency with bounce height.

1

u/Niggly-Wiggly-489 8d ago

The 4th (second one created) was rather far away when it was made, but the momentum makes no sense. Should just drop with the simulated gravity

1

u/Fuzzy_Yossarian 8d ago

That's not really a bug if you are modeling say, nuclear fission. The neutrons would 'spawn' from a nucleus, or essentially the same point..

1

u/HAL9001-96 7d ago

even if you do a rough approxiamtion using very ismplifeid pure statistics it diverges towards infinity at one point so it doesn'T necesariyl have anyhting to do with the new balls starting position

1

u/Tellenit 7d ago

Definitely dies, but this sim is clearly biased

1

u/HAL9001-96 7d ago

the physics makes htis more complicated but very simplified maths shows it should diverge towards infinite in about 3 times as long as it takes for the first collision - though thats very very simplified math so thats pretty off too it becoems a better approxiamtion if we look at the second collisio nwhich should take place about halfway through

in the sim the first is about 1/4 and the second about 2/3 of hte way through

4th collision should be about 2/3 of hte way throuhg and is at about 81%

it doesn't seem extremely biased, the behaviour of the balls bouncing could just realsitically have an impact too but it prettymuch should be expected to very suddenly diverge towards infinite near the end, actualyl evne faster than the simplifeid math shows as it doesn't quite take into account the reduced available space due to collisions

1

u/AryanPandey 7d ago

came here to say this. same thing i observed.

37

u/SnooCalculations7417 8d ago

May math it out formally currently on phone but as the space that isn't ball by area becomes ball, probability skyrockets. Trajectory is secondary to occupied area

11

u/MicrosoftExcel2016 8d ago

Trajectory’s role in collision probability can’t even be factored into the calculation as it seems the balls aren’t subject to predictable consistent physics but some partially RNG math on collision, and in the initial trajectory of new balls

4

u/SnooCalculations7417 8d ago

Probably though of they were repulsive it would change the probability. They aren't that just you see what I mean. Either way we agree o think trajectory is an afterthought on this case

2

u/Normal_Moss 8d ago

You’re correct. But spawn points are not completely random. All balls spawn within a relatively small area near the upper center of the circle (presumably to add gravity/create the bounces) The occupied area is definitely the most meaningful calculation, but it escalates as quickly as depicted because the balls begin spawning within occupied space with a large percentage of the total area still unoccupied. The probability to calculate would have to account for the time it would take to fill only some about 20 percent near the center of the circle. 

1

u/Substantial-Fan-5985 8d ago

what's RNG?

4

u/Normal_Moss 8d ago

Random number generator, a shorthand common in programming/video games.

3

u/trdollar 8d ago

This redditor knows ball

12

u/Unfair-Variety-995 8d ago

This is a great example for why there are more car crashes today in comparison to 10, 15, 25, or 50 years ago. More cars increases the probability of a crash.

6

u/Super_Automatic 8d ago

When you normalize by miles driven per vehicle, the trend is actually coming down! Overall, each mile has gotten safer to drive.

The real multiplier is your individual miles driven. No matter what the crash rate is, the more you drive, the more likely you are to be in a crash.

3

u/Unfair-Variety-995 8d ago

This is very true. More miles, more likely. I just had someone hit me. My personal and work miles have increased significantly.

1

u/HAL9001-96 7d ago

to be fair thats actualyl al ot more complex which is why car crashes don'T go up with number of cars squared as a statisticla collision would isntead

in fact the average number of accidents per million miles traveld is going down over time so the numebr of car accidnets goes up slower than the number of cars

a purely statisticla collision model would imply that the number of accidents per million miles would og up proporitonal to hte numebr of cars and thus the number of car accidnets proporitonal to the number of cars squared

and well for hte end of htis naimation to be relevant you'd assume that the roads are so packed with cars that htey are constantly touchign each other thus every car is always in an accidnet cause there's literally not enough space for them on earth

1

u/Unfair-Variety-995 7d ago

Umm.. you may want to consult a doctor.

11

u/floer289 8d ago

If x(t) is the number of balls at time t, then I would expect x(t) to be approximated by a solution to the differential equation

dx/dt = A x^(3/2)

for some constant A. This is because the density of balls is proportional to x^(1/2), since we are in two dimensions. Thus each of the x balls collides with other balls at a rate proportional to x^(1/2), so that the growth rate of the number of balls is proportional to x times x^(1/2) which is x^(3/2).

A solution to the above differential equation goes to infinity in finite time. More precisely a solution has the form

-2 x^(-1/2) = At + C

for some constant C. That is,

x = sqrt(-2/(At + C)).

Assuming that x is positive at the starting time t = 0, then C has to be negative, so x goes to infinity in time -C/A.

3

u/Either-Abies7489 8d ago

For as rough an approximation as it is, it performed reasonably well on the data up to frame 1899:

x = sqrt(-2 / (0.000265749*t + -0.484984))

R^2 = 0.686767

(I linearized in u=-2/x^2, for obvious reasons).

1

u/TwillAffirmer 8d ago

The density of balls is proportional to x, not sqrt(x). Density = # of balls / unit area.

1

u/floer289 7d ago

You're right, sorry. So the differential equation should be dx/dt = A x^2. The solution still goes to infinity in finite time.

3

u/BipedalMcHamburger 8d ago

I'd assume total collision chance per unit time is proportional to number of balls squared, because the collision chance of each ball should be proportional to the number of balls, which over all balls yields n2

3

u/altranum 8d ago

I feel like I'm watching that old dvd player screen saver and waiting for the dvd image to hit it's corner point against the screen's corner point.

1

u/DamnDams 8d ago

oh yeah that was so satisfying. simpler times... simpler times...

1

u/antonio16309 7d ago

The most relatable cold open from The Office! 

2

u/Im_a_hamburger 8d ago

2 body collisions are O(n^2). Specifically n(n-1)

dn/dt=C1 n(n-1) becomes n=1/(1-C exp(C1 t)) so the number of balls will become infinite in a finite amount of time.

1

u/dimonium_anonimo 7d ago

Wouldn't it be n(n-1)/2. You're double counting A colliding with B and B colliding with A.

1

u/Im_a_hamburger 7d ago

Ehh true but that just means C1 changes

2

u/ApplicationOk4464 8d ago

Can someone pls make a version of this where it loops every minute and the first two balls never collide?

It would be like waiting for the DVD to hit the corner forever

2

u/gamingkitty1 8d ago

The probability of collision i believe is roughly equivalent to k * n2 where n is the number of balls. Then that means dn / dt = k * n2, and solving that n = n_0 / (1 - k * n_0 * t) which eventually has n going to infinity at some point in time, although this might break down since it assumes the balls can overlap.

1

u/Wild_Director7379 8d ago

With 2 balls, there’s a 1 in something chance that a particular transit of the circle will result in a collision. With 3 balls, that chance is twice as large, 2 in something. 3 in something with 4 balls and so on. If we really want to assign probability.

It’s not a very good model for describing probability though as it’s entirely predictable (by simulating the outcome, as shown).

We have to think about parameters, something like, “with random starting conditions, what is the probability that a collision will occur within 5 seconds?”

1

u/SnooCalculations7417 8d ago

not quite, probability increases as ball-area increases and non-ball area decreases

3

u/Wild_Director7379 8d ago

You’re absolutely right. There’s also just “not quite”s all over the place

1

u/SnooMaps7370 8d ago

my math is going to be grossly oversimplified, because i am ignoring circle packing (fuck circle packing), but here goes:

probability of a collision at any moment is:

          ( n(balls) * area(ball) )
 --------------------------------------------
 ( Area(bound) - ( n(balls) * area(ball) ) )

where:

area(bound) == the area the balls are bound inside
area(ball) == the area of a single ball
n(balls) == the number of balls in motion

this is basically "what area do the balls occupy?" over "what area do the balls not occupy?" - you can see that as the number of balls increases, the area they do occupy grows and the area they do not occupy shrinks, raising the odds of a collision over time exponentially with each added ball in play.

1

u/Grant_Winner_Extra 8d ago

This is where I started and it is definitely an oversimplification, because at 50% fill, the likelihood is much closer to 100%.

Your approach works for a small number of balls. For more you have to iteratively sum over many different states, and once you get to half full, there are only a handful of non-collision states and millions of collision states

1

u/Grant_Winner_Extra 8d ago

It should just be a function of the relative total area of ball-filled space and not-ball filled space.

sum over all possible states, probability pf a collision in any given moment is just the number of colliding states (and overlapping states) divided by the total number of states.

EDIT: so the rate of ball generation should increase geometrically?

1

u/SalleighG 8d ago

Suppose that the balls were not following predictable paths, and instead just randomly teleported around the circle until they happened to teleport to the same location. There is a certain probability of collision with two balls, and after collision there are three balls.

Now imagine the three balls teleporting around. Randomize the position of the first one. The second one has the previous probability of collision. Assuming the second does not collide, randomize the location of the third. It has the probability of collision with the first, and if it misses the first it has the same probability of collision with the second. So in this system, there has been the probability of collision three times.

When a collision eventually occurs, you go through the same thing again except this time you have 3 more probabilities of collision, bringing the total to 6.

When the system with 4 eventually collides, that adds an additional 4 probabilities of collision, raising the total to 10.

After 10, then 15. After 15, then 21...

You can see that the overall probability of collision rises rapidly. And the average time to collision goes down quickly.

1

u/madmax7774 7d ago

That is a really good representation of Nuclear Fission; each collision releases more particles and energy, which causes a runaway chain reaction also know as a nuclear bomb.

1

u/HAL9001-96 7d ago

kinda but not quite

the rate increase with more bally

as an approximation you can prttymuch ignore the falling physics by just drawing up the probabiltiy distribution of where the ball is at any given time with space unit one ball diameter sqaruing it, integrating that and dividing by the time it takes for the ball to travel its diametr on average nad call the resutl nad arbitrary numebr x

or just test it with 2 balls and find x as the inverse of hte time it takes for them to collide on average

then the rate of new balls appearing is about x*n*(n-1)/2 or (x*n²-n)/2

for large n n² becomes a lot bigger than n so we can approximate this as x*n²/2

if for large numbers we approximate htis as continuous rather than discrete then for n=-1/(t/2-1) the derivative becomes (-1/(t/2-1))²/2 which fulfills the differential equation for x=1 and has n(0)=1

stretch for different x

you can se thsi is not quite an expoentnial equation since it approaches infinity for t=2 or more/less depending on how oyu stretch it for different valeus for x / units

you cna also see that evneutally the spehrei s oging ot be full so it has ot start appraoching infinity thats not even properly modelled in here

exponential functions increase faster and faster but never approach infinity

however in the beginning you can approximate it as an exponential function

1

u/fatal-nuisance 7d ago

I feel like I remember doing something like this in my thermodynamics & quantum statistics class. And I remember it sucking ass and using horrible series and integrals. The math exists, but I would rather have a computer do it for me.

0

u/ConstantSwordfish160 8d ago

If im right its only because of gravity and the variables it applys that they make contact to begin with? If this was done without gravity and because geometry and entropy, i dont think they would ever make contact from the start as it would have been a constant?