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

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.