Reader small image

You're reading from  Quantum Computing Algorithms

Product typeBook
Published inSep 2023
PublisherPackt
ISBN-139781804617373
Edition1st Edition
Right arrow
Author (1)
Barry Burd
Barry Burd
author image
Barry Burd

Barry Burd received a master's degree in computer science at Rutgers University and a Ph.D. in mathematics at the University of Illinois. As a teaching assistant in Champaign–Urbana, Illinois, he was elected five times to the university-wide List of Teachers Ranked as Excellent by Their Students. Since 1980, Dr. Burd has been a professor in the department of mathematics and computer science at Drew University in Madison, New Jersey. He has spoken at conferences in the United States, Europe, Australia, and Asia. In 2020, he was honored to be named a Java Champion. Dr. Burd lives in Madison, New Jersey, USA, where he spends most of his waking hours in front of a computer screen.
Read more about Barry Burd

Right arrow

New Ways to Think about Bits

Classical computing is everywhere. The phone in your pocket, the laptop on your desk, and the world's fastest supercomputers use classical computing hardware. A classical computer codes everything in bits, and bits are quite simple. The rules for dealing with bits have been known since the mid-1800s. (George Boole wrote his ground-breaking work on logic in 1854). The computer hardware that manipulates bits has developed steadily since the mid-1940s.

Before you read about quantum computing, you need to have explored certain mathematical concepts. With that in mind, this chapter shows you how math applies to ordinary, classical bits.

If you’ve done any coding, you’re already familiar with the and, or, and not operators, but you may not know how to represent these operators using matrices. This chapter explores the connection between bit operations and matrices. After a tour through the math, we walk through the creation of matrices...

Technical requirements

Every chapter in this book requires that you have access to a web browser. You can download each chapter’s Python code from the following GitHub link: https://github.com/PacktPublishing/Quantum-Computing-Algorithms.

Bits and logic gates

A classical computer codes information as sequences of bits, each bit having one of two values – 0 or 1. Of course, if you looked inside the circuitry, you wouldn’t see things shaped like ovals for 0s and vertical lines for 1s. Instead, you might observe electrical voltages. Any voltage below 0.8 volts might stand for a 0 bit, and any voltage over 2.0 volts might stand for 1 bit. A voltage between 0.8 and 2.0 would be treated as an error condition.

As bits flow from one part of the computer to another, they pass through the circuitry’s gates. A gate is a piece of hardware (often made of transistors) that operates on bits. Each kind of gate is named after the operation that it performs.

Let’s see a few examples:

  • A NOT gate performs a NOT operation. The gate outputs 1 if and only if the gate’s input is not 1:
Figure 1.1 – Behavior of the NOT gate

Figure 1.1 – Behavior of the NOT gate

  • An AND gate performs the...

Working with matrices

A matrix is a rectangle of numbers. For example:

open parentheses table row 2 cell negative 3 end cell 0 row 1 5 19 end table close parentheses

The matrix shown previously has two rows and three columns, so we call it a 2×3 matrix (pronounced as two-by-three matrix).

Tip

The plural of matrix is matrices (pronounced as MAY-trih-sees). To sound like a pro, never say matrixes or matricee.

It’s common to use an uppercase to represent a matrix. You refer to the entries in a matrix using the entries’ row numbers and column numbers. Some authors start with row number 1 and column number 1, but, for our purposes, it’s better to start with row number 0 and column number 0.

When you talk about matrices, you need a name that refers to a single number – a number that isn’t inside of a matrix. For example, if you write the number 12 with no parentheses around it, you’re referring to one of these single numbers. A number of this kind is called a scalar.

So, what can you do with...

Matrix representation of bits and gates

For an inkling of the way matrices work in computer logic, we introduce two new ways to represent bits:

  • In Dirac notation, the zero bit is |0, and the one bit is |1.

The | combination of characters is called a ket.

  • In vector notation, the zero bit is open parentheses table row 1 row 0 end table close parentheses, and the one bit is open parentheses table row 0 row 1 end table close parentheses.

These new ways to represent bits may seem cumbersome and redundant, but they’re really very helpful. If you like, think of the numbers in a vector as amounts ranging from zero to one. A vector’s top entry is an amount of zero-ness and the vector’s bottom entry is an amount of one-ness.

Figure 1.16 – The correspondence between vector notation and Dirac notation

Figure 1.16 – The correspondence between vector notation and Dirac notation

This business about all zero-ness and all one-ness will make more sense when you read about qubits in the next chapter.

Disclaimer

Most authors reserve kets and vectors for qubits (quantum bits). For...

Jupyter notebooks

Jupyter notebooks are web-based environments for running code and displaying information about the code. To program quantum computers, we’ll create Jupyter notebooks that run Python programs with IBM’s Qiskit library functions.

To get started with Qiskit, follow these steps:

  1. Visit the quantum computing lab: https://quantum-computing.ibm.com/lab.
  2. Create an IBM account.
  3. Return to the quantum computing lab page: https://quantum-computing.ibm.com/lab.
  4. In the resulting Launcher tab, click on the Notebook | Python 3 (ipykernel) buttons:
Figure 1.21 – Creating a Qiskit notebook

Figure 1.21 – Creating a Qiskit notebook

A new Jupyter notebook appears. Near the top of the notebook, there’s an empty text field.

In the next section, you will populate that text field with Python code.

Creating and displaying values

A Jupyter notebook consists of cells. In a typical scenario, each cell contains a text field. You can type code...

Matrices in Python

Doing matrix operations by hand is tedious and error-prone, but you don’t have to do everything by hand. This section describes a nice alternative:

  1. If you haven’t already done so, follow steps 1 to 3 at the beginning of this chapter’s Jupyter notebooks section.
  2. In the upper-left corner of the page, click the New File button.
  3. In the resulting Launcher tab, click the Notebook | Qiskit button.

A new, empty Jupyter/Python notebook appears.

  1. In the empty cell, near the top of the notebook, type the following code, and then press Shift+Enter:
    import numpy as np

No output shows up on the screen, but behind the scenes, this statement makes a library named NumPy available to the code in your notebook. As the name suggests, NumPy deals with numbers and other mathematical concepts. From this point on, your code uses np as a nickname for NumPy.

Important note

The previous section (Copying this book’s code...

Summary

You can represent bits and bit sequences as vectors. You can represent operators on bits as matrices. To combine bits, combine operators, and apply operators to bits, you use matrix multiplication and the tensor product.

In truth, most people who deal with bit-level concepts don’t do matrix calculations. There are other, less cumbersome ways to understand bits and bit operations, but quantum computing deals with things that are more complicated than bits. Quantum computing deals with quantum bits, also known as qubits, and matrices give us excellent insights into the workings of qubits.

The next chapter extends your understanding of matrices from bits to qubits. In that chapter, you begin investigating the weird world of quantum computing.

Questions

  1. What’s the output of the following circuit?

  1. What’s the decimal representation of the binary number 10111001?
  2. Find the dot product:
  1. Find the product of the two matrices:
  1. Find the tensor product:

open parentheses table row 2 row 3 row 1 end table close parentheses space open parentheses table row 8 4 0 row 1 3 5 end table close parentheses

  1. Express the following circuit in matrix form:
  1. Express the following circuit in matrix form:
  1. Redo questions 4 and 5 using a Jupyter notebook with NumPy.
  2. Look for the toolbar near the top of the Jupyter notebook. Hover over each of the toolbar’s icons and read each tooltip that appears. These icons give you quick access to some of the notebook’s more frequently-used commands.
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Quantum Computing Algorithms
Published in: Sep 2023Publisher: PacktISBN-13: 9781804617373
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Barry Burd

Barry Burd received a master's degree in computer science at Rutgers University and a Ph.D. in mathematics at the University of Illinois. As a teaching assistant in Champaign–Urbana, Illinois, he was elected five times to the university-wide List of Teachers Ranked as Excellent by Their Students. Since 1980, Dr. Burd has been a professor in the department of mathematics and computer science at Drew University in Madison, New Jersey. He has spoken at conferences in the United States, Europe, Australia, and Asia. In 2020, he was honored to be named a Java Champion. Dr. Burd lives in Madison, New Jersey, USA, where he spends most of his waking hours in front of a computer screen.
Read more about Barry Burd