(** (Order b q p) means the order of b is q in multgroup(Z_p). *)

Definition Order (b : Z) (q p : nat) :=
  0 < q /\
  Mod (Exp b q) 1 p /\ (forall d : nat, 0 < d -> Mod (Exp b d) 1 p -> q <= d).

(* Specifications: *)
Lemma orderdec : forall (b : Z) (q p : nat), Order b q p \/ ~ Order b q p.
Lemma order_ex1 : forall (b : Z) (p : nat), Prime p -> (exists d : nat, 0 < d /\ Mod (Exp b d) 1 p) -> exists x : nat, Order b x p.
Lemma order_ex : forall (b : Z) (p : nat), Prime p -> ~ Mod b 0 p -> exists x : nat, x < p /\ Order b x p.
Lemma order_div : forall (b : Z) (x p : nat), Order b x p -> forall y : nat, 0 < y -> Mod (Exp b y) 1 p -> Divides x y.
Lemma order_le_predp : forall (b : Z) (q p : nat), Prime p -> Order b q p -> q <= pred p.