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

Copyright (C) 2011-2015 Sylvie Boldo
#<br />#
Copyright (C) 2011-2015 Catherine Lelay
#<br />#
Copyright (C) 2011-2015 Guillaume Melquiond

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
COPYING file for more details.
*)

Require Import Reals Omega Psatz.
Require Import mathcomp.ssreflect.ssreflect.
Require Import Rcomplements Hierarchy Continuity Derive.

(** This file describes results about differentiability in [R x
 R]. This includes the [Schwarz] theorem and the 2D Taylor-Lagrange
 inequality. *)

(** * Differentiability *)

Definition differentiable_pt_lim (f : R -> R -> R) (x y : R) (lx ly : R) :=
  forall eps : posreal, locally_2d (fun u v =>
    Rabs (f u v - f x y - (lx * (u - x) + ly * (v - y))) <= eps * Rmax (Rabs (u - x)) (Rabs (v - y))) x y.

Lemma filterdiff_differentiable_pt_lim (f : R -> R -> R) (x y lx ly : R) :
  filterdiff (fun u : R * R => f (fst u) (snd u)) (locally (x,y)) (fun u : R * R => fst u * lx + snd u * ly)
  <-> differentiable_pt_lim f x y lx ly.
Proof.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
  split => Df.
  move => eps.
  case: Df => _ Df.
  assert (is_filter_lim (locally (x, y)) (x, y)) by now intro.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
  specialize (Df (x,y) H) => {H}.
  apply locally_2d_locally.
  assert (0 < eps / sqrt 2).
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply Rdiv_lt_0_compat.
(* Goal: not (@eq R h (IZR Z0)) *)
    by apply eps.
(* Goal: not (@eq R h (IZR Z0)) *)
    by apply Rlt_sqrt2_0.
  move: (Df (mkposreal _ H)).
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
  apply filter_imp => [[u v] /= Huv].
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite !(Rmult_comm _ (_-_)).
  eapply Rle_trans.
  apply Huv.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rmult_assoc.
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply Rmult_le_compat_l.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply Rlt_le, eps.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rmult_comm Rle_div_l.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rmult_comm.
  eapply Rle_trans.
  apply norm_prod.
  apply Rle_refl.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply Rlt_sqrt2_0.
  
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
  split.
  apply (is_linear_comp (fun u : R * R => (scal (fst u) lx,scal (snd u) ly))
                          (fun u : R * R => plus (fst u) (snd u))).
  apply is_linear_prod.
  apply (is_linear_comp (@fst _ _) (fun t : R => scal t lx)).
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply is_linear_fst.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply @is_linear_scal_l.
  apply (is_linear_comp (@snd _ _) (fun t : R => scal t ly)).
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply is_linear_snd.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply @is_linear_scal_l.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply @is_linear_plus.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
  simpl => u Hu.
  replace u with (x,y) by now apply is_filter_lim_locally_unique.
  move => {u Hu} eps /=.
  move: (proj1 (locally_2d_locally _ _ _) (Df eps)).
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
  apply filter_imp => [[u v]] /= Huv.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite !(Rmult_comm (_-_)).
  eapply Rle_trans.
  apply Huv.
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply Rmult_le_compat_l.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply Rlt_le, eps.
  apply (norm_prod (u - x) (v - y)).
Qed.

Lemma differentiable_pt_lim_ext : forall f1 f2 x y lx ly,
  locally_2d (fun u v => f1 u v = f2 u v) x y ->
  differentiable_pt_lim f1 x y lx ly -> differentiable_pt_lim f2 x y lx ly.
Proof.
(* Goal: forall (f1 f2 : forall (_ : R) (_ : R), R) (x y lx ly : R) (_ : locally_2d (fun u v : R => @eq R (f1 u v) (f2 u v)) x y) (_ : differentiable_pt_lim f1 x y lx ly), differentiable_pt_lim f2 x y lx ly *)
  intros f1 f2 x y lx ly H H1 eps.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
  apply: locally_2d_impl (H1 eps) => {H1}.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite (locally_2d_singleton _ _ _ H).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
  apply: locally_2d_impl H.
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
  apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : @eq R (f1 u v) (f2 u v)) (_ : Rle (Rabs (Rminus (Rminus (f1 u v) (f2 x y)) (Rplus (Rmult lx (Rminus u x)) (Rmult ly (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))), Rle (Rabs (Rminus (Rminus (f2 u v) (f2 x y)) (Rplus (Rmult lx (Rminus u x)) (Rmult ly (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) *)
  now intros u v ->.
Qed.

Definition differentiable_pt (f : R -> R -> R) (x y : R) :=
  exists lx, exists ly, differentiable_pt_lim f x y lx ly.

Lemma differentiable_continuity_pt : forall f x y,
  differentiable_pt f x y -> continuity_2d_pt f x y.
Proof.
(* Goal: forall (f : forall (_ : R) (_ : R), R) (x y : R) (_ : differentiable_pt f x y), continuity_2d_pt f x y *)
  intros f x y (l1&l2&Df) eps ; simpl in Df.
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
  assert (0 < eps / 2).
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply Rdiv_lt_0_compat ; [apply eps|apply Rlt_R0_R2].
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    set (eps' := mkposreal _ H).
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
  elim (Df eps') ; clear Df ; intros d0 Df.
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
  assert (0 < Rmin (Rmin d0 1) (Rmin (eps/(4*Rmax (Rabs l1) 1)) (eps / (4* Rmax (Rabs l2) 1)))).
(* Goal: Rlt (IZR Z0) (Rmin (Rmin (pos d0) (IZR (Zpos xH))) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply Rmin_pos ; apply Rmin_pos.
(* Goal: Rlt (IZR Z0) (pos d0) *)
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) *)
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply d0.
(* Goal: Rlt (IZR Z0) (IZR (Zpos xH)) *)
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) *)
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply Rlt_0_1.
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply Rdiv_lt_0_compat.
(* Goal: Rlt (IZR Z0) (pos eps) *)
(* Goal: Rlt (IZR Z0) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH)))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply eps.
(* Goal: Rlt (IZR Z0) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH)))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply Rmult_lt_0_compat.
(* Goal: Rlt (IZR Z0) (IZR (Zpos (xO (xO xH)))) *)
(* Goal: Rlt (IZR Z0) (Rmax (Rabs l1_2) (IZR (Zpos xH))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply Rmult_lt_0_compat ; apply Rlt_R0_R2.
(* Goal: Rlt (IZR Z0) (Rmax (Rabs l1_2) (IZR (Zpos xH))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply (Rlt_le_trans _ _ _ Rlt_0_1 (RmaxLess2 _ _)).
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply Rdiv_lt_0_compat.
(* Goal: Rlt (IZR Z0) (pos eps) *)
(* Goal: Rlt (IZR Z0) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH)))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply eps.
(* Goal: Rlt (IZR Z0) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH)))) *)
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    apply Rmult_lt_0_compat.
(* Goal: Rlt (IZR Z0) (IZR (Zpos (xO (xO xH)))) *)
(* Goal: Rlt (IZR Z0) (Rmax (Rabs l1_2) (IZR (Zpos xH))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply Rmult_lt_0_compat ; apply Rlt_R0_R2.
(* Goal: Rlt (IZR Z0) (Rmax (Rabs l1_2) (IZR (Zpos xH))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply (Rlt_le_trans _ _ _ Rlt_0_1 (RmaxLess2 _ _)).
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
    set (delta := mkposreal _ H0).
(* Goal: locally_2d (fun u v : R => Rlt (Rabs (Rminus (f u v) (f x y))) (pos eps)) x y *)
  exists delta ; intros x' y' H1 H2.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite (double_var eps).
  apply (Rle_lt_trans _ (Rabs (f x' y' - f x y - (l1 * (x' - x) + l2 * (y' - y)))
    + Rabs (l1 * (x' - x) + l2 * (y' - y)))).
    assert (Rabs (f x' y' - f x y) =
      Rabs ((f x' y' - f x y - (l1 * (x' - x) + l2 * (y' - y))) +
      (l1 * (x' - x) + l2 * (y' - y)))).
      assert ((f x' y' - f x y) =
        (f x' y' - f x y - (l1 * (x' - x) + l2 * (y' - y)) +
        (l1 * (x' - x) + l2 * (y' - y)))).
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
        ring.
(* Goal: @eq R (Rabs (Rminus (f x' y') (f x y))) (Rabs (Rplus (Rminus (Rminus (f x' y') (f x y)) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y)))) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) *)
(* Goal: Rle (Rabs (Rminus (f x' y') (f x y))) (Rplus (Rabs (Rminus (Rminus (f x' y') (f x y)) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) *)
(* Goal: Rlt (Rplus (Rabs (Rminus (Rminus (f x' y') (f x y)) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) *)
      rewrite <- H3 ; clear H3 ; reflexivity.
(* Goal: Rle (Rabs (Rminus (f x' y') (f x y))) (Rplus (Rabs (Rminus (Rminus (f x' y') (f x y)) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) *)
(* Goal: Rlt (Rplus (Rabs (Rminus (Rminus (f x' y') (f x y)) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) *)
    rewrite H3 ; clear H3 ; apply Rabs_triang.
(* Goal: Rlt (Rplus (Rabs (Rminus (Rminus (f x' y') (f x y)) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rplus (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rdiv (pos eps) (IZR (Zpos (xO xH))))) *)
  apply Rplus_lt_le_compat.
(* Goal: Rlt (Rabs (Rminus (Rminus (f x' y') (f x y)) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
  apply (Rle_lt_trans _ (eps' * Rmax (Rabs (x' - x)) (Rabs (y' - y)))).
(* Goal: Rle (Rabs (Rminus (Rminus (f x' y') (f x y)) (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y))))) (Rmult (pos eps') (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rlt (Rmult (pos eps') (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
  apply Df.
  apply (Rlt_le_trans _ _ _ H1) ; unfold delta ; simpl ;
  apply (Rle_trans _ _ _ (Rmin_l _ _) (Rmin_l _ _)).
  apply (Rlt_le_trans _ _ _ H2) ; unfold delta ; simpl ;
  apply (Rle_trans _ _ _ (Rmin_l _ _) (Rmin_l _ _)).
(* Goal: Rlt (Rmult (pos eps') (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
  rewrite <- (Rmult_1_r (eps/2)) ; unfold eps' ; simpl.
(* Goal: Rlt (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos xH))) *)
(* Goal: Rle (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
  apply Rmult_lt_compat_l.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
  apply H.
(* Goal: Rlt (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
  apply (Rlt_le_trans _ delta).
(* Goal: Rlt (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) (pos delta) *)
(* Goal: Rle (pos delta) (IZR (Zpos xH)) *)
(* Goal: Rle (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
  apply (Rmax_lub_lt _ _ _ H1 H2).
  unfold delta ; simpl ;
  apply (Rle_trans _ _ _ (Rmin_l _ _) (Rmin_r _ _)).
(* Goal: Rle (Rabs (Rplus (Rmult l1 (Rminus x' x)) (Rmult l2 (Rminus y' y)))) (Rdiv (pos eps) (IZR (Zpos (xO xH)))) *)
  apply (Rle_trans _ (Rabs l1 * Rabs (x'-x) + Rabs l2 * Rabs (y'-y))).
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
    repeat rewrite <- Rabs_mult.
(* Goal: Rle (Rabs (Rplus (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y))))) (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rmult (pos eps) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Rabs_triang.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite (double_var (eps/2)).
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
  apply Rplus_le_compat.
(* Goal: Rle (Rmult (Rabs l1) (Rabs (Rminus x' x))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rabs (Rminus y' y))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply (Rle_trans _ (Rabs l1 * delta)).
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rabs_pos.
(* Goal: Rle (Rabs (Rminus x' x)) (pos delta) *)
(* Goal: Rle (Rmult (Rabs l1) (pos delta)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rabs (Rminus y' y))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rlt_le, H1.
  apply (Rle_trans _ (Rabs l1 * (Rmin (eps / (4 * Rmax (Rabs l1) 1))
                     (eps / (4 * Rmax (Rabs l2) 1))))).
(* Goal: Rle (Rmult (Rabs l2) (pos delta)) (Rmult (Rabs l2) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Rmult_le_compat_l ; unfold delta ; simpl ; [apply Rabs_pos| apply Rmin_r].
(* Goal: Rle (Rmult (Rabs l1) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rabs (Rminus y' y))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply (Rle_trans _ (Rabs l1 * (eps / (4 * Rmax (Rabs l1) 1)))).
(* Goal: Rle (Rmult (Rabs l1) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) (Rmult (Rabs l1) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH)))))) *)
(* Goal: Rle (Rmult (Rabs l1) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH)))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rabs (Rminus y' y))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rmult_le_compat_l ; [apply Rabs_pos | apply Rmin_l].
(* Goal: Rle (Rmult (Rabs l1) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH)))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rabs (Rminus y' y))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  unfold Rmax ; destruct (Rle_dec (Rabs l1) 1).
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  rewrite <- (Rmult_1_l (eps/2/2)).
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH))))) (Rmult (IZR (Zpos xH)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rabs_pos.
  apply Rlt_le, Rdiv_lt_0_compat ;
  [apply eps | apply Rmult_lt_0_compat ;
  [apply Rmult_lt_0_compat ; apply Rlt_R0_R2|apply Rlt_0_1]].
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply r.
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Req_le ; field.
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Req_le ; field.
(* Goal: not (@eq R (Rabs l2) (IZR Z0)) *)
  apply Rnot_le_lt in n.
(* Goal: not (@eq R (Rabs l2) (IZR Z0)) *)
  apply sym_not_eq, Rlt_not_eq, (Rlt_trans _ _ _ Rlt_0_1 n).

(* Goal: Rle (Rmult (Rabs l2) (Rabs (Rminus y' y))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply (Rle_trans _ (Rabs l2 * delta)).
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rabs_pos.
(* Goal: Rle (Rabs (Rminus y' y)) (pos delta) *)
(* Goal: Rle (Rmult (Rabs l2) (pos delta)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rlt_le, H2.
  apply (Rle_trans _ (Rabs l2 * (Rmin (eps / (4 * Rmax (Rabs l1) 1))
                     (eps / (4 * Rmax (Rabs l2) 1))))).
(* Goal: Rle (Rmult (Rabs l2) (pos delta)) (Rmult (Rabs l2) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Rmult_le_compat_l ; unfold delta ; simpl ; [apply Rabs_pos| apply Rmin_r].
(* Goal: Rle (Rmult (Rabs l2) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply (Rle_trans _ (Rabs l2 * (eps / (4 * Rmax (Rabs l2) 1)))).
(* Goal: Rle (Rmult (Rabs l2) (Rmin (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1) (IZR (Zpos xH))))) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH))))))) (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH)))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH)))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rmult_le_compat_l ; [apply Rabs_pos | apply Rmin_r].
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l2) (IZR (Zpos xH)))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  unfold Rmax ; destruct (Rle_dec (Rabs l2) 1).
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH))))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  rewrite <- (Rmult_1_l (eps/2/2)).
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH))))) (Rmult (IZR (Zpos xH)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rabs_pos.
  apply Rlt_le, Rdiv_lt_0_compat ;
  [apply eps | apply Rmult_lt_0_compat ;
  [apply Rmult_lt_0_compat ; apply Rlt_R0_R2|apply Rlt_0_1]].
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply r.
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Req_le ; field.
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Req_le ; field.
(* Goal: not (@eq R (Rabs l2) (IZR Z0)) *)
  apply Rnot_le_lt in n.
(* Goal: not (@eq R (Rabs l2) (IZR Z0)) *)
  apply sym_not_eq, Rlt_not_eq, (Rlt_trans _ _ _ Rlt_0_1 n).
Qed.

Lemma differentiable_pt_lim_proj1_0 (f : R -> R) (x y l : R) :
  derivable_pt_lim f x l -> differentiable_pt_lim (fun u v => f u) x y l 0.
Proof.
(* Goal: forall _ : derivable_pt_lim f x l, differentiable_pt_lim (fun u _ : R => f u) x y l (IZR Z0) *)
  intros Df eps.
  apply is_derive_Reals in Df ;
  elim (proj2 Df x (fun P H => H) eps) ; clear Df ; intros delta Df.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f u) (f x)) (Rplus (Rmult l (Rminus u x)) (Rmult (IZR Z0) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  exists delta ; simpl ; intros.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rmult_0_l Rplus_0_r.
(* Goal: Rle (Rabs (Rminus (Rminus (f u) (f x)) (Rmult l (Rminus u x)))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) *)
  apply (Rle_trans _ (eps * Rabs (u - x))).
(* Goal: Rle (Rabs (Rminus (Rminus (f u) (f x)) (Rmult l (Rminus u x)))) (Rmult (pos eps) (Rabs (Rminus u x))) *)
(* Goal: Rle (Rmult (pos eps) (Rabs (Rminus u x))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y)))) *)
  rewrite Rmult_comm ; apply (Df _ H).
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (pos eps) *)
(* Goal: Rle (Rabs (Rminus u x)) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))) *)
  apply Rlt_le, eps.
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply RmaxLess1.
Qed.

Lemma differentiable_pt_lim_proj1_1 (f : R -> R) (x y l : R) :
  differentiable_pt_lim (fun u v => f u) x y l 0 -> derivable_pt_lim f x l.
Proof.
(* Goal: forall _ : differentiable_pt_lim (fun u _ : R => f u) x y l (IZR Z0), derivable_pt_lim f x l *)
  intros Df.
(* Goal: derivable_pt_lim f x l *)
  apply is_derive_Reals ; split => [ | z Hz eps].
(* Goal: not (@eq R h (IZR Z0)) *)
    by apply @is_linear_scal_l.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
  rewrite -(is_filter_lim_locally_unique _ _ Hz) => {z Hz}.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x0 : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x0) (f x)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x0 x) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x0 x)))) *)
  elim (Df eps) ; clear Df ; intros delta Df.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x0 : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x0) (f x)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x0 x) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x0 x)))) *)
  exists delta ; simpl in Df ; simpl ; intros.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite /minus /plus /opp /scal /= /mult /=.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
  replace (f y0 + - f x + - ((y0 + - x) * l)) with (f y0 - f x - (l * (y0 - x) + 0 * (y - y))) by ring.
(* Goal: Rle (@norm R_AbsRing R_NormedModule (Rminus (Rminus (f y0) (f x)) (Rplus (Rmult l (Rminus y0 x)) (Rmult (IZR Z0) (Rminus y y))))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (Rplus y0 (Ropp x)))) *)
  assert (Rabs (y0 - x) = Rmax (Rabs (y0 - x)) (Rabs (y-y))).
(* Goal: @eq R (Rabs (Rminus y0 x)) (Rmax (Rabs (Rminus y0 x)) (Rabs (Rminus y y))) *)
(* Goal: Rle (@norm R_AbsRing R_NormedModule (Rminus (Rminus (f y0) (f x)) (Rplus (Rmult l (Rminus y0 x)) (Rmult (IZR Z0) (Rminus y y))))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (Rplus y0 (Ropp x)))) *)
    rewrite Rmax_comm ; apply sym_equal, Rmax_right.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    rewrite Rminus_eq_0 Rabs_R0 ; apply Rabs_pos.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite /norm /= /abs /=.
(* Goal: Rle (Rabs (Rminus (Rminus (f y0) (f x)) (Rplus (Rmult l (Rminus y0 x)) (Rmult (IZR Z0) (Rminus y y))))) (Rmult (pos eps) (Rabs (Rplus y0 (Ropp x)))) *)
  rewrite H0 ; clear H0.
(* Goal: Rle (Rabs (Rminus (Rminus (f y0) (f x)) (Rplus (Rmult l (Rminus y0 x)) (Rmult (IZR Z0) (Rminus y y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus y0 x)) (Rabs (Rminus y y)))) *)
  apply (Df _ _ H).
(* Goal: Rlt (Rabs (Rminus y y)) (pos delta) *)
  rewrite Rminus_eq_0 Rabs_R0 ; apply delta.
Qed.

Lemma differentiable_pt_lim_unique (f : R -> R -> R) (x y : R) (lx ly : R) :
  differentiable_pt_lim f x y lx ly
    -> Derive (fun x => f x y) x = lx /\ Derive (fun y => f x y) y = ly.
Proof.
  move => Df ; split ; apply is_derive_unique, is_derive_Reals => e He ;
  case: (Df (pos_div_2 (mkposreal e He))) => {Df} delta /= Df ;
  exists delta => h Hh0 Hh.

  replace ((f (x + h) y - f x y) / h - lx)
    with ((f (x+h) y - f x y - (lx * ((x+h) - x) + ly * (y - y))) / h)
    by (by field).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rabs_div.
(* Goal: Rlt (Rdiv (Rabs (Rminus (Rminus (f x (Rplus y h)) (f x y)) (Rplus (Rmult lx (Rminus x x)) (Rmult ly (Rminus (Rplus y h) y))))) (Rabs h)) e *)
(* Goal: not (@eq R h (IZR Z0)) *)
  apply Rlt_div_l.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply Rabs_pos_lt.
(* Goal: Rlt (Rabs (Rminus (Rminus (f (Rplus x h) y) (f x y)) (Rplus (Rmult lx (Rminus (Rplus x h) x)) (Rmult ly (Rminus y y))))) (Rmult e (Rabs h)) *)
(* Goal: not (@eq R h (IZR Z0)) *)
(* Goal: Rlt (Rabs (Rminus (Rdiv (Rminus (f x (Rplus y h)) (f x y)) h) ly)) e *)
  apply Rle_lt_trans with (e / 2 * Rmax (Rabs (x + h - x)) (Rabs (y - y))).
(* Goal: Rle (Rabs (Rminus (Rminus (f (Rplus x h) y) (f x y)) (Rplus (Rmult lx (Rminus (Rplus x h) x)) (Rmult ly (Rminus y y))))) (Rmult (Rdiv e (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus (Rplus x h) x)) (Rabs (Rminus y y)))) *)
(* Goal: Rlt (Rmult (Rdiv e (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus (Rplus x h) x)) (Rabs (Rminus y y)))) (Rmult e (Rabs h)) *)
(* Goal: not (@eq R h (IZR Z0)) *)
(* Goal: Rlt (Rabs (Rminus (Rdiv (Rminus (f x (Rplus y h)) (f x y)) h) ly)) e *)
  apply (Df (x+h) y).
(* Goal: not (@eq R h (IZR Z0)) *)
  by (ring_simplify (x + h - x)).
(* Goal: Rle (Rabs (Rminus x x)) (Rabs h) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  rewrite Rminus_eq_0 Rabs_R0 ; by apply delta.
(* Goal: Rlt (Rmult (Rdiv e (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus (Rplus x h) x)) (Rabs (Rminus y y)))) (Rmult e (Rabs h)) *)
(* Goal: not (@eq R h (IZR Z0)) *)
(* Goal: Rlt (Rabs (Rminus (Rdiv (Rminus (f x (Rplus y h)) (f x y)) h) ly)) e *)
  ring_simplify (x + h - x).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rmax_left.
(* Goal: Rlt (Rmult (Rdiv e (IZR (Zpos (xO xH)))) (Rabs h)) (Rmult e (Rabs h)) *)
(* Goal: Rle (Rabs (Rminus x x)) (Rabs h) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  apply Rmult_lt_compat_r.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply Rabs_pos_lt.
(* Goal: Rlt (Rdiv e (IZR (Zpos (xO xH)))) e *)
(* Goal: Rle (Rabs (Rminus x x)) (Rabs h) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  lra.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  rewrite Rminus_eq_0 Rabs_R0 ; by apply Rabs_pos.
(* Goal: not (@eq R h (IZR Z0)) *)
  by [].

  replace ((f x (y + h) - f x y) / h - ly)
    with ((f x (y + h) - f x y - (lx * (x - x) + ly * ((y + h) - y))) / h)
    by (by field).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rabs_div.
(* Goal: Rlt (Rdiv (Rabs (Rminus (Rminus (f x (Rplus y h)) (f x y)) (Rplus (Rmult lx (Rminus x x)) (Rmult ly (Rminus (Rplus y h) y))))) (Rabs h)) e *)
(* Goal: not (@eq R h (IZR Z0)) *)
  apply Rlt_div_l.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply Rabs_pos_lt.
(* Goal: Rlt (Rabs (Rminus (Rminus (f x (Rplus y h)) (f x y)) (Rplus (Rmult lx (Rminus x x)) (Rmult ly (Rminus (Rplus y h) y))))) (Rmult e (Rabs h)) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  apply Rle_lt_trans with (e / 2 * Rmax (Rabs (x - x)) (Rabs (y + h - y))).
(* Goal: Rle (Rabs (Rminus (Rminus (f x (Rplus y h)) (f x y)) (Rplus (Rmult lx (Rminus x x)) (Rmult ly (Rminus (Rplus y h) y))))) (Rmult (Rdiv e (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x x)) (Rabs (Rminus (Rplus y h) y)))) *)
(* Goal: Rlt (Rmult (Rdiv e (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x x)) (Rabs (Rminus (Rplus y h) y)))) (Rmult e (Rabs h)) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  apply (Df x (y + h)).
(* Goal: Rle (Rabs (Rminus x x)) (Rabs h) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  rewrite Rminus_eq_0 Rabs_R0 ; by apply delta.
(* Goal: not (@eq R h (IZR Z0)) *)
  by (ring_simplify (y + h - y)).
(* Goal: Rlt (Rmult (Rdiv e (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x x)) (Rabs (Rminus (Rplus y h) y)))) (Rmult e (Rabs h)) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  ring_simplify (y + h - y).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rmax_right.
(* Goal: Rlt (Rmult (Rdiv e (IZR (Zpos (xO xH)))) (Rabs h)) (Rmult e (Rabs h)) *)
(* Goal: Rle (Rabs (Rminus x x)) (Rabs h) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  apply Rmult_lt_compat_r.
(* Goal: not (@eq R h (IZR Z0)) *)
  by apply Rabs_pos_lt.
(* Goal: Rlt (Rdiv e (IZR (Zpos (xO xH)))) e *)
(* Goal: Rle (Rabs (Rminus x x)) (Rabs h) *)
(* Goal: not (@eq R h (IZR Z0)) *)
  lra.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  rewrite Rminus_eq_0 Rabs_R0 ; by apply Rabs_pos.
(* Goal: not (@eq R h (IZR Z0)) *)
  by [].
Qed.

(** * Operations *)

Lemma differentiable_pt_lim_comp : forall f1 f2 f3 x y l1x l1y l2x l2y l3x l3y,
  differentiable_pt_lim f1 (f2 x y) (f3 x y) l1x l1y ->
  differentiable_pt_lim f2 x y l2x l2y -> differentiable_pt_lim f3 x y l3x l3y ->
  differentiable_pt_lim (fun u v => f1 (f2 u v) (f3 u v)) x y
    (l1x * l2x + l1y * l3x) (l1x * l2y + l1y * l3y).
Proof.
  intros f1 f2 f3 x y l1_1 l1_2 l2_1 l2_2 l3_1 l3_2
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
    Df1 Df2 Df3 eps ; simpl.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  assert (Cf2 : continuity_2d_pt f2 x y).
(* Goal: continuity_2d_pt f3 x y *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply differentiable_continuity_pt.
(* Goal: differentiable_pt f2 x y *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    exists l2_1 ; exists l2_2 ; apply Df2.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  assert (Cf3 : continuity_2d_pt f3 x y).
(* Goal: continuity_2d_pt f3 x y *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply differentiable_continuity_pt.
(* Goal: differentiable_pt f3 x y *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    exists l3_1 ; exists l3_2 ; apply Df3.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  assert (He2 : 0 < eps / (4 * Rmax (Rabs l1_1) 1)).
    apply Rdiv_lt_0_compat ;
    [apply eps | apply Rmult_lt_0_compat].
(* Goal: Rlt (IZR Z0) (IZR (Zpos (xO (xO xH)))) *)
(* Goal: Rlt (IZR Z0) (Rmax (Rabs l1_2) (IZR (Zpos xH))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply Rmult_lt_0_compat ; apply Rlt_R0_R2.
(* Goal: Rlt (IZR Z0) (Rmax (Rabs l1_2) (IZR (Zpos xH))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply (Rlt_le_trans _ _ _ Rlt_0_1 (RmaxLess2 _ _)).
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    set (eps2 := mkposreal _ He2).
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  assert (He3 : 0 < eps / (4 * Rmax (Rabs l1_2) 1)).
    apply Rdiv_lt_0_compat ;
    [apply eps | apply Rmult_lt_0_compat].
(* Goal: Rlt (IZR Z0) (IZR (Zpos (xO (xO xH)))) *)
(* Goal: Rlt (IZR Z0) (Rmax (Rabs l1_2) (IZR (Zpos xH))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply Rmult_lt_0_compat ; apply Rlt_R0_R2.
(* Goal: Rlt (IZR Z0) (Rmax (Rabs l1_2) (IZR (Zpos xH))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply (Rlt_le_trans _ _ _ Rlt_0_1 (RmaxLess2 _ _)).
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    set (eps3 := mkposreal _ He3).
  assert (He1 : 0 < eps / (2 * Rmax (eps2 + Rabs l2_1 + Rabs l2_2)
    (eps3 + Rabs l3_1 + Rabs l3_2))).
(* Goal: Rlt (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO xH))) (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply Rdiv_lt_0_compat ; [apply eps | apply Rmult_lt_0_compat].
(* Goal: Rlt (IZR Z0) (IZR (Zpos (xO xH))) *)
(* Goal: Rlt (IZR Z0) (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply Rlt_R0_R2.
(* Goal: Rlt (IZR Z0) (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    apply (Rlt_le_trans _ (eps2 + Rabs l2_1 + Rabs l2_2)).
(* Goal: Rlt (IZR Z0) (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) *)
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    rewrite Rplus_assoc ; apply Rplus_lt_le_0_compat.
(* Goal: Rlt (IZR Z0) (pos eps2) *)
(* Goal: Rle (IZR Z0) (Rplus (Rabs l2_1) (Rabs l2_2)) *)
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply eps2.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Rplus_le_le_0_compat ; apply Rabs_pos.
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply RmaxLess1.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    set (eps1 := mkposreal _ He1).
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  elim (Df1 eps1) ; clear Df1 ; intros d0 Df1.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    elim (Cf2 d0) ; clear Cf2 ; intros d1 Cf2.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    elim (Cf3 d0) ; clear Cf3 ; intros d'1 Cf3.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  elim (Df2 eps2) ; clear Df2 ; intros d2 Df2.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  elim (Df3 eps3) ; clear Df3 ; intros d3 Df3.
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  assert (Hd : 0 < Rmin (Rmin d1 d'1) (Rmin d2 d3)).
    apply Rmin_pos ; apply Rmin_pos ;
    [apply d1 | apply d'1 | apply d2 | apply d3].
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
    set (delta := mkposreal _ Hd).
(* Goal: locally_2d (fun u v : R => Rle (Rabs (Rminus (Rminus (f1 (f2 u v) (f3 u v)) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus u x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus v y))))) (Rmult (pos eps) (Rmax (Rabs (Rminus u x)) (Rabs (Rminus v y))))) x y *)
  exists delta ; intros x' y' ; intros.
  apply (Rle_trans _ (Rabs (f1 (f2 x' y') (f3 x' y') - f1 (f2 x y) (f3 x y) -
    (l1_1 * (f2 x' y' - f2 x y) + l1_2 * (f3 x' y' - f3 x y)))
    + Rabs (l1_1 * (f2 x' y' - f2 x y) + l1_2 * (f3 x' y' - f3 x y) -
    ((l1_1 * l2_1 + l1_2 * l3_1) * (x' - x) + (l1_1 * l2_2 + l1_2 * l3_2) * (y' - y))))).
    replace ((f1 (f2 x' y') (f3 x' y') - f1 (f2 x y) (f3 x y) -
      ((l1_1 * l2_1 + l1_2 * l3_1) * (x' - x) +
      (l1_1 * l2_2 + l1_2 * l3_2) * (y' - y)))) with
      ((f1 (f2 x' y') (f3 x' y') - f1 (f2 x y) (f3 x y) -
      (l1_1 * (f2 x' y' - f2 x y) + l1_2 * (f3 x' y' - f3 x y))) +
      (l1_1 * (f2 x' y' - f2 x y) + l1_2 * (f3 x' y' - f3 x y) -
      ((l1_1 * l2_1 + l1_2 * l3_1) * (x' - x) +
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
      (l1_1 * l2_2 + l1_2 * l3_2) * (y' - y)))) by ring.
(* Goal: Rle (Rabs (Rplus (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y))))) (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rmult (pos eps) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Rabs_triang.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite (double_var eps) (Rmult_plus_distr_r (eps/2)).
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
  apply Rplus_le_compat.
(* Goal: Rle (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply (Rle_trans _ (eps1 * Rmax (Rabs (f2 x' y' - f2 x y)) (Rabs (f3 x' y' - f3 x y)))).
(* Goal: Rle (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rmult (pos eps1) (Rmax (Rabs (Rminus (f2 x' y') (f2 x y))) (Rabs (Rminus (f3 x' y') (f3 x y))))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmax (Rabs (Rminus (f2 x' y') (f2 x y))) (Rabs (Rminus (f3 x' y') (f3 x y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Df1.
(* Goal: Rlt (Rabs (Rminus (f2 x' y') (f2 x y))) (pos d0) *)
(* Goal: Rlt (Rabs (Rminus (f3 x' y') (f3 x y))) (pos d0) *)
(* Goal: Rle (Rmult (pos eps1) (Rmax (Rabs (Rminus (f2 x' y') (f2 x y))) (Rabs (Rminus (f3 x' y') (f3 x y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Cf2.
    apply (Rlt_le_trans _ _ _ H) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_l _ _) (Rmin_l _ _)).
    apply (Rlt_le_trans _ _ _ H0) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_l _ _) (Rmin_l _ _)).
(* Goal: Rlt (Rabs (Rminus (f3 x' y') (f3 x y))) (pos d0) *)
(* Goal: Rle (Rmult (pos eps1) (Rmax (Rabs (Rminus (f2 x' y') (f2 x y))) (Rabs (Rminus (f3 x' y') (f3 x y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Cf3.
    apply (Rlt_le_trans _ _ _ H) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_l _ _) (Rmin_r _ _)).
    apply (Rlt_le_trans _ _ _ H0) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_l _ _) (Rmin_r _ _)).
  apply (Rle_trans _ (eps1 * (Rmax (eps2 + Rabs l2_1 + Rabs l2_2)
    (eps3 + Rabs l3_1 + Rabs l3_2) * Rmax (Rabs (x'-x)) (Rabs (y'-y))))).
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (pos eps1) *)
(* Goal: Rle (Rmax (Rabs (Rminus (f2 x' y') (f2 x y))) (Rabs (Rminus (f3 x' y') (f3 x y)))) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Rlt_le, eps1.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
    rewrite Rmax_mult.
(* Goal: Rle (Rmax (Rabs (Rminus (f2 x' y') (f2 x y))) (Rabs (Rminus (f3 x' y') (f3 x y)))) (Rmax (Rmult (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Rmax_le_compat.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
    rewrite Rplus_assoc Rmult_plus_distr_r.
    apply (Rle_trans _ (Rabs (f2 x' y' - f2 x y - (l2_1 * (x' - x) + l2_2 * (y' - y)))
      + Rabs (l2_1 * (x' - x) + l2_2 * (y' - y)))).
      assert (Rabs (f2 x' y' - f2 x y) =
      Rabs ((f2 x' y' - f2 x y - (l2_1 * (x' - x) + l2_2 * (y' - y))) +
      (l2_1 * (x' - x) + l2_2 * (y' - y)))).
      assert ((f2 x' y' - f2 x y) =
      ((f2 x' y' - f2 x y - (l2_1 * (x' - x) + l2_2 * (y' - y))) +
      (l2_1 * (x' - x) + l2_2 * (y' - y)))).
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
      ring.
(* Goal: @eq R (Rabs (Rminus (f3 x' y') (f3 x y))) (Rabs (Rplus (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) *)
(* Goal: Rle (Rabs (Rminus (f3 x' y') (f3 x y))) (Rplus (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) (Rabs (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) (Rabs (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) (Rplus (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rplus (Rabs l3_1) (Rabs l3_2)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      rewrite <- H1 ; clear H1 ; reflexivity.
(* Goal: Rle (Rabs (Rplus (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y))))) (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rmult (pos eps) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    rewrite H1 ; clear H1 ; apply Rabs_triang.
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
    apply Rplus_le_compat.
(* Goal: Rle (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult (pos eps2) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rmult (Rabs l1_1) (Rmult (pos eps2) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Df2.
    apply (Rlt_le_trans _ _ _ H) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_r _ _) (Rmin_l _ _)).
    apply (Rlt_le_trans _ _ _ H0) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_r _ _) (Rmin_l _ _)).
(* Goal: Rle (Rabs (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))) (Rmult (Rplus (Rabs l2_1) (Rabs l2_2)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (f3 x' y') (f3 x y))) (Rmult (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply (Rle_trans _ (Rabs l2_1 * Rabs (x'-x) + Rabs l2_2 * Rabs (y'-y))).
(* Goal: Rle (Rabs (Rplus (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y))))) (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rmult (pos eps) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      repeat rewrite <- Rabs_mult ; apply Rabs_triang.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
      rewrite Rmult_plus_distr_r.
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      apply Rplus_le_compat ; apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
      apply Rabs_pos.
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      apply RmaxLess1.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
      apply Rabs_pos.
(* Goal: Rle (Rabs (Rminus y' y)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      apply RmaxLess2.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite Rplus_assoc Rmult_plus_distr_r.
  apply (Rle_trans _ (Rabs (f3 x' y' - f3 x y - (l3_1 * (x' - x) + l3_2 * (y' - y)))
      + Rabs (l3_1 * (x' - x) + l3_2 * (y' - y)))).
      assert (Rabs (f3 x' y' - f3 x y) =
      Rabs ((f3 x' y' - f3 x y - (l3_1 * (x' - x) + l3_2 * (y' - y))) +
      (l3_1 * (x' - x) + l3_2 * (y' - y)))).
      assert ((f3 x' y' - f3 x y) =
      ((f3 x' y' - f3 x y - (l3_1 * (x' - x) + l3_2 * (y' - y))) +
      (l3_1 * (x' - x) + l3_2 * (y' - y)))).
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
      ring.
(* Goal: @eq R (Rabs (Rminus (f3 x' y') (f3 x y))) (Rabs (Rplus (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) *)
(* Goal: Rle (Rabs (Rminus (f3 x' y') (f3 x y))) (Rplus (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) (Rabs (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) (Rabs (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) (Rplus (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rplus (Rabs l3_1) (Rabs l3_2)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      rewrite <- H1 ; clear H1 ; reflexivity.
(* Goal: Rle (Rabs (Rplus (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y))))) (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rmult (pos eps) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    rewrite H1 ; clear H1 ; apply Rabs_triang.
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
    apply Rplus_le_compat.
(* Goal: Rle (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Df3.
    apply (Rlt_le_trans _ _ _ H) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_r _ _) (Rmin_r _ _)).
    apply (Rlt_le_trans _ _ _ H0) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_r _ _) (Rmin_r _ _)).
(* Goal: Rle (Rabs (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))) (Rmult (Rplus (Rabs l3_1) (Rabs l3_2)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply (Rle_trans _ (Rabs l3_1 * Rabs (x'-x) + Rabs l3_2 * Rabs (y'-y))).
(* Goal: Rle (Rabs (Rplus (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y))))) (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rmult (pos eps) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      repeat rewrite <- Rabs_mult ; apply Rabs_triang.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
      rewrite Rmult_plus_distr_r.
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      apply Rplus_le_compat ; apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
      apply Rabs_pos.
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      apply RmaxLess1.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
      apply Rabs_pos.
(* Goal: Rle (Rabs (Rminus y' y)) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (pos eps1) (Rmult (Rmax (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (pos eps3) (Rabs l3_1)) (Rabs l3_2))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
      apply RmaxLess2.
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (pos eps3)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply (Rle_trans _ _ _ (Rabs_pos _) (RmaxLess1 _ _)).
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  simpl ; apply Req_le ; field.
(* Goal: not (@eq R (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) (IZR Z0)) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply sym_not_eq, Rlt_not_eq, (Rlt_le_trans _ (eps2 + Rabs l2_1 + Rabs l2_2)).
(* Goal: Rlt (IZR Z0) (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) *)
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  rewrite Rplus_assoc ; apply Rplus_lt_le_0_compat.
(* Goal: Rlt (IZR Z0) (pos eps2) *)
(* Goal: Rle (IZR Z0) (Rplus (Rabs l2_1) (Rabs l2_2)) *)
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply eps2.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
  apply Rplus_le_le_0_compat ; apply Rabs_pos.
(* Goal: Rle (Rplus (Rplus (pos eps2) (Rabs l2_1)) (Rabs l2_2)) (Rmax (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_1) (IZR (Zpos xH))))) (Rabs l2_1)) (Rabs l2_2)) (Rplus (Rplus (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rmax (Rabs l1_2) (IZR (Zpos xH))))) (Rabs l3_1)) (Rabs l3_2))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rmult (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply RmaxLess1.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite (double_var (eps/2)) (Rmult_plus_distr_r (eps/2/2)).
  apply (Rle_trans _ (Rabs l1_1 * Rabs (f2 x' y' - f2 x y - (l2_1 * (x' - x) + l2_2 * (y' - y)))
    + Rabs l1_2 * Rabs (f3 x' y' - f3 x y - (l3_1 * (x' - x) + l3_2 * (y' - y))))).
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
    repeat rewrite <- Rabs_mult.
    assert ((l1_1 * (f2 x' y' - f2 x y) + l1_2 * (f3 x' y' - f3 x y) -
      ((l1_1 * l2_1 + l1_2 * l3_1) * (x' - x) +
      (l1_1 * l2_2 + l1_2 * l3_2) * (y' - y))) =
      (l1_1 * (f2 x' y' - f2 x y - (l2_1 * (x' - x) + l2_2 * (y' - y)))) +
      (l1_2 * (f3 x' y' - f3 x y - (l3_1 * (x' - x) + l3_2 * (y' - y))))).
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
      ring.
(* Goal: Rle (Rabs (Rplus (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y))))) (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) *)
(* Goal: Rle (Rplus (Rabs (Rminus (Rminus (f1 (f2 x' y') (f3 x' y')) (f1 (f2 x y) (f3 x y))) (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))))) (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))))) (Rmult (pos eps) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    rewrite H1 ; clear H1 ; apply Rabs_triang.
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
  apply Rplus_le_compat.
(* Goal: Rle (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply (Rle_trans _ (Rabs l1_1 * (eps2 * Rmax (Rabs (x' - x)) (Rabs (y' - y))))).
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Rabs_pos.
(* Goal: Rle (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult (pos eps2) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rmult (Rabs l1_1) (Rmult (pos eps2) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Df2.
    apply (Rlt_le_trans _ _ _ H) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_r _ _) (Rmin_l _ _)).
    apply (Rlt_le_trans _ _ _ H0) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_r _ _) (Rmin_l _ _)).
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    rewrite <- Rmult_assoc ; apply Rmult_le_compat_r.
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (pos eps3)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply (Rle_trans _ _ _ (Rabs_pos _) (RmaxLess1 _ _)).
(* Goal: Rle (Rmult (Rabs l1_1) (pos eps2)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    unfold eps2, Rmax ; simpl ; destruct (Rle_dec (Rabs l1_1) 1).
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH))))) (Rmult (IZR (Zpos xH)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    rewrite <- (Rmult_1_l (eps/2/2)) ; apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Rabs_pos.
    rewrite Rmult_1_r ; apply Rlt_le, Rdiv_lt_0_compat ;
    [apply eps | apply Rmult_lt_0_compat ; apply Rlt_R0_R2].
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply r.
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Req_le ; field.
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Req_le ; field.
(* Goal: not (@eq R (Rabs l1_2) (IZR Z0)) *)
    apply sym_not_eq, Rlt_not_eq, (Rlt_trans _ _ _ Rlt_0_1 (Rnot_le_lt _ _ n)).
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
  apply (Rle_trans _ (Rabs l1_2 * (eps3 * Rmax (Rabs (x' - x)) (Rabs (y' - y))))).
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Rabs_pos.
(* Goal: Rle (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    apply Df3.
    apply (Rlt_le_trans _ _ _ H) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_r _ _) (Rmin_r _ _)).
    apply (Rlt_le_trans _ _ _ H0) ; simpl ;
    apply (Rle_trans _ _ _ (Rmin_r _ _) (Rmin_r _ _)).
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
    rewrite <- Rmult_assoc ; apply Rmult_le_compat_r.
(* Goal: Rle (IZR Z0) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (pos eps3)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply (Rle_trans _ _ _ (Rabs_pos _) (RmaxLess1 _ _)).
(* Goal: Rle (Rmult (Rabs l1_2) (pos eps3)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    unfold eps3, Rmax ; simpl ; destruct (Rle_dec (Rabs l1_2) 1).
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH))))) (Rmult (IZR (Zpos xH)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    rewrite <- (Rmult_1_l (eps/2/2)) ; apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Rabs_pos.
    rewrite Rmult_1_r ; apply Rlt_le, Rdiv_lt_0_compat ;
    [apply eps | apply Rmult_lt_0_compat ; apply Rlt_R0_R2].
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply r.
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Req_le ; field.
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
    apply Req_le ; field.
(* Goal: not (@eq R (Rabs l1_2) (IZR Z0)) *)
    apply sym_not_eq, Rlt_not_eq, (Rlt_trans _ _ _ Rlt_0_1 (Rnot_le_lt _ _ n)).
Qed.

Lemma derivable_pt_lim_comp_2d : forall f1 f2 f3 x l1x l1y l2 l3,
  differentiable_pt_lim f1 (f2 x) (f3 x) l1x l1y ->
  derivable_pt_lim f2 x l2 -> derivable_pt_lim f3 x l3 ->
  derivable_pt_lim (fun t => f1 (f2 t) (f3 t)) x (l1x * l2 + l1y * l3).
Proof.
(* Goal: forall (f1 : forall (_ : R) (_ : R), R) (f2 f3 : forall _ : R, R) (x l1x l1y l2 l3 : R) (_ : differentiable_pt_lim f1 (f2 x) (f3 x) l1x l1y) (_ : derivable_pt_lim f2 x l2) (_ : derivable_pt_lim f3 x l3), derivable_pt_lim (fun t : R => f1 (f2 t) (f3 t)) x (Rplus (Rmult l1x l2) (Rmult l1y l3)) *)
  intros.
(* Goal: derivable_pt_lim (fun t : R => f1 (f2 t) (f3 t)) x (Rplus (Rmult l1x l2) (Rmult l1y l3)) *)
  apply (differentiable_pt_lim_proj1_1 _ x 0 (l1x * l2 + l1y * l3)).
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
  pattern 0 at 2 ; replace 0 with (l1x * 0 + l1y * 0) by ring.
(* Goal: differentiable_pt_lim (fun u _ : R => f1 (f2 u) (f3 u)) x (IZR Z0) (Rplus (Rmult l1x l2) (Rmult l1y l3)) (Rplus (Rmult l1x (IZR Z0)) (Rmult l1y (IZR Z0))) *)
  apply differentiable_pt_lim_comp.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
  apply H.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
  apply: differentiable_pt_lim_proj1_0 H0.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
  apply: differentiable_pt_lim_proj1_0 H1.
Qed.

(** * Partial derivatives *)

Definition partial_derive (m k : nat) (f : R -> R -> R) : R -> R -> R :=
  fun x y => Derive_n (fun t => Derive_n (fun z => f t z) k y) m x.

Definition differential (p : nat) (f : R -> R -> R) (x y dx dy : R) : R :=
  sum_f_R0
    (fun m =>
      C p m *
      partial_derive m (p - m)%nat f x y *
      dx ^ m * dy ^ (p - m)%nat)
    p.

Definition DL_pol (n : nat) (f : R -> R -> R) (x y dx dy : R) : R :=
  sum_f_R0
    (fun p =>
      differential p f x y dx dy / INR (fact p))
    n.

Lemma partial_derive_ext_loc :
  forall f g p q x y,
  locally_2d (fun u v => f u v = g u v) x y ->
  partial_derive p q f x y = partial_derive p q g x y.
Proof.
(* Goal: forall (f g : forall (_ : R) (_ : R), R) (p q : nat) (x y : R) (_ : locally_2d (fun u v : R => @eq R (f u v) (g u v)) x y), @eq R (partial_derive p q f x y) (partial_derive p q g x y) *)
intros f g p q x y H.
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive.
(* Goal: @eq R (Derive_n (fun z : R => Derive (fun x : R => Derive (fun x0 : R => f x x0) z) x) p y) (Derive_n (fun z : R => Derive (fun x0 : R => Derive (fun x : R => f x x0) x) z) p y) *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply Derive_n_ext_loc.
(* Goal: @locally R_UniformSpace x (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive_n (fun z : R => f t z) q y) (Derive_n (fun z : R => g t z) q y)) *)
destruct H as (e,He).
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (f u t) (g u t)) *)
exists e.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace x (pos e) y0), @eq R (Derive_n (fun z : R => f y0 z) q y) (Derive_n (fun z : R => g y0 z) q y) *)
intros u Hu.
(* Goal: @eq R (Derive_n (fun z : R => Derive (fun x : R => Derive (fun x0 : R => f x x0) z) x) p y) (Derive_n (fun z : R => Derive (fun x0 : R => Derive (fun x : R => f x x0) x) z) p y) *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply Derive_n_ext_loc.
(* Goal: @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (f u t) (g u t)) *)
exists e.
(* Goal: forall (y0 : UniformSpace.sort R_UniformSpace) (_ : @ball R_UniformSpace y (pos e) y0), @eq R (f u y0) (g u y0) *)
intros v Hv.
(* Goal: @eq R (f u v) (g u v) *)
now apply He.
Qed.

(** * Schwarz theorem *)

Lemma Schwarz_aux :
  forall f x y (eps : posreal),
  ( forall u v, Rabs (u - x) < eps -> Rabs (v - y) < eps ->
    ex_derive (fun z : R => f z v) u /\
    ex_derive (fun z : R => Derive (fun t => f t z) u) v ) ->
  forall h k, Rabs h < eps -> Rabs k < eps ->
  let phi k x := f x (y + k) - f x y in
  exists u, exists v,
  Rabs (u - x) <= Rabs h /\ Rabs (v - y) <= Rabs k /\
  phi k (x + h) - phi k x = h * k * (Derive (fun z => Derive (fun t => f t z) u) v).
Proof.
intros f x y eps HD h k Hh Hk phi.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
assert (Hx: x + h - x = h) by ring.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
assert (Hy: y + k - y = k) by ring.
(* . *)
destruct (MVT_cor4 (phi k) (Derive (phi k)) x (Rabs h)) with (b := x + h) as (u&Hu1&Hu2).
intros c Hc.
apply Derive_correct.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: ex_derive_minus.
apply (HD c).
now apply Rle_lt_trans with (Rabs h).
(* Goal: @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (Init.Nat.add p O) (Init.Nat.add O k) (partial_derive (S O) O f) u v) *)
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now rewrite Hy.
apply (HD c).
now apply Rle_lt_trans with (Rabs h).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite /Rminus Rplus_opp_r Rabs_R0.
apply cond_pos.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Hx.
apply Rle_refl.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Hx in Hu1, Hu2.
exists u.
(* . *)
destruct (MVT_cor4 (fun v => Derive (fun t => f t v) u) (Derive (fun v => Derive (fun t => f t v) u)) y (Rabs k)) with (b := y + k) as (v&Hv1&Hv2).
intros c Hc.
apply Derive_correct, HD.
now apply Rle_lt_trans with (Rabs h).
now apply Rle_lt_trans with (1 := Hc).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Hy.
apply Rle_refl.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Hy in Hv1, Hv2.
exists v.
(* . *)
refine (conj Hu2 (conj Hv2 _)).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Hu1 /phi Derive_minus.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Hv1.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
ring.
apply (HD u).
now apply Rle_lt_trans with (Rabs h).
(* Goal: @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (Init.Nat.add p O) (Init.Nat.add O k) (partial_derive (S O) O f) u v) *)
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now rewrite Hy.
apply (HD u).
now apply Rle_lt_trans with (Rabs h).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite /Rminus Rplus_opp_r Rabs_R0.
apply cond_pos.
Qed.

Lemma Schwarz :
  forall (f : R -> R -> R) x y,
  locally_2d (fun u v =>
    ex_derive (fun z : R => f z v) u /\
    ex_derive (fun z : R => f u z) v /\
    ex_derive (fun z : R => Derive (fun t => f z t) v) u /\
    ex_derive (fun z : R => Derive (fun t => f t z) u) v) x y ->
  continuity_2d_pt (fun u v => Derive (fun z => Derive (fun t => f z t) v) u) x y ->
  continuity_2d_pt (fun u v => Derive (fun z => Derive (fun t => f t z) u) v) x y ->
  Derive (fun z => Derive (fun t => f z t) y) x = Derive (fun z => Derive (fun t => f t z) x) y.
Proof.
intros f x y (eps, HD) HC2 HC1.
refine ((fun H1 => _) (Schwarz_aux f x y eps _)).
2: intros u v Hu Hv ; split ; now apply (HD u v).
refine ((fun H2 => _ )(Schwarz_aux (fun x y => f y x) y x eps _)).
2: intros u v Hu Hv ; split ; now apply (HD v u).
simpl in H1, H2.
apply Req_lt_aux.
intros e.
destruct (HC1 (pos_div_2 e)) as (d1,Hc1).
destruct (HC2 (pos_div_2 e)) as (d2,Hc2).
set (d := Rmin (Rmin (pos_div_2 d1) (pos_div_2 d2)) (pos_div_2 eps)).
assert (Hd: d > 0).
apply Rmin_glb_lt.
apply Rmin_stable_in_posreal.
apply cond_pos.
assert (K: Rabs d < eps).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Rabs_right.
apply Rle_lt_trans with (1 := Rmin_r _ _).
apply (Rlt_eps2_eps eps).
apply cond_pos.
now apply Rgt_ge.
specialize (H1 d d K K).
specialize (H2 d d K K).
destruct H1 as (u1&v1&Hu1&Hv1&H1).
destruct H2 as (v2&u2&Hv2&Hu2&H2).
clear K.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite (Rabs_right d (Rgt_ge _ _ Hd)) in Hu1 Hv1 Hu2 Hv2.
assert (K: forall a b, Rabs (a - b) <= d -> Rabs (a - b) < d1).
intros a b H.
apply Rle_lt_trans with (1 := H).
apply Rle_lt_trans with (1 := Rmin_l _ _).
apply Rle_lt_trans with (1 := Rmin_l _ _).
apply (Rlt_eps2_eps d1).
apply cond_pos.
specialize (Hc1 u1 v1 (K _ _ Hu1) (K _ _ Hv1)).
clear K.
assert (K: forall a b, Rabs (a - b) <= d -> Rabs (a - b) < d2).
intros a b H.
apply Rle_lt_trans with (1 := H).
apply Rle_lt_trans with (1 := Rmin_l _ _).
apply Rle_lt_trans with (1 := Rmin_r _ _).
apply (Rlt_eps2_eps d2).
apply cond_pos.
specialize (Hc2 u2 v2 (K _ _ Hu2) (K _ _ Hv2)).
clear -Hd H1 H2 Hc1 Hc2.
assert (H: forall a b c, b - c = -(a - b) + (a - c)) by (intros ; ring).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite (H (Derive (fun z : R => Derive (fun t : R => f z t) v2) u2)).
clear H.
apply Rle_lt_trans with (1 := Rabs_triang _ _).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Rabs_Ropp (double_var e).
apply Rplus_lt_compat.
exact Hc2.
replace (Derive (fun z : R => Derive (fun t : R => f z t) v2) u2) with
  (Derive (fun z : R => Derive (fun t : R => f t z) u1) v1).
exact Hc1.
apply Rmult_eq_reg_l with (d * d).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite -H1 -H2.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
ring.
apply Rgt_not_eq.
now apply Rmult_gt_0_compat.
Qed.

Lemma partial_derive_add_zero: forall f p q r s x y,
  (q=0)%nat \/ (r=0)%nat ->
  partial_derive p q (partial_derive r s f) x y
   = partial_derive (p+r) (q+s) f x y.
(* Goal: forall (f : forall (_ : R) (_ : R), R) (p q r s : nat) (x y : R) (_ : or (@eq nat q O) (@eq nat r O)), @eq R (partial_derive p q (partial_derive r s f) x y) (partial_derive (Init.Nat.add p r) (Init.Nat.add q s) f x y) *)
intros f p q r s x y H.
(* Goal: @eq R (partial_derive p q (partial_derive r s f) x y) (partial_derive (Init.Nat.add p r) (Init.Nat.add q s) f x y) *)
destruct H; rewrite H.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite plus_0_l.
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite -Derive_n_comp.
(* Goal: @eq R (Derive_n (fun z : R => Derive_n (fun z0 : R => f y0 z0) s z) q y) (Derive_n (Derive_n (fun z : R => f y0 z) s) q y) *)
now apply Derive_n_ext.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite plus_0_r.
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun z0 : R => f t z0) s z) q y) p x) (Derive_n (fun t : R => Derive_n (fun z : R => f t z) (Init.Nat.add q s) y) p x) *)
apply Derive_n_ext.
(* Goal: forall t : R, @eq R (Derive_n (fun z : R => Derive_n (fun z0 : R => f t z0) s z) q y) (Derive_n (fun z : R => f t z) (Init.Nat.add q s) y) *)
intros y0.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite -Derive_n_comp.
(* Goal: @eq R (Derive_n (fun z : R => Derive_n (fun z0 : R => f y0 z0) s z) q y) (Derive_n (Derive_n (fun z : R => f y0 z) s) q y) *)
now apply Derive_n_ext.
Qed.


(** * Iterated differential *)

Fixpoint ex_diff_n f n x y :=
  continuity_2d_pt f x y /\
  match n with
  | O => True
  | S n =>
    ex_derive (fun z => f z y) x /\
    ex_derive (fun z => f x z) y /\
    ex_diff_n (fun u v => Derive (fun z => f z v) u) n x y /\
    ex_diff_n (fun u v => Derive (fun z => f u z) v) n x y
  end.

Lemma ex_diff_n_ext_loc: forall f g n x y,
    locally_2d (fun u v =>  f u v = g u v) x y
      -> ex_diff_n f n x y -> ex_diff_n g n x y.
Proof.
(* Goal: forall (f g : forall (_ : R) (_ : R), R) (n : nat) (x y : R) (_ : locally_2d (fun u v : R => @eq R (f u v) (g u v)) x y) (_ : ex_diff_n f n x y), ex_diff_n g n x y *)
intros f g n; revert f g.
(* Goal: ex_diff_n f m x y *)
induction n.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros f g x y H; simpl.
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros (H1,_); split.
(* Goal: continuity_2d_pt g x y *)
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => g z y) x) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y) (and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y))) *)
apply (continuity_2d_pt_ext_loc _ _ _ _ H H1).
(* Goal: forall _ : @eq R (partial_derive O (S O) (partial_derive p k f) x y) (partial_derive p (S k) f x y), @eq R (Derive (fun v : R => partial_derive p k f x v) y) (partial_derive p (S k) f x y) *)
easy.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: forall (f g : forall (_ : R) (_ : R), R) (x y : R) (_ : locally_2d (fun u v : R => @eq R (f u v) (g u v)) x y) (_ : and (continuity_2d_pt f x y) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => f z y) x) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y) (and (ex_diff_n (fun u v : R => Derive (fun z : R => f z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) n x y))))), and (continuity_2d_pt g x y) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => g z y) x) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y) (and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y)))) *)
intros f g x y H (H1&H2&H3&H4&H5).
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: continuity_2d_pt g x y *)
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => g z y) x) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y) (and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y))) *)
apply (continuity_2d_pt_ext_loc _ _ _ _ H H1).
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: ex_derive_ext_loc H2.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (f t y) (g t y)) *)
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y) (and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y)) *)
apply locally_2d_1d_const_y with (1:=H).
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: ex_derive_ext_loc H3.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) y (fun t : AbsRing.sort R_AbsRing => @eq (NormedModule.sort R_AbsRing R_NormedModule) (f x t) (g x t)) *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply locally_2d_1d_const_x with (1:=H).
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y *)
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y *)
apply IHn with (2:=H4).
(* Goal: locally_2d (fun u v : R => @eq R (partial_derive O k (partial_derive (S O) O f) u v) (partial_derive (S O) k f u v)) u v *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply locally_2d_impl_strong with (2:=H).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : locally_2d (fun u0 v0 : R => @eq R (f u0 v0) (g u0 v0)) u v), @eq R (Derive (fun z : R => f u z) v) (Derive (fun z : R => g u z) v) *)
intros u v H6.
(* Goal: @eq R (Derive (fun z : R => f u z) v) (Derive (fun z : R => g u z) v) *)
apply Derive_ext_loc.
(* Goal: @locally R_UniformSpace u (fun t : UniformSpace.sort R_UniformSpace => @eq R (f t v) (g t v)) *)
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y *)
apply locally_2d_1d_const_y with (1:=H6).
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y *)
apply IHn with (2:=H5).
(* Goal: locally_2d (fun u v : R => @eq R (partial_derive O k (partial_derive (S O) O f) u v) (partial_derive (S O) k f u v)) u v *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply locally_2d_impl_strong with (2:=H).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : locally_2d (fun u0 v0 : R => @eq R (f u0 v0) (g u0 v0)) u v), @eq R (Derive (fun z : R => f u z) v) (Derive (fun z : R => g u z) v) *)
intros u v H6.
(* Goal: @eq R (Derive (fun z : R => f u z) v) (Derive (fun z : R => g u z) v) *)
apply Derive_ext_loc.
(* Goal: @locally R_UniformSpace v (fun t : UniformSpace.sort R_UniformSpace => @eq R (f u t) (g u t)) *)
apply locally_2d_1d_const_x with (1:=H6).
Qed.

Lemma ex_diff_n_m :
  forall n m, (m <= n)%nat -> forall f x y, ex_diff_n f n x y -> ex_diff_n f m x y.
Proof.
(* Goal: forall (n m : nat) (_ : le m n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), ex_diff_n f m x y *)
assert (forall n f x y, ex_diff_n f (S n) x y -> ex_diff_n f n x y).
(* Goal: ex_diff_n f m x y *)
induction n.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros f x y H; split; try apply H.
(* Goal: forall (f : forall (_ : R) (_ : R), R) (x y : R) (_ : locally_2d (ex_diff_n f (S (S p))) x y), @eq R (partial_derive (S O) (S p) f x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
intros f x y H.
(* Goal: ex_diff_n f (S n) x y *)
(* Goal: forall (n m : nat) (_ : le m n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), ex_diff_n f m x y *)
repeat (split; try apply H).
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) n x y *)
(* Goal: forall (n m : nat) (_ : le m n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), ex_diff_n f m x y *)
apply IHn.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
apply H.
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) n x y *)
(* Goal: forall (n m : nat) (_ : le m n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), ex_diff_n f m x y *)
apply IHn.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
apply H.
(* Goal: forall (n m : nat) (_ : le m n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), ex_diff_n f m x y *)
intros n m H1 f x y Hn.
(* Goal: ex_diff_n f m x y *)
induction n.
(* Goal: ex_diff_n f m x y *)
(* Goal: ex_diff_n f m x y *)
replace m with 0%nat.
(* Goal: ex_diff_n f O x y *)
(* Goal: @eq nat O m *)
(* Goal: ex_diff_n f m x y *)
exact Hn.
(* Goal: @eq nat O m *)
(* Goal: ex_diff_n f m x y *)
now apply le_n_0_eq.
(* Goal: ex_diff_n f m x y *)
case (le_lt_or_eq _ _ H1).
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) n x y *)
(* Goal: forall (n m : nat) (_ : le m n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), ex_diff_n f m x y *)
intros H2; apply IHn.
(* Goal: le m n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: forall _ : @eq nat m (S n), ex_diff_n f m x y *)
now apply gt_S_le.
(* Goal: ex_diff_n f n x y *)
(* Goal: forall _ : @eq nat m (S n), ex_diff_n f m x y *)
apply (H _ _ _ _ Hn).
(* Goal: forall _ : @eq nat m (S n), ex_diff_n f m x y *)
intros H2; now rewrite H2.
Qed.

Lemma ex_diff_n_deriv_aux1: forall f n x y,
  ex_diff_n f (S n) x y -> ex_diff_n (fun u v => Derive (fun z => f z v) u) n x y.
Proof.
(* Goal: forall (f : forall (_ : R) (_ : R), R) (n : nat) (x y : R) (_ : ex_diff_n f (S n) x y), ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) n x y *)
intros f n x y.
(* Goal: forall _ : ex_diff_n f (S n) x y, ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) n x y *)
case n.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros H; split; apply H.
(* Goal: forall (n : nat) (_ : ex_diff_n f (S (S n)) x y), ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) (S n) x y *)
clear n;intros n H.
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) (S n) x y *)
simpl in H.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
repeat split; apply H.
Qed.

Lemma ex_diff_n_deriv_aux2: forall f n x y,
  ex_diff_n f (S n) x y -> ex_diff_n (fun u v => Derive (fun z => f u z) v) n x y.
Proof.
(* Goal: forall (f : forall (_ : R) (_ : R), R) (n : nat) (x y : R) (_ : ex_diff_n f (S n) x y), ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) n x y *)
intros f n x y.
(* Goal: forall _ : ex_diff_n f (S n) x y, ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) n x y *)
case n.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros H; split; apply H.
(* Goal: forall (n : nat) (_ : ex_diff_n f (S (S n)) x y), ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) (S n) x y *)
clear n;intros n H.
(* Goal: ex_diff_n (fun u v : R => Derive (fun z : R => f u z) v) (S n) x y *)
simpl in H.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
repeat split; apply H.
Qed.

Lemma ex_diff_n_deriv: forall n p q, (p+q <= n)%nat -> forall f x y,
    ex_diff_n f n x y-> ex_diff_n (partial_derive p q f) (n -(p+q)) x y.
induction p.
(* . *)
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
intros q; rewrite plus_0_l.
induction q.
intros H f x y H1.
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite - minus_n_O.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: (ex_diff_n_ext_loc _ _ _ _ _ _ H1).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
now apply locally_2d_forall.
intros H f x y H1.
apply (ex_diff_n_ext_loc (fun u v => Derive (fun z => (partial_derive 0 q f) u z) v)).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros u v; unfold partial_derive.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
apply ex_diff_n_deriv_aux2.
replace ((S (n - S q))) with (n-q)%nat by omega.
apply IHq.
(* Goal: le (Init.Nat.add p k) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
now apply lt_le_weak.
exact H1.
(* . *)
intros q H f x y H1.
apply (ex_diff_n_ext_loc (fun u v => Derive (fun z => (partial_derive p q f) z v) u)).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros u v; unfold partial_derive.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
apply ex_diff_n_deriv_aux1.
replace ((S (n - (S p +q)))) with (n-(p+q))%nat by omega.
apply IHp.
(* Goal: le (Init.Nat.add p k) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
now apply lt_le_weak.
exact H1.
Qed.

Lemma ex_diff_n_ex_deriv_inf_1 : forall n p k, (p+k < n)%nat -> forall f x y,
    ex_diff_n f n x y ->
    ex_derive  (fun z : R => partial_derive p k f z y) x.
Proof.
(* Goal: forall (n p k : nat) (_ : lt (Init.Nat.add p k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive p k f x z) y *)
intros n p; case p; clear p.
(* . *)
(* Goal: forall (k : nat) (_ : lt (Init.Nat.add O k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O k f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros k; case k; clear k.
(* Goal: forall (_ : lt (Init.Nat.add O O) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O O f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
case n; clear n.
(* Goal: forall (_ : lt (Init.Nat.add O O) O) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f O x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O O f x z) y *)
(* Goal: forall (n : nat) (_ : lt (Init.Nat.add O O) (S n)) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f (S n) x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O O f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros Hn; contradict Hn; apply lt_n_O.
(* Goal: forall (n : nat) (_ : lt (Init.Nat.add O O) (S n)) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f (S n) x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O O f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros n _ f x y H.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive; simpl.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
apply H.
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros n0 H f x y Hf.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
assert (ex_diff_n (partial_derive 0 n0 f) (n -(0+n0)) x y).
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
apply ex_diff_n_deriv.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
auto with zarith.
(* Goal: ex_diff_n f n x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
exact Hf.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
revert H0; rewrite plus_0_l.
(* Goal: forall _ : ex_diff_n (partial_derive O n0 f) (Init.Nat.sub n n0) x y, @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
case_eq (n-n0)%nat.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
intros H1; contradict H; auto with zarith.
(* Goal: forall (n1 : nat) (_ : @eq nat (Init.Nat.sub n n0) (S n1)) (_ : ex_diff_n (partial_derive O n0 f) (S n1) x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros n1 H1 H2.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => partial_derive O (S n0) f z y) x *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : R => partial_derive (S n0) k f z y) x *)
apply ex_derive_ext with (fun z => Derive (fun t => (partial_derive 0 n0 f z) t) y).
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros y0; unfold partial_derive; simpl.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive O n0 f x t) z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
simpl in H2.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive O n0 f x t) z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
destruct H2 as (T1&T2&T3&T4&T5).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
case_eq n1.
(* Goal: forall _ : @eq nat n1 O, @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
(* Goal: forall (n : nat) (_ : @eq nat n1 (S n)), @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
intros H2; rewrite H2 in H1.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
clear -H H1; contradict H; auto with zarith.
(* Goal: forall (n : nat) (_ : @eq nat n1 (S n)), @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
intros n2 Hn2; rewrite Hn2 in T5.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u' *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v' *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply T5.
(* . *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros p q H f x y Hf.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
assert (ex_diff_n (partial_derive p q f) (n -(p+q)) x y).
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
apply ex_diff_n_deriv.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
auto with zarith.
(* Goal: ex_diff_n f n x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
exact Hf.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
case_eq (n-(p+q))%nat.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
intros H1; contradict H; auto with zarith.
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p q)) (S n0)), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
intros n1 H1.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => partial_derive (S p) q f z y) x *)
apply ex_derive_ext with (fun z => Derive (fun t => (partial_derive p q f t) y) z).
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros x0; unfold partial_derive; simpl.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
rewrite H1 in H0; simpl in H0.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
destruct H0 as (T1&T2&T3&T4&T5).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
case_eq n1.
(* Goal: forall _ : @eq nat n1 O, @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
(* Goal: forall (n : nat) (_ : @eq nat n1 (S n)), @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
intros H2; rewrite H2 in H1.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
clear -H H1; contradict H; auto with zarith.
(* Goal: forall (n : nat) (_ : @eq nat n1 (S n)), @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
intros n2 Hn2; rewrite Hn2 in T4.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v' *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply T4.
Qed.

Lemma ex_diff_n_ex_deriv_inf_2 : forall n p k, (p+k < n)%nat -> forall f x y,
  ex_diff_n f n x y ->
  ex_derive (fun z => partial_derive p k f x z) y.
Proof.
(* Goal: forall (n p k : nat) (_ : lt (Init.Nat.add p k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive p k f x z) y *)
intros n p; case p; clear p.
(* . *)
(* Goal: forall (k : nat) (_ : lt (Init.Nat.add O k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O k f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros k; case k; clear k.
(* Goal: forall (_ : lt (Init.Nat.add O O) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O O f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
case n; clear n.
(* Goal: forall (_ : lt (Init.Nat.add O O) O) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f O x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O O f x z) y *)
(* Goal: forall (n : nat) (_ : lt (Init.Nat.add O O) (S n)) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f (S n) x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O O f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros Hn; contradict Hn; apply lt_n_O.
(* Goal: forall (n : nat) (_ : lt (Init.Nat.add O O) (S n)) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f (S n) x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O O f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros n _ f x y H.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive; simpl.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
apply H.
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros n0 H f x y Hf.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
assert (ex_diff_n (partial_derive 0 n0 f) (n -(0+n0)) x y).
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
apply ex_diff_n_deriv.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
auto with zarith.
(* Goal: ex_diff_n f n x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
exact Hf.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
revert H0; rewrite plus_0_l.
(* Goal: forall _ : ex_diff_n (partial_derive O n0 f) (Init.Nat.sub n n0) x y, @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
case_eq (n-n0)%nat.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
intros H1; contradict H; auto with zarith.
(* Goal: forall (n1 : nat) (_ : @eq nat (Init.Nat.sub n n0) (S n1)) (_ : ex_diff_n (partial_derive O n0 f) (S n1) x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros n1 H1 H2.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
apply ex_derive_ext with (fun z => Derive (fun t => (partial_derive 0 n0 f x) t) z).
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros y0; unfold partial_derive; simpl.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive O n0 f x t) z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
simpl in H2.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive O n0 f x t) z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
destruct H2 as (T1&T2&T3&T4&T5).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
case_eq n1.
(* Goal: forall _ : @eq nat n1 O, @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
(* Goal: forall (n : nat) (_ : @eq nat n1 (S n)), @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
intros H2; rewrite H2 in H1.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
clear -H H1; contradict H; auto with zarith.
(* Goal: forall (n : nat) (_ : @eq nat n1 (S n)), @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
intros n2 Hn2; rewrite Hn2 in T5.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u' *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v' *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply T5.
(* . *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros p q H f x y Hf.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
assert (ex_diff_n (partial_derive p q f) (n -(p+q)) x y).
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
apply ex_diff_n_deriv.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
auto with zarith.
(* Goal: ex_diff_n f n x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
exact Hf.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
case_eq (n-(p+q))%nat.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
intros H1; contradict H; auto with zarith.
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p q)) (S n0)), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
intros n1 H1.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
apply ex_derive_ext with (fun z => Derive (fun t => (partial_derive p q f t) z) x).
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros x0; unfold partial_derive; simpl.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
rewrite H1 in H0; simpl in H0.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
destruct H0 as (T1&T2&T3&T4&T5).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
case_eq n1.
(* Goal: forall _ : @eq nat n1 O, @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
(* Goal: forall (n : nat) (_ : @eq nat n1 (S n)), @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
intros H2; rewrite H2 in H1.
(* Goal: le (Init.Nat.add p q) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S p) q f x z) y *)
clear -H H1; contradict H; auto with zarith.
(* Goal: forall (n : nat) (_ : @eq nat n1 (S n)), @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive p q f t z) x) y *)
intros n2 Hn2; rewrite Hn2 in T4.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v' *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply T4.
Qed.

Lemma ex_diff_n_continuity_inf_1 : forall n p k, (p+k < n)%nat -> forall f x y,
  ex_diff_n f n x y ->
  continuity_2d_pt (fun u v => Derive (fun z : R => partial_derive p k f z v) u) x y.
Proof.
(* Goal: forall (n p k : nat) (_ : lt (Init.Nat.add p k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
intros n p k Hn f x y Hf.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f z v) u) x y *)
assert (ex_diff_n (partial_derive (S p) k f) (n -(S p+k)) x y).
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
now apply ex_diff_n_deriv.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f z v) u) x y *)
apply continuity_2d_pt_ext_loc with (partial_derive (S p) k f).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros u v; unfold partial_derive; simpl.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: continuity_2d_pt (partial_derive (S p) k f) x y *)
revert H; case (n - (S p + k))%nat.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
simpl; intros H; apply H.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
intros n0; simpl; intros H; apply H.
Qed.

Lemma Derive_partial_derive_aux1: forall p f x y,
  locally_2d (ex_diff_n f (S p)) x y ->
   partial_derive  1 p f x y = partial_derive 0 p (partial_derive  1 0 f) x y.
Proof.
intros p; induction p.
(* Goal: forall (f : forall (_ : R) (_ : R), R) (x y : R) (_ : locally_2d (ex_diff_n f (S (S p))) x y), @eq R (partial_derive (S O) (S p) f x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
intros f x y H.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive; now simpl.
(* Goal: forall (f : forall (_ : R) (_ : R), R) (x y : R) (_ : locally_2d (ex_diff_n f (S (S p))) x y), @eq R (partial_derive (S O) (S p) f x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
intros f x y H.
apply trans_eq with  (partial_derive 1 p (partial_derive 0 1 f) x y).
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @eq R (Derive (fun x : R => Derive (Derive_n (fun z : R => f x z) p) y) x) (Derive (fun x : R => Derive_n (fun z : R => Derive (fun x0 : R => f x x0) z) p y) x) *)
(* Goal: @eq R (partial_derive (S O) p (partial_derive O (S O) f) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
apply Derive_ext.
(* Goal: forall t : R, @eq R (Derive (Derive_n (fun z : R => f t z) p) y) (Derive_n (fun z : R => Derive (fun x : R => f t x) z) p y) *)
(* Goal: @eq R (partial_derive (S O) p (partial_derive O (S O) f) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
intros t.
(* Goal: @eq R (Derive (Derive_n (fun z : R => f t z) p) y) (Derive_n (fun z : R => Derive (fun x : R => f t x) z) p y) *)
(* Goal: @eq R (partial_derive (S O) p (partial_derive O (S O) f) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
apply trans_eq with (Derive_n (Derive_n (fun z : R => f t z) p) 1 y).
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Derive_n_comp.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Arith.Plus.plus_comm.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite -Derive_n_comp.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite IHp.
apply trans_eq with
  (partial_derive 0 p (partial_derive 0 1 (partial_derive 1 0 f)) x y).
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @eq R (Derive_n (fun z : R => Derive (fun x : R => Derive (fun x0 : R => f x x0) z) x) p y) (Derive_n (fun z : R => Derive (fun x0 : R => Derive (fun x : R => f x x0) x) z) p y) *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply Derive_n_ext_loc.
cut (locally_2d (fun u v =>
         Derive (fun x0 : R => Derive (fun x1 : R => f x0 x1) v) u =
         Derive (fun x0 : R => Derive (fun x1 : R => f x1 x0) u) v) x y).
(* Goal: forall _ : locally_2d (fun u v : R => @eq R (Derive (fun x0 : R => Derive (fun x1 : R => f x0 x1) v) u) (Derive (fun x0 : R => Derive (fun x1 : R => f x1 x0) u) v)) x y, @locally R_UniformSpace y (fun t : UniformSpace.sort R_UniformSpace => @eq R (Derive (fun x : R => Derive (fun x0 : R => f x x0) t) x) (Derive (fun x0 : R => Derive (fun x : R => f x x0) x) t)) *)
(* Goal: locally_2d (fun u v : R => @eq R (Derive (fun x0 : R => Derive (fun x1 : R => f x0 x1) v) u) (Derive (fun x0 : R => Derive (fun x1 : R => f x1 x0) u) v)) x y *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply locally_2d_1d_const_x.
(* Goal: locally_2d (fun u v : R => @eq R (partial_derive O k (partial_derive (S O) O f) u v) (partial_derive (S O) k f u v)) u v *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply locally_2d_impl_strong with (2:=H).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : locally_2d (ex_diff_n f (S (S p))) u v), @eq R (Derive (fun x0 : R => Derive (fun x1 : R => f x0 x1) v) u) (Derive (fun x0 : R => Derive (fun x1 : R => f x1 x0) u) v) *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros u v H1.
(* Goal: @eq R (Derive (fun x0 : R => Derive (fun x1 : R => f x0 x1) v) u) (Derive (fun x0 : R => Derive (fun x1 : R => f x1 x0) u) v) *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply Schwarz.
(* Goal: locally_2d (fun u v : R => and (@ex_derive R_AbsRing R_NormedModule (fun z : R => f z v) u) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => f u z) v) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v) u) (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u) v)))) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply locally_2d_impl with (2:=H1).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : ex_diff_n f (S (S p)) u v), and (@ex_derive R_AbsRing R_NormedModule (fun z : R => f z v) u) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => f u z) v) (and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v) u) (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u) v))) *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
intros u' v' H2.
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f u' z) v' *)
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply H2.
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f u' z) v' *)
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply H2.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => partial_derive O n0 f x t) z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
simpl in H2; destruct H2 as (T1&T2&T3&T4&T5).
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u' *)
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v' *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply T5.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v' *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply T4.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply locally_2d_singleton in H1.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl in H1; destruct H1 as (T1&T2&T3&T4&T5).
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
destruct T5 as (Y1&Y2&Y3&Y4&Y5).
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
clear - Y4.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
case p in Y4; simpl in Y4; apply Y4.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply locally_2d_singleton in H1.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl in H1; destruct H1 as (T1&T2&T3&T4&T5).
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
destruct T4 as (Y1&Y2&Y3&Y4&Y5).
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
clear - Y5.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
case p in Y5; simpl in Y5; apply Y5.
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold partial_derive.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @eq R (Derive_n (fun z : R => Derive (fun x0 : R => Derive (fun x : R => f x x0) x) z) p y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
apply trans_eq with (Derive_n (Derive_n (fun z => Derive (fun x0 => f x0 z) x) p) 1 y).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Derive_n_comp.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Arith.Plus.plus_comm.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite -Derive_n_comp.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
(* Goal: locally_2d (ex_diff_n f (S (S k))) u v *)
(* Goal: @eq R (partial_derive p O (partial_derive O (S k) (partial_derive (S O) O f)) x y) (partial_derive O (S O) (partial_derive (S p) k f) x y) *)
apply locally_2d_impl with (2:=H).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : ex_diff_n f (S (S p)) u v), ex_diff_n (partial_derive O (S O) f) (S p) u v *)
intros u v.
(* Goal: forall _ : ex_diff_n f (S (S p)) u v, ex_diff_n (partial_derive O (S O) f) (S p) u v *)
pattern (S p) at 2; replace (S p) with (S (S p) -(0+1))%nat.
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
apply ex_diff_n_deriv.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite plus_0_l.
(* Goal: le (S O) (S (S p)) *)
(* Goal: @eq nat (Init.Nat.sub (S (S p)) (Init.Nat.add O (S O))) (S p) *)
apply lt_le_S; apply lt_0_Sn.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite plus_0_l.
(* Goal: not (lt (Init.Nat.add p k) n) *)
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p k)) (S n0)) (_ : ex_diff_n (partial_derive p k f) (S n0) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
omega.
Qed.

Lemma Derive_partial_derive_aux2: forall p k f x y,
  locally_2d (ex_diff_n f (p+S k)) x y ->
  partial_derive 0 1 (partial_derive p k f) x y =
     partial_derive p (S k) f x y.
Proof.
intros p; induction p.
(* Goal: forall _ : @eq R (partial_derive O (S O) (partial_derive p k f) x y) (partial_derive p (S k) f x y), @eq R (Derive (fun v : R => partial_derive p k f x v) y) (partial_derive p (S k) f x y) *)
intros; easy.
(* Goal: forall (k : nat) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : locally_2d (ex_diff_n f (Init.Nat.add (S p) (S k))) x y), @eq R (partial_derive O (S O) (partial_derive (S p) k f) x y) (partial_derive (S p) (S k) f x y) *)
intros k f x y Y.
(* Goal: @eq R (partial_derive O k (partial_derive (S O) O f) u' v') (partial_derive (S O) k f u' v') *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply sym_eq.
apply trans_eq with
  (partial_derive p 0 (partial_derive 1 (S k) f) x y).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite partial_derive_add_zero.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite plus_0_l.
(* Goal: @eq R (partial_derive (Init.Nat.add p (S O)) k f u v) (partial_derive (S p) k f u v) *)
(* Goal: or (@eq nat O O) (@eq nat (S O) O) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
replace (S p) with (p+1)%nat by apply Arith.Plus.plus_comm.
(* Goal: forall _ : @eq R (partial_derive O (S O) (partial_derive p k f) x y) (partial_derive p (S k) f x y), @eq R (Derive (fun v : R => partial_derive p k f x v) y) (partial_derive p (S k) f x y) *)
easy.
(* Goal: or (@eq nat O O) (@eq nat (S O) O) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now left.
apply trans_eq with
  (partial_derive p 0 (partial_derive 0 (S k) (partial_derive 1 0 f)) x y).
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive p O (partial_derive (S O) k f) u v) *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply partial_derive_ext_loc.
(* Goal: locally_2d (fun u v : R => @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (S p) k f u v)) x y *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply locally_2d_impl_strong with (2:=Y).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : locally_2d (ex_diff_n f (Init.Nat.add (S p) (S k))) u v), @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
intros u v H.
(* Goal: @eq R (partial_derive (S O) k f u' v') (partial_derive O k (partial_derive (S O) O f) u' v') *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply Derive_partial_derive_aux1.
(* Goal: locally_2d (ex_diff_n f (S (S k))) u v *)
(* Goal: @eq R (partial_derive p O (partial_derive O (S k) (partial_derive (S O) O f)) x y) (partial_derive O (S O) (partial_derive (S p) k f) x y) *)
apply locally_2d_impl with (2:=H).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v), ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v *)
intros u'' v''.
(* Goal: forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u'' v'', ex_diff_n f (S k) u'' v'' *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply ex_diff_n_m.
(* Goal: not (lt (Init.Nat.add p k) n) *)
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p k)) (S n0)) (_ : ex_diff_n (partial_derive p k f) (S n0) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
omega.
(* Goal: @eq R (partial_derive p O (partial_derive O (S k) (partial_derive (S O) O f)) x y) (partial_derive O (S O) (partial_derive (S p) k f) x y) *)
apply trans_eq with (partial_derive p (S k) (partial_derive 1 0 f) x y).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite partial_derive_add_zero.
(* Goal: @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (Init.Nat.add p O) (Init.Nat.add O k) (partial_derive (S O) O f) u v) *)
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now rewrite plus_0_l plus_0_r.
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now right.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite - IHp.
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive p O (partial_derive (S O) k f) u v) *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply partial_derive_ext_loc.
(* Goal: locally_2d (fun u v : R => @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (S p) k f u v)) x y *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply locally_2d_impl_strong with (2:=Y).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : locally_2d (ex_diff_n f (Init.Nat.add (S p) (S k))) u v), @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
intros u v H.
apply trans_eq with
 (partial_derive p 0 (partial_derive 0 k (partial_derive 1 0 f)) u v).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite (partial_derive_add_zero _ _ 0%nat).
(* Goal: @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (Init.Nat.add p O) (Init.Nat.add O k) (partial_derive (S O) O f) u v) *)
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now rewrite plus_0_l plus_0_r.
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now right.
apply trans_eq with
 (partial_derive p 0 (partial_derive 1 k f) u v).
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive p O (partial_derive (S O) k f) u v) *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply partial_derive_ext_loc.
(* Goal: locally_2d (fun u v : R => @eq R (partial_derive O k (partial_derive (S O) O f) u v) (partial_derive (S O) k f u v)) u v *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply locally_2d_impl_strong with (2:=H).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : locally_2d (ex_diff_n f (Init.Nat.add (S p) (S k))) u v), @eq R (partial_derive O k (partial_derive (S O) O f) u v) (partial_derive (S O) k f u v) *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
intros u' v' H'.
(* Goal: @eq R (partial_derive O k (partial_derive (S O) O f) u' v') (partial_derive (S O) k f u' v') *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply sym_eq.
(* Goal: @eq R (partial_derive (S O) k f u' v') (partial_derive O k (partial_derive (S O) O f) u' v') *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply Derive_partial_derive_aux1.
(* Goal: locally_2d (ex_diff_n f (S k)) u' v' *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply locally_2d_impl with (2:=H').
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v), ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v *)
intros u'' v''.
(* Goal: forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u'' v'', ex_diff_n f (S k) u'' v'' *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply ex_diff_n_m.
(* Goal: le (S k) (Init.Nat.add (S p) (S k)) *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply le_plus_r.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite partial_derive_add_zero.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite plus_0_l.
(* Goal: @eq R (partial_derive (Init.Nat.add p (S O)) k f u v) (partial_derive (S p) k f u v) *)
(* Goal: or (@eq nat O O) (@eq nat (S O) O) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
replace (S p) with (p+1)%nat by apply Arith.Plus.plus_comm.
(* Goal: forall _ : @eq R (partial_derive O (S O) (partial_derive p k f) x y) (partial_derive p (S k) f x y), @eq R (Derive (fun v : R => partial_derive p k f x v) y) (partial_derive p (S k) f x y) *)
easy.
(* Goal: or (@eq nat O O) (@eq nat (S O) O) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now left.
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply locally_2d_impl with (2:=Y).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
(* Goal: forall (u v : R) (_ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v), ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v *)
intros u'' v''.
(* Goal: forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u'' v'', ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u'' v'' *)
replace (p+ S k)%nat with ((S p+S k)-(1+0))%nat.
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
apply ex_diff_n_deriv.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite plus_0_r.
(* Goal: le (S O) (S (S p)) *)
(* Goal: @eq nat (Init.Nat.sub (S (S p)) (Init.Nat.add O (S O))) (S p) *)
apply le_plus_trans; apply lt_le_S; apply lt_0_Sn.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite plus_0_r.
(* Goal: not (lt (Init.Nat.add p k) n) *)
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p k)) (S n0)) (_ : ex_diff_n (partial_derive p k f) (S n0) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
omega.
Qed.

Lemma Derive_partial_derive: forall p k f x y,
  locally_2d (ex_diff_n f (p+S k)) x y ->
  Derive (fun v : R => partial_derive p k f x v) y =
     partial_derive p (S k) f x y.
Proof.
(* Goal: forall (p k : nat) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : locally_2d (ex_diff_n f (Init.Nat.add p (S k))) x y), @eq R (Derive (fun v : R => partial_derive p k f x v) y) (partial_derive p (S k) f x y) *)
intros p k f x y H.
(* Goal: @eq R (Derive (fun v : R => partial_derive p k f x v) y) (partial_derive p (S k) f x y) *)
generalize (Derive_partial_derive_aux2 p k f x y H).
(* Goal: forall _ : @eq R (partial_derive O (S O) (partial_derive p k f) x y) (partial_derive p (S k) f x y), @eq R (Derive (fun v : R => partial_derive p k f x v) y) (partial_derive p (S k) f x y) *)
easy.
Qed.

Lemma ex_diff_n_continuity_inf_2 : forall n p k, (p+k < n)%nat -> forall f x y,
  ex_diff_n f n x y ->
  continuity_2d_pt (fun u v => Derive (fun z : R => partial_derive p k f u z) v) x y.
Proof.
(* Goal: forall (n p k : nat) (_ : lt (Init.Nat.add p k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
intros n p k Hn f x y Hf.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
assert (ex_diff_n (partial_derive p k f) (n -(p+k)) x y).
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
apply ex_diff_n_deriv.
(* Goal: le (Init.Nat.add p k) n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
now apply lt_le_weak.
(* Goal: ex_diff_n f n x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
exact Hf.
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
revert H; case_eq (n-(p+k))%nat.
(* Goal: forall (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p k)) O) (_ : ex_diff_n (partial_derive p k f) O x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p k)) (S n0)) (_ : ex_diff_n (partial_derive p k f) (S n0) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
intros H; contradict Hn.
(* Goal: not (lt (Init.Nat.add p k) n) *)
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p k)) (S n0)) (_ : ex_diff_n (partial_derive p k f) (S n0) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
omega.
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p k)) (S n0)) (_ : ex_diff_n (partial_derive p k f) (S n0) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
intros n0 Hn0; simpl; intros (T1&T2&T3&T4&T5).
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
revert T5; case n0.
(* Goal: forall _ : ex_diff_n (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) O x y, continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
(* Goal: forall (n : nat) (_ : ex_diff_n (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) (S n) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
intros Y; apply Y.
(* Goal: forall (n : nat) (_ : ex_diff_n (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) (S n) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
intros n1 Y; apply Y.
Qed.

(** * 2D Taylor-Lagrange inequality *)

Definition DL_regular_n f m x y :=
  exists D, locally_2d (fun u v =>
    Rabs (f u v - DL_pol m f x y (u-x) (v-y)) <= D * (Rmax (Rabs (u-x)) (Rabs (v-y))) ^ (S m)) x y.

Theorem Taylor_Lagrange_2d : forall f n x y,
  locally_2d (fun u v => ex_diff_n f (S n) u v) x y -> DL_regular_n f n x y.
Proof.
intros f n x y Df.
(* *)
assert (exists D, locally_2d (fun u v => forall p, (p <= S n)%nat ->
  Rabs (partial_derive p (S n - p) f u v) <= D) x y).
(* . *)
assert (forall p, (p <= S n)%nat -> exists D, locally_2d (fun u v => Rabs (partial_derive p (S n - p) f u v) <= D) x y).
intros p Hp.
(* .. *)
assert (continuity_2d_pt (partial_derive p (S n - p) f) x y).
apply locally_2d_singleton in Df.
refine (proj1 (_: ex_diff_n (partial_derive p (S n - p) f) 0 x y)).
replace O with (S n - (p + (S n - p)))%nat by rewrite le_plus_minus_r // minus_diag //.
cut (p + (S n - p) <= S n)%nat.
2: now rewrite le_plus_minus_r.
generalize (S n - p)%nat.
clear Hp.
revert f Df p.
generalize (S n).
clear n.
(* Goal: ex_diff_n f m x y *)
induction n.
intros f (H,_) [|p] [|q] H' ; try inversion H'.
done.
intros f H [|p] q H'.
destruct q as [|q].
exact H.
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
now apply ex_diff_n_deriv.
(* Goal: ex_diff_n (partial_derive p k f) (Init.Nat.sub n (Init.Nat.add p k)) x y *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
now apply ex_diff_n_deriv.
(* .. *)
exists (Rabs (partial_derive p (S n - p) f x y) + 1).
specialize (H (mkposreal 1 Rlt_0_1)).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: locally_2d_impl H.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: locally_2d_forall => u v H.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
replace (partial_derive p (S n - p) f u v) with (partial_derive p (S n - p) f x y + (partial_derive p (S n - p) f u v - partial_derive p (S n - p) f x y)) by ring.
apply Rle_trans with (1 := Rabs_triang _ _).
apply Rplus_le_compat_l.
now apply Rlt_le.
(* . *)
clear -H.
generalize (le_refl (S n)).
generalize (S n) at 1 3.
intros p Hp.
induction p.
move: (H _ Hp) => {H} [D H].
exists D.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: locally_2d_impl H.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
apply locally_2d_forall => u v H [|p] Hp' //.
inversion Hp'.
move: (IHp (le_S _ _ (le_S_n _ _ Hp))) => {IHp} [D1 H1].
move: (H _ Hp) => {H} [D2 H2].
exists (Rmax D1 D2).
move: (locally_2d_and _ _ x y H1 H2) => {H1 H2} H.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: locally_2d_impl H.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
apply locally_2d_forall => u v H p' Hp'.
destruct (le_lt_or_eq _ _ Hp').
apply Rle_trans with (2 := Rmax_l _ _).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
apply H.
(* Goal: le m n *)
(* Goal: ex_diff_n f n x y *)
(* Goal: forall _ : @eq nat m (S n), ex_diff_n f m x y *)
now apply gt_S_le.
apply Rle_trans with (2 := Rmax_r _ _).
(* Goal: @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (Init.Nat.add p O) (Init.Nat.add O k) (partial_derive (S O) O f) u v) *)
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now rewrite H0.
(* *)
destruct H as (D,H).
exists  (/ INR (fact (S n)) * D * sum_f_R0 (fun i : nat => Rabs (C (S n) i)) (S n)).
move: (locally_2d_and _ _ _ _ Df H) => {Df H} HH.
apply locally_2d_1d_strong in HH.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: locally_2d_impl HH.
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
apply locally_2d_forall => u v HH.
set (g t := f (x + t * (u - x)) (y + t * (v - y))).
replace (f u v) with (g 1) by (rewrite /g 2!Rmult_1_l ; apply f_equal2 ; ring).
assert (forall k t, (k <= S n)%nat -> 0 <= t <= 1 ->
  is_derive_n g k t (sum_f_R0 (fun m => C k m * partial_derive m (k - m)%nat f (x+t*(u-x)) (y+t*(v-y)) *
         (u-x) ^ m * (v-y) ^ (k - m)%nat) k)).
intros k t Hk Ht.
specialize (HH t Ht).
revert HH.
pattern t ; apply locally_singleton.
induction k.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite /C /partial_derive /g /=.
apply filter_forall.
intros ; field.
specialize (IHk (le_S _ _ (le_S_n _ _ Hk))).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite /is_derive_n.
apply locally_locally in IHk.
move: IHk ; apply filter_imp => {t Ht} z IHk HH.
apply is_derive_ext_loc with (fun t => sum_n (fun m => C k m *
  partial_derive m (k - m) f (x + t * (u - x)) (y + t * (v - y)) * (u - x) ^ m * (v - y) ^ (k - m)) k).
  apply locally_locally in HH.
  generalize (filter_and _ _ HH IHk).
(* Goal: @locally (AbsRing_UniformSpace R_AbsRing) x (fun x : UniformSpace.sort (NormedModule.UniformSpace R_AbsRing (AbsRing_NormedModule R_AbsRing)) => Rle (@norm R_AbsRing R_NormedModule (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing R_NormedModule) (f x) (f z)) (@scal (AbsRing.Ring R_AbsRing) (NormedModule.ModuleSpace R_AbsRing R_NormedModule) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z) l))) (Rmult (pos eps) (@norm R_AbsRing (AbsRing_NormedModule R_AbsRing) (@minus (NormedModule.AbelianGroup R_AbsRing (AbsRing_NormedModule R_AbsRing)) x z)))) *)
  apply filter_imp => {z HH IHk} z [Hz HH].
  specialize (HH Hz).
(* Goal: @eq R (partial_derive O k (partial_derive (S O) O f) u' v') (partial_derive (S O) k f u' v') *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
  apply sym_eq.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
  rewrite sum_n_Reals.
  now apply is_derive_n_unique.
replace (sum_f_R0 (fun m : nat => C (S k) m *
    partial_derive m (S k - m) f (x + z * (u - x)) (y + z * (v - y)) * (u - x) ^ m * (v - y) ^ (S k - m)) (S k)) with
  (sum_n (fun m : nat => C k m * (u - x) ^ m  * (v - y) ^ (k - m) *
    ((u - x) * partial_derive (S m) (k - m) f (x + z * (u - x)) (y + z * (v - y)) +
     (v - y) * partial_derive m (S (k - m)) f (x + z * (u - x)) (y + z * (v - y)))) k).
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => g x z) y *)
(* Goal: and (ex_diff_n (fun u v : R => Derive (fun z : R => g z v) u) n x y) (ex_diff_n (fun u v : R => Derive (fun z : R => g u z) v) n x y) *)
apply: is_derive_sum_n => p Hp.
apply is_derive_ext with (fun u0 => C k p * (u - x) ^ p * (v - y) ^ (k - p) * partial_derive p (k - p) f (x + u0 * (u - x)) (y + u0 * (v - y))).
intros w.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
simpl ; ring.
apply is_derive_Reals, derivable_pt_lim_scal.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite (Rmult_comm (u - x)) (Rmult_comm (v - y)).
apply derivable_pt_lim_comp_2d.
apply locally_singleton in HH.
replace (partial_derive (S p) (k - p) f (x + z * (u - x)) (y + z * (v - y)))
  with (Derive (fun u : R => partial_derive p (k - p) f u (y + z * (v - y))) (x + z * (u - x))).
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
2: reflexivity.
replace (partial_derive p (S (k - p)) f (x + z * (u - x)) (y + z * (v - y))) with
  (Derive (fun v : R => partial_derive p (k - p) f  (x + z * (u - x)) v) (y + z * (v - y))).
apply filterdiff_differentiable_pt_lim.
eapply filterdiff_ext_lin.
apply is_derive_filterdiff.
apply locally_2d_locally in HH.
apply filter_imp with (2:=HH).
clear - Hk Hp ; intros [u' v'] (H1,H2).
evar_last.
apply Derive_correct.
apply ex_diff_n_ex_deriv_inf_1 with (S n).
(* Goal: @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (Init.Nat.add p O) (Init.Nat.add O k) (partial_derive (S O) O f) u v) *)
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now rewrite - le_plus_minus.
exact H1.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl ; reflexivity.
apply locally_2d_singleton in HH.
apply Derive_correct.
apply ex_diff_n_ex_deriv_inf_2 with (S n).
(* Goal: @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (Init.Nat.add p O) (Init.Nat.add O k) (partial_derive (S O) O f) u v) *)
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now rewrite - le_plus_minus.
apply HH.
apply locally_2d_singleton in HH.
apply continuity_2d_pt_filterlim.
apply ex_diff_n_continuity_inf_1 with (S n).
(* Goal: @eq R (partial_derive p k (partial_derive (S O) O f) u v) (partial_derive (Init.Nat.add p O) (Init.Nat.add O k) (partial_derive (S O) O f) u v) *)
(* Goal: or (@eq nat O O) (@eq nat O O) *)
(* Goal: @eq R (partial_derive p O (partial_derive O k (partial_derive (S O) O f)) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
now rewrite - le_plus_minus.
apply HH.
case => /= u' v'.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
reflexivity.
apply Derive_partial_derive_aux2.
apply locally_2d_impl with (2:=HH).
(* Goal: locally_2d (fun u v : R => forall _ : ex_diff_n f (Init.Nat.add (S p) (S k)) u v, ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k)) u v) x y *)
apply locally_2d_forall.
intros u' v' (Y,_).
apply ex_diff_n_m with (2:=Y).
(* Goal: not (lt (Init.Nat.add p k) n) *)
(* Goal: forall (n0 : nat) (_ : @eq nat (Init.Nat.sub n (Init.Nat.add p k)) (S n0)) (_ : ex_diff_n (partial_derive p k f) (S n0) x y), continuity_2d_pt (fun u v : R => Derive (fun z : R => partial_derive p k f u z) v) x y *)
omega.
apply is_derive_Reals ; eapply filterdiff_ext_lin.
apply @filterdiff_plus_fct ; try apply locally_filter.
apply filterdiff_const.
apply @filterdiff_scal_l ; try apply locally_filter.
simpl => y0 ; apply plus_zero_l.
apply is_derive_Reals ; eapply filterdiff_ext_lin.
apply @filterdiff_plus_fct ; try apply locally_filter.
apply filterdiff_const.
apply @filterdiff_scal_l ; try apply locally_filter.
simpl => y0 ; apply plus_zero_l.
rewrite sum_n_Reals -(sum_eq (fun m =>
  C k m * (u - x) ^ (S m) * (v - y) ^ (k - m) * partial_derive (S m) (k - m) f (x + z * (u - x)) (y + z * (v - y)) +
  C k m * (u - x) ^ m * (v - y) ^ (S (k - m)) * partial_derive m (S (k - m)) f (x + z * (u - x)) (y + z * (v - y)))).
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
2: intros ; simpl ; ring.
case k; clear Hk IHk k.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
unfold C; simpl.
simpl ; field.
intros k.
(* Goal: @eq R (partial_derive O k (partial_derive (S O) O f) u' v') (partial_derive (S O) k f u' v') *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply sym_eq.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite (decomp_sum _ (S (S k))).
2: apply lt_0_Sn.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite - pred_Sn.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite tech5.
rewrite (sum_eq _ (fun i : nat =>
     (C (S k) i*
    partial_derive (S i) (S (S k) - S i) f (x + z * (u - x))
      (y + z * (v - y)) * (u - x) ^ S i * (v - y) ^ (S (S k) - S i))
     + (C (S k) (S i) *
       partial_derive (S i) (S (S k) - S i) f (x + z * (u - x))
      (y + z * (v - y)) * (u - x) ^ S i * (v - y) ^ (S (S k) - S i)))).
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite sum_plus.
(* Goal: @eq R (partial_derive O k (partial_derive (S O) O f) u' v') (partial_derive (S O) k f u' v') *)
(* Goal: @eq R (partial_derive p O (partial_derive (S O) k f) u v) (partial_derive (S p) k f u v) *)
(* Goal: locally_2d (ex_diff_n (partial_derive (S O) O f) (Init.Nat.add p (S k))) x y *)
apply sym_eq.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite sum_plus.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite tech5.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite (tech2 _ 0 (S k)).
2: apply lt_0_Sn.
replace
 (sum_f_R0
   (fun l : nat =>
    C (S k) l * (u - x) ^ l * (v - y) ^ S (S k - l) *
    partial_derive l (S (S k - l)) f (x + z * (u - x)) (y + z * (v - y))) 0)
with  (C (S (S k)) 0 *
partial_derive 0 (S (S k) - 0) f (x + z * (u - x)) (y + z * (v - y)) *
(u - x) ^ 0 * (v - y) ^ (S (S k) - 0)).
replace (C (S k) (S k) * (u - x) ^ S (S k) * (v - y) ^ (S k - S k) *
   partial_derive (S (S k)) (S k - S k) f (x + z * (u - x)) (y + z * (v - y))) with
 (C (S (S k)) (S (S k)) *
 partial_derive (S (S k)) (S (S k) - S (S k)) f (x + z * (u - x))
   (y + z * (v - y)) * (u - x) ^ S (S k) * (v - y) ^ (S (S k) - S (S k))).
replace (sum_f_R0
  (fun l : nat =>
   C (S k) l *
   partial_derive (S l) (S (S k) - S l) f (x + z * (u - x)) (y + z * (v - y)) *
   (u - x) ^ S l * (v - y) ^ (S (S k) - S l)) k)
  with (sum_f_R0
  (fun l : nat =>
   C (S k) l * (u - x) ^ S l * (v - y) ^ (S k - l) *
   partial_derive (S l) (S k - l) f (x + z * (u - x)) (y + z * (v - y))) k).
replace (sum_f_R0
  (fun l : nat =>
   C (S k) (S l) *
   partial_derive (S l) (S (S k) - S l) f (x + z * (u - x)) (y + z * (v - y)) *
   (u - x) ^ S l * (v - y) ^ (S (S k) - S l)) k)
 with (sum_f_R0
  (fun i : nat =>
   C (S k) (1 + i) * (u - x) ^ (1 + i) * (v - y) ^ S (S k - (1 + i)) *
   partial_derive (1 + i) (S (S k - (1 + i))) f (x + z * (u - x))
     (y + z * (v - y))) (S k - 1)).
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
simpl ; ring.
replace (S k - 1)%nat with k. 2: now apply plus_minus.
apply sum_eq.
intros i Hi.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
replace (1+i)%nat with (S i) by reflexivity.
replace (S (S k - S i))%nat with (S (S k) - S i)%nat.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
ring.
now (rewrite minus_Sn_m; try apply le_n_S).
apply sum_eq.
intros i Hi.
(* Goal: @eq R (Derive_n (Derive_n (fun z : R => Derive (fun x0 : R => f x0 z) x) p) (S O) y) (Derive (Derive_n (fun z : R => Derive (fun x : R => f x z) x) p) y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
replace (S k - i)%nat with (S (S k) - S i)%nat by reflexivity.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
ring.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite 2!C_n_n 2!minus_diag.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
ring.
(* Goal: @eq R (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => Derive_n (fun t1 : R => Derive_n (fun z1 : R => f t1 z1) O z0) (S O) t0) (S O) z) O t) p y) O x) (Derive_n (fun t : R => Derive_n (fun z : R => Derive_n (fun t0 : R => Derive_n (fun z0 : R => f t0 z0) O z) (S O) t) (S p) y) O x) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
simpl.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite 2!C_n_0.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
ring.
(* Goal: forall (f1 : forall (_ : R) (_ : R), R) (f2 f3 : forall _ : R, R) (x l1x l1y l2 l3 : R) (_ : differentiable_pt_lim f1 (f2 x) (f3 x) l1x l1y) (_ : derivable_pt_lim f2 x l2) (_ : derivable_pt_lim f3 x l3), derivable_pt_lim (fun t : R => f1 (f2 t) (f3 t)) x (Rplus (Rmult l1x l2) (Rmult l1y l3)) *)
intros.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite - (pascal (S k) i).
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
ring.
now apply le_lt_n_Sm.
(* *)
destruct (Taylor_Lagrange g n 0 1 Rlt_0_1) as (t&Ht&Hg).
intros t Ht.
intros [|k] Hk.
(* Goal: forall _ : @eq R (partial_derive O (S O) (partial_derive p k f) x y) (partial_derive p (S k) f x y), @eq R (Derive (fun v : R => partial_derive p k f x v) y) (partial_derive p (S k) f x y) *)
easy.
eexists.
now apply (H (S k)).
(* *)
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Hg /DL_pol.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
replace (1 - 0) with 1 by ring.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite pow1 {1}/Rminus Rplus_assoc [_*_+_]Rplus_comm -Rplus_assoc -/(Rminus _ _).
assert (forall k t, (k <= S n)%nat -> 0 <= t <= 1 -> Derive_n g k t =
      (sum_f_R0 (fun m =>  C k m * partial_derive m (k - m)%nat f (x+t*(u-x)) (y+t*(v-y)) *
         (u-x) ^ m * (v-y) ^ (k - m)%nat) k)).
intros k t0 Hk Ht0.
apply is_derive_n_unique.
(* Goal: @ex_derive R_AbsRing R_NormedModule (fun z : R => f x z) y *)
(* Goal: forall (n0 : nat) (_ : lt (Init.Nat.add O (S n0)) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive O (S n0) f x z) y *)
(* Goal: forall (n0 k : nat) (_ : lt (Init.Nat.add (S n0) k) n) (f : forall (_ : R) (_ : R), R) (x y : R) (_ : ex_diff_n f n x y), @ex_derive R_AbsRing R_NormedModule (fun z : AbsRing.sort R_AbsRing => partial_derive (S n0) k f x z) y *)
now apply H.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite -minus_sum sum_eq_R0.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite H0.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Rplus_0_l.
unfold differential.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Rabs_mult.
eapply Rle_trans.
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply Rabs_pos.
eapply Rle_trans.
apply Rsum_abs.
apply sum_Rle.
intros n0 Hn0.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Rmult_assoc 3!Rabs_mult.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite Rmult_assoc.
(* Goal: Rle (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rmult (pos eps3) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) *)
apply Rmult_le_compat_l.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply Rabs_pos.
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH))))) (Rmult (IZR (Zpos xH)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply Rabs_pos.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply Rmult_le_pos; apply Rabs_pos.
specialize (HH t (conj (Rlt_le _ _ (proj1 Ht)) (Rlt_le _ _ (proj2 Ht)))).
apply locally_singleton in HH.
apply locally_2d_singleton in HH.
now apply HH.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite - 2!RPow_abs.
instantiate (1:=(Rmax (Rabs (u - x)) (Rabs (v - y)) ^ S n)).
apply Rle_trans with ((Rmax (Rabs (u - x)) (Rabs (v - y)) ^ n0) * (Rmax (Rabs (u - x)) (Rabs (v - y)) ^ (S n - n0))).
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH))))) (Rmult (IZR (Zpos xH)) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH))))) *)
(* Goal: Rle (Rmult (Rabs l2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply Rmult_le_compat.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply pow_le ; apply Rabs_pos.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply pow_le ; apply Rabs_pos.
apply pow_incr.
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply Rabs_pos.
apply Rmax_l.
apply pow_incr.
(* Goal: and (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f z t) v') u') (@ex_derive R_AbsRing R_NormedModule (fun z : R => Derive (fun t : R => f t z) u') v') *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f z t) v) u) u v *)
(* Goal: continuity_2d_pt (fun u v : R => Derive (fun z : R => Derive (fun t : R => f t z) u) v) u v *)
(* Goal: @eq R (partial_derive O p (partial_derive O (S O) (partial_derive (S O) O f)) x y) (partial_derive O (S p) (partial_derive (S O) O f) x y) *)
(* Goal: locally_2d (ex_diff_n (partial_derive O (S O) f) (S p)) x y *)
split.
(* Goal: Rle (IZR Z0) (Rabs l1_2) *)
(* Goal: Rle (IZR Z0) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) *)
(* Goal: Rle (Rabs l1_2) (IZR (Zpos xH)) *)
(* Goal: Rle (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (IZR (Zpos xH)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
(* Goal: Rle (Rmult (Rabs l1_2) (Rdiv (pos eps) (Rmult (IZR (Zpos (xO (xO xH)))) (Rabs l1_2)))) (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) *)
apply Rabs_pos.
apply Rmax_r.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite -pow_add.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite -le_plus_minus.
apply Rle_refl.
exact Hn0.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite - scal_sum.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite /Rdiv Rmult_1_l Rabs_right .
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
right; ring.
apply Rle_ge; apply Rlt_le; apply Rinv_0_lt_compat.
apply INR_fact_lt_0.
apply le_refl.
split; apply Rlt_le, Ht.
intros n0 hn0.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite H0.
(* Goal: @eq nat (Init.Nat.sub (Init.Nat.add (S p) (S k)) (Init.Nat.add (S O) O)) (Init.Nat.add p (S k)) *)
rewrite 2!Rmult_0_l 2!Rplus_0_r pow1.
(* Goal: @eq R (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y)))) (Rplus (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y))))) (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y)))))) *)
(* Goal: Rle (Rabs (Rminus (Rplus (Rmult l1_1 (Rminus (f2 x' y') (f2 x y))) (Rmult l1_2 (Rminus (f3 x' y') (f3 x y)))) (Rplus (Rmult (Rplus (Rmult l1_1 l2_1) (Rmult l1_2 l3_1)) (Rminus x' x)) (Rmult (Rplus (Rmult l1_1 l2_2) (Rmult l1_2 l3_2)) (Rminus y' y))))) (Rplus (Rabs (Rmult l1_1 (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rabs (Rmult l1_2 (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) *)
(* Goal: Rle (Rplus (Rmult (Rabs l1_1) (Rabs (Rminus (Rminus (f2 x' y') (f2 x y)) (Rplus (Rmult l2_1 (Rminus x' x)) (Rmult l2_2 (Rminus y' y)))))) (Rmult (Rabs l1_2) (Rabs (Rminus (Rminus (f3 x' y') (f3 x y)) (Rplus (Rmult l3_1 (Rminus x' x)) (Rmult l3_2 (Rminus y' y))))))) (Rplus (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y)))) (Rmult (Rdiv (Rdiv (pos eps) (IZR (Zpos (xO xH)))) (IZR (Zpos (xO xH)))) (Rmax (Rabs (Rminus x' x)) (Rabs (Rminus y' y))))) *)
unfold differential, Rdiv; ring.
now apply le_S.
split; [apply Rle_refl | apply Rle_0_1].
Qed.
