summaryrefslogtreecommitdiff
path: root/theories/Reals/NewtonInt.v
blob: 832e7adc40954a51aa848ae1dbd26c17b225cf8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, *   INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015     *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

Require Import Rbase.
Require Import Rfunctions.
Require Import SeqSeries.
Require Import Rtrigo1.
Require Import Ranalysis.
Local Open Scope R_scope.

(*******************************************)
(*            Newton's Integral            *)
(*******************************************)

Definition Newton_integrable (f:R -> R) (a b:R) : Type :=
  { g:R -> R | antiderivative f g a b \/ antiderivative f g b a }.

Definition NewtonInt (f:R -> R) (a b:R) (pr:Newton_integrable f a b) : R :=
  let (g,_) := pr in g b - g a.

(* If f is differentiable, then f' is Newton integrable (Tautology ?) *)
Lemma FTCN_step1 :
  forall (f:Differential) (a b:R),
    Newton_integrable (fun x:R => derive_pt f x (cond_diff f x)) a b.
Proof.
  intros f a b; unfold Newton_integrable; exists (d1 f);
    unfold antiderivative; intros; case (Rle_dec a b);
      intro;
        [ left; split; [ intros; exists (cond_diff f x); reflexivity | assumption ]
          | right; split;
            [ intros; exists (cond_diff f x); reflexivity | auto with real ] ].
Defined.

(* By definition, we have the Fondamental Theorem of Calculus *)
Lemma FTC_Newton :
  forall (f:Differential) (a b:R),
    NewtonInt (fun x:R => derive_pt f x (cond_diff f x)) a b
    (FTCN_step1 f a b) = f b - f a.
Proof.
  intros; unfold NewtonInt; reflexivity.
Qed.

(* $\int_a^a f$ exists forall a:R and f:R->R *)
Lemma NewtonInt_P1 : forall (f:R -> R) (a:R), Newton_integrable f a a.
Proof.
  intros f a; unfold Newton_integrable;
    exists (fct_cte (f a) * id)%F; left;
      unfold antiderivative; split.
  intros; assert (H1 : derivable_pt (fct_cte (f a) * id) x).
  apply derivable_pt_mult.
  apply derivable_pt_const.
  apply derivable_pt_id.
  exists H1; assert (H2 : x = a).
  elim H; intros; apply Rle_antisym; assumption.
  symmetry ; apply derive_pt_eq_0;
    replace (f x) with (0 * id x + fct_cte (f a) x * 1);
    [ apply (derivable_pt_lim_mult (fct_cte (f a)) id x);
      [ apply derivable_pt_lim_const | apply derivable_pt_lim_id ]
      | unfold id, fct_cte; rewrite H2; ring ].
  right; reflexivity.
Qed.

(* $\int_a^a f = 0$ *)
Lemma NewtonInt_P2 :
  forall (f:R -> R) (a:R), NewtonInt f a a (NewtonInt_P1 f a) = 0.
Proof.
  intros; unfold NewtonInt; simpl;
    unfold mult_fct, fct_cte, id.
  destruct NewtonInt_P1 as [g _].
  now apply Rminus_diag_eq.
Qed.

(* If $\int_a^b f$ exists, then $\int_b^a f$ exists too *)
Lemma NewtonInt_P3 :
  forall (f:R -> R) (a b:R) (X:Newton_integrable f a b),
    Newton_integrable f b a.
Proof.
  unfold Newton_integrable; intros; elim X; intros g H;
    exists g; tauto.
Defined.

(* $\int_a^b f = -\int_b^a f$ *)
Lemma NewtonInt_P4 :
  forall (f:R -> R) (a b:R) (pr:Newton_integrable f a b),
    NewtonInt f a b pr = - NewtonInt f b a (NewtonInt_P3 f a b pr).
Proof.
  intros f a b (x,H). unfold NewtonInt, NewtonInt_P3; simpl; ring.
Qed.

(* The set of Newton integrable functions is a vectorial space *)
Lemma NewtonInt_P5 :
  forall (f g:R -> R) (l a b:R),
    Newton_integrable f a b ->
    Newton_integrable g a b ->
    Newton_integrable (fun x:R => l * f x + g x) a b.
Proof.
  unfold Newton_integrable; intros f g l a b X X0;
    elim X; intros x p; elim X0; intros x0 p0;
      exists (fun y:R => l * x y + x0 y).
  elim p; intro.
  elim p0; intro.
  left; unfold antiderivative; unfold antiderivative in H, H0; elim H;
    clear H; intros; elim H0; clear H0; intros H0 _.
  split.
  intros; elim (H _ H2); elim (H0 _ H2); intros.
  assert (H5 : derivable_pt (fun y:R => l * x y + x0 y) x1).
  reg.
  exists H5; symmetry ; reg; rewrite <- H3; rewrite <- H4; reflexivity.
  assumption.
  unfold antiderivative in H, H0; elim H; elim H0; intros; elim H4; intro.
  elim (Rlt_irrefl _ (Rlt_le_trans _ _ _ H5 H2)).
  left; rewrite <- H5; unfold antiderivative; split.
  intros; elim H6; intros; assert (H9 : x1 = a).
  apply Rle_antisym; assumption.
  assert (H10 : a <= x1 <= b).
  split; right; [ symmetry ; assumption | rewrite <- H5; assumption ].
  assert (H11 : b <= x1 <= a).
  split; right; [ rewrite <- H5; symmetry ; assumption | assumption ].
  assert (H12 : derivable_pt x x1).
  unfold derivable_pt; exists (f x1); elim (H3 _ H10); intros;
    eapply derive_pt_eq_1; symmetry ; apply H12.
  assert (H13 : derivable_pt x0 x1).
  unfold derivable_pt; exists (g x1); elim (H1 _ H11); intros;
    eapply derive_pt_eq_1; symmetry ; apply H13.
  assert (H14 : derivable_pt (fun y:R => l * x y + x0 y) x1).
  reg.
  exists H14; symmetry ; reg.
  assert (H15 : derive_pt x0 x1 H13 = g x1).
  elim (H1 _ H11); intros; rewrite H15; apply pr_nu.
  assert (H16 : derive_pt x x1 H12 = f x1).
  elim (H3 _ H10); intros; rewrite H16; apply pr_nu.
  rewrite H15; rewrite H16; ring.
  right; reflexivity.
  elim p0; intro.
  unfold antiderivative in H, H0; elim H; elim H0; intros; elim H4; intro.
  elim (Rlt_irrefl _ (Rlt_le_trans _ _ _ H5 H2)).
  left; rewrite H5; unfold antiderivative; split.
  intros; elim H6; intros; assert (H9 : x1 = a).
  apply Rle_antisym; assumption.
  assert (H10 : a <= x1 <= b).
  split; right; [ symmetry ; assumption | rewrite H5; assumption ].
  assert (H11 : b <= x1 <= a).
  split; right; [ rewrite H5; symmetry ; assumption | assumption ].
  assert (H12 : derivable_pt x x1).
  unfold derivable_pt; exists (f x1); elim (H3 _ H11); intros;
    eapply derive_pt_eq_1; symmetry ; apply H12.
  assert (H13 : derivable_pt x0 x1).
  unfold derivable_pt; exists (g x1); elim (H1 _ H10); intros;
    eapply derive_pt_eq_1; symmetry ; apply H13.
  assert (H14 : derivable_pt (fun y:R => l * x y + x0 y) x1).
  reg.
  exists H14; symmetry ; reg.
  assert (H15 : derive_pt x0 x1 H13 = g x1).
  elim (H1 _ H10); intros; rewrite H15; apply pr_nu.
  assert (H16 : derive_pt x x1 H12 = f x1).
  elim (H3 _ H11); intros; rewrite H16; apply pr_nu.
  rewrite H15; rewrite H16; ring.
  right; reflexivity.
  right; unfold antiderivative; unfold antiderivative in H, H0; elim H;
    clear H; intros; elim H0; clear H0; intros H0 _; split.
  intros; elim (H _ H2); elim (H0 _ H2); intros.
  assert (H5 : derivable_pt (fun y:R => l * x y + x0 y) x1).
  reg.
  exists H5; symmetry ; reg; rewrite <- H3; rewrite <- H4; reflexivity.
  assumption.
Defined.

(**********)
Lemma antiderivative_P1 :
  forall (f g F G:R -> R) (l a b:R),
    antiderivative f F a b ->
    antiderivative g G a b ->
    antiderivative (fun x:R => l * f x + g x) (fun x:R => l * F x + G x) a b.
Proof.
  unfold antiderivative; intros; elim H; elim H0; clear H H0; intros;
    split.
  intros; elim (H _ H3); elim (H1 _ H3); intros.
  assert (H6 : derivable_pt (fun x:R => l * F x + G x) x).
  reg.
  exists H6; symmetry ; reg; rewrite <- H4; rewrite <- H5; ring.
  assumption.
Qed.

(* $\int_a^b \lambda f + g = \lambda \int_a^b f + \int_a^b f *)
Lemma NewtonInt_P6 :
  forall (f g:R -> R) (l a b:R) (pr1:Newton_integrable f a b)
    (pr2:Newton_integrable g a b),
    NewtonInt (fun x:R => l * f x + g x) a b (NewtonInt_P5 f g l a b pr1 pr2) =
    l * NewtonInt f a b pr1 + NewtonInt g a b pr2.
Proof.
  intros f g l a b pr1 pr2; unfold NewtonInt;
    destruct (NewtonInt_P5 f g l a b pr1 pr2) as (x,o); destruct pr1 as (x0,o0);
      destruct pr2 as (x1,o1); destruct (total_order_T a b) as [[Hlt|Heq]|Hgt].
  elim o; intro.
  elim o0; intro.
  elim o1; intro.
  assert (H2 := antiderivative_P1 f g x0 x1 l a b H0 H1);
    assert (H3 := antiderivative_Ucte _ _ _ _ _ H H2);
      elim H3; intros; assert (H5 : a <= a <= b).
  split; [ right; reflexivity | left; assumption ].
  assert (H6 : a <= b <= b).
  split; [ left; assumption | right; reflexivity ].
  assert (H7 := H4 _ H5); assert (H8 := H4 _ H6); rewrite H7; rewrite H8; ring.
  unfold antiderivative in H1; elim H1; intros;
    elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H3 Hlt)).
  unfold antiderivative in H0; elim H0; intros;
    elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hlt)).
  unfold antiderivative in H; elim H; intros;
    elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H1 Hlt)).
  rewrite Heq; ring.
  elim o; intro.
  unfold antiderivative in H; elim H; intros;
    elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H1 Hgt)).
  elim o0; intro.
  unfold antiderivative in H0; elim H0; intros;
    elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hgt)).
  elim o1; intro.
  unfold antiderivative in H1; elim H1; intros;
    elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H3 Hgt)).
  assert (H2 := antiderivative_P1 f g x0 x1 l b a H0 H1);
    assert (H3 := antiderivative_Ucte _ _ _ _ _ H H2);
      elim H3; intros; assert (H5 : b <= a <= a).
  split; [ left; assumption | right; reflexivity ].
  assert (H6 : b <= b <= a).
  split; [ right; reflexivity | left; assumption ].
  assert (H7 := H4 _ H5); assert (H8 := H4 _ H6); rewrite H7; rewrite H8; ring.
Qed.

Lemma antiderivative_P2 :
  forall (f F0 F1:R -> R) (a b c:R),
    antiderivative f F0 a b ->
    antiderivative f F1 b c ->
    antiderivative f
    (fun x:R =>
      match Rle_dec x b with
        | left _ => F0 x
        | right _ => F1 x + (F0 b - F1 b)
      end) a c.
Proof.
  intros; destruct H as (H,H1), H0 as (H0,H2); split.
  2: apply Rle_trans with b; assumption.
  intros x (H3,H4); destruct (total_order_T x b) as [[Hlt|Heq]|Hgt].
  assert (H5 : a <= x <= b).
  split; [ assumption | left; assumption ].
  destruct (H _ H5) as (x0,H6).
    assert
      (H7 :
        derivable_pt_lim
        (fun x:R =>
          match Rle_dec x b with
            | left _ => F0 x
            | right _ => F1 x + (F0 b - F1 b)
          end) x (f x)).
  unfold derivable_pt_lim. intros eps H9.
  assert (H7 : derive_pt F0 x x0 = f x) by (symmetry; assumption).
  destruct (derive_pt_eq_1 F0 x (f x) x0 H7 _ H9) as (x1,H10); set (D := Rmin x1 (b - x)).
  assert (H11 : 0 < D).
  unfold D, Rmin; case (Rle_dec x1 (b - x)); intro.
  apply (cond_pos x1).
  apply Rlt_Rminus; assumption.
  exists (mkposreal _ H11); intros h H12 H13. case (Rle_dec x b) as [|[]].
  case (Rle_dec (x + h) b) as [|[]].
  apply H10.
  assumption.
  apply Rlt_le_trans with D; [ assumption | unfold D; apply Rmin_l ].
  left; apply Rlt_le_trans with (x + D).
  apply Rplus_lt_compat_l; apply Rle_lt_trans with (Rabs h).
  apply RRle_abs.
  apply H13.
  apply Rplus_le_reg_l with (- x); rewrite <- Rplus_assoc; rewrite Rplus_opp_l;
    rewrite Rplus_0_l; rewrite Rplus_comm; unfold D;
      apply Rmin_r.
  left; assumption.
  assert
    (H8 :
      derivable_pt
      (fun x:R =>
        match Rle_dec x b with
          | left _ => F0 x
          | right _ => F1 x + (F0 b - F1 b)
        end) x).
  unfold derivable_pt; exists (f x); apply H7.
  exists H8; symmetry ; apply derive_pt_eq_0; apply H7.
  assert (H5 : a <= x <= b).
  split; [ assumption | right; assumption ].
  assert (H6 : b <= x <= c).
  split; [ right; symmetry ; assumption | assumption ].
  elim (H _ H5); elim (H0 _ H6); intros; assert (H9 : derive_pt F0 x x1 = f x).
  symmetry ; assumption.
  assert (H10 : derive_pt F1 x x0 = f x).
  symmetry ; assumption.
  assert (H11 := derive_pt_eq_1 F0 x (f x) x1 H9);
    assert (H12 := derive_pt_eq_1 F1 x (f x) x0 H10);
      assert
        (H13 :
          derivable_pt_lim
          (fun x:R =>
            match Rle_dec x b with
              | left _ => F0 x
              | right _ => F1 x + (F0 b - F1 b)
            end) x (f x)).
  unfold derivable_pt_lim; unfold derivable_pt_lim in H11, H12; intros;
    elim (H11 _ H13); elim (H12 _ H13); intros; set (D := Rmin x2 x3);
      assert (H16 : 0 < D).
  unfold D; unfold Rmin; case (Rle_dec x2 x3); intro.
  apply (cond_pos x2).
  apply (cond_pos x3).
  exists (mkposreal _ H16); intros; case (Rle_dec x b) as [|[]].
  case (Rle_dec (x + h) b); intro.
  apply H15.
  assumption.
  apply Rlt_le_trans with D; [ assumption | unfold D; apply Rmin_r ].
  replace (F1 (x + h) + (F0 b - F1 b) - F0 x) with (F1 (x + h) - F1 x).
  apply H14.
  assumption.
  apply Rlt_le_trans with D; [ assumption | unfold D; apply Rmin_l ].
  rewrite Heq; ring.
  right; assumption.
  assert
    (H14 :
      derivable_pt
      (fun x:R =>
        match Rle_dec x b with
          | left _ => F0 x
          | right _ => F1 x + (F0 b - F1 b)
        end) x).
  unfold derivable_pt; exists (f x); apply H13.
  exists H14; symmetry ; apply derive_pt_eq_0; apply H13.
  assert (H5 : b <= x <= c).
  split; [ left; assumption | assumption ].
  assert (H6 := H0 _ H5); elim H6; clear H6; intros;
    assert
      (H7 :
        derivable_pt_lim
        (fun x:R =>
          match Rle_dec x b with
            | left _ => F0 x
            | right _ => F1 x + (F0 b - F1 b)
          end) x (f x)).
  unfold derivable_pt_lim; assert (H7 : derive_pt F1 x x0 = f x).
  symmetry ; assumption.
  assert (H8 := derive_pt_eq_1 F1 x (f x) x0 H7); unfold derivable_pt_lim in H8;
    intros; elim (H8 _ H9); intros; set (D := Rmin x1 (x - b));
      assert (H11 : 0 < D).
  unfold D; unfold Rmin; case (Rle_dec x1 (x - b)); intro.
  apply (cond_pos x1).
  apply Rlt_Rminus; assumption.
  exists (mkposreal _ H11); intros; destruct (Rle_dec x b) as [Hle|Hnle].
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ Hle Hgt)).
  destruct (Rle_dec (x + h) b) as [Hle'|Hnle'].
  cut (b < x + h).
  intro; elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ Hle' H14)).
  apply Rplus_lt_reg_l with (- h - b); replace (- h - b + b) with (- h);
    [ idtac | ring ]; replace (- h - b + (x + h)) with (x - b);
    [ idtac | ring ]; apply Rle_lt_trans with (Rabs h).
  rewrite <- Rabs_Ropp; apply RRle_abs.
  apply Rlt_le_trans with D.
  apply H13.
  unfold D; apply Rmin_r.
  replace (F1 (x + h) + (F0 b - F1 b) - (F1 x + (F0 b - F1 b))) with
  (F1 (x + h) - F1 x); [ idtac | ring ]; apply H10.
  assumption.
  apply Rlt_le_trans with D.
  assumption.
  unfold D; apply Rmin_l.
  assert
    (H8 :
      derivable_pt
      (fun x:R =>
        match Rle_dec x b with
          | left _ => F0 x
          | right _ => F1 x + (F0 b - F1 b)
        end) x).
  unfold derivable_pt; exists (f x); apply H7.
  exists H8; symmetry ; apply derive_pt_eq_0; apply H7.
Qed.

Lemma antiderivative_P3 :
  forall (f F0 F1:R -> R) (a b c:R),
    antiderivative f F0 a b ->
    antiderivative f F1 c b ->
    antiderivative f F1 c a \/ antiderivative f F0 a c.
Proof.
  intros; unfold antiderivative in H, H0; elim H; clear H; elim H0; clear H0;
    intros; destruct (total_order_T a c) as [[Hle|Heq]|Hgt].
  right; unfold antiderivative; split.
  intros; apply H1; elim H3; intros; split;
    [ assumption | apply Rle_trans with c; assumption ].
  left; assumption.
  right; unfold antiderivative; split.
  intros; apply H1; elim H3; intros; split;
    [ assumption | apply Rle_trans with c; assumption ].
  right; assumption.
  left; unfold antiderivative; split.
  intros; apply H; elim H3; intros; split;
    [ assumption | apply Rle_trans with a; assumption ].
  left; assumption.
Qed.

Lemma antiderivative_P4 :
  forall (f F0 F1:R -> R) (a b c:R),
    antiderivative f F0 a b ->
    antiderivative f F1 a c ->
    antiderivative f F1 b c \/ antiderivative f F0 c b.
Proof.
  intros; unfold antiderivative in H, H0; elim H; clear H; elim H0; clear H0;
    intros; destruct (total_order_T c b) as [[Hlt|Heq]|Hgt].
  right; unfold antiderivative; split.
  intros; apply H1; elim H3; intros; split;
    [ apply Rle_trans with c; assumption | assumption ].
  left; assumption.
  right; unfold antiderivative; split.
  intros; apply H1; elim H3; intros; split;
    [ apply Rle_trans with c; assumption | assumption ].
  right; assumption.
  left; unfold antiderivative; split.
  intros; apply H; elim H3; intros; split;
    [ apply Rle_trans with b; assumption | assumption ].
  left; assumption.
Qed.

Lemma NewtonInt_P7 :
  forall (f:R -> R) (a b c:R),
    a < b ->
    b < c ->
    Newton_integrable f a b ->
    Newton_integrable f b c -> Newton_integrable f a c.
Proof.
  unfold Newton_integrable; intros f a b c Hab Hbc X X0; elim X;
    clear X; intros F0 H0; elim X0; clear X0; intros F1 H1;
      set
        (g :=
          fun x:R =>
            match Rle_dec x b with
              | left _ => F0 x
              | right _ => F1 x + (F0 b - F1 b)
            end); exists g; left; unfold g;
        apply antiderivative_P2.
  elim H0; intro.
  assumption.
  unfold antiderivative in H; elim H; clear H; intros;
    elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hab)).
  elim H1; intro.
  assumption.
  unfold antiderivative in H; elim H; clear H; intros;
    elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hbc)).
Qed.

Lemma NewtonInt_P8 :
  forall (f:R -> R) (a b c:R),
    Newton_integrable f a b ->
    Newton_integrable f b c -> Newton_integrable f a c.
Proof.
  intros.
  elim X; intros F0 H0.
  elim X0; intros F1 H1.
  destruct (total_order_T a b) as [[Hlt|Heq]|Hgt].
  destruct (total_order_T b c) as [[Hlt'|Heq']|Hgt'].
(* a<b & b<c *)
  unfold Newton_integrable;
    exists
      (fun x:R =>
        match Rle_dec x b with
          | left _ => F0 x
          | right _ => F1 x + (F0 b - F1 b)
        end).
  elim H0; intro.
  elim H1; intro.
  left; apply antiderivative_P2; assumption.
  unfold antiderivative in H2; elim H2; clear H2; intros _ H2.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hlt')).
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hlt)).
(* a<b & b=c *)
  rewrite Heq' in X; apply X.
(* a<b & b>c *)
  destruct (total_order_T a c) as [[Hlt''|Heq'']|Hgt''].
  unfold Newton_integrable; exists F0.
  left.
  elim H1; intro.
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hgt')).
  elim H0; intro.
  assert (H3 := antiderivative_P3 f F0 F1 a b c H2 H).
  elim H3; intro.
  unfold antiderivative in H4; elim H4; clear H4; intros _ H4.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H4 Hlt'')).
  assumption.
  unfold antiderivative in H2; elim H2; clear H2; intros _ H2.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hlt)).
  rewrite Heq''; apply NewtonInt_P1.
  unfold Newton_integrable; exists F1.
  right.
  elim H1; intro.
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hgt')).
  elim H0; intro.
  assert (H3 := antiderivative_P3 f F0 F1 a b c H2 H).
  elim H3; intro.
  assumption.
  unfold antiderivative in H4; elim H4; clear H4; intros _ H4.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H4 Hgt'')).
  unfold antiderivative in H2; elim H2; clear H2; intros _ H2.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hlt)).
(* a=b *)
  rewrite Heq; apply X0.
  destruct (total_order_T b c) as [[Hlt'|Heq']|Hgt'].
(* a>b & b<c *)
  destruct (total_order_T a c) as [[Hlt''|Heq'']|Hgt''].
  unfold Newton_integrable; exists F1.
  left.
  elim H1; intro.
(*****************)
  elim H0; intro.
  unfold antiderivative in H2; elim H2; clear H2; intros _ H2.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hgt)).
  assert (H3 := antiderivative_P4 f F0 F1 b a c H2 H).
  elim H3; intro.
  assumption.
  unfold antiderivative in H4; elim H4; clear H4; intros _ H4.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H4 Hlt'')).
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hlt')).
  rewrite Heq''; apply NewtonInt_P1.
  unfold Newton_integrable; exists F0.
  right.
  elim H0; intro.
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hgt)).
  elim H1; intro.
  assert (H3 := antiderivative_P4 f F0 F1 b a c H H2).
  elim H3; intro.
  unfold antiderivative in H4; elim H4; clear H4; intros _ H4.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H4 Hgt'')).
  assumption.
  unfold antiderivative in H2; elim H2; clear H2; intros _ H2.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H2 Hlt')).
(* a>b & b=c *)
  rewrite Heq' in X; apply X.
(* a>b & b>c *)
  assert (X1 := NewtonInt_P3 f a b X).
  assert (X2 := NewtonInt_P3 f b c X0).
  apply NewtonInt_P3.
  apply NewtonInt_P7 with b; assumption.
Qed.

(* Chasles' relation *)
Lemma NewtonInt_P9 :
  forall (f:R -> R) (a b c:R) (pr1:Newton_integrable f a b)
    (pr2:Newton_integrable f b c),
    NewtonInt f a c (NewtonInt_P8 f a b c pr1 pr2) =
    NewtonInt f a b pr1 + NewtonInt f b c pr2.
Proof.
  intros; unfold NewtonInt.
  case (NewtonInt_P8 f a b c pr1 pr2) as (x,Hor).
  case pr1 as (x0,Hor0).
  case pr2 as (x1,Hor1).
  destruct (total_order_T a b) as [[Hlt|Heq]|Hgt].
  destruct (total_order_T b c) as [[Hlt'|Heq']|Hgt'].
(* a<b & b<c *)
  case Hor0; intro.
  case Hor1; intro.
  case Hor; intro.
  assert (H2 := antiderivative_P2 f x0 x1 a b c H H0).
  assert
    (H3 :=
      antiderivative_Ucte f x
      (fun x:R =>
        match Rle_dec x b with
          | left _ => x0 x
          | right _ => x1 x + (x0 b - x1 b)
        end) a c H1 H2).
  elim H3; intros.
  assert (H5 : a <= a <= c).
  split; [ right; reflexivity | left; apply Rlt_trans with b; assumption ].
  assert (H6 : a <= c <= c).
  split; [ left; apply Rlt_trans with b; assumption | right; reflexivity ].
  rewrite (H4 _ H5); rewrite (H4 _ H6).
  destruct (Rle_dec a b) as [Hlea|Hnlea].
  destruct (Rle_dec c b) as [Hlec|Hnlec].
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ Hlec Hlt')).
  ring.
  elim Hnlea; left; assumption.
  unfold antiderivative in H1; elim H1; clear H1; intros _ H1.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H1 (Rlt_trans _ _ _ Hlt Hlt'))).
  unfold antiderivative in H0; elim H0; clear H0; intros _ H0.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H0 Hlt')).
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hlt)).
(* a<b & b=c *)
  rewrite <- Heq'.
  unfold Rminus; rewrite Rplus_opp_r; rewrite Rplus_0_r.
  rewrite <- Heq' in Hor.
  elim Hor0; intro.
  elim Hor; intro.
  assert (H1 := antiderivative_Ucte f x x0 a b H0 H).
  elim H1; intros.
  rewrite (H2 b).
  rewrite (H2 a).
  ring.
  split; [ right; reflexivity | left; assumption ].
  split; [ left; assumption | right; reflexivity ].
  unfold antiderivative in H0; elim H0; clear H0; intros _ H0.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H0 Hlt)).
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hlt)).
(* a<b & b>c *)
  elim Hor1; intro.
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hgt')).
  elim Hor0; intro.
  elim Hor; intro.
  assert (H2 := antiderivative_P2 f x x1 a c b H1 H).
  assert (H3 := antiderivative_Ucte _ _ _ a b H0 H2).
  elim H3; intros.
  rewrite (H4 a).
  rewrite (H4 b).
  destruct (Rle_dec b c) as [Hle|Hnle].
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ Hle Hgt')).
  destruct (Rle_dec a c) as [Hle'|Hnle'].
  ring.
  elim Hnle'; unfold antiderivative in H1; elim H1; intros; assumption.
  split; [ left; assumption | right; reflexivity ].
  split; [ right; reflexivity | left; assumption ].
  assert (H2 := antiderivative_P2 _ _ _ _ _ _ H1 H0).
  assert (H3 := antiderivative_Ucte _ _ _ c b H H2).
  elim H3; intros.
  rewrite (H4 c).
  rewrite (H4 b).
  destruct (Rle_dec b a) as [Hle|Hnle].
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ Hle Hlt)).
  destruct (Rle_dec c a) as [Hle'|[]].
  ring.
  unfold antiderivative in H1; elim H1; intros; assumption.
  split; [ left; assumption | right; reflexivity ].
  split; [ right; reflexivity | left; assumption ].
  unfold antiderivative in H0; elim H0; clear H0; intros _ H0.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H0 Hlt)).
(* a=b *)
  rewrite Heq in Hor |- *.
  elim Hor; intro.
  elim Hor1; intro.
  assert (H1 := antiderivative_Ucte _ _ _ b c H H0).
  elim H1; intros.
  assert (H3 : b <= c).
  unfold antiderivative in H; elim H; intros; assumption.
  rewrite (H2 b).
  rewrite (H2 c).
  ring.
  split; [ assumption | right; reflexivity ].
  split; [ right; reflexivity | assumption ].
  assert (H1 : b = c).
  unfold antiderivative in H, H0; elim H; elim H0; intros; apply Rle_antisym;
    assumption.
  rewrite H1; ring.
  elim Hor1; intro.
  assert (H1 : b = c).
  unfold antiderivative in H, H0; elim H; elim H0; intros; apply Rle_antisym;
    assumption.
  rewrite H1; ring.
  assert (H1 := antiderivative_Ucte _ _ _ c b H H0).
  elim H1; intros.
  assert (H3 : c <= b).
  unfold antiderivative in H; elim H; intros; assumption.
  rewrite (H2 c).
  rewrite (H2 b).
  ring.
  split; [ assumption | right; reflexivity ].
  split; [ right; reflexivity | assumption ].
(* a>b & b<c *)
  destruct (total_order_T b c) as [[Hlt'|Heq']|Hgt'].
  elim Hor0; intro.
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hgt)).
  elim Hor1; intro.
  elim Hor; intro.
  assert (H2 := antiderivative_P2 _ _ _ _ _ _ H H1).
  assert (H3 := antiderivative_Ucte _ _ _ b c H0 H2).
  elim H3; intros.
  rewrite (H4 b).
  rewrite (H4 c).
  case (Rle_dec b a) as [|[]].
  case (Rle_dec c a) as [|].
  assert (H5 : a = c).
  unfold antiderivative in H1; elim H1; intros; apply Rle_antisym; assumption.
  rewrite H5; ring.
  ring.
  left; assumption.
  split; [ left; assumption | right; reflexivity ].
  split; [ right; reflexivity | left; assumption ].
  assert (H2 := antiderivative_P2 _ _ _ _ _ _ H0 H1).
  assert (H3 := antiderivative_Ucte _ _ _ b a H H2).
  elim H3; intros.
  rewrite (H4 a).
  rewrite (H4 b).
  case (Rle_dec b c) as [|[]].
  case (Rle_dec a c) as [|].
  assert (H5 : a = c).
  unfold antiderivative in H1; elim H1; intros; apply Rle_antisym; assumption.
  rewrite H5; ring.
  ring.
  left; assumption.
  split; [ right; reflexivity | left; assumption ].
  split; [ left; assumption | right; reflexivity ].
  unfold antiderivative in H0; elim H0; clear H0; intros _ H0.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H0 Hlt')).
(* a>b & b=c *)
  rewrite <- Heq'.
  unfold Rminus; rewrite Rplus_opp_r; rewrite Rplus_0_r.
  rewrite <- Heq' in Hor.
  elim Hor0; intro.
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hgt)).
  elim Hor; intro.
  unfold antiderivative in H0; elim H0; clear H0; intros _ H0.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H0 Hgt)).
  assert (H1 := antiderivative_Ucte f x x0 b a H0 H).
  elim H1; intros.
  rewrite (H2 b).
  rewrite (H2 a).
  ring.
  split; [ left; assumption | right; reflexivity ].
  split; [ right; reflexivity | left; assumption ].
(* a>b & b>c *)
  elim Hor0; intro.
  unfold antiderivative in H; elim H; clear H; intros _ H.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H Hgt)).
  elim Hor1; intro.
  unfold antiderivative in H0; elim H0; clear H0; intros _ H0.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H0 Hgt')).
  elim Hor; intro.
  unfold antiderivative in H1; elim H1; clear H1; intros _ H1.
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ H1 (Rlt_trans _ _ _ Hgt' Hgt))).
  assert (H2 := antiderivative_P2 _ _ _ _ _ _ H0 H).
  assert (H3 := antiderivative_Ucte _ _ _ c a H1 H2).
  elim H3; intros.
  assert (H5 : c <= a).
  unfold antiderivative in H1; elim H1; intros; assumption.
  rewrite (H4 c).
  rewrite (H4 a).
  destruct (Rle_dec a b) as [Hle|Hnle].
  elim (Rlt_irrefl _ (Rle_lt_trans _ _ _ Hle Hgt)).
  destruct (Rle_dec c b) as [|[]].
  ring.
  left; assumption.
  split; [ assumption | right; reflexivity ].
  split; [ right; reflexivity | assumption ].
Qed.