Skip to main content

Section 1.1 Reading Circuits

Quantum operations are visualized in what they call "circuits." Circuits are a visualization that depict the order of operations. Let’s first see what some some familiar operations might look like if visualized like a circuit!

Section 1.1.1 Cookie Circuits

In this picture, we begin with a plate of 4 cookies (the input). We have one operation, "eat one cookie". After the operation is applied, we are left with 3 cookies. There is only one operation depicted, so that is the end of the program. Therefore, the plate with 3 cookies is the output. Likewise, if give the same circuit an input of a plate of 3 cookies and applied that operation once, we would end up with an output of a plate with 2 cookies.
We can also draw a circuit that starts out with multiple plates of cookies and applies the operations to each plate. In this case, we start with two plates of cookies - one that has 5 cookies and the other that has 3. We then apply operations to each of the plates. There are two operations applied to the plate with 5 cookies, and one operation applied to the plate with 3 cookies. We then end up with plates of 3 and 2 cookies, respectively.
Pick the circuit that has the correct end state given the start state. (four circuit diagrams with two starting plates of cookies (1-3 cookies) and one or two operations each time, only one has a correct output given the starting input)

Section 1.1.2 Math Circuits

Now let’s consider how we would depict mathematical operations.
We will use the following operations:
  • Increment - add one to a number
  • Decrement - subtract one from a number
  • Negate - negate a number

Checkpoint 1.1.1. Applying a Math Operation 1.

    Pick the circuit that has the correct end state given the start state.
  • 8
  • Yes! If you increment the input by 1, then the output is 8.
  • 6
  • There is one “Increment” operation, but it looks like you applied the “Decrement” operation.
  • -7
  • There is one “Increment” operation, but it looks like you applied the “Negate” operation.
  • 11
  • Did you apply the “Increment” operation?
Hint.
The increment operation adds 1 to the input value.

Checkpoint 1.1.2. Applying a Math Operation 2.

    Pick the circuit that has the correct end state given the start state.
  • 2
  • Yes! If you decrement the input by 1, then the output is 2.
  • 4
  • There is one “Decrement” operation, but it looks like you applied the “Increment” operation.
  • -3
  • There is one “Decrement” operation, but it looks like you applied the “Negate” operation.
  • 6
  • Did you apply the “Decrement” operation?
Hint.
The decrement operation subtracts 1 from the input value.

Checkpoint 1.1.3. Applying a Math Operation 3.

    Pick the circuit that has the correct end state given the start state.
  • -11
  • Yes! If you negate the input, then the output is -11.
  • 12
  • There is one “Negate” operation, but it looks like you applied the “Increment” operation.
  • 10
  • There is one “Negate” operation, but it looks like you applied the “Decrement” operation.
  • 0
  • Did you apply the “Negate” operation?
Hint.
The negate operation changes a positive number into it’s negative counter part - and vice versa (e.g. 3 becomes -3; -7 becomes 7).
We can also define two-variable gates:
  • Add - add two numbers. Add two numbers and place result in the target, indicated by *. Other input is unchanged.
  • Controlled increment - increment the target if and only if the control is odd. Target is indicated by *, control remains unchanged.
These two-variable gates bring up a few details that cannot be ignored. First - where does the result go? There are two inputs. In mathematics, there is only one result - in programming, we specify where the result goes by writing "variable = expression". We don’t have this functionality in quantum operations. In quantum computing, if there are two inputs, there are two outputs - and we need to define what both of those outputs are. In both of the gates defined above, we will place the result in the target, leaving the other output to match its input.

Checkpoint 1.1.4. Applying a two-variable Math Operation 1.

    Pick the circuit that has the correct end state given the start state.
  • x = 7; y = 2
  • Yes! If you add 5 and 2, the total is 7. The total replaces the original value in x, and the y value remains the same.
  • 7
  • The "Add" operation should have two outputs.
  • x = 5; y = 2
  • The circuit has one "Add" operation. The sum of x and y should replace the original x value, and the y value should remain unchanged.
  • x = 5; y = 7
  • Did you correctly store the calculated total in the Target?
Hint.
The Add operation calculates the sum of x and y. The calculated total is stored in x (replacing the its value) and the y value remains the same.

Checkpoint 1.1.5. Applying a two-variable Math Operation 2.

    Pick the circuit that has the correct end state given the start state.
  • x = 9; y = 6
  • Yes! There is no change to the Target value, because the Control value is even.
  • x = 10; y = 6
  • Looks like you incremented the Target. The "Controlled Increment" operation only increments the Target value if the Control is odd.
  • x = 9; y = 7
  • Looks like you incremented the Control. The "Controlled Increment" operation increments the Target value if the Control is odd.
  • x = 15; y = 6
  • Did you apply the correct operation? There is one "Controlled Increment" operation in the circuit.
Hint.
The "Controlled Increment" operation adds 1 to the value of the Target, if the Control value is odd. If the Control is even, then the Target is unchanged.
Now, consider two starting variables, x and y. We will start with an input of x=5 and y=3. Consider the following sequence of operations:
  • x = x + 1
  • y = y - 1
  • x = x + y
  • y = x - y
The following circuit would depict that sequence of operations:

Checkpoint 1.1.6. Solving a Math Circuit with two inputs 1.

    What are the values of x and y after the following math circuit runs?
  • x = -5; y = 0
  • Yes! There are two operations applied to each input:
    • The input (x = 4) is incremented by one (x = 5), and then the value is negated (x = -5).
    • The input (y = 2) is decremented by one (y = 1), and then it is decremented again (y = 0).
    The resulting outputs are: x = -5 and y = 0.
  • x = -5; y = 4
  • Not quite. Double check that you applied the correct operations. Did you apply them in the correct order - left to right?
  • x = 0; y = 4
  • Not quite. Double check that you applied the correct operations. Did you apply them in the correct order - left to right?
  • x = 5; y = 0
  • Not quite. Double check that you applied the correct operations. Did you apply them in the correct order - left to right?
Hint.
There are two operations applied to each input: x and y
  • For the x-input: Increment x, and then negate it.
  • For the y-input: Decrement y two times.

Checkpoint 1.1.7. Solving a Math Circuit with two inputs 2.

    What does the circuit look like for this sequence of operations?
    Start with an input of x = 1 and y = 5 and apply the following sequence of operations:
    • x = x - 1
    • y = y + 1
    • x = x + y
    • y = - y
  • Yes!! First, the x variable is decremented. Then, the y-variable is incremented. Next, the sum of x and y is stored in the x varaible. Finally, the y variable is negated. The final outputs are: x = 6 and y = -6.
  • Not quite. Double check that you applied the correct operations. Did you apply them in the correct order - left to right? Did you apply them to the correct variable - x or y?
  • Not quite. Double check that you applied the correct operations. Did you apply them in the correct order - left to right? Did you apply them to the correct variable - x or y?
  • Not quite. Double check that you applied the correct operations. Did you apply them in the correct order - left to right? Did you apply them to the correct variable - x or y?
Hint 1.
Double check that you applied the correct operations to the correct variables.
Hint 2.
Did you apply the operations in the correct order - left to right?

Checkpoint 1.1.8. Solving a Math Circuit with two inputs 3.

    Select the circuit that would produce the following values: x = 5; y = 2.
  • Yes! Start with x = 3 and y = 2; the Controlled Increment has no effect, because the control is even; and finally the sum of x and y is stored in x (y remains unchanged). The result is x = 5 and y = 2.
  • Not quite.
  • Not quite.
  • Not quite.
Hint 1.
Look at where the (target) says to place the addition result.
Hint 2.
Remember that the Controlled Increment operation, increments the target if - and only if - the control is ODD.

Checkpoint 1.1.9. Solving a Math Circuit with two inputs 4.

    Select the circuit that would produce the following values: x = 8; y = 1.
  • Not quite.
  • Not quite.
  • Not quite.
  • Yes! Start with x = 6 and y = 1; the Add operation stores the sum of x and y in x (y remains unchanged); and finally the Controlled Increment adds 1 to x, because the control is odd.
Hint 1.
Look at where the (target) says to place the addition result.
Hint 2.
Remember that the Controlled Increment operation, increments the target if - and only if - the control is ODD.
Summary:
  • A single operation can involve multiple items.
  • Circuits depict the order of operations.
  • The order of operations goes from left to right.
  • The left to right convention depicts the order operation are applied, not physical movement.
  • Multiple operations may be depicted in the same circuit.
You have attempted 1 of 12 activities on this page.