# catalan() Function & Examples

Use the catalan() combinatorics function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## catalan

#### catalan(n)

Try it yourself:

```calculio
catalan(3)
catalan(8)
```

---

## catalan(): count recursive structures

**catalan(n)** returns the nth Catalan number. This sequence begins 1, 1, 2, 5, 14, 42 and counts many apparently different structures: correctly nested parentheses, binary search tree shapes, polygon triangulations, and non-crossing pairings.

## Formula and example

For a non-negative integer n, the value is `binomial(2n, n)/(n + 1)`. `catalan(3)` is 5, which is the number of valid ways to arrange three matched pairs of parentheses. The numbers grow quickly, so exact integer arithmetic is preferable for larger n.

## Related combinatorics

[combinations()](https://calcul.io/function/combinations/index.md) computes the central coefficient in the formula. For other counting families, see [combinations()](https://calcul.io/function/combinations/index.md), [bernoulli()](https://calcul.io/function/bernoulli/index.md), and [stirlingS2()](https://calcul.io/function/stirlingS2/index.md). [factorial()](https://calcul.io/function/factorial/index.md) helps derive the equivalent factorial form.

## Valid input

n must be a non-negative integer. A fractional or negative index does not identify a standard Catalan number. Do not confuse a count of structures with a probability; normalize separately if needed.

[All functions](https://calcul.io/functions/index.md)
