Re: direct product of two sets

*To*: mathgroup at smc.vnet.net*Subject*: [mg53315] Re: [mg53264] direct product of two sets*From*: Richard Phillips <richardp at wolfram.com>*Date*: Wed, 5 Jan 2005 01:21:50 -0500 (EST)*Organization*: Wolfram Research*Sender*: owner-wri-mathgroup at wolfram.com

Hello Cong, There are two methods that come to mind: In[1]:= A={1, 2, 3}; In[2]:= B={x, y, z}; In[3]:= Tuples[{A, B}] Out[3]= {{1, x}, {1, y}, {1, z}, {2, x}, {2, y}, {2, z}, {3, x}, {3, y}, {3, z}} Note that Tuples is a new function introduced in Version 5.1. In[4]:= Flatten[Outer[List, A, B, 1], 1] Out[4]= {{1, x}, {1, y}, {1, z}, {2, x}, {2, y}, {2, z}, {3, x}, {3, y}, {3, z}} Other short programs will do this too, but I think these are the shortest. Best wishes, Richard Phillips Wolfram Research ps. http://mathworld.wolfram.com/CartesianProduct.html http://mathworld.wolfram.com/DirectProduct.html