End Of_Z.
End ZnZ.
(** A modular specification grouping the earlier records. *)
Module Type CyclicType.
Parameter t : Set.
#[global]
Declare Instance ops : ZnZ.Ops t.
#[global]
Declare Instance specs : ZnZ.Specs ops.
End CyclicType.
(** A Cyclic structure can be seen as a ring *)
Module CyclicRing (Import Cyclic : CyclicType).
Local Notation "[| x |]" := (ZnZ.to_Z x) (at level 0, x at level 99).
Definition eq (n m : t) := [| n |] = [| m |].
Local Infix "=="  := eq (at level 70).
Local Notation "0" := ZnZ.zero.
Local Notation "1" := ZnZ.one.
Local Infix "+" := ZnZ.add.
Local Infix "-" := ZnZ.sub.
Local Notation "- x" := (ZnZ.opp x).
Local Infix "*" := ZnZ.mul.
Local Notation wB := (base ZnZ.digits).
Global Hint Rewrite ZnZ.spec_0 ZnZ.spec_1 ZnZ.spec_add ZnZ.spec_mul
ZnZ.spec_opp ZnZ.spec_sub
: cyclic.
Ltac zify := unfold eq in *; autorewrite with cyclic.

(* Specifications: *)
Lemma add_0_l : forall x, 0 + x == x.
Lemma add_comm : forall x y, x + y == y + x.
Lemma add_assoc : forall x y z, x + (y + z) == x + y + z.
Lemma mul_1_l : forall x, 1 * x == x.
Lemma mul_comm : forall x y, x * y == y * x.
Lemma mul_assoc : forall x y z, x * (y * z) == x * y * z.
Lemma mul_add_distr_r : forall x y z, (x+y)*z == x*z + y*z.
Lemma add_opp_r : forall x y, x + - y == x-y.
Lemma add_opp_diag_r : forall x, x + - x == 0.
Lemma CyclicRing : ring_theory 0 1 ZnZ.add ZnZ.mul ZnZ.sub ZnZ.opp eq.
Definition eqb x y :=
match ZnZ.compare x y with Eq => true | _ => false end.
Lemma eqb_eq : forall x y, eqb x y = true <-> x == y.
Lemma eqb_correct : forall x y, eqb x y = true -> x==y.