(* KEEP TOGETHER> *)
unfold d. rewrite Z_from_minusw. rewrite s'_eq. rewrite Zmod_minus_distr_l.
rewrite <- Zmod_minus_distr_l with (b := x mod 2 ^ p). rewrite <- Zmod_minus_distr_l.
rewrite <- Zdiv_a_b_b_Zmod. elim y_eq; intro H. left. rewrite H. rewrite <- Zmod_minus_distr_r.
rewrite Zminus_Zdiv_Zmult. apply modred. apply Zmod_le_0_z. omega. apply Zlt_le_trans with M.
apply Zmod_lt_z_m. omega. auto with a. omega. auto with a. right. rewrite H.
rewrite <- Zmod_minus_distr_r.
replace (x / 2 ^ p * 2 ^ p - (x / 2 ^ p * 2 ^ p / M * M - M))
with (x / 2 ^ p * 2 ^ p - x / 2 ^ p * 2 ^ p / M * M + M). rewrite Zminus_Zdiv_Zmult. apply modred.
fold (0 + 0). apply Zplus_le_compat. apply Zmod_le_0_z. omega. omega. apply Zlt_le_trans with (M + M).
apply Zplus_lt_le_compat. apply Zmod_lt_z_m. omega. omega. rewrite Zpow_2_w_is_2Zpow_2_wm1. omega. omega.
ring. auto with a. auto with a. auto with a. auto with a. auto with a. Qed.

(* Specifications: *)
(* <KEEP TOGETHER - r_eq *)
Lemma r_eq : _Z r = (_Z d + x mod 2 ^ p) mod 2 ^ w.
unfold r. unfold d. rewrite Z_from_minusw. rewrite Z_from_minusw. fold u. rewrite s'_eq.