Require Export Reals.
Definition sup := completeness.
Open Scope R_scope.
Definition is_lower_bound (E:R->Prop) (m:R) :=
forall x:R, E x -> x >= m.
Definition lower_bound (E:R->Prop) :=
exists m:R, is_lower_bound E m.
Definition is_glb (E:R->Prop) (m:R) :=
is_lower_bound E m /\ (forall b:R, is_lower_bound E b -> b <= m).
Definition inf: forall E:R->Prop, lower_bound E -> (exists x:R, E x) ->
{ m:R | is_glb E m }.
unshelve refine (fun E Hlb Hinh =>
let H:=_ in let H0:=_ in
exist _ (- (proj1_sig (sup (Im E Ropp) H H0))) _).
destruct Hlb as [m].
exists (-m).
red; intros.
destruct H0.
rewrite H1.
auto with real.
destruct Hinh as [x].
exists (-x).
exists x; trivial.
destruct sup as [m].
simpl.
split.
red; intros.
cut (-x <= m).
intros.
replace x with (--x) by ring.
auto with real.
apply i.
exists x; trivial.
intros.
cut (m <= -b).
intros.
replace b with (--b) by ring.
auto with real.
apply i.
red; intros.
cut (-x >= b).
intros.
replace x with (--x) by ring.
auto with real.
apply H1.
destruct H2.
rewrite H3.
replace (--x) with x by ring; trivial.
Qed.

Lemma lub_approx: forall (S:Ensemble R) (m:R) (eps:R),
is_lub S m -> eps > 0 -> exists x:R, In S x /\
m - eps < x <= m.