package euler

  1. Overview
  2. Docs

The functor application Make (M) defines modular arithmetic operations with a fixed, non‐zero modulus M.modulo. Because the modulus needs not be repeated for each individual operation, meaningful unary and binary operators can be defined. Operations in the resulting module follow the same specifications as those in module Modular, with respect to return values, exceptions raised, and time costs.

Parameters

module _ : sig ... end

Signature

val modulo : int

The (positive) modulus m.

type t = private int

The type of an element of the ring ℤ∕mℤ.

val of_int : int -> t
val to_int : t -> int

Conversions to and from integers.

val (!:) : int -> t

A prefix alias for of_int.

val opp : t -> t

Modular opposite.

val (~-:) : t -> t

A prefix alias for opp.

val inv : t -> t

Modular inverse.

val (~/:) : t -> t

A prefix alias for inv.

val (+:) : t -> t -> t

Modular addition.

val (-:) : t -> t -> t

Modular subtraction.

val (*:) : t -> t -> t

Modular multiplication.

val (/:) : t -> t -> t

Modular division.

val (//:) : t -> t -> t

This is Modular.div_nonunique ~modulo.

val inv_factorize : t -> t

This is Modular.inv_factorize ~modulo.

val pow : t -> int -> t

Modular exponentiation.

val (**:) : t -> int -> t

An infix alias for pow.

val rand : unit -> t

Random generation with the uniform distribution.

The following operators are shortcuts that spare us the need to write of_int conversions on their operands. The most useful ones are ( *.:) and (/:.), for multiplicative literal constants.

val (~-:.) : int -> t
val (~/:.) : int -> t
val (+.:) : int -> t -> t
val (+:.) : t -> int -> t
val (+..) : int -> int -> t
val (-.:) : int -> t -> t
val (-:.) : t -> int -> t
val (-..) : int -> int -> t
val (*.:) : int -> t -> t
val (*:.) : t -> int -> t
val (*..) : int -> int -> t
val (/.:) : int -> t -> t
val (/:.) : t -> int -> t
val (/..) : int -> int -> t
val (//.:) : int -> t -> t
val (//:.) : t -> int -> t
val (//..) : int -> int -> t
val (**.:) : int -> int -> t
OCaml

Innovation. Community. Security.