Quantum Programming Tutorial #3: The V Gate
Hey guys, this is Maads 101, and today I'm going to be showing you something called V gates in Quantum Computing.
Now, a V gate just multiplies a complex number by the coefficient of the one state of a qubit.
Now, what do I mean by a complex number? Well, a complex number, if you're not familiar from math class or wherever else you may have learned that, a complex number is a real number, which is just a number you're probably used to, plus another real number times the <TK of 1, which we'll call I.
Now, the complex numbers we're going to be multiplying as coefficients are going to have a magnitude of one. What do I mean by that? Well, I mean if you think about a complex number as a real number plus another real number times I, the magnitude of a complex number is the square of the first number plus the square of the second real number, that's the coefficient of I, and then you take the square root of all of that.
So, for example, if you had the number one, the magnitude of that is one. If you have the number I, the coefficient for the I component is one, so and the coefficient for the other component is zero, so the magnitude is once again one.
And if you have something that's <TK 2 over 2 + <TK 2 over 2 I, that is also an example of a complex number, which has the magnitude of one.
Now, the set of all complex numbers with a magnitude of one is basically all the points on a unit circle. So, if you think about a unit circle with a circle with a radius of one, as you go around the circle, anywhere on the circle can be represented by an angle, and the distance to that point on the circle is going to be one.
So, the magnitude is one, and we can think about the Y-axis more like the I-axis and the X-axis as the real axis. The component for the Y value will be I sin Theta, where Theta is the angle, and the X component will be cosine Theta, where Theta, once again, is the angle.
So, these complex numbers are actually very useful, and I'm going to be showing you why here. I'm not going to be proving it, but we have a video on YouTube already where we do prove it if you're familiar with Calculus.
So, the concept which we're going to be using is called Euler's Identity or rather Euler's Formula is the actual name for it. Euler's Identity is the common example of it.
So, here's the actual formula: here's Euler's Formula. It's that e to the I * X, where I * X is the exponent, is equal to cosine X plus I sin X. Of course, this formula only works if cosine and sine take radians, because otherwise, calculus breaks.
So, if you're not familiar with radians, real quick, 2 pi radians is one revolution around a circle, so pi radians is a half revolution or 180°. But that's a little side note.
So, here is Euler's Formula, and here's what it does for us. Now, alone, this is just a cool way to write cosine X plus I sin X in a shorter way because we have this guy here, which is clearly shorter.
So, why is that useful? Well, here I'm actually doing a mini proof. It's not a real proof, but if you recall the exponential property where e to the a * e to the b is equal to e to the a + b, which is just a property of exponents, then you can use this to prove that e to the i * X and that times e to the i * y is equal to e to the i * (X + y).
So, when you multiply e to the i * X by e to the i * y, you get a total rotation of X + y radians.
So, as you keep multiplying on more and more e to the i * something, you're actually just continually rotating around this complex number. And when it does half a revolution, it'll be minus one. When it does a whole revolution, it'll be back to one. When it does a quarter of a revolution, it'll be I.
So, this is pretty useful because, like I said, a V gate actually will multiply a complex number with a magnitude of one, and it'll multiply that by the coefficient of the one state of a qubit.
So, now really quickly, I'm just going to write out what the V function does so you get an idea of what it will do to a qubit.
So, let's say we have a qubit, and we'll call it X, right? And let's say – and this isn't real code, I'm just writing this out – x = a * 1 + b * 0. This is our qubit state, and remember the magnitude of this squared plus the magnitude of this square has got to equal one. But that's a side note.
And of course, the magnitude of a complex number we've just discussed is the square root of this square plus the square root of this, or the square root of this squared plus this squared.
For all these things, which give you a point on the unit circle, like we said, the magnitude will be one. So, multiplying by this doesn't change the magnitude, so it doesn't break our qubit state by making something not have the magnitude of one.
But anyway, let's say this is our X state. Then what V of X will do – let's say we call it V Theta of X – that'll yield X being equal to a times e to the I Theta * 1 plus b * 0.
And I'll just get rid of that times because that might be misleading. But basically, so what we're doing is when you use the V gate, it's just adding this little part of the coefficient to the one component.
And so, I'm going to just go ahead and fire up QCL and give you an example of how we might rotate a qubit. So, first let me declare a Quantum register like I discussed in the last video, and we'll call it X.
And right now, if you recall, X is all in the zero state. Since we said the V gate rotates the one state, the zero state shouldn't change, and what's actually happening is, you know, it'll rotate the one state, but the one state is zero, so the rotation doesn't matter.
So, I'm going to go ahead and rotate this, and I'll use pi/2 radians, and I'll do it to X. You can see clearly X has not changed.
Now, I'm going to go ahead and set X to be one by using a NOT gate. So, the NOT gate, like we said, swaps the two coefficients and that would be completely one.
Now, here we go. I'm going to go ahead and apply this pi/2 V gate, and the up arrow doesn't work because I don't have read line support.
So, now I'm going to rotate the X again, except this time it's all the one component, and what we can expect to see is we're actually going to get to see a was already one because that was the coefficient to the one component.
We're going to expect to see e to the I pi/2 times the one state. And what's e to the i pi/2? Well, pi/2 is 1/4 of the way around the circle. 1/4 of the way around the circle is facing completely up, since we start pointing to the right.
And the up direction we've declared to be I because it's I sin Theta right here. So, what we're going to see actually is the one component's coefficient will now be I, and as you can see, it is I * the one state.
And if I rotate it by pi/2 again, just to show you, it should now be negative one because now it's going to be facing all the way to the left, and that's negative one on the X direction.
And, as you can see, it actually is negative one.
So, now I'm going to rotate it by pi again, and that'll bring it back all the way around to one because you can see we've done a full revolution now.
So, what we've got here is a way to rotate or change something called the phase of a coefficient. The reason it's called the phase, I won't really get into that in this video, but what you should note is it doesn't actually change the probability of reading off a one.
The coefficient still has a magnitude that's the same as it was before; it's just been rotated around this complex plane.
So, let's say I do a Hadamard of X real quick. And now, oops, because it was a one already, I'm going to NOT X and then take a Hadamard.
So, it's just an equal playing field to begin with. So, here we've got (1/sqrt(2)) * the zero state plus (1/sqrt(2)) * the one state.
And now if I apply a V, and I will do pi/2 again because I like that, we should now see this time I * 1. And as you can see, the I is now there.
So, we've just been rotating around the one coefficient, but these coefficients still have the same probability. It's just this one is facing a different way.
So, that's kind of a hard thing to see, but we already saw it in the last video with the Hadamard gate. It's just that when something is negative instead of positive, that means it's been rotated around the 180°.
So, it still looks like a real number. In fact, it is a real number, but it's actually just a real number that's been rotated around the complex axis.
And so this is something you're going to want to start rolling over in your head, the idea of getting comfortable with e to the I Theta being this kind of rotation.
If you're familiar with calculus but you haven't seen Euler's Formula before, you can check out our proof on YouTube.
And if you are familiar with Euler's Formula and you don't know calculus and you don't understand it, feel free to leave a comment, and I'll try to explain it better because it's pretty difficult to get a sense of where our audience is with this.
I mean, I want to try to make this video series as accessible as possible, and part of that includes not using a ton of calculus in our videos just because a lot of people don't want to see calculus, and they still want to be able to do this kind of stuff, which I completely understand.
But, anyway, if you don't have any intention of learning calculus or anything like that, all you really need to know is that we use this I thing, this rotation idea with E, and it all happens to work out, and it's pretty significant for quantum programming.
But if you just remember these rules, you don't actually have to understand deeply the math behind them; you just have to know how they work.
But, anyway, thanks for watching Maads 101. Like I said, please leave any questions if you have any, subscribe and goodbye.