what is going on everybody and welcome
to the Future welcome to part three of
the quantum computer programming
tutorials in this tutorial we're going
to be getting into our very first
algorithm which is the Deutsch Yosa
algorithm now this algorithm is
relatively pointless in what its actual
outcome is but instead what it what it's
good for is to two things really one is
it really is an algorithm that is
provably faster than a quantum computer
in terms of how many like say cycles
through the circuit are required to get
the answer but also the reason it's it's
more so it's not just the speed it's why
is it faster so this is the first time
you should get a real idea and feeling
for how is this working and then open
why is this working because the reason
why it works is the circuit is able to
consider all of the possible inputs that
could have come into the circuit and it
can immediately respond with the with
the output so and the output is not
output based on input its output based
on the nature of the circuit and so
that's what's cool about this algorithm
it's not the app it's not the actual
result of the algorithm and I think that
point gets lost on a lot of people at
least when I'm looking around at
explanations and stuff of the dojos
algorithm as well as some of the others
like the Bernstein Voss Ronnie and even
Shor's algorithm although we we I think
most people will understand oh it breaks
encryption cool ok but the Deutsch Yosa
algorithm is the inspiration behind
Bernstein Baz Ronnie Shor's algorithm
and I'm sure many others because it
shows and this was kind of the first one
that shows you could do this stuff like
this is these are things that you just
can't do with a regular clap classical
circuit so let me just formulate really
quickly I don't want to spend too much
time explaining some problem but it
would probably be useful to explain the
problem so with the the Deutsch Yosa
algorithm you've got a function right so
the function is your black box and let's
say you're gonna pass a two-bit string
to this box and the
question that we want to answer is is
this black box going to output a
constant output or will the output be a
balanced output so will this box always
output all zeros or all ones or will it
output zeros and ones in a balanced
manner so an even number of zeros and
ones so with a classical circuit the
only way that you could find this out is
that minimum two you would need two
outputs from the machine so if we got a
two-bit string it's going to take at
least two queries because on the second
query you could find that oh there's a
let's say on the first query the result
is 0 0 the second query you got a 0 1
right and when I say query I mean like
pass through the circuit so to find out
if a circuit is balanced or constant on
a two-bit string it's going to take at
least two passes as we increase the
number of bits in the string that we
want to pass through this function it's
going to take longer and longer and
longer for a classical circuit to be
able to make this determination a
quantum circuit on the other hand can
make this determination regardless of
how long that bit string is in one pass
and this is what shows the power of
quantum circuits and again the problem
itself is not useful it's just this is
the most basic representation that we
can come up with that shows the
attribute that quantum circuits have
that classic circuits do not have so
don't get hung up on the problem get
hung up on why this solves this problem
so with that out of the way let's go
ahead and get into it
mmm so to begin this all rests on a term
that I'm gonna coin as Hadamard
sandwiches so again like I said in part
1 I'm not a quantum physics expert okay
I'm not even a physics expert I'm really
not an expert of anything so but
remember you're just watching the
dude on YouTube so so I'm gonna use
words here that I feel describe what's
going on but they're probably the wrong
word so so yeah just just bear with me
there if you're like an actual you know
PhD person feel free to correct me and
tell me that the word is correct and if
I've somehow stolen Hadamard sandwiches
I apologize I'm pretty confident I've
never seen that anywhere but that's what
it looks like it's just had margins on
all the sides
so you're just squishing something
between Hadamard x' it's it's a Hadamard
sandwich so anyway if there's an
official term for it let me know
so to begin well we're probably going to
need some some of our initial imports
huh
I don't really want to type this out
everyone should have these so I'm not
gonna do that again it's a waste of time
so we will have a kiss Kate will hover I
did check this by the way I'm sure by
the time this video is coming out after
part two but I'm sure people will
correct me but I don't know which one is
the the new one but this happens all the
time in libraries I'm gonna go with the
shorter one but you can import both of
these from the shorter one so cool so
yeah all this stuff is stuff you've seen
so the first thing I want to do is show
you this Hadamard sandwich on what I'm
also going to call uncertain qubits and
when I say an uncertain qubit this is a
qubit that will collapse not always to
the same to the same answer so to begin
let's say we've got a circuit and that's
going to be a quantum circuit and we'll
give it we'll make it a two two and two
so two qubits two classical bits and
then we'll say rotation on the Y and
we'll go with math dot pi divided by
four on cubed zero and then we're just
going to do the same thing to cube it at
index one so that's our two qubits are
done and then what we're gonna say is
I'm going to call this a Ridge State vac
and that's going to be equal to Q dot X
cute and we're gonna execute the circuit
on the back end
of this state vex simulator so just
remember you need if you want to get the
state vectors you have to do it before
you actually take the measurement
otherwise the circuit will have
collapsed and you the state vector won't
work but I mean do it work
it just won't give you what you hoped so
state vex em and then we're gonna say
dot result dot get state vector hmm so
now we have the actual state Veck and
then we will see dot measure and then
we're just gonna measure both qubits to
both classical bits and then we'll do a
co op o Q dot quantum circuit IC Q
quantum circuit did I screw it hopefully
I didn't get anything else up get state
vector why not
results oh we didn't call result
certainly in the morning coffee's still
setting in cool okay so we have our
rotation or measurements great so the
first thing I would want to do is let's
plot Blanc multi vector and then we will
do the original state Veck cool run that
alright so that's how the original state
vector appears to us before we've done
anything for any Hadamard z-- or
anything so it's just a quantum circuit
we do a couple rotations on the Y that's
what it looks like okay so now let's do
orig counts equals Q dot execute and we
will execute that circuit we're gonna
say back end back end equals the chasm
underscore sim shots will be 1024 I'm
gonna make this Pepe and then we will do
dot results get underscore counts and
then we will plot histo gram or ridge
a ridge underscore counts and then
legend 2 equals probably don't even need
a legend here honestly but I'll put it
in so mmm this is our distribution so
it's going to be important because first
we're going to whoops trying to get an
above here first what we want to do is
uncertain cubits let's say so this is
for uncertain cubits just naturally this
is what they look like now what we're
gonna do is we're gonna do uncertain
cubits Hadamard x' at front ok so all
we're gonna do is we're going to take
this copy paste and now we're just going
to add to how to Margate stew the to the
beginning so how to Mardon 0 Hadamard on
1 that's our circuit cool we don't
actually want to say a ridge state
vector that should be reserved for the
original and then we're gonna do the
counts as well so we've got a state Veck
draw I guess well well first we'll do
we'll do everything in the same order I
don't want to make it confusing as I'm
scrolling through here a ridge state
Veck
urn actually state vector did we not run
no we didn't run this I think I just ran
it before I made the change so as you
can see the the single Hadamard actually
made kind of a significant difference
right so there's that and then let's go
ahead and plot so like ok that's how
impacted this the actual block
multi-vector but how does it impact the
actual distribution so let's do this so
like how do these actually collapse what
would it actually end up looking like so
counts and then I'll just paste counts
so if we look at this and in fact let me
just just to make it easy y'all get rid
of this after we're done but so this was
the original it looks as though probably
0 1 and 1 0 are unchanged but really
what happened is every
just flipped right so now zero zero is
as frequent as one one was these are
stay the same because they've flipped
and then one one is you know flipped
basically with zero zero from the
original so applying the Hadamard did
something kind of funky here because
instead of you know they were already
uncertain so then you applied the
Hadamard and then it flips them around
right and also changed that multi-vector
pretty significantly but that's a head
of art in front now what about the let's
say a Hadamard sandwich on uncertain
qubits and all we're gonna do is take
this paste and now we're going to just
gonna wrap Hadamard x' on the other side
so now you can see Hadamard Hadamard
Hadamard header mug so it's just
squishing in these qubits around
Hadamard gates
hence the head of martin sandwich so now
let's take this let's look at the state
vector that this produces and let's go
back up to the original just because I
think scrolling around is kind of
confusing and in fact I'm going to I'm
just going to delete this because I
don't want to look at it and come down
here I just want that to be confusing
now when we look at these isn't that
interesting so this is the Hadamard
sandwich this is your original no
Hadamard now this is on again uncertain
qubits that starts to look like wow it's
almost the same it's just kind of
flipped right but doesn't it look like
if you were to guess where these are
gonna collapse would you not guess that
like if I was the guess I would have
guessed that this whole like flipped
output would be what happens actually at
this point right like because there
these are they look like they're
opposite alright so I would expect that
kind of flip there but instead spoil
alert
boiler alerts here's the Hadamard
sandwich distribution right counts
regular counts just the circuit we just
ran that's what that looks like now
let's go up to our original distribution
I'm just gonna copy it scroll down here
had a mart sandwich on top original on
bottom it turns out there are the same
they give us the exact same output on
the distribution but so what happened
though what happened for us is even
though the output is the same so the
circuit outputs the same what what we
got it was the possibility to look at
this point with these qubits here we
could have done something interesting at
this stage in the circuit we could have
had another qubit that does something
else that works off of this state here
before we get to the final Hadamard x'
and then take our measurements so so if
we had one more qubit we can do some
something based on this superposition
state that is basically querying all of
the possibilities of input into the
circuit without impacting the actual
output which is very interesting so so
that's with an uncertain uncertain
qubits the next question is how does
this look in front of certain qubits so
imagine let's go with I guess we just do
the same thing and then we'll do maybe a
knot or something so that was uncertain
qubits so let's just come down here and
let's say certain qubits and just for
the record all of this that I'm showing
is completely applicable to the dojos
algorithm as well as all of the other
fancy ones that everyone
ever heard of its that it's this is the
concept that is important so I'm not
just wasting your time I promise so now
let's look at Hadamard let's look at
certain qubits again I don't know if
that's the right word I just that's
that's what I'm thinking of when I look
at these I'm like okay this is always
going to collapse and such such a way so
rotation on Y is uncertain but we could
either do nothing or just to do
something let's just do a not gate okay
so so we'll just say see X and then see
X here so that's our what we've got now
and then we'll just do we'll just take
this multi or the state vector here so
now what we do is let's apply a head of
mard
on so Hadamard in front of certain
qubits whoops and then I'm gonna make
some space so we're not constantly
dealing on the bottom here so now what
we're gonna say is C dot H zero and then
we will do at the one draw we don't want
to call this original state vector
oh I kind of want to do the I'd like to
do the original counts as well let's go
ahead and let's get that done as well so
let me let me just pop that in here so
just be four bottom will give us that so
those they're the I guess we'll do the
vector and then we'll do this should
give it to us let me just I'm gonna make
sure I haven't made some sort of silly
error here we should just get one though
right so so we always get a one one okay
so then we throw a Hadamard in front of
everything and then change this to be
state vector so so we'll run this
circuit cool so now there's Hadamard in
front and now we've got this sort of
situation where it's like just fully
pointing towards that X then what we're
gonna do is let's look at the counts now
I mean you should you should kind of
know we what what to expect so again
like I've tried I've tried to kind of do
this every time but
applying a Hadamard to let's say I'm not
gate
what do you which should be the
distribution output here so let's see
orig counts just counts flips cool so
it's what you hopefully expected right
is just a perfect distribution of all
the possibilities here so again don't
forget this is a point where I want to
stress that in order to get that
distribution we had to take many shots
right we had in order to know that this
circuit like if we couldn't look into
this circuit in order to know what the
distribution this circuit had like in
order to know that characteristic we had
to take a lot of shots so if I just had
one shot here we get one one type of
result this is not informative to us as
to the characteristic of the circuit
okay so it just happens to be the case
that when we take many shots because of
the superposition state here we get a
distribution but what we're building up
to here is the ability to know a little
bit about what the output should be
based on this Hadamard sandwich so okay
back to what we're doing so we've got
Hadamard Xin front right now let's do a
Hadamard sammich so had a mode Hadamard
sandwich sandwich certain qubits so we
paste that in and then Hadamard 0 1
Hadamard 0 1 draw the circuit looks
correct nice little sandwich going on
there and then we will do our multi
vector okay now that is the opposite of
this and recall that is also exactly
what happened here it was the opposite
and if I'm being honest I still don't
totally understand how we're getting a
collapse to me this should have
collapsed mostly to 1 1
but it doesn't but coming down here this
should collapse okay right
oh it's flipped so this should collapse
to 0-0 every time right look if this
doesn't I quit because I have to work in
some I have to work at least with some
rules okay I understand some of these
things are kind of funky but come on
without rules what are we so savages so
oh we already plotted the multi Vedra
what I want is the accounts so we come
down here then we do the counts now this
is our Hadamard sandwich on certain
qubits and what we do get in this case
is actually flipped values okay which is
still pretty interesting behavior and
it's important to take note that a
certain qubit will respond in this way
and an uncertain qubit will respond this
way so what does that tell you so
getting back to our Deutsch Yosa
algorithm this tells me we can do
something interesting here we can take
probably any n number of bits use a
Hadamard sandwich to determine is our
algorithm
variable output or not now if we just
have what we have here without
understanding the inputs coming in we
would we might still see things getting
flipped but this is the very this is the
basis right away 0 0 for a constant 1 1
for balance so keep that in mind
you've just been shown something amazing
so now now that we've done that what I
want to do is propose to you the
the rest of the Deutsch iou's algorithm
because I think a lot of this gets lost
when people just go straight to the
Deutsch iou's algorithm now everything
I've shown is still applicable and it's
part of the Deutsch chiozza algorithm
but usually just get it coated all the
way through and that's not the point
where people focus on the black box
that's not the point that's not what's
cool like that's it then that has
nothing to do with it so okay so now
let's go ahead and define our black box
or actually let's say a balanced black
box it's going to take in a circuit and
it's going to output a circuit so we're
gonna make our little black box function
for balanced and constant so so let's go
so for constant what I'm going to do is
make this four in the way that everybody
else has presented the Deutsch eo2
algorithm so we're the black box is this
balanced either balanced or constant and
the way everyone does is with the
controlled-not
so i'm going to use it with a controlled
not but understand there's so many other
things that we can do here besides just
the one way that the Deutsch shows the
algorithm is formulated and again this
is why the Deutsch oza algorithm is is
the basis for all these other algorithms
it's not like people actually care to
determine whether a quantum circuit is
balanced or constant it's that we can
determine that all in one pass because
that one pass can consider all of the
possibilities so anyway we are going to
use what everyone uses this way if you
are confused I thought about not doing
the typical formulation but I feel like
with a topic like this at least for me
I've been I've just been scouring the
web for just all the resources I can
find and then I'm looking to compare
things and just see like see how one
person explains something how another
person explains something like in the
learning process it's useful if everyone
is at least using sort of the same
so I'm going to use the same things but
just know that the possibilities here
really truly are endless you don't
you're not constrained to this this
formulation so anyway we're going to do
a controlled not from the zeroeth to the
at index to which you'll see in a moment
we're gonna add another qubit here so
we're gonna do this entanglement between
qubit zero qubit 1 and they're just
going to entangle with this qubit at
index 2 then we're gonna say a constant
constant black box it's going to take a
circuit oh and this needs to return a
circuit so we'll just we'll just define
our circuit and then when we're ready
for this black box we'll just C equals C
basically or C equals black box C anyway
you'll see point into it okay so the
constant black box the easiest constant
black box is to just return C we don't
got to do anything so expert tutorials
okay so now what we're going to do is we
can define our circuit now so we're
gonna say C equals quantum circuit and
again we're gonna have three qubits to
classical bits because we don't actually
care about qubit number well qubit at
index two that's not it's not relevant
to us because instead what we're
actually curious about is what are the
outputs to qubit one and two so anyway
so what we're gonna say now is C equals
balanced balanced black box C so now if
we did C draw see that draw
quantum Oh keep forgetting this stupid
cute Boop look I'm pretty sure I spelled
that right okay so as you can see we
started it we can apply this black box
however however we feel so now what
we're gonna do is encase this in the
Hadamard sandwich so we're going to say
basically this copy-paste
and then we're going to apply Hadamard
gates to basically everything so we're
gonna say C dot H zero one two and then
you you you can do this and in fact I've
seen people do this it's kind of funny
but you don't actually need the Hadamard
gate here right which will make more
sense later on you can put it there for
symmetry if you really want but it's
unnecessary so now what we have is the
following circuit so things are starting
to get kind of jumbled up so one option
you have when this is happening
especially if you're just trying to make
things clears you can use this barrier
so for example you could say see barrier
and it will create this little line for
us so just a quick example here run that
and so now you can see it's a little
easier to read right it looks a little
more linear as far as what's happening
at this point you could Hadamard over
here like it's really possible it's fine
but it looks it's hard for us to read it
if everything's not in line so as far as
I can tell from looking around the
barrier is used to stop the kiss kit
optimizer like in the back end that
optimizes your actual input circuit
before it goes to the quantum machine
that will optimize your circuit so if
you're doing something stupid and
wasteful I it appears to me that they
can fix that with this optimizer but so
you can use the barrier to stop that
from happening so now the optimizer will
optimize this section this section in
this section again this is my
understanding I could be wrong
but in terms of how I see barrier
actually being used it's just
purely for aesthetics it's purely for
making these easier to read maybe as I
get deeper I'll find a scenario where I
really need to stop the optimizer from
doing something but I haven't seen it
yet so anyway like I say I'm a noob so
maybe I'm missing it okay so so there's
our nice beautiful Hadamard sandwich and
I think probably I think what I'd like
to show before so one of the things that
gets added again to to make this
uncertain is you can add what you'll
typically see is a cx4 gate too so a not
gate on quantum gate too but before we
just throw that in there I want to talk
about what that does right because again
it gets kind of missed and in fact
before exactly why we want to use this
gate so again here's our little black
box if you want to be abundantly clear
you can put like two barriers or
something but I think this is fine so
what happens when you have a not gate
and then a Hadamard gate what goes on
there so really quickly again I'm just
trying not to gloss over anything at all
here cuz I think I think that that from
what I've seen at least when I was going
through tutorials I'm like trying to
figure out okay why is every single gate
why are they here
what are they doing and there's really
not explanations for this and this it
just it reminds me so much of why I
started doing YouTube tutorials and in
general like I'm just in Python because
I was like no you have to explain
everything you can't just skip things
but so anyway what happens like let's
see what happens we have a not gate
followed by a Hadamard gate whoops so
let me just I just want to steal our
state back code stay back here down here
not that you don't have to follow along
on this step if you don't want you can
just look at it I'm just
to show you this is all in the
text-based version too so don't worry
about it so so what was the original
Hadamard gate right it's this positive x
value right but if we do a naught then a
Hadamard it's a negative x value what if
what if we start with a Hadamard and
then we not the Hadamard what happens
not what we expected really so now what
we're gonna do is I'm gonna ask a
question that I'm hopefully going to
remember to answer by the end and that
is is there another way to achieve going
from here to here that does not involve
what appears to be the requirement that
you first have a not than a Hadamard is
there another way that we could do this
right here think about that because
again the Deutsch iou's algorithm is not
specific to doing things in some
perfectly exact way instead it's there
to show you that this this
characteristic is there unlike all of
these quantum algorithms when you use
this notion of superposition so think
about it feel free to pause it and think
about or whatever but at the end I'll
show you the answer to that question
will you go away there you go
I couldn't get it to go away like you
press D by the way to get things to go
away if you want cells to the bottom be
a top a like above okay so now that you
understand what is happening when we add
that not let's go so we've already got
it there actually so we'll add that not
gate I'm trying to think I think we're
actually completed here in terms of
everything we need the only thing that
we need actually
well we're our circuit is basically done
but we're not doing anything with the
circuit right so let's go ahead and
we'll take our measurement again this
Hadamard you can add there
I have even seen people throw another X
here for the purposes of what we're
doing know now if you were gonna maybe
work with qubit to at index to you know
who knows what you might have here but
for the purposes of actually showing the
circuit at work
no you it doesn't have to be symmetrical
even though it's very it is very
tempting to make this a nice perfect
Hannah marred sandwich just I'm just
saying
so now Morgan is seen up measure and
again we're going to measure qubit zero
one and we're going to map that to the
classical bits of zero and one so here's
our circuit and now we can actually
measure these so let's go to counts mmm
pasta so what we get as our response
here is one one so it's not so but this
is what basically what this is informing
us is it's not really like the output to
the circuit instead this one one
corresponds to the nature of the
internals of the circuit or something
it's responding to us the nature of like
the probabilities in this circuit so in
this case this is our balanced output
we're getting once now if you had you
can continue adding as many qubits as
you want so we've got two qubits here
you could have had thirty cubits if you
had a machine that could do it it's
infinite you can have as many as you
wanted you could answer this question of
like what what's the characteristic of
this circuit in terms of is they're
balanced or constant output so
continuing this what if we went with
rather than the balance box what if we
did the constant box so I think we just
called it constant black box
constant yes okay so now we do the
counts
run that again and what we get is zero
zero and again it's important for me I
think to stress this is one one for
every single shot so we took a hundred
or a thousand twenty-four shots but we
could have gotten this answer with one
shot right it's a hundred percent one
one always so given a perfect quantum
machine we would have always gotten this
response of course quantum machines
again have noise so we have to we can't
quite get away with that yet there's no
reason to believe that I know of we
can't reach perfect quantum machines
right but again
fundamentally we can we can query these
quantum circuits one time and understand
what is the variability of this output
that's incredible just one shot through
but it's because of this superposition
and Hadamard sandwich that this can
happen right so that's incredible right
so again what does this all mean and
like where do we go from here it's not
really answering the question of well
it's basically this algorithm does two
things like the Deutsch algorithm is
really the first algorithm that provably
like mathematically can solve this
question even though it's au relatively
useless question it can solve this
question faster than a classical
computer a classical Pierre will really
require at least two passes through the
circuit to answer this question the next
thing and as you increased qubits it
would get even more complicated than
that so so it's faster than a class
provably faster than a classical
computer in terms of like house to the
cycle through the circuit but then also
what's more impressed I'm impressive
that it's faster it's like why is it
faster though and we're like oh because
we can actually query wow we're in
superposition the attributes of this
this circuit and output that instead so
then so then what we can do is clearly
there's more information here right it's
not just as simple as 0 & 1 there's
much more to the story and we can work
with that intra circuit that's what
that's the the real amazing part of all
of this it's not oh we did it in one
shot it's why did we do it in one shot
so with that we're almost done here the
the the last thing I want to show you is
what I asked earlier which was can we I
don't know if I saved it up here I was
hoping to just copy/paste but I don't
think I did
can we mimic let me just take a circuit
real quick can we mimic lil deuce one
one the Deutsch EO is this stuff is
basically over oh well I guess it's not
because I'm going to make a point
but anyway now we're just kind of
screwing around again you don't have to
follow along you can just watch so we
have a quantum circuit we have a c x0 so
it not a Hadamard on 0 we don't really
have to draw but I'll just do it C draw
and then we want a state vector where is
a state vector code you don't I'd really
like you know it'd be awesome
kiss kit devs like C dot draw multi
venture that's what I want in my life
cuz like doing this every time you want
to make the drawing
the victor state facts okay so that was
that way and then if we were to flip the
Hadamard and then not so what if we did
Hadamard then a not because don't forget
as well if we just have a Hadamard what
what did that look like right it's fully
in the X and then if we have C X
Hadamard so this is the order of a knot
Hadamard that we have in our Deutsch oza
algorithm we can see okay it flips it
around right so again if we do and I'm
gonna stop drawing X that way we can do
all this in one run I'm just going to
save boop boop
so again Hadamard all the way and then
if we if we put them not gate after the
Hadamard what happens nothing happens
but what is actually happening when we
go from X to this like negative x what's
going on how how else could we get there
could we get there some other way so
like from here could we get there of
course we can get there remember all the
gates are superposition entanglement and
a rotation so what if we say circuit
rotate on the Y and we're going to
rotate by math.pi on qubit zero can we
get there it turns out we can we can get
there after the Hadamard we could also
get there before the Hadamard so we
could we can throw this rotation on the
y anywhere the heck we want the next
question is does this collapse in the
same way as we would hope and expect now
I could we could do it with just this
circuit but instead what I'm going to do
is let's take well everything we've been
doing up to this point so we're gonna
loop take this now in theory
right this not this is what we're trying
to wonder hey could we change this so
this not as you've already seen if we
put it after the Hadamard it doesn't
work at least in our simple example now
I can prove to you it also isn't going
to work here so for example I'm gonna
comment that out and then we're gonna
move it here so we'll move it after the
Hadamard and then we'll do let's just
take counts here copy come down here I
don't think we need to draw it so again
I'm just gonna run everything
immediately so we get a zero zero on the
balance box and then you might be
thinking well maybe the constant is a
1/1 constant flexbox
it's not we get zero zero across the
board so we've lost our the attribute
that was so cool
and we know we can understand maybe not
the the quantum mechanics in the
background maybe we don't understand
that but because we when we actually
graphed the the multi-vector I don't
know where my option my example win but
when we did you saw it didn't do
anything right you Hadamard it was full
x you did a not it was still full x so
as no surprise this is not working but
what about I'm gonna comment that out
again we're going to say a rotation now
so we're gonna we're going to replace
the original formulation where there's a
not before the Hadamard with a rotation
on the y instead so we're gonna say math
dot pi qubit number two or index two
rather run it
okay constant is a zero zero so i don't
want to rewrite the whole thing probably
could have done it by now though
balanced black box is a 1/1 so now we're
back to the behavior right that we
expected before but again rotation on
why we're doing the same thing with the
multi vectors as before but as we've
also seen we can get that exact same
behavior right and as long as we're
getting it before we take this
measurement we should be fine right so
the question is okay can we take this
rotation on the wire
move it from there and apply it here
where the control decks are controlled
not rather or not how to control not the
not gate did not work so we run this on
the balance box we get a 1 1 again good
that's what we hoped now can we do the
same thing and get it on the constant
black box and get it hopefully a zero
zero we can so I'm gonna leave it here
and just leave you with this that again
you you don't the math might elude you
is to and it eludes me why the not
didn't flip the Hadamard back the other
way right but then I like I said as I'm
just kind of playing with this Deutsch
iou's algorithm I'm like hmm that's
interesting you know because in theory
you you just need to make sure
everything is the same either have a
balanced or a constant you know thing
that happens at this point so as long as
we do our operation before we get to the
C not in theory we should be fine and
then as long as nothing else changes
here before the measurements again you
should be fine or as long as before the
measurements you either have a constant
or a balance so anyway I was playing
with it and I was like well is there
another way that we could get this like
I was curious do we actually have to
have this not gate here like why can't
it be here and then I plotted the multi
vector and I was like oh it just can't
be there and then I was like but that's
weird why doesn't it move the multi
vector and I'm like well what if we do a
rotation like surely that will move it
right and it does and it works at least
on the sim so anyway very interesting so
that's it for now
if you know the proper terminology for a
Hadamard sandwich feel free to let me
know if I've said anything else stupid
feel free to let me know but yeah that's
so cool so hopefully you guys are as
intrigued by all this quantum computer
programming as I am I'm having a really
really good time playing around with all
this stuff this is just super
interesting
and it's really cool to see all it's
like the it's just a complete it's just
totally different you have all these
possibilities and like what we're going
to be able to do with that is very
interesting to me as we move forward so
again while this might not be an as an
algorithm all that interesting it's very
simple so it's easy to understand but
this concept this is the inspiration
behind Bernstein Voss Ronnie which is
basically a way that you can encode a
bit string into your circuit and then
there's the Shor's algorithm which is
the one that you know can factor large
prime numbers so factor for large prime
numbers so anyway in an effect break
break encryption so okay I think that's
all so you thought you were rid of me
but actually I wanted to stress one one
final thing and that's in relation to
why did the knot not work and then the
rotation on the why did work I don't
think I didn't make that totally clear
like it might be like oh why did that
happen there's a reason it happens so so
what I'm going to do is I'm just going
to take this here and real quickly
answer that question so hmm what is a
rotation or what's a not gate right so
so with our Hadamard we've lost it okay
I'll just do it down here
so we're Hadamard goes to here or even
better yet let's say let's do let's just
do nothing and then we'll add a not gate
so so this is our start we initialize to
zero let's say we apply a not gate now
it points to down to one the question
though is how do we get to one right
there there's two ways we could have
applied a rotation to qubit zero to make
our way to one one of the ways is to
rotate along the let's say one of the
ways was we could have rotated along the
y axes to get to one the other way as we
could have rotated along the x axis to
get to one the dot X should give you an
idea of what happened
right but what if we said can what if we
say C dot y 0 we get the same result and
you might think oh I didn't even know
those existed right and you also have a
control Z right because your zeros ette
axis right here so and when we do it a
cz on what otherwise is already pointing
you know if you're trying to rotate
along the axes that you're like
perfectly along nothing happens right so
that's why if you have a Hadamard first
you're you're on the x axis so when you
try to go and do a CX on the x axis you
just kind of like nothing really
happened right but that's why nothing
happened a not gate is actually you're
just rotating along the x that's that's
it so a not gate is a rotate on the X
math dot pi it's so like for example and
then we'll say zero and then we'll just
comment this out right boom and then
BOOM right there's your not gate ok so
that is I just want to make a point that
that's why the not gate doesn't work
after the Hadamard right because the
Hadamard runs us along the x axis so so
there's really when we rotate there's
nothing to rotate on but that leaves us
the opportunity to rotate along the y
axes to get back to where we wanted
hopefully that's a little more clear I
just don't want to leave you guys with
this like notion that there's some sort
of magical reason the not gate just
doesn't work after the atom are no it
it's just we're not we're rotating along
the axes that were perfectly along so it
just there's nothing to rotate so anyway
that's all and thank you to my most
recent awesome human / Channel members
Stephan Bowman Ryan Hallett's Munna
Nasir's a newsie Dhruv Gupta rabo a
gaming in kumaras very glue thank you
all very much for your support and of
course for all of the channel
if you want to join you can collect that
beautiful blue join button next to the
subscribe button I will see you guys in
another video