# Inner product of states in Q#

I have a state $$|x\rangle$$ and I want to get the expected result when measuring observable $$A$$ (i.e. get the result of $$\langle x| A | x \rangle$$). In my case $$A$$ can be any of the Pauli gates. Does anyone know how to do this in Q#? There doesn't seem to be an inner product function in the libraries.

Thanks for the help!

Q# has a Measure operation which performs a measurement in a given Pauli basis. For example, if you have a Qubit object q in some state $$|\psi\rangle$$ and you want to measure it in the $$X$$ basis, you can write:
   let result = Measure([PauliX], [q]);

Here result will be either Zero or One. If you want to then estimate the expectation value of the measurement, you would need to repeat your full operation (including whatever you did to prepare your qubit in the state $$|\psi\rangle$$) many times and take an average of the measurement results.
• If your qubit is in the |0⟩ state, that is a Pauli-Z basis state. In terms of Pauli-X basis states, |0⟩ = (|+⟩ + |-⟩)/sqrt(2), so it is actually in superposition with respect to that basis. When measuring a state in the Pauli-X basis, a Zero result corresponds to |+⟩ and a One result corresponds to |-⟩. So it's correct that measuring the state |0⟩ in the Pauli-X basis will give equal probabilities of Zero and One. On the other hand, if you measure |0⟩ in the Pauli-Z basis, you should get Zero with 100% probability. May 16, 2020 at 13:51