proposition: Lemma wordToZ_inj: forall sz (w1 w2: word sz), wordToZ w1 = wordToZ w2 -> w1 = w2.
proof: Proof. unfold wordToZ; intros. remember (wmsb w1 false) as msb1. remember (wmsb w2 false) as msb2. destruct msb1, msb2. - remember (wordToN (wneg w1)) as wn1. remember (wordToN (wneg w2)) as wn2. destruct wn1, wn2; try discriminate. + assert (wneg w1 = wneg w2). { apply wordToN_inj. rewrite <-Heqwn1, <-Heqwn2; reflexivity. } rewrite <-wneg_idempotent with (w:= w1). rewrite <-wneg_idempotent with (w:= w2). rewrite H0; reflexivity. + inversion H; subst; clear H. assert (wneg w1 = wneg w2). { apply wordToN_inj. rewrite <-Heqwn1, <-Heqwn2; reflexivity. } rewrite <-wneg_idempotent with (w:= w1). rewrite <-wneg_idempotent with (w:= w2). rewrite H; reflexivity. - remember (wordToN (wneg w1)) as wn1. remember (wordToN w2) as wn2. destruct wn1, wn2; try discriminate. rewrite <-wordToN_wzero with (sz:= sz) in Heqwn1, Heqwn2. apply wordToN_inj in Heqwn1. apply wordToN_inj in Heqwn2. assert (w1 = wzero sz). { rewrite <-wneg_idempotent with (w:= w1), <-Heqwn1. apply wzero_wneg. } subst; reflexivity. - remember (wordToN w1) as wn1. remember (wordToN (wneg w2)) as wn2. destruct wn1, wn2; try discriminate. rewrite <-wordToN_wzero with (sz:= sz) in Heqwn1, Heqwn2. apply wordToN_inj in Heqwn1. apply wordToN_inj in Heqwn2. assert (w2 = wzero sz). { rewrite <-wneg_idempotent with (w:= w2), <-Heqwn2. apply wzero_wneg. } subst; reflexivity. - remember (wordToN w1) as wn1. remember (wordToN w2) as wn2. destruct wn1, wn2; try discriminate. + rewrite <-wordToN_wzero with (sz:= sz) in Heqwn1, Heqwn2. rewrite Heqwn1 in Heqwn2. apply wordToN_inj in Heqwn2; auto. + inversion H; subst; clear H. rewrite Heqwn1 in Heqwn2. apply wordToN_inj in Heqwn2; 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