Inductive location := loc_Exact | loc_Inexact : comparison -> location.Inductive location := loc_Exact | loc_Inexact : comparison -> location.Inductive location := loc_Exact | loc_Inexact : comparison -> location.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).(** 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).(** 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_bounds : inbetween l -> (d <= x < u)%R.
Theorem inbetween_bounds_not_Eq : inbetween l -> l <> loc_Exact -> (d < x < u)%R.
Theorem inbetween_distance_inexact : forall l, inbetween (loc_Inexact l) -> Rcompare (x - d) (u - x) = l.
Theorem inbetween_distance_inexact_abs : forall l, inbetween (loc_Inexact l) -> Rcompare (Rabs (d - x)) (Rabs (u - x)) = l.
Theorem inbetween_ex : forall d u l, (d < u)%R -> exists x, inbetween d u x l.
Lemma ordered_steps : forall k, (start + Z2R k * step < start + Z2R (k + 1) * step)%R.
Lemma middle_range : forall k, ((start + (start + Z2R k * step)) / 2 = start + (Z2R k / 2 * step))%R.
Lemma inbetween_step_not_Eq : forall x k l l', inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x l -> (0 < k < nb_steps)%Z -> Rcompare x (start + (Z2R nb_steps / 2 * step))%R = l' -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact l').
Theorem inbetween_step_Lo : forall x k l, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x l -> (0 < k)%Z -> (2 * k + 1 < nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Lt).
Theorem inbetween_step_Hi : forall x k l, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x l -> (nb_steps < 2 * k)%Z -> (k < nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Gt).
Theorem inbetween_step_Lo_not_Eq : forall x l, inbetween start (start + step) x l -> l <> loc_Exact -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Lt).
Lemma middle_odd : forall k, (2 * k + 1 = nb_steps)%Z -> (((start + Z2R k * step) + (start + Z2R (k + 1) * step))/2 = start + Z2R nb_steps /2 * step)%R.
Theorem inbetween_step_any_Mi_odd : forall x k l, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x (loc_Inexact l) -> (2 * k + 1 = nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact l).
Theorem inbetween_step_Lo_Mi_Eq_odd : forall x k, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x loc_Exact -> (2 * k + 1 = nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Lt).
Theorem inbetween_step_Hi_Mi_even : forall x k l, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x l -> l <> loc_Exact -> (2 * k = nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Gt).
Theorem inbetween_step_Mi_Mi_even : forall x k, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x loc_Exact -> (2 * k = nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Eq).
Theorem inbetween_spec : (d <= x < u)%R -> inbetween inbetween_loc.
Theorem inbetween_unique : forall l l', inbetween l -> inbetween l' -> l = l'.
Theorem inbetween_bounds : inbetween l -> (d <= x < u)%R.
Theorem inbetween_bounds_not_Eq : inbetween l -> l <> loc_Exact -> (d < x < u)%R.
Theorem inbetween_distance_inexact : forall l, inbetween (loc_Inexact l) -> Rcompare (x - d) (u - x) = l.
Theorem inbetween_distance_inexact_abs : forall l, inbetween (loc_Inexact l) -> Rcompare (Rabs (d - x)) (Rabs (u - x)) = l.
Theorem inbetween_ex : forall d u l, (d < u)%R -> exists x, inbetween d u x l.
Lemma ordered_steps : forall k, (start + Z2R k * step < start + Z2R (k + 1) * step)%R.
Lemma middle_range : forall k, ((start + (start + Z2R k * step)) / 2 = start + (Z2R k / 2 * step))%R.
Lemma inbetween_step_not_Eq : forall x k l l', inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x l -> (0 < k < nb_steps)%Z -> Rcompare x (start + (Z2R nb_steps / 2 * step))%R = l' -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact l').
Theorem inbetween_step_Lo : forall x k l, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x l -> (0 < k)%Z -> (2 * k + 1 < nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Lt).
Theorem inbetween_step_Hi : forall x k l, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x l -> (nb_steps < 2 * k)%Z -> (k < nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Gt).
Theorem inbetween_step_Lo_not_Eq : forall x l, inbetween start (start + step) x l -> l <> loc_Exact -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Lt).
Lemma middle_odd : forall k, (2 * k + 1 = nb_steps)%Z -> (((start + Z2R k * step) + (start + Z2R (k + 1) * step))/2 = start + Z2R nb_steps /2 * step)%R.
Theorem inbetween_step_any_Mi_odd : forall x k l, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x (loc_Inexact l) -> (2 * k + 1 = nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact l).
Theorem inbetween_step_Lo_Mi_Eq_odd : forall x k, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x loc_Exact -> (2 * k + 1 = nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Lt).
Theorem inbetween_step_Hi_Mi_even : forall x k l, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x l -> l <> loc_Exact -> (2 * k = nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Gt).
Theorem inbetween_step_Mi_Mi_even : forall x k, inbetween (start + Z2R k * step) (start + Z2R (k + 1) * step) x loc_Exact -> (2 * k = nb_steps)%Z -> inbetween start (start + Z2R nb_steps * step) x (loc_Inexact Eq).