Top

Module mathcomp.analysis.exp

From mathcomp Require Import all_ssreflect ssralg ssrint ssrnum matrix.
From mathcomp Require Import interval rat.
From mathcomp Require Import boolp classical_sets functions.
From mathcomp Require Import mathcomp_extra.
Require Import reals ereal.
Require Import signed topology normedtype landau sequences derive realfun.
Require Import itv convex.

Theory of exponential/logarithm functions

This file defines exponential and logarithm functions and develops their theory.

Differentiability of series (Section PseriesDiff)

This formalization is inspired by HOL-Light (transc.ml). This part is temporary: it should be subsumed by a proper theory of power series.

        pseries f x == [series f n * x ^ n]_n
  pseries_diffs f i == (i + 1) * f (i + 1)

            expeR x == extended real number-valued exponential function
               ln x == the natural logarithm
             s `^ r == power function, in ring_scope (assumes s >= 0)
             e `^ r == power function, in ereal_scope (assumes e >= 0)
         riemannR a == sequence n |-> 1 / (n.+1) `^ a where a has a type
                       of type realType
      e `^?(r +? s) == validity condition for the distributivity of
                       the power of the addition, in ereal_scope

Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GRing.Theory Num.Def Num.Theory.
Import numFieldNormedType.Exports.

Local Open Scope classical_set_scope.
Local Open Scope ring_scope.

Reserved Notation "x '`^?' ( r +? s )"
 (format "x '`^?' ( r +? s )", r at next level, at level 11) .

Lemma normr_nneg (R : numDomainType) (x : R) : `|x| \is Num.nneg.
Proof.
#[global] Hint Extern 0 (is_true (@Num.norm _ _ _ \is Num.nneg)) =>
  solve [apply: normr_nneg] : core.

Section PseriesDiff.

Variable R : realType.

Definition pseries f (x : R) := [series f i * x ^+ i]_i.

Fact is_cvg_pseries_inside_norm f (x z : R) :
    cvgn (pseries f x) -> `|z| < `|x| ->
  cvgn (pseries (fun i => `|f i|) z).
Proof.

Fact is_cvg_pseries_inside f (x z : R) :
  cvgn (pseries f x) -> `|z| < `|x| -> cvgn (pseries f z).
Proof.

Definition pseries_diffs (f : nat -> R) i := i.+1%:R * f i.+1.

Lemma pseries_diffsN (f : nat -> R) : pseries_diffs (- f) = -(pseries_diffs f).
Proof.

Lemma pseries_diffs_inv_fact :
  pseries_diffs (fun n => (n`!%:R)^-1) = (fun n => (n`!%:R)^-1 : R).
Proof.

Lemma pseries_diffs_sumE n f x :
  \sum_(0 <= i < n) pseries_diffs f i * x ^+ i =
  (\sum_(0 <= i < n) i%:R * f i * x ^+ i.-1) + n%:R * f n * x ^+ n.-1.
Proof.

Lemma pseries_diffs_equiv f x :
  let s i := i%:R * f i * x ^+ i.-1 in
  cvgn (pseries (pseries_diffs f) x) ->
  series s @ \oo --> limn (pseries (pseries_diffs f) x).
Proof.

Lemma is_cvg_pseries_diffs_equiv f x :
    cvgn (pseries (pseries_diffs f) x) ->
  cvgn ([series i%:R * f i * x ^+ i.-1]_i).
Proof.

Let pseries_diffs_P1 m (z h : R) :
  \sum_(0 <= i < m) ((h + z) ^+ (m - i) * z ^+ i - z ^+ m) =
  \sum_(0 <= i < m) z ^+ i * ((h + z) ^+ (m - i) - z ^+ (m - i)).
Proof.

Let pseries_diffs_P2 n (z h : R) :
  h != 0 ->
  ((h + z) ^+ n - (z ^+ n)) / h - n%:R * z ^+ n.-1 =
  h * \sum_(0 <= i < n.-1) z ^+ i *
      \sum_(0 <= j < n.-1 - i) (h + z) ^+ j * z ^+ (n.-2 - i - j).
Proof.

Let pseries_diffs_P3 (z h : R) n K :
  h != 0 -> `|z| <= K -> `|h + z| <= K ->
    `|((h +z) ^+ n - z ^+ n) / h - n%:R * z ^+ n.-1|
      <= n%:R * n.-1%:R * K ^+ n.-2 * `|h|.
Proof.

Lemma pseries_snd_diffs (c : R^nat) K x :
  cvgn (pseries c K) ->
  cvgn (pseries (pseries_diffs c) K) ->
  cvgn (pseries (pseries_diffs (pseries_diffs c)) K) ->
  `|x| < `|K| ->
  is_derive x (1 : R)
    (fun x => limn (pseries c x))
    (limn (pseries (pseries_diffs c) x)).
Proof.

End PseriesDiff.

Section expR.
Variable R : realType.
Implicit Types x : R.

Lemma expR0 : expR 0 = 1 :> R.
Proof.

Lemma expR_ge1Dx x : 0 <= x -> 1 + x <= expR x.
Proof.

Lemma exp_coeffE x : exp_coeff x = (fun n => (fun n => (n`!%:R)^-1) n * x ^+ n).
Proof.

Import GRing.Theory.
Local Open Scope ring_scope.

Lemma expRE :
  expR = fun x => limn (pseries (fun n => (fun n => (n`!%:R)^-1) n) x).
Proof.

Global Instance is_derive_expR x : is_derive x 1 expR (expR x).
Proof.

Lemma derivable_expR x : derivable expR x 1.
Proof.

Lemma derive_expR : 'D_1 expR = expR :> (R -> R).
Proof.

Lemma continuous_expR : continuous (@expR R).
Proof.

Lemma expRxDyMexpx x y : expR (x + y) * expR (- x) = expR y.
Proof.

Lemma expRxMexpNx_1 x : expR x * expR (- x) = 1.
Proof.

Lemma pexpR_gt1 x : 0 < x -> 1 < expR x.
Proof.

Lemma expR_gt0 x : 0 < expR x.
Proof.

Lemma expR_ge0 x : 0 <= expR x. Proof. by rewrite ltW// expR_gt0.
Lemma expR_eq0 x : (expR x == 0) = false.
Proof.

Lemma expRN x : expR (- x) = (expR x)^-1.
Proof.

Lemma expRD x y : expR (x + y) = expR x * expR y.
Proof.

Lemma expRM_natl n x : expR (n%:R * x) = expR x ^+ n.
Proof.

Lemma expRM_natr n x : expR (x * n%:R) = expR x ^+ n.
Proof.

Lemma expR_gt1 x : (1 < expR x) = (0 < x).
Proof.

Lemma expR_lt1 x : (expR x < 1) = (x < 0).
Proof.

Lemma expRB x y : expR (x - y) = expR x / expR y.
Proof.

Lemma ltr_expR : {mono (@expR R) : x y / x < y}.
Proof.

Lemma ler_expR : {mono (@expR R) : x y / x <= y}.
Proof.

Lemma expR_inj : injective (@expR R).
Proof.

Lemma expR_total_gt1 x :
  1 <= x -> exists y, [/\ 0 <= y, 1 + y <= x & expR y = x].
Proof.

Lemma expR_total x : 0 < x -> exists y, expR y = x.
Proof.

Local Open Scope convex_scope.
Lemma convex_expR (t : {i01 R}) (a b : R^o) :
  expR (a <| t |> b) <= (expR a : R^o) <| t |> (expR b : R^o).
Proof.
Local Close Scope convex_scope.

End expR.

#[deprecated(since="mathcomp-analysis 1.1.0", note="renamed `expRM_natl`")]
Notation expRMm := expRM_natl (only parsing).

Section expeR.
Context {R : realType}.
Implicit Types (x y : \bar R) (r s : R).

Local Open Scope ereal_scope.

Definition expeR x :=
  match x with | r%:E => (expR r)%:E | +oo => +oo | -oo => 0 end.

Lemma expeR0 : expeR 0 = 1. Proof. by rewrite /= expR0.
Lemma expeR_ge0 x : 0 <= expeR x.
Proof.

Lemma expeR_gt0 x : -oo < x -> 0 < expeR x.
Proof.

Lemma expeR_eq0 x : (expeR x == 0) = (x == -oo).
Proof.

Lemma expeRD x y : expeR (x + y) = expeR x * expeR y.
Proof.

Lemma expeR_ge1Dx x : 0 <= x -> 1 + x <= expeR x.
Proof.

Lemma ltr_expeR : {mono expeR : x y / x < y}.
Proof.

Lemma ler_expeR : {mono expeR : x y / x <= y}.
Proof.

Lemma expeR_inj : injective expeR.
Proof.

Lemma expeR_total x : 0 <= x -> exists y, expeR y = x.
Proof.

End expeR.

Section Ln.
Variable R : realType.
Implicit Types x : R.

Notation exp := (@expR R).

Definition ln x : R := [get y | exp y == x ].

Fact ln0 x : x <= 0 -> ln x = 0.
Proof.

Lemma expRK : cancel exp ln.
Proof.

Lemma lnK : {in Num.pos, cancel ln exp}.
Proof.

Lemma lnK_eq x : (exp (ln x) == x) = (0 < x).
Proof.

Lemma ln1 : ln 1 = 0.
Proof.

Lemma lnM : {in Num.pos &, {morph ln : x y / x * y >-> x + y}}.
Proof.

Lemma ln_inj : {in Num.pos &, injective ln}.
Proof.

Lemma lnV : {in Num.pos, {morph ln : x / x ^-1 >-> - x}}.
Proof.

Lemma ln_div : {in Num.pos &, {morph ln : x y / x / y >-> x - y}}.
Proof.

Lemma ltr_ln : {in Num.pos &, {mono ln : x y / x < y}}.
Proof.

Lemma ler_ln : {in Num.pos &, {mono ln : x y / x <= y}}.
Proof.

Lemma lnXn n x : 0 < x -> ln (x ^+ n) = ln x *+ n.
Proof.

Lemma le_ln1Dx x : 0 <= x -> ln (1 + x) <= x.
Proof.

Lemma ln_sublinear x : 0 < x -> ln x < x.
Proof.

Lemma ln_ge0 x : 1 <= x -> 0 <= ln x.
Proof.

Lemma ln_lt0 x : 0 < x < 1 -> ln x < 0.
Proof.

Lemma ln_gt0 x : 1 < x -> 0 < ln x.
Proof.

Lemma ln_le0 (x : R) : x <= 1 -> ln x <= 0.
Proof.

Lemma continuous_ln x : 0 < x -> {for x, continuous ln}.
Proof.

Global Instance is_derive1_ln (x : R) : 0 < x -> is_derive x 1 ln x^-1.
Proof.

Local Open Scope convex_scope.
Lemma concave_ln (t : {i01 R}) (a b : R^o) : 0 < a -> 0 < b ->
  (ln a : R^o) <| t |> (ln b : R^o) <= ln (a <| t |> b).
Proof.
Local Close Scope convex_scope.

End Ln.

Section PowR.
Variable R : realType.
Implicit Types a x y z r : R.

Definition powR a x := if a == 0 then (x == 0)%:R else expR (x * ln a).

Local Notation "a `^ x" := (powR a x).

Lemma expRM x y : expR (x * y) = (expR x) `^ y.
Proof.

Lemma powR_ge0 a x : 0 <= a `^ x.
Proof.

Lemma powR_gt0 a x : 0 < a -> 0 < a `^ x.
Proof.

Lemma gt0_powR a x : 0 < x -> 0 <= a -> 0 < a `^ x -> 0 < a.
Proof.

Lemma powR0 x : x != 0 -> 0 `^ x = 0.
Proof.

Lemma powRr1 a : 0 <= a -> a `^ 1 = a.
Proof.

Lemma powRr0 a : a `^ 0 = 1.
Proof.

Lemma powR1 : powR 1 = fun=> 1.
Proof.

Lemma powR_eq0 x p : (x `^ p == 0) = (x == 0) && (p != 0).
Proof.

Lemma powR_eq0_eq0 x p : x `^ p = 0 -> x = 0.
Proof.

Lemma ger_powR a : 0 < a <= 1 -> {homo powR a : x y /~ y <= x}.
Proof.

Lemma ler_powR a : 1 <= a -> {homo powR a : x y / x <= y}.
Proof.

Lemma powR_injective r : 0 < r -> {in Num.nneg &, injective (powR ^~ r)}.
Proof.

Lemma ler1_powR a r : 1 <= a -> r <= 1 -> a >= a `^ r.
Proof.

Lemma le1r_powR a r : 1 <= a -> 1 <= r -> a <= a `^ r.
Proof.

Lemma ger1_powR a r : 0 < a <= 1 -> r <= 1 -> a <= a `^ r.
Proof.

Lemma ge1r_powR a r : 0 < a <= 1 -> 1 <= r -> a >= a `^ r.
Proof.

Lemma ge0_ler_powR r : 0 <= r ->
  {in Num.nneg &, {homo powR ^~ r : x y / x <= y >-> x <= y}}.
Proof.

Lemma gt0_ltr_powR r : 0 < r ->
  {in Num.nneg &, {homo powR ^~ r : x y / x < y >-> x < y}}.
Proof.

Lemma powRM x y r : 0 <= x -> 0 <= y -> (x * y) `^ r = x `^ r * y `^ r.
Proof.

Lemma ge1r_powRZ x y r : 0 < x <= 1 -> 0 <= y -> 1 <= r ->
  (x * y) `^ r <= x * (y `^ r).
Proof.

Lemma le1r_powRZ x y r : x >= 1 -> 0 <= y -> 1 <= r ->
  (x * y) `^ r >= x * (y `^ r).
Proof.

Lemma powRrM x y z : x `^ (y * z) = (x `^ y) `^ z.
Proof.

Lemma powRAC x y z : (x `^ y) `^ z = (x `^ z) `^ y.
Proof.

Lemma powRD x r s : (r + s == 0) ==> (x != 0) -> x `^ (r + s) = x `^ r * x `^ s.
Proof.

Lemma mulr_powRB1 x p : 0 <= x -> 0 < p -> x * x `^ (p - 1) = x `^ p.
Proof.

Lemma powRN x r : x `^ (- r) = (x `^ r)^-1.
Proof.

Lemma powRB x r s : (r == s) ==> (x != 0) -> x `^ (r - s) = x `^ r / x `^ s.
Proof.

Lemma powR_mulrn a n : 0 <= a -> a `^ n%:R = a ^+ n.
Proof.

Lemma powR_inv1 a : 0 <= a -> a `^ (-1) = a ^-1.
Proof.

Lemma powR_invn a n : 0 <= a -> a `^ (- n%:R) = a ^- n.
Proof.

Lemma powR_intmul a (z : int) : 0 <= a -> a `^ z%:~R = a ^ z.
Proof.

Lemma ln_powR a x : ln (a `^ x) = x * ln a.
Proof.

Lemma powR12_sqrt a : 0 <= a -> a `^ (2^-1) = Num.sqrt a.
Proof.

Lemma norm_powR a x : 0 <= a -> `|a `^ x| = `|a| `^ x.
Proof.

Lemma lt0_norm_powR a x : a < 0 -> `|a `^ x| = 1.
Proof.

Lemma conjugate_powR a b p q : 0 <= a -> 0 <= b ->
  0 < p -> 0 < q -> p^-1 + q^-1 = 1 ->
  a * b <= a `^ p / p + b `^ q / q.
Proof.

End PowR.
Notation "a `^ x" := (powR a x) : ring_scope.

#[deprecated(since="mathcomp-analysis 0.6.5", note="renamed `ge0_ler_powR`")]
Notation gt0_ler_powR := ge0_ler_powR.

Section poweR.
Local Open Scope ereal_scope.
Context {R : realType}.
Implicit Types (s r : R) (x y : \bar R).

Definition poweR x r :=
  match x with
  | x'%:E => (x' `^ r)%:E
  | +oo => if r == 0%R then 1%E else +oo
  | -oo => if r == 0%R then 1%E else 0%E
  end.

Local Notation "x `^ r" := (poweR x r).

Lemma poweR_EFin s r : s%:E `^ r = (s `^ r)%:E.
Proof.

Lemma poweRyr r : r != 0%R -> +oo `^ r = +oo.
Proof.

Lemma poweRe0 x : x `^ 0 = 1.
Proof.

Lemma poweRe1 x : 0 <= x -> x `^ 1 = x.
Proof.

Lemma poweRN x r : x \is a fin_num -> x `^ (- r) = (fine x `^ r)^-1%:E.
Proof.

Lemma poweRNyr r : r != 0%R -> -oo `^ r = 0.
Proof.

Lemma poweR_eqy x r : x `^ r = +oo -> x = +oo.
Proof.

Lemma eqy_poweR x r : (0 < r)%R -> x = +oo -> x `^ r = +oo.
Proof.

Lemma poweR_lty x r : x < +oo -> x `^ r < +oo.
Proof.

Lemma lty_poweRy x r : r != 0%R -> x `^ r < +oo -> x < +oo.
Proof.

Lemma poweR0r r : r != 0%R -> 0 `^ r = 0.
Proof.

Lemma poweR1r r : 1 `^ r = 1. Proof. by rewrite poweR_EFin powR1.
Lemma fine_poweR x r : fine (x `^ r) = ((fine x) `^ r)%R.
Proof.

Lemma poweR_ge0 x r : 0 <= x `^ r.
Proof.

Lemma poweR_gt0 x r : 0 < x -> 0 < x `^ r.
Proof.

Lemma gt0_poweR x r : (0 < r)%R -> 0 <= x -> 0 < x `^ r -> 0 < x.
Proof.

Lemma poweR_eq0 x r : 0 <= x -> (x `^ r == 0) = ((x == 0) && (r != 0%R)).
Proof.

Lemma poweR_eq0_eq0 x r : 0 <= x -> x `^ r = 0 -> x = 0.
Proof.

Lemma gt0_ler_poweR r : (0 <= r)%R ->
  {in `[0, +oo] &, {homo poweR ^~ r : x y / x <= y >-> x <= y}}.
Proof.

Lemma fin_num_poweR x r : x \is a fin_num -> x `^ r \is a fin_num.
Proof.

Lemma poweRM x y r : 0 <= x -> 0 <= y -> (x * y) `^ r = x `^ r * y `^ r.
Proof.

Lemma poweRrM x r s : x `^ (r * s) = (x `^ r) `^ s.
Proof.

Lemma poweRAC x r s : (x `^ r) `^ s = (x `^ s) `^ r.
Proof.

Definition poweRD_def x r s := ((r + s == 0)%R ==>
  ((x != 0) && ((x \isn't a fin_num) ==> (r == 0%R) && (s == 0%R)))).
Notation "x '`^?' ( r +? s )" := (poweRD_def x r s) : ereal_scope.

Lemma poweRD_defE x r s :
  x `^?(r +? s) = ((r + s == 0)%R ==>
  ((x != 0) && ((x \isn't a fin_num) ==> (r == 0%R) && (s == 0%R)))).
Proof.

Lemma poweRB_defE x r s :
  x `^?(r +? - s) = ((r == s)%R ==>
  ((x != 0) && ((x \isn't a fin_num) ==> (r == 0%R) && (s == 0%R)))).
Proof.

Lemma add_neq0_poweRD_def x r s : (r + s != 0)%R -> x `^?(r +? s).
Proof.

Lemma add_neq0_poweRB_def x r s : (r != s)%R -> x `^?(r +? - s).
Proof.

Lemma nneg_neq0_poweRD_def x r s : x != 0 -> (r >= 0)%R -> (s >= 0)%R ->
  x `^?(r +? s).
Proof.

Lemma nneg_neq0_poweRB_def x r s : x != 0 -> (r >= 0)%R -> (s <= 0)%R ->
  x `^?(r +? - s).
Proof.

Lemma poweRD x r s : x `^?(r +? s) -> x `^ (r + s) = x `^ r * x `^ s.
Proof.

Lemma poweRB x r s : x `^?(r +? - s) -> x `^ (r - s) = x `^ r * x `^ (- s).
Proof.

Lemma poweR12_sqrt x : 0 <= x -> x `^ 2^-1 = sqrte x.
Proof.

End poweR.
Notation "a `^ x" := (poweR a x) : ereal_scope.

Section riemannR_series.
Variable R : realType.
Implicit Types a : R.
Local Open Scope real_scope.

Definition riemannR a : R ^nat := fun n => (n.+1%:R `^ a)^-1.
Arguments riemannR a n /.

Lemma riemannR_gt0 a i : 0 <= a -> 0 < riemannR a i.
Proof.

Lemma dvg_riemannR a : 0 <= a <= 1 -> ~ cvgn (series (riemannR a)).
Proof.

End riemannR_series.