<jupyter_start><jupyter_text>$ \newcommand{\bra}[1]{\langle 1|} $$ \newcommand{\ket}[1]{|1\rangle} $$ \newcommand{\braket}[2]{\langle 1|2\rangle} $$ \newcommand{\dot}[2]{ 1 \cdot 2} $$ \newcommand{\biginner}[2]{\left\langle 1,2\right\rangle} $$ \newcommand{\mymatrix}[2]{\left( \begin{array}{1} 2\end{array} \right)} $$ \newcommand{\myvector}[1]{\mymatrix{c}{1}} $$ \newcommand{\myrvector}[1]{\mymatrix{r}{1}} $$ \newcommand{\mypar}[1]{\left( 1 \right)} $$ \newcommand{\mybigpar}[1]{ \Big( 1 \Big)} $$ \newcommand{\sqrttwo}{\frac{1}{\sqrt{2}}} $$ \newcommand{\dsqrttwo}{\dfrac{1}{\sqrt{2}}} $$ \newcommand{\onehalf}{\frac{1}{2}} $$ \newcommand{\donehalf}{\dfrac{1}{2}} $$ \newcommand{\hadamard}{ \mymatrix{rr}{ \sqrttwo & \sqrttwo \\ \sqrttwo & -\sqrttwo }} $$ \newcommand{\vzero}{\myvector{1\\0}} $$ \newcommand{\vone}{\myvector{0\\1}} $$ \newcommand{\stateplus}{\myvector{ \sqrttwo \\  \sqrttwo } } $$ \newcommand{\stateminus}{ \myrvector{ \sqrttwo \\ -\sqrttwo } } $$ \newcommand{\myarray}[2]{ \begin{array}{1}2\end{array}} $$ \newcommand{\X}{ \mymatrix{cc}{0 & 1 \\ 1 & 0}  } $$ \newcommand{\I}{ \mymatrix{rr}{1 & 0 \\ 0 & 1}  } $$ \newcommand{\Z}{ \mymatrix{rr}{1 & 0 \\ 0 & -1}  } $$ \newcommand{\Htwo}{ \mymatrix{rrrr}{ \frac{1}{2} & \frac{1}{2} & \frac{1}{2} & \frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2} & \frac{1}{2} & -\frac{1}{2} \\ \frac{1}{2} & \frac{1}{2} & -\frac{1}{2} & -\frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2} & -\frac{1}{2} & \frac{1}{2} } } $$ \newcommand{\CNOT}{ \mymatrix{cccc}{1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0} } $$ \newcommand{\norm}[1]{ \left\lVert 1 \right\rVert } $$ \newcommand{\pstate}[1]{ \lceil \mspace{-1mu} 1 \mspace{-1.5mu} \rfloor } $$ \newcommand{\greenbit}[1] {\mathbf{{\color{green}1}}} $$ \newcommand{\bluebit}[1] {\mathbf{{\color{blue}1}}} $$ \newcommand{\redbit}[1] {\mathbf{{\color{red}1}}} $$ \newcommand{\brownbit}[1] {\mathbf{{\color{brown}1}}} $$ \newcommand{\blackbit}[1] {\mathbf{{\color{black}1}}} $  A Game with two biased coins  _prepared by <NAME>_[](https://youtu.be/k0OJvv7AAgU)  Probabilistic bitsWe start with a short introduction to the probabilistic bits to trace the details of the game below.Suppose that we have a biased coin landing on heads with probability $ 0.3 $, and it is tossed once but we do not see the outcome.Even though it lands on either heads or tails, our information about the outcome is probabilistic: It is heads with probability $ 0.3 $ and tails with probablity $ 0.7 $. If we consider this coin as a system with two states (heads and tails: respectively, states 0 and 1), then we can say that after one iteration it is in states 0 and 1 with probabilities 0.3 and 0.7, respectively.In general, a probabilistic bit is in states 0 and 1 with probabilities $ p $ and $ 1-p $, where $ p $ is a number between 0 and 1. Remark that if $  p=1 $ or $ p=0 $, then the bit becomes deterministic.If the above biased coin is tossed once more, the probabilisties of the getting heads and tails (or being in the states in 0 and 1) will still be the same. In the following game, by using two biased-coins, we will be able to have different probabilities for the states 0 and 1. This game is our first step to define a probabilitic operator for probabilistic bits.  The game Our friend Asja has one euro and one cent. Both coins are biased, and the probabilities of getting heads and tails are as follows:     one euro: heads with probability $ 0.6 $ and tails with probability $ 0.4 $.      one cent: heads with probability $ 0.3 $ and tails with probability $ 0.7 $. Asja flips her coins based on the following protocol:       she starts with flipping one euro[*];      whenever she gets heads, she flips one euro in the next round; and,      whenever she gets tails, she flips one cent in the next round. By using a single bit, we summarize all transitions of this game as follows:$GameCoins = \begin{array}{c|cc} \hookleftarrow & \mathbf{Head} & \mathbf{Tail} \\ \hline \mathbf{Head} & 0.6 & 0.3\\  \mathbf{Tail} & 0.4 & 0.7  \end{array} = \begin{array}{c|cc} \hookleftarrow & \mathbf{0} & \mathbf{1} \\ \hline \mathbf{0} & 0.6 & 0.3 \\  \mathbf{1} & 0.4 & 0.7  \end{array}$[*] We should fix an initial condition. Otherwise, Asja cannot pick any of the coins at the beginning of game. Task 1: Convince yourself Convince yourself about the correctness of transitions given in the table. Remark that there is no difference between getting heads from the one euro coin or from the one cent coin.    Therefore, one bit is enough to represent all transitions.  Tracing Asja's three coin tosses Suppose that Asja secretly tosses her coins based on the defined protocol.By using python, we can calculate the probabilities of Asja seeing heads and tails after three coin tosses.Remark: In the previous tasks of [Coin Flipping](B06_Coin_Flip.ipynb), we know the ideal ratios, and we experiment many coin tosses and then expect to observe the results close to the ideal ratios.    Here we calculate the exact probabilities (the ideal ratio) by using python. (We will not do the experiments as in the previous tasks.)We present our solution step by step.<jupyter_code>#
# OUR SOLUTION
#

# initial condition:
# Asja will start with one euro,
#    and so, we assume that the probability of having head is 1 at the beginning.
prob_head = 1
prob_tail = 0


#
# first coin-flip
#

# the new probability of head is calculated by using the first row of table
new_prob_head = prob_head * 0.6 + prob_tail * 0.3

# the new probability of tail is calculated by using the second row of the table
new_prob_tail = prob_head * 0.4 + prob_tail * 0.7

# update the probabilities for the second round
prob_head = new_prob_head
prob_tail = new_prob_tail

#
# second coin-flip
#
# we do the same calculations

new_prob_head = prob_head * 0.6 + prob_tail * 0.3
new_prob_tail = prob_head * 0.4 + prob_tail * 0.7

prob_head = new_prob_head
prob_tail = new_prob_tail

#
# third coin-flip
#
# we do the same calculations

new_prob_head = prob_head * 0.6 + prob_tail * 0.3
new_prob_tail = prob_head * 0.4 + prob_tail * 0.7

prob_head = new_prob_head
prob_tail = new_prob_tail

# print prob_head and prob_tail
print("the probability of getting head after 3 coin tosses is",prob_head)
print("the probability of getting tail after 3 coin tosses is",prob_tail)<jupyter_output><empty_output><jupyter_text>Task 2: Tracing ten biased coin tosses By using python, calculate the probabilities of Asja seeing heads and tails after 10 coin tosses.$GameCoins = \begin{array}{c|cc} \hookleftarrow & \mathbf{Head} & \mathbf{Tail} \\ \hline \mathbf{Head} & 0.6 & 0.3\\  \mathbf{Tail} & 0.4 & 0.7  \end{array} = \begin{array}{c|cc} \hookleftarrow & \mathbf{0} & \mathbf{1} \\ \hline \mathbf{0} & 0.6 & 0.3 \\  \mathbf{1} & 0.4 & 0.7  \end{array}$Use a loop in your solution.<jupyter_code>#
# your solution is here
#<jupyter_output><empty_output><jupyter_text>click for our solution  Task 3Repeat Task 2 for 20, 30, and 50 coin tosses.<jupyter_code>#
# your solution is here
#<jupyter_output><empty_output><jupyter_text>click for our solution  Task 4Repeat Task 2 for 10, 20, and 50 coin tosses by picking different initial conditions, e.g.,         prob_head = prob_tail = 1/2or        prob_head = 0     prob_tail = 1<jupyter_code>#
# your solution is here
#<jupyter_output><empty_output><jupyter_text>click for our solution   Extra: Arbitrary transitions for GameCoinsBy changing the bias of each Asja's coin, we can define arbitrary GameCoins.If $ a $ is the probability of getting heads for one euro and $ b $ is the probability of getting heads for one cent, then we have the following transitions:$GameCoins(a,b) = \begin{array}{c|cc} \hookleftarrow & \mathbf{Head} & \mathbf{Tail} \\ \hline \mathbf{Head} & a & b\\  \mathbf{Tail} & 1-a & 1-b  \end{array} = \begin{array}{c|cc} \hookleftarrow & \mathbf{0} & \mathbf{1} \\ \hline \mathbf{0} & a & b \\  \mathbf{1} & 1-a & 1-b  \end{array}$  Task 5 Observe that if $ a=1 $ and $ b = 0 $, then it is Identity operator, i.e., the initial condition will stay as it is.If $ a=0 $ and $ b=1 $, then it is NOT operator. NOT operator swaps the probabilities of heads and tails in each step. If the initial probabilities are not $ 0.5 $ and $ 0.5 $, then the system never converges to a fixed probabilities.<jupyter_code>#
# your solution is here
#<jupyter_output><empty_output><jupyter_text>Task 6Randomly pick the values of $ a $ and $ b $, and then implement Tasks 3 and 4 for $ GameCoins(a,b) $.<jupyter_code>#
# your solution is here
#<jupyter_output><empty_output><jupyter_text>Task 710 times repeat Task 6 and observe whether the probabilities converge in each time.<jupyter_code>#
# your solution is here
#<jupyter_output><empty_output><jupyter_text>Task 8We can rewrite arbitrary GameCoins as $  \begin{array}{c|cc} \hookleftarrow & \mathbf{Head} & \mathbf{Tail} \\ \hline \mathbf{Head} & 1-y & x\\  \mathbf{Tail} & y & 1-x  \end{array} = \begin{array}{c|cc} \hookleftarrow & \mathbf{0} & \mathbf{1} \\ \hline \mathbf{0} & 1-y & x \\  \mathbf{1} & y & 1-x  \end{array}.$ We assume that it is neither Identity nor NOT operator. Then, independent of the initial state, the system always converges to $ Pr[\mbox{"heads"}] = \dfrac{x}{x+y} $ and $ Pr[\mbox{"tails"}]=\dfrac{y}{x+y} $, which are the probabilities of getting heads and tails, respectively.Observe this fact by checking the results of Task 7.<jupyter_code>#
# your solution is here
#<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14041565565987973, 'fraction_numerical': 0.029538980905158774, 'mean_word_length': 4.0371944739638685, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '60489', 'license': 'Apache-2.0', 'n_tokens_mistral': 3288, 'n_tokens_neox': 3019, 'n_words': 1130, 'path': 'classical-systems/CS12_Coin_Flip_Game.ipynb', 'repo_name': 'jaorduz/QWorld2021_QMexico', 'size': '9491'}