aboutsummaryrefslogtreecommitdiff
path: root/lib/fields.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fields.ml')
-rw-r--r--lib/fields.ml36
1 files changed, 33 insertions, 3 deletions
diff --git a/lib/fields.ml b/lib/fields.ml
index e9a6514..1ab2712 100644
--- a/lib/fields.ml
+++ b/lib/fields.ml
@@ -1,3 +1,33 @@
+module Fimpl (F : sig
+ type t
+
+ val zero : t
+ val one : t
+ val equal : t -> t -> bool
+ val neg : t -> t
+ val inv : t -> t
+ val add : t -> t -> t
+ val mul : t -> t -> t
+end) : Field.S with type t = F.t = struct
+ type t = F.t
+
+ let zero = F.zero
+ let one = F.one
+ let equal = F.equal
+ let neg = F.neg
+ let inv = F.inv
+ let add = F.add
+ let sub a b = add a (neg b)
+ let mul = F.mul
+ let div a b = mul a (inv b)
+ let ( ~- ) = neg
+ let ( ~/ ) = inv
+ let ( + ) = add
+ let ( - ) = sub
+ let ( * ) = mul
+ let ( / ) = div
+end
+
module Fp = struct
let p =
Z.of_string
@@ -6,7 +36,7 @@ module Fp = struct
let p_minus_2 = Z.(p - ~$2)
let mod_p x = Z.erem x p
- include Field.Make (struct
+ include Fimpl (struct
type t = Z.t
let zero = Z.zero
@@ -28,7 +58,7 @@ end) =
struct
let degree = Array.length R.p
- include Field.Make (struct
+ include Fimpl (struct
type t = Fp.t array
let zero = Array.make degree Fp.zero
@@ -111,7 +141,7 @@ struct
Scanf.sscanf s "(%[^)])" (String.split_on_char ',')
|> List.map String.trim |> List.map Fp.of_string |> Array.of_list
in
- if Array.length a = Array.length R.p then a
+ if Array.length a = degree then a
else invalid_arg "wrong number of elements"
let to_string a =