Discover
/
Article

Some curious facts about quantum factoring

OCT 01, 2007
For six years before he retired last year, David Mermin taught quantum computation to Cornell University students of computer science. Google “CS483” for his lecture notes, where everything that he says can easily be shown is shown easily.

DOI: 10.1063/1.2800253

N. David Mermin

PTO.v60.i10.10_1.d1.jpg

As explained in my Reference Frame column of April 2007 (page 8), a key to factoring the product N = pq of two prime numbers, each hundreds of digits long, is being able to find the smallest power r for which ar (mod N) = 1 for random integers a. (Two numbers are equal modulo N if they differ by a multiple of N.) Peter Shor’s 1994 discovery that a quantum computer would be superefficient at this cryptographically crucial task underlies today’s wide-spread interest in quantum computation. Shor’s period-finding algorithm—so called because the function f(x) = ax (mod N) is periodic with period r—illustrates in striking ways the novel basis quantum mechanics provides for computation.

In a quantum computer, a nonnegative integer x less than 2 n is represented by the product state | x n = | x n - 1 | x 0 of n two-state systems (called Qbits—if you prefer the vulgar spelling qubit , please regard Qbit as an abbreviation), where xn-1, …, x 0 are the bits (0 or 1) in the binary expansion of x. Quantum-computational architecture executes a function f that takes n-bit integers to m-bit integers, with a linear subroutine U f that takes an n-Qbit “input register” initially in the state | x n and an m-Qbit “output register” initially in the state | 0 m into the state | x n | f ( x ) m .

Suppose the initial state of the input register is the superposition of all possible n-Qbit inputs,

| φ = ( 1 / 2 n / 2 ) x | x n .

(This can be constructed by starting with each Qbit in the state | 0 and applying to each a rotation taking | 0 into ( 1 / 2 ) ( | 0 + | 1 ) . ) Since U f is linear, if the initial state of input and output registers is | φ | 0 m then their final joint state will be

| Ψ = ( 1 / 2 n / 2 ) x | x n | f ( x ) m .

So it appears that just one application of the subroutine evaluates the function f for all the 2 n possible values of x. This trick is called “quantum parallelism.”

But appearances can be deceptive. Given a system in a state you know nothing about, there is no way to learn that state. You can only extract information through measurement. If you immediately measure all the Qbits, you acquire a random value x 0 of x and the value f 0 of f(x 0), after which the state becomes | x 0 n | f 0 m from which you can learn nothing more. So you could have accomplished as much with an ordinary classical computer by feeding it a random input.

Ah, but suppose you measure only the m Qbits in the output register. When f(x) is ax (mod N), you will find with equal probability any one of the r distinct values f 0 and the input register will be left in a state | ψ proportional to

| x 0 n + | x 0 + r n + | x 0 + 2 r n + ,

where x 0 is that random integer less than r at which a x 0 (mod N) = f 0.

This looks promising. By learning only two of the many states | x appearing in | ψ , you could learn a multiple of the sought-for period r and be well on the way to learning r itself. With high probability, you could learn such a multiple with two measurements on two sets of Qbits, both in the same state | ψ . But this route to success is thwarted by the “no-cloning” theorem, which establishes the impossibility of duplicating an unknown quantum state. Something more clever is needed.

Fourier to the rescue

The clever move is Fourier analysis, in the form of a spectacularly efficient linear subroutine U FT that takes the n-Qbit state | x n into

U FT | x n = ( 1 / 2 n / 2 ) y e 2 π i x y / 2 n | y n .

Here the eyes of the quantum physicist tend to glaze over. Ah yes, if you go from position to momentum states, then measurement probabilities become sharply peaked at integral multiples j/r of the inverse period, from which the period r itself can be learned. Ho-hum.

But things are not ho-hummish. To lose interest at this stage is to overlook two crucial differences from boring everyday quantum mechanics. First, x has nothing to do with the position of anything, concrete or abstract. It is an arithmetically useful numerical construction out of the states | x i of n independent two-state systems, devoid of physical content: x = x 0 + 2 x 1 + 4 x 2 + + 2 n - 1 x n - 1 . . Second, “sharply peaked” normally means sharply enough that widths are smaller than the resolution of any detectors. But here one wants an integer r that could be hundreds of digits long. An error of only one part in 1010 would get all but a few digits wrong. Such precision lends to the word “sharp” new meaning that no physicist ever dreamed of. All the folklore has to be reexamined.

Reexamination shows that when n Qbits in the state U FT | ψ are measured, the resulting integer 0 y < 2 n has a significant (over 40%) chance of being within ½ of—that is, as close as possible to—an integral multiple of 2 n /r. So with a little luck, y/2 n is going to be within ½ n + 1 of j/r for some random integer j. Does this pin down a unique rational number j/r? Suppose there is a second candidate j / r j / r . The difference between them is ( j r - j r ) / r r . Since the candidates are different, the integer j r j r can’t be zero, and since the possible periods r and r’ are both less than N, the difference between the candidates is at least 1/N 2. So if 2 n > N 2, such an integer y does indeed determine a unique rational number j/r.

Of course, j/r determines not r, but r after any factors it has in common with the random integer j have been divided out. So what our quantum computer gives us is a 40% shot at learning a divisor r 0 of r. The odds that j and r have any really big factors in common are small, so chances are that r will be a fairly small multiple of r 0. You can easily check with a classical computer to see if ax = 1 (mod N) when x = r 0. If so, r = r 0. If not, try 2 r 0 , 3 r 0 , , and with a little luck one of them will work. If you get up to 1000 r 0 without success, then either you were in the unlucky 60%, or the j you got did indeed share a large factor with r. In that case try the whole thing over again. After not enormously many runs, you’re quite likely to succeed. And that is how Shor’s “factoring” algorithm actually works.

Troublesome phases

But wait a minute! Looking more closely at the crucial subroutine U FT, one finds it to be cunningly constructed out of operations that apply conditional phase shifts e 2 π i φ to Qbits, where the values of φ are inverse powers of 2, ranging from ½ to ½ n . Since 2 n must exceed N 2, and N is hundreds of digits long, most of those phase shifts are absurdly tiny—far too tiny for real hardware, with its inevitable imperfections, to produce. All a real quantum computer can execute is an approximate U FT, grotesquely crude on the scale of parts in 10300, the scale on which one needs to learn the period r.

When this dawned on me, I concluded that all the hoopla rested on a silly failure to notice that you can’t turn fields on and off for durations you control to parts in 10300. But I was the silly one. I failed to appreciate the exquisite interplay between digital and analog in a quantum computation. Subroutines like U FT depend on parameters that vary continuously, as in analog computation. But readout through measurement produces an unambiguous sequence of 0s and 1s, as in digital computation. Reading out a thousand Qbits gives you a thousand bits of a definite integer—about 300 digits of the decimal representation of that integer. You learn every one of those 300 digits. The question is whether they are the right 300 digits.

Those “huge” (perhaps parts in 104) uncontrollable phase errors lead to comparable errors in the probability that that 300-digit integer will be one of the ones you’re looking for. So realistic phase errors might change the probability of getting what you’d like from a little over 40% to a little under 40%. They hardly matter!

A nice illustration of how quantum and classical programming styles differ is provided by the actual calculation of ax (mod N). Start with a, square it to get a 2 (here I stop writing “(mod N)”—all multiplications are modulo N), square that to get a 4, continuing in this way to get all the powers of the form a 2 j for 0 < j < n. Then to get ax , you simply form the product of all those powers of a 2 j for which xj = 1 in the binary expansion of x. But now there is a parting of the quantum and classical ways.

In a classical computer, the two-state systems used to represent 0 and 1, called Cbits, are cheap and time is precious. If you want to calculate ax for 2 n different values of x, you use n groups of Cbits to make a table of all the n different a 2 j and you look up the various entries going into ax for each value of x, thereby removing the need to recompute those squares each time you turn to a new value of x.

But in a quantum computer, Qbits are precious and time is cheap. The multiplication of the appropriate a 2 j into ax is not applied 2 n different times to an input register in each of the states | x n , but only once, to an input register in the state | φ in which all 2 n possible | x n are superposed. Each a 2 j is used just once. In some terms in the superposition it’s multiplied in, and in others it isn’t, depending on whether the jth bit of x is 1 or 0. After that single conditional multiplication is carried out, you can square a 2 j to get the next power a 2 ( j + 1 ) a 2 ( j + 1 ) and store the result in the same group of Qbits that formerly held a 2 j , at a huge saving in Qbits.

Why factoring 15 is too easy

There is another saving in Qbits to watch out for, because it is misleading. The period r of ax (mod pq) can easily be shown to be a divisor of ( p - 1 ) ( q - 1 ) . So if p − 1 and q − 1 are both powers of 2, as with the primes 3, 5, 17, 257, …, then so is r. But when r is 2 m , then 2 n/r is itself an integer, and measuring the output of the subroutine U FT can, again easily, be shown to give an integral multiple of 2n/r with probability 1, even when 2 n merely exceeds N but not N 2. Therefore factoring N = 15 = ( 2 + 1 ) × ( 4 + 1 ) with a 4-Qbit input register does not provide a serious test of the real Shor algorithm. The smallest number that demonstrates the full subtlety of the procedure is 21, which requires an input register of 9 Qbits, big enough to accommodate (21)2.

PTO.v60.i10.10_1.d2.jpg

Another subtlety, only recently pointed out, 1 reduces that irritating 60% chance of not getting a divisor of r. When N is the product of two distinct primes, one can (again easily) show that r is not only less than N but less than ½N. As a result, besides getting a divisor of r when the measurement yields a y as close as possible to an integral multiple of 2n/r, second, third, and even fourth closest also work. This increase in the number of useful outcomes lowers the probability of failure from 60% to 10%, greatly simplifying the subsequent classical detective work.

Features of Shor’s “factoring” algorithm like those mentioned here are usually buried in the technical details. By exposing them to the light, I hope to have revealed some of the subtlety and charm of that remarkable procedure.

References

  1. 1. E. Gerjuoy, Am. J. Phys. 73, 521 (2005). https://doi.org/10.1119/1.1891170

More about the Authors

N. David Mermin. Cornell University, US .

This Content Appeared In
pt-cover_2007_10.jpeg

Volume 60, Number 10

Related content
/
Article
The scientific enterprise is under attack. Being a physicist means speaking out for it.
/
Article
Clogging can take place whenever a suspension of discrete objects flows through a confined space.
/
Article
A listing of newly published books spanning several genres of the physical sciences.
/
Article
Unusual Arctic fire activity in 2019–21 was driven by, among other factors, earlier snowmelt and varying atmospheric conditions brought about by rising temperatures.
/
Article
This year’s Nobel Prize confirmed the appeal of quantum mysteriousness. And readers couldn’t ignore the impact of international affairs on science.
/
Article
Dive into reads about “quantum steampunk,” the military’s role in oceanography, and a social history of “square” physicists.

Get PT in your inbox

Physics Today - The Week in Physics

The Week in Physics" is likely a reference to the regular updates or summaries of new physics research, such as those found in publications like Physics Today from AIP Publishing or on news aggregators like Phys.org.

Physics Today - Table of Contents
Physics Today - Whitepapers & Webinars
By signing up you agree to allow AIP to send you email newsletters. You further agree to our privacy policy and terms of service.