algsubs - substitute subexpressions into an expression
|
Calling Sequence
|
|
algsubs(a = b, f)
algsubs(a = b, f, v)
algsubs(a = b, f, v, options)
|
|
Parameters
|
|
a, b
|
-
|
algebraic expressions
|
f
|
-
|
any expression
|
v
|
-
|
name or list or set of names
|
|
|
|
|
Description
|
|
•
|
The function algsubs performs an algebraic substitution, replacing occurrences of a with b in the expression f. It is a generalization of the subs command, which only handles syntactic substitution. The purpose of algsubs can be seen from these five examples where subs fails.
|
>
|
algsubs( s^2=1-c^2, s^3 );
|
| (1) |
>
|
algsubs( a+b=d, 1+a+b+c );
|
| (2) |
>
|
algsubs( a*b=c, 2*a*b^2-a*b*d );
|
| (3) |
>
|
algsubs( a*b/c=d, 2*a*b^2/c );
|
| (4) |
>
|
algsubs( a^2=0, exp(2-a+a^2/2-a^3/6) );
|
| (5) |
|
Both modes depend on the ordering of the variables that appear in a. This can be set to a specific ordering by specifying the variables v in a list as a third argument. If the variables are not explicitly given, the set of indeterminates in a, b which are functions and names defines the variables and their order. Also, the result is collected in the variables given.
|
|
Both modes require that monomials in a divide monomials in f for a substitution to occur. A monomial u in a divides a monomial v in f if for each variable x in u, then either or .
|
|
Note: The algsubs command currently works only with integer exponents.
|
|
Note that the requirement for monomials in a to divide monomials in f means that the negative powers of u in the following example are not substituted, and must be handled separately as shown.
|
>
|
f := a/u^4+b/u^2+c+d*u^2+e*u^4;
|
| (6) |
| (7) |
| (8) |
|
Hence, to substitute for both positive and negative powers.
|
>
|
algsubs(u^2=v,algsubs(1/u^2=1/v,f));
|
| (9) |
•
|
If the option remainder is specified, or no option is specified, a generalized remainder is computed. If the leading monomial of a divides the leading monomial of f then the leading monomial of f is replaced with the appropriate value, and this is repeated until the leading monomial in f is less than the leading monomial in a.
|
•
|
The algsubs command goes recursively through the expression . Unlike the subs command it does not substitute inside indexed names, and function calls are applied to the result of a substitution. Like subs, it does not expand products or powers before substitution. Hence algsubs( x^2=0, (x+1)^3 ) yields .
|
|
|
Examples
|
|
>
|
|
| (10) |
>
|
|
| (11) |
>
|
|
| (12) |
>
|
|
| (13) |
>
|
|
| (14) |
Truncating polynomials
>
|
|
| (15) |
>
|
|
| (16) |
>
|
|
| (17) |
>
|
|
| (18) |
>
|
|
| (19) |
>
|
|
| (20) |
Ambiguous cases
>
|
|
| (21) |
>
|
|
| (22) |
>
|
|
| (23) |
>
|
|
| (24) |
>
|
|
| (25) |
>
|
|
| (26) |
>
|
|
| (27) |
|
|