proposition: Lemma wneg_wnot: forall sz (w: word sz), wnot w = wneg w ^- (natToWord _ 1).
proof: Proof. unfold wneg; intros. rewrite wnot_def. destruct (weq w (wzero _)); subst. - rewrite wordToN_nat. unfold wzero; rewrite roundTrip_0; cbn. rewrite N.sub_0_r. do 2 rewrite NToWord_nat. rewrite Npow2_nat, natToWord_pow2, N2Nat.inj_sub. change (N.to_nat 1%N) with 1. rewrite Npow2_nat. apply wordToNat_inj. rewrite wordToNat_natToWord_2 by (pose proof (zero_lt_pow2 sz); lia). unfold wminus. rewrite wplus_unit, <-wones_wneg_one. apply eq_sym, wones_pow2_minus_one. - pose proof (wordToN_bound w). assert (Npow2 sz - wordToN w < Npow2 sz)%N. { apply N.sub_lt. { apply N.lt_le_incl; auto. } { assert (wordToN w <> 0)%N. { replace 0%N with (wordToN (wzero sz)). { intro Hx; elim n. apply wordToN_inj; auto. } { rewrite wordToN_nat. unfold wzero; rewrite roundTrip_0; reflexivity. } } nomega. } } apply N.sub_gt in H. remember (Npow2 sz - wordToN w)%N as p; clear Heqp. do 2 rewrite NToWord_nat. rewrite N2Nat.inj_sub. change (N.to_nat 1%N) with 1. assert (N.to_nat p < pow2 sz)%nat by (rewrite <-Npow2_nat; apply Nlt_out; auto); clear H0. assert (N.to_nat p <> 0) by (change 0 with (N.to_nat 0%N); intro Hx; elim H; apply N2Nat.inj; auto); clear H. apply wordToNat_inj. rewrite <-wordToNat_natToWord_pred. + do 2 rewrite wordToNat_natToWord_2 by lia. lia. + intro Hx; elim H0. apply natToWord_inj with (sz:= sz); try lia. assumption. 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