(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \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.
(** Tools *)
Definition pos_half_prf : 0 < /2.
(* The following lemmas are general purpose lemmas about squares. They do not belong here *)
(** * Properties of tangent *)
(** Proof that tangent is a bijection *)
(* to be removed? *)
(* end hide *)
(* The following lemmas about PI should probably be in Rtrigo. *)
Definition frame_tan y : {x | 0 < x < PI/2 /\ Rabs y < tan x}.
Definition pre_atan (y : R) : {x : R | -PI/2 < x < PI/2 /\ tan x = y}.
Definition atan x := let (v, _) := pre_atan x in v.
(** atan's derivative value is the function 1 / (1+x²) *)
(** * Definition of the arctangent function as the sum of the arctan power series *)
(* Proof taken from Guillaume Melquiond's interval package for Coq *)
Definition Ratan_seq x :=  fun n => (x ^ (2 * n + 1) / INR (2 * n + 1))%R.
Definition ps_atan_exists_01 (x : R) (Hx:0 <= x <= 1) :
{l : R | Un_cv (fun N : nat => sum_f_R0 (tg_alt (Ratan_seq x)) N) l}.
Definition ps_atan_exists_1 (x : R) (Hx : -1 <= x <= 1) :
{l : R | Un_cv (fun N : nat => sum_f_R0 (tg_alt (Ratan_seq x)) N) l}.
Definition in_int (x : R) : {-1 <= x <= 1}+{~ -1 <= x <= 1}.
Definition ps_atan (x : R) : R :=
match in_int x with
left h => let (v, _) := ps_atan_exists_1 x h in v
| right h => atan x
end.
(** * Proof of the equivalence of the two definitions between -1 and 1 *)
(** atan = ps_atan *)
(** Definition of ps_atan's derivative *)
Definition Datan_seq := fun (x:R) (n:nat) => x ^ (2*n).

Lemma Datan_seq_CV_0 : forall x, -1 < x -> x < 1 -> Un_cv (Datan_seq x) 0.