
subs - substitution of complete subexpressions

Calling sequence:

subs(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:

subs substitutes subexpressions of the expressionexpr.  The simplest call
of subs is in the form subs(expr, expr_1=expr_2) with the substitutions
specified in form of equations expr_1=expr_2. With this every subexpression
of the form expr_1 in expression expr is substituted by the expression expr_2.

The arguments of subs are substitution equations or listsof substitution
equations. 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  However, if the argument is a list of substitution equations then all
     substitutions in the list (seen logically) are carried out simultaneously.
     The result of these substitutions is then processed further with the
     next argument.  (See examples 2 and 3.)  This is also called parallel
     substitution.

With subs only complete subexpressions are substituted.  These are the
subexpressions obtained with the function op. If the user wishes to substitute
an incomplete subexpression, like a+3 in a+b+3, then the function subsex has
to be used.

In general, a simplificationof the expression is carried out after substitution.
Sometimes it is desirable to avoid simplification. This can be achieved with
the option Unsimplified. subs uses a copy of expr, thus the argument expr
remains unchanged. subs is a kernel function.

>>  subs(a*(b+c), b+c=a);

      a^2

>>  subs(a+x, a=x+y, x=z);

      y + z*2

>>  subs(a+x, [a=x+y, x=z]);

      x + y + z

>>  subs(a+x, [a=x+y, x=z], x=y);

      y*2 + z

>>  subs(a+b+c, a+b=x);

      a + b + c

>>  subs(a+b+2, a=1, b=0, Unsimplified);

      1 + 0 + 2

See also:  op, subsop , subsex

