QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: STxAxTIC 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:
... which fails downward. The answer is still somehow dragged down toward zero. Hmmm. Let's see if 3*RND works instead:
... 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.
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.
-
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.
-
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)
-
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...
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 (http://wfbarnes.net/homedata/Probability%20and%20Statistics.pdf)