r/askscience • • Mar 28 '21

Computing How exactly do quantum computers simulate molecular/particle interactions better than classical computers?

I’m struggling to understand why quantum computers can simulate nature better than classical computers.

2.5k Upvotes

134 comments sorted by

View all comments

Show parent comments

126

u/GroundStateGecko Mar 28 '21 edited Mar 28 '21

Shor's algorithm is quite more "indirect". I'll try to give an explanation here, but the level of explain-like-I'm-five-ness will be significantly higher. So this comment will only give you a feeling and please know that this is not by any means rigorous.

In the following formulas, you can assume all numbers are integers.

Shor's algorithm is to find factors for a number. If we want to find the factor for the number B, we happen to prove that there must exist a relationship:

Ap = m * B + 1

where we just randomly pick some number A (without some trivial scenario), and we can eventually find a power P, that the remainder after divided by B is 1.

We now just assume we have found the power P for an A we picked. We can write:

(Ap/2 + 1)(Ap/2 - 1) = m * B

(It's the same thing, just wrote differently. You can multiply this back to the formula above.)

For example, if we want to find the factor of 85, we randomly pick a number 11, and try multiple power P, until we find one that satisfies Ap = m * B + 1:

112 = 1 * 85 + 36

113 = 15 * 85 + 56

114 = 172 * 85 + 21

115 = 1894 * 85 + 61

116 = 20841 * 85 + 76

117 = 229260 * 85 + 71

118 = 2521869 * 85 + 16

119 = 27740561 * 85 + 6

1110 = 305146171 * 85 + 66

1111 = 3356607889 * 85 + 46

1112 = 36922686784 * 85 + 81

1113 = 406149554634 * 85 + 41

1114 = 4467645100979 * 85 + 26

1115 = 49144096110772 * 85 + 31

1116 = 540585057218496 * 85 + 1

Got it!

Now, we wrote:

(118+1)(118-1) = 540585057218496 * 85

which is

214358882*214358880 = 540585057218496 * 85

Now, remember, we want to find C * D, so that C * D = 85.

So we wrote

214358882*214358880 = 540585057218496 * (C * D)

Now, as the left and the right are the same, they MUST share the same factors.

So if neither 214358882 itself nor 214358880 itself is a multiple of 85, it must satisfy:

214358882 = C * something

214358880 = D * something

(or vise versa)

we now know:

85 = C * something

214358882 = C * something

So 85 and 214358882 share factor.

Also 85 and 214358880 share factor.

There is a fast algorithm that is specifically used for finding common factors, called Euclidean algorithm. Which you can even do it by hand for 85 and 214358882 / 214358880.

214358882 = 2521869 * 85 + 17

And 17 is a prime number, so 85 has a factor 17.

214358880 = 2521869 * 85 + 15

85 = 5 * 15 + 10

15 = 1 * 10 + 5

And 5 is a prime number, so 85 has a factor 5.

So we got it! 85 = 5*17

Now, why do we go through this hell?

(Continue on the second part, as Reddit have a 10000 character limit)

123

u/GroundStateGecko Mar 28 '21 edited Mar 28 '21

(This is the second part, read the first part first)

Now, why do we go through this hell?

Indeed, using a classical computer, this algorithm is definitely not faster than just trying to divide 85 by prime numbers. The main problem is to find a p, so that we have:

Ap = m * B + 1

We now need another fact:

If Ap = m * B + 1, and we pick any number q:

Aq = n * B + k

We multiply those two, you will always get:

Aq * Ap = Ap+q = something * B + k

(you can multiply (m * B + 1)*(n * B + k) yourself to get the something term)

Also:

Aq * Ap * Ap = A2p+q = something * B + k

Aq * Ap * Ap * Ap = A3p+q = something * B + k

.....

You can derive it yourself.

Now we test it with our case:

Our p is 16, we randomly pick q to be 8.

You can test:

118 = 2521869 * 85 + 16

118+16 = [A long number] * 85 + 16

118+16×2 = [A much longer number] * 85 + 16

118+16×3 = [A much much longer number] * 85 + 16

The remainder is always 16.

This satisfies for ANY q:

Like when q is 5:

115 = 1894 * 85 + 61

115+16 = [A long number] * 85 + 61

115+16×2 = [A much longer number] * 85 + 61

115+16×3 = [A much much longer number] * 85 + 61

The remainder is always 61.

So, here is the most important message, this sequence has a period of p. If we find the period (frequency), we find our factors.

The answer to how do we find a period is almost always Fourier transform.

It's kinda like when you hear a sound, the sound signal is very very complicated if you look at the position-time diagram (see this image). But after Fourier transform, you can immediately see it's just the superposition of three sine waves.

Now when you hear a song, you immediately notice that's an A-minus, not because you can calculate really fast, but because there are hair cells, that will resonances with different frequencies (Wikipedia), only the hair cell that has the right frequency will vibrate strongly, forced vibration to the other cells will cancel out as multiple periods of the sound passes through.

In a strikingly accurate way, your ear is a Fourier transform computer!

This finding-period part is where the quantum part comes in.

Now we can do a very similar thing with a quantum computer to crack passwords.

As we said before,

118 , 118+16, 118+16×2,118+16×3 all satisfies [A much much longer number] * 85 + 16

115 , 115+16, 115+16×2,115+16×3 all satisfies [A much much longer number] * 85 + 61

So we can somehow craft a system, which is the superposition of the states including the power and the remainder:

|8, 16> + |8+16, 16> + |8+16*2, 16> + |8+16*3, 16> + ...

|5, 61> + |5+16, 61> + |5+16*2, 61> + |5+16*3, 61> + ...

All this sequence will have a period 16, which is our p.

So this sequence will resonance only with something that also has a period 16 (or the multiple of it)

So, we can somehow build a "quantum ear", called QFT (quantum Fourier transform), so that only the "quantum hair cell" that has a period 16 will vibrate strongly, and the other will stay still.

Why do we need to do this? As I said in the original comment "you can only get ONE answer from the superposition of 2N states." So we must do something, to let the correct answer "pop out".

By constructing the "quantum ear", only the period-16 "hair cell" vibrates, so it has the largest amplitude. If we do a measurement, it's highly likely we will find the period-16 "hair cell" (the wave function will collapse to period-16), instead of any other number.

Now we can find our p (it's 16) with one measurement (one try)!

And with some simple Euclidean algorithm. We can crack the Internet!

(Actually, not all encryption is based on prime factors. There are things like Elliptic-curve Diffie–Hellman that will not be solved by Shor's algorithm and a quantum computer. So not all of the Internet will be cracked.) Edit: This sentence is not correct, as pointed out by u/Oye_Beltalowda. Elliptic-curve can be accelerated by Shor's algorithm. Although people have proposed variants to ECDH like SIDH that can resist quantum computer attacks.

17

u/Oye_Beltalowda Mar 28 '21

There are things like Elliptic-curve Diffie–Hellman that will not be solved by Shor's algorithm and a quantum computer.

Wikipedia says otherwise. In fact, it says that elliptic curve cryptography is even easier to break with Shor's algorithm than traditional RSA.

26

u/Harrison_Fjord Mar 28 '21

Wow. I'm reading through this a slowly, and reading through it a couple of times, but thank you so much for this explanation! The connection between FFTs is I think the biggest thing I was missing, I've tried to get explanations of the actual things that are going on when quantum computers are... executed?, but I always got something like "we wrangle these things called qubits, do black magic process that no one explains, and then we get the results. Easy peasy, what don't you understand?'. I never had a grasp on the translation between "quantum qubits are in a set of superpositions" and "we measure that to get results" until now.

Thanks again for going over all this. Your procedural method for explaining it makes it easy to follow and you do a good job of leading me through all the steps involved, not just the beginning and the end.

4

u/SirSilvan96 Mar 28 '21

Your explanation was beautiful!

2

u/atimholt Mar 28 '21

Quick question: I've read Feynman's book QED (though it's been a long time), and I've built up some (tentative) intuition for superpositions/entanglement. If this isn't a purely philosophical question, is it correct to say that a waveform collapse is still entangled with all the “histories” that could have caused it? That is, the “quantum fourier transform” doesn't necessarily collapse to the most likely outcome because it “picked one of the options”—there can still be a superposition of every Feynman diagram that leads to that outcome.

I figure it has to be this way for time-reversibility to make any sense. Aside from the massive low-entropy well that is the big bang, the past has aspects of unknowability that are the same as those of the future.

2

u/[deleted] Mar 28 '21 edited Mar 29 '21

[removed] — view removed comment

1

u/[deleted] Mar 29 '21

So you just make sure that you encrypt with an odd P and this doesn't work?

1

u/dack42 Mar 29 '21

I don't think shor's algorithm would help crack passwords. Those are normally stored as hashes - not something that involves primes or factoring.

3

u/[deleted] Mar 28 '21

Thanks for taking the time to write this up. great explanation