(** Number of bits (radix 2) of a positive integer.

It serves as an upper bound on the number of digits to ensure termination.
*)

Fixpoint digits2_Pnat (n : positive) : nat :=
  match n with
  | xH => O
  | xO p => S (digits2_Pnat p)
  | xI p => S (digits2_Pnat p)
  end.

(* Specifications: *)
Theorem digits2_Pnat_correct : forall n, let d := digits2_Pnat n in (Zpower_nat 2 d <= Zpos n < Zpower_nat 2 (S d))%Z.