Section parm_sec.
Variable M_in_Z_ : Z_ (2 ^ w).
Variable ptM' : Z_ w * Z_ w * Z_ (2 ^ w).
Variables v_in_Z_ u_in_Z_ : Z_ (2 ^ w).
Let p_in_Z_w := fst (fst ptM').
Let t_in_Z_w := snd (fst ptM').
Let M'_in_Z_ := snd ptM'.
Let M := _Z M_in_Z_.
Let p := _Z p_in_Z_w.
Let t := _Z t_in_Z_w.
Let M' := _Z M'_in_Z_.
Let v := _Z v_in_Z_.
Let u := _Z u_in_Z_.
Hypothesis le_1_M : 1 <= M.
Hypothesis le_M_max : M <= 2 ^ (w - 1).
Hypothesis p_M : p = Zlog_sup M.
Hypothesis t_M : t = w - p \/ M = 1.
Hypothesis M'_M : M' = 2 ^ (p + w) / M mod 2 ^ w.
Hypothesis v_M : v < 2 ^ p.
Let x := v * 2 ^ w + u.
unfold p. apply le_0__Z. Qed.
unfold u. apply le_0__Z. Qed.
unfold u. apply lt_z__Z. Qed.
unfold v. apply le_0__Z. Qed.
unfold v. apply lt_z__Z. Qed.
apply Zlt_le_weak. exact lt02w. Qed.
Local Hint Resolve le_0_w lt02w le02w : a.
Local Hint Resolve le_0_p le_0_l lt_l_2w le_0_v lt_v_2w : a.
unfold x. fold (0 + 0). apply Zplus_le_compat; auto with a. apply Zmult_le_0_compat; auto with a. Qed.
Local Hint Resolve le_0_x : a.
(* <KEEP TOGETHER - modred_equations *)
Let s := ursh u_in_Z_ p_in_Z_w.
Let s' := multp2 s p_in_Z_w.
Let h := multp2 v_in_Z_ t_in_Z_w.
Let h' := plusw h s.
Let q := uhwm h' M'_in_Z_.
Let q' := plusw q h'.
Let y := multw q' M_in_Z_.
Let d := minusw s' y.
Let r := minusw u_in_Z_ y.
Let r' := ltw d M_in_Z_ r (minusw r M_in_Z_).
Let r'' := ltw r' M_in_Z_ r' (minusw r' M_in_Z_).
Let r''' := ltw r'' M_in_Z_ r'' (minusw r'' M_in_Z_).
(* KEEP TOGETHER> *)
Definition ModRed := _Z r'''. (* keeps _Z out of ModRed_eq *)
unfold x. rewrite Zmod_km_plus. symmetry. apply modred. auto with a. auto with a. auto with a. Qed.
unfold x. rewrite Zdiv_times_plus. rewrite Zdiv_small_0. ring. auto with a. auto with a. auto with a. Qed.
(* KEEP TOGETHER> *)
simpl. fold u. fold p. rewrite l_eq. trivial. Qed.
apply lt_0_Zpow. fold (0 + 0). apply Zplus_le_compat; auto with a. Qed.
apply lt_0_Zpow. auto with a. Qed.
Local Hint Resolve lt_0_2pp : a.
unfold x. apply Z.le_lt_trans with ((2 ^ p - 1) * 2 ^ w + (2 ^ w - 1)). apply Zplus_le_compat.
apply Zmult_le_compat. auto with a. auto with a. cut (v < 2 ^ p). omega. auto with a. omega. auto with a.
auto with a. cut (u < 2 ^ w). omega. auto with a. rewrite Zmult_minus_distr_r. rewrite <- Zpower_exp.
omega. auto with a. apply Z.le_ge. auto with a. apply Z.le_ge. auto with a. Qed.
cut (x < 2 ^ (p + w)). omega. exact lt_x_xmax. Qed.
Local Hint Resolve lt_x_xmax le_x_xmax : a.
cut (0 < w). omega. exact lt_0_w. Qed.
Local Hint Resolve le_0_wm1 lt_0_w : a.
rewrite p_M. apply Z.le_lt_trans with (w - 1). rewrite <- Zlog_sup_pow. apply Zlog_sup_seq.
assumption. auto with a. omega. Qed.
apply Zlt_le_weak. exact lt_p_w. Qed.
cut (p <= w). omega. exact le_p_w. Qed.
Local Hint Resolve lt_p_w le_p_w le_0_wmp : a.
(* KEEP TOGETHER> *)
unfold s'. rewrite Z_from_multp2. fold p. rewrite s_eq. rewrite Zmult_comm. rewrite modred.
replace (x mod 2 ^ p) with (x mod 2 ^ w mod 2 ^ p). apply Zdiv_a_b_b_Zmod. auto with a.
replace (2 ^ w) with (2 ^ (w - p) * 2 ^ p). apply Zmod_prod_Zmod. apply lt_0_Zpow. auto with a.
auto with a. rewrite <- Zpower_exp. apply f_equal2 with (f := Zpower). trivial. ring. apply Z.le_ge.
auto with a. apply Z.le_ge. auto with a. fold (0 * 0). apply Zmult_le_compat. apply Zle_0_div.
apply Zmod_le_0_z. auto with a. auto with a. apply Zlt_le_weak. auto with a. omega. omega.
apply Z.le_lt_trans with (x mod 2 ^ w). rewrite Zmult_comm. apply Z_mult_div_ge. apply Z.lt_gt.
auto with a. apply Zmod_lt_z_m. auto with a. Qed.

(* <KEEP TOGETHER - h_eq *)
Lemma h_eq : _Z h = x / 2 ^ w * 2 ^ (w - p).