DEV Community

Cover image for Universal Gates making using Reversible Computing in QISKIT
Md. Zubair
Md. Zubair

Posted on

Universal Gates making using Reversible Computing in QISKIT

There are different types of classical gates like AND, OR , NOT, NOR, NAND etc. If we think about it classically , Only the NOT gate is reversible and rests are not.
By reversible I meant we can get the input value by looking at the value of output. If we look at the truth table of NOT gate,

Image description

Here you can infer the input or the output value by looking at the other .

But this is not the case with other gates. To understand it clearly , let's take OR gate truth table,

Image description

Here , suppose by using or gate on 2 unknown bits you got the output 1, now can you infer from here the input values of 2 bits ? No you can't . It is because there can be 3 possibilites like 01,10,11.

But we can do this in Quantum Computer. Quantum Computer is reversible according to the laws of physics . Quantum Gates U are invertible (U^-1 = U^t) and hence quantum circuit (without measurement) are invertible . The idea for making it reversible is whenever you compute a gate save the inputs. So, And & OR gates should be implemented in a reversible manner . The idea is to create a 3-qubit circuit which donot modify the input bits and writes the output of 3rd bit.

Image description

Reversible AND gates implementaion:

Image description

It is implemented using a Toffoli gate , It is revertible in the sense that given x1,x2 and y (xor) (x1 and x2) , we can compute back y.

Image description

Now the Qiskit Implementation,

Image description

The output of the code will be ,

Image description

OR gate Implementation:

Image description

Now there can be a lot of ways to implement this,
I am showing here two method.

Method 1: By using the rule A xor B xor AB = A OR B

Image description

Image description

Method 2: Simply negating and using De-Morgan

Image description

Image description

XOR gate Implementation:

Image description

Image description

Top comments (1)

Collapse
 
taradev profile image
imtarajones

Looks awesome, but finding it hard to follow. Could you add a little more context or walkthrough on this? I'm using qiskit in the office now, and enjoying the challenge of adapting our workloads to test quantum processing versions, so any good contnet like this I'd love to read more!