|
@@ -14,6 +14,8 @@ The logarithmic $\log$ function is assumed to be in base two, i.e. $\log_2$.
|
|
|
\\
|
|
|
The $\idiv$ symbol is the integer division over $\naturalN$, i.e.
|
|
|
$a \idiv b = \floor{\frac{a}{b}}$.
|
|
|
+\\
|
|
|
+$\naturalPrime \subset \naturalN$ is the set containing all prime intgers.
|
|
|
|
|
|
\section{Algorithmic Complexity Notation}
|
|
|
The notation used to describe asymptotic complexity follows the $O$-notation,
|
|
@@ -72,8 +74,8 @@ Anyway, both show that algorithm ~\ref{alg:gcd} belongs to the class
|
|
|
|
|
|
\Else
|
|
|
\If{$b$ is odd}
|
|
|
- \State $a = a \gg 1$
|
|
|
- \If{$a < b$} $a, b = b, a$ \EndIf
|
|
|
+ \State $a \gets a \gg 1$
|
|
|
+ \If{$a < b$} $a, b \gets b, a$ \EndIf
|
|
|
\Else
|
|
|
\State $k \gets k+1$
|
|
|
\State $a, b \gets a \gg 1, b \gg 1$
|
|
@@ -157,7 +159,17 @@ for completeness' sake, we report in table
|
|
|
|
|
|
For each digit of the result, we perform a subtraction, and a limited number of
|
|
|
multiplications. This means that the complexity of this solutions belongs to
|
|
|
-\bigO{\log n \log n} = \bigO{\log^2 n}
|
|
|
+\bigO{\log n \log n} = \bigO{\log^2 n}.
|
|
|
+
|
|
|
+\begin{remark}
|
|
|
+ Note that Bombelli actually has found a solution in $x$ for a slightly
|
|
|
+ different equation than the one we initially formulated. Specifically, he
|
|
|
+ found the pair $\angular{x, r}$ such that $(x+r)^2=a$, where $x$ is the mantissa,
|
|
|
+ while $r$ is the decimal part. For our purpose this change is irrelevant: we
|
|
|
+ just need to be able to distinguish perfect squares, and thus assert that $r$
|
|
|
+ is nonzero.
|
|
|
+\end{remark}
|
|
|
+
|
|
|
\paragraph{Dijkstra's Algorithm \label{par:preq:sqrt:dijkstra}} can be found in
|
|
|
\cite{Dijkstra:adop}, \S 8, p.61. There, Dijkstra presents an elightning
|
|
|
process for the computation of the square root, making only use of binary shift
|
|
@@ -213,7 +225,7 @@ For any further details and explainations, the reference is still
|
|
|
\begin{algorithm}[H]
|
|
|
\caption{Square Root: final version}
|
|
|
\label{alg:sqrt:dijkstra}
|
|
|
- \begin{algorithmic}
|
|
|
+ \begin{algorithmic}[1]
|
|
|
\State $p, q, r \gets 0, 1, n$
|
|
|
\While{$q \leq n$} $q \gets q \gg 2$ \EndWhile
|
|
|
\While{$q \neq 1$}
|