Calculate-Legendre.tex 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage[utf8]{inputenc} % this is needed for umlauts
  5. \usepackage[ngerman]{babel} % this is needed for umlauts
  6. \usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
  7. \usepackage{amssymb,amsmath,amsfonts} % nice math rendering
  8. \usepackage{braket} % needed for \Set
  9. \usepackage{algorithm,algpseudocode}
  10. \usepackage{tikz}
  11. \usetikzlibrary{decorations.pathreplacing,calc}
  12. \newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
  13. \newcommand*{\AddNote}[4]{%
  14. \begin{tikzpicture}[overlay, remember picture]
  15. \draw [decoration={brace,amplitude=0.5em},decorate,very thick]
  16. ($(#3)!(#1.north)!($(#3)-(0,1)$)$) --
  17. ($(#3)!(#2.south)!($(#3)-(0,1)$)$)
  18. node [align=center, text width=2.5cm, pos=0.5, anchor=west] {#4};
  19. \end{tikzpicture}
  20. }%
  21. \begin{document}
  22. \begin{preview}
  23. \begin{algorithm}[H]
  24. \begin{algorithmic}
  25. \Require $p \in \mathbb{P}, a \in \mathbb{Z}, p \geq 3$
  26. \If{$a \geq p$ or $a < 0$}\Comment{Regel (III)}
  27. \State \Return $\Call{CalculateLegendre}{a \mod p, p}$ \Comment{nun: $a \in [0, \dots, p-1]$}
  28. \ElsIf{$a \equiv 0 \mod p$} \Comment{Null-Fall}
  29. \State \Return 0
  30. \ElsIf{$a \equiv 1 \mod p$} \Comment{Eins-Fall}
  31. \State \Return 1
  32. \ElsIf{$a \equiv -1 \mod p$} \Comment{Regel (VI)}
  33. \If{$p \equiv 1 \mod 4$}
  34. \State \Return 1
  35. \Else
  36. \State \Return -1
  37. \EndIf
  38. \ElsIf{!$\Call{isPrime}{|a|}$} \Comment{Regel (II)}
  39. \State $p_1, p_2, \dots, p_n \gets \Call{Faktorisiere}{a}$
  40. \State \Return $\prod_{i=1}^n \Call{CalculateLegendre}{p_i, a}$ \Comment{nun: $a \in \mathbb{P}$}
  41. \ElsIf{$a == 2$} \Comment{Regel (VII)}
  42. \If{$a \equiv \pm 1 \mod 8$}
  43. \State \Return 1
  44. \Else
  45. \State \Return -1
  46. \EndIf \Comment{nun: $a \in \mathbb{P}, a \geq 3$}
  47. \ElsIf{$p == 3$} \Comment{Regel (IV)}
  48. \State $t \gets p \mod 3$
  49. \If{$t == 2$}
  50. \State $t \gets -1$
  51. \EndIf
  52. \State \Return $t$
  53. \Else
  54. \State \Return $(-1) \cdot \Call{CalculateLegendre}{p, a}$
  55. \EndIf
  56. \end{algorithmic}
  57. \caption{Calculate Legendre-Symbol}
  58. %\AddNote{top}{bottom}{right}{calclulate $p$ such that: $b^p \leq Z < b^{p+1}$} %\tikzmark{top},\tikzmark{right},\tikzmark{bottom}
  59. \label{alg:euclidBaseTransformation}
  60. \end{algorithm}
  61. \end{preview}
  62. \end{document}