Basic Adder and Subtractor using Blueqat quantum computer SDK

Yuichiro Minato
May 19 · 3 min read

Introduction

We try to implement basic adder and subtractor circuit on our blueqat SDK

Decimal and Binary number

First you have to convert decimal to binary number using qubits.

15 is ,

when,

Adder of 2qubits

Now we realize adder of 2qubits,

We need additional carry bit for the answer C

First we implement all the carry. a0,b0 to c1 and a1,b1,c1 using 3 toffoli gate.

and sum

That’s all. Now we can use adder with input of data with X gate.

Toffoli gate can implement with ccx[c,c,x] and cnot gate with cx[c,x].

Create each circuit using instance and just add each other finally use .run()

Subtractor

To implement subtractor is simple just reverse the circuit because the quantum circuit is reversible.

Let’s see the code.

Basic subtractor is also easy to implement.

Improvement of the code and about toffoli gate

This time we use integrated toffoli gate. If you want to make the adder circuit with basic gate set you need to implement a complicated and long logical circuit before like,

but now,

It’s quite simple, let’s contribute and give some request for developers.

What is Blueqat?

Blueqat is an open source library for quantum computer.

How to install Blueqat?

Blueqat is provided as Python (ver 3.6+) library. You can install by pip.

pip install blueqat

The overlayed state has shifted so that 0 and 1 come to q2 in about half probability.

If you have any questions or suggestions, please feel free to contact us by our Slack community. (Join from here)

Yuichiro Minato

Written by

MDR, Quantum Computing@Tokyo, https://mdrft.com/