% Teleportation Example
% Author: Michel Barbeau
% Version: February 7, 2016
% Dependency: Quantum Information Toolkit and helper.m
% qubit to teleport
%phi=state('0');
%phi=state('1'); phi=state([-1 0]); phi=state([0 -1]); 
phi=state([-1/sqrt(2) 1/sqrt(2)]); phi=fix_phase(u_propagate(state('0',2), rand_SU(2)));
display(phi);
% ebit creation
psi=helper.ebit(state('00'));
display(psi);
% combine with phi
r1=tensor(phi,psi);
display(r1);
% measurement preparation
r2=u_propagate(r1,tensor(helper.prep,helper.I));
display(r2);
% measurement
[~, b1, r3]=measure(r2, 1); b1=b1-1;
[~, b2, r4]=measure(r3, 2); b2=b2-1;
display(r4);
% conditional X gate
I3=helper.power(helper.I,3);
IIX=tensor(helper.I,helper.I,helper.X);
r5=u_propagate(r4,b2*IIX+double(~b2)*I3);
display(r5);
% conditional Z
IIZ=tensor(helper.I,helper.I,helper.Z);
r6=u_propagate(r5,b1*IIZ+double(~b1)*I3);
display(r6);


