longd1_function(ps,pss,pff,n,d) { #this program compute the probability P(N(n,d)=0)# #i.e., the number of non-overlapping type 1 runs having at most 1 type 0 # #under given initial ps and pf with length d is zero.d=#1+#0# NN_((1+d)*d/2)+1 pf_1-ps psf_1-pss pfs_1-pff c0_matrix(0,1,NN-1) p0_cbind(1,c0) c1_matrix(1,NN-1,1) U_rbind(c1,0) M_matrix(0,NN,NN) for(ir in 0:(d-1)) { for(jr in 0:ir){ for(ic in 0:(d-1)) { for(jc in 0:ic){ rid_((ir+1)*ir/2)+jr+1 cid_((ic+1)*ic/2)+jc+1 if( ir>0 && jr==0 && ic==ir+1 && jc==0){M[rid,cid]_pss} if(jr>1 && ic==ir+1 && jc==jr+1){M[rid,cid]_pss} if(ir>0 && ic==ir+1 && jr==0 && jc==1){M[rid,cid]_psf} if(jr>0 && ic==jr && jc==1){M[rid,cid]_psf} if(ir>0 && jr==1 && ic==1 && jc==1){M[rid,cid]_pff} if(ir>0 && jr==1 && ic==ir+1 && jc==2){M[rid,cid]_pfs} if(ir==0 && jr==0 && ic==1 && jc==0){M[rid,cid]_ps} if(ir==0 && jr==0 && ic==1 && jc==1){M[rid,cid]_pf} }}}} for(i in 1:NN) { M[i,NN]_1-sum(M[i,]) } Mn_M%*%M for (i in 3:n) {Mn_Mn%*%M } 1-p0%*%Mn%*%U }