File size: 29,869 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Computability.MinUncut.PCP.Overlap

namespace OAI

namespace MinUncutGames.Foundations.Repetition.CompletedSampling

open scoped BigOperators
open Games

noncomputable section

section DistributionIdentities

variable {A B C D : Type*} [Fintype A] [Fintype B] [Fintype C] [Fintype D]

theorem mixture_pushforward_base (ΞΌ : FiniteDistribution A) (f : A β†’ B)
    (K : B β†’ FiniteDistribution C) :
    (ΞΌ.pushforward f).mixture K = ΞΌ.mixture (fun a => K (f a)) := by
  apply FiniteDistribution.eq_of_weight_eq
  intro c
  exact FiniteDistribution.expectation_pushforward ΞΌ f (fun b => (K b).weight c)

theorem product_pushforward_eq_mixture_right (ΞΌ : FiniteDistribution A)
    (Ξ½ : FiniteDistribution B) (f : A Γ— B β†’ C) :
    (ΞΌ.product Ξ½).pushforward f =
      Ξ½.mixture (fun b => ΞΌ.pushforward (fun a => f (a, b))) := by
  classical
  apply FiniteDistribution.eq_of_weight_eq
  intro c
  simp only [FiniteDistribution.pushforward, FiniteDistribution.product,
    FiniteDistribution.mixture, Fintype.sum_prod_type]
  rw [Finset.sum_comm]
  apply Finset.sum_congr rfl
  intro b _
  rw [Finset.mul_sum]
  apply Finset.sum_congr rfl
  intro a _
  by_cases h : f (a, b) = c <;> simp [h, mul_comm]

theorem product_product_pushforward_eq_mixture (ΞΌ : FiniteDistribution A)
    (Ξ½ : FiniteDistribution B) (ΞΊ : FiniteDistribution C) (f : A β†’ B β†’ C β†’ D) :
    (ΞΌ.product (Ξ½.product ΞΊ)).pushforward (fun z => f z.1 z.2.1 z.2.2) =
      (ΞΌ.product Ξ½).mixture
        (fun z => ΞΊ.pushforward (fun c => f z.1 z.2 c)) := by
  classical
  apply FiniteDistribution.eq_of_weight_eq
  intro d
  simp only [FiniteDistribution.pushforward, FiniteDistribution.product,
    FiniteDistribution.mixture, Fintype.sum_prod_type]
  simp only [Finset.mul_sum, mul_ite, mul_zero, mul_assoc]

theorem mixture_totalVariation_le (ΞΌ Ξ½ : FiniteDistribution A)
    (K : A β†’ FiniteDistribution B) :
    (ΞΌ.mixture K).totalVariation (Ξ½.mixture K) ≀ ΞΌ.totalVariation Ξ½ := by
  simpa only [FiniteDistribution.totalVariation, FiniteDistribution.mixture,
    Information.totalVariation, kernelPushforward] using
      totalVariation_kernelPushforward_le ΞΌ.weight Ξ½.weight
        (fun a => (K a).weight) (fun a => Information.gameLaw_isProbability (K a))

end DistributionIdentities

section Diagonal

variable {Z S : Type*} [Fintype Z] [Fintype S]

def diagonalLaw (Οƒ : FiniteDistribution (Z Γ— S)) : FiniteDistribution (Z Γ— S Γ— S) :=
  Information.toGameLaw (diagonalWeights Οƒ.weight)
    (diagonalWeights_isProbability _ (Information.gameLaw_isProbability Οƒ))

theorem diagonalLaw_eq_pushforward (Οƒ : FiniteDistribution (Z Γ— S)) :
    diagonalLaw Οƒ = Οƒ.pushforward (fun z => (z.1, z.2, z.2)) := by
  classical
  apply FiniteDistribution.eq_of_weight_eq
  rintro ⟨z, a, b⟩
  change diagonalWeights Οƒ.weight (z, a, b) =
    (Οƒ.pushforward (fun t => (t.1, t.2, t.2))).weight (z, a, b)
  simp only [diagonalWeights, FiniteDistribution.pushforward,
    Fintype.sum_prod_type, Prod.mk.injEq]
  by_cases hab : a = b
  Β· subst b
    simp [ite_and]
  Β· simp [hab, ite_and]

theorem diagonalLaw_mixture {T : Type*} [Fintype T]
    (Οƒ : FiniteDistribution (Z Γ— S)) (K : Z Γ— S Γ— S β†’ FiniteDistribution T) :
    (diagonalLaw Οƒ).mixture K = Οƒ.mixture (fun z => K (z.1, z.2, z.2)) := by
  rw [diagonalLaw_eq_pushforward, mixture_pushforward_base]

end Diagonal

section Completion

variable {X Y S Ξ“ U V : Type*}
  [Fintype X] [Fintype Y] [Fintype S] [Fintype Ξ“] [Fintype U] [Fintype V]
  [DecidableEq X] [DecidableEq Y] [DecidableEq S]

abbrev Seed (Ξ“ X Y S U V : Type*) :=
  Ξ“ Γ— KernelSampling.Seed (X Γ— S) (Y Γ— S) U V

def seedLaw (Ξ³ : FiniteDistribution Ξ“)
    (L : X Γ— S β†’ FiniteDistribution U) (R : Y Γ— S β†’ FiniteDistribution V) :
    FiniteDistribution (Seed Ξ“ X Y S U V) :=
  Ξ³.product (KernelSampling.seedLaw L R)

def left (sL : Ξ“ β†’ X β†’ S) (seed : Seed Ξ“ X Y S U V) (x : X) : U :=
  KernelSampling.readLeft seed.2 (x, sL seed.1 x)

def right (sR : Ξ“ β†’ Y β†’ S) (seed : Seed Ξ“ X Y S U V) (y : Y) : V :=
  KernelSampling.readRight seed.2 (y, sR seed.1 y)

def completionKernel (L : X Γ— S β†’ FiniteDistribution U)
    (R : Y Γ— S β†’ FiniteDistribution V) (z : (X Γ— Y) Γ— S Γ— S) :
    FiniteDistribution (U Γ— V) :=
  (L (z.1.1, z.2.1)).product (R (z.1.2, z.2.2))

def outputLaw (ΞΌ : FiniteDistribution (X Γ— Y)) (Ξ³ : FiniteDistribution Ξ“)
    (sL : Ξ“ β†’ X β†’ S) (sR : Ξ“ β†’ Y β†’ S)
    (L : X Γ— S β†’ FiniteDistribution U) (R : Y Γ— S β†’ FiniteDistribution V) :
    FiniteDistribution (U Γ— V) :=
  (seedLaw Ξ³ L R).mixture (fun seed =>
    ΞΌ.pushforward (fun q => (left sL seed q.1, right sR seed q.2)))

theorem outputLaw_eq_product_pushforward
    (ΞΌ : FiniteDistribution (X Γ— Y)) (Ξ³ : FiniteDistribution Ξ“)
    (sL : Ξ“ β†’ X β†’ S) (sR : Ξ“ β†’ Y β†’ S)
    (L : X Γ— S β†’ FiniteDistribution U) (R : Y Γ— S β†’ FiniteDistribution V) :
    outputLaw ΞΌ Ξ³ sL sR L R =
      (ΞΌ.product (seedLaw Ξ³ L R)).pushforward
        (fun z => (left sL z.2 z.1.1, right sR z.2 z.1.2)) := by
  exact (product_pushforward_eq_mixture_right ΞΌ (seedLaw Ξ³ L R)
    (fun z : (X Γ— Y) Γ— Seed Ξ“ X Y S U V =>
      (left sL z.2 z.1.1, right sR z.2 z.1.2))).symm

theorem outputLaw_eq_mixture
    (ΞΌ : FiniteDistribution (X Γ— Y)) (Ξ³ : FiniteDistribution Ξ“)
    (sL : Ξ“ β†’ X β†’ S) (sR : Ξ“ β†’ Y β†’ S)
    (L : X Γ— S β†’ FiniteDistribution U) (R : Y Γ— S β†’ FiniteDistribution V) :
    outputLaw ΞΌ Ξ³ sL sR L R =
      (sharedOutputLaw ΞΌ Ξ³ sL sR).mixture (completionKernel L R) := by
  calc
    outputLaw ΞΌ Ξ³ sL sR L R =
        (ΞΌ.product Ξ³).mixture (fun z =>
          (KernelSampling.seedLaw L R).pushforward (fun table =>
            (KernelSampling.readLeft table (z.1.1, sL z.2 z.1.1),
             KernelSampling.readRight table (z.1.2, sR z.2 z.1.2)))) := by
      rw [outputLaw_eq_product_pushforward]
      exact product_product_pushforward_eq_mixture ΞΌ Ξ³ (KernelSampling.seedLaw L R)
        (fun q seed table =>
          (KernelSampling.readLeft table (q.1, sL seed q.1),
           KernelSampling.readRight table (q.2, sR seed q.2)))
    _ = (ΞΌ.product Ξ³).mixture (fun z =>
        completionKernel L R (z.1, sL z.2 z.1.1, sR z.2 z.1.2)) := by
      apply congrArg ((ΞΌ.product Ξ³).mixture)
      funext z
      exact KernelSampling.read_joint_pushforward L R
        (z.1.1, sL z.2 z.1.1) (z.1.2, sR z.2 z.1.2)
    _ = (sharedOutputLaw ΞΌ Ξ³ sL sR).mixture (completionKernel L R) := by
      exact (mixture_pushforward_base (ΞΌ.product Ξ³)
        (fun z => (z.1, sL z.2 z.1.1, sR z.2 z.1.2)) (completionKernel L R)).symm

omit [DecidableEq X] [DecidableEq Y] [DecidableEq S] in

theorem diagonalLaw_completion_mixture
    (Οƒ : FiniteDistribution ((X Γ— Y) Γ— S))
    (L : X Γ— S β†’ FiniteDistribution U) (R : Y Γ— S β†’ FiniteDistribution V) :
    (diagonalLaw Οƒ).mixture (completionKernel L R) =
      Οƒ.mixture (fun z => (L (z.1.1, z.2)).product (R (z.1.2, z.2))) := by
  exact diagonalLaw_mixture Οƒ (completionKernel L R)

theorem outputLaw_totalVariation_le
    (ΞΌ : FiniteDistribution (X Γ— Y)) (Ξ³ : FiniteDistribution Ξ“)
    (sL : Ξ“ β†’ X β†’ S) (sR : Ξ“ β†’ Y β†’ S)
    (L : X Γ— S β†’ FiniteDistribution U) (R : Y Γ— S β†’ FiniteDistribution V)
    (Οƒ : FiniteDistribution ((X Γ— Y) Γ— S)) :
    (outputLaw ΞΌ Ξ³ sL sR L R).totalVariation
        (Οƒ.mixture (fun z => (L (z.1.1, z.2)).product (R (z.1.2, z.2)))) ≀
      (sharedOutputLaw ΞΌ Ξ³ sL sR).totalVariation (diagonalLaw Οƒ) := by
  rw [outputLaw_eq_mixture, ← diagonalLaw_completion_mixture Οƒ L R]
  exact mixture_totalVariation_le _ _ (completionKernel L R)

end Completion

variable {I X Y S Ξ“ : Type*}
  [Fintype I] [Fintype X] [Fintype Y] [Fintype S] [Fintype Ξ“]
  [DecidableEq I] [DecidableEq X] [DecidableEq Y] [DecidableEq S]

def coordinateLeft (j : I) (sL : Ξ“ β†’ X β†’ S)
    (seed : Seed Ξ“ X Y S (I β†’ X) (I β†’ Y)) (x : X) : I β†’ X :=
  KernelSampling.completedLeft j seed.2 (x, sL seed.1 x)

def coordinateRight (j : I) (sR : Ξ“ β†’ Y β†’ S)
    (seed : Seed Ξ“ X Y S (I β†’ X) (I β†’ Y)) (y : Y) : I β†’ Y :=
  KernelSampling.completedRight j seed.2 (y, sR seed.1 y)

omit [Fintype I] [Fintype X] [Fintype Y] [Fintype S] [Fintype Ξ“]
  [DecidableEq X] [DecidableEq Y] [DecidableEq S] in
@[simp] theorem coordinateLeft_preserves (j : I) (sL : Ξ“ β†’ X β†’ S)
    (seed : Seed Ξ“ X Y S (I β†’ X) (I β†’ Y)) (x : X) :
    coordinateLeft j sL seed x j = x := by
  simp [coordinateLeft]

omit [Fintype I] [Fintype X] [Fintype Y] [Fintype S] [Fintype Ξ“]
  [DecidableEq X] [DecidableEq Y] [DecidableEq S] in
@[simp] theorem coordinateRight_preserves (j : I) (sR : Ξ“ β†’ Y β†’ S)
    (seed : Seed Ξ“ X Y S (I β†’ X) (I β†’ Y)) (y : Y) :
    coordinateRight j sR seed y j = y := by
  simp [coordinateRight]

def coordinateOutputLaw (ΞΌ : FiniteDistribution (X Γ— Y)) (Ξ³ : FiniteDistribution Ξ“)
    (j : I) (sL : Ξ“ β†’ X β†’ S) (sR : Ξ“ β†’ Y β†’ S)
    (L : X Γ— S β†’ FiniteDistribution (I β†’ X))
    (R : Y Γ— S β†’ FiniteDistribution (I β†’ Y)) :
    FiniteDistribution ((I β†’ X) Γ— (I β†’ Y)) :=
  (seedLaw Ξ³ L R).mixture (fun seed => ΞΌ.pushforward
    (fun q => (coordinateLeft j sL seed q.1, coordinateRight j sR seed q.2)))

theorem coordinateOutputLaw_eq_mixture
    (ΞΌ : FiniteDistribution (X Γ— Y)) (Ξ³ : FiniteDistribution Ξ“)
    (j : I) (sL : Ξ“ β†’ X β†’ S) (sR : Ξ“ β†’ Y β†’ S)
    (L : X Γ— S β†’ FiniteDistribution (I β†’ X))
    (R : Y Γ— S β†’ FiniteDistribution (I β†’ Y))
    (hL : βˆ€ q xs, (L q).weight xs β‰  0 β†’ xs j = q.1)
    (hR : βˆ€ q ys, (R q).weight ys β‰  0 β†’ ys j = q.1) :
    coordinateOutputLaw ΞΌ Ξ³ j sL sR L R =
      (sharedOutputLaw ΞΌ Ξ³ sL sR).mixture (completionKernel L R) := by
  calc
    coordinateOutputLaw ΞΌ Ξ³ j sL sR L R =
        (ΞΌ.product (seedLaw Ξ³ L R)).pushforward
          (fun z => (coordinateLeft j sL z.2 z.1.1,
            coordinateRight j sR z.2 z.1.2)) := by
      exact (product_pushforward_eq_mixture_right ΞΌ (seedLaw Ξ³ L R)
        (fun z : (X Γ— Y) Γ— Seed Ξ“ X Y S (I β†’ X) (I β†’ Y) =>
          (coordinateLeft j sL z.2 z.1.1, coordinateRight j sR z.2 z.1.2))).symm
    _ = (ΞΌ.product Ξ³).mixture (fun z =>
        (KernelSampling.seedLaw L R).pushforward (fun table =>
          (KernelSampling.completedLeft j table (z.1.1, sL z.2 z.1.1),
           KernelSampling.completedRight j table (z.1.2, sR z.2 z.1.2)))) := by
      exact product_product_pushforward_eq_mixture ΞΌ Ξ³ (KernelSampling.seedLaw L R)
        (fun q seed table =>
          (KernelSampling.completedLeft j table (q.1, sL seed q.1),
           KernelSampling.completedRight j table (q.2, sR seed q.2)))
    _ = (ΞΌ.product Ξ³).mixture (fun z =>
        completionKernel L R (z.1, sL z.2 z.1.1, sR z.2 z.1.2)) := by
      apply congrArg ((ΞΌ.product Ξ³).mixture)
      funext z
      exact KernelSampling.completed_joint_pushforward L R j hL hR
        (z.1.1, sL z.2 z.1.1) (z.1.2, sR z.2 z.1.2)
    _ = (sharedOutputLaw ΞΌ Ξ³ sL sR).mixture (completionKernel L R) := by
      exact (mixture_pushforward_base (ΞΌ.product Ξ³)
        (fun z => (z.1, sL z.2 z.1.1, sR z.2 z.1.2)) (completionKernel L R)).symm

theorem coordinateOutputLaw_eq_outputLaw
    (ΞΌ : FiniteDistribution (X Γ— Y)) (Ξ³ : FiniteDistribution Ξ“)
    (j : I) (sL : Ξ“ β†’ X β†’ S) (sR : Ξ“ β†’ Y β†’ S)
    (L : X Γ— S β†’ FiniteDistribution (I β†’ X))
    (R : Y Γ— S β†’ FiniteDistribution (I β†’ Y))
    (hL : βˆ€ q xs, (L q).weight xs β‰  0 β†’ xs j = q.1)
    (hR : βˆ€ q ys, (R q).weight ys β‰  0 β†’ ys j = q.1) :
    coordinateOutputLaw ΞΌ Ξ³ j sL sR L R = outputLaw ΞΌ Ξ³ sL sR L R := by
  rw [coordinateOutputLaw_eq_mixture ΞΌ Ξ³ j sL sR L R hL hR, outputLaw_eq_mixture]

theorem coordinateOutputLaw_totalVariation_le
    (ΞΌ : FiniteDistribution (X Γ— Y)) (Ξ³ : FiniteDistribution Ξ“)
    (j : I) (sL : Ξ“ β†’ X β†’ S) (sR : Ξ“ β†’ Y β†’ S)
    (L : X Γ— S β†’ FiniteDistribution (I β†’ X))
    (R : Y Γ— S β†’ FiniteDistribution (I β†’ Y))
    (hL : βˆ€ q xs, (L q).weight xs β‰  0 β†’ xs j = q.1)
    (hR : βˆ€ q ys, (R q).weight ys β‰  0 β†’ ys j = q.1)
    (Οƒ : FiniteDistribution ((X Γ— Y) Γ— S)) :
    (coordinateOutputLaw ΞΌ Ξ³ j sL sR L R).totalVariation
        (Οƒ.mixture (fun z => (L (z.1.1, z.2)).product (R (z.1.2, z.2)))) ≀
      (sharedOutputLaw ΞΌ Ξ³ sL sR).totalVariation (diagonalLaw Οƒ) := by
  rw [coordinateOutputLaw_eq_outputLaw ΞΌ Ξ³ j sL sR L R hL hR]
  exact outputLaw_totalVariation_le ΞΌ Ξ³ sL sR L R Οƒ

end

end MinUncutGames.Foundations.Repetition.CompletedSampling

namespace MinUncutGames.Foundations.Games.Game

noncomputable section

variable {Q₁ Qβ‚‚ A₁ Aβ‚‚ R₁ Rβ‚‚ B₁ Bβ‚‚ Seed : Type*}
  [Fintype Q₁] [Fintype Qβ‚‚] [Fintype A₁] [Fintype Aβ‚‚]
  [Fintype R₁] [Fintype Rβ‚‚] [Fintype B₁] [Fintype Bβ‚‚] [Fintype Seed]
  [Nonempty A₁] [Nonempty Aβ‚‚]

def localEmbeddingLaw (G : Game Q₁ Qβ‚‚ A₁ Aβ‚‚)
    (seedLaw : FiniteDistribution Seed)
    (left : Seed β†’ Q₁ β†’ R₁) (right : Seed β†’ Qβ‚‚ β†’ Rβ‚‚) :
    FiniteDistribution (R₁ Γ— Rβ‚‚) :=
  seedLaw.mixture fun seed =>
    G.questions.pushforward fun q => (left seed q.1, right seed q.2)

theorem success_le_value_add_embedding_distance
    (G : Game Q₁ Qβ‚‚ A₁ Aβ‚‚) (H : Game R₁ Rβ‚‚ B₁ Bβ‚‚)
    (seedLaw : FiniteDistribution Seed)
    (left : Seed β†’ Q₁ β†’ R₁) (right : Seed β†’ Qβ‚‚ β†’ Rβ‚‚)
    (answerLeft : Seed β†’ Q₁ β†’ B₁ β†’ A₁)
    (answerRight : Seed β†’ Qβ‚‚ β†’ Bβ‚‚ β†’ Aβ‚‚)
    (acceptance : βˆ€ seed x y a b,
      H.accepts (left seed x) (right seed y) a b = true β†’
      G.accepts x y (answerLeft seed x a) (answerRight seed y b) = true)
    (strategy : Strategy R₁ Rβ‚‚ B₁ Bβ‚‚) :
    H.success strategy ≀ G.value +
      H.questions.totalVariation (G.localEmbeddingLaw seedLaw left right) := by
  have localBound (seed : Seed) :
      (G.questions.pushforward (fun q => (left seed q.1, right seed q.2))).probability
        (H.wins strategy) ≀ G.value := by
    let embedded : Game R₁ Rβ‚‚ B₁ Bβ‚‚ :=
      { questions := G.questions.pushforward fun q => (left seed q.1, right seed q.2)
        accepts := H.accepts }
    change embedded.success strategy ≀ G.value
    exact (G.success_le_of_localSimulation embedded (left seed) (right seed)
      (answerLeft seed) (answerRight seed) rfl (acceptance seed) strategy).trans
      (G.success_le_value _)
  have mixtureBound :
      (G.localEmbeddingLaw seedLaw left right).probability (H.wins strategy) ≀ G.value :=
    seedLaw.probability_mixture_le _ _ _ localBound
  exact (H.questions.probability_le_add_totalVariation
    (G.localEmbeddingLaw seedLaw left right) (H.wins strategy)).trans
    (add_le_add mixtureBound (le_refl _))

def coordinateGame (G : Game Q₁ Qβ‚‚ A₁ Aβ‚‚) {n : Nat} (coordinate : Fin n)
    (law : FiniteDistribution ((Fin n β†’ Q₁) Γ— (Fin n β†’ Qβ‚‚))) :
    Game (Fin n β†’ Q₁) (Fin n β†’ Qβ‚‚) (Fin n β†’ A₁) (Fin n β†’ Aβ‚‚) where
  questions := law
  accepts x y a b := G.accepts (x coordinate) (y coordinate) (a coordinate) (b coordinate)

theorem coordinate_probability_le_value_add_embedding_distance
    (G : Game Q₁ Qβ‚‚ A₁ Aβ‚‚) {n : Nat} (coordinate : Fin n)
    (law : FiniteDistribution ((Fin n β†’ Q₁) Γ— (Fin n β†’ Qβ‚‚)))
    (seedLaw : FiniteDistribution Seed)
    (left : Seed β†’ Q₁ β†’ Fin n β†’ Q₁) (right : Seed β†’ Qβ‚‚ β†’ Fin n β†’ Qβ‚‚)
    (left_preserves : βˆ€ seed x, left seed x coordinate = x)
    (right_preserves : βˆ€ seed y, right seed y coordinate = y)
    (strategy : Strategy (Fin n β†’ Q₁) (Fin n β†’ Qβ‚‚) (Fin n β†’ A₁) (Fin n β†’ Aβ‚‚)) :
    law.probability (G.coordinateWin strategy coordinate) ≀ G.value +
      law.totalVariation (G.localEmbeddingLaw seedLaw left right) := by
  apply G.success_le_value_add_embedding_distance (G.coordinateGame coordinate law)
    seedLaw left right (fun _ _ a => a coordinate) (fun _ _ b => b coordinate)
  intro seed x y a b h
  simpa only [coordinateGame, left_preserves, right_preserves] using h

theorem coordinate_probability_le_value_of_approximate_embeddings
    {SeedFamily : Nat β†’ Type*} [βˆ€ t, Fintype (SeedFamily t)]
    (G : Game Q₁ Qβ‚‚ A₁ Aβ‚‚) {n : Nat} (coordinate : Fin n)
    (law : FiniteDistribution ((Fin n β†’ Q₁) Γ— (Fin n β†’ Qβ‚‚)))
    (seedLaw : (t : Nat) β†’ FiniteDistribution (SeedFamily t))
    (left : (t : Nat) β†’ SeedFamily t β†’ Q₁ β†’ Fin n β†’ Q₁)
    (right : (t : Nat) β†’ SeedFamily t β†’ Qβ‚‚ β†’ Fin n β†’ Qβ‚‚)
    (left_preserves : βˆ€ t seed x, left t seed x coordinate = x)
    (right_preserves : βˆ€ t seed y, right t seed y coordinate = y)
    (strategy : Strategy (Fin n β†’ Q₁) (Fin n β†’ Qβ‚‚) (Fin n β†’ A₁) (Fin n β†’ Aβ‚‚))
    (distance : ℝ)
    (close : βˆ€ Ξ· : ℝ, 0 < Ξ· β†’ βˆƒ t,
      law.totalVariation (G.localEmbeddingLaw (seedLaw t) (left t) (right t)) ≀
        distance + Ξ·) :
    law.probability (G.coordinateWin strategy coordinate) ≀ G.value + distance := by
  by_contra h
  have gap : 0 < law.probability (G.coordinateWin strategy coordinate) -
      (G.value + distance) := sub_pos.mpr (lt_of_not_ge h)
  obtain ⟨t, ht⟩ := close
    ((law.probability (G.coordinateWin strategy coordinate) - (G.value + distance)) / 2)
    (by linarith)
  have bound := G.coordinate_probability_le_value_add_embedding_distance coordinate law
    (seedLaw t) (left t) (right t) (left_preserves t) (right_preserves t) strategy
  linarith

end
end MinUncutGames.Foundations.Games.Game

namespace MinUncutGames.Foundations.Repetition
open scoped BigOperators
open Games CorrelatedSampling
noncomputable section
variable {Q₁ Qβ‚‚ A₁ Aβ‚‚ S : Type*}
  [Fintype Q₁] [Fintype Qβ‚‚] [Fintype A₁] [Fintype Aβ‚‚] [Fintype S]
  [Nonempty A₁] [Nonempty Aβ‚‚] [Nonempty S]
  [DecidableEq Q₁] [DecidableEq Qβ‚‚] [DecidableEq S] {n : Nat}

theorem coordinate_probability_le_value_of_local_completion
    (G : Game Q₁ Qβ‚‚ A₁ Aβ‚‚) (j : Fin n)
    (strategy : Strategy (Fin n β†’ Q₁) (Fin n β†’ Qβ‚‚) (Fin n β†’ A₁) (Fin n β†’ Aβ‚‚))
    (Οƒ : FiniteDistribution ((Q₁ Γ— Qβ‚‚) Γ— S))
    (profileL : Q₁ β†’ FiniteDistribution S) (profileR : Qβ‚‚ β†’ FiniteDistribution S)
    (completionL : Q₁ Γ— S β†’ FiniteDistribution (Fin n β†’ Q₁))
    (completionR : Qβ‚‚ Γ— S β†’ FiniteDistribution (Fin n β†’ Qβ‚‚))
    (supportL : βˆ€ q xs, (completionL q).weight xs β‰  0 β†’ xs j = q.1)
    (supportR : βˆ€ q ys, (completionR q).weight ys β‰  0 β†’ ys j = q.1)
    (fallback : S) :
    (Οƒ.mixture (fun z => (completionL (z.1.1,z.2)).product
      (completionR (z.1.2,z.2)))).probability (G.coordinateWin strategy j) ≀
      G.value +
        (2 * Information.totalVariation Οƒ.weight
          (fun z => G.questions.weight z.1 * (profileL z.1.1).weight z.2) +
         2 * Information.totalVariation Οƒ.weight
          (fun z => G.questions.weight z.1 * (profileR z.1.2).weight z.2)) := by
  let targetLaw := Οƒ.mixture (fun z => (completionL (z.1.1,z.2)).product (completionR (z.1.2,z.2)))
  let Ξ΄ := 2 * Information.totalVariation Οƒ.weight
      (fun z => G.questions.weight z.1 * (profileL z.1.1).weight z.2) +
    2 * Information.totalVariation Οƒ.weight
      (fun z => G.questions.weight z.1 * (profileR z.1.2).weight z.2)
  change targetLaw.probability (G.coordinateWin strategy j) ≀ G.value + Ξ΄
  by_contra h
  have gap : 0 < targetLaw.probability (G.coordinateWin strategy j) - (G.value + Ξ΄) :=
    sub_pos.mpr (lt_of_not_ge h)
  let Ξ· := (targetLaw.probability (G.coordinateWin strategy j) - (G.value + Ξ΄)) / 2
  have hΞ· : 0 < Ξ· := by dsimp [Ξ·]; linarith
  obtain ⟨N,hN⟩ := samplerOutputLaw_arbitrarily_close Οƒ G.questions profileL profileR fallback Ξ· hΞ·
  let thresholds := sharedProfileThresholds profileL profileR
  let Ξ³ := traceSeedLaw (rectangleDistribution (Ξ± := S) thresholds) N
  let sL := samplerLocal thresholds profileL fallback N
  let sR := samplerLocal thresholds profileR fallback N
  have hvariation := CompletedSampling.coordinateOutputLaw_totalVariation_le
    G.questions Ξ³ j sL sR completionL completionR supportL supportR Οƒ
  have hclose : (CompletedSampling.coordinateOutputLaw G.questions Ξ³ j sL sR completionL completionR).totalVariation targetLaw ≀ Ξ΄ + Ξ· :=
    hvariation.trans hN
  have hsuccess := G.coordinate_probability_le_value_add_embedding_distance j targetLaw
    (CompletedSampling.seedLaw Ξ³ completionL completionR)
    (CompletedSampling.coordinateLeft j sL) (CompletedSampling.coordinateRight j sR)
    (CompletedSampling.coordinateLeft_preserves j sL)
    (CompletedSampling.coordinateRight_preserves j sR) strategy
  have hsym : targetLaw.totalVariation
      (G.localEmbeddingLaw (CompletedSampling.seedLaw Ξ³ completionL completionR)
        (CompletedSampling.coordinateLeft j sL) (CompletedSampling.coordinateRight j sR)) =
      (CompletedSampling.coordinateOutputLaw G.questions Ξ³ j sL sR completionL completionR).totalVariation targetLaw := by
    unfold FiniteDistribution.totalVariation
    congr 1
    apply Finset.sum_congr rfl
    intro q _
    exact abs_sub_comm _ _
  rw [hsym] at hsuccess
  dsimp [Ξ·] at hclose
  linarith

end

noncomputable def logTwo (x : ℝ) : ℝ := Real.log x / Real.log 2

@[simp] theorem logTwo_one : logTwo 1 = 0 := by simp [logTwo]

theorem logTwo_inv_le_of_half_pow_le {p : ℝ} (m : β„•)
    (h : (1 / 2 : ℝ) ^ m ≀ p) : logTwo (1 / p) ≀ m := by
  have hp : 0 < p := (pow_pos (by norm_num : (0 : ℝ) < 1 / 2) m).trans_le h
  have hlog := Real.log_le_log (pow_pos (by norm_num : (0 : ℝ) < 1 / 2) m) h
  have hhalf : Real.log (1 / 2 : ℝ) = -Real.log 2 := by
    rw [one_div, Real.log_inv]
  rw [Real.log_pow, hhalf] at hlog
  unfold logTwo
  rw [one_div, Real.log_inv]
  apply (div_le_iffβ‚€ (Real.log_pos (by norm_num : (1 : ℝ) < 2))).2
  nlinarith

theorem contraction_step {v ell : ℝ} {n m : β„•} {p next : ℝ}
    (hv0 : 0 ≀ v) (hv1 : v < 1) (hell : 1 ≀ ell)
    (hm : 1 ≀ m) (hmn : m < n) (hp : 0 ≀ p)
    (hmono : next ≀ p)
    (hprev : p ≀ ((1 + v) / 2) ^ m)
    (hcut : 2700 * (m : ℝ) * ell ≀ (1 - v) ^ 2 * ((n : ℝ) - m))
    (hstep : next ≀ p * (v + 15 * Real.sqrt
      (((m : ℝ) * ell + logTwo (1 / p)) / ((n : ℝ) - m)))) :
    next ≀ ((1 + v) / 2) ^ (m + 1) := by
  by_cases hsmall : p ≀ ((1 + v) / 2) ^ (m + 1)
  Β· exact hmono.trans hsmall
  have hq : (1 / 2 : ℝ) ≀ (1 + v) / 2 := by linarith
  have hhalf : (1 / 2 : ℝ) ^ (m + 1) ≀ p :=
    (pow_le_pow_leftβ‚€ (by norm_num) hq (m + 1)).trans (le_of_not_ge hsmall)
  have hlog := logTwo_inv_le_of_half_pow_le (m + 1) hhalf
  have hmreal : (1 : ℝ) ≀ m := by exact_mod_cast hm
  have hden : 0 < (n : ℝ) - m := by
    have hmnreal : (m : ℝ) < n := by exact_mod_cast hmn
    linarith
  have hmell : (m : ℝ) ≀ (m : ℝ) * ell := by nlinarith
  have hbudget : (m : ℝ) * ell + logTwo (1 / p) ≀ 3 * (m : ℝ) * ell := by
    simp only [Nat.cast_add, Nat.cast_one] at hlog
    nlinarith
  have hsqrt : Real.sqrt
      (((m : ℝ) * ell + logTwo (1 / p)) / ((n : ℝ) - m)) ≀ (1 - v) / 30 := by
    apply (Real.sqrt_le_left (by linarith : 0 ≀ (1 - v) / 30)).2
    apply (div_le_iffβ‚€ hden).2
    nlinarith
  have hfactor : v + 15 * Real.sqrt
      (((m : ℝ) * ell + logTwo (1 / p)) / ((n : ℝ) - m)) ≀ (1 + v) / 2 := by
    linarith
  calc
    next ≀ p * (v + 15 * Real.sqrt
        (((m : ℝ) * ell + logTwo (1 / p)) / ((n : ℝ) - m))) := hstep
    _ ≀ p * ((1 + v) / 2) := mul_le_mul_of_nonneg_left hfactor hp
    _ ≀ ((1 + v) / 2) ^ m * ((1 + v) / 2) :=
      mul_le_mul_of_nonneg_right hprev (by linarith)
    _ = ((1 + v) / 2) ^ (m + 1) := (pow_succ _ _).symm

theorem initial_step {v ell next : ℝ} {n : β„•}
    (hstep : next ≀ 1 * (v + 15 * Real.sqrt
      (((0 : ℝ) * ell + logTwo (1 / 1)) / ((n : ℝ) - 0)))) :
    next ≀ v := by simpa using hstep

theorem cutoff_step {v ell : ℝ} {n m : β„•}
    (hv0 : 0 ≀ v) (hv1 : v < 1) (hell : 1 ≀ ell)
    (hm : (m : ℝ) < (n : ℝ) * (1 - v) ^ 2 / (2925 * ell)) :
    2700 * (m : ℝ) * ell ≀ (1 - v) ^ 2 * ((n : ℝ) - m) := by
  have hell0 : 0 < ell := by linarith
  have hd : (1 - v) ^ 2 ≀ 1 := by nlinarith
  have hmul : (m : ℝ) * (2925 * ell) < (n : ℝ) * (1 - v) ^ 2 :=
    (lt_div_iffβ‚€ (by positivity : 0 < 2925 * ell)).1 hm
  have hdell : (1 - v) ^ 2 ≀ 225 * ell := by linarith
  have hprod := mul_le_mul_of_nonneg_left hdell (Nat.cast_nonneg m : (0 : ℝ) ≀ m)
  nlinarith

theorem cutoff_le_length {v ell : ℝ} (n : β„•)
    (hv0 : 0 ≀ v) (hv1 : v < 1) (hell : 1 ≀ ell) :
    (n : ℝ) * (1 - v) ^ 2 / (2925 * ell) ≀ n := by
  have hell0 : 0 < ell := by linarith
  apply (div_le_iffβ‚€ (by positivity : 0 < 2925 * ell)).2
  have hd : (1 - v) ^ 2 ≀ 2925 * ell := by nlinarith
  nlinarith [mul_le_mul_of_nonneg_left hd (Nat.cast_nonneg n : (0 : ℝ) ≀ n)]

def ScalarRecurrence (p : β„• β†’ ℝ) (n : β„•) (v ell : ℝ) : Prop :=
  βˆ€ m, m < n β†’ p (m + 1) ≀ p m * (v + 15 * Real.sqrt
    (((m : ℝ) * ell + logTwo (1 / p m)) / ((n : ℝ) - m)))

theorem decay_to_cutoff (p : β„• β†’ ℝ) (n : β„•) {v ell : ℝ}
    (hv0 : 0 ≀ v) (hv1 : v < 1) (hell : 1 ≀ ell)
    (hp0 : p 0 = 1) (hpnonneg : βˆ€ m, 0 ≀ p m)
    (hpmono : Antitone p) (hrec : ScalarRecurrence p n v ell) :
    p n ≀ ((1 + v) / 2) ^
      ((n : ℝ) * (1 - v) ^ 2 / (2925 * ell)) := by
  let T : ℝ := (n : ℝ) * (1 - v) ^ 2 / (2925 * ell)
  let M : β„• := Nat.ceil T
  have hMn : M ≀ n := Nat.ceil_le.mpr (cutoff_le_length n hv0 hv1 hell)
  have hind : βˆ€ m, m ≀ M β†’ p m ≀ ((1 + v) / 2) ^ m := by
    intro m
    induction m with
    | zero => intro _; simp [hp0]
    | succ m ih =>
        intro hmM
        have hmM' : m < M := Nat.lt_of_succ_le hmM
        have hmn : m < n := hmM'.trans_le hMn
        have hprev := ih (Nat.le_of_lt hmM')
        by_cases hm0 : m = 0
        Β· subst m
          have hinit : p 1 ≀ v := by
            have hs := hrec 0 hmn
            simpa [hp0] using hs
          simpa using hinit.trans (by linarith : v ≀ (1 + v) / 2)
        Β· have hmT : (m : ℝ) < T := Nat.lt_ceil.mp hmM'
          exact contraction_step hv0 hv1 hell (Nat.one_le_iff_ne_zero.mpr hm0)
            hmn (hpnonneg m) (hpmono (Nat.le_succ m)) hprev
            (cutoff_step hv0 hv1 hell hmT) (hrec m hmn)
  have hq0 : 0 < (1 + v) / 2 := by linarith
  have hq1 : (1 + v) / 2 ≀ 1 := by linarith
  calc
    p n ≀ p M := hpmono hMn
    _ ≀ ((1 + v) / 2) ^ M := hind M le_rfl
    _ = ((1 + v) / 2) ^ (M : ℝ) := (Real.rpow_natCast _ _).symm
    _ ≀ ((1 + v) / 2) ^ T :=
      Real.rpow_le_rpow_of_exponent_ge hq0 hq1 (Nat.le_ceil T)

theorem block_contraction {v : ℝ} (hv0 : 0 ≀ v) (hv1 : v < 1) :
    ((1 + v) / 2) ^ ((1 - v) ^ 2 / 2925 : ℝ) ≀
      1 - (1 - v) ^ 3 / 5850 := by
  have hd : (1 - v) ^ 2 ≀ 1 := by nlinarith
  have hb := rpow_one_add_le_one_add_mul_self
    (s := -(1 - v) / 2) (p := (1 - v) ^ 2 / 2925)
    (by linarith) (by positivity) (by nlinarith)
  have hbase : 1 + -(1 - v) / 2 = (1 + v) / 2 := by ring
  have hrhs : 1 + (1 - v) ^ 2 / 2925 * (-(1 - v) / 2) =
      1 - (1 - v) ^ 3 / 5850 := by ring
  rwa [hbase, hrhs] at hb

theorem scalar_bound_6000 (p : β„• β†’ ℝ) (n : β„•) {v ell : ℝ}
    (hv0 : 0 ≀ v) (hv1 : v < 1) (hell : 1 ≀ ell)
    (hp0 : p 0 = 1) (hpnonneg : βˆ€ m, 0 ≀ p m)
    (hpmono : Antitone p) (hrec : ScalarRecurrence p n v ell) :
    p n ≀ (1 - (1 - v) ^ 3 / 6000) ^ ((n : ℝ) / ell) := by
  have hell0 : 0 < ell := by linarith
  have hq0 : 0 ≀ (1 + v) / 2 := by linarith
  have hexp : 0 ≀ (n : ℝ) / ell := by positivity
  have hblock := block_contraction hv0 hv1
  have hweak : 1 - (1 - v) ^ 3 / 5850 ≀ 1 - (1 - v) ^ 3 / 6000 := by
    have : 0 ≀ (1 - v) ^ 3 := by positivity
    nlinarith
  calc
    p n ≀ ((1 + v) / 2) ^
        ((n : ℝ) * (1 - v) ^ 2 / (2925 * ell)) :=
      decay_to_cutoff p n hv0 hv1 hell hp0 hpnonneg hpmono hrec
    _ = (((1 + v) / 2) ^ ((1 - v) ^ 2 / 2925 : ℝ)) ^ ((n : ℝ) / ell) := by
      rw [← Real.rpow_mul hq0]
      congr 1
      ring
    _ ≀ (1 - (1 - v) ^ 3 / 6000) ^ ((n : ℝ) / ell) :=
      Real.rpow_le_rpow (Real.rpow_nonneg hq0 _) (hblock.trans hweak) hexp

noncomputable def incidenceRate : ℝ := 1 - 1 / (100000 * 192 ^ 3)

theorem incidenceRate_pos : 0 < incidenceRate := by norm_num [incidenceRate]

theorem incidenceRate_lt_one : incidenceRate < 1 := by norm_num [incidenceRate]

theorem incidenceRate_fourth :
    1 - (1 / 192 : ℝ) ^ 3 / 6000 ≀ incidenceRate ^ 4 := by
  norm_num [incidenceRate]

theorem incidence_rate_comparison (n : β„•) :
    (1 - (1 / 192 : ℝ) ^ 3 / 6000) ^ ((n : ℝ) / 4) ≀ incidenceRate ^ n := by
  calc
    (1 - (1 / 192 : ℝ) ^ 3 / 6000) ^ ((n : ℝ) / 4)
        ≀ (incidenceRate ^ 4) ^ ((n : ℝ) / 4) :=
      Real.rpow_le_rpow (by norm_num) incidenceRate_fourth (by positivity)
    _ = incidenceRate ^ ((4 : ℝ) * ((n : ℝ) / 4)) :=
      (Real.rpow_natCast_mul incidenceRate_pos.le 4 ((n : ℝ) / 4)).symm
    _ = incidenceRate ^ (n : ℝ) := by congr 1; ring
    _ = incidenceRate ^ n := Real.rpow_natCast _ _

theorem scalar_incidence_bound (p : β„• β†’ ℝ) (n : β„•) {v : ℝ}
    (hv : v ≀ 1 - (1 / 192 : ℝ))
    (hp0 : p 0 = 1) (hpnonneg : βˆ€ m, 0 ≀ p m)
    (hpmono : Antitone p) (hrec : ScalarRecurrence p n v 4) :
    p n ≀ incidenceRate ^ n := by
  have hrec' : ScalarRecurrence p n (1 - (1 / 192 : ℝ)) 4 := by
    intro m hm
    exact (hrec m hm).trans (mul_le_mul_of_nonneg_left (by linarith) (hpnonneg m))
  have hbound := scalar_bound_6000 p n
    (v := 1 - (1 / 192 : ℝ)) (ell := 4)
    (by norm_num) (by norm_num) (by norm_num) hp0 hpnonneg hpmono hrec'
  norm_num only [sub_sub_cancel] at hbound
  have hcomparison := incidence_rate_comparison n
  norm_num at hcomparison
  exact hbound.trans hcomparison

end MinUncutGames.Foundations.Repetition

end OAI