%run qlatvia.py

draw_qubit()

sqrttwo=2**0.5

draw_quantum_state(1,0,"")

draw_quantum_state(1/sqrttwo,1/sqrttwo,"|+>")

# drawing the angle with |0>-axis
from matplotlib.pyplot import gca, text
from matplotlib.patches import Arc
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=0,theta2=45) )
text(0.08,0.05,'.',fontsize=30)
text(0.21,0.09,'\u03C0/4')

%run qlatvia.py

draw_qubit()

sqrttwo=2**0.5

draw_quantum_state(0,0,"")

draw_quantum_state(1/sqrttwo,1/sqrttwo,"|+>")

# line of reflection for Hadamard
from matplotlib.pyplot import arrow
arrow(-1.109,-0.459,2.218,0.918,linestyle='dotted',color='red')

# drawing the angle with |0>-axis
from matplotlib.pyplot import gca, text
from matplotlib.patches import Arc
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=0,theta2=22.5) )
text(0.09,0.015,'.',fontsize=30)
text(0.25,0.03,'\u03C0/8')
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=22.5,theta2=45) )
text(0.075,0.065,'.',fontsize=30)
text(0.21,0.16,'\u03C0/8')

%run qlatvia.py

draw_qubit()

# line of reflection for Hadamard
from matplotlib.pyplot import arrow
arrow(-1.109,-0.459,2.218,0.918,linestyle='dotted',color='red')

#
# your code is here
#

# visually draw the reflections
# second draw

sqrttwo=2**0.5

draw_quantum_state(0,1,"|1>")

draw_quantum_state(1/sqrttwo,-1/sqrttwo,"|->")


%run qlatvia.py

draw_qubit()

# line of reflection for Hadamard
from matplotlib.pyplot import arrow
arrow(-1.109,-0.459,2.218,0.918,linestyle='dotted',color='red')

#
# your code is here
#
sqrttwo=2**0.5

draw_quantum_state(-1,0,"-|0>")

draw_quantum_state(-1/sqrttwo,-1/sqrttwo,"-|+>")

%run qlatvia.py

draw_qubit()

# line of reflection for Hadamard
from matplotlib.pyplot import arrow
arrow(-1.109,-0.459,2.218,0.918,linestyle='dotted',color='red')

#
# your code is here
#
sqrttwo=2**0.5

draw_quantum_state(0,-1,"-|1>")

draw_quantum_state(-1/sqrttwo,1/sqrttwo,"-|->")

%run qlatvia.py

draw_qubit()

# line of reflection for Hadamard
from matplotlib.pyplot import arrow
arrow(-1.109,-0.459,2.218,0.918,linestyle='dotted',color='red')

#
# your code is here
#

# create a random quantum state
random_state = random_quantum_state2()

# draw random
draw_quantum_state(random_state[0],random_state[1],"randomState")

# apply hadamard
sqrttwo=2**0.5
next_state = [random_state[0] * (1/sqrttwo) + random_state[1] * (1/sqrttwo), random_state[0] * (1/sqrttwo) + random_state[1] * -(1/sqrttwo)]
# draw the state
draw_quantum_state(next_state[0],next_state[1],"refectState")


%run qlatvia.py

draw_qubit()

#
# your code is here
#
random_state = random_quantum_state2()

# draw random
draw_quantum_state(random_state[0],random_state[1],"randomState")

# find the reflection to x-axis
# apply hadamard
sqrttwo=2**0.5
next_state = [random_state[0] * (1/sqrttwo) + random_state[1] * (1/sqrttwo), random_state[0] * (1/sqrttwo) + random_state[1] * -(1/sqrttwo)]
# draw the state
draw_quantum_state(next_state[0],next_state[1],"refectState")

%run qlatvia.py

draw_qubit()

# the line y=x
from matplotlib.pyplot import arrow
arrow(-1,-1,2,2,linestyle='dotted',color='red')

#
# your code is here
#
random_state = random_quantum_state2()

# draw random
draw_quantum_state(random_state[0],random_state[1],"randomState")

# find the reflection to x-axis
# apply hadamard
sqrttwo=2**0.5
next_state = [random_state[0] * 0 + random_state[1] * 1, random_state[0] * 1 + random_state[1] * 0]
# draw the state
# not operator -> switches x and y
draw_quantum_state(next_state[0],next_state[1],"refectState")

%run qlatvia.py

draw_qubit()

#
# your code is here
#
# line of reflection 
from matplotlib.pyplot import arrow
#arrow(x,y,dx,dy,linestyle='dotted',color='red')
#
#
# draw_quantum_state(x,y,"name")


import numpy as np
import math
# method for reflection matrix
def get_reflection_matrix(theta):
    reflect_matrix = np.array([[math.cos(2 * theta), math.sin(2 * theta)],[math.sin(2 * theta), -math.cos(2 * theta)]])
    return reflect_matrix

# obtain a random quantum state
random_quantum_state = np.array(random_quantum_state2())
draw_quantum_state(random_quantum_state[0],random_quantum_state[1],"q-state")
theta = math.pi/8
reflected_state = np.matmul(get_reflection_matrix(theta), random_quantum_state)
draw_quantum_state(reflected_state[0],reflected_state[1],"reflect-q-state")

arrow(0,0,math.cos(theta),math.sin(theta),linestyle='dotted',color='red')

