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

58 lines
2.3 KiB
TeX
Raw Normal View History

2013-09-01 11:01:24 +02:00
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}
\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
\usepackage{amssymb,amsmath,amsfonts} % nice math rendering
\usepackage{braket} % needed for \Set
\usepackage{algorithm,algpseudocode}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand*{\AddNote}[4]{%
\begin{tikzpicture}[overlay, remember picture]
\draw [decoration={brace,amplitude=0.5em},decorate,very thick]
($(#3)!(#1.north)!($(#3)-(0,1)$)$) --
($(#3)!(#2.south)!($(#3)-(0,1)$)$)
node [align=center, text width=2.5cm, pos=0.5, anchor=west] {#4};
\end{tikzpicture}
}%
\begin{document}
\begin{preview}
\begin{algorithm}[H]
\begin{algorithmic}
\Require $p \in \mathbb{P}, a \in \mathbb{Z}, p \geq 3$
2013-09-01 11:10:31 +02:00
\If{$a \geq p$ or $a < 0$}\Comment{Regel (III)}
2013-09-01 11:01:24 +02:00
\State \Return $\Call{CalculateLegendre}{a \mod p, p}$ \Comment{nun: $a \in [0, \dots, p-1]$}
2013-09-01 11:38:48 +02:00
\ElsIf{$a == 0$ or $a == 1$}
\State \Return $a$ \Comment{nun: $a \in [2, \dots, p-1]$}
2013-09-01 11:29:01 +02:00
\ElsIf{$a == 2$} \Comment{Regel (VII)}
\If{$a \equiv \pm 1 \mod 8$}
2013-09-01 11:01:24 +02:00
\State \Return 1
\Else
\State \Return -1
2013-09-01 11:29:01 +02:00
\EndIf \Comment{nun: $a \in [3, \dots, p-1]$}
\ElsIf{$a == p-1$} \Comment{Regel (VI)}
\If{$p \equiv 1 \mod 4$}
2013-09-01 11:18:19 +02:00
\State \Return 1
\Else
\State \Return -1
2013-09-01 11:29:01 +02:00
\EndIf \Comment{nun: $a \in [3, \dots, p-2]$}
\ElsIf{!$\Call{isPrime}{a}$} \Comment{Regel (II)}
\State $p_1, p_2, \dots, p_n \gets \Call{Faktorisiere}{a}$
2013-09-01 11:38:48 +02:00
\State \Return $\prod_{i=1}^n \Call{CalculateLegendre}{p_i, p}$ \Comment{nun: $a \in \mathbb{P}, \sqrt{p-2} \geq a \geq 3$}
2013-09-01 11:01:24 +02:00
\Else
2013-09-01 11:18:19 +02:00
\State \Return $(-1) \cdot \Call{CalculateLegendre}{p, a}$
2013-09-01 11:01:24 +02:00
\EndIf
\end{algorithmic}
\caption{Calculate Legendre-Symbol}
%\AddNote{top}{bottom}{right}{calclulate $p$ such that: $b^p \leq Z < b^{p+1}$} %\tikzmark{top},\tikzmark{right},\tikzmark{bottom}
\label{alg:euclidBaseTransformation}
\end{algorithm}
\end{preview}
\end{document}