# Solve recurrence relations (solve_recurrence)

Solve a recurrence relation for a sequence.

## How to write it

### solve_recurrence(equations, unknown, variable)

Solve for the sequence in terms of its index. With t(n/b), n is a power of b and the answer states it.

**equations**

The recurrence, or a list that includes initial values such as a(0) = 1. Takes an equation, or a list of equations in brackets.

**unknown**

The unknown to solve for, such as y. Takes a variable, or a list of variables.

**variable**

The variable to work with, a name such as x. Takes a variable, or a list of variables.

## Examples

- $\displaystyle \begin{cases} a(n+1) = 2 a(n) \\ a(0) = 1 \end{cases} \Rightarrow a(n) = 2^{n}$

  `solve_recurrence([a(n+1) = 2 a(n), a(0) = 1], a, n)`

  In the solver, `solve_recurrence([a(n+1) = 2 a(n), a(0) = 1], a, n)` gives `[[a(n) -> 2^n]]`.

  [Open in the solver](https://hilberon.com/?q=solve_recurrence%28%5Ba%28n%2B1%29%20%3D%202%20a%28n%29%2C%20a%280%29%20%3D%201%5D%2C%20a%2C%20n%29)
- $\displaystyle \begin{cases} t(n) = 2 t\left(\frac{n}{2}\right)+n \\ t(1) = 1 \end{cases} \Rightarrow t(n) = n+\frac{n \ln(n)}{\ln(2)},\ n \ge 1,\ \frac{\ln(n)}{\ln(2)} \in \mathbb{Z}$

  `solve_recurrence([t(n) = 2 t(n/2) + n, t(1) = 1], t, n)`

  In the solver, `solve_recurrence([t(n) = 2 t(n/2) + n, t(1) = 1], t, n)` gives `[[t(n) -> n + n*ln(n)/ln(2) if n >= 1 and ln(n)/ln(2) : integer]]`.

  [Open in the solver](https://hilberon.com/?q=solve_recurrence%28%5Bt%28n%29%20%3D%202%20t%28n%2F2%29%20%2B%20n%2C%20t%281%29%20%3D%201%5D%2C%20t%2C%20n%29)

## Related functions

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

  The order of growth of a divide-and-conquer recurrence, as big_theta of a simple function.
- [solve_ode](https://hilberon.com/library/solve_ode)

  Solve a differential equation, or a system, with optional initial conditions.

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