Algosim documentation: ×

× (multiplication sign)

× is an operator that serves two distinct functions:

Syntax

Description and examples

Vector cross product

If u and v are three-dimensional (real or complex) vectors, then u × v is the vector cross product of u and v.

The product is complex iff at least one of the operands is complex.

a ≔ ❨4, 1, 2❩; b ≔ ❨1, 0, 2❩;
a × b
 ⎛2 ⎞
e⎜−6⎟
 ⎝−1⎠
a ≔ ❨4, 1, 2❩; b ≔ ❨1, 0, 2❩; c ≔ ❨−2, 1, −1❩;
(a | b × c)
−9

Cartesian product

If S1, S2, ..., Sn are sets, then S1 × S2 × ⋯ × Sn is the Cartesian product of S1, S2, ..., Sn.

{1, 2, 3} × {"a", "b", "c"} × {"!", "?"}
{(3, a, !), (1, c, ?), (2, a, ?), (1, b, ?), (3, c, !), (2, c, ?), (3, b, !), (1, a, !), (3, a, ?), (2, b, ?), (1, c, !), (2, a, !), (3, c, ?), (1, b, !), (3, b, ?), (1, a, ?), (2, c, !), (2, b, !)}
animals ≔ { "dog", "rat", "cat", "rabbit", "guinea pig" };
sexes = { "male", "female" };
animals × sexes
{(dog, female), (rat, male), (guinea pig, male), (cat, female), (rat, female), (rabbit, male), (guinea pig, female), (rabbit, female), (dog, male), (cat, male)}

The operator can also act on lists, which, unlike sets, are ordered containers.

The product will contain the elements in lexicographical order with the left-most list varying the fastest.

animals ≔ '( "dog", "rat", "cat", "rabbit", "guinea pig" );
sexes ≔ '( "male", "female" );
animals × sexes
(dog, male)
(rat, male)
(cat, male)
(rabbit, male)
(guinea pig, male)
(dog, female)
(rat, female)
(cat, female)
(rabbit, female)
(guinea pig, female)
ages ≔ '( "old", "young" );
animals × sexes × ages
(dog, male, old)
(rat, male, old)
(cat, male, old)
(rabbit, male, old)
(guinea pig, male, old)
(dog, female, old)
(rat, female, old)
(cat, female, old)
(rabbit, female, old)
(guinea pig, female, old)
(dog, male, young)
(rat, male, young)
(cat, male, young)
(rabbit, male, young)
(guinea pig, male, young)
(dog, female, young)
(rat, female, young)
(cat, female, young)
(rabbit, female, young)
(guinea pig, female, young)

Notes

The × operator is implemented by the cross function. CrossProduct is a distinct function that is equivalent to the restriction of cross to (two) vector operands.

If A is a set or a list and n a small positive integer, then A^n is equal to

A × ⋯ × A

the product containing exactly n factors.

See also