proposition: Lemma uwordToZ_ZToWord_k: forall (sz : nat) (n : Z), (0 <= n)%Z -> exists k, uwordToZ (ZToWord sz n) = (n - k * 2 ^ Z.of_nat sz)%Z /\ (k * 2 ^ Z.of_nat sz <= n)%Z.
proof: Proof. intros *. intro C. unfold uwordToZ. pose proof (wordToN_NToWord sz (Z.to_N n)) as P. destruct P as [k [P Q]]. exists (Z.of_N k). rewrite NToWord_Z_to_N in P by assumption. rewrite P. clear P. rewrite <- Z_of_N_Npow2 in *. rewrite <- N2Z.inj_mul. rewrite N2Z.inj_sub by assumption. apply N2Z.inj_le in Q. rewrite Z2N.id in * by assumption. 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