@ -- compose functions
Introductionf@g represents the composition x ->
f(g(x)) of the functions f and g.
Call(s)
f @ g @ ... _fconcat(f,
g...)
Parametersf, g... |
- | functions |
Returnsan expression of type "_fconcat".
f, g, ...
Related
Functions
DetailsDOM_PROC, function environments, or
functional expressions such as f@g@exp + id^2. In fact,
practically any MuPAD object may serve as a function.f @ g is equivalent to the function call
_fconcat(f, g)._fconcat() returns the identity map id; _fconcat(f) returns
f._fconcat is a function of the system kernel.
Example
1The following function h is the composition
of the system functions abs and sin:
>> h := abs@sin
abs@sin
>> h(x), h(y + 2), h(0.5)
abs(sin(x)), abs(sin(y + 2)), 0.4794255386
The following functional expressions represent polynomials:
>> f := id^3 + 3*id - 1: f(x), (f@f)(x)
3 3 3 3
3 x + x - 1, 9 x + 3 x + (3 x + x - 1) - 4
The random generator random produces nonnegative integers
with 12 digits. The following composition of float and random produces random floating point
numbers between 0.0 and 1.0:
>> rand := float@random/10^12: rand() $ k = 1..12
0.427419669, 0.3211106933, 0.3436330737, 0.4742561436,
0.5584587189, 0.7467538305, 0.03206222209, 0.7229741218,
0.6043056139, 0.7455800374, 0.2598119527, 0.3100754872
In conjunction with the function map, the composition operator
@ is a handy tool to apply composed functions to the
operands of a data structure:
>> map([1, 2, 3, 4], (PI + id^2)@sin),
map({1, 2, 3, 4}, cos@float)
2 2 2 2
[PI + sin(1) , PI + sin(2) , PI + sin(3) , PI + sin(4) ],
{-0.9899924966, -0.6536436209, -0.4161468366, 0.5403023059}
>> delete h, f, rand:
Example
2Some simplifications of functional expressions are
possible via simplify:
>> cos@arccos + exp@ln = simplify(cos@arccos + exp@ln)
cos@arccos + exp@ln = 2 id