abs
-- the absolute value of a real
or complex numberabs(
z)
returns the absolute value of the
number z
.
abs(z)
z |
- | an arithmetical expression |
an arithmetical expression.
z
abs
respects properties of identifiers.
abs
returns the
absolute value as an explicit number or expression. Cf. example 1.abs
is returned if the absolute
value cannot be determined (e.g., because the argument involves
identifiers). The result is subject to certain simplifications. In
particular, abs
extracts constant factors. Properties of
identifiers are taken into account. Cf. examples 2 and 3.expand
function
rewrites the absolute value of a product to a product of absolute
values. E.g., expand(abs(x*y))
yields
abs(x)*abs(y)
. Cf. example 4.CATALAN
, E
, EULER
, and PI
are processed by abs
. Cf.
example 5."abs"
of function
environments. Cf. example 7.For many constant expressions, the absolute value can be computed explicitly:
>> abs(1.2), abs(-8/3), abs(3 + I), abs(sqrt(-3))
1/2 1/2 1.2, 8/3, 10 , 3
>> abs(sin(42)), abs(PI^2 - 10), abs(exp(3) - tan(157/100))
2 -sin(42), 10 - PI , tan(157/100) - exp(3)
>> abs(exp(3 + I) - sqrt(2))
2 2 1/2 2 1/2 (sin(1) exp(3) + (cos(1) exp(3) - 2 ) )
Symbolic calls are returned if the argument contains identifiers without properties:
>> abs(x), abs(x + 1), abs(sin(x + y))
abs(x), abs(x + 1), abs(sin(x + y))
The result is subject to some simplifications. In
particular, abs
splits off constant factors in
products:
>> abs(PI*x*y), abs((1 + I)*x), abs(sin(4)*(x + sqrt(3)))
1/2 1/2 PI abs(x y), abs(x) 2 , - sin(4) abs(x + 3 )
abs
is sensitive to properties of
identifiers:
>> assume(x < 0): abs(3*x), abs(PI - x), abs(I*x), abs(x + I)
2 1/2 -3 x, PI - x, -x, (x + 1)
>> unassume(x):
The expand
function produces products of
abs
calls:
>> abs(x*(y + 1)), expand(abs(x*(y + 1)))
abs(x (y + 1)), abs(x) abs(y + 1)
The absolut value of the symbolic constants PI
, EULER
etc. are known:
>> abs(PI), abs(EULER + CATALAN^2)
2 PI, EULER + CATALAN
Expressions containing abs
can be
differentiated:
>> diff(abs(x), x), diff(abs(x), x, x)
sign(x), 2 dirac(x)
The slot "
abs" of a
function environment f
defines the absolute value of
symbolic calls of f
:
>> abs(f(x))
abs(f(x))
>> f := funcenv(f): f::abs := x -> f(x)/sign(f(x)): abs(f(x))
f(x) ---------- sign(f(x))
>> delete f:
The slot "
abs" of a
domain d
defines the absolute value of its elements:
>> d := newDomain("d"): e1 := new(d, 2): e2 := new(d, x): abs(e1), abs(e2)
abs(new(d, 2)), abs(new(d, x))
>> d::abs := x -> abs(extop(x, 1)): abs(e1), abs(e2)
2, abs(x)
>> delete d, e1, e2: