Comment

Comment by SideQuark

Lots of math all over the place computing the expected value :)

So, here's a derivation: if rand(x) returns uniformly a real in [0,x) or equivalently for expected value, in [0,x], then here are the first few iteration expected values from which you can see the general answer. 1 term

    E(r) = (1/1) * Integral_0^1 x_0 dx_0 = (x_0^2/2) from 0 to 1 = 1/2
2 terms

    E(r(r)) = (1/1) * Int_0^1  (1/x_0) Int_0^x_0 x_1 dx_1 dx_0 = 1/4
3 terms:

    E(r(r(r))) = (1/1) * Int_0^1 (1/x_0) Int_0^x_0 (1/x_1) Int_0^x_1 x_2 dx_2 dx_1 dx_0 = 1/8
And so on. The nth term is exactly (1/2)^n
parent SideQuark 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton