Code Monkey home page Code Monkey logo

zarith's Introduction

OVERVIEW:

This library implements arithmetic and logical operations over
arbitrary-precision integers.  

The module is simply named "Z".  Its interface is similar to that of
the Int32, Int64 and Nativeint modules from the OCaml standard
library, with some additional functions.  See the file z.mlip for
documentation.

The implementation uses GMP (the GNU Multiple Precision arithmetic
library) to compute over big integers. 
However, small integers are represented as unboxed Caml integers, to save 
space and improve performance. Big integers are allocated in the Caml heap, 
bypassing GMP's memory management and achieving better GC behavior than e.g. 
the MLGMP library.
Computations on small integers use a special, faster path (coded in assembly
for some platforms and functions) eschewing calls to GMP, while computations
on large intergers use the low-level MPN functions from GMP.

Arbitrary-precision integers can be compared correctly using OCaml's 
polymorphic comparison operators (=, <, >, etc.). 
This requires OCaml version 3.12.1 or later, though.

Additional features include:
- a module Q for rationals, built on top of Z (see q.mli)
- a compatibility layer Big_int_Z that implements the same API as Big_int,
but uses Z internally



REQUIREMENTS:

- OCaml, preferably version 3.12.1 or later.  
(Earlier versions are usable but generic comparisons will misbehave.)
- Either the GMP library or the MPIR library, including development files.
- The GNU C compiler (gcc) and assembler.
- The Perl programming language.
- (optional) The Findlib package manager.


INSTALLATION:

1) First, run the "configure" script by typing:

   ./configure

2) It creates a Makefile, which can be invoked by:

   make

This builds native and bytecode versions of the library.

3) The libraries are installed by typing:

   make install

or, if you install to a system location but are not an administrator

   sudo make install

If Findlib is detected, it is used to install files. 
Otherwise, the files are copied to a zarith subdirectory of the directory 
given by `ocamlc -where`.
The libraries are named "zarith.cmxa" and "zarith.cma", and the Findlib module
is named "zarith". 
Compiling and linking with the library requires passing the "-I +zarith" 
option to ocamlc / ocamlopt.
The "configure" script has a few options. Use the "-help" option to get a
list and short description of each option.

4) (optional) 
HTML API documentation is built (using ocamldoc) by the additional command

  make doc

Test programs are built by the additional command

  make tests

(but these are  not installed).



LICENSE:

This Library is distributed under the terms of the GNU Library General
Public License version 2, with a special exception allowing unconstrained 
static linking. 
See LICENSE file for details.



AUTHORS:

Antoine Miné, ENS Paris.
Xavier Leroy, INRIA Paris-Rocquencourt.
Pascal Cuoq, CEA LIST.



COPYRIGHT:

Copyright (c) 2010-2011 Antoine Miné, Abstraction project.
Abstraction is part of the LIENS (Laboratoire d'Informatique de l'ENS),
a joint laboratory by:
CNRS (Centre national de la recherche scientifique, France),
ENS (École normale supérieure, Paris, France),
INRIA Rocquencourt (Institut national de recherche en informatique, France).



CONTENTS:

The source files are:
* configure         - configuration script
* caml_z.c          - C implementation of all functions
* caml_z_*.S        - asm implementation for a few functions
* z_pp.pl           - script to generate z.ml[i] from z.ml[i]p
* z.ml[i]p          - templates used to generate z.ml[i]p
* big_int_z.ml[i]   - wrapper to provide a Big_int compatible API to Z
* q.ml[i]           - rational library, pure OCaml on top of Z
* test.ml           - simple test
* bitest.ml         - consistency test between Z and Big_int
* projet.mak        - builds Z, Q and the tests

Note: z_pp.pl simply scans the asm file (if any) to see which functions have
an asm implementation. It then fixes the external statements in .mlp and 
.mlip accordingly.
The argument to z_pp.pl is the suffix * of the caml_z_*.S to use (guessed by
configure).

zarith's People

Contributors

talex5 avatar

Stargazers

abdul dakkak avatar Jeff Hammerbacher avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

aluuu

zarith's Issues

Problem with custom installation of GMP

Hi,
recently cryptokit introduced the dependency on zarith which depends on gmp. So now, my code needs gmp.
I am trying to compile it on a machine on which I am not root, so I downloaded and installed libgmp in a custom directory. I included the path to the include files of GMP in my C_INCLUDE_PATH and the path to the libraries both in LIBRARY_PATH and LD_LIBRARY_PATH.
I installed cryptokit and zarith using opam install zarith cryptokit and the install was successful.
Now, when I try to compile my code, I get a missing symbol __gmpn_sqr which comes from GMP. So it seems that libgmp is not linked with my program.

But on a machine where I am root, I can install libgmp3-dev with the package manager and everything works fine. What is going on here? I really don't understand why the opam install was successful and why libgmp is not linked.

Here is the output:

ocamlbuild -j 0 -syntax camlp4o -cflags "-g -warn-error A" -lflags "-g -warn-error A"  qptypes_generator.byte  -use-ocamlfind 
+ ocamlfind ocamlc -g -warn-error A -linkpkg -thread -package core,cryptokit,ZMQ,sexplib.syntax,str -syntax camlp4o qptypes_generator.cmo -o qptypes_generator.byte
File "_none_", line 1:
Error: Error on dynamically loaded library: /users/sysadmin/renon/.opam/4.02.1/lib/stublibs/dllzarith.so: /users/sysadmin/renon/.opam/4.02.1/lib/stublibs/dllzarith.so: undefined symbol: __gmpn_sqr
Command exited with code 2.
Compilation unsuccessful after building 3 targets (2 cached) in 00:00:00.
make: *** [qptypes_generator.byte] Error 10
make: Leaving directory `/eosscratch/sysadmin/renon/TEST_CAMPAGNE_2016_2017/TEST6/quantum_package/ocaml'
FAILED: ocaml_target 
make -C /eosscratch/sysadmin/renon/TEST_CAMPAGNE_2016_2017/TEST6/quantum_package/ocaml
ninja: build stopped: subcommand failed.
[renon@eoslogin2 quantum_package]$ strings lib/libgmp.so | grep sqr
__gmp_sqrt_of_negative
__gmpn_sqr
__gmpf_sqrt
__gmpn_sqrtrem
__gmpf_sqrt_ui
__gmpz_sqrt
__gmpz_sqrtrem
__gmpn_toom8_sqr
__gmpn_sqr_basecase
__gmpn_toom3_sqr
__gmpn_toom2_sqr
__gmpn_toom4_sqr
__gmpn_toom6_sqr
__gmpn_sqrmod_bnm1_next_size
__gmpn_sqrmod_bnm1
__gmpn_bsqrtinv
__gmpn_sqrlo
__gmpn_sqrlo_basecase
__gmpn_bsqrt
__gmpn_sec_sqr
__gmpn_sec_sqr_itch
__gmpn_sqr_diag_addlsh1

Thanks for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.