proposition: Lemma sext_wneg_natToWord': forall sz1 sz2 n, (2 * n < pow2 sz1)%nat -> sext (wneg (natToWord sz1 n)) sz2 = wneg (natToWord (sz1 + sz2) n).
proof: Proof. intros. rewrite wneg_alt. unfold wnegN. destruct n as [|n]. - rewrite roundTrip_0. rewrite Nat.sub_0_r. rewrite natToWord_pow2. unfold sext. assert (wmsb (natToWord sz1 0) false = false) as W. { destruct sz1. + simpl. reflexivity. + apply wmsb_0_natToWord. assumption. } rewrite W. rewrite combine_wzero. symmetry. apply wneg_zero'. - rewrite sext_wneg_natToWord''. + rewrite wneg_alt. unfold wnegN. rewrite wordToNat_natToWord_idempotent' by lia. rewrite wordToNat_natToWord_idempotent'. * replace (pow2 sz1 - (pow2 sz1 - S n)) with (S n) by lia. reflexivity. * rewrite pow2_add_mul. apply Nat.le_trans with (m := pow2 sz1); [lia|]. rewrite <- Nat.mul_1_r at 1. apply Nat.mul_le_mono_l. apply one_le_pow2. + rewrite wordToNat_natToWord_idempotent' by lia. simpl. lia. 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