Classical gate codes on basis states #
The classical gate codes NOT, CNOT and Toffoli of
CslibFrontier/Computability/Circuit/Quantum/Code.lean permute the computational basis: the code
(false, t, cs) flips bit t when every bit of cs is one
(Cslib.Quantum.GateCode.classicalStep). A list of classical codes therefore maps the basis
state |x⟩ to the basis state of the composed permutation
(Cslib.Quantum.Circuit.eval_ofCodes_ket), and it acts on any state by reading amplitudes back
through the inverse permutation (Cslib.Quantum.Circuit.eval_ofCodes_apply). Measuring after a
classical circuit is measuring before it and then applying the permutation to the outcome
(Cslib.Quantum.Circuit.measureProb_eval_ofCodes).
Bits of a basis string are read by their number (Cslib.Quantum.readBit), as in gate codes.
Main definitions #
Cslib.Quantum.readBit: bitcof a basis string,falsepast its end.Cslib.Quantum.GateCode.target,Cslib.Quantum.GateCode.controls: target wire and control wires of a gate code.Cslib.Quantum.GateCode.classicalStep: the action of a classical gate code on basis strings, a permutation when the target is not a control.Cslib.Quantum.GateCode.IsClassical: a list of well-formed classical gate codes.Cslib.Quantum.GateCode.classicalRun,Cslib.Quantum.GateCode.classicalUnrun: the composed action of a list of classical codes and, for a list of well-formed classical codes, its inverse.Cslib.Quantum.GateCode.swapCodes: three CNOT gates moving qubita ≠ 0into qubit0.
Main results #
Cslib.Quantum.GateCode.readBit_classicalStep: a classical code changes only its target.Cslib.Quantum.Circuit.eval_ofCodes_ket,Cslib.Quantum.Circuit.eval_ofCodes_apply: classical circuits permute basis states.Cslib.Quantum.Circuit.measureProb_eval_ofCodes: measuring after a classical circuit.
The target wire t of a gate code (h, t, cs).
The control wire list cs of a gate code (h, t, cs).
The action on basis strings of the classical gate code (false, t, cs): bit t flips when
every bit of cs is one. It is the identity when t is out of range, and a permutation when t
is not in cs (classicalStep_classicalStep).
The target of a well-formed classical code is not one of its controls.
The steps of classicalRun applied last to first: the inverse of classicalRun when
IsClassical m gs (classicalUnrun_classicalRun, classicalRun_classicalUnrun).
Classical codes that never read a written bit add to each bit the controls' values on the initial string, one for each code writing that bit.
Classical codes with distinct targets that no code reads flip each target exactly when the controls of its code are one on the initial string.
A well-formed classical code denotes a gate that maps |x⟩ to |classicalStep g x⟩.
A well-formed classical code reads each amplitude at the permuted basis string.
Swapping two qubits #
Three CNOT gates swapping wires left and right.
Swapping two distinct valid wires is a well-formed classical circuit.
For a ≠ 0, swap qubit a into qubit 0.
A classical circuit permutes basis states.
A classical circuit started in |x⟩ ends in |classicalRun gs x⟩.
A classical circuit reads amplitudes through the inverse permutation.
Measuring after a classical circuit is measuring before it and permuting the outcome.