package euler

  1. Overview
  2. Docs

Module Modular.MakeSource

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

Sourceval modulo : int

The (positive) modulus m.

Sourcetype t = private int

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

Sourceval of_int : int -> t
Sourceval to_int : t -> int

Conversions to and from integers.

Sourceval (!:) : int -> t

A prefix alias for of_int.

Sourceval opp : t -> t

Modular opposite.

Sourceval (~-:) : t -> t

A prefix alias for opp.

Sourceval inv : t -> t

Modular inverse.

Sourceval (~/:) : t -> t

A prefix alias for inv.

Sourceval (+:) : t -> t -> t

Modular addition.

Sourceval (-:) : t -> t -> t

Modular subtraction.

Sourceval (*:) : t -> t -> t

Modular multiplication.

Sourceval (/:) : t -> t -> t

Modular division.

Sourceval (//:) : t -> t -> t

This is Modular.div_nonunique ~modulo.

Sourceval inv_factorize : t -> t

This is Modular.inv_factorize ~modulo.

Sourceval pow : t -> int -> t

Modular exponentiation.

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

An infix alias for pow.

Sourceval 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.

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