dixon.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. \chapter{Dixon's factorization method\label{chap:dixon}}
  2. ~\cite{dixon} describes a class of ``probabilistic algorithms'' for finding a
  3. factor of any composite number, at a sub-exponential cost. They basically
  4. consists into taking random integers $r$ in $\{1, \ldots, N\}$ and look for those
  5. where $r^2 \mod{N}$ is \emph{smooth}. If enough are found, then those integers
  6. can somehow be assembled, and so a fatorization of N attemped.
  7. %% that's not really academic to be stated officially, but I would have never
  8. %% understood this section without Firas (thanks).
  9. %% <http://blog.fkraiem.org/2013/12/08/factoring-integers-dixons-algorithm/>
  10. %% I kept the voila` phrase, that was so lovely.
  11. \section{Interlude \label{sec:dixon:history}}
  12. During the latest century there has been a huge effort to approach the problem
  13. formulated by Fermat ~\ref{eq:fermat_problem} from different perspecives. This
  14. led to an entire family of algorithms, like \emph{Quadratic Sieve},
  15. \emph{Dixon}, \ldots.
  16. The core idea is still to find a pair of perfect squares whose difference can
  17. factorize $N$, but maybe Fermat's hypotesis can be made weaker.
  18. \paragraph{Kraitchick} was the first one popularizing the idea that instead of
  19. looking for integers $\angular{x, y}$ such that $x^2 -y^2 = N$ it is sufficient
  20. to look for \emph{multiples} of $N$:
  21. \begin{align}
  22. x^2 - y^2 \equiv 0 \pmod{N}
  23. \end{align}
  24. and, once found, claim that $\gcd(N, x \pm y)$ are non-trial divisors of $N$
  25. just as we did in \ref{sec:fermat:implementation}.
  26. Kraitchick did not stop here: instead of trying $x^2 \equiv y^2 \pmod{N}$ he
  27. kept the value of previous attempt, and tries to find \emph{a product} of such
  28. values which is also a square. So we have a sequence
  29. \begin{align}
  30. \label{eq:dixon:x_sequence}
  31. \angular{x_0, \ldots, x_k} \mid \forall i \leq k \quad x_i^2 - N
  32. \; \text{ is a perfect square}
  33. \end{align}
  34. and hence
  35. \begin{align*}
  36. \prod_i (x_i^2 - N) = y^2
  37. \end{align*}
  38. that $\mod{N}$ is equivalent to:
  39. \begin{align}
  40. \label{eq:dixon:fermat_revisited}
  41. y^2 \equiv \prod_i (x_i^2 - N) \equiv \big( \prod_i x_i \big) ^2 \pmod{N}
  42. \end{align}
  43. and voil\`a our congruence of squares (\cite{discretelogs} \S 4). For what
  44. concerns the generation of $x_i$ with the property \ref{eq:dixon:x_sequence},
  45. they can simply be taken at random and tested using trial division.
  46. \paragraph{Brillhart and Morrison} later proposed (\cite{morrison-brillhart}
  47. p.187) a better approach than trial division to find such $x$. Their idea aims
  48. to ease the enormous effort required by the trial division. In order to achieve
  49. this. they introduce a \emph{factor base} $\factorBase$ and generate random $x$
  50. such that $x^2 - N$ is $\factorBase$-smooth. Recalling what we anticipated in
  51. ~\ref{chap:preq}, $\factorBase$ is a precomputed set of primes
  52. $p_i \in \naturalPrime$.
  53. This way the complexity of generating a new $x$ is dominated by
  54. \bigO{|\factorBase|}. Now that the right side of \ref{eq:dixon:fermat_revisited}
  55. has been satisfied, we have to select a subset of those $x$ so that their
  56. product can be seen as a square. Consider an \emph{exponent vector}
  57. $v_i = (\alpha_0, \alpha_1, \ldots, \alpha_{r-1})$ with $r = |\factorBase| + 1$
  58. associated with each $x_i$, where
  59. \begin{align}
  60. \label{eq:dixon:alphas}
  61. \alpha_j = \begin{cases}
  62. 1 \quad \text{if $p_j$ divides $x_i$ to an odd power} \\
  63. 0 \quad \text{otherwise}
  64. \end{cases}
  65. \end{align}
  66. for each $1 \leq j < r $. There is no need to restrict ourselves for positive
  67. values of $x^2 -N$, so we are going to use $\alpha_0$ to indicate the sign -$1$
  68. if negative, $0$ otherwise.
  69. This benefit has a neglegible cost: we have to add the non-prime $-1$ to our
  70. factor base $\factorBase$.
  71. Let now $M \in \mathbb{F}_2^{(f \times r)}$,
  72. for some $f > r$,
  73. be the rectangular matrix having per each $i$-th row the
  74. $v_i$ associated to $x_i$: this way each matrix element $m_{ij}$ will be the
  75. $j$-th component of $v_i$.
  76. We are interested in finding set(s) of the subsequences of $x_i$
  77. whose product always have even powers (\ref{eq:dixon:fermat_revisited}).
  78. Turns out that this is equivalent to look for the set of vectors
  79. $\{ w \mid wM = 0 \} = \ker(M)$ by definition of matrix multiplication
  80. in $\mathbb{F}_2$.
  81. \paragraph{Dixon} Morrison and Brillhart's ideas of \cite{morrison-brillhart}
  82. were actually used for a slightly different factorization method, employing
  83. continued fractions instead of the square difference polynomial. Dixon simply
  84. ported these to the square problem, achieving a probabilistic factorization
  85. method working at a computational cost asymptotically better than all other ones
  86. previously described: \bigO{\exp \{\beta(\log N \log \log N )^{\rfrac{1}{2}}\}}
  87. for some constant $\beta > 0$ \cite{dixon}.
  88. \section{Breaching the kernel}
  89. The following reduction procedure, extracted from ~\cite{morrison-brillhart}, is
  90. a forward part of the Gauss-Jordan elimination algorithm (carried out from right
  91. to left), and can be used to determine whether the set of exponent vectors is
  92. linearly dependent.
  93. For each $v_i$ described as above, associate a \emph{companion history vector} \\
  94. $h_i = (\beta_0, \beta_1, \ldots, \beta_{f-1})$, where for $0 \leq m < f$:
  95. \begin{align*}
  96. \beta_m = \begin{cases}
  97. 1 \quad \text{ if $m = i$} \\
  98. 0 \quad \text{ otherwise}
  99. \end{cases}
  100. \end{align*}
  101. At this point, we have all data structures needed:
  102. \\
  103. \\
  104. \\
  105. \begin{center}
  106. \emph{Reduction Procedure}
  107. \end{center}
  108. \begin{enumerate}[(i)]
  109. \item Set $j=r-1$;
  110. \item find the ``pivot vector'', i.e. the first vector
  111. $v_i, \quad 0 \leq i < f$ such that $\alpha_j = 1$. If none is found, go
  112. to (iv);
  113. \item
  114. \begin{enumerate}[(a)]
  115. \item replace every following vector $v_m, \quad i < m < f$
  116. whose rightmost $1$ is the $j$-th component, by the sum $v_i \xor v_m$;
  117. \item whenever $v_m$ is replaced by $v_i \xor v_m$, replace also the
  118. associated history vector $h_m$ with $h_i \xor h_m$;
  119. \end{enumerate}
  120. \item Reduce $j$ by $1$. If $j \geq 0$, return to (ii); otherwise stop.
  121. \end{enumerate}
  122. Algorithm \ref{alg:dixon:kernel} formalizes concepts so far discussed, by
  123. presenting a function \texttt{ker}, discovering linear dependencies in any
  124. rectangular matrix $M \in \mathbb{F}_2^{(f \times r)}$
  125. and storing dependencies into a \emph{history matrix} $H$.
  126. \begin{remark}
  127. We are proceeding from right to left in order to conform with
  128. \cite{morrison-brillhart}.
  129. Instead, their choice lays on optimization reasons, which does
  130. not apply any more to a modern calculator.
  131. \end{remark}
  132. \begin{algorithm}
  133. \caption{Reduction Procedure \label{alg:dixon:kernel}}
  134. \begin{algorithmic}[1]
  135. \Function{Ker}{$M$}
  136. \State $H \gets \texttt{Id}(f \times f)$
  137. \Comment the initial $H$ is the identity matrix
  138. \For{$j = r-1 \strong{ downto } 0$}
  139. \Comment reduce
  140. \For{$i=0 \strong{ to } f-1$}
  141. \If{$M_{i, j} = 1$}
  142. \For{$i' = i+1 \strong{ to } f-1$}
  143. \If{$M_{i', k} = 1$}
  144. \State $M_{i'} = M_i \xor M_{i'}$
  145. \State $H_{i'} = H_i \xor H_{i'}$
  146. \EndIf
  147. \EndFor
  148. \State \strong{break}
  149. \EndIf
  150. \EndFor
  151. \EndFor
  152. \For{$i = 0 \strong{ to } f-1$}
  153. \Comment yield linear dependencies
  154. \If{$M_i = (0, \ldots, 0)$}
  155. \strong{yield} $\{\mu \mid H_{i,\mu} = 1\}$
  156. \EndIf
  157. \EndFor
  158. \EndFunction
  159. \end{algorithmic}
  160. \end{algorithm}
  161. \begin{remark}
  162. The \texttt{yield} statement in line $12$ of algorithm \ref{alg:dixon:kernel}
  163. has the same semantics as in the python programming language.
  164. It is intended to underline the fact that each $\{\mu \mid H_{i,\mu} = 1\}$
  165. can lead to a solution for \ref{eq:dixon:x_sequence}, and therefore their
  166. generation can be performed asynchronously.
  167. \end{remark}
  168. \section{An Implementation Perspective}
  169. Before gluing all toghether, we need one last building brick necessary for
  170. Dixon's factorization algorithm: a \texttt{smooth}($x$) function. In our
  171. specific case, we need a function that, given as input a number $x$, returns
  172. \strong{nil} if $x^2 -N$ is not $\factorBase$-smooth. Otherwise,
  173. returns a vector $v = (\alpha_0, \ldots, \alpha_r)$ such that each $\alpha_j$ is
  174. defined just as in \ref{eq:dixon:alphas}. Once we have established $\factorBase$, its
  175. implementation comes straightfoward.
  176. \paragraph{How do we choose $\factorBase$?}
  177. It's not easy to answer: if we choose $\factorBase$ small, we will rarely find
  178. $x^2 -N$ \emph{smooth}. If we chose it large, attempting to factorize $x^2 -N$
  179. with $\factorBase$ will pay the price of iterating through a large set.
  180. \cite{Crandall} \S 6.1 finds a solution for this problem by employing complex
  181. analytic number theory.
  182. As a result, the ideal value for $|\factorBase|$ is
  183. $e^{\sqrt{\ln N \ln \ln N}}$.
  184. \begin{algorithm}
  185. \caption{Discovering Smoothness}
  186. \begin{algorithmic}[1]
  187. \Require $\factorBase$, the factor base
  188. \Function{smooth}{$x$}
  189. \State $v \gets (\alpha_0 = 0, \ldots, \alpha_{|\factorBase|} = 0)$
  190. \If{$x < 0$} $\alpha_0 \gets 1$ \EndIf
  191. \For{$i = 1 \strong{ to } |\factorBase|$}
  192. \While{$\factorBase_i \mid x$}
  193. \State $x \gets x// \factorBase_i$
  194. \State $\alpha_i \gets \alpha_i \xor 1$
  195. \EndWhile
  196. \EndFor
  197. \If{$x = 1$}
  198. \State \Return $v$
  199. \Else
  200. \State \Return \strong{nil}
  201. \EndIf
  202. \EndFunction
  203. \end{algorithmic}
  204. \end{algorithm}
  205. \begin{algorithm}
  206. \caption{Dixon}
  207. \begin{algorithmic}[1]
  208. \Require $\factorBase$, the factor base
  209. \Function{dixon}{\PKArg}
  210. \State $i \gets 0$
  211. \State $f \getsRandom \naturalN_{ > |\factorBase|}$
  212. \Comment finding linearity requires redundance
  213. \While{$i < f$}
  214. \Comment search for suitable pairs
  215. \State $x_i \getsRandom \naturalN_{< N}$
  216. \State $y_i \gets x_i^2 - N$
  217. \State $v_i \gets \textsc{smooth}(y_i)$
  218. \If{$v_i \neq \strong{nil} $} $i \gets i+1$ \EndIf
  219. \EndWhile
  220. \State $M \gets \texttt{matrix}(v_0, \ldots, v_{f-1})$
  221. \For{$\lambda = \{\mu_0, \ldots, \mu_k\}
  222. \strong{ in } \textsc{ker}(M)$}
  223. \Comment get relations
  224. \State $x \gets \prod_{\mu \in \lambda} x_\mu \pmod{N}$
  225. \State $y, r \gets \dsqrt{\prod_{\mu \in \lambda} y_\mu \pmod{N}}$
  226. \State $g \gets \gcd(x+y, N)$
  227. \If{$1 < g < N$}
  228. \State $p \gets g $
  229. \State $q \gets N//p$
  230. \State \Return $p, q$
  231. \EndIf
  232. \EndFor
  233. \EndFunction
  234. \end{algorithmic}
  235. \end{algorithm}
  236. \paragraph{Parallelism}
  237. Dixon's factorization is ideally suited to parallel implementation. Similarly to
  238. other methods like ECM and MPQS, treated in \cite{brent:parallel} \S 6.1,
  239. we can \emph{linearly} improve the running time by distributing across many
  240. nodes the discovery of $\factorBase$-smooth numbers.
  241. Depending on the granularity we desire - and the number of nodes available, we
  242. can even act on the \texttt{ker} function - but less easily.
  243. This idea would boil down to the same structure we discussed with Wiener's attack:
  244. one node - the \emph{producer} - discovers linear dependencies, while the others
  245. - the \emph{consumers} - attempt to factorize $N$.
  246. Certainly, due to the probabilistic nature of this algorithm, we can even think
  247. about running multiple instances of the same program. This solution is fairly
  248. effective in proportion to the development cost.
  249. %%% Local Variables:
  250. %%% mode: latex
  251. %%% TeX-master: "question_authority"
  252. %%% End: