Closest

# Library Closest

`Require Export Fround.
Section Fclosest.
Variable b : Fbound.
Variable radix : Z.
Variable precision : nat.
Coercion Local FtoRradix := FtoR radix.
Hypothesis radixMoreThanOne : (1 < radix)%Z.
Hypothesis precisionGreaterThanOne : 1 < precision.
Hypothesis pGivesBound : Zpos (vNum b) = Zpower_nat radix precision.
Definition Closest (r : R) (p : float) :=
Fbounded b p /\
(forall f : float, Fbounded b f -> (Rabs (p - r) <= Rabs (f - r))%R).
Theorem ClosestTotal : TotalP Closest.
Theorem ClosestCompatible : CompatibleP b radix Closest.
Theorem ClosestMin :
forall (r : R) (min max : float),
isMin b radix r min ->
isMax b radix r max -> (2%nat * r <= min + max)%R -> Closest r min.
Theorem ClosestMax :
forall (r : R) (min max : float),
isMin b radix r min ->
isMax b radix r max -> (min + max <= 2%nat * r)%R -> Closest r max.
Theorem ClosestMinOrMax : MinOrMaxP b radix Closest.
Theorem ClosestMinEq :
forall (r : R) (min max p : float),
isMin b radix r min ->
isMax b radix r max ->
(2%nat * r < min + max)%R -> Closest r p -> p = min :>R.
Theorem ClosestMaxEq :
forall (r : R) (min max p : float),
isMin b radix r min ->
isMax b radix r max ->
(min + max < 2%nat * r)%R -> Closest r p -> p = max :>R.
Theorem ClosestMonotone : MonotoneP radix Closest.
Theorem ClosestRoundedModeP : RoundedModeP b radix Closest.
Definition EvenClosest (r : R) (p : float) :=
Closest r p /\
(FNeven b radix precision p \/ (forall q : float, Closest r q -> q = p :>R)).
Theorem EvenClosestTotal : TotalP EvenClosest.
Theorem EvenClosestCompatible : CompatibleP b radix EvenClosest.
Theorem EvenClosestMinOrMax : MinOrMaxP b radix EvenClosest.
Theorem EvenClosestMonotone : MonotoneP radix EvenClosest.
Theorem EvenClosestRoundedModeP : RoundedModeP b radix EvenClosest.
Theorem EvenClosestUniqueP : UniqueP radix EvenClosest.
Theorem ClosestSymmetric : SymmetricP Closest.
Theorem EvenClosestSymmetric : SymmetricP EvenClosest.
End Fclosest.
Hint Resolve ClosestTotal ClosestCompatible ClosestMin ClosestMax
ClosestMinOrMax ClosestMonotone ClosestRoundedModeP EvenClosestTotal
EvenClosestCompatible EvenClosestMinOrMax EvenClosestMonotone
EvenClosestRoundedModeP FnOddNEven EvenClosestUniqueP ClosestSymmetric
EvenClosestSymmetric: float.
`