Choose independently two numbers B and C at random from the interval [0, 1] with uniform density. Prove that B and C are proper probability distributions.

Note that the point (B,C) is then chosen at random in the unit square.

set.seed(101)

n <- 1000000

# Create two series of random variables B and C
B <- runif(n, min = 0, max = 1)

C <- runif(n, min = 0, max = 1)

# check on few values
head(B)
## [1] 0.37219838 0.04382482 0.70968402 0.65769040 0.24985572 0.30005483
head(C)
## [1] 0.7928403 0.3772390 0.8139653 0.8201430 0.3630771 0.3242720

To Prove that B and C are proper probability distributions, we need to show that all the values are greater than 0 and the empirical cumulative values lies between 0 to 1.

#All values of B lie between 0 and 1. Verifying that there are no B values external to the interval [0, 1], and that all B values are within [0, 1]:
length(B[B>0])
## [1] 1000000
length(B[B<0])
## [1] 0
length(B[B>1])
## [1] 0
length(B[B<n])
## [1] 1000000
#All values of C lie between 0 and 1. Verifying that there are no C values external to the interval [0, 1], and that all C values are within [0, 1]:
length(C[C>0])
## [1] 1000000
length(C[C<0])
## [1] 0
length(C[C>1])
## [1] 0
length(C[C<n])
## [1] 1000000
#Verfying that the empirical cumulative values lies between 0 to 1 for both B and C:
ecdf(B)
## Empirical CDF 
## Call: ecdf(B)
##  x[1:999866] = 1.2456e-07, 1.9977e-07, 1.0019e-06,  ...,      1,      1
ecdf(C)
## Empirical CDF 
## Call: ecdf(C)
##  x[1:999890] = 3.5949e-07, 1.1071e-06, 2.9947e-06,  ...,      1,      1

we can clearly see that the values of the empirical cumulative functions for B and C lie between 0 and 1. Therefore randomly choosen two random numbers B and C are proper probability distributions.

we can also use histograms to prove this:

hist(B)

hist(C)

Find the probability that:

(a) B + C < 1/2

sum(punif((B+C)<0.5, min=0, max=1)) / n
## [1] 0.124998

(b) B*C < 1/2

sum(punif((B*C)<0.5, min=0, max=1)) / n
## [1] 0.84773

(c) |B − C| < 1/2

sum(punif(abs(B-C)<0.5, min=0, max=1)) / n
## [1] 0.749891

(d) max{B,C} < 1/2

found <- 0
for(i in 1:length(B)){
  if(max(B[i], C[i]) < 0.5){
    found <- found + 1
  }
}
found/n
## [1] 0.249616

(e) min{B,C} < 1/2

found <- 0
for(i in 1:length(B)){
  if(min(B[i], C[i]) < 0.5){
    found <- found + 1
  }
}
found/n
## [1] 0.750642

Please notice that we can also solve all these using the histogram way. For example for (a), we can do:

X <- B + C

#show the hitogram
hist(X, main = "Histogram of B + C")

#calculate the probability that B + C < 1/2
sum(X < .5) / n
## [1] 0.124998

You can clearly see that the result for (a) is the same, that is 0.124998.