Quantum Multiplication

I heard that the hardest math equation ever calculated on a quantum computer was 3 x 5. I don’t know how long ago that video was made, but I decided to try multiplying 3 x 5 myself.

It turns out to not be too difficult. With 3 × 5, multiplication is all AND gates and addition is all XOR gates.

Of particular note, no half adders or full adders are required to perform the addition; multiplying other numbers could require much more code and, more importantly, more quantum bits (qubits). As it is, I used 13 of the only 14 qubits available to me, leaving only 1 qubit to spare.

OPENQASM 2.0;
include "qelib1.inc";
qreg q[13];
creg c[4];
This initializes 13 quantum registers and 4 classical registers.

x q[0];
x q[1]; // 1st 2 qubits 11 (3)
x q[2];
x q[4]; // next 3 qubits 101 (5)
All qubits start at a ground state of 0; this changes 4 of the first 5 qubits to 1 so that I could use a binary 11 (digital 3) and a binary 101 (digital 5).

barrier q; // multiply
ccx q[2], q[0], q[5]; // LSQ
ccx q[2], q[1], q[6];
ccx q[3], q[0], q[7];
ccx q[3], q[1], q[8];
ccx q[4], q[0], q[9];
ccx q[4], q[1], q[10]; // MSQ
Multiplication is all AND gates: 1 x 1 = 1; all else is 0.

barrier q; // add
cx q[6], q[11];
cx q[7], q[11]; // 2nd digit
cx q[8], q[12];
cx q[9], q[12]; // 3rd digit
With 3 x 5, all addition can be done with simple XOR gates.

barrier q; // measure
measure q[5] -> c[0];
measure q[11] -> c[1];
measure q[12] -> c[2];
measure q[10] -> c[3];
This measures the appropriate qubits and sends the output to the classical registers for display as a histogram.

This is the graphical representation of the code. I finally figured out that I can download it as an image instead of trying to piece together screen captures. Green is NOT gates, purple is AND gates, blue is XOR gates, and red is measurements.

This is the result on a simulator. Since binary 1111 is digital 15, the result of multiplying 3 x 5 is a success.

Unfortunately, imperfect measurements and residual heat cause this on real hardware: every possible combination of zeroes and ones has some probability of being the result. Because quantum computing is still in its infancy, the correct answer has only a 2.563% chance of being the result.

Since I had one qubit to spare, and because it is possible to reset, recycle, and reuse qubits, I’m going to try something harder. I’m not sure yet what that will be, but I’m searching for ideas with practical value.