(************************************************************************)
(*         *      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.

(* Specifications: *)
(** Division *)
Theorem derivable_pt_lim_div :
forall (f1 f2:R -> R) (x l1 l2:R),
derivable_pt_lim f1 x l1 ->
derivable_pt_lim f2 x l2 ->
f2 x <> 0 ->
derivable_pt_lim (f1 / f2) x ((l1 * f2 x - l2 * f1 x) / Rsqr (f2 x)).
Lemma derivable_pt_div :
forall (f1 f2:R -> R) (x:R),
derivable_pt f1 x ->
derivable_pt f2 x -> f2 x <> 0 -> derivable_pt (f1 / f2) x.
Lemma derivable_div :
forall f1 f2:R -> R,
derivable f1 ->
derivable f2 -> (forall x:R, f2 x <> 0) -> derivable (f1 / f2).
Lemma derive_pt_div :
forall (f1 f2:R -> R) (x:R) (pr1:derivable_pt f1 x)
(pr2:derivable_pt f2 x) (na:f2 x <> 0),
derive_pt (f1 / f2) x (derivable_pt_div _ _ _ pr1 pr2 na) =
(derive_pt f1 x pr1 * f2 x - derive_pt f2 x pr2 * f1 x) / Rsqr (f2 x).
(**********)
Lemma derivable_pt_inv :
forall (f:R -> R) (x:R),
f x <> 0 -> derivable_pt f x -> derivable_pt (/ f) x.
(**********)
Lemma pr_nu_var :
forall (f g:R -> R) (x:R) (pr1:derivable_pt f x) (pr2:derivable_pt g x),
f = g -> derive_pt f x pr1 = derive_pt g x pr2.
(**********)
Lemma pr_nu_var2 :
forall (f g:R -> R) (x:R) (pr1:derivable_pt f x) (pr2:derivable_pt g x),
(forall h:R, f h = g h) -> derive_pt f x pr1 = derive_pt g x pr2.
(**********)
Lemma derivable_inv :
forall f:R -> R, (forall x:R, f x <> 0) -> derivable f -> derivable (/ f).
Lemma derive_pt_inv :
forall (f:R -> R) (x:R) (pr:derivable_pt f x) (na:f x <> 0),
derive_pt (/ f) x (derivable_pt_inv f x na pr) =
- derive_pt f x pr / Rsqr (f x).
(** Rabsolu *)
Lemma Rabs_derive_1 : forall x:R, 0 < x -> derivable_pt_lim Rabs x 1.
Lemma Rabs_derive_2 : forall x:R, x < 0 -> derivable_pt_lim Rabs x (-1).
(** Rabsolu is derivable for all x <> 0 *)
Lemma Rderivable_pt_abs : forall x:R, x <> 0 -> derivable_pt Rabs x.
(** Rabsolu is continuous for all x *)
Lemma Rcontinuity_abs : continuity Rabs.
(** Finite sums : Sum a_k x^k *)
Lemma continuity_finite_sum :
forall (An:nat -> R) (N:nat),
continuity (fun y:R => sum_f_R0 (fun k:nat => An k * y ^ k) N).
Lemma derivable_pt_lim_fs :
forall (An:nat -> R) (x:R) (N:nat),
(0 < N)%nat ->
derivable_pt_lim (fun y:R => sum_f_R0 (fun k:nat => An k * y ^ k) N) x
(sum_f_R0 (fun k:nat => INR (S k) * An (S k) * x ^ k) (pred N)).
Lemma derivable_pt_lim_finite_sum :
forall (An:nat -> R) (x:R) (N:nat),
derivable_pt_lim (fun y:R => sum_f_R0 (fun k:nat => An k * y ^ k) N) x
match N with
| O => 0
| _ => sum_f_R0 (fun k:nat => INR (S k) * An (S k) * x ^ k) (pred N)
end.
Lemma derivable_pt_finite_sum :
forall (An:nat -> R) (N:nat) (x:R),
derivable_pt (fun y:R => sum_f_R0 (fun k:nat => An k * y ^ k) N) x.
Lemma derivable_finite_sum :
forall (An:nat -> R) (N:nat),
derivable (fun y:R => sum_f_R0 (fun k:nat => An k * y ^ k) N).
(** Regularity of hyperbolic functions *)
Lemma derivable_pt_lim_cosh : forall x:R, derivable_pt_lim cosh x (sinh x).
Lemma derivable_pt_lim_sinh : forall x:R, derivable_pt_lim sinh x (cosh x).
Lemma derivable_pt_exp : forall x:R, derivable_pt exp x.
Lemma derivable_pt_cosh : forall x:R, derivable_pt cosh x.
Lemma derivable_pt_sinh : forall x:R, derivable_pt sinh x.
Lemma derivable_exp : derivable exp.
Lemma derivable_cosh : derivable cosh.
Lemma derivable_sinh : derivable sinh.
Lemma derive_pt_exp :
forall x:R, derive_pt exp x (derivable_pt_exp x) = exp x.
Lemma derive_pt_cosh :
forall x:R, derive_pt cosh x (derivable_pt_cosh x) = sinh x.
Lemma derive_pt_sinh :
forall x:R, derive_pt sinh x (derivable_pt_sinh x) = cosh x.
Lemma sinh_lt : forall x y, x < y -> sinh x < sinh y.
intros x y xy; destruct (MVT_cor2 sinh cosh x y xy) as [c [Pc _]].
Lemma Rlt_R0_R2 : 0 < 2.
Notation Rplus_lt_pos := Rplus_lt_0_compat (only parsing).
Lemma IZR_eq : forall z1 z2:Z, z1 = z2 -> IZR z1 = IZR z2.
Ltac discrR :=
try
match goal with
|  |- (?X1 <> ?X2) =>
repeat
rewrite <- plus_IZR ||
rewrite <- mult_IZR ||
rewrite <- Ropp_Ropp_IZR || rewrite Z_R_minus;
apply eq_IZR_contrapositive; try discriminate
end.
(**********)
Lemma sqrt_var_maj :
forall h:R, Rabs h <= 1 -> Rabs (sqrt (1 + h) - 1) <= Rabs h.
(** sqrt is continuous in 1 *)
Lemma sqrt_continuity_pt_R1 : continuity_pt sqrt 1.
(** sqrt is continuous forall x>0 *)
Lemma sqrt_continuity_pt : forall x:R, 0 < x -> continuity_pt sqrt x.
(** sqrt is derivable for all x>0 *)
Lemma derivable_pt_lim_sqrt :
forall x:R, 0 < x -> derivable_pt_lim sqrt x (/ (2 * sqrt x)).
(**********)
Lemma derivable_pt_sqrt : forall x:R, 0 < x -> derivable_pt sqrt x.
(**********)
Lemma derive_pt_sqrt :
forall (x:R) (pr:0 < x),
derive_pt sqrt x (derivable_pt_sqrt _ pr) = / (2 * sqrt x).
(** We show that sqrt is continuous for all x>=0 *)
(** Remark : by definition of sqrt (as extension of Rsqrt on |R), we could also show that sqrt is continuous for all x *)
Lemma continuity_pt_sqrt : forall x:R, 0 <= x -> continuity_pt sqrt x.
Lemma tech1 :
forall (An:nat -> R) (N:nat),
(forall n:nat, (n <= N)%nat -> 0 < An n) -> 0 < sum_f_R0 An N.
(* Chasles' relation *)
Lemma tech2 :
forall (An:nat -> R) (m n:nat),
(m < n)%nat ->
sum_f_R0 An n =
sum_f_R0 An m + sum_f_R0 (fun i:nat => An (S m + i)%nat) (n - S m).
(* Sum of geometric sequences *)
Lemma tech3 :
forall (k:R) (N:nat),
k <> 1 -> sum_f_R0 (fun i:nat => k ^ i) N = (1 - k ^ S N) / (1 - k).
Lemma tech4 :
forall (An:nat -> R) (k:R) (N:nat),
0 <= k -> (forall i:nat, An (S i) < k * An i) -> An N <= An 0%nat * k ^ N.
Lemma tech5 :
forall (An:nat -> R) (N:nat), sum_f_R0 An (S N) = sum_f_R0 An N + An (S N).
Lemma tech6 :
forall (An:nat -> R) (k:R) (N:nat),
0 <= k ->
(forall i:nat, An (S i) < k * An i) ->
sum_f_R0 An N <= An 0%nat * sum_f_R0 (fun i:nat => k ^ i) N.
Lemma tech7 : forall r1 r2:R, r1 <> 0 -> r2 <> 0 -> r1 <> r2 -> / r1 <> / r2.
Lemma tech11 :
forall (An Bn Cn:nat -> R) (N:nat),
(forall i:nat, An i = Bn i - Cn i) ->
sum_f_R0 An N = sum_f_R0 Bn N - sum_f_R0 Cn N.
Lemma tech12 :
forall (An:nat -> R) (x l:R),
Un_cv (fun N:nat => sum_f_R0 (fun i:nat => An i * x ^ i) N) l ->
Pser An x l.
Lemma scal_sum :
forall (An:nat -> R) (N:nat) (x:R),
x * sum_f_R0 An N = sum_f_R0 (fun i:nat => An i * x) N.
Lemma decomp_sum :
forall (An:nat -> R) (N:nat),
(0 < N)%nat ->
sum_f_R0 An N = An 0%nat + sum_f_R0 (fun i:nat => An (S i)) (pred N).
Lemma plus_sum :
forall (An Bn:nat -> R) (N:nat),
sum_f_R0 (fun i:nat => An i + Bn i) N = sum_f_R0 An N + sum_f_R0 Bn N.
Lemma sum_eq :
forall (An Bn:nat -> R) (N:nat),
(forall i:nat, (i <= N)%nat -> An i = Bn i) ->
sum_f_R0 An N = sum_f_R0 Bn N.
(* Unicity of the limit defined by convergent series *)
Lemma uniqueness_sum :
forall (An:nat -> R) (l1 l2:R),
infinite_sum An l1 -> infinite_sum An l2 -> l1 = l2.
Lemma minus_sum :
forall (An Bn:nat -> R) (N:nat),
sum_f_R0 (fun i:nat => An i - Bn i) N = sum_f_R0 An N - sum_f_R0 Bn N.
Lemma sum_decomposition :
forall (An:nat -> R) (N:nat),
sum_f_R0 (fun l:nat => An (2 * l)%nat) (S N) +
sum_f_R0 (fun l:nat => An (S (2 * l))) N = sum_f_R0 An (2 * S N).
Lemma sum_Rle :
forall (An Bn:nat -> R) (N:nat),
(forall n:nat, (n <= N)%nat -> An n <= Bn n) ->
sum_f_R0 An N <= sum_f_R0 Bn N.
Lemma Rsum_abs :
forall (An:nat -> R) (N:nat),
Rabs (sum_f_R0 An N) <= sum_f_R0 (fun l:nat => Rabs (An l)) N.
Lemma sum_cte :
forall (x:R) (N:nat), sum_f_R0 (fun _:nat => x) N = x * INR (S N).
(**********)
Lemma sum_growing :
forall (An Bn:nat -> R) (N:nat),
(forall n:nat, An n <= Bn n) -> sum_f_R0 An N <= sum_f_R0 Bn N.
(**********)
Lemma Rabs_triang_gen :
forall (An:nat -> R) (N:nat),
Rabs (sum_f_R0 An N) <= sum_f_R0 (fun i:nat => Rabs (An i)) N.
(**********)
Lemma cond_pos_sum :
forall (An:nat -> R) (N:nat),
(forall n:nat, 0 <= An n) -> 0 <= sum_f_R0 An N.
Lemma tan_PI : tan PI = 0.
Lemma sin_3PI2 : sin (3 * (PI / 2)) = -1.
Lemma tan_2PI : tan (2 * PI) = 0.
Lemma sin_cos_PI4 : sin (PI / 4) = cos (PI / 4).
Lemma sin_PI3_cos_PI6 : sin (PI / 3) = cos (PI / 6).
Lemma sin_PI6_cos_PI3 : cos (PI / 3) = sin (PI / 6).
Lemma PI6_RGT_0 : 0 < PI / 6.
Lemma PI6_RLT_PI2 : PI / 6 < PI / 2.
Lemma sin_PI6 : sin (PI / 6) = 1 / 2.
Lemma sqrt2_neq_0 : sqrt 2 <> 0.
Lemma R1_sqrt2_neq_0 : 1 / sqrt 2 <> 0.
Lemma sqrt3_2_neq_0 : 2 * sqrt 3 <> 0.
Lemma Rlt_sqrt2_0 : 0 < sqrt 2.
Lemma Rlt_sqrt3_0 : 0 < sqrt 3.
Lemma PI4_RGT_0 : 0 < PI / 4.
Lemma cos_PI4 : cos (PI / 4) = 1 / sqrt 2.
Proof with trivial.
(**********)
Lemma sum_N_predN :
forall (An:nat -> R) (N:nat),
(0 < N)%nat -> sum_f_R0 An N = sum_f_R0 An (pred N) + An N.
(**********)
Lemma sum_plus :
forall (An Bn:nat -> R) (N:nat),
sum_f_R0 (fun l:nat => An l + Bn l) N = sum_f_R0 An N + sum_f_R0 Bn N.
(* The main result *)
Theorem cauchy_finite :
forall (An Bn:nat -> R) (N:nat),
(0 < N)%nat ->
sum_f_R0 An N * sum_f_R0 Bn N =
sum_f_R0 (fun k:nat => sum_f_R0 (fun p:nat => An p * Bn (k - p)%nat) k) N +
sum_f_R0
(fun k:nat =>
sum_f_R0 (fun l:nat => An (S (l + k)) * Bn (N - l)%nat)
(pred (N - k))) (pred N).
(* The Mean Value Theorem *)
Theorem MVT :
forall (f g:R -> R) (a b:R) (pr1:forall c:R, a < c < b -> derivable_pt f c)
(pr2:forall c:R, a < c < b -> derivable_pt g c),
a < b ->
(forall c:R, a <= c <= b -> continuity_pt f c) ->
(forall c:R, a <= c <= b -> continuity_pt g c) ->
exists c : R,
(exists P : a < c < b,
(g b - g a) * derive_pt f c (pr1 c P) =
(f b - f a) * derive_pt g c (pr2 c P)).
(* Corollaries ... *)
Lemma MVT_cor1 :
forall (f:R -> R) (a b:R) (pr:derivable f),
a < b ->
exists c : R, f b - f a = derive_pt f c (pr c) * (b - a) /\ a < c < b.
Theorem MVT_cor2 :
forall (f f':R -> R) (a b:R),
a < b ->
(forall c:R, a <= c <= b -> derivable_pt_lim f c (f' c)) ->
exists c : R, f b - f a = f' c * (b - a) /\ a < c < b.
Lemma MVT_cor3 :
forall (f f':R -> R) (a b:R),
a < b ->
(forall x:R, a <= x -> x <= b -> derivable_pt_lim f x (f' x)) ->
exists c : R, a <= c /\ c <= b /\ f b = f a + f' c * (b - a).
Lemma Rolle :
forall (f:R -> R) (a b:R) (pr:forall x:R, a < x < b -> derivable_pt f x),
(forall x:R, a <= x <= b -> continuity_pt f x) ->
a < b ->
f a = f b ->
exists c : R, (exists P : a < c < b, derive_pt f c (pr c P) = 0).
(**********)
Lemma nonneg_derivative_1 :
forall (f:R -> R) (pr:derivable f),
(forall x:R, 0 <= derive_pt f x (pr x)) -> increasing f.
(**********)
Lemma nonpos_derivative_0 :
forall (f:R -> R) (pr:derivable f),
decreasing f -> forall x:R, derive_pt f x (pr x) <= 0.
(**********)
Lemma increasing_decreasing_opp :
forall f:R -> R, increasing f -> decreasing (- f)%F.
(**********)
Lemma nonpos_derivative_1 :
forall (f:R -> R) (pr:derivable f),
(forall x:R, derive_pt f x (pr x) <= 0) -> decreasing f.
(**********)
Lemma positive_derivative :
forall (f:R -> R) (pr:derivable f),
(forall x:R, 0 < derive_pt f x (pr x)) -> strict_increasing f.
(**********)
Lemma strictincreasing_strictdecreasing_opp :
forall f:R -> R, strict_increasing f -> strict_decreasing (- f)%F.
(**********)
Lemma negative_derivative :
forall (f:R -> R) (pr:derivable f),
(forall x:R, derive_pt f x (pr x) < 0) -> strict_decreasing f.
(**********)
Lemma null_derivative_0 :
forall (f:R -> R) (pr:derivable f),
constant f -> forall x:R, derive_pt f x (pr x) = 0.
(**********)
Lemma increasing_decreasing :
forall f:R -> R, increasing f -> decreasing f -> constant f.
(**********)
Lemma null_derivative_1 :
forall (f:R -> R) (pr:derivable f),
(forall x:R, derive_pt f x (pr x) = 0) -> constant f.
(**********)
Lemma derive_increasing_interv_ax :
forall (a b:R) (f:R -> R) (pr:derivable f),
a < b ->
((forall t:R, a < t < b -> 0 < derive_pt f t (pr t)) ->
forall x y:R, a <= x <= b -> a <= y <= b -> x < y -> f x < f y) /\
((forall t:R, a < t < b -> 0 <= derive_pt f t (pr t)) ->
forall x y:R, a <= x <= b -> a <= y <= b -> x < y -> f x <= f y).
(**********)
Lemma derive_increasing_interv :
forall (a b:R) (f:R -> R) (pr:derivable f),
a < b ->
(forall t:R, a < t < b -> 0 < derive_pt f t (pr t)) ->
forall x y:R, a <= x <= b -> a <= y <= b -> x < y -> f x < f y.
(**********)
Lemma derive_increasing_interv_var :
forall (a b:R) (f:R -> R) (pr:derivable f),
a < b ->
(forall t:R, a < t < b -> 0 <= derive_pt f t (pr t)) ->
forall x y:R, a <= x <= b -> a <= y <= b -> x < y -> f x <= f y.
(**********)
(**********)
Theorem IAF :
forall (f:R -> R) (a b k:R) (pr:derivable f),
a <= b ->
(forall c:R, a <= c <= b -> derive_pt f c (pr c) <= k) ->
f b - f a <= k * (b - a).
Lemma IAF_var :
forall (f g:R -> R) (a b:R) (pr1:derivable f) (pr2:derivable g),
a <= b ->
(forall c:R, a <= c <= b -> derive_pt g c (pr2 c) <= derive_pt f c (pr1 c)) ->
g b - g a <= f b - f a.
(* If f has a null derivative in ]a,b[ and is continue in [a,b], *)
(* then f is constant on [a,b] *)
Lemma null_derivative_loc :
forall (f:R -> R) (a b:R) (pr:forall x:R, a < x < b -> derivable_pt f x),
(forall x:R, a <= x <= b -> continuity_pt f x) ->
(forall (x:R) (P:a < x < b), derive_pt f x (pr x P) = 0) ->
constant_D_eq f (fun x:R => a <= x <= b) (f a).
(* Unicity of the antiderivative *)
Lemma antiderivative_Ucte :
forall (f g1 g2:R -> R) (a b:R),
antiderivative f g1 a b ->
antiderivative f g2 a b ->
exists c : R, (forall x:R, a <= x <= b -> g1 x = g2 x + c).
(* A variant of MVT using absolute values. *)
Lemma MVT_abs :
forall (f f' : R -> R) (a b : R),
(forall c : R, Rmin a b <= c <= Rmax a b ->
derivable_pt_lim f c (f' c)) ->
exists c : R, Rabs (f b - f a) = Rabs (f' c) * Rabs (b - a) /\
Rmin a b <= c <= Rmax a b.
(**********)
Lemma formule :
forall (x h l1 l2:R) (f1 f2:R -> R),
h <> 0 ->
f2 x <> 0 ->
f2 (x + h) <> 0 ->
(f1 (x + h) / f2 (x + h) - f1 x / f2 x) / h -
(l1 * f2 x - l2 * f1 x) / Rsqr (f2 x) =
/ f2 (x + h) * ((f1 (x + h) - f1 x) / h - l1) +
l1 / (f2 x * f2 (x + h)) * (f2 x - f2 (x + h)) -
f1 x / (f2 x * f2 (x + h)) * ((f2 (x + h) - f2 x) / h - l2) +
l2 * f1 x / (Rsqr (f2 x) * f2 (x + h)) * (f2 (x + h) - f2 x).