borelScript.sml

1(* ------------------------------------------------------------------------- *)
2(* Borel Space and Borel-measurable functions                                *)
3(* Authors: Tarek Mhamdi, Osman Hasan, Sofiene Tahar (2013) [2]              *)
4(* HVG Group, Concordia University, Montreal                                 *)
5(* ------------------------------------------------------------------------- *)
6(* Based on the work of Aaron Coble [3] (2010)                               *)
7(* Cambridge University                                                      *)
8(* ------------------------------------------------------------------------- *)
9(* Construction of one-dimensional household Borel measure space (lborel)    *)
10(*                                                                           *)
11(* Author: Chun Tian (binghe) <binghe.lisp@gmail.com> (2019 - 2021)          *)
12(* Fondazione Bruno Kessler and University of Trento, Italy                  *)
13(* ------------------------------------------------------------------------- *)
14
15Theory borel
16Ancestors
17  prim_rec arithmetic combin res_quan pair pred_set relation real
18  seq transc real_sigma topology real_topology list metric extreal
19  sigma_algebra iterate real_borel measure
20Libs
21  numLib res_quanTools pred_setLib realLib RealArith hurdUtils
22
23val ASM_ARITH_TAC = rpt (POP_ASSUM MP_TAC) >> ARITH_TAC; (* numLib *)
24val DISC_RW_KILL = DISCH_TAC >> ONCE_ASM_REWRITE_TAC [] >> POP_ASSUM K_TAC;
25fun METIS ths tm = prove(tm, METIS_TAC ths);
26
27val set_ss = std_ss ++ PRED_SET_ss;
28
29val _ = hide "S";
30
31val _ = intLib.deprecate_int ();
32val _ = ratLib.deprecate_rat ();
33
34(* ************************************************************************* *)
35(*    Borel Space and Measurable functions                                   *)
36(* ************************************************************************* *)
37
38(* This is the (extreal-valued) Borel set. See ‘real_borel$borel’ for reals.
39
40   Named after Emile Borel [7], a French mathematician and politician.
41
42   See martingaleTheory for 2-dimensional Borel space based on pairTheory
43   (term: ‘Borel CROSS Borel’).
44
45   See examples/probability/stochastic_processesTheory for n-dimensional Borel
46   spaces based on fcpTheory (term: ‘Borel of_dimension(:'N)’).
47
48   See "Borel_def" for the old definition.
49
50   Below is the new definition according to [1, p.61]:
51 *)
52Definition Borel :
53    Borel = (univ(:extreal),
54             {B' | ?B S. B' = (IMAGE Normal B) UNION S /\ B IN subsets borel /\
55                         S IN {EMPTY; {NegInf}; {PosInf}; {NegInf; PosInf}}})
56End
57
58(* MATHEMATICAL DOUBLE-STRUCK CAPITAL B
59val _ = Unicode.unicode_version {u = UTF8.chr 0x1D539, tmnm = "Borel"};
60val _ = TeX_notation {hol = "Borel", TeX = ("\\ensuremath{{\\cal{B}}}", 1)};
61 *)
62
63(* for compatibility and abbreviation purposes *)
64Overload Borel_measurable = “\a. measurable a Borel”;
65
66(* Lemma 8.2 [1, p.61], another equivalent definition of ‘borel’ *)
67Theorem borel_eq_real_set :
68    borel = (univ(:real), IMAGE real_set (subsets Borel))
69Proof
70    REWRITE_TAC [Once (SYM (Q.ISPEC ‘borel’ SPACE)), space_borel]
71 >> Suff ‘IMAGE real_set (subsets Borel) = subsets borel’ >- rw []
72 >> rw [Borel, Once EXTENSION, IN_IMAGE, real_set_def]
73 >> EQ_TAC >> rw [] (* 5 subgoals *)
74 >| [ (* goal 1 (of 5) *)
75      REWRITE_TAC [UNION_EMPTY] \\
76      Suff ‘{real x | x <> PosInf /\ x <> NegInf /\ x IN IMAGE Normal B} = B’
77      >- rw [] \\
78      rw [Once EXTENSION] >> EQ_TAC >> rw [] >- art [real_normal] \\
79      Q.EXISTS_TAC ‘Normal x’ >> rw [extreal_not_infty, real_normal],
80      (* goal 2 (of 5) *)
81      Suff ‘{real x | x <> PosInf /\ x <> NegInf /\
82            x IN IMAGE Normal B UNION {NegInf}} = B’ >- rw [] \\
83      rw [Once EXTENSION] >> EQ_TAC >> rw [] >- art [real_normal] \\
84      Q.EXISTS_TAC ‘Normal x’ >> rw [extreal_not_infty, real_normal],
85      (* goal 3 (of 5) *)
86      Suff ‘{real x | x <> PosInf /\ x <> NegInf /\
87             x IN IMAGE Normal B UNION {PosInf}} = B’ >- rw [] \\
88      rw [Once EXTENSION] >> EQ_TAC >> rw [] >- art [real_normal] \\
89      Q.EXISTS_TAC ‘Normal x’ >> rw [extreal_not_infty, real_normal],
90      (* goal 4 (of 5) *)
91      Suff ‘{real x | x <> PosInf /\ x <> NegInf /\
92                      x IN IMAGE Normal B UNION {NegInf; PosInf}} = B’ >- rw [] \\
93      rw [Once EXTENSION] >> EQ_TAC >> rw [] >- art [real_normal] \\
94      Q.EXISTS_TAC ‘Normal x’ >> rw [extreal_not_infty, real_normal],
95      (* goal 5 (of 5) *)
96      Q.EXISTS_TAC ‘IMAGE Normal x’ \\
97      CONJ_TAC
98      >- (Suff ‘{real y | y <> PosInf /\ y <> NegInf /\ y IN IMAGE Normal x} = x’
99          >- rw [] \\
100          rw [Once EXTENSION] >> EQ_TAC >> rw [] >- art [real_normal] \\
101          rename1 ‘y IN A’ \\
102          Q.EXISTS_TAC ‘Normal y’ >> rw [extreal_not_infty, real_normal]) \\
103      qexistsl_tac [‘x’, ‘EMPTY’] >> rw [] ]
104QED
105
106Theorem borel_measurable_real_set :
107    !s. s IN subsets Borel ==> real_set s IN subsets borel
108Proof
109    rw [borel_eq_real_set]
110QED
111
112Theorem SPACE_BOREL :
113    space Borel = UNIV
114Proof
115    rw [Borel]
116QED
117
118local (* small tactics for the last 16 subgoals *)
119  val t_none =
120      qexistsl_tac [‘B UNION B'’, ‘{}’] >> simp [] \\
121      MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [];
122  val t_neg =
123      qexistsl_tac [‘B UNION B'’, ‘{NegInf}’] >> simp [] \\
124      reverse CONJ_TAC >- (MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []) \\
125      rw [Once EXTENSION] >> METIS_TAC [];
126  val t_pos =
127      qexistsl_tac [‘B UNION B'’, ‘{PosInf}’] >> simp [] \\
128      reverse CONJ_TAC >- (MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []) \\
129      rw [Once EXTENSION] >> METIS_TAC [];
130  val t_both =
131      qexistsl_tac [‘B UNION B'’, ‘{NegInf; PosInf}’] >> simp [] \\
132      reverse CONJ_TAC >- (MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []) \\
133      rw [Once EXTENSION] >> METIS_TAC [];
134in
135Theorem SIGMA_ALGEBRA_BOREL :
136    sigma_algebra Borel
137Proof
138    reverse (rw [Borel, SIGMA_ALGEBRA_ALT, IN_FUNSET, SUBSET_DEF])
139 >- (fs [SKOLEM_THM] \\
140     qexistsl_tac [‘BIGUNION (IMAGE f' UNIV)’, ‘BIGUNION (IMAGE f'' UNIV)’] \\
141     CONJ_TAC >- (rw [Once EXTENSION, IN_BIGUNION_IMAGE] >> METIS_TAC []) \\
142     reverse CONJ_TAC
143     >- (rename1 ‘BIGUNION (IMAGE g univ(:num)) = {} \/ _’ \\
144         Cases_on ‘!n. g n = {}’
145         >- (DISJ1_TAC >> rw [Once EXTENSION, NOT_IN_EMPTY, IN_BIGUNION_IMAGE]) \\
146         DISJ2_TAC \\
147         Cases_on ‘!n. PosInf NOTIN (g n)’
148         >- (DISJ1_TAC >> rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
149             EQ_TAC >> rw [] >- ASM_SET_TAC [] \\
150             fs [] >> Q.EXISTS_TAC ‘n’ >> ASM_SET_TAC []) \\
151         DISJ2_TAC \\
152         Cases_on ‘!n. NegInf NOTIN (g n)’
153         >- (DISJ1_TAC >> rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
154             EQ_TAC >> rw [] >- ASM_SET_TAC [] \\
155             fs [] >> Q.EXISTS_TAC ‘n’ >> ASM_SET_TAC []) \\
156         DISJ2_TAC \\
157         fs [] >> rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
158         EQ_TAC >> rw [] >> ASM_SET_TAC []) \\
159     MP_TAC sigma_algebra_borel \\
160     rw [SIGMA_ALGEBRA_FN, IN_FUNSET])
161 (* algebra Borel *)
162 >> SIMP_TAC std_ss [algebra_def, subset_class_def, space_def, subsets_def,
163                     GSPECIFICATION, SUBSET_UNIV]
164 >> ASSUME_TAC sigma_algebra_borel
165 (* 1st group *)
166 >> CONJ_TAC
167 >- (qexistsl_tac [‘{}’, ‘{}’] >> rw [] \\
168     MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY >> art [])
169 (* 2nd group *)
170 >> CONJ_TAC
171 >- (Q.X_GEN_TAC ‘A’ \\
172     DISCH_THEN (qx_choosel_then [‘B’, ‘S’] STRIP_ASSUME_TAC) >| (* 4 subgoals *)
173     [ (* goal 1 (of 4) *)
174       POP_ASSUM (fs o wrap) \\
175       qexistsl_tac [‘UNIV DIFF B’, ‘{NegInf; PosInf}’] >> simp [] \\
176       reverse CONJ_TAC >- METIS_TAC [SIGMA_ALGEBRA_COMPL, space_borel] \\
177       rw [Once EXTENSION] >> EQ_TAC >> rw [] >- METIS_TAC [extreal_cases] \\
178       PROVE_TAC [],
179       (* goal 2 (of 4) *)
180       POP_ASSUM (fs o wrap) \\
181       qexistsl_tac [‘UNIV DIFF B’, ‘{PosInf}’] >> simp [] \\
182       reverse CONJ_TAC >- METIS_TAC [SIGMA_ALGEBRA_COMPL, space_borel] \\
183       rw [Once EXTENSION] >> EQ_TAC >> rw [] >- METIS_TAC [extreal_cases] \\
184       PROVE_TAC [],
185       (* goal 3 (of 4) *)
186       POP_ASSUM (fs o wrap) \\
187       qexistsl_tac [‘UNIV DIFF B’, ‘{NegInf}’] >> simp [] \\
188       reverse CONJ_TAC >- METIS_TAC [SIGMA_ALGEBRA_COMPL, space_borel] \\
189       rw [Once EXTENSION] >> EQ_TAC >> rw [] >- METIS_TAC [extreal_cases] \\
190       PROVE_TAC [],
191       (* goal 3 (of 4) *)
192       POP_ASSUM (fs o wrap) \\
193       qexistsl_tac [‘UNIV DIFF B’, ‘{}’] >> simp [] \\
194       reverse CONJ_TAC >- METIS_TAC [SIGMA_ALGEBRA_COMPL, space_borel] \\
195       rw [Once EXTENSION] >> EQ_TAC >> rw [] >- METIS_TAC [extreal_cases] \\
196       PROVE_TAC [] ])
197 (* 3rd group *)
198 >> rw [] (* 16 subgoals *)
199 >| [ t_none, t_neg,  t_pos, t_both, t_neg,  t_neg,  t_both, t_both,
200      t_pos,  t_both, t_pos, t_both, t_both, t_both, t_both, t_both ]
201QED
202end (* local env for SIGMA_ALGEBRA_BOREL *)
203
204(* The old definition of ‘Borel’ now becomes a theorem (alternative definition),
205   cf. borel_eq_less
206
207   The proof follows Lemma 8.3 [1, p.61]
208 *)
209
210(* shared by Borel_def and Borel_eq_ge *)
211val early_tactics =
212 (* preparing for SIGMA_ALGEBRA_RESTRICT *)
213    Q.ABBREV_TAC ‘R = IMAGE Normal UNIV’ (* the set of all normal extreals *)
214 >> Know ‘R IN S’
215 >- (Know ‘R = BIGUNION (IMAGE (\n. {x | Normal (-&n) <= x /\ x < Normal (&n)}) UNIV)’
216     >- (Q.UNABBREV_TAC ‘R’ >> rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
217         reverse EQ_TAC >> rw []
218         >- (Q.EXISTS_TAC ‘real x’ >> ONCE_REWRITE_TAC [EQ_SYM_EQ] \\
219             MATCH_MP_TAC normal_real >> REWRITE_TAC [lt_infty] \\
220             CONJ_TAC >| (* 2 subgoals *)
221             [ (* goal 1 (of 2) *)
222               MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC ‘Normal (-&n)’ >> art [lt_infty],
223               (* goal 2 (of 2) *)
224               MATCH_MP_TAC lt_trans >> Q.EXISTS_TAC ‘Normal (&n)’ >> art [lt_infty] ]) \\
225         STRIP_ASSUME_TAC (Q.SPEC ‘x'’ SIMP_REAL_ARCH) \\
226         rename1 ‘y <= &m’ \\
227         STRIP_ASSUME_TAC (Q.SPEC ‘y’ SIMP_REAL_ARCH_NEG) \\
228         Q.EXISTS_TAC ‘MAX (SUC m) n’ >> rw [extreal_lt_eq, extreal_le_eq] >|
229         [ (* goal 1 (of 2) *)
230           MATCH_MP_TAC REAL_LE_TRANS >> Q.EXISTS_TAC ‘-&n’ >> rw [],
231           (* goal 2 (of 2) *)
232           MATCH_MP_TAC REAL_LET_TRANS >> Q.EXISTS_TAC ‘&m’ >> rw [] ]) >> Rewr' \\
233     fs [SIGMA_ALGEBRA_FN, IN_FUNSET, SPACE_SIGMA, Abbr ‘S’])
234 >> DISCH_TAC;
235
236(* shared by Borel_eq_le and Borel_eq_gr *)
237val early_tactics' =
238 (* preparing for SIGMA_ALGEBRA_RESTRICT *)
239    Q.ABBREV_TAC ‘R = IMAGE Normal UNIV’ (* the set of all normal extreals *)
240 >> Know ‘R IN S’
241 >- (Know ‘R = BIGUNION (IMAGE (\n. {x | Normal (-&n) < x /\ x <= Normal (&n)}) UNIV)’
242     >- (Q.UNABBREV_TAC ‘R’ >> rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
243         reverse EQ_TAC >> rw []
244         >- (Q.EXISTS_TAC ‘real x’ >> ONCE_REWRITE_TAC [EQ_SYM_EQ] \\
245             MATCH_MP_TAC normal_real >> REWRITE_TAC [lt_infty] \\
246             CONJ_TAC >| (* 2 subgoals *)
247             [ (* goal 1 (of 2) *)
248               MATCH_MP_TAC lt_trans >> Q.EXISTS_TAC ‘Normal (-&n)’ >> art [lt_infty],
249               (* goal 2 (of 2) *)
250               MATCH_MP_TAC let_trans >> Q.EXISTS_TAC ‘Normal (&n)’ >> art [lt_infty] ]) \\
251         STRIP_ASSUME_TAC (Q.SPEC ‘x'’ SIMP_REAL_ARCH) \\
252         rename1 ‘y <= &m’ \\
253         STRIP_ASSUME_TAC (Q.SPEC ‘y’ SIMP_REAL_ARCH_NEG) \\
254         Q.EXISTS_TAC ‘MAX (SUC n) m’ >> rw [extreal_lt_eq, extreal_le_eq] >|
255         [ (* goal 1 (of 2) *)
256           MATCH_MP_TAC REAL_LTE_TRANS >> Q.EXISTS_TAC ‘-&n’ >> rw [],
257           (* goal 2 (of 2) *)
258           MATCH_MP_TAC REAL_LE_TRANS >> Q.EXISTS_TAC ‘&m’ >> rw [] ]) >> Rewr' \\
259     fs [SIGMA_ALGEBRA_FN, IN_FUNSET, SPACE_SIGMA, Abbr ‘S’])
260 >> DISCH_TAC;
261
262(* shared by Borel_def and Borel_eq_ge *)
263val middle_tactics =
264 (* applying PREIMAGE_SIGMA_ALGEBRA *)
265    Know ‘sigma_algebra (UNIV, IMAGE (\s. PREIMAGE Normal s INTER UNIV)
266                                     (subsets (R,IMAGE (\s. s INTER R) S)))’
267 >- (MATCH_MP_TAC PREIMAGE_SIGMA_ALGEBRA >> rw [IN_FUNSET, Abbr ‘R’])
268 >> REWRITE_TAC [INTER_UNIV, subsets_def, IMAGE_IMAGE]
269 >> ‘((\s. PREIMAGE Normal s) o (\s. s INTER R)) = real_set’
270       by rw [FUN_EQ_THM, Abbr ‘R’, normal_real_set, o_DEF, IN_APP] >> POP_ORW
271 >> DISCH_TAC
272 (* preparing for SIGMA_SUBSET *)
273 >> Know ‘!a b. a <= b ==> {x | a <= x /\ x < b} IN IMAGE real_set S’
274 >- (rw [real_set_def] \\
275     Q.EXISTS_TAC ‘{x | Normal a <= x /\ x < Normal b}’ \\
276     reverse CONJ_TAC >- (FIRST_X_ASSUM MATCH_MP_TAC >> art []) \\
277     rw [Once EXTENSION] \\
278     EQ_TAC >> rw [] >| (* 3 subgoals *)
279     [ (* goal 1 (of 3) *)
280       Q.EXISTS_TAC ‘Normal x’ \\
281       rw [extreal_not_infty, real_normal, extreal_lt_eq, extreal_le_eq],
282       (* goal 2 (of 3) *)
283       rename1 ‘a <= real y’ >> REWRITE_TAC [GSYM extreal_le_eq] \\
284       Suff ‘Normal (real y) = y’ >- RW_TAC std_ss [] \\
285       MATCH_MP_TAC normal_real >> art [],
286       (* goal 3 (of 3) *)
287       rename1 ‘real y < b’ >> REWRITE_TAC [GSYM extreal_lt_eq] \\
288       Suff ‘Normal (real y) = y’ >- RW_TAC std_ss [] \\
289       MATCH_MP_TAC normal_real >> art [] ])
290 >> DISCH_TAC
291 (* applying SIGMA_SUBSET *)
292 >> Know ‘subsets (sigma UNIV (IMAGE (\(a,b). {x | a <= x /\ x < b}) UNIV))
293          SUBSET (IMAGE real_set S)’
294 >- (MATCH_MP_TAC
295       (REWRITE_RULE [space_def, subsets_def]
296         (Q.ISPECL [‘IMAGE (\(a,b). {x | a <= x /\ x < b}) univ(:real # real)’,
297                    ‘(univ(:real),IMAGE real_set S)’] SIGMA_SUBSET)) \\
298     simp [SUBSET_DEF, IN_IMAGE, IN_UNIV, real_set_def] \\
299     Q.X_GEN_TAC ‘z’ \\
300     DISCH_THEN (Q.X_CHOOSE_THEN ‘y’ MP_TAC) \\
301     Cases_on ‘y’ >> rw [] \\
302     Cases_on ‘q <= r’
303     >- (Q.EXISTS_TAC ‘{x | Normal q <= x /\ x < Normal r}’ \\
304         reverse CONJ_TAC >- (FIRST_X_ASSUM MATCH_MP_TAC >> art []) \\
305         rw [Once EXTENSION] \\
306         EQ_TAC >> rw [] >| (* 3 subgoals *)
307         [ (* goal 1 (of 3) *)
308           Q.EXISTS_TAC ‘Normal x’ \\
309           rw [extreal_not_infty, real_normal, extreal_lt_eq, extreal_le_eq],
310           (* goal 2 (of 3) *)
311           rename1 ‘a <= real y’ >> REWRITE_TAC [GSYM extreal_le_eq] \\
312           Suff ‘Normal (real y) = y’ >- RW_TAC std_ss [] \\
313           MATCH_MP_TAC normal_real >> art [],
314           (* goal 3 (of 3) *)
315           rename1 ‘real y < b’ >> REWRITE_TAC [GSYM extreal_lt_eq] \\
316           Suff ‘Normal (real y) = y’ >- RW_TAC std_ss [] \\
317           MATCH_MP_TAC normal_real >> art [] ]) \\
318     Know ‘{x | q <= x /\ x < r} = {}’
319     >- (rw [Once EXTENSION, NOT_IN_EMPTY] \\
320         ONCE_REWRITE_TAC [DISJ_COMM] >> STRONG_DISJ_TAC \\
321        ‘r < q’ by METIS_TAC [real_lt] \\
322         REWRITE_TAC [GSYM real_lt] \\
323         MATCH_MP_TAC REAL_LT_TRANS >> Q.EXISTS_TAC ‘r’ >> art []) >> Rewr' \\
324     Q.EXISTS_TAC ‘{}’ \\
325     reverse CONJ_TAC
326     >- (Q.UNABBREV_TAC ‘S’ \\
327         MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY >> art []) \\
328     rw [NOT_IN_EMPTY, Once EXTENSION])
329 >> REWRITE_TAC [GSYM borel_eq_ge_less] (* key step *)
330 >> DISCH_TAC;
331
332(* shared by Borel_eq_le and Borel_eq_gr *)
333val middle_tactics' =
334 (* applying PREIMAGE_SIGMA_ALGEBRA *)
335    Know ‘sigma_algebra (UNIV, IMAGE (\s. PREIMAGE Normal s INTER UNIV)
336                                     (subsets (R,IMAGE (\s. s INTER R) S)))’
337 >- (MATCH_MP_TAC PREIMAGE_SIGMA_ALGEBRA >> rw [IN_FUNSET, Abbr ‘R’])
338 >> REWRITE_TAC [INTER_UNIV, subsets_def, IMAGE_IMAGE]
339 >> ‘((\s. PREIMAGE Normal s) o (\s. s INTER R)) = real_set’
340       by rw [FUN_EQ_THM, Abbr ‘R’, normal_real_set, o_DEF, IN_APP] >> POP_ORW
341 >> DISCH_TAC
342 (* preparing for SIGMA_SUBSET *)
343 >> Know ‘!a b. a <= b ==> {x | a < x /\ x <= b} IN IMAGE real_set S’
344 >- (rw [real_set_def] \\
345     Q.EXISTS_TAC ‘{x | Normal a < x /\ x <= Normal b}’ \\
346     reverse CONJ_TAC >- (FIRST_X_ASSUM MATCH_MP_TAC >> art []) \\
347     rw [Once EXTENSION] \\
348     EQ_TAC >> rw [] >| (* 3 subgoals *)
349     [ (* goal 1 (of 3) *)
350       Q.EXISTS_TAC ‘Normal x’ \\
351       rw [extreal_not_infty, real_normal, extreal_lt_eq, extreal_le_eq],
352       (* goal 2 (of 3) *)
353       rename1 ‘a < real y’ >> REWRITE_TAC [GSYM extreal_lt_eq] \\
354       Suff ‘Normal (real y) = y’ >- RW_TAC std_ss [] \\
355       MATCH_MP_TAC normal_real >> art [],
356       (* goal 3 (of 3) *)
357       rename1 ‘real y <= b’ >> REWRITE_TAC [GSYM extreal_le_eq] \\
358       Suff ‘Normal (real y) = y’ >- RW_TAC std_ss [] \\
359       MATCH_MP_TAC normal_real >> art [] ])
360 >> DISCH_TAC
361 (* applying SIGMA_SUBSET *)
362 >> Know ‘subsets (sigma UNIV (IMAGE (\(a,b). {x | a < x /\ x <= b}) UNIV))
363          SUBSET (IMAGE real_set S)’
364 >- (MATCH_MP_TAC
365       (REWRITE_RULE [space_def, subsets_def]
366         (Q.ISPECL [‘IMAGE (\(a,b). {x | a < x /\ x <= b}) univ(:real # real)’,
367                    ‘(univ(:real),IMAGE real_set S)’] SIGMA_SUBSET)) \\
368     simp [SUBSET_DEF, IN_IMAGE, IN_UNIV, real_set_def] \\
369     Q.X_GEN_TAC ‘z’ \\
370     DISCH_THEN (Q.X_CHOOSE_THEN ‘y’ MP_TAC) \\
371     Cases_on ‘y’ >> rw [] \\
372     Cases_on ‘q <= r’
373     >- (Q.EXISTS_TAC ‘{x | Normal q < x /\ x <= Normal r}’ \\
374         reverse CONJ_TAC >- (FIRST_X_ASSUM MATCH_MP_TAC >> art []) \\
375         rw [Once EXTENSION] \\
376         EQ_TAC >> rw [] >| (* 3 subgoals *)
377         [ (* goal 1 (of 3) *)
378           Q.EXISTS_TAC ‘Normal x’ \\
379           rw [extreal_not_infty, real_normal, extreal_lt_eq, extreal_le_eq],
380           (* goal 2 (of 3) *)
381           rename1 ‘q < real y’ >> REWRITE_TAC [GSYM extreal_lt_eq] \\
382           Suff ‘Normal (real y) = y’ >- RW_TAC std_ss [] \\
383           MATCH_MP_TAC normal_real >> art [],
384           (* goal 3 (of 3) *)
385           rename1 ‘real y <= r’ >> REWRITE_TAC [GSYM extreal_le_eq] \\
386           Suff ‘Normal (real y) = y’ >- RW_TAC std_ss [] \\
387           MATCH_MP_TAC normal_real >> art [] ]) \\
388     Know ‘{x | q < x /\ x <= r} = {}’
389     >- (rw [Once EXTENSION, NOT_IN_EMPTY] \\
390         ONCE_REWRITE_TAC [DISJ_COMM] >> STRONG_DISJ_TAC \\
391        ‘r < q’ by METIS_TAC [real_lt] \\
392         REWRITE_TAC [real_lt] \\
393         MATCH_MP_TAC REAL_LT_IMP_LE \\
394         MATCH_MP_TAC REAL_LET_TRANS >> Q.EXISTS_TAC ‘r’ >> art []) >> Rewr' \\
395     Q.EXISTS_TAC ‘{}’ \\
396     reverse CONJ_TAC
397     >- (Q.UNABBREV_TAC ‘S’ \\
398         MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY >> art []) \\
399     rw [NOT_IN_EMPTY, Once EXTENSION])
400 >> REWRITE_TAC [GSYM borel_eq_gr_le] (* key step *)
401 >> DISCH_TAC;
402
403val final_tactics = (* shared by all four Borel_eq theorems *)
404    Know ‘IMAGE Normal B IN S’
405 >- (Suff ‘IMAGE Normal B IN IMAGE (\s. s INTER R) S’
406     >- (Suff ‘IMAGE (\s. s INTER R) S SUBSET S’ >- METIS_TAC [SUBSET_DEF] \\
407         Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
408         rw [SUBSET_DEF, Abbr ‘S’] \\
409         MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []) \\
410     Q.PAT_X_ASSUM ‘subsets borel SUBSET IMAGE real_set S’ MP_TAC \\
411     Know ‘B IN subsets borel’ >- rw [] \\
412     Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
413     rw [SUBSET_DEF, real_set_def] \\
414     POP_ASSUM (MP_TAC o (Q.SPEC ‘B’)) >> RW_TAC std_ss [] \\
415     rename1 ‘s IN S’ >> Q.EXISTS_TAC ‘s’ >> art [] \\
416     rw [Once EXTENSION] \\
417     EQ_TAC >> rw [] >| (* 3 subgoals *)
418     [ (* goal 1 (of 3) *)
419       METIS_TAC [normal_real],
420       (* goal 2 (of 3) *)
421       Q.UNABBREV_TAC ‘R’ >> rw [],
422       (* goal 3 (of 3) *)
423       POP_ASSUM MP_TAC >> rw [Abbr ‘R’] \\
424       rename1 ‘Normal r IN s’ \\
425       Q.EXISTS_TAC ‘Normal r’ >> rw [real_normal, extreal_not_infty] ])
426 >> DISCH_TAC
427 >> fs [] (* 3 subgoals *)
428 >| [ (* goal 1 (of 3) *)
429      Q.UNABBREV_TAC ‘S’ \\
430      MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [],
431      (* goal 2 (of 3) *)
432      Q.UNABBREV_TAC ‘S’ \\
433      MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [],
434      (* goal 3 (of 3) *)
435      Q.UNABBREV_TAC ‘S’ \\
436      MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
437     ‘{NegInf; PosInf} = {NegInf} UNION {PosInf}’ by SET_TAC [] >> POP_ORW \\
438      MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] ];
439
440(* The original definition of Borel now becomes a theorem *)
441Theorem Borel_def :
442    Borel = sigma univ(:extreal) (IMAGE (\a. {x | x < Normal a}) univ(:real))
443Proof
444    Suff ‘subsets (sigma UNIV (IMAGE (\a. {x | x < Normal a}) UNIV)) = subsets Borel’
445 >- METIS_TAC [SPACE, SPACE_BOREL, SPACE_SIGMA]
446 >> Q.ABBREV_TAC ‘S = subsets (sigma UNIV (IMAGE (\a. {x | x < Normal a}) UNIV))’
447 >> Know ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | x < Normal a}) UNIV))’
448 >- (MATCH_MP_TAC SIGMA_ALGEBRA_SIGMA >> rw [subset_class_def])
449 >> DISCH_TAC
450 >> MATCH_MP_TAC SUBSET_ANTISYM
451 (* easy part *)
452 >> CONJ_TAC
453 >- (Q.UNABBREV_TAC ‘S’ \\
454     MATCH_MP_TAC (REWRITE_RULE [SPACE_BOREL]
455                                (Q.ISPECL [‘IMAGE (\a. {x | x < Normal a}) UNIV’, ‘Borel’]
456                                          SIGMA_SUBSET)) \\
457     REWRITE_TAC [SIGMA_ALGEBRA_BOREL] \\
458     rw [SUBSET_DEF, IN_IMAGE, Borel] \\
459     qexistsl_tac [‘{y | y < a}’, ‘{NegInf}’] \\
460     CONJ_TAC
461     >- (rw [Once EXTENSION, IN_IMAGE, IN_UNIV] \\
462         EQ_TAC >> rw [] >| (* 3 subgoals *)
463         [ (* goal 1 (of 3) *)
464           Cases_on ‘x = NegInf’ >- rw [] >> DISJ1_TAC \\
465           Know ‘x <> PosInf’
466           >- (REWRITE_TAC [lt_infty] \\
467               MATCH_MP_TAC lt_trans >> Q.EXISTS_TAC ‘Normal a’ >> art [lt_infty]) \\
468           DISCH_TAC >> ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] \\
469           Q.EXISTS_TAC ‘r’ >> fs [extreal_lt_eq],
470           (* goal 2 (of 3) *)
471           rw [extreal_lt_eq],
472           (* goal 3 (of 3) *)
473           REWRITE_TAC [lt_infty] ]) \\
474     reverse CONJ_TAC >- rw [] \\
475     REWRITE_TAC [borel_measurable_sets_less])
476 (* more properties of S *)
477 >> Know ‘!a b. a <= b ==> {x | Normal a <= x /\ x < Normal b} IN S’
478 >- (rpt STRIP_TAC \\
479    ‘{x | Normal a <= x /\ x < Normal b} =
480     {x | x < Normal b} DIFF {x | x < Normal a}’ by SET_TAC [extreal_lt_def] >> POP_ORW \\
481     Q.UNABBREV_TAC ‘S’ \\
482     MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> art [] \\
483     CONJ_TAC >| (* 2 subgoals *)
484     [ (* goal 1 (of 2) *)
485       Suff ‘{x | x < Normal b} IN (IMAGE (\a. {x | x < Normal a}) UNIV)’
486       >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
487       rw [IN_IMAGE] >> Q.EXISTS_TAC ‘b’ >> rw [],
488       (* goal 2 (of 2) *)
489       Suff ‘{x | x < Normal a} IN (IMAGE (\a. {x | x < Normal a}) UNIV)’
490       >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
491       rw [IN_IMAGE] >> Q.EXISTS_TAC ‘a’ >> rw [] ]) >> DISCH_TAC
492 (* adding new assumptions:
493    3.  Abbrev (R = IMAGE Normal univ(:real))
494    4.  R IN S
495  *)
496 >> early_tactics
497 (* applying SIGMA_ALGEBRA_RESTRICT *)
498 >> Know ‘sigma_algebra (R,IMAGE (\s. s INTER R) S)’
499 >- (MATCH_MP_TAC SIGMA_ALGEBRA_RESTRICT >> art [] \\
500     Q.EXISTS_TAC ‘space (sigma UNIV (IMAGE (\a. {x | x < Normal a}) UNIV))’ \\
501     rw [Abbr ‘S’, SPACE])
502 >> DISCH_TAC
503 (* adding new assumptions:
504    6.  sigma_algebra (univ(:real),IMAGE real_set S)
505    7.  !a b. a <= b ==> {x | a <= x /\ x < b} IN IMAGE real_set S
506    8.  subsets borel SUBSET IMAGE real_set S
507  *)
508 >> middle_tactics
509 (* stage work *)
510 >> simp [SUBSET_DEF, Borel]
511 >> GEN_TAC >> DISCH_THEN (qx_choosel_then [‘B’,‘X’] ASSUME_TAC)
512 >> ‘x = IMAGE Normal B UNION X’ by PROVE_TAC [] >> POP_ORW
513 >> Know ‘{NegInf} IN S’
514 >- (Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
515     Know ‘{NegInf} = BIGINTER (IMAGE (\n. {x | x < Normal (-&n)}) UNIV)’
516     >- (rw [Once EXTENSION, IN_BIGINTER_IMAGE] \\
517         EQ_TAC >- METIS_TAC [num_not_infty,lt_infty,extreal_ainv_def,extreal_of_num_def] \\
518         RW_TAC std_ss [] \\
519         SPOSE_NOT_THEN ASSUME_TAC \\
520         METIS_TAC [SIMP_EXTREAL_ARCH_NEG, extreal_of_num_def,
521                    extreal_lt_def, extreal_ainv_def, neg_neg, lt_neg]) >> Rewr' \\
522     Q.UNABBREV_TAC ‘S’ \\
523     Q.PAT_X_ASSUM ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | x < Normal a}) UNIV))’
524        (STRIP_ASSUME_TAC o (MATCH_MP SIGMA_ALGEBRA_FN_BIGINTER)) \\
525     POP_ASSUM MATCH_MP_TAC \\
526     rw [IN_FUNSET] \\
527     Suff ‘{x | x < Normal (-&n)} IN (IMAGE (\a. {x | x < Normal a}) UNIV)’
528     >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
529     rw [] >> Q.EXISTS_TAC ‘-&n’ >> rw [])
530 >> DISCH_TAC
531 >> Know ‘{PosInf} IN S’
532 >- (Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
533    ‘{PosInf} = (space (sigma UNIV (IMAGE (\a. {x | x < Normal a}) UNIV))) DIFF
534                {x | x <> PosInf}’ by SET_TAC [SPACE_SIGMA] >> POP_ORW \\
535     Know ‘{x | x <> PosInf} = BIGUNION (IMAGE (\n. {x | x < Normal (&n)}) UNIV)’
536     >- (rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
537         reverse EQ_TAC
538         >- METIS_TAC [num_not_infty, lt_infty, extreal_ainv_def, extreal_of_num_def] \\
539         RW_TAC std_ss [] \\
540        ‘?n. x <= &n’ by METIS_TAC [SIMP_EXTREAL_ARCH] \\
541         Q.EXISTS_TAC ‘SUC n’ \\
542         MATCH_MP_TAC let_trans >> Q.EXISTS_TAC ‘Normal &n’ \\
543         fs [extreal_of_num_def, extreal_lt_eq, extreal_le_eq]) >> Rewr' \\
544     Q.UNABBREV_TAC ‘S’ \\
545     MATCH_MP_TAC SIGMA_ALGEBRA_COMPL >> art [] \\
546     Q.PAT_X_ASSUM ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | x < Normal a}) UNIV))’
547        (STRIP_ASSUME_TAC o (REWRITE_RULE [SIGMA_ALGEBRA_FN])) \\
548     POP_ASSUM MATCH_MP_TAC \\
549     rw [IN_FUNSET] \\
550     Suff ‘{x | x < Normal (&n)} IN (IMAGE (\a. {x | x < Normal a}) UNIV)’
551     >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
552     rw [] >> Q.EXISTS_TAC ‘&n’ >> rw [])
553 >> DISCH_TAC
554 >> final_tactics
555QED
556
557Theorem Borel_eq_ge :
558    Borel = sigma univ(:extreal) (IMAGE (\a. {x | Normal a <= x}) univ(:real))
559Proof
560    Suff ‘subsets (sigma UNIV (IMAGE (\a. {x | Normal a <= x}) UNIV)) = subsets Borel’
561 >- METIS_TAC [SPACE, SPACE_BOREL, SPACE_SIGMA]
562 >> Q.ABBREV_TAC ‘S = subsets (sigma UNIV (IMAGE (\a. {x | Normal a <= x}) UNIV))’
563 >> Know ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | Normal a <= x}) UNIV))’
564 >- (MATCH_MP_TAC SIGMA_ALGEBRA_SIGMA >> rw [subset_class_def])
565 >> DISCH_TAC
566 >> MATCH_MP_TAC SUBSET_ANTISYM
567 (* easy part *)
568 >> CONJ_TAC
569 >- (Q.UNABBREV_TAC ‘S’ \\
570     MATCH_MP_TAC (REWRITE_RULE [SPACE_BOREL]
571                                (Q.ISPECL [‘IMAGE (\a. {x | Normal a <= x}) UNIV’, ‘Borel’]
572                                          SIGMA_SUBSET)) \\
573     REWRITE_TAC [SIGMA_ALGEBRA_BOREL] \\
574     rw [SUBSET_DEF, IN_IMAGE, Borel] \\
575     qexistsl_tac [‘{y | a <= y}’, ‘{PosInf}’] >> simp [] \\
576     CONJ_TAC
577     >- (rw [Once EXTENSION, IN_IMAGE, IN_UNIV] \\
578         EQ_TAC >> rw [] >| (* 3 subgoals *)
579         [ (* goal 1 (of 3) *)
580           Cases_on ‘x = PosInf’ >- rw [] >> DISJ1_TAC \\
581           Know ‘x <> NegInf’
582           >- (REWRITE_TAC [lt_infty] \\
583               MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC ‘Normal a’ >> art [lt_infty]) \\
584           DISCH_TAC >> ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] \\
585           Q.EXISTS_TAC ‘r’ >> fs [extreal_le_eq],
586           (* goal 2 (of 3) *)
587           rw [extreal_le_eq],
588           (* goal 3 (of 3) *)
589           REWRITE_TAC [le_infty] ]) \\
590     REWRITE_TAC [borel_measurable_sets_ge])
591 (* more properties of S *)
592 >> Know ‘!a b. a <= b ==> {x | Normal a <= x /\ x < Normal b} IN S’
593 >- (rpt STRIP_TAC \\
594    ‘{x | Normal a <= x /\ x < Normal b} =
595     {x | Normal a <= x} DIFF {x | Normal b <= x}’ by SET_TAC [extreal_lt_def] >> POP_ORW \\
596     Q.UNABBREV_TAC ‘S’ \\
597     MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> art [] \\
598     CONJ_TAC >| (* 2 subgoals *)
599     [ (* goal 1 (of 2) *)
600       Suff ‘{x | Normal a <= x} IN (IMAGE (\a. {x | Normal a <= x}) UNIV)’
601       >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
602       rw [IN_IMAGE] >> Q.EXISTS_TAC ‘a’ >> rw [],
603       (* goal 2 (of 2) *)
604       Suff ‘{x | Normal b <= x} IN (IMAGE (\a. {x | Normal a <= x}) UNIV)’
605       >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
606       rw [IN_IMAGE] >> Q.EXISTS_TAC ‘b’ >> rw [] ]) >> DISCH_TAC
607 >> early_tactics
608 (* applying SIGMA_ALGEBRA_RESTRICT *)
609 >> Know ‘sigma_algebra (R,IMAGE (\s. s INTER R) S)’
610 >- (MATCH_MP_TAC SIGMA_ALGEBRA_RESTRICT >> art [] \\
611     Q.EXISTS_TAC ‘space (sigma UNIV (IMAGE (\a. {x | Normal a <= x}) UNIV))’ \\
612     rw [Abbr ‘S’, SPACE])
613 >> DISCH_TAC
614 >> middle_tactics
615 (* stage work *)
616 >> simp [SUBSET_DEF, Borel]
617 >> GEN_TAC >> DISCH_THEN (qx_choosel_then [‘B’,‘X’] ASSUME_TAC)
618 >> ‘x = IMAGE Normal B UNION X’ by PROVE_TAC [] >> POP_ORW
619 >> Know ‘{PosInf} IN S’
620 >- (Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
621     Know ‘{PosInf} = BIGINTER (IMAGE (\n. {x | Normal (&n) <= x}) UNIV)’
622     >- (rw [Once EXTENSION, IN_BIGINTER_IMAGE] \\
623         EQ_TAC >- rw [le_infty] \\
624         RW_TAC std_ss [] \\
625         SPOSE_NOT_THEN ASSUME_TAC \\
626        ‘?n. x <= &n’ by METIS_TAC [SIMP_EXTREAL_ARCH] \\
627         fs [extreal_of_num_def] \\
628         Q.PAT_X_ASSUM ‘!n. Normal (&n) <= x’ (STRIP_ASSUME_TAC o (Q.SPEC ‘SUC n’)) \\
629        ‘Normal (&SUC n) <= Normal (&n)’ by PROVE_TAC [le_trans] \\
630         fs [extreal_le_eq]) >> Rewr' \\
631     Q.UNABBREV_TAC ‘S’ \\
632     Q.PAT_X_ASSUM ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | Normal a <= x}) UNIV))’
633        (STRIP_ASSUME_TAC o (MATCH_MP SIGMA_ALGEBRA_FN_BIGINTER)) \\
634     POP_ASSUM MATCH_MP_TAC \\
635     rw [IN_FUNSET] \\
636     Suff ‘{x | Normal (&n) <= x} IN (IMAGE (\a. {x | Normal a <= x}) UNIV)’
637     >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
638     rw [] >> Q.EXISTS_TAC ‘&n’ >> rw [])
639 >> DISCH_TAC
640 >> Know ‘{NegInf} IN S’
641 >- (Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
642    ‘{NegInf} = (space (sigma UNIV (IMAGE (\a. {x | Normal a <= x}) UNIV))) DIFF
643                {x | x <> NegInf}’ by SET_TAC [SPACE_SIGMA] >> POP_ORW \\
644     Know ‘{x | x <> NegInf} = BIGUNION (IMAGE (\n. {x | Normal (-&n) <= x}) UNIV)’
645     >- (rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
646         reverse EQ_TAC
647         >- (rw [lt_infty] \\
648             MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC ‘Normal (-&n)’ >> rw [lt_infty]) \\
649         RW_TAC std_ss [] \\
650        ‘?n. -&n <= x’ by METIS_TAC [SIMP_EXTREAL_ARCH_NEG] \\
651         Q.EXISTS_TAC ‘n’ >> fs [extreal_of_num_def, extreal_ainv_def]) >> Rewr' \\
652     Q.UNABBREV_TAC ‘S’ \\
653     MATCH_MP_TAC SIGMA_ALGEBRA_COMPL >> art [] \\
654     Q.PAT_X_ASSUM ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | Normal a <= x}) UNIV))’
655        (STRIP_ASSUME_TAC o (REWRITE_RULE [SIGMA_ALGEBRA_FN])) \\
656     POP_ASSUM MATCH_MP_TAC \\
657     rw [IN_FUNSET] \\
658     Suff ‘{x | Normal (-&n) <= x} IN (IMAGE (\a. {x | Normal a <= x}) UNIV)’
659     >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
660     rw [] >> Q.EXISTS_TAC ‘-&n’ >> rw [])
661 >> DISCH_TAC
662 >> final_tactics
663QED
664
665Theorem Borel_eq_le : (* cf. borel_eq_le (borel_def) *)
666    Borel = sigma univ(:extreal) (IMAGE (\a. {x | x <= Normal a}) univ(:real))
667Proof
668    Suff ‘subsets (sigma UNIV (IMAGE (\a. {x | x <= Normal a}) UNIV)) = subsets Borel’
669 >- METIS_TAC [SPACE, SPACE_BOREL, SPACE_SIGMA]
670 >> Q.ABBREV_TAC ‘S = subsets (sigma UNIV (IMAGE (\a. {x | x <= Normal a}) UNIV))’
671 >> Know ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | x <= Normal a}) UNIV))’
672 >- (MATCH_MP_TAC SIGMA_ALGEBRA_SIGMA >> rw [subset_class_def])
673 >> DISCH_TAC
674 >> MATCH_MP_TAC SUBSET_ANTISYM
675 (* easy part *)
676 >> CONJ_TAC
677 >- (Q.UNABBREV_TAC ‘S’ \\
678     MATCH_MP_TAC (REWRITE_RULE [SPACE_BOREL]
679                                (Q.ISPECL [‘IMAGE (\a. {x | x <= Normal a}) UNIV’, ‘Borel’]
680                                          SIGMA_SUBSET)) \\
681     REWRITE_TAC [SIGMA_ALGEBRA_BOREL] \\
682     rw [SUBSET_DEF, IN_IMAGE, Borel] \\
683     qexistsl_tac [‘{y | y <= a}’, ‘{NegInf}’] \\
684     CONJ_TAC
685     >- (rw [Once EXTENSION, IN_IMAGE, IN_UNIV] \\
686         EQ_TAC >> rw [] >| (* 3 subgoals *)
687         [ (* goal 1 (of 3) *)
688           Cases_on ‘x = NegInf’ >- rw [] >> DISJ1_TAC \\
689           Know ‘x <> PosInf’
690           >- (REWRITE_TAC [lt_infty] \\
691               MATCH_MP_TAC let_trans >> Q.EXISTS_TAC ‘Normal a’ >> art [lt_infty]) \\
692           DISCH_TAC >> ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] \\
693           Q.EXISTS_TAC ‘r’ >> fs [extreal_le_eq],
694           (* goal 2 (of 3) *)
695           fs [extreal_le_eq],
696           (* goal 3 (of 3) *)
697           REWRITE_TAC [le_infty] ]) \\
698     reverse CONJ_TAC >- rw [] \\
699     REWRITE_TAC [borel_measurable_sets_le])
700 (* more properties of S *)
701 >> Know ‘!a b. a <= b ==> {x | Normal a < x /\ x <= Normal b} IN S’
702 >- (rpt STRIP_TAC \\
703    ‘{x | Normal a < x /\ x <= Normal b} =
704     {x | x <= Normal b} DIFF {x | x <= Normal a}’ by SET_TAC [extreal_lt_def] >> POP_ORW \\
705     Q.UNABBREV_TAC ‘S’ \\
706     MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> art [] \\
707     CONJ_TAC >| (* 2 subgoals *)
708     [ (* goal 1 (of 2) *)
709       Suff ‘{x | x <= Normal b} IN (IMAGE (\a. {x | x <= Normal a}) UNIV)’
710       >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
711       rw [IN_IMAGE] >> Q.EXISTS_TAC ‘b’ >> rw [],
712       (* goal 2 (of 2) *)
713       Suff ‘{x | x <= Normal a} IN (IMAGE (\a. {x | x <= Normal a}) UNIV)’
714       >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
715       rw [IN_IMAGE] >> Q.EXISTS_TAC ‘a’ >> rw [] ]) >> DISCH_TAC
716 >> early_tactics'
717 (* applying SIGMA_ALGEBRA_RESTRICT *)
718 >> Know ‘sigma_algebra (R,IMAGE (\s. s INTER R) S)’
719 >- (MATCH_MP_TAC SIGMA_ALGEBRA_RESTRICT >> art [] \\
720     Q.EXISTS_TAC ‘space (sigma UNIV (IMAGE (\a. {x | x <= Normal a}) UNIV))’ \\
721     rw [Abbr ‘S’, SPACE])
722 >> DISCH_TAC
723 >> middle_tactics'
724 (* stage work *)
725 >> simp [SUBSET_DEF, Borel]
726 >> GEN_TAC >> DISCH_THEN (qx_choosel_then [‘B’,‘X’] ASSUME_TAC)
727 >> ‘x = IMAGE Normal B UNION X’ by PROVE_TAC [] >> POP_ORW
728 >> Know ‘{NegInf} IN S’
729 >- (Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
730     Know ‘{NegInf} = BIGINTER (IMAGE (\n. {x | x <= Normal (-&n)}) UNIV)’
731     >- (rw [Once EXTENSION, IN_BIGINTER_IMAGE] \\
732         EQ_TAC >- rw [le_infty] \\
733         RW_TAC std_ss [] \\
734         SPOSE_NOT_THEN ASSUME_TAC \\
735        ‘?n. -&n <= x’ by METIS_TAC [SIMP_EXTREAL_ARCH_NEG] \\
736         fs [extreal_of_num_def, extreal_ainv_def] \\
737         Q.PAT_X_ASSUM ‘!n. x <= Normal (-&n)’ (STRIP_ASSUME_TAC o (Q.SPEC ‘SUC n’)) \\
738        ‘Normal (-&n) <= Normal (-&SUC n)’ by PROVE_TAC [le_trans] \\
739         fs [extreal_le_eq]) >> Rewr' \\
740     Q.UNABBREV_TAC ‘S’ \\
741     Q.PAT_X_ASSUM ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | x <= Normal a}) UNIV))’
742        (STRIP_ASSUME_TAC o (MATCH_MP SIGMA_ALGEBRA_FN_BIGINTER)) \\
743     POP_ASSUM MATCH_MP_TAC \\
744     rw [IN_FUNSET] \\
745     Suff ‘{x | x <= Normal (-&n)} IN (IMAGE (\a. {x | x <= Normal a}) UNIV)’
746     >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
747     rw [] >> Q.EXISTS_TAC ‘-&n’ >> rw [])
748 >> DISCH_TAC
749 >> Know ‘{PosInf} IN S’
750 >- (Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
751    ‘{PosInf} = (space (sigma UNIV (IMAGE (\a. {x | x <= Normal a}) UNIV))) DIFF
752                {x | x <> PosInf}’ by SET_TAC [SPACE_SIGMA] >> POP_ORW \\
753     Know ‘{x | x <> PosInf} = BIGUNION (IMAGE (\n. {x | x <= Normal (&n)}) UNIV)’
754     >- (rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
755         reverse EQ_TAC
756         >- (rw [lt_infty] \\
757             MATCH_MP_TAC let_trans >> Q.EXISTS_TAC ‘Normal (&n)’ >> rw [lt_infty]) \\
758         RW_TAC std_ss [] \\
759        ‘?n. x <= &n’ by METIS_TAC [SIMP_EXTREAL_ARCH] \\
760         Q.EXISTS_TAC ‘n’ >> fs [extreal_of_num_def]) >> Rewr' \\
761     Q.UNABBREV_TAC ‘S’ \\
762     MATCH_MP_TAC SIGMA_ALGEBRA_COMPL >> art [] \\
763     Q.PAT_X_ASSUM ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | x <= Normal a}) UNIV))’
764        (STRIP_ASSUME_TAC o (REWRITE_RULE [SIGMA_ALGEBRA_FN])) \\
765     POP_ASSUM MATCH_MP_TAC \\
766     rw [IN_FUNSET] \\
767     Suff ‘{x | x <= Normal (&n)} IN (IMAGE (\a. {x | x <= Normal a}) UNIV)’
768     >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
769     rw [] >> Q.EXISTS_TAC ‘&n’ >> rw [])
770 >> DISCH_TAC
771 >> final_tactics
772QED
773
774Theorem Borel_eq_gr : (* cf. borel_eq_gr *)
775    Borel = sigma univ(:extreal) (IMAGE (\a. {x | Normal a < x}) univ(:real))
776Proof
777    Suff ‘subsets (sigma UNIV (IMAGE (\a. {x | Normal a < x}) UNIV)) = subsets Borel’
778 >- METIS_TAC [SPACE, SPACE_BOREL, SPACE_SIGMA]
779 >> Q.ABBREV_TAC ‘S = subsets (sigma UNIV (IMAGE (\a. {x | Normal a < x}) UNIV))’
780 >> Know ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | Normal a < x}) UNIV))’
781 >- (MATCH_MP_TAC SIGMA_ALGEBRA_SIGMA >> rw [subset_class_def])
782 >> DISCH_TAC
783 >> MATCH_MP_TAC SUBSET_ANTISYM
784 (* easy part *)
785 >> CONJ_TAC
786 >- (Q.UNABBREV_TAC ‘S’ \\
787     MATCH_MP_TAC (REWRITE_RULE [SPACE_BOREL]
788                                (Q.ISPECL [‘IMAGE (\a. {x | Normal a < x}) UNIV’, ‘Borel’]
789                                          SIGMA_SUBSET)) \\
790     REWRITE_TAC [SIGMA_ALGEBRA_BOREL] \\
791     rw [SUBSET_DEF, IN_IMAGE, Borel] \\
792     qexistsl_tac [‘{y | a < y}’, ‘{PosInf}’] \\
793     CONJ_TAC
794     >- (rw [Once EXTENSION, IN_IMAGE, IN_UNIV] \\
795         EQ_TAC >> rw [] >| (* 3 subgoals *)
796         [ (* goal 1 (of 3) *)
797           Cases_on ‘x = PosInf’ >- rw [] >> DISJ1_TAC \\
798           Know ‘x <> NegInf’
799           >- (REWRITE_TAC [lt_infty] \\
800               MATCH_MP_TAC lt_trans >> Q.EXISTS_TAC ‘Normal a’ >> art [lt_infty]) \\
801           DISCH_TAC >> ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] \\
802           Q.EXISTS_TAC ‘r’ >> fs [extreal_lt_eq],
803           (* goal 2 (of 3) *)
804           fs [extreal_lt_eq],
805           (* goal 3 (of 3) *)
806           REWRITE_TAC [lt_infty] ]) \\
807     reverse CONJ_TAC >- rw [] \\
808     REWRITE_TAC [borel_measurable_sets_gr])
809 (* more properties of S *)
810 >> Know ‘!a b. a <= b ==> {x | Normal a < x /\ x <= Normal b} IN S’
811 >- (rpt STRIP_TAC \\
812    ‘{x | Normal a < x /\ x <= Normal b} =
813     {x | Normal a < x} DIFF {x | Normal b < x}’ by SET_TAC [extreal_lt_def] >> POP_ORW \\
814     Q.UNABBREV_TAC ‘S’ \\
815     MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> art [] \\
816     CONJ_TAC >| (* 2 subgoals *)
817     [ (* goal 1 (of 2) *)
818       Suff ‘{x | Normal a < x} IN (IMAGE (\a. {x | Normal a < x}) UNIV)’
819       >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
820       rw [IN_IMAGE] >> Q.EXISTS_TAC ‘a’ >> rw [],
821       (* goal 2 (of 2) *)
822       Suff ‘{x | Normal b < x} IN (IMAGE (\a. {x | Normal a < x}) UNIV)’
823       >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
824       rw [IN_IMAGE] >> Q.EXISTS_TAC ‘b’ >> rw [] ]) >> DISCH_TAC
825 >> early_tactics'
826 (* applying SIGMA_ALGEBRA_RESTRICT *)
827 >> Know ‘sigma_algebra (R,IMAGE (\s. s INTER R) S)’
828 >- (MATCH_MP_TAC SIGMA_ALGEBRA_RESTRICT >> art [] \\
829     Q.EXISTS_TAC ‘space (sigma UNIV (IMAGE (\a. {x | Normal a < x}) UNIV))’ \\
830     rw [Abbr ‘S’, SPACE])
831 >> DISCH_TAC
832 >> middle_tactics'
833 (* stage work *)
834 >> simp [SUBSET_DEF, Borel]
835 >> GEN_TAC >> DISCH_THEN (qx_choosel_then [‘B’,‘X’] ASSUME_TAC)
836 >> ‘x = IMAGE Normal B UNION X’ by PROVE_TAC [] >> POP_ORW
837 >> Know ‘{PosInf} IN S’
838 >- (Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
839     Know ‘{PosInf} = BIGINTER (IMAGE (\n. {x | Normal (&n) < x}) UNIV)’
840     >- (rw [Once EXTENSION, IN_BIGINTER_IMAGE] \\
841         EQ_TAC >- rw [lt_infty] \\
842         RW_TAC std_ss [] \\
843         SPOSE_NOT_THEN ASSUME_TAC \\
844        ‘?n. x <= &n’ by METIS_TAC [SIMP_EXTREAL_ARCH] \\
845         fs [extreal_of_num_def] \\
846         Q.PAT_X_ASSUM ‘!n. Normal (&n) < x’ (STRIP_ASSUME_TAC o (Q.SPEC ‘n’)) \\
847        ‘x < x’ by PROVE_TAC [let_trans] \\
848         PROVE_TAC [lt_refl]) >> Rewr' \\
849     Q.UNABBREV_TAC ‘S’ \\
850     Q.PAT_X_ASSUM ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | Normal a < x}) UNIV))’
851        (STRIP_ASSUME_TAC o (MATCH_MP SIGMA_ALGEBRA_FN_BIGINTER)) \\
852     POP_ASSUM MATCH_MP_TAC \\
853     rw [IN_FUNSET] \\
854     Suff ‘{x | Normal (&n) < x} IN (IMAGE (\a. {x | Normal a < x}) UNIV)’
855     >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
856     rw [] >> Q.EXISTS_TAC ‘&n’ >> rw [])
857 >> DISCH_TAC
858 >> Know ‘{NegInf} IN S’
859 >- (Q.PAT_X_ASSUM ‘x = IMAGE Normal B UNION X /\ _’ K_TAC \\
860    ‘{NegInf} = (space (sigma UNIV (IMAGE (\a. {x | Normal a < x}) UNIV))) DIFF
861                {x | x <> NegInf}’ by SET_TAC [SPACE_SIGMA] >> POP_ORW \\
862     Know ‘{x | x <> NegInf} = BIGUNION (IMAGE (\n. {x | Normal (-&n) < x}) UNIV)’
863     >- (rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
864         reverse EQ_TAC
865         >- (rw [lt_infty] \\
866             MATCH_MP_TAC lt_trans >> Q.EXISTS_TAC ‘Normal (-&n)’ >> rw [lt_infty]) \\
867         RW_TAC std_ss [] \\
868        ‘?n. -&n <= x’ by METIS_TAC [SIMP_EXTREAL_ARCH_NEG] \\
869         Q.EXISTS_TAC ‘SUC n’ >> fs [extreal_of_num_def, extreal_ainv_def] \\
870         MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC ‘Normal (-&n)’ \\
871         rw [extreal_lt_eq]) >> Rewr' \\
872     Q.UNABBREV_TAC ‘S’ \\
873     MATCH_MP_TAC SIGMA_ALGEBRA_COMPL >> art [] \\
874     Q.PAT_X_ASSUM ‘sigma_algebra (sigma UNIV (IMAGE (\a. {x | Normal a < x}) UNIV))’
875        (STRIP_ASSUME_TAC o (REWRITE_RULE [SIGMA_ALGEBRA_FN])) \\
876     POP_ASSUM MATCH_MP_TAC \\
877     rw [IN_FUNSET] \\
878     Suff ‘{x | Normal (-&n) < x} IN (IMAGE (\a. {x | Normal a < x}) UNIV)’
879     >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
880     rw [] >> Q.EXISTS_TAC ‘-&n’ >> rw [])
881 >> DISCH_TAC
882 >> final_tactics
883QED
884
885(* NOTE: moved ‘sigma_algebra a’ to antecedents due to changes of ‘measurable’ *)
886Theorem MEASURABLE_BOREL :
887    !f a. sigma_algebra a ==>
888         (f IN measurable a Borel <=>
889          f IN (space a -> UNIV) /\
890          !c. ((PREIMAGE f {x| x < Normal c}) INTER (space a)) IN subsets a)
891Proof
892    RW_TAC std_ss []
893 >> `sigma_algebra Borel` by RW_TAC std_ss [SIGMA_ALGEBRA_BOREL]
894 >> `space Borel = UNIV` by RW_TAC std_ss [Borel_def, space_def, SPACE_SIGMA]
895 >> EQ_TAC
896 >- (RW_TAC std_ss [Borel_def, IN_MEASURABLE, IN_FUNSET, IN_UNIV, subsets_def, GSPECIFICATION]
897     >> POP_ASSUM MATCH_MP_TAC
898     >> MATCH_MP_TAC IN_SIGMA
899     >> RW_TAC std_ss [IN_IMAGE,IN_UNIV]
900     >> METIS_TAC [])
901 >> RW_TAC std_ss [Borel_def]
902 >> MATCH_MP_TAC MEASURABLE_SIGMA
903 >> RW_TAC std_ss [subset_class_def,SUBSET_UNIV,IN_IMAGE,IN_UNIV]
904 >> METIS_TAC []
905QED
906
907Theorem IN_MEASURABLE_BOREL :
908    !f a. sigma_algebra a ==>
909         (f IN measurable a Borel <=>
910          f IN (space a -> UNIV) /\
911          !c. ({x | f x < Normal c} INTER space a) IN subsets a)
912Proof
913  RW_TAC std_ss []
914  >> `!c. {x | f x < Normal c} = PREIMAGE f {x| x < Normal c}`
915       by RW_TAC std_ss [EXTENSION,IN_PREIMAGE,GSPECIFICATION]
916  >> RW_TAC std_ss [MEASURABLE_BOREL]
917QED
918
919(* NOTE: added ‘sigma_algebra a’ due to changes of ‘measurable’ *)
920Theorem IN_MEASURABLE_BOREL_NEGINF :
921    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
922          ({x | f x = NegInf} INTER space a) IN subsets a
923Proof
924    rpt STRIP_TAC
925 >> rfs [IN_MEASURABLE_BOREL, GSPECIFICATION, IN_FUNSET]
926 >> Know `{x | f x = NegInf} INTER space a =
927          BIGINTER (IMAGE (\n. {x | f x < -(&n)} INTER space a) UNIV)`
928 >- (RW_TAC std_ss [EXTENSION, IN_BIGINTER_IMAGE, IN_UNIV, GSPECIFICATION, IN_INTER] \\
929     EQ_TAC >- METIS_TAC [num_not_infty,lt_infty,extreal_ainv_def,extreal_of_num_def] \\
930     RW_TAC std_ss [] \\
931     SPOSE_NOT_THEN ASSUME_TAC \\
932     METIS_TAC [SIMP_EXTREAL_ARCH_NEG, extreal_lt_def,extreal_ainv_def,neg_neg,lt_neg])
933 >> Rewr'
934 >> IMP_RES_TAC SIGMA_ALGEBRA_FN_BIGINTER
935 >> POP_ASSUM MATCH_MP_TAC
936 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
937 >> `- &n = Normal (- &n)` by PROVE_TAC [extreal_ainv_def, extreal_of_num_def]
938 >> METIS_TAC []
939QED
940
941(* NOTE: added ‘sigma_algebra a’ due to changes of ‘measurable’ *)
942Theorem IN_MEASURABLE_BOREL_NOT_POSINF :
943    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
944          ({x | f x <> PosInf} INTER space a) IN subsets a
945Proof
946    rpt STRIP_TAC
947 >> rfs [IN_MEASURABLE_BOREL, GSPECIFICATION, IN_FUNSET]
948 >> Know `{x | f x <> PosInf} INTER space a =
949          BIGUNION (IMAGE (\n. {x | f x < &n} INTER space a) UNIV)`
950 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION, IN_INTER] \\
951     EQ_TAC
952     >- (rpt STRIP_TAC \\
953         `?n. f x <= &n` by PROVE_TAC [SIMP_EXTREAL_ARCH] \\
954         Q.EXISTS_TAC `SUC n` >> art [] \\
955         MATCH_MP_TAC let_trans >> Q.EXISTS_TAC `&n` >> art [] \\
956         SIMP_TAC arith_ss [extreal_of_num_def, extreal_lt_eq, REAL_LT]) \\
957     RW_TAC std_ss [] >- METIS_TAC [num_not_infty, lt_infty] \\
958     ASM_REWRITE_TAC [])
959 >> Rewr'
960 >> fs [SIGMA_ALGEBRA_FN]
961 >> FIRST_X_ASSUM MATCH_MP_TAC
962 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
963 >> `&n = Normal (&n)` by PROVE_TAC [extreal_of_num_def]
964 >> METIS_TAC []
965QED
966
967(* NOTE: added ‘sigma_algebra a’ due to changes of ‘measurable’ *)
968Theorem IN_MEASURABLE_BOREL_IMP :
969    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
970          !c. ({x | f x < c} INTER space a) IN subsets a
971Proof
972    rpt STRIP_TAC
973 >> Cases_on `c`
974 >- (REWRITE_TAC [lt_infty, GSPEC_F, INTER_EMPTY] \\
975     rw [SIGMA_ALGEBRA_EMPTY])
976 >- (REWRITE_TAC [GSYM lt_infty] \\
977     MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [])
978 >> rfs [IN_MEASURABLE_BOREL]
979QED
980
981(* |- !f a.
982        sigma_algebra a /\ f IN Borel_measurable a ==>
983        !c. {x | f x < c} INTER space a IN subsets a
984 *)
985Theorem IN_MEASURABLE_BOREL_RO = IN_MEASURABLE_BOREL_IMP
986
987(* NOTE: moved ‘sigma_algebra a’ to antecedents due to changes of ‘measurable’ *)
988Theorem IN_MEASURABLE_BOREL_ALT1 :
989    !f a. sigma_algebra a ==>
990         (f IN measurable a Borel <=>
991          f IN (space a -> UNIV) /\
992          !c. ({x | Normal c <= f x} INTER space a) IN subsets a)
993Proof
994    rpt STRIP_TAC
995 >> RW_TAC std_ss [IN_MEASURABLE_BOREL, GSPECIFICATION, IN_FUNSET, IN_UNIV]
996 >> EQ_TAC
997 >- (RW_TAC std_ss []
998     >> `{x | Normal c <= f x} = PREIMAGE f {x | Normal c <= x}`
999         by RW_TAC std_ss [PREIMAGE_def, GSPECIFICATION]
1000     >> `!c. {x | f x < Normal c} = PREIMAGE f {x | x < Normal c}`
1001         by RW_TAC std_ss [PREIMAGE_def, GSPECIFICATION]
1002     >> `!c. space a DIFF ((PREIMAGE f {x | x < Normal c}) INTER space a) IN subsets a`
1003         by METIS_TAC [sigma_algebra_def, algebra_def]
1004     >> `!c. space a DIFF (PREIMAGE f {x | x < Normal c}) IN subsets a` by METIS_TAC [DIFF_INTER2]
1005     >> `!c. (PREIMAGE f (COMPL {x | x < Normal c}) INTER space a) IN subsets a`
1006         by METIS_TAC [GSYM PREIMAGE_COMPL_INTER]
1007     >> `!c. COMPL {x | x < Normal c} = {x | Normal c <= x}`
1008         by RW_TAC std_ss [EXTENSION, IN_COMPL, IN_UNIV, IN_DIFF, GSPECIFICATION, extreal_lt_def]
1009     >> FULL_SIMP_TAC std_ss [])
1010 >> RW_TAC std_ss []
1011 >> `{x | f x < Normal c} = PREIMAGE f {x | x < Normal c}`
1012     by RW_TAC std_ss [PREIMAGE_def, GSPECIFICATION]
1013 >> `!c. {x | Normal c <= f x} = PREIMAGE f {x | Normal c <= x}`
1014     by RW_TAC std_ss [PREIMAGE_def, GSPECIFICATION]
1015 >> `!c. space a DIFF ((PREIMAGE f {x | Normal c <= x}) INTER space a) IN subsets a`
1016     by METIS_TAC [sigma_algebra_def,algebra_def]
1017 >> `!c. space a DIFF (PREIMAGE f {x | Normal c <= x}) IN subsets a` by METIS_TAC [DIFF_INTER2]
1018 >> `!c. (PREIMAGE f (COMPL {x | Normal c <= x}) INTER space a) IN subsets a`
1019     by METIS_TAC [GSYM PREIMAGE_COMPL_INTER]
1020 >> `!c. COMPL {x | Normal c <= x} = {x | x < Normal c}`
1021     by RW_TAC std_ss [EXTENSION, IN_COMPL, IN_UNIV, IN_DIFF, GSPECIFICATION, extreal_lt_def]
1022 >> METIS_TAC []
1023QED
1024
1025(* NOTE: moved ‘sigma_algebra a’ to antecedents due to changes of ‘measurable’ *)
1026Theorem IN_MEASURABLE_BOREL_ALT2 :
1027    !f a. sigma_algebra a ==>
1028         (f IN measurable a Borel <=>
1029          f IN (space a -> UNIV) /\
1030          !c. ({x | f x <= Normal c} INTER space a) IN subsets a)
1031Proof
1032    rpt STRIP_TAC
1033 >> RW_TAC std_ss [IN_MEASURABLE_BOREL]
1034 >> EQ_TAC
1035 >- (RW_TAC std_ss [] \\
1036     `!c. {x | f x <= Normal c} INTER (space a) =
1037             BIGINTER (IMAGE (\n:num. {x | f x < Normal (c + (1/2) pow n)} INTER space a) UNIV)`
1038        by (RW_TAC std_ss [EXTENSION, IN_BIGINTER_IMAGE, IN_UNIV,IN_INTER]
1039            >> EQ_TAC
1040            >- (RW_TAC std_ss [GSPECIFICATION,GSYM extreal_add_def]
1041                >> `0:real < (1 / 2) pow n` by RW_TAC real_ss [REAL_POW_LT]
1042                >> `0 < Normal ((1 / 2) pow n)` by METIS_TAC [extreal_of_num_def,extreal_lt_eq]
1043                >> Cases_on `f x = NegInf` >- METIS_TAC [lt_infty,extreal_add_def]
1044                >> METIS_TAC [let_add2,extreal_of_num_def,extreal_not_infty,add_rzero,le_infty])
1045             >> RW_TAC std_ss [GSPECIFICATION]
1046             >> `!n. f x < Normal (c + (1 / 2) pow n)` by METIS_TAC []
1047             >> `(\n. c + (1 / 2) pow n) = (\n. (\n. c) n + (\n. (1 / 2) pow n) n)`
1048                    by RW_TAC real_ss [FUN_EQ_THM]
1049             >> `(\n. (1 / 2) pow n) --> 0` by RW_TAC real_ss [SEQ_POWER]
1050             >> `(\n. c + (1 / 2) pow n) --> c`
1051                    by METIS_TAC [SEQ_CONST,
1052                         Q.SPECL [`(\n:num. c)`,`c`,`(\n. (1/2) pow n)`,`0`] SEQ_ADD,REAL_ADD_RID]
1053             >> Cases_on `f x = NegInf` >- METIS_TAC [le_infty]
1054             >> `f x <> PosInf` by METIS_TAC [lt_infty]
1055             >> `?r. f x = Normal r` by METIS_TAC [extreal_cases]
1056             >> FULL_SIMP_TAC std_ss [extreal_lt_eq,extreal_le_def]
1057             >> METIS_TAC [REAL_LT_IMP_LE,
1058                           Q.SPECL [`r`,`c`,`(\n. c + (1 / 2) pow n)`] LE_SEQ_IMP_LE_LIM])
1059     >> `BIGINTER (IMAGE (\n:num. {x | f x < Normal (c + (1 / 2) pow n)} INTER space a) UNIV)
1060           IN subsets a`
1061         by (RW_TAC std_ss []
1062             >> (MP_TAC o Q.SPEC `a`) SIGMA_ALGEBRA_FN_BIGINTER
1063             >> RW_TAC std_ss []
1064             >> `(\n. {x | f x < Normal (c + (1/2) pow n)} INTER space a) IN (UNIV -> subsets a)`
1065                 by (RW_TAC std_ss [IN_FUNSET])
1066             >> METIS_TAC [])
1067     >> METIS_TAC [])
1068 >> RW_TAC std_ss []
1069 >> `!c. {x | f x < Normal c} INTER (space a) =
1070         BIGUNION (IMAGE (\n:num. {x | f x <= Normal (c - (1/2) pow n)} INTER space a) UNIV)`
1071     by (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV,IN_INTER,GSPECIFICATION]
1072         >> `(\n. c - (1 / 2) pow n) = (\n. (\n. c) n - (\n. (1 / 2) pow n) n)`
1073             by RW_TAC real_ss [FUN_EQ_THM]
1074         >> `(\n. c) --> c` by RW_TAC std_ss [SEQ_CONST]
1075         >> `(\n. (1 / 2) pow n) --> 0` by RW_TAC real_ss [SEQ_POWER]
1076         >> `(\n. c - (1 / 2) pow n) --> c`
1077             by METIS_TAC [Q.SPECL [`(\n. c)`,`c`,`(\n. (1/2) pow n)`,`0`] SEQ_SUB, REAL_SUB_RZERO]
1078         >> EQ_TAC
1079         >- (RW_TAC std_ss []
1080             >> Cases_on `f x = NegInf` >- METIS_TAC [le_infty]
1081             >> `f x <> PosInf` by METIS_TAC [lt_infty]
1082             >> `?r. f x = Normal r` by METIS_TAC [extreal_cases]
1083             >> FULL_SIMP_TAC std_ss [extreal_lt_eq,extreal_le_def]
1084             >> `!e:real. 0 < e ==> ?N. !n. n >= N ==> abs ((1 / 2) pow n) < e`
1085                 by FULL_SIMP_TAC real_ss [Q.SPECL [`(\n. (1/2) pow n)`,`0`] SEQ, REAL_SUB_RZERO]
1086             >> `!n. abs ((1 / 2) pow n):real = (1 / 2) pow n`
1087                 by FULL_SIMP_TAC real_ss [POW_POS, ABS_REFL]
1088             >> `!e:real. 0 < e ==> ?N. !n. n >= N ==> (1 / 2) pow n < e` by METIS_TAC []
1089             >> `?N. !n. n >= N ==> (1 / 2) pow n < c - r` by METIS_TAC [REAL_SUB_LT]
1090             >> Q.EXISTS_TAC `N`
1091             >> `(1 / 2) pow N < c - r` by FULL_SIMP_TAC real_ss []
1092             >> FULL_SIMP_TAC real_ss [GSYM REAL_LT_ADD_SUB,REAL_ADD_COMM,REAL_LT_IMP_LE])
1093         >> RW_TAC std_ss []
1094         >- (`!n. - ((1 / 2) pow n) < 0:real`
1095              by METIS_TAC [REAL_POW_LT, REAL_NEG_0, REAL_LT_NEG, EVAL ``0:real < 1/2``]
1096             >> `!n. c - (1 / 2) pow n < c` by METIS_TAC [REAL_LT_IADD,REAL_ADD_RID,real_sub]
1097             >> Cases_on `f x = NegInf` >- METIS_TAC [lt_infty]
1098             >> `f x <> PosInf` by METIS_TAC [le_infty,extreal_not_infty]
1099             >> `?r. f x = Normal r` by METIS_TAC [extreal_cases]
1100             >> FULL_SIMP_TAC std_ss [extreal_lt_eq,extreal_le_def]
1101             >> METIS_TAC [REAL_LET_TRANS])
1102         >> METIS_TAC [])
1103 >> FULL_SIMP_TAC std_ss []
1104 >> MATCH_MP_TAC SIGMA_ALGEBRA_ENUM
1105 >> RW_TAC std_ss [IN_FUNSET]
1106QED
1107
1108(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1109Theorem IN_MEASURABLE_BOREL_ALT2_IMP :
1110    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1111          !c. ({x | f x <= c} INTER space a) IN subsets a
1112Proof
1113    rpt STRIP_TAC
1114 >> Cases_on `c`
1115 >- (REWRITE_TAC [le_infty] \\
1116     MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [])
1117 >- (REWRITE_TAC [le_infty, GSPEC_T, INTER_UNIV] \\
1118     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_SPACE])
1119 >> rfs [IN_MEASURABLE_BOREL_ALT2]
1120QED
1121
1122(* |- !f a.
1123        sigma_algebra a /\ f IN Borel_measurable a ==>
1124        !c. {x | f x <= c} INTER space a IN subsets a
1125
1126   NOTE: "RC" ("C" is at right of "R") means a right-closed (C) half-interval (R).
1127 *)
1128Theorem IN_MEASURABLE_BOREL_RC = IN_MEASURABLE_BOREL_ALT2_IMP
1129
1130(* NOTE: moved ‘sigma_algebra a’ to antecedents due to changes of ‘measurable’ *)
1131Theorem IN_MEASURABLE_BOREL_ALT3 :
1132    !f a. sigma_algebra a ==>
1133         (f IN measurable a Borel <=>
1134          f IN (space a -> UNIV) /\
1135          !c. ({x | Normal c < f x} INTER space a) IN subsets a)
1136Proof
1137    RW_TAC std_ss [IN_MEASURABLE_BOREL_ALT2,GSPECIFICATION]
1138 >> EQ_TAC
1139 >- (RW_TAC std_ss []
1140     >> `{x|Normal c < f x} = PREIMAGE f {x | Normal c < x}` by RW_TAC std_ss[PREIMAGE_def,GSPECIFICATION]
1141     >> `!c. {x | f x <= Normal c} = PREIMAGE f {x | x <= Normal c}` by RW_TAC std_ss[PREIMAGE_def,GSPECIFICATION]
1142     >> `!c. space a DIFF ((PREIMAGE f {x | x <= Normal c}) INTER space a) IN subsets a` by METIS_TAC [sigma_algebra_def,algebra_def]
1143     >> `!c. space a DIFF (PREIMAGE f {x | x <= Normal c}) IN subsets a` by METIS_TAC [DIFF_INTER2]
1144     >> `!c. (PREIMAGE f (COMPL {x | x <= Normal c}) INTER space a) IN subsets a` by METIS_TAC [GSYM PREIMAGE_COMPL_INTER]
1145     >> `COMPL {x | x <= Normal c} = {x | Normal c < x}` by RW_TAC std_ss [EXTENSION,GSPECIFICATION,IN_COMPL,extreal_lt_def]
1146     >> METIS_TAC [])
1147 >> RW_TAC std_ss []
1148 >> `{x | f x <= Normal c} = PREIMAGE f {x | x <= Normal c}` by RW_TAC std_ss[PREIMAGE_def,GSPECIFICATION]
1149 >> `!c. { x | Normal c < f x } = PREIMAGE f { x | Normal c < x }` by RW_TAC std_ss[PREIMAGE_def,GSPECIFICATION]
1150 >> `!c. space a DIFF ((PREIMAGE f {x | Normal c < x}) INTER space a) IN subsets a` by METIS_TAC [sigma_algebra_def,algebra_def]
1151 >> `!c. space a DIFF (PREIMAGE f {x | Normal c < x}) IN subsets a` by METIS_TAC [DIFF_INTER2]
1152 >> `!c. (PREIMAGE f (COMPL {x | Normal c < x}) INTER space a) IN subsets a` by METIS_TAC [GSYM PREIMAGE_COMPL_INTER]
1153 >> `COMPL {x | Normal c < x} = {x | x <= Normal c}` by RW_TAC std_ss [EXTENSION,GSPECIFICATION,IN_COMPL,extreal_lt_def]
1154 >> METIS_TAC []
1155QED
1156
1157(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1158Theorem IN_MEASURABLE_BOREL_POSINF :
1159    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1160          ({x | f x = PosInf} INTER space a) IN subsets a
1161Proof
1162    rpt STRIP_TAC
1163 >> rfs [IN_MEASURABLE_BOREL_ALT3, GSPECIFICATION, IN_FUNSET]
1164 >> Know `{x | f x = PosInf} INTER space a =
1165          BIGINTER (IMAGE (\n. {x | &n < f x} INTER space a) UNIV)`
1166 >- (RW_TAC std_ss [EXTENSION, IN_BIGINTER_IMAGE, IN_UNIV, GSPECIFICATION, IN_INTER] \\
1167     EQ_TAC >- METIS_TAC [num_not_infty, lt_infty, extreal_ainv_def, extreal_of_num_def] \\
1168     RW_TAC std_ss [] \\
1169     SPOSE_NOT_THEN ASSUME_TAC \\
1170     METIS_TAC [SIMP_EXTREAL_ARCH, extreal_lt_def])
1171 >> Rewr'
1172 >> IMP_RES_TAC SIGMA_ALGEBRA_FN_BIGINTER
1173 >> POP_ASSUM MATCH_MP_TAC
1174 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1175 >> `&n = Normal (&n)` by PROVE_TAC [extreal_of_num_def]
1176 >> METIS_TAC []
1177QED
1178
1179(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1180Theorem IN_MEASURABLE_BOREL_NOT_NEGINF :
1181    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1182          ({x | f x <> NegInf} INTER space a) IN subsets a
1183Proof
1184    rpt STRIP_TAC
1185 >> rfs [IN_MEASURABLE_BOREL_ALT3, GSPECIFICATION, IN_FUNSET]
1186 >> Know `{x | f x <> NegInf} INTER space a =
1187          BIGUNION (IMAGE (\n. {x | -(&n) < f x} INTER space a) UNIV)`
1188 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION, IN_INTER] \\
1189     EQ_TAC
1190     >- (rpt STRIP_TAC \\
1191         `?n. -(&n) <= f x` by PROVE_TAC [SIMP_EXTREAL_ARCH_NEG] \\
1192         Q.EXISTS_TAC `SUC n` >> art [] \\
1193         MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC `-&n` >> art [] \\
1194         SIMP_TAC arith_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT]) \\
1195     RW_TAC std_ss [] >- METIS_TAC [num_not_infty, lt_infty] \\
1196     ASM_REWRITE_TAC [])
1197 >> Rewr'
1198 >> fs [SIGMA_ALGEBRA_FN]
1199 >> FIRST_X_ASSUM MATCH_MP_TAC
1200 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1201 >> `-&n = Normal (-&n)` by PROVE_TAC [extreal_ainv_def, extreal_of_num_def]
1202 >> METIS_TAC []
1203QED
1204
1205(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1206Theorem IN_MEASURABLE_BOREL_ALT1_IMP :
1207    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1208          !c. ({x | c <= f x} INTER space a) IN subsets a
1209Proof
1210    rpt STRIP_TAC
1211 >> Cases_on `c`
1212 >- (REWRITE_TAC [le_infty, GSPEC_T, INTER_UNIV] \\
1213     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_SPACE])
1214 >- (REWRITE_TAC [le_infty] \\
1215     MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [])
1216 >> rfs [IN_MEASURABLE_BOREL_ALT1]
1217QED
1218
1219(* |- !f a.
1220        sigma_algebra a /\ f IN Borel_measurable a ==>
1221        !c. {x | c <= f x} INTER space a IN subsets a
1222
1223   NOTE: "CR" ("C" is at left of "R") means a left-closed (C) half-interval (R).
1224 *)
1225Theorem IN_MEASURABLE_BOREL_CR = IN_MEASURABLE_BOREL_ALT1_IMP
1226
1227(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1228Theorem IN_MEASURABLE_BOREL_ALT3_IMP :
1229    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1230          !c. ({x | c < f x} INTER space a) IN subsets a
1231Proof
1232    rpt STRIP_TAC
1233 >> Cases_on `c`
1234 >- (REWRITE_TAC [GSYM lt_infty] \\
1235     MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [])
1236 >- (REWRITE_TAC [lt_infty, GSPEC_F, INTER_EMPTY] \\
1237     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1238 >> rfs [IN_MEASURABLE_BOREL_ALT3]
1239QED
1240
1241(*  |- !f a.
1242        sigma_algebra a /\ f IN Borel_measurable a ==>
1243        !c. {x | c < f x} INTER space a IN subsets a
1244
1245   NOTE: "OR" ("O" is at left of "R") means a left-open (O) half-interval (R).
1246 *)
1247Theorem IN_MEASURABLE_BOREL_OR = IN_MEASURABLE_BOREL_ALT3_IMP
1248
1249(* changed ‘!x. f x <> NegInf’ to ‘!x. x IN space a ==> f x <> NegInf’
1250
1251   NOTE: moved ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’
1252 *)
1253Theorem IN_MEASURABLE_BOREL_ALT4 :
1254    !f a. sigma_algebra a /\ (!x. x IN space a ==> f x <> NegInf) ==>
1255         (f IN measurable a Borel <=>
1256          f IN (space a -> UNIV) /\
1257          !c d. ({x | Normal c <= f x /\ f x < Normal d} INTER space a) IN subsets a)
1258Proof
1259    RW_TAC std_ss []
1260 >> EQ_TAC
1261 >- (rpt STRIP_TAC >- rfs [IN_MEASURABLE_BOREL] \\
1262    `{x | f x < Normal d} INTER space a IN subsets a`
1263        by METIS_TAC [IN_MEASURABLE_BOREL] \\
1264    `{x | Normal c <= f x} INTER space a IN subsets a`
1265        by METIS_TAC [IN_MEASURABLE_BOREL_ALT1] \\
1266     rfs [IN_MEASURABLE_BOREL] \\
1267    `(({x | Normal c <= f x} INTER space a) INTER
1268      ({x | f x < Normal d} INTER space a)) IN subsets a`
1269        by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER] \\
1270    `({x | Normal c <= f x} INTER space a) INTER ({x | f x < Normal d} INTER space a) =
1271     ({x | Normal c <= f x} INTER {x | f x < Normal d} INTER space a)`
1272        by METIS_TAC [INTER_ASSOC, INTER_COMM, INTER_IDEMPOT] \\
1273    `{x | Normal c <= f x} INTER {x | f x < Normal d} = {x | Normal c <= f x /\ f x < Normal d}`
1274        by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] \\
1275     METIS_TAC [SIGMA_ALGEBRA_INTER])
1276 >> RW_TAC std_ss [IN_MEASURABLE_BOREL]
1277 >> `!c. {x | f x < Normal c} INTER (space a) =
1278         BIGUNION
1279           (IMAGE (\n:num. {x | Normal (- &n) <= f x /\ f x < Normal c} INTER space a) UNIV)`
1280        by (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, IN_INTER] \\
1281            EQ_TAC >- (RW_TAC std_ss [GSPECIFICATION] \\
1282                      `f x <> PosInf` by METIS_TAC [lt_infty] \\
1283                      `?r. f x = Normal r` by METIS_TAC [extreal_cases] \\
1284                       METIS_TAC [SIMP_REAL_ARCH_NEG, extreal_le_def]) \\
1285            RW_TAC std_ss [GSPECIFICATION] \\
1286            METIS_TAC [lt_infty])
1287 >> `BIGUNION
1288       (IMAGE (\n:num. {x | Normal (- &n) <= f x /\ f x < Normal c} INTER space a) UNIV)
1289         IN subsets a`
1290        by (RW_TAC std_ss [] \\
1291            MP_TAC (Q.SPEC `a` SIGMA_ALGEBRA_FN) \\
1292            RW_TAC std_ss [] \\
1293           `(\n. {x | Normal (- &n) <= f x /\ f x < Normal c} INTER space a) IN (UNIV -> subsets a)`
1294                by (RW_TAC std_ss [IN_FUNSET]) \\
1295           `{x | Normal (-&n) <= f x /\ f x < Normal c} INTER space a IN subsets a` by METIS_TAC [] \\
1296            METIS_TAC [])
1297 >> METIS_TAC []
1298QED
1299
1300(* changed ‘!x. f x <> NegInf’ to ‘!x. x IN space a ==> f x <> NegInf’
1301
1302   NOTE: moved ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’
1303 *)
1304Theorem IN_MEASURABLE_BOREL_ALT5 :
1305    !f a. sigma_algebra a /\ (!x. x IN space a ==> f x <> NegInf) ==>
1306         (f IN measurable a Borel <=>
1307          f IN (space a -> UNIV) /\
1308          !c d. ({x | Normal c < f x /\ f x <= Normal d} INTER space a) IN subsets a)
1309Proof
1310    RW_TAC std_ss []
1311 >> EQ_TAC
1312 >- (rpt STRIP_TAC >- rfs [IN_MEASURABLE_BOREL]
1313     >> `{x | f x <= Normal d} INTER space a IN subsets a` by METIS_TAC [IN_MEASURABLE_BOREL_ALT2]
1314     >> `{x | Normal c < f x} INTER space a IN subsets a` by METIS_TAC [IN_MEASURABLE_BOREL_ALT3]
1315     >> rfs [IN_MEASURABLE_BOREL]
1316     >> `({x | Normal c < f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a) IN subsets a`
1317          by METIS_TAC [sigma_algebra_def,ALGEBRA_INTER]
1318     >> `({x | Normal c < f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a) =
1319          {x | Normal c < f x} INTER {x | f x <= Normal d} INTER space a`
1320          by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
1321     >> `{x | Normal c < f x} INTER {x | f x <= Normal d} = {x | Normal c < f x /\ f x <= Normal d}`
1322          by RW_TAC std_ss [EXTENSION ,GSPECIFICATION, IN_INTER]
1323     >> METIS_TAC [SIGMA_ALGEBRA_INTER])
1324 >> RW_TAC std_ss [IN_MEASURABLE_BOREL_ALT2]
1325 >> `!c. {x | f x <= Normal c} INTER (space a) =
1326          BIGUNION (IMAGE (\n:num. {x | Normal (- &n) < f x /\ f x <= Normal c } INTER space a) UNIV)`
1327        by (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, IN_INTER]
1328            >> EQ_TAC
1329            >- (RW_TAC std_ss [GSPECIFICATION]
1330                >> `f x <> PosInf` by METIS_TAC [le_infty,extreal_not_infty]
1331                >> `?r. f x = Normal r` by METIS_TAC [extreal_cases]
1332                >> FULL_SIMP_TAC std_ss [extreal_le_def,extreal_lt_eq]
1333                >> (MP_TAC o Q.SPEC `r`) SIMP_REAL_ARCH_NEG
1334                >> RW_TAC real_ss []
1335                >> Q.EXISTS_TAC `n+1`
1336                >> ONCE_REWRITE_TAC [GSYM REAL_ADD]
1337                >> RW_TAC real_ss [REAL_NEG_ADD, REAL_LT_ADD_SUB,REAL_LT_ADD1])
1338            >> RW_TAC std_ss [GSPECIFICATION] >> METIS_TAC [lt_infty])
1339 >> `BIGUNION (IMAGE (\n:num. {x | Normal (- &n) < f x /\ f x <= Normal c} INTER space a) UNIV) IN subsets a`
1340     by (RW_TAC std_ss []
1341         >> (MP_TAC o Q.SPEC `a`) SIGMA_ALGEBRA_FN
1342         >> RW_TAC std_ss []
1343         >> `(\n. {x | Normal (-&n) < f x /\ f x <= Normal c} INTER space a) IN (UNIV -> subsets a)`
1344            by FULL_SIMP_TAC real_ss [IN_FUNSET, GSPECIFICATION, IN_INTER]
1345         >> `{x | Normal (-&n) < f x /\ f x <= Normal c} INTER space a IN subsets a` by METIS_TAC []
1346         >> METIS_TAC [])
1347 >> METIS_TAC []
1348QED
1349
1350(* changed ‘!x. f x <> NegInf’ to ‘!x. x IN space a ==> f x <> NegInf’
1351
1352   NOTE: ‘sigma_algebra a’ is moved to antecedents due to changes of ‘measurable’
1353 *)
1354Theorem IN_MEASURABLE_BOREL_ALT6 :
1355    !f a. sigma_algebra a /\ (!x. x IN space a ==> f x <> NegInf) ==>
1356         (f IN measurable a Borel <=>
1357          f IN (space a -> UNIV) /\
1358          !c d. ({x | Normal c <= f x /\ f x <= Normal d} INTER space a) IN subsets a)
1359Proof
1360     RW_TAC std_ss []
1361  >> EQ_TAC
1362  >- (rpt STRIP_TAC >- rfs [IN_MEASURABLE_BOREL]
1363      >> `{x | f x <= Normal d} INTER space a IN subsets a` by METIS_TAC [IN_MEASURABLE_BOREL_ALT2]
1364      >> `{x | Normal c <= f x} INTER space a IN subsets a` by METIS_TAC [IN_MEASURABLE_BOREL_ALT1]
1365      >> rfs [IN_MEASURABLE_BOREL]
1366      >> `({x | Normal c <= f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a) IN subsets a`
1367         by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
1368      >> `({x | Normal c <= f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a) =
1369          ({x | Normal c <= f x} INTER {x | f x <= Normal d} INTER space a)`
1370         by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
1371      >> `{x | Normal c <= f x} INTER {x | f x <= Normal d} = {x | Normal c <= f x /\ f x <= Normal d}`
1372         by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
1373      >> `{x | Normal c <= f x} INTER {x | f x <= Normal d} = {x | Normal c <= f x /\ f x <= Normal d}`
1374         by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
1375      >> METIS_TAC [SIGMA_ALGEBRA_INTER])
1376  >> RW_TAC std_ss [IN_MEASURABLE_BOREL_ALT4]
1377  >> `!c. {x | Normal c <= f x /\ f x < Normal d} INTER (space a) =
1378          BIGUNION (IMAGE (\n:num. {x | Normal c <= f x /\
1379                                        f x <= Normal (d - (1/2) pow n)} INTER space a) UNIV)`
1380      by (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, IN_INTER, GSPECIFICATION]
1381          >> `(\n. c - (1 / 2) pow n) = (\n. (\n. c) n - (\n. (1 / 2) pow n) n)`
1382             by RW_TAC real_ss [FUN_EQ_THM]
1383          >> `(\n. c) --> c` by RW_TAC std_ss [SEQ_CONST]
1384          >> `(\n. (1 / 2) pow n) --> 0` by RW_TAC real_ss [SEQ_POWER]
1385          >> `(\n. c - (1 / 2) pow n) --> c`
1386             by METIS_TAC [Q.SPECL [`(\n. c)`,`c`,`(\n. (1/2) pow n)`,`0`] SEQ_SUB,REAL_SUB_RZERO]
1387          >> EQ_TAC
1388          >- (RW_TAC std_ss []
1389              >> `!e:real. 0 < e ==> ?N. !n. n >= N ==> abs ((1 / 2) pow n) < e`
1390                 by FULL_SIMP_TAC real_ss [Q.SPECL [`(\n. (1/2) pow n)`,`0`] SEQ,REAL_SUB_RZERO]
1391              >> `!n. abs ((1/2) pow n) = ((1/2) pow n):real` by FULL_SIMP_TAC real_ss [POW_POS,ABS_REFL]
1392              >> `!e:real. 0 < e ==> ?N. !n. n >= N ==> (1 / 2) pow n < e` by METIS_TAC []
1393              >> `f x <> PosInf` by METIS_TAC [lt_infty]
1394              >> `?r. f x = Normal r` by METIS_TAC [extreal_cases]
1395              >> FULL_SIMP_TAC std_ss [extreal_le_def,extreal_lt_eq]
1396              >> `?N. !n. n >= N ==> (1 / 2) pow n < d - r` by METIS_TAC [REAL_SUB_LT]
1397              >> Q.EXISTS_TAC `N`
1398              >> `(1 / 2) pow N < d - r` by FULL_SIMP_TAC real_ss []
1399              >> FULL_SIMP_TAC real_ss [GSYM REAL_LT_ADD_SUB, REAL_ADD_COMM, REAL_LT_IMP_LE])
1400          >> RW_TAC std_ss [] >|
1401             [ METIS_TAC[],
1402               `!n. - ((1 / 2) pow n) < 0:real`
1403                 by METIS_TAC [REAL_POW_LT, REAL_NEG_0, REAL_LT_NEG, EVAL ``0:real < 1/2``]
1404               >> `!n. d - (1 / 2) pow n < d` by METIS_TAC [REAL_LT_IADD, REAL_ADD_RID, real_sub]
1405               >> `f x <> PosInf` by METIS_TAC [le_infty,extreal_not_infty]
1406               >> `?r. f x = Normal r` by METIS_TAC [extreal_cases]
1407               >> FULL_SIMP_TAC std_ss [extreal_le_def,extreal_lt_eq]
1408               >> METIS_TAC [REAL_LET_TRANS],
1409               METIS_TAC [] ])
1410  >> `BIGUNION (IMAGE (\n:num. {x | Normal c <= f x /\
1411                                    f x <= Normal (d - ((1 / 2) pow n))} INTER space a) UNIV)
1412        IN subsets a`
1413      by (RW_TAC std_ss []
1414          >> (MP_TAC o Q.SPEC `a`) SIGMA_ALGEBRA_FN
1415          >> RW_TAC std_ss []
1416          >> `(\n. {x | Normal c <= f x /\ f x <= Normal (d - ((1 / 2) pow n))} INTER space a)
1417                IN (UNIV -> subsets a)`
1418             by FULL_SIMP_TAC real_ss [IN_FUNSET, GSPECIFICATION, IN_INTER]
1419          >> `{x | Normal c <= f x /\ f x <= Normal (d - ((1/2) pow n))} INTER space a IN subsets a`
1420             by METIS_TAC []
1421          >> METIS_TAC [])
1422  >> METIS_TAC []
1423QED
1424
1425(* changed ‘!x. f x <> NegInf’ to ‘!x. x IN space a ==> f x <> NegInf’
1426
1427   NOTE: ‘sigma_algebra a’ is moved to antecedents due to changes of ‘measurable’
1428 *)
1429Theorem IN_MEASURABLE_BOREL_ALT7 :
1430    !f a. sigma_algebra a /\ (!x. x IN space a ==> f x <> NegInf) ==>
1431         (f IN measurable a Borel <=>
1432          f IN (space a -> UNIV) /\
1433          !c d. ({x | Normal c < f x /\ f x < Normal d } INTER space a) IN subsets a)
1434Proof
1435  RW_TAC std_ss []
1436  >> EQ_TAC
1437  >- (rpt STRIP_TAC >- rfs [IN_MEASURABLE_BOREL]
1438      >> `(!d. {x | f x < Normal d} INTER space a IN subsets a)` by METIS_TAC [IN_MEASURABLE_BOREL]
1439      >> `(!c. {x | Normal c < f x} INTER space a IN subsets a)` by METIS_TAC [IN_MEASURABLE_BOREL_ALT3]
1440      >> FULL_SIMP_TAC std_ss [IN_MEASURABLE_BOREL]
1441      >> `!c d. (({x | Normal c < f x} INTER space a) INTER ({x | f x < Normal d} INTER space a)) IN subsets a` by METIS_TAC [sigma_algebra_def,ALGEBRA_INTER]
1442      >> `!c d. (({x | Normal c < f x} INTER space a) INTER ({x | f x < Normal d} INTER space a)) =
1443                 ({x | Normal c < f x} INTER {x | f x < Normal d} INTER space a)`
1444            by METIS_TAC [INTER_ASSOC,INTER_COMM,INTER_IDEMPOT]
1445      >> `{x | Normal c < f x} INTER {x | f x < Normal d} = {x | Normal c < f x /\ f x < Normal d}` by RW_TAC std_ss [EXTENSION,GSPECIFICATION,IN_INTER]
1446      >> `{x | Normal c < f x} INTER {x | f x < Normal d} = {x | Normal c < f x /\ f x < Normal d}` by RW_TAC std_ss [EXTENSION,GSPECIFICATION,IN_INTER]
1447      >> METIS_TAC [])
1448  >> RW_TAC std_ss [IN_MEASURABLE_BOREL]
1449  >> `!c. {x | f x < Normal c} INTER (space a) = BIGUNION (IMAGE (\n:num. {x | Normal (- &n) < f x /\ f x < Normal c } INTER space a) UNIV)`
1450        by (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV,IN_INTER]
1451            >> EQ_TAC
1452            >- (RW_TAC std_ss [GSPECIFICATION]
1453                >> `f x <> PosInf` by METIS_TAC [lt_infty]
1454                >> `?r. f x = Normal r` by METIS_TAC [extreal_cases]
1455                >> FULL_SIMP_TAC std_ss [extreal_le_def,extreal_lt_eq]
1456                >> (MP_TAC o Q.SPEC `r`) SIMP_REAL_ARCH_NEG
1457                     >> RW_TAC real_ss []
1458                     >> Q.EXISTS_TAC `n + 1`
1459                     >> ONCE_REWRITE_TAC [GSYM REAL_ADD]
1460                     >> RW_TAC real_ss [REAL_NEG_ADD, REAL_LT_ADD_SUB,REAL_LT_ADD1])
1461            >> RW_TAC std_ss [GSPECIFICATION] >> METIS_TAC [lt_infty])
1462  >> `BIGUNION (IMAGE (\n:num. {x | Normal (- &n) < f x /\ f x < Normal c } INTER space a) UNIV) IN subsets a`
1463        by (RW_TAC std_ss []
1464            >> (MP_TAC o Q.SPEC `a`) SIGMA_ALGEBRA_FN
1465            >> RW_TAC std_ss []
1466            >> `(\n. {x | Normal (-&n) < f x /\ f x < Normal c} INTER space a) IN (UNIV -> subsets a)` by FULL_SIMP_TAC real_ss [IN_FUNSET,GSPECIFICATION,IN_INTER]
1467            >> `{x | Normal (-&n) < f x /\ f x < Normal c} INTER space a IN subsets a` by METIS_TAC []
1468            >> METIS_TAC [])
1469  >> METIS_TAC []
1470QED
1471
1472Theorem IN_MEASURABLE_BOREL_ALT4_IMP_r[local] :
1473    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1474          !c d. ({x | Normal c <= f x /\ f x < Normal d} INTER space a) IN subsets a
1475Proof
1476    RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1477 >> `!d. {x | f x < Normal d} INTER space a IN subsets a` by METIS_TAC [IN_MEASURABLE_BOREL]
1478 >> `!c. {x | Normal c <= f x} INTER space a IN subsets a` by METIS_TAC [IN_MEASURABLE_BOREL_ALT1]
1479 >> FULL_SIMP_TAC std_ss [IN_MEASURABLE_BOREL]
1480 >> `!c d. (({x | Normal c <= f x} INTER space a) INTER ({x | f x < Normal d} INTER space a)) IN subsets a`
1481    by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
1482 >> `!c d. (({x | Normal c <= f x} INTER space a) INTER ({x | f x < Normal d} INTER space a)) =
1483            ({x | Normal c <= f x} INTER {x | f x < Normal d} INTER space a)`
1484    by METIS_TAC [INTER_ASSOC, INTER_COMM, INTER_IDEMPOT]
1485 >> `{x | Normal c <= f x} INTER {x | f x < Normal d} = {x | Normal c <= f x /\ f x < Normal d}`
1486    by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
1487 >> METIS_TAC []
1488QED
1489
1490Theorem IN_MEASURABLE_BOREL_ALT4_IMP_p[local] :
1491    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1492          !c. ({x | Normal c <= f x /\ f x < PosInf} INTER space a) IN subsets a
1493Proof
1494    RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1495 >> Know `{x | f x < PosInf} INTER space a IN subsets a`
1496 >- (REWRITE_TAC [GSYM lt_infty] \\
1497     METIS_TAC [IN_MEASURABLE_BOREL_NOT_POSINF]) >> DISCH_TAC
1498 >> `!c. {x | Normal c <= f x} INTER space a IN subsets a` by METIS_TAC [IN_MEASURABLE_BOREL_ALT1]
1499 >> FULL_SIMP_TAC std_ss [IN_MEASURABLE_BOREL]
1500 >> `!c. (({x | Normal c <= f x} INTER space a) INTER ({x | f x < PosInf} INTER space a)) IN subsets a`
1501    by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
1502 >> `!c. (({x | Normal c <= f x} INTER space a) INTER ({x | f x < PosInf} INTER space a)) =
1503          ({x | Normal c <= f x} INTER {x | f x < PosInf} INTER space a)`
1504    by METIS_TAC [INTER_ASSOC, INTER_COMM, INTER_IDEMPOT]
1505 >> `{x | Normal c <= f x} INTER {x | f x < PosInf} = {x | Normal c <= f x /\ f x < PosInf}`
1506    by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
1507 >> METIS_TAC []
1508QED
1509
1510(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1511Theorem IN_MEASURABLE_BOREL_ALT4_IMP :
1512    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1513          !c d. ({x | c <= f x /\ f x < d} INTER space a) IN subsets a
1514Proof
1515    rpt STRIP_TAC
1516 >> Cases_on `c` >> Cases_on `d` (* 9 subgoals *)
1517 >- ((* goal 1 (of 9) *)
1518     REWRITE_TAC [lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1519     rfs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1520 >- ((* goal 2 (of 9) *)
1521     REWRITE_TAC [GSYM lt_infty, le_infty] \\
1522     MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [])
1523 >- ((* goal 3 (of 9) *)
1524     REWRITE_TAC [le_infty] \\
1525     MATCH_MP_TAC IN_MEASURABLE_BOREL_IMP >> art [])
1526 >- ((* goal 4 (of 9) *)
1527     REWRITE_TAC [lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1528     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1529 >- ((* goal 5 (of 9) *)
1530     SIMP_TAC std_ss [GSYM lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1531     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1532 >- ((* goal 6 (of 9) *)
1533     `!x. PosInf <= f x /\ f x < Normal r <=> F`
1534        by METIS_TAC [le_infty, lt_infty, extreal_not_infty, lt_imp_ne] \\
1535     POP_ORW >> REWRITE_TAC [GSPEC_F, INTER_EMPTY] \\
1536     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1537 >- ((* goal 7 (of 9) *)
1538     REWRITE_TAC [lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1539     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1540 >- ((* goal 8 (of 9) *)
1541     MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT4_IMP_p >> art [])
1542 (* goal 9 (of 9) *)
1543 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT4_IMP_r >> art []
1544QED
1545
1546(* |- !f a.
1547        sigma_algebra a /\ f IN Borel_measurable a ==>
1548        !c d. {x | c <= f x /\ f x < d} INTER space a IN subsets a
1549
1550   NOTE: "CO" means left-closed (C) and right-open (O) intervals.
1551 *)
1552Theorem IN_MEASURABLE_BOREL_CO = IN_MEASURABLE_BOREL_ALT4_IMP
1553
1554Theorem IN_MEASURABLE_BOREL_ALT5_IMP_r[local] :
1555    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1556          !c d. ({x | Normal c < f x /\ f x <= Normal d} INTER space a) IN subsets a
1557Proof
1558    RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1559 >> `(!d. {x | f x <= Normal d} INTER space a IN subsets a)` by METIS_TAC [IN_MEASURABLE_BOREL_ALT2]
1560 >> `(!c. {x | Normal c < f x} INTER space a IN subsets a)` by METIS_TAC [IN_MEASURABLE_BOREL_ALT3]
1561 >> FULL_SIMP_TAC std_ss [IN_MEASURABLE_BOREL]
1562 >> `!c d. (({x | Normal c < f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a)) IN subsets a`
1563    by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
1564 >> `!c d. (({x | Normal c < f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a)) =
1565           ({x | Normal c < f x} INTER {x | f x <= Normal d} INTER space a)`
1566    by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
1567 >> `{x | Normal c < f x} INTER {x | f x <= Normal d} =
1568     {x | Normal c < f x /\ f x <= Normal d}` by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
1569 >> METIS_TAC []
1570QED
1571
1572Theorem IN_MEASURABLE_BOREL_ALT5_IMP_n[local] :
1573    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1574          !d. ({x | NegInf < f x /\ f x <= Normal d} INTER space a) IN subsets a
1575Proof
1576    RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1577 >> `!d. {x | f x <= Normal d} INTER space a IN subsets a` by METIS_TAC [IN_MEASURABLE_BOREL_ALT2]
1578 >> Know `{x | NegInf < f x} INTER space a IN subsets a`
1579 >- (REWRITE_TAC [GSYM lt_infty] \\
1580     METIS_TAC [IN_MEASURABLE_BOREL_NOT_NEGINF]) >> DISCH_TAC
1581 >> FULL_SIMP_TAC std_ss [IN_MEASURABLE_BOREL]
1582 >> `!d. (({x | NegInf < f x} INTER space a) INTER
1583          ({x | f x <= Normal d} INTER space a)) IN subsets a`
1584    by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
1585 >> `!d. (({x | NegInf < f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a)) =
1586          ({x | NegInf < f x} INTER {x | f x <= Normal d} INTER space a)`
1587    by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
1588 >> `{x | NegInf < f x} INTER {x | f x <= Normal d} =
1589     {x | NegInf < f x /\ f x <= Normal d}` by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
1590 >> METIS_TAC []
1591QED
1592
1593(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1594Theorem IN_MEASURABLE_BOREL_ALT5_IMP :
1595    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1596          !c d. ({x | c < f x /\ f x <= d} INTER space a) IN subsets a
1597Proof
1598    rpt STRIP_TAC
1599 >> Cases_on `c` >> Cases_on `d` (* 9 subgoals *)
1600 >- ((* goal 1 (of 9) *)
1601     `!x. NegInf < f x /\ f x <= NegInf <=> F`
1602        by METIS_TAC [le_infty, lt_infty, extreal_not_infty, lt_imp_ne] \\
1603     POP_ORW >> REWRITE_TAC [GSPEC_F, INTER_EMPTY] \\
1604     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1605 >- ((* goal 2 (of 9) *)
1606     REWRITE_TAC [GSYM lt_infty, le_infty] \\
1607     MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [])
1608 >- ((* goal 3 (of 9) *)
1609     MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT5_IMP_n >> art [])
1610 >- ((* goal 4 (of 9) *)
1611     REWRITE_TAC [lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1612     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1613 >- ((* goal 5 (of 9) *)
1614     REWRITE_TAC [lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1615     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1616 >- ((* goal 6 (of 9) *)
1617     REWRITE_TAC [lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1618     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1619 >- ((* goal 7 (of 9) *)
1620     `!x. Normal r < f x /\ f x <= NegInf <=> F`
1621       by METIS_TAC [lt_infty, le_infty, extreal_not_infty, lt_imp_ne] \\
1622     POP_ORW >> REWRITE_TAC [GSPEC_F, INTER_EMPTY] \\
1623     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1624 >- ((* goal 8 (of 9) *)
1625     REWRITE_TAC [le_infty] \\
1626     MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT3_IMP >> art [])
1627 (* goal 9 (of 9) *)
1628 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT5_IMP_r >> art []
1629QED
1630
1631(* |- !f a.
1632        sigma_algebra a /\ f IN Borel_measurable a ==>
1633        !c d. {x | c < f x /\ f x <= d} INTER space a IN subsets a
1634 *)
1635Theorem IN_MEASURABLE_BOREL_OC = IN_MEASURABLE_BOREL_ALT5_IMP
1636
1637Theorem IN_MEASURABLE_BOREL_ALT6_IMP_r[local] :
1638    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1639          !c d. ({x| Normal c <= f x /\ f x <= Normal d} INTER space a) IN subsets a
1640Proof
1641    RW_TAC std_ss [IN_FUNSET,IN_UNIV]
1642 >> `(!d. {x | f x <= Normal d} INTER space a IN subsets a)` by METIS_TAC [IN_MEASURABLE_BOREL_ALT2]
1643 >> `(!c. {x | Normal c <= f x} INTER space a IN subsets a)` by METIS_TAC [IN_MEASURABLE_BOREL_ALT1]
1644 >> rfs [IN_MEASURABLE_BOREL]
1645 >> `!c d. (({x | Normal c <= f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a)) IN subsets a`
1646    by METIS_TAC [sigma_algebra_def,ALGEBRA_INTER]
1647 >> `!c d. (({x | Normal c <= f x} INTER space a) INTER ({x | f x <= Normal d} INTER space a)) =
1648           ({x | Normal c <= f x} INTER {x | f x <= Normal d} INTER space a)`
1649    by (RW_TAC std_ss [EXTENSION,GSPECIFICATION,IN_INTER] >> METIS_TAC [])
1650 >> `{x | Normal c <= f x} INTER {x | f x <= Normal d} = {x | Normal c <= f x /\ f x <= Normal d}`
1651    by RW_TAC std_ss [EXTENSION,GSPECIFICATION,IN_INTER]
1652 >> `{x | Normal c <= f x} INTER {x | f x <= Normal d} = {x | Normal c <= f x /\ f x <= Normal d}`
1653    by RW_TAC std_ss [EXTENSION,GSPECIFICATION,IN_INTER]
1654 >> METIS_TAC []
1655QED
1656
1657(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1658Theorem IN_MEASURABLE_BOREL_ALT6_IMP :
1659    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1660          !c d. ({x| c <= f x /\ f x <= d} INTER space a) IN subsets a
1661Proof
1662    rpt STRIP_TAC
1663 >> Cases_on `c` >> Cases_on `d` (* 9 subgoals *)
1664 >- ((* goal 1 (of 9) *)
1665     REWRITE_TAC [GSYM lt_infty, le_infty] \\
1666     MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [])
1667 >- ((* goal 2 (of 9) *)
1668     REWRITE_TAC [le_infty, GSPEC_T, INTER_UNIV] \\
1669     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_SPACE])
1670 >- ((* goal 3 (of 9) *)
1671     REWRITE_TAC [le_infty] \\
1672     MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT2_IMP >> art [])
1673 >- ((* goal 4 (of 9) *)
1674     `!x. PosInf <= f x /\ f x <= NegInf <=> F`
1675        by METIS_TAC [le_infty, lt_infty, extreal_not_infty, extreal_cases] \\
1676     POP_ORW >> REWRITE_TAC [GSPEC_F, INTER_EMPTY] \\
1677     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1678 >- ((* goal 5 (of 9) *)
1679     REWRITE_TAC [le_infty] \\
1680     MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [])
1681 >- ((* goal 6 (of 9) *)
1682     `!x. PosInf <= f x /\ f x <= Normal r <=> F`
1683       by METIS_TAC [lt_infty, le_infty, extreal_not_infty, lt_imp_ne] \\
1684     POP_ORW >> REWRITE_TAC [GSPEC_F, INTER_EMPTY] \\
1685     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1686 >- ((* goal 7 (of 9) *)
1687     `!x. Normal r <= f x /\ f x <= NegInf <=> F`
1688       by METIS_TAC [lt_infty, le_infty, extreal_not_infty, lt_imp_ne] \\
1689     POP_ORW >> REWRITE_TAC [GSPEC_F, INTER_EMPTY] \\
1690     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1691 >- ((* goal 8 (of 9) *)
1692     REWRITE_TAC [le_infty] \\
1693     MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT1_IMP >> art [])
1694 (* goal 9 (of 9) *)
1695 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT6_IMP_r >> art []
1696QED
1697
1698(* |- !f a.
1699        sigma_algebra a /\ f IN Borel_measurable a ==>
1700        !c d. {x | c <= f x /\ f x <= d} INTER space a IN subsets a: thm
1701 *)
1702Theorem IN_MEASURABLE_BOREL_CC = IN_MEASURABLE_BOREL_ALT6_IMP
1703
1704Theorem IN_MEASURABLE_BOREL_ALT7_IMP_r[local] :
1705    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1706          !c d. ({x | Normal c < f x /\ f x < Normal d} INTER space a) IN subsets a
1707Proof
1708    RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1709 >> `(!d. {x | f x < Normal d} INTER space a IN subsets a)` by METIS_TAC [IN_MEASURABLE_BOREL]
1710 >> `(!c. {x | Normal c < f x} INTER space a IN subsets a)` by METIS_TAC [IN_MEASURABLE_BOREL_ALT3]
1711 >> rfs [IN_MEASURABLE_BOREL]
1712 >> `!c d. (({x | Normal c < f x} INTER space a) INTER ({x | f x < Normal d} INTER space a)) IN subsets a`
1713    by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
1714 >> `!c d. ({x | Normal c < f x} INTER space a) INTER ({x | f x < Normal d} INTER space a) =
1715           ({x | Normal c < f x} INTER {x | f x < Normal d} INTER space a)`
1716    by METIS_TAC [INTER_ASSOC, INTER_COMM, INTER_IDEMPOT]
1717 >> `{x | Normal c < f x} INTER {x | f x < Normal d} = {x | Normal c < f x /\ f x < Normal d}`
1718    by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
1719 >> `{x | Normal c < f x} INTER {x | f x < Normal d} = {x | Normal c < f x /\ f x < Normal d}`
1720    by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
1721 >> METIS_TAC []
1722QED
1723
1724Theorem IN_MEASURABLE_BOREL_ALT7_IMP_np[local] :
1725    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1726          ({x | NegInf < f x /\ f x < PosInf} INTER space a) IN subsets a
1727Proof
1728    rpt STRIP_TAC
1729 >> IMP_RES_TAC IN_MEASURABLE_BOREL_ALT7_IMP_r
1730 >> rfs [IN_MEASURABLE_BOREL, IN_FUNSET, IN_UNIV]
1731 >> Know `{x | NegInf < f x /\ f x < PosInf} INTER space a =
1732          BIGUNION (IMAGE (\n. {x | -&n < f x /\ f x < &n} INTER space a) UNIV)`
1733 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION, IN_INTER] \\
1734     EQ_TAC
1735     >- (RW_TAC std_ss [GSYM lt_infty] \\
1736         `?n1. -&n1 <= f x` by PROVE_TAC [SIMP_EXTREAL_ARCH_NEG] \\
1737         `?n2. f x <= &n2` by PROVE_TAC [SIMP_EXTREAL_ARCH] \\
1738         Q.EXISTS_TAC `SUC (MAX n1 n2)` \\
1739         CONJ_TAC >- (MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC `-&n1` >> art [] \\
1740                      SIMP_TAC std_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT] \\
1741                      MATCH_MP_TAC LESS_EQ_IMP_LESS_SUC \\
1742                      REWRITE_TAC [MAX_LE] >> DISJ1_TAC >> REWRITE_TAC [LESS_EQ_REFL]) \\
1743         MATCH_MP_TAC let_trans >> Q.EXISTS_TAC `&n2` >> art [] \\
1744         SIMP_TAC std_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT] \\
1745         MATCH_MP_TAC LESS_EQ_IMP_LESS_SUC \\
1746         REWRITE_TAC [MAX_LE] >> DISJ2_TAC >> REWRITE_TAC [LESS_EQ_REFL]) \\
1747     RW_TAC std_ss [] >| (* 3 subgoals *)
1748     [ METIS_TAC [num_not_infty, lt_infty],
1749       METIS_TAC [num_not_infty, lt_infty],
1750       ASM_REWRITE_TAC [] ])
1751 >> Rewr'
1752 >> fs [SIGMA_ALGEBRA_FN]
1753 >> FIRST_X_ASSUM MATCH_MP_TAC
1754 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1755 >> `&n = Normal (&n)` by PROVE_TAC [extreal_of_num_def]
1756 >> `-&n = Normal (-&n)` by PROVE_TAC [extreal_ainv_def, extreal_of_num_def]
1757 >> METIS_TAC []
1758QED
1759
1760Theorem IN_MEASURABLE_BOREL_ALT7_IMP_n[local] :
1761    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1762          !d. ({x | NegInf < f x /\ f x < Normal d} INTER space a) IN subsets a
1763Proof
1764    rpt STRIP_TAC
1765 >> IMP_RES_TAC IN_MEASURABLE_BOREL_ALT7_IMP_r
1766 >> rfs [IN_MEASURABLE_BOREL, IN_FUNSET, IN_UNIV]
1767 >> Know `{x | NegInf < f x /\ f x < Normal d} INTER space a =
1768          BIGUNION (IMAGE (\n. {x | -&n < f x /\ f x < Normal d} INTER space a) UNIV)`
1769 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION, IN_INTER] \\
1770     EQ_TAC
1771     >- (RW_TAC std_ss [GSYM lt_infty] \\
1772         `?n. -&n <= f x` by PROVE_TAC [SIMP_EXTREAL_ARCH_NEG] \\
1773         Q.EXISTS_TAC `SUC n` \\
1774         MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC `-&n` >> art [] \\
1775         SIMP_TAC arith_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT]) \\
1776     RW_TAC std_ss [] >| (* 3 subgoals *)
1777     [ METIS_TAC [num_not_infty, lt_infty],
1778       ASM_REWRITE_TAC [],
1779       ASM_REWRITE_TAC [] ])
1780 >> Rewr'
1781 >> fs [SIGMA_ALGEBRA_FN]
1782 >> FIRST_X_ASSUM MATCH_MP_TAC
1783 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1784 >> `-&n = Normal (-&n)` by PROVE_TAC [extreal_ainv_def, extreal_of_num_def]
1785 >> METIS_TAC []
1786QED
1787
1788Theorem IN_MEASURABLE_BOREL_ALT7_IMP_p[local] :
1789    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1790          !c. ({x | Normal c < f x /\ f x < PosInf} INTER space a) IN subsets a
1791Proof
1792    rpt STRIP_TAC
1793 >> IMP_RES_TAC IN_MEASURABLE_BOREL_ALT7_IMP_r
1794 >> rfs [IN_MEASURABLE_BOREL, IN_FUNSET, IN_UNIV]
1795 >> Know `{x | Normal c < f x /\ f x < PosInf} INTER space a =
1796          BIGUNION (IMAGE (\n. {x | Normal c < f x /\ f x < &n} INTER space a) UNIV)`
1797 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION, IN_INTER] \\
1798     EQ_TAC
1799     >- (RW_TAC std_ss [GSYM lt_infty] \\
1800         `?n. f x <= &n` by PROVE_TAC [SIMP_EXTREAL_ARCH] \\
1801         Q.EXISTS_TAC `SUC n` \\
1802         MATCH_MP_TAC let_trans >> Q.EXISTS_TAC `&n` >> art [] \\
1803         SIMP_TAC arith_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT]) \\
1804     RW_TAC std_ss [] >| (* 3 subgoals *)
1805     [ METIS_TAC [num_not_infty, lt_infty],
1806       METIS_TAC [num_not_infty, lt_infty],
1807       ASM_REWRITE_TAC [] ])
1808 >> Rewr'
1809 >> fs [SIGMA_ALGEBRA_FN]
1810 >> FIRST_X_ASSUM MATCH_MP_TAC
1811 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1812 >> `&n = Normal (&n)` by PROVE_TAC [extreal_of_num_def]
1813 >> METIS_TAC []
1814QED
1815
1816(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1817Theorem IN_MEASURABLE_BOREL_ALT7_IMP :
1818    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1819          !c d. ({x | c < f x /\ f x < d} INTER space a) IN subsets a
1820Proof
1821    rpt STRIP_TAC
1822 >> Cases_on `c` >> Cases_on `d` (* 9 subgoals *)
1823 >- ((* goal 1 (of 9) *)
1824     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1825     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1826 >- ((* goal 2 (of 9) *)
1827     MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT7_IMP_np >> art [])
1828 >- ((* goal 3 (of 9) *)
1829     MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT7_IMP_n >> art [])
1830 >- ((* goal 4 (of 9) *)
1831     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1832     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1833 >- ((* goal 5 (of 9) *)
1834     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1835     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1836 >- ((* goal 6 (of 9) *)
1837     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1838     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1839 >- ((* goal 7 (of 9) *)
1840     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
1841     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
1842 >- ((* goal 8 (of 9) *)
1843     MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT7_IMP_p >> art [])
1844 (* goal 9 (of 9) *)
1845 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_ALT7_IMP_r >> art []
1846QED
1847
1848(* |- !f a.
1849        sigma_algebra a /\ f IN Borel_measurable a ==>
1850        !c d. {x | c < f x /\ f x < d} INTER space a IN subsets a
1851 *)
1852Theorem IN_MEASURABLE_BOREL_OO = IN_MEASURABLE_BOREL_ALT7_IMP
1853
1854Theorem IN_MEASURABLE_BOREL_ALT8_r[local] :
1855    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1856          !c. ({x | f x = Normal c} INTER space a) IN subsets a
1857Proof
1858    RW_TAC std_ss [IN_FUNSET, IN_UNIV]
1859 >> MP_TAC IN_MEASURABLE_BOREL_ALT4_IMP_r
1860 >> RW_TAC std_ss []
1861 >> Know `!c. {x | f x = Normal c} INTER (space a) =
1862              BIGINTER (IMAGE (\n. {x | Normal (c - ((1/2) pow n)) <= f x /\
1863                                        f x < Normal (c + ((1/2) pow n))} INTER space a) UNIV)`
1864 >- (RW_TAC std_ss [EXTENSION, IN_BIGINTER_IMAGE, IN_UNIV,IN_SING,IN_INTER] \\
1865     EQ_TAC >- RW_TAC real_ss [extreal_le_def, extreal_lt_eq, GSPECIFICATION, REAL_POW_LT,
1866                               REAL_LT_IMP_LE, REAL_LT_ADDR, REAL_LT_DIV, HALF_POS,
1867                               REAL_LT_ADDNEG2, real_sub, IN_INTER] \\
1868     RW_TAC std_ss [GSPECIFICATION] \\
1869    `f x <> PosInf` by METIS_TAC [lt_infty] \\
1870    `f x <> NegInf` by METIS_TAC [le_infty, extreal_not_infty] \\
1871    `?r. f x = Normal r` by METIS_TAC [extreal_cases] \\
1872     FULL_SIMP_TAC std_ss [extreal_le_def, extreal_lt_eq, extreal_11] \\
1873    `!n. c - (1 / 2) pow n <= r` by FULL_SIMP_TAC real_ss [real_sub] \\
1874    `!n. r <= c + (1 / 2) pow n` by FULL_SIMP_TAC real_ss [REAL_LT_IMP_LE] \\
1875    `(\n. c - (1 / 2) pow n) = (\n. (\n. c) n - (\n. (1 / 2) pow n) n)`
1876        by RW_TAC real_ss [FUN_EQ_THM] \\
1877    `(\n. c + (1 / 2) pow n) = (\n. (\n. c) n + (\n. (1 / 2) pow n) n)`
1878        by RW_TAC real_ss [FUN_EQ_THM] \\
1879    `(\n. c) --> c` by RW_TAC std_ss [SEQ_CONST] \\
1880    `(\n. (1 / 2) pow n) --> 0` by RW_TAC real_ss [SEQ_POWER] \\
1881    `(\n. c - (1 / 2) pow n) --> c`
1882        by METIS_TAC [Q.SPECL [`(\n. c)`,`c`,`(\n. (1/2) pow n)`,`0`] SEQ_SUB, REAL_SUB_RZERO] \\
1883    `(\n. c + (1 / 2) pow n) --> c`
1884        by METIS_TAC [Q.SPECL [`(\n. c)`,`c`,`(\n. (1/2) pow n)`,`0`] SEQ_ADD, REAL_ADD_RID] \\
1885    `c <= r` by METIS_TAC [Q.SPECL [`r`,`c`,`(\n. c - (1 / 2) pow n)`] SEQ_LE_IMP_LIM_LE] \\
1886    `r <= c` by METIS_TAC [Q.SPECL [`r`,`c`,`(\n. c + (1 / 2) pow n)`] LE_SEQ_IMP_LE_LIM] \\
1887     METIS_TAC [REAL_LE_ANTISYM]) >> Rewr'
1888 >> RW_TAC std_ss []
1889 >> MP_TAC (Q.SPEC `a` SIGMA_ALGEBRA_FN_BIGINTER)
1890 >> RW_TAC std_ss []
1891 >> `(\n. {x | Normal (c - ((1/2) pow n)) <= f x /\
1892               f x < Normal (c + ((1/2) pow n))} INTER space a) IN (UNIV -> subsets a)`
1893        by (RW_TAC std_ss [IN_FUNSET])
1894 >> METIS_TAC [IN_MEASURABLE_BOREL]
1895QED
1896
1897(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1898Theorem IN_MEASURABLE_BOREL_ALT8 :
1899    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1900          !c. ({x | f x = c} INTER space a) IN subsets a
1901Proof
1902    rpt STRIP_TAC
1903 >> Cases_on `c` (* 3 subgoals *)
1904 >| [ (* goal 1 (of 3) *)
1905      RW_TAC std_ss [IN_MEASURABLE_BOREL] \\
1906      MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [IN_MEASURABLE_BOREL],
1907      (* goal 2 (of 3) *)
1908      RW_TAC std_ss [IN_MEASURABLE_BOREL_ALT3] \\
1909      MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [IN_MEASURABLE_BOREL_ALT3],
1910      (* goal 3 (of 3) *)
1911      IMP_RES_TAC IN_MEASURABLE_BOREL_ALT8_r >> art [] ]
1912QED
1913
1914(* |- !f a.
1915        sigma_algebra a /\ f IN Borel_measurable a ==>
1916        !c. {x | f x = c} INTER space a IN subsets a
1917 *)
1918Theorem IN_MEASURABLE_BOREL_SING = IN_MEASURABLE_BOREL_ALT8
1919
1920(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1921Theorem IN_MEASURABLE_BOREL_ALT9 :
1922    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
1923          !c. ({x | f x <> c} INTER space a) IN subsets a
1924Proof
1925    rpt STRIP_TAC
1926 >> IMP_RES_TAC IN_MEASURABLE_BOREL_SING
1927 >> Know `!c. {x | f x <> c} INTER (space a) =
1928              space a DIFF ({x | f x = c} INTER space a)`
1929 >- (RW_TAC std_ss [EXTENSION, IN_UNIV, IN_DIFF, IN_INTER, GSPECIFICATION] \\
1930     EQ_TAC >- (rpt STRIP_TAC >> art []) \\
1931     METIS_TAC []) >> Rewr
1932 >> rfs [IN_MEASURABLE_BOREL]
1933 >> MATCH_MP_TAC SIGMA_ALGEBRA_COMPL >> art []
1934QED
1935
1936(* |- !f a.
1937        sigma_algebra a /\ f IN Borel_measurable a ==>
1938        !c. {x | f x <> c} INTER space a IN subsets a
1939 *)
1940Theorem IN_MEASURABLE_BOREL_NOT_SING = IN_MEASURABLE_BOREL_ALT9
1941
1942(* All IMP versions of IN_MEASURABLE_BOREL_ALTs
1943
1944   NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’
1945 *)
1946Theorem IN_MEASURABLE_BOREL_ALL :
1947    !f a.
1948        sigma_algebra a /\ f IN measurable a Borel ==>
1949        (!c. {x | f x < c} INTER space a IN subsets a) /\
1950        (!c. {x | c <= f x} INTER space a IN subsets a) /\
1951        (!c. {x | f x <= c} INTER space a IN subsets a) /\
1952        (!c. {x | c < f x} INTER space a IN subsets a) /\
1953        (!c d. {x | c <= f x /\ f x < d} INTER space a IN subsets a) /\
1954        (!c d. {x | c < f x /\ f x <= d} INTER space a IN subsets a) /\
1955        (!c d. {x | c <= f x /\ f x <= d} INTER space a IN subsets a) /\
1956        (!c d. {x | c < f x /\ f x < d} INTER space a IN subsets a) /\
1957        (!c. {x | f x = c} INTER space a IN subsets a) /\
1958        (!c. {x | f x <> c} INTER space a IN subsets a)
1959Proof
1960    METIS_TAC [IN_MEASURABLE_BOREL_RO,         (* f x < c *)
1961               IN_MEASURABLE_BOREL_CR,         (* c <= f x *)
1962               IN_MEASURABLE_BOREL_RC,         (* f x <= c *)
1963               IN_MEASURABLE_BOREL_OR,         (* c < f x *)
1964               IN_MEASURABLE_BOREL_CO,         (* c <= f x /\ f x < d *)
1965               IN_MEASURABLE_BOREL_OC,         (* c < f x /\ f x <= d *)
1966               IN_MEASURABLE_BOREL_CC,         (* c <= f x /\ f x <= d *)
1967               IN_MEASURABLE_BOREL_OO,         (* c < f x /\ f x < d *)
1968               IN_MEASURABLE_BOREL_SING,       (* f x = c *)
1969               IN_MEASURABLE_BOREL_NOT_SING]   (* f x <> c *)
1970QED
1971
1972(* |- !f m.
1973        sigma_algebra (measurable_space m) /\ f IN Borel_measurable (measurable_space m) ==>
1974        (!c. {x | f x < c} INTER m_space m IN measurable_sets m) /\
1975        (!c. {x | c <= f x} INTER m_space m IN measurable_sets m) /\
1976        (!c. {x | f x <= c} INTER m_space m IN measurable_sets m) /\
1977        (!c. {x | c < f x} INTER m_space m IN measurable_sets m) /\
1978        (!c d. {x | c <= f x /\ f x < d} INTER m_space m IN measurable_sets m) /\
1979        (!c d. {x | c < f x /\ f x <= d} INTER m_space m IN measurable_sets m) /\
1980        (!c d. {x | c <= f x /\ f x <= d} INTER m_space m IN measurable_sets m) /\
1981        (!c d. {x | c < f x /\ f x < d} INTER m_space m IN measurable_sets m) /\
1982        (!c. {x | f x = c} INTER m_space m IN measurable_sets m) /\
1983        !c. {x | f x <> c} INTER m_space m IN measurable_sets m: thm
1984 *)
1985Theorem IN_MEASURABLE_BOREL_ALL_MEASURE =
1986  ((Q.GENL [`f`, `m`]) o
1987   (REWRITE_RULE [space_def, subsets_def]) o
1988   (Q.SPECL [`f`, `(m_space m,measurable_sets m)`])) IN_MEASURABLE_BOREL_ALL
1989
1990(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
1991Theorem IN_MEASURABLE_BOREL_LT :
1992    !f g a. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel ==>
1993            ({x | f x < g x} INTER space a) IN subsets a
1994Proof
1995  RW_TAC std_ss []
1996  >> `{x | f x < g x} INTER space a =
1997      BIGUNION (IMAGE (\r. {x | f x < r /\ r < g x} INTER space a) Q_set)`
1998        by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_BIGUNION_IMAGE, IN_INTER]
1999            >> EQ_TAC
2000            >- RW_TAC std_ss [Q_DENSE_IN_R]
2001            >> METIS_TAC [lt_trans])
2002  >> POP_ORW
2003  >> MATCH_MP_TAC BIGUNION_IMAGE_Q >> art []
2004  >> RW_TAC std_ss [IN_FUNSET]
2005  >> `{x | f x < r /\ r < g x} INTER space a =
2006     ({x | f x < r} INTER space a) INTER ({x | r < g x} INTER space a)`
2007       by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
2008  >> POP_ORW
2009  >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
2010  >> METIS_TAC [IN_MEASURABLE_BOREL_ALL]
2011QED
2012
2013(* changed quantifier orders (was: f g a)
2014
2015   NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’
2016 *)
2017Theorem IN_MEASURABLE_BOREL_LE :
2018    !a f g. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel ==>
2019            ({x | f x <= g x} INTER space a) IN subsets a
2020Proof
2021    RW_TAC std_ss []
2022 >> `{x | f x <= g x} INTER space a = space a DIFF ({x | g x < f x} INTER space a)`
2023      by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER, IN_DIFF] \\
2024          METIS_TAC [extreal_lt_def])
2025 >> `{x | g x < f x} INTER space a IN subsets a` by RW_TAC std_ss [IN_MEASURABLE_BOREL_LT]
2026 >> METIS_TAC [algebra_def, IN_MEASURABLE_BOREL, sigma_algebra_def]
2027QED
2028
2029Theorem IN_MEASURABLE_BOREL_EQ' :
2030    !a f g. (!x. x IN space a ==> (f x = g x)) /\
2031            g IN measurable a Borel ==> f IN measurable a Borel
2032Proof
2033    rw [measurable_def, IN_FUNSET]
2034 >> Know ‘PREIMAGE f s INTER space a = PREIMAGE g s INTER space a’
2035 >- (rw [Once EXTENSION, PREIMAGE_def] \\
2036     METIS_TAC [])
2037 >> Rewr'
2038 >> FIRST_X_ASSUM MATCH_MP_TAC >> art []
2039QED
2040
2041Theorem IN_MEASURABLE_BOREL_EQ_SYM :
2042    !a f g. (!x. x IN space a ==> (f x = g x)) ==>
2043            (f IN measurable a Borel <=> g IN measurable a Borel)
2044Proof
2045    rpt STRIP_TAC
2046 >> EQ_TAC >> STRIP_TAC
2047 >| [ (* goal 1 (of 2) *)
2048      MATCH_MP_TAC IN_MEASURABLE_BOREL_EQ' \\
2049      Q.EXISTS_TAC ‘f’ >> rw [],
2050      (* goal 2 (of 2) *)
2051      MATCH_MP_TAC IN_MEASURABLE_BOREL_EQ' \\
2052      Q.EXISTS_TAC ‘g’ >> rw [] ]
2053QED
2054
2055(* changed quantifier orders (was: f g m) for applications in martingaleTheory *)
2056Theorem IN_MEASURABLE_BOREL_EQ :
2057    !m f g. (!x. x IN m_space m ==> (f x = g x)) /\
2058            g IN measurable (m_space m,measurable_sets m) Borel ==>
2059            f IN measurable (m_space m,measurable_sets m) Borel
2060Proof
2061    rpt STRIP_TAC
2062 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_EQ'
2063 >> Q.EXISTS_TAC ‘g’ >> rw []
2064QED
2065
2066(* cf. IN_MEASURABLE_CONG (sigma_algebraTheory) for a more general version *)
2067Theorem IN_MEASURABLE_BOREL_CONG :
2068    !m f g. (!x. x IN m_space m ==> (f x = g x)) ==>
2069            (f IN measurable (m_space m,measurable_sets m) Borel <=>
2070             g IN measurable (m_space m,measurable_sets m) Borel)
2071Proof
2072    rpt STRIP_TAC
2073 >> EQ_TAC >> STRIP_TAC
2074 >| [ (* goal 1 (of 2) *)
2075      MATCH_MP_TAC IN_MEASURABLE_BOREL_EQ \\
2076      Q.EXISTS_TAC ‘f’ >> rw [],
2077      (* goal 2 (of 2) *)
2078      MATCH_MP_TAC IN_MEASURABLE_BOREL_EQ \\
2079      Q.EXISTS_TAC ‘g’ >> rw [] ]
2080QED
2081
2082(*****************************************************)
2083
2084Theorem BOREL_MEASURABLE_SETS_RO_r[local]:
2085    !c. {x | x < Normal c} IN subsets Borel
2086Proof
2087    RW_TAC std_ss [Borel_def]
2088 >> MATCH_MP_TAC IN_SIGMA
2089 >> RW_TAC std_ss [IN_IMAGE, IN_UNIV]
2090 >> METIS_TAC []
2091QED
2092
2093Theorem BOREL_MEASURABLE_SETS_NEGINF[local]:  (* new *)
2094    {x | x = NegInf} IN subsets Borel
2095Proof
2096 (* proof *)
2097    Know `{x | x = NegInf} = BIGINTER (IMAGE (\n. {x | x < -(&n)}) UNIV)`
2098 >- (RW_TAC std_ss [EXTENSION, IN_BIGINTER_IMAGE, IN_UNIV, GSPECIFICATION] \\
2099     EQ_TAC >- METIS_TAC [num_not_infty,lt_infty,extreal_ainv_def,extreal_of_num_def] \\
2100     RW_TAC std_ss [] \\
2101     SPOSE_NOT_THEN ASSUME_TAC \\
2102     METIS_TAC [SIMP_EXTREAL_ARCH_NEG, extreal_lt_def, extreal_ainv_def, neg_neg, lt_neg])
2103 >> Rewr'
2104 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2105 >> IMP_RES_TAC SIGMA_ALGEBRA_FN_BIGINTER
2106 >> POP_ASSUM MATCH_MP_TAC
2107 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
2108 >> `-&n = Normal (- &n)` by PROVE_TAC [extreal_ainv_def, extreal_of_num_def] >> POP_ORW
2109 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_RO_r]
2110QED
2111
2112Theorem BOREL_MEASURABLE_SETS_NEGINF'[local]:  (* new *)
2113    {NegInf} IN subsets Borel
2114Proof
2115    Know `{NegInf} = {x | x = NegInf}`
2116 >- RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_SING]
2117 >> Rewr' >> REWRITE_TAC [BOREL_MEASURABLE_SETS_NEGINF]
2118QED
2119
2120Theorem BOREL_MEASURABLE_SETS_NOT_POSINF[local]:  (* new *)
2121    {x | x <> PosInf} IN subsets Borel
2122Proof
2123    Know `{x | x <> PosInf} = BIGUNION (IMAGE (\n. {x | x < &n}) UNIV)`
2124 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION] \\
2125     EQ_TAC
2126     >- (DISCH_TAC \\
2127         `?n. x <= &n` by PROVE_TAC [SIMP_EXTREAL_ARCH] \\
2128         Q.EXISTS_TAC `SUC n` \\
2129         MATCH_MP_TAC let_trans >> Q.EXISTS_TAC `&n` >> art [] \\
2130         SIMP_TAC arith_ss [extreal_of_num_def, extreal_lt_eq, REAL_LT]) \\
2131     RW_TAC std_ss [] >> METIS_TAC [num_not_infty, lt_infty])
2132 >> Rewr'
2133 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2134 >> fs [SIGMA_ALGEBRA_FN]
2135 >> FIRST_X_ASSUM MATCH_MP_TAC
2136 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
2137 >> `&n = Normal (&n)` by PROVE_TAC [extreal_of_num_def] >> POP_ORW
2138 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_RO_r]
2139QED
2140
2141Theorem BOREL_MEASURABLE_SETS_RO:   !c. {x | x < c} IN subsets Borel
2142Proof
2143    GEN_TAC >> Cases_on `c`
2144 >- (REWRITE_TAC [lt_infty, GSPEC_F, INTER_EMPTY] \\
2145     PROVE_TAC [SIGMA_ALGEBRA_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
2146 >- REWRITE_TAC [GSYM lt_infty, BOREL_MEASURABLE_SETS_NOT_POSINF]
2147 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_RO_r]
2148QED
2149
2150Theorem BOREL_MEASURABLE_SETS_CR_r[local]:
2151    !c. {x | Normal c <= x} IN subsets Borel
2152Proof
2153    RW_TAC std_ss []
2154 >> `{x | Normal c <= x} = UNIV DIFF {x | x < Normal c}`
2155      by RW_TAC std_ss [extreal_lt_def, EXTENSION, GSPECIFICATION, DIFF_DEF, IN_UNIV, real_lte]
2156 >> METIS_TAC [SPACE_BOREL, SIGMA_ALGEBRA_BOREL, sigma_algebra_def, algebra_def,
2157               BOREL_MEASURABLE_SETS_RO]
2158QED
2159
2160Theorem BOREL_MEASURABLE_SETS_RC_r[local]:
2161    !c. {x | x <= Normal c} IN subsets Borel
2162Proof
2163    RW_TAC std_ss []
2164 >> `!c. {x | x <= Normal c} = BIGINTER (IMAGE (\n:num. {x | x < Normal (c + (1/2) pow n)}) UNIV)`
2165         by (RW_TAC std_ss [EXTENSION, IN_BIGINTER_IMAGE, IN_UNIV,IN_INTER]
2166             >> EQ_TAC
2167             >- (RW_TAC std_ss [GSPECIFICATION]
2168                 >> `0:real < (1/2) pow n` by RW_TAC real_ss [REAL_POW_LT]
2169                 >> Cases_on `x = NegInf` >- METIS_TAC [lt_infty]
2170                 >> `x <> PosInf` by METIS_TAC [le_infty,extreal_not_infty]
2171                 >> `0 < Normal ((1 / 2) pow n)` by METIS_TAC [extreal_lt_eq,extreal_of_num_def]
2172                 >> RW_TAC std_ss [GSYM extreal_add_def]
2173                 >> METIS_TAC [extreal_of_num_def,extreal_not_infty,let_add2,add_rzero])
2174                    >> RW_TAC std_ss [GSPECIFICATION]
2175                    >> `!n. x < Normal (c + (1 / 2) pow n)` by METIS_TAC []
2176                    >> `(\n. c + (1 / 2) pow n) = (\n. (\n. c) n + (\n. (1 / 2) pow n) n)`
2177                  by RW_TAC real_ss [FUN_EQ_THM]
2178                    >> `(\n. c) --> c` by RW_TAC std_ss [SEQ_CONST]
2179                    >> `(\n. (1 / 2) pow n) --> 0` by RW_TAC real_ss [SEQ_POWER]
2180                    >> `(\n. c + (1 / 2) pow n) --> c`
2181                  by METIS_TAC [Q.SPECL [`(\n. c)`,`c`,`(\n. (1/2) pow n)`,`0`] SEQ_ADD,REAL_ADD_RID]
2182             >> Cases_on `x = NegInf` >- RW_TAC std_ss [le_infty]
2183             >> `x <> PosInf` by METIS_TAC [lt_infty]
2184             >> `?r. x = Normal r` by METIS_TAC [extreal_cases]
2185             >> FULL_SIMP_TAC std_ss [extreal_le_def,extreal_lt_eq]
2186             >> METIS_TAC [REAL_LT_IMP_LE,
2187                           Q.SPECL [`r`,`c`,`(\n. c + (1 / 2) pow n)`] LE_SEQ_IMP_LE_LIM])
2188 >> FULL_SIMP_TAC std_ss []
2189 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2190 >> (MP_TAC o UNDISCH o Q.SPEC `Borel`)
2191        (INST_TYPE [alpha |-> ``:extreal``] SIGMA_ALGEBRA_FN_BIGINTER)
2192 >> RW_TAC std_ss []
2193 >> Q.PAT_X_ASSUM `!f. P f ==> Q f` (MP_TAC o Q.SPEC `(\n. {x | x < Normal (c + (1 / 2) pow n)})`)
2194 >> `(\n. {x | x < Normal (c + (1 / 2) pow n)}) IN (UNIV -> subsets Borel)`
2195        by RW_TAC std_ss [IN_FUNSET,BOREL_MEASURABLE_SETS_RO]
2196 >> METIS_TAC []
2197QED
2198
2199Theorem BOREL_MEASURABLE_SETS_RC:   !c. {x | x <= c} IN subsets Borel
2200Proof
2201    GEN_TAC >> Cases_on `c`
2202 >- (REWRITE_TAC [le_infty, BOREL_MEASURABLE_SETS_NEGINF])
2203 >- (REWRITE_TAC [le_infty, GSPEC_T] \\
2204     PROVE_TAC [SIGMA_ALGEBRA_BOREL, sigma_algebra_def, ALGEBRA_SPACE, SPACE_BOREL])
2205 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_RC_r]
2206QED
2207
2208Theorem BOREL_MEASURABLE_SETS_OR_r[local]:
2209    !c. {x | Normal c < x} IN subsets Borel
2210Proof
2211    GEN_TAC
2212 >> `{x | Normal c < x} = UNIV DIFF {x | x <= Normal c}`
2213     by RW_TAC std_ss [extreal_lt_def, EXTENSION, GSPECIFICATION, DIFF_DEF, IN_UNIV, real_lte]
2214 >> METIS_TAC [SPACE_BOREL, SIGMA_ALGEBRA_BOREL, sigma_algebra_def, algebra_def,
2215               BOREL_MEASURABLE_SETS_RC]
2216QED
2217
2218Theorem BOREL_MEASURABLE_SETS_NOT_NEGINF[local]:  (* new *)
2219    {x | x <> NegInf} IN subsets Borel
2220Proof
2221    Know `{x | x <> NegInf} = BIGUNION (IMAGE (\n. {x | -(&n) < x}) UNIV)`
2222 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION] \\
2223     EQ_TAC
2224     >- (DISCH_TAC \\
2225         `?n. -(&n) <= x` by PROVE_TAC [SIMP_EXTREAL_ARCH_NEG] \\
2226         Q.EXISTS_TAC `SUC n` \\
2227         MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC `-&n` >> art [] \\
2228         SIMP_TAC arith_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT]) \\
2229     RW_TAC std_ss [] >> METIS_TAC [num_not_infty, lt_infty]) >> Rewr'
2230 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2231 >> fs [SIGMA_ALGEBRA_FN]
2232 >> FIRST_X_ASSUM MATCH_MP_TAC
2233 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
2234 >> `-&n = Normal (-&n)` by PROVE_TAC [extreal_ainv_def, extreal_of_num_def] >> POP_ORW
2235 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_OR_r]
2236QED
2237
2238Theorem BOREL_MEASURABLE_SETS_OR:   !c. {x | c < x} IN subsets Borel
2239Proof
2240    GEN_TAC >> Cases_on `c`
2241 >- (REWRITE_TAC [GSYM lt_infty, BOREL_MEASURABLE_SETS_NOT_NEGINF])
2242 >- (REWRITE_TAC [lt_infty, GSPEC_F] \\
2243     PROVE_TAC [SIGMA_ALGEBRA_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
2244 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_OR_r]
2245QED
2246
2247Theorem BOREL_MEASURABLE_SETS_POSINF[local]:  (* new *)
2248    {x | x = PosInf} IN subsets Borel
2249Proof
2250    Know `{x | x = PosInf} = BIGINTER (IMAGE (\n. {x | &n < x}) UNIV)`
2251 >- (RW_TAC std_ss [EXTENSION, IN_BIGINTER_IMAGE, IN_UNIV, GSPECIFICATION] \\
2252     EQ_TAC >- METIS_TAC [num_not_infty, lt_infty, extreal_ainv_def, extreal_of_num_def] \\
2253     RW_TAC std_ss [] \\
2254     SPOSE_NOT_THEN ASSUME_TAC \\
2255     METIS_TAC [SIMP_EXTREAL_ARCH, extreal_lt_def])
2256 >> Rewr'
2257 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2258 >> IMP_RES_TAC SIGMA_ALGEBRA_FN_BIGINTER
2259 >> POP_ASSUM MATCH_MP_TAC
2260 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
2261 >> `&n = Normal (&n)` by PROVE_TAC [extreal_of_num_def] >> POP_ORW
2262 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_OR]
2263QED
2264
2265Theorem BOREL_MEASURABLE_SETS_POSINF'[local]:  (* new *)
2266    {PosInf} IN subsets Borel
2267Proof
2268    Know `{PosInf} = {x | x = PosInf}`
2269 >- RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_SING]
2270 >> Rewr' >> REWRITE_TAC [BOREL_MEASURABLE_SETS_POSINF]
2271QED
2272
2273(* for compatibility with lebesgue_measure_hvgTheory *)
2274Theorem BOREL_MEASURABLE_INFINITY :
2275    {PosInf} IN subsets Borel /\ {NegInf} IN subsets Borel
2276Proof
2277    REWRITE_TAC [BOREL_MEASURABLE_SETS_POSINF',
2278                 BOREL_MEASURABLE_SETS_NEGINF']
2279QED
2280
2281Theorem BOREL_MEASURABLE_SETS_CR:
2282    !c. {x | c <= x} IN subsets Borel
2283Proof
2284    GEN_TAC >> Cases_on `c`
2285 >- (REWRITE_TAC [le_infty, GSPEC_T] \\
2286     PROVE_TAC [SIGMA_ALGEBRA_BOREL, sigma_algebra_def, ALGEBRA_SPACE, SPACE_BOREL])
2287 >- REWRITE_TAC [le_infty, BOREL_MEASURABLE_SETS_POSINF]
2288 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_CR_r]
2289QED
2290
2291Theorem BOREL_MEASURABLE_SETS_CO_r[local]:
2292    !c d. {x | Normal c <= x /\ x < Normal d} IN subsets Borel
2293Proof
2294    rpt GEN_TAC
2295 >> `!d. {x | x < Normal d} IN subsets Borel` by METIS_TAC [BOREL_MEASURABLE_SETS_RO]
2296 >> `!c. {x | Normal c <= x} IN subsets Borel` by METIS_TAC [BOREL_MEASURABLE_SETS_CR]
2297 >> `{x | Normal c <= x /\ x < Normal d} = {x | Normal c <= x} INTER {x | x < Normal d}`
2298        by  RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
2299 >> METIS_TAC [sigma_algebra_def, ALGEBRA_INTER, SIGMA_ALGEBRA_BOREL]
2300QED
2301
2302Theorem BOREL_MEASURABLE_SETS_CO_p[local]:  (* new *)
2303    !c d. {x | Normal c <= x /\ x < PosInf} IN subsets Borel
2304Proof
2305    rpt GEN_TAC
2306 >> Know `{x | x < PosInf} IN subsets Borel`
2307 >- (REWRITE_TAC [GSYM lt_infty] \\
2308     REWRITE_TAC [BOREL_MEASURABLE_SETS_NOT_POSINF]) >> DISCH_TAC
2309 >> `!c. {x | Normal c <= x} IN subsets Borel` by REWRITE_TAC [BOREL_MEASURABLE_SETS_CR]
2310 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2311 >> `!c. {x | Normal c <= x} INTER {x | x < PosInf} IN subsets Borel`
2312    by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
2313 >> `{x | Normal c <= x /\ x < PosInf} = {x | Normal c <= x} INTER {x | x < PosInf}`
2314    by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> POP_ORW
2315 >> METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
2316QED
2317
2318Theorem BOREL_MEASURABLE_SETS_CO:
2319    !c d. {x | c <= x /\ x < d} IN subsets Borel
2320Proof
2321    rpt GEN_TAC
2322 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2323 >> Cases_on `c` >> Cases_on `d` (* 9 subgoals *)
2324 >- ((* goal 1 (of 9) *)
2325     REWRITE_TAC [lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
2326     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2327 >- ((* goal 2 (of 9) *)
2328     REWRITE_TAC [GSYM lt_infty, le_infty] \\
2329     REWRITE_TAC [BOREL_MEASURABLE_SETS_NOT_POSINF])
2330 >- ((* goal 3 (of 9) *)
2331     REWRITE_TAC [le_infty] \\
2332     REWRITE_TAC [BOREL_MEASURABLE_SETS_RO])
2333 >- ((* goal 4 (of 9) *)
2334     REWRITE_TAC [lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
2335     fs [IN_MEASURABLE_BOREL, sigma_algebra_def, ALGEBRA_EMPTY])
2336 >- ((* goal 5 (of 9) *)
2337     SIMP_TAC std_ss [GSYM lt_infty, le_infty, GSPEC_F, INTER_EMPTY] \\
2338     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2339 >- ((* goal 6 (of 9) *)
2340     `!x. PosInf <= x /\ x < Normal r <=> F`
2341        by METIS_TAC [le_infty, lt_infty, extreal_not_infty, lt_imp_ne] \\
2342     POP_ORW >> REWRITE_TAC [GSPEC_F] \\
2343     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2344 >- ((* goal 7 (of 9) *)
2345     REWRITE_TAC [lt_infty, le_infty, GSPEC_F] \\
2346     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2347 >- ((* goal 8 (of 9) *)
2348     REWRITE_TAC [BOREL_MEASURABLE_SETS_CO_p])
2349 (* goal 9 (of 9) *)
2350 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_CO_r]
2351QED
2352
2353Theorem BOREL_MEASURABLE_SETS_OC_r[local]:
2354    !c d. {x | Normal c < x /\ x <= Normal d} IN subsets Borel
2355Proof
2356    rpt GEN_TAC
2357 >> `!d. {x | x <= Normal d} IN subsets Borel` by METIS_TAC [BOREL_MEASURABLE_SETS_RC]
2358 >> `!c. {x | Normal c < x} IN subsets Borel` by METIS_TAC [BOREL_MEASURABLE_SETS_OR]
2359 >> `{x | Normal c < x /\ x <= Normal d} = {x | Normal c < x} INTER {x | x <= Normal d}`
2360        by  RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
2361 >> METIS_TAC [sigma_algebra_def, ALGEBRA_INTER, SIGMA_ALGEBRA_BOREL]
2362QED
2363
2364Theorem BOREL_MEASURABLE_SETS_OC_n[local]:  (* new *)
2365    !d. {x | NegInf < x /\ x <= Normal d} IN subsets Borel
2366Proof
2367    GEN_TAC
2368 >> `!d. {x | x <= Normal d} IN subsets Borel` by REWRITE_TAC [BOREL_MEASURABLE_SETS_RC]
2369 >> Know `{x | NegInf < x} IN subsets Borel`
2370 >- (REWRITE_TAC [GSYM lt_infty] \\
2371     REWRITE_TAC [BOREL_MEASURABLE_SETS_NOT_NEGINF]) >> DISCH_TAC
2372 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2373 >> `!d. ({x | NegInf < x} INTER {x | x <= Normal d}) IN subsets Borel`
2374    by METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
2375 >> `{x | NegInf < x /\ x <= Normal d} = {x | NegInf < x} INTER {x | x <= Normal d}`
2376    by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> POP_ORW
2377 >> METIS_TAC [sigma_algebra_def, ALGEBRA_INTER, SIGMA_ALGEBRA_BOREL]
2378QED
2379
2380Theorem BOREL_MEASURABLE_SETS_OC:
2381    !c d. {x | c < x /\ x <= d} IN subsets Borel
2382Proof
2383    rpt GEN_TAC
2384 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2385 >> Cases_on `c` >> Cases_on `d` (* 9 subgoals *)
2386 >- ((* goal 1 (of 9) *)
2387     `!x. NegInf < x /\ x <= NegInf <=> F`
2388        by METIS_TAC [le_infty, lt_infty, extreal_not_infty, lt_imp_ne] \\
2389     POP_ORW >> REWRITE_TAC [GSPEC_F] \\
2390     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2391 >- ((* goal 2 (of 9) *)
2392     REWRITE_TAC [GSYM lt_infty, le_infty] \\
2393     REWRITE_TAC [BOREL_MEASURABLE_SETS_NOT_NEGINF])
2394 >- ((* goal 3 (of 9) *)
2395     REWRITE_TAC [BOREL_MEASURABLE_SETS_OC_n])
2396 >- ((* goal 4 (of 9) *)
2397     REWRITE_TAC [lt_infty, le_infty, GSPEC_F] \\
2398     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2399 >- ((* goal 5 (of 9) *)
2400     REWRITE_TAC [lt_infty, le_infty, GSPEC_F] \\
2401     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2402 >- ((* goal 6 (of 9) *)
2403     REWRITE_TAC [lt_infty, le_infty, GSPEC_F] \\
2404     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2405 >- ((* goal 7 (of 9) *)
2406     `!x. Normal r < x /\ x <= NegInf <=> F`
2407       by METIS_TAC [lt_infty, le_infty, extreal_not_infty, lt_imp_ne] \\
2408     POP_ORW >> REWRITE_TAC [GSPEC_F] \\
2409     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2410 >- ((* goal 8 (of 9) *)
2411     REWRITE_TAC [le_infty] \\
2412     REWRITE_TAC [BOREL_MEASURABLE_SETS_OR])
2413 (* goal 9 (of 9) *)
2414 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_OC_r]
2415QED
2416
2417Theorem BOREL_MEASURABLE_SETS_CC_r[local]:
2418    !c d. {x | Normal c <= x /\ x <= Normal d} IN subsets Borel
2419Proof
2420    rpt GEN_TAC
2421 >> `!d. {x | x <= Normal d} IN subsets Borel` by METIS_TAC [BOREL_MEASURABLE_SETS_RC]
2422 >> `!c. {x | Normal c <= x} IN subsets Borel` by METIS_TAC [BOREL_MEASURABLE_SETS_CR]
2423 >> `{x | Normal c <= x /\ x <= Normal d} = {x | Normal c <= x} INTER {x | x <= Normal d}`
2424        by  RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
2425 >> METIS_TAC [sigma_algebra_def, ALGEBRA_INTER, SIGMA_ALGEBRA_BOREL]
2426QED
2427
2428Theorem BOREL_MEASURABLE_SETS_CC:   !c d. {x | c <= x /\ x <= d} IN subsets Borel
2429Proof
2430    rpt GEN_TAC
2431 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2432 >> Cases_on `c` >> Cases_on `d` (* 9 subgoals *)
2433 >- ((* goal 1 (of 9) *)
2434     REWRITE_TAC [GSYM lt_infty, le_infty] \\
2435     REWRITE_TAC [BOREL_MEASURABLE_SETS_NEGINF])
2436 >- ((* goal 2 (of 9) *)
2437     REWRITE_TAC [le_infty, GSPEC_T] \\
2438     METIS_TAC [sigma_algebra_def, ALGEBRA_SPACE, SPACE_BOREL])
2439 >- ((* goal 3 (of 9) *)
2440     REWRITE_TAC [le_infty] \\
2441     REWRITE_TAC [BOREL_MEASURABLE_SETS_RC])
2442 >- ((* goal 4 (of 9) *)
2443     `!x. PosInf <= x /\ x <= NegInf <=> F`
2444        by METIS_TAC [le_infty, lt_infty, extreal_not_infty, extreal_cases] \\
2445     POP_ORW >> REWRITE_TAC [GSPEC_F] \\
2446     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2447 >- ((* goal 5 (of 9) *)
2448     REWRITE_TAC [le_infty] \\
2449     REWRITE_TAC [BOREL_MEASURABLE_SETS_POSINF])
2450 >- ((* goal 6 (of 9) *)
2451     `!x. PosInf <= x /\ x <= Normal r <=> F`
2452       by METIS_TAC [lt_infty, le_infty, extreal_not_infty, lt_imp_ne] \\
2453     POP_ORW >> REWRITE_TAC [GSPEC_F] \\
2454     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2455 >- ((* goal 7 (of 9) *)
2456     `!x. Normal r <= x /\ x <= NegInf <=> F`
2457       by METIS_TAC [lt_infty, le_infty, extreal_not_infty, lt_imp_ne] \\
2458     POP_ORW >> REWRITE_TAC [GSPEC_F] \\
2459     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2460 >- ((* goal 8 (of 9) *)
2461     REWRITE_TAC [le_infty] \\
2462     REWRITE_TAC [BOREL_MEASURABLE_SETS_CR])
2463 (* goal 9 (of 9) *)
2464 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_CC_r]
2465QED
2466
2467Theorem BOREL_MEASURABLE_SETS_OO_r[local]:  (* not "00_r" *)
2468    !c d. {x | Normal c < x /\ x < Normal d} IN subsets Borel
2469Proof
2470    rpt GEN_TAC
2471 >> `!d. {x | x < Normal d} IN subsets Borel` by METIS_TAC [BOREL_MEASURABLE_SETS_RO]
2472 >> `!c. {x | Normal c < x} IN subsets Borel` by METIS_TAC [BOREL_MEASURABLE_SETS_OR]
2473 >> `{x | Normal c < x /\ x < Normal d} = {x | Normal c < x} INTER {x | x < Normal d}`
2474       by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
2475 >> METIS_TAC [sigma_algebra_def, ALGEBRA_INTER, SIGMA_ALGEBRA_BOREL]
2476QED
2477
2478Theorem BOREL_MEASURABLE_SETS_OO_np[local]:  (* new, not "00_np" *)
2479    {x | NegInf < x /\ x < PosInf} IN subsets Borel
2480Proof
2481    ASSUME_TAC SIGMA_ALGEBRA_BOREL
2482 >> Know `{x | NegInf < x /\ x < PosInf} =
2483          BIGUNION (IMAGE (\n. {x | -&n < x /\ x < &n}) UNIV)`
2484 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION] \\
2485     EQ_TAC
2486     >- (RW_TAC std_ss [GSYM lt_infty] \\
2487         `?n1. -&n1 <= x` by PROVE_TAC [SIMP_EXTREAL_ARCH_NEG] \\
2488         `?n2. x <= &n2` by PROVE_TAC [SIMP_EXTREAL_ARCH] \\
2489         Q.EXISTS_TAC `SUC (MAX n1 n2)` \\
2490         CONJ_TAC >- (MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC `-&n1` >> art [] \\
2491                      SIMP_TAC std_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT] \\
2492                      MATCH_MP_TAC LESS_EQ_IMP_LESS_SUC \\
2493                      REWRITE_TAC [MAX_LE] >> DISJ1_TAC >> REWRITE_TAC [LESS_EQ_REFL]) \\
2494         MATCH_MP_TAC let_trans >> Q.EXISTS_TAC `&n2` >> art [] \\
2495         SIMP_TAC std_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT] \\
2496         MATCH_MP_TAC LESS_EQ_IMP_LESS_SUC \\
2497         REWRITE_TAC [MAX_LE] >> DISJ2_TAC >> REWRITE_TAC [LESS_EQ_REFL]) \\
2498     RW_TAC std_ss [] >| (* 2 subgoals *)
2499     [ METIS_TAC [num_not_infty, lt_infty],
2500       METIS_TAC [num_not_infty, lt_infty] ])
2501 >> Rewr'
2502 >> fs [SIGMA_ALGEBRA_FN]
2503 >> FIRST_X_ASSUM MATCH_MP_TAC
2504 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
2505 >> `&n = Normal (&n)` by PROVE_TAC [extreal_of_num_def]
2506 >> `-&n = Normal (-&n)` by PROVE_TAC [extreal_ainv_def, extreal_of_num_def]
2507 >> ASM_REWRITE_TAC [BOREL_MEASURABLE_SETS_OO_r]
2508QED
2509
2510Theorem BOREL_MEASURABLE_SETS_OO_n[local]:  (* new, not "00_n" *)
2511    !d. {x | NegInf < x /\ x < Normal d} IN subsets Borel
2512Proof
2513    GEN_TAC
2514 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2515 >> Know `{x | NegInf < x /\ x < Normal d} =
2516          BIGUNION (IMAGE (\n. {x | -&n < x /\ x < Normal d}) UNIV)`
2517 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION] \\
2518     EQ_TAC
2519     >- (RW_TAC std_ss [GSYM lt_infty] \\
2520         `?n. -&n <= x` by PROVE_TAC [SIMP_EXTREAL_ARCH_NEG] \\
2521         Q.EXISTS_TAC `SUC n` \\
2522         MATCH_MP_TAC lte_trans >> Q.EXISTS_TAC `-&n` >> art [] \\
2523         SIMP_TAC arith_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT]) \\
2524     RW_TAC std_ss [] >| (* 2 subgoals *)
2525     [ METIS_TAC [num_not_infty, lt_infty],
2526       ASM_REWRITE_TAC [] ])
2527 >> Rewr'
2528 >> fs [SIGMA_ALGEBRA_FN]
2529 >> FIRST_X_ASSUM MATCH_MP_TAC
2530 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
2531 >> `-&n = Normal (-&n)` by PROVE_TAC [extreal_ainv_def, extreal_of_num_def]
2532 >> ASM_REWRITE_TAC [BOREL_MEASURABLE_SETS_OO_r]
2533QED
2534
2535Theorem BOREL_MEASURABLE_SETS_OO_p[local]:  (* new, not "00_p" *)
2536    !c. {x | Normal c < x /\ x < PosInf} IN subsets Borel
2537Proof
2538    GEN_TAC
2539 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2540 >> Know `{x | Normal c < x /\ x < PosInf} =
2541          BIGUNION (IMAGE (\n. {x | Normal c < x /\ x < &n}) UNIV)`
2542 >- (RW_TAC std_ss [EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, GSPECIFICATION] \\
2543     EQ_TAC
2544     >- (RW_TAC std_ss [GSYM lt_infty] \\
2545         `?n. x <= &n` by PROVE_TAC [SIMP_EXTREAL_ARCH] \\
2546         Q.EXISTS_TAC `SUC n` \\
2547         MATCH_MP_TAC let_trans >> Q.EXISTS_TAC `&n` >> art [] \\
2548         SIMP_TAC arith_ss [lt_neg, extreal_of_num_def, extreal_lt_eq, REAL_LT]) \\
2549     RW_TAC std_ss [] >| (* 3 subgoals *)
2550     [ METIS_TAC [num_not_infty, lt_infty],
2551       METIS_TAC [num_not_infty, lt_infty] ])
2552 >> Rewr'
2553 >> fs [SIGMA_ALGEBRA_FN]
2554 >> FIRST_X_ASSUM MATCH_MP_TAC
2555 >> RW_TAC std_ss [IN_FUNSET, IN_UNIV]
2556 >> `&n = Normal (&n)` by PROVE_TAC [extreal_of_num_def]
2557 >> ASM_REWRITE_TAC [BOREL_MEASURABLE_SETS_OO_r]
2558QED
2559
2560Theorem BOREL_MEASURABLE_SETS_OO:   !c d. {x | c < x /\ x < d} IN subsets Borel
2561Proof
2562    rpt GEN_TAC
2563 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2564 >> Cases_on `c` >> Cases_on `d` (* 9 subgoals *)
2565 >- ((* goal 1 (of 9) *)
2566     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F] \\
2567     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2568 >- ((* goal 2 (of 9) *)
2569     REWRITE_TAC [BOREL_MEASURABLE_SETS_OO_np])
2570 >- ((* goal 3 (of 9) *)
2571     REWRITE_TAC [BOREL_MEASURABLE_SETS_OO_n])
2572 >- ((* goal 4 (of 9) *)
2573     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F] \\
2574     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2575 >- ((* goal 5 (of 9) *)
2576     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F] \\
2577     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2578 >- ((* goal 6 (of 9) *)
2579     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F] \\
2580     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2581 >- ((* goal 7 (of 9) *)
2582     REWRITE_TAC [GSYM lt_infty, le_infty, GSPEC_F] \\
2583     fs [sigma_algebra_def, ALGEBRA_EMPTY])
2584 >- ((* goal 8 (of 9) *)
2585     REWRITE_TAC [BOREL_MEASURABLE_SETS_OO_p])
2586 (* goal 9 (of 9) *)
2587 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_OO_r]
2588QED
2589
2590Theorem BOREL_MEASURABLE_SETS_SING_r[local]:
2591    !c. {Normal c} IN subsets Borel
2592Proof
2593    RW_TAC std_ss []
2594 >> Know `!c. {Normal c} = BIGINTER (IMAGE (\n. {x | Normal (c - ((1/2) pow n)) <= x /\
2595                                                     x < Normal (c + ((1/2) pow n))}) UNIV)`
2596 >- (RW_TAC std_ss [EXTENSION, IN_BIGINTER_IMAGE, IN_UNIV, IN_SING, IN_INTER] \\
2597     EQ_TAC >- RW_TAC real_ss [extreal_lt_eq, extreal_le_def, GSPECIFICATION,
2598                               REAL_POW_LT, REAL_LT_IMP_LE, REAL_LT_ADDR, REAL_LT_DIV,
2599                               HALF_POS, REAL_LT_ADDNEG2, real_sub, IN_INTER] \\
2600     RW_TAC std_ss [GSPECIFICATION] \\
2601    `!n. Normal (c - (1/2) pow n) <= x` by FULL_SIMP_TAC real_ss [real_sub] \\
2602    `!n. x <= Normal (c + (1/2) pow n)` by FULL_SIMP_TAC real_ss [lt_imp_le] \\
2603    `(\n. c - (1/2) pow n) = (\n. (\n. c) n - (\n. (1/2) pow n) n)`
2604       by RW_TAC real_ss [FUN_EQ_THM] \\
2605    `(\n. c + (1/2) pow n) = (\n. (\n. c) n + (\n. (1/2) pow n) n)`
2606       by RW_TAC real_ss [FUN_EQ_THM] \\
2607    `(\n. c) --> c` by RW_TAC std_ss [SEQ_CONST] \\
2608    `(\n. (1/2) pow n) --> 0` by RW_TAC real_ss [SEQ_POWER] \\
2609    `(\n. c - (1/2) pow n) --> c`
2610       by METIS_TAC [Q.SPECL [`(\n. c)`, `c`, `(\n. (1/2) pow n)`, `0`] SEQ_SUB, REAL_SUB_RZERO] \\
2611    `(\n. c + (1/2) pow n) --> c`
2612       by METIS_TAC [Q.SPECL [`(\n. c)`, `c`, `(\n. (1/2) pow n)`, `0`] SEQ_ADD, REAL_ADD_RID] \\
2613    `x <> PosInf` by METIS_TAC [lt_infty] \\
2614    `x <> NegInf` by METIS_TAC [le_infty, extreal_not_infty] \\
2615    `?r. x = Normal r` by METIS_TAC [extreal_cases] \\
2616     FULL_SIMP_TAC std_ss [extreal_le_def, extreal_lt_eq, extreal_11] \\
2617    `c <= r` by METIS_TAC [Q.SPECL [`r`, `c`, `(\n. c - (1/2) pow n)`] SEQ_LE_IMP_LIM_LE] \\
2618    `r <= c` by METIS_TAC [Q.SPECL [`r`, `c`, `(\n. c + (1/2) pow n)`] LE_SEQ_IMP_LE_LIM] \\
2619     METIS_TAC [REAL_LE_ANTISYM]) >> DISCH_TAC
2620 >> FULL_SIMP_TAC std_ss []
2621 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
2622 >> (MP_TAC o UNDISCH o Q.SPEC `Borel` o (INST_TYPE [alpha |-> ``:extreal``]))
2623      SIGMA_ALGEBRA_FN_BIGINTER
2624 >> RW_TAC std_ss []
2625 >> Q.PAT_X_ASSUM `!f. P f ==> Q f`
2626     (MP_TAC o
2627      Q.SPEC `(\n. {x | Normal (c - ((1/2) pow n)) <= x /\ x < Normal (c + ((1/2) pow n))})`)
2628 >> `(\n. {x | Normal (c - ((1/2) pow n)) <= x /\
2629               x < Normal (c + ((1/2) pow n))}) IN (UNIV -> subsets Borel)`
2630     by RW_TAC std_ss [IN_FUNSET, BOREL_MEASURABLE_SETS_CO]
2631 >> METIS_TAC []
2632QED
2633
2634Theorem BOREL_MEASURABLE_SETS_SING[simp] : (* was: BOREL_MEASURABLE_SING *)
2635    !c. {c} IN subsets Borel
2636Proof
2637    GEN_TAC >> Cases_on `c`
2638 >- REWRITE_TAC [BOREL_MEASURABLE_SETS_NEGINF']
2639 >- REWRITE_TAC [BOREL_MEASURABLE_SETS_POSINF']
2640 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_SING_r]
2641QED
2642
2643Theorem BOREL_MEASURABLE_SETS_FINITE :
2644    !s. FINITE s ==> s IN subsets Borel
2645Proof
2646    HO_MATCH_MP_TAC FINITE_INDUCT
2647 >> rpt STRIP_TAC
2648 >- (MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY \\
2649     REWRITE_TAC [SIGMA_ALGEBRA_BOREL])
2650 >> ‘e INSERT s = {e} UNION s’ by SET_TAC []
2651 >> POP_ORW
2652 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION
2653 >> rw [BOREL_MEASURABLE_SETS_SING, SIGMA_ALGEBRA_BOREL]
2654QED
2655
2656Theorem BOREL_MEASURABLE_SETS_SING' :
2657    !c. {x | x = c} IN subsets Borel
2658Proof
2659    GEN_TAC
2660 >> `{x | x = c} = {c}` by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_SING]
2661 >> POP_ORW
2662 >> REWRITE_TAC [BOREL_MEASURABLE_SETS_SING]
2663QED
2664
2665Theorem BOREL_MEASURABLE_SETS_NOT_SING :
2666    !c. {x | x <> c} IN subsets Borel
2667Proof
2668    RW_TAC std_ss []
2669 >> `{x | x <> c} = (space Borel) DIFF ({c})`
2670      by RW_TAC std_ss [SPACE_BOREL, EXTENSION, IN_DIFF, IN_SING, GSPECIFICATION,
2671                        IN_UNIV]
2672 >> POP_ORW
2673 >> METIS_TAC [SIGMA_ALGEBRA_BOREL, BOREL_MEASURABLE_SETS_SING,
2674               sigma_algebra_def, algebra_def]
2675QED
2676
2677(* For backwards compatibilities *)
2678Theorem BOREL_MEASURABLE_SETS1 = BOREL_MEASURABLE_SETS_RO;
2679Theorem BOREL_MEASURABLE_SETS2 = BOREL_MEASURABLE_SETS_CR;
2680Theorem BOREL_MEASURABLE_SETS3 = BOREL_MEASURABLE_SETS_RC;
2681Theorem BOREL_MEASURABLE_SETS4 = BOREL_MEASURABLE_SETS_OR;
2682Theorem BOREL_MEASURABLE_SETS5 = BOREL_MEASURABLE_SETS_CO;
2683Theorem BOREL_MEASURABLE_SETS6 = BOREL_MEASURABLE_SETS_OC;
2684Theorem BOREL_MEASURABLE_SETS7 = BOREL_MEASURABLE_SETS_CC;
2685Theorem BOREL_MEASURABLE_SETS8 = BOREL_MEASURABLE_SETS_OO;
2686Theorem BOREL_MEASURABLE_SETS9 = BOREL_MEASURABLE_SETS_SING;
2687Theorem BOREL_MEASURABLE_SETS10 = BOREL_MEASURABLE_SETS_NOT_SING;
2688
2689(* A summary of all Borel-measurable sets *)
2690Theorem BOREL_MEASURABLE_SETS:
2691    (!c. {x | x < c} IN subsets Borel) /\
2692    (!c. {x | c < x} IN subsets Borel) /\
2693    (!c. {x | x <= c} IN subsets Borel) /\
2694    (!c. {x | c <= x} IN subsets Borel) /\
2695    (!c d. {x | c <= x /\ x < d} IN subsets Borel) /\
2696    (!c d. {x | c < x /\ x <= d} IN subsets Borel) /\
2697    (!c d. {x | c <= x /\ x <= d} IN subsets Borel) /\
2698    (!c d. {x | c < x /\ x < d} IN subsets Borel) /\
2699    (!c. {c} IN subsets Borel) /\
2700    (!c. {x | x <> c} IN subsets Borel)
2701Proof
2702    RW_TAC std_ss [BOREL_MEASURABLE_SETS_RO, (*           x < c  *)
2703                   BOREL_MEASURABLE_SETS_OR, (* c < x            *)
2704                   BOREL_MEASURABLE_SETS_RC, (*           x <= c *)
2705                   BOREL_MEASURABLE_SETS_CR, (* c <= x           *)
2706                   BOREL_MEASURABLE_SETS_CO, (* c <= x /\ x < d  *)
2707                   BOREL_MEASURABLE_SETS_OC, (* c < x  /\ x <= d *)
2708                   BOREL_MEASURABLE_SETS_CC, (* c <= x /\ x <= d *)
2709                   BOREL_MEASURABLE_SETS_OO, (* c < x  /\ x < d  *)
2710                   BOREL_MEASURABLE_SETS_SING,         (* x = c  *)
2711                   BOREL_MEASURABLE_SETS_NOT_SING]     (* x <> c *)
2712QED
2713
2714(* NOTE: This is similar with Borel_eq_le but this generator contains exhausting
2715   sequences, which is needed when generating product sigma-algebras.
2716 *)
2717Theorem Borel_eq_le_ext :
2718    Borel = sigma univ(:extreal) (IMAGE (\c. {x | x <= c}) univ(:extreal))
2719Proof
2720    Suff ‘subsets Borel =
2721          subsets (sigma univ(:extreal) (IMAGE (\c. {x | x <= c}) univ(:extreal)))’
2722 >- METIS_TAC [SPACE, SPACE_BOREL, SPACE_SIGMA]
2723 >> MATCH_MP_TAC SUBSET_ANTISYM
2724 >> reverse CONJ_TAC
2725 >- (rw [GSYM SPACE_BOREL] \\
2726     MATCH_MP_TAC SIGMA_SUBSET \\
2727     rw [SPACE_BOREL, SIGMA_ALGEBRA_BOREL] \\
2728     rw [SUBSET_DEF] \\
2729     rw [BOREL_MEASURABLE_SETS_RC])
2730 >> rw [Borel_eq_le]
2731 >> MATCH_MP_TAC SIGMA_MONOTONE
2732 >> rw [SUBSET_DEF]
2733 >> Q.EXISTS_TAC ‘Normal a’ >> rw []
2734QED
2735
2736(* ******************************************* *)
2737(*        Borel measurable functions           *)
2738(* ******************************************* *)
2739
2740Theorem IN_MEASURABLE_BOREL_CONST :
2741    !a k f. sigma_algebra a /\ (!x. x IN space a ==> (f x = k)) ==>
2742            f IN measurable a Borel
2743Proof
2744    RW_TAC std_ss [IN_MEASURABLE_BOREL, IN_FUNSET, IN_UNIV]
2745 >> Cases_on `Normal c <= k`
2746 >- (`{x | f x < Normal c} INTER space a = {}`
2747         by  (RW_TAC std_ss [EXTENSION, GSPECIFICATION, NOT_IN_EMPTY, IN_INTER]
2748              >> METIS_TAC [extreal_lt_def])
2749      >> METIS_TAC [sigma_algebra_def, algebra_def])
2750 >> `{x | f x < Normal c} INTER space a = space a`
2751      by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
2752          >> METIS_TAC [extreal_lt_def])
2753 >> METIS_TAC [sigma_algebra_def, algebra_def, INTER_IDEMPOT,DIFF_EMPTY]
2754QED
2755
2756Theorem IN_MEASURABLE_BOREL_CONST' :
2757    !a k. sigma_algebra a ==> (\x. k) IN measurable a Borel
2758Proof
2759    rpt STRIP_TAC
2760 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_CONST
2761 >> Q.EXISTS_TAC `k` >> RW_TAC std_ss []
2762QED
2763
2764Theorem IN_MEASURABLE_BOREL_INDICATOR:
2765    !a A f. sigma_algebra a /\ A IN subsets a /\
2766           (!x. x IN space a ==> (f x = indicator_fn A x))
2767        ==> f IN measurable a Borel
2768Proof
2769    RW_TAC std_ss [IN_MEASURABLE_BOREL]
2770 >- RW_TAC std_ss [IN_FUNSET,UNIV_DEF,indicator_fn_def,IN_DEF]
2771 >> `!x. x IN space a ==> 0 <= f x /\ f x <= 1` by RW_TAC real_ss [indicator_fn_def,le_01,le_refl]
2772 >> Cases_on `Normal c <= 0`
2773 >- (`{x | f x < Normal c} INTER space a = {}`
2774      by (RW_TAC std_ss [EXTENSION,GSPECIFICATION,NOT_IN_EMPTY,IN_INTER,extreal_lt_def]
2775          >> METIS_TAC [le_trans])
2776      >> METIS_TAC [sigma_algebra_def,algebra_def,DIFF_EMPTY])
2777 >> Cases_on `1 < Normal c`
2778 >- (`{x | f x < Normal c} INTER space a = space a`
2779        by (RW_TAC std_ss [EXTENSION,GSPECIFICATION,NOT_IN_EMPTY,IN_INTER]
2780            >> METIS_TAC [let_trans])
2781     >> METIS_TAC [sigma_algebra_def,algebra_def,DIFF_EMPTY])
2782 >> `{x | f x < Normal c} INTER space a = (space a) DIFF A`
2783        by (RW_TAC std_ss [EXTENSION,GSPECIFICATION,IN_INTER,IN_DIFF]
2784            >> FULL_SIMP_TAC std_ss [extreal_lt_def,indicator_fn_def]
2785            >> METIS_TAC [extreal_lt_def])
2786 >> METIS_TAC [sigma_algebra_def,algebra_def,DIFF_EMPTY]
2787QED
2788
2789Theorem IN_MEASURABLE_BOREL_CMUL:
2790    !a f g z. sigma_algebra a /\ f IN measurable a Borel /\
2791             (!x. x IN space a ==> (g x = Normal z * f x))
2792          ==> g IN measurable a Borel
2793Proof
2794    RW_TAC std_ss []
2795 >> Cases_on `Normal z = 0`
2796 >- METIS_TAC [IN_MEASURABLE_BOREL_CONST, mul_lzero]
2797 >> Cases_on `0 < Normal z`
2798 >- (RW_TAC real_ss [IN_MEASURABLE_BOREL, IN_FUNSET, IN_UNIV] \\
2799    `!c. {x | g x < Normal c} INTER space a = {x | f x < Normal (c) / Normal z} INTER space a`
2800      by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] \\
2801          METIS_TAC [lt_rdiv, mul_comm, extreal_of_num_def, extreal_lt_eq]) \\
2802     METIS_TAC [IN_MEASURABLE_BOREL_ALL, extreal_div_eq, extreal_of_num_def, extreal_11])
2803 >> `z < 0` by METIS_TAC [extreal_lt_def, extreal_le_def, extreal_of_num_def,
2804                          REAL_LT_LE, GSYM real_lte]
2805 >> RW_TAC real_ss [IN_MEASURABLE_BOREL, IN_FUNSET, IN_UNIV]
2806 >> `!c. {x | g x < Normal c} INTER space a = {x | Normal c / Normal z < f x} INTER space a`
2807      by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] \\
2808          METIS_TAC [lt_rdiv_neg, mul_comm])
2809 >> METIS_TAC [IN_MEASURABLE_BOREL_ALL, extreal_div_eq, REAL_LT_IMP_NE]
2810QED
2811
2812Theorem IN_MEASURABLE_BOREL_MINUS :
2813    !a f g. sigma_algebra a /\ f IN measurable a Borel /\
2814           (!x. x IN space a ==> (g x = -f x)) ==> g IN measurable a Borel
2815Proof
2816    rpt STRIP_TAC
2817 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_CMUL
2818 >> qexistsl_tac [`f`, `-1`]
2819 >> RW_TAC std_ss [Once neg_minus1]
2820 >> REWRITE_TAC [extreal_of_num_def, extreal_ainv_def]
2821QED
2822
2823Theorem IN_MEASURABLE_BOREL_AINV :
2824    !a f. sigma_algebra a /\ f IN measurable a Borel ==> (\x. -f x) IN measurable a Borel
2825Proof
2826    rpt STRIP_TAC
2827 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_MINUS
2828 >> Q.EXISTS_TAC ‘f’ >> rw []
2829QED
2830
2831Theorem IN_MEASURABLE_BOREL_ABS:
2832    !a f g. sigma_algebra a /\ f IN measurable a Borel /\
2833            (!x. x IN space a ==> (g x = abs (f x)))
2834         ==> g IN measurable a Borel
2835Proof
2836    RW_TAC real_ss [IN_MEASURABLE_BOREL,IN_UNIV,IN_FUNSET]
2837 >> Cases_on `c <= 0`
2838 >- (`{x | g x < Normal c} INTER space a = {}`
2839        by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER, NOT_IN_EMPTY, GSYM real_lte] \\
2840            METIS_TAC [abs_pos, le_trans, extreal_le_def, extreal_of_num_def, extreal_lt_def]) \\
2841     METIS_TAC [sigma_algebra_def, algebra_def])
2842 >> FULL_SIMP_TAC real_ss [GSYM real_lt]
2843 >> Suff `{x | g x < Normal c} INTER space a =
2844          ({x | f x < Normal c} INTER space a) INTER ({x | Normal (-c) < f x} INTER space a)`
2845 >- (Rewr' \\
2846     METIS_TAC [sigma_algebra_def, ALGEBRA_INTER, IN_MEASURABLE_BOREL_ALL,
2847               IN_MEASURABLE_BOREL, IN_FUNSET, IN_UNIV])
2848 >> RW_TAC real_ss [EXTENSION, GSPECIFICATION, IN_INTER]
2849 >> EQ_TAC
2850 >- (RW_TAC std_ss []
2851     >- (`abs (f x) < Normal c` by METIS_TAC [] \\
2852         Cases_on `f x` >| (* 3 subgoals *)
2853         [ METIS_TAC [lt_infty],
2854           METIS_TAC [extreal_abs_def, lt_infty, extreal_not_infty],
2855          `g x = Normal (abs r)` by METIS_TAC [extreal_abs_def] \\
2856           FULL_SIMP_TAC std_ss [extreal_lt_eq] \\
2857           METIS_TAC [REAL_ADD_LID, REAL_SUB_RZERO, ABS_BETWEEN] ]) \\
2858     Cases_on `f x` >| (* 3 subgoals *)
2859     [ METIS_TAC [extreal_abs_def, lt_infty],
2860       METIS_TAC [lt_infty],
2861      `g x = Normal (abs r)` by METIS_TAC [extreal_abs_def] \\
2862       FULL_SIMP_TAC std_ss [extreal_lt_eq] \\
2863       METIS_TAC [REAL_ADD_LID, REAL_SUB_LZERO, REAL_SUB_RZERO, ABS_BETWEEN] ])
2864 >> RW_TAC std_ss []
2865 >> `f x <> NegInf` by METIS_TAC [lt_infty]
2866 >> `f x <> PosInf` by METIS_TAC [lt_infty]
2867 >> `?r. f x = Normal r` by METIS_TAC [extreal_cases]
2868 >> FULL_SIMP_TAC std_ss [extreal_abs_def, extreal_lt_eq, extreal_le_def]
2869 >> `r = r - 0` by PROVE_TAC [REAL_SUB_RZERO] >> POP_ORW
2870 >> REWRITE_TAC [GSYM ABS_BETWEEN]
2871 >> ASM_REWRITE_TAC [REAL_ADD_LID, REAL_SUB_LZERO, REAL_SUB_RZERO]
2872 >> METIS_TAC [REAL_LET_ANTISYM, REAL_NOT_LE]
2873QED
2874
2875Theorem IN_MEASURABLE_BOREL_ABS' :
2876    !a f. sigma_algebra a /\ f IN measurable a Borel ==> (abs o f) IN measurable a Borel
2877Proof
2878    rpt STRIP_TAC
2879 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_ABS
2880 >> Q.EXISTS_TAC `f` >> RW_TAC std_ss [o_DEF]
2881QED
2882
2883(* A few theorems enhancing the existing IN_MEASURABLE_BOREL_ALL with ‘abs’ *)
2884
2885Theorem IN_MEASURABLE_BOREL_ALL_ABS :
2886    !f a. sigma_algebra a /\ f IN measurable a Borel ==>
2887        (!c. {x | f x < c} INTER space a IN subsets a) /\
2888        (!c. {x | c <= f x} INTER space a IN subsets a) /\
2889        (!c. {x | f x <= c} INTER space a IN subsets a) /\
2890        (!c. {x | c < f x} INTER space a IN subsets a) /\
2891        (!c. {x | abs (f x) < c} INTER space a IN subsets a) /\
2892        (!c. {x | c <= abs (f x)} INTER space a IN subsets a) /\
2893        (!c. {x | abs (f x) <= c} INTER space a IN subsets a) /\
2894        (!c. {x | c < abs (f x)} INTER space a IN subsets a) /\
2895        (!c d. {x | c <= f x /\ f x < d} INTER space a IN subsets a) /\
2896        (!c d. {x | c < f x /\ f x <= d} INTER space a IN subsets a) /\
2897        (!c d. {x | c <= f x /\ f x <= d} INTER space a IN subsets a) /\
2898        (!c d. {x | c < f x /\ f x < d} INTER space a IN subsets a) /\
2899        (!c. {x | f x = c} INTER space a IN subsets a) /\
2900        (!c. {x | f x <> c} INTER space a IN subsets a) /\
2901        (!c. {x | abs (f x) = c} INTER space a IN subsets a) /\
2902        (!c. {x | abs (f x) <> c} INTER space a IN subsets a)
2903Proof
2904    rpt GEN_TAC >> STRIP_TAC
2905 >> Q.ABBREV_TAC ‘g = \x. abs (f x)’ >> simp []
2906 >> Know ‘g IN measurable a Borel’
2907 >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_ABS \\
2908     Q.EXISTS_TAC ‘f’ >> rw [Abbr ‘g’])
2909 >> DISCH_TAC
2910 >> rw [IN_MEASURABLE_BOREL_ALL]
2911QED
2912
2913Theorem IN_MEASURABLE_BOREL_ALL_MEASURE_ABS :
2914   !m f. measure_space m /\ f IN Borel_measurable (measurable_space m) ==>
2915        (!c. {x | f x < c} INTER m_space m IN measurable_sets m) /\
2916        (!c. {x | c <= f x} INTER m_space m IN measurable_sets m) /\
2917        (!c. {x | f x <= c} INTER m_space m IN measurable_sets m) /\
2918        (!c. {x | c < f x} INTER m_space m IN measurable_sets m) /\
2919        (!c. {x | abs (f x) < c} INTER m_space m IN measurable_sets m) /\
2920        (!c. {x | c <= abs (f x)} INTER m_space m IN measurable_sets m) /\
2921        (!c. {x | abs (f x) <= c} INTER m_space m IN measurable_sets m) /\
2922        (!c. {x | c < abs (f x)} INTER m_space m IN measurable_sets m) /\
2923        (!c d. {x | c <= f x /\ f x < d} INTER m_space m IN measurable_sets m) /\
2924        (!c d. {x | c < f x /\ f x <= d} INTER m_space m IN measurable_sets m) /\
2925        (!c d. {x | c <= f x /\ f x <= d} INTER m_space m IN measurable_sets m) /\
2926        (!c d. {x | c < f x /\ f x < d} INTER m_space m IN measurable_sets m) /\
2927        (!c. {x | f x = c} INTER m_space m IN measurable_sets m) /\
2928        (!c. {x | f x <> c} INTER m_space m IN measurable_sets m) /\
2929        (!c. {x | abs (f x) = c} INTER m_space m IN measurable_sets m) /\
2930        (!c. {x | abs (f x) <> c} INTER m_space m IN measurable_sets m)
2931Proof
2932    rpt GEN_TAC >> STRIP_TAC
2933 >> MP_TAC (REWRITE_RULE [space_def, subsets_def]
2934             (Q.SPECL [‘f’, ‘measurable_space m’] IN_MEASURABLE_BOREL_ALL_ABS))
2935 >> FULL_SIMP_TAC std_ss [measure_space_def]
2936QED
2937
2938Theorem IN_MEASURABLE_BOREL_ALL_MEASURE_ABS' :
2939   !m f. measure_space m /\ f IN Borel_measurable (measurable_space m) ==>
2940        (!c. {x | x IN m_space m /\ f x < c} IN measurable_sets m) /\
2941        (!c. {x | x IN m_space m /\ c <= f x} IN measurable_sets m) /\
2942        (!c. {x | x IN m_space m /\ f x <= c} IN measurable_sets m) /\
2943        (!c. {x | x IN m_space m /\ c < f x} IN measurable_sets m) /\
2944        (!c. {x | x IN m_space m /\ abs (f x) < c} IN measurable_sets m) /\
2945        (!c. {x | x IN m_space m /\ c <= abs (f x)} IN measurable_sets m) /\
2946        (!c. {x | x IN m_space m /\ abs (f x) <= c} IN measurable_sets m) /\
2947        (!c. {x | x IN m_space m /\ c < abs (f x)} IN measurable_sets m) /\
2948        (!c d. {x | x IN m_space m /\ c <= f x /\ f x < d} IN measurable_sets m) /\
2949        (!c d. {x | x IN m_space m /\ c < f x /\ f x <= d} IN measurable_sets m) /\
2950        (!c d. {x | x IN m_space m /\ c <= f x /\ f x <= d} IN measurable_sets m) /\
2951        (!c d. {x | x IN m_space m /\ c < f x /\ f x < d} IN measurable_sets m) /\
2952        (!c. {x | x IN m_space m /\ f x = c} IN measurable_sets m) /\
2953        (!c. {x | x IN m_space m /\ f x <> c} IN measurable_sets m) /\
2954        (!c. {x | x IN m_space m /\ abs (f x) = c} IN measurable_sets m) /\
2955        (!c. {x | x IN m_space m /\ abs (f x) <> c} IN measurable_sets m)
2956Proof
2957    rpt GEN_TAC >> STRIP_TAC
2958 >> ‘!P. {x | x IN m_space m /\ P x} = {x | P x} INTER m_space m’ by SET_TAC []
2959 >> simp []
2960 >> MP_TAC (Q.SPECL [‘m’, ‘f’] IN_MEASURABLE_BOREL_ALL_MEASURE_ABS)
2961 >> rw []
2962QED
2963
2964Theorem IN_MEASURABLE_BOREL_SQR:
2965    !a f g. sigma_algebra a /\ f IN measurable a Borel /\
2966            (!x. x IN space a ==> (g x = (f x) pow 2))
2967        ==> g IN measurable a Borel
2968Proof
2969  RW_TAC real_ss []
2970  >> `!c. {x | f x <= Normal c} INTER space a IN subsets a` by RW_TAC std_ss [IN_MEASURABLE_BOREL_ALL]
2971  >> `!c. {x | Normal c <= f x} INTER space a IN subsets a` by RW_TAC std_ss [IN_MEASURABLE_BOREL_ALL]
2972  >> RW_TAC real_ss [IN_UNIV,IN_FUNSET,IN_MEASURABLE_BOREL_ALT2]
2973  >> Cases_on `Normal c < 0`
2974  >- (`{x | g x <= Normal c} INTER space a = {}`
2975          by ( RW_TAC real_ss [EXTENSION,GSPECIFICATION,NOT_IN_EMPTY,IN_INTER,GSYM real_lt]
2976             >> METIS_TAC [le_pow2,lte_trans,extreal_lt_def])
2977      >> METIS_TAC [sigma_algebra_def,algebra_def])
2978  >> FULL_SIMP_TAC real_ss [extreal_lt_def]
2979  >> `{x | g x <= Normal c} INTER space a =
2980        ({x | f x <= sqrt (Normal c)} INTER space a) INTER
2981        ({x | - (sqrt (Normal c)) <= f x} INTER space a)`
2982        by (RW_TAC real_ss [EXTENSION,GSPECIFICATION,IN_INTER]
2983            >> EQ_TAC
2984            >- (RW_TAC real_ss []
2985                >- (Cases_on `f x < 0` >- METIS_TAC [lte_trans,lt_imp_le,sqrt_pos_le]
2986                         >> METIS_TAC [pow2_sqrt,sqrt_mono_le,le_pow2,extreal_lt_def])
2987                     >> Cases_on `0 <= f x` >- METIS_TAC [le_trans,le_neg,sqrt_pos_le,neg_0]
2988                >> SPOSE_NOT_THEN ASSUME_TAC
2989                >> FULL_SIMP_TAC real_ss [GSYM extreal_lt_def]
2990                >> `sqrt (Normal c) < - (f x)` by METIS_TAC [lt_neg,neg_neg]
2991                >> `(sqrt (Normal c)) pow 2 < (- (f x)) pow 2` by RW_TAC real_ss [pow_lt2,sqrt_pos_le]
2992                >> `(sqrt (Normal c)) pow 2 = Normal c` by METIS_TAC [sqrt_pow2]
2993                >> `(-1) pow 2 = 1` by METIS_TAC [pow_minus1,MULT_RIGHT_1]
2994                >> `(- (f x)) pow 2 = (f x) pow 2` by RW_TAC std_ss [Once neg_minus1,pow_mul,mul_lone]
2995                >> METIS_TAC [extreal_lt_def])
2996            >> RW_TAC std_ss []
2997            >> Cases_on `0 <= f x` >- METIS_TAC [pow_le,sqrt_pow2]
2998            >> FULL_SIMP_TAC real_ss [GSYM extreal_lt_def]
2999            >> `- (f x) <= sqrt (Normal c)` by METIS_TAC [le_neg,neg_neg]
3000            >> `(- (f x)) pow 2 <= (sqrt (Normal c)) pow 2`
3001               by METIS_TAC [pow_le, sqrt_pos_le, lt_neg, neg_neg, neg_0, lt_imp_le]
3002            >> `(sqrt (Normal c)) pow 2 = Normal c` by METIS_TAC [sqrt_pow2]
3003            >> `(-1) pow 2 = 1` by METIS_TAC [pow_minus1,MULT_RIGHT_1]
3004            >> `(- (f x)) pow 2 = (f x) pow 2` by RW_TAC std_ss [Once neg_minus1,pow_mul,mul_lone]
3005            >> METIS_TAC [])
3006  >> METIS_TAC [sigma_algebra_def,ALGEBRA_INTER,extreal_sqrt_def,extreal_ainv_def]
3007QED
3008
3009(* enhanced with more general antecedents, old:
3010
3011      (!x. x IN space a ==> (f x <> NegInf /\ g x <> NegInf))
3012
3013   new:
3014
3015      (!x. x IN space a ==> (f x <> NegInf /\ g x <> NegInf) \/
3016                            (f x <> PosInf /\ g x <> PosInf))
3017 *)
3018Theorem IN_MEASURABLE_BOREL_ADD :
3019    !a f g h. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel /\
3020              (!x. x IN space a ==> (f x <> NegInf /\ g x <> NegInf) \/
3021                                    (f x <> PosInf /\ g x <> PosInf)) /\
3022              (!x. x IN space a ==> (h x = f x + g x))
3023          ==> h IN measurable a Borel
3024Proof
3025    rpt STRIP_TAC
3026 >> RW_TAC std_ss [IN_MEASURABLE_BOREL] >- RW_TAC std_ss [IN_FUNSET, IN_UNIV]
3027 >> Know `!c. {x | h x < Normal c} INTER (space a) =
3028              BIGUNION (IMAGE (\r. {x | f x < r /\ r < Normal c - g x} INTER space a) Q_set)`
3029 >- (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_BIGUNION_IMAGE, IN_UNIV, IN_INTER] \\
3030     EQ_TAC >- (RW_TAC std_ss [] \\
3031                MATCH_MP_TAC Q_DENSE_IN_R \\
3032                METIS_TAC [lt_sub_imp, lt_sub_imp']) \\
3033     reverse (RW_TAC std_ss []) >- art [] \\
3034    ‘h x = f x + g x’ by PROVE_TAC [] >> POP_ORW \\
3035    ‘f x < Normal c - g x’ by PROVE_TAC [lt_trans] \\
3036     Q.PAT_X_ASSUM ‘!x. x IN space a ==> P \/ Q’ (MP_TAC o (Q.SPEC ‘x’)) \\
3037     RW_TAC std_ss [] >| (* 2 subgoals *)
3038     [ METIS_TAC [lt_sub , extreal_not_infty],
3039       METIS_TAC [lt_sub', extreal_not_infty] ])
3040 >> DISCH_TAC
3041 >> FULL_SIMP_TAC std_ss []
3042 >> MATCH_MP_TAC BIGUNION_IMAGE_Q
3043 >> RW_TAC std_ss [IN_FUNSET]
3044 >> `?y. r = Normal y` by METIS_TAC [Q_not_infty, extreal_cases]
3045 >> `{x | f x < Normal y /\ Normal y < Normal c - g x} =
3046     {x | f x < Normal y} INTER {x | Normal y < Normal c - g x}`
3047     by RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER]
3048 >> `({x | f x < Normal y} INTER space a) IN subsets a` by RW_TAC std_ss [IN_MEASURABLE_BOREL_ALL]
3049 >> Know `!x. x IN space a ==> (Normal y < Normal c - g x <=> g x < Normal c - Normal y)`
3050 >- (rpt STRIP_TAC \\
3051     Q.PAT_X_ASSUM ‘!x. x IN space a ==> P \/ Q’ (MP_TAC o (Q.SPEC ‘x’)) \\
3052     RW_TAC std_ss [] >| (* 2 subgoals *)
3053     [ METIS_TAC [lt_sub , extreal_not_infty, add_comm],
3054       METIS_TAC [lt_sub', extreal_not_infty, add_comm] ])
3055 >> DISCH_TAC
3056 >> `{x | Normal y < Normal c - g x} INTER space a = {x | g x < Normal c - Normal y} INTER space a`
3057     by (RW_TAC std_ss [IN_INTER, EXTENSION, GSPECIFICATION] >> METIS_TAC [])
3058 >> `({x | Normal y < Normal c - g x} INTER space a) IN subsets a`
3059     by METIS_TAC [IN_MEASURABLE_BOREL_ALL, extreal_sub_def]
3060 >> `({x | f x < Normal y} INTER space a) INTER ({x | Normal y < Normal c - g x} INTER space a) =
3061     ({x | f x < Normal y} INTER {x | Normal y < Normal c - g x} INTER space a)`
3062     by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] \\
3063         EQ_TAC >> RW_TAC std_ss [])
3064 >> METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
3065QED
3066
3067(* enhanced with more general antecedents, old:
3068
3069             (!x. x IN space a ==> (f x <> NegInf /\ g x <> PosInf))
3070
3071   new:
3072             (!x. x IN space a ==> (f x <> NegInf /\ g x <> PosInf) \/
3073                                   (f x <> PosInf /\ g x <> NegInf))
3074 *)
3075Theorem IN_MEASURABLE_BOREL_SUB :
3076    !a f g h. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel /\
3077             (!x. x IN space a ==> (f x <> NegInf /\ g x <> PosInf) \/
3078                                   (f x <> PosInf /\ g x <> NegInf)) /\
3079             (!x. x IN space a ==> (h x = f x - g x))
3080          ==> h IN measurable a Borel
3081Proof
3082    RW_TAC std_ss []
3083 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_ADD
3084 >> qexistsl_tac [`f`, `\x. - g x`]
3085 >> RW_TAC std_ss []
3086 >| [ (* goal 1 (of 3) *)
3087      MATCH_MP_TAC IN_MEASURABLE_BOREL_CMUL \\
3088      Q.EXISTS_TAC `g` \\
3089      Q.EXISTS_TAC `-1` \\
3090      RW_TAC std_ss [GSYM extreal_ainv_def, GSYM extreal_of_num_def, GSYM neg_minus1],
3091      (* goal 2 (of 3) *)
3092      METIS_TAC [extreal_ainv_def, neg_neg],
3093      (* goal 3 (of 3) *)
3094      Cases_on `f x` >> Cases_on `g x` \\
3095      METIS_TAC [le_infty, extreal_ainv_def, extreal_sub_def, extreal_add_def, real_sub] ]
3096QED
3097
3098(* cf. IN_MEASURABLE_BOREL_TIMES for a more general version *)
3099Theorem IN_MEASURABLE_BOREL_MUL :
3100    !a f g h. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel /\
3101             (!x. x IN space a ==> (h x = f x * g x)) /\
3102             (!x. x IN space a ==> f x <> NegInf /\ f x <> PosInf /\
3103                                   g x <> NegInf /\ g x <> PosInf)
3104          ==> h IN measurable a Borel
3105Proof
3106    RW_TAC std_ss []
3107 >> `!x. x IN space a ==> (f x * g x = 1 / 2 * ((f x + g x) pow 2 - f x pow 2 - g x pow 2))`
3108 by (RW_TAC std_ss [] \\
3109     (MP_TAC o Q.SPECL [`f x`, `g x`]) add_pow2 \\
3110     RW_TAC std_ss [] \\
3111    `?r. f x = Normal r` by METIS_TAC [extreal_cases] \\
3112    `?r. g x = Normal r` by METIS_TAC [extreal_cases] \\
3113     FULL_SIMP_TAC real_ss [extreal_11, extreal_pow_def, extreal_add_def, extreal_sub_def,
3114                            extreal_of_num_def, extreal_mul_def, extreal_div_eq] \\
3115    `r pow 2 + r' pow 2 + 2 * r * r' - r pow 2 - r' pow 2 = 2 * r * r'` by REAL_ARITH_TAC \\
3116     RW_TAC real_ss [REAL_MUL_ASSOC])
3117 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_CMUL
3118 >> Q.EXISTS_TAC `(\x. (f x + g x) pow 2 - f x pow 2 - g x pow 2)`
3119 >> Q.EXISTS_TAC `1 / 2`
3120 >> RW_TAC real_ss [extreal_of_num_def, extreal_div_eq]
3121 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_SUB
3122 >> Q.EXISTS_TAC `(\x. (f x + g x) pow 2 - f x pow 2)`
3123 >> Q.EXISTS_TAC `(\x. g x pow 2)`
3124 >> RW_TAC std_ss []
3125 >| [ (* goal 1 (of 3) *)
3126      MATCH_MP_TAC IN_MEASURABLE_BOREL_SUB \\
3127      Q.EXISTS_TAC `(\x. (f x + g x) pow 2)` \\
3128      Q.EXISTS_TAC `(\x. f x pow 2)` \\
3129      RW_TAC std_ss [] >| (* 3 subgoals *)
3130      [ (* goal 1.1 (of 3) *)
3131        MATCH_MP_TAC IN_MEASURABLE_BOREL_SQR \\
3132        Q.EXISTS_TAC `(\x. (f x + g x))` \\
3133        RW_TAC std_ss [] \\
3134        MATCH_MP_TAC IN_MEASURABLE_BOREL_ADD \\
3135        qexistsl_tac [`f`, `g`] \\
3136        RW_TAC std_ss [],
3137        (* goal 1.2 (of 3) *)
3138        MATCH_MP_TAC IN_MEASURABLE_BOREL_SQR >> METIS_TAC [],
3139        (* goal 1.3 (of 3) *)
3140        METIS_TAC [add_not_infty,pow_not_infty] ],
3141      (* goal 2 (of 3) *)
3142      MATCH_MP_TAC IN_MEASURABLE_BOREL_SQR >> METIS_TAC [],
3143      (* goal 3 (of 3) *)
3144      DISJ1_TAC \\
3145      METIS_TAC [add_not_infty, pow_not_infty, sub_not_infty] ]
3146QED
3147
3148Theorem IN_MEASURABLE_BOREL_SUM:
3149    !a f g s. FINITE s /\ sigma_algebra a /\
3150              (!i. i IN s ==> (f i) IN measurable a Borel) /\
3151              (!i x. i IN s /\ x IN space a ==> f i x <> NegInf) /\
3152              (!x. x IN space a ==> (g x = SIGMA (\i. (f i) x) s)) ==>
3153                 g IN measurable a Borel
3154Proof
3155    Suff `!s:'b -> bool. FINITE s ==>
3156            (\s:'b -> bool. !a f g. FINITE s /\ sigma_algebra a /\
3157                (!i. i IN s ==> f i IN measurable a Borel) /\
3158                (!i x. i IN s /\ x IN space a ==> f i x <> NegInf) /\
3159                (!x. x IN space a ==> (g x = SIGMA (\i. f i x) s)) ==>
3160                   g IN measurable a Borel) s`
3161 >- METIS_TAC []
3162 >> MATCH_MP_TAC FINITE_INDUCT
3163 >> RW_TAC std_ss [EXTREAL_SUM_IMAGE_EMPTY,NOT_IN_EMPTY]
3164 >- METIS_TAC [IN_MEASURABLE_BOREL_CONST]
3165 >> `!x. x IN space a ==> (SIGMA (\i. f i x) (e INSERT s) = f e x + SIGMA (\i. f i x) (s DELETE e))`
3166        by (RW_TAC std_ss [] \\
3167            (MP_TAC o Q.SPEC `e` o UNDISCH o Q.SPECL [`(\i. f i x)`,`s`] o
3168                INST_TYPE [alpha |-> beta]) EXTREAL_SUM_IMAGE_PROPERTY \\
3169            RW_TAC std_ss [])
3170 >> FULL_SIMP_TAC std_ss []
3171 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_ADD
3172 >> Q.EXISTS_TAC `f e`
3173 >> Q.EXISTS_TAC `(\x. SIGMA (\i. f i x) s)`
3174 >> FULL_SIMP_TAC std_ss [IN_INSERT, DELETE_NON_ELEMENT, EXTREAL_SUM_IMAGE_NOT_INFTY]
3175 >> Q.PAT_X_ASSUM `!a f g. P ==> g IN measurable a Borel` MATCH_MP_TAC
3176 >> Q.EXISTS_TAC `f`
3177 >> RW_TAC std_ss []
3178QED
3179
3180Theorem IN_MEASURABLE_BOREL_CMUL_INDICATOR:
3181    !a z s. sigma_algebra a /\ s IN subsets a
3182        ==> (\x. Normal z * indicator_fn s x) IN measurable a Borel
3183Proof
3184    RW_TAC std_ss []
3185 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_CMUL
3186 >> Q.EXISTS_TAC `indicator_fn s`
3187 >> Q.EXISTS_TAC `z`
3188 >> RW_TAC std_ss []
3189 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_INDICATOR
3190 >> METIS_TAC []
3191QED
3192
3193Theorem IN_MEASURABLE_BOREL_MUL_INDICATOR :
3194    !a f s. sigma_algebra a /\ f IN measurable a Borel /\ s IN subsets a ==>
3195            (\x. f x * indicator_fn s x) IN measurable a Borel
3196Proof
3197    rpt STRIP_TAC
3198 >> rfs [IN_MEASURABLE_BOREL_ALT2, IN_FUNSET]
3199 >> Q.X_GEN_TAC ‘c’
3200 >> Cases_on `0 <= Normal c`
3201 >- (`{x | f x * indicator_fn s x <= Normal c} INTER space a =
3202      (({x | f x <= Normal c} INTER space a) INTER s) UNION (space a DIFF s)`
3203         by (RW_TAC std_ss [indicator_fn_def, EXTENSION, GSPECIFICATION, IN_INTER,
3204                            IN_UNION, IN_DIFF] \\
3205             Cases_on `x IN s` >- RW_TAC std_ss [mul_rone, mul_rzero] \\
3206             RW_TAC std_ss [mul_rone, mul_rzero]) >> POP_ORW \\
3207     MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
3208     CONJ_TAC >- (MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []) \\
3209     MATCH_MP_TAC SIGMA_ALGEBRA_COMPL >> art [])
3210 >> `{x | f x * indicator_fn s x <= Normal c} INTER space a =
3211     (({x | f x <= Normal c} INTER space a) INTER s)`
3212         by (RW_TAC std_ss [indicator_fn_def, EXTENSION, GSPECIFICATION, IN_INTER] \\
3213             Cases_on `x IN s` >- RW_TAC std_ss [mul_rone, mul_rzero] \\
3214             RW_TAC std_ss [mul_rone, mul_rzero]) >> POP_ORW
3215 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
3216QED
3217
3218Theorem IN_MEASURABLE_BOREL_CMUL_INDICATOR' :
3219    !a c s. sigma_algebra a /\ s IN subsets a ==>
3220            (\x. c * indicator_fn s x) IN measurable a Borel
3221Proof
3222    rpt STRIP_TAC
3223 >> MP_TAC (Q.SPECL [‘a’, ‘\x. c’, ‘s’] IN_MEASURABLE_BOREL_MUL_INDICATOR) >> rw []
3224 >> POP_ASSUM MATCH_MP_TAC
3225 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_CONST' >> art []
3226QED
3227
3228Theorem IN_MEASURABLE_BOREL_MUL_INDICATOR_EQ:
3229    !a f. sigma_algebra a ==>
3230         (f IN measurable a Borel <=> (\x. f x * indicator_fn (space a) x) IN measurable a Borel)
3231Proof
3232    RW_TAC std_ss []
3233 >> EQ_TAC >- METIS_TAC [IN_MEASURABLE_BOREL_MUL_INDICATOR, ALGEBRA_SPACE, sigma_algebra_def]
3234 >> RW_TAC std_ss [IN_MEASURABLE_BOREL, IN_UNIV, IN_FUNSET]
3235 >> `{x | f x < Normal c} INTER space a =
3236     {x | f x * indicator_fn (space a) x < Normal c} INTER space a`
3237       by (RW_TAC std_ss [IN_INTER, EXTENSION, GSPECIFICATION, indicator_fn_def,
3238                          mul_rzero, mul_rone]
3239           >> METIS_TAC [mul_rzero, mul_rone])
3240 >> POP_ORW >> art []
3241QED
3242
3243Theorem IN_MEASURABLE_BOREL_MAX :
3244    !a f g. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel
3245        ==> (\x. max (f x) (g x)) IN measurable a Borel
3246Proof
3247    RW_TAC std_ss [extreal_max_def]
3248 >> rfs [IN_MEASURABLE_BOREL, IN_FUNSET]
3249 >> `!c. {x | (if f x <= g x then g x else f x) < c} = {x | f x < c} INTER {x | g x < c}`
3250        by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] \\
3251            EQ_TAC
3252            >- (RW_TAC std_ss [] >- METIS_TAC [let_trans] \\
3253                METIS_TAC [extreal_lt_def, lt_trans]) \\
3254            METIS_TAC [extreal_lt_def, lt_trans])
3255 >> `!c. {x | (if f x <= g x then g x else f x) < c} INTER space a =
3256         ({x | f x < c} INTER space a) INTER ({x | g x < c} INTER space a)`
3257        by METIS_TAC [INTER_ASSOC, INTER_COMM, INTER_IDEMPOT]
3258 >> METIS_TAC [sigma_algebra_def, ALGEBRA_INTER]
3259QED
3260
3261Theorem IN_MEASURABLE_BOREL_MIN :
3262    !a f g. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel
3263        ==> (\x. min (f x) (g x)) IN measurable a Borel
3264Proof
3265    RW_TAC std_ss [extreal_min_def]
3266 >> rfs [IN_MEASURABLE_BOREL, IN_FUNSET]
3267 >> Know `!c. {x | (if f x <= g x then f x else g x) < c} =
3268              {x | f x < c} UNION {x | g x < c}`
3269 >- (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_UNION] \\
3270     EQ_TAC >- RW_TAC std_ss [] \\
3271     RW_TAC std_ss [] >- METIS_TAC [let_trans] \\
3272     METIS_TAC [extreal_lt_def, lt_trans]) >> DISCH_TAC
3273 >> `!c. {x | (if f x <= g x then f x else g x) < c} INTER space a =
3274         ({x | f x < c} INTER space a) UNION ({x | g x < c} INTER space a)`
3275       by ASM_SET_TAC []
3276 >> METIS_TAC [sigma_algebra_def, ALGEBRA_UNION]
3277QED
3278
3279(* see extrealTheory.max_fn_seq_def *)
3280Theorem IN_MEASURABLE_BOREL_MAX_FN_SEQ :
3281    !a f. sigma_algebra a /\ (!i. f i IN measurable a Borel) ==>
3282          !n. max_fn_seq f n IN measurable a Borel
3283Proof
3284    rpt GEN_TAC >> STRIP_TAC
3285 >> Induct_on ‘n’ >> rw [max_fn_seq_def]
3286 >> ‘max_fn_seq f (SUC n) = \x. max (max_fn_seq f n x) (f (SUC n) x)’
3287      by rw [max_fn_seq_def, FUN_EQ_THM]
3288 >> POP_ORW
3289 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_MAX >> rw []
3290QED
3291
3292(* TODO: ‘!n x. x IN space a ==> fn n x <= fn (SUC n) x’ (MONO) is unnecessary *)
3293Theorem IN_MEASURABLE_BOREL_MONO_SUP :
3294    !fi f a. sigma_algebra a /\ (!n:num. fi n IN measurable a Borel) /\
3295            (!n x. x IN space a ==> fi n x <= fi (SUC n) x) /\
3296            (!x. x IN space a ==> (f x = sup (IMAGE (\n. fi n x) UNIV)))
3297         ==> f IN measurable a Borel
3298Proof
3299    rpt STRIP_TAC
3300 >> rfs [IN_MEASURABLE_BOREL_ALT2, IN_FUNSET]
3301 >> Q.X_GEN_TAC ‘c’
3302 >> Know ‘{x | sup (IMAGE (\n. fi n x) UNIV) <= Normal c} INTER space a =
3303           BIGINTER (IMAGE (\n. {x | fi n x <= Normal c} INTER space a) UNIV)’
3304 >- (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_BIGINTER_IMAGE, IN_UNIV, IN_INTER, sup_le'] \\
3305     EQ_TAC
3306     >- (RW_TAC std_ss [] \\
3307         Q.PAT_X_ASSUM `!y. P y ==> y <= Normal c` MATCH_MP_TAC \\
3308         RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3309         METIS_TAC []) \\
3310     RW_TAC std_ss [] \\
3311     POP_ASSUM MP_TAC \\
3312     RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3313     METIS_TAC [])
3314 >> DISCH_TAC
3315 >> ‘{x | f x <= Normal c} INTER space a =
3316     {x | sup (IMAGE (\n. fi n x) UNIV) <= Normal c} INTER space a’
3317      by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
3318 >> ‘!c. BIGINTER (IMAGE (\n. {x | fi n x <= Normal c} INTER (space a)) UNIV) IN subsets a’
3319      by (RW_TAC std_ss [] \\
3320          (MP_TAC o Q.SPEC `(space a,subsets a)`) SIGMA_ALGEBRA_FN_BIGINTER \\
3321          RW_TAC std_ss [IN_FUNSET, IN_UNIV, space_def, subsets_def, SPACE])
3322 >> METIS_TAC []
3323QED
3324
3325(* Here univ(:num) is replaced by a subset X *)
3326Theorem IN_MEASURABLE_BOREL_SUP :
3327    !a fi f X. sigma_algebra a /\ X <> {} /\
3328              (!n:num. n IN X ==> fi n IN measurable a Borel) /\
3329              (!x. x IN space a ==> (f x = sup (IMAGE (\n. fi n x) X)))
3330           ==> f IN measurable a Borel
3331Proof
3332    rpt STRIP_TAC
3333 >> rfs [IN_MEASURABLE_BOREL_ALT2, IN_FUNSET]
3334 >> Q.X_GEN_TAC ‘c’
3335 >> Know ‘{x | sup (IMAGE (\n. fi n x) X) <= Normal c} INTER space a =
3336           BIGINTER (IMAGE (\n. {x | fi n x <= Normal c} INTER space a) X)’
3337 >- (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_BIGINTER_IMAGE, IN_UNIV, IN_INTER, sup_le'] \\
3338     EQ_TAC
3339     >- (RW_TAC std_ss [] \\
3340         Q.PAT_X_ASSUM `!y. P y ==> y <= Normal c` MATCH_MP_TAC \\
3341         RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3342         Q.EXISTS_TAC ‘n’ >> art []) \\
3343     RW_TAC std_ss [] >| (* 2 subgoals *)
3344     [ (* goal 1 (of 2) *)
3345       POP_ASSUM MP_TAC \\
3346       RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3347       METIS_TAC [],
3348       (* goal 2 (of 2) *)
3349      ‘?i. i IN X’ by METIS_TAC [MEMBER_NOT_EMPTY] \\
3350       METIS_TAC [] ])
3351 >> DISCH_TAC
3352 >> ‘{x | f x <= Normal c} INTER space a =
3353     {x | sup (IMAGE (\n. fi n x) X) <= Normal c} INTER space a’
3354      by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
3355 >> NTAC 2 POP_ORW
3356 >> Q.ABBREV_TAC ‘A = \n. {x | fi n x <= Normal c} INTER space a’
3357 >> ‘IMAGE A X = {A i | i IN X}’ by SET_TAC [] >> POP_ORW
3358 >> MATCH_MP_TAC (Q.SPECL [‘space a’, ‘subsets a’] SIGMA_ALGEBRA_COUNTABLE_INT)
3359 >> rw [IN_FUNSET, space_def, subsets_def, SPACE, SUBSET_DEF, Abbr ‘A’]
3360 >> FIRST_X_ASSUM MATCH_MP_TAC >> art []
3361QED
3362
3363Theorem IN_MEASURABLE_BOREL_MONO_INF :
3364    !fi f a. sigma_algebra a /\ (!n:num. fi n IN measurable a Borel) /\
3365            (!x. x IN space a ==> (f x = inf (IMAGE (\n. fi n x) UNIV)))
3366         ==> f IN measurable a Borel
3367Proof
3368    rpt STRIP_TAC
3369 >> rfs [IN_MEASURABLE_BOREL_ALT1, IN_FUNSET]
3370 >> Q.X_GEN_TAC ‘c’
3371 >> Know ‘{x | Normal c <= inf (IMAGE (\n. fi n x) UNIV)} INTER space a =
3372           BIGINTER (IMAGE (\n. {x | Normal c <= fi n x} INTER space a) UNIV)’
3373 >- (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_BIGINTER_IMAGE, IN_UNIV, IN_INTER, le_inf'] \\
3374     EQ_TAC
3375     >- (RW_TAC std_ss [] \\
3376         Q.PAT_X_ASSUM ‘!y. P y ==> Normal c <= y’ MATCH_MP_TAC \\
3377         RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3378         METIS_TAC []) \\
3379     RW_TAC std_ss [] \\
3380     POP_ASSUM MP_TAC \\
3381     RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3382     METIS_TAC [])
3383 >> DISCH_TAC
3384 >> ‘{x | Normal c <= f x} INTER space a =
3385     {x | Normal c <= inf (IMAGE (\n. fi n x) UNIV)} INTER space a’
3386       by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
3387 >> ‘!c. BIGINTER (IMAGE (\n. {x | Normal c <= fi n x} INTER (space a)) UNIV) IN subsets a’
3388       by (RW_TAC std_ss [] \\
3389           (MP_TAC o Q.SPEC `(space a,subsets a)`) SIGMA_ALGEBRA_FN_BIGINTER \\
3390           RW_TAC std_ss [IN_FUNSET, IN_UNIV, space_def, subsets_def, SPACE])
3391 >> METIS_TAC []
3392QED
3393
3394Theorem IN_MEASURABLE_BOREL_INF :
3395    !a fi f X. sigma_algebra a /\ X <> {} /\
3396              (!n:num. n IN X ==> fi n IN measurable a Borel) /\
3397              (!x. x IN space a ==> (f x = inf (IMAGE (\n. fi n x) X)))
3398           ==> f IN measurable a Borel
3399Proof
3400    rpt STRIP_TAC
3401 >> rfs [IN_MEASURABLE_BOREL_ALT1, IN_FUNSET]
3402 >> Q.X_GEN_TAC ‘c’
3403 >> Know ‘{x | Normal c <= inf (IMAGE (\n. fi n x) X)} INTER space a =
3404           BIGINTER (IMAGE (\n. {x | Normal c <= fi n x} INTER space a) X)’
3405 >- (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_BIGINTER_IMAGE, IN_UNIV, IN_INTER, le_inf'] \\
3406     EQ_TAC
3407     >- (RW_TAC std_ss [] \\
3408         Q.PAT_X_ASSUM ‘!y. P y ==> Normal c <= y’ MATCH_MP_TAC \\
3409         RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3410         Q.EXISTS_TAC ‘n’ >> art []) \\
3411     RW_TAC std_ss [] >| (* 2 subgoals *)
3412     [ (* goal 1 (of 2) *)
3413       POP_ASSUM MP_TAC \\
3414       RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3415       METIS_TAC [],
3416       (* goal 2 (of 2) *)
3417      ‘?i. i IN X’ by METIS_TAC [MEMBER_NOT_EMPTY] \\
3418       METIS_TAC [] ])
3419 >> DISCH_TAC
3420 >> ‘{x | Normal c <= f x} INTER space a =
3421     {x | Normal c <= inf (IMAGE (\n. fi n x) X)} INTER space a’
3422       by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, IN_INTER] >> METIS_TAC [])
3423 >> NTAC 2 POP_ORW
3424 >> Q.ABBREV_TAC ‘A = \n. {x | Normal c <= fi n x} INTER space a’
3425 >> ‘IMAGE A X = {A i | i IN X}’ by SET_TAC [] >> POP_ORW
3426 >> MATCH_MP_TAC (Q.SPECL [‘space a’, ‘subsets a’] SIGMA_ALGEBRA_COUNTABLE_INT)
3427 >> rw [IN_FUNSET, space_def, subsets_def, SPACE, SUBSET_DEF, Abbr ‘A’]
3428 >> FIRST_X_ASSUM MATCH_MP_TAC >> art []
3429QED
3430
3431(* a generalized version of IN_MEASURABLE_BOREL_MAX, cf. sup_maximal *)
3432Theorem IN_MEASURABLE_BOREL_MAXIMAL :
3433    !N. FINITE (N :'b set) ==>
3434        !g f a. sigma_algebra a /\ (!n. g n IN measurable a Borel) /\
3435               (!x. f x = sup (IMAGE (\n. g n x) N)) ==> f IN measurable a Borel
3436Proof
3437    HO_MATCH_MP_TAC FINITE_INDUCT
3438 >> RW_TAC std_ss [sup_empty, IMAGE_EMPTY, IMAGE_INSERT]
3439 >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_CONST \\
3440     Q.EXISTS_TAC `NegInf` >> art [])
3441 >> Cases_on `N = {}`
3442 >- (fs [IMAGE_EMPTY, sup_sing] >> METIS_TAC [])
3443 >> Know `!x. sup (g e x INSERT (IMAGE (\n. g n x) N)) =
3444              max (g e x) (sup (IMAGE (\n. g n x) N))`
3445 >- (RW_TAC std_ss [sup_eq'] >| (* 2 subgoals *)
3446    [ (* goal 1 (of 2) *)
3447      fs [IN_INSERT, le_max] >> DISJ2_TAC \\
3448      MATCH_MP_TAC le_sup_imp' >> rw [IN_IMAGE] \\
3449      Q.EXISTS_TAC `n` >> art [],
3450      (* goal 2 (of 2) *)
3451      POP_ASSUM MATCH_MP_TAC \\
3452      fs [IN_INSERT, extreal_max_def] \\
3453      Cases_on `g e x <= sup (IMAGE (\n. g n x) N)` >> fs [] \\
3454      DISJ2_TAC \\
3455     `FINITE (IMAGE (\n. g n x) N)` by METIS_TAC [IMAGE_FINITE] \\
3456      Know `IMAGE (\n. g n x) N <> {}`
3457      >- (RW_TAC set_ss [NOT_IN_EMPTY, Once EXTENSION]) >> DISCH_TAC \\
3458     `sup (IMAGE (\n. g n x) N) IN (IMAGE (\n. g n x) N)` by METIS_TAC [sup_maximal] \\
3459      fs [IN_IMAGE] >> Q.EXISTS_TAC `n` >> art [] ])
3460 >> DISCH_THEN (fs o wrap)
3461 >> Q.PAT_X_ASSUM `!g f a. P => f IN Borel_measurable a`
3462      (MP_TAC o (Q.SPECL [`g`, `\x. sup (IMAGE (\n. g n x) N)`, `a`]))
3463 >> rw []
3464 >> `f = \x. max (g e x) ((\x. sup (IMAGE (\n. g n x) N)) x)` by METIS_TAC []
3465 >> POP_ORW
3466 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_MAX >> art []
3467QED
3468
3469(* a generalized version of IN_MEASURABLE_BOREL_MIN, cf. inf_minimal *)
3470Theorem IN_MEASURABLE_BOREL_MINIMAL :
3471    !N. FINITE (N :'b set) ==>
3472        !g f a. sigma_algebra a /\ (!n. g n IN measurable a Borel) /\
3473               (!x. f x = inf (IMAGE (\n. g n x) N)) ==> f IN measurable a Borel
3474Proof
3475    HO_MATCH_MP_TAC FINITE_INDUCT
3476 >> RW_TAC std_ss [inf_empty, IMAGE_EMPTY, IMAGE_INSERT]
3477 >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_CONST \\
3478     Q.EXISTS_TAC `PosInf` >> art [])
3479 >> Cases_on `N = {}`
3480 >- (fs [IMAGE_EMPTY, inf_sing] >> METIS_TAC [])
3481 >> Know `!x. inf (g e x INSERT (IMAGE (\n. g n x) N)) =
3482              min (g e x) (inf (IMAGE (\n. g n x) N))`
3483 >- (RW_TAC std_ss [inf_eq'] >| (* 2 subgoals *)
3484    [ (* goal 1 (of 2) *)
3485      fs [IN_INSERT, min_le] >> DISJ2_TAC \\
3486      MATCH_MP_TAC inf_le_imp' >> rw [IN_IMAGE] \\
3487      Q.EXISTS_TAC `n` >> art [],
3488      (* goal 2 (of 2) *)
3489      POP_ASSUM MATCH_MP_TAC \\
3490      fs [IN_INSERT, extreal_min_def] \\
3491      Cases_on `g e x <= inf (IMAGE (\n. g n x) N)` >> fs [] \\
3492      DISJ2_TAC \\
3493     `FINITE (IMAGE (\n. g n x) N)` by METIS_TAC [IMAGE_FINITE] \\
3494      Know `IMAGE (\n. g n x) N <> {}`
3495      >- (RW_TAC set_ss [NOT_IN_EMPTY, Once EXTENSION]) >> DISCH_TAC \\
3496     `inf (IMAGE (\n. g n x) N) IN (IMAGE (\n. g n x) N)` by METIS_TAC [inf_minimal] \\
3497      fs [IN_IMAGE] >> Q.EXISTS_TAC `n` >> art [] ])
3498 >> DISCH_THEN (fs o wrap)
3499 >> Q.PAT_X_ASSUM `!g f a. P => f IN Borel_measurable a`
3500      (MP_TAC o (Q.SPECL [`g`, `\x. inf (IMAGE (\n. g n x) N)`, `a`]))
3501 >> rw []
3502 >> `f = \x. min (g e x) ((\x. inf (IMAGE (\n. g n x) N)) x)` by METIS_TAC []
3503 >> POP_ORW
3504 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_MIN >> art []
3505QED
3506
3507Theorem IN_MEASURABLE_BOREL_SUMINF :
3508    !fn f a. sigma_algebra a /\ (!n:num. fn n IN measurable a Borel) /\
3509            (!i x. x IN space a ==> 0 <= fn i x) /\
3510            (!x. x IN space a ==> (f x = suminf (\n. fn n x))) ==> f IN measurable a Borel
3511Proof
3512    rpt STRIP_TAC
3513 >> Know `!x. x IN space a ==>
3514              f x = sup (IMAGE (\n. SIGMA (\i. fn i x) (count n)) univ(:num))`
3515 >- (rpt STRIP_TAC \\
3516     RES_TAC >> Q.PAT_X_ASSUM `f x = Y` (ONCE_REWRITE_TAC o wrap) \\
3517     MATCH_MP_TAC ext_suminf_def >> rw []) >> DISCH_TAC
3518 >> Q.PAT_X_ASSUM `!x. x IN space a ==> f x = suminf (\n. fn n x)` K_TAC
3519 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_MONO_SUP
3520 >> Q.EXISTS_TAC `\n x. SIGMA (\i. fn i x) (count n)`
3521 >> RW_TAC std_ss []
3522 >| [ (* goal 1 (of 2) *)
3523      MATCH_MP_TAC (ISPECL [``a :'a algebra``, ``fn :num -> 'a -> extreal``]
3524                           IN_MEASURABLE_BOREL_SUM) \\
3525      Q.EXISTS_TAC `count n` >> RW_TAC std_ss [FINITE_COUNT, IN_COUNT] \\
3526      MATCH_MP_TAC pos_not_neginf >> PROVE_TAC [],
3527      (* goal 2 (of 2) *)
3528      MATCH_MP_TAC EXTREAL_SUM_IMAGE_MONO_SET \\
3529      RW_TAC arith_ss [COUNT_SUC, SUBSET_DEF, FINITE_COUNT, IN_COUNT] ]
3530QED
3531
3532(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
3533Theorem IN_MEASURABLE_BOREL_FN_PLUS :
3534    !a f. sigma_algebra a /\ f IN measurable a Borel ==>
3535          fn_plus f IN measurable a Borel
3536Proof
3537    rpt STRIP_TAC
3538 >> rfs [IN_MEASURABLE_BOREL, IN_FUNSET, fn_plus_def]
3539 >> Q.X_GEN_TAC ‘c’
3540 >> Cases_on `c <= 0`
3541 >- (`{x | (if 0 < f x then f x else 0) < Normal c} = {}`
3542       by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, NOT_IN_EMPTY] \\
3543          `!x. 0 <= (if 0 < f x then f x else 0)`
3544             by RW_TAC real_ss [lt_imp_le, le_refl] \\
3545           METIS_TAC [le_trans, extreal_lt_def, extreal_of_num_def, extreal_le_def]) \\
3546     METIS_TAC [sigma_algebra_def, algebra_def, INTER_EMPTY])
3547 >> `{x | (if 0 < f x then f x else 0) < Normal c} = {x | f x < Normal c}`
3548       by (RW_TAC real_ss [EXTENSION, GSPECIFICATION] \\
3549           EQ_TAC
3550           >- (RW_TAC real_ss [] >> METIS_TAC [extreal_lt_def, let_trans]) \\
3551           RW_TAC real_ss [] \\
3552           METIS_TAC [extreal_lt_eq, extreal_of_num_def, real_lte])
3553 >> METIS_TAC []
3554QED
3555
3556(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’ *)
3557Theorem IN_MEASURABLE_BOREL_FN_MINUS :
3558    !a f. sigma_algebra a /\ f IN measurable a Borel ==>
3559          fn_minus f IN measurable a Borel
3560Proof
3561    RW_TAC std_ss [fn_minus_def]
3562 >> rw [IN_MEASURABLE_BOREL, IN_FUNSET]
3563 >> Cases_on `c <= 0`
3564 >- (`{x | (if f x < 0 then -f x else 0) < Normal c} = {}`
3565        by (RW_TAC std_ss [EXTENSION, GSPECIFICATION, NOT_IN_EMPTY] \\
3566           `!x. 0 <= (if f x < 0 then -f x else 0)`
3567                 by (RW_TAC real_ss [le_refl] \\
3568                     METIS_TAC [lt_neg, neg_0, lt_imp_le]) \\
3569            METIS_TAC [extreal_of_num_def, extreal_le_def, le_trans, extreal_lt_def]) \\
3570     METIS_TAC [sigma_algebra_def, algebra_def, INTER_EMPTY, IN_MEASURABLE_BOREL])
3571 >> `{x | (if f x < 0 then -f x else 0) < Normal c} = {x | Normal (-c) < f x}`
3572        by (RW_TAC real_ss [EXTENSION,GSPECIFICATION] \\
3573            EQ_TAC
3574            >- (RW_TAC std_ss [] >- METIS_TAC [lt_neg, neg_neg, extreal_ainv_def] \\
3575                METIS_TAC [lt_neg, neg_neg, neg_0, extreal_lt_def, lte_trans, lt_imp_le,
3576                           extreal_ainv_def]) \\
3577            RW_TAC std_ss [] >- METIS_TAC [lt_neg, neg_neg, extreal_ainv_def] \\
3578            METIS_TAC [real_lte, extreal_lt_eq, extreal_of_num_def, extreal_ainv_def])
3579 >> METIS_TAC [IN_MEASURABLE_BOREL_ALL]
3580QED
3581
3582(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’
3583
3584   This theorem is used in martingaleTheory.FUBINI.
3585 *)
3586Theorem IN_MEASURABLE_BOREL_PLUS_MINUS :
3587    !a f. sigma_algebra a ==>
3588         (f IN measurable a Borel <=>
3589          fn_plus f IN measurable a Borel /\ fn_minus f IN measurable a Borel)
3590Proof
3591    rpt STRIP_TAC
3592 >> EQ_TAC
3593 >- RW_TAC std_ss [IN_MEASURABLE_BOREL_FN_PLUS, IN_MEASURABLE_BOREL_FN_MINUS]
3594 >> rpt STRIP_TAC
3595 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_SUB
3596 >> qexistsl_tac [`fn_plus f`, `fn_minus f`]
3597 >> RW_TAC std_ss [fn_plus_def, fn_minus_def, sub_rzero, lt_antisym, sub_rzero,
3598                   add_lzero]
3599 >| [ (* goal 2 (of 8) *)
3600      METIS_TAC [lt_antisym],
3601      (* goal 3 (of 8) *)
3602      DISJ1_TAC >> REWRITE_TAC [extreal_not_infty, extreal_of_num_def] \\
3603      MATCH_MP_TAC pos_not_neginf \\
3604      MATCH_MP_TAC lt_imp_le >> art [],
3605      (* goal 4 (of 8) *)
3606      DISJ2_TAC >> REWRITE_TAC [extreal_not_infty, extreal_of_num_def] \\
3607      MATCH_MP_TAC pos_not_neginf \\
3608      Suff ‘f x <= 0’ >- METIS_TAC [neg_neg, le_neg, neg_0] \\
3609      MATCH_MP_TAC lt_imp_le >> art [],
3610      (* goal 5 (of 8) *)
3611      METIS_TAC [extreal_not_infty, extreal_of_num_def],
3612      (* goal 6 (of 8) *)
3613      METIS_TAC [lt_antisym],
3614      (* goal 7 (of 8) *)
3615      METIS_TAC [sub_rneg, add_lzero, extreal_of_num_def],
3616      (* goal 8 (of 8) *)
3617      METIS_TAC [le_antisym, extreal_lt_def] ]
3618QED
3619
3620Theorem IN_MEASURABLE_BOREL_LIMSUP :
3621    !a fi f. sigma_algebra a /\ (!n. fi n IN measurable a Borel) /\
3622            (!x. x IN space a ==> f x = limsup (\i. fi i x)) ==>
3623             f IN measurable a Borel
3624Proof
3625    rw [ext_limsup_def]
3626 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_INF
3627 >> qexistsl_tac [‘\m x. sup {fi i x | m <= i}’, ‘UNIV’] >> rw []
3628 >> ‘!x. {fi i x | n <= i} = IMAGE (\i. fi i x) (from n)’
3629      by rw [Once EXTENSION, from_def] >> POP_ORW
3630 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_SUP
3631 >> qexistsl_tac [‘fi’, ‘from n’]
3632 >> simp [FROM_NOT_EMPTY]
3633QED
3634
3635Theorem IN_MEASURABLE_BOREL_LIMINF :
3636    !a fi f. sigma_algebra a /\ (!n. fi n IN measurable a Borel) /\
3637            (!x. x IN space a ==> f x = liminf (\i. fi i x)) ==>
3638             f IN measurable a Borel
3639Proof
3640    rw [ext_liminf_def]
3641 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_SUP
3642 >> qexistsl_tac [‘\m x. inf {fi i x | m <= i}’, ‘UNIV’] >> rw []
3643 >> ‘!x. {fi i x | n <= i} = IMAGE (\i. fi i x) (from n)’
3644      by rw [Once EXTENSION, from_def] >> POP_ORW
3645 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_INF
3646 >> qexistsl_tac [‘fi’, ‘from n’]
3647 >> simp [FROM_NOT_EMPTY]
3648QED
3649
3650(* The reverse version of IN_MEASURABLE_BOREL_IMP_BOREL
3651
3652   NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’
3653 *)
3654Theorem in_borel_measurable_from_Borel :
3655    !a f. sigma_algebra a /\ f IN measurable a Borel ==>
3656         (real o f) IN measurable a borel
3657Proof
3658    rpt GEN_TAC >> STRIP_TAC
3659 >> simp [IN_MEASURABLE, sigma_algebra_borel, IN_FUNSET, space_borel]
3660 >> Q.X_GEN_TAC ‘B’ >> STRIP_TAC
3661 >> rw [PREIMAGE_def]
3662 >> Know ‘{x | real (f x) IN B} INTER space a =
3663          if 0 IN B then
3664            ({x | f x IN (IMAGE Normal B)} INTER space a) UNION
3665            ({x | f x = PosInf} INTER space a) UNION
3666            ({x | f x = NegInf} INTER space a)
3667          else
3668            ({x | f x IN (IMAGE Normal B)} INTER space a)’
3669 >- (Cases_on ‘0 IN B’ >> rw [Once EXTENSION] >| (* 2 subgoals *)
3670     [ (* goal 1 (of 2) *)
3671       EQ_TAC >> rw [] >> rw [real_def] \\
3672       Cases_on ‘f x’ >> fs [real_normal],
3673       (* goal 2 (of 2) *)
3674       EQ_TAC >> rw [] >> rw [real_def] \\
3675       Q.EXISTS_TAC ‘real (f x)’ >> art [] \\
3676       ONCE_REWRITE_TAC [EQ_SYM_EQ] \\
3677       MATCH_MP_TAC normal_real \\
3678       CONJ_TAC >> CCONTR_TAC >> fs [real_def] ])
3679 >> Rewr'
3680 >> Cases_on ‘0 IN B’ >> ASM_SIMP_TAC std_ss []
3681 >| [ (* goal 1 (of 2) *)
3682      MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
3683      reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art []) \\
3684      MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
3685      reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art []) \\
3686      REWRITE_TAC [GSYM PREIMAGE_def] \\
3687      FULL_SIMP_TAC std_ss [Borel, IN_MEASURABLE, SPACE_BOREL, IN_FUNSET,
3688                            SIGMA_ALGEBRA_BOREL, IN_UNIV, subsets_def, GSPECIFICATION] \\
3689      FIRST_X_ASSUM MATCH_MP_TAC \\
3690      qexistsl_tac [‘B’, ‘{}’] >> rw [],
3691      (* goal 2 (of 2) *)
3692      REWRITE_TAC [GSYM PREIMAGE_def] \\
3693      FULL_SIMP_TAC std_ss [Borel, IN_MEASURABLE, SPACE_BOREL, IN_FUNSET,
3694                            SIGMA_ALGEBRA_BOREL, IN_UNIV, subsets_def, GSPECIFICATION] \\
3695      FIRST_X_ASSUM MATCH_MP_TAC \\
3696      qexistsl_tac [‘B’, ‘{}’] >> rw [] ]
3697QED
3698
3699Theorem IN_MEASURABLE_BOREL_IMP_BOREL : (* was: borel_IMP_Borel *)
3700    !f m. f IN measurable (m_space m,measurable_sets m) borel ==>
3701          (Normal o f) IN measurable (m_space m,measurable_sets m) Borel
3702Proof
3703    RW_TAC std_ss [IN_MEASURABLE, SIGMA_ALGEBRA_BOREL, o_DEF]
3704 >- (EVAL_TAC >> SRW_TAC[] [IN_DEF, IN_FUNSET])
3705 >> FULL_SIMP_TAC std_ss [space_def, subsets_def]
3706 >> Know ‘PREIMAGE (\x. Normal (f x)) s = PREIMAGE f (real_set s)’
3707 >- (SIMP_TAC std_ss [PREIMAGE_def, EXTENSION, GSPECIFICATION] \\
3708     RW_TAC std_ss [real_set_def, GSPECIFICATION] \\
3709     EQ_TAC >> RW_TAC std_ss []
3710     >- (Q.EXISTS_TAC `Normal (f x)` \\
3711         ASM_SIMP_TAC std_ss [extreal_not_infty, real_normal]) \\
3712     ASM_SIMP_TAC std_ss [normal_real])
3713 >> DISCH_TAC
3714 >> FULL_SIMP_TAC std_ss []
3715 >> FIRST_X_ASSUM MATCH_MP_TAC
3716 >> UNDISCH_TAC ``s IN subsets Borel``
3717 >> FULL_SIMP_TAC std_ss [borel_eq_less, Borel_def]
3718 >> RW_TAC std_ss [subsets_def, sigma_def, IN_BIGINTER, GSPECIFICATION, SUBSET_DEF]
3719 >> FIRST_X_ASSUM (MP_TAC o Q.SPEC `{s | real_set s IN P}`)
3720 >> RW_TAC std_ss [IN_IMAGE, IN_UNIV, GSPECIFICATION]
3721 >> FIRST_X_ASSUM MATCH_MP_TAC >> CONJ_TAC
3722 >- (RW_TAC std_ss [real_set_def] >> SIMP_TAC std_ss [GSPECIFICATION] \\
3723     FIRST_X_ASSUM MATCH_MP_TAC \\
3724     SIMP_TAC std_ss [IN_IMAGE, IN_UNIV] \\
3725     SIMP_TAC std_ss [EXTENSION, GSPECIFICATION] >> Q.EXISTS_TAC `a` \\
3726     GEN_TAC >> EQ_TAC >> RW_TAC std_ss []
3727     >- (ONCE_REWRITE_TAC [GSYM extreal_lt_eq] \\
3728         ASM_SIMP_TAC std_ss [normal_real]) \\
3729     Q.EXISTS_TAC `Normal x` \\
3730     ASM_SIMP_TAC std_ss [extreal_lt_eq, extreal_not_infty, real_normal])
3731 >> POP_ASSUM MP_TAC
3732 (* sigma_algebra (UNIV,P) ==> sigma_algebra (UNIV,{s | real_set s IN P}) *)
3733 >> RW_TAC std_ss [sigma_algebra_alt_pow]
3734 >| [ (* goal 1 (of 4) *)
3735      SIMP_TAC std_ss [SUBSET_DEF, IN_POW, IN_UNIV],
3736      (* goal 2 (of 4) *)
3737      SIMP_TAC std_ss [GSPECIFICATION, real_set_def, NOT_IN_EMPTY] \\
3738      ASM_SIMP_TAC std_ss [SET_RULE ``{real x | F} = {}``],
3739      (* goal 3 (of 4) *)
3740      POP_ASSUM MP_TAC >> SIMP_TAC std_ss [GSPECIFICATION] >> DISCH_TAC \\
3741      FIRST_X_ASSUM (MP_TAC o Q.SPEC `real_set s'`) >> ASM_REWRITE_TAC [] \\
3742      SIMP_TAC std_ss [real_set_def, GSPECIFICATION, IN_DIFF, IN_UNIV] \\
3743      SIMP_TAC std_ss [DIFF_DEF, IN_UNIV, GSPECIFICATION] \\
3744      MATCH_MP_TAC EQ_IMPLIES >> AP_THM_TAC >> AP_TERM_TAC \\
3745      SIMP_TAC std_ss [EXTENSION, GSPECIFICATION] \\
3746      GEN_TAC >> EQ_TAC
3747      >- (RW_TAC std_ss [] >> Q.EXISTS_TAC `Normal x` \\
3748          POP_ASSUM (MP_TAC o Q.SPEC `Normal x`) \\
3749          SIMP_TAC std_ss [real_normal, extreal_not_infty]) \\
3750      RW_TAC std_ss [] >> ASM_CASES_TAC ``real x' <> real x''`` \\
3751      ASM_REWRITE_TAC [] \\
3752      ASM_CASES_TAC ``x'' = PosInf`` >> ASM_REWRITE_TAC [] \\
3753      ASM_CASES_TAC ``x'' = NegInf`` >> ASM_REWRITE_TAC [] \\
3754      FULL_SIMP_TAC std_ss [] >> UNDISCH_TAC ``real x' = real x''`` \\
3755      ONCE_REWRITE_TAC [GSYM extreal_11] >> FULL_SIMP_TAC std_ss [normal_real] \\
3756      METIS_TAC [],
3757      (* goal 4 (of 4) *)
3758      SIMP_TAC std_ss [GSPECIFICATION] \\
3759      FIRST_X_ASSUM (MP_TAC o Q.SPEC `(\i. real_set (A i))`) \\
3760      Suff `real_set (BIGUNION {A i | i IN univ(:num)}) =
3761            BIGUNION {(\i. real_set (A i)) i | i IN univ(:num)}`
3762      >- (Rewr' >> DISCH_THEN (MATCH_MP_TAC) >> POP_ASSUM MP_TAC \\
3763          RW_TAC std_ss [SUBSET_DEF, IN_IMAGE, IN_UNIV, GSPECIFICATION] \\
3764          FIRST_X_ASSUM MATCH_MP_TAC >> METIS_TAC []) \\
3765      SIMP_TAC std_ss [real_set_def, EXTENSION, GSPECIFICATION, IN_BIGUNION] \\
3766      GEN_TAC >> EQ_TAC >> RW_TAC std_ss []
3767      >- (Q.EXISTS_TAC `real_set s'` \\
3768          CONJ_TAC
3769          >- (SIMP_TAC std_ss [real_set_def, GSPECIFICATION] >> METIS_TAC []) \\
3770          SIMP_TAC std_ss [IN_UNIV] \\
3771          Q.EXISTS_TAC `i` >> GEN_TAC \\
3772          SIMP_TAC std_ss [real_set_def, GSPECIFICATION] \\
3773          METIS_TAC []) \\
3774      UNDISCH_TAC ``(x:real) IN s'`` >> ASM_REWRITE_TAC [] \\
3775      RW_TAC std_ss [] >> Q.EXISTS_TAC `x'` \\
3776      ASM_REWRITE_TAC [IN_UNIV] >> Q.EXISTS_TAC `A i` \\
3777      METIS_TAC [] ]
3778QED
3779
3780Theorem IN_MEASURABLE_BOREL_IMP_BOREL' :
3781    !a f. sigma_algebra a /\ f IN measurable a borel ==>
3782         (Normal o f) IN measurable a Borel
3783Proof
3784    rpt STRIP_TAC
3785 >> MP_TAC (Q.SPECL [‘f’, ‘(space a,subsets a,(\s. 0))’]
3786                    IN_MEASURABLE_BOREL_IMP_BOREL)
3787 >> Know ‘sigma_finite_measure_space (space a,subsets a,(\s. 0))’
3788 >- (MATCH_MP_TAC measure_space_trivial >> art [])
3789 >> rw [sigma_finite_measure_space_def]
3790QED
3791
3792(* |- !f. f IN borel_measurable borel ==>
3793          (\x. Normal (f x)) IN Borel_measurable borel
3794 *)
3795Theorem IN_MEASURABLE_BOREL_BOREL_NORMAL =
3796        IN_MEASURABLE_BOREL_IMP_BOREL' |> SRULE [o_DEF] |> ISPEC “borel”
3797                                       |> REWRITE_RULE [sigma_algebra_borel]
3798
3799Theorem real_in_borel_measurable :
3800    real IN measurable Borel borel
3801Proof
3802    rw [in_borel_measurable_le, SIGMA_ALGEBRA_BOREL, SPACE_BOREL, IN_FUNSET]
3803 >> Cases_on ‘0 <= a’
3804 >- (Know ‘{w | real w <= a} = {x | x <= Normal a} UNION {PosInf}’
3805     >- (rw [Once EXTENSION] \\
3806         Cases_on ‘x = PosInf’ >- rw [real_def] \\
3807         Cases_on ‘x = NegInf’ >- rw [real_def] \\
3808        ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] >> rw []) >> Rewr' \\
3809     MATCH_MP_TAC SIGMA_ALGEBRA_UNION \\
3810     rw [SIGMA_ALGEBRA_BOREL, BOREL_MEASURABLE_SETS_RC])
3811 >> fs [GSYM real_lt]
3812 (* stage work *)
3813 >> Know ‘{w | real w <= a} = {x | x <= Normal a} DIFF {NegInf}’
3814 >- (rw [Once EXTENSION] \\
3815     Cases_on ‘x = PosInf’ >- rw [real_def, GSYM real_lt] \\
3816     Cases_on ‘x = NegInf’ >- rw [real_def, GSYM real_lt] \\
3817    ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] >> rw [])
3818 >> Rewr'
3819 >> MATCH_MP_TAC SIGMA_ALGEBRA_DIFF
3820 >> rw [SIGMA_ALGEBRA_BOREL, BOREL_MEASURABLE_SETS_RC]
3821QED
3822
3823Theorem in_measurable_sigma_pow : (* was: measurable_measure_of *)
3824    !m sp N f. measure_space m /\
3825               N SUBSET POW sp /\ f IN (m_space m -> sp) /\
3826              (!y. y IN N ==>
3827                  (PREIMAGE f y) INTER m_space m IN measurable_sets m) ==>
3828               f IN measurable (m_space m, measurable_sets m) (sigma sp N)
3829Proof
3830    RW_TAC std_ss [] >> MATCH_MP_TAC MEASURABLE_SIGMA
3831 >> FULL_SIMP_TAC std_ss [measure_space_def, subset_class_def]
3832 >> CONJ_TAC >- (ASM_SET_TAC [POW_DEF])
3833 >> RW_TAC std_ss []
3834 >- (SIMP_TAC std_ss [space_def, sigma_def] \\
3835     POP_ASSUM MP_TAC >> POP_ASSUM MP_TAC >> EVAL_TAC >> METIS_TAC [])
3836 >> FULL_SIMP_TAC std_ss [space_def, subsets_def]
3837QED
3838
3839Theorem in_borel_measurable_imp : (* was: borel_measurableI *)
3840    !m f. measure_space m /\
3841         (!s. open s ==> (PREIMAGE f s) INTER m_space m IN measurable_sets m) ==>
3842          f IN measurable (m_space m, measurable_sets m) borel
3843Proof
3844    RW_TAC std_ss [borel]
3845 >> MATCH_MP_TAC in_measurable_sigma_pow
3846 >> ASM_SIMP_TAC std_ss [IN_FUNSET, IN_UNIV]
3847 >> CONJ_TAC >- SET_TAC [POW_DEF]
3848 >> ASM_SET_TAC []
3849QED
3850
3851(* ------------------------------------------------------------------------- *)
3852(*  Construction of Borel measure space by CARATHEODORY_SEMIRING             *)
3853(* ------------------------------------------------------------------------- *)
3854
3855(* The content (length) of [a, b), cf. integrationTheory.content *)
3856local
3857  val thm = prove (
3858    ``?l. !a b. a <= b ==> (l (right_open_interval a b) = Normal (b - a))``,
3859      Q.EXISTS_TAC `Normal o content` (* detail is not important *)
3860   >> RW_TAC std_ss [o_DEF, content]
3861   >- (IMP_RES_TAC REAL_LE_LT >> fs [right_open_interval_empty])
3862   >> fs [right_open_interval_empty]
3863   >> rw [right_open_interval_lowerbound, right_open_interval_upperbound]);
3864in
3865  (* |- !a b. a <= b ==> (lambda0 (right_open_interval a b) = Normal (b - a) *)
3866  val lambda0_def = new_specification ("lambda0_def", ["lambda0"], thm);
3867end;
3868
3869Overload lborel0 =
3870        “(space right_open_intervals,subsets right_open_intervals,lambda0)”
3871
3872Theorem lambda0_empty :
3873    lambda0 {} = 0
3874Proof
3875    MP_TAC (REWRITE_RULE [le_refl] (Q.SPECL [`0`, `0`] lambda0_def))
3876 >> `right_open_interval 0 0 = {}`
3877      by PROVE_TAC [right_open_interval_empty_eq, REAL_LE_REFL]
3878 >> rw [extreal_of_num_def]
3879QED
3880
3881Theorem lambda0_not_infty :
3882    !a b. lambda0 (right_open_interval a b) <> PosInf /\
3883          lambda0 (right_open_interval a b) <> NegInf
3884Proof
3885    rpt GEN_TAC
3886 >> Cases_on `a < b`
3887 >- (IMP_RES_TAC REAL_LT_IMP_LE \\
3888     ASM_SIMP_TAC std_ss [lambda0_def, extreal_not_infty])
3889 >> fs [GSYM right_open_interval_empty, lambda0_empty,
3890        extreal_of_num_def, extreal_not_infty]
3891QED
3892
3893Theorem lborel0_positive :
3894    positive lborel0
3895Proof
3896    RW_TAC std_ss [positive_def, measure_def, measurable_sets_def, lambda0_empty]
3897 >> fs [right_open_intervals, subsets_def]
3898 >> Cases_on `a < b`
3899 >- (IMP_RES_TAC REAL_LT_LE \\
3900     rw [lambda0_def, extreal_of_num_def, extreal_le_eq] \\
3901     REAL_ASM_ARITH_TAC)
3902 >> fs [GSYM right_open_interval_empty, lambda0_empty, le_refl]
3903QED
3904
3905Theorem lborel0_subadditive :
3906    subadditive lborel0
3907Proof
3908    RW_TAC std_ss [subadditive_def, measure_def, measurable_sets_def, subsets_def,
3909                   right_open_intervals, GSPECIFICATION]
3910 >> Cases_on `x` >> Cases_on `x'` >> Cases_on `x''` >> fs []
3911 >> rename1 `s = right_open_interval a b`
3912 >> rename1 `t = right_open_interval c d`
3913 >> rename1 `s UNION t = right_open_interval q r`
3914 >> Cases_on `~(a < b)`
3915 >- (fs [GSYM right_open_interval_empty, right_open_interval, lambda0_empty,
3916         add_lzero, add_rzero] \\
3917     rfs [UNION_EMPTY, le_refl])
3918 >> Cases_on `~(c < d)`
3919 >- (fs [GSYM right_open_interval_empty, right_open_interval, lambda0_empty,
3920         add_lzero, add_rzero] \\
3921     rfs [UNION_EMPTY, le_refl])
3922 >> fs [] (* now: a < b /\ c < d *)
3923 >> Know `s UNION t IN subsets right_open_intervals`
3924 >- (SIMP_TAC std_ss [right_open_intervals, subsets_def, GSPECIFICATION] \\
3925     Q.EXISTS_TAC `(q,r)` >> ASM_SIMP_TAC std_ss [])
3926 >> DISCH_TAC
3927 >> `a <= d /\ c <= b` by PROVE_TAC [right_open_interval_union_imp]
3928 >> `s UNION t = right_open_interval (min a c) (max b d)`
3929     by PROVE_TAC [right_open_interval_union]
3930 >> `s <> {} /\ t <> {}` by PROVE_TAC [right_open_interval_empty]
3931 >> `s UNION t <> {}` by ASM_SET_TAC []
3932 >> `q < r /\ min a c < max b d` by PROVE_TAC [right_open_interval_empty]
3933 >> `(q = min a c) /\ (r = max b d)` by PROVE_TAC [right_open_interval_11]
3934 >> FULL_SIMP_TAC std_ss []
3935 (* max b d - min a c <= b - a + (d - c) *)
3936 >> IMP_RES_TAC REAL_LT_IMP_LE
3937 >> rw [lambda0_def, extreal_add_def, extreal_le_eq]
3938 >> `0 < b - a /\ 0 < d - c` by REAL_ASM_ARITH_TAC
3939 >> Cases_on `b <= d` >> Cases_on `a <= c`
3940 >> FULL_SIMP_TAC std_ss [real_lte, REAL_MAX_REDUCE, REAL_MIN_REDUCE]
3941 >> REAL_ASM_ARITH_TAC
3942QED
3943
3944Theorem lborel0_additive :
3945    additive lborel0
3946Proof
3947    RW_TAC std_ss [additive_def, measure_def, measurable_sets_def, subsets_def,
3948                   right_open_intervals, GSPECIFICATION]
3949 (* rename the variables *)
3950 >> Cases_on `x` >> Cases_on `x'` >> Cases_on `x''` >> fs []
3951 >> rename1 `s = right_open_interval a b`
3952 >> rename1 `t = right_open_interval c d`
3953 >> rename1 `s UNION t = right_open_interval q r`
3954 >> Cases_on `~(a < b)`
3955 >- (fs [GSYM right_open_interval_empty, right_open_interval, lambda0_empty,
3956         add_lzero, add_rzero] \\
3957     rfs [UNION_EMPTY])
3958 >> Cases_on `~(c < d)`
3959 >- (fs [GSYM right_open_interval_empty, right_open_interval, lambda0_empty,
3960         add_lzero, add_rzero] \\
3961     rfs [UNION_EMPTY])
3962 >> fs [] (* now: a < b /\ c < d *)
3963 >> Know `s UNION t IN subsets right_open_intervals`
3964 >- (SIMP_TAC std_ss [right_open_intervals, subsets_def, GSPECIFICATION] \\
3965     Q.EXISTS_TAC `(q,r)` >> ASM_SIMP_TAC std_ss [])
3966 >> DISCH_TAC
3967 >> `a <= d /\ c <= b` by PROVE_TAC [right_open_interval_union_imp]
3968 >> `s UNION t = right_open_interval (min a c) (max b d)`
3969     by PROVE_TAC [right_open_interval_union]
3970 >> `s <> {} /\ t <> {}` by PROVE_TAC [right_open_interval_empty]
3971 >> `s UNION t <> {}` by ASM_SET_TAC []
3972 >> `q < r /\ min a c < max b d` by PROVE_TAC [right_open_interval_empty]
3973 >> `(q = min a c) /\ (r = max b d)` by PROVE_TAC [right_open_interval_11]
3974 >> FULL_SIMP_TAC std_ss []
3975 >> IMP_RES_TAC REAL_LT_IMP_LE
3976 >> ASM_SIMP_TAC std_ss [lambda0_def, extreal_add_def, extreal_11]
3977 (* max b d - min a c = b - a + (d - c) *)
3978 >> Know `b <= c \/ d <= a`
3979 >- (MATCH_MP_TAC right_open_interval_DISJOINT_imp >> PROVE_TAC [])
3980 (* clean up useless assumptions *)
3981 >> Q.PAT_X_ASSUM `s = right_open_interval a b` K_TAC
3982 >> Q.PAT_X_ASSUM `t = right_open_interval c d` K_TAC
3983 >> Q.PAT_X_ASSUM `_ IN subsets right_open_intervals` K_TAC
3984 >> Q.PAT_X_ASSUM `s UNION t = _` K_TAC
3985 >> Q.PAT_X_ASSUM `s UNION t <> {}` K_TAC
3986 >> Q.PAT_X_ASSUM `s <> {}` K_TAC
3987 >> Q.PAT_X_ASSUM `t <> {}` K_TAC
3988 >> Q.PAT_X_ASSUM `q = _` K_TAC
3989 >> Q.PAT_X_ASSUM `r = _` K_TAC
3990 >> Q.PAT_X_ASSUM `DISJOINT s t` K_TAC
3991 (* below are pure real arithmetic problems *)
3992 >> STRIP_TAC
3993 >| [ (* goal 1 (of 2) *)
3994     `a <= c /\ b <= d` by PROVE_TAC [REAL_LE_TRANS] \\
3995      fs [REAL_MAX_REDUCE, REAL_MIN_REDUCE] \\
3996      REAL_ASM_ARITH_TAC,
3997      (* goal 2 (of 2) *)
3998     `d <= b /\ c <= a` by PROVE_TAC [REAL_LE_TRANS] \\
3999      fs [REAL_MAX_REDUCE, REAL_MIN_REDUCE] \\
4000      REAL_ASM_ARITH_TAC ]
4001QED
4002
4003(* It seems that additivity of semiring does not imply finite additivity in
4004   general. To prove finite additivity of lborel0, we must first filter out
4005   all empty sets, then sort the rest of sets to guarantee that the first n
4006   sets still form a right-open interval.  -- Chun Tian, 26/1/2020
4007 *)
4008Theorem lborel0_finite_additive :
4009    finite_additive lborel0
4010Proof
4011    RW_TAC std_ss [finite_additive_def, measure_def, measurable_sets_def]
4012 >> ASSUME_TAC right_open_intervals_semiring
4013 >> ASSUME_TAC lborel0_positive
4014 >> ASSUME_TAC lborel0_additive
4015 (* spacial case 1: n = 0 *)
4016 >> `(n = 0) \/ 0 < n` by RW_TAC arith_ss []
4017 >- (rw [COUNT_ZERO, IMAGE_EMPTY, BIGUNION_EMPTY, EXTREAL_SUM_IMAGE_EMPTY] \\
4018     fs [semiring_def, space_def, subsets_def,
4019         positive_def, measurable_sets_def, measure_def])
4020 (* special case 2: all f(i) = {} *)
4021 >> Cases_on `!k. k < n ==> f k = {}`
4022 >- (Suff `BIGUNION (IMAGE f (count n)) = {}`
4023     >- (Rewr' >> fs [positive_def, measurable_sets_def, measure_def] \\
4024         MATCH_MP_TAC EXTREAL_SUM_IMAGE_0 \\
4025         rw [FINITE_COUNT, IN_COUNT, o_DEF]) \\
4026     RW_TAC std_ss [Once EXTENSION, IN_BIGUNION_IMAGE, IN_COUNT, NOT_IN_EMPTY] \\
4027     STRONG_DISJ_TAC >> rw [])
4028 >> FULL_SIMP_TAC bool_ss [] (* f k <> {} *)
4029 (* Below are new proofs based on TOPOLOGICAL_SORT' *)
4030 >> Q.ABBREV_TAC ‘filtered = {i | i < n /\ f i <> {}}’
4031 >> ‘filtered SUBSET (count n)’ by rw [Abbr ‘filtered’, SUBSET_DEF]
4032 >> Know ‘FINITE filtered’
4033 >- (MATCH_MP_TAC SUBSET_FINITE_I \\
4034     Q.EXISTS_TAC ‘count n’ >> rw [IMAGE_FINITE])
4035 >> DISCH_TAC
4036 >> Q.ABBREV_TAC ‘N = CARD filtered’
4037 >> Know ‘0 < N /\ N <= n’
4038 >- (rw [Abbr ‘N’, GSYM NOT_ZERO_LT_ZERO, CARD_EQ_0, GSYM MEMBER_NOT_EMPTY] >|
4039     [ (* goal 1 (of 2) *)
4040       rw [Abbr ‘filtered’] \\
4041       Q.EXISTS_TAC ‘k’ >> rw [MEMBER_NOT_EMPTY],
4042       (* goal 2 (of 2) *)
4043      ‘n = CARD (count n)’ by PROVE_TAC [CARD_COUNT] >> POP_ORW \\
4044       irule CARD_SUBSET >> rw [] ])
4045 >> STRIP_TAC
4046 >> Q.PAT_X_ASSUM ‘k < n’     K_TAC
4047 >> Q.PAT_X_ASSUM ‘f k <> {}’ K_TAC
4048 >> ‘filtered HAS_SIZE N’ by PROVE_TAC [HAS_SIZE]
4049 (* preparing for TOPOLOGICAL_SORT' (on ‘filtered’) *)
4050 >> Q.ABBREV_TAC ‘R = \i j. i < n /\ j < n /\ f i <> {} /\ f j <> {} /\
4051                            interval_lowerbound (f i) <= interval_lowerbound (f j)’
4052 >> Know ‘transitive R /\ antisymmetric R’
4053 >- (rw [Abbr ‘R’, transitive_def, antisymmetric_def] >- PROVE_TAC [REAL_LE_TRANS] \\
4054    ‘interval_lowerbound (f i) = interval_lowerbound (f j)’ by PROVE_TAC [REAL_LE_ANTISYM] \\
4055    ‘?a1 b1. a1 < b1 /\ f i = right_open_interval a1 b1’
4056        by METIS_TAC [in_right_open_intervals_nonempty] \\
4057    ‘?a2 b2. a2 < b2 /\ f j = right_open_interval a2 b2’
4058        by METIS_TAC [in_right_open_intervals_nonempty] \\
4059     FULL_SIMP_TAC std_ss [right_open_interval_lowerbound] \\
4060     CCONTR_TAC \\
4061     Q.PAT_X_ASSUM ‘!i j. _ ==> DISJOINT (f i) (f j)’ (MP_TAC o (Q.SPECL [‘i’, ‘j’])) \\
4062     simp [DISJOINT_ALT] \\
4063    ‘a2 < min b1 b2’ by PROVE_TAC [REAL_LT_MIN] \\
4064    ‘?z. a2 < z /\ z < min b1 b2’ by METIS_TAC [REAL_MEAN] \\
4065     FULL_SIMP_TAC std_ss [REAL_LT_MIN] \\
4066     Q.EXISTS_TAC ‘z’ >> rw [in_right_open_interval, REAL_LT_IMP_LE])
4067 >> STRIP_TAC
4068 (* applying TOPOLOGICAL_SORT' *)
4069 >> drule_all TOPOLOGICAL_SORT'
4070 >> DISCH_THEN (Q.X_CHOOSE_THEN ‘g’ STRIP_ASSUME_TAC) (* this asserts ‘g’ *)
4071 >> Know ‘!i. i < N ==> g i < n /\ f (g i) <> {}’
4072 >- (rpt STRIP_TAC \\
4073     Q.PAT_X_ASSUM ‘filtered = IMAGE g (count N)’ MP_TAC \\
4074     rw [Once EXTENSION, Abbr ‘filtered’] >> METIS_TAC [])
4075 >> DISCH_TAC
4076 >> Know ‘!i j. i < N /\ j < N /\ i < j ==>
4077                interval_lowerbound (f (g i)) < interval_lowerbound (f (g j))’
4078 >- (rpt STRIP_TAC \\
4079     Q.PAT_X_ASSUM ‘!j k. _ ==> ~R (g k) (g j)’ (MP_TAC o (Q.SPECL [‘i’, ‘j’])) \\
4080     rw [Abbr ‘R’, GSYM real_lt])
4081 >> DISCH_TAC
4082 >> Know ‘!i j. i < N /\ j < N /\ i <> j ==> g i <> g j’
4083 >- (rpt STRIP_TAC \\
4084    ‘i < j \/ j < i’ by rw [] >| (* 2 subgoals *)
4085     [ (* goal 1 (of 2) *)
4086       Q.PAT_X_ASSUM ‘!i j. _ ==> interval_lowerbound (f (g i)) < interval_lowerbound (f (g j))’
4087         (MP_TAC o (Q.SPECL [‘i’, ‘j’])) >> rw [],
4088       (* goal 2 (of 2) *)
4089       Q.PAT_X_ASSUM ‘!i j. _ ==> interval_lowerbound (f (g i)) < interval_lowerbound (f (g j))’
4090         (MP_TAC o (Q.SPECL [‘j’, ‘i’])) >> rw [] ])
4091 >> DISCH_TAC
4092 (* eliminate ‘R’ *)
4093 >> Q.PAT_X_ASSUM ‘!j k. _ ==> ~R (g k) (g j)’ K_TAC (* superseded *)
4094 >> Q.PAT_X_ASSUM ‘transitive R’        K_TAC
4095 >> Q.PAT_X_ASSUM ‘antisymmetric R’     K_TAC
4096 >> Q.PAT_X_ASSUM ‘filtered HAS_SIZE N’ K_TAC
4097 >> Q.UNABBREV_TAC ‘R’
4098 (* define h = f o g *)
4099 >> Q.ABBREV_TAC ‘h = f o g’
4100 (* LHS rewriting *)
4101 >> Know ‘BIGUNION (IMAGE f (count n)) = BIGUNION (IMAGE h (count N))’
4102 >- (Q.PAT_X_ASSUM ‘filtered = IMAGE g (count N)’ MP_TAC \\
4103     rw [Abbr ‘filtered’, Once EXTENSION] \\
4104     rw [Once EXTENSION, IN_BIGUNION_IMAGE, Abbr ‘h’] \\
4105     EQ_TAC >> rpt STRIP_TAC >| (* 2 subgoals *)
4106     [ (* goal 1 (of 2) *)
4107       rename1 ‘i < n’ >> ‘f i <> {}’ by METIS_TAC [MEMBER_NOT_EMPTY] \\
4108      ‘?j. i = g j /\ j < N’ by METIS_TAC [] \\
4109       Q.EXISTS_TAC ‘j’ >> rw [],
4110       (* goal 2 (of 2) *)
4111       rename1 ‘i < N’ >> Q.EXISTS_TAC ‘g i’ >> rw [] ])
4112 >> DISCH_THEN (REV_FULL_SIMP_TAC std_ss o wrap)
4113 (* RHS rewriting *)
4114 >> Know ‘SIGMA (lambda0 o f) (count n) = SIGMA (lambda0 o f) filtered’
4115 >- (Q.ABBREV_TAC ‘empties = {i | i < n /\ f i = {}}’ \\
4116     Know ‘filtered = (count n) DIFF empties’
4117     >- (qunabbrevl_tac [‘empties’, ‘filtered’] \\
4118         rw [Once EXTENSION] >> METIS_TAC []) >> Rewr' \\
4119     irule EXTREAL_SUM_IMAGE_ZERO_DIFF \\
4120     rw [Abbr ‘empties’, o_DEF, lambda0_empty] \\
4121     DISJ1_TAC >> Q.X_GEN_TAC ‘i’ >> DISCH_TAC \\
4122    ‘?a1 b1. f i = right_open_interval a1 b1’
4123        by METIS_TAC [in_right_open_intervals] >> POP_ORW \\
4124     PROVE_TAC [lambda0_not_infty])
4125 >> Rewr'
4126 >> Q.PAT_X_ASSUM ‘filtered = IMAGE g (count N)’ (REWRITE_TAC o wrap)
4127 >> Know ‘SIGMA (lambda0 o f) (IMAGE g (count N)) =
4128          SIGMA ((lambda0 o f) o g) (count N)’
4129 >- (irule EXTREAL_SUM_IMAGE_IMAGE >> simp [o_DEF] \\
4130     reverse CONJ_TAC >- (rw [INJ_DEF] >> METIS_TAC []) \\
4131     DISJ1_TAC >> Q.X_GEN_TAC ‘i’ >> STRIP_TAC >> rename1 ‘i = g j’ \\
4132    ‘?a1 b1. f i = right_open_interval a1 b1’
4133        by METIS_TAC [in_right_open_intervals] >> POP_ORW \\
4134     PROVE_TAC [lambda0_not_infty])
4135 >> Rewr'
4136 >> simp [GSYM o_ASSOC]
4137 (* clean up *)
4138 >> ‘!i. i < N ==> h i IN subsets right_open_intervals’ by rw [Abbr ‘h’]
4139 >> ‘!i j. i < N /\ j < N /\ i <> j ==> DISJOINT (h i) (h j)’ by rw [Abbr ‘h’]
4140 >> ‘!i j. i < N /\ j < N /\ i < j ==>
4141           interval_lowerbound (h i) < interval_lowerbound (h j)’ by rw [Abbr ‘h’]
4142 >> ‘!i. i < N ==> h i <> {}’ by rw [Abbr ‘h’]
4143 >> Q.PAT_X_ASSUM ‘!i. _ ==> f i IN subsets right_open_intervals’ K_TAC
4144 >> Q.PAT_X_ASSUM ‘!i j. _ ==> DISJOINT (f i) (f j)’              K_TAC
4145 >> Q.PAT_X_ASSUM ‘!i j. _ ==> interval_lowerbound (f (g i)) < _’ K_TAC
4146 >> Q.PAT_X_ASSUM ‘!i. i < N ==> g i < n /\ f (g i) <> {}’        K_TAC
4147 >> Q.PAT_X_ASSUM ‘FINITE filtered’         K_TAC
4148 >> Q.PAT_X_ASSUM ‘filtered SUBSET count n’ K_TAC
4149 >> Q.PAT_X_ASSUM ‘0 < n’ K_TAC
4150 >> Q.PAT_X_ASSUM ‘N <= n’ K_TAC
4151 >> Q.PAT_X_ASSUM ‘!i j. i < N /\ j < N /\ i <> j ==> g i <> g j’ K_TAC
4152 >> Q.UNABBREV_TAC ‘filtered’
4153 (* now the goal and assumptions are only about ‘h’ and ‘N’ *)
4154 >> Suff `!i. i <= N ==>
4155              BIGUNION (IMAGE h (count i)) IN subsets right_open_intervals`
4156 >- (DISCH_TAC \\
4157     Suff `!m. m <= N ==>
4158               (lambda0 (BIGUNION (IMAGE h (count m))) =
4159                SIGMA (lambda0 o h) (count m))`
4160     >- (DISCH_THEN MATCH_MP_TAC >> rw [LESS_EQ_REFL]) \\
4161     Induct_on `m` (* final induction *)
4162     >- rw [COUNT_ZERO, IMAGE_EMPTY, BIGUNION_EMPTY, EXTREAL_SUM_IMAGE_EMPTY, lambda0_empty] \\
4163     DISCH_TAC \\
4164     SIMP_TAC std_ss [COUNT_SUC, IMAGE_INSERT, BIGUNION_INSERT] \\
4165     Know `lambda0 (h m UNION BIGUNION (IMAGE h (count m))) =
4166           lambda0 (h m) + lambda0 (BIGUNION (IMAGE h (count m)))`
4167     >- (MATCH_MP_TAC (REWRITE_RULE [measurable_sets_def, measure_def]
4168                                    (Q.ISPEC `lborel0` ADDITIVE)) \\
4169         rw [] >- (FIRST_X_ASSUM MATCH_MP_TAC >> rw []) \\
4170         REWRITE_TAC [GSYM BIGUNION_INSERT, GSYM IMAGE_INSERT, GSYM COUNT_SUC] \\
4171         FIRST_X_ASSUM MATCH_MP_TAC >> art []) >> Rewr' \\
4172     Q.PAT_X_ASSUM `m <= N ==> _` MP_TAC \\
4173    `m <= N` by RW_TAC arith_ss [] \\
4174     RW_TAC std_ss [] \\
4175     ONCE_REWRITE_TAC [EQ_SYM_EQ] \\
4176     Suff `SIGMA (lambda0 o h) (m INSERT count m) = (lambda0 o h) m +
4177           SIGMA (lambda0 o h) (count m DELETE m)`
4178     >- rw [o_DEF, COUNT_DELETE] \\
4179     irule EXTREAL_SUM_IMAGE_PROPERTY_NEG \\
4180     RW_TAC std_ss [GSYM COUNT_SUC, IN_COUNT, o_DEF, FINITE_COUNT] \\
4181     MATCH_MP_TAC pos_not_neginf \\
4182     fs [positive_def, measure_def, measurable_sets_def])
4183 (* h-property of upper- and lowerbounds *)
4184 >> Know `!i j. i < N /\ j < N /\ i <= j ==>
4185                interval_lowerbound (h i) <= interval_lowerbound (h j)`
4186 >- (rw [REAL_LE_LT] \\
4187    ‘j = i \/ i < j’ by rw [] >- rw [] >> DISJ1_TAC \\
4188     FIRST_X_ASSUM MATCH_MP_TAC >> art [])
4189 >> DISCH_TAC
4190 >> Know `!i j. i < N /\ j < N /\ i < j ==>
4191                interval_upperbound (h i) <= interval_lowerbound (h j)`
4192 >- (rpt STRIP_TAC \\
4193     SPOSE_NOT_THEN (ASSUME_TAC o (REWRITE_RULE [GSYM real_lt])) \\
4194    ‘interval_lowerbound (h i) < interval_lowerbound (h j)’ by PROVE_TAC [] \\
4195    `?a1 b1. a1 < b1 /\ (h i = right_open_interval a1 b1)`
4196         by METIS_TAC [in_right_open_intervals_nonempty] \\
4197    `?a2 b2. a2 < b2 /\ (h j = right_open_interval a2 b2)`
4198         by METIS_TAC [in_right_open_intervals_nonempty] \\
4199     FULL_SIMP_TAC std_ss [right_open_interval_upperbound,
4200                           right_open_interval_lowerbound] \\
4201    `i <> j` by RW_TAC arith_ss [] \\
4202     Know `DISJOINT (h i) (h j)` >- PROVE_TAC [] \\
4203     Q.PAT_X_ASSUM `h i = _` (PURE_ONCE_REWRITE_TAC o wrap) \\
4204     Q.PAT_X_ASSUM `h j = _` (PURE_ONCE_REWRITE_TAC o wrap) \\
4205     (* 2 possibile cases: [a1, [a2, b1) b2) or [a1, [a2, b2) b1),
4206        anyway we have `a2 IN [a1, b1)`. *)
4207     DISCH_THEN (ASSUME_TAC o (REWRITE_RULE [DISJOINT_ALT])) \\
4208     POP_ASSUM (MP_TAC o (Q.SPEC `a2`)) \\
4209     Know `a2 IN right_open_interval a1 b1`
4210     >- (rw [in_right_open_interval] >> rw [REAL_LT_IMP_LE]) \\
4211     Know `a2 IN right_open_interval a2 b2`
4212     >- (rw [in_right_open_interval]) \\
4213     RW_TAC bool_ss []) >> DISCH_TAC
4214 (* h-property of upperbounds *)
4215 >> Know `!i j. i < N /\ j < N /\ i < j ==>
4216                interval_upperbound (h i) <= interval_upperbound (h j)`
4217 >- (rpt STRIP_TAC \\
4218     MATCH_MP_TAC REAL_LE_TRANS \\
4219     Q.EXISTS_TAC `interval_lowerbound (h j)` >> rw [] \\
4220    `h j IN subsets right_open_intervals` by PROVE_TAC [] \\
4221     POP_ASSUM (STRIP_ASSUME_TAC o
4222                (REWRITE_RULE [in_right_open_intervals])) >> POP_ORW \\
4223     REWRITE_TAC [right_open_interval_two_bounds]) >> DISCH_TAC
4224 (* h-compactness: there's no gap between each h(i) *)
4225 >> Know `!i. SUC i < N ==>
4226             (interval_lowerbound (h (SUC i)) = interval_upperbound (h i))`
4227 >- (rpt STRIP_TAC >> `i < N` by RW_TAC arith_ss [] \\
4228     ONCE_REWRITE_TAC [EQ_SYM_EQ] \\
4229     Know `BIGUNION (IMAGE h (count N)) <> {} /\
4230           BIGUNION (IMAGE h (count N)) IN subsets right_open_intervals`
4231     >- (Q.UNABBREV_TAC `N` >> art [] \\
4232         RW_TAC std_ss [Once EXTENSION, IN_BIGUNION_IMAGE, IN_COUNT, NOT_IN_EMPTY] \\
4233        `h i <> {}` by METIS_TAC [] \\
4234         FULL_SIMP_TAC std_ss [GSYM MEMBER_NOT_EMPTY] \\
4235         qexistsl_tac [`x`, `i`] >> art []) \\
4236     REWRITE_TAC [in_right_open_intervals_nonempty] \\
4237     STRIP_TAC >> POP_ASSUM MP_TAC \\
4238     SIMP_TAC std_ss [GSPECIFICATION, right_open_interval, IN_BIGUNION_IMAGE,
4239                      IN_COUNT, Once EXTENSION] >> DISCH_TAC \\
4240  (* |- !x. (?x'. x' < N /\ x IN h x') <=> a <= x /\ x < b *)
4241     CCONTR_TAC \\ (* suppose there's a gap between h(i) and h(i+1) *)
4242    `i < SUC i` by RW_TAC arith_ss [] \\
4243     Q.PAT_X_ASSUM `!i j. _ ==> interval_upperbound (h i) <= interval_lowerbound (h j)`
4244       (MP_TAC o (Q.SPECL [`i`, `SUC i`])) >> rw [] \\
4245  (* now prove by contradiction *)
4246     CCONTR_TAC >> FULL_SIMP_TAC bool_ss [] \\
4247     Q.ABBREV_TAC `b1 = interval_upperbound (h i)` \\
4248     Q.ABBREV_TAC `a2 = interval_lowerbound (h (SUC i))` \\
4249    `b1 < a2` by METIS_TAC [REAL_LT_LE] \\ (* [a1, b1) < [a2, b2) *)
4250     Q.PAT_X_ASSUM `b1 <> a2` K_TAC \\
4251     Q.PAT_X_ASSUM `b1 <= a2` K_TAC \\
4252     qunabbrevl_tac [`b1`, `a2`] \\
4253     Know `h i <> {} /\ h i IN subsets right_open_intervals` >- PROVE_TAC [] \\
4254     DISCH_THEN (STRIP_ASSUME_TAC o
4255                 (REWRITE_RULE [in_right_open_intervals_nonempty])) \\
4256     Know `h (SUC i) <> {} /\
4257           h (SUC i) IN subsets right_open_intervals` >- PROVE_TAC [] \\
4258     DISCH_THEN (STRIP_ASSUME_TAC o
4259                 (REWRITE_RULE [in_right_open_intervals_nonempty])) \\
4260    `interval_upperbound (h i) = b'`
4261       by METIS_TAC [right_open_interval_upperbound] \\
4262    `interval_lowerbound (h (SUC i)) = a''`
4263       by METIS_TAC [right_open_interval_lowerbound] \\
4264     NTAC 2 (POP_ASSUM ((FULL_SIMP_TAC bool_ss) o wrap)) \\
4265     rename1 `h i       = right_open_interval a1 b1` \\
4266     rename1 `h (SUC i) = right_open_interval a2 b2` \\
4267     Know `a <= a1 /\ a1 < b`
4268     >- (`a1 IN right_open_interval a1 b1`
4269            by PROVE_TAC [right_open_interval_interior] \\
4270         PROVE_TAC []) >> STRIP_TAC \\
4271     Know `a <= a2 /\ a2 < b`
4272     >- (`a2 IN right_open_interval a2 b2`
4273            by PROVE_TAC [right_open_interval_interior] \\
4274         PROVE_TAC []) >> STRIP_TAC \\
4275  (* pick any point `z` in the "gap" *)
4276    `?z. b1 < z /\ z < a2` by PROVE_TAC [REAL_MEAN] \\
4277     Know `a <= z /\ z < b`
4278     >- (CONJ_TAC
4279         >- (MATCH_MP_TAC REAL_LT_IMP_LE \\
4280             MATCH_MP_TAC REAL_LT_TRANS >> Q.EXISTS_TAC `b1` >> art [] \\
4281             MATCH_MP_TAC REAL_LET_TRANS >> Q.EXISTS_TAC `a1` >> art []) \\
4282         MATCH_MP_TAC REAL_LT_TRANS \\
4283         Q.EXISTS_TAC `a2` >> art []) >> STRIP_TAC \\
4284    `?j. j < N /\ z IN h j` by METIS_TAC [] \\
4285  (* now we show `i < j < SUC i`, i.e. j doesn't exist at all *)
4286     Know `h j <> {} /\ h j IN subsets right_open_intervals` >- PROVE_TAC [] \\
4287     DISCH_THEN (STRIP_ASSUME_TAC o
4288                 (REWRITE_RULE [in_right_open_intervals_nonempty])) \\
4289     rename1 `h j = right_open_interval a3 b3` \\
4290     Know `z IN right_open_interval a3 b3` >- PROVE_TAC [] \\
4291     DISCH_THEN (STRIP_ASSUME_TAC o (REWRITE_RULE [in_right_open_interval])) \\
4292     Know `i < j`
4293     >- (SPOSE_NOT_THEN (ASSUME_TAC o (REWRITE_RULE [NOT_LESS])) \\
4294         Know `interval_upperbound (h j) <= interval_upperbound (h i)`
4295         >- (`(j = i) \/ j < i` by RW_TAC arith_ss []
4296             >- (POP_ORW >> REWRITE_TAC [REAL_LE_REFL]) \\
4297             FIRST_X_ASSUM MATCH_MP_TAC >> art []) \\
4298        `(interval_upperbound (h j) = b3) /\
4299         (interval_upperbound (h i) = b1)` by PROVE_TAC [right_open_interval_upperbound] \\
4300         NTAC 2 (POP_ASSUM (PURE_ONCE_REWRITE_TAC o wrap)) >> DISCH_TAC \\
4301        `z < b1` by PROVE_TAC [REAL_LTE_TRANS] \\
4302         METIS_TAC [REAL_LT_ANTISYM]) >> DISCH_TAC \\
4303     Know `j < SUC i`
4304     >- (SPOSE_NOT_THEN (ASSUME_TAC o (REWRITE_RULE [NOT_LESS])) \\
4305         Know `interval_lowerbound (h (SUC i)) <= interval_lowerbound (h j)`
4306         >- (FIRST_X_ASSUM MATCH_MP_TAC >> rw []) \\
4307        `(interval_lowerbound (h (SUC i)) = a2) /\
4308         (interval_lowerbound (h j) = a3)` by PROVE_TAC [right_open_interval_lowerbound] \\
4309         NTAC 2 (POP_ASSUM (PURE_ONCE_REWRITE_TAC o wrap)) >> DISCH_TAC \\
4310        `z < a3` by PROVE_TAC [REAL_LTE_TRANS] \\
4311         METIS_TAC [REAL_LTE_ANTISYM]) >> DISCH_TAC \\
4312    `SUC i <= j` by RW_TAC arith_ss [] \\
4313     METIS_TAC [LESS_EQ_ANTISYM]) >> DISCH_TAC
4314 (* final strike *)
4315 >> NTAC 3 (Q.PAT_X_ASSUM `!i j. i < N /\ j < N /\ _ ==> A <= B` K_TAC)
4316 >> rpt STRIP_TAC
4317 >> Cases_on `i`
4318 >- (rw [COUNT_ZERO, IMAGE_EMPTY, BIGUNION_EMPTY, EXTREAL_SUM_IMAGE_EMPTY] \\
4319     MATCH_MP_TAC SEMIRING_EMPTY >> art [])
4320 >> rename1 `SUC i <= N`
4321 >> Suff `!j. SUC j <= N ==>
4322              BIGUNION (IMAGE h (count (SUC j))) <> {} /\
4323             (BIGUNION (IMAGE h (count (SUC j))) =
4324              right_open_interval (interval_lowerbound (h 0))
4325                                 (interval_upperbound (h j)))`
4326 >- (DISCH_THEN (MP_TAC o (Q.SPEC `i`)) \\
4327     RW_TAC std_ss [right_open_interval_in_intervals])
4328 >> Induct_on `j`
4329 >- (DISCH_TAC \\
4330     SIMP_TAC std_ss [COUNT_SUC, COUNT_ZERO, IMAGE_INSERT, BIGUNION_INSERT,
4331                      IMAGE_EMPTY, BIGUNION_EMPTY, UNION_EMPTY] \\
4332     CONJ_TAC >- PROVE_TAC [] (* h 0 <> {} *) \\
4333     Know `h 0 <> {} /\ h 0 IN subsets right_open_intervals` >- PROVE_TAC [] \\
4334     DISCH_THEN (STRIP_ASSUME_TAC o
4335                 (REWRITE_RULE [in_right_open_intervals_nonempty])) \\
4336     POP_ORW \\
4337     METIS_TAC [right_open_interval_lowerbound, right_open_interval_upperbound])
4338 >> DISCH_TAC
4339 >> `SUC j < N /\ SUC j <= N` by RW_TAC arith_ss []
4340 >> Q.PAT_X_ASSUM `SUC j <= N ==> P` MP_TAC
4341 >> Q.UNABBREV_TAC `N` >> RW_TAC std_ss []
4342 >- (SIMP_TAC std_ss [Once COUNT_SUC, IMAGE_INSERT, BIGUNION_INSERT] \\
4343     ASM_SET_TAC [])
4344 >> SIMP_TAC std_ss [Once COUNT_SUC, IMAGE_INSERT, BIGUNION_INSERT, Once UNION_COMM]
4345 >> `interval_lowerbound (h 0) < interval_upperbound (h j)`
4346       by METIS_TAC [right_open_interval_empty]
4347 >> Know `h (SUC j) <> {} /\ h (SUC j) IN subsets right_open_intervals`
4348 >- PROVE_TAC []
4349 >> DISCH_THEN (STRIP_ASSUME_TAC o
4350                (REWRITE_RULE [in_right_open_intervals_nonempty])) >> art []
4351 >> `interval_upperbound (h j) = a`
4352       by METIS_TAC [right_open_interval_lowerbound]
4353 >> `interval_upperbound (right_open_interval a b) = b`
4354       by METIS_TAC [right_open_interval_upperbound]
4355 >> `interval_lowerbound (h (SUC j)) = interval_upperbound (h j)`
4356       by METIS_TAC []
4357 >> RW_TAC real_ss [right_open_interval, Once EXTENSION, IN_UNION, GSPECIFICATION]
4358 >> EQ_TAC >> rpt STRIP_TAC >> art [] (* 3 subgoals *)
4359 >| [ (* goal 1 (of 3) *)
4360      MATCH_MP_TAC REAL_LT_TRANS \\
4361      Q.EXISTS_TAC `interval_upperbound (h j)` >> art [],
4362      (* goal 2 (of 3) *)
4363      MATCH_MP_TAC REAL_LT_IMP_LE \\
4364      MATCH_MP_TAC REAL_LTE_TRANS \\
4365      Q.EXISTS_TAC `interval_upperbound (h j)` >> art [],
4366      (* goal 3 (of 3) *)
4367      REWRITE_TAC [REAL_LTE_TOTAL] ]
4368QED
4369
4370(* Proposition 6.3 [1, p.46], for constructing `lborel` by CARATHEODORY_SEMIRING *)
4371Theorem lborel0_premeasure :
4372    premeasure lborel0
4373Proof
4374    ASSUME_TAC lborel0_positive >> art [premeasure_def]
4375 >> RW_TAC std_ss [countably_additive_def, measurable_sets_def, measure_def,
4376                   IN_FUNSET, IN_UNIV]
4377 >> Know `!n. 0 <= (lambda0 o f) n`
4378 >- (RW_TAC std_ss [o_DEF] \\
4379     fs [positive_def, measure_def, measurable_sets_def]) >> DISCH_TAC
4380 >> Know `0 <= suminf (lambda0 o f)`
4381 >- (MATCH_MP_TAC ext_suminf_pos >> rw []) >> DISCH_TAC
4382 (* special case: finite non-empty sets *)
4383 >> ASSUME_TAC lborel0_finite_additive
4384 >> Q.ABBREV_TAC `P = \n. f n <> {}`
4385 >> Cases_on `?n. !i. n <= i ==> ~P i`
4386 >- (Q.UNABBREV_TAC `P` >> FULL_SIMP_TAC bool_ss [] \\
4387     Know `suminf (lambda0 o f) = SIGMA (lambda0 o f) (count n)`
4388     >- (MATCH_MP_TAC ext_suminf_sum >> RW_TAC std_ss [] \\
4389         fs [positive_def, measure_def, measurable_sets_def]) >> Rewr' \\
4390     Know `BIGUNION (IMAGE f UNIV) = BIGUNION (IMAGE f (count n))`
4391     >- (RW_TAC std_ss [Once EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, IN_COUNT] \\
4392         EQ_TAC >> rpt STRIP_TAC >> rename1 `x IN f i` >| (* 2 subgoals *)
4393         [ (* goal 1 (of 2) *)
4394           Q.EXISTS_TAC `i` >> art [] \\
4395           SPOSE_NOT_THEN (ASSUME_TAC o (REWRITE_RULE [NOT_LESS])) \\
4396           METIS_TAC [MEMBER_NOT_EMPTY],
4397           (* goal 2 (of 2) *)
4398           Q.EXISTS_TAC `i` >> art [] ]) \\
4399     DISCH_THEN ((FULL_SIMP_TAC bool_ss) o wrap) \\
4400     MATCH_MP_TAC EQ_SYM \\
4401     MATCH_MP_TAC (REWRITE_RULE [measure_def, measurable_sets_def]
4402                                (Q.ISPEC `lborel0` FINITE_ADDITIVE)) \\
4403     RW_TAC std_ss [])
4404 (* `lborel1` construction *)
4405 >> Know `?lborel1. ((m_space lborel1, measurable_sets lborel1) =
4406                     smallest_ring (space right_open_intervals)
4407                                   (subsets right_open_intervals)) /\
4408                    (!s. s IN subsets right_open_intervals ==>
4409                        (measure lborel1 s = lambda0 s)) /\
4410                    positive lborel1 /\ additive lborel1`
4411 >- (MP_TAC (Q.ISPEC `lborel0` SEMIRING_FINITE_ADDITIVE_EXTENSION) \\
4412     MP_TAC right_open_intervals_semiring \\
4413     MP_TAC lborel0_positive \\
4414     MP_TAC lborel0_finite_additive \\
4415     RW_TAC std_ss [m_space_def, measurable_sets_def, measure_def, SPACE])
4416 >> STRIP_TAC (* now we have `lborel1` in assumptions *)
4417 >> `ring (m_space lborel1,measurable_sets lborel1)`
4418       by METIS_TAC [SMALLEST_RING, right_open_intervals_semiring, semiring_def]
4419 >> `m_space lborel1 = univ(:real)`
4420       by METIS_TAC [SPACE, SPACE_SMALLEST_RING, right_open_intervals,
4421                     space_def, subsets_def]
4422 >> Know `subsets right_open_intervals SUBSET (measurable_sets lborel1)`
4423 >- (ASSUME_TAC
4424      (Q.ISPECL [`space right_open_intervals`,
4425                 `subsets right_open_intervals`] SMALLEST_RING_SUBSET_SUBSETS) \\
4426     Suff `measurable_sets lborel1 =
4427           subsets (smallest_ring (space right_open_intervals)
4428                                  (subsets right_open_intervals))` >- rw [] \\
4429     METIS_TAC [SPACE, space_def, subsets_def]) >> DISCH_TAC
4430 >> `finite_additive lborel1 /\ increasing lborel1 /\
4431     subadditive lborel1 /\ finite_subadditive lborel1`
4432       by METIS_TAC [RING_ADDITIVE_EVERYTHING]
4433 >> Q.ABBREV_TAC `lambda1 = measure lborel1`
4434 >> reverse (rw [GSYM le_antisym])
4435 (* easy part: suminf (lambda0 o f) <= lambda0 (BIGUNION (IMAGE f univ(:num))) *)
4436 >- (rw [ext_suminf_def, sup_le', GSPECIFICATION] \\
4437    `lambda0 (BIGUNION (IMAGE f univ(:num))) =
4438     lambda1 (BIGUNION (IMAGE f univ(:num)))` by PROVE_TAC [] >> POP_ORW \\
4439     Know `SIGMA (lambda0 o f) (count n) = SIGMA (lambda1 o f) (count n)`
4440     >- (MATCH_MP_TAC EQ_SYM >> irule EXTREAL_SUM_IMAGE_EQ \\
4441         STRONG_CONJ_TAC
4442         >- rw [FINITE_COUNT, IN_COUNT, o_DEF] \\
4443         rw [] >> DISJ1_TAC >> GEN_TAC >> DISCH_TAC \\
4444         MATCH_MP_TAC pos_not_neginf \\
4445         fs [positive_def, measure_def, subsets_def]) >> Rewr' \\
4446     Know `BIGUNION (IMAGE f (count n)) IN measurable_sets lborel1`
4447     >- (MATCH_MP_TAC (REWRITE_RULE [subsets_def]
4448                        (Q.ISPEC `(m_space lborel1, measurable_sets lborel1)`
4449                                 RING_FINITE_UNION_ALT)) >> rw [] \\
4450         fs [SUBSET_DEF]) >> DISCH_TAC \\
4451     Know `SIGMA (lambda1 o f) (count n) = lambda1 (BIGUNION (IMAGE f (count n)))`
4452     >- (Q.UNABBREV_TAC `lambda1` \\
4453         MATCH_MP_TAC (Q.SPEC `lborel`
4454                        (INST_TYPE [alpha |-> ``:real``] FINITE_ADDITIVE)) \\
4455         rw [] >> fs [SUBSET_DEF]) >> Rewr' \\
4456     Q.UNABBREV_TAC `lambda1` \\
4457     MATCH_MP_TAC (REWRITE_RULE [subsets_def]
4458                    (Q.SPEC `lborel1`
4459                      (INST_TYPE [alpha |-> ``:real``] INCREASING))) \\
4460     rw [] >- SET_TAC [] \\
4461     fs [SUBSET_DEF])
4462 (* N is an infinite subset of UNIV, but it doesn't hold all non-empty sets *)
4463 >> `?N. INFINITE N /\ !n. n IN N ==> P n` by METIS_TAC [infinitely_often_lemma]
4464 >> Know `INFINITE P`
4465 >- (`N SUBSET P` by METIS_TAC [IN_APP, SUBSET_DEF] \\
4466     METIS_TAC [INFINITE_SUBSET]) >> DISCH_TAC
4467 (* N is useless from now on *)
4468 >> Q.PAT_X_ASSUM `INFINITE N`               K_TAC
4469 >> Q.PAT_X_ASSUM `!n. n IN N ==> P n`       K_TAC
4470 >> Q.PAT_X_ASSUM `~?n. !i. n <= i ==> ~P i` K_TAC
4471 >> Know `!n. n IN P <=> f n <> {}`
4472 >- (GEN_TAC >> Q.UNABBREV_TAC `P` >> EQ_TAC >> RW_TAC std_ss [IN_APP])
4473 >> DISCH_TAC
4474 >> Know `BIGUNION (IMAGE f UNIV) = BIGUNION (IMAGE f P)`
4475 >- (SIMP_TAC bool_ss [Once EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV] \\
4476     GEN_TAC >> EQ_TAC >> rpt STRIP_TAC >> rename1 `x IN f i` >| (* 2 subgoals *)
4477     [ (* goal 1 (of 2) *)
4478       Q.EXISTS_TAC `i` >> art [GSYM MEMBER_NOT_EMPTY] \\
4479       Q.EXISTS_TAC `x` >> art [],
4480       (* goal 2 (of 2) *)
4481       Q.EXISTS_TAC `i` >> art [] ])
4482 >> DISCH_THEN ((FULL_SIMP_TAC bool_ss) o wrap)
4483 (* use P instead of univ(:num) *)
4484 >> `countable P` by PROVE_TAC [COUNTABLE_NUM]
4485 >> POP_ASSUM (STRIP_ASSUME_TAC o
4486               (REWRITE_RULE [COUNTABLE_ALT_BIJ, GSYM ENUMERATE]))
4487 (* rewrite LHS, g is the BIJ enumeration of P *)
4488 >> rename1 `BIJ g univ(:num) P`
4489 >> Know `BIGUNION (IMAGE f P) = BIGUNION (IMAGE (f o g) UNIV)`
4490 >- (SIMP_TAC bool_ss [Once EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV, o_DEF] \\
4491     GEN_TAC >> EQ_TAC >> rpt STRIP_TAC >| (* 2 subgoals *)
4492     [ (* goal 1 (of 2) *)
4493       rename1 `x IN f i` >> FULL_SIMP_TAC bool_ss [BIJ_DEF, SURJ_DEF, IN_UNIV] \\
4494      `?y. g y = i` by PROVE_TAC [] >> Q.EXISTS_TAC `y` >> art [],
4495       (* goal 2 (of 2) *)
4496       rename1 `x IN f (g i)` >> Q.PAT_X_ASSUM `!n. n IN P <=> f n <> {}` K_TAC \\
4497       Q.EXISTS_TAC `g i` >> art [] \\
4498       fs [BIJ_DEF, INJ_DEF, IN_UNIV] ])
4499 >> DISCH_THEN ((FULL_SIMP_TAC bool_ss) o wrap)
4500 >> Q.ABBREV_TAC `h = f o g`
4501 >> Know `!n. h n <> {}`
4502 >- (Q.UNABBREV_TAC `h` >> GEN_TAC >> SIMP_TAC bool_ss [o_DEF] \\
4503     Q.PAT_X_ASSUM `!n. n IN P <=> f n <> {}` (ONCE_REWRITE_TAC o wrap o GSYM) \\
4504     fs [BIJ_DEF, INJ_DEF, IN_UNIV]) >> DISCH_TAC
4505 (* h-properties in place of f-properties *)
4506 >> Know `!n. h n IN subsets right_open_intervals`
4507 >- (Q.UNABBREV_TAC `h` >> RW_TAC std_ss [o_DEF]) >> DISCH_TAC
4508 >> Know `!i j. i <> j ==> DISJOINT (h i) (h j)`
4509 >- (Q.UNABBREV_TAC `h` >> RW_TAC std_ss [o_DEF] \\
4510     FIRST_X_ASSUM MATCH_MP_TAC \\
4511     CCONTR_TAC >> fs [BIJ_ALT, IN_FUNSET, IN_UNIV] \\
4512     METIS_TAC [EXISTS_UNIQUE_THM]) >> DISCH_TAC
4513 >> Know `!n. 0 <= (lambda0 o h) n`
4514 >- (Q.UNABBREV_TAC `h` >> GEN_TAC >> fs [o_DEF]) >> DISCH_TAC
4515 (* rewrite RHS, using `h` in place of `f` *)
4516 >> Know `suminf (lambda0 o f) = suminf (lambda0 o h)`
4517 >- (Q.UNABBREV_TAC `h` >> ASM_SIMP_TAC std_ss [ext_suminf_def] \\
4518     FULL_SIMP_TAC pure_ss [o_ASSOC] \\
4519     Q.ABBREV_TAC `l = lambda0 o f` \\
4520     Know `!n. SIGMA (l o g) (count n) = SIGMA l (IMAGE g (count n))`
4521     >- (GEN_TAC >> MATCH_MP_TAC EQ_SYM \\
4522         irule EXTREAL_SUM_IMAGE_IMAGE >> art [FINITE_COUNT] \\
4523         CONJ_TAC >- (DISJ1_TAC >> RW_TAC std_ss [IN_IMAGE, IN_COUNT] \\
4524                      MATCH_MP_TAC pos_not_neginf >> fs [o_DEF]) \\
4525         MATCH_MP_TAC INJ_IMAGE \\
4526         Q.EXISTS_TAC `P` >> fs [BIJ_DEF, INJ_DEF]) >> Rewr' \\
4527     RW_TAC std_ss [GSYM le_antisym, Once CONJ_SYM] >| (* 2 subgoals *)
4528     [ (* goal 1 (of 2): easy *)
4529       RW_TAC std_ss [sup_le', IN_IMAGE, IN_UNIV] \\
4530       RW_TAC std_ss [le_sup', IN_IMAGE, IN_UNIV] \\
4531       (* SIGMA l (IMAGE g (count n)) <= y,
4532          |- !z. (?n. z = SIGMA l (count n)) ==> z <= y
4533
4534          The goal is to find an `m` such that
4535
4536            (IMAGE g (count n)) SUBSET (count m) *)
4537       MATCH_MP_TAC le_trans \\
4538       Q.ABBREV_TAC `m = SUC (MAX_SET (IMAGE g (count n)))` \\
4539       Q.EXISTS_TAC `SIGMA l (count m)` \\
4540       reverse CONJ_TAC >- (FIRST_X_ASSUM MATCH_MP_TAC \\
4541                            Q.EXISTS_TAC `m` >> art []) \\
4542       Q.UNABBREV_TAC `m` \\
4543       MATCH_MP_TAC EXTREAL_SUM_IMAGE_MONO_SET \\
4544       ASM_SIMP_TAC std_ss [IMAGE_FINITE, FINITE_COUNT] \\
4545       RW_TAC std_ss [SUBSET_DEF, IN_IMAGE, IN_COUNT] \\
4546       rename1 `i < n` \\
4547       Suff `g i <= MAX_SET (IMAGE g (count n))` >- RW_TAC arith_ss [] \\
4548       irule in_max_set \\ (* in pred_setTheory, contributed by CakeML *)
4549       RW_TAC std_ss [IMAGE_FINITE, FINITE_COUNT, IN_IMAGE, IN_COUNT] \\
4550       Q.EXISTS_TAC `i` >> art [],
4551       (* goal 2 (of 2): hard *)
4552       RW_TAC std_ss [sup_le', IN_IMAGE, IN_UNIV] \\
4553       RW_TAC std_ss [le_sup', IN_IMAGE, IN_UNIV] \\
4554       (* SIGMA l (count n) <= y
4555          |- !z. (?n. z = SIGMA l (IMAGE g (count n))) ==> z <= y
4556
4557          The goal is to find an `m` such that
4558
4559            (count n INTER P) SUBSET (IMAGE g (count m)) *)
4560       MATCH_MP_TAC le_trans \\
4561       IMP_RES_TAC BIJ_INV >> fs [IN_UNIV, o_DEF] \\
4562       Q.ABBREV_TAC `m = SUC (MAX_SET (IMAGE g' (count n INTER P)))` \\
4563       Q.EXISTS_TAC `SIGMA l (IMAGE g (count m))` \\
4564       reverse CONJ_TAC >- (FIRST_X_ASSUM MATCH_MP_TAC \\
4565                            Q.EXISTS_TAC `m` >> art []) \\
4566       Q.UNABBREV_TAC `m` \\
4567       Know `SIGMA l (count n) = SIGMA l (count n INTER P)`
4568       >- (MATCH_MP_TAC EQ_SYM >> irule EXTREAL_SUM_IMAGE_INTER_ELIM \\
4569           REWRITE_TAC [FINITE_COUNT] \\
4570           CONJ_TAC >- (Q.UNABBREV_TAC `l` >> BETA_TAC >> rpt STRIP_TAC \\
4571                       `f x = {}` by PROVE_TAC [] >> POP_ORW \\
4572                        fs [positive_def, measure_def, measurable_sets_def]) \\
4573           DISJ1_TAC >> NTAC 2 STRIP_TAC \\
4574           MATCH_MP_TAC pos_not_neginf >> art []) >> Rewr' \\
4575       MATCH_MP_TAC EXTREAL_SUM_IMAGE_MONO_SET \\
4576       ASM_SIMP_TAC std_ss [IMAGE_FINITE, FINITE_COUNT] \\
4577       CONJ_TAC >- (MATCH_MP_TAC SUBSET_FINITE_I \\
4578                    Q.EXISTS_TAC `count n` >> rw [FINITE_COUNT, INTER_SUBSET]) \\
4579       SIMP_TAC bool_ss [SUBSET_DEF, IN_IMAGE, IN_COUNT, IN_INTER] \\
4580       Q.X_GEN_TAC `i` >> STRIP_TAC \\
4581       Q.EXISTS_TAC `g' i` >> ASM_SIMP_TAC bool_ss [] \\
4582       Suff `g' i <= MAX_SET (IMAGE g' (count n INTER P))` >- RW_TAC arith_ss [] \\
4583       irule in_max_set \\
4584       CONJ_TAC >- (MATCH_MP_TAC IMAGE_FINITE \\
4585                    MATCH_MP_TAC SUBSET_FINITE_I \\
4586                    Q.EXISTS_TAC `count n` >> rw [FINITE_COUNT, INTER_SUBSET]) \\
4587       SIMP_TAC std_ss [IN_IMAGE, IN_COUNT, IN_INTER] \\
4588       Q.EXISTS_TAC `i` >> art [] ]) >> Rewr'
4589 (* cleanup all f-properties *)
4590 >> Q.PAT_X_ASSUM `!x. f x IN subsets right_open_intervals` K_TAC
4591 >> Q.PAT_X_ASSUM `!n. 0 <= (lambda0 o f) n`                K_TAC
4592 >> Q.PAT_X_ASSUM `0 <= suminf (lambda0 o f)`               K_TAC
4593 >> Q.PAT_X_ASSUM `!i j. i <> j ==> DISJOINT (f i) (f j)`   K_TAC
4594 (* hard part: lambda0 (BIGUNION (IMAGE h univ(:num))) <= suminf (lambda0 o h) *)
4595 >> `0 <= suminf (lambda0 o h)` by PROVE_TAC [ext_suminf_pos]
4596 >> Know `BIGUNION (IMAGE h UNIV) <> {}`
4597 >- (RW_TAC std_ss [Once EXTENSION, NOT_IN_EMPTY, IN_BIGUNION_IMAGE, IN_UNIV] \\
4598    `h 0 <> {}` by PROVE_TAC [] >> fs [GSYM MEMBER_NOT_EMPTY] \\
4599     qexistsl_tac [`x`, `0`] >> art []) >> DISCH_TAC
4600 >> Know `?a b. BIGUNION (IMAGE h UNIV) = right_open_interval a b`
4601 >- (Q.PAT_X_ASSUM `BIGUNION (IMAGE h UNIV) IN subsets right_open_intervals`
4602       (MP_TAC o
4603        (REWRITE_RULE [right_open_intervals, right_open_interval, subsets_def])) \\
4604     RW_TAC set_ss [right_open_interval]) >> STRIP_TAC
4605 >> `a < b` by PROVE_TAC [right_open_interval_empty]
4606 (* stage work *)
4607 >> MATCH_MP_TAC le_epsilon >> rpt STRIP_TAC
4608 >> reverse (Cases_on `e < Normal (b - a)`)
4609 >- (POP_ASSUM (ASSUME_TAC o (REWRITE_RULE [extreal_lt_def])) \\
4610     IMP_RES_TAC REAL_LT_IMP_LE >> rw [lambda0_def] \\
4611     MATCH_MP_TAC le_trans >> Q.EXISTS_TAC `e` >> rw [] \\
4612     MATCH_MP_TAC le_addl_imp >> art [])
4613 >> Know `e <> NegInf`
4614 >- (MATCH_MP_TAC pos_not_neginf \\
4615     MATCH_MP_TAC lt_imp_le >> art []) >> DISCH_TAC
4616 >> Know `lambda0 (BIGUNION (IMAGE h UNIV)) <= suminf (lambda0 o h) + e <=>
4617          lambda0 (BIGUNION (IMAGE h UNIV)) - e <= suminf (lambda0 o h)`
4618 >- (MATCH_MP_TAC EQ_SYM \\
4619     MATCH_MP_TAC sub_le_eq >> art []) >> Rewr'
4620 >> `?d. e = Normal d` by METIS_TAC [extreal_cases]
4621 >> `0 < d` by METIS_TAC [extreal_lt_eq, extreal_of_num_def]
4622 >> Q.PAT_X_ASSUM `0 < e`            K_TAC
4623 >> Q.PAT_X_ASSUM `INFINITE P`       K_TAC
4624 >> Q.PAT_X_ASSUM `!n. n IN P <=> _` K_TAC
4625 >> Q.PAT_X_ASSUM `BIJ g UNIV P`     K_TAC
4626 >> Q.UNABBREV_TAC `P` (* last appearence of P *)
4627 (* (A n) and (B n) are lower- and upperbounds of each non-empty (h n) *)
4628 >> Know `?A B. !n. h n = right_open_interval (A n) (B n)`
4629 >- (Q.PAT_X_ASSUM `!x. h x IN subsets right_open_intervals`
4630       (MP_TAC o (REWRITE_RULE [right_open_intervals, right_open_interval, subsets_def])) \\
4631     RW_TAC set_ss [right_open_interval, SKOLEM_THM]) >> STRIP_TAC
4632 >> `!n. A n < B n` by METIS_TAC [right_open_interval_empty]
4633 >> Know `!i j. i <> j ==> B i <> B j`
4634 >- (rpt STRIP_TAC >> `A i < B i /\ A j < B j` by PROVE_TAC [] \\
4635    `(A i = A j) \/ A i < A j \/ A j < A i` by PROVE_TAC [REAL_LT_TOTAL] >|
4636     [ (* goal 1 (of 3) *)
4637      `h i = h j` by PROVE_TAC [] >> METIS_TAC [DISJOINT_EMPTY_REFL],
4638       (* goal 2 (of 3): [A i, [A j, B i/j)) *)
4639      `DISJOINT (h i) (h j)` by PROVE_TAC [] \\
4640       METIS_TAC [real_lte, right_open_interval_DISJOINT_imp],
4641       (* goal 3 (of 3): [A j, [A i, B i/j)) *)
4642      `DISJOINT (h i) (h j)` by PROVE_TAC [] \\
4643       METIS_TAC [real_lte, right_open_interval_DISJOINT_imp] ]) >> DISCH_TAC
4644 (* "open" (J) and "half open" (H) intervals of the same bounds *)
4645 >> Q.ABBREV_TAC `r = d / 2`
4646 >> Know `0 < r`
4647 >- (Q.UNABBREV_TAC `r` >> MATCH_MP_TAC REAL_LT_DIV \\
4648     RW_TAC real_ss [] (* 0 < 2 *)) >> DISCH_TAC
4649 >> Q.ABBREV_TAC `J = \n.      OPEN_interval (A n - r * (1 / 2) pow (n + 1),  B n)`
4650 >> Q.ABBREV_TAC `H = \n. right_open_interval (A n - r * (1 / 2) pow (n + 1)) (B n)`
4651 >> Know `!n. A n - r * (1 / 2) pow (n + 1) < B n`
4652 >- (GEN_TAC >> MATCH_MP_TAC REAL_LT_TRANS >> Q.EXISTS_TAC `A n` \\
4653     ASM_REWRITE_TAC [REAL_LT_SUB_RADD, REAL_LT_ADDR] \\
4654     REWRITE_TAC [Once ADD_COMM, GSYM SUC_ONE_ADD] \\
4655     METIS_TAC [REAL_HALF_BETWEEN, POW_POS_LT, REAL_LT_MUL]) >> DISCH_TAC
4656 >> Know `!n. J n SUBSET H n`
4657 >- (GEN_TAC >> qunabbrevl_tac [`J`, `H`] >> BETA_TAC \\
4658     RW_TAC std_ss [SUBSET_DEF, IN_INTERVAL, in_right_open_interval] \\
4659     MATCH_MP_TAC REAL_LT_IMP_LE >> art []) >> DISCH_TAC
4660 >> Know `!n. J n <> {}`
4661 >- (GEN_TAC >> Q.UNABBREV_TAC `J` \\
4662     BETA_TAC >> art [INTERVAL_NE_EMPTY]) >> DISCH_TAC
4663 >> Know `!n. H n <> {}`
4664 >- (GEN_TAC >> Q.UNABBREV_TAC `H` \\
4665     BETA_TAC >> art [right_open_interval_empty]) >> DISCH_TAC
4666 >> Know `!m n. m <> n ==> J m <> J n`
4667 >- (Q.UNABBREV_TAC `J` >> BETA_TAC >> rpt STRIP_TAC \\
4668     METIS_TAC [EQ_INTERVAL]) >> DISCH_TAC
4669 >> Know `!m n. m <> n ==> H m <> H n`
4670 >- (Q.UNABBREV_TAC `H` >> BETA_TAC >> rpt STRIP_TAC \\
4671     METIS_TAC [right_open_interval_11]) >> DISCH_TAC
4672 (* applying Heine-Borel theorem *)
4673 >> Know `compact (interval [a, b - r])`
4674 >- (MATCH_MP_TAC BOUNDED_CLOSED_IMP_COMPACT \\
4675     REWRITE_TAC [BOUNDED_INTERVAL, CLOSED_INTERVAL])
4676 >> DISCH_THEN (ASSUME_TAC o (MATCH_MP COMPACT_IMP_HEINE_BOREL))
4677 >> POP_ASSUM (ASSUME_TAC o (Q.SPEC `IMAGE J univ(:num)`))
4678 >> Know `!t. t IN (IMAGE J univ(:num)) ==> open t`
4679 >- (RW_TAC std_ss [IN_IMAGE, IN_UNIV] \\
4680     Q.UNABBREV_TAC `J` >> SIMP_TAC std_ss [OPEN_INTERVAL]) >> DISCH_TAC
4681 >> Know `BIGUNION (IMAGE h UNIV) SUBSET BIGUNION (IMAGE J UNIV)`
4682 >- (RW_TAC std_ss [SUBSET_DEF, IN_BIGUNION_IMAGE, IN_UNIV,
4683                    in_right_open_interval] \\
4684     rename1 `A i <= x` >> Q.EXISTS_TAC `i` \\
4685     Q.UNABBREV_TAC `J` >> RW_TAC std_ss [OPEN_interval, GSPECIFICATION] \\
4686     MATCH_MP_TAC REAL_LTE_TRANS \\
4687     Q.EXISTS_TAC `A i` >> art [] \\
4688     REWRITE_TAC [Once ADD_COMM, GSYM SUC_ONE_ADD] \\
4689     REWRITE_TAC [REAL_LT_SUB_RADD, REAL_LT_ADDR] \\
4690     METIS_TAC [REAL_HALF_BETWEEN, POW_POS_LT, REAL_LT_MUL]) >> DISCH_TAC
4691 (* all "open" intervals J cover the compact interval [a, b - r] *)
4692 >> Know `(CLOSED_interval [a, b - r]) SUBSET (BIGUNION (IMAGE J univ(:num)))`
4693 >- (MATCH_MP_TAC SUBSET_TRANS \\
4694     Q.EXISTS_TAC `BIGUNION (IMAGE h UNIV)` >> art [] \\
4695     RW_TAC list_ss [CLOSED_interval, right_open_interval, SUBSET_DEF, GSPECIFICATION] \\
4696     MATCH_MP_TAC REAL_LET_TRANS \\
4697     Q.EXISTS_TAC `b - r` >> art [REAL_LT_SUB_RADD, REAL_LT_ADDR]) >> DISCH_TAC
4698 (* there exists a finite cover c from J (by Heine-Borel theorem) *)
4699 >> `?c. c SUBSET (IMAGE J univ(:num)) /\ FINITE c /\
4700         CLOSED_interval [a,b - r] SUBSET (BIGUNION c)` by PROVE_TAC []
4701 >> Q.PAT_X_ASSUM `X ==> ?f'. f' SUBSET (IMAGE J UNIV) /\ Y` K_TAC
4702 >> Know `BIJ J univ(:num) (IMAGE J univ(:num))`
4703 >- (RW_TAC std_ss [BIJ_ALT, IN_FUNSET, IN_UNIV, IN_IMAGE, EXISTS_UNIQUE_THM]
4704     >- (Q.EXISTS_TAC `x` >> art []) \\
4705     METIS_TAC [])
4706 >> DISCH_THEN (STRIP_ASSUME_TAC o
4707                (SIMP_RULE std_ss [IN_UNIV, IN_IMAGE]) o (MATCH_MP BIJ_INV))
4708 >> rename1 `!x. J' (J x) = x`
4709 >> Know `?cover. FINITE cover /\ (c = IMAGE J cover)`
4710 >- (Q.EXISTS_TAC `IMAGE J' c` \\
4711     CONJ_TAC >- METIS_TAC [IMAGE_FINITE] \\
4712     REWRITE_TAC [IMAGE_IMAGE] \\
4713     RW_TAC std_ss [Once EXTENSION, IN_IMAGE] \\
4714     EQ_TAC >> rpt STRIP_TAC >| (* 2 subgoals *)
4715     [ (* goal 1 (of 2) *)
4716       Q.EXISTS_TAC `x` >> art [] \\
4717       MATCH_MP_TAC EQ_SYM >> FIRST_X_ASSUM MATCH_MP_TAC \\
4718       fs [SUBSET_DEF, IN_IMAGE, IN_UNIV],
4719       (* goal 2 (of 2) *)
4720       Suff `J (J' x') = x'` >- PROVE_TAC [] \\
4721       FIRST_X_ASSUM MATCH_MP_TAC \\
4722       fs [SUBSET_DEF, IN_IMAGE, IN_UNIV] ]) >> STRIP_TAC
4723 >> POP_ASSUM ((REV_FULL_SIMP_TAC bool_ss) o wrap)
4724 >> Q.PAT_X_ASSUM `FINITE (IMAGE J cover)` K_TAC
4725 (* `N` is the minimal index such that `cover SUBSET (count N)` *)
4726 >> Q.ABBREV_TAC `N = SUC (MAX_SET cover)`
4727 >> Know `cover SUBSET (count N)` (* for IMAGE_SUBSET *)
4728 >- (Q.UNABBREV_TAC `N` \\
4729     RW_TAC std_ss [SUBSET_DEF, IN_COUNT] \\
4730     Suff `x <= MAX_SET cover` >- RW_TAC arith_ss [] \\
4731     irule in_max_set >> art []) >> DISCH_TAC
4732 (* RHS: from `suminf lambda0 o h` to `SIGMA (lambda0 o h) (count N)` *)
4733 >> ASM_SIMP_TAC bool_ss [ext_suminf_def, le_sup', IN_IMAGE, IN_UNIV, IN_COUNT]
4734 >> rpt STRIP_TAC
4735 >> MATCH_MP_TAC le_trans
4736 >> Q.EXISTS_TAC `SIGMA (lambda0 o h) (count N)`
4737 >> reverse CONJ_TAC
4738 >- (POP_ASSUM MATCH_MP_TAC >> Q.EXISTS_TAC `N` >> art [])
4739  (* now there's no infinity anywhere *)
4740 >> ASSUME_TAC lborel0_additive
4741 >> Know `lambda0 (right_open_interval a       b) =
4742          lambda0 (right_open_interval a (b - r)) +
4743          lambda0 (right_open_interval (b - r) b)`
4744 >- (MATCH_MP_TAC (REWRITE_RULE [measure_def, measurable_sets_def]
4745                                (Q.ISPEC `lborel0` ADDITIVE)) \\
4746     ASM_SIMP_TAC bool_ss [right_open_interval_in_intervals] \\
4747     Know `a < b - r /\ b - r < b`
4748     >- (ASM_REWRITE_TAC [REAL_LT_SUB_RADD, REAL_LT_ADDR] \\
4749        `a < b - r <=> r < b - a` by REAL_ARITH_TAC >> POP_ORW \\
4750         MATCH_MP_TAC REAL_LET_TRANS >> Q.EXISTS_TAC `d` \\
4751         reverse CONJ_TAC >- fs [extreal_lt_eq] \\
4752         Q.UNABBREV_TAC `r` \\
4753         MATCH_MP_TAC REAL_LE_LDIV >> RW_TAC real_ss [] \\
4754         MATCH_MP_TAC (SIMP_RULE real_ss []
4755                                 (Q.SPECL [`d`, `d`, `1`, `2`] REAL_LE_MUL2)) \\
4756         MATCH_MP_TAC REAL_LT_IMP_LE >> art []) >> STRIP_TAC \\
4757     CONJ_TAC >- (METIS_TAC [right_open_interval_DISJOINT,
4758                             REAL_LE_REFL, REAL_LT_IMP_LE]) \\
4759     RW_TAC std_ss [Once EXTENSION, IN_UNION, in_right_open_interval] \\
4760     EQ_TAC >> STRIP_TAC >> fs [REAL_LTE_TOTAL] >| (* 2 subgoals *)
4761     [ (* goal 1 (of 2) *)
4762       MATCH_MP_TAC REAL_LT_TRANS >> Q.EXISTS_TAC `b - r` >> art [],
4763       (* goal 2 (of 2) *)
4764       MATCH_MP_TAC REAL_LE_TRANS >> Q.EXISTS_TAC `b - r` >> art [] \\
4765       MATCH_MP_TAC REAL_LT_IMP_LE >> art [] ]) >> Rewr'
4766 >> Know `lambda0 (right_open_interval (b - r) b) = Normal r`
4767 >- (Know `Normal r = Normal (b - (b - r))`
4768     >- (REWRITE_TAC [extreal_11] >> REAL_ARITH_TAC) >> Rewr' \\
4769     MATCH_MP_TAC lambda0_def \\
4770     REWRITE_TAC [REAL_LE_SUB_RADD, REAL_LE_ADDR] \\
4771     MATCH_MP_TAC REAL_LT_IMP_LE >> art []) >> Rewr'
4772 >> Know `right_open_interval a (b - r) SUBSET (BIGUNION (IMAGE H (count N)))`
4773 >- ((* step 1 (of 4) *)
4774     MATCH_MP_TAC SUBSET_TRANS \\
4775     Q.EXISTS_TAC `interval [a,b - r]` \\
4776     CONJ_TAC (* [a,b - r) SUBSET [a,b - r] *)
4777     >- (RW_TAC std_ss [SUBSET_DEF, IN_INTERVAL, in_right_open_interval] \\
4778         MATCH_MP_TAC REAL_LT_IMP_LE >> art []) \\
4779     (* step 2 (of 4) *)
4780     MATCH_MP_TAC SUBSET_TRANS \\
4781     Q.EXISTS_TAC `BIGUNION (IMAGE J cover)` >> art [] \\
4782     (* step 3 (of 4) *)
4783     MATCH_MP_TAC SUBSET_TRANS \\
4784     Q.EXISTS_TAC `BIGUNION (IMAGE J (count N))` \\
4785     CONJ_TAC >- (MATCH_MP_TAC SUBSET_BIGUNION \\
4786                  MATCH_MP_TAC IMAGE_SUBSET >> art []) \\
4787     (* step 4 (of 4) *)
4788     RW_TAC std_ss [SUBSET_DEF, IN_BIGUNION_IMAGE, IN_COUNT] \\
4789     rename1 `i < N` >> Q.EXISTS_TAC `i` >> art [] \\
4790     fs [SUBSET_DEF]) >> DISCH_TAC
4791 >> Know `lambda0 (right_open_interval a (b - r)) <= SIGMA (lambda0 o H) (count N)`
4792 >- (MATCH_MP_TAC le_trans \\
4793     Q.EXISTS_TAC `lambda1 (BIGUNION (IMAGE H (count N)))` \\
4794    `lambda0 (right_open_interval a (b - r)) =
4795     lambda1 (right_open_interval a (b - r))`
4796        by METIS_TAC [right_open_interval_in_intervals] >> POP_ORW \\
4797     CONJ_TAC (* by "increasing" *)
4798     >- (Q.UNABBREV_TAC `lambda1` \\
4799         MATCH_MP_TAC (REWRITE_RULE [measure_def, measurable_sets_def]
4800                        (Q.SPEC `lborel1`
4801                          (INST_TYPE [alpha |-> ``:real``] INCREASING))) \\
4802         ASM_SIMP_TAC bool_ss [] \\
4803         CONJ_TAC >- METIS_TAC [SUBSET_DEF, in_right_open_intervals] \\
4804         MATCH_MP_TAC (REWRITE_RULE [subsets_def]
4805                                    (Q.ISPEC `(m_space lborel1,measurable_sets lborel1)`
4806                                             RING_FINITE_UNION)) \\
4807         ASM_SIMP_TAC bool_ss [IMAGE_FINITE, FINITE_COUNT, IN_IMAGE, IN_COUNT,
4808                               SUBSET_DEF] \\
4809         rpt STRIP_TAC >> rename1 `s = H i` \\
4810         METIS_TAC [SUBSET_DEF, in_right_open_intervals]) \\
4811     Know `SIGMA (lambda0 o H) (count N) = SIGMA (lambda1 o H) (count N)`
4812     >- (MATCH_MP_TAC EQ_SYM >> irule EXTREAL_SUM_IMAGE_EQ \\
4813         STRONG_CONJ_TAC
4814         >- (RW_TAC std_ss [IN_COUNT, FINITE_COUNT, o_DEF] \\
4815             METIS_TAC [right_open_interval_in_intervals]) \\
4816         RW_TAC std_ss [FINITE_COUNT] \\
4817         DISJ1_TAC >> NTAC 2 STRIP_TAC \\
4818         MATCH_MP_TAC pos_not_neginf \\
4819         fs [positive_def, measure_def, measurable_sets_def] \\
4820         FIRST_X_ASSUM MATCH_MP_TAC \\
4821         METIS_TAC [right_open_interval_in_intervals]) >> Rewr' \\
4822     (* by "finite additive" *)
4823     Q.UNABBREV_TAC `lambda1` \\
4824     MATCH_MP_TAC (REWRITE_RULE [measure_def, measurable_sets_def]
4825                    (Q.SPEC `lborel1`
4826                      (INST_TYPE [alpha |-> ``:real``] FINITE_SUBADDITIVE))) \\
4827     ASM_SIMP_TAC bool_ss [] \\
4828     rpt STRIP_TAC >- METIS_TAC [SUBSET_DEF, in_right_open_intervals] \\
4829     MATCH_MP_TAC (REWRITE_RULE [subsets_def]
4830                                (Q.ISPEC `(m_space lborel1,measurable_sets lborel1)`
4831                                         RING_FINITE_UNION)) \\
4832     ASM_SIMP_TAC bool_ss [IMAGE_FINITE, FINITE_COUNT, IN_IMAGE, IN_COUNT, SUBSET_DEF] \\
4833     rpt STRIP_TAC >> rename1 `s = H i` \\
4834     METIS_TAC [SUBSET_DEF, in_right_open_intervals]) >> DISCH_TAC
4835 (* H and h *)
4836 >> Know `!n. lambda0 (right_open_interval (A n - r * (1 / 2) pow (n + 1)) (A n)) =
4837              Normal (r * (1 / 2) pow (n + 1))`
4838 >- (GEN_TAC \\
4839    `r * (1 / 2) pow (n + 1) = A n - (A n - r * (1 / 2) pow (n + 1))`
4840       by REAL_ARITH_TAC \\
4841     POP_ASSUM ((GEN_REWRITE_TAC (RAND_CONV o ONCE_DEPTH_CONV) empty_rewrites) o wrap) \\
4842     MATCH_MP_TAC lambda0_def \\
4843     MATCH_MP_TAC REAL_LT_IMP_LE \\
4844     REWRITE_TAC [REAL_LT_SUB_RADD, REAL_LT_ADDR] \\
4845     MATCH_MP_TAC REAL_LT_MUL >> art [POW_HALF_POS]) >> DISCH_TAC
4846 (* rewrite `lambda0 o h` by `lambda0 o H` and the rest *)
4847 >> Q.ABBREV_TAC `D = (\n. right_open_interval (A n - r * (1 / 2) pow (n + 1)) (A n))`
4848 >> Know `lambda0 o h = \n. (lambda0 o H) n - (lambda0 o D) n`
4849 >- (Q.UNABBREV_TAC `D` \\
4850     FUN_EQ_TAC >> Q.X_GEN_TAC `n` >> SIMP_TAC std_ss [o_DEF] >> art [] \\
4851     REWRITE_TAC [eq_sub_ladd_normal] \\
4852     POP_ASSUM (ONCE_REWRITE_TAC o wrap o GSYM) \\
4853     MATCH_MP_TAC EQ_SYM \\
4854     MATCH_MP_TAC (REWRITE_RULE [measure_def, measurable_sets_def]
4855                                (Q.ISPEC `lborel0` ADDITIVE)) \\
4856     Q.UNABBREV_TAC `H` \\
4857     ASM_SIMP_TAC bool_ss [right_open_interval_in_intervals] \\
4858     Know `0 < r * (1 / 2) pow (n + 1)`
4859     >- (MATCH_MP_TAC REAL_LT_MUL >> art [POW_HALF_POS]) >> DISCH_TAC \\
4860     CONJ_TAC (* DISJOINT *)
4861     >- (ONCE_REWRITE_TAC [DISJOINT_SYM] \\
4862         MATCH_MP_TAC right_open_interval_DISJOINT \\
4863         RW_TAC std_ss [REAL_LE_REFL] >| (* 2 subgoals *)
4864         [ (* goal 1 (of 2) *)
4865           MATCH_MP_TAC REAL_LT_IMP_LE >> art [REAL_LT_SUB_RADD, REAL_LT_ADDR],
4866           (* goal 2 (of 2) *)
4867           MATCH_MP_TAC REAL_LT_IMP_LE >> art [] ]) \\
4868     RW_TAC std_ss [Once EXTENSION, IN_UNION, in_right_open_interval] \\
4869     EQ_TAC >> rpt STRIP_TAC >> RW_TAC std_ss [REAL_LET_TOTAL] >| (* 2 subgoals *)
4870     [ (* goal 1 (of 2) *)
4871       MATCH_MP_TAC REAL_LE_TRANS >> Q.EXISTS_TAC `A n` >> art [] \\
4872       MATCH_MP_TAC REAL_LT_IMP_LE >> art [REAL_LT_SUB_RADD, REAL_LT_ADDR],
4873       (* goal 2 (of 2) *)
4874       MATCH_MP_TAC REAL_LT_TRANS >> Q.EXISTS_TAC `A n` >> art [] ]) >> Rewr'
4875 (* simplify extreal$SIGMA (EXTREAL_SUM_IMAGE) *)
4876 >> Know `SIGMA (\n. (lambda0 o H) n - (lambda0 o D) n) (count N) =
4877          SIGMA (lambda0 o H) (count N) - SIGMA (lambda0 o D) (count N)`
4878 >- (irule EXTREAL_SUM_IMAGE_SUB >> REWRITE_TAC [FINITE_COUNT, IN_COUNT] \\
4879     DISJ1_TAC (* this one is easier *) \\
4880     Q.X_GEN_TAC `n` >> Q.UNABBREV_TAC `D` >> SIMP_TAC std_ss [o_DEF] \\
4881     DISCH_TAC \\
4882     reverse CONJ_TAC >- (Q.PAT_X_ASSUM `!n. lambda0 _ = Normal _`
4883                            (ONCE_REWRITE_TAC o wrap) \\
4884                          REWRITE_TAC [extreal_not_infty]) \\
4885     MATCH_MP_TAC pos_not_neginf \\
4886     Q.UNABBREV_TAC `H` >> BETA_TAC \\
4887     Know `lambda0 (right_open_interval (A n - r * (1 / 2) pow (n + 1)) (B n)) =
4888           Normal (B n - (A n - r * (1 / 2) pow (n + 1)))`
4889     >- (MATCH_MP_TAC lambda0_def \\
4890         MATCH_MP_TAC REAL_LT_IMP_LE >> art []) >> Rewr' \\
4891     REWRITE_TAC [extreal_le_eq, extreal_of_num_def] \\
4892     MATCH_MP_TAC REAL_LT_IMP_LE \\
4893     ASM_REWRITE_TAC [REAL_LT_SUB_LADD, REAL_ADD_LID]) >> Rewr'
4894 >> Know `SIGMA (lambda0 o D) (count N) =
4895          SIGMA (\n. Normal (r * (1 / 2) pow (n + 1))) (count N)`
4896 >- (Q.UNABBREV_TAC `D` >> ASM_SIMP_TAC std_ss [o_DEF]) >> Rewr'
4897 >> Q.UNABBREV_TAC `D` (* D is not needed any more *)
4898 >> POP_ASSUM K_TAC
4899 >> Know `SIGMA (\n. Normal ((\n. r * (1 / 2) pow (n + 1)) n)) (count N) =
4900               Normal (SIGMA (\n. r * (1 / 2) pow (n + 1))     (count N))`
4901 >- (MATCH_MP_TAC EXTREAL_SUM_IMAGE_NORMAL \\
4902     REWRITE_TAC [FINITE_COUNT]) >> BETA_TAC >> Rewr'
4903 (* fallback to real_sigma$SIGMA (REAL_SUM_IMAGE) *)
4904 >> Know `REAL_SUM_IMAGE (\n. r * ((\n. (1 / 2) pow (n + 1)) n)) (count N) =
4905                r * REAL_SUM_IMAGE (\n. (1 / 2) pow (n + 1))     (count N)`
4906 >- (MATCH_MP_TAC REAL_SUM_IMAGE_CMUL \\
4907     REWRITE_TAC [FINITE_COUNT]) >> BETA_TAC >> Rewr'
4908 >> Know `REAL_SUM_IMAGE (\n. (1 / 2) pow (n + 1)) (count N) <
4909          suminf (\n. (1 / 2) pow (n + 1))`
4910 >- (REWRITE_TAC [REAL_SUM_IMAGE_COUNT] \\
4911     MATCH_MP_TAC SER_POS_LT \\
4912     CONJ_TAC >- (MATCH_MP_TAC SUM_SUMMABLE \\
4913                  Q.EXISTS_TAC `1` >> REWRITE_TAC [POW_HALF_SER]) \\
4914     RW_TAC std_ss [Once ADD_COMM, GSYM SUC_ONE_ADD] \\
4915     METIS_TAC [REAL_HALF_BETWEEN, POW_POS_LT])
4916 >> Know `suminf (\n. (1 / 2) pow (n + 1)) = (1 :real)`
4917 >- (MATCH_MP_TAC EQ_SYM \\
4918     MATCH_MP_TAC SUM_UNIQ >> REWRITE_TAC [POW_HALF_SER]) >> Rewr'
4919 >> DISCH_TAC
4920 >> Know `Normal (r * SIGMA (\n. (1 / 2) pow (n + 1)) (count N)) < Normal r`
4921 >- (REWRITE_TAC [extreal_lt_eq] \\
4922     MATCH_MP_TAC (REWRITE_RULE [REAL_MUL_RID]
4923                    (Q.SPECL [`r`, `SIGMA (\n. (1 / 2) pow (n + 1)) (count N)`,
4924                              `1`] REAL_LT_LMUL_IMP)) >> art [])
4925 >> POP_ASSUM K_TAC >> DISCH_TAC
4926 (* clean up all ring assumptions *)
4927 >> Q.PAT_X_ASSUM `ring _` K_TAC
4928 >> Q.PAT_X_ASSUM `_ = smallest_ring _ _` K_TAC
4929 >> Q.PAT_X_ASSUM `subsets right_open_intervals SUBSET measurable_sets lborel1` K_TAC
4930 >> Q.PAT_X_ASSUM `finite_additive lborel1` K_TAC
4931 >> Q.PAT_X_ASSUM `positive lborel1` K_TAC
4932 >> Q.PAT_X_ASSUM `additive lborel1` K_TAC
4933 >> Q.PAT_X_ASSUM `increasing lborel1` K_TAC
4934 >> Q.PAT_X_ASSUM `subadditive lborel1` K_TAC
4935 >> Q.PAT_X_ASSUM `finite_subadditive lborel1` K_TAC
4936 >> Q.PAT_X_ASSUM `!s. P ==> (lambda1 s = lambda0 s)` K_TAC
4937 >> Q.PAT_X_ASSUM `m_space lborel1 = UNIV` K_TAC
4938 >> Q.UNABBREV_TAC `lambda1`
4939 (* final extreal arithmetics *)
4940 >> Know `lambda0 (right_open_interval a (b - r)) = Normal (b - r - a)`
4941 >- (MATCH_MP_TAC lambda0_def \\
4942     MATCH_MP_TAC REAL_LT_IMP_LE \\
4943    `a < b - r <=> r < b - a` by REAL_ARITH_TAC >> POP_ORW \\
4944     MATCH_MP_TAC REAL_LET_TRANS >> Q.EXISTS_TAC `d` \\
4945     reverse CONJ_TAC >- fs [extreal_lt_eq] \\
4946     Q.UNABBREV_TAC `r` \\
4947     MATCH_MP_TAC REAL_LE_LDIV >> RW_TAC real_ss [] \\
4948     MATCH_MP_TAC (SIMP_RULE real_ss []
4949                             (Q.SPECL [`d`, `d`, `1`, `2`] REAL_LE_MUL2)) \\
4950     MATCH_MP_TAC REAL_LT_IMP_LE >> art [])
4951 >> DISCH_THEN ((FULL_SIMP_TAC std_ss) o wrap)
4952 >> Q.ABBREV_TAC `r1 = b - r - a`
4953 >> Q.ABBREV_TAC `R2 = SIGMA (lambda0 o H) (count N)`
4954 >> Know `R2 <> NegInf /\ R2 <> PosInf`
4955 >- (Q.UNABBREV_TAC `R2` \\
4956     CONJ_TAC (* positive *)
4957     >- (MATCH_MP_TAC pos_not_neginf \\
4958         irule EXTREAL_SUM_IMAGE_POS >> art [FINITE_COUNT] \\
4959         Q.UNABBREV_TAC `H` \\
4960         Q.X_GEN_TAC `i`>> RW_TAC std_ss [IN_COUNT, o_DEF] \\
4961         fs [positive_def, measure_def, measurable_sets_def] \\
4962         FIRST_X_ASSUM MATCH_MP_TAC \\
4963         REWRITE_TAC [right_open_interval_in_intervals]) \\
4964     (* finiteness *)
4965     MATCH_MP_TAC EXTREAL_SUM_IMAGE_NOT_POSINF >> art [FINITE_COUNT] \\
4966     Q.UNABBREV_TAC `H` \\
4967     Q.X_GEN_TAC `i`>> SIMP_TAC std_ss [IN_COUNT, o_DEF] \\
4968     DISCH_TAC >> PROVE_TAC [lambda0_not_infty]) >> STRIP_TAC
4969 >> `?r2. R2 = Normal r2` by METIS_TAC [extreal_cases]
4970 >> Q.ABBREV_TAC `r3 = REAL_SUM_IMAGE (\n. (1 / 2) pow (n + 1)) (count N)`
4971 >> FULL_SIMP_TAC std_ss [extreal_le_eq, extreal_lt_eq,
4972                          extreal_add_def, extreal_sub_def]
4973 (* final real arithmetics *)
4974 >> Q.PAT_X_ASSUM `r1 <= r2` MP_TAC
4975 >> Q.PAT_X_ASSUM `r * r3 < r` MP_TAC
4976 >> Know `d = r * 2`
4977 >- (Q.UNABBREV_TAC `r` \\
4978     MATCH_MP_TAC EQ_SYM >> MATCH_MP_TAC REAL_DIV_RMUL \\
4979     RW_TAC real_ss []) >> Rewr'
4980 >> KILL_TAC >> REAL_ARITH_TAC
4981QED
4982
4983(* Borel measure space with the household Lebesgue measure (lborel),
4984   constructed directly by Caratheodory's Extension Theorem.
4985 *)
4986local
4987  val thm = prove (
4988    ``?m. (!s. s IN subsets right_open_intervals ==> (measure m s = lambda0 s)) /\
4989          ((m_space m, measurable_sets m) = borel) /\ measure_space m``,
4990   (* proof *)
4991      MP_TAC (Q.ISPEC `lborel0` CARATHEODORY_SEMIRING) \\
4992      MP_TAC right_open_intervals_semiring \\
4993      MP_TAC right_open_intervals_sigma_borel \\
4994      MP_TAC lborel0_premeasure \\
4995      RW_TAC std_ss [m_space_def, measurable_sets_def, measure_def, SPACE] \\
4996      Q.EXISTS_TAC `m` >> art []);
4997in
4998  (* |- (!s. s IN subsets right_open_intervals ==> lambda s = lambda0 s) /\
4999        (m_space lborel,measurable_sets lborel) = borel /\
5000        measure_space lborel *)
5001  val lborel_def = new_specification ("lborel_def", ["lborel"], thm);
5002end;
5003
5004Theorem space_lborel :
5005    m_space lborel = univ(:real)
5006Proof
5007    PROVE_TAC [lborel_def, GSYM SPACE, CLOSED_PAIR_EQ, space_borel]
5008QED
5009
5010Theorem m_space_lborel :
5011    m_space lborel = space borel
5012Proof
5013    PROVE_TAC [lborel_def, GSYM SPACE, CLOSED_PAIR_EQ]
5014QED
5015
5016Theorem sets_lborel :
5017    measurable_sets lborel = subsets borel
5018Proof
5019    PROVE_TAC [lborel_def, GSYM SPACE, CLOSED_PAIR_EQ]
5020QED
5021
5022(* give `measure lebesgue` a special symbol (cf. `lambda0`) *)
5023Overload lambda = ``measure lborel``
5024
5025Theorem lambda_empty :
5026    lambda {} = 0
5027Proof
5028    ASSUME_TAC right_open_intervals_semiring
5029 >> `{} IN subsets right_open_intervals` by PROVE_TAC [semiring_def]
5030 >> `lambda {} = lambda0 {}` by PROVE_TAC [lborel_def]
5031 >> POP_ORW >> REWRITE_TAC [lambda0_empty]
5032QED
5033
5034Theorem lambda_prop :
5035    !a b. a <= b ==> (lambda (right_open_interval a b) = Normal (b - a))
5036Proof
5037    rpt STRIP_TAC
5038 >> Know `(right_open_interval a b) IN subsets right_open_intervals`
5039 >- (RW_TAC std_ss [subsets_def, right_open_intervals, GSPECIFICATION, IN_UNIV] \\
5040     Q.EXISTS_TAC `(a,b)` >> SIMP_TAC std_ss [])
5041 >> RW_TAC std_ss [lborel_def, lambda0_def, measure_def]
5042QED
5043
5044Theorem lambda_not_infty :
5045    !a b. lambda (right_open_interval a b) <> PosInf /\
5046          lambda (right_open_interval a b) <> NegInf
5047Proof
5048    rpt GEN_TAC
5049 >> Know `lambda (right_open_interval a b) = lambda0 (right_open_interval a b)`
5050 >- (`right_open_interval a b IN subsets right_open_intervals`
5051       by PROVE_TAC [right_open_interval_in_intervals] \\
5052     PROVE_TAC [lborel_def]) >> Rewr'
5053 >> PROVE_TAC [lambda0_not_infty]
5054QED
5055
5056(* |- measure_space lborel *)
5057Theorem measure_space_lborel = List.nth (CONJUNCTS lborel_def, 2);
5058
5059(* first step beyond right-open_intervals *)
5060Theorem lambda_sing :
5061    !c. lambda {c} = 0
5062Proof
5063    GEN_TAC
5064 >> Q.ABBREV_TAC `f = \n. right_open_interval (c - (1/2) pow n) (c + (1/2) pow n)`
5065 >> Know `{c} = BIGINTER (IMAGE f UNIV)`
5066 >- (Q.UNABBREV_TAC `f` \\
5067     REWRITE_TAC [right_open_interval, REAL_SING_BIGINTER]) >> Rewr'
5068 >> Know `0 = inf (IMAGE (lambda o f) UNIV)`
5069 >- (Q.UNABBREV_TAC `f` \\
5070     SIMP_TAC std_ss [inf_eq', IN_IMAGE, IN_UNIV] \\
5071     Know `!x. lambda  (right_open_interval (c - (1/2) pow x) (c + (1/2) pow x)) =
5072               lambda0 (right_open_interval (c - (1/2) pow x) (c + (1/2) pow x))`
5073     >- METIS_TAC [right_open_interval_in_intervals, lborel_def] >> Rewr' \\
5074     Know `!x. lambda0 (right_open_interval (c - (1/2) pow x) (c + (1/2) pow x)) =
5075               Normal ((c + (1/2) pow x) - (c - (1/2) pow x))`
5076     >- (GEN_TAC >> MATCH_MP_TAC lambda0_def \\
5077         REWRITE_TAC [real_sub, REAL_LE_LADD] \\
5078         MATCH_MP_TAC REAL_LT_IMP_LE \\
5079        `(0 :real) < 1 / 2` by PROVE_TAC [REAL_HALF_BETWEEN] \\
5080         MATCH_MP_TAC REAL_LT_TRANS >> Q.EXISTS_TAC `0` \\
5081         ASM_SIMP_TAC std_ss [REAL_POW_LT, REAL_NEG_LT0]) >> Rewr' \\
5082     Know `!x. c + (1/2) pow x - (c - (1/2) pow x) = 2 * (1/2) pow x`
5083     >- (GEN_TAC >> Q.ABBREV_TAC `(r :real) = (1 / 2) pow x` \\
5084        `c + r - (c - r) = 2 * r` by REAL_ARITH_TAC >> POP_ORW \\
5085         Q.UNABBREV_TAC `r` >> REWRITE_TAC [pow]) >> Rewr' \\
5086     rpt STRIP_TAC >| (* 2 subgoals *)
5087     [ (* goal 1 (of 2): easy *)
5088       POP_ORW >> REWRITE_TAC [extreal_of_num_def, extreal_le_eq] \\
5089       MATCH_MP_TAC REAL_LT_IMP_LE \\
5090       MATCH_MP_TAC REAL_LT_MUL >> RW_TAC real_ss [REAL_POW_LT],
5091       (* goal 2 (of 2): hard *)
5092       MATCH_MP_TAC le_epsilon >> RW_TAC std_ss [add_lzero] \\
5093       MATCH_MP_TAC le_trans \\
5094      `e <> NegInf` by METIS_TAC [pos_not_neginf, lt_imp_le] \\
5095      `?r. e = Normal r` by METIS_TAC [extreal_cases] \\
5096       POP_ASSUM (fn th =>
5097                  FULL_SIMP_TAC std_ss [extreal_not_infty, extreal_of_num_def,
5098                                        extreal_lt_eq, th]) \\
5099      `0 < r / 2` by RW_TAC real_ss [] \\
5100       MP_TAC (Q.SPEC `r / 2` POW_HALF_SMALL) >> RW_TAC std_ss [] \\
5101       Q.EXISTS_TAC `Normal (2 * (1/2) pow n)` \\
5102       CONJ_TAC >- (FIRST_X_ASSUM MATCH_MP_TAC \\
5103                    Q.EXISTS_TAC `n` >> art []) \\
5104       REWRITE_TAC [extreal_le_eq, Once REAL_MUL_COMM] \\
5105       MATCH_MP_TAC REAL_LT_IMP_LE \\
5106       ASSUME_TAC (Q.SPEC `n` POW_HALF_POS) \\
5107      `(0 :real) < 2` by REAL_ARITH_TAC \\
5108       POP_ASSUM (art o wrap o (MATCH_MP (GSYM REAL_LT_RDIV_EQ))) ]) >> Rewr'
5109 >> MATCH_MP_TAC EQ_SYM
5110 >> MATCH_MP_TAC (Q.ISPEC `lborel` MONOTONE_CONVERGENCE_BIGINTER2)
5111 >> RW_TAC std_ss [measure_space_lborel, IN_FUNSET, IN_UNIV, sets_lborel]
5112 >| [ (* goal 1 (of 3) *)
5113      rename1 `f n IN _` \\
5114     `f n IN subsets right_open_intervals`
5115        by METIS_TAC [right_open_interval_in_intervals] \\
5116      PROVE_TAC [SUBSET_DEF, right_open_intervals_subset_borel],
5117      (* goal 2 (of 3) *)
5118     `f n IN subsets right_open_intervals`
5119        by METIS_TAC [right_open_interval_in_intervals] \\
5120     `lambda (f n) = lambda0 (f n)` by PROVE_TAC [lborel_def] >> POP_ORW \\
5121      Q.UNABBREV_TAC `f` >> BETA_TAC \\
5122      REWRITE_TAC [lambda0_not_infty],
5123      (* goal 3 (of 3) *)
5124      Q.UNABBREV_TAC `f` >> BETA_TAC \\
5125      RW_TAC std_ss [in_right_open_interval, SUBSET_DEF, GSPECIFICATION] >|
5126      [ (* goal 3.1 (of 2) *)
5127        MATCH_MP_TAC REAL_LE_TRANS \\
5128        Q.EXISTS_TAC `c - (1 / 2) pow (SUC n)` >> art [] \\
5129       `n <= SUC n` by RW_TAC arith_ss [] \\
5130        POP_ASSUM (ASSUME_TAC o (MATCH_MP POW_HALF_MONO)) \\
5131        REAL_ASM_ARITH_TAC,
5132        (* goal 3.2 (of 2) *)
5133        MATCH_MP_TAC REAL_LTE_TRANS \\
5134        Q.EXISTS_TAC `c + (1 / 2) pow (SUC n)` >> art [] \\
5135       `n <= SUC n` by RW_TAC arith_ss [] \\
5136        POP_ASSUM (ASSUME_TAC o (MATCH_MP POW_HALF_MONO)) \\
5137        REAL_ASM_ARITH_TAC ] ]
5138QED
5139
5140Theorem lambda_finite :
5141    !c. FINITE c ==> lambda c = 0
5142Proof
5143    HO_MATCH_MP_TAC FINITE_INDUCT
5144 >> ASSUME_TAC measure_space_lborel
5145 >> rw [MEASURE_EMPTY]
5146 >> ‘DISJOINT c {e} /\ e INSERT c = c UNION {e}’ by ASM_SET_TAC []
5147 >> POP_ORW
5148 >> ‘additive lborel’ by PROVE_TAC [MEASURE_SPACE_ADDITIVE]
5149 >> fs [additive_def]
5150 >> Suff ‘lambda (c UNION {e}) = lambda c + lambda {e}’
5151 >- rw [lambda_sing]
5152 >> POP_ASSUM MATCH_MP_TAC
5153 >> rw [finite_imp_borel_measurable, sets_lborel, borel_measurable_sets_sing]
5154QED
5155
5156(* This elegant result is based on MEASURE_COUNTABLY_ADDITIVE and lambda_sing *)
5157Theorem lambda_countable :
5158    !c. countable c ==> lambda c = 0
5159Proof
5160    ASSUME_TAC measure_space_lborel
5161 >> rw [COUNTABLE_ALT_BIJ]
5162 >- (MATCH_MP_TAC lambda_finite >> art [])
5163 >> ‘c = IMAGE (enumerate c) UNIV’ by PROVE_TAC [BIJ_IMAGE]
5164 >> POP_ORW
5165 >> qmatch_abbrev_tac ‘lambda (IMAGE f UNIV) = 0’
5166 >> qabbrev_tac ‘g = \x. {f x}’
5167 >> Know ‘IMAGE f UNIV = BIGUNION (IMAGE g UNIV)’
5168 >- rw [Once EXTENSION, IN_BIGUNION_IMAGE, Abbr ‘g’]
5169 >> Rewr'
5170 >> qmatch_abbrev_tac ‘lambda s = 0’
5171 >> Know ‘lambda s = suminf (lambda o g)’
5172 >- (ONCE_REWRITE_TAC [EQ_SYM_EQ] \\
5173     MATCH_MP_TAC MEASURE_COUNTABLY_ADDITIVE \\
5174     simp [IN_FUNSET, Abbr ‘g’, sets_lborel, borel_measurable_sets_sing] \\
5175     rpt STRIP_TAC \\
5176     fs [BIJ_DEF, INJ_DEF] >> METIS_TAC [])
5177 >> Rewr'
5178 >> simp [o_DEF, lambda_sing, Abbr ‘g’, ext_suminf_0]
5179QED
5180
5181Theorem lambda_closed_interval :
5182    !a b. a <= b ==> (lambda (interval [a,b]) = Normal (b - a))
5183Proof
5184    rpt STRIP_TAC
5185 >> POP_ASSUM (STRIP_ASSUME_TAC o (REWRITE_RULE [REAL_LE_LT, Once DISJ_SYM]))
5186 >- fs [GSYM extreal_of_num_def, INTERVAL_SING, lambda_sing]
5187 >> Know `interval [a,b] = right_open_interval a b UNION {b}`
5188 >- (RW_TAC std_ss [Once EXTENSION, IN_UNION, IN_SING, IN_INTERVAL,
5189                    in_right_open_interval] \\
5190     EQ_TAC >> rpt STRIP_TAC >> fs [REAL_LE_REFL]
5191     >- fs [REAL_LE_LT] \\ (* 2 goals left, same tactics *)
5192     MATCH_MP_TAC REAL_LT_IMP_LE >> art []) >> Rewr'
5193 >> Suff `lambda (right_open_interval a b UNION {b}) =
5194          lambda (right_open_interval a b) + lambda {b}`
5195 >- (Rewr' >> REWRITE_TAC [lambda_sing, add_rzero] \\
5196     MATCH_MP_TAC lambda_prop \\
5197     MATCH_MP_TAC REAL_LT_IMP_LE >> art [])
5198 >> MATCH_MP_TAC (Q.ISPEC `lborel` ADDITIVE)
5199 >> ASSUME_TAC measure_space_lborel
5200 >> CONJ_TAC >- (MATCH_MP_TAC MEASURE_SPACE_ADDITIVE >> art [])
5201 >> REWRITE_TAC [sets_lborel]
5202 >> STRONG_CONJ_TAC
5203 >- REWRITE_TAC [right_open_interval, borel_measurable_sets] >> DISCH_TAC
5204 >> STRONG_CONJ_TAC
5205 >- REWRITE_TAC [borel_measurable_sets] >> DISCH_TAC
5206 >> reverse CONJ_TAC
5207 >- (MATCH_MP_TAC ALGEBRA_UNION >> art [] \\
5208     REWRITE_TAC [REWRITE_RULE [sigma_algebra_def] sigma_algebra_borel])
5209 >> ONCE_REWRITE_TAC [DISJOINT_SYM]
5210 >> RW_TAC std_ss [DISJOINT_ALT, IN_SING, right_open_interval,
5211                   GSPECIFICATION, REAL_LT_REFL, real_lte]
5212QED
5213
5214Theorem lambda_closed_interval_content :
5215    !a b. lambda (interval [a,b]) = Normal (content (interval [a,b]))
5216Proof
5217    rpt STRIP_TAC
5218 >> `a <= b \/ b < a` by PROVE_TAC [REAL_LTE_TOTAL]
5219 >- ASM_SIMP_TAC std_ss [CONTENT_CLOSED_INTERVAL, lambda_closed_interval]
5220 >> IMP_RES_TAC REAL_LT_IMP_LE
5221 >> fs [GSYM CONTENT_EQ_0, GSYM extreal_of_num_def]
5222 >> fs [INTERVAL_EQ_EMPTY]
5223 >> REWRITE_TAC [lambda_empty]
5224QED
5225
5226Theorem lambda_open_interval :
5227    !a b. a <= b ==> (lambda (interval (a,b)) = Normal (b - a))
5228Proof
5229    rpt STRIP_TAC
5230 >> POP_ASSUM (STRIP_ASSUME_TAC o (REWRITE_RULE [REAL_LE_LT, Once DISJ_SYM]))
5231 >- fs [GSYM extreal_of_num_def, INTERVAL_SING, lambda_empty]
5232 >> Know `interval (a,b) = right_open_interval a b DIFF {a}`
5233 >- (RW_TAC std_ss [Once EXTENSION, IN_DIFF, IN_SING, IN_INTERVAL,
5234                    in_right_open_interval] \\
5235     EQ_TAC >> rpt STRIP_TAC >> fs [REAL_LE_REFL]
5236     >- (MATCH_MP_TAC REAL_LT_IMP_LE >> art []) \\
5237     fs [REAL_LE_LT]) >> Rewr'
5238 >> Suff `lambda (right_open_interval a b DIFF {a}) =
5239          lambda (right_open_interval a b) - lambda {a}`
5240 >- (Rewr' >> REWRITE_TAC [lambda_sing, sub_rzero] \\
5241     MATCH_MP_TAC lambda_prop \\
5242     MATCH_MP_TAC REAL_LT_IMP_LE >> art [])
5243 >> MATCH_MP_TAC (Q.ISPEC `lborel` MEASURE_SPACE_FINITE_DIFF_SUBSET)
5244 >> REWRITE_TAC [measure_space_lborel, sets_lborel]
5245 >> STRONG_CONJ_TAC
5246 >- REWRITE_TAC [right_open_interval, borel_measurable_sets] >> DISCH_TAC
5247 >> STRONG_CONJ_TAC
5248 >- REWRITE_TAC [borel_measurable_sets] >> DISCH_TAC
5249 >> CONJ_TAC
5250 >- RW_TAC std_ss [SUBSET_DEF, IN_SING, in_right_open_interval, REAL_LE_REFL]
5251 >> REWRITE_TAC [lambda_not_infty]
5252QED
5253
5254(* |- sigma_finite lborel <=>
5255      ?A. COUNTABLE A /\ A SUBSET measurable_sets lborel /\
5256          BIGUNION A = m_space lborel /\ !a. a IN A ==> lambda a <> PosInf
5257 *)
5258val sigma_finite_measure = MATCH_MP SIGMA_FINITE_ALT2 measure_space_lborel;
5259
5260Theorem sigma_finite_lborel :
5261    sigma_finite lborel
5262Proof
5263    RW_TAC std_ss [sigma_finite_measure]
5264 >> Q.EXISTS_TAC `{line n | n IN UNIV}`
5265 >> rpt CONJ_TAC (* 4 subgoals *)
5266 >- (SIMP_TAC std_ss [GSYM IMAGE_DEF] \\
5267     MATCH_MP_TAC image_countable >> SIMP_TAC std_ss [COUNTABLE_NUM])
5268 >- (SIMP_TAC std_ss [SUBSET_DEF, GSPECIFICATION, sets_lborel, IN_UNIV] \\
5269     rpt STRIP_TAC >> RW_TAC std_ss [borel_line])
5270 >- (SIMP_TAC std_ss [EXTENSION, space_lborel, IN_UNIV] \\
5271     SIMP_TAC std_ss [IN_BIGUNION, GSPECIFICATION] \\
5272     GEN_TAC >> ASSUME_TAC REAL_IN_LINE \\
5273     POP_ASSUM (MP_TAC o Q.SPEC `x`) >> SET_TAC [])
5274 >> RW_TAC std_ss [GSPECIFICATION, IN_UNIV, line]
5275 >> `-&n <= (&n) :real` by RW_TAC real_ss []
5276 >> POP_ASSUM (MP_TAC o (SIMP_RULE list_ss [CLOSED_interval]) o
5277               (MATCH_MP lambda_closed_interval)) >> Rewr'
5278 >> REWRITE_TAC [extreal_not_infty]
5279QED
5280
5281Theorem lambda_univ :
5282    lambda UNIV = PosInf
5283Proof
5284    qabbrev_tac ‘f = \n. interval (-&n,&n)’
5285 >> Know ‘UNIV = BIGUNION (IMAGE f UNIV)’
5286 >- (rw [Once EXTENSION, IN_BIGUNION_IMAGE] \\
5287     MP_TAC (Q.SPEC ‘abs x’ SIMP_REAL_ARCH_SUC) >> rw [ABS_BOUNDS_LT] \\
5288     Q.EXISTS_TAC ‘SUC n’ >> simp [Abbr ‘f’, IN_INTERVAL])
5289 >> Rewr'
5290 >> qmatch_abbrev_tac ‘lambda s = PosInf’
5291 >> Know ‘measure lborel s = sup (IMAGE (measure lborel o f) UNIV)’
5292 >- (SYM_TAC >> MATCH_MP_TAC MONOTONE_CONVERGENCE \\
5293     simp [measure_space_lborel, sets_lborel] \\
5294     CONJ_TAC
5295     >- rw [IN_FUNSET, Abbr ‘f’, OPEN_interval, borel_measurable_sets] \\
5296     rw [Abbr ‘f’, SUBSET_DEF, IN_INTERVAL] >| (* 2 subgoals *)
5297     [ (* goal 1 (of 2) *)
5298       Q_TAC (TRANS_TAC REAL_LT_TRANS) ‘-&n’ >> simp [],
5299       (* goal 2 (of 2) *)
5300       Q_TAC (TRANS_TAC REAL_LT_TRANS) ‘&n’ >> simp [] ])
5301 >> Rewr'
5302 >> Know ‘lambda o f = \n. Normal 2 * &n’
5303 >- rw [o_DEF, FUN_EQ_THM, Abbr ‘f’, lambda_open_interval,
5304        extreal_of_num_def, extreal_mul_eq, REAL_SUB_RNEG]
5305 >> Rewr'
5306 >> qabbrev_tac ‘g :num -> extreal = \n. &n’
5307 >> simp []
5308 >> Know ‘sup (IMAGE (\n. Normal 2 * g n) UNIV) =
5309          Normal 2 * sup (IMAGE g UNIV)’
5310 >- (MATCH_MP_TAC sup_cmul >> simp [])
5311 >> Rewr'
5312 >> ‘IMAGE g UNIV = \x. ?n. x = &n’ by rw [Once EXTENSION]
5313 >> POP_ORW
5314 >> simp [sup_num, mul_infty]
5315QED
5316
5317(* ------------------------------------------------------------------------- *)
5318(*  Extreal-based Borel measure space                                        *)
5319(* ------------------------------------------------------------------------- *)
5320
5321Definition ext_lborel_def :
5322    ext_lborel = (space Borel, subsets Borel, lambda o real_set)
5323End
5324
5325Theorem measure_space_ext_lborel : (* was: MEASURE_SPACE_LBOREL *)
5326    measure_space ext_lborel
5327Proof
5328    simp [ext_lborel_def, measure_space_def, SIGMA_ALGEBRA_BOREL]
5329 >> Know ‘!B. real_set (IMAGE Normal B) = B /\
5330              real_set (IMAGE Normal B UNION {NegInf}) = B /\
5331              real_set (IMAGE Normal B UNION {PosInf}) = B /\
5332              real_set (IMAGE Normal B UNION {NegInf; PosInf}) = B’
5333 >- (rpt STRIP_TAC \\
5334     rw [Once EXTENSION, real_set_def] \\
5335     EQ_TAC >> rw [] >> art [real_normal] \\
5336     Q.EXISTS_TAC ‘Normal x’ >> rw [extreal_not_infty])
5337 >> rpt STRIP_TAC
5338 (* positive *)
5339 >- (rw [positive_def] >- rw [real_set_def, lambda_empty] \\
5340     STRIP_ASSUME_TAC
5341       (REWRITE_RULE [positive_def] (MATCH_MP MEASURE_SPACE_POSITIVE
5342                                              measure_space_lborel)) \\
5343     POP_ASSUM MATCH_MP_TAC >> fs [Borel, sets_lborel])
5344 (* countably_additive *)
5345 >> rw [countably_additive_def, SPACE_BOREL, IN_FUNSET, IN_UNIV]
5346 >> Q.ABBREV_TAC ‘rf = real_set o f’
5347 >> Know ‘!n. rf n IN subsets borel’
5348 >- (GEN_TAC \\
5349     Q.PAT_X_ASSUM ‘BIGUNION (IMAGE f UNIV) IN subsets Borel’ K_TAC \\
5350     Q.PAT_X_ASSUM ‘!i j. i <> j ==> DISJOINT (f i) (f j)’ K_TAC \\
5351     fs [Abbr ‘rf’, Borel] \\
5352     POP_ASSUM (STRIP_ASSUME_TAC o (Q.SPEC ‘n’)) >> fs [])
5353 >> DISCH_TAC
5354 >> Know ‘real_set (BIGUNION (IMAGE f UNIV)) = BIGUNION (IMAGE rf UNIV)’
5355 >- (rw [Once EXTENSION, real_set_def, Abbr ‘rf’] \\
5356     EQ_TAC >> rw []
5357     >- (rename1 ‘y IN f n’ \\
5358         Q.EXISTS_TAC ‘(real_set o f) n’ \\
5359         rw [real_set_def] >- (Q.EXISTS_TAC ‘y’ >> rw []) \\
5360         Q.EXISTS_TAC ‘n’ >> rw []) \\
5361     fs [GSPECIFICATION] >> rename1 ‘y IN f n’ \\
5362     Q.EXISTS_TAC ‘y’ >> rw [] \\
5363     Q.EXISTS_TAC ‘f n’ >> rw [] \\
5364     Q.EXISTS_TAC ‘n’ >> rw []) >> Rewr'
5365 >> MATCH_MP_TAC EQ_SYM
5366 >> MATCH_MP_TAC (Q.ISPEC ‘lborel’ COUNTABLY_ADDITIVE)
5367 >> simp [IN_FUNSET, IN_UNIV, sets_lborel]
5368 >> CONJ_TAC >- METIS_TAC [measure_space_def, measure_space_lborel]
5369 (* DISJOINT (rf i) (rf j) *)
5370 >> CONJ_TAC
5371 >- (qx_genl_tac [‘m’, ‘n’] >> DISCH_TAC \\
5372     fs [DISJOINT_ALT, Abbr ‘rf’] \\
5373     rw [real_set_def] >> rename1 ‘y IN f m’ \\
5374     rename1 ‘real z = real y’ \\
5375     Cases_on ‘z = PosInf’ >- rw [] >> DISJ2_TAC \\
5376     Cases_on ‘z = NegInf’ >- rw [] >> DISJ2_TAC \\
5377    ‘?a. y = Normal a’ by METIS_TAC [extreal_cases] \\
5378    ‘?b. z = Normal b’ by METIS_TAC [extreal_cases] \\
5379     fs [real_normal] \\
5380     FIRST_X_ASSUM irule >> Q.EXISTS_TAC ‘m’ >> rw [])
5381 (* BIGUNION IN subsets borel *)
5382 >> STRIP_ASSUME_TAC (REWRITE_RULE [SIGMA_ALGEBRA_FN] sigma_algebra_borel)
5383 >> POP_ASSUM MATCH_MP_TAC
5384 >> rw [IN_FUNSET]
5385QED
5386
5387Theorem sigma_finite_ext_lborel : (* was: SIGMA_FINITE_LBOREL *)
5388    sigma_finite ext_lborel
5389Proof
5390    RW_TAC std_ss [MATCH_MP SIGMA_FINITE_ALT2 measure_space_ext_lborel]
5391 >> Q.EXISTS_TAC `{NegInf; PosInf} INSERT {IMAGE Normal (line n) | n IN UNIV}`
5392 >> rpt CONJ_TAC (* 4 subgoals *)
5393 >- (REWRITE_TAC [countable_INSERT] \\
5394     Know ‘{IMAGE Normal (line n) | n IN UNIV} =
5395           IMAGE (IMAGE Normal) {line n | n IN UNIV}’
5396     >- (rw [Once EXTENSION] >> EQ_TAC >> rw []
5397         >- (Q.EXISTS_TAC ‘line n’ >> REWRITE_TAC [] \\
5398             Q.EXISTS_TAC ‘n’ >> REWRITE_TAC []) \\
5399         Q.EXISTS_TAC ‘n’ >> REWRITE_TAC []) >> Rewr' \\
5400     MATCH_MP_TAC image_countable \\
5401    ‘{line n | n IN UNIV} = IMAGE line UNIV’ by SET_TAC [] >> POP_ORW \\
5402     MATCH_MP_TAC image_countable \\
5403     SIMP_TAC std_ss [COUNTABLE_NUM])
5404 (* SUBSET *)
5405 >- (SIMP_TAC std_ss [SUBSET_DEF, GSPECIFICATION, measurable_sets_def,
5406                      ext_lborel_def, IN_UNIV, line] \\
5407     rw [IN_INSERT]
5408     >- (rw [Borel] >> qexistsl_tac [‘{}’, ‘{NegInf; PosInf}’] >> rw [] \\
5409         MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY >> REWRITE_TAC [sigma_algebra_borel]) \\
5410     Know ‘IMAGE Normal {x | -&n <= x /\ x <= &n} =
5411           {x | Normal (-&n) <= x /\ x <= Normal (&n)}’
5412     >- (rw [Once EXTENSION] >> EQ_TAC >> rw [] >> rw [extreal_le_eq] \\
5413         Q.EXISTS_TAC ‘real x’ \\
5414         STRONG_CONJ_TAC
5415         >- (MATCH_MP_TAC EQ_SYM >> MATCH_MP_TAC normal_real \\
5416             CONJ_TAC >> REWRITE_TAC [lt_infty] >| (* 2 subgoals *)
5417             [ (* goal 1 (of 2) *)
5418               MATCH_MP_TAC lte_trans \\
5419               Q.EXISTS_TAC ‘Normal (-&n)’ >> art [lt_infty],
5420               (* goal 2 (of 2) *)
5421               MATCH_MP_TAC let_trans \\
5422               Q.EXISTS_TAC ‘Normal (&n)’ >> art [lt_infty] ]) \\
5423         DISCH_THEN (ASSUME_TAC o (ONCE_REWRITE_RULE [EQ_SYM_EQ])) \\
5424         ASM_SIMP_TAC std_ss [GSYM extreal_le_eq]) >> Rewr' \\
5425     REWRITE_TAC [BOREL_MEASURABLE_SETS_CC])
5426 (* BIGUNION *)
5427 >- (SIMP_TAC std_ss [Once EXTENSION, m_space_def, ext_lborel_def, IN_UNIV] \\
5428     SIMP_TAC std_ss [IN_BIGUNION, GSPECIFICATION, IN_INSERT, SPACE_BOREL, IN_UNIV] \\
5429     GEN_TAC >> ASSUME_TAC REAL_IN_LINE \\
5430     Cases_on ‘x = PosInf’
5431     >- (Q.EXISTS_TAC ‘{NegInf; PosInf}’ >> rw []) \\
5432     Cases_on ‘x = NegInf’
5433     >- (Q.EXISTS_TAC ‘{NegInf; PosInf}’ >> rw []) \\
5434    ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] >> POP_ORW \\
5435     Q.PAT_X_ASSUM ‘!x. ?n. x IN line n’ (STRIP_ASSUME_TAC o Q.SPEC `r`) \\
5436     Q.EXISTS_TAC ‘IMAGE Normal (line n)’ \\
5437     CONJ_TAC >- (rw [IN_IMAGE]) \\
5438     DISJ2_TAC >> Q.EXISTS_TAC ‘n’ >> REWRITE_TAC [])
5439 >> rw [GSPECIFICATION, IN_UNIV, line, ext_lborel_def]
5440 >- (Know ‘real_set {NegInf; PosInf} = {}’
5441     >- (rw [Once EXTENSION, NOT_IN_EMPTY, real_set_def] >> PROVE_TAC []) >> Rewr' \\
5442     REWRITE_TAC [lambda_empty, extreal_of_num_def, extreal_not_infty])
5443 >> Know ‘real_set (IMAGE Normal {x | -&n <= x /\ x <= &n}) =
5444          {x | -&n <= x /\ x <= &n}’
5445 >- (rw [Once EXTENSION, real_set_def] \\
5446     EQ_TAC >> rw [] >| (* 3 subgoals *)
5447     [ (* goal 1 (of 3) *)
5448       rename1 ‘y <= &n’ >> art [real_normal],
5449       (* goal 2 (of 3) *)
5450       rename1 ‘-&n <= y’ >> art [real_normal],
5451       (* goal 3 (of 3) *)
5452       Q.EXISTS_TAC ‘Normal x’ >> rw [extreal_not_infty, real_normal] ])
5453 >> Rewr'
5454 >> `-&n <= (&n) :real` by RW_TAC real_ss []
5455 >> POP_ASSUM (MP_TAC o (SIMP_RULE list_ss [CLOSED_interval]) o
5456               (MATCH_MP lambda_closed_interval)) >> Rewr'
5457 >> REWRITE_TAC [extreal_not_infty]
5458QED
5459
5460(* NOTE: This theorem is the modern version of HVG's lborel_eqI *)
5461Theorem lambda_eq :
5462    !m. (!a b. measure m (interval [a,b]) =
5463         Normal (content (interval [a,b]))) /\ measure_space m /\
5464        (m_space m = space borel) /\ (measurable_sets m = subsets borel) ==>
5465        !s. s IN subsets borel ==> (lambda s = measure m s)
5466Proof
5467    rpt STRIP_TAC >> irule UNIQUENESS_OF_MEASURE
5468 >> qexistsl_tac [`univ(:real)`, `{interval [a,b] | T}`]
5469 >> CONJ_TAC (* INTER_STABLE *)
5470 >- (POP_ASSUM K_TAC >> RW_TAC std_ss [GSPECIFICATION] \\
5471     Cases_on `x` >> Cases_on `x'` >> fs [] \\
5472     rename1 `t = interval [c,d]` \\
5473     rename1 `s = interval [a,b]` \\
5474     REWRITE_TAC [INTER_INTERVAL] \\
5475     Q.EXISTS_TAC `(max a c, min b d)` >> rw [])
5476 >> CONJ_TAC (* lambda = measure m *)
5477 >- (POP_ASSUM K_TAC >> RW_TAC std_ss [GSPECIFICATION] \\
5478     Cases_on `x` >> fs [lambda_closed_interval_content])
5479 >> Know `{interval [a,b] | T} = IMAGE (\(a,b). {x | a <= x /\ x <= b}) UNIV`
5480 >- (RW_TAC list_ss [Once EXTENSION, GSPECIFICATION, IN_IMAGE, IN_UNIV,
5481                     CLOSED_interval] \\
5482     EQ_TAC >> rpt STRIP_TAC >| (* 2 subgoals *)
5483     [ (* goal 1 (of 2) *)
5484       Cases_on `x'` >> fs [] \\
5485       Q.EXISTS_TAC `(q,r)` >> rw [],
5486       (* goal 2 (of 2) *)
5487       Cases_on `x'` >> fs [] \\
5488       Q.EXISTS_TAC `(q,r)` >> rw [] ]) >> Rewr'
5489 >> ASM_REWRITE_TAC [SYM borel_eq_ge_le]
5490 >> CONJ_TAC (* measure_space lborel *)
5491 >- (KILL_TAC \\
5492     REWRITE_TAC [GSYM space_lborel, GSYM sets_lborel, MEASURE_SPACE_REDUCE,
5493                  measure_space_lborel])
5494 >> CONJ_TAC (* measure_space m *)
5495 >- (REWRITE_TAC [SYM space_borel] \\
5496     Q.PAT_X_ASSUM `_ = space borel` (ONCE_REWRITE_TAC o wrap o SYM) \\
5497     Q.PAT_X_ASSUM `_ = subsets borel` (ONCE_REWRITE_TAC o wrap o SYM) \\
5498     ASM_REWRITE_TAC [MEASURE_SPACE_REDUCE])
5499 >> rw [sigma_finite_def, subset_class_def, IN_UNIV, IN_FUNSET,
5500        m_space_def, measurable_sets_def, measure_def] (* subset_class *)
5501 >> Q.EXISTS_TAC `\n. {x | -&n <= x /\ x <= &n}`
5502 >> CONJ_TAC (* in closed intervals *)
5503 >- (Q.X_GEN_TAC `n` >> BETA_TAC \\
5504     Q.EXISTS_TAC `(-&n,&n)` >> SIMP_TAC std_ss [])
5505 >> CONJ_TAC (* monotonic *)
5506 >- (RW_TAC std_ss [SUBSET_DEF, GSPECIFICATION] >| (* 2 subgoals *)
5507     [ (* goal 1 (of 2) *)
5508       MATCH_MP_TAC REAL_LT_IMP_LE \\
5509       MATCH_MP_TAC REAL_LTE_TRANS >> Q.EXISTS_TAC `-&n` >> art [] \\
5510       RW_TAC real_ss [],
5511       (* goal 2 (of 2) *)
5512       MATCH_MP_TAC REAL_LT_IMP_LE \\
5513       MATCH_MP_TAC REAL_LET_TRANS >> Q.EXISTS_TAC `&n` >> art [] \\
5514       RW_TAC real_ss [] ])
5515 >> CONJ_TAC (* BIGUNION = UNIV *)
5516 >- (RW_TAC std_ss [Once EXTENSION, IN_BIGUNION_IMAGE, IN_UNIV] \\
5517    `?n. abs x <= &n` by SIMP_TAC std_ss [SIMP_REAL_ARCH] \\
5518     Q.EXISTS_TAC `n` >> SIMP_TAC real_ss [GSPECIFICATION] \\
5519     fs [ABS_BOUNDS])
5520 >> RW_TAC std_ss [GSYM lt_infty, GSYM interval]
5521 >> `-&n <= (&n :real)` by PROVE_TAC [le_int]
5522 >> ASM_SIMP_TAC std_ss [lambda_closed_interval, extreal_not_infty]
5523QED
5524
5525(* The original lborel_eqI, now proved by the above lambda_eq *)
5526Theorem lborel_eqI :
5527    !M. (!a b. measure M (interval [a,b]) = Normal (content (interval [a,b]))) /\
5528         measure_space M /\ measurable_sets M = subsets borel ==>
5529         measure_of lborel = measure_of M
5530Proof
5531    rw [GSYM sets_lborel]
5532 >> ‘measure_space lborel’ by PROVE_TAC [lborel_def]
5533 >> ‘m_space M = m_space lborel’ by PROVE_TAC [sets_eq_imp_space_eq]
5534 >> simp [measure_of_def, FUN_EQ_THM]
5535 >> Know ‘sigma_sets (m_space lborel) (measurable_sets lborel) =
5536          measurable_sets lborel’
5537 >- (MATCH_MP_TAC sigma_sets_fixpoint \\
5538     rw [SIGMA_ALGEBRA_BOREL, lborel_def])
5539 >> Rewr'
5540 >> Q.X_GEN_TAC ‘s’
5541 >> Cases_on ‘s IN measurable_sets lborel’ >> simp []
5542 >> Q.PAT_ASSUM ‘m_space M = m_space lborel’ (REWRITE_TAC o wrap o SYM)
5543 >> Q.PAT_ASSUM ‘measurable_sets M = measurable_sets lborel’
5544      (REWRITE_TAC o wrap o SYM)
5545 >> REWRITE_TAC [MEASURE_SPACE_REDUCE]
5546 >> simp [Once EQ_SYM_EQ]
5547 >> irule lambda_eq >> fs [m_space_lborel, sets_lborel]
5548QED
5549
5550(* ------------------------------------------------------------------------- *)
5551(*  Almost everywhere (a.e.) - basic binder definitions                      *)
5552(* ------------------------------------------------------------------------- *)
5553
5554Definition almost_everywhere_def:
5555    almost_everywhere m P = ?N. null_set m N /\ !x. x IN (m_space m DIFF N) ==> P x
5556End
5557
5558(* This binder syntax is learnt from Thomas Tuerk. ‘lborel’ is a required
5559   household measure space for `AE x. P x` without `::m`, but it's never used.
5560 *)
5561Definition AE_def :
5562    $AE = \P. almost_everywhere lborel P
5563End
5564
5565val _ = set_fixity "AE" Binder;
5566val _ = associate_restriction ("AE", "almost_everywhere");
5567
5568(* LATIN CAPITAL LETTER AE (doesn't look good)
5569val _ = Unicode.unicode_version {u = UTF8.chr 0x00C6, tmnm = "AE"};
5570 *)
5571
5572Theorem AE_THM :
5573    !m P. (AE x::m. P x) <=> almost_everywhere m P
5574Proof
5575    SIMP_TAC std_ss [almost_everywhere_def]
5576QED
5577
5578Theorem AE_DEF :
5579    !m P. (AE x::m. P x) <=>
5580          ?N. null_set m N /\ !x. x IN (m_space m DIFF N) ==> P x
5581Proof
5582    rw [AE_THM, almost_everywhere_def]
5583QED
5584
5585Theorem AE_ALT :
5586    !m P. (AE x::m. P x) <=>
5587          ?N. null_set m N /\ {x | x IN m_space m /\ ~P x} SUBSET N
5588Proof
5589    RW_TAC std_ss [AE_DEF, SUBSET_DEF, GSPECIFICATION, IN_DIFF]
5590 >> METIS_TAC []
5591QED
5592
5593Theorem AE_filter : (* was: AE + ae_filter *)
5594    !m P. (AE x::m. P x) <=>
5595          ?N. N IN null_set m /\ {x | x IN m_space m /\ x NOTIN P} SUBSET N
5596Proof
5597    RW_TAC std_ss [AE_ALT]
5598 >> EQ_TAC >> rpt STRIP_TAC >> Q.EXISTS_TAC `N` (* 2 subgoals, same tactics *)
5599 >> fs [IN_APP]
5600QED
5601
5602Theorem FORALL_IMP_AE :
5603    !m P. measure_space m /\ (!x. x IN m_space m ==> P x) ==> AE x::m. P x
5604Proof
5605    RW_TAC std_ss [AE_DEF]
5606 >> Q.EXISTS_TAC `{}`
5607 >> RW_TAC std_ss [NULL_SET_EMPTY, IN_DIFF, NOT_IN_EMPTY]
5608QED
5609
5610(* ------------------------------------------------------------------------- *)
5611(* Some Useful Theorems about Almost everywhere (ported by Waqar Ahmed)      *)
5612(* ------------------------------------------------------------------------- *)
5613
5614Theorem AE_I :
5615    !N M P. null_set M N ==> {x | x IN m_space M /\ ~P x} SUBSET N ==>
5616            AE x::M. P x
5617Proof
5618  RW_TAC std_ss [] THEN
5619  FULL_SIMP_TAC std_ss [AE_ALT, almost_everywhere_def, null_set_def] THEN
5620  FULL_SIMP_TAC std_ss [SUBSET_DEF, GSPECIFICATION] THEN METIS_TAC []
5621QED
5622
5623Theorem AE_iff_null :
5624    !M P. measure_space M /\
5625          {x | x IN m_space M /\ ~P x} IN measurable_sets M ==>
5626          ((AE x::M. P x) <=> (null_set M {x | x IN m_space M /\ ~P x}))
5627Proof
5628  RW_TAC std_ss [AE_ALT, null_set_def, GSPECIFICATION] THEN EQ_TAC THEN
5629  RW_TAC std_ss [] THENL [ALL_TAC, METIS_TAC [SUBSET_REFL]] THEN
5630  Q_TAC SUFF_TAC `measure M {x | x IN m_space M /\ ~P x} <=
5631                  measure M N` THENL
5632  [DISCH_TAC THEN ONCE_REWRITE_TAC [GSYM le_antisym] THEN
5633   METIS_TAC [measure_space_def, positive_def], ALL_TAC] THEN
5634  MATCH_MP_TAC INCREASING THEN METIS_TAC [MEASURE_SPACE_INCREASING]
5635QED
5636
5637(* NOTE: changed ‘{x | ~N x} x’ to ‘~N x’ *)
5638Theorem AE_iff_null_sets :
5639    !N M. measure_space M /\ N IN measurable_sets M ==>
5640         (null_set M N <=> AE x::M. ~N x)
5641Proof
5642    rpt STRIP_TAC
5643 >> EQ_TAC >> RW_TAC std_ss [AE_ALT, null_set_def]
5644 >- (Q.EXISTS_TAC ‘N’ >> rw [SUBSET_DEF, IN_DEF])
5645 >> fs [SUBSET_DEF]
5646 >> Suff ‘measure M N <= measure M N'’
5647 >- (DISCH_TAC >> ONCE_REWRITE_TAC [GSYM le_antisym] \\
5648     METIS_TAC [measure_space_def, positive_def])
5649 >> MATCH_MP_TAC INCREASING
5650 >> ASM_SIMP_TAC std_ss [MEASURE_SPACE_INCREASING]
5651 >> ‘N SUBSET m_space M’ by METIS_TAC [MEASURABLE_SETS_SUBSET_SPACE]
5652 >> fs [SUBSET_DEF, IN_DEF]
5653QED
5654
5655Theorem AE_NOT_IN :
5656    !N M. null_set M N ==> AE x::M. x NOTIN N
5657Proof
5658    RW_TAC std_ss [AE_ALT]
5659 >> Q.EXISTS_TAC ‘N’
5660 >> ASM_SIMP_TAC std_ss [SUBSET_DEF, GSPECIFICATION, IN_DEF]
5661QED
5662
5663(* |- !N M. null_set M N ==> AE x::M. ~N x
5664
5665   NOTE: changed ‘{x | ~N x} x’ to ‘~N x’
5666 *)
5667Theorem AE_not_in = SIMP_RULE std_ss [IN_DEF] AE_NOT_IN
5668
5669Theorem AE_iff_measurable :
5670    !N M P. measure_space M /\ N IN measurable_sets M /\
5671            ({x | x IN m_space M /\ ~P x} = N) ==>
5672            ((AE x::M. P x) <=> (measure M N = 0))
5673Proof
5674  RW_TAC std_ss [AE_ALT, GSPECIFICATION] THEN
5675  EQ_TAC THEN RW_TAC std_ss [] THENL
5676  [FULL_SIMP_TAC std_ss [null_set_def, GSPECIFICATION] THEN
5677   Q_TAC SUFF_TAC `measure M {x | x IN m_space M /\ ~P x} <= measure M N'` THENL
5678   [DISCH_TAC THEN ONCE_REWRITE_TAC [GSYM le_antisym] THEN
5679    METIS_TAC [measure_space_def, positive_def], ALL_TAC] THEN
5680   MATCH_MP_TAC INCREASING THEN ASM_SIMP_TAC std_ss [MEASURE_SPACE_INCREASING],
5681   ALL_TAC] THEN
5682  FULL_SIMP_TAC std_ss [null_set_def, GSPECIFICATION] THEN
5683  METIS_TAC [SUBSET_REFL]
5684QED
5685
5686(* Quantifier movement conversions for AE *)
5687Theorem RIGHT_IMP_AE_THM : (* was: AE_impl *)
5688    !m P Q. measure_space m ==> ((P ==> AE x::m. Q x) <=> (AE x::m. P ==> Q x))
5689Proof
5690    rpt STRIP_TAC
5691 >> EQ_TAC >> RW_TAC bool_ss [AE_DEF]
5692 >- (Cases_on ‘P’ >- (fs [] >> Q.EXISTS_TAC ‘N’ >> rw []) \\
5693     rw [] >> Q.EXISTS_TAC ‘{}’ \\
5694     MATCH_MP_TAC NULL_SET_EMPTY >> art [])
5695 >> Q.EXISTS_TAC ‘N’ >> rw []
5696QED
5697
5698Theorem RIGHT_IMP_AE_THM' : (* was: AE_all_S *)
5699    !m P Q. measure_space m ==>
5700           ((!i. P i ==> AE x::m. Q i x) <=> (!i. AE x::m. P i ==> Q i x))
5701Proof
5702    rpt STRIP_TAC
5703 >> reverse EQ_TAC >> RW_TAC bool_ss [AE_DEF]
5704 >- (Q.PAT_X_ASSUM ‘!i. _’ (MP_TAC o Q.SPEC ‘i’) >> STRIP_TAC \\
5705     Q.EXISTS_TAC ‘N’ >> rw [])
5706 >> Cases_on ‘P i’
5707 >- (Q.PAT_X_ASSUM ‘!i. _’ (MP_TAC o Q.SPEC ‘i’) >> STRIP_TAC \\
5708     POP_ASSUM MP_TAC >> RW_TAC bool_ss [])
5709 >> rw [] >> Q.EXISTS_TAC ‘{}’
5710 >> MATCH_MP_TAC NULL_SET_EMPTY >> art []
5711QED
5712
5713(* Fixed statements by checking Isabelle's Measure_Space.thy *)
5714Theorem AE_FORALL_SWAP_THM : (* was: AE_all_countable *)
5715    !m P. measure_space m /\ countable univ(:'index) ==>
5716         ((AE x::m. !i. P i x) <=> !(i:'index). AE x::m. P i x)
5717Proof
5718    rpt STRIP_TAC
5719 >> EQ_TAC >> rw [AE_DEF] >- (Q.EXISTS_TAC `N` >> rw [])
5720 >> fs [SKOLEM_THM] (* this assert ‘f’ *)
5721 >> fs [COUNTABLE_ENUM]
5722 >> rename1 ‘IMAGE g univ(:num) = univ(:'index)’
5723 >> Q.EXISTS_TAC ‘BIGUNION (IMAGE (f o g) univ(:num))’
5724 >> CONJ_TAC
5725 >- (MATCH_MP_TAC (REWRITE_RULE [IN_APP] NULL_SET_BIGUNION) >> rw [o_DEF])
5726 >> rw [IN_BIGUNION]
5727 >> Q.PAT_X_ASSUM ‘!i. null_set m (f i) /\ _’ (MP_TAC o (Q.SPEC ‘i’))
5728 >> RW_TAC std_ss []
5729 >> FIRST_X_ASSUM MATCH_MP_TAC >> RW_TAC std_ss []
5730 >> CCONTR_TAC >> fs []
5731 >> Q.PAT_X_ASSUM ‘!s. x NOTIN s \/ _’ (MP_TAC o (Q.SPEC ‘f (i :'index)’))
5732 >> RW_TAC std_ss []
5733 >> Q.PAT_X_ASSUM ‘IMAGE g univ(:num) = univ(:'index)’ MP_TAC
5734 >> rw [Once EXTENSION]
5735 >> METIS_TAC []
5736QED
5737
5738(* NOTE: the need of complete measure space is necessary if P is a generic property.
5739   This is confirmed with Prof. Massimo Campanino (University of Bologna, Italy):
5740
5741   "If P is a generic property, as you say this set is not necessarily measurable."
5742 *)
5743Theorem AE_IMP_MEASURABLE_SETS :
5744    !m P. complete_measure_space m /\ (AE x::m. P x) ==>
5745          {x | x IN m_space m /\ P x} IN measurable_sets m
5746Proof
5747    RW_TAC std_ss [complete_measure_space_def]
5748 >> fs [AE_ALT]
5749 >> ‘{x | x IN m_space m /\ P x} = m_space m DIFF {x | x IN m_space m /\ ~P x}’
5750      by SET_TAC [] >> POP_ORW
5751 >> MATCH_MP_TAC MEASURE_SPACE_COMPL >> art []
5752 >> FIRST_X_ASSUM irule
5753 >> Q.EXISTS_TAC ‘N’ >> art []
5754QED
5755
5756(* NOTE: the need of complete measure space is necessary.
5757   This is confirmed with Prof. Massimo Campanino (University of Bologna, Italy):
5758
5759   "No, in general g is not measurable."
5760 *)
5761Theorem IN_MEASURABLE_BOREL_AE_EQ :
5762    !m f g. complete_measure_space m /\ (AE x::m. f x = g x) /\
5763            f IN measurable (m_space m,measurable_sets m) Borel ==>
5764            g IN measurable (m_space m,measurable_sets m) Borel
5765Proof
5766    rpt STRIP_TAC
5767 (* complete_measure_space is used here indirectly *)
5768 >> ‘{x | x IN m_space m /\ (f x = g x)} IN measurable_sets m’
5769      by METIS_TAC [AE_IMP_MEASURABLE_SETS]
5770 >> fs [complete_measure_space_def, AE_ALT, IN_MEASURABLE_BOREL, IN_FUNSET]
5771 >> ‘N IN measurable_sets m’ by PROVE_TAC [null_set_def]
5772 >> GEN_TAC
5773 >> ‘{x | g x < Normal c} = {x | g x < Normal c /\ (f x = g x)} UNION
5774                            {x | g x < Normal c /\ (f x <> g x)}’
5775      by SET_TAC [] >> POP_ORW
5776 >> ‘{x | g x < Normal c /\ (f x = g x)} = {x | f x < Normal c /\ (f x = g x)}’
5777      by SET_TAC [] >> POP_ORW
5778 >> ‘({x | f x < Normal c /\ f x = g x} UNION
5779      {x | g x < Normal c /\ f x <> g x}) INTER m_space m =
5780     ({x | f x < Normal c /\ f x = g x} INTER m_space m) UNION
5781     ({x | g x < Normal c /\ f x <> g x} INTER m_space m)’
5782      by SET_TAC [] >> POP_ORW
5783 >> MATCH_MP_TAC MEASURE_SPACE_UNION >> art []
5784 (* complete_measure_space is used in this branch *)
5785 >> reverse CONJ_TAC
5786 >- (FIRST_X_ASSUM irule >> Q.EXISTS_TAC ‘N’ >> art [] \\
5787     MATCH_MP_TAC SUBSET_TRANS \\
5788     Q.EXISTS_TAC ‘{x | x IN m_space m /\ f x <> g x}’ >> art [] \\
5789     SET_TAC [])
5790 >> ‘{x | f x < Normal c /\ f x = g x} INTER m_space m =
5791     ({x | f x < Normal c} INTER m_space m) INTER {x | x IN m_space m /\ (f x = g x)}’
5792      by SET_TAC [] >> POP_ORW
5793 >> MATCH_MP_TAC MEASURE_SPACE_INTER >> art []
5794 >> ‘sigma_algebra (measurable_space m)’ by PROVE_TAC [measure_space_def]
5795 >> fs [IN_MEASURABLE_BOREL]
5796QED
5797
5798(* ------------------------------------------------------------------------- *)
5799(*   Unconditional IN_MEASURABLE_BOREL_ADD and IN_MEASURABLE_BOREL_SUB       *)
5800(*   (Author: Chun Tian)                                                     *)
5801(* ------------------------------------------------------------------------- *)
5802
5803(* |- !s t u. (t UNION u) INTER s = t INTER s UNION u INTER s *)
5804val UNION_OVER_INTER' = ONCE_REWRITE_RULE [INTER_COMM] UNION_OVER_INTER;
5805
5806val IN_MEASURABLE_BOREL_ADD_tactics_1 =
5807    Know ‘{x | ?r. f x + g x = Normal r /\ r IN B} INTER space a =
5808          {x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
5809               ?r. rf x + rg x = r /\ r IN B} INTER space a’
5810 >- (rw [Once EXTENSION] >> EQ_TAC
5811     >- (STRIP_TAC \\
5812         Know ‘f x <> PosInf’
5813         >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] >> rfs []) \\
5814         Know ‘f x <> NegInf’
5815         >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] >> rfs []) \\
5816         Know ‘g x <> PosInf’
5817         >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def] >> rfs []) \\
5818         Know ‘g x <> NegInf’
5819         >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def] >> rfs []) \\
5820         NTAC 4 STRIP_TAC >> art [] \\
5821        ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
5822        ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
5823        ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
5824        ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
5825         fs [extreal_add_def]) \\
5826     STRIP_TAC >> art [] \\
5827     Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
5828     rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
5829     simp [normal_real])
5830 >> Rewr'
5831 >> ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
5832          ?r. rf x + rg x = r /\ r IN B} INTER space a =
5833      ({x | ?r. rf x + rg x = r /\ r IN B} INTER space a) INTER
5834      ({x | f x <> PosInf} INTER space a) INTER
5835      ({x | f x <> NegInf} INTER space a) INTER
5836      ({x | g x <> PosInf} INTER space a) INTER
5837      ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW
5838 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
5839 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [])
5840 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
5841 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [])
5842 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
5843 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [])
5844 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
5845 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [])
5846 >> Q.ABBREV_TAC ‘h = \x. rf x + rg x’
5847 >> Know ‘{x | ?r. rf x + rg x = r /\ r IN B} = PREIMAGE h B’
5848 >- rw [PREIMAGE_def, Abbr ‘h’] >> Rewr'
5849 >> Suff ‘h IN measurable a borel’ >- rw [IN_MEASURABLE]
5850 >> MATCH_MP_TAC in_borel_measurable_add
5851 >> qexistsl_tac [‘rf’, ‘rg’] >> simp []
5852 >> CONJ_TAC (* 2 subgoals *)
5853 >| [ (* goal 1.1 (of 2) *)
5854      Q.UNABBREV_TAC ‘rf’ \\
5855      MATCH_MP_TAC in_borel_measurable_from_Borel >> art [],
5856      (* goal 1.2 (of 2) *)
5857      Q.UNABBREV_TAC ‘rg’ \\
5858      MATCH_MP_TAC in_borel_measurable_from_Borel >> art [] ];
5859
5860val IN_MEASURABLE_BOREL_ADD_tactics_3 =
5861    rename1 ‘NegInf + PosInf = Normal z’
5862 >> Know ‘{x | ?r. f x + g x = Normal r /\ r IN B} INTER space a =
5863          if z IN B then
5864            ({x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
5865                  ?r. rf x + rg x = r /\ r IN B} INTER space a) UNION
5866            ({x | f x = NegInf /\ g x = PosInf} INTER space a)
5867          else
5868            ({x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
5869                  ?r. rf x + rg x = r /\ r IN B} INTER space a)’
5870 >- (Cases_on ‘z IN B’ >> rw [Once EXTENSION] >| (* 2 subgoal *)
5871     [ (* goal 3.1 (of 2) *)
5872       EQ_TAC >> STRIP_TAC >| (* 3 subgoals *)
5873       [ (* goal 3.1.1 (of 3) *)
5874         Know ‘f x <> PosInf’
5875         >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] >> rfs []) \\
5876         Know ‘g x <> NegInf’
5877         >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def] >> rfs []) \\
5878         NTAC 2 STRIP_TAC >> simp [] \\
5879         Cases_on ‘f x = NegInf’
5880         >- (simp [] >> CCONTR_TAC \\
5881            ‘?y. g x = Normal y’ by METIS_TAC [extreal_cases] \\
5882             fs [extreal_add_def]) \\
5883         Cases_on ‘g x = PosInf’
5884         >- (simp [] \\
5885            ‘?y. f x = Normal y’ by METIS_TAC [extreal_cases] \\
5886             fs [extreal_add_def]) \\
5887         DISJ1_TAC >> art [] \\
5888        ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
5889        ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
5890        ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
5891        ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
5892         fs [extreal_add_def],
5893         (* goal 3.1.2 (of 3) *)
5894         simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
5895         rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
5896         simp [normal_real],
5897         (* goal 3.1.3 (of 3) *)
5898         simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] ],
5899       (* goal 3.2 (of 2) *)
5900       EQ_TAC >> STRIP_TAC >| (* 2 subgoals *)
5901       [ (* goal 3.2.1 (of 2) *)
5902         simp [] \\
5903         Know ‘f x <> PosInf’
5904         >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] >> rfs []) \\
5905         Know ‘g x <> NegInf’
5906         >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def] >> rfs []) \\
5907         NTAC 2 STRIP_TAC >> simp [] \\
5908         STRONG_CONJ_TAC
5909         >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] \\
5910             METIS_TAC [extreal_11]) >> DISCH_TAC \\
5911         STRONG_CONJ_TAC
5912         >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
5913         DISCH_TAC \\
5914        ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
5915        ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
5916        ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
5917        ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
5918         fs [extreal_add_def],
5919         (* goal 3.2.2 (of 2) *)
5920         simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
5921         rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
5922         simp [normal_real] ] ])
5923 >> Rewr'
5924 (* stage work *)
5925 >> Know ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
5926               ?r. rf x + rg x = r /\ r IN B} INTER space a IN subsets a’
5927 >- (‘{x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
5928           ?r. rf x + rg x = r /\ r IN B} INTER space a =
5929       ({x | ?r. rf x + rg x = r /\ r IN B} INTER space a) INTER
5930       ({x | f x <> PosInf} INTER space a) INTER
5931       ({x | f x <> NegInf} INTER space a) INTER
5932       ({x | g x <> PosInf} INTER space a) INTER
5933       ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
5934     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
5935     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
5936     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
5937     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art []) \\
5938     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
5939     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
5940     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
5941     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art []) \\
5942     Q.ABBREV_TAC ‘h = \x. rf x + rg x’ \\
5943     Know ‘{x | ?r. rf x + rg x = r /\ r IN B} = PREIMAGE h B’
5944     >- rw [PREIMAGE_def, Abbr ‘h’] >> Rewr' \\
5945     Suff ‘h IN measurable a borel’ >- rw [IN_MEASURABLE] \\
5946     MATCH_MP_TAC in_borel_measurable_add \\
5947     qexistsl_tac [‘rf’, ‘rg’] >> simp [] \\
5948     CONJ_TAC >| (* 2 subgoals *)
5949     [ (* goal 2.1 (of 2) *)
5950       Q.UNABBREV_TAC ‘rf’ \\
5951       MATCH_MP_TAC in_borel_measurable_from_Borel >> art [],
5952       (* goal 2.2 (of 2) *)
5953       Q.UNABBREV_TAC ‘rg’ \\
5954       MATCH_MP_TAC in_borel_measurable_from_Borel >> art [] ])
5955 >> DISCH_TAC
5956 >> Cases_on ‘z IN B’ >> fs []
5957 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
5958 >> ‘{x | f x = NegInf /\ g x = PosInf} INTER space a =
5959      ({x | f x = NegInf} INTER space a) INTER
5960      ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW
5961 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
5962 >> CONJ_TAC (* 2 subgoals *)
5963 >| [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
5964      MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ];
5965
5966val IN_MEASURABLE_BOREL_ADD_tactics_7 =
5967    rename1 ‘PosInf + NegInf = Normal z’
5968 >> Know ‘{x | ?r. f x + g x = Normal r /\ r IN B} INTER space a =
5969          if z IN B then
5970             ({x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
5971                   ?r. rf x + rg x = r /\ r IN B} INTER space a) UNION
5972             ({x | f x = PosInf /\ g x = NegInf} INTER space a)
5973          else
5974             ({x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
5975                   ?r. rf x + rg x = r /\ r IN B} INTER space a)’
5976 >- (Cases_on ‘z IN B’ >> rw [Once EXTENSION] >| (* 2 subgoal *)
5977     [ (* goal 7.1 (of 2) *)
5978       EQ_TAC >> STRIP_TAC >| (* 3 subgoals *)
5979       [ (* goal 7.1.1 (of 3) *)
5980         Know ‘f x <> NegInf’
5981         >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] >> rfs []) \\
5982         Know ‘g x <> PosInf’
5983         >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def] >> rfs []) \\
5984         NTAC 2 STRIP_TAC >> simp [] \\
5985         Cases_on ‘f x = PosInf’
5986         >- (simp [] >> CCONTR_TAC \\
5987            ‘?y. g x = Normal y’ by METIS_TAC [extreal_cases] \\
5988             fs [extreal_add_def]) \\
5989         Cases_on ‘g x = NegInf’
5990         >- (simp [] \\
5991            ‘?y. f x = Normal y’ by METIS_TAC [extreal_cases] \\
5992             fs [extreal_add_def]) \\
5993         DISJ1_TAC >> art [] \\
5994        ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
5995        ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
5996        ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
5997        ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
5998         fs [extreal_add_def],
5999         (* goal 7.1.2 (of 3) *)
6000         simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
6001         rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
6002         simp [normal_real],
6003         (* goal 7.1.3 (of 3) *)
6004         simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] ],
6005       (* goal 7.2 (of 2) *)
6006       EQ_TAC >> STRIP_TAC >| (* 2 subgoals *)
6007       [ (* goal 7.2.1 (of 2) *)
6008         simp [] \\
6009         Know ‘f x <> NegInf’
6010         >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] >> rfs []) \\
6011         Know ‘g x <> PosInf’
6012         >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def] >> rfs []) \\
6013         NTAC 2 STRIP_TAC >> simp [] \\
6014         STRONG_CONJ_TAC
6015         >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] \\
6016             METIS_TAC [extreal_11]) >> DISCH_TAC \\
6017         STRONG_CONJ_TAC
6018         >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
6019         DISCH_TAC \\
6020        ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
6021        ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
6022        ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
6023        ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
6024         fs [extreal_add_def],
6025         (* goal 3.2.2 (of 2) *)
6026         simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
6027         rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
6028         simp [normal_real] ] ])
6029 >> Rewr'
6030 (* stage work *)
6031 >> Know ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
6032               ?r. rf x + rg x = r /\ r IN B} INTER space a IN subsets a’
6033 >- (‘{x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
6034           ?r. rf x + rg x = r /\ r IN B} INTER space a =
6035      ({x | ?r. rf x + rg x = r /\ r IN B} INTER space a) INTER
6036      ({x | f x <> PosInf} INTER space a) INTER
6037      ({x | f x <> NegInf} INTER space a) INTER
6038      ({x | g x <> PosInf} INTER space a) INTER
6039      ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6040     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6041     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6042     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6043     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art []) \\
6044     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6045     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6046     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6047     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art []) \\
6048     Q.ABBREV_TAC ‘h = \x. rf x + rg x’ \\
6049     Know ‘{x | ?r. rf x + rg x = r /\ r IN B} = PREIMAGE h B’
6050     >- (rw [PREIMAGE_def, Abbr ‘h’]) >> Rewr' \\
6051     Suff ‘h IN measurable a borel’ >- rw [IN_MEASURABLE] \\
6052     MATCH_MP_TAC in_borel_measurable_add \\
6053     qexistsl_tac [‘rf’, ‘rg’] >> simp [] \\
6054     CONJ_TAC >| (* 2 subgoals *)
6055     [ (* goal 2.1 (of 2) *)
6056       Q.UNABBREV_TAC ‘rf’ \\
6057       MATCH_MP_TAC in_borel_measurable_from_Borel >> art [],
6058       (* goal 2.2 (of 2) *)
6059       Q.UNABBREV_TAC ‘rg’ \\
6060       MATCH_MP_TAC in_borel_measurable_from_Borel >> art [] ])
6061 >> DISCH_TAC
6062 >> Cases_on ‘z IN B’ >> fs []
6063 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6064 >> ‘{x | f x = PosInf /\ g x = NegInf} INTER space a =
6065      ({x | f x = PosInf} INTER space a) INTER
6066      ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW
6067 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6068 >> CONJ_TAC (* 2 subgoals *)
6069 >| [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6070      MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ];
6071
6072val IN_MEASURABLE_BOREL_ADD_tactics_1p =
6073    Know ‘{x | f x + g x = PosInf} INTER space a =
6074           ({x | f x = PosInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a) UNION
6075           ({x | f x <> PosInf /\ f x <> NegInf /\ g x = PosInf} INTER space a) UNION
6076           ({x | f x = PosInf /\ g x = PosInf} INTER space a)’
6077 >- (rw [Once EXTENSION] \\
6078     EQ_TAC >> rpt STRIP_TAC >> rw [extreal_add_def] >| (* 3 subgoals left *)
6079     [ (* goal 1.1 (of 3) *)
6080       Cases_on ‘f x = PosInf’ >> simp []
6081       >- (Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6082       STRONG_CONJ_TAC >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6083       DISCH_TAC \\
6084      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6085       Cases_on ‘g x’ >> fs [extreal_add_def],
6086       (* goal 1.2 (of 3) *)
6087      ‘?r. g x = Normal r’ by METIS_TAC [extreal_cases] \\
6088       rw [extreal_add_def],
6089       (* goal 1.3 (of 3) *)
6090      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6091       rw [extreal_add_def] ])
6092 >> Rewr'
6093 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6094 >> reverse CONJ_TAC
6095 >- (‘{x | f x = PosInf /\ g x = PosInf} INTER space a =
6096       ({x | f x = PosInf} INTER space a) INTER
6097       ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6098     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6099     CONJ_TAC >|
6100     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6101       MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ])
6102 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6103 >> CONJ_TAC
6104 >- (‘{x | f x = PosInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a =
6105       ({x | f x = PosInf} INTER space a) INTER
6106       ({x | g x <> PosInf} INTER space a) INTER
6107       ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6108     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6109     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6110     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6111     CONJ_TAC >|
6112     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6113       MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [] ])
6114 >> ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x = PosInf} INTER space a =
6115      ({x | f x <> PosInf} INTER space a) INTER
6116      ({x | f x <> NegInf} INTER space a) INTER
6117      ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW
6118 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6119 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [])
6120 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6121 >> CONJ_TAC
6122 >| [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [],
6123      MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [] ];
6124
6125val IN_MEASURABLE_BOREL_ADD_tactics_2p =
6126    Know ‘{x | f x + g x = PosInf} INTER space a =
6127           ({x | f x = PosInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a) UNION
6128           ({x | f x <> PosInf /\ f x <> NegInf /\ g x = PosInf} INTER space a) UNION
6129           ({x | f x = PosInf /\ g x = PosInf} INTER space a) UNION
6130           ({x | f x = NegInf /\ g x = PosInf} INTER space a)’
6131 >- (rw [Once EXTENSION] \\
6132     EQ_TAC >> rpt STRIP_TAC >> rw [extreal_add_def] >| (* 3 subgoals left *)
6133     [ (* goal 2.1 (of 3) *)
6134       Cases_on ‘f x = PosInf’ >> simp []
6135       >- (Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6136       Suff ‘g x = PosInf’ >- PROVE_TAC [] \\
6137       CCONTR_TAC \\
6138       Cases_on ‘f x’ >> Cases_on ‘g x’ >> fs [extreal_add_def],
6139       (* goal 2.2 (of 3) *)
6140      ‘?r. g x = Normal r’ by METIS_TAC [extreal_cases] \\
6141       rw [extreal_add_def],
6142       (* goal 2.3 (of 3) *)
6143      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6144       rw [extreal_add_def] ])
6145 >> Rewr'
6146 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6147 >> reverse CONJ_TAC
6148 >- (‘{x | f x = NegInf /\ g x = PosInf} INTER space a =
6149       ({x | f x = NegInf} INTER space a) INTER
6150       ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6151     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6152     CONJ_TAC >|
6153     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6154       MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ])
6155 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6156 >> reverse CONJ_TAC
6157 >- (‘{x | f x = PosInf /\ g x = PosInf} INTER space a =
6158       ({x | f x = PosInf} INTER space a) INTER
6159       ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6160     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6161     CONJ_TAC >|
6162     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6163       MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ])
6164 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6165 >> CONJ_TAC
6166 >- (‘{x | f x = PosInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a =
6167       ({x | f x = PosInf} INTER space a) INTER
6168       ({x | g x <> PosInf} INTER space a) INTER
6169       ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6170     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6171     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6172     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6173     CONJ_TAC >|
6174     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6175       MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [] ])
6176 >> ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x = PosInf} INTER space a =
6177      ({x | f x <> PosInf} INTER space a) INTER
6178      ({x | f x <> NegInf} INTER space a) INTER
6179      ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW
6180 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6181 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [])
6182 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6183 >> CONJ_TAC
6184 >| [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [],
6185      MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [] ];
6186
6187val IN_MEASURABLE_BOREL_ADD_tactics_4p =
6188    Know ‘{x | f x + g x = PosInf} INTER space a =
6189           ({x | f x = PosInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a) UNION
6190           ({x | f x <> PosInf /\ f x <> NegInf /\ g x = PosInf} INTER space a) UNION
6191           ({x | f x = PosInf /\ g x = PosInf} INTER space a) UNION
6192           ({x | f x = PosInf /\ g x = NegInf} INTER space a)’
6193 >- (rw [Once EXTENSION] \\
6194     EQ_TAC >> rpt STRIP_TAC >> rw [extreal_add_def] >| (* 3 subgoals left *)
6195     [ (* goal 4.1 (of 3) *)
6196       Cases_on ‘f x = PosInf’ >> simp []
6197       >- (Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6198       STRONG_CONJ_TAC >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6199       DISCH_TAC \\
6200      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6201       CCONTR_TAC \\
6202       Cases_on ‘g x’ >> fs [extreal_add_def],
6203       (* goal 4.2 (of 3) *)
6204      ‘?r. g x = Normal r’ by METIS_TAC [extreal_cases] \\
6205       rw [extreal_add_def],
6206       (* goal 4.3 (of 3) *)
6207      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6208       rw [extreal_add_def] ])
6209 >> Rewr'
6210 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6211 >> reverse CONJ_TAC
6212 >- (‘{x | f x = PosInf /\ g x = NegInf} INTER space a =
6213       ({x | f x = PosInf} INTER space a) INTER
6214       ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6215     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6216     CONJ_TAC >|
6217     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6218       MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ])
6219 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6220 >> reverse CONJ_TAC
6221 >- (‘{x | f x = PosInf /\ g x = PosInf} INTER space a =
6222       ({x | f x = PosInf} INTER space a) INTER
6223       ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6224     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6225     CONJ_TAC >|
6226     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6227       MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ])
6228 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6229 >> CONJ_TAC
6230 >- (‘{x | f x = PosInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a =
6231       ({x | f x = PosInf} INTER space a) INTER
6232       ({x | g x <> PosInf} INTER space a) INTER
6233       ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6234     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6235     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6236     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6237     CONJ_TAC >|
6238     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6239       MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [] ])
6240 >> ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x = PosInf} INTER space a =
6241      ({x | f x <> PosInf} INTER space a) INTER
6242      ({x | f x <> NegInf} INTER space a) INTER
6243      ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW
6244 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6245 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [])
6246 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6247 >> CONJ_TAC
6248 >| [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [],
6249      MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [] ];
6250
6251val IN_MEASURABLE_BOREL_ADD_tactics_2n =
6252    Know ‘{x | f x + g x = NegInf} INTER space a =
6253               ({x | f x = NegInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a) UNION
6254               ({x | f x <> PosInf /\ f x <> NegInf /\ g x = NegInf} INTER space a) UNION
6255               ({x | f x = NegInf /\ g x = NegInf} INTER space a) UNION
6256               ({x | f x = PosInf /\ g x = NegInf} INTER space a)’
6257 >- (rw [Once EXTENSION] \\
6258     EQ_TAC >> rpt STRIP_TAC >> rw [extreal_add_def] >| (* 3 subgoals left *)
6259     [ (* goal 2.1 (of 3) *)
6260       Cases_on ‘f x = NegInf’ >> simp []
6261       >- (Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6262       Suff ‘g x = NegInf’ >- PROVE_TAC [] \\
6263       CCONTR_TAC \\
6264       Cases_on ‘f x’ >> Cases_on ‘g x’ >> fs [extreal_add_def],
6265       (* goal 2.2 (of 3) *)
6266      ‘?r. g x = Normal r’ by METIS_TAC [extreal_cases] \\
6267       rw [extreal_add_def],
6268       (* goal 2.3 (of 3) *)
6269      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6270       rw [extreal_add_def] ])
6271 >> Rewr'
6272 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6273 >> reverse CONJ_TAC
6274 >- (‘{x | f x = PosInf /\ g x = NegInf} INTER space a =
6275       ({x | f x = PosInf} INTER space a) INTER
6276       ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6277     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6278     CONJ_TAC >|
6279     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6280       MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ])
6281 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6282 >> reverse CONJ_TAC
6283 >- (‘{x | f x = NegInf /\ g x = NegInf} INTER space a =
6284       ({x | f x = NegInf} INTER space a) INTER
6285       ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6286     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6287     CONJ_TAC >|
6288     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6289       MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ])
6290 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6291 >> CONJ_TAC
6292 >- (‘{x | f x = NegInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a =
6293       ({x | f x = NegInf} INTER space a) INTER
6294       ({x | g x <> PosInf} INTER space a) INTER
6295       ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6296     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6297     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6298     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6299     CONJ_TAC >|
6300     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6301       MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [] ])
6302 >> ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x = NegInf} INTER space a =
6303      ({x | f x <> PosInf} INTER space a) INTER
6304      ({x | f x <> NegInf} INTER space a) INTER
6305      ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW
6306 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6307 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [])
6308 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6309 >> CONJ_TAC
6310 >| [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [],
6311      MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [] ];
6312
6313val IN_MEASURABLE_BOREL_ADD_tactics_4n =
6314    Know ‘{x | f x + g x = NegInf} INTER space a =
6315               ({x | f x = NegInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a) UNION
6316               ({x | f x <> PosInf /\ f x <> NegInf /\ g x = NegInf} INTER space a) UNION
6317               ({x | f x = NegInf /\ g x = NegInf} INTER space a) UNION
6318               ({x | f x = NegInf /\ g x = PosInf} INTER space a)’
6319 >- (rw [Once EXTENSION] \\
6320     EQ_TAC >> rpt STRIP_TAC >> rw [extreal_add_def] >| (* 3 subgoals left *)
6321     [ (* goal 4.1 (of 3) *)
6322       Cases_on ‘f x = PosInf’ >> simp []
6323       >- (Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6324       Cases_on ‘f x = NegInf’ >> simp []
6325       >- (Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6326      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6327       CCONTR_TAC \\
6328       Cases_on ‘g x’ >> fs [extreal_add_def],
6329       (* goal 4.2 (of 3) *)
6330      ‘?r. g x = Normal r’ by METIS_TAC [extreal_cases] \\
6331       rw [extreal_add_def],
6332       (* goal 4.3 (of 3) *)
6333      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6334       rw [extreal_add_def] ])
6335 >> Rewr'
6336 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6337 >> reverse CONJ_TAC
6338 >- (‘{x | f x = NegInf /\ g x = PosInf} INTER space a =
6339       ({x | f x = NegInf} INTER space a) INTER
6340       ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6341     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6342     CONJ_TAC >|
6343     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6344       MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ])
6345 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6346 >> reverse CONJ_TAC
6347 >- (‘{x | f x = NegInf /\ g x = NegInf} INTER space a =
6348       ({x | f x = NegInf} INTER space a) INTER
6349       ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6350     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6351     CONJ_TAC >|
6352     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6353       MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ])
6354 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6355 >> CONJ_TAC
6356 >- (‘{x | f x = NegInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a =
6357       ({x | f x = NegInf} INTER space a) INTER
6358       ({x | g x <> PosInf} INTER space a) INTER
6359       ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6360     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6361     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6362     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6363     CONJ_TAC >|
6364     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6365       MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [] ])
6366 >> ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x = NegInf} INTER space a =
6367      ({x | f x <> PosInf} INTER space a) INTER
6368      ({x | f x <> NegInf} INTER space a) INTER
6369      ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW
6370 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6371 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [])
6372 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6373 >> CONJ_TAC
6374 >| [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [],
6375      MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [] ];
6376
6377val IN_MEASURABLE_BOREL_ADD_tactics_5n =
6378    Know ‘{x | f x + g x = NegInf} INTER space a =
6379           ({x | f x = NegInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a) UNION
6380           ({x | f x <> PosInf /\ f x <> NegInf /\ g x = NegInf} INTER space a) UNION
6381           ({x | f x = NegInf /\ g x = NegInf} INTER space a)’
6382 >- (rw [Once EXTENSION] \\
6383     EQ_TAC >> rpt STRIP_TAC >> rw [extreal_add_def] >| (* 3 subgoals left *)
6384     [ (* goal 1.1 (of 3) *)
6385       Cases_on ‘f x = NegInf’ >> simp []
6386       >- (Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6387       STRONG_CONJ_TAC >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6388       DISCH_TAC \\
6389      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6390       Cases_on ‘g x’ >> fs [extreal_add_def],
6391       (* goal 1.2 (of 3) *)
6392      ‘?r. g x = Normal r’ by METIS_TAC [extreal_cases] \\
6393       rw [extreal_add_def],
6394       (* goal 1.3 (of 3) *)
6395      ‘?r. f x = Normal r’ by METIS_TAC [extreal_cases] \\
6396       rw [extreal_add_def] ])
6397 >> Rewr'
6398 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6399 >> reverse CONJ_TAC
6400 >- (‘{x | f x = NegInf /\ g x = NegInf} INTER space a =
6401       ({x | f x = NegInf} INTER space a) INTER
6402       ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6403     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6404     CONJ_TAC >|
6405     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6406       MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ])
6407 >> MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []
6408 >> CONJ_TAC
6409 >- (‘{x | f x = NegInf /\ g x <> PosInf /\ g x <> NegInf} INTER space a =
6410       ({x | f x = NegInf} INTER space a) INTER
6411       ({x | g x <> PosInf} INTER space a) INTER
6412       ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6413     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6414     reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6415     MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6416     CONJ_TAC >|
6417     [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6418       MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [] ])
6419 >> ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x = NegInf} INTER space a =
6420      ({x | f x <> PosInf} INTER space a) INTER
6421      ({x | f x <> NegInf} INTER space a) INTER
6422      ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW
6423 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6424 >> reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [])
6425 >> MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art []
6426 >> CONJ_TAC
6427 >| [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art [],
6428      MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art [] ];
6429
6430Theorem IN_MEASURABLE_BOREL_ADD' : (* cf. IN_MEASURABLE_BOREL_ADD *)
6431    !a f g h. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel /\
6432              (!x. x IN space a ==> (h x = f x + g x)) ==> h IN measurable a Borel
6433Proof
6434    rpt STRIP_TAC
6435 >> rw [IN_MEASURABLE, SIGMA_ALGEBRA_BOREL, IN_FUNSET, SPACE_BOREL]
6436 >> Suff ‘(!B. B IN subsets borel ==> PREIMAGE h (IMAGE Normal B) INTER space a IN subsets a) /\
6437           PREIMAGE h {PosInf} INTER space a IN subsets a /\
6438           PREIMAGE h {NegInf} INTER space a IN subsets a’
6439 >- (STRIP_TAC \\
6440     Know ‘PREIMAGE h {NegInf; PosInf} INTER space a IN subsets a’
6441     >- (‘{NegInf; PosInf} = {NegInf} UNION {PosInf}’ by SET_TAC [] >> POP_ORW \\
6442         rw [PREIMAGE_UNION, UNION_OVER_INTER'] \\
6443         MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art []) \\
6444     DISCH_TAC \\
6445     fs [Borel, PREIMAGE_UNION, UNION_OVER_INTER'] (* 3 subgoals, same tactics *) \\
6446     MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
6447     FIRST_X_ASSUM MATCH_MP_TAC >> art [])
6448 (* PREIMAGE h (IMAGE Normal B) INTER space a IN subsets a *)
6449 >> STRONG_CONJ_TAC
6450 >- (rpt STRIP_TAC \\
6451     Q.PAT_X_ASSUM ‘s IN subsets Borel’ K_TAC (* useless *) \\
6452     rw [PREIMAGE_def] \\
6453     Know ‘{x | ?x'. h x = Normal x' /\ x' IN B} INTER space a =
6454           {x | ?r. f x + g x = Normal r /\ r IN B} INTER space a’
6455     >- (rw [Once EXTENSION] >> EQ_TAC >> rw [] \\
6456         rename1 ‘b IN B’ >> Q.EXISTS_TAC ‘b’ >> art [] \\
6457         PROVE_TAC []) >> Rewr' \\
6458     Q.PAT_X_ASSUM ‘!x. x IN space a ==> _’ K_TAC \\
6459     Q.ABBREV_TAC ‘rf = real o f’ \\
6460     Q.ABBREV_TAC ‘rg = real o g’ \\
6461     (* KEY: conditioning on infinities *)
6462     Cases_on ‘PosInf + NegInf’ >> Cases_on ‘NegInf + PosInf’ >| (* 9 subgoals *)
6463     [ (* goal 1 (of 9) *)
6464       IN_MEASURABLE_BOREL_ADD_tactics_1,
6465       (* goal 2 (of 9) *)
6466       IN_MEASURABLE_BOREL_ADD_tactics_1,
6467       (* goal 3 (of 9) *)
6468       IN_MEASURABLE_BOREL_ADD_tactics_3,
6469       (* goal 4 (of 9) *)
6470       IN_MEASURABLE_BOREL_ADD_tactics_1,
6471       (* goal 5 (of 9) *)
6472       IN_MEASURABLE_BOREL_ADD_tactics_1,
6473       (* goal 6 (of 9) *)
6474       IN_MEASURABLE_BOREL_ADD_tactics_3,
6475       (* goal 7 (of 9) *)
6476       IN_MEASURABLE_BOREL_ADD_tactics_7,
6477       (* goal 8 (of 9) *)
6478       IN_MEASURABLE_BOREL_ADD_tactics_7,
6479       (* goal 9 (of 9), the most complicated one! *)
6480       rename1 ‘PosInf + NegInf = Normal z1’ \\
6481       rename1 ‘NegInf + PosInf = Normal z2’ \\
6482       Know ‘{x | ?r. f x + g x = Normal r /\ r IN B} INTER space a =
6483             if z1 IN B /\ z2 IN B then
6484               ({x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
6485                     ?r. rf x + rg x = r /\ r IN B} INTER space a) UNION
6486               ({x | f x = PosInf /\ g x = NegInf} INTER space a) UNION
6487               ({x | f x = NegInf /\ g x = PosInf} INTER space a)
6488             else if z1 IN B then
6489               ({x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
6490                     ?r. rf x + rg x = r /\ r IN B} INTER space a) UNION
6491               ({x | f x = PosInf /\ g x = NegInf} INTER space a)
6492             else if z2 IN B then
6493               ({x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
6494                     ?r. rf x + rg x = r /\ r IN B} INTER space a) UNION
6495               ({x | f x = NegInf /\ g x = PosInf} INTER space a)
6496             else
6497               ({x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
6498                     ?r. rf x + rg x = r /\ r IN B} INTER space a)’
6499       >- (Cases_on ‘z1 IN B’ >> Cases_on ‘z2 IN B’ >> rw [Once EXTENSION] >| (* 4 subgoal *)
6500           [ (* goal 9.1 (of 4) *)
6501             EQ_TAC >> STRIP_TAC >| (* 4 subgoals *)
6502             [ (* goal 9.1.1 (of 4) *)
6503               Cases_on ‘f x = NegInf’
6504               >- (simp [] >> CCONTR_TAC \\
6505                   Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6506               Cases_on ‘g x = PosInf’
6507               >- (simp [] >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
6508               Cases_on ‘f x = PosInf’
6509               >- (simp [] >> CCONTR_TAC \\
6510                  ‘?y. g x = Normal y’ by METIS_TAC [extreal_cases] \\
6511                   fs [extreal_add_def]) \\
6512               Cases_on ‘g x = NegInf’
6513               >- (simp [] \\
6514                  ‘?y. f x = Normal y’ by METIS_TAC [extreal_cases] \\
6515                   fs [extreal_add_def]) \\
6516               DISJ1_TAC >> art [] \\
6517              ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
6518              ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
6519              ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
6520              ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
6521               fs [extreal_add_def],
6522               (* goal 9.1.2 (of 4) *)
6523               simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
6524               rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
6525               simp [normal_real],
6526               (* goal 9.1.3 (of 4) *)
6527               simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [],
6528               (* goal 9.1.4 (of 4) *)
6529               simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] ],
6530             (* goal 9.2 (of 4) *)
6531             EQ_TAC >> STRIP_TAC >| (* 3 subgoals *)
6532             [ (* goal 9.2.1 (of 3) *)
6533               simp [] \\
6534               Cases_on ‘f x = PosInf’
6535               >- (DISJ2_TAC >> art [] \\
6536                   CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6537               Cases_on ‘g x = NegInf’
6538               >- (DISJ2_TAC >> art [] \\
6539                   CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
6540               DISJ1_TAC >> art [] \\
6541               STRONG_CONJ_TAC
6542               >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] \\
6543                   METIS_TAC [extreal_11]) >> DISCH_TAC \\
6544               STRONG_CONJ_TAC
6545               >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
6546               DISCH_TAC \\
6547              ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
6548              ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
6549              ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
6550              ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
6551               fs [extreal_add_def],
6552               (* goal 9.2.2 (of 3) *)
6553               simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
6554               rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
6555               simp [normal_real],
6556               (* goal 9.2.3 (of 3) *)
6557               simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
6558               rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
6559               simp [normal_real] ],
6560             (* goal 9.3 (of 4) *)
6561             EQ_TAC >> STRIP_TAC >| (* 3 subgoals *)
6562             [ (* goal 9.3.1 (of 3) *)
6563               Cases_on ‘f x = NegInf’
6564               >- (simp [] >> CCONTR_TAC \\
6565                   Cases_on ‘g x’ >> fs [extreal_add_def]) \\
6566               Cases_on ‘g x = PosInf’
6567               >- (simp [] >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
6568               DISJ1_TAC >> art [] \\
6569               STRONG_CONJ_TAC
6570               >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] \\
6571                   METIS_TAC [extreal_11]) >> DISCH_TAC \\
6572               STRONG_CONJ_TAC
6573               >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
6574               DISCH_TAC \\
6575              ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
6576              ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
6577              ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
6578              ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
6579               fs [extreal_add_def],
6580               (* goal 9.3.2 (of 3) *)
6581               simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
6582               rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
6583               simp [normal_real],
6584               (* goal 9.3.3 (of 3) *)
6585               simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] ],
6586             (* goal 9.4 (of 4) *)
6587             EQ_TAC >> STRIP_TAC >| (* 2 subgoals *)
6588             [ (* goal 9.4.1 (of 2) *)
6589               Know ‘f x <> PosInf’
6590               >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] \\
6591                   METIS_TAC [extreal_11]) >> DISCH_TAC \\
6592               Know ‘f x <> NegInf’
6593               >- (CCONTR_TAC >> Cases_on ‘g x’ >> fs [extreal_add_def] \\
6594                   METIS_TAC [extreal_11]) >> DISCH_TAC \\
6595               Know ‘g x <> PosInf’
6596               >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
6597               DISCH_TAC \\
6598               Know ‘g x <> NegInf’
6599               >- (CCONTR_TAC >> Cases_on ‘f x’ >> fs [extreal_add_def]) \\
6600               DISCH_TAC \\
6601              ‘?s. f x = Normal s’ by METIS_TAC [extreal_cases] \\
6602              ‘?t. g x = Normal t’ by METIS_TAC [extreal_cases] \\
6603              ‘rf x = s’ by rw [Abbr ‘rf’, o_DEF] \\
6604              ‘rg x = t’ by rw [Abbr ‘rg’, o_DEF] \\
6605               fs [extreal_add_def],
6606               (* goal 9.4.2 (of 2) *)
6607               simp [] >> Q.EXISTS_TAC ‘rf x + rg x’ >> art [] \\
6608               rw [GSYM extreal_add_def, Abbr ‘rf’, Abbr ‘rg’] \\
6609               simp [normal_real] ] ]) >> Rewr' \\
6610       (* stage work *)
6611       Know ‘{x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
6612                  ?r. rf x + rg x = r /\ r IN B} INTER space a IN subsets a’
6613       >- (‘{x | f x <> PosInf /\ f x <> NegInf /\ g x <> PosInf /\ g x <> NegInf /\
6614                 ?r. rf x + rg x = r /\ r IN B} INTER space a =
6615             ({x | ?r. rf x + rg x = r /\ r IN B} INTER space a) INTER
6616             ({x | f x <> PosInf} INTER space a) INTER
6617             ({x | f x <> NegInf} INTER space a) INTER
6618             ({x | g x <> PosInf} INTER space a) INTER
6619             ({x | g x <> NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6620           MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6621           reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6622           MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6623           reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art []) \\
6624           MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6625           reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_NEGINF >> art []) \\
6626           MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6627           reverse CONJ_TAC >- (MATCH_MP_TAC IN_MEASURABLE_BOREL_NOT_POSINF >> art []) \\
6628           Q.ABBREV_TAC ‘h = \x. rf x + rg x’ \\
6629           Know ‘{x | ?r. rf x + rg x = r /\ r IN B} = PREIMAGE h B’
6630           >- rw [PREIMAGE_def, Abbr ‘h’] >> Rewr' \\
6631           Suff ‘h IN measurable a borel’ >- rw [IN_MEASURABLE] \\
6632           MATCH_MP_TAC in_borel_measurable_add \\
6633           qexistsl_tac [‘rf’, ‘rg’] >> simp [] \\
6634           CONJ_TAC >| (* 2 subgoals *)
6635           [ (* goal 9.1 (of 2) *)
6636             Q.UNABBREV_TAC ‘rf’ \\
6637             MATCH_MP_TAC in_borel_measurable_from_Borel >> art [],
6638             (* goal 9.2 (of 2) *)
6639             Q.UNABBREV_TAC ‘rg’ \\
6640             MATCH_MP_TAC in_borel_measurable_from_Borel >> art [] ]) \\
6641       DISCH_TAC \\
6642       Cases_on ‘z1 IN B’ >> Cases_on ‘z2 IN B’ >> fs [] >| (* 3 subgoals *)
6643       [ (* goal 9.1 (of 3) *)
6644         MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
6645         reverse CONJ_TAC
6646         >- (‘{x | f x = NegInf /\ g x = PosInf} INTER space a =
6647              ({x | f x = NegInf} INTER space a) INTER
6648              ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6649             MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6650             CONJ_TAC >| (* 2 subgoals *)
6651             [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6652               MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ]) \\
6653         MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
6654        ‘{x | f x = PosInf /\ g x = NegInf} INTER space a =
6655           ({x | f x = PosInf} INTER space a) INTER
6656           ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6657         MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6658         CONJ_TAC >| (* 2 subgoals *)
6659         [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6660           MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ],
6661         (* goal 9.2 (of 3) *)
6662         MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
6663        ‘{x | f x = PosInf /\ g x = NegInf} INTER space a =
6664           ({x | f x = PosInf} INTER space a) INTER
6665           ({x | g x = NegInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6666         MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6667         CONJ_TAC >| (* 2 subgoals *)
6668         [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6669           MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ],
6670         (* goal 9.3 (of 3) *)
6671         MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
6672        ‘{x | f x = NegInf /\ g x = PosInf} INTER space a =
6673           ({x | f x = NegInf} INTER space a) INTER
6674           ({x | g x = PosInf} INTER space a)’ by SET_TAC [] >> POP_ORW \\
6675         MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [] \\
6676         CONJ_TAC >| (* 2 subgoals *)
6677         [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6678           MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ] ] ])
6679 >> DISCH_TAC
6680 (* PREIMAGE h {PosInf} INTER space a IN subsets a *)
6681 >> CONJ_TAC
6682 >- (rw [PREIMAGE_def] \\
6683     Know ‘{x | h x = PosInf} INTER space a = {x | f x + g x = PosInf} INTER space a’
6684     >- (rw [Once EXTENSION] >> EQ_TAC >> rw [] \\
6685         PROVE_TAC []) >> Rewr' \\
6686     Q.PAT_X_ASSUM ‘!x. x IN space a ==> _’ K_TAC \\
6687     (* KEY: conditioning on infinities *)
6688     Cases_on ‘PosInf + NegInf’ >> Cases_on ‘NegInf + PosInf’ >| (* 9 subgoals *)
6689     [ (* goal 1 (of 9) *)
6690       IN_MEASURABLE_BOREL_ADD_tactics_1p,
6691       (* goal 2 (of 9) *)
6692       IN_MEASURABLE_BOREL_ADD_tactics_2p,
6693       (* goal 3 (of 9) *)
6694       IN_MEASURABLE_BOREL_ADD_tactics_1p,
6695       (* goal 4 (of 9) *)
6696       IN_MEASURABLE_BOREL_ADD_tactics_4p,
6697       (* goal 5 (of 9) *)
6698       Know ‘{x | f x + g x = PosInf} INTER space a =
6699               ({x | f x = PosInf} INTER space a) UNION
6700               ({x | g x = PosInf} INTER space a)’
6701       >- (rw [Once EXTENSION] >> EQ_TAC >> rw [] >| (* 5 subgoals *)
6702           [ (* goal 5.1 (of 5) *)
6703             Cases_on ‘f x’ >> Cases_on ‘g x’ >> fs [extreal_add_def],
6704             (* goal 5.2 (of 5) *)
6705             Cases_on ‘g x’ >> rw [extreal_add_def],
6706             (* goal 5.3 (of 5) *)
6707             ASM_REWRITE_TAC [],
6708             (* goal 5.4 (of 5) *)
6709             Cases_on ‘f x’ >> rw [extreal_add_def],
6710             (* goal 5.5 (of 5) *)
6711             ASM_REWRITE_TAC [] ]) >> Rewr' \\
6712       MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
6713       CONJ_TAC >|
6714       [ MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [],
6715         MATCH_MP_TAC IN_MEASURABLE_BOREL_POSINF >> art [] ],
6716       (* goal 6 (of 9) *)
6717       IN_MEASURABLE_BOREL_ADD_tactics_4p,
6718       (* goal 7 (of 9) *)
6719       IN_MEASURABLE_BOREL_ADD_tactics_1p,
6720       (* goal 8 (of 9) *)
6721       IN_MEASURABLE_BOREL_ADD_tactics_2p,
6722       (* goal 9 (of 9) *)
6723       IN_MEASURABLE_BOREL_ADD_tactics_1p ])
6724 (* PREIMAGE h {NegInf} INTER space a IN subsets a *)
6725 >> (rw [PREIMAGE_def] \\
6726     Know ‘{x | h x = NegInf} INTER space a = {x | f x + g x = NegInf} INTER space a’
6727     >- (rw [Once EXTENSION] >> EQ_TAC >> rw [] \\
6728         PROVE_TAC []) >> Rewr' \\
6729     Q.PAT_X_ASSUM ‘!x. x IN space a ==> _’ K_TAC \\
6730     (* KEY: conditioning on infinities *)
6731     Cases_on ‘PosInf + NegInf’ >> Cases_on ‘NegInf + PosInf’ >| (* 9 subgoals *)
6732     [ (* goal 1 (of 9) *)
6733       Know ‘{x | f x + g x = NegInf} INTER space a =
6734               ({x | f x = NegInf} INTER space a) UNION
6735               ({x | g x = NegInf} INTER space a)’
6736       >- (rw [Once EXTENSION] \\
6737           EQ_TAC >> rpt STRIP_TAC >> rw [extreal_add_def] >| (* 3 subgoals left *)
6738           [ (* goal 5.1 (of 3) *)
6739             Cases_on ‘f x’ >> Cases_on ‘g x’ >> fs [extreal_add_def],
6740             (* goal 5.2 (of 3) *)
6741             Cases_on ‘g x’ >> rw [extreal_add_def],
6742             (* goal 5.3 (of 3) *)
6743             Cases_on ‘f x’ >> rw [extreal_add_def] ]) >> Rewr' \\
6744       MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
6745       CONJ_TAC >|
6746       [ MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [],
6747         MATCH_MP_TAC IN_MEASURABLE_BOREL_NEGINF >> art [] ],
6748       (* goal 2 (of 9) *)
6749       IN_MEASURABLE_BOREL_ADD_tactics_2n,
6750       (* goal 3 (of 9) *)
6751       IN_MEASURABLE_BOREL_ADD_tactics_2n,
6752       (* goal 4 (of 9) *)
6753       IN_MEASURABLE_BOREL_ADD_tactics_4n,
6754       (* goal 5 (of 9) *)
6755       IN_MEASURABLE_BOREL_ADD_tactics_5n,
6756       (* goal 6 (of 9) *)
6757       IN_MEASURABLE_BOREL_ADD_tactics_5n,
6758       (* goal 7 (of 9) *)
6759       IN_MEASURABLE_BOREL_ADD_tactics_4n,
6760       (* goal 8 (of 9) *)
6761       IN_MEASURABLE_BOREL_ADD_tactics_5n,
6762       (* goal 9 (of 9) *)
6763       IN_MEASURABLE_BOREL_ADD_tactics_5n ])
6764QED
6765
6766(* NOTE: this new, natural proof is only possible after the new ‘extreal_sub’ *)
6767Theorem IN_MEASURABLE_BOREL_SUB' :
6768    !a f g h. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel /\
6769              (!x. x IN space a ==> (h x = f x - g x)) ==> h IN measurable a Borel
6770Proof
6771    rpt STRIP_TAC
6772 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_ADD'
6773 >> qexistsl_tac [‘f’, ‘\x. -g x’]
6774 >> rw [extreal_sub, IN_MEASURABLE_BOREL_AINV]
6775QED
6776
6777(* ------------------------------------------------------------------------- *)
6778(*  Two-dimensional Borel sigma-algebra (extreal version), author: Chun Tian *)
6779(* ------------------------------------------------------------------------- *)
6780
6781Theorem SPACE_BOREL_2D :
6782    space (Borel CROSS Borel) = UNIV
6783Proof
6784    REWRITE_TAC [SPACE_PROD_SIGMA, SPACE_BOREL, CROSS_UNIV]
6785QED
6786
6787Theorem SIGMA_ALGEBRA_BOREL_2D :
6788    sigma_algebra (Borel CROSS Borel)
6789Proof
6790    MATCH_MP_TAC SIGMA_ALGEBRA_PROD_SIGMA
6791 >> rw [SPACE_BOREL, subset_class_def]
6792QED
6793
6794Theorem CROSS_UNION_R[local] :
6795    !a b c. a CROSS (b UNION c) = (a CROSS b) UNION (a CROSS c)
6796Proof
6797    rw [Once EXTENSION, IN_CROSS]
6798 >> METIS_TAC []
6799QED
6800
6801Theorem CROSS_UNION_L[local] :
6802    !a b c. (a UNION b) CROSS c = (a CROSS c) UNION (b CROSS c)
6803Proof
6804    rw [Once EXTENSION, IN_CROSS]
6805 >> METIS_TAC []
6806QED
6807
6808(* Alternative definition of ‘Borel CROSS Borel’ by ‘borel CROSS borel’
6809
6810   Following the same idea in "borel_2d", the extreal-based Borel sets (2D) can
6811   be seen as the real-based Borel sets with optional "infinity" borders.
6812 *)
6813val corner_set_tm1 =
6814   “{(x,y) | (x = PosInf \/ x = NegInf) /\ (y = PosInf \/ y = NegInf)}”;
6815
6816val corner_set_tm2 =
6817   “{(PosInf,PosInf); (PosInf,NegInf); (NegInf,PosInf); (NegInf,NegInf)}”;
6818
6819(* The following terms re-define ‘Borel CROSS Borel’ in terms of ‘borel’ and
6820  ‘borel CROSS borel’.
6821
6822   The first version involves only disjoint unions, easier in proving its own
6823   properties.
6824 *)
6825val borel_2d_sets_tm1 =
6826   “{B' | ?B S Z b1 b2 b3 b4.
6827           B' = (IMAGE (\(x,y). (Normal x,Normal y)) B) UNION S UNION Z /\
6828           B IN subsets (borel CROSS borel) /\
6829           S = ({PosInf} CROSS (IMAGE Normal b1)) UNION
6830               ({NegInf} CROSS (IMAGE Normal b2)) UNION
6831               ((IMAGE Normal b3) CROSS {PosInf}) UNION
6832               ((IMAGE Normal b4) CROSS {NegInf}) /\
6833           b1 IN subsets borel /\ b2 IN subsets borel /\
6834           b3 IN subsets borel /\ b4 IN subsets borel /\
6835           Z SUBSET ^corner_set_tm2}”;
6836
6837(* The second version is shorter, and easier in applications. *)
6838val borel_2d_sets_tm2 =
6839   “{B' | ?B S B1 B2 B3 B4.
6840           B' = (IMAGE (\(x,y). (Normal x,Normal y)) B) UNION S /\
6841           B IN subsets (borel CROSS borel) /\
6842           S = ({PosInf} CROSS B1) UNION
6843               ({NegInf} CROSS B2) UNION
6844               (B3 CROSS {PosInf}) UNION
6845               (B4 CROSS {NegInf}) /\
6846           B1 IN subsets Borel /\ B2 IN subsets Borel /\
6847           B3 IN subsets Borel /\ B4 IN subsets Borel}”;
6848
6849val borel_2d_tm1 = “(univ(:extreal # extreal), ^borel_2d_sets_tm1)”;
6850val borel_2d_tm2 = “(univ(:extreal # extreal), ^borel_2d_sets_tm2)”;
6851
6852Theorem BOREL_MEASURABLE_SETS_NORMAL :
6853    !b. b IN subsets borel ==> IMAGE Normal b IN subsets Borel
6854Proof
6855    rw [Borel]
6856 >> qexistsl_tac [‘b’, ‘{}’] >> simp []
6857QED
6858
6859Theorem BOREL_MEASURABLE_SETS_EMPTY[simp] :
6860    {} IN subsets Borel
6861Proof
6862    MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY
6863 >> REWRITE_TAC [SIGMA_ALGEBRA_BOREL]
6864QED
6865
6866Theorem UNION_LEFT_CONG[local] :
6867    !A B C. B = C ==> A UNION B = A UNION C
6868Proof
6869    SET_TAC []
6870QED
6871
6872Theorem IN_CROSS_SING[local] :
6873   !x A B. x IN {A} CROSS {B} <=> x = (A,B)
6874Proof
6875    rw [IN_CROSS]
6876 >> Cases_on ‘x’ >> rw []
6877QED
6878
6879(* The equivalence of borel_2d_tm1 and borel_2d_tm2 *)
6880Theorem BOREL_2D_lemma1[local] :
6881    ^borel_2d_tm1 = ^borel_2d_tm2
6882Proof
6883    Suff ‘^borel_2d_sets_tm1 = ^borel_2d_sets_tm2’ >- Rewr
6884 >> MATCH_MP_TAC SUBSET_ANTISYM
6885 >> CONJ_TAC (* 2 subgoals, same initial tactics *)
6886 >> RW_TAC std_ss [Once SUBSET_DEF, GSPECIFICATION]
6887 >> Q.EXISTS_TAC ‘B’ >> art []
6888 >| [ (* goal 1 (of 2) *)
6889      qexistsl_tac
6890        [‘(IMAGE Normal b1) UNION if (PosInf,NegInf) IN Z then {NegInf} else {}’,
6891         ‘(IMAGE Normal b2) UNION if (NegInf,PosInf) IN Z then {PosInf} else {}’,
6892         ‘(IMAGE Normal b3) UNION if (PosInf,PosInf) IN Z then {PosInf} else {}’,
6893         ‘(IMAGE Normal b4) UNION if (NegInf,NegInf) IN Z then {NegInf} else {}’] \\
6894      reverse CONJ_TAC
6895      >- (rpt STRIP_TAC \\ (* 4 subgoals, same initial tactics *)
6896          (MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> REWRITE_TAC [SIGMA_ALGEBRA_BOREL] \\
6897           CONJ_TAC >- (MATCH_MP_TAC BOREL_MEASURABLE_SETS_NORMAL >> art [])) >|
6898          [ Cases_on ‘(PosInf,NegInf) IN Z’ >> rw [],
6899            Cases_on ‘(NegInf,PosInf) IN Z’ >> rw [],
6900            Cases_on ‘(PosInf,PosInf) IN Z’ >> rw [],
6901            Cases_on ‘(NegInf,NegInf) IN Z’ >> rw [] ]) \\
6902      REWRITE_TAC [GSYM UNION_ASSOC] \\
6903      MATCH_MP_TAC UNION_LEFT_CONG \\
6904      REWRITE_TAC [UNION_ASSOC] \\
6905      rw [] \\ (* 16 subgoals, same tactics *)
6906      MATCH_MP_TAC SUBSET_ANTISYM \\
6907      RW_TAC std_ss [SUBSET_DEF, IN_UNION, IN_CROSS_SING,
6908                     CROSS_UNION_L, CROSS_UNION_R] >> art [] \\
6909      FULL_SIMP_TAC std_ss [SUBSET_DEF] \\
6910      Q.PAT_X_ASSUM ‘!x. x IN Z ==> _’ (MP_TAC o (Q.SPEC ‘x’)) \\
6911      RW_TAC std_ss [IN_INSERT, NOT_IN_EMPTY] \\
6912      FULL_SIMP_TAC bool_ss [],
6913      (* goal 2 (of 2) *)
6914      FULL_SIMP_TAC std_ss [Borel, UNION_EMPTY, subsets_def, GSPECIFICATION] \\
6915      qexistsl_tac
6916        [‘({PosInf} CROSS S) UNION ({NegInf} CROSS S') UNION
6917          (S'' CROSS {PosInf}) UNION (S''' CROSS {NegInf})’,
6918         ‘B'’, ‘B''’, ‘B'3'’, ‘B'4'’] >> art [] \\
6919      reverse CONJ_TAC
6920      >- (rw [SUBSET_DEF] (* 4 subgoals, same tactics *) \\
6921          Cases_on ‘x’ \\
6922          FULL_SIMP_TAC std_ss [IN_SING, IN_INSERT] \\
6923          REV_FULL_SIMP_TAC std_ss [NOT_IN_EMPTY, IN_SING, IN_INSERT]) \\
6924      MATCH_MP_TAC SUBSET_ANTISYM \\
6925      RW_TAC std_ss [SUBSET_DEF, IN_UNION, IN_CROSS_SING,
6926                     CROSS_UNION_L, CROSS_UNION_R] >> art [] ]
6927QED
6928
6929Theorem BOREL_2D_lemma2[local] :
6930    sigma_algebra ^borel_2d_tm1
6931Proof
6932    rw [sigma_algebra_alt_pow] (* 4 subgoals *)
6933 >| [ (* goal 1 (of 4) *)
6934      rw [SUBSET_DEF, IN_POW],
6935      (* goal 2 (of 4) *)
6936      qexistsl_tac [‘{}’, ‘{}’, ‘{}’, ‘{}’] >> simp [CROSS_EMPTY] \\
6937      CONJ_TAC >- (MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY \\
6938                   REWRITE_TAC [sigma_algebra_borel_2d]) \\
6939      MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY \\
6940      REWRITE_TAC [sigma_algebra_borel],
6941      (* goal 3 (of 4): DIFF (hard) *)
6942      qexistsl_tac [‘univ(:real # real) DIFF B’,
6943                    ‘^corner_set_tm2 DIFF Z’,
6944                    ‘univ(:real) DIFF b1’,
6945                    ‘univ(:real) DIFF b2’,
6946                    ‘univ(:real) DIFF b3’,
6947                    ‘univ(:real) DIFF b4’] \\
6948      reverse CONJ_TAC (* easy part *)
6949      >- (REWRITE_TAC [CONJ_ASSOC] \\
6950          reverse CONJ_TAC >- (POP_ASSUM MP_TAC >> SET_TAC []) \\
6951          METIS_TAC [space_borel, space_borel_2d, SIGMA_ALGEBRA_COMPL,
6952                     sigma_algebra_borel, sigma_algebra_borel_2d]) \\
6953
6954      MATCH_MP_TAC SUBSET_ANTISYM \\
6955      CONJ_TAC (* "easy" part *)
6956      >- (REWRITE_TAC [SUBSET_DEF] \\
6957          Q.X_GEN_TAC ‘z’ >> DISCH_TAC \\
6958          FULL_SIMP_TAC std_ss [IN_DIFF, IN_UNIV, IN_UNION] \\
6959          CCONTR_TAC >> FULL_SIMP_TAC std_ss [] \\
6960
6961          Know ‘z NOTIN {PosInf} CROSS UNIV’
6962          >- (Know ‘univ(:extreal) = (IMAGE Normal b1) UNION
6963                                     (IMAGE Normal (UNIV DIFF b1)) UNION {PosInf; NegInf}’
6964              >- (rw [Once EXTENSION] >> Cases_on ‘x’ >> rw []) >> Rewr' \\
6965              CCONTR_TAC \\
6966              POP_ASSUM (MP_TAC o (REWRITE_RULE [IN_UNION, CROSS_UNION_R])) \\
6967              RW_TAC std_ss [] \\
6968              Q.PAT_X_ASSUM ‘z NOTIN ^corner_set_tm2’ MP_TAC \\
6969              rw [IN_CROSS] >> Cases_on ‘z’ >> fs []) \\
6970          Q.PAT_X_ASSUM ‘z NOTIN {PosInf} CROSS (IMAGE Normal b1)’ K_TAC \\
6971          Q.PAT_X_ASSUM ‘z NOTIN {PosInf} CROSS (IMAGE Normal (UNIV DIFF b1))’ K_TAC \\
6972          DISCH_TAC \\
6973
6974          Know ‘z NOTIN {NegInf} CROSS UNIV’
6975          >- (Know ‘univ(:extreal) = (IMAGE Normal b2) UNION
6976                                     (IMAGE Normal (UNIV DIFF b2)) UNION {PosInf; NegInf}’
6977              >- (rw [Once EXTENSION] >> Cases_on ‘x’ >> rw []) >> Rewr' \\
6978              CCONTR_TAC \\
6979              POP_ASSUM (MP_TAC o (REWRITE_RULE [IN_UNION, CROSS_UNION_R])) \\
6980              RW_TAC std_ss [] \\
6981              Q.PAT_X_ASSUM ‘z NOTIN ^corner_set_tm2’ MP_TAC \\
6982              rw [IN_CROSS] >> Cases_on ‘z’ >> fs []) \\
6983          Q.PAT_X_ASSUM ‘z NOTIN {NegInf} CROSS (IMAGE Normal b2)’ K_TAC \\
6984          Q.PAT_X_ASSUM ‘z NOTIN {NegInf} CROSS (IMAGE Normal (UNIV DIFF b2))’ K_TAC \\
6985          DISCH_TAC \\
6986
6987          Know ‘z NOTIN UNIV CROSS {PosInf}’
6988          >- (Know ‘univ(:extreal) = (IMAGE Normal b3) UNION
6989                                     (IMAGE Normal (UNIV DIFF b3)) UNION {PosInf; NegInf}’
6990              >- (rw [Once EXTENSION] >> Cases_on ‘x’ >> rw []) >> Rewr' \\
6991              CCONTR_TAC \\
6992              POP_ASSUM (MP_TAC o (REWRITE_RULE [IN_UNION, CROSS_UNION_L])) \\
6993              RW_TAC std_ss [] \\
6994              Q.PAT_X_ASSUM ‘z NOTIN ^corner_set_tm2’ MP_TAC \\
6995              rw [IN_CROSS] >> Cases_on ‘z’ >> fs []) \\
6996          Q.PAT_X_ASSUM ‘z NOTIN (IMAGE Normal b3) CROSS {PosInf}’ K_TAC \\
6997          Q.PAT_X_ASSUM ‘z NOTIN (IMAGE Normal (UNIV DIFF b3)) CROSS {PosInf}’ K_TAC \\
6998          DISCH_TAC \\
6999
7000          Know ‘z NOTIN UNIV CROSS {NegInf}’
7001          >- (Know ‘univ(:extreal) = (IMAGE Normal b4) UNION
7002                                     (IMAGE Normal (UNIV DIFF b4)) UNION {PosInf; NegInf}’
7003              >- (rw [Once EXTENSION] >> Cases_on ‘x’ >> rw []) >> Rewr' \\
7004              CCONTR_TAC \\
7005              POP_ASSUM (MP_TAC o (REWRITE_RULE [IN_UNION, CROSS_UNION_L])) \\
7006              RW_TAC std_ss [] \\
7007              Q.PAT_X_ASSUM ‘z NOTIN ^corner_set_tm2’ MP_TAC \\
7008              rw [IN_CROSS] >> Cases_on ‘z’ >> fs []) \\
7009          Q.PAT_X_ASSUM ‘z NOTIN (IMAGE Normal b4) CROSS {NegInf}’ K_TAC \\
7010          Q.PAT_X_ASSUM ‘z NOTIN (IMAGE Normal (UNIV DIFF b4)) CROSS {NegInf}’ K_TAC \\
7011          DISCH_TAC \\
7012
7013          Know ‘z NOTIN IMAGE (\(x,y). (Normal x,Normal y)) univ(:real # real)’
7014          >- (‘univ(:real # real) = B UNION (univ(:real # real) DIFF B)’ by SET_TAC [] \\
7015              POP_ORW >> CCONTR_TAC \\
7016              POP_ASSUM (MP_TAC o (REWRITE_RULE [IN_UNION, IMAGE_UNION])) \\
7017              PROVE_TAC []) \\
7018          Q.PAT_X_ASSUM ‘z NOTIN IMAGE (\(x,y). (Normal x,Normal y)) B’ K_TAC \\
7019          Q.PAT_X_ASSUM ‘z NOTIN
7020                           IMAGE (\(x,y). (Normal x,Normal y)) (univ(:real # real) DIFF B)’ K_TAC \\
7021          DISCH_TAC \\
7022
7023          NTAC 5 (POP_ASSUM MP_TAC) >> rw [] \\
7024          Cases_on ‘z’ >> fs [] \\
7025         ‘?a. q = Normal a’ by METIS_TAC [extreal_cases] >> POP_ORW \\
7026         ‘?b. r = Normal b’ by METIS_TAC [extreal_cases] >> POP_ORW \\
7027          Q.EXISTS_TAC ‘(a,b)’ >> rw []) \\
7028   (* hard part of CONJ_TAC *)
7029      REWRITE_TAC [SUBSET_DEF] \\
7030      Q.X_GEN_TAC ‘z’ >> STRIP_TAC \\
7031      REWRITE_TAC [IN_DIFF, IN_UNIV] \\
7032      RW_TAC std_ss [IN_UNION] >| (* 6 subgoals *)
7033      [ (* goal 3.1 (of 6) *)
7034       ‘B = UNIV DIFF (UNIV DIFF B)’ by SET_TAC [] >> POP_ORW \\
7035        CCONTR_TAC \\
7036        FULL_SIMP_TAC std_ss [IN_IMAGE, IN_UNION, IN_DIFF, IN_UNIV, IN_CROSS, IN_SING] \\
7037        rename1 ‘y IN B’ >|
7038        [ Cases_on ‘x’  >> Cases_on ‘y’ >> fs [] >> METIS_TAC [],
7039          Cases_on ‘y’ >> fs [],
7040          Cases_on ‘y’ >> fs [],
7041          Cases_on ‘y’ >> fs [],
7042          Cases_on ‘y’ >> fs [],
7043          Cases_on ‘y’ >> fs [] ],
7044        (* goal 3.2 (of 6) *)
7045        CCONTR_TAC >> fs [IN_IMAGE, IN_UNION, IN_DIFF, IN_UNIV, IN_CROSS, IN_SING] \\
7046        rename1 ‘y IN b1’ >|
7047        [ Cases_on ‘x’ >> Cases_on ‘z’ >> fs [],
7048          Cases_on ‘z’ >> fs [] >> METIS_TAC [],
7049          Cases_on ‘z’ >> fs [],
7050          Cases_on ‘z’ >> fs [],
7051          Cases_on ‘z’ >> fs [],
7052          Cases_on ‘z’ >> fs [] ],
7053        (* goal 3.3 (of 6) *)
7054        CCONTR_TAC >> fs [IN_IMAGE, IN_UNION, IN_DIFF, IN_UNIV, IN_CROSS, IN_SING] \\
7055        rename1 ‘y IN b2’ >|
7056        [ Cases_on ‘x’ >> Cases_on ‘z’ >> fs [],
7057          Cases_on ‘z’ >> fs [] >> METIS_TAC [],
7058          Cases_on ‘z’ >> fs [],
7059          Cases_on ‘z’ >> fs [],
7060          Cases_on ‘z’ >> fs [],
7061          Cases_on ‘z’ >> fs [] ],
7062        (* goal 3.4 (of 6) *)
7063        CCONTR_TAC >> fs [IN_IMAGE, IN_UNION, IN_DIFF, IN_UNIV, IN_CROSS, IN_SING] \\
7064        rename1 ‘y IN b3’ >|
7065        [ Cases_on ‘x’ >> Cases_on ‘z’ >> fs [],
7066          Cases_on ‘z’ >> fs [] >> METIS_TAC [],
7067          Cases_on ‘z’ >> fs [],
7068          Cases_on ‘z’ >> fs [],
7069          Cases_on ‘z’ >> fs [],
7070          Cases_on ‘z’ >> fs [] ],
7071        (* goal 3.5 (of 6) *)
7072        CCONTR_TAC >> fs [IN_IMAGE, IN_UNION, IN_DIFF, IN_UNIV, IN_CROSS, IN_SING] \\
7073        rename1 ‘y IN b4’ >|
7074        [ Cases_on ‘x’ >> Cases_on ‘z’ >> fs [],
7075          Cases_on ‘z’ >> fs [] >> METIS_TAC [],
7076          Cases_on ‘z’ >> fs [],
7077          Cases_on ‘z’ >> fs [],
7078          Cases_on ‘z’ >> fs [],
7079          Cases_on ‘z’ >> fs [] ],
7080        (* goal 3.6 (of 6) *)
7081        CCONTR_TAC \\
7082        fs [SUBSET_DEF, IN_IMAGE, IN_UNION, IN_DIFF, IN_UNIV, IN_CROSS, IN_SING] \\
7083        Q.PAT_X_ASSUM ‘!x. x IN Z ==> _’ (MP_TAC o Q.SPEC ‘z’) >|
7084        [ Cases_on ‘x’ >> fs [],
7085          Cases_on ‘z’ >> fs [],
7086          Cases_on ‘z’ >> fs [],
7087          Cases_on ‘z’ >> fs [],
7088          Cases_on ‘z’ >> fs [] ] ],
7089      (* goal 4 (of 4) *)
7090      POP_ASSUM (MP_TAC o (REWRITE_RULE [Once SUBSET_DEF, IN_UNIV, IN_IMAGE])) >> rw [] \\
7091      Know ‘!n. ?B Z b1 b2 b3 b4.
7092                 A n = IMAGE (\(x,y). (Normal x,Normal y)) B UNION
7093                       ({PosInf} CROSS IMAGE Normal b1 UNION
7094                        {NegInf} CROSS IMAGE Normal b2 UNION
7095                        IMAGE Normal b3 CROSS {PosInf} UNION
7096                        IMAGE Normal b4 CROSS {NegInf}) UNION Z /\
7097                 B IN subsets (borel CROSS borel) /\
7098                 b1 IN subsets borel /\
7099                 b2 IN subsets borel /\
7100                 b3 IN subsets borel /\
7101                 b4 IN subsets borel /\
7102                 Z SUBSET ^corner_set_tm2’
7103      >- (GEN_TAC \\
7104          POP_ASSUM (MP_TAC o (Q.SPEC ‘A (n :num)’)) \\
7105          Know ‘?x'. A n = A x'’ >- METIS_TAC [] \\
7106          RW_TAC std_ss []) \\
7107      KILL_TAC >> STRIP_TAC \\
7108      FULL_SIMP_TAC std_ss [SKOLEM_THM] \\
7109      qexistsl_tac [‘BIGUNION (IMAGE f UNIV)’,
7110                    ‘BIGUNION (IMAGE f' UNIV)’,
7111                    ‘BIGUNION (IMAGE f'2' UNIV)’,
7112                    ‘BIGUNION (IMAGE f'3' UNIV)’,
7113                    ‘BIGUNION (IMAGE f'4' UNIV)’,
7114                    ‘BIGUNION (IMAGE f'5' UNIV)’] \\
7115      rw [Once EXTENSION, IN_BIGUNION] >| (* 7 subgoals *)
7116      [ (* goal 4.1 (of 7) *)
7117        RW_TAC std_ss [Once EXTENSION, IN_BIGUNION, GSPECIFICATION] \\
7118        reverse EQ_TAC
7119        >- (RW_TAC std_ss [IN_IMAGE, IN_UNIV, IN_UNION, IN_BIGUNION_IMAGE] >| (* 6 *)
7120            [ (* goal 4.1.1 (of 6) *)
7121              rename1 ‘y IN f n’ \\
7122              Q.EXISTS_TAC ‘IMAGE (\(x,y). (Normal x,Normal y)) (f n) UNION
7123                            ({PosInf} CROSS IMAGE Normal (f'' n) UNION
7124                             {NegInf} CROSS IMAGE Normal (f'3' n) UNION
7125                             IMAGE Normal (f'4' n) CROSS {PosInf} UNION
7126                             IMAGE Normal (f'5' n) CROSS {NegInf}) UNION f' n’ \\
7127              reverse CONJ_TAC >- (Q.EXISTS_TAC ‘n’ >> REWRITE_TAC []) \\
7128              RW_TAC std_ss [IN_IMAGE, IN_UNION] \\
7129              METIS_TAC [],
7130              (* goal 4.1.2 (of 6) *)
7131              POP_ASSUM MP_TAC >> rw [] \\
7132              rename1 ‘y IN f'' n’ \\
7133              Q.EXISTS_TAC ‘IMAGE (\(x,y). (Normal x,Normal y)) (f n) UNION
7134                            ({PosInf} CROSS IMAGE Normal (f'' n) UNION
7135                             {NegInf} CROSS IMAGE Normal (f'3' n) UNION
7136                             IMAGE Normal (f'4' n) CROSS {PosInf} UNION
7137                             IMAGE Normal (f'5' n) CROSS {NegInf}) UNION f' n’ \\
7138              reverse CONJ_TAC >- (Q.EXISTS_TAC ‘n’ >> REWRITE_TAC []) \\
7139              rw [IN_IMAGE, IN_UNION],
7140              (* goal 4.1.3 (of 6) *)
7141              POP_ASSUM MP_TAC >> rw [] \\
7142              rename1 ‘y IN f'3' n’ \\
7143              Q.EXISTS_TAC ‘IMAGE (\(x,y). (Normal x,Normal y)) (f n) UNION
7144                            ({PosInf} CROSS IMAGE Normal (f'' n) UNION
7145                             {NegInf} CROSS IMAGE Normal (f'3' n) UNION
7146                             IMAGE Normal (f'4' n) CROSS {PosInf} UNION
7147                             IMAGE Normal (f'5' n) CROSS {NegInf}) UNION f' n’ \\
7148              reverse CONJ_TAC >- (Q.EXISTS_TAC ‘n’ >> REWRITE_TAC []) \\
7149              rw [IN_IMAGE, IN_UNION],
7150              (* goal 4.1.4 (of 6) *)
7151              POP_ASSUM MP_TAC >> rw [] \\
7152              rename1 ‘y IN f'4' n’ \\
7153              Q.EXISTS_TAC ‘IMAGE (\(x,y). (Normal x,Normal y)) (f n) UNION
7154                            ({PosInf} CROSS IMAGE Normal (f'' n) UNION
7155                             {NegInf} CROSS IMAGE Normal (f'3' n) UNION
7156                             IMAGE Normal (f'4' n) CROSS {PosInf} UNION
7157                             IMAGE Normal (f'5' n) CROSS {NegInf}) UNION f' n’ \\
7158              reverse CONJ_TAC >- (Q.EXISTS_TAC ‘n’ >> REWRITE_TAC []) \\
7159              rw [IN_IMAGE, IN_UNION],
7160              (* goal 4.1.5 (of 6) *)
7161              POP_ASSUM MP_TAC >> rw [] \\
7162              rename1 ‘y IN f'5' n’ \\
7163              Q.EXISTS_TAC ‘IMAGE (\(x,y). (Normal x,Normal y)) (f n) UNION
7164                            ({PosInf} CROSS IMAGE Normal (f'' n) UNION
7165                             {NegInf} CROSS IMAGE Normal (f'3' n) UNION
7166                             IMAGE Normal (f'4' n) CROSS {PosInf} UNION
7167                             IMAGE Normal (f'5' n) CROSS {NegInf}) UNION f' n’ \\
7168              reverse CONJ_TAC >- (Q.EXISTS_TAC ‘n’ >> REWRITE_TAC []) \\
7169              rw [IN_IMAGE, IN_UNION],
7170              (* goal 4.1.6 (of 6) *)
7171              rename1 ‘y IN f' n’ \\
7172              Q.EXISTS_TAC ‘IMAGE (\(x,y). (Normal x,Normal y)) (f n) UNION
7173                            ({PosInf} CROSS IMAGE Normal (f'' n) UNION
7174                             {NegInf} CROSS IMAGE Normal (f'3' n) UNION
7175                             IMAGE Normal (f'4' n) CROSS {PosInf} UNION
7176                             IMAGE Normal (f'5' n) CROSS {NegInf}) UNION f' n’ \\
7177              reverse CONJ_TAC >- (Q.EXISTS_TAC ‘n’ >> REWRITE_TAC []) \\
7178              rw [IN_IMAGE, IN_UNION] ]) \\
7179        STRIP_TAC \\
7180        FULL_SIMP_TAC std_ss [IN_UNION, IN_IMAGE, IN_BIGUNION_IMAGE, IN_UNIV] >| (* 6 *)
7181        [ (* goal 4.1.1 (of 6) *)
7182          METIS_TAC [],
7183          (* goal 4.1.2 (of 6) *)
7184          Suff ‘x IN {PosInf} CROSS IMAGE Normal (BIGUNION (IMAGE f'' UNIV))’ >- rw [] \\
7185          fs [] >> rename1 ‘y IN f'' n’ \\
7186          METIS_TAC [],
7187          (* goal 4.1.3 (of 6) *)
7188          Suff ‘x IN {NegInf} CROSS IMAGE Normal (BIGUNION (IMAGE f'3' UNIV))’ >- rw [] \\
7189          fs [] >> rename1 ‘y IN f'3' n’ \\
7190          METIS_TAC [],
7191          (* goal 4.1.4 (of 6) *)
7192          Suff ‘x IN IMAGE Normal (BIGUNION (IMAGE f'4' UNIV)) CROSS {PosInf}’ >- rw [] \\
7193          fs [] >> rename1 ‘y IN f'4' n’ \\
7194          METIS_TAC [],
7195          (* goal 4.1.5 (of 6) *)
7196          Suff ‘x IN IMAGE Normal (BIGUNION (IMAGE f'5' UNIV)) CROSS {NegInf}’ >- rw [] \\
7197          fs [] >> rename1 ‘y IN f'5' n’ \\
7198          METIS_TAC [],
7199          (* goal 4.1.6 (of 6) *)
7200          METIS_TAC [] ],
7201        (* goal 4.2 (of 7) *)
7202        STRIP_ASSUME_TAC (REWRITE_RULE [SIGMA_ALGEBRA_ALT] sigma_algebra_borel_2d) \\
7203        FIRST_X_ASSUM MATCH_MP_TAC \\
7204        rw [IN_FUNSET],
7205        (* goal 4.3 (of 7) *)
7206        STRIP_ASSUME_TAC (REWRITE_RULE [SIGMA_ALGEBRA_ALT] sigma_algebra_borel) \\
7207        FIRST_X_ASSUM MATCH_MP_TAC \\
7208        rw [IN_FUNSET],
7209        (* goal 4.4 (of 7) *)
7210        STRIP_ASSUME_TAC (REWRITE_RULE [SIGMA_ALGEBRA_ALT] sigma_algebra_borel) \\
7211        FIRST_X_ASSUM MATCH_MP_TAC \\
7212        rw [IN_FUNSET],
7213        (* goal 4.5 (of 7) *)
7214        STRIP_ASSUME_TAC (REWRITE_RULE [SIGMA_ALGEBRA_ALT] sigma_algebra_borel) \\
7215        FIRST_X_ASSUM MATCH_MP_TAC \\
7216        rw [IN_FUNSET],
7217        (* goal 4.6 (of 7) *)
7218        STRIP_ASSUME_TAC (REWRITE_RULE [SIGMA_ALGEBRA_ALT] sigma_algebra_borel) \\
7219        FIRST_X_ASSUM MATCH_MP_TAC \\
7220        rw [IN_FUNSET],
7221        (* goal 4.7 (of 7) *)
7222        fs [SUBSET_DEF] >> METIS_TAC [] ] ]
7223QED
7224
7225(* |- sigma_algebra ^borel_2d_tm2 *)
7226Theorem BOREL_2D_lemma3[local] = REWRITE_RULE [BOREL_2D_lemma1] BOREL_2D_lemma2
7227
7228Theorem BOREL_2D_lemma4[local] :
7229    !A B. A IN subsets borel /\ B IN subsets borel ==>
7230          A CROSS B IN subsets (borel CROSS borel)
7231Proof
7232    rw [prod_sigma_def]
7233 >> Suff ‘A CROSS B IN (prod_sets (subsets borel) (subsets borel))’
7234 >- (METIS_TAC [SUBSET_DEF, SIGMA_SUBSET_SUBSETS])
7235 >> rw [IN_PROD_SETS]
7236 >> qexistsl_tac [‘A’, ‘B’] >> art []
7237QED
7238
7239Theorem BOREL_2D_lemma5[local] :
7240    !A B. A IN subsets Borel /\ B IN subsets Borel ==>
7241          A CROSS B IN subsets (Borel CROSS Borel)
7242Proof
7243    rw [prod_sigma_def]
7244 >> Suff ‘A CROSS B IN (prod_sets (subsets Borel) (subsets Borel))’
7245 >- (METIS_TAC [SUBSET_DEF, SIGMA_SUBSET_SUBSETS])
7246 >> rw [IN_PROD_SETS]
7247 >> qexistsl_tac [‘A’, ‘B’] >> art []
7248QED
7249
7250(* Main Theorem: alternative definition of ‘Borel CROSS Borel’  *)
7251Theorem BOREL_2D :
7252    Borel CROSS Borel = ^borel_2d_tm2
7253Proof
7254    Q.ABBREV_TAC ‘S = ^borel_2d_tm2’
7255 >> ONCE_REWRITE_TAC [GSYM SPACE]
7256 >> ‘space (Borel CROSS Borel) = space S’ by rw [SPACE_BOREL_2D, Abbr ‘S’]
7257 >> POP_ORW
7258 >> Suff ‘subsets (Borel CROSS Borel) = subsets S’ >- rw []
7259 >> MATCH_MP_TAC SUBSET_ANTISYM
7260 (* stage work *)
7261 >> reverse CONJ_TAC
7262 >- (rw [Once SUBSET_DEF, Abbr ‘S’] \\
7263     Suff ‘{PosInf} CROSS B1 IN subsets (Borel CROSS Borel) /\
7264           {NegInf} CROSS B2 IN subsets (Borel CROSS Borel) /\
7265           B3 CROSS {PosInf} IN subsets (Borel CROSS Borel) /\
7266           B4 CROSS {NegInf} IN subsets (Borel CROSS Borel) /\
7267           IMAGE (\(x,y). (Normal x,Normal y)) B IN subsets (Borel CROSS Borel)’
7268     >- (STRIP_TAC \\
7269         rpt (MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [SIGMA_ALGEBRA_BOREL_2D])) \\
7270     CONJ_TAC >- (REWRITE_TAC [prod_sigma_def] \\
7271                  Suff ‘{PosInf} CROSS B1 IN (prod_sets (subsets Borel) (subsets Borel))’
7272                  >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
7273                  REWRITE_TAC [IN_PROD_SETS] \\
7274                  qexistsl_tac [‘{PosInf}’, ‘B1’] >> art [BOREL_MEASURABLE_SETS_SING]) \\
7275     CONJ_TAC >- (REWRITE_TAC [prod_sigma_def] \\
7276                  Suff ‘{NegInf} CROSS B2 IN (prod_sets (subsets Borel) (subsets Borel))’
7277                  >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
7278                  REWRITE_TAC [IN_PROD_SETS] \\
7279                  qexistsl_tac [‘{NegInf}’, ‘B2’] >> art [BOREL_MEASURABLE_SETS_SING]) \\
7280     CONJ_TAC >- (REWRITE_TAC [prod_sigma_def] \\
7281                  Suff ‘B3 CROSS {PosInf} IN (prod_sets (subsets Borel) (subsets Borel))’
7282                  >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
7283                  REWRITE_TAC [IN_PROD_SETS] \\
7284                  qexistsl_tac [‘B3’, ‘{PosInf}’] >> art [BOREL_MEASURABLE_SETS_SING]) \\
7285     CONJ_TAC >- (REWRITE_TAC [prod_sigma_def] \\
7286                  Suff ‘B4 CROSS {NegInf} IN (prod_sets (subsets Borel) (subsets Borel))’
7287                  >- METIS_TAC [SIGMA_SUBSET_SUBSETS, SUBSET_DEF] \\
7288                  REWRITE_TAC [IN_PROD_SETS] \\
7289                  qexistsl_tac [‘B4’, ‘{NegInf}’] >> art [BOREL_MEASURABLE_SETS_SING]) \\
7290  (* the rest is hard *)
7291     NTAC 4 (POP_ASSUM K_TAC) (* useless assumptions *) \\
7292     Q.ABBREV_TAC ‘D = {IMAGE (\(x,y). (Normal x,Normal y)) Z |
7293                        Z IN subsets (borel CROSS borel)}’ \\
7294     Suff ‘D SUBSET subsets (Borel CROSS Borel)’
7295     >- (rw [SUBSET_DEF, Abbr ‘D’] \\
7296         POP_ASSUM MATCH_MP_TAC >> Q.EXISTS_TAC ‘B’ >> art []) \\
7297     Q.ABBREV_TAC ‘E = IMAGE (\(x,y). (Normal x,Normal y)) (UNIV CROSS UNIV)’ \\
7298     Know ‘E IN subsets (Borel CROSS Borel)’
7299     >- (Q.UNABBREV_TAC ‘E’ \\
7300         Know ‘IMAGE (\(x,y). (Normal x,Normal y)) (univ(:real) CROSS univ(:real)) =
7301                 (IMAGE Normal UNIV) CROSS (IMAGE Normal UNIV)’
7302         >- (rw [Once EXTENSION, IN_CROSS] \\
7303             Cases_on ‘x’ >> EQ_TAC >> rw [] >| (* 3 subgoals *)
7304             [ Cases_on ‘x'’ >> fs [],
7305               Cases_on ‘x'’ >> fs [],
7306               Q.EXISTS_TAC ‘(x',x'')’ >> rw [] ]) >> Rewr' \\
7307         MATCH_MP_TAC BOREL_2D_lemma5 >> REWRITE_TAC [] \\
7308         rw [Borel] \\
7309         qexistsl_tac [‘UNIV’, ‘{}’] >> rw [] \\
7310         REWRITE_TAC [GSYM space_borel] \\
7311         MATCH_MP_TAC SIGMA_ALGEBRA_SPACE \\
7312         REWRITE_TAC [sigma_algebra_borel]) >> DISCH_TAC \\
7313  (* applying TRACE_SIGMA_ALGEBRA *)
7314     Q.ABBREV_TAC ‘S = {A INTER E | A IN subsets (Borel CROSS Borel)}’ \\
7315     Know ‘sigma_algebra (E,S)’
7316     >- (Q.UNABBREV_TAC ‘S’ \\
7317         MATCH_MP_TAC TRACE_SIGMA_ALGEBRA \\
7318         rw [SPACE_BOREL_2D, SUBSET_UNIV, SIGMA_ALGEBRA_BOREL_2D]) >> DISCH_TAC \\
7319     Suff ‘D SUBSET S’
7320     >- (Q.UNABBREV_TAC ‘S’ >> DISCH_TAC \\
7321         MATCH_MP_TAC SUBSET_TRANS \\
7322         Q.EXISTS_TAC ‘{A INTER E | A IN subsets (Borel CROSS Borel)}’ >> art [] \\
7323         rw [SUBSET_DEF] \\
7324         MATCH_MP_TAC SIGMA_ALGEBRA_INTER >> art [SIGMA_ALGEBRA_BOREL_2D]) \\
7325  (* applying borel_2d_alt_box; preparing for PREIMAGE_SIGMA *)
7326     Q.ABBREV_TAC ‘f = \(x,y). (real x,real y)’ \\
7327     Know ‘D = IMAGE (\s. PREIMAGE f s INTER E)
7328                     (subsets (sigma univ(:real # real) {box a b CROSS box c d | T}))’
7329     >- (rw [Abbr ‘D’, Once EXTENSION, PREIMAGE_def, borel_2d_alt_box] \\
7330         EQ_TAC >> rw [] >| (* 2 subgoals *)
7331         [ (* goal 1 (of 2) *)
7332           Q.EXISTS_TAC ‘Z’ >> art [] \\
7333           rw [Once EXTENSION, Abbr ‘E’] \\
7334           EQ_TAC >> rw [] >| (* 3 subgoals *)
7335           [ (* goal 1.1 (of 3) *)
7336             Cases_on ‘x'’ >> rw [Abbr ‘f’, real_normal],
7337             (* goal 1.2 (of 3) *)
7338             Q.EXISTS_TAC ‘x'’ >> rw [],
7339             (* goal 1.3 (of 3) *)
7340             Q.EXISTS_TAC ‘x'’ >> rw [] \\
7341             Cases_on ‘x'’ >> fs [Abbr ‘f’, real_normal] ],
7342           (* goal 2 (of 2) *)
7343           rename1 ‘z IN subsets (sigma UNIV {box a b CROSS box c d | T})’ \\
7344           Q.EXISTS_TAC ‘z’ >> rw [] \\
7345           rw [Once EXTENSION] >> EQ_TAC >> rw [] >| (* 3 subgoals *)
7346           [ (* goal 2.1 (of 3) *)
7347             Q.EXISTS_TAC ‘f x’ >> art [] \\
7348             Cases_on ‘x’ >> rw [Abbr ‘f’, Abbr ‘E’] \\ (* 2 subgoals, same tactics *)
7349             fs [IN_IMAGE] >> Cases_on ‘x’ >> fs [],
7350             (* goal 2.2 (of 3) *)
7351             Cases_on ‘x'’ >> rw [Abbr ‘f’, real_normal],
7352             (* goal 2.3 (of 3) *)
7353             Cases_on ‘x'’ >> rw [Abbr ‘f’, Abbr ‘E’] ] ]) >> Rewr' \\
7354  (* applying PREIMAGE_SIGMA *)
7355     Know ‘IMAGE (\s. PREIMAGE f s INTER E)
7356                 (subsets (sigma univ(:real # real) {box a b CROSS box c d | T})) =
7357           subsets (sigma E (IMAGE (\s. PREIMAGE f s INTER E)
7358                                   {box a b CROSS box c d | T}))’
7359     >- (MATCH_MP_TAC PREIMAGE_SIGMA \\
7360         rw [subset_class_def, IN_FUNSET]) >> Rewr' \\
7361     Q.UNABBREV_TAC ‘D’ \\
7362  (* applying SIGMA_SUBSET *)
7363    ‘S = subsets (E,S)’ by rw [] >> POP_ORW \\
7364    ‘E = space (E,S)’ by rw [] \\
7365     POP_ASSUM ((GEN_REWRITE_TAC (RATOR_CONV o ONCE_DEPTH_CONV) empty_rewrites) o wrap) \\
7366     MATCH_MP_TAC SIGMA_SUBSET >> rw [] \\
7367     rw [SUBSET_DEF, PREIMAGE_def, Abbr ‘S’] \\
7368  (* stage work *)
7369     Q.EXISTS_TAC ‘IMAGE (\(x,y). (Normal x,Normal y)) (box a b CROSS box c d)’ \\
7370     CONJ_TAC
7371     >- (rw [Abbr ‘f’, Once EXTENSION] >> Cases_on ‘x’ >> rw [Abbr ‘E’] \\
7372         EQ_TAC >> rw [] >| (* 3 subgoals *)
7373         [ Q.EXISTS_TAC ‘(real q,real r)’ >> Cases_on ‘x’ >> fs [],
7374           Cases_on ‘x’ >> Cases_on ‘x'’ >> fs [],
7375           Cases_on ‘x’ >> Cases_on ‘x'’ >> fs [] ]) \\
7376  (* final stage *)
7377     rw [prod_sigma_def, SPACE_BOREL, GSYM CROSS_UNIV] \\
7378     Suff ‘IMAGE (\(x,y). (Normal x,Normal y)) (box a b CROSS box c d) IN
7379           prod_sets (subsets Borel) (subsets Borel)’
7380     >- METIS_TAC [SUBSET_DEF, SIGMA_SUBSET_SUBSETS] \\
7381     rw [IN_PROD_SETS, box] \\
7382     qexistsl_tac [‘{x | Normal a < x /\ x < Normal b}’,
7383                   ‘{x | Normal c < x /\ x < Normal d}’] \\
7384     rw [BOREL_MEASURABLE_SETS, Once EXTENSION] \\
7385     EQ_TAC >> rw [] >| (* 5 subgoals *)
7386     [ (* goal 1 (of 5) *) Cases_on ‘x'’ >> fs [extreal_lt_eq],
7387       (* goal 2 (of 5) *) Cases_on ‘x'’ >> fs [extreal_lt_eq],
7388       (* goal 3 (of 5) *) Cases_on ‘x'’ >> fs [extreal_lt_eq],
7389       (* goal 4 (of 5) *) Cases_on ‘x'’ >> fs [extreal_lt_eq],
7390       (* goal 5 (of 5) *)
7391       Cases_on ‘x’ >> fs [] \\
7392       Know ‘q <> PosInf /\ q <> NegInf’
7393       >- (CONJ_TAC >> CCONTR_TAC >> fs [lt_infty]) >> STRIP_TAC \\
7394       Know ‘r <> PosInf /\ r <> NegInf’
7395       >- (CONJ_TAC >> CCONTR_TAC >> fs [lt_infty]) >> STRIP_TAC \\
7396       Q.EXISTS_TAC ‘(real q,real r)’ >> rw [normal_real] \\ (* 4 subgoals, same tactics *)
7397       RW_TAC std_ss [GSYM extreal_lt_eq, normal_real] ])
7398 (* stage work (tedious part) *)
7399 >> REWRITE_TAC [prod_sigma_def]
7400 >> ‘space Borel CROSS space Borel = space S’ by rw [Abbr ‘S’, SPACE_BOREL, CROSS_UNIV]
7401 >> POP_ORW
7402 >> MATCH_MP_TAC SIGMA_SUBSET
7403 (* applying BOREL_2D_lemma3 *)
7404 >> CONJ_TAC >- rw [BOREL_2D_lemma3, Abbr ‘S’]
7405 >> ‘{} IN subsets borel’ by (MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY \\
7406                              REWRITE_TAC [sigma_algebra_borel])
7407 >> rw [Once SUBSET_DEF, IN_PROD_SETS, Borel, Abbr ‘S’] (* 16 subgoals *)
7408 >> ‘B CROSS B' IN subsets (borel CROSS borel)’
7409      by (MATCH_MP_TAC BOREL_2D_lemma4 >> art [])
7410 >> Q.EXISTS_TAC ‘B CROSS B'’
7411 >| [ (* goal 1 (of 16) *)
7412      qexistsl_tac [‘{}’, ‘{}’, ‘{}’, ‘{}’] \\
7413      rw [UNION_EMPTY, CROSS_EMPTY] \\
7414      rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7415      Cases_on ‘x’ >> rw [] \\
7416      EQ_TAC >> rw [] >| (* 3 subgoals *)
7417      [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7418        rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7419        rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7420      (* goal 2 (of 16) *)
7421      qexistsl_tac [‘{}’, ‘{}’, ‘{}’, ‘IMAGE Normal B’] \\
7422      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 2 subgoals *)
7423      [ (* goal 2.1 (of 2) *)
7424        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7425        Cases_on ‘x’ >> rw [] \\
7426        EQ_TAC >> rw [] >| (* 3 subgoals *)
7427        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7428          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7429          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7430        (* goal 2.3 (of 2) *)
7431        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7432      (* goal 3 (of 16) *)
7433      qexistsl_tac [‘{}’, ‘{}’, ‘IMAGE Normal B’, ‘{}’] \\
7434      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 2 subgoals *)
7435      [ (* goal 3.1 (of 2) *)
7436        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7437        Cases_on ‘x’ >> rw [] \\
7438        EQ_TAC >> rw [] >| (* 3 subgoals *)
7439        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7440          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7441          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7442        (* goal 3.3 (of 2) *)
7443        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7444      (* goal 4 (of 16) *)
7445      qexistsl_tac [‘{}’, ‘{}’, ‘IMAGE Normal B’, ‘IMAGE Normal B’] \\
7446      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 3 subgoals *)
7447      [ (* goal 4.1 (of 3) *)
7448        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7449        Cases_on ‘x’ >> rw [] \\
7450        EQ_TAC >> rw [] >| (* 3 subgoals *)
7451        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7452          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7453          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7454        (* goal 4.2 (of 3) *)
7455        qexistsl_tac [‘B’, ‘{}’] >> rw [],
7456        (* goal 4.3 (of 3) *)
7457        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7458      (* goal 5 (of 16) *)
7459      qexistsl_tac [‘{}’, ‘IMAGE Normal B'’, ‘{}’, ‘{}’] \\
7460      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 2 subgoals *)
7461      [ (* goal 5.1 (of 2) *)
7462        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7463        Cases_on ‘x’ >> rw [] \\
7464        EQ_TAC >> rw [] >| (* 3 subgoals *)
7465        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7466          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7467          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7468        (* goal 5.2 (of 2) *)
7469        qexistsl_tac [‘B'’, ‘{}’] >> rw [] ],
7470      (* goal 6 (of 16) *)
7471      qexistsl_tac [‘{}’, ‘(IMAGE Normal B') UNION {NegInf}’, ‘{}’, ‘IMAGE Normal B’] \\
7472      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 3 subgoals *)
7473      [ (* goal 6.1 (of 3) *)
7474        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7475        Cases_on ‘x’ >> rw [] \\
7476        EQ_TAC >> rw [] >| (* 3 subgoals *)
7477        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7478          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7479          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7480        (* goal 6.2 (of 3) *)
7481        qexistsl_tac [‘B'’, ‘{NegInf}’] >> rw [],
7482        (* goal 6.3 (of 3) *)
7483        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7484      (* goal 7 (of 16) *)
7485      qexistsl_tac [‘{}’, ‘(IMAGE Normal B') UNION {PosInf}’, ‘IMAGE Normal B’, ‘{}’] \\
7486      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 3 subgoals *)
7487      [ (* goal 7.1 (of 3) *)
7488        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7489        Cases_on ‘x’ >> rw [] \\
7490        EQ_TAC >> rw [] >| (* 3 subgoals *)
7491        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7492          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7493          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7494        (* goal 7.2 (of 3) *)
7495        qexistsl_tac [‘B'’, ‘{PosInf}’] >> rw [],
7496        (* goal 7.3 (of 3) *)
7497        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7498      (* goal 8 (of 16) *)
7499      qexistsl_tac [‘{}’, ‘(IMAGE Normal B') UNION {NegInf; PosInf}’,
7500                    ‘IMAGE Normal B’, ‘IMAGE Normal B’] \\
7501      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 4 subgoals *)
7502      [ (* goal 8.1 (of 4) *)
7503        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7504        Cases_on ‘x’ >> rw [] \\
7505        EQ_TAC >> rw [] >| (* 3 subgoals *)
7506        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7507          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7508          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7509        (* goal 8.2 (of 4) *)
7510        qexistsl_tac [‘B'’, ‘{NegInf;PosInf}’] >> rw [],
7511        (* goal 8.3 (of 4) *)
7512        qexistsl_tac [‘B’, ‘{}’] >> rw [],
7513        (* goal 8.4 (of 4) *)
7514        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7515      (* goal 9 (of 16) *)
7516      qexistsl_tac [‘IMAGE Normal B'’, ‘{}’, ‘{}’, ‘{}’] \\
7517      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 2 subgoals *)
7518      [ (* goal 9.1 (of 2) *)
7519        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7520        Cases_on ‘x’ >> rw [] \\
7521        EQ_TAC >> rw [] >| (* 3 subgoals *)
7522        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7523          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7524          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7525        (* goal 9.2 (of 2) *)
7526        qexistsl_tac [‘B'’, ‘{}’] >> rw [] ],
7527      (* goal 10 (of 16) *)
7528      qexistsl_tac [‘(IMAGE Normal B') UNION {NegInf}’, ‘{}’,
7529                    ‘{}’, ‘IMAGE Normal B’] \\
7530      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 3 subgoals *)
7531      [ (* goal 10.1 (of 3) *)
7532        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7533        Cases_on ‘x’ >> rw [] \\
7534        EQ_TAC >> rw [] >| (* 3 subgoals *)
7535        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7536          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7537          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7538        (* goal 10.3 (of 3) *)
7539        qexistsl_tac [‘B'’, ‘{NegInf}’] >> rw [],
7540        (* goal 10.3 (of 3) *)
7541        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7542      (* goal 11 (of 16) *)
7543      qexistsl_tac [‘(IMAGE Normal B') UNION {PosInf}’, ‘{}’,
7544                    ‘IMAGE Normal B’, ‘{}’] \\
7545      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 3 subgoals *)
7546      [ (* goal 11.1 (of 3) *)
7547        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7548        Cases_on ‘x’ >> rw [] \\
7549        EQ_TAC >> rw [] >| (* 3 subgoals *)
7550        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7551          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7552          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7553        (* goal 11.2 (of 3) *)
7554        qexistsl_tac [‘B'’, ‘{PosInf}’] >> rw [],
7555        (* goal 11.3 (of 3) *)
7556        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7557      (* goal 12 (of 16) *)
7558      qexistsl_tac [‘(IMAGE Normal B') UNION {NegInf;PosInf}’, ‘{}’,
7559                    ‘IMAGE Normal B’, ‘IMAGE Normal B’] \\
7560      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 4 subgoals *)
7561      [ (* goal 12.1 (of 4) *)
7562        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7563        Cases_on ‘x’ >> rw [] \\
7564        EQ_TAC >> rw [] >| (* 3 subgoals *)
7565        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7566          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7567          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7568        (* goal 12.2 (of 4) *)
7569        qexistsl_tac [‘B'’, ‘{NegInf;PosInf}’] >> rw [],
7570        (* goal 12.3 (of 4) *)
7571        qexistsl_tac [‘B’, ‘{}’] >> rw [],
7572        (* goal 12.4 (of 4) *)
7573        qexistsl_tac [‘B’, ‘{}’] >> rw [] ],
7574      (* goal 13 (of 16) *)
7575      qexistsl_tac [‘IMAGE Normal B'’, ‘IMAGE Normal B'’, ‘{}’, ‘{}’] \\
7576      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 3 subgoals *)
7577      [ (* goal 13.1 (of 3) *)
7578        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7579        Cases_on ‘x’ >> rw [] \\
7580        EQ_TAC >> rw [] >| (* 3 subgoals *)
7581        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7582          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7583          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7584        (* goal 13.2 (of 3) *)
7585        qexistsl_tac [‘B'’, ‘{}’] >> rw [],
7586        (* goal 13.3 (of 3) *)
7587        qexistsl_tac [‘B'’, ‘{}’] >> rw [] ],
7588      (* goal 14 (of 16) *)
7589      qexistsl_tac [‘(IMAGE Normal B') UNION {NegInf}’,
7590                    ‘(IMAGE Normal B') UNION {NegInf}’,
7591                    ‘{}’, ‘(IMAGE Normal B) UNION {NegInf;PosInf}’] \\
7592      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 4 subgoals *)
7593      [ (* goal 14.1 (of 4) *)
7594        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7595        Cases_on ‘x’ >> rw [] \\
7596        EQ_TAC >> rw [] >| (* 3 subgoals *)
7597        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7598          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7599          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7600        (* goal 14.2 (of 4) *)
7601        qexistsl_tac [‘B'’, ‘{NegInf}’] >> rw [],
7602        (* goal 14.3 (of 4) *)
7603        qexistsl_tac [‘B'’, ‘{NegInf}’] >> rw [],
7604        (* goal 14.4 (of 4) *)
7605        qexistsl_tac [‘B’, ‘{NegInf;PosInf}’] >> rw [] ],
7606      (* goal 15 (of 16) *)
7607      qexistsl_tac [‘(IMAGE Normal B') UNION {PosInf}’,
7608                    ‘(IMAGE Normal B') UNION {PosInf}’,
7609                    ‘(IMAGE Normal B) UNION {NegInf;PosInf}’, ‘{}’] \\
7610      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 4 subgoals *)
7611      [ (* goal 15.1 (of 4) *)
7612        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7613        Cases_on ‘x’ >> rw [] \\
7614        EQ_TAC >> rw [] >| (* 3 subgoals *)
7615        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7616          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7617          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7618        (* goal 15.2 (of 4) *)
7619        qexistsl_tac [‘B'’, ‘{PosInf}’] >> rw [],
7620        (* goal 15.3 (of 4) *)
7621        qexistsl_tac [‘B'’, ‘{PosInf}’] >> rw [],
7622        (* goal 15.4 (of 4) *)
7623        qexistsl_tac [‘B’, ‘{NegInf;PosInf}’] >> rw [] ],
7624      (* goal 16 (of 16) *)
7625      qexistsl_tac [‘(IMAGE Normal B') UNION {NegInf;PosInf}’,
7626                    ‘(IMAGE Normal B') UNION {NegInf;PosInf}’,
7627                    ‘(IMAGE Normal B) UNION {NegInf;PosInf}’,
7628                    ‘(IMAGE Normal B) UNION {NegInf;PosInf}’] \\
7629      rw [UNION_EMPTY, CROSS_EMPTY] >| (* 5 subgoals *)
7630      [ (* goal 16.1 (of 5) *)
7631        rw [Once EXTENSION, IN_IMAGE, IN_CROSS] \\
7632        Cases_on ‘x’ >> rw [] \\
7633        EQ_TAC >> rw [] >| (* 3 subgoals *)
7634        [ Q.EXISTS_TAC ‘(x',x'')’ >> rw [],
7635          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [],
7636          rename1 ‘FST z IN B’ >> Cases_on ‘z’ >> fs [] ],
7637        (* goal 16.2 (of 5) *)
7638        qexistsl_tac [‘B'’, ‘{NegInf;PosInf}’] >> rw [],
7639        (* goal 16.3 (of 5) *)
7640        qexistsl_tac [‘B'’, ‘{NegInf;PosInf}’] >> rw [],
7641        (* goal 16.4 (of 5) *)
7642        qexistsl_tac [‘B’, ‘{NegInf;PosInf}’] >> rw [],
7643        (* goal 16.5 (of 5) *)
7644        qexistsl_tac [‘B’, ‘{NegInf;PosInf}’] >> rw [] ] ]
7645QED
7646
7647Theorem IN_MEASURABLE_BOREL_BOREL_I :
7648    (\x. x) IN measurable Borel Borel
7649Proof
7650    ‘(\x :extreal. x) = I’ by METIS_TAC [I_THM]
7651 >> POP_ORW
7652 >> MATCH_MP_TAC MEASURABLE_I
7653 >> REWRITE_TAC [SIGMA_ALGEBRA_BOREL]
7654QED
7655
7656Theorem IN_MEASURABLE_BOREL_BOREL_ABS :
7657    abs IN measurable Borel Borel
7658Proof
7659    MATCH_MP_TAC IN_MEASURABLE_BOREL_ABS
7660 >> Q.EXISTS_TAC ‘\x. x’
7661 >> rw [SIGMA_ALGEBRA_BOREL, IN_MEASURABLE_BOREL_BOREL_I, SPACE_BOREL]
7662QED
7663
7664(* cf. stochastic_processTheory.random_variable_sigma_of_dimension for a
7665   generalization of this theorem to arbitrary finite dimensions.
7666 *)
7667Theorem IN_MEASURABLE_BOREL_2D_VECTOR :
7668    !a X Y. sigma_algebra a /\
7669            X IN measurable a Borel /\ Y IN measurable a Borel ==>
7670            (\x. (X x,Y x)) IN measurable a (Borel CROSS Borel)
7671Proof
7672    rpt STRIP_TAC
7673 >> MATCH_MP_TAC MEASURABLE_PAIR
7674 >> rw [SIGMA_ALGEBRA_BOREL]
7675QED
7676
7677Theorem IN_MEASURABLE_BOREL_2D_FUNCTION :
7678    !a X Y f. sigma_algebra a /\
7679              X IN measurable a Borel /\ Y IN measurable a Borel /\
7680              f IN measurable (Borel CROSS Borel) Borel ==>
7681              (\x. f (X x,Y x)) IN measurable a Borel
7682Proof
7683    rpt STRIP_TAC
7684 >> Q.ABBREV_TAC ‘g = \x. (X x,Y x)’
7685 >> ‘(\x. f (X x,Y x)) = f o g’ by rw [Abbr ‘g’, o_DEF] >> POP_ORW
7686 >> MATCH_MP_TAC MEASURABLE_COMP
7687 >> Q.EXISTS_TAC ‘Borel CROSS Borel’ >> art []
7688 >> Q.UNABBREV_TAC ‘g’
7689 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_2D_VECTOR >> art []
7690QED
7691
7692Theorem IN_MEASURABLE_BOREL_2D_MUL :
7693    (\(x,y). x * y) IN measurable (Borel CROSS Borel) Borel
7694Proof
7695    simp [IN_MEASURABLE, SIGMA_ALGEBRA_BOREL_2D, SPACE_BOREL, IN_FUNSET,
7696          SIGMA_ALGEBRA_BOREL, SPACE_PROD_SIGMA, SYM CROSS_UNIV]
7697 >> Q.ABBREV_TAC ‘f = \(x :extreal,y). x * y’
7698 >> Suff ‘IMAGE (\s. PREIMAGE f s INTER (UNIV CROSS UNIV)) (subsets Borel) SUBSET
7699          subsets (Borel CROSS Borel)’
7700 >- (rw [SUBSET_DEF, IN_IMAGE] \\
7701     FIRST_X_ASSUM MATCH_MP_TAC \\
7702     Q.EXISTS_TAC ‘s’ \\
7703     rw [Once EXTENSION, SYM CROSS_UNIV])
7704 >> Q.ABBREV_TAC ‘Z = univ(:extreal) CROSS univ(:extreal)’
7705 >> GEN_REWRITE_TAC (RATOR_CONV o ONCE_DEPTH_CONV) empty_rewrites [Borel_eq_gr]
7706 >> Q.ABBREV_TAC ‘sts = IMAGE (\a. {x | Normal a < x}) univ(:real)’
7707 (* applying PREIMAGE_SIGMA *)
7708 >> Know ‘IMAGE (\s. PREIMAGE f s INTER Z) (subsets (sigma UNIV sts)) =
7709          subsets (sigma Z (IMAGE (\s. PREIMAGE f s INTER Z) sts))’
7710 >- (MATCH_MP_TAC PREIMAGE_SIGMA >> rw [IN_FUNSET, subset_class_def])
7711 >> Rewr'
7712 >> Suff ‘(IMAGE (\s. PREIMAGE f s INTER Z) sts) SUBSET
7713            subsets (Borel CROSS Borel)’
7714 >- (DISCH_THEN (MP_TAC o (Q.SPEC ‘Z’) o (MATCH_MP SIGMA_MONOTONE)) \\
7715     Suff ‘sigma Z (subsets (Borel CROSS Borel)) = Borel CROSS Borel’ >- rw [] \\
7716     Know ‘Z = space (Borel CROSS Borel)’
7717     >- rw [Abbr ‘Z’, prod_sigma_def, SPACE_SIGMA, SPACE_BOREL] >> Rewr' \\
7718     MATCH_MP_TAC SIGMA_STABLE \\
7719     REWRITE_TAC [SIGMA_ALGEBRA_BOREL_2D])
7720 >> rw [SUBSET_DEF, Abbr ‘sts’, Abbr ‘Z’, SYM CROSS_UNIV]
7721 (* start using ‘*’ *)
7722 >> rw [Abbr ‘f’, PREIMAGE_def]
7723 >> ‘{x | Normal a < (\(x,y). x * y) x} = {(x,y) | Normal a < x * y}’ by SET_TAC []
7724 >> POP_ORW
7725 (* applying BOREL_2D, then case analysis on ‘a’ *)
7726 >> rw [BOREL_2D]
7727 >> Cases_on ‘0 <= a’
7728 >- (qexistsl_tac [‘{(x,y) | a < x * y}’,
7729                   ‘{y | 0 < y}’, ‘{y | y < 0}’, ‘{x | 0 < x}’, ‘{x | x < 0}’] \\
7730     rw [BOREL_MEASURABLE_SETS]
7731     >- (rw [Once EXTENSION] >> Cases_on ‘x’ \\
7732         EQ_TAC >> rw [GSYM extreal_of_num_def] >| (* 6 subgoals *)
7733         [ (* goal 1 (of 6) *)
7734           Cases_on ‘q’ >> Cases_on ‘r’ >> Cases_on ‘0 < r'’ \\
7735           rw [extreal_mul_def, extreal_of_num_def, extreal_lt_eq, lt_infty] \\
7736           fs [extreal_mul_def, lt_infty, extreal_of_num_def] >| (* 8 subgoals *)
7737           [ (* goal 1.1 (of 8) *)
7738            ‘r' <> 0’ by PROVE_TAC [REAL_LT_IMP_NE] >> fs [lt_infty, extreal_of_num_def],
7739             (* goal 1.2 (of 8) *)
7740            ‘r' = 0 \/ (r' <> 0 /\ r' < 0)’ by PROVE_TAC [REAL_LT_TOTAL]
7741             >- fs [real_lte, extreal_lt_eq] \\
7742             fs [lt_infty, extreal_of_num_def],
7743             (* goal 1.3 (of 8) *)
7744            ‘r' = 0 \/ (r' <> 0 /\ r' < 0)’ by PROVE_TAC [REAL_LT_TOTAL]
7745             >- fs [real_lte, extreal_lt_eq] \\
7746             fs [lt_infty, extreal_of_num_def],
7747             (* goal 1.4 (of 8) *)
7748            ‘r' <> 0’ by PROVE_TAC [REAL_LT_IMP_NE] >> fs [lt_infty, extreal_of_num_def],
7749             (* goal 1.5 (of 8) *)
7750            ‘r' = 0 \/ (r' <> 0 /\ r' < 0)’ by PROVE_TAC [REAL_LT_TOTAL]
7751             >- fs [real_lte, extreal_lt_eq] \\
7752             fs [lt_infty, extreal_of_num_def],
7753             (* goal 1.6 (of 8) *)
7754            ‘r' = 0 \/ (r' <> 0 /\ r' < 0)’ by PROVE_TAC [REAL_LT_TOTAL]
7755             >- fs [real_lte, extreal_lt_eq] \\
7756             fs [lt_infty, extreal_of_num_def],
7757             (* goal 1.7 (of 8) *)
7758             Q.EXISTS_TAC ‘(r',r'')’ >> rw [] >> fs [extreal_lt_eq],
7759             (* goal 1.8 (of 8) *)
7760             Q.EXISTS_TAC ‘(r',r'')’ >> rw [] >> fs [extreal_lt_eq] ],
7761           (* goal 2 (of 6) *)
7762           fs [extreal_mul_def, extreal_lt_eq] \\
7763           rw [extreal_of_num_def, extreal_lt_eq],
7764           (* goal 3 (of 6) *)
7765           rw [mul_infty, lt_infty],
7766           (* goal 4 (of 6) *)
7767           rw [mul_infty', lt_infty],
7768           (* goal 5 (of 6) *)
7769           rw [mul_infty, lt_infty],
7770           (* goal 6 (of 6) *)
7771           rw [mul_infty', lt_infty] ]) \\
7772      rw [borel_2d] \\
7773      Suff ‘{(x,y) | a < x * y} IN {s | open_in (mtop mr2) s}’
7774      >- METIS_TAC [SUBSET_DEF, SIGMA_SUBSET_SUBSETS] \\
7775      REWRITE_TAC [hyperbola_open_in_mr2])
7776 >> qexistsl_tac [‘{(x,y) | a < x * y}’,
7777                  ‘{y | 0 <= y}’, ‘{y | y <= 0}’, ‘{x | 0 <= x}’, ‘{x | x <= 0}’]
7778 >> rw [BOREL_MEASURABLE_SETS]
7779 >- (rw [Once EXTENSION] >> Cases_on ‘x’ \\
7780     EQ_TAC >> rw [GSYM extreal_of_num_def] >| (* 6 subgoals *)
7781     [ (* goal 1 (of 6) *)
7782       Cases_on ‘q’ >> Cases_on ‘r’ >> Cases_on ‘0 < r'’ \\
7783       rw [extreal_mul_def, extreal_of_num_def, extreal_lt_eq, lt_infty, le_infty] \\
7784       fs [extreal_mul_def, lt_infty, le_infty,
7785           extreal_of_num_def] >| (* 10 subgoals *)
7786       [ (* goal 1 (of 10) *)
7787        ‘r' <> 0’ by PROVE_TAC [REAL_LT_IMP_NE] \\
7788         fs [le_infty, lt_infty, extreal_of_num_def],
7789         (* goal 2 (of 10) *)
7790        ‘r' = 0 \/ (r' <> 0 /\ r' < 0)’ by PROVE_TAC [REAL_LT_TOTAL]
7791         >- fs [real_lte, extreal_lt_eq, extreal_le_eq] \\
7792         fs [lt_infty, extreal_of_num_def, extreal_le_eq, real_lte],
7793         (* goal 3 (of 10) *)
7794        ‘r' <> 0’ by PROVE_TAC [REAL_LT_IMP_NE] \\
7795         fs [le_infty, lt_infty, extreal_of_num_def, extreal_le_eq] \\
7796         DISJ2_TAC >> MATCH_MP_TAC REAL_LT_IMP_LE >> art [],
7797         (* goal 4 (of 10) *)
7798        ‘r' = 0 \/ (r' <> 0 /\ r' < 0)’ by PROVE_TAC [REAL_LT_TOTAL]
7799         >- fs [real_lte, extreal_lt_eq, extreal_le_eq] \\
7800         fs [lt_infty, extreal_of_num_def, extreal_le_eq, real_lte],
7801         (* goal 5 (of 10) *)
7802        ‘r' <> 0’ by PROVE_TAC [REAL_LT_IMP_NE] \\
7803         fs [le_infty, lt_infty, extreal_of_num_def, extreal_le_eq],
7804         (* goal 6 (of 10) *)
7805        ‘r' = 0 \/ (r' <> 0 /\ r' < 0)’ by PROVE_TAC [REAL_LT_TOTAL]
7806         >- fs [real_lte, extreal_lt_eq, extreal_le_eq] \\
7807         fs [lt_infty, extreal_of_num_def, extreal_le_eq, real_lte],
7808         (* goal 7 (of 10) *)
7809        ‘r' <> 0’ by PROVE_TAC [REAL_LT_IMP_NE] \\
7810         fs [le_infty, lt_infty, extreal_of_num_def, extreal_le_eq] \\
7811         DISJ2_TAC >> MATCH_MP_TAC REAL_LT_IMP_LE >> art [],
7812         (* goal 8 (of 10) *)
7813        ‘r' = 0 \/ (r' <> 0 /\ r' < 0)’ by PROVE_TAC [REAL_LT_TOTAL]
7814         >- fs [real_lte, extreal_lt_eq, extreal_le_eq] \\
7815         fs [lt_infty, extreal_of_num_def, extreal_le_eq, real_lte],
7816         (* goal 9 (of 10) *)
7817         Q.EXISTS_TAC ‘(r',r'')’ >> rw [] >> fs [extreal_lt_eq],
7818         (* goal 10 (of 10) *)
7819         Q.EXISTS_TAC ‘(r',r'')’ >> rw [] >> fs [extreal_lt_eq] ],
7820       (* goal 2 (of 6) *)
7821       fs [extreal_mul_def, extreal_lt_eq],
7822       (* goal 3 (of 6) *)
7823      ‘r = 0 \/ 0 < r’ by PROVE_TAC [le_lt]
7824       >- (rw [mul_rzero, extreal_of_num_def, extreal_lt_eq] \\
7825           fs [real_lte]) \\
7826       rw [mul_infty, lt_infty],
7827       (* goal 4 (of 6) *)
7828      ‘r = 0 \/ r < 0’ by PROVE_TAC [le_lt]
7829       >- (rw [mul_rzero, extreal_of_num_def, extreal_lt_eq] \\
7830           fs [real_lte]) \\
7831       rw [mul_infty', lt_infty],
7832       (* goal 5 (of 6) *)
7833      ‘q = 0 \/ 0 < q’ by PROVE_TAC [le_lt]
7834       >- (rw [mul_rzero, extreal_of_num_def, extreal_lt_eq] \\
7835           fs [real_lte]) \\
7836       rw [mul_infty, lt_infty],
7837       (* goal 6 (of 6) *)
7838      ‘q = 0 \/ q < 0’ by PROVE_TAC [le_lt]
7839       >- (rw [mul_rzero, extreal_of_num_def, extreal_lt_eq] \\
7840           fs [real_lte]) \\
7841       rw [mul_infty', lt_infty] ])
7842 >> rw [borel_2d]
7843 >> Suff ‘{(x,y) | a < x * y} IN {s | open_in (mtop mr2) s}’
7844 >- METIS_TAC [SUBSET_DEF, SIGMA_SUBSET_SUBSETS]
7845 >> REWRITE_TAC [hyperbola_open_in_mr2]
7846QED
7847
7848Theorem IN_MEASURABLE_BOREL_TIMES' :
7849    !a f g h. sigma_algebra a /\ f IN measurable a Borel /\ g IN measurable a Borel /\
7850             (!x. x IN space a ==> h x = f x * g x) ==> h IN measurable a Borel
7851Proof
7852    rpt STRIP_TAC
7853 >> Q.ABBREV_TAC ‘ff = \(x :extreal,y). x * y’
7854 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_EQ'
7855 >> Q.EXISTS_TAC ‘\x. ff (f x,g x)’ >> rw []
7856 >- rw [Abbr ‘ff’]
7857 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_2D_FUNCTION >> art []
7858 >> rw [Abbr ‘ff’, IN_MEASURABLE_BOREL_2D_MUL]
7859QED
7860
7861Theorem IN_MEASURABLE_BOREL_TIMES :
7862  !m f g h.
7863     measure_space m /\
7864     f IN measurable (m_space m, measurable_sets m) Borel /\
7865     g IN measurable (m_space m, measurable_sets m) Borel /\
7866     (!x. x IN m_space m ==> (h x = f x * g x)) ==>
7867     h IN measurable (m_space m, measurable_sets m) Borel
7868Proof
7869    rpt STRIP_TAC
7870 >> MP_TAC (Q.SPECL [‘(m_space m,measurable_sets m)’, ‘f’, ‘g’, ‘h’]
7871                    IN_MEASURABLE_BOREL_TIMES')
7872 >> fs [measure_space_def]
7873QED
7874
7875Theorem IN_MEASURABLE_BOREL_BOREL_CONST :
7876    !c. (\x. c) IN measurable Borel Borel
7877Proof
7878    Q.X_GEN_TAC ‘c’
7879 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_CONST
7880 >> Q.EXISTS_TAC ‘c’
7881 >> rw [SIGMA_ALGEBRA_BOREL]
7882QED
7883
7884Theorem IN_MEASURABLE_BOREL_BOREL_AINV :
7885    extreal_ainv IN measurable Borel Borel
7886Proof
7887    Know ‘$extreal_ainv = \x. -1 * x’
7888 >- (rw [FUN_EQ_THM, Once neg_minus1])
7889 >> Rewr'
7890 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_CMUL
7891 >> qexistsl_tac [‘\x. x’, ‘-1’]
7892 >> rw [SIGMA_ALGEBRA_BOREL, IN_MEASURABLE_BOREL_BOREL_I, SPACE_BOREL,
7893        extreal_of_num_def, extreal_ainv_def, extreal_mul_def]
7894QED
7895
7896Theorem IN_MEASURABLE_BOREL_BOREL_MAX :
7897    !c. (\x. max x c) IN measurable Borel Borel
7898Proof
7899    Q.X_GEN_TAC ‘c’
7900 >> MATCH_MP_TAC
7901      (BETA_RULE (Q.SPECL [‘Borel’, ‘\x :extreal. x’, ‘\x :extreal. c’]
7902                          (INST_TYPE [“:'a” |-> “:extreal”] IN_MEASURABLE_BOREL_MAX)))
7903 >> rw [IN_MEASURABLE_BOREL_BOREL_I, IN_MEASURABLE_BOREL_BOREL_CONST,
7904        SIGMA_ALGEBRA_BOREL]
7905QED
7906
7907Theorem IN_MEASURABLE_BOREL_BOREL_MIN :
7908    !c. (\x. min x c) IN measurable Borel Borel
7909Proof
7910    Q.X_GEN_TAC ‘c’
7911 >> MATCH_MP_TAC
7912      (BETA_RULE (Q.SPECL [‘Borel’, ‘\x :extreal. x’, ‘\x :extreal. c’]
7913                          (INST_TYPE [“:'a” |-> “:extreal”] IN_MEASURABLE_BOREL_MIN)))
7914 >> rw [IN_MEASURABLE_BOREL_BOREL_I, IN_MEASURABLE_BOREL_BOREL_CONST,
7915        SIGMA_ALGEBRA_BOREL]
7916QED
7917
7918Theorem IN_MEASURABLE_BOREL_BOREL_POW :
7919    !n. (\x. x pow n) IN measurable Borel Borel
7920Proof
7921    Induct_on ‘n’
7922 >- REWRITE_TAC [pow_0, IN_MEASURABLE_BOREL_BOREL_CONST]
7923 >> REWRITE_TAC [extreal_pow]
7924 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_TIMES'
7925 >> qexistsl_tac [‘\x. x’, ‘\x. x pow n’]
7926 >> rw [SPACE_BOREL, SIGMA_ALGEBRA_BOREL, IN_MEASURABLE_BOREL_BOREL_I]
7927QED
7928
7929(* Improved without ‘f x <> NegInf /\ f x <> PosInf’ (and also ‘sigma_algebra a’) *)
7930Theorem IN_MEASURABLE_BOREL_POW :
7931    !n a f. f IN measurable a Borel ==> (\x. (f x) pow n) IN measurable a Borel
7932Proof
7933    rpt STRIP_TAC
7934 >> ‘(\x. f x pow n) = (\x. x pow n) o f’ by rw [o_DEF] >> POP_ORW
7935 >> MATCH_MP_TAC MEASURABLE_COMP
7936 >> Q.EXISTS_TAC ‘Borel’
7937 >> rw [IN_MEASURABLE_BOREL_BOREL_POW]
7938QED
7939
7940(* IMPORTANT: every mono-increasing function is Borel measurable!
7941
7942   This is also Problem 8.21 of [1, p.70], the easy part!
7943 *)
7944Theorem IN_MEASURABLE_BOREL_MONO_INCREASING :
7945    !f sp. (!x y. x <= y ==> f x <= f y) /\ sp IN subsets Borel ==>
7946           f IN measurable (restrict_algebra Borel sp) Borel
7947Proof
7948    rpt STRIP_TAC
7949 >> ASSUME_TAC SIGMA_ALGEBRA_BOREL
7950 >> ‘sigma_algebra (restrict_algebra Borel sp)’
7951       by PROVE_TAC [sigma_algebra_restrict_algebra]
7952 >> rw [IN_MEASURABLE_BOREL, restrict_algebra_def, SPACE_BOREL, IN_FUNSET]
7953 >> Q.ABBREV_TAC ‘A = {x | f x < Normal c}’
7954 (* step 1 *)
7955 >> Cases_on ‘!y. f y < Normal c’
7956 >- (Q.EXISTS_TAC ‘A’ \\
7957     rw [Abbr ‘A’, GSYM SPACE_BOREL, SIGMA_ALGEBRA_SPACE])
7958 >> POP_ASSUM (STRIP_ASSUME_TAC o (SIMP_RULE bool_ss [extreal_lt_def]))
7959 (* step 2 *)
7960 >> Cases_on ‘!x. Normal c <= f x’
7961 >- (Know ‘A = EMPTY’
7962     >- (rw [Abbr ‘A’, NOT_IN_EMPTY, Once EXTENSION, extreal_lt_def]) >> Rewr' \\
7963     Q.EXISTS_TAC ‘{}’ >> rw [])
7964 >> fs [GSYM extreal_lt_def]
7965 >> Q.PAT_X_ASSUM ‘sigma_algebra Borel’ K_TAC (* not needed *)
7966 (* step 3 *)
7967 >> Cases_on ‘?z. f z = Normal c’
7968 >- (FULL_SIMP_TAC bool_ss [] (* but z may not be unique! *) \\
7969     Q.ABBREV_TAC ‘z0 = inf {x | f x = Normal c}’ \\
7970     Cases_on ‘f z0 = Normal c’ >| (* 2 subgoals *)
7971     [ (* goal 1 (of 2) *)
7972       Suff ‘A = {x | x < z0}’
7973       >- (DISCH_TAC \\
7974           Q.EXISTS_TAC ‘A’ >> rw [BOREL_MEASURABLE_SETS]) \\
7975       rw [Abbr ‘A’, Once EXTENSION] \\
7976       rename1 ‘f t < Normal c <=> t < z0’ \\
7977       EQ_TAC >> rw [Abbr ‘z0’] >| (* 2 subgoals *)
7978       [ (* goal 1.1 (of 2) *)
7979         SPOSE_NOT_THEN (STRIP_ASSUME_TAC o (REWRITE_RULE [extreal_lt_def])) \\
7980         POP_ASSUM (MP_TAC o (REWRITE_RULE [inf_le'])) \\
7981         rw [GSYM extreal_lt_def] \\
7982         Q.PAT_X_ASSUM ‘Normal c <= f y’ K_TAC (* useless *) \\
7983         Q.PAT_X_ASSUM ‘f x < Normal c’  K_TAC (* useless *) \\
7984         Q.EXISTS_TAC ‘inf {x | f x = Normal c}’ \\
7985         reverse CONJ_TAC >- METIS_TAC [extreal_lt_def] \\
7986         Q.X_GEN_TAC ‘y’ >> rw [inf_le'],
7987         (* goal 1.2 (of 2) *)
7988         Q.PAT_X_ASSUM ‘f z = Normal c’ K_TAC (* useless *) \\
7989         Q.PAT_ASSUM ‘f _ = Normal c’ (ONCE_REWRITE_TAC o wrap o SYM) \\
7990         REWRITE_TAC [lt_le] \\
7991         CONJ_TAC >- (FIRST_X_ASSUM MATCH_MP_TAC \\
7992                      MATCH_MP_TAC lt_imp_le >> art []) \\
7993         SPOSE_NOT_THEN (STRIP_ASSUME_TAC o REWRITE_RULE []) \\
7994         Q.PAT_X_ASSUM ‘f _ = Normal c’ (fs o wrap) \\
7995         Q.PAT_X_ASSUM ‘Normal c <= f y’ K_TAC (* useless *) \\
7996         Q.PAT_X_ASSUM ‘f x < Normal c’  K_TAC (* useless *) \\
7997         Suff ‘inf {x | f x = Normal c} <= t’ >- METIS_TAC [extreal_lt_def] \\
7998         Q.PAT_X_ASSUM ‘t < inf _’ K_TAC (* just used *) \\
7999         rw [inf_le'] ],
8000       (* goal 2 (of 2) *)
8001       Suff ‘A = {x | x <= z0}’
8002       >- (DISCH_TAC \\
8003           Q.EXISTS_TAC ‘A’ >> rw [BOREL_MEASURABLE_SETS]) \\
8004       rw [Abbr ‘A’, Once EXTENSION] \\
8005       rename1 ‘f t < Normal c <=> t <= z0’ \\
8006       EQ_TAC >> rw [Abbr ‘z0’, le_inf'] >| (* 2 subgoals *)
8007       [ (* goal 2.1 (of 2) *)
8008         MATCH_MP_TAC lt_imp_le >> METIS_TAC [extreal_lt_def],
8009         (* goal 2.2 (of 2) *)
8010         REWRITE_TAC [lt_le] \\
8011         CONJ_TAC
8012         >- (Q.PAT_ASSUM ‘f z = Normal c’ (ONCE_REWRITE_TAC o wrap o SYM) \\
8013             FIRST_X_ASSUM MATCH_MP_TAC \\
8014             FIRST_X_ASSUM MATCH_MP_TAC >> art []) \\
8015         SPOSE_NOT_THEN (STRIP_ASSUME_TAC o REWRITE_RULE []) \\
8016        ‘inf {x | f x = Normal c} <= t’ by rw [inf_le'] \\
8017        ‘f (inf {x | f x = Normal c}) <= f t’ by PROVE_TAC [] \\
8018        ‘f (inf {x | f x = Normal c}) < f t’ by METIS_TAC [le_lt] \\
8019        ‘inf {x | f x = Normal c} < t’ by METIS_TAC [extreal_lt_def] \\
8020        ‘t <= inf {x | f x = Normal c}’ by rw [le_inf'] \\
8021         METIS_TAC [let_antisym] ] ])
8022 (* step 4, now take ‘z’ as the last position where ‘f’ jumps over ‘Normal c’.
8023    Note that ‘f z’ as the function of ‘sup’ may be above or below ‘Normal c’. *)
8024 >> FULL_SIMP_TAC std_ss []
8025 >> Q.ABBREV_TAC ‘z = sup {x | f x < Normal c}’
8026 >> Cases_on ‘f z < Normal c’
8027 >- (Suff ‘A = {x | x <= z}’
8028     >- (DISCH_TAC \\
8029         Q.EXISTS_TAC ‘A’ >> rw [BOREL_MEASURABLE_SETS]) \\
8030     rw [Abbr ‘A’, Once EXTENSION] \\
8031     rename1 ‘f t < Normal c <=> t <= z’ \\
8032     EQ_TAC >> rw [Abbr ‘z’, le_sup'] \\
8033     MATCH_MP_TAC let_trans \\
8034     Q.EXISTS_TAC ‘f (sup {x | f x < Normal c})’ >> art [] \\
8035     FIRST_X_ASSUM MATCH_MP_TAC \\
8036     FIRST_X_ASSUM MATCH_MP_TAC \\
8037     rw [le_sup'])
8038 >> POP_ASSUM (STRIP_ASSUME_TAC o (SIMP_RULE bool_ss [extreal_lt_def]))
8039 (* step 5 *)
8040 >> Suff ‘A = {x | x < z}’
8041 >- (DISCH_TAC \\
8042     Q.EXISTS_TAC ‘A’ >> rw [BOREL_MEASURABLE_SETS])
8043 >> rw [Abbr ‘A’, Once EXTENSION]
8044 >> rename1 ‘f t < Normal c <=> t < z’
8045 >> EQ_TAC >> rw [Abbr ‘z’]
8046 >| [ (* goal 1 (of 2) *)
8047     ‘f t < f (sup {x | f x < Normal c})’ by PROVE_TAC [lte_trans] \\
8048      METIS_TAC [extreal_lt_def],
8049      (* goal 2 (of 2) *)
8050      Q.PAT_X_ASSUM ‘Normal c <= f y’ K_TAC (* useless *) \\
8051      Q.PAT_X_ASSUM ‘f x < Normal c’  K_TAC (* useless *) \\
8052      Q.PAT_X_ASSUM ‘Normal c <= f _’ K_TAC (* useless *) \\
8053      fs [lt_sup] >> rename1 ‘t < y’ \\
8054      MATCH_MP_TAC let_trans >> Q.EXISTS_TAC ‘f y’ >> art [] \\
8055      FIRST_X_ASSUM MATCH_MP_TAC >> rw [lt_imp_le] ]
8056QED
8057
8058Theorem IN_MEASURABLE_BOREL_MONO_DECREASING :
8059    !f sp. (!x y. x <= y ==> f y <= f x) /\ sp IN subsets Borel ==>
8060           f IN measurable (restrict_algebra Borel sp) Borel
8061Proof
8062    rpt STRIP_TAC
8063 >> Q.ABBREV_TAC ‘g = numeric_negate o f’
8064 >> Know ‘f = numeric_negate o g’
8065 >- (rw [Abbr ‘g’, FUN_EQ_THM]) >> Rewr'
8066 >> MATCH_MP_TAC MEASURABLE_COMP
8067 >> Q.EXISTS_TAC ‘Borel’ >> rw [IN_MEASURABLE_BOREL_BOREL_AINV]
8068 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_MONO_INCREASING
8069 >> rw [Abbr ‘g’, le_neg]
8070QED
8071
8072Theorem IN_MEASURABLE_BOREL_BOREL_MONO_INCREASING :
8073    !f. (!x y. x <= y ==> f x <= f y) ==> f IN measurable Borel Borel
8074Proof
8075    rpt STRIP_TAC
8076 >> Suff ‘f IN Borel_measurable (restrict_algebra Borel (space Borel))’
8077 >- rw [restrict_algebra_reduce', SIGMA_ALGEBRA_BOREL]
8078 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_MONO_INCREASING >> art []
8079 >> MATCH_MP_TAC SIGMA_ALGEBRA_SPACE
8080 >> rw [SIGMA_ALGEBRA_BOREL]
8081QED
8082
8083(* An easy corollary of the previous theorem *)
8084Theorem IN_MEASURABLE_BOREL_BOREL_MONO_DECREASING :
8085    !f. (!x y. x <= y ==> f y <= f x) ==> f IN measurable Borel Borel
8086Proof
8087    rpt STRIP_TAC
8088 >> Q.ABBREV_TAC ‘g = numeric_negate o f’
8089 >> Know ‘f = numeric_negate o g’
8090 >- (rw [Abbr ‘g’, FUN_EQ_THM]) >> Rewr'
8091 >> MATCH_MP_TAC MEASURABLE_COMP
8092 >> Q.EXISTS_TAC ‘Borel’ >> rw [IN_MEASURABLE_BOREL_BOREL_AINV]
8093 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_BOREL_MONO_INCREASING
8094 >> rw [Abbr ‘g’, le_neg]
8095QED
8096
8097(* NOTE: we put ‘abs’ together because ‘powr’ is only defined on [0, PosInf] *)
8098Theorem IN_MEASURABLE_BOREL_BOREL_ABS_POWR :
8099    !p. 0 <= p /\ p <> PosInf ==> (\x. (abs x) powr p) IN measurable Borel Borel
8100Proof
8101    rpt STRIP_TAC
8102 >> Cases_on ‘p = 0’ >- rw [IN_MEASURABLE_BOREL_BOREL_CONST]
8103 >> ‘0 < p’ by rw [lt_le]
8104 >> Q.ABBREV_TAC ‘g = \x. if 0 <= x then x powr p else 0’
8105 >> ‘(\x. abs x powr p) = g o abs’ by (rw [FUN_EQ_THM, Abbr ‘g’]) >> POP_ORW
8106 >> MATCH_MP_TAC MEASURABLE_COMP
8107 >> Q.EXISTS_TAC ‘Borel’
8108 >> rw [IN_MEASURABLE_BOREL_BOREL_ABS]
8109 >> MATCH_MP_TAC IN_MEASURABLE_BOREL_BOREL_MONO_INCREASING
8110 >> rpt GEN_TAC
8111 >> Cases_on ‘0 <= x’ >> Cases_on ‘0 <= y’
8112 >> rw [Abbr ‘g’] (* 3 subgoals *)
8113 >| [ (* goal 1 (of 3) *)
8114      Suff ‘x powr p <= y powr p <=> x <= y’ >- rw [] \\
8115      MATCH_MP_TAC powr_mono_eq >> art [],
8116      (* goal 2 (of 3) *)
8117      fs [GSYM extreal_lt_def] \\
8118     ‘x < 0’ by PROVE_TAC [let_trans] \\
8119      METIS_TAC [let_antisym],
8120      (* goal 3 (of 3) *)
8121      rw [powr_pos] ]
8122QED
8123
8124Theorem IN_MEASURABLE_BOREL_ABS_POWR :
8125    !a p f. f IN measurable a Borel /\ 0 <= p /\ p <> PosInf ==>
8126           (\x. (abs (f x)) powr p) IN measurable a Borel
8127Proof
8128    rpt STRIP_TAC
8129 >> ‘(\x. (abs (f x)) powr p) = (\x. (abs x) powr p) o f’ by rw [o_DEF] >> POP_ORW
8130 >> MATCH_MP_TAC MEASURABLE_COMP
8131 >> Q.EXISTS_TAC ‘Borel’
8132 >> rw [IN_MEASURABLE_BOREL_BOREL_ABS_POWR]
8133QED
8134
8135(***********************)
8136(*   Further Results   *)
8137(***********************)
8138
8139(*  I add these results at the end
8140      in order to manipulate the simplifier without breaking anything
8141      - Jared Yeager                                                    *)
8142
8143val _ = augment_srw_ss [realSimps.REAL_ARITH_ss];
8144
8145val _ = reveal "C";
8146
8147(*** IN_MEASURABLE_BOREL Theorems ***)
8148
8149(* There is already an IN_MEASURABLE_BOREL_CONG earlier in this theory *)
8150Theorem IN_MEASURABLE_BOREL_CONG':
8151    !a f g. (!x. x IN space a ==> f x = g x) ==>
8152            (f IN Borel_measurable a <=> g IN Borel_measurable a)
8153Proof
8154    rw[] >> eq_tac >> rw[]
8155 >> dxrule_at_then (Pos $ el 2) irule IN_MEASURABLE_BOREL_EQ' >> simp[]
8156QED
8157
8158Theorem IN_MEASURABLE_BOREL_COMP:
8159    !a b f g h. f IN Borel_measurable b /\ g IN measurable a b /\
8160               (!x. x IN space a ==> h x = f (g x)) ==> h IN Borel_measurable a
8161Proof
8162    rw[] >> dxrule_all_then assume_tac MEASURABLE_COMP >>
8163    irule IN_MEASURABLE_BOREL_EQ' >> qexists_tac ‘f o g’ >> simp[]
8164QED
8165
8166Theorem IN_MEASURABLE_BOREL_COMP_BOREL:
8167    !a f g h. f IN Borel_measurable Borel /\ g IN Borel_measurable a /\
8168             (!x. x IN space a ==> h x = f (g x)) ==> h IN Borel_measurable a
8169Proof
8170    rw[] >> dxrule_all_then assume_tac MEASURABLE_COMP >>
8171    irule IN_MEASURABLE_BOREL_EQ' >> qexists_tac ‘f o g’ >> simp[]
8172QED
8173
8174Theorem IN_MEASURABLE_BOREL_SUM':
8175    !a f g s. FINITE s /\ sigma_algebra a /\
8176             (!i. i IN s ==> f i IN Borel_measurable a) /\
8177             (!x. x IN space a ==> g x = EXTREAL_SUM_IMAGE (λi. f i x) s) ==>
8178              g IN Borel_measurable a
8179Proof
8180   ‘!a f g l. sigma_algebra a /\
8181             (!i. MEM i l ==> f i IN Borel_measurable a) /\
8182             (!x. x IN space a ==> g x = FOLDR (λi acc. f i x + acc) 0 l) ==>
8183              g IN Borel_measurable a’
8184     suffices_by
8185      (rw[] >> last_x_assum irule >> simp[] \\
8186       qexistsl_tac [‘f’,‘REVERSE (SET_TO_LIST s)’] \\
8187       simp[EXTREAL_SUM_IMAGE_ALT_FOLDR,SF SFY_ss])
8188 >> Induct_on ‘l’ >> rw[FOLDR]
8189 >- (irule IN_MEASURABLE_BOREL_CONST >> simp[] >> qexists_tac ‘0’ >> simp[])
8190 >> irule IN_MEASURABLE_BOREL_ADD' >> simp[]
8191 >> qexistsl_tac [‘f h’,‘λx. FOLDR (λi acc. f i x + acc) 0 l’] >> simp[]
8192 >> last_x_assum irule >> simp[] >> qexists_tac ‘f’ >> simp[]
8193QED
8194
8195(* This is just a naming consistence thing, the _TIMES suffix deviates from
8196   convention.
8197 *)
8198Theorem IN_MEASURABLE_BOREL_MUL' = IN_MEASURABLE_BOREL_TIMES';
8199
8200Theorem IN_MEASURABLE_BOREL_PROD:
8201    !a f g s. FINITE s /\ sigma_algebra a /\
8202             (!i. i IN s ==> f i IN Borel_measurable a) /\
8203             (!i x. i IN s /\ x IN space a ==> f i x <> NegInf /\ f i x <> PosInf) /\
8204             (!x. x IN space a ==> g x = EXTREAL_PROD_IMAGE (λi. f i x) s) ==>
8205              g IN Borel_measurable a
8206Proof
8207    NTAC 2 gen_tac
8208 >> simp[Once SWAP_FORALL_THM,Once $ GSYM AND_IMP_INTRO,RIGHT_FORALL_IMP_THM]
8209 >> Induct_on ‘s’ >> rw[]
8210 >- (fs[EXTREAL_PROD_IMAGE_EMPTY] >> irule IN_MEASURABLE_BOREL_CONST >>
8211     simp[] >> qexists_tac ‘1’ >> simp[])
8212 >> rfs[EXTREAL_PROD_IMAGE_PROPERTY,DELETE_NON_ELEMENT_RWT]
8213 >> irule IN_MEASURABLE_BOREL_MUL >> simp[]
8214 >> qexistsl_tac [‘f e’,‘λx. EXTREAL_PROD_IMAGE (λi. f i x) s’] >> simp[]
8215 >> NTAC 2 strip_tac
8216 >> irule EXTREAL_PROD_IMAGE_NOT_INFTY >> simp[]
8217QED
8218
8219Theorem IN_MEASURABLE_BOREL_PROD':
8220    !a f g s. FINITE s /\ sigma_algebra a /\
8221             (!i. i IN s ==> f i IN Borel_measurable a) /\
8222             (!x. x IN space a ==> g x = EXTREAL_PROD_IMAGE (λi. f i x) s) ==>
8223              g IN Borel_measurable a
8224Proof
8225    NTAC 2 gen_tac
8226 >> simp[Once SWAP_FORALL_THM,Once $ GSYM AND_IMP_INTRO,RIGHT_FORALL_IMP_THM]
8227 >> Induct_on ‘s’ >> rw[]
8228 >- (fs[EXTREAL_PROD_IMAGE_EMPTY] >> irule IN_MEASURABLE_BOREL_CONST >>
8229     simp[] >> qexists_tac ‘1’ >> simp[])
8230 >> rfs[EXTREAL_PROD_IMAGE_PROPERTY,DELETE_NON_ELEMENT_RWT]
8231 >> irule IN_MEASURABLE_BOREL_MUL' >> simp[]
8232 >> qexistsl_tac [‘f e’,‘λx. EXTREAL_PROD_IMAGE (λi. f i x) s’] >> simp[]
8233QED
8234
8235Theorem IN_MEASURABLE_BOREL_INV:
8236    !a f g. sigma_algebra a /\ f IN Borel_measurable a /\
8237           (!x. x IN space a ==>
8238                g x = extreal_inv (f x) * indicator_fn {y | f y <> 0} x) ==>
8239            g IN Borel_measurable a
8240Proof
8241    rw[]
8242 >> simp[IN_MEASURABLE_BOREL,FUNSET]
8243 >> ‘(!c. c <= 0 ==> {x | g x < Normal c} INTER space a IN subsets a) /\
8244      {x | g x = 0} INTER space a IN subsets a /\
8245      (!c. 0 < c ==> {x | 0 < g x /\ g x < Normal c} INTER space a IN subsets a)’
8246      suffices_by (
8247        rw[] >> Cases_on ‘c <= 0’ >> simp[] >> fs[REAL_NOT_LE] >>
8248        first_x_assum $ drule_then assume_tac \\
8249        first_x_assum $ qspec_then ‘0’ assume_tac >>
8250        fs[normal_0] \\
8251        drule_then (fn th => NTAC 2 $ dxrule_all_then assume_tac th)
8252                   SIGMA_ALGEBRA_UNION \\
8253        pop_assum mp_tac \\
8254        qmatch_abbrev_tac ‘s IN _ ==> t IN _’ >> ‘s = t’ suffices_by simp[] >>
8255        UNABBREV_ALL_TAC >> rw[EXTENSION] >> qpat_x_assum ‘!x. _’ kall_tac >>
8256        Cases_on ‘x IN space a’ >> simp[] >> Cases_on ‘g x’ >> simp[])
8257 >> rw[]
8258 >- (MP_TAC (Q.SPECL [‘f’, ‘a’] IN_MEASURABLE_BOREL_OO) >> RW_TAC std_ss [] \\
8259     POP_ASSUM
8260       (qspecl_then [‘if c = 0 then NegInf else Normal (inv c)’,‘0’] mp_tac) \\
8261     qmatch_abbrev_tac ‘s IN _ ==> t IN _’ >> ‘s = t’ suffices_by simp[] \\
8262     UNABBREV_ALL_TAC \\
8263     simp[EXTENSION] >> strip_tac \\
8264     Cases_on ‘x IN space a’ >> simp[indicator_fn_def] >>
8265     Cases_on ‘f x’ >> rw[extreal_inv_def] >> eq_tac >> strip_tac >> simp[] >>
8266     drule_all_then assume_tac REAL_LTE_TRANS >> fs[])
8267 >- (drule_all_then assume_tac IN_MEASURABLE_BOREL_SING >>
8268     pop_assum (fn th => map_every (fn tm => qspec_then tm assume_tac th)
8269                                   [‘NegInf’,‘0’,‘PosInf’]) >>
8270     drule_then (fn th => NTAC 2 $ dxrule_all_then assume_tac th)
8271                SIGMA_ALGEBRA_UNION >>
8272     pop_assum mp_tac >> qmatch_abbrev_tac ‘s IN _ ==> t IN _’ >>
8273    ‘s = t’ suffices_by simp[] >>
8274     UNABBREV_ALL_TAC >> rw[EXTENSION] >>
8275     Cases_on ‘x IN space a’ >> simp[indicator_fn_def] >>
8276     Cases_on ‘f x’ >> rw[extreal_inv_def])
8277 >> (MP_TAC (Q.SPECL [‘f’, ‘a’] IN_MEASURABLE_BOREL_OO) >> RW_TAC std_ss [] \\
8278     POP_ASSUM (qspecl_then [‘Normal (inv c)’,‘PosInf’] mp_tac) \\
8279     qmatch_abbrev_tac ‘s IN _ ==> t IN _’ >> ‘s = t’ suffices_by simp[] \\
8280     UNABBREV_ALL_TAC >>
8281     rw[EXTENSION] >> Cases_on ‘x IN space a’ >> simp[indicator_fn_def] >>
8282     Cases_on ‘f x’ >> rw[extreal_inv_def] >> simp[] \\
8283     eq_tac >> strip_tac >> rfs[] >>
8284     REVERSE CONJ_ASM1_TAC >- simp[] \\
8285    ‘0 <= c * r’ by simp[] >> rfs[REAL_MUL_SIGN])
8286QED
8287
8288Theorem IN_MEASURABLE_BOREL_MUL_INV:
8289    !a f g h. sigma_algebra a /\ f IN Borel_measurable a /\
8290              g IN Borel_measurable a /\
8291             (!x. x IN space a /\ g x = 0 ==> f x = 0) /\
8292             (!x. x IN space a ==> h x = f x * extreal_inv (g x)) ==>
8293              h IN Borel_measurable a
8294Proof
8295    rw[] >> irule IN_MEASURABLE_BOREL_MUL' >> simp[]
8296 >> qexistsl_tac [‘f’,‘λx. extreal_inv (g x) * indicator_fn {y | g y <> 0} x’]
8297 >> simp[]
8298 >> irule_at Any IN_MEASURABLE_BOREL_INV
8299 >> qexists_tac ‘g’ >> simp[]
8300 >> rw[indicator_fn_def] >> simp[]
8301QED
8302
8303Theorem IN_MEASURABLE_BOREL_EXP:
8304    !a f g. sigma_algebra a /\ f IN Borel_measurable a /\
8305           (!x. x IN space a ==> g x = exp (f x)) ==> g IN Borel_measurable a
8306Proof
8307    rw[] >> irule IN_MEASURABLE_BOREL_COMP_BOREL >> simp[]
8308 >> qexistsl_tac [‘exp’,‘f’] >> simp[]
8309 >> rw[IN_MEASURABLE_BOREL_ALT2,SIGMA_ALGEBRA_BOREL,FUNSET,SPACE_BOREL]
8310 >> Cases_on ‘c < 0’
8311 >- (‘{x | exp x <= Normal c} = EMPTY’
8312       suffices_by simp[BOREL_MEASURABLE_SETS_EMPTY] \\
8313     rw[EXTENSION,GSYM extreal_lt_def] \\
8314     irule lte_trans >> qexists_tac ‘0’ >> simp[exp_pos])
8315 >> ‘{x | exp x <= Normal c} = {x | x <= ln (Normal c)}’
8316       suffices_by simp[BOREL_MEASURABLE_SETS_RC]
8317 >> fs[GSYM real_lte] >> rw[EXTENSION]
8318 >> REVERSE (fs[REAL_LE_LT])
8319 >- (simp[extreal_ln_def,normal_0] >> Cases_on ‘x’ >>
8320     simp[extreal_exp_def,GSYM real_lt,EXP_POS_LT])
8321 >> drule_then SUBST1_TAC $ GSYM $ iffRL EXP_LN
8322 >> simp[Once $ GSYM extreal_exp_def]
8323 >> simp[iffRL EXP_LN,extreal_ln_def]
8324QED
8325
8326Theorem IN_MEASURABLE_BOREL_POW':
8327    !n a f g. sigma_algebra a /\ f IN Borel_measurable a /\
8328             (!x. x IN space a ==> g x = f x pow n) ==> g IN Borel_measurable a
8329Proof
8330    Induct_on ‘n’
8331 >> rw[extreal_pow_alt]
8332 >- (irule IN_MEASURABLE_BOREL_CONST >> simp[] >> qexists_tac ‘1’ >> simp[])
8333 >> irule IN_MEASURABLE_BOREL_MUL' >> simp[]
8334 >> qexistsl_tac [‘λx. f x pow n’,‘f’] >> simp[]
8335 >> last_x_assum irule >> simp[]
8336 >> qexists_tac ‘f’ >> simp[]
8337QED
8338
8339Theorem IN_MEASURABLE_BOREL_POW_EXP:
8340    !a f g h. sigma_algebra a /\ f IN Borel_measurable a /\
8341             (!n. {x | g x = n} INTER space a IN subsets a) /\
8342             (!x. x IN space a ==> h x = (f x) pow (g x)) ==>
8343              h IN Borel_measurable a
8344Proof
8345    rw[] >> simp[Once IN_MEASURABLE_BOREL_PLUS_MINUS]
8346 >> ‘!P. {x | P (g x)} INTER space a IN subsets a’
8347      by (rw[] \\
8348         ‘{x | P (g x)} INTER space a =
8349            BIGUNION {{x | g x = n} INTER space a | P n}’
8350            by (rw[Once EXTENSION,IN_BIGUNION] \\
8351                eq_tac >> strip_tac >> gvs[] \\
8352                qexists_tac ‘{y | g y = g x} INTER space a’ >> simp[] \\
8353                qexists_tac ‘g x’ >> simp[]) \\
8354          pop_assum SUBST1_TAC >> irule SIGMA_ALGEBRA_COUNTABLE_UNION \\
8355          REVERSE (rw[SUBSET_DEF]) >- simp[SF SFY_ss] \\
8356          simp[COUNTABLE_ALT] \\
8357          qexists_tac ‘λn. {x | g x = n} INTER space a’ >> rw[] \\
8358          qexists_tac ‘n’ >> simp[])
8359 >> map_every (fn (pos,tm,qex,ths) =>
8360                  irule_at pos tm >> qexistsl_tac qex >> simp ths)
8361  [ (Pos hd,IN_MEASURABLE_BOREL_ADD',
8362     [‘λx. fn_minus f x pow g x * indicator_fn {x | EVEN (g x)} x’,
8363      ‘λx. fn_plus f x pow g x * indicator_fn {x | $< 0 (g x)} x’],[]),
8364    (Pos (el 2),IN_MEASURABLE_BOREL_MUL',
8365     [‘indicator_fn {x | EVEN (g x)}’,‘λx. fn_minus f x pow g x’],[]),
8366    (Pos (el 2),IN_MEASURABLE_BOREL_INDICATOR,
8367     [‘{x | EVEN (g x)} INTER space a’],[]),
8368    (Pos (el 3),IN_MEASURABLE_BOREL_MUL',
8369     [‘indicator_fn {x | $< 0 (g x)}’,‘λx. fn_plus f x pow g x’],[]),
8370    (Pos (el 2),IN_MEASURABLE_BOREL_INDICATOR,
8371     [‘{x | $< 0 (g x)} INTER space a’],[]),
8372    (Pos last,IN_MEASURABLE_BOREL_MUL',
8373     [‘indicator_fn {x | ODD (g x)}’,‘λx. fn_minus f x pow g x’],[]),
8374    (Pos (el 2),IN_MEASURABLE_BOREL_INDICATOR,
8375     [‘{x | ODD (g x)} INTER space a’],[]) ]
8376 >> pop_assum kall_tac
8377 >> ‘!pf. pf IN Borel_measurable a /\
8378          (!x. 0 <= pf x) ==> (λx. pf x pow g x) IN Borel_measurable a’
8379      by (rw[] >> irule IN_MEASURABLE_BOREL_SUMINF >> simp[] >>
8380        qexistsl_tac [‘λn x. pf x pow n * indicator_fn {x | g x = n} x’] >> simp[pow_pos_le,INDICATOR_FN_POS,le_mul] >>
8381        simp[RIGHT_AND_FORALL_THM] >> strip_tac >>
8382        map_every (fn (pos,tm,qex,ths) => irule_at pos tm >> simp[] >> qexistsl_tac qex >> simp ths) [
8383            (Any,IN_MEASURABLE_BOREL_MUL',[‘indicator_fn {x | g x = n}’,‘λx. pf x pow n’],[]),
8384            (Pos hd,IN_MEASURABLE_BOREL_POW',[‘n’,‘pf’],[]),
8385            (Pos hd,IN_MEASURABLE_BOREL_INDICATOR,[‘{x | g x = n} INTER space a’],[indicator_fn_def])] >>
8386        rw[] >> qspecl_then [‘g x’,‘pf x pow g x’] mp_tac ext_suminf_sing_general >>
8387        simp[pow_pos_le] >> DISCH_THEN $ SUBST1_TAC o SYM >> AP_TERM_TAC >> rw[FUN_EQ_THM] >>
8388        Cases_on ‘g x = n’ >> simp[])
8389 (* stage work *)
8390 >> pop_assum (fn th => NTAC 2 (irule_at Any th >> simp[iffLR IN_MEASURABLE_BOREL_PLUS_MINUS]))
8391 >> simp[FN_PLUS_POS,FN_MINUS_POS]
8392 >> rw[indicator_fn_def] >> simp[fn_minus_def,fn_plus_alt]
8393 >- (Cases_on ‘f x < 0’ >- fs[pow_neg_odd,pow_ainv_odd] \\
8394     fs[ODD_POS,zero_pow] \\
8395    ‘~(f x pow g x < 0)’ suffices_by simp[] \\
8396     fs[extreal_lt_def,pow_pos_le])
8397 >- (‘~(f x pow g x < 0)’ suffices_by simp[] \\
8398     fs[ODD_EVEN] >> simp[extreal_lt_def,pow_even_le])
8399 >- (Cases_on ‘0 <= f x’ >> fs[GSYM extreal_lt_def] >>
8400     simp[ineq_imp,pow_pos_le,zero_pow,pow_even_le,pow_ainv_even])
8401 >- (fs[EVEN_ODD] \\
8402     Cases_on ‘0 <= f x’ >> fs[GSYM extreal_lt_def] \\
8403     simp[ineq_imp,pow_pos_le,zero_pow] \\
8404    ‘~(0 <= f x pow g x)’ suffices_by simp[] \\
8405     simp[GSYM extreal_lt_def,pow_neg_odd])
8406 >- (Cases_on ‘0 <= f x’ >> fs[GSYM extreal_lt_def] >> simp[ineq_imp])
8407 >> rfs[EVEN_ODD,ODD]
8408QED
8409
8410(* NOTE: added ‘sigma_algebra a’ into antecedents due to changes of ‘measurable’
8411
8412   Here ‘Normal o real’ is actually used as a "filter" to remove all infinities from
8413   the domain of a function f.
8414 *)
8415Theorem IN_MEASURABLE_BOREL_NORMAL_REAL:
8416    !a f. sigma_algebra a /\ f IN Borel_measurable a ==>
8417          Normal o real o f IN Borel_measurable a
8418Proof
8419    rw[] >> irule IN_MEASURABLE_BOREL_IMP_BOREL' >> art []
8420 >> irule_at Any in_borel_measurable_from_Borel >> art []
8421QED
8422
8423Theorem IN_MEASURABLE_BOREL_NORMAL[simp] :
8424    Normal IN measurable borel Borel
8425Proof
8426    rw [sigma_algebra_borel, IN_MEASURABLE_BOREL, space_borel, IN_FUNSET]
8427 >> rw [borel_measurable_sets]
8428QED
8429
8430(*** AE Theorems ***)
8431
8432Theorem AE_subset:
8433    !m P Q. (AE x::m. P x) /\ (!x. x IN m_space m /\ P x ==> Q x) ==> (AE x::m. Q x)
8434Proof
8435    rw[AE_ALT] >> qexists_tac `N` >> fs[SUBSET_DEF] >> rw[] >>
8436    NTAC 2 $ first_x_assum $ drule_then assume_tac >> gs[]
8437QED
8438
8439Theorem AE_cong:
8440    !m P Q. (!x. x IN m_space m ==> P x = Q x) ==> ((AE x::m. P x) <=> (AE x::m. Q x))
8441Proof
8442    rw[] >> eq_tac >> rw[]
8443 >> dxrule_at_then (Pos $ el 1) irule AE_subset >> simp[SF CONJ_ss]
8444QED
8445
8446Theorem AE_T:
8447    !m. measure_space m ==> AE x::m. T
8448Proof
8449    rw[AE_ALT] >> qexists_tac ‘ {} ’ >> simp[NULL_SET_EMPTY]
8450QED
8451
8452Theorem AE_UNION:
8453    !m P Q. measure_space m /\ ((AE x::m. P x) \/ (AE x::m. Q x)) ==>
8454           (AE x::m. P x \/ Q x)
8455Proof
8456    rw[AE_ALT,null_set_def] >> qexists_tac ‘N’ >> fs[SUBSET_DEF]
8457QED
8458
8459Theorem AE_BIGUNION:
8460    !m P s. measure_space m /\ (?n. n IN s /\ AE x::m. P n x) ==>
8461           (AE x::m. ?n. n IN s /\ P n x)
8462Proof
8463    rw[AE_ALT,null_set_def] >> qexists_tac ‘N’ >> fs[SUBSET_DEF,GSYM IMP_DISJ_THM]
8464QED
8465
8466Theorem AE_INTER:
8467    !m P Q. measure_space m /\ (AE x::m. P x) /\ (AE x::m. Q x) ==>
8468           (AE x::m. P x /\ Q x)
8469Proof
8470    rw[AE_ALT] >> qexists_tac ‘N UNION N'’ >> rename [‘N UNION M’] >>
8471    simp[SIMP_RULE (srw_ss ()) [IN_APP] NULL_SET_UNION] >>
8472    fs[SUBSET_DEF] >> rw[] >> simp[]
8473QED
8474
8475Theorem AE_BIGINTER:
8476    !m P s. measure_space m /\ countable s /\ (!n. n IN s ==> AE x::m. P n x) ==>
8477           (AE x::m. !n. n IN s ==> P n x)
8478Proof
8479    rw[AE_ALT]
8480 >> fs[GSYM RIGHT_EXISTS_IMP_THM,SKOLEM_THM]
8481 >> qexists_tac ‘BIGUNION (IMAGE f s)’
8482 >> rename [‘IMAGE N s’]
8483 >> REVERSE CONJ_TAC
8484 >- (fs[SUBSET_DEF] >> rw[] \\
8485     NTAC 2 (first_x_assum $ drule_then assume_tac >> rfs[])
8486 >> map_every (fn qex => qexists_tac qex >> simp[]) [‘N n’,‘n’])
8487 >> fs[COUNTABLE_ENUM] >- simp[NULL_SET_EMPTY]
8488 >> simp[IMAGE_IMAGE]
8489 >> fs[null_set_def]
8490 >> CONJ_ASM1_TAC >- (irule MEASURE_SPACE_BIGUNION >> simp[])
8491 >> simp[GSYM le_antisym]
8492 >> irule_at Any $ cj 2 $ iffLR positive_def
8493 >> simp[iffLR measure_space_def]
8494 >> irule leeq_trans
8495 >> qexists_tac ‘suminf (measure m o (N o f))’
8496 >> irule_at Any $ iffLR countably_subadditive_def
8497 >> simp[MEASURE_SPACE_COUNTABLY_SUBADDITIVE,FUNSET,combinTheory.o_DEF,ext_suminf_0]
8498QED
8499
8500Theorem AE_eq_add:
8501    !m f fae g gae. measure_space m /\ (AE x::m. f x = fae x) /\
8502                   (AE x::m. g x = gae x) ==>
8503                    AE x::m. f x + g x = fae x + gae x
8504Proof
8505    rw[] >> fs[AE_ALT] >> qexists_tac ‘N UNION N'’ >>
8506    (drule_then assume_tac) NULL_SET_UNION >> rfs[IN_APP] >> pop_assum kall_tac >>
8507    fs[SUBSET_DEF] >> rw[] >> NTAC 2 (last_x_assum (drule_then assume_tac)) >>
8508    CCONTR_TAC >> fs[]
8509QED
8510
8511Theorem AE_eq_sum:
8512    !m f fae s. FINITE s /\ measure_space m /\
8513               (!n. n IN s ==> AE x::m. (f n x):extreal = fae n x) ==>
8514                AE x::m. SIGMA (C f x) s = SIGMA (C fae x) s
8515Proof
8516    rw[] >> qspecl_then [‘m’,‘λn x. f n x = fae n x’,‘s’] assume_tac AE_BIGINTER
8517 >> rfs[finite_countable]
8518 >> qspecl_then [‘m’,‘λx. !n. n IN s ==> f n x = fae n x’,
8519                 ‘λx. SIGMA (C f x) s = SIGMA (C fae x) s’]
8520        (irule o SIMP_RULE (srw_ss ()) []) AE_subset
8521 >> rw[] >> irule EXTREAL_SUM_IMAGE_EQ' >> rw[combinTheory.C_DEF]
8522QED
8523
8524(* ------------------------------------------------------------------------- *)
8525(* Borel and general_borel (of ext_euclidean)                                *)
8526(* ------------------------------------------------------------------------- *)
8527
8528(* NOTE: singleton sets are closed in the usual Euclidean space, but singleton
8529   of PosInf or NegInf are open in extended Euclidean space, because there's
8530   no other points in their neighbor when the distance is less than 1.
8531 *)
8532Theorem open_in_ext_euclidean_posinf :
8533    open_in ext_euclidean {PosInf}
8534Proof
8535    rw [ext_euclidean_def, OPEN_IN_MTOPOLOGY, MSPACE]
8536 >> Q.EXISTS_TAC ‘1’
8537 >> rw [SUBSET_DEF, IN_MBALL, MSPACE]
8538 >> CCONTR_TAC
8539 >> Cases_on ‘x = NegInf’ >> fs []
8540 >> ‘?r. x = Normal r’ by METIS_TAC [extreal_cases]
8541 >> fs []
8542QED
8543
8544Theorem open_in_ext_euclidean_neginf :
8545    open_in ext_euclidean {NegInf}
8546Proof
8547    rw [ext_euclidean_def, OPEN_IN_MTOPOLOGY, MSPACE]
8548 >> Q.EXISTS_TAC ‘1’
8549 >> rw [SUBSET_DEF, IN_MBALL, MSPACE]
8550 >> CCONTR_TAC
8551 >> Cases_on ‘x = PosInf’ >> fs []
8552 >> ‘?r. x = Normal r’ by METIS_TAC [extreal_cases]
8553 >> fs []
8554QED
8555
8556Theorem open_in_ext_euclidean_infty :
8557    open_in ext_euclidean {NegInf; PosInf}
8558Proof
8559   ‘{NegInf; PosInf} = {NegInf} UNION {PosInf}’ by SET_TAC []
8560 >> POP_ORW
8561 >> MATCH_MP_TAC OPEN_IN_UNION
8562 >> REWRITE_TAC [open_in_ext_euclidean_neginf, open_in_ext_euclidean_posinf]
8563QED
8564
8565Theorem Borel_alt_general :
8566    Borel = general_borel ext_euclidean
8567Proof
8568    SIMP_TAC std_ss [Borel]
8569 >> qmatch_abbrev_tac ‘(UNIV,sts) = _’
8570 >> Suff ‘sts = (subsets (general_borel ext_euclidean))’
8571 >- METIS_TAC [space_general_borel, subsets_def, SPACE, topspace_ext_euclidean]
8572 >> simp [Once EXTENSION, Abbr ‘sts’]
8573 >> Q.X_GEN_TAC ‘s’
8574 >> EQ_TAC
8575 >- (qmatch_abbrev_tac ‘_ ==> s IN subsets A’ \\
8576    ‘sigma_algebra A’ by simp [Abbr ‘A’, sigma_algebra_general_borel] \\
8577     Suff ‘!a. a IN subsets borel ==> IMAGE Normal a IN subsets A’
8578     >- (DISCH_TAC >> rw [] >| (* 4 subgoals *)
8579         [ (* goal 1 (of 4) *)
8580           simp [],
8581           (* goal 2 (of 4) *)
8582           MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> simp [] \\
8583           qunabbrev_tac ‘A’ \\
8584           MATCH_MP_TAC open_in_general_borel \\
8585           REWRITE_TAC [open_in_ext_euclidean_neginf],
8586           (* goal 3 (of 4) *)
8587           MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> simp [] \\
8588           qunabbrev_tac ‘A’ \\
8589           MATCH_MP_TAC open_in_general_borel \\
8590           REWRITE_TAC [open_in_ext_euclidean_posinf],
8591           (* goal 4 (of 4) *)
8592           MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> simp [] \\
8593           qunabbrev_tac ‘A’ \\
8594           MATCH_MP_TAC open_in_general_borel \\
8595           REWRITE_TAC [open_in_ext_euclidean_infty] ]) \\
8596  (* applying SIGMA_SUBSET *)
8597     qabbrev_tac ‘P = \a. IMAGE Normal a IN subsets A’ >> simp [] \\
8598     Suff ‘subsets borel SUBSET P’ >- METIS_TAC [SUBSET_DEF, IN_APP] \\
8599     REWRITE_TAC [borel_eq_gr] \\
8600     MATCH_MP_TAC SIGMA_PROPERTY_ALT \\
8601     simp [subset_class_def, IN_FUNSET] \\
8602     CONJ_TAC >- simp [Abbr ‘P’, SIGMA_ALGEBRA_EMPTY] \\
8603     CONJ_TAC
8604     >- (rw [SUBSET_DEF, Abbr ‘P’, Abbr ‘A’] \\
8605         MATCH_MP_TAC open_in_general_borel \\
8606         REWRITE_TAC [ext_euclidean_def] \\
8607         rw [OPEN_IN_MTOPOLOGY, mspace_extreal_mr1] \\
8608         rename1 ‘a < c’ \\
8609         qabbrev_tac ‘d = c - a’ \\
8610        ‘0 < d’ by simp [Abbr ‘d’] \\
8611         Q.EXISTS_TAC ‘1 - inv (1 + d)’ \\
8612         CONJ_ASM1_TAC >- simp [REAL_SUB_LT] \\
8613         rw [SUBSET_DEF, IN_MBALL, mspace_extreal_mr1] \\
8614        ‘1 - inv (1 + d) < 1’ by simp [REAL_LT_SUB_RADD] \\
8615         Cases_on ‘x = PosInf’ >- fs [] \\
8616         Cases_on ‘x = NegInf’ >- fs [] \\
8617        ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] >> rw [] \\
8618         Q.PAT_X_ASSUM ‘dist extreal_mr1 _ < _’ MP_TAC \\
8619         simp [extreal_mr1_normal'] \\
8620         simp [REAL_ARITH “a - b < a - c <=> c < (b :real)”] \\
8621         simp [Abbr ‘d’]) \\
8622     CONJ_TAC
8623     >- (rw [Abbr ‘P’] \\
8624         Suff ‘IMAGE Normal (univ(:real) DIFF s) =
8625               space A DIFF (IMAGE Normal s UNION {NegInf; PosInf})’
8626         >- (Rewr' \\
8627             MATCH_MP_TAC SIGMA_ALGEBRA_COMPL >> art [] \\
8628             MATCH_MP_TAC SIGMA_ALGEBRA_UNION >> art [] \\
8629             qunabbrev_tac ‘A’ \\
8630             MATCH_MP_TAC open_in_general_borel \\
8631             REWRITE_TAC [open_in_ext_euclidean_infty]) \\
8632         rw [Once EXTENSION, Abbr ‘A’, space_general_borel, topspace_ext_euclidean] \\
8633         EQ_TAC >> rw [] >> rw [] \\
8634        ‘?r. x = Normal r’ by METIS_TAC [extreal_cases] >> fs []) \\
8635     rw [Abbr ‘P’, IMAGE_BIGUNION, IMAGE_IMAGE] \\
8636     MATCH_MP_TAC SIGMA_ALGEBRA_COUNTABLE_UNION >> simp [image_countable] \\
8637     rw [SUBSET_DEF] >> simp [])
8638 (* stage work *)
8639 >> DISCH_TAC
8640 >> qabbrev_tac ‘A = general_borel ext_euclidean’
8641 >> ‘sigma_algebra A’ by simp [Abbr ‘A’, sigma_algebra_general_borel]
8642 >> Suff ‘!a. a IN subsets A /\ PosInf NOTIN a /\ NegInf NOTIN a ==>
8643              ?B. a = IMAGE Normal B /\ B IN subsets borel’
8644 >- (DISCH_TAC \\
8645     Cases_on ‘PosInf IN s’ >> Cases_on ‘NegInf IN s’ >| (* 4 subgoals *)
8646     [ (* goal 1 (of 4) *)
8647       qabbrev_tac ‘t = s DIFF {NegInf; PosInf}’ \\
8648       Know ‘t IN subsets A’
8649       >- (qunabbrev_tac ‘t’ \\
8650           MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> art [] \\
8651           qunabbrev_tac ‘A’ \\
8652           MATCH_MP_TAC open_in_general_borel \\
8653           REWRITE_TAC [open_in_ext_euclidean_infty]) >> DISCH_TAC \\
8654      ‘PosInf NOTIN t /\ NegInf NOTIN t /\
8655       s = t UNION {NegInf; PosInf}’ by ASM_SET_TAC [] >> POP_ORW \\
8656       Q.PAT_X_ASSUM ‘!A. P’ (MP_TAC o Q.SPEC ‘t’) >> rw [] \\
8657       qexistsl_tac [‘B’, ‘{NegInf; PosInf}’] >> simp [],
8658       (* goal 2 (of 4) *)
8659       qabbrev_tac ‘t = s DIFF {PosInf}’ \\
8660       Know ‘t IN subsets A’
8661       >- (qunabbrev_tac ‘t’ \\
8662           MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> art [] \\
8663           qunabbrev_tac ‘A’ \\
8664           MATCH_MP_TAC open_in_general_borel \\
8665           REWRITE_TAC [open_in_ext_euclidean_posinf]) >> DISCH_TAC \\
8666      ‘PosInf NOTIN t /\ NegInf NOTIN t /\
8667       s = t UNION {PosInf}’ by ASM_SET_TAC [] >> POP_ORW \\
8668       Q.PAT_X_ASSUM ‘!A. P’ (MP_TAC o Q.SPEC ‘t’) >> rw [] \\
8669       qexistsl_tac [‘B’, ‘{PosInf}’] >> simp [],
8670       (* goal 3 (of 4) *)
8671       qabbrev_tac ‘t = s DIFF {NegInf}’ \\
8672       Know ‘t IN subsets A’
8673       >- (qunabbrev_tac ‘t’ \\
8674           MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> art [] \\
8675           qunabbrev_tac ‘A’ \\
8676           MATCH_MP_TAC open_in_general_borel \\
8677           REWRITE_TAC [open_in_ext_euclidean_neginf]) >> DISCH_TAC \\
8678      ‘PosInf NOTIN t /\ NegInf NOTIN t /\
8679       s = t UNION {NegInf}’ by ASM_SET_TAC [] >> POP_ORW \\
8680       Q.PAT_X_ASSUM ‘!A. P’ (MP_TAC o Q.SPEC ‘t’) >> rw [] \\
8681       qexistsl_tac [‘B’, ‘{NegInf}’] >> simp [],
8682       (* goal 4 (of 4) *)
8683       Q.PAT_X_ASSUM ‘!A. P’ (MP_TAC o Q.SPEC ‘s’) >> rw [] \\
8684       qexistsl_tac [‘B’, ‘{}’] >> simp [] ])
8685 (* stage work
8686
8687    NOTE: Here we need to prove that, any open set in ext_euclidean removing
8688    infinities is still an open set (in euclidean) by “real_set”. There's no
8689    other better generator we can use (from ext_euclidean) at this moment.
8690  *)
8691 >> Q.PAT_X_ASSUM ‘s IN subsets A’ K_TAC
8692 >> qabbrev_tac ‘sp = IMAGE Normal UNIV’ (* a restricted space *)
8693 >> Know ‘sp IN subsets A’
8694 >- (qunabbrev_tac ‘A’ \\
8695     MATCH_MP_TAC closed_in_general_borel \\
8696     simp [closed_in, topspace_ext_euclidean] \\
8697     Know ‘UNIV DIFF sp = {NegInf; PosInf}’
8698     >- (rw [Abbr ‘sp’, Once EXTENSION] \\
8699         EQ_TAC >> rw [] \\
8700         METIS_TAC [extreal_cases]) >> Rewr' \\
8701     REWRITE_TAC [open_in_ext_euclidean_infty])
8702 >> DISCH_TAC
8703 >> Suff ‘!a. a IN subsets A ==> real_set (a INTER sp) IN subsets borel’
8704 >- (DISCH_TAC \\
8705     rpt STRIP_TAC \\
8706     Q.PAT_X_ASSUM ‘!a. a IN subsets A ==> _’ (MP_TAC o Q.SPEC ‘a’) >> rw [] \\
8707     Q.EXISTS_TAC ‘real_set (a INTER sp)’ >> art [] \\
8708     rw [Once EXTENSION, real_set_def] \\
8709     EQ_TAC >> rw []
8710     >- (‘?r. x = Normal r’ by METIS_TAC [extreal_cases] \\
8711         Q.EXISTS_TAC ‘r’ >> rw [] \\
8712         Q.EXISTS_TAC ‘Normal r’ >> rw [real_normal] \\
8713         simp [Abbr ‘sp’]) \\
8714     simp [normal_real])
8715 >> qabbrev_tac ‘P = \a. real_set (a INTER sp) IN subsets borel’
8716 >> simp []
8717 >> Suff ‘subsets A SUBSET P’ >- METIS_TAC [SUBSET_DEF, IN_APP]
8718 >> simp [Abbr ‘A’, general_borel_def, topspace_ext_euclidean]
8719 >> MATCH_MP_TAC SIGMA_PROPERTY_ALT
8720 >> simp [subset_class_def, IN_FUNSET]
8721 >> CONJ_TAC (* {} IN P *)
8722 >- (simp [Abbr ‘P’, real_set_empty] \\
8723     MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY \\
8724     REWRITE_TAC [sigma_algebra_borel])
8725 >> CONJ_TAC (* open_in ext_euclidean SUBSET P *)
8726 >- (simp [SUBSET_DEF, Abbr ‘P’, Once IN_APP] \\
8727     Q.X_GEN_TAC ‘s’ >> DISCH_TAC \\
8728     Know ‘open_in ext_euclidean sp’
8729     >- (Q.PAT_X_ASSUM ‘sp IN subsets _’ K_TAC \\
8730         simp [Once OPEN_IN_SUBOPEN, Abbr ‘sp’] \\
8731         Q.X_GEN_TAC ‘z’ \\
8732         DISCH_THEN (Q.X_CHOOSE_THEN ‘r’ MP_TAC) >> rw [] \\
8733         Q.EXISTS_TAC ‘mball extreal_mr1 (Normal r,1 / 2)’ \\
8734         CONJ_TAC >- simp [ext_euclidean_def, OPEN_IN_MBALL] \\
8735         reverse CONJ_TAC
8736         >- (rw [SUBSET_DEF, IN_MBALL, extreal_mr1_normal', mspace_extreal_mr1] \\
8737             Cases_on ‘x = PosInf’ >> fs [] \\
8738             Cases_on ‘x = NegInf’ >> fs [] \\
8739             METIS_TAC [extreal_cases]) \\
8740         simp [IN_MBALL, extreal_mr1_normal', mspace_extreal_mr1]) >> DISCH_TAC \\
8741    ‘open_in ext_euclidean (s INTER sp)’ by PROVE_TAC [OPEN_IN_INTER] \\
8742     MATCH_MP_TAC borel_open \\
8743     qabbrev_tac ‘t = s INTER sp’ \\
8744     simp [open_def, real_set_def] \\
8745     Q.X_GEN_TAC ‘x’ \\
8746     DISCH_THEN (Q.X_CHOOSE_THEN ‘z’ MP_TAC) >> rw [] \\
8747     POP_ASSUM MP_TAC \\
8748    ‘?r. z = Normal r’ by METIS_TAC [extreal_cases] >> rw [] \\
8749     Q.PAT_X_ASSUM ‘open_in ext_euclidean t’ MP_TAC \\
8750     rw [ext_euclidean_def, OPEN_IN_MTOPOLOGY, mspace_extreal_mr1] \\
8751     POP_ASSUM (MP_TAC o Q.SPEC ‘Normal r’) >> art [] \\
8752     DISCH_THEN (Q.X_CHOOSE_THEN ‘e’ MP_TAC) \\
8753     rw [SUBSET_DEF, IN_MBALL, mspace_extreal_mr1] \\
8754     Cases_on ‘1 < e’ (* impossible case *)
8755     >- (Q.PAT_X_ASSUM ‘!x. _ ==> x IN t’ (MP_TAC o Q.SPEC ‘PosInf’) \\
8756         simp [Abbr ‘t’, Abbr ‘sp’]) \\
8757     FULL_SIMP_TAC std_ss [REAL_NOT_LT, Once DIST_SYM] \\
8758     Cases_on ‘e = 1’ (* trivial case *)
8759     >- (POP_ASSUM (fs o wrap) \\
8760        ‘t SUBSET sp’ by ASM_SET_TAC [] \\
8761         qabbrev_tac ‘d = sp DIFF t’ \\
8762         Know ‘t = sp’
8763         >- (Suff ‘d = {}’ >- ASM_SET_TAC [] \\
8764             CCONTR_TAC \\
8765             fs [GSYM MEMBER_NOT_EMPTY, Abbr ‘d’, Abbr ‘sp’] \\
8766             rename1 ‘x = Normal z’ \\
8767             Q.PAT_X_ASSUM ‘!x. _ ==> x IN t’ (MP_TAC o Q.SPEC ‘x’) \\
8768             rw [extreal_mr1_lt_1]) >> Rewr' \\
8769         qunabbrev_tac ‘d’ \\
8770         simp [Abbr ‘sp’] \\
8771         Q.EXISTS_TAC ‘1’ >> simp [] \\
8772         Q.X_GEN_TAC ‘y’ >> DISCH_TAC \\
8773         Q.EXISTS_TAC ‘Normal y’ >> simp []) \\
8774    ‘e < 1’ by simp [lt_le] \\
8775     Know ‘!y. dist extreal_mr1 (Normal r,Normal y) < e ==> Normal y IN t’
8776     >- rw [] \\
8777     SIMP_TAC real_ss [extreal_mr1_normal', dist] \\
8778     SIMP_TAC std_ss [REAL_ARITH “x - y < z <=> x - z < (y :real)”] \\
8779     Know ‘1 - e = inv (inv (1 - e))’
8780     >- (SYM_TAC >> MATCH_MP_TAC REAL_INVINV \\
8781         Suff ‘0 < 1 - e’ >- PROVE_TAC [REAL_LT_IMP_NE] \\
8782         simp [REAL_SUB_LT]) >> Rewr' \\
8783     Know ‘!y. inv (inv (1 - e)) < inv (1 + abs (r - y)) <=>
8784               1 + abs (r - y) < inv (1 - e)’
8785     >- (Q.X_GEN_TAC ‘x’ \\
8786         MATCH_MP_TAC REAL_INV_LT_ANTIMONO >> simp []) >> Rewr' \\
8787         SIMP_TAC std_ss [REAL_ARITH “x + y < z <=> y < z - (x :real)”] \\
8788         DISCH_TAC \\
8789         Q.EXISTS_TAC ‘inv (1 - e) - 1’ \\
8790         CONJ_TAC >- simp [REAL_SUB_LT] \\
8791         Q.X_GEN_TAC ‘y’ >> DISCH_TAC \\
8792         Q.EXISTS_TAC ‘Normal y’ >> simp [real_normal])
8793 >> CONJ_TAC
8794 >- (rw [Abbr ‘P’] \\
8795     qabbrev_tac ‘t = real_set (s INTER sp)’ \\
8796     Suff ‘real_set ((univ(:extreal) DIFF s) INTER sp) = space borel DIFF t’
8797     >- (Rewr' >> MATCH_MP_TAC SIGMA_ALGEBRA_COMPL \\
8798         simp [sigma_algebra_borel]) \\
8799     rw [space_borel, Once EXTENSION, real_set_def, Abbr ‘t’] \\
8800     simp [Abbr ‘sp’] \\
8801     EQ_TAC >> rw [] >> fs [real_normal]
8802     >- (rename1 ‘real x = r’ \\
8803         Cases_on ‘x = PosInf’ >- simp [] \\
8804         Cases_on ‘x = NegInf’ >- simp [] \\
8805        ‘?z. x = Normal z’ by METIS_TAC [extreal_cases] \\
8806         fs [real_normal]) \\
8807     POP_ASSUM (MP_TAC o Q.SPEC ‘Normal x’) >> rw [] \\
8808     Q.EXISTS_TAC ‘Normal x’ >> simp [])
8809 >> rw [Abbr ‘P’, FORALL_AND_THM]
8810 >> Suff ‘real_set (BIGUNION (IMAGE f univ(:num)) INTER sp) =
8811          BIGUNION (IMAGE (\i. real_set (f i INTER sp)) UNIV)’
8812 >- (Rewr' \\
8813     MATCH_MP_TAC SIGMA_ALGEBRA_COUNTABLE_UNION \\
8814     simp [image_countable, sigma_algebra_borel] \\
8815     rw [SUBSET_DEF] >> art [])
8816 >> NTAC 3 (POP_ASSUM K_TAC)
8817 >> rw [Once EXTENSION, IN_BIGUNION_IMAGE, Abbr ‘sp’, real_set_def]
8818 >> EQ_TAC >> rw []
8819 >- (rename1 ‘Normal r IN f n’ \\
8820     qexistsl_tac [‘n’, ‘Normal r’] >> simp [])
8821 >> rename1 ‘Normal r IN f n’
8822 >> Q.EXISTS_TAC ‘Normal r’ >> simp []
8823 >> Q.EXISTS_TAC ‘n’ >> art []
8824QED
8825
8826Theorem IN_MEASURABLE_CONTINUOUS_MAP :
8827    !top1 top2 f. continuous_map (top1,top2) f ==>
8828                  f IN measurable (general_borel top1) (general_borel top2)
8829Proof
8830    rw [CONTINUOUS_MAP, measurable_def, IN_FUNSET, SUBSET_DEF, space_general_borel]
8831 >- (rename1 ‘f y IN topspace top2’ \\
8832     FIRST_X_ASSUM MATCH_MP_TAC \\
8833     Q.EXISTS_TAC ‘y’ >> art [])
8834 >> POP_ASSUM MP_TAC
8835 >> Q.ID_SPEC_TAC ‘s’
8836 >> qabbrev_tac
8837     ‘P = \s. PREIMAGE f s INTER topspace top1 IN subsets (general_borel top1)’
8838 >> simp []
8839 >> Suff ‘subsets (general_borel top2) SUBSET {s | s SUBSET topspace top2 /\ P s}’
8840 >- SET_TAC []
8841 >> REWRITE_TAC [general_borel_def]
8842 >> MATCH_MP_TAC SIGMA_PROPERTY_ALT
8843 >> CONJ_TAC >- rw [Abbr ‘P’, subset_class_def]
8844 >> CONJ_TAC
8845 >- (simp [Abbr ‘P’] \\
8846     MATCH_MP_TAC SIGMA_ALGEBRA_EMPTY \\
8847     REWRITE_TAC [sigma_algebra_general_borel])
8848 >> CONJ_TAC
8849 >- (simp [SUBSET_DEF, Once IN_APP] \\
8850     Q.X_GEN_TAC ‘s’ >> rw [Abbr ‘P’]
8851     >- (rename1 ‘y IN s’ \\
8852         simp [topspace, IN_BIGUNION] \\
8853         Q.EXISTS_TAC ‘s’ >> art []) \\
8854     simp [PREIMAGE_def] \\
8855     MATCH_MP_TAC open_in_general_borel \\
8856    ‘{x | f x IN s} INTER topspace top1 = {x | x IN topspace top1 /\ f x IN s}’
8857       by SET_TAC [] >> POP_ORW \\
8858     FIRST_X_ASSUM MATCH_MP_TAC >> art [])
8859 >> CONJ_TAC
8860 >- (rw [Abbr ‘P’] \\
8861     Suff ‘PREIMAGE f (topspace top2 DIFF s) INTER topspace top1 =
8862           space (general_borel top1) DIFF (PREIMAGE f s INTER topspace top1)’
8863     >- (Rewr' \\
8864         MATCH_MP_TAC SIGMA_ALGEBRA_COMPL \\
8865         simp [sigma_algebra_general_borel]) \\
8866     simp [PREIMAGE_DIFF, space_general_borel] \\
8867     rw [Once EXTENSION] >> METIS_TAC [])
8868 >> rw [IN_FUNSET, Abbr ‘P’, FORALL_AND_THM, SUBSET_DEF]
8869 >- (FIRST_X_ASSUM MATCH_MP_TAC \\
8870     rename1 ‘x IN g n’ \\
8871     Q.EXISTS_TAC ‘n’ >> art [])
8872 >> simp [PREIMAGE_BIGUNION, IMAGE_IMAGE, BIGUNION_OVER_INTER_L]
8873 >> MATCH_MP_TAC SIGMA_ALGEBRA_COUNTABLE_UNION
8874 >> simp [sigma_algebra_general_borel, image_countable]
8875 >> rw [SUBSET_DEF] >> simp []
8876QED
8877
8878(* NOTE: This proof is tedious but easy to work out, based on the existing
8879   borel_measurable_real_set.
8880 *)
8881Theorem borel_measurable_image_real :
8882    !s. s IN subsets Borel ==> IMAGE real s IN subsets borel
8883Proof
8884    rpt STRIP_TAC
8885 >> Cases_on ‘PosInf IN s’ >> Cases_on ‘NegInf IN s’ (* 4 subgoals *)
8886 >| [ (* goal 1 (of 4) *)
8887      qabbrev_tac ‘t = s DIFF ({PosInf} UNION {NegInf})’ \\
8888      Know ‘t IN subsets Borel’
8889      >- (qunabbrev_tac ‘t’ \\
8890          MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> rw [SIGMA_ALGEBRA_BOREL] \\
8891          MATCH_MP_TAC SIGMA_ALGEBRA_UNION \\
8892          simp [SIGMA_ALGEBRA_BOREL, BOREL_MEASURABLE_SETS]) >> DISCH_TAC \\
8893     ‘PosInf NOTIN t /\ NegInf NOTIN t’ by ASM_SET_TAC [] \\
8894     ‘s = t UNION {PosInf; NegInf}’ by ASM_SET_TAC [] >> POP_ORW \\
8895      Know ‘IMAGE real (t UNION {PosInf; NegInf}) = real_set t UNION {0}’
8896      >- (rw [Once EXTENSION, real_set_def] \\
8897          EQ_TAC >> rw [] >> simp [] >| (* 3 subgoals left *)
8898          [ (* goal 1.1 (of 3) *)
8899            rename1 ‘y IN t’ \\
8900           ‘y <> PosInf /\ y <> NegInf’ by METIS_TAC [] \\
8901           ‘?r. y = Normal r’ by METIS_TAC [extreal_cases] \\
8902            simp [] >> DISJ1_TAC \\
8903            Q.EXISTS_TAC ‘y’ >> simp [],
8904            (* goal 1.2 (of 3) *)
8905            rename1 ‘y IN t’ \\
8906           ‘?r. y = Normal r’ by METIS_TAC [extreal_cases] \\
8907            simp [] \\
8908            Q.EXISTS_TAC ‘y’ >> simp [],
8909            (* goal 1.3 (of 3) *)
8910            Q.EXISTS_TAC ‘PosInf’ >> simp [] ]) >> Rewr' \\
8911      MATCH_MP_TAC SIGMA_ALGEBRA_UNION \\
8912      simp [sigma_algebra_borel, borel_measurable_sets] \\
8913      MATCH_MP_TAC borel_measurable_real_set >> art [],
8914      (* goal 2 (of 4) *)
8915      qabbrev_tac ‘t = s DIFF {PosInf}’ \\
8916      Know ‘t IN subsets Borel’
8917      >- (qunabbrev_tac ‘t’ \\
8918          MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> rw [SIGMA_ALGEBRA_BOREL]) \\
8919      DISCH_TAC \\
8920     ‘PosInf NOTIN t /\ NegInf NOTIN t’ by ASM_SET_TAC [] \\
8921     ‘s = t UNION {PosInf}’ by ASM_SET_TAC [] >> POP_ORW \\
8922      Know ‘IMAGE real (t UNION {PosInf}) = real_set t UNION {0}’
8923      >- (rw [Once EXTENSION, real_set_def] \\
8924          EQ_TAC >> rw [] >> simp [] >| (* 3 subgoals left *)
8925          [ (* goal 2.1 (of 3) *)
8926            rename1 ‘y IN t’ \\
8927           ‘y <> PosInf /\ y <> NegInf’ by METIS_TAC [] \\
8928           ‘?r. y = Normal r’ by METIS_TAC [extreal_cases] \\
8929            simp [] >> DISJ1_TAC \\
8930            Q.EXISTS_TAC ‘y’ >> simp [],
8931            (* goal 2.2 (of 3) *)
8932            rename1 ‘y IN t’ \\
8933           ‘?r. y = Normal r’ by METIS_TAC [extreal_cases] \\
8934            simp [] >> Q.EXISTS_TAC ‘y’ >> simp [],
8935            (* goal 2.3 (of 3) *)
8936            Q.EXISTS_TAC ‘PosInf’ >> simp [] ]) >> Rewr' \\
8937      MATCH_MP_TAC SIGMA_ALGEBRA_UNION \\
8938      simp [sigma_algebra_borel, borel_measurable_sets] \\
8939      MATCH_MP_TAC borel_measurable_real_set >> art [],
8940      (* goal 3 (of 4) *)
8941      qabbrev_tac ‘t = s DIFF {NegInf}’ \\
8942      Know ‘t IN subsets Borel’
8943      >- (qunabbrev_tac ‘t’ \\
8944          MATCH_MP_TAC SIGMA_ALGEBRA_DIFF >> rw [SIGMA_ALGEBRA_BOREL]) \\
8945      DISCH_TAC \\
8946     ‘PosInf NOTIN t /\ NegInf NOTIN t’ by ASM_SET_TAC [] \\
8947     ‘s = t UNION {NegInf}’ by ASM_SET_TAC [] >> POP_ORW \\
8948      Know ‘IMAGE real (t UNION {NegInf}) = real_set t UNION {0}’
8949      >- (rw [Once EXTENSION, real_set_def] \\
8950          EQ_TAC >> rw [] >> simp [] >| (* 3 subgoals left *)
8951          [ (* goal 3.1 (of 3) *)
8952            rename1 ‘y IN t’ \\
8953           ‘y <> PosInf /\ y <> NegInf’ by METIS_TAC [] \\
8954           ‘?r. y = Normal r’ by METIS_TAC [extreal_cases] \\
8955            simp [] >> DISJ1_TAC \\
8956            Q.EXISTS_TAC ‘y’ >> simp [],
8957            (* goal 3.2 (of 3) *)
8958            rename1 ‘y IN t’ \\
8959           ‘?r. y = Normal r’ by METIS_TAC [extreal_cases] \\
8960            simp [] >> Q.EXISTS_TAC ‘y’ >> simp [],
8961            (* goal 3.3 (of 3) *)
8962            Q.EXISTS_TAC ‘NegInf’ >> simp [] ]) >> Rewr' \\
8963      MATCH_MP_TAC SIGMA_ALGEBRA_UNION \\
8964      simp [sigma_algebra_borel, borel_measurable_sets] \\
8965      MATCH_MP_TAC borel_measurable_real_set >> art [],
8966      (* goal 4 (of 4) *)
8967      Know ‘IMAGE real s = real_set s’
8968      >- (rw [Once EXTENSION, real_set_def] \\
8969          EQ_TAC >> rw [] >> simp [] >| (* 2 subgoals left *)
8970          [ (* goal 4.1 (of 2) *)
8971            rename1 ‘y IN s’ \\
8972           ‘y <> PosInf /\ y <> NegInf’ by METIS_TAC [] \\
8973            Q.EXISTS_TAC ‘y’ >> simp [],
8974            (* goal 4.2 (of 2) *)
8975            rename1 ‘y IN t’ \\
8976            Q.EXISTS_TAC ‘y’ >> simp [] ]) >> Rewr' \\
8977      MATCH_MP_TAC borel_measurable_real_set >> art [] ]
8978QED
8979
8980(* A different version of this also exists in Martingale,
8981   but it can proved here, and this form is more consistent with other results.
8982- Jared
8983*)
8984
8985Theorem IN_MEASURABLE_BOREL_FROM_PROD_SIGMA':
8986    ∀a b f. sigma_algebra a ∧ sigma_algebra b ∧ f ∈ Borel_measurable (a × b) ⇒
8987        (∀y. y ∈ space b ⇒ (λx. f (x,y)) ∈ Borel_measurable a) ∧
8988        (∀x. x ∈ space a ⇒ (λy. f (x,y)) ∈ Borel_measurable b)
8989Proof
8990    rpt gen_tac >> DISCH_TAC >> irule IN_MEASURABLE_FROM_PROD_SIGMA >> simp[SIGMA_ALGEBRA_BOREL]
8991QED
8992
8993(* References:
8994
8995  [1] Schilling, R.L.: Measures, Integrals and Martingales (Second Edition).
8996      Cambridge University Press (2017).
8997  [2] Mhamdi, T., Hasan, O., Tahar, S.: Formalization of Measure Theory and
8998      Lebesgue Integration for Probabilistic Analysis in HOL.
8999      ACM Trans. Embedded Comput. Syst. 12, 1--23 (2013).
9000  [3] Coble, A.R.: Anonymity, information, and machine-assisted proof, (2010).
9001  [4] Hurd, J.: Formal verification of probabilistic algorithms. (2001).
9002  [7] Wikipedia: https://en.wikipedia.org/wiki/Emile_Borel
9003  [8] Hardy, G.H., Littlewood, J.E.: A Course of Pure Mathematics, Tenth Edition.
9004      Cambridge University Press, London (1967).
9005 *)