Actually you want to use a multiset, also called a bag.

Power set:
   ~.(<@#~ [:#:@i. 2^ #) 1 2 2 3 3
++-+---+-+---+-----+---+-----+-------+-+---+-----+---+-----+-------+-----+-------+---------+
||3|3 3|2|2 3|2 3 3|2 2|2 2 3|2 2 3 3|1|1 3|1 3 3|1 2|1 2 3|1 2 3 3|1 2 2|1 2 2 
3|1 2 2 3 3|
++-+---+-+---+-----+---+-----+-------+-+---+-----+---+-----+-------+-----+-------+---------+

Products:
    ~.(*/@#~ [:#:@i. 2^ #) 1 2 2 3 3
1 3 9 2 6 18 4 12 36


R.E. Boss


> -----Original Message-----
> From: Programming [mailto:[email protected]]
> On Behalf Of Skip Cave
> Sent: zondag 8 mei 2016 8:06
> To: [email protected]
> Subject: Re: [Jprogramming] Another Combination Problem
> 
> Well,
> 
> On second thought, I DO want the full set to be included in the
> subsets (Is THAT the universal set?) So the previous example, the set
> 1 2 2 3 3 should be in the output sets, but not the null set (though
> it is easy to get rid of the null set, if eliminating it in the
> function makes it too complex).
> 
> Skip
> Skip Cave
> Cave Consulting LLC
> 
> 
> On Sun, May 8, 2016 at 12:59 AM, Skip Cave <[email protected]>
> wrote:
> > Roger, Robert, Nollaig,
> >
> > Power Set! So THAT's what it is called! My Electrical Engineering math
> > courses in the '60s stopped at calculus and matrix algebra, and barely
> > touched on set theory, so I never knew that all the subsets of a set
> > had a name.
> >
> > In any case, I don't need the function to include the null set or the
> > universal set, so Nollaig's function looks like it would be what I
> > want.
> >
> >       psm =. ((] # 2:) #: >:@i.@(_2: + 2: ^ ])) #L:0"1 <@i.
> >       psmm=: (psm @#){ L:0 <@]
> >
> >       psmm  1 2 2 3 3
> >
> >
> ┌─┬─┬───┬─┬───┬───┬─────┬─┬───┬───┬─────┬───┬─────┬─────┬─
> ──────┬─┬───┬───┬─────┬───┬─────┬─────┬───────┬───┬─────┬─
> ────┬───────┬─────┬───────┬───────┐
> >
> > │3│3│3 3│2│2 3│2 3│2 3 3│2│2 3│2 3│2 3 3│2 2│2 2 3│2 2 3│2 2 3 3│1│1
> > 3│1 3│1 3 3│1 2│1 2 3│1 2 3│1 2 3 3│1 2│1 2 3│1 2 3│1 2 3 3│1 2 2│1 2
> > 2 3│1 2 2 3│
> >
> >
> └─┴─┴───┴─┴───┴───┴─────┴─┴───┴───┴─────┴───┴─────┴─────┴─
> ──────┴─┴───┴───┴─────┴───┴─────┴─────┴───────┴───┴─────┴─
> ────┴───────┴─────┴───────┴───────┘
> >
> > Looks right!
> >
> > Now how to I find the products of each subset?
> >
> >     prod psmm  1 2 2 3 3
> >
> > 3 3 9 2 6 6 18 2 6 6 18 4 12 .......
> >
> > Skip
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Sun, May 8, 2016 at 12:35 AM, Nollaig MacKenzie
> > <[email protected]> wrote:
> >> My terminal has garbled much of the output, so I
> >> drop the previous content.
> >>
> >> I use
> >>
> >>    psmn
> >>    ((] # 2:) #: >:@i.@(_2: + 2: ^ ])) #L:0"1 <@i.
> >>
> >> which gives the power set without the null set
> >> and the relative universal set.
> >>
> >> Then psmm=: (psm @#){ L:0 <@]
> >>
> >> would give what SC wanted (except for the null
> >> and universal).
> >>
> >> Wouldn't be fast, I think.
> >>
> >> On 2016.05.08 00:18:40, you,
> >>  the extraordinary Skip Cave, spake thus:
> >>
> >>> Nice! However, I realized that I didn't specify my problem in quite
> >>> enough detail. I need to keep duplicated integers in the final
> >>> sub-sets:
> >>
> >> --
> >> Nollaig MacKenzie
> >> ftp://ftp.nollaig.ca/pub/pap/
> >> ----------------------------------------------------------------------
> >> For information about J forums see
> http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to