src/HOL/Analysis/Extended_Real_Limits.thy
author nipkow
Sat Dec 29 15:43:53 2018 +0100 (6 months ago)
changeset 69529 4ab9657b3257
parent 69517 dc20f278e8f3
child 69566 c41954ee87cf
permissions -rw-r--r--
capitalize proper names in lemma names
hoelzl@63627
     1
(*  Title:      HOL/Analysis/Extended_Real_Limits.thy
wenzelm@41983
     2
    Author:     Johannes Hölzl, TU München
wenzelm@41983
     3
    Author:     Robert Himmelmann, TU München
wenzelm@41983
     4
    Author:     Armin Heller, TU München
wenzelm@41983
     5
    Author:     Bogdan Grechuk, University of Edinburgh
wenzelm@41983
     6
*)
hoelzl@41980
     7
nipkow@69517
     8
section%important \<open>Limits on the Extended Real Number Line\<close> (* TO FIX: perhaps put all Nonstandard Analysis related
ak2110@69221
     9
topics together? *)
hoelzl@41980
    10
hoelzl@41980
    11
theory Extended_Real_Limits
wenzelm@61560
    12
imports
wenzelm@61560
    13
  Topology_Euclidean_Space
wenzelm@66453
    14
  "HOL-Library.Extended_Real"
wenzelm@66453
    15
  "HOL-Library.Extended_Nonnegative_Real"
wenzelm@66453
    16
  "HOL-Library.Indicator_Function"
hoelzl@41980
    17
begin
hoelzl@41980
    18
ak2110@69221
    19
lemma%important compact_UNIV:
wenzelm@53788
    20
  "compact (UNIV :: 'a::{complete_linorder,linorder_topology,second_countable_topology} set)"
ak2110@69221
    21
  using%unimportant compact_complete_linorder
hoelzl@51351
    22
  by (auto simp: seq_compact_eq_compact[symmetric] seq_compact_def)
hoelzl@51351
    23
ak2110@69221
    24
lemma%important compact_eq_closed:
wenzelm@53788
    25
  fixes S :: "'a::{complete_linorder,linorder_topology,second_countable_topology} set"
hoelzl@51351
    26
  shows "compact S \<longleftrightarrow> closed S"
ak2110@69221
    27
  using%unimportant closed_Int_compact[of S, OF _ compact_UNIV] compact_imp_closed
wenzelm@53788
    28
  by auto
hoelzl@51351
    29
ak2110@69221
    30
lemma%important closed_contains_Sup_cl:
wenzelm@53788
    31
  fixes S :: "'a::{complete_linorder,linorder_topology,second_countable_topology} set"
wenzelm@53788
    32
  assumes "closed S"
wenzelm@53788
    33
    and "S \<noteq> {}"
wenzelm@53788
    34
  shows "Sup S \<in> S"
ak2110@69221
    35
proof%unimportant -
hoelzl@51351
    36
  from compact_eq_closed[of S] compact_attains_sup[of S] assms
wenzelm@53788
    37
  obtain s where S: "s \<in> S" "\<forall>t\<in>S. t \<le> s"
wenzelm@53788
    38
    by auto
wenzelm@53374
    39
  then have "Sup S = s"
hoelzl@51351
    40
    by (auto intro!: Sup_eqI)
wenzelm@53374
    41
  with S show ?thesis
hoelzl@51351
    42
    by simp
hoelzl@51351
    43
qed
hoelzl@51351
    44
ak2110@69221
    45
lemma%important closed_contains_Inf_cl:
wenzelm@53788
    46
  fixes S :: "'a::{complete_linorder,linorder_topology,second_countable_topology} set"
wenzelm@53788
    47
  assumes "closed S"
wenzelm@53788
    48
    and "S \<noteq> {}"
wenzelm@53788
    49
  shows "Inf S \<in> S"
ak2110@69221
    50
proof%unimportant -
hoelzl@51351
    51
  from compact_eq_closed[of S] compact_attains_inf[of S] assms
wenzelm@53788
    52
  obtain s where S: "s \<in> S" "\<forall>t\<in>S. s \<le> t"
wenzelm@53788
    53
    by auto
wenzelm@53374
    54
  then have "Inf S = s"
hoelzl@51351
    55
    by (auto intro!: Inf_eqI)
wenzelm@53374
    56
  with S show ?thesis
hoelzl@51351
    57
    by simp
hoelzl@51351
    58
qed
hoelzl@51351
    59
hoelzl@64320
    60
instance enat :: second_countable_topology
hoelzl@64320
    61
proof
hoelzl@64320
    62
  show "\<exists>B::enat set set. countable B \<and> open = generate_topology B"
hoelzl@64320
    63
  proof (intro exI conjI)
hoelzl@64320
    64
    show "countable (range lessThan \<union> range greaterThan::enat set set)"
hoelzl@64320
    65
      by auto
hoelzl@64320
    66
  qed (simp add: open_enat_def)
hoelzl@64320
    67
qed
hoelzl@64320
    68
ak2110@69221
    69
instance%important ereal :: second_countable_topology
ak2110@69221
    70
proof%unimportant (standard, intro exI conjI)
hoelzl@51351
    71
  let ?B = "(\<Union>r\<in>\<rat>. {{..< r}, {r <..}} :: ereal set set)"
wenzelm@53788
    72
  show "countable ?B"
wenzelm@53788
    73
    by (auto intro: countable_rat)
hoelzl@51351
    74
  show "open = generate_topology ?B"
hoelzl@51351
    75
  proof (intro ext iffI)
wenzelm@53788
    76
    fix S :: "ereal set"
wenzelm@53788
    77
    assume "open S"
hoelzl@51351
    78
    then show "generate_topology ?B S"
hoelzl@51351
    79
      unfolding open_generated_order
hoelzl@51351
    80
    proof induct
hoelzl@51351
    81
      case (Basis b)
wenzelm@53788
    82
      then obtain e where "b = {..<e} \<or> b = {e<..}"
wenzelm@53788
    83
        by auto
hoelzl@51351
    84
      moreover have "{..<e} = \<Union>{{..<x}|x. x \<in> \<rat> \<and> x < e}" "{e<..} = \<Union>{{x<..}|x. x \<in> \<rat> \<and> e < x}"
hoelzl@51351
    85
        by (auto dest: ereal_dense3
hoelzl@51351
    86
                 simp del: ex_simps
hoelzl@51351
    87
                 simp add: ex_simps[symmetric] conj_commute Rats_def image_iff)
hoelzl@51351
    88
      ultimately show ?case
hoelzl@51351
    89
        by (auto intro: generate_topology.intros)
hoelzl@51351
    90
    qed (auto intro: generate_topology.intros)
hoelzl@51351
    91
  next
wenzelm@53788
    92
    fix S
wenzelm@53788
    93
    assume "generate_topology ?B S"
wenzelm@53788
    94
    then show "open S"
wenzelm@53788
    95
      by induct auto
hoelzl@51351
    96
  qed
hoelzl@51351
    97
qed
hoelzl@51351
    98
hoelzl@62375
    99
text \<open>This is a copy from \<open>ereal :: second_countable_topology\<close>. Maybe find a common super class of
hoelzl@62375
   100
topological spaces where the rational numbers are densely embedded ?\<close>
ak2110@69221
   101
instance%important ennreal :: second_countable_topology
ak2110@69221
   102
proof%unimportant (standard, intro exI conjI)
hoelzl@62375
   103
  let ?B = "(\<Union>r\<in>\<rat>. {{..< r}, {r <..}} :: ennreal set set)"
hoelzl@62375
   104
  show "countable ?B"
hoelzl@62375
   105
    by (auto intro: countable_rat)
hoelzl@62375
   106
  show "open = generate_topology ?B"
hoelzl@62375
   107
  proof (intro ext iffI)
hoelzl@62375
   108
    fix S :: "ennreal set"
hoelzl@62375
   109
    assume "open S"
hoelzl@62375
   110
    then show "generate_topology ?B S"
hoelzl@62375
   111
      unfolding open_generated_order
hoelzl@62375
   112
    proof induct
hoelzl@62375
   113
      case (Basis b)
hoelzl@62375
   114
      then obtain e where "b = {..<e} \<or> b = {e<..}"
hoelzl@62375
   115
        by auto
hoelzl@62375
   116
      moreover have "{..<e} = \<Union>{{..<x}|x. x \<in> \<rat> \<and> x < e}" "{e<..} = \<Union>{{x<..}|x. x \<in> \<rat> \<and> e < x}"
hoelzl@62375
   117
        by (auto dest: ennreal_rat_dense
hoelzl@62375
   118
                 simp del: ex_simps
hoelzl@62375
   119
                 simp add: ex_simps[symmetric] conj_commute Rats_def image_iff)
hoelzl@62375
   120
      ultimately show ?case
hoelzl@62375
   121
        by (auto intro: generate_topology.intros)
hoelzl@62375
   122
    qed (auto intro: generate_topology.intros)
hoelzl@62375
   123
  next
hoelzl@62375
   124
    fix S
hoelzl@62375
   125
    assume "generate_topology ?B S"
hoelzl@62375
   126
    then show "open S"
hoelzl@62375
   127
      by induct auto
hoelzl@62375
   128
  qed
hoelzl@62375
   129
qed
hoelzl@62375
   130
ak2110@69221
   131
lemma%important ereal_open_closed_aux:
hoelzl@43920
   132
  fixes S :: "ereal set"
wenzelm@53788
   133
  assumes "open S"
wenzelm@53788
   134
    and "closed S"
wenzelm@53788
   135
    and S: "(-\<infinity>) \<notin> S"
hoelzl@41980
   136
  shows "S = {}"
ak2110@69221
   137
proof%unimportant (rule ccontr)
wenzelm@53788
   138
  assume "\<not> ?thesis"
wenzelm@53788
   139
  then have *: "Inf S \<in> S"
hoelzl@62375
   140
wenzelm@53788
   141
    by (metis assms(2) closed_contains_Inf_cl)
wenzelm@53788
   142
  {
wenzelm@53788
   143
    assume "Inf S = -\<infinity>"
wenzelm@53788
   144
    then have False
wenzelm@53788
   145
      using * assms(3) by auto
wenzelm@53788
   146
  }
hoelzl@41980
   147
  moreover
wenzelm@53788
   148
  {
wenzelm@53788
   149
    assume "Inf S = \<infinity>"
wenzelm@53788
   150
    then have "S = {\<infinity>}"
wenzelm@60420
   151
      by (metis Inf_eq_PInfty \<open>S \<noteq> {}\<close>)
wenzelm@53788
   152
    then have False
wenzelm@53788
   153
      by (metis assms(1) not_open_singleton)
wenzelm@53788
   154
  }
hoelzl@41980
   155
  moreover
wenzelm@53788
   156
  {
wenzelm@53788
   157
    assume fin: "\<bar>Inf S\<bar> \<noteq> \<infinity>"
wenzelm@53788
   158
    from ereal_open_cont_interval[OF assms(1) * fin]
wenzelm@53788
   159
    obtain e where e: "e > 0" "{Inf S - e<..<Inf S + e} \<subseteq> S" .
wenzelm@53788
   160
    then obtain b where b: "Inf S - e < b" "b < Inf S"
wenzelm@53788
   161
      using fin ereal_between[of "Inf S" e] dense[of "Inf S - e"]
noschinl@44918
   162
      by auto
wenzelm@67613
   163
    then have "b \<in> {Inf S - e <..< Inf S + e}"
wenzelm@53788
   164
      using e fin ereal_between[of "Inf S" e]
wenzelm@53788
   165
      by auto
wenzelm@53788
   166
    then have "b \<in> S"
wenzelm@53788
   167
      using e by auto
wenzelm@53788
   168
    then have False
wenzelm@53788
   169
      using b by (metis complete_lattice_class.Inf_lower leD)
wenzelm@53788
   170
  }
wenzelm@53788
   171
  ultimately show False
wenzelm@53788
   172
    by auto
hoelzl@41980
   173
qed
hoelzl@41980
   174
ak2110@69221
   175
lemma%important ereal_open_closed:
hoelzl@43920
   176
  fixes S :: "ereal set"
wenzelm@53788
   177
  shows "open S \<and> closed S \<longleftrightarrow> S = {} \<or> S = UNIV"
ak2110@69221
   178
proof%unimportant -
wenzelm@53788
   179
  {
wenzelm@53788
   180
    assume lhs: "open S \<and> closed S"
wenzelm@53788
   181
    {
wenzelm@53788
   182
      assume "-\<infinity> \<notin> S"
wenzelm@53788
   183
      then have "S = {}"
wenzelm@53788
   184
        using lhs ereal_open_closed_aux by auto
wenzelm@53788
   185
    }
wenzelm@49664
   186
    moreover
wenzelm@53788
   187
    {
wenzelm@53788
   188
      assume "-\<infinity> \<in> S"
wenzelm@53788
   189
      then have "- S = {}"
wenzelm@53788
   190
        using lhs ereal_open_closed_aux[of "-S"] by auto
wenzelm@53788
   191
    }
wenzelm@53788
   192
    ultimately have "S = {} \<or> S = UNIV"
wenzelm@53788
   193
      by auto
wenzelm@53788
   194
  }
wenzelm@53788
   195
  then show ?thesis
wenzelm@53788
   196
    by auto
hoelzl@41980
   197
qed
hoelzl@41980
   198
ak2110@69221
   199
lemma%important ereal_open_atLeast:
wenzelm@53788
   200
  fixes x :: ereal
wenzelm@53788
   201
  shows "open {x..} \<longleftrightarrow> x = -\<infinity>"
ak2110@69221
   202
proof%unimportant
wenzelm@53788
   203
  assume "x = -\<infinity>"
wenzelm@53788
   204
  then have "{x..} = UNIV"
wenzelm@53788
   205
    by auto
wenzelm@53788
   206
  then show "open {x..}"
wenzelm@53788
   207
    by auto
hoelzl@41980
   208
next
hoelzl@41980
   209
  assume "open {x..}"
wenzelm@53788
   210
  then have "open {x..} \<and> closed {x..}"
wenzelm@53788
   211
    by auto
wenzelm@53788
   212
  then have "{x..} = UNIV"
wenzelm@53788
   213
    unfolding ereal_open_closed by auto
wenzelm@53788
   214
  then show "x = -\<infinity>"
wenzelm@53788
   215
    by (simp add: bot_ereal_def atLeast_eq_UNIV_iff)
hoelzl@41980
   216
qed
hoelzl@41980
   217
ak2110@69221
   218
lemma%important mono_closed_real:
hoelzl@41980
   219
  fixes S :: "real set"
wenzelm@53788
   220
  assumes mono: "\<forall>y z. y \<in> S \<and> y \<le> z \<longrightarrow> z \<in> S"
wenzelm@49664
   221
    and "closed S"
wenzelm@53788
   222
  shows "S = {} \<or> S = UNIV \<or> (\<exists>a. S = {a..})"
ak2110@69221
   223
proof%unimportant -
wenzelm@53788
   224
  {
wenzelm@53788
   225
    assume "S \<noteq> {}"
wenzelm@53788
   226
    { assume ex: "\<exists>B. \<forall>x\<in>S. B \<le> x"
wenzelm@53788
   227
      then have *: "\<forall>x\<in>S. Inf S \<le> x"
hoelzl@54258
   228
        using cInf_lower[of _ S] ex by (metis bdd_below_def)
wenzelm@53788
   229
      then have "Inf S \<in> S"
wenzelm@53788
   230
        apply (subst closed_contains_Inf)
wenzelm@60420
   231
        using ex \<open>S \<noteq> {}\<close> \<open>closed S\<close>
wenzelm@53788
   232
        apply auto
wenzelm@53788
   233
        done
wenzelm@53788
   234
      then have "\<forall>x. Inf S \<le> x \<longleftrightarrow> x \<in> S"
wenzelm@53788
   235
        using mono[rule_format, of "Inf S"] *
wenzelm@53788
   236
        by auto
wenzelm@53788
   237
      then have "S = {Inf S ..}"
wenzelm@53788
   238
        by auto
wenzelm@53788
   239
      then have "\<exists>a. S = {a ..}"
wenzelm@53788
   240
        by auto
wenzelm@49664
   241
    }
wenzelm@49664
   242
    moreover
wenzelm@53788
   243
    {
wenzelm@53788
   244
      assume "\<not> (\<exists>B. \<forall>x\<in>S. B \<le> x)"
wenzelm@53788
   245
      then have nex: "\<forall>B. \<exists>x\<in>S. x < B"
wenzelm@53788
   246
        by (simp add: not_le)
wenzelm@53788
   247
      {
wenzelm@53788
   248
        fix y
wenzelm@53788
   249
        obtain x where "x\<in>S" and "x < y"
wenzelm@53788
   250
          using nex by auto
wenzelm@53788
   251
        then have "y \<in> S"
wenzelm@53788
   252
          using mono[rule_format, of x y] by auto
wenzelm@53788
   253
      }
wenzelm@53788
   254
      then have "S = UNIV"
wenzelm@53788
   255
        by auto
wenzelm@49664
   256
    }
wenzelm@53788
   257
    ultimately have "S = UNIV \<or> (\<exists>a. S = {a ..})"
wenzelm@53788
   258
      by blast
wenzelm@53788
   259
  }
wenzelm@53788
   260
  then show ?thesis
wenzelm@53788
   261
    by blast
hoelzl@41980
   262
qed
hoelzl@41980
   263
ak2110@69221
   264
lemma%important mono_closed_ereal:
hoelzl@41980
   265
  fixes S :: "real set"
wenzelm@53788
   266
  assumes mono: "\<forall>y z. y \<in> S \<and> y \<le> z \<longrightarrow> z \<in> S"
wenzelm@49664
   267
    and "closed S"
wenzelm@53788
   268
  shows "\<exists>a. S = {x. a \<le> ereal x}"
ak2110@69221
   269
proof%unimportant -
wenzelm@53788
   270
  {
wenzelm@53788
   271
    assume "S = {}"
wenzelm@53788
   272
    then have ?thesis
wenzelm@53788
   273
      apply (rule_tac x=PInfty in exI)
wenzelm@53788
   274
      apply auto
wenzelm@53788
   275
      done
wenzelm@53788
   276
  }
wenzelm@49664
   277
  moreover
wenzelm@53788
   278
  {
wenzelm@53788
   279
    assume "S = UNIV"
wenzelm@53788
   280
    then have ?thesis
wenzelm@53788
   281
      apply (rule_tac x="-\<infinity>" in exI)
wenzelm@53788
   282
      apply auto
wenzelm@53788
   283
      done
wenzelm@53788
   284
  }
wenzelm@49664
   285
  moreover
wenzelm@53788
   286
  {
wenzelm@53788
   287
    assume "\<exists>a. S = {a ..}"
wenzelm@53788
   288
    then obtain a where "S = {a ..}"
wenzelm@53788
   289
      by auto
wenzelm@53788
   290
    then have ?thesis
wenzelm@53788
   291
      apply (rule_tac x="ereal a" in exI)
wenzelm@53788
   292
      apply auto
wenzelm@53788
   293
      done
wenzelm@49664
   294
  }
wenzelm@53788
   295
  ultimately show ?thesis
wenzelm@53788
   296
    using mono_closed_real[of S] assms by auto
hoelzl@41980
   297
qed
hoelzl@41980
   298
ak2110@69221
   299
lemma%important Liminf_within:
hoelzl@51340
   300
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
haftmann@69260
   301
  shows "Liminf (at x within S) f = (SUP e\<in>{0<..}. INF y\<in>(S \<inter> ball x e - {x}). f y)"
hoelzl@51641
   302
  unfolding Liminf_def eventually_at
ak2110@69221
   303
proof%unimportant (rule SUP_eq, simp_all add: Ball_def Bex_def, safe)
wenzelm@53788
   304
  fix P d
wenzelm@53788
   305
  assume "0 < d" and "\<forall>y. y \<in> S \<longrightarrow> y \<noteq> x \<and> dist y x < d \<longrightarrow> P y"
hoelzl@51340
   306
  then have "S \<inter> ball x d - {x} \<subseteq> {x. P x}"
hoelzl@51340
   307
    by (auto simp: zero_less_dist_iff dist_commute)
haftmann@69313
   308
  then show "\<exists>r>0. Inf (f ` (Collect P)) \<le> Inf (f ` (S \<inter> ball x r - {x}))"
wenzelm@60420
   309
    by (intro exI[of _ d] INF_mono conjI \<open>0 < d\<close>) auto
hoelzl@51340
   310
next
wenzelm@53788
   311
  fix d :: real
wenzelm@53788
   312
  assume "0 < d"
hoelzl@51641
   313
  then show "\<exists>P. (\<exists>d>0. \<forall>xa. xa \<in> S \<longrightarrow> xa \<noteq> x \<and> dist xa x < d \<longrightarrow> P xa) \<and>
haftmann@69313
   314
    Inf (f ` (S \<inter> ball x d - {x})) \<le> Inf (f ` (Collect P))"
hoelzl@51340
   315
    by (intro exI[of _ "\<lambda>y. y \<in> S \<inter> ball x d - {x}"])
hoelzl@51340
   316
       (auto intro!: INF_mono exI[of _ d] simp: dist_commute)
hoelzl@51340
   317
qed
hoelzl@51340
   318
ak2110@69221
   319
lemma%important Limsup_within:
wenzelm@53788
   320
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
haftmann@69260
   321
  shows "Limsup (at x within S) f = (INF e\<in>{0<..}. SUP y\<in>(S \<inter> ball x e - {x}). f y)"
hoelzl@51641
   322
  unfolding Limsup_def eventually_at
ak2110@69221
   323
proof%unimportant (rule INF_eq, simp_all add: Ball_def Bex_def, safe)
wenzelm@53788
   324
  fix P d
wenzelm@53788
   325
  assume "0 < d" and "\<forall>y. y \<in> S \<longrightarrow> y \<noteq> x \<and> dist y x < d \<longrightarrow> P y"
hoelzl@51340
   326
  then have "S \<inter> ball x d - {x} \<subseteq> {x. P x}"
hoelzl@51340
   327
    by (auto simp: zero_less_dist_iff dist_commute)
haftmann@69313
   328
  then show "\<exists>r>0. Sup (f ` (S \<inter> ball x r - {x})) \<le> Sup (f ` (Collect P))"
wenzelm@60420
   329
    by (intro exI[of _ d] SUP_mono conjI \<open>0 < d\<close>) auto
hoelzl@51340
   330
next
wenzelm@53788
   331
  fix d :: real
wenzelm@53788
   332
  assume "0 < d"
hoelzl@51641
   333
  then show "\<exists>P. (\<exists>d>0. \<forall>xa. xa \<in> S \<longrightarrow> xa \<noteq> x \<and> dist xa x < d \<longrightarrow> P xa) \<and>
haftmann@69313
   334
    Sup (f ` (Collect P)) \<le> Sup (f ` (S \<inter> ball x d - {x}))"
hoelzl@51340
   335
    by (intro exI[of _ "\<lambda>y. y \<in> S \<inter> ball x d - {x}"])
hoelzl@51340
   336
       (auto intro!: SUP_mono exI[of _ d] simp: dist_commute)
hoelzl@51340
   337
qed
hoelzl@51340
   338
hoelzl@51340
   339
lemma Liminf_at:
hoelzl@54257
   340
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
haftmann@69260
   341
  shows "Liminf (at x) f = (SUP e\<in>{0<..}. INF y\<in>(ball x e - {x}). f y)"
hoelzl@51340
   342
  using Liminf_within[of x UNIV f] by simp
hoelzl@51340
   343
hoelzl@51340
   344
lemma Limsup_at:
hoelzl@54257
   345
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
haftmann@69260
   346
  shows "Limsup (at x) f = (INF e\<in>{0<..}. SUP y\<in>(ball x e - {x}). f y)"
hoelzl@51340
   347
  using Limsup_within[of x UNIV f] by simp
hoelzl@51340
   348
hoelzl@51340
   349
lemma min_Liminf_at:
wenzelm@53788
   350
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_linorder"
haftmann@69260
   351
  shows "min (f x) (Liminf (at x) f) = (SUP e\<in>{0<..}. INF y\<in>ball x e. f y)"
hoelzl@51340
   352
  unfolding inf_min[symmetric] Liminf_at
hoelzl@51340
   353
  apply (subst inf_commute)
hoelzl@51340
   354
  apply (subst SUP_inf)
hoelzl@51340
   355
  apply (intro SUP_cong[OF refl])
hoelzl@54260
   356
  apply (cut_tac A="ball x xa - {x}" and B="{x}" and M=f in INF_union)
haftmann@56166
   357
  apply (drule sym)
haftmann@56166
   358
  apply auto
wenzelm@57865
   359
  apply (metis INF_absorb centre_in_ball)
wenzelm@57865
   360
  done
hoelzl@51340
   361
eberlm@66456
   362
ak2110@69221
   363
subsection%important \<open>Extended-Real.thy\<close> (*FIX title *)
eberlm@66456
   364
eberlm@66456
   365
lemma sum_constant_ereal:
eberlm@66456
   366
  fixes a::ereal
eberlm@66456
   367
  shows "(\<Sum>i\<in>I. a) = a * card I"
eberlm@66456
   368
apply (cases "finite I", induct set: finite, simp_all)
eberlm@66456
   369
apply (cases a, auto, metis (no_types, hide_lams) add.commute mult.commute semiring_normalization_rules(3))
eberlm@66456
   370
done
eberlm@66456
   371
eberlm@66456
   372
lemma real_lim_then_eventually_real:
eberlm@66456
   373
  assumes "(u \<longlongrightarrow> ereal l) F"
eberlm@66456
   374
  shows "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) F"
eberlm@66456
   375
proof -
eberlm@66456
   376
  have "ereal l \<in> {-\<infinity><..<(\<infinity>::ereal)}" by simp
eberlm@66456
   377
  moreover have "open {-\<infinity><..<(\<infinity>::ereal)}" by simp
eberlm@66456
   378
  ultimately have "eventually (\<lambda>n. u n \<in> {-\<infinity><..<(\<infinity>::ereal)}) F" using assms tendsto_def by blast
eberlm@66456
   379
  moreover have "\<And>x. x \<in> {-\<infinity><..<(\<infinity>::ereal)} \<Longrightarrow> x = ereal(real_of_ereal x)" using ereal_real by auto
eberlm@66456
   380
  ultimately show ?thesis by (metis (mono_tags, lifting) eventually_mono)
eberlm@66456
   381
qed
eberlm@66456
   382
ak2110@69221
   383
lemma%important ereal_Inf_cmult:
eberlm@66456
   384
  assumes "c>(0::real)"
eberlm@66456
   385
  shows "Inf {ereal c * x |x. P x} = ereal c * Inf {x. P x}"
ak2110@69221
   386
proof%unimportant -
eberlm@66456
   387
  have "(\<lambda>x::ereal. c * x) (Inf {x::ereal. P x}) = Inf ((\<lambda>x::ereal. c * x)`{x::ereal. P x})"
eberlm@66456
   388
    apply (rule mono_bij_Inf)
eberlm@66456
   389
    apply (simp add: assms ereal_mult_left_mono less_imp_le mono_def)
eberlm@66456
   390
    apply (rule bij_betw_byWitness[of _ "\<lambda>x. (x::ereal) / c"], auto simp add: assms ereal_mult_divide)
eberlm@66456
   391
    using assms ereal_divide_eq apply auto
eberlm@66456
   392
    done
eberlm@66456
   393
  then show ?thesis by (simp only: setcompr_eq_image[symmetric])
eberlm@66456
   394
qed
eberlm@66456
   395
eberlm@66456
   396
ak2110@69221
   397
subsubsection%important \<open>Continuity of addition\<close>
eberlm@66456
   398
eberlm@66456
   399
text \<open>The next few lemmas remove an unnecessary assumption in \verb+tendsto_add_ereal+, culminating
eberlm@66456
   400
in \verb+tendsto_add_ereal_general+ which essentially says that the addition
eberlm@66456
   401
is continuous on ereal times ereal, except at $(-\infty, \infty)$ and $(\infty, -\infty)$.
eberlm@66456
   402
It is much more convenient in many situations, see for instance the proof of
eberlm@66456
   403
\verb+tendsto_sum_ereal+ below.\<close>
eberlm@66456
   404
ak2110@69221
   405
lemma%important tendsto_add_ereal_PInf:
eberlm@66456
   406
  fixes y :: ereal
eberlm@66456
   407
  assumes y: "y \<noteq> -\<infinity>"
eberlm@66456
   408
  assumes f: "(f \<longlongrightarrow> \<infinity>) F" and g: "(g \<longlongrightarrow> y) F"
eberlm@66456
   409
  shows "((\<lambda>x. f x + g x) \<longlongrightarrow> \<infinity>) F"
ak2110@69221
   410
proof%unimportant -
eberlm@66456
   411
  have "\<exists>C. eventually (\<lambda>x. g x > ereal C) F"
eberlm@66456
   412
  proof (cases y)
eberlm@66456
   413
    case (real r)
eberlm@66456
   414
    have "y > y-1" using y real by (simp add: ereal_between(1))
eberlm@66456
   415
    then have "eventually (\<lambda>x. g x > y - 1) F" using g y order_tendsto_iff by auto
eberlm@66456
   416
    moreover have "y-1 = ereal(real_of_ereal(y-1))"
eberlm@66456
   417
      by (metis real ereal_eq_1(1) ereal_minus(1) real_of_ereal.simps(1))
eberlm@66456
   418
    ultimately have "eventually (\<lambda>x. g x > ereal(real_of_ereal(y - 1))) F" by simp
eberlm@66456
   419
    then show ?thesis by auto
eberlm@66456
   420
  next
eberlm@66456
   421
    case (PInf)
eberlm@66456
   422
    have "eventually (\<lambda>x. g x > ereal 0) F" using g PInf by (simp add: tendsto_PInfty)
eberlm@66456
   423
    then show ?thesis by auto
eberlm@66456
   424
  qed (simp add: y)
eberlm@66456
   425
  then obtain C::real where ge: "eventually (\<lambda>x. g x > ereal C) F" by auto
eberlm@66456
   426
eberlm@66456
   427
  {
eberlm@66456
   428
    fix M::real
eberlm@66456
   429
    have "eventually (\<lambda>x. f x > ereal(M - C)) F" using f by (simp add: tendsto_PInfty)
eberlm@66456
   430
    then have "eventually (\<lambda>x. (f x > ereal (M-C)) \<and> (g x > ereal C)) F"
eberlm@66456
   431
      by (auto simp add: ge eventually_conj_iff)
eberlm@66456
   432
    moreover have "\<And>x. ((f x > ereal (M-C)) \<and> (g x > ereal C)) \<Longrightarrow> (f x + g x > ereal M)"
eberlm@66456
   433
      using ereal_add_strict_mono2 by fastforce
eberlm@66456
   434
    ultimately have "eventually (\<lambda>x. f x + g x > ereal M) F" using eventually_mono by force
eberlm@66456
   435
  }
eberlm@66456
   436
  then show ?thesis by (simp add: tendsto_PInfty)
eberlm@66456
   437
qed
eberlm@66456
   438
eberlm@66456
   439
text\<open>One would like to deduce the next lemma from the previous one, but the fact
eberlm@66456
   440
that $-(x+y)$ is in general different from $(-x) + (-y)$ in ereal creates difficulties,
eberlm@66456
   441
so it is more efficient to copy the previous proof.\<close>
eberlm@66456
   442
ak2110@69221
   443
lemma%important tendsto_add_ereal_MInf:
eberlm@66456
   444
  fixes y :: ereal
eberlm@66456
   445
  assumes y: "y \<noteq> \<infinity>"
eberlm@66456
   446
  assumes f: "(f \<longlongrightarrow> -\<infinity>) F" and g: "(g \<longlongrightarrow> y) F"
eberlm@66456
   447
  shows "((\<lambda>x. f x + g x) \<longlongrightarrow> -\<infinity>) F"
ak2110@69221
   448
proof%unimportant -
eberlm@66456
   449
  have "\<exists>C. eventually (\<lambda>x. g x < ereal C) F"
eberlm@66456
   450
  proof (cases y)
eberlm@66456
   451
    case (real r)
eberlm@66456
   452
    have "y < y+1" using y real by (simp add: ereal_between(1))
eberlm@66456
   453
    then have "eventually (\<lambda>x. g x < y + 1) F" using g y order_tendsto_iff by force
eberlm@66456
   454
    moreover have "y+1 = ereal(real_of_ereal (y+1))" by (simp add: real)
eberlm@66456
   455
    ultimately have "eventually (\<lambda>x. g x < ereal(real_of_ereal(y + 1))) F" by simp
eberlm@66456
   456
    then show ?thesis by auto
eberlm@66456
   457
  next
eberlm@66456
   458
    case (MInf)
eberlm@66456
   459
    have "eventually (\<lambda>x. g x < ereal 0) F" using g MInf by (simp add: tendsto_MInfty)
eberlm@66456
   460
    then show ?thesis by auto
eberlm@66456
   461
  qed (simp add: y)
eberlm@66456
   462
  then obtain C::real where ge: "eventually (\<lambda>x. g x < ereal C) F" by auto
eberlm@66456
   463
eberlm@66456
   464
  {
eberlm@66456
   465
    fix M::real
eberlm@66456
   466
    have "eventually (\<lambda>x. f x < ereal(M - C)) F" using f by (simp add: tendsto_MInfty)
eberlm@66456
   467
    then have "eventually (\<lambda>x. (f x < ereal (M- C)) \<and> (g x < ereal C)) F"
eberlm@66456
   468
      by (auto simp add: ge eventually_conj_iff)
eberlm@66456
   469
    moreover have "\<And>x. ((f x < ereal (M-C)) \<and> (g x < ereal C)) \<Longrightarrow> (f x + g x < ereal M)"
eberlm@66456
   470
      using ereal_add_strict_mono2 by fastforce
eberlm@66456
   471
    ultimately have "eventually (\<lambda>x. f x + g x < ereal M) F" using eventually_mono by force
eberlm@66456
   472
  }
eberlm@66456
   473
  then show ?thesis by (simp add: tendsto_MInfty)
eberlm@66456
   474
qed
eberlm@66456
   475
ak2110@69221
   476
lemma%important tendsto_add_ereal_general1:
eberlm@66456
   477
  fixes x y :: ereal
eberlm@66456
   478
  assumes y: "\<bar>y\<bar> \<noteq> \<infinity>"
eberlm@66456
   479
  assumes f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
eberlm@66456
   480
  shows "((\<lambda>x. f x + g x) \<longlongrightarrow> x + y) F"
ak2110@69221
   481
proof%unimportant (cases x)
eberlm@66456
   482
  case (real r)
eberlm@66456
   483
  have a: "\<bar>x\<bar> \<noteq> \<infinity>" by (simp add: real)
eberlm@66456
   484
  show ?thesis by (rule tendsto_add_ereal[OF a, OF y, OF f, OF g])
eberlm@66456
   485
next
eberlm@66456
   486
  case PInf
eberlm@66456
   487
  then show ?thesis using tendsto_add_ereal_PInf assms by force
eberlm@66456
   488
next
eberlm@66456
   489
  case MInf
eberlm@66456
   490
  then show ?thesis using tendsto_add_ereal_MInf assms
eberlm@66456
   491
    by (metis abs_ereal.simps(3) ereal_MInfty_eq_plus)
eberlm@66456
   492
qed
eberlm@66456
   493
ak2110@69221
   494
lemma%important tendsto_add_ereal_general2:
eberlm@66456
   495
  fixes x y :: ereal
eberlm@66456
   496
  assumes x: "\<bar>x\<bar> \<noteq> \<infinity>"
eberlm@66456
   497
      and f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
eberlm@66456
   498
  shows "((\<lambda>x. f x + g x) \<longlongrightarrow> x + y) F"
ak2110@69221
   499
proof%unimportant -
eberlm@66456
   500
  have "((\<lambda>x. g x + f x) \<longlongrightarrow> x + y) F"
eberlm@66456
   501
    using tendsto_add_ereal_general1[OF x, OF g, OF f] add.commute[of "y", of "x"] by simp
eberlm@66456
   502
  moreover have "\<And>x. g x + f x = f x + g x" using add.commute by auto
eberlm@66456
   503
  ultimately show ?thesis by simp
eberlm@66456
   504
qed
eberlm@66456
   505
eberlm@66456
   506
text \<open>The next lemma says that the addition is continuous on ereal, except at
eberlm@66456
   507
the pairs $(-\infty, \infty)$ and $(\infty, -\infty)$.\<close>
eberlm@66456
   508
ak2110@69221
   509
lemma%important tendsto_add_ereal_general [tendsto_intros]:
eberlm@66456
   510
  fixes x y :: ereal
eberlm@66456
   511
  assumes "\<not>((x=\<infinity> \<and> y=-\<infinity>) \<or> (x=-\<infinity> \<and> y=\<infinity>))"
eberlm@66456
   512
      and f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
eberlm@66456
   513
  shows "((\<lambda>x. f x + g x) \<longlongrightarrow> x + y) F"
ak2110@69221
   514
proof%unimportant (cases x)
eberlm@66456
   515
  case (real r)
eberlm@66456
   516
  show ?thesis
eberlm@66456
   517
    apply (rule tendsto_add_ereal_general2) using real assms by auto
eberlm@66456
   518
next
eberlm@66456
   519
  case (PInf)
eberlm@66456
   520
  then have "y \<noteq> -\<infinity>" using assms by simp
eberlm@66456
   521
  then show ?thesis using tendsto_add_ereal_PInf PInf assms by auto
eberlm@66456
   522
next
eberlm@66456
   523
  case (MInf)
eberlm@66456
   524
  then have "y \<noteq> \<infinity>" using assms by simp
eberlm@66456
   525
  then show ?thesis using tendsto_add_ereal_MInf MInf f g by (metis ereal_MInfty_eq_plus)
eberlm@66456
   526
qed
eberlm@66456
   527
ak2110@69221
   528
subsubsection%important \<open>Continuity of multiplication\<close>
eberlm@66456
   529
eberlm@66456
   530
text \<open>In the same way as for addition, we prove that the multiplication is continuous on
eberlm@66456
   531
ereal times ereal, except at $(\infty, 0)$ and $(-\infty, 0)$ and $(0, \infty)$ and $(0, -\infty)$,
eberlm@66456
   532
starting with specific situations.\<close>
eberlm@66456
   533
ak2110@69221
   534
lemma%important tendsto_mult_real_ereal:
eberlm@66456
   535
  assumes "(u \<longlongrightarrow> ereal l) F" "(v \<longlongrightarrow> ereal m) F"
eberlm@66456
   536
  shows "((\<lambda>n. u n * v n) \<longlongrightarrow> ereal l * ereal m) F"
ak2110@69221
   537
proof%unimportant -
eberlm@66456
   538
  have ureal: "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) F" by (rule real_lim_then_eventually_real[OF assms(1)])
eberlm@66456
   539
  then have "((\<lambda>n. ereal(real_of_ereal(u n))) \<longlongrightarrow> ereal l) F" using assms by auto
eberlm@66456
   540
  then have limu: "((\<lambda>n. real_of_ereal(u n)) \<longlongrightarrow> l) F" by auto
eberlm@66456
   541
  have vreal: "eventually (\<lambda>n. v n = ereal(real_of_ereal(v n))) F" by (rule real_lim_then_eventually_real[OF assms(2)])
eberlm@66456
   542
  then have "((\<lambda>n. ereal(real_of_ereal(v n))) \<longlongrightarrow> ereal m) F" using assms by auto
eberlm@66456
   543
  then have limv: "((\<lambda>n. real_of_ereal(v n)) \<longlongrightarrow> m) F" by auto
eberlm@66456
   544
eberlm@66456
   545
  {
eberlm@66456
   546
    fix n assume "u n = ereal(real_of_ereal(u n))" "v n = ereal(real_of_ereal(v n))"
eberlm@66456
   547
    then have "ereal(real_of_ereal(u n) * real_of_ereal(v n)) = u n * v n" by (metis times_ereal.simps(1))
eberlm@66456
   548
  }
eberlm@66456
   549
  then have *: "eventually (\<lambda>n. ereal(real_of_ereal(u n) * real_of_ereal(v n)) = u n * v n) F"
eberlm@66456
   550
    using eventually_elim2[OF ureal vreal] by auto
eberlm@66456
   551
eberlm@66456
   552
  have "((\<lambda>n. real_of_ereal(u n) * real_of_ereal(v n)) \<longlongrightarrow> l * m) F" using tendsto_mult[OF limu limv] by auto
eberlm@66456
   553
  then have "((\<lambda>n. ereal(real_of_ereal(u n)) * real_of_ereal(v n)) \<longlongrightarrow> ereal(l * m)) F" by auto
eberlm@66456
   554
  then show ?thesis using * filterlim_cong by fastforce
eberlm@66456
   555
qed
eberlm@66456
   556
ak2110@69221
   557
lemma%important tendsto_mult_ereal_PInf:
eberlm@66456
   558
  fixes f g::"_ \<Rightarrow> ereal"
eberlm@66456
   559
  assumes "(f \<longlongrightarrow> l) F" "l>0" "(g \<longlongrightarrow> \<infinity>) F"
eberlm@66456
   560
  shows "((\<lambda>x. f x * g x) \<longlongrightarrow> \<infinity>) F"
ak2110@69221
   561
proof%unimportant -
eberlm@66456
   562
  obtain a::real where "0 < ereal a" "a < l" using assms(2) using ereal_dense2 by blast
eberlm@66456
   563
  have *: "eventually (\<lambda>x. f x > a) F" using \<open>a < l\<close> assms(1) by (simp add: order_tendsto_iff)
eberlm@66456
   564
  {
eberlm@66456
   565
    fix K::real
eberlm@66456
   566
    define M where "M = max K 1"
eberlm@66456
   567
    then have "M > 0" by simp
eberlm@66456
   568
    then have "ereal(M/a) > 0" using \<open>ereal a > 0\<close> by simp
eberlm@66456
   569
    then have "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > ereal a * ereal(M/a))"
eberlm@66456
   570
      using ereal_mult_mono_strict'[where ?c = "M/a", OF \<open>0 < ereal a\<close>] by auto
eberlm@66456
   571
    moreover have "ereal a * ereal(M/a) = M" using \<open>ereal a > 0\<close> by simp
eberlm@66456
   572
    ultimately have "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > M)" by simp
eberlm@66456
   573
    moreover have "M \<ge> K" unfolding M_def by simp
eberlm@66456
   574
    ultimately have Imp: "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > K)"
eberlm@66456
   575
      using ereal_less_eq(3) le_less_trans by blast
eberlm@66456
   576
eberlm@66456
   577
    have "eventually (\<lambda>x. g x > M/a) F" using assms(3) by (simp add: tendsto_PInfty)
eberlm@66456
   578
    then have "eventually (\<lambda>x. (f x > a) \<and> (g x > M/a)) F"
eberlm@66456
   579
      using * by (auto simp add: eventually_conj_iff)
eberlm@66456
   580
    then have "eventually (\<lambda>x. f x * g x > K) F" using eventually_mono Imp by force
eberlm@66456
   581
  }
eberlm@66456
   582
  then show ?thesis by (auto simp add: tendsto_PInfty)
eberlm@66456
   583
qed
eberlm@66456
   584
ak2110@69221
   585
lemma%important tendsto_mult_ereal_pos:
eberlm@66456
   586
  fixes f g::"_ \<Rightarrow> ereal"
eberlm@66456
   587
  assumes "(f \<longlongrightarrow> l) F" "(g \<longlongrightarrow> m) F" "l>0" "m>0"
eberlm@66456
   588
  shows "((\<lambda>x. f x * g x) \<longlongrightarrow> l * m) F"
ak2110@69221
   589
proof%unimportant (cases)
eberlm@66456
   590
  assume *: "l = \<infinity> \<or> m = \<infinity>"
eberlm@66456
   591
  then show ?thesis
eberlm@66456
   592
  proof (cases)
eberlm@66456
   593
    assume "m = \<infinity>"
eberlm@66456
   594
    then show ?thesis using tendsto_mult_ereal_PInf assms by auto
eberlm@66456
   595
  next
eberlm@66456
   596
    assume "\<not>(m = \<infinity>)"
eberlm@66456
   597
    then have "l = \<infinity>" using * by simp
eberlm@66456
   598
    then have "((\<lambda>x. g x * f x) \<longlongrightarrow> l * m) F" using tendsto_mult_ereal_PInf assms by auto
eberlm@66456
   599
    moreover have "\<And>x. g x * f x = f x * g x" using mult.commute by auto
eberlm@66456
   600
    ultimately show ?thesis by simp
eberlm@66456
   601
  qed
eberlm@66456
   602
next
eberlm@66456
   603
  assume "\<not>(l = \<infinity> \<or> m = \<infinity>)"
eberlm@66456
   604
  then have "l < \<infinity>" "m < \<infinity>" by auto
eberlm@66456
   605
  then obtain lr mr where "l = ereal lr" "m = ereal mr"
eberlm@66456
   606
    using \<open>l>0\<close> \<open>m>0\<close> by (metis ereal_cases ereal_less(6) not_less_iff_gr_or_eq)
eberlm@66456
   607
  then show ?thesis using tendsto_mult_real_ereal assms by auto
eberlm@66456
   608
qed
eberlm@66456
   609
eberlm@66456
   610
text \<open>We reduce the general situation to the positive case by multiplying by suitable signs.
eberlm@66456
   611
Unfortunately, as ereal is not a ring, all the neat sign lemmas are not available there. We
eberlm@66456
   612
give the bare minimum we need.\<close>
eberlm@66456
   613
eberlm@66456
   614
lemma ereal_sgn_abs:
eberlm@66456
   615
  fixes l::ereal
eberlm@66456
   616
  shows "sgn(l) * l = abs(l)"
eberlm@66456
   617
apply (cases l) by (auto simp add: sgn_if ereal_less_uminus_reorder)
eberlm@66456
   618
eberlm@66456
   619
lemma sgn_squared_ereal:
eberlm@66456
   620
  assumes "l \<noteq> (0::ereal)"
eberlm@66456
   621
  shows "sgn(l) * sgn(l) = 1"
eberlm@66456
   622
apply (cases l) using assms by (auto simp add: one_ereal_def sgn_if)
eberlm@66456
   623
ak2110@69221
   624
lemma%important tendsto_mult_ereal [tendsto_intros]:
eberlm@66456
   625
  fixes f g::"_ \<Rightarrow> ereal"
eberlm@66456
   626
  assumes "(f \<longlongrightarrow> l) F" "(g \<longlongrightarrow> m) F" "\<not>((l=0 \<and> abs(m) = \<infinity>) \<or> (m=0 \<and> abs(l) = \<infinity>))"
eberlm@66456
   627
  shows "((\<lambda>x. f x * g x) \<longlongrightarrow> l * m) F"
ak2110@69221
   628
proof%unimportant (cases)
eberlm@66456
   629
  assume "l=0 \<or> m=0"
eberlm@66456
   630
  then have "abs(l) \<noteq> \<infinity>" "abs(m) \<noteq> \<infinity>" using assms(3) by auto
eberlm@66456
   631
  then obtain lr mr where "l = ereal lr" "m = ereal mr" by auto
eberlm@66456
   632
  then show ?thesis using tendsto_mult_real_ereal assms by auto
eberlm@66456
   633
next
eberlm@66456
   634
  have sgn_finite: "\<And>a::ereal. abs(sgn a) \<noteq> \<infinity>"
eberlm@66456
   635
    by (metis MInfty_neq_ereal(2) PInfty_neq_ereal(2) abs_eq_infinity_cases ereal_times(1) ereal_times(3) ereal_uminus_eq_reorder sgn_ereal.elims)
eberlm@66456
   636
  then have sgn_finite2: "\<And>a b::ereal. abs(sgn a * sgn b) \<noteq> \<infinity>"
eberlm@66456
   637
    by (metis abs_eq_infinity_cases abs_ereal.simps(2) abs_ereal.simps(3) ereal_mult_eq_MInfty ereal_mult_eq_PInfty)
eberlm@66456
   638
  assume "\<not>(l=0 \<or> m=0)"
eberlm@66456
   639
  then have "l \<noteq> 0" "m \<noteq> 0" by auto
eberlm@66456
   640
  then have "abs(l) > 0" "abs(m) > 0"
eberlm@66456
   641
    by (metis abs_ereal_ge0 abs_ereal_less0 abs_ereal_pos ereal_uminus_uminus ereal_uminus_zero less_le not_less)+
eberlm@66456
   642
  then have "sgn(l) * l > 0" "sgn(m) * m > 0" using ereal_sgn_abs by auto
eberlm@66456
   643
  moreover have "((\<lambda>x. sgn(l) * f x) \<longlongrightarrow> (sgn(l) * l)) F"
eberlm@66456
   644
    by (rule tendsto_cmult_ereal, auto simp add: sgn_finite assms(1))
eberlm@66456
   645
  moreover have "((\<lambda>x. sgn(m) * g x) \<longlongrightarrow> (sgn(m) * m)) F"
eberlm@66456
   646
    by (rule tendsto_cmult_ereal, auto simp add: sgn_finite assms(2))
eberlm@66456
   647
  ultimately have *: "((\<lambda>x. (sgn(l) * f x) * (sgn(m) * g x)) \<longlongrightarrow> (sgn(l) * l) * (sgn(m) * m)) F"
eberlm@66456
   648
    using tendsto_mult_ereal_pos by force
eberlm@66456
   649
  have "((\<lambda>x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x))) \<longlongrightarrow> (sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m))) F"
eberlm@66456
   650
    by (rule tendsto_cmult_ereal, auto simp add: sgn_finite2 *)
eberlm@66456
   651
  moreover have "\<And>x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x)) = f x * g x"
eberlm@66456
   652
    by (metis mult.left_neutral sgn_squared_ereal[OF \<open>l \<noteq> 0\<close>] sgn_squared_ereal[OF \<open>m \<noteq> 0\<close>] mult.assoc mult.commute)
eberlm@66456
   653
  moreover have "(sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m)) = l * m"
eberlm@66456
   654
    by (metis mult.left_neutral sgn_squared_ereal[OF \<open>l \<noteq> 0\<close>] sgn_squared_ereal[OF \<open>m \<noteq> 0\<close>] mult.assoc mult.commute)
eberlm@66456
   655
  ultimately show ?thesis by auto
eberlm@66456
   656
qed
eberlm@66456
   657
eberlm@66456
   658
lemma tendsto_cmult_ereal_general [tendsto_intros]:
eberlm@66456
   659
  fixes f::"_ \<Rightarrow> ereal" and c::ereal
eberlm@66456
   660
  assumes "(f \<longlongrightarrow> l) F" "\<not> (l=0 \<and> abs(c) = \<infinity>)"
eberlm@66456
   661
  shows "((\<lambda>x. c * f x) \<longlongrightarrow> c * l) F"
eberlm@66456
   662
by (cases "c = 0", auto simp add: assms tendsto_mult_ereal)
eberlm@66456
   663
eberlm@66456
   664
ak2110@69221
   665
subsubsection%important \<open>Continuity of division\<close>
eberlm@66456
   666
ak2110@69221
   667
lemma%important tendsto_inverse_ereal_PInf:
eberlm@66456
   668
  fixes u::"_ \<Rightarrow> ereal"
eberlm@66456
   669
  assumes "(u \<longlongrightarrow> \<infinity>) F"
eberlm@66456
   670
  shows "((\<lambda>x. 1/ u x) \<longlongrightarrow> 0) F"
ak2110@69221
   671
proof%unimportant -
eberlm@66456
   672
  {
eberlm@66456
   673
    fix e::real assume "e>0"
eberlm@66456
   674
    have "1/e < \<infinity>" by auto
eberlm@66456
   675
    then have "eventually (\<lambda>n. u n > 1/e) F" using assms(1) by (simp add: tendsto_PInfty)
eberlm@66456
   676
    moreover
eberlm@66456
   677
    {
eberlm@66456
   678
      fix z::ereal assume "z>1/e"
eberlm@66456
   679
      then have "z>0" using \<open>e>0\<close> using less_le_trans not_le by fastforce
eberlm@66456
   680
      then have "1/z \<ge> 0" by auto
eberlm@66456
   681
      moreover have "1/z < e" using \<open>e>0\<close> \<open>z>1/e\<close>
eberlm@66456
   682
        apply (cases z) apply auto
eberlm@66456
   683
        by (metis (mono_tags, hide_lams) less_ereal.simps(2) less_ereal.simps(4) divide_less_eq ereal_divide_less_pos ereal_less(4)
eberlm@66456
   684
            ereal_less_eq(4) less_le_trans mult_eq_0_iff not_le not_one_less_zero times_ereal.simps(1))
eberlm@66456
   685
      ultimately have "1/z \<ge> 0" "1/z < e" by auto
eberlm@66456
   686
    }
eberlm@66456
   687
    ultimately have "eventually (\<lambda>n. 1/u n<e) F" "eventually (\<lambda>n. 1/u n\<ge>0) F" by (auto simp add: eventually_mono)
eberlm@66456
   688
  } note * = this
eberlm@66456
   689
  show ?thesis
eberlm@66456
   690
  proof (subst order_tendsto_iff, auto)
eberlm@66456
   691
    fix a::ereal assume "a<0"
eberlm@66456
   692
    then show "eventually (\<lambda>n. 1/u n > a) F" using *(2) eventually_mono less_le_trans linordered_field_no_ub by fastforce
eberlm@66456
   693
  next
eberlm@66456
   694
    fix a::ereal assume "a>0"
eberlm@66456
   695
    then obtain e::real where "e>0" "a>e" using ereal_dense2 ereal_less(2) by blast
eberlm@66456
   696
    then have "eventually (\<lambda>n. 1/u n < e) F" using *(1) by auto
eberlm@66456
   697
    then show "eventually (\<lambda>n. 1/u n < a) F" using \<open>a>e\<close> by (metis (mono_tags, lifting) eventually_mono less_trans)
eberlm@66456
   698
  qed
eberlm@66456
   699
qed
eberlm@66456
   700
eberlm@66456
   701
text \<open>The next lemma deserves to exist by itself, as it is so common and useful.\<close>
eberlm@66456
   702
eberlm@66456
   703
lemma tendsto_inverse_real [tendsto_intros]:
eberlm@66456
   704
  fixes u::"_ \<Rightarrow> real"
eberlm@66456
   705
  shows "(u \<longlongrightarrow> l) F \<Longrightarrow> l \<noteq> 0 \<Longrightarrow> ((\<lambda>x. 1/ u x) \<longlongrightarrow> 1/l) F"
eberlm@66456
   706
  using tendsto_inverse unfolding inverse_eq_divide .
eberlm@66456
   707
ak2110@69221
   708
lemma%important tendsto_inverse_ereal [tendsto_intros]:
eberlm@66456
   709
  fixes u::"_ \<Rightarrow> ereal"
eberlm@66456
   710
  assumes "(u \<longlongrightarrow> l) F" "l \<noteq> 0"
eberlm@66456
   711
  shows "((\<lambda>x. 1/ u x) \<longlongrightarrow> 1/l) F"
ak2110@69221
   712
proof%unimportant (cases l)
eberlm@66456
   713
  case (real r)
eberlm@66456
   714
  then have "r \<noteq> 0" using assms(2) by auto
eberlm@66456
   715
  then have "1/l = ereal(1/r)" using real by (simp add: one_ereal_def)
eberlm@66456
   716
  define v where "v = (\<lambda>n. real_of_ereal(u n))"
eberlm@66456
   717
  have ureal: "eventually (\<lambda>n. u n = ereal(v n)) F" unfolding v_def using real_lim_then_eventually_real assms(1) real by auto
eberlm@66456
   718
  then have "((\<lambda>n. ereal(v n)) \<longlongrightarrow> ereal r) F" using assms real v_def by auto
eberlm@66456
   719
  then have *: "((\<lambda>n. v n) \<longlongrightarrow> r) F" by auto
eberlm@66456
   720
  then have "((\<lambda>n. 1/v n) \<longlongrightarrow> 1/r) F" using \<open>r \<noteq> 0\<close> tendsto_inverse_real by auto
eberlm@66456
   721
  then have lim: "((\<lambda>n. ereal(1/v n)) \<longlongrightarrow> 1/l) F" using \<open>1/l = ereal(1/r)\<close> by auto
eberlm@66456
   722
eberlm@66456
   723
  have "r \<in> -{0}" "open (-{(0::real)})" using \<open>r \<noteq> 0\<close> by auto
eberlm@66456
   724
  then have "eventually (\<lambda>n. v n \<in> -{0}) F" using * using topological_tendstoD by blast
eberlm@66456
   725
  then have "eventually (\<lambda>n. v n \<noteq> 0) F" by auto
eberlm@66456
   726
  moreover
eberlm@66456
   727
  {
eberlm@66456
   728
    fix n assume H: "v n \<noteq> 0" "u n = ereal(v n)"
eberlm@66456
   729
    then have "ereal(1/v n) = 1/ereal(v n)" by (simp add: one_ereal_def)
eberlm@66456
   730
    then have "ereal(1/v n) = 1/u n" using H(2) by simp
eberlm@66456
   731
  }
eberlm@66456
   732
  ultimately have "eventually (\<lambda>n. ereal(1/v n) = 1/u n) F" using ureal eventually_elim2 by force
eberlm@66456
   733
  with Lim_transform_eventually[OF this lim] show ?thesis by simp
eberlm@66456
   734
next
eberlm@66456
   735
  case (PInf)
eberlm@66456
   736
  then have "1/l = 0" by auto
eberlm@66456
   737
  then show ?thesis using tendsto_inverse_ereal_PInf assms PInf by auto
eberlm@66456
   738
next
eberlm@66456
   739
  case (MInf)
eberlm@66456
   740
  then have "1/l = 0" by auto
eberlm@66456
   741
  have "1/z = -1/ -z" if "z < 0" for z::ereal
eberlm@66456
   742
    apply (cases z) using divide_ereal_def \<open> z < 0 \<close> by auto
eberlm@66456
   743
  moreover have "eventually (\<lambda>n. u n < 0) F" by (metis (no_types) MInf assms(1) tendsto_MInfty zero_ereal_def)
eberlm@66456
   744
  ultimately have *: "eventually (\<lambda>n. -1/-u n = 1/u n) F" by (simp add: eventually_mono)
eberlm@66456
   745
eberlm@66456
   746
  define v where "v = (\<lambda>n. - u n)"
eberlm@66456
   747
  have "(v \<longlongrightarrow> \<infinity>) F" unfolding v_def using MInf assms(1) tendsto_uminus_ereal by fastforce
eberlm@66456
   748
  then have "((\<lambda>n. 1/v n) \<longlongrightarrow> 0) F" using tendsto_inverse_ereal_PInf by auto
eberlm@66456
   749
  then have "((\<lambda>n. -1/v n) \<longlongrightarrow> 0) F" using tendsto_uminus_ereal by fastforce
eberlm@66456
   750
  then show ?thesis unfolding v_def using Lim_transform_eventually[OF *] \<open> 1/l = 0 \<close> by auto
eberlm@66456
   751
qed
eberlm@66456
   752
ak2110@69221
   753
lemma%important tendsto_divide_ereal [tendsto_intros]:
eberlm@66456
   754
  fixes f g::"_ \<Rightarrow> ereal"
eberlm@66456
   755
  assumes "(f \<longlongrightarrow> l) F" "(g \<longlongrightarrow> m) F" "m \<noteq> 0" "\<not>(abs(l) = \<infinity> \<and> abs(m) = \<infinity>)"
eberlm@66456
   756
  shows "((\<lambda>x. f x / g x) \<longlongrightarrow> l / m) F"
ak2110@69221
   757
proof%unimportant -
eberlm@66456
   758
  define h where "h = (\<lambda>x. 1/ g x)"
eberlm@66456
   759
  have *: "(h \<longlongrightarrow> 1/m) F" unfolding h_def using assms(2) assms(3) tendsto_inverse_ereal by auto
eberlm@66456
   760
  have "((\<lambda>x. f x * h x) \<longlongrightarrow> l * (1/m)) F"
eberlm@66456
   761
    apply (rule tendsto_mult_ereal[OF assms(1) *]) using assms(3) assms(4) by (auto simp add: divide_ereal_def)
eberlm@66456
   762
  moreover have "f x * h x = f x / g x" for x unfolding h_def by (simp add: divide_ereal_def)
eberlm@66456
   763
  moreover have "l * (1/m) = l/m" by (simp add: divide_ereal_def)
eberlm@66456
   764
  ultimately show ?thesis unfolding h_def using Lim_transform_eventually by auto
eberlm@66456
   765
qed
eberlm@66456
   766
eberlm@66456
   767
ak2110@69221
   768
subsubsection%important \<open>Further limits\<close>
eberlm@66456
   769
immler@67727
   770
text \<open>The assumptions of @{thm tendsto_diff_ereal} are too strong, we weaken them here.\<close>
immler@67727
   771
ak2110@69221
   772
lemma%important tendsto_diff_ereal_general [tendsto_intros]:
immler@67727
   773
  fixes u v::"'a \<Rightarrow> ereal"
immler@67727
   774
  assumes "(u \<longlongrightarrow> l) F" "(v \<longlongrightarrow> m) F" "\<not>((l = \<infinity> \<and> m = \<infinity>) \<or> (l = -\<infinity> \<and> m = -\<infinity>))"
immler@67727
   775
  shows "((\<lambda>n. u n - v n) \<longlongrightarrow> l - m) F"
ak2110@69221
   776
proof%unimportant -
immler@67727
   777
  have "((\<lambda>n. u n + (-v n)) \<longlongrightarrow> l + (-m)) F"
immler@67727
   778
    apply (intro tendsto_intros assms) using assms by (auto simp add: ereal_uminus_eq_reorder)
immler@67727
   779
  then show ?thesis by (simp add: minus_ereal_def)
immler@67727
   780
qed
immler@67727
   781
eberlm@66456
   782
lemma id_nat_ereal_tendsto_PInf [tendsto_intros]:
eberlm@66456
   783
  "(\<lambda> n::nat. real n) \<longlonglongrightarrow> \<infinity>"
eberlm@66456
   784
by (simp add: filterlim_real_sequentially tendsto_PInfty_eq_at_top)
eberlm@66456
   785
ak2110@69221
   786
lemma%important tendsto_at_top_pseudo_inverse [tendsto_intros]:
eberlm@66456
   787
  fixes u::"nat \<Rightarrow> nat"
eberlm@66456
   788
  assumes "LIM n sequentially. u n :> at_top"
eberlm@66456
   789
  shows "LIM n sequentially. Inf {N. u N \<ge> n} :> at_top"
ak2110@69221
   790
proof%unimportant -
eberlm@66456
   791
  {
eberlm@66456
   792
    fix C::nat
eberlm@66456
   793
    define M where "M = Max {u n| n. n \<le> C}+1"
eberlm@66456
   794
    {
eberlm@66456
   795
      fix n assume "n \<ge> M"
eberlm@66456
   796
      have "eventually (\<lambda>N. u N \<ge> n) sequentially" using assms
eberlm@66456
   797
        by (simp add: filterlim_at_top)
eberlm@66456
   798
      then have *: "{N. u N \<ge> n} \<noteq> {}" by force
eberlm@66456
   799
eberlm@66456
   800
      have "N > C" if "u N \<ge> n" for N
eberlm@66456
   801
      proof (rule ccontr)
eberlm@66456
   802
        assume "\<not>(N > C)"
eberlm@66456
   803
        have "u N \<le> Max {u n| n. n \<le> C}"
eberlm@66456
   804
          apply (rule Max_ge) using \<open>\<not>(N > C)\<close> by auto
eberlm@66456
   805
        then show False using \<open>u N \<ge> n\<close> \<open>n \<ge> M\<close> unfolding M_def by auto
eberlm@66456
   806
      qed
eberlm@66456
   807
      then have **: "{N. u N \<ge> n} \<subseteq> {C..}" by fastforce
eberlm@66456
   808
      have "Inf {N. u N \<ge> n} \<ge> C"
eberlm@66456
   809
        by (metis "*" "**" Inf_nat_def1 atLeast_iff subset_eq)
eberlm@66456
   810
    }
eberlm@66456
   811
    then have "eventually (\<lambda>n. Inf {N. u N \<ge> n} \<ge> C) sequentially"
eberlm@66456
   812
      using eventually_sequentially by auto
eberlm@66456
   813
  }
eberlm@66456
   814
  then show ?thesis using filterlim_at_top by auto
eberlm@66456
   815
qed
eberlm@66456
   816
ak2110@69221
   817
lemma%important pseudo_inverse_finite_set:
eberlm@66456
   818
  fixes u::"nat \<Rightarrow> nat"
eberlm@66456
   819
  assumes "LIM n sequentially. u n :> at_top"
eberlm@66456
   820
  shows "finite {N. u N \<le> n}"
ak2110@69221
   821
proof%unimportant -
eberlm@66456
   822
  fix n
eberlm@66456
   823
  have "eventually (\<lambda>N. u N \<ge> n+1) sequentially" using assms
eberlm@66456
   824
    by (simp add: filterlim_at_top)
eberlm@66456
   825
  then obtain N1 where N1: "\<And>N. N \<ge> N1 \<Longrightarrow> u N \<ge> n + 1"
eberlm@66456
   826
    using eventually_sequentially by auto
eberlm@66456
   827
  have "{N. u N \<le> n} \<subseteq> {..<N1}"
eberlm@66456
   828
    apply auto using N1 by (metis Suc_eq_plus1 not_less not_less_eq_eq)
eberlm@66456
   829
  then show "finite {N. u N \<le> n}" by (simp add: finite_subset)
eberlm@66456
   830
qed
eberlm@66456
   831
eberlm@66456
   832
lemma tendsto_at_top_pseudo_inverse2 [tendsto_intros]:
eberlm@66456
   833
  fixes u::"nat \<Rightarrow> nat"
eberlm@66456
   834
  assumes "LIM n sequentially. u n :> at_top"
eberlm@66456
   835
  shows "LIM n sequentially. Max {N. u N \<le> n} :> at_top"
eberlm@66456
   836
proof -
eberlm@66456
   837
  {
eberlm@66456
   838
    fix N0::nat
eberlm@66456
   839
    have "N0 \<le> Max {N. u N \<le> n}" if "n \<ge> u N0" for n
eberlm@66456
   840
      apply (rule Max.coboundedI) using pseudo_inverse_finite_set[OF assms] that by auto
eberlm@66456
   841
    then have "eventually (\<lambda>n. N0 \<le> Max {N. u N \<le> n}) sequentially"
eberlm@66456
   842
      using eventually_sequentially by blast
eberlm@66456
   843
  }
eberlm@66456
   844
  then show ?thesis using filterlim_at_top by auto
eberlm@66456
   845
qed
eberlm@66456
   846
eberlm@66456
   847
lemma ereal_truncation_top [tendsto_intros]:
eberlm@66456
   848
  fixes x::ereal
eberlm@66456
   849
  shows "(\<lambda>n::nat. min x n) \<longlonglongrightarrow> x"
eberlm@66456
   850
proof (cases x)
eberlm@66456
   851
  case (real r)
eberlm@66456
   852
  then obtain K::nat where "K>0" "K > abs(r)" using reals_Archimedean2 gr0I by auto
eberlm@66456
   853
  then have "min x n = x" if "n \<ge> K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce
eberlm@66456
   854
  then have "eventually (\<lambda>n. min x n = x) sequentially" using eventually_at_top_linorder by blast
eberlm@66456
   855
  then show ?thesis by (simp add: Lim_eventually)
eberlm@66456
   856
next
eberlm@66456
   857
  case (PInf)
eberlm@66456
   858
  then have "min x n = n" for n::nat by (auto simp add: min_def)
eberlm@66456
   859
  then show ?thesis using id_nat_ereal_tendsto_PInf PInf by auto
eberlm@66456
   860
next
eberlm@66456
   861
  case (MInf)
eberlm@66456
   862
  then have "min x n = x" for n::nat by (auto simp add: min_def)
eberlm@66456
   863
  then show ?thesis by auto
eberlm@66456
   864
qed
eberlm@66456
   865
ak2110@69221
   866
lemma%important ereal_truncation_real_top [tendsto_intros]:
eberlm@66456
   867
  fixes x::ereal
eberlm@66456
   868
  assumes "x \<noteq> - \<infinity>"
eberlm@66456
   869
  shows "(\<lambda>n::nat. real_of_ereal(min x n)) \<longlonglongrightarrow> x"
ak2110@69221
   870
proof%unimportant (cases x)
eberlm@66456
   871
  case (real r)
eberlm@66456
   872
  then obtain K::nat where "K>0" "K > abs(r)" using reals_Archimedean2 gr0I by auto
eberlm@66456
   873
  then have "min x n = x" if "n \<ge> K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce
eberlm@66456
   874
  then have "real_of_ereal(min x n) = r" if "n \<ge> K" for n using real that by auto
eberlm@66456
   875
  then have "eventually (\<lambda>n. real_of_ereal(min x n) = r) sequentially" using eventually_at_top_linorder by blast
eberlm@66456
   876
  then have "(\<lambda>n. real_of_ereal(min x n)) \<longlonglongrightarrow> r" by (simp add: Lim_eventually)
eberlm@66456
   877
  then show ?thesis using real by auto
eberlm@66456
   878
next
eberlm@66456
   879
  case (PInf)
eberlm@66456
   880
  then have "real_of_ereal(min x n) = n" for n::nat by (auto simp add: min_def)
eberlm@66456
   881
  then show ?thesis using id_nat_ereal_tendsto_PInf PInf by auto
eberlm@66456
   882
qed (simp add: assms)
eberlm@66456
   883
ak2110@69221
   884
lemma%important ereal_truncation_bottom [tendsto_intros]:
eberlm@66456
   885
  fixes x::ereal
eberlm@66456
   886
  shows "(\<lambda>n::nat. max x (- real n)) \<longlonglongrightarrow> x"
ak2110@69221
   887
proof%unimportant (cases x)
eberlm@66456
   888
  case (real r)
eberlm@66456
   889
  then obtain K::nat where "K>0" "K > abs(r)" using reals_Archimedean2 gr0I by auto
eberlm@66456
   890
  then have "max x (-real n) = x" if "n \<ge> K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce
eberlm@66456
   891
  then have "eventually (\<lambda>n. max x (-real n) = x) sequentially" using eventually_at_top_linorder by blast
eberlm@66456
   892
  then show ?thesis by (simp add: Lim_eventually)
eberlm@66456
   893
next
eberlm@66456
   894
  case (MInf)
eberlm@66456
   895
  then have "max x (-real n) = (-1)* ereal(real n)" for n::nat by (auto simp add: max_def)
eberlm@66456
   896
  moreover have "(\<lambda>n. (-1)* ereal(real n)) \<longlonglongrightarrow> -\<infinity>"
eberlm@66456
   897
    using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def)
eberlm@66456
   898
  ultimately show ?thesis using MInf by auto
eberlm@66456
   899
next
eberlm@66456
   900
  case (PInf)
eberlm@66456
   901
  then have "max x (-real n) = x" for n::nat by (auto simp add: max_def)
eberlm@66456
   902
  then show ?thesis by auto
eberlm@66456
   903
qed
eberlm@66456
   904
ak2110@69221
   905
lemma%important ereal_truncation_real_bottom [tendsto_intros]:
eberlm@66456
   906
  fixes x::ereal
eberlm@66456
   907
  assumes "x \<noteq> \<infinity>"
eberlm@66456
   908
  shows "(\<lambda>n::nat. real_of_ereal(max x (- real n))) \<longlonglongrightarrow> x"
ak2110@69221
   909
proof%unimportant (cases x)
eberlm@66456
   910
  case (real r)
eberlm@66456
   911
  then obtain K::nat where "K>0" "K > abs(r)" using reals_Archimedean2 gr0I by auto
eberlm@66456
   912
  then have "max x (-real n) = x" if "n \<ge> K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce
eberlm@66456
   913
  then have "real_of_ereal(max x (-real n)) = r" if "n \<ge> K" for n using real that by auto
eberlm@66456
   914
  then have "eventually (\<lambda>n. real_of_ereal(max x (-real n)) = r) sequentially" using eventually_at_top_linorder by blast
eberlm@66456
   915
  then have "(\<lambda>n. real_of_ereal(max x (-real n))) \<longlonglongrightarrow> r" by (simp add: Lim_eventually)
eberlm@66456
   916
  then show ?thesis using real by auto
eberlm@66456
   917
next
eberlm@66456
   918
  case (MInf)
eberlm@66456
   919
  then have "real_of_ereal(max x (-real n)) = (-1)* ereal(real n)" for n::nat by (auto simp add: max_def)
eberlm@66456
   920
  moreover have "(\<lambda>n. (-1)* ereal(real n)) \<longlonglongrightarrow> -\<infinity>"
eberlm@66456
   921
    using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def)
eberlm@66456
   922
  ultimately show ?thesis using MInf by auto
eberlm@66456
   923
qed (simp add: assms)
eberlm@66456
   924
eberlm@66456
   925
text \<open>the next one is copied from \verb+tendsto_sum+.\<close>
eberlm@66456
   926
lemma tendsto_sum_ereal [tendsto_intros]:
eberlm@66456
   927
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> ereal"
eberlm@66456
   928
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i \<longlongrightarrow> a i) F"
eberlm@66456
   929
          "\<And>i. abs(a i) \<noteq> \<infinity>"
eberlm@66456
   930
  shows "((\<lambda>x. \<Sum>i\<in>S. f i x) \<longlongrightarrow> (\<Sum>i\<in>S. a i)) F"
eberlm@66456
   931
proof (cases "finite S")
eberlm@66456
   932
  assume "finite S" then show ?thesis using assms
eberlm@66456
   933
    by (induct, simp, simp add: tendsto_add_ereal_general2 assms)
eberlm@66456
   934
qed(simp)
eberlm@66456
   935
eberlm@66456
   936
ak2110@69221
   937
lemma%important continuous_ereal_abs:
immler@67727
   938
  "continuous_on (UNIV::ereal set) abs"
ak2110@69221
   939
proof%unimportant -
immler@67727
   940
  have "continuous_on ({..0} \<union> {(0::ereal)..}) abs"
immler@67727
   941
    apply (rule continuous_on_closed_Un, auto)
immler@67727
   942
    apply (rule iffD1[OF continuous_on_cong, of "{..0}" _ "\<lambda>x. -x"])
immler@67727
   943
    using less_eq_ereal_def apply (auto simp add: continuous_uminus_ereal)
immler@67727
   944
    apply (rule iffD1[OF continuous_on_cong, of "{0..}" _ "\<lambda>x. x"])
immler@67727
   945
      apply (auto simp add: continuous_on_id)
immler@67727
   946
    done
immler@67727
   947
  moreover have "(UNIV::ereal set) = {..0} \<union> {(0::ereal)..}" by auto
immler@67727
   948
  ultimately show ?thesis by auto
immler@67727
   949
qed
immler@67727
   950
immler@67727
   951
lemmas continuous_on_compose_ereal_abs[continuous_intros] =
immler@67727
   952
  continuous_on_compose2[OF continuous_ereal_abs _ subset_UNIV]
immler@67727
   953
immler@67727
   954
lemma tendsto_abs_ereal [tendsto_intros]:
immler@67727
   955
  assumes "(u \<longlongrightarrow> (l::ereal)) F"
immler@67727
   956
  shows "((\<lambda>n. abs(u n)) \<longlongrightarrow> abs l) F"
immler@67727
   957
using continuous_ereal_abs assms by (metis UNIV_I continuous_on tendsto_compose)
immler@67727
   958
immler@67727
   959
lemma ereal_minus_real_tendsto_MInf [tendsto_intros]:
immler@67727
   960
  "(\<lambda>x. ereal (- real x)) \<longlonglongrightarrow> - \<infinity>"
immler@67727
   961
by (subst uminus_ereal.simps(1)[symmetric], intro tendsto_intros)
immler@67727
   962
immler@67727
   963
ak2110@69221
   964
subsection%important \<open>Extended-Nonnegative-Real.thy\<close> (*FIX title *)
immler@67727
   965
immler@67727
   966
lemma tendsto_diff_ennreal_general [tendsto_intros]:
immler@67727
   967
  fixes u v::"'a \<Rightarrow> ennreal"
immler@67727
   968
  assumes "(u \<longlongrightarrow> l) F" "(v \<longlongrightarrow> m) F" "\<not>(l = \<infinity> \<and> m = \<infinity>)"
immler@67727
   969
  shows "((\<lambda>n. u n - v n) \<longlongrightarrow> l - m) F"
immler@67727
   970
proof -
immler@67727
   971
  have "((\<lambda>n. e2ennreal(enn2ereal(u n) - enn2ereal(v n))) \<longlongrightarrow> e2ennreal(enn2ereal l - enn2ereal m)) F"
immler@67727
   972
    apply (intro tendsto_intros) using assms by  auto
immler@67727
   973
  then show ?thesis by auto
immler@67727
   974
qed
immler@67727
   975
ak2110@69221
   976
lemma%important tendsto_mult_ennreal [tendsto_intros]:
immler@67727
   977
  fixes l m::ennreal
immler@67727
   978
  assumes "(u \<longlongrightarrow> l) F" "(v \<longlongrightarrow> m) F" "\<not>((l = 0 \<and> m = \<infinity>) \<or> (l = \<infinity> \<and> m = 0))"
immler@67727
   979
  shows "((\<lambda>n. u n * v n) \<longlongrightarrow> l * m) F"
ak2110@69221
   980
proof%unimportant -
immler@67727
   981
  have "((\<lambda>n. e2ennreal(enn2ereal (u n) * enn2ereal (v n))) \<longlongrightarrow> e2ennreal(enn2ereal l * enn2ereal m)) F"
immler@67727
   982
    apply (intro tendsto_intros) using assms apply auto
immler@67727
   983
    using enn2ereal_inject zero_ennreal.rep_eq by fastforce+
immler@67727
   984
  moreover have "e2ennreal(enn2ereal (u n) * enn2ereal (v n)) = u n * v n" for n
immler@67727
   985
    by (subst times_ennreal.abs_eq[symmetric], auto simp add: eq_onp_same_args)
immler@67727
   986
  moreover have "e2ennreal(enn2ereal l * enn2ereal m)  = l * m"
immler@67727
   987
    by (subst times_ennreal.abs_eq[symmetric], auto simp add: eq_onp_same_args)
immler@67727
   988
  ultimately show ?thesis
immler@67727
   989
    by auto
immler@67727
   990
qed
immler@67727
   991
immler@67727
   992
ak2110@69221
   993
subsection%important \<open>monoset\<close>
hoelzl@51340
   994
ak2110@69221
   995
definition%important (in order) mono_set:
hoelzl@51340
   996
  "mono_set S \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> x \<in> S \<longrightarrow> y \<in> S)"
hoelzl@51340
   997
hoelzl@51340
   998
lemma (in order) mono_greaterThan [intro, simp]: "mono_set {B<..}" unfolding mono_set by auto
hoelzl@51340
   999
lemma (in order) mono_atLeast [intro, simp]: "mono_set {B..}" unfolding mono_set by auto
hoelzl@51340
  1000
lemma (in order) mono_UNIV [intro, simp]: "mono_set UNIV" unfolding mono_set by auto
hoelzl@51340
  1001
lemma (in order) mono_empty [intro, simp]: "mono_set {}" unfolding mono_set by auto
hoelzl@51340
  1002
ak2110@69221
  1003
lemma%important (in complete_linorder) mono_set_iff:
hoelzl@51340
  1004
  fixes S :: "'a set"
hoelzl@51340
  1005
  defines "a \<equiv> Inf S"
wenzelm@53788
  1006
  shows "mono_set S \<longleftrightarrow> S = {a <..} \<or> S = {a..}" (is "_ = ?c")
ak2110@69221
  1007
proof%unimportant
hoelzl@51340
  1008
  assume "mono_set S"
wenzelm@53788
  1009
  then have mono: "\<And>x y. x \<le> y \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S"
wenzelm@53788
  1010
    by (auto simp: mono_set)
hoelzl@51340
  1011
  show ?c
hoelzl@51340
  1012
  proof cases
hoelzl@51340
  1013
    assume "a \<in> S"
hoelzl@51340
  1014
    show ?c
wenzelm@60420
  1015
      using mono[OF _ \<open>a \<in> S\<close>]
hoelzl@51340
  1016
      by (auto intro: Inf_lower simp: a_def)
hoelzl@51340
  1017
  next
hoelzl@51340
  1018
    assume "a \<notin> S"
hoelzl@51340
  1019
    have "S = {a <..}"
hoelzl@51340
  1020
    proof safe
hoelzl@51340
  1021
      fix x assume "x \<in> S"
wenzelm@53788
  1022
      then have "a \<le> x"
wenzelm@53788
  1023
        unfolding a_def by (rule Inf_lower)
wenzelm@53788
  1024
      then show "a < x"
wenzelm@60420
  1025
        using \<open>x \<in> S\<close> \<open>a \<notin> S\<close> by (cases "a = x") auto
hoelzl@51340
  1026
    next
hoelzl@51340
  1027
      fix x assume "a < x"
wenzelm@53788
  1028
      then obtain y where "y < x" "y \<in> S"
wenzelm@53788
  1029
        unfolding a_def Inf_less_iff ..
wenzelm@53788
  1030
      with mono[of y x] show "x \<in> S"
wenzelm@53788
  1031
        by auto
hoelzl@51340
  1032
    qed
hoelzl@51340
  1033
    then show ?c ..
hoelzl@51340
  1034
  qed
hoelzl@51340
  1035
qed auto
hoelzl@51340
  1036
hoelzl@51340
  1037
lemma ereal_open_mono_set:
hoelzl@51340
  1038
  fixes S :: "ereal set"
wenzelm@53788
  1039
  shows "open S \<and> mono_set S \<longleftrightarrow> S = UNIV \<or> S = {Inf S <..}"
hoelzl@51340
  1040
  by (metis Inf_UNIV atLeast_eq_UNIV_iff ereal_open_atLeast
hoelzl@51340
  1041
    ereal_open_closed mono_set_iff open_ereal_greaterThan)
hoelzl@51340
  1042
hoelzl@51340
  1043
lemma ereal_closed_mono_set:
hoelzl@51340
  1044
  fixes S :: "ereal set"
wenzelm@53788
  1045
  shows "closed S \<and> mono_set S \<longleftrightarrow> S = {} \<or> S = {Inf S ..}"
hoelzl@51340
  1046
  by (metis Inf_UNIV atLeast_eq_UNIV_iff closed_ereal_atLeast
hoelzl@51340
  1047
    ereal_open_closed mono_empty mono_set_iff open_ereal_greaterThan)
hoelzl@51340
  1048
ak2110@69221
  1049
lemma%important ereal_Liminf_Sup_monoset:
wenzelm@53788
  1050
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@51340
  1051
  shows "Liminf net f =
hoelzl@51340
  1052
    Sup {l. \<forall>S. open S \<longrightarrow> mono_set S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net}"
hoelzl@51340
  1053
    (is "_ = Sup ?A")
ak2110@69221
  1054
proof%unimportant (safe intro!: Liminf_eqI complete_lattice_class.Sup_upper complete_lattice_class.Sup_least)
wenzelm@53788
  1055
  fix P
wenzelm@53788
  1056
  assume P: "eventually P net"
wenzelm@53788
  1057
  fix S
haftmann@69313
  1058
  assume S: "mono_set S" "Inf (f ` (Collect P)) \<in> S"
wenzelm@53788
  1059
  {
wenzelm@53788
  1060
    fix x
wenzelm@53788
  1061
    assume "P x"
haftmann@69313
  1062
    then have "Inf (f ` (Collect P)) \<le> f x"
hoelzl@51340
  1063
      by (intro complete_lattice_class.INF_lower) simp
hoelzl@51340
  1064
    with S have "f x \<in> S"
wenzelm@53788
  1065
      by (simp add: mono_set)
wenzelm@53788
  1066
  }
hoelzl@51340
  1067
  with P show "eventually (\<lambda>x. f x \<in> S) net"
lp15@61810
  1068
    by (auto elim: eventually_mono)
hoelzl@51340
  1069
next
hoelzl@51340
  1070
  fix y l
hoelzl@51340
  1071
  assume S: "\<forall>S. open S \<longrightarrow> mono_set S \<longrightarrow> l \<in> S \<longrightarrow> eventually  (\<lambda>x. f x \<in> S) net"
haftmann@69313
  1072
  assume P: "\<forall>P. eventually P net \<longrightarrow> Inf (f ` (Collect P)) \<le> y"
hoelzl@51340
  1073
  show "l \<le> y"
hoelzl@51340
  1074
  proof (rule dense_le)
wenzelm@53788
  1075
    fix B
wenzelm@53788
  1076
    assume "B < l"
hoelzl@51340
  1077
    then have "eventually (\<lambda>x. f x \<in> {B <..}) net"
hoelzl@51340
  1078
      by (intro S[rule_format]) auto
haftmann@69313
  1079
    then have "Inf (f ` {x. B < f x}) \<le> y"
hoelzl@51340
  1080
      using P by auto
haftmann@69313
  1081
    moreover have "B \<le> Inf (f ` {x. B < f x})"
hoelzl@51340
  1082
      by (intro INF_greatest) auto
hoelzl@51340
  1083
    ultimately show "B \<le> y"
hoelzl@51340
  1084
      by simp
hoelzl@51340
  1085
  qed
hoelzl@51340
  1086
qed
hoelzl@51340
  1087
ak2110@69221
  1088
lemma%important ereal_Limsup_Inf_monoset:
wenzelm@53788
  1089
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@51340
  1090
  shows "Limsup net f =
hoelzl@51340
  1091
    Inf {l. \<forall>S. open S \<longrightarrow> mono_set (uminus ` S) \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net}"
hoelzl@51340
  1092
    (is "_ = Inf ?A")
ak2110@69221
  1093
proof%unimportant (safe intro!: Limsup_eqI complete_lattice_class.Inf_lower complete_lattice_class.Inf_greatest)
wenzelm@53788
  1094
  fix P
wenzelm@53788
  1095
  assume P: "eventually P net"
wenzelm@53788
  1096
  fix S
haftmann@69313
  1097
  assume S: "mono_set (uminus`S)" "Sup (f ` (Collect P)) \<in> S"
wenzelm@53788
  1098
  {
wenzelm@53788
  1099
    fix x
wenzelm@53788
  1100
    assume "P x"
haftmann@69313
  1101
    then have "f x \<le> Sup (f ` (Collect P))"
hoelzl@51340
  1102
      by (intro complete_lattice_class.SUP_upper) simp
haftmann@69313
  1103
    with S(1)[unfolded mono_set, rule_format, of "- Sup (f ` (Collect P))" "- f x"] S(2)
hoelzl@51340
  1104
    have "f x \<in> S"
hoelzl@51340
  1105
      by (simp add: inj_image_mem_iff) }
hoelzl@51340
  1106
  with P show "eventually (\<lambda>x. f x \<in> S) net"
lp15@61810
  1107
    by (auto elim: eventually_mono)
hoelzl@51340
  1108
next
hoelzl@51340
  1109
  fix y l
hoelzl@51340
  1110
  assume S: "\<forall>S. open S \<longrightarrow> mono_set (uminus ` S) \<longrightarrow> l \<in> S \<longrightarrow> eventually  (\<lambda>x. f x \<in> S) net"
haftmann@69313
  1111
  assume P: "\<forall>P. eventually P net \<longrightarrow> y \<le> Sup (f ` (Collect P))"
hoelzl@51340
  1112
  show "y \<le> l"
hoelzl@51340
  1113
  proof (rule dense_ge)
wenzelm@53788
  1114
    fix B
wenzelm@53788
  1115
    assume "l < B"
hoelzl@51340
  1116
    then have "eventually (\<lambda>x. f x \<in> {..< B}) net"
hoelzl@51340
  1117
      by (intro S[rule_format]) auto
haftmann@69313
  1118
    then have "y \<le> Sup (f ` {x. f x < B})"
hoelzl@51340
  1119
      using P by auto
haftmann@69313
  1120
    moreover have "Sup (f ` {x. f x < B}) \<le> B"
hoelzl@51340
  1121
      by (intro SUP_least) auto
hoelzl@51340
  1122
    ultimately show "y \<le> B"
hoelzl@51340
  1123
      by simp
hoelzl@51340
  1124
  qed
hoelzl@51340
  1125
qed
hoelzl@51340
  1126
ak2110@69221
  1127
lemma%important liminf_bounded_open:
hoelzl@51340
  1128
  fixes x :: "nat \<Rightarrow> ereal"
hoelzl@51340
  1129
  shows "x0 \<le> liminf x \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> mono_set S \<longrightarrow> x0 \<in> S \<longrightarrow> (\<exists>N. \<forall>n\<ge>N. x n \<in> S))"
hoelzl@51340
  1130
  (is "_ \<longleftrightarrow> ?P x0")
ak2110@69221
  1131
proof%unimportant
hoelzl@51340
  1132
  assume "?P x0"
hoelzl@51340
  1133
  then show "x0 \<le> liminf x"
hoelzl@51340
  1134
    unfolding ereal_Liminf_Sup_monoset eventually_sequentially
hoelzl@51340
  1135
    by (intro complete_lattice_class.Sup_upper) auto
hoelzl@51340
  1136
next
hoelzl@51340
  1137
  assume "x0 \<le> liminf x"
wenzelm@53788
  1138
  {
wenzelm@53788
  1139
    fix S :: "ereal set"
wenzelm@53788
  1140
    assume om: "open S" "mono_set S" "x0 \<in> S"
wenzelm@53788
  1141
    {
wenzelm@53788
  1142
      assume "S = UNIV"
wenzelm@53788
  1143
      then have "\<exists>N. \<forall>n\<ge>N. x n \<in> S"
wenzelm@53788
  1144
        by auto
wenzelm@53788
  1145
    }
hoelzl@51340
  1146
    moreover
wenzelm@53788
  1147
    {
wenzelm@53788
  1148
      assume "S \<noteq> UNIV"
wenzelm@53788
  1149
      then obtain B where B: "S = {B<..}"
wenzelm@53788
  1150
        using om ereal_open_mono_set by auto
wenzelm@53788
  1151
      then have "B < x0"
wenzelm@53788
  1152
        using om by auto
wenzelm@53788
  1153
      then have "\<exists>N. \<forall>n\<ge>N. x n \<in> S"
wenzelm@53788
  1154
        unfolding B
wenzelm@60420
  1155
        using \<open>x0 \<le> liminf x\<close> liminf_bounded_iff
wenzelm@53788
  1156
        by auto
hoelzl@51340
  1157
    }
wenzelm@53788
  1158
    ultimately have "\<exists>N. \<forall>n\<ge>N. x n \<in> S"
wenzelm@53788
  1159
      by auto
hoelzl@51340
  1160
  }
wenzelm@53788
  1161
  then show "?P x0"
wenzelm@53788
  1162
    by auto
hoelzl@51340
  1163
qed
hoelzl@51340
  1164
ak2110@69221
  1165
lemma%important limsup_finite_then_bounded:
eberlm@66456
  1166
  fixes u::"nat \<Rightarrow> real"
eberlm@66456
  1167
  assumes "limsup u < \<infinity>"
eberlm@66456
  1168
  shows "\<exists>C. \<forall>n. u n \<le> C"
ak2110@69221
  1169
proof%unimportant -
eberlm@66456
  1170
  obtain C where C: "limsup u < C" "C < \<infinity>" using assms ereal_dense2 by blast
eberlm@66456
  1171
  then have "C = ereal(real_of_ereal C)" using ereal_real by force
eberlm@66456
  1172
  have "eventually (\<lambda>n. u n < C) sequentially" using C(1) unfolding Limsup_def
eberlm@66456
  1173
    apply (auto simp add: INF_less_iff)
eberlm@66456
  1174
    using SUP_lessD eventually_mono by fastforce
eberlm@66456
  1175
  then obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> u n < C" using eventually_sequentially by auto
eberlm@66456
  1176
  define D where "D = max (real_of_ereal C) (Max {u n |n. n \<le> N})"
eberlm@66456
  1177
  have "\<And>n. u n \<le> D"
eberlm@66456
  1178
  proof -
eberlm@66456
  1179
    fix n show "u n \<le> D"
eberlm@66456
  1180
    proof (cases)
eberlm@66456
  1181
      assume *: "n \<le> N"
eberlm@66456
  1182
      have "u n \<le> Max {u n |n. n \<le> N}" by (rule Max_ge, auto simp add: *)
eberlm@66456
  1183
      then show "u n \<le> D" unfolding D_def by linarith
eberlm@66456
  1184
    next
eberlm@66456
  1185
      assume "\<not>(n \<le> N)"
eberlm@66456
  1186
      then have "n \<ge> N" by simp
eberlm@66456
  1187
      then have "u n < C" using N by auto
eberlm@66456
  1188
      then have "u n < real_of_ereal C" using \<open>C = ereal(real_of_ereal C)\<close> less_ereal.simps(1) by fastforce
eberlm@66456
  1189
      then show "u n \<le> D" unfolding D_def by linarith
eberlm@66456
  1190
    qed
eberlm@66456
  1191
  qed
eberlm@66456
  1192
  then show ?thesis by blast
eberlm@66456
  1193
qed
eberlm@66456
  1194
eberlm@66456
  1195
lemma liminf_finite_then_bounded_below:
eberlm@66456
  1196
  fixes u::"nat \<Rightarrow> real"
eberlm@66456
  1197
  assumes "liminf u > -\<infinity>"
eberlm@66456
  1198
  shows "\<exists>C. \<forall>n. u n \<ge> C"
eberlm@66456
  1199
proof -
eberlm@66456
  1200
  obtain C where C: "liminf u > C" "C > -\<infinity>" using assms using ereal_dense2 by blast
eberlm@66456
  1201
  then have "C = ereal(real_of_ereal C)" using ereal_real by force
eberlm@66456
  1202
  have "eventually (\<lambda>n. u n > C) sequentially" using C(1) unfolding Liminf_def
eberlm@66456
  1203
    apply (auto simp add: less_SUP_iff)
eberlm@66456
  1204
    using eventually_elim2 less_INF_D by fastforce
eberlm@66456
  1205
  then obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> u n > C" using eventually_sequentially by auto
eberlm@66456
  1206
  define D where "D = min (real_of_ereal C) (Min {u n |n. n \<le> N})"
eberlm@66456
  1207
  have "\<And>n. u n \<ge> D"
eberlm@66456
  1208
  proof -
eberlm@66456
  1209
    fix n show "u n \<ge> D"
eberlm@66456
  1210
    proof (cases)
eberlm@66456
  1211
      assume *: "n \<le> N"
eberlm@66456
  1212
      have "u n \<ge> Min {u n |n. n \<le> N}" by (rule Min_le, auto simp add: *)
eberlm@66456
  1213
      then show "u n \<ge> D" unfolding D_def by linarith
eberlm@66456
  1214
    next
eberlm@66456
  1215
      assume "\<not>(n \<le> N)"
eberlm@66456
  1216
      then have "n \<ge> N" by simp
eberlm@66456
  1217
      then have "u n > C" using N by auto
eberlm@66456
  1218
      then have "u n > real_of_ereal C" using \<open>C = ereal(real_of_ereal C)\<close> less_ereal.simps(1) by fastforce
eberlm@66456
  1219
      then show "u n \<ge> D" unfolding D_def by linarith
eberlm@66456
  1220
    qed
eberlm@66456
  1221
  qed
eberlm@66456
  1222
  then show ?thesis by blast
eberlm@66456
  1223
qed
eberlm@66456
  1224
eberlm@66456
  1225
lemma liminf_upper_bound:
eberlm@66456
  1226
  fixes u:: "nat \<Rightarrow> ereal"
eberlm@66456
  1227
  assumes "liminf u < l"
eberlm@66456
  1228
  shows "\<exists>N>k. u N < l"
eberlm@66456
  1229
by (metis assms gt_ex less_le_trans liminf_bounded_iff not_less)
eberlm@66456
  1230
eberlm@66456
  1231
lemma limsup_shift:
eberlm@66456
  1232
  "limsup (\<lambda>n. u (n+1)) = limsup u"
eberlm@66456
  1233
proof -
haftmann@69260
  1234
  have "(SUP m\<in>{n+1..}. u m) = (SUP m\<in>{n..}. u (m + 1))" for n
eberlm@66456
  1235
    apply (rule SUP_eq) using Suc_le_D by auto
haftmann@69260
  1236
  then have a: "(INF n. SUP m\<in>{n..}. u (m + 1)) = (INF n. (SUP m\<in>{n+1..}. u m))" by auto
haftmann@69260
  1237
  have b: "(INF n. (SUP m\<in>{n+1..}. u m)) = (INF n\<in>{1..}. (SUP m\<in>{n..}. u m))"
eberlm@66456
  1238
    apply (rule INF_eq) using Suc_le_D by auto
haftmann@69260
  1239
  have "(INF n\<in>{1..}. v n) = (INF n. v n)" if "decseq v" for v::"nat \<Rightarrow> 'a"
eberlm@66456
  1240
    apply (rule INF_eq) using \<open>decseq v\<close> decseq_Suc_iff by auto
haftmann@69260
  1241
  moreover have "decseq (\<lambda>n. (SUP m\<in>{n..}. u m))" by (simp add: SUP_subset_mono decseq_def)
haftmann@69260
  1242
  ultimately have c: "(INF n\<in>{1..}. (SUP m\<in>{n..}. u m)) = (INF n. (SUP m\<in>{n..}. u m))" by simp
haftmann@69313
  1243
  have "(INF n. Sup (u ` {n..})) = (INF n. SUP m\<in>{n..}. u (m + 1))" using a b c by simp
eberlm@66456
  1244
  then show ?thesis by (auto cong: limsup_INF_SUP)
eberlm@66456
  1245
qed
eberlm@66456
  1246
eberlm@66456
  1247
lemma limsup_shift_k:
eberlm@66456
  1248
  "limsup (\<lambda>n. u (n+k)) = limsup u"
eberlm@66456
  1249
proof (induction k)
eberlm@66456
  1250
  case (Suc k)
eberlm@66456
  1251
  have "limsup (\<lambda>n. u (n+k+1)) = limsup (\<lambda>n. u (n+k))" using limsup_shift[where ?u="\<lambda>n. u(n+k)"] by simp
eberlm@66456
  1252
  then show ?case using Suc.IH by simp
eberlm@66456
  1253
qed (auto)
eberlm@66456
  1254
eberlm@66456
  1255
lemma liminf_shift:
eberlm@66456
  1256
  "liminf (\<lambda>n. u (n+1)) = liminf u"
eberlm@66456
  1257
proof -
haftmann@69260
  1258
  have "(INF m\<in>{n+1..}. u m) = (INF m\<in>{n..}. u (m + 1))" for n
eberlm@66456
  1259
    apply (rule INF_eq) using Suc_le_D by (auto)
haftmann@69260
  1260
  then have a: "(SUP n. INF m\<in>{n..}. u (m + 1)) = (SUP n. (INF m\<in>{n+1..}. u m))" by auto
haftmann@69260
  1261
  have b: "(SUP n. (INF m\<in>{n+1..}. u m)) = (SUP n\<in>{1..}. (INF m\<in>{n..}. u m))"
eberlm@66456
  1262
    apply (rule SUP_eq) using Suc_le_D by (auto)
haftmann@69260
  1263
  have "(SUP n\<in>{1..}. v n) = (SUP n. v n)" if "incseq v" for v::"nat \<Rightarrow> 'a"
eberlm@66456
  1264
    apply (rule SUP_eq) using \<open>incseq v\<close> incseq_Suc_iff by auto
haftmann@69260
  1265
  moreover have "incseq (\<lambda>n. (INF m\<in>{n..}. u m))" by (simp add: INF_superset_mono mono_def)
haftmann@69260
  1266
  ultimately have c: "(SUP n\<in>{1..}. (INF m\<in>{n..}. u m)) = (SUP n. (INF m\<in>{n..}. u m))" by simp
haftmann@69313
  1267
  have "(SUP n. Inf (u ` {n..})) = (SUP n. INF m\<in>{n..}. u (m + 1))" using a b c by simp
eberlm@66456
  1268
  then show ?thesis by (auto cong: liminf_SUP_INF)
eberlm@66456
  1269
qed
eberlm@66456
  1270
eberlm@66456
  1271
lemma liminf_shift_k:
eberlm@66456
  1272
  "liminf (\<lambda>n. u (n+k)) = liminf u"
eberlm@66456
  1273
proof (induction k)
eberlm@66456
  1274
  case (Suc k)
eberlm@66456
  1275
  have "liminf (\<lambda>n. u (n+k+1)) = liminf (\<lambda>n. u (n+k))" using liminf_shift[where ?u="\<lambda>n. u(n+k)"] by simp
eberlm@66456
  1276
  then show ?case using Suc.IH by simp
eberlm@66456
  1277
qed (auto)
eberlm@66456
  1278
ak2110@69221
  1279
lemma%important Limsup_obtain:
eberlm@66456
  1280
  fixes u::"_ \<Rightarrow> 'a :: complete_linorder"
eberlm@66456
  1281
  assumes "Limsup F u > c"
eberlm@66456
  1282
  shows "\<exists>i. u i > c"
ak2110@69221
  1283
proof%unimportant -
haftmann@69260
  1284
  have "(INF P\<in>{P. eventually P F}. SUP x\<in>{x. P x}. u x) > c" using assms by (simp add: Limsup_def)
eberlm@66456
  1285
  then show ?thesis by (metis eventually_True mem_Collect_eq less_INF_D less_SUP_iff)
eberlm@66456
  1286
qed
eberlm@66456
  1287
eberlm@66456
  1288
text \<open>The next lemma is extremely useful, as it often makes it possible to reduce statements
eberlm@66456
  1289
about limsups to statements about limits.\<close>
eberlm@66456
  1290
ak2110@69221
  1291
lemma%important limsup_subseq_lim:
eberlm@66456
  1292
  fixes u::"nat \<Rightarrow> 'a :: {complete_linorder, linorder_topology}"
eberlm@66456
  1293
  shows "\<exists>r::nat\<Rightarrow>nat. strict_mono r \<and> (u o r) \<longlonglongrightarrow> limsup u"
ak2110@69221
  1294
proof%unimportant (cases)
eberlm@66456
  1295
  assume "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. u m \<le> u p"
eberlm@66456
  1296
  then have "\<exists>r. \<forall>n. (\<forall>m\<ge>r n. u m \<le> u (r n)) \<and> r n < r (Suc n)"
eberlm@66456
  1297
    by (intro dependent_nat_choice) (auto simp: conj_commute)
eberlm@66456
  1298
  then obtain r :: "nat \<Rightarrow> nat" where "strict_mono r" and mono: "\<And>n m. r n \<le> m \<Longrightarrow> u m \<le> u (r n)"
eberlm@66456
  1299
    by (auto simp: strict_mono_Suc_iff)
haftmann@69260
  1300
  define umax where "umax = (\<lambda>n. (SUP m\<in>{n..}. u m))"
eberlm@66456
  1301
  have "decseq umax" unfolding umax_def by (simp add: SUP_subset_mono antimono_def)
eberlm@66456
  1302
  then have "umax \<longlonglongrightarrow> limsup u" unfolding umax_def by (metis LIMSEQ_INF limsup_INF_SUP)
eberlm@66456
  1303
  then have *: "(umax o r) \<longlonglongrightarrow> limsup u" by (simp add: LIMSEQ_subseq_LIMSEQ \<open>strict_mono r\<close>)
eberlm@66456
  1304
  have "\<And>n. umax(r n) = u(r n)" unfolding umax_def using mono
eberlm@66456
  1305
    by (metis SUP_le_iff antisym atLeast_def mem_Collect_eq order_refl)
eberlm@66456
  1306
  then have "umax o r = u o r" unfolding o_def by simp
eberlm@66456
  1307
  then have "(u o r) \<longlonglongrightarrow> limsup u" using * by simp
eberlm@66456
  1308
  then show ?thesis using \<open>strict_mono r\<close> by blast
eberlm@66456
  1309
next
eberlm@66456
  1310
  assume "\<not> (\<forall>n. \<exists>p>n. (\<forall>m\<ge>p. u m \<le> u p))"
eberlm@66456
  1311
  then obtain N where N: "\<And>p. p > N \<Longrightarrow> \<exists>m>p. u p < u m" by (force simp: not_le le_less)
eberlm@66456
  1312
  have "\<exists>r. \<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<le> u (r (Suc n)))"
eberlm@66456
  1313
  proof (rule dependent_nat_choice)
eberlm@66456
  1314
    fix x assume "N < x"
eberlm@66456
  1315
    then have a: "finite {N<..x}" "{N<..x} \<noteq> {}" by simp_all
eberlm@66456
  1316
    have "Max {u i |i. i \<in> {N<..x}} \<in> {u i |i. i \<in> {N<..x}}" apply (rule Max_in) using a by (auto)
eberlm@66456
  1317
    then obtain p where "p \<in> {N<..x}" and upmax: "u p = Max{u i |i. i \<in> {N<..x}}" by auto
eberlm@66456
  1318
    define U where "U = {m. m > p \<and> u p < u m}"
eberlm@66456
  1319
    have "U \<noteq> {}" unfolding U_def using N[of p] \<open>p \<in> {N<..x}\<close> by auto
eberlm@66456
  1320
    define y where "y = Inf U"
eberlm@66456
  1321
    then have "y \<in> U" using \<open>U \<noteq> {}\<close> by (simp add: Inf_nat_def1)
eberlm@66456
  1322
    have a: "\<And>i. i \<in> {N<..x} \<Longrightarrow> u i \<le> u p"
eberlm@66456
  1323
    proof -
eberlm@66456
  1324
      fix i assume "i \<in> {N<..x}"
eberlm@66456
  1325
      then have "u i \<in> {u i |i. i \<in> {N<..x}}" by blast
eberlm@66456
  1326
      then show "u i \<le> u p" using upmax by simp
eberlm@66456
  1327
    qed
eberlm@66456
  1328
    moreover have "u p < u y" using \<open>y \<in> U\<close> U_def by auto
eberlm@66456
  1329
    ultimately have "y \<notin> {N<..x}" using not_le by blast
eberlm@66456
  1330
    moreover have "y > N" using \<open>y \<in> U\<close> U_def \<open>p \<in> {N<..x}\<close> by auto
eberlm@66456
  1331
    ultimately have "y > x" by auto
eberlm@66456
  1332
eberlm@66456
  1333
    have "\<And>i. i \<in> {N<..y} \<Longrightarrow> u i \<le> u y"
eberlm@66456
  1334
    proof -
eberlm@66456
  1335
      fix i assume "i \<in> {N<..y}" show "u i \<le> u y"
eberlm@66456
  1336
      proof (cases)
eberlm@66456
  1337
        assume "i = y"
eberlm@66456
  1338
        then show ?thesis by simp
eberlm@66456
  1339
      next
eberlm@66456
  1340
        assume "\<not>(i=y)"
eberlm@66456
  1341
        then have i:"i \<in> {N<..<y}" using \<open>i \<in> {N<..y}\<close> by simp
eberlm@66456
  1342
        have "u i \<le> u p"
eberlm@66456
  1343
        proof (cases)
eberlm@66456
  1344
          assume "i \<le> x"
eberlm@66456
  1345
          then have "i \<in> {N<..x}" using i by simp
eberlm@66456
  1346
          then show ?thesis using a by simp
eberlm@66456
  1347
        next
eberlm@66456
  1348
          assume "\<not>(i \<le> x)"
eberlm@66456
  1349
          then have "i > x" by simp
eberlm@66456
  1350
          then have *: "i > p" using \<open>p \<in> {N<..x}\<close> by simp
eberlm@66456
  1351
          have "i < Inf U" using i y_def by simp
eberlm@66456
  1352
          then have "i \<notin> U" using Inf_nat_def not_less_Least by auto
eberlm@66456
  1353
          then show ?thesis using U_def * by auto
eberlm@66456
  1354
        qed
eberlm@66456
  1355
        then show "u i \<le> u y" using \<open>u p < u y\<close> by auto
eberlm@66456
  1356
      qed
eberlm@66456
  1357
    qed
eberlm@66456
  1358
    then have "N < y \<and> x < y \<and> (\<forall>i\<in>{N<..y}. u i \<le> u y)" using \<open>y > x\<close> \<open>y > N\<close> by auto
eberlm@66456
  1359
    then show "\<exists>y>N. x < y \<and> (\<forall>i\<in>{N<..y}. u i \<le> u y)" by auto
eberlm@66456
  1360
  qed (auto)
eberlm@66456
  1361
  then obtain r where r: "\<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<le> u (r (Suc n)))" by auto
eberlm@66456
  1362
  have "strict_mono r" using r by (auto simp: strict_mono_Suc_iff)
eberlm@66456
  1363
  have "incseq (u o r)" unfolding o_def using r by (simp add: incseq_SucI order.strict_implies_order)
eberlm@66456
  1364
  then have "(u o r) \<longlonglongrightarrow> (SUP n. (u o r) n)" using LIMSEQ_SUP by blast
eberlm@66456
  1365
  then have "limsup (u o r) = (SUP n. (u o r) n)" by (simp add: lim_imp_Limsup)
eberlm@66456
  1366
  moreover have "limsup (u o r) \<le> limsup u" using \<open>strict_mono r\<close> by (simp add: limsup_subseq_mono)
eberlm@66456
  1367
  ultimately have "(SUP n. (u o r) n) \<le> limsup u" by simp
eberlm@66456
  1368
eberlm@66456
  1369
  {
eberlm@66456
  1370
    fix i assume i: "i \<in> {N<..}"
eberlm@66456
  1371
    obtain n where "i < r (Suc n)" using \<open>strict_mono r\<close> using Suc_le_eq seq_suble by blast
eberlm@66456
  1372
    then have "i \<in> {N<..r(Suc n)}" using i by simp
eberlm@66456
  1373
    then have "u i \<le> u (r(Suc n))" using r by simp
eberlm@66456
  1374
    then have "u i \<le> (SUP n. (u o r) n)" unfolding o_def by (meson SUP_upper2 UNIV_I)
eberlm@66456
  1375
  }
haftmann@69260
  1376
  then have "(SUP i\<in>{N<..}. u i) \<le> (SUP n. (u o r) n)" using SUP_least by blast
eberlm@66456
  1377
  then have "limsup u \<le> (SUP n. (u o r) n)" unfolding Limsup_def
eberlm@66456
  1378
    by (metis (mono_tags, lifting) INF_lower2 atLeast_Suc_greaterThan atLeast_def eventually_ge_at_top mem_Collect_eq)
eberlm@66456
  1379
  then have "limsup u = (SUP n. (u o r) n)" using \<open>(SUP n. (u o r) n) \<le> limsup u\<close> by simp
eberlm@66456
  1380
  then have "(u o r) \<longlonglongrightarrow> limsup u" using \<open>(u o r) \<longlonglongrightarrow> (SUP n. (u o r) n)\<close> by simp
eberlm@66456
  1381
  then show ?thesis using \<open>strict_mono r\<close> by auto
eberlm@66456
  1382
qed
eberlm@66456
  1383
ak2110@69221
  1384
lemma%important liminf_subseq_lim:
eberlm@66456
  1385
  fixes u::"nat \<Rightarrow> 'a :: {complete_linorder, linorder_topology}"
eberlm@66456
  1386
  shows "\<exists>r::nat\<Rightarrow>nat. strict_mono r \<and> (u o r) \<longlonglongrightarrow> liminf u"
ak2110@69221
  1387
proof%unimportant (cases)
eberlm@66456
  1388
  assume "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. u m \<ge> u p"
eberlm@66456
  1389
  then have "\<exists>r. \<forall>n. (\<forall>m\<ge>r n. u m \<ge> u (r n)) \<and> r n < r (Suc n)"
eberlm@66456
  1390
    by (intro dependent_nat_choice) (auto simp: conj_commute)
eberlm@66456
  1391
  then obtain r :: "nat \<Rightarrow> nat" where "strict_mono r" and mono: "\<And>n m. r n \<le> m \<Longrightarrow> u m \<ge> u (r n)"
eberlm@66456
  1392
    by (auto simp: strict_mono_Suc_iff)
haftmann@69260
  1393
  define umin where "umin = (\<lambda>n. (INF m\<in>{n..}. u m))"
eberlm@66456
  1394
  have "incseq umin" unfolding umin_def by (simp add: INF_superset_mono incseq_def)
eberlm@66456
  1395
  then have "umin \<longlonglongrightarrow> liminf u" unfolding umin_def by (metis LIMSEQ_SUP liminf_SUP_INF)
eberlm@66456
  1396
  then have *: "(umin o r) \<longlonglongrightarrow> liminf u" by (simp add: LIMSEQ_subseq_LIMSEQ \<open>strict_mono r\<close>)
eberlm@66456
  1397
  have "\<And>n. umin(r n) = u(r n)" unfolding umin_def using mono
eberlm@66456
  1398
    by (metis le_INF_iff antisym atLeast_def mem_Collect_eq order_refl)
eberlm@66456
  1399
  then have "umin o r = u o r" unfolding o_def by simp
eberlm@66456
  1400
  then have "(u o r) \<longlonglongrightarrow> liminf u" using * by simp
eberlm@66456
  1401
  then show ?thesis using \<open>strict_mono r\<close> by blast
eberlm@66456
  1402
next
eberlm@66456
  1403
  assume "\<not> (\<forall>n. \<exists>p>n. (\<forall>m\<ge>p. u m \<ge> u p))"
eberlm@66456
  1404
  then obtain N where N: "\<And>p. p > N \<Longrightarrow> \<exists>m>p. u p > u m" by (force simp: not_le le_less)
eberlm@66456
  1405
  have "\<exists>r. \<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<ge> u (r (Suc n)))"
eberlm@66456
  1406
  proof (rule dependent_nat_choice)
eberlm@66456
  1407
    fix x assume "N < x"
eberlm@66456
  1408
    then have a: "finite {N<..x}" "{N<..x} \<noteq> {}" by simp_all
eberlm@66456
  1409
    have "Min {u i |i. i \<in> {N<..x}} \<in> {u i |i. i \<in> {N<..x}}" apply (rule Min_in) using a by (auto)
eberlm@66456
  1410
    then obtain p where "p \<in> {N<..x}" and upmin: "u p = Min{u i |i. i \<in> {N<..x}}" by auto
eberlm@66456
  1411
    define U where "U = {m. m > p \<and> u p > u m}"
eberlm@66456
  1412
    have "U \<noteq> {}" unfolding U_def using N[of p] \<open>p \<in> {N<..x}\<close> by auto
eberlm@66456
  1413
    define y where "y = Inf U"
eberlm@66456
  1414
    then have "y \<in> U" using \<open>U \<noteq> {}\<close> by (simp add: Inf_nat_def1)
eberlm@66456
  1415
    have a: "\<And>i. i \<in> {N<..x} \<Longrightarrow> u i \<ge> u p"
eberlm@66456
  1416
    proof -
eberlm@66456
  1417
      fix i assume "i \<in> {N<..x}"
eberlm@66456
  1418
      then have "u i \<in> {u i |i. i \<in> {N<..x}}" by blast
eberlm@66456
  1419
      then show "u i \<ge> u p" using upmin by simp
eberlm@66456
  1420
    qed
eberlm@66456
  1421
    moreover have "u p > u y" using \<open>y \<in> U\<close> U_def by auto
eberlm@66456
  1422
    ultimately have "y \<notin> {N<..x}" using not_le by blast
eberlm@66456
  1423
    moreover have "y > N" using \<open>y \<in> U\<close> U_def \<open>p \<in> {N<..x}\<close> by auto
eberlm@66456
  1424
    ultimately have "y > x" by auto
eberlm@66456
  1425
eberlm@66456
  1426
    have "\<And>i. i \<in> {N<..y} \<Longrightarrow> u i \<ge> u y"
eberlm@66456
  1427
    proof -
eberlm@66456
  1428
      fix i assume "i \<in> {N<..y}" show "u i \<ge> u y"
eberlm@66456
  1429
      proof (cases)
eberlm@66456
  1430
        assume "i = y"
eberlm@66456
  1431
        then show ?thesis by simp
eberlm@66456
  1432
      next
eberlm@66456
  1433
        assume "\<not>(i=y)"
eberlm@66456
  1434
        then have i:"i \<in> {N<..<y}" using \<open>i \<in> {N<..y}\<close> by simp
eberlm@66456
  1435
        have "u i \<ge> u p"
eberlm@66456
  1436
        proof (cases)
eberlm@66456
  1437
          assume "i \<le> x"
eberlm@66456
  1438
          then have "i \<in> {N<..x}" using i by simp
eberlm@66456
  1439
          then show ?thesis using a by simp
eberlm@66456
  1440
        next
eberlm@66456
  1441
          assume "\<not>(i \<le> x)"
eberlm@66456
  1442
          then have "i > x" by simp
eberlm@66456
  1443
          then have *: "i > p" using \<open>p \<in> {N<..x}\<close> by simp
eberlm@66456
  1444
          have "i < Inf U" using i y_def by simp
eberlm@66456
  1445
          then have "i \<notin> U" using Inf_nat_def not_less_Least by auto
eberlm@66456
  1446
          then show ?thesis using U_def * by auto
eberlm@66456
  1447
        qed
eberlm@66456
  1448
        then show "u i \<ge> u y" using \<open>u p > u y\<close> by auto
eberlm@66456
  1449
      qed
eberlm@66456
  1450
    qed
eberlm@66456
  1451
    then have "N < y \<and> x < y \<and> (\<forall>i\<in>{N<..y}. u i \<ge> u y)" using \<open>y > x\<close> \<open>y > N\<close> by auto
eberlm@66456
  1452
    then show "\<exists>y>N. x < y \<and> (\<forall>i\<in>{N<..y}. u i \<ge> u y)" by auto
eberlm@66456
  1453
  qed (auto)
eberlm@66456
  1454
  then obtain r :: "nat \<Rightarrow> nat" 
eberlm@66456
  1455
    where r: "\<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<ge> u (r (Suc n)))" by auto
eberlm@66456
  1456
  have "strict_mono r" using r by (auto simp: strict_mono_Suc_iff)
eberlm@66456
  1457
  have "decseq (u o r)" unfolding o_def using r by (simp add: decseq_SucI order.strict_implies_order)
eberlm@66456
  1458
  then have "(u o r) \<longlonglongrightarrow> (INF n. (u o r) n)" using LIMSEQ_INF by blast
eberlm@66456
  1459
  then have "liminf (u o r) = (INF n. (u o r) n)" by (simp add: lim_imp_Liminf)
eberlm@66456
  1460
  moreover have "liminf (u o r) \<ge> liminf u" using \<open>strict_mono r\<close> by (simp add: liminf_subseq_mono)
eberlm@66456
  1461
  ultimately have "(INF n. (u o r) n) \<ge> liminf u" by simp
eberlm@66456
  1462
eberlm@66456
  1463
  {
eberlm@66456
  1464
    fix i assume i: "i \<in> {N<..}"
eberlm@66456
  1465
    obtain n where "i < r (Suc n)" using \<open>strict_mono r\<close> using Suc_le_eq seq_suble by blast
eberlm@66456
  1466
    then have "i \<in> {N<..r(Suc n)}" using i by simp
eberlm@66456
  1467
    then have "u i \<ge> u (r(Suc n))" using r by simp
eberlm@66456
  1468
    then have "u i \<ge> (INF n. (u o r) n)" unfolding o_def by (meson INF_lower2 UNIV_I)
eberlm@66456
  1469
  }
haftmann@69260
  1470
  then have "(INF i\<in>{N<..}. u i) \<ge> (INF n. (u o r) n)" using INF_greatest by blast
eberlm@66456
  1471
  then have "liminf u \<ge> (INF n. (u o r) n)" unfolding Liminf_def
eberlm@66456
  1472
    by (metis (mono_tags, lifting) SUP_upper2 atLeast_Suc_greaterThan atLeast_def eventually_ge_at_top mem_Collect_eq)
eberlm@66456
  1473
  then have "liminf u = (INF n. (u o r) n)" using \<open>(INF n. (u o r) n) \<ge> liminf u\<close> by simp
eberlm@66456
  1474
  then have "(u o r) \<longlonglongrightarrow> liminf u" using \<open>(u o r) \<longlonglongrightarrow> (INF n. (u o r) n)\<close> by simp
eberlm@66456
  1475
  then show ?thesis using \<open>strict_mono r\<close> by auto
eberlm@66456
  1476
qed
eberlm@66456
  1477
eberlm@66456
  1478
text \<open>The following statement about limsups is reduced to a statement about limits using
eberlm@66456
  1479
subsequences thanks to \verb+limsup_subseq_lim+. The statement for limits follows for instance from
eberlm@66456
  1480
\verb+tendsto_add_ereal_general+.\<close>
eberlm@66456
  1481
ak2110@69221
  1482
lemma%important ereal_limsup_add_mono:
eberlm@66456
  1483
  fixes u v::"nat \<Rightarrow> ereal"
eberlm@66456
  1484
  shows "limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v"
ak2110@69221
  1485
proof%unimportant (cases)
eberlm@66456
  1486
  assume "(limsup u = \<infinity>) \<or> (limsup v = \<infinity>)"
eberlm@66456
  1487
  then have "limsup u + limsup v = \<infinity>" by simp
eberlm@66456
  1488
  then show ?thesis by auto
eberlm@66456
  1489
next
eberlm@66456
  1490
  assume "\<not>((limsup u = \<infinity>) \<or> (limsup v = \<infinity>))"
eberlm@66456
  1491
  then have "limsup u < \<infinity>" "limsup v < \<infinity>" by auto
eberlm@66456
  1492
eberlm@66456
  1493
  define w where "w = (\<lambda>n. u n + v n)"
eberlm@66456
  1494
  obtain r where r: "strict_mono r" "(w o r) \<longlonglongrightarrow> limsup w" using limsup_subseq_lim by auto
eberlm@66456
  1495
  obtain s where s: "strict_mono s" "(u o r o s) \<longlonglongrightarrow> limsup (u o r)" using limsup_subseq_lim by auto
eberlm@66456
  1496
  obtain t where t: "strict_mono t" "(v o r o s o t) \<longlonglongrightarrow> limsup (v o r o s)" using limsup_subseq_lim by auto
eberlm@66456
  1497
eberlm@66456
  1498
  define a where "a = r o s o t"
eberlm@66456
  1499
  have "strict_mono a" using r s t by (simp add: a_def strict_mono_o)
eberlm@66456
  1500
  have l:"(w o a) \<longlonglongrightarrow> limsup w"
eberlm@66456
  1501
         "(u o a) \<longlonglongrightarrow> limsup (u o r)"
eberlm@66456
  1502
         "(v o a) \<longlonglongrightarrow> limsup (v o r o s)"
eberlm@66456
  1503
  apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
eberlm@66456
  1504
  apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
eberlm@66456
  1505
  apply (metis (no_types, lifting) t(2) a_def comp_assoc)
eberlm@66456
  1506
  done
eberlm@66456
  1507
eberlm@66456
  1508
  have "limsup (u o r) \<le> limsup u" by (simp add: limsup_subseq_mono r(1))
eberlm@66456
  1509
  then have a: "limsup (u o r) \<noteq> \<infinity>" using \<open>limsup u < \<infinity>\<close> by auto
eberlm@66456
  1510
  have "limsup (v o r o s) \<le> limsup v" 
eberlm@66456
  1511
    by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) strict_mono_o)
eberlm@66456
  1512
  then have b: "limsup (v o r o s) \<noteq> \<infinity>" using \<open>limsup v < \<infinity>\<close> by auto
eberlm@66456
  1513
eberlm@66456
  1514
  have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)"
eberlm@66456
  1515
    using l tendsto_add_ereal_general a b by fastforce
eberlm@66456
  1516
  moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
eberlm@66456
  1517
  ultimately have "(w o a) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)" by simp
eberlm@66456
  1518
  then have "limsup w = limsup (u o r) + limsup (v o r o s)" using l(1) LIMSEQ_unique by blast
eberlm@66456
  1519
  then have "limsup w \<le> limsup u + limsup v"
nipkow@68752
  1520
    using \<open>limsup (u o r) \<le> limsup u\<close> \<open>limsup (v o r o s) \<le> limsup v\<close> add_mono by simp
eberlm@66456
  1521
  then show ?thesis unfolding w_def by simp
eberlm@66456
  1522
qed
eberlm@66456
  1523
eberlm@66456
  1524
text \<open>There is an asymmetry between liminfs and limsups in ereal, as $\infty + (-\infty) = \infty$.
eberlm@66456
  1525
This explains why there are more assumptions in the next lemma dealing with liminfs that in the
eberlm@66456
  1526
previous one about limsups.\<close>
eberlm@66456
  1527
ak2110@69221
  1528
lemma%important ereal_liminf_add_mono:
eberlm@66456
  1529
  fixes u v::"nat \<Rightarrow> ereal"
eberlm@66456
  1530
  assumes "\<not>((liminf u = \<infinity> \<and> liminf v = -\<infinity>) \<or> (liminf u = -\<infinity> \<and> liminf v = \<infinity>))"
eberlm@66456
  1531
  shows "liminf (\<lambda>n. u n + v n) \<ge> liminf u + liminf v"
ak2110@69221
  1532
proof%unimportant (cases)
eberlm@66456
  1533
  assume "(liminf u = -\<infinity>) \<or> (liminf v = -\<infinity>)"
eberlm@66456
  1534
  then have *: "liminf u + liminf v = -\<infinity>" using assms by auto
eberlm@66456
  1535
  show ?thesis by (simp add: *)
eberlm@66456
  1536
next
eberlm@66456
  1537
  assume "\<not>((liminf u = -\<infinity>) \<or> (liminf v = -\<infinity>))"
eberlm@66456
  1538
  then have "liminf u > -\<infinity>" "liminf v > -\<infinity>" by auto
eberlm@66456
  1539
eberlm@66456
  1540
  define w where "w = (\<lambda>n. u n + v n)"
eberlm@66456
  1541
  obtain r where r: "strict_mono r" "(w o r) \<longlonglongrightarrow> liminf w" using liminf_subseq_lim by auto
eberlm@66456
  1542
  obtain s where s: "strict_mono s" "(u o r o s) \<longlonglongrightarrow> liminf (u o r)" using liminf_subseq_lim by auto
eberlm@66456
  1543
  obtain t where t: "strict_mono t" "(v o r o s o t) \<longlonglongrightarrow> liminf (v o r o s)" using liminf_subseq_lim by auto
eberlm@66456
  1544
eberlm@66456
  1545
  define a where "a = r o s o t"
eberlm@66456
  1546
  have "strict_mono a" using r s t by (simp add: a_def strict_mono_o)
eberlm@66456
  1547
  have l:"(w o a) \<longlonglongrightarrow> liminf w"
eberlm@66456
  1548
         "(u o a) \<longlonglongrightarrow> liminf (u o r)"
eberlm@66456
  1549
         "(v o a) \<longlonglongrightarrow> liminf (v o r o s)"
eberlm@66456
  1550
  apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
eberlm@66456
  1551
  apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
eberlm@66456
  1552
  apply (metis (no_types, lifting) t(2) a_def comp_assoc)
eberlm@66456
  1553
  done
eberlm@66456
  1554
eberlm@66456
  1555
  have "liminf (u o r) \<ge> liminf u" by (simp add: liminf_subseq_mono r(1))
eberlm@66456
  1556
  then have a: "liminf (u o r) \<noteq> -\<infinity>" using \<open>liminf u > -\<infinity>\<close> by auto
eberlm@66456
  1557
  have "liminf (v o r o s) \<ge> liminf v" 
eberlm@66456
  1558
    by (simp add: comp_assoc liminf_subseq_mono r(1) s(1) strict_mono_o)
eberlm@66456
  1559
  then have b: "liminf (v o r o s) \<noteq> -\<infinity>" using \<open>liminf v > -\<infinity>\<close> by auto
eberlm@66456
  1560
eberlm@66456
  1561
  have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> liminf (u o r) + liminf (v o r o s)"
eberlm@66456
  1562
    using l tendsto_add_ereal_general a b by fastforce
eberlm@66456
  1563
  moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
eberlm@66456
  1564
  ultimately have "(w o a) \<longlonglongrightarrow> liminf (u o r) + liminf (v o r o s)" by simp
eberlm@66456
  1565
  then have "liminf w = liminf (u o r) + liminf (v o r o s)" using l(1) LIMSEQ_unique by blast
eberlm@66456
  1566
  then have "liminf w \<ge> liminf u + liminf v"
nipkow@68752
  1567
    using \<open>liminf (u o r) \<ge> liminf u\<close> \<open>liminf (v o r o s) \<ge> liminf v\<close> add_mono by simp
eberlm@66456
  1568
  then show ?thesis unfolding w_def by simp
eberlm@66456
  1569
qed
eberlm@66456
  1570
ak2110@69221
  1571
lemma%important ereal_limsup_lim_add:
eberlm@66456
  1572
  fixes u v::"nat \<Rightarrow> ereal"
eberlm@66456
  1573
  assumes "u \<longlonglongrightarrow> a" "abs(a) \<noteq> \<infinity>"
eberlm@66456
  1574
  shows "limsup (\<lambda>n. u n + v n) = a + limsup v"
ak2110@69221
  1575
proof%unimportant -
eberlm@66456
  1576
  have "limsup u = a" using assms(1) using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by blast
eberlm@66456
  1577
  have "(\<lambda>n. -u n) \<longlonglongrightarrow> -a" using assms(1) by auto
eberlm@66456
  1578
  then have "limsup (\<lambda>n. -u n) = -a" using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by blast
eberlm@66456
  1579
eberlm@66456
  1580
  have "limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v"
eberlm@66456
  1581
    by (rule ereal_limsup_add_mono)
eberlm@66456
  1582
  then have up: "limsup (\<lambda>n. u n + v n) \<le> a + limsup v" using \<open>limsup u = a\<close> by simp
eberlm@66456
  1583
eberlm@66456
  1584
  have a: "limsup (\<lambda>n. (u n + v n) + (-u n)) \<le> limsup (\<lambda>n. u n + v n) + limsup (\<lambda>n. -u n)"
eberlm@66456
  1585
    by (rule ereal_limsup_add_mono)
eberlm@66456
  1586
  have "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) sequentially" using assms
eberlm@66456
  1587
    real_lim_then_eventually_real by auto
eberlm@66456
  1588
  moreover have "\<And>x. x = ereal(real_of_ereal(x)) \<Longrightarrow> x + (-x) = 0"
eberlm@66456
  1589
    by (metis plus_ereal.simps(1) right_minus uminus_ereal.simps(1) zero_ereal_def)
eberlm@66456
  1590
  ultimately have "eventually (\<lambda>n. u n + (-u n) = 0) sequentially"
eberlm@66456
  1591
    by (metis (mono_tags, lifting) eventually_mono)
eberlm@66456
  1592
  moreover have "\<And>n. u n + (-u n) = 0 \<Longrightarrow> u n + v n + (-u n) = v n"
eberlm@66456
  1593
    by (metis add.commute add.left_commute add.left_neutral)
eberlm@66456
  1594
  ultimately have "eventually (\<lambda>n. u n + v n + (-u n) = v n) sequentially"
eberlm@66456
  1595
    using eventually_mono by force
eberlm@66456
  1596
  then have "limsup v = limsup (\<lambda>n. u n + v n + (-u n))" using Limsup_eq by force
eberlm@66456
  1597
  then have "limsup v \<le> limsup (\<lambda>n. u n + v n) -a" using a \<open>limsup (\<lambda>n. -u n) = -a\<close> by (simp add: minus_ereal_def)
eberlm@66456
  1598
  then have "limsup (\<lambda>n. u n + v n) \<ge> a + limsup v" using assms(2) by (metis add.commute ereal_le_minus)
eberlm@66456
  1599
  then show ?thesis using up by simp
eberlm@66456
  1600
qed
eberlm@66456
  1601
ak2110@69221
  1602
lemma%important ereal_limsup_lim_mult:
eberlm@66456
  1603
  fixes u v::"nat \<Rightarrow> ereal"
eberlm@66456
  1604
  assumes "u \<longlonglongrightarrow> a" "a>0" "a \<noteq> \<infinity>"
eberlm@66456
  1605
  shows "limsup (\<lambda>n. u n * v n) = a * limsup v"
ak2110@69221
  1606
proof%unimportant -
eberlm@66456
  1607
  define w where "w = (\<lambda>n. u n * v n)"
eberlm@66456
  1608
  obtain r where r: "strict_mono r" "(v o r) \<longlonglongrightarrow> limsup v" using limsup_subseq_lim by auto
eberlm@66456
  1609
  have "(u o r) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ r by auto
eberlm@66456
  1610
  with tendsto_mult_ereal[OF this r(2)] have "(\<lambda>n. (u o r) n * (v o r) n) \<longlonglongrightarrow> a * limsup v" using assms(2) assms(3) by auto
eberlm@66456
  1611
  moreover have "\<And>n. (w o r) n = (u o r) n * (v o r) n" unfolding w_def by auto
eberlm@66456
  1612
  ultimately have "(w o r) \<longlonglongrightarrow> a * limsup v" unfolding w_def by presburger
eberlm@66456
  1613
  then have "limsup (w o r) = a * limsup v" by (simp add: tendsto_iff_Liminf_eq_Limsup)
eberlm@66456
  1614
  then have I: "limsup w \<ge> a * limsup v" by (metis limsup_subseq_mono r(1))
eberlm@66456
  1615
eberlm@66456
  1616
  obtain s where s: "strict_mono s" "(w o s) \<longlonglongrightarrow> limsup w" using limsup_subseq_lim by auto
eberlm@66456
  1617
  have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
eberlm@66456
  1618
  have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
eberlm@66456
  1619
  moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
eberlm@66456
  1620
  moreover have "(w o s) n / (u o s) n = (v o s) n" if "(u o s) n > 0" "(u o s) n < \<infinity>" for n
eberlm@66456
  1621
    unfolding w_def using that by (auto simp add: ereal_divide_eq)
eberlm@66456
  1622
  ultimately have "eventually (\<lambda>n. (w o s) n / (u o s) n = (v o s) n) sequentially" using eventually_elim2 by force
eberlm@66456
  1623
  moreover have "(\<lambda>n. (w o s) n / (u o s) n) \<longlonglongrightarrow> (limsup w) / a"
eberlm@66456
  1624
    apply (rule tendsto_divide_ereal[OF s(2) *]) using assms(2) assms(3) by auto
eberlm@66456
  1625
  ultimately have "(v o s) \<longlonglongrightarrow> (limsup w) / a" using Lim_transform_eventually by fastforce
eberlm@66456
  1626
  then have "limsup (v o s) = (limsup w) / a" by (simp add: tendsto_iff_Liminf_eq_Limsup)
eberlm@66456
  1627
  then have "limsup v \<ge> (limsup w) / a" by (metis limsup_subseq_mono s(1))
eberlm@66456
  1628
  then have "a * limsup v \<ge> limsup w" using assms(2) assms(3) by (simp add: ereal_divide_le_pos)
eberlm@66456
  1629
  then show ?thesis using I unfolding w_def by auto
eberlm@66456
  1630
qed
eberlm@66456
  1631
ak2110@69221
  1632
lemma%important ereal_liminf_lim_mult:
eberlm@66456
  1633
  fixes u v::"nat \<Rightarrow> ereal"
eberlm@66456
  1634
  assumes "u \<longlonglongrightarrow> a" "a>0" "a \<noteq> \<infinity>"
eberlm@66456
  1635
  shows "liminf (\<lambda>n. u n * v n) = a * liminf v"
ak2110@69221
  1636
proof%unimportant -
eberlm@66456
  1637
  define w where "w = (\<lambda>n. u n * v n)"
eberlm@66456
  1638
  obtain r where r: "strict_mono r" "(v o r) \<longlonglongrightarrow> liminf v" using liminf_subseq_lim by auto
eberlm@66456
  1639
  have "(u o r) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ r by auto
eberlm@66456
  1640
  with tendsto_mult_ereal[OF this r(2)] have "(\<lambda>n. (u o r) n * (v o r) n) \<longlonglongrightarrow> a * liminf v" using assms(2) assms(3) by auto
eberlm@66456
  1641
  moreover have "\<And>n. (w o r) n = (u o r) n * (v o r) n" unfolding w_def by auto
eberlm@66456
  1642
  ultimately have "(w o r) \<longlonglongrightarrow> a * liminf v" unfolding w_def by presburger
eberlm@66456
  1643
  then have "liminf (w o r) = a * liminf v" by (simp add: tendsto_iff_Liminf_eq_Limsup)
eberlm@66456
  1644
  then have I: "liminf w \<le> a * liminf v" by (metis liminf_subseq_mono r(1))
eberlm@66456
  1645
eberlm@66456
  1646
  obtain s where s: "strict_mono s" "(w o s) \<longlonglongrightarrow> liminf w" using liminf_subseq_lim by auto
eberlm@66456
  1647
  have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
eberlm@66456
  1648
  have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
eberlm@66456
  1649
  moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
eberlm@66456
  1650
  moreover have "(w o s) n / (u o s) n = (v o s) n" if "(u o s) n > 0" "(u o s) n < \<infinity>" for n
eberlm@66456
  1651
    unfolding w_def using that by (auto simp add: ereal_divide_eq)
eberlm@66456
  1652
  ultimately have "eventually (\<lambda>n. (w o s) n / (u o s) n = (v o s) n) sequentially" using eventually_elim2 by force
eberlm@66456
  1653
  moreover have "(\<lambda>n. (w o s) n / (u o s) n) \<longlonglongrightarrow> (liminf w) / a"
eberlm@66456
  1654
    apply (rule tendsto_divide_ereal[OF s(2) *]) using assms(2) assms(3) by auto
eberlm@66456
  1655
  ultimately have "(v o s) \<longlonglongrightarrow> (liminf w) / a" using Lim_transform_eventually by fastforce
eberlm@66456
  1656
  then have "liminf (v o s) = (liminf w) / a" by (simp add: tendsto_iff_Liminf_eq_Limsup)
eberlm@66456
  1657
  then have "liminf v \<le> (liminf w) / a" by (metis liminf_subseq_mono s(1))
eberlm@66456
  1658
  then have "a * liminf v \<le> liminf w" using assms(2) assms(3) by (simp add: ereal_le_divide_pos)
eberlm@66456
  1659
  then show ?thesis using I unfolding w_def by auto
eberlm@66456
  1660
qed
eberlm@66456
  1661
ak2110@69221
  1662
lemma%important ereal_liminf_lim_add:
eberlm@66456
  1663
  fixes u v::"nat \<Rightarrow> ereal"
eberlm@66456
  1664
  assumes "u \<longlonglongrightarrow> a" "abs(a) \<noteq> \<infinity>"
eberlm@66456
  1665
  shows "liminf (\<lambda>n. u n + v n) = a + liminf v"
ak2110@69221
  1666
proof%unimportant -
eberlm@66456
  1667
  have "liminf u = a" using assms(1) tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by blast
eberlm@66456
  1668
  then have *: "abs(liminf u) \<noteq> \<infinity>" using assms(2) by auto
eberlm@66456
  1669
  have "(\<lambda>n. -u n) \<longlonglongrightarrow> -a" using assms(1) by auto
eberlm@66456
  1670
  then have "liminf (\<lambda>n. -u n) = -a" using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by blast
eberlm@66456
  1671
  then have **: "abs(liminf (\<lambda>n. -u n)) \<noteq> \<infinity>" using assms(2) by auto
eberlm@66456
  1672
eberlm@66456
  1673
  have "liminf (\<lambda>n. u n + v n) \<ge> liminf u + liminf v"
eberlm@66456
  1674
    apply (rule ereal_liminf_add_mono) using * by auto
eberlm@66456
  1675
  then have up: "liminf (\<lambda>n. u n + v n) \<ge> a + liminf v" using \<open>liminf u = a\<close> by simp
eberlm@66456
  1676
eberlm@66456
  1677
  have a: "liminf (\<lambda>n. (u n + v n) + (-u n)) \<ge> liminf (\<lambda>n. u n + v n) + liminf (\<lambda>n. -u n)"
eberlm@66456
  1678
    apply (rule ereal_liminf_add_mono) using ** by auto
eberlm@66456
  1679
  have "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) sequentially" using assms
eberlm@66456
  1680
    real_lim_then_eventually_real by auto
eberlm@66456
  1681
  moreover have "\<And>x. x = ereal(real_of_ereal(x)) \<Longrightarrow> x + (-x) = 0"
eberlm@66456
  1682
    by (metis plus_ereal.simps(1) right_minus uminus_ereal.simps(1) zero_ereal_def)
eberlm@66456
  1683
  ultimately have "eventually (\<lambda>n. u n + (-u n) = 0) sequentially"
eberlm@66456
  1684
    by (metis (mono_tags, lifting) eventually_mono)
eberlm@66456
  1685
  moreover have "\<And>n. u n + (-u n) = 0 \<Longrightarrow> u n + v n + (-u n) = v n"
eberlm@66456
  1686
    by (metis add.commute add.left_commute add.left_neutral)
eberlm@66456
  1687
  ultimately have "eventually (\<lambda>n. u n + v n + (-u n) = v n) sequentially"
eberlm@66456
  1688
    using eventually_mono by force
eberlm@66456
  1689
  then have "liminf v = liminf (\<lambda>n. u n + v n + (-u n))" using Liminf_eq by force
eberlm@66456
  1690
  then have "liminf v \<ge> liminf (\<lambda>n. u n + v n) -a" using a \<open>liminf (\<lambda>n. -u n) = -a\<close> by (simp add: minus_ereal_def)
eberlm@66456
  1691
  then have "liminf (\<lambda>n. u n + v n) \<le> a + liminf v" using assms(2) by (metis add.commute ereal_minus_le)
eberlm@66456
  1692
  then show ?thesis using up by simp
eberlm@66456
  1693
qed
eberlm@66456
  1694
ak2110@69221
  1695
lemma%important ereal_liminf_limsup_add:
eberlm@66456
  1696
  fixes u v::"nat \<Rightarrow> ereal"
eberlm@66456
  1697
  shows "liminf (\<lambda>n. u n + v n) \<le> liminf u + limsup v"
ak2110@69221
  1698
proof%unimportant (cases)
eberlm@66456
  1699
  assume "limsup v = \<infinity> \<or> liminf u = \<infinity>"
eberlm@66456
  1700
  then show ?thesis by auto
eberlm@66456
  1701
next
eberlm@66456
  1702
  assume "\<not>(limsup v = \<infinity> \<or> liminf u = \<infinity>)"
eberlm@66456
  1703
  then have "limsup v < \<infinity>" "liminf u < \<infinity>" by auto
eberlm@66456
  1704
eberlm@66456
  1705
  define w where "w = (\<lambda>n. u n + v n)"
eberlm@66456
  1706
  obtain r where r: "strict_mono r" "(u o r) \<longlonglongrightarrow> liminf u" using liminf_subseq_lim by auto
eberlm@66456
  1707
  obtain s where s: "strict_mono s" "(w o r o s) \<longlonglongrightarrow> liminf (w o r)" using liminf_subseq_lim by auto
eberlm@66456
  1708
  obtain t where t: "strict_mono t" "(v o r o s o t) \<longlonglongrightarrow> limsup (v o r o s)" using limsup_subseq_lim by auto
eberlm@66456
  1709
eberlm@66456
  1710
  define a where "a = r o s o t"
eberlm@66456
  1711
  have "strict_mono a" using r s t by (simp add: a_def strict_mono_o)
eberlm@66456
  1712
  have l:"(u o a) \<longlonglongrightarrow> liminf u"
eberlm@66456
  1713
         "(w o a) \<longlonglongrightarrow> liminf (w o r)"
eberlm@66456
  1714
         "(v o a) \<longlonglongrightarrow> limsup (v o r o s)"
eberlm@66456
  1715
  apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
eberlm@66456
  1716
  apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
eberlm@66456
  1717
  apply (metis (no_types, lifting) t(2) a_def comp_assoc)
eberlm@66456
  1718
  done
eberlm@66456
  1719
eberlm@66456
  1720
  have "liminf (w o r) \<ge> liminf w" by (simp add: liminf_subseq_mono r(1))
eberlm@66456
  1721
  have "limsup (v o r o s) \<le> limsup v" 
eberlm@66456
  1722
    by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) strict_mono_o)
eberlm@66456
  1723
  then have b: "limsup (v o r o s) < \<infinity>" using \<open>limsup v < \<infinity>\<close> by auto
eberlm@66456
  1724
eberlm@66456
  1725
  have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> liminf u + limsup (v o r o s)"
eberlm@66456
  1726
    apply (rule tendsto_add_ereal_general) using b \<open>liminf u < \<infinity>\<close> l(1) l(3) by force+
eberlm@66456
  1727
  moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
eberlm@66456
  1728
  ultimately have "(w o a) \<longlonglongrightarrow> liminf u + limsup (v o r o s)" by simp
eberlm@66456
  1729
  then have "liminf (w o r) = liminf u + limsup (v o r o s)" using l(2) using LIMSEQ_unique by blast
eberlm@66456
  1730
  then have "liminf w \<le> liminf u + limsup v"
eberlm@66456
  1731
    using \<open>liminf (w o r) \<ge> liminf w\<close> \<open>limsup (v o r o s) \<le> limsup v\<close>
eberlm@66456
  1732
    by (metis add_mono_thms_linordered_semiring(2) le_less_trans not_less)
eberlm@66456
  1733
  then show ?thesis unfolding w_def by simp
eberlm@66456
  1734
qed
eberlm@66456
  1735
eberlm@66456
  1736
lemma ereal_liminf_limsup_minus:
eberlm@66456
  1737
  fixes u v::"nat \<Rightarrow> ereal"
eberlm@66456
  1738
  shows "liminf (\<lambda>n. u n - v n) \<le> limsup u - limsup v"
eberlm@66456
  1739
  unfolding minus_ereal_def
eberlm@66456
  1740
  apply (subst add.commute)
eberlm@66456
  1741
  apply (rule order_trans[OF ereal_liminf_limsup_add])
eberlm@66456
  1742
  using ereal_Limsup_uminus[of sequentially "\<lambda>n. - v n"]
eberlm@66456
  1743
  apply (simp add: add.commute)
eberlm@66456
  1744
  done
eberlm@66456
  1745
eberlm@66456
  1746
ak2110@69221
  1747
lemma%important liminf_minus_ennreal:
eberlm@66456
  1748
  fixes u v::"nat \<Rightarrow> ennreal"
eberlm@66456
  1749
  shows "(\<And>n. v n \<le> u n) \<Longrightarrow> liminf (\<lambda>n. u n - v n) \<le> limsup u - limsup v"
eberlm@66456
  1750
  unfolding liminf_SUP_INF limsup_INF_SUP
eberlm@66456
  1751
  including ennreal.lifting
ak2110@69221
  1752
proof%unimportant (transfer, clarsimp)
eberlm@66456
  1753
  fix v u :: "nat \<Rightarrow> ereal" assume *: "\<forall>x. 0 \<le> v x" "\<forall>x. 0 \<le> u x" "\<And>n. v n \<le> u n"
eberlm@66456
  1754
  moreover have "0 \<le> limsup u - limsup v"
eberlm@66456
  1755
    using * by (intro ereal_diff_positive Limsup_mono always_eventually) simp
haftmann@69313
  1756
  moreover have "0 \<le> Sup (u ` {x..})" for x
eberlm@66456
  1757
    using * by (intro SUP_upper2[of x]) auto
haftmann@69313
  1758
  moreover have "0 \<le> Sup (v ` {x..})" for x
eberlm@66456
  1759
    using * by (intro SUP_upper2[of x]) auto
haftmann@69260
  1760
  ultimately show "(SUP n. INF n\<in>{n..}. max 0 (u n - v n))
haftmann@69313
  1761
            \<le> max 0 ((INF x. max 0 (Sup (u ` {x..}))) - (INF x. max 0 (Sup (v ` {x..}))))"
eberlm@66456
  1762
    by (auto simp: * ereal_diff_positive max.absorb2 liminf_SUP_INF[symmetric] limsup_INF_SUP[symmetric] ereal_liminf_limsup_minus)
eberlm@66456
  1763
qed
eberlm@66456
  1764
ak2110@69221
  1765
subsection%unimportant "Relate extended reals and the indicator function"
hoelzl@57446
  1766
hoelzl@59000
  1767
lemma ereal_indicator_le_0: "(indicator S x::ereal) \<le> 0 \<longleftrightarrow> x \<notin> S"
hoelzl@59000
  1768
  by (auto split: split_indicator simp: one_ereal_def)
hoelzl@59000
  1769
hoelzl@57446
  1770
lemma ereal_indicator: "ereal (indicator A x) = indicator A x"
hoelzl@57446
  1771
  by (auto simp: indicator_def one_ereal_def)
hoelzl@57446
  1772
hoelzl@57446
  1773
lemma ereal_mult_indicator: "ereal (x * indicator A y) = ereal x * indicator A y"
hoelzl@57446
  1774
  by (simp split: split_indicator)
hoelzl@57446
  1775
hoelzl@57446
  1776
lemma ereal_indicator_mult: "ereal (indicator A y * x) = indicator A y * ereal x"
hoelzl@57446
  1777
  by (simp split: split_indicator)
hoelzl@57446
  1778
hoelzl@57446
  1779
lemma ereal_indicator_nonneg[simp, intro]: "0 \<le> (indicator A x ::ereal)"
hoelzl@57446
  1780
  unfolding indicator_def by auto
hoelzl@57446
  1781
hoelzl@59425
  1782
lemma indicator_inter_arith_ereal: "indicator A x * indicator B x = (indicator (A \<inter> B) x :: ereal)"
hoelzl@59425
  1783
  by (simp split: split_indicator)
hoelzl@59425
  1784
huffman@44125
  1785
end