Re: I'm looking for an algorithm: Cartesian Product

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg1663] Re: I'm looking for an algorithm: Cartesian Product
• From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
• Date: Tue, 11 Jul 1995 03:57:13 -0400
• Organization: University of Colorado, Boulder

```In article <3ti27l\$klt at news0.cybernetics.net>,
Hala Skaf <Hala.Skaf at loria.fr> wrote:
>
>Hello,
>
>     I'm looking for an algorithm that can compute
> Cartesian Product for several sets. For example:
>
> How can I compute the Cartesian Product of:
>
>	E1={a1 a2} E2={b1 b2 b3} E3={z1 z2}
>
In[3]:=
Outer[List, {a1, a2}, {b1, b2, b3}, {z1, z2}]
Out[3]=
{{{{a1, b1, z1}, {a1, b1, z2}},
{{a1, b2, z1}, {a1, b2, z2}},
{{a1, b3, z1}, {a1, b3, z2}}},
{{{a2, b1, z1}, {a2, b1, z2}},
{{a2, b2, z1}, {a2, b2, z2}},
{{a2, b3, z1}, {a2, b3, z2}}}}

In[4]:=
Flatten[%, 2]
Out[4]=
{{a1, b1, z1}, {a1, b1, z2}, {a1, b2, z1},
{a1, b2, z2}, {a1, b3, z1}, {a1, b3, z2},
{a2, b1, z1}, {a2, b1, z2}, {a2, b2, z1},
{a2, b2, z2}, {a2, b3, z1}, {a2, b3, z2}}

Dave Wagner
Principia Consulting
(303) 786-8371
dbwagner at princon.com
http://www.princon.com/princon

```

• Prev by Date: Re: Download from Mathsource
• Next by Date: Re: Options in self-defined functions
• Previous by thread: I'm looking for an algorithm: Cartesian Product
• Next by thread: Re: I'm looking for an algorithm: Cartesian Product