/************** Subsets of a Matrix *************************
Authors: Thomas Noack <noack@hermes1.econ.uni-hamburg.de>
                Georg-Thielen-Gasse 15
                22303 Hamburg
                thomas-noack@hamburg.de
                www.nucch.de
          Alan G. Isaac (a few modifications)
Date: 16 Mar 01
Purpose: Generating all the subsets of a set
Caveat: this code is supplied gratis but without warrantee.

Comments:  Assumes numeric data, but easily modified.
************************************************************/

proc (1) = subsets(v);
  local m,n,b,s;
  v=unique(vecr(v),1);
  m=rows(v);
  n=seqa(0,1,2^m);  @ numbers for the subsets @
  b=rev(recserrc(n,reshape(2,m,2^m)))'; @ binary version of n @
  s=miss(b.*v',0);  @ ..every row of s contains one subset of v @
                        @ including the empty and the full (sub)set @
retp(s);
endp;

