algsubs - Maple Programming Help

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 );
 $\left({-}{{c}}^{{2}}{+}{1}\right){}{s}$ (1)
 > algsubs( a+b=d, 1+a+b+c );
 ${1}{+}{d}{+}{c}$ (2)
 > algsubs( a*b=c, 2*a*b^2-a*b*d );
 ${2}{}{b}{}{c}{-}{c}{}{d}$ (3)
 > algsubs( a*b/c=d, 2*a*b^2/c );
 ${2}{}{d}{}{b}$ (4)
 > algsubs( a^2=0, exp(2-a+a^2/2-a^3/6) );
 ${{ⅇ}}^{{2}{-}{a}}$ (5)
 • Where the expression being replaced has more than one variable, the result is ambiguous. For example, should algsubs(a+b=c, 2*a+b) return $2c-b$ or $a+c$? What should algsubs(a+b=c, a+Pi*b) return? Should algsubs(x*y^2=c, x*y^4) return $c{y}^{2}$ or $\frac{{c}^{2}}{x}$? The algsubs command provides two modes for breaking ambiguities, an exact mode and a remainder mode (the default).
 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 $0<\mathrm{degree}\left(u,x\right)\le \mathrm{degree}\left(v,x\right)$ or $\mathrm{degree}\left(v,x\right)\le \mathrm{degree}\left(u,x\right)<0$.
 For example, the monomial $\frac{{x}^{2}}{{y}^{2}}$ divides the monomial $\frac{{x}^{3}}{{y}^{2}}$ but not $\frac{x}{{y}^{2}}$ or $\frac{{x}^{2}}{y}$.
 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;
 ${f}{≔}\frac{{a}}{{{u}}^{{4}}}{+}\frac{{b}}{{{u}}^{{2}}}{+}{c}{+}{d}{}{{u}}^{{2}}{+}{e}{}{{u}}^{{4}}$ (6)
 > algsubs(u^2=v,f);
 ${e}{}{{v}}^{{2}}{+}{d}{}{v}{+}{c}{+}\frac{{b}}{{{u}}^{{2}}}{+}\frac{{a}}{{{u}}^{{4}}}$ (7)
 > algsubs(1/u^2=1/v,f);
 ${e}{}{{u}}^{{4}}{+}{d}{}{{u}}^{{2}}{+}\frac{{c}{}{{v}}^{{2}}{+}{b}{}{v}{+}{a}}{{{v}}^{{2}}}$ (8)
 Hence, to substitute for both positive and negative powers.
 > algsubs(u^2=v,algsubs(1/u^2=1/v,f));
 $\frac{{e}{}{{v}}^{{4}}{+}{d}{}{{v}}^{{3}}{+}{c}{}{{v}}^{{2}}{+}{b}{}{v}{+}{a}}{{{v}}^{{2}}}$ (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.
 • If the option exact is specified, then if the value a being replaced is a sum of terms ${a}_{i}$, and the value f it is replacing is the sum of terms ${f}_{i}$, then the replacement is made if and only if each monomial ${a}_{i}$ divides ${f}_{i}$ and $\sum \phantom{\rule[-0.0ex]{5.0px}{0.0ex}}{a}_{i}=c\left(\sum \phantom{\rule[-0.0ex]{5.0px}{0.0ex}}{f}_{i}\right)$ that is, the coefficients must all be the same. For example, algsubs( x^2+2*y=z, 3*x^2+6*y ) succeeds with $c=3$ but algsubs(x^2+2*y=z, 3*x^2+3*y) fails.
 • The algsubs command goes recursively through the expression $f$. 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 ${\left(x+1\right)}^{3}$.

Examples

 > $\mathrm{algsubs}\left(a+b=c,{ⅇ}^{a+b+d}\right)$
 ${{ⅇ}}^{{c}{+}{d}}$ (10)
 > $\mathrm{algsubs}\left(\frac{PV}{T}=R,\frac{{P}^{2}V}{{T}^{2}}-PR\right)$
 ${-}{P}{}{R}{+}\frac{{R}{}{P}}{{T}}$ (11)
 > $\mathrm{algsubs}\left(s+\frac{1}{t}=y,{\left(s+\frac{1}{t}+1\right)}^{3}-s-\frac{2}{t}\right)$
 ${\left({y}{+}{1}\right)}^{{3}}{-}\frac{{1}}{{t}}{-}{y}$ (12)
 > $f≔{\mathrm{sin}\left(x\right)}^{3}-\mathrm{cos}\left(x\right){\mathrm{sin}\left(x\right)}^{2}+{\mathrm{cos}\left(x\right)}^{2}\mathrm{sin}\left(x\right)+{\mathrm{cos}\left(x\right)}^{3}$
 ${f}{≔}{{\mathrm{sin}}{}\left({x}\right)}^{{3}}{-}{\mathrm{cos}}{}\left({x}\right){}{{\mathrm{sin}}{}\left({x}\right)}^{{2}}{+}{{\mathrm{cos}}{}\left({x}\right)}^{{2}}{}{\mathrm{sin}}{}\left({x}\right){+}{{\mathrm{cos}}{}\left({x}\right)}^{{3}}$ (13)
 > $\mathrm{algsubs}\left({\mathrm{sin}\left(x\right)}^{2}=1-{\mathrm{cos}\left(x\right)}^{2},f\right)$
 ${2}{}{{\mathrm{cos}}{}\left({x}\right)}^{{3}}{+}{\mathrm{sin}}{}\left({x}\right){-}{\mathrm{cos}}{}\left({x}\right)$ (14)

Truncating polynomials

 > $f≔\mathrm{expand}\left({\left(u+w-\frac{1}{w}\right)}^{3}\right)$
 ${f}{≔}{{u}}^{{3}}{+}{3}{}{{u}}^{{2}}{}{w}{-}\frac{{3}{}{{u}}^{{2}}}{{w}}{+}{3}{}{u}{}{{w}}^{{2}}{-}{6}{}{u}{+}\frac{{3}{}{u}}{{{w}}^{{2}}}{+}{{w}}^{{3}}{-}{3}{}{w}{+}\frac{{3}}{{w}}{-}\frac{{1}}{{{w}}^{{3}}}$ (15)
 > $\mathrm{algsubs}\left({u}^{2}=0,f\right)$
 $\frac{{{w}}^{{6}}{-}{3}{}{{w}}^{{4}}{+}{3}{}{{w}}^{{2}}{-}{1}}{{{w}}^{{3}}}{+}\frac{{3}{}\left({{w}}^{{4}}{-}{2}{}{{w}}^{{2}}{+}{1}\right){}{u}}{{{w}}^{{2}}}$ (16)
 > $\mathrm{algsubs}\left({u}^{2}=0,f,\left[u,w\right]\right)$
 ${3}{}{u}{}{{w}}^{{2}}{-}{6}{}{u}{+}\frac{{3}{}{u}}{{{w}}^{{2}}}{+}{{w}}^{{3}}{-}{3}{}{w}{+}\frac{{3}}{{w}}{-}\frac{{1}}{{{w}}^{{3}}}$ (17)
 > $\mathrm{algsubs}\left(\frac{1}{{w}^{2}}=0,f,\left[u,w\right]\right)$
 ${{u}}^{{3}}{+}{3}{}{{u}}^{{2}}{}{w}{-}\frac{{3}{}{{u}}^{{2}}}{{w}}{+}{3}{}{u}{}{{w}}^{{2}}{-}{6}{}{u}{+}{{w}}^{{3}}{-}{3}{}{w}{+}\frac{{3}}{{w}}$ (18)
 > $\mathrm{algsubs}\left(uw=0,f\right)$
 ${{u}}^{{3}}{-}\frac{{3}{}{{u}}^{{2}}}{{w}}{-}{6}{}{u}{+}\frac{{3}{}{u}}{{{w}}^{{2}}}{+}{{w}}^{{3}}{-}{3}{}{w}{+}\frac{{3}}{{w}}{-}\frac{{1}}{{{w}}^{{3}}}$ (19)
 > $\mathrm{algsubs}\left(\frac{u}{w}=0,f\right)$
 ${{u}}^{{3}}{+}{3}{}{{u}}^{{2}}{}{w}{+}{3}{}{u}{}{{w}}^{{2}}{-}{6}{}{u}{+}{{w}}^{{3}}{-}{3}{}{w}{+}\frac{{3}}{{w}}{-}\frac{{1}}{{{w}}^{{3}}}$ (20)

Ambiguous cases

 > $f≔2a+b$
 ${f}{≔}{2}{}{a}{+}{b}$ (21)
 > $\mathrm{algsubs}\left(a+b=c,f,\left[a,b\right]\right)$
 ${2}{}{c}{-}{b}$ (22)
 > $\mathrm{algsubs}\left(a+b=c,f,\left[b,a\right]\right)$
 ${a}{+}{c}$ (23)
 > $\mathrm{algsubs}\left(a+b=c,f,\mathrm{exact}\right)$
 ${2}{}{a}{+}{b}$ (24)
 > $f≔\frac{\left(\mathrm{a1}+\mathrm{a2}-1\right)x}{\mathrm{a1}+\mathrm{a2}}+\frac{\mathrm{a1}y}{\mathrm{a1}+\mathrm{a2}}-\frac{\mathrm{a2}\left(\mathrm{a1}+\mathrm{a2}\right)}{z}$
 ${f}{≔}\frac{\left({\mathrm{a1}}{+}{\mathrm{a2}}{-}{1}\right){}{x}}{{\mathrm{a1}}{+}{\mathrm{a2}}}{+}\frac{{\mathrm{a1}}{}{y}}{{\mathrm{a1}}{+}{\mathrm{a2}}}{-}\frac{{\mathrm{a2}}{}\left({\mathrm{a1}}{+}{\mathrm{a2}}\right)}{{z}}$ (25)
 > $\mathrm{algsubs}\left(\mathrm{a1}+\mathrm{a2}=p,f\right)$
 $\frac{{x}{}\left({p}{-}{1}\right)}{{p}}{+}\frac{{y}{}\left({-}{\mathrm{a2}}{+}{p}\right)}{{p}}{-}\frac{{\mathrm{a2}}{}{p}}{{z}}$ (26)
 > $\mathrm{algsubs}\left(\mathrm{a1}+\mathrm{a2}=p,f,\mathrm{exact}\right)$
 $\frac{{x}{}\left({p}{-}{1}\right)}{{p}}{+}\frac{{y}{}{\mathrm{a1}}}{{p}}{-}\frac{{\mathrm{a2}}{}{p}}{{z}}$ (27)