Fixpoint pos_length (p : positive) : nat :=
  match p with
  | xH => 0
  | xO p' => S (pos_length p')
  | xI p' => S (pos_length p')
  end.

(* Specifications: *)
Theorem digitAuxMore : forall (v r : Z) (q : positive), (0 < r)%Z -> (v < Zpower_nat n (pos_length q) * r)%Z -> (v < Zpower_nat n (digitAux v r q) * r)%Z.
Theorem pos_length_pow : forall p : positive, (Zpos p < Zpower_nat n (S (pos_length p)))%Z.
Theorem digitMore : forall q : Z, (Zabs q < Zpower_nat n (digit q))%Z.
Theorem digitInv : forall (q : Z) (r : nat), (Zpower_nat n (pred r) <= Zabs q)%Z -> (Zabs q < Zpower_nat n r)%Z -> digit q = r.
Theorem digitO : digit 0 = 0.
Theorem digit1 : digit 1 = 1.
Theorem digit_monotone : forall p q : Z, (Zabs p <= Zabs q)%Z -> digit p <= digit q.
Theorem digitNotZero : forall q : Z, q <> 0%Z -> 0 < digit q.
Theorem digitAdd : forall (q : Z) (r : nat), q <> 0%Z -> digit (q * Zpower_nat n r) = digit q + r.
Theorem digit_minus1 : forall p : nat, digit (Zpower_nat n p - 1) = p.
Theorem digit_bound : forall (x y z : Z) (n : nat), (Zabs x <= Zabs y)%Z -> (Zabs y <= Zabs z)%Z -> digit x = n -> digit z = n -> digit y = n.
Theorem digit_abs : forall p : Z, digit (Zabs p) = digit p.
Theorem digit_anti_monotone_lt : (1 < n)%Z -> forall p q : Z, digit p < digit q -> (Zabs p < Zabs q)%Z.