# Implementing a quatum operator with Pennylane

I have an ADD operator. Its action is look lie this:
… ADD|L-1> = ADD|L> and finally ADD|L> = |000…000>. As you can see, ADD is like ladder operator. I want to implement this operator with Pennylane. how can i do it? I want some hints from you.

I don’t know how you would implement this. Maybe our demo on Basic arithmetic with the quantum Fourier transform (QFT) can help you.

Give it a try and let us know if you run into any specific issues.

Many thanks @CatalinaAlbornoz. The link was very useful. I could implement it.

I think this is a interesting exercise so I’d like to give it a try.
Thinking about a two bit system, |00> -> |01>, |01> -> |10> etc,
that transform can be done by a matrix

\mathrm{ADD1} =: \begin{bmatrix} 0& 0& 0& 1\\ 1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\\ \end{bmatrix}

Looks familiar? Recall the backwards CNOT is

\mathrm{CNOT}_{ba}=: \begin{bmatrix} 1& 0& 0& 0\\ 0& 0& 0& 1\\ 0& 0& 1& 0\\ 0& 1& 0& 0\\ \end{bmatrix}

Try divide ADD1 by backwards CNOT gives

\begin{bmatrix} 0& 1& 0& 0\\ 1& 0& 0& 0\\ 0& 0& 0& 1\\ 0& 0& 1& 0\\ \end{bmatrix}

and by knowing the definition of tensor product, it can be written as

\begin{bmatrix} 1 & 0\\ 0 & 1\\ \end{bmatrix} \otimes \begin{bmatrix} 0 & 1\\ 1 & 0\\ \end{bmatrix} = I \otimes X

which means it is easy to discover that for the two bit system \mathrm{ADD1} = (I \otimes X)\,\mathrm{CNOT}_{ba}

The circuit would be like this (note that 0 is the most significant bit)

For a 3-bit system, we can just reference the above circuit and build (again, 0 is the most significant bit)

Be aware that start with more bits you need to figure out a way to build multiple input controlled NOT gate, (and qml.MultiControlledX already does that), but from thing point now on the rules should be apparent to you, it can be generalized to that a bit should be flipped if all the bits after it are turned on, and the least significant bit is always flipped.

It’s great to see that you found a solution @sassan_moradi . Feel free to post it here so everyone can see different solutions!