End Double_round_plus_FTZ.
Section Double_round_plus_beta_ge_3.
Definition double_round_plus_beta_ge_3_hyp fexp1 fexp2 :=
(forall ex ey, (fexp1 (ex + 1) <= ey)%Z -> (fexp2 ex <= fexp1 ey)%Z)
/\ (forall ex ey, (fexp1 (ex - 1) + 1 <= ey)%Z -> (fexp2 ex <= fexp1 ey)%Z)
/\ (forall ex ey, (fexp1 ex <= ey)%Z -> (fexp2 ex <= fexp1 ey)%Z)
/\ (forall ex ey, (ex - 1 <= ey)%Z -> (fexp2 ex <= fexp1 ey)%Z).

(* Specifications: *)
(* fexp1 (ln_beta x) <= ln_beta y : * addition is exact in the largest precision (fexp2). *)
Lemma double_round_plus_beta_ge_3_aux0 :
forall (fexp1 fexp2 : Z -> Z), Valid_exp fexp1 ->
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
(0 < y)%R -> (y <= x)%R ->
(fexp1 (ln_beta x) <= ln_beta y)%Z ->
generic_format beta fexp1 x -> generic_format beta fexp1 y ->
generic_format beta fexp2 (x + y).
(* ln_beta y <= fexp1 (ln_beta x) - 1 : double_round_lt_mid applies. *)
Lemma double_round_plus_beta_ge_3_aux1 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < x -> 0 < y ->
(ln_beta y <= fexp1 (ln_beta x) - 1)%Z ->
generic_format beta fexp1 x ->
double_round_eq fexp1 fexp2 choice1 choice2 (x + y).
(* double_round_plus_beta_ge_3_aux{0,1} together *)
Lemma double_round_plus_beta_ge_3_aux2 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y <= x ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x + y).
Lemma double_round_plus_beta_ge_3_aux :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 <= x -> 0 <= y ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x + y).
(* fexp1 (ln_beta x) <= ln_beta y : * substraction is exact in the largest precision (fexp2). *)
Lemma double_round_minus_beta_ge_3_aux0 :
forall (fexp1 fexp2 : Z -> Z),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y < x ->
(fexp1 (ln_beta x) <= ln_beta y)%Z ->
generic_format beta fexp1 x -> generic_format beta fexp1 y ->
generic_format beta fexp2 (x - y).
(* ln_beta y <= fexp1 (ln_beta x) - 1, * fexp1 (ln_beta (x - y)) <= ln_beta y : * substraction is exact in the largest precision (fexp2). *)
Lemma double_round_minus_beta_ge_3_aux1 :
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y < x ->
(ln_beta y <= fexp1 (ln_beta x) - 1)%Z ->
(fexp1 (ln_beta (x - y)) <= ln_beta y)%Z ->
generic_format beta fexp1 x -> generic_format beta fexp1 y ->
generic_format beta fexp2 (x - y).
(* ln_beta y <= fexp1 (ln_beta x) - 1 : * ln_beta y <= fexp1 (ln_beta (x - y)) - 1 : * double_round_gt_mid applies. *)
Lemma double_round_minus_beta_ge_3_aux2 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y < x ->
(ln_beta y <= fexp1 (ln_beta x) - 1)%Z ->
(ln_beta y <= fexp1 (ln_beta (x - y)) - 1)%Z ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x - y).
(* double_round_minus_aux{0,1,2} together *)
Lemma double_round_minus_beta_ge_3_aux3 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y <= x ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x - y).
Lemma double_round_minus_beta_ge_3_aux :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 <= x -> 0 <= y ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x - y).
Lemma double_round_plus_beta_ge_3 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x + y).
Lemma double_round_minus_beta_ge_3 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x - y).
(* fexp1 (ln_beta x) <= ln_beta y : * addition is exact in the largest precision (fexp2). *)
Lemma double_round_plus_beta_ge_3_aux0 :
forall (fexp1 fexp2 : Z -> Z), Valid_exp fexp1 ->
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
(0 < y)%R -> (y <= x)%R ->
(fexp1 (ln_beta x) <= ln_beta y)%Z ->
generic_format beta fexp1 x -> generic_format beta fexp1 y ->
generic_format beta fexp2 (x + y).
(* ln_beta y <= fexp1 (ln_beta x) - 1 : double_round_lt_mid applies. *)
Lemma double_round_plus_beta_ge_3_aux1 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < x -> 0 < y ->
(ln_beta y <= fexp1 (ln_beta x) - 1)%Z ->
generic_format beta fexp1 x ->
double_round_eq fexp1 fexp2 choice1 choice2 (x + y).
(* double_round_plus_beta_ge_3_aux{0,1} together *)
Lemma double_round_plus_beta_ge_3_aux2 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y <= x ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x + y).
Lemma double_round_plus_beta_ge_3_aux :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 <= x -> 0 <= y ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x + y).
(* fexp1 (ln_beta x) <= ln_beta y : * substraction is exact in the largest precision (fexp2). *)
Lemma double_round_minus_beta_ge_3_aux0 :
forall (fexp1 fexp2 : Z -> Z),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y < x ->
(fexp1 (ln_beta x) <= ln_beta y)%Z ->
generic_format beta fexp1 x -> generic_format beta fexp1 y ->
generic_format beta fexp2 (x - y).
(* ln_beta y <= fexp1 (ln_beta x) - 1, * fexp1 (ln_beta (x - y)) <= ln_beta y : * substraction is exact in the largest precision (fexp2). *)
Lemma double_round_minus_beta_ge_3_aux1 :
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y < x ->
(ln_beta y <= fexp1 (ln_beta x) - 1)%Z ->
(fexp1 (ln_beta (x - y)) <= ln_beta y)%Z ->
generic_format beta fexp1 x -> generic_format beta fexp1 y ->
generic_format beta fexp2 (x - y).
(* ln_beta y <= fexp1 (ln_beta x) - 1 : * ln_beta y <= fexp1 (ln_beta (x - y)) - 1 : * double_round_gt_mid applies. *)
Lemma double_round_minus_beta_ge_3_aux2 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y < x ->
(ln_beta y <= fexp1 (ln_beta x) - 1)%Z ->
(ln_beta y <= fexp1 (ln_beta (x - y)) - 1)%Z ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x - y).
(* double_round_minus_aux{0,1,2} together *)
Lemma double_round_minus_beta_ge_3_aux3 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 < y -> y <= x ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x - y).
Lemma double_round_minus_beta_ge_3_aux :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
0 <= x -> 0 <= y ->
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x - y).
Lemma double_round_plus_beta_ge_3 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x + y).
Lemma double_round_minus_beta_ge_3 :
(3 <= beta)%Z ->
forall (fexp1 fexp2 : Z -> Z),
Valid_exp fexp1 -> Valid_exp fexp2 ->
forall (choice1 choice2 : Z -> bool),
double_round_plus_beta_ge_3_hyp fexp1 fexp2 ->
forall x y,
generic_format beta fexp1 x ->
generic_format beta fexp1 y ->
double_round_eq fexp1 fexp2 choice1 choice2 (x - y).