I want to create an ADD gate like this: enter image description here

in qiskit using elementary gates.

Can it be done?

  • $\begingroup$ Hello ! Did you check this example in the textbook? It could be good for a first start :) $\endgroup$ – Lena Feb 16 at 13:03
  • $\begingroup$ @Lena I also said the same thing regarding addition. Is there anything wrong with my answer? :( $\endgroup$ – user27286 Feb 16 at 14:47
  • $\begingroup$ @user27286 No you didn't, actually. What you described is an XOR operation, not an adder. That's why I put the link to know if he/she knew this. $\endgroup$ – Lena Feb 16 at 15:03
  • $\begingroup$ @Lena Oh. I thought adding |0> and |1> is just xor of these two and the carry part I didn't use. I will delete the answer...I misinterpreted completely and no point answering it now because you shared the link. $\endgroup$ – user27286 Feb 16 at 15:12
  • 5
    $\begingroup$ Does this answer your question? How to make a half adder for x number of qubits with min. cost? $\endgroup$ – luciano Mar 13 at 19:38

The method of creating a quantum adder circuit is similar to how a half or full adder circuit is designed in elementary digital electronics. These circuits add numbers in the binary representation.

For example, for the half adder, there are 2 bits to be added (A and B). These are taken to be the inputs. The output has 2 bits - a sum bit (S)which is the least significant bit of the output and a carry bit (C) which is the MSB. For example, if the inputs to be added are 1 and 1, the result would be carry=1 and sum=0.

To figure out the logic for the adder, write the truth table for the operation:


0 0 0 0

0 1 0 1

1 0 0 1

1 1 1 0

For the quantum half adder, take 1 qubit each to represent A,B,C and S respectively. A and B are initialized to the input bits that you wish to add. (For example if you want to add 1 and 0, initialize A = |1> and B=|0>).

Now we need to determine the quantum gates which can take A and B as inputs and give C and S as the outputs - this is like boolean logic minimization. Look at bit C in the truth table - it is 1 only when both A and B are 1. So, C can be obtained by a CCNOT operation using A and B as inputs and C as target. Also, S is a classical XOR operation - this can be achieved by 2 successive CNOTs, both havong S as target and one with A as control and other with B as control.

Keep in mind that the advantage of a quantum adder could be to add several possible input combinations in one go by creating superpostion states in A and B.

You may refer to this example present in the knowldege base of the Quantum Inspire platform by TU Delft for quantum circuits for adders. The qiskit textbook also has an example of how to implement a quantum adder here. It explaines how to apply the appropriate quantum gates, and it should be possible to follow this approach to implement the circuit of your choice.


Not the answer you're looking for? Browse other questions tagged or ask your own question.