function y = mydeutsch(f)
% Deutsch's algorithm in QIT
%! Author: Michel Barbeau
%! Version: January 31, 2016
%! f = bininary function, an array, e.g., [1 0]
% H gate creation
H=helper.H;
% Identity gate creation
I=helper.I;
% define the U gate
U=[ not(f(1)) f(1) 0 0 ; 
    f(1) not(f(1)) 0 0 ; 
    0 0 not(f(2)) f(2); 
    0 0 f(2) not(f(2)) ];
% convert to a "lmap"
Uf=lmap(U, {[ 2 2 ], [ 2 2 ]});
% Build the circuit
C=tensor(H,I)*Uf*tensor(H,H);
% Propagate input state through the circuit
reg=u_propagate(state('01'),C);
% Measure the first qubit
[~, b, ~]=measure(reg, 1);
% Return the result
y=b-1; % conversion to 0s and 1s

