ForHosting KIT · Math

Perrin sequence term

Get any term of the Perrin sequence, which starts 3, 0, 2 and adds the terms two and three places back: P(10) is 17, that is 10 plus 7. Indices run from 0 to 130. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
N
10
You get
Perrin
17
Recurrence
P(0)=3; P(1)=0; P(2)=2; P(n)=P(n-2)+P(n-3) for n>2

The Perrin sequence begins with three, zero, and two, then builds every later term by adding the values two and three places back. This calculator returns the term at a zero-based index n, together with the exact convention used for the initial values and recurrence. It is useful when checking discrete mathematics exercises, testing sequence code, or comparing recurrences that look similar but start differently. Computation is deterministic, uses integer addition only, and runs without network access, random values, or time-dependent behavior. Negative indices are rejected instead of being silently reinterpreted.

Understand the Perrin sequence convention

This capability uses the classical zero-based Perrin definition: P(0) is 3, P(1) is 0, and P(2) is 2. For every index greater than two, P(n) equals P(n-2) plus P(n-3). The first terms are therefore 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, and 22.

Notice that the recurrence has the same lag pattern as the Padovan sequence, but the initial values differ. That distinction matters because identical recurrence rules can produce completely different terms when their seeds change. The response includes both a compact formula and the full seed statement so the convention is never hidden.

Indexing begins at zero, which means an input of zero returns 3 rather than the first computed recurrence step. The operation returns one requested term, not an array containing every earlier term.

Send an index and read the result

Provide n as a non-negative whole number from zero through 130. A successful result echoes the normalized index in n, places the requested integer in perrin, and supplies formula and recurrence fields that describe how it was obtained. For example, n equal to 10 returns the Perrin value 17 because P(10) is P(8) plus P(7), or 10 plus 7.

Text entered through the browser control may contain an unsigned integer, but fractions, scientific notation, blank input, and unrelated text are rejected rather than rounded or guessed. The computation uses a rolling window of three terms, so it requires constant memory and performs at most 128 additions.

Use the value in lessons, tests, and algorithms

Perrin terms are useful for teaching recurrence relations because the rule is short while the nonstandard seeds expose careless assumptions. In a classroom, compare the returned formula with a student's handwritten expansion and verify the base cases before checking later arithmetic. If your application needs very large terms, use a BigInt-oriented implementation with a clearly documented string output.

For ordinary educational and validation work, the bounded integer response is easier to inspect, serialize, and compare across environments.

Check a recurrence exercise

Verify a student's n-th Perrin term while keeping the initial values and lag-two-plus-lag-three rule visible in the response.

Compare Perrin and Padovan numbers

Demonstrate how different seeds change a sequence even when two definitions use the same recurrence pattern.

What are the first Perrin numbers?

Using zero-based indexing, they begin 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, and 22.

Which recurrence does this calculator use?

It uses P(0)=3, P(1)=0, P(2)=2, followed by P(n)=P(n-2)+P(n-3) for n greater than 2.

What is P(10) in the Perrin sequence?

P(10) is 17. It is the sum of P(8), which is 10, and P(7), which is 7: the terms two and three places before it.

How is the Perrin sequence different from Padovan's?

Both use the same rule, adding the terms two and three places back, but they start from different values. Perrin starts 3, 0, 2, so the terms that follow are completely different.

What is the largest index I can use?

Any whole index from 0 to 130. Up to that point every term stays exact. Negative indices are refused rather than reinterpreted, and the index 0 returns 3.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/perrin-sequence

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/perrin-sequence \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":10}'
{
  "n": 10
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.perrin_sequence",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_n130
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Understand the Perrin sequence convention

Negative indices are outside this contract and produce an invalid_input error. This explicit behavior makes the calculator suitable for exercises, automated checks, and documentation where an off-by-one interpretation would otherwise be difficult to spot.

Send an index and read the result

The upper bound protects exact arithmetic: through index 130, every returned value remains within JavaScript's safe-integer range in both the browser and Worker runtime. Each successful API request costs $0.002; invalid input is reported as invalid_input and is not a valid sequence result.

Use the value in lessons, tests, and algorithms

The deterministic JSON result also works well in programming challenge graders and regression suites: assert the n and perrin fields, while retaining the recurrence text as a human-readable explanation when a test fails. This capability intentionally does not extend Perrin numbers to negative indices, return a full prefix, or approximate values beyond the exact safe-integer limit.

Test a sequence implementation

Create deterministic fixtures for base cases and later indices without duplicating the reference recurrence in every test harness.

Does n start at zero or one?

It starts at zero. Therefore n=0 returns 3, n=1 returns 0, and n=2 returns 2.

What happens when n is negative?

The request fails with invalid_input because this capability supports only the classical non-negative Perrin sequence.

How much does an API request cost?

A successful API request costs $0.002. The same deterministic calculation is also available in the free browser runner.

Read the full KIT documentation →