In this computational essay, I will explore Quantum Counterpart of Classical Gates. I would implement some gates like NOT, AND, OR, etc. in classical and then quantum ways, using the Wolfram Quantum Computation Framework
Introduction
Introduction
We have been studying the classical gates like AND, NOT, NAND, etc. as a fundamental building block for the classical computing. Quantum Computers are believed to be outperform the classical and this can not be achieved without implementing basic operations. The quantum counterpart of subsequent classical gates is achieved by the Quantum gates like Pauli gates, Toffoli gates, etc.
NOT X Gate
NOT X Gate
NOT operation gives complement of the state.
Truth table for Classical NOT operation
In[]:=
not=Boole[BooleanTable[{a,Not[a]},{a}]];Text@Grid[Prepend[not,{"A","A'"}],Background{None,{Lighter[Yellow,.9],{White,Lighter[Blend[{Blue,Green}],.8]}}},Dividers{{Darker[Gray,.6],{Lighter[Gray,.5]},Darker[Gray,.6]},{Darker[Gray,.6],Darker[Gray,.6],{False},Darker[Gray,.6]}},Alignment{{Center,Center,{Center}}},ItemSize{{5,5}},FrameDarker[Gray,.6],ItemStyle14]
Out[]=
A | A' |
1 | 0 |
0 | 1 |
Quantum circuit is defined independently using the 'PauliX' gate and then visualized.
In[]:=
qNOT=QuantumCircuitOperator[{QuantumOperator["PauliX"]}];qNOT["Diagram","WireLabels"->{{Placed["A",Left],Placed["A'",Right]}}]
Out[]=
Choose both 0 and 1 as input and measure the output.
In[]:=
input=QuantumState/@{"0","1"};output=qNOT/@input;
Arrange input and output of Quantum Circuit using TableForm.
In[]:=
TableForm[Transpose[MapAt[#["Formula"]&,{input,output},{All,All}]],TableHeadings{None,{"A","A'"}}]
Out[]//TableForm=
A | A' |
|0〉 | |1〉 |
|1〉 | |0〉 |
Truth table of both classical and quantum version of NOT gate are same. The Quantum Counterpart of NOT gate is PauliX/NOT gate.
AND Toffoli Gate
AND Toffoli Gate
An AND gate operates on logical multiplication rules . In this gate, if either of the inputs is low and high, then the output is also low and high respectively.
Truth table of classical AND operation.
In[]:=
and=Boole[BooleanTable[{a,b,And[a,b]},{a,b}]];Text@Grid[Prepend[and,{"A","B","AB"}],Background{None,{Lighter[Yellow,.9],{White,Lighter[Blend[{Blue,Green}],.8]}}},Dividers{{Darker[Gray,.6],{Lighter[Gray,.5]},Darker[Gray,.6]},{Darker[Gray,.6],Darker[Gray,.6],{False},Darker[Gray,.6]}},Alignment{{Center,Center,{Center}}},ItemSize{{5,5,5}},FrameDarker[Gray,.6],ItemStyle14]
Out[]=
A | B | AB |
1 | 1 | 1 |
1 | 0 | 0 |
0 | 1 | 0 |
0 | 0 | 0 |
Define circuit operator
In[]:=
qAND=QuantumCircuitOperator[{QuantumOperator["Toffoli"]}];
Visualize it
In[]:=
qAND["Diagram","WireLabels"->{{Placed["A",Left],Placed["A",Right]},{Placed["B",Left],Placed["B",Right]},{Placed["|0〉",Left],Placed["AB",Right]}}]
Out[]=
All combinations of A and B, with setting 3rd qubit as 0
In[]:=
states=QuantumState[StringJoin[#,"0"]]&/@Tuples[{"0","1"},2];
Formulas of states (only for illustration purposes)
In[]:=
#["Formula"]&/@states
Out[]=
{|000〉,|010〉,|100〉,|110〉}
Measure 3rd qubit (which will be AB)
In[]:=
final=QuantumMeasurementOperator[{3}][qAND]/@states;
Delete cases with repetitive 0 probabilities and keep unique keys
In[]:=
results=Keys[DeleteCases[#["Probabilities"],0]]&/@final//Flatten
Out[]=
{|0〉,|0〉,|0〉,|1〉}
Visualize the quantum version of AND truth table.
In[]:=
Grid[Prepend[Transpose[{QuantumState[#]["Formula"]&/@StringJoin@@@Tuples[{"0","1"},2],results}],{"|A,B〉","|AB〉"}],Frame->All,Background{None,{{LightRed,LightBlue}}}]
Out[]=
|A,B〉 | |AB〉 |
|00〉 | |0〉 |
|01〉 | |0〉 |
|10〉 | |0〉 |
|11〉 | |1〉 |
The third qubit initialized at 0 is chosen as the output and is similar to the classical counterpart.
OR anti-Toffoli Gate
OR anti-Toffoli Gate
The Logic OR Gate output goes HIGH only when one or more of its inputs are HIGH.
Truth table of classical OR gate.
In[]:=
or=Boole[BooleanTable[{a,b,Or[a,b]},{a,b}]];Text@Grid[Prepend[or,{"A","B","A+B"}],Background{None,{Lighter[Yellow,.9],{White,Lighter[Blend[{Blue,Green}],.8]}}},Dividers{{Darker[Gray,.6],{Lighter[Gray,.5]},Darker[Gray,.6]},{Darker[Gray,.6],Darker[Gray,.6],{False},Darker[Gray,.6]}},Alignment{{Center,Center,{Center}}},ItemSize{{5,5,5}},FrameDarker[Gray,.6],ItemStyle14]
Out[]=
A | B | A+B |
1 | 1 | 1 |
1 | 0 | 1 |
0 | 1 | 1 |
0 | 0 | 0 |
Quantum counterpart of OR gate is an anti-Toffoli gate having third qubit initialized at '1'.
Define the circuit along with the Measurement operator.
In[]:=
qOR=QuantumCircuitOperator[{QuantumOperator[{"Controlled0","NOT",{1,2}},{3}],QuantumMeasurementOperator[{3}]}];
Visualize it. The right hand side of third qubit is the desired OR gate output 'A+B'.
In[]:=
qOR["Diagram","WireLabels"->{{Placed["A",Left],Placed["A",Right]},{Placed["B",Left],Placed["B",Right]},{Placed["|1〉",Left],Placed["A+B",Right]}}]
Out[]=
All combinations of A and B, with 3rd qubit initialized at 1.
In[]:=
statesor=QuantumState[StringJoin[#,"1"]]&/@Tuples[{"0","1"},2];
Apply each combination for measurement.
In[]:=
finalor=qOR/@statesor;
Delete cases with repetitive probabilities and retain only unique keys.
In[]:=
resultsor=Keys[DeleteCases[#["Probabilities"],0]]&/@finalor//Flatten
Out[]=
{|0〉,|1〉,|1〉,|1〉}
Visualize the Quantum version of OR truth table.
In[]:=
Grid[Prepend[Transpose[{QuantumState[#]["Formula"]&/@StringJoin@@@Tuples[{"0","1"},2],resultsor}],{"|A,B〉","|A+B〉"}],Frame->All,Background{None,{{LightRed,LightBlue}}}]
Out[]=
|A,B〉 | |A+B〉 |
|00〉 | |0〉 |
|01〉 | |1〉 |
|10〉 | |1〉 |
|11〉 | |1〉 |
This is alternate approach where the measurement is done alongside with the circuit operator.
XOR CNOT Gate
XOR CNOT Gate
XOR is widely used in cryptography as well as in generating parity bits for error checking and fault tolerance.
XOR gate gives a HIGH output when the number of true inputs is odd.
XOR gate gives a HIGH output when the number of true inputs is odd.
Truth table of classical xor gate.
Note that the state is high only when both states are not same.
Quantum counterpart of XOR operation is realized using two CNOT gates. We will use the measurement operation altogether again.
Define circuit operator initializing third qubit as 0.
Visualize it.
All combinations of A and B, initializing third qubit as 0.
Measure all possible states.
There are two operations which are at HIGH state.
Deleting cases with repetitive probabilities and retaining only unique keys.
Visualize the truth table
The truth table of quantum version of XOR complies with the classical counterpart.
NAND Toffoli Gate
NAND Toffoli Gate
NAND gate produces an output which is LOW only if all its inputs are HIGH. Its output is thus complement to that of an AND gate.
Truth table of Classical NAND gate.
Quantum counterpart of NAND gate is realized using Toffoli gate with 3rd qubit initialized as 1.
Define circuit operator.
Visualize it.
All combinations of A and B, initializing 3rd qubit as 1.
Measuring third qubit initialized as 1.
Deleting repetitive probabilities and retaining unique keys.
Truth table of Quantum version of NAND gate.
Alternate approach of realizing Toffoli gate.
Measuring third qubit
Deleting repetitive probabilities and retaining unique keys for the alternate approach.
Truth table of Quantum version of NAND gate(alternate approach).
It is apparent that truth table of both the approach as Quantum counterpart of NAND gate are equal which verifies the equivalence of CNOT and combination of gates used in alternate approach.
NOR anti-Toffoli Gate
NOR anti-Toffoli Gate
A NOR gate produces a HIGH output only if all its inputs are low, and LOW output otherwise.
Truth table of classical NOR gate.
Quantum counterpart of NOR gate is realized like OR gates' except initializing 3rd qubit as 0.
Define circuit operator.
Visualize it.
All combinations of A and B initializing 3rd qubit as 0.
Visualize the states defined above.
Measuring 3rd qubit on all possible states.
Deleting cases with repetitive probabilities and retaining unique keys.
Visualize the truth table.
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Quantum counterpart of classical gates
by Shivam Sawarn
Wolfram Community, STAFF PICKS, March 22, 2022
https://community.wolfram.com/groups/-/m/t/2494463
by Shivam Sawarn
Wolfram Community, STAFF PICKS, March 22, 2022
https://community.wolfram.com/groups/-/m/t/2494463