# **Building a basic Quantum Adder using Toffoli Gates** ## Problem Statement Alice wishes to perform the addition of two 4-bit numbers using Quantum Circuits. Let those two numbers be a and b. ![](https://hackmd.io/_uploads/SkG0PgMP2.png) ![](https://hackmd.io/_uploads/ry3xdxMP2.png) In classical digital electronics, this is achieved using the full-adder circuit, which inputs the bits a_i,b_i and carry bit C_(i-1) and returns the sum bit S_i and carry bit C_i. Hence, the result of the computation would be as follows: ![](https://hackmd.io/_uploads/S1fzueGw3.png) Your task is to help Alice design a fully functional Quantum Adder using just CNOT and Toffoli Gates. ## Pre-Requisite Knowledge about Digital Full Adders ### Full Adder In classical digital electronics, half and full adder circuits are used to perform additions on n bits. ![](https://hackmd.io/_uploads/HyjjoxGwh.png) The computation of the sum and carry bits are done using the following relations: ![](https://hackmd.io/_uploads/rJSp0lMDn.png) ![](https://hackmd.io/_uploads/rk90AefP3.png) ### Classical Circuit Hence, multiple full-adders are used to compute the sum of an n-bit number. Below you would find the circuit for a simple classical full adder. ![](https://hackmd.io/_uploads/Sy0BxWGvn.png) To reduce propogation delay, even Carry-Look-Ahead circuits can be used. ## Instructions and Roadmap ### Some general instructions: * You can use any programming language or framework of your choice to implement the above adder. Qiskit would be preferred, however you can use any other framework. * Make sure to include appropriate documentation and comments in your code for clarity. * You are not allowed to use any pre-built algorithms or oracles. **You need to build all the circuits by yourself.** ### Roadmap: 1. #### Design a single full adder circuit. ![](https://hackmd.io/_uploads/ByI1bD7w3.png) Ideally, this should be a 4-qubit circuit. Using the relations for the sum and carry bits, design the single full adder circuit using CNOT and Toffoli gates. **Note:** You should attempt to not use any additional auxillary/ancilla qubits. 2. #### Using a single full adder, design a full adder circuit for adding two 4-bit numbers. ![](https://hackmd.io/_uploads/SysoIv7Dn.png) 3. #### Test the circuit for the following values of A and B * ![](https://hackmd.io/_uploads/SyfDb1Xvn.png) * ![](https://hackmd.io/_uploads/r19wZ17wh.png) * ![](https://hackmd.io/_uploads/BJVOZkQD2.png) * ![](https://hackmd.io/_uploads/rJZvMyXw3.png) A and B can be initialised using X,H and CX gates. 4. Obtain and show your measurements in the form of a histogram. You can use any Quantum Simulator (like QASM). :::info ## Bonus Tasks 1. Now, what would be the result in the case that the qubits of the registers of A and B are entangled, what would you expect to happen? Alongside running approriate test cases, give an explanation for your results. 2. Try and see if an analogue for the Classical Carry Look-Ahead Adder can be implemented. Implement it for the above test cases and show/compare your results. Also compare circuit depth in each case. ::: :::success ## Resources * Qiskit Textbook: https://qiskit.org/learn/ * Qiskit Documentation: https://qiskit.org/documentation/ * Classical Implementation of Full Adders: https://www.geeksforgeeks.org/full-adder-in-digital-logic/ :::