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

886

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

First, I'd like to demystify something. It's common that people say an N-bit quantum computer can simultaneously exist in a superposition of 2N states, such that it will be able to access 2N answers, thus much faster than classical computers.

This is FALSE. You can only get ONE answer from the superposition of 2N states. ONE measurement will disrupt the whole system so that the superposition (of that property you were measuring) is broken. So an N-bit quantum computer has nothing to do with running 2N calculations at the same time.

Now the real answer to this question:

A tl;dr answer would be: because we can construct certain quantum systems, so that some physical properties of that system happens to be the same as some formula we need. (And that formula is hard to calculate using other stuff, like a classical computer or in our head.)

You can use this exact same explanation to answer "how do classical computers calculate addition faster than human". An adder, built with classical electronic circuits (like this one), are just some physical objects that do "experiments" so that if you flip the switches as your input, the output light bulbs will almost instantaneously illuminate in a way that happens to be the same as how addition works. We then measure the on/off of the light bulbs, and say that this "computer" (consisted of two switches, two logical gates, and two light bulbs) can do addition as fast as the electricity can flow through the wire, like billions of times a second (assuming you have bulbs that can flicker really fast).

We can now put our switch-gate-light bulb thing in a case, and call that thing "a classical computer that can quickly calculate the sum of two one-bit numbers". The switches are input, and (the brightness of) the light bulbs are output.

So what's a fast computer?

It's a physical apparatus, which we have configurations to change as input; and the measurement of some physical property happens to correlate to some formula we need.

Now, the same thing for quantum computers.

I'll use the calculation of a permanent of matrix as an example. A permanent (Wikipedia) of an n*n matrix is a sum of products, each product is consisted by n element, the horizontal indices are 1...n, and the vertical indices are each of the possible permutations for the n indices. So the total number of products in the summation is the factorial of n. Like for 2*2 matrix, for 3*3 matrix, and I generated the permanent for 4*4 and 5*5 matrices. You can see as the matrix grow bigger, it will be exponentially more complicated if we calculate the multiplications one by one (and the optimal complexity on a classical computer is ~O(n×2n)). For a 100*100 matrix, You would need to do ~1032 times calculation to get the result, and that will need ~1000 years on our best classical supercomputers.

However, there happens to be a quantum process, called Boson sampling (Wikipedia), whose physical property happens to satisfy:

[Boson sampling] = |permanent of matrix|2 / S₁! S₂! ... Sn!

We can calculate the "S₁! S₂! ... Sn!" part very quickly (using a classical computer), so we now build a quantum apparatus and measure the [Boson sampling] term for a certain input, we can now get the permanent of matrix very quickly from the above equation.

And we finally put that apparatus in a case, and call this quantum apparatus "a quantum computer that can quickly calculate the permanent of matrix". Just like our switch-gate-light bulb thing.

(There are caveats that I glossed over for simplicity. Read this like an Explain-like-I'm-five-answer. Comments are welcome.)

120

u/Harrison_Fjord Mar 28 '21

This is a cool explanation, thanks. I've never heard this explanation of a quantum computer before (or more likely, I never heard it distilled into simple enough terms for me to understand). Is there a list of these quantum processes that 'happen to be' equivalent to real-world problems we're trying to solve? My main curiosity is what natural quantum process is used for Shor's algorithm, which is the only quantum algorithm I'm tangentially familiar with.

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.

4

u/SirSilvan96 Mar 28 '21

Your explanation was beautiful!