Arithmetic Block in Shor Algorithm

Click For Summary

Discussion Overview

The discussion focuses on the arithmetic component of Shor's algorithm for prime factorization, particularly the implementation of the function f(x) = ax mod N and the use of controlled gates in a quantum context. Participants explore both theoretical and practical aspects of this arithmetic block, including its execution under superposition.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant seeks clarification on the implementation of the arithmetic block in Shor's algorithm, specifically regarding the simultaneous calculation of f(x) values and the implications of superposition on controlled gates.
  • Another participant describes their work on a paper detailing a complete implementation of Shor's algorithm using 2n+1 qubits, emphasizing that arithmetic can be performed with classical reversible circuits despite the quantum nature of the algorithm.
  • A participant mentions the use of a quantum circuit simulator, Quirk, to simulate the period-finding part of Shor's algorithm, noting limitations in performing the continued fractions algorithm within the simulator.
  • One participant expresses confusion about how to handle superposition when the control qubit value is unknown, prompting further clarification from others.
  • Another participant explains that controlled operations can be performed using a phase estimation qubit as the control, indicating that the operation affects only the relevant part of the superposition.

Areas of Agreement / Disagreement

Participants generally agree on the use of classical reversible circuits for arithmetic in Shor's algorithm, but there remains some uncertainty regarding the handling of superposition and controlled operations, with differing levels of understanding expressed.

Contextual Notes

Some assumptions about the nature of superposition and the specifics of controlled operations remain unresolved, as participants discuss their implications without reaching a consensus.

Ricardo Belchior
Messages
13
Reaction score
0
Hello everyone!

So I was looking at Shor Algorithm for prime factorization and I have some doubts in the arithmetic part.

Let's define a function f that : f(x) = ax mod N. The middle step in shor algorithm is to calculate, simultaneously, all values of f. In some papers and books, I saw some high level implementation of this block, but nothing concrete. Can someone explain to me, how they do this?

In some implementations they use Controlled-Gates. Ok, that's fine, but the control qubit is always in some superposition of states. So what happens in this cases?Thanks!
 
Physics news on Phys.org
I've been working on a paper that explains how to implement Shor's algorithm from top to bottom using 2n+1 qubits (w/ n-1 in an unknown state that must be preserved) (the previous best was 2n+2 w/ none in an unknown state). Here's a few diagrams from it.

The fact that the exponentiation is calculated under superposition doesn't really matter at all. All the arithmetic can be done with classical reversible circuits. There are some optimizations made possible by quantum gates, and of course the very top level has some quantum stuff, but all the arithmetic really is just standard classical reversible stuff.

An adder (not novel):

inline-adder.png


Incrementing (novel):

controlled-increment-odd.png


Scaled modular addition (not really novel; clearly I should just be adding 2^p*K instead of doing this doubling stuff):

controlled-modular-multiply-accumulate.png


Transitive reduction of the dependency graph between constructions:

dependencies.png


As that last diagram shows, there's a rather lot of constructions on the path from exponentiation to Toffolis. But they all basically look like the diagrams I showed: take what you've built up so far, and combine it to build the next thing.
 
Last edited:
Incidentally, you can simulate the period-finding part of Shor's algorithm in my quantum circuit simulator Quirk.

You can't do the follow-up continued fractions algorithm to turn the period into a factor in Quirk, so mostly you can just see that "Yup, there's strong peaks near 2^n*k/p where p is the period and k is arbitrary". But still Quirk is a tool I used when looking for / optimizing / checking most of the constructions. I would add a known-good construction plus its inverse to the circuit, set up a "test harness" that made/unmade random test vectors, and then just watched to make sure the output stayed consistently off as I tried to optimize one of the constructions.
 
Thanks a lot! That schemes where very helpful. But I still don't get that superposition thing. If I don't know the control qubit value, how do I do it? I suppose you assume some value? I think that I do not get that superposition part.
 
You just do a controlled operation with the appropriate phase estimation qubit as the control. The operation will only affect the part of the superposition where the control is on.

Controlled operations are also a classical reversible computing concept, so again you don't need to know any quantum computing to implement circuits that do controlled arithmetic. (Notice that the diagrams do include controls)
 
Ok Thanks, I think I got it.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K