Section digits_aux.
Variable p : Z.
Fixpoint Zdigits_aux (nb pow : Z) (n : nat) { struct n } : Z :=
match n with
| O => nb
| S n => if Zlt_bool p pow then nb else Zdigits_aux (nb + 1) (Zmult beta pow) n
end.
End digits_aux.
(** Number of digits of an integer *)
Definition Zdigits n :=
match n with
| Z0 => Z0
| Zneg p => Zdigits_aux (Zpos p) 1 beta (digits2_Pnat p)
| Zpos p => Zdigits_aux n 1 beta (digits2_Pnat p)
end.
(** Number of digits of a product.  This strong version is needed for proofs of division and square root algorithms, since they involve operation remainders. *)

Theorem Zdigits_mult_ge :
forall x y,
(x <> 0)%Z -> (y <> 0)%Z ->
(Zdigits x + Zdigits y - 1 <= Zdigits (x * y))%Z.