# Formula of a sequence from its terms (find_sequence_function)

The formula of a sequence from its first terms, given only when it also predicts two more.

## How to write it

### find_sequence_function(terms, variable)

A formula a(n) that gives every term, with the terms that follow it; one term short, the rule as a hint.

**terms**

The first terms, whole numbers or fractions, the first being a(1). Takes a list.

**variable**

The index of the formula, a name such as n. Takes a variable, or a list of variables.

## Examples

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

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

  In the solver, `find_sequence_function([1, 4, 9, 16, 25], n)` gives `n^2`.

  [Open in the solver](https://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)`

  In the solver, `find_sequence_function([1, 1, 2, 3, 5, 8, 13, 21], n)` gives `fibonacci(n)`.

  [Open in the solver](https://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)`

  In the solver, `find_sequence_function([1, 2, 6, 24, 120], n)` gives `n!`.

  [Open in the solver](https://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)`

  In the solver, `find_sequence_function([2, 3, 5, 5, 8, 7], n)` gives `piecewise((3n + 1)/2 if n % 2 = 1, n + 1 otherwise)`.

  [Open in the solver](https://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)`

  In the solver, `find_sequence_function([3, 8, 17, 32, 57, 100, 177], n)` gives `n^2 + 2^n`.

  [Open in the solver](https://hilberon.com/?q=find_sequence_function%28%5B3%2C%208%2C%2017%2C%2032%2C%2057%2C%20100%2C%20177%5D%2C%20n%29)

## Related functions

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

  The recurrence a list of terms obeys, given only when it also holds on two more.
- [next_terms](https://hilberon.com/library/next_terms)

  The terms that follow a list, given only when a rule explains it and predicts two more.
- [numeric_product](https://hilberon.com/library/numeric_product)

  Multiply an expression over a range, as a decimal.
- [differences](https://hilberon.com/library/differences)

  The differences between neighbouring elements of a list.
- [numeric_sum](https://hilberon.com/library/numeric_sum)

  Add up an expression over a range, as a decimal.
- [sum_convergence](https://hilberon.com/library/sum_convergence)

  Test whether the sum of an expression over a variable converges.

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