# 由项求数列通项公式（Formula of a sequence from its terms，find_sequence_function）

由开头若干项求数列的公式；仅当它还能预测另外两项时才给出。

## 怎么写

### find_sequence_function(terms, variable)

给出每一项的公式 a(n)，以及跟在它后面的项；若少一项，则以规则作为提示。

**terms**

开头的若干项，整数或分数，第一项为 a(1)。接受一个列表。

**variable**

公式的指标，如 n 这样的名字。接受一个变量或变量列表。

## 示例

- $\displaystyle 1, 4, 9, 16, 25, \ldots \Rightarrow n^{2}$

  `find_sequence_function([1, 4, 9, 16, 25], n)`

  在求解器中，`find_sequence_function([1, 4, 9, 16, 25], n)` 的结果是 `n^2`。

  [在求解器中打开](https://zh.hilberon.com/?q=find_sequence_function%28%5B1%2C%204%2C%209%2C%2016%2C%2025%5D%2C%20n%29)
- $\displaystyle 1, 1, 2, 3, 5, 8, 13, 21, \ldots \Rightarrow \operatorname{fibonacci}(n)$

  `find_sequence_function([1, 1, 2, 3, 5, 8, 13, 21], n)`

  在求解器中，`find_sequence_function([1, 1, 2, 3, 5, 8, 13, 21], n)` 的结果是 `fibonacci(n)`。

  [在求解器中打开](https://zh.hilberon.com/?q=find_sequence_function%28%5B1%2C%201%2C%202%2C%203%2C%205%2C%208%2C%2013%2C%2021%5D%2C%20n%29)
- $\displaystyle 1, 2, 6, 24, 120, \ldots \Rightarrow n!$

  `find_sequence_function([1, 2, 6, 24, 120], n)`

  在求解器中，`find_sequence_function([1, 2, 6, 24, 120], n)` 的结果是 `n!`。

  [在求解器中打开](https://zh.hilberon.com/?q=find_sequence_function%28%5B1%2C%202%2C%206%2C%2024%2C%20120%5D%2C%20n%29)
- $\displaystyle 2, 3, 5, 5, 8, 7, \ldots \Rightarrow \begin{cases} \frac{3 n+1}{2} & \text{if } n \bmod 2 = 1 \\ n+1 & \text{otherwise} \end{cases}$

  `find_sequence_function([2, 3, 5, 5, 8, 7], n)`

  在求解器中，`find_sequence_function([2, 3, 5, 5, 8, 7], n)` 的结果是 `piecewise((3n + 1)/2 if n % 2 = 1, n + 1 otherwise)`。

  [在求解器中打开](https://zh.hilberon.com/?q=find_sequence_function%28%5B2%2C%203%2C%205%2C%205%2C%208%2C%207%5D%2C%20n%29)
- $\displaystyle 3, 8, 17, 32, 57, 100, 177, \ldots \Rightarrow n^{2}+2^{n}$

  `find_sequence_function([3, 8, 17, 32, 57, 100, 177], n)`

  在求解器中，`find_sequence_function([3, 8, 17, 32, 57, 100, 177], n)` 的结果是 `n^2 + 2^n`。

  [在求解器中打开](https://zh.hilberon.com/?q=find_sequence_function%28%5B3%2C%208%2C%2017%2C%2032%2C%2057%2C%20100%2C%20177%5D%2C%20n%29)

## 相关函数

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

  一个项列表所满足的递推关系；仅当它在另外两项上也成立时才给出。
- [next_terms](https://zh.hilberon.com/library/next_terms)

  列表之后的项：仅当某条规则能解释它并预测出另外两项时才给出。
- [numeric_product](https://zh.hilberon.com/library/numeric_product)

  在某个范围内对表达式求乘积，以小数表示。
- [differences](https://zh.hilberon.com/library/differences)

  列表中相邻元素之差。
- [numeric_sum](https://zh.hilberon.com/library/numeric_sum)

  在某个范围内对表达式求和，以小数表示。
- [sum_convergence](https://zh.hilberon.com/library/sum_convergence)

  检验表达式关于某个变量的和是否收敛。

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