(* KEEP TOGETHER> *)
apply Zplus_le_compat. apply Zmod_le_0_z. omega. apply Zmod_le_0_z. auto with a.
rewrite Zpow_2_w_is_2Zpow_2_wm1. apply Zplus_lt_le_compat. apply Zlt_le_trans with M. apply Zmod_lt_z_m. omega.
assumption. apply Zlt_le_weak. apply Zlt_le_trans with (2 ^ p). apply Zmod_lt_z_m. auto with a. apply Zle_pow_le.
auto with a. cut (p < w). omega. auto with a. fold M. rewrite H. apply Zmod_lt_z_m. omega.
rewrite ltw_false. rewrite Z_from_minusw. rewrite r_eq. rewrite H. fold M. rewrite <- Zmod_minus_distr_l.
replace ((x / 2 ^ p * 2 ^ p) mod M + M + x mod 2 ^ p - M)
with ((x / 2 ^ p * 2 ^ p) mod M + x mod 2 ^ p). apply modred. fold (0 + 0). apply Zplus_le_compat.
apply Zmod_le_0_z. omega. apply Zmod_le_0_z. auto with a. rewrite Zpow_2_w_is_2Zpow_2_wm1.
apply Zplus_lt_le_compat. apply Zlt_le_trans with M. apply Zmod_lt_z_m. omega. assumption.
apply Zlt_le_weak. apply Zlt_le_trans with (2 ^ p). apply Zmod_lt_z_m. auto with a. apply Zle_pow_le. auto with a.
cut (p < w). omega. auto with a. ring. auto with a. fold M. rewrite H. cut (0 <= x / 2 ^ p * 2 ^ p mod M).
omega. apply Zmod_le_0_z. omega. Qed.

Lemma r'_x : _Z r' = x mod M \/ _Z r' = x mod M + M \/ _Z r' = x mod M + M + M.
rewrite r'_eq. rewrite <- Zdivmod_split with (x := x mod 2 ^ p) (m := M). rewrite Zdiv_a_b_b_Zmod.