Tweaking verb allsubsets follows the quote.
Fraser Jackson wrote:
> In additon to the functions in Dan's post you might want something like the
> following, probably with some tweaking.
>
> Set =: (/:~)@~. NB. sorted nub
> isin =: *./ @ e.
> isequalset =: isin~ *. isin
> ispropersubset =: < & (#...@~.)
> isemptyset =: 3 : 'if. isboxed y do. y=a: else. isempty y end.'
> isdisjoint =: (-...@in) *. (-.@ (in~))
>
> allsubsets =: 3 : 0 NB. An explicit alternative to Raul's neat form.
> if. isemptyset y do. a:
> else.
> (#&y) &.> ( <"1 (#: i.2^#y))
> end.
> )
When I ran allsubsets I found isboxed and isempty in isemptyset undefined, so I
renamed Dan's isEmpty and defined isboxed:
isempty =: -: 0&#
isboxed =: 0 < L.
Then
] a =: Set 'baa' NB. as expected:
ab
allsubsets a NB. order is wrong: "numeric" order of masks in verb
++-+-+--+
||b|a|ab|
++-+-+--+
Set allsubsets a NB. correct order: "alpha" order from /:~
++-+--+-+
||a|ab|b|
++-+--+-+
pwrset a NB. pwrset is allsubsets with /:~ inserted, see below
++-+--+-+
||a|ab|b|
++-+--+-+
pwrset =: 3 : 0 NB. allsubsets with sort /:~ added
if. isemptyset y do. a:
else.
/:~ (#&y) &.> ( <"1 (#: i.2^#y))
end.
)
Kip
P.S. I would like to see verb isin renamed ispart because the name isin
suggests
"iselement" (e.) to me. "ispart" is my attempt at an everyday name for
issubset, which is what verb isin is, very neatly.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm