62375
|
1 |
(* Title: HOL/Library/Extended_Nonnegative_Real.thy
|
|
2 |
Author: Johannes Hölzl
|
|
3 |
*)
|
|
4 |
|
|
5 |
subsection \<open>The type of non-negative extended real numbers\<close>
|
|
6 |
|
|
7 |
theory Extended_Nonnegative_Real
|
|
8 |
imports Extended_Real
|
|
9 |
begin
|
|
10 |
|
|
11 |
typedef ennreal = "{x :: ereal. 0 \<le> x}"
|
|
12 |
morphisms enn2ereal e2ennreal
|
|
13 |
by auto
|
|
14 |
|
|
15 |
setup_lifting type_definition_ennreal
|
|
16 |
|
|
17 |
|
|
18 |
lift_definition ennreal :: "real \<Rightarrow> ennreal" is "max 0 \<circ> ereal"
|
|
19 |
by simp
|
|
20 |
|
|
21 |
declare [[coercion ennreal]]
|
|
22 |
declare [[coercion e2ennreal]]
|
|
23 |
|
|
24 |
instantiation ennreal :: semiring_1_no_zero_divisors
|
|
25 |
begin
|
|
26 |
|
|
27 |
lift_definition one_ennreal :: ennreal is 1 by simp
|
|
28 |
lift_definition zero_ennreal :: ennreal is 0 by simp
|
|
29 |
lift_definition plus_ennreal :: "ennreal \<Rightarrow> ennreal \<Rightarrow> ennreal" is "op +" by simp
|
|
30 |
lift_definition times_ennreal :: "ennreal \<Rightarrow> ennreal \<Rightarrow> ennreal" is "op *" by simp
|
|
31 |
|
|
32 |
instance
|
|
33 |
by standard (transfer; auto simp: field_simps ereal_right_distrib)+
|
|
34 |
|
|
35 |
end
|
|
36 |
|
|
37 |
instance ennreal :: numeral ..
|
|
38 |
|
|
39 |
instantiation ennreal :: inverse
|
|
40 |
begin
|
|
41 |
|
|
42 |
lift_definition inverse_ennreal :: "ennreal \<Rightarrow> ennreal" is inverse
|
|
43 |
by (rule inverse_ereal_ge0I)
|
|
44 |
|
|
45 |
definition divide_ennreal :: "ennreal \<Rightarrow> ennreal \<Rightarrow> ennreal"
|
|
46 |
where "x div y = x * inverse (y :: ennreal)"
|
|
47 |
|
|
48 |
instance ..
|
|
49 |
|
|
50 |
end
|
|
51 |
|
|
52 |
|
|
53 |
instantiation ennreal :: complete_linorder
|
|
54 |
begin
|
|
55 |
|
|
56 |
lift_definition top_ennreal :: ennreal is top by simp
|
|
57 |
lift_definition bot_ennreal :: ennreal is 0 by simp
|
|
58 |
lift_definition sup_ennreal :: "ennreal \<Rightarrow> ennreal \<Rightarrow> ennreal" is sup by (simp add: max.coboundedI1)
|
|
59 |
lift_definition inf_ennreal :: "ennreal \<Rightarrow> ennreal \<Rightarrow> ennreal" is inf by (simp add: min.boundedI)
|
|
60 |
|
|
61 |
lift_definition Inf_ennreal :: "ennreal set \<Rightarrow> ennreal" is "Inf"
|
|
62 |
by (auto intro: Inf_greatest)
|
|
63 |
|
|
64 |
lift_definition Sup_ennreal :: "ennreal set \<Rightarrow> ennreal" is "sup 0 \<circ> Sup"
|
|
65 |
by auto
|
|
66 |
|
|
67 |
lift_definition less_eq_ennreal :: "ennreal \<Rightarrow> ennreal \<Rightarrow> bool" is "op \<le>" .
|
|
68 |
lift_definition less_ennreal :: "ennreal \<Rightarrow> ennreal \<Rightarrow> bool" is "op <" .
|
|
69 |
|
|
70 |
instance
|
|
71 |
by standard
|
|
72 |
(transfer ; auto simp: Inf_lower Inf_greatest Sup_upper Sup_least le_max_iff_disj max.absorb1)+
|
|
73 |
|
|
74 |
end
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
lemma ennreal_zero_less_one: "0 < (1::ennreal)"
|
|
79 |
by transfer auto
|
|
80 |
|
|
81 |
instance ennreal :: ordered_comm_semiring
|
|
82 |
by standard
|
|
83 |
(transfer ; auto intro: add_mono mult_mono mult_ac ereal_left_distrib ereal_mult_left_mono)+
|
|
84 |
|
|
85 |
instantiation ennreal :: linear_continuum_topology
|
|
86 |
begin
|
|
87 |
|
|
88 |
definition open_ennreal :: "ennreal set \<Rightarrow> bool"
|
|
89 |
where "(open :: ennreal set \<Rightarrow> bool) = generate_topology (range lessThan \<union> range greaterThan)"
|
|
90 |
|
|
91 |
instance
|
|
92 |
proof
|
|
93 |
show "\<exists>a b::ennreal. a \<noteq> b"
|
|
94 |
using ennreal_zero_less_one by (auto dest: order.strict_implies_not_eq)
|
|
95 |
show "\<And>x y::ennreal. x < y \<Longrightarrow> \<exists>z>x. z < y"
|
|
96 |
proof transfer
|
|
97 |
fix x y :: ereal assume "0 \<le> x" "x < y"
|
|
98 |
moreover from dense[OF this(2)] guess z ..
|
|
99 |
ultimately show "\<exists>z\<in>Collect (op \<le> 0). x < z \<and> z < y"
|
|
100 |
by (intro bexI[of _ z]) auto
|
|
101 |
qed
|
|
102 |
qed (rule open_ennreal_def)
|
|
103 |
|
|
104 |
end
|
|
105 |
|
|
106 |
lemma ennreal_rat_dense:
|
|
107 |
fixes x y :: ennreal
|
|
108 |
shows "x < y \<Longrightarrow> \<exists>r::rat. x < real_of_rat r \<and> real_of_rat r < y"
|
|
109 |
proof transfer
|
|
110 |
fix x y :: ereal assume xy: "0 \<le> x" "0 \<le> y" "x < y"
|
|
111 |
moreover
|
|
112 |
from ereal_dense3[OF \<open>x < y\<close>]
|
|
113 |
obtain r where "x < ereal (real_of_rat r)" "ereal (real_of_rat r) < y"
|
|
114 |
by auto
|
|
115 |
moreover then have "0 \<le> r"
|
|
116 |
using le_less_trans[OF \<open>0 \<le> x\<close> \<open>x < ereal (real_of_rat r)\<close>] by auto
|
|
117 |
ultimately show "\<exists>r. x < (max 0 \<circ> ereal) (real_of_rat r) \<and> (max 0 \<circ> ereal) (real_of_rat r) < y"
|
|
118 |
by (intro exI[of _ r]) (auto simp: max_absorb2)
|
|
119 |
qed
|
|
120 |
|
|
121 |
lemma enn2ereal_range: "e2ennreal ` {0..} = UNIV"
|
|
122 |
proof -
|
|
123 |
have "\<exists>y\<ge>0. x = e2ennreal y" for x
|
|
124 |
by (cases x) auto
|
|
125 |
then show ?thesis
|
|
126 |
by (auto simp: image_iff Bex_def)
|
|
127 |
qed
|
|
128 |
|
|
129 |
lemma enn2ereal_nonneg: "0 \<le> enn2ereal x"
|
|
130 |
using ennreal.enn2ereal[of x] by simp
|
|
131 |
|
|
132 |
lemma ereal_ennreal_cases:
|
|
133 |
obtains b where "0 \<le> a" "a = enn2ereal b" | "a < 0"
|
|
134 |
using e2ennreal_inverse[of a, symmetric] by (cases "0 \<le> a") (auto intro: enn2ereal_nonneg)
|
|
135 |
|
|
136 |
lemma enn2ereal_Iio: "enn2ereal -` {..<a} = (if 0 \<le> a then {..< e2ennreal a} else {})"
|
|
137 |
using enn2ereal_nonneg
|
|
138 |
by (cases a rule: ereal_ennreal_cases)
|
|
139 |
(auto simp add: vimage_def set_eq_iff ennreal.enn2ereal_inverse less_ennreal.rep_eq
|
|
140 |
intro: le_less_trans less_imp_le)
|
|
141 |
|
|
142 |
lemma enn2ereal_Ioi: "enn2ereal -` {a <..} = (if 0 \<le> a then {e2ennreal a <..} else UNIV)"
|
|
143 |
using enn2ereal_nonneg
|
|
144 |
by (cases a rule: ereal_ennreal_cases)
|
|
145 |
(auto simp add: vimage_def set_eq_iff ennreal.enn2ereal_inverse less_ennreal.rep_eq
|
|
146 |
intro: less_le_trans)
|
|
147 |
|
|
148 |
lemma continuous_e2ennreal: "continuous_on {0 ..} e2ennreal"
|
|
149 |
by (rule continuous_onI_mono)
|
|
150 |
(auto simp add: less_eq_ennreal.abs_eq eq_onp_def enn2ereal_range)
|
|
151 |
|
|
152 |
lemma continuous_enn2ereal: "continuous_on UNIV enn2ereal"
|
|
153 |
by (rule continuous_on_generate_topology[OF open_generated_order])
|
|
154 |
(auto simp add: enn2ereal_Iio enn2ereal_Ioi)
|
|
155 |
|
|
156 |
lemma transfer_enn2ereal_continuous_on [transfer_rule]:
|
|
157 |
"rel_fun (op =) (rel_fun (rel_fun op = pcr_ennreal) op =) continuous_on continuous_on"
|
|
158 |
proof -
|
|
159 |
have "continuous_on A f" if "continuous_on A (\<lambda>x. enn2ereal (f x))" for A and f :: "'a \<Rightarrow> ennreal"
|
|
160 |
using continuous_on_compose2[OF continuous_e2ennreal that]
|
|
161 |
by (auto simp: ennreal.enn2ereal_inverse subset_eq enn2ereal_nonneg)
|
|
162 |
moreover
|
|
163 |
have "continuous_on A (\<lambda>x. enn2ereal (f x))" if "continuous_on A f" for A and f :: "'a \<Rightarrow> ennreal"
|
|
164 |
using continuous_on_compose2[OF continuous_enn2ereal that] by auto
|
|
165 |
ultimately
|
|
166 |
show ?thesis
|
|
167 |
by (auto simp add: rel_fun_def ennreal.pcr_cr_eq cr_ennreal_def)
|
|
168 |
qed
|
|
169 |
|
|
170 |
lemma continuous_on_add_ennreal[continuous_intros]:
|
|
171 |
fixes f g :: "'a::topological_space \<Rightarrow> ennreal"
|
|
172 |
shows "continuous_on A f \<Longrightarrow> continuous_on A g \<Longrightarrow> continuous_on A (\<lambda>x. f x + g x)"
|
|
173 |
by (transfer fixing: A) (auto intro!: tendsto_add_ereal_nonneg simp: continuous_on_def)
|
|
174 |
|
|
175 |
lemma continuous_on_inverse_ennreal[continuous_intros]:
|
|
176 |
fixes f :: "_ \<Rightarrow> ennreal"
|
|
177 |
shows "continuous_on A f \<Longrightarrow> continuous_on A (\<lambda>x. inverse (f x))"
|
|
178 |
proof (transfer fixing: A)
|
|
179 |
show "pred_fun (op \<le> 0) f \<Longrightarrow> continuous_on A (\<lambda>x. inverse (f x))" if "continuous_on A f"
|
|
180 |
for f :: "_ \<Rightarrow> ereal"
|
|
181 |
using continuous_on_compose2[OF continuous_on_inverse_ereal that] by (auto simp: subset_eq)
|
|
182 |
qed
|
|
183 |
|
|
184 |
end
|