function sancheck global nstate global lenseq global ALLSEQ global ALLSEQ1 nstate = 4; lenseq = 4; i0=1; m = nstate; global A C global CURE d = .01; nn = 0:lenseq-1; ALLSEQ = list_all_ind(repmat(nstate,1,lenseq)); ALLSEQ1 = list_all_ind(repmat(nstate,1,lenseq-i0+1)); T = 1000 for t=1:T %for t=1 A = pnormdim(rand(nstate,nstate,lenseq-1),1); h = strict(A); C = pnormdim(rand(nstate,1),1); while 1 dA = Ndiff('ER',2,{0,A,C}); dA = reshape(dA,[m m lenseq-1]); %dC = Ndiff('ER',3,{0,A,C}); %dC = reshape(dC,[m 1]); e = CURE; % check main condition H = sum(h.^nn); g = (sqrt(e)<=H+1e-10); if ~g 'REEEEEEEEEEEEAL PROBLEM!!!!' keyboard end % perhaps gradient has stopped changing? %if sum(sum(abs(dA)))+sum(abs(dC)) < 1e-7 if sum(sum(abs(dA))) < 1e-7 brstr = 'converged'; break end A = A + d*dA; A = A.*(A>=0); A = pnormdim(A+realmin,1); h1 = strict(A); if h1>h % we've violated the strict. constraint brstr = 'constraint'; break end %C = C + d*dC; %C = C.*(C>=0); %C = pnormdim(C,1); end fprintf('verified %5d out of %5d breaktype = %s\n',t,T,brstr); end return function r = F(x) global nstate %global lenseq if ~x(end), x=x(1:end-1); end; r = length(find(x~=1)); return function Ef = E(Xi) % E[f(X)|Xi] global ALLSEQ %global A Ef = 0; i = length(Xi); n = size(ALLSEQ,2); for k=1:size(ALLSEQ,1) x = ALLSEQ(k,:); p = P(x); if (i & (i