Algosim documentation: ∏

∏ (n-ary product)

Computes the product of all elements in a container or in a sequence. The elements may be numbers or square matrices.

Syntax

Description

Computing the product of all elements in a container

If X is a container, then ∏(X) is the product of all elements in X.

The following container types are supported:

Typewise, the factors may be either real or complex, and the result is complex iff at least one of the factors is complex.

Computing the product of all elements in a sequence

∏(expr, var, a, b) computes the product of the expression expr in one variable var as var takes all integer values from a to b (inclusively). This precisely implements the pi notation for n-ary products.

expr must return a number or a matrix.

Notes

These note apply to both modes of operation: computing the product of all elements in a container and computing the product of all elements in a sequence.

The empty product is 1. Notice that the product of an empty collection of matrices is also equal to the scalar 1, because the system cannot tell that the collection indeed is an empty collection of matrices. And even if it could, it wouldn’t know the size of the matrices.

When computing the product of a collection of objects, the objects must be of the same kind (numbers or matrices). If they are matrices, they must all be of the same size.

Notice that is a function, not a prefix operator. Hence, to compute the product of all elements in a container X you must write ∏(X)∏X would be a syntax error.

You cannot compute the product of all matrices in a set because matrix multiplication is not commutative and a set is not an ordered container.

Examples

Computing the product of all elements in a container

∏(❨2, 1, 3, −4, 5, 2, 1, 3, −2❩)
1440
∏(❨❨4, 2, 1❩, ❨3, 2, 5❩❩)
240
∏('(❨❨1, 3❩, ❨2, 1❩❩, ❨❨−2, 1❩, ❨0, 3❩❩, ❨❨1, 0❩, ❨−1, i❩❩))
⎛−12  10⋅i⎞
⎝ −9  5⋅i ⎠
∏(unique(PrimeFactors(19871226)))
6623742

Computing the product of all elements in a sequence

abs(∏(1 − 1/prime(n)^2, n, 1, 100000) − 6/π^2)
3.11339510472⋅10^−8

See also