(* 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.

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.