% Sum Circuit
% Author: Michel Barbeau
% Version: February 2, 2016
% Dependencies: Quantum Information Toolkit & helper.n
CNOT=helper.ACNOT;
H=helper.H;
I=helper.I;
SWAP=helper.SWAP;
%%
%%% SOLUTION 1
%%
% input
in=u_propagate(state('000'),tensor(H,H,I));
display(in);
% apply 1st CNOT
s0=u_propagate(in,tensor(I,CNOT));
% reorder qubits 1 & 2
s1=reorder(s0,[2 1 3]);
% apply 2nd CNOT
s2=u_propagate(s1,tensor(I,CNOT));
% reorder qubits 1 & 2
out=reorder(s2,[2 1 3]);
display(out);
%%
%%% SOLUTION 2
%
% gate that reorders qubits 1 and 2
R=tensor(SWAP,I);
C=tensor(I,CNOT)*R*tensor(I,CNOT)*R;
% input
in=u_propagate(state('000'),tensor(H,H,I));
display(in);
% apply gate
out=u_propagate(in,C);
display(out);
%%
%%% SOLUTION 3
%
% gate that reorders qubits 1 and 2
R=helper.R(1,3);
C=tensor(I,CNOT)*R*tensor(I,CNOT)*R;
% input
in=u_propagate(state('000'),tensor(H,H,I));
display(in);
% apply gate
out=u_propagate(in,C);
display(out);