# Lecture 018 - Hadamard Test

To measure the rotational degree of a operation $U$

1. one way is to analyze the method to produce the rotation $U$
2. and the other way is to look at the result of applying the rotation $U$.

or, do some transformation on $U$ and then apply, for example, controlled-$U$.

Since determine the outcome of a computation without running it is not computable, we need to look at the result of rotation. Therefore we need to put in qubits to the rotation machine and observe the output qubit.

• rotation is always around an axis through the origin

• rotation applied to a vector in a plane orthogonal to the rotational axis will yield greatest cosine difference (maximum change in angle)

• rotation applied to a vector in rotational axis will have no effect to the vector

• therefore, talking about "the angle of rotation" is meaningless without giving the vector the rotation supposed to be applied to.

• to measure rotation of an operation $U$ applied to $|start\rangle$ by observing the change in angle, we can measure the rotation $U$ applied to any vector $|v\rangle$ that is in the same rotational plane as $|start\rangle$.

Hadamard Test allow us to measure the rotation $U$ performed on $|start\rangle$ giving only one copy of $|start\rangle$ repeatedly without collapse $|start\rangle$ to deterministic state.

## Quantum Phase Estimation

Although Q.P.E. is about complex unitrary eigenvectors and values. This is not what we study today.

In Grover, we can:

• make $|start\rangle \in \mathbb{R}^N$ (by making $|111\rangle$)

• make mystery quantum operation $U$ (that's a "combo")

Given an unknown $|start\rangle$, how to you use it to do measurement against $|start\rangle$ multiple times?

def measureAgainstMysteryStart(U, |start>)
Make T
H on T
If T then U on |start>
H on T
Measure T
return |start> # that is rotated


Note that we can easily make Controll-U operation by replacing every suboperation $s$ in $U$ with Controll-$s$.

U|\text{start}\rangle = U\begin{bmatrix} a\\ b\\ c\\ d\\ \end{bmatrix} = \begin{bmatrix} e\\ f\\ g\\ h\\ \end{bmatrix}

Then we have:

Pr\{T=0\} = \left(\frac{a+e}{2}\right)^2 + \left(\frac{b+f}{2}\right)^2 + \left(\frac{c+g}{2}\right)^2 + \left(\frac{d+h}{2}\right)^2 = \langle\text{avg}|\text{avg}\rangle = \left(\cos\frac{\theta}{2}\right)^2\\ \text{and state rotate to }\frac{|\text{avg}\rangle}{\cos(\theta/2)}\\ Pr\{T=1\} = \left(\frac{a-e}{2}\right)^2 + \left(\frac{b-f}{2}\right)^2 + \left(\frac{c-g}{2}\right)^2 + \left(\frac{d-h}{2}\right)^2 = \langle\text{disp}|\text{disp}\rangle = \left(\sin\frac{\theta}{2}\right)^2\\ \text{and state rotate to }\frac{|\text{disp}\rangle}{\sin(\theta/2)}\\

Notice that all vectors $|avg\rangle, |disp\rangle, |start\rangle, U|start\rangle$ are all in the same rotational plane. Therefore, we can reuse $|start\rangle$ for the next test (only remake $T$) for testing the same operation. Moreover, observe $|avg|\rangle \perp |disp\rangle$.

However, using above method, we can't distinguish between $\pi + \delta$ and $\pi - \delta$. This is because our probability is squared (see above image: the $x$ value is $\theta$ of our rotation and the $y$ axis is $Pr\{T = 1\}$).

From the above formula, Hadamard Test can distinguish rotation by 0 degrees and rotation by 180 degrees, since in the case of 0 degrees $Pr\{T = 0\} = 1$ and in the case of 180 degrees $Pr\{T = 0\} = 0$.

Q: This is strange: since rotation in a 2D plane by $180^\circ$ will always negate the entire vector, and there is no way to tell the difference between $|v\rangle$ and $-|v\rangle$. Therefore there shouldn’t be a way to tell the difference between $0^\circ$ and $180^\circ$ rotation.

A: Suppose I have a qubit in state $|v\rangle$ and a quantum operator $U$, which I promise to be either the identity operator or the Minus operator. Then, I would argue that it is possible to determine which one $U$ is. We can see this when we do "If A then U." We know the "If A then Minus" is a useful operator, as in it helps us do things (e.g. Grover's). However, "If A then identity" is not a useful operator. So we can determine $U$ by simply observing the side effects of using Controlled-$U$. (When you make a controlled version, "doing nothing" is different from "invert but only certain axis") So in summary, we don't have to test an operation by just applying it, we can transform our operation (make it a controlled version) and then test it.

### Revolver Resolver

The exact Revolver Resolver pseudocode is very hard to write

• you have to do a proper translation from probability to angle

• you have to do a angle to digit translation for every significant digit

• you need to make $U^{2^d}$ efficiently

• you can only rotate after creation of $T$. (Can you simultaneously create a bunch of $T$ and then do only 1 measurement?) // QUESTION: is this true?

## - you don't have to consider side effect of Hadamard Test that rotate the original $|start\rangle$ depending on the measuring outcome

// TODO: psdo code

Input:

• basis vector: $|start\rangle$

• operation: $U$

• digits of accuracy: $d$

Output: $\theta$ with $d$ digits of accuracy

Complexity: $d$ measurements, $O(1)$ use of $\{U^{2^0}, U^{2^1}, ..., U^{2^k}\}$ for $2^k = 10^d$ (total $O(d)$ different rotations, instead of $2^{d-1}$ we learned from last class)

• To create $\{U^{2^0}, U^{2^1}, ..., U^{2^k}\}$, we can naively construct using $O(2^k)$ steps

• But if we know how to simplify $U^{2^k}$, we can construct by repeatably squareing. If our function $U$ represent $U(x) = a^{2^d} \cdot x \mod F$ and $F$ has $n$ digits, we can make $U^{2^k}$ (and $\{U^{2^0}, U^{2^1}, ..., U^{2^k}\}$) in $O(nd)$ steps.

$O(nd\log d + d)$ if we can efficiently power matrix, $O(10^d\log d + d)$ otherwise.

## Standard Form

Any algorithm can be put into standard form: 1. make all qubits at the beginning 2. then do only quantum operations 3. then only measure at the end

Table of Content