
subsex - expanded substitution of subexpressions

Calling sequence:

subsex(expr, subsexpr... [ , Unsimplified ])
subsexpr      --->  [ subsequation ...]
subsexpr      --->  subsequation
subsequation  --->  expr_1 = expr_2

Parameter:
expr            --   expression
expr_1, expr_2  --   expressions
Unsimplified    --   option

Overloading:

1

Summary:

subsex substitutes subexpressions of expr. In contrast to the function subs,
subsex also replaces incomplete subexpressions, e.g. a+3 in a+b+3. However,
in contrast to subs, subsex is much slower, because the expressions have to
be looked through entirely.

The simplest call of subsex is in the form subsex(expr, expr_1 = expr_2)
of the substitution equation expr_1 = expr_2. Here all subexpressions with

the form expr_1 in the expression expr are substituted by the expression
expr_2.

As in the function subs, the arguments of subsex are substitution equations
or listsof them. The arguments are processed in sequence from left to right:

  o  If the argument is a single substitution equation then the substitution is
     carried out and the result of this substitution is then processed further.

  o  If the argument is a list of substitution equations then all the substitutions
     in the list (seen logically) are carried out simultaneously (parallel substitution).

In general, after substitution the expression is simplified.  Sometimes it is
desirable to avoid this simplification.  This can be achieved by using the
option Unsimplified. subsex uses a copy of expr, thus the argument expr
remains unchanged. subsex is a kernel function.

>>  subsex(a+b*c*d+b*d, b*d=c);

      a + c + c^2

>>  subsex(a+b*c*x, b*c=x, x=a);

      a + a^2

>>  subsex(a+b*c*x, [b*c=x, x=a]);

      a + a*x

>>  subsex(a+b+c, [a+c=x, b+c=y]);

      b + x

>>  subsex(a+b+c, a+c=0, b=1, Unsimplified);

      1 + 0

See also:  op, subs, subsop

