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

Math for Qubits and Quantum Gates

In the previous chapter, we examined the idea of a qubit with its elusive behavior and its probabilistic nature. That chapter mentioned states other than |0, |1, and a halfway state but doesn’t describe any details about such states.

To understand the full range of states a qubit can have, we need some math, and this chapter lays the mathematical groundwork. We’ll start this chapter by replacing the intuitive halfway terminology with numbers. We’ll show how those numbers apply to a qubit’s state. We will send qubits through quantum computer circuits and compute the outcome using matrices.

Using our tools to represent circuits with matrices, we will discover the kinds of operations that a circuit can perform. We’ll combine these operations using matrix arithmetic. To bring these concepts into crystal clear focus, we’ll write code to run on a quantum computer.

We’ll cover the following...

Matrices for qubit states and operations

In Chapter 1, New Ways to Think about Bits, we represented bits with kets and vectors:

Let’s expand that notation for qubits.

When you apply a Hadamard (h) gate to a |0 qubit, the qubit goes into a halfway state. Here’s how we represent that halfway state in Dirac notation:

And here’s how we represent that state with a vector:

This qubit state crops up so often in quantum computing that it’s convenient to give the state its own symbol. We put a plus sign inside a ket and say that .

In vector notation, the vector’s top number represents the amount of |0’ness, while the bottom number represents an equal amount of |1’ness. But what do the square roots do? What follows is a slight simplification.

Important note

A qubit’s state has two parts. When you take the square of either...

Reversible operations

You’re composing a letter to the love of your life. You accidentally delete an entire paragraph. So, what do you do? Do you try to recreate the paragraph word by word? No. You use the document editor’s Undo feature to go back to the time when the paragraph appeared.

Some things in life can be undone, whereas others can’t. If you shoot a missile into the air, you can’t get it back onto the launch pad unscathed. If the love of your life reads your letter, you can’t un-write what you wrote. If someone sends bits through a classical AND gate and you examine the gate’s output, you can’t always tell what the input bits were. Figure 3.16 illustrates this point.

Figure 3.16 – Are the inputs 00, 01, or 10?

Figure 3.16 – Are the inputs 00, 01, or 10?

What about this chapter’s quantum gates? Can they be undone? Pick any starting point on the Bloch sphere and then apply the X gate. When you apply the X gate, you rotate the...

Rotating the Bloch sphere around an axis

Rotations of the Bloch sphere can move a qubit from any point on the sphere’s surface to any other point on the surface. This section will show you some of Qiskit’s most useful rotation commands.

Experimenting with rotations

Qiskit provides many functions that rotate the Bloch sphere and change a qubit’s state. For hands-on practice with some of these rotations, open a new Qiskit notebook and follow these steps:

  1. Run the following code:
    from qiskit import QuantumRegister, QuantumCircuit
    from math import pi
    reg = QuantumRegister(1)
    circuit = QuantumCircuit(reg)
    circuit.ry(pi/2, reg[0])
    display(circuit.draw('latex'))

Figure 3.18 shows you the circuit diagram that this code generates:

Figure 3.18 – Rotating by  radians about the Y-axis

Figure 3.18 – Rotating by {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mfrac><mi mathvariant=\"normal\">&#x3C0;</mi><mn>2</mn></mfrac></mstyle></math>"} radians about the Y-axis

The circuit’s one and only qubit begins its life in the |0 state. Then, the circuit.ry(pi/2, reg[0]) statement...

Summary

In this chapter, we developed the tools to describe a qubit. We changed a qubit’s state by sending the qubit through a quantum gate. In mathematical terms, the gate applies an operator to the qubit – an operator that we represent using a matrix.

In classical computing, things start to become interesting when we execute statements conditionally. Most languages have if statements for conditional execution. To perform conditional execution at the quantum level, we need some kind of qubit-to-qubit interaction. One qubit changes if some other qubit’s state is |1.

To achieve this interaction, we need some new operators. Each such operator acts on more than one qubit at a time. We use matrices to represent these operators. When we do, we discover some bizarre effects. That’s what the next chapter is all about.

Questions

Answer the following questions to test your knowledge of this chapter:

  1. Which of the following vectors represents a qubit state?

A. {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mfrac><mn>1</mn><msqrt><mn>7</mn></msqrt></mfrac><mo>&#xA0;</mo><mfenced><mtable><mtr><mtd><msqrt><mn>3</mn></msqrt></mtd></mtr><mtr><mtd><mo>-</mo><mn>2</mn></mtd></mtr></mtable></mfenced></mstyle></math>"}

B. {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mfenced><mtable><mtr><mtd><mn>1</mn></mtd></mtr><mtr><mtd><mn>1</mn></mtd></mtr></mtable></mfenced></mstyle></math>"}

C. {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mfenced><mtable><mtr><mtd><mn>1</mn></mtd></mtr><mtr><mtd><mn>0</mn></mtd></mtr><mtr><mtd><mn>0</mn></mtd></mtr></mtable></mfenced></mstyle></math>"}

  1. In quantum computing, the Z gate rotates a Bloch sphere {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mi mathvariant=\"normal\">&#x3C0;</mi></mstyle></math>"} radians around the Z-axis. Draw the result of applying a Z gate to a |+ qubit.
  2. The matrix representation of a Z gate is {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mfenced><mtable><mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr><mtr><mtd><mn>0</mn></mtd><mtd><mo>-</mo><mn>1</mn></mtd></mtr></mtable></mfenced></mstyle></math>"}. Check to make sure that this matrix is unitary.
  3. Apply the Z gate matrix from Question 3 to a |+ qubit. Does the result you get confirm your answer to Question 2?
  4. Write Qiskit code to test the result you got in Questions 2, 3, and 4.
  5. The matrix representation of {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><msub><mi>R</mi><mi>Y</mi></msub><mfenced><mfrac><mi mathvariant=\"normal\">&#x3C0;</mi><mn>2</mn></mfrac></mfenced></mstyle></math>"} is {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mfrac><mn>1</mn><msqrt><mn>2</mn></msqrt></mfrac><mo>&#xA0;</mo><mfenced><mtable><mtr><mtd><mn>1</mn></mtd><mtd><mo>-</mo><mn>1</mn></mtd></mtr><mtr><mtd><mn>1</mn></mtd><mtd><mn>1</mn></mtd></mtr></mtable></mfenced></mstyle></math>"}. Check to make sure that this matrix is unitary.
  6. Verify that the matrix representation of {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><msub><mi>R</mi><mi>Y</mi></msub><mfenced><mfrac><mi mathvariant=\"normal\">&#x3C0;</mi><mn>2</mn></mfrac></mfenced></mstyle></math>"} is {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mfrac><mn>1</mn><msqrt><mn>2</mn></msqrt></mfrac><mo>&#xA0;</mo><mfenced><mtable><mtr><mtd><mn>1</mn></mtd><mtd><mo>-</mo><mn>1</mn></mtd></mtr><mtr><mtd><mn>1</mn></mtd><mtd><mn>1</mn></mtd></mtr></mtable></mfenced></mstyle></math>"}. Use the last formula in this chapter’s Experimenting with rotations section.
  7. In Step 2 of the Experimenting with rotations section, applying {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><msub><mi>R</mi><mi>Y</mi></msub><mfenced><mfrac><mi mathvariant=\"normal\">&#x3C0;</mi><mn>2</mn></mfrac></mfenced></mstyle></math>"} to |0 has the same effect as applying {"mathml":"<math style=\"font-family:stix;font-size:16px;\" xmlns=\"http://www.w3.org/1998/Math/MathML\"><mstyle mathsize=\"16px\"><mi>H</mi></mstyle></math>"} to |0. Do the matrix calculation...
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