On Mon, 26 Aug 2002 18:35:55 +0100, MacDonald Phillips <[log in to unmask]>
wrote:
>Is there a way to access the elements of a set similar to accessing the
>elements of a vector or matrix? The POWER_SET function is very powerful,
>but it cannot be used in programming because there is no way to access the
>subsets or elements of sets. For instance, I may want to know the
>combinations of four things taken two at a time and perform some
>calculations based on those combinations. POWER_SET(s,n) can tell me what
>the combinations are, but I can't do anything with them.
>
>It would be nice if this ability was added to the next version of DERIVE.
>
>Don PHillips
>[log in to unmask]
I guess asking a quesiton can really focus the mind. I came up with the
following routine that can take a set of elements or a set of sets and
convert it to a vector or a matrix.
SetToMatrix(s, v) :=
Prog
v := SORT(s)
If SET?(v sub(1))
VECTOR(SORT(v sub(i)), i, DIM(v))
v
Don Phillips
[log in to unmask]
|