2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00

fixed another bug

This commit is contained in:
Martin Thoma 2013-09-01 12:57:42 +02:00
parent b9095ef768
commit 496a8b0adf
3 changed files with 16 additions and 4 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Before After
Before After

View file

@ -20,7 +20,7 @@
\ElsIf{$a == 0$ or $a == 1$}
\State \Return $a$ \Comment{now: $a \in [2, \dots, p-1]$}
\ElsIf{$a == 2$} \Comment{rule (VII)}
\If{$a \equiv \pm 1 \mod 8$}
\If{$p \equiv \pm 1 \mod 8$}
\State \Return 1
\Else
\State \Return -1
@ -35,7 +35,7 @@
\State $p_1, p_2, \dots, p_n \gets \Call{Factorize}{a}$
\State \Return $\prod_{i=1}^n \Call{CalculateLegendre}{p_i, p}$
\Else \Comment{now: $a \in \mathbb{P}, \sqrt{p-2} \geq a \geq 3$}
\If{$\frac{p-1}{2} \equiv 0 \mod 2$}
\If{$\frac{p-1}{2} \equiv 0 \mod 2$ or $\frac{a-1}{2} \equiv 0 \mod 2$}
\State \Return $\Call{CalculateLegendre}{p, a}$
\Else
\State \Return $(-1) \cdot \Call{CalculateLegendre}{p, a}$

View file

@ -31,13 +31,25 @@ def calculateLegendre(a, p):
-1
>>> calculateLegendre(113, 41) # Beispiel aus dem Skript, S. 114
1
>>> calculateLegendre(2, 31)
1
>>> calculateLegendre(5, 31)
1
>>> calculateLegendre(150, 1009) # http://math.stackexchange.com/q/221223/6876
1
>>> calculateLegendre(25, 1009) # http://math.stackexchange.com/q/221223/6876
1
>>> calculateLegendre(2, 1009) # http://math.stackexchange.com/q/221223/6876
1
>>> calculateLegendre(3, 1009) # http://math.stackexchange.com/q/221223/6876
1
"""
if a >= p or a < 0:
return calculateLegendre(a % p, p)
elif a == 0 or a == 1:
return a
elif a == 2:
if a%8 == 1 or a%8 == 7:
if p%8 == 1 or p%8 == 7:
return 1
else:
return -1
@ -53,7 +65,7 @@ def calculateLegendre(a, p):
product *= calculateLegendre(pi, p)
return product
else:
if ((p-1)/2)%2==0:
if ((p-1)/2)%2==0 or ((a-1)/2)%2==0:
return calculateLegendre(p, a)
else:
return (-1)*calculateLegendre(p, a)