Debian Codegraph @

reals/stdlib/CMTReals.v

raw
1 (*
2 Copyright © 2020 Vincent Semeria
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
6 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
8 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 *)
10
11
12
13 (*
14 We provide the standard constructive integration space on the real
15 numbers. This is the constructive expression of the Lebesgue measure.
16
17 The elementary functions are the uniformly continuous functions R -> R
18 with compact support, with the canonical definition of the integral
19 in this case : the difference of anti-derivatives.
20
21 It is the example given by Bishop and Cheng, page 67 of
22 their article. Working in R rather than in a locally
23 compact space X simplifies the proof, because we replace
24 compact sets by segments (thus skipping the theory of profiles).
25
26 One might be tempted to restrict to piecewise linear functions with
27 compact support, however one cannot constructively prove that those
28 are stable under absolute value. It would require exact comparisons
29 of the values of the functions with zero.
30 *)
31
32 From Coq Require Import ZArith QArith Qminmax Qpower Qabs.
33
34 From Coq Require Import ConstructiveReals.
35 From Coq Require Import ConstructiveAbs.
36 From Coq Require Import ConstructiveMinMax.
37 From Coq Require Import ConstructiveSum.
38 From Coq Require Import ConstructivePower.
39 From Coq Require Import ConstructiveLimits.
40 Require Import ConstructiveDiagonal.
41 Require Import ConstructivePartialFunctions.
42 Require Import ConstructiveUniformCont.
43 Require Import ConstructiveCauchyIntegral.
44 Require Import CMTbase.
45 Require Import CMTPositivity.
46 Require Import CMTIntegrableFunctions.
47 Require Import CMTFullSets.
48 Require Import CMTIntegrableSets.
49
50 Local Open Scope ConstructiveReals.
51
52
53 Record Is_CSUC_func {R : ConstructiveReals}
54 (f : PartialFunction (CRcarrier R)) : Type :=
55 {
56 CSUC_fullDomain : forall x : CRcarrier R, Domain f x;
57 CSUC_low : CRcarrier R;
58 CSUC_high : CRcarrier R;
59 (* The zero function has an empty support, but we
60 can extend it to a point. A nonempty support allows
61 to define its distance to a point. *)
62 CSUC_lowHigh : CSUC_low <= CSUC_high;
63 CSUC_cont_mod : forall x:CRcarrier R, 0 < x -> CRcarrier R;
64 CSUC_adapt : CSUC (TotalizeFunc (CRcarrier R) f CSUC_fullDomain)
65 CSUC_low CSUC_high CSUC_cont_mod;
66 }.
67
68 Definition CSUC_func_plus_stable
69 : forall {R : ConstructiveReals} (f g : PartialFunction (CRcarrier R)),
70 Is_CSUC_func f -> Is_CSUC_func g -> Is_CSUC_func (Xplus f g).
71 Proof.
72 intros R [df f injPrF] [dg g injPrG]
73 [fullDomF lowF highF lowHighF modF]
74 [fullDomG lowG highG lowHighG modG].
75 assert (CRmin lowF lowG <= CRmax highF highG) as sumLowHigh.
76 { apply (CRle_trans _ lowF). apply CRmin_l.
77 apply (CRle_trans _ highF). apply lowHighF. apply CRmax_l. }
78 apply (Build_Is_CSUC_func
79 R (Xplus
80 {| Domain := df; partialApply := f; DomainProp := injPrF |}
81 {| Domain := dg; partialApply := g; DomainProp := injPrG |})
82 (fun x => pair (fullDomF x) (fullDomG x))
83 (CRmin lowF lowG) (CRmax highF highG) sumLowHigh
84 (fun x xPos => CRmin (modF (x * CR_of_Q R (1#2)) (eps2_Rgt_R0 x xPos))
85 (modG (x * CR_of_Q R (1#2)) (eps2_Rgt_R0 x xPos)))).
86 split.
87 - apply UC_plus. apply CSUC_adapt0. apply CSUC_adapt1.
88 - intros. simpl.
89 destruct CSUC_adapt0 as [H0 H1]. simpl in H1. rewrite H1.
90 destruct CSUC_adapt1 as [H2 H3]. simpl in H3. rewrite H3.
91 rewrite CRplus_0_l. reflexivity.
92 destruct H as [H|H].
93 left. apply (CRlt_le_trans x _ _ H). apply CRmin_r.
94 right.
95 apply (CRle_lt_trans _ (CRmax highF highG)).
96 apply CRmax_r. apply H.
97 destruct H as [H|H]. left. apply (CRlt_le_trans x _ _ H).
98 apply CRmin_l. right.
99 apply (CRle_lt_trans _ (CRmax highF highG)).
100 apply CRmax_l. apply H.
101 Defined.
102
103 Definition CSUC_func_abs_stable
104 : forall {R : ConstructiveReals} (f : PartialFunction (CRcarrier R)),
105 Is_CSUC_func f -> Is_CSUC_func (Xabs f).
106 Proof.
107 intros R f H. destruct H, f.
108 apply (Build_Is_CSUC_func
109 R (Xabs
110 {|
111 Domain := Domain;
112 partialApply := partialApply;
113 DomainProp := DomainProp |})
114 CSUC_fullDomain0
115 CSUC_low0 CSUC_high0 CSUC_lowHigh0 CSUC_cont_mod0).
116 destruct CSUC_adapt0. split. split.
117 - intro x. apply (fst u).
118 - intros. simpl.
119 apply (CRle_lt_trans _ _ _ (CRabs_triang_inv2 _ _)).
120 destruct u.
121 apply (c1 _ _ _ epsPos). apply H.
122 - intros. simpl. destruct u. simpl in c. rewrite c.
123 apply CRabs_right. apply CRle_refl. apply H.
124 Defined.
125
126 Definition CSUC_func_min_stable
127 : forall {R : ConstructiveReals} (f : PartialFunction (CRcarrier R)),
128 Is_CSUC_func f -> Is_CSUC_func (XminConst f 1).
129 Proof.
130 intros R f H. destruct H,f.
131 apply (Build_Is_CSUC_func
132 R (XminConst
133 {|
134 Domain := Domain;
135 partialApply := partialApply;
136 DomainProp := DomainProp |} 1)
137 CSUC_fullDomain0
138 CSUC_low0 CSUC_high0 CSUC_lowHigh0 CSUC_cont_mod0).
139 destruct CSUC_adapt0. split. split.
140 - intro x. apply (fst u).
141 - intros. simpl.
142 apply (CRle_lt_trans _ (CRabs _ (partialApply x (CSUC_fullDomain0 x)
143 - partialApply y (CSUC_fullDomain0 y)))).
144 apply CRmin_contract.
145 destruct u. apply (c1 _ _ _ epsPos). apply H.
146 - intros. simpl in c.
147 unfold TotalizeFunc, XminConst, Xop, ConstructivePartialFunctions.partialApply.
148 rewrite c. apply CRmin_left.
149 apply CRlt_asym, CRzero_lt_one. apply H.
150 Defined.
151
152 Definition CSUC_func_scale {R : ConstructiveReals} (a : CRcarrier R)
153 (f : PartialFunction (CRcarrier R))
154 : Is_CSUC_func f -> Is_CSUC_func (Xscale a f).
155 Proof.
156 intros H. destruct H,f.
157
158 apply (Build_Is_CSUC_func
159 R (Xscale a
160 {|
161 Domain := Domain;
162 partialApply := partialApply;
163 DomainProp := DomainProp |})
164 CSUC_fullDomain0
165 CSUC_low0 CSUC_high0 CSUC_lowHigh0
166 (fun (eps:CRcarrier R) epsPos
167 => CSUC_cont_mod0 (eps * CRinv R (CRmax 1 (CRabs _ a)) (inr (posScale a)))
168 (CRmult_lt_0_compat _
169 eps _ epsPos (CRinv_0_lt_compat _
170 _ (inr (posScale a)) (posScale a))))).
171 destruct CSUC_adapt0. split.
172 - apply UC_scale. exact u.
173 - intros. simpl. simpl in c. rewrite c.
174 rewrite CRmult_0_r. reflexivity. exact H.
175 Defined.
176
177 Lemma CSUCext :
178 forall {R : ConstructiveReals} (f g : PartialFunction (CRcarrier R)),
179 PartialFunExtEq f g -> Is_CSUC_func f -> Is_CSUC_func g.
180 Proof.
181 intros R f g H H0. destruct f,g,H,H0,p; simpl in d.
182 simpl in CSUC_fullDomain0.
183 apply (Build_Is_CSUC_func R
184 {|
185 Domain := Domain0;
186 partialApply := partialApply0;
187 DomainProp := DomainProp0 |}
188 (fun x => d x (CSUC_fullDomain0 x)) CSUC_low0 CSUC_high0
189 CSUC_lowHigh0 CSUC_cont_mod0).
190 split.
191 apply (UC_ext (TotalizeFunc (CRcarrier R)
192 {|
193 Domain := Domain;
194 partialApply := partialApply;
195 DomainProp := DomainProp |} CSUC_fullDomain0)).
196 apply CSUC_adapt0. intro x. simpl.
197 apply c.
198 intros. simpl. destruct CSUC_adapt0. simpl in c, c0.
199 rewrite <- (c x (CSUC_fullDomain0 x)). apply c0. exact H.
200 Defined.
201
202 Definition ElemCSUC {R : ConstructiveReals}
203 : FunctionRieszSpace.
204 Proof.
205 apply (Build_FunctionRieszSpace
206 (CRcarrier R) R Is_CSUC_func).
207 - apply CSUCext.
208 - apply CSUC_func_plus_stable.
209 - apply CSUC_func_abs_stable.
210 - apply CSUC_func_min_stable.
211 - apply CSUC_func_scale.
212 Defined.
213
214 Definition IntegralCSUC {R : ConstructiveReals}
215 (f : PartialFunction (CRcarrier R)) (fCSUC : Is_CSUC_func f) : CRcarrier R
216 := UC_integral
217 (TotalizeFunc (CRcarrier R) f (CSUC_fullDomain _ fCSUC))
218 (CSUC_low _ fCSUC) (CSUC_high _ fCSUC)
219 (CSUC_cont_mod _ fCSUC)
220 (fst (CSUC_adapt _ fCSUC))
221 (CSUC_lowHigh _ fCSUC).
222
223 (* Extend the support *)
224 Lemma CSUCextendAdapt : forall {R : ConstructiveReals} (f : PartialFunction (CRcarrier R))
225 (fL : Is_CSUC_func f)
226 (a b : CRcarrier R),
227 a <= CSUC_low f fL
228 -> CSUC_high f fL <= b
229 -> CSUC (TotalizeFunc (CRcarrier R) f (CSUC_fullDomain f fL)) a b
230 (CSUC_cont_mod f fL).
231 Proof.
232 split. split.
233 - apply fL.
234 - apply fL.
235 - intros. destruct fL,CSUC_adapt0,u.
236 simpl. simpl in H,H0. rewrite (c x).
237 reflexivity. destruct H1. left. exact (CRlt_le_trans x a _ c2 H).
238 right. exact (CRle_lt_trans _ b x H0 c2).
239 Qed.
240
241 Lemma CSUCextendSupport : forall {R : ConstructiveReals} (f : PartialFunction (CRcarrier R))
242 (fL : Is_CSUC_func f)
243 (a b : CRcarrier R)
244 (aBelow : a <= CSUC_low f fL)
245 (bAbove : CSUC_high f fL <= b)
246 (leab : a <= b), (* redundant *)
247 IntegralCSUC f fL
248 == UC_integral
249 (TotalizeFunc (CRcarrier R) f (CSUC_fullDomain f fL))
250 a b (CSUC_cont_mod f fL)
251 (fst (CSUCextendAdapt f fL a b aBelow bAbove)) leab.
252 Proof.
253 (* Use Chasles relation *)
254 intros.
255 assert (CSUC_low f fL <= b).
256 { apply (CRle_trans _ (CSUC_high f fL)).
257 apply CSUC_lowHigh. apply bAbove. }
258 rewrite (UC_integral_chasles a (CSUC_low f fL) b
259 _ _ _ aBelow H).
260 rewrite (UC_integral_chasles (CSUC_low f fL) (CSUC_high f fL) b
261 _ _ _ (CSUC_lowHigh f fL) bAbove).
262 rewrite (UC_integral_zero _ a (CSUC_low f fL)).
263 rewrite (UC_integral_zero _ (CSUC_high f fL) b).
264 rewrite CRplus_0_l, CRplus_0_r.
265 apply (UC_integral_extens
266 (TotalizeFunc (CRcarrier R) f (CSUC_fullDomain f fL))
267 (TotalizeFunc (CRcarrier R) f (CSUC_fullDomain f fL))
268 (CSUC_low f fL) (CSUC_high f fL)).
269 - intros. reflexivity.
270 - intros.
271 apply (CSUC_connect_support
272 _ (CSUC_low f fL)
273 (CSUC_high f fL) (CSUC_cont_mod f fL)).
274 apply fL. right. apply H0.
275 - intros.
276 apply (CSUC_connect_support
277 _ (CSUC_low f fL)
278 (CSUC_high f fL) (CSUC_cont_mod f fL)).
279 apply fL. left. apply H0.
280 Qed.
281
282 Lemma CSUCIntegralAdditive : forall {R : ConstructiveReals}
283 (f g : PartialFunction (CRcarrier R))
284 (fL : Is_CSUC_func f)
285 (gL : Is_CSUC_func g),
286 IntegralCSUC (Xplus f g) (CSUC_func_plus_stable f g fL gL)
287 == IntegralCSUC f fL + IntegralCSUC g gL.
288 Proof.
289 intros.
290 pose (CRmin (CSUC_low f fL) (CSUC_low g gL)) as c.
291 pose (CRmax (CSUC_high f fL) (CSUC_high g gL)) as d.
292 assert (c <= d).
293 { apply (CRle_trans _ (CSUC_low f fL)). apply CRmin_l.
294 apply (CRle_trans _ (CSUC_high f fL)). apply (CSUC_lowHigh f fL).
295 apply CRmax_l. }
296 (* Integrate f and g on [c,d], with same integral because
297 they equal 0 outside their supports. *)
298 rewrite (CSUCextendSupport f fL c d (CRmin_l _ _) (CRmax_l _ _) H).
299 rewrite (CSUCextendSupport g gL c d (CRmin_r _ _) (CRmax_r _ _) H).
300 transitivity (UC_integral
301 (fun x => TotalizeFunc (CRcarrier R) f (CSUC_fullDomain f fL) x
302 + TotalizeFunc (CRcarrier R) g (CSUC_fullDomain g gL) x)
303 (CSUC_low (Xplus f g) (CSUC_func_plus_stable f g fL gL))
304 (CSUC_high (Xplus f g) (CSUC_func_plus_stable f g fL gL))
305 _ (UC_plus _ _ _ _ (fst (CSUC_adapt f fL))
306 (fst (CSUC_adapt g gL)))
307 (CSUC_lowHigh (Xplus f g) (CSUC_func_plus_stable f g fL gL))).
308 unfold IntegralCSUC.
309 apply (UC_integral_extens
310 (TotalizeFunc (CRcarrier R) (Xplus f g)
311 (CSUC_fullDomain (Xplus f g) (CSUC_func_plus_stable f g fL gL)))
312 (fun x : CRcarrier R =>
313 TotalizeFunc (CRcarrier R) f (CSUC_fullDomain f fL) x +
314 TotalizeFunc (CRcarrier R) g (CSUC_fullDomain g gL) x)).
315 - intros. destruct f,g,fL,gL; reflexivity.
316 - destruct f,g,fL,gL; apply UC_integral_plus.
317 Qed.
318
319 Lemma CSUCIntegralAdditiveIterate
320 : forall {R : ConstructiveReals} (fn : nat -> @PartialFunction R (X ElemCSUC))
321 (fnL : forall n : nat, L ElemCSUC (fn n)) (N : nat),
322 IntegralCSUC (Xsum fn N) (LsumStable fn fnL N)
323 == CRsum (fun n : nat => IntegralCSUC (fn n) (fnL n)) N.
324 Proof.
325 induction N.
326 - reflexivity.
327 - simpl. rewrite <- IHN.
328 rewrite CSUCIntegralAdditive. reflexivity.
329 Qed.
330
331 Lemma CSUC_bound_ext
332 : forall {R : ConstructiveReals} (f : CRcarrier R -> CRcarrier R)
333 (a b c d : CRcarrier R) (cont_mod : forall x:CRcarrier R, 0 < x -> CRcarrier R),
334 a == c
335 -> b == d
336 -> CSUC f a b cont_mod
337 -> CSUC f c d cont_mod.
338 Proof.
339 intros. destruct H1. split. exact u.
340 intros. destruct H1. apply c0. left.
341 apply (CRlt_le_trans _ _ _ c1). apply H.
342 apply c0. right. apply (CRle_lt_trans _ d).
343 apply H0. exact c1.
344 Qed.
345
346 Definition CSUCTrapeze_IS_CSUC
347 {R : ConstructiveReals} (a b eta : CRcarrier R) (etaPos : 0 < eta)
348 : a <= b -> Is_CSUC_func (PartializeFunc (CRcarrier R)
349 (CSUCUnitTrapeze a b eta etaPos))
350 := fun leab => Build_Is_CSUC_func
351 R (PartializeFunc (CRcarrier R)
352 (CSUCUnitTrapeze a b eta etaPos))
353 (fun x:CRcarrier R => Logic.I)
354 (a-eta) (b+eta) (TrapezeLe a b eta etaPos leab)
355 (* The modulus could be improved to eps *)
356 (fun eps epsPos => eps * CR_of_Q R (1#2) * eta)
357 (CSUCTrapeze_CSUC a b eta etaPos leab).
358
359 Lemma CSUCIntegralHomogeneous
360 : forall {R : ConstructiveReals} (a : CRcarrier R) (f : PartialFunction (CRcarrier R))
361 (fL : Is_CSUC_func f),
362 IntegralCSUC (Xscale a f) (CSUC_func_scale a f fL)
363 == a * IntegralCSUC f fL.
364 Proof.
365 intros. (* Get the a inside to the right *)
366 unfold IntegralCSUC.
367 rewrite <- UC_integral_scale.
368 destruct f,fL; apply UC_integral_extens; reflexivity.
369 Qed.
370
371 Section CSUCContinuous. (* Hide the details of this proof *)
372
373 Variable (R : ConstructiveReals)
374 (g : CRcarrier R -> CRcarrier R)
375 (fn : nat -> CRcarrier R -> CRcarrier R)
376 (fnPos : forall (k:nat) (x:CRcarrier R), 0 <= fn k x)
377 (fnMod : nat -> forall eps:CRcarrier R, 0 < eps -> CRcarrier R)
378 (fnCont : forall n:nat, UniformCont (fn n) (fnMod n))
379 (gMod : forall eps:CRcarrier R, 0 < eps -> CRcarrier R)
380 (a b : CRcarrier R)
381 (leab : a <= b)
382 (gCSUC : CSUC g a b gMod)
383 (majInt : series_cv_lim_lt (fun k : nat => UC_integral
384 (fn k) a b
385 (fnMod k) (fnCont k) leab)
386 (UC_integral
387 g a b
388 gMod (fst gCSUC) leab)).
389
390 (* An interval where the searched point is *)
391 Record CSUCposPointApprox
392 : Set :=
393 { x : CRcarrier R;
394 y : CRcarrier R;
395 lexy : x <= y;
396
397 lambdaInfiniteMaj :
398 series_cv_lim_lt (fun k : nat => UC_integral
399 (fn k) x y
400 (fnMod k) (fnCont k) lexy)
401 (UC_integral
402 g x y
403 gMod (fst gCSUC) lexy);
404 }.
405
406
407 Definition CSUCposPointApproxInit
408 : CSUCposPointApprox
409 := Build_CSUCposPointApprox a b leab majInt.
410
411 Lemma LocalizeIntegralSeries
412 : forall (x y z t : CRcarrier R) (infint : CRcarrier R)
413 (lexy : x <= y) (lezt : z <= t),
414 x <= z
415 -> t <= y
416 -> series_cv (fun k : nat => UC_integral
417 (fn k) x y
418 (fnMod k) (fnCont k) lexy)
419 infint
420 -> { sLoc : CRcarrier R & series_cv (fun k : nat => UC_integral
421 (fn k) z t
422 (fnMod k) (fnCont k) lezt)
423 sLoc }.
424 Proof.
425 intros.
426 destruct (series_cv_maj (fun k : nat => UC_integral
427 (fn k) z t
428 (fnMod k) (fnCont k) lezt)
429 (fun k : nat => UC_integral
430 (fn k) x0 y0
431 (fnMod k) (fnCont k) lexy0)
432 infint).
433 - intros. rewrite CRabs_right.
434 apply (UC_integral_extend_nonneg (fn n) (fnMod n)).
435 exact H. exact H0. apply fnPos.
436 apply UC_integral_pos.
437 intros. apply fnPos.
438 - exact H1.
439 - exists x1. apply p.
440 Qed.
441
442
443 Definition CSUCposPointApproxStep
444 (n : nat)
445 (currStep : CSUCposPointApprox)
446 : { nextApprox : CSUCposPointApprox
447 | x currStep <= x nextApprox
448 /\ y nextApprox <= y currStep
449 /\ y nextApprox - x nextApprox == (y currStep - x currStep) * CR_of_Q R (1#2) }.
450 Proof.
451 clear majInt. destruct currStep, lambdaInfiniteMaj0, p as [i r].
452 assert (x0 <= (x0+y0) * CR_of_Q R (1#2)).
453 { apply (CRmult_le_reg_r (CR_of_Q R 2)). apply CR_of_Q_pos. reflexivity.
454 rewrite CRmult_assoc, <- CR_of_Q_mult.
455 setoid_replace ((1 # 2) * 2)%Q with 1%Q. 2: reflexivity.
456 rewrite (CR_of_Q_plus R 1 1), CRmult_plus_distr_l, CRmult_1_r, CRmult_1_r.
457 apply CRplus_le_compat_l. exact lexy0. }
458 assert ((x0+y0) * CR_of_Q R (1#2) <= y0).
459 { apply (CRmult_le_reg_r (CR_of_Q R 2)). apply CR_of_Q_pos. reflexivity.
460 rewrite CRmult_assoc, <- CR_of_Q_mult.
461 setoid_replace ((1 # 2) * 2)%Q with 1%Q. 2: reflexivity.
462 rewrite (CR_of_Q_plus R 1 1), CRmult_plus_distr_l, CRmult_1_r, CRmult_1_r.
463 apply CRplus_le_compat_r. exact lexy0. }
464 destruct (LocalizeIntegralSeries
465 x0 y0 x0 ((x0+y0)*CR_of_Q R (1#2)) x1 lexy0 H (CRle_refl x0)).
466 exact H0. exact i.
467 destruct (LocalizeIntegralSeries
468 x0 y0 ((x0+y0) * CR_of_Q R (1#2)) y0 x1 lexy0 H0 H).
469 apply CRle_refl. exact i.
470 assert (x1 == x2 + x3) as H1.
471 { apply (CR_cv_unique _ _ _ i).
472 apply (series_cv_eq
473 (fun k : nat => UC_integral (fn k) x0 ((x0 + y0) * CR_of_Q R (1#2)) (fnMod k) (fnCont k) H
474 + (UC_integral (fn k) ((x0 + y0) * CR_of_Q R (1#2)) y0 (fnMod k) (fnCont k) H0))).
475 intros. symmetry. apply UC_integral_chasles.
476 apply series_cv_plus. exact s. exact s0. }
477 simpl. rewrite H1 in r.
478 rewrite (UC_integral_chasles
479 x0 ((x0+y0) * CR_of_Q R (1#2)) y0 _ _ _ H H0) in r.
480 apply Rplus_lt_epsilon in r.
481 assert ((y0 - x0) * CR_of_Q R (1 # 2) <= (x0 + y0) * CR_of_Q R (1 # 2) - x0).
482 { apply (CRmult_le_reg_r (CR_of_Q R 2)). apply CR_of_Q_pos. reflexivity.
483 unfold CRminus. rewrite CRmult_plus_distr_r, CRmult_plus_distr_r.
484 rewrite CRmult_assoc, <- CR_of_Q_mult.
485 rewrite CRmult_assoc, <- CR_of_Q_mult.
486 rewrite CRmult_plus_distr_r, CRmult_assoc, <- CR_of_Q_mult.
487 setoid_replace ((1 # 2) * 2)%Q with 1%Q. 2: reflexivity.
488 rewrite (CR_of_Q_plus R 1 1), CRmult_1_r, CRmult_1_r, CRmult_1_r.
489 rewrite (CRplus_comm x0), CRplus_assoc. apply CRplus_le_compat_l.
490 rewrite CRmult_plus_distr_l, CRmult_1_r, <- CRplus_assoc, CRplus_opp_r.
491 rewrite CRplus_0_l. apply CRle_refl. }
492 destruct r.
493 - assert (series_cv_lim_lt
494 (fun k : nat => UC_integral (fn k) x0 ((x0 + y0) * CR_of_Q R (1#2)) (fnMod k) (fnCont k) H)
495 (UC_integral g x0 ((x0 + y0) * CR_of_Q R (1#2)) gMod (fst gCSUC) H)).
496 { exists x2. split. exact s. exact c. }
497 exists (Build_CSUCposPointApprox x0 ((x0 + y0) * CR_of_Q R (1#2)) H H3).
498 simpl. repeat split. apply CRle_refl. exact H0.
499 exact H2.
500 apply (CRmult_le_reg_r (CR_of_Q R 2)). apply CR_of_Q_pos. reflexivity.
501 unfold CRminus. rewrite CRmult_plus_distr_r, CRmult_plus_distr_r.
502 rewrite CRmult_assoc, <- CR_of_Q_mult.
503 rewrite CRmult_plus_distr_r, CRmult_assoc, <- CR_of_Q_mult.
504 rewrite CRmult_plus_distr_r, CRmult_assoc, <- CR_of_Q_mult.
505 setoid_replace ((1 # 2) * 2)%Q with 1%Q. 2: reflexivity.
506 rewrite (CR_of_Q_plus R 1 1), CRmult_1_r, CRmult_1_r, CRmult_1_r.
507 rewrite (CRplus_comm x0), CRplus_assoc. apply CRplus_le_compat_l.
508 rewrite CRmult_plus_distr_l, CRmult_1_r, <- CRplus_assoc, CRplus_opp_r.
509 rewrite CRplus_0_l. apply CRle_refl.
510 - assert (series_cv_lim_lt
511 (fun k : nat => UC_integral (fn k) ((x0 + y0) * CR_of_Q R (1#2)) y0 (fnMod k) (fnCont k) H0)
512 (UC_integral g ((x0 + y0) * CR_of_Q R (1#2)) y0 gMod (fst gCSUC) H0)).
513 { exists x3. split. exact s0. exact c. }
514 exists (Build_CSUCposPointApprox ((x0 + y0) * CR_of_Q R (1#2)) y0 H0 H3).
515 simpl. repeat split. exact H. apply CRle_refl.
516 apply (CRmult_le_reg_r (CR_of_Q R 2)). apply CR_of_Q_pos. reflexivity.
517 unfold CRminus. rewrite CRmult_plus_distr_r, CRmult_plus_distr_r.
518 rewrite CRmult_assoc, <- CR_of_Q_mult.
519 rewrite CRmult_assoc, <- CR_of_Q_mult.
520 rewrite CRmult_plus_distr_r, CRopp_mult_distr_l, CRmult_assoc, <- CR_of_Q_mult.
521 setoid_replace ((1 # 2) * 2)%Q with 1%Q. 2: reflexivity.
522 rewrite (CR_of_Q_plus R 1 1), CRmult_1_r, CRmult_1_r, CRmult_1_r.
523 rewrite CRopp_plus_distr.
524 rewrite (CRplus_comm (-x0)), <- CRplus_assoc. apply CRplus_le_compat_r.
525 rewrite CRmult_plus_distr_l, CRmult_1_r, CRplus_assoc, CRplus_opp_r.
526 rewrite CRplus_0_r. apply CRle_refl.
527 apply (CRmult_le_reg_r (CR_of_Q R 2)). apply CR_of_Q_pos. reflexivity.
528 unfold CRminus. rewrite CRmult_plus_distr_r, CRmult_plus_distr_r.
529 rewrite CRmult_assoc, <- CR_of_Q_mult.
530 rewrite CRopp_plus_distr, CRmult_plus_distr_r, CRopp_mult_distr_l, CRmult_assoc, <- CR_of_Q_mult.
531 rewrite CRopp_mult_distr_l, CRmult_assoc, <- CR_of_Q_mult.
532 setoid_replace ((1 # 2) * 2)%Q with 1%Q. 2: reflexivity.
533 rewrite (CR_of_Q_plus R 1 1), CRmult_1_r, CRmult_1_r, CRmult_1_r.
534 rewrite (CRplus_comm (-x0)), <- CRplus_assoc. apply CRplus_le_compat_r.
535 rewrite CRmult_plus_distr_l, CRmult_1_r, CRplus_assoc, CRplus_opp_r.
536 rewrite CRplus_0_r. apply CRle_refl.
537 Qed.
538
539 Definition CSUCposPointApproxSequence
540 : nat -> CSUCposPointApprox
541 := nat_rec _ CSUCposPointApproxInit
542 (fun (n:nat) currStep => proj1_sig (CSUCposPointApproxStep n currStep)).
543
544 (* The segments are nested, so the centers form a Cauchy sequence. *)
545 Lemma CSUCposPointApproxSequenceNested
546 : forall n p : nat,
547 x (CSUCposPointApproxSequence n) <= x (CSUCposPointApproxSequence (n + p))
548 /\ y (CSUCposPointApproxSequence (n+p)) <= y (CSUCposPointApproxSequence n).
549 Proof.
550 intros. generalize dependent n. induction p.
551 - intros. rewrite Nat.add_0_r.
552 destruct (CSUCposPointApproxSequence n).
553 split; apply CRle_refl.
554 - intro n. rewrite Nat.add_succ_r. simpl. specialize (IHp n).
555 destruct (CSUCposPointApproxSequence n).
556 destruct (CSUCposPointApproxStep (n + p) (CSUCposPointApproxSequence (n + p))).
557 destruct (CSUCposPointApproxSequence (n+p)), x1.
558 simpl. simpl in a0. split. apply (CRle_trans _ x2).
559 apply IHp. apply a0. apply (CRle_trans _ y1). apply a0. apply IHp.
560 Qed.
561
562 Lemma CSUCposPointApproxSequenceLength
563 : forall n:nat, (y (CSUCposPointApproxSequence n) - x (CSUCposPointApproxSequence n)
564 == (b-a) * CR_of_Q R (/2^Z.of_nat n)).
565 Proof.
566 induction n.
567 - simpl. rewrite CRmult_1_r. reflexivity.
568 - rewrite Nat2Z.inj_succ. unfold Z.succ. rewrite Qpower_plus.
569 simpl. destruct (CSUCposPointApproxStep n (CSUCposPointApproxSequence n)); simpl.
570 destruct a0, H0. unfold Qdiv.
571 rewrite Qinv_mult_distr, CR_of_Q_mult, <- CRmult_assoc, <- IHn. clear IHn.
572 exact H1. discriminate.
573 Qed.
574
575 Lemma CSUCposPointApproxSequenceCvZero
576 : forall n : positive,
577 { p : nat &
578 forall i : nat,
579 (p <= i)%nat ->
580 CRabs R (y (CSUCposPointApproxSequence i) - x (CSUCposPointApproxSequence i))
581 < CR_of_Q R (1 # n) }.
582 Proof.
583 intros n.
584 destruct (CRup_nat (b - a)) as [i imaj].
585 destruct i. exfalso. simpl in imaj.
586 rewrite <- (CRplus_opp_r a) in imaj.
587 apply CRplus_lt_reg_r in imaj. contradiction.
588 destruct (@GeoCvZero R (Pos.of_nat (S i)*n)%positive) as [p pmaj].
589 exists p. intros.
590 apply (CRle_lt_trans _ ((b-a)* CR_of_Q R ((/2)^Z.of_nat p))).
591 - rewrite Qinv_power.
592 pose proof (CSUCposPointApproxSequenceLength p).
593 rewrite <- H0. clear H0.
594 destruct (Nat.le_exists_sub p i0 H), H0. subst i0.
595 apply Rsmaller_interval.
596 rewrite Nat.add_comm. apply CSUCposPointApproxSequenceNested.
597 apply (CRle_trans _ (y (CSUCposPointApproxSequence (x0 + p)))).
598 destruct (CSUCposPointApproxSequence (x0 + p)); simpl. exact lexy0.
599 rewrite Nat.add_comm. apply CSUCposPointApproxSequenceNested.
600 apply (CRle_trans _ (x (CSUCposPointApproxSequence (x0+p)))).
601 rewrite Nat.add_comm. apply CSUCposPointApproxSequenceNested.
602 destruct (CSUCposPointApproxSequence (x0 + p)); simpl. exact lexy0.
603 rewrite Nat.add_comm. apply CSUCposPointApproxSequenceNested.
604 - specialize (pmaj p (Nat.le_refl p)).
605 unfold CRminus in pmaj. rewrite CRopp_0, CRplus_0_r in pmaj.
606 apply (CRlt_le_trans _ (CR_of_Q R ((Z.of_nat (S i) # 1) * (/ 2) ^ Z.of_nat p ))).
607 rewrite CR_of_Q_mult.
608 apply CRmult_lt_compat_r. 2: exact imaj.
609 apply CR_of_Q_pos. apply Qpower_positive. reflexivity.
610 rewrite CRabs_right in pmaj.
611 2: apply CRlt_asym, CRpow_gt_zero; exact Rlt_0_half.
612 apply CR_of_Q_le.
613 setoid_replace (CRpow (CR_of_Q R (1 # 2)) p)
614 with (CR_of_Q R ((/ 2) ^ Z.of_nat p )) in pmaj.
615 destruct (Q_dec ((/ 2) ^ Z.of_nat p) (1 # Pos.of_nat (S i) * n)). destruct s.
616 apply (Qmult_lt_l _ _ (Z.of_nat (S i) # 1)) in q.
617 apply (Qle_trans _ ((Z.of_nat (S i) # 1) * (1 # Pos.of_nat (S i) * n))%Q).
618 apply Qlt_le_weak, q. 2: reflexivity.
619 unfold Qmult, Qle, Qnum, Qden. rewrite Z.mul_1_r, Z.mul_1_l, Pos.mul_1_l.
620 rewrite Pos2Z.inj_mul. unfold Z.of_nat.
621 rewrite Pos.of_nat_succ. apply Z.le_refl.
622 exfalso. apply (CR_of_Q_lt R) in q. apply pmaj, q.
623 rewrite q.
624 unfold Qmult, Qle, Qnum, Qden. rewrite Z.mul_1_r, Z.mul_1_l, Pos.mul_1_l.
625 rewrite Pos2Z.inj_mul. unfold Z.of_nat.
626 rewrite Pos.of_nat_succ. apply Z.le_refl.
627 rewrite pow_inject_Q. reflexivity. discriminate.
628 Qed.
629
630 Lemma CSUCposPointApproxSequenceCauchy
631 : { l : CRcarrier R
632 & CR_cv R (fun n => x (CSUCposPointApproxSequence n)) l }.
633 Proof.
634 apply (CR_complete R (fun n => x (CSUCposPointApproxSequence n))).
635 intros n.
636 destruct (CSUCposPointApproxSequenceCvZero n) as [p pmaj].
637 exists p. intros.
638 apply (CRle_trans _ (y (CSUCposPointApproxSequence p)
639 - x (CSUCposPointApproxSequence p))).
640 - destruct (Nat.le_exists_sub p j H0), H1. subst j.
641 destruct (Nat.le_exists_sub p i H), H1. subst i.
642 apply Rsmaller_interval.
643 rewrite Nat.add_comm. apply CSUCposPointApproxSequenceNested.
644 apply (CRle_trans _ (y (CSUCposPointApproxSequence (x0 + p)))).
645 destruct (CSUCposPointApproxSequence (x0 + p)); simpl. exact lexy0.
646 rewrite Nat.add_comm. apply CSUCposPointApproxSequenceNested.
647 rewrite Nat.add_comm. apply CSUCposPointApproxSequenceNested.
648 apply (CRle_trans _ (y (CSUCposPointApproxSequence (x1 + p)))).
649 destruct (CSUCposPointApproxSequence (x1 + p)); simpl. exact lexy0.
650 rewrite Nat.add_comm. apply CSUCposPointApproxSequenceNested.
651 - specialize (pmaj p (Nat.le_refl p)). unfold CRminus in pmaj.
652 unfold CRminus. apply CRlt_asym.
653 exact (CRle_lt_trans _ _ _ (CRle_abs _) pmaj).
654 Qed.
655
656 Lemma CSUCposPointApproxLimitNested
657 : forall n : nat,
658 let (l,_) := CSUCposPointApproxSequenceCauchy in
659 x (CSUCposPointApproxSequence n) <= l
660 /\ l <= y (CSUCposPointApproxSequence n).
661 Proof.
662 intro n. pose proof (CSUCposPointApproxSequenceNested n).
663 destruct CSUCposPointApproxSequenceCauchy
664 as [l lcv], (CSUCposPointApproxSequence n); simpl.
665 split.
666 - apply (CR_cv_bound_down
667 (fun n : nat => x (CSUCposPointApproxSequence n)) _ _ n).
668 intros. destruct (Nat.le_exists_sub n n0 H0). destruct H1. subst n0.
669 rewrite Nat.add_comm. specialize (H x1).
670 destruct (CSUCposPointApproxSequence (n + x1)); simpl; simpl in H.
671 apply H. apply lcv.
672 - apply (CR_cv_bound_up
673 (fun n : nat => x (CSUCposPointApproxSequence n)) _ _ n).
674 intros. destruct (Nat.le_exists_sub n n0 H0). destruct H1. subst n0.
675 rewrite Nat.add_comm. specialize (H x1).
676 destruct (CSUCposPointApproxSequence (n + x1)); simpl; simpl in H.
677 apply (CRle_trans _ y1). exact lexy1. apply H. apply lcv.
678 Qed.
679
680 Lemma CSUCIcontinuous :
681 let (l,_) := CSUCposPointApproxSequenceCauchy in
682 forall k:nat, CRsum (fun n => fn n l) k <= g l.
683 Proof.
684 pose proof CSUCposPointApproxLimitNested.
685 destruct CSUCposPointApproxSequenceCauchy as [l lcv].
686 intro k. intro abs.
687 destruct (UC_sum (fun n x => fn n x) fnMod fnCont k) as [modS contS].
688 destruct (EnlargePointMajoration g _ l gMod modS (fst gCSUC) contS abs)
689 as [eta [etaPos etaMaj]].
690 (* Put the approximation's integral domain inside eta *)
691 destruct (CRup_nat (CRinv R eta (inr etaPos))) as [p pmaj].
692 assert (0 < @INR R p) as qpPos.
693 { apply (CRlt_trans _ (CRinv R eta (inr etaPos))).
694 apply CRinv_0_lt_compat. exact etaPos. exact pmaj. }
695 assert (0 < p)%nat.
696 { unfold INR in qpPos. destruct p. 2: apply le_n_S, Nat.le_0_l.
697 exfalso. contradict qpPos. apply (CRle_trans _ (CR_of_Q R 0)).
698 apply CR_of_Q_le. discriminate. apply CRle_refl. }
699 destruct (CSUCposPointApproxSequenceCvZero (Pos.of_nat p)) as [i imaj].
700 specialize (imaj i (Nat.le_refl i)). specialize (H i).
701 destruct (CSUCposPointApproxSequence i); unfold x,y in imaj.
702 destruct lambdaInfiniteMaj0. simpl in H.
703 assert (CRsum (fun j : nat => UC_integral (fn j) x0 y0
704 (fnMod j) (fnCont j) lexy0) k
705 < UC_integral g x0 y0 gMod (fst gCSUC) lexy0).
706 { apply (CRle_lt_trans _ x1). 2: apply p0.
707 apply growing_ineq. 2: apply p0.
708 intros n.
709 rewrite <- (CRplus_0_r (CRsum (fun j : nat => UC_integral (fn j) x0 y0
710 (fnMod j) (fnCont j)
711 lexy0) n)).
712 apply CRplus_le_compat_l. apply UC_integral_pos.
713 intros. apply fnPos. }
714 assert (forall x y : CRcarrier R, x < y -> ~(y<=x)) as CReal_lt_not_le.
715 { intros. intro abs1. contradiction. }
716 apply (CReal_lt_not_le _ _ H1).
717 destruct (UC_sum fn fnMod fnCont k) as [modSk c].
718 rewrite <- (UC_integral_sum fn _ _ k _ _ fnCont c).
719 apply UC_integral_nonneg.
720 intros. apply CRlt_asym, etaMaj.
721 rewrite CRabs_right in imaj.
722 apply (CRle_lt_trans _ (y0- x0)).
723 apply Rsmaller_interval.
724 apply H2. apply H2. apply H. apply H.
725 apply (CRlt_trans _ (CR_of_Q R (1#Pos.of_nat p))).
726 unfold CRminus. exact imaj.
727 2: rewrite <- (CRplus_opp_r x0); apply CRplus_le_compat_r, lexy0.
728 apply (CRmult_lt_compat_l eta) in pmaj.
729 rewrite CRinv_r in pmaj. 2: exact etaPos.
730 apply (CRmult_lt_reg_r (INR p)).
731 exact qpPos.
732 apply (CRle_lt_trans _ 1). 2: exact pmaj.
733 unfold INR. rewrite <- CR_of_Q_mult. apply CR_of_Q_le.
734 unfold Qmult, Qle, Qden, Qnum. rewrite Z.mul_1_l, Z.mul_1_l, Pos.mul_1_r.
735 rewrite Z.mul_1_r. rewrite <- positive_nat_Z.
736 rewrite Nat2Pos.id. apply Z.le_refl. intro abs1.
737 subst p. inversion H0.
738 Qed.
739
740 (* Workaround a destruct problem *)
741 Lemma DestructCSUCposPoint :
742 { l : CRcarrier R
743 | (forall k:nat, CRsum (fun n => fn n l) k <= g l)
744 /\ x (CSUCposPointApproxSequence 0) <= l
745 /\ l <= y (CSUCposPointApproxSequence 0) }.
746 Proof.
747 pose proof CSUCIcontinuous.
748 pose proof CSUCposPointApproxLimitNested.
749 destruct CSUCposPointApproxSequenceCauchy as [l lcv].
750 exists l. split. exact H. apply H0.
751 Qed.
752
753 End CSUCContinuous.
754
755
756 Lemma CSUC_extend_pos
757 : forall {R : ConstructiveReals} (f : PartialFunction (CRcarrier R))
758 (fL : Is_CSUC_func f) (a b : CRcarrier R) (leab : a <= b),
759 nonNegFunc f
760 -> UC_integral (TotalizeFunc (CRcarrier R) f (CSUC_fullDomain f fL))
761 a b (CSUC_cont_mod f fL)
762 (fst (CSUC_adapt f fL)) leab
763 <= IntegralCSUC f fL.
764 Proof.
765 intros. unfold IntegralCSUC, TotalizeFunc.
766 pose proof (CSUC_connect_support
767 (TotalizeFunc (CRcarrier R) f (CSUC_fullDomain f fL)) (CSUC_low f fL)
768 (CSUC_high f fL) (CSUC_cont_mod f fL)).
769 destruct fL, f; simpl; simpl in H0.
770 assert (CRmin a CSUC_low0 <= CRmax b CSUC_high0).
771 { apply (CRle_trans _ a). apply CRmin_l.
772 apply (CRle_trans _ b _ leab). apply CRmax_l. }
773 apply (CRle_trans
774 _ (UC_integral (fun x1 : CRcarrier R => partialApply x1 (CSUC_fullDomain0 x1))
775 (CRmin a CSUC_low0) (CRmax b CSUC_high0)
776 CSUC_cont_mod0 (fst CSUC_adapt0) H1)).
777 apply (UC_integral_extend_nonneg _ CSUC_cont_mod0).
778 apply CRmin_l. apply CRmax_l. intros. apply H.
779 assert (forall x y:CRcarrier R, x == y -> x <= y).
780 { intros. rewrite H2. apply CRle_refl. }
781 apply H2. symmetry. apply (UC_integral_extend_zero _ CSUC_cont_mod0).
782 apply CRmin_r. apply CRmax_r.
783 intros. apply H0. apply CSUC_adapt0. left. apply H3.
784 intros. apply H0. apply CSUC_adapt0. right. apply H3.
785 Qed.
786
787 Lemma CSUCIntegralContinuous {R : ConstructiveReals}
788 : @ElemIntegralContinuous (@ElemCSUC R) IntegralCSUC.
789 Proof.
790 intros. apply IcontinuousClassic.
791 - apply CSUCIntegralHomogeneous.
792 - apply CSUCIntegralAdditiveIterate.
793 - intros g gL.
794 assert (nonNegFunc (PartializeFunc (CRcarrier R) (CSUCUnitTrapeze (CSUC_low g gL) (CSUC_high g gL) 1 (CRzero_lt_one R))))
795 as ZnonNeg.
796 { intros x xdf. simpl.
797 apply (CSUCTrapezeBounded
798 (CSUC_low g gL) (CSUC_high g gL)
799 1 x (CRzero_lt_one R)).
800 apply (CSUC_lowHigh g gL). }
801 exists (existT _ (PartializeFunc (CRcarrier R) (CSUCUnitTrapeze (CSUC_low g gL) (CSUC_high g gL) 1 (CRzero_lt_one R)))
802 (pair (CSUCTrapeze_IS_CSUC (CSUC_low g gL)
803 (CSUC_high g gL)
804 1 (CRzero_lt_one R)
805 (CSUC_lowHigh g gL))
806 ZnonNeg)).
807 intros.
808 assert (forall (k : nat) (x : CRcarrier R),
809 (0 <= (fun n : nat => TotalizeFunc (CRcarrier R) (fn n) (CSUC_fullDomain (fn n) (fnL n))) k x))
810 as fnPos.
811 { intros. unfold TotalizeFunc. specialize (H k). clear H0.
812 unfold nonNegFunc in H.
813 destruct (fnL k), (fn k); simpl; simpl in H. apply H. }
814 destruct H0 as [sIfn [icv imaj]].
815 assert (forall n : nat,
816 (CRabs _
817 ((fun k : nat =>
818 UC_integral ((fun n0 : nat => TotalizeFunc (CRcarrier R) (fn n0) (CSUC_fullDomain (fn n0) (fnL n0))) k)
819 (CSUC_low g gL) (CSUC_high g gL)
820 ((fun n0 : nat => CSUC_cont_mod (fn n0) (fnL n0)) k)
821 ((fun n0 : nat => fst (CSUC_adapt (fn n0) (fnL n0))) k)
822 (CSUC_lowHigh g gL) ) n) <=
823 (fun n0 : nat =>
824 UC_integral (TotalizeFunc (CRcarrier R) (fn n0) (CSUC_fullDomain (fn n0) (fnL n0)))
825 (CSUC_low (fn n0) (fnL n0)) (CSUC_high (fn n0) (fnL n0))
826 (CSUC_cont_mod (fn n0) (fnL n0)) (fst (CSUC_adapt (fn n0) (fnL n0)))
827 (CSUC_lowHigh (fn n0) (fnL n0))) n)).
828 { intro n. rewrite CRabs_right.
829 apply CSUC_extend_pos. apply H.
830 apply UC_integral_pos.
831 intros. specialize (H n). destruct (fnL n), (fn n); simpl. apply H. }
832 destruct (series_cv_maj _ _ sIfn H0 icv) as [sIfnTrunc [scv smaj]].
833 assert (sIfnTrunc < UC_integral (TotalizeFunc (CRcarrier R) g (CSUC_fullDomain g gL))
834 (CSUC_low g gL) (CSUC_high g gL)
835 (CSUC_cont_mod g gL) (fst (CSUC_adapt g gL))
836 (CSUC_lowHigh g gL) ) as majInt.
837 { apply (CRle_lt_trans _ sIfn). apply smaj. exact imaj. }
838 destruct (DestructCSUCposPoint
839 R (TotalizeFunc (CRcarrier R) g (CSUC_fullDomain _ gL))
840 (fun n => TotalizeFunc (CRcarrier R) (fn n) (CSUC_fullDomain _ (fnL n)))
841 fnPos (fun n => CSUC_cont_mod _ (fnL n))
842 (fun n => fst (CSUC_adapt _ (fnL n)))
843 (CSUC_cont_mod _ gL)
844 (CSUC_low _ gL) (CSUC_high _ gL) (CSUC_lowHigh _ gL)
845 (CSUC_adapt _ gL) (existT _ sIfnTrunc (pair scv majInt)))
846 as [l lcv].
847 exists (Build_CommonPointFunSeq
848 _ _ g fn l (CSUC_fullDomain g gL l)
849 (fun n => CSUC_fullDomain (fn n) (fnL n) l)).
850 unfold cpx, cpxF, cpxFn. simpl in lcv.
851 split. exists Logic.I. unfold PartializeFunc, partialApply.
852 apply CSUCTrapezePlateau. apply lcv. apply lcv.
853 Qed.
854
855 Lemma CSUC_transport_apply
856 : forall {R : ConstructiveReals} (f g : PartialFunction (CRcarrier R))
857 (fL : Is_CSUC_func f)
858 (pEq : PartialFunExtEq f g)
859 (x : CRcarrier R),
860 TotalizeFunc (CRcarrier R) f (CSUC_fullDomain _ fL) x
861 == TotalizeFunc (CRcarrier R) g (CSUC_fullDomain _ (CSUCext f g pEq fL)) x.
862 Proof.
863 intros. destruct pEq, p. apply c.
864 Qed.
865
866 Lemma CSUC_transport_low
867 : forall {R : ConstructiveReals} (f g : PartialFunction (CRcarrier R))
868 (fL : Is_CSUC_func f)
869 (pEq : PartialFunExtEq f g),
870 CSUC_low _ fL
871 = CSUC_low _ (Lext ElemCSUC f g pEq fL).
872 Proof.
873 intros. destruct pEq, p, f, g, fL; reflexivity.
874 Qed.
875
876 Lemma CSUC_transport_high
877 : forall {R : ConstructiveReals} (f g : PartialFunction (CRcarrier R))
878 (fL : Is_CSUC_func f)
879 (pEq : PartialFunExtEq f g),
880 CSUC_high _ fL
881 = CSUC_high _ (Lext ElemCSUC f g pEq fL).
882 Proof.
883 intros. destruct pEq, p, f, g, fL; reflexivity.
884 Qed.
885
886 Lemma IntegralCSUC_ext
887 : forall {R : ConstructiveReals}
888 (g h : PartialFunction (CRcarrier R)) (gCS : Is_CSUC_func g)
889 (hCS : Is_CSUC_func h),
890 (forall x:CRcarrier R, TotalizeFunc (CRcarrier R) g (CSUC_fullDomain g gCS) x
891 == TotalizeFunc (CRcarrier R) h (CSUC_fullDomain h hCS) x)
892 -> IntegralCSUC g gCS == IntegralCSUC h hCS.
893 Proof.
894 intros.
895 pose proof (CSUC_connect_support
896 (TotalizeFunc (CRcarrier R) g (CSUC_fullDomain g gCS)) (CSUC_low g gCS)
897 (CSUC_high g gCS) (CSUC_cont_mod g gCS)).
898 pose proof (CSUC_connect_support
899 (TotalizeFunc (CRcarrier R) h (CSUC_fullDomain h hCS)) (CSUC_low h hCS)
900 (CSUC_high h hCS) (CSUC_cont_mod h hCS)).
901 unfold IntegralCSUC; destruct gCS, hCS, g, h; simpl; simpl in H, H0, H1.
902 unfold TotalizeFunc.
903 assert (CRmin CSUC_low0 CSUC_low1 <= CRmax CSUC_high0 CSUC_high1).
904 { apply (CRle_trans _ CSUC_low0). apply CRmin_l.
905 apply (CRle_trans _ CSUC_high0). apply CSUC_lowHigh0.
906 apply CRmax_l. }
907 (* Extend bounds *)
908 transitivity (UC_integral
909 (fun x2 : CRcarrier R => partialApply x2 (CSUC_fullDomain0 x2))
910 (CRmin CSUC_low0 CSUC_low1)
911 (CRmax CSUC_high0 CSUC_high1) CSUC_cont_mod0 (fst CSUC_adapt0) H2).
912 - apply (UC_integral_extend_zero _ CSUC_cont_mod0). apply CRmin_l.
913 apply CRmax_l. intros. apply H0. apply CSUC_adapt0.
914 left. apply H3. intros. apply H0. apply CSUC_adapt0.
915 right. apply H3.
916 - transitivity (UC_integral
917 (fun x2 : CRcarrier R => partialApply0 x2 (CSUC_fullDomain1 x2))
918 (CRmin CSUC_low0 CSUC_low1)
919 (CRmax CSUC_high0 CSUC_high1)
920 CSUC_cont_mod1 (fst CSUC_adapt1) H2).
921 apply UC_integral_extens. intros. apply H.
922 symmetry.
923 apply (UC_integral_extend_zero _ CSUC_cont_mod1).
924 apply CRmin_r. apply CRmax_r.
925 intros. apply H1. apply CSUC_adapt1.
926 left. apply H3. intros. apply H1. apply CSUC_adapt1.
927 right. apply H3.
928 Qed.
929
930 Lemma IntegralCSUC_bounded
931 : forall {R : ConstructiveReals} (g : PartialFunction (CRcarrier R))
932 (gCS : Is_CSUC_func g)
933 (A : CRcarrier R),
934 (forall x:CRcarrier R, TotalizeFunc (CRcarrier R) g (CSUC_fullDomain g gCS) x <= A)
935 -> IntegralCSUC g gCS <= (A* (CSUC_high g gCS - CSUC_low g gCS)).
936 Proof.
937 intros. rewrite CRmult_comm. unfold Qminus.
938 rewrite <- (UC_integral_constant
939 _ _ _ A
940 _ (UC_constant A) (CSUC_lowHigh g gCS)).
941 unfold IntegralCSUC.
942 apply (UC_integral_nonneg
943 (TotalizeFunc (CRcarrier R) g (CSUC_fullDomain g gCS))
944 (fun _ => A)).
945 intros. apply H.
946 intros. reflexivity.
947 Qed.
948
949 Lemma CSUCIntegralLimit
950 : forall {R : ConstructiveReals} (f : PartialFunction (CRcarrier R))
951 (fL : Is_CSUC_func f),
952 prod (CR_cv _ (fun n => IntegralCSUC (XminConst f (INR n))
953 (@LminIntStable ElemCSUC n f fL))
954 (IntegralCSUC f fL))
955 (CR_cv _ (fun n => IntegralCSUC (XminConst (Xabs f) (CR_of_Q R (1# Pos.of_nat (S n))))
956 (@LminConstStable ElemCSUC (CR_of_Q R (1# Pos.of_nat (S n))) (Xabs f)
957 (invSuccRealPositive n)
958 (LabsStable ElemCSUC f fL)))
959 0).
960 Proof.
961 split.
962 - destruct (CSUC_bounded (TotalizeFunc (CRcarrier R) f (CSUC_fullDomain _ fL))
963 (CSUC_low _ fL) (CSUC_high _ fL)
964 (CSUC_cont_mod _ fL) (CSUC_adapt _ fL)
965 (CSUC_lowHigh _ fL))
966 as [B Bmaj].
967 destruct (CRup_nat B) as [k kmaj].
968 apply (CR_cv_shift _ k).
969 apply (CR_cv_eq _ (fun n : nat => IntegralCSUC f fL)).
970 intro n.
971 apply IntegralCSUC_ext. intro x0.
972 assert (PartialFunExtEq
973 f (XminConst f (INR (n + k)))) as feq.
974 { split. split.
975 intros x H. destruct f; simpl. exact H.
976 intros x H. destruct f; simpl. exact H.
977 intros. unfold XminConst, Xop, partialApply.
978 rewrite CRmin_left. rewrite (DomainProp f x1 xD xG).
979 reflexivity.
980 apply (CRle_trans _ B).
981 specialize (Bmaj x1). unfold TotalizeFunc in Bmaj.
982 rewrite (DomainProp _ _ _ (CSUC_fullDomain f fL x1)).
983 apply (CRle_trans _ _ _ (CRle_abs _)).
984 apply CRlt_asym, Bmaj.
985 apply (CRle_trans _ (INR k)). apply CRlt_asym, kmaj.
986 apply CR_of_Q_le. unfold Qle, Qden, Qnum.
987 do 2 rewrite Z.mul_1_r.
988 rewrite <- (Z.add_0_r (Z.of_nat k)).
989 rewrite Nat2Z.inj_add. rewrite (Z.add_comm (Z.of_nat n)).
990 apply Z.add_le_mono_l. apply Nat2Z.is_nonneg. }
991 rewrite (CSUC_transport_apply
992 f (XminConst f (INR (n + k))) fL feq).
993 unfold TotalizeFunc. apply DomainProp.
994 exists O. intros. unfold CRminus. rewrite CRplus_opp_r.
995 rewrite CRabs_right. apply CR_of_Q_le; discriminate.
996 apply CRle_refl.
997 - intros p.
998 destruct (CRup_nat ((CSUC_high f fL - CSUC_low f fL )
999 * (CR_of_Q R (Z.pos p # 1)))) as [k kmaj].
1000 exists k. intros n H. unfold CRminus. rewrite CRopp_0. rewrite CRplus_0_r.
1001 rewrite CRabs_right.
1002 apply (CRle_trans
1003 _ (CR_of_Q R (1# Pos.of_nat (S n))
1004 * (CSUC_high _ (@LminConstStable ElemCSUC (CR_of_Q R (1# Pos.of_nat (S n)))
1005 (Xabs f) (invSuccRealPositive n)
1006 (LabsStable ElemCSUC f fL))
1007 - CSUC_low _ (@LminConstStable ElemCSUC (CR_of_Q R (1# Pos.of_nat (S n))) (Xabs f) (invSuccRealPositive n)
1008 (LabsStable ElemCSUC f fL))))).
1009 + apply IntegralCSUC_bounded.
1010 intro x0. apply CRmin_r.
1011 + apply CRlt_asym in kmaj.
1012 apply (CRmult_le_compat_r (CR_of_Q R (1 # p))) in kmaj.
1013 rewrite CRmult_assoc, <- CR_of_Q_mult in kmaj.
1014 setoid_replace ((Z.pos p # 1) * (1 # p))%Q with 1%Q in kmaj.
1015 rewrite CRmult_1_r in kmaj.
1016 apply (CRmult_le_reg_l (CR_of_Q R (Z.of_nat (S n) #1))).
1017 apply CR_of_Q_pos; reflexivity.
1018 rewrite <- CRmult_assoc, <- CR_of_Q_mult.
1019 setoid_replace ((Z.of_nat (S n) # 1) * (1 # Pos.of_nat (S n)))%Q with 1%Q.
1020 rewrite CRmult_1_l.
1021 apply (CRle_trans _ (INR k * CR_of_Q R (1#p))).
1022 apply (CRle_trans _ (CSUC_high f fL - CSUC_low f fL)).
1023 2: apply kmaj.
1024 unfold LminConstStable. rewrite <- CSUC_transport_low.
1025 rewrite <- CSUC_transport_high. destruct f, fL; apply CRle_refl.
1026 apply CRmult_le_compat_r.
1027 apply CR_of_Q_le; discriminate.
1028 apply CR_of_Q_le. unfold Qle, Qnum, Qden.
1029 do 2 rewrite Z.mul_1_r. apply Nat2Z.inj_le, le_S, H.
1030 unfold Qmult, Qeq, Qnum, Qden.
1031 rewrite Z.mul_1_r, Z.mul_1_r, Z.mul_1_l, Pos.mul_1_l.
1032 rewrite <- positive_nat_Z, Nat2Pos.id. reflexivity. discriminate.
1033 unfold Qmult, Qeq, Qnum, Qden.
1034 rewrite Z.mul_1_r, Z.mul_1_r, Z.mul_1_l, Pos.mul_1_l. reflexivity.
1035 apply CR_of_Q_le. discriminate.
1036 + unfold IntegralCSUC.
1037 apply (UC_integral_pos
1038 (TotalizeFunc (CRcarrier R)
1039 (XminConst (Xabs f) (CR_of_Q R (1 # Pos.of_nat (S n))))
1040 (CSUC_fullDomain
1041 (XminConst (Xabs f) (CR_of_Q R (1 # Pos.of_nat (S n))))
1042 (@LminConstStable ElemCSUC (CR_of_Q R (1 # Pos.of_nat (S n)))
1043 (Xabs f) (invSuccRealPositive n) (LabsStable ElemCSUC f fL))))).
1044 intros. unfold TotalizeFunc.
1045 assert (Domain (Xabs f) x0).
1046 { destruct fL,f; apply CSUC_fullDomain0. }
1047 rewrite applyXminConst. apply CRmin_glb.
1048 2: apply CR_of_Q_le; discriminate.
1049 destruct f; apply CRabs_pos.
1050 Qed.
1051
1052 Lemma OneCSUC_IS_CSUC :
1053 forall {R : ConstructiveReals},
1054 Is_CSUC_func (PartializeFunc (CRcarrier R)
1055 (CSUCUnitTrapeze 0 0 1 (CRzero_lt_one R))).
1056 Proof.
1057 intro R. assert (-(1) <= CR_of_Q R 1).
1058 { apply (CRle_trans _ (-0)).
1059 apply CRopp_ge_le_contravar, CRlt_asym, CRzero_lt_one.
1060 rewrite CRopp_0. apply CRlt_asym, CRzero_lt_one. }
1061 apply (Build_Is_CSUC_func
1062 R (PartializeFunc (CRcarrier R) (CSUCUnitTrapeze 0 0 1 (CRzero_lt_one R)))
1063 (fun x:CRcarrier R => Logic.I)
1064 (-(1)) 1 H (fun eps epsPos => eps *CR_of_Q R (1#2))).
1065 pose proof (CSUCTrapeze_CSUC 0 0 1 (CRzero_lt_one R) (CRle_refl 0)).
1066 destruct H0. destruct u. split. split.
1067 intros. specialize (c0 x0 xPos).
1068 apply (CRlt_le_trans _ _ _ c0).
1069 rewrite CRmult_1_r. apply CRle_refl.
1070 intros. apply (c1 eps x0 y0 epsPos).
1071 apply (CRlt_le_trans _ _ _ H0).
1072 rewrite CRmult_1_r. apply CRle_refl.
1073 intros. apply c. destruct H0.
1074 left. apply (CRlt_le_trans _ _ _ c2).
1075 unfold CRminus. rewrite CRplus_0_l. apply CRle_refl.
1076 right. apply (CRle_lt_trans _ 1). rewrite CRplus_0_l.
1077 apply CRle_refl. exact c2.
1078 Defined.
1079
1080 Lemma IntegralOneCSUC
1081 : forall {R : ConstructiveReals},
1082 IntegralCSUC (PartializeFunc (CRcarrier R) (CSUCUnitTrapeze 0 0 1 (CRzero_lt_one R)))
1083 OneCSUC_IS_CSUC == 1.
1084 Proof.
1085 intro R.
1086 transitivity (CR_of_Q R 1 + 0 - 0).
1087 rewrite <- (CSUCUnitTrapezeInt 0 0 1 (CRzero_lt_one R) (CRle_refl 0)).
1088 (* IntegralCSUC is between CR_of_Q (-1) and CR_of_Q 1 *)
1089 assert (-(1) <= CR_of_Q R 1).
1090 { apply (CRle_trans _ (-0)).
1091 apply CRopp_ge_le_contravar, CRlt_asym, CRzero_lt_one.
1092 rewrite CRopp_0. apply CRlt_asym, CRzero_lt_one. }
1093 rewrite (UC_integral_bound_proper
1094 (CSUCUnitTrapeze 0 0 1 (CRzero_lt_one R))
1095 (0-1) (0+1) (-(1)) 1 _ _ _ H).
1096 apply UC_integral_extens. reflexivity.
1097 unfold CRminus. rewrite CRplus_0_l, <- CR_of_Q_opp.
1098 apply CR_of_Q_morph. reflexivity.
1099 rewrite CRplus_0_l. reflexivity.
1100 unfold CRminus. rewrite CRplus_assoc, CRplus_opp_r, CRplus_0_r. reflexivity.
1101 Qed.
1102
1103 Definition IntSpaceCSUCFunctions {R : ConstructiveReals} : IntegrationSpace
1104 := Build_IntegrationSpace ElemCSUC
1105 IntegralCSUC
1106 CSUCIntegralAdditive
1107 CSUCIntegralHomogeneous
1108 (PartializeFunc (CRcarrier R) (CSUCUnitTrapeze 0 0 1 (CRzero_lt_one R)))
1109 OneCSUC_IS_CSUC
1110 IntegralOneCSUC
1111 CSUCIntegralContinuous
1112 CSUCIntegralLimit.
1113
1114 (* An integrable function for the Lebesgue measure is proper almost everywhere. *)
1115 Lemma CSUCIntegrableProper
1116 : forall {R : ConstructiveReals} (fn : nat -> PartialFunction (CRcarrier R))
1117 (x y : CRcarrier R)
1118 (xD : Domain (XinfiniteSumAbs fn) x)
1119 (yD : Domain (XinfiniteSumAbs fn) y),
1120 (forall n : nat, Is_CSUC_func (fn n))
1121 -> x == y
1122 -> partialApply _ x xD == partialApply _ y yD.
1123 Proof.
1124 intros. simpl.
1125 destruct xD, yD. simpl in c, c0.
1126 apply series_cv_abs_eq.
1127 apply (series_cv_eq (fun n : nat => partialApply (fn n) x0 (x1 n))).
1128 2: apply series_cv_abs_cv.
1129 intro n. specialize (H n). destruct H, CSUC_adapt0.
1130 pose proof (UniformContProper _ _ u x0 y0 H0).
1131 unfold TotalizeFunc in H. transitivity (partialApply (fn n) x0 (CSUC_fullDomain0 x0)).
1132 apply DomainProp. rewrite H. apply DomainProp.
1133 Qed.
1134
1135 Lemma OpenIntervalIntegrable
1136 : forall {R : ConstructiveReals} (a b : CRcarrier R),
1137 a < b
1138 -> { limInt : @IntegrableSet IntSpaceCSUCFunctions
1139 (fun x => CRltProp R a x
1140 /\ CRltProp R x b)
1141 | MeasureSet limInt == b-a }.
1142 Proof.
1143 intros.
1144 assert (forall n:nat, 0 < (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2))) as etaPos.
1145 { intro n. apply CRmult_lt_0_compat.
1146 rewrite <- (CRplus_opp_r a). apply CRplus_lt_compat_r, H.
1147 apply CR_of_Q_pos. reflexivity. }
1148 pose (fun n:nat => PartializeFunc
1149 (CRcarrier R)
1150 (CSUCUnitTrapeze (a + (b-a) * CR_of_Q R (1#Pos.of_nat (n+2)))
1151 (b - (b-a) * CR_of_Q R (1#Pos.of_nat (n+2)))
1152 ((b-a) * CR_of_Q R (1#Pos.of_nat (n+2)))
1153 (etaPos n)))
1154 as fn.
1155 assert (forall c d : CRcarrier R,
1156 CR_cv R (fun n => c + d * CR_of_Q R (1 # Pos.of_nat (n + 2))) c)
1157 as affineCv.
1158 { intros. apply (CR_cv_proper _ (c+0) c).
1159 apply CR_cv_plus. apply CR_cv_const. apply (CR_cv_proper _ (0*d)).
1160 apply (CR_cv_eq _ (fun n : nat => CR_of_Q R (1 # Pos.of_nat (n + 2)) * d)).
1161 intro n. apply CRmult_comm. apply CR_cv_scale.
1162 intro p. exists (Pos.to_nat p). intros. unfold CRminus.
1163 rewrite CRopp_0, CRplus_0_r. rewrite CRabs_right.
1164 apply CR_of_Q_le. unfold Qle, Qnum, Qden. do 2 rewrite Z.mul_1_l.
1165 apply Pos2Z.pos_le_pos. apply Pos2Nat.inj_le.
1166 rewrite Nat2Pos.id. apply (Nat.le_trans _ _ _ H0). rewrite Nat.add_comm.
1167 apply le_S, le_S, Nat.le_refl. intro abs. rewrite Nat.add_comm in abs. discriminate.
1168 apply CR_of_Q_le. discriminate.
1169 rewrite CRmult_0_l. reflexivity. rewrite CRplus_0_r. reflexivity. }
1170 assert (CR_cv R (fun n => a + (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2))) a)
1171 as cv_left.
1172 { apply affineCv. }
1173 assert (CR_cv R (fun n => b - (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2))) b)
1174 as cv_right.
1175 { apply (CR_cv_eq _ (fun n => b + (-(b - a)) * CR_of_Q R (1 # Pos.of_nat (n + 2)))).
1176 intro n. apply CRplus_morph. reflexivity.
1177 rewrite CRopp_mult_distr_l. reflexivity.
1178 apply affineCv. }
1179 assert (forall x (xdn : forall n, Domain (fn n) x),
1180 (CRltProp R a x /\ CRltProp R x b)
1181 -> CR_cv R (fun n => partialApply (fn n) x (xdn n)) 1) as inPlateau.
1182 (* Serves twice. First, for the domain inclusion when the limit is below 1,
1183 we assume by contradiction that the point is in the interval, and then 1
1184 is below 1. Second, to prove the partial restriction inside the interval. *)
1185 { intros. destruct H0.
1186 apply CRltEpsilon in H0. apply CRltEpsilon in H1.
1187 destruct (CR_cv_open_above _ x0 a cv_left H0).
1188 destruct (CR_cv_open_below _ x0 b cv_right H1).
1189 exists (max x1 x2). intros.
1190 specialize (c i). specialize (c0 i).
1191 simpl. rewrite CSUCTrapezePlateau. unfold CRminus.
1192 rewrite CRplus_opp_r, CRabs_right.
1193 apply CR_of_Q_le. discriminate. apply CRle_refl.
1194 split; apply CRlt_asym. apply c. apply (Nat.le_trans _ (max x1 x2)).
1195 apply Nat.le_max_l. exact H2. apply c0.
1196 apply (Nat.le_trans _ (max x1 x2)). apply Nat.le_max_r. exact H2. }
1197
1198 assert (forall n:nat, a + (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2))
1199 <= b - (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2))) as fnL.
1200 { intro n.
1201 apply (CRplus_le_reg_r ((b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)))).
1202 unfold CRminus. rewrite (CRplus_assoc b), CRplus_opp_l, CRplus_0_r.
1203 apply (CRplus_le_reg_l (-a)). rewrite <- CRplus_assoc, <- CRplus_assoc.
1204 rewrite CRplus_opp_l, CRplus_0_l.
1205 rewrite <- CRmult_plus_distr_l, <- CR_of_Q_plus.
1206 rewrite Qinv_plus_distr, CRplus_comm.
1207 rewrite <- (CRmult_1_r (-a + b)).
1208 rewrite CRmult_assoc. apply CRmult_le_compat_l.
1209 rewrite <- (CRplus_opp_l a). apply CRplus_le_compat_l, CRlt_asym, H.
1210 rewrite CRmult_1_l. apply CR_of_Q_le.
1211 unfold Qle,Qnum,Qden. rewrite Z.mul_1_r, Z.mul_1_l.
1212 apply Pos2Z.pos_le_pos. apply Pos2Nat.inj_le.
1213 rewrite Nat2Pos.id. rewrite Nat.add_comm. apply le_n_S, le_n_S, Nat.le_0_l.
1214 intro abs. rewrite Nat.add_comm in abs. discriminate. }
1215
1216 assert (PartialRestriction (XpointwiseLimit fn)
1217 (CharacFunc (fun x0 : CRcarrier R =>
1218 CRltProp R a x0
1219 /\ CRltProp R x0 b))).
1220 { split.
1221 - intros x xdf. simpl. destruct xdf as [xdn c].
1222 apply CR_complete in c. destruct c as [l lcv].
1223 destruct (CRltLinear R). destruct (s 0 l 1 (CRzero_lt_one R)).
1224 + left.
1225 apply (CR_cv_open_below _ 0) in lcv. 2: exact c.
1226 destruct lcv as [n nmaj].
1227 specialize (nmaj n (Nat.le_refl n)).
1228 apply (CSUCTrapezeInPlateau
1229 (a + (b-a) * CR_of_Q R (1#Pos.of_nat (n+2)))
1230 (b - (b-a) * CR_of_Q R (1#Pos.of_nat (n+2)))
1231 ((b-a) * CR_of_Q R (1#Pos.of_nat (n+2))) x
1232 (etaPos n)) in nmaj.
1233 destruct nmaj. split.
1234 apply CRltForget.
1235 apply (CRle_lt_trans _ (a + (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)) -
1236 (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)))).
1237 unfold CRminus. rewrite CRplus_assoc, CRplus_opp_r, CRplus_0_r.
1238 apply CRle_refl. exact c0.
1239 unfold CRminus in c1. apply CRltForget.
1240 apply (CRlt_le_trans _ _ _ c1).
1241 rewrite CRplus_assoc, CRplus_opp_l, CRplus_0_r. apply CRle_refl.
1242 + right. intro abs. specialize (inPlateau x xdn abs).
1243 contradict c. fold (CRle _ 1 l).
1244 rewrite (CR_cv_unique _ _ _ inPlateau lcv). apply CRle_refl.
1245 - intros. simpl in xG. destruct xG.
1246 + (* one *)
1247 apply applyPointwiseLimit.
1248 exact (inPlateau _ (fun n => let (xdn,_) := xD in xdn n) a0).
1249 + (* zero *)
1250 apply applyPointwiseLimit.
1251 apply (CR_cv_eq _ (fun _ => 0)). 2: apply CR_cv_const.
1252 intros. simpl.
1253 unfold CSUCUnitTrapeze, UCUnitHeaviside.
1254 rewrite (CRinv_morph _ ((b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)))
1255 _ (inr (etaPos n0))).
1256 rewrite (CRinv_morph (b - (b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)) +
1257 (b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)) -
1258 (b - (b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2))))
1259 ((b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)))
1260 _ (inr (etaPos n0))).
1261 destruct (CRltLinear R).
1262 destruct (s a x0 b H).
1263 assert (b <= x0).
1264 { intro abs. apply n. split. apply CRltForget, c. apply CRltForget, abs. }
1265 clear c. rewrite CRmin_left, CRmin_left.
1266 rewrite CRmax_right. unfold CRminus. rewrite CRplus_opp_r. reflexivity.
1267 apply CRlt_asym, CRzero_lt_one.
1268 apply (CRmult_le_reg_r ((b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)))).
1269 apply etaPos. rewrite CRmult_assoc, CRinv_l, CRmult_1_r, CRmult_1_l.
1270 unfold CRminus.
1271 rewrite <- CRplus_0_l.
1272 rewrite CRopp_plus_distr, CRopp_involutive.
1273 do 2 rewrite <- CRplus_assoc. apply CRplus_le_compat_r.
1274 rewrite CRplus_0_r.
1275 rewrite <- (CRplus_opp_r b). apply CRplus_le_compat_r, H0.
1276 apply (CRmult_le_reg_r ((b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)))).
1277 apply etaPos. rewrite CRmult_assoc, CRinv_l, CRmult_1_r, CRmult_1_l.
1278 unfold CRminus.
1279 rewrite CRopp_plus_distr, CRopp_involutive, <- CRplus_0_l.
1280 rewrite <- CRplus_assoc, <- CRplus_assoc. apply CRplus_le_compat_r.
1281 rewrite CRplus_0_r, CRplus_0_l.
1282 rewrite <- (CRplus_opp_r (a + (b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)))).
1283 apply CRplus_le_compat_r, (CRle_trans _ b).
1284 2: exact H0. apply (CRplus_le_reg_l (-a)).
1285 rewrite <- CRplus_assoc, CRplus_opp_l, CRplus_0_l.
1286 rewrite <- (CRmult_1_r (-a+b)), (CRplus_comm (-a)).
1287 apply CRmult_le_compat_l.
1288 rewrite <- (CRplus_opp_r a). apply CRplus_le_compat_r. apply CRlt_asym, H.
1289 apply CR_of_Q_le.
1290 unfold Qle, Qnum, Qden. rewrite Z.mul_1_r, Z.mul_1_l.
1291 apply Pos2Z.pos_le_pos. apply Pos2Nat.inj_le.
1292 rewrite Nat2Pos.id. rewrite Nat.add_comm. apply le_n_S, Nat.le_0_l.
1293 intro abs. rewrite Nat.add_comm in abs. discriminate.
1294 assert (x0 <= a).
1295 { intro abs. apply n. split. apply CRltForget, abs. apply CRltForget, c. }
1296 clear c. rewrite CRmax_left, CRmax_left.
1297 unfold CRminus. rewrite CRplus_opp_r. reflexivity.
1298 apply (CRle_trans _ _ _ (CRmin_r _ _)).
1299 apply (CRmult_le_reg_r ((b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)))).
1300 apply etaPos. rewrite CRmult_0_l, CRmult_assoc, CRinv_l, CRmult_1_r.
1301 rewrite <- (CRplus_opp_r (b - (b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)))).
1302 apply CRplus_le_compat_r. apply (CRle_trans _ _ _ H0).
1303 apply (CRplus_le_reg_l (-b)). unfold CRminus.
1304 rewrite <- CRplus_assoc, CRplus_opp_l, CRplus_0_l.
1305 setoid_replace (-b+a) with (-(b-a)). apply CRopp_ge_le_contravar.
1306 rewrite <- (CRmult_1_r (b-a)).
1307 apply CRmult_le_compat_l. rewrite <- (CRplus_opp_r a).
1308 apply CRplus_le_compat_r, CRlt_asym, H. apply CR_of_Q_le.
1309 unfold Qle, Qnum, Qden. rewrite Z.mul_1_r, Z.mul_1_l.
1310 apply Pos2Z.pos_le_pos. apply Pos2Nat.inj_le.
1311 rewrite Nat2Pos.id. rewrite Nat.add_comm. apply le_n_S, Nat.le_0_l.
1312 intro abs. rewrite Nat.add_comm in abs. discriminate.
1313 unfold CRminus. rewrite CRopp_plus_distr, CRopp_involutive. reflexivity.
1314 apply (CRle_trans _ _ _ (CRmin_r _ _)).
1315 apply (CRmult_le_reg_r ((b - a) * CR_of_Q R (1 # Pos.of_nat (n0 + 2)))).
1316 apply etaPos. rewrite CRmult_0_l, CRmult_assoc, CRinv_l, CRmult_1_r.
1317 unfold CRminus. rewrite CRplus_assoc, CRplus_opp_r, CRplus_0_r.
1318 rewrite <- (CRplus_opp_r a). apply CRplus_le_compat_r, H0.
1319 unfold CRminus. rewrite CRplus_comm, <- CRplus_assoc, CRplus_opp_l, CRplus_0_l.
1320 reflexivity.
1321 unfold CRminus. rewrite CRopp_plus_distr, CRopp_involutive.
1322 rewrite <- CRplus_assoc, CRplus_opp_r, CRplus_0_l. reflexivity.
1323 }
1324 destruct (IntegralMonotoneConvergence
1325 IntSpaceCSUCFunctions
1326 fn (fun n => @IntegrableL IntSpaceCSUCFunctions
1327 (fn n) (CSUCTrapeze_IS_CSUC
1328 (a + (b-a) * CR_of_Q R (1#Pos.of_nat (n+2)))
1329 (b - (b-a) * CR_of_Q R (1#Pos.of_nat (n+2)))
1330 ((b-a) * CR_of_Q R (1#Pos.of_nat (n+2))) (etaPos n) (fnL n)))
1331 (b-a))
1332 as [limInt mesRect].
1333 - intros n x xdf xdg.
1334 unfold fn, PartializeFunc, partialApply.
1335 apply TrapezeIncluded.
1336 unfold CRminus. rewrite CRplus_assoc, CRplus_opp_r, CRplus_0_r.
1337 rewrite CRplus_assoc, CRplus_opp_r, CRplus_0_r.
1338 reflexivity. unfold CRminus.
1339 rewrite CRplus_assoc, CRplus_opp_l, CRplus_0_r.
1340 rewrite CRplus_assoc, CRplus_opp_l, CRplus_0_r.
1341 reflexivity. apply CRmult_le_compat_l.
1342 apply CRle_minus, CRlt_asym, H.
1343 apply CR_of_Q_le.
1344 unfold Qle,Qnum,Qden. rewrite Z.mul_1_l, Z.mul_1_l.
1345 apply Pos2Z.pos_le_pos. apply Pos2Nat.inj_le.
1346 rewrite Nat2Pos.id, Nat2Pos.id. apply le_S, Nat.le_refl.
1347 discriminate.
1348 intro abs. rewrite Nat.add_comm in abs. discriminate.
1349 - simpl.
1350 apply (CR_cv_eq _ (fun n => b-a
1351 + (-(b-a)) * CR_of_Q R (1 # Pos.of_nat (n + 2)))).
1352 2: apply affineCv.
1353 intro n. rewrite IntegralLstable. simpl.
1354 symmetry. unfold fn.
1355 unfold IntegralCSUC, CSUCTrapeze_IS_CSUC, CSUC_fullDomain, CSUC_low;
1356 simpl.
1357 rewrite (UC_integral_extens
1358 _ (CSUCUnitTrapeze (a + (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)))
1359 (b - (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)))
1360 ((b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2))) (etaPos n))
1361 _ _
1362 _ (fun eps epsPos => eps * CR_of_Q R (1#2) * ((b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)))) _
1363 (CSUCUnitTrapeze_cont _ _ _ _ (fnL n))
1364 _ (TrapezeLe _ _ _ (etaPos n) (fnL n))).
1365 2: intros; reflexivity.
1366 rewrite (CSUCUnitTrapezeInt
1367 (a + (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)))
1368 (b - (b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)))
1369 ((b - a) * CR_of_Q R (1 # Pos.of_nat (n + 2)))
1370 (etaPos n) (fnL n)).
1371 unfold CRminus.
1372 rewrite CRplus_comm, CRopp_plus_distr, CRplus_assoc.
1373 rewrite <- (CRplus_assoc (- ((b + - a) * CR_of_Q R (1 # Pos.of_nat (n + 2))))).
1374 rewrite CRplus_opp_l, CRplus_0_l, <- CRplus_assoc, (CRplus_comm (-a)).
1375 rewrite CRopp_mult_distr_l. reflexivity.
1376 - exists (@IntegrableFunctionExtensional
1377 IntSpaceCSUCFunctions _ _ X limInt).
1378 unfold MeasureSet. rewrite IntegralRestrict. exact mesRect.
1379 Qed.
1380
1381 Lemma ClosedIntervalIntegrable
1382 : forall {R : ConstructiveReals} (a b : CRcarrier R),
1383 a <= b
1384 -> { limInt : @IntegrableSet IntSpaceCSUCFunctions
1385 (fun x => a <= x <= b)
1386 | MeasureSet limInt == b-a }.
1387 Proof.
1388 intros.
1389 assert (forall n:nat, a - CR_of_Q R (1 # Pos.of_nat n)
1390 < b + CR_of_Q R (1 # Pos.of_nat n)) as ltabn.
1391 { intro n. apply (CRle_lt_trans _ (a + 0)).
1392 rewrite <- CRopp_0. apply CRplus_le_compat_l, CRopp_ge_le_contravar.
1393 apply CR_of_Q_le. discriminate.
1394 apply (CRle_lt_trans _ (b+0)). apply CRplus_le_compat_r, H.
1395 apply CRplus_lt_compat_l, CR_of_Q_pos. reflexivity. }
1396 assert (CR_cv R (fun i : nat => CR_of_Q R (1 # Pos.of_nat i)) 0) as invCv.
1397 { intro p. exists (Pos.to_nat p).
1398 intros. unfold CRminus. rewrite CRopp_0, CRplus_0_r, CRabs_right.
1399 apply CR_of_Q_le. unfold Qle, Qnum, Qden. do 2 rewrite Z.mul_1_l.
1400 apply Pos2Z.pos_le_pos. apply Pos2Nat.inj_le. rewrite Nat2Pos.id.
1401 exact H0. destruct i. exfalso. inversion H0.
1402 pose proof (Pos2Nat.is_pos p). rewrite H2 in H1. inversion H1.
1403 discriminate. apply CR_of_Q_le. discriminate. }
1404 destruct (@IntegrableSetCountableIntersect
1405 IntSpaceCSUCFunctions
1406 (fun n x => CRltProp R (a - CR_of_Q _ (1 # Pos.of_nat n)) x
1407 /\ CRltProp R x (b + CR_of_Q _ (1 # Pos.of_nat n)))
1408 (fun n => let (i,_) := OpenIntervalIntegrable _ _ (ltabn n) in i)
1409 (b-a)).
1410 - apply (CR_cv_eq _ (fun n => b + CR_of_Q R (1 # Pos.of_nat n)
1411 - (a - CR_of_Q R (1 # Pos.of_nat n)))).
1412 intro n. rewrite MeasureIntersectSeqDecr.
1413 destruct (OpenIntervalIntegrable
1414 (a - CR_of_Q R (1 # Pos.of_nat n))
1415 (b + CR_of_Q R (1 # Pos.of_nat n)) (ltabn n)).
1416 symmetry; exact c. intros.
1417 destruct H0. split. apply CRltForget.
1418 apply CRltEpsilon in H0.
1419 apply (CRle_lt_trans _ (a - CR_of_Q R (1 # Pos.of_nat (S n0)))).
1420 2: exact H0. apply CRplus_le_compat_l. apply CRopp_ge_le_contravar.
1421 apply CR_of_Q_le. unfold Qle, Qnum, Qden.
1422 do 2 rewrite Z.mul_1_l. apply Pos2Z.pos_le_pos.
1423 destruct n0. discriminate.
1424 apply Pos2Nat.inj_le. rewrite Nat2Pos.id, Nat2Pos.id.
1425 apply le_S, Nat.le_refl. discriminate. discriminate.
1426 apply CRltEpsilon in H1. apply CRltForget.
1427 apply (CRlt_le_trans _ _ _ H1).
1428 apply CRplus_le_compat_l. apply CR_of_Q_le. unfold Qle, Qnum, Qden.
1429 do 2 rewrite Z.mul_1_l. apply Pos2Z.pos_le_pos.
1430 destruct n0. discriminate.
1431 apply Pos2Nat.inj_le. rewrite Nat2Pos.id, Nat2Pos.id.
1432 apply le_S, Nat.le_refl. discriminate. discriminate.
1433 apply CR_cv_minus.
1434 apply (CR_cv_proper _ (b+0)). apply CR_cv_plus.
1435 apply CR_cv_const. exact invCv. rewrite CRplus_0_r. reflexivity.
1436 apply (CR_cv_proper _ (a-0)). apply CR_cv_minus.
1437 apply CR_cv_const. exact invCv.
1438 unfold CRminus. rewrite CRopp_0, CRplus_0_r. reflexivity.
1439 - assert (forall x, (forall n : nat,
1440 CRltProp R (a - CR_of_Q R (1 # Pos.of_nat n)) x /\
1441 CRltProp R x (b + CR_of_Q R (1 # Pos.of_nat n)))
1442 <-> a <= x <= b) as H0.
1443 { split. intros. split.
1444 apply (CR_cv_bound_up (fun n => (a - CR_of_Q R (1 # Pos.of_nat n))) _ _ O).
1445 intros. specialize (H0 n) as [H0 _]. apply CRlt_asym, CRltEpsilon, H0.
1446 apply (CR_cv_proper _ (a-0)). apply CR_cv_minus.
1447 apply CR_cv_const. exact invCv.
1448 unfold CRminus. rewrite CRopp_0, CRplus_0_r. reflexivity.
1449 apply (CR_cv_bound_down (fun n => (b + CR_of_Q R (1 # Pos.of_nat n))) _ _ O).
1450 intros. specialize (H0 n) as [_ H0]. apply CRlt_asym, CRltEpsilon, H0.
1451 apply (CR_cv_proper _ (b+0)). apply CR_cv_plus.
1452 apply CR_cv_const. exact invCv. rewrite CRplus_0_r. reflexivity.
1453 intros. split. apply CRltForget.
1454 apply (CRlt_le_trans _ (a+-0)).
1455 2: rewrite CRopp_0, CRplus_0_r; exact (proj1 H0).
1456 apply CRplus_lt_compat_l, CRopp_gt_lt_contravar, CR_of_Q_pos.
1457 reflexivity.
1458 apply CRltForget.
1459 apply (CRle_lt_trans _ (b+0)). rewrite CRplus_0_r. exact (proj2 H0).
1460 apply CRplus_lt_compat_l, CR_of_Q_pos. reflexivity. }
1461 exists (IntegrableSetExtensional
1462 (fun x : X (ElemFunc IntSpaceCSUCFunctions) =>
1463 forall n : nat,
1464 CRltProp R (a - CR_of_Q R (1 # Pos.of_nat n)) x /\
1465 CRltProp R x (b + CR_of_Q R (1 # Pos.of_nat n))) _
1466 (fun x _ => H0 x) x0).
1467 rewrite <- (MeasureExtensional _ _ x0 _ (fun x _ _ => H0 x)). exact c.
1468 Qed.