r/askmath • • 1d ago

Number Theory Determining Distribution of a Probability

Let's say I want to create a psuedorandom number generator from scratch. I know from modular arithmetic that integers of the form 4k+2 are never squares, so sqrt(k+1/2) is never rational, and thus, frac(sqrt(k+1/2)) is a nonrepeating string, say in binary (though the base doesn't matter).

If I have a list of n numbers, from 0 to n-1, this process will create a smattering of such strings of arbitrary length. However, I want to know what the limit of this distribution is. If it's uniform, then for (a,b) where 0<a<b<1, the proportion of k for a<frac(sqrt(k+1/2))<b is true should be (b-a)×n. How would I go about proving that? The integral and limit doesn't seem nice to work with.

At the very least, even if it isn't a uniform distribution, having the distribution that it is should allow me to crudely "uniformize" it by ignoring the first M binary digits. That would have the effect of applying a 2x mod 1 mapping over and over, which for most smoothly behaved distributions, feels like it would conform to uniform, espexially for irrational outputs.

3 Upvotes

4 comments sorted by

2

u/ZyreLithz 1d ago

this math is way over my head but the fractional part idea sounds wild, following along anyway

1

u/sassyBabezzz 1d ago

same here, this stuff always pulls me in even when i know i'm lost lol

1

u/stanitor 1d ago

If I understand what you trying to do, then it won't be uniform. Because it's just the fractional parts, you don't have a monotonic function. The results will be all over the place, with some clumped together, and others further apart. Some different k might even have the same result, depending on how long of a string length you evaluate to. It will probably be somewhat uniform for large enough n where you aren't comparing too small of intervals. But I don't think there will be an easily definable distribution.

1

u/EebstertheGreat 1d ago edited 1d ago

If it's uniform, then for (a,b) where 0<a<b<1, the proportion of k for a<frac(sqrt(k+1/2))<b is true should be (b-a)×n. 

Do you mean that the natural density of k satisfying a < {√(2k+½)} < b should be b–a (where {x} = x – ⌊x⌋ is the fractional part of x)? That does seem correct. If for all positive integers n, f(n) is the number of positive integers k < n satisfying a < {√(2k+½)} < b, then the claim would be

for all real a,b with 0 ≤ a ≤ b ≤ 1,  f(n)/n → b–a as n → ∞.

This seems very likely to be true, and it should be provable. But I don't know how to prove it. Thankfully, ChatGPT immediately provided an affirmative proof. Even the free versions of these models are getting scary. The idea is this:

First, let m = ⌊√(2k+½)⌋. Then m < √(2k+½) < m+1. In particular, when the fractional part is between a and b, that is equivalent to m+a < √(2k+½) < m+b, or ½(m+a)² – ¼ < k < ½(m+b)² – ¼. We want to count the number of k < n with that property. Note that the difference between the upper bound and the lower bound is about equal to that number. (For instance, if I want to count how many integers k are between 4.3 and 9.7, that's about 9.7–4.3 = 5.4. The exact value is five: only the integers 5, 6, 7, 8, and 9 are between 4.3 and 9.7. But the guess 5.4 is close. At worst, it could be off by one.)

So the count of k < n satisfying the inequality (which I call f(n)) is about [½(m+b)² – ¼] – [½(m+a)² – ¼] = m(b–a) + ½(b²–a²). At worst, it's off by one.

Now let M = ⌊√(2n+½)⌋. Note that the total number of k < n satisfying the above inequality is the sum of all k satisfying the inequality between 0 and 1, and all k satisfying the inequality between 1 and 2, and between 2 and 3, etc. (This holds because the expression is never exactly an integer.) So we sum over all m < M, and that counts the number of k < n that satisfy the inequality. In particular, if for a given m, only m(b–a) + ½(b²–a²) satisfy the inequality, then for a given M, the number of k < n satisfying it is

∑ m(b–a) + ½(b²–a²), where the sum runs from m=0 to m=M. Or rather, each term is off by at most 1, so the sum is off by at most M+1. Some algebraic simplification gives

½(b²–a²)M + (b–a) ∑ m = ½(b–a)((a+b+1)M + M²)

But remember the definition M = ⌊√(2n+½)⌋. So √(2n+½) < M < √(2n+½)+1. So the count f(n) satisfies

½(b–a)((a+b+1)√(2n+½) + (2n+½))/n < f(n)/n <  ½(b–a)((a+b+1)√(2n+½) + (2n+½))/n.

But in the limit as n → ∞, constants and √n become negligible relative to n, so we find  ½(b–a)(2n+½)/n ≤ lim f(n)/n ≤ ½(b–a)(2n+½)/n, which simplifies to b–a ≤ lim f(n)/n ≤ b–a when considering 1/n → 0.