src/HOL/Probability/Positive_Infinite_Real.thy
author wenzelm
Wed, 01 Sep 2010 18:18:47 +0200
changeset 38976 a4a465dc89d9
parent 38705 aaee86c0e237
child 39092 98de40859858
permissions -rw-r--r--
Document.State.Assignment: eliminated promise in favour of plain values -- signalling is done via event bus in Session;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38656
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
     1
(* Author: Johannes Hoelzl, TU Muenchen *)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
     2
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
     3
header {* A type for positive real numbers with infinity *}
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
     4
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
     5
theory Positive_Infinite_Real
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
     6
  imports Complex_Main Nat_Bijection Multivariate_Analysis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
     7
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
     8
38705
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
     9
lemma (in complete_lattice) Sup_start:
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    10
  assumes *: "\<And>x. f x \<le> f 0"
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    11
  shows "(SUP n. f n) = f 0"
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    12
proof (rule antisym)
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    13
  show "f 0 \<le> (SUP n. f n)" by (rule le_SUPI) auto
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    14
  show "(SUP n. f n) \<le> f 0" by (rule SUP_leI[OF *])
38656
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    15
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    16
38705
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    17
lemma (in complete_lattice) Inf_start:
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    18
  assumes *: "\<And>x. f 0 \<le> f x"
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    19
  shows "(INF n. f n) = f 0"
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    20
proof (rule antisym)
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    21
  show "(INF n. f n) \<le> f 0" by (rule INF_leI) simp
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    22
  show "f 0 \<le> (INF n. f n)" by (rule le_INFI[OF *])
38656
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    23
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    24
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    25
lemma (in complete_lattice) Sup_mono_offset:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    26
  fixes f :: "'b :: {ordered_ab_semigroup_add,monoid_add} \<Rightarrow> 'a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    27
  assumes *: "\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y" and "0 \<le> k"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    28
  shows "(SUP n . f (k + n)) = (SUP n. f n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    29
proof (rule antisym)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    30
  show "(SUP n. f (k + n)) \<le> (SUP n. f n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    31
    by (auto intro!: Sup_mono simp: SUPR_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    32
  { fix n :: 'b
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    33
    have "0 + n \<le> k + n" using `0 \<le> k` by (rule add_right_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    34
    with * have "f n \<le> f (k + n)" by simp }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    35
  thus "(SUP n. f n) \<le> (SUP n. f (k + n))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    36
    by (auto intro!: Sup_mono exI simp: SUPR_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    37
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    38
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    39
lemma (in complete_lattice) Sup_mono_offset_Suc:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    40
  assumes *: "\<And>x. f x \<le> f (Suc x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    41
  shows "(SUP n . f (Suc n)) = (SUP n. f n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    42
  unfolding Suc_eq_plus1
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    43
  apply (subst add_commute)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    44
  apply (rule Sup_mono_offset)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    45
  by (auto intro!: order.lift_Suc_mono_le[of "op \<le>" "op <" f, OF _ *]) default
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    46
38705
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    47
lemma (in complete_lattice) Inf_mono_offset:
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    48
  fixes f :: "'b :: {ordered_ab_semigroup_add,monoid_add} \<Rightarrow> 'a"
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    49
  assumes *: "\<And>x y. x \<le> y \<Longrightarrow> f y \<le> f x" and "0 \<le> k"
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    50
  shows "(INF n . f (k + n)) = (INF n. f n)"
38656
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    51
proof (rule antisym)
38705
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    52
  show "(INF n. f n) \<le> (INF n. f (k + n))"
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    53
    by (auto intro!: Inf_mono simp: INFI_def)
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    54
  { fix n :: 'b
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    55
    have "0 + n \<le> k + n" using `0 \<le> k` by (rule add_right_mono)
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    56
    with * have "f (k + n) \<le> f n" by simp }
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    57
  thus "(INF n. f (k + n)) \<le> (INF n. f n)"
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
    58
    by (auto intro!: Inf_mono exI simp: INFI_def)
38656
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    59
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    60
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    61
lemma (in complete_lattice) isotone_converge:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    62
  fixes f :: "nat \<Rightarrow> 'a" assumes "\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y "
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    63
  shows "(INF n. SUP m. f (n + m)) = (SUP n. INF m. f (n + m))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    64
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    65
  have "\<And>n. (SUP m. f (n + m)) = (SUP n. f n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    66
    apply (rule Sup_mono_offset)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    67
    apply (rule assms)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    68
    by simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    69
  moreover
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    70
  { fix n have "(INF m. f (n + m)) = f n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    71
      using Inf_start[of "\<lambda>m. f (n + m)"] assms by simp }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    72
  ultimately show ?thesis by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    73
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    74
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    75
lemma (in complete_lattice) antitone_converges:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    76
  fixes f :: "nat \<Rightarrow> 'a" assumes "\<And>x y. x \<le> y \<Longrightarrow> f y \<le> f x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    77
  shows "(INF n. SUP m. f (n + m)) = (SUP n. INF m. f (n + m))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    78
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    79
  have "\<And>n. (INF m. f (n + m)) = (INF n. f n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    80
    apply (rule Inf_mono_offset)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    81
    apply (rule assms)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    82
    by simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    83
  moreover
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    84
  { fix n have "(SUP m. f (n + m)) = f n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    85
      using Sup_start[of "\<lambda>m. f (n + m)"] assms by simp }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    86
  ultimately show ?thesis by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    87
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    88
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    89
text {*
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    90
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    91
We introduce the the positive real numbers as needed for measure theory.
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    92
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    93
*}
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    94
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    95
typedef pinfreal = "(Some ` {0::real..}) \<union> {None}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    96
  by (rule exI[of _ None]) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    97
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    98
subsection "Introduce @{typ pinfreal} similar to a datatype"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
    99
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   100
definition "Real x = Abs_pinfreal (Some (sup 0 x))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   101
definition "\<omega> = Abs_pinfreal None"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   102
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   103
definition "pinfreal_case f i x = (if x = \<omega> then i else f (THE r. 0 \<le> r \<and> x = Real r))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   104
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   105
definition "of_pinfreal = pinfreal_case (\<lambda>x. x) 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   106
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   107
defs (overloaded)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   108
  real_of_pinfreal_def [code_unfold]: "real == of_pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   109
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   110
lemma pinfreal_Some[simp]: "0 \<le> x \<Longrightarrow> Some x \<in> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   111
  unfolding pinfreal_def by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   112
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   113
lemma pinfreal_Some_sup[simp]: "Some (sup 0 x) \<in> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   114
  by (simp add: sup_ge1)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   115
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   116
lemma pinfreal_None[simp]: "None \<in> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   117
  unfolding pinfreal_def by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   118
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   119
lemma Real_inj[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   120
  assumes  "0 \<le> x" and "0 \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   121
  shows "Real x = Real y \<longleftrightarrow> x = y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   122
  unfolding Real_def assms[THEN sup_absorb2]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   123
  using assms by (simp add: Abs_pinfreal_inject)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   124
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   125
lemma Real_neq_\<omega>[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   126
  "Real x = \<omega> \<longleftrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   127
  "\<omega> = Real x \<longleftrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   128
  by (simp_all add: Abs_pinfreal_inject \<omega>_def Real_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   129
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   130
lemma Real_neg: "x < 0 \<Longrightarrow> Real x = Real 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   131
  unfolding Real_def by (auto simp add: Abs_pinfreal_inject intro!: sup_absorb1)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   132
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   133
lemma pinfreal_cases[case_names preal infinite, cases type: pinfreal]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   134
  assumes preal: "\<And>r. x = Real r \<Longrightarrow> 0 \<le> r \<Longrightarrow> P" and inf: "x = \<omega> \<Longrightarrow> P"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   135
  shows P
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   136
proof (cases x rule: pinfreal.Abs_pinfreal_cases)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   137
  case (Abs_pinfreal y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   138
  hence "y = None \<or> (\<exists>x \<ge> 0. y = Some x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   139
    unfolding pinfreal_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   140
  thus P
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   141
  proof (rule disjE)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   142
    assume "\<exists>x\<ge>0. y = Some x" then guess x ..
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   143
    thus P by (simp add: preal[of x] Real_def Abs_pinfreal(1) sup_absorb2)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   144
  qed (simp add: \<omega>_def Abs_pinfreal(1) inf)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   145
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   146
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   147
lemma pinfreal_case_\<omega>[simp]: "pinfreal_case f i \<omega> = i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   148
  unfolding pinfreal_case_def by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   149
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   150
lemma pinfreal_case_Real[simp]: "pinfreal_case f i (Real x) = (if 0 \<le> x then f x else f 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   151
proof (cases "0 \<le> x")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   152
  case True thus ?thesis unfolding pinfreal_case_def by (auto intro: theI2)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   153
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   154
  case False
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   155
  moreover have "(THE r. 0 \<le> r \<and> Real 0 = Real r) = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   156
    by (auto intro!: the_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   157
  ultimately show ?thesis unfolding pinfreal_case_def by (simp add: Real_neg)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   158
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   159
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   160
lemma pinfreal_case_cancel[simp]: "pinfreal_case (\<lambda>c. i) i x = i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   161
  by (cases x) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   162
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   163
lemma pinfreal_case_split:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   164
  "P (pinfreal_case f i x) = ((x = \<omega> \<longrightarrow> P i) \<and> (\<forall>r\<ge>0. x = Real r \<longrightarrow> P (f r)))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   165
  by (cases x) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   166
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   167
lemma pinfreal_case_split_asm:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   168
  "P (pinfreal_case f i x) = (\<not> (x = \<omega> \<and> \<not> P i \<or> (\<exists>r. r \<ge> 0 \<and> x = Real r \<and> \<not> P (f r))))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   169
  by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   170
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   171
lemma pinfreal_case_cong[cong]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   172
  assumes eq: "x = x'" "i = i'" and cong: "\<And>r. 0 \<le> r \<Longrightarrow> f r = f' r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   173
  shows "pinfreal_case f i x = pinfreal_case f' i' x'"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   174
  unfolding eq using cong by (cases x') simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   175
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   176
lemma real_Real[simp]: "real (Real x) = (if 0 \<le> x then x else 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   177
  unfolding real_of_pinfreal_def of_pinfreal_def by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   178
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   179
lemma Real_real_image:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   180
  assumes "\<omega> \<notin> A" shows "Real ` real ` A = A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   181
proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   182
  fix x assume "x \<in> A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   183
  hence *: "x = Real (real x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   184
    using `\<omega> \<notin> A` by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   185
  show "x \<in> Real ` real ` A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   186
    using `x \<in> A` by (subst *) (auto intro!: imageI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   187
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   188
  fix x assume "x \<in> A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   189
  thus "Real (real x) \<in> A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   190
    using `\<omega> \<notin> A` by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   191
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   192
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   193
lemma real_pinfreal_nonneg[simp, intro]: "0 \<le> real (x :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   194
  unfolding real_of_pinfreal_def of_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   195
  by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   196
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   197
lemma real_\<omega>[simp]: "real \<omega> = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   198
  unfolding real_of_pinfreal_def of_pinfreal_def by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   199
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   200
lemma pinfreal_noteq_omega_Ex: "X \<noteq> \<omega> \<longleftrightarrow> (\<exists>r\<ge>0. X = Real r)" by (cases X) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   201
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   202
subsection "@{typ pinfreal} is a monoid for addition"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   203
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   204
instantiation pinfreal :: comm_monoid_add
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   205
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   206
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   207
definition "0 = Real 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   208
definition "x + y = pinfreal_case (\<lambda>r. pinfreal_case (\<lambda>p. Real (r + p)) \<omega> y) \<omega> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   209
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   210
lemma pinfreal_plus[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   211
  "Real r + Real p = (if 0 \<le> r then if 0 \<le> p then Real (r + p) else Real r else Real p)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   212
  "x + 0 = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   213
  "0 + x = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   214
  "x + \<omega> = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   215
  "\<omega> + x = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   216
  by (simp_all add: plus_pinfreal_def Real_neg zero_pinfreal_def split: pinfreal_case_split)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   217
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   218
lemma \<omega>_neq_0[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   219
  "\<omega> = 0 \<longleftrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   220
  "0 = \<omega> \<longleftrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   221
  by (simp_all add: zero_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   222
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   223
lemma Real_eq_0[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   224
  "Real r = 0 \<longleftrightarrow> r \<le> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   225
  "0 = Real r \<longleftrightarrow> r \<le> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   226
  by (auto simp add: Abs_pinfreal_inject zero_pinfreal_def Real_def sup_real_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   227
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   228
lemma Real_0[simp]: "Real 0 = 0" by (simp add: zero_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   229
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   230
instance
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   231
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   232
  fix a :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   233
  show "0 + a = a" by (cases a) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   234
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   235
  fix b show "a + b = b + a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   236
    by (cases a, cases b) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   237
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   238
  fix c show "a + b + c = a + (b + c)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   239
    by (cases a, cases b, cases c) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   240
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   241
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   242
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   243
lemma pinfreal_plus_eq_\<omega>[simp]: "(a :: pinfreal) + b = \<omega> \<longleftrightarrow> a = \<omega> \<or> b = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   244
  by (cases a, cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   245
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   246
lemma pinfreal_add_cancel_left:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   247
  "a + b = a + c \<longleftrightarrow> (a = \<omega> \<or> b = c)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   248
  by (cases a, cases b, cases c, simp_all, cases c, simp_all)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   249
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   250
lemma pinfreal_add_cancel_right:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   251
  "b + a = c + a \<longleftrightarrow> (a = \<omega> \<or> b = c)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   252
  by (cases a, cases b, cases c, simp_all, cases c, simp_all)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   253
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   254
lemma Real_eq_Real:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   255
  "Real a = Real b \<longleftrightarrow> (a = b \<or> (a \<le> 0 \<and> b \<le> 0))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   256
proof (cases "a \<le> 0 \<or> b \<le> 0")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   257
  case False with Real_inj[of a b] show ?thesis by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   258
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   259
  case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   260
  thus ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   261
  proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   262
    assume "a \<le> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   263
    hence *: "Real a = 0" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   264
    show ?thesis using `a \<le> 0` unfolding * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   265
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   266
    assume "b \<le> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   267
    hence *: "Real b = 0" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   268
    show ?thesis using `b \<le> 0` unfolding * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   269
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   270
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   271
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   272
lemma real_pinfreal_0[simp]: "real (0 :: pinfreal) = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   273
  unfolding zero_pinfreal_def real_Real by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   274
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   275
lemma real_of_pinfreal_eq_0: "real X = 0 \<longleftrightarrow> (X = 0 \<or> X = \<omega>)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   276
  by (cases X) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   277
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   278
lemma real_of_pinfreal_eq: "real X = real Y \<longleftrightarrow>
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   279
    (X = Y \<or> (X = 0 \<and> Y = \<omega>) \<or> (Y = 0 \<and> X = \<omega>))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   280
  by (cases X, cases Y) (auto simp add: real_of_pinfreal_eq_0)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   281
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   282
lemma real_of_pinfreal_add: "real X + real Y =
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   283
    (if X = \<omega> then real Y else if Y = \<omega> then real X else real (X + Y))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   284
  by (auto simp: pinfreal_noteq_omega_Ex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   285
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   286
subsection "@{typ pinfreal} is a monoid for multiplication"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   287
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   288
instantiation pinfreal :: comm_monoid_mult
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   289
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   290
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   291
definition "1 = Real 1"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   292
definition "x * y = (if x = 0 \<or> y = 0 then 0 else
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   293
  pinfreal_case (\<lambda>r. pinfreal_case (\<lambda>p. Real (r * p)) \<omega> y) \<omega> x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   294
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   295
lemma pinfreal_times[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   296
  "Real r * Real p = (if 0 \<le> r \<and> 0 \<le> p then Real (r * p) else 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   297
  "\<omega> * x = (if x = 0 then 0 else \<omega>)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   298
  "x * \<omega> = (if x = 0 then 0 else \<omega>)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   299
  "0 * x = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   300
  "x * 0 = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   301
  "1 = \<omega> \<longleftrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   302
  "\<omega> = 1 \<longleftrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   303
  by (auto simp add: times_pinfreal_def one_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   304
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   305
lemma pinfreal_one_mult[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   306
  "Real x + 1 = (if 0 \<le> x then Real (x + 1) else 1)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   307
  "1 + Real x = (if 0 \<le> x then Real (1 + x) else 1)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   308
  unfolding one_pinfreal_def by simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   309
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   310
instance
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   311
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   312
  fix a :: pinfreal show "1 * a = a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   313
    by (cases a) (simp_all add: one_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   314
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   315
  fix b show "a * b = b * a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   316
    by (cases a, cases b) (simp_all add: mult_nonneg_nonneg)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   317
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   318
  fix c show "a * b * c = a * (b * c)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   319
    apply (cases a, cases b, cases c)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   320
    apply (simp_all add: mult_nonneg_nonneg not_le mult_pos_pos)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   321
    apply (cases b, cases c)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   322
    apply (simp_all add: mult_nonneg_nonneg not_le mult_pos_pos)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   323
    done
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   324
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   325
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   326
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   327
lemma pinfreal_mult_cancel_left:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   328
  "a * b = a * c \<longleftrightarrow> (a = 0 \<or> b = c \<or> (a = \<omega> \<and> b \<noteq> 0 \<and> c \<noteq> 0))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   329
  by (cases a, cases b, cases c, auto simp: Real_eq_Real mult_le_0_iff, cases c, auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   330
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   331
lemma pinfreal_mult_cancel_right:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   332
  "b * a = c * a \<longleftrightarrow> (a = 0 \<or> b = c \<or> (a = \<omega> \<and> b \<noteq> 0 \<and> c \<noteq> 0))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   333
  by (cases a, cases b, cases c, auto simp: Real_eq_Real mult_le_0_iff, cases c, auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   334
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   335
lemma Real_1[simp]: "Real 1 = 1" by (simp add: one_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   336
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   337
lemma real_pinfreal_1[simp]: "real (1 :: pinfreal) = 1"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   338
  unfolding one_pinfreal_def real_Real by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   339
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   340
lemma real_of_pinfreal_mult: "real X * real Y = real (X * Y :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   341
  by (cases X, cases Y) (auto simp: zero_le_mult_iff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   342
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   343
subsection "@{typ pinfreal} is a linear order"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   344
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   345
instantiation pinfreal :: linorder
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   346
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   347
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   348
definition "x < y \<longleftrightarrow> pinfreal_case (\<lambda>i. pinfreal_case (\<lambda>j. i < j) True y) False x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   349
definition "x \<le> y \<longleftrightarrow> pinfreal_case (\<lambda>j. pinfreal_case (\<lambda>i. i \<le> j) False x) True y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   350
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   351
lemma pinfreal_less[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   352
  "Real r < \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   353
  "Real r < Real p \<longleftrightarrow> (if 0 \<le> r \<and> 0 \<le> p then r < p else 0 < p)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   354
  "\<omega> < x \<longleftrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   355
  "0 < \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   356
  "0 < Real r \<longleftrightarrow> 0 < r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   357
  "x < 0 \<longleftrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   358
  "0 < (1::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   359
  by (simp_all add: less_pinfreal_def zero_pinfreal_def one_pinfreal_def del: Real_0 Real_1)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   360
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   361
lemma pinfreal_less_eq[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   362
  "x \<le> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   363
  "Real r \<le> Real p \<longleftrightarrow> (if 0 \<le> r \<and> 0 \<le> p then r \<le> p else r \<le> 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   364
  "0 \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   365
  by (simp_all add: less_eq_pinfreal_def zero_pinfreal_def del: Real_0)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   366
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   367
lemma pinfreal_\<omega>_less_eq[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   368
  "\<omega> \<le> x \<longleftrightarrow> x = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   369
  by (cases x) (simp_all add: not_le less_eq_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   370
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   371
lemma pinfreal_less_eq_zero[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   372
  "(x::pinfreal) \<le> 0 \<longleftrightarrow> x = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   373
  by (cases x) (simp_all add: zero_pinfreal_def del: Real_0)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   374
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   375
instance
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   376
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   377
  fix x :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   378
  show "x \<le> x" by (cases x) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   379
  fix y
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   380
  show "(x < y) = (x \<le> y \<and> \<not> y \<le> x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   381
    by (cases x, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   382
  show "x \<le> y \<or> y \<le> x "
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   383
    by (cases x, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   384
  { assume "x \<le> y" "y \<le> x" thus "x = y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   385
      by (cases x, cases y) auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   386
  { fix z assume "x \<le> y" "y \<le> z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   387
    thus "x \<le> z" by (cases x, cases y, cases z) auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   388
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   389
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   390
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   391
lemma pinfreal_zero_lessI[intro]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   392
  "(a :: pinfreal) \<noteq> 0 \<Longrightarrow> 0 < a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   393
  by (cases a) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   394
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   395
lemma pinfreal_less_omegaI[intro, simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   396
  "a \<noteq> \<omega> \<Longrightarrow> a < \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   397
  by (cases a) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   398
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   399
lemma pinfreal_plus_eq_0[simp]: "(a :: pinfreal) + b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   400
  by (cases a, cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   401
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   402
lemma pinfreal_le_add1[simp, intro]: "n \<le> n + (m::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   403
  by (cases n, cases m) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   404
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   405
lemma pinfreal_le_add2: "(n::pinfreal) + m \<le> k \<Longrightarrow> m \<le> k"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   406
  by (cases n, cases m, cases k) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   407
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   408
lemma pinfreal_le_add3: "(n::pinfreal) + m \<le> k \<Longrightarrow> n \<le> k"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   409
  by (cases n, cases m, cases k) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   410
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   411
lemma pinfreal_less_\<omega>: "x < \<omega> \<longleftrightarrow> x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   412
  by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   413
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   414
subsection {* @{text "x - y"} on @{typ pinfreal} *}
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   415
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   416
instantiation pinfreal :: minus
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   417
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   418
definition "x - y = (if y < x then THE d. x = y + d else 0 :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   419
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   420
lemma minus_pinfreal_eq:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   421
  "(x - y = (z :: pinfreal)) \<longleftrightarrow> (if y < x then x = y + z else z = 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   422
  (is "?diff \<longleftrightarrow> ?if")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   423
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   424
  assume ?diff
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   425
  thus ?if
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   426
  proof (cases "y < x")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   427
    case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   428
    then obtain p where p: "y = Real p" "0 \<le> p" by (cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   429
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   430
    show ?thesis unfolding `?diff`[symmetric] if_P[OF True] minus_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   431
    proof (rule theI2[where Q="\<lambda>d. x = y + d"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   432
      show "x = y + pinfreal_case (\<lambda>r. Real (r - real y)) \<omega> x" (is "x = y + ?d")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   433
        using `y < x` p by (cases x) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   434
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   435
      fix d assume "x = y + d"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   436
      thus "d = ?d" using `y < x` p by (cases d, cases x) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   437
    qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   438
  qed (simp add: minus_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   439
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   440
  assume ?if
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   441
  thus ?diff
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   442
  proof (cases "y < x")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   443
    case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   444
    then obtain p where p: "y = Real p" "0 \<le> p" by (cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   445
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   446
    from True `?if` have "x = y + z" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   447
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   448
    show ?thesis unfolding minus_pinfreal_def if_P[OF True] unfolding `x = y + z`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   449
    proof (rule the_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   450
      fix d :: pinfreal assume "y + z = y + d"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   451
      thus "d = z" using `y < x` p
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   452
        by (cases d, cases z) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   453
    qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   454
  qed (simp add: minus_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   455
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   456
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   457
instance ..
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   458
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   459
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   460
lemma pinfreal_minus[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   461
  "Real r - Real p = (if 0 \<le> r \<and> p < r then if 0 \<le> p then Real (r - p) else Real r else 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   462
  "(A::pinfreal) - A = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   463
  "\<omega> - Real r = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   464
  "Real r - \<omega> = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   465
  "A - 0 = A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   466
  "0 - A = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   467
  by (auto simp: minus_pinfreal_eq not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   468
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   469
lemma pinfreal_le_epsilon:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   470
  fixes x y :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   471
  assumes "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   472
  shows "x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   473
proof (cases y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   474
  case (preal r)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   475
  then obtain p where x: "x = Real p" "0 \<le> p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   476
    using assms[of 1] by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   477
  { fix e have "0 < e \<Longrightarrow> p \<le> r + e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   478
      using assms[of "Real e"] preal x by auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   479
  hence "p \<le> r" by (rule field_le_epsilon)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   480
  thus ?thesis using preal x by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   481
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   482
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   483
instance pinfreal :: "{ordered_comm_semiring, comm_semiring_1}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   484
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   485
  show "0 \<noteq> (1::pinfreal)" unfolding zero_pinfreal_def one_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   486
    by (simp del: Real_1 Real_0)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   487
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   488
  fix a :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   489
  show "0 * a = 0" "a * 0 = 0" by simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   490
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   491
  fix b c :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   492
  show "(a + b) * c = a * c + b * c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   493
    by (cases c, cases a, cases b)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   494
       (auto intro!: arg_cong[where f=Real] simp: field_simps not_le mult_le_0_iff mult_less_0_iff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   495
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   496
  { assume "a \<le> b" thus "c + a \<le> c + b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   497
     by (cases c, cases a, cases b) auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   498
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   499
  assume "a \<le> b" "0 \<le> c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   500
  thus "c * a \<le> c * b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   501
    apply (cases c, cases a, cases b)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   502
    by (auto simp: mult_left_mono mult_le_0_iff mult_less_0_iff not_le)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   503
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   504
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   505
lemma mult_\<omega>[simp]: "x * y = \<omega> \<longleftrightarrow> (x = \<omega> \<or> y = \<omega>) \<and> x \<noteq> 0 \<and> y \<noteq> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   506
  by (cases x, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   507
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   508
lemma \<omega>_mult[simp]: "(\<omega> = x * y) = ((x = \<omega> \<or> y = \<omega>) \<and> x \<noteq> 0 \<and> y \<noteq> 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   509
  by (cases x, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   510
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   511
lemma pinfreal_mult_0[simp]: "x * y = 0 \<longleftrightarrow> x = 0 \<or> (y::pinfreal) = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   512
  by (cases x, cases y) (auto simp: mult_le_0_iff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   513
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   514
lemma pinfreal_mult_cancel:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   515
  fixes x y z :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   516
  assumes "y \<le> z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   517
  shows "x * y \<le> x * z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   518
  using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   519
  by (cases x, cases y, cases z)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   520
     (auto simp: mult_le_cancel_left mult_le_0_iff mult_less_0_iff not_le)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   521
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   522
lemma Real_power[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   523
  "Real x ^ n = (if x \<le> 0 then (if n = 0 then 1 else 0) else Real (x ^ n))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   524
  by (induct n) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   525
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   526
lemma Real_power_\<omega>[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   527
  "\<omega> ^ n = (if n = 0 then 1 else \<omega>)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   528
  by (induct n) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   529
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   530
lemma pinfreal_of_nat[simp]: "of_nat m = Real (real m)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   531
  by (induct m) (auto simp: real_of_nat_Suc one_pinfreal_def simp del: Real_1)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   532
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   533
lemma real_of_pinfreal_mono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   534
  fixes a b :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   535
  assumes "b \<noteq> \<omega>" "a \<le> b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   536
  shows "real a \<le> real b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   537
using assms by (cases b, cases a) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   538
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   539
instance pinfreal :: "semiring_char_0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   540
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   541
  fix m n
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   542
  show "inj (of_nat::nat\<Rightarrow>pinfreal)" by (auto intro!: inj_onI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   543
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   544
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   545
subsection "@{typ pinfreal} is a complete lattice"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   546
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   547
instantiation pinfreal :: lattice
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   548
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   549
definition [simp]: "sup x y = (max x y :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   550
definition [simp]: "inf x y = (min x y :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   551
instance proof qed simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   552
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   553
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   554
instantiation pinfreal :: complete_lattice
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   555
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   556
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   557
definition "bot = Real 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   558
definition "top = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   559
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   560
definition "Sup S = (LEAST z. \<forall>x\<in>S. x \<le> z :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   561
definition "Inf S = (GREATEST z. \<forall>x\<in>S. z \<le> x :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   562
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   563
lemma pinfreal_complete_Sup:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   564
  fixes S :: "pinfreal set" assumes "S \<noteq> {}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   565
  shows "\<exists>x. (\<forall>y\<in>S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>S. y \<le> z) \<longrightarrow> x \<le> z)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   566
proof (cases "\<exists>x\<ge>0. \<forall>a\<in>S. a \<le> Real x")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   567
  case False
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   568
  hence *: "\<And>x. x\<ge>0 \<Longrightarrow> \<exists>a\<in>S. \<not>a \<le> Real x" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   569
  show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   570
  proof (safe intro!: exI[of _ \<omega>])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   571
    fix y assume **: "\<forall>z\<in>S. z \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   572
    show "\<omega> \<le> y" unfolding pinfreal_\<omega>_less_eq
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   573
    proof (rule ccontr)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   574
      assume "y \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   575
      then obtain x where [simp]: "y = Real x" and "0 \<le> x" by (cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   576
      from *[OF `0 \<le> x`] show False using ** by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   577
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   578
  qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   579
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   580
  case True then obtain y where y: "\<And>a. a\<in>S \<Longrightarrow> a \<le> Real y" and "0 \<le> y" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   581
  from y[of \<omega>] have "\<omega> \<notin> S" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   582
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   583
  with `S \<noteq> {}` obtain x where "x \<in> S" and "x \<noteq> \<omega>" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   584
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   585
  have bound: "\<forall>x\<in>real ` S. x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   586
  proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   587
    fix z assume "z \<in> real ` S" then guess a ..
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   588
    with y[of a] `\<omega> \<notin> S` `0 \<le> y` show "z \<le> y" by (cases a) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   589
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   590
  with reals_complete2[of "real ` S"] `x \<in> S`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   591
  obtain s where s: "\<forall>y\<in>S. real y \<le> s" "\<forall>z. ((\<forall>y\<in>S. real y \<le> z) \<longrightarrow> s \<le> z)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   592
    by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   593
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   594
  show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   595
  proof (safe intro!: exI[of _ "Real s"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   596
    fix z assume "z \<in> S" thus "z \<le> Real s"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   597
      using s `\<omega> \<notin> S` by (cases z) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   598
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   599
    fix z assume *: "\<forall>y\<in>S. y \<le> z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   600
    show "Real s \<le> z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   601
    proof (cases z)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   602
      case (preal u)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   603
      { fix v assume "v \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   604
        hence "v \<le> Real u" using * preal by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   605
        hence "real v \<le> u" using `\<omega> \<notin> S` `0 \<le> u` by (cases v) auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   606
      hence "s \<le> u" using s(2) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   607
      thus "Real s \<le> z" using preal by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   608
    qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   609
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   610
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   611
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   612
lemma pinfreal_complete_Inf:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   613
  fixes S :: "pinfreal set" assumes "S \<noteq> {}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   614
  shows "\<exists>x. (\<forall>y\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   615
proof (cases "S = {\<omega>}")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   616
  case True thus ?thesis by (auto intro!: exI[of _ \<omega>])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   617
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   618
  case False with `S \<noteq> {}` have "S - {\<omega>} \<noteq> {}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   619
  hence not_empty: "\<exists>x. x \<in> uminus ` real ` (S - {\<omega>})" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   620
  have bounds: "\<exists>x. \<forall>y\<in>uminus ` real ` (S - {\<omega>}). y \<le> x" by (auto intro!: exI[of _ 0])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   621
  from reals_complete2[OF not_empty bounds]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   622
  obtain s where s: "\<And>y. y\<in>S - {\<omega>} \<Longrightarrow> - real y \<le> s" "\<forall>z. ((\<forall>y\<in>S - {\<omega>}. - real y \<le> z) \<longrightarrow> s \<le> z)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   623
    by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   624
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   625
  show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   626
  proof (safe intro!: exI[of _ "Real (-s)"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   627
    fix z assume "z \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   628
    show "Real (-s) \<le> z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   629
    proof (cases z)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   630
      case (preal r)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   631
      with s `z \<in> S` have "z \<in> S - {\<omega>}" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   632
      hence "- r \<le> s" using preal s(1)[of z] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   633
      hence "- s \<le> r" by (subst neg_le_iff_le[symmetric]) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   634
      thus ?thesis using preal by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   635
    qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   636
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   637
    fix z assume *: "\<forall>y\<in>S. z \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   638
    show "z \<le> Real (-s)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   639
    proof (cases z)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   640
      case (preal u)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   641
      { fix v assume "v \<in> S-{\<omega>}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   642
        hence "Real u \<le> v" using * preal by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   643
        hence "- real v \<le> - u" using `0 \<le> u` `v \<in> S - {\<omega>}` by (cases v) auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   644
      hence "u \<le> - s" using s(2) by (subst neg_le_iff_le[symmetric]) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   645
      thus "z \<le> Real (-s)" using preal by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   646
    next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   647
      case infinite
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   648
      with * have "S = {\<omega>}" using `S \<noteq> {}` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   649
      with `S - {\<omega>} \<noteq> {}` show ?thesis by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   650
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   651
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   652
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   653
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   654
instance
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   655
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   656
  fix x :: pinfreal and A
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   657
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   658
  show "bot \<le> x" by (cases x) (simp_all add: bot_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   659
  show "x \<le> top" by (simp add: top_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   660
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   661
  { assume "x \<in> A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   662
    with pinfreal_complete_Sup[of A]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   663
    obtain s where s: "\<forall>y\<in>A. y \<le> s" "\<forall>z. (\<forall>y\<in>A. y \<le> z) \<longrightarrow> s \<le> z" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   664
    hence "x \<le> s" using `x \<in> A` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   665
    also have "... = Sup A" using s unfolding Sup_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   666
      by (auto intro!: Least_equality[symmetric])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   667
    finally show "x \<le> Sup A" . }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   668
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   669
  { assume "x \<in> A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   670
    with pinfreal_complete_Inf[of A]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   671
    obtain i where i: "\<forall>y\<in>A. i \<le> y" "\<forall>z. (\<forall>y\<in>A. z \<le> y) \<longrightarrow> z \<le> i" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   672
    hence "Inf A = i" unfolding Inf_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   673
      by (auto intro!: Greatest_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   674
    also have "i \<le> x" using i `x \<in> A` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   675
    finally show "Inf A \<le> x" . }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   676
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   677
  { assume *: "\<And>z. z \<in> A \<Longrightarrow> z \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   678
    show "Sup A \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   679
    proof (cases "A = {}")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   680
      case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   681
      hence "Sup A = 0" unfolding Sup_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   682
        by (auto intro!: Least_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   683
      thus "Sup A \<le> x" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   684
    next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   685
      case False
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   686
      with pinfreal_complete_Sup[of A]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   687
      obtain s where s: "\<forall>y\<in>A. y \<le> s" "\<forall>z. (\<forall>y\<in>A. y \<le> z) \<longrightarrow> s \<le> z" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   688
      hence "Sup A = s"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   689
        unfolding Sup_pinfreal_def by (auto intro!: Least_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   690
      also have "s \<le> x" using * s by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   691
      finally show "Sup A \<le> x" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   692
    qed }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   693
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   694
  { assume *: "\<And>z. z \<in> A \<Longrightarrow> x \<le> z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   695
    show "x \<le> Inf A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   696
    proof (cases "A = {}")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   697
      case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   698
      hence "Inf A = \<omega>" unfolding Inf_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   699
        by (auto intro!: Greatest_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   700
      thus "x \<le> Inf A" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   701
    next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   702
      case False
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   703
      with pinfreal_complete_Inf[of A]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   704
      obtain i where i: "\<forall>y\<in>A. i \<le> y" "\<forall>z. (\<forall>y\<in>A. z \<le> y) \<longrightarrow> z \<le> i" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   705
      have "x \<le> i" using * i by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   706
      also have "i = Inf A" using i
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   707
        unfolding Inf_pinfreal_def by (auto intro!: Greatest_equality[symmetric])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   708
      finally show "x \<le> Inf A" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   709
    qed }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   710
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   711
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   712
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   713
lemma Inf_pinfreal_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   714
  fixes z :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   715
  shows "(\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> (\<exists>x\<in>X. x<y) \<longleftrightarrow> Inf X < y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   716
  by (metis complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower less_le_not_le linear
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   717
            order_less_le_trans)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   718
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   719
lemma Inf_greater:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   720
  fixes z :: pinfreal assumes "Inf X < z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   721
  shows "\<exists>x \<in> X. x < z"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   722
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   723
  have "X \<noteq> {}" using assms by (auto simp: Inf_empty top_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   724
  with assms show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   725
    by (metis Inf_pinfreal_iff mem_def not_leE)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   726
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   727
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   728
lemma Inf_close:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   729
  fixes e :: pinfreal assumes "Inf X \<noteq> \<omega>" "0 < e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   730
  shows "\<exists>x \<in> X. x < Inf X + e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   731
proof (rule Inf_greater)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   732
  show "Inf X < Inf X + e" using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   733
    by (cases "Inf X", cases e) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   734
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   735
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   736
lemma pinfreal_SUPI:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   737
  fixes x :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   738
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   739
  assumes "\<And>y. (\<And>i. i \<in> A \<Longrightarrow> f i \<le> y) \<Longrightarrow> x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   740
  shows "(SUP i:A. f i) = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   741
  unfolding SUPR_def Sup_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   742
  using assms by (auto intro!: Least_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   743
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   744
lemma Sup_pinfreal_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   745
  fixes z :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   746
  shows "(\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> (\<exists>x\<in>X. y<x) \<longleftrightarrow> y < Sup X"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   747
  by (metis complete_lattice_class.Sup_least complete_lattice_class.Sup_upper less_le_not_le linear
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   748
            order_less_le_trans)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   749
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   750
lemma Sup_lesser:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   751
  fixes z :: pinfreal assumes "z < Sup X"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   752
  shows "\<exists>x \<in> X. z < x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   753
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   754
  have "X \<noteq> {}" using assms by (auto simp: Sup_empty bot_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   755
  with assms show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   756
    by (metis Sup_pinfreal_iff mem_def not_leE)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   757
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   758
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   759
lemma Sup_eq_\<omega>: "\<omega> \<in> S \<Longrightarrow> Sup S = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   760
  unfolding Sup_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   761
  by (auto intro!: Least_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   762
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   763
lemma Sup_close:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   764
  assumes "0 < e" and S: "Sup S \<noteq> \<omega>" "S \<noteq> {}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   765
  shows "\<exists>X\<in>S. Sup S < X + e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   766
proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   767
  assume "Sup S = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   768
  moreover obtain X where "X \<in> S" using `S \<noteq> {}` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   769
  ultimately show ?thesis using `0 < e` by (auto intro!: bexI[OF _ `X\<in>S`])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   770
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   771
  assume "Sup S \<noteq> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   772
  have "\<exists>X\<in>S. Sup S - e < X"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   773
  proof (rule Sup_lesser)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   774
    show "Sup S - e < Sup S" using `0 < e` `Sup S \<noteq> 0` `Sup S \<noteq> \<omega>`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   775
      by (cases e) (auto simp: pinfreal_noteq_omega_Ex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   776
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   777
  then guess X .. note X = this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   778
  with `Sup S \<noteq> \<omega>` Sup_eq_\<omega> have "X \<noteq> \<omega>" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   779
  thus ?thesis using `Sup S \<noteq> \<omega>` X unfolding pinfreal_noteq_omega_Ex
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   780
    by (cases e) (auto intro!: bexI[OF _ `X\<in>S`] simp: split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   781
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   782
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   783
lemma Sup_\<omega>: "(SUP i::nat. Real (real i)) = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   784
proof (rule pinfreal_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   785
  fix y assume *: "\<And>i::nat. i \<in> UNIV \<Longrightarrow> Real (real i) \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   786
  thus "\<omega> \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   787
  proof (cases y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   788
    case (preal r)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   789
    then obtain k :: nat where "r < real k"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   790
      using ex_less_of_nat by (auto simp: real_eq_of_nat)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   791
    with *[of k] preal show ?thesis by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   792
  qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   793
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   794
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   795
subsubsection {* Equivalence between @{text "f ----> x"} and @{text SUP} on @{typ pinfreal} *}
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   796
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   797
lemma monoseq_monoI: "mono f \<Longrightarrow> monoseq f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   798
  unfolding mono_def monoseq_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   799
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   800
lemma incseq_mono: "mono f \<longleftrightarrow> incseq f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   801
  unfolding mono_def incseq_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   802
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   803
lemma SUP_eq_LIMSEQ:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   804
  assumes "mono f" and "\<And>n. 0 \<le> f n" and "0 \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   805
  shows "(SUP n. Real (f n)) = Real x \<longleftrightarrow> f ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   806
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   807
  assume x: "(SUP n. Real (f n)) = Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   808
  { fix n
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   809
    have "Real (f n) \<le> Real x" using x[symmetric] by (auto intro: le_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   810
    hence "f n \<le> x" using assms by simp }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   811
  show "f ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   812
  proof (rule LIMSEQ_I)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   813
    fix r :: real assume "0 < r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   814
    show "\<exists>no. \<forall>n\<ge>no. norm (f n - x) < r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   815
    proof (rule ccontr)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   816
      assume *: "\<not> ?thesis"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   817
      { fix N
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   818
        from * obtain n where "N \<le> n" "r \<le> x - f n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   819
          using `\<And>n. f n \<le> x` by (auto simp: not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   820
        hence "f N \<le> f n" using `mono f` by (auto dest: monoD)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   821
        hence "f N \<le> x - r" using `r \<le> x - f n` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   822
        hence "Real (f N) \<le> Real (x - r)" and "r \<le> x" using `0 \<le> f N` by auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   823
      hence "(SUP n. Real (f n)) \<le> Real (x - r)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   824
        and "Real (x - r) < Real x" using `0 < r` by (auto intro: SUP_leI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   825
      hence "(SUP n. Real (f n)) < Real x" by (rule le_less_trans)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   826
      thus False using x by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   827
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   828
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   829
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   830
  assume "f ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   831
  show "(SUP n. Real (f n)) = Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   832
  proof (rule pinfreal_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   833
    fix n
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   834
    from incseq_le[of f x] `mono f` `f ----> x`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   835
    show "Real (f n) \<le> Real x" using assms incseq_mono by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   836
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   837
    fix y assume *: "\<And>n. n\<in>UNIV \<Longrightarrow> Real (f n) \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   838
    show "Real x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   839
    proof (cases y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   840
      case (preal r)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   841
      with * have "\<exists>N. \<forall>n\<ge>N. f n \<le> r" using assms by fastsimp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   842
      from LIMSEQ_le_const2[OF `f ----> x` this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   843
      show "Real x \<le> y" using `0 \<le> x` preal by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   844
    qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   845
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   846
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   847
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   848
lemma SUPR_bound:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   849
  assumes "\<forall>N. f N \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   850
  shows "(SUP n. f n) \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   851
  using assms by (simp add: SUPR_def Sup_le_iff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   852
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   853
lemma pinfreal_less_eq_diff_eq_sum:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   854
  fixes x y z :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   855
  assumes "y \<le> x" and "x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   856
  shows "z \<le> x - y \<longleftrightarrow> z + y \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   857
  using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   858
  apply (cases z, cases y, cases x)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   859
  by (simp_all add: field_simps minus_pinfreal_eq)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   860
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   861
lemma Real_diff_less_omega: "Real r - x < \<omega>" by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   862
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   863
subsubsection {* Numbers on @{typ pinfreal} *}
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   864
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   865
instantiation pinfreal :: number
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   866
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   867
definition [simp]: "number_of x = Real (number_of x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   868
instance proof qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   869
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   870
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   871
subsubsection {* Division on @{typ pinfreal} *}
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   872
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   873
instantiation pinfreal :: inverse
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   874
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   875
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   876
definition "inverse x = pinfreal_case (\<lambda>x. if x = 0 then \<omega> else Real (inverse x)) 0 x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   877
definition [simp]: "x / y = x * inverse (y :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   878
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   879
instance proof qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   880
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   881
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   882
lemma pinfreal_inverse[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   883
  "inverse 0 = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   884
  "inverse (Real x) = (if x \<le> 0 then \<omega> else Real (inverse x))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   885
  "inverse \<omega> = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   886
  "inverse (1::pinfreal) = 1"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   887
  "inverse (inverse x) = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   888
  by (simp_all add: inverse_pinfreal_def one_pinfreal_def split: pinfreal_case_split del: Real_1)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   889
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   890
lemma pinfreal_inverse_le_eq:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   891
  assumes "x \<noteq> 0" "x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   892
  shows "y \<le> z / x \<longleftrightarrow> x * y \<le> (z :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   893
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   894
  from assms obtain r where r: "x = Real r" "0 < r" by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   895
  { fix p q :: real assume "0 \<le> p" "0 \<le> q"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   896
    have "p \<le> q * inverse r \<longleftrightarrow> p \<le> q / r" by (simp add: divide_inverse)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   897
    also have "... \<longleftrightarrow> p * r \<le> q" using `0 < r` by (auto simp: field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   898
    finally have "p \<le> q * inverse r \<longleftrightarrow> p * r \<le> q" . }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   899
  with r show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   900
    by (cases y, cases z, auto simp: zero_le_mult_iff field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   901
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   902
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   903
lemma inverse_antimono_strict:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   904
  fixes x y :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   905
  assumes "x < y" shows "inverse y < inverse x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   906
  using assms by (cases x, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   907
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   908
lemma inverse_antimono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   909
  fixes x y :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   910
  assumes "x \<le> y" shows "inverse y \<le> inverse x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   911
  using assms by (cases x, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   912
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   913
lemma pinfreal_inverse_\<omega>_iff[simp]: "inverse x = \<omega> \<longleftrightarrow> x = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   914
  by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   915
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   916
subsection "Infinite sum over @{typ pinfreal}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   917
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   918
text {*
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   919
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   920
The infinite sum over @{typ pinfreal} has the nice property that it is always
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   921
defined.
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   922
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   923
*}
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   924
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   925
definition psuminf :: "(nat \<Rightarrow> pinfreal) \<Rightarrow> pinfreal" (binder "\<Sum>\<^isub>\<infinity>" 10) where
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   926
  "(\<Sum>\<^isub>\<infinity> x. f x) = (SUP n. \<Sum>i<n. f i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   927
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   928
subsubsection {* Equivalence between @{text "\<Sum> n. f n"} and @{text "\<Sum>\<^isub>\<infinity> n. f n"} *}
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   929
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   930
lemma setsum_Real:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   931
  assumes "\<forall>x\<in>A. 0 \<le> f x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   932
  shows "(\<Sum>x\<in>A. Real (f x)) = Real (\<Sum>x\<in>A. f x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   933
proof (cases "finite A")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   934
  case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   935
  thus ?thesis using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   936
  proof induct case (insert x s)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   937
    hence "0 \<le> setsum f s" apply-apply(rule setsum_nonneg) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   938
    thus ?case using insert by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   939
  qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   940
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   941
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   942
lemma setsum_Real':
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   943
  assumes "\<forall>x. 0 \<le> f x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   944
  shows "(\<Sum>x\<in>A. Real (f x)) = Real (\<Sum>x\<in>A. f x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   945
  apply(rule setsum_Real) using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   946
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   947
lemma setsum_\<omega>:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   948
  "(\<Sum>x\<in>P. f x) = \<omega> \<longleftrightarrow> (finite P \<and> (\<exists>i\<in>P. f i = \<omega>))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   949
proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   950
  assume *: "setsum f P = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   951
  show "finite P"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   952
  proof (rule ccontr) assume "infinite P" with * show False by auto qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   953
  show "\<exists>i\<in>P. f i = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   954
  proof (rule ccontr)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   955
    assume "\<not> ?thesis" hence "\<And>i. i\<in>P \<Longrightarrow> f i \<noteq> \<omega>" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   956
    from `finite P` this have "setsum f P \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   957
      by induct auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   958
    with * show False by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   959
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   960
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   961
  fix i assume "finite P" "i \<in> P" "f i = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   962
  thus "setsum f P = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   963
  proof induct
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   964
    case (insert x A)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   965
    show ?case using insert by (cases "x = i") auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   966
  qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   967
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   968
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   969
lemma real_of_pinfreal_setsum:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   970
  assumes "\<And>x. x \<in> S \<Longrightarrow> f x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   971
  shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   972
proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   973
  assume "finite S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   974
  from this assms show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   975
    by induct (simp_all add: real_of_pinfreal_add setsum_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   976
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   977
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   978
lemma setsum_0:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   979
  fixes f :: "'a \<Rightarrow> pinfreal" assumes "finite A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   980
  shows "(\<Sum>x\<in>A. f x) = 0 \<longleftrightarrow> (\<forall>i\<in>A. f i = 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   981
  using assms by induct auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   982
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   983
lemma suminf_imp_psuminf:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   984
  assumes "f sums x" and "\<forall>n. 0 \<le> f n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   985
  shows "(\<Sum>\<^isub>\<infinity> x. Real (f x)) = Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   986
  unfolding psuminf_def setsum_Real'[OF assms(2)]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   987
proof (rule SUP_eq_LIMSEQ[THEN iffD2])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   988
  show "mono (\<lambda>n. setsum f {..<n})" (is "mono ?S")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   989
    unfolding mono_iff_le_Suc using assms by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   990
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   991
  { fix n show "0 \<le> ?S n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   992
      using setsum_nonneg[of "{..<n}" f] assms by auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   993
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   994
  thus "0 \<le> x" "?S ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   995
    using `f sums x` LIMSEQ_le_const
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   996
    by (auto simp: atLeast0LessThan sums_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   997
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   998
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
   999
lemma psuminf_equality:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1000
  assumes "\<And>n. setsum f {..<n} \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1001
  and "\<And>y. y \<noteq> \<omega> \<Longrightarrow> (\<And>n. setsum f {..<n} \<le> y) \<Longrightarrow> x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1002
  shows "psuminf f = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1003
  unfolding psuminf_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1004
proof (safe intro!: pinfreal_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1005
  fix n show "setsum f {..<n} \<le> x" using assms(1) .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1006
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1007
  fix y assume *: "\<forall>n. n \<in> UNIV \<longrightarrow> setsum f {..<n} \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1008
  show "x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1009
  proof (cases "y = \<omega>")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1010
    assume "y \<noteq> \<omega>" from assms(2)[OF this] *
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1011
    show "x \<le> y" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1012
  qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1013
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1014
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1015
lemma psuminf_\<omega>:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1016
  assumes "f i = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1017
  shows "(\<Sum>\<^isub>\<infinity> x. f x) = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1018
proof (rule psuminf_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1019
  fix y assume *: "\<And>n. setsum f {..<n} \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1020
  have "setsum f {..<Suc i} = \<omega>" 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1021
    using assms by (simp add: setsum_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1022
  thus "\<omega> \<le> y" using *[of "Suc i"] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1023
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1024
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1025
lemma psuminf_imp_suminf:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1026
  assumes "(\<Sum>\<^isub>\<infinity> x. f x) \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1027
  shows "(\<lambda>x. real (f x)) sums real (\<Sum>\<^isub>\<infinity> x. f x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1028
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1029
  have "\<forall>i. \<exists>r. f i = Real r \<and> 0 \<le> r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1030
  proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1031
    fix i show "\<exists>r. f i = Real r \<and> 0 \<le> r" using psuminf_\<omega> assms by (cases "f i") auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1032
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1033
  from choice[OF this] obtain r where f: "f = (\<lambda>i. Real (r i))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1034
    and pos: "\<forall>i. 0 \<le> r i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1035
    by (auto simp: expand_fun_eq)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1036
  hence [simp]: "\<And>i. real (f i) = r i" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1037
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1038
  have "mono (\<lambda>n. setsum r {..<n})" (is "mono ?S")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1039
    unfolding mono_iff_le_Suc using pos by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1040
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1041
  { fix n have "0 \<le> ?S n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1042
      using setsum_nonneg[of "{..<n}" r] pos by auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1043
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1044
  from assms obtain p where *: "(\<Sum>\<^isub>\<infinity> x. f x) = Real p" and "0 \<le> p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1045
    by (cases "(\<Sum>\<^isub>\<infinity> x. f x)") auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1046
  show ?thesis unfolding * using * pos `0 \<le> p` SUP_eq_LIMSEQ[OF `mono ?S` `\<And>n. 0 \<le> ?S n` `0 \<le> p`]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1047
    by (simp add: f atLeast0LessThan sums_def psuminf_def setsum_Real'[OF pos] f)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1048
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1049
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1050
lemma psuminf_bound:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1051
  assumes "\<forall>N. (\<Sum>n<N. f n) \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1052
  shows "(\<Sum>\<^isub>\<infinity> n. f n) \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1053
  using assms by (simp add: psuminf_def SUPR_def Sup_le_iff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1054
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1055
lemma psuminf_bound_add:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1056
  assumes "\<forall>N. (\<Sum>n<N. f n) + y \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1057
  shows "(\<Sum>\<^isub>\<infinity> n. f n) + y \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1058
proof (cases "x = \<omega>")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1059
  have "y \<le> x" using assms by (auto intro: pinfreal_le_add2)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1060
  assume "x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1061
  note move_y = pinfreal_less_eq_diff_eq_sum[OF `y \<le> x` this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1062
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1063
  have "\<forall>N. (\<Sum>n<N. f n) \<le> x - y" using assms by (simp add: move_y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1064
  hence "(\<Sum>\<^isub>\<infinity> n. f n) \<le> x - y" by (rule psuminf_bound)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1065
  thus ?thesis by (simp add: move_y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1066
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1067
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1068
lemma psuminf_finite:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1069
  assumes "\<forall>N\<ge>n. f N = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1070
  shows "(\<Sum>\<^isub>\<infinity> n. f n) = (\<Sum>N<n. f N)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1071
proof (rule psuminf_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1072
  fix N
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1073
  show "setsum f {..<N} \<le> setsum f {..<n}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1074
  proof (cases rule: linorder_cases)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1075
    assume "N < n" thus ?thesis by (auto intro!: setsum_mono3)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1076
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1077
    assume "n < N"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1078
    hence *: "{..<N} = {..<n} \<union> {n..<N}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1079
    moreover have "setsum f {n..<N} = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1080
      using assms by (auto intro!: setsum_0')
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1081
    ultimately show ?thesis unfolding *
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1082
      by (subst setsum_Un_disjoint) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1083
  qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1084
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1085
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1086
lemma psuminf_upper:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1087
  shows "(\<Sum>n<N. f n) \<le> (\<Sum>\<^isub>\<infinity> n. f n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1088
  unfolding psuminf_def SUPR_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1089
  by (auto intro: complete_lattice_class.Sup_upper image_eqI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1090
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1091
lemma psuminf_le:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1092
  assumes "\<And>N. f N \<le> g N"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1093
  shows "psuminf f \<le> psuminf g"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1094
proof (safe intro!: psuminf_bound)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1095
  fix n
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1096
  have "setsum f {..<n} \<le> setsum g {..<n}" using assms by (auto intro: setsum_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1097
  also have "... \<le> psuminf g" by (rule psuminf_upper)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1098
  finally show "setsum f {..<n} \<le> psuminf g" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1099
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1100
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1101
lemma psuminf_const[simp]: "psuminf (\<lambda>n. c) = (if c = 0 then 0 else \<omega>)" (is "_ = ?if")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1102
proof (rule psuminf_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1103
  fix y assume *: "\<And>n :: nat. (\<Sum>n<n. c) \<le> y" and "y \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1104
  then obtain r p where
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1105
    y: "y = Real r" "0 \<le> r" and
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1106
    c: "c = Real p" "0 \<le> p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1107
      using *[of 1] by (cases c, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1108
  show "(if c = 0 then 0 else \<omega>) \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1109
  proof (cases "p = 0")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1110
    assume "p = 0" with c show ?thesis by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1111
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1112
    assume "p \<noteq> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1113
    with * c y have **: "\<And>n :: nat. real n \<le> r / p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1114
      by (auto simp: zero_le_mult_iff field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1115
    from ex_less_of_nat[of "r / p"] guess n ..
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1116
    with **[of n] show ?thesis by (simp add: real_eq_of_nat)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1117
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1118
qed (cases "c = 0", simp_all)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1119
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1120
lemma psuminf_add[simp]: "psuminf (\<lambda>n. f n + g n) = psuminf f + psuminf g"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1121
proof (rule psuminf_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1122
  fix n
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1123
  from psuminf_upper[of f n] psuminf_upper[of g n]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1124
  show "(\<Sum>n<n. f n + g n) \<le> psuminf f + psuminf g"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1125
    by (auto simp add: setsum_addf intro!: add_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1126
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1127
  fix y assume *: "\<And>n. (\<Sum>n<n. f n + g n) \<le> y" and "y \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1128
  { fix n m
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1129
    have **: "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1130
    proof (cases rule: linorder_le_cases)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1131
      assume "n \<le> m"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1132
      hence "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> (\<Sum>n<m. f n) + (\<Sum>n<m. g n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1133
        by (auto intro!: add_right_mono setsum_mono3)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1134
      also have "... \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1135
        using * by (simp add: setsum_addf)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1136
      finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1137
    next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1138
      assume "m \<le> n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1139
      hence "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> (\<Sum>n<n. f n) + (\<Sum>n<n. g n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1140
        by (auto intro!: add_left_mono setsum_mono3)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1141
      also have "... \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1142
        using * by (simp add: setsum_addf)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1143
      finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1144
    qed }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1145
  hence "\<And>m. \<forall>n. (\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> y" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1146
  from psuminf_bound_add[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1147
  have "\<forall>m. (\<Sum>n<m. g n) + psuminf f \<le> y" by (simp add: ac_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1148
  from psuminf_bound_add[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1149
  show "psuminf f + psuminf g \<le> y" by (simp add: ac_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1150
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1151
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1152
lemma psuminf_0: "psuminf f = 0 \<longleftrightarrow> (\<forall>i. f i = 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1153
proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1154
  assume "\<forall>i. f i = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1155
  hence "f = (\<lambda>i. 0)" by (simp add: expand_fun_eq)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1156
  thus "psuminf f = 0" using psuminf_const by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1157
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1158
  fix i assume "psuminf f = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1159
  hence "(\<Sum>n<Suc i. f n) = 0" using psuminf_upper[of f "Suc i"] by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1160
  thus "f i = 0" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1161
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1162
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1163
lemma psuminf_cmult_right[simp]: "psuminf (\<lambda>n. c * f n) = c * psuminf f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1164
proof (rule psuminf_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1165
  fix n show "(\<Sum>n<n. c * f n) \<le> c * psuminf f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1166
   by (auto simp: setsum_right_distrib[symmetric] intro: mult_left_mono psuminf_upper)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1167
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1168
  fix y
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1169
  assume "\<And>n. (\<Sum>n<n. c * f n) \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1170
  hence *: "\<And>n. c * (\<Sum>n<n. f n) \<le> y" by (auto simp add: setsum_right_distrib)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1171
  thus "c * psuminf f \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1172
  proof (cases "c = \<omega> \<or> c = 0")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1173
    assume "c = \<omega> \<or> c = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1174
    thus ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1175
      using * by (fastsimp simp add: psuminf_0 setsum_0 split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1176
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1177
    assume "\<not> (c = \<omega> \<or> c = 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1178
    hence "c \<noteq> 0" "c \<noteq> \<omega>" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1179
    note rewrite_div = pinfreal_inverse_le_eq[OF this, of _ y]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1180
    hence "\<forall>n. (\<Sum>n<n. f n) \<le> y / c" using * by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1181
    hence "psuminf f \<le> y / c" by (rule psuminf_bound)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1182
    thus ?thesis using rewrite_div by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1183
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1184
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1185
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1186
lemma psuminf_cmult_left[simp]: "psuminf (\<lambda>n. f n * c) = psuminf f * c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1187
  using psuminf_cmult_right[of c f] by (simp add: ac_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1188
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1189
lemma psuminf_half_series: "psuminf (\<lambda>n. (1/2)^Suc n) = 1"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1190
  using suminf_imp_psuminf[OF power_half_series] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1191
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1192
lemma setsum_pinfsum: "(\<Sum>\<^isub>\<infinity> n. \<Sum>m\<in>A. f n m) = (\<Sum>m\<in>A. (\<Sum>\<^isub>\<infinity> n. f n m))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1193
proof (cases "finite A")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1194
  assume "finite A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1195
  thus ?thesis by induct simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1196
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1197
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1198
lemma psuminf_reindex:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1199
  fixes f:: "nat \<Rightarrow> nat" assumes "bij f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1200
  shows "psuminf (g \<circ> f) = psuminf g"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1201
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1202
  have [intro, simp]: "\<And>A. inj_on f A" using `bij f` unfolding bij_def by (auto intro: subset_inj_on)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1203
  have f[intro, simp]: "\<And>x. f (inv f x) = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1204
    using `bij f` unfolding bij_def by (auto intro: surj_f_inv_f)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1205
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1206
  show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1207
  proof (rule psuminf_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1208
    fix n
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1209
    have "setsum (g \<circ> f) {..<n} = setsum g (f ` {..<n})"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1210
      by (simp add: setsum_reindex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1211
    also have "\<dots> \<le> setsum g {..Max (f ` {..<n})}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1212
      by (rule setsum_mono3) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1213
    also have "\<dots> \<le> psuminf g" unfolding lessThan_Suc_atMost[symmetric] by (rule psuminf_upper)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1214
    finally show "setsum (g \<circ> f) {..<n} \<le> psuminf g" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1215
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1216
    fix y assume *: "\<And>n. setsum (g \<circ> f) {..<n} \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1217
    show "psuminf g \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1218
    proof (safe intro!: psuminf_bound)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1219
      fix N
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1220
      have "setsum g {..<N} \<le> setsum g (f ` {..Max (inv f ` {..<N})})"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1221
        by (rule setsum_mono3) (auto intro!: image_eqI[where f="f", OF f[symmetric]])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1222
      also have "\<dots> = setsum (g \<circ> f) {..Max (inv f ` {..<N})}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1223
        by (simp add: setsum_reindex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1224
      also have "\<dots> \<le> y" unfolding lessThan_Suc_atMost[symmetric] by (rule *)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1225
      finally show "setsum g {..<N} \<le> y" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1226
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1227
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1228
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1229
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1230
lemma psuminf_2dimen:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1231
  fixes f:: "nat * nat \<Rightarrow> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1232
  assumes fsums: "\<And>m. g m = (\<Sum>\<^isub>\<infinity> n. f (m,n))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1233
  shows "psuminf (f \<circ> prod_decode) = psuminf g"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1234
proof (rule psuminf_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1235
  fix n :: nat
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1236
  let ?P = "prod_decode ` {..<n}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1237
  have "setsum (f \<circ> prod_decode) {..<n} = setsum f ?P"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1238
    by (auto simp: setsum_reindex inj_prod_decode)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1239
  also have "\<dots> \<le> setsum f ({..Max (fst ` ?P)} \<times> {..Max (snd ` ?P)})"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1240
  proof (safe intro!: setsum_mono3 Max_ge image_eqI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1241
    fix a b x assume "(a, b) = prod_decode x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1242
    from this[symmetric] show "a = fst (prod_decode x)" "b = snd (prod_decode x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1243
      by simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1244
  qed simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1245
  also have "\<dots> = (\<Sum>m\<le>Max (fst ` ?P). (\<Sum>n\<le>Max (snd ` ?P). f (m,n)))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1246
    unfolding setsum_cartesian_product by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1247
  also have "\<dots> \<le> (\<Sum>m\<le>Max (fst ` ?P). g m)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1248
    by (auto intro!: setsum_mono psuminf_upper simp del: setsum_lessThan_Suc
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1249
        simp: fsums lessThan_Suc_atMost[symmetric])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1250
  also have "\<dots> \<le> psuminf g"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1251
    by (auto intro!: psuminf_upper simp del: setsum_lessThan_Suc
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1252
        simp: lessThan_Suc_atMost[symmetric])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1253
  finally show "setsum (f \<circ> prod_decode) {..<n} \<le> psuminf g" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1254
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1255
  fix y assume *: "\<And>n. setsum (f \<circ> prod_decode) {..<n} \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1256
  have g: "g = (\<lambda>m. \<Sum>\<^isub>\<infinity> n. f (m,n))" unfolding fsums[symmetric] ..
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1257
  show "psuminf g \<le> y" unfolding g
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1258
  proof (rule psuminf_bound, unfold setsum_pinfsum[symmetric], safe intro!: psuminf_bound)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1259
    fix N M :: nat
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1260
    let ?P = "{..<N} \<times> {..<M}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1261
    let ?M = "Max (prod_encode ` ?P)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1262
    have "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> (\<Sum>(m, n)\<in>?P. f (m, n))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1263
      unfolding setsum_commute[of _ _ "{..<M}"] unfolding setsum_cartesian_product ..
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1264
    also have "\<dots> \<le> (\<Sum>(m,n)\<in>(prod_decode ` {..?M}). f (m, n))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1265
      by (auto intro!: setsum_mono3 image_eqI[where f=prod_decode, OF prod_encode_inverse[symmetric]])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1266
    also have "\<dots> \<le> y" using *[of "Suc ?M"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1267
      by (simp add: lessThan_Suc_atMost[symmetric] setsum_reindex
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1268
               inj_prod_decode del: setsum_lessThan_Suc)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1269
    finally show "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> y" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1270
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1271
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1272
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1273
lemma pinfreal_mult_less_right:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1274
  assumes "b * a < c * a" "0 < a" "a < \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1275
  shows "b < c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1276
  using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1277
  by (cases a, cases b, cases c) (auto split: split_if_asm simp: zero_less_mult_iff zero_le_mult_iff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1278
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1279
lemma pinfreal_\<omega>_eq_plus[simp]: "\<omega> = a + b \<longleftrightarrow> (a = \<omega> \<or> b = \<omega>)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1280
  by (cases a, cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1281
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1282
lemma pinfreal_of_nat_le_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1283
  "(of_nat k :: pinfreal) \<le> of_nat m \<longleftrightarrow> k \<le> m" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1284
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1285
lemma pinfreal_of_nat_less_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1286
  "(of_nat k :: pinfreal) < of_nat m \<longleftrightarrow> k < m" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1287
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1288
lemma pinfreal_bound_add:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1289
  assumes "\<forall>N. f N + y \<le> (x::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1290
  shows "(SUP n. f n) + y \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1291
proof (cases "x = \<omega>")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1292
  have "y \<le> x" using assms by (auto intro: pinfreal_le_add2)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1293
  assume "x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1294
  note move_y = pinfreal_less_eq_diff_eq_sum[OF `y \<le> x` this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1295
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1296
  have "\<forall>N. f N \<le> x - y" using assms by (simp add: move_y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1297
  hence "(SUP n. f n) \<le> x - y" by (rule SUPR_bound)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1298
  thus ?thesis by (simp add: move_y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1299
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1300
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1301
lemma SUPR_pinfreal_add:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1302
  fixes f g :: "nat \<Rightarrow> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1303
  assumes f: "\<forall>n. f n \<le> f (Suc n)" and g: "\<forall>n. g n \<le> g (Suc n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1304
  shows "(SUP n. f n + g n) = (SUP n. f n) + (SUP n. g n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1305
proof (rule pinfreal_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1306
  fix n :: nat from le_SUPI[of n UNIV f] le_SUPI[of n UNIV g]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1307
  show "f n + g n \<le> (SUP n. f n) + (SUP n. g n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1308
    by (auto intro!: add_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1309
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1310
  fix y assume *: "\<And>n. n \<in> UNIV \<Longrightarrow> f n + g n \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1311
  { fix n m
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1312
    have "f n + g m \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1313
    proof (cases rule: linorder_le_cases)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1314
      assume "n \<le> m"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1315
      hence "f n + g m \<le> f m + g m"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1316
        using f lift_Suc_mono_le by (auto intro!: add_right_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1317
      also have "\<dots> \<le> y" using * by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1318
      finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1319
    next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1320
      assume "m \<le> n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1321
      hence "f n + g m \<le> f n + g n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1322
        using g lift_Suc_mono_le by (auto intro!: add_left_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1323
      also have "\<dots> \<le> y" using * by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1324
      finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1325
    qed }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1326
  hence "\<And>m. \<forall>n. f n + g m \<le> y" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1327
  from pinfreal_bound_add[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1328
  have "\<forall>m. (g m) + (SUP n. f n) \<le> y" by (simp add: ac_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1329
  from pinfreal_bound_add[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1330
  show "SUPR UNIV f + SUPR UNIV g \<le> y" by (simp add: ac_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1331
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1332
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1333
lemma SUPR_pinfreal_setsum:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1334
  fixes f :: "'x \<Rightarrow> nat \<Rightarrow> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1335
  assumes "\<And>i. i \<in> P \<Longrightarrow> \<forall>n. f i n \<le> f i (Suc n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1336
  shows "(SUP n. \<Sum>i\<in>P. f i n) = (\<Sum>i\<in>P. SUP n. f i n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1337
proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1338
  assume "finite P" from this assms show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1339
  proof induct
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1340
    case (insert i P)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1341
    thus ?case
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1342
      apply simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1343
      apply (subst SUPR_pinfreal_add)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1344
      by (auto intro!: setsum_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1345
  qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1346
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1347
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1348
lemma Real_max:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1349
  assumes "x \<ge> 0" "y \<ge> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1350
  shows "Real (max x y) = max (Real x) (Real y)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1351
  using assms unfolding max_def by (auto simp add:not_le)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1352
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1353
lemma Real_real: "Real (real x) = (if x = \<omega> then 0 else x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1354
  using assms by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1355
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1356
lemma inj_on_real: "inj_on real (UNIV - {\<omega>})"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1357
proof (rule inj_onI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1358
  fix x y assume mem: "x \<in> UNIV - {\<omega>}" "y \<in> UNIV - {\<omega>}" and "real x = real y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1359
  thus "x = y" by (cases x, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1360
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1361
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1362
lemma inj_on_Real: "inj_on Real {0..}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1363
  by (auto intro!: inj_onI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1364
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1365
lemma range_Real[simp]: "range Real = UNIV - {\<omega>}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1366
proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1367
  fix x assume "x \<notin> range Real"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1368
  thus "x = \<omega>" by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1369
qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1370
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1371
lemma image_Real[simp]: "Real ` {0..} = UNIV - {\<omega>}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1372
proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1373
  fix x assume "x \<notin> Real ` {0..}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1374
  thus "x = \<omega>" by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1375
qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1376
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1377
lemma pinfreal_SUP_cmult:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1378
  fixes f :: "'a \<Rightarrow> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1379
  shows "(SUP i : R. z * f i) = z * (SUP i : R. f i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1380
proof (rule pinfreal_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1381
  fix i assume "i \<in> R"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1382
  from le_SUPI[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1383
  show "z * f i \<le> z * (SUP i:R. f i)" by (rule pinfreal_mult_cancel)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1384
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1385
  fix y assume "\<And>i. i\<in>R \<Longrightarrow> z * f i \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1386
  hence *: "\<And>i. i\<in>R \<Longrightarrow> z * f i \<le> y" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1387
  show "z * (SUP i:R. f i) \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1388
  proof (cases "\<forall>i\<in>R. f i = 0")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1389
    case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1390
    show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1391
    proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1392
      assume "R \<noteq> {}" hence "f ` R = {0}" using True by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1393
      thus ?thesis by (simp add: SUPR_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1394
    qed (simp add: SUPR_def Sup_empty bot_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1395
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1396
    case False then obtain i where i: "i \<in> R" and f0: "f i \<noteq> 0" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1397
    show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1398
    proof (cases "z = 0 \<or> z = \<omega>")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1399
      case True with f0 *[OF i] show ?thesis by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1400
    next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1401
      case False hence z: "z \<noteq> 0" "z \<noteq> \<omega>" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1402
      note div = pinfreal_inverse_le_eq[OF this, symmetric]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1403
      hence "\<And>i. i\<in>R \<Longrightarrow> f i \<le> y / z" using * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1404
      thus ?thesis unfolding div SUP_le_iff by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1405
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1406
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1407
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1408
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1409
instantiation pinfreal :: topological_space
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1410
begin
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1411
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1412
definition "open A \<longleftrightarrow>
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1413
  (\<exists>T. open T \<and> (Real ` (T\<inter>{0..}) = A - {\<omega>})) \<and> (\<omega> \<in> A \<longrightarrow> (\<exists>x\<ge>0. {Real x <..} \<subseteq> A))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1414
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1415
lemma open_omega: "open A \<Longrightarrow> \<omega> \<in> A \<Longrightarrow> (\<exists>x\<ge>0. {Real x<..} \<subseteq> A)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1416
  unfolding open_pinfreal_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1417
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1418
lemma open_omegaD: assumes "open A" "\<omega> \<in> A" obtains x where "x\<ge>0" "{Real x<..} \<subseteq> A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1419
  using open_omega[OF assms] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1420
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1421
lemma pinfreal_openE: assumes "open A" obtains A' x where
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1422
  "open A'" "Real ` (A' \<inter> {0..}) = A - {\<omega>}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1423
  "x \<ge> 0" "\<omega> \<in> A \<Longrightarrow> {Real x<..} \<subseteq> A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1424
  using assms open_pinfreal_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1425
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1426
instance
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1427
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1428
  let ?U = "UNIV::pinfreal set"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1429
  show "open ?U" unfolding open_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1430
    by (auto intro!: exI[of _ "UNIV"] exI[of _ 0])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1431
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1432
  fix S T::"pinfreal set" assume "open S" and "open T"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1433
  from `open S`[THEN pinfreal_openE] guess S' xS . note S' = this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1434
  from `open T`[THEN pinfreal_openE] guess T' xT . note T' = this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1435
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1436
  from S'(1-3) T'(1-3)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1437
  show "open (S \<inter> T)" unfolding open_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1438
  proof (safe intro!: exI[of _ "S' \<inter> T'"] exI[of _ "max xS xT"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1439
    fix x assume *: "Real (max xS xT) < x" and "\<omega> \<in> S" "\<omega> \<in> T"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1440
    from `\<omega> \<in> S`[THEN S'(4)] * show "x \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1441
      by (cases x, auto simp: max_def split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1442
    from `\<omega> \<in> T`[THEN T'(4)] * show "x \<in> T"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1443
      by (cases x, auto simp: max_def split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1444
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1445
    fix x assume x: "x \<notin> Real ` (S' \<inter> T' \<inter> {0..})"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1446
    have *: "S' \<inter> T' \<inter> {0..} = (S' \<inter> {0..}) \<inter> (T' \<inter> {0..})" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1447
    assume "x \<in> T" "x \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1448
    with S'(2) T'(2) show "x = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1449
      using x[unfolded *] inj_on_image_Int[OF inj_on_Real] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1450
  qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1451
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1452
  fix K assume openK: "\<forall>S \<in> K. open (S:: pinfreal set)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1453
  hence "\<forall>S\<in>K. \<exists>T. open T \<and> Real ` (T \<inter> {0..}) = S - {\<omega>}" by (auto simp: open_pinfreal_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1454
  from bchoice[OF this] guess T .. note T = this[rule_format]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1455
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1456
  show "open (\<Union>K)" unfolding open_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1457
  proof (safe intro!: exI[of _ "\<Union>(T ` K)"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1458
    fix x S assume "0 \<le> x" "x \<in> T S" "S \<in> K"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1459
    with T[OF `S \<in> K`] show "Real x \<in> \<Union>K" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1460
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1461
    fix x S assume x: "x \<notin> Real ` (\<Union>T ` K \<inter> {0..})" "S \<in> K" "x \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1462
    hence "x \<notin> Real ` (T S \<inter> {0..})"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1463
      by (auto simp: image_UN UN_simps[symmetric] simp del: UN_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1464
    thus "x = \<omega>" using T[OF `S \<in> K`] `x \<in> S` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1465
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1466
    fix S assume "\<omega> \<in> S" "S \<in> K"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1467
    from openK[rule_format, OF `S \<in> K`, THEN pinfreal_openE] guess S' x .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1468
    from this(3, 4) `\<omega> \<in> S`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1469
    show "\<exists>x\<ge>0. {Real x<..} \<subseteq> \<Union>K"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1470
      by (auto intro!: exI[of _ x] bexI[OF _ `S \<in> K`])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1471
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1472
    from T[THEN conjunct1] show "open (\<Union>T`K)" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1473
  qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1474
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1475
end
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1476
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1477
lemma open_pinfreal_lessThan[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1478
  "open {..< a :: pinfreal}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1479
proof (cases a)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1480
  case (preal x) thus ?thesis unfolding open_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1481
  proof (safe intro!: exI[of _ "{..< x}"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1482
    fix y assume "y < Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1483
    moreover assume "y \<notin> Real ` ({..<x} \<inter> {0..})"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1484
    ultimately have "y \<noteq> Real (real y)" using preal by (cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1485
    thus "y = \<omega>" by (auto simp: Real_real split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1486
  qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1487
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1488
  case infinite thus ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1489
    unfolding open_pinfreal_def by (auto intro!: exI[of _ UNIV])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1490
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1491
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1492
lemma open_pinfreal_greaterThan[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1493
  "open {a :: pinfreal <..}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1494
proof (cases a)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1495
  case (preal x) thus ?thesis unfolding open_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1496
  proof (safe intro!: exI[of _ "{x <..}"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1497
    fix y assume "Real x < y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1498
    moreover assume "y \<notin> Real ` ({x<..} \<inter> {0..})"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1499
    ultimately have "y \<noteq> Real (real y)" using preal by (cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1500
    thus "y = \<omega>" by (auto simp: Real_real split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1501
  qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1502
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1503
  case infinite thus ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1504
    unfolding open_pinfreal_def by (auto intro!: exI[of _ "{}"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1505
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1506
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1507
lemma pinfreal_open_greaterThanLessThan[simp]: "open {a::pinfreal <..< b}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1508
  unfolding greaterThanLessThan_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1509
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1510
lemma closed_pinfreal_atLeast[simp, intro]: "closed {a :: pinfreal ..}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1511
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1512
  have "- {a ..} = {..< a}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1513
  then show "closed {a ..}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1514
    unfolding closed_def using open_pinfreal_lessThan by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1515
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1516
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1517
lemma closed_pinfreal_atMost[simp, intro]: "closed {.. b :: pinfreal}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1518
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1519
  have "- {.. b} = {b <..}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1520
  then show "closed {.. b}" 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1521
    unfolding closed_def using open_pinfreal_greaterThan by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1522
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1523
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1524
lemma closed_pinfreal_atLeastAtMost[simp, intro]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1525
  shows "closed {a :: pinfreal .. b}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1526
  unfolding atLeastAtMost_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1527
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1528
lemma pinfreal_dense:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1529
  fixes x y :: pinfreal assumes "x < y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1530
  shows "\<exists>z. x < z \<and> z < y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1531
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1532
  from `x < y` obtain p where p: "x = Real p" "0 \<le> p" by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1533
  show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1534
  proof (cases y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1535
    case (preal r) with p `x < y` have "p < r" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1536
    with dense obtain z where "p < z" "z < r" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1537
    thus ?thesis using preal p by (auto intro!: exI[of _ "Real z"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1538
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1539
    case infinite thus ?thesis using `x < y` p
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1540
      by (auto intro!: exI[of _ "Real p + 1"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1541
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1542
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1543
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1544
instance pinfreal :: t2_space
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1545
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1546
  fix x y :: pinfreal assume "x \<noteq> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1547
  let "?P x (y::pinfreal)" = "\<exists> U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1548
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1549
  { fix x y :: pinfreal assume "x < y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1550
    from pinfreal_dense[OF this] obtain z where z: "x < z" "z < y" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1551
    have "?P x y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1552
      apply (rule exI[of _ "{..<z}"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1553
      apply (rule exI[of _ "{z<..}"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1554
      using z by auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1555
  note * = this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1556
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1557
  from `x \<noteq> y`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1558
  show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1559
  proof (cases rule: linorder_cases)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1560
    assume "x = y" with `x \<noteq> y` show ?thesis by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1561
  next assume "x < y" from *[OF this] show ?thesis by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1562
  next assume "y < x" from *[OF this] show ?thesis by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1563
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1564
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1565
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1566
definition (in complete_lattice) isoton :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<up>" 50) where
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1567
  "A \<up> X \<longleftrightarrow> (\<forall>i. A i \<le> A (Suc i)) \<and> (SUP i. A i) = X"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1568
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1569
definition (in complete_lattice) antiton (infix "\<down>" 50) where
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1570
  "A \<down> X \<longleftrightarrow> (\<forall>i. A i \<ge> A (Suc i)) \<and> (INF i. A i) = X"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1571
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1572
lemma range_const[simp]: "range (\<lambda>x. c) = {c}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1573
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1574
lemma isoton_cmult_right:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1575
  assumes "f \<up> (x::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1576
  shows "(\<lambda>i. c * f i) \<up> (c * x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1577
  using assms unfolding isoton_def pinfreal_SUP_cmult
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1578
  by (auto intro: pinfreal_mult_cancel)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1579
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1580
lemma isoton_cmult_left:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1581
  "f \<up> (x::pinfreal) \<Longrightarrow> (\<lambda>i. f i * c) \<up> (x * c)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1582
  by (subst (1 2) mult_commute) (rule isoton_cmult_right)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1583
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1584
lemma isoton_add:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1585
  assumes "f \<up> (x::pinfreal)" and "g \<up> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1586
  shows "(\<lambda>i. f i + g i) \<up> (x + y)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1587
  using assms unfolding isoton_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1588
  by (auto intro: pinfreal_mult_cancel add_mono simp: SUPR_pinfreal_add)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1589
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1590
lemma isoton_fun_expand:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1591
  "f \<up> x \<longleftrightarrow> (\<forall>i. (\<lambda>j. f j i) \<up> (x i))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1592
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1593
  have "\<And>i. {y. \<exists>f'\<in>range f. y = f' i} = range (\<lambda>j. f j i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1594
    by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1595
  with assms show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1596
    by (auto simp add: isoton_def le_fun_def Sup_fun_def SUPR_def)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1597
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1598
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1599
lemma isoton_indicator:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1600
  assumes "f \<up> g"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1601
  shows "(\<lambda>i x. f i x * indicator A x) \<up> (\<lambda>x. g x * indicator A x :: pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1602
  using assms unfolding isoton_fun_expand by (auto intro!: isoton_cmult_left)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1603
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1604
lemma pinfreal_ord_one[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1605
  "Real p < 1 \<longleftrightarrow> p < 1"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1606
  "Real p \<le> 1 \<longleftrightarrow> p \<le> 1"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1607
  "1 < Real p \<longleftrightarrow> 1 < p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1608
  "1 \<le> Real p \<longleftrightarrow> 1 \<le> p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1609
  by (simp_all add: one_pinfreal_def del: Real_1)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1610
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1611
lemma isoton_Sup:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1612
  assumes "f \<up> u"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1613
  shows "f i \<le> u"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1614
  using le_SUPI[of i UNIV f] assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1615
  unfolding isoton_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1616
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1617
lemma isoton_mono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1618
  assumes iso: "x \<up> a" "y \<up> b" and *: "\<And>n. x n \<le> y (N n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1619
  shows "a \<le> b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1620
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1621
  from iso have "a = (SUP n. x n)" "b = (SUP n. y n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1622
    unfolding isoton_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1623
  with * show ?thesis by (auto intro!: SUP_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1624
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1625
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1626
lemma pinfreal_le_mult_one_interval:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1627
  fixes x y :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1628
  assumes "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1629
  shows "x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1630
proof (cases x, cases y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1631
  assume "x = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1632
  with assms[of "1 / 2"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1633
  show "x \<le> y" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1634
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1635
  fix r p assume *: "y = Real p" "x = Real r" and **: "0 \<le> r" "0 \<le> p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1636
  have "r \<le> p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1637
  proof (rule field_le_mult_one_interval)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1638
    fix z :: real assume "0 < z" and "z < 1"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1639
    with assms[of "Real z"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1640
    show "z * r \<le> p" using ** * by (auto simp: zero_le_mult_iff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1641
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1642
  thus "x \<le> y" using ** * by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1643
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1644
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1645
lemma pinfreal_greater_0[intro]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1646
  fixes a :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1647
  assumes "a \<noteq> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1648
  shows "a > 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1649
using assms apply (cases a) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1650
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1651
lemma pinfreal_mult_strict_right_mono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1652
  assumes "a < b" and "0 < c" "c < \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1653
  shows "a * c < b * c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1654
  using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1655
  by (cases a, cases b, cases c)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1656
     (auto simp: zero_le_mult_iff pinfreal_less_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1657
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1658
lemma minus_pinfreal_eq2:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1659
  fixes x y z :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1660
  assumes "y \<le> x" and "y \<noteq> \<omega>" shows "z = x - y \<longleftrightarrow> z + y = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1661
  using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1662
  apply (subst eq_commute)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1663
  apply (subst minus_pinfreal_eq)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1664
  by (cases x, cases z, auto simp add: ac_simps not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1665
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1666
lemma pinfreal_diff_eq_diff_imp_eq:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1667
  assumes "a \<noteq> \<omega>" "b \<le> a" "c \<le> a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1668
  assumes "a - b = a - c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1669
  shows "b = c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1670
  using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1671
  by (cases a, cases b, cases c) (auto split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1672
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1673
lemma pinfreal_inverse_eq_0: "inverse x = 0 \<longleftrightarrow> x = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1674
  by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1675
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1676
lemma pinfreal_mult_inverse:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1677
  "\<lbrakk> x \<noteq> \<omega> ; x \<noteq> 0 \<rbrakk> \<Longrightarrow> x * inverse x = 1"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1678
  by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1679
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1680
lemma pinfreal_zero_less_diff_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1681
  fixes a b :: pinfreal shows "0 < a - b \<longleftrightarrow> b < a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1682
  apply (cases a, cases b)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1683
  apply (auto simp: pinfreal_noteq_omega_Ex pinfreal_less_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1684
  apply (cases b)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1685
  by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1686
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1687
lemma pinfreal_less_Real_Ex:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1688
  fixes a b :: pinfreal shows "x < Real r \<longleftrightarrow> (\<exists>p\<ge>0. p < r \<and> x = Real p)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1689
  by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1690
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1691
lemma open_Real: assumes "open S" shows "open (Real ` ({0..} \<inter> S))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1692
  unfolding open_pinfreal_def apply(rule,rule,rule,rule assms) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1693
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1694
lemma pinfreal_zero_le_diff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1695
  fixes a b :: pinfreal shows "a - b = 0 \<longleftrightarrow> a \<le> b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1696
  by (cases a, cases b, simp_all, cases b, auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1697
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1698
lemma lim_Real[simp]: assumes "\<forall>n. f n \<ge> 0" "m\<ge>0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1699
  shows "(\<lambda>n. Real (f n)) ----> Real m \<longleftrightarrow> (\<lambda>n. f n) ----> m" (is "?l = ?r")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1700
proof assume ?l show ?r unfolding Lim_sequentially
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1701
  proof safe fix e::real assume e:"e>0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1702
    note open_ball[of m e] note open_Real[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1703
    note * = `?l`[unfolded tendsto_def,rule_format,OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1704
    have "eventually (\<lambda>x. Real (f x) \<in> Real ` ({0..} \<inter> ball m e)) sequentially"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1705
      apply(rule *) unfolding image_iff using assms(2) e by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1706
    thus "\<exists>N. \<forall>n\<ge>N. dist (f n) m < e" unfolding eventually_sequentially 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1707
      apply safe apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1708
    proof- fix n x assume "Real (f n) = Real x" "0 \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1709
      hence *:"f n = x" using assms(1) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1710
      assume "x \<in> ball m e" thus "dist (f n) m < e" unfolding *
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1711
        by (auto simp add:dist_commute)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1712
    qed qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1713
next assume ?r show ?l unfolding tendsto_def eventually_sequentially 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1714
  proof safe fix S assume S:"open S" "Real m \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1715
    guess T y using S(1) apply-apply(erule pinfreal_openE) . note T=this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1716
    have "m\<in>real ` (S - {\<omega>})" unfolding image_iff 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1717
      apply(rule_tac x="Real m" in bexI) using assms(2) S(2) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1718
    hence "m \<in> T" unfolding T(2)[THEN sym] by auto 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1719
    from `?r`[unfolded tendsto_def eventually_sequentially,rule_format,OF T(1) this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1720
    guess N .. note N=this[rule_format]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1721
    show "\<exists>N. \<forall>n\<ge>N. Real (f n) \<in> S" apply(rule_tac x=N in exI) 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1722
    proof safe fix n assume n:"N\<le>n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1723
      have "f n \<in> real ` (S - {\<omega>})" using N[OF n] assms unfolding T(2)[THEN sym] 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1724
        unfolding image_iff apply-apply(rule_tac x="Real (f n)" in bexI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1725
        unfolding real_Real by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1726
      then guess x unfolding image_iff .. note x=this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1727
      show "Real (f n) \<in> S" unfolding x apply(subst Real_real) using x by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1728
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1729
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1730
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1731
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1732
lemma pinfreal_INFI:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1733
  fixes x :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1734
  assumes "\<And>i. i \<in> A \<Longrightarrow> x \<le> f i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1735
  assumes "\<And>y. (\<And>i. i \<in> A \<Longrightarrow> y \<le> f i) \<Longrightarrow> y \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1736
  shows "(INF i:A. f i) = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1737
  unfolding INFI_def Inf_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1738
  using assms by (auto intro!: Greatest_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1739
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1740
lemma real_of_pinfreal_less:"x < y \<Longrightarrow> y\<noteq>\<omega> \<Longrightarrow> real x < real y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1741
proof- case goal1
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1742
  have *:"y = Real (real y)" "x = Real (real x)" using goal1 Real_real by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1743
  show ?case using goal1 apply- apply(subst(asm) *(1))apply(subst(asm) *(2))
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1744
    unfolding pinfreal_less by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1745
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1746
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1747
lemma not_less_omega[simp]:"\<not> x < \<omega> \<longleftrightarrow> x = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1748
  by (metis antisym_conv3 pinfreal_less(3)) 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1749
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1750
lemma Real_real': assumes "x\<noteq>\<omega>" shows "Real (real x) = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1751
proof- have *:"(THE r. 0 \<le> r \<and> x = Real r) = real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1752
    apply(rule the_equality) using assms unfolding Real_real by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1753
  have "Real (THE r. 0 \<le> r \<and> x = Real r) = x" unfolding *
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1754
    using assms unfolding Real_real by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1755
  thus ?thesis unfolding real_of_pinfreal_def of_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1756
    unfolding pinfreal_case_def using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1757
qed 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1758
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1759
lemma Real_less_plus_one:"Real x < Real (max (x + 1) 1)" 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1760
  unfolding pinfreal_less by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1761
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1762
lemma Lim_omega: "f ----> \<omega> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. f n \<ge> Real B)" (is "?l = ?r")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1763
proof assume ?r show ?l apply(rule topological_tendstoI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1764
    unfolding eventually_sequentially
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1765
  proof- fix S assume "open S" "\<omega> \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1766
    from open_omega[OF this] guess B .. note B=this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1767
    from `?r`[rule_format,of "(max B 0)+1"] guess N .. note N=this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1768
    show "\<exists>N. \<forall>n\<ge>N. f n \<in> S" apply(rule_tac x=N in exI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1769
    proof safe case goal1 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1770
      have "Real B < Real ((max B 0) + 1)" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1771
      also have "... \<le> f n" using goal1 N by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1772
      finally show ?case using B by fastsimp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1773
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1774
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1775
next assume ?l show ?r
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1776
  proof fix B::real have "open {Real B<..}" "\<omega> \<in> {Real B<..}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1777
    from topological_tendstoD[OF `?l` this,unfolded eventually_sequentially]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1778
    guess N .. note N=this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1779
    show "\<exists>N. \<forall>n\<ge>N. Real B \<le> f n" apply(rule_tac x=N in exI) using N by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1780
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1781
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1782
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1783
lemma Lim_bounded_omgea: assumes lim:"f ----> l" and "\<And>n. f n \<le> Real B" shows "l \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1784
proof(rule ccontr,unfold not_not) let ?B = "max (B + 1) 1" assume as:"l=\<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1785
  from lim[unfolded this Lim_omega,rule_format,of "?B"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1786
  guess N .. note N=this[rule_format,OF le_refl]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1787
  hence "Real ?B \<le> Real B" using assms(2)[of N] by(rule order_trans) 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1788
  hence "Real ?B < Real ?B" using Real_less_plus_one[of B] by(rule le_less_trans)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1789
  thus False by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1790
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1791
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1792
lemma incseq_le_pinfreal: assumes inc: "\<And>n m. n\<ge>m \<Longrightarrow> X n \<ge> X m"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1793
  and lim: "X ----> (L::pinfreal)" shows "X n \<le> L"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1794
proof(cases "L = \<omega>")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1795
  case False have "\<forall>n. X n \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1796
  proof(rule ccontr,unfold not_all not_not,safe)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1797
    case goal1 hence "\<forall>n\<ge>x. X n = \<omega>" using inc[of x] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1798
    hence "X ----> \<omega>" unfolding tendsto_def eventually_sequentially
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1799
      apply safe apply(rule_tac x=x in exI) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1800
    note Lim_unique[OF trivial_limit_sequentially this lim]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1801
    with False show False by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1802
  qed note * =this[rule_format]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1803
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1804
  have **:"\<forall>m n. m \<le> n \<longrightarrow> Real (real (X m)) \<le> Real (real (X n))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1805
    unfolding Real_real using * inc by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1806
  have "real (X n) \<le> real L" apply-apply(rule incseq_le) defer
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1807
    apply(subst lim_Real[THEN sym]) apply(rule,rule,rule)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1808
    unfolding Real_real'[OF *] Real_real'[OF False] 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1809
    unfolding incseq_def using ** lim by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1810
  hence "Real (real (X n)) \<le> Real (real L)" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1811
  thus ?thesis unfolding Real_real using * False by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1812
qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1813
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1814
lemma SUP_Lim_pinfreal: assumes "\<And>n m. n\<ge>m \<Longrightarrow> f n \<ge> f m" "f ----> l"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1815
  shows "(SUP n. f n) = (l::pinfreal)" unfolding SUPR_def Sup_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1816
proof (safe intro!: Least_equality)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1817
  fix n::nat show "f n \<le> l" apply(rule incseq_le_pinfreal)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1818
    using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1819
next fix y assume y:"\<forall>x\<in>range f. x \<le> y" show "l \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1820
  proof(rule ccontr,cases "y=\<omega>",unfold not_le)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1821
    case False assume as:"y < l"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1822
    have l:"l \<noteq> \<omega>" apply(rule Lim_bounded_omgea[OF assms(2), of "real y"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1823
      using False y unfolding Real_real by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1824
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1825
    have yl:"real y < real l" using as apply-
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1826
      apply(subst(asm) Real_real'[THEN sym,OF `y\<noteq>\<omega>`])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1827
      apply(subst(asm) Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1828
      unfolding pinfreal_less apply(subst(asm) if_P) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1829
    hence "y + (y - l) * Real (1 / 2) < l" apply-
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1830
      apply(subst Real_real'[THEN sym,OF `y\<noteq>\<omega>`]) apply(subst(2) Real_real'[THEN sym,OF `y\<noteq>\<omega>`])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1831
      apply(subst Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) apply(subst(2) Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1832
    hence *:"l \<in> {y + (y - l) / 2<..}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1833
    have "open {y + (y-l)/2 <..}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1834
    note topological_tendstoD[OF assms(2) this *]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1835
    from this[unfolded eventually_sequentially] guess N .. note this[rule_format, of N]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1836
    hence "y + (y - l) * Real (1 / 2) < y" using y[rule_format,of "f N"] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1837
    hence "Real (real y) + (Real (real y) - Real (real l)) * Real (1 / 2) < Real (real y)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1838
      unfolding Real_real using `y\<noteq>\<omega>` `l\<noteq>\<omega>` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1839
    thus False using yl by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1840
  qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1841
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1842
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1843
lemma Real_max':"Real x = Real (max x 0)" 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1844
proof(cases "x < 0") case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1845
  hence *:"max x 0 = 0" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1846
  show ?thesis unfolding * using True by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1847
qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1848
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1849
lemma lim_pinfreal_increasing: assumes "\<forall>n m. n\<ge>m \<longrightarrow> f n \<ge> f m"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1850
  obtains l where "f ----> (l::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1851
proof(cases "\<exists>B. \<forall>n. f n < Real B")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1852
  case False thus thesis apply- apply(rule that[of \<omega>]) unfolding Lim_omega not_ex not_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1853
    apply safe apply(erule_tac x=B in allE,safe) apply(rule_tac x=x in exI,safe)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1854
    apply(rule order_trans[OF _ assms[rule_format]]) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1855
next case True then guess B .. note B = this[rule_format]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1856
  hence *:"\<And>n. f n < \<omega>" apply-apply(rule less_le_trans,assumption) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1857
  have *:"\<And>n. f n \<noteq> \<omega>" proof- case goal1 show ?case using *[of n] by auto qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1858
  have B':"\<And>n. real (f n) \<le> max 0 B" proof- case goal1 thus ?case
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1859
      using B[of n] apply-apply(subst(asm) Real_real'[THEN sym]) defer
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1860
      apply(subst(asm)(2) Real_max') unfolding pinfreal_less apply(subst(asm) if_P) using *[of n] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1861
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1862
  have "\<exists>l. (\<lambda>n. real (f n)) ----> l" apply(rule Topology_Euclidean_Space.bounded_increasing_convergent)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1863
  proof safe show "bounded {real (f n) |n. True}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1864
      unfolding bounded_def apply(rule_tac x=0 in exI,rule_tac x="max 0 B" in exI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1865
      using B' unfolding dist_norm by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1866
    fix n::nat have "Real (real (f n)) \<le> Real (real (f (Suc n)))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1867
      using assms[rule_format,of n "Suc n"] apply(subst Real_real)+
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1868
      using *[of n] *[of "Suc n"] by fastsimp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1869
    thus "real (f n) \<le> real (f (Suc n))" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1870
  qed then guess l .. note l=this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1871
  have "0 \<le> l" apply(rule LIMSEQ_le_const[OF l])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1872
    by(rule_tac x=0 in exI,auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1873
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1874
  thus ?thesis apply-apply(rule that[of "Real l"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1875
    using l apply-apply(subst(asm) lim_Real[THEN sym]) prefer 3
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1876
    unfolding Real_real using * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1877
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1878
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1879
lemma setsum_neq_omega: assumes "finite s" "\<And>x. x \<in> s \<Longrightarrow> f x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1880
  shows "setsum f s \<noteq> \<omega>" using assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1881
proof induct case (insert x s)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1882
  show ?case unfolding setsum.insert[OF insert(1-2)] 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1883
    using insert by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1884
qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1885
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1886
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1887
lemma real_Real': "0 \<le> x \<Longrightarrow> real (Real x) = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1888
  unfolding real_Real by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1889
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1890
lemma real_pinfreal_pos[intro]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1891
  assumes "x \<noteq> 0" "x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1892
  shows "real x > 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1893
  apply(subst real_Real'[THEN sym,of 0]) defer
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1894
  apply(rule real_of_pinfreal_less) using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1895
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1896
lemma Lim_omega_gt: "f ----> \<omega> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. f n > Real B)" (is "?l = ?r")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1897
proof assume ?l thus ?r unfolding Lim_omega apply safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1898
    apply(erule_tac x="max B 0 +1" in allE,safe)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1899
    apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1900
    apply(rule_tac y="Real (max B 0 + 1)" in less_le_trans) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1901
next assume ?r thus ?l unfolding Lim_omega apply safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1902
    apply(erule_tac x=B in allE,safe) apply(rule_tac x=N in exI,safe) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1903
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1904
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1905
lemma pinfreal_minus_le_cancel:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1906
  fixes a b c :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1907
  assumes "b \<le> a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1908
  shows "c - a \<le> c - b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1909
  using assms by (cases a, cases b, cases c, simp, simp, simp, cases b, cases c, simp_all)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1910
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1911
lemma pinfreal_minus_\<omega>[simp]: "x - \<omega> = 0" by (cases x) simp_all
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1912
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1913
lemma pinfreal_minus_mono[intro]: "a - x \<le> (a::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1914
proof- have "a - x \<le> a - 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1915
    apply(rule pinfreal_minus_le_cancel) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1916
  thus ?thesis by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1917
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1918
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1919
lemma pinfreal_minus_eq_\<omega>[simp]: "x - y = \<omega> \<longleftrightarrow> (x = \<omega> \<and> y \<noteq> \<omega>)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1920
  by (cases x, cases y) (auto, cases y, auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1921
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1922
lemma pinfreal_less_minus_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1923
  fixes a b c :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1924
  shows "a < b - c \<longleftrightarrow> c + a < b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1925
  by (cases c, cases a, cases b, auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1926
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1927
lemma pinfreal_minus_less_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1928
  fixes a b c :: pinfreal shows "a - c < b \<longleftrightarrow> (0 < b \<and> (c \<noteq> \<omega> \<longrightarrow> a < b + c))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1929
  by (cases c, cases a, cases b, auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1930
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1931
lemma pinfreal_le_minus_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1932
  fixes a b c :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1933
  shows "a \<le> c - b \<longleftrightarrow> ((c \<le> b \<longrightarrow> a = 0) \<and> (b < c \<longrightarrow> a + b \<le> c))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1934
  by (cases a, cases c, cases b, auto simp: pinfreal_noteq_omega_Ex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1935
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1936
lemma pinfreal_minus_le_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1937
  fixes a b c :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1938
  shows "a - c \<le> b \<longleftrightarrow> (c \<le> a \<longrightarrow> a \<le> b + c)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1939
  by (cases a, cases c, cases b, auto simp: pinfreal_noteq_omega_Ex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1940
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1941
lemmas pinfreal_minus_order = pinfreal_minus_le_iff pinfreal_minus_less_iff pinfreal_le_minus_iff pinfreal_less_minus_iff
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1942
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1943
lemma pinfreal_minus_strict_mono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1944
  assumes "a > 0" "x > 0" "a\<noteq>\<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1945
  shows "a - x < (a::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1946
  using assms by(cases x, cases a, auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1947
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1948
lemma pinfreal_minus':
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1949
  "Real r - Real p = (if 0 \<le> r \<and> p \<le> r then if 0 \<le> p then Real (r - p) else Real r else 0)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1950
  by (auto simp: minus_pinfreal_eq not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1951
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1952
lemma pinfreal_minus_plus:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1953
  "x \<le> (a::pinfreal) \<Longrightarrow> a - x + x = a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1954
  by (cases a, cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1955
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1956
lemma pinfreal_cancel_plus_minus: "b \<noteq> \<omega> \<Longrightarrow> a + b - b = a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1957
  by (cases a, cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1958
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1959
lemma pinfreal_minus_le_cancel_right:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1960
  fixes a b c :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1961
  assumes "a \<le> b" "c \<le> a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1962
  shows "a - c \<le> b - c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1963
  using assms by (cases a, cases b, cases c, auto, cases c, auto)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1964
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1965
lemma real_of_pinfreal_setsum':
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1966
  assumes "\<forall>x \<in> S. f x \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1967
  shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1968
proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1969
  assume "finite S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1970
  from this assms show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1971
    by induct (simp_all add: real_of_pinfreal_add setsum_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1972
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1973
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1974
lemma Lim_omega_pos: "f ----> \<omega> \<longleftrightarrow> (\<forall>B>0. \<exists>N. \<forall>n\<ge>N. f n \<ge> Real B)" (is "?l = ?r")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1975
  unfolding Lim_omega apply safe defer
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1976
  apply(erule_tac x="max 1 B" in allE) apply safe defer
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1977
  apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1978
  apply(rule_tac y="Real (max 1 B)" in order_trans) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1979
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1980
lemma (in complete_lattice) isotonD[dest]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1981
  assumes "A \<up> X" shows "A i \<le> A (Suc i)" "(SUP i. A i) = X"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1982
  using assms unfolding isoton_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1983
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1984
lemma isotonD'[dest]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1985
  assumes "(A::_=>_) \<up> X" shows "A i x \<le> A (Suc i) x" "(SUP i. A i) = X"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1986
  using assms unfolding isoton_def le_fun_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1987
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1988
lemma pinfreal_LimI_finite:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1989
  assumes "x \<noteq> \<omega>" "\<And>r. 0 < r \<Longrightarrow> \<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1990
  shows "u ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1991
proof (rule topological_tendstoI, unfold eventually_sequentially)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1992
  fix S assume "open S" "x \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1993
  then obtain A where "open A" and A_eq: "Real ` (A \<inter> {0..}) = S - {\<omega>}" by (auto elim!: pinfreal_openE)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1994
  then have "x \<in> Real ` (A \<inter> {0..})" using `x \<in> S` `x \<noteq> \<omega>` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1995
  then have "real x \<in> A" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1996
  then obtain r where "0 < r" and dist: "\<And>y. dist y (real x) < r \<Longrightarrow> y \<in> A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1997
    using `open A` unfolding open_real_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1998
  then obtain n where
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  1999
    upper: "\<And>N. n \<le> N \<Longrightarrow> u N < x + Real r" and
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2000
    lower: "\<And>N. n \<le> N \<Longrightarrow> x < u N + Real r" using assms(2)[of "Real r"] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2001
  show "\<exists>N. \<forall>n\<ge>N. u n \<in> S"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2002
  proof (safe intro!: exI[of _ n])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2003
    fix N assume "n \<le> N"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2004
    from upper[OF this] `x \<noteq> \<omega>` `0 < r`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2005
    have "u N \<noteq> \<omega>" by (force simp: pinfreal_noteq_omega_Ex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2006
    with `x \<noteq> \<omega>` `0 < r` lower[OF `n \<le> N`] upper[OF `n \<le> N`]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2007
    have "dist (real (u N)) (real x) < r" "u N \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2008
      by (auto simp: pinfreal_noteq_omega_Ex dist_real_def abs_diff_less_iff field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2009
    from dist[OF this(1)]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2010
    have "u N \<in> Real ` (A \<inter> {0..})" using `u N \<noteq> \<omega>`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2011
      by (auto intro!: image_eqI[of _ _ "real (u N)"] simp: pinfreal_noteq_omega_Ex Real_real)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2012
    thus "u N \<in> S" using A_eq by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2013
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2014
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2015
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2016
lemma real_Real_max:"real (Real x) = max x 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2017
  unfolding real_Real by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2018
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2019
lemma (in complete_lattice) SUPR_upper:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2020
  "x \<in> A \<Longrightarrow> f x \<le> SUPR A f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2021
  unfolding SUPR_def apply(rule Sup_upper) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2022
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2023
lemma (in complete_lattice) SUPR_subset:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2024
  assumes "A \<subseteq> B" shows "SUPR A f \<le> SUPR B f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2025
  apply(rule SUP_leI) apply(rule SUPR_upper) using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2026
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2027
lemma (in complete_lattice) SUPR_mono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2028
  assumes "\<forall>a\<in>A. \<exists>b\<in>B. f b \<ge> f a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2029
  shows "SUPR A f \<le> SUPR B f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2030
  unfolding SUPR_def apply(rule Sup_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2031
  using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2032
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2033
lemma Sup_lim:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2034
  assumes "\<forall>n. b n \<in> s" "b ----> (a::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2035
  shows "a \<le> Sup s"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2036
proof(rule ccontr,unfold not_le)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2037
  assume as:"Sup s < a" hence om:"Sup s \<noteq> \<omega>" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2038
  have s:"s \<noteq> {}" using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2039
  { presume *:"\<forall>n. b n < a \<Longrightarrow> False"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2040
    show False apply(cases,rule *,assumption,unfold not_all not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2041
    proof- case goal1 then guess n .. note n=this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2042
      thus False using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of n]]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2043
        using as by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2044
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2045
  } assume b:"\<forall>n. b n < a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2046
  show False
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2047
  proof(cases "a = \<omega>")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2048
    case False have *:"a - Sup s > 0" 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2049
      using False as by(auto simp: pinfreal_zero_le_diff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2050
    have "(a - Sup s) / 2 \<le> a / 2" unfolding divide_pinfreal_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2051
      apply(rule mult_right_mono) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2052
    also have "... = Real (real (a / 2))" apply(rule Real_real'[THEN sym])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2053
      using False by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2054
    also have "... < Real (real a)" unfolding pinfreal_less using as False
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2055
      by(auto simp add: real_of_pinfreal_mult[THEN sym])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2056
    also have "... = a" apply(rule Real_real') using False by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2057
    finally have asup:"a > (a - Sup s) / 2" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2058
    have "\<exists>n. a - b n < (a - Sup s) / 2"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2059
    proof(rule ccontr,unfold not_ex not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2060
      case goal1
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2061
      have "(a - Sup s) * Real (1 / 2)  > 0" 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2062
        using * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2063
      hence "a - (a - Sup s) * Real (1 / 2) < a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2064
        apply-apply(rule pinfreal_minus_strict_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2065
        using False * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2066
      hence *:"a \<in> {a - (a - Sup s) / 2<..}"using asup by auto 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2067
      note topological_tendstoD[OF assms(2) open_pinfreal_greaterThan,OF *]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2068
      from this[unfolded eventually_sequentially] guess n .. 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2069
      note n = this[rule_format,of n] 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2070
      have "b n + (a - Sup s) / 2 \<le> a" 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2071
        using add_right_mono[OF goal1[rule_format,of n],of "b n"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2072
        unfolding pinfreal_minus_plus[OF less_imp_le[OF b[rule_format]]]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2073
        by(auto simp: add_commute)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2074
      hence "b n \<le> a - (a - Sup s) / 2" unfolding pinfreal_le_minus_iff
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2075
        using asup by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2076
      hence "b n \<notin> {a - (a - Sup s) / 2<..}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2077
      thus False using n by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2078
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2079
    then guess n .. note n = this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2080
    have "Sup s < a - (a - Sup s) / 2"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2081
      using False as om by (cases a) (auto simp: pinfreal_noteq_omega_Ex field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2082
    also have "... \<le> b n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2083
    proof- note add_right_mono[OF less_imp_le[OF n],of "b n"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2084
      note this[unfolded pinfreal_minus_plus[OF less_imp_le[OF b[rule_format]]]]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2085
      hence "a - (a - Sup s) / 2 \<le> (a - Sup s) / 2 + b n - (a - Sup s) / 2"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2086
        apply(rule pinfreal_minus_le_cancel_right) using asup by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2087
      also have "... = b n + (a - Sup s) / 2 - (a - Sup s) / 2" 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2088
        by(auto simp add: add_commute)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2089
      also have "... = b n" apply(subst pinfreal_cancel_plus_minus)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2090
      proof(rule ccontr,unfold not_not) case goal1
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2091
        show ?case using asup unfolding goal1 by auto 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2092
      qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2093
      finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2094
    qed     
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2095
    finally show False
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2096
      using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of n]] by auto  
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2097
  next case True
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2098
    from assms(2)[unfolded True Lim_omega_gt,rule_format,of "real (Sup s)"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2099
    guess N .. note N = this[rule_format,of N]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2100
    thus False using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of N]] 
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2101
      unfolding Real_real using om by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2102
  qed qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2103
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2104
lemma less_SUP_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2105
  fixes a :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2106
  shows "(a < (SUP i:A. f i)) \<longleftrightarrow> (\<exists>x\<in>A. a < f x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2107
  unfolding SUPR_def less_Sup_iff by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2108
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2109
lemma Sup_mono_lim:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2110
  assumes "\<forall>a\<in>A. \<exists>b. \<forall>n. b n \<in> B \<and> b ----> (a::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2111
  shows "Sup A \<le> Sup B"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2112
  unfolding Sup_le_iff apply(rule) apply(drule assms[rule_format]) apply safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2113
  apply(rule_tac b=b in Sup_lim) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2114
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2115
lemma pinfreal_less_add:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2116
  assumes "x \<noteq> \<omega>" "a < b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2117
  shows "x + a < x + b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2118
  using assms by (cases a, cases b, cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2119
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2120
lemma SUPR_lim:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2121
  assumes "\<forall>n. b n \<in> B" "(\<lambda>n. f (b n)) ----> (f a::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2122
  shows "f a \<le> SUPR B f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2123
  unfolding SUPR_def apply(rule Sup_lim[of "\<lambda>n. f (b n)"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2124
  using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2125
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2126
lemma SUP_\<omega>_imp:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2127
  assumes "(SUP i. f i) = \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2128
  shows "\<exists>i. Real x < f i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2129
proof (rule ccontr)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2130
  assume "\<not> ?thesis" hence "\<And>i. f i \<le> Real x" by (simp add: not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2131
  hence "(SUP i. f i) \<le> Real x" unfolding SUP_le_iff by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2132
  with assms show False by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2133
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2134
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2135
lemma SUPR_mono_lim:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2136
  assumes "\<forall>a\<in>A. \<exists>b. \<forall>n. b n \<in> B \<and> (\<lambda>n. f (b n)) ----> (f a::pinfreal)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2137
  shows "SUPR A f \<le> SUPR B f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2138
  unfolding SUPR_def apply(rule Sup_mono_lim)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2139
  apply safe apply(drule assms[rule_format],safe)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2140
  apply(rule_tac x="\<lambda>n. f (b n)" in exI) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2141
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2142
lemma real_0_imp_eq_0:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2143
  assumes "x \<noteq> \<omega>" "real x = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2144
  shows "x = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2145
using assms by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2146
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2147
lemma SUPR_mono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2148
  assumes "\<forall>a\<in>A. \<exists>b\<in>B. f b \<ge> f a"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2149
  shows "SUPR A f \<le> SUPR B f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2150
  unfolding SUPR_def apply(rule Sup_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2151
  using assms by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2152
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2153
lemma less_add_Real:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2154
  fixes x :: real
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2155
  fixes a b :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2156
  assumes "x \<ge> 0" "a < b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2157
  shows "a + Real x < b + Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2158
using assms by (cases a, cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2159
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2160
lemma le_add_Real:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2161
  fixes x :: real
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2162
  fixes a b :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2163
  assumes "x \<ge> 0" "a \<le> b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2164
  shows "a + Real x \<le> b + Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2165
using assms by (cases a, cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2166
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2167
lemma le_imp_less_pinfreal:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2168
  fixes x :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2169
  assumes "x > 0" "a + x \<le> b" "a \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2170
  shows "a < b"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2171
using assms by (cases x, cases a, cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2172
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2173
lemma pinfreal_INF_minus:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2174
  fixes f :: "nat \<Rightarrow> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2175
  assumes "c \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2176
  shows "(INF i. c - f i) = c - (SUP i. f i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2177
proof (cases "SUP i. f i")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2178
  case infinite
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2179
  from `c \<noteq> \<omega>` obtain x where [simp]: "c = Real x" by (cases c) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2180
  from SUP_\<omega>_imp[OF infinite] obtain i where "Real x < f i" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2181
  have "(INF i. c - f i) \<le> c - f i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2182
    by (auto intro!: complete_lattice_class.INF_leI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2183
  also have "\<dots> = 0" using `Real x < f i` by (auto simp: minus_pinfreal_eq)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2184
  finally show ?thesis using infinite by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2185
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2186
  case (preal r)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2187
  from `c \<noteq> \<omega>` obtain x where c: "c = Real x" by (cases c) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2188
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2189
  show ?thesis unfolding c
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2190
  proof (rule pinfreal_INFI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2191
    fix i have "f i \<le> (SUP i. f i)" by (rule le_SUPI) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2192
    thus "Real x - (SUP i. f i) \<le> Real x - f i" by (rule pinfreal_minus_le_cancel)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2193
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2194
    fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> y \<le> Real x - f i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2195
    from this[of 0] obtain p where p: "y = Real p" "0 \<le> p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2196
      by (cases "f 0", cases y, auto split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2197
    hence "\<And>i. Real p \<le> Real x - f i" using * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2198
    hence *: "\<And>i. Real x \<le> f i \<Longrightarrow> Real p = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2199
      "\<And>i. f i < Real x \<Longrightarrow> Real p + f i \<le> Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2200
      unfolding pinfreal_le_minus_iff by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2201
    show "y \<le> Real x - (SUP i. f i)" unfolding p pinfreal_le_minus_iff
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2202
    proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2203
      assume x_less: "Real x \<le> (SUP i. f i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2204
      show "Real p = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2205
      proof (rule ccontr)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2206
        assume "Real p \<noteq> 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2207
        hence "0 < Real p" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2208
        from Sup_close[OF this, of "range f"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2209
        obtain i where e: "(SUP i. f i) < f i + Real p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2210
          using preal unfolding SUPR_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2211
        hence "Real x \<le> f i + Real p" using x_less by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2212
        show False
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2213
        proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2214
          assume "\<forall>i. f i < Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2215
          hence "Real p + f i \<le> Real x" using * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2216
          hence "f i + Real p \<le> (SUP i. f i)" using x_less by (auto simp: field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2217
          thus False using e by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2218
        next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2219
          assume "\<not> (\<forall>i. f i < Real x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2220
          then obtain i where "Real x \<le> f i" by (auto simp: not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2221
          from *(1)[OF this] show False using `Real p \<noteq> 0` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2222
        qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2223
      qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2224
    next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2225
      have "\<And>i. f i \<le> (SUP i. f i)" by (rule complete_lattice_class.le_SUPI) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2226
      also assume "(SUP i. f i) < Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2227
      finally have "\<And>i. f i < Real x" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2228
      hence *: "\<And>i. Real p + f i \<le> Real x" using * by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2229
      have "Real p \<le> Real x" using *[of 0] by (cases "f 0") (auto split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2230
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2231
      have SUP_eq: "(SUP i. f i) \<le> Real x - Real p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2232
      proof (rule SUP_leI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2233
        fix i show "f i \<le> Real x - Real p" unfolding pinfreal_le_minus_iff
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2234
        proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2235
          assume "Real x \<le> Real p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2236
          with *[of i] show "f i = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2237
            by (cases "f i") (auto split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2238
        next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2239
          assume "Real p < Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2240
          show "f i + Real p \<le> Real x" using * by (auto simp: field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2241
        qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2242
      qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2243
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2244
      show "Real p + (SUP i. f i) \<le> Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2245
      proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2246
        assume "Real x \<le> Real p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2247
        with `Real p \<le> Real x` have [simp]: "Real p = Real x" by (rule antisym)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2248
        { fix i have "f i = 0" using *[of i] by (cases "f i") (auto split: split_if_asm) }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2249
        hence "(SUP i. f i) \<le> 0" by (auto intro!: SUP_leI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2250
        thus ?thesis by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2251
      next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2252
        assume "\<not> Real x \<le> Real p" hence "Real p < Real x" unfolding not_le .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2253
        with SUP_eq show ?thesis unfolding pinfreal_le_minus_iff by (auto simp: field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2254
      qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2255
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2256
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2257
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2258
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2259
lemma pinfreal_SUP_minus:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2260
  fixes f :: "nat \<Rightarrow> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2261
  shows "(SUP i. c - f i) = c - (INF i. f i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2262
proof (rule pinfreal_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2263
  fix i have "(INF i. f i) \<le> f i" by (rule INF_leI) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2264
  thus "c - f i \<le> c - (INF i. f i)" by (rule pinfreal_minus_le_cancel)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2265
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2266
  fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> c - f i \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2267
  show "c - (INF i. f i) \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2268
  proof (cases y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2269
    case (preal p)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2270
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2271
    show ?thesis unfolding pinfreal_minus_le_iff preal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2272
    proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2273
      assume INF_le_x: "(INF i. f i) \<le> c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2274
      from * have *: "\<And>i. f i \<le> c \<Longrightarrow> c \<le> Real p + f i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2275
        unfolding pinfreal_minus_le_iff preal by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2276
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2277
      have INF_eq: "c - Real p \<le> (INF i. f i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2278
      proof (rule le_INFI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2279
        fix i show "c - Real p \<le> f i" unfolding pinfreal_minus_le_iff
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2280
        proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2281
          assume "Real p \<le> c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2282
          show "c \<le> f i + Real p"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2283
          proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2284
            assume "f i \<le> c" from *[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2285
            show ?thesis by (simp add: field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2286
          next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2287
            assume "\<not> f i \<le> c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2288
            hence "c \<le> f i" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2289
            also have "\<dots> \<le> f i + Real p" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2290
            finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2291
          qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2292
        qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2293
      qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2294
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2295
      show "c \<le> Real p + (INF i. f i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2296
      proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2297
        assume "Real p \<le> c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2298
        with INF_eq show ?thesis unfolding pinfreal_minus_le_iff by (auto simp: field_simps)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2299
      next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2300
        assume "\<not> Real p \<le> c"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2301
        hence "c \<le> Real p" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2302
        also have "Real p \<le> Real p + (INF i. f i)" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2303
        finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2304
      qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2305
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2306
  qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2307
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2308
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2309
lemma pinfreal_le_minus_imp_0:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2310
  fixes a b :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2311
  shows "a \<le> a - b \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> a \<noteq> \<omega> \<Longrightarrow> b = 0"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2312
  by (cases a, cases b, auto split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2313
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2314
lemma lim_INF_le_lim_SUP:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2315
  fixes f :: "nat \<Rightarrow> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2316
  shows "(SUP n. INF m. f (n + m)) \<le> (INF n. SUP m. f (n + m))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2317
proof (rule complete_lattice_class.SUP_leI, rule complete_lattice_class.le_INFI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2318
  fix i j show "(INF m. f (i + m)) \<le> (SUP m. f (j + m))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2319
  proof (cases rule: le_cases)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2320
    assume "i \<le> j"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2321
    have "(INF m. f (i + m)) \<le> f (i + (j - i))" by (rule INF_leI) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2322
    also have "\<dots> = f (j + 0)" using `i \<le> j` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2323
    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2324
    finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2325
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2326
    assume "j \<le> i"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2327
    have "(INF m. f (i + m)) \<le> f (i + 0)" by (rule INF_leI) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2328
    also have "\<dots> = f (j + (i - j))" using `j \<le> i` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2329
    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2330
    finally show ?thesis .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2331
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2332
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2333
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2334
lemma lim_INF_eq_lim_SUP:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2335
  fixes X :: "nat \<Rightarrow> real"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2336
  assumes "\<And>i. 0 \<le> X i" and "0 \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2337
  and lim_INF: "(SUP n. INF m. Real (X (n + m))) = Real x" (is "(SUP n. ?INF n) = _")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2338
  and lim_SUP: "(INF n. SUP m. Real (X (n + m))) = Real x" (is "(INF n. ?SUP n) = _")
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2339
  shows "X ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2340
proof (rule LIMSEQ_I)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2341
  fix r :: real assume "0 < r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2342
  hence "0 \<le> r" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2343
  from Sup_close[of "Real r" "range ?INF"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2344
  obtain n where inf: "Real x < ?INF n + Real r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2345
    unfolding SUPR_def lim_INF[unfolded SUPR_def] using `0 < r` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2346
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2347
  from Inf_close[of "range ?SUP" "Real r"]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2348
  obtain n' where sup: "?SUP n' < Real x + Real r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2349
    unfolding INFI_def lim_SUP[unfolded INFI_def] using `0 < r` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2350
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2351
  show "\<exists>N. \<forall>n\<ge>N. norm (X n - x) < r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2352
  proof (safe intro!: exI[of _ "max n n'"])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2353
    fix m assume "max n n' \<le> m" hence "n \<le> m" "n' \<le> m" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2354
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2355
    note inf
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2356
    also have "?INF n + Real r \<le> Real (X (n + (m - n))) + Real r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2357
      by (rule le_add_Real, auto simp: `0 \<le> r` intro: INF_leI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2358
    finally have up: "x < X m + r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2359
      using `0 \<le> X m` `0 \<le> x` `0 \<le> r` `n \<le> m` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2360
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2361
    have "Real (X (n' + (m - n'))) \<le> ?SUP n'"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2362
      by (auto simp: `0 \<le> r` intro: le_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2363
    also note sup
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2364
    finally have down: "X m < x + r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2365
      using `0 \<le> X m` `0 \<le> x` `0 \<le> r` `n' \<le> m` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2366
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2367
    show "norm (X m - x) < r" using up down by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2368
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2369
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2370
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2371
lemma Sup_countable_SUPR:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2372
  assumes "Sup A \<noteq> \<omega>" "A \<noteq> {}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2373
  shows "\<exists> f::nat \<Rightarrow> pinfreal. range f \<subseteq> A \<and> Sup A = SUPR UNIV f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2374
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2375
  have "\<And>n. 0 < 1 / (of_nat n :: pinfreal)" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2376
  from Sup_close[OF this assms]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2377
  have "\<forall>n. \<exists>x. x \<in> A \<and> Sup A < x + 1 / of_nat n" by blast
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2378
  from choice[OF this] obtain f where "range f \<subseteq> A" and
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2379
    epsilon: "\<And>n. Sup A < f n + 1 / of_nat n" by blast
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2380
  have "SUPR UNIV f = Sup A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2381
  proof (rule pinfreal_SUPI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2382
    fix i show "f i \<le> Sup A" using `range f \<subseteq> A`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2383
      by (auto intro!: complete_lattice_class.Sup_upper)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2384
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2385
    fix y assume bound: "\<And>i. i \<in> UNIV \<Longrightarrow> f i \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2386
    show "Sup A \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2387
    proof (rule pinfreal_le_epsilon)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2388
      fix e :: pinfreal assume "0 < e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2389
      show "Sup A \<le> y + e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2390
      proof (cases e)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2391
        case (preal r)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2392
        hence "0 < r" using `0 < e` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2393
        then obtain n where *: "inverse (of_nat n) < r" "0 < n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2394
          using ex_inverse_of_nat_less by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2395
        have "Sup A \<le> f n + 1 / of_nat n" using epsilon[of n] by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2396
        also have "1 / of_nat n \<le> e" using preal * by (auto simp: real_eq_of_nat)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2397
        with bound have "f n + 1 / of_nat n \<le> y + e" by (rule add_mono) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2398
        finally show "Sup A \<le> y + e" .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2399
      qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2400
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2401
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2402
  with `range f \<subseteq> A` show ?thesis by (auto intro!: exI[of _ f])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2403
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2404
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2405
lemma SUPR_countable_SUPR:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2406
  assumes "SUPR A g \<noteq> \<omega>" "A \<noteq> {}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2407
  shows "\<exists> f::nat \<Rightarrow> pinfreal. range f \<subseteq> g`A \<and> SUPR A g = SUPR UNIV f"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2408
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2409
  have "Sup (g`A) \<noteq> \<omega>" "g`A \<noteq> {}" using assms unfolding SUPR_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2410
  from Sup_countable_SUPR[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2411
  show ?thesis unfolding SUPR_def .
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2412
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2413
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2414
lemma pinfreal_setsum_subtractf:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2415
  assumes "\<And>i. i\<in>A \<Longrightarrow> g i \<le> f i" and "\<And>i. i\<in>A \<Longrightarrow> f i \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2416
  shows "(\<Sum>i\<in>A. f i - g i) = (\<Sum>i\<in>A. f i) - (\<Sum>i\<in>A. g i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2417
proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2418
  assume "finite A" from this assms show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2419
  proof induct
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2420
    case (insert x A)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2421
    hence hyp: "(\<Sum>i\<in>A. f i - g i) = (\<Sum>i\<in>A. f i) - (\<Sum>i\<in>A. g i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2422
      by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2423
    { fix i assume *: "i \<in> insert x A"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2424
      hence "g i \<le> f i" using insert by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2425
      also have "f i < \<omega>" using * insert by (simp add: pinfreal_less_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2426
      finally have "g i \<noteq> \<omega>" by (simp add: pinfreal_less_\<omega>) }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2427
    hence "setsum g A \<noteq> \<omega>" "g x \<noteq> \<omega>" by (auto simp: setsum_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2428
    moreover have "setsum f A \<noteq> \<omega>" "f x \<noteq> \<omega>" using insert by (auto simp: setsum_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2429
    moreover have "g x \<le> f x" using insert by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2430
    moreover have "(\<Sum>i\<in>A. g i) \<le> (\<Sum>i\<in>A. f i)" using insert by (auto intro!: setsum_mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2431
    ultimately show ?case using `finite A` `x \<notin> A` hyp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2432
      by (auto simp: pinfreal_noteq_omega_Ex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2433
  qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2434
qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2435
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2436
lemma real_of_pinfreal_diff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2437
  "y \<le> x \<Longrightarrow> x \<noteq> \<omega> \<Longrightarrow> real x - real y = real (x - y)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2438
  by (cases x, cases y) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2439
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2440
lemma psuminf_minus:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2441
  assumes ord: "\<And>i. g i \<le> f i" and fin: "psuminf g \<noteq> \<omega>" "psuminf f \<noteq> \<omega>"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2442
  shows "(\<Sum>\<^isub>\<infinity> i. f i - g i) = psuminf f - psuminf g"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2443
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2444
  have [simp]: "\<And>i. f i \<noteq> \<omega>" using fin by (auto intro: psuminf_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2445
  from fin have "(\<lambda>x. real (f x)) sums real (\<Sum>\<^isub>\<infinity>x. f x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2446
    and "(\<lambda>x. real (g x)) sums real (\<Sum>\<^isub>\<infinity>x. g x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2447
    by (auto intro: psuminf_imp_suminf)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2448
  from sums_diff[OF this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2449
  have "(\<lambda>n. real (f n - g n)) sums (real ((\<Sum>\<^isub>\<infinity>x. f x) - (\<Sum>\<^isub>\<infinity>x. g x)))" using fin ord
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2450
    by (subst (asm) (1 2) real_of_pinfreal_diff) (auto simp: psuminf_\<omega> psuminf_le)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2451
  hence "(\<Sum>\<^isub>\<infinity> i. Real (real (f i - g i))) = Real (real ((\<Sum>\<^isub>\<infinity>x. f x) - (\<Sum>\<^isub>\<infinity>x. g x)))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2452
    by (rule suminf_imp_psuminf) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2453
  thus ?thesis using fin by (simp add: Real_real psuminf_\<omega>)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2454
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2455
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2456
lemma INF_eq_LIMSEQ:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2457
  assumes "mono (\<lambda>i. - f i)" and "\<And>n. 0 \<le> f n" and "0 \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2458
  shows "(INF n. Real (f n)) = Real x \<longleftrightarrow> f ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2459
proof
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2460
  assume x: "(INF n. Real (f n)) = Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2461
  { fix n
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2462
    have "Real x \<le> Real (f n)" using x[symmetric] by (auto intro: INF_leI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2463
    hence "x \<le> f n" using assms by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2464
    hence "\<bar>f n - x\<bar> = f n - x" by auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2465
  note abs_eq = this
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2466
  show "f ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2467
  proof (rule LIMSEQ_I)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2468
    fix r :: real assume "0 < r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2469
    show "\<exists>no. \<forall>n\<ge>no. norm (f n - x) < r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2470
    proof (rule ccontr)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2471
      assume *: "\<not> ?thesis"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2472
      { fix N
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2473
        from * obtain n where *: "N \<le> n" "r \<le> f n - x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2474
          using abs_eq by (auto simp: not_less)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2475
        hence "x + r \<le> f n" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2476
        also have "f n \<le> f N" using `mono (\<lambda>i. - f i)` * by (auto dest: monoD)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2477
        finally have "Real (x + r) \<le> Real (f N)" using `0 \<le> f N` by auto }
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2478
      hence "Real x < Real (x + r)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2479
        and "Real (x + r) \<le> (INF n. Real (f n))" using `0 < r` `0 \<le> x` by (auto intro: le_INFI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2480
      hence "Real x < (INF n. Real (f n))" by (rule less_le_trans)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2481
      thus False using x by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2482
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2483
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2484
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2485
  assume "f ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2486
  show "(INF n. Real (f n)) = Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2487
  proof (rule pinfreal_INFI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2488
    fix n
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2489
    from decseq_le[OF _ `f ----> x`] assms
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2490
    show "Real x \<le> Real (f n)" unfolding decseq_eq_incseq incseq_mono by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2491
  next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2492
    fix y assume *: "\<And>n. n\<in>UNIV \<Longrightarrow> y \<le> Real (f n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2493
    thus "y \<le> Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2494
    proof (cases y)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2495
      case (preal r)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2496
      with * have "\<exists>N. \<forall>n\<ge>N. r \<le> f n" using assms by fastsimp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2497
      from LIMSEQ_le_const[OF `f ----> x` this]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2498
      show "y \<le> Real x" using `0 \<le> x` preal by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2499
    qed simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2500
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2501
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2502
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2503
lemma INFI_bound:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2504
  assumes "\<forall>N. x \<le> f N"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2505
  shows "x \<le> (INF n. f n)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2506
  using assms by (simp add: INFI_def le_Inf_iff)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2507
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2508
lemma LIMSEQ_imp_lim_INF:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2509
  assumes pos: "\<And>i. 0 \<le> X i" and lim: "X ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2510
  shows "(SUP n. INF m. Real (X (n + m))) = Real x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2511
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2512
  have "0 \<le> x" using assms by (auto intro!: LIMSEQ_le_const)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2513
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2514
  have "\<And>n. (INF m. Real (X (n + m))) \<le> Real (X (n + 0))" by (rule INF_leI) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2515
  also have "\<And>n. Real (X (n + 0)) < \<omega>" by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2516
  finally have "\<forall>n. \<exists>r\<ge>0. (INF m. Real (X (n + m))) = Real r"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2517
    by (auto simp: pinfreal_less_\<omega> pinfreal_noteq_omega_Ex)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2518
  from choice[OF this] obtain r where r: "\<And>n. (INF m. Real (X (n + m))) = Real (r n)" "\<And>n. 0 \<le> r n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2519
    by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2520
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2521
  show ?thesis unfolding r
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2522
  proof (subst SUP_eq_LIMSEQ)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2523
    show "mono r" unfolding mono_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2524
    proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2525
      fix x y :: nat assume "x \<le> y"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2526
      have "Real (r x) \<le> Real (r y)" unfolding r(1)[symmetric] using pos
38705
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
  2527
      proof (safe intro!: INF_mono bexI)
38656
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2528
        fix m have "x + (m + y - x) = y + m"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2529
          using `x \<le> y` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2530
        thus "Real (X (x + (m + y - x))) \<le> Real (X (y + m))" by simp
38705
aaee86c0e237 moved generic lemmas in Probability to HOL
hoelzl
parents: 38656
diff changeset
  2531
      qed simp
38656
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2532
      thus "r x \<le> r y" using r by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2533
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2534
    show "\<And>n. 0 \<le> r n" by fact
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2535
    show "0 \<le> x" by fact
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2536
    show "r ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2537
    proof (rule LIMSEQ_I)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2538
      fix e :: real assume "0 < e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2539
      hence "0 < e/2" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2540
      from LIMSEQ_D[OF lim this] obtain N where *: "\<And>n. N \<le> n \<Longrightarrow> \<bar>X n - x\<bar> < e/2"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2541
        by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2542
      show "\<exists>N. \<forall>n\<ge>N. norm (r n - x) < e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2543
      proof (safe intro!: exI[of _ N])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2544
        fix n assume "N \<le> n"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2545
        show "norm (r n - x) < e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2546
        proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2547
          assume "r n < x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2548
          have "x - r n \<le> e/2"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2549
          proof cases
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2550
            assume e: "e/2 \<le> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2551
            have "Real (x - e/2) \<le> Real (r n)" unfolding r(1)[symmetric]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2552
            proof (rule le_INFI)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2553
              fix m show "Real (x - e / 2) \<le> Real (X (n + m))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2554
                using *[of "n + m"] `N \<le> n`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2555
                using pos by (auto simp: field_simps abs_real_def split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2556
            qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2557
            with e show ?thesis using pos `0 \<le> x` r(2) by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2558
          next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2559
            assume "\<not> e/2 \<le> x" hence "x - e/2 < 0" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2560
            with `0 \<le> r n` show ?thesis by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2561
          qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2562
          with `r n < x` show ?thesis by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2563
        next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2564
          assume e: "\<not> r n < x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2565
          have "Real (r n) \<le> Real (X (n + 0))" unfolding r(1)[symmetric]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2566
            by (rule INF_leI) simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2567
          hence "r n - x \<le> X n - x" using r pos by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2568
          also have "\<dots> < e/2" using *[OF `N \<le> n`] by (auto simp: field_simps abs_real_def split: split_if_asm)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2569
          finally have "r n - x < e" using `0 < e` by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2570
          with e show ?thesis by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2571
        qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2572
      qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2573
    qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2574
  qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2575
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2576
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2577
lemma real_of_pinfreal_strict_mono_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2578
  "real a < real b \<longleftrightarrow> (b \<noteq> \<omega> \<and> ((a = \<omega> \<and> 0 < b) \<or> (a < b)))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2579
proof (cases a)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2580
  case infinite thus ?thesis by (cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2581
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2582
  case preal thus ?thesis by (cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2583
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2584
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2585
lemma real_of_pinfreal_mono_iff:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2586
  "real a \<le> real b \<longleftrightarrow> (a = \<omega> \<or> (b \<noteq> \<omega> \<and> a \<le> b) \<or> (b = \<omega> \<and> a = 0))"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2587
proof (cases a)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2588
  case infinite thus ?thesis by (cases b) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2589
next
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2590
  case preal thus ?thesis by (cases b)  auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2591
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2592
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2593
lemma ex_pinfreal_inverse_of_nat_Suc_less:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2594
  fixes e :: pinfreal assumes "0 < e" shows "\<exists>n. inverse (of_nat (Suc n)) < e"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2595
proof (cases e)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2596
  case (preal r)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2597
  with `0 < e` ex_inverse_of_nat_Suc_less[of r]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2598
  obtain n where "inverse (of_nat (Suc n)) < r" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2599
  with preal show ?thesis
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2600
    by (auto simp: real_eq_of_nat[symmetric])
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2601
qed auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2602
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2603
lemma Lim_eq_Sup_mono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2604
  fixes u :: "nat \<Rightarrow> pinfreal" assumes "mono u"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2605
  shows "u ----> (SUP i. u i)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2606
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2607
  from lim_pinfreal_increasing[of u] `mono u`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2608
  obtain l where l: "u ----> l" unfolding mono_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2609
  from SUP_Lim_pinfreal[OF _ this] `mono u`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2610
  have "(SUP i. u i) = l" unfolding mono_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2611
  with l show ?thesis by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2612
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2613
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2614
lemma isotone_Lim:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2615
  fixes x :: pinfreal assumes "u \<up> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2616
  shows "u ----> x" (is ?lim) and "mono u" (is ?mono)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2617
proof -
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2618
  show ?mono using assms unfolding mono_iff_le_Suc isoton_def by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2619
  from Lim_eq_Sup_mono[OF this] `u \<up> x`
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2620
  show ?lim unfolding isoton_def by simp
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2621
qed
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2622
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2623
lemma isoton_iff_Lim_mono:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2624
  fixes u :: "nat \<Rightarrow> pinfreal"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2625
  shows "u \<up> x \<longleftrightarrow> (mono u \<and> u ----> x)"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2626
proof safe
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2627
  assume "mono u" and x: "u ----> x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2628
  with SUP_Lim_pinfreal[OF _ x]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2629
  show "u \<up> x" unfolding isoton_def
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2630
    using `mono u`[unfolded mono_def]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2631
    using `mono u`[unfolded mono_iff_le_Suc]
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2632
    by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2633
qed (auto dest: isotone_Lim)
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2634
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2635
lemma pinfreal_inverse_inverse[simp]:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2636
  fixes x :: pinfreal
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2637
  shows "inverse (inverse x) = x"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2638
  by (cases x) auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2639
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2640
lemma atLeastAtMost_omega_eq_atLeast:
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2641
  shows "{a .. \<omega>} = {a ..}"
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2642
by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2643
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2644
lemma atLeast0AtMost_eq_atMost: "{0 :: pinfreal .. a} = {.. a}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2645
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2646
lemma greaterThan_omega_Empty: "{\<omega> <..} = {}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2647
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2648
lemma lessThan_0_Empty: "{..< 0 :: pinfreal} = {}" by auto
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2649
d5d342611edb Rewrite the Probability theory.
hoelzl
parents:
diff changeset
  2650
end