FLINT = Fast Library for Number Theoryenglish wikipedia : Fast_Library_for_Number_Theory Instalacja zależności GNU Make LaTeX dla dokumentacji github flint2 issue : make doc error #302 texlive-full texlive-latex-extra pthreads GMP MPFR
git
Instalujemy wersję rozwojowąflintlib development
git clone git://github.com/wbhart/flint2.git flint2 cd flint2 make make check sudo make install
Sprawdzamy:
~/flint2$ git branch * trunk
uaktualniamy
git pull
doc
~/flint2$ cd doc/latex make
apt
sudo apt-get install libflint-dev # nie testowane
lokalizacja bibliotek
sudo updatedb locate libflint
przykładowy wynik:
/home/a/flint2/libflint.a /home/a/flint2/libflint.so /home/a/flint2/libflint.so.13 /home/a/flint2/libflint.so.13.5.2 /usr/local/lib/libflint.a /usr/local/lib/libflint.so /usr/local/lib/libflint.so.13 /usr/local/lib/libflint.so.13.5.2
biblioteka jest zainstalowana w:
/usr/local/lib/
lokalizacja plików nagłówkowych locate flint.h
Przykładowy wynik:
~/flint2/flint.h /usr/local/include/flint/flint.h Ścieżka wyszukiwania bibliotek
echo $LD_LIBRARY_PATH
ustawiamy (czasowo):
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
lub na stałe przez wpis (jako root) w plikuubuntu environment Variables
/etc/ld.so.conf.d/*.conf
Typy całkowite slong = (ang. signed long) zamiast long lub long long (w celu przenośności = niezależności od platformy sprzętowej) ulong = (ang. unsigned long) ulong lub ulong long (w celu przenośności = niezależności od platformy sprzętowej) fmpz_t = typ całkowity o dowolnej precyzji wektorowe fmpz vec = typ wektorowy całkowity. Dla wektora liczb całkowitych o dowolnej precyzji rzeczywiste fmpq_t = typ rzeczywisty (rational numbers) jako ułamki liczb całkowitych o dowolnej precyzji
flint_printf("%wu", d); /* print ulong */ flint_printf("%wd", d); /* print slong */
Przykłady
Pierwszy program
/* gcc f.c -lflint -lgmp -lmpfr -lpthread -Wall export LD_LIBRARY_PATH=/usr/local/lib/ */ #include #include #include int main ( void ) { flint_printf (" MPFR-%s \n GMP-%s \n Flint-%s\n", mpfr_version, gmp_version, FLINT_VERSION ); return 0; }
Przykładowy wynik:
MPFR-3.1.5 GMP-6.1.1 Flint-2.5.2
liczby całkowite
/* gcc c.c -lflint -lgmp -lmpfr -lpthread -Wall export LD_LIBRARY_PATH=/usr/local/lib/ */ #include #include #include #include
int main ( void )
fmpz_t x , y ; // init fmpz_init ( x ) ; fmpz_init ( y ) ; // set fmpz_set_ui (x , 7) ; fmpz_mul (y , x , x ) ;
// print fmpz_print ( x ) ; flint_printf ( " ^2 = " ) ; fmpz_print ( y ) ; flint_printf ( " \n" ) ; flint_printf (" MPFR-%s \n GMP-%s \n Flint-%s\n", mpfr_version, gmp_version, FLINT_VERSION ); // clear fmpz_clear ( x ) ; fmpz_clear ( y ) ;
return 0; }
Wynik :
gcc c.c -lflint -lgmp -lmpfr -lpthread -Wall ./a.out 7 ^2 = 49 MPFR-3.1.5 GMP-6.1.1 Flint-2.5.2
primegen
Program wyświetla lub liczy liczby pierwsze mniejsze niż podana liczba.
Jest to przykładowy program z biblioteki flint. Kod źródłowy znajduje się w pliku:
~/flint2/examples/primegen.c
skompilowana wersja :
~/flint2/build/examples/primegen
Możemy samodzielnie skompilować program po wprowadzeniu kilku zmian :
/* Copyright (C) 2012 Fredrik Johansson
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. See .
gcc primegen.c -lflint -lgmp -lmpfr -lpthread -Wall export LD_LIBRARY_PATH=/usr/local/lib/ */
#include #include #include #include // change #include // change
int main(int argc, char* argv[]) { n_primes_t iter; mp_limb_t p, N;
if (argc < 2)
flint_printf("primegen N - print all primes <= N\n"); flint_printf("primegen -c N - generate the primes but just count them\n"); return EXIT_FAILURE;
N = strtoul(argv[argc-1], NULL, 10); if (N == UWORD_MAX)
flint_printf("N must be smaller than %wu\n", UWORD_MAX); return EXIT_FAILURE;
if (argc == 3)
ulong count = 0; n_primes_init(iter); while ((p = n_primes_next(iter)) <= N) count++; n_primes_clear(iter); flint_printf("pi(%wu) = %wu\n", N, count);
else
n_primes_init(iter); while ((p = n_primes_next(iter)) <= N) flint_printf("%wu\n", p); n_primes_clear(iter);
return EXIT_SUCCESS; }
wynik: ./a.out primegen N - print all primes <= N primegen -c N - generate the primes but just count them
./a.out 100 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
./a.out -c 100 pi(100) = 25
Pomoc plik pdf http://flintlib.org/flint-dev.pdf http://www.flintlib.org/flint-2.5.pdf grupy dyskusyjne Google flint-devel flint
video Video of the talk Parallel Computation in Number Theory (January 30, 2007) by William Hart Video of the talk FLINT and Fast Polynomial Arithmetic (June 13, 2007) By David Harvey Video of the talk A short talk on short division (October 1, 2007) by William Hart Video of the talk Algebraic Number Theory with FLINT (November 11, 2007) by William Hart
Źródła