(** Definition and properties of pred and succ *)
Definition pred_pos x :=
if Req_bool x (bpow (ln_beta beta x - 1)) then
(x - bpow (fexp (ln_beta beta x - 1)))%R
else
(x - ulp x)%R.
Definition succ x :=
if (Rle_bool 0 x) then
(x+ulp x)%R
else
(- pred_pos (-x))%R.
Definition pred x := (- succ (-x))%R.

(* Specifications: *)
Theorem pred_eq_pos:
forall x, (0 <= x)%R -> (pred x = pred_pos x)%R.
Theorem succ_eq_pos:
forall x, (0 <= x)%R -> (succ x = x + ulp x)%R.
Lemma pred_eq_opp_succ_opp: forall x, pred x = (- succ (-x))%R.
Lemma succ_eq_opp_pred_opp: forall x, succ x = (- pred (-x))%R.
Lemma succ_opp: forall x, (succ (-x) = - pred x)%R.
Lemma pred_opp: forall x, (pred (-x) = - succ x)%R.
(** pred and succ are in the format *)
(* cannont be x <> ulp 0, due to the counter-example 1-bit FP format fexp: e -> e-1 *)
(* was pred_ge_bpow *)
Theorem id_m_ulp_ge_bpow :
forall x e,  F x ->
x <> ulp x ->
(bpow e < x)%R ->
(bpow e <= x - ulp x)%R.
(* was succ_le_bpow *)
Theorem id_p_ulp_le_bpow :
forall x e, (0 < x)%R -> F x ->
(x < bpow e)%R ->
(x + ulp x <= bpow e)%R.
Lemma generic_format_pred_aux1:
forall x, (0 < x)%R -> F x ->
x <> bpow (ln_beta beta x - 1) ->
F (x - ulp x).
Lemma generic_format_pred_aux2 :
forall x, (0 < x)%R -> F x ->
let e := ln_beta_val beta x (ln_beta beta x) in
x =  bpow (e - 1) ->
F (x - bpow (fexp (e - 1))).
Theorem generic_format_succ_aux1 :
forall x, (0 < x)%R -> F x ->
F (x + ulp x).
Theorem generic_format_pred_pos :
forall x, F x -> (0 < x)%R ->
F (pred_pos x).
Theorem generic_format_succ :
forall x, F x ->
F (succ x).
Theorem generic_format_pred :
forall x, F x ->
F (pred x).
Theorem pred_pos_lt_id :
forall x, (x <> 0)%R ->
(pred_pos x < x)%R.
Theorem succ_gt_id :
forall x, (x <> 0)%R ->
(x < succ x)%R.
Theorem pred_lt_id :
forall x,  (x <> 0)%R ->
(pred x < x)%R.
Theorem succ_ge_id :
forall x, (x <= succ x)%R.
Theorem pred_le_id :
forall x,  (pred x <= x)%R.
Theorem pred_pos_ge_0 :
forall x,
(0 < x)%R -> F x -> (0 <= pred_pos x)%R.
Theorem pred_ge_0 :
forall x,
(0 < x)%R -> F x -> (0 <= pred x)%R.
Lemma pred_pos_plus_ulp_aux1 :
forall x, (0 < x)%R -> F x ->
x <> bpow (ln_beta beta x - 1) ->
((x - ulp x) + ulp (x-ulp x) = x)%R.
Lemma pred_pos_plus_ulp_aux2 :
forall x, (0 < x)%R -> F x ->
let e := ln_beta_val beta x (ln_beta beta x) in
x =  bpow (e - 1) ->
(x - bpow (fexp (e-1)) <> 0)%R ->
((x - bpow (fexp (e-1))) + ulp (x - bpow (fexp (e-1))) = x)%R.
Lemma pred_pos_plus_ulp_aux3 :
forall x, (0 < x)%R -> F x ->
let e := ln_beta_val beta x (ln_beta beta x) in
x =  bpow (e - 1) ->
(x - bpow (fexp (e-1)) = 0)%R ->
(ulp 0 = x)%R.
Theorem pred_eq_pos:
forall x, (0 <= x)%R -> (pred x = pred_pos x)%R.
Theorem succ_eq_pos:
forall x, (0 <= x)%R -> (succ x = x + ulp x)%R.
Lemma pred_eq_opp_succ_opp: forall x, pred x = (- succ (-x))%R.
Lemma succ_eq_opp_pred_opp: forall x, succ x = (- pred (-x))%R.
Lemma succ_opp: forall x, (succ (-x) = - pred x)%R.
Lemma pred_opp: forall x, (pred (-x) = - succ x)%R.
(** pred and succ are in the format *)
(* cannont be x <> ulp 0, due to the counter-example 1-bit FP format fexp: e -> e-1 *)
(* was pred_ge_bpow *)
Theorem id_m_ulp_ge_bpow :
forall x e,  F x ->
x <> ulp x ->
(bpow e < x)%R ->
(bpow e <= x - ulp x)%R.
(* was succ_le_bpow *)
Theorem id_p_ulp_le_bpow :
forall x e, (0 < x)%R -> F x ->
(x < bpow e)%R ->
(x + ulp x <= bpow e)%R.
Lemma generic_format_pred_aux1:
forall x, (0 < x)%R -> F x ->
x <> bpow (ln_beta beta x - 1) ->
F (x - ulp x).
Lemma generic_format_pred_aux2 :
forall x, (0 < x)%R -> F x ->
let e := ln_beta_val beta x (ln_beta beta x) in
x =  bpow (e - 1) ->
F (x - bpow (fexp (e - 1))).
Theorem generic_format_succ_aux1 :
forall x, (0 < x)%R -> F x ->
F (x + ulp x).
Theorem generic_format_pred_pos :
forall x, F x -> (0 < x)%R ->
F (pred_pos x).
Theorem generic_format_succ :
forall x, F x ->
F (succ x).
Theorem generic_format_pred :
forall x, F x ->
F (pred x).
Theorem pred_pos_lt_id :
forall x, (x <> 0)%R ->
(pred_pos x < x)%R.
Theorem succ_gt_id :
forall x, (x <> 0)%R ->
(x < succ x)%R.
Theorem pred_lt_id :
forall x,  (x <> 0)%R ->
(pred x < x)%R.
Theorem succ_ge_id :
forall x, (x <= succ x)%R.
Theorem pred_le_id :
forall x,  (pred x <= x)%R.
Theorem pred_pos_ge_0 :
forall x,
(0 < x)%R -> F x -> (0 <= pred_pos x)%R.
Theorem pred_ge_0 :
forall x,
(0 < x)%R -> F x -> (0 <= pred x)%R.
Lemma pred_pos_plus_ulp_aux1 :
forall x, (0 < x)%R -> F x ->
x <> bpow (ln_beta beta x - 1) ->
((x - ulp x) + ulp (x-ulp x) = x)%R.
Lemma pred_pos_plus_ulp_aux2 :
forall x, (0 < x)%R -> F x ->
let e := ln_beta_val beta x (ln_beta beta x) in
x =  bpow (e - 1) ->
(x - bpow (fexp (e-1)) <> 0)%R ->
((x - bpow (fexp (e-1))) + ulp (x - bpow (fexp (e-1))) = x)%R.
Lemma pred_pos_plus_ulp_aux3 :
forall x, (0 < x)%R -> F x ->
let e := ln_beta_val beta x (ln_beta beta x) in
x =  bpow (e - 1) ->
(x - bpow (fexp (e-1)) = 0)%R ->
(ulp 0 = x)%R.