# Sheldon Ross 10: Exercise 3.08

Question: An unbiased die is successively rolled. Let X and Y denote, respectively, the number of rolls necessary to obtain a six and a five. Find

1. E[X]
2. E[X|Y = 1]
3. E[X|Y = 5]

Analytical Solution Let us solve this part by part

1. E[X]
• Intuitively this can be solved in a single step. Since the probability obtaining any of the numbers is independent and equal to 16 this means that the E[X] is simply the reciprocal of 16 which is 6
• Formally we can start modelling this as E[X] = E[E[X|T]] where T is the variable on which we wish to condition the variable X on. We can condition X on the outcome of the first roll.
• ⇒ E[X] = E[X|T=6] P{T=6} + E[X|T≠6] P{T≠6}
• Let us examine a few things before getting to the next step
• E[X|T=6] is simply 1 since the first roll is itself 6
• P{T=6} = 16
• E[X|T≠6] would be E[X]+1 since we have already rolled the dice once and still trying to determine the value of E[X]
• P{T≠6} = 56
• E[X] = 16 + (E[X]+1)56
• ⇒ E[X] = 6
2. E[X|Y=1]
• This is a straightforward item
• E[X|Y=1] = E[X|T≠6] = 1+E[X] = 1+6 = 7
3. E[X|Y=5]
• This might look straightforward but there is a rather a twist to it. Let us examine this step by step
• Firstly we know that the 5th one is the  number 5 (OR not 6)
• Also, this means that we know partial information about the so called random system
• this knowledge means that our calculation of the expected value
• this knowledge means that the there are only five possibilities in all the rolls except the fifth one
• E[X|Y=5] = 1(15) + 2(15)(45)1 + 3(15)(45)2 + 4(15)(45)3 + 6(16)(45)4 + 7(16)(56)(45)4 + . . .

Simulation Solution

Since the outcomes are small here, I have simulated the sections 1 and 3 (since the section 2 is simple enough to not need any). The code is also provided just below, so you could run the code yourself in your Mathematica Notebook.

Observations

• The plots are not of the actual outcomes. Plotting the actual outcomes would mean that we would only see integral bins in the histogram
• Vital things to note of this operation
• There is loss of the data in the frequency (or counts) realm
• There is additional information created that shows how the batches of set sizes are behaving
• Here is what I have done to eliminate the non integral-ity
• I took the list and partitioned it into non overlapping sublists (or batches) of
• 1000 in the first case &
• 100 in the second case
• Then, I calculated the means of these partitioned list and plotted them as histograms

Code

I have coded this problem in both Python and Mathematica. I have pasted them as two distinct blocks of code. It should be fairly simple to tell them apart.

```from mathematica.random_functions import RandomChoice, RandomInteger

_masterList = []
for r in range(0, 1000000):
_list = []
_i = 1

while True:
if _i == 5:
_list.append(5)
elif _i < 6 and _i != 5:
_rand = RandomChoice([1, 2, 3, 4, 6])
_list.append(_rand)
elif _i >= 6:
_rand = RandomInteger(1, 6)
if _rand != 6:
_list.append(_rand)
elif _rand == 6:
_list.append(_rand)
break
_i = _i + 1
_masterList.append(_list.index(6) + 1)

_file = open('FilePath.txt', 'w')
for r in _masterList:
_file.write(r.__str__() + '\n')

```
```Histogram[
Parallelize[
Mean[Differences[
Position[RandomInteger[{1, 6}, 1000], 6] // Flatten]] & /@
Range], {0.02}, "Probability", ImageSize -> 800,
Frame -> True, PlotLabel -> "Mean[X]"]

Module[{data =
Partition[
ToExpression[#] & /@
StringSplit[Import[FileNames["*.txt", NotebookDirectory[]][]],
"\n"], 100]},
Histogram[Mean[#] & /@ data, {0.02}, ImageSize -> 800, Frame -> True,
PlotLabel -> "Mean[X|Y=5]"]]```

End of the post 😉

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.