Testy pierwszości. Liczby pseudopierwsze Lucasa i liczby silnie pseudopierwsze Lucasa. Test BPSW: Różnice pomiędzy wersjami

Z Henryk Dąbrowski
Przejdź do nawigacji Przejdź do wyszukiwania
Linia 5: Linia 5:
  
  
== Symbol Jacobiego ==
+
== Ciągi Lucasa ==
  
 
<span style="font-size: 110%; font-weight: bold;">Definicja L1</span><br/>
 
<span style="font-size: 110%; font-weight: bold;">Definicja L1</span><br/>
Symbol Jacobiego<ref name="jacobi1"/> <math>\left( {\small\frac{a}{n}} \right)_{\small{\!\! J}}</math> jest uogólnieniem symbolu Legendre'a<ref name="legendre1"/> <math>\left( {\small\frac{a}{p}} \right)_{\small{\!\! L}}</math> dla dodatnich liczb nieparzystych.  
+
Niech <math>P, Q \in \mathbb{Z} \setminus \{0\}</math> oraz <math>D = P^2 - 4 Q \neq 0</math>. Ciągi Lucasa <math>U_n = U_n (P, Q)</math> i <math>V_n = V_n (P, Q)</math> definiujemy następująco
Niech <math>n = \prod_i p_i^{\alpha_i}</math> będzie rozkładem liczby <math>n</math> na czynniki pierwsze, wtedy
 
  
::<math>\left( {\small\frac{a}{n}} \right)_{\small{\!\! J}} = \prod_i \left( {\small\frac{a}{p_i}} \right)_{\small{\!\! L}}^{\!\! \alpha_i}</math>
+
::<math>U_n = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}}</math>
  
 +
::<math>V_n = \alpha^n + \beta^n</math>
  
 +
gdzie liczby
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L2</span><br/>
+
::<math>\alpha = {\small\frac{P + \sqrt{D}}{2}}</math>
Zauważmy, że w&nbsp;przypadku gdy <math>n = 1</math>, po prawej stronie mamy „pusty” iloczyn (bez jakiegokolwiek czynnika). Podobnie jak „pustej” sumie przypisujemy wartość zero, tak „pustemu” iloczynowi przypisujemy wartość jeden. Zatem dla dowolnego <math>a \in \mathbb{Z}</math> jest <math>\left( {\small\frac{a}{1}} \right)_{\small{\!\! J}} = 1</math>.
 
  
 +
::<math>\beta = {\small\frac{P - \sqrt{D}}{2}}</math>
  
 +
są pierwiastkami równania <math>x^2 - P x + Q = 0</math>.
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L3*</span><br/>
 
Niech <math>a, b \in \mathbb{Z}</math> oraz <math>m, n \in \mathbb{Z}_+</math> i <math>m, n</math> będą liczbami nieparzystymi. Symbol Jacobiego ma następujące właściwości
 
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: left; margin-right: auto;"
 
|-
 
| &nbsp;&nbsp;1.&nbsp;&nbsp; || <math>\left( {\small\frac{a}{n}} \right)_{\small{\!\! J}} \,\, = \,\, 0 \quad \Longleftrightarrow \quad \gcd (a, n) > 1</math>
 
|-
 
| &nbsp;&nbsp;2.&nbsp;&nbsp; || <math>a \equiv b \pmod n \quad \Longrightarrow \quad \left( {\small\frac{a}{n}} \right)_{\small{\!\! J}} = \left( {\small\frac{b}{n}} \right)_{\small{\!\! J}}</math>
 
|-
 
| &nbsp;&nbsp;3.&nbsp;&nbsp; || <math>\left( {\small\frac{a b}{n}} \right)_{\small{\!\! J}} \,\, = \,\, \left( {\small\frac{a}{n}} \right)_{\small{\!\! J}} \cdot  \left( {\small\frac{b}{n}} \right)_{\small{\!\! J}}</math>
 
|-
 
| &nbsp;&nbsp;4.&nbsp;&nbsp; || <math>\left( {\small\frac{a}{m n}} \right)_{\small{\!\! J}} \,\, = \,\, \left( {\small\frac{a}{m}} \right)_{\small{\!\! J}} \cdot  \left( {\small\frac{a}{n}} \right)_{\small{\!\! J}}</math>
 
|-
 
| &nbsp;&nbsp;5.&nbsp;&nbsp; || <math>\left( {\small\frac{1}{n}} \right)_{\small{\!\! J}} \,\, = \,\, 1</math>
 
|-
 
| &nbsp;&nbsp;6.&nbsp;&nbsp; || <math>\left( {\small\frac{- 1}{n}} \right)_{\small{\!\! J}} \,\, = \,\, (- 1)^{\tfrac{n - 1}{2}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } n \equiv 1 \pmod{4} \\
 
      - 1 & \text{gdy } n \equiv 3 \pmod{4}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;7.&nbsp;&nbsp; || <math>\left( {\small\frac{2}{n}} \right)_{\small{\!\! J}} \,\, = \,\, (- 1)^{\tfrac{n^2 - 1}{8}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } n \equiv 1, 7 \pmod{8} \\
 
      - 1 & \text{gdy } n \equiv 3, 5 \pmod{8}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;8.&nbsp;&nbsp; || <math>\left( {\small\frac{- 2}{n}} \right)_{\small{\!\! J}} \,\, = \,\, (- 1)^{\tfrac{(n - 1)(n - 3)}{8}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } n \equiv 1, 3 \pmod{8} \\
 
      - 1 & \text{gdy } n \equiv 5, 7 \pmod{8}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;9.&nbsp;&nbsp; || <math>\left( {\small\frac{m}{n}} \right)_{\small{\!\! J}} \,\, = \,\, \left( {\small\frac{n}{m}} \right)_{\small{\!\! J}} \cdot (-1)^{\tfrac{n - 1}{2} \cdot \tfrac{m - 1}{2}} \,\, = \,\, \left( {\small\frac{n}{m}} \right)_{\small{\!\! J}} \cdot
 
\begin{cases}
 
\;\;\: 1 & \text{gdy } m \equiv 1 \pmod{4} \;\;\; \text{lub} \;\;\; n \equiv 1 \pmod{4} \\
 
      - 1 & \text{gdy } m \equiv n \equiv 3 \pmod{4}
 
  \end{cases}</math>
 
|}
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga L2</span><br/>
 +
Zauważmy, że:
  
 +
::<math>P = \alpha + \beta</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L4</span><br/>
+
::<math>Q = \alpha \beta</math>
Pokazać, że
 
  
::<math>\left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{- 12}{m}} \right)_{\small{\!\! J}} =
+
::<math>\sqrt{D} = \alpha - \beta</math>
\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>
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
::<math>U_0 = 0</math>, <math>U_1 = 1</math>, <math>V_0 = 2</math> i <math>V_1 = P</math>
Zauważmy, że
 
  
::<math>\left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{- 1}{m}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{3}{m}} \right)_{\small{\!\! J}}</math>
 
  
::::<math>\; = (- 1)^{\tfrac{m - 1}{2}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} \cdot \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}}</math>
+
Warunek <math>P^2 - 4 Q \neq 0</math> wyklucza następujące pary <math>(P, Q)</math>
  
::::<math>\; = (- 1)^{m - 1} \cdot \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}}</math>
+
::<math>(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>
  
::::<math>\; = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}}</math>
 
  
bo <math>m</math> jest liczbą nieparzystą.
 
  
Rozważmy liczby nieparzyste <math>m</math> postaci <math>6 k + r</math>, gdzie <math>r = 1, 3, 5</math>. Mamy
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L3</span><br/>
 +
Oczywiście liczby <math>\alpha</math> i <math>\beta</math> są również pierwiastkami równania
  
::<math>\left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}}</math>
+
::<math>x^{n + 2} - P x^{n + 1} + Q x^n = 0</math>
  
::::<math>\; = \left( {\small\frac{6 k + r}{3}} \right)_{\small{\!\! J}}</math>
+
Wynika stąd, że ciągi <math>(\alpha^n)</math> i <math>(\beta^n)</math> spełniają równania rekurencyjne
  
::::<math>\; = \left( {\small\frac{r}{3}} \right)_{\small{\!\! J}}</math>
+
::<math>\alpha^{n + 2} = P \alpha^{n + 1} - Q \alpha^n</math>
  
::::<math>\; =
+
::<math>\beta^{n + 2} = P \beta^{n + 1} - Q \beta^n</math>
\begin{cases}
 
\;\;\: 1 & \text{gdy } r = 1 \\
 
\;\;\: 0 & \text{gdy } r = 3 \\
 
      - 1 & \text{gdy } r = 5
 
\end{cases}</math>
 
  
bo odpowiednio dla <math>r = 1, 3, 5</math> jest
+
Ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> spełniają identyczne równania rekurencyjne jak ciągi <math>(\alpha^n)</math> i <math>(\beta^n)</math>. Istotnie, odejmując i&nbsp;dodając stronami wypisane powyżej równania, otrzymujemy
  
::<math>\left( {\small\frac{1}{3}} \right)_{\small{\!\! J}} = 1</math>
+
::<math>U_{n + 2} = P U_{n + 1} - Q U_n</math>
  
::<math>\left( {\small\frac{3}{3}} \right)_{\small{\!\! J}} = 0</math>
+
::<math>V_{n + 2} = P V_{n + 1} - Q V_n</math>
  
::<math>\left( {\small\frac{5}{3}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{3}} \right)_{\small{\!\! J}} = (- 1)^{\tfrac{9 - 1}{8}} = - 1</math>
+
Dlatego możemy zdefiniować ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> w&nbsp;sposób równoważny
  
Łatwo zauważamy, że
 
  
::<math>\left( {\small\frac{- 12}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{- 3 \cdot 2^2}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{2}{m}} \right)_{\small{\!\! J}}^{\! 2} = \left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}}</math>
 
  
Co należało pokazać.<br/>
+
<span style="font-size: 110%; font-weight: bold;">Definicja L4</span><br/>
&#9633;
+
Niech <math>P, Q \in \mathbb{Z} \setminus \{0\}</math> oraz <math>D = P^2 - 4 Q \neq 0</math>. Ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> określone są następującymi wzorami rekurencyjnymi
{{\Spoiler}}
 
  
 +
::<math>U_0 = 0</math>, <math>U_1 = 1</math>, <math>U_n = P U_{n - 1} - Q U_{n - 2}</math>
  
 +
::<math>V_0 = 2</math>, <math>V_1 = P</math>, <math>V_n = P V_{n - 1} - Q V_{n - 2}</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L5</span><br/>
 
Pokazać, że
 
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} =
 
\begin{cases}
 
\;\;\: 1 & \text{gdy } m = 12 k \pm 1 \\
 
\;\;\: 0 & \text{gdy } m = 12 k \pm 3 \\
 
      - 1 & \text{gdy } m = 12 k \pm 5
 
\end{cases}</math>
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Przykład L5</span><br/>
 +
Początkowe wyrazy ciągów Lucasa
 +
 +
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: left; margin-right: auto;"
 +
|-
 +
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{U_n (P, Q)}</math> !! <math>\boldsymbol{V_n (P, Q)}</math>
 +
|-
 +
| &nbsp;&nbsp;<math>0</math>&nbsp;&nbsp; || <math>0</math> || <math>2</math>
 +
|-
 +
| &nbsp;&nbsp;<math>1</math>&nbsp;&nbsp; || <math>1</math> || <math>P</math>
 +
|-
 +
| &nbsp;&nbsp;<math>2</math>&nbsp;&nbsp; || <math>P</math> || <math>P^2 - 2 Q</math>
 +
|-
 +
| &nbsp;&nbsp;<math>3</math>&nbsp;&nbsp; || <math>P^2 - Q</math> || <math>P^3 - 3 P Q</math>
 +
|-
 +
| &nbsp;&nbsp;<math>4</math>&nbsp;&nbsp; || <math>P^3 - 2 P Q</math> || <math>P^4 - 4 P^2 Q + 2 Q^2</math>
 +
|-
 +
| &nbsp;&nbsp;<math>5</math>&nbsp;&nbsp; || <math>P^4 - 3 P^2 Q + Q^2</math> || <math>P^5 - 5 P^3 Q + 5 P Q^2</math>
 +
|-
 +
| &nbsp;&nbsp;<math>6</math>&nbsp;&nbsp; || <math>P^5 - 4 P^3 Q + 3 P Q^2</math> || <math>P^6 - 6 P^4 Q + 9 P^2 Q^2 - 2 Q^3</math>
 +
|-
 +
| &nbsp;&nbsp;<math>7</math>&nbsp;&nbsp; || <math>P^6 - 5 P^4 Q + 6 P^2 Q^2 - Q^3</math> || <math>P^7 - 7 P^5 Q + 14 P^3 Q^2 - 7 P Q^3</math>
 +
|-
 +
| &nbsp;&nbsp;<math>8</math>&nbsp;&nbsp; || <math>P^7 - 6 P^5 Q + 10 P^3 Q^2 - 4 P Q^3</math> || <math>P^8 - 8 P^6 Q + 20 P^4 Q^2 - 16 P^2 Q^3 + 2 Q^4</math>
 +
|-
 +
| &nbsp;&nbsp;<math>9</math>&nbsp;&nbsp; || <math>P^8 - 7 P^6 Q + 15 P^4 Q^2 - 10 P^2 Q^3 + Q^4</math> || <math>P^9 - 9 P^7 Q + 27 P^5 Q^2 - 30 P^3 Q^3 + 9 P Q^4</math>
 +
|}
  
::<math>\left( {\small\frac{- 4}{m}} \right)_{\small{\!\! J}} =
 
\begin{cases}
 
\;\;\: 1 & \text{gdy } m = 4 k + 1 \\
 
      - 1 & \text{gdy } m = 4 k + 3
 
\end{cases}</math>
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} = \left( {\small\frac{12 k + 1}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{12 k}{2}} = \left( {\small\frac{1}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{6 k} = 1</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L6</span><br/>
 +
W PARI/GP możemy napisać prosty kod, który pozwoli obliczyć wartości wyrazów <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math>
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} = \left( {\small\frac{12 k + 5}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{12 k + 4}{2}} = \left( {\small\frac{5}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{(6 k + 2)} = \left( {\small\frac{2}{3}} \right)_{\small{\!\! J}} = - 1</math>
+
<span style="font-size: 90%; color:black;">LucasU(n, P, Q) = '''if'''( n == 0, 0, '''if'''( n == 1, 1, P*LucasU(n-1, P, Q) - Q*LucasU(n-2, P, Q) ) )</span>
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} = \left( {\small\frac{12 k + 7}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{12 k + 6}{2}} = \left( {\small\frac{1}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{(6 k + 3)} = - 1</math>
+
<span style="font-size: 90%; color:black;">LucasV(n, P, Q) = '''if'''( n == 0, 2, '''if'''( n == 1, P, P*LucasV(n-1, P, Q) - Q*LucasV(n-2, P, Q) ) )</span>
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} = \left( {\small\frac{12 k + 11}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{12 k + 10}{2}} = \left( {\small\frac{2}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{(6 k + 5)} = (- 1) \cdot (- 1) = 1</math>
 
<br/>
 
&#9633;
 
{{\Spoiler}}
 
  
  
 +
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L7</span><br/>
 +
Niech <math>D = P^2 - 4 Q</math>. Wyrazy ciągów Lucasa można przedstawić w&nbsp;postaci sumy
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L6</span><br/>
+
::<math>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>
Wykorzystując podane wyżej właściwości symbolu Jacobiego, możemy napisać prostą funkcję w&nbsp;PARI/GP znajdującą jego wartość. Zauważmy, że nie potrzebujemy znać rozkładu liczby <math>n</math> na czynniki pierwsze.
 
  
<span style="font-size: 90%; color:black;">jacobi(a, n) =  
+
::<math>2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
{
 
'''local'''(r, w);
 
'''if'''( n <= 0 || n % 2 == 0, '''return'''("Error") );
 
a = a % n; \\ korzystamy ze wzoru (a|n) = (b|n), gdy a &equiv; b (mod n)
 
w = 1;
 
'''while'''( a <> 0,
 
        '''while'''( a % 2 == 0, a = a/2; r = n % 8; '''if'''( r == 3 || r == 5, w = -w ) );
 
        \\ usunęliśmy czynnik 2 ze zmiennej a, uwzględniając, że (2|n) = -1, gdy n &equiv; 3,5 (mod 8)
 
        \\ teraz zmienne a oraz n są nieparzyste
 
        r = a; \\ zmienna r tylko przechowuje wartość a
 
        a = n;
 
        n = r;
 
        '''if'''( a % 4 == 3 && n % 4 == 3, w = -w );
 
        \\ zamieniliśmy zmienne, uwzględniając, że (a|n) = - (n|a), gdy a &equiv; n &equiv; 3 (mod 4)
 
        a = a % n;
 
      );
 
'''if'''( n == 1, '''return'''(w), '''return'''(0) ); \\ n jest teraz równe gcd(a, n)
 
}</span>
 
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Oznaczmy <math>\delta = \sqrt{D}</math>, zatem <math>2 \alpha = P + \delta</math> i <math>2 \beta = P - \delta</math>. Ze wzoru dwumianowego, mamy
  
 +
::<math>2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j</math>
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L7</span><br/>
+
::<math>2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j</math>
Ten rozdział moglibyśmy zakończyć na podaniu kodu funkcji <code>jacobi(a, m)</code>. Dlatego Czytelnik może pominąć dalsze rozważania i&nbsp;wrócić do nich, gdy będziemy omawiali metodę Selfridge'a – dopiero tam pojęcie najmniejszej liczby niekwadratowej modulo <math>p</math> nabierze znaczenia, a&nbsp;i&nbsp;tak nie będzie konieczne dla zrozumienia tematu.
 
  
 +
Obliczając sumę powyższych wzorów, otrzymujemy
  
 +
::<math>2^n (\alpha^n + \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j + (- \delta)^j)</math>
  
<span style="font-size: 110%; font-weight: bold;">Przykład L8</span><br/>
+
:::::<math>\quad \: = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} \cdot 2 \delta^{2 k}</math>
W tabeli przedstawiliśmy najmniejsze liczby <math>g = g (m)</math> takie, że <math>\left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = - 1</math>.
 
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
+
:::::<math>\quad \: = 2 \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
! <math>\boldsymbol{m}</math>
 
| <math>3</math> || <math>5</math> || <math>7</math> || <math>9</math> || <math>11</math> || <math>13</math> || <math>15</math> || <math>17</math> || <math>19</math> || <math>21</math> || <math>23</math> || <math>25</math> || <math>27</math> || <math>29</math> || <math>31</math> || <math>33</math> || <math>35</math> || <math>37</math> || <math>39</math> || <math>41</math> || <math>43</math> || <math>45</math> || <math>47</math> || <math>49</math> || <math>51</math>
 
|-
 
!  <math>\boldsymbol{g}</math>
 
| <math>2</math> || <math>2</math> || <math>3</math> || <math>-</math> || <math>2</math> || <math>2</math> || <math>7</math> || <math>3</math> || <math>2</math> || <math>2</math> || <math>5</math> || <math>-</math> || <math>2</math> || <math>2</math> || <math>3</math> || <math>5</math> || <math>2</math> || <math>2</math> || <math>7</math> || <math>3</math> || <math>2</math> || <math>2</math> || <math>5</math> || <math>-</math> || <math>2</math>
 
|}
 
  
 +
gdzie <math>j = 2 k</math> i&nbsp;sumowanie przebiega od <math>k = 0</math> do <math>k = \lfloor n / 2 \rfloor</math>
  
Do wyszukiwania liczb <math>g = g (m)</math> (nazywanych najmniejszymi liczbami niekwadratowymi modulo <math>m</math>) Czytelnik może wykorzystać prostą funkcję napisaną w&nbsp;PARI/GP
+
Zatem
  
<span style="font-size: 90%; color:black;">LeastQuadraticNonresidue(m) =  
+
::<math>2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
{
 
'''local'''(g);
 
'''if'''( m%2 == 0, '''return'''(0) );
 
'''if'''( '''issquare'''(m), '''return'''(0) );
 
'''forprime'''(g = 2, m, '''if'''( jacobi(g, m) == -1, '''return'''(g) ));
 
}</span>
 
  
  
O&nbsp;liczbach kwadratowych i&nbsp;niekwadratowych modulo podamy jedynie podstawowe fakty.
+
Obliczając różnicę tych wzorów, mamy
  
Niech liczby <math>a</math> i <math>m \geqslant 1</math> będą względnie pierwsze.
+
::<math>2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j)</math>
  
:* jeżeli istnieje taka liczba <math>r</math>, że <math>r^2 \equiv a \pmod{m}</math>, to <math>a</math> jest liczbą kwadratową modulo <math>m</math>.
+
:::::<math>\quad \: = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} \cdot 2 \delta^{2 k + 1}</math>
:* jeżeli nie istnieje taka liczba <math>r</math>, że <math>r^2 \equiv a \pmod{m}</math>, to <math>a</math> jest liczbą niekwadratową modulo <math>m</math>.
 
  
 +
:::::<math>\quad \: = 2 \delta \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
  
Zauważmy również, że (w przypadku, gdy <math>m</math> jest liczbą nieparzystą)
+
gdzie <math>j = 2 k + 1</math> i&nbsp;sumowanie przebiega od <math>k = 0</math> do <math>k = \lfloor (n - 1) / 2 \rfloor</math>
  
:* jeżeli <math>\left( {\small\frac{a}{m}} \right)_{\small{\!\! J}} = - 1</math>, to <math>a</math> jest liczbą niekwadratową modulo <math>m</math>
 
:* jeżeli <math>\left( {\small\frac{a}{m}} \right)_{\small{\!\! J}} = + 1</math>, to <math>a</math> nie musi być liczbą kwadratową modulo <math>m</math>
 
:* jeżeli <math>a</math> jest liczbą kwadratową modulo <math>m</math>, to <math>\left( {\small\frac{a}{m}} \right)_{\small{\!\! J}} = + 1</math>
 
  
Dla przykładu: jeżeli <math>\gcd (a, m) = 1</math>, to <math>\left( {\small\frac{a}{m^2}} \right)_{\small{\!\! J}} = + 1</math>, ale <math>a</math> może być liczbą niekwadratową modulo <math>m^2</math>.
+
Zatem
  
Modulo <math>9</math> liczbami niekwadratowymi są: <math>2, 5, 8</math>. Modulo <math>25</math> liczbami niekwadratowymi są: <math>2, 3, 7, 8, 12, 13, 17, 18, 22, 23</math>.
+
::<math>2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}} = 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>
  
Liczby kwadratowe i&nbsp;niekwadratowe modulo <math>m</math> można łatwo znaleźć, wykorzystując prosty program:
+
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
<span style="font-size: 90%; color:black;">QRandQNR(m) =
 
{
 
'''local'''(k, S, V);
 
S = [];
 
V = [];
 
'''for'''(k = 1,  m - 1, '''if'''( '''gcd'''(k, m) > 1, '''next'''() ); S = '''concat'''(S, k));
 
S = '''Set'''(S); \\ zbiór liczb względnie pierwszych z m
 
'''for'''(k = 1,  m - 1, '''if'''( '''gcd'''(k, m) > 1, '''next'''() ); V = '''concat'''(V, k^2 % m));
 
V = '''Set'''(V); \\ zbiór liczb kwadratowych modulo m
 
'''print'''("QR: ", V);
 
'''print'''("QNR: ", '''setminus'''(S, V)); \\ różnica zbiorów S i V
 
}</span>
 
  
  
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga L8</span><br/>
 +
Korzystając z&nbsp;twierdzenia L7, możemy napisać proste funkcje do znajdowania postaci kolejnych wyrazów <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L9</span><br/>
+
<span style="font-size: 90%; color:black;">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)</span>
Niech <math>g, m \in \mathbb{Z}_+</math> i&nbsp;niech <math>m \geqslant 3</math> będzie liczbą nieparzystą, a <math>g</math> będzie najmniejszą liczbą taką, że <math>\left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = - 1</math>. Liczba <math>g</math> musi być liczbą pierwszą.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
<span style="font-size: 90%; color:black;">V(n) = 2^(1 - n)*'''sum'''(k=0, '''floor'''(n/2), '''binomial'''(n, 2*k) * P^(n-2*k) * (P^2-4*Q)^k)</span>
Przypuśćmy, że <math>g = a b</math> jest liczbą złożoną, gdzie <math>1 < a, b < g</math>. Mamy
 
  
::<math>- 1 = \left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{a b}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{a}{m}} \right)_{\small{\!\! J}}</math><math>\left( {\small\frac{b}{m}} \right)_{\small{\!\! J}}</math>
 
  
Zatem jeden z&nbsp;czynników po prawej stronie musi być równy <math>- 1</math> wbrew definicji liczby <math>g</math>.<br/>
 
&#9633;
 
{{\Spoiler}}
 
  
 +
Często możemy spotkać założenie <math>P \geqslant 1</math>. Poniższe twierdzenie wyjaśnia, dlaczego tak jest.
  
 +
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L9</span><br/>
 +
Jeżeli <math>(U_n)</math> i <math>(V_n)</math> są ciągami Lucasa, to
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L10</span><br/>
+
::<math>U_n (- P, Q) = (- 1)^{n - 1} U_n (P, Q)</math>
Niech <math>p</math> będzie liczbą pierwszą nieparzystą, a <math>g</math> będzie najmniejszą liczbą pierwszą taką, że <math>\left( {\small\frac{g}{p}} \right)_{\small{\!\! J}} = - 1</math>. Prawdziwe jest oszacowanie
 
  
::<math>g (p) < \sqrt{p} + {\small\frac{1}{2}}</math>
+
::<math>V_n (- P, Q) = (- 1)^n V_n (P, Q)</math>
  
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
Niech <math>u = g - R_g (p)</math>, gdzie <math>R_g (p)</math> jest resztą z&nbsp;dzielenia liczby <math>p</math> przez <math>g</math>. Ponieważ <math>g \nmid p</math>, zatem <math>R_g (p) \neq 0</math> i <math>u \in [1, g - 1]</math>. Mamy
+
Niech
  
::<math>u = g - R_g (p) \equiv g + p - R_g (p) = {\small\frac{g + p - R_g (p)}{g}} \cdot g = b g \pmod{p}</math>
+
::<math>\alpha = \frac{P + \sqrt{D}}{2} \qquad \qquad \;\; \beta = \frac{P - \sqrt{D}}{2}</math>
  
gdzie oznaczyliśmy
+
::<math>a = \frac{- P + \sqrt{D}}{2} \qquad \qquad b = \frac{- P - \sqrt{D}}{2}</math>
  
::<math>b = {\small\frac{g + p - R_g (p)}{g}}</math>
+
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
  
Ponieważ z&nbsp;założenia <math>p</math> jest liczbą pierwszą, to <math>\gcd (u, p) = 1</math> i&nbsp;musi być <math>\left( {\small\frac{u}{p}} \right)_{\small{\!\! J}} = 1</math>, bo <math>u < g</math>. Zatem
+
::<math>x^2 - P x + Q = 0</math>
  
::<math>1 = \left( {\small\frac{u}{p}} \right)_{\small{\!\! J}} = \left( {\small\frac{b g}{p}} \right)_{\small{\!\! J}} = \left( {\small\frac{b}{p}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{g}{p}} \right)_{\small{\!\! J}} = - \left( {\small\frac{b}{p}} \right)_{\small{\!\! J}}</math>
+
::<math>x^2 + P x + Q = 0</math>
  
Ale z&nbsp;założenia <math>g</math> jest najmniejszą liczbą taką, że <math>\left( {\small\frac{g}{p}} \right)_{\small{\!\! J}} = - 1</math>. Wynika stąd, że musi być <math>g \leqslant b</math> i&nbsp;łatwo znajdujemy, że
+
Zatem definiują one ciągi Lucasa
  
::<math>g \leqslant {\small\frac{g + p - R_g (p)}{g}} \leqslant {\small\frac{g + p - 1}{g}}</math>
+
::<math>U_n (P, Q) = \frac{\alpha^n - \beta^n}{\alpha - \beta} \qquad \qquad \;\; V_n (P, Q) = \alpha^n + \beta^n</math>
  
Czyli
+
::<math>U_n (- P, Q) = \frac{a^n - b^n}{a - b} \qquad \qquad V_n (- P, Q) = a^n + b^n</math>
  
::<math>g^2 \leqslant g + p - 1</math>
+
Zauważmy, że
  
Skąd otrzymujemy
+
::<math>\alpha - \beta = a - b = \sqrt{D}</math>
  
::<math>\left( g - {\small\frac{1}{2}} \right)^2 \leqslant p - {\small\frac{3}{4}}</math>
+
::<math>\frac{a}{\beta} = \frac{b}{\alpha} = - 1</math>
  
::<math>g \leqslant {\small\frac{1}{2}} + \sqrt{p - {\small\frac{3}{4}}} < {\small\frac{1}{2}} + \sqrt{p}</math>
+
Łatwo znajdujemy
 +
 
 +
::<math>U_n (- P, Q) = \frac{a^n - b^n}{a - b} = \frac{(- \beta)^n - (- \alpha)^n}{\sqrt{D}} = (- 1)^n \cdot \frac{\beta^n - \alpha^n}{\alpha - \beta} = (- 1)^{n - 1} \cdot U_n (P, Q)</math>
 +
 
 +
::<math>V_n (- P, Q) = a^n + b^n = (- \beta)^n + (- \alpha)^n = (- 1)^n \cdot (\alpha^n + \beta^n) = (- 1)^n \cdot V_n (P, Q)</math>
  
 
Co należało pokazać.<br/>
 
Co należało pokazać.<br/>
Linia 290: Linia 216:
  
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L11*</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Zadanie L10</span><br/>
Niech <math>p</math> będzie liczbą pierwszą nieparzystą, a <math>g</math> będzie najmniejszą liczbą pierwszą taką, że <math>\left( {\small\frac{g}{p}} \right)_{\small{\!\! J}} = - 1</math>. Dla <math>p \geqslant 5</math> prawdziwe jest oszacowanie<ref name="Norton1"/><ref name="Trevino1"/><ref name="Trevino2"/>
+
Pokazać, że jeżeli <math>P, Q \in \mathbb{Z} \setminus \{ 0 \}</math> i <math>D = P^2 - 4 Q \neq 0</math>, to
  
::<math>g (p) \leqslant 1.1 \cdot p^{1 / 4} \log p</math>
+
::<math>U_n (2 P, 4 Q) = 2^{n - 1} U_n (P, Q)</math>
  
 +
::<math>V_n (2 P, 4 Q) = 2^n V_n (P, Q)</math>
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Niech
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L12</span><br/>
+
::<math>\alpha = {\small\frac{P + \sqrt{D}}{2}} \qquad \qquad \;\; \beta = {\small\frac{P - \sqrt{D}}{2}}</math>
W przypadku liczb złożonych podane w&nbsp;twierdzeniu L10 oszacowanie <math>g(m) < \sqrt{m} + {\small\frac{1}{2}}</math> nie jest prawdziwe. Mamy
 
  
::<math>g = g (15) = 7 > \sqrt{15} + {\small\frac{1}{2}} \approx 4.37</math>
+
::<math>a = P + \sqrt{D} \qquad \qquad \;\; b = P - \sqrt{D}</math>
  
::<math>g = g (39) = 7 > \sqrt{39} + {\small\frac{1}{2}} \approx 6.74</math>
+
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
  
::<math>g = g (105) = 11 > \sqrt{105} + {\small\frac{1}{2}} \approx 10.75</math>
+
::<math>x^2 - P x + Q = 0</math>
  
::<math>g = g (231) = 17 > \sqrt{231} + {\small\frac{1}{2}} \approx 15.7</math>
+
::<math>x^2 - 2 P x + 4 Q = 0</math>
  
Nie ma więcej takich przypadków dla <math>m < 10^9</math>.
+
Zatem definiują one ciągi Lucasa
  
 +
::<math>U_n (P, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \;\;\; V_n (P, Q) = \alpha^n + \beta^n</math>
  
 +
::<math>U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (2 P, 4 Q) = a^n + b^n</math>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L13</span><br/>
+
Zauważmy, że
Niech <math>p</math> będzie liczbą pierwszą nieparzystą, a&nbsp;liczby <math>u_k = a k + b</math> tworzą ciąg arytmetyczny oraz <math>\gcd (a, p) = 1</math>. Ciąg <math>(u_k)</math> zawiera nieskończenie wiele liczb kwadratowych i&nbsp;nieskończenie wiele liczb niekwadratowych modulo <math>p</math>.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
::<math>\alpha - \beta = \sqrt{D}</math>
Wystarczy pokazać, że w&nbsp;ciągu <math>u_k = a k + b</math> rozpatrywanym modulo <math>p</math> występuje każda z&nbsp;liczb <math>0, 1, 2, \ldots, p - 1</math>. Niech <math>r</math> oznacza dowolną z&nbsp;tych liczb. Musimy pokazać istnienie takiej liczby <math>k</math>, że
 
  
::<math>u_k = a k + b \equiv r \pmod{p}</math>
+
::<math>a - b = 2 \sqrt{D}</math>
  
::<math>a k \equiv r - b \pmod{p}</math>
+
::<math>{\small\frac{a}{\alpha}} = {\small\frac{b}{\beta}} = 2</math>
  
Ponieważ <math>\gcd (a, p) = 1</math>, to istnieją takie liczby <math>x, y</math>, że <math>a x + p y = 1</math> (zobacz C69 – lemat Bézouta). Zauważmy, że <math>p \nmid x</math>, bo gdyby tak było, to liczba <math>p</math> dzieliłaby wyrażenie <math>a x + p y</math>, ale jest to niemożliwe, bo <math>a x + p y = 1</math>. Zatem
+
Łatwo znajdujemy
  
::<math>a x k \equiv x (r - b) \pmod{p}</math>
+
::<math>U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} = {\small\frac{(2 \alpha)^n - (2 \beta)^n}{2 \sqrt{D}}} = 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = 2^{n - 1} U_n (P, Q)</math>
  
::<math>(1 - p y) k \equiv x (r - b) \pmod{p}</math>
+
::<math>V_n (2 P, 4 Q) = a^n + b^n = (2 \alpha)^n + (2 \beta)^n = 2^n (\alpha^n + \beta^n) = 2^n V_n (P, Q)</math>
  
::<math>k - p y k \equiv x (r - b) \pmod{p}</math>
+
Co należało pokazać.<br/>
 
 
::<math>k \equiv x (r - b) \pmod{p}</math>
 
 
 
Czyli szukana liczba <math>k</math> istnieje dla każdego <math>r \in [0, 1, \ldots, p - 1]</math>. Co kończy dowód.<br/>
 
 
&#9633;
 
&#9633;
 
{{\Spoiler}}
 
{{\Spoiler}}
Linia 338: Linia 262:
  
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L14</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Zadanie L11</span><br/>
Metody użytej w&nbsp;dowodzie twierdzenia L10 nie można stosować w przypadku liczb złożonych, bo łatwo można znaleźć przykłady takich złożonych liczb <math>m</math>, że każda z&nbsp;liczb <math>u \in [1, g - 1]</math> (poza liczbą <math>1</math> i&nbsp;potęgami liczby <math>2</math>) nie jest względnie pierwsza z <math>m</math>. Niech <math>g = p_{n + 1}</math>, gdzie <math>n \geqslant 2</math>, oraz <math>r = p_2 \cdot \ldots \cdot p_n</math> będzie iloczynem wszystkich liczb pierwszych nieparzystych mniejszych od <math>g</math>. Z&nbsp;definicji liczby <math>r</math> wynika, że
+
Pokazać, że jeżeli <math>Q \in \mathbb{Z} \setminus \{ 0 \}</math> oraz <math>P = 4 Q - 1</math>, to
  
* dla każdej liczby pierwszej nieparzystej <math>q</math> mniejszej od <math>g</math> mamy <math>\left( {\small\frac{q}{r}} \right)_{\small{\!\! J}} = 0</math>
+
::<math>U_{2 k} (P, P Q) = - (- P)^k U_{2 k} (1, Q)</math>
  
* każda z&nbsp;liczb <math>u \in [1, g - 1]</math> (poza liczbą <math>1</math> i&nbsp;potęgami liczby <math>2</math>) nie jest względnie pierwsza z <math>r</math>
+
::<math>U_{2 k + 1} (P, P Q) = (- P)^k V_{2 k + 1} (1, Q)</math>
  
 +
::<math>V_{2 k} (P, P Q) = (- P)^k V_{2 k} (1, Q)</math>
  
Zauważmy, że
+
::<math>V_{2 k + 1} (P, P Q) = - (- P)^{k + 1} U_{2 k + 1} (1, Q)</math>
  
* jeżeli <math>\left( {\small\frac{2}{r}} \right)_{\small{\!\! J}} = + 1</math> i <math>\left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = - 1</math>, to <math>r</math> jest poszukiwaną liczbą, czyli <math>m = r</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Niech
  
* jeżeli <math>\left( {\small\frac{2}{r}} \right)_{\small{\!\! J}} = - 1</math> i <math>\left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = - 1</math>, to wystarczy znaleźć liczbę nieparzystą <math>k</math> taką, że <math>\left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} = - 1</math> i <math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = + 1</math>, wtedy liczba <math>m = k r</math> jest poszukiwaną liczbą, bo
+
::<math>\alpha = {\small\frac{1 + \sqrt{- P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{- P}}{2}}</math>
  
::<math>\left( {\small\frac{2}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{k r}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{2}{r}} \right)_{\small{\!\! J}} = (- 1) \cdot (- 1) = + 1</math>
+
::<math>a = {\small\frac{P + \sqrt{- P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{- P}}{2}}</math>
  
::<math>\left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{g}{k r}} \right)_{\small{\!\! J}} = \left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = (+ 1) \cdot (- 1) = - 1</math>
+
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
  
* jeżeli <math>\left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = + 1</math>, to wystarczy znaleźć liczbę nieparzystą <math>k</math> taką, że <math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = - 1</math> i <math>\left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{r}} \right)_{\small{\!\! J}}</math>, wtedy liczba <math>m = k r</math> jest poszukiwaną liczbą, bo
+
::<math>x^2 - x + {\small\frac{P + 1}{4}} = 0</math>
  
::<math>\left( {\small\frac{2}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{k r}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{2}{r}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{r}} \right)_{\small{\!\! J}}^{\! 2} = + 1</math>
+
::<math>x^2 - P x + {\small\frac{P (P + 1)}{4}} = 0</math>
  
::<math>\left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{g}{k r}} \right)_{\small{\!\! J}} = \left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = (- 1) \cdot (+ 1) = - 1</math>
+
Z założenia <math>P = 4 Q - 1</math>, zatem
  
 +
::<math>x^2 - x + Q = 0</math>
  
Zauważmy, że poszukiwana liczba <math>k</math> istnieje. Pokażemy to dla punktu drugiego, ale Czytelnik bez trudu może powtórzyć poniższe rozważania dla punktu trzeciego. Szukamy liczby <math>k</math> takiej, że <math>\left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} = - 1</math> i <math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = + 1</math>. Ponieważ musi być <math>\left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} = - 1</math>, to <math>k</math> musi być postaci <math>k = 8 j \pm 3</math>. Niech <math>k = 8 j - 3</math>, mamy
+
::<math>x^2 - P x + P Q = 0</math>
  
::<math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = \left( {\small\frac{k}{g}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{k - 1}{2} \cdot \tfrac{g - 1}{2}}</math>
+
Czyli definiują one ciągi Lucasa
  
Wykładnik jest liczbą parzystą, bo <math>{\small\frac{g - 1}{2}}</math> jest liczbą całkowitą, a <math>{\small\frac{k - 1}{2}} = 4 j - 2</math>. Zatem
+
::<math>U_n (1, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \:\:\: V_n (1, Q) = \alpha^n + \beta^n</math>
  
::<math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = \left( {\small\frac{k}{g}} \right)_{\small{\!\! J}} = \left( {\small\frac{8 j - 3}{g}} \right)_{\small{\!\! J}}</math>
+
::<math>U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n</math>
  
Ponieważ <math>\gcd (8, g) = 1</math>, to ciąg arytmetyczny liczb <math>k = 8 j - 3</math> zawiera nieskończenie wiele liczb kwadratowych i&nbsp;nieskończenie wiele liczb niekwadratowych modulo <math>g</math> (zobacz L13), zatem istnieje taki wyraz <math>k = 8 j - 3</math>, że <math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = + 1</math>.
+
Zauważmy, że
  
 +
::<math>\alpha - \beta = a - b = \sqrt{- P}</math>
  
Poniżej podajemy przykłady najmniejszych liczb <math>k</math> dla kolejnych liczb <math>g</math>. Nie wypisujemy pełnych iloczynów <math>m = k r</math>, bo są to zbyt duże liczby. Przykładowo liczba <math>m = k r</math> dla <math>g = 97</math> jest równa <math>m \approx 3.565 \cdot 10^{34}</math>.
+
::<math>{\small\frac{a}{\beta}} = {\small\frac{P + \sqrt{- P}}{1 - \sqrt{- P}}} = \sqrt{- P}</math>
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
+
::<math>{\small\frac{b}{\alpha}} = {\small\frac{P - \sqrt{- P}}{1 + \sqrt{- P}}} = - \sqrt{- P}</math>
! <math>g</math>
 
| <math>5</math> || <math>7</math> || <math>11</math> || <math>13</math> || <math>17</math> || <math>19</math> || <math>23</math> || <math>29</math> || <math>31</math> || <math>37</math> || <math>41</math> || <math>43</math> || <math>47</math> || <math>53</math> || <math>59</math> || <math>61</math> || <math>67</math> || <math>71</math> || <math>73</math> || <math>79</math> || <math>83</math> || <math>89</math> || <math>97</math>
 
|-
 
! <math>k</math>
 
| <math>11</math> || <math>1</math> || <math>1</math> || <math>3</math> || <math>7</math> || <math>1</math> || <math>11</math> || <math>3</math> || <math>1</math> || <math>1</math> || <math>5</math> || <math>5</math> || <math>7</math> || <math>23</math> || <math>5</math> || <math>7</math> || <math>3</math> || <math>15</math> || <math>1</math> || <math>1</math> || <math>7</math> || <math>5</math> || <math>3</math>
 
|}
 
  
  
 +
Łatwo znajdujemy
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L15</span><br/>
+
::<math>U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k} - \left( - \alpha \sqrt{- P} \right)^{2 k}}{\sqrt{- P}} = \frac{(- P)^k (\beta^{2 k} - \alpha^{2 k})}{\alpha - \beta} = - (- P)^k U_{2 k} (1, Q)</math>
Liczby <math>g = g (m)</math> są zaskakująco małe. Średnia wartość <math>g = g (p)</math>, gdzie <math>p</math> są nieparzystymi liczbami pierwszymi, jest równa<ref name="Erdos1"/>
 
  
::<math>\lim_{x \to \infty} {\small\frac{1}{\pi (x)}} \sum_{p \leqslant x} g (p) = \sum_{k = 1}^{\infty} {\small\frac{p_k}{2^k}} = 3.674643966 \ldots</math>
 
  
A średnia wartość <math>g = g (m)</math>, gdzie <math>m</math> są liczbami nieparzystymi (przyjmujemy <math>g(m) = 0</math>, gdy <math>m</math> jest liczbą kwadratową) wynosi<ref name="BaillieWagstaff1"/>
+
::<math>U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k + 1} - \left( - \alpha \sqrt{- P} \right)^{2 k + 1}}{\sqrt{- P}} = (- P)^k (\beta^{2 k + 1} + \alpha^{2 k + 1}) = (- P)^k V_{2 k + 1} (1, Q)</math>
  
::<math>\lim_{x \to \infty} {\small\frac{1}{x / 2}} \underset{m \; \text{nieparzyste}}{\sum_{m \leqslant x}} g (m) = \sum_{k = 2}^{\infty} {\small\frac{p_k + 1}{2^{k - 1}}} \prod^{k - 1}_{j = 1} \left( 1 - {\small\frac{1}{p_j}} \right) = 3.147755149 \ldots</math>
 
  
 +
::<math>V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \beta \sqrt{- P} \right)^{2 k} + \left( - \alpha \sqrt{- P} \right)^{2 k} = (- P)^k (\alpha^{2 k} + \beta^{2 k}) = (- P)^k V_{2 k} (1, Q)</math>
  
  
 +
::<math>V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \beta \sqrt{- P} \right)^{2 k + 1} + \left( - \alpha \sqrt{- P} \right)^{2 k + 1} = (- P)^{k + 1} \cdot \frac{\beta^{2 k + 1} - \alpha^{2 k + 1}}{\sqrt{- P}} = - (- P)^{k + 1} U_{2 k + 1} (1, Q)</math>
  
 +
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
== Ciągi Lucasa ==
 
  
<span style="font-size: 110%; font-weight: bold;">Definicja L16</span><br/>
 
Niech <math>P, Q \in \mathbb{Z} \setminus \{0\}</math> oraz <math>D = P^2 - 4 Q \neq 0</math>. Ciągi Lucasa <math>U_n = U_n (P, Q)</math> i <math>V_n = V_n (P, Q)</math> definiujemy następująco
 
  
::<math>U_n = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}}</math>
+
<span style="font-size: 110%; font-weight: bold;">Zadanie L12</span><br/>
 +
Pokazać, że jeżeli <math>Q \in \mathbb{Z} \setminus \{ 0 \}</math> oraz <math>P = 4 Q + 1</math>, to
  
::<math>V_n = \alpha^n + \beta^n</math>
+
::<math>U_{2 k} (P, P Q) = P^k U_{2 k} (1, - Q)</math>
  
gdzie liczby
+
::<math>U_{2 k + 1} (P, P Q) = P^k V_{2 k + 1} (1, - Q)</math>
  
::<math>\alpha = {\small\frac{P + \sqrt{D}}{2}}</math>
+
::<math>V_{2 k} (P, P Q) = P^k V_{2 k} (1, - Q)</math>
  
::<math>\beta = {\small\frac{P - \sqrt{D}}{2}}</math>
+
::<math>V_{2 k + 1} (P, P Q) = P^{k + 1} U_{2 k + 1} (1, - Q)</math>
  
są pierwiastkami równania <math>x^2 - P x + Q = 0</math>.
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Niech
  
 +
::<math>\alpha = {\small\frac{1 + \sqrt{P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{P}}{2}}</math>
  
 +
::<math>a = {\small\frac{P + \sqrt{P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{P}}{2}}</math>
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L17</span><br/>
+
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
Zauważmy, że:
 
  
::<math>P = \alpha + \beta</math>
+
::<math>x^2 - x - {\small\frac{P - 1}{4}} = 0</math>
  
::<math>Q = \alpha \beta</math>
+
::<math>x^2 - P x + {\small\frac{P (P - 1)}{4}} = 0</math>
  
::<math>\sqrt{D} = \alpha - \beta</math>
+
Z założenia <math>P = 4 Q + 1</math>, zatem
  
::<math>U_0 = 0</math>, <math>U_1 = 1</math>, <math>V_0 = 2</math> i <math>V_1 = P</math>
+
::<math>x^2 - x - Q = 0</math>
  
 +
::<math>x^2 - P x + P Q = 0</math>
  
Warunek <math>P^2 - 4 Q \neq 0</math> wyklucza następujące pary <math>(P, Q)</math>
+
Czyli definiują one ciągi Lucasa
  
::<math>(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>
+
::<math>U_n (1, - Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad V_n (1, - Q) = \alpha^n + \beta^n</math>
  
 +
::<math>U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n</math>
  
 +
Zauważmy, że
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L18</span><br/>
+
::<math>\alpha - \beta = a - b = \sqrt{P}</math>
Oczywiście liczby <math>\alpha</math> i <math>\beta</math> są również pierwiastkami równania
 
  
::<math>x^{n + 2} - P x^{n + 1} + Q x^n = 0</math>
+
::<math>{\small\frac{a}{\alpha}} = {\small\frac{P + \sqrt{P}}{1 + \sqrt{P}}} = \sqrt{P}</math>
  
Wynika stąd, że ciągi <math>(\alpha^n)</math> i <math>(\beta^n)</math> spełniają równania rekurencyjne
+
::<math>{\small\frac{b}{\beta}} = {\small\frac{P - \sqrt{P}}{1 - \sqrt{P}}} = - \sqrt{P}</math>
 
 
::<math>\alpha^{n + 2} = P \alpha^{n + 1} - Q \alpha^n</math>
 
  
::<math>\beta^{n + 2} = P \beta^{n + 1} - Q \beta^n</math>
 
  
Ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> spełniają identyczne równania rekurencyjne jak ciągi <math>(\alpha^n)</math> i <math>(\beta^n)</math>. Istotnie, odejmując i&nbsp;dodając stronami wypisane powyżej równania, otrzymujemy
+
Łatwo znajdujemy
  
::<math>U_{n + 2} = P U_{n + 1} - Q U_n</math>
+
::<math>U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k} - \left( - \beta \sqrt{P} \right)^{2 k}}{\sqrt{P}} = \frac{P^k (\alpha^{2 k} - \beta^{2 k})}{\alpha - \beta} = P^k U_{2 k} (1, - Q)</math>
  
::<math>V_{n + 2} = P V_{n + 1} - Q V_n</math>
 
  
Dlatego możemy zdefiniować ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> w&nbsp;sposób równoważny
+
::<math>U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k + 1} - \left( - \beta \sqrt{P} \right)^{2 k + 1}}{\sqrt{P}} = P^k (\alpha^{2 k + 1} + \beta^{2 k + 1}) = P^k V_{2 k + 1} (1, - Q)</math>
  
  
 +
::<math>V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \alpha \sqrt{P} \right)^{2 k} + \left( - \beta \sqrt{P} \right)^{2 k} = P^k (\alpha^{2 k} + \beta^{2 k}) = P^k V_{2 k} (1, - Q)</math>
  
<span style="font-size: 110%; font-weight: bold;">Definicja L19</span><br/>
 
Niech <math>P, Q \in \mathbb{Z} \setminus \{0\}</math> oraz <math>D = P^2 - 4 Q \neq 0</math>. Ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> określone są następującymi wzorami rekurencyjnymi
 
  
::<math>U_0 = 0</math>, <math>U_1 = 1</math>, <math>U_n = P U_{n - 1} - Q U_{n - 2}</math>
+
::<math>V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \alpha \sqrt{P} \right)^{2 k + 1} + \left( - \beta \sqrt{P} \right)^{2 k + 1} = P^{k + 1} \cdot \frac{\alpha^{2 k + 1} - \beta^{2 k + 1}}{\sqrt{P}} = P^{k + 1} U_{2 k + 1} (1, - Q)</math>
  
::<math>V_0 = 2</math>, <math>V_1 = P</math>, <math>V_n = P V_{n - 1} - Q V_{n - 2}</math>
+
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
  
  
<span style="font-size: 110%; font-weight: bold;">Przykład L20</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L13</span><br/>
Początkowe wyrazy ciągów Lucasa
+
Dla wyrazów ciągów Lucasa prawdziwe są wzory
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: left; margin-right: auto;"
+
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 
|-
 
|-
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{U_n (P, Q)}</math> !! <math>\boldsymbol{V_n (P, Q)}</math>
+
| <math>1.</math> || <math>U_{m + n} = U_m U_{n + 1} - Q U_{m - 1} U_n</math> ||
 
|-
 
|-
| &nbsp;&nbsp;<math>0</math>&nbsp;&nbsp; || <math>0</math> || <math>2</math>
+
| <math>2.</math> || <math>V_{m + n} = V_m V_n - Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 +
|-
 +
| <math>3.</math> || <math>U_{m + n} = U_m V_n - Q^n U_{m - n}</math> || <math>m \geqslant n</math>
 +
|-
 +
| <math>4.</math> || <math>V_{m + n} = D U_m U_n + Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 +
|-
 +
| <math>5.</math> || <math>U_m V_n - V_m U_n = 2 Q^n U_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
|-
| &nbsp;&nbsp;<math>1</math>&nbsp;&nbsp; || <math>1</math> || <math>P</math>
+
| <math>6.</math> || <math>U^2_n = U_{n - 1} U_{n + 1} + Q^{n - 1}</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>2</math>&nbsp;&nbsp; || <math>P</math> || <math>P^2 - 2 Q</math>
+
| <math>7.</math> || <math>V^2_n = V_{n - 1} V_{n + 1} - D Q^{n - 1}</math> ||  
 +
|}
 +
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 
|-
 
|-
| &nbsp;&nbsp;<math>3</math>&nbsp;&nbsp; || <math>P^2 - Q</math> || <math>P^3 - 3 P Q</math>
+
| <math>\;\; 8.</math> || <math>2 U_{m + n} = U_m V_n + V_m U_n</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>4</math>&nbsp;&nbsp; || <math>P^3 - 2 P Q</math> || <math>P^4 - 4 P^2 Q + 2 Q^2</math>
+
| <math>\;\; 9.</math> || <math>2 V_{m + n} = V_m V_n + D U_m U_n</math> ||
 
|-
 
|-
| &nbsp;&nbsp;<math>5</math>&nbsp;&nbsp; || <math>P^4 - 3 P^2 Q + Q^2</math> || <math>P^5 - 5 P^3 Q + 5 P Q^2</math>
+
| <math>10.</math> || <math>V_m V_n - D U_m U_n = 2 Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
|-
| &nbsp;&nbsp;<math>6</math>&nbsp;&nbsp; || <math>P^5 - 4 P^3 Q + 3 P Q^2</math> || <math>P^6 - 6 P^4 Q + 9 P^2 Q^2 - 2 Q^3</math>
+
| <math>11.</math> || <math>U_{2 n} = U_n V_n</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>7</math>&nbsp;&nbsp; || <math>P^6 - 5 P^4 Q + 6 P^2 Q^2 - Q^3</math> || <math>P^7 - 7 P^5 Q + 14 P^3 Q^2 - 7 P Q^3</math>
+
| <math>12.</math> || <math>V_{2 n} = V^2_n - 2 Q^n</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>8</math>&nbsp;&nbsp; || <math>P^7 - 6 P^5 Q + 10 P^3 Q^2 - 4 P Q^3</math> || <math>P^8 - 8 P^6 Q + 20 P^4 Q^2 - 16 P^2 Q^3 + 2 Q^4</math>
+
| <math>13.</math> || <math>V_{2 n} = D U^2_n + 2 Q^n</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>9</math>&nbsp;&nbsp; || <math>P^8 - 7 P^6 Q + 15 P^4 Q^2 - 10 P^2 Q^3 + Q^4</math> || <math>P^9 - 9 P^7 Q + 27 P^5 Q^2 - 30 P^3 Q^3 + 9 P Q^4</math>
+
| <math>14.</math> || <math>V^2_n - D U^2_n = 4 Q^n</math> ||
|}
+
|-
 
+
| <math>15.</math> || <math>D U_n = 2 V_{n + 1} - P V_n</math> ||
 
+
|-
 
+
| <math>16.</math> || <math>V_n = 2 U_{n + 1} - P U_n</math> ||
<span style="font-size: 110%; font-weight: bold;">Uwaga L21</span><br/>
+
|-
W PARI/GP możemy napisać prosty kod, który pozwoli obliczyć wartości wyrazów <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math>
+
| <math>17.</math> || <math>D U_n = V_{n + 1} - Q V_{n - 1}</math> || <math>n \geqslant 1</math>
 +
|-
 +
| <math>18.</math> || <math>V_n = U_{n + 1} - Q U_{n - 1}</math> || <math>n \geqslant 1</math>
 +
|}
 +
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 +
|-
 +
| <math>19.</math> || <math>U_{2 n} = 2 U_n U_{n + 1} - P U^2_n</math>
 +
|-
 +
| <math>20.</math> || <math>U_{2 n + 1} = U^2_{n + 1} - Q U^2_n</math>
 +
|-
 +
| <math>21.</math> || <math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
 +
|}
  
<span style="font-size: 90%; color:black;">LucasU(n, P, Q) = '''if'''( n == 0, 0, '''if'''( n == 1, 1, P*LucasU(n-1, P, Q) - Q*LucasU(n-2, P, Q) ) )</span>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
'''Wzory 1. - 7. najłatwiej udowodnić korzystając z&nbsp;definicji L1.'''
  
<span style="font-size: 90%; color:black;">LucasV(n, P, Q) = '''if'''( n == 0, 2, '''if'''( n == 1, P, P*LucasV(n-1, P, Q) - Q*LucasV(n-2, P, Q) ) )</span>
+
Wzór 1.
  
 +
::<math>U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}}</math>
  
 +
:::<math>\quad \: = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} - \alpha \beta \cdot {\small\frac{\alpha^{m - 1} - \beta^{m - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}}</math>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L22</span><br/>
+
:::<math>\quad \: = U_m U_{n + 1} - Q U_{m - 1} U_n</math>
Niech <math>D = P^2 - 4 Q</math>. Wyrazy ciągów Lucasa można przedstawić w&nbsp;postaci sumy
 
  
::<math>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>2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
+
Wzór 2.
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
::<math>V_{m + n} = \alpha^{m + n} + \beta^{m + n}</math>
Oznaczmy <math>\delta = \sqrt{D}</math>, zatem <math>2 \alpha = P + \delta</math> i <math>2 \beta = P - \delta</math>. Ze wzoru dwumianowego, mamy
 
  
::<math>2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j</math>
+
:::<math>\quad \;\! = (\alpha^m + \beta^m) (\alpha^n + \beta^n) - \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n})</math>
  
::<math>2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j</math>
+
:::<math>\quad \;\! = V_m V_n - Q^n V_{m - n}</math>
  
Obliczając sumę powyższych wzorów, otrzymujemy
 
  
::<math>2^n (\alpha^n + \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j + (- \delta)^j)</math>
+
Wzór 3.
  
:::::<math>\quad \: = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} \cdot 2 \delta^{2 k}</math>
+
::<math>U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}}</math>
  
:::::<math>\quad \: = 2 \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
+
:::<math>\quad \: = {\small\frac{(\alpha^m - \beta^m) (\alpha^n + \beta^n)}{\alpha - \beta}} - {\small\frac{\alpha^n \beta^n \cdot (\alpha^{m - n} - \beta^{m - n})}{\alpha - \beta}}</math>
  
gdzie <math>j = 2 k</math> i&nbsp;sumowanie przebiega od <math>k = 0</math> do <math>k = \lfloor n / 2 \rfloor</math>
+
:::<math>\quad \: = U_m V_n - Q^n U_{m - n}</math>
  
Zatem
 
  
::<math>2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
+
Wzór 4.
  
 +
::<math>V_{m + n} = \alpha^{m + n} + \beta^{m + n}</math>
  
Obliczając różnicę tych wzorów, mamy
+
:::<math>\quad \;\! = (\alpha - \beta)^2 \cdot {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} + \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n})</math>
  
::<math>2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j)</math>
+
:::<math>\quad \;\! = D U_m U_n + Q^n V_{m - n}</math>
  
:::::<math>\quad \: = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} \cdot 2 \delta^{2 k + 1}</math>
 
  
:::::<math>\quad \: = 2 \delta \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
+
Wzór 5.
  
gdzie <math>j = 2 k + 1</math> i&nbsp;sumowanie przebiega od <math>k = 0</math> do <math>k = \lfloor (n - 1) / 2 \rfloor</math>
+
::<math>U_m V_n - V_m U_n = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot (\alpha^n + \beta^n) - (\alpha^m + \beta^m) \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}}</math>
  
 +
::::::<math>\;\;\: = 2 \cdot \alpha^n \beta^n \cdot {\small\frac{\alpha^{m - n} - \beta^{m - n}}{\alpha - \beta}}</math>
  
Zatem
+
::::::<math>\;\;\: = 2 Q^n U_{m - n}</math>
  
::<math>2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}} = 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>
 
  
Co należało pokazać.<br/>
+
Wzór 6.
&#9633;
 
{{\Spoiler}}
 
  
 +
::<math>U^2_n = \left( {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \right)^2</math>
  
 +
:::<math>\;\! = {\small\frac{\alpha^{n - 1} - \beta^{n - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} + \alpha^{n - 1} \beta^{n - 1}</math>
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L23</span><br/>
+
:::<math>\;\! = U_{n - 1} U_{n + 1} + Q^{n - 1}</math>
Korzystając z&nbsp;twierdzenia L22, możemy napisać proste funkcje do znajdowania postaci kolejnych wyrazów <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math>
 
  
<span style="font-size: 90%; color:black;">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)</span>
 
  
<span style="font-size: 90%; color:black;">V(n) = 2^(1 - n)*'''sum'''(k=0, '''floor'''(n/2), '''binomial'''(n, 2*k) * P^(n-2*k) * (P^2-4*Q)^k)</span>
+
Wzór 7.
  
 +
::<math>V^2_n = (\alpha^n + \beta^n)^2</math>
  
 +
:::<math>\;\! = (\alpha^{n - 1} + \beta^{n - 1}) (\alpha^{n + 1} + \beta^{n + 1}) - (\alpha - \beta)^2 \cdot \alpha^{n - 1} \beta^{n - 1}</math>
  
Często możemy spotkać założenie <math>P \geqslant 1</math>. Poniższe twierdzenie wyjaśnia, dlaczego tak jest.
+
:::<math>\;\! = V_{n - 1} V_{n + 1} - D Q^{n - 1}</math>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L24</span><br/>
 
Jeżeli <math>(U_n)</math> i <math>(V_n)</math> są ciągami Lucasa, to
 
  
::<math>U_n (- P, Q) = (- 1)^{n - 1} U_n (P, Q)</math>
+
'''Wzory 8. - 18. można łatwo udowodnić, korzystając ze wzorów 1. - 7.'''
  
::<math>V_n (- P, Q) = (- 1)^n V_n (P, Q)</math>
+
Wzór 8. Policzyć sumę wzoru 3. pomnożonego przez <math>2</math> i&nbsp;wzoru 5.
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
Wzór 9. Policzyć sumę wzorów 2. i 4.
Niech
 
  
::<math>\alpha = \frac{P + \sqrt{D}}{2} \qquad \qquad \;\; \beta = \frac{P - \sqrt{D}}{2}</math>
+
Wzór 10. Połączyć wzory 2. i 4.
  
::<math>a = \frac{- P + \sqrt{D}}{2} \qquad \qquad b = \frac{- P - \sqrt{D}}{2}</math>
+
Wzór 11. We wzorze 3. położyć <math>m = n</math>.
  
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
+
Wzór 12. We wzorze 2. położyć <math>m = n</math>.
  
::<math>x^2 - P x + Q = 0</math>
+
Wzór 13. We wzorze 4. położyć <math>m = n</math>.
  
::<math>x^2 + P x + Q = 0</math>
+
Wzór 14. We wzorze 10. położyć <math>m = n</math> lub połączyć wzory 12. i 13.
  
Zatem definiują one ciągi Lucasa
+
Wzór 15. We wzorze 9. położyć <math>m = 1</math>.
 +
 
 +
Wzór 16. We wzorze 8. położyć <math>m = 1</math>.
 +
 
 +
Wzór 17. We wzorze 15. położyć <math>V_{n + 1} = P V_n - Q V_{n - 1}</math>.
 +
 
 +
Wzór 18. We wzorze 16. położyć <math>U_{n + 1} = P U_n - Q U_{n - 1}</math>.
 +
 
 +
 
 +
'''Wzory 19. - 21. to wzory, które wykorzystamy w&nbsp;przyszłości do szybkiego obliczania wartości wyrazów <math>U_n</math> i <math>V_n</math> modulo.'''
 +
 
 +
Wzór 19. Wystarczy połączyć wzory 11. oraz 16.
 +
 
 +
Wzór 20. Wystarczy we wzorze 1. położyć <math>m = n + 1</math>.
  
::<math>U_n (P, Q) = \frac{\alpha^n - \beta^n}{\alpha - \beta} \qquad \qquad \;\; V_n (P, Q) = \alpha^n + \beta^n</math>
+
Wzór 21. Kładąc we wzorze 19. <math>n \rightarrow n + 1</math>, otrzymujemy
  
::<math>U_n (- P, Q) = \frac{a^n - b^n}{a - b} \qquad \qquad V_n (- P, Q) = a^n + b^n</math>
+
::<math>U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - P U^2_{n + 1} \qquad (*)</math>
  
Zauważmy, że
+
Kładąc we wzorze 1. <math>m = n + 2</math>, mamy
  
::<math>\alpha - \beta = a - b = \sqrt{D}</math>
+
::<math>U_{2 n + 2} = U_{n + 2} U_{n + 1} - Q U_{n + 1} U_n</math>
  
::<math>\frac{a}{\beta} = \frac{b}{\alpha} = - 1</math>
+
Czyli
  
Łatwo znajdujemy
+
::<math>2 U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - 2 Q U_n U_{n + 1}</math>
  
::<math>U_n (- P, Q) = \frac{a^n - b^n}{a - b} = \frac{(- \beta)^n - (- \alpha)^n}{\sqrt{D}} = (- 1)^n \cdot \frac{\beta^n - \alpha^n}{\alpha - \beta} = (- 1)^{n - 1} \cdot U_n (P, Q)</math>
+
Odejmując od powyższego wzoru wzór <math>(*)</math>, dostajemy wzór 21.
  
::<math>V_n (- P, Q) = a^n + b^n = (- \beta)^n + (- \alpha)^n = (- 1)^n \cdot (\alpha^n + \beta^n) = (- 1)^n \cdot V_n (P, Q)</math>
+
::<math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
  
 
Co należało pokazać.<br/>
 
Co należało pokazać.<br/>
Linia 610: Linia 561:
  
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L25</span><br/>
 
Pokazać, że jeżeli <math>P, Q \in \mathbb{Z} \setminus \{ 0 \}</math> i <math>D = P^2 - 4 Q \neq 0</math>, to
 
  
::<math>U_n (2 P, 4 Q) = 2^{n - 1} U_n (P, Q)</math>
 
  
::<math>V_n (2 P, 4 Q) = 2^n V_n (P, Q)</math>
+
== Obliczanie wyrazów ciągu Lucasa modulo <math>m</math> ==
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
<span style="font-size: 110%; font-weight: bold;">Przykład L14</span><br/>
Niech
+
Pokażemy, jak wykorzystać podane w&nbsp;twierdzeniu L13 wzory 19, 20, 21 i 16
  
::<math>\alpha = {\small\frac{P + \sqrt{D}}{2}} \qquad \qquad \;\; \beta = {\small\frac{P - \sqrt{D}}{2}}</math>
+
::<math>U_{2 n} = 2 U_n U_{n + 1} - P U^2_n</math>
  
::<math>a = P + \sqrt{D} \qquad \qquad \;\; b = P - \sqrt{D}</math>
+
::<math>U_{2 n + 1} = U^2_{n + 1} - Q U^2_n</math>
  
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
+
::<math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
  
::<math>x^2 - P x + Q = 0</math>
+
::<math>V_n = 2 U_{n + 1} - P U_n</math>
  
::<math>x^2 - 2 P x + 4 Q = 0</math>
+
do szybkiego obliczania wyrazów ciągu Lucasa modulo <math>m</math>.
  
Zatem definiują one ciągi Lucasa
 
  
::<math>U_n (P, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \;\;\; V_n (P, Q) = \alpha^n + \beta^n</math>
+
Niech <math>P = 3</math>, <math>Q = 1</math>, <math>D = P^2 - 4 Q = 5</math>, <math>n = 22 = (10110)_2 = \sum_{j = 0}^{4} a_j \cdot 2^j</math>.
  
::<math>U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (2 P, 4 Q) = a^n + b^n</math>
+
W tabeli przedstawione są kolejne kroki, jakie musimy wykonać, aby policzyć <math>U_n = U_{22}</math> modulo <math>m = 23</math>.
  
Zauważmy, że
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
 
+
|-
::<math>\alpha - \beta = \sqrt{D}</math>
+
! <math>\boldsymbol{j}</math> !! <math>\boldsymbol{a_j}</math> !! <math>\boldsymbol{k_j}</math> !! <math>\boldsymbol{U_{k_j}}</math> !! <math>\boldsymbol{U_{k_j + 1}}</math>
 
+
|-
::<math>a - b = 2 \sqrt{D}</math>
+
| <math>4</math> || <math>1</math> || <math>(1)_2 = 1</math> || <math>U_1 = 1</math> || <math>U_2 = P = 3</math>
 
+
|-
::<math>{\small\frac{a}{\alpha}} = {\small\frac{b}{\beta}} = 2</math>
+
| <math>3</math> || <math>0</math> || <math>(10)_2 = 2</math> || <math>U_2 = 2 U_1 U_2 - 3 U^2_1 = 6 - 3 = 3</math> || <math>U_3 = U^2_2 - 1 = 8</math>
 +
|-
 +
| <math>2</math> || <math>1</math> || <math>(101)_2 = 5</math> || <math>U_5 = U^2_3 - U^2_2 = 64 - 9 = 55 \equiv 9</math> || <math>U_6 = 3 U_3^2 - 2 U_2 U_3 = 192 - 48 = 144 \equiv 6</math>
 +
|-
 +
| <math>1</math> || <math>1</math> || <math>(1011)_2 = 11</math> || <math>U_{11} = U^2_6 - U^2_5 \equiv 36 - 81 \equiv - 45 \equiv 1</math> || <math>U_{12} = 3 U_6^2 - 2 U_5 U_6 \equiv 108 - 108 \equiv 0</math>
 +
|-
 +
| <math>0</math> || <math>0</math> || <math>(10110)_2 = 22</math> || <math>U_{22} = 2 U_{11} U_{12} - 3 U^2_{11} \equiv 0 - 3 \equiv 20</math> || <math>U_{23} = U^2_{12} - U^2_{11} \equiv 0 - 1 \equiv 22</math>
 +
|}
  
Łatwo znajdujemy
+
W kolumnie <math>a_j</math> wypisujemy kolejne cyfry liczby <math>n = 22 = (10110)_2</math> zapisanej w&nbsp;układzie dwójkowym. Liczby w&nbsp;kolumnie <math>k_j</math> tworzymy, biorąc kolejne (od prawej do lewej) cyfry liczby <math>n</math> w&nbsp;zapisie dwójkowym. Postępując w&nbsp;ten sposób, w&nbsp;ostatnim wierszu mamy <math>k_j = n</math> i&nbsp;wyliczamy liczby <math>U_n</math> i <math>U_{n + 1}</math> modulo <math>m</math>.
  
::<math>U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} = {\small\frac{(2 \alpha)^n - (2 \beta)^n}{2 \sqrt{D}}} = 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = 2^{n - 1} U_n (P, Q)</math>
+
Dla uproszczenia zapisu i&nbsp;ułatwienia zrozumienia liczbę <math>k_j</math> oznaczymy jako <math>r</math>, a <math>k_{j + 1}</math> jako <math>s</math>. Zauważmy, że
  
::<math>V_n (2 P, 4 Q) = a^n + b^n = (2 \alpha)^n + (2 \beta)^n = 2^n (\alpha^n + \beta^n) = 2^n V_n (P, Q)</math>
+
:* tabela jest zbudowana tak, że musimy znaleźć wyrazy ciągu Lucasa o&nbsp;indeksie <math>r = k_j</math> oraz o&nbsp;indeksie o&nbsp;jeden większym: <math>r + 1 = k_j + 1</math>
 +
:* przejście do następnego wiersza (w dół) oznacza, że musimy znaleźć wyrazy o&nbsp;indeksie <math>s = k_{j + 1}</math> oraz o&nbsp;indeksie o&nbsp;jeden większym: <math>s + 1</math>
 +
:* przechodząc do następnego wiersza, dotychczasowa liczba <math>r = k_j</math> powiększa się o&nbsp;kolejną cyfrę ( <math>0</math> lub <math>1</math> ), którą dopisujemy z&nbsp;prawej strony
 +
:* dodanie na końcu liczby <math>r = k_j</math> zera podwaja liczbę <math>r</math>, czyli <math>s = k_{j + 1} = 2 r</math> oraz <math>s + 1 = 2 r + 1</math>
 +
:* dodanie na końcu liczby <math>r = k_j</math> jedynki podwaja liczbę <math>r</math> i&nbsp;zwiększą ją o&nbsp;jeden, czyli <math>s = k_{j + 1} = 2 r + 1</math> oraz <math>s + 1 = 2 r + 2</math>
  
Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
  
 +
Dlatego, jeżeli kolejną dodaną cyfrą jest zero, to korzystamy ze wzorów
  
 +
::<math>U_s = U_{2 r} = 2 U_r U_{r + 1} - P U^2_r</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L26</span><br/>
+
::<math>U_{s + 1} = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r</math>
Pokazać, że jeżeli <math>Q \in \mathbb{Z} \setminus \{ 0 \}</math> oraz <math>P = 4 Q - 1</math>, to
 
  
::<math>U_{2 k} (P, P Q) = - (- P)^k U_{2 k} (1, Q)</math>
+
Gdy kolejną dodaną cyfrą jest jeden, to stosujemy wzory
  
::<math>U_{2 k + 1} (P, P Q) = (- P)^k V_{2 k + 1} (1, Q)</math>
+
::<math>U_s = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r</math>
  
::<math>V_{2 k} (P, P Q) = (- P)^k V_{2 k} (1, Q)</math>
+
::<math>U_{s + 1} = U_{2 r + 2} = P U^2_{r + 1} - 2 Q U_r U_{r + 1}</math>
  
::<math>V_{2 k + 1} (P, P Q) = - (- P)^{k + 1} U_{2 k + 1} (1, Q)</math>
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
Korzystając ze wzoru <math>V_n = 2 U_{n + 1} - P U_n</math>, mamy
Niech
 
  
::<math>\alpha = {\small\frac{1 + \sqrt{- P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{- P}}{2}}</math>
+
::<math>V_{22} = 2 U_{23} - 3 U_{22} \equiv 44 - 60 \equiv - 16 \equiv 7 \pmod{23}</math>
  
::<math>a = {\small\frac{P + \sqrt{- P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{- P}}{2}}</math>
+
Ostatecznie otrzymujemy
  
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
+
::<math>U_{22} \equiv 20 \pmod{23} \quad</math> oraz <math>\quad V_{22} \equiv 7 \pmod{23}</math>
  
::<math>x^2 - x + {\small\frac{P + 1}{4}} = 0</math>
 
  
::<math>x^2 - P x + {\small\frac{P (P + 1)}{4}} = 0</math>
 
  
Z założenia <math>P = 4 Q - 1</math>, zatem
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L15</span><br/>
 +
Uogólniając postępowanie przedstawione w&nbsp;przykładzie L14, możemy napisać program w&nbsp;PARI/GP do szybkiego obliczania wyrazów ciągu Lucasa <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math> modulo <math>m</math>.
  
::<math>x^2 - x + Q = 0</math>
+
<span style="font-size: 90%; color:black;">modLucas(n, P, Q, m) =
 
+
{
::<math>x^2 - P x + P Q = 0</math>
+
'''local'''(A, i, s, U, U2, V, W, W2);
 
+
'''if'''( m == 1, '''return'''([0, 0]) );
Czyli definiują one ciągi Lucasa
+
'''if'''( n == 0, '''return'''([0, 2 % m]) );
 
+
A = '''digits'''(n, 2); \\ otrzymujemy wektor cyfr liczby n w układzie dwójkowym
::<math>U_n (1, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \:\:\: V_n (1, Q) = \alpha^n + \beta^n</math>
+
s = '''length'''(A); \\ długość wektora A
 
+
U = 1;
::<math>U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n</math>
+
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]);
 +
}</span>
  
Zauważmy, że
 
  
::<math>\alpha - \beta = a - b = \sqrt{- P}</math>
 
  
::<math>{\small\frac{a}{\beta}} = {\small\frac{P + \sqrt{- P}}{1 - \sqrt{- P}}} = \sqrt{- P}</math>
 
  
::<math>{\small\frac{b}{\alpha}} = {\small\frac{P - \sqrt{- P}}{1 + \sqrt{- P}}} = - \sqrt{- P}</math>
 
  
 +
== Podzielność wyrazów <math>U_n (P, Q)</math> przez liczbę pierwszą nieparzystą ==
  
Łatwo znajdujemy
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L16</span><br/>
 +
Niech <math>p</math> będzie liczbą pierwszą nieparzystą. W&nbsp;przypadku, gdy <math>p \nmid P Q</math> nie możemy nic powiedzieć o&nbsp;podzielności wyrazów <math>U_n</math> przez <math>p</math>. Przykładowo, jeżeli <math>P \equiv 1 \pmod{p} \;</math> <math>\text{i} \;\; Q \equiv 1 \pmod{p}</math>, to modulo <math>p</math>, mamy
  
::<math>U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k} - \left( - \alpha \sqrt{- P} \right)^{2 k}}{\sqrt{- P}} = \frac{(- P)^k (\beta^{2 k} - \alpha^{2 k})}{\alpha - \beta} = - (- P)^k U_{2 k} (1, Q)</math>
+
::<math>(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>P \equiv 2 \pmod{p} \;</math> <math>\text{i} \;\; Q \equiv 1 \pmod{p}</math>, to modulo <math>p</math> mamy
  
::<math>U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k + 1} - \left( - \alpha \sqrt{- P} \right)^{2 k + 1}}{\sqrt{- P}} = (- P)^k (\beta^{2 k + 1} + \alpha^{2 k + 1}) = (- P)^k V_{2 k + 1} (1, Q)</math>
+
::<math>(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>p \, | \, P Q</math>.
  
::<math>V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \beta \sqrt{- P} \right)^{2 k} + \left( - \alpha \sqrt{- P} \right)^{2 k} = (- P)^k (\alpha^{2 k} + \beta^{2 k}) = (- P)^k V_{2 k} (1, Q)</math>
 
  
  
::<math>V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \beta \sqrt{- P} \right)^{2 k + 1} + \left( - \alpha \sqrt{- P} \right)^{2 k + 1} = (- P)^{k + 1} \cdot \frac{\beta^{2 k + 1} - \alpha^{2 k + 1}}{\sqrt{- P}} = - (- P)^{k + 1} U_{2 k + 1} (1, Q)</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L17</span><br/>
 +
Niech <math>p</math> będzie liczbą pierwszą nieparzystą.
  
Co należało pokazać.<br/>
+
::{| border="0"
&#9633;
+
|-style=height:1.9em
{{\Spoiler}}
+
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, P \;</math> <math>\text{i} \;\; p \, | \, Q , \;</math> to <math>\; p \, | \, U_n \;</math> dla <math>n \geqslant 2</math>
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, P \;</math> <math>\text{i} \;\; p \nmid Q , \;</math> to <math>\; p \, | \, U_{2 n} \;</math> i <math>\; p \nmid U_{2 n + 1}</math>
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \nmid P \;</math> <math>\text{i} \;\; p \, | \, Q , \;</math> to <math>\; p \nmid U_n \;</math> dla <math>n \geqslant 1</math>
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, Q , \;</math> to <math>\; p \, | \, U_n</math>, gdzie <math>n \geqslant 2</math>, wtedy i&nbsp;tylko wtedy, gdy <math>\; p \, | \, P</math>
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \nmid P \;</math> <math>\text{i} \;\; p \, | \, D , \;</math> to <math>\; p \, | \, U_n \;</math> wtedy i&nbsp;tylko wtedy, gdy <math>p \, | \, n</math>
 +
|}
  
 +
Założenie, że <math>p \nmid P</math> w&nbsp;ostatnim punkcie jest istotne. Gdy <math>\; p \, | \, P \;</math> i <math>\; p \, | \, D , \;</math> to <math>\; p \, | \, Q \;</math> i&nbsp;otrzymujemy punkt pierwszy.
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
'''Punkt 1.'''
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L27</span><br/>
+
Ponieważ <math>U_2 = P</math>, zatem <math>p \, | \, U_2</math>. Dla <math>n \geqslant 3</math> wyrażenie <math>U_n = P U_{n - 1} - Q U_{n - 2}</math> jest podzielne przez <math>p</math>.
Pokazać, że jeżeli <math>Q \in \mathbb{Z} \setminus \{ 0 \}</math> oraz <math>P = 4 Q + 1</math>, to
 
  
::<math>U_{2 k} (P, P Q) = P^k U_{2 k} (1, - Q)</math>
+
'''Punkt 2.'''
  
::<math>U_{2 k + 1} (P, P Q) = P^k V_{2 k + 1} (1, - Q)</math>
+
Indeksy parzyste. Indukcja matematyczna. Mamy <math>U_0 = 0</math> i <math>U_2 = P</math>, zatem <math>p \, | \, U_0</math> i <math>p \, | \, U_2</math>. Zakładając, że <math>p \, | \, U_{2 n}</math>, z definicji ciągu <math>(U_k)</math>, otrzymujemy dla <math>U_{2 n + 2}</math>
  
::<math>V_{2 k} (P, P Q) = P^k V_{2 k} (1, - Q)</math>
+
::<math>U_{2 n + 2} = P U_{2 n - 1} - Q U_{2 n}</math>
  
::<math>V_{2 k + 1} (P, P Q) = P^{k + 1} U_{2 k + 1} (1, - Q)</math>
+
Z założenia indukcyjnego wynika, że <math>p \, | \, U_{2 n + 2}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich <math>n \geqslant 0</math>.
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
Indeksy nieparzyste. Indukcja matematyczna. Mamy <math>U_1 = 1</math> i <math>U_3 = P^2 - Q</math>, zatem <math>p \nmid U_1</math> i <math>p \nmid U_3</math>. Zakładając, że <math>p \nmid U_{2 n - 1}</math>, z definicji ciągu <math>(U_k)</math>, otrzymujemy dla <math>U_{2 n + 1}</math>
Niech
 
  
::<math>\alpha = {\small\frac{1 + \sqrt{P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{P}}{2}}</math>
+
::<math>U_{2 n + 1} = P U_{2 n} - Q U_{2 n - 1}</math>
  
::<math>a = {\small\frac{P + \sqrt{P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{P}}{2}}</math>
+
Z założenia indukcyjnego wynika, że <math>p \nmid U_{2 n + 1}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich <math>n \geqslant 1</math>.
  
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
+
'''Punkt 3.'''
  
::<math>x^2 - x - {\small\frac{P - 1}{4}} = 0</math>
+
Indukcja matematyczna. Mamy <math>U_1 = 1</math> i <math>U_2 = P</math>, zatem <math>p \nmid U_1</math> i <math>p \nmid U_2</math>. Zakładając, że <math>p \nmid U_n</math> zachodzi dla wszystkich liczb całkowitych dodatnich nie większych od <math>n</math>, z&nbsp;definicji ciągu <math>(U_n)</math>
 +
otrzymujemy dla <math>n + 1</math>
  
::<math>x^2 - P x + {\small\frac{P (P - 1)}{4}} = 0</math>
+
::<math>U_{n + 1} = P U_n - Q U_{n - 1}</math>
  
Z założenia <math>P = 4 Q + 1</math>, zatem  
+
Z założenia indukcyjnego wynika, że <math>p \nmid U_{n + 1}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich liczb <math>n \geqslant 1</math>.
  
::<math>x^2 - x - Q = 0</math>
+
'''Punkt 4.'''
  
::<math>x^2 - P x + P Q = 0</math>
+
Wynika z&nbsp;punktów pierwszego i&nbsp;trzeciego.
  
Czyli definiują one ciągi Lucasa
+
'''Punkt 5.'''
  
::<math>U_n (1, - Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad V_n (1, - Q) = \alpha^n + \beta^n</math>
+
Z twierdzenia L7 wiemy, że
  
::<math>U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n</math>
+
::<math>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>
  
Zauważmy, że
+
::::<math>\;\; = n P^{n - 1} + \binom{n}{3} P^{n - 3} D + \binom{n}{5} P^{n - 5} D^2 + \ldots +
 +
\begin{cases}
 +
n P D^{(n - 2) / 2} & \text{gdy }n\text{ jest parzyste} \\
 +
D^{(n - 1) / 2} & \text{gdy }n\text{ jest nieparzyste}
 +
\end{cases}</math>
  
::<math>\alpha - \beta = a - b = \sqrt{P}</math>
+
Z założenia <math>p \, | \, D</math>, zatem modulo <math>p</math> dostajemy
  
::<math>{\small\frac{a}{\alpha}} = {\small\frac{P + \sqrt{P}}{1 + \sqrt{P}}} = \sqrt{P}</math>
+
::<math>2^{n - 1} U_n \equiv n P^{n - 1} \pmod{p}</math>
  
::<math>{\small\frac{b}{\beta}} = {\small\frac{P - \sqrt{P}}{1 - \sqrt{P}}} = - \sqrt{P}</math>
+
Ponieważ <math>p \nmid P</math>, zatem <math>p \, | \, U_n</math> wtedy i&nbsp;tylko wtedy, gdy <math>p \, | \, n</math>.
 +
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
  
Łatwo znajdujemy
 
  
::<math>U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k} - \left( - \beta \sqrt{P} \right)^{2 k}}{\sqrt{P}} = \frac{P^k (\alpha^{2 k} - \beta^{2 k})}{\alpha - \beta} = P^k U_{2 k} (1, - Q)</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L18</span><br/>
 +
Jeżeli <math>d</math> jest nieparzystym dzielnikiem <math>Q</math>, to dla <math>n \geqslant 2</math> jest
  
 +
::<math>U_n \equiv P^{n - 1} \pmod{d}</math>
 +
 +
W szczególności, gdy liczba pierwsza nieparzysta <math>p</math> jest dzielnikiem <math>Q</math> i <math>p \nmid P</math>, to
 +
 +
::<math>U_p \equiv 1 \pmod{p}</math>
 +
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Oznaczmy <math>\delta = \sqrt{D}</math>, zatem <math>2 \alpha = P + \delta</math> i <math>2 \beta = P - \delta</math>. Ze wzoru dwumianowego, mamy
 +
 +
::<math>2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j</math>
  
::<math>U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k + 1} - \left( - \beta \sqrt{P} \right)^{2 k + 1}}{\sqrt{P}} = P^k (\alpha^{2 k + 1} + \beta^{2 k + 1}) = P^k V_{2 k + 1} (1, - Q)</math>
+
::<math>2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j</math>
  
  
::<math>V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \alpha \sqrt{P} \right)^{2 k} + \left( - \beta \sqrt{P} \right)^{2 k} = P^k (\alpha^{2 k} + \beta^{2 k}) = P^k V_{2 k} (1, - Q)</math>
+
Obliczając różnicę wyjściowych wzorów, mamy
  
 +
::<math>2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j) =</math>
  
::<math>V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \alpha \sqrt{P} \right)^{2 k + 1} + \left( - \beta \sqrt{P} \right)^{2 k + 1} = P^{k + 1} \cdot \frac{\alpha^{2 k + 1} - \beta^{2 k + 1}}{\sqrt{P}} = P^{k + 1} U_{2 k + 1} (1, - Q)</math>
+
:::::<math>\quad \: = \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot 2 \delta^j</math>
  
Co należało pokazać.<br/>
+
:::::<math>\quad \: = 2 \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot \delta \cdot D^{(j - 1) / 2}</math>
&#9633;
 
{{\Spoiler}}
 
  
 +
Rozpatrując powyższą równość modulo <math>Q</math> dostajemy (zobacz L43)
  
 +
::<math>2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\delta}} = 2^{n - 1} U_n \equiv \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot P^{j - 1}</math>
 +
 +
:::::::::<math>\;\:\: \equiv P^{n - 1} \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j}</math>
 +
 +
:::::::::<math>\;\:\: \equiv 2^{n - 1} P^{n - 1}</math>
 +
 +
Czyli
 +
 +
::<math>2^{n - 1} (U_n - P^{n - 1}) \equiv 0 \pmod{Q}</math>
 +
 +
Ponieważ <math>Q</math> dzieli <math>2^{n - 1} (U_n - P^{n - 1})</math>, to tym bardziej <math>d</math> dzieli <math>2^{n - 1} (U_n - P^{n - 1})</math>. Z założenia <math>\gcd (d, 2^{n - 1}) = 1</math>, zatem <math>d</math> dzieli <math>U_n - P^{n - 1}</math> (zobacz C70).
 +
 +
W przypadku szczególnym, gdy <math>d = p</math>, gdzie <math>p</math> jest nieparzystą liczbą pierwszą i <math>p \nmid P</math>, z&nbsp;twierdzenia Fermata otrzymujemy natychmiast
 +
 +
::<math>U_p \equiv P^{p - 1} \equiv 1 \pmod{p}</math>
 +
 +
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L28</span><br/>
 
Dla wyrazów ciągów Lucasa prawdziwe są wzory
 
  
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 
|-
 
| <math>1.</math> || <math>U_{m + n} = U_m U_{n + 1} - Q U_{m - 1} U_n</math> ||
 
|-
 
| <math>2.</math> || <math>V_{m + n} = V_m V_n - Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
| <math>3.</math> || <math>U_{m + n} = U_m V_n - Q^n U_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
| <math>4.</math> || <math>V_{m + n} = D U_m U_n + Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
| <math>5.</math> || <math>U_m V_n - V_m U_n = 2 Q^n U_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
| <math>6.</math> || <math>U^2_n = U_{n - 1} U_{n + 1} + Q^{n - 1}</math> ||
 
|-
 
| <math>7.</math> || <math>V^2_n = V_{n - 1} V_{n + 1} - D Q^{n - 1}</math> ||
 
|}
 
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 
|-
 
| <math>\;\; 8.</math> || <math>2 U_{m + n} = U_m V_n + V_m U_n</math> ||
 
|-
 
| <math>\;\; 9.</math> || <math>2 V_{m + n} = V_m V_n + D U_m U_n</math> ||
 
|-
 
| <math>10.</math> || <math>V_m V_n - D U_m U_n = 2 Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
| <math>11.</math> || <math>U_{2 n} = U_n V_n</math> ||
 
|-
 
| <math>12.</math> || <math>V_{2 n} = V^2_n - 2 Q^n</math> ||
 
|-
 
| <math>13.</math> || <math>V_{2 n} = D U^2_n + 2 Q^n</math> ||
 
|-
 
| <math>14.</math> || <math>V^2_n - D U^2_n = 4 Q^n</math> ||
 
|-
 
| <math>15.</math> || <math>D U_n = 2 V_{n + 1} - P V_n</math> ||
 
|-
 
| <math>16.</math> || <math>V_n = 2 U_{n + 1} - P U_n</math> ||
 
|-
 
| <math>17.</math> || <math>D U_n = V_{n + 1} - Q V_{n - 1}</math> || <math>n \geqslant 1</math>
 
|-
 
| <math>18.</math> || <math>V_n = U_{n + 1} - Q U_{n - 1}</math> || <math>n \geqslant 1</math>
 
|}
 
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 
|-
 
| <math>19.</math> || <math>U_{2 n} = 2 U_n U_{n + 1} - P U^2_n</math>
 
|-
 
| <math>20.</math> || <math>U_{2 n + 1} = U^2_{n + 1} - Q U^2_n</math>
 
|-
 
| <math>21.</math> || <math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
 
|}
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L19</span><br/>
'''Wzory 1. - 7. najłatwiej udowodnić korzystając z&nbsp;definicji L16.'''
+
Niech <math>D = P^2 - 4 Q</math>, a <math>(D \, | \, p)</math> oznacza symbol Legendre'a, gdzie <math>p</math> jest liczbą pierwszą nieparzystą i <math>p \nmid Q</math>. Mamy
  
Wzór 1.
+
::{| border="0"
 
+
|-style=height:2em
::<math>U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}}</math>
+
| &#9679;&nbsp;&nbsp;&nbsp; <math>U_p \equiv (D \, | \, p) \pmod{p}</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>(D \, | \, p) = - 1 , \;</math> to <math>\; p \, | \, U_{p + 1}</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>(D \, | \, p) = 1 , \;</math> to <math>\; p \, | \, U_{p - 1}</math>
 +
|}
  
:::<math>\quad \: = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} - \alpha \beta \cdot {\small\frac{\alpha^{m - 1} - \beta^{m - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}}</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
'''Punkt 1.'''
  
:::<math>\quad \: = U_m U_{n + 1} - Q U_{m - 1} U_n</math>
+
Zauważmy, że przypadek gdy <math>p \, | \, Q</math>, omówiliśmy w&nbsp;twierdzeniu poprzednim. Z&nbsp;założenia <math>p</math> jest liczbą pierwszą nieparzystą. Z&nbsp;twierdzenia L7, w&nbsp;przypadku nieparzystego <math>n = p</math>, otrzymujemy
  
 +
::<math>2^{p - 1} U_p = p P^{p - 1} + \binom{p}{3} P^{p - 3} D + \binom{p}{5} P^{p - 5} D^2 + \ldots + \binom{p}{p-2} P^2 D^{(p - 3) / 2} + D^{(p - 1) / 2}</math>
  
Wzór 2.
+
Ponieważ dla każdego <math>k \in [1, p - 1]</math> (zobacz L43)
  
::<math>V_{m + n} = \alpha^{m + n} + \beta^{m + n}</math>
+
::<math>\binom{p}{k} \equiv 0 \pmod{p}</math>
  
:::<math>\quad \;\! = (\alpha^m + \beta^m) (\alpha^n + \beta^n) - \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n})</math>
+
to modulo <math>p</math> dostajemy (zobacz J22)
  
:::<math>\quad \;\! = V_m V_n - Q^n V_{m - n}</math>
+
::<math>2^{p - 1} U_p \equiv U_p \equiv D^{(p - 1) / 2} \equiv (D \, | \, p) \pmod{p}</math>
  
 +
'''Punkt 2.'''
  
Wzór 3.
+
Zauważmy, że warunek <math>(D \, | \, p) = - 1</math> nie może być spełniony, gdy <math>p \, | \, Q</math>. Istotnie, gdy <math>p \, | \, Q</math>, to <math>D = P^2 - 4 Q \equiv P^2 \pmod{p}</math>, czyli
  
::<math>U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}}</math>
+
::<math>(D \, | \, p) = (P^2 \, | \, p) = (P \, | \, p)^2 = 0 , \;</math> gdy <math>p \, | \, P</math>
  
:::<math>\quad \: = {\small\frac{(\alpha^m - \beta^m) (\alpha^n + \beta^n)}{\alpha - \beta}} - {\small\frac{\alpha^n \beta^n \cdot (\alpha^{m - n} - \beta^{m - n})}{\alpha - \beta}}</math>
+
lub
  
:::<math>\quad \: = U_m V_n - Q^n U_{m - n}</math>
+
::<math>(D \, | \, p) = (P^2 \, | \, p) = (P \, | \, p)^2 = 1 , \;</math> gdy <math>p \nmid P</math>
  
 +
i nie może być <math>(D \, | \, p) = - 1</math>.
  
Wzór 4.
+
Dla parzystego <math>n = p + 1</math> otrzymujemy z&nbsp;twierdzenia L7
  
::<math>V_{m + n} = \alpha^{m + n} + \beta^{m + n}</math>
+
::<math>2^p U_{p + 1} = (p + 1) P^p + \binom{p + 1}{3} P^{p - 2} D + \binom{p + 1}{5} P^{p - 4} D^2 + \ldots + \binom{p + 1}{p - 2} P^3 D^{(p - 3) / 2} + (p + 1) P D^{(p - 1) / 2}</math>
  
:::<math>\quad \;\! = (\alpha - \beta)^2 \cdot {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} + \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n})</math>
+
Ponieważ dla <math>k \in [2, p - 1]</math> (zobacz L44)
  
:::<math>\quad \;\! = D U_m U_n + Q^n V_{m - n}</math>
+
::<math>\binom{p + 1}{k} \equiv 0 \pmod{p}</math>
  
 +
to modulo <math>p</math> dostajemy
  
Wzór 5.
+
::<math>2 U_{p + 1} \equiv P + P D^{(p - 1) / 2} \pmod{p}</math>
  
::<math>U_m V_n - V_m U_n = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot (\alpha^n + \beta^n) - (\alpha^m + \beta^m) \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}}</math>
 
  
::::::<math>\;\;\: = 2 \cdot \alpha^n \beta^n \cdot {\small\frac{\alpha^{m - n} - \beta^{m - n}}{\alpha - \beta}}</math>
+
Z założenia <math>D</math> jest liczbą niekwadratową modulo <math>p</math>, zatem <math>D^{(p - 1) / 2} \equiv - 1 \pmod{p}</math> (zobacz J19). Skąd wynika natychmiast, że
  
::::::<math>\;\;\: = 2 Q^n U_{m - n}</math>
+
::<math>2 U_{p + 1} \equiv 0 \pmod{p}</math>
  
 +
Czyli <math>p \, | \, U_{p + 1}</math>.
  
Wzór 6.
+
'''Punkt 3.'''
  
::<math>U^2_n = \left( {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \right)^2</math>
+
Dla parzystego <math>n = p - 1</math> otrzymujemy z&nbsp;twierdzenia L7
  
:::<math>\;\! = {\small\frac{\alpha^{n - 1} - \beta^{n - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} + \alpha^{n - 1} \beta^{n - 1}</math>
+
::<math>2^{p - 2} U_{p - 1} = (p - 1) P^{p - 2} + \binom{p - 1}{3} P^{p - 4} D + \binom{p - 1}{5} P^{p - 6} D^2 + \ldots + \binom{p - 1}{p - 4} P^3 D^{(p - 5) / 2} + (p - 1) P D^{(p - 3) / 2}</math>
  
:::<math>\;\! = U_{n - 1} U_{n + 1} + Q^{n - 1}</math>
+
Ponieważ dla <math>k \in [0, p - 1]</math> (zobacz L45)
  
 +
::<math>\binom{p - 1}{k} \equiv (- 1)^k \pmod{p}</math>
  
Wzór 7.
+
to modulo <math>p</math> mamy
  
::<math>V^2_n = (\alpha^n + \beta^n)^2</math>
+
::<math>2^{p - 2} U_{p - 1} \equiv - (P^{p - 2} + P^{p - 4} D + P^{p - 6} D^2 + \ldots + P D^{(p - 3) / 2}) \pmod{p}</math>
  
:::<math>\;\! = (\alpha^{n - 1} + \beta^{n - 1}) (\alpha^{n + 1} + \beta^{n + 1}) - (\alpha - \beta)^2 \cdot \alpha^{n - 1} \beta^{n - 1}</math>
+
::::<math>\quad \,\, \equiv - P (P^{p - 3} + P^{p - 5} D + P^{p - 7} D^2 + \ldots + D^{(p - 3) / 2}) \pmod{p}</math>
  
:::<math>\;\! = V_{n - 1} V_{n + 1} - D Q^{n - 1}</math>
 
  
 +
Z założenia <math>D</math> jest liczbą kwadratową modulo <math>p</math> (zobacz J17), zatem istnieje taka liczba <math>R</math>, że
  
'''Wzory 8. - 18. można łatwo udowodnić, korzystając ze wzorów 1. - 7.'''
+
::<math>D \equiv R^2 \pmod{p}</math>
  
Wzór 8. Policzyć sumę wzoru 3. pomnożonego przez <math>2</math> i&nbsp;wzoru 5.
+
Ponieważ
  
Wzór 9. Policzyć sumę wzorów 2. i 4.
+
:* <math>(D \, | \, p) = 1</math>, to <math>p \nmid D</math>, zatem <math>p \nmid R</math>
 +
:* z&nbsp;założenia <math>p \nmid Q</math>, to <math>P^2 - R^2 \equiv P^2 - D \equiv 4 Q \not\equiv 0 \pmod{p}</math>
  
Wzór 10. Połączyć wzory 2. i 4.
 
  
Wzór 11. We wzorze 3. położyć <math>m = n</math>.
+
Czyli
  
Wzór 12. We wzorze 2. położyć <math>m = n</math>.
+
::<math>2^{p - 2} U_{p - 1} \equiv - P (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p}</math>
  
Wzór 13. We wzorze 4. położyć <math>m = n</math>.
 
  
Wzór 14. We wzorze 10. położyć <math>m = n</math> lub połączyć wzory 12. i 13.
+
Uwzględniając, że <math>P^2 - R^2 \not\equiv 0 \pmod{p}</math>, możemy napisać
  
Wzór 15. We wzorze 9. położyć <math>m = 1</math>.
+
::<math>2^{p - 2} (P^2 - R^2) U_{p - 1} \equiv - P (P^2 - R^2) (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p}</math>
  
Wzór 16. We wzorze 8. położyć <math>m = 1</math>.
+
::::::::<math>\equiv - P (P^{p - 1} - R^{p - 1}) \pmod{p}</math>
  
Wzór 17. We wzorze 15. położyć <math>V_{n + 1} = P V_n - Q V_{n - 1}</math>.
+
::::::::<math>\equiv 0 \pmod{p}</math>
  
Wzór 18. We wzorze 16. położyć <math>U_{n + 1} = P U_n - Q U_{n - 1}</math>.
+
Zauważmy, że wynik nie zależy od tego, czy <math>p \, | \, P</math>, czy <math>p \nmid P</math>. Skąd wynika
  
 +
::<math>U_{p - 1} \equiv 0 \pmod{p}</math>
  
'''Wzory 19. - 21. to wzory, które wykorzystamy w&nbsp;przyszłości do szybkiego obliczania wartości wyrazów <math>U_n</math> i <math>V_n</math> modulo.'''
+
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
Wzór 19. Wystarczy połączyć wzory 11. oraz 16.
 
  
Wzór 20. Wystarczy we wzorze 1. położyć <math>m = n + 1</math>.
 
  
Wzór 21. Kładąc we wzorze 19. <math>n \rightarrow n + 1</math>, otrzymujemy
+
Aby zapisać punkty 2. i 3. twierdzenia L19 (i tylko te punkty) w&nbsp;zwartej formie, musimy założyć, że <math>\gcd (p, D) = 1</math>. Otrzymujemy<br/>
 +
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L20</span><br/>
 +
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą i <math>\gcd (p, Q D) = 1</math>, to
  
::<math>U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - P U^2_{n + 1} \qquad (*)</math>
+
::<math>U_{p - (D \, | \, p)} \equiv 0 \pmod{p}</math>
  
Kładąc we wzorze 1. <math>m = n + 2</math>, mamy
 
  
::<math>U_{2 n + 2} = U_{n + 2} U_{n + 1} - Q U_{n + 1} U_n</math>
 
  
Czyli
 
  
::<math>2 U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - 2 Q U_n U_{n + 1}</math>
 
  
Odejmując od powyższego wzoru wzór <math>(*)</math>, dostajemy wzór 21.
+
== Liczby pseudopierwsze Lucasa ==
  
::<math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L21</span><br/>
 +
Z twierdzenia L20 wiemy, że liczby pierwsze nieparzyste <math>p</math> takie, że <math>p \nmid Q D</math> są dzielnikami wyrazów ciągu Lucasa <math>U_{p - (D \, | \, p)}</math>, gdzie <math>(D \, | \, 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&nbsp;łatwo przekonamy się, że dla pewnych liczb złożonych <math>m</math> kongruencja
 +
 
 +
::<math>U_{m - (D \, | \, m)} \equiv 0 \pmod{m}</math>
 +
 
 +
również jest prawdziwa. Prowadzi to definicji liczb pseudopierwszych Lucasa.
  
Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
  
  
 +
<span style="font-size: 110%; font-weight: bold;">Definicja L22</span><br/>
 +
Powiemy, że liczba złożona nieparzysta <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P</math> i <math>Q</math> (symbolicznie: LPSP( <math>P, Q</math> )), jeżeli <math>\gcd (m, Q D) = 1</math> i
  
 +
::<math>U_{m - (D \, | \, m)} \equiv 0 \pmod{m}</math>
  
 +
gdzie <math>(D \, | \, m)</math> oznacza symbol Jacobiego.
  
== Obliczanie wyrazów ciągu Lucasa modulo <math>m</math> ==
 
  
<span style="font-size: 110%; font-weight: bold;">Przykład L29</span><br/>
 
Pokażemy, jak wykorzystać podane w&nbsp;twierdzeniu L28 wzory 19, 20, 21 i 16
 
  
::<math>U_{2 n} = 2 U_n U_{n + 1} - P U^2_n</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L23</span><br/>
 +
Jeżeli liczba złożona nieparzysta <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P = a + 1</math> i <math>Q = a</math>, gdzie <math>a \geqslant 2</math>, to jest liczbą pseudopierwszą Fermata przy podstawie <math>a</math>.
  
::<math>U_{2 n + 1} = U^2_{n + 1} - Q U^2_n</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Połóżmy we wzorze definiującym ciąg Lucasa
  
::<math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
+
::<math>U_m = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}}</math>
  
::<math>V_n = 2 U_{n + 1} - P U_n</math>
+
<math>\alpha = a</math> i <math>\beta = 1</math>. Odpowiada to parametrom <math>P = \alpha + \beta = a + 1</math>, <math>Q = \alpha \beta = a</math>, <math>D = (\alpha - \beta)^2 = (a - 1)^2</math>.
  
do szybkiego obliczania wyrazów ciągu Lucasa modulo <math>m</math>.
+
Ponieważ musi być <math>\gcd (m, Q D) = 1</math>, to mamy <math>\gcd (m, (a - 1) a) = 1</math> i&nbsp;wynika stąd, że <math>(D \, | \, m) = 1</math>. Z&nbsp;założenia <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P = a + 1</math> i <math>Q = a</math>, zatem
  
 +
::<math>U_{m - 1} (a + 1, a) \equiv 0 \pmod{m}</math>
  
Niech <math>P = 3</math>, <math>Q = 1</math>, <math>D = P^2 - 4 Q = 5</math>, <math>n = 22 = (10110)_2 = \sum_{j = 0}^{4} a_j \cdot 2^j</math>.
+
Czyli
  
W tabeli przedstawione są kolejne kroki, jakie musimy wykonać, aby policzyć <math>U_n = U_{22}</math> modulo <math>m = 23</math>.
+
::<math>{\small\frac{a^{m - 1} - 1}{a - 1}} \equiv 0 \pmod{m}</math>
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
+
Jeżeli <math>m \biggr\rvert {\small\frac{a^{m - 1} - 1}{a - 1}}</math>, to tym bardziej <math>m \big\rvert (a^{m - 1} - 1)</math> i&nbsp;możemy napisać
|-
 
! <math>\boldsymbol{j}</math> !! <math>\boldsymbol{a_j}</math> !! <math>\boldsymbol{k_j}</math> !! <math>\boldsymbol{U_{k_j}}</math> !! <math>\boldsymbol{U_{k_j + 1}}</math>
 
|-
 
| <math>4</math> || <math>1</math> || <math>(1)_2 = 1</math> || <math>U_1 = 1</math> || <math>U_2 = P = 3</math>
 
|-
 
| <math>3</math> || <math>0</math> || <math>(10)_2 = 2</math> || <math>U_2 = 2 U_1 U_2 - 3 U^2_1 = 6 - 3 = 3</math> || <math>U_3 = U^2_2 - 1 = 8</math>
 
|-
 
| <math>2</math> || <math>1</math> || <math>(101)_2 = 5</math> || <math>U_5 = U^2_3 - U^2_2 = 64 - 9 = 55 \equiv 9</math> || <math>U_6 = 3 U_3^2 - 2 U_2 U_3 = 192 - 48 = 144 \equiv 6</math>
 
|-
 
| <math>1</math> || <math>1</math> || <math>(1011)_2 = 11</math> || <math>U_{11} = U^2_6 - U^2_5 \equiv 36 - 81 \equiv - 45 \equiv 1</math> || <math>U_{12} = 3 U_6^2 - 2 U_5 U_6 \equiv 108 - 108 \equiv 0</math>
 
|-
 
| <math>0</math> || <math>0</math> || <math>(10110)_2 = 22</math> || <math>U_{22} = 2 U_{11} U_{12} - 3 U^2_{11} \equiv 0 - 3 \equiv 20</math> || <math>U_{23} = U^2_{12} - U^2_{11} \equiv 0 - 1 \equiv 22</math>
 
|}
 
  
W kolumnie <math>a_j</math> wypisujemy kolejne cyfry liczby <math>n = 22 = (10110)_2</math> zapisanej w&nbsp;układzie dwójkowym. Liczby w&nbsp;kolumnie <math>k_j</math> tworzymy, biorąc kolejne (od prawej do lewej) cyfry liczby <math>n</math> w&nbsp;zapisie dwójkowym. Postępując w&nbsp;ten sposób, w&nbsp;ostatnim wierszu mamy <math>k_j = n</math> i&nbsp;wyliczamy liczby <math>U_n</math> i <math>U_{n + 1}</math> modulo <math>m</math>.
+
::<math>a^{m - 1} - 1 \equiv 0 \pmod{m}</math>
  
Dla uproszczenia zapisu i&nbsp;ułatwienia zrozumienia liczbę <math>k_j</math> oznaczymy jako <math>r</math>, a <math>k_{j + 1}</math> jako <math>s</math>. Zauważmy, że
+
Zatem <math>m</math> jest liczbą pseudopierwszą Fermata przy podstawie <math>a</math>. Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
:* tabela jest zbudowana tak, że musimy znaleźć wyrazy ciągu Lucasa o&nbsp;indeksie <math>r = k_j</math> oraz o&nbsp;indeksie o&nbsp;jeden większym: <math>r + 1 = k_j + 1</math>
 
:* przejście do następnego wiersza (w dół) oznacza, że musimy znaleźć wyrazy o&nbsp;indeksie <math>s = k_{j + 1}</math> oraz o&nbsp;indeksie o&nbsp;jeden większym: <math>s + 1</math>
 
:* przechodząc do następnego wiersza, dotychczasowa liczba <math>r = k_j</math> powiększa się o&nbsp;kolejną cyfrę ( <math>0</math> lub <math>1</math> ), którą dopisujemy z&nbsp;prawej strony
 
:* dodanie na końcu liczby <math>r = k_j</math> zera podwaja liczbę <math>r</math>, czyli <math>s = k_{j + 1} = 2 r</math> oraz <math>s + 1 = 2 r + 1</math>
 
:* dodanie na końcu liczby <math>r = k_j</math> jedynki podwaja liczbę <math>r</math> i&nbsp;zwiększą ją o&nbsp;jeden, czyli <math>s = k_{j + 1} = 2 r + 1</math> oraz <math>s + 1 = 2 r + 2</math>
 
  
  
Dlatego, jeżeli kolejną dodaną cyfrą jest zero, to korzystamy ze wzorów
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L24</span><br/>
 +
Wykorzystując funkcje <code>jacobi(a, n)</code> i <code>modLucas(n, P, Q, m)</code> (zobacz J34, L15) możemy napisać prosty program, który sprawdza, czy dla liczby nieparzystej <math>m</math> prawdziwe jest twierdzenie L20.
  
::<math>U_s = U_{2 r} = 2 U_r U_{r + 1} - P U^2_r</math>
+
<span style="font-size: 90%; color:black;">isPrimeOr<span style="background-color: #fee481;">LPSP</span>(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) );
 +
}
  
::<math>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>U_s = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r</math>
+
<span style="font-size: 110%; font-weight: bold;">Przykład L25</span><br/>
 +
Poniższa tabela zawiera najmniejsze liczby pseudopierwsze Lucasa dla różnych parametrów <math>P</math> i <math>Q</math>
  
::<math>U_{s + 1} = U_{2 r + 2} = P U^2_{r + 1} - 2 Q U_r U_{r + 1}</math>
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
+
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
+
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
Korzystając ze wzoru <math>V_n = 2 U_{n + 1} - P U_n</math>, mamy
+
|-
 
+
! <math>\boldsymbol{- 5}</math>
::<math>V_{22} = 2 U_{23} - 3 U_{22} \equiv 44 - 60 \equiv - 16 \equiv 7 \pmod{23}</math>
+
| <math>253</math> || <math>121</math> || <math>57</math> || <math>217</math> || style="background-color: yellow" | <math>323</math> || <math>69</math> || <math>121</math> || <math>253</math> || <math>9</math> || style="background-color: yellow" | <math>143</math>
 
+
|-
Ostatecznie otrzymujemy
+
! <math>\boldsymbol{- 4}</math>
 
+
| <math>9</math> || style="background-color: yellow" | <math>323</math> || <math>91</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>15</math> || style="background-color: yellow" | <math>119</math> || <math>57</math> || <math>9</math> || <math>9</math> || <math>9</math>
::<math>U_{22} \equiv 20 \pmod{23} \quad</math> oraz <math>\quad V_{22} \equiv 7 \pmod{23}</math>
+
|-
 
+
! <math>\boldsymbol{- 3}</math>
 
+
| <math>217</math> || <math>91</math> || style="background-color: yellow" | <math>527</math> || <math>25</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>65</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math>
 
+
|-
<span style="font-size: 110%; font-weight: bold;">Uwaga L30</span><br/>
+
! <math>\boldsymbol{- 2}</math>
Uogólniając postępowanie przedstawione w&nbsp;przykładzie L29, możemy napisać program w&nbsp;PARI/GP do szybkiego obliczania wyrazów ciągu Lucasa <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math> modulo <math>m</math>.
+
| <math>341</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>39</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>15</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || <math>9</math> || <math>85</math>
 
+
|-
  <span style="font-size: 90%; color:black;">modLucas(n, P, Q, m) =
+
! <math>\boldsymbol{- 1}</math>
 +
| style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>119</math> || <math>9</math> || <math>9</math> || style="background-color: yellow" | <math>143</math> || <math>25</math> || <math>33</math> || <math>9</math> || style="background-color: yellow" | <math>15</math>
 +
|-
 +
! <math>\boldsymbol{1}</math>
 +
| <math>25</math> || style="background-color: red" | <math></math> || <math>21</math> || style="background-color: yellow" | <math>65</math> || style="background-color: yellow" | <math>115</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>209</math> || <math>9</math> || style="background-color: yellow" | <math>35</math>
 +
|-
 +
! <math>\boldsymbol{2}</math>
 +
| <math>1541</math> || <math>9</math> || <math>341</math> || style="background-color: yellow" | <math>35</math> || <math>21</math> || <math>85</math> || <math>9</math> || style="background-color: yellow" | <math>15</math> || <math>9</math> || style="background-color: yellow" | <math>35</math>
 +
|-
 +
! <math>\boldsymbol{3}</math>
 +
| style="background-color: yellow" | <math>629</math> || style="background-color: yellow" | <math>559</math> || <math>25</math> || <math>91</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>35</math> || <math>55</math> || <math>25</math> || style="background-color: yellow" | <math>35</math>
 +
|-
 +
! <math>\boldsymbol{4}</math>
 +
| style="background-color: yellow" | <math>119</math> || <math>25</math> || style="background-color: yellow" | <math>209</math> || style="background-color: red" | <math></math> || <math>85</math> || <math>21</math> || style="background-color: yellow" | <math>119</math> || style="background-color: yellow" | <math>65</math> || <math>9</math> || style="background-color: yellow" | <math>115</math>
 +
|-
 +
! <math>\boldsymbol{5}</math>
 +
| <math>9</math> || style="background-color: yellow" | <math>143</math> || <math>49</math> || style="background-color: yellow" | <math>143</math> || style="background-color: yellow" | <math>323</math> || <math>217</math> || style="background-color: yellow" | <math>39</math> || <math>9</math> || <math>9</math> || <math>9</math>  
 +
|}
 +
 
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 +
  <span style="font-size: 90%; color:black;">FirstLPSP(Stop) =
 +
\\ najmniejsze LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
  {
 
  {
  '''local'''(A, i, s, U, U2, V, W, W2);
+
  '''local'''(D, m, P, Q);
  '''if'''( m == 1, '''return'''([0, 0]) );
+
  Q = -6;
'''if'''( n == 0, '''return'''([0, 2 % m]) );
+
'''while'''( Q++ <= 5,
A = '''digits'''(n, 2); \\ otrzymujemy wektor cyfr liczby n w układzie dwójkowym
+
        '''if'''( Q == 0, '''next'''() );
s = '''length'''(A); \\ długość wektora A
+
        P = 0;
U = 1;
+
        '''while'''( P++ <= 10,
W = P;
+
              D = P^2 - 4*Q;
i = 1;
+
              '''if'''( D == 0,  
'''while'''( i++ <= s,
+
                  '''print'''("Q= ", Q, "  P= ", P, "  ------------------");
        '''if'''( A[i] == 0U2 = 2*U*W - P*U^2; W2 = W^2 - Q*U^2 );
+
                  '''next'''();
        '''if'''( A[i] == 1, U2 = W^2 - Q*U^2; W2 = P*W^2 - 2*Q*U*W );
+
                );
        U = U2 % m;
+
              m = 3;
        W = W2 % m;
+
              '''while'''( m < Stop,
 +
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q) && !'''isprime'''(m),
 +
                          '''print'''("Q= ", Q, "  P= ", P, "  m= ", m, "  (D|m)= ", jacobi(D, m));
 +
                          '''break'''();
 +
                        );
 +
                      m = m + 2;
 +
                    );
 +
            );
 
       );
 
       );
V = (2*W - P*U) % m;
 
'''return'''([U, V]);
 
 
  }</span>
 
  }</span>
 +
<br/>
 +
{{\Spoiler}}
  
 +
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których <math>(D \, | \, m) = - 1</math>.
  
  
  
 +
<span style="font-size: 110%; font-weight: bold;">Przykład L26</span><br/>
 +
Ilość liczb LPSP(<math>P, Q</math>) mniejszych od <math>10^9</math>
  
== Podzielność wyrazów <math>U_n (P, Q)</math> przez liczbę pierwszą nieparzystą ==
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
+
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="font-size: 110%; font-weight: bold;">Uwaga L31</span><br/>
+
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>  
Niech <math>p</math> będzie liczbą pierwszą nieparzystą. W&nbsp;przypadku, gdy <math>p \nmid P Q</math> nie możemy nic powiedzieć o&nbsp;podzielności wyrazów <math>U_n</math> przez <math>p</math>. Przykładowo, jeżeli <math>P \equiv 1 \pmod{p} \;</math> <math>\text{i} \;\; Q \equiv 1 \pmod{p}</math>, to modulo <math>p</math>, mamy
+
|-
 
+
! <math>\boldsymbol{- 5}</math>
::<math>(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>
+
| <math>4266</math> || <math>4935</math> || <math>4278</math> || <math>4981</math> || <math>6363</math> || <math>6028</math> || <math>5202</math> || <math>4426</math> || <math>5832</math> || <math>6027</math>  
 
+
|-
W przypadku, gdy <math>P \equiv 2 \pmod{p} \;</math> <math>\text{i} \;\; Q \equiv 1 \pmod{p}</math>, to modulo <math>p</math> mamy
+
! <math>\boldsymbol{- 4}</math>
 
+
| <math>4599</math> || <math>4152</math> || <math>9272</math> || <math>5886</math> || <math>6958</math> || <math>4563</math> || <math>5600</math> || <math>9509</math> || <math>7007</math> || <math>4142</math>
::<math>(U_n) \equiv (0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, \ldots)</math>
+
|-
 
+
! <math>\boldsymbol{- 3}</math>
Sytuacja wygląda inaczej, gdy <math>p \, | \, P Q</math>.
+
| <math>4265</math> || <math>5767</math> || <math>4241</math> || <math>5114</math> || <math>5859</math> || <math>7669</math> || <math>6083</math> || <math>6120</math> || <math>4420</math> || <math>5096</math>  
 
+
|-
 
+
! <math>\boldsymbol{- 2}</math>
 
+
| <math>5361</math> || <math>4389</math> || <math>5063</math> || <math>5632</math> || <math>5364</math> || <math>5228</math> || <math>5859</math> || <math>10487</math> || <math>5370</math> || <math>9798</math>
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L32</span><br/>
+
|-
Niech <math>p</math> będzie liczbą pierwszą nieparzystą.
+
! <math>\boldsymbol{- 1}</math>
 
+
| <math>4152</math> || <math>5886</math> || <math>4563</math> || <math>9509</math> || <math>4142</math> || <math>6273</math> || <math>5773</math> || <math>4497</math> || <math>5166</math> || <math>5305</math>  
::{| border="0"
+
|-
|-style=height:1.9em
+
! <math>\boldsymbol{1}</math>
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, P \;</math> <math>\text{i} \;\; p \, | \, Q , \;</math> to <math>\; p \, | \, U_n \;</math> dla <math>n \geqslant 2</math>
+
| <math>282485800</math> || style="background-color: red" | <math></math> || <math>6567</math> || <math>7669</math> || <math>7131</math> || <math>10882</math> || <math>8626</math> || <math>8974</math> || <math>8509</math> || <math>8752</math>  
|-style=height:1.9em
+
|-
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, P \;</math> <math>\text{i} \;\; p \nmid Q , \;</math> to <math>\; p \, | \, U_{2 n} \;</math> i <math>\; p \nmid U_{2 n + 1}</math>
+
! <math>\boldsymbol{2}</math>
|-style=height:1.9em
+
| <math>7803</math> || <math>449152466</math> || <math>5597</math> || <math>5886</math> || <math>6509</math> || <math>5761</math> || <math>8115</math> || <math>6945</math> || <math>8380</math> || <math>7095</math>  
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \nmid P \;</math> <math>\text{i} \;\; p \, | \, Q , \;</math> to <math>\; p \nmid U_n \;</math> dla <math>n \geqslant 1</math>
+
|-
|-style=height:1.9em
+
! <math>\boldsymbol{3}</math>
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, Q , \;</math> to <math>\; p \, | \, U_n</math>, gdzie <math>n \geqslant 2</math>, wtedy i&nbsp;tylko wtedy, gdy <math>\; p \, | \, P</math>
+
| <math>5974</math> || <math>8768</math> || <math>282485800</math> || <math>5767</math> || <math>5651</math> || <math>5632</math> || <math>6640</math> || <math>5725</math> || <math>6058</math> || <math>7050</math>  
|-style=height:1.9em
+
|-
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \nmid P \;</math> <math>\text{i} \;\; p \, | \, D , \;</math> to <math>\; p \, | \, U_n \;</math> wtedy i&nbsp;tylko wtedy, gdy <math>p \, | \, n</math>
+
! <math>\boldsymbol{4}</math>
 +
| <math>10749</math> || <math>282485800</math> || <math>14425</math> || style="background-color: red" | <math></math> || <math>9735</math> || <math>6567</math> || <math>8164</math> || <math>7669</math> || <math>7608</math> || <math>7131</math>  
 +
|-
 +
! <math>\boldsymbol{5}</math>
 +
| <math>5047</math> || <math>15127</math> || <math>6155</math> || <math>15127</math> || <math>4152</math> || <math>5146</math> || <math>4423</math> || <math>5526</math> || <math>6289</math> || <math>9509</math>  
 
|}
 
|}
  
Założenie, że <math>p \nmid P</math> w&nbsp;ostatnim punkcie jest istotne. Gdy <math>\; p \, | \, P \;</math> i <math>\; p \, | \, D , \;</math> to <math>\; p \, | \, Q \;</math> i&nbsp;otrzymujemy punkt pierwszy.
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
+
<span style="font-size: 90%; color:black;">NumOfLPSP(Stop) =
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
\\ ilość liczb pseudopierwszych Lucasa LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
'''Punkt 1.'''
+
{
 +
'''local'''(D, m, P, Q);
 +
Q = -6;
 +
'''while'''( Q++ <= 5,
 +
        '''if'''( Q == 0, '''next'''() );
 +
        P = 0;
 +
        '''while'''( P++ <= 10,
 +
              D = P^2 - 4*Q;
 +
              '''if'''( D == 0, '''print'''("Q= ", Q, "  P= ", P, "  ------------------"); '''next'''() );
 +
              s = 0;
 +
              m = 3;
 +
              '''while'''( m < Stop,
 +
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q)  &&  !'''isprime'''(m), s++ );
 +
                      m = m + 2;
 +
                    );
 +
              '''print'''("Q= ", Q, "  P= ", P, "  s= ", s);
 +
            );
 +
      );
 +
}</span>
 +
<br/>
 +
{{\Spoiler}}
  
Ponieważ <math>U_2 = P</math>, zatem <math>p \, | \, U_2</math>. Dla <math>n \geqslant 3</math> wyrażenie <math>U_n = P U_{n - 1} - Q U_{n - 2}</math> jest podzielne przez <math>p</math>.
 
  
'''Punkt 2.'''
 
  
Indeksy parzyste. Indukcja matematyczna. Mamy <math>U_0 = 0</math> i <math>U_2 = P</math>, zatem <math>p \, | \, U_0</math> i <math>p \, | \, U_2</math>. Zakładając, że <math>p \, | \, U_{2 n}</math>, z definicji ciągu <math>(U_k)</math>, otrzymujemy dla <math>U_{2 n + 2}</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L27</span><br/>
 +
Dla <math>(P, Q) = (1, 1)</math> ciąg Lucasa <math>(U_n)</math> ma postać
  
::<math>U_{2 n + 2} = P U_{2 n - 1} - Q U_{2 n}</math>
+
::<math>(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>
  
Z założenia indukcyjnego wynika, że <math>p \, | \, U_{2 n + 2}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich <math>n \geqslant 0</math>.
+
Stosując indukcję matematyczną, udowodnimy, że <math>U_{3 k} = 0</math>. Łatwo sprawdzamy, że dla <math>k = 0</math> i <math>k = 1</math> wzór jest prawdziwy. Zakładając prawdziwość wzoru dla wszystkich liczb naturalnych nie większych od <math>k</math>, otrzymujemy dla <math>k + 1</math> (zobacz L13 p.3)
  
Indeksy nieparzyste. Indukcja matematyczna. Mamy <math>U_1 = 1</math> i <math>U_3 = P^2 - Q</math>, zatem <math>p \nmid U_1</math> i <math>p \nmid U_3</math>. Zakładając, że <math>p \nmid U_{2 n - 1}</math>, z definicji ciągu <math>(U_k)</math>, otrzymujemy dla <math>U_{2 n + 1}</math>
+
::<math>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>(P, Q) = (1, 1)</math>.
 +
 
 +
Mamy <math>D = P^2 - 4 Q = - 3</math>. Wynika stąd, że nie może być <math>3 \, | \, m</math>, bo mielibyśmy <math>\gcd (m, Q D) = 3 > 1</math>.
  
::<math>U_{2 n + 1} = P U_{2 n} - Q U_{2 n - 1}</math>
+
Z zadania J32 wiemy, że
  
Z założenia indukcyjnego wynika, że <math>p \nmid U_{2 n + 1}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich <math>n \geqslant 1</math>.
+
::<math>(- 3 \, | \, 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>
  
'''Punkt 3.'''
+
Ponieważ <math>3 \nmid m</math>, to wystarczy zbadać przypadki <math>m = 6 k + 1</math> i <math>m = 6 k + 5</math>. W&nbsp;pierwszym przypadku jest
  
Indukcja matematyczna. Mamy <math>U_1 = 1</math> i <math>U_2 = P</math>, zatem <math>p \nmid U_1</math> i <math>p \nmid U_2</math>. Zakładając, że <math>p \nmid U_n</math> zachodzi dla wszystkich liczb całkowitych dodatnich nie większych od <math>n</math>, z&nbsp;definicji ciągu <math>(U_n)</math>
+
::<math>U_{m - (- 3 \, | \, m)} = U_{6 k + 1 - 1} = U_{6 k} = 0</math>
otrzymujemy dla <math>n + 1</math>
 
  
::<math>U_{n + 1} = P U_n - Q U_{n - 1}</math>
+
W drugim przypadku, gdy <math>m = 6 k + 5</math>, dostajemy
  
Z założenia indukcyjnego wynika, że <math>p \nmid U_{n + 1}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich liczb <math>n \geqslant 1</math>.
+
::<math>U_{m - (- 3 \, | \, m)} = U_{6 k + 5 + 1} = U_{6 (k + 1)} = 0</math>
  
'''Punkt 4.'''
+
Zatem dla dowolnej liczby nieparzystej <math>m</math> niepodzielnej przez <math>3</math> jest
  
Wynika z&nbsp;punktów pierwszego i&nbsp;trzeciego.
+
::<math>U_{m - (- 3 \, | \, m)} \equiv 0 \pmod{m}</math>
  
'''Punkt 5.'''
+
Czyli liczbami pseudopierwszymi Lucasa dla parametrów <math>(P, Q) = (1, 1)</math> będą liczby nieparzyste <math>m</math>, które nie są podzielne przez <math>3</math> i&nbsp;nie są liczbami pierwszymi. Ilość takich liczb nie większych od <math>10^k</math> możemy łatwo znaleźć poleceniem
  
Z twierdzenia L22 wiemy, że
+
'''for'''(k = 1, 9, s = 0; '''forstep'''(m = 3, 10^k, 2, '''if'''( m%6 <> 3, s = s + !'''isprime'''(m) )); '''print'''(s))
  
::<math>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>\;\; = n P^{n - 1} + \binom{n}{3} P^{n - 3} D + \binom{n}{5} P^{n - 5} D^2 + \ldots +
 
\begin{cases}
 
n P D^{(n - 2) / 2} & \text{gdy }n\text{ jest parzyste} \\
 
D^{(n - 1) / 2} & \text{gdy }n\text{ jest nieparzyste}
 
\end{cases}</math>
 
  
Z założenia <math>p \, | \, D</math>, zatem modulo <math>p</math> dostajemy
+
<span style="font-size: 110%; font-weight: bold;">Zadanie L28</span><br/>
 +
Pokazać, że ilość liczb pseudopierwszych Lucasa dla parametrów <math>(P, Q) = (2, 2)</math> nie większych od <math>10^k</math> możemy znaleźć poleceniem
  
::<math>2^{n - 1} U_n \equiv n P^{n - 1} \pmod{p}</math>
+
'''for'''(k = 1, 9, s = 0; '''forstep'''(m = 3, 10^k, 2, s = s + !'''isprime'''(m)); '''print'''(s))
  
Ponieważ <math>p \nmid P</math>, zatem <math>p \, | \, U_n</math> wtedy i&nbsp;tylko wtedy, gdy <math>p \, | \, n</math>.
 
Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
  
  
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L33</span><br/>
 
Jeżeli <math>d</math> jest nieparzystym dzielnikiem <math>Q</math>, to dla <math>n \geqslant 2</math> jest
 
  
::<math>U_n \equiv P^{n - 1} \pmod{d}</math>
+
== Metoda Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math> ==
  
W szczególności, gdy liczba pierwsza nieparzysta <math>p</math> jest dzielnikiem <math>Q</math> i <math>p \nmid P</math>, to
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L29</span><br/>
 +
Twierdzenie L20 możemy wykorzystać do testowania pierwszości liczb. Ponieważ musi być spełniony warunek <math>\gcd (m, Q D) = 1</math>, to nie każda para liczb <math>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>P, Q</math>.
  
::<math>U_p \equiv 1 \pmod{p}</math>
+
Robert Baillie i&nbsp;Samuel Wagstaff przedstawili<ref name="BaillieWagstaff1"/> dwie metody wyboru parametrów dla testu Lucasa. Ograniczymy się do omówienia tylko pierwszej z&nbsp;nich (metodę zaproponował John Selfridge).
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
Rozważmy ciąg <math>a_k = (- 1)^k (2 k + 1)</math>, gdzie <math>k \geqslant 2</math>, czyli <math>a_k = (5, - 7, 9, - 11, 13, - 15, \ldots)</math>. Niech <math>D</math> będzie pierwszym wyrazem ciągu <math>(a_k)</math>, dla którego jest <math>(a_k \, | \, m) = - 1</math>. Dla tak ustalonego <math>D</math> przyjmujemy <math>P = 1</math> i <math>Q = (1 - D) / 4</math>.
Oznaczmy <math>\delta = \sqrt{D}</math>, zatem <math>2 \alpha = P + \delta</math> i <math>2 \beta = P - \delta</math>. Ze wzoru dwumianowego, mamy
 
  
::<math>2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j</math>
+
Tabela przedstawia początkowe wartości <math>Q</math>, jakie otrzymamy, stosując tę metodę.
  
::<math>2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j</math>
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
+
! <math>\boldsymbol{k}</math>
 
+
| <math>2</math> || <math>3</math> || <math>4</math> || <math>5</math> || <math>6</math> || <math>7</math> || <math>8</math> || <math>9</math> || <math>10</math> || <math>11</math> || <math>12</math> || <math>13</math> || <math>14</math> || <math>15</math> || <math>16</math> || <math>17</math> || <math>18</math> || <math>19</math> || <math>20</math>
Obliczając różnicę wyjściowych wzorów, mamy
+
|-
 
+
!  <math>\boldsymbol{a_k}</math>
::<math>2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j) =</math>
+
| <math>5</math> || <math>-7</math> || <math>9</math> || <math>-11</math> || <math>13</math> || <math>-15</math> || <math>17</math> || <math>-19</math> || <math>21</math> || <math>-23</math> || <math>25</math> || <math>-27</math> || <math>29</math> || <math>-31</math> || <math>33</math> || <math>-35</math> || <math>37</math> || <math>-39</math> || <math>41</math>
 +
|-
 +
!  <math>\boldsymbol{Q}</math>
 +
| <math>-1</math> || <math>2</math> || style="background-color: red" | <math>-2</math> || <math>3</math> || <math>-3</math> || <math>4</math> || <math>-4</math> || <math>5</math> || <math>-5</math> || <math>6</math> || style="background-color: red" | <math>-6</math> || <math>7</math> || <math>-7</math> || <math>8</math> || <math>-8</math> || <math>9</math> || <math>-9</math> || <math>10</math> || <math>-10</math>
 +
|}
  
:::::<math>\quad \: = \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot 2 \delta^j</math>
 
  
:::::<math>\quad \: = 2 \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot \delta \cdot D^{(j - 1) / 2}</math>
+
Zauważmy, że
 +
:* jeżeli liczba nieparzysta <math>m</math> jest liczbą kwadratową, to wybór <math>D</math> nie będzie możliwy
 +
:* w&nbsp;przypadku zastosowania tej metody znajdziemy tylko liczby pierwsze lub pseudopierwsze Lucasa, które spełniają kongruencję <math>U_{m + 1} \equiv 0 \pmod{m}</math>, czyli tylko część liczb pseudopierwszych Lucasa określonych w&nbsp;definicji L22
  
Rozpatrując powyższą równość modulo <math>Q</math> dostajemy (zobacz L74)
 
  
::<math>2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\delta}} = 2^{n - 1} U_n \equiv \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot P^{j - 1}</math>
+
Ponieważ Baillie i&nbsp;Wagstaff określili metodę zaproponowaną przez Selfridge'a jako metodę A, to pozostaniemy przy tej nazwie. Korzystając ze wzoru rekurencyjnego
  
:::::::::<math>\;\:\: \equiv P^{n - 1} \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j}</math>
+
::<math> 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>
  
:::::::::<math>\;\:\: \equiv 2^{n - 1} P^{n - 1}</math>
+
możemy łatwo napisać odpowiednią funkcję znajdującą liczby <math>P, Q</math> według tej metody.
  
Czyli
+
<span style="font-size: 90%; color:black;">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);
 +
      );
 +
}</span>
  
::<math>2^{n - 1} (U_n - P^{n - 1}) \equiv 0 \pmod{Q}</math>
+
Wyjaśnienia wymaga druga linia kodu w&nbsp;pętli <code>while</code>. Wiemy, że (zobacz J28)
  
Ponieważ <math>Q</math> dzieli <math>2^{n - 1} (U_n - P^{n - 1})</math>, to tym bardziej <math>d</math> dzieli <math>2^{n - 1} (U_n - P^{n - 1})</math>. Z założenia <math>\gcd (d, 2^{n - 1}) = 1</math>, zatem <math>d</math> dzieli <math>U_n - P^{n - 1}</math> (zobacz C70).
+
::<math>(a \, | \, m) = 0 \quad \qquad \Longleftrightarrow \quad \qquad \gcd (a, m) > 1</math>
  
W przypadku szczególnym, gdy <math>d = p</math>, gdzie <math>p</math> jest nieparzystą liczbą pierwszą i <math>p \nmid P</math>, z&nbsp;twierdzenia Fermata otrzymujemy natychmiast
+
Jednak z&nbsp;faktu, że <math>\gcd (a, m) > 1</math> nie wynika natychmiast, że liczba <math>m</math> jest liczbą złożoną. Rozważmy dwa przypadki: gdy <math>m \, | \, a</math> i <math>m \nmid a</math>.
  
::<math>U_p \equiv P^{p - 1} \equiv 1 \pmod{p}</math>
+
Gdy <math>\gcd (a, m) > 1</math> i <math>m \, | \, a</math>, to <math>\gcd (a, m) = \gcd (k \cdot m, m) = m > 1</math> i&nbsp;nie jesteśmy w&nbsp;stanie rozstrzygnąć, czy liczba <math>m</math> jest liczbą pierwszą, czy złożoną. Widać to dobrze na prostych przykładach
  
Co należało pokazać.<br/>
+
::<math>\gcd (7, 7) = \gcd (14, 7) = 7 > 1</math>
&#9633;
 
{{\Spoiler}}
 
  
 +
::<math>\gcd (15, 15) = \gcd (30, 15) = 15 > 1</math>
  
 +
Gdy <math>\gcd (a, m) > 1</math> i <math>m \nmid a</math>, to <math>m</math> jest liczbą złożoną. Ponieważ <math>m \nmid a</math>, to <math>a = k \cdot m + r</math>, gdzie <math>r \in [1, m - 1]</math>. Mamy
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L34</span><br/>
+
::<math>\gcd (a, m) = \gcd (k \cdot m + r, m) = \gcd (r, m) = d</math>
Niech <math>D = P^2 - 4 Q</math>, a <math>(D \, | \, p)</math> oznacza symbol Legendre'a, gdzie <math>p</math> jest liczbą pierwszą nieparzystą i <math>p \nmid Q</math>. Mamy
 
  
::{| border="0"
+
Musi być <math>d > 1</math>, bo założyliśmy, że <math>\gcd (a, m) > 1</math> i&nbsp;musi być <math>d < m</math>, bo <math>d \leqslant r \leqslant m - 1</math>. Zatem <math>d</math> jest dzielnikiem nietrywialnym liczby <math>m</math> i <math>m</math> jest liczbą złożoną.
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; <math>U_p \equiv (D \, | \, p) \pmod{p}</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>(D \, | \, p) = - 1 , \;</math> to <math>\; p \, | \, U_{p + 1}</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>(D \, | \, p) = 1 , \;</math> to <math>\; p \, | \, U_{p - 1}</math>
 
|}
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
Omawiana linia kodu zapewnia wysłanie informacji o&nbsp;tym, że liczba <math>m</math> jest liczbą złożoną (zwrot wektora [0, 0]). W&nbsp;przypadku, gdy nie mamy takiej pewności, kontynuujemy szukanie liczby <math>a</math>, takiej że <math>(a \, | \, m) = - 1</math>, pozostawiając zbadanie pierwszości liczby <math>m</math> na kolejnym etapie testowania.
'''Punkt 1.'''
 
  
Zauważmy, że przypadek gdy <math>p \, | \, Q</math>, omówiliśmy w&nbsp;twierdzeniu poprzednim. Z&nbsp;założenia <math>p</math> jest liczbą pierwszą nieparzystą. Z&nbsp;twierdzenia L22, w&nbsp;przypadku nieparzystego <math>n = p</math>, otrzymujemy
 
  
::<math>2^{p - 1} U_p = p P^{p - 1} + \binom{p}{3} P^{p - 3} D + \binom{p}{5} P^{p - 5} D^2 + \ldots + \binom{p}{p-2} P^2 D^{(p - 3) / 2} + D^{(p - 1) / 2}</math>
+
Uważny Czytelnik dostrzeże, że nie zbadaliśmy, czy spełniony jest warunek <math>\gcd (m, Q) = 1</math>. Nie musimy tego robić, bo zwracana przez funkcję <code>MethodA()</code> liczba <math>Q</math> jest względnie pierwsza z <math>m</math>. Omówimy ten problem dokładnie w&nbsp;zadaniu L30. Poniżej pokażemy, że nawet gdyby było <math>\gcd (m, Q) > 1</math>, to złożona liczba <math>m</math> nie zostanie uznana za liczbę pseudopierwszą Lucasa.
  
Ponieważ dla każdego <math>k \in [1, p - 1]</math> (zobacz L74)
+
Zauważmy, że jeżeli <math>m</math> jest liczbą złożoną i&nbsp;ma dzielnik pierwszy <math>p < m</math>, który dzieli <math>Q</math>, to <math>p \, | \, Q</math> i <math>p \nmid P</math> (bo <math>P = 1</math>), zatem <math>p \nmid U_k</math> dla <math>k \geqslant 1</math> (zobacz L17), czyli nie może być
  
::<math>\binom{p}{k} \equiv 0 \pmod{p}</math>
+
::<math>U_{m + 1} (1, Q) \equiv 0 \pmod{m}</math>
  
to modulo <math>p</math> dostajemy (zobacz L72)
+
bo mielibyśmy
  
::<math>2^{p - 1} U_p \equiv U_p \equiv D^{(p - 1) / 2} \equiv (D \, | \, p) \pmod{p}</math>
+
::<math>U_{m + 1} (1, Q) \equiv 0 \pmod{p}</math>
  
'''Punkt 2.'''
+
a to jest niemożliwe. Zatem program wykorzystujący twierdzenie L20 wykryje złożoność liczby <math>m</math>.
  
Zauważmy, że warunek <math>(D \, | \, p) = - 1</math> nie może być spełniony, gdy <math>p \, | \, Q</math>. Istotnie, gdy <math>p \, | \, Q</math>, to <math>D = P^2 - 4 Q \equiv P^2 \pmod{p}</math>, czyli
+
Łatwo pokażemy, że nie jest możliwe, aby liczba <math>m</math> była liczbą pierwszą i&nbsp;była dzielnikiem <math>Q</math>. Jeżeli <math>m</math> jest liczbą pierwszą, to istnieje dokładnie <math>\tfrac{m - 1}{2}</math> liczb kwadratowych modulo <math>p</math> i <math>\tfrac{m - 1}{2}</math> liczb niekwadratowych modulo <math>p</math>, zatem rozpoczynając od wyrazu <math>a_2</math> możemy dojść co najwyżej do wyrazu o&nbsp;indeksie <math>k = \tfrac{m - 1}{2} + 2</math>, czyli
  
::<math>(D \, | \, p) = (P^2 \, | \, p) = (P \, | \, p)^2 = 0 , \;</math> gdy <math>p \, | \, P</math>
+
::<math>| a_k | \leqslant m + 4</math>
  
lub
+
Skąd wynika, że
  
::<math>(D \, | \, p) = (P^2 \, | \, p) = (P \, | \, p)^2 = 1 , \;</math> gdy <math>p \nmid P</math>
+
::<math>| Q | = \left| {\small\frac{1 - a_k}{4}} \right| \leqslant {\small\frac{m + 5}{4}} < m</math>
  
i nie może być <math>(D \, | \, p) = - 1</math>.
+
Ostatnia nierówność jest prawdziwa dla <math>m > {\small\frac{5}{3}}</math>, czyli dla wszystkich liczb pierwszych. Ponieważ <math>| Q | < m</math>, w&nbsp;przypadku gdy <math>m</math> jest liczbą pierwszą, to <math>m</math> nie może być dzielnikiem liczby <math>Q</math>.
  
Dla parzystego <math>n = p + 1</math> otrzymujemy z&nbsp;twierdzenia L22
 
  
::<math>2^p U_{p + 1} = (p + 1) P^p + \binom{p + 1}{3} P^{p - 2} D + \binom{p + 1}{5} P^{p - 4} D^2 + \ldots + \binom{p + 1}{p - 2} P^3 D^{(p - 3) / 2} + (p + 1) P D^{(p - 1) / 2}</math>
 
  
Ponieważ dla <math>k \in [2, p - 1]</math> (zobacz L75)
+
<span style="font-size: 110%; font-weight: bold;">Zadanie L30</span><br/>
 +
Pokazać, że w&nbsp;przypadku, gdy dla kolejnych liczb <math>a_k = (- 1)^k (2 k + 1)</math> sprawdzamy, czy konsekwencją <math>(a_k \, | \, m) = 0</math> jest złożoność liczby <math>m</math>, to dla każdej liczby <math>Q</math> wyznaczonej metodą Selfridge'a jest <math>\gcd (Q, m) = 1</math>.
  
::<math>\binom{p + 1}{k} \equiv 0 \pmod{p}</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Niech <math>m = 21</math>. Rozpoczniemy od przykładu liczb <math>a_k = (- 1)^k (2 k + 1)</math> dla <math>k = 0, 1, \ldots, m - 1</math>.
  
to modulo <math>p</math> dostajemy
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
 +
! <math>\boldsymbol{k}</math> !! <math>\boldsymbol{0}</math> !!  !!  !!  !!  !!  !!  !!  !!  !!  !! <math>\boldsymbol{(m-1)/2}</math> !!  !!  !!  !!  !!  !!  !!  !!  !!  !! <math>\boldsymbol{m-1}</math>
 +
|-
 +
! <math>\boldsymbol{k}</math>
 +
| <math>0</math> || <math>1</math> || <math>2</math> || <math>3</math> || <math>4</math> || <math>5</math> || <math>6</math> || <math>7</math> || <math>8</math> || <math>9</math> || <math>10</math> || <math>11</math> || <math>12</math> || <math>13</math> || <math>14</math> || <math>15</math> || <math>16</math> || <math>17</math> || <math>18</math> || <math>19</math> || <math>20</math>
 +
|-
 +
! <math>\boldsymbol{a_k}</math>
 +
| <math>1</math> || <math>-3</math> || <math>5</math> || <math>-7</math> || <math>9</math> || <math>-11</math> || <math>13</math> || <math>-15</math> || <math>17</math> || <math>-19</math> || <math>21</math> || <math>-23</math> || <math>25</math> || <math>-27</math> || <math>29</math> || <math>-31</math> || <math>33</math> || <math>-35</math> || <math>37</math> || <math>-39</math> || <math>41</math>
 +
|-
 +
! <math>\boldsymbol{R_m(a_k)}</math>
 +
| <math>1</math> || <math>18</math> || <math>5</math> || <math>14</math> || <math>9</math> || <math>10</math> || <math>13</math> || <math>6</math> || <math>17</math> || <math>2</math> || <math>0</math> || <math>19</math> || <math>4</math> || <math>15</math> || <math>8</math> || <math>11</math> || <math>12</math> || <math>7</math> || <math>16</math> || <math>3</math> || <math>20</math>
 +
|}
  
::<math>2 U_{p + 1} \equiv P + P D^{(p - 1) / 2} \pmod{p}</math>
+
Zauważmy, że modulo <math>21</math> ciąg <math>(a_k) = (1, - 3, 5, - 7, \ldots, 37, - 39, 41)</math> jest identyczny z&nbsp;ciągiem <math>(0, 1, 2, \ldots, 19, 20)</math>, a&nbsp;ciąg <math>(| a_k |)</math> to kolejne liczby nieparzyste od <math>1</math> do <math>2 m - 1</math>.
  
  
Z założenia <math>D</math> jest liczbą niekwadratową modulo <math>p</math>, zatem <math>D^{(p - 1) / 2} \equiv - 1 \pmod{p}</math> (zobacz L69). Skąd wynika natychmiast, że
+
Poniżej pokażemy, dlaczego musi być <math>\gcd (Q, m) = 1</math>, gdzie <math>Q</math> jest liczbą wyznaczoną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby <math>m</math> przy testowaniu kolejnych liczb <math>a_k</math>). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby <math>m</math>. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość <math>Q</math> na podstawie innego wyrazu ciągu <math>a_k</math> (ten symbol Jacobiego został zapisany zwykłą czcionką).
  
::<math>2 U_{p + 1} \equiv 0 \pmod{p}</math>
+
::<math>m = 3 , \;\; (5 \, | \, 3) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
  
Czyli <math>p \, | \, U_{p + 1}</math>.
+
::<math>m = 5 , \;\; (5 \, | \, 5) = 0 , \;\; (- 7 \, | \, 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(5 \, | \, 5) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
  
'''Punkt 3.'''
+
::<math>m = 7 , \;\; (5 \, | \, 7) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
  
Dla parzystego <math>n = p - 1</math> otrzymujemy z&nbsp;twierdzenia L22
+
::<math>m = 9 , \;\; </math> (liczba kwadratowa)
  
::<math>2^{p - 2} U_{p - 1} = (p - 1) P^{p - 2} + \binom{p - 1}{3} P^{p - 4} D + \binom{p - 1}{5} P^{p - 6} D^2 + \ldots + \binom{p - 1}{p - 4} P^3 D^{(p - 5) / 2} + (p - 1) P D^{(p - 3) / 2}</math>
+
::<math>m = 11 , \;\; (- 11 \, | \, 11) = 0 , \;\; (13 \, | \, 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(- 11 \, | \, 11) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
  
Ponieważ dla <math>k \in [0, p - 1]</math> (zobacz L76)
+
::<math>m = 13 , \;\; (5 \, | \, 13) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
  
::<math>\binom{p - 1}{k} \equiv (- 1)^k \pmod{p}</math>
+
::<math>m = 15 , \;\; \boldsymbol{(5 \, | \, 15) = 0} , \;\; (13 \, | \, 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
  
to modulo <math>p</math> mamy
+
::<math>m = 17 , \;\; (5 \, | \, 17) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
  
::<math>2^{p - 2} U_{p - 1} \equiv - (P^{p - 2} + P^{p - 4} D + P^{p - 6} D^2 + \ldots + P D^{(p - 3) / 2}) \pmod{p}</math>
+
::<math>m = 19 , \;\; (- 7 \, | \, 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
::::<math>\quad \,\, \equiv - P (P^{p - 3} + P^{p - 5} D + P^{p - 7} D^2 + \ldots + D^{(p - 3) / 2}) \pmod{p}</math>
+
::<math>m = 21 , \;\; \boldsymbol{(- 7 \, | \, 21) = 0} , \;\; (- 11 \, | \, 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
  
  
Z założenia <math>D</math> jest liczbą kwadratową modulo <math>p</math> (zobacz L67), zatem istnieje taka liczba <math>R</math>, że
+
Niech <math>m \geqslant 23</math>. Wiemy, że w&nbsp;ciągu <math>(5, - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1)</math> wystąpią liczby <math>a_k</math> takie, że <math>(a_k \, | \, m) = - 1</math>. Warunek <math>(a_k \, | \, m) = 0</math> oznacza, że <math>(2 k + 1 \, | \, m) = 0</math>, bo
  
::<math>D \equiv R^2 \pmod{p}</math>
+
::<math>(a_k \, | \, m) = ((- 1)^k (2 k + 1) \, | \, m) = ((- 1)^k \, | \, m) \cdot (2 k + 1 \, | \, m) = (- 1 \, | \, m)^k \cdot (2 k + 1 \, | \, m) = \pm (2 k + 1 \, | \, m)</math>
  
Ponieważ
+
Jeżeli będą spełnione warunki <math>(a_k \, | \, m) = 0</math> i <math>R_m (a_k) \neq 0</math>, to liczba <math>m</math> będzie liczbą złożoną.
  
:* <math>(D \, | \, p) = 1</math>, to <math>p \nmid D</math>, zatem <math>p \nmid R</math>
+
Wypiszmy kolejne próby dla <math>m \geqslant 23</math>. Liczba <math>r</math> jest numerem próby.
:* z&nbsp;założenia <math>p \nmid Q</math>, to <math>P^2 - R^2 \equiv P^2 - D \equiv 4 Q \not\equiv 0 \pmod{p}</math>
 
  
 +
::<math>r = 1 , \;\; a_{r + 1} = 5</math>
  
Czyli
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = 1</math> || <math>5 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = 0</math> || <math>5 \, | \, m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = - 1 \quad</math> || <math>5 \nmid m</math> || <math>D = 5 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 +
|}
  
::<math>2^{p - 2} U_{p - 1} \equiv - P (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p}</math>
+
::<math>r = 2 , \;\; a_{r + 1} = - 7</math>
  
 +
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 1</math> || <math>7 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 0</math> || <math>7 \, | \, m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = - 1 \quad</math> || <math>7 \nmid m</math> || <math>D = -7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 +
|}
  
Uwzględniając, że <math>P^2 - R^2 \not\equiv 0 \pmod{p}</math>, możemy napisać
+
::<math>r = 3</math>, <math>a_{r + 1} = 9</math>
  
::<math>2^{p - 2} (P^2 - R^2) U_{p - 1} \equiv - P (P^2 - R^2) (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p}</math>
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 1</math> || <math>3 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 0</math> || <math>3 \, | \, m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) \neq - 1 \quad</math> || - - - - || bo <math>9</math> jest liczbą kwadratową
 +
|}
  
::::::::<math>\equiv - P (P^{p - 1} - R^{p - 1}) \pmod{p}</math>
 
  
::::::::<math>\equiv 0 \pmod{p}</math>
+
Po wykonaniu trzech prób niezakończonych sukcesem (tzn. wykryciem złożoności <math>m</math> lub ustaleniem wartości liczb <math>D</math> i <math>Q</math>) wiemy, że <math>m</math> nie jest podzielna przez żadną z&nbsp;liczb pierwszych <math>p = 3, 5, 7</math>.
  
Zauważmy, że wynik nie zależy od tego, czy <math>p \, | \, P</math>, czy <math>p \nmid P</math>. Skąd wynika
+
::<math>r</math>-ta próba, gdzie <math>r \geqslant 4 , \;\;</math> wyraz <math>a_{r + 1}</math>
  
::<math>U_{p - 1} \equiv 0 \pmod{p}</math>
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = 1</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = 0</math> || A. jeżeli <math>m \, | \, a_{r + 1}</math><sup>( * )</sup><br/>B. jeżeli <math>m \nmid a_{r + 1}</math> || A. przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math> <br/> B. <math>a_{r + 1} \, | \, m</math><sup>( ** )</sup>, '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = - 1 \quad</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || <math>D = a_{r + 1}</math>, <math>Q = {\small\frac{1 - a_{r + 1}}{4}}</math>, '''koniec'''
 +
|}
  
Co należało pokazać.<br/>
+
<sup>( * )</sup> jest to możliwe tylko dla <math>a_{r + 1} = a_{(m - 1) / 2} = m</math>
&#9633;
 
{{\Spoiler}}
 
  
 +
<sup>( ** )</sup> zauważmy, że jeżeli <math>m \nmid a_{r + 1}</math>, to <math>\gcd (a_{r + 1}, m) = | a_{r + 1} |</math>, bo gdyby liczba <math>| a_{r + 1} |</math> była liczbą złożoną, to żaden z&nbsp;jej dzielników pierwszych nie dzieliłby liczby <math>m</math>
  
  
Aby zapisać punkty 2. i 3. twierdzenia L34 (i tylko te punkty) w&nbsp;zwartej formie, musimy założyć, że <math>\gcd (p, D) = 1</math>. Otrzymujemy<br/>
+
Jeżeli nie została wykryta złożoność liczby <math>m</math>, to żadna z&nbsp;liczb pierwszych <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m</math>. Zatem <math>\gcd (Q, m) > 1</math> może być tylko w&nbsp;przypadku, gdy pewna liczba pierwsza <math>q \geqslant 2 r + 5</math> będzie wspólnym dzielnikiem liczb <math>Q</math> i <math>m</math>, ale jest to niemożliwe, bo
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L35</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą i <math>\gcd (p, Q D) = 1</math>, to
 
  
::<math>U_{p - (D \, | \, p)} \equiv 0 \pmod{p}</math>
+
::<math>| Q | = \left| {\small\frac{1 - a_{r + 1}}{4}} \right| \leqslant {\small\frac{| a_{r + 1} | + 1}{4}} = {\small\frac{2 r + 4}{4}} < 2 r + 5 \leqslant q</math>
  
 +
Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich <math>r</math> naturalnych.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
  
  
 +
<span style="font-size: 110%; font-weight: bold;">Zadanie L31</span><br/>
 +
Zmodyfikujmy metodę Selfridge'a w&nbsp;taki sposób, że będziemy rozpoczynali próby nie od wyrazu <math>a_2 = 5</math>, ale od wyrazu <math>a_3 = - 7</math>. Pokazać, że w&nbsp;przypadku, gdy dla kolejnych liczb <math>a_k = (- 1)^k (2 k + 1)</math> sprawdzamy, czy konsekwencją <math>(a_k \, | \, m) = 0</math> jest złożoność liczby <math>m</math>, to dla każdej liczby <math>Q</math> wyznaczonej tak zmodyfikowaną metodą Selfridge'a jest <math>\gcd (Q, m) = 1</math>.
  
== Liczby pseudopierwsze Lucasa ==
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Poniżej pokażemy, dlaczego musi być <math>\gcd (Q, m) = 1</math>, gdzie <math>Q</math> jest liczbą wyznaczoną zmodyfikowaną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby <math>m</math> przy testowaniu kolejnych liczb <math>a_k</math>). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby <math>m</math>. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość <math>Q</math> na podstawie innego wyrazu ciągu <math>a_k</math> (ten symbol Jacobiego został zapisany zwykłą czcionką).
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L36</span><br/>
+
::<math>m = 3 , \;\; (- 7 \, | \, 3) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
Z twierdzenia L35 wiemy, że liczby pierwsze nieparzyste <math>p</math> takie, że <math>p \nmid Q D</math> są dzielnikami wyrazów ciągu Lucasa <math>U_{p - (D \, | \, p)}</math>, gdzie <math>(D \, | \, 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&nbsp;łatwo przekonamy się, że dla pewnych liczb złożonych <math>m</math> kongruencja
 
  
::<math>U_{m - (D \, | \, m)} \equiv 0 \pmod{m}</math>
+
::<math>m = 5 , \;\; (- 7 \, | \, 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
również jest prawdziwa. Prowadzi to definicji liczb pseudopierwszych Lucasa.
+
::<math>m = 7 , \;\; (- 7 \, | \, 7) = 0 , \;\; (- 11 \, | \, 7) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1</math> (zauważmy, że <math>(- 7 \, | \, 7) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
  
 +
::<math>m = 9 , \;\; </math> (liczba kwadratowa)
  
 +
::<math>m = 11 , \;\; (- 11 \, | \, 11) = 0 , \;\; (13 \, | \, 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(- 11 \, | \, 11) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
  
<span style="font-size: 110%; font-weight: bold;">Definicja L37</span><br/>
+
::<math>m = 13 , \;\; (- 7 \, | \, 13) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
Powiemy, że liczba złożona nieparzysta <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P</math> i <math>Q</math> (symbolicznie: LPSP( <math>P, Q</math> )), jeżeli <math>\gcd (m, Q D) = 1</math> i
 
  
::<math>U_{m - (D \, | \, m)} \equiv 0 \pmod{m}</math>
+
::<math>m = 15 , \;\; \boldsymbol{(9 \, | \, 15) = 0} , \;\; (13 \, | \, 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
  
gdzie <math>(D \, | \, m)</math> oznacza symbol Jacobiego.
+
::<math>m = 17 , \;\; (- 7 \, | \, 17) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
 +
::<math>m = 19 , \;\; (- 7 \, | \, 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
 +
::<math>m = 21 , \;\; \boldsymbol{(- 7 \, | \, 21) = 0} , \;\; (- 11 \, | \, 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L38</span><br/>
 
Jeżeli liczba złożona nieparzysta <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P = a + 1</math> i <math>Q = a</math>, gdzie <math>a \geqslant 2</math>, to jest liczbą pseudopierwszą Fermata przy podstawie <math>a</math>.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
Niech <math>m \geqslant 23</math>. Wiemy, że w&nbsp;ciągu <math>( - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1)</math> wystąpią liczby <math>a_k</math> takie, że <math>(a_k \, | \, m) = - 1</math>. Warunek <math>(a_k \, | \, m) = 0</math> oznacza, że <math>(2 k + 1 \, | \, m) = 0</math>, bo
Połóżmy we wzorze definiującym ciąg Lucasa
 
  
::<math>U_m = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}}</math>
+
::<math>(a_k \, | \, m) = ((- 1)^k (2 k + 1) \, | \, m) = ((- 1)^k \, | \, m) \cdot (2 k + 1 \, | \, m) = (- 1 \, | \, m)^k \cdot (2 k + 1 \, | \, m) = \pm (2 k + 1 \, | \, m)</math>
  
<math>\alpha = a</math> i <math>\beta = 1</math>. Odpowiada to parametrom <math>P = \alpha + \beta = a + 1</math>, <math>Q = \alpha \beta = a</math>, <math>D = (\alpha - \beta)^2 = (a - 1)^2</math>.
+
Jeżeli będą spełnione warunki <math>(a_k \, | \, m) = 0</math> i <math>R_m (a_k) \neq 0</math>, to liczba <math>m</math> będzie liczbą złożoną.
  
Ponieważ musi być <math>\gcd (m, Q D) = 1</math>, to mamy <math>\gcd (m, (a - 1) a) = 1</math> i&nbsp;wynika stąd, że <math>(D \, | \, m) = 1</math>. Z&nbsp;założenia <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P = a + 1</math> i <math>Q = a</math>, zatem
+
Wypiszmy kolejne próby dla <math>m \geqslant 23</math>. Liczba <math>r</math> jest numerem próby.
  
::<math>U_{m - 1} (a + 1, a) \equiv 0 \pmod{m}</math>
+
::<math>r = 1 , \;\; a_{r + 2} = - 7</math>
  
Czyli
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 1</math> || <math>7 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 0</math> || <math>7 \, | \, m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = - 1 \quad</math> || <math>7 \nmid m</math> || <math>D = - 7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 +
|}
  
::<math>{\small\frac{a^{m - 1} - 1}{a - 1}} \equiv 0 \pmod{m}</math>
+
::<math>r = 2 , \;\; a_{r + 2} = 9</math>
  
Jeżeli <math>m \biggr\rvert {\small\frac{a^{m - 1} - 1}{a - 1}}</math>, to tym bardziej <math>m \big\rvert (a^{m - 1} - 1)</math> i&nbsp;możemy napisać
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 1</math> || <math>3 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 0</math> || <math>3 \, | \, m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) \neq - 1 \quad</math> || - - - - || bo <math>9</math> jest liczbą kwadratową
 +
|}
  
::<math>a^{m - 1} - 1 \equiv 0 \pmod{m}</math>
+
::<math>r = 3 , \;\; a_{r + 2} = - 11</math>
  
Zatem <math>m</math> jest liczbą pseudopierwszą Fermata przy podstawie <math>a</math>. Co należało pokazać.<br/>
+
::{| border="0"
&#9633;
+
|-style=height:2em
{{\Spoiler}}
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = 1</math> || <math>11 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = 0</math> || <math>11 \, | \, m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = - 1 \quad</math> || <math>11 \nmid m</math> || <math>D = - 11 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec''' (bo liczby złożone <math>m = 3 k</math> zostały usunięte w&nbsp;poprzedniej próbie, <math>r = 2</math>)
 +
|}
  
 +
::<math>r = 4 , \;\; a_{r + 2} = 13</math>
  
 +
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = 1</math> || <math>13 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = 0</math> || <math>13 \, | \, m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = - 1 \quad</math> || <math>13 \nmid m</math> || <math>D = 13 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec''' (bo liczby złożone <math>m = 3 k</math> zostały usunięte w&nbsp;próbie o&nbsp;numerze <math>r = 2</math>)
 +
|}
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L39</span><br/>
+
::<math>r = 5 , \;\; a_{r + 2} = - 15</math>
Wykorzystując funkcje <code>jacobi(a, n)</code> i <code>modLucas(n, P, Q, m)</code> (zobacz L6, L30) możemy napisać prosty program, który sprawdza, czy dla liczby nieparzystej <math>m</math> prawdziwe jest twierdzenie L35.
 
  
<span style="font-size: 90%; color:black;">isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q) =  
+
::{| border="0"
{
+
|-style=height:2em
'''local'''(D, js);
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = 1</math> || <math>5 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
D = P^2 - 4*Q;
+
|-style=height:2em
'''if'''( gcd(m, 2*Q*D) > 1, '''return'''(0) );
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = 0</math> || <math>5 \, | \, m</math> || '''koniec'''
js = jacobi(D, m);
+
|-style=height:2em
'''if'''( modLucas(m - js, P, Q, m)[1] == 0, '''return'''(1), '''return'''(0) );
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = - 1 \quad</math> || <math>5 \nmid m</math> || <math>D = - 15 , \;\; Q = 4 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
}
+
|}
  
  
 +
Po wykonaniu pięciu prób niezakończonych sukcesem (tzn. wykryciem złożoności <math>m</math> lub ustaleniem wartości liczb <math>D</math> i <math>Q</math>) wiemy, że <math>m</math> nie jest podzielna przez żadną z&nbsp;liczb pierwszych <math>p = 3, 5, 7, 11, 13</math>.
  
<span style="font-size: 110%; font-weight: bold;">Przykład L40</span><br/>
+
::<math>r</math>-ta próba, gdzie <math>r \geqslant 6 , \;\;</math> wyraz <math>a_{r + 2}</math>
Poniższa tabela zawiera najmniejsze liczby pseudopierwsze Lucasa dla różnych parametrów <math>P</math> i <math>Q</math>
 
  
::{| class="wikitable plainlinks" style="font-size: 100%; text-align: right; margin-right: auto;"
+
::{| border="0"  
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
|-style=height:2em
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = 1</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
|-
+
|-style=height:2em
! <math>\boldsymbol{- 5}</math>
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = 0</math> || A. jeżeli <math>m \, | \, a_{r + 2}</math><sup>( * )</sup><br/>B. jeżeli <math>m \nmid a_{r + 2}</math> || A. przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math> <br/> B. <math>a_{r + 1} \, | \, m</math><sup>( ** )</sup>, '''koniec'''
| <math>253</math> || <math>121</math> || <math>57</math> || <math>217</math> || style="background-color: yellow" | <math>323</math> || <math>69</math> || <math>121</math> || <math>253</math> || <math>9</math> || style="background-color: yellow" | <math>143</math>
+
|-style=height:2em
|-
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = - 1 \quad</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || <math>D = a_{r + 2}</math>, <math>Q = {\small\frac{1 - a_{r + 2}}{4}}</math>, '''koniec'''
! <math>\boldsymbol{- 4}</math>
 
| <math>9</math> || style="background-color: yellow" | <math>323</math> || <math>91</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>15</math> || style="background-color: yellow" | <math>119</math> || <math>57</math> || <math>9</math> || <math>9</math> || <math>9</math>
 
|-
 
! <math>\boldsymbol{- 3}</math>
 
| <math>217</math> || <math>91</math> || style="background-color: yellow" | <math>527</math> || <math>25</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>65</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math>
 
|-
 
! <math>\boldsymbol{- 2}</math>
 
| <math>341</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>39</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>15</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || <math>9</math> || <math>85</math>
 
|-
 
! <math>\boldsymbol{- 1}</math>
 
| style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>119</math> || <math>9</math> || <math>9</math> || style="background-color: yellow" | <math>143</math> || <math>25</math> || <math>33</math> || <math>9</math> || style="background-color: yellow" | <math>15</math>
 
|-
 
! <math>\boldsymbol{1}</math>
 
| <math>25</math> || style="background-color: red" | <math></math> || <math>21</math> || style="background-color: yellow" | <math>65</math> || style="background-color: yellow" | <math>115</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>209</math> || <math>9</math> || style="background-color: yellow" | <math>35</math>
 
|-
 
! <math>\boldsymbol{2}</math>
 
| <math>1541</math> || <math>9</math> || <math>341</math> || style="background-color: yellow" | <math>35</math> || <math>21</math> || <math>85</math> || <math>9</math> || style="background-color: yellow" | <math>15</math> || <math>9</math> || style="background-color: yellow" | <math>35</math>
 
|-
 
! <math>\boldsymbol{3}</math>
 
| style="background-color: yellow" | <math>629</math> || style="background-color: yellow" | <math>559</math> || <math>25</math> || <math>91</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>35</math> || <math>55</math> || <math>25</math> || style="background-color: yellow" | <math>35</math>
 
|-
 
! <math>\boldsymbol{4}</math>
 
| style="background-color: yellow" | <math>119</math> || <math>25</math> || style="background-color: yellow" | <math>209</math> || style="background-color: red" | <math></math> || <math>85</math> || <math>21</math> || style="background-color: yellow" | <math>119</math> || style="background-color: yellow" | <math>65</math> || <math>9</math> || style="background-color: yellow" | <math>115</math>
 
|-
 
! <math>\boldsymbol{5}</math>
 
| <math>9</math> || style="background-color: yellow" | <math>143</math> || <math>49</math> || style="background-color: yellow" | <math>143</math> || style="background-color: yellow" | <math>323</math> || <math>217</math> || style="background-color: yellow" | <math>39</math> || <math>9</math> || <math>9</math> || <math>9</math>
 
 
|}
 
|}
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
+
<sup>( * )</sup> jest to możliwe tylko dla <math>a_{r + 2} = a_{(m - 1) / 2} = m</math>
<span style="font-size: 90%; color:black;">FirstLPSP(Stop) =
+
 
\\ najmniejsze LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
+
<sup>( ** )</sup> zauważmy, że jeżeli <math>m \nmid a_{r + 2}</math>, to <math>\gcd (a_{r + 2}, m) = | a_{r + 2} |</math>, bo gdyby liczba <math>| a_{r + 2} |</math> była liczbą złożoną, to żaden z&nbsp;jej dzielników pierwszych nie dzieliłby liczby <math>m</math>
{
 
'''local'''(D, m, P, Q);
 
Q = -6;
 
'''while'''( Q++ <= 5,
 
        '''if'''( Q == 0, '''next'''() );
 
        P = 0;
 
        '''while'''( P++ <= 10,
 
              D = P^2 - 4*Q;
 
              '''if'''( D == 0,
 
                  '''print'''("Q= ", Q, "  P= ", P, "  ------------------");
 
                  '''next'''();
 
                );
 
              m = 3;
 
              '''while'''( m < Stop,
 
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q)  &&  !'''isprime'''(m),
 
                          '''print'''("Q= ", Q, "  P= ", P, "  m= ", m, "  (D|m)= ", jacobi(D, m));
 
                          '''break'''();
 
                        );
 
                      m = m + 2;
 
                    );
 
            );
 
      );
 
}</span>
 
<br/>
 
{{\Spoiler}}
 
  
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których <math>(D \, | \, m) = - 1</math>.
 
  
 +
Jeżeli nie została wykryta złożoność liczby <math>m</math>, to żadna z&nbsp;liczb pierwszych <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m</math>. Zatem <math>\gcd (Q, m) > 1</math> może być tylko w&nbsp;przypadku, gdy pewna liczba pierwsza <math>q \geqslant 2 r + 7</math> będzie wspólnym dzielnikiem liczb <math>Q</math> i <math>m</math>, ale jest to niemożliwe, bo
  
 +
::<math>| Q | = \left| {\small\frac{1 - a_{r + 2}}{4}} \right| \leqslant {\small\frac{| a_{r + 2} | + 1}{4}} = {\small\frac{2 r + 6}{4}} < 2 r + 7 \leqslant q</math>
  
<span style="font-size: 110%; font-weight: bold;">Przykład L41</span><br/>
+
Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich <math>r</math> naturalnych.<br/>
Ilość liczb LPSP(<math>P, Q</math>) mniejszych od <math>10^9</math>
+
&#9633;
 +
{{\Spoiler}}
 +
 
 +
 
 +
 
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga L32</span><br/>
 +
Przyjmując metodę Selfridge'a wyboru parametrów <math>P, Q</math> dla testu Lucasa, możemy łatwo napisać odpowiedni program w&nbsp;PARI/GP testujący pierwszość liczb
  
::{| class="wikitable plainlinks" style="font-size: 100%; text-align: right; margin-right: auto;"
+
  <span style="font-size: 90%; color:black;">LucasTest(m) =
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
{
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
+
'''local'''(P, Q, X);
|-
+
'''if'''( m % 2 == 0, '''return'''(m == 2) );
! <math>\boldsymbol{- 5}</math>
+
'''if'''( '''issquare'''(m), '''return'''(0) ); \\ sprawdzamy, czy m nie jest liczbą kwadratową
| <math>4266</math> || <math>4935</math> || <math>4278</math> || <math>4981</math> || <math>6363</math> || <math>6028</math> || <math>5202</math> || <math>4426</math> || <math>5832</math> || <math>6027</math>
+
X = MethodA(m);
|-
+
P = X[1];
! <math>\boldsymbol{- 4}</math>
+
Q = X[2];
| <math>4599</math> || <math>4152</math> || <math>9272</math> || <math>5886</math> || <math>6958</math> || <math>4563</math> || <math>5600</math> || <math>9509</math> || <math>7007</math> || <math>4142</math>
+
'''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) );
! <math>\boldsymbol{- 3}</math>
+
}</span>
| <math>4265</math> || <math>5767</math> || <math>4241</math> || <math>5114</math> || <math>5859</math> || <math>7669</math> || <math>6083</math> || <math>6120</math> || <math>4420</math> || <math>5096</math>
+
 
|-
+
 
! <math>\boldsymbol{- 2}</math>
+
 
| <math>5361</math> || <math>4389</math> || <math>5063</math> || <math>5632</math> || <math>5364</math> || <math>5228</math> || <math>5859</math> || <math>10487</math> || <math>5370</math> || <math>9798</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L33</span><br/>
|-
+
Najmniejsze liczby pseudopierwsze Lucasa, które pojawiają się przy zastosowaniu metody Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math>, to
! <math>\boldsymbol{- 1}</math>
+
 
| <math>4152</math> || <math>5886</math> || <math>4563</math> || <math>9509</math> || <math>4142</math> || <math>6273</math> || <math>5773</math> || <math>4497</math> || <math>5166</math> || <math>5305</math>
+
::<math>323, 377, 1159, 1829, 3827, 5459, 5777, 9071, 9179, 10877, 11419, 11663, 13919, 14839, 16109, 16211, 18407, 18971, 19043, 22499, \ldots</math>
|-
 
! <math>\boldsymbol{1}</math>
 
| <math>282485800</math> || style="background-color: red" | <math></math> || <math>6567</math> || <math>7669</math> || <math>7131</math> || <math>10882</math> || <math>8626</math> || <math>8974</math> || <math>8509</math> || <math>8752</math>
 
|-
 
! <math>\boldsymbol{2}</math>
 
| <math>7803</math> || <math>449152466</math> || <math>5597</math> || <math>5886</math> || <math>6509</math> || <math>5761</math> || <math>8115</math> || <math>6945</math> || <math>8380</math> || <math>7095</math>
 
|-
 
! <math>\boldsymbol{3}</math>
 
| <math>5974</math> || <math>8768</math> || <math>282485800</math> || <math>5767</math> || <math>5651</math> || <math>5632</math> || <math>6640</math> || <math>5725</math> || <math>6058</math> || <math>7050</math>
 
|-
 
! <math>\boldsymbol{4}</math>
 
| <math>10749</math> || <math>282485800</math> || <math>14425</math> || style="background-color: red" | <math></math> || <math>9735</math> || <math>6567</math> || <math>8164</math> || <math>7669</math> || <math>7608</math> || <math>7131</math>  
 
|-
 
! <math>\boldsymbol{5}</math>
 
| <math>5047</math> || <math>15127</math> || <math>6155</math> || <math>15127</math> || <math>4152</math> || <math>5146</math> || <math>4423</math> || <math>5526</math> || <math>6289</math> || <math>9509</math>
 
|}
 
  
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
  <span style="font-size: 90%; color:black;">NumOfLPSP(Stop) =
+
  <span style="font-size: 90%; color:black;">'''forstep'''(k=1, 3*10^4, 2, '''if'''( LucasTest(k) && !'''isprime'''(k), '''print'''(k)) )</span>
\\ ilość liczb pseudopierwszych Lucasa LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
+
<br/>
{
+
{{\Spoiler}}
'''local'''(D, m, P, Q);
+
 
Q = -6;
+
 
'''while'''( Q++ <= 5,
+
 
        '''if'''( Q == 0, '''next'''() );
+
Tabela przedstawia ilość takich liczb nie większych od <math>10^n</math>
        P = 0;
+
 
        '''while'''( P++ <= 10,
+
::{| class="wikitable plainlinks" style="font-size: 90%; text-align: right; margin-right: auto;"
              D = P^2 - 4*Q;
+
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math>
              '''if'''( D == 0, '''print'''("Q= ", Q, "  P= ", P, "  ------------------"); '''next'''() );
+
|-
              s = 0;
+
| #LPSP <math>< 10^n</math> (metoda Selfridge'a) || <math>2</math> || <math>9</math> || <math>57</math> || <math>219</math> || <math>659</math> || <math>1911</math> || <math>5485</math>
              m = 3;
+
|}
              '''while'''( m < Stop,
+
 
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q) && !'''isprime'''(m), s++ );
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
                      m = m + 2;
+
<span style="font-size: 90%; color:black;">'''for'''(n=3, 9, s=0; '''forstep'''(k = 1, 10^n, 2, '''if'''( LucasTest(k) && !'''isprime'''(k), s++ ) ); '''print'''("n= ", n, "  ", s) )</span>
                    );
 
              '''print'''("Q= ", Q, "  P= ", P, "  s= ", s);
 
            );
 
      );
 
}</span>
 
 
<br/>
 
<br/>
 
{{\Spoiler}}
 
{{\Spoiler}}
Linia 1506: Linia 1534:
  
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L42</span><br/>
 
Dla <math>(P, Q) = (1, 1)</math> ciąg Lucasa <math>(U_n)</math> ma postać
 
  
::<math>(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>U_{3 k} = 0</math>. Łatwo sprawdzamy, że dla <math>k = 0</math> i <math>k = 1</math> wzór jest prawdziwy. Zakładając prawdziwość wzoru dla wszystkich liczb naturalnych nie większych od <math>k</math>, otrzymujemy dla <math>k + 1</math> (zobacz L28 p.3)
+
== Liczby silnie pseudopierwsze Lucasa ==
  
::<math>U_{3 (k + 1)} = U_{3 k + 3} = U_{3 k} V_3 - U_{3 (k - 1)} = 0</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L34</span><br/>
 +
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą taką, że <math>\gcd (p, Q D) = 1</math> oraz <math>p - (D \, | \, p) = 2^r w</math>, gdzie <math>w</math> jest liczbą nieparzystą, to spełniony jest dokładnie jeden z&nbsp;warunków
  
Co kończy dowód. Zbadajmy liczby pseudopierwsze Lucasa dla <math>(P, Q) = (1, 1)</math>.
+
::<math>U_w \equiv 0 \pmod{p}</math>
  
Mamy <math>D = P^2 - 4 Q = - 3</math>. Wynika stąd, że nie może być <math>3 \, | \, m</math>, bo mielibyśmy <math>\gcd (m, Q D) = 3 > 1</math>.
+
lub
  
Z zadania L4 wiemy, że
+
::<math>V_{2^k w} \equiv 0 \pmod{p} \qquad</math> dla pewnego <math>k \in [0, r - 1]</math>
  
::<math>(- 3 \, | \, m) =
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
\begin{cases}
+
Wiemy (zobacz L20), że jeżeli <math>p</math> jest liczbą pierwszą nieparzystą taką, że <math>\gcd (p, Q D) = 1</math>, to <math>p \, | \, U_{p - (D \, | \, p)}</math>. Z&nbsp;założenia jest <math>p - (D \, | \, p) = 2^r w</math>, zatem <math>p \, | \, U_{2^r w}</math>. Ponieważ założyliśmy, że <math>p \nmid Q</math> i <math>p \nmid D</math>, to ze wzoru <math>V^2_n - D U^2_n = 4 Q^n</math> (zobacz L13 p.14) wynika natychmiast, że <math>p</math> nie może dzielić jednocześnie liczb <math>U_n</math> i <math>V_n</math>.
\;\;\: 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>3 \nmid m</math>, to wystarczy zbadać przypadki <math>m = 6 k + 1</math> i <math>m = 6 k + 5</math>. W&nbsp;pierwszym przypadku jest
+
Korzystając ze wzoru <math>U_{2 n} = U_n V_n</math> (zobacz L13 p.11), otrzymujemy
  
::<math>U_{m - (- 3 \, | \, m)} = U_{6 k + 1 - 1} = U_{6 k} = 0</math>
+
::{| border="0"
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2^r w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2^{r - 1} w} \cdot V_{2^{r - 1} w} \quad</math> || Jeżeli <math>p \, | \, V_{2^{r - 1} w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2^{r - 1} w}</math>, to <math>p \, | \, U_{2^{r - 1} w}</math>.
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2^{r - 1} w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2^{r - 2} w} \cdot V_{2^{r - 2} w} \quad</math> || Jeżeli <math>p \, | \, V_{2^{r - 2} w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2^{r - 2} w}</math>, to <math>p \, | \, U_{2^{r - 2} w}</math>.
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>.................</math> ||
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{4 w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2 w} \cdot V_{2 w}</math> || Jeżeli <math>p \, | \, V_{2 w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2 w}</math>, to <math>p \, | \, U_{2 w}</math>.
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2 w} \;\; \Longleftrightarrow \;\; p \, | \, U_w \cdot V_w</math> || Jeżeli <math>p \, | \, V_w</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_w</math>, to <math>p \, | \, U_w</math>.
 +
|}
  
W drugim przypadku, gdy <math>m = 6 k + 5</math>, dostajemy
+
Z powyższego wynika, że musi być spełniony jeden z wypisanych w twierdzeniu warunków.
  
::<math>U_{m - (- 3 \, | \, m)} = U_{6 k + 5 + 1} = U_{6 (k + 1)} = 0</math>
 
  
Zatem dla dowolnej liczby nieparzystej <math>m</math> niepodzielnej przez <math>3</math> jest
+
Zauważmy teraz, że jeżeli liczba pierwsza <math>p</math> dzieli <math>V_w</math>, to <math>p \nmid U_w</math>, bo <math>p</math> nie może jednocześnie być dzielnikiem liczb <math>U_w</math> i <math>V_w</math>.
  
::<math>U_{m - (- 3 \, | \, m)} \equiv 0 \pmod{m}</math>
+
Zauważmy też, że jeżeli dla pewnego <math>k \in [1, r - 1]</math> liczba pierwsza <math>p</math> dzieli <math>V_{2^k w}</math>, to <math>p</math> nie dzieli żadnej liczby <math>V_{2^j w}</math> dla <math>j \in [0, k - 1] \;\; \text{i} \;\; p \nmid U_w</math>. Istotnie:
  
Czyli liczbami pseudopierwszymi Lucasa dla parametrów <math>(P, Q) = (1, 1)</math> będą liczby nieparzyste <math>m</math>, które nie są podzielne przez <math>3</math> i&nbsp;nie są liczbami pierwszymi. Ilość takich liczb nie większych od <math>10^k</math> możemy łatwo znaleźć poleceniem
+
::{| border="0"
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \, | \, V_{2^k w}</math>, to <math>p \nmid U_{2^k w} \;\; \text{i} \;\; U_{2^k w} = U_{2^{k - 1} w} V_{2^{k - 1} w}</math>, zatem <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2^{k - 1} w} \;\; \text{i} \;\; V_{2^{k - 1} w}</math>
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{2^{k - 1} w} \;\; \text{i} \;\; U_{2^{k - 1} w} = U_{2^{k - 2} w} V_{2^{k - 2} w}</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2^{k - 2} w} \;\; \text{i} \;\; V_{2^{k - 2} w}</math>
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>.................</math> ||
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{4 w} \;\; \text{i} \;\; U_{4 w} = U_{2 w} V_{2 w}</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2 w} \;\; \text{i} \;\; V_{2 w}</math>
 +
|-style=height:3em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{2 w} \;\; \text{i} \;\; U_{2 w} = U_w V_w</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_w \;\; \text{i} \;\; V_w</math>
 +
|}
  
'''for'''(k = 1, 9, s = 0; '''forstep'''(m = 3, 10^k, 2, '''if'''( m%6 <> 3, s = s + !'''isprime'''(m) )); '''print'''(s))
 
  
 +
Co dowodzi, że spełniony jest dokładnie jeden z <math>r + 1</math> warunków:
  
 +
::<math>U_w \equiv 0 \pmod{p}</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L43</span><br/>
+
::<math>V_{2^k w} \equiv 0 \pmod{p} \qquad</math> gdzie <math>k \in [0, r - 1]</math>
Pokazać, że ilość liczb pseudopierwszych Lucasa dla parametrów <math>(P, Q) = (2, 2)</math> nie większych od <math>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))
+
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
  
  
 +
Konsekwentnie definiujemy liczby pseudopierwsze<br/>
 +
<span style="font-size: 110%; font-weight: bold;">Definicja L35</span><br/>
 +
Powiemy, że liczba złożona nieparzysta <math>m</math> jest liczbą silnie pseudopierwszą Lucasa (SLPSP) dla parametrów <math>P</math> i <math>Q</math>, jeżeli <math>\gcd (m, Q D) = 1</math> oraz <math>m - (D \, | \, m) = 2^r w</math>, gdzie <math>w</math> jest liczbą nieparzystą i&nbsp;spełniony jest jeden z&nbsp;warunków
  
 +
::<math>U_w \equiv 0 \pmod{m}</math>
  
== Metoda Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math> ==
+
lub
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L44</span><br/>
+
::<math>V_{2^k w} \equiv 0 \pmod{m} \;</math> dla pewnego <math>k \in [0, r - 1]</math>
Twierdzenie L35 możemy wykorzystać do testowania pierwszości liczb. Ponieważ musi być spełniony warunek <math>\gcd (m, Q D) = 1</math>, to nie każda para liczb <math>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>P, Q</math>.
 
  
Robert Baillie i&nbsp;Samuel Wagstaff przedstawili<ref name="BaillieWagstaff1"/> dwie metody wyboru parametrów dla testu Lucasa. Ograniczymy się do omówienia tylko pierwszej z&nbsp;nich (metodę zaproponował John Selfridge).
 
  
Rozważmy ciąg <math>a_k = (- 1)^k (2 k + 1)</math>, gdzie <math>k \geqslant 2</math>, czyli <math>a_k = (5, - 7, 9, - 11, 13, - 15, \ldots)</math>. Niech <math>D</math> będzie pierwszym wyrazem ciągu <math>(a_k)</math>, dla którego jest <math>(a_k \, | \, m) = - 1</math>. Dla tak ustalonego <math>D</math> przyjmujemy <math>P = 1</math> i <math>Q = (1 - D) / 4</math>.
 
  
Tabela przedstawia początkowe wartości <math>Q</math>, jakie otrzymamy, stosując tę metodę.
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L36</span><br/>
 +
Każda liczba SLPSP(<math>P, Q</math>) jest LPSP(<math>P, Q</math>). Korzystając ze zdefiniowanych wcześniej funkcji: <code>modPower(a, n, m)</code>, <code>jacobi(a, n)</code> i <code>modLucas(n, P, Q, m)</code> (zobacz K2, J34, L15), możemy napisać prosty program, który sprawdza, czy liczba <math>m</math> spełnia jeden z&nbsp;warunków podanych w&nbsp;twierdzeniu L34.
  
::{| class="wikitable plainlinks" style="font-size: 100%; text-align: right; margin-right: auto;"
+
  <span style="font-size: 90%; color: black;">isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q) =  
! <math>\boldsymbol{k}</math>  
+
  {
| <math>2</math> || <math>3</math> || <math>4</math> || <math>5</math> || <math>6</math> || <math>7</math> || <math>8</math> || <math>9</math> || <math>10</math> || <math>11</math> || <math>12</math> || <math>13</math> || <math>14</math> || <math>15</math> || <math>16</math> || <math>17</math> || <math>18</math> || <math>19</math> || <math>20</math>
+
  '''local'''(a, b, c, D, js, k, r, w, X);
|-
+
  D = P^2 - 4*Q;
!  <math>\boldsymbol{a_k}</math>
+
  '''if'''( gcd(m, 2*Q*D) > 1, '''return'''(0) );
| <math>5</math> || <math>-7</math> || <math>9</math> || <math>-11</math> || <math>13</math> || <math>-15</math> || <math>17</math> || <math>-19</math> || <math>21</math> || <math>-23</math> || <math>25</math> || <math>-27</math> || <math>29</math> || <math>-31</math> || <math>33</math> || <math>-35</math> || <math>37</math> || <math>-39</math> || <math>41</math>
+
js = jacobi(D, m);
|-
+
r = '''valuation'''(m - js, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m - js
!  <math>\boldsymbol{Q}</math>
+
w = (m - js) / 2^r;
| <math>-1</math> || <math>2</math> || style="background-color: red" | <math>-2</math> || <math>3</math> || <math>-3</math> || <math>4</math> || <math>-4</math> || <math>5</math> || <math>-5</math> || <math>6</math> || style="background-color: red" | <math>-6</math> || <math>7</math> || <math>-7</math> || <math>8</math> || <math>-8</math> || <math>9</math> || <math>-9</math> || <math>10</math> || <math>-10</math>
+
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
Zauważmy, że
+
'''if'''( r == 1, '''return'''(0) ); \\ nie ma dalszych przypadków
:* jeżeli liczba nieparzysta <math>m</math> jest liczbą kwadratową, to wybór <math>D</math> nie będzie możliwy
+
c = modPower(Q, w, m); \\ Q^w % m
:* w&nbsp;przypadku zastosowania tej metody znajdziemy tylko liczby pierwsze lub pseudopierwsze Lucasa, które spełniają kongruencję <math>U_{m + 1} \equiv 0 \pmod{m}</math>, czyli tylko część liczb pseudopierwszych Lucasa określonych w&nbsp;definicji L37
+
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,
Ponieważ Baillie i&nbsp;Wagstaff określili metodę zaproponowaną przez Selfridge'a jako metodę A, to pozostaniemy przy tej nazwie. Korzystając ze wzoru rekurencyjnego
+
         b = (b^2 - 2*c) % m;
 
+
        '''if'''( b == 0, '''return'''(1) );
::<math> a_{k+1} =
+
        c = c^2 % m;
  \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>P, Q</math> według tej metody.
 
 
 
<span style="font-size: 90%; color:black;">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);
 
 
       );
 
       );
 +
'''return'''(0);
 
  }</span>
 
  }</span>
  
Wyjaśnienia wymaga druga linia kodu w&nbsp;pętli <code>while</code>. Wiemy, że (zobacz L3)
 
  
::<math>(a \, | \, m) = 0 \quad \qquad \Longleftrightarrow \quad \qquad \gcd (a, m) > 1</math>
 
  
Jednak z&nbsp;faktu, że <math>\gcd (a, m) > 1</math> nie wynika natychmiast, że liczba <math>m</math> jest liczbą złożoną. Rozważmy dwa przypadki: gdy <math>m \, | \, a</math> i <math>m \nmid a</math>.
+
<span style="font-size: 110%; font-weight: bold;">Przykład L37</span><br/>
 +
Poniższa tabela zawiera najmniejsze liczby silnie pseudopierwsze Lucasa dla różnych parametrów <math>P</math> i <math>Q</math>
  
Gdy <math>\gcd (a, m) > 1</math> i <math>m \, | \, a</math>, to <math>\gcd (a, m) = \gcd (k \cdot m, m) = m > 1</math> i&nbsp;nie jesteśmy w&nbsp;stanie rozstrzygnąć, czy liczba <math>m</math> jest liczbą pierwszą, czy złożoną. Widać to dobrze na prostych przykładach
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
+
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
::<math>\gcd (7, 7) = \gcd (14, 7) = 7 > 1</math>
+
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>  
 
+
|-
::<math>\gcd (15, 15) = \gcd (30, 15) = 15 > 1</math>
+
! <math>\boldsymbol{- 5}</math>
 
+
| <math>253</math> || <math>121</math> || style="background-color: yellow" | <math>143</math> || <math>781</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>299</math> || <math>121</math> || style="background-color: yellow" | <math>407</math> || <math>9</math> || style="background-color: yellow" | <math>143</math>
Gdy <math>\gcd (a, m) > 1</math> i <math>m \nmid a</math>, to <math>m</math> jest liczbą złożoną. Ponieważ <math>m \nmid a</math>, to <math>a = k \cdot m + r</math>, gdzie <math>r \in [1, m - 1]</math>. Mamy
+
|-
 
+
! <math>\boldsymbol{- 4}</math>
::<math>\gcd (a, m) = \gcd (k \cdot m + r, m) = \gcd (r, m) = d</math>
+
| <math>9</math> || <math>4181</math> || <math>341</math> || <math>169</math> || <math>33</math> || style="background-color: yellow" | <math>119</math> || <math>57</math> || <math>9</math> || <math>9</math> || <math>9</math>  
 
+
|-
Musi być <math>d > 1</math>, bo założyliśmy, że <math>\gcd (a, m) > 1</math> i&nbsp;musi być <math>d < m</math>, bo <math>d \leqslant r \leqslant m - 1</math>. Zatem <math>d</math> jest dzielnikiem nietrywialnym liczby <math>m</math> i <math>m</math> jest liczbą złożoną.
+
! <math>\boldsymbol{- 3}</math>
 
+
| style="background-color: yellow" | <math>799</math> || <math>121</math> || style="background-color: yellow" | <math>527</math> || <math>25</math> || <math>85</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>55</math> || style="background-color: yellow" | <math>35</math> || <math>169</math> || <math>529</math>  
Omawiana linia kodu zapewnia wysłanie informacji o&nbsp;tym, że liczba <math>m</math> jest liczbą złożoną (zwrot wektora [0, 0]). W&nbsp;przypadku, gdy nie mamy takiej pewności, kontynuujemy szukanie liczby <math>a</math>, takiej że <math>(a \, | \, m) = - 1</math>, pozostawiając zbadanie pierwszości liczby <math>m</math> na kolejnym etapie testowania.
+
|-
 
+
! <math>\boldsymbol{- 2}</math>
 
+
| <math>2047</math> || style="background-color: yellow" | <math>989</math> || <math>161</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || <math>9</math> || <math>265</math>
Uważny Czytelnik dostrzeże, że nie zbadaliśmy, czy spełniony jest warunek <math>\gcd (m, Q) = 1</math>. Nie musimy tego robić, bo zwracana przez funkcję <code>MethodA()</code> liczba <math>Q</math> jest względnie pierwsza z <math>m</math>. Omówimy ten problem dokładnie w&nbsp;zadaniu L45. Poniżej pokażemy, że nawet gdyby było <math>\gcd (m, Q) > 1</math>, to złożona liczba <math>m</math> nie zostanie uznana za liczbę pseudopierwszą Lucasa.
+
|-
 +
! <math>\boldsymbol{- 1}</math>
 +
| <math>4181</math> || <math>169</math> || style="background-color: yellow" | <math>119</math> || <math>9</math> || <math>9</math> || style="background-color: yellow" | <math>629</math> || <math>25</math> || <math>33</math> || <math>9</math> || style="background-color: yellow" | <math>51</math>
 +
|-
 +
! <math>\boldsymbol{1}</math>
 +
| <math>25</math> || style="background-color: red" | <math></math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>527</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>559</math> || <math>9</math> || <math>49</math>
 +
|-
 +
! <math>\boldsymbol{2}</math>
 +
| style="background-color: yellow" | <math>5459</math> || <math>9</math> || <math>2047</math> || <math>169</math> || <math>21</math> || <math>253</math> || <math>9</math> || style="background-color: yellow" | <math>15</math> || <math>9</math> || <math>49</math>  
 +
|-
 +
! <math>\boldsymbol{3}</math>
 +
| style="background-color: yellow" | <math>899</math> || style="background-color: yellow" | <math>5983</math> || <math>25</math> || <math>121</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>35</math> || <math>55</math> || <math>25</math> || style="background-color: yellow" | <math>35</math>  
 +
|-
 +
! <math>\boldsymbol{4}</math>
 +
| style="background-color: yellow" | <math>899</math> || <math>25</math> || <math>1541</math> || style="background-color: red" | <math></math> || <math>341</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>377</math> || style="background-color: yellow" | <math>209</math> || <math>9</math> || style="background-color: yellow" | <math>527</math>  
 +
|-
 +
! <math>\boldsymbol{5}</math>
 +
| <math>9</math> || style="background-color: yellow" | <math>527</math> || <math>49</math> || style="background-color: yellow" | <math>527</math> || <math>4181</math> || <math>781</math> || style="background-color: yellow" | <math>39</math> || <math>9</math> || <math>9</math> || <math>9</math>  
 +
|}
  
Zauważmy, że jeżeli <math>m</math> jest liczbą złożoną i&nbsp;ma dzielnik pierwszy <math>p < m</math>, który dzieli <math>Q</math>, to <math>p \, | \, Q</math> i <math>p \nmid P</math> (bo <math>P = 1</math>), zatem <math>p \nmid U_k</math> dla <math>k \geqslant 1</math> (zobacz L32), czyli nie może być
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
+
<span style="font-size: 90%; color:black;">FirstSLPSP(Stop) =
::<math>U_{m + 1} (1, Q) \equiv 0 \pmod{m}</math>
+
\\ najmniejsze SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
+
{
bo mielibyśmy
+
'''local'''(D, m, P, Q);
 
+
Q = -6;
::<math>U_{m + 1} (1, Q) \equiv 0 \pmod{p}</math>
+
'''while'''( Q++ <= 5,
 
+
        '''if'''( Q == 0, '''next'''() );
a to jest niemożliwe. Zatem program wykorzystujący twierdzenie L35 wykryje złożoność liczby <math>m</math>.
+
        P = 0;
 
+
        '''while'''( P++ <= 10,
Łatwo pokażemy, że nie jest możliwe, aby liczba <math>m</math> była liczbą pierwszą i&nbsp;była dzielnikiem <math>Q</math>. Jeżeli <math>m</math> jest liczbą pierwszą, to istnieje dokładnie <math>\tfrac{m - 1}{2}</math> liczb kwadratowych modulo <math>p</math> i <math>\tfrac{m - 1}{2}</math> liczb niekwadratowych modulo <math>p</math>, zatem rozpoczynając od wyrazu <math>a_2</math> możemy dojść co najwyżej do wyrazu o&nbsp;indeksie <math>k = \tfrac{m - 1}{2} + 2</math>, czyli
+
              D = P^2 - 4*Q;
 +
              '''if'''( D == 0,
 +
                  '''print'''("Q= ", Q, "  P= ", P, "  ------------------");
 +
                  '''next'''();
 +
                );
 +
              m = 3;
 +
              '''while'''( m < Stop,
 +
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q)  && !'''isprime'''(m),
 +
                          '''print'''("Q= ", Q, "  P= ", P, "  m= ", m, "  (D|m)= ", jacobi(D, m));
 +
                          '''break'''();
 +
                        );
 +
                      m = m + 2;
 +
                    );
 +
            );
 +
      );
 +
}</span>
 +
<br/>
 +
{{\Spoiler}}
  
::<math>| a_k | \leqslant m + 4</math>
+
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których <math>(D \, | \, m) = - 1</math>.
  
Skąd wynika, że
 
  
::<math>| Q | = \left| {\small\frac{1 - a_k}{4}} \right| \leqslant {\small\frac{m + 5}{4}} < m</math>
 
  
Ostatnia nierówność jest prawdziwa dla <math>m > {\small\frac{5}{3}}</math>, czyli dla wszystkich liczb pierwszych. Ponieważ <math>| Q | < m</math>, w&nbsp;przypadku gdy <math>m</math> jest liczbą pierwszą, to <math>m</math> nie może być dzielnikiem liczby <math>Q</math>.
+
<span style="font-size: 110%; font-weight: bold;">Przykład L38</span><br/>
 +
Ilość liczb SLPSP(<math>P, Q</math>) mniejszych od <math>10^9</math>
  
 
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
+
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="font-size: 110%; font-weight: bold;">Zadanie L45</span><br/>
+
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>  
Pokazać, że w&nbsp;przypadku, gdy dla kolejnych liczb <math>a_k = (- 1)^k (2 k + 1)</math> sprawdzamy, czy konsekwencją <math>(a_k \, | \, m) = 0</math> jest złożoność liczby <math>m</math>, to dla każdej liczby <math>Q</math> wyznaczonej metodą Selfridge'a jest <math>\gcd (Q, m) = 1</math>.
+
|-
 
+
! <math>\boldsymbol{- 5}</math>
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
| <math>1056</math> || <math>1231</math> || <math>1184</math> || <math>1264</math> || <math>2278</math> || <math>1284</math> || <math>1181</math> || <math>1174</math> || <math>1281</math> || <math>1429</math>  
Niech <math>m = 21</math>. Rozpoczniemy od przykładu liczb <math>a_k = (- 1)^k (2 k + 1)</math> dla <math>k = 0, 1, \ldots, m - 1</math>.
+
|-
 
+
! <math>\boldsymbol{- 4}</math>
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
+
| <math>1043</math> || <math>1165</math> || <math>2139</math> || <math>1316</math> || <math>1151</math> || <math>1079</math> || <math>1112</math> || <math>2377</math> || <math>1197</math> || <math>989</math>  
! <math>\boldsymbol{k}</math> !! <math>\boldsymbol{0}</math> !!  !!  !!  !!  !!  !!  !!  !!  !!  !! <math>\boldsymbol{(m-1)/2}</math> !!  !!  !!  !!  !!  !!  !!  !!  !!  !! <math>\boldsymbol{m-1}</math>
 
 
|-
 
|-
! <math>\boldsymbol{k}</math>  
+
! <math>\boldsymbol{- 3}</math>
| <math>0</math> || <math>1</math> || <math>2</math> || <math>3</math> || <math>4</math> || <math>5</math> || <math>6</math> || <math>7</math> || <math>8</math> || <math>9</math> || <math>10</math> || <math>11</math> || <math>12</math> || <math>13</math> || <math>14</math> || <math>15</math> || <math>16</math> || <math>17</math> || <math>18</math> || <math>19</math> || <math>20</math>
+
| <math>952</math> || <math>1514</math> || <math>1055</math> || <math>1153</math> || <math>1135</math> || <math>2057</math> || <math>998</math> || <math>1202</math> || <math>1077</math> || <math>1112</math>  
 
|-
 
|-
! <math>\boldsymbol{a_k}</math>  
+
! <math>\boldsymbol{- 2}</math>
| <math>1</math> || <math>-3</math> || <math>5</math> || <math>-7</math> || <math>9</math> || <math>-11</math> || <math>13</math> || <math>-15</math> || <math>17</math> || <math>-19</math> || <math>21</math> || <math>-23</math> || <math>25</math> || <math>-27</math> || <math>29</math> || <math>-31</math> || <math>33</math> || <math>-35</math> || <math>37</math> || <math>-39</math> || <math>41</math>
+
| <math>1282</math> || <math>1092</math> || <math>1212</math> || <math>1510</math> || <math>1155</math> || <math>1179</math> || <math>1173</math> || <math>2240</math> || <math>1089</math> || <math>2109</math>  
 
|-
 
|-
! <math>\boldsymbol{R_m(a_k)}</math>  
+
! <math>\boldsymbol{- 1}</math>
| <math>1</math> || <math>18</math> || <math>5</math> || <math>14</math> || <math>9</math> || <math>10</math> || <math>13</math> || <math>6</math> || <math>17</math> || <math>2</math> || <math>0</math> || <math>19</math> || <math>4</math> || <math>15</math> || <math>8</math> || <math>11</math> || <math>12</math> || <math>7</math> || <math>16</math> || <math>3</math> || <math>20</math>
+
| <math>1165</math> || <math>1316</math> || <math>1079</math> || <math>2377</math> || <math>989</math> || <math>1196</math> || <math>1129</math> || <math>1050</math> || <math>1055</math> || <math>1147</math>
|}
+
|-
 
+
! <math>\boldsymbol{1}</math>
Zauważmy, że modulo <math>21</math> ciąg <math>(a_k) = (1, - 3, 5, - 7, \ldots, 37, - 39, 41)</math> jest identyczny z&nbsp;ciągiem <math>(0, 1, 2, \ldots, 19, 20)</math>, a&nbsp;ciąg <math>(| a_k |)</math> to kolejne liczby nieparzyste od <math>1</math> do <math>2 m - 1</math>.
+
| <math>282485800</math> || style="background-color: red" | <math></math> || <math>2278</math> || <math>2057</math> || <math>2113</math> || <math>2266</math> || <math>4053</math> || <math>2508</math> || <math>2285</math> || <math>3083</math>
 
+
|-
 
+
! <math>\boldsymbol{2}</math>
Poniżej pokażemy, dlaczego musi być <math>\gcd (Q, m) = 1</math>, gdzie <math>Q</math> jest liczbą wyznaczoną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby <math>m</math> przy testowaniu kolejnych liczb <math>a_k</math>). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby <math>m</math>. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość <math>Q</math> na podstawie innego wyrazu ciągu <math>a_k</math> (ten symbol Jacobiego został zapisany zwykłą czcionką).
+
| <math>1776</math> || <math>449152466</math> || <math>1282</math> || <math>1316</math> || <math>1645</math> || <math>1413</math> || <math>1564</math> || <math>1595</math> || <math>1683</math> || <math>1435</math>  
 +
|-
 +
! <math>\boldsymbol{3}</math>
 +
| <math>1621</math> || <math>1553</math> || <math>282485800</math> || <math>1514</math> || <math>1530</math> || <math>1510</math> || <math>1588</math> || <math>1549</math> || <math>1468</math> || <math>1692</math>  
 +
|-
 +
! <math>\boldsymbol{4}</math>
 +
| <math>2760</math> || <math>282485800</math> || <math>2978</math> || style="background-color: red" | <math></math> || <math>2137</math> || <math>2278</math> || <math>1995</math> || <math>2057</math> || <math>2260</math> || <math>2113</math>  
 +
|-
 +
! <math>\boldsymbol{5}</math>
 +
| <math>1314</math> || <math>2392</math> || <math>1497</math> || <math>2392</math> || <math>1165</math> || <math>1268</math> || <math>1227</math> || <math>1411</math> || <math>1253</math> || <math>2377</math>  
 +
|}
  
::<math>m = 3 , \;\; (5 \, | \, 3) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
 
  
::<math>m = 5 , \;\; (5 \, | \, 5) = 0 , \;\; (- 7 \, | \, 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(5 \, | \, 5) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
 
  
::<math>m = 7 , \;\; (5 \, | \, 7) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
+
<span style="font-size: 90%; color:black;">NumOfSLPSP(Stop) =
::<math>m = 9 , \;\; </math> (liczba kwadratowa)
+
\\ ilość liczb silnie pseudopierwszych Lucasa SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
+
{
::<math>m = 11 , \;\; (- 11 \, | \, 11) = 0 , \;\; (13 \, | \, 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(- 11 \, | \, 11) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
+
'''local'''(D, m, P, Q);
 
+
Q = -6;
::<math>m = 13 , \;\; (5 \, | \, 13) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
+
'''while'''( Q++ <= 5,
 +
        '''if'''( Q == 0, '''next'''() );
 +
        P = 0;
 +
        '''while'''( P++ <= 10,
 +
              D = P^2 - 4*Q;
 +
              '''if'''( D == 0, '''print'''("Q= ", Q, "  P= ", P, "  ------------------"); '''next'''() );
 +
              s = 0;
 +
              m = 3;
 +
              '''while'''( m < Stop,
 +
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q)  &&  !'''isprime'''(m), s++ );
 +
                      m = m + 2;
 +
                    );
 +
              '''print'''("Q= ", Q, "  P= ", P, "  s= ", s);
 +
            );
 +
      );
 +
}</span>
 +
<br/>
 +
{{\Spoiler}}
  
::<math>m = 15 , \;\; \boldsymbol{(5 \, | \, 15) = 0} , \;\; (13 \, | \, 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
 
  
::<math>m = 17 , \;\; (5 \, | \, 17) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
 
  
::<math>m = 19 , \;\; (- 7 \, | \, 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L39</span><br/>
 +
Można pokazać<ref name="Arnault1"/>, że dla liczby złożonej nieparzystej <math>m \neq 9</math> i&nbsp;ustalonego <math>D</math> ilość par <math>P, Q</math> takich, że
  
::<math>m = 21 , \;\; \boldsymbol{(- 7 \, | \, 21) = 0} , \;\; (- 11 \, | \, 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
+
:* <math>0 \leqslant P, Q < m</math>
 +
:* <math>\gcd (Q, m) = 1</math>
 +
:* <math>P^2 - 4 Q \equiv D \pmod{m}</math>
 +
:* <math>m</math> jest SLPSP(<math>P, Q</math>)
  
 +
nie przekracza <math>\tfrac{4}{15} n</math>.
  
Niech <math>m \geqslant 23</math>. Wiemy, że w&nbsp;ciągu <math>(5, - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1)</math> wystąpią liczby <math>a_k</math> takie, że <math>(a_k \, | \, m) = - 1</math>. Warunek <math>(a_k \, | \, m) = 0</math> oznacza, że <math>(2 k + 1 \, | \, m) = 0</math>, bo
+
Nie dotyczy to przypadku, gdy <math>m = p (p + 2)</math> jest iloczynem liczb pierwszych bliźniaczych takich, że <math>(D \, | \, p) = - (D \, | \, p + 2) = - 1</math>, wtedy mamy słabsze oszacowanie: <math>\# (P, Q) \leqslant \tfrac{1}{2} n</math>. Zauważmy, że taką sytuację łatwo wykryć, bo w&nbsp;tym przypadku <math>m + 1 = (p + 1)^2</math> jest liczbą kwadratową.
  
::<math>(a_k \, | \, m) = ((- 1)^k (2 k + 1) \, | \, m) = ((- 1)^k \, | \, m) \cdot (2 k + 1 \, | \, m) = (- 1 \, | \, m)^k \cdot (2 k + 1 \, | \, m) = \pm (2 k + 1 \, | \, m)</math>
 
  
Jeżeli będą spełnione warunki <math>(a_k \, | \, m) = 0</math> i <math>R_m (a_k) \neq 0</math>, to liczba <math>m</math> będzie liczbą złożoną.
 
  
Wypiszmy kolejne próby dla <math>m \geqslant 23</math>. Liczba <math>r</math> jest numerem próby.
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L40</span><br/>
 +
Podobnie jak w&nbsp;przypadku liczb pseudopierwszych Lucasa LPSP(<math>P, Q</math>) tak i&nbsp;w&nbsp;przypadku liczb silnie pseudopierwszych Lucasa SLPSP(<math>P, Q</math>) możemy testować pierwszość liczby <math>m</math>, wybierając liczby <math>P, Q</math> losowo lub zastosować wybraną metodę postępowania. Przedstawiony poniżej program, to zmodyfikowany kod z uwagi L36. Teraz parametry <math>P, Q</math> są wybierane metodą Selfridge'a, a symbol Jacobiego <math>(D \, | \, m)</math> jest równy <math>- 1</math>.
 +
 
 +
<span style="font-size: 90%; color:black;">StrongLucasTest(m) =
 +
{
 +
'''local'''(a, b, c, k, P, Q, r, w, X);
 +
'''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);
 +
}</span>
 +
 
  
::<math>r = 1 , \;\; a_{r + 1} = 5</math>
 
  
::{| border="0"
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L41</span><br/>
|-style=height:2em
+
Najmniejsze liczby silnie pseudopierwsze Lucasa, które otrzymujemy po zastosowaniu metody Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math>, to
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = 1</math> || <math>5 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = 0</math> || <math>5 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = - 1 \quad</math> || <math>5 \nmid m</math> || <math>D = 5 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 
|}
 
  
::<math>r = 2 , \;\; a_{r + 1} = - 7</math>
+
::<math>5459, 5777, 10877, 16109, 18971, 22499, 24569, 25199, 40309, 58519, 75077, 97439, \ldots</math>
  
::{| border="0"
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
|-style=height:2em
+
<span style="font-size: 90%; color:black;">'''forstep'''(k=1, 10^5, 2, '''if'''( StrongLucasTest(k) && !'''isprime'''(k), '''print'''(k)) )</span>
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 1</math> || <math>7 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
+
<br/>
|-style=height:2em
+
{{\Spoiler}}
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 0</math> || <math>7 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = - 1 \quad</math> || <math>7 \nmid m</math> || <math>D = -7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 
|}
 
  
::<math>r = 3</math>, <math>a_{r + 1} = 9</math>
 
  
::{| border="0"
+
Tabela przedstawia ilość takich liczb nie większych od <math>10^n</math>
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 1</math> || <math>3 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 0</math> || <math>3 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) \neq - 1 \quad</math> || - - - - || bo <math>9</math> jest liczbą kwadratową
 
|}
 
  
 
+
::{| class="wikitable plainlinks" style="font-size: 90%; text-align: right; margin-right: auto;"
Po wykonaniu trzech prób niezakończonych sukcesem (tzn. wykryciem złożoności <math>m</math> lub ustaleniem wartości liczb <math>D</math> i <math>Q</math>) wiemy, że <math>m</math> nie jest podzielna przez żadną z&nbsp;liczb pierwszych <math>p = 3, 5, 7</math>.
+
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math>
 
+
|-
::<math>r</math>-ta próba, gdzie <math>r \geqslant 4 , \;\;</math> wyraz <math>a_{r + 1}</math>
+
| #SLPSP <math>< 10^n</math> (metoda Selfridge'a) || <math>0</math> || <math>2</math> || <math>12</math> || <math>58</math> || <math>178</math> || <math>505</math> || <math>1415</math>
 
 
::{| border="0"  
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = 1</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = 0</math> || A. jeżeli <math>m \, | \, a_{r + 1}</math><sup>( * )</sup><br/>B. jeżeli <math>m \nmid a_{r + 1}</math> || A. przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math> <br/> B. <math>a_{r + 1} \, | \, m</math><sup>( ** )</sup>, '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = - 1 \quad</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || <math>D = a_{r + 1}</math>, <math>Q = {\small\frac{1 - a_{r + 1}}{4}}</math>, '''koniec'''
 
 
|}
 
|}
  
<sup>( * )</sup> jest to możliwe tylko dla <math>a_{r + 1} = a_{(m - 1) / 2} = m</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 +
<span style="font-size: 90%; color:black;">'''for'''(n=3, 9, s=0; '''forstep'''(k = 1, 10^n, 2, '''if'''( StrongLucasTest(k) && !'''isprime'''(k), s++ ) ); '''print'''("n=", n, "  ", s) )</span>
 +
<br/>
 +
{{\Spoiler}}
  
<sup>( ** )</sup> zauważmy, że jeżeli <math>m \nmid a_{r + 1}</math>, to <math>\gcd (a_{r + 1}, m) = | a_{r + 1} |</math>, bo gdyby liczba <math>| a_{r + 1} |</math> była liczbą złożoną, to żaden z&nbsp;jej dzielników pierwszych nie dzieliłby liczby <math>m</math>
 
  
  
Jeżeli nie została wykryta złożoność liczby <math>m</math>, to żadna z&nbsp;liczb pierwszych <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m</math>. Zatem <math>\gcd (Q, m) > 1</math> może być tylko w&nbsp;przypadku, gdy pewna liczba pierwsza <math>q \geqslant 2 r + 5</math> będzie wspólnym dzielnikiem liczb <math>Q</math> i <math>m</math>, ale jest to niemożliwe, bo
 
  
::<math>| Q | = \left| {\small\frac{1 - a_{r + 1}}{4}} \right| \leqslant {\small\frac{| a_{r + 1} | + 1}{4}} = {\small\frac{2 r + 4}{4}} < 2 r + 5 \leqslant q</math>
 
  
Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich <math>r</math> naturalnych.<br/>
+
== Test BPSW ==
&#9633;
 
{{\Spoiler}}
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga L42</span><br/>
 +
Jest <math>488</math> liczb SPSP(<math>2</math>) mniejszych od <math>10^8</math> i są 582 liczby SPSP(<math>3</math>) mniejsze od <math>10^8</math> (zobacz K20). Ale jest aż <math>21</math> liczb mniejszych od <math>10^8</math> silnie pseudopierwszych jednocześnie względem podstaw <math>2</math> i <math>3</math>:
  
 +
<math>1373653, 1530787, 1987021, 2284453, 3116107, 5173601, 6787327, 11541307, 13694761, 15978007, 16070429,</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L46</span><br/>
+
<math>16879501, 25326001, 27509653, 27664033, 28527049, 54029741, 61832377, 66096253, 74927161, 80375707</math>
Zmodyfikujmy metodę Selfridge'a w&nbsp;taki sposób, że będziemy rozpoczynali próby nie od wyrazu <math>a_2 = 5</math>, ale od wyrazu <math>a_3 = - 7</math>. Pokazać, że w&nbsp;przypadku, gdy dla kolejnych liczb <math>a_k = (- 1)^k (2 k + 1)</math> sprawdzamy, czy konsekwencją <math>(a_k \, | \, m) = 0</math> jest złożoność liczby <math>m</math>, to dla każdej liczby <math>Q</math> wyznaczonej tak zmodyfikowaną metodą Selfridge'a jest <math>\gcd (Q, m) = 1</math>.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
Poniżej pokażemy, dlaczego musi być <math>\gcd (Q, m) = 1</math>, gdzie <math>Q</math> jest liczbą wyznaczoną zmodyfikowaną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby <math>m</math> przy testowaniu kolejnych liczb <math>a_k</math>). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby <math>m</math>. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość <math>Q</math> na podstawie innego wyrazu ciągu <math>a_k</math> (ten symbol Jacobiego został zapisany zwykłą czcionką).
+
<span style="font-size: 90%; color:black;">'''forstep'''(m=3, 10^8, 2, '''if'''( isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 2)  &&  isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 3)  &&  !'''isprime'''(m), '''print'''("m=", m) ) )</span>
 +
<br/>
 +
{{\Spoiler}}
  
::<math>m = 3 , \;\; (- 7 \, | \, 3) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
Widzimy, że prawdopodobieństwo błędnego rozpoznania pierwszości w&nbsp;przypadku liczb mniejszych od <math>10^8</math> dla podstaw <math>2</math> i <math>3</math> jest rzędu kilku milionowych. Gdyby prawdopodobieństwa błędnego rozpoznania pierwszości w&nbsp;przypadku podstaw <math>2</math> i <math>3</math> były niezależne, to spodziewalibyśmy się, że nie będzie wcale liczb mniejszych od <math>10^8</math> silnie pseudopierwszych jednocześnie względem podstaw <math>2</math> i <math>3</math>, bo prawdopodobieństwo takiego zdarzenia byłoby równe kilkudziesięciu bilonowym. Ale tak nie jest.
  
::<math>m = 5 , \;\; (- 7 \, | \, 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
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.
  
::<math>m = 7 , \;\; (- 7 \, | \, 7) = 0 , \;\; (- 11 \, | \, 7) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1</math> (zauważmy, że <math>(- 7 \, | \, 7) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
+
Połączenie znanych nam już testów prowadzi do prostego programu
  
::<math>m = 9 , \;\; </math> (liczba kwadratowa)
+
<span style="font-size: 90%; color:black;">BPSWtest(m) =
 +
{
 +
'''forprime'''(p = 2, 1000, '''if'''( m % p > 0, '''next'''() ); '''if'''( m == p, '''return'''(1), '''return'''(0) ));
 +
'''if'''( !isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 2), '''return'''(0) );
 +
'''if'''( !StrongLucasTest(m), '''return'''(0), '''return'''(1) );
 +
}</span>
  
::<math>m = 11 , \;\; (- 11 \, | \, 11) = 0 , \;\; (13 \, | \, 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(- 11 \, | \, 11) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
 
  
::<math>m = 13 , \;\; (- 7 \, | \, 13) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
 
  
::<math>m = 15 , \;\; \boldsymbol{(9 \, | \, 15) = 0} , \;\; (13 \, | \, 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
+
Funkcja <code>BPSWtest(m)</code> kolejno sprawdza:
  
::<math>m = 17 , \;\; (- 7 \, | \, 17) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
:* czy liczba <math>m</math> jest podzielna przez niewielkie liczby pierwsze (w naszym przypadku mniejsze od <math>1000</math>); jeśli tak, to sprawdza, czy <math>m</math> jest liczbą pierwszą, czy złożoną i&nbsp;zwraca odpowiednio <math>1</math> lub <math>0</math>
 +
:* czy liczba <math>m</math> przechodzi test Millera-Rabina dla podstawy <math>2</math>; jeśli nie, to zwraca <math>0</math>
 +
:* czy liczba <math>m</math> przechodzi silny test Lucasa dla parametrów <math>P</math> i <math>Q</math>, które wybieramy metodą Selfridge'a; jeśli nie, to zwraca <math>0</math>, w&nbsp;przeciwnym wypadku zwraca <math>1</math>
  
::<math>m = 19 , \;\; (- 7 \, | \, 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
 
  
::<math>m = 21 , \;\; \boldsymbol{(- 7 \, | \, 21) = 0} , \;\; (- 11 \, | \, 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
+
Test w&nbsp;dokładnie takiej postaci zaproponowali Robert Baillie i&nbsp;Samuel Wagstaff<ref name="BaillieWagstaff1"/>. Nazwa testu to akronim, utworzony od pierwszych liter nazwisk Roberta Bailliego, Carla Pomerance'a, Johna Selfridge'a i&nbsp;Samuela Wagstaffa.
  
 +
Nie jest znany żaden przykład liczby złożonej <math>m</math>, którą test BPSW<ref name="BPSW1"/><ref name="BPSW2"/> identyfikowałby jako pierwszą i&nbsp;z&nbsp;pewnością nie ma takich liczb dla <math>m < 2^{64} \approx 1.844 \cdot 10^{19}</math>. Warto przypomnieć: potrzebowaliśmy siedmiu testów Millera-Rabina (dla podstaw <math>2, 3, 5, 7, 11, 13, 17</math>), aby mieć pewność, że dowolna liczba <math>m < 3.41 \cdot 10^{14}</math> jest pierwsza (zobacz K21).
  
Niech <math>m \geqslant 23</math>. Wiemy, że w&nbsp;ciągu <math>( - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1)</math> wystąpią liczby <math>a_k</math> takie, że <math>(a_k \, | \, m) = - 1</math>. Warunek <math>(a_k \, | \, m) = 0</math> oznacza, że <math>(2 k + 1 \, | \, m) = 0</math>, bo
 
  
::<math>(a_k \, | \, m) = ((- 1)^k (2 k + 1) \, | \, m) = ((- 1)^k \, | \, m) \cdot (2 k + 1 \, | \, m) = (- 1 \, | \, m)^k \cdot (2 k + 1 \, | \, m) = \pm (2 k + 1 \, | \, m)</math>
 
  
Jeżeli będą spełnione warunki <math>(a_k \, | \, m) = 0</math> i <math>R_m (a_k) \neq 0</math>, to liczba <math>m</math> będzie liczbą złożoną.
 
  
Wypiszmy kolejne próby dla <math>m \geqslant 23</math>. Liczba <math>r</math> jest numerem próby.
 
  
::<math>r = 1 , \;\; a_{r + 2} = - 7</math>
+
== Uzupełnienia ==
 +
 
 +
&nbsp;
 +
 
 +
=== <span style="border-bottom:1px solid #000;">Pewne własności współczynników dwumianowych</span> ===
  
::{| border="0"
+
&nbsp;
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 1</math> || <math>7 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 0</math> || <math>7 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = - 1 \quad</math> || <math>7 \nmid m</math> || <math>D = - 7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 
|}
 
  
::<math>r = 2 , \;\; a_{r + 2} = 9</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L43</span><br/>
 +
Jeżeli <math>p</math> jest liczbą pierwszą, to
  
::{| border="0"
+
::<math>\binom{p}{k} \equiv 0 \pmod{p}</math>
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 1</math> || <math>3 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 0</math> || <math>3 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) \neq - 1 \quad</math> || - - - - || bo <math>9</math> jest liczbą kwadratową
 
|}
 
  
::<math>r = 3 , \;\; a_{r + 2} = - 11</math>
+
dla każdego <math>k \in [1, p - 1]</math>.
  
::{| border="0"
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
|-style=height:2em
+
Łatwo zauważamy, że dla <math>k \in [1, p - 1]</math> liczba pierwsza <math>p</math> dzieli licznik, ale nie dzieli mianownika współczynnika dwumianowego
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = 1</math> || <math>11 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = 0</math> || <math>11 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = - 1 \quad</math> || <math>11 \nmid m</math> || <math>D = - 11 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec''' (bo liczby złożone <math>m = 3 k</math> zostały usunięte w&nbsp;poprzedniej próbie, <math>r = 2</math>)
 
|}
 
  
::<math>r = 4 , \;\; a_{r + 2} = 13</math>
+
::<math>\binom{p}{k} = {\small\frac{p!}{k! \cdot (p - k)!}}</math>
  
::{| border="0"
+
zatem <math>p \biggr\rvert \binom{p}{k}</math>. Co należało pokazać.<br/>
|-style=height:2em
+
&#9633;
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = 1</math> || <math>13 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
+
{{\Spoiler}}
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = 0</math> || <math>13 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = - 1 \quad</math> || <math>13 \nmid m</math> || <math>D = 13 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec''' (bo liczby złożone <math>m = 3 k</math> zostały usunięte w&nbsp;próbie o&nbsp;numerze <math>r = 2</math>)
 
|}
 
  
::<math>r = 5 , \;\; a_{r + 2} = - 15</math>
 
  
::{| border="0"
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = 1</math> || <math>5 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = 0</math> || <math>5 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = - 1 \quad</math> || <math>5 \nmid m</math> || <math>D = - 15 , \;\; Q = 4 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 
|}
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L44</span><br/>
 +
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą, to
  
Po wykonaniu pięciu prób niezakończonych sukcesem (tzn. wykryciem złożoności <math>m</math> lub ustaleniem wartości liczb <math>D</math> i <math>Q</math>) wiemy, że <math>m</math> nie jest podzielna przez żadną z&nbsp;liczb pierwszych <math>p = 3, 5, 7, 11, 13</math>.
+
::<math>\binom{p + 1}{k} \equiv 0 \pmod{p}</math>
  
::<math>r</math>-ta próba, gdzie <math>r \geqslant 6 , \;\;</math> wyraz <math>a_{r + 2}</math>
+
dla każdego <math>k \in [2, p - 1]</math>.
  
::{| border="0"
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
|-style=height:2em
+
Jeżeli <math>k \in [2, p - 1]</math>, to modulo <math>p</math> dostajemy
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = 1</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = 0</math> || A. jeżeli <math>m \, | \, a_{r + 2}</math><sup>( * )</sup><br/>B. jeżeli <math>m \nmid a_{r + 2}</math> || A. przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math> <br/> B. <math>a_{r + 1} \, | \, m</math><sup>( ** )</sup>, '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = - 1 \quad</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || <math>D = a_{r + 2}</math>, <math>Q = {\small\frac{1 - a_{r + 2}}{4}}</math>, '''koniec'''
 
|}
 
  
<sup>( * )</sup> jest to możliwe tylko dla <math>a_{r + 2} = a_{(m - 1) / 2} = m</math>
+
::<math>\binom{p + 1}{k} = \binom{p}{k} + \binom{p}{k - 1} \equiv 0 \pmod{p}</math>
  
<sup>( ** )</sup> zauważmy, że jeżeli <math>m \nmid a_{r + 2}</math>, to <math>\gcd (a_{r + 2}, m) = | a_{r + 2} |</math>, bo gdyby liczba <math>| a_{r + 2} |</math> była liczbą złożoną, to żaden z&nbsp;jej dzielników pierwszych nie dzieliłby liczby <math>m</math>
+
Bo liczba pierwsza <math>p</math> dzieli licznik, ale nie dzieli mianownika współczynników dwumianowych po prawej stronie. Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
  
Jeżeli nie została wykryta złożoność liczby <math>m</math>, to żadna z&nbsp;liczb pierwszych <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m</math>. Zatem <math>\gcd (Q, m) > 1</math> może być tylko w&nbsp;przypadku, gdy pewna liczba pierwsza <math>q \geqslant 2 r + 7</math> będzie wspólnym dzielnikiem liczb <math>Q</math> i <math>m</math>, ale jest to niemożliwe, bo
 
  
::<math>| Q | = \left| {\small\frac{1 - a_{r + 2}}{4}} \right| \leqslant {\small\frac{| a_{r + 2} | + 1}{4}} = {\small\frac{2 r + 6}{4}} < 2 r + 7 \leqslant q</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L45</span><br/>
 +
Jeżeli <math>p</math> jest liczbą pierwszą, to
  
Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich <math>r</math> naturalnych.<br/>
+
::<math>\binom{p - 1}{k} \equiv (- 1)^k \pmod{p}</math>
&#9633;
 
{{\Spoiler}}
 
  
 +
dla każdego <math>k \in [0, p - 1]</math>.
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Łatwo sprawdzamy, że twierdzenie jest prawdziwe dla liczby pierwszej parzystej <math>p = 2</math>. Załóżmy, że <math>p</math> jest liczbą pierwszą nieparzystą. Równie łatwo sprawdzamy, że twierdzenie jest prawdziwe dla <math>k = 0</math> i <math>k = 1</math>. Zauważmy, że dla <math>k \in [1, p - 1]</math> jest
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L47</span><br/>
+
::<math>\binom{p - 1}{k} = {\small\frac{(p - 1) !}{k! (p - 1 - k) !}} = {\small\frac{p - k}{k}} \cdot {\small\frac{(p - 1) !}{(k - 1) ! (p - k) !}} = {\small\frac{p - k}{k}} \cdot \binom{p - 1}{k - 1} = {\small\frac{p}{k}} \cdot \binom{p - 1}{k - 1} - \binom{p - 1}{k - 1}</math>
Przyjmując metodę Selfridge'a wyboru parametrów <math>P, Q</math> dla testu Lucasa, możemy łatwo napisać odpowiedni program w&nbsp;PARI/GP testujący pierwszość liczb
 
  
<span style="font-size: 90%; color:black;">LucasTest(m) =
+
Ponieważ współczynniki dwumianowe są liczbami całkowitymi, a&nbsp;liczba <math>k \in [2, p - 1]</math> nie dzieli liczby pierwszej nieparzystej <math>p</math>, to <math>k</math> musi dzielić liczbę <math>\binom{p - 1}{k - 1}</math>. Zatem dla <math>k \in [2, p - 1]</math> modulo <math>p</math> mamy
{
 
'''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) );
 
}</span>
 
  
 +
::<math>\binom{p - 1}{k} \equiv - \binom{p - 1}{k - 1}\pmod{p}</math>
  
 +
Skąd otrzymujemy
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L48</span><br/>
+
::<math>\binom{p - 1}{k} \equiv (- 1)^1 \binom{p - 1}{k - 1} \equiv (- 1)^2 \binom{p - 1}{k - 2} \equiv \ldots \equiv (- 1)^{k - 2} \binom{p - 1}{2} \equiv (- 1)^{k - 1} \binom{p - 1}{1} \equiv (- 1)^k \pmod{p}</math>
Najmniejsze liczby pseudopierwsze Lucasa, które pojawiają się przy zastosowaniu metody Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math>, to
 
  
::<math>323, 377, 1159, 1829, 3827, 5459, 5777, 9071, 9179, 10877, 11419, 11663, 13919, 14839, 16109, 16211, 18407, 18971, 19043, 22499, \ldots</math>
+
Co należało pokazać.<br/>
 
+
&#9633;
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">'''forstep'''(k=1, 3*10^4, 2, '''if'''( LucasTest(k) && !'''isprime'''(k), '''print'''(k)) )</span>
 
<br/>
 
 
{{\Spoiler}}
 
{{\Spoiler}}
  
  
  
Tabela przedstawia ilość takich liczb nie większych od <math>10^n</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L46</span><br/>
 +
Dla współczynników dwumianowych prawdziwe są następujące wzory
  
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
+
::<math>\underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1}</math>
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math>
 
|-
 
| #LPSP <math>< 10^n</math> (metoda Selfridge'a) || <math>2</math> || <math>9</math> || <math>57</math> || <math>219</math> || <math>659</math> || <math>1911</math> || <math>5485</math>
 
|}
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
+
::<math>\underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1}</math>
<span style="font-size: 90%; color:black;">'''for'''(n=3, 9, s=0; '''forstep'''(k = 1, 10^n, 2, '''if'''( LucasTest(k) && !'''isprime'''(k), s++ ) ); '''print'''("n= ", n, "  ", s) )</span>
+
 
<br/>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
{{\Spoiler}}
+
Ze wzoru dwumianowego
 +
 
 +
::<math>(a + b)^n = \sum_{k = 0}^{n} \binom{n}{k} a^{n - k} b^k</math>
  
 +
z łatwością otrzymujemy
  
 +
::<math>(1 + 1)^n = \sum_{k = 0}^{n} \binom{n}{k} = 2^n</math>
  
 +
::<math>(1 - 1)^n = \sum_{k = 0}^{n} (- 1)^k \binom{n}{k} = 0</math>
  
 +
Obliczając sumę i&nbsp;różnicę powyższych wzorów mamy
  
== Liczby silnie pseudopierwsze Lucasa ==
+
::<math>\sum_{k = 0}^{n} \binom{n}{k} (1 + (- 1)^k) = 2 \underset{k \; \text{parzyste}}{\sum^n_{k = 0}} \binom{n}{k} = 2^n</math>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L49</span><br/>
+
::<math>\sum_{k = 0}^{n} \binom{n}{k} (1 - (- 1)^k) = 2 \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^n</math>
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą taką, że <math>\gcd (p, Q D) = 1</math> oraz <math>p - (D \, | \, p) = 2^r w</math>, gdzie <math>w</math> jest liczbą nieparzystą, to spełniony jest dokładnie jeden z&nbsp;warunków
 
  
::<math>U_w \equiv 0 \pmod{p}</math>
+
Skąd natychmiast wynika
  
lub
+
::<math>\underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1}</math>
  
::<math>V_{2^k w} \equiv 0 \pmod{p} \qquad</math> dla pewnego <math>k \in [0, r - 1]</math>
+
::<math>\underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1}</math>
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
Co należało pokazać.<br/>
Wiemy (zobacz L35), że jeżeli <math>p</math> jest liczbą pierwszą nieparzystą taką, że <math>\gcd (p, Q D) = 1</math>, to <math>p \, | \, U_{p - (D \, | \, p)}</math>. Z&nbsp;założenia jest <math>p - (D \, | \, p) = 2^r w</math>, zatem <math>p \, | \, U_{2^r w}</math>. Ponieważ założyliśmy, że <math>p \nmid Q</math> i <math>p \nmid D</math>, to ze wzoru <math>V^2_n - D U^2_n = 4 Q^n</math> (zobacz L28 p.14) wynika natychmiast, że <math>p</math> nie może dzielić jednocześnie liczb <math>U_n</math> i <math>V_n</math>.
+
&#9633;
 +
{{\Spoiler}}
  
Korzystając ze wzoru <math>U_{2 n} = U_n V_n</math> (zobacz L28 p.11), otrzymujemy
 
  
::{| border="0"
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2^r w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2^{r - 1} w} \cdot V_{2^{r - 1} w} \quad</math> || Jeżeli <math>p \, | \, V_{2^{r - 1} w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2^{r - 1} w}</math>, to <math>p \, | \, U_{2^{r - 1} w}</math>.
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2^{r - 1} w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2^{r - 2} w} \cdot V_{2^{r - 2} w} \quad</math> || Jeżeli <math>p \, | \, V_{2^{r - 2} w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2^{r - 2} w}</math>, to <math>p \, | \, U_{2^{r - 2} w}</math>.
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>.................</math> ||
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{4 w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2 w} \cdot V_{2 w}</math> || Jeżeli <math>p \, | \, V_{2 w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2 w}</math>, to <math>p \, | \, U_{2 w}</math>.
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2 w} \;\; \Longleftrightarrow \;\; p \, | \, U_w \cdot V_w</math> || Jeżeli <math>p \, | \, V_w</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_w</math>, to <math>p \, | \, U_w</math>.
 
|}
 
  
Z powyższego wynika, że musi być spełniony jeden z wypisanych w twierdzeniu warunków.
 
  
  
Zauważmy teraz, że jeżeli liczba pierwsza <math>p</math> dzieli <math>V_w</math>, to <math>p \nmid U_w</math>, bo <math>p</math> nie może jednocześnie być dzielnikiem liczb <math>U_w</math> i <math>V_w</math>.
+
=== <span style="border-bottom:1px solid #000;">Funkcje <span style="font-size: 95%; background-color: #f8f9fa"><tt>digits(m, b)</tt></span> oraz <span style="font-size: 95%; background-color: #f8f9fa"><tt>issquare(m)</tt></span></span> ===
  
Zauważmy też, że jeżeli dla pewnego <math>k \in [1, r - 1]</math> liczba pierwsza <math>p</math> dzieli <math>V_{2^k w}</math>, to <math>p</math> nie dzieli żadnej liczby <math>V_{2^j w}</math> dla <math>j \in [0, k - 1] \;\; \text{i} \;\; p \nmid U_w</math>. Istotnie:
+
&nbsp;
  
::{| border="0"
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L47</span><br/>
|-style=height:3em
+
W funkcji <code>modLucas()</code> wykorzystaliśmy zaimplementowaną w&nbsp;PARI/GP funkcję
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \, | \, V_{2^k w}</math>, to <math>p \nmid U_{2^k w} \;\; \text{i} \;\; U_{2^k w} = U_{2^{k - 1} w} V_{2^{k - 1} w}</math>, zatem <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2^{k - 1} w} \;\; \text{i} \;\; V_{2^{k - 1} w}</math>
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{2^{k - 1} w} \;\; \text{i} \;\; U_{2^{k - 1} w} = U_{2^{k - 2} w} V_{2^{k - 2} w}</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2^{k - 2} w} \;\; \text{i} \;\; V_{2^{k - 2} w}</math>
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>.................</math> ||
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{4 w} \;\; \text{i} \;\; U_{4 w} = U_{2 w} V_{2 w}</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2 w} \;\; \text{i} \;\; V_{2 w}</math>
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{2 w} \;\; \text{i} \;\; U_{2 w} = U_w V_w</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_w \;\; \text{i} \;\; V_w</math>
 
|}
 
  
 +
<code>digits(m, b)</code> – zwraca wektor cyfr liczby <math>| m |</math> w&nbsp;systemie liczbowym o&nbsp;podstawie <math>b</math>
  
Co dowodzi, że spełniony jest dokładnie jeden z <math>r + 1</math> warunków:
+
W naszym przypadku potrzebowaliśmy uzyskać wektor cyfr liczby <math>m</math> w&nbsp;układzie dwójkowym, czyli funkcję <code>digits(m, 2)</code> . Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Zauważmy, że do zapisania liczby <math>m \geqslant 1</math> potrzebujemy <math>\log_2 m + 1</math> cyfr. Zastępując funkcję <math>\log_2 m</math> funkcją <math>\left \lfloor \tfrac{\log m}{\log 2} \right \rfloor</math> musimy liczyć się z&nbsp;możliwym błędem zaokrąglenia – dlatego w&nbsp;programie deklarujemy wektor <code>V</code> o&nbsp;długości <code>floor( log(m)/log(2) ) + 2</code>. Zwracany wektor <code>W</code> ma już prawidłową długość.
  
::<math>U_w \equiv 0 \pmod{p}</math>
+
<span style="font-size: 90%; color:black;">Dec2Bin(m) =
 
+
\\ zwraca wektor cyfr liczby m w układzie dwójkowym
::<math>V_{2^k w} \equiv 0 \pmod{p} \qquad</math> gdzie <math>k \in [0, r - 1]</math>
+
{
 
+
'''local'''(i, k, V, W);
Co należało pokazać.<br/>
+
'''if'''( m == 0, '''return'''([0]) );
&#9633;
+
V = '''vector'''( '''floor'''( '''log'''(m)/'''log'''(2) ) + 2 ); \\ potrzeba floor( log(m)/log(2) ) + 1, ale błąd zaokrąglenia może zepsuć wynik
{{\Spoiler}}
+
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);
 +
}
  
  
  
Konsekwentnie definiujemy liczby pseudopierwsze<br/>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga L48</span><br/>
<span style="font-size: 110%; font-weight: bold;">Definicja L50</span><br/>
 
Powiemy, że liczba złożona nieparzysta <math>m</math> jest liczbą silnie pseudopierwszą Lucasa (SLPSP) dla parametrów <math>P</math> i <math>Q</math>, jeżeli <math>\gcd (m, Q D) = 1</math> oraz <math>m - (D \, | \, m) = 2^r w</math>, gdzie <math>w</math> jest liczbą nieparzystą i&nbsp;spełniony jest jeden z&nbsp;warunków
 
 
 
::<math>U_w \equiv 0 \pmod{m}</math>
 
 
 
lub
 
 
 
::<math>V_{2^k w} \equiv 0 \pmod{m} \;</math> dla pewnego <math>k \in [0, r - 1]</math>
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L51</span><br/>
 
Każda liczba SLPSP(<math>P, Q</math>) jest LPSP(<math>P, Q</math>). Korzystając ze zdefiniowanych wcześniej funkcji: <code>modPower(a, n, m)</code>, <code>jacobi(a, n)</code> i <code>modLucas(n, P, Q, m)</code> (zobacz K3, L6, L30), możemy napisać prosty program, który sprawdza, czy liczba <math>m</math> spełnia jeden z&nbsp;warunków podanych w&nbsp;twierdzeniu L49.
 
 
 
<span style="font-size: 90%; color: black;">isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(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);
 
}</span>
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Przykład L52</span><br/>
 
Poniższa tabela zawiera najmniejsze liczby silnie pseudopierwsze Lucasa dla różnych parametrów <math>P</math> i <math>Q</math>
 
 
 
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
 
|-
 
! <math>\boldsymbol{- 5}</math>
 
| <math>253</math> || <math>121</math> || style="background-color: yellow" | <math>143</math> || <math>781</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>299</math> || <math>121</math> || style="background-color: yellow" | <math>407</math> || <math>9</math> || style="background-color: yellow" | <math>143</math>
 
|-
 
! <math>\boldsymbol{- 4}</math>
 
| <math>9</math> || <math>4181</math> || <math>341</math> || <math>169</math> || <math>33</math> || style="background-color: yellow" | <math>119</math> || <math>57</math> || <math>9</math> || <math>9</math> || <math>9</math>
 
|-
 
! <math>\boldsymbol{- 3}</math>
 
| style="background-color: yellow" | <math>799</math> || <math>121</math> || style="background-color: yellow" | <math>527</math> || <math>25</math> || <math>85</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>55</math> || style="background-color: yellow" | <math>35</math> || <math>169</math> || <math>529</math>
 
|-
 
! <math>\boldsymbol{- 2}</math>
 
| <math>2047</math> || style="background-color: yellow" | <math>989</math> || <math>161</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || <math>9</math> || <math>265</math>
 
|-
 
! <math>\boldsymbol{- 1}</math>
 
| <math>4181</math> || <math>169</math> || style="background-color: yellow" | <math>119</math> || <math>9</math> || <math>9</math> || style="background-color: yellow" | <math>629</math> || <math>25</math> || <math>33</math> || <math>9</math> || style="background-color: yellow" | <math>51</math>
 
|-
 
! <math>\boldsymbol{1}</math>
 
| <math>25</math> || style="background-color: red" | <math></math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>527</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>559</math> || <math>9</math> || <math>49</math>
 
|-
 
! <math>\boldsymbol{2}</math>
 
| style="background-color: yellow" | <math>5459</math> || <math>9</math> || <math>2047</math> || <math>169</math> || <math>21</math> || <math>253</math> || <math>9</math> || style="background-color: yellow" | <math>15</math> || <math>9</math> || <math>49</math>
 
|-
 
! <math>\boldsymbol{3}</math>
 
| style="background-color: yellow" | <math>899</math> || style="background-color: yellow" | <math>5983</math> || <math>25</math> || <math>121</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>35</math> || <math>55</math> || <math>25</math> || style="background-color: yellow" | <math>35</math>
 
|-
 
! <math>\boldsymbol{4}</math>
 
| style="background-color: yellow" | <math>899</math> || <math>25</math> || <math>1541</math> || style="background-color: red" | <math></math> || <math>341</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>377</math> || style="background-color: yellow" | <math>209</math> || <math>9</math> || style="background-color: yellow" | <math>527</math>
 
|-
 
! <math>\boldsymbol{5}</math>
 
| <math>9</math> || style="background-color: yellow" | <math>527</math> || <math>49</math> || style="background-color: yellow" | <math>527</math> || <math>4181</math> || <math>781</math> || style="background-color: yellow" | <math>39</math> || <math>9</math> || <math>9</math> || <math>9</math>
 
|}
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">FirstSLPSP(Stop) =
 
\\ najmniejsze SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
{
 
'''local'''(D, m, P, Q);
 
Q = -6;
 
'''while'''( Q++ <= 5,
 
        '''if'''( Q == 0, '''next'''() );
 
        P = 0;
 
        '''while'''( P++ <= 10,
 
              D = P^2 - 4*Q;
 
              '''if'''( D == 0,
 
                  '''print'''("Q= ", Q, "  P= ", P, "  ------------------");
 
                  '''next'''();
 
                );
 
              m = 3;
 
              '''while'''( m < Stop,
 
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q)  &&  !'''isprime'''(m),
 
                          '''print'''("Q= ", Q, "  P= ", P, "  m= ", m, "  (D|m)= ", jacobi(D, m));
 
                          '''break'''();
 
                        );
 
                      m = m + 2;
 
                    );
 
            );
 
      );
 
}</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których <math>(D \, | \, m) = - 1</math>.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Przykład L53</span><br/>
 
Ilość liczb SLPSP(<math>P, Q</math>) mniejszych od <math>10^9</math>
 
 
 
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
 
|-
 
! <math>\boldsymbol{- 5}</math>
 
| <math>1056</math> || <math>1231</math> || <math>1184</math> || <math>1264</math> || <math>2278</math> || <math>1284</math> || <math>1181</math> || <math>1174</math> || <math>1281</math> || <math>1429</math>
 
|-
 
! <math>\boldsymbol{- 4}</math>
 
| <math>1043</math> || <math>1165</math> || <math>2139</math> || <math>1316</math> || <math>1151</math> || <math>1079</math> || <math>1112</math> || <math>2377</math> || <math>1197</math> || <math>989</math>
 
|-
 
! <math>\boldsymbol{- 3}</math>
 
| <math>952</math> || <math>1514</math> || <math>1055</math> || <math>1153</math> || <math>1135</math> || <math>2057</math> || <math>998</math> || <math>1202</math> || <math>1077</math> || <math>1112</math>
 
|-
 
! <math>\boldsymbol{- 2}</math>
 
| <math>1282</math> || <math>1092</math> || <math>1212</math> || <math>1510</math> || <math>1155</math> || <math>1179</math> || <math>1173</math> || <math>2240</math> || <math>1089</math> || <math>2109</math>
 
|-
 
! <math>\boldsymbol{- 1}</math>
 
| <math>1165</math> || <math>1316</math> || <math>1079</math> || <math>2377</math> || <math>989</math> || <math>1196</math> || <math>1129</math> || <math>1050</math> || <math>1055</math> || <math>1147</math>
 
|-
 
! <math>\boldsymbol{1}</math>
 
| <math>282485800</math> || style="background-color: red" | <math></math> || <math>2278</math> || <math>2057</math> || <math>2113</math> || <math>2266</math> || <math>4053</math> || <math>2508</math> || <math>2285</math> || <math>3083</math>
 
|-
 
! <math>\boldsymbol{2}</math>
 
| <math>1776</math> || <math>449152466</math> || <math>1282</math> || <math>1316</math> || <math>1645</math> || <math>1413</math> || <math>1564</math> || <math>1595</math> || <math>1683</math> || <math>1435</math>
 
|-
 
! <math>\boldsymbol{3}</math>
 
| <math>1621</math> || <math>1553</math> || <math>282485800</math> || <math>1514</math> || <math>1530</math> || <math>1510</math> || <math>1588</math> || <math>1549</math> || <math>1468</math> || <math>1692</math>
 
|-
 
! <math>\boldsymbol{4}</math>
 
| <math>2760</math> || <math>282485800</math> || <math>2978</math> || style="background-color: red" | <math></math> || <math>2137</math> || <math>2278</math> || <math>1995</math> || <math>2057</math> || <math>2260</math> || <math>2113</math>
 
|-
 
! <math>\boldsymbol{5}</math>
 
| <math>1314</math> || <math>2392</math> || <math>1497</math> || <math>2392</math> || <math>1165</math> || <math>1268</math> || <math>1227</math> || <math>1411</math> || <math>1253</math> || <math>2377</math>
 
|}
 
 
 
 
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">NumOfSLPSP(Stop) =
 
\\ ilość liczb silnie pseudopierwszych Lucasa SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
{
 
'''local'''(D, m, P, Q);
 
Q = -6;
 
'''while'''( Q++ <= 5,
 
        '''if'''( Q == 0, '''next'''() );
 
        P = 0;
 
        '''while'''( P++ <= 10,
 
              D = P^2 - 4*Q;
 
              '''if'''( D == 0, '''print'''("Q= ", Q, "  P= ", P, "  ------------------"); '''next'''() );
 
              s = 0;
 
              m = 3;
 
              '''while'''( m < Stop,
 
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q)  &&  !'''isprime'''(m), s++ );
 
                      m = m + 2;
 
                    );
 
              '''print'''("Q= ", Q, "  P= ", P, "  s= ", s);
 
            );
 
      );
 
}</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L54</span><br/>
 
Można pokazać<ref name="Arnault1"/>, że dla liczby złożonej nieparzystej <math>m \neq 9</math> i&nbsp;ustalonego <math>D</math> ilość par <math>P, Q</math> takich, że
 
 
 
:* <math>0 \leqslant P, Q < m</math>
 
:* <math>\gcd (Q, m) = 1</math>
 
:* <math>P^2 - 4 Q \equiv D \pmod{m}</math>
 
:* <math>m</math> jest SLPSP(<math>P, Q</math>)
 
 
 
nie przekracza <math>\tfrac{4}{15} n</math>.
 
 
 
Nie dotyczy to przypadku, gdy <math>m = p (p + 2)</math> jest iloczynem liczb pierwszych bliźniaczych takich, że <math>(D \, | \, p) = - (D \, | \, p + 2) = - 1</math>, wtedy mamy słabsze oszacowanie: <math>\# (P, Q) \leqslant \tfrac{1}{2} n</math>. Zauważmy, że taką sytuację łatwo wykryć, bo w&nbsp;tym przypadku <math>m + 1 = (p + 1)^2</math> jest liczbą kwadratową.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L55</span><br/>
 
Podobnie jak w&nbsp;przypadku liczb pseudopierwszych Lucasa LPSP(<math>P, Q</math>) tak i&nbsp;w&nbsp;przypadku liczb silnie pseudopierwszych Lucasa SLPSP(<math>P, Q</math>) możemy testować pierwszość liczby <math>m</math>, wybierając liczby <math>P, Q</math> losowo lub zastosować wybraną metodę postępowania. Przedstawiony poniżej program, to zmodyfikowany kod z uwagi L51. Teraz parametry <math>P, Q</math> są wybierane metodą Selfridge'a, a symbol Jacobiego <math>(D \, | \, m)</math> jest równy <math>- 1</math>.
 
 
 
<span style="font-size: 90%; color:black;">StrongLucasTest(m) =
 
{
 
'''local'''(a, b, c, k, P, Q, r, w, X);
 
'''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);
 
}</span>
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L56</span><br/>
 
Najmniejsze liczby silnie pseudopierwsze Lucasa, które otrzymujemy po zastosowaniu metody Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math>, to
 
 
 
::<math>5459, 5777, 10877, 16109, 18971, 22499, 24569, 25199, 40309, 58519, 75077, 97439, \ldots</math>
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">'''forstep'''(k=1, 10^5, 2, '''if'''( StrongLucasTest(k) && !'''isprime'''(k), '''print'''(k)) )</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
 
 
Tabela przedstawia ilość takich liczb nie większych od <math>10^n</math>
 
 
 
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
 
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math>
 
|-
 
| #SLPSP <math>< 10^n</math> (metoda Selfridge'a) || <math>0</math> || <math>2</math> || <math>12</math> || <math>58</math> || <math>178</math> || <math>505</math> || <math>1415</math>
 
|}
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">'''for'''(n=3, 9, s=0; '''forstep'''(k = 1, 10^n, 2, '''if'''( StrongLucasTest(k) && !'''isprime'''(k), s++ ) ); '''print'''("n=", n, "  ", s) )</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
 
 
 
 
 
 
 
 
== Test BPSW ==
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L57</span><br/>
 
Jest <math>488</math> liczb SPSP(<math>2</math>) mniejszych od <math>10^8</math> i są 582 liczby SPSP(<math>3</math>) mniejsze od <math>10^8</math> (zobacz K21). Ale jest aż <math>21</math> liczb mniejszych od <math>10^8</math> silnie pseudopierwszych jednocześnie względem podstaw <math>2</math> i <math>3</math>:
 
 
 
<math>1373653, 1530787, 1987021, 2284453, 3116107, 5173601, 6787327, 11541307, 13694761, 15978007, 16070429,</math>
 
 
 
<math>16879501, 25326001, 27509653, 27664033, 28527049, 54029741, 61832377, 66096253, 74927161, 80375707</math>
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">'''forstep'''(m=3, 10^8, 2, '''if'''( isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 2)  &&  isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 3)  &&  !'''isprime'''(m), '''print'''("m=", m) ) )</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
Widzimy, że prawdopodobieństwo błędnego rozpoznania pierwszości w&nbsp;przypadku liczb mniejszych od <math>10^8</math> dla podstaw <math>2</math> i <math>3</math> jest rzędu kilku milionowych. Gdyby prawdopodobieństwa błędnego rozpoznania pierwszości w&nbsp;przypadku podstaw <math>2</math> i <math>3</math> były niezależne, to spodziewalibyśmy się, że nie będzie wcale liczb mniejszych od <math>10^8</math> silnie pseudopierwszych jednocześnie względem podstaw <math>2</math> i <math>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
 
 
 
<span style="font-size: 90%; color:black;">BPSWtest(m) =
 
{
 
'''forprime'''(p = 2, 1000, '''if'''( m % p > 0, '''next'''() ); '''if'''( m == p, '''return'''(1), '''return'''(0) ));
 
'''if'''( !isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 2), '''return'''(0) );
 
'''if'''( !StrongLucasTest(m), '''return'''(0), '''return'''(1) );
 
}</span>
 
 
 
 
 
 
 
Funkcja <code>BPSWtest(m)</code> kolejno sprawdza:
 
 
 
:* czy liczba <math>m</math> jest podzielna przez niewielkie liczby pierwsze (w naszym przypadku mniejsze od <math>1000</math>); jeśli tak, to sprawdza, czy <math>m</math> jest liczbą pierwszą, czy złożoną i&nbsp;zwraca odpowiednio <math>1</math> lub <math>0</math>
 
:* czy liczba <math>m</math> przechodzi test Millera-Rabina dla podstawy <math>2</math>; jeśli nie, to zwraca <math>0</math>
 
:* czy liczba <math>m</math> przechodzi silny test Lucasa dla parametrów <math>P</math> i <math>Q</math>, które wybieramy metodą Selfridge'a; jeśli nie, to zwraca <math>0</math>, w&nbsp;przeciwnym wypadku zwraca <math>1</math>
 
 
 
 
 
Test w&nbsp;dokładnie takiej postaci zaproponowali Robert Baillie i&nbsp;Samuel Wagstaff<ref name="BaillieWagstaff1"/>. Nazwa testu to akronim, utworzony od pierwszych liter nazwisk Roberta Bailliego, Carla Pomerance'a, Johna Selfridge'a i&nbsp;Samuela Wagstaffa.
 
 
 
Nie jest znany żaden przykład liczby złożonej <math>m</math>, którą test BPSW<ref name="BPSW1"/><ref name="BPSW2"/> identyfikowałby jako pierwszą i&nbsp;z&nbsp;pewnością nie ma takich liczb dla <math>m < 2^{64} \approx 1.844 \cdot 10^{19}</math>. Warto przypomnieć: potrzebowaliśmy siedmiu testów Millera-Rabina (dla podstaw <math>2, 3, 5, 7, 11, 13, 17</math>), aby mieć pewność, że dowolna liczba <math>m < 3.41 \cdot 10^{14}</math> jest pierwsza (zobacz K22).
 
 
 
 
 
 
 
 
 
 
 
== Uzupełnienia ==
 
 
 
&nbsp;
 
 
 
=== <span style="border-bottom:1px solid #000;">Twierdzenie Lagrange'a, twierdzenie Wilsona, kryterium Eulera i symbol Legendre'a</span> ===
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L58</span><br/>
 
Niech <math>W_n (x)</math> będzie dowolnym wielomianem stopnia <math>n</math>. Wielomian <math>W_n (x)</math> można przedstawić w&nbsp;postaci
 
 
 
::<math>W_n (x) = W_n (s) + (x - s) V_{n - 1} (x)</math>
 
 
 
gdzie <math>V_{n - 1} (x)</math> jest wielomianem stopnia <math>n - 1</math>, a&nbsp;współczynniki wiodące wielomianów <math>W_n (x)</math> i <math>V_{n - 1} (x)</math> są sobie równe.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Z założenia <math>W_n (x) = \sum_{k = 0}^{n} a_k x^k</math>, gdzie <math>a_n \neq 0</math>. Zauważmy, że
 
 
 
::<math>W_n (x) - W_n (s) = \sum_{k = 0}^{n} a_k x^k - \sum_{k = 0}^{n} a_k s^k</math>
 
 
 
::::::<math>\quad \; = \sum_{k = 1}^{n} a_k (x^k - s^k)</math>
 
 
 
Dla <math>k \geqslant 1</math> prawdziwy jest wzór
 
 
 
::<math>x^k - s^k = (x - s) \sum_{j = 1}^{k} x^{k - j} s^{j - 1}</math>
 
 
 
::::<math>\;\,\, = (x - s) (x^{k - 1} + s x^{k - 2} + \ldots + s^{k - 2} x + s^{k - 1})</math>
 
 
 
::::<math>\;\,\, = (x - s) U^{(k)} (x)</math>
 
 
 
Gdzie przez <math>U^{(k)} (x) = \sum_{j = 1}^{k} x^{k - j} s^{j - 1}</math> oznaczyliśmy wielomian, którego stopień jest równy <math>k - 1</math>. Zatem możemy napisać
 
 
 
::<math>W_n (x) - W_n (s) = (x - s) \sum_{k = 1}^{n} a_k U^{(k)} (x)</math>
 
 
 
Suma wypisana po prawej stronie jest pewnym wielomianem <math>V_{n - 1} (x)</math>. Ponieważ ze wszystkich wielomianów <math>a_k U^{(k)} (x)</math>, wielomian <math>a_n U^{(n)} (x)</math> ma największy stopień równy <math>n - 1</math>, to stopień wielomianu <math>V_{n - 1} (x)</math> jest równy <math>n - 1</math>. Czyli
 
 
 
::<math>W_n (x) - W_n (s) = (x - s) V_{n - 1} (x)</math>
 
 
 
Niech <math>V_n (x) = \sum_{k = 0}^{n - 1} b_k x^k</math>. Mamy
 
 
 
::<math>\sum_{k = 0}^{n} a_k x^k - W_n (s) = \sum_{k = 0}^{n - 1} b_k x^{k + 1} + s \sum_{k = 0}^{n - 1} b_k x^k</math>
 
 
 
Porównując wyrazy o&nbsp;największym stopniu, łatwo zauważamy, że <math>a_n = b_{n - 1}</math>. Czyli współczynnik wiodący wielomianu <math>V_{n - 1} (x)</math> jest równy <math>a_n</math>. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Definicja L59</span><br/>
 
Powiemy, że wielomian <math>W_n (x) = \sum_{k = 0}^{n} a_k x^k</math> o&nbsp;współczynnikach całkowitych <math>a_k</math> jest stopnia <math>n</math> modulo <math>p</math>, jeżeli <math>p \nmid a_n</math>. Jeżeli każdy współczynnik <math>a_k</math>, gdzie <math>k = 0, 1, \ldots, n</math>, jest podzielny przez <math>p</math>, to stopień wielomianu <math>W_n (x)</math> modulo <math>p</math> jest nieokreślony.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L60</span><br/>
 
Zauważmy, że w&nbsp;twierdzeniu L58 mówimy o&nbsp;dowolnym wielomianie, którego współczynniki mogą być całkowite, wymierne, rzeczywiste, zespolone itd. Stopień wielomianu wynika z&nbsp;warunku <math>a_n \neq 0</math>.
 
 
 
W definicji L59 mówimy o&nbsp;wielomianie, którego współczynniki są liczbami całkowitymi i&nbsp;który dla <math>x \in \mathbb{Z}</math> przyjmuje wartości całkowite. Wprowadzamy też nowe pojęcie: stopnia wielomianu modulo liczba pierwsza <math>p</math>. Warunek <math>p \nmid a_n</math> możemy zapisać w&nbsp;postaci równoważnej <math>a_n \not\equiv 0 \pmod{p}</math>.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L61</span><br/>
 
Kongruencja
 
 
 
::<math>a_1 x + a_0 \equiv 0 \pmod{p}</math>
 
 
 
gdzie <math>p \nmid a_1</math>, ma dokładnie jedno rozwiązanie modulo <math>p</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
 
 
'''A. Istnienie rozwiązania'''
 
 
 
Ponieważ rozpatrywaną kongruencję możemy zapisać w postaci <math>a_1 x + a_0 = k p</math>, to istnienie liczb <math>x</math> i <math>k</math>, dla których ta równość jest prawdziwa, wynika z twierdzenia C72. Poniżej przedstawimy jeszcze jeden sposób znalezienia rozwiązania.
 
 
 
Ponieważ <math>\gcd (a_1, p) = 1</math>, to istnieją takie liczby <math>r, s</math>, że <math>a_1 r + p s = 1</math> (zobacz C69 - lemat Bézouta). Zauważmy, że <math>p \nmid r</math>, bo gdyby tak było, to liczba pierwsza <math>p</math> dzieliłaby wyrażenie <math>a_1 r + p s</math>, ale jest to niemożliwe, bo <math>a_1 r + p s = 1</math>. Czyli modulo <math>p</math> mamy
 
 
 
::<math>a_1 r \equiv 1 \pmod{p}</math>
 
 
 
Mnożąc rozpatrywaną kongruencję przez <math>r</math>, otrzymujemy
 
 
 
::<math>a_1 r x + a_0 r \equiv 0 \pmod{p}</math>
 
 
 
Zatem
 
 
 
::<math>x \equiv - a_0 r \pmod{p}</math>
 
 
 
'''B. Brak innych rozwiązań'''
 
 
 
Przypuśćmy, że istnieją dwa różne rozwiązania kongruencji
 
 
 
::<math>a_1 x + a_0 \equiv 0 \pmod{p}</math>
 
 
 
Jeśli oznaczymy je przez <math>x_1</math> i <math>x_2</math>, to otrzymamy
 
 
 
::<math>a_1 x_1 + a_0 \equiv 0 \equiv a_1 x_2 + a_0 \pmod{p}</math>
 
 
 
Czyli
 
 
 
::<math>a_1 x_1 \equiv a_1 x_2 \pmod{p}</math>
 
 
 
::<math>p \, | \, a_1 (x_1 - x_2)</math>
 
 
 
Ponieważ <math>p \nmid a_1</math>, to z&nbsp;lematu Euklidesa (C70) otrzymujemy natychmiast <math>p \, | \, (x_1 - x_2)</math>. Skąd wynika, że <math>x_1 \equiv x_2 \pmod{p}</math>, wbrew założeniu, że <math>x_1</math> i <math>x_2</math> są dwoma różnymi rozwiązaniami. Co kończy dowód.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L62 (Lagrange, 1768)</span><br/>
 
Jeżeli wielomian <math>W_n (x) = \sum_{k = 0}^{n} a_k x^k</math> ma stopień <math>n</math> modulo <math>p</math>, gdzie <math>n \geqslant 1</math>, to kongruencja
 
 
 
::<math>W_n (x) \equiv 0 \pmod{p}</math>
 
 
 
ma co najwyżej <math>n</math> rozwiązań.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Indukcja matematyczna. Z&nbsp;L61 wiemy, że dowodzone twierdzenie jest prawdziwe dla <math>n = 1</math>. Załóżmy, że twierdzenie jest prawdziwe dla wszystkich liczb całkowitych dodatnich nie większych od <math>n - 1</math>. Niech wielomian <math>W_n (x)</math> ma stopień <math>n</math> modulo <math>p</math>. Jeżeli kongruencja
 
 
 
::<math>W_n (x) \equiv 0 \pmod{p}</math>
 
 
 
nie ma żadnego rozwiązania, to dowodzone twierdzenie jest prawdziwe dla <math>n</math>. Przypuśćmy teraz, że wypisana wyżej kongruencja ma przynajmniej jeden pierwiastek <math>x \equiv s \pmod{p}</math>. Korzystając z&nbsp;twierdzenia L58, możemy napisać
 
 
 
::<math>W_n (x) - W_n (s) = (x - s) V_{n - 1} (x)</math>
 
 
 
gdzie wielomian <math>V_{n - 1} (x)</math> ma stopień <math>n - 1</math> modulo <math>p</math>, bo wielomiany <math>W_n (x)</math> oraz <math>V_{n - 1} (x)</math> mają jednakowe współczynniki wiodące.
 
 
 
 
 
Z założenia <math>x \equiv s \pmod{p}</math> jest jednym z&nbsp;pierwiastków kongruencji <math>W_n (x) \equiv 0 \pmod{p}</math>, zatem modulo <math>p</math> otrzymujemy
 
 
 
::<math>W_n (x) \equiv (x - s) V_{n - 1} (x) \pmod{p}</math>
 
 
 
Ponieważ <math>p</math> jest liczbą pierwszą, to z&nbsp;rozpatrywanej kongruencji
 
 
 
::<math>W_n (x) \equiv 0 \pmod{p}</math>
 
 
 
wynika, że musi być (zobacz C70)
 
 
 
::<math>x \equiv s \pmod{p} \qquad \qquad \text{lub} \qquad \qquad V_{n - 1} (x) \equiv 0 \pmod{p}</math>
 
 
 
 
 
Z założenia indukcyjnego kongruencja
 
 
 
::<math>V_{n - 1} (x) \pmod{p}</math>
 
 
 
ma co najwyżej <math>n - 1</math> rozwiązań, zatem kongruencja
 
 
 
::<math>W_n (x) \equiv 0 \pmod{p}</math>
 
 
 
ma nie więcej niż <math>n</math> rozwiązań. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L63</span><br/>
 
Jeżeli kongruencja
 
 
 
::<math>a_n x^n + a_{n - 1} x^{n - 1} + \ldots + a_1 x + a_0 \equiv 0 \pmod{p}</math>
 
 
 
ma więcej niż <math>n</math> rozwiązań, to wszystkie współczynniki <math>a_k</math>, gdzie <math>k = 0, \ldots, n</math>, muszą być podzielne przez <math>p</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Niech <math>S \subset \{ 0, 1, \ldots, n \}</math> będzie zbiorem takim, że dla każdego <math>k \in S</math> jest <math>p \nmid a_k</math>. Przypuśćmy, że <math>S</math> jest zbiorem niepustym. Niech <math>j</math> oznacza największy element zbioru <math>S</math>. Jeżeli <math>j = 0</math>, to wielomian <math>W_n (x) = \sum_{k = 0}^{n} a_k x^k</math> jest stopnia <math>0</math> modulo <math>p</math> i
 
 
 
::<math>a_0 \not\equiv 0 \pmod{p}</math>
 
 
 
Konsekwentnie, dla dowolnego <math>x \in \mathbb{Z}</math> jest
 
 
 
::<math>a_n x^n + a_{n - 1} x^{n - 1} + \ldots + a_1 x + a_0 \not\equiv 0 \pmod{p}</math>
 
 
 
bo dla każdego <math>1 \leqslant k \leqslant n</math> mamy <math>a_k \equiv 0 \pmod{p}</math>. Zatem rozpatrywana kongruencja nie ma ani jednego rozwiązania, czyli rozwiązań nie może być więcej niż <math>n</math>.
 
 
 
W przypadku gdy <math>j \neq 0</math>, z&nbsp;twierdzenia Lagrange'a wynika, że rozpatrywana kongruencja ma nie więcej niż <math>j \leqslant n</math> rozwiązań, ponownie wbrew założeniu, że kongruencja ta ma więcej niż <math>n</math> rozwiązań. Uczynione przypuszczenie, że <math>S</math> jest zbiorem niepustym, okazało się fałszywe, zatem zbiór <math>S</math> musi być zbiorem pustym. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Przykład L64</span><br/>
 
Z twierdzenia Lagrange'a wynika, że kongruencja
 
 
 
::<math>x^p - x - 1 \equiv 0 \pmod{p}</math>
 
 
 
ma co najwyżej <math>p</math> rozwiązań. W&nbsp;rzeczywistości nie ma ani jednego rozwiązania, bo z&nbsp;twierdzenia Fermata wiemy, że dla dowolnej liczby pierwszej <math>p</math> jest
 
 
 
::<math>x^p \equiv x \pmod{p}</math>
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Przykład L65</span><br/>
 
Zauważmy, że w&nbsp;przypadku, gdy <math>n \geqslant p</math>, możemy zawsze wielomian przekształcić do postaci takiej, że <math>n < p</math>. Niech <math>p = 5</math> i
 
 
 
::<math>W(x) = x^{15} + 11 x^{11} + 5 x^5 + 2 x^2 + x + 1</math>
 
 
 
Ponieważ <math>x^5 \equiv x \pmod{5}</math>, to
 
 
 
::<math>W(x) \equiv x^3 + 11 x^3 + 5 x + 2 x^2 + x + 1 \equiv 12 x^3 + 2 x^2 + 6 x + 1 \pmod{5}</math>
 
 
 
Co wynika również z&nbsp;faktu, że <math>W(x)</math> można zapisać w&nbsp;postaci
 
 
 
::<math>W(x) = x^{15} + 11 x^{11} + 5 x^5 + 2 x^2 + x + 1 = (x^5 - x) (x^{10} + 12 x^6 + 12 x^2 + 5) + 12 x^3 + 2 x^2 + 6 x + 1</math>
 
 
 
ale <math>x^5 - x \equiv 0 \pmod{5}</math> na mocy twierdzenia Fermata.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L66 (Wilson, 1770)</span><br/>
 
Liczba całkowita <math>p \geqslant 2</math> jest liczbą pierwszą wtedy i&nbsp;tylko wtedy, gdy
 
 
 
::<math>(p - 1) ! \equiv - 1 \pmod{p}</math>
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
<math>\Longleftarrow</math><br/>
 
Przypuśćmy, że prawdziwa jest kongruencja <math>(p - 1) ! \equiv - 1 \pmod{p}</math> oraz <math>p</math> jest liczbą złożoną. Zatem liczba <math>p</math> ma dzielnik <math>d</math> taki, że <math>2 \leqslant d \leqslant p - 1</math>. Ponieważ <math>d \, | \, p</math>, to prawdziwa jest kongruencja
 
 
 
::<math>(p - 1) ! \equiv - 1 \pmod{d}</math>
 
 
 
czyli
 
 
 
::<math>0 \equiv - 1 \pmod{d}</math>
 
 
 
co jest niemożliwe.
 
 
 
<math>\Longrightarrow</math><br/>
 
Łatwo sprawdzamy, że twierdzenie jest prawdziwe dla <math>p = 2</math>. Niech teraz <math>p</math> będzie liczbą pierwszą nieparzystą. Rozważmy wielomiany
 
 
 
::<math>W(x) = (x - 1) (x - 2) \cdot \ldots \cdot (x - (p - 1))</math>
 
 
 
oraz
 
 
 
::<math>V(x) = x^{p - 1} - 1</math>
 
 
 
Zauważmy, że
 
 
 
:* stopnie tych wielomianów są równe <math>p - 1</math>
 
:* współczynniki wiodące są równe <math>1</math>
 
:* wyrazy wolne są równe odpowiednio <math>(p - 1) !</math> oraz <math>- 1</math>
 
:* wielomiany mają <math>p - 1</math> rozwiązań modulo <math>p</math>
 
 
 
Niech
 
 
 
::<math>U(x) = W (x) - V (x)</math>
 
 
 
Zauważmy, że
 
 
 
:* stopień wielomianu <math>U(x)</math> jest równy <math>p - 2 \geqslant 1</math>, ponieważ wyrazy o&nbsp;najwyższym stopniu uległy redukcji
 
:* wielomian <math>U(x)</math> ma <math>p - 1</math> rozwiązań modulo <math>p</math>, bo dla każdego <math>k \in \{ 1, 2, \ldots, p - 1 \}</math> mamy <math>U(k) = W (k) - V (k) \equiv 0 \pmod{p}</math>
 
 
 
Z twierdzenia Lagrange'a wiemy, że wielomian <math>U(x)</math> nie może mieć więcej niż <math>p - 2</math> rozwiązań modulo <math>p</math>. Zatem z&nbsp;twierdzenia L63 wynika natychmiast, że liczba pierwsza <math>p</math> musi dzielić każdy współczynnik <math>a_k</math> wielomianu <math>U(x)</math> i&nbsp;w&nbsp;szczególności musi dzielić wyraz wolny, który jest równy <math>(p - 1) ! + 1</math>. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Definicja L67</span><br/>
 
Niech <math>p</math> będzie liczbą pierwszą i <math>a \in \mathbb{Z}</math>. Powiemy, że liczba <math>a</math> jest liczbą kwadratową modulo <math>p</math>, jeżeli kongruencja
 
 
 
::<math>x^2 \equiv a \pmod{p}</math>
 
 
 
ma rozwiązanie, czyli istnieje taka liczba <math>k \in \mathbb{Z}</math>, że <math>p \, | \, (k^2 - a)</math>.
 
 
 
Powiemy, że liczba <math>a</math> jest liczbą niekwadratową modulo <math>p</math>, jeżeli kongruencja
 
 
 
::<math>x^2 \equiv a \pmod{p}</math>
 
 
 
nie ma rozwiązania.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L68</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą, to wśród liczb <math>1, 2, \ldots, p - 1</math> istnieje dokładnie <math>{\small\frac{p - 1}{2}}</math> liczb kwadratowych modulo <math>p</math> i&nbsp;tyle samo liczb niekwadratowych modulo <math>p</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Zauważmy, że w&nbsp;rozważanym zbiorze liczb <math>\{ 1, 2, \ldots, p - 1 \}</math>, kwadraty liczb <math>k</math> i <math>p - k</math> są takimi samymi liczbami modulo <math>p</math>, co wynika z&nbsp;oczywistej kongruencji
 
 
 
::<math>k^2 \equiv (p - k)^2 \pmod{p}</math>
 
 
 
Pozwala to wypisać pary liczb, których kwadraty są identyczne modulo <math>p</math>
 
 
 
::<math>(1, p - 1), (2, p - 2), \ldots, \left( {\small\frac{p - 1}{2}}, p - {\small\frac{p - 1}{2}} \right)</math>
 
 
 
Ponieważ
 
 
 
::<math>p - {\small\frac{p - 1}{2}} = {\small\frac{p + 1}{2}} = {\small\frac{p - 1}{2}} + 1</math>
 
 
 
to wypisane pary wyczerpują cały zbiór <math>\{ 1, 2, \ldots, p - 1 \}</math>. Co więcej, liczby <math>1^2, 2^2, \ldots, \left( {\small\frac{p - 1}{2}} \right)^2</math> są wszystkie różne modulo <math>p</math>. Istotnie, przypuśćmy, że <math>1 \leqslant i, j \leqslant {\small\frac{p - 1}{2}}</math> oraz <math>i \neq j</math>, a&nbsp;jednocześnie <math>i^2 \equiv j^2 \pmod{p}</math>. Gdyby tak było, to mielibyśmy
 
 
 
::<math>(i - j) (i + j) \equiv 0 \pmod{p}</math>
 
 
 
Łatwo zauważamy, że jest to niemożliwe, bo żaden z&nbsp;czynników nie jest podzielny przez <math>p</math>, co wynika z&nbsp;prostych oszacowań
 
 
 
::<math>1 \leqslant | i - j | \leqslant i + j < p - 1</math>
 
 
 
::<math>2 < i + j < p - 1</math>
 
 
 
 
 
Ponieważ (z definicji) liczba <math>a</math> jest liczbą kwadratową modulo <math>p</math>, jeżeli kongruencja
 
 
 
::<math>x^2 \equiv a \pmod{p}</math>
 
 
 
ma rozwiązanie, to liczba kwadratowa modulo <math>p</math> musi przystawać do pewnego kwadratu modulo <math>p</math>.
 
 
 
Wynika stąd, że różnych liczb kwadratowych modulo <math>p</math> jest tyle samo, co kwadratów <math>1^2, 2^2, \ldots, \left( {\small\frac{p - 1}{2}} \right)^2</math>. Czyli jest ich dokładnie <math>{\small\frac{p - 1}{2}}</math>. Pozostałe liczby w&nbsp;zbiorze <math>\{ 1, 2, \ldots, p - 1 \}</math> to liczby niekwadratowe modulo <math>p</math> i&nbsp;jest ich również <math>{\small\frac{p - 1}{2}}</math>. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L69 (kryterium Eulera, 1748)</span><br/>
 
Niech <math>p</math> będzie liczbą pierwszą nieparzystą i <math>p \nmid a</math>. Modulo <math>p</math> mamy
 
 
 
::{| border="0"
 
|-style=height:2.5em
 
| &#9679;&nbsp;&nbsp;&nbsp; || liczba <math>a</math> jest liczbą kwadratową modulo <math>p</math> wtedy i tylko wtedy, gdy <math>a^{(p - 1) / 2} \equiv 1 \pmod{p}</math>
 
|-style=height:2.5em
 
| &#9679;&nbsp;&nbsp;&nbsp; || liczba <math>a</math> jest liczbą niekwadratową modulo <math>p</math> wtedy i tylko wtedy, gdy <math>a^{(p - 1) / 2} \equiv - 1 \pmod{p}</math>
 
|}
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
 
 
'''Punkt 1.'''
 
 
 
Niech <math>Q \subset \{ 1, 2, \ldots, p - 1 \}</math> będzie zbiorem wszystkich liczb kwadratowych modulo <math>p</math>, a <math>S \subset \{ 1, 2, \ldots, p - 1 \}</math> będzie zbiorem wszystkich rozwiązań kongruencji
 
 
 
::<math>x^{(p - 1) / 2} \equiv 1 \pmod{p}</math>
 
 
 
Zauważmy, że
 
 
 
::{| border=1 style="border-collapse: collapse;"
 
|-style=height:2.5em
 
| &nbsp;&nbsp;&nbsp;'''A'''&nbsp;&nbsp;&nbsp; || &nbsp;&nbsp;&nbsp;<math>| Q | = {\small\frac{p - 1}{2}}</math> || &nbsp;&nbsp;&nbsp;zobacz L68
 
|-style=height:2.5em
 
| &nbsp;&nbsp;&nbsp;'''B'''&nbsp;&nbsp;&nbsp; || &nbsp;&nbsp;&nbsp;<math>| S | \leqslant {\small\frac{p - 1}{2}}</math> || &nbsp;&nbsp;&nbsp;zobacz twierdzenie Lagrange'a L62
 
|-style=height:2.5em
 
| &nbsp;&nbsp;&nbsp;'''C'''&nbsp;&nbsp;&nbsp; || &nbsp;&nbsp;&nbsp;jeżeli <math>a \in Q</math>, to <math>a \in S \qquad </math> || &nbsp;&nbsp;&nbsp;wynika z ciągu implikacji:<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>a \in Q \qquad \Longrightarrow \qquad a \equiv k^2 \pmod{p}</math><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>a \equiv k^2 \pmod{p} \qquad \Longrightarrow \qquad a^{(p - 1) / 2} \equiv (k^2)^{(p - 1) / 2} \equiv k^{p - 1} \equiv 1 \pmod{p}</math>&nbsp;&nbsp;&nbsp;<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>a^{(p - 1) / 2} \equiv 1 \pmod{p} \qquad \Longrightarrow \qquad a \in S</math>
 
|-style=height:2.5em
 
| &nbsp;&nbsp;&nbsp;'''D'''&nbsp;&nbsp;&nbsp; || &nbsp;&nbsp;&nbsp;<math>Q \subseteq S</math> || &nbsp;&nbsp;&nbsp;z punktu '''C''' wynika, że '''każdy''' element zbioru <math>Q</math> należy do zbioru <math>S</math>
 
|}
 
 
 
 
 
Łącząc rezultaty z tabeli, otrzymujemy
 
 
 
::<math>{\small\frac{p - 1}{2}} = | Q | \leqslant | S | \leqslant {\small\frac{p - 1}{2}}</math>
 
 
 
Skąd łatwo widzimy, że
 
 
 
::<math>| Q | = | S | = {\small\frac{p - 1}{2}}</math>
 
 
 
Ponieważ <math>Q \subseteq S</math>, a zbiory <math>Q</math> i <math>S</math> są równoliczne, to zbiory te są równe (zobacz L70). Prostą konsekwencją równości zbiorów <math>Q</math> i <math>S</math> jest stwierdzenie
 
 
 
::{| border=0 style="background: #EEEEEE;"
 
|-style=height:2.0em
 
|&nbsp;&nbsp;&nbsp;liczba <math>a</math> jest liczbą kwadratową modulo <math>p</math> wtedy i tylko wtedy, gdy <math>a^{(p - 1) / 2} \equiv 1 \pmod{p}</math>&nbsp;&nbsp;&nbsp;
 
|}
 
 
 
Co kończy dowód punktu pierwszego.
 
 
 
'''Punkt 2.'''
 
 
 
Z udowodnionego już punktu pierwszego wynika<ref name="logic1"/>, że
 
 
 
::{| border=0 style="background: #EEEEEE;"
 
|-style=height:2.0em
 
|&nbsp;&nbsp;&nbsp;liczba <math>a</math> jest liczbą niekwadratową modulo <math>p</math> wtedy i tylko wtedy, gdy <math>a^{(p - 1) / 2} \not\equiv 1 \pmod{p}</math>&nbsp;&nbsp;&nbsp;
 
|}
 
 
 
Z twierdzenia Fermata
 
 
 
::<math>a^{p - 1} - 1 = (a^{(p - 1) / 2} - 1) \cdot (a^{(p - 1) / 2} + 1) \equiv 0 \pmod{p}</math>
 
 
 
wynika natychmiast, że jeżeli <math>a^{(p - 1) / 2} - 1 \not\equiv 0 \pmod{p}</math>, to musi być
 
 
 
::<math>a^{(p - 1) / 2} + 1 \equiv 0 \pmod{p}</math>
 
 
 
Fakt ten pozwala sformułować uzyskaną równoważność bardziej precyzyjnie
 
 
 
::{| border=0 style="background: #EEEEEE;"
 
|-style=height:2.0em
 
|&nbsp;&nbsp;&nbsp;liczba <math>a</math> jest liczbą niekwadratową modulo <math>p</math> wtedy i tylko wtedy, gdy <math>a^{(p - 1) / 2} \equiv - 1 \pmod{p}</math>&nbsp;&nbsp;&nbsp;
 
|}
 
 
 
Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Zadanie L70</span><br/>
 
Niech <math>A</math> i <math>B</math> będą zbiorami skończonymi. Pokazać, że jeżeli <math>A \subseteq B \;\; \text{i} \;\; | A | = | B |</math>, to <math>\; A = B</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 
Ponieważ zbiór <math>A</math> jest podzbiorem zbioru <math>B</math>, to zbiór <math>B</math> można przedstawić w postaci sumy zbiorów <math>A</math> i <math>C</math> takich, że żaden element zbioru <math>C</math> nie jest elementem zbioru <math>A</math>. Zatem
 
 
 
::<math>B = A \cup C \qquad \text{i} \qquad A \cap C = \varnothing</math>
 
 
 
Ponieważ z założenia zbiory <math>A</math> i <math>C</math> są rozłączne, to wiemy, że
 
 
 
::<math>| A \cup C | = | A | + | C |</math>
 
 
 
Czyli
 
 
 
::<math>| B | = | A \cup C | = | A | + | C |</math>
 
 
 
Skąd wynika, że <math>| C | = 0</math>, zatem zbiór <math>C</math> jest zbiorem pustym i otrzymujemy natychmiast <math>B = A</math>. Co należało pokazać.
 
 
 
 
 
<span style="border-bottom-style: double;">Uwaga (przypadek zbiorów skończonych)</span><br/>
 
Najczęściej prawdziwe jest jedynie oszacowanie <math>| A \cup C | \leqslant | A | + | C |</math>, bo niektóre elementy mogą zostać policzone dwa razy. Elementy liczone dwukrotnie to te, które należą do iloczynu zbiorów <math>| A |</math> i <math>| C |</math>, zatem od sumy <math>| A | + | C |</math> musimy odjąć liczbę elementów iloczynu zbiorów <math>| A |</math> i <math>| C |</math>. Co daje ogólny wzór<ref name="sumazbiorow"/>
 
 
 
::<math>| A \cup C | = | A | + | C | - | A \cap C |</math><br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Definicja L71</span><br/>
 
Niech <math>p</math> będzie liczbą pierwszą nieparzystą i <math>a \in \mathbb{Z}</math>. Symbolem Legendre'a nazywamy funkcję <math>a</math> i <math>p</math> zdefiniowaną następująco
 
 
 
::<math>\left( {\small\frac{a}{p}} \right)_{\small{\!\! L}} =
 
\begin{cases}
 
\;\;\: 1 & \text{gdy } \, a \, \text{ jest liczbą kwadratową modulo } \, p \,  \text{ oraz } \, p \nmid a \\
 
      - 1 & \text{gdy } \, a \, \text{ jest liczbą niekwadratową modulo } \, p \\
 
\;\;\: 0 & \text{gdy } \, p \, | \, a
 
\end{cases}</math>
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L72</span><br/>
 
Powyższa definicja pozwala nam zapisać kryterium Eulera w&nbsp;zwartej formie, która obejmuje również przypadek, gdy <math>p \, | \, a</math>
 
 
 
::<math>a^{(p - 1) / 2} \equiv \left( {\small\frac{a}{p}} \right)_{\small{\!\! L}} \pmod{p}</math>
 
 
 
Porównanie właściwości symbolu Legendre'a i&nbsp;symbolu Jacobiego będzie łatwiejsze, gdy przedstawimy je w&nbsp;tabeli (podobnie jak w&nbsp;twierdzeniu L3). Zauważmy, że poza zmienionym założeniem tabele te różnią się jedynie punktem czwartym. Oczywiście jest to tylko podobieństwo formalne – symbol Legendre'a i&nbsp;symbol Jacobiego są różnymi funkcjami.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L73*</span><br/>
 
Niech <math>a, b \in \mathbb{Z}</math> oraz <math>p, q</math> będą nieparzystymi liczbami pierwszymi. Symbol Legendre'a ma następujące właściwości
 
 
 
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: left; margin-right: auto;"
 
|-
 
| &nbsp;&nbsp;1.&nbsp;&nbsp; || <math>\left( {\small\frac{a}{p}} \right)_{\small{\!\! L}} \,\, = \,\, 0 \quad \Longleftrightarrow \quad \gcd (a, p) > 1</math>
 
|-
 
| &nbsp;&nbsp;2.&nbsp;&nbsp; || <math>a \equiv b \pmod p \quad \Longrightarrow \quad \left( {\small\frac{a}{p}} \right)_{\small{\!\! L}} = \left( {\small\frac{b}{p}} \right)_{\small{\!\! L}}</math>
 
|-
 
| &nbsp;&nbsp;3.&nbsp;&nbsp; || <math>\left( {\small\frac{a b}{p}} \right)_{\small{\!\! L}} \,\, = \,\, \left( {\small\frac{a}{p}} \right)_{\small{\!\! L}} \cdot  \left( {\small\frac{b}{p}} \right)_{\small{\!\! L}}</math>
 
|-
 
| &nbsp;&nbsp;4.&nbsp;&nbsp; || <math>a^{(p - 1) / 2} \equiv \left( {\small\frac{a}{p}} \right)_{\small{\!\! L}} \pmod{p}</math>
 
|-
 
| &nbsp;&nbsp;5.&nbsp;&nbsp; || <math>\left( {\small\frac{1}{p}} \right)_{\small{\!\! L}} \,\, = \,\, 1</math>
 
|-
 
| &nbsp;&nbsp;6.&nbsp;&nbsp; || <math>\left( {\small\frac{- 1}{p}} \right)_{\small{\!\! L}} \,\, = \,\, (- 1)^{\tfrac{p - 1}{2}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } p \equiv 1 \pmod{4} \\
 
      - 1 & \text{gdy } p \equiv 3 \pmod{4}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;7.&nbsp;&nbsp; || <math>\left( {\small\frac{2}{p}} \right)_{\small{\!\! L}} \,\, = \,\, (- 1)^{\tfrac{p^2 - 1}{8}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } p \equiv 1, 7 \pmod{8} \\
 
      - 1 & \text{gdy } p \equiv 3, 5 \pmod{8}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;8.&nbsp;&nbsp; || <math>\left( {\small\frac{- 2}{p}} \right)_{\small{\!\! L}} \,\, = \,\, (- 1)^{\tfrac{(p - 1)(p - 3)}{8}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } p \equiv 1, 3 \pmod{8} \\
 
      - 1 & \text{gdy } p \equiv 5, 7 \pmod{8}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;9.&nbsp;&nbsp; || <math>\left( {\small\frac{p}{q}} \right)_{\small{\!\! L}} \,\, = \,\, \left( {\small\frac{q}{p}} \right)_{\small{\!\! L}} \cdot (-1)^{\tfrac{q - 1}{2} \cdot \tfrac{p - 1}{2}} \,\, = \,\, \left( {\small\frac{q}{p}} \right)_{\small{\!\! L}} \cdot
 
\begin{cases}
 
\;\;\: 1 & \text{gdy } p \equiv 1 \pmod{4} \;\;\; \text{lub} \;\;\; q \equiv 1 \pmod{4} \\
 
      - 1 & \text{gdy } p \equiv q \equiv 3 \pmod{4}
 
  \end{cases}</math>
 
|}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
=== <span style="border-bottom:1px solid #000;">Pewne własności współczynników dwumianowych</span> ===
 
 
 
&nbsp;
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L74</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą, to
 
 
 
::<math>\binom{p}{k} \equiv 0 \pmod{p}</math>
 
 
 
dla każdego <math>k \in [1, p - 1]</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Łatwo zauważamy, że dla <math>k \in [1, p - 1]</math> liczba pierwsza <math>p</math> dzieli licznik, ale nie dzieli mianownika współczynnika dwumianowego
 
 
 
::<math>\binom{p}{k} = {\small\frac{p!}{k! \cdot (p - k)!}}</math>
 
 
 
zatem <math>p \biggr\rvert \binom{p}{k}</math>. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L75</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą, to
 
 
 
::<math>\binom{p + 1}{k} \equiv 0 \pmod{p}</math>
 
 
 
dla każdego <math>k \in [2, p - 1]</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Jeżeli <math>k \in [2, p - 1]</math>, to modulo <math>p</math> dostajemy
 
 
 
::<math>\binom{p + 1}{k} = \binom{p}{k} + \binom{p}{k - 1} \equiv 0 \pmod{p}</math>
 
 
 
Bo liczba pierwsza <math>p</math> dzieli licznik, ale nie dzieli mianownika współczynników dwumianowych po prawej stronie. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L76</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą, to
 
 
 
::<math>\binom{p - 1}{k} \equiv (- 1)^k \pmod{p}</math>
 
 
 
dla każdego <math>k \in [0, p - 1]</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Łatwo sprawdzamy, że twierdzenie jest prawdziwe dla liczby pierwszej parzystej <math>p = 2</math>. Załóżmy, że <math>p</math> jest liczbą pierwszą nieparzystą. Równie łatwo sprawdzamy, że twierdzenie jest prawdziwe dla <math>k = 0</math> i <math>k = 1</math>. Zauważmy, że dla <math>k \in [1, p - 1]</math> jest
 
 
 
::<math>\binom{p - 1}{k} = {\small\frac{(p - 1) !}{k! (p - 1 - k) !}} = {\small\frac{p - k}{k}} \cdot {\small\frac{(p - 1) !}{(k - 1) ! (p - k) !}} = {\small\frac{p - k}{k}} \cdot \binom{p - 1}{k - 1} = {\small\frac{p}{k}} \cdot \binom{p - 1}{k - 1} - \binom{p - 1}{k - 1}</math>
 
 
 
Ponieważ współczynniki dwumianowe są liczbami całkowitymi, a&nbsp;liczba <math>k \in [2, p - 1]</math> nie dzieli liczby pierwszej nieparzystej <math>p</math>, to <math>k</math> musi dzielić liczbę <math>\binom{p - 1}{k - 1}</math>. Zatem dla <math>k \in [2, p - 1]</math> modulo <math>p</math> mamy
 
 
 
::<math>\binom{p - 1}{k} \equiv - \binom{p - 1}{k - 1}\pmod{p}</math>
 
 
 
Skąd otrzymujemy
 
 
 
::<math>\binom{p - 1}{k} \equiv (- 1)^1 \binom{p - 1}{k - 1} \equiv (- 1)^2 \binom{p - 1}{k - 2} \equiv \ldots \equiv (- 1)^{k - 2} \binom{p - 1}{2} \equiv (- 1)^{k - 1} \binom{p - 1}{1} \equiv (- 1)^k \pmod{p}</math>
 
 
 
Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L77</span><br/>
 
Dla współczynników dwumianowych prawdziwe są następujące wzory
 
 
 
::<math>\underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
 
 
::<math>\underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Ze wzoru dwumianowego
 
 
 
::<math>(a + b)^n = \sum_{k = 0}^{n} \binom{n}{k} a^{n - k} b^k</math>
 
 
 
z łatwością otrzymujemy
 
 
 
::<math>(1 + 1)^n = \sum_{k = 0}^{n} \binom{n}{k} = 2^n</math>
 
 
 
::<math>(1 - 1)^n = \sum_{k = 0}^{n} (- 1)^k \binom{n}{k} = 0</math>
 
 
 
Obliczając sumę i&nbsp;różnicę powyższych wzorów mamy
 
 
 
::<math>\sum_{k = 0}^{n} \binom{n}{k} (1 + (- 1)^k) = 2 \underset{k \; \text{parzyste}}{\sum^n_{k = 0}} \binom{n}{k} = 2^n</math>
 
 
 
::<math>\sum_{k = 0}^{n} \binom{n}{k} (1 - (- 1)^k) = 2 \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^n</math>
 
 
 
Skąd natychmiast wynika
 
 
 
::<math>\underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
 
 
::<math>\underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
 
 
Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
=== <span style="border-bottom:1px solid #000;">Funkcje <span style="font-size: 95%; background-color: #f8f9fa"><tt>digits(m, b)</tt></span> oraz <span style="font-size: 95%; background-color: #f8f9fa"><tt>issquare(m)</tt></span></span> ===
 
 
 
&nbsp;
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L78</span><br/>
 
W funkcji <code>modLucas()</code> wykorzystaliśmy zaimplementowaną w&nbsp;PARI/GP funkcję
 
 
 
<code>digits(m, b)</code> – zwraca wektor cyfr liczby <math>| m |</math> w&nbsp;systemie liczbowym o&nbsp;podstawie <math>b</math>
 
 
 
W naszym przypadku potrzebowaliśmy uzyskać wektor cyfr liczby <math>m</math> w&nbsp;układzie dwójkowym, czyli funkcję <code>digits(m, 2)</code> . Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Zauważmy, że do zapisania liczby <math>m \geqslant 1</math> potrzebujemy <math>\log_2 m + 1</math> cyfr. Zastępując funkcję <math>\log_2 m</math> funkcją <math>\left \lfloor \tfrac{\log m}{\log 2} \right \rfloor</math> musimy liczyć się z&nbsp;możliwym błędem zaokrąglenia – dlatego w&nbsp;programie deklarujemy wektor <code>V</code> o&nbsp;długości <code>floor( log(m)/log(2) ) + 2</code>. Zwracany wektor <code>W</code> ma już prawidłową długość.
 
 
 
<span style="font-size: 90%; color:black;">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);
 
}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L79</span><br/>
 
 
W funkcjach <code>LucasTest()</code> i <code>StrongLucasTest()</code> wykorzystaliśmy zaimplementowaną w&nbsp;PARI/GP funkcję
 
W funkcjach <code>LucasTest()</code> i <code>StrongLucasTest()</code> wykorzystaliśmy zaimplementowaną w&nbsp;PARI/GP funkcję
  
Linia 2962: Linia 2089:
  
 
<references>
 
<references>
 
<ref name="jacobi1">Wikipedia, ''Symbol Jacobiego'', ([https://pl.wikipedia.org/wiki/Symbol_Jacobiego Wiki-pl]), ([https://en.wikipedia.org/wiki/Jacobi_symbol Wiki-en])</ref>
 
 
<ref name="legendre1">Wikipedia, ''Symbol Legendre’a'', ([https://pl.wikipedia.org/wiki/Symbol_Legendre%E2%80%99a Wiki-pl]), ([https://en.wikipedia.org/wiki/Legendre_symbol Wiki-en])</ref>
 
 
<ref name="Norton1">Karl K. Norton, ''Numbers with Small Prime Factors, and the Least ''k''th Power Non-Residue'', Memoirs of the American Mathematical Society, No. 106 (1971)</ref>
 
 
<ref name="Trevino1">Enrique Treviño, ''The least k-th power non-residue'', Journal of Number Theory, Volume 149 (2015)</ref>
 
 
<ref name="Trevino2">Kevin J. McGown and Enrique Treviño, ''The least quadratic non-residue'', Mexican Mathematicians in the World (2021)</ref>
 
 
<ref name="Erdos1">Paul Erdős, ''Számelméleti megjegyzések I'', Afar. Lapok, v. 12 (1961)</ref>
 
  
 
<ref name="BaillieWagstaff1">Robert Baillie and Samuel S. Wagstaff Jr., ''Lucas Pseudoprimes'', Mathematics of Computation Vol. 35, No. 152 (1980), ([http://mpqs.free.fr/LucasPseudoprimes.pdf LINK])</ref>
 
<ref name="BaillieWagstaff1">Robert Baillie and Samuel S. Wagstaff Jr., ''Lucas Pseudoprimes'', Mathematics of Computation Vol. 35, No. 152 (1980), ([http://mpqs.free.fr/LucasPseudoprimes.pdf LINK])</ref>
Linia 2982: Linia 2097:
  
 
<ref name="IntegerSquareRoot1">Wikipedia, ''Integer square root'', ([https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division Wiki-en])</ref>
 
<ref name="IntegerSquareRoot1">Wikipedia, ''Integer square root'', ([https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division Wiki-en])</ref>
 
<ref name="logic1">Wikipedia, ''Logical equivalence'', ([https://en.wikipedia.org/wiki/Logical_equivalence Wiki-en])</ref>
 
 
<ref name="sumazbiorow">Wikipedia, ''Zasada włączeń i wyłączeń'', ([https://pl.wikipedia.org/wiki/Zasada_w%C5%82%C4%85cze%C5%84_i_wy%C5%82%C4%85cze%C5%84 Wiki-pl]), ([https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle Wiki-en])</ref>
 
  
 
<ref name="BPSW1">Wikipedia, ''Baillie–PSW primality test'', ([https://en.wikipedia.org/wiki/Baillie%E2%80%93PSW_primality_test Wiki-en])</ref>
 
<ref name="BPSW1">Wikipedia, ''Baillie–PSW primality test'', ([https://en.wikipedia.org/wiki/Baillie%E2%80%93PSW_primality_test Wiki-en])</ref>

Wersja z 20:48, 22 mar 2023

11.01.2023



Ciągi Lucasa

Definicja L1
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 L2
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 L3
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 L4
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 L5
Początkowe wyrazy ciągów Lucasa


Uwaga L6
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 L7
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]
Dowód

Oznaczmy [math]\displaystyle{ \delta = \sqrt{D} }[/math], zatem [math]\displaystyle{ 2 \alpha = P + \delta }[/math] i [math]\displaystyle{ 2 \beta = P - \delta }[/math]. Ze wzoru dwumianowego, mamy

[math]\displaystyle{ 2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j }[/math]
[math]\displaystyle{ 2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j }[/math]

Obliczając sumę powyższych wzorów, otrzymujemy

[math]\displaystyle{ 2^n (\alpha^n + \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j + (- \delta)^j) }[/math]
[math]\displaystyle{ \quad \: = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} \cdot 2 \delta^{2 k} }[/math]
[math]\displaystyle{ \quad \: = 2 \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k }[/math]

gdzie [math]\displaystyle{ j = 2 k }[/math] i sumowanie przebiega od [math]\displaystyle{ k = 0 }[/math] do [math]\displaystyle{ k = \lfloor n / 2 \rfloor }[/math]

Zatem

[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]


Obliczając różnicę tych wzorów, mamy

[math]\displaystyle{ 2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j) }[/math]
[math]\displaystyle{ \quad \: = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} \cdot 2 \delta^{2 k + 1} }[/math]
[math]\displaystyle{ \quad \: = 2 \delta \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k }[/math]

gdzie [math]\displaystyle{ j = 2 k + 1 }[/math] i sumowanie przebiega od [math]\displaystyle{ k = 0 }[/math] do [math]\displaystyle{ k = \lfloor (n - 1) / 2 \rfloor }[/math]


Zatem

[math]\displaystyle{ 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}} = 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]

Co należało pokazać.


Uwaga L8
Korzystając z twierdzenia L7, 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 L9
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]
Dowód

Niech

[math]\displaystyle{ \alpha = \frac{P + \sqrt{D}}{2} \qquad \qquad \;\; \beta = \frac{P - \sqrt{D}}{2} }[/math]
[math]\displaystyle{ a = \frac{- P + \sqrt{D}}{2} \qquad \qquad b = \frac{- P - \sqrt{D}}{2} }[/math]

Liczby [math]\displaystyle{ \alpha, \beta }[/math] oraz [math]\displaystyle{ a, b }[/math] są odpowiednio pierwiastkami równań

[math]\displaystyle{ x^2 - P x + Q = 0 }[/math]
[math]\displaystyle{ x^2 + P x + Q = 0 }[/math]

Zatem definiują one ciągi Lucasa

[math]\displaystyle{ U_n (P, Q) = \frac{\alpha^n - \beta^n}{\alpha - \beta} \qquad \qquad \;\; V_n (P, Q) = \alpha^n + \beta^n }[/math]
[math]\displaystyle{ U_n (- P, Q) = \frac{a^n - b^n}{a - b} \qquad \qquad V_n (- P, Q) = a^n + b^n }[/math]

Zauważmy, że

[math]\displaystyle{ \alpha - \beta = a - b = \sqrt{D} }[/math]
[math]\displaystyle{ \frac{a}{\beta} = \frac{b}{\alpha} = - 1 }[/math]

Łatwo znajdujemy

[math]\displaystyle{ U_n (- P, Q) = \frac{a^n - b^n}{a - b} = \frac{(- \beta)^n - (- \alpha)^n}{\sqrt{D}} = (- 1)^n \cdot \frac{\beta^n - \alpha^n}{\alpha - \beta} = (- 1)^{n - 1} \cdot U_n (P, Q) }[/math]
[math]\displaystyle{ V_n (- P, Q) = a^n + b^n = (- \beta)^n + (- \alpha)^n = (- 1)^n \cdot (\alpha^n + \beta^n) = (- 1)^n \cdot V_n (P, Q) }[/math]

Co należało pokazać.


Zadanie L10
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]
Rozwiązanie

Niech

[math]\displaystyle{ \alpha = {\small\frac{P + \sqrt{D}}{2}} \qquad \qquad \;\; \beta = {\small\frac{P - \sqrt{D}}{2}} }[/math]
[math]\displaystyle{ a = P + \sqrt{D} \qquad \qquad \;\; b = P - \sqrt{D} }[/math]

Liczby [math]\displaystyle{ \alpha, \beta }[/math] oraz [math]\displaystyle{ a, b }[/math] są odpowiednio pierwiastkami równań

[math]\displaystyle{ x^2 - P x + Q = 0 }[/math]
[math]\displaystyle{ x^2 - 2 P x + 4 Q = 0 }[/math]

Zatem definiują one ciągi Lucasa

[math]\displaystyle{ U_n (P, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \;\;\; V_n (P, Q) = \alpha^n + \beta^n }[/math]
[math]\displaystyle{ U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (2 P, 4 Q) = a^n + b^n }[/math]

Zauważmy, że

[math]\displaystyle{ \alpha - \beta = \sqrt{D} }[/math]
[math]\displaystyle{ a - b = 2 \sqrt{D} }[/math]
[math]\displaystyle{ {\small\frac{a}{\alpha}} = {\small\frac{b}{\beta}} = 2 }[/math]

Łatwo znajdujemy

[math]\displaystyle{ U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} = {\small\frac{(2 \alpha)^n - (2 \beta)^n}{2 \sqrt{D}}} = 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = 2^{n - 1} U_n (P, Q) }[/math]
[math]\displaystyle{ V_n (2 P, 4 Q) = a^n + b^n = (2 \alpha)^n + (2 \beta)^n = 2^n (\alpha^n + \beta^n) = 2^n V_n (P, Q) }[/math]

Co należało pokazać.


Zadanie L11
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]
Rozwiązanie

Niech

[math]\displaystyle{ \alpha = {\small\frac{1 + \sqrt{- P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{- P}}{2}} }[/math]
[math]\displaystyle{ a = {\small\frac{P + \sqrt{- P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{- P}}{2}} }[/math]

Liczby [math]\displaystyle{ \alpha, \beta }[/math] oraz [math]\displaystyle{ a, b }[/math] są odpowiednio pierwiastkami równań

[math]\displaystyle{ x^2 - x + {\small\frac{P + 1}{4}} = 0 }[/math]
[math]\displaystyle{ x^2 - P x + {\small\frac{P (P + 1)}{4}} = 0 }[/math]

Z założenia [math]\displaystyle{ P = 4 Q - 1 }[/math], zatem

[math]\displaystyle{ x^2 - x + Q = 0 }[/math]
[math]\displaystyle{ x^2 - P x + P Q = 0 }[/math]

Czyli definiują one ciągi Lucasa

[math]\displaystyle{ U_n (1, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \:\:\: V_n (1, Q) = \alpha^n + \beta^n }[/math]
[math]\displaystyle{ U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n }[/math]

Zauważmy, że

[math]\displaystyle{ \alpha - \beta = a - b = \sqrt{- P} }[/math]
[math]\displaystyle{ {\small\frac{a}{\beta}} = {\small\frac{P + \sqrt{- P}}{1 - \sqrt{- P}}} = \sqrt{- P} }[/math]
[math]\displaystyle{ {\small\frac{b}{\alpha}} = {\small\frac{P - \sqrt{- P}}{1 + \sqrt{- P}}} = - \sqrt{- P} }[/math]


Łatwo znajdujemy

[math]\displaystyle{ U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k} - \left( - \alpha \sqrt{- P} \right)^{2 k}}{\sqrt{- P}} = \frac{(- P)^k (\beta^{2 k} - \alpha^{2 k})}{\alpha - \beta} = - (- P)^k U_{2 k} (1, Q) }[/math]


[math]\displaystyle{ U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k + 1} - \left( - \alpha \sqrt{- P} \right)^{2 k + 1}}{\sqrt{- P}} = (- P)^k (\beta^{2 k + 1} + \alpha^{2 k + 1}) = (- P)^k V_{2 k + 1} (1, Q) }[/math]


[math]\displaystyle{ V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \beta \sqrt{- P} \right)^{2 k} + \left( - \alpha \sqrt{- P} \right)^{2 k} = (- P)^k (\alpha^{2 k} + \beta^{2 k}) = (- P)^k V_{2 k} (1, Q) }[/math]


[math]\displaystyle{ V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \beta \sqrt{- P} \right)^{2 k + 1} + \left( - \alpha \sqrt{- P} \right)^{2 k + 1} = (- P)^{k + 1} \cdot \frac{\beta^{2 k + 1} - \alpha^{2 k + 1}}{\sqrt{- P}} = - (- P)^{k + 1} U_{2 k + 1} (1, Q) }[/math]

Co należało pokazać.


Zadanie L12
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]
Rozwiązanie

Niech

[math]\displaystyle{ \alpha = {\small\frac{1 + \sqrt{P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{P}}{2}} }[/math]
[math]\displaystyle{ a = {\small\frac{P + \sqrt{P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{P}}{2}} }[/math]

Liczby [math]\displaystyle{ \alpha, \beta }[/math] oraz [math]\displaystyle{ a, b }[/math] są odpowiednio pierwiastkami równań

[math]\displaystyle{ x^2 - x - {\small\frac{P - 1}{4}} = 0 }[/math]
[math]\displaystyle{ x^2 - P x + {\small\frac{P (P - 1)}{4}} = 0 }[/math]

Z założenia [math]\displaystyle{ P = 4 Q + 1 }[/math], zatem

[math]\displaystyle{ x^2 - x - Q = 0 }[/math]
[math]\displaystyle{ x^2 - P x + P Q = 0 }[/math]

Czyli definiują one ciągi Lucasa

[math]\displaystyle{ U_n (1, - Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad V_n (1, - Q) = \alpha^n + \beta^n }[/math]
[math]\displaystyle{ U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n }[/math]

Zauważmy, że

[math]\displaystyle{ \alpha - \beta = a - b = \sqrt{P} }[/math]
[math]\displaystyle{ {\small\frac{a}{\alpha}} = {\small\frac{P + \sqrt{P}}{1 + \sqrt{P}}} = \sqrt{P} }[/math]
[math]\displaystyle{ {\small\frac{b}{\beta}} = {\small\frac{P - \sqrt{P}}{1 - \sqrt{P}}} = - \sqrt{P} }[/math]


Łatwo znajdujemy

[math]\displaystyle{ U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k} - \left( - \beta \sqrt{P} \right)^{2 k}}{\sqrt{P}} = \frac{P^k (\alpha^{2 k} - \beta^{2 k})}{\alpha - \beta} = P^k U_{2 k} (1, - Q) }[/math]


[math]\displaystyle{ U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k + 1} - \left( - \beta \sqrt{P} \right)^{2 k + 1}}{\sqrt{P}} = P^k (\alpha^{2 k + 1} + \beta^{2 k + 1}) = P^k V_{2 k + 1} (1, - Q) }[/math]


[math]\displaystyle{ V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \alpha \sqrt{P} \right)^{2 k} + \left( - \beta \sqrt{P} \right)^{2 k} = P^k (\alpha^{2 k} + \beta^{2 k}) = P^k V_{2 k} (1, - Q) }[/math]


[math]\displaystyle{ V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \alpha \sqrt{P} \right)^{2 k + 1} + \left( - \beta \sqrt{P} \right)^{2 k + 1} = P^{k + 1} \cdot \frac{\alpha^{2 k + 1} - \beta^{2 k + 1}}{\sqrt{P}} = P^{k + 1} U_{2 k + 1} (1, - Q) }[/math]

Co należało pokazać.


Twierdzenie L13
Dla wyrazów ciągów Lucasa prawdziwe są wzory

Dowód

Wzory 1. - 7. najłatwiej udowodnić korzystając z definicji L1.

Wzór 1.

[math]\displaystyle{ U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \quad \: = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} - \alpha \beta \cdot {\small\frac{\alpha^{m - 1} - \beta^{m - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \quad \: = U_m U_{n + 1} - Q U_{m - 1} U_n }[/math]


Wzór 2.

[math]\displaystyle{ V_{m + n} = \alpha^{m + n} + \beta^{m + n} }[/math]
[math]\displaystyle{ \quad \;\! = (\alpha^m + \beta^m) (\alpha^n + \beta^n) - \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n}) }[/math]
[math]\displaystyle{ \quad \;\! = V_m V_n - Q^n V_{m - n} }[/math]


Wzór 3.

[math]\displaystyle{ U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \quad \: = {\small\frac{(\alpha^m - \beta^m) (\alpha^n + \beta^n)}{\alpha - \beta}} - {\small\frac{\alpha^n \beta^n \cdot (\alpha^{m - n} - \beta^{m - n})}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \quad \: = U_m V_n - Q^n U_{m - n} }[/math]


Wzór 4.

[math]\displaystyle{ V_{m + n} = \alpha^{m + n} + \beta^{m + n} }[/math]
[math]\displaystyle{ \quad \;\! = (\alpha - \beta)^2 \cdot {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} + \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n}) }[/math]
[math]\displaystyle{ \quad \;\! = D U_m U_n + Q^n V_{m - n} }[/math]


Wzór 5.

[math]\displaystyle{ U_m V_n - V_m U_n = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot (\alpha^n + \beta^n) - (\alpha^m + \beta^m) \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \;\;\: = 2 \cdot \alpha^n \beta^n \cdot {\small\frac{\alpha^{m - n} - \beta^{m - n}}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \;\;\: = 2 Q^n U_{m - n} }[/math]


Wzór 6.

[math]\displaystyle{ U^2_n = \left( {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \right)^2 }[/math]
[math]\displaystyle{ \;\! = {\small\frac{\alpha^{n - 1} - \beta^{n - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} + \alpha^{n - 1} \beta^{n - 1} }[/math]
[math]\displaystyle{ \;\! = U_{n - 1} U_{n + 1} + Q^{n - 1} }[/math]


Wzór 7.

[math]\displaystyle{ V^2_n = (\alpha^n + \beta^n)^2 }[/math]
[math]\displaystyle{ \;\! = (\alpha^{n - 1} + \beta^{n - 1}) (\alpha^{n + 1} + \beta^{n + 1}) - (\alpha - \beta)^2 \cdot \alpha^{n - 1} \beta^{n - 1} }[/math]
[math]\displaystyle{ \;\! = V_{n - 1} V_{n + 1} - D Q^{n - 1} }[/math]


Wzory 8. - 18. można łatwo udowodnić, korzystając ze wzorów 1. - 7.

Wzór 8. Policzyć sumę wzoru 3. pomnożonego przez [math]\displaystyle{ 2 }[/math] i wzoru 5.

Wzór 9. Policzyć sumę wzorów 2. i 4.

Wzór 10. Połączyć wzory 2. i 4.

Wzór 11. We wzorze 3. położyć [math]\displaystyle{ m = n }[/math].

Wzór 12. We wzorze 2. położyć [math]\displaystyle{ m = n }[/math].

Wzór 13. We wzorze 4. położyć [math]\displaystyle{ m = n }[/math].

Wzór 14. We wzorze 10. położyć [math]\displaystyle{ m = n }[/math] lub połączyć wzory 12. i 13.

Wzór 15. We wzorze 9. położyć [math]\displaystyle{ m = 1 }[/math].

Wzór 16. We wzorze 8. położyć [math]\displaystyle{ m = 1 }[/math].

Wzór 17. We wzorze 15. położyć [math]\displaystyle{ V_{n + 1} = P V_n - Q V_{n - 1} }[/math].

Wzór 18. We wzorze 16. położyć [math]\displaystyle{ U_{n + 1} = P U_n - Q U_{n - 1} }[/math].


Wzory 19. - 21. to wzory, które wykorzystamy w przyszłości do szybkiego obliczania wartości wyrazów [math]\displaystyle{ U_n }[/math] i [math]\displaystyle{ V_n }[/math] modulo.

Wzór 19. Wystarczy połączyć wzory 11. oraz 16.

Wzór 20. Wystarczy we wzorze 1. położyć [math]\displaystyle{ m = n + 1 }[/math].

Wzór 21. Kładąc we wzorze 19. [math]\displaystyle{ n \rightarrow n + 1 }[/math], otrzymujemy

[math]\displaystyle{ U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - P U^2_{n + 1} \qquad (*) }[/math]

Kładąc we wzorze 1. [math]\displaystyle{ m = n + 2 }[/math], mamy

[math]\displaystyle{ U_{2 n + 2} = U_{n + 2} U_{n + 1} - Q U_{n + 1} U_n }[/math]

Czyli

[math]\displaystyle{ 2 U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - 2 Q U_n U_{n + 1} }[/math]

Odejmując od powyższego wzoru wzór [math]\displaystyle{ (*) }[/math], dostajemy wzór 21.

[math]\displaystyle{ U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1} }[/math]

Co należało pokazać.



Obliczanie wyrazów ciągu Lucasa modulo [math]\displaystyle{ m }[/math]

Przykład L14
Pokażemy, jak wykorzystać podane w twierdzeniu L13 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].

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 L15
Uogólniając postępowanie przedstawione w przykładzie L14, 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 L16
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 \, | \, P Q }[/math].


Twierdzenie L17
Niech [math]\displaystyle{ p }[/math] będzie liczbą pierwszą nieparzystą.

●    jeżeli [math]\displaystyle{ \; p \, | \, P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \, | \, Q , \; }[/math] to [math]\displaystyle{ \; p \, | \, U_n \; }[/math] dla [math]\displaystyle{ n \geqslant 2 }[/math]
●    jeżeli [math]\displaystyle{ \; p \, | \, P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \nmid Q , \; }[/math] to [math]\displaystyle{ \; p \, | \, 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 \, | \, Q , \; }[/math] to [math]\displaystyle{ \; p \nmid U_n \; }[/math] dla [math]\displaystyle{ n \geqslant 1 }[/math]
●    jeżeli [math]\displaystyle{ \; p \, | \, Q , \; }[/math] to [math]\displaystyle{ \; p \, | \, U_n }[/math], gdzie [math]\displaystyle{ n \geqslant 2 }[/math], wtedy i tylko wtedy, gdy [math]\displaystyle{ \; p \, | \, P }[/math]
●    jeżeli [math]\displaystyle{ \; p \nmid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \, | \, D , \; }[/math] to [math]\displaystyle{ \; p \, | \, U_n \; }[/math] wtedy i tylko wtedy, gdy [math]\displaystyle{ p \, | \, n }[/math]

Założenie, że [math]\displaystyle{ p \nmid P }[/math] w ostatnim punkcie jest istotne. Gdy [math]\displaystyle{ \; p \, | \, P \; }[/math] i [math]\displaystyle{ \; p \, | \, D , \; }[/math] to [math]\displaystyle{ \; p \, | \, Q \; }[/math] i otrzymujemy punkt pierwszy.

Dowód

Punkt 1.

Ponieważ [math]\displaystyle{ U_2 = P }[/math], zatem [math]\displaystyle{ p \, | \, U_2 }[/math]. Dla [math]\displaystyle{ n \geqslant 3 }[/math] wyrażenie [math]\displaystyle{ U_n = P U_{n - 1} - Q U_{n - 2} }[/math] jest podzielne przez [math]\displaystyle{ p }[/math].

Punkt 2.

Indeksy parzyste. Indukcja matematyczna. Mamy [math]\displaystyle{ U_0 = 0 }[/math] i [math]\displaystyle{ U_2 = P }[/math], zatem [math]\displaystyle{ p \, | \, U_0 }[/math] i [math]\displaystyle{ p \, | \, U_2 }[/math]. Zakładając, że [math]\displaystyle{ p \, | \, U_{2 n} }[/math], z definicji ciągu [math]\displaystyle{ (U_k) }[/math], otrzymujemy dla [math]\displaystyle{ U_{2 n + 2} }[/math]

[math]\displaystyle{ U_{2 n + 2} = P U_{2 n - 1} - Q U_{2 n} }[/math]

Z założenia indukcyjnego wynika, że [math]\displaystyle{ p \, | \, U_{2 n + 2} }[/math], zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich [math]\displaystyle{ n \geqslant 0 }[/math].

Indeksy nieparzyste. Indukcja matematyczna. Mamy [math]\displaystyle{ U_1 = 1 }[/math] i [math]\displaystyle{ U_3 = P^2 - Q }[/math], zatem [math]\displaystyle{ p \nmid U_1 }[/math] i [math]\displaystyle{ p \nmid U_3 }[/math]. Zakładając, że [math]\displaystyle{ p \nmid U_{2 n - 1} }[/math], z definicji ciągu [math]\displaystyle{ (U_k) }[/math], otrzymujemy dla [math]\displaystyle{ U_{2 n + 1} }[/math]

[math]\displaystyle{ U_{2 n + 1} = P U_{2 n} - Q U_{2 n - 1} }[/math]

Z założenia indukcyjnego wynika, że [math]\displaystyle{ p \nmid U_{2 n + 1} }[/math], zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich [math]\displaystyle{ n \geqslant 1 }[/math].

Punkt 3.

Indukcja matematyczna. Mamy [math]\displaystyle{ U_1 = 1 }[/math] i [math]\displaystyle{ U_2 = P }[/math], zatem [math]\displaystyle{ p \nmid U_1 }[/math] i [math]\displaystyle{ p \nmid U_2 }[/math]. Zakładając, że [math]\displaystyle{ p \nmid U_n }[/math] zachodzi dla wszystkich liczb całkowitych dodatnich nie większych od [math]\displaystyle{ n }[/math], z definicji ciągu [math]\displaystyle{ (U_n) }[/math] otrzymujemy dla [math]\displaystyle{ n + 1 }[/math]

[math]\displaystyle{ U_{n + 1} = P U_n - Q U_{n - 1} }[/math]

Z założenia indukcyjnego wynika, że [math]\displaystyle{ p \nmid U_{n + 1} }[/math], zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich liczb [math]\displaystyle{ n \geqslant 1 }[/math].

Punkt 4.

Wynika z punktów pierwszego i trzeciego.

Punkt 5.

Z twierdzenia L7 wiemy, że

[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{ \;\; = n P^{n - 1} + \binom{n}{3} P^{n - 3} D + \binom{n}{5} P^{n - 5} D^2 + \ldots + \begin{cases} n P D^{(n - 2) / 2} & \text{gdy }n\text{ jest parzyste} \\ D^{(n - 1) / 2} & \text{gdy }n\text{ jest nieparzyste} \end{cases} }[/math]

Z założenia [math]\displaystyle{ p \, | \, D }[/math], zatem modulo [math]\displaystyle{ p }[/math] dostajemy

[math]\displaystyle{ 2^{n - 1} U_n \equiv n P^{n - 1} \pmod{p} }[/math]

Ponieważ [math]\displaystyle{ p \nmid P }[/math], zatem [math]\displaystyle{ p \, | \, U_n }[/math] wtedy i tylko wtedy, gdy [math]\displaystyle{ p \, | \, n }[/math]. Co należało pokazać.


Twierdzenie L18
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]
Dowód

Oznaczmy [math]\displaystyle{ \delta = \sqrt{D} }[/math], zatem [math]\displaystyle{ 2 \alpha = P + \delta }[/math] i [math]\displaystyle{ 2 \beta = P - \delta }[/math]. Ze wzoru dwumianowego, mamy

[math]\displaystyle{ 2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j }[/math]
[math]\displaystyle{ 2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j }[/math]


Obliczając różnicę wyjściowych wzorów, mamy

[math]\displaystyle{ 2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j) = }[/math]
[math]\displaystyle{ \quad \: = \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot 2 \delta^j }[/math]
[math]\displaystyle{ \quad \: = 2 \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot \delta \cdot D^{(j - 1) / 2} }[/math]

Rozpatrując powyższą równość modulo [math]\displaystyle{ Q }[/math] dostajemy (zobacz L43)

[math]\displaystyle{ 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\delta}} = 2^{n - 1} U_n \equiv \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot P^{j - 1} }[/math]
[math]\displaystyle{ \;\:\: \equiv P^{n - 1} \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} }[/math]
[math]\displaystyle{ \;\:\: \equiv 2^{n - 1} P^{n - 1} }[/math]

Czyli

[math]\displaystyle{ 2^{n - 1} (U_n - P^{n - 1}) \equiv 0 \pmod{Q} }[/math]

Ponieważ [math]\displaystyle{ Q }[/math] dzieli [math]\displaystyle{ 2^{n - 1} (U_n - P^{n - 1}) }[/math], to tym bardziej [math]\displaystyle{ d }[/math] dzieli [math]\displaystyle{ 2^{n - 1} (U_n - P^{n - 1}) }[/math]. Z założenia [math]\displaystyle{ \gcd (d, 2^{n - 1}) = 1 }[/math], zatem [math]\displaystyle{ d }[/math] dzieli [math]\displaystyle{ U_n - P^{n - 1} }[/math] (zobacz C70).

W przypadku szczególnym, gdy [math]\displaystyle{ d = p }[/math], gdzie [math]\displaystyle{ p }[/math] jest nieparzystą liczbą pierwszą i [math]\displaystyle{ p \nmid P }[/math], z twierdzenia Fermata otrzymujemy natychmiast

[math]\displaystyle{ U_p \equiv P^{p - 1} \equiv 1 \pmod{p} }[/math]

Co należało pokazać.


Twierdzenie L19
Niech [math]\displaystyle{ D = P^2 - 4 Q }[/math], a [math]\displaystyle{ (D \, | \, 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 \, | \, p) \pmod{p} }[/math]
●    jeżeli [math]\displaystyle{ (D \, | \, p) = - 1 , \; }[/math] to [math]\displaystyle{ \; p \, | \, U_{p + 1} }[/math]
●    jeżeli [math]\displaystyle{ (D \, | \, p) = 1 , \; }[/math] to [math]\displaystyle{ \; p \, | \, U_{p - 1} }[/math]
Dowód

Punkt 1.

Zauważmy, że przypadek gdy [math]\displaystyle{ p \, | \, Q }[/math], omówiliśmy w twierdzeniu poprzednim. Z założenia [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą. Z twierdzenia L7, w przypadku nieparzystego [math]\displaystyle{ n = p }[/math], otrzymujemy

[math]\displaystyle{ 2^{p - 1} U_p = p P^{p - 1} + \binom{p}{3} P^{p - 3} D + \binom{p}{5} P^{p - 5} D^2 + \ldots + \binom{p}{p-2} P^2 D^{(p - 3) / 2} + D^{(p - 1) / 2} }[/math]

Ponieważ dla każdego [math]\displaystyle{ k \in [1, p - 1] }[/math] (zobacz L43)

[math]\displaystyle{ \binom{p}{k} \equiv 0 \pmod{p} }[/math]

to modulo [math]\displaystyle{ p }[/math] dostajemy (zobacz J22)

[math]\displaystyle{ 2^{p - 1} U_p \equiv U_p \equiv D^{(p - 1) / 2} \equiv (D \, | \, p) \pmod{p} }[/math]

Punkt 2.

Zauważmy, że warunek [math]\displaystyle{ (D \, | \, p) = - 1 }[/math] nie może być spełniony, gdy [math]\displaystyle{ p \, | \, Q }[/math]. Istotnie, gdy [math]\displaystyle{ p \, | \, Q }[/math], to [math]\displaystyle{ D = P^2 - 4 Q \equiv P^2 \pmod{p} }[/math], czyli

[math]\displaystyle{ (D \, | \, p) = (P^2 \, | \, p) = (P \, | \, p)^2 = 0 , \; }[/math] gdy [math]\displaystyle{ p \, | \, P }[/math]

lub

[math]\displaystyle{ (D \, | \, p) = (P^2 \, | \, p) = (P \, | \, p)^2 = 1 , \; }[/math] gdy [math]\displaystyle{ p \nmid P }[/math]

i nie może być [math]\displaystyle{ (D \, | \, p) = - 1 }[/math].

Dla parzystego [math]\displaystyle{ n = p + 1 }[/math] otrzymujemy z twierdzenia L7

[math]\displaystyle{ 2^p U_{p + 1} = (p + 1) P^p + \binom{p + 1}{3} P^{p - 2} D + \binom{p + 1}{5} P^{p - 4} D^2 + \ldots + \binom{p + 1}{p - 2} P^3 D^{(p - 3) / 2} + (p + 1) P D^{(p - 1) / 2} }[/math]

Ponieważ dla [math]\displaystyle{ k \in [2, p - 1] }[/math] (zobacz L44)

[math]\displaystyle{ \binom{p + 1}{k} \equiv 0 \pmod{p} }[/math]

to modulo [math]\displaystyle{ p }[/math] dostajemy

[math]\displaystyle{ 2 U_{p + 1} \equiv P + P D^{(p - 1) / 2} \pmod{p} }[/math]


Z założenia [math]\displaystyle{ D }[/math] jest liczbą niekwadratową modulo [math]\displaystyle{ p }[/math], zatem [math]\displaystyle{ D^{(p - 1) / 2} \equiv - 1 \pmod{p} }[/math] (zobacz J19). Skąd wynika natychmiast, że

[math]\displaystyle{ 2 U_{p + 1} \equiv 0 \pmod{p} }[/math]

Czyli [math]\displaystyle{ p \, | \, U_{p + 1} }[/math].

Punkt 3.

Dla parzystego [math]\displaystyle{ n = p - 1 }[/math] otrzymujemy z twierdzenia L7

[math]\displaystyle{ 2^{p - 2} U_{p - 1} = (p - 1) P^{p - 2} + \binom{p - 1}{3} P^{p - 4} D + \binom{p - 1}{5} P^{p - 6} D^2 + \ldots + \binom{p - 1}{p - 4} P^3 D^{(p - 5) / 2} + (p - 1) P D^{(p - 3) / 2} }[/math]

Ponieważ dla [math]\displaystyle{ k \in [0, p - 1] }[/math] (zobacz L45)

[math]\displaystyle{ \binom{p - 1}{k} \equiv (- 1)^k \pmod{p} }[/math]

to modulo [math]\displaystyle{ p }[/math] mamy

[math]\displaystyle{ 2^{p - 2} U_{p - 1} \equiv - (P^{p - 2} + P^{p - 4} D + P^{p - 6} D^2 + \ldots + P D^{(p - 3) / 2}) \pmod{p} }[/math]
[math]\displaystyle{ \quad \,\, \equiv - P (P^{p - 3} + P^{p - 5} D + P^{p - 7} D^2 + \ldots + D^{(p - 3) / 2}) \pmod{p} }[/math]


Z założenia [math]\displaystyle{ D }[/math] jest liczbą kwadratową modulo [math]\displaystyle{ p }[/math] (zobacz J17), zatem istnieje taka liczba [math]\displaystyle{ R }[/math], że

[math]\displaystyle{ D \equiv R^2 \pmod{p} }[/math]

Ponieważ

  • [math]\displaystyle{ (D \, | \, p) = 1 }[/math], to [math]\displaystyle{ p \nmid D }[/math], zatem [math]\displaystyle{ p \nmid R }[/math]
  • z założenia [math]\displaystyle{ p \nmid Q }[/math], to [math]\displaystyle{ P^2 - R^2 \equiv P^2 - D \equiv 4 Q \not\equiv 0 \pmod{p} }[/math]


Czyli

[math]\displaystyle{ 2^{p - 2} U_{p - 1} \equiv - P (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p} }[/math]


Uwzględniając, że [math]\displaystyle{ P^2 - R^2 \not\equiv 0 \pmod{p} }[/math], możemy napisać

[math]\displaystyle{ 2^{p - 2} (P^2 - R^2) U_{p - 1} \equiv - P (P^2 - R^2) (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p} }[/math]
[math]\displaystyle{ \equiv - P (P^{p - 1} - R^{p - 1}) \pmod{p} }[/math]
[math]\displaystyle{ \equiv 0 \pmod{p} }[/math]

Zauważmy, że wynik nie zależy od tego, czy [math]\displaystyle{ p \, | \, P }[/math], czy [math]\displaystyle{ p \nmid P }[/math]. Skąd wynika

[math]\displaystyle{ U_{p - 1} \equiv 0 \pmod{p} }[/math]

Co należało pokazać.


Aby zapisać punkty 2. i 3. twierdzenia L19 (i tylko te punkty) w zwartej formie, musimy założyć, że [math]\displaystyle{ \gcd (p, D) = 1 }[/math]. Otrzymujemy
Twierdzenie L20
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 \, | \, p)} \equiv 0 \pmod{p} }[/math]



Liczby pseudopierwsze Lucasa

Uwaga L21
Z twierdzenia L20 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 \, | \, p)} }[/math], gdzie [math]\displaystyle{ (D \, | \, 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 \, | \, m)} \equiv 0 \pmod{m} }[/math]

również jest prawdziwa. Prowadzi to definicji liczb pseudopierwszych Lucasa.


Definicja L22
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 \, | \, m)} \equiv 0 \pmod{m} }[/math]

gdzie [math]\displaystyle{ (D \, | \, m) }[/math] oznacza symbol Jacobiego.


Twierdzenie L23
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].

Dowód

Połóżmy we wzorze definiującym ciąg Lucasa

[math]\displaystyle{ U_m = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} }[/math]

[math]\displaystyle{ \alpha = a }[/math] i [math]\displaystyle{ \beta = 1 }[/math]. Odpowiada to parametrom [math]\displaystyle{ P = \alpha + \beta = a + 1 }[/math], [math]\displaystyle{ Q = \alpha \beta = a }[/math], [math]\displaystyle{ D = (\alpha - \beta)^2 = (a - 1)^2 }[/math].

Ponieważ musi być [math]\displaystyle{ \gcd (m, Q D) = 1 }[/math], to mamy [math]\displaystyle{ \gcd (m, (a - 1) a) = 1 }[/math] i wynika stąd, że [math]\displaystyle{ (D \, | \, m) = 1 }[/math]. Z założenia [math]\displaystyle{ m }[/math] jest liczbą pseudopierwszą Lucasa dla parametrów [math]\displaystyle{ P = a + 1 }[/math] i [math]\displaystyle{ Q = a }[/math], zatem

[math]\displaystyle{ U_{m - 1} (a + 1, a) \equiv 0 \pmod{m} }[/math]

Czyli

[math]\displaystyle{ {\small\frac{a^{m - 1} - 1}{a - 1}} \equiv 0 \pmod{m} }[/math]

Jeżeli [math]\displaystyle{ m \biggr\rvert {\small\frac{a^{m - 1} - 1}{a - 1}} }[/math], to tym bardziej [math]\displaystyle{ m \big\rvert (a^{m - 1} - 1) }[/math] i możemy napisać

[math]\displaystyle{ a^{m - 1} - 1 \equiv 0 \pmod{m} }[/math]

Zatem [math]\displaystyle{ m }[/math] jest liczbą pseudopierwszą Fermata przy podstawie [math]\displaystyle{ a }[/math]. Co należało pokazać.


Uwaga L24
Wykorzystując funkcje jacobi(a, n) i modLucas(n, P, Q, m) (zobacz J34, L15) możemy napisać prosty program, który sprawdza, czy dla liczby nieparzystej [math]\displaystyle{ m }[/math] prawdziwe jest twierdzenie L20.

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 L25
Poniższa tabela zawiera najmniejsze liczby pseudopierwsze Lucasa dla różnych parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math]

Pokaż kod
FirstLPSP(Stop) = 
\\ najmniejsze LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
{
local(D, m, P, Q);
Q = -6;
while( Q++ <= 5,
       if( Q == 0, next() );
       P = 0;
       while( P++ <= 10,
              D = P^2 - 4*Q;
              if( D == 0, 
                  print("Q= ", Q, "   P= ", P, "   ------------------");
                  next();
                );
              m = 3;
              while( m < Stop,
                     if( isPrimeOrLPSP(m, P, Q)  &&  !isprime(m),
                         print("Q= ", Q, "   P= ", P, "   m= ", m, "   (D|m)= ", jacobi(D, m));
                         break();
                       );
                     m = m + 2;
                   );
            );
     );
}


Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których [math]\displaystyle{ (D \, | \, m) = - 1 }[/math].


Przykład L26
Ilość liczb LPSP([math]\displaystyle{ P, Q }[/math]) mniejszych od [math]\displaystyle{ 10^9 }[/math]

Pokaż kod
NumOfLPSP(Stop) = 
\\ ilość liczb pseudopierwszych Lucasa LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
{
local(D, m, P, Q);
Q = -6;
while( Q++ <= 5,
       if( Q == 0, next() );
       P = 0;
       while( P++ <= 10,
              D = P^2 - 4*Q;
              if( D == 0, print("Q= ", Q, "   P= ", P, "   ------------------"); next() );
              s = 0;
              m = 3;
              while( m < Stop,
                     if( isPrimeOrLPSP(m, P, Q)  &&  !isprime(m), s++ );
                     m = m + 2;
                   );
              print("Q= ", Q, "   P= ", P, "   s= ", s);
            );
     );
}



Uwaga L27
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 L13 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 \, | \, m }[/math], bo mielibyśmy [math]\displaystyle{ \gcd (m, Q D) = 3 \gt 1 }[/math].

Z zadania J32 wiemy, że

[math]\displaystyle{ (- 3 \, | \, 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 \, | \, 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 \, | \, 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 \, | \, 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 L28
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 L29
Twierdzenie L20 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 \, | \, 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ę.


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 L22


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 J28)

[math]\displaystyle{ (a \, | \, 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 \, | \, a }[/math] i [math]\displaystyle{ m \nmid a }[/math].

Gdy [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] i [math]\displaystyle{ m \, | \, 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 \, | \, 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 L30. 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 \, | \, 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 L17), 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 L20 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 L30
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 \, | \, 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].

Rozwiązanie

Niech [math]\displaystyle{ m = 21 }[/math]. Rozpoczniemy od przykładu liczb [math]\displaystyle{ a_k = (- 1)^k (2 k + 1) }[/math] dla [math]\displaystyle{ k = 0, 1, \ldots, m - 1 }[/math].

Zauważmy, że modulo [math]\displaystyle{ 21 }[/math] ciąg [math]\displaystyle{ (a_k) = (1, - 3, 5, - 7, \ldots, 37, - 39, 41) }[/math] jest identyczny z ciągiem [math]\displaystyle{ (0, 1, 2, \ldots, 19, 20) }[/math], a ciąg [math]\displaystyle{ (| a_k |) }[/math] to kolejne liczby nieparzyste od [math]\displaystyle{ 1 }[/math] do [math]\displaystyle{ 2 m - 1 }[/math].


Poniżej pokażemy, dlaczego musi być [math]\displaystyle{ \gcd (Q, m) = 1 }[/math], gdzie [math]\displaystyle{ Q }[/math] jest liczbą wyznaczoną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby [math]\displaystyle{ m }[/math] przy testowaniu kolejnych liczb [math]\displaystyle{ a_k }[/math]). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby [math]\displaystyle{ m }[/math]. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość [math]\displaystyle{ Q }[/math] na podstawie innego wyrazu ciągu [math]\displaystyle{ a_k }[/math] (ten symbol Jacobiego został zapisany zwykłą czcionką).

[math]\displaystyle{ m = 3 , \;\; (5 \, | \, 3) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 5 , \;\; (5 \, | \, 5) = 0 , \;\; (- 7 \, | \, 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 \;\; }[/math] (zauważmy, że [math]\displaystyle{ (5 \, | \, 5) = 0 }[/math] nie pozwala wnioskować o złożoności)
[math]\displaystyle{ m = 7 , \;\; (5 \, | \, 7) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 9 , \;\; }[/math] (liczba kwadratowa)
[math]\displaystyle{ m = 11 , \;\; (- 11 \, | \, 11) = 0 , \;\; (13 \, | \, 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\; }[/math] (zauważmy, że [math]\displaystyle{ (- 11 \, | \, 11) = 0 }[/math] nie pozwala wnioskować o złożoności)
[math]\displaystyle{ m = 13 , \;\; (5 \, | \, 13) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 15 , \;\; \boldsymbol{(5 \, | \, 15) = 0} , \;\; (13 \, | \, 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\; }[/math] (gdyby nie zbadano złożoności)
[math]\displaystyle{ m = 17 , \;\; (5 \, | \, 17) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 19 , \;\; (- 7 \, | \, 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 21 , \;\; \boldsymbol{(- 7 \, | \, 21) = 0} , \;\; (- 11 \, | \, 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\; }[/math] (gdyby nie zbadano złożoności)


Niech [math]\displaystyle{ m \geqslant 23 }[/math]. Wiemy, że w ciągu [math]\displaystyle{ (5, - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1) }[/math] wystąpią liczby [math]\displaystyle{ a_k }[/math] takie, że [math]\displaystyle{ (a_k \, | \, m) = - 1 }[/math]. Warunek [math]\displaystyle{ (a_k \, | \, m) = 0 }[/math] oznacza, że [math]\displaystyle{ (2 k + 1 \, | \, m) = 0 }[/math], bo

[math]\displaystyle{ (a_k \, | \, m) = ((- 1)^k (2 k + 1) \, | \, m) = ((- 1)^k \, | \, m) \cdot (2 k + 1 \, | \, m) = (- 1 \, | \, m)^k \cdot (2 k + 1 \, | \, m) = \pm (2 k + 1 \, | \, m) }[/math]

Jeżeli będą spełnione warunki [math]\displaystyle{ (a_k \, | \, m) = 0 }[/math] i [math]\displaystyle{ R_m (a_k) \neq 0 }[/math], to liczba [math]\displaystyle{ m }[/math] będzie liczbą złożoną.

Wypiszmy kolejne próby dla [math]\displaystyle{ m \geqslant 23 }[/math]. Liczba [math]\displaystyle{ r }[/math] jest numerem próby.

[math]\displaystyle{ r = 1 , \;\; a_{r + 1} = 5 }[/math]
●    [math]\displaystyle{ (5 \, | \, m) = 1 }[/math] [math]\displaystyle{ 5 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (5 \, | \, m) = 0 }[/math] [math]\displaystyle{ 5 \, | \, m }[/math] koniec
●    [math]\displaystyle{ (5 \, | \, m) = - 1 \quad }[/math] [math]\displaystyle{ 5 \nmid m }[/math] [math]\displaystyle{ D = 5 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec
[math]\displaystyle{ r = 2 , \;\; a_{r + 1} = - 7 }[/math]
●    [math]\displaystyle{ (- 7 \, | \, m) = 1 }[/math] [math]\displaystyle{ 7 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (- 7 \, | \, m) = 0 }[/math] [math]\displaystyle{ 7 \, | \, m }[/math] koniec
●    [math]\displaystyle{ (- 7 \, | \, m) = - 1 \quad }[/math] [math]\displaystyle{ 7 \nmid m }[/math] [math]\displaystyle{ D = -7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec
[math]\displaystyle{ r = 3 }[/math], [math]\displaystyle{ a_{r + 1} = 9 }[/math]
●    [math]\displaystyle{ (9 \, | \, m) = 1 }[/math] [math]\displaystyle{ 3 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (9 \, | \, m) = 0 }[/math] [math]\displaystyle{ 3 \, | \, m }[/math] koniec
●    [math]\displaystyle{ (9 \, | \, m) \neq - 1 \quad }[/math] - - - - bo [math]\displaystyle{ 9 }[/math] jest liczbą kwadratową


Po wykonaniu trzech prób niezakończonych sukcesem (tzn. wykryciem złożoności [math]\displaystyle{ m }[/math] lub ustaleniem wartości liczb [math]\displaystyle{ D }[/math] i [math]\displaystyle{ Q }[/math]) wiemy, że [math]\displaystyle{ m }[/math] nie jest podzielna przez żadną z liczb pierwszych [math]\displaystyle{ p = 3, 5, 7 }[/math].

[math]\displaystyle{ r }[/math]-ta próba, gdzie [math]\displaystyle{ r \geqslant 4 , \;\; }[/math] wyraz [math]\displaystyle{ a_{r + 1} }[/math]
●    [math]\displaystyle{ (a_{r + 1} \, | \, m) = 1 }[/math] żadna liczba pierwsza [math]\displaystyle{ p \leqslant | a_{r + 1} | = 2 r + 3 }[/math] nie dzieli liczby [math]\displaystyle{ m \quad }[/math]     przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (a_{r + 1} \, | \, m) = 0 }[/math] A. jeżeli [math]\displaystyle{ m \, | \, a_{r + 1} }[/math]( * )
B. jeżeli [math]\displaystyle{ m \nmid a_{r + 1} }[/math]
A. przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
B. [math]\displaystyle{ a_{r + 1} \, | \, m }[/math]( ** ), koniec
●    [math]\displaystyle{ (a_{r + 1} \, | \, m) = - 1 \quad }[/math] żadna liczba pierwsza [math]\displaystyle{ p \leqslant | a_{r + 1} | = 2 r + 3 }[/math] nie dzieli liczby [math]\displaystyle{ m \quad }[/math]     [math]\displaystyle{ D = a_{r + 1} }[/math], [math]\displaystyle{ Q = {\small\frac{1 - a_{r + 1}}{4}} }[/math], koniec

( * ) jest to możliwe tylko dla [math]\displaystyle{ a_{r + 1} = a_{(m - 1) / 2} = m }[/math]

( ** ) zauważmy, że jeżeli [math]\displaystyle{ m \nmid a_{r + 1} }[/math], to [math]\displaystyle{ \gcd (a_{r + 1}, m) = | a_{r + 1} | }[/math], bo gdyby liczba [math]\displaystyle{ | a_{r + 1} | }[/math] była liczbą złożoną, to żaden z jej dzielników pierwszych nie dzieliłby liczby [math]\displaystyle{ m }[/math]


Jeżeli nie została wykryta złożoność liczby [math]\displaystyle{ m }[/math], to żadna z liczb pierwszych [math]\displaystyle{ p \leqslant | a_{r + 1} | = 2 r + 3 }[/math] nie dzieli liczby [math]\displaystyle{ m }[/math]. Zatem [math]\displaystyle{ \gcd (Q, m) \gt 1 }[/math] może być tylko w przypadku, gdy pewna liczba pierwsza [math]\displaystyle{ q \geqslant 2 r + 5 }[/math] będzie wspólnym dzielnikiem liczb [math]\displaystyle{ Q }[/math] i [math]\displaystyle{ m }[/math], ale jest to niemożliwe, bo

[math]\displaystyle{ | Q | = \left| {\small\frac{1 - a_{r + 1}}{4}} \right| \leqslant {\small\frac{| a_{r + 1} | + 1}{4}} = {\small\frac{2 r + 4}{4}} \lt 2 r + 5 \leqslant q }[/math]

Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich [math]\displaystyle{ r }[/math] naturalnych.


Zadanie L31
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 \, | \, 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].

Rozwiązanie

Poniżej pokażemy, dlaczego musi być [math]\displaystyle{ \gcd (Q, m) = 1 }[/math], gdzie [math]\displaystyle{ Q }[/math] jest liczbą wyznaczoną zmodyfikowaną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby [math]\displaystyle{ m }[/math] przy testowaniu kolejnych liczb [math]\displaystyle{ a_k }[/math]). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby [math]\displaystyle{ m }[/math]. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość [math]\displaystyle{ Q }[/math] na podstawie innego wyrazu ciągu [math]\displaystyle{ a_k }[/math] (ten symbol Jacobiego został zapisany zwykłą czcionką).

[math]\displaystyle{ m = 3 , \;\; (- 7 \, | \, 3) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 5 , \;\; (- 7 \, | \, 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 7 , \;\; (- 7 \, | \, 7) = 0 , \;\; (- 11 \, | \, 7) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1 }[/math] (zauważmy, że [math]\displaystyle{ (- 7 \, | \, 7) = 0 }[/math] nie pozwala wnioskować o złożoności)
[math]\displaystyle{ m = 9 , \;\; }[/math] (liczba kwadratowa)
[math]\displaystyle{ m = 11 , \;\; (- 11 \, | \, 11) = 0 , \;\; (13 \, | \, 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\; }[/math] (zauważmy, że [math]\displaystyle{ (- 11 \, | \, 11) = 0 }[/math] nie pozwala wnioskować o złożoności)
[math]\displaystyle{ m = 13 , \;\; (- 7 \, | \, 13) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 15 , \;\; \boldsymbol{(9 \, | \, 15) = 0} , \;\; (13 \, | \, 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\; }[/math] (gdyby nie zbadano złożoności)
[math]\displaystyle{ m = 17 , \;\; (- 7 \, | \, 17) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 19 , \;\; (- 7 \, | \, 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 21 , \;\; \boldsymbol{(- 7 \, | \, 21) = 0} , \;\; (- 11 \, | \, 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\; }[/math] (gdyby nie zbadano złożoności)


Niech [math]\displaystyle{ m \geqslant 23 }[/math]. Wiemy, że w ciągu [math]\displaystyle{ ( - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1) }[/math] wystąpią liczby [math]\displaystyle{ a_k }[/math] takie, że [math]\displaystyle{ (a_k \, | \, m) = - 1 }[/math]. Warunek [math]\displaystyle{ (a_k \, | \, m) = 0 }[/math] oznacza, że [math]\displaystyle{ (2 k + 1 \, | \, m) = 0 }[/math], bo

[math]\displaystyle{ (a_k \, | \, m) = ((- 1)^k (2 k + 1) \, | \, m) = ((- 1)^k \, | \, m) \cdot (2 k + 1 \, | \, m) = (- 1 \, | \, m)^k \cdot (2 k + 1 \, | \, m) = \pm (2 k + 1 \, | \, m) }[/math]

Jeżeli będą spełnione warunki [math]\displaystyle{ (a_k \, | \, m) = 0 }[/math] i [math]\displaystyle{ R_m (a_k) \neq 0 }[/math], to liczba [math]\displaystyle{ m }[/math] będzie liczbą złożoną.

Wypiszmy kolejne próby dla [math]\displaystyle{ m \geqslant 23 }[/math]. Liczba [math]\displaystyle{ r }[/math] jest numerem próby.

[math]\displaystyle{ r = 1 , \;\; a_{r + 2} = - 7 }[/math]
●    [math]\displaystyle{ (- 7 \, | \, m) = 1 }[/math] [math]\displaystyle{ 7 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (- 7 \, | \, m) = 0 }[/math] [math]\displaystyle{ 7 \, | \, m }[/math] koniec
●    [math]\displaystyle{ (- 7 \, | \, m) = - 1 \quad }[/math] [math]\displaystyle{ 7 \nmid m }[/math] [math]\displaystyle{ D = - 7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec
[math]\displaystyle{ r = 2 , \;\; a_{r + 2} = 9 }[/math]
●    [math]\displaystyle{ (9 \, | \, m) = 1 }[/math] [math]\displaystyle{ 3 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (9 \, | \, m) = 0 }[/math] [math]\displaystyle{ 3 \, | \, m }[/math] koniec
●    [math]\displaystyle{ (9 \, | \, m) \neq - 1 \quad }[/math] - - - - bo [math]\displaystyle{ 9 }[/math] jest liczbą kwadratową
[math]\displaystyle{ r = 3 , \;\; a_{r + 2} = - 11 }[/math]
●    [math]\displaystyle{ (- 11 \, | \, m) = 1 }[/math] [math]\displaystyle{ 11 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (- 11 \, | \, m) = 0 }[/math] [math]\displaystyle{ 11 \, | \, m }[/math] koniec
●    [math]\displaystyle{ (- 11 \, | \, m) = - 1 \quad }[/math] [math]\displaystyle{ 11 \nmid m }[/math] [math]\displaystyle{ D = - 11 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec (bo liczby złożone [math]\displaystyle{ m = 3 k }[/math] zostały usunięte w poprzedniej próbie, [math]\displaystyle{ r = 2 }[/math])
[math]\displaystyle{ r = 4 , \;\; a_{r + 2} = 13 }[/math]
●    [math]\displaystyle{ (13 \, | \, m) = 1 }[/math] [math]\displaystyle{ 13 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (13 \, | \, m) = 0 }[/math] [math]\displaystyle{ 13 \, | \, m }[/math] koniec
●    [math]\displaystyle{ (13 \, | \, m) = - 1 \quad }[/math] [math]\displaystyle{ 13 \nmid m }[/math] [math]\displaystyle{ D = 13 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec (bo liczby złożone [math]\displaystyle{ m = 3 k }[/math] zostały usunięte w próbie o numerze [math]\displaystyle{ r = 2 }[/math])
[math]\displaystyle{ r = 5 , \;\; a_{r + 2} = - 15 }[/math]
●    [math]\displaystyle{ (- 15 \, | \, m) = 1 }[/math] [math]\displaystyle{ 5 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (- 15 \, | \, m) = 0 }[/math] [math]\displaystyle{ 5 \, | \, m }[/math] koniec
●    [math]\displaystyle{ (- 15 \, | \, m) = - 1 \quad }[/math] [math]\displaystyle{ 5 \nmid m }[/math] [math]\displaystyle{ D = - 15 , \;\; Q = 4 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec


Po wykonaniu pięciu prób niezakończonych sukcesem (tzn. wykryciem złożoności [math]\displaystyle{ m }[/math] lub ustaleniem wartości liczb [math]\displaystyle{ D }[/math] i [math]\displaystyle{ Q }[/math]) wiemy, że [math]\displaystyle{ m }[/math] nie jest podzielna przez żadną z liczb pierwszych [math]\displaystyle{ p = 3, 5, 7, 11, 13 }[/math].

[math]\displaystyle{ r }[/math]-ta próba, gdzie [math]\displaystyle{ r \geqslant 6 , \;\; }[/math] wyraz [math]\displaystyle{ a_{r + 2} }[/math]
●    [math]\displaystyle{ (a_{r + 2} \, | \, m) = 1 }[/math] żadna liczba pierwsza [math]\displaystyle{ p \leqslant | a_{r + 2} | = 2 r + 5 }[/math] nie dzieli liczby [math]\displaystyle{ m \quad }[/math]     przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (a_{r + 2} \, | \, m) = 0 }[/math] A. jeżeli [math]\displaystyle{ m \, | \, a_{r + 2} }[/math]( * )
B. jeżeli [math]\displaystyle{ m \nmid a_{r + 2} }[/math]
A. przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
B. [math]\displaystyle{ a_{r + 1} \, | \, m }[/math]( ** ), koniec
●    [math]\displaystyle{ (a_{r + 2} \, | \, m) = - 1 \quad }[/math] żadna liczba pierwsza [math]\displaystyle{ p \leqslant | a_{r + 2} | = 2 r + 5 }[/math] nie dzieli liczby [math]\displaystyle{ m \quad }[/math]     [math]\displaystyle{ D = a_{r + 2} }[/math], [math]\displaystyle{ Q = {\small\frac{1 - a_{r + 2}}{4}} }[/math], koniec

( * ) jest to możliwe tylko dla [math]\displaystyle{ a_{r + 2} = a_{(m - 1) / 2} = m }[/math]

( ** ) zauważmy, że jeżeli [math]\displaystyle{ m \nmid a_{r + 2} }[/math], to [math]\displaystyle{ \gcd (a_{r + 2}, m) = | a_{r + 2} | }[/math], bo gdyby liczba [math]\displaystyle{ | a_{r + 2} | }[/math] była liczbą złożoną, to żaden z jej dzielników pierwszych nie dzieliłby liczby [math]\displaystyle{ m }[/math]


Jeżeli nie została wykryta złożoność liczby [math]\displaystyle{ m }[/math], to żadna z liczb pierwszych [math]\displaystyle{ p \leqslant | a_{r + 2} | = 2 r + 5 }[/math] nie dzieli liczby [math]\displaystyle{ m }[/math]. Zatem [math]\displaystyle{ \gcd (Q, m) \gt 1 }[/math] może być tylko w przypadku, gdy pewna liczba pierwsza [math]\displaystyle{ q \geqslant 2 r + 7 }[/math] będzie wspólnym dzielnikiem liczb [math]\displaystyle{ Q }[/math] i [math]\displaystyle{ m }[/math], ale jest to niemożliwe, bo

[math]\displaystyle{ | Q | = \left| {\small\frac{1 - a_{r + 2}}{4}} \right| \leqslant {\small\frac{| a_{r + 2} | + 1}{4}} = {\small\frac{2 r + 6}{4}} \lt 2 r + 7 \leqslant q }[/math]

Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich [math]\displaystyle{ r }[/math] naturalnych.


Uwaga L32
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 L33
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]
Pokaż kod
forstep(k=1, 3*10^4, 2, if( LucasTest(k) && !isprime(k), print(k)) )



Tabela przedstawia ilość takich liczb nie większych od [math]\displaystyle{ 10^n }[/math]

Pokaż kod
for(n=3, 9, s=0; forstep(k = 1, 10^n, 2, if( LucasTest(k) && !isprime(k), s++ ) ); print("n= ", n, "   ", s) )




Liczby silnie pseudopierwsze Lucasa

Twierdzenie L34
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 \, | \, 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]
Dowód

Wiemy (zobacz L20), że jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą taką, że [math]\displaystyle{ \gcd (p, Q D) = 1 }[/math], to [math]\displaystyle{ p \, | \, U_{p - (D \, | \, p)} }[/math]. Z założenia jest [math]\displaystyle{ p - (D \, | \, p) = 2^r w }[/math], zatem [math]\displaystyle{ p \, | \, U_{2^r w} }[/math]. Ponieważ założyliśmy, że [math]\displaystyle{ p \nmid Q }[/math] i [math]\displaystyle{ p \nmid D }[/math], to ze wzoru [math]\displaystyle{ V^2_n - D U^2_n = 4 Q^n }[/math] (zobacz L13 p.14) wynika natychmiast, że [math]\displaystyle{ p }[/math] nie może dzielić jednocześnie liczb [math]\displaystyle{ U_n }[/math] i [math]\displaystyle{ V_n }[/math].

Korzystając ze wzoru [math]\displaystyle{ U_{2 n} = U_n V_n }[/math] (zobacz L13 p.11), otrzymujemy

●    [math]\displaystyle{ p \, | \, U_{2^r w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2^{r - 1} w} \cdot V_{2^{r - 1} w} \quad }[/math] Jeżeli [math]\displaystyle{ p \, | \, V_{2^{r - 1} w} }[/math], to twierdzenie jest dowiedzione. Jeżeli [math]\displaystyle{ p \nmid V_{2^{r - 1} w} }[/math], to [math]\displaystyle{ p \, | \, U_{2^{r - 1} w} }[/math].
●    [math]\displaystyle{ p \, | \, U_{2^{r - 1} w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2^{r - 2} w} \cdot V_{2^{r - 2} w} \quad }[/math] Jeżeli [math]\displaystyle{ p \, | \, V_{2^{r - 2} w} }[/math], to twierdzenie jest dowiedzione. Jeżeli [math]\displaystyle{ p \nmid V_{2^{r - 2} w} }[/math], to [math]\displaystyle{ p \, | \, U_{2^{r - 2} w} }[/math].
●    [math]\displaystyle{ ................. }[/math]
●    [math]\displaystyle{ p \, | \, U_{4 w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2 w} \cdot V_{2 w} }[/math] Jeżeli [math]\displaystyle{ p \, | \, V_{2 w} }[/math], to twierdzenie jest dowiedzione. Jeżeli [math]\displaystyle{ p \nmid V_{2 w} }[/math], to [math]\displaystyle{ p \, | \, U_{2 w} }[/math].
●    [math]\displaystyle{ p \, | \, U_{2 w} \;\; \Longleftrightarrow \;\; p \, | \, U_w \cdot V_w }[/math] Jeżeli [math]\displaystyle{ p \, | \, V_w }[/math], to twierdzenie jest dowiedzione. Jeżeli [math]\displaystyle{ p \nmid V_w }[/math], to [math]\displaystyle{ p \, | \, U_w }[/math].

Z powyższego wynika, że musi być spełniony jeden z wypisanych w twierdzeniu warunków.


Zauważmy teraz, że jeżeli liczba pierwsza [math]\displaystyle{ p }[/math] dzieli [math]\displaystyle{ V_w }[/math], to [math]\displaystyle{ p \nmid U_w }[/math], bo [math]\displaystyle{ p }[/math] nie może jednocześnie być dzielnikiem liczb [math]\displaystyle{ U_w }[/math] i [math]\displaystyle{ V_w }[/math].

Zauważmy też, że jeżeli dla pewnego [math]\displaystyle{ k \in [1, r - 1] }[/math] liczba pierwsza [math]\displaystyle{ p }[/math] dzieli [math]\displaystyle{ V_{2^k w} }[/math], to [math]\displaystyle{ p }[/math] nie dzieli żadnej liczby [math]\displaystyle{ V_{2^j w} }[/math] dla [math]\displaystyle{ j \in [0, k - 1] \;\; \text{i} \;\; p \nmid U_w }[/math]. Istotnie:

●    jeżeli [math]\displaystyle{ p \, | \, V_{2^k w} }[/math], to [math]\displaystyle{ p \nmid U_{2^k w} \;\; \text{i} \;\; U_{2^k w} = U_{2^{k - 1} w} V_{2^{k - 1} w} }[/math], zatem [math]\displaystyle{ p }[/math] nie może być dzielnikiem żadnej z liczb [math]\displaystyle{ U_{2^{k - 1} w} \;\; \text{i} \;\; V_{2^{k - 1} w} }[/math]
●    jeżeli [math]\displaystyle{ p \nmid U_{2^{k - 1} w} \;\; \text{i} \;\; U_{2^{k - 1} w} = U_{2^{k - 2} w} V_{2^{k - 2} w} }[/math], to [math]\displaystyle{ p }[/math] nie może być dzielnikiem żadnej z liczb [math]\displaystyle{ U_{2^{k - 2} w} \;\; \text{i} \;\; V_{2^{k - 2} w} }[/math]
●    [math]\displaystyle{ ................. }[/math]
●    jeżeli [math]\displaystyle{ p \nmid U_{4 w} \;\; \text{i} \;\; U_{4 w} = U_{2 w} V_{2 w} }[/math], to [math]\displaystyle{ p }[/math] nie może być dzielnikiem żadnej z liczb [math]\displaystyle{ U_{2 w} \;\; \text{i} \;\; V_{2 w} }[/math]
●    jeżeli [math]\displaystyle{ p \nmid U_{2 w} \;\; \text{i} \;\; U_{2 w} = U_w V_w }[/math], to [math]\displaystyle{ p }[/math] nie może być dzielnikiem żadnej z liczb [math]\displaystyle{ U_w \;\; \text{i} \;\; V_w }[/math]


Co dowodzi, że spełniony jest dokładnie jeden z [math]\displaystyle{ r + 1 }[/math] warunków:

[math]\displaystyle{ U_w \equiv 0 \pmod{p} }[/math]
[math]\displaystyle{ V_{2^k w} \equiv 0 \pmod{p} \qquad }[/math] gdzie [math]\displaystyle{ k \in [0, r - 1] }[/math]

Co należało pokazać.


Konsekwentnie definiujemy liczby pseudopierwsze
Definicja L35
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 \, | \, 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 L36
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 K2, J34, L15), możemy napisać prosty program, który sprawdza, czy liczba [math]\displaystyle{ m }[/math] spełnia jeden z warunków podanych w twierdzeniu L34.

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 L37
Poniższa tabela zawiera najmniejsze liczby silnie pseudopierwsze Lucasa dla różnych parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math]

Pokaż kod
FirstSLPSP(Stop) = 
\\ najmniejsze SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
{
local(D, m, P, Q);
Q = -6;
while( Q++ <= 5,
       if( Q == 0, next() );
       P = 0;
       while( P++ <= 10,
              D = P^2 - 4*Q;
              if( D == 0, 
                  print("Q= ", Q, "   P= ", P, "   ------------------");
                  next();
                );
              m = 3;
              while( m < Stop,
                     if( isPrimeOrSLPSP(m, P, Q)  &&  !isprime(m), 
                         print("Q= ", Q, "   P= ", P, "   m= ", m, "   (D|m)= ", jacobi(D, m));
                         break();
                       );
                     m = m + 2;
                   );
           );
     );
}


Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których [math]\displaystyle{ (D \, | \, m) = - 1 }[/math].


Przykład L38
Ilość liczb SLPSP([math]\displaystyle{ P, Q }[/math]) mniejszych od [math]\displaystyle{ 10^9 }[/math]


Pokaż kod
NumOfSLPSP(Stop) = 
\\ ilość liczb silnie pseudopierwszych Lucasa SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
{
local(D, m, P, Q);
Q = -6;
while( Q++ <= 5,
       if( Q == 0, next() );
       P = 0;
       while( P++ <= 10,
              D = P^2 - 4*Q;
              if( D == 0, print("Q= ", Q, "   P= ", P, "   ------------------"); next() );
              s = 0;
              m = 3;
              while( m < Stop,
                     if( isPrimeOrSLPSP(m, P, Q)  &&  !isprime(m), s++ );
                     m = m + 2;
                   );
              print("Q= ", Q, "   P= ", P, "   s= ", s);
            );
     );
}



Uwaga L39
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 \, | \, p) = - (D \, | \, 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 L40
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 L36. Teraz parametry [math]\displaystyle{ P, Q }[/math] są wybierane metodą Selfridge'a, a symbol Jacobiego [math]\displaystyle{ (D \, | \, m) }[/math] jest równy [math]\displaystyle{ - 1 }[/math].

StrongLucasTest(m) =
{
local(a, b, c, k, P, Q, r, w, X);
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 L41
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]
Pokaż kod
forstep(k=1, 10^5, 2, if( StrongLucasTest(k) && !isprime(k), print(k)) )



Tabela przedstawia ilość takich liczb nie większych od [math]\displaystyle{ 10^n }[/math]

Pokaż kod
for(n=3, 9, s=0; forstep(k = 1, 10^n, 2, if( StrongLucasTest(k) && !isprime(k), s++ ) ); print("n=", n, "   ", s) )




Test BPSW

Uwaga L42
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 K20). 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]

Pokaż kod
forstep(m=3, 10^8, 2, if( isPrimeOrSPSP(m, 2)  &&  isPrimeOrSPSP(m, 3)  &&  !isprime(m), print("m=", m) ) )


Widzimy, że prawdopodobieństwo błędnego rozpoznania pierwszości w przypadku liczb mniejszych od [math]\displaystyle{ 10^8 }[/math] dla podstaw [math]\displaystyle{ 2 }[/math] i [math]\displaystyle{ 3 }[/math] jest rzędu kilku milionowych. Gdyby prawdopodobieństwa błędnego rozpoznania pierwszości w przypadku podstaw [math]\displaystyle{ 2 }[/math] i [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 K21).



Uzupełnienia

 

Pewne własności współczynników dwumianowych

 

Twierdzenie L43
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].

Dowód

Łatwo zauważamy, że dla [math]\displaystyle{ k \in [1, p - 1] }[/math] liczba pierwsza [math]\displaystyle{ p }[/math] dzieli licznik, ale nie dzieli mianownika współczynnika dwumianowego

[math]\displaystyle{ \binom{p}{k} = {\small\frac{p!}{k! \cdot (p - k)!}} }[/math]

zatem [math]\displaystyle{ p \biggr\rvert \binom{p}{k} }[/math]. Co należało pokazać.


Twierdzenie L44
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].

Dowód

Jeżeli [math]\displaystyle{ k \in [2, p - 1] }[/math], to modulo [math]\displaystyle{ p }[/math] dostajemy

[math]\displaystyle{ \binom{p + 1}{k} = \binom{p}{k} + \binom{p}{k - 1} \equiv 0 \pmod{p} }[/math]

Bo liczba pierwsza [math]\displaystyle{ p }[/math] dzieli licznik, ale nie dzieli mianownika współczynników dwumianowych po prawej stronie. Co należało pokazać.


Twierdzenie L45
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].

Dowód

Łatwo sprawdzamy, że twierdzenie jest prawdziwe dla liczby pierwszej parzystej [math]\displaystyle{ p = 2 }[/math]. Załóżmy, że [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą. Równie łatwo sprawdzamy, że twierdzenie jest prawdziwe dla [math]\displaystyle{ k = 0 }[/math] i [math]\displaystyle{ k = 1 }[/math]. Zauważmy, że dla [math]\displaystyle{ k \in [1, p - 1] }[/math] jest

[math]\displaystyle{ \binom{p - 1}{k} = {\small\frac{(p - 1) !}{k! (p - 1 - k) !}} = {\small\frac{p - k}{k}} \cdot {\small\frac{(p - 1) !}{(k - 1) ! (p - k) !}} = {\small\frac{p - k}{k}} \cdot \binom{p - 1}{k - 1} = {\small\frac{p}{k}} \cdot \binom{p - 1}{k - 1} - \binom{p - 1}{k - 1} }[/math]

Ponieważ współczynniki dwumianowe są liczbami całkowitymi, a liczba [math]\displaystyle{ k \in [2, p - 1] }[/math] nie dzieli liczby pierwszej nieparzystej [math]\displaystyle{ p }[/math], to [math]\displaystyle{ k }[/math] musi dzielić liczbę [math]\displaystyle{ \binom{p - 1}{k - 1} }[/math]. Zatem dla [math]\displaystyle{ k \in [2, p - 1] }[/math] modulo [math]\displaystyle{ p }[/math] mamy

[math]\displaystyle{ \binom{p - 1}{k} \equiv - \binom{p - 1}{k - 1}\pmod{p} }[/math]

Skąd otrzymujemy

[math]\displaystyle{ \binom{p - 1}{k} \equiv (- 1)^1 \binom{p - 1}{k - 1} \equiv (- 1)^2 \binom{p - 1}{k - 2} \equiv \ldots \equiv (- 1)^{k - 2} \binom{p - 1}{2} \equiv (- 1)^{k - 1} \binom{p - 1}{1} \equiv (- 1)^k \pmod{p} }[/math]

Co należało pokazać.


Twierdzenie L46
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]
Dowód

Ze wzoru dwumianowego

[math]\displaystyle{ (a + b)^n = \sum_{k = 0}^{n} \binom{n}{k} a^{n - k} b^k }[/math]

z łatwością otrzymujemy

[math]\displaystyle{ (1 + 1)^n = \sum_{k = 0}^{n} \binom{n}{k} = 2^n }[/math]
[math]\displaystyle{ (1 - 1)^n = \sum_{k = 0}^{n} (- 1)^k \binom{n}{k} = 0 }[/math]

Obliczając sumę i różnicę powyższych wzorów mamy

[math]\displaystyle{ \sum_{k = 0}^{n} \binom{n}{k} (1 + (- 1)^k) = 2 \underset{k \; \text{parzyste}}{\sum^n_{k = 0}} \binom{n}{k} = 2^n }[/math]
[math]\displaystyle{ \sum_{k = 0}^{n} \binom{n}{k} (1 - (- 1)^k) = 2 \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^n }[/math]

Skąd natychmiast wynika

[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]

Co należało pokazać.



Funkcje digits(m, b) oraz issquare(m)

 

Uwaga L47
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 L48
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

  1. 1,0 1,1 Robert Baillie and Samuel S. Wagstaff Jr., Lucas Pseudoprimes, Mathematics of Computation Vol. 35, No. 152 (1980), (LINK)
  2. François Arnault, The Rabin-Monier Theorem for Lucas Pseudoprimes, Mathematics of Computation Vol. 66, No. 218 (1997)
  3. Wikipedia, Baillie–PSW primality test, (Wiki-en)
  4. MathWorld, Baillie-PSW Primality Test, (LINK)
  5. Wikipedia, Pierwiastek kwadratowy, (Wiki-pl), (Wiki-en)
  6. Wikipedia, Integer square root, (Wiki-en)