(** This file is part of the Flocq formalization of floating-point arithmetic in Coq: http://flocq.gforge.inria.fr/  Copyright (C) 2010-2013 Sylvie Boldo #<br /># Copyright (C) 2010-2013 Guillaume Melquiond  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the COPYING file for more details. *)
(** * Locations: where a real number is positioned with respect to its rounded-down value in an arbitrary format. *)
Section Fcalc_bracket.
Variable d u : R.
Hypothesis Hdu : (d < u)%R.
Inductive location := loc_Exact | loc_Inexact : comparison -> location.
Variable x : R.
Definition inbetween_loc :=
match Rcompare x d with
| Gt => loc_Inexact (Rcompare x ((d + u) / 2))
| _ => loc_Exact
end.
(** Locates a real number with respect to the middle of two other numbers. *)
Inductive inbetween : location -> Prop :=
| inbetween_Exact : x = d -> inbetween loc_Exact
| inbetween_Inexact l : (d < x < u)%R -> Rcompare x ((d + u) / 2)%R = l -> inbetween (loc_Inexact l).

(* Specifications: *)
Theorem inbetween_spec :
(d <= x < u)%R -> inbetween inbetween_loc.
Theorem inbetween_unique :
forall l l',
inbetween l -> inbetween l' -> l = l'.
Theorem inbetween_spec :
(d <= x < u)%R -> inbetween inbetween_loc.
Theorem inbetween_unique :
forall l l',
inbetween l -> inbetween l' -> l = l'.