Codercise H.7.2


I am having trouble with the section a) of the exercise. I believe I understood correctly how to build the PREPARE matrix. First we should substract the alpha coefficients from the zero vector and divide it by its norm. This will result in the state that will be given to the householder function to get the PREPARE matrix.

    zero_vec = np.array([1] + [0]*(2**k_bits - 1))
    state = (zero_vec - alpha_list) / np.linalg.norm(zero_vec - alpha_list)
    return householder(state)

This is the code I use to perform this operation.

I did by hand some calculations and ran the code locally, the results were as follows:

If I did the calculations correctly, these should be the expected PREPARE matrices for the corresponding alphas. Nevertheless, I could have made a mistake either on the calculations or on the code, so any help is appreciated :grin:.


Hello @erqs !

You are almost there! Just make sure that |\alpha\rangle is a proper state, i.e., it is normalized. :wink:

Hi @ludmilaaasb,

I got it, thanks for the hint. I thought that First, |alpha> is a vector of coefficients which has been normalized and can therefore be interpreted as a state. meant that the vector was already being given normalized :upside_down_face:. Anyways, thanks again for the help.


Indeed. It does look misleading. :thinking:

I’ll contact the team and suggest a fix! Thank you! :slight_smile:

1 Like