<jupyter_start><jupyter_text>prepared by <NAME> (QLatvia)                 This cell contains some macros. If there is a problem with displaying mathematical formulas, please run this cell to load these macros. $ \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{\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 } $  Quantum states with complex numbers  The main properties of quantum states do not change whether we are using complex numbers or not. Let's recall the definition we had in Bronze:**Recall: Quantum states with real numbers**When a quantum system is measured, the probability of observing one state is the square of its value.The summation of amplitude squares must be 1 for a valid quantum state.The second property also means that the overall probability must be 1 when we observe a quantum system. If we consider a quantum system as a vector, then the length of such vector should be 1. How complex numbers affect probabilitiesSuppose that we have a quantum state with the amplitude $a+bi$. What is the probability to observe such state when the quantum system is measured? We need a small update to our statement about the probability of the measurement - it is equal to the square of the absolute value of the amplitude. If amplitudes are restricted to real numbers, then this update makes no difference. With complex numbers we obtain the following:$\mathopen|a+bi\mathclose| = \sqrt{a^2+b^2} \implies \mathopen|a+bi\mathclose|^2 = a^2+b^2$.It is easy to see that this calculation works fine if we do not have imaginary part - we just obtain the real part $a^2$. Notice that for the probability $a^2 + b^2$ both real and imaginary part contribute in a similar way - with the square of its value.<!--Let's check the square of the complex number:$(a+bi)^2 = (a+bi)(a+bi) = a^2 + 2abi + b^2i^2 = (a^2-b^2) + 2abi$.In such case we still obtain a complex number, but for a probability we need a real number. -->Suppose that we have the following vector, representing a quantum system:$$    \myvector{ \frac{1+i}{\sqrt{3}} \\ -\frac{1}{\sqrt{3}} }.$$This vector represents the state $\frac{1+i}{\sqrt{3}}\ket{0} - \frac{1}{\sqrt{3}}\ket{1}$. After doing measurement, we observe state $\ket{1}$ with probability $\mypar{-\frac{1}{\sqrt{3}}}^2 = \frac{1}{3}$. Let's decompose the amplitude of state $\ket{0}$ into form $a+bi$. Then we obtain $\frac{1}{\sqrt{3}} + \frac{1}{\sqrt{3}}i$, and so our probability is $\mypar{\frac{1}{\sqrt{3}}}^2 + \mypar{\frac{1}{\sqrt{3}}}^2 = \frac{2}{3}$.  Task 1 Calculate on the paper the probabilities to observe state $\ket{0}$ and $\ket{1}$ for each quantum system:$$    \myvector{ \frac{1-i\sqrt{2}}{2} \\ \frac{i}{2} }     \mbox{ , }    \myvector{ \frac{2i}{\sqrt{6}} \\ \frac{1-i}{\sqrt{6}} }     \mbox{ and }    \myvector{ \frac{1+i\sqrt{3}}{\sqrt{5}} \\ \frac{-i}{\sqrt{5}} }.$$. click for our solution  Task 2 If the following vectors are valid quantum states, then what can be the values of $a$ and $b$?$$    \ket{v} = \myrvector{0.1 - ai \\ -0.7 \\ 0.4 + 0.3i }    ~~~~~ \mbox{and} ~~~~~   \ket{u} = \myrvector{ \frac{1-i}{\sqrt{6}} \\ \frac{1+2i}{\sqrt{b}} \\ -\frac{1}{\sqrt{4}} }.$$<jupyter_code>#
# your code is here 
#    (you may find the values by hand (in mind) as well)
#<jupyter_output><empty_output><jupyter_text>click for our solution  Task 3Randomly create a 2-dimensional quantum state, where both amplitudes are complex numbers.Write a function that returns a randomly created 2-dimensional quantum state.Hint:     Pick four random values between -100 and 100 for the real and imaginary parts of the amplitudes of state 0 and state 1      Find an appropriate normalization factor to divide each amplitude such that the length of quantum state should be 1 Repeat several times:     Randomly pick a quantum state      Check whether the picked quantum state is valid     _Note:_ Comment out the first line after writing your code to store the function you have written for later use.<jupyter_code>#%%writefile random_complex_quantum_state.py
from random import randrange
def random_complex_quantum_state():
    # quantum state 
    quantum_state=[0,0]
    #
    #
    #
    return quantum_state
#%%writefile is_quantum_state.py
# testing whether a given quantum state is valid
def is_quantum_state(quantum_state):
#
# your code is here
#

#Use the functions you have written to randomly generate and check quantum states
#
# your code is here
#<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16929530201342283, 'fraction_numerical': 0.032550335570469796, 'mean_word_length': 3.992462311557789, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '48229', 'license': 'Apache-2.0', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1852, 'n_words': 669, 'path': 'silver/C02_Quantum_States_With_Complex_Numbers.ipynb', 'repo_name': 'dev-aditya/QWorld_Summer_School_2021', 'size': '5971'}