SUB Operator
Date: 2020-10-07 18:10:00

Up | Next | Tail

### 11.1 SUB Operator

Syntax:

SUB(⟨substitution_list⟩,⟨EXPRN1:algebraic⟩) : algebraic

where ⟨substitution_list⟩ is a list of one or more equations of the form

⟨VAR:kernel⟩ = ⟨EXPRN:algebraic⟩

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. Speciﬁcally, EXPRN1 is ﬁrst evaluated using all available rules. Next the substitutions are made, and ﬁnally 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:

2 2
sub({x=a+y,y=y+1},x^2+y^2) -> A + 2*A*Y + 2*Y + 2*Y + 1

and with s := {x=a+y,y=y+1},

2 2
sub(s,x^2+y^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 deﬁned 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:

2 2
sub(x=a+y,y=y+1,x^2+y^2) -> A + 2*A*Y + 2*Y + 2*Y + 1

Up | Next | Front