Calculate-Legendre.tex 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 == 0$ or $a == 1$}
  29. \State \Return $a$ \Comment{nun: $a \in [2, \dots, p-1]$}
  30. \ElsIf{$a == 2$} \Comment{Regel (VII)}
  31. \If{$a \equiv \pm 1 \mod 8$}
  32. \State \Return 1
  33. \Else
  34. \State \Return -1
  35. \EndIf \Comment{nun: $a \in [3, \dots, p-1]$}
  36. \ElsIf{$a == p-1$} \Comment{Regel (VI)}
  37. \If{$p \equiv 1 \mod 4$}
  38. \State \Return 1
  39. \Else
  40. \State \Return -1
  41. \EndIf \Comment{nun: $a \in [3, \dots, p-2]$}
  42. \ElsIf{!$\Call{isPrime}{a}$} \Comment{Regel (II)}
  43. \State $p_1, p_2, \dots, p_n \gets \Call{Faktorisiere}{a}$
  44. \State \Return $\prod_{i=1}^n \Call{CalculateLegendre}{p_i, p}$ \Comment{nun: $a \in \mathbb{P}, \sqrt{p-2} \geq a \geq 3$}
  45. \Else
  46. \State \Return $(-1) \cdot \Call{CalculateLegendre}{p, a}$
  47. \EndIf
  48. \end{algorithmic}
  49. \caption{Calculate Legendre-Symbol}
  50. %\AddNote{top}{bottom}{right}{calclulate $p$ such that: $b^p \leq Z < b^{p+1}$} %\tikzmark{top},\tikzmark{right},\tikzmark{bottom}
  51. \label{alg:euclidBaseTransformation}
  52. \end{algorithm}
  53. \end{preview}
  54. \end{document}