Author Topic: Random Products and Magic Numbers  (Read 3129 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Random Products and Magic Numbers
« on: October 02, 2020, 09:45:15 am »
So I don't know *why* I started pursuing this question, and I'm not really sure I understand fully what's going on here, but I figure it's time to release this to the wild (looking at you, vince and bplus) and see what happens.

Let's dwell on repeated multiplication. Consider any number q. Then multiply q by itself a lot of times, specifically n times, to get something like q * q * q * q * q ... = q^n. Now, the final form that q^n takes is entirely dependent on the original q:
  • If q<1, then q^n will tend toward zero.
  • On the other hand, if q>1, then q^n grows toward infinity.
  • Only the special case q=1 leads to stable behavior, as you get q^n=1^n=1.

To make things interesting, let's again start with q, but then multiply q by a *random* number in each iteration. Taking QB64's RND function at face value, which gives you a random real number between 0 and 1, would only cause q to shrink to zero:

q = q * RND * RND * RND * RND ... --> 0

... This is because the average value of RND is 0.5. On average, it's *as if* we are calculating q = q * .5 * .5 * .5 * .5, which shrinks quickly.



Let's play a game then. Let us try to scale the RND function so that the long-term behavior in q neither shrinks to zero nor tends to infinity. It should seem obvious that choosing a random number between 0 and 2 would save the day, as the average of 2*RND is surely 1. Let's try it:

Code: QB64: [Select]
  1. X = 1
  2.     X = X * 2 * RND
  3.     PRINT X

... which fails downward. The answer is still somehow dragged down toward zero. Hmmm. Let's see if 3*RND works instead:

Code: QB64: [Select]
  1. X = 1
  2.     X = X * 3 * RND
  3.     PRINT X

... which fails in the other direction (toward infinity), as expected. But what the hell was wrong with 2*RND? Is it's average not one?



After a little bit of fiddling, I eventually found that there *is* a number between 2 and 3 that does the thing I'm asking. Turns out it's none other than Euler's constant, e=2.71828... . In the following code, you can see the randomly-updated X just meander up and down the real number line without picking a direction - that is, until we max out what type DOUBLE can keep track of.

Code: QB64: [Select]
  1. X = 1
  2.     X = X * EXP(1) * RND
  3.     PRINT X
  4.     _DELAY .01



The real question is, *why* does e=EXP(1) do the job, where plain 2 doesn't? Can we prove why the factor must be EXP(1)? Strangely, the best thing I can "prove" by hand is that the factor is equal to one plus the golden ratio, which is about 0.1 off from e itself. Beautiful, and close, but flat wrong. I can hand-wave my way to justifying the presence of e, but that's it. Read the attached paper, it contains my whole effort to date.
« Last Edit: October 02, 2020, 09:47:31 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Random Products and Magic Numbers
« Reply #1 on: October 02, 2020, 12:32:56 pm »
I think for every 1/n you multiply by you have to counter by multiplying by n to keep the product stable.

So if you mult n/m then balance by m/n, so 2 only balances 1/2.

Here is a question back at you if RND is and even distribution from 0 to 1 then is 1/RND an even distribution from 1 to infinity? No, I don't think so, I think it is a little heavy on the side of 1, maybe e is related to that.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Random Products and Magic Numbers
« Reply #2 on: October 02, 2020, 05:24:19 pm »
Some handwavy thoughts since I was summoned

Here is a question back at you if RND is and even distribution from 0 to 1 then is 1/RND an even distribution from 1 to infinity? No, I don't think so, I think it is a little heavy on the side of 1, maybe e is related to that.

This is a transformation of a random variable problem, too bad I forgot how to do it

Some thoughts on the original question.  RND is supposed to be a uniformly distributed random variable, lets call it X

Y = (a*X) * (a*X) * ...
then the mean of Y should be 0.5 and the above experiment seems to suggest that a=exp(1)
« Last Edit: October 02, 2020, 05:30:42 pm by _vince »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Random Products and Magic Numbers
« Reply #3 on: October 04, 2020, 09:48:35 pm »
Okay I solved it.

For funzies, here is another loop that adds a random value to a running total that just hates going to -infinity or +infinity. Fascinating...

Code: QB64: [Select]
  1. x = 0
  2.     x = x + 1 + LOG(RND)
  3.     PRINT x

Below is the sacred proof. Damn this took a while:

And this is the document where the problem now lives: http://wfbarnes.net/homedata/Probability%20and%20Statistics.pdf

« Last Edit: October 04, 2020, 11:17:15 pm by STxAxTIC »
You're not done when it works, you're done when it's right.