(************************************************************************)
(*         *      The Rocq Prover / The Rocq Development Team           *)
(*  v      *         Copyright INRIA, CNRS and contributors             *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
Local Open Scope R_scope.
Fixpoint Dichotomy_lb (x y:R) (P:R -> bool) (N:nat) {struct N} : R :=
match N with
| O => x
| S n =>
let down := Dichotomy_lb x y P n in
let up := Dichotomy_ub x y P n in
let z := (down + up) / 2 in if P z then down else z
end
with Dichotomy_ub (x y:R) (P:R -> bool) (N:nat) {struct N} : R :=
match N with
| O => y
| S n =>
let down := Dichotomy_lb x y P n in
let up := Dichotomy_ub x y P n in
let z := (down + up) / 2 in if P z then z else up
end.
Definition dicho_lb (x y:R) (P:R -> bool) (N:nat) : R := Dichotomy_lb x y P N.
Definition dicho_up (x y:R) (P:R -> bool) (N:nat) : R := Dichotomy_ub x y P N.

(* Specifications: *)
(**********)
Lemma dicho_comp :
forall (x y:R) (P:R -> bool) (n:nat),
x <= y -> dicho_lb x y P n <= dicho_up x y P n.
Lemma dicho_lb_growing :
forall (x y:R) (P:R -> bool), x <= y -> Un_growing (dicho_lb x y P).
Lemma dicho_up_decreasing :
forall (x y:R) (P:R -> bool), x <= y -> Un_decreasing (dicho_up x y P).
Lemma dicho_lb_maj_y :
forall (x y:R) (P:R -> bool), x <= y -> forall n:nat, dicho_lb x y P n <= y.
Lemma dicho_lb_maj :
forall (x y:R) (P:R -> bool), x <= y -> has_ub (dicho_lb x y P).
Lemma dicho_up_min_x :
forall (x y:R) (P:R -> bool), x <= y -> forall n:nat, x <= dicho_up x y P n.
Lemma dicho_up_min :
forall (x y:R) (P:R -> bool), x <= y -> has_lb (dicho_up x y P).
Lemma dicho_lb_cv :
forall (x y:R) (P:R -> bool),
x <= y -> { l:R | Un_cv (dicho_lb x y P) l }.
Lemma dicho_up_cv :
forall (x y:R) (P:R -> bool),
x <= y -> { l:R | Un_cv (dicho_up x y P) l }.
Lemma dicho_lb_dicho_up :
forall (x y:R) (P:R -> bool) (n:nat),
x <= y -> dicho_up x y P n - dicho_lb x y P n = (y - x) / 2 ^ n.