Grover's Algorithm: solve \text{SAT} in O(n^\frac{n}{2})
Unique SAT: promise there is exactly one solution in a circuit SAT.
Notice for Bias Busting, we detect if a truth table is biased toward 1 or !0$. For Unique SAT, we determine which row there is a 1.
The true power is that we can first Had all bits to uniform superposition, then we can compile a classical code to quantum gates just by running sign-compute on uniform superposition.
In order to understand grover's algorithm, we first build some helper function such that: when given a bunch of amplitude, it calculates the mean of the amplitude and reflect every amplitude accross the mean amplitude.
def reflection_accross_mean():
Had X1, X2, ..., Xn
If OR(X1, X2, ..., Xn) then Minus
Had X1, X2, ..., Xn
Notice the above function is 4n instruction where n is the number of variables.
After the first line, we produce some vector who's first element is the mean and some random stuff after it:
After the second line, we add negative sign on all amplitudes except the first one.
After the third line, we successfully get reflected version of \vec{f} called \vec{f'}. But why?
Essentially, we need to prove that
To see why, let's write \vec{f} as its mean \mu plus difference \vec{\Delta}
Then reflection accross mean just means we want to transform
To see that \vec{f'} equals, let's write \vec{g} differently. $$ \vec{g} = \mu \begin{bmatrix} 1\ 0\ \dots\ 0\ 0\ \end{bmatrix} + \begin{bmatrix} 0\ ?\ \dots\ ?\ ?\ \end{bmatrix} = \mu \vec{10} + \vec{?}\ $$
Then we have the following
Now, we have successfully proved the correctness of reflect accross the mean.
Problem: given f : \{0, 1\}^n \to \{0, 1\}, find input x so that f(x) = 1.
Think
Had x1, x2, ...
followed by a signed compute as a way to do start some parallel computation by brute force trying all inputs but storing the result into negative amplitude.
@require x1, x2, ... = 0
def solve_sat(f):
// prepare uniform superposition
Had x1, x2, ...
// repeat following two steps
If f() then Minus // reflection accross 0
reflection_accross_mean()
Let's trace down the states
For n variables with T, we need O(T) instructions for if f() then minus
and O(n) instructions for reflection accross mean
. If we repeat k times, then it is O(knT)
For small enough k \leq 0.01\sqrt{2^n}, amplitude of x^* is about 2k + 1. Which is about \frac{1}{2500} probability.
To get Pr\{\text{print out } x^*\} \simeq 100\%, we need:
The following two computation are equivalent:
H on A
CNOT B A
H on A
H on B
CNOT A B
H on B
They all change amplitude on \alpha|11\rangle to -\alpha|11\rangle. (Can be proved by brute force computation using grids.)
Table of Content