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,
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,
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.
Reversible AND gates implementaion:
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.
Now the Qiskit Implementation,
The output of the code will be ,
OR gate Implementation:
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
Method 2: Simply negating and using De-Morgan














Top comments (1)
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!