Atom - p - Cartesian Product

Characters: p

Tags: array , combinatorics

Arity: dyadic

This atom is dyadic, which means it takes two arguments.

Functionality

Return a list of all pairs of elements from x and y.

Details

Rather than returning a table, cartesian product returns a flat list of pairs (it is not really flat because its elements are pairs, but for two flat lists, it will return a depth-2 list rather than a depth-3 list). Elements are ordered firstly by order in x and then in y. The left argument is cast to a singleton list, but the right argument is cast to a range. For example, 1,2 p 3,4 gives [[1, 3], [1, 4], [2, 3], [2, 4]], 1 p 2,3 gives [[1, 2], [1, 3]], and 1,2 p 3 gives [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3]].