function b = is_aperiodic(S) % is the monoid S aperiodic? b = 1; [n,n] = size(S); for i=1:n x = i; if (S(x,x)~=x) %element not idempotent for k=1:n x1 = S(x,i); if (x1==i) % periodic b = 0; break elseif (x1==x) break end x = x1; end end if ~b break end end return