simplify
-- simplify an
expressionsimplify
(f)
tries to simplify the
expression f
by applying term rewriting rules.
simplify
(f, target)
restricts the
simplification to term rewriting rules applicable to the target
function(s).
simplify(f <, target>)
simplify(l <, target>)
f |
- | an arithmetical expression |
l |
- | a set, a list, an array, or a polynomial of type DOM_POLY |
target |
- | one of the identifiers cos ,
sin , exp , ln , sqrt ,
logic, or relation |
an object of the same type as the input object f
or
l
, respectively.
f
, l
Without a target option, simplify
reacts to properties of identifiers.
Chapter ``Manipulating Expressions'' of the Tutorial.
collect
, combine
, expand
, factor
, match
, normal
, radsimp
, rectform
, rewrite
simplify
is
recursively applied to the operands of the expression. In this process,
the "simplify"
methods of the special functions contained
in the expression are called.simplify(
f)
implies all
simplifications that can be achieved with the targets sin
,
cos
, exp
, and ln
.simplify(
f, sqrt)
is equivalent
to radsimp
(f)
. With this
option, constant radical expressions are simplified.simplify(
l <, target>)
,
simplification is applied to the operands of the
object l
.sin
, cos
,
exp
, and ln
, only specific simplifications
such as rewriting of products of trigonometric or exponential terms
occur.sqrt
invokes radsimp
, i.e., simplification of
constant radicals occur. See radsimp
for details.simplify
tries to simplify algebraic
expressions:
>> simplify(exp(x)-exp(x/2)^2)
0
>> f := sin(x)^2 + cos(x)^2 + (exp(x) - 1)/(exp(x/2) + 1): simplify(f)
/ x \ exp| - | \ 2 /
Only special simplifications occur if special target functions are specified:
>> simplify(f, sin)
/ x \ exp(x) + exp| - | \ 2 / ----------------- / x \ exp| - | + 1 \ 2 /
>> simplify(f, exp)
2 2 / x \ cos(x) + sin(x) + exp| - | - 1 \ 2 /
>> delete f:
The option sqrt
serves for simplifying
radicals:
>> simplify(sqrt(4 + 2*sqrt(3)), sqrt)
1/2 3 + 1
>> x := 1/2 + sqrt(23/108): y := x^(1/3) + 1/3/x^(1/3): z := y^3 - y
/ / 1/2 1/2 \1/3 \3 | 1 | 3 23 | | | ------------------------- + | ---------- + 1/2 | | - | / 1/2 1/2 \1/3 \ 18 / | | | 3 23 | | | 3 | ---------- + 1/2 | | \ \ 18 / / / 1/2 1/2 \1/3 | 3 23 | 1 | ---------- + 1/2 | - ------------------------- \ 18 / / 1/2 1/2 \1/3 | 3 23 | 3 | ---------- + 1/2 | \ 18 /
>> simplify(z, sqrt)
1
>> delete x, y, z:
The option logic serves for simplifying Boolean expressions:
>> simplify((a and b) or (a and (not b)), logic)
a
User-defined functions can have "simplify"
attributes. For example, suppose we know that f is an
additive function (but we do not know more about f). Hence
we cannot compute the function value of f at any point
except zero, but we can tell MuPAD to use the additivity:
>> f := funcenv( x -> if iszero(x) then 0 else procname(x) end): f::simplify := proc(F) local argument; begin argument := op(F,1); if type(argument) = "_plus" then map(argument, f) else F end end:
>> f(x + 3*y) - f(3*y) = simplify(f(x + 3*y) - f(3*y))
f(x + 3 y) - f(3 y) = f(x)
We could still refine the "simplify"
attribute of f
such that it also turns f(3*y)
into 3*f(y)
. However, it is certainly a matter of taste
whether f(x)+f(y) is really simpler than f(x+y).
The reverse rule (rewriting f(x)+f(y) as f(x+y))
is not context-free and cannot be implemented in a
"simplify"
attribute.