What is the name for this Cartesian product-like operation?

686 Views Asked by At

I have two sets of multisets, like this:

a: { { 11, 21, 31, 41 }, { 12, 22, 32, 42 }, { 13, 23, 33, 43 } }

b: { { 21, 121, 131 }, { 22, 122, 132 } }

I'm combining them together into another set of multisets by joining each multiset in a with each multiset in b:

a (operation) b = { 
  { 11, 21, 31, 41, 21, 121, 131 },
  { 12, 22, 32, 42, 21, 121, 131 },
  { 13, 23, 33, 43, 21, 121, 131 },
  { 11, 21, 31, 41, 22, 122, 132 },
  { 12, 22, 32, 42, 22, 122, 132 },
  { 13, 23, 33, 43, 22, 122, 132 }
}

The closest thing I can think of to describe this is a Cartesian product, but that's not really accurate.

Is there a name for the operation I'm performing on a and b?


I just realized that this operation is the same as a cross join in SQL, and took a look at some documentation on cross join to see how people describe that. Some docs for SQL Server describe it as "the Cartesian product of the tables involved in the join." Oracle's docs, Wikipedia, and others all describe it essentially the same way.

Is Cartesian product a correct name for this after all?

1

There are 1 best solutions below

5
On BEST ANSWER
a = [[11, 21, 31, 41 ], [12, 22, 32, 42 ], [ 13, 23, 33, 43 ]]
b = [[ 21, 121, 131 ], [ 22, 122, 132 ] ]
︡︠[a[i]+b[j] for i in range (0,len(a))  for j in range (0,len(b))]

#gives the desired result on SAGE;

[[11, 21, 31, 41, 21, 121, 131], [11, 21, 31, 41, 22, 122, 132], [12, 22, 32, 42, 21, 121, 131], [12, 22, 32, 42, 22, 122, 132], [13, 23, 33, 43, 21, 121, 131], [13, 23, 33, 43, 22, 122, 132]]

you may also name the result, and check the size;

a = [[11, 21, 31, 41 ], [12, 22, 32, 42 ], [ 13, 23, 33, 43 ]]
b = [[ 21, 121, 131 ], [ 22, 122, 132 ] ]
︡︠L = [a[i]+b[j] for i in range (0,len(a))  for j in range (0,len(b))]
len(L)

gives you the output 6.