Uniform Variables: Smaller Below Larger Squared
Problem statement
Two random variables X and Y are independent and uniformly distributed on [0, upperBound]. Return the probability that min(X,Y) < max(X,Y)^2.
For this exercise, assume the common upper bound is supplied as an input, generalizing the reported [0,1] question. The inequality is strict. If upperBound = 0, both variables are zero and the event is false.
Complete uniformSquareProbability(upperBound). Answers within 1e-9 absolute error are accepted.
Function
uniformSquareProbability(upperBound: double) → doubleExamples
Example 1
upperBound = 1.0return = 0.6666666666666666In either half of the unit square, the favorable region has area 1/3. The total probability is 2/3; 1/3 is the complementary event.
Example 2
upperBound = 0.5return = 0.3333333333333333On this smaller square, integrate twice the area under m^2 and divide by 0.5^2, giving 1/3.
Example 3
upperBound = 2.0return = 0.9166666666666666For a maximum above one, every smaller value is below its square. The resulting probability is 1 - 1/12 = 11/12.
Example 4
upperBound = 0.0return = 0.0Both variables equal zero, so 0 < 0 is false.
Constraints
- For this exercise, assume
upperBound = 0or0.000001 <= upperBound <= 1000. - The two variables have the same continuous uniform law when the upper bound is positive.
- Return a
doubleprobability from0through1.