Path: blob/main/translations/ja/ch-ex/Solutions/Exercise for 1.1.ipynb
3855 views
Kernel: Python 3
In [ ]:
Solutions: Classical logic gates with quantum circuits
NOT gate
This function takes a binary string input ('0' or '1') and returns the opposite binary output'.
In [2]:
XOR gate
Takes two binary strings as input and gives one as output.
The output is '0' when the inputs are equal and '1' otherwise.
In [3]:
AND gate
Takes two binary strings as input and gives one as output.
The output is '1' only when both the inputs are '1'.
In [4]:
NAND gate
Takes two binary strings as input and gives one as output.
The output is '0' only when both the inputs are '1'.
In [5]:
OR gate
Takes two binary strings as input and gives one as output.
The output is '1' if either input is '1'.
In [6]:
Tests
The following code runs the functions above for all possible inputs, so that you can check whether they work.
In [7]:
Out[7]:
Results for the NOT gate
NOT with input 0 gives output 1
NOT with input 1 gives output 0
Results for the XOR gate
NOT with inputs 0 0 gives output 0
NOT with inputs 0 1 gives output 1
NOT with inputs 1 0 gives output 1
NOT with inputs 1 1 gives output 0
Results for the AND gate
NOT with inputs 0 0 gives output 0
NOT with inputs 0 1 gives output 0
NOT with inputs 1 0 gives output 0
NOT with inputs 1 1 gives output 1
Results for the NAND gate
NOT with inputs 0 0 gives output 1
NOT with inputs 0 1 gives output 1
NOT with inputs 1 0 gives output 1
NOT with inputs 1 1 gives output 0
Results for the OR gate
NOT with inputs 0 0 gives output 0
NOT with inputs 0 1 gives output 1
NOT with inputs 1 0 gives output 1
NOT with inputs 1 1 gives output 1
In [ ]: