@menu
* Functions and Variables for opsubst::
@end menu

@node Functions and Variables for opsubst,  , opsubst-pkg, opsubst-pkg
@section Functions and Variables for opsubst

@anchor{opsubst_func}
@deffn {Function} opsubst @
@fname{opsubst} (@var{f},@var{g},@var{e}) @
@fname{opsubst} (@var{g}=@var{f},@var{e}) @
@fname{opsubst} ([@var{g1}=@var{f1},@var{g2}=@var{f2},..., @var{gn}=@var{fn}],@var{e})
The function @code{opsubst} is similar to the function @code{subst}, except that
@code{opsubst} only makes substitutions for the operators in an expression. In general, 
When @var{f} is an operator in the expression @var{e}, substitute @var{g} 
for @var{f} in the expression @var{e}.

To determine the operator, @code{opsubst} sets @code{inflag} to true. This means 
@code{opsubst} substitutes for the internal, not the displayed, operator
in the expression.

Examples:
@example
(%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)
@end example

Internally, Maxima does not use the unary negation,
division, or the subtraction operators; thus:
@example
(%i8) opsubst("+","-",a-b);
(%o8)                     a - b
(%i9) opsubst("f","-",-a);
(%o9)                      - a
(%i10) opsubst("^^","/",a/b);
                             a
(%o10)                       -
                             b
@end example

The internal representation of -a*b is *(-1,a,b); thus
@example
(%i11) opsubst("[","*", -a*b);
(%o11)                  [- 1, a, b]
@end example

When either operator isn't a Maxima symbol, generally some other function
will signal an error:
@example
(%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);
@end example

However, subscripted operators are allowed:
@example
(%i13) opsubst(g[5],f, f(x));
(%o13)                     g (x)
                            5
@end example

To use this function write first @code{load("opsubst")}.

@opencatbox
@category{Expressions}
@category{Share packages}
@category{Package opsubst}
@closecatbox

@end deffn

