matchlib::analyze
-- structure
of an expressionmatchlib::analyze
analyses the structure of any
expression.
matchlib::analyze(ex <option...>)
ex |
- | any MuPAD expression |
Const = set |
- | a set or list of expressions that will be taken as constants |
Cond = list |
- | a list of functions that will be taken to analyze the given expression |
Ident = ident |
- | an ident or the option Any |
an object of the type adt::Tree
match
, adt::Tree
, prog::exprtree
matchlib::analyze
expressions will be patitioned
and returned in tree structure as adt::Tree
.X, S,
L
. The first operand X
is the above describes
expression with the pattern variables as operands, the second operand
S
is a set of equations of the form ident =
expression
, whereby ident
is a generated pattern
variable and expression
the corresponding subexpression of
the original expression. The third operand L
is a list of
all operands of the partitioned expression, that was replaced by a
pattern variable.expose
. The operands can be taken
with the methods of the tree, which is an object of the type adt::Tree
.C
is a list of functions
that will be taken to analyze the given expression. Every function will
be called with the given expression (or a subexpression) and must be
return TRUE
or FALSE
(or an expression that will
be evaluated to this with bool
). The order of the functions in
the list C
determines the precedence to analyze the
expression.x
is an identifier or the option Any
(default). If an identifier will be given only expressions with this
identifier will be analyzed, all others will be taken as
constants.>> X:= a^2 + x^2: expose(matchlib::analyze(sin(X)/cos(X)))
1/X1*X2, {X1 = cos(a^2 + x^2), X2 = sin(a^2 + x^2)}, [cos(a^2 \ + x^2), sin(a^2 + x^2)] | +-- cos(X3), {X3 = a^2 + x^2}, [a^2 + x^2] | | | `-- X4^2 + X5^2, {X4 = a, X5 = x}, [a, x] | | | +-- a | | | `-- x | `-- sin(X6), {X6 = a^2 + x^2}, [a^2 + x^2] | `-- X7^2 + X8^2, {X7 = a, X8 = x}, [a, x] | +-- a | `-- x
Subexpression of the form a^2 + x^2
are
constant.
>> expose(matchlib::analyze(sin(X)/cos(X), Const = [X]))
1/X9*X10, {X9 = cos(a^2 + x^2), X10 = sin(a^2 + x^2)}, [cos(a^\ 2 + x^2), sin(a^2 + x^2)] | +-- cos(X12), {X12 = a^2 + x^2}, [a^2 + x^2] | `-- sin(X13), {X13 = a^2 + x^2}, [a^2 + x^2]
Only expressions of the type "_mult"
and
"_plus"
will be examined.
>> F:= X -> type(X) = "_mult" or type(X) = "_plus": T:= matchlib::analyze(sin(X)/cos(X), Cond = [F])
Tree3
>> expose(%)
X14*X15, {X15 = sin(a^2 + x^2), X14 = 1/cos(a^2 + x^2)}, [1/co\ s(a^2 + x^2), sin(a^2 + x^2)] | +-- 1/cos(a^2 + x^2) | `-- sin(a^2 + x^2)