proposition: Lemma wminus_Alt2: forall sz x y, y <= x -> @wminusN sz x y = wordBinN minus x y.
proof: Proof. intros. unfold wminusN, wplusN, wnegN, wordBinN. destruct (weq y (natToWord sz 0)); subst. rewrite roundTrip_0. repeat rewrite Nat.sub_0_r. rewrite <- drop_sub with (k:=1) (n:=pow2 sz); try lia. replace (pow2 sz - 1 * pow2 sz) with (0) by lia. rewrite roundTrip_0. rewrite <- plus_n_O. reflexivity. rewrite wordToNat_natToWord_idempotent' with (n:=pow2 sz - wordToNat y). rewrite <- drop_sub with (k:=1). simpl. rewrite <- plus_n_O. replace (wordToNat x + (pow2 sz - wordToNat y) - pow2 sz) with (wordToNat x - wordToNat y). auto. rewrite Nat.add_sub_assoc. lia. generalize dependent (wordToNat_bound y); intros; lia. simpl. rewrite <- plus_n_O. rewrite Nat.add_sub_assoc; [| generalize dependent (wordToNat_bound y); intros; lia ]. rewrite Nat.add_comm. rewrite <- Nat.add_sub_assoc. lia. apply Nat.nlt_ge. unfold not in *; intros. apply H. apply lt_wlt; auto. apply Nat.sub_lt. generalize dependent (wordToNat_bound y); intros; lia. assert (wordToNat y <> 0); [ | lia ]. assert (wordToN y <> wordToN (natToWord sz 0)). unfold not in *. intros. apply n. apply wordToN_inj. auto. repeat rewrite wordToN_nat in H0. unfold not in *. intros. apply H0. apply N2Nat.inj. repeat rewrite Nat2N.id. rewrite roundTrip_0. 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