Once LiDIA
is installed properly (see section ) its library is
used as any other C++
library. We illustrate the use of the LiDIA
library by an example. The following little C++
-program reads a number
from the standard input and prints its factorization on the
standard output.
# include <LiDIA/rational_factorization.h> main() { rational_factorization f; bigint n; cout << "\n Please enter a number: "; cin >> n; f.assign(n); f.factor(); if (f.is_prime_factorization()) cout<<"\n Prime Factorization: " << f << "\n"; else cout<<"\n Factorization: "<< f << "\n"; }
It uses the LiDIA factorization class (compare the description of rational_factorization ). This is done by including <LiDIA/rational_factorization.h>. In general, the LiDIA include file for the data type xxx is <LiDIA/xxx.h>. Since all data types and algorithms of LiDIA reside in libLiDIA.a this is the only library that has to be linked. The program fact.c can be compiled and linked using the following command (we assume that you have installed LiDIA in /usr/local and that you have compiled LiDIA on a sparc7 machine using g++):
g++ -O fact.c -I/usr/local/include -L/usr/local/lib/LiDIA/sparc7/g++
-o fact -lLiDIA -lm
On an OS/2 -- system the program can be compiled and linked using the
following command (we assume that you have installed LiDIA
in
d:LiDIA and that you have compiled LiDIA
using
EMX):
gcc -O2 fact.C -Id:/LiDIA/include -Ld:/LiDIA/lib/LiDIA/os2/g++
-lLiDIA -lbsd -liostream
(If you updated your environment variables as described in chapter
in the description of LIDIA_INSTALL_DIR you may
also use the following simpler command:
gcc -O2 fact.C -lLiDIA -lbsd -liostream
If you installed LiDIA to some default path you still have to specify the path to the library, i.e. you need the -L -- option, but you may leave out the -I -- option.)
Here is a sample running session:
host% fact <RET>
Please enter an integer 18446744073709551617 <RET>
Prime Factorization: [(274177,1)(67280421310721,1)]