(* As we know that log_n q < log_2 q we can define our function digit*)
 
Definition digit (q : Z) :=
  match q with
  | Z0 => 0
  | Zpos q' => digitAux (Zabs q) 1 (xO q')
  | Zneg q' => digitAux (Zabs q) 1 (xO q')
  end.

(* Specifications: *)
Theorem digitAux1 : forall p r, (Zpower_nat n (S p) * r)%Z = (Zpower_nat n p * (n * r))%Z.
Theorem digitAuxLess : forall (v r : Z) (q : positive), match digitAux v r q with | S r' => (Zpower_nat n r' * r <= v)%Z | O => True end.
Theorem digitLess : forall q : Z, q <> 0%Z -> (Zpower_nat n (pred (digit q)) <= Zabs q)%Z.