unfold r'0. unfold d0. unfold r0. fold r'_i. (* too long *)
unfold s''_i. fold t. fold p. elim (Zle_or_lt c r'_i); intro H. rewrite ltw_false. rewrite ltw_false. simpl. fold M''.
rewrite M''_M. fold M. fold x_i. rewrite Zmult_comm. rewrite <- Zmod_mult_distr_l. rewrite <- Zmod_plus_distr_l.
rewrite <- Zmod_minus_distr_r. rewrite <- Zmod_plus_distr_l. rewrite Zplus_comm with (n := 2 ^ t * r'_i).
rewrite <- Zmod_plus_distr_l. fold p. apply f_equal2 with (f := Zmod). ring. trivial. exact lt02w. exact lt02w. exact lt02w.
exact lt02w. exact lt02w. assumption. assumption. rewrite ltw_true. rewrite ltw_true. trivial. assumption. assumption. Qed.

(* Specifications: *)
(* <KE EP TOGETHER - q_i_eq *)
Lemma q_i_eq :
_Z q_i = x' / 2 ^ p * (2 ^ (p + w) / M mod 2 ^ w) / 2 ^ w.