proposition: Lemma wordToNat_natToWord' : forall sz w, exists k, wordToNat (natToWord sz w) + k * pow2 sz = w.
proof: Proof. induction sz as [|sz IHsz]; simpl; intro w; intuition; repeat rewrite untimes2. exists w; intuition. case_eq (mod2 w); intro Hmw. specialize (IHsz (Nat.div2 w)); firstorder. rewrite wordToNat_wordToNat' in *. let x' := match goal with H : _ + ?x * _ = _ |- _ => x end in rename x' into x. exists x; intuition. rewrite Nat.mul_assoc. rewrite (Nat.mul_comm x 2). rewrite Nat.mul_comm. simpl mult at 1. rewrite (plus_Sn_m (2 * wordToNat' (natToWord sz (Nat.div2 w)))). rewrite <- Nat.mul_assoc. rewrite <- Nat.mul_add_distr_l. rewrite H; clear H. symmetry; apply div2_odd; auto. specialize (IHsz (Nat.div2 w)); firstorder. let x' := match goal with H : _ + ?x * _ = _ |- _ => x end in rename x' into x. exists x; intuition. rewrite Nat.mul_assoc. rewrite (Nat.mul_comm x 2). rewrite <- Nat.mul_assoc. rewrite Nat.mul_comm. rewrite <- Nat.mul_add_distr_l. match goal with H : _ |- _ => rewrite H; clear H end. symmetry; apply div2_even; auto. Qed.
imports: Coq.Classes.Morphisms Coq.Classes.Morphisms_Prop Coq.Classes.Equivalence Coq.Arith.PeanoNat Coq.ZArith.BinInt  Coq.Arith.Arith Coq.NArith.NArith Coq.Bool.Bool Coq.ZArith.ZArith Coq.Logic.Eqdep_dec Coq.Logic.EqdepFacts Coq.Program.Tactics Coq.Program.Equality Coq.setoid_ring.Ring Coq.setoid_ring.Ring_polynom bbv.Nomega bbv.ZLib bbv.NatLib bbv.NLib bbv.N_Z_nat_conversions bbv.DepEq bbv.DepEqNat bbv.ReservedNotations Coq.micromega.Lia