CoCoA:CartesianProduct, CartesianProductList

From ApCoCoAWiki
Revision as of 10:02, 24 October 2007 by XMLBot (talk | contribs) (pushing XML rev. 1.46, again)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

CartesianProduct, CartesianProductList

Cartesian product of lists

Description

This command returns the list whose elements form the Cartesian product

of <formula>L_1,...,L_n</formula>.

For the N-fold product of a list with itself, one may use <ttref>Tuples</ttref>.

Example

  L1 := [1,2,3];
  L2 := [<quotes>a</quotes>,<quotes>b</quotes>];
  L1 &gt;&lt; L2 &gt;&lt; [5];  -- same as
  CartesianProduct(L1, L2, [5]);  -- same as
  CartesianProductList([L1, L2, [5]]);  -- this takes a lists of lists
[[1, <quotes>a</quotes>, 5], [1, <quotes>b</quotes>, 5], [2, <quotes>a</quotes>, 5], [2, <quotes>b</quotes>, 5], [3, <quotes>a</quotes>, 5], [3, <quotes>b</quotes>, 5]]
-------------------------------
  ChessBoard := (1..8)&gt;&lt;(1..8); -- Need brackets around 1..8 otherwise
                                -- we get a parse error.

Note that only <> is used for not equal in CoCoA.

Syntax

L_1 &gt;&lt; ... &gt;&lt; L_n

where each L_i is a list.

CoCoA Operators

Tuples

Shortcuts

   <type>list</type>