1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2%% 3%% fact.tex LiDIA documentation 4%% 5%% This file contains the documentation of the class 6%% rational_factorization 7%% 8%% Copyright (c) 1997 by LiDIA-Group 9%% 10%% Authors: Andreas Mueller, Volker Mueller 11%% 12 13\newcommand{\base}{\mathit{base}} 14\newcommand{\expt}{\mathit{exp}} 15\newcommand{\sign}{\mathit{sign}} 16\newcommand{\step}{\mathit{step}} 17\newcommand{\upperbound}{\mathit{upper\uscore bound}} 18\newcommand{\lowerbound}{\mathit{lower\uscore bound}} 19 20 21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 23\NAME 24 25\CLASS{rational_factorization} \dotfill class for factoring rational 26numbers and representing factorizations 27 28 29%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30 31\ABSTRACT 32 33\code{rational_factorization} is a class for factoring non-zero rational numbers and holding 34factorizations. At the moment \emph{trial division (TD)}, the \emph{elliptic curve method 35 (ECM)} (see \cite{LenstraHW:1987}) and the \emph{quadratic sieve (QS)} (see 36\cite{Pomerance:1982}) are supported. Depending on the size of the number to be factored, 37different combinations of \emph{ TD}, \emph{ECM} and \emph{QS} are chosen. In addition it is 38possible to use own strategies by changing various parameters of \emph{TD} and \emph{ECM}. 39 40 41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 42 43\DESCRIPTION 44 45The factorization of a rational number is internally represented by an \code{int} variable 46$\sign$ and a vector of pairs $(\base, \expt)$, where $\base$ is of type \code{bigint} and 47$\expt$ of type \code{int}. Let in the following $(\base_i, \expt_i)$ denote the $i$-th vector 48component and $l$ the length of the vector. The length of a \code{rational_factorization} is 49defined as length of ``its vector''. Then this \code{rational_factorization} represents the 50rational number 51\begin{displaymath} 52 f = \sign \cdot \prod_{i = 0}^{l-1} \base_i^{\expt_i} \enspace. 53\end{displaymath} 54 55The value of $\sign$ is either $1$ or $-1$. The values of the bases $\base_i$ are always 56positive. The vector is sorted according to the size of the value of the $\base$ component. 57Note that the rational number 0 can not be represented by a \code{rational_factorization}. 58Different bases $\base_i$, $\base_j$ ($i \neq j$) of the vector are not equal, but not 59necessarily coprime. In particular, a \code{rational_factorization} does in general not 60represent the prime factorization of a rational number. 61 62\begin{techdoc} 63 The implementation of most of the operations and access functions of this class is self 64 explaining and can directly be understood by looking at the code. On the other hand, the 65 implementation of the factoring algorithms ECM and MPQS is tricky, we will describe several 66 design principles below. 67\end{techdoc} 68 69 70%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 71 72\CONS 73 74All constructors invoke the \LEH if the value of the input variable is 0. 75 76\begin{fcode}{ct}{rational_factorization}{} 77 initializes the variable with 1. 78\end{fcode} 79 80\begin{fcode}{ct}{rational_factorization}{int $x$, int $e$ = 1} 81 initializes the variable with $x^e$. 82\end{fcode} 83 84\begin{fcode}{ct}{rational_factorization}{unsigned int $x$, int $e$ = 1} 85 initializes the variable with $x^e$. 86\end{fcode} 87 88\begin{fcode}{ct}{rational_factorization}{long $x$, int $e$ = 1} 89 initializes the variable with $x^e$. 90\end{fcode} 91 92\begin{fcode}{ct}{rational_factorization}{unsigned long $x$, int $e$ = 1} 93 initializes the variable with $x^e$. 94\end{fcode} 95 96\begin{fcode}{ct}{rational_factorization}{const bigint & $x$, int $e$ = 1} 97 initializes the variable with $x^e$. 98\end{fcode} 99 100\begin{fcode}{ct}{rational_factorization}{const bigrational & $x$, int $e$ = 1} 101 initializes the variable with $x^e$. 102\end{fcode} 103 104\begin{fcode}{ct}{rational_factorization}{const rational_factorization & $x$, int $e$ = 1} 105 initializes the variable with $x^e$. 106\end{fcode}{} 107 108\begin{fcode}{dt}{~rational_factorization}{} 109\end{fcode} 110 111 112%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 113 114\ASGN 115 116Let $a$ be of type \code{rational_factorization}. The operator \code{=} is overloaded and the 117following assignment functions exist. If you try to assign $0$ to a variable of type 118\code{rational_factorization}, the \LEH will be invoked. 119 120\begin{fcode}{void}{a.assign}{long $i$, int $e$ = 1} 121 $a \assign i^e$. 122\end{fcode} 123 124\begin{fcode}{void}{a.assign}{const bigint & $I$, int $e$ = 1} 125 $a \assign I^e$. 126\end{fcode} 127 128\begin{fcode}{void}{a.assign}{const bigrational & $J$, int $e$ = 1} 129 $a \assign J^e$. 130\end{fcode} 131 132\begin{fcode}{void}{a.assign}{const rational_factorization & $F$, int $e$ = 1} 133 $a \assign F^e$. 134\end{fcode} 135 136 137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 138 139\ACCS 140 141\begin{cfcode}{lidia_size_t}{$a$.no_of_comp}{} 142 returns the number of components of the \code{rational_factorization} $a$, which is the number 143 of different $(\base, \expt)$-pairs. 144\end{cfcode} 145 146\begin{cfcode}{int}{$a$.sign}{} 147 returns the sign of the rational number represented by $a$. 148\end{cfcode} 149 150 151\begin{cfcode}{bigint}{$a$.base}{lidia_size_t $i$} 152 returns $\base_i$. If $i < 0$ or if $i$ is greater or equal than the number of components of 153 $a$, the \LEH will be invoked. 154\end{cfcode} 155 156 157\begin{cfcode}{int}{$a$.exponent}{lidia_size_t $i$} 158 returns $\expt_i$. If $i < 0$ or if $i$ is greater or equal than the number of components of 159 $a$, the \LEH will be invoked. 160\end{cfcode} 161 162\begin{fcode}{void}{$a$.set_exponent}{lidia_size_t $i$, int $e$} 163 set $\expt_i \assign e$. If $i < 0$ or if $i$ is greater or equal than the number of 164 components of $a$, the \LEH will be invoked. 165\end{fcode} 166 167 168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 169 170\ARTH 171 172The following operators are overloaded and can be used in exactly the same way as for machine 173types in C++ (e.g.~\code{int}) : 174 175\begin{center} 176 \code{(binary) *, /} 177\end{center} 178 179Let $a$ be of type \code{rational_factorization}. To avoid copying, these operations can also 180be performed by the following functions: 181 182\begin{fcode}{void}{multiply}{rational_factorization & $c$, const rational_factorization & $a$, 183 const rational_factorization & $b$}% 184 $c \assign a \cdot b$. 185\end{fcode} 186 187\begin{fcode}{void}{$a$.square}{} 188\end{fcode} 189 190\begin{fcode}{void}{square}{rational_factorization & $c$, const rational_factorization & $a$} 191 $c \assign a^2$. 192\end{fcode} 193 194\begin{fcode}{void}{divide}{rational_factorization & $c$, const rational_factorization & $a$, 195 const rational_factorization & $b$}% 196 $c \assign a / b$. 197\end{fcode} 198 199\begin{fcode}{void}{$a$.invert}{} 200\end{fcode} 201 202\begin{fcode}{void}{invert}{rational_factorization & $c$, const rational_factorization & $a$} 203 $c \assign a^{-1}$. 204\end{fcode} 205 206 207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 208 209\COMP 210 211The binary operators \code{==} and \code{!=} are overloaded and can be used in exactly the same 212way as for machine types in C++ (e.g.~\code{int}). 213 214 215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 216 217\HIGH 218 219\STITLE{General High-Level Functions} 220 221\begin{fcode}{void}{$a$.verbose}{int $\mathit{state}$} 222 sets the amount of information which is printed during computations. If $\mathit{state} = 1$ 223 then the factorization functions print information about the strategy, for $\mathit{state} = 224 0$ there is no such output. The predefined value is $\mathit{state} = 0$. The verbose mode 225 is stored in a static class variable such that the output behavior is the same for all 226 variables of type \code{rational_factorization}. 227\end{fcode} 228 229\begin{fcode}{bool}{$a$.is_prime_factor}{lidia_size_t $i$} 230 returns \TRUE if $\base_i$ is probably a prime number, otherwise \FALSE. For checking 231 primality the \code{bigint} function \code{is_prime()} is used, which uses a probabilistic 232 primality test. 233\end{fcode} 234 235\begin{fcode}{bool}{$a$.is_prime_factorization}{} 236 returns \TRUE if $a$ is probably a prime factorization of a rational number, \FALSE otherwise. 237 For checking primality the \code{bigint} function \code{is_prime()}, which uses a 238 probabilistic primality test on each base element of $a$, is used. 239\end{fcode} 240 241\begin{fcode}{void}{$a$.refine}{} 242 refines the factorization $a$ such that the bases of $a$ are pairwise coprime. 243\end{fcode} 244 245\begin{fcode}{bool}{$a$.refine}{const bigint & $x$} 246 refines the factorization $a$ by computing greatest common divisors of $x$ with every base 247 occurring in $a$. If $x$ has a proper common divisor with at least one base, the return-value 248 of this function will be \TRUE; otherwise it will be \FALSE. 249\end{fcode} 250 251\begin{fcode}{bool}{$a$.refine_comp}{lidia_size_t $i$, const bigint & $x$} 252 refines the factorization $a$ by computing the greatest common divisor of $x$ with $\base_i$ 253 in $a$. If $x$ has a proper common divisor with $\base_i$, the return-value of this function 254 will be \TRUE; otherwise it will be \FALSE. 255\end{fcode} 256 257\begin{fcode}{void}{$a$.factor_comp}{lidia_size_t $i$, int $\upperbound$ = 34} 258 tries to find factors of $\base_i$. A combination of \emph{TD}, \emph{ECM} and \emph{QS} is 259 used. The $i$-th component of $a$ is erased, found factors (with appropriate exponents) are 260 added to the vector of $a$ and the vector is resorted. If the default parameter $\upperbound$ 261 is set, \emph{ECM} tries to find factors up to $\upperbound$ digits. 262\end{fcode} 263 264\begin{fcode}{void}{$a$.factor}{int $\upperbound$ = 34} 265 tries to factor all base elements of $a$ with a combination of \emph{TD}, \emph{ECM} and 266 \emph{QS} and changes $a$ appropriately. If you have more information about all bases (for 267 example no prime factors smaller than $10^6$ in any base of $a$) you may get the results more 268 efficiently by using the function \code{$a$.ecm()} or \code{$a$.mpqs_comp()}. (see below) 269\end{fcode} 270 271\begin{fcode}{rational_factorization}{factor}{const bigint & $N$} 272 tries to factor the number $N$ with a combination of \emph{TD}, \emph{ECM} and \emph{QS} and 273 returns the \code{rational_factorization} representing the number $N$. 274\end{fcode} 275 276\begin{fcode}{sort_vector < bigint >}{divisors}{rational_factorization & $f$} 277 return a sorted vector of all positive divisors of the number represented by $f$ (in ascending 278 order). If $f$ is no prime factorization, the function tries to refine $f$ to a prime 279 factorization. In this case, the computed prime factorization is assigned to $f$. 280\end{fcode} 281 282\begin{fcode}{sort_vector < bigint >}{divisors}{const bigint & $N$} 283 return a sorted vector of all positive divisors of $N$ (in ascending order). 284\end{fcode} 285 286\begin{fcode}{bigrational}{evaluate}{const rational_factorization & $f$} 287 return the rational number represented by $f$. 288\end{fcode} 289 290\begin{fcode}{bigint}{evaluate_to_bigint}{const rational_factorization & $f$} 291 return the integer represented by $f$. If $f$ represents no integer, the \LEH is invoked. 292\end{fcode} 293 294 295%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 296 297\STITLE{Special High-Level Functions} 298 299\begin{fcode}{void}{$a$.trialdiv_comp}{lidia_size_t $i$, unsigned int $\upperbound$ = 1000000, 300 unsigned int $\lowerbound$ = 1}% 301 tries to factor the element $\base_i$ of $a$ by using \emph{TD} with all primes $p$ with 302 $\lowerbound < p < \upperbound$. The $i$-th component of $a$ is erased, found factors (with 303 appropriate exponents) are added to the vector of $a$ and the vector is resorted. $\base_i$ 304 is not tested for primality. 305\end{fcode} 306 307\begin{fcode}{void}{$a$.trialdiv}{unsigned int $\upperbound$ = 1000000, unsigned int $\lowerbound$ = 1} 308 tries to factor all base elements of $a$ with \emph{TD} using all primes $p$ with $\lowerbound 309 < p < \upperbound$. The vector of $a$ is changed according to the rules used in 310 \code{$a$.trialdiv_comp($i$)}. The base elements are not tested for primality. 311\end{fcode} 312 313\begin{fcode}{rational_factorization}{trialdiv}{const bigint & $N$, 314 unsigned int $\upperbound$ = 1000000, unsigned int $\lowerbound$ = 1}% 315 tries to factor the number $N$ with \emph{TD} using all primes $p$ with $\lowerbound < p < 316 \upperbound$ and returns the \code{rational_factorization} representing the number $N$. $N$ 317 is not tested for primality. 318\end{fcode} 319 320The following functions require some understanding of the underlying strategy of ECM. A 321detailed description of the implementation of \emph{TD} and \emph{ECM} can be found in 322\cite{Berger_Thesis:1993} and \cite{Mueller_Thesis:1995}. \emph{ECM} uses the following 323strategy, which is parameterized by the \code{int} variables $\lowerbound$, $\upperbound$ and 324$\step$. These variables can be chosen by the user. It starts to look for factors with 325$\lowerbound$ decimal digits. After having tried a ``few'' curves and not having found a factor 326the parameters of \emph{ECM} are changed and we try to find $(\lowerbound + \step)$-digit 327factors, $(\lowerbound + 2\,\step)$-digit factors and so on, until the decimal size of the 328factors we are looking for exceeds $\upperbound$. The number of curves which is used for 329finding a $d$-digit factor is chosen such that we find a $d$-digit factor with probability of at 330least $50 \%$ if it exists. Note that found factors can be composite. The built-in default 331values are $\lowerbound = 6, \step = 3$ and $\upperbound$ is set to half the decimal length of 332the number to be factored. The bounds $\lowerbound \geq 6$ and $\upperbound \leq 34$ are 333limited because we have only precomputed parameters for \emph{ECM} for factors of that size. 334 335\begin{fcode}{void}{$a$.ecm_comp}{lidia_size_t $i$, int $\upperbound$ = 34, int $\lowerbound$ = 6, 336 int $\step$ = 3}% 337 tries to find factors of $\base_i$ with decimal length $k$, $\lowerbound \leq k$ and $k \leq 338 \upperbound$, by means of \emph{ECM} according to the strategy explained above. Note that 339 found factors of $\base_i$ can be composite. If the value of $\upperbound$ is $34$, then 340 $\upperbound$ is set to $\min(34, \frac{1}{2} \lfloor \log_10 (\base_i)\rfloor + 1)$. The 341 vector of $a$ is changed appropriately. Unreasonable input ($\step \leq 0$, $\lowerbound$ or 342 $\upperbound$ out of range etc.) leads to a call of the \code{lidia_warning_handler}, the 343 parameter is set to a predefined value. 344\end{fcode} 345 346\begin{fcode}{void}{$a$.ecm}{int $\upperbound$ = 34, int $\lowerbound$ = 6, int $\step$ = 3} 347 tries to factor all base elements of $a$ with \emph{ECM} using the strategy described in 348 \code{$a$.ecm_comp($i$)} and changes $a$ appropriately. Note that the result is not 349 necessarily a prime factorization. 350\end{fcode} 351 352\begin{fcode}{rational_factorization}{ecm}{const bigint & $N$, int $\upperbound$ = 34, 353 int $\lowerbound$ = 6, int $\step$ = 3}% 354 tries to factor the number $N$ with \emph{ECM} using the strategy described in 355 \code{$a$.ecm_comp($i$)} and returns the \code{rational_factorization} representing the number 356 $N$. Note that the result is not necessarily a prime factorization. 357\end{fcode} 358 359\begin{techdoc} 360 A description of the ECM implementation can be found in the diploma thesis of Andreas 361 M{\"u}ller. Note however that here we use the improved standard continuation. Once you are 362 familiar with the theory and idea of ECM the \LiDIA implementation of ECM is pretty self 363 explaining. One important feature of this implementation is the decision when to switch to 364 the MPQS: this is done by calling the function \code{zeitqs} which returns an expected time of 365 MPQS for factoring a number of given size. If this expected time is lower than the already 366 used time of ECM on this number, then ECM is stopped and the unfactored number is returned. 367\end{techdoc} 368 369The version of \emph{QS} used in \LiDIA is called self initializing multiple polynomial large 370prime quadratic sieve. A description of the algorithm can be found in 371\cite{Alford/Pomerance:1993}, \cite{Denny_Thesis:1993} or \cite{Sosnowski_Thesis:1994}. The 372linear equation step uses an implementation of the Block Lanczos algorithm for $\bbfZ/2\bbfZ$. 373 374Note that the running time of \emph{QS} depends on the size of the number to be factored, not on 375the size of the factors. 376 377\begin{fcode}{void}{$a$.mpqs_comp}{lidia_size_t $i$} 378 tries to factor $\base_i$ using the large prime variation of the quadratic sieve. For bases 379 with more than 75 digits the \code{lidia_warning_handler} will be invoked, the 380 \code{rational_factorization} $a$ is not changed. Notice that as \emph{QS} creates temporary 381 files, you need write permission either in the \code{/tmp}-directory or in the directory from 382 which \emph{QS} is called. 383\end{fcode} 384 385\begin{fcode}{void}{$a$.mpqs}{const bigint & $N$} 386 tries to factor $N$ using \code{$a$.mpqs_comp} (see above). 387\end{fcode} 388 389 390\begin{techdoc} 391 The MPQS implementation of \LiDIA is described in detail in the diploma thesis of Thomas 392 Sosnowski. 393 394 Several temporary files are used during the computation. We describe the format of these 395 temporary files below. Note that the brackets [ ] are only used for clarification in these 396 descriptions. 397 398 \code{NEWR}: relations in a format such that the Lanczos implementation can read it. Since the 399 Lanczos interface should be the same for $\GF(2)$ and odd characteristic prime fields, we 400 decided to store the indices of non zero coefficients together with the value of the 401 coefficient (which is in our case always one). Therefore the Lanczos format of a non zero 402 coefficient is given as [1 [index of coefficient]]. A row of NEWR looks then like 403 404 [index of line] [number of entries per line] 0 [list of entries in Lanczos format, in 405 ascending order, divided by blanks] 0 406 407 Note that the end of a row is marked with a zero. 408 409 \code{FAKM, ZUSA}: files which store relations. The format is as follows: If the factor basis 410 element with index i has non zero exponent, then we store [exp\_i i]. In general the storing 411 format of relations is then 412 413 [H\_1] [H\_2] : [list of pairs [exp\_i i], in ascending order, divided by blanks] 0 414 415 where $H_1^2 \equiv H_2^2 \cdot \prod_{i} p_i^{\expt_i}$. For full relations $H_2$ is set to 416 one. The combination of partial relations (done in function zusam) does not use inversions 417 such that both $H_1$ and $H_2$ are non trivial in this case. ZUSA is used for full relations 418 found by the sieving procedure, FAKM stores full relations and combined relations. 419 420 \code{PART}: file for storing partial relations. Format is (notation as above) 421 422 [large prime] @ [H\_1] : [list of pairs [exp\_i i], in ascending order, divided by blanks] 0 423 424 Several other files are used for sorting and merging files. The format of these files is one 425 of the formats described above. 426 427 Now we describe the functionality of the most important functions. Several other functions 428 are small and can best be understood by looking into the code. 429 430 The function \code{rational_factorization::mpqs_comp} is the key function which does the 431 complete allocation/deallocation of memory and temporary files, computation of multiplier and 432 factor basis, choice of parameters. Then an endless loop is started where the different 433 polynomials are determined, sieving/testing is done. Full relations are written to the 434 temporary file ZUSA, partial relations to PART. The number of full relations is counted in 435 variable \code{counter_treff}. From time to time the number of combined relations is 436 determined with the function \code{count_partials}. If the number of relations is bigger than 437 the size of the factor basis, then the function \code{zusam} is called which combines partials 438 relations. Then \code{qs_build_factors} starts the Lanczos routine for solving the linear 439 system, uses the solutions for constructing ``pseudo solution'' and test for a factor. If no 440 factor has been found, then re-sieving is started again. 441 442 In a lot of functions parameters are given as call by reference objects. This is for 443 historical reasons and should be changed in a future release. Important variables are 444 \code{size_FB} (size of the factor basis), \code{M} (size of sieving interval), \code{P_ONCE} 445 (number of primes used in construction of highest polynomial coefficient --- see description 446 of self initializing variant), \code{P_TOTAL} (total number of primes the actually used 447 \code{P_ONCE} primes are chosen from), smallstart (index of factor basis element where sieving 448 starts --- smaller primes are not used in sieving procedure). 449\end{techdoc} 450 451\begin{Tfcode}{int}{transform_relations}{} 452 reads relations in internal format and transforms these relations into Lanczos format. These 453 relations are written to file \code{NEWR} without changing the order. 454\end{Tfcode} 455 456\begin{Tfcode}{void}{rational_factorization::qs_read_par}{...} 457 reads parameters from precomputed table and initializes global variables. Note that these 458 variables are given as call by reference objects to the function. 459\end{Tfcode} 460 461\begin{Tfcode}{long}{count_partials}{} 462 return number of combined partial relations which can be combined with actually known partial 463 relations. 464\end{Tfcode} 465 466\begin{Tfcode}{void}{zusam}{} 467 combine partial relations to full relations and write all found relations to file FAKM. 468 Multiple relations are removed. 469\end{Tfcode} 470 471\begin{Tfcode}{void}{compute_coeff}{...} 472 compute the next polynomial. This function is a direct translation of the formulas in the 473 self initialization variant. Additional information like sieving starting points are also 474 determined. 475\end{Tfcode} 476 477\begin{Tfcode}{int}{teste}{...} 478 Given a set of candidates, this functions tests with trial division whether a full/partial 479 relation has been found. Found relations are written to the corresponding temporary files, 480 the number of found full relations is returned. 481\end{Tfcode} 482 483\begin{Tfcode}{bool}{rational_factorization::qs_build_factors}{...} 484 functions calls the Lanczos routine, determines pseudo solutions and checks for a factor. If 485 a factor is found, then a variable of type \code{rational_factorization} is set to the found 486 factorization and \FALSE is returned; otherwise \TRUE is returned. 487\end{Tfcode} 488 489 490%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 491 492\IO 493 494The \code{istream} operator \code{>>} and the \code{ostream} operator \code{<<} are overloaded. 495The \code{istream} operator \code{>>} expects the input of a \code{rational_factori-zation} in 496the following format: 497\begin{displaymath} 498 [(\base_0,\expt_0)\,(\base_1,\expt_1)\,\dots \,(\base_{l-1},\expt_{l-1})] 499\end{displaymath} 500 501In the input $\base_i$ is allowed to be an arbitrary non-zero rational integer (i.e., of type 502\code{bigint}). The input function computes the internal format which was explained in the 503beginning. 504 505 506%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 507 508\SEEALSO 509 510\SEE{bigint}, \SEE{bigrational} 511 512 513%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 514 515\WARNINGS 516 517\emph{ECM} fails to factor rational numbers that only consist of prime factors smaller than 518$1000$. Therefore it is strongly recommended to use the function \code{factor()} or to ensure 519with the function \code{trialdiv()}, that there are no such small prime factors left before 520calling functions which use \emph{ECM}. 521 522 523%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 524 525\EXAMPLES 526 527\begin{quote} 528\begin{verbatim} 529#include <LiDIA/rational_factorization.h> 530 531int main() 532{ 533 rational_factorization f; 534 bigint n; 535 536 cout << "enter an integer n: "; 537 cin >> n; // input n 538 f.assign(n); // assign n as trivial factorization to f 539 f.verbose(1); // we want a lot of informations 540 f.factor(); // calculate prime factorization 541 // using the factor function 542 cout << f; // output f 543 544 cout << "enter an integer n: "; 545 cin >> n; // input n 546 f.assign(n); // assign n as trivial factorization to f 547 f.verbose(1); // we want a lot of informations 548 f.trialdiv(); // calculate prime factorization using trialdiv 549 cout << f; // output f 550 551 cout << "enter an integer n: "; 552 cin >> n; // input n 553 f.assign(n); // assign n as trivial factorization to f 554 f.verbose(1); // we want a lot of informations 555 f.ecm_comp(0); // calculate prime factorization using ecm 556 cout << f; // output f 557 558 cout << "enter an integer n: "; 559 cin >> n; // input n 560 f.assign(n); // assign n as trivial factorization to f 561 f.verbose(1); // we want a lot of informations 562 f.mpqs_comp(0); // calculate prime factorization using 563 // quadratic sieve 564 cout << f; // output f 565 566 return 0; 567} 568\end{verbatim} 569\end{quote} 570 571For further references please refer to 572\path{LiDIA/src/simple_classes/factorization/rational_factorization_appl.cc} 573 574 575%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 576 577\AUTHOR 578 579Franz-Dieter Berger, Thomas F.~Denny, Andreas M{\"u}ller, Volker M{\"u}ller, Thomas Sosnowski 580 581 582%%% Local Variables: 583%%% mode: latex 584%%% TeX-master: t 585%%% End: 586