proposition: Lemma wordToZ_wordToN: forall sz (w: word sz), wordToZ w = (Z.of_N (wordToN w) - Z.of_N (if wmsb w false then Npow2 sz else 0))%Z.
proof: Proof. unfold wordToZ; intros. remember (wmsb w false) as msb; destruct msb; [|simpl; rewrite Z.sub_0_r; reflexivity]. destruct (weq w (wzero _)); subst; [rewrite wmsb_wzero in Heqmsb; discriminate|]. rewrite wneg_wordToN. - pose proof (wordToN_bound w). replace (Z.of_N (wordToN w) - Z.of_N (Npow2 sz))%Z with (- (Z.of_N (Npow2 sz) - Z.of_N (wordToN w)))%Z by lia. rewrite <-N2Z.inj_sub by (apply N.lt_le_incl; assumption). clear; destruct (Npow2 sz - wordToN w)%N; reflexivity. - intro Hx; elim n. rewrite <-wordToN_wzero with (sz:= sz) in Hx. apply wordToN_inj in Hx; 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