function M2 = reassign_alf_dfsa(M1,ALF2,MAP) % remap the alphabet of M1 to the new letters ALF2 % applying the MAP transformation % (not necessarily a one-to-one transformation) % M1.ALF, ALF2, MAP must all have same length % if MAP contains '@' then these characters are simply consumed % actually, I'm not sure how to deal with '@' so I'll leave it for later % OK, here's how we deal with '@': its preimage is a dead letter % meaning that if it's observed, we reject! l(1) = length(M1.ALF); l(2) = length(ALF2); l(3) = length(MAP); if ~all(l==l(1)) error('M1.ALF, ALF2, MAP must all have same length'); end M2 = M1; M2.ALF = ALF2; nQ1 = length(M1.Q); % deadlets cause all states to transit to dead state deadlets = setdiff(ALF2,MAP); dl = ~isempty(deadlets); nQ2 = nQ1+dl; % create an extra dead state for the dead letters M2.Q = 1:nQ2; M2 = init_ddelta(M2); if dl for s=deadlets M2 = set_ddelta(M2,M2.Q(1:end-1),repmat(s,[1,nQ1]),repmat(nQ2,[1,nQ1])); end % dead state transits to itself on all letters M2 = set_ddelta(M2,repmat(nQ2,[1,length(M2.ALF)]),M2.ALF,repmat(nQ2,[1,length(M2.ALF)])); end %PROGstart(nQ1*length(M1.ALF),'reassigning alphabet...') %cnt = 0; for q=M1.Q for si=1:length(M1.ALF) s = M1.ALF(si); r = dfsa_delta(M1,q,s); t = ALF2(si); t1 = MAP(si); %if (t1=='@') % % just consume t % M2 = set_ddelta(M2,q,t,q); %else M2 = set_ddelta(M2,q,t1,r); %end %cnt = cnt + 1; %PROGupdate(cnt); end end %PROGend; %M2 = minimize_dfsa(M2); return