aboutsummaryrefslogtreecommitdiff
path: root/lib/fp.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fp.ml')
-rw-r--r--lib/fp.ml25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/fp.ml b/lib/fp.ml
new file mode 100644
index 0000000..2489f11
--- /dev/null
+++ b/lib/fp.ml
@@ -0,0 +1,25 @@
+type t = Z.t
+
+let p =
+ Z.of_string
+ "21888242871839275222246405745257275088696311157297823662689037894645226208583"
+
+let p_minus_2 = Z.(p - ~$2)
+let mod_p x = Z.erem x p
+let zero = Z.zero
+let one = Z.one
+let of_string s = Z.of_string s |> mod_p
+let to_string = Z.to_string
+let equal = Z.equal
+let neg a = Z.neg a |> mod_p
+let inv a = Z.powm a p_minus_2 p
+let add a b = Z.add a b |> mod_p
+let sub a b = add a (neg b)
+let mul a b = Z.mul a b |> mod_p
+let div a b = mul a (inv b)
+let ( ~- ) = neg
+let ( ~/ ) = inv
+let ( + ) = add
+let ( - ) = sub
+let ( * ) = mul
+let ( / ) = div