Cartesian Product the cute way

*To*: mathgroup at yoda.physics.unc.edu*Subject*: Cartesian Product the cute way*From*: cfw2 at po.cwru.edu (Charles F. Wells)*Date*: Wed, 6 Jan 93 17:27:11 -0500

This is to brag about the following simple way to define the cartesian product of two sets represented as lists: In[1] := CartesianProduct[lists__] := Distribute[List[lists],List] In[2] := CartesianProduct[{a,b},{1,2,3},{x,y}] Out[2] = {{a, 1, x}, {a, 1, y}, {a, 2, x}, {a, 2, y}, {a, 3, x}, {a, 3, y}, {b, 1, x}, {b, 1, y}, {b, 2, x}, {b, 2, y}, {b, 3, x}, {b, 3, y}} Isn't that cute? Charles Wells Department of Mathematics Case Western Reserve University 10900 Euclid Avenue Cleveland, OH 44106-7058 216-368-2893