### 9.1.16 Substituting a subexpression by another expression

The algsubs command replaces subexpressions of an expression, rather than just replace variables.

- algsubs takes two arguments:
  - expr1=expr2, an equation between two expressions.
  - expr, another expression.
- algsubs(expr1=expr2,expr) returns the last expression expr with expr1 replaced by expr2.

#### Examples

algsubs(x^2=u,1+x^2+x^4)

u2+u+1 |  |  |  |  |  |  |  |  |  |

algsubs(a*b/c=d,2*a*b^2/c)

2*b*d |  |  |  |  |  |  |  |  |  |

algsubs(2 a=p^2-q^2,algsubs(2 c=p^2+q^2, c^2-a^2))

p2q2 |  |  |  |  |  |  |  |  |  |