function M = randlt(alf,minidlen,maxidlen,minnumids,maxnumids) % outputs a random locally testable language % by computing a random boolean function of random shuffle ideals % minidlen = minimal ideal length % maxidlen = maximal ideal length (smaller => simpler language) % minnumids = minimal total of ideals in the number boolean expression % maxnumids) = maximal number of ideals (smaller => simpler language) S = {}; MM = {}; numids = round(randinseg(minnumids,maxnumids)); for i=1:numids u = get_datum_unique(alf,minidlen,maxidlen,S) S{i} = u; %if isempty(u) % u = '@'; %end fprintf('processing U = %s \n',u); % just do n-grams M = midl2dfsa(u,alf); if 0 r = rand; if r<1/3 % prefix M = pref2dfsa(u,alf); elseif r<2/3 % suffix M = suff2dfsa(u,alf); else % inside M = midl2dfsa(u,alf); end end MM{i} = M; end ii = randperm(numids); ii=ii(:)'; M = MM{ii(1)}; if flip M = negate_fsa(M); end for i=ii(2:end) Mi = MM{i}; if flip Mi = negate_fsa(Mi); end if flip M = union_dfsa(M,Mi); else M = intersect_dfsa(M,Mi); end end % as a bit of clean-up: % a loc-test language never contains the empty string: M = intersect_dfsa(M,negate_fsa(str2dfsa('',alf))); return function r = randinseg(a,b) r = rand*(b-a) + a; return function b=flip b = round(rand); return function x = get_datum_unique(alf,minidlen,maxidlen,PREV) good = 0; na = length(alf); while ~good n = round(randinseg(minidlen,maxidlen)); x = alf(ceil(rand(1,n)*na)); good = isempty(strmatch(x,PREV,'exact')); end return