Page
Library
Module
Module type
Parameter
Class
Class type
Source
Euler is a library for doing arithmetic with OCaml’s native integers (31 or 63 bits).
Documentation. Algorithmic complexities are documented. Besides, implementation code has a lot of comments.
Euler provides:
Euler.Arith
can be used to shadow the standard library’s arithmetic functions (beware that Euler.Arith.min_int
differs from Stdlib.min_int
, the latter being a forbidden value). There are also additional elementary functions on integers, such as logarithms and square roots.Advanced arithmetic: for the weird folks (like myself) who are interested in advanced arithmetic but do not care about integers larger than 262, and thus do not want the burden of using an arbitrary-precision library (like zarith or GMP), there you are. The library provides many classic functions such as
Solvers for some forms of integer equations (so-called “Diophantine equations”):
Modular arithmetic: including finding modular inverses, pseudo-inverses and multiplicative orders. A nice functorial interface provides convenient notations and uses a private type to enforce that values are always normalized in the range 0…m−1 where m is the modulus. Example use:
module M = Euler.Modular.Make (struct let modulo = 42 end)
let () = assert (M.( !:1 /: (!:33 +: !:4) = !:5 **:(-4) ))
(* modulo 42, the inverse of (33 + 4) is equal to 5^(−4) *)
Euler may prove actually useful outside of the playground.
(a * b) mod m
because this computation might overflow).However the functions related to prime numbers, for instance, are more of an educational or recreational interest, because of their limitation to native integers. Actual applications, such as cryptography, need arbitrary-precision integers.
Writing this library was fun and educative for me, and allowed me to solidify my math training in code. In fact, as the name suggests, the initial incentive was to play with Project Euler (hence the focus on integers that fit in a machine word) while sparing me the boredom of re-implementing a prime sieve for the hundredth time.