The function opsubst
is similar to the function subst
, except that
opsubst
only makes substitutions for the operators in an expression. In
general, when f is an operator in the expression e, substitute
g for f in the expression e.
To determine the operator, opsubst
sets inflag
to true. This
means opsubst
substitutes for the internal, not the displayed, operator
in the expression.
To use this function write first load("opsubst")
.
Examples:
(%i1) load("opsubst")$ (%i2) opsubst(f, g, g(g(x))); (%o2) f(f(x)) (%i3) opsubst(f, g, g(g)); (%o3) f(g) (%i4) opsubst(f, g[x], g[x](z)); (%o4) f(z) (%i5) opsubst(g[x], f, f(z)); (%o5) g (z) x (%i6) opsubst(tan, sin, sin(sin)); (%o6) tan(sin) (%i7) opsubst([f=g, g=h], f(x)); (%o7) h(x)
Internally, Maxima does not use the unary negation, division, or the subtraction operators; thus:
(%i8) opsubst("+", "-", a-b); (%o8) a - b (%i9) opsubst("f", "-", -a); (%o9) - a (%i10) opsubst("^^", "/", a/b); a (%o10) - b
The internal representation of -a*b
is *(-1,a,b)
; thus
(%i11) opsubst("[", "*", -a*b); (%o11) [- 1, a, b]
When either operator isn’t a Maxima symbol, generally some other function will signal an error:
(%i12) opsubst(a+b, f, f(x)); Improper name or value in functional position: b + a -- an error. Quitting. To debug this try debugmode(true);
However, subscripted operators are allowed:
(%i13) opsubst(g[5], f, f(x)); (%o13) g (x) 5