(** This file is part of the Coquelicot formalization of real analysis in Coq: http://coquelicot.saclay.inria.fr/  Copyright (C) 2011-2015 Sylvie Boldo #<br /># Copyright (C) 2011-2015 Catherine Lelay #<br /># Copyright (C) 2011-2015 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. *)
(** This file contains the definition and properties of the set [R] # &#8746; {+ &infin;} &#8746; {- &infin;} # denoted by [Rbar]. We have defined: - coercions from [R] to [Rbar] and vice versa ([Finite] gives [R0] at infinity points) - an order [Rbar_lt] and [Rbar_le] - total operations: [Rbar_opp], [Rbar_plus], [Rbar_minus], [Rbar_inv], [Rbar_min] and [Rbar_abs] - lemmas about the decidability of the order and properties of the operations (such as [Rbar_plus_comm] or [Rbar_plus_lt_compat]) *)
Open Scope R_scope.
(** * Definitions *)
Inductive Rbar :=
| Finite : R -> Rbar
| p_infty : Rbar
| m_infty : Rbar.
Definition real (x : Rbar) :=
match x with
| Finite x => x
| _ => 0
end.
Coercion Finite : R >-> Rbar.
Coercion real : Rbar >-> R.
Definition is_finite (x : Rbar) := Finite (real x) = x.
(** ** Order *)
Definition Rbar_lt (x y : Rbar) : Prop :=
match x,y with
| p_infty, _ | _, m_infty => False
| m_infty, _ | _, p_infty => True
| Finite x, Finite y => Rlt x y
end.
Definition Rbar_le (x y : Rbar) : Prop :=
match x,y with
| m_infty, _ | _, p_infty => True
| p_infty, _ | _, m_infty => False
| Finite x, Finite y => Rle x y
end.
(** ** Operations *)
(** *** Additive operators *)
Definition Rbar_opp (x : Rbar) :=
match x with
| Finite x => Finite (-x)
| p_infty => m_infty
| m_infty => p_infty
end.
Definition Rbar_plus' (x y : Rbar) :=
match x,y with
| p_infty, m_infty | m_infty, p_infty => None
| p_infty, _ | _, p_infty => Some p_infty
| m_infty, _ | _, m_infty => Some m_infty
| Finite x', Finite y' => Some (Finite (x' + y'))
end.
Definition Rbar_plus (x y : Rbar) :=
match Rbar_plus' x y with Some z => z | None => Finite 0 end.
Arguments Rbar_plus !x !y /.
Definition is_Rbar_plus (x y z : Rbar) : Prop :=
Rbar_plus' x y = Some z.
Definition ex_Rbar_plus (x y : Rbar) : Prop :=
match Rbar_plus' x y with Some _ => True | None => False end.
Arguments ex_Rbar_plus !x !y /.

Lemma is_Rbar_plus_unique (x y z : Rbar) :
is_Rbar_plus x y z -> Rbar_plus x y = z.