Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-optimal number of iterations in Grover's algorithm tutorial #1222

Closed
jhwatrous opened this issue Nov 16, 2023 · 0 comments · Fixed by #1293
Closed

Sub-optimal number of iterations in Grover's algorithm tutorial #1222

jhwatrous opened this issue Nov 16, 2023 · 0 comments · Fixed by #1293
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jhwatrous
Copy link

jhwatrous commented Nov 16, 2023

In the tutorial Grover's algorithm using the Sampler primitive the number of iterations claimed to be optimal for Grover's algorithm is this number:

$$ \left\lfloor \frac{\pi}{4} \sqrt{\frac{N}{s}} \right\rfloor $$

where $N = 2^n$ and $s$ is the number of marked items.

Screen Shot 2023-11-16 at 11 56 12 AM

This number is usually optimal but not always — the number should be this:

$$ \left\lfloor \frac{\pi}{4 \sin^{-1}\left(\sqrt{s/N}\right)} \right\rfloor $$

For example, if there are $n=7$ bits (so $N=2^7 = 128$) and there are $s = 19$ marked items, then the two expressions give a number of iterations that differ by one, and the second number of iterations (which is optimal) succeeds with a probability slightly larger than the first: about 85.9% versus 84.3%.

Suggested solutions

Use the second formula.

@jhwatrous jhwatrous added the bug Something isn't working label Nov 16, 2023
@jhwatrous jhwatrous reopened this Nov 16, 2023
@kt474 kt474 self-assigned this Dec 28, 2023
@kt474 kt474 added this to the 0.18.0 milestone Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants