I have an ADD operator. Its action is look lie this:

ADD|000…000> = |000…001> (or ADD|0> = |1>)

ADD|000…001> = |000…010> (or ADD|1> = |2>)

ADD|000…010> = |000…011> (or ADD|2> = |3>)

… 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.

Hi @sassan_moradi ,

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

Looks familiar? Recall the backwards CNOT is

Try divide ADD1 by backwards CNOT gives

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

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!

By the way @LdBeth, I think your matrix ADD1 should be

\left(\begin{array}{cc} 0 & 0 & 0 & 1 \\ 1& 0 & 0 &0 \\ 0 & 1& 0 &0 \\ 0 & 0 & 1& 0 \end{array}\right)

Thank you for pointing that out, it has been fixed now.

No problem, thank you for posting the solution @LdBeth !