Chapter 5. Quantum Arithmetic and Logic

QPU applications often gain an advantage over their conventional counterparts by performing a large number of logical operations in superposition.1

A key aspect of this is the ability to apply simple arithmetic operations on a qubit register in superposition. In this chapter, we will look in detail at how to do this. Initially, we’ll discuss arithmetic operations at the more abstracted level we’re used to in conventional programming, dealing with integers and variables rather than qubits and operations. But toward the end of the chapter we’ll also take a closer look at the logical operations making these up (akin to the elementary gates of digital logic).

Strangely Different

Conventional digital logic has plenty of well-optimized approaches for performing arithmetical operations—why can’t we just replace bits with qubits and use those in our QPU?

The problem, of course, is that conventional operations are expected to operate on a single set of inputs at a time, whereas we will often have input registers that are in superposition, for which we want quantum arithmetic operations to affect all values in the superposition.

Let’s start with a simple example demonstrating how we want logic to work on a superposition. Suppose we have three single-qubit QPU registers, a, b, and c, and we want to implement the following logic: if (a and b) then invert c. So if a is ∣1⟩ and b is ∣1⟩, then the value of c will be flipped. We saw in Figure 3-20 that ...

Get Programming Quantum Computers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.