Substituting a subexpression by another expression: algsubs

### 6.12.21 Substituting a subexpression by another expression: algsubs

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.

- Input:
  algsubs(x^2 = u, 1 + x^2 + x^4)
  Output:

  u2 + u + 1

- Input:
  algsubs(a*b/c = d, 2*a*b^2/c)
  Output:

  2*b*d

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

  p2q2