Page 1 of 1

enumerate all subsets of a set

Posted: Wed Jun 23, 2021 3:58 pm
by abhosekar
An easy way to get this is using powerset system attribute. Here, we want all subsets of the set i. We know that there are 2**card(i) subsets of the set i. We use a set j containing two elements and system.powersetright to create a set IJ0. Any column of IJ0 is a powerset IJ as shown by display statement.

Code: Select all

sets
    I		/ i1 * i3 /
;
Scalar nsubsets;

$eval nsubsets power(2, card(I))
Sets
  J		/ j1 * j2/
  nsets /n1*n%nsubsets%/
  IJ0(nsets,i,j) / system.powersetRight /
  IJ(nsets,i) 'power set'
;
IJ(nsets, i) = IJ0(nsets, i, 'j1');

display IJ;