TITLE: is there any non prime (pseudoprime) that holds true for this test, or any prime that fall out of this test?
QUESTION [5 upvotes]: The sequence is defined by the following formula   $d_{n + 3} = d_{n + 2} + 2d_{n + 1} - d_n$ where $d_1 = 0, d_2 = 1, d_3 = 2$, $\{0, 1, 2, 4, 7, 13, 23,42, ...\}$ if this sequence is calculated over finite field $p$ $$(d_{n + 3} = d_{n + 2} + 2d_{n + 1} - d_n)\,mod\,\text{p}$$ It follows that if $p$ is prime, then the last three terms $d_{p - 1},\; d_p$, and  $d_{p + 1}$ fall within one of the following ending patterns
$\;\{4, 2, 1\}$ , $\{p - 1, 0, 1\}$, or  $\{p - 6, p - 3, p - 2\}$. this is true for all prime up to tested range, $60000$

my questions


why only primes follow these patterns?
is there any non prime(s) following this patterns?
is there any published work like this and in the same pattern. To see if i can study more about it

REPLY [4 votes]: Prime $p=7$ fails the test, but this is the only exception below $10^7$. This is likely explained by the characteristic polynomial $x^3 - x^2 - 2x + 1$ having discriminant $49=7^2$.
Also, there are nine pseudoprimes below $10^7$: 
$$530881,~ 597871,~ 1152271,~ 3057601,~ 3581761,~ 3698241,~ 5444489,~ 5968873,~ 6868261.$$