NEXT SUBSET

A basic combinatorial problem is to generate the 2n
subsets of the set {1, 2, ..., n}. For a given value of
n there are 2n subsets.

This command can be used to generate all of these subsets for
a given value of n. Each time this command is called for a
given value of n, the next subset is returned. Note that the
first call with a given value of n has a slightly different
syntax than the subsequent calls since the subsequent calls
need to specify the most recent subset generated.

The output is an array of zero and one values where zero
for the ith element of the set indicates the element is not
present and a value of one indicates the ith element is
present. For example, if n = 5 an output array of

1 0 0 1 1

specifies that elements 1, 4, and 5 are present while
elements 2 and 3 are not.

Syntax 1:

LET <y> = NEXT SUBSET <n>
where <n> is a number or parameter that specifies the size of
the set;
and <y> is a variable where the current
subset is saved.

This syntax is used to return the first subset in the sequence
of subsets.

Syntax 2:

LET <y> = NEXT SUBSET <n> <yprev>
where <n> is a number or parameter that specifies the size of
the set;
<yprev> is a variable that contains the most recently
generated subset for the given value of <n>;
and <y> is a variable where the current
subset is saved.

This syntax is used to return all subsets in the sequence
of subsets after the first subset has been generated.

Examples:

LET Y = NEXT SUBSET N
LET Y = NEXT SUBSET N YPREV

Note:

Dataplot implements this command using the algorithm NEXSUB
described in Nijenhuis and Wilf (see Reference section
below).

Note:

Dataplot saves the internal parameter LASTSEQU when this
command is entered. If LASTSEQU = 1, this indicates that
the current subset is the last subset in the sequence
for the given value of n. Otherwise, the value of LASTSEQU
will be set to 0.