Testy pierwszości. Liczby pseudopierwsze Lucasa i liczby silnie pseudopierwsze Lucasa. Test BPSW
Ciągi Lucasa
Definicja N1
Niech [math]\displaystyle{ P, Q \in \mathbb{Z} \setminus \{0\} }[/math] oraz [math]\displaystyle{ D = P^2 - 4 Q \neq 0 }[/math]. Ciągi Lucasa [math]\displaystyle{ U_n = U_n (P, Q) }[/math] i [math]\displaystyle{ V_n = V_n (P, Q) }[/math] definiujemy następująco
- [math]\displaystyle{ U_n = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}} }[/math]
- [math]\displaystyle{ V_n = \alpha^n + \beta^n }[/math]
gdzie liczby
- [math]\displaystyle{ \alpha = {\small\frac{P + \sqrt{D}}{2}} }[/math]
- [math]\displaystyle{ \beta = {\small\frac{P - \sqrt{D}}{2}} }[/math]
są pierwiastkami równania [math]\displaystyle{ x^2 - P x + Q = 0 }[/math].
Uwaga N2
Zauważmy, że:
- [math]\displaystyle{ P = \alpha + \beta }[/math]
- [math]\displaystyle{ Q = \alpha \beta }[/math]
- [math]\displaystyle{ \sqrt{D} = \alpha - \beta }[/math]
- [math]\displaystyle{ U_0 = 0 }[/math], [math]\displaystyle{ U_1 = 1 }[/math], [math]\displaystyle{ V_0 = 2 }[/math] i [math]\displaystyle{ V_1 = P }[/math]
Warunek [math]\displaystyle{ P^2 - 4 Q \neq 0 }[/math] wyklucza następujące pary [math]\displaystyle{ (P, Q) }[/math]
- [math]\displaystyle{ (0, 0), (\pm 2, 1), (\pm 4, 4), (\pm 6, 9), (\pm 8, 16), (\pm 10, 25), (\pm 12, 36), ..., (\pm 2 n, n^2), ... }[/math]
Uwaga N3
Oczywiście liczby [math]\displaystyle{ \alpha }[/math] i [math]\displaystyle{ \beta }[/math] są również pierwiastkami równania
- [math]\displaystyle{ x^{n + 2} - P x^{n + 1} + Q x^n = 0 }[/math]
Wynika stąd, że ciągi [math]\displaystyle{ (\alpha^n) }[/math] i [math]\displaystyle{ (\beta^n) }[/math] spełniają równania rekurencyjne
- [math]\displaystyle{ \alpha^{n + 2} = P \alpha^{n + 1} - Q \alpha^n }[/math]
- [math]\displaystyle{ \beta^{n + 2} = P \beta^{n + 1} - Q \beta^n }[/math]
Ciągi Lucasa [math]\displaystyle{ (U_n) }[/math] i [math]\displaystyle{ (V_n) }[/math] spełniają identyczne równania rekurencyjne jak ciągi [math]\displaystyle{ (\alpha^n) }[/math] i [math]\displaystyle{ (\beta^n) }[/math]. Istotnie, odejmując i dodając stronami wypisane powyżej równania, otrzymujemy
- [math]\displaystyle{ U_{n + 2} = P U_{n + 1} - Q U_n }[/math]
- [math]\displaystyle{ V_{n + 2} = P V_{n + 1} - Q V_n }[/math]
Dlatego możemy zdefiniować ciągi Lucasa [math]\displaystyle{ (U_n) }[/math] i [math]\displaystyle{ (V_n) }[/math] w sposób równoważny
Definicja N4
Niech [math]\displaystyle{ P, Q \in \mathbb{Z} \setminus \{0\} }[/math] oraz [math]\displaystyle{ D = P^2 - 4 Q \neq 0 }[/math]. Ciągi Lucasa [math]\displaystyle{ (U_n) }[/math] i [math]\displaystyle{ (V_n) }[/math] określone są następującymi wzorami rekurencyjnymi
- [math]\displaystyle{ U_0 = 0 }[/math], [math]\displaystyle{ U_1 = 1 }[/math], [math]\displaystyle{ U_n = P U_{n - 1} - Q U_{n - 2} }[/math]
- [math]\displaystyle{ V_0 = 2 }[/math], [math]\displaystyle{ V_1 = P }[/math], [math]\displaystyle{ V_n = P V_{n - 1} - Q V_{n - 2} }[/math]
Przykład N5
Początkowe wyrazy ciągów Lucasa
[math]\displaystyle{ \boldsymbol{n} }[/math] [math]\displaystyle{ \boldsymbol{U_n (P, Q)} }[/math] [math]\displaystyle{ \boldsymbol{V_n (P, Q)} }[/math] [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 2 }[/math] [math]\displaystyle{ 1 }[/math] [math]\displaystyle{ 1 }[/math] [math]\displaystyle{ P }[/math] [math]\displaystyle{ 2 }[/math] [math]\displaystyle{ P }[/math] [math]\displaystyle{ P^2 - 2 Q }[/math] [math]\displaystyle{ 3 }[/math] [math]\displaystyle{ P^2 - Q }[/math] [math]\displaystyle{ P^3 - 3 P Q }[/math] [math]\displaystyle{ 4 }[/math] [math]\displaystyle{ P^3 - 2 P Q }[/math] [math]\displaystyle{ P^4 - 4 P^2 Q + 2 Q^2 }[/math] [math]\displaystyle{ 5 }[/math] [math]\displaystyle{ P^4 - 3 P^2 Q + Q^2 }[/math] [math]\displaystyle{ P^5 - 5 P^3 Q + 5 P Q^2 }[/math] [math]\displaystyle{ 6 }[/math] [math]\displaystyle{ P^5 - 4 P^3 Q + 3 P Q^2 }[/math] [math]\displaystyle{ P^6 - 6 P^4 Q + 9 P^2 Q^2 - 2 Q^3 }[/math] [math]\displaystyle{ 7 }[/math] [math]\displaystyle{ P^6 - 5 P^4 Q + 6 P^2 Q^2 - Q^3 }[/math] [math]\displaystyle{ P^7 - 7 P^5 Q + 14 P^3 Q^2 - 7 P Q^3 }[/math] [math]\displaystyle{ 8 }[/math] [math]\displaystyle{ P^7 - 6 P^5 Q + 10 P^3 Q^2 - 4 P Q^3 }[/math] [math]\displaystyle{ P^8 - 8 P^6 Q + 20 P^4 Q^2 - 16 P^2 Q^3 + 2 Q^4 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ P^8 - 7 P^6 Q + 15 P^4 Q^2 - 10 P^2 Q^3 + Q^4 }[/math] [math]\displaystyle{ P^9 - 9 P^7 Q + 27 P^5 Q^2 - 30 P^3 Q^3 + 9 P Q^4 }[/math]
Uwaga N6
W PARI/GP możemy napisać prosty kod, który pozwoli obliczyć wartości wyrazów [math]\displaystyle{ U_n (P, Q) }[/math] i [math]\displaystyle{ V_n (P, Q) }[/math]
LucasU(n, P, Q) = if( n == 0, 0, if( n == 1, 1, P*LucasU(n-1, P, Q) - Q*LucasU(n-2, P, Q) ) )
LucasV(n, P, Q) = if( n == 0, 2, if( n == 1, P, P*LucasV(n-1, P, Q) - Q*LucasV(n-2, P, Q) ) )
Twierdzenie N7
Niech [math]\displaystyle{ D = P^2 - 4 Q }[/math]. Wyrazy ciągów Lucasa można przedstawić w postaci sumy
- [math]\displaystyle{ 2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k }[/math]
- [math]\displaystyle{ 2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k }[/math]
Uwaga N8
Korzystając z twierdzenia N7, możemy napisać proste funkcje do znajdowania postaci kolejnych wyrazów [math]\displaystyle{ U_n (P, Q) }[/math] i [math]\displaystyle{ V_n (P, Q) }[/math]
U(n) = 2^(1 - n)*sum(k=0, floor((n-1)/2), binomial(n, 2*k+1) * P^(n-2*k-1) * (P^2-4*Q)^k)
V(n) = 2^(1 - n)*sum(k=0, floor(n/2), binomial(n, 2*k) * P^(n-2*k) * (P^2-4*Q)^k)
Często możemy spotkać założenie [math]\displaystyle{ P \geqslant 1 }[/math]. Poniższe twierdzenie wyjaśnia, dlaczego tak jest.
Twierdzenie N9
Jeżeli [math]\displaystyle{ (U_n) }[/math] i [math]\displaystyle{ (V_n) }[/math] są ciągami Lucasa, to
- [math]\displaystyle{ U_n (- P, Q) = (- 1)^{n - 1} U_n (P, Q) }[/math]
- [math]\displaystyle{ V_n (- P, Q) = (- 1)^n V_n (P, Q) }[/math]
Zadanie N10
Pokazać, że jeżeli [math]\displaystyle{ P, Q \in \mathbb{Z} \setminus \{ 0 \} }[/math] i [math]\displaystyle{ D = P^2 - 4 Q \neq 0 }[/math], to
- [math]\displaystyle{ U_n (2 P, 4 Q) = 2^{n - 1} U_n (P, Q) }[/math]
- [math]\displaystyle{ V_n (2 P, 4 Q) = 2^n V_n (P, Q) }[/math]
Zadanie N11
Pokazać, że jeżeli [math]\displaystyle{ Q \in \mathbb{Z} \setminus \{ 0 \} }[/math] oraz [math]\displaystyle{ P = 4 Q - 1 }[/math], to
- [math]\displaystyle{ U_{2 k} (P, P Q) = - (- P)^k U_{2 k} (1, Q) }[/math]
- [math]\displaystyle{ U_{2 k + 1} (P, P Q) = (- P)^k V_{2 k + 1} (1, Q) }[/math]
- [math]\displaystyle{ V_{2 k} (P, P Q) = (- P)^k V_{2 k} (1, Q) }[/math]
- [math]\displaystyle{ V_{2 k + 1} (P, P Q) = - (- P)^{k + 1} U_{2 k + 1} (1, Q) }[/math]
Zadanie N12
Pokazać, że jeżeli [math]\displaystyle{ Q \in \mathbb{Z} \setminus \{ 0 \} }[/math] oraz [math]\displaystyle{ P = 4 Q + 1 }[/math], to
- [math]\displaystyle{ U_{2 k} (P, P Q) = P^k U_{2 k} (1, - Q) }[/math]
- [math]\displaystyle{ U_{2 k + 1} (P, P Q) = P^k V_{2 k + 1} (1, - Q) }[/math]
- [math]\displaystyle{ V_{2 k} (P, P Q) = P^k V_{2 k} (1, - Q) }[/math]
- [math]\displaystyle{ V_{2 k + 1} (P, P Q) = P^{k + 1} U_{2 k + 1} (1, - Q) }[/math]
Twierdzenie N13
Dla wyrazów ciągów Lucasa prawdziwe są wzory
[math]\displaystyle{ 1. }[/math] | [math]\displaystyle{ U_{m + n} = U_m U_{n + 1} - Q U_{m - 1} U_n }[/math] | |
[math]\displaystyle{ 2. }[/math] | [math]\displaystyle{ V_{m + n} = V_m V_n - Q^n V_{m - n} }[/math] | [math]\displaystyle{ m \geqslant n }[/math] |
[math]\displaystyle{ 3. }[/math] | [math]\displaystyle{ U_{m + n} = U_m V_n - Q^n U_{m - n} }[/math] | [math]\displaystyle{ m \geqslant n }[/math] |
[math]\displaystyle{ 4. }[/math] | [math]\displaystyle{ V_{m + n} = D U_m U_n + Q^n V_{m - n} }[/math] | [math]\displaystyle{ m \geqslant n }[/math] |
[math]\displaystyle{ 5. }[/math] | [math]\displaystyle{ U_m V_n - V_m U_n = 2 Q^n U_{m - n} }[/math] | [math]\displaystyle{ m \geqslant n }[/math] |
[math]\displaystyle{ 6. }[/math] | [math]\displaystyle{ U^2_n = U_{n - 1} U_{n + 1} + Q^{n - 1} }[/math] | |
[math]\displaystyle{ 7. }[/math] | [math]\displaystyle{ V^2_n = V_{n - 1} V_{n + 1} - D Q^{n - 1} }[/math] |
[math]\displaystyle{ \;\; 8. }[/math] | [math]\displaystyle{ 2 U_{m + n} = U_m V_n + V_m U_n }[/math] | |
[math]\displaystyle{ \;\; 9. }[/math] | [math]\displaystyle{ 2 V_{m + n} = V_m V_n + D U_m U_n }[/math] | |
[math]\displaystyle{ 10. }[/math] | [math]\displaystyle{ V_m V_n - D U_m U_n = 2 Q^n V_{m - n} }[/math] | [math]\displaystyle{ m \geqslant n }[/math] |
[math]\displaystyle{ 11. }[/math] | [math]\displaystyle{ U_{2 n} = U_n V_n }[/math] | |
[math]\displaystyle{ 12. }[/math] | [math]\displaystyle{ V_{2 n} = V^2_n - 2 Q^n }[/math] | |
[math]\displaystyle{ 13. }[/math] | [math]\displaystyle{ V_{2 n} = D U^2_n + 2 Q^n }[/math] | |
[math]\displaystyle{ 14. }[/math] | [math]\displaystyle{ V^2_n - D U^2_n = 4 Q^n }[/math] | |
[math]\displaystyle{ 15. }[/math] | [math]\displaystyle{ D U_n = 2 V_{n + 1} - P V_n }[/math] | |
[math]\displaystyle{ 16. }[/math] | [math]\displaystyle{ V_n = 2 U_{n + 1} - P U_n }[/math] | |
[math]\displaystyle{ 17. }[/math] | [math]\displaystyle{ D U_n = V_{n + 1} - Q V_{n - 1} }[/math] | [math]\displaystyle{ n \geqslant 1 }[/math] |
[math]\displaystyle{ 18. }[/math] | [math]\displaystyle{ V_n = U_{n + 1} - Q U_{n - 1} }[/math] | [math]\displaystyle{ n \geqslant 1 }[/math] |
[math]\displaystyle{ 19. }[/math] | [math]\displaystyle{ U_{2 n} = 2 U_n U_{n + 1} - P U^2_n }[/math] |
[math]\displaystyle{ 20. }[/math] | [math]\displaystyle{ U_{2 n + 1} = U^2_{n + 1} - Q U^2_n }[/math] |
[math]\displaystyle{ 21. }[/math] | [math]\displaystyle{ U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1} }[/math] |
Obliczanie wyrazów ciągu Lucasa modulo [math]\displaystyle{ m }[/math]
Przykład N14
Pokażemy, jak wykorzystać podane w twierdzeniu N13 wzory 19, 20, 21 i 16
- [math]\displaystyle{ U_{2 n} = 2 U_n U_{n + 1} - P U^2_n }[/math]
- [math]\displaystyle{ U_{2 n + 1} = U^2_{n + 1} - Q U^2_n }[/math]
- [math]\displaystyle{ U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1} }[/math]
- [math]\displaystyle{ V_n = 2 U_{n + 1} - P U_n }[/math]
do szybkiego obliczania wyrazów ciągu Lucasa modulo [math]\displaystyle{ m }[/math].
Niech [math]\displaystyle{ P = 3 }[/math], [math]\displaystyle{ Q = 1 }[/math], [math]\displaystyle{ D = P^2 - 4 Q = 5 }[/math], [math]\displaystyle{ n = 22 = (10110)_2 = \sum_{j = 0}^{4} a_j \cdot 2^j }[/math].
W tabeli przedstawione są kolejne kroki, jakie musimy wykonać, aby policzyć [math]\displaystyle{ U_n = U_{22} }[/math] modulo [math]\displaystyle{ m = 23 }[/math].
[math]\displaystyle{ \boldsymbol{j} }[/math] [math]\displaystyle{ \boldsymbol{a_j} }[/math] [math]\displaystyle{ \boldsymbol{k_j} }[/math] [math]\displaystyle{ \boldsymbol{U_{k_j}} }[/math] [math]\displaystyle{ \boldsymbol{U_{k_j + 1}} }[/math] [math]\displaystyle{ 4 }[/math] [math]\displaystyle{ 1 }[/math] [math]\displaystyle{ (1)_2 = 1 }[/math] [math]\displaystyle{ U_1 = 1 }[/math] [math]\displaystyle{ U_2 = P = 3 }[/math] [math]\displaystyle{ 3 }[/math] [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ (10)_2 = 2 }[/math] [math]\displaystyle{ U_2 = 2 U_1 U_2 - 3 U^2_1 = 6 - 3 = 3 }[/math] [math]\displaystyle{ U_3 = U^2_2 - 1 = 8 }[/math] [math]\displaystyle{ 2 }[/math] [math]\displaystyle{ 1 }[/math] [math]\displaystyle{ (101)_2 = 5 }[/math] [math]\displaystyle{ U_5 = U^2_3 - U^2_2 = 64 - 9 = 55 \equiv 9 }[/math] [math]\displaystyle{ U_6 = 3 U_3^2 - 2 U_2 U_3 = 192 - 48 = 144 \equiv 6 }[/math] [math]\displaystyle{ 1 }[/math] [math]\displaystyle{ 1 }[/math] [math]\displaystyle{ (1011)_2 = 11 }[/math] [math]\displaystyle{ U_{11} = U^2_6 - U^2_5 \equiv 36 - 81 \equiv - 45 \equiv 1 }[/math] [math]\displaystyle{ U_{12} = 3 U_6^2 - 2 U_5 U_6 \equiv 108 - 108 \equiv 0 }[/math] [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ (10110)_2 = 22 }[/math] [math]\displaystyle{ U_{22} = 2 U_{11} U_{12} - 3 U^2_{11} \equiv 0 - 3 \equiv 20 }[/math] [math]\displaystyle{ U_{23} = U^2_{12} - U^2_{11} \equiv 0 - 1 \equiv 22 }[/math]
W kolumnie [math]\displaystyle{ a_j }[/math] wypisujemy kolejne cyfry liczby [math]\displaystyle{ n = 22 = (10110)_2 }[/math] zapisanej w układzie dwójkowym. Liczby w kolumnie [math]\displaystyle{ k_j }[/math] tworzymy, biorąc kolejne (od prawej do lewej) cyfry liczby [math]\displaystyle{ n }[/math] w zapisie dwójkowym. Postępując w ten sposób, w ostatnim wierszu mamy [math]\displaystyle{ k_j = n }[/math] i wyliczamy liczby [math]\displaystyle{ U_n }[/math] i [math]\displaystyle{ U_{n + 1} }[/math] modulo [math]\displaystyle{ m }[/math].
Dla uproszczenia zapisu i ułatwienia zrozumienia liczbę [math]\displaystyle{ k_j }[/math] oznaczymy jako [math]\displaystyle{ r }[/math], a [math]\displaystyle{ k_{j + 1} }[/math] jako [math]\displaystyle{ s }[/math]. Zauważmy, że
- tabela jest zbudowana tak, że musimy znaleźć wyrazy ciągu Lucasa o indeksie [math]\displaystyle{ r = k_j }[/math] oraz o indeksie o jeden większym: [math]\displaystyle{ r + 1 = k_j + 1 }[/math]
- przejście do następnego wiersza (w dół) oznacza, że musimy znaleźć wyrazy o indeksie [math]\displaystyle{ s = k_{j + 1} }[/math] oraz o indeksie o jeden większym: [math]\displaystyle{ s + 1 }[/math]
- przechodząc do następnego wiersza, dotychczasowa liczba [math]\displaystyle{ r = k_j }[/math] powiększa się o kolejną cyfrę ( [math]\displaystyle{ 0 }[/math] lub [math]\displaystyle{ 1 }[/math] ), którą dopisujemy z prawej strony
- dodanie na końcu liczby [math]\displaystyle{ r = k_j }[/math] zera podwaja liczbę [math]\displaystyle{ r }[/math], czyli [math]\displaystyle{ s = k_{j + 1} = 2 r }[/math] oraz [math]\displaystyle{ s + 1 = 2 r + 1 }[/math]
- dodanie na końcu liczby [math]\displaystyle{ r = k_j }[/math] jedynki podwaja liczbę [math]\displaystyle{ r }[/math] i zwiększą ją o jeden, czyli [math]\displaystyle{ s = k_{j + 1} = 2 r + 1 }[/math] oraz [math]\displaystyle{ s + 1 = 2 r + 2 }[/math]
Dlatego, jeżeli kolejną dodaną cyfrą jest zero, to korzystamy ze wzorów
- [math]\displaystyle{ U_s = U_{2 r} = 2 U_r U_{r + 1} - P U^2_r }[/math]
- [math]\displaystyle{ U_{s + 1} = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r }[/math]
Gdy kolejną dodaną cyfrą jest jeden, to stosujemy wzory
- [math]\displaystyle{ U_s = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r }[/math]
- [math]\displaystyle{ U_{s + 1} = U_{2 r + 2} = P U^2_{r + 1} - 2 Q U_r U_{r + 1} }[/math]
Korzystając ze wzoru [math]\displaystyle{ V_n = 2 U_{n + 1} - P U_n }[/math], mamy
- [math]\displaystyle{ V_{22} = 2 U_{23} - 3 U_{22} \equiv 44 - 60 \equiv - 16 \equiv 7 \pmod{23} }[/math]
Ostatecznie otrzymujemy
- [math]\displaystyle{ U_{22} \equiv 20 \pmod{23} \quad }[/math] oraz [math]\displaystyle{ \quad V_{22} \equiv 7 \pmod{23} }[/math]
Uwaga N15
Uogólniając postępowanie przedstawione w przykładzie N14, możemy napisać program w PARI/GP do szybkiego obliczania wyrazów ciągu Lucasa [math]\displaystyle{ U_n (P, Q) }[/math] i [math]\displaystyle{ V_n (P, Q) }[/math] modulo [math]\displaystyle{ m }[/math].
modLucas(n, P, Q, m) =
{
local(A, i, s, U, U2, V, W, W2);
if( m == 1, return([0, 0]) );
if( n == 0, return([0, 2 % m]) );
A = digits(n, 2); \\ otrzymujemy wektor cyfr liczby n w układzie dwójkowym
s = length(A); \\ długość wektora A
U = 1;
W = P;
i = 1;
while( i++ <= s,
if( A[i] == 0, U2 = 2*U*W - P*U^2; W2 = W^2 - Q*U^2 );
if( A[i] == 1, U2 = W^2 - Q*U^2; W2 = P*W^2 - 2*Q*U*W );
U = U2 % m;
W = W2 % m;
);
V = (2*W - P*U) % m;
return([U, V]);
}
Podzielność wyrazów [math]\displaystyle{ U_n (P, Q) }[/math] przez liczbę pierwszą nieparzystą
Uwaga N16
Niech [math]\displaystyle{ p }[/math] będzie liczbą pierwszą nieparzystą. W przypadku, gdy [math]\displaystyle{ p \nmid P Q }[/math] nie możemy nic powiedzieć o podzielności wyrazów [math]\displaystyle{ U_n }[/math] przez [math]\displaystyle{ p }[/math]. Przykładowo, jeżeli [math]\displaystyle{ P \equiv 1 \pmod{p} \; }[/math] [math]\displaystyle{ \text{i} \;\; Q \equiv 1 \pmod{p} }[/math], to modulo [math]\displaystyle{ p }[/math], mamy
- [math]\displaystyle{ (U_n) \equiv (0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, \ldots) }[/math]
W przypadku, gdy [math]\displaystyle{ P \equiv 2 \pmod{p} \; }[/math] [math]\displaystyle{ \text{i} \;\; Q \equiv 1 \pmod{p} }[/math], to modulo [math]\displaystyle{ p }[/math] mamy
- [math]\displaystyle{ (U_n) \equiv (0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, \ldots) }[/math]
Sytuacja wygląda inaczej, gdy [math]\displaystyle{ p \mid P Q }[/math].
Twierdzenie N17
Niech [math]\displaystyle{ p }[/math] będzie liczbą pierwszą nieparzystą.
● jeżeli [math]\displaystyle{ \; p \mid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \mid Q , \; }[/math] to [math]\displaystyle{ \; p \mid U_n \; }[/math] dla [math]\displaystyle{ n \geqslant 2 }[/math] ● jeżeli [math]\displaystyle{ \; p \mid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \nmid Q , \; }[/math] to [math]\displaystyle{ \; p \mid U_{2 n} \; }[/math] i [math]\displaystyle{ \; p \nmid U_{2 n + 1} }[/math] ● jeżeli [math]\displaystyle{ \; p \nmid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \mid Q , \; }[/math] to [math]\displaystyle{ \; p \nmid U_n \; }[/math] dla [math]\displaystyle{ n \geqslant 1 }[/math] ● jeżeli [math]\displaystyle{ \; p \mid Q , \; }[/math] to [math]\displaystyle{ \; p \mid U_n }[/math], gdzie [math]\displaystyle{ n \geqslant 2 }[/math], wtedy i tylko wtedy, gdy [math]\displaystyle{ \; p \mid P }[/math] ● jeżeli [math]\displaystyle{ \; p \nmid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \mid D , \; }[/math] to [math]\displaystyle{ \; p \mid U_n \; }[/math] wtedy i tylko wtedy, gdy [math]\displaystyle{ p \mid n }[/math]
Założenie, że [math]\displaystyle{ p \nmid P }[/math] w ostatnim punkcie jest istotne. Gdy [math]\displaystyle{ \; p \mid P \; }[/math] i [math]\displaystyle{ \; p \mid D , \; }[/math] to [math]\displaystyle{ \; p \mid Q \; }[/math] i otrzymujemy punkt pierwszy.
Twierdzenie N18
Jeżeli [math]\displaystyle{ d }[/math] jest nieparzystym dzielnikiem [math]\displaystyle{ Q }[/math], to dla [math]\displaystyle{ n \geqslant 2 }[/math] jest
- [math]\displaystyle{ U_n \equiv P^{n - 1} \pmod{d} }[/math]
W szczególności, gdy liczba pierwsza nieparzysta [math]\displaystyle{ p }[/math] jest dzielnikiem [math]\displaystyle{ Q }[/math] i [math]\displaystyle{ p \nmid P }[/math], to
- [math]\displaystyle{ U_p \equiv 1 \pmod{p} }[/math]
Twierdzenie N19
Niech [math]\displaystyle{ D = P^2 - 4 Q }[/math], a [math]\displaystyle{ (D \mid p) }[/math] oznacza symbol Legendre'a, gdzie [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą i [math]\displaystyle{ p \nmid Q }[/math]. Mamy
● [math]\displaystyle{ U_p \equiv (D \mid p) \pmod{p} }[/math] ● jeżeli [math]\displaystyle{ (D \mid p) = - 1 , \; }[/math] to [math]\displaystyle{ \; p \mid U_{p + 1} }[/math] ● jeżeli [math]\displaystyle{ (D \mid p) = 1 , \; }[/math] to [math]\displaystyle{ \; p \mid U_{p - 1} }[/math]
Aby zapisać punkty 2. i 3. twierdzenia N19 (i tylko te punkty) w zwartej formie, musimy założyć, że [math]\displaystyle{ \gcd (p, D) = 1 }[/math]. Otrzymujemy
Twierdzenie N20
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą i [math]\displaystyle{ \gcd (p, Q D) = 1 }[/math], to
- [math]\displaystyle{ U_{p - (D \mid p)} \equiv 0 \pmod{p} }[/math]
Liczby pseudopierwsze Lucasa
Uwaga N21
Z twierdzenia N20 wiemy, że liczby pierwsze nieparzyste [math]\displaystyle{ p }[/math] takie, że [math]\displaystyle{ p \nmid Q D }[/math] są dzielnikami wyrazów ciągu Lucasa [math]\displaystyle{ U_{p - (D \mid p)} }[/math], gdzie [math]\displaystyle{ (D \mid p) }[/math] oznacza symbol Legendre'a. Jeśli zastąpimy symbol Legendre'a symbolem Jacobiego, to będziemy mogli badać prawdziwość tego twierdzenia dla liczb złożonych i łatwo przekonamy się, że dla pewnych liczb złożonych [math]\displaystyle{ m }[/math] kongruencja
- [math]\displaystyle{ U_{m - (D \mid m)} \equiv 0 \pmod{m} }[/math]
również jest prawdziwa. Prowadzi to definicji liczb pseudopierwszych Lucasa.
Definicja N22
Powiemy, że liczba złożona nieparzysta [math]\displaystyle{ m }[/math] jest liczbą pseudopierwszą Lucasa dla parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math] (symbolicznie: LPSP( [math]\displaystyle{ P, Q }[/math] )), jeżeli [math]\displaystyle{ \gcd (m, Q D) = 1 }[/math] i
- [math]\displaystyle{ U_{m - (D \mid m)} \equiv 0 \pmod{m} }[/math]
gdzie [math]\displaystyle{ (D \mid m) }[/math] oznacza symbol Jacobiego.
Twierdzenie N23
Jeżeli liczba złożona nieparzysta [math]\displaystyle{ m }[/math] jest liczbą pseudopierwszą Lucasa dla parametrów [math]\displaystyle{ P = a + 1 }[/math] i [math]\displaystyle{ Q = a }[/math], gdzie [math]\displaystyle{ a \geqslant 2 }[/math], to jest liczbą pseudopierwszą Fermata przy podstawie [math]\displaystyle{ a }[/math].
Uwaga N24
Wykorzystując funkcje jacobi(a, n)
i modLucas(n, P, Q, m)
(zobacz J48, N15) możemy napisać prosty program, który sprawdza, czy dla liczby nieparzystej [math]\displaystyle{ m }[/math] prawdziwe jest twierdzenie N20.
isPrimeOrLPSP(m, P, Q) =
{
local(D, js);
D = P^2 - 4*Q;
if( gcd(m, 2*Q*D) > 1, return(0) );
js = jacobi(D, m);
if( modLucas(m - js, P, Q, m)[1] == 0, return(1), return(0) );
}
Przykład N25
Poniższa tabela zawiera najmniejsze liczby pseudopierwsze Lucasa dla różnych parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math]
[math]\displaystyle{ \boldsymbol{P} }[/math]
[math]\displaystyle{ \boldsymbol{Q} }[/math][math]\displaystyle{ \boldsymbol{1} }[/math] [math]\displaystyle{ \boldsymbol{2} }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ \boldsymbol{6} }[/math] [math]\displaystyle{ \boldsymbol{7} }[/math] [math]\displaystyle{ \boldsymbol{8} }[/math] [math]\displaystyle{ \boldsymbol{9} }[/math] [math]\displaystyle{ \boldsymbol{10} }[/math] [math]\displaystyle{ \boldsymbol{- 5} }[/math] [math]\displaystyle{ 253 }[/math] [math]\displaystyle{ 121 }[/math] [math]\displaystyle{ 57 }[/math] [math]\displaystyle{ 217 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 69 }[/math] [math]\displaystyle{ 121 }[/math] [math]\displaystyle{ 253 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 143 }[/math] [math]\displaystyle{ \boldsymbol{- 4} }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 91 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 15 }[/math] [math]\displaystyle{ 119 }[/math] [math]\displaystyle{ 57 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ \boldsymbol{- 3} }[/math] [math]\displaystyle{ 217 }[/math] [math]\displaystyle{ 91 }[/math] [math]\displaystyle{ 527 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 65 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ \boldsymbol{- 2} }[/math] [math]\displaystyle{ 341 }[/math] [math]\displaystyle{ 209 }[/math] [math]\displaystyle{ 39 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 15 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 85 }[/math] [math]\displaystyle{ \boldsymbol{- 1} }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 119 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 143 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 33 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 15 }[/math] [math]\displaystyle{ \boldsymbol{1} }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ }[/math] [math]\displaystyle{ 21 }[/math] [math]\displaystyle{ 65 }[/math] [math]\displaystyle{ 115 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 209 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ \boldsymbol{2} }[/math] [math]\displaystyle{ 1541 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 341 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 21 }[/math] [math]\displaystyle{ 85 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 15 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ 629 }[/math] [math]\displaystyle{ 559 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 91 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 55 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ 119 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 209 }[/math] [math]\displaystyle{ }[/math] [math]\displaystyle{ 85 }[/math] [math]\displaystyle{ 21 }[/math] [math]\displaystyle{ 119 }[/math] [math]\displaystyle{ 65 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 115 }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 143 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 143 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 217 }[/math] [math]\displaystyle{ 39 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math]
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których [math]\displaystyle{ (D \mid m) = - 1 }[/math].
Przykład N26
Ilość liczb LPSP([math]\displaystyle{ P, Q }[/math]) mniejszych od [math]\displaystyle{ 10^9 }[/math]
[math]\displaystyle{ \boldsymbol{P} }[/math]
[math]\displaystyle{ \boldsymbol{Q} }[/math][math]\displaystyle{ \boldsymbol{1} }[/math] [math]\displaystyle{ \boldsymbol{2} }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ \boldsymbol{6} }[/math] [math]\displaystyle{ \boldsymbol{7} }[/math] [math]\displaystyle{ \boldsymbol{8} }[/math] [math]\displaystyle{ \boldsymbol{9} }[/math] [math]\displaystyle{ \boldsymbol{10} }[/math] [math]\displaystyle{ \boldsymbol{- 5} }[/math] [math]\displaystyle{ 4266 }[/math] [math]\displaystyle{ 4935 }[/math] [math]\displaystyle{ 4278 }[/math] [math]\displaystyle{ 4981 }[/math] [math]\displaystyle{ 6363 }[/math] [math]\displaystyle{ 6028 }[/math] [math]\displaystyle{ 5202 }[/math] [math]\displaystyle{ 4426 }[/math] [math]\displaystyle{ 5832 }[/math] [math]\displaystyle{ 6027 }[/math] [math]\displaystyle{ \boldsymbol{- 4} }[/math] [math]\displaystyle{ 4599 }[/math] [math]\displaystyle{ 4152 }[/math] [math]\displaystyle{ 9272 }[/math] [math]\displaystyle{ 5886 }[/math] [math]\displaystyle{ 6958 }[/math] [math]\displaystyle{ 4563 }[/math] [math]\displaystyle{ 5600 }[/math] [math]\displaystyle{ 9509 }[/math] [math]\displaystyle{ 7007 }[/math] [math]\displaystyle{ 4142 }[/math] [math]\displaystyle{ \boldsymbol{- 3} }[/math] [math]\displaystyle{ 4265 }[/math] [math]\displaystyle{ 5767 }[/math] [math]\displaystyle{ 4241 }[/math] [math]\displaystyle{ 5114 }[/math] [math]\displaystyle{ 5859 }[/math] [math]\displaystyle{ 7669 }[/math] [math]\displaystyle{ 6083 }[/math] [math]\displaystyle{ 6120 }[/math] [math]\displaystyle{ 4420 }[/math] [math]\displaystyle{ 5096 }[/math] [math]\displaystyle{ \boldsymbol{- 2} }[/math] [math]\displaystyle{ 5361 }[/math] [math]\displaystyle{ 4389 }[/math] [math]\displaystyle{ 5063 }[/math] [math]\displaystyle{ 5632 }[/math] [math]\displaystyle{ 5364 }[/math] [math]\displaystyle{ 5228 }[/math] [math]\displaystyle{ 5859 }[/math] [math]\displaystyle{ 10487 }[/math] [math]\displaystyle{ 5370 }[/math] [math]\displaystyle{ 9798 }[/math] [math]\displaystyle{ \boldsymbol{- 1} }[/math] [math]\displaystyle{ 4152 }[/math] [math]\displaystyle{ 5886 }[/math] [math]\displaystyle{ 4563 }[/math] [math]\displaystyle{ 9509 }[/math] [math]\displaystyle{ 4142 }[/math] [math]\displaystyle{ 6273 }[/math] [math]\displaystyle{ 5773 }[/math] [math]\displaystyle{ 4497 }[/math] [math]\displaystyle{ 5166 }[/math] [math]\displaystyle{ 5305 }[/math] [math]\displaystyle{ \boldsymbol{1} }[/math] [math]\displaystyle{ 282485800 }[/math] [math]\displaystyle{ }[/math] [math]\displaystyle{ 6567 }[/math] [math]\displaystyle{ 7669 }[/math] [math]\displaystyle{ 7131 }[/math] [math]\displaystyle{ 10882 }[/math] [math]\displaystyle{ 8626 }[/math] [math]\displaystyle{ 8974 }[/math] [math]\displaystyle{ 8509 }[/math] [math]\displaystyle{ 8752 }[/math] [math]\displaystyle{ \boldsymbol{2} }[/math] [math]\displaystyle{ 7803 }[/math] [math]\displaystyle{ 449152466 }[/math] [math]\displaystyle{ 5597 }[/math] [math]\displaystyle{ 5886 }[/math] [math]\displaystyle{ 6509 }[/math] [math]\displaystyle{ 5761 }[/math] [math]\displaystyle{ 8115 }[/math] [math]\displaystyle{ 6945 }[/math] [math]\displaystyle{ 8380 }[/math] [math]\displaystyle{ 7095 }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ 5974 }[/math] [math]\displaystyle{ 8768 }[/math] [math]\displaystyle{ 282485800 }[/math] [math]\displaystyle{ 5767 }[/math] [math]\displaystyle{ 5651 }[/math] [math]\displaystyle{ 5632 }[/math] [math]\displaystyle{ 6640 }[/math] [math]\displaystyle{ 5725 }[/math] [math]\displaystyle{ 6058 }[/math] [math]\displaystyle{ 7050 }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ 10749 }[/math] [math]\displaystyle{ 282485800 }[/math] [math]\displaystyle{ 14425 }[/math] [math]\displaystyle{ }[/math] [math]\displaystyle{ 9735 }[/math] [math]\displaystyle{ 6567 }[/math] [math]\displaystyle{ 8164 }[/math] [math]\displaystyle{ 7669 }[/math] [math]\displaystyle{ 7608 }[/math] [math]\displaystyle{ 7131 }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ 5047 }[/math] [math]\displaystyle{ 15127 }[/math] [math]\displaystyle{ 6155 }[/math] [math]\displaystyle{ 15127 }[/math] [math]\displaystyle{ 4152 }[/math] [math]\displaystyle{ 5146 }[/math] [math]\displaystyle{ 4423 }[/math] [math]\displaystyle{ 5526 }[/math] [math]\displaystyle{ 6289 }[/math] [math]\displaystyle{ 9509 }[/math]
Uwaga N27
Dla [math]\displaystyle{ (P, Q) = (1, 1) }[/math] ciąg Lucasa [math]\displaystyle{ (U_n) }[/math] ma postać
- [math]\displaystyle{ (U_n) = (0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, \ldots) }[/math]
Stosując indukcję matematyczną, udowodnimy, że [math]\displaystyle{ U_{3 k} = 0 }[/math]. Łatwo sprawdzamy, że dla [math]\displaystyle{ k = 0 }[/math] i [math]\displaystyle{ k = 1 }[/math] wzór jest prawdziwy. Zakładając prawdziwość wzoru dla wszystkich liczb naturalnych nie większych od [math]\displaystyle{ k }[/math], otrzymujemy dla [math]\displaystyle{ k + 1 }[/math] (zobacz N13 p.3)
- [math]\displaystyle{ U_{3 (k + 1)} = U_{3 k + 3} = U_{3 k} V_3 - U_{3 (k - 1)} = 0 }[/math]
Co kończy dowód. Zbadajmy liczby pseudopierwsze Lucasa dla [math]\displaystyle{ (P, Q) = (1, 1) }[/math].
Mamy [math]\displaystyle{ D = P^2 - 4 Q = - 3 }[/math]. Wynika stąd, że nie może być [math]\displaystyle{ 3 \mid m }[/math], bo mielibyśmy [math]\displaystyle{ \gcd (m, Q D) = 3 \gt 1 }[/math].
Z zadania J46 wiemy, że
- [math]\displaystyle{ (- 3 \mid m) = \begin{cases} \;\;\: 1 & \text{gdy } m = 6 k + 1 \\ \;\;\: 0 & \text{gdy } m = 6 k + 3 \\ - 1 & \text{gdy } m = 6 k + 5 \\ \end{cases} }[/math]
Ponieważ [math]\displaystyle{ 3 \nmid m }[/math], to wystarczy zbadać przypadki [math]\displaystyle{ m = 6 k + 1 }[/math] i [math]\displaystyle{ m = 6 k + 5 }[/math]. W pierwszym przypadku jest
- [math]\displaystyle{ U_{m - (- 3 \mid m)} = U_{6 k + 1 - 1} = U_{6 k} = 0 }[/math]
W drugim przypadku, gdy [math]\displaystyle{ m = 6 k + 5 }[/math], dostajemy
- [math]\displaystyle{ U_{m - (- 3 \mid m)} = U_{6 k + 5 + 1} = U_{6 (k + 1)} = 0 }[/math]
Zatem dla dowolnej liczby nieparzystej [math]\displaystyle{ m }[/math] niepodzielnej przez [math]\displaystyle{ 3 }[/math] jest
- [math]\displaystyle{ U_{m - (- 3 \mid m)} \equiv 0 \pmod{m} }[/math]
Czyli liczbami pseudopierwszymi Lucasa dla parametrów [math]\displaystyle{ (P, Q) = (1, 1) }[/math] będą liczby nieparzyste [math]\displaystyle{ m }[/math], które nie są podzielne przez [math]\displaystyle{ 3 }[/math] i nie są liczbami pierwszymi. Ilość takich liczb nie większych od [math]\displaystyle{ 10^k }[/math] możemy łatwo znaleźć poleceniem
for(k = 1, 9, s = 0; forstep(m = 3, 10^k, 2, if( m%6 <> 3, s = s + !isprime(m) )); print(s))
Zadanie N28
Pokazać, że ilość liczb pseudopierwszych Lucasa dla parametrów [math]\displaystyle{ (P, Q) = (2, 2) }[/math] nie większych od [math]\displaystyle{ 10^k }[/math] możemy znaleźć poleceniem
for(k = 1, 9, s = 0; forstep(m = 3, 10^k, 2, s = s + !isprime(m)); print(s))
Metoda Selfridge'a wyboru parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math]
Uwaga N29
Twierdzenie N20 możemy wykorzystać do testowania pierwszości liczb. Ponieważ musi być spełniony warunek [math]\displaystyle{ \gcd (m, Q D) = 1 }[/math], to nie każda para liczb [math]\displaystyle{ P, Q }[/math] (np. wybrana losowo) nadaje się do przeprowadzenia testu. Zawsze będziemy zmuszeni określić zasadę postępowania, która doprowadzi do wyboru właściwej pary [math]\displaystyle{ P, Q }[/math].
Robert Baillie i Samuel Wagstaff przedstawili[1] dwie metody wyboru parametrów dla testu Lucasa. Ograniczymy się do omówienia tylko pierwszej z nich (metodę zaproponował John Selfridge).
Rozważmy ciąg [math]\displaystyle{ a_k = (- 1)^k (2 k + 1) }[/math], gdzie [math]\displaystyle{ k \geqslant 2 }[/math], czyli [math]\displaystyle{ a_k = (5, - 7, 9, - 11, 13, - 15, \ldots) }[/math]. Niech [math]\displaystyle{ D }[/math] będzie pierwszym wyrazem ciągu [math]\displaystyle{ (a_k) }[/math], dla którego jest [math]\displaystyle{ (a_k \mid m) = - 1 }[/math]. Dla tak ustalonego [math]\displaystyle{ D }[/math] przyjmujemy [math]\displaystyle{ P = 1 }[/math] i [math]\displaystyle{ Q = (1 - D) / 4 }[/math].
Tabela przedstawia początkowe wartości [math]\displaystyle{ Q }[/math], jakie otrzymamy, stosując tę metodę.
[math]\displaystyle{ \boldsymbol{k} }[/math] [math]\displaystyle{ 2 }[/math] [math]\displaystyle{ 3 }[/math] [math]\displaystyle{ 4 }[/math] [math]\displaystyle{ 5 }[/math] [math]\displaystyle{ 6 }[/math] [math]\displaystyle{ 7 }[/math] [math]\displaystyle{ 8 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 10 }[/math] [math]\displaystyle{ 11 }[/math] [math]\displaystyle{ 12 }[/math] [math]\displaystyle{ 13 }[/math] [math]\displaystyle{ 14 }[/math] [math]\displaystyle{ 15 }[/math] [math]\displaystyle{ 16 }[/math] [math]\displaystyle{ 17 }[/math] [math]\displaystyle{ 18 }[/math] [math]\displaystyle{ 19 }[/math] [math]\displaystyle{ 20 }[/math] [math]\displaystyle{ \boldsymbol{a_k} }[/math] [math]\displaystyle{ 5 }[/math] [math]\displaystyle{ -7 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ -11 }[/math] [math]\displaystyle{ 13 }[/math] [math]\displaystyle{ -15 }[/math] [math]\displaystyle{ 17 }[/math] [math]\displaystyle{ -19 }[/math] [math]\displaystyle{ 21 }[/math] [math]\displaystyle{ -23 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ -27 }[/math] [math]\displaystyle{ 29 }[/math] [math]\displaystyle{ -31 }[/math] [math]\displaystyle{ 33 }[/math] [math]\displaystyle{ -35 }[/math] [math]\displaystyle{ 37 }[/math] [math]\displaystyle{ -39 }[/math] [math]\displaystyle{ 41 }[/math] [math]\displaystyle{ \boldsymbol{Q} }[/math] [math]\displaystyle{ -1 }[/math] [math]\displaystyle{ 2 }[/math] [math]\displaystyle{ -2 }[/math] [math]\displaystyle{ 3 }[/math] [math]\displaystyle{ -3 }[/math] [math]\displaystyle{ 4 }[/math] [math]\displaystyle{ -4 }[/math] [math]\displaystyle{ 5 }[/math] [math]\displaystyle{ -5 }[/math] [math]\displaystyle{ 6 }[/math] [math]\displaystyle{ -6 }[/math] [math]\displaystyle{ 7 }[/math] [math]\displaystyle{ -7 }[/math] [math]\displaystyle{ 8 }[/math] [math]\displaystyle{ -8 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ -9 }[/math] [math]\displaystyle{ 10 }[/math] [math]\displaystyle{ -10 }[/math]
Zauważmy, że
- jeżeli liczba nieparzysta [math]\displaystyle{ m }[/math] jest liczbą kwadratową, to wybór [math]\displaystyle{ D }[/math] nie będzie możliwy
- w przypadku zastosowania tej metody znajdziemy tylko liczby pierwsze lub pseudopierwsze Lucasa, które spełniają kongruencję [math]\displaystyle{ U_{m + 1} \equiv 0 \pmod{m} }[/math], czyli tylko część liczb pseudopierwszych Lucasa określonych w definicji N22
Ponieważ Baillie i Wagstaff określili metodę zaproponowaną przez Selfridge'a jako metodę A, to pozostaniemy przy tej nazwie. Korzystając ze wzoru rekurencyjnego
- [math]\displaystyle{ a_{k+1} = \begin{cases} \qquad \qquad 5 & \text{gdy } k = 1 \\ - a_k - 2 * \mathop{\textnormal{sign}}( a_k ) & \text{gdy } k \geqslant 2 \\ \end{cases} }[/math]
możemy łatwo napisać odpowiednią funkcję znajdującą liczby [math]\displaystyle{ P, Q }[/math] według tej metody.
MethodA(m) =
{
local(a, js);
a = 5;
while( 1,
js = jacobi(a, m);
if( js == 0 && a % m <> 0, return([0, 0]) );
if( js == -1, return([1, (1 - a)/4]) );
a = -a - 2*sign(a);
);
}
Wyjaśnienia wymaga druga linia kodu w pętli while
. Wiemy, że (zobacz J42)
- [math]\displaystyle{ (a \mid m) = 0 \quad \qquad \Longleftrightarrow \quad \qquad \gcd (a, m) \gt 1 }[/math]
Jednak z faktu, że [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] nie wynika natychmiast, że liczba [math]\displaystyle{ m }[/math] jest liczbą złożoną. Rozważmy dwa przypadki: gdy [math]\displaystyle{ m \mid a }[/math] i [math]\displaystyle{ m \nmid a }[/math].
Gdy [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] i [math]\displaystyle{ m \mid a }[/math], to [math]\displaystyle{ \gcd (a, m) = \gcd (k \cdot m, m) = m \gt 1 }[/math] i nie jesteśmy w stanie rozstrzygnąć, czy liczba [math]\displaystyle{ m }[/math] jest liczbą pierwszą, czy złożoną. Widać to dobrze na prostych przykładach
- [math]\displaystyle{ \gcd (7, 7) = \gcd (14, 7) = 7 \gt 1 }[/math]
- [math]\displaystyle{ \gcd (15, 15) = \gcd (30, 15) = 15 \gt 1 }[/math]
Gdy [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] i [math]\displaystyle{ m \nmid a }[/math], to [math]\displaystyle{ m }[/math] jest liczbą złożoną. Ponieważ [math]\displaystyle{ m \nmid a }[/math], to [math]\displaystyle{ a = k \cdot m + r }[/math], gdzie [math]\displaystyle{ r \in [1, m - 1] }[/math]. Mamy
- [math]\displaystyle{ \gcd (a, m) = \gcd (k \cdot m + r, m) = \gcd (r, m) = d }[/math]
Musi być [math]\displaystyle{ d \gt 1 }[/math], bo założyliśmy, że [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] i musi być [math]\displaystyle{ d \lt m }[/math], bo [math]\displaystyle{ d \leqslant r \leqslant m - 1 }[/math]. Zatem [math]\displaystyle{ d }[/math] jest dzielnikiem nietrywialnym liczby [math]\displaystyle{ m }[/math] i [math]\displaystyle{ m }[/math] jest liczbą złożoną.
Omawiana linia kodu zapewnia wysłanie informacji o tym, że liczba [math]\displaystyle{ m }[/math] jest liczbą złożoną (zwrot wektora [0, 0]). W przypadku, gdy nie mamy takiej pewności, kontynuujemy szukanie liczby [math]\displaystyle{ a }[/math], takiej że [math]\displaystyle{ (a \mid m) = - 1 }[/math], pozostawiając zbadanie pierwszości liczby [math]\displaystyle{ m }[/math] na kolejnym etapie testowania.
Uważny Czytelnik dostrzeże, że nie zbadaliśmy, czy spełniony jest warunek [math]\displaystyle{ \gcd (m, Q) = 1 }[/math]. Nie musimy tego robić, bo zwracana przez funkcję MethodA()
liczba [math]\displaystyle{ Q }[/math] jest względnie pierwsza z [math]\displaystyle{ m }[/math]. Omówimy ten problem dokładnie w zadaniu N30. Poniżej pokażemy, że nawet gdyby było [math]\displaystyle{ \gcd (m, Q) \gt 1 }[/math], to złożona liczba [math]\displaystyle{ m }[/math] nie zostanie uznana za liczbę pseudopierwszą Lucasa.
Zauważmy, że jeżeli [math]\displaystyle{ m }[/math] jest liczbą złożoną i ma dzielnik pierwszy [math]\displaystyle{ p \lt m }[/math], który dzieli [math]\displaystyle{ Q }[/math], to [math]\displaystyle{ p \mid Q }[/math] i [math]\displaystyle{ p \nmid P }[/math] (bo [math]\displaystyle{ P = 1 }[/math]), zatem [math]\displaystyle{ p \nmid U_k }[/math] dla [math]\displaystyle{ k \geqslant 1 }[/math] (zobacz N17), czyli nie może być
- [math]\displaystyle{ U_{m + 1} (1, Q) \equiv 0 \pmod{m} }[/math]
bo mielibyśmy
- [math]\displaystyle{ U_{m + 1} (1, Q) \equiv 0 \pmod{p} }[/math]
a to jest niemożliwe. Zatem program wykorzystujący twierdzenie N20 wykryje złożoność liczby [math]\displaystyle{ m }[/math].
Łatwo pokażemy, że nie jest możliwe, aby liczba [math]\displaystyle{ m }[/math] była liczbą pierwszą i była dzielnikiem [math]\displaystyle{ Q }[/math]. Jeżeli [math]\displaystyle{ m }[/math] jest liczbą pierwszą, to istnieje dokładnie [math]\displaystyle{ \tfrac{m - 1}{2} }[/math] liczb kwadratowych modulo [math]\displaystyle{ p }[/math] i [math]\displaystyle{ \tfrac{m - 1}{2} }[/math] liczb niekwadratowych modulo [math]\displaystyle{ p }[/math], zatem rozpoczynając od wyrazu [math]\displaystyle{ a_2 }[/math] możemy dojść co najwyżej do wyrazu o indeksie [math]\displaystyle{ k = \tfrac{m - 1}{2} + 2 }[/math], czyli
- [math]\displaystyle{ | a_k | \leqslant m + 4 }[/math]
Skąd wynika, że
- [math]\displaystyle{ | Q | = \left| {\small\frac{1 - a_k}{4}} \right| \leqslant {\small\frac{m + 5}{4}} \lt m }[/math]
Ostatnia nierówność jest prawdziwa dla [math]\displaystyle{ m \gt {\small\frac{5}{3}} }[/math], czyli dla wszystkich liczb pierwszych. Ponieważ [math]\displaystyle{ | Q | \lt m }[/math], w przypadku gdy [math]\displaystyle{ m }[/math] jest liczbą pierwszą, to [math]\displaystyle{ m }[/math] nie może być dzielnikiem liczby [math]\displaystyle{ Q }[/math].
Zadanie N30
Pokazać, że w przypadku, gdy dla kolejnych liczb [math]\displaystyle{ a_k = (- 1)^k (2 k + 1) }[/math] sprawdzamy, czy konsekwencją [math]\displaystyle{ (a_k \mid m) = 0 }[/math] jest złożoność liczby [math]\displaystyle{ m }[/math], to dla każdej liczby [math]\displaystyle{ Q }[/math] wyznaczonej metodą Selfridge'a jest [math]\displaystyle{ \gcd (Q, m) = 1 }[/math].
Zadanie N31
Zmodyfikujmy metodę Selfridge'a w taki sposób, że będziemy rozpoczynali próby nie od wyrazu [math]\displaystyle{ a_2 = 5 }[/math], ale od wyrazu [math]\displaystyle{ a_3 = - 7 }[/math]. Pokazać, że w przypadku, gdy dla kolejnych liczb [math]\displaystyle{ a_k = (- 1)^k (2 k + 1) }[/math] sprawdzamy, czy konsekwencją [math]\displaystyle{ (a_k \mid m) = 0 }[/math] jest złożoność liczby [math]\displaystyle{ m }[/math], to dla każdej liczby [math]\displaystyle{ Q }[/math] wyznaczonej tak zmodyfikowaną metodą Selfridge'a jest [math]\displaystyle{ \gcd (Q, m) = 1 }[/math].
Uwaga N32
Przyjmując metodę Selfridge'a wyboru parametrów [math]\displaystyle{ P, Q }[/math] dla testu Lucasa, możemy łatwo napisać odpowiedni program w PARI/GP testujący pierwszość liczb
LucasTest(m) =
{
local(P, Q, X);
if( m % 2 == 0, return(m == 2) );
if( issquare(m), return(0) ); \\ sprawdzamy, czy m nie jest liczbą kwadratową
X = MethodA(m);
P = X[1];
Q = X[2];
if( P == 0, return(0) ); \\ jeżeli P = 0, to m jest liczbą złożoną
if( modLucas(m + 1, P, Q, m)[1] == 0, return(1), return(0) );
}
Uwaga N33
Najmniejsze liczby pseudopierwsze Lucasa, które pojawiają się przy zastosowaniu metody Selfridge'a wyboru parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math], to
- [math]\displaystyle{ 323, 377, 1159, 1829, 3827, 5459, 5777, 9071, 9179, 10877, 11419, 11663, 13919, 14839, 16109, 16211, 18407, 18971, 19043, 22499, \ldots }[/math]
Tabela przedstawia ilość takich liczb nie większych od [math]\displaystyle{ 10^n }[/math]
[math]\displaystyle{ \boldsymbol{n} }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ \boldsymbol{6} }[/math] [math]\displaystyle{ \boldsymbol{7} }[/math] [math]\displaystyle{ \boldsymbol{8} }[/math] [math]\displaystyle{ \boldsymbol{9} }[/math] #LPSP [math]\displaystyle{ \lt 10^n }[/math] (metoda Selfridge'a) [math]\displaystyle{ 2 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 57 }[/math] [math]\displaystyle{ 219 }[/math] [math]\displaystyle{ 659 }[/math] [math]\displaystyle{ 1911 }[/math] [math]\displaystyle{ 5485 }[/math]
Liczby silnie pseudopierwsze Lucasa
Twierdzenie N34
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą taką, że [math]\displaystyle{ \gcd (p, Q D) = 1 }[/math] oraz [math]\displaystyle{ p - (D \mid p) = 2^r w }[/math], gdzie [math]\displaystyle{ w }[/math] jest liczbą nieparzystą, to spełniony jest dokładnie jeden z warunków
- [math]\displaystyle{ U_w \equiv 0 \pmod{p} }[/math]
lub
- [math]\displaystyle{ V_{2^k w} \equiv 0 \pmod{p} \qquad }[/math] dla pewnego [math]\displaystyle{ k \in [0, r - 1] }[/math]
Konsekwentnie definiujemy liczby pseudopierwsze
Definicja N35
Powiemy, że liczba złożona nieparzysta [math]\displaystyle{ m }[/math] jest liczbą silnie pseudopierwszą Lucasa (SLPSP) dla parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math], jeżeli [math]\displaystyle{ \gcd (m, Q D) = 1 }[/math] oraz [math]\displaystyle{ m - (D \mid m) = 2^r w }[/math], gdzie [math]\displaystyle{ w }[/math] jest liczbą nieparzystą i spełniony jest jeden z warunków
- [math]\displaystyle{ U_w \equiv 0 \pmod{m} }[/math]
lub
- [math]\displaystyle{ V_{2^k w} \equiv 0 \pmod{m} \; }[/math] dla pewnego [math]\displaystyle{ k \in [0, r - 1] }[/math]
Uwaga N36
Każda liczba SLPSP([math]\displaystyle{ P, Q }[/math]) jest LPSP([math]\displaystyle{ P, Q }[/math]). Korzystając ze zdefiniowanych wcześniej funkcji: modPower(a, n, m)
, jacobi(a, n)
i modLucas(n, P, Q, m)
(zobacz M2, J48, N15), możemy napisać prosty program, który sprawdza, czy liczba [math]\displaystyle{ m }[/math] spełnia jeden z warunków podanych w twierdzeniu N34.
isPrimeOrSLPSP(m, P, Q) =
{
local(a, b, c, D, js, k, r, w, X);
D = P^2 - 4*Q;
if( gcd(m, 2*Q*D) > 1, return(0) );
js = jacobi(D, m);
r = valuation(m - js, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m - js
w = (m - js) / 2^r;
X = modLucas(w, P, Q, m);
a = X[1]; \\ U_w(P, Q) % m
b = X[2]; \\ V_w(P, Q) % m
if( a == 0 || b == 0, return(1) ); \\ b == 0 to przypadek k == 0
if( r == 1, return(0) ); \\ nie ma dalszych przypadków
c = modPower(Q, w, m); \\ Q^w % m
k = 0;
\\ sprawdzamy warunek V_(2^k * w) % m = 0; korzystamy ze wzoru V_(2*t) = (V_t)^2 - 2*Q^t
while( k++ < r,
b = (b^2 - 2*c) % m;
if( b == 0, return(1) );
c = c^2 % m;
);
return(0);
}
Przykład N37
Poniższa tabela zawiera najmniejsze liczby silnie pseudopierwsze Lucasa dla różnych parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math]
[math]\displaystyle{ \boldsymbol{P} }[/math]
[math]\displaystyle{ \boldsymbol{Q} }[/math][math]\displaystyle{ \boldsymbol{1} }[/math] [math]\displaystyle{ \boldsymbol{2} }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ \boldsymbol{6} }[/math] [math]\displaystyle{ \boldsymbol{7} }[/math] [math]\displaystyle{ \boldsymbol{8} }[/math] [math]\displaystyle{ \boldsymbol{9} }[/math] [math]\displaystyle{ \boldsymbol{10} }[/math] [math]\displaystyle{ \boldsymbol{- 5} }[/math] [math]\displaystyle{ 253 }[/math] [math]\displaystyle{ 121 }[/math] [math]\displaystyle{ 143 }[/math] [math]\displaystyle{ 781 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 299 }[/math] [math]\displaystyle{ 121 }[/math] [math]\displaystyle{ 407 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 143 }[/math] [math]\displaystyle{ \boldsymbol{- 4} }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 4181 }[/math] [math]\displaystyle{ 341 }[/math] [math]\displaystyle{ 169 }[/math] [math]\displaystyle{ 33 }[/math] [math]\displaystyle{ 119 }[/math] [math]\displaystyle{ 57 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ \boldsymbol{- 3} }[/math] [math]\displaystyle{ 799 }[/math] [math]\displaystyle{ 121 }[/math] [math]\displaystyle{ 527 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 85 }[/math] [math]\displaystyle{ 209 }[/math] [math]\displaystyle{ 55 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 169 }[/math] [math]\displaystyle{ 529 }[/math] [math]\displaystyle{ \boldsymbol{- 2} }[/math] [math]\displaystyle{ 2047 }[/math] [math]\displaystyle{ 989 }[/math] [math]\displaystyle{ 161 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 265 }[/math] [math]\displaystyle{ \boldsymbol{- 1} }[/math] [math]\displaystyle{ 4181 }[/math] [math]\displaystyle{ 169 }[/math] [math]\displaystyle{ 119 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 629 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 33 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 51 }[/math] [math]\displaystyle{ \boldsymbol{1} }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 209 }[/math] [math]\displaystyle{ 527 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 559 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ \boldsymbol{2} }[/math] [math]\displaystyle{ 5459 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 2047 }[/math] [math]\displaystyle{ 169 }[/math] [math]\displaystyle{ 21 }[/math] [math]\displaystyle{ 253 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 15 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ 899 }[/math] [math]\displaystyle{ 5983 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 121 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ 55 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 35 }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ 899 }[/math] [math]\displaystyle{ 25 }[/math] [math]\displaystyle{ 1541 }[/math] [math]\displaystyle{ }[/math] [math]\displaystyle{ 341 }[/math] [math]\displaystyle{ 323 }[/math] [math]\displaystyle{ 377 }[/math] [math]\displaystyle{ 209 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 527 }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 527 }[/math] [math]\displaystyle{ 49 }[/math] [math]\displaystyle{ 527 }[/math] [math]\displaystyle{ 4181 }[/math] [math]\displaystyle{ 781 }[/math] [math]\displaystyle{ 39 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math] [math]\displaystyle{ 9 }[/math]
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których [math]\displaystyle{ (D \mid m) = - 1 }[/math].
Przykład N38
Ilość liczb SLPSP([math]\displaystyle{ P, Q }[/math]) mniejszych od [math]\displaystyle{ 10^9 }[/math]
[math]\displaystyle{ \boldsymbol{P} }[/math]
[math]\displaystyle{ \boldsymbol{Q} }[/math][math]\displaystyle{ \boldsymbol{1} }[/math] [math]\displaystyle{ \boldsymbol{2} }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ \boldsymbol{6} }[/math] [math]\displaystyle{ \boldsymbol{7} }[/math] [math]\displaystyle{ \boldsymbol{8} }[/math] [math]\displaystyle{ \boldsymbol{9} }[/math] [math]\displaystyle{ \boldsymbol{10} }[/math] [math]\displaystyle{ \boldsymbol{- 5} }[/math] [math]\displaystyle{ 1056 }[/math] [math]\displaystyle{ 1231 }[/math] [math]\displaystyle{ 1184 }[/math] [math]\displaystyle{ 1264 }[/math] [math]\displaystyle{ 2278 }[/math] [math]\displaystyle{ 1284 }[/math] [math]\displaystyle{ 1181 }[/math] [math]\displaystyle{ 1174 }[/math] [math]\displaystyle{ 1281 }[/math] [math]\displaystyle{ 1429 }[/math] [math]\displaystyle{ \boldsymbol{- 4} }[/math] [math]\displaystyle{ 1043 }[/math] [math]\displaystyle{ 1165 }[/math] [math]\displaystyle{ 2139 }[/math] [math]\displaystyle{ 1316 }[/math] [math]\displaystyle{ 1151 }[/math] [math]\displaystyle{ 1079 }[/math] [math]\displaystyle{ 1112 }[/math] [math]\displaystyle{ 2377 }[/math] [math]\displaystyle{ 1197 }[/math] [math]\displaystyle{ 989 }[/math] [math]\displaystyle{ \boldsymbol{- 3} }[/math] [math]\displaystyle{ 952 }[/math] [math]\displaystyle{ 1514 }[/math] [math]\displaystyle{ 1055 }[/math] [math]\displaystyle{ 1153 }[/math] [math]\displaystyle{ 1135 }[/math] [math]\displaystyle{ 2057 }[/math] [math]\displaystyle{ 998 }[/math] [math]\displaystyle{ 1202 }[/math] [math]\displaystyle{ 1077 }[/math] [math]\displaystyle{ 1112 }[/math] [math]\displaystyle{ \boldsymbol{- 2} }[/math] [math]\displaystyle{ 1282 }[/math] [math]\displaystyle{ 1092 }[/math] [math]\displaystyle{ 1212 }[/math] [math]\displaystyle{ 1510 }[/math] [math]\displaystyle{ 1155 }[/math] [math]\displaystyle{ 1179 }[/math] [math]\displaystyle{ 1173 }[/math] [math]\displaystyle{ 2240 }[/math] [math]\displaystyle{ 1089 }[/math] [math]\displaystyle{ 2109 }[/math] [math]\displaystyle{ \boldsymbol{- 1} }[/math] [math]\displaystyle{ 1165 }[/math] [math]\displaystyle{ 1316 }[/math] [math]\displaystyle{ 1079 }[/math] [math]\displaystyle{ 2377 }[/math] [math]\displaystyle{ 989 }[/math] [math]\displaystyle{ 1196 }[/math] [math]\displaystyle{ 1129 }[/math] [math]\displaystyle{ 1050 }[/math] [math]\displaystyle{ 1055 }[/math] [math]\displaystyle{ 1147 }[/math] [math]\displaystyle{ \boldsymbol{1} }[/math] [math]\displaystyle{ 282485800 }[/math] [math]\displaystyle{ }[/math] [math]\displaystyle{ 2278 }[/math] [math]\displaystyle{ 2057 }[/math] [math]\displaystyle{ 2113 }[/math] [math]\displaystyle{ 2266 }[/math] [math]\displaystyle{ 4053 }[/math] [math]\displaystyle{ 2508 }[/math] [math]\displaystyle{ 2285 }[/math] [math]\displaystyle{ 3083 }[/math] [math]\displaystyle{ \boldsymbol{2} }[/math] [math]\displaystyle{ 1776 }[/math] [math]\displaystyle{ 449152466 }[/math] [math]\displaystyle{ 1282 }[/math] [math]\displaystyle{ 1316 }[/math] [math]\displaystyle{ 1645 }[/math] [math]\displaystyle{ 1413 }[/math] [math]\displaystyle{ 1564 }[/math] [math]\displaystyle{ 1595 }[/math] [math]\displaystyle{ 1683 }[/math] [math]\displaystyle{ 1435 }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ 1621 }[/math] [math]\displaystyle{ 1553 }[/math] [math]\displaystyle{ 282485800 }[/math] [math]\displaystyle{ 1514 }[/math] [math]\displaystyle{ 1530 }[/math] [math]\displaystyle{ 1510 }[/math] [math]\displaystyle{ 1588 }[/math] [math]\displaystyle{ 1549 }[/math] [math]\displaystyle{ 1468 }[/math] [math]\displaystyle{ 1692 }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ 2760 }[/math] [math]\displaystyle{ 282485800 }[/math] [math]\displaystyle{ 2978 }[/math] [math]\displaystyle{ }[/math] [math]\displaystyle{ 2137 }[/math] [math]\displaystyle{ 2278 }[/math] [math]\displaystyle{ 1995 }[/math] [math]\displaystyle{ 2057 }[/math] [math]\displaystyle{ 2260 }[/math] [math]\displaystyle{ 2113 }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ 1314 }[/math] [math]\displaystyle{ 2392 }[/math] [math]\displaystyle{ 1497 }[/math] [math]\displaystyle{ 2392 }[/math] [math]\displaystyle{ 1165 }[/math] [math]\displaystyle{ 1268 }[/math] [math]\displaystyle{ 1227 }[/math] [math]\displaystyle{ 1411 }[/math] [math]\displaystyle{ 1253 }[/math] [math]\displaystyle{ 2377 }[/math]
Uwaga N39
Można pokazać[2], że dla liczby złożonej nieparzystej [math]\displaystyle{ m \neq 9 }[/math] i ustalonego [math]\displaystyle{ D }[/math] ilość par [math]\displaystyle{ P, Q }[/math] takich, że
- [math]\displaystyle{ 0 \leqslant P, Q \lt m }[/math]
- [math]\displaystyle{ \gcd (Q, m) = 1 }[/math]
- [math]\displaystyle{ P^2 - 4 Q \equiv D \pmod{m} }[/math]
- [math]\displaystyle{ m }[/math] jest SLPSP([math]\displaystyle{ P, Q }[/math])
nie przekracza [math]\displaystyle{ \tfrac{4}{15} n }[/math].
Nie dotyczy to przypadku, gdy [math]\displaystyle{ m = p (p + 2) }[/math] jest iloczynem liczb pierwszych bliźniaczych takich, że [math]\displaystyle{ (D \mid p) = - (D \mid p + 2) = - 1 }[/math], wtedy mamy słabsze oszacowanie: [math]\displaystyle{ \# (P, Q) \leqslant \tfrac{1}{2} n }[/math]. Zauważmy, że taką sytuację łatwo wykryć, bo w tym przypadku [math]\displaystyle{ m + 1 = (p + 1)^2 }[/math] jest liczbą kwadratową.
Uwaga N40
Podobnie jak w przypadku liczb pseudopierwszych Lucasa LPSP([math]\displaystyle{ P, Q }[/math]) tak i w przypadku liczb silnie pseudopierwszych Lucasa SLPSP([math]\displaystyle{ P, Q }[/math]) możemy testować pierwszość liczby [math]\displaystyle{ m }[/math], wybierając liczby [math]\displaystyle{ P, Q }[/math] losowo lub zastosować wybraną metodę postępowania. Przedstawiony poniżej program, to zmodyfikowany kod z uwagi N36. Teraz parametry [math]\displaystyle{ P, Q }[/math] są wybierane metodą Selfridge'a, a symbol Jacobiego [math]\displaystyle{ (D \mid m) }[/math] jest równy [math]\displaystyle{ - 1 }[/math].
StrongLucasTest(m) =
{
local(a, b, c, k, P, Q, r, w, X);
if( m % 2 == 0, return(m == 2) );
if( issquare(m), return(0) ); \\ sprawdzamy, czy liczba m nie jest kwadratowa
X = MethodA(m);
P = X[1];
Q = X[2];
if( P == 0 || gcd(m, 2*Q) > 1, return(0) ); \\ jeżeli P = 0, to m jest liczbą złożoną
r = valuation(m + 1, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m + 1
w = (m + 1) / 2^r;
X = modLucas(w, P, Q, m);
a = X[1]; \\ U_w(P, Q) % m
b = X[2]; \\ V_w(P, Q) % m
if( a == 0 || b == 0, return(1) ); \\ b == 0 to przypadek k == 0
if( r == 1, return(0) ); \\ nie ma dalszych przypadków
c = modPower(Q, w, m); \\ Q^w % m
k = 0;
\\ sprawdzamy warunek V_(2^k * w) %m = 0; korzystamy ze wzoru V_(2*w) = (V_w)^2 - 2*Q^w
while( k++ < r,
b = (b^2 - 2*c) % m;
if( b == 0, return(1) );
c = c^2 % m;
);
return(0);
}
Uwaga N41
Najmniejsze liczby silnie pseudopierwsze Lucasa, które otrzymujemy po zastosowaniu metody Selfridge'a wyboru parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math], to
- [math]\displaystyle{ 5459, 5777, 10877, 16109, 18971, 22499, 24569, 25199, 40309, 58519, 75077, 97439, \ldots }[/math]
Tabela przedstawia ilość takich liczb nie większych od [math]\displaystyle{ 10^n }[/math]
[math]\displaystyle{ \boldsymbol{n} }[/math] [math]\displaystyle{ \boldsymbol{3} }[/math] [math]\displaystyle{ \boldsymbol{4} }[/math] [math]\displaystyle{ \boldsymbol{5} }[/math] [math]\displaystyle{ \boldsymbol{6} }[/math] [math]\displaystyle{ \boldsymbol{7} }[/math] [math]\displaystyle{ \boldsymbol{8} }[/math] [math]\displaystyle{ \boldsymbol{9} }[/math] #SLPSP [math]\displaystyle{ \lt 10^n }[/math] (metoda Selfridge'a) [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 2 }[/math] [math]\displaystyle{ 12 }[/math] [math]\displaystyle{ 58 }[/math] [math]\displaystyle{ 178 }[/math] [math]\displaystyle{ 505 }[/math] [math]\displaystyle{ 1415 }[/math]
Test BPSW
Uwaga N42
Jest [math]\displaystyle{ 488 }[/math] liczb SPSP([math]\displaystyle{ 2 }[/math]) mniejszych od [math]\displaystyle{ 10^8 }[/math] i są 582 liczby SPSP([math]\displaystyle{ 3 }[/math]) mniejsze od [math]\displaystyle{ 10^8 }[/math] (zobacz M21). Ale jest aż [math]\displaystyle{ 21 }[/math] liczb mniejszych od [math]\displaystyle{ 10^8 }[/math] silnie pseudopierwszych jednocześnie względem podstaw [math]\displaystyle{ 2 }[/math] i [math]\displaystyle{ 3 }[/math]:
[math]\displaystyle{ 1373653, 1530787, 1987021, 2284453, 3116107, 5173601, 6787327, 11541307, 13694761, 15978007, 16070429, }[/math]
[math]\displaystyle{ 16879501, 25326001, 27509653, 27664033, 28527049, 54029741, 61832377, 66096253, 74927161, 80375707 }[/math]
Widzimy, że prawdopodobieństwo błędnego rozpoznania pierwszości w przypadku liczb mniejszych od [math]\displaystyle{ 10^8 }[/math] dla podstawy [math]\displaystyle{ 2 }[/math] lub podstawy [math]\displaystyle{ 3 }[/math] jest rzędu kilku milionowych. Gdyby prawdopodobieństwa błędnego rozpoznania pierwszości w przypadku podstawy [math]\displaystyle{ 2 }[/math] lub podstawy [math]\displaystyle{ 3 }[/math] były niezależne, to spodziewalibyśmy się, że nie będzie wcale liczb mniejszych od [math]\displaystyle{ 10^8 }[/math] silnie pseudopierwszych jednocześnie względem podstaw [math]\displaystyle{ 2 }[/math] i [math]\displaystyle{ 3 }[/math], bo prawdopodobieństwo takiego zdarzenia byłoby równe kilkudziesięciu bilonowym. Ale tak nie jest.
Jest to mocny argument za tym, że zastosowanie różnych (niezależnych) testów może być znacznie silniejszym narzędziem do testowania pierwszości liczb, niż wielokrotne stosowanie tego samego testu, gdzie poszczególne próby są tylko pozornie niezależne.
Połączenie znanych nam już testów prowadzi do prostego programu
BPSWtest(m) =
{
forprime(p = 2, 1000, if( m % p > 0, next() ); if( m == p, return(1), return(0) ));
if( !isPrimeOrSPSP(m, 2), return(0) );
if( !StrongLucasTest(m), return(0), return(1) );
}
Funkcja BPSWtest(m)
kolejno sprawdza:
- czy liczba [math]\displaystyle{ m }[/math] jest podzielna przez niewielkie liczby pierwsze (w naszym przypadku mniejsze od [math]\displaystyle{ 1000 }[/math]); jeśli tak, to sprawdza, czy [math]\displaystyle{ m }[/math] jest liczbą pierwszą, czy złożoną i zwraca odpowiednio [math]\displaystyle{ 1 }[/math] lub [math]\displaystyle{ 0 }[/math]
- czy liczba [math]\displaystyle{ m }[/math] przechodzi test Millera-Rabina dla podstawy [math]\displaystyle{ 2 }[/math]; jeśli nie, to zwraca [math]\displaystyle{ 0 }[/math]
- czy liczba [math]\displaystyle{ m }[/math] przechodzi silny test Lucasa dla parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math], które wybieramy metodą Selfridge'a; jeśli nie, to zwraca [math]\displaystyle{ 0 }[/math], w przeciwnym wypadku zwraca [math]\displaystyle{ 1 }[/math]
Test w dokładnie takiej postaci zaproponowali Robert Baillie i Samuel Wagstaff[1]. Nazwa testu to akronim, utworzony od pierwszych liter nazwisk Roberta Bailliego, Carla Pomerance'a, Johna Selfridge'a i Samuela Wagstaffa.
Nie jest znany żaden przykład liczby złożonej [math]\displaystyle{ m }[/math], którą test BPSW[3][4] identyfikowałby jako pierwszą i z pewnością nie ma takich liczb dla [math]\displaystyle{ m \lt 2^{64} \approx 1.844 \cdot 10^{19} }[/math]. Warto przypomnieć: potrzebowaliśmy siedmiu testów Millera-Rabina (dla podstaw [math]\displaystyle{ 2, 3, 5, 7, 11, 13, 17 }[/math]), aby mieć pewność, że dowolna liczba [math]\displaystyle{ m \lt 3.41 \cdot 10^{14} }[/math] jest pierwsza (zobacz M22).
Uzupełnienie
Pewne własności współczynników dwumianowych
Twierdzenie N43
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą, to
- [math]\displaystyle{ \binom{p}{k} \equiv 0 \pmod{p} }[/math]
dla każdego [math]\displaystyle{ k \in [1, p - 1] }[/math].
Twierdzenie N44
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą, to
- [math]\displaystyle{ \binom{p + 1}{k} \equiv 0 \pmod{p} }[/math]
dla każdego [math]\displaystyle{ k \in [2, p - 1] }[/math].
Twierdzenie N45
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą, to
- [math]\displaystyle{ \binom{p - 1}{k} \equiv (- 1)^k \pmod{p} }[/math]
dla każdego [math]\displaystyle{ k \in [0, p - 1] }[/math].
Twierdzenie N46
Dla współczynników dwumianowych prawdziwe są następujące wzory
- [math]\displaystyle{ \underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1} }[/math]
- [math]\displaystyle{ \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1} }[/math]
Funkcje digits(m, b) oraz issquare(m)
Uwaga N47
W funkcji modLucas()
wykorzystaliśmy zaimplementowaną w PARI/GP funkcję
digits(m, b)
– zwraca wektor cyfr liczby [math]\displaystyle{ | m | }[/math] w systemie liczbowym o podstawie [math]\displaystyle{ b }[/math]
W naszym przypadku potrzebowaliśmy uzyskać wektor cyfr liczby [math]\displaystyle{ m }[/math] w układzie dwójkowym, czyli funkcję digits(m, 2)
. Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Zauważmy, że do zapisania liczby [math]\displaystyle{ m \geqslant 1 }[/math] potrzebujemy [math]\displaystyle{ \log_2 m + 1 }[/math] cyfr. Zastępując funkcję [math]\displaystyle{ \log_2 m }[/math] funkcją [math]\displaystyle{ \left \lfloor \tfrac{\log m}{\log 2} \right \rfloor }[/math] musimy liczyć się z możliwym błędem zaokrąglenia – dlatego w programie deklarujemy wektor V
o długości floor( log(m)/log(2) ) + 2
. Zwracany wektor W
ma już prawidłową długość.
Dec2Bin(m) =
\\ zwraca wektor cyfr liczby m w układzie dwójkowym
{
local(i, k, V, W);
if( m == 0, return([0]) );
V = vector( floor( log(m)/log(2) ) + 2 ); \\ potrzeba floor( log(m)/log(2) ) + 1, ale błąd zaokrąglenia może zepsuć wynik
k = 0;
while( m > 0,
V[k++] = m % 2;
m = floor(m / 2);
);
W = vector(k);
for(i = 1, k, W[i] = V[k + 1 - i]);
return(W);
}
Uwaga N48
W funkcjach LucasTest()
i StrongLucasTest()
wykorzystaliśmy zaimplementowaną w PARI/GP funkcję
issquare(m)
– sprawdza, czy liczba [math]\displaystyle{ m }[/math] jest liczbą kwadratową
Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Potrzebna nam będzie funkcja, która znajduje całość z pierwiastka z liczby [math]\displaystyle{ m }[/math], czyli [math]\displaystyle{ \left\lfloor \sqrt{m} \right\rfloor }[/math]. Wykorzystamy tutaj ciąg
- [math]\displaystyle{ a_{k + 1} = \begin{cases} \qquad \;\; 1 & \text{gdy } k = 0 \\ \tfrac{1}{2} \left( a_k + \tfrac{x}{a_k} \right) & \text{gdy } k \gt 0 \\ \end{cases} }[/math]
którego granicą jest [math]\displaystyle{ \sqrt{x} }[/math] [5].
Modyfikując powyższą definicję tak, aby operacje były zawsze wykonywane na liczbach całkowitych[6]
- [math]\displaystyle{ a_{k + 1} = \begin{cases} \qquad \quad \; 1 & \text{gdy } k = 0 \\ \left\lfloor \tfrac{1}{2} \left( a_k + \left\lfloor \tfrac{m}{a_k} \right\rfloor \right) \right\rfloor & \text{gdy } k \gt 0 \\ \end{cases} }[/math]
otrzymujemy ciąg, którego wszystkie wyrazy, począwszy od pewnego skończonego [math]\displaystyle{ n_0 }[/math], są równe [math]\displaystyle{ \left\lfloor \sqrt{m} \right\rfloor }[/math]. Nie dotyczy to przypadku, gdy [math]\displaystyle{ m + 1 }[/math] jest liczbą kwadratową, wtedy, począwszy od pewnego skończonego [math]\displaystyle{ n_0 }[/math], wyrazy ciągu przyjmują na zmianę wartości [math]\displaystyle{ \left\lfloor \sqrt{m} \right\rfloor }[/math] oraz [math]\displaystyle{ \left\lfloor \sqrt{m} \right\rfloor + 1 }[/math].
Na tej podstawie możemy w PARI/GP napisać funkcję
intSqrt(m) =
{
local(a, b);
if( m == 0, return(0) );
a = 2^( floor( log(m)/log(2)/2 ) + 2 ); \\ musi być a > sqrt(m)
b = floor(( a + floor( m/a ) )/2);
while( b < a,
a = b;
b = floor( ( a + floor(m/a) )/2 );
);
return(a);
}
Oczywiście liczba [math]\displaystyle{ m }[/math] jest liczbą kwadratową, wtedy i tylko wtedy, gdy [math]\displaystyle{ m = \left\lfloor \sqrt{m} \right\rfloor^2 }[/math], zatem wystarczy sprawdzić, czy m == intSqrt(m)^2
.
Przypisy
- ↑ Skocz do: 1,0 1,1 Robert Baillie and Samuel S. Wagstaff Jr., Lucas Pseudoprimes, Mathematics of Computation Vol. 35, No. 152 (1980), (LINK)
- ↑ François Arnault, The Rabin-Monier Theorem for Lucas Pseudoprimes, Mathematics of Computation Vol. 66, No. 218 (1997)
- ↑ Wikipedia, Baillie–PSW primality test, (Wiki-en)
- ↑ MathWorld, Baillie-PSW Primality Test, (LINK)
- ↑ Wikipedia, Pierwiastek kwadratowy, (Wiki-pl), (Wiki-en)
- ↑ Wikipedia, Integer square root, (Wiki-en)