aboutsummaryrefslogtreecommitdiff
path: root/lib/field.ml
blob: 8f72c378a46340c96dc99bd68320d34c359b81c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(** Finite field. *)

(** Module signature for a finite field. *)
module type S = sig
  type t
  (** A type representing an element in the finite field. *)

  val zero : t
  (** The zero value, i.e. the additive identity. *)

  val one : t
  (** The one value, i.e. the multiplicative identity. *)

  val of_string : string -> t
  (** [of_string s] returns the field element represented by [s]. *)

  val to_string : t -> string
  (** [to_string a] returns the string representation of [a]. *)

  val equal : t -> t -> bool
  (** [equal a b] returns [true] if [a] is equal to [b]. *)

  val neg : t -> t
  (** [neg a] is the additive inverse of [a]. [add a (neg a) = zero] for all
      [a]. *)

  val inv : t -> t
  (** [inv a] is the multiplicative inverse of [a]. [mul a (inv a) = one] for
      all non-zero [a]. Furthermore, we define [inv zero = zero]. *)

  val add : t -> t -> t
  (** [add a b] is the sum of [a] plus [b] *)

  val sub : t -> t -> t
  (** [sub a b] is the difference of [a] minus [b]. It is equivalent to
      [add a (neg b)]. *)

  val mul : t -> t -> t
  (** [add a b] is the product of [a] times [b] *)

  val div : t -> t -> t
  (** [div a b] is the field division of [a] by [b]. It is equivalent to
      [mul a (inv b)]. Furthermore, we define [div a zero = zero]. *)

  val ( ~- ) : t -> t
  (** [neg]. *)

  val ( ~/ ) : t -> t
  (** [inv]. *)

  val ( + ) : t -> t -> t
  (** [add]. *)

  val ( - ) : t -> t -> t
  (** [sub]. *)

  val ( * ) : t -> t -> t
  (** [mul]. *)

  val ( / ) : t -> t -> t
  (** [div]. *)
end