Re: multiplying sets

*To*: mathgroup at smc.vnet.net*Subject*: [mg2969] Re: multiplying sets*From*: Jorma.Virtamo at vtt.fi (Jorma Virtamo)*Date*: Wed, 17 Jan 1996 03:09:50 -0500

Tommi Salminen <titosa at uta.fi> wrote: > > I have a problem as follows: > > I have a set, for instance: s={{a,b,c},{d,e},{f,g}}, and I would like > to get a set t, that includes all possible multiplications between > those three sets {a,b,c}, {d,e} and {f,g}. > > Of course, one way would be : > > Outer[Times,{a,b,c},{d,e},{f,g}], but I'd like find some kind > of a more reasonable way to do it, because it would be just a part > of a larger program. Anyway, it doesn't have to be some elegant way; > if it works, it's OK. > I don't know what is wrong with the Outer. If you define s1={a,b,c}; s2={d,e}; s3={f,g}; then Outer yields: Outer[Times,s1,s2,s3] // Flatten {a d f, a d g, a e f, a e g, b d f, b d g, b e f, b e g, c d f, c d g, c e f, c e g} Another way to write the same is for instance: s3#& /@ s2#& /@ s1 // Flatten with an identical result: {a d f, a d g, a e f, a e g, b d f, b d g, b e f, b e g, c d f, c d g, c e f, c e g} Whether this is more reasonable way to write the expression is rather a matter of taste. Personally, I would prefer Outer, which also seems to be faster. Maybe you want something faster than Outer? -- Jorma Virtamo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Jorma Virtamo VTT Information Technology phone: +358 0 456 5612 Telecommunications fax: +358 0 455 0115 P.O. Box 1202 email: jorma.virtamo at vtt.fi FIN-02044 VTT web: http://www.vtt.fi/tte/ Finland ==== [MESSAGE SEPARATOR] ====