rewrite <- l'_i_eq. rewrite <- Zmod_minus_distr_l. replace (_Z d_i + _Z l'_i - M) with (_Z d_i + (_Z l'_i - M)).
replace (_Z l'_i - M) with (_Z l'_i mod M). trivial. rewrite l'_i_eq. rewrite l'_i_eq in H. rewrite <- Zmod_minus_m.
apply modred. omega. cut (x' mod 2 ^ p < M + M). omega. apply Zlt_le_trans with (2 ^ p). apply Zmod_lt_z_m. apply lt_0_Zpow.
auto with a. apply Zlt_le_weak. exact le2ppMM. omega. ring. auto with a. assumption. rewrite ltw_true. rewrite rrr_i_eq.
rewrite l'_i_eq in H. rewrite modred with (m := M). trivial. apply Zmod_le_0_z. apply lt_0_Zpow. auto with a. assumption.
assumption. Qed.
Definition d_ir_i := (d_i, r_i).

(* Specifications: *)
Lemma d_i_r_i_eq : P' M p d_i r_i x x_i_in_Z_.
unfold P'. split. elim d_i_eq; unfold x'. elim r'a_eq; intro H; rewrite H. tauto. tauto. elim r'a_eq; intro H; rewrite H. tauto.