(** This file is part of the Coquelicot formalization of real analysis in Coq: http://coquelicot.saclay.inria.fr/  Copyright (C) 2011-2015 Sylvie Boldo #<br /># Copyright (C) 2011-2015 Catherine Lelay #<br /># Copyright (C) 2011-2015 Guillaume Melquiond  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the COPYING file for more details. *)
(** This file 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.
Definition differentiable_pt (f : R -> R -> R) (x y : R) :=
exists lx, exists ly, differentiable_pt_lim f x y lx ly.
(** * Operations *)
(** * 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.
(** * 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).