# 代入（Substitution，subs）

在表达式中代入一条规则或规则列表。

## 怎么写

### subs(expr, rules)

**expr**

任意表达式：一个数、一个公式、一个列表或一个矩阵。接受一个表达式。

**rules**

用什么替换什么。接受一条规则或规则列表。

## 示例

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

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

  在求解器中，`subs(x^2 + 1, x -> 2)` 的结果是 `5`。

  [在求解器中打开](https://zh.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])`

  在求解器中，`subs(x^2 + y, [x -> 1, y -> 2])` 的结果是 `3`。

  [在求解器中打开](https://zh.hilberon.com/?q=subs%28x%5E2%20%2B%20y%2C%20%5Bx%20-%3E%201%2C%20y%20-%3E%202%5D%29)

## 相关函数

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

  把以多项式根形式给出的代数数用根式表示。
- [simplify](https://zh.hilberon.com/library/simplify)

  化简表达式，可选在假设条件下进行。
- [together](https://zh.hilberon.com/library/together)

  把分数合并成同分母的一个分数。
- [resultant](https://zh.hilberon.com/library/resultant)

  两个多项式关于某个变量的结式。
- [apart](https://zh.hilberon.com/library/apart)

  将有理式拆分成部分分式。
- [power_expand](https://zh.hilberon.com/library/power_expand)

  展开乘积与幂的幂和对数。

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