Fixpoint countLeadingZerosWord_nat ni: word ni -> nat :=
match ni return word ni -> nat with
| 0 => fun _ => 0
| S m => fun e =>
if (weq (split2 m 1 (nat_cast (fun n => word n) (eq_sym (Nat.add_1_r m)) e)) WO~0)
then 1 + @countLeadingZerosWord_nat m (split1 m 1 (nat_cast (fun n => word n) (eq_sym (Nat.add_1_r m)) e))
else 0
end.

(* Usually this kind of lemmas would need a guarantee that "(wordToN a mod wordToN b)%N" does not overflow, but fortunately this can never overflow. And also, we don't need to prevent b from being 0. *)
Lemma wordToN_mod: forall sz (a b: word sz),
wordToN (a ^% b) = (wordToN a mod wordToN b)%N.