2
Usage: The function 'opsubst' is similar to the function 'subst', except that
3
'opsubst' only makes substitutions for the operators in an expression. Specifically,
5
opsubst(f,g,e) --> When 'f' is an operator in the expression e, substitute 'g'
6
for 'f' in the expression 'e'.
7
opsubst(g=f,e) --> opsubst(f,g,e).
9
opsubst([g1=f1, g2=f2, ..., gn=fn],e) --> opsubst([g2=f2,...,gn=fn], opsubst(f1=f1, e)).
13
(%i1) opsubst(f,g,g(g(x)));
15
(%i2) opsubst(f,g,g(g));
17
(%i3) opsubst(f,g[x],g[x](z));
19
(%i4) opsubst(g[x],f, f(z));
21
(%i5) opsubst(tan, sin, sin(sin));
23
(%i6) opsubst([f=g,g=h],f(x));
26
To determine the operator, 'opsubst' sets 'inflag' to true. This means
27
'opsubst' substitutes for the internal, not the displayed, operator
28
in the expression. Internally, Maxima does not use the unary negation,
29
division, or the subtraction operators; thus:
31
(%i1) opsubst("+","-",a-b);
33
(%i2) opsubst("f","-",-a);
35
(%i3) opsubst("^^","//",a/b);
38
The internal representation of -a*b is *(-1,a,b); thus
40
(%i4) opsubst("[","*", -a*b);
44
When either operator isn't a Maxima symbol, generally some other function
47
(%i5) opsubst(a+b,f, f(x));
48
Improper name or value in functional position:b+a
50
However, subscripted operators are allowed:
52
(%i6) opsubst(g[5],f, f(x));
57
(defun $opsubst (&rest q)
59
(cond ((= 3 (length q)) (apply 'op-subst q))
62
(setq q (if ($listp (first q)) (margs (first q)) (list (first q))))
64
(if (op-equalp qi 'mequal) (setq e (op-subst ($rhs qi) ($lhs qi) e))
65
(merror "Expected an expression of the form `a = b'; instead found ~:M" qi))))
66
(t (wna-err '$opsubst)))))
68
(defun op-subst (f g e)
71
(mfuncall '$apply (if (like g ($op e)) f ($op e))
72
(cons '(mlist) (mapcar #'(lambda (s) (op-subst f g s)) (margs ($args e))))))))