Grover's search for one solution using Silq programming
In this section, let's start coding Grover's search algorithm using the Silq programming language and you will see that the uncomputation of Grover's oracle and the Grover diffusion circuit happens automatically. Because of this advantage of automatic uncomputation, the Grover code is very simple and concise and intuitive.
Let's start coding the Grover diffusion operator first because that operator is generic and can be used by any kind of Grover's oracle. Open a new Silq file, name it groverDiffusion.slq
, and save it inside a folder called helpers
. Then, inside this file, insert the following code:
def groverDiffusion[n:!](cand:uint[n])mfree: uint[n]{ Â Â Â Â for k in [0..n) { cand[k] := H(cand[k]); } Â Â Â Â if cand!=0{ phase(); } Â Â Â Â for k in [0..n) { cand[k] := H(cand[k]); } Â Â Â Â return cand; }
Let's try to understand...