src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy
author wenzelm
Tue Aug 05 16:58:19 2014 +0200 (2014-08-05)
changeset 57865 dcfb33c26f50
parent 57447 87429bdecad5
child 58877 262572d90bc6
permissions -rw-r--r--
tuned proofs -- fewer warnings;
wenzelm@41983
     1
(*  Title:      HOL/Multivariate_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
hoelzl@41980
     8
header {* Limits on the Extended real number line *}
hoelzl@41980
     9
hoelzl@41980
    10
theory Extended_Real_Limits
hoelzl@57446
    11
  imports Topology_Euclidean_Space "~~/src/HOL/Library/Extended_Real" "~~/src/HOL/Library/Indicator_Function"
hoelzl@41980
    12
begin
hoelzl@41980
    13
hoelzl@51351
    14
lemma convergent_limsup_cl:
wenzelm@53788
    15
  fixes X :: "nat \<Rightarrow> 'a::{complete_linorder,linorder_topology}"
hoelzl@51351
    16
  shows "convergent X \<Longrightarrow> limsup X = lim X"
hoelzl@51351
    17
  by (auto simp: convergent_def limI lim_imp_Limsup)
hoelzl@51351
    18
hoelzl@51351
    19
lemma lim_increasing_cl:
hoelzl@51351
    20
  assumes "\<And>n m. n \<ge> m \<Longrightarrow> f n \<ge> f m"
wenzelm@53788
    21
  obtains l where "f ----> (l::'a::{complete_linorder,linorder_topology})"
hoelzl@51351
    22
proof
hoelzl@51351
    23
  show "f ----> (SUP n. f n)"
hoelzl@51351
    24
    using assms
hoelzl@51351
    25
    by (intro increasing_tendsto)
hoelzl@51351
    26
       (auto simp: SUP_upper eventually_sequentially less_SUP_iff intro: less_le_trans)
hoelzl@51351
    27
qed
hoelzl@51351
    28
hoelzl@51351
    29
lemma lim_decreasing_cl:
hoelzl@51351
    30
  assumes "\<And>n m. n \<ge> m \<Longrightarrow> f n \<le> f m"
wenzelm@53788
    31
  obtains l where "f ----> (l::'a::{complete_linorder,linorder_topology})"
hoelzl@51351
    32
proof
hoelzl@51351
    33
  show "f ----> (INF n. f n)"
hoelzl@51351
    34
    using assms
hoelzl@51351
    35
    by (intro decreasing_tendsto)
hoelzl@51351
    36
       (auto simp: INF_lower eventually_sequentially INF_less_iff intro: le_less_trans)
hoelzl@51351
    37
qed
hoelzl@51351
    38
hoelzl@51351
    39
lemma compact_complete_linorder:
wenzelm@53788
    40
  fixes X :: "nat \<Rightarrow> 'a::{complete_linorder,linorder_topology}"
hoelzl@51351
    41
  shows "\<exists>l r. subseq r \<and> (X \<circ> r) ----> l"
hoelzl@51351
    42
proof -
hoelzl@51351
    43
  obtain r where "subseq r" and mono: "monoseq (X \<circ> r)"
wenzelm@53788
    44
    using seq_monosub[of X]
wenzelm@53788
    45
    unfolding comp_def
wenzelm@53788
    46
    by auto
hoelzl@51351
    47
  then have "(\<forall>n m. m \<le> n \<longrightarrow> (X \<circ> r) m \<le> (X \<circ> r) n) \<or> (\<forall>n m. m \<le> n \<longrightarrow> (X \<circ> r) n \<le> (X \<circ> r) m)"
hoelzl@51351
    48
    by (auto simp add: monoseq_def)
wenzelm@53788
    49
  then obtain l where "(X \<circ> r) ----> l"
wenzelm@53788
    50
     using lim_increasing_cl[of "X \<circ> r"] lim_decreasing_cl[of "X \<circ> r"]
wenzelm@53788
    51
     by auto
wenzelm@53788
    52
  then show ?thesis
wenzelm@53788
    53
    using `subseq r` by auto
hoelzl@51351
    54
qed
hoelzl@51351
    55
wenzelm@53788
    56
lemma compact_UNIV:
wenzelm@53788
    57
  "compact (UNIV :: 'a::{complete_linorder,linorder_topology,second_countable_topology} set)"
hoelzl@51351
    58
  using compact_complete_linorder
hoelzl@51351
    59
  by (auto simp: seq_compact_eq_compact[symmetric] seq_compact_def)
hoelzl@51351
    60
hoelzl@51351
    61
lemma compact_eq_closed:
wenzelm@53788
    62
  fixes S :: "'a::{complete_linorder,linorder_topology,second_countable_topology} set"
hoelzl@51351
    63
  shows "compact S \<longleftrightarrow> closed S"
wenzelm@53788
    64
  using closed_inter_compact[of S, OF _ compact_UNIV] compact_imp_closed
wenzelm@53788
    65
  by auto
hoelzl@51351
    66
hoelzl@51351
    67
lemma closed_contains_Sup_cl:
wenzelm@53788
    68
  fixes S :: "'a::{complete_linorder,linorder_topology,second_countable_topology} set"
wenzelm@53788
    69
  assumes "closed S"
wenzelm@53788
    70
    and "S \<noteq> {}"
wenzelm@53788
    71
  shows "Sup S \<in> S"
hoelzl@51351
    72
proof -
hoelzl@51351
    73
  from compact_eq_closed[of S] compact_attains_sup[of S] assms
wenzelm@53788
    74
  obtain s where S: "s \<in> S" "\<forall>t\<in>S. t \<le> s"
wenzelm@53788
    75
    by auto
wenzelm@53374
    76
  then have "Sup S = s"
hoelzl@51351
    77
    by (auto intro!: Sup_eqI)
wenzelm@53374
    78
  with S show ?thesis
hoelzl@51351
    79
    by simp
hoelzl@51351
    80
qed
hoelzl@51351
    81
hoelzl@51351
    82
lemma closed_contains_Inf_cl:
wenzelm@53788
    83
  fixes S :: "'a::{complete_linorder,linorder_topology,second_countable_topology} set"
wenzelm@53788
    84
  assumes "closed S"
wenzelm@53788
    85
    and "S \<noteq> {}"
wenzelm@53788
    86
  shows "Inf S \<in> S"
hoelzl@51351
    87
proof -
hoelzl@51351
    88
  from compact_eq_closed[of S] compact_attains_inf[of S] assms
wenzelm@53788
    89
  obtain s where S: "s \<in> S" "\<forall>t\<in>S. s \<le> t"
wenzelm@53788
    90
    by auto
wenzelm@53374
    91
  then have "Inf S = s"
hoelzl@51351
    92
    by (auto intro!: Inf_eqI)
wenzelm@53374
    93
  with S show ?thesis
hoelzl@51351
    94
    by simp
hoelzl@51351
    95
qed
hoelzl@51351
    96
wenzelm@53788
    97
lemma ereal_dense3:
wenzelm@53788
    98
  fixes x y :: ereal
wenzelm@53788
    99
  shows "x < y \<Longrightarrow> \<exists>r::rat. x < real_of_rat r \<and> real_of_rat r < y"
hoelzl@51351
   100
proof (cases x y rule: ereal2_cases, simp_all)
wenzelm@53788
   101
  fix r q :: real
wenzelm@53788
   102
  assume "r < q"
wenzelm@53788
   103
  from Rats_dense_in_real[OF this] show "\<exists>x. r < real_of_rat x \<and> real_of_rat x < q"
hoelzl@51351
   104
    by (fastforce simp: Rats_def)
hoelzl@51351
   105
next
wenzelm@53788
   106
  fix r :: real
wenzelm@53788
   107
  show "\<exists>x. r < real_of_rat x" "\<exists>x. real_of_rat x < r"
hoelzl@51351
   108
    using gt_ex[of r] lt_ex[of r] Rats_dense_in_real
hoelzl@51351
   109
    by (auto simp: Rats_def)
hoelzl@51351
   110
qed
hoelzl@51351
   111
hoelzl@51351
   112
instance ereal :: second_countable_topology
hoelzl@51351
   113
proof (default, intro exI conjI)
hoelzl@51351
   114
  let ?B = "(\<Union>r\<in>\<rat>. {{..< r}, {r <..}} :: ereal set set)"
wenzelm@53788
   115
  show "countable ?B"
wenzelm@53788
   116
    by (auto intro: countable_rat)
hoelzl@51351
   117
  show "open = generate_topology ?B"
hoelzl@51351
   118
  proof (intro ext iffI)
wenzelm@53788
   119
    fix S :: "ereal set"
wenzelm@53788
   120
    assume "open S"
hoelzl@51351
   121
    then show "generate_topology ?B S"
hoelzl@51351
   122
      unfolding open_generated_order
hoelzl@51351
   123
    proof induct
hoelzl@51351
   124
      case (Basis b)
wenzelm@53788
   125
      then obtain e where "b = {..<e} \<or> b = {e<..}"
wenzelm@53788
   126
        by auto
hoelzl@51351
   127
      moreover have "{..<e} = \<Union>{{..<x}|x. x \<in> \<rat> \<and> x < e}" "{e<..} = \<Union>{{x<..}|x. x \<in> \<rat> \<and> e < x}"
hoelzl@51351
   128
        by (auto dest: ereal_dense3
hoelzl@51351
   129
                 simp del: ex_simps
hoelzl@51351
   130
                 simp add: ex_simps[symmetric] conj_commute Rats_def image_iff)
hoelzl@51351
   131
      ultimately show ?case
hoelzl@51351
   132
        by (auto intro: generate_topology.intros)
hoelzl@51351
   133
    qed (auto intro: generate_topology.intros)
hoelzl@51351
   134
  next
wenzelm@53788
   135
    fix S
wenzelm@53788
   136
    assume "generate_topology ?B S"
wenzelm@53788
   137
    then show "open S"
wenzelm@53788
   138
      by induct auto
hoelzl@51351
   139
  qed
hoelzl@51351
   140
qed
hoelzl@51351
   141
hoelzl@43920
   142
lemma continuous_on_ereal[intro, simp]: "continuous_on A ereal"
wenzelm@53788
   143
  unfolding continuous_on_topological open_ereal_def
wenzelm@53788
   144
  by auto
hoelzl@41980
   145
hoelzl@43920
   146
lemma continuous_at_ereal[intro, simp]: "continuous (at x) ereal"
wenzelm@53788
   147
  using continuous_on_eq_continuous_at[of UNIV]
wenzelm@53788
   148
  by auto
hoelzl@41980
   149
hoelzl@43920
   150
lemma continuous_within_ereal[intro, simp]: "x \<in> A \<Longrightarrow> continuous (at x within A) ereal"
wenzelm@53788
   151
  using continuous_on_eq_continuous_within[of A]
wenzelm@53788
   152
  by auto
hoelzl@41980
   153
hoelzl@43920
   154
lemma ereal_open_uminus:
hoelzl@43920
   155
  fixes S :: "ereal set"
wenzelm@53788
   156
  assumes "open S"
wenzelm@53788
   157
  shows "open (uminus ` S)"
hoelzl@51340
   158
  using `open S`[unfolded open_generated_order]
hoelzl@51340
   159
proof induct
hoelzl@51340
   160
  have "range uminus = (UNIV :: ereal set)"
hoelzl@51340
   161
    by (auto simp: image_iff ereal_uminus_eq_reorder)
wenzelm@53788
   162
  then show "open (range uminus :: ereal set)"
wenzelm@53788
   163
    by simp
hoelzl@51340
   164
qed (auto simp add: image_Union image_Int)
hoelzl@41980
   165
hoelzl@43920
   166
lemma ereal_uminus_complement:
hoelzl@43920
   167
  fixes S :: "ereal set"
hoelzl@41980
   168
  shows "uminus ` (- S) = - uminus ` S"
hoelzl@41980
   169
  by (auto intro!: bij_image_Compl_eq surjI[of _ uminus] simp: bij_betw_def)
hoelzl@41980
   170
hoelzl@43920
   171
lemma ereal_closed_uminus:
hoelzl@43920
   172
  fixes S :: "ereal set"
hoelzl@41980
   173
  assumes "closed S"
hoelzl@41980
   174
  shows "closed (uminus ` S)"
wenzelm@53788
   175
  using assms
wenzelm@53788
   176
  unfolding closed_def ereal_uminus_complement[symmetric]
wenzelm@53788
   177
  by (rule ereal_open_uminus)
hoelzl@41980
   178
hoelzl@43920
   179
lemma ereal_open_closed_aux:
hoelzl@43920
   180
  fixes S :: "ereal set"
wenzelm@53788
   181
  assumes "open S"
wenzelm@53788
   182
    and "closed S"
wenzelm@53788
   183
    and S: "(-\<infinity>) \<notin> S"
hoelzl@41980
   184
  shows "S = {}"
wenzelm@49664
   185
proof (rule ccontr)
wenzelm@53788
   186
  assume "\<not> ?thesis"
wenzelm@53788
   187
  then have *: "Inf S \<in> S"
wenzelm@53788
   188
    by (metis assms(2) closed_contains_Inf_cl)
wenzelm@53788
   189
  {
wenzelm@53788
   190
    assume "Inf S = -\<infinity>"
wenzelm@53788
   191
    then have False
wenzelm@53788
   192
      using * assms(3) by auto
wenzelm@53788
   193
  }
hoelzl@41980
   194
  moreover
wenzelm@53788
   195
  {
wenzelm@53788
   196
    assume "Inf S = \<infinity>"
wenzelm@53788
   197
    then have "S = {\<infinity>}"
wenzelm@53788
   198
      by (metis Inf_eq_PInfty `S \<noteq> {}`)
wenzelm@53788
   199
    then have False
wenzelm@53788
   200
      by (metis assms(1) not_open_singleton)
wenzelm@53788
   201
  }
hoelzl@41980
   202
  moreover
wenzelm@53788
   203
  {
wenzelm@53788
   204
    assume fin: "\<bar>Inf S\<bar> \<noteq> \<infinity>"
wenzelm@53788
   205
    from ereal_open_cont_interval[OF assms(1) * fin]
wenzelm@53788
   206
    obtain e where e: "e > 0" "{Inf S - e<..<Inf S + e} \<subseteq> S" .
wenzelm@53788
   207
    then obtain b where b: "Inf S - e < b" "b < Inf S"
wenzelm@53788
   208
      using fin ereal_between[of "Inf S" e] dense[of "Inf S - e"]
noschinl@44918
   209
      by auto
wenzelm@53788
   210
    then have "b: {Inf S - e <..< Inf S + e}"
wenzelm@53788
   211
      using e fin ereal_between[of "Inf S" e]
wenzelm@53788
   212
      by auto
wenzelm@53788
   213
    then have "b \<in> S"
wenzelm@53788
   214
      using e by auto
wenzelm@53788
   215
    then have False
wenzelm@53788
   216
      using b by (metis complete_lattice_class.Inf_lower leD)
wenzelm@53788
   217
  }
wenzelm@53788
   218
  ultimately show False
wenzelm@53788
   219
    by auto
hoelzl@41980
   220
qed
hoelzl@41980
   221
hoelzl@43920
   222
lemma ereal_open_closed:
hoelzl@43920
   223
  fixes S :: "ereal set"
wenzelm@53788
   224
  shows "open S \<and> closed S \<longleftrightarrow> S = {} \<or> S = UNIV"
wenzelm@49664
   225
proof -
wenzelm@53788
   226
  {
wenzelm@53788
   227
    assume lhs: "open S \<and> closed S"
wenzelm@53788
   228
    {
wenzelm@53788
   229
      assume "-\<infinity> \<notin> S"
wenzelm@53788
   230
      then have "S = {}"
wenzelm@53788
   231
        using lhs ereal_open_closed_aux by auto
wenzelm@53788
   232
    }
wenzelm@49664
   233
    moreover
wenzelm@53788
   234
    {
wenzelm@53788
   235
      assume "-\<infinity> \<in> S"
wenzelm@53788
   236
      then have "- S = {}"
wenzelm@53788
   237
        using lhs ereal_open_closed_aux[of "-S"] by auto
wenzelm@53788
   238
    }
wenzelm@53788
   239
    ultimately have "S = {} \<or> S = UNIV"
wenzelm@53788
   240
      by auto
wenzelm@53788
   241
  }
wenzelm@53788
   242
  then show ?thesis
wenzelm@53788
   243
    by auto
hoelzl@41980
   244
qed
hoelzl@41980
   245
hoelzl@43920
   246
lemma ereal_open_affinity_pos:
hoelzl@43923
   247
  fixes S :: "ereal set"
wenzelm@53788
   248
  assumes "open S"
wenzelm@53788
   249
    and m: "m \<noteq> \<infinity>" "0 < m"
wenzelm@53788
   250
    and t: "\<bar>t\<bar> \<noteq> \<infinity>"
hoelzl@41980
   251
  shows "open ((\<lambda>x. m * x + t) ` S)"
hoelzl@41980
   252
proof -
wenzelm@53788
   253
  obtain r where r[simp]: "m = ereal r"
wenzelm@53788
   254
    using m by (cases m) auto
wenzelm@53788
   255
  obtain p where p[simp]: "t = ereal p"
wenzelm@53788
   256
    using t by auto
wenzelm@53788
   257
  have "r \<noteq> 0" "0 < r" and m': "m \<noteq> \<infinity>" "m \<noteq> -\<infinity>" "m \<noteq> 0"
wenzelm@53788
   258
    using m by auto
wenzelm@55522
   259
  from `open S` [THEN ereal_openE]
wenzelm@55522
   260
  obtain l u where T:
wenzelm@55522
   261
      "open (ereal -` S)"
wenzelm@55522
   262
      "\<infinity> \<in> S \<Longrightarrow> {ereal l<..} \<subseteq> S"
wenzelm@55522
   263
      "- \<infinity> \<in> S \<Longrightarrow> {..<ereal u} \<subseteq> S"
wenzelm@55522
   264
    by blast
hoelzl@41980
   265
  let ?f = "(\<lambda>x. m * x + t)"
wenzelm@49664
   266
  show ?thesis
wenzelm@49664
   267
    unfolding open_ereal_def
hoelzl@41980
   268
  proof (intro conjI impI exI subsetI)
hoelzl@43920
   269
    have "ereal -` ?f ` S = (\<lambda>x. r * x + p) ` (ereal -` S)"
hoelzl@41980
   270
    proof safe
wenzelm@49664
   271
      fix x y
wenzelm@49664
   272
      assume "ereal y = m * x + t" "x \<in> S"
hoelzl@43920
   273
      then show "y \<in> (\<lambda>x. r * x + p) ` ereal -` S"
hoelzl@41980
   274
        using `r \<noteq> 0` by (cases x) (auto intro!: image_eqI[of _ _ "real x"] split: split_if_asm)
hoelzl@41980
   275
    qed force
hoelzl@43920
   276
    then show "open (ereal -` ?f ` S)"
wenzelm@53788
   277
      using open_affinity[OF T(1) `r \<noteq> 0`]
wenzelm@53788
   278
      by (auto simp: ac_simps)
hoelzl@41980
   279
  next
wenzelm@49664
   280
    assume "\<infinity> \<in> ?f`S"
wenzelm@53788
   281
    with `0 < r` have "\<infinity> \<in> S"
wenzelm@53788
   282
      by auto
wenzelm@49664
   283
    fix x
wenzelm@49664
   284
    assume "x \<in> {ereal (r * l + p)<..}"
wenzelm@53788
   285
    then have [simp]: "ereal (r * l + p) < x"
wenzelm@53788
   286
      by auto
hoelzl@41980
   287
    show "x \<in> ?f`S"
hoelzl@41980
   288
    proof (rule image_eqI)
hoelzl@41980
   289
      show "x = m * ((x - t) / m) + t"
wenzelm@53788
   290
        using m t
wenzelm@53788
   291
        by (cases rule: ereal3_cases[of m x t]) auto
wenzelm@53788
   292
      have "ereal l < (x - t) / m"
wenzelm@53788
   293
        using m t
wenzelm@53788
   294
        by (simp add: ereal_less_divide_pos ereal_less_minus)
wenzelm@53788
   295
      then show "(x - t) / m \<in> S"
wenzelm@53788
   296
        using T(2)[OF `\<infinity> \<in> S`] by auto
hoelzl@41980
   297
    qed
hoelzl@41980
   298
  next
wenzelm@53788
   299
    assume "-\<infinity> \<in> ?f ` S"
wenzelm@53788
   300
    with `0 < r` have "-\<infinity> \<in> S"
wenzelm@53788
   301
      by auto
hoelzl@43920
   302
    fix x assume "x \<in> {..<ereal (r * u + p)}"
wenzelm@53788
   303
    then have [simp]: "x < ereal (r * u + p)"
wenzelm@53788
   304
      by auto
hoelzl@41980
   305
    show "x \<in> ?f`S"
hoelzl@41980
   306
    proof (rule image_eqI)
hoelzl@41980
   307
      show "x = m * ((x - t) / m) + t"
wenzelm@53788
   308
        using m t
wenzelm@53788
   309
        by (cases rule: ereal3_cases[of m x t]) auto
hoelzl@43920
   310
      have "(x - t)/m < ereal u"
wenzelm@53788
   311
        using m t
wenzelm@53788
   312
        by (simp add: ereal_divide_less_pos ereal_minus_less)
wenzelm@53788
   313
      then show "(x - t)/m \<in> S"
wenzelm@53788
   314
        using T(3)[OF `-\<infinity> \<in> S`]
wenzelm@53788
   315
        by auto
hoelzl@41980
   316
    qed
hoelzl@41980
   317
  qed
hoelzl@41980
   318
qed
hoelzl@41980
   319
hoelzl@43920
   320
lemma ereal_open_affinity:
hoelzl@43923
   321
  fixes S :: "ereal set"
wenzelm@49664
   322
  assumes "open S"
wenzelm@49664
   323
    and m: "\<bar>m\<bar> \<noteq> \<infinity>" "m \<noteq> 0"
wenzelm@49664
   324
    and t: "\<bar>t\<bar> \<noteq> \<infinity>"
hoelzl@41980
   325
  shows "open ((\<lambda>x. m * x + t) ` S)"
hoelzl@41980
   326
proof cases
wenzelm@49664
   327
  assume "0 < m"
wenzelm@49664
   328
  then show ?thesis
wenzelm@53788
   329
    using ereal_open_affinity_pos[OF `open S` _ _ t, of m] m
wenzelm@53788
   330
    by auto
hoelzl@41980
   331
next
hoelzl@41980
   332
  assume "\<not> 0 < m" then
wenzelm@53788
   333
  have "0 < -m"
wenzelm@53788
   334
    using `m \<noteq> 0`
wenzelm@53788
   335
    by (cases m) auto
wenzelm@53788
   336
  then have m: "-m \<noteq> \<infinity>" "0 < -m"
wenzelm@53788
   337
    using `\<bar>m\<bar> \<noteq> \<infinity>`
hoelzl@43920
   338
    by (auto simp: ereal_uminus_eq_reorder)
wenzelm@53788
   339
  from ereal_open_affinity_pos[OF ereal_open_uminus[OF `open S`] m t] show ?thesis
wenzelm@53788
   340
    unfolding image_image by simp
hoelzl@41980
   341
qed
hoelzl@41980
   342
hoelzl@43920
   343
lemma ereal_lim_mult:
hoelzl@43920
   344
  fixes X :: "'a \<Rightarrow> ereal"
wenzelm@49664
   345
  assumes lim: "(X ---> L) net"
wenzelm@49664
   346
    and a: "\<bar>a\<bar> \<noteq> \<infinity>"
hoelzl@41980
   347
  shows "((\<lambda>i. a * X i) ---> a * L) net"
hoelzl@41980
   348
proof cases
hoelzl@41980
   349
  assume "a \<noteq> 0"
hoelzl@41980
   350
  show ?thesis
hoelzl@41980
   351
  proof (rule topological_tendstoI)
wenzelm@49664
   352
    fix S
wenzelm@53788
   353
    assume "open S" and "a * L \<in> S"
hoelzl@41980
   354
    have "a * L / a = L"
wenzelm@53788
   355
      using `a \<noteq> 0` a
wenzelm@53788
   356
      by (cases rule: ereal2_cases[of a L]) auto
hoelzl@41980
   357
    then have L: "L \<in> ((\<lambda>x. x / a) ` S)"
wenzelm@53788
   358
      using `a * L \<in> S`
wenzelm@53788
   359
      by (force simp: image_iff)
hoelzl@41980
   360
    moreover have "open ((\<lambda>x. x / a) ` S)"
hoelzl@43920
   361
      using ereal_open_affinity[OF `open S`, of "inverse a" 0] `a \<noteq> 0` a
hoelzl@43920
   362
      by (auto simp: ereal_divide_eq ereal_inverse_eq_0 divide_ereal_def ac_simps)
hoelzl@41980
   363
    note * = lim[THEN topological_tendstoD, OF this L]
wenzelm@53788
   364
    {
wenzelm@53788
   365
      fix x
wenzelm@49664
   366
      from a `a \<noteq> 0` have "a * (x / a) = x"
wenzelm@53788
   367
        by (cases rule: ereal2_cases[of a x]) auto
wenzelm@53788
   368
    }
hoelzl@41980
   369
    note this[simp]
hoelzl@41980
   370
    show "eventually (\<lambda>x. a * X x \<in> S) net"
hoelzl@41980
   371
      by (rule eventually_mono[OF _ *]) auto
hoelzl@41980
   372
  qed
noschinl@44918
   373
qed auto
hoelzl@41980
   374
hoelzl@43920
   375
lemma ereal_lim_uminus:
wenzelm@49664
   376
  fixes X :: "'a \<Rightarrow> ereal"
wenzelm@53788
   377
  shows "((\<lambda>i. - X i) ---> - L) net \<longleftrightarrow> (X ---> L) net"
hoelzl@43920
   378
  using ereal_lim_mult[of X L net "ereal (-1)"]
wenzelm@49664
   379
    ereal_lim_mult[of "(\<lambda>i. - X i)" "-L" net "ereal (-1)"]
hoelzl@41980
   380
  by (auto simp add: algebra_simps)
hoelzl@41980
   381
wenzelm@53788
   382
lemma ereal_open_atLeast:
wenzelm@53788
   383
  fixes x :: ereal
wenzelm@53788
   384
  shows "open {x..} \<longleftrightarrow> x = -\<infinity>"
hoelzl@41980
   385
proof
wenzelm@53788
   386
  assume "x = -\<infinity>"
wenzelm@53788
   387
  then have "{x..} = UNIV"
wenzelm@53788
   388
    by auto
wenzelm@53788
   389
  then show "open {x..}"
wenzelm@53788
   390
    by auto
hoelzl@41980
   391
next
hoelzl@41980
   392
  assume "open {x..}"
wenzelm@53788
   393
  then have "open {x..} \<and> closed {x..}"
wenzelm@53788
   394
    by auto
wenzelm@53788
   395
  then have "{x..} = UNIV"
wenzelm@53788
   396
    unfolding ereal_open_closed by auto
wenzelm@53788
   397
  then show "x = -\<infinity>"
wenzelm@53788
   398
    by (simp add: bot_ereal_def atLeast_eq_UNIV_iff)
hoelzl@41980
   399
qed
hoelzl@41980
   400
wenzelm@53788
   401
lemma open_uminus_iff:
wenzelm@53788
   402
  fixes S :: "ereal set"
wenzelm@53788
   403
  shows "open (uminus ` S) \<longleftrightarrow> open S"
wenzelm@53788
   404
  using ereal_open_uminus[of S] ereal_open_uminus[of "uminus ` S"]
wenzelm@53788
   405
  by auto
hoelzl@41980
   406
hoelzl@43920
   407
lemma ereal_Liminf_uminus:
wenzelm@53788
   408
  fixes f :: "'a \<Rightarrow> ereal"
wenzelm@53788
   409
  shows "Liminf net (\<lambda>x. - (f x)) = - Limsup net f"
hoelzl@43920
   410
  using ereal_Limsup_uminus[of _ "(\<lambda>x. - (f x))"] by auto
hoelzl@41980
   411
hoelzl@43920
   412
lemma ereal_Lim_uminus:
wenzelm@49664
   413
  fixes f :: "'a \<Rightarrow> ereal"
wenzelm@49664
   414
  shows "(f ---> f0) net \<longleftrightarrow> ((\<lambda>x. - f x) ---> - f0) net"
hoelzl@41980
   415
  using
hoelzl@43920
   416
    ereal_lim_mult[of f f0 net "- 1"]
hoelzl@43920
   417
    ereal_lim_mult[of "\<lambda>x. - (f x)" "-f0" net "- 1"]
hoelzl@43920
   418
  by (auto simp: ereal_uminus_reorder)
hoelzl@41980
   419
hoelzl@41980
   420
lemma Liminf_PInfty:
hoelzl@43920
   421
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@41980
   422
  assumes "\<not> trivial_limit net"
hoelzl@41980
   423
  shows "(f ---> \<infinity>) net \<longleftrightarrow> Liminf net f = \<infinity>"
wenzelm@53788
   424
  unfolding tendsto_iff_Liminf_eq_Limsup[OF assms]
wenzelm@53788
   425
  using Liminf_le_Limsup[OF assms, of f]
wenzelm@53788
   426
  by auto
hoelzl@41980
   427
hoelzl@41980
   428
lemma Limsup_MInfty:
hoelzl@43920
   429
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@41980
   430
  assumes "\<not> trivial_limit net"
hoelzl@41980
   431
  shows "(f ---> -\<infinity>) net \<longleftrightarrow> Limsup net f = -\<infinity>"
wenzelm@53788
   432
  unfolding tendsto_iff_Liminf_eq_Limsup[OF assms]
wenzelm@53788
   433
  using Liminf_le_Limsup[OF assms, of f]
wenzelm@53788
   434
  by auto
hoelzl@41980
   435
hoelzl@50104
   436
lemma convergent_ereal:
wenzelm@53788
   437
  fixes X :: "nat \<Rightarrow> 'a :: {complete_linorder,linorder_topology}"
hoelzl@50104
   438
  shows "convergent X \<longleftrightarrow> limsup X = liminf X"
hoelzl@51340
   439
  using tendsto_iff_Liminf_eq_Limsup[of sequentially]
hoelzl@50104
   440
  by (auto simp: convergent_def)
hoelzl@50104
   441
hoelzl@57447
   442
lemma limsup_le_liminf_real:
hoelzl@57447
   443
  fixes X :: "nat \<Rightarrow> real" and L :: real
hoelzl@57447
   444
  assumes 1: "limsup X \<le> L" and 2: "L \<le> liminf X"
hoelzl@57447
   445
  shows "X ----> L"
hoelzl@57447
   446
proof -
hoelzl@57447
   447
  from 1 2 have "limsup X \<le> liminf X" by auto
hoelzl@57447
   448
  hence 3: "limsup X = liminf X"  
hoelzl@57447
   449
    apply (subst eq_iff, rule conjI)
hoelzl@57447
   450
    by (rule Liminf_le_Limsup, auto)
hoelzl@57447
   451
  hence 4: "convergent (\<lambda>n. ereal (X n))"
hoelzl@57447
   452
    by (subst convergent_ereal)
hoelzl@57447
   453
  hence "limsup X = lim (\<lambda>n. ereal(X n))"
hoelzl@57447
   454
    by (rule convergent_limsup_cl)
hoelzl@57447
   455
  also from 1 2 3 have "limsup X = L" by auto
hoelzl@57447
   456
  finally have "lim (\<lambda>n. ereal(X n)) = L" ..
hoelzl@57447
   457
  hence "(\<lambda>n. ereal (X n)) ----> L"
hoelzl@57447
   458
    apply (elim subst)
hoelzl@57447
   459
    by (subst convergent_LIMSEQ_iff [symmetric], rule 4) 
hoelzl@57447
   460
  thus ?thesis by simp
hoelzl@57447
   461
qed
hoelzl@57447
   462
hoelzl@41980
   463
lemma liminf_PInfty:
hoelzl@51351
   464
  fixes X :: "nat \<Rightarrow> ereal"
hoelzl@51351
   465
  shows "X ----> \<infinity> \<longleftrightarrow> liminf X = \<infinity>"
wenzelm@49664
   466
  by (metis Liminf_PInfty trivial_limit_sequentially)
hoelzl@41980
   467
hoelzl@41980
   468
lemma limsup_MInfty:
hoelzl@51351
   469
  fixes X :: "nat \<Rightarrow> ereal"
hoelzl@51351
   470
  shows "X ----> -\<infinity> \<longleftrightarrow> limsup X = -\<infinity>"
wenzelm@49664
   471
  by (metis Limsup_MInfty trivial_limit_sequentially)
hoelzl@41980
   472
hoelzl@43920
   473
lemma ereal_lim_mono:
wenzelm@53788
   474
  fixes X Y :: "nat \<Rightarrow> 'a::linorder_topology"
wenzelm@53788
   475
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n \<le> Y n"
wenzelm@53788
   476
    and "X ----> x"
wenzelm@53788
   477
    and "Y ----> y"
wenzelm@53788
   478
  shows "x \<le> y"
hoelzl@51000
   479
  using assms(1) by (intro LIMSEQ_le[OF assms(2,3)]) auto
hoelzl@41980
   480
hoelzl@43920
   481
lemma incseq_le_ereal:
hoelzl@51351
   482
  fixes X :: "nat \<Rightarrow> 'a::linorder_topology"
wenzelm@53788
   483
  assumes inc: "incseq X"
wenzelm@53788
   484
    and lim: "X ----> L"
hoelzl@41980
   485
  shows "X N \<le> L"
wenzelm@53788
   486
  using inc
wenzelm@53788
   487
  by (intro ereal_lim_mono[of N, OF _ tendsto_const lim]) (simp add: incseq_def)
hoelzl@41980
   488
wenzelm@49664
   489
lemma decseq_ge_ereal:
wenzelm@49664
   490
  assumes dec: "decseq X"
hoelzl@51351
   491
    and lim: "X ----> (L::'a::linorder_topology)"
wenzelm@53788
   492
  shows "X N \<ge> L"
wenzelm@49664
   493
  using dec by (intro ereal_lim_mono[of N, OF _ lim tendsto_const]) (simp add: decseq_def)
hoelzl@41980
   494
hoelzl@41980
   495
lemma bounded_abs:
wenzelm@53788
   496
  fixes a :: real
wenzelm@53788
   497
  assumes "a \<le> x"
wenzelm@53788
   498
    and "x \<le> b"
wenzelm@53788
   499
  shows "abs x \<le> max (abs a) (abs b)"
wenzelm@49664
   500
  by (metis abs_less_iff assms leI le_max_iff_disj
wenzelm@49664
   501
    less_eq_real_def less_le_not_le less_minus_iff minus_minus)
hoelzl@41980
   502
hoelzl@43920
   503
lemma ereal_Sup_lim:
wenzelm@53788
   504
  fixes a :: "'a::{complete_linorder,linorder_topology}"
wenzelm@53788
   505
  assumes "\<And>n. b n \<in> s"
wenzelm@53788
   506
    and "b ----> a"
hoelzl@41980
   507
  shows "a \<le> Sup s"
wenzelm@49664
   508
  by (metis Lim_bounded_ereal assms complete_lattice_class.Sup_upper)
hoelzl@41980
   509
hoelzl@43920
   510
lemma ereal_Inf_lim:
wenzelm@53788
   511
  fixes a :: "'a::{complete_linorder,linorder_topology}"
wenzelm@53788
   512
  assumes "\<And>n. b n \<in> s"
wenzelm@53788
   513
    and "b ----> a"
hoelzl@41980
   514
  shows "Inf s \<le> a"
wenzelm@49664
   515
  by (metis Lim_bounded2_ereal assms complete_lattice_class.Inf_lower)
hoelzl@41980
   516
hoelzl@43920
   517
lemma SUP_Lim_ereal:
wenzelm@53788
   518
  fixes X :: "nat \<Rightarrow> 'a::{complete_linorder,linorder_topology}"
wenzelm@53788
   519
  assumes inc: "incseq X"
wenzelm@53788
   520
    and l: "X ----> l"
wenzelm@53788
   521
  shows "(SUP n. X n) = l"
wenzelm@53788
   522
  using LIMSEQ_SUP[OF inc] tendsto_unique[OF trivial_limit_sequentially l]
wenzelm@53788
   523
  by simp
hoelzl@41980
   524
hoelzl@51351
   525
lemma INF_Lim_ereal:
wenzelm@53788
   526
  fixes X :: "nat \<Rightarrow> 'a::{complete_linorder,linorder_topology}"
wenzelm@53788
   527
  assumes dec: "decseq X"
wenzelm@53788
   528
    and l: "X ----> l"
wenzelm@53788
   529
  shows "(INF n. X n) = l"
wenzelm@53788
   530
  using LIMSEQ_INF[OF dec] tendsto_unique[OF trivial_limit_sequentially l]
wenzelm@53788
   531
  by simp
hoelzl@41980
   532
hoelzl@41980
   533
lemma SUP_eq_LIMSEQ:
hoelzl@41980
   534
  assumes "mono f"
hoelzl@43920
   535
  shows "(SUP n. ereal (f n)) = ereal x \<longleftrightarrow> f ----> x"
hoelzl@41980
   536
proof
hoelzl@43920
   537
  have inc: "incseq (\<lambda>i. ereal (f i))"
hoelzl@41980
   538
    using `mono f` unfolding mono_def incseq_def by auto
wenzelm@53788
   539
  {
wenzelm@53788
   540
    assume "f ----> x"
wenzelm@53788
   541
    then have "(\<lambda>i. ereal (f i)) ----> ereal x"
wenzelm@53788
   542
      by auto
wenzelm@53788
   543
    from SUP_Lim_ereal[OF inc this] show "(SUP n. ereal (f n)) = ereal x" .
wenzelm@53788
   544
  next
wenzelm@53788
   545
    assume "(SUP n. ereal (f n)) = ereal x"
wenzelm@53788
   546
    with LIMSEQ_SUP[OF inc] show "f ----> x" by auto
wenzelm@53788
   547
  }
hoelzl@41980
   548
qed
hoelzl@41980
   549
hoelzl@43920
   550
lemma liminf_ereal_cminus:
wenzelm@49664
   551
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@49664
   552
  assumes "c \<noteq> -\<infinity>"
hoelzl@42950
   553
  shows "liminf (\<lambda>x. c - f x) = c - limsup f"
hoelzl@42950
   554
proof (cases c)
wenzelm@49664
   555
  case PInf
wenzelm@53788
   556
  then show ?thesis
wenzelm@53788
   557
    by (simp add: Liminf_const)
hoelzl@42950
   558
next
wenzelm@49664
   559
  case (real r)
wenzelm@49664
   560
  then show ?thesis
haftmann@56212
   561
    unfolding liminf_SUP_INF limsup_INF_SUP
haftmann@56212
   562
    apply (subst INF_ereal_cminus)
hoelzl@42950
   563
    apply auto
haftmann@56212
   564
    apply (subst SUP_ereal_cminus)
hoelzl@42950
   565
    apply auto
hoelzl@42950
   566
    done
hoelzl@42950
   567
qed (insert `c \<noteq> -\<infinity>`, simp)
hoelzl@42950
   568
wenzelm@49664
   569
hoelzl@41980
   570
subsubsection {* Continuity *}
hoelzl@41980
   571
hoelzl@43920
   572
lemma continuous_at_of_ereal:
hoelzl@43920
   573
  fixes x0 :: ereal
hoelzl@41980
   574
  assumes "\<bar>x0\<bar> \<noteq> \<infinity>"
hoelzl@41980
   575
  shows "continuous (at x0) real"
wenzelm@49664
   576
proof -
wenzelm@53788
   577
  {
wenzelm@53788
   578
    fix T
wenzelm@53788
   579
    assume T: "open T" "real x0 \<in> T"
wenzelm@53788
   580
    def S \<equiv> "ereal ` T"
wenzelm@53788
   581
    then have "ereal (real x0) \<in> S"
wenzelm@53788
   582
      using T by auto
wenzelm@53788
   583
    then have "x0 \<in> S"
wenzelm@53788
   584
      using assms ereal_real by auto
wenzelm@53788
   585
    moreover have "open S"
wenzelm@53788
   586
      using open_ereal S_def T by auto
wenzelm@53788
   587
    moreover have "\<forall>y\<in>S. real y \<in> T"
wenzelm@53788
   588
      using S_def T by auto
wenzelm@53788
   589
    ultimately have "\<exists>S. x0 \<in> S \<and> open S \<and> (\<forall>y\<in>S. real y \<in> T)"
wenzelm@53788
   590
      by auto
wenzelm@49664
   591
  }
wenzelm@53788
   592
  then show ?thesis
wenzelm@53788
   593
    unfolding continuous_at_open by blast
hoelzl@41980
   594
qed
hoelzl@41980
   595
hoelzl@57447
   596
lemma nhds_ereal: "nhds (ereal r) = filtermap ereal (nhds r)"
hoelzl@57447
   597
  by (simp add: filtermap_nhds_open_map open_ereal continuous_at_of_ereal)
hoelzl@57447
   598
hoelzl@57447
   599
lemma at_ereal: "at (ereal r) = filtermap ereal (at r)"
hoelzl@57447
   600
  by (simp add: filter_eq_iff eventually_at_filter nhds_ereal eventually_filtermap)
hoelzl@57447
   601
hoelzl@57447
   602
lemma at_left_ereal: "at_left (ereal r) = filtermap ereal (at_left r)"
hoelzl@57447
   603
  by (simp add: filter_eq_iff eventually_at_filter nhds_ereal eventually_filtermap)
hoelzl@57447
   604
hoelzl@57447
   605
lemma at_right_ereal: "at_right (ereal r) = filtermap ereal (at_right r)"
hoelzl@57447
   606
  by (simp add: filter_eq_iff eventually_at_filter nhds_ereal eventually_filtermap)
hoelzl@57447
   607
hoelzl@57447
   608
lemma
hoelzl@57447
   609
  shows at_left_PInf: "at_left \<infinity> = filtermap ereal at_top"
hoelzl@57447
   610
    and at_right_MInf: "at_right (-\<infinity>) = filtermap ereal at_bot"
hoelzl@57447
   611
  unfolding filter_eq_iff eventually_filtermap eventually_at_top_dense eventually_at_bot_dense
hoelzl@57447
   612
    eventually_at_left[OF ereal_less(5)] eventually_at_right[OF ereal_less(6)]
hoelzl@57447
   613
  by (auto simp add: ereal_all_split ereal_ex_split)
hoelzl@57447
   614
hoelzl@57447
   615
lemma ereal_tendsto_simps1:
hoelzl@57447
   616
  "((f \<circ> real) ---> y) (at_left (ereal x)) \<longleftrightarrow> (f ---> y) (at_left x)"
hoelzl@57447
   617
  "((f \<circ> real) ---> y) (at_right (ereal x)) \<longleftrightarrow> (f ---> y) (at_right x)"
hoelzl@57447
   618
  "((f \<circ> real) ---> y) (at_left (\<infinity>::ereal)) \<longleftrightarrow> (f ---> y) at_top"
hoelzl@57447
   619
  "((f \<circ> real) ---> y) (at_right (-\<infinity>::ereal)) \<longleftrightarrow> (f ---> y) at_bot"
hoelzl@57447
   620
  unfolding tendsto_compose_filtermap at_left_ereal at_right_ereal at_left_PInf at_right_MInf
hoelzl@57447
   621
  by (auto simp: filtermap_filtermap filtermap_ident)
hoelzl@57447
   622
hoelzl@57447
   623
lemma ereal_tendsto_simps2:
hoelzl@57447
   624
  "((ereal \<circ> f) ---> ereal a) F \<longleftrightarrow> (f ---> a) F"
hoelzl@57447
   625
  "((ereal \<circ> f) ---> \<infinity>) F \<longleftrightarrow> (LIM x F. f x :> at_top)"
hoelzl@57447
   626
  "((ereal \<circ> f) ---> -\<infinity>) F \<longleftrightarrow> (LIM x F. f x :> at_bot)"
hoelzl@57447
   627
  unfolding tendsto_PInfty filterlim_at_top_dense tendsto_MInfty filterlim_at_bot_dense
hoelzl@57447
   628
  using lim_ereal by (simp_all add: comp_def)
hoelzl@57447
   629
hoelzl@57447
   630
lemmas ereal_tendsto_simps = ereal_tendsto_simps1 ereal_tendsto_simps2
hoelzl@57447
   631
hoelzl@43920
   632
lemma continuous_at_iff_ereal:
wenzelm@53788
   633
  fixes f :: "'a::t2_space \<Rightarrow> real"
hoelzl@57447
   634
  shows "continuous (at x0 within s) f \<longleftrightarrow> continuous (at x0 within s) (ereal \<circ> f)"
hoelzl@57447
   635
  unfolding continuous_within comp_def lim_ereal ..
hoelzl@41980
   636
hoelzl@43920
   637
lemma continuous_on_iff_ereal:
wenzelm@49664
   638
  fixes f :: "'a::t2_space => real"
wenzelm@53788
   639
  assumes "open A"
wenzelm@53788
   640
  shows "continuous_on A f \<longleftrightarrow> continuous_on A (ereal \<circ> f)"
hoelzl@57447
   641
  unfolding continuous_on_def comp_def lim_ereal ..
hoelzl@41980
   642
wenzelm@53788
   643
lemma continuous_on_real: "continuous_on (UNIV - {\<infinity>, -\<infinity>::ereal}) real"
wenzelm@53788
   644
  using continuous_at_of_ereal continuous_on_eq_continuous_at open_image_ereal
wenzelm@53788
   645
  by auto
hoelzl@41980
   646
hoelzl@41980
   647
lemma continuous_on_iff_real:
wenzelm@53788
   648
  fixes f :: "'a::t2_space \<Rightarrow> ereal"
hoelzl@57447
   649
  assumes *: "\<And>x. x \<in> A \<Longrightarrow> \<bar>f x\<bar> \<noteq> \<infinity>"
hoelzl@41980
   650
  shows "continuous_on A f \<longleftrightarrow> continuous_on A (real \<circ> f)"
wenzelm@49664
   651
proof -
wenzelm@53788
   652
  have "f ` A \<subseteq> UNIV - {\<infinity>, -\<infinity>}"
wenzelm@53788
   653
    using assms by force
wenzelm@49664
   654
  then have *: "continuous_on (f ` A) real"
wenzelm@49664
   655
    using continuous_on_real by (simp add: continuous_on_subset)
wenzelm@53788
   656
  have **: "continuous_on ((real \<circ> f) ` A) ereal"
wenzelm@53788
   657
    using continuous_on_ereal continuous_on_subset[of "UNIV" "ereal" "(real \<circ> f) ` A"]
wenzelm@53788
   658
    by blast
wenzelm@53788
   659
  {
wenzelm@53788
   660
    assume "continuous_on A f"
wenzelm@53788
   661
    then have "continuous_on A (real \<circ> f)"
wenzelm@49664
   662
      apply (subst continuous_on_compose)
wenzelm@53788
   663
      using *
wenzelm@53788
   664
      apply auto
wenzelm@49664
   665
      done
wenzelm@49664
   666
  }
wenzelm@49664
   667
  moreover
wenzelm@53788
   668
  {
wenzelm@53788
   669
    assume "continuous_on A (real \<circ> f)"
wenzelm@53788
   670
    then have "continuous_on A (ereal \<circ> (real \<circ> f))"
wenzelm@49664
   671
      apply (subst continuous_on_compose)
wenzelm@53788
   672
      using **
wenzelm@53788
   673
      apply auto
wenzelm@49664
   674
      done
wenzelm@49664
   675
    then have "continuous_on A f"
wenzelm@53788
   676
      apply (subst continuous_on_eq[of A "ereal \<circ> (real \<circ> f)" f])
wenzelm@53788
   677
      using assms ereal_real
wenzelm@53788
   678
      apply auto
wenzelm@49664
   679
      done
wenzelm@49664
   680
  }
wenzelm@53788
   681
  ultimately show ?thesis
wenzelm@53788
   682
    by auto
hoelzl@41980
   683
qed
hoelzl@41980
   684
hoelzl@41980
   685
lemma continuous_at_const:
wenzelm@53788
   686
  fixes f :: "'a::t2_space \<Rightarrow> ereal"
wenzelm@53788
   687
  assumes "\<forall>x. f x = C"
wenzelm@53788
   688
  shows "\<forall>x. continuous (at x) f"
wenzelm@53788
   689
  unfolding continuous_at_open
wenzelm@53788
   690
  using assms t1_space
wenzelm@53788
   691
  by auto
hoelzl@41980
   692
hoelzl@41980
   693
lemma mono_closed_real:
hoelzl@41980
   694
  fixes S :: "real set"
wenzelm@53788
   695
  assumes mono: "\<forall>y z. y \<in> S \<and> y \<le> z \<longrightarrow> z \<in> S"
wenzelm@49664
   696
    and "closed S"
wenzelm@53788
   697
  shows "S = {} \<or> S = UNIV \<or> (\<exists>a. S = {a..})"
wenzelm@49664
   698
proof -
wenzelm@53788
   699
  {
wenzelm@53788
   700
    assume "S \<noteq> {}"
wenzelm@53788
   701
    { assume ex: "\<exists>B. \<forall>x\<in>S. B \<le> x"
wenzelm@53788
   702
      then have *: "\<forall>x\<in>S. Inf S \<le> x"
hoelzl@54258
   703
        using cInf_lower[of _ S] ex by (metis bdd_below_def)
wenzelm@53788
   704
      then have "Inf S \<in> S"
wenzelm@53788
   705
        apply (subst closed_contains_Inf)
wenzelm@53788
   706
        using ex `S \<noteq> {}` `closed S`
wenzelm@53788
   707
        apply auto
wenzelm@53788
   708
        done
wenzelm@53788
   709
      then have "\<forall>x. Inf S \<le> x \<longleftrightarrow> x \<in> S"
wenzelm@53788
   710
        using mono[rule_format, of "Inf S"] *
wenzelm@53788
   711
        by auto
wenzelm@53788
   712
      then have "S = {Inf S ..}"
wenzelm@53788
   713
        by auto
wenzelm@53788
   714
      then have "\<exists>a. S = {a ..}"
wenzelm@53788
   715
        by auto
wenzelm@49664
   716
    }
wenzelm@49664
   717
    moreover
wenzelm@53788
   718
    {
wenzelm@53788
   719
      assume "\<not> (\<exists>B. \<forall>x\<in>S. B \<le> x)"
wenzelm@53788
   720
      then have nex: "\<forall>B. \<exists>x\<in>S. x < B"
wenzelm@53788
   721
        by (simp add: not_le)
wenzelm@53788
   722
      {
wenzelm@53788
   723
        fix y
wenzelm@53788
   724
        obtain x where "x\<in>S" and "x < y"
wenzelm@53788
   725
          using nex by auto
wenzelm@53788
   726
        then have "y \<in> S"
wenzelm@53788
   727
          using mono[rule_format, of x y] by auto
wenzelm@53788
   728
      }
wenzelm@53788
   729
      then have "S = UNIV"
wenzelm@53788
   730
        by auto
wenzelm@49664
   731
    }
wenzelm@53788
   732
    ultimately have "S = UNIV \<or> (\<exists>a. S = {a ..})"
wenzelm@53788
   733
      by blast
wenzelm@53788
   734
  }
wenzelm@53788
   735
  then show ?thesis
wenzelm@53788
   736
    by blast
hoelzl@41980
   737
qed
hoelzl@41980
   738
hoelzl@43920
   739
lemma mono_closed_ereal:
hoelzl@41980
   740
  fixes S :: "real set"
wenzelm@53788
   741
  assumes mono: "\<forall>y z. y \<in> S \<and> y \<le> z \<longrightarrow> z \<in> S"
wenzelm@49664
   742
    and "closed S"
wenzelm@53788
   743
  shows "\<exists>a. S = {x. a \<le> ereal x}"
wenzelm@49664
   744
proof -
wenzelm@53788
   745
  {
wenzelm@53788
   746
    assume "S = {}"
wenzelm@53788
   747
    then have ?thesis
wenzelm@53788
   748
      apply (rule_tac x=PInfty in exI)
wenzelm@53788
   749
      apply auto
wenzelm@53788
   750
      done
wenzelm@53788
   751
  }
wenzelm@49664
   752
  moreover
wenzelm@53788
   753
  {
wenzelm@53788
   754
    assume "S = UNIV"
wenzelm@53788
   755
    then have ?thesis
wenzelm@53788
   756
      apply (rule_tac x="-\<infinity>" in exI)
wenzelm@53788
   757
      apply auto
wenzelm@53788
   758
      done
wenzelm@53788
   759
  }
wenzelm@49664
   760
  moreover
wenzelm@53788
   761
  {
wenzelm@53788
   762
    assume "\<exists>a. S = {a ..}"
wenzelm@53788
   763
    then obtain a where "S = {a ..}"
wenzelm@53788
   764
      by auto
wenzelm@53788
   765
    then have ?thesis
wenzelm@53788
   766
      apply (rule_tac x="ereal a" in exI)
wenzelm@53788
   767
      apply auto
wenzelm@53788
   768
      done
wenzelm@49664
   769
  }
wenzelm@53788
   770
  ultimately show ?thesis
wenzelm@53788
   771
    using mono_closed_real[of S] assms by auto
hoelzl@41980
   772
qed
hoelzl@41980
   773
wenzelm@53788
   774
hoelzl@41980
   775
subsection {* Sums *}
hoelzl@41980
   776
wenzelm@49664
   777
lemma setsum_ereal[simp]: "(\<Sum>x\<in>A. ereal (f x)) = ereal (\<Sum>x\<in>A. f x)"
wenzelm@53788
   778
proof (cases "finite A")
wenzelm@53788
   779
  case True
wenzelm@49664
   780
  then show ?thesis by induct auto
wenzelm@53788
   781
next
wenzelm@53788
   782
  case False
wenzelm@53788
   783
  then show ?thesis by simp
wenzelm@53788
   784
qed
hoelzl@41980
   785
hoelzl@43923
   786
lemma setsum_Pinfty:
hoelzl@43923
   787
  fixes f :: "'a \<Rightarrow> ereal"
wenzelm@53788
   788
  shows "(\<Sum>x\<in>P. f x) = \<infinity> \<longleftrightarrow> finite P \<and> (\<exists>i\<in>P. f i = \<infinity>)"
hoelzl@41980
   789
proof safe
hoelzl@41980
   790
  assume *: "setsum f P = \<infinity>"
hoelzl@41980
   791
  show "finite P"
wenzelm@53788
   792
  proof (rule ccontr)
wenzelm@53788
   793
    assume "infinite P"
wenzelm@53788
   794
    with * show False
wenzelm@53788
   795
      by auto
wenzelm@53788
   796
  qed
hoelzl@41980
   797
  show "\<exists>i\<in>P. f i = \<infinity>"
hoelzl@41980
   798
  proof (rule ccontr)
wenzelm@53788
   799
    assume "\<not> ?thesis"
wenzelm@53788
   800
    then have "\<And>i. i \<in> P \<Longrightarrow> f i \<noteq> \<infinity>"
wenzelm@53788
   801
      by auto
wenzelm@53788
   802
    with `finite P` have "setsum f P \<noteq> \<infinity>"
hoelzl@41980
   803
      by induct auto
wenzelm@53788
   804
    with * show False
wenzelm@53788
   805
      by auto
hoelzl@41980
   806
  qed
hoelzl@41980
   807
next
wenzelm@53788
   808
  fix i
wenzelm@53788
   809
  assume "finite P" and "i \<in> P" and "f i = \<infinity>"
wenzelm@49664
   810
  then show "setsum f P = \<infinity>"
hoelzl@41980
   811
  proof induct
hoelzl@41980
   812
    case (insert x A)
hoelzl@41980
   813
    show ?case using insert by (cases "x = i") auto
hoelzl@41980
   814
  qed simp
hoelzl@41980
   815
qed
hoelzl@41980
   816
hoelzl@41980
   817
lemma setsum_Inf:
hoelzl@43923
   818
  fixes f :: "'a \<Rightarrow> ereal"
wenzelm@53788
   819
  shows "\<bar>setsum f A\<bar> = \<infinity> \<longleftrightarrow> finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)"
hoelzl@41980
   820
proof
hoelzl@41980
   821
  assume *: "\<bar>setsum f A\<bar> = \<infinity>"
wenzelm@53788
   822
  have "finite A"
wenzelm@53788
   823
    by (rule ccontr) (insert *, auto)
hoelzl@41980
   824
  moreover have "\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>"
hoelzl@41980
   825
  proof (rule ccontr)
wenzelm@53788
   826
    assume "\<not> ?thesis"
wenzelm@53788
   827
    then have "\<forall>i\<in>A. \<exists>r. f i = ereal r"
wenzelm@53788
   828
      by auto
wenzelm@53788
   829
    from bchoice[OF this] obtain r where "\<forall>x\<in>A. f x = ereal (r x)" ..
wenzelm@53788
   830
    with * show False
wenzelm@53788
   831
      by auto
hoelzl@41980
   832
  qed
wenzelm@53788
   833
  ultimately show "finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)"
wenzelm@53788
   834
    by auto
hoelzl@41980
   835
next
hoelzl@41980
   836
  assume "finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)"
wenzelm@53788
   837
  then obtain i where "finite A" "i \<in> A" and "\<bar>f i\<bar> = \<infinity>"
wenzelm@53788
   838
    by auto
hoelzl@41980
   839
  then show "\<bar>setsum f A\<bar> = \<infinity>"
hoelzl@41980
   840
  proof induct
wenzelm@53788
   841
    case (insert j A)
wenzelm@53788
   842
    then show ?case
hoelzl@43920
   843
      by (cases rule: ereal3_cases[of "f i" "f j" "setsum f A"]) auto
hoelzl@41980
   844
  qed simp
hoelzl@41980
   845
qed
hoelzl@41980
   846
hoelzl@43920
   847
lemma setsum_real_of_ereal:
hoelzl@43923
   848
  fixes f :: "'i \<Rightarrow> ereal"
hoelzl@41980
   849
  assumes "\<And>x. x \<in> S \<Longrightarrow> \<bar>f x\<bar> \<noteq> \<infinity>"
hoelzl@41980
   850
  shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
hoelzl@41980
   851
proof -
hoelzl@43920
   852
  have "\<forall>x\<in>S. \<exists>r. f x = ereal r"
hoelzl@41980
   853
  proof
wenzelm@53788
   854
    fix x
wenzelm@53788
   855
    assume "x \<in> S"
wenzelm@53788
   856
    from assms[OF this] show "\<exists>r. f x = ereal r"
wenzelm@53788
   857
      by (cases "f x") auto
hoelzl@41980
   858
  qed
wenzelm@53788
   859
  from bchoice[OF this] obtain r where "\<forall>x\<in>S. f x = ereal (r x)" ..
wenzelm@53788
   860
  then show ?thesis
wenzelm@53788
   861
    by simp
hoelzl@41980
   862
qed
hoelzl@41980
   863
hoelzl@43920
   864
lemma setsum_ereal_0:
wenzelm@53788
   865
  fixes f :: "'a \<Rightarrow> ereal"
wenzelm@53788
   866
  assumes "finite A"
wenzelm@53788
   867
    and "\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i"
hoelzl@41980
   868
  shows "(\<Sum>x\<in>A. f x) = 0 \<longleftrightarrow> (\<forall>i\<in>A. f i = 0)"
hoelzl@41980
   869
proof
hoelzl@41980
   870
  assume *: "(\<Sum>x\<in>A. f x) = 0"
wenzelm@53788
   871
  then have "(\<Sum>x\<in>A. f x) \<noteq> \<infinity>"
wenzelm@53788
   872
    by auto
wenzelm@53788
   873
  then have "\<forall>i\<in>A. \<bar>f i\<bar> \<noteq> \<infinity>"
wenzelm@53788
   874
    using assms by (force simp: setsum_Pinfty)
wenzelm@53788
   875
  then have "\<forall>i\<in>A. \<exists>r. f i = ereal r"
wenzelm@53788
   876
    by auto
hoelzl@41980
   877
  from bchoice[OF this] * assms show "\<forall>i\<in>A. f i = 0"
hoelzl@41980
   878
    using setsum_nonneg_eq_0_iff[of A "\<lambda>i. real (f i)"] by auto
haftmann@57418
   879
qed (rule setsum.neutral)
hoelzl@41980
   880
hoelzl@43920
   881
lemma setsum_ereal_right_distrib:
wenzelm@49664
   882
  fixes f :: "'a \<Rightarrow> ereal"
wenzelm@49664
   883
  assumes "\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i"
hoelzl@41980
   884
  shows "r * setsum f A = (\<Sum>n\<in>A. r * f n)"
hoelzl@41980
   885
proof cases
wenzelm@49664
   886
  assume "finite A"
wenzelm@49664
   887
  then show ?thesis using assms
hoelzl@43920
   888
    by induct (auto simp: ereal_right_distrib setsum_nonneg)
hoelzl@41980
   889
qed simp
hoelzl@41980
   890
hoelzl@43920
   891
lemma sums_ereal_positive:
wenzelm@49664
   892
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@49664
   893
  assumes "\<And>i. 0 \<le> f i"
wenzelm@49664
   894
  shows "f sums (SUP n. \<Sum>i<n. f i)"
hoelzl@41980
   895
proof -
hoelzl@41980
   896
  have "incseq (\<lambda>i. \<Sum>j=0..<i. f j)"
wenzelm@53788
   897
    using ereal_add_mono[OF _ assms]
wenzelm@53788
   898
    by (auto intro!: incseq_SucI)
hoelzl@51000
   899
  from LIMSEQ_SUP[OF this]
wenzelm@53788
   900
  show ?thesis unfolding sums_def
wenzelm@53788
   901
    by (simp add: atLeast0LessThan)
hoelzl@41980
   902
qed
hoelzl@41980
   903
hoelzl@43920
   904
lemma summable_ereal_pos:
wenzelm@49664
   905
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@49664
   906
  assumes "\<And>i. 0 \<le> f i"
wenzelm@49664
   907
  shows "summable f"
wenzelm@53788
   908
  using sums_ereal_positive[of f, OF assms]
wenzelm@53788
   909
  unfolding summable_def
wenzelm@53788
   910
  by auto
hoelzl@41980
   911
haftmann@56212
   912
lemma suminf_ereal_eq_SUP:
wenzelm@49664
   913
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@49664
   914
  assumes "\<And>i. 0 \<le> f i"
hoelzl@41980
   915
  shows "(\<Sum>x. f x) = (SUP n. \<Sum>i<n. f i)"
wenzelm@53788
   916
  using sums_ereal_positive[of f, OF assms, THEN sums_unique]
wenzelm@53788
   917
  by simp
hoelzl@41980
   918
wenzelm@49664
   919
lemma sums_ereal: "(\<lambda>x. ereal (f x)) sums ereal x \<longleftrightarrow> f sums x"
hoelzl@41980
   920
  unfolding sums_def by simp
hoelzl@41980
   921
hoelzl@41980
   922
lemma suminf_bound:
hoelzl@43920
   923
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@53788
   924
  assumes "\<forall>N. (\<Sum>n<N. f n) \<le> x"
wenzelm@53788
   925
    and pos: "\<And>n. 0 \<le> f n"
hoelzl@41980
   926
  shows "suminf f \<le> x"
hoelzl@43920
   927
proof (rule Lim_bounded_ereal)
hoelzl@43920
   928
  have "summable f" using pos[THEN summable_ereal_pos] .
hoelzl@41980
   929
  then show "(\<lambda>N. \<Sum>n<N. f n) ----> suminf f"
hoelzl@41980
   930
    by (auto dest!: summable_sums simp: sums_def atLeast0LessThan)
hoelzl@41980
   931
  show "\<forall>n\<ge>0. setsum f {..<n} \<le> x"
hoelzl@41980
   932
    using assms by auto
hoelzl@41980
   933
qed
hoelzl@41980
   934
hoelzl@41980
   935
lemma suminf_bound_add:
hoelzl@43920
   936
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@49664
   937
  assumes "\<forall>N. (\<Sum>n<N. f n) + y \<le> x"
wenzelm@49664
   938
    and pos: "\<And>n. 0 \<le> f n"
wenzelm@49664
   939
    and "y \<noteq> -\<infinity>"
hoelzl@41980
   940
  shows "suminf f + y \<le> x"
hoelzl@41980
   941
proof (cases y)
wenzelm@49664
   942
  case (real r)
wenzelm@49664
   943
  then have "\<forall>N. (\<Sum>n<N. f n) \<le> x - y"
hoelzl@43920
   944
    using assms by (simp add: ereal_le_minus)
wenzelm@53788
   945
  then have "(\<Sum> n. f n) \<le> x - y"
wenzelm@53788
   946
    using pos by (rule suminf_bound)
hoelzl@41980
   947
  then show "(\<Sum> n. f n) + y \<le> x"
hoelzl@43920
   948
    using assms real by (simp add: ereal_le_minus)
hoelzl@41980
   949
qed (insert assms, auto)
hoelzl@41980
   950
hoelzl@41980
   951
lemma suminf_upper:
wenzelm@49664
   952
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@49664
   953
  assumes "\<And>n. 0 \<le> f n"
hoelzl@41980
   954
  shows "(\<Sum>n<N. f n) \<le> (\<Sum>n. f n)"
haftmann@56212
   955
  unfolding suminf_ereal_eq_SUP [OF assms]
haftmann@56166
   956
  by (auto intro: complete_lattice_class.SUP_upper)
hoelzl@41980
   957
hoelzl@41980
   958
lemma suminf_0_le:
wenzelm@49664
   959
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@49664
   960
  assumes "\<And>n. 0 \<le> f n"
hoelzl@41980
   961
  shows "0 \<le> (\<Sum>n. f n)"
wenzelm@53788
   962
  using suminf_upper[of f 0, OF assms]
wenzelm@53788
   963
  by simp
hoelzl@41980
   964
hoelzl@41980
   965
lemma suminf_le_pos:
hoelzl@43920
   966
  fixes f g :: "nat \<Rightarrow> ereal"
wenzelm@53788
   967
  assumes "\<And>N. f N \<le> g N"
wenzelm@53788
   968
    and "\<And>N. 0 \<le> f N"
hoelzl@41980
   969
  shows "suminf f \<le> suminf g"
hoelzl@41980
   970
proof (safe intro!: suminf_bound)
wenzelm@49664
   971
  fix n
wenzelm@53788
   972
  {
wenzelm@53788
   973
    fix N
wenzelm@53788
   974
    have "0 \<le> g N"
wenzelm@53788
   975
      using assms(2,1)[of N] by auto
wenzelm@53788
   976
  }
wenzelm@49664
   977
  have "setsum f {..<n} \<le> setsum g {..<n}"
wenzelm@49664
   978
    using assms by (auto intro: setsum_mono)
wenzelm@53788
   979
  also have "\<dots> \<le> suminf g"
wenzelm@53788
   980
    using `\<And>N. 0 \<le> g N`
wenzelm@53788
   981
    by (rule suminf_upper)
hoelzl@41980
   982
  finally show "setsum f {..<n} \<le> suminf g" .
hoelzl@41980
   983
qed (rule assms(2))
hoelzl@41980
   984
wenzelm@53788
   985
lemma suminf_half_series_ereal: "(\<Sum>n. (1/2 :: ereal) ^ Suc n) = 1"
hoelzl@43920
   986
  using sums_ereal[THEN iffD2, OF power_half_series, THEN sums_unique, symmetric]
hoelzl@43920
   987
  by (simp add: one_ereal_def)
hoelzl@41980
   988
hoelzl@43920
   989
lemma suminf_add_ereal:
hoelzl@43920
   990
  fixes f g :: "nat \<Rightarrow> ereal"
wenzelm@53788
   991
  assumes "\<And>i. 0 \<le> f i"
wenzelm@53788
   992
    and "\<And>i. 0 \<le> g i"
hoelzl@41980
   993
  shows "(\<Sum>i. f i + g i) = suminf f + suminf g"
haftmann@56212
   994
  apply (subst (1 2 3) suminf_ereal_eq_SUP)
haftmann@57418
   995
  unfolding setsum.distrib
haftmann@56212
   996
  apply (intro assms ereal_add_nonneg_nonneg SUP_ereal_add_pos incseq_setsumI setsum_nonneg ballI)+
wenzelm@49664
   997
  done
hoelzl@41980
   998
hoelzl@43920
   999
lemma suminf_cmult_ereal:
hoelzl@43920
  1000
  fixes f g :: "nat \<Rightarrow> ereal"
wenzelm@53788
  1001
  assumes "\<And>i. 0 \<le> f i"
wenzelm@53788
  1002
    and "0 \<le> a"
hoelzl@41980
  1003
  shows "(\<Sum>i. a * f i) = a * suminf f"
hoelzl@43920
  1004
  by (auto simp: setsum_ereal_right_distrib[symmetric] assms
haftmann@56212
  1005
       ereal_zero_le_0_iff setsum_nonneg suminf_ereal_eq_SUP
haftmann@56212
  1006
       intro!: SUP_ereal_cmult)
hoelzl@41980
  1007
hoelzl@41980
  1008
lemma suminf_PInfty:
hoelzl@43923
  1009
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@53788
  1010
  assumes "\<And>i. 0 \<le> f i"
wenzelm@53788
  1011
    and "suminf f \<noteq> \<infinity>"
hoelzl@41980
  1012
  shows "f i \<noteq> \<infinity>"
hoelzl@41980
  1013
proof -
hoelzl@41980
  1014
  from suminf_upper[of f "Suc i", OF assms(1)] assms(2)
wenzelm@53788
  1015
  have "(\<Sum>i<Suc i. f i) \<noteq> \<infinity>"
wenzelm@53788
  1016
    by auto
wenzelm@53788
  1017
  then show ?thesis
wenzelm@53788
  1018
    unfolding setsum_Pinfty by simp
hoelzl@41980
  1019
qed
hoelzl@41980
  1020
hoelzl@41980
  1021
lemma suminf_PInfty_fun:
wenzelm@53788
  1022
  assumes "\<And>i. 0 \<le> f i"
wenzelm@53788
  1023
    and "suminf f \<noteq> \<infinity>"
hoelzl@43920
  1024
  shows "\<exists>f'. f = (\<lambda>x. ereal (f' x))"
hoelzl@41980
  1025
proof -
hoelzl@43920
  1026
  have "\<forall>i. \<exists>r. f i = ereal r"
hoelzl@41980
  1027
  proof
wenzelm@53788
  1028
    fix i
wenzelm@53788
  1029
    show "\<exists>r. f i = ereal r"
wenzelm@53788
  1030
      using suminf_PInfty[OF assms] assms(1)[of i]
wenzelm@53788
  1031
      by (cases "f i") auto
hoelzl@41980
  1032
  qed
wenzelm@53788
  1033
  from choice[OF this] show ?thesis
wenzelm@53788
  1034
    by auto
hoelzl@41980
  1035
qed
hoelzl@41980
  1036
hoelzl@43920
  1037
lemma summable_ereal:
wenzelm@53788
  1038
  assumes "\<And>i. 0 \<le> f i"
wenzelm@53788
  1039
    and "(\<Sum>i. ereal (f i)) \<noteq> \<infinity>"
hoelzl@41980
  1040
  shows "summable f"
hoelzl@41980
  1041
proof -
hoelzl@43920
  1042
  have "0 \<le> (\<Sum>i. ereal (f i))"
hoelzl@41980
  1043
    using assms by (intro suminf_0_le) auto
hoelzl@43920
  1044
  with assms obtain r where r: "(\<Sum>i. ereal (f i)) = ereal r"
hoelzl@43920
  1045
    by (cases "\<Sum>i. ereal (f i)") auto
hoelzl@43920
  1046
  from summable_ereal_pos[of "\<lambda>x. ereal (f x)"]
wenzelm@53788
  1047
  have "summable (\<lambda>x. ereal (f x))"
wenzelm@53788
  1048
    using assms by auto
hoelzl@41980
  1049
  from summable_sums[OF this]
wenzelm@53788
  1050
  have "(\<lambda>x. ereal (f x)) sums (\<Sum>x. ereal (f x))"
wenzelm@53788
  1051
    by auto
hoelzl@41980
  1052
  then show "summable f"
hoelzl@43920
  1053
    unfolding r sums_ereal summable_def ..
hoelzl@41980
  1054
qed
hoelzl@41980
  1055
hoelzl@43920
  1056
lemma suminf_ereal:
wenzelm@53788
  1057
  assumes "\<And>i. 0 \<le> f i"
wenzelm@53788
  1058
    and "(\<Sum>i. ereal (f i)) \<noteq> \<infinity>"
hoelzl@43920
  1059
  shows "(\<Sum>i. ereal (f i)) = ereal (suminf f)"
hoelzl@41980
  1060
proof (rule sums_unique[symmetric])
hoelzl@43920
  1061
  from summable_ereal[OF assms]
hoelzl@43920
  1062
  show "(\<lambda>x. ereal (f x)) sums (ereal (suminf f))"
wenzelm@53788
  1063
    unfolding sums_ereal
wenzelm@53788
  1064
    using assms
wenzelm@53788
  1065
    by (intro summable_sums summable_ereal)
hoelzl@41980
  1066
qed
hoelzl@41980
  1067
hoelzl@43920
  1068
lemma suminf_ereal_minus:
hoelzl@43920
  1069
  fixes f g :: "nat \<Rightarrow> ereal"
wenzelm@53788
  1070
  assumes ord: "\<And>i. g i \<le> f i" "\<And>i. 0 \<le> g i"
wenzelm@53788
  1071
    and fin: "suminf f \<noteq> \<infinity>" "suminf g \<noteq> \<infinity>"
hoelzl@41980
  1072
  shows "(\<Sum>i. f i - g i) = suminf f - suminf g"
hoelzl@41980
  1073
proof -
wenzelm@53788
  1074
  {
wenzelm@53788
  1075
    fix i
wenzelm@53788
  1076
    have "0 \<le> f i"
wenzelm@53788
  1077
      using ord[of i] by auto
wenzelm@53788
  1078
  }
hoelzl@41980
  1079
  moreover
wenzelm@53788
  1080
  from suminf_PInfty_fun[OF `\<And>i. 0 \<le> f i` fin(1)] obtain f' where [simp]: "f = (\<lambda>x. ereal (f' x))" ..
wenzelm@53788
  1081
  from suminf_PInfty_fun[OF `\<And>i. 0 \<le> g i` fin(2)] obtain g' where [simp]: "g = (\<lambda>x. ereal (g' x))" ..
wenzelm@53788
  1082
  {
wenzelm@53788
  1083
    fix i
wenzelm@53788
  1084
    have "0 \<le> f i - g i"
wenzelm@53788
  1085
      using ord[of i] by (auto simp: ereal_le_minus_iff)
wenzelm@53788
  1086
  }
hoelzl@41980
  1087
  moreover
hoelzl@41980
  1088
  have "suminf (\<lambda>i. f i - g i) \<le> suminf f"
hoelzl@41980
  1089
    using assms by (auto intro!: suminf_le_pos simp: field_simps)
wenzelm@53788
  1090
  then have "suminf (\<lambda>i. f i - g i) \<noteq> \<infinity>"
wenzelm@53788
  1091
    using fin by auto
wenzelm@53788
  1092
  ultimately show ?thesis
wenzelm@53788
  1093
    using assms `\<And>i. 0 \<le> f i`
hoelzl@41980
  1094
    apply simp
wenzelm@49664
  1095
    apply (subst (1 2 3) suminf_ereal)
wenzelm@49664
  1096
    apply (auto intro!: suminf_diff[symmetric] summable_ereal)
wenzelm@49664
  1097
    done
hoelzl@41980
  1098
qed
hoelzl@41980
  1099
wenzelm@49664
  1100
lemma suminf_ereal_PInf [simp]: "(\<Sum>x. \<infinity>::ereal) = \<infinity>"
hoelzl@41980
  1101
proof -
wenzelm@53788
  1102
  have "(\<Sum>i<Suc 0. \<infinity>) \<le> (\<Sum>x. \<infinity>::ereal)"
wenzelm@53788
  1103
    by (rule suminf_upper) auto
wenzelm@53788
  1104
  then show ?thesis
wenzelm@53788
  1105
    by simp
hoelzl@41980
  1106
qed
hoelzl@41980
  1107
hoelzl@43920
  1108
lemma summable_real_of_ereal:
hoelzl@43923
  1109
  fixes f :: "nat \<Rightarrow> ereal"
wenzelm@49664
  1110
  assumes f: "\<And>i. 0 \<le> f i"
wenzelm@49664
  1111
    and fin: "(\<Sum>i. f i) \<noteq> \<infinity>"
hoelzl@41980
  1112
  shows "summable (\<lambda>i. real (f i))"
hoelzl@41980
  1113
proof (rule summable_def[THEN iffD2])
wenzelm@53788
  1114
  have "0 \<le> (\<Sum>i. f i)"
wenzelm@53788
  1115
    using assms by (auto intro: suminf_0_le)
wenzelm@53788
  1116
  with fin obtain r where r: "ereal r = (\<Sum>i. f i)"
wenzelm@53788
  1117
    by (cases "(\<Sum>i. f i)") auto
wenzelm@53788
  1118
  {
wenzelm@53788
  1119
    fix i
wenzelm@53788
  1120
    have "f i \<noteq> \<infinity>"
wenzelm@53788
  1121
      using f by (intro suminf_PInfty[OF _ fin]) auto
wenzelm@53788
  1122
    then have "\<bar>f i\<bar> \<noteq> \<infinity>"
wenzelm@53788
  1123
      using f[of i] by auto
wenzelm@53788
  1124
  }
hoelzl@41980
  1125
  note fin = this
hoelzl@43920
  1126
  have "(\<lambda>i. ereal (real (f i))) sums (\<Sum>i. ereal (real (f i)))"
wenzelm@53788
  1127
    using f
wenzelm@57865
  1128
    by (auto intro!: summable_ereal_pos simp: ereal_le_real_iff zero_ereal_def)
wenzelm@53788
  1129
  also have "\<dots> = ereal r"
wenzelm@53788
  1130
    using fin r by (auto simp: ereal_real)
wenzelm@53788
  1131
  finally show "\<exists>r. (\<lambda>i. real (f i)) sums r"
wenzelm@53788
  1132
    by (auto simp: sums_ereal)
hoelzl@41980
  1133
qed
hoelzl@41980
  1134
hoelzl@42950
  1135
lemma suminf_SUP_eq:
hoelzl@43920
  1136
  fixes f :: "nat \<Rightarrow> nat \<Rightarrow> ereal"
wenzelm@53788
  1137
  assumes "\<And>i. incseq (\<lambda>n. f n i)"
wenzelm@53788
  1138
    and "\<And>n i. 0 \<le> f n i"
hoelzl@42950
  1139
  shows "(\<Sum>i. SUP n. f n i) = (SUP n. \<Sum>i. f n i)"
hoelzl@42950
  1140
proof -
wenzelm@53788
  1141
  {
wenzelm@53788
  1142
    fix n :: nat
hoelzl@42950
  1143
    have "(\<Sum>i<n. SUP k. f k i) = (SUP k. \<Sum>i<n. f k i)"
wenzelm@53788
  1144
      using assms
haftmann@56212
  1145
      by (auto intro!: SUP_ereal_setsum [symmetric])
wenzelm@53788
  1146
  }
hoelzl@42950
  1147
  note * = this
wenzelm@53788
  1148
  show ?thesis
wenzelm@53788
  1149
    using assms
haftmann@56212
  1150
    apply (subst (1 2) suminf_ereal_eq_SUP)
hoelzl@42950
  1151
    unfolding *
hoelzl@44928
  1152
    apply (auto intro!: SUP_upper2)
wenzelm@49664
  1153
    apply (subst SUP_commute)
wenzelm@49664
  1154
    apply rule
wenzelm@49664
  1155
    done
hoelzl@42950
  1156
qed
hoelzl@42950
  1157
hoelzl@47761
  1158
lemma suminf_setsum_ereal:
hoelzl@47761
  1159
  fixes f :: "_ \<Rightarrow> _ \<Rightarrow> ereal"
hoelzl@47761
  1160
  assumes nonneg: "\<And>i a. a \<in> A \<Longrightarrow> 0 \<le> f i a"
hoelzl@47761
  1161
  shows "(\<Sum>i. \<Sum>a\<in>A. f i a) = (\<Sum>a\<in>A. \<Sum>i. f i a)"
wenzelm@53788
  1162
proof (cases "finite A")
wenzelm@53788
  1163
  case True
wenzelm@53788
  1164
  then show ?thesis
wenzelm@53788
  1165
    using nonneg
hoelzl@47761
  1166
    by induct (simp_all add: suminf_add_ereal setsum_nonneg)
wenzelm@53788
  1167
next
wenzelm@53788
  1168
  case False
wenzelm@53788
  1169
  then show ?thesis by simp
wenzelm@53788
  1170
qed
hoelzl@47761
  1171
hoelzl@50104
  1172
lemma suminf_ereal_eq_0:
hoelzl@50104
  1173
  fixes f :: "nat \<Rightarrow> ereal"
hoelzl@50104
  1174
  assumes nneg: "\<And>i. 0 \<le> f i"
hoelzl@50104
  1175
  shows "(\<Sum>i. f i) = 0 \<longleftrightarrow> (\<forall>i. f i = 0)"
hoelzl@50104
  1176
proof
hoelzl@50104
  1177
  assume "(\<Sum>i. f i) = 0"
wenzelm@53788
  1178
  {
wenzelm@53788
  1179
    fix i
wenzelm@53788
  1180
    assume "f i \<noteq> 0"
wenzelm@53788
  1181
    with nneg have "0 < f i"
wenzelm@53788
  1182
      by (auto simp: less_le)
hoelzl@50104
  1183
    also have "f i = (\<Sum>j. if j = i then f i else 0)"
hoelzl@50104
  1184
      by (subst suminf_finite[where N="{i}"]) auto
hoelzl@50104
  1185
    also have "\<dots> \<le> (\<Sum>i. f i)"
wenzelm@53788
  1186
      using nneg
wenzelm@53788
  1187
      by (auto intro!: suminf_le_pos)
wenzelm@53788
  1188
    finally have False
wenzelm@53788
  1189
      using `(\<Sum>i. f i) = 0` by auto
wenzelm@53788
  1190
  }
wenzelm@53788
  1191
  then show "\<forall>i. f i = 0"
wenzelm@53788
  1192
    by auto
hoelzl@50104
  1193
qed simp
hoelzl@50104
  1194
hoelzl@51340
  1195
lemma Liminf_within:
hoelzl@51340
  1196
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
hoelzl@51340
  1197
  shows "Liminf (at x within S) f = (SUP e:{0<..}. INF y:(S \<inter> ball x e - {x}). f y)"
hoelzl@51641
  1198
  unfolding Liminf_def eventually_at
haftmann@56212
  1199
proof (rule SUP_eq, simp_all add: Ball_def Bex_def, safe)
wenzelm@53788
  1200
  fix P d
wenzelm@53788
  1201
  assume "0 < d" and "\<forall>y. y \<in> S \<longrightarrow> y \<noteq> x \<and> dist y x < d \<longrightarrow> P y"
hoelzl@51340
  1202
  then have "S \<inter> ball x d - {x} \<subseteq> {x. P x}"
hoelzl@51340
  1203
    by (auto simp: zero_less_dist_iff dist_commute)
haftmann@56218
  1204
  then show "\<exists>r>0. INFIMUM (Collect P) f \<le> INFIMUM (S \<inter> ball x r - {x}) f"
hoelzl@51340
  1205
    by (intro exI[of _ d] INF_mono conjI `0 < d`) auto
hoelzl@51340
  1206
next
wenzelm@53788
  1207
  fix d :: real
wenzelm@53788
  1208
  assume "0 < d"
hoelzl@51641
  1209
  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@56218
  1210
    INFIMUM (S \<inter> ball x d - {x}) f \<le> INFIMUM (Collect P) f"
hoelzl@51340
  1211
    by (intro exI[of _ "\<lambda>y. y \<in> S \<inter> ball x d - {x}"])
hoelzl@51340
  1212
       (auto intro!: INF_mono exI[of _ d] simp: dist_commute)
hoelzl@51340
  1213
qed
hoelzl@51340
  1214
hoelzl@51340
  1215
lemma Limsup_within:
wenzelm@53788
  1216
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
hoelzl@51340
  1217
  shows "Limsup (at x within S) f = (INF e:{0<..}. SUP y:(S \<inter> ball x e - {x}). f y)"
hoelzl@51641
  1218
  unfolding Limsup_def eventually_at
haftmann@56212
  1219
proof (rule INF_eq, simp_all add: Ball_def Bex_def, safe)
wenzelm@53788
  1220
  fix P d
wenzelm@53788
  1221
  assume "0 < d" and "\<forall>y. y \<in> S \<longrightarrow> y \<noteq> x \<and> dist y x < d \<longrightarrow> P y"
hoelzl@51340
  1222
  then have "S \<inter> ball x d - {x} \<subseteq> {x. P x}"
hoelzl@51340
  1223
    by (auto simp: zero_less_dist_iff dist_commute)
haftmann@56218
  1224
  then show "\<exists>r>0. SUPREMUM (S \<inter> ball x r - {x}) f \<le> SUPREMUM (Collect P) f"
hoelzl@51340
  1225
    by (intro exI[of _ d] SUP_mono conjI `0 < d`) auto
hoelzl@51340
  1226
next
wenzelm@53788
  1227
  fix d :: real
wenzelm@53788
  1228
  assume "0 < d"
hoelzl@51641
  1229
  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@56218
  1230
    SUPREMUM (Collect P) f \<le> SUPREMUM (S \<inter> ball x d - {x}) f"
hoelzl@51340
  1231
    by (intro exI[of _ "\<lambda>y. y \<in> S \<inter> ball x d - {x}"])
hoelzl@51340
  1232
       (auto intro!: SUP_mono exI[of _ d] simp: dist_commute)
hoelzl@51340
  1233
qed
hoelzl@51340
  1234
hoelzl@51340
  1235
lemma Liminf_at:
hoelzl@54257
  1236
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
hoelzl@51340
  1237
  shows "Liminf (at x) f = (SUP e:{0<..}. INF y:(ball x e - {x}). f y)"
hoelzl@51340
  1238
  using Liminf_within[of x UNIV f] by simp
hoelzl@51340
  1239
hoelzl@51340
  1240
lemma Limsup_at:
hoelzl@54257
  1241
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
hoelzl@51340
  1242
  shows "Limsup (at x) f = (INF e:{0<..}. SUP y:(ball x e - {x}). f y)"
hoelzl@51340
  1243
  using Limsup_within[of x UNIV f] by simp
hoelzl@51340
  1244
hoelzl@51340
  1245
lemma min_Liminf_at:
wenzelm@53788
  1246
  fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_linorder"
hoelzl@51340
  1247
  shows "min (f x) (Liminf (at x) f) = (SUP e:{0<..}. INF y:ball x e. f y)"
hoelzl@51340
  1248
  unfolding inf_min[symmetric] Liminf_at
hoelzl@51340
  1249
  apply (subst inf_commute)
hoelzl@51340
  1250
  apply (subst SUP_inf)
hoelzl@51340
  1251
  apply (intro SUP_cong[OF refl])
hoelzl@54260
  1252
  apply (cut_tac A="ball x xa - {x}" and B="{x}" and M=f in INF_union)
haftmann@56166
  1253
  apply (drule sym)
haftmann@56166
  1254
  apply auto
wenzelm@57865
  1255
  apply (metis INF_absorb centre_in_ball)
wenzelm@57865
  1256
  done
hoelzl@51340
  1257
wenzelm@53788
  1258
hoelzl@57025
  1259
lemma suminf_ereal_offset_le:
hoelzl@57025
  1260
  fixes f :: "nat \<Rightarrow> ereal"
hoelzl@57025
  1261
  assumes f: "\<And>i. 0 \<le> f i"
hoelzl@57025
  1262
  shows "(\<Sum>i. f (i + k)) \<le> suminf f"
hoelzl@57025
  1263
proof -
hoelzl@57025
  1264
  have "(\<lambda>n. \<Sum>i<n. f (i + k)) ----> (\<Sum>i. f (i + k))"
hoelzl@57025
  1265
    using summable_sums[OF summable_ereal_pos] by (simp add: sums_def atLeast0LessThan f)
hoelzl@57025
  1266
  moreover have "(\<lambda>n. \<Sum>i<n. f i) ----> (\<Sum>i. f i)"
hoelzl@57025
  1267
    using summable_sums[OF summable_ereal_pos] by (simp add: sums_def atLeast0LessThan f)
hoelzl@57025
  1268
  then have "(\<lambda>n. \<Sum>i<n + k. f i) ----> (\<Sum>i. f i)"
hoelzl@57025
  1269
    by (rule LIMSEQ_ignore_initial_segment)
hoelzl@57025
  1270
  ultimately show ?thesis
hoelzl@57025
  1271
  proof (rule LIMSEQ_le, safe intro!: exI[of _ k])
hoelzl@57025
  1272
    fix n assume "k \<le> n"
hoelzl@57025
  1273
    have "(\<Sum>i<n. f (i + k)) = (\<Sum>i<n. (f \<circ> (\<lambda>i. i + k)) i)"
hoelzl@57025
  1274
      by simp
hoelzl@57025
  1275
    also have "\<dots> = (\<Sum>i\<in>(\<lambda>i. i + k) ` {..<n}. f i)"
haftmann@57418
  1276
      by (subst setsum.reindex) auto
hoelzl@57025
  1277
    also have "\<dots> \<le> setsum f {..<n + k}"
hoelzl@57025
  1278
      by (intro setsum_mono3) (auto simp: f)
hoelzl@57025
  1279
    finally show "(\<Sum>i<n. f (i + k)) \<le> setsum f {..<n + k}" .
hoelzl@57025
  1280
  qed
hoelzl@57025
  1281
qed
hoelzl@57025
  1282
hoelzl@57025
  1283
lemma sums_suminf_ereal: "f sums x \<Longrightarrow> (\<Sum>i. ereal (f i)) = ereal x"
hoelzl@57025
  1284
  by (metis sums_ereal sums_unique)
hoelzl@57025
  1285
hoelzl@57025
  1286
lemma suminf_ereal': "summable f \<Longrightarrow> (\<Sum>i. ereal (f i)) = ereal (\<Sum>i. f i)"
hoelzl@57025
  1287
  by (metis sums_ereal sums_unique summable_def)
hoelzl@57025
  1288
hoelzl@57025
  1289
lemma suminf_ereal_finite: "summable f \<Longrightarrow> (\<Sum>i. ereal (f i)) \<noteq> \<infinity>"
hoelzl@57025
  1290
  by (auto simp: sums_ereal[symmetric] summable_def sums_unique[symmetric])
hoelzl@57025
  1291
hoelzl@51340
  1292
subsection {* monoset *}
hoelzl@51340
  1293
hoelzl@51340
  1294
definition (in order) mono_set:
hoelzl@51340
  1295
  "mono_set S \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> x \<in> S \<longrightarrow> y \<in> S)"
hoelzl@51340
  1296
hoelzl@51340
  1297
lemma (in order) mono_greaterThan [intro, simp]: "mono_set {B<..}" unfolding mono_set by auto
hoelzl@51340
  1298
lemma (in order) mono_atLeast [intro, simp]: "mono_set {B..}" unfolding mono_set by auto
hoelzl@51340
  1299
lemma (in order) mono_UNIV [intro, simp]: "mono_set UNIV" unfolding mono_set by auto
hoelzl@51340
  1300
lemma (in order) mono_empty [intro, simp]: "mono_set {}" unfolding mono_set by auto
hoelzl@51340
  1301
hoelzl@51340
  1302
lemma (in complete_linorder) mono_set_iff:
hoelzl@51340
  1303
  fixes S :: "'a set"
hoelzl@51340
  1304
  defines "a \<equiv> Inf S"
wenzelm@53788
  1305
  shows "mono_set S \<longleftrightarrow> S = {a <..} \<or> S = {a..}" (is "_ = ?c")
hoelzl@51340
  1306
proof
hoelzl@51340
  1307
  assume "mono_set S"
wenzelm@53788
  1308
  then have mono: "\<And>x y. x \<le> y \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S"
wenzelm@53788
  1309
    by (auto simp: mono_set)
hoelzl@51340
  1310
  show ?c
hoelzl@51340
  1311
  proof cases
hoelzl@51340
  1312
    assume "a \<in> S"
hoelzl@51340
  1313
    show ?c
hoelzl@51340
  1314
      using mono[OF _ `a \<in> S`]
hoelzl@51340
  1315
      by (auto intro: Inf_lower simp: a_def)
hoelzl@51340
  1316
  next
hoelzl@51340
  1317
    assume "a \<notin> S"
hoelzl@51340
  1318
    have "S = {a <..}"
hoelzl@51340
  1319
    proof safe
hoelzl@51340
  1320
      fix x assume "x \<in> S"
wenzelm@53788
  1321
      then have "a \<le> x"
wenzelm@53788
  1322
        unfolding a_def by (rule Inf_lower)
wenzelm@53788
  1323
      then show "a < x"
wenzelm@53788
  1324
        using `x \<in> S` `a \<notin> S` by (cases "a = x") auto
hoelzl@51340
  1325
    next
hoelzl@51340
  1326
      fix x assume "a < x"
wenzelm@53788
  1327
      then obtain y where "y < x" "y \<in> S"
wenzelm@53788
  1328
        unfolding a_def Inf_less_iff ..
wenzelm@53788
  1329
      with mono[of y x] show "x \<in> S"
wenzelm@53788
  1330
        by auto
hoelzl@51340
  1331
    qed
hoelzl@51340
  1332
    then show ?c ..
hoelzl@51340
  1333
  qed
hoelzl@51340
  1334
qed auto
hoelzl@51340
  1335
hoelzl@51340
  1336
lemma ereal_open_mono_set:
hoelzl@51340
  1337
  fixes S :: "ereal set"
wenzelm@53788
  1338
  shows "open S \<and> mono_set S \<longleftrightarrow> S = UNIV \<or> S = {Inf S <..}"
hoelzl@51340
  1339
  by (metis Inf_UNIV atLeast_eq_UNIV_iff ereal_open_atLeast
hoelzl@51340
  1340
    ereal_open_closed mono_set_iff open_ereal_greaterThan)
hoelzl@51340
  1341
hoelzl@51340
  1342
lemma ereal_closed_mono_set:
hoelzl@51340
  1343
  fixes S :: "ereal set"
wenzelm@53788
  1344
  shows "closed S \<and> mono_set S \<longleftrightarrow> S = {} \<or> S = {Inf S ..}"
hoelzl@51340
  1345
  by (metis Inf_UNIV atLeast_eq_UNIV_iff closed_ereal_atLeast
hoelzl@51340
  1346
    ereal_open_closed mono_empty mono_set_iff open_ereal_greaterThan)
hoelzl@51340
  1347
hoelzl@51340
  1348
lemma ereal_Liminf_Sup_monoset:
wenzelm@53788
  1349
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@51340
  1350
  shows "Liminf net f =
hoelzl@51340
  1351
    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
  1352
    (is "_ = Sup ?A")
hoelzl@51340
  1353
proof (safe intro!: Liminf_eqI complete_lattice_class.Sup_upper complete_lattice_class.Sup_least)
wenzelm@53788
  1354
  fix P
wenzelm@53788
  1355
  assume P: "eventually P net"
wenzelm@53788
  1356
  fix S
haftmann@56218
  1357
  assume S: "mono_set S" "INFIMUM (Collect P) f \<in> S"
wenzelm@53788
  1358
  {
wenzelm@53788
  1359
    fix x
wenzelm@53788
  1360
    assume "P x"
haftmann@56218
  1361
    then have "INFIMUM (Collect P) f \<le> f x"
hoelzl@51340
  1362
      by (intro complete_lattice_class.INF_lower) simp
hoelzl@51340
  1363
    with S have "f x \<in> S"
wenzelm@53788
  1364
      by (simp add: mono_set)
wenzelm@53788
  1365
  }
hoelzl@51340
  1366
  with P show "eventually (\<lambda>x. f x \<in> S) net"
hoelzl@51340
  1367
    by (auto elim: eventually_elim1)
hoelzl@51340
  1368
next
hoelzl@51340
  1369
  fix y l
hoelzl@51340
  1370
  assume S: "\<forall>S. open S \<longrightarrow> mono_set S \<longrightarrow> l \<in> S \<longrightarrow> eventually  (\<lambda>x. f x \<in> S) net"
haftmann@56218
  1371
  assume P: "\<forall>P. eventually P net \<longrightarrow> INFIMUM (Collect P) f \<le> y"
hoelzl@51340
  1372
  show "l \<le> y"
hoelzl@51340
  1373
  proof (rule dense_le)
wenzelm@53788
  1374
    fix B
wenzelm@53788
  1375
    assume "B < l"
hoelzl@51340
  1376
    then have "eventually (\<lambda>x. f x \<in> {B <..}) net"
hoelzl@51340
  1377
      by (intro S[rule_format]) auto
haftmann@56218
  1378
    then have "INFIMUM {x. B < f x} f \<le> y"
hoelzl@51340
  1379
      using P by auto
haftmann@56218
  1380
    moreover have "B \<le> INFIMUM {x. B < f x} f"
hoelzl@51340
  1381
      by (intro INF_greatest) auto
hoelzl@51340
  1382
    ultimately show "B \<le> y"
hoelzl@51340
  1383
      by simp
hoelzl@51340
  1384
  qed
hoelzl@51340
  1385
qed
hoelzl@51340
  1386
hoelzl@51340
  1387
lemma ereal_Limsup_Inf_monoset:
wenzelm@53788
  1388
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@51340
  1389
  shows "Limsup net f =
hoelzl@51340
  1390
    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
  1391
    (is "_ = Inf ?A")
hoelzl@51340
  1392
proof (safe intro!: Limsup_eqI complete_lattice_class.Inf_lower complete_lattice_class.Inf_greatest)
wenzelm@53788
  1393
  fix P
wenzelm@53788
  1394
  assume P: "eventually P net"
wenzelm@53788
  1395
  fix S
haftmann@56218
  1396
  assume S: "mono_set (uminus`S)" "SUPREMUM (Collect P) f \<in> S"
wenzelm@53788
  1397
  {
wenzelm@53788
  1398
    fix x
wenzelm@53788
  1399
    assume "P x"
haftmann@56218
  1400
    then have "f x \<le> SUPREMUM (Collect P) f"
hoelzl@51340
  1401
      by (intro complete_lattice_class.SUP_upper) simp
haftmann@56218
  1402
    with S(1)[unfolded mono_set, rule_format, of "- SUPREMUM (Collect P) f" "- f x"] S(2)
hoelzl@51340
  1403
    have "f x \<in> S"
hoelzl@51340
  1404
      by (simp add: inj_image_mem_iff) }
hoelzl@51340
  1405
  with P show "eventually (\<lambda>x. f x \<in> S) net"
hoelzl@51340
  1406
    by (auto elim: eventually_elim1)
hoelzl@51340
  1407
next
hoelzl@51340
  1408
  fix y l
hoelzl@51340
  1409
  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@56218
  1410
  assume P: "\<forall>P. eventually P net \<longrightarrow> y \<le> SUPREMUM (Collect P) f"
hoelzl@51340
  1411
  show "y \<le> l"
hoelzl@51340
  1412
  proof (rule dense_ge)
wenzelm@53788
  1413
    fix B
wenzelm@53788
  1414
    assume "l < B"
hoelzl@51340
  1415
    then have "eventually (\<lambda>x. f x \<in> {..< B}) net"
hoelzl@51340
  1416
      by (intro S[rule_format]) auto
haftmann@56218
  1417
    then have "y \<le> SUPREMUM {x. f x < B} f"
hoelzl@51340
  1418
      using P by auto
haftmann@56218
  1419
    moreover have "SUPREMUM {x. f x < B} f \<le> B"
hoelzl@51340
  1420
      by (intro SUP_least) auto
hoelzl@51340
  1421
    ultimately show "y \<le> B"
hoelzl@51340
  1422
      by simp
hoelzl@51340
  1423
  qed
hoelzl@51340
  1424
qed
hoelzl@51340
  1425
hoelzl@51340
  1426
lemma liminf_bounded_open:
hoelzl@51340
  1427
  fixes x :: "nat \<Rightarrow> ereal"
hoelzl@51340
  1428
  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
  1429
  (is "_ \<longleftrightarrow> ?P x0")
hoelzl@51340
  1430
proof
hoelzl@51340
  1431
  assume "?P x0"
hoelzl@51340
  1432
  then show "x0 \<le> liminf x"
hoelzl@51340
  1433
    unfolding ereal_Liminf_Sup_monoset eventually_sequentially
hoelzl@51340
  1434
    by (intro complete_lattice_class.Sup_upper) auto
hoelzl@51340
  1435
next
hoelzl@51340
  1436
  assume "x0 \<le> liminf x"
wenzelm@53788
  1437
  {
wenzelm@53788
  1438
    fix S :: "ereal set"
wenzelm@53788
  1439
    assume om: "open S" "mono_set S" "x0 \<in> S"
wenzelm@53788
  1440
    {
wenzelm@53788
  1441
      assume "S = UNIV"
wenzelm@53788
  1442
      then have "\<exists>N. \<forall>n\<ge>N. x n \<in> S"
wenzelm@53788
  1443
        by auto
wenzelm@53788
  1444
    }
hoelzl@51340
  1445
    moreover
wenzelm@53788
  1446
    {
wenzelm@53788
  1447
      assume "S \<noteq> UNIV"
wenzelm@53788
  1448
      then obtain B where B: "S = {B<..}"
wenzelm@53788
  1449
        using om ereal_open_mono_set by auto
wenzelm@53788
  1450
      then have "B < x0"
wenzelm@53788
  1451
        using om by auto
wenzelm@53788
  1452
      then have "\<exists>N. \<forall>n\<ge>N. x n \<in> S"
wenzelm@53788
  1453
        unfolding B
wenzelm@53788
  1454
        using `x0 \<le> liminf x` liminf_bounded_iff
wenzelm@53788
  1455
        by auto
hoelzl@51340
  1456
    }
wenzelm@53788
  1457
    ultimately have "\<exists>N. \<forall>n\<ge>N. x n \<in> S"
wenzelm@53788
  1458
      by auto
hoelzl@51340
  1459
  }
wenzelm@53788
  1460
  then show "?P x0"
wenzelm@53788
  1461
    by auto
hoelzl@51340
  1462
qed
hoelzl@51340
  1463
hoelzl@57446
  1464
subsection "Relate extended reals and the indicator function"
hoelzl@57446
  1465
hoelzl@57446
  1466
lemma ereal_indicator: "ereal (indicator A x) = indicator A x"
hoelzl@57446
  1467
  by (auto simp: indicator_def one_ereal_def)
hoelzl@57446
  1468
hoelzl@57446
  1469
lemma ereal_mult_indicator: "ereal (x * indicator A y) = ereal x * indicator A y"
hoelzl@57446
  1470
  by (simp split: split_indicator)
hoelzl@57446
  1471
hoelzl@57446
  1472
lemma ereal_indicator_mult: "ereal (indicator A y * x) = indicator A y * ereal x"
hoelzl@57446
  1473
  by (simp split: split_indicator)
hoelzl@57446
  1474
hoelzl@57446
  1475
lemma ereal_indicator_nonneg[simp, intro]: "0 \<le> (indicator A x ::ereal)"
hoelzl@57446
  1476
  unfolding indicator_def by auto
hoelzl@57446
  1477
huffman@44125
  1478
end