Library Fcomp
Require Export Float.
Section comparisons.
Variable radix : Z.
Hypothesis radixMoreThanOne : (1 < radix)%Z.
Let radixMoreThanZERO := Zlt_1_O _ (Zlt_le_weak _ _ radixMoreThanOne).
Hint Resolve radixMoreThanZERO: zarith.
Definition Fdiff (x y : float) :=
(Fnum x * Zpower_nat radix (Zabs_nat (Fexp x - Zmin (Fexp x) (Fexp y))) -
Fnum y * Zpower_nat radix (Zabs_nat (Fexp y - Zmin (Fexp x) (Fexp y))))%Z.
Coercion Local FtoRradix := FtoR radix.
Theorem Fdiff_correct :
forall x y : float,
(Fdiff x y * powerRZ radix (Zmin (Fexp x) (Fexp y)))%R = (x - y)%R.
Definition Feq (x y : float) := x = y :>R.
Definition Fle (x y : float) := (x <= y)%R.
Definition Flt (x y : float) := (x < y)%R.
Definition Fge (x y : float) := (x >= y)%R.
Definition Fgt (x y : float) := (x > y)%R.
Definition Fcompare (x y : float) := (Fdiff x y ?= 0)%Z.
Definition Feq_bool (x y : float) :=
match Fcompare x y with
| Eq => true
| _ => false
end.
Theorem Feq_bool_correct_t :
forall x y : float, Feq_bool x y = true -> Feq x y.
Theorem Feq_bool_correct_r :
forall x y : float, Feq x y -> Feq_bool x y = true.
Theorem Feq_bool_correct_f :
forall x y : float, Feq_bool x y = false -> ~ Feq x y.
Definition Flt_bool (x y : float) :=
match Fcompare x y with
| Lt => true
| _ => false
end.
Theorem Flt_bool_correct_t :
forall x y : float, Flt_bool x y = true -> Flt x y.
Theorem Flt_bool_correct_r :
forall x y : float, Flt x y -> Flt_bool x y = true.
Theorem Flt_bool_correct_f :
forall x y : float, Flt_bool x y = false -> Fle y x.
Definition Fle_bool (x y : float) :=
match Fcompare x y with
| Lt => true
| Eq => true
| _ => false
end.
Theorem Fle_bool_correct_t :
forall x y : float, Fle_bool x y = true -> Fle x y.
Theorem Fle_bool_correct_r :
forall x y : float, Fle x y -> Fle_bool x y = true.
Theorem Fle_bool_correct_f :
forall x y : float, Fle_bool x y = false -> Flt y x.
Lemma Fle_Zle :
forall n1 n2 d : Z, (n1 <= n2)%Z -> Fle (Float n1 d) (Float n2 d).
Lemma Flt_Zlt :
forall n1 n2 d : Z, (n1 < n2)%Z -> Flt (Float n1 d) (Float n2 d).
Lemma Fle_Fge : forall x y : float, Fle x y -> Fge y x.
Lemma Fge_Zge :
forall n1 n2 d : Z, (n1 >= n2)%Z -> Fge (Float n1 d) (Float n2 d).
Lemma Flt_Fgt : forall x y : float, Flt x y -> Fgt y x.
Lemma Fgt_Zgt :
forall n1 n2 d : Z, (n1 > n2)%Z -> Fgt (Float n1 d) (Float n2 d).
Lemma Fle_refl : forall x y : float, Feq x y -> Fle x y.
Lemma Fle_trans : forall x y z : float, Fle x y -> Fle y z -> Fle x z.
Theorem Rlt_Fexp_eq_Zlt :
forall x y : float, (x < y)%R -> Fexp x = Fexp y -> (Fnum x < Fnum y)%Z.
Theorem Rle_Fexp_eq_Zle :
forall x y : float, (x <= y)%R -> Fexp x = Fexp y -> (Fnum x <= Fnum y)%Z.
Theorem LtR0Fnum : forall p : float, (0 < p)%R -> (0 < Fnum p)%Z.
Theorem LeR0Fnum : forall p : float, (0 <= p)%R -> (0 <= Fnum p)%Z.
Theorem LeFnumZERO : forall x : float, (0 <= Fnum x)%Z -> (0 <= x)%R.
Theorem R0LtFnum : forall p : float, (p < 0)%R -> (Fnum p < 0)%Z.
Theorem R0LeFnum : forall p : float, (p <= 0)%R -> (Fnum p <= 0)%Z.
Theorem LeZEROFnum : forall x : float, (Fnum x <= 0)%Z -> (x <= 0)%R.
End comparisons.
Hint Resolve LeFnumZERO LeZEROFnum: float.