MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

Cartesian Product the cute way



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






  • Prev by Date: Geometry`Polytopes` vs. Graphics`Polyhedra`
  • Next by Date: Rational approximations
  • Previous by thread: Geometry`Polytopes` vs. Graphics`Polyhedra`
  • Next by thread: Rational approximations