Perrin Number Calculator
Sequences
- The Perrin sequence starts 3, 0, 2 and each later term adds the terms two and three places back: P(n) = P(n - 2) + P(n - 3).
- Running the recurrence up to n = 20 gives P(20) = 277.
- Consecutive ratios settle towards the plastic constant, about 1.3247 - the real root of x^3 = x + 1.
- Perrin numbers also power a primality test: every prime p divides P(p), and the rare composites that pass anyway are called Perrin pseudoprimes - the smallest is 271,441.
The Perrin sequence starts 3, 0, 2 and then follows a rule with a skip in it: each new term adds the terms two and three places back, P(n) = P(n - 2) + P(n - 3). That gives 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17 and onwards - P(20) = 277, P(50) = 1,276,942. It is the less famous cousin of the Fibonacci and Padovan sequences, with the same family charm: a simple recurrence, an irrational growth constant, and a surprise appearance in primality testing.
The surprise is the reason this calculator has two modes. In 1899 Perrin observed that every prime p divides P(p). That divisibility is a primality test - and unlike the Fermat test, it has almost no false positives. The smallest composite that passes, 271,441 = 521^2, hid until a computer search found it in 1982.
Value mode computes P(n) exactly. Test mode computes P(n) modulo n by fast matrix exponentiation - never writing the huge term out - and reports whether n passes, and whether n is actually prime.
Worked examples
Perrin number P(20)
(0 - the Perrin number P(n) · 20)
| Perrin number P(20) | 277 |
| previous term P(n - 1) | 209 |
| next term P(n + 1) | 367 |
| ratio P(n) / P(n - 1) | 1.3254 |
| is P(n) itself prime? | Yes |
Perrin number P(10)
(0 - the Perrin number P(n) · 10)
| Perrin number P(10) | 17 |
| previous term P(n - 1) | 12 |
| next term P(n + 1) | 22 |
| ratio P(n) / P(n - 1) | 1.4167 |
| is P(n) itself prime? | Yes |
Perrin test at 271,441
(1 - Perrin prime test for n · 271441)
| Perrin test at n = 271,441 | composite but it passes - a Perrin pseudoprime |
| P(n) mod n | 0 |
| is n prime? | No |
| smallest Perrin pseudoprime | 271,441 = 521^2 |
The recurrence
Most famous recurrences look at the last two terms. The Perrin recurrence reaches past the previous term entirely: P(n) depends on P(n - 2) and P(n - 3). Starting from 3, 0, 2, that gives P(3) = P(1) + P(0) = 3, P(4) = P(2) + P(1) = 2, P(5) = P(3) + P(2) = 5, and the sequence unfolds 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, 22, 29, ... The skip gives the sequence a distinctive lilt - pairs of equal terms appear early (5, 5) and the growth is gentler than Fibonacci's.
The Perrin sequence shares its recurrence with the Padovan sequence, which uses different seeds; the two are shifts and combinations of each other. That kinship is a useful check on computations and a reminder that a recurrence is a family, not a single sequence - the seeds choose which member you meet.
- P(0) = 3, P(1) = 0, P(2) = 2
- P(n) = P(n - 2) + P(n - 3)
- Sequence: 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17
- A skip-recurrence: the immediate predecessor is ignored
Computing a term
Value mode runs the recurrence in exact integer arithmetic up to n = 100, reporting the term, its neighbours and the ratio between consecutive terms. P(10) = 17 and P(20) = 277 are small enough to verify by hand from the seed values in a minute or two. P(50) = 1,276,942 shows the growth regime the sequence settles into: steady multiplication by about 1.3247 per step.
The terms grow exponentially but mildly - nothing like the factorial explosion elsewhere on this site - so exact values stay manageable for hundreds of terms. Beyond the calculator's value-mode range, the primality-test mode takes over: it never needs P(n) itself, only P(n) modulo n, and gets it by matrix exponentiation in O(log n) matrix multiplications.
- P(10) = 17, P(20) = 277, P(50) = 1,276,942
- Exact integer arithmetic - no rounding anywhere
- Previous and next terms reported with each value
- Ratio P(n) / P(n - 1) shown to 4 decimals
The plastic constant
Divide consecutive Perrin terms and the ratios settle towards a constant: P(n) / P(n - 1) approaches about 1.3247, the plastic constant. It is the unique real root of x^3 = x + 1, and it plays for this recurrence the role the golden ratio plays for Fibonacci - the characteristic root whose powers dominate the sequence, while the complex roots have modulus below 1 and their contributions fade.
The calculator shows the ratio to four decimals with every value so the convergence is visible: by P(20) the ratio is already close to 1.3247, wobbling gently around the limit. The plastic constant also appears in architecture and design lore as the plastic number, but its cleanest definition is exactly this - the growth rate of the Perrin and Padovan recurrences.
- Ratios approach the plastic constant, about 1.3247
- The plastic constant is the real root of x^3 = x + 1
- It is the Perrin analogue of the golden ratio
- The other two roots are complex and shrink away
The Perrin prime test
Perrin's divisibility observation turns the sequence into a primality test: compute P(n) mod n, and if the remainder is not 0, n is certainly composite. Every prime passes, so a failure is a proof. The tantalising direction is the converse - and it almost holds. The composites that pass anyway, the Perrin pseudoprimes, are so rare that none was known until 1982, when a computer search found the smallest: 271,441 = 521^2. Only a handful are known even now.
Run the test on 271,441 in the calculator and it reports the strange verdict honestly: the remainder is 0, the number passes - and the number is composite, a Perrin pseudoprime. For ordinary inputs the test agrees with true primality, which the calculator also reports, so you can see the test's verdict and the ground truth side by side. That pairing is the right way to present any one-sided test: the proof direction is absolute, the heuristic direction is labelled.
- Every prime p divides P(p) (Perrin, 1899)
- Failure proves compositeness with certainty
- Smallest Perrin pseudoprime: 271,441 = 521^2, found in 1982
- Test mode uses fast matrix exponentiation modulo n
Perrin numbers in design and nature
The plastic constant that governs Perrin growth has a life outside number theory. The Dutch architect Hans van der Laan built a system of architectural proportions on it, and the Padovan sequence - the Perrin recurrence with different seeds - generates a spiral of cubes whose side lengths follow the same ratio, a three-dimensional analogue of the golden spiral's squares. Where the golden ratio tiles rectangles, the plastic constant tiles cubes, and designers have used it for everything from furniture proportions to type scales.
Within mathematics, the Perrin sequence's divisibility property generalises: for prime p, p divides P(p), and the same style of test exists for other linear recurrences - the Lucas sequences behind the Lucas primality test are the famous case. The Perrin test's distinction is the extreme rarity of its pseudoprimes: where the Fermat test has infinitely many Carmichael numbers to trip on, the Perrin test has a bare handful of known failures, which is why it survived for eight decades as a suspected (but false) primality proof.
A caution for users of this calculator's test mode: passing the Perrin test is evidence, not proof, and the calculator says so by always showing whether n is actually prime beside the verdict. For the ranges on this page the ground truth is computed independently, so the famous pseudoprime 271,441 can be seen failing upward - passing a test it should fail - with both facts on display. That transparency is the right way to meet any one-sided test.
- Plastic constant proportions in architecture (van der Laan)
- Padovan cubes: the 3D golden spiral analogue
- Lucas sequences generalise the divisibility test idea
- Test mode always shows true primality beside the verdict
Worked checks and pitfalls
Hand-check the recurrence against the calculator at small n: from 3, 0, 2 the rule P(n) = P(n - 2) + P(n - 3) gives P(3) = 0 + 3 = 3, P(4) = 2 + 0 = 2, P(5) = 3 + 2 = 5, P(6) = 2 + 3 = 5, P(7) = 5 + 2 = 7, P(8) = 5 + 5 = 10, P(9) = 7 + 5 = 12, P(10) = 10 + 7 = 17. If a source lists a different P(10), it is probably using the Padovan seeds or a shifted indexing - the Perrin literature has an off-by-one dialect problem, and stating P(0) = 3, P(1) = 0, P(2) = 2, as this page does, is the only way to pin a claim down.
For the test mode, the pitfall is over-reading a pass. A pass at composite n is a pseudoprime event - rare, famous, and the entire reason the calculator prints true primality beside the verdict. Conversely a fail is a proof of compositeness with no caveats: no prime fails, ever. One direction is evidence, the other is certainty, and the output labels them accordingly.
- P(10) = 17 by hand from the seeds
- Indexing dialects differ - pin down P(0), P(1), P(2)
- A fail proves composite; a pass is only evidence
- 271,441 is the standing warning about passes
FAQs
What is a Perrin number?
A term of the sequence P(n) = P(n - 2) + P(n - 3) starting 3, 0, 2. For example P(20) = 277.
What is P(50)?
1,276,942.
What is the Perrin prime test?
Perrin proved every prime p divides P(p). So if n does not divide P(n), n is certainly composite - a one-sided primality test.
What is a Perrin pseudoprime?
A composite number that passes the test anyway - n divides P(n) despite n being composite. The smallest is 271,441 = 521^2.
What constant do Perrin ratios approach?
The plastic constant, about 1.3247 - the real root of x^3 = x + 1, the Perrin analogue of the golden ratio.
What is P(10)?
17. The sequence runs 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17 for P(0) to P(10).