$ -- create an expression
sequence
Introduction$a..b creates the sequence of integers from
a through b.
f $n creates the sequence f,
... , f consisting of n copies
of f.
f(i) $i = a..b creates the sequence f(a),
f(a+1), ... , f(b).
f(i) $i in object creates the sequence f(i1),
f(i2), ..., where i1, i2 etc. are the
operands of the object.
Call(s)
$a..b _seqgen(a..b)
f $n _seqgen(f, n)
f $i = a..b _seqgen(f, i, a..b)
f $i in object _seqin(f, i,
object)
Parametersf, object |
- | arbitrary MuPAD objects |
n, a, b |
- | integers |
i |
- | an identifier or a local
variable (DOM_VAR) of
a procedure |
Returnsan expression sequence of type "_exprseq" or the void object of type
DOM_NULL.
a..b, f, n, i,
object
Related
Functions
Details$ operator is a most useful tool. It serves for
generating sequences of objects. Sequences are used to define sets or lists, and may be
passed as arguments to system functions. Cf. example 1.$a..b and the equivalent function call
_seqgen(a..b) produce the sequence of integers a, a
+ 1, ... , b. The void object of type DOM_NULL is produced if a
> b.f $n and the equivalent function call _seqgen(f,
n) produce a sequence of n copies of the object
f. Note that f is evaluated only once, before
the sequence is created. The empty sequence of type DOM_NULL is produced if
n is not positive.f $i = a..b and the equivalent function call
_seqgen(f, i, a..b) successively substitute i =
a through i = b into f and evaluates
the results. The following expression sequence is produced:
eval(subs(f,i=a)), eval(subs(f,i=a+1)), ... , eval(subs(f,i=b)).f is not evaluated before the substitutions. The
void object of type DOM_NULL is produced if a
> b.f $i in object and the equivalent function call
_seqin(f, i, object) successively replace i
by the operands of the object: they substitute i =
op(object, 1) through i = op(object, n) into
f and evaluate the results (n = nops(object) is the number of
operands). The following expression sequence is produced:
eval(subs(f,i=op(object,1))), ... ,
eval(subs(f,i=op(object,n))).f is not evaluated before the substitutions. The
empty sequence of type DOM_NULL is produced if the
object has no operands.i in f $i = a..b
and f $i in object may have a value. This value is not
changed by using i inside a $ statement._seqgen is a function of the system kernel.
Example
1The following sequence can be passed as arguments to the
function _plus, which
adds up its arguments:
>> i^2 $ i = 1..5
1, 4, 9, 16, 25
>> _plus(i^2 $ i = 1..5)
55
The 5-th derivative of the expression
exp(x^2) is:
>> diff(exp(x^2), x $ 5)
2 3 2 5 2
120 x exp(x ) + 160 x exp(x ) + 32 x exp(x )
We compute the first derivatives of
sin(x):
>> diff(sin(x), x $ i) $ i = 0..5
sin(x), cos(x), -sin(x), -cos(x), sin(x), cos(x)
We use ithprime to compute the first
10 prime numbers:
>> ithprime(i) $ i = 1..10
2, 3, 5, 7, 11, 13, 17, 19, 23, 29
We select all primes from the set of integers between 1990 and 2010:
>> select({$ 1990..2010}, isprime)
{1993, 1997, 1999, 2003}
The 3 x 3 matrix with entries A[i,j] = i*j is generated:
>> n := 3: matrix([[i*j $ j = 1..n] $ i = 1..n])
+- -+
| 1, 2, 3 |
| |
| 2, 4, 6 |
| |
| 3, 6, 9 |
+- -+
>> delete n:
Example
2In f $n, the object f is
evaluated only once. The result is copied n times.
Consequently, the following call produces copies of one single random number:
>> random() $ 3
427419669081, 427419669081, 427419669081
The following call evaluates random for each value of of
i:
>> random() $ i = 1..3
321110693270, 343633073697, 474256143563
Example
3In the following call, i runs through the
list:
>> i^2 $ i in [3, 2, 1]
9, 4, 1
Note that the screen output of sets does not necessarily coincide with the internal ordering:
>> Set := {1, 2, 3, 4}: Set, [op(Set)]
{1, 2, 3, 4}, [4, 3, 2, 1]
The $ operator respects the internal
ordering:
>> i^2 $ i in Set
16, 9, 4, 1
>> delete Set:
Example
4Arbitrary objects f are allowed in f
$i = a..b. In the following call, f is an
assignment (it has to be enclosed in brackets). The sequence computes a
table f[i] = i!:
>> f[0] := 1: (f[i] := i*f[i - 1]) $ i = 1..4: f
table(
4 = 24,
3 = 6,
2 = 2,
1 = 1,
0 = 1
)
>> delete f:
i in f $i = a..b was not allowed to have a
value. Now, this variable may have a value.f $hold(i) = a..b were popular in
previous MuPAD versions. Now, hold is not necessary any longer,
because the loop variable may have a value. In fact, in the present
release, hold must not be
used for the loop variable in $.