REDUCE

11.1 SUB Operator

Syntax:

sub(\(\langle \)substitution_list\(\rangle \), \(\langle \)exprn1:algebraic\(\rangle \)) : algebraic

where \(\langle \)substitution_list\(\rangle \) is a list of one or more equations of the form

\(\langle \)var:kernel\(\rangle \) = \(\langle \)exprn:algebraic\(\rangle \)

or a kernel that evaluates to such a list.

The sub operator gives the algebraic result of replacing every occurrence of the variable var in the expression exprn1 by the expression exprn. Specifically, exprn1 is first evaluated using all available rules. Next the substitutions are made, and finally the substituted expression is reevaluated. When more than one variable occurs in the substitution list, the substitution is performed by recursively walking down the tree representing exprn1, and replacing every var found by the appropriate exprn. The exprn are not themselves searched for any occurrences of the various vars. The trivial case sub(exprn1) returns the algebraic value of exprn1.

Examples:

sub({x=a+y,y=y+1},x^2+y^2);

 2              2
a  + 2*a*y + 2*y  + 2*y + 1

and

s := {x=a+y,y=y+1}$

sub(s,x^2+y^2);

 2              2
a  + 2*a*y + 2*y  + 2*y + 1

Note that the global assignments x:=a+y, etc., do not take place.

exprn1 can be any valid algebraic expression whose type is such that a substitution process is defined for it (e.g., scalar expressions, lists and matrices). An error will occur if an expression of an invalid type for substitution occurs either in exprn or exprn1.

The braces around the substitution list may also be omitted, as in:

sub(x=a+y,y=y+1,x^2+y^2);

 2              2
a  + 2*a*y + 2*y  + 2*y + 1


Hosted by Download REDUCE Powered by MathJax