function M=prune_eps(M) % a technical routine to disconnect unnecessary states for q=M.Q E = just_eps(q,M); if (length(E)==1) %there is exactly one exclusive epsilon-child M = replace(q,E(1),M); end end return function set1 = setrepl(set1,p,q) %replace all occurrences of p w/q in set1 if ~isempty(set1) set1(find(set1==p)) = q; end return function M = replace(q1,p1,M) % make everything that pointed to q now point to p M.q0 = setrepl(M.q0,q1,p1); M.F = setrepl(M.F ,q1,p1); for q = M.Q for s = M.ALF R = nfsa_delta(M,q,s); R = setrepl(R,q1,p1); M = set_ndelta(M,[q],[s],{R}); end end return function E = just_eps(q,M) % if the only transitions out of q are epsilon-transitions % E is a list of q's children % otherwise, E is empty E = nfsa_delta(M,q,'@'); if (length(E)==1) % it's a candidate for s=M.ALF(2:end) R = nfsa_delta(M,q,s); if ~isempty(R) % other children -- abort E = []; break; end end end