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