#
# your code is here 
#    (you may find the values by hand (in mind) as well)
#
import numpy as np
v = np.array([0, -0.1, 0.3, 0.4, 0.5])
v_square = v ** 2
print(v_square)
a = 1 - np.sum(v_square[1:])
a = np.sqrt(a)
print("a: "+ str(a))
u = np.array([1/np.sqrt(2), -1/np.sqrt(3)])
u_square = u ** 2
print(u_square)
b0 = 1/(1 - np.sum(u_square))
print("b: " + str(b0))

#%%writefile FILENAME.py
# for storing the content of this cell, 
#   comment out the the first line (by modifying the FILENAME) 
#   and then execute the cell
#
# later, you can execute your saved content by using %run FILENAME.py
#

#
# you may define your first function in a separate cell 
#     and then save it to a file for using it later
#

from random import randrange
def random_quantum_state():
    # quantum state 
    quantum_state=[0,0]
    r = randrange(101)
    r = r / 100
    r = np.sqrt(r)
    if randrange(2) == 0:  # randomly make the value negative
        r = -1 * r
    quantum_state[0] = r
    # second entry
    quantum_state[1] = np.sqrt(1 - r**2)
    return quantum_state

#
# your code is here
#
quantum_state = random_quantum_state()
print(quantum_state)
hadamard_matrix = np.array([[(1/(np.sqrt(2))), (1/(np.sqrt(2)))],[(1/(np.sqrt(2))), (-1/(np.sqrt(2)))]])
new_quantum_state = np.matmul(hadamard_matrix, np.array(quantum_state))
print(new_quantum_state)

def verify_quantum_state(quantum_state):
    square_of_state = np.power(quantum_state, 2)
    summation = np.sum(square_of_state) 
    return np.sqrt(summation)

print(verify_quantum_state(quantum_state))
print("should be close to 1: " + str(verify_quantum_state(new_quantum_state)))
results = []
for test in range(100):
    quantum_state = random_quantum_state()
    sums = verify_quantum_state(quantum_state)
    results.append(sums)

summation = np.sum(np.array(sums)) 
print(summation)

