function [w]=gatecount(n) %plots the discrepancy between the weight produced G=zeros(n,n); %G(r,k) is the number of r-qubit gates with k-1 controls in our decomposition H=zeros(n,n); %H(r,k) is the number of r-qubit gates with k-1 controls in the Finnish paper W=zeros(n,n); %weight matrix column k of G*W is column k of G times (k-1) %s=zeros(2,n); %s(1,r) is the total number of controlled gates used in %decomposing U in G_r (our paper) %s(2,r) is the total number of controlled gates used in %decomposing U in G_r (Finnish paper) %s(1,r)=s(2,r)=2^{r-1}(2^r-1) for all r w=zeros(2,n); %w(1,r)=T_1(r) and w(2,r)=T_2(r) as described in our conclusion for r=1:n W(r,r)=r-1; G(r,1)=r; H(r,1)=2^(r-1); if r>1 G(r,2)=r*(r-1)*(2^(r-2)+1); for k=2:r H(r,k)=H(r-1,k)+H(r-1,k-1)+ max([2^(r-2),2^(k-1)])+ 2^(2*r-k-1)-2^(r-2); end end if r>2 G(r,3)=(1/3)*(4^r-4)-(2^r)*(r-1)+r*(r-1)*(r-2)/2; end if r>3 for k=4:r G(r,k)=G(r-1,k)+G(r-1,k-1)+ nchoosek(r-1,k-1); end end %s(1,r)=sum(G(r,:)); %s(2,r)=sum(H(r,:)); V=G*W; X=H*W; w(1,r)=sum(V(r,:)); w(2,r)=sum(X(r,:)); end x=1:n; plot(x,log10(w(2,:)-w(1,:)),'LineWidth', 2); ylabel('T2(n)-T1(n) in logarithm base 10'); xlabel('n'); title('Comparison of the total number of controls of our scheme and that of [7]')