Algosim documentation: compute

compute

Computes values of an expression in any number of variables and stores them in a nested list.

Syntax

Description

The compute function evaluates an expression in n variables at the integer points inside an n-orthotope. The obtained values are returned as a nested list of depth n.

expr is an expression optionally containing the variables x1, x2, ... xn. Each such variable xk is evaluated from ak to bk. The result X has X[ξ1][ξ2][⋯][ξn] equal to the value of expr when x1 = ξ1 − a1, x2 = ξ2 − a2, ..., xn = ξn − an.

expr may evaluate to any kind of object, and the type need not be the same for every combination of the variables. The result may be a list of five pixmaps, two sounds, and one complex matrix.

Notice that the result may be cast to a vector if n = 1 and to a matrix if n = 2, assuming expr always evaluate to a number.

Examples

compute(n!, n, 1, 5)
1
2
6
24
120
matrix(compute(a⋅b, a, 1, 12, b, 1, 12))
⎛  1    2    3    4    5    6    7    8    9   10   11   12⎞
⎜  2    4    6    8   10   12   14   16   18   20   22   24⎟
⎜  3    6    9   12   15   18   21   24   27   30   33   36⎟
⎜  4    8   12   16   20   24   28   32   36   40   44   48⎟
⎜  5   10   15   20   25   30   35   40   45   50   55   60⎟
⎜  6   12   18   24   30   36   42   48   54   60   66   72⎟
⎜  7   14   21   28   35   42   49   56   63   70   77   84⎟
⎜  8   16   24   32   40   48   56   64   72   80   88   96⎟
⎜  9   18   27   36   45   54   63   72   81   90   99  108⎟
⎜ 10   20   30   40   50   60   70   80   90  100  110  120⎟
⎜ 11   22   33   44   55   66   77   88   99  110  121  132⎟
⎝ 12   24   36   48   60   72   84   96  108  120  132  144⎠
compute(❨sin(t/100), cos(t/100), t/100❩, t, 1, 100) \5
(0.00999983333417, 0.999950000417, 0.01)
(0.0199986666933, 0.999800006667, 0.02)
(0.0299955002025, 0.999550033749, 0.03)
(0.0399893341866, 0.999200106661, 0.04)
(0.0499791692707, 0.998750260395, 0.05)
⋮
compute(Mertens(a)⋅b^c, a, 1, 10, b, 1, 5, c, 0, 2)
((1, 1, 1), (1, 2, 4), (1, 3, 9), (1, 4, 16), (1, 5, 25))
((0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0))
((−1, −1, −1), (−1, −2, −4), (−1, −3, −9), (−1, −4, −16), (−1, −5, −25))
((−1, −1, −1), (−1, −2, −4), (−1, −3, −9), (−1, −4, −16), (−1, −5, −25))
((−2, −2, −2), (−2, −4, −8), (−2, −6, −18), (−2, −8, −32), (−2, −10, −50))
((−1, −1, −1), (−1, −2, −4), (−1, −3, −9), (−1, −4, −16), (−1, −5, −25))
((−2, −2, −2), (−2, −4, −8), (−2, −6, −18), (−2, −8, −32), (−2, −10, −50))
((−2, −2, −2), (−2, −4, −8), (−2, −6, −18), (−2, −8, −32), (−2, −10, −50))
((−2, −2, −2), (−2, −4, −8), (−2, −6, −18), (−2, −8, −32), (−2, −10, −50))
((−1, −1, −1), (−1, −2, −4), (−1, −3, −9), (−1, −4, −16), (−1, −5, −25))

See also