-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweights.v
More file actions
executable file
·1580 lines (1439 loc) · 52.1 KB
/
weights.v
File metadata and controls
executable file
·1580 lines (1439 loc) · 52.1 KB
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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Set Implicit Arguments.
Unset Strict Implicit.
Require Import QArith Reals Rpower Ranalysis Fourier.
Require Import Coq.Logic.ProofIrrelevance.
Require Import mathcomp.ssreflect.ssreflect.
From mathcomp Require Import all_ssreflect.
From mathcomp Require Import all_algebra.
Import GRing.Theory Num.Def Num.Theory.
Require Import Lra.
Require Import OUVerT.extrema OUVerT.dist OUVerT.numerics OUVerT.bigops.
(** [NOTE on refs] Section and lemma names below (e.g., R177)
refer to sections/lemmas in Roughgarden's "Twenty Lectures
in Algorithmic Game Theory" (Cambridge 2016). *)
Section weights.
Local Open Scope ring_scope.
Variable A : finType.
Variable a0 : A. (*A is inhabited*)
Variable eps : rat.
Variable eps_range : 0 < eps <= 1/2%:R.
Definition weights := {ffun A -> rat}.
Definition init_weights : weights := finfun (fun _ => 1%:R).
Definition costs := {ffun A -> rat}.
Lemma init_weights_gt0 :
forall a : A, 0 < init_weights a.
Proof. by move=> a; rewrite /init_weights ffunE. Qed.
Definition update_weights (w : weights) (c : costs) : weights :=
finfun (fun a : A => w a * (1 - eps * c a)).
Lemma update_weights_gt0 (w : weights) (c : costs) :
(forall a : A, `|c a| <= 1) ->
(forall a : A, 0 < w a) ->
forall a : A, 0 < update_weights w c a.
Proof.
move=> H0 H a.
rewrite /update_weights ffunE.
apply: mulr_gt0=> //.
rewrite subr_gt0.
case: (andP eps_range)=> H1 H2.
rewrite mulrC.
case H3: (c a == 0).
{ move: (eqP H3)=> ->; rewrite mul0r=> //. }
case H4: (c a < 0).
{ have H5: c a * eps < 0.
{ rewrite mulrC pmulr_rlt0 => //. }
by apply: (ltr_le_trans H5). }
have H5: 0 < c a.
{ have H6: (c a != 0) by apply/negP; rewrite H3.
by case: (ltr_total H6); rewrite H4. }
have H6: (c a * eps < c a).
{ rewrite gtr_pmulr => //.
apply: (ler_lt_trans H2)=> //. }
move: (H0 a)=> H7; apply: (ltr_le_trans H6).
by rewrite ler_norml in H7; case: (andP H7).
Qed.
(** The cost functions [cs] are given in reverse chronological order.
That is,
[cs = c_T :: c_(T-1) :: ... :: c_1].
This simplifies reasoning: [weights_of] is now fold-right
rather than fold-left. *)
Fixpoint weights_of (cs : seq costs) (w : weights) : weights :=
if cs is [:: c & cs'] then
update_weights (weights_of cs' w) c
else w.
Lemma weights_of_ind
(cs : seq costs)
(w : weights)
(P : seq costs -> weights -> Prop) :
P [::] w ->
(forall w' c cs',
P cs' w' ->
P [:: c & cs'] (update_weights w' c)) ->
P cs (weights_of cs w).
Proof.
move=> H IH; elim: cs=> //.
move=> c cs' H0 /=.
by apply: IH.
Qed.
Lemma weights_of_eq (cs : seq costs) :
weights_of cs init_weights =
finfun (fun a => \prod_(c <- cs) (1 - eps*(c a))).
Proof.
elim: cs.
{ simpl.
rewrite /init_weights.
apply/ffunP=> x.
by rewrite !ffunE big_nil.
}
move=> a l H /=.
rewrite /update_weights; apply/ffunP=> x; rewrite H !ffunE.
by rewrite big_cons mulrC.
Qed.
(** Here's an alternative version: fold-left-style [weights_of]: *)
Fixpoint weights_of_left (cs : seq costs) (w : weights) : weights :=
if cs is [:: c & cs'] then
weights_of_left cs' (update_weights w c)
else w.
Lemma weights_of_app cs1 cs2 w :
weights_of (cs1 ++ cs2) w =
weights_of cs1 (weights_of cs2 w).
Proof. by elim: cs1 cs2 w => // c cs1 IH cs2 w /=; rewrite IH. Qed.
Lemma weights_of_rightleft cs w :
weights_of (rev cs) w = weights_of_left cs w.
Proof.
elim: cs w => // c cs' IH w /=; rewrite -IH.
by rewrite rev_cons -cats1 weights_of_app.
Qed.
Lemma weights_of_gt0 (cs : seq costs) (w : weights) :
(forall c, c \in cs -> forall a : A, `|c a| <= 1) ->
(forall a : A, 0 < w a) ->
forall a : A, 0 < weights_of cs w a.
Proof.
apply weights_of_ind=> //.
move=> w' c cs' IH H0 H1 a.
apply: update_weights_gt0=> //.
by apply: H0; rewrite /in_mem /=; apply/orP; left.
apply: IH=> // c0 Hin a1.
by apply: H0; rewrite /in_mem /=; apply/orP; right.
Qed.
Lemma sum_gt0 (w : weights) :
(forall a : A, 0 < w a) ->
0 < \sum_(a : A) w a.
Proof.
move=> H0.
have H: 0 <= \sum_(a : A) w a.
{ by apply/sumr_ge0=> i _; apply/ltrW. }
rewrite ltr_def; apply/andP; split=> //.
apply/eqP=> H1.
have H2: forall i : A, true -> 0 <= w i.
{ by move=> i _; apply/ltrW. }
move: (psumr_eq0P (P:=xpredT)(F:=w) H2 H1).
move: (H0 a0)=> H4.
by move/(_ a0 erefl)=> H3; rewrite H3 in H4.
Qed.
Lemma sum_weights_of_gt0 (cs : seq costs) (w : weights) :
(forall c, c \in cs -> forall a : A, `|c a| <= 1) ->
(forall a : A, 0 < w a) ->
0 < \sum_(a : A) (weights_of cs w) a.
Proof.
by move=> H0 H; apply: sum_gt0; apply: weights_of_gt0.
Qed.
Lemma sum_weights_of_not0 (cs : seq costs) :
(forall c, c \in cs -> forall a : A, `|c a| <= 1) ->
\sum_(a : A) (weights_of cs init_weights) a != 0.
Proof.
move=> H; move: sum_weights_of_gt0.
move/(_ cs init_weights H init_weights_gt0)=> H0.
by apply/eqP=> H1; rewrite H1 in H0.
Qed.
Lemma weight1_sum_ler (a : A) (w : weights) :
(forall a : A, 0 <= w a) ->
w a <= \sum_(a0 : A) w a0.
Proof.
move=> H.
suff: ((\sum_(a1 : A) if a1 == a then w a1 else 0) <= \sum_a1 w a1).
{ move=> H2.
have H3: w a <= \sum_a1 (if a1 == a then w a1 else 0).
{ have H4: \sum_a1 (if a1 == a then w a1 else 0) = \sum_(a1 | a1 == a) w a1.
{ by rewrite -big_mkcond.
}
by rewrite H4 big_pred1_eq.
}
by apply: (ler_trans H3 H2).
}
apply: ler_sum.
by move=> i _; case: (i == a).
Qed.
Definition gamma (w : weights) : rat :=
\sum_(a : A) (w a).
Lemma gamma_normalizes (w : weights) :
\sum_(a : A) w a != 0 ->
\sum_(a : A) w a / gamma w == 1.
Proof. by move=> H; rewrite /gamma -mulr_suml mulrC mulVf. Qed.
Lemma gamma_ge0 (w : weights) :
(forall a : A, 0 <= w a) ->
0 <= gamma w.
Proof.
by move=> H; apply: sumr_ge0.
Qed.
Definition p_aux (cs : seq costs) (w : weights) : weights :=
let w' := weights_of cs w in
finfun (fun a : A => w' a / gamma w').
(** The following definition of [p_aux] uses fold-left [weights_of']: *)
Definition p_aux_left (cs : seq costs) (w : weights) : weights :=
let w' := weights_of_left cs w in
finfun (fun a : A => w' a / gamma w').
Lemma p_aux_aux_left cs w : p_aux (rev cs) w = p_aux_left cs w.
Proof.
rewrite /p_aux /p_aux_left; apply/ffunP => a; rewrite 2!ffunE.
by rewrite weights_of_rightleft.
Qed.
Lemma div1rr (r : rat) : r != 0 -> 1 / r * r == 1.
Proof. by move=> H; rewrite div1r mulVf. Qed.
Lemma div1rn (n : nat) (r : rat) : r != 0 -> r == n%:R -> 1 / r *+ n == 1.
Proof.
move=> H H2; move: (eqP H2)=> H3.
rewrite H3 -mulrnAl mulfV=> //.
by rewrite -H3.
Qed.
Lemma Acard_gt0 : (0 < #|A|)%N.
Proof. by apply/card_gt0P; exists a0. Qed.
Lemma rat_to_R_Acard_gt0 : Rlt 0 (rat_to_R #|A|%:R).
Proof.
move: Acard_gt0; rewrite -rat_to_R0 -(@ltr_nat rat_numDomainType).
by apply: rat_to_R_lt.
Qed.
Lemma rat_to_R_Acard_ge1 : Rle 1 (rat_to_R #|A|%:R).
Proof.
move: Acard_gt0; rewrite -rat_to_R1 -(@ler_nat rat_numDomainType).
by apply: rat_to_R_le.
Qed.
Lemma p_aux_ind
(cs : seq costs)
(w : weights)
(CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1)
(WEIGHTS : forall a : A, 0 < w a)
(P : seq costs -> weights -> Prop) :
P [::] [ffun a => w a / gamma w] ->
(forall (w' : weights) c cs',
let: w'' := update_weights w' c in
(forall a : A, `|c a| <= 1) ->
(forall a : A, 0 < w' a) ->
P cs' [ffun a => w' a / gamma w'] ->
P [:: c & cs'] [ffun a => w'' a / gamma w'']) ->
P cs (p_aux cs w).
Proof.
move=> H IH; elim: cs CMAX=> //.
move=> c cs'; rewrite /p_aux /=.
set w' := weights_of cs' w.
move=> H0 H1; apply: (IH w' c cs').
by apply: H1; rewrite /in_mem /=; apply/orP; left.
apply: weights_of_gt0=> // cx Hin a; apply: H1.
by rewrite /in_mem /=; apply/orP; right.
by apply: H0=> c0 H2 a; apply: H1; rewrite /in_mem /=; apply/orP; right.
Qed.
Lemma p_aux_dist_axiom (cs : seq costs) (w : weights) :
(forall a : A, 0 < w a) ->
(forall c, c \in cs -> forall a : A, `|c a| <= 1) ->
dist_axiom (p_aux cs w).
Proof.
move => Hx H0; rewrite /p_aux /dist_axiom; apply/andP; split.
{ have H:
\sum_(t : A)
[ffun a => (weights_of cs w) a /
gamma (weights_of cs w)] t
= \sum_(t : A)
(weights_of cs w) t /
gamma (weights_of cs w).
{ by apply/congr_big=> // i _; rewrite ffunE. }
rewrite H; move {H}.
rewrite gamma_normalizes=> //.
have H1: 0 < \sum_a (weights_of cs w) a.
{ apply: sum_weights_of_gt0 => //. }
by apply/eqP => H2; rewrite H2 in H1.
}
change [forall t, 0 <= p_aux cs w t].
apply (p_aux_ind H0 Hx).
{ apply/forallP=> x; rewrite ffunE.
apply: mulr_ge0; first by apply: ltrW; apply: Hx.
rewrite invr_ge0 /gamma /init_weights; apply/sumr_ge0=> i _.
by apply: ltrW; apply: Hx. }
move=> w' c cs' H1 H2 H3; apply/forallP=> x; rewrite ffunE.
have H4: forall a : A, 0 < update_weights w' c a.
{ move=> a; apply: update_weights_gt0=> //. }
apply: divr_ge0; first by apply/ltrW; apply: (H4 x).
by apply: gamma_ge0=> a; apply/ltrW.
Qed.
Lemma p_aux_left_dist_axiom (cs : seq costs) (w : weights) :
(forall a : A, 0 < w a) ->
(forall c, c \in cs -> forall a : A, `|c a| <= 1) ->
dist_axiom (p_aux_left cs w).
Proof.
move => H H2; rewrite /p_aux_left.
rewrite -weights_of_rightleft; apply: p_aux_dist_axiom => //.
move => c H3 a; apply: H2.
by rewrite mem_rev in H3.
Qed.
Definition p_aux_dist
(w : weights)
(WPOS : forall a : A, 0 < w a)
(cs : seq costs)
(CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1)
: dist A [numDomainType of rat] :=
mkDist (p_aux_dist_axiom WPOS CMAX).
Definition p_aux_left_dist
(w : weights)
(WPOS : forall a : A, 0 < w a)
(cs : seq costs)
(CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1)
: dist A [numDomainType of rat] :=
mkDist (p_aux_left_dist_axiom WPOS CMAX).
Definition p (cs : seq costs) : {ffun A -> rat} :=
p_aux cs init_weights.
Lemma p_dist_axiom (cs : seq costs) :
(forall c, c \in cs -> forall a : A, `|c a| <= 1) ->
dist_axiom (p cs).
Proof.
move => H; apply: p_aux_dist_axiom => //.
apply: init_weights_gt0.
Qed.
Delimit Scope R_scope with R.
Lemma rat_to_R_prod' (cs : seq costs) a :
rat_to_R (\prod_(c <- cs) (1 - eps * c a)) =
big_product cs (fun c => (rat_to_R 1 - rat_to_R eps * rat_to_R (c a)))%R.
Proof.
rewrite rat_to_R_prod; apply: big_product_ext=> // x.
by rewrite rat_to_R_plus rat_to_R_opp rat_to_R1 /Rminus rat_to_R_mul.
Qed.
Lemma exprDr_seq (r : rat) (cs : seq costs) (a : A) :
0 < r ->
Rpower (rat_to_R r) (rat_to_R (\sum_(c <- cs) c a)) =
big_product cs (fun c => Rpower (rat_to_R r) (rat_to_R (c a))).
Proof.
move=> H; elim: cs=> //=.
{ rewrite big_nil rat_to_R0 Rpower_O=> //.
have H2: (0 = rat_to_R 0)%R.
{ by rewrite /rat_to_R /Qreals.Q2R /= Rmult_0_l. }
rewrite H2.
by apply: rat_to_R_lt.
}
move=> a1 l IH; rewrite !big_cons.
rewrite -IH.
rewrite rat_to_R_plus.
by rewrite Rpower_plus.
Qed.
Lemma neps_gt0 : 0 < 1 - eps.
Proof.
rewrite subr_gt0.
have H3: (1/2%:R : rat) < 1.
{ by rewrite ltr_pdivr_mulr. }
have H4: eps <= 1 / 2%:R.
{ by case: (andP eps_range). }
by apply: (ler_lt_trans H4 H3).
Qed.
Lemma rat_to_R_eps_gt0 : (0 < rat_to_R eps)%R.
Proof.
case: (andP eps_range)=> H1 H2.
by rewrite -rat_to_R0; apply: rat_to_R_lt.
Qed.
Lemma rat_to_R_eps_pos : (0 <= rat_to_R eps)%R.
Proof.
by apply: Rlt_le; apply: rat_to_R_eps_gt0.
Qed.
Lemma rat_to_R_eps_neq0 : (rat_to_R eps <> 0)%R.
Proof.
move=> H; move: rat_to_R_eps_gt0; rewrite H.
apply: Rlt_irrefl.
Qed.
Lemma rat_to_R_eps_le_one_half : (rat_to_R eps <= 1/2)%R.
Proof.
case: (andP eps_range)=> H1 H2.
have H3: (1 / 2 = rat_to_R (1 / 2%:R))%R.
{ rewrite /Rdiv rat_to_R_mul rat_to_R1; f_equal.
rewrite rat_to_R_inv => //.
by rewrite rat_to_R2. }
by rewrite H3; apply: rat_to_R_le.
Qed.
Lemma rat_to_R_neps : rat_to_R (1 - eps) = (1 - rat_to_R eps)%R.
Proof. by rewrite rat_to_R_plus rat_to_R_opp rat_to_R1. Qed.
Lemma rat_to_R_neps_gt0 : (0 < rat_to_R (1 - eps))%R.
Proof. by rewrite -rat_to_R0; apply: rat_to_R_lt; apply: neps_gt0. Qed.
Lemma Rpower_pos x y : (0 < x -> 0 <= y -> 0 < Rpower x y)%R.
Proof.
rewrite /Rpower.
case: (Req_dec y 0%R).
{ move=> ->; rewrite Rmult_0_l exp_0.
by move=> _ _; lra. }
move=> H H2 H3.
apply: exp_pos.
Qed.
Lemma one_minus_pos x : (x <= 1 -> 0 <= 1 - x)%R.
Proof. move=> H; fourier. Qed.
Definition pdist
(cs : seq costs)
(CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1)
: dist A [numDomainType of rat] :=
mkDist (p_dist_axiom CMAX).
(** The expected cost of the MW algorithm after [length cs] timesteps *)
Definition expCost
(cT : costs)
(cs : seq costs)
(CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1)
: rat :=
expectedValue (pdist CMAX) cT.
(** The best fixed action wrt. cost functions [cs] *)
Definition best_action (cs : seq costs) : A :=
arg_min xpredT (fun a : A => \sum_(c <- cs) c a) a0.
(** Some general lemmas about logarithms
-- should be moved elsewhere *)
Lemma ln_le (x y : R) : (0 < x -> x <= y -> ln x <= ln y)%R.
Proof.
move=> H0; case=> H.
left; apply: ln_increasing=> //.
by right; subst x.
Qed.
(* The construction of the derivability proof is needed to apply
the compositional rules in the next two proofs *)
Definition aux_const x : derivable_pt (fun x => (exp x - (1%R +x))%R) x :=
derivable_pt_minus exp (Rplus 1%R) x (derivable_pt_exp x)
(derivable_pt_plus (fun _ : R => 1%R) id x (derivable_pt_const 1 x)
(derivable_pt_id x)).
Lemma aux_neg y (H :(y < 0)%R) :
(derive (fun x => (exp x - (1 + x))%R) aux_const y < 0)%R.
Proof.
rewrite /derive /aux_const
derive_pt_minus
derive_pt_exp
derive_pt_plus
derive_pt_const
derive_pt_id.
apply Rlt_minus.
rewrite -exp_0 Rplus_0_l.
apply exp_increasing => //.
Qed.
Lemma aux_pos y (H :(0 <= y)%R) :
(derive (fun x => (exp x - (1 + x))%R) aux_const y >= 0)%R.
Proof.
rewrite /derive /aux_const
derive_pt_minus
derive_pt_exp
derive_pt_plus
derive_pt_const
derive_pt_id.
apply Rge_minus.
rewrite -exp_0 Rplus_0_l.
apply Rle_ge.
case: H => H;
first by left; apply exp_increasing => //.
right. f_equal => //.
Qed.
Lemma ln_Taylor_upper' x : ((1 + x) <= exp x)%R.
Proof.
clear A a0 eps eps_range.
apply Rge_le.
apply Rminus_ge.
set f := fun x => (exp x - (1 + x))%R.
have H0 : (f x = exp x - (1 + x))%R => //.
rewrite -H0; clear H0.
have H0 : (f 0 = 0)%R by
rewrite /f exp_0 Rplus_0_r;
apply Rminus_diag_eq => //.
rewrite -H0.
case: (Rtotal_order x 0) => H.
{
left.
apply (MVT_cor1 f x 0 aux_const) in H.
case: H => c; case => H1 H2.
rewrite H0 !Rminus_0_l in H1.
rewrite H0.
have H3 : (x < 0)%R
by case: H2 => H2 H3; apply (Rlt_trans x c 0) => //.
apply Ropp_eq_compat in H1.
rewrite Ropp_involutive in H1.
rewrite H1.
apply Rlt_gt.
rewrite Ropp_mult_distr_l.
apply Rmult_lt_0_compat.
apply Ropp_0_gt_lt_contravar.
apply Rlt_gt.
apply aux_neg.
case: H2 => //.
fourier.
}
{
case: H => H;
first by subst; rewrite /f Rplus_0_r exp_0; right => //.
apply (MVT_cor1 f 0 x aux_const) in H.
case: H => c; case => H1 H2.
rewrite H0 !Rminus_0_r in H1.
rewrite H0.
have H3 : (0 < x)%R
by case: H2 => H2 H3; apply (Rlt_trans 0 c x) => //.
rewrite H1.
apply Rle_ge.
rewrite -(Rmult_0_l x).
apply Rmult_le_compat.
right => //.
left => //.
apply Rge_le.
apply aux_pos.
left. case: H2 => //.
right => //.
}
Qed.
Lemma ln_Taylor_upper x : (x < 1)%R -> (ln (1 - x) <= -x)%R.
Proof.
intros h.
rewrite /ln.
case_eq (Rlt_dec 0 (1-x)); move => h1 h2;
last by apply False_rec; apply h1; fourier.
rewrite /Rln => /=.
destruct (ln_exists (1 - x) h1) as [x0 e0].
apply Rplus_le_reg_l with (r := 1%R).
rewrite /Rminus in e0.
rewrite e0.
apply ln_Taylor_upper'.
Qed.
Lemma deriv_aux_lower :
derivable (fun x : R => ((1 - x) * exp (x + x ^ 2))%R).
Proof.
rewrite /derivable => x.
apply derivable_pt_mult.
apply derivable_pt_minus.
apply derivable_pt_const.
apply derivable_pt_id.
set f1 := fun x => (x + x ^2)%R.
set f2 := fun x => exp x.
have H : (fun x0 : R => exp (x0 + x0 ^ 2))
= Ranalysis1.comp f2 f1 => //.
rewrite H.
apply derivable_pt_comp.
rewrite /f1.
apply derivable_pt_plus.
apply derivable_pt_id.
apply derivable_pt_mult.
apply derivable_pt_id.
apply derivable_pt_mult.
apply derivable_pt_id.
apply derivable_pt_const.
apply derivable_pt_exp.
Defined.
Lemma ln_Taylor_lower_aux_lt_0 x (H : (x < 0)%R) :
(derive_pt (fun x : R => ((1 - x) * exp (x + x ^ 2))%R)
x (deriv_aux_lower x) < 0)%R.
Proof.
rewrite /deriv_aux_lower
derive_pt_mult
derive_pt_minus
derive_pt_const
derive_pt_id
(* Need to eliminate the substitution in the above proof *)
/ssr_have /eq_rec_r /eq_rec /eq_rect => /=.
rewrite derive_pt_comp
derive_pt_exp
derive_pt_plus
derive_pt_id
derive_pt_mult
derive_pt_id
derive_pt_mult
derive_pt_id
derive_pt_const.
ring_simplify.
set Y := exp (x + x * (x * 1)).
have H0 : (- 2* Y * x ^ 2 + Y * x = Y * ( x * (-2 * x + 1)))%R
by ring.
rewrite H0.
rewrite -(Rmult_0_r Y).
apply Rmult_lt_compat_l.
apply exp_pos.
rewrite -(Rmult_0_r x).
apply Rmult_lt_gt_compat_neg_l => //.
fourier.
Qed.
Lemma ln_Taylor_lower_aux_gt_0
x (H0 : (0 < x)%R) (H1 : (x <= 1/2)%R) :
(derive_pt (fun x : R => ((1 - x) * exp (x + x ^ 2))%R)
x (deriv_aux_lower x) >= 0)%R.
Proof.
rewrite /deriv_aux_lower
derive_pt_mult
derive_pt_minus
derive_pt_const
derive_pt_id
(* Need to eliminate the substitution in the above proof *)
/ssr_have /eq_rec_r /eq_rec /eq_rect => /=.
rewrite derive_pt_comp
derive_pt_exp
derive_pt_plus
derive_pt_id
derive_pt_mult
derive_pt_id
derive_pt_mult
derive_pt_id
derive_pt_const.
ring_simplify.
set Y := exp (x + x * (x * 1)).
have H2 : (- 2* Y * x ^ 2 + Y * x = Y * ( x * (-2 * x + 1)))%R
by ring.
rewrite H2.
rewrite -(Rmult_0_r Y).
apply Rmult_ge_compat_l.
left.
apply exp_pos.
rewrite -(Rmult_0_r x).
apply Rmult_ge_compat_l => //. fourier.
case: H1 => H1. fourier. subst. fourier.
Qed.
Lemma ln_Taylor_lower x : (x <= 1/2 -> -x - x^2 <= ln (1 - x))%R.
Proof.
intros H.
rewrite -[(-x - x^2)%R] ln_exp.
apply ln_le; first by apply exp_pos.
have h : ((- x - x ^2) = - (x + x^2))%R by field.
rewrite h. clear h.
apply (Rmult_le_reg_r (/exp (- (x + x ^ 2))));
first by apply Rinv_0_lt_compat; apply exp_pos.
rewrite Rinv_r;
last by move: (exp_pos (- (x + x ^ 2))%R) => H0 H1; fourier.
rewrite exp_Ropp Rinv_involutive;
last by move: (exp_pos (x + x^2)%R) => H0 H1; fourier.
set F := fun x => ((1 - x) * exp (x + x^2))%R.
have H0 : (F x = (1 - x) * exp (x + x ^ 2))%R => //.
rewrite -H0; clear H0.
have H1 : (F 0 = 1)%R. rewrite /F.
have H0 : (0 + 0^2 = 0)%R by ring.
rewrite H0; ring_simplify; apply exp_0; clear H0.
rewrite -H1.
apply Rminus_le.
case: (Rtotal_order 0 x) => H2; last case: H2 => H2.
{
move: (MVT_cor1 F 0 x deriv_aux_lower H2) => H3.
destruct H3 as [c [H3 [H4 H5]]].
have h : (F 0 - F x = - (F x - F 0))%R. ring.
rewrite h H3. apply Rge_le. clear h.
rewrite Rminus_0_r.
apply Ropp_0_le_ge_contravar.
apply Rmult_le_pos; last by fourier.
apply Rge_le.
apply ln_Taylor_lower_aux_gt_0 => //.
fourier.
}
{
right. subst. ring.
}
{
move: (MVT_cor1 F x 0 deriv_aux_lower H2) => H3.
destruct H3 as [c [H3 [H4 H5]]].
rewrite H3.
rewrite Rminus_0_l.
rewrite -(Rmult_0_r (derive_pt F c (deriv_aux_lower c))%R).
apply Rmult_le_compat_neg_l; last by fourier.
left.
apply ln_Taylor_lower_aux_lt_0 => //.
}
Qed.
Lemma exp_Taylor_lower x : (x <= 1/2 -> exp(-x - x^2) <= 1 - x)%R.
Proof.
move => H.
move: (ln_Taylor_lower H); case.
{ move => H2; left.
rewrite -[(1 - _)%R]exp_ln.
{ apply: exp_increasing.
apply: H2. }
fourier. }
move => ->; rewrite exp_ln; fourier.
Qed.
Lemma gamma0_sizeA : gamma init_weights = #|A|%:R.
Proof.
rewrite /gamma /init_weights sum_ffunE'.
have H: \sum_(t : A) (1%:R : rat) = (\sum_(t : A) 1%N)%:R.
{ by rewrite natr_sum. }
by rewrite H sum1_card.
Qed.
(** All nonempty subsequences of "cs" *)
Fixpoint subSeqs_of A (cs : seq A) : seq (seq A) :=
if cs is [:: c & cs'] then [:: cs & subSeqs_of cs']
else [::].
Lemma in_subSeqs_of (cs : seq costs) :
cs != [::] -> cs \in subSeqs_of cs.
Proof.
case: cs; first by [].
by move=> // a l H /=; rewrite in_cons; apply/orP; left.
Qed.
Lemma subSeqs_of_CMAX (cs : seq costs)
(CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1) :
forall cs', cs' \in subSeqs_of cs ->
forall c, c \in cs' -> forall a : A, `|c a| <= 1.
Proof.
elim: cs CMAX=> /=.
{ by move=> H cs'; rewrite in_nil. }
move=> a l IH H cs'; rewrite in_cons; case/orP.
{ move/eqP=> -> c; rewrite in_cons; case/orP.
{ by move/eqP=> -> a1; apply: H; apply/orP; left. }
by move=> H2; apply: H; apply/orP; right. }
move=> H2 c H3.
have H4: forall c, c \in l -> forall a, `|c a| <= 1.
{ by move=> c0 H4; apply: H; apply/orP; right. }
by apply: (IH H4 cs' H2).
Qed.
Lemma CMAX_nil :
forall c : costs, c \in [::] -> forall a : A, `|c a| <= 1.
Proof. by move=> c; rewrite in_nil. Qed.
Definition CMAXb (cs : seq costs) :=
all [pred c : costs | [forall a : A, `|c a| <= 1]] cs.
Lemma CMAXb_behead (cs : seq costs) :
CMAXb cs -> CMAXb (behead cs).
Proof. by move/allP=> H; apply/allP=> y/mem_behead H2; apply: H. Qed.
Lemma CMAXP (cs : seq costs) :
reflect (forall c, c \in cs -> forall a : A, `|c a| <= 1) (CMAXb cs).
Proof.
case H: (CMAXb cs).
{ apply: ReflectT=> c H2 a; rewrite /CMAXb in H; move: (allP H).
by move/(_ c)/(_ H2)=> /= => /forallP/(_ a). }
apply: ReflectF=> H2; rewrite /CMAXb in H; move: (negbT H).
move/allPn; case=> c H3; move/negP=> /=; apply; apply/forallP=> x.
by apply: H2.
Qed.
Lemma CMAXb_CMAX cs :
CMAXb cs ->
forall c, c \in cs -> forall a, `|c a| <= 1.
Proof. by apply/CMAXP. Qed.
Definition CMAX_costs_seq := {cs : seq costs | CMAXb cs}.
Definition CMAX_seq (cs' : seq (seq costs)) := all CMAXb cs'.
Program Fixpoint subSeqs_aux (cs' : seq (seq weights)) (CMAX : CMAX_seq cs')
: seq CMAX_costs_seq
:= (match cs' as cs'' return _ = cs'' -> seq CMAX_costs_seq with
| [::] => fun _ => [::]
| [:: cs'' & cs'_rest] => fun pf : cs' = cs'' :: cs'_rest => [:: exist _ cs'' _ & @subSeqs_aux cs'_rest _]
end) erefl.
Next Obligation. by case: (andP CMAX). Qed.
Next Obligation. by case: (andP CMAX). Qed.
Lemma CMAX_seq_subSeqs_of (cs : seq weights)
(CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1)
: CMAX_seq (subSeqs_of cs).
Proof.
elim: cs CMAX=> //= a l IH H; apply/andP; split.
apply/andP; split.
{ by apply/forallP; apply: H; rewrite in_cons; apply/orP; left. }
have H2: forall c, c \in l -> forall a, `|c a| <= 1.
{ by move=> c H2 a1; apply: H; rewrite in_cons; apply/orP; right. }
case H0: (l == [::]).
{ move: (eqP H0)=> -> //. }
{ by apply: (allP (IH H2)); apply: in_subSeqs_of; rewrite H0. }
by apply: IH=> c H2 a1; apply: H; rewrite in_cons; apply/orP; right.
Qed.
Definition subSeqs (cs : seq weights)
(CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1)
: seq CMAX_costs_seq
:= @subSeqs_aux (subSeqs_of cs) (CMAX_seq_subSeqs_of CMAX).
Lemma Rle_contra_tech x y z : (-x <= y + -z -> z <= y + x)%R.
Proof.
have ->: (y + -z = -(-y + z))%R.
{ by rewrite Ropp_plus_distr Ropp_involutive. }
move/Ropp_le_cancel/(Rplus_le_compat_r y).
have ->: (-y + z + y = z)%R.
{ by rewrite Rplus_comm -Rplus_assoc Rplus_opp_r Rplus_0_l. }
by rewrite Rplus_comm.
Qed.
Lemma pow_le1 x : (-1 <= x <= 1 -> x^2 <= 1)%R.
Proof.
case => H1 H2.
have ->: (1 = 1^2)%R by rewrite pow1.
case H3: (Rlt_dec x 0) => [pf|pf].
{ clear H2 H3.
rewrite /pow Rmult_1_r Rmult_1_l.
have H2: (x * x <= x * -1)%R.
{ apply: Rmult_le_compat_neg_l; try fourier. }
apply: Rle_trans; first by apply: H2.
fourier. }
apply pow_incr.
split => //.
by apply: Rnot_lt_le.
Qed.
Section R173_175_176_aux.
Variable cT : costs.
Variable cs : seq costs.
Notation cs' := ([:: cT & cs]).
Variable CMAX : forall c, c \in cs -> forall a : A, `|c a| <= 1.
Notation astar := (best_action cs).
Notation OPT := (\sum_(c <- cs) c astar).
Notation wT := (weights_of cs init_weights).
Notation gammaT := (gamma wT).
Notation pT := (pdist CMAX).
(** In expCostT, CMAX defines the distributed pT computed at time t.
cT is the cost function returned by the adversary, after pT has
been calculated. *)
Notation expCostT := (expCost cT CMAX).
Lemma gammaT_ge_wT_astar : wT astar <= gammaT.
Proof.
rewrite /gamma.
apply: weight1_sum_ler=> a.
apply/ltrW; apply: weights_of_gt0=> //.
apply: init_weights_gt0.
Qed.
Lemma wT_astar_eq :
rat_to_R (wT astar) =
big_product cs (fun c => (rat_to_R 1 - rat_to_R eps * rat_to_R (c astar)))%R.
Proof. by rewrite weights_of_eq ffunE rat_to_R_prod'. Qed.
Lemma rat_to_R_cost_pos a c : c \in cs -> (0 <= rat_to_R `|c a|)%R.
Proof.
rewrite -rat_to_R0=> H.
apply: rat_to_R_le.
by move: (normr_ge0 (c a)).
Qed.
Lemma rat_to_R_sumcost_pos a : (0 <= rat_to_R (\sum_(c <- cs) `|c a|))%R.
Proof.
move: rat_to_R_cost_pos; elim: cs.
{ move=> _; rewrite big_nil rat_to_R0; apply: Rle_refl. }
move=> c' l IH H; rewrite big_cons rat_to_R_plus.
apply: Rplus_le_le_0_compat.
by apply: H; apply/orP; left.
by apply: IH=> a1 c H2; apply: H; apply/orP; right.
Qed.
Lemma rat_to_R_cost_le1 a c : c \in cs -> (rat_to_R `|c a| <= 1)%R.
Proof.
rewrite -rat_to_R1=> H; move: (CMAX H a)=> H2.
by apply: rat_to_R_le.
Qed.
Lemma expCostT_eq :
expCostT = \sum_(a : A) (wT a / gammaT) * cT a.
Proof.
rewrite /expCost /expectedValue /expectedCondValue /pT /p /= /p_aux.
by apply: congr_big=> // i _; rewrite ffunE.
Qed.
(** R17.3: Gamma^{T+1} = gamma^T * (1 - eps * expCostT) *)
Lemma gammaT_Tprod1 :
gamma (weights_of cs' init_weights) = gammaT * (1 - eps * expCostT).
Proof.
rewrite expCostT_eq.
rewrite /weights_of -/weights_of /update_weights.
rewrite /gamma sum_ffunE'.
have H: \sum_t wT t * (1 - eps * cT t) =
\sum_t (wT t - wT t * eps * cT t).
{ apply: congr_big=> // x _; rewrite mulrDr.
by rewrite mulr1 -mulrA mulrN. }
rewrite H sumrB.
have H2: \sum_i wT i * eps * cT i =
eps * \sum_i wT i * cT i.
{ have H3: \sum_i wT i * eps * cT i = \sum_i eps * (wT i * cT i).
{ by apply: congr_big=> // i _; rewrite mulrA [wT i * _]mulrC. }
by rewrite H3 mulr_sumr. }
rewrite H2.
have H3: \sum_i wT i - eps * (\sum_i wT i * cT i) =
gammaT * (1 - eps * (\sum_i wT i * cT i) / gammaT).
{ rewrite mulrDr mulr1 [(eps * _) / _]mulrC mulrN mulrA mulfV.
{ by rewrite mul1r. }
by apply sum_weights_of_not0. }
rewrite H3.
rewrite /gammaT.
f_equal.
f_equal.
f_equal.
rewrite -mulrA; f_equal.
rewrite mulr_suml; apply: congr_big=> // i _.
by rewrite -mulrA [cT i / _]mulrC mulrA.
Qed.
Lemma gammaT_exp_neps :
(rat_to_R (gamma (weights_of cs' init_weights)) <=
rat_to_R (gammaT) * exp (- rat_to_R eps * rat_to_R expCostT))%R.
Proof.
rewrite gammaT_Tprod1 rat_to_R_mul.
apply: Rmult_le_compat_l.
{ rewrite -rat_to_R0; apply: rat_to_R_le.
apply: gamma_ge0; move => a; apply/ltrW.
apply: weights_of_gt0 => // a1; apply: init_weights_gt0. }
rewrite rat_to_R_plus rat_to_R1 rat_to_R_opp rat_to_R_mul.
rewrite Ropp_mult_distr_l.
apply: ln_Taylor_upper'.
Qed.
Lemma R175 :
(big_product cs
(fun c : costs => 1 - rat_to_R eps * (rat_to_R (c astar))) <=
rat_to_R gammaT)%R.
Proof.
have H: (Rle (big_product
cs
(fun c : costs => 1 - rat_to_R eps * (rat_to_R (c astar))))
(rat_to_R (wT astar)))%R.
{ rewrite wT_astar_eq rat_to_R1.
apply: Rle_refl. }
apply: Rle_trans; first by apply: H.
apply: rat_to_R_le.
apply: gammaT_ge_wT_astar => //.
Qed.
Lemma ler_contra (R : realFieldType) (x y : R) : ~~(x <= y) -> y < x.
Proof.
rewrite ler_eqVlt; move/negP.
case H: (x < y); first by rewrite orbC.
case H2: (x == y) => // _.
case H3: (y < x) => //.
have H4: x != y.
{ by apply/negP => H5; rewrite H5 in H2. }
by move: (ltr_total H4); rewrite H H3.
Qed.
Lemma eps_mult_cost_le12 a c (H : c \in cs) :
(rat_to_R eps * rat_to_R (c a) <= 1/2)%R.
Proof.
have ->: (1/2 = 1/2*1)%R by field.
case H2: (c a < 0).
{ have H3: (rat_to_R eps * rat_to_R (c a) <= 0)%R.
{ move: rat_to_R_eps_le_one_half => H3.
have H4: (rat_to_R (c a) < 0)%R.
{ clear - H2.
rewrite -rat_to_R0.
by apply: rat_to_R_lt. }
move: rat_to_R_eps_gt0 => H5.
clear - H4 H5; move: H4 H5.
move: (rat_to_R eps) => x; move: (rat_to_R (c a)) => y H1 H2.
have H3: (x * y <= y * 0)%R.
{ rewrite Rmult_comm.
by left; apply Rmult_lt_gt_compat_neg_l. }
apply: Rle_trans; first by apply: H3.
rewrite Rmult_0_r; apply: Rle_refl. }
apply: Rle_trans; first by apply: H3.
fourier. }
apply: Rmult_le_compat.
{ apply: rat_to_R_eps_pos. }
{ rewrite -rat_to_R0; apply: rat_to_R_le.
have H3: 0 <= c a.
{ clear - H2; rewrite ltr_def in H2.
move: H2; rewrite andb_false_iff; case.
{ rewrite /negb; case H: (0 == c a) => //.
by move: (eqP H) => <-. }
by move => H; apply: ltrW; apply: ler_contra; rewrite H. }
by []. }
{ apply: Rle_trans; first by apply: rat_to_R_eps_le_one_half.