Repository navigation
Expand file tree
/
Copy pathSubmission.lean
More file actions
1803 lines (1743 loc) · 89.8 KB
/
Copy pathSubmission.lean
File metadata and controls
1803 lines (1743 loc) · 89.8 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
import Submission.Library.Auto.ThreeStateChannelSpectrum
import Submission.Library.TheoremOS.Probability.TreeReconstruction
import Mathlib
namespace OAI
namespace ThreeState
abbrev Spin := Fin 3
def Admissible (lam : ℝ) : Prop := -(1 / 2 : ℝ) ≤ lam ∧ lam ≤ 1
noncomputable def channel (lam : ℝ) (i j : Spin) : ℝ :=
if i = j then (1 + 2 * lam) / 3 else (1 - lam) / 3
def Observation : ℕ → Type
| 0 => Spin
| n + 1 => Multiset (Observation n)
noncomputable def leafSum (phi : Spin → ℝ) : (n : ℕ) → Observation n → ℝ
| 0 => phi
| n + 1 => fun s => (s.map (leafSum phi n)).sum
theorem leafSum_zero (phi : Spin → ℝ) (i : Spin) :
leafSum phi 0 i = phi i := rfl
theorem leafSum_succ (phi : Spin → ℝ) (n : ℕ) (s : Multiset (Observation n)) :
leafSum phi (n + 1) s = (s.map (leafSum phi n)).sum := rfl
theorem channel_nonneg {lam : ℝ} (h : Admissible lam) (i j : Spin) :
0 ≤ channel lam i j := by
unfold channel
split_ifs
· dsimp [Admissible] at h
linarith [h.1]
· dsimp [Admissible] at h
linarith [h.2]
theorem channel_sum (lam : ℝ) (i : Spin) : ∑ j, channel lam i j = 1 := by
fin_cases i <;> simp [channel, Fin.sum_univ_succ] <;> ring
theorem channel_col_sum (lam : ℝ) (j : Spin) : ∑ i : Spin, channel lam i j = 1 := by
fin_cases j <;> simp [channel, Fin.sum_univ_succ] <;> ring
theorem channel_eigen (lam : ℝ) (phi : Spin → ℝ) (hphi : ∑ j : Spin, phi j = 0) :
∀ i : Spin, ∑ j : Spin, channel lam i j * phi j = lam * phi i := by
intro i
have hterm : ∀ j : Spin, channel lam i j * phi j =
(1 - lam) / 3 * phi j + (if i = j then lam * phi j else 0) := by
intro j
unfold channel
split_ifs <;> ring
calc ∑ j : Spin, channel lam i j * phi j
= ∑ j : Spin, ((1 - lam) / 3 * phi j + (if i = j then lam * phi j else 0)) :=
Finset.sum_congr rfl fun j _ => hterm j
_ = (1 - lam) / 3 * (∑ j : Spin, phi j)
+ ∑ j : Spin, (if i = j then lam * phi j else 0) := by
rw [Finset.sum_add_distrib, Finset.mul_sum]
_ = lam * phi i := by
rw [hphi, mul_zero, zero_add]
simp [Finset.sum_ite_eq]
noncomputable def channelPMF (lam : ℝ) (h : Admissible lam) (i : Spin) : PMF Spin :=
PMF.ofFintype (fun j => ENNReal.ofReal (channel lam i j)) (by
rw [← ENNReal.ofReal_sum_of_nonneg (fun j _ => channel_nonneg h i j)]
simp [channel_sum])
theorem toReal_channelPMF (lam : ℝ) (h : Admissible lam) (i j : Spin) :
(channelPMF lam h i j).toReal = channel lam i j := by
exact ENNReal.toReal_ofReal (channel_nonneg h i j)
noncomputable def iidList {α : Type*} (p : PMF α) : ℕ → PMF (List α)
| 0 => PMF.pure []
| n + 1 => p.bind fun a => (iidList p n).map (List.cons a)
noncomputable def observedLaw (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) :
(n : ℕ) → Spin → PMF (Observation n)
| 0, i => PMF.pure i
| n + 1, i => offspring.bind fun k =>
(iidList ((channelPMF lam h i).bind (observedLaw offspring lam h n)) k).map
(fun xs : List (Observation n) => (xs : Multiset (Observation n)))
noncomputable def uniformSpin : PMF Spin := PMF.ofFintype (fun _ => 1 / 3) (by
simp
exact ENNReal.mul_inv_cancel (by norm_num) (by finiteness))
noncomputable def marginal {α : Type*} (law : Spin → PMF α) : PMF α :=
uniformSpin.bind law
noncomputable def posterior {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : ℝ :=
if marginal law y = 0 then 1 / 3
else (law i y).toReal / (3 * (marginal law y).toReal)
noncomputable def advantage {α : Type*} (law : Spin → PMF α) : ℝ :=
∑' y, (marginal law y).toReal *
((∑ i : Spin, |posterior law y i - 1 / 3|) / 2)
noncomputable def regularLaw (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) :=
observedLaw (PMF.pure b) lam h n
noncomputable def poissonOffspring (d : ℝ) (hd : 0 ≤ d) : PMF ℕ := by
refine ⟨fun k => ENNReal.ofReal (Real.exp (-d) * d ^ k / (k.factorial : ℝ)), ?_⟩
apply ENNReal.hasSum_coe.2
have hsum : HasSum (fun k : ℕ => Real.exp (-d) * d ^ k / (k.factorial : ℝ)) 1 :=
ProbabilityTheory.hasSum_one_poissonMeasure ⟨d, hd⟩
simpa using hsum.toNNReal (fun k => by positivity)
noncomputable def poissonLaw (d : ℝ) (hd : 0 ≤ d) (lam : ℝ)
(h : Admissible lam) (n : ℕ) :=
observedLaw (poissonOffspring d hd) lam h n
noncomputable def regularAdvantage (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) : ℝ :=
advantage (regularLaw b lam h n)
noncomputable def poissonAdvantage (d : ℝ) (hd : 1 < d) (lam : ℝ)
(h : Admissible lam) (n : ℕ) : ℝ :=
advantage (poissonLaw d (le_trans (by norm_num) hd.le) lam h n)
def Reconstructs (a : ℕ → ℝ) : Prop :=
∃ L : ℝ, 0 < L ∧ Filter.Tendsto a Filter.atTop (nhds L)
theorem isBroadcastLaw_observedLaw (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) :
TheoremOS.Probability.IsBroadcastLaw (channelPMF lam h) offspring (fun i : Spin => i)
(fun _ s => s) (observedLaw offspring lam h) := by
refine ⟨fun i => rfl, fun n i => ?_⟩
simp only [observedLaw]
rw [TheoremOS.Probability.iidList_eq_of_rec iidList (fun _ => rfl) (fun _ _ => rfl)]
theorem observedLaw_isBroadcastLaw (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) :
TheoremOS.Probability.IsBroadcastLaw (channelPMF lam h) offspring (fun i : Spin => i)
(fun _ s => s) (observedLaw offspring lam h) :=
isBroadcastLaw_observedLaw offspring lam h
theorem uniformSpin_apply (i : Spin) :
uniformSpin i = (Fintype.card Spin : ENNReal)⁻¹ := by
simp [uniformSpin, Fintype.card_fin]
theorem advantage_eq_reconAdvantage {α : Type*} (law : Spin → PMF α) :
advantage law = TheoremOS.Probability.reconAdvantage law := by
have hmix : marginal law = TheoremOS.Probability.pmfMixture law := by
simp only [marginal]
exact TheoremOS.Probability.bind_eq_pmfMixture uniformSpin uniformSpin_apply law
unfold advantage posterior
rw [hmix]
exact TheoremOS.Probability.tsum_mul_posterior_ite_eq_reconAdvantage law (1 / 3) (by norm_num)
noncomputable def census : (n : ℕ) → Observation n → ENNReal
| 0 => fun i => if (show Spin from i) = (1 : Spin) then 1 else 0
| n + 1 => fun s => (s.map (census n)).sum
theorem census_succ (n : ℕ) (s : Multiset (Observation n)) :
census (n + 1) s = (s.map (census n)).sum := rfl
noncomputable def eSpin : Spin → ℝ :=
fun i => (if i = (1 : Spin) then (1 : ℝ) else 0) - 1 / 3
theorem indicator_eq_eSpin (i : Spin) :
(if i = (1 : Spin) then (1 : ℝ) else 0) = 1 / 3 + eSpin i := by
unfold eSpin; ring
theorem channel_mul_eSpin (lam : ℝ) (i : Spin) :
∑ j, channel lam i j * eSpin j = lam * eSpin i := by
fin_cases i <;> (simp [channel, eSpin, Fin.sum_univ_three]; ring)
theorem sum_eSpin : ∑ i, eSpin i = 0 := by
simp [eSpin, Fin.sum_univ_three]
theorem eSpin_one_sub_zero : eSpin (1 : Spin) - eSpin (0 : Spin) = 1 := by
simp [eSpin]
theorem eSpin_sq_le (i : Spin) : eSpin i ^ 2 ≤ (4 : ℝ) / 9 := by
fin_cases i <;> norm_num [eSpin]
noncomputable def regM (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : ENNReal :=
∑' o : Observation n, regularLaw b lam h n i o * census n o
noncomputable def regA (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : ENNReal :=
∑' o : Observation n, regularLaw b lam h n i o * (census n o * census n o)
theorem channelPMF_tsum (lam : ℝ) (h : Admissible lam) (i : Spin) :
(∑ j : Spin, channelPMF lam h i j) = 1 := by
rw [← tsum_fintype (L := SummationFilter.unconditional Spin)]
simpa using (channelPMF lam h i).tsum_coe
theorem regM_zero (b : ℕ) (lam : ℝ) (h : Admissible lam) (i : Spin) :
regM b lam h 0 i = (if i = (1 : Spin) then (1 : ENNReal) else 0) := by
unfold regM regularLaw observedLaw
change (∑' o : Spin, (PMF.pure i : PMF Spin) o * census 0 o) = _
rw [tsum_eq_single i]
· rw [PMF.pure_apply_self]
simp [census]
· intro o ho
rw [PMF.pure_apply, if_neg ho]
simp
theorem regM_rec (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
regM b lam h (n + 1) i =
(b : ENNReal) * ∑ j : Spin, channelPMF lam h i j * regM b lam h n j := by
unfold regM
have hb := (isBroadcastLaw_observedLaw (PMF.pure b) lam h).tsum_mul_census
(O := Observation) (K := channelPMF lam h) (N := PMF.pure b)
(leaf := fun i : Spin => i) (up := fun _ s => s)
(law := observedLaw (PMF.pure b) lam h) census (fun n s => census_succ n s) n i
simpa [regularLaw, TheoremOS.Probability.tsum_pure_mul_natCast] using hb
theorem regM_bound (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
regM b lam h n i ≤ (b ^ n : ENNReal) := by
induction n generalizing i with
| zero =>
rw [regM_zero]
split_ifs <;> simp
| succ n ih =>
rw [regM_rec]
calc
(b : ENNReal) * ∑ j : Spin, channelPMF lam h i j * regM b lam h n j
≤ (b : ENNReal) * ∑ j : Spin, channelPMF lam h i j * (b ^ n : ENNReal) := by
gcongr with j
exact ih j
_ = (b : ENNReal) * ((b ^ n : ENNReal) * ∑ j : Spin, channelPMF lam h i j) := by
congr 1
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro j _
ring
_ = (b ^ (n + 1) : ENNReal) := by
rw [channelPMF_tsum, mul_one, pow_succ]
ring
theorem regM_ne_top (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
regM b lam h n i ≠ ⊤ :=
ne_top_of_le_ne_top (by simpa [Nat.cast_pow] using ENNReal.natCast_ne_top (b ^ n))
(regM_bound b lam h n i)
theorem regA_rec (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
regA b lam h (n + 1) i =
(b : ENNReal) * ∑ j : Spin, channelPMF lam h i j * regA b lam h n j +
((b * (b - 1) : ℕ) : ENNReal) *
((∑ j : Spin, channelPMF lam h i j * regM b lam h n j) *
(∑ j : Spin, channelPMF lam h i j * regM b lam h n j)) := by
unfold regA regM
have hb := (isBroadcastLaw_observedLaw (PMF.pure b) lam h).tsum_mul_census_mul_census
(O := Observation) (K := channelPMF lam h) (N := PMF.pure b)
(leaf := fun i : Spin => i) (up := fun _ s => s)
(law := observedLaw (PMF.pure b) lam h) census census
(fun n s => census_succ n s) (fun n s => census_succ n s) n i
simpa [regularLaw, TheoremOS.Probability.tsum_pure_mul_natCast] using hb
theorem regA_zero (b : ℕ) (lam : ℝ) (h : Admissible lam) (i : Spin) :
regA b lam h 0 i = (if i = (1 : Spin) then (1 : ENNReal) else 0) := by
unfold regA regularLaw observedLaw
change (∑' o : Spin, (PMF.pure i : PMF Spin) o * (census 0 o * census 0 o)) = _
rw [tsum_eq_single i]
· rw [PMF.pure_apply_self]
simp [census]
· intro o ho
rw [PMF.pure_apply, if_neg ho]
simp
theorem regA_ne_top (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
regA b lam h n i ≠ ⊤ := by
induction n generalizing i with
| zero =>
rw [regA_zero]
split_ifs <;> simp
| succ n ih =>
rw [regA_rec]
apply ENNReal.add_ne_top.2
refine ⟨ENNReal.mul_ne_top (ENNReal.natCast_ne_top _) ?_,
ENNReal.mul_ne_top (ENNReal.natCast_ne_top _) ?_⟩
· rw [ENNReal.sum_ne_top]
intro j _
exact ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (ih j)
· exact ENNReal.mul_ne_top
(ENNReal.sum_ne_top.2 fun j _ => ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (regM_ne_top b lam h n j))
(ENNReal.sum_ne_top.2 fun j _ => ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (regM_ne_top b lam h n j))
theorem regM_toReal_rec (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
(regM b lam h (n + 1) i).toReal =
(b : ℝ) * ∑ j : Spin, channel lam i j * (regM b lam h n j).toReal := by
rw [regM_rec, ENNReal.toReal_mul, ENNReal.toReal_natCast]
congr 1
rw [ENNReal.toReal_sum]
· apply Finset.sum_congr rfl
intro j _
rw [ENNReal.toReal_mul, toReal_channelPMF]
· intro j _
exact ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (regM_ne_top b lam h n j)
theorem regM_formula (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
(regM b lam h n i).toReal = (b : ℝ) ^ n * (1 / 3 + lam ^ n * eSpin i) := by
induction n generalizing i with
| zero =>
rw [regM_zero]
split_ifs with hi
· subst hi
simp [eSpin]
· simp [eSpin, hi]
| succ n ih =>
rw [regM_toReal_rec]
calc
(b : ℝ) * ∑ j : Spin, channel lam i j * (regM b lam h n j).toReal
= (b : ℝ) * ∑ j : Spin, channel lam i j *
((b : ℝ) ^ n * (1 / 3 + lam ^ n * eSpin j)) := by
congr 1
apply Finset.sum_congr rfl
intro j _
rw [ih j]
_ = (b : ℝ) ^ (n + 1) * (1 / 3 + lam ^ (n + 1) * eSpin i) := by
have h1 : (∑ j : Spin, channel lam i j * (1 / 3 : ℝ)) = 1 / 3 := by
have := channel_sum lam i
calc ∑ j : Spin, channel lam i j * (1 / 3 : ℝ)
= (∑ j : Spin, channel lam i j) * (1 / 3) := by rw [Finset.sum_mul]
_ = 1 / 3 := by rw [this]; ring
have h2 : (∑ j : Spin, channel lam i j * eSpin j) = lam * eSpin i :=
channel_mul_eSpin lam i
have h3 : (∑ j : Spin, channel lam i j * (lam ^ n * eSpin j)) =
lam ^ n * (lam * eSpin i) := by
calc ∑ j : Spin, channel lam i j * (lam ^ n * eSpin j)
= ∑ j : Spin, lam ^ n * (channel lam i j * eSpin j) := by
apply Finset.sum_congr rfl
intro j _; ring
_ = lam ^ n * ∑ j : Spin, channel lam i j * eSpin j := by
rw [Finset.mul_sum]
_ = lam ^ n * (lam * eSpin i) := by rw [h2]
have hsum : (∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j)) =
(1 / 3 + lam ^ n * (lam * eSpin i)) := by
rw [show (∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j)) =
∑ j : Spin, (channel lam i j * (1 / 3 : ℝ) + channel lam i j * (lam ^ n * eSpin j)) by
apply Finset.sum_congr rfl
intro j _; ring]
rw [Finset.sum_add_distrib, h1, h3]
calc
(b : ℝ) * ∑ j : Spin, channel lam i j *
((b : ℝ) ^ n * (1 / 3 + lam ^ n * eSpin j))
= (b : ℝ) * ((b : ℝ) ^ n *
∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j)) := by
congr 1
calc ∑ j : Spin, channel lam i j *
((b : ℝ) ^ n * (1 / 3 + lam ^ n * eSpin j))
= ∑ j : Spin, (b : ℝ) ^ n *
(channel lam i j * (1 / 3 + lam ^ n * eSpin j)) := by
apply Finset.sum_congr rfl
intro j _; ring
_ = (b : ℝ) ^ n *
∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j) := by
rw [Finset.mul_sum]
_ = (b : ℝ) ^ (n + 1) * (1 / 3 + lam ^ (n + 1) * eSpin i) := by
rw [hsum, pow_succ]
ring
noncomputable def regC (b : ℕ) (n : ℕ) : ℝ := (b : ℝ) ^ n / 3
noncomputable def regW (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : ℝ :=
∑' o : Observation n,
(regularLaw b lam h n i o).toReal * ((census n o).toReal - regC b n) ^ 2
theorem regA_toReal_rec (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
(regA b lam h (n + 1) i).toReal =
(b : ℝ) * ∑ j : Spin, channel lam i j * (regA b lam h n j).toReal +
((b * (b - 1) : ℕ) : ℝ) *
((∑ j : Spin, channel lam i j * (regM b lam h n j).toReal) ^ 2) := by
rw [regA_rec]
rw [ENNReal.toReal_add]
· rw [ENNReal.toReal_mul, ENNReal.toReal_natCast]
have hA : ((∑ x : Spin, (channelPMF lam h i) x * regA b lam h n x).toReal) =
∑ x : Spin, channel lam i x * (regA b lam h n x).toReal := by
rw [ENNReal.toReal_sum]
· apply Finset.sum_congr rfl
intro j _
rw [ENNReal.toReal_mul, toReal_channelPMF]
· intro j _
exact ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (regA_ne_top b lam h n j)
rw [hA, ENNReal.toReal_mul]
congr 1
have hM : ((∑ x : Spin, (channelPMF lam h i) x * regM b lam h n x).toReal) =
∑ x : Spin, channel lam i x * (regM b lam h n x).toReal := by
rw [ENNReal.toReal_sum]
· apply Finset.sum_congr rfl
intro j _
rw [ENNReal.toReal_mul, toReal_channelPMF]
· intro j _
exact ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (regM_ne_top b lam h n j)
simp only [ENNReal.toReal_mul, ENNReal.toReal_natCast, hM]
ring
· exact ENNReal.mul_ne_top (ENNReal.natCast_ne_top _)
(ENNReal.sum_ne_top.2 fun j _ => ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (regA_ne_top b lam h n j))
· exact ENNReal.mul_ne_top (ENNReal.natCast_ne_top _)
(ENNReal.mul_ne_top
(ENNReal.sum_ne_top.2 fun j _ => ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (regM_ne_top b lam h n j))
(ENNReal.sum_ne_top.2 fun j _ => ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (regM_ne_top b lam h n j)))
theorem regW_eq (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
regW b lam h n i = (regA b lam h n i).toReal -
2 * regC b n * (regM b lam h n i).toReal + (regC b n) ^ 2 := by
unfold regW regA regM
have hA : (∑' o : Observation n, (regularLaw b lam h n i o).toReal * (census n o).toReal ^ 2) =
(∑' o : Observation n, regularLaw b lam h n i o * (census n o * census n o)).toReal := by
rw [show (∑' o : Observation n, ((regularLaw b lam h n i) o).toReal * (census n o).toReal ^ 2)
= ∑' o : Observation n, ((regularLaw b lam h n i) o).toReal *
((census n o * census n o).toReal) by
apply tsum_congr
intro o
rw [pow_two, ENNReal.toReal_mul]]
rw [TheoremOS.Probability.tsum_toReal_mul_toReal (regularLaw b lam h n i)
(fun o => census n o * census n o) (by simpa [regA] using regA_ne_top b lam h n i)]
have hM : (∑' o : Observation n, (regularLaw b lam h n i o).toReal * (census n o).toReal) =
(∑' o : Observation n, regularLaw b lam h n i o * census n o).toReal := by
rw [TheoremOS.Probability.tsum_toReal_mul_toReal (regularLaw b lam h n i)
(fun o => census n o) (by simpa [regM] using regM_ne_top b lam h n i)]
rw [TheoremOS.Probability.tsum_mul_sub_sq]
· rw [hA, hM]
· exact by
simpa [pow_two] using
(TheoremOS.Probability.summable_toReal_mul_toReal (regularLaw b lam h n i)
(fun o => census n o * census n o)
(by simpa [regA] using regA_ne_top b lam h n i))
theorem regM_center (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
(∑ j : Spin, channel lam i j * (regM b lam h n j).toReal) - regC b n =
(b : ℝ) ^ n * lam ^ (n + 1) * eSpin i := by
have hsum : (∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j)) =
1 / 3 + lam ^ (n + 1) * eSpin i := by
have h1 : (∑ j : Spin, channel lam i j * (1 / 3 : ℝ)) = 1 / 3 := by
have := channel_sum lam i
calc ∑ j : Spin, channel lam i j * (1 / 3 : ℝ)
= (∑ j : Spin, channel lam i j) * (1 / 3) := by rw [Finset.sum_mul]
_ = 1 / 3 := by rw [this]; ring
have h3 : (∑ j : Spin, channel lam i j * (lam ^ n * eSpin j)) =
lam ^ n * (lam * eSpin i) := by
calc ∑ j : Spin, channel lam i j * (lam ^ n * eSpin j)
= ∑ j : Spin, lam ^ n * (channel lam i j * eSpin j) := by
apply Finset.sum_congr rfl
intro j _; ring
_ = lam ^ n * ∑ j : Spin, channel lam i j * eSpin j := by
rw [Finset.mul_sum]
_ = lam ^ n * (lam * eSpin i) := by rw [channel_mul_eSpin]
rw [show (∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j)) =
∑ j : Spin, (channel lam i j * (1 / 3 : ℝ) + channel lam i j * (lam ^ n * eSpin j)) by
apply Finset.sum_congr rfl
intro j _; ring]
rw [Finset.sum_add_distrib, h1, h3]
rw [pow_succ]
ring
have hfactor : (∑ j : Spin, channel lam i j *
((b : ℝ) ^ n * (1 / 3 + lam ^ n * eSpin j))) =
(b : ℝ) ^ n * ∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j) := by
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro j _; ring
calc
(∑ j : Spin, channel lam i j * (regM b lam h n j).toReal) - regC b n
= (∑ j : Spin, channel lam i j *
((b : ℝ) ^ n * (1 / 3 + lam ^ n * eSpin j))) - (b : ℝ) ^ n / 3 := by
rw [regC]
congr 1
apply Finset.sum_congr rfl
intro j _
rw [regM_formula]
_ = (b : ℝ) ^ n * (1 / 3 + lam ^ (n + 1) * eSpin i) - (b : ℝ) ^ n / 3 := by
rw [hfactor, hsum]
_ = (b : ℝ) ^ n * lam ^ (n + 1) * eSpin i := by ring
theorem regW_rec (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
regW b lam h (n + 1) i =
(b : ℝ) * (∑ j : Spin, channel lam i j * regW b lam h n j) +
((b * (b - 1) : ℕ) : ℝ) *
(((b : ℝ) ^ n * lam ^ (n + 1) * eSpin i) ^ 2) := by
have hB : ((b * (b - 1) : ℕ) : ℝ) = (b : ℝ) * ((b : ℝ) - 1) := by
rw [Nat.cast_mul, Nat.cast_sub (by omega : 1 ≤ b)]
norm_num
have hsumW : (∑ j : Spin, channel lam i j * regW b lam h n j) =
(∑ j : Spin, channel lam i j * (regA b lam h n j).toReal) -
2 * regC b n * (∑ j : Spin, channel lam i j * (regM b lam h n j).toReal) +
(regC b n) ^ 2 := by
calc
(∑ j : Spin, channel lam i j * regW b lam h n j)
= ∑ j : Spin, channel lam i j *
((regA b lam h n j).toReal - 2 * regC b n * (regM b lam h n j).toReal +
(regC b n) ^ 2) := by
apply Finset.sum_congr rfl
intro j _
rw [regW_eq]
_ = (∑ j : Spin, channel lam i j * (regA b lam h n j).toReal) -
2 * regC b n * (∑ j : Spin, channel lam i j * (regM b lam h n j).toReal) +
(regC b n) ^ 2 := by
rw [show (∑ j : Spin, channel lam i j *
((regA b lam h n j).toReal - 2 * regC b n * (regM b lam h n j).toReal +
(regC b n) ^ 2)) =
∑ j : Spin, (channel lam i j * (regA b lam h n j).toReal -
2 * regC b n * (channel lam i j * (regM b lam h n j).toReal) +
channel lam i j * (regC b n) ^ 2) by
apply Finset.sum_congr rfl
intro j _; ring]
rw [Finset.sum_add_distrib, Finset.sum_sub_distrib]
rw [show (∑ x, 2 * regC b n * (channel lam i x * (regM b lam h n x).toReal)) =
2 * regC b n * ∑ x, channel lam i x * (regM b lam h n x).toReal by
rw [Finset.mul_sum]]
rw [show (∑ x, channel lam i x * regC b n ^ 2) = regC b n ^ 2 by
rw [← Finset.sum_mul, channel_sum]
ring]
rw [regW_eq b lam h (n + 1) i, regA_toReal_rec, regM_toReal_rec, hsumW]
have hc : regC b (n + 1) = (b : ℝ) * regC b n := by
rw [regC, regC, pow_succ]; ring
rw [hc]
set X := ∑ j : Spin, channel lam i j * (regM b lam h n j).toReal
have hcenter := regM_center b lam h n i
rw [← hcenter]
rw [hB]
ring
theorem regW_zero (b : ℕ) (lam : ℝ) (h : Admissible lam) (i : Spin) :
regW b lam h 0 i = eSpin i ^ 2 := by
unfold regW regularLaw observedLaw regC
simp only [pow_zero, Nat.cast_one]
change (∑' o : Spin, ((PMF.pure i : PMF Spin) o).toReal *
((census 0 o).toReal - (1 : ℝ) / 3) ^ 2) = eSpin i ^ 2
rw [tsum_eq_single i]
· rw [PMF.pure_apply_self]
by_cases hi : i = (1 : Spin)
· simp [census, eSpin, hi]
· simp [census, eSpin, hi]
· intro o ho
rw [PMF.pure_apply, if_neg ho]
simp
theorem regW_bound (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam)
(hcrit : 1 < (b : ℝ) * lam ^ 2) (n : ℕ) (i : Spin) :
regW b lam h n i ≤
(4 * ((b : ℝ) * lam ^ 2) / (9 * ((b : ℝ) * lam ^ 2 - 1))) *
((((b : ℝ) * lam) ^ 2) ^ n) := by
set r : ℝ := (b : ℝ) * lam ^ 2 with hr
set s : ℝ := ((b : ℝ) * lam) ^ 2 with hs
set Q : ℝ := 4 * r / (9 * (r - 1)) with hQ
have hr1 : 1 < r := hcrit
have hr0 : 0 < r := lt_trans zero_lt_one hr1
have hrm1 : 0 < r - 1 := by linarith
have hs0 : 0 ≤ s := sq_nonneg _
have hs_eq : s = (b : ℝ) * r := by rw [hs, hr]; ring
have hQpos : 0 < Q := by rw [hQ]; positivity
have hQbase : (4 : ℝ) / 9 ≤ Q := by
rw [hQ]
have hfrac : (1 : ℝ) ≤ r / (r - 1) := by
rw [le_div_iff₀ hrm1]
linarith
calc (4 : ℝ) / 9 = (4 / 9) * 1 := by ring
_ ≤ (4 / 9) * (r / (r - 1)) := by gcongr
_ = 4 * r / (9 * (r - 1)) := by field_simp
have hB : ((b * (b - 1) : ℕ) : ℝ) = (b : ℝ) * ((b : ℝ) - 1) := by
rw [Nat.cast_mul, Nat.cast_sub (by omega : 1 ≤ b)]
norm_num
induction n generalizing i with
| zero =>
rw [regW_zero, pow_zero, mul_one]
exact (eSpin_sq_le i).trans hQbase
| succ n ih =>
rw [regW_rec b hb lam h n i]
have hSum : (∑ j : Spin, channel lam i j * regW b lam h n j) ≤ Q * s ^ n := by
calc
(∑ j : Spin, channel lam i j * regW b lam h n j)
≤ ∑ j : Spin, channel lam i j * (Q * s ^ n) := by
apply Finset.sum_le_sum
intro j _
exact mul_le_mul_of_nonneg_left (ih j) (channel_nonneg h i j)
_ = Q * s ^ n := by
rw [← Finset.sum_mul, channel_sum]
ring
have hterm : (((b : ℝ) ^ n * lam ^ (n + 1) * eSpin i) ^ 2) ≤
s ^ n * lam ^ 2 * ((4 : ℝ) / 9) := by
have hbase : ((b : ℝ) ^ n * lam ^ (n + 1)) ^ 2 = s ^ n * lam ^ 2 := by
have hbl : (b : ℝ) ^ n * lam ^ (n + 1) = ((b : ℝ) * lam) ^ n * lam := by
rw [mul_pow, pow_succ]
ring
rw [hbl, mul_pow, hs, pow_right_comm]
calc
(((b : ℝ) ^ n * lam ^ (n + 1) * eSpin i) ^ 2)
= ((b : ℝ) ^ n * lam ^ (n + 1)) ^ 2 * eSpin i ^ 2 := by ring
_ = (s ^ n * lam ^ 2) * eSpin i ^ 2 := by rw [hbase]
_ ≤ (s ^ n * lam ^ 2) * ((4 : ℝ) / 9) := by
gcongr
exact eSpin_sq_le i
_ = s ^ n * lam ^ 2 * ((4 : ℝ) / 9) := by ring
calc
(b : ℝ) * (∑ j : Spin, channel lam i j * regW b lam h n j) +
((b * (b - 1) : ℕ) : ℝ) *
(((b : ℝ) ^ n * lam ^ (n + 1) * eSpin i) ^ 2)
≤ (b : ℝ) * (Q * s ^ n) +
((b * (b - 1) : ℕ) : ℝ) * (s ^ n * lam ^ 2 * ((4 : ℝ) / 9)) := by
gcongr
_ = ((b : ℝ) * Q + ((b * (b - 1) : ℕ) : ℝ) * lam ^ 2 * ((4 : ℝ) / 9)) * s ^ n := by
ring
_ ≤ Q * s ^ (n + 1) := by
rw [pow_succ]
have hcoef : (b : ℝ) * Q +
((b * (b - 1) : ℕ) : ℝ) * lam ^ 2 * (4 / 9) ≤ Q * s := by
rw [hB]
rw [hs_eq, hQ]
have hb1 : (0 : ℝ) ≤ (b : ℝ) - 1 := by
have : (1 : ℝ) ≤ b := by exact_mod_cast (by omega : 1 ≤ b)
linarith
have hlam : ((b : ℝ) - 1) * lam ^ 2 ≤ r := by
rw [hr]
nlinarith [sq_nonneg lam]
have hcoef0 : (b : ℝ) * (4 * r / (9 * (r - 1))) +
(b : ℝ) * ((b : ℝ) - 1) * lam ^ 2 * (4 / 9) ≤
(4 * r / (9 * (r - 1))) * ((b : ℝ) * r) := by
field_simp [hrm1.ne']
nlinarith [hlam, hr0, hrm1]
simpa [mul_assoc, mul_left_comm, mul_comm] using hcoef0
calc
((b : ℝ) * Q + ((b * (b - 1) : ℕ) : ℝ) * lam ^ 2 * ((4 : ℝ) / 9)) * s ^ n
≤ (Q * s) * s ^ n := mul_le_mul_of_nonneg_right hcoef (pow_nonneg hs0 n)
_ = Q * s ^ (n + 1) := by ring
theorem poisson_mean (d : ℝ) (hd : 0 ≤ d) :
(∑' k : ℕ, poissonOffspring d hd k * ((k : ℕ) : ENNReal)) = ENNReal.ofReal d := by
have h := TheoremOS.Probability.tsum_ofReal_poissonWeight_mul (d := d) hd
have hfun : (fun k : ℕ => poissonOffspring d hd k * ((k : ℕ) : ENNReal)) =
fun k : ℕ => ENNReal.ofReal (Real.exp (-d) * d ^ k / (k.factorial : ℝ)) * ((k : ℕ) : ENNReal) := by
funext k; rfl
rw [hfun]; exact h
noncomputable def poisM (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam)
(n : ℕ) (i : Spin) : ENNReal :=
∑' o : Observation n, poissonLaw d hd lam h n i o * census n o
theorem poisM_zero (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (i : Spin) :
poisM d hd lam h 0 i = (if i = (1 : Spin) then (1 : ENNReal) else 0) := by
unfold poisM poissonLaw observedLaw
change (∑' o : Spin, (PMF.pure i : PMF Spin) o * census 0 o) = _
rw [tsum_eq_single i]
· rw [PMF.pure_apply_self]
simp [census]
· intro o ho
rw [PMF.pure_apply, if_neg ho]
simp
theorem poisM_rec (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
poisM d hd lam h (n + 1) i =
ENNReal.ofReal d * ∑ j : Spin, channelPMF lam h i j * poisM d hd lam h n j := by
unfold poisM
have hb := (isBroadcastLaw_observedLaw (poissonOffspring d hd) lam h).tsum_mul_census
(O := Observation) (K := channelPMF lam h) (N := poissonOffspring d hd)
(leaf := fun i : Spin => i) (up := fun _ s => s)
(law := observedLaw (poissonOffspring d hd) lam h) census (fun n s => census_succ n s) n i
rw [poisson_mean d hd] at hb
simpa [poissonLaw] using hb
theorem poisM_bound (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
poisM d hd lam h n i ≤ (ENNReal.ofReal d) ^ n := by
induction n generalizing i with
| zero =>
rw [poisM_zero]
split_ifs <;> simp
| succ n ih =>
rw [poisM_rec]
calc
ENNReal.ofReal d * ∑ j : Spin, channelPMF lam h i j * poisM d hd lam h n j
≤ ENNReal.ofReal d * ∑ j : Spin, channelPMF lam h i j * (ENNReal.ofReal d) ^ n := by
gcongr with j
exact ih j
_ = ENNReal.ofReal d * ((ENNReal.ofReal d) ^ n * ∑ j : Spin, channelPMF lam h i j) := by
congr 1
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro j _
ring
_ = (ENNReal.ofReal d) ^ (n + 1) := by
rw [channelPMF_tsum, mul_one, pow_succ]
ring
theorem poisM_ne_top (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
poisM d hd lam h n i ≠ ⊤ :=
ne_top_of_le_ne_top (ENNReal.pow_ne_top ENNReal.ofReal_ne_top) (poisM_bound d hd lam h n i)
theorem poisM_toReal_rec (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
(poisM d hd lam h (n + 1) i).toReal =
d * ∑ j : Spin, channel lam i j * (poisM d hd lam h n j).toReal := by
rw [poisM_rec, ENNReal.toReal_mul, ENNReal.toReal_ofReal hd]
congr 1
rw [ENNReal.toReal_sum]
· apply Finset.sum_congr rfl
intro j _
rw [ENNReal.toReal_mul, toReal_channelPMF]
· intro j _
exact ENNReal.mul_ne_top ((channelPMF lam h i).apply_ne_top j) (poisM_ne_top d hd lam h n j)
theorem poisM_formula (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
(poisM d hd lam h n i).toReal = d ^ n * (1 / 3 + lam ^ n * eSpin i) := by
induction n generalizing i with
| zero =>
rw [poisM_zero]
split_ifs with hi
· subst hi
simp [eSpin]
· simp [eSpin, hi]
| succ n ih =>
rw [poisM_toReal_rec]
have h1 : (∑ j : Spin, channel lam i j * (1 / 3 : ℝ)) = 1 / 3 := by
calc ∑ j : Spin, channel lam i j * (1 / 3 : ℝ)
= (∑ j : Spin, channel lam i j) * (1 / 3) := by rw [Finset.sum_mul]
_ = 1 / 3 := by rw [channel_sum]; ring
have h3 : (∑ j : Spin, channel lam i j * (lam ^ n * eSpin j)) =
lam ^ n * (lam * eSpin i) := by
calc ∑ j : Spin, channel lam i j * (lam ^ n * eSpin j)
= ∑ j : Spin, lam ^ n * (channel lam i j * eSpin j) := by
apply Finset.sum_congr rfl
intro j _; ring
_ = lam ^ n * ∑ j : Spin, channel lam i j * eSpin j := by rw [Finset.mul_sum]
_ = lam ^ n * (lam * eSpin i) := by rw [channel_mul_eSpin]
have hsum : (∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j)) =
1 / 3 + lam ^ (n + 1) * eSpin i := by
rw [show (∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j)) =
∑ j : Spin, (channel lam i j * (1 / 3 : ℝ) + channel lam i j * (lam ^ n * eSpin j)) by
apply Finset.sum_congr rfl
intro j _; ring]
rw [Finset.sum_add_distrib, h1, h3, pow_succ]
ring
have hfactor : (∑ j : Spin, channel lam i j *
(d ^ n * (1 / 3 + lam ^ n * eSpin j))) =
d ^ n * ∑ j : Spin, channel lam i j * (1 / 3 + lam ^ n * eSpin j) := by
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro j _; ring
calc
d * ∑ j : Spin, channel lam i j * (poisM d hd lam h n j).toReal
= d * ∑ j : Spin, channel lam i j *
(d ^ n * (1 / 3 + lam ^ n * eSpin j)) := by
congr 1
apply Finset.sum_congr rfl
intro j _
rw [ih j]
_ = d * (d ^ n * (1 / 3 + lam ^ (n + 1) * eSpin i)) := by
rw [hfactor, hsum]
_ = d ^ (n + 1) * (1 / 3 + lam ^ (n + 1) * eSpin i) := by
rw [pow_succ]; ring
noncomputable def totalCensus : (n : ℕ) → Observation n → ENNReal
| 0 => fun _ => 1
| n + 1 => fun s => (s.map (totalCensus n)).sum
theorem totalCensus_succ (n : ℕ) (s : Multiset (Observation n)) :
totalCensus (n + 1) s = (s.map (totalCensus n)).sum := rfl
noncomputable def poisT (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam)
(n : ℕ) (i : Spin) : ENNReal :=
∑' o : Observation n, poissonLaw d hd lam h n i o * totalCensus n o
theorem poisT_zero (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (i : Spin) :
poisT d hd lam h 0 i = 1 := by
unfold poisT poissonLaw observedLaw
change (∑' o : Spin, (PMF.pure i : PMF Spin) o * totalCensus 0 o) = 1
rw [tsum_eq_single i]
· rw [PMF.pure_apply_self]
simp [totalCensus]
· intro o ho
rw [PMF.pure_apply, if_neg ho]
simp
theorem poisT_rec (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
poisT d hd lam h (n + 1) i =
ENNReal.ofReal d * ∑ j : Spin, channelPMF lam h i j * poisT d hd lam h n j := by
unfold poisT
have hb := (isBroadcastLaw_observedLaw (poissonOffspring d hd) lam h).tsum_mul_census
(O := Observation) (K := channelPMF lam h) (N := poissonOffspring d hd)
(leaf := fun i : Spin => i) (up := fun _ s => s)
(law := observedLaw (poissonOffspring d hd) lam h) totalCensus
(fun n s => totalCensus_succ n s) n i
rw [poisson_mean d hd] at hb
simpa [poissonLaw] using hb
theorem poisT_eq (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
poisT d hd lam h n i = (ENNReal.ofReal d) ^ n := by
induction n generalizing i with
| zero => rw [poisT_zero, pow_zero]
| succ n ih =>
rw [poisT_rec]
calc
ENNReal.ofReal d * ∑ j : Spin, channelPMF lam h i j * poisT d hd lam h n j
= ENNReal.ofReal d * ∑ j : Spin, channelPMF lam h i j * (ENNReal.ofReal d) ^ n := by
congr 1
apply Finset.sum_congr rfl
intro j _
rw [ih j]
_ = ENNReal.ofReal d * ((ENNReal.ofReal d) ^ n * ∑ j : Spin, channelPMF lam h i j) := by
congr 1
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro j _
ring
_ = (ENNReal.ofReal d) ^ (n + 1) := by
rw [channelPMF_tsum, mul_one, pow_succ]
ring
theorem poisT_ne_top (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
poisT d hd lam h n i ≠ ⊤ := by
rw [poisT_eq]
exact ENNReal.pow_ne_top ENNReal.ofReal_ne_top
theorem poisT_formula (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
(poisT d hd lam h n i).toReal = d ^ n := by
rw [poisT_eq, ENNReal.toReal_pow, ENNReal.toReal_ofReal hd]
theorem multiset_sum_ne_top {α : Type*} (s : Multiset α) (f : α → ENNReal)
(hf : ∀ a ∈ s, f a ≠ ⊤) : (s.map f).sum ≠ ⊤ := by
induction s using Multiset.induction_on with
| empty => simp
| cons x t ih =>
simp only [Multiset.map_cons, Multiset.sum_cons]
exact ENNReal.add_ne_top.2
⟨hf x (by simp), ih fun a ha => hf a (by simp [ha])⟩
theorem toReal_multiset_sum {α : Type*} (s : Multiset α) (f : α → ENNReal)
(hf : ∀ a ∈ s, f a ≠ ⊤) :
((s.map f).sum).toReal = (s.map (fun a => (f a).toReal)).sum := by
induction s using Multiset.induction_on with
| empty => simp
| cons x t ih =>
have hx : f x ≠ ⊤ := hf x (by simp)
have ht : ∀ a ∈ t, f a ≠ ⊤ := fun a ha => hf a (by simp [ha])
simp only [Multiset.map_cons, Multiset.sum_cons]
rw [ENNReal.toReal_add hx (multiset_sum_ne_top t f ht), ih ht]
theorem census_ne_top (n : ℕ) (o : Observation n) : census n o ≠ ⊤ := by
induction n with
| zero =>
change (if (show Spin from o) = (1 : Spin) then (1 : ENNReal) else 0) ≠ ⊤
split_ifs <;> simp
| succ n ih =>
change (o.map (census n)).sum ≠ ⊤
exact multiset_sum_ne_top o (census n) fun a _ => ih a
theorem totalCensus_ne_top (n : ℕ) (o : Observation n) : totalCensus n o ≠ ⊤ := by
induction n with
| zero => simp [totalCensus]
| succ n ih =>
change (o.map (totalCensus n)).sum ≠ ⊤
exact multiset_sum_ne_top o (totalCensus n) fun a _ => ih a
theorem multiset_sum_map_sub {α : Type*} (s : Multiset α) (f g : α → ℝ) :
(s.map (fun a => f a - g a)).sum = (s.map f).sum - (s.map g).sum := by
induction s using Multiset.induction_on with
| empty => simp
| cons x t ih =>
simp only [Multiset.map_cons, Multiset.sum_cons]
rw [ih]; ring
theorem leafSum_eSpin_eq (n : ℕ) (o : Observation n) :
leafSum eSpin n o = (census n o).toReal - (1 / 3) * (totalCensus n o).toReal := by
induction n with
| zero =>
change eSpin o = (if (show Spin from o) = (1 : Spin) then (1:ENNReal) else 0).toReal
- (1/3) * (1:ENNReal).toReal
simp [eSpin]
split_ifs <;> norm_num
| succ n ih =>
set o' : Multiset (Observation n) := o
change (o'.map (leafSum eSpin n)).sum =
((o'.map (census n)).sum).toReal - (1/3) * ((o'.map (totalCensus n)).sum).toReal
rw [toReal_multiset_sum o' (census n) (fun a _ => census_ne_top n a),
toReal_multiset_sum o' (totalCensus n) (fun a _ => totalCensus_ne_top n a)]
have hcongr : (o'.map (leafSum eSpin n)) =
(o'.map fun a => (census n a).toReal - (1/3) * (totalCensus n a).toReal) := by
apply Multiset.map_congr rfl
intro a _
exact ih a
rw [hcongr, ← Multiset.sum_map_mul_left (s := o') (a := (1/3 : ℝ))
(f := fun a => (totalCensus n a).toReal)]
exact multiset_sum_map_sub (α := Observation n) o'
(fun a => (census n a).toReal) (fun a => (1/3) * (totalCensus n a).toReal)
theorem poissonLeaf_mean (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) :
(∑' o : Observation n, (poissonLaw d hd lam h n i o).toReal * leafSum eSpin n o)
= ((d : ℝ) * lam) ^ n * eSpin i := by
have hsm : Summable fun o : Observation n =>
(poissonLaw d hd lam h n i o).toReal * (census n o).toReal :=
TheoremOS.Probability.summable_toReal_mul_toReal _ _ (poisM_ne_top d hd lam h n i)
have hst : Summable fun o : Observation n =>
(poissonLaw d hd lam h n i o).toReal * ((1 / 3) * (totalCensus n o).toReal) := by
have h0 := TheoremOS.Probability.summable_toReal_mul_toReal
(poissonLaw d hd lam h n i) (totalCensus n) (poisT_ne_top d hd lam h n i)
refine (h0.mul_right (1 / 3)).congr fun o => ?_
ring
have hsplit : (∑' o : Observation n,
(poissonLaw d hd lam h n i o).toReal * leafSum eSpin n o)
= (∑' o : Observation n, (poissonLaw d hd lam h n i o).toReal * (census n o).toReal)
- (∑' o : Observation n,
(poissonLaw d hd lam h n i o).toReal * ((1 / 3) * (totalCensus n o).toReal)) := by
rw [← Summable.tsum_sub hsm hst]
apply tsum_congr
intro o
rw [leafSum_eSpin_eq]
ring
have hM : (∑' o : Observation n, (poissonLaw d hd lam h n i o).toReal * (census n o).toReal)
= (poisM d hd lam h n i).toReal :=
TheoremOS.Probability.tsum_toReal_mul_toReal _ _ (poisM_ne_top d hd lam h n i)
have hT : (∑' o : Observation n,
(poissonLaw d hd lam h n i o).toReal * ((1 / 3) * (totalCensus n o).toReal))
= (1 / 3) * (poisT d hd lam h n i).toReal := by
rw [show (∑' o : Observation n,
(poissonLaw d hd lam h n i o).toReal * ((1 / 3) * (totalCensus n o).toReal))
= ∑' o : Observation n,
(1 / 3) * ((poissonLaw d hd lam h n i o).toReal * (totalCensus n o).toReal) from
tsum_congr fun o => by ring]
rw [tsum_mul_left]
rw [TheoremOS.Probability.tsum_toReal_mul_toReal (poissonLaw d hd lam h n i) (totalCensus n)
(poisT_ne_top d hd lam h n i)]
rfl
rw [hsplit, hM, hT, poisM_formula, poisT_formula, mul_pow]
ring
theorem poissonLeaf_first_moment (d : ℝ) (hd : 1 < d) (lam : ℝ) (h : Admissible lam)
(hcrit : 1 < d * lam ^ 2) (n : ℕ) (i : Spin) :
(∑' o : Observation n, (poissonLaw d (le_trans (by norm_num) hd.le) lam h n i o).toReal
* leafSum eSpin n o) = ((d : ℝ) * lam) ^ n * eSpin i :=
poissonLeaf_mean d (le_trans (by norm_num) hd.le) lam h n i
theorem poisson_reconstructs_of_leaf_moments (d : ℝ) (hd : 1 < d) (lam : ℝ)
(h : Admissible lam) (hcrit : 1 < d * lam ^ 2)
(hfirst : ∀ (n : ℕ) (i : Spin),
(∑' o : Observation n,
(poissonLaw d (le_trans (by norm_num) hd.le) lam h n i o).toReal * leafSum eSpin n o)
= ((d : ℝ) * lam) ^ n * eSpin i)
(hsecond : (∀ (n : ℕ) (i : Spin), Summable (fun o : Observation n =>
(poissonLaw d (le_trans (by norm_num) hd.le) lam h n i o).toReal *
(leafSum eSpin n o) ^ 2)) ∧
(∀ (n : ℕ) (i : Spin),
(∑' o : Observation n,
(poissonLaw d (le_trans (by norm_num) hd.le) lam h n i o).toReal *
(leafSum eSpin n o) ^ 2)
≤ ((4 / 9) / (1 - 1 / (d * lam ^ 2))) * ((d : ℝ) * lam) ^ (2 * n))) :
Reconstructs (poissonAdvantage d hd lam h) := by
classical
have hd0 : 0 ≤ d := le_trans (by norm_num) hd.le
set s : ℝ := (d * lam) ^ 2 with hs
set q : ℝ := 1 / (d * lam ^ 2) with hq
set C : ℝ := (4 / 9) / (1 - q) with hC
have hdl2 : 0 < d * lam ^ 2 := lt_trans zero_lt_one hcrit
have hqpos : 0 < q := by rw [hq]; exact div_pos one_pos hdl2
have hq1 : q < 1 := by
rw [hq, div_lt_one hdl2]
linarith
have h1q : 0 < 1 - q := by linarith
have hCpos : 0 < C := by rw [hC]; exact div_pos (by norm_num) h1q
have hdlne : d * lam ≠ 0 := by
intro h0
nlinarith [hcrit]
have hs_pos : 0 < s := by
rw [hs, pow_two]
exact mul_self_pos.mpr hdlne
have hs_pow : ∀ n : ℕ, s ^ n = (d * lam) ^ (2 * n) := by
intro n
rw [hs, ← pow_mul]
have hconst : ∀ n : ℕ, ((4 / 9) / (1 - 1 / (d * lam ^ 2))) * ((d : ℝ) * lam) ^ (2 * n)
= C * s ^ n := by
intro n
rw [hs_pow n]
have hTV : ∀ n : ℕ, (1 : ℝ) / (4 * C) ≤
TheoremOS.Probability.pmfTV (poissonLaw d hd0 lam h n (1 : Spin))
(poissonLaw d hd0 lam h n (0 : Spin)) := by
intro n
set p : PMF (Observation n) := poissonLaw d hd0 lam h n (1 : Spin) with hp_def
set q0 : PMF (Observation n) := poissonLaw d hd0 lam h n (0 : Spin) with hq0_def
set S : Observation n → ℝ := fun o => leafSum eSpin n o with hS_def
have hp_sum : Summable fun a => (p a).toReal * S a ^ 2 := by
simpa [p, S] using hsecond.1 n (1 : Spin)
have hq_sum : Summable fun a => (q0 a).toReal * S a ^ 2 := by
simpa [q0, S] using hsecond.1 n (0 : Spin)
have hM1 : (∑' o : Observation n, (p o).toReal * S o) =
(d * lam) ^ n * eSpin (1 : Spin) := by
simpa [p, S] using hfirst n (1 : Spin)
have hM0 : (∑' o : Observation n, (q0 o).toReal * S o) =
(d * lam) ^ n * eSpin (0 : Spin) := by
simpa [q0, S] using hfirst n (0 : Spin)
have hmean : (∑' o : Observation n, (p o).toReal * S o) -
(∑' o : Observation n, (q0 o).toReal * S o) = (d * lam) ^ n := by
rw [hM1, hM0, ← mul_sub, eSpin_one_sub_zero, mul_one]
have hsquare : ((∑' o : Observation n, (p o).toReal * S o) -
(∑' o : Observation n, (q0 o).toReal * S o)) ^ 2 = s ^ n := by
rw [hmean, hs]
rw [← pow_mul, ← pow_mul, Nat.mul_comm]
have hboundp : (∑' o : Observation n, (p o).toReal * S o ^ 2) ≤ C * s ^ n := by
have h2 := hsecond.2 n (1 : Spin)
rw [hconst n] at h2
simpa [p, S] using h2
have hboundq : (∑' o : Observation n, (q0 o).toReal * S o ^ 2) ≤ C * s ^ n := by
have h2 := hsecond.2 n (0 : Spin)
rw [hconst n] at h2
simpa [q0, S] using h2
have hmain := TheoremOS.Probability.sq_sub_le_pmfTV_mul_centred p q0 S 0 hp_sum hq_sum
have hmain' : ((∑' o : Observation n, (p o).toReal * S o) -
(∑' o : Observation n, (q0 o).toReal * S o)) ^ 2 ≤
2 * TheoremOS.Probability.pmfTV p q0 *
((∑' o : Observation n, (p o).toReal * S o ^ 2) +
(∑' o : Observation n, (q0 o).toReal * S o ^ 2)) := by
simpa only [sub_zero] using hmain
have hWsum : (∑' o : Observation n, (p o).toReal * S o ^ 2) +
(∑' o : Observation n, (q0 o).toReal * S o ^ 2) ≤ 2 * (C * s ^ n) := by
linarith
have hle : s ^ n ≤ 2 * TheoremOS.Probability.pmfTV p q0 * (2 * (C * s ^ n)) := by
calc
s ^ n = ((∑' o : Observation n, (p o).toReal * S o) -
(∑' o : Observation n, (q0 o).toReal * S o)) ^ 2 := hsquare.symm
_ ≤ 2 * TheoremOS.Probability.pmfTV p q0 *
((∑' o : Observation n, (p o).toReal * S o ^ 2) +
(∑' o : Observation n, (q0 o).toReal * S o ^ 2)) := hmain'
_ ≤ 2 * TheoremOS.Probability.pmfTV p q0 * (2 * (C * s ^ n)) := by
apply mul_le_mul_of_nonneg_left hWsum
have htv0 : 0 ≤ TheoremOS.Probability.pmfTV p q0 :=
TheoremOS.Probability.pmfTV_nonneg p q0
positivity
have hspos : 0 < s ^ n := pow_pos hs_pos n
have hquad : 1 ≤ 4 * C * TheoremOS.Probability.pmfTV p q0 := by
have hle' : s ^ n ≤ (4 * C * s ^ n) * TheoremOS.Probability.pmfTV p q0 := by
calc
s ^ n ≤ 2 * TheoremOS.Probability.pmfTV p q0 * (2 * (C * s ^ n)) := hle
_ = (4 * C * s ^ n) * TheoremOS.Probability.pmfTV p q0 := by ring
have hle2 : s ^ n * 1 ≤ s ^ n * (4 * C * TheoremOS.Probability.pmfTV p q0) := by
calc
s ^ n * 1 = s ^ n := by ring
_ ≤ (4 * C * s ^ n) * TheoremOS.Probability.pmfTV p q0 := hle'
_ = s ^ n * (4 * C * TheoremOS.Probability.pmfTV p q0) := by ring
exact (mul_le_mul_iff_of_pos_left hspos).mp hle2
have htv : (1 : ℝ) / (4 * C) ≤ TheoremOS.Probability.pmfTV p q0 := by
rw [div_le_iff₀ (by positivity : (0 : ℝ) < 4 * C)]
simpa [mul_comm] using hquad
simpa [p, q0] using htv
have hAdv : ∀ n : ℕ, (1 : ℝ) / (12 * C) ≤