from math import cos, pi, acos

print("cosine of 90 degrees is zero:",cos(pi/2))

# find the degree of two unit vectors having the dot product of 0.
radian_degree = acos(0)
degree = 360*radian_degree/(2*pi)
print("the degree of two unit vectors having the dot product of 0 is",degree,"degrees")

# include our predefined functions
%run qlatvia.py

# draw the axes
draw_qubit()

#
# your solution is here
#
draw_quantum_state(3/5,4/5,"main")
draw_quantum_state(-4/5,3/5,"ort1")
draw_quantum_state(4/5,-3/5,"ort2")

draw_qubit()
draw_quantum_state(3/5,-4/5,"main")
draw_quantum_state(4/5,3/5,"ort1")



# randomly create a 2-dimensional quantum state
from math import cos, sin, pi
from random import randrange
def random_quantum_state2():
    angle_degree = randrange(360)
    angle_radian = 2*pi*angle_degree/360
    return [cos(angle_radian),sin(angle_radian)]

# finding the angle of a 2-dimensional quantum state
from math import acos, pi
def angle_quantum_state(x,y):
    angle_radian = acos(x) # radian of the angle with state |0>
    angle_degree = 360*angle_radian/(2*pi) # degree of the angle with state |0>
    # if the second amplitude is negative, 
    #     then angle is (-angle_degree)
    #     or equivalently 360 + (-angle_degree)
    if y<0: angle_degree = 360-angle_degree # degree of the angle
    # else degree of the angle is the same as degree of the angle with state |0>
    return angle_degree


%run qlatvia.py

draw_qubit()

from math import acos, pi

[x1,y1]=random_quantum_state() # randomly pick a quantum state
first_angle = angle_quantum_state(x1,y1)
print("the angle of |u> is",first_angle)

[x2,y2]=random_quantum_state() # randomly pick a quantum state
second_angle = angle_quantum_state(x2,y2)
print("the angle of |c> is",second_angle)

angle_between_1 = first_angle - second_angle
if angle_between_1 < 0: angle_between_1 *= -1
if angle_between_1 >180: angle_between_1 = 360 - angle_between_1

dot_product = x1*x2+y1*y2
print("their dot prouct is",dot_product)

angle_between_radian = acos(dot_product)
angle_between_2 = 360 * angle_between_radian/(2*pi)

print("the angle in between is calculated as",angle_between_1,"and",angle_between_2)

draw_quantum_state(x1,y1,"|u>") 
draw_quantum_state(x2,y2,"|v>")

