(**
This file is part of the Coquelicot formalization of real
analysis in Coq: http://coquelicot.saclay.inria.fr/

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Copyright (C) 2011-2015 Sylvie Boldo
#<br />#
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Copyright (C) 2011-2015 Catherine Lelay
#<br />#
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
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.
*)

Require Import Reals Psatz.
Require Import mathcomp.ssreflect.ssreflect.
Require Import Rcomplements Rbar Lim_seq Iter.
Require Import Hierarchy Continuity Equiv.
Open Scope R_scope.

(** This file describes results about differentiability on a generic
normed module. Specific results are also given on [R] with a total
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
function [Derive]. It ends with the Taylor-Lagrange formula. *)

Section LinearFct.

(** * Linear functions *)

Context {K : AbsRing} {U V : NormedModule K}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Record is_linear (l : U -> V) := {
  linear_plus : forall (x y : U), l (plus x y) = plus (l x) (l y) ;
  linear_scal : forall (k : K) (x : U), l (scal k x) = scal k (l x) ;
  linear_norm : exists M : R, 0 < M /\ (forall x : U, norm (l x) <= M * norm x) }.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma linear_zero (l : U -> V) : is_linear l ->
  l zero = zero.
Proof.
(* Goal: forall _ : is_linear l, @eq (NormedModule.sort K V) (l (@opp (NormedModule.AbelianGroup K U) x)) (@opp (NormedModule.AbelianGroup K V) (l x)) *)
  intros Hl.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite -(scal_zero_l zero).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite linear_scal.
(* Goal: @eq (NormedModule.sort K V) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (@zero (Ring.AbelianGroup (AbsRing.Ring K))) (l (@zero (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K U))))) (@zero (NormedModule.AbelianGroup K V)) *)
(* Goal: is_linear l *)
  exact (scal_zero_l (l zero)).
(* Goal: @is_linear K U V l *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K U)) (_ : @is_filter_lim (NormedModule.UniformSpace K U) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K U)) K K U V F (fun y : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K U) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K U) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f x)) (l (@minus (NormedModule.AbelianGroup K U) y x))) *)
  exact Hl.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma linear_opp (l : U -> V) (x : U) : is_linear l ->
  l (opp x) = opp (l x).
Proof.
(* Goal: forall _ : is_linear l, @eq (NormedModule.sort K V) (l (@opp (NormedModule.AbelianGroup K U) x)) (@opp (NormedModule.AbelianGroup K V) (l x)) *)
  intros Hl.
(* Goal: @eq (NormedModule.sort K V) (l (@opp (NormedModule.AbelianGroup K U) x)) (@opp (NormedModule.AbelianGroup K V) (l x)) *)
  apply plus_reg_r with (l x).
(* Goal: @eq (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@plus (NormedModule.AbelianGroup K V) (l (@opp (NormedModule.AbelianGroup K U) x)) (l x)) (@plus (NormedModule.AbelianGroup K V) (@opp (NormedModule.AbelianGroup K V) (l x)) (l x)) *)
  rewrite <- linear_plus, !plus_opp_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply linear_zero.
(* Goal: @is_linear K U V l *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K U)) (_ : @is_filter_lim (NormedModule.UniformSpace K U) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K U)) K K U V F (fun y : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K U) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K U) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f x)) (l (@minus (NormedModule.AbelianGroup K U) y x))) *)
  exact Hl.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma linear_cont (l : U -> V) (x : U) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_linear l -> continuous l x.
Proof.
(* Goal: forall _ : is_linear l, @eq (NormedModule.sort K V) (l (@opp (NormedModule.AbelianGroup K U) x)) (@opp (NormedModule.AbelianGroup K V) (l x)) *)
  intros Hl.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filterlim_locally_ball_norm => eps.
  apply locally_le_locally_norm.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (linear_norm _ Hl) => M Hn.
  assert (0 < eps / M).
(* Goal: Rlt (IZR Z0) (Rdiv (pos r) (Rabs a)) *)
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rmult (pow a n) (Derive_n f n (Rmult a t))) (Derive_n (fun y : R => f (Rmult a y)) n t)) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rdiv_lt_0_compat.
    apply cond_pos.
    apply Hn.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  exists (mkposreal _ H) => y Hy.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /ball_norm /minus -linear_opp // -linear_plus //.
  eapply Rle_lt_trans.
  by apply Hn.
  evar_last.
  apply Rmult_lt_compat_l with (2 := Hy).
  apply Hn.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
  simpl.
  field.
  apply Rgt_not_eq, Hn.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_linear_ext (l1 l2 : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall x, l1 x = l2 x) -> is_linear l1 -> is_linear l2.
Proof.
(* Goal: forall (_ : forall x : NormedModule.sort K U, @eq (NormedModule.sort K V) (l1 x) (l2 x)) (_ : is_linear l1), is_linear l2 *)
  intros Hl Hl1.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: forall x : NormedModule.sort K U, Rle (@norm K V (l2 x)) (Rmult M (@norm K U x)) *)
  intros ; rewrite -!Hl ; apply Hl1.
(* Goal: forall x : NormedModule.sort K U, Rle (@norm K V (l2 x)) (Rmult M (@norm K U x)) *)
  intros ; rewrite -!Hl ; apply Hl1.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Hl1 => _ _ [M Hl1].
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  exists M ; split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Hl1.
(* Goal: forall x : NormedModule.sort K U, Rle (@norm K V (l2 x)) (Rmult M (@norm K U x)) *)
  intros ; rewrite -!Hl ; apply Hl1.
Qed.

(** zero in a linear function *)
Lemma is_linear_zero : is_linear (fun _ => zero).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  repeat split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => _ _ ; by rewrite plus_zero_l.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => k _ ; by rewrite scal_zero_r.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  - exists 1 ; split.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
(* Goal: forall t : AbsRing.sort R_AbsRing, @eq (NormedModule.sort R_AbsRing R_NormedModule) (Derive_n (Derive f) n t) (Derive (Derive_n f n) t) *)
    move => x ; rewrite Rmult_1_l norm_zero.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
    apply norm_ge_0.
Qed.

End LinearFct.

Lemma is_linear_comp {K : AbsRing} {U V W : NormedModule K}
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (l1 : U -> V) (l2 : V -> W) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_linear l1 -> is_linear l2 -> is_linear (fun x => l2 (l1 x)).
Proof.
  intros Hl1 Hl2.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => x y.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by rewrite !linear_plus.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => k x.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by rewrite !linear_scal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - destruct (linear_norm _ Hl1) as [M1 Hn1].
    destruct (linear_norm _ Hl2) as [M2 Hn2].
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
    exists (M2 * M1) ; split.
    now apply Rmult_lt_0_compat.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
    move => x.
    eapply Rle_trans.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Hn2.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rmult_assoc.
    apply Rmult_le_compat_l.
    now apply Rlt_le.
    apply Hn1.
Qed.

Section Op_LinearFct.

Context {K : AbsRing} {V : NormedModule K}.

(** id is a linear function *)
Lemma is_linear_id : is_linear (fun (x : V) => x).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  repeat split.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  - exists 1 ; split.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
(* Goal: forall t : AbsRing.sort R_AbsRing, @eq (NormedModule.sort R_AbsRing R_NormedModule) (Derive_n (Derive f) n t) (Derive (Derive_n f n) t) *)
    move => x ; rewrite Rmult_1_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rle_refl.
Qed.

(** opp is a linear function *)
Lemma is_linear_opp : is_linear (@opp V).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  repeat split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => x y.
(* Goal: @eq (NormedModule.sort K V) (@opp (NormedModule.AbelianGroup K V) (@plus (NormedModule.AbelianGroup K V) x y)) (@plus (NormedModule.AbelianGroup K V) (@opp (NormedModule.AbelianGroup K V) x) (@opp (NormedModule.AbelianGroup K V) y)) *)
(* Goal: forall (k : AbsRing.sort K) (x : NormedModule.sort K V), @eq (NormedModule.sort K V) (@opp (NormedModule.AbelianGroup K V) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k (@opp (NormedModule.AbelianGroup K V) x)) *)
(* Goal: @ex R (fun M : R => and (Rlt (IZR Z0) M) (forall x : NormedModule.sort K V, Rle (@norm K V (@opp (NormedModule.AbelianGroup K V) x)) (Rmult M (@norm K V x)))) *)
    now apply opp_plus.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => k x.
(* Goal: @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
    apply sym_eq.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
    apply: scal_opp_r.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  - exists 1 ; split.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
(* Goal: forall t : AbsRing.sort R_AbsRing, @eq (NormedModule.sort R_AbsRing R_NormedModule) (Derive_n (Derive f) n t) (Derive (Derive_n f n) t) *)
    move => x ; rewrite norm_opp Rmult_1_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rle_refl.
Qed.

(** plus is a linear function *)
Lemma is_linear_plus : is_linear (fun x : V * V => plus (fst x) (snd x)).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  repeat split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => x y.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite -!plus_assoc ; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite plus_comm -!plus_assoc.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply f_equal, @plus_comm.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => k x.
(* Goal: Rlt (IZR Z0) (Rplus (Ropp a) b) *)
(* Goal: forall (c : R) (_ : and (Rle a c) (Rle c b)), derivable_pt_lim f c (df c) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
    now rewrite scal_distr_l.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  - exists 2 ; split.
    exact Rlt_0_2.
    move => x /= ; eapply Rle_trans.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply @norm_triangle.
    rewrite Rmult_plus_distr_r Rmult_1_l ; apply Rplus_le_compat.
    apply Rle_trans with (2 := proj1 (sqrt_plus_sqr _ _)).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite -> Rabs_pos_eq by apply norm_ge_0.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rmax_l.
    apply Rle_trans with (2 := proj1 (sqrt_plus_sqr _ _)).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite -> (Rabs_pos_eq (norm (snd x))) by apply norm_ge_0.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rmax_r.
Qed.

(** [fun k => scal k x] is a linear function *)
Lemma is_linear_scal_l (x : V) :
  is_linear (fun k : K => scal k x).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => u v ; by apply @scal_distr_r.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => u v /= ; apply sym_eq, @scal_assoc.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  - exists (norm x + 1) ; split.
(* Goal: Rlt (IZR Z0) (Rplus (@abs K k) (IZR (Zpos xH))) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    apply Rplus_le_lt_0_compat.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
    apply norm_ge_0.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
    move => k /=.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite Rmult_plus_distr_r Rmult_1_l -(Rplus_0_r (norm (scal k x))).
(* Goal: Rle (Rplus (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (IZR Z0)) (Rplus (Rmult (@abs K k) (@norm K V x)) (@norm K V x)) *)
    apply Rplus_le_compat.
(* Goal: Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (@norm K V x) (@norm K (AbsRing_NormedModule K) k)) *)
(* Goal: Rle (IZR Z0) (@norm K (AbsRing_NormedModule K) k) *)
    now rewrite Rmult_comm ; apply norm_scal.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
    apply norm_ge_0.
Qed.

(** [fun x => scal k x] is a linear function if [mult] is commutative *)
Lemma is_linear_scal_r (k : K) :
  (forall n m : K, mult n m = mult m n)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> is_linear (fun x : V => scal k x).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => u v ; by apply @scal_distr_l.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => u v /= ; apply sym_eq ; rewrite !@scal_assoc.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by rewrite H.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  - exists (abs k + 1) ; split.
(* Goal: Rlt (IZR Z0) (Rplus (@abs K k) (IZR (Zpos xH))) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    apply Rplus_le_lt_0_compat.
(* Goal: Rle (IZR Z0) (@abs K k) *)
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    apply abs_ge_0.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
    move => x /=.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite Rmult_plus_distr_r Rmult_1_l -(Rplus_0_r (norm (scal k x))).
(* Goal: Rle (Rplus (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (IZR Z0)) (Rplus (Rmult (@abs K k) (@norm K V x)) (@norm K V x)) *)
    apply Rplus_le_compat.
(* Goal: Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (@abs K k) (@norm K V x)) *)
(* Goal: Rle (IZR Z0) (@norm K V x) *)
    apply norm_scal.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
    apply norm_ge_0.
Qed.

End Op_LinearFct.

Lemma is_linear_prod {K : AbsRing} {T U V : NormedModule K}
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (l1 : T -> U) (l2 : T -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_linear l1 -> is_linear l2 -> is_linear (fun t : T => (l1 t, l2 t)).
Proof.
  intros H1 H2.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - intros x y.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
    apply injective_projections ; simpl.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply H1.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply H2.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - intros k x.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
    apply injective_projections ; simpl.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply H1.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply H2.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - destruct (linear_norm l1 H1) as [M1 [HM1 Hn1]].
    destruct (linear_norm l2 H2) as [M2 [HM2 Hn2]].
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
    exists (sqrt 2 * Rmax M1 M2)%R ; split.
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
    apply Rmult_lt_0_compat.
    apply sqrt_lt_R0, Rlt_0_2.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rmax_case.
(* Goal: forall x : R, @eq R (Derive (Derive_n (Derive_n f m) n) x) (Derive (Derive_n f (Init.Nat.add n m)) x) *)
    intros x.
    eapply Rle_trans.
    apply norm_prod.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rmult_assoc.
    apply Rmult_le_compat_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply sqrt_pos.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rmult_max_distr_r.
    apply Rmax_case.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by eapply Rle_trans, Rmax_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by eapply Rle_trans, Rmax_r.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
    by apply norm_ge_0.
Qed.

Lemma is_linear_fst {K : AbsRing} {U V : NormedModule K} :
  is_linear (fun t : U * V => fst t).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
  - intros [x1 x2] [y1 y2] ; by simpl.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
  - intros k [x1 x2] ; by simpl.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  - exists 1 ; split.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
    intros [x1 x2] ; simpl fst ; rewrite Rmult_1_l.
    eapply Rle_trans.
    2: by apply norm_prod.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rmax_l.
Qed.

Lemma is_linear_snd {K : AbsRing} {U V : NormedModule K} :
  is_linear (fun t : U * V => snd t).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
  - intros [x1 x2] [y1 y2] ; by simpl.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
  - intros k [x1 x2] ; by simpl.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  - exists 1 ; split.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
    intros [x1 x2] ; simpl snd ; rewrite Rmult_1_l.
    eapply Rle_trans.
    2: by apply norm_prod.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rmax_r.
Qed.

Section Linear_domin.

Context {T : Type} {Kw K : AbsRing} {W : NormedModule Kw} {U V : NormedModule K}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_domin_linear {F : (T -> Prop) -> Prop} {FF : Filter F} (f : T -> W) (g : T -> U) (l : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_linear l -> is_domin F f g -> is_domin F f (fun t => l (g t)).
Proof.
  intros [_ _ [M [Hm Hn]]] H eps.
  assert (He : 0 < eps / M).
    apply Rdiv_lt_0_compat with (2 := Hm).
    apply cond_pos.
  specialize (H (mkposreal _ He)).
  move: H ;
  apply filter_imp => /= x Hx.
  apply Rle_trans with (1 := Hn _).
  evar_last.
  apply Rmult_le_compat_l with (2 := Hx).
  now apply Rlt_le.
  field.
  now apply Rgt_not_eq.
Qed.

End Linear_domin.

(** * Differentiability using filters *)

Section Diff.

Context {K : AbsRing} {U : NormedModule K} {V : NormedModule K}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Definition filterdiff (f : U -> V) F (l : U -> V) :=
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_linear l /\ forall x, is_filter_lim F x ->
  is_domin F (fun y : U => minus y x) (fun y => minus (minus (f y) (f x)) (l (minus y x))).

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Definition ex_filterdiff (f : U -> V) F :=
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  exists (l : U -> V), filterdiff f F l.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_continuous_aux {F} {FF : Filter F} (f : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f F -> forall x, is_filter_lim F x -> filterlim f F (locally (f x)).
Proof.
  intros [l [Hl Df]] x Hx.
  specialize (Df x Hx).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filterlim_locally_ball_norm => eps.
  specialize (Df (mkposreal _ Rlt_0_1)) ; simpl in Df.
  destruct (linear_norm _ Hl) as [M Hm].
  assert (F (fun y => norm (minus (f y) (f x)) <= (M + 1) * norm (minus y x))).
(* Goal: @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n (fun x : R => Ropp (g x)) k y) *)
(* Goal: is_derive_n f n x lf *)
(* Goal: is_derive_n (fun x : R => Ropp (g x)) n x (Ropp lg) *)
    move: Df ; apply filter_imp => y Hy.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rmult_1_l in Hy.
    apply Rle_trans with (1 := norm_triangle_inv _ _) in Hy.
    apply Rabs_le_between' in Hy.
    eapply Rle_trans.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Hy.
    apply Rle_minus_r ; ring_simplify.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Hm.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move: H => {Df} Df.
  assert (Hm': 0 < M + 1).
(* Goal: Rlt (IZR Z0) (Rplus (@abs K k) (IZR (Zpos xH))) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    apply Rplus_le_lt_0_compat.
    apply Rlt_le, Hm.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
  assert (0 < eps / (M+1)).
    apply Rdiv_lt_0_compat with (2 := Hm').
    apply cond_pos.
  specialize (Hx _ (locally_ball_norm x (mkposreal _ H))).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  generalize (filter_and _ _ Hx Df) => /=.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp => y [Hy Hy'] {Hx Df}.
  apply Rle_lt_trans with (1 := Hy').
  evar_last.
  now apply Rmult_lt_compat_l with (2 := Hy).
  field.
  now apply Rgt_not_eq.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_continuous (f : U -> V) x :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f (locally x) -> continuous f x.
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_continuous_aux.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_locally {F} {FF : ProperFilter F} (f : U -> V) x l :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_filter_lim F x ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f (locally x) l ->
  filterdiff f F l.
Proof.
(* Goal: forall (_ : @is_filter_lim (NormedModule.UniformSpace K U) F x) (_ : filterdiff f (@locally (NormedModule.UniformSpace K U) x) l), filterdiff f F l *)
intros Fx [Hl Df].
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
split.
(* Goal: @is_linear K U V l *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K U)) (_ : @is_filter_lim (NormedModule.UniformSpace K U) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K U)) K K U V F (fun y : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K U) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K U) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f x)) (l (@minus (NormedModule.AbelianGroup K U) y x))) *)
exact Hl.
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K U)) (_ : @is_filter_lim (NormedModule.UniformSpace K U) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K U)) K K U V F (fun y : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K U) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K U) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f x)) (l (@minus (NormedModule.AbelianGroup K U) y x))) *)
intros z Fz.
(* Goal: @is_domin (UniformSpace.sort (NormedModule.UniformSpace K U)) K K U V F (fun y : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K U) y z) (fun y : UniformSpace.sort (NormedModule.UniformSpace K U) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f z)) (l (@minus (NormedModule.AbelianGroup K U) y z))) *)
specialize (Df _ (fun P H => H)).
(* Goal: @is_domin (UniformSpace.sort (NormedModule.UniformSpace K U)) K K U V F (fun y : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K U) y z) (fun y : UniformSpace.sort (NormedModule.UniformSpace K U) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f z)) (l (@minus (NormedModule.AbelianGroup K U) y z))) *)
generalize (is_filter_lim_unique _ _ Fx Fz).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
intros ->.
(* Goal: @is_domin (UniformSpace.sort (NormedModule.UniformSpace K U)) K K U V F (fun y : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K U) y z) (fun y : UniformSpace.sort (NormedModule.UniformSpace K U) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f z)) (l (@minus (NormedModule.AbelianGroup K U) y z))) *)
now apply is_domin_le with (2 := Fz).
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_locally {F} {FF : ProperFilter F} (f : U -> V) x :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_filter_lim F x ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f (locally x) ->
  ex_filterdiff f F.
Proof.
  intros Fx [l Df].
  eexists.
  apply filterdiff_locally with x.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Df.
Qed.

(** ** Operations *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_ext_lin {F} {FF : Filter F} (f : U -> V) (l1 l2 : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f F l1 -> (forall y, l1 y = l2 y) -> filterdiff f F l2.
Proof.
(* Goal: forall (_ : filterdiff f F l1) (_ : forall y : NormedModule.sort K U, @eq (NormedModule.sort K V) (l1 y) (l2 y)), filterdiff f F l2 *)
  intros [Hl1 Hf1] Hl ; split => [ | x Hx eps].
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  + split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    - intros x y ; rewrite -!Hl.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
      by apply linear_plus.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    - intros k x ; rewrite -!Hl.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
      by apply linear_scal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    - destruct (linear_norm _ Hl1) as [M Hm].
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
      exists M ; split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
      by apply Hm.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
      move => x ; now rewrite -Hl.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  + move: (Hf1 x Hx eps).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
    apply filter_imp => y.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by rewrite !Hl.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_ext_loc {F} {FF : Filter F} (f g : U -> V) (l : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  F (fun y => f y = g y) -> (forall x, is_filter_lim F x -> f x = g x)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> filterdiff f F l -> filterdiff g F l.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => H H0 [Hl Df].
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  split => //.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hx eps.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (g x0) (g x)) (l (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  specialize (H0 x Hx).
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (g x0) (g x)) (l (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  specialize (Df x Hx eps).
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (g x0) (g x)) (l (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  apply filter_and with (1 := H) in Df.
(* Goal: @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n (fun x : R => Ropp (g x)) k y) *)
(* Goal: is_derive_n f n x lf *)
(* Goal: is_derive_n (fun x : R => Ropp (g x)) n x (Ropp lg) *)
  move: Df ; apply filter_imp => y [Hy].
(* Goal: forall _ : Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f x)) (l (@minus (NormedModule.AbelianGroup K U) y x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) y x))), Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (g y) (g x)) (l (@minus (NormedModule.AbelianGroup K U) y x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) y x))) *)
  apply Rle_trans.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Req_le ; rewrite Hy H0.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_ext_loc {F} {FF : Filter F} (f g : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  F (fun y => f y = g y) -> (forall x, is_filter_lim F x -> f x = g x)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ex_filterdiff f F -> ex_filterdiff g F.
Proof.
(* Goal: forall (_ : F (fun y : NormedModule.sort K U => @eq (NormedModule.sort K V) (f y) (g y))) (_ : forall (x : UniformSpace.sort (NormedModule.UniformSpace K U)) (_ : @is_filter_lim (NormedModule.UniformSpace K U) F x), @eq (NormedModule.sort K V) (f x) (g x)) (_ : ex_filterdiff f F), ex_filterdiff g F *)
  intros H H0 [l Hl].
(* Goal: ex_filterdiff g F *)
  exists l ; by apply filterdiff_ext_loc with f.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_ext_locally (f g : U -> V) (x : U) (l : U -> V) :
  locally x (fun y => f y = g y)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> filterdiff f (locally x) l -> filterdiff g (locally x) l.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => H.
(* Goal: forall _ : filterdiff f (@locally (NormedModule.UniformSpace K U) x) l, filterdiff g (@locally (NormedModule.UniformSpace K U) x) l *)
  apply filterdiff_ext_loc with (1 := H).
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y Hy.
(* Goal: @eq (NormedModule.sort K V) (f y) (g y) *)
  destruct H as [d Hd].
(* Goal: @eq (NormedModule.sort K V) (f y) (g y) *)
  apply Hd.
(* Goal: @ball (NormedModule.UniformSpace K U) x (pos d) y *)
  replace y with x.
(* Goal: @ball (NormedModule.UniformSpace K U) x (pos d) x *)
(* Goal: @eq (NormedModule.sort K U) x y *)
  apply ball_center.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_filter_lim_locally_unique.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_ext_locally (f g : U -> V) x :
  locally x (fun y => f y = g y)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ex_filterdiff f (locally x) -> ex_filterdiff g (locally x).
Proof.
(* Goal: forall (_ : forall y : NormedModule.sort K U, @eq (NormedModule.sort K V) (f y) (g y)) (_ : ex_filterdiff f F), ex_filterdiff g F *)
  intros H [l Hl].
(* Goal: ex_filterdiff g F *)
  exists l ; by apply filterdiff_ext_locally with f.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_ext {F} {FF : Filter F} (f g : U -> V) (l : U -> V) :
  (forall y , f y = g y)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> filterdiff f F l -> filterdiff g F l.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => H.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filterdiff_ext_loc => //.
(* Goal: F (fun y : NormedModule.sort K U => @eq (NormedModule.sort K V) (f y) (g y)) *)
  now apply filter_imp with (2 := filter_true).
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_ext {F} {FF : Filter F} (f g : U -> V) :
  (forall y , f y = g y)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ex_filterdiff f F -> ex_filterdiff g F.
Proof.
(* Goal: forall (_ : forall y : NormedModule.sort K U, @eq (NormedModule.sort K V) (f y) (g y)) (_ : ex_filterdiff f F), ex_filterdiff g F *)
  intros H [l Hl].
(* Goal: ex_filterdiff g F *)
  exists l ; by apply filterdiff_ext with f.
Qed.

Lemma filterdiff_const {F} {FF : Filter F} (a : V) :
  filterdiff (fun _ => a) F (fun _ => zero).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_zero.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hx eps.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp with (2 := filter_true) => y _.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /minus plus_opp_r plus_zero_l norm_opp norm_zero.
(* Goal: Rle (IZR Z0) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@plus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u (@opp (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x)))) *)
(* Goal: @eq (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x))) v *)
  apply Rmult_le_pos.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rlt_le, eps.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
  by apply norm_ge_0.
Qed.
Lemma ex_filterdiff_const {F} {FF : Filter F} (a : V) :
  ex_filterdiff (fun _ => a) F.
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: ex_filterdiff (fun _ : NormedModule.sort K U => a) F *)
  exists (fun _ => zero).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_const.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_linear {F} (l : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_linear l -> filterdiff l F l.
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  move => Hl ; split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hx eps.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K V) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@opp (NormedModule.AbelianGroup K V) x0) (@opp (NormedModule.AbelianGroup K V) x)) (@opp (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) x0 x)))) (Rmult (pos eps) (@norm K V (@minus (NormedModule.AbelianGroup K V) x0 x)))) *)
  apply Hx.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_forall => y.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /minus -(linear_opp l x Hl) -linear_plus // plus_opp_r norm_zero.
(* Goal: Rle (IZR Z0) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@plus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u (@opp (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x)))) *)
(* Goal: @eq (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x))) v *)
  apply Rmult_le_pos.
(* Goal: Rle (IZR Z0) (pos eps) *)
(* Goal: Rle (IZR Z0) (@norm K U (@plus (NormedModule.AbelianGroup K U) y (@opp (NormedModule.AbelianGroup K U) x))) *)
  apply Rlt_le, eps.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
  by apply norm_ge_0.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_linear {F} (l : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_linear l -> ex_filterdiff l F.
Proof.
(* Goal: forall _ : @is_linear K U V l, ex_filterdiff l F *)
  intro Hl ; exists l; by apply filterdiff_linear.
Qed.

End Diff.

Section Diff_comp.

Context {K : AbsRing} {U V W : NormedModule K}.

Lemma filterdiff_comp
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  {F} {FF : Filter F} f g (lf : U -> V) (lg : V -> W) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f F lf -> filterdiff g (filtermap f F) lg
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> filterdiff (fun y => g (f y)) F (fun y => lg (lf y)).
Proof.
(* Goal: forall (_ : @ex_derive R_AbsRing R_NormedModule f (g x)) (_ : @ex_derive R_AbsRing R_NormedModule g x), @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  intros Df Dg.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun t : NormedModule.sort K (prod_NormedModule K V V) => @opp (NormedModule.AbelianGroup K V) (@snd (NormedModule.sort K V) (NormedModule.sort K V) t)) *)
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun u : NormedModule.sort K (prod_NormedModule K V V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) (_ : @is_filter_lim (NormedModule.UniformSpace K (prod_NormedModule K V V)) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) K K (prod_NormedModule K V V) V F (fun y : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) y) (@snd (NormedModule.sort K V) (NormedModule.sort K V) y)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)))) *)
    apply is_linear_comp.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Df.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Dg.
(* Goal: forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) (h a)) *)
  intros x Hx.
  assert (Cf : filterlim f F (locally (f x))).
    apply filterdiff_continuous_aux with (2 := Hx).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    eexists ; by apply Df.
  assert (is_domin (filtermap f F) (fun y : V => minus y (f x))
    (fun y : V => minus (minus (g y) (g (f x))) (lg (minus y (f x))))).
    apply Dg.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
    move => P HP.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Cf.
  destruct Dg as [Hg _].
  rename H into Dg.
  destruct Df as [Hf Df].
  apply domin_rw_r with
    (fun y : U => plus (minus (minus (g (f y)) (g (f x))) (lg (minus (f y) (f x))))
                       (lg (minus (minus (f y) (f x)) (lf (minus y x))))).
  apply equiv_ext_loc.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_forall => y.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /minus -!plus_assoc.
  repeat apply f_equal.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite plus_assoc.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite (linear_plus _ Hg (plus _ _)).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite plus_assoc.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite plus_opp_l plus_zero_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply linear_opp.

  apply domin_plus.
(* Goal: is_lim' (fun h : R => Rdiv (Rminus (f (Rplus x h)) (f x)) h) (Finite (IZR Z0)) (Finite l) *)
  intros eps.
  destruct (linear_norm _ Hf) as [mf [Hmf Hnf]].
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  assert (F (fun y => norm (minus (f y) (f x)) <= (1 + mf) * norm  (minus y x))).
    specialize (Df x Hx (mkposreal _ Rlt_0_1)).
    move: Df ; apply filter_imp.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
    move => y /= Hy.
    replace (minus (f y) (f x))
    with (plus (minus (minus (f y) (f x)) (lf (minus y x))) (lf (minus y x))).
    eapply Rle_trans.
    apply @norm_triangle.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rmult_plus_distr_r.
(* Goal: Rle (Rplus (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (IZR Z0)) (Rplus (Rmult (@abs K k) (@norm K V x)) (@norm K V x)) *)
    apply Rplus_le_compat.
    exact Hy.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Hnf.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    by rewrite {1}/minus -plus_assoc plus_opp_l plus_zero_r.
  clear Df ; rename H into Df.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  assert (He : 0 < eps / (1 + mf)).
(* Goal: Rlt (IZR Z0) (Rdiv (pos r) (Rabs a)) *)
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rmult (pow a n) (Derive_n f n (Rmult a t))) (Derive_n (fun y : R => f (Rmult a y)) n t)) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rdiv_lt_0_compat.
    apply cond_pos.
    apply Rplus_lt_0_compat.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    exact Rlt_0_1.
    exact Hmf.
  specialize (Dg (mkposreal _ He)).
  unfold filtermap in Dg.
  generalize (filter_and _ _ Df Dg).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp => /= y {Df Dg} [Df Dg].
  apply Rle_trans with (1 := Dg).
  unfold Rdiv.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Rmult_assoc.
  apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (pos eps) *)
(* Goal: Rle (IZR Z0) (@norm K U (@plus (NormedModule.AbelianGroup K U) y (@opp (NormedModule.AbelianGroup K U) x))) *)
  apply Rlt_le, eps.
  rewrite Rmult_comm ; apply Rle_div_l.
  apply Rplus_lt_0_compat.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
  exact Rlt_0_1.
  exact Hmf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  rewrite Rmult_comm ; by apply Df.

  specialize (Df x Hx).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_domin_linear.
Qed.

Lemma ex_filterdiff_comp
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  {F} {FF : Filter F} (f : U -> V) (g : V -> W) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f F -> ex_filterdiff g (filtermap f F)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ex_filterdiff (fun y => g (f y)) F.
Proof.
(* Goal: forall (_ : @ex_filterdiff K U V f F) (_ : @ex_filterdiff K V W g (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f F)), @ex_filterdiff K U W (fun y : NormedModule.sort K U => g (f y)) F *)
  intros [lf Df] [lg Dg].
(* Goal: @ex_filterdiff K U W (fun y : NormedModule.sort K U => g (f y)) F *)
  eexists ; eapply filterdiff_comp ; eassumption.
Qed.

Lemma filterdiff_comp'
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  f g x (lf : U -> V) (lg : V -> W) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f (locally x) lf -> filterdiff g (locally (f x)) lg
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> filterdiff (fun y => g (f y)) (locally x) (fun y => lg (lf y)).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: @filterdiff K U V (fun t : NormedModule.sort K U => @opp (NormedModule.AbelianGroup K V) (f t)) F (fun t : NormedModule.sort K U => @opp (NormedModule.AbelianGroup K V) (lf t)) *)
  apply filterdiff_comp.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @filterdiff K V W g (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f (@locally (NormedModule.UniformSpace K U) x)) lg *)
  apply filterdiff_locally with (f x).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply is_filter_lim_filtermap => //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filterdiff_continuous => //.
(* Goal: @ex_filterdiff K U V f (@locally (NormedModule.UniformSpace K U) x) *)
(* Goal: @filterdiff K V W g (@locally (NormedModule.UniformSpace K V) (f x)) lg *)
  eexists ; by apply H.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
Qed.

Lemma ex_filterdiff_comp'
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (f : U -> V) (g : V -> W) x :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f (locally x) -> ex_filterdiff g (locally (f x))
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ex_filterdiff (fun y => g (f y)) (locally x).
Proof.
(* Goal: forall (_ : @ex_filterdiff K U V f F) (_ : @ex_filterdiff K V W g (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f F)), @ex_filterdiff K U W (fun y : NormedModule.sort K U => g (f y)) F *)
  intros [lf Df] [lg Dg].
  eexists.
  apply filterdiff_comp' ; eassumption.
Qed.

End Diff_comp.

Section Diff_comp2.

Context {K : AbsRing} {T U V : NormedModule K}.

Section Diff_comp2'.

Context {W : NormedModule K}.

Lemma filterdiff_comp_2
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  {F : (T -> Prop) -> Prop} {FF : Filter F} :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : T -> U) (g : T -> V) (h : U -> V -> W) (lf : T -> U) (lg : T -> V)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    (lh : U -> V -> W),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    filterdiff f F lf ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    filterdiff g F lg ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    filterdiff (fun t => h (fst t) (snd t)) (filtermap (fun t => (f t,g t)) F) (fun t => lh (fst t) (snd t)) ->
    filterdiff (fun y : T => h (f y) (g y)) F (fun y : T => lh (lf y) (lg y)).
Proof.
  intros f g h lf lg lh [Hf Df] [Hg Dg] Dh.
  apply (filterdiff_comp (fun t => (f t, g t)) _ (fun t => (lf t, lg t)) _) in Dh.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_prod.
  intros x Hx eps.
  assert (0 < eps / sqrt 2).
(* Goal: Rlt (IZR Z0) (Rdiv (pos r) (Rabs a)) *)
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rmult (pow a n) (Derive_n f n (Rmult a t))) (Derive_n (fun y : R => f (Rmult a y)) n t)) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rdiv_lt_0_compat.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply eps.
    apply Rlt_sqrt2_0.
  generalize (filter_and _ _ (Df x Hx (mkposreal _ H)) (Dg x Hx (mkposreal _ H))).
  simpl pos.
  apply filter_imp ; intros y [Hnf Hng].
  eapply Rle_trans.
  apply norm_prod.
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u x))))) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u x))) *)
  simpl fst ; simpl snd.
  eapply Rle_trans.
  apply Rmult_le_compat_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply sqrt_pos.
  apply Rmax_case.
  apply Hnf.
  apply Hng.
  apply Req_le ; field.
  apply Rgt_not_eq, Rlt_sqrt2_0.
Qed.

Lemma ex_filterdiff_comp_2
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  {F : (T -> Prop) -> Prop} {FF : Filter F} :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : T -> U) (g : T -> V) (h : U -> V -> W),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    ex_filterdiff f F ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    ex_filterdiff g F ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    ex_filterdiff (fun t => h (fst t) (snd t)) (filtermap (fun t => (f t,g t)) F) ->
    ex_filterdiff (fun y : T => h (f y) (g y)) F.
Proof.
  intros f g h [lf Df] [lg Dg] [lh Dh].
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos (mkposreal (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y)) Hy)) y0), @eq R (Derive_n (fun y : R => f (Rmult a y)) n y0) (Rmult (pow a n) (Derive_n f n (Rmult a y0))) *)
  set lh' := fun x y => lh (x,y).
  eexists ; eapply (filterdiff_comp_2 _ _ _ _ _ lh') ; try eassumption.
  eapply filterdiff_ext_lin.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Dh.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by case.
Qed.

End Diff_comp2'.

Context {W : NormedModule K}.

Lemma filterdiff_comp'_2 :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : T -> U) (g : T -> V) (h : U -> V -> W) x (lf : T -> U) (lg : T -> V)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    (lh : U -> V -> W),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    filterdiff f (locally x) lf ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    filterdiff g (locally x) lg ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    filterdiff (fun t => h (fst t) (snd t)) (locally (f x,g x)) (fun t => lh (fst t) (snd t)) ->
    filterdiff (fun y : T => h (f y) (g y)) (locally x) (fun y : T => lh (lf y) (lg y)).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: @filterdiff K U V (fun u : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K V) (f u) (g u)) F (fun u : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K V) (lf u) (lg u)) *)
  apply filterdiff_comp_2.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@filtermap (NormedModule.sort K T) (prod (NormedModule.sort K U) (NormedModule.sort K V)) (fun t : NormedModule.sort K T => @pair (NormedModule.sort K U) (NormedModule.sort K V) (f t) (g t)) (@locally (NormedModule.UniformSpace K T) x)) (fun t : NormedModule.sort K (prod_NormedModule K U V) => lh (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) *)
  apply filterdiff_locally with (f x, g x).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply (is_filter_lim_filtermap _ _ (fun t : T => (f t, g t))) => //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply (filterdiff_continuous (fun t : T => (f t, g t))) => //.
(* Goal: @ex_filterdiff K T (prod_NormedModule K U V) (fun t : NormedModule.sort K T => @pair (NormedModule.sort K U) (NormedModule.sort K V) (f t) (g t)) (@locally (NormedModule.UniformSpace K T) x) *)
(* Goal: @filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@locally (NormedModule.UniformSpace K (prod_NormedModule K U V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) (f x) (g x))) (fun t : NormedModule.sort K (prod_NormedModule K U V) => lh (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) *)
  apply ex_filterdiff_comp_2.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by exists lf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by exists lg.
(* Goal: @ex_filterdiff K (prod_NormedModule K U V) (prod_NormedModule K U V) (fun t : NormedModule.sort K (prod_NormedModule K U V) => @pair (NormedModule.sort K U) (NormedModule.sort K V) (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@filtermap (NormedModule.sort K T) (prod (NormedModule.sort K U) (NormedModule.sort K V)) (fun t : NormedModule.sort K T => @pair (NormedModule.sort K U) (NormedModule.sort K V) (f t) (g t)) (@locally (NormedModule.UniformSpace K T) x)) *)
(* Goal: @filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@locally (NormedModule.UniformSpace K (prod_NormedModule K U V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) (f x) (g x))) (fun t : NormedModule.sort K (prod_NormedModule K U V) => lh (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) *)
  apply ex_filterdiff_linear.
(* Goal: @is_linear K (prod_NormedModule K V V) (prod_NormedModule K V V) (fun u : NormedModule.sort K (prod_NormedModule K V V) => @pair (NormedModule.sort K V) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@opp (NormedModule.AbelianGroup K V) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u))) *)
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun u : NormedModule.sort K (prod_NormedModule K V V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) (_ : @is_filter_lim (NormedModule.UniformSpace K (prod_NormedModule K V V)) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) K K (prod_NormedModule K V V) V F (fun y : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) y) (@snd (NormedModule.sort K V) (NormedModule.sort K V) y)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)))) *)
  apply is_linear_prod.
(* Goal: @is_linear K (prod_NormedModule K U V) U (@fst (NormedModule.sort K U) (NormedModule.sort K V)) *)
(* Goal: @is_linear K (prod_NormedModule K U V) V (@snd (NormedModule.sort K U) (NormedModule.sort K V)) *)
(* Goal: @filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@locally (NormedModule.UniformSpace K (prod_NormedModule K U V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) (f x) (g x))) (fun t : NormedModule.sort K (prod_NormedModule K U V) => lh (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) *)
  apply is_linear_fst.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_snd.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
Qed.

Lemma ex_filterdiff_comp'_2 :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : T -> U) (g : T -> V) (h : U -> V -> W) x,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    ex_filterdiff f (locally x) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    ex_filterdiff g (locally x) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    ex_filterdiff (fun t => h (fst t) (snd t)) (locally (f x,g x)) ->
    ex_filterdiff (fun y : T => h (f y) (g y)) (locally x).
Proof.
(* Goal: forall (f : forall _ : NormedModule.sort K T, NormedModule.sort K U) (g : forall _ : NormedModule.sort K T, NormedModule.sort K V) (h : forall (_ : NormedModule.sort K U) (_ : NormedModule.sort K V), NormedModule.sort K W) (x : UniformSpace.sort (NormedModule.UniformSpace K T)) (_ : @ex_filterdiff K T U f (@locally (NormedModule.UniformSpace K T) x)) (_ : @ex_filterdiff K T V g (@locally (NormedModule.UniformSpace K T) x)) (_ : @ex_filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@locally (prod_UniformSpace (NormedModule.UniformSpace K U) (NormedModule.UniformSpace K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) (f x) (g x)))), @ex_filterdiff K T W (fun y : NormedModule.sort K T => h (f y) (g y)) (@locally (NormedModule.UniformSpace K T) x) *)
  intros f g h x [lf Df] [lg Dg] [lh Dh].
(* Goal: @ex_filterdiff K T W (fun y : NormedModule.sort K T => h (f y) (g y)) (@locally (NormedModule.UniformSpace K T) x) *)
  exists (fun x => lh (lf x,lg x)).
(* Goal: @filterdiff K T W (fun y : NormedModule.sort K T => h (f y) (g y)) (@locally (NormedModule.UniformSpace K T) x) (fun x : NormedModule.sort K T => lh (@pair (NormedModule.sort K U) (NormedModule.sort K V) (lf x) (lg x))) *)
  apply (filterdiff_comp'_2 f g h x lf lg (fun x y => lh (x,y))) ; try eassumption.
(* Goal: @filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@locally (prod_UniformSpace (NormedModule.UniformSpace K U) (NormedModule.UniformSpace K V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) (f x) (g x))) (fun t : NormedModule.sort K (prod_NormedModule K U V) => lh (@pair (NormedModule.sort K U) (NormedModule.sort K V) (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t))) *)
  eapply filterdiff_ext_lin ; try eassumption.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by case.
Qed.

End Diff_comp2.

Section Operations.

Context {K : AbsRing} {V : NormedModule K}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_id (F : (V -> Prop) -> Prop) :
  filterdiff (fun y => y) F (fun y => y).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_id.

(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hx eps.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x0) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x0)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x))))) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x)))) *)
  apply Hx ; exists eps => y /= Hy.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /minus plus_opp_r norm_zero.
(* Goal: Rle (IZR Z0) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@plus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u (@opp (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x)))) *)
(* Goal: @eq (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x))) v *)
  apply Rmult_le_pos.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rlt_le, eps.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
  by apply norm_ge_0.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_id (F : (V -> Prop) -> Prop) :
  ex_filterdiff (fun y => y) F.
Proof.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_id.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_opp (F : (V -> Prop) -> Prop) :
  filterdiff opp F opp.
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_opp.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hx eps.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K V) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@opp (NormedModule.AbelianGroup K V) x0) (@opp (NormedModule.AbelianGroup K V) x)) (@opp (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) x0 x)))) (Rmult (pos eps) (@norm K V (@minus (NormedModule.AbelianGroup K V) x0 x)))) *)
  apply Hx.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  exists eps => y /= Hy.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /minus -!opp_plus plus_opp_r norm_opp norm_zero.
(* Goal: Rle (IZR Z0) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@plus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u (@opp (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x)))) *)
(* Goal: @eq (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x))) v *)
  apply Rmult_le_pos.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rlt_le, eps.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
  by apply norm_ge_0.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_opp (F : (V -> Prop) -> Prop) :
  ex_filterdiff opp F.
Proof.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_opp.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_plus (F : (V * V -> Prop) -> Prop) :
  filterdiff (fun u => plus (fst u) (snd u)) F (fun u => plus (fst u) (snd u)).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_plus.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hx eps.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x0) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x0)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x))))) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x)))) *)
  apply Hx ; exists eps => u /= Hu.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos (mkposreal (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y)) Hy)) y0), @eq R (Derive_n (fun y : R => f (Rmult a y)) n y0) (Rmult (pow a n) (Derive_n f n (Rmult a y0))) *)
  set v := plus (plus _ _) _.
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) (@plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) v)) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u x))) *)
  replace v with (minus (plus (fst u) (snd u)) (plus (fst x) (snd x))).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /minus plus_opp_r norm_zero.
(* Goal: Rle (IZR Z0) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@plus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u (@opp (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x)))) *)
(* Goal: @eq (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x))) v *)
  apply Rmult_le_pos.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rlt_le, eps.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply sqrt_pos.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /v /minus -!plus_assoc ; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite opp_plus plus_comm -!plus_assoc ; apply f_equal, @plus_comm.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_plus (F : (V * V -> Prop) -> Prop) :
  ex_filterdiff (fun u => plus (fst u) (snd u)) F.
Proof.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_plus.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_minus (F : (V * V -> Prop) -> Prop) :
  filterdiff (fun u => minus (fst u) (snd u)) F (fun u => minus (fst u) (snd u)).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun u : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) (_ : @is_filter_lim (NormedModule.UniformSpace K (prod_NormedModule K V V)) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) K K (prod_NormedModule K V V) V F (fun y : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) y) (@snd (NormedModule.sort K V) (NormedModule.sort K V) y)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)))) *)
  apply (is_linear_comp (fun u => (fst u, opp (snd u))) (fun u => plus (fst u) (snd u))).
(* Goal: @is_linear K (prod_NormedModule K V V) (prod_NormedModule K V V) (fun u : NormedModule.sort K (prod_NormedModule K V V) => @pair (NormedModule.sort K V) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@opp (NormedModule.AbelianGroup K V) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u))) *)
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun u : NormedModule.sort K (prod_NormedModule K V V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) (_ : @is_filter_lim (NormedModule.UniformSpace K (prod_NormedModule K V V)) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) K K (prod_NormedModule K V V) V F (fun y : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) y) (@snd (NormedModule.sort K V) (NormedModule.sort K V) y)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)))) *)
  apply is_linear_prod.
(* Goal: @is_linear K (prod_NormedModule K U V) U (@fst (NormedModule.sort K U) (NormedModule.sort K V)) *)
(* Goal: @is_linear K (prod_NormedModule K U V) V (@snd (NormedModule.sort K U) (NormedModule.sort K V)) *)
(* Goal: @filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@locally (NormedModule.UniformSpace K (prod_NormedModule K U V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) (f x) (g x))) (fun t : NormedModule.sort K (prod_NormedModule K U V) => lh (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) *)
  by apply is_linear_fst.
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun t : NormedModule.sort K (prod_NormedModule K V V) => @opp (NormedModule.AbelianGroup K V) (@snd (NormedModule.sort K V) (NormedModule.sort K V) t)) *)
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun u : NormedModule.sort K (prod_NormedModule K V V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) (_ : @is_filter_lim (NormedModule.UniformSpace K (prod_NormedModule K V V)) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) K K (prod_NormedModule K V V) V F (fun y : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) y) (@snd (NormedModule.sort K V) (NormedModule.sort K V) y)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)))) *)
  apply is_linear_comp.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_snd.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_opp.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_plus.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hx eps.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x0) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x0)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x))))) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x0 x)))) *)
  apply Hx ; exists eps => u Hu.
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u x))))) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u x))) *)
  simpl fst ; simpl snd.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos (mkposreal (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y)) Hy)) y0), @eq R (Derive_n (fun y : R => f (Rmult a y)) n y0) (Rmult (pow a n) (Derive_n f n (Rmult a y0))) *)
  set v := minus (plus _ (opp (fst x))) _.
(* Goal: Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) v)) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u x))) *)
  replace v with (minus (minus (fst u) (snd u)) (minus (fst x) (snd x))).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /minus plus_opp_r norm_zero.
(* Goal: Rle (IZR Z0) (Rmult (pos eps) (@norm K (prod_NormedModule K V V) (@plus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) u (@opp (NormedModule.AbelianGroup K (prod_NormedModule K V V)) x)))) *)
(* Goal: @eq (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) u)) (@minus (NormedModule.AbelianGroup K V) (@fst (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x) (@snd (UniformSpace.sort (NormedModule.UniformSpace K V)) (UniformSpace.sort (NormedModule.UniformSpace K V)) x))) v *)
  apply Rmult_le_pos.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rlt_le, eps.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply sqrt_pos.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /v /minus -!plus_assoc ; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite !opp_plus !opp_opp plus_comm -!plus_assoc ;
  apply f_equal, @plus_comm.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_minus (F : (V * V -> Prop) -> Prop) :
  ex_filterdiff (fun u => minus (fst u) (snd u)) F.
Proof.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_minus.
Qed.

Local Ltac plus_grab e :=
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  repeat rewrite (plus_assoc _ e) -(plus_comm e) -(plus_assoc e).

Lemma filterdiff_scal :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall {F : (K * V -> Prop) -> Prop} {FF : ProperFilter F} (x : K * V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_filter_lim F x ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
  filterdiff (fun t : K * V => scal (fst t) (snd t)) F
    (fun t => plus (scal (fst t) (snd x)) (scal (fst x) (snd t))).
Proof.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  move => F FF [x1 x2] Hx Hcomm ; split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - apply (is_linear_comp (fun t : K * V => (scal (fst t) x2,scal x1 (snd t))) (fun t : V * V => plus (fst t) (snd t))).
(* Goal: @is_linear K (prod_NormedModule K V V) (prod_NormedModule K V V) (fun u : NormedModule.sort K (prod_NormedModule K V V) => @pair (NormedModule.sort K V) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@opp (NormedModule.AbelianGroup K V) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u))) *)
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun u : NormedModule.sort K (prod_NormedModule K V V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) (_ : @is_filter_lim (NormedModule.UniformSpace K (prod_NormedModule K V V)) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) K K (prod_NormedModule K V V) V F (fun y : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) y) (@snd (NormedModule.sort K V) (NormedModule.sort K V) y)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)))) *)
    apply is_linear_prod.
    apply (is_linear_comp (fun t : K * V => fst t) (fun k : K => scal k x2)).
(* Goal: @is_linear K (prod_NormedModule K U V) U (@fst (NormedModule.sort K U) (NormedModule.sort K V)) *)
(* Goal: @is_linear K (prod_NormedModule K U V) V (@snd (NormedModule.sort K U) (NormedModule.sort K V)) *)
(* Goal: @filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@locally (NormedModule.UniformSpace K (prod_NormedModule K U V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) (f x) (g x))) (fun t : NormedModule.sort K (prod_NormedModule K U V) => lh (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) *)
    by apply is_linear_fst.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply is_linear_scal_l.
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun t : NormedModule.sort K (prod_NormedModule K V V) => @opp (NormedModule.AbelianGroup K V) (@snd (NormedModule.sort K V) (NormedModule.sort K V) t)) *)
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun u : NormedModule.sort K (prod_NormedModule K V V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) (_ : @is_filter_lim (NormedModule.UniformSpace K (prod_NormedModule K V V)) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) K K (prod_NormedModule K V V) V F (fun y : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) y) (@snd (NormedModule.sort K V) (NormedModule.sort K V) y)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)))) *)
    apply is_linear_comp.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply is_linear_snd.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply is_linear_scal_r.
    apply is_linear_plus.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - move => y Hy eps.
    replace y with (x1,x2).
    2: now apply is_filter_lim_unique with (1 := Hx).
    clear y Hy.
    apply Hx ; clear Hx.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
    apply: locally_le_locally_norm.
    exists eps.
    intros [y1 y2] H.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
    simpl.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos (mkposreal (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y)) Hy)) y0), @eq R (Derive_n (fun y : R => f (Rmult a y)) n y0) (Rmult (pow a n) (Derive_n f n (Rmult a y0))) *)
    set v := minus (minus _ _) _.
    replace v with (scal (minus y1 x1) (minus y2 x2)).
    apply Rle_trans with (1 := norm_scal _ _).
    generalize (proj1 (sqrt_plus_sqr (abs (minus y1 x1)) (norm (minus y2 x2)))).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite -> Rabs_pos_eq by apply abs_ge_0.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite -> Rabs_pos_eq by apply norm_ge_0.
    intros H'.
    apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (@abs K k) *)
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: forall x : NormedModule.sort K V, Rle (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (Rmult (Rplus (@abs K k) (IZR (Zpos xH))) (@norm K V x)) *)
    apply abs_ge_0.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
    apply norm_ge_0.
    apply Rlt_le, Rle_lt_trans with (2 := H).
    apply Rle_trans with (2 := H').
(* Goal: Rle (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) x)) (Rmax (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) x)) (Rabs (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x)))) *)
(* Goal: Rle (IZR Z0) (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) x)) *)
    apply Rmax_l.
    apply Rle_trans with (2 := H').
(* Goal: Rle (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x)) (Rmax (Rabs (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) x))) (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x))) *)
(* Goal: Rle (IZR Z0) (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x)) *)
    apply Rmax_r.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite /v /minus !scal_distr_l !scal_distr_r !opp_plus !scal_opp_r !scal_opp_l !opp_opp -!plus_assoc.
(* Goal: @eq R (Rmult (pow a n) (Derive (fun x : R => Derive_n f n (Rmult a x)) y)) (Rmult (pow a n) (Rmult a (Derive (Derive_n f n) (Rmult a y)))) *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
    apply f_equal.
    plus_grab (opp (scal x1 y2)).
(* Goal: @eq R (Rmult (pow a n) (Derive (fun x : R => Derive_n f n (Rmult a x)) y)) (Rmult (pow a n) (Rmult a (Derive (Derive_n f n) (Rmult a y)))) *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
    apply f_equal.
    plus_grab (opp (scal y1 x2)).
(* Goal: @eq R (Rmult (pow a n) (Derive (fun x : R => Derive_n f n (Rmult a x)) y)) (Rmult (pow a n) (Rmult a (Derive (Derive_n f n) (Rmult a y)))) *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
    apply f_equal.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by rewrite plus_assoc plus_opp_l plus_zero_l.
Qed.

Lemma ex_filterdiff_scal : forall {F} {FF : ProperFilter F} (x : K * V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_filter_lim F x ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
  ex_filterdiff (fun t : K * V => scal (fst t) (snd t)) F.
Proof.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply (filterdiff_scal x).
Qed.

Lemma filterdiff_scal_l : forall {F} {FF : Filter F} (x : V),
  filterdiff (fun k : K => scal k x) F (fun k => scal k x).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => F FF x.
(* Goal: @filterdiff K V V (fun x : NormedModule.sort K V => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x) (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f F) (fun x : NormedModule.sort K V => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x) *)
  apply filterdiff_linear.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_scal_l.
Qed.

Lemma ex_filterdiff_scal_l : forall {F} {FF : Filter F} (x : V),
  ex_filterdiff (fun k : K => scal k x) F.
Proof.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply (filterdiff_scal_l x).
Qed.

Lemma filterdiff_scal_r : forall {F} {FF : Filter F} (k : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
  filterdiff (fun x : V => scal k x) F (fun x => scal k x).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => F FF x Hcomm.
(* Goal: @filterdiff K V V (fun x : NormedModule.sort K V => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x) (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f F) (fun x : NormedModule.sort K V => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x) *)
  apply filterdiff_linear.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_scal_r.
Qed.

Lemma ex_filterdiff_scal_r : forall {F} {FF : Filter F} (k : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
  ex_filterdiff (fun x : V => scal k x) F.
Proof.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply (filterdiff_scal_r k).
Qed.

End Operations.

Lemma filterdiff_mult {K : AbsRing} :
 forall {F} {FF : ProperFilter F} (x : K * K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_filter_lim F x ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
  filterdiff (fun t : K * K => mult (fst t) (snd t)) F
    (fun t => plus (mult (fst t) (snd x)) (mult (fst x) (snd t))).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
  generalize (filterdiff_scal x H H0) ; by simpl.
Qed.

Lemma ex_filterdiff_mult {K : AbsRing} :
 forall {F} {FF : ProperFilter F} (x : K * K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_filter_lim F x ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
  ex_filterdiff (fun t : K * K => mult (fst t) (snd t)) F.
Proof.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply (filterdiff_mult x).
Qed.

(** Composed operations *)

Section Operations_fct.

Context {K : AbsRing} {U V : NormedModule K}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_opp_fct {F} {FF : Filter F} (f lf : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f F lf ->
  filterdiff (fun t => opp (f t)) F (fun t => opp (lf t)).
Proof.
(* Goal: forall _ : @filterdiff K U V f F lf, @filterdiff K U V (fun t : NormedModule.sort K U => @opp (NormedModule.AbelianGroup K V) (f t)) F (fun t : NormedModule.sort K U => @opp (NormedModule.AbelianGroup K V) (lf t)) *)
  intro Df.
(* Goal: @filterdiff K U V (fun t : NormedModule.sort K U => @opp (NormedModule.AbelianGroup K V) (f t)) F (fun t : NormedModule.sort K U => @opp (NormedModule.AbelianGroup K V) (lf t)) *)
  apply filterdiff_comp.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_opp.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_opp_fct {F} {FF : Filter F} (f : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f F ->
  ex_filterdiff (fun t => opp (f t)) F.
Proof.
  intros [lf Df].
  eexists.
  apply filterdiff_opp_fct ; eassumption.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_plus_fct {F} {FF : Filter F} (f g : U -> V) (lf lg : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f F lf -> filterdiff g F lg ->
  filterdiff (fun u => plus (f u) (g u)) F (fun u => plus (lf u) (lg u)).
Proof.
(* Goal: forall (_ : @ex_derive R_AbsRing R_NormedModule f (g x)) (_ : @ex_derive R_AbsRing R_NormedModule g x), @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  intros Df Dg.
(* Goal: @filterdiff K U V (fun u : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K V) (f u) (g u)) F (fun u : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K V) (lf u) (lg u)) *)
  apply filterdiff_comp_2.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_plus.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_plus_fct {F} {FF : Filter F} (f g : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f F -> ex_filterdiff g F ->
  ex_filterdiff (fun u => plus (f u) (g u)) F.
Proof.
(* Goal: forall (_ : @ex_filterdiff K U V f F) (_ : @ex_filterdiff K V W g (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f F)), @ex_filterdiff K U W (fun y : NormedModule.sort K U => g (f y)) F *)
  intros [lf Df] [lg Dg].
  eexists.
  apply filterdiff_plus_fct ; eassumption.
Qed.
Lemma filterdiff_iter_plus_fct {I} {F} {FF : Filter F}
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (l : list I) (f : I -> U -> V) df (x : U) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (j : I), List.In j l -> filterdiff (f j) F (df j)) ->
  filterdiff (fun y => iter plus zero l (fun j => f j y)) F
    (fun x => iter plus zero l (fun j => df j x)).
Proof.
(* Goal: forall _ : forall (j : I) (_ : @List.In I j l), @filterdiff K U V (f j) F (df j), @filterdiff K U V (fun y : NormedModule.sort K U => @iter I (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@plus (NormedModule.AbelianGroup K V)) (@zero (NormedModule.AbelianGroup K V)) l (fun j : I => f j y)) F (fun x : NormedModule.sort K U => @iter I (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@plus (NormedModule.AbelianGroup K V)) (@zero (NormedModule.AbelianGroup K V)) l (fun j : I => df j x)) *)
  intros Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  induction l ; simpl in * |- *.
(* Goal: @filterdiff K (AbsRing_NormedModule K) V (fun _ : AbsRing.sort K => a) (@locally (AbsRing_UniformSpace K) x) (fun _ : AbsRing.sort K => @zero (NormedModule.AbelianGroup K V)) *)
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@zero (NormedModule.AbelianGroup K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@zero (NormedModule.AbelianGroup K V))) *)
  apply filterdiff_const.
(* Goal: @filterdiff K U V (fun y : NormedModule.sort K U => @plus (NormedModule.AbelianGroup K V) (f a y) (@iter I (NormedModule.sort K V) (@plus (NormedModule.AbelianGroup K V)) (@zero (NormedModule.AbelianGroup K V)) l (fun j : I => f j y))) F (fun x : NormedModule.sort K U => @plus (NormedModule.AbelianGroup K V) (df a x) (@iter I (NormedModule.sort K V) (@plus (NormedModule.AbelianGroup K V)) (@zero (NormedModule.AbelianGroup K V)) l (fun j : I => df j x))) *)
  apply filterdiff_plus_fct.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by left.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  apply IHl ; intros.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by right.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_minus_fct {F} {FF : Filter F} (f g : U -> V) (lf lg : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f F lf -> filterdiff g F lg ->
  filterdiff (fun u => minus (f u) (g u)) F (fun u => minus (lf u) (lg u)).
Proof.
(* Goal: forall (_ : @ex_derive R_AbsRing R_NormedModule f (g x)) (_ : @ex_derive R_AbsRing R_NormedModule g x), @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  intros Df Dg.
(* Goal: @filterdiff K U V (fun u : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K V) (f u) (g u)) F (fun u : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K V) (lf u) (lg u)) *)
  apply filterdiff_comp_2.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_minus.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_minus_fct {F} {FF : Filter F} (f g : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f F -> ex_filterdiff g F ->
  ex_filterdiff (fun u => minus (f u) (g u)) F.
Proof.
(* Goal: forall (_ : @ex_filterdiff K U V f F) (_ : @ex_filterdiff K V W g (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f F)), @ex_filterdiff K U W (fun y : NormedModule.sort K U => g (f y)) F *)
  intros [lf Df] [lg Dg].
  eexists.
  apply filterdiff_minus_fct ; eassumption.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_scal_fct x (f : U -> K) (g : U -> V) lf lg :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f (locally x) lf -> filterdiff g (locally x) lg ->
  filterdiff (fun t => scal (f t) (g t)) (locally x)
    (fun t => plus (scal (lf t) (g x)) (scal (f x) (lg t))).
Proof.
(* Goal: forall (_ : forall n m : AbsRing.sort K, @eq (Ring.sort (AbsRing.Ring K)) (@mult (AbsRing.Ring K) n m) (@mult (AbsRing.Ring K) m n)) (_ : @filterdiff K U (AbsRing_NormedModule K) f (@locally (NormedModule.UniformSpace K U) x) lf) (_ : @filterdiff K U V g (@locally (NormedModule.UniformSpace K U) x) lg), @filterdiff K U V (fun t : NormedModule.sort K U => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (f t) (g t)) (@locally (NormedModule.UniformSpace K U) x) (fun t : NormedModule.sort K U => @plus (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (lf t) (g x)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (f x) (lg t))) *)
  intros Hcomm Df Dg.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply (filterdiff_comp'_2 f g scal x lf lg (fun k v => plus (scal k (g x)) (scal (f x) v))) => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply (filterdiff_scal (f x, g x)).
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_scal_fct x (f : U -> K) (g : U -> V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f (locally x) -> ex_filterdiff g (locally x) ->
  ex_filterdiff (fun t => scal (f t) (g t)) (locally x).
Proof.
  intros Hcomm [lf Df] [lg Dg].
  eexists.
  apply (filterdiff_scal_fct x) ; eassumption.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_scal_l_fct : forall {F} {FF : Filter F} (x : V) (f : U -> K) lf,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f F lf ->
  filterdiff (fun u => scal (f u) x) F (fun u => scal (lf u) x).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => F FF x f lf Df.
(* Goal: @filterdiff K U V (fun u : NormedModule.sort K U => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (f u) x) F (fun u : NormedModule.sort K U => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (lf u) x) *)
  apply (filterdiff_comp f (fun k => scal k x) lf (fun k => scal k x)).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @filterdiff K V V (fun x : NormedModule.sort K V => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x) (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f F) (fun x : NormedModule.sort K V => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x) *)
  apply filterdiff_linear.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_scal_l.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_scal_l_fct : forall {F} {FF : Filter F} (x : V) (f : U -> K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f F ->
  ex_filterdiff (fun u => scal (f u) x) F.
Proof.
  intros F FF x f [lf Df].
  eexists.
  apply (filterdiff_scal_l_fct x) ; eassumption.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma filterdiff_scal_r_fct : forall {F} {FF : Filter F} (k : K) (f lf : U -> V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f F lf ->
  filterdiff (fun x => scal k (f x)) F (fun x => scal k (lf x)).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => F FF k f lf Hcomm Df.
(* Goal: @filterdiff K U V (fun x : NormedModule.sort K U => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k (f x)) F (fun x : NormedModule.sort K U => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k (lf x)) *)
  apply (filterdiff_comp f (fun x => scal k x) lf (fun x => scal k x)).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @filterdiff K V V (fun x : NormedModule.sort K V => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x) (@filtermap (NormedModule.sort K U) (NormedModule.sort K V) f F) (fun x : NormedModule.sort K V => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x) *)
  apply filterdiff_linear.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_scal_r.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_filterdiff_scal_r_fct : forall {F} {FF : Filter F} (k : K) (f : U -> V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f F ->
  ex_filterdiff (fun x => scal k (f x)) F.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => F FF k f Hcomm [lf Df].
  eexists.
  apply (filterdiff_scal_r_fct k) ; eassumption.
Qed.

End Operations_fct.

Lemma filterdiff_mult_fct {K : AbsRing} {U : NormedModule K}
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (f g : U -> K) x (lf lg : U -> K) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  filterdiff f (locally x) lf -> filterdiff g (locally x) lg
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> filterdiff (fun t => mult (f t) (g t)) (locally x)
    (fun t => plus (mult (lf t) (g x)) (mult (f x) (lg t))).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply @filterdiff_scal_fct.
Qed.

Lemma ex_filterdiff_mult_fct {K : AbsRing} {U : NormedModule K}
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (f g : U -> K) x :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (n m : K), mult n m = mult m n) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_filterdiff f (locally x) -> ex_filterdiff g (locally x)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ex_filterdiff (fun t => mult (f t) (g t)) (locally x).
Proof.
  intros Hcomm [lf Df] [lg Dg].
  eexists.
  apply @filterdiff_mult_fct ; eassumption.
Qed.

(** * Differentiability in 1 dimentional space *)

Section Derive.

Context {K : AbsRing} {V : NormedModule K}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Definition is_derive (f : K -> V) (x : K) (l : V) :=
  filterdiff f (locally x) (fun y : K => scal y l).

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Definition ex_derive (f : K -> V) (x : K) :=
  exists l : V, is_derive f x l.

Lemma ex_derive_filterdiff :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : K -> V) (x : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x <-> ex_filterdiff f (locally x).
Proof.
(* Goal: forall (f : forall _ : R, R) (x : R), @eq R (Derive (fun x0 : R => Ropp (f x0)) x) (Ropp (Derive f x)) *)
intros f x.
split ; case => d Df.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
- eexists.
  exact Df.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
- exists (d one).
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
  apply is_linear_scal_l.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  simpl => t Ht.
  destruct Df as [Ld Df].
  simpl in Df.
  apply domin_rw_r with (2 := Df t Ht).
  apply equiv_ext_loc.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp with (2 := filter_true) => y /= _.
(* Goal: @eq R (Rmult (pow a n) (Derive (fun x : R => Derive_n f n (Rmult a x)) y)) (Rmult (pow a n) (Rmult a (Derive (Derive_n f n) (Rmult a y)))) *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -linear_scal //=.
  apply f_equal, sym_eq, mult_one_r.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_continuous (f : K -> V) (x : K) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> continuous f x.
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: @continuous (AbsRing_UniformSpace K) (NormedModule.UniformSpace K V) f x *)
  apply @filterdiff_continuous.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply ex_derive_filterdiff.
Qed.

End Derive.

(** * Definitions on [R] *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Definition Derive (f : R -> R) (x : R) := real (Lim (fun h => (f (x+h) - f x)/h) 0).

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_Reals (f : R -> R) (x l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x l <-> derivable_pt_lim f x l.
Proof.
  apply iff_sym.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  split => Hf.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  + split.
    apply @is_linear_scal_l.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
    simpl => y Hy eps.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite -(is_filter_lim_locally_unique _ _ Hy) ; clear y Hy.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
    case: (Hf eps (cond_pos _)) => {Hf} d Hf.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
    exists d => y /= Hy.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
    case: (Req_dec y x) => Hxy.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Hxy /norm /scal /= /abs /minus /plus /opp /mult /=.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    ring_simplify (f x + - f x + - ((x + - x) * l)).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    ring_simplify (x + - x).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rabs_R0 Rmult_0_r.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rle_refl.
    apply Rle_div_l.
    apply Rabs_pos_lt.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rminus_eq_contra.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite -Rabs_div.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    2: by apply Rminus_eq_contra.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite /scal /= /minus /plus /opp /mult /=.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    replace ((f y + - f x + - ((y + - x) * l)) / (y + - x))
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
      with ((f (x + (y-x)) - f x) / (y-x) - l).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    2: ring_simplify (x + (y - x)) ; field ; by apply Rminus_eq_contra.
    apply Rlt_le, Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rminus_eq_contra.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by [].
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  + move => e He.
    destruct Hf as [_ Hf].
    specialize (Hf x (fun P H => H)).
    destruct (Hf (pos_div_2 (mkposreal _ He))) as [delta Hd].
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
    exists delta => h Hh0 Hh.
    apply Rle_lt_trans with (e / 2).
    simpl in Hd.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    replace ((f (x + h) - f x) / h - l) with
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
      ((f (x + h) + - f x + - ((x + h + - x) * l)) / (x + h + - x)).
    2: by field.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rabs_div.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    2: by ring_simplify (x + h + - x).
    apply Rle_div_l.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    now ring_simplify (x + h + - x) ; apply Rabs_pos_lt.
(* Goal: @eq (NormedModule.sort K V) (f y) (g y) *)
    apply Hd.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite /ball /= /AbsRing_ball /= /abs /minus /plus /opp /=.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    by ring_simplify (x + h + - x).
    apply Rlt_div_l, Rminus_lt_0 ; ring_simplify.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply Rlt_0_2.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by [].
Qed.

(** Derive is correct *)

Lemma is_derive_unique f x l :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x l -> Derive f x = l.
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (j : I) (k : nat) (_ : @List.In I j l) (_ : le k n), ex_derive_n (f j) k y), @eq R (Derive_n (fun y : R => @iter I R Rplus (IZR Z0) l (fun j : I => f j y)) n x) (@iter I R Rplus (IZR Z0) l (fun j : I => Derive_n (f j) n x)) *)
  intros H.
(* Goal: @eq R (Derive f x) l *)
  apply (@f_equal _ _ real _ l).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus x h)) (f x)) h) (Finite (IZR Z0))) (Finite l) *)
  apply is_lim_unique.
(* Goal: is_lim (fun h : R => Rdiv (Rminus (f (Rplus x h)) (f x)) h) (Finite (IZR Z0)) (Finite l) *)
  apply is_lim_spec.
(* Goal: is_lim' (fun h : R => Rdiv (Rminus (f (Rplus x h)) (f x)) h) (Finite (IZR Z0)) (Finite l) *)
  apply is_derive_Reals in H.
(* Goal: is_lim' (fun h : R => Rdiv (Rminus (f (Rplus x h)) (f x)) h) (Finite (IZR Z0)) (Finite l) *)
  intros eps.
(* Goal: Rbar_locally' (Finite (IZR Z0)) (fun y : R => Rlt (Rabs (Rminus (Rdiv (Rminus (f (Rplus x y)) (f x)) y) l)) (pos eps)) *)
  destruct (H eps (cond_pos _)) as [d Hd].
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  exists d => h.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /ball /= /AbsRing_ball /= /minus /plus /opp /= Ropp_0 Rplus_0_r.
(* Goal: forall (_ : Rlt (@abs R_AbsRing h) (pos d)) (_ : not (@eq R h (IZR Z0))), Rlt (Rabs (Rminus (Rdiv (Rminus (f (Rplus x h)) (f x)) h) l)) (pos eps) *)
  intros Hu Zu.
(* Goal: @eq (NormedModule.sort K V) (f y) (g y) *)
  now apply Hd.
Qed.

Lemma Derive_correct f x :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> is_derive f x (Derive f x).
Proof.
(* Goal: forall _ : @ex_derive R_AbsRing R_NormedModule f x, @is_derive R_AbsRing R_NormedModule f x (Derive f x) *)
    intros (l,H).
(* Goal: @is_derive R_AbsRing R_NormedModule f x (Derive f x) *)
  cut (Derive f x = l).
(* Goal: forall _ : @eq R (Derive f x) l, @is_derive R_AbsRing R_NormedModule f x (Derive f x) *)
(* Goal: @eq R (Derive f x) l *)
    intros ; rewrite H0 ; apply H.
(* Goal: @eq R (Derive f x) l *)
  apply is_derive_unique, H.
Qed.

(** Equivalence with standard library Reals *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_Reals_0 (f : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> derivable_pt f x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf.
(* Goal: derivable_pt f x *)
  apply Derive_correct in Hf.
(* Goal: derivable_pt f x *)
  apply is_derive_Reals in Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by exists (Derive f x).
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_Reals_1 (f : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  derivable_pt f x -> ex_derive f x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case => l Hf.
(* Goal: @ex_derive K V g x *)
  exists l.
(* Goal: derivable_pt_lim f x l *)
(* Goal: derivable_pt_lim (fun x : R => pow x n) (f x) (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) *)
  now apply is_derive_Reals.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_Reals (f : R -> R) (x : R) (pr : derivable_pt f x) :
  derive_pt f x pr = Derive f x.
Proof.
(* Goal: @eq R (derive_pt f x pr) (Derive f x) *)
  apply sym_eq, is_derive_unique.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: pr => /= l Hf.
(* Goal: derivable_pt_lim f x l *)
(* Goal: derivable_pt_lim (fun x : R => pow x n) (f x) (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) *)
  now apply is_derive_Reals.
Qed.

(** Extensionality *)

Section Extensionality.

Context {K : AbsRing} {V : NormedModule K}.

Lemma is_derive_ext_loc :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : K -> V) (x : K) (l : V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t : K => f t = g t) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x l -> is_derive g x l.
Proof.
(* Goal: forall (f g : forall _ : AbsRing.sort K, NormedModule.sort K V) (x : AbsRing.sort K) (l : NormedModule.sort K V) (_ : forall t : AbsRing.sort K, @eq (NormedModule.sort K V) (f t) (g t)) (_ : @is_derive K V f x l), @is_derive K V g x l *)
intros f g x l Heq Hf.
(* Goal: @is_derive K V g x l *)
now apply (filterdiff_ext_locally f g _ _ Heq).
Qed.

Lemma ex_derive_ext_loc :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : K -> V) (x : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t : K => f t = g t) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive g x.
Proof.
(* Goal: forall (f g : forall _ : AbsRing.sort K, NormedModule.sort K V) (x : AbsRing.sort K) (_ : @locally (AbsRing_UniformSpace K) x (fun t : AbsRing.sort K => @eq (NormedModule.sort K V) (f t) (g t))) (_ : @ex_derive K V f x), @ex_derive K V g x *)
intros f g x Hfg (l,Hf).
(* Goal: @ex_derive K V g x *)
exists l.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
apply: is_derive_ext_loc Hfg Hf.
Qed.

Lemma is_derive_ext :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : K -> V) (x : K) (l : V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall t : K, f t = g t) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x l -> is_derive g x l.
Proof.
(* Goal: forall (f g : forall _ : AbsRing.sort K, NormedModule.sort K V) (x : AbsRing.sort K) (l : NormedModule.sort K V) (_ : forall t : AbsRing.sort K, @eq (NormedModule.sort K V) (f t) (g t)) (_ : @is_derive K V f x l), @is_derive K V g x l *)
intros f g x l Heq Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
apply: filterdiff_ext_locally Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by apply filter_forall.
Qed.

Lemma ex_derive_ext :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : K -> V) (x : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall t : K, f t = g t) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive g x.
Proof.
(* Goal: forall (f g : forall _ : AbsRing.sort K, NormedModule.sort K V) (x : AbsRing.sort K) (_ : forall t : AbsRing.sort K, @eq (NormedModule.sort K V) (f t) (g t)) (_ : @ex_derive K V f x), @ex_derive K V g x *)
intros f g x Heq [l Hf].
(* Goal: @ex_derive K V g x *)
exists l ; move: Hf ; by apply is_derive_ext.
Qed.

End Extensionality.

Lemma Derive_ext_loc :
  forall f g x,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => f t = g t) ->
  Derive f x = Derive g x.
Proof.
(* Goal: forall (f g : forall _ : R, R) (x : R) (_ : forall t : R, @eq R (f t) (g t)), @eq R (Derive f x) (Derive g x) *)
intros f g x Hfg.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite /Derive /Lim.
(* Goal: @eq R (real (Lim_seq (fun n : nat => Rdiv (Rminus (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n))) (f x)) (Rbar_loc_seq (Finite (IZR Z0)) n)))) (real (Lim_seq (fun n : nat => Rdiv (Rminus (g (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n))) (g x)) (Rbar_loc_seq (Finite (IZR Z0)) n)))) *)
apply f_equal, Lim_seq_ext_loc.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
apply (filterlim_Rbar_loc_seq 0 (fun h => (f (x + h) - f x) / h = (g (x + h) - g x) / h)).
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
apply (filter_imp (fun h => f (x + h) = g (x + h))).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
intros h ->.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by rewrite (locally_singleton _ _ Hfg).
(* Goal: Rbar_locally' (Finite (IZR Z0)) (fun h : R => @eq R (f (Rplus x h)) (g (Rplus x h))) *)
destruct Hfg as [eps He].
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
exists eps => h H Hh.
(* Goal: @eq R (f (Rplus x h)) (g (Rplus x h)) *)
apply He.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite /ball /= /AbsRing_ball /= /minus /plus /opp /=.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
now replace (x + h + - x) with (h - 0) by ring.
Qed.

Lemma Derive_ext :
  forall f g x,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall t, f t = g t) ->
  Derive f x = Derive g x.
Proof.
(* Goal: forall (f g : forall _ : R, R) (x : R) (_ : forall t : R, @eq R (f t) (g t)), @eq R (Derive f x) (Derive g x) *)
intros f g x Hfg.
(* Goal: @eq R (Derive (Derive_n (fun x : R => Rplus (f x) (g x)) n) x) (Derive (fun x : R => Rplus (Derive_n f n x) (Derive_n g n x)) x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
apply Derive_ext_loc.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by apply filter_forall.
Qed.

(** * Operations *)
(** Constant functions *)

Section Const.

Context {K : AbsRing} {V : NormedModule K}.

Lemma is_derive_const :
  forall (a : V) (x : K), is_derive (fun _ : K => a) x zero.
Proof.
(* Goal: forall a x : R, @eq R (Derive (fun _ : R => a) x) (IZR Z0) *)
intros a x.
(* Goal: @is_derive K V (fun _ : AbsRing.sort K => a) x (@zero (NormedModule.AbelianGroup K V)) *)
apply filterdiff_ext_lin with (fun y : K => zero).
(* Goal: @filterdiff K (AbsRing_NormedModule K) V (fun _ : AbsRing.sort K => a) (@locally (AbsRing_UniformSpace K) x) (fun _ : AbsRing.sort K => @zero (NormedModule.AbelianGroup K V)) *)
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@zero (NormedModule.AbelianGroup K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@zero (NormedModule.AbelianGroup K V))) *)
apply filterdiff_const.
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
intros y.
(* Goal: @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
apply sym_eq.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
apply: scal_zero_r.
Qed.

Lemma ex_derive_const :
  forall (a : V) (x : K), ex_derive (fun _ => a) x.
Proof.
(* Goal: forall a x : R, @eq R (Derive (fun _ : R => a) x) (IZR Z0) *)
intros a x.
eexists.
apply is_derive_const.
Qed.

End Const.

Lemma Derive_const :
  forall (a x : R),
  Derive (fun _ => a) x = 0.
Proof.
(* Goal: forall a x : R, @eq R (Derive (fun _ : R => a) x) (IZR Z0) *)
intros a x.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
apply is_derive_unique.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
apply: is_derive_const.
Qed.

(** Identity function *)

Section Id.

Context {K : AbsRing}.

Lemma is_derive_id :
  forall x : K, is_derive (fun t : K => t) x one.
Proof.
(* Goal: forall x : R, @eq R (Derive (Derive_n (Derive_n f m) n) x) (Derive (Derive_n f (Init.Nat.add n m)) x) *)
intros x.
(* Goal: @is_derive K (AbsRing_NormedModule K) (fun t : AbsRing.sort K => t) x (@one (AbsRing.Ring K)) *)
apply filterdiff_ext_lin with (fun t : K => t).
(* Goal: @filterdiff K (AbsRing_NormedModule K) (AbsRing_NormedModule K) (fun t : AbsRing.sort K => t) (@locally (AbsRing_UniformSpace K) x) (fun t : AbsRing.sort K => t) *)
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K (AbsRing_NormedModule K)) y (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K (AbsRing_NormedModule K)) y (@one (AbsRing.Ring K))) *)
apply filterdiff_id.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite /scal /=.
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
intros y.
(* Goal: @eq (AbsRing.sort K) y (@mult (AbsRing.Ring K) y (@one (AbsRing.Ring K))) *)
apply sym_eq, mult_one_r.
Qed.

Lemma ex_derive_id :
  forall x : K, ex_derive (fun t : K => t) x.
Proof.
(* Goal: forall x : R, @eq R (Derive (Derive_n (Derive_n f m) n) x) (Derive (Derive_n f (Init.Nat.add n m)) x) *)
intros x.
eexists.
apply is_derive_id.
Qed.

End Id.

Lemma Derive_id :
  forall x,
  Derive id x = 1.
Proof.
(* Goal: forall x : R, @eq R (Derive (Derive_n (Derive_n f m) n) x) (Derive (Derive_n f (Init.Nat.add n m)) x) *)
intros x.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
apply is_derive_unique.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
apply: is_derive_id.
Qed.

(** ** Additive operators *)
(** Opposite of functions *)

Section Opp.

Context {K : AbsRing} {V : NormedModule K}.

Lemma is_derive_opp :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : K -> V) (x : K) (l : V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x l ->
  is_derive (fun x => opp (f x)) x (opp l).
Proof.
(* Goal: forall (f : forall _ : AbsRing.sort K, NormedModule.sort K V) (x : AbsRing.sort K) (l : NormedModule.sort K V) (_ : @is_derive K V f x l), @is_derive K V (fun x0 : AbsRing.sort K => @opp (NormedModule.AbelianGroup K V) (f x0)) x (@opp (NormedModule.AbelianGroup K V) l) *)
intros f x l Df.
(* Goal: @is_derive K V (fun x : AbsRing.sort K => @opp (NormedModule.AbelianGroup K V) (f x)) x (@opp (NormedModule.AbelianGroup K V) l) *)
apply filterdiff_ext_lin with (fun t : K => opp (scal t l)).
(* Goal: @filterdiff K (AbsRing_NormedModule K) V (fun x : AbsRing.sort K => @opp (NormedModule.AbelianGroup K V) (f x)) (@locally (AbsRing_UniformSpace K) x) (fun t : AbsRing.sort K => @opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) t l)) *)
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
apply filterdiff_comp' with (1 := Df).
(* Goal: @filterdiff K V V (@opp (NormedModule.AbelianGroup K V)) (@locally (NormedModule.UniformSpace K V) (f x)) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V))) *)
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
apply filterdiff_opp.
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
intros y.
(* Goal: @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
apply sym_eq.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
apply: scal_opp_r.
Qed.

Lemma ex_derive_opp :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : K -> V) (x : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x ->
  ex_derive (fun x => opp (f x)) x.
Proof.
intros f x [df Df].
eexists.
apply is_derive_opp.
exact Df.
Qed.

End Opp.

Lemma Derive_opp :
  forall f x,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  Derive (fun x => - f x) x = - Derive f x.
Proof.
(* Goal: forall (f : forall _ : R, R) (x : R), @eq R (Derive (fun x0 : R => Ropp (f x0)) x) (Ropp (Derive f x)) *)
intros f x.
(* Goal: @eq R (Derive (fun x : R => Rmult k (f x)) x) (Rmult k (Derive f x)) *)
unfold Derive, Lim.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite /Rbar_loc_seq.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -Rbar.Rbar_opp_real.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -Lim_seq_opp.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
apply f_equal, Lim_seq_ext => n.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -Ropp_mult_distr_l_reverse.
(* Goal: @eq R (Rdiv (Rminus (Rmult k (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n)))) (Rmult k (f x))) (Rbar_loc_seq (Finite (IZR Z0)) n)) (Rmult (Rmult k (Rminus (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n))) (f x))) (Rinv (Rbar_loc_seq (Finite (IZR Z0)) n))) *)
apply (f_equal (fun v => v / _)).
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
ring.
Qed.

(** Addition of functions *)

Section Plus.

Context {K : AbsRing} {V : NormedModule K}.

Lemma is_derive_plus :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : K -> V) (x : K) (df dg : V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x df ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive g x dg ->
  is_derive (fun x => plus (f x) (g x)) x (plus df dg).
Proof.
intros f g x df dg Df Dg.
eapply filterdiff_ext_lin.
apply filterdiff_plus_fct ; try eassumption.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
simpl => y.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by rewrite scal_distr_l.
Qed.

Lemma ex_derive_plus :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : K -> V) (x : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive g x ->
  ex_derive (fun x => plus (f x) (g x)) x.
Proof.
(* Goal: forall (f : forall _ : AbsRing.sort K, NormedModule.sort K V) (g : forall _ : AbsRing.sort K, AbsRing.sort K) (x : AbsRing.sort K) (_ : @ex_derive K V f (g x)) (_ : @ex_derive K (AbsRing_NormedModule K) g x), @ex_derive K V (fun x0 : AbsRing.sort K => f (g x0)) x *)
intros f g x [df Df] [dg Dg].
(* Goal: @ex_derive K V (fun x : AbsRing.sort K => @plus (NormedModule.AbelianGroup K V) (f x) (g x)) x *)
exists (plus df dg).
(* Goal: @is_derive K V (fun x : AbsRing.sort K => @plus (NormedModule.AbelianGroup K V) (f x) (g x)) x (@plus (NormedModule.AbelianGroup K V) df dg) *)
now apply is_derive_plus.
Qed.

Lemma is_derive_sum_n :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : nat -> K -> V) (n : nat) (x : K) (d : nat -> V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall k, (k <= n)%nat -> is_derive (f k) x (d k)) ->
  is_derive (fun y => sum_n (fun k => f k y) n) x (sum_n d n).
Proof.
  intros f n x d.
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n => /= [ | n IH] Hf.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite sum_O.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  eapply is_derive_ext, (Hf O) => //.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  intros t ; by rewrite sum_O.
  eapply is_derive_ext.
  intros t ; apply sym_eq, sum_Sn.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite sum_Sn.
  apply is_derive_plus.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply IH => k Hk.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Hf, le_trans with (1 := Hk), le_n_Sn.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  by apply Hf.
Qed.

Lemma ex_derive_sum_n :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : nat -> K -> V) (n : nat) (x : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall k, (k <= n)%nat -> ex_derive (f k) x) ->
  ex_derive (fun y => sum_n (fun k => f k y) n) x.
Proof.
  intros f n x.
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n => /= [ | n IH] Hf.
  eapply ex_derive_ext.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  intros t ; by rewrite sum_O.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply (Hf O).
  eapply ex_derive_ext.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  intros t ; by rewrite sum_Sn.
  apply ex_derive_plus.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply IH => k Hk.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Hf, le_trans with (1 := Hk), le_n_Sn.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  by apply Hf.
Qed.

End Plus.

Lemma Derive_plus :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall f g x, ex_derive f x -> ex_derive g x ->
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  Derive (fun x => f x + g x) x = Derive f x + Derive g x.
Proof.
(* Goal: forall (f g : forall _ : AbsRing.sort R_AbsRing, NormedModule.sort R_AbsRing R_NormedModule) (x : AbsRing.sort R_AbsRing) (_ : @ex_derive R_AbsRing R_NormedModule f x) (_ : @ex_derive R_AbsRing R_NormedModule g x), @eq R (Derive (fun x0 : R => Rminus (f x0) (g x0)) x) (Rminus (Derive f x) (Derive g x)) *)
intros f g x Df Dg.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
apply is_derive_unique.
apply: is_derive_plus ;
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x (Derive_n (fun y : R => f (Rmult a y)) (S n) x) *)
  now apply Derive_correct.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_sum_n (f : nat -> R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall k, (k <= n)%nat -> ex_derive (f k) x) ->
  Derive (fun y => sum_n (fun k => f k y) n) x = sum_n (fun k => Derive (f k) x) n.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  apply is_derive_unique.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply: is_derive_sum_n.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => k Hk.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Derive_correct, Hf.
Qed.

(** Difference of functions *)

Section Minus.

Context {K : AbsRing} {V : NormedModule K}.

Lemma is_derive_minus :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : K -> V) (x : K) (df dg : V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x df ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive g x dg ->
  is_derive (fun x => minus (f x) (g x)) x (minus df dg).
Proof.
intros f g x df dg Df Dg.
eapply filterdiff_ext_lin.
apply filterdiff_minus_fct ; try eassumption.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
simpl => y.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by rewrite scal_distr_l scal_opp_r.
Qed.

Lemma ex_derive_minus :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : K -> V) (x : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive g x ->
  ex_derive (fun x => minus (f x) (g x)) x.
Proof.
(* Goal: forall (f : forall _ : AbsRing.sort K, NormedModule.sort K V) (g : forall _ : AbsRing.sort K, AbsRing.sort K) (x : AbsRing.sort K) (_ : @ex_derive K V f (g x)) (_ : @ex_derive K (AbsRing_NormedModule K) g x), @ex_derive K V (fun x0 : AbsRing.sort K => f (g x0)) x *)
intros f g x [df Df] [dg Dg].
(* Goal: @ex_derive K V (fun x : AbsRing.sort K => @minus (NormedModule.AbelianGroup K V) (f x) (g x)) x *)
exists (minus df dg).
(* Goal: @is_derive K V (fun x : AbsRing.sort K => @minus (NormedModule.AbelianGroup K V) (f x) (g x)) x (@minus (NormedModule.AbelianGroup K V) df dg) *)
now apply is_derive_minus.
Qed.

End Minus.

Lemma Derive_minus :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall f g x, ex_derive f x -> ex_derive g x ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  Derive (fun x => f x - g x) x = Derive f x - Derive g x.
Proof.
(* Goal: forall (f g : forall _ : AbsRing.sort R_AbsRing, NormedModule.sort R_AbsRing R_NormedModule) (x : AbsRing.sort R_AbsRing) (_ : @ex_derive R_AbsRing R_NormedModule f x) (_ : @ex_derive R_AbsRing R_NormedModule g x), @eq R (Derive (fun x0 : R => Rminus (f x0) (g x0)) x) (Rminus (Derive f x) (Derive g x)) *)
intros f g x Df Dg.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
apply is_derive_unique.
apply: is_derive_minus ;
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x (Derive_n (fun y : R => f (Rmult a y)) (S n) x) *)
  now apply Derive_correct.
Qed.

(** ** Multiplicative operators *)
(** Multiplication of functions *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_inv (f : R -> R) (x l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x l -> f x <> 0
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> is_derive (fun y : R => / f y) x (-l/(f x)^2).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf Hl.
  eapply filterdiff_ext_lin.
  apply filterdiff_ext with (fun y => 1/f y).
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
(* Goal: is_derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => t ; by rewrite /Rdiv Rmult_1_l.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => pow (f x) n) x (Rmult (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) l) *)
  apply is_derive_Reals.
  apply derivable_pt_lim_div.
  apply derivable_pt_lim_const.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => pow (f x) n) x (Rmult (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) l) *)
  apply is_derive_Reals.
  exact Hf.
(* Goal: @is_linear K U V l *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K U)) (_ : @is_filter_lim (NormedModule.UniformSpace K U) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K U)) K K U V F (fun y : NormedModule.sort K U => @minus (NormedModule.AbelianGroup K U) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K U) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f y) (f x)) (l (@minus (NormedModule.AbelianGroup K U) y x))) *)
  exact Hl.
(* Goal: @eq R (Rmult (pow a n) (Derive (fun x : R => Derive_n f n (Rmult a x)) y)) (Rmult (pow a n) (Rmult a (Derive (Derive_n f n) (Rmult a y)))) *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  simpl => y ; apply f_equal.
  rewrite /= /Rsqr ; by field.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_inv (f : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> f x <> 0
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> ex_derive (fun y : R => / f y) x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case => l Hf Hl.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  exists (-l/(f x)^2).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_derive_inv.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_inv (f : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> f x <> 0
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> Derive (fun y => / f y) x = - Derive f x / (f x) ^ 2.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move/Derive_correct => Hf Hl.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  apply is_derive_unique.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_derive_inv.
Qed.

Lemma is_derive_scal :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : R -> R) (x k df : R),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x df ->
  is_derive (fun x : R => k * f x) x (k * df).
Proof.
intros f x k df Df.
change Rmult with (scal (V := R_NormedModule)).
eapply filterdiff_ext_lin.
apply filterdiff_scal_r_fct with (2 := Df).
apply Rmult_comm.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
rewrite /scal /= /mult /= => y.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
ring.
Qed.

Lemma ex_derive_scal :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : R -> R) (k x : R),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x ->
  ex_derive (fun x : R => k * f x) x.
Proof.
(* Goal: forall (f : forall _ : R, R) (k x : R) (_ : @ex_derive R_AbsRing R_NormedModule f x), @ex_derive R_AbsRing R_NormedModule (fun x0 : R => Rmult k (f x0)) x *)
intros f k x (df,Df).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult k (f x)) x *)
exists (k * df).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Rmult k (f x)) x (Rmult k df) *)
now apply is_derive_scal.
Qed.

Lemma Derive_scal :
  forall f k x,
  Derive (fun x => k * f x) x = k * Derive f x.
Proof.
(* Goal: forall (f : forall _ : R, R) (k x : R), @eq R (Derive (fun x0 : R => Rmult k (f x0)) x) (Rmult k (Derive f x)) *)
intros f k x.
(* Goal: @eq R (Derive (fun x : R => Rmult k (f x)) x) (Rmult k (Derive f x)) *)
unfold Derive, Lim.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
have H : (forall x, k * Rbar.real x = Rbar.real (Rbar.Rbar_mult (Rbar.Finite k) x)).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  case: (Req_dec k 0) => [-> | Hk].
(* Goal: forall x : Rbar, @eq R (Rmult k (real x)) (real (Rbar_mult (Finite k) x)) *)
(* Goal: @eq R (real (Lim_seq (fun n : nat => Rdiv (Rminus (Rmult k (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n)))) (Rmult k (f x))) (Rbar_loc_seq (Finite (IZR Z0)) n)))) (Rmult k (real (Lim_seq (fun n : nat => Rdiv (Rminus (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n))) (f x)) (Rbar_loc_seq (Finite (IZR Z0)) n))))) *)
  case => [l | | ] //= ; rewrite Rmult_0_l.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_dec (Rle_refl 0) => //= H _.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_lt_or_eq_dec (Rlt_irrefl 0) => //= _ _.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_dec (Rle_refl 0) => //= H _.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_lt_or_eq_dec (Rlt_irrefl 0) => //= _ _.
(* Goal: forall x : Rbar, @eq R (Rmult k (real x)) (real (Rbar_mult (Finite k) x)) *)
(* Goal: @eq R (real (Lim_seq (fun n : nat => Rdiv (Rminus (Rmult k (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n)))) (Rmult k (f x))) (Rbar_loc_seq (Finite (IZR Z0)) n)))) (Rmult k (real (Lim_seq (fun n : nat => Rdiv (Rminus (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n))) (f x)) (Rbar_loc_seq (Finite (IZR Z0)) n))))) *)
  case => [l | | ] //= ; rewrite Rmult_0_r.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_dec => //= H.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_lt_or_eq_dec => //=.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_dec => //= H.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_lt_or_eq_dec => //=.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite H.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -Lim_seq_scal_l.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
apply f_equal, Lim_seq_ext => n.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -Rmult_assoc.
(* Goal: @eq R (Rdiv (Rminus (Rmult k (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n)))) (Rmult k (f x))) (Rbar_loc_seq (Finite (IZR Z0)) n)) (Rmult (Rmult k (Rminus (f (Rplus x (Rbar_loc_seq (Finite (IZR Z0)) n))) (f x))) (Rinv (Rbar_loc_seq (Finite (IZR Z0)) n))) *)
apply (f_equal (fun v => v / _)).
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
ring.
Qed.

Section Scal_l.

Context {K : AbsRing} {V : NormedModule K}.

Lemma is_derive_scal_l :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : K -> K) (x l : K) (k : V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x l ->
  is_derive (fun x => scal (f x) k) x (scal l k).
Proof.
  intros f x l k Df.
  eapply filterdiff_ext_lin.
  apply @filterdiff_scal_l_fct ; try by apply locally_filter.
  exact Df.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  simpl => y.
  apply sym_eq, scal_assoc.
Qed.

Lemma ex_derive_scal_l :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : K -> K) (x : K) (k : V),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x ->
  ex_derive (fun x => scal (f x) k) x.
Proof.
(* Goal: forall (f : forall _ : AbsRing.sort K, AbsRing.sort K) (x : AbsRing.sort K) (k : NormedModule.sort K V) (_ : @ex_derive K (AbsRing_NormedModule K) f x), @ex_derive K V (fun x0 : AbsRing.sort K => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (f x0) k) x *)
  intros f x k [df Df].
(* Goal: @ex_derive K V (fun x : AbsRing.sort K => @scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) (f x) k) x *)
  exists (scal df k).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_derive_scal_l.
Qed.

End Scal_l.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_scal_l (f : R -> R) (k x : R) :
  Derive (fun x => f x * k) x = Derive f x * k.
Proof.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite Rmult_comm -Derive_scal.
  apply Derive_ext => t ; by apply Rmult_comm.
Qed.

Lemma is_derive_mult :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : R -> R) (x : R) (df dg : R),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x df ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive g x dg ->
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  is_derive (fun t : R => f t * g t) x (df * g x + f x * dg) .
Proof.
intros f g x df dg Df Dg.
eapply filterdiff_ext_lin.
apply @filterdiff_mult_fct with (2 := Df) (3 := Dg).
exact Rmult_comm.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
rewrite /scal /= /mult /plus /= => y.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
ring.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_mult (f g : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive g x
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> ex_derive (fun x : R => f x * g x) x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => [d1 H1] [d2 H2].
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  exists (d1 * g x + f x * d2).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Rmult (f x) (g x)) x (Rplus (Rmult d1 (g x)) (Rmult (f x) d2)) *)
  now apply is_derive_mult.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_mult (f g : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive g x
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> Derive (fun x => f x * g x) x = Derive f x * g x + f x * Derive g x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => H1 H2.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  apply is_derive_unique.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Rmult (f x) (g x)) x (Rplus (Rmult (Derive f x) (g x)) (Rmult (f x) (Derive g x))) *)
  now apply is_derive_mult ; apply Derive_correct.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_pow (f : R -> R) (n : nat) (x : R) (l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x l -> is_derive (fun x : R => (f x)^n) x (INR n * l * (f x)^(pred n)).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => H.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite (Rmult_comm _ l) Rmult_assoc Rmult_comm.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => pow (f x) n) x (Rmult (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) l) *)
  apply is_derive_Reals.
(* Goal: derivable_pt_lim (fun x : R => pow (f x) n) x (Rmult (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) l) *)
  apply (derivable_pt_lim_comp f (fun x => x^n)).
(* Goal: derivable_pt_lim f x l *)
(* Goal: derivable_pt_lim (fun x : R => pow x n) (f x) (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) *)
  now apply is_derive_Reals.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply derivable_pt_lim_pow.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_pow (f : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive (fun x : R => (f x)^n) x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case => l H.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => pow (f x) n) x *)
  exists (INR n * l * (f x)^(pred n)).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_derive_pow.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_pow (f : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> Derive (fun x => (f x)^n) x = (INR n * Derive f x * (f x)^(pred n)).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => H.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  apply is_derive_unique.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => pow (f x) n) x (Rmult (Rmult (INR n) (Derive f x)) (pow (f x) (Init.Nat.pred n))) *)
  apply is_derive_pow.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Derive_correct.
Qed.

Lemma is_derive_div :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f g : R -> R) (x : R) (df dg : R),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f x df ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive g x dg ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  g x <> 0 ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive (fun t : R => f t / g t) x ((df * g x - f x * dg) / (g x ^ 2)).
Proof.
intros f g x df dg Df Dg Zgx.
evar_last.
apply is_derive_mult.
exact Df.
apply is_derive_inv with (2 := Zgx).
exact Dg.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
simpl.
now field.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_div (f g : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive g x -> g x <> 0
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> ex_derive (fun y => f y / g y) x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf Hg Hl.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun y : AbsRing.sort R_AbsRing => Rdiv (f y) (g y)) x *)
  apply ex_derive_mult.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply ex_derive_inv.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_div (f g : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f x -> ex_derive g x -> g x <> 0
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> Derive (fun y => f y / g y) x = (Derive f x * g x - f x * Derive g x) / (g x) ^ 2.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf Hg Hl.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  apply is_derive_unique.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun y : R => Rdiv (f y) (g y)) x (Rdiv (Rminus (Rmult (Derive f x) (g x)) (Rmult (f x) (Derive g x))) (pow (g x) (S (S O)))) *)
  now apply is_derive_div ; try apply Derive_correct.
Qed.

(** Composition of functions *)

Section Comp.

Context {K : AbsRing} {V : NormedModule K}.

Lemma is_derive_comp :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : K -> V) (g : K -> K) (x : K) (df : V) (dg : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f (g x) df ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive g x dg ->
  is_derive (fun x => f (g x)) x (scal dg df).
Proof.
intros f g x df dg Df Dg.
eapply filterdiff_ext_lin.
apply filterdiff_comp' with (1 := Dg) (2 := Df).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
simpl => y.
apply sym_eq, scal_assoc.
Qed.

Lemma ex_derive_comp :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : K -> V) (g : K -> K) (x : K),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f (g x) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive g x ->
  ex_derive (fun x => f (g x)) x.
Proof.
(* Goal: forall (f : forall _ : AbsRing.sort K, NormedModule.sort K V) (g : forall _ : AbsRing.sort K, AbsRing.sort K) (x : AbsRing.sort K) (_ : @ex_derive K V f (g x)) (_ : @ex_derive K (AbsRing_NormedModule K) g x), @ex_derive K V (fun x0 : AbsRing.sort K => f (g x0)) x *)
intros f g x [df Df] [dg Dg].
(* Goal: @ex_derive K V (fun x : AbsRing.sort K => f (g x)) x *)
exists (scal dg df).
(* Goal: @is_derive K V (fun x : AbsRing.sort K => f (g x)) x (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) dg df) *)
now apply is_derive_comp.
Qed.

End Comp.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_comp (f g : R -> R) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive f (g x) -> ex_derive g x
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> Derive (fun x => f (g x)) x = Derive g x * Derive f (g x).
Proof.
(* Goal: forall (_ : @ex_derive R_AbsRing R_NormedModule f (g x)) (_ : @ex_derive R_AbsRing R_NormedModule g x), @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
intros Df Dg.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
apply is_derive_unique.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => f (g x)) x (Rmult (Derive g x) (Derive f (g x))) *)
apply: is_derive_comp ; now apply Derive_correct.
Qed.

(** * Mean value theorem *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma MVT_gen (f : R -> R) (a b : R) (df : R -> R) :
  let a0 := Rmin a b in
  let b0 := Rmax a b in
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall x, a0 < x < b0 -> is_derive f x (df x))
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> (forall x, a0 <= x <= b0 -> continuity_pt f x)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> exists c, a0 <= c <= b0 /\ f b - f a = df c * (b - a).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => a0 b0 Hd Hf.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (Req_dec a0 b0) => Hab.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  exists a0 ; split.
(* Goal: and (Rle a0 c) (Rle c b0) *)
(* Goal: @eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a)) *)
  split ; by apply Req_le.
(* Goal: and (@eq R (Rminus (f b) (f a)) (Rmult (df a) (Rminus b a))) (Rle (Rabs (Rminus a a)) (Rminus b a)) *)
  replace b with a.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  ring.
(* Goal: @eq R a b *)
(* Goal: @ex R (fun c : R => and (and (Rle a0 c) (Rle c b0)) (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a)))) *)
  move: Hab ; rewrite /a0 /b0 /Rmin /Rmax ; by case: Rle_dec => Hab.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  have pr1 : forall c:R, a0 < c < b0 -> derivable_pt f c.
(* Goal: forall (c : R) (_ : and (Rlt a0 c) (Rlt c b0)), derivable_pt f c *)
(* Goal: @ex R (fun c : R => and (and (Rle a0 c) (Rle c b0)) (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a)))) *)
    move => x Hx ; exists (df x).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply is_derive_Reals, Hd.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  have pr2 : forall c:R, a0 < c < b0 -> derivable_pt id c.
(* Goal: forall (c : R) (_ : and (Rlt a0 c) (Rlt c b0)), derivable_pt id c *)
(* Goal: @ex R (fun c : R => and (and (Rle a0 c) (Rle c b0)) (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a)))) *)
    move => x Hx ; exists 1.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply derivable_pt_lim_id.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (MVT f id a0 b0 pr1 pr2).
(* Goal: Rlt a0 b0 *)
(* Goal: forall (c : R) (_ : and (Rle a0 c) (Rle c b0)), continuity_pt f c *)
(* Goal: forall (c : R) (_ : and (Rle a0 c) (Rle c b0)), continuity_pt id c *)
(* Goal: forall (x : R) (_ : @ex (and (Rlt a0 x) (Rlt x b0)) (fun P : and (Rlt a0 x) (Rlt x b0) => @eq R (Rmult (Rminus (id b0) (id a0)) (derive_pt f x (pr1 x P))) (Rmult (Rminus (f b0) (f a0)) (derive_pt id x (pr2 x P))))), @ex R (fun c : R => and (and (Rle a0 c) (Rle c b0)) (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a)))) *)
  apply Rnot_le_lt ; contradict Hab ; apply Rle_antisym.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rcomplements.Rmin_Rmax.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Hab.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  by apply Hf.
(* Goal: forall (c : R) (_ : and (Rle a0 c) (Rle c b0)), continuity_pt id c *)
(* Goal: forall (x : R) (_ : @ex (and (Rlt a0 x) (Rlt x b0)) (fun P : and (Rlt a0 x) (Rlt x b0) => @eq R (Rmult (Rminus (id b0) (id a0)) (derive_pt f x (pr1 x P))) (Rmult (Rminus (f b0) (f a0)) (derive_pt id x (pr2 x P))))), @ex R (fun c : R => and (and (Rle a0 c) (Rle c b0)) (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a)))) *)
  move => x Hx ; apply derivable_continuous, derivable_id.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => /= c [Hc H].
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  exists c ; split.
(* Goal: and (Rle a0 c) (Rle c b0) *)
(* Goal: @eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a)) *)
  split ; by apply Rlt_le, Hc.
(* Goal: @eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a)) *)
  replace (df c) with (derive_pt f c (pr1 c Hc)).
  move: H ; rewrite {1 2}/id /a0 /b0 /Rmin /Rmax ;
  case: Rle_dec => Hab0 H.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite Rmult_comm H -(pr_nu _ _ (derivable_pt_id _)) derive_pt_id.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  ring.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  replace (derive_pt f c (pr1 c Hc) * (b - a))
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    with (-((a - b) * derive_pt f c (pr1 c Hc)))
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
    by ring.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite H -(pr_nu _ _ (derivable_pt_id _)) derive_pt_id.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  ring.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (pr1 c Hc) => /= l Hl.
(* Goal: @eq R l (df c) *)
  transitivity (Derive f c).
(* Goal: @eq R l (Derive f c) *)
(* Goal: @eq R (Derive f c) (df c) *)
  apply sym_eq, is_derive_unique, is_derive_Reals, Hl.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_derive_unique, Hd.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma incr_function (f : R -> R) (a b : Rbar) (df : R -> R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (x : R), Rbar_lt a x -> Rbar_lt x b -> is_derive f x (df x))
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ((forall (x : R), Rbar_lt a x -> Rbar_lt x b -> df x > 0)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> (forall (x y : R), Rbar_lt a x -> x < y -> Rbar_lt y b -> f x < f y)).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Df Hf x y Hax Hxy Hyb.
(* Goal: Rlt (f x) (f y) *)
  apply Rminus_lt_0.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  case: (MVT_gen f x y df) => [z Hz | z Hz | c [Hc ->]].
(* Goal: @is_derive R_AbsRing R_NormedModule f z (df z) *)
(* Goal: continuity_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Df.
(* Goal: Rbar_lt a (Finite z) *)
(* Goal: Rbar_lt (Finite z) b *)
(* Goal: continuity_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rbar_lt_le_trans with (y := Rmin x y) (2 := Rlt_le _ _ (proj1 Hz)).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmin ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: Rbar_lt (Finite z) b *)
(* Goal: continuity_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rbar_le_lt_trans with (y := Rmax x y) (1 := Rlt_le _ _ (proj2 Hz)).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmax ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: continuity_pt h x *)
(* Goal: forall (_ : @eq R x b) (_ : Rlt a x), continuity_pt h x *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
  apply derivable_continuous_pt.
(* Goal: derivable_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  exists (df z) ; apply is_derive_Reals, Df.
(* Goal: Rbar_lt a (Finite z) *)
(* Goal: Rbar_lt (Finite z) b *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rbar_lt_le_trans with (y := Rmin x y) (2 := proj1 Hz).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmin ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: Rbar_lt (Finite z) b *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rbar_le_lt_trans with (y := Rmax x y) (1 := proj2 Hz).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmax ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rmult_lt_0_compat.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Hf.
(* Goal: Rbar_lt a (Finite c) *)
(* Goal: Rbar_lt (Finite c) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  apply Rbar_lt_le_trans with (y := Rmin x y) (2 := proj1 Hc).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmin ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: Rbar_lt (Finite c) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  apply Rbar_le_lt_trans with (y := Rmax x y) (1 := proj2 Hc).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmax ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by apply -> Rminus_lt_0.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma incr_function_le (f : R -> R) (a b : Rbar) (df : R -> R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall (x : R), Rbar_le a x -> Rbar_le x b -> is_derive f x (df x))
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ((forall (x : R), Rbar_le a x -> Rbar_le x b -> df x > 0)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    -> (forall (x y : R), Rbar_le a x -> x < y -> Rbar_le y b -> f x < f y)).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Df Hf x y Hax Hxy Hyb.
(* Goal: Rlt (f x) (f y) *)
  apply Rminus_lt_0.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  case: (MVT_gen f x y df) => [z Hz | z Hz | c [Hc ->]].
(* Goal: @is_derive R_AbsRing R_NormedModule f z (df z) *)
(* Goal: continuity_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Df.
(* Goal: Rbar_le a (Finite z) *)
(* Goal: Rbar_le (Finite z) b *)
(* Goal: continuity_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rbar_le_trans with (y := Rmin x y) (2 := Rlt_le _ _ (proj1 Hz)).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmin ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: Rbar_le (Finite z) b *)
(* Goal: continuity_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rbar_le_trans with (y := Rmax x y) (1 := Rlt_le _ _ (proj2 Hz)).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmax ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: continuity_pt h x *)
(* Goal: forall (_ : @eq R x b) (_ : Rlt a x), continuity_pt h x *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
  apply derivable_continuous_pt.
(* Goal: derivable_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  exists (df z) ; apply is_derive_Reals, Df.
(* Goal: Rbar_le a (Finite z) *)
(* Goal: Rbar_le (Finite z) b *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rbar_le_trans with (y := Rmin x y) (2 := proj1 Hz).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmin ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: Rbar_le (Finite z) b *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rbar_le_trans with (y := Rmax x y) (1 := proj2 Hz).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmax ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Rmult_lt_0_compat.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Hf.
(* Goal: Rbar_le a (Finite c) *)
(* Goal: Rbar_le (Finite c) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  apply Rbar_le_trans with (y := Rmin x y) (2 := proj1 Hc).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmin ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: Rbar_le (Finite c) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  apply Rbar_le_trans with (y := Rmax x y) (1 := proj2 Hc).
(* Goal: Rbar_le (Finite (Rmax x y)) b *)
(* Goal: Rlt (IZR Z0) (Rminus y x) *)
  rewrite /Rmax ; case: Rle_dec (Rlt_le _ _ Hxy) => //.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by apply -> Rminus_lt_0.
Qed.

Lemma MVT_cor4:
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f df : R -> R) a eps,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall c, Rabs (c - a) <= eps -> is_derive f c (df c)) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall b, (Rabs (b - a) <= eps) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  exists c, f b - f a = df c * (b - a) /\ (Rabs (c - a) <= Rabs (b - a)).
Proof.
(* Goal: forall (f df : forall _ : R, R) (a eps : R) (_ : forall (c : R) (_ : Rle (Rabs (Rminus c a)) eps), @is_derive R_AbsRing R_NormedModule f c (df c)) (b : R) (_ : Rle (Rabs (Rminus b a)) eps), @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rabs (Rminus b a)))) *)
intros f df a eps Hf' b.
(* Goal: forall _ : Rle (Rabs (Rminus b a)) eps, @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rabs (Rminus b a)))) *)
unfold Rabs at 1 3.
case Rcase_abs; intros H1 H2.
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Ropp (Rminus b a)))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
destruct (MVT_cor2 f df b a).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -(Rplus_0_l a).
(* Goal: Rlt b (Rplus (IZR Z0) a) *)
(* Goal: forall (c : R) (_ : and (Rle b c) (Rle c a)), derivable_pt_lim f c (df c) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Ropp (Rminus b a)))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
now apply Rlt_minus_l.
(* Goal: forall (c : R) (_ : Rle (Rabs (Rminus c x)) (Rabs (Rminus y x))), @is_derive R_AbsRing R_NormedModule h c (dh c) *)
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
intros c Hc.
(* Goal: derivable_pt_lim f c (df c) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply is_derive_Reals, Hf'.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite Rabs_left1.
(* Goal: Rle (Rminus c a) eps *)
(* Goal: Rge (Rminus c a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply Rle_trans with (2:=H2).
(* Goal: Rle (Ropp (Rminus x a)) (Ropp (Rminus b a)) *)
(* Goal: Rlt (Rminus x a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply Ropp_le_contravar.
(* Goal: Rle (Rminus c a) (Rminus b a) *)
(* Goal: Rge (Rminus c a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
now apply Rplus_le_compat_r.
(* Goal: Rle (Rminus c a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Ropp (Rminus b a)))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply Rplus_le_reg_r with a.
(* Goal: Rle (Rplus (IZR Z0) a) (Rplus (Rminus c a) a) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
now ring_simplify.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
exists x; split.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -RIneq.Ropp_minus_distr (proj1 H).
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
ring.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite Rabs_left.
(* Goal: Rle (Ropp (Rminus x a)) (Ropp (Rminus b a)) *)
(* Goal: Rlt (Rminus x a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply Ropp_le_contravar.
(* Goal: Rle (Rminus x a) (Rminus b a) *)
(* Goal: Rge (Rminus x a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
left; now apply Rplus_lt_compat_r.
(* Goal: Rlt (Rminus x a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply Rplus_lt_reg_r with a.
(* Goal: Rle (Rplus (IZR Z0) a) (Rplus (Rminus c a) a) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
now ring_simplify.
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
destruct H1.
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
destruct (MVT_cor2 f df a b).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
apply Rplus_lt_reg_r with (-a).
(* Goal: @eq R (Rplus (Ropp a) a) (Rplus (Ropp a) b) *)
ring_simplify.
(* Goal: Rlt (IZR Z0) (Rplus (Ropp a) b) *)
(* Goal: forall (c : R) (_ : and (Rle a c) (Rle c b)), derivable_pt_lim f c (df c) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
now rewrite Rplus_comm.
(* Goal: forall (c : R) (_ : Rle (Rabs (Rminus c x)) (Rabs (Rminus y x))), @is_derive R_AbsRing R_NormedModule h c (dh c) *)
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
intros c Hc.
(* Goal: derivable_pt_lim f c (df c) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply is_derive_Reals, Hf'.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite Rabs_right.
(* Goal: Rle (Rminus c a) eps *)
(* Goal: Rge (Rminus c a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply Rle_trans with (2:=H2).
(* Goal: Rle (Rminus c a) (Rminus b a) *)
(* Goal: Rge (Rminus c a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
now apply Rplus_le_compat_r.
(* Goal: Rle (Rminus c a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Ropp (Rminus b a)))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply Rle_ge; apply Rplus_le_reg_r with a.
(* Goal: Rle (Rplus (IZR Z0) a) (Rplus (Rminus c a) a) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
now ring_simplify.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
exists x; split.
(* Goal: @eq R (Rminus (f b) (f a)) (Rmult (df x) (Rminus b a)) *)
(* Goal: Rle (Rabs (Rminus x a)) (Rminus b a) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
exact (proj1 H0).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite Rabs_right.
(* Goal: Rle (Rminus x a) (Rminus b a) *)
(* Goal: Rge (Rminus x a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
left; now apply Rplus_lt_compat_r.
(* Goal: Rle (Rminus c a) (IZR Z0) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Ropp (Rminus b a)))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
apply Rle_ge; apply Rplus_le_reg_r with a.
(* Goal: Rle (Rplus (IZR Z0) a) (Rplus (Rminus c a) a) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
left; now ring_simplify.
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
exists a.
(* Goal: and (@eq R (Rminus (f b) (f a)) (Rmult (df a) (Rminus b a))) (Rle (Rabs (Rminus a a)) (Rminus b a)) *)
replace b with a.
(* Goal: and (@eq R (Rminus (f a) (f a)) (Rmult (df a) (Rminus a a))) (Rle (Rabs (Rminus a a)) (Rminus a a)) *)
(* Goal: @eq R a b *)
split;[ring|idtac].
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite /Rminus Rplus_opp_r Rabs_R0.
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
apply Rle_refl.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
apply Rplus_eq_reg_l with (-a).
(* Goal: @eq R (Rplus (Ropp a) a) (Rplus (Ropp a) b) *)
ring_simplify.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite - H; ring.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma bounded_variation (h dh : R -> R) (D : R) (x y : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall t : R, Rabs (t - x) <= Rabs (y - x) -> is_derive h t (dh t) /\ (Rabs (dh t) <= D)) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  Rabs (h y - h x) <= D * Rabs (y - x).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (j : I) (k : nat) (_ : @List.In I j l) (_ : le k n), ex_derive_n (f j) k y), @eq R (Derive_n (fun y : R => @iter I R Rplus (IZR Z0) l (fun j : I => f j y)) n x) (@iter I R Rplus (IZR Z0) l (fun j : I => Derive_n (f j) n x)) *)
intros H.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
destruct (MVT_cor4 h dh x (Rabs (y - x))) with (b := y) as [t Ht].
(* Goal: forall (c : R) (_ : Rle (Rabs (Rminus c x)) (Rabs (Rminus y x))), @is_derive R_AbsRing R_NormedModule h c (dh c) *)
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
intros c Hc.
(* Goal: @is_derive R_AbsRing R_NormedModule h c (dh c) *)
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
specialize (H c Hc).
(* Goal: @is_derive R_AbsRing R_NormedModule h c (dh c) *)
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
apply H.
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
apply Rle_refl.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite (proj1 Ht).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite Rabs_mult.
(* Goal: Rle (Rmult (Rabs (dh t)) (Rabs (Rminus y x))) (Rmult D (Rabs (Rminus y x))) *)
apply Rmult_le_compat_r.
(* Goal: Rle (IZR Z0) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (dh t)) D *)
apply Rabs_pos.
(* Goal: @is_derive R_AbsRing R_NormedModule h c (dh c) *)
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
now apply H.
Qed.

Lemma norm_le_prod_norm_1 {K : AbsRing} {U V : NormedModule K} (x : U * V) :
  norm (fst x) <= norm x.
Proof.
(* Goal: Rle (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x)) (@norm K (prod_NormedModule K U V) x) *)
  eapply Rle_trans, sqrt_plus_sqr.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Rabs_pos_eq.
(* Goal: Rle (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) x)) (Rmax (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) x)) (Rabs (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x)))) *)
(* Goal: Rle (IZR Z0) (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) x)) *)
  apply Rmax_l.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
  by apply norm_ge_0.
Qed.
Lemma norm_le_prod_norm_2 {K : AbsRing} {U V : NormedModule K} (x : U * V) :
  norm (snd x) <= norm x.
Proof.
(* Goal: Rle (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x)) (@norm K (prod_NormedModule K U V) x) *)
  eapply Rle_trans, sqrt_plus_sqr.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite (Rabs_pos_eq (norm (snd x))).
(* Goal: Rle (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x)) (Rmax (Rabs (@norm K U (@fst (NormedModule.sort K U) (NormedModule.sort K V) x))) (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x))) *)
(* Goal: Rle (IZR Z0) (@norm K V (@snd (NormedModule.sort K U) (NormedModule.sort K V) x)) *)
  apply Rmax_r.
(* Goal: Rle (IZR Z0) (@norm K V x) *)
  by apply norm_ge_0.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_filterdiff (f : R -> R -> R) (x y : R) (dfx : R -> R -> R) (dfy : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally (x,y) (fun u : R * R => is_derive (fun z => f z (snd u)) (fst u) (dfx (fst u) (snd u))) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive (fun z : R => f x z) y dfy ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  continuous (fun u : R * R => dfx (fst u) (snd u)) (x,y) ->
  filterdiff (fun u : R * R => f (fst u) (snd u)) (locally (x,y)) (fun u : R * R => plus (scal (fst u) (dfx x y)) (scal (snd u) dfy)).
Proof.
  intros Dx Dy Cx.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
    apply (is_linear_comp (fun u : R * R => (scal (fst u) (dfx x y),scal (snd u) dfy))
                          (fun u : R * R => plus (fst u) (snd u))).
(* Goal: @is_linear K (prod_NormedModule K V V) (prod_NormedModule K V V) (fun u : NormedModule.sort K (prod_NormedModule K V V) => @pair (NormedModule.sort K V) (AbelianGroup.sort (NormedModule.AbelianGroup K V)) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@opp (NormedModule.AbelianGroup K V) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u))) *)
(* Goal: @is_linear K (prod_NormedModule K V V) V (fun u : NormedModule.sort K (prod_NormedModule K V V) => @plus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) u) (@snd (NormedModule.sort K V) (NormedModule.sort K V) u)) *)
(* Goal: forall (x : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) (_ : @is_filter_lim (NormedModule.UniformSpace K (prod_NormedModule K V V)) F x), @is_domin (UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V))) K K (prod_NormedModule K V V) V F (fun y : NormedModule.sort K (prod_NormedModule K V V) => @minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x) (fun y : UniformSpace.sort (NormedModule.UniformSpace K (prod_NormedModule K V V)) => @minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) y) (@snd (NormedModule.sort K V) (NormedModule.sort K V) y)) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) x) (@snd (NormedModule.sort K V) (NormedModule.sort K V) x))) (@minus (NormedModule.AbelianGroup K V) (@fst (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)) (@snd (NormedModule.sort K V) (NormedModule.sort K V) (@minus (NormedModule.AbelianGroup K (prod_NormedModule K V V)) y x)))) *)
    apply is_linear_prod.
    apply (is_linear_comp (@fst _ _) (fun t : R => scal t (dfx x y))).
(* Goal: @is_linear K (prod_NormedModule K U V) U (@fst (NormedModule.sort K U) (NormedModule.sort K V)) *)
(* Goal: @is_linear K (prod_NormedModule K U V) V (@snd (NormedModule.sort K U) (NormedModule.sort K V)) *)
(* Goal: @filterdiff K (prod_NormedModule K U V) W (fun t : NormedModule.sort K (prod_NormedModule K U V) => h (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) (@locally (NormedModule.UniformSpace K (prod_NormedModule K U V)) (@pair (NormedModule.sort K U) (NormedModule.sort K V) (f x) (g x))) (fun t : NormedModule.sort K (prod_NormedModule K U V) => lh (@fst (NormedModule.sort K U) (NormedModule.sort K V) t) (@snd (NormedModule.sort K U) (NormedModule.sort K V) t)) *)
    by apply is_linear_fst.
    by apply @is_linear_scal_l.
    apply (is_linear_comp (@snd _ _) (fun t : R => scal t dfy)).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply is_linear_snd.
    by apply @is_linear_scal_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply @is_linear_plus.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  simpl => u Hu.
  replace u with (x,y) by now apply is_filter_lim_locally_unique.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => {u Hu} eps /=.
  set (eps' := pos_div_2 eps).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  generalize (proj1 (filterlim_locally _ _) Cx eps') => {Cx} /= Cx.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  generalize (filter_and _ _ Dx Cx) => {Dx Cx}.
  intros (d1,Hd1).
  destruct (proj2 Dy y (fun P H => H) eps') as (d2,Hd2).
  set (l1 := dfx x y).
  exists (mkposreal _ (Rmin_stable_in_posreal d1 d2)).
  intros (u,v) (Hu,Hv) ; simpl in *.
  set (g1 t := minus (f t v) (scal t l1)).
  set (g2 t := minus (f x t) (scal t dfy)).
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  apply Rle_trans with (norm (minus (g1 u) (g1 x)) + norm (minus (g2 v) (g2 y))).
  eapply Rle_trans, norm_triangle.
  apply Req_le, f_equal, sym_eq.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite /g1 /g2 /minus !opp_plus !opp_opp -!plus_assoc ; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    do 5 rewrite plus_comm -!plus_assoc ; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite !scal_distr_r !opp_plus -!plus_assoc !scal_opp_l !opp_opp.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite plus_comm -!plus_assoc ; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite plus_comm -!plus_assoc ; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    by rewrite plus_comm -!plus_assoc plus_opp_l plus_zero_r.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  replace (pos eps) with (eps' + eps') by (apply sym_eq ; apply double_var).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Rmult_plus_distr_r.
(* Goal: Rle (Rplus (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (IZR Z0)) (Rplus (Rmult (@abs K k) (@norm K V x)) (@norm K V x)) *)
  apply Rplus_le_compat.
  (* *)
  apply Rle_trans with (eps' * norm (minus u x)).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply bounded_variation with (fun t => minus (dfx t v) l1) => t Ht.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
    apply: is_derive_minus.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
    apply (Hd1 (t,v)) ; split ; simpl.
    apply Rle_lt_trans with (1 := Ht).
    apply Rlt_le_trans with (1:=Hu).
    apply Rmin_l.
    apply Rlt_le_trans with (1:=Hv).
    apply Rmin_l.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite -{2}(Rmult_1_r l1).
    evar_last.
    apply filterdiff_linear, is_linear_scal_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by rewrite Rmult_1_r.
  apply Rlt_le.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
  apply (Hd1 (t,v)) ; split ; simpl.
  apply Rle_lt_trans with (1 := Ht).
  apply Rlt_le_trans with (1:=Hu).
  apply Rmin_l.
  apply Rlt_le_trans with (1:=Hv).
  apply Rmin_l.
  apply Rmult_le_compat_l.
  apply Rlt_le.
  apply cond_pos.
  apply (norm_le_prod_norm_1 (minus (u, v) (x, y))).
  (* *)
  apply Rle_trans with (eps' * norm (minus v y)).
  apply Rle_trans with (norm (minus (minus (f x v) (f x y)) (scal (minus v y) dfy))).
(* Goal: @eq R (Rmult (pow a n) (Derive (fun x : R => Derive_n f n (Rmult a x)) y)) (Rmult (pow a n) (Rmult a (Derive (Derive_n f n) (Rmult a y)))) *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  right; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /g2 scal_minus_distr_r /minus !opp_plus opp_opp -!plus_assoc ; apply f_equal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite plus_comm -!plus_assoc ; apply f_equal.
  apply plus_comm.
  apply Hd2.
  apply Rlt_le_trans with (1:=Hv).
  apply Rmin_r.
  apply Rmult_le_compat_l.
  apply Rlt_le.
  apply cond_pos.
  apply (norm_le_prod_norm_2 (minus (u, v) (x, y))).
Qed.


(** * Newton integration *)

Lemma fn_eq_Derive_eq: forall f g a b,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  continuity_pt f a -> continuity_pt f b ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  continuity_pt g a -> continuity_pt g b ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall x, a < x < b -> ex_derive f x) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall x, a < x < b -> ex_derive g x) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall x, a < x < b -> Derive f x = Derive g x) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  exists C, forall x, a <= x <= b -> f x = g x + C.
Proof.
(* Goal: forall (f g : forall _ : R, R) (a b : R) (_ : continuity_pt f a) (_ : continuity_pt f b) (_ : continuity_pt g a) (_ : continuity_pt g b) (_ : forall (x : R) (_ : and (Rlt a x) (Rlt x b)), @ex_derive R_AbsRing R_NormedModule f x) (_ : forall (x : R) (_ : and (Rlt a x) (Rlt x b)), @ex_derive R_AbsRing R_NormedModule g x) (_ : forall (x : R) (_ : and (Rlt a x) (Rlt x b)), @eq R (Derive f x) (Derive g x)), @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
intros f g a b Cfa Cfb Cga Cgb Df Dg Hfg.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
pose (h := fun x => f x - g x).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
assert  (pr : forall x : R, a < x < b -> derivable_pt h x).
(* Goal: forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) (h a)) *)
intros x Hx.
(* Goal: derivable_pt h x *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply derivable_pt_minus.
(* Goal: derivable_pt f x *)
(* Goal: derivable_pt g x *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
eexists; apply is_derive_Reals, Derive_correct, Df, Hx.
(* Goal: derivable_pt g x *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
eexists; apply is_derive_Reals, Derive_correct, Dg, Hx.
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
assert (constant_D_eq h (fun x : R => a <= x <= b) (h a)).
(* Goal: constant_D_eq h (fun x : R => and (Rle a x) (Rle x b)) (h a) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply null_derivative_loc with (pr:=pr).
(* Goal: forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) (h a)) *)
intros x Hx.
(* Goal: continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
case (proj1 Hx).
(* Goal: forall _ : Rlt a x, continuity_pt h x *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
case (proj2 Hx).
(* Goal: forall (_ : Rlt x b) (_ : Rlt a x), continuity_pt h x *)
(* Goal: forall (_ : @eq R x b) (_ : Rlt a x), continuity_pt h x *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
intros Y1 Y2.
(* Goal: continuity_pt h x *)
(* Goal: forall (_ : @eq R x b) (_ : Rlt a x), continuity_pt h x *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply derivable_continuous_pt.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
apply pr; now split.
(* Goal: forall (_ : @eq R x b) (_ : Rlt a x), continuity_pt h x *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
intros Y1 _; rewrite Y1.
(* Goal: continuity_pt h a *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply continuity_pt_minus.
(* Goal: continuity_pt f b *)
(* Goal: continuity_pt g b *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply Cfb.
(* Goal: continuity_pt g b *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply Cgb.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
intros Y1; rewrite <- Y1.
(* Goal: continuity_pt h a *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply continuity_pt_minus.
(* Goal: continuity_pt f a *)
(* Goal: continuity_pt g a *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply Cfa.
(* Goal: continuity_pt g a *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply Cga.
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
intros x P.
(* Goal: @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply trans_eq with (Derive h x).
(* Goal: @eq R (derive_pt h x (pr x P)) (Derive h x) *)
(* Goal: @eq R (Derive h x) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply sym_eq, is_derive_unique, is_derive_Reals.
(* Goal: derivable_pt_lim h x (derive_pt h x (pr x P)) *)
(* Goal: @eq R (Derive h x) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
now destruct (pr x P).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite Derive_minus.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite (Hfg _ P).
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
ring.
(* Goal: @ex_derive R_AbsRing R_NormedModule f x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule g x *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply Df; split; apply P.
(* Goal: @ex_derive R_AbsRing R_NormedModule g x *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply Dg; split; apply P.
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
unfold constant_D_eq in H.
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
exists (h a).
(* Goal: forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) (h a)) *)
intros x Hx.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite <- (H _ Hx).
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
unfold h; ring.
Qed.

(** * Extension *)

Section ext_cont.

Context {U : UniformSpace}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Definition extension_cont (f g : R -> U) (a x : R) : U :=
  match Rle_dec x a with
    | left _ => f x
    | right _ => g x
  end.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma extension_cont_continuous (f g : R -> U) (a : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  continuous f a -> continuous g a
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> f a = g a
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> continuous (extension_cont f g a) a.
Proof.
(* Goal: forall (_ : @continuous R_UniformSpace U f a) (_ : @continuous R_UniformSpace U g a) (_ : @eq (UniformSpace.sort U) (f a) (g a)), @continuous R_UniformSpace U (extension_cont f g a) a *)
  simpl => Cf Cg Heq ; apply filterlim_locally => /= eps.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  generalize (proj1 (filterlim_locally _ _) Cf eps) => {Cf} Cf.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  generalize (proj1 (filterlim_locally _ _) Cg eps) => {Cg} Cg.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) a (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing V (@minus (NormedModule.AbelianGroup R_AbsRing V) (@minus (NormedModule.AbelianGroup R_AbsRing V) (@extension_cont (NormedModule.UniformSpace R_AbsRing V) f g a x) (@extension_cont (NormedModule.UniformSpace R_AbsRing V) f g a a)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing V) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x a) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x a)))) *)
  generalize (filter_and _ _ Cf Cg).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp => {Cf Cg} x [Cf Cg].
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_cont.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_dec (Rle_refl a) => // _ _.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rle_dec => // H.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Heq.
Qed.

End ext_cont.

Section ext_cont'.

Context {V : NormedModule R_AbsRing}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma extension_cont_is_derive (f g : R -> V) (a : R) (l : V) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive f a l -> is_derive g a l
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> f a = g a
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> is_derive (extension_cont f g a) a l.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case => _ Cf [_ Cg] Heq.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_linear_scal_l.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hx eps.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move: (Cf x Hx eps) => {Cf} Cf.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move: (Cg x Hx eps) => {Cg} Cg.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  generalize (is_filter_lim_locally_unique _ _ Hx) => {Hx} Hx.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Hx {x Hx} in Cf, Cg |- *.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) a (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing V (@minus (NormedModule.AbelianGroup R_AbsRing V) (@minus (NormedModule.AbelianGroup R_AbsRing V) (@extension_cont (NormedModule.UniformSpace R_AbsRing V) f g a x) (@extension_cont (NormedModule.UniformSpace R_AbsRing V) f g a a)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing V) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x a) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x a)))) *)
  generalize (filter_and _ _ Cf Cg).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp => {Cf Cg} x [Cf Cg].
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_cont.
  case: Rle_dec => Hx ;
  case: Rle_dec (Rle_refl a) => //= _ _.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Heq.
Qed.

End ext_cont'.

Section ext_C0.

Context {V : NormedModule R_AbsRing}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Definition extension_C0 (f : R -> V) (a b : Rbar) (x : R) : V :=
  match Rbar_le_dec a x with
    | left _ => match Rbar_le_dec x b with
        | left _ => f x
        | right _ => f (real b)
      end
    | right _ => f (real a)
  end.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma extension_C0_ext (f : R -> V) (a b : Rbar) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (x : R), Rbar_le a x -> Rbar_le x b -> (extension_C0 f a b) x = f x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hax Hxb.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => // _.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => // _.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma extension_C0_continuous (f : R -> V) (a b : Rbar) :
  Rbar_le a b
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> (forall x : R, Rbar_le a x -> Rbar_le x b -> continuous f x)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> forall x, continuous (extension_C0 f a b) x.
Proof.
  intros Hab Cf x.

  apply Rbar_le_lt_or_eq_dec in Hab ; case: Hab => Hab.

(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (Rbar_lt_le_dec x a) => Hax.

  eapply continuous_ext_loc.
  apply locally_interval with m_infty a.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y _ Hay.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H.
  contradict H ; by apply Rbar_lt_not_le.
  reflexivity.
  apply continuous_const.

  apply Rbar_le_lt_or_eq_dec in Hax ; case: Hax => Hax.

(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (Rbar_lt_le_dec x b) => Hbx.

  eapply continuous_ext_loc.
  apply locally_interval with a b.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y Hay Hby.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H0.
  reflexivity.
  contradict H0 ; by apply Rbar_lt_le.
  contradict H ; by apply Rbar_lt_le.
  apply Cf ; by apply Rbar_lt_le.

  apply Rbar_le_lt_or_eq_dec in Hbx ; case: Hbx => Hbx.

  eapply continuous_ext_loc.
  apply locally_interval with b p_infty.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y Hby _.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H0.
  contradict H0 ; by apply Rbar_lt_not_le.
  reflexivity.
  contradict H ; eapply Rbar_le_trans, Rbar_lt_le, Hby.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le.
  apply continuous_const.

(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  destruct b as [b | | ] => //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  injection Hbx => {Hbx} Hbx.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Hbx {x Hbx} in Hax |- *.
  apply continuous_ext_loc with (extension_cont f (fun _ => f (real b)) b).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply locally_interval with a p_infty => //.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y Hay _.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_cont /extension_C0.
  case: Rle_dec => H ;
  case: Rbar_le_dec => H0 ;
  case: (Rbar_le_dec y b) => // _.
  contradict H0 ; by apply Rbar_lt_le.
  contradict H0 ; by apply Rbar_lt_le.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply extension_cont_continuous => //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply Cf => /=.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rle_refl.
  by apply continuous_const.

(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  destruct a as [a | | ] => //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  injection Hax => {Hax} Hax.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Hax {x Hax}.
  apply continuous_ext_loc with (extension_cont (fun _ => f (real a)) f a).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply locally_interval with m_infty b => //.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y _ Hbx.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_cont /extension_C0.
  case: Rle_dec => H ;
  case: Rbar_le_dec => //= H0 ;
  try case: Rbar_le_dec => // H1.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by replace y with a by now apply Rle_antisym.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  contradict H1 ; by apply Rbar_lt_le.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  contradict H1 ; by apply Rbar_lt_le.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by contradict H0 ; apply Rlt_le, Rnot_le_lt.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply extension_cont_continuous => //.
  by apply continuous_const.
  apply Cf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rle_refl.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Hab {b Hab Cf}.
  eapply continuous_ext.
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
  intros y.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H.
  2: reflexivity.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => // H0.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  destruct a as [a | | ] => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by replace y with a by now apply Rle_antisym.
  by apply continuous_const.
Qed.

End ext_C0.

(** ** C1 extension *)

Section ext_C1.

Context {V : NormedModule R_AbsRing}.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Definition extension_C1 (f df : R -> V) (a b : Rbar) (x : R) : V :=
  match Rbar_le_dec a x with
    | left _ => match Rbar_le_dec x b with
        | left _ => f x
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
        | right _ => plus (f (real b)) (scal (x - real b) (df (real b)))
      end
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    | right _ => plus (f (real a)) (scal (x - real a) (df (real a)))
  end.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma extension_C1_ext (f df : R -> V) (a b : Rbar) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (x : R), Rbar_le a x -> Rbar_le x b -> (extension_C1 f df a b) x = f x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => x Hax Hxb.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C1.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => // _.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => // _.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma extension_C1_is_derive (f df : R -> V) (a b : Rbar) :
  Rbar_le a b
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> (forall x : R, Rbar_le a x -> Rbar_le x b -> is_derive f x (df x))
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> forall x : R, is_derive (extension_C1 f df a b) x (extension_C0 df a b x).
Proof.
  intros Hab Cf x.

  apply Rbar_le_lt_or_eq_dec in Hab ; case: Hab => Hab.

(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (Rbar_lt_le_dec x a) => Hax.

  evar_last.
  eapply is_derive_ext_loc.
  apply locally_interval with m_infty a.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y _ Hay.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C1.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H.
  contradict H ; by apply Rbar_lt_not_le.
  reflexivity.
  apply is_derive_plus.
  apply is_derive_const.
  apply @is_derive_scal_l.
  apply @is_derive_minus.
  apply is_derive_id.
  apply is_derive_const.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite plus_zero_l minus_zero_r scal_one.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_le_not_lt in H.

  apply Rbar_le_lt_or_eq_dec in Hax ; case: Hax => Hax.

(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (Rbar_lt_le_dec x b) => Hbx.

  evar_last.
  eapply is_derive_ext_loc.
  apply locally_interval with a b.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y Hay Hby.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  apply sym_eq, extension_C1_ext ; by apply Rbar_lt_le.
  apply Cf ; by apply Rbar_lt_le.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => // H.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => // H0.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le in Hbx.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le in Hax.

  apply Rbar_le_lt_or_eq_dec in Hbx ; case: Hbx => Hbx.

  evar_last.
  eapply is_derive_ext_loc.
  apply locally_interval with b p_infty.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y Hby _.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C1.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H0.
  contradict H0 ; by apply Rbar_lt_not_le.
  reflexivity.
  contradict H ; eapply Rbar_le_trans, Rbar_lt_le, Hby.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le.
  apply is_derive_plus.
  apply is_derive_const.
  apply @is_derive_scal_l.
  apply @is_derive_minus.
  apply is_derive_id.
  apply is_derive_const.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite plus_zero_l minus_zero_r scal_one.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H //.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H0 //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_le_not_lt in H0.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le in Hax.

(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  destruct b as [b | | ] => //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  injection Hbx => {Hbx} Hbx.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Hbx {x Hbx} in Hax |- *.
  evar_last.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply is_derive_ext_loc with (extension_cont f (fun x => plus (f (real b)) (scal (x - real b) (df (real b)))) b).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply locally_interval with a p_infty => //.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y Hay _.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_cont /extension_C1.
  case: Rle_dec => H ;
  case: Rbar_le_dec => H0 ;
  case: (Rbar_le_dec y b) => // _.
  contradict H0 ; by apply Rbar_lt_le.
  contradict H0 ; by apply Rbar_lt_le.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply extension_cont_is_derive => //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply Cf => /=.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rle_refl.
  evar_last.
  apply is_derive_plus.
  apply is_derive_const.
  apply @is_derive_scal_l.
  apply @is_derive_minus.
  apply is_derive_id.
  apply is_derive_const.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  by rewrite plus_zero_l minus_zero_r scal_one.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Rminus_eq_0 @scal_zero_l plus_zero_r.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec (Rle_refl b) => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le in Hax.

(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  destruct a as [a | | ] => //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  injection Hax => {Hax} Hax.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Hax {x Hax}.
  evar_last.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply is_derive_ext_loc with (extension_cont (fun x => plus (f (real a)) (scal (x - real a) (df (real a)))) f a).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply locally_interval with m_infty b => //.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y _ Hbx.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_cont /extension_C1.
  case: Rle_dec => H ;
  case: Rbar_le_dec => //= H0 ;
  try case: Rbar_le_dec => // H1.
  replace y with a by now apply Rle_antisym.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Rminus_eq_0 @scal_zero_l plus_zero_r.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  contradict H1 ; by apply Rbar_lt_le.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  contradict H1 ; by apply Rbar_lt_le.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by contradict H0 ; apply Rlt_le, Rnot_le_lt.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply extension_cont_is_derive => //.
  apply is_derive_plus.
  apply is_derive_const.
  apply @is_derive_scal_l.
  apply @is_derive_minus.
  apply is_derive_id.
  apply is_derive_const.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite plus_zero_l minus_zero_r scal_one.
  apply Cf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rle_refl.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Rminus_eq_0 @scal_zero_l plus_zero_r.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite plus_zero_l minus_zero_r scal_one.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec (Rle_refl a) => // _ _.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Rbar_lt_le in Hab.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Hab {b Hab Cf}.
  evar_last.
  eapply is_derive_ext.
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@opp (ModuleSpace.AbelianGroup (AbsRing.Ring K) (NormedModule.ModuleSpace K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y l)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@opp (NormedModule.AbelianGroup K V) l)) *)
  intros y.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C1.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H.
  2: reflexivity.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => // H0.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  destruct a as [a | | ] => //.
  replace y with a by now apply Rle_antisym.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Rminus_eq_0 @scal_zero_l plus_zero_r.
  apply is_derive_plus.
  apply is_derive_const.
  apply @is_derive_scal_l.
  apply @is_derive_minus.
  apply is_derive_id.
  apply is_derive_const.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite plus_zero_l minus_zero_r scal_one.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /extension_C0.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H //.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Rbar_le_dec => H0 //.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  destruct a as [a | | ] => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by replace a with x by now apply Rle_antisym.
Qed.

End ext_C1.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma extension_C1_ex_derive (f df : R -> R) (a b : Rbar) :
  Rbar_le a b
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> (forall x : R, Rbar_le a x -> Rbar_le x b -> ex_derive f x)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> forall x : R, ex_derive (extension_C1 f (Derive f) a b) x.
Proof.
  intros Hab Df x.
  eexists.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply extension_C1_is_derive => //.
  intros y Hay Hby.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Derive_correct, Df.
Qed.

Section NullDerivative.

Context {V : NormedModule R_AbsRing}.

Lemma eq_is_derive :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall (f : R -> V) (a b : R),
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall t, a <= t <= b -> is_derive f t zero) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  a < b -> f a = f b.
Proof.
intros f a b Hd Hab.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
apply ball_norm_eq => eps2.
pose eps := pos_div_2 eps2.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
have Heps': 0 < eps / (b - a).
(* Goal: Rlt (IZR Z0) (Rdiv (pos r) (Rabs a)) *)
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rmult (pow a n) (Derive_n f n (Rmult a t))) (Derive_n (fun y : R => f (Rmult a y)) n t)) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Rdiv_lt_0_compat.
  apply eps.
  exact: Rlt_Rminus.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
pose eps' := mkposreal (eps / (b - a)) Heps'.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
pose P t := norm (minus (f t) (f a)) <= eps' * (t - a).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
pose A x := x <= b /\ forall t, a <= t <= x -> P t.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
have H c : (forall t, a <= t < c -> P t) -> a <= c <= b ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    exists delta:posreal, (forall t, a <= t <= Rmin b (c + delta) -> P t).
  intros HP Hc.
  destruct (Hd c Hc) as [_ Hd'].
  refine (_ (Hd' c _ eps')).
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case => delta H.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  have Hdelta := cond_pos delta.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  exists (pos_div_2 delta) => t Ht.
  destruct (Rlt_le_dec t c) as [Htc|Htc].
  apply HP.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  now split.
  unfold P.
  replace (minus (f t) (f a)) with (plus (minus (f t) (f c)) (minus (f c) (f a))).
  apply Rle_trans with (1 := norm_triangle _ _).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  replace (eps' * (t - a)) with (eps' * (t - c) + eps' * (c - a)) by ring.
(* Goal: Rle (Rplus (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (IZR Z0)) (Rplus (Rmult (@abs K k) (@norm K V x)) (@norm K V x)) *)
  apply Rplus_le_compat.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move: (H t) => {H}.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite scal_zero_r minus_zero_r -[norm (minus t c)]/(Rabs (t - c)).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -> Rabs_pos_eq by lra.
  apply.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply: norm_compat1.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  change (Rabs (t - c) < delta).
(* Goal: @ball R_UniformSpace x (pos r) t *)
  apply Rabs_lt_between'.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  cut (t <= c + delta/2).
  lra.
  apply Rle_trans with (1 := proj2 Ht).
  apply Rmin_r.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  set (d' := Rmax a (c - delta/2)).
  replace (minus (f c) (f a)) with (plus (opp (minus (f d') (f c))) (minus (f d') (f a))).
  apply Rle_trans with (1 := norm_triangle _ _).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  replace (eps' * (c - a)) with (eps' * (c - d') + eps' * (d' - a)) by ring.
(* Goal: Rle (Rplus (@norm K V (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) k x)) (IZR Z0)) (Rplus (Rmult (@abs K k) (@norm K V x)) (@norm K V x)) *)
  apply Rplus_le_compat.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move: (H d') => {H}.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite scal_zero_r minus_zero_r -[norm (minus d' c)]/(Rabs (d' - c)).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite norm_opp -Rabs_Ropp Rabs_pos_eq Ropp_minus_distr.
  apply.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply: norm_compat1.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  change (Rabs (d' - c) < delta).
(* Goal: @ball R_UniformSpace x (pos r) t *)
  apply Rabs_lt_between'.
  apply Rmax_case_strong ; lra.
  apply Rmax_case_strong ; lra.
  destruct (Req_dec a d') as [Had|Had].
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Had.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /minus plus_opp_r /Rminus Rplus_opp_r Rmult_0_r norm_zero.
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
  apply Rle_refl.
  apply HP.
  revert Had.
  apply Rmax_case_strong ; lra.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by rewrite opp_minus /minus plus_assoc -(plus_assoc (f c)) plus_opp_l plus_zero_r.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by rewrite /minus plus_assoc -(plus_assoc (f t)) plus_opp_l plus_zero_r.
(* Goal: forall _ : is_derive_n f O x l, @eq R (Derive_n f O x) l *)
(* Goal: forall (n : nat) (_ : is_derive_n f (S n) x l), @eq R (Derive_n f (S n) x) l *)
  easy.
assert (Ha : A a).
  apply (conj (Rlt_le _ _ Hab)).
  intros t [Ht1 Ht2].
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite (Rle_antisym _ _ Ht2 Ht1).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /P /minus plus_opp_r /Rminus Rplus_opp_r Rmult_0_r norm_zero.
(* Goal: Rle (Rabs (Rminus y x)) (Rabs (Rminus y x)) *)
(* Goal: Rle (Rabs (Rminus (h y) (h x))) (Rmult D (Rabs (Rminus y x))) *)
  apply Rle_refl.
destruct (completeness A) as [s [Hs1 Hs2]].
  now exists b => t [At _].
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
  now exists a.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
assert (Hs: forall t, a <= t < s -> P t).
  intros t Ht.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply Rnot_lt_le => H'.
  specialize (Hs2 t).
  apply (Rlt_not_le _ _ (proj2 Ht)), Hs2.
  intros x [Ax1 Ax2].
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply Rnot_lt_le => Hxt.
  apply (Rlt_not_le _ _ H').
  apply Ax2.
  lra.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
destruct (Req_dec s b) as [->|Hsb].
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
- destruct (H b) as [delta Hdelta].
    apply Hs.
    lra.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply Rle_lt_trans with (eps' * (b - a)).
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply: Hdelta.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  have Hdelta := cond_pos delta.
  rewrite Rmin_left ; lra.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
  simpl.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  have Heps2 := cond_pos eps2.
  field_simplify ; lra.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
- destruct (H s) as [delta Hdelta].
    apply Hs.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
    split.
    now apply Hs1.
    apply Hs2.
(* Goal: forall x : R, @eq R (Derive (Derive_n (Derive_n f m) n) x) (Derive (Derive_n f (Init.Nat.add n m)) x) *)
    intros x.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by case.
  eelim Rle_not_lt.
  apply Hs1.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
  apply Rmin_l.
  apply Hdelta.
(* Goal: Rlt (IZR Z0) (Rmin (Rdiv (pos r0) (Rabs a)) (pos r)) *)
(* Goal: @locally R_UniformSpace x (fun x : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) (S n) x) (Rmult (pow a (S n)) (Derive_n f (S n) (Rmult a x)))) *)
  apply Rmin_case.
(* Goal: forall _ : is_derive_n f O x l, @eq R (Derive_n f O x) l *)
(* Goal: forall (n : nat) (_ : is_derive_n f (S n) x l), @eq R (Derive_n f (S n) x) l *)
  destruct (Hs2 b) ; try easy.
(* Goal: forall x : R, @eq R (Derive (Derive_n (Derive_n f m) n) x) (Derive (Derive_n f (Init.Nat.add n m)) x) *)
  intros x.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by case.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  have Hdelta' := cond_pos delta.
  lra.
Qed.



End NullDerivative.

(** * Iterated differential *)

(** ** Definition *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Fixpoint Derive_n (f : R -> R) (n : nat) x :=
  match n with
    | O => f x
    | S n => Derive (Derive_n f n) x
  end.

Definition ex_derive_n f n x :=
  match n with
  | O => True
  | S n => ex_derive (Derive_n f n) x
  end.

Definition is_derive_n f n x l :=
  match n with
  | O => f x = l
  | S n => is_derive (Derive_n f n) x l
  end.

Lemma is_derive_n_unique f n x l :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n x l -> Derive_n f n x = l.
Proof.
(* Goal: forall _ : is_derive_n f n x l, @eq R (Derive_n f n x) l *)
  case n.
(* Goal: forall _ : is_derive_n f O x l, @eq R (Derive_n f O x) l *)
(* Goal: forall (n : nat) (_ : is_derive_n f (S n) x l), @eq R (Derive_n f (S n) x) l *)
  easy.
(* Goal: forall (n : nat) (_ : is_derive_n f (S n) x l), @eq R (Derive_n f (S n) x) l *)
  simpl; intros n0 H.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  now apply is_derive_unique.
Qed.

Lemma Derive_n_correct f n x :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n f n x -> is_derive_n f n x (Derive_n f n x).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n => /= [ | n] Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Derive_correct.
Qed.

(** Extensionality *)

Lemma Derive_n_ext_loc :
  forall f g n x,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => f t = g t) ->
  Derive_n f n x = Derive_n g n x.
Proof.
(* Goal: forall (f g : forall _ : R, R) (n : nat) (x : AbsRing.sort R_AbsRing) (_ : forall t : R, @eq R (f t) (g t)) (_ : ex_derive_n f n x), ex_derive_n g n x *)
intros f g n x Heq.
(* Goal: @eq R (Derive_n f n x) (Derive_n g n x) *)
pattern x ; apply locally_singleton.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) n x) (Derive_n f (Init.Nat.add n m) x) *)
induction n.
(* Goal: @locally R_UniformSpace x (fun s : UniformSpace.sort R_UniformSpace => @eq R (Derive_n f O s) (Derive_n g O s)) *)
(* Goal: @locally R_UniformSpace x (fun s : UniformSpace.sort R_UniformSpace => @eq R (Derive_n f (S n) s) (Derive_n g (S n) s)) *)
exact Heq.
(* Goal: @locally R_UniformSpace x (fun s : UniformSpace.sort R_UniformSpace => @eq R (Derive_n f (S n) s) (Derive_n g (S n) s)) *)
apply locally_locally in IHn.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
apply filter_imp with (2 := IHn) => {IHn}.
(* Goal: forall (x : UniformSpace.sort R_UniformSpace) (_ : @locally R_UniformSpace x (fun s : UniformSpace.sort R_UniformSpace => @eq R (Derive_n f n s) (Derive_n g n s))), @eq R (Derive_n f (S n) x) (Derive_n g (S n) x) *)
intros t H.
(* Goal: @eq R (Derive (Derive_n (fun x : R => Rplus (f x) (g x)) n) x) (Derive (fun x : R => Rplus (Derive_n f n x) (Derive_n g n x)) x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
now apply Derive_ext_loc.
Qed.

Lemma ex_derive_n_ext_loc :
  forall f g n x,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => f t = g t) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n f n x -> ex_derive_n g n x.
Proof.
(* Goal: forall (f g : forall _ : R, R) (n : nat) (x : AbsRing.sort R_AbsRing) (_ : forall t : R, @eq R (f t) (g t)) (_ : ex_derive_n f n x), ex_derive_n g n x *)
intros f g n x Heq.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
case: n => /= [ | n].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by [].
(* Goal: forall _ : @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x, @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
apply ex_derive_ext_loc.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Derive_n f n t) (Derive_n g n t)) *)
apply locally_locally in Heq.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
apply filter_imp with (2 := Heq) => {Heq}.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by apply Derive_n_ext_loc.
Qed.

Lemma is_derive_n_ext_loc :
  forall f g n x l,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => f t = g t) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n x l -> is_derive_n g n x l.
Proof.
(* Goal: forall (f g : forall _ : R, R) (n : nat) (x l : R) (_ : forall t : R, @eq R (f t) (g t)) (_ : is_derive_n f n x l), is_derive_n g n x l *)
  intros f g n x l Heq.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n => /= [ | n].
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  move => <- ; apply sym_eq.
(* Goal: @eq R (f x) (g x) *)
(* Goal: forall _ : @is_derive R_AbsRing R_NormedModule (Derive_n f n) x l, @is_derive R_AbsRing R_NormedModule (Derive_n g n) x l *)
  pattern x ; now apply locally_singleton.
(* Goal: forall _ : @is_derive R_AbsRing R_NormedModule (Derive_n f n) x l, @is_derive R_AbsRing R_NormedModule (Derive_n g n) x l *)
  apply is_derive_ext_loc.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Derive_n f n t) (Derive_n g n t)) *)
  apply locally_locally in Heq.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp with (2 := Heq) => {Heq}.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Derive_n_ext_loc.
Qed.

Lemma Derive_n_ext :
  forall f g n x,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall t, f t = g t) ->
  Derive_n f n x = Derive_n g n x.
Proof.
(* Goal: forall (f g : forall _ : R, R) (n : nat) (x : AbsRing.sort R_AbsRing) (_ : forall t : R, @eq R (f t) (g t)) (_ : ex_derive_n f n x), ex_derive_n g n x *)
intros f g n x Heq.
(* Goal: @eq R (Derive_n f n x) (Derive_n g n x) *)
apply Derive_n_ext_loc.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by apply filter_forall.
Qed.

Lemma ex_derive_n_ext :
  forall f g n x,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall t, f t = g t) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n f n x -> ex_derive_n g n x.
Proof.
(* Goal: forall (f g : forall _ : R, R) (n : nat) (x : AbsRing.sort R_AbsRing) (_ : forall t : R, @eq R (f t) (g t)) (_ : ex_derive_n f n x), ex_derive_n g n x *)
intros f g n x Heq.
(* Goal: forall _ : ex_derive_n f n x, ex_derive_n g n x *)
apply ex_derive_n_ext_loc.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by apply filter_forall.
Qed.

Lemma is_derive_n_ext :
  forall f g n x l,
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (forall t, f t = g t) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n x l -> is_derive_n g n x l.
Proof.
(* Goal: forall (f g : forall _ : R, R) (n : nat) (x l : R) (_ : forall t : R, @eq R (f t) (g t)) (_ : is_derive_n f n x l), is_derive_n g n x l *)
intros f g n x l Heq.
(* Goal: forall _ : is_derive_n f n x l, is_derive_n g n x l *)
apply is_derive_n_ext_loc.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
by apply filter_forall.
Qed.

Lemma Derive_n_comp: forall f n m x,
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  Derive_n (Derive_n f m) n x = Derive_n f (n+m) x.
Proof.
(* Goal: forall (f : forall _ : R, R) (n m : nat) (x : R), @eq R (Derive_n (Derive_n f m) n x) (Derive_n f (Init.Nat.add n m) x) *)
intros f n m.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) n x) (Derive_n f (Init.Nat.add n m) x) *)
induction n.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
now simpl.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
simpl.
(* Goal: forall x : R, @eq R (Derive (Derive_n (Derive_n f m) n) x) (Derive (Derive_n f (Init.Nat.add n m)) x) *)
intros x.
(* Goal: @eq R (Derive (Derive_n (Derive_n f m) n) x) (Derive (Derive_n f (Init.Nat.add n m)) x) *)
now apply Derive_ext.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_Sn (f : R -> R) (n : nat) (x l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (ex_derive f) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (is_derive_n f (S n) x l <-> is_derive_n (Derive f) n x l).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n => /= [ | n].
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  split => H.
(* Goal: @eq R (Derive (fun x : R => f (g x)) x) (Rmult (Derive g x) (Derive f (g x))) *)
  by apply is_derive_unique.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -H ; apply Derive_correct.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => f x) x *)
(* Goal: iff (@is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l) (@is_derive R_AbsRing R_NormedModule (Derive_n (Derive f) n) x l) *)
  now apply locally_singleton.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  split => Hf'.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - apply is_derive_ext with (2 := Hf').
(* Goal: forall t : AbsRing.sort R_AbsRing, @eq (NormedModule.sort R_AbsRing R_NormedModule) (Derive_n (Derive f) n t) (Derive (Derive_n f n) t) *)
    move => y ; rewrite (Derive_n_comp _ n 1%nat).
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
    by (replace (n + 1)%nat with (S n) by ring).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  - apply is_derive_ext with (2 := Hf').
(* Goal: forall t : AbsRing.sort R_AbsRing, @eq (NormedModule.sort R_AbsRing R_NormedModule) (Derive_n (Derive f) n t) (Derive (Derive_n f n) t) *)
    move => y ; rewrite (Derive_n_comp _ n 1%nat).
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
    by (replace (n + 1)%nat with (S n) by ring).
Qed.

(** Constant function *)

Lemma is_derive_n_const n a : forall x, is_derive_n (fun _ => a) (S n) x 0.
Proof.
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n => /= [ | n IH] x.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply @is_derive_const.
  eapply is_derive_ext.
  intros t ; apply sym_equal, is_derive_unique, IH.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply @is_derive_const.
Qed.
Lemma ex_derive_n_const a n x: ex_derive_n (fun _  => a) n x.
Proof.
(* Goal: Rle (@norm R_AbsRing V (@minus (NormedModule.AbelianGroup R_AbsRing V) (@minus (NormedModule.AbelianGroup R_AbsRing V) (if Rle_dec x a then f x else g x) (if Rle_dec a a then f a else g a)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing V) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x a) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x a))) *)
  case: n => //= ; case => //= [ | n].
  apply ex_derive_const.
  eapply ex_derive_ext.
  intros t ; apply sym_equal, is_derive_unique, is_derive_n_const.
  by apply ex_derive_const.
Qed.
Lemma Derive_n_const n a  : forall x, Derive_n (fun _ => a) (S n) x = 0.
Proof.
(* Goal: forall x : R, @eq R (Derive_n (fun _ : R => a) (S n) x) (IZR Z0) *)
  intros x ; apply is_derive_n_unique, is_derive_n_const.
Qed.

(** ** Operations *)
(** *** Additive operators *)
(** Opposite *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_opp (f : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  Derive_n (fun x => - f x) n x = - Derive_n f n x.
Proof.
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n x => [ | n IH] x /=.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Derive_opp.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Derive_ext.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_opp (f : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n f n x -> ex_derive_n (fun x => -f x) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n x => [ | n] /= x Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x *)
  apply ex_derive_opp in Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply: ex_derive_ext Hf.
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
(* Goal: is_derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y ; by rewrite Derive_n_opp.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_opp (f : R -> R) (n : nat) (x l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n x l -> is_derive_n (fun x => -f x) n x (- l).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n x => [ | n] /= x Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply is_derive_opp in Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply: is_derive_ext Hf.
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
(* Goal: is_derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y ; by rewrite Derive_n_opp.
Qed.

(** Addition of functions *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_plus (f g : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n f k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n g k y) ->
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  Derive_n (fun x => f x + g x) n x = Derive_n f n x + Derive_n g n x.
Proof.
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n x => /= [ | n IH] x [rf Hf] [rg Hg].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Derive_plus.
(* Goal: @eq R (Derive (Derive_n (fun x : R => Rplus (f x) (g x)) n) x) (Derive (fun x : R => Rplus (Derive_n f n x) (Derive_n g n x)) x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Derive_ext_loc.
  set r := (mkposreal _ (Rmin_stable_in_posreal rf rg)) ;
  exists r => y Hy.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /ball /= /AbsRing_ball /= in Hy.
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  apply Rabs_lt_between' in Hy.
(* Goal: @eq R (Derive_n (fun x : R => Rplus (f x) (g x)) n y) (Rplus (Derive_n f n y) (Derive_n g n y)) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  case: Hy ; move/Rlt_Rminus => Hy1 ; move/Rlt_Rminus => Hy2.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos (mkposreal (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y)) Hy)) y0), @eq R (Derive_n (fun y : R => f (Rmult a y)) n y0) (Rmult (pow a n) (Derive_n f n (Rmult a y0))) *)
  set r0 := mkposreal _ (Rmin_pos _ _ Hy1 Hy2).
  apply IH ;
  exists r0 => z Hz k Hk.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Hf.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /ball /= /AbsRing_ball /= in Hz.
(* Goal: @ball R_UniformSpace x (pos rg) z *)
(* Goal: le k (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Rabs_lt_between' in Hz.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /Rminus -Rmax_opp_Rmin Rplus_max_distr_l (Rplus_min_distr_l y) in Hz.
(* Goal: @ball R_UniformSpace x (pos rg) z *)
(* Goal: le k (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  case: Hz ; move => Hz1 Hz2.
(* Goal: @ball R_UniformSpace x (pos rg) z *)
(* Goal: le k (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Rle_lt_trans with (1 := Rmax_l _ _) in Hz1 ; ring_simplify in Hz1.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply Rlt_le_trans with (2 := Rmin_r _ _) in Hz2 ; ring_simplify (y + (x + Rmin rf rg + - y)) in Hz2.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  have Hz := (conj Hz1 Hz2) => {Hz1 Hz2}.
(* Goal: @ball R_UniformSpace x (pos rg) z *)
(* Goal: le k (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Rabs_lt_between' in Hz.
  apply Rlt_le_trans with (1 := Hz) => /= ; by apply Rmin_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply le_trans with (1 := Hk), le_n_Sn.
(* Goal: ex_derive_n g k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Hg.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /ball /= /AbsRing_ball /= in Hz.
(* Goal: @ball R_UniformSpace x (pos rg) z *)
(* Goal: le k (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Rabs_lt_between' in Hz.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /Rminus -Rmax_opp_Rmin Rplus_max_distr_l (Rplus_min_distr_l y) in Hz.
(* Goal: @ball R_UniformSpace x (pos rg) z *)
(* Goal: le k (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  case: Hz ; move => Hz1 Hz2.
(* Goal: @ball R_UniformSpace x (pos rg) z *)
(* Goal: le k (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Rle_lt_trans with (1 := Rmax_l _ _) in Hz1 ; ring_simplify in Hz1.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply Rlt_le_trans with (2 := Rmin_r _ _) in Hz2 ; ring_simplify (y + (x + Rmin rf rg + - y)) in Hz2.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  have Hz := (conj Hz1 Hz2) => {Hz1 Hz2}.
(* Goal: @ball R_UniformSpace x (pos rg) z *)
(* Goal: le k (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Rabs_lt_between' in Hz.
  apply Rlt_le_trans with (1 := Hz) => /= ; by apply Rmin_r.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply le_trans with (1 := Hk), le_n_Sn.
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) (Rmult a y) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Rmult a) y *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  apply Hf with (k := (S n)).
(* Goal: @ball (NormedModule.UniformSpace K U) x (pos d) x *)
(* Goal: @eq (NormedModule.sort K U) x y *)
  by apply ball_center.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply le_refl.
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply Hg with (k := S n).
(* Goal: @ball (NormedModule.UniformSpace K U) x (pos d) x *)
(* Goal: @eq (NormedModule.sort K U) x y *)
  by apply ball_center.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply le_refl.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_plus (f g : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n f k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n g k y) ->
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  ex_derive_n (fun x => f x + g x) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n x => /= [ | n] x Hf Hg.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  apply ex_derive_ext_loc with (fun y => Derive_n f n y + Derive_n g n y).
  apply locally_locally in Hf.
  apply locally_locally in Hg.
  generalize (filter_and _ _ Hf Hg).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp => {Hf Hg} y [Hf Hg].
(* Goal: @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rplus (Derive_n f n y) (Derive_n g n y)) (Derive_n (fun x : R => Rplus (f x) (g x)) n y) *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun y : R => Rplus (Derive_n f n y) (Derive_n g n y)) x (Rplus lf lg) *)
  apply sym_eq, Derive_n_plus.
  apply filter_imp with (2 := Hf) ; by intuition.
  apply filter_imp with (2 := Hg) ; by intuition.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply: ex_derive_plus.
  apply locally_singleton ; apply filter_imp with (2 := Hf) => {Hf} y Hy ;
  by apply (Hy (S n)).
  apply locally_singleton ; apply filter_imp with (2 := Hg) => {Hg} y Hy ;
  by apply (Hy (S n)).
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_plus (f g : R -> R) (n : nat) (x lf lg : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n f k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n g k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n x lf -> is_derive_n g n x lg ->
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  is_derive_n (fun x => f x + g x) n x (lf + lg).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n x lf lg => /= [ | n] x lf lg Hfn Hgn Hf Hg.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Hf Hg.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  apply is_derive_ext_loc with (fun y => Derive_n f n y + Derive_n g n y).
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rplus (Derive_n f n t) (Derive_n g n t)) (Derive_n (fun x : R => Rplus (f x) (g x)) n t)) *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun y : R => Rplus (Derive_n f n y) (Derive_n g n y)) x (Rplus lf lg) *)
  apply locally_locally in Hfn.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rplus (Derive_n f n t) (Derive_n g n t)) (Derive_n (fun x : R => Rplus (f x) (g x)) n t)) *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun y : R => Rplus (Derive_n f n y) (Derive_n g n y)) x (Rplus lf lg) *)
  apply locally_locally in Hgn.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rplus (Derive_n f n t) (Derive_n g n t)) (Derive_n (fun x : R => Rplus (f x) (g x)) n t)) *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun y : R => Rplus (Derive_n f n y) (Derive_n g n y)) x (Rplus lf lg) *)
  generalize (filter_and _ _ Hfn Hgn).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply filter_imp => {Hfn Hgn} y [Hfn Hgn].
(* Goal: @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rplus (Derive_n f n y) (Derive_n g n y)) (Derive_n (fun x : R => Rplus (f x) (g x)) n y) *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun y : R => Rplus (Derive_n f n y) (Derive_n g n y)) x (Rplus lf lg) *)
  apply sym_eq, Derive_n_plus.
(* Goal: @locally R_UniformSpace y (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y) *)
(* Goal: @locally R_UniformSpace y (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n g k y) *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun y : R => Rplus (Derive_n f n y) (Derive_n g n y)) x (Rplus lf lg) *)
  apply filter_imp with (2 := Hfn) ; by intuition.
(* Goal: @locally R_UniformSpace y (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n g k y) *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun y : R => Rplus (Derive_n f n y) (Derive_n g n y)) x (Rplus lf lg) *)
  apply filter_imp with (2 := Hgn) ; by intuition.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply: is_derive_plus.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_iter_plus {I : Type} (l : list I) (f : I -> R -> R) (n: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall (j : I) (k : nat), List.In j l -> (k <= n)%nat -> ex_derive_n (f j) k y) ->
  is_derive_n (fun y => iter Rplus 0 l (fun j => f j y)) n x
    (iter Rplus 0 l (fun j => Derive_n (f j) n x)).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (j : I) (k : nat) (_ : @List.In I j l) (_ : le k n), ex_derive_n (f j) k y), @eq R (Derive_n (fun y : R => @iter I R Rplus (IZR Z0) l (fun j : I => f j y)) n x) (@iter I R Rplus (IZR Z0) l (fun j : I => Derive_n (f j) n x)) *)
  intros H.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  elim: n {-2}n x (le_refl n) H => [ | n IH] m x Hn Hx.
  now replace m with O by intuition.
  apply le_lt_eq_dec in Hn ; case: Hn => Hn.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply IH => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply lt_n_Sm_le.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite Hn in Hx |- * => {m Hn} /=.
  eapply is_derive_ext_loc.
  eapply filter_imp.
  intros y Hy.
  apply sym_equal, is_derive_n_unique.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t))) *)
  apply IH.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply le_refl.
  apply Hy.
  apply locally_locally.
  move: Hx ; apply filter_imp.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => y Hy j k Hj Hk.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply Hy => //.
  now eapply le_trans, le_n_Sn.
  eapply filterdiff_ext_lin.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply @filterdiff_iter_plus_fct => //.
  apply locally_filter.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x (Derive_n (fun y : R => f (Rmult a y)) (S n) x) *)
  apply Derive_correct.
  apply ((locally_singleton _ _ Hx) j (S n) H (le_refl _)).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  simpl => y.
  clear ; elim: l => /= [ | h l IH].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite scal_zero_r.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite IH scal_distr_l.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_iter_plus {I : Type} (l : list I) (f : I -> R -> R) (n: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall (j : I) (k : nat), List.In j l -> (k <= n)%nat -> ex_derive_n (f j) k y) ->
  ex_derive_n (fun y => iter Rplus 0 l (fun j => f j y)) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n => //= n H.
  eexists.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply (is_derive_n_iter_plus l f (S n)).
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_iter_plus {I : Type} (l : list I) (f : I -> R -> R) (n: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall (j : I) (k : nat), List.In j l -> (k <= n)%nat -> ex_derive_n (f j) k y) ->
  Derive_n (fun y => iter Rplus 0 l (fun j => f j y)) n x =
    iter Rplus 0 l (fun j => Derive_n (f j) n x).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (j : I) (k : nat) (_ : @List.In I j l) (_ : le k n), ex_derive_n (f j) k y), @eq R (Derive_n (fun y : R => @iter I R Rplus (IZR Z0) l (fun j : I => f j y)) n x) (@iter I R Rplus (IZR Z0) l (fun j : I => Derive_n (f j) n x)) *)
  intros H.
(* Goal: @eq R (Derive_n (fun y : R => @iter I R Rplus (IZR Z0) l (fun j : I => f j y)) n x) (@iter I R Rplus (IZR Z0) l (fun j : I => Derive_n (f j) n x)) *)
  apply is_derive_n_unique.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_derive_n_iter_plus.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_sum_n_m n m (f : nat -> R -> R) (k: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => forall l j , (n <= l <= m)%nat ->(j <= k)%nat -> ex_derive_n (f l) j t) ->
  is_derive_n (fun y => sum_n_m (fun j => f j y) n m) k x
    (sum_n_m (fun j => Derive_n (f j) k x) n m).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: is_derive_n (fun y : R => @sum_n_m R_AbelianGroup (fun j : nat => f j y) n m) k x (@sum_n_m R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n m) *)
  apply is_derive_n_iter_plus.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  move: H ; apply filter_imp ; intros.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply H => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply In_iota.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_sum_n_m n m (f : nat -> R -> R) (k: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => forall l j , (n <= l <= m)%nat ->(j <= k)%nat -> ex_derive_n (f l) j t) ->
  ex_derive_n (fun y => sum_n_m (fun j => f j y) n m) k x.
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: ex_derive_n (fun y : R => @sum_n_m R_AbelianGroup (fun j : nat => f j y) n m) k x *)
  apply ex_derive_n_iter_plus.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  move: H ; apply filter_imp ; intros.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply H => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply In_iota.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_sum_n_m n m (f : nat -> R -> R) (k: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => forall l j , (n <= l <= m)%nat ->(j <= k)%nat -> ex_derive_n (f l) j t) ->
  Derive_n (fun y => sum_n_m (fun j => f j y) n m) k x
    = sum_n_m (fun j => Derive_n (f j) k x) n m.
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: @eq R (Derive_n (fun y : R => @sum_n_m R_AbelianGroup (fun j : nat => f j y) n m) k x) (@sum_n_m R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n m) *)
  apply Derive_n_iter_plus.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  move: H ; apply filter_imp ; intros.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply H => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply In_iota.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_sum_n n (f : nat -> R -> R) (k: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => forall l j , (l <= n)%nat ->(j <= k)%nat -> ex_derive_n (f l) j t) ->
  is_derive_n (fun y => sum_n (fun j => f j y) n) k x
    (sum_n (fun j => Derive_n (f j) k x) n).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: is_derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  apply is_derive_n_sum_n_m.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  move: H ; apply filter_imp ; intros.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply H => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply H0.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_sum_n n (f : nat -> R -> R) (k: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => forall l j , (l <= n)%nat ->(j <= k)%nat -> ex_derive_n (f l) j t) ->
  ex_derive_n (fun y => sum_n (fun j => f j y) n) k x.
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: ex_derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x *)
  apply ex_derive_n_sum_n_m.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  move: H ; apply filter_imp ; intros.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply H => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply H0.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_sum_n n (f : nat -> R -> R) (k: nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun t => forall l j , (l <= n)%nat ->(j <= k)%nat -> ex_derive_n (f l) j t) ->
  Derive_n (fun y => sum_n (fun j => f j y) n) k x =
    (sum_n (fun j => Derive_n (f j) k x) n).
Proof.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  intros.
(* Goal: @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  apply Derive_n_sum_n_m.
(* Goal: forall _ : @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => forall (l j : nat) (_ : le l n) (_ : le j k), ex_derive_n (f l) j t), @eq R (Derive_n (fun y : R => @sum_n R_AbelianGroup (fun j : nat => f j y) n) k x) (@sum_n R_AbelianGroup (fun j : nat => Derive_n (f j) k x) n) *)
  move: H ; apply filter_imp ; intros.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply H => //.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply H0.
Qed.

(** Subtraction of functions *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_minus (f g : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n f k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n g k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  Derive_n (fun x => f x - g x) n x = Derive_n f n x - Derive_n g n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf Hg.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Derive_n_plus.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Derive_n_opp.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n (fun x : R => Ropp (g x)) k y) *)
(* Goal: is_derive_n f n x lf *)
(* Goal: is_derive_n (fun x : R => Ropp (g x)) n x (Ropp lg) *)
  move: Hg ; apply filter_imp => y Hg k Hk.
(* Goal: ex_derive_n g k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply ex_derive_n_opp ; by apply Hg.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_minus (f g : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n f k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n g k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n (fun x => f x - g x) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf Hg.
(* Goal: ex_derive_n (fun x : R => Rminus (f x) (g x)) n x *)
  apply ex_derive_n_plus.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n (fun x : R => Ropp (g x)) k y) *)
(* Goal: is_derive_n f n x lf *)
(* Goal: is_derive_n (fun x : R => Ropp (g x)) n x (Ropp lg) *)
  move: Hg ; apply filter_imp => y Hg k Hk.
(* Goal: ex_derive_n g k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply ex_derive_n_opp ; by apply Hg.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_minus (f g : R -> R) (n : nat) (x lf lg : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n f k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally x (fun y => forall k, (k <= n)%nat -> ex_derive_n g k y) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n x lf -> is_derive_n g n x lg ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n (fun x => f x - g x) n x (lf - lg).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf Hg Df Dg.
(* Goal: is_derive_n (fun x : R => Rminus (f x) (g x)) n x (Rminus lf lg) *)
  apply is_derive_n_plus.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @locally R_UniformSpace x (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n (fun x : R => Ropp (g x)) k y) *)
(* Goal: is_derive_n f n x lf *)
(* Goal: is_derive_n (fun x : R => Ropp (g x)) n x (Ropp lg) *)
  move: Hg ; apply filter_imp => y Hg k Hk.
(* Goal: ex_derive_n g k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n g n) x *)
  apply ex_derive_n_opp ; by apply Hg.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply is_derive_n_opp.
Qed.

(** *** Multiplicative operators *)

(** Scalar multiplication *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_scal_l (f : R -> R) (n : nat) (a x : R) :
  Derive_n (fun y => a * f y) n x = a * Derive_n f n x.
Proof.
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n x => /= [ | n IH] x.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Derive_scal.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Derive_ext.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_scal_l (f : R -> R) (n : nat) (a x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n f n x -> ex_derive_n (fun y => a * f y) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n x => /= [ | n] x Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => Rmult a (f y)) n) x *)
  apply ex_derive_ext with (fun y => a * Derive_n f n y).
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
(* Goal: is_derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => t ; by rewrite Derive_n_scal_l.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun y : R => Rmult a (Derive_n f n y)) x *)
  now apply ex_derive_scal.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_scal_l (f : R -> R) (n : nat) (a x l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n x l -> is_derive_n (fun y => a * f y) n x (a * l).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n x => /= [ | n] x Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Hf.
  eapply filterdiff_ext_lin.
  apply filterdiff_ext with (fun y => a * Derive_n f n y).
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
(* Goal: is_derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => t ; by rewrite Derive_n_scal_l.
  apply @filterdiff_scal_r_fct ; try by apply locally_filter.
  by apply Rmult_comm.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Hf.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => /= y.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /scal /= /mult /=.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  ring.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_scal_r (f : R -> R) (n : nat) (a x : R) :
  Derive_n (fun y => f y * a) n x = Derive_n f n x * a.
Proof.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite Rmult_comm -Derive_n_scal_l.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  apply Derive_n_ext => y ; ring.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_scal_r (f : R -> R) (n : nat) (a x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n f n x -> ex_derive_n (fun y => f y * a) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move/(ex_derive_n_scal_l _ _ a).
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  apply ex_derive_n_ext => y ; ring.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_scal_r (f : R -> R) (n : nat) (a x l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n x l -> is_derive_n (fun y => f y * a) n x (l * a).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move/(is_derive_n_scal_l _ _ a).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Rmult_comm.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  apply is_derive_n_ext => y ; ring.
Qed.

(** *** Composition *)

(** Composition with linear functions *)

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_comp_scal (f : R -> R) (a : R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally (a * x) (fun x => forall k, (k <= n)%nat -> ex_derive_n f k x) ->
  Derive_n (fun y => f (a * y)) n x  = (a ^ n * Derive_n f n (a * x)).
Proof.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  case: (Req_dec a 0) => [ -> _ | Ha] /=.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Rmult_0_l.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n x) (Rmult (pow (IZR Z0) n) (Derive_n f n (IZR Z0))) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  elim: n x => [ | n IH] x /= ; rewrite ?Rmult_0_l.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  ring.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite (Derive_ext _ _ _ IH).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Derive_const.

(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  apply (locally_singleton _ (fun x => Derive_n (fun y : R => f (a * y)) n x = a ^ n * Derive_n f n (a * x))).
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n Hf => [ | n IH] Hf.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  apply filter_forall => /= y ; ring.

(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: IH => [ | r IH].
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Hf => r0 Hf.
(* Goal: @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @locally R_UniformSpace x (fun x : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) (S n) x) (Rmult (pow a (S n)) (Derive_n f (S n) (Rmult a x)))) *)
  exists r0 => y Hy k Hk ; by intuition.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Hf => r0 Hf.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  have Hr1 : 0 < Rmin (r0 / (Rabs a)) r.
(* Goal: Rlt (IZR Z0) (Rmin (Rdiv (pos r0) (Rabs a)) (pos r)) *)
(* Goal: @locally R_UniformSpace x (fun x : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) (S n) x) (Rmult (pow a (S n)) (Derive_n f (S n) (Rmult a x)))) *)
    apply Rmin_case.
(* Goal: Rlt (IZR Z0) (Rdiv (pos r) (Rabs a)) *)
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rmult (pow a n) (Derive_n f n (Rmult a t))) (Derive_n (fun y : R => f (Rmult a y)) n t)) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rdiv_lt_0_compat.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply r0.
    by apply Rabs_pos_lt.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by apply r.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos (mkposreal (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y)) Hy)) y0), @eq R (Derive_n (fun y : R => f (Rmult a y)) n y0) (Rmult (pow a n) (Derive_n f n (Rmult a y0))) *)
  set r1 := mkposreal _ Hr1.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  exists r1 => y Hy /=.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite (Derive_ext_loc _ (fun y => a ^ n * Derive_n f n (a * y))).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Derive_scal.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite (Rmult_comm a (a^n)) Rmult_assoc.
(* Goal: @eq R (Rmult (pow a n) (Derive (fun x : R => Derive_n f n (Rmult a x)) y)) (Rmult (pow a n) (Rmult a (Derive (Derive_n f n) (Rmult a y)))) *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  apply f_equal.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite Derive_comp.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  rewrite (Derive_ext (Rmult a) (fun x => a * x)) => //.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
  rewrite Derive_scal Derive_id ; ring.
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) (Rmult a y) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Rmult a) y *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  apply Hf with (k := S n).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /ball /= /AbsRing_ball /= /abs /minus /plus /opp /=.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -/(Rminus _ _) -Rmult_minus_distr_l Rabs_mult.
(* Goal: Rlt (Rmult (Rabs a) (Rabs (Rminus y x))) (pos r0) *)
(* Goal: le (S n) (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Rmult a) y *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  apply Rlt_le_trans with (Rabs a * r1).
(* Goal: Rlt (Rmult (Rabs a) (Rabs (Rminus y x))) (Rmult (Rabs a) (Rdiv (pos r) (Rabs a))) *)
(* Goal: forall _ : Rlt (Rabs (Rminus (Rmult a y) (Rmult a x))) (pos r), @locally R_UniformSpace (Rmult a y) (fun x0 : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x0) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Rmult_lt_compat_l.
  by apply Rabs_pos_lt.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Hy.
(* Goal: Rle (Rmult (Rabs a) (pos r1)) (pos r0) *)
(* Goal: le (S n) (S n) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Rmult a) y *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  rewrite Rmult_comm ; apply Rle_div_r.
  by apply Rabs_pos_lt.
  rewrite /r1 ; by apply Rmin_l.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply lt_n_Sn.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply ex_derive_scal.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply ex_derive_id.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /ball /= /AbsRing_ball /= in Hy.
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  apply Rabs_lt_between' in Hy.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: Hy => Hy1 Hy2.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Rlt_Rminus in Hy1.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply Rlt_Rminus in Hy2.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  have Hy : 0 < Rmin (y - (x - r1)) (x + r1 - y).
(* Goal: Rlt (IZR Z0) (Rmin (Rdiv (pos r0) (Rabs a)) (pos r)) *)
(* Goal: @locally R_UniformSpace x (fun x : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) (S n) x) (Rmult (pow a (S n)) (Derive_n f (S n) (Rmult a x)))) *)
  by apply Rmin_case.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  exists (mkposreal (Rmin (y - (x - r1)) (x + r1 - y)) Hy).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  set r2 := Rmin (y - (x - r1)) (x + r1 - y).
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => t Ht.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t))) *)
  apply IH.
(* Goal: @ball R_UniformSpace x (pos r) t *)
  apply Rabs_lt_between'.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
  rewrite /ball /= /AbsRing_ball /= in Ht.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  apply Rabs_lt_between' in Ht.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  simpl in Ht.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
  split.
(* Goal: Rlt (Rminus x (pos r)) t *)
(* Goal: Rlt t (Rplus x (pos r)) *)
  apply Rle_lt_trans with (2 := proj1 Ht).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /r2 ; apply Rle_trans with (y-(y-(x-r1))).
(* Goal: Rle (Rminus x (pos r)) (Rminus y (Rminus y (Rminus x (pos r1)))) *)
(* Goal: Rle (Rminus y (Rminus y (Rminus x (pos r1)))) (Rminus y (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y))) *)
(* Goal: Rlt t (Rplus x (pos r)) *)
  ring_simplify ; apply Rplus_le_compat_l, Ropp_le_contravar.
  rewrite /r1 ; apply Rmin_r.
(* Goal: Rle (Rminus y (Rminus y (Rminus x (pos r1)))) (Rminus y (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y))) *)
(* Goal: Rlt t (Rplus x (pos r)) *)
  apply Rplus_le_compat_l, Ropp_le_contravar, Rmin_l.
(* Goal: Rlt t (Rplus x (pos r)) *)
  apply Rlt_le_trans with (1 := proj2 Ht).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite /r2 ; apply Rle_trans with (y+((x+r1)-y)).
(* Goal: Rle (Rplus y (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y))) (Rplus y (Rminus (Rplus x (pos r1)) y)) *)
(* Goal: Rle (Rplus y (Rminus (Rplus x (pos r1)) y)) (Rplus x (pos r)) *)
  apply Rplus_le_compat_l, Rmin_r.
(* Goal: Rle (Rplus y (Rminus (Rplus x (pos r1)) y)) (Rplus x (pos r)) *)
  ring_simplify ; apply Rplus_le_compat_l.
  rewrite /r1 ; apply Rmin_r.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_comp_scal (f : R -> R) (a : R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally (a * x) (fun x => forall k, (k <= n)%nat -> ex_derive_n f k x)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> ex_derive_n (fun y => f (a * y)) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n f x => /= [ | n] f x Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].

(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: (Req_dec a 0) => Ha.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  rewrite Ha => {a Ha Hf}.
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x *)
  apply ex_derive_ext with (fun _ => Derive_n (fun y : R => f (0 * y)) n 0).
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n => /= [ | n IH] t.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite ?Rmult_0_l.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -?(Derive_ext _ _ _ IH).
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite ?Derive_const.
  by apply ex_derive_const.
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x *)
  apply ex_derive_ext_loc with (fun x => a^n * Derive_n f n (a * x)).
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
    case: Hf => r Hf.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    have Hr0 : 0 < r / Rabs a.
(* Goal: Rlt (IZR Z0) (Rdiv (pos r) (Rabs a)) *)
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (Rmult (pow a n) (Derive_n f n (Rmult a t))) (Derive_n (fun y : R => f (Rmult a y)) n t)) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
      apply Rdiv_lt_0_compat.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
      by apply r.
      by apply Rabs_pos_lt.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
    exists (mkposreal _ Hr0) => /= y Hy.
(* Goal: @eq R (Rmult (pow a n) (Derive_n f n (Rmult a y))) (Derive_n (fun y : R => f (Rmult a y)) n y) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply eq_sym, Derive_n_comp_scal.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    have : Rabs (a*y - a*x) < r.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
      rewrite -Rmult_minus_distr_l Rabs_mult.
      replace (pos r) with (Rabs a * (r / Rabs a))
        by (field ; by apply Rgt_not_eq, Rabs_pos_lt).
(* Goal: Rlt (Rmult (Rabs a) (Rabs (Rminus y x))) (Rmult (Rabs a) (Rdiv (pos r) (Rabs a))) *)
(* Goal: forall _ : Rlt (Rabs (Rminus (Rmult a y) (Rmult a x))) (pos r), @locally R_UniformSpace (Rmult a y) (fun x0 : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x0) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
      apply Rmult_lt_compat_l.
      by apply Rabs_pos_lt.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
      by apply Hy.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
      move => {Hy} Hy.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
    apply Rabs_lt_between' in Hy ; case: Hy => Hy1 Hy2.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rlt_Rminus in Hy1.
(* Goal: @locally R_UniformSpace (Rmult a y) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rlt_Rminus in Hy2.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
    exists (mkposreal _ (Rmin_pos _ _ Hy1 Hy2)) => /= z Hz k Hk.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite /ball /= /AbsRing_ball /= in Hz.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rabs_lt_between' in Hz ; case: Hz => Hz1 Hz2.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    rewrite /Rminus -Rmax_opp_Rmin in Hz1.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rplus_min_distr_l in Hz2.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rlt_le_trans with (2 := Rmin_r _ _) in Hz2.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    ring_simplify in Hz2.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
    rewrite Rplus_max_distr_l in Hz1.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Rle_lt_trans with (1 := Rmax_l _ _) in Hz1.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    ring_simplify in Hz1.
(* Goal: ex_derive_n f k z *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
    apply Hf.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
    apply Rabs_lt_between' ; by split.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
    by intuition.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Rmult (pow a n) (Derive_n f n (Rmult a x))) x *)
  apply ex_derive_scal.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Derive_n f n (Rmult a x)) x *)
  apply ex_derive_comp.
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) (Rmult a x) *)
(* Goal: @ex_derive R_AbsRing (AbsRing_NormedModule R_AbsRing) (Rmult a) x *)
  apply (locally_singleton _ _) in Hf.
(* Goal: @ex_derive R_AbsRing R_NormedModule (Derive_n f n) (Rmult a y) *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (Rmult a) y *)
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun y : R => f (Rmult a y)) n t) (Rmult (pow a n) (Derive_n f n (Rmult a t)))) *)
  by apply Hf with (k := S n).

(* Goal: @ex_derive R_AbsRing (AbsRing_NormedModule R_AbsRing) (Rmult a) x *)
  apply (ex_derive_scal id a x (ex_derive_id _)).
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_comp_scal (f : R -> R) (a : R) (n : nat) (x l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally (a * x) (fun x => forall k, (k <= n)%nat -> ex_derive_n f k x)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> is_derive_n f n (a * x) l
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  -> is_derive_n (fun y => f (a * y)) n x (a ^ n * l).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n => /= [ | n] Hfn Hf.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite Rmult_1_l.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x (Rmult (Rmult a (pow a n)) l) *)
  apply is_derive_unique in Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -(Derive_n_comp_scal f a (S n) x) => //.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x (Derive_n (fun y : R => f (Rmult a y)) (S n) x) *)
  apply Derive_correct.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply (ex_derive_n_comp_scal f a (S n) x).
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_comp_opp (f : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally (- x) (fun y => (forall k, (k <= n)%nat -> ex_derive_n f k y)) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  Derive_n (fun y => f (- y)) n x  = ((-1) ^ n * Derive_n f n (-x)).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite -(Derive_n_ext (fun y : R => f (-1 * y))).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  rewrite (Derive_n_comp_scal f (-1) n x).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by replace (-1*x) with (-x) by ring.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by replace (-1*x) with (-x) by ring.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  move => t ; by replace (-1*t) with (-t) by ring.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_comp_opp (f : R -> R) (n : nat) (x : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally (- x) (fun y => (forall k, (k <= n)%nat -> ex_derive_n f k y)) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n (fun y => f (- y)) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply (ex_derive_n_ext (fun y : R => f (-1 * y))).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  move => t ; by ring_simplify (-1*t).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply (ex_derive_n_comp_scal f (-1) n x).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by replace (-1*x) with (-x) by ring.
Qed.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_comp_opp (f : R -> R) (n : nat) (x l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  locally (- x) (fun y => (forall k, (k <= n)%nat -> ex_derive_n f k y)) ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n (-x) l ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n (fun y => f (- y)) n x ((-1)^n * l).
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move => Hfn Hf.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply (is_derive_n_ext (fun y : R => f (-1 * y))).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  move => t ; by ring_simplify (-1*t).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  apply (is_derive_n_comp_scal f (-1) n x).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by replace (-1*x) with (-x) by ring.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  by replace (-1*x) with (-x) by ring.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma Derive_n_comp_trans (f : R -> R) (n : nat) (x b : R) :
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  Derive_n (fun y => f (y + b)) n x  = Derive_n f n (x + b).
Proof.
(* Goal: @eq R (Derive_n (fun y : R => f (Rplus y b)) n x) (Derive_n f n (Rplus x b)) *)
  elim: n x => [ | n IH] x /=.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  rewrite (Derive_ext _ _ _ IH) => {IH}.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  generalize (Derive_n f n) => {f} f.
(* Goal: @eq R (Derive (fun x : R => f (Rplus x b)) x) (Derive f (Rplus x b)) *)
  apply (f_equal real).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  apply Lim_ext => y.
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  replace (x + b + y) with (x + y + b) by ring.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma ex_derive_n_comp_trans (f : R -> R) (n : nat) (x b : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ex_derive_n f n (x + b) ->
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  ex_derive_n (fun y => f (y + b)) n x.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n => [ | n] /= Df.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  apply ex_derive_ext with (fun x => Derive_n f n (x + b)).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  simpl => t.
  apply sym_eq, Derive_n_comp_trans.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move: (Derive_n f n) Df => {f} f Df.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun x : R => Derive_n f n (Rmult a x)) x *)
  apply ex_derive_comp.
(* Goal: @is_derive R_AbsRing R_NormedModule f z (df z) *)
(* Goal: continuity_pt f z *)
(* Goal: Rlt (IZR Z0) (Rmult (df c) (Rminus y x)) *)
  apply Df.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
  apply: ex_derive_plus.
  apply ex_derive_id.
  apply ex_derive_const.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
Lemma is_derive_n_comp_trans (f : R -> R) (n : nat) (x b l : R) :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  is_derive_n f n (x + b) l ->
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  is_derive_n (fun y => f (y + b)) n x l.
Proof.
(* Goal: forall (_ : @locally R_UniformSpace (Rmult a x) (fun x : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k x)) (_ : is_derive_n f n (Rmult a x) l), is_derive_n (fun y : R => f (Rmult a y)) n x (Rmult (pow a n) l) *)
  case: n => [ | n] /= Df.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by [].
(* Goal: F (fun x0 : UniformSpace.sort (NormedModule.UniformSpace K U) => Rle (@norm K V (@minus (NormedModule.AbelianGroup K V) (@minus (NormedModule.AbelianGroup K V) (f x0) (f x)) (l2 (@minus (NormedModule.AbelianGroup K U) x0 x)))) (Rmult (pos eps) (@norm K U (@minus (NormedModule.AbelianGroup K U) x0 x)))) *)
  apply is_derive_ext with (fun x => Derive_n f n (x + b)).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  simpl => t.
  apply sym_eq, Derive_n_comp_trans.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
  move: (Derive_n f n) Df => {f} f Df.
  eapply filterdiff_ext_lin.
  apply @filterdiff_comp'.
  apply @filterdiff_plus_fct ; try by apply locally_filter.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_id.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply filterdiff_const.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by apply Df.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
  simpl => y.
(* Goal: @eq R (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) (Rdiv (Rminus (f (Rplus (Rplus x y) b)) (f (Rplus x b))) y) *)
  by rewrite plus_zero_r.
Qed.

(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
(** * Taylor-Lagrange formula *)

Theorem Taylor_Lagrange :
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  forall f n x y, x < y ->
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  ( forall t, x <= t <= y -> forall k, (k <= S n)%nat -> ex_derive_n f k t ) ->
  exists zeta, x < zeta < y /\
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    f y =  sum_f_R0 (fun m => (y-x) ^ m / INR (fact m) * Derive_n f m x )  n
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
        + (y-x) ^ (S n) / INR (fact (S n)) * Derive_n f (S n) zeta.
Proof.
intros f n x y Hxy Df.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
pose (c:= (f y - sum_f_R0 (fun m => (y-x) ^ m / INR (fact m) * Derive_n f m x )  n)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
                / (y-x) ^ (S n)).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
pose (g t := f y - sum_f_R0 (fun m => (y-t) ^ m / INR (fact m) * Derive_n f m t )  n
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
               - c * (y-t) ^ (S n)).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
assert (Dg : forall t, x <= t <= y -> is_derive g t
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
  (- (y-t) ^ n / INR (fact n) * Derive_n f (S n) t + c * INR (S n) * (y-t) ^ n)).
intros t Ht.
unfold g.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
assert (Dp: forall n, derivable_pt_lim (fun x0 : R => (y - x0) ^ S n) t (INR (S n) * (y - t) ^ n * (0 - 1))).
intros m.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
apply (derivable_pt_lim_comp (fun t => y - t) (fun t => t ^ (S m))).
apply derivable_pt_lim_minus.
apply derivable_pt_lim_const.
apply derivable_pt_lim_id.
apply derivable_pt_lim_pow.
(* *)
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun x : R => Ropp (f x)) n) x (Ropp l) *)
apply: is_derive_plus.
(* . *)
clear c g.
rename n into N.
generalize (le_refl N).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
generalize N at -2.
intros n Hn.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
move: Hn.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) n x) (Derive_n f (Init.Nat.add n m) x) *)
induction n.
(* .. *)
intros _.
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
simpl.
eapply filterdiff_ext_lin.
apply @filterdiff_minus_fct ; try by apply locally_filter.
(* Goal: @filterdiff K (AbsRing_NormedModule K) V (fun _ : AbsRing.sort K => a) (@locally (AbsRing_UniformSpace K) x) (fun _ : AbsRing.sort K => @zero (NormedModule.AbelianGroup K V)) *)
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@zero (NormedModule.AbelianGroup K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@zero (NormedModule.AbelianGroup K V))) *)
apply filterdiff_const.
apply @filterdiff_scal_r_fct with (f := fun u => f u).
by apply locally_filter.
by apply Rmult_comm.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x (Derive_n (fun y : R => f (Rmult a y)) (S n) x) *)
apply Derive_correct.
apply (Df t Ht 1%nat).
apply le_n_S.
apply le_0_n.
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
simpl => z.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite /minus /plus /opp /zero /scal /= /mult /=.
field.
(* .. *)
intros Hn.
apply filterdiff_ext with (fun x0 : R =>
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
   (f y -
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
   (sum_f_R0 (fun m : nat => (y - x0) ^ m / INR (fact m) * Derive_n f m x0) n)) -
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
    (y - x0) ^ (S n) / INR (fact (S n)) *
     Derive_n f (S n) x0).
(* Goal: forall x : R, @eq R (Derive_n (Derive_n f m) (S n) x) (Derive_n f (Init.Nat.add (S n) m) x) *)
simpl.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
intros; ring.
eapply filterdiff_ext_lin.
apply @filterdiff_plus_fct ; try by apply locally_filter.
apply IHn.
now apply lt_le_weak.
apply @filterdiff_opp_fct ; try by apply locally_filter.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
generalize (filterdiff_mult_fct (fun x0 => ((y - x0) ^ S n / INR (fact (S n))))
  (fun x0 => Derive_n f (S n) x0)) => /= H.
apply H ; clear H.
by apply Rmult_comm.
apply @filterdiff_scal_l_fct ; try by apply locally_filter.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
generalize (filterdiff_comp' (fun u => y - u) (fun x => pow x (S n))) => /= H ;
apply H ; clear H.
apply @filterdiff_minus_fct ; try apply locally_filter.
(* Goal: @filterdiff K (AbsRing_NormedModule K) V (fun _ : AbsRing.sort K => a) (@locally (AbsRing_UniformSpace K) x) (fun _ : AbsRing.sort K => @zero (NormedModule.AbelianGroup K V)) *)
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K V) (@zero (NormedModule.AbelianGroup K V)) (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K V) y (@zero (NormedModule.AbelianGroup K V))) *)
apply filterdiff_const.
(* Goal: @filterdiff K (AbsRing_NormedModule K) (AbsRing_NormedModule K) (fun t : AbsRing.sort K => t) (@locally (AbsRing_UniformSpace K) x) (fun t : AbsRing.sort K => t) *)
(* Goal: forall y : NormedModule.sort K (AbsRing_NormedModule K), @eq (NormedModule.sort K (AbsRing_NormedModule K)) y (@scal (AbsRing.Ring K) (NormedModule.ModuleSpace K (AbsRing_NormedModule K)) y (@one (AbsRing.Ring K))) *)
apply filterdiff_id.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => pow (f x) n) x (Rmult (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) l) *)
apply is_derive_Reals.
apply (derivable_pt_lim_pow _ (S n)).
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x (Derive_n (fun y : R => f (Rmult a y)) (S n) x) *)
apply Derive_correct.
apply (Df t Ht (S (S n))).
now apply le_n_S.
(* Goal: forall (_ : @locally R_UniformSpace (Ropp x) (fun y : UniformSpace.sort R_UniformSpace => forall (k : nat) (_ : le k n), ex_derive_n f k y)) (_ : is_derive_n f n (Ropp x) l), is_derive_n (fun y : R => f (Ropp y)) n x (Rmult (pow (IZR (Zneg xH)) n) l) *)
move => z.
change (fact (S n)) with ((S n)*fact n)%nat.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite mult_INR.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos (mkposreal (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y)) Hy)) y0), @eq R (Derive_n (fun y : R => f (Rmult a y)) n y0) (Rmult (pow a n) (Derive_n f n (Rmult a y0))) *)
set v := INR (S n).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite /minus /plus /opp /zero /scal /= /mult /=.
field.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
split.
apply INR_fact_neq_0.
now apply not_0_INR.
(* . *)
eapply filterdiff_ext_lin.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
apply filterdiff_ext with (fun x0 : R => -c * (y - x0) ^ S n).
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
simpl => z ; ring.
apply @filterdiff_scal_r_fct ; try by apply locally_filter.
by apply Rmult_comm.
apply is_derive_Reals, Dp.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos (mkposreal (Rmin (Rminus y (Rminus x (pos r1))) (Rminus (Rplus x (pos r1)) y)) Hy)) y0), @eq R (Derive_n (fun y : R => f (Rmult a y)) n y0) (Rmult (pow a n) (Derive_n f n (Rmult a y0))) *)
set v := INR (S n).
(* Goal: @eq Rbar (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x h) b)) (f (Rplus x b))) h) (Finite (IZR Z0))) (Lim (fun h : R => Rdiv (Rminus (f (Rplus (Rplus x b) h)) (f (Rplus x b))) h) (Finite (IZR Z0))) *)
simpl => z.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite /scal /= /mult /=.
(* Goal: @eq R (f (IZR Z0)) (Rmult (IZR (Zpos xH)) (f (IZR Z0))) *)
(* Goal: @eq R (Derive (Derive_n (fun y : R => f (Rmult (IZR Z0) y)) n) x) (IZR Z0) *)
(* Goal: forall _ : @locally R_UniformSpace (Rmult a x) (fun x : R => forall (k : nat) (_ : le k n), ex_derive_n f k x), @eq R (Derive_n (fun y : R => f (Rmult a y)) n x) (Rmult (pow a n) (Derive_n f n (Rmult a x))) *)
ring.
(* *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
assert (Dg' : forall t : R, x <= t <= y -> derivable_pt g t).
intros t Ht.
exists (Derive g t).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => pow (f x) n) x (Rmult (Rmult (INR n) (pow (f x) (Init.Nat.pred n))) l) *)
apply is_derive_Reals.
(* Goal: @is_derive R_AbsRing R_NormedModule (Derive_n (fun y : R => f (Rmult a y)) n) x (Derive_n (fun y : R => f (Rmult a y)) (S n) x) *)
apply Derive_correct.
eexists.
apply (Dg t Ht).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
assert (pr : forall t : R, x < t < y -> derivable_pt g t).
intros t Ht.
apply Dg'.
split ; now apply Rlt_le.
(* *)
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
assert (Zxy: (y - x) ^ (S n) <> 0).
apply pow_nonzero.
apply Rgt_not_eq.
apply Rplus_gt_reg_l with x.
(* Goal: Rle (Rplus (IZR Z0) a) (Rplus (Rminus c a) a) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
(* Goal: @ex R (fun c : R => and (@eq R (Rminus (f b) (f a)) (Rmult (df c) (Rminus b a))) (Rle (Rabs (Rminus c a)) (Rminus b a))) *)
now ring_simplify.
(* *)
destruct (Rolle g x y pr) as (zeta, (Hzeta1,Hzeta2)).
intros t Ht.
(* Goal: continuity_pt h x *)
(* Goal: forall (_ : @eq R x b) (_ : Rlt a x), continuity_pt h x *)
(* Goal: forall _ : @eq R a x, continuity_pt h x *)
(* Goal: forall (x : R) (P : and (Rlt a x) (Rlt x b)), @eq R (derive_pt h x (pr x P)) (IZR Z0) *)
(* Goal: @ex R (fun C : R => forall (x : R) (_ : and (Rle a x) (Rle x b)), @eq R (f x) (Rplus (g x) C)) *)
apply derivable_continuous_pt.
now apply Dg'.
exact Hxy.
apply trans_eq with 0.
unfold g, c.
now field.
unfold g.
destruct n.
simpl; field.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite decomp_sum.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite sum_eq_R0.
simpl; field.
intros; simpl; field.
exact (INR_fact_neq_0 (S n0)).
apply lt_0_Sn.
exists zeta.
apply (conj Hzeta1).
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite Rmult_assoc.
replace (/ INR (fact (S n)) * Derive_n f (S n) zeta) with c.
unfold c.
now field.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
apply Rmult_eq_reg_r with (INR (S n) * (y - zeta) ^ n).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
apply Rplus_eq_reg_l with ((- (y - zeta) ^ n / INR (fact n) * Derive_n f (S n) zeta)).
change (fact (S n)) with (S n * fact n)%nat.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite mult_INR.
apply trans_eq with 0.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -Rmult_assoc.
assert (H: x <= zeta <= y) by (split ; apply Rlt_le ; apply Hzeta1).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : R => Derive (Derive_n f n) x) x l *)
rewrite -(is_derive_unique _ _ _ (Dg _ H)).
destruct (pr zeta Hzeta1) as (x0,Hd).
simpl in Hzeta2.
(* Goal: @eq R (Derive_n (fun y : R => f (Rmult (IZR (Zneg xH)) y)) n x) (Rmult (pow (IZR (Zneg xH)) n) (Derive_n f n (Ropp x))) *)
(* Goal: forall t : R, @eq R (f (Rmult (IZR (Zneg xH)) t)) (f (Ropp t)) *)
rewrite Hzeta2 in Hd.
now apply is_derive_unique, is_derive_Reals.
field.
(* Goal: and (Rlt (Rminus x (pos r)) t) (Rlt t (Rplus x (pos r))) *)
split.
apply INR_fact_neq_0.
now apply not_0_INR.
apply Rmult_integral_contrapositive_currified.
now apply not_0_INR.
apply pow_nonzero.
apply Rgt_not_eq.
apply Rplus_gt_reg_l with zeta.
(* Goal: @eq R (Rplus (Ropp a) a) (Rplus (Ropp a) b) *)
ring_simplify.
apply Hzeta1.
Qed.
