# Substitution (subs)

Substitute a rule, or a list of rules, in an expression.

## How to write it

### subs(expr, rules)

**expr**

Any expression: a number, a formula, a list or a matrix. Takes an expression.

**rules**

What to put in place of what. Takes a rule, or a list of rules.

## Examples

- $\displaystyle \operatorname{subs}(x^{2}+1, x \to 2) = 5$

  `subs(x^2 + 1, x -> 2)`

  In the solver, `subs(x^2 + 1, x -> 2)` gives `5`.

  [Open in the solver](https://hilberon.com/?q=subs%28x%5E2%20%2B%201%2C%20x%20-%3E%202%29)
- $\displaystyle \operatorname{subs}(x^{2}+y, \left[ x \to 1, y \to 2 \right]) = 3$

  `subs(x^2 + y, [x -> 1, y -> 2])`

  In the solver, `subs(x^2 + y, [x -> 1, y -> 2])` gives `3`.

  [Open in the solver](https://hilberon.com/?q=subs%28x%5E2%20%2B%20y%2C%20%5Bx%20-%3E%201%2C%20y%20-%3E%202%5D%29)

## Related functions

- [to_radicals](https://hilberon.com/library/to_radicals)

  Write algebraic numbers, given as roots of polynomials, with radicals.
- [simplify](https://hilberon.com/library/simplify)

  Simplify an expression, optionally under assumptions.
- [together](https://hilberon.com/library/together)

  Combine fractions into one over a common denominator.
- [resultant](https://hilberon.com/library/resultant)

  Resultant of two polynomials in a variable.
- [apart](https://hilberon.com/library/apart)

  Split a rational expression into partial fractions.
- [power_expand](https://hilberon.com/library/power_expand)

  Expand powers and logarithms of products and powers.

---
Source: https://hilberon.com/library/subs
