File size: 28,380 Bytes
b797a5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.NumberTheory.PrimePackets.LeafAnchors

namespace OAI

section
noncomputable section
open scoped Matrix Topology BigOperators Classical TensorProduct ENNReal
open MeasureTheory Filter Set Module
universe u
open scoped TensorProduct
open Set Module
open MeasureTheory Set
open scoped ENNReal
open IsDiscreteValuationRing IsLocalRing
open scoped ENNReal BigOperators
open MeasureTheory Set IsDiscreteValuationRing
open Filter
open scoped BigOperators Topology
open NumberField
open scoped NumberField nonZeroDivisors
open scoped BigOperators ArithmeticFunction.zeta
open Finset
open scoped BigOperators Classical
open Finset Nat ArithmeticFunction BoundingSieve
open scoped BigOperators Classical
open Finset Nat
open scoped BigOperators
open Filter Topology
open scoped nonZeroDivisors
open Ideal NumberField Finset UniqueFactorizationMonoid
open Filter Set Topology NumberField
open scoped Matrix Topology BigOperators Classical TensorProduct ENNReal NumberField Pointwise nonZeroDivisors
open MeasureTheory Filter Set Module NumberField FractionalIdeal Topology TopologicalSpace
open Filter Set Topology
open scoped Matrix Topology BigOperators Classical TensorProduct ENNReal NumberField Pointwise nonZeroDivisors RealInnerProductSpace
open MeasureTheory Filter Set Module NumberField FractionalIdeal Topology TopologicalSpace Matrix
open MeasureTheory Filter Set Module TopologicalSpace
open MeasureTheory Filter Set
open scoped BigOperators Topology ENNReal
open scoped BigOperators Topology ENNReal Classical
open scoped BigOperators Topology ENNReal Classical Matrix Matrix.Norms.Elementwise
open scoped BigOperators Topology ENNReal Classical Matrix Matrix.Norms.Elementwise Pointwise
open scoped BigOperators Topology ENNReal Classical Matrix Pointwise
open scoped BigOperators Topology ENNReal Classical Matrix
open MeasureTheory ProbabilityTheory Filter Set
open Set Filter
open scoped Topology
open scoped Classical
open scoped Topology ENNReal Classical
open scoped ENNReal Classical
open MeasureTheory Set Topology UniformSpace TopologicalSpace
open scoped ENNReal Topology
open MeasureTheory Filter Set Matrix
open scoped Topology Classical
open scoped Matrix Classical
open scoped Topology Classical Matrix
open scoped Classical Pointwise
open scoped Topology Classical ENNReal
open scoped Matrix Topology Classical
open MeasureTheory ProbabilityTheory Set Filter
open scoped Matrix Topology Classical ENNReal ProbabilityTheory
open scoped ENNReal ProbabilityTheory
open Set Filter Topology
open Set Filter Topology MeasureTheory
open MeasureTheory Set Filter Topology
open MeasureTheory ProbabilityTheory Set Filter Topology
open scoped Matrix ENNReal NNReal ProbabilityTheory
open MeasureTheory
open scoped BigOperators ENNReal
open NumberField Finset
open NumberField Filter Set Topology
open MeasureTheory ProbabilityTheory Matrix
open scoped Classical BigOperators ENNReal
open MeasureTheory Set Filter Topology Module
open scoped BigOperators SchwartzMap
open MeasureTheory Set Filter Topology Module WithLp
open scoped BigOperators SchwartzMap ZeroAtInfty
open scoped FourierTransform
open scoped BigOperators SchwartzMap FourierTransform
open scoped BigOperators FourierTransform
open MeasureTheory Set Filter Topology Module WithLp Asymptotics
open Module WithLp MeasureTheory
open scoped BigOperators Matrix
open Module MeasureTheory
open MeasureTheory Module WithLp
open scoped BigOperators NumberField nonZeroDivisors ENNReal
open Complex Set Metric Filter
open Complex Set Metric Filter MeromorphicOn
open scoped Topology ComplexConjugate
open MeasureTheory Set Filter
open scoped ENNReal BigOperators Topology
open MeasureTheory Set Module
open scoped BigOperators ENNReal NumberField nonZeroDivisors
open scoped BigOperators ENNReal NumberField nonZeroDivisors Topology
open Set
open Filter Set Module MeasureTheory
open scoped Topology NumberField
open Filter Set Module MeasureTheory WithLp
open scoped Topology NumberField BigOperators nonZeroDivisors
open scoped Topology NumberField BigOperators nonZeroDivisors ComplexConjugate
open MeasureTheory Set Filter Module WithLp
open scoped Topology BigOperators NumberField nonZeroDivisors
open Complex Set Filter Module
open Complex
open Complex Set Filter
open scoped Topology NumberField ComplexConjugate
open scoped Topology NumberField ComplexConjugate Classical
open Filter Set Topology Module
open MeasureTheory ProbabilityTheory Set Filter TopologicalSpace
open MeasureTheory MeasureTheory.Measure ProbabilityTheory Set Filter
open scoped Matrix Topology Classical ENNReal NNReal ProbabilityTheory
namespace PrimeDegreePackets
variable {α β γ δ : Type*} [MeasurableSpace α] [MeasurableSpace β]
  [MeasurableSpace γ] [MeasurableSpace δ]

lemma fst_map_fibers_of_measurable (ρ : Measure (α × β))
    (e : α → γ) (he : Measurable e) (F : α × β → δ) (hF : Measurable F) :
    (ρ.map (fun z => (e z.1,F z))).fst = ρ.fst.map e := by
  have hfull : Measurable (fun z : α × β => (e z.1,F z)) := (he.comp measurable_fst).prodMk hF
  rw [Measure.fst,Measure.map_map measurable_fst hfull,
    Measure.fst,Measure.map_map he measurable_fst]
  rfl

lemma compProd_map_fibers_leftInverse (μ : Measure α) [SFinite μ] (κ : Kernel α β)
    [IsFiniteKernel κ] (e : α → γ) (he : Measurable e)
    (r : γ → α) (hr : Measurable r) (hre : Function.LeftInverse r e)
    (F : α × β → δ) (hF : Measurable F) :
    (μ ⊗ₘ κ).map (fun z => (e z.1,F z)) =
      μ.map e ⊗ₘ (mapFibers κ F hF).comap r hr := by
  have hfull : Measurable (fun z : α × β => (e z.1,F z)) := (he.comp measurable_fst).prodMk hF
  ext S hS
  rw [Measure.map_apply hfull hS,Measure.compProd_apply (hfull hS),Measure.compProd_apply hS,
    lintegral_map (Kernel.measurable_kernel_prodMk_left hS) he]
  apply lintegral_congr
  intro a
  rw [Kernel.comap_apply,hre a,mapFibers_apply]
  exact (Measure.map_apply (hF.comp measurable_prodMk_left)
    (show MeasurableSet (Prod.mk (e a) ⁻¹' S) from measurable_prodMk_left hS)).symm

lemma conditional_map_fibers_leftInverse [StandardBorelSpace β] [Nonempty β]
    [StandardBorelSpace δ] [Nonempty δ] (ρ : Measure (α × β)) [IsFiniteMeasure ρ]
    (e : α → γ) (he : Measurable e) (r : γ → α) (hr : Measurable r)
    (hre : Function.LeftInverse r e) (F : α × β → δ) (hF : Measurable F) :
    ∀ᵐ a ∂ρ.fst, (ρ.map (fun z => (e z.1,F z))).condKernel (e a) =
      (ρ.condKernel a).map (fun b => F (a,b)) := by
  let κ := (mapFibers ρ.condKernel F hF).comap r hr
  have heq : ρ.map (fun z => (e z.1,F z)) = (ρ.map (fun z => (e z.1,F z))).fst ⊗ₘ κ := by
    rw [fst_map_fibers_of_measurable ρ e he F hF,
      ←compProd_map_fibers_leftInverse ρ.fst ρ.condKernel e he r hr hre F hF,
      Measure.disintegrate]
  have H := eq_condKernel_of_measure_eq_compProd κ heq
  rw [fst_map_fibers_of_measurable ρ e he F hF] at H
  have H' := ae_of_ae_map he.aemeasurable H
  filter_upwards [H'] with a ha
  simpa only [κ,Kernel.comap_apply,hre a,mapFibers_apply] using ha.symm

 

theorem conditional_map_fibers_embedding [StandardBorelSpace β] [Nonempty β]
    [StandardBorelSpace δ] [Nonempty δ] (ρ : Measure (α × β)) [IsFiniteMeasure ρ]
    (e : α → γ) (he : MeasurableEmbedding e) (F : α × β → δ) (hF : Measurable F) :
    ∀ᵐ a ∂ρ.fst, (ρ.map (fun z => (e z.1,F z))).condKernel (e a) =
      (ρ.condKernel a).map (fun b => F (a,b)) := by
  cases isEmpty_or_nonempty α with
  | inl h => exact ae_of_all _ (fun a => isEmptyElim a)
  | inr h =>
    exact conditional_map_fibers_leftInverse ρ e he.measurable he.invFun
      he.measurable_invFun he.leftInverse_invFun F hF

end PrimeDegreePackets


namespace PrimeDegreePackets
variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]

abbrev baseSubtypeMap (U : Set α) : U × β → α × β := fun z => (z.1.val,z.2)

lemma baseSubtypeMap_embedding (U : Set α) (hU : MeasurableSet U) :
    MeasurableEmbedding (baseSubtypeMap (β := β) U) :=
  (MeasurableEmbedding.subtype_coe hU).prodMap MeasurableEmbedding.id

omit [MeasurableSpace α] [MeasurableSpace β] in
lemma baseSubtypeMap_range (U : Set α) :
    Set.range (baseSubtypeMap (β := β) U) = U ×ˢ univ := by
  ext z
  simp only [Set.mem_range,Set.mem_prod,Set.mem_univ,and_true]
  constructor
  · rintro ⟨x,rfl⟩; exact x.1.prop
  · intro hz; exact ⟨(⟨z.1,hz⟩,z.2),Prod.ext rfl rfl⟩

lemma map_comap_baseSubtype (ρ : Measure (α × β)) (U : Set α) (hU : MeasurableSet U) :
    (ρ.comap (baseSubtypeMap U)).map (baseSubtypeMap U) = ρ.restrict (U ×ˢ univ) := by
  rw [(baseSubtypeMap_embedding U hU).map_comap,baseSubtypeMap_range]

lemma fst_map_comap_baseSubtype [StandardBorelSpace β] [Nonempty β]
    (ρ : Measure (α × β)) [IsFiniteMeasure ρ] (U : Set α) (hU : MeasurableSet U) :
    ((ρ.comap (baseSubtypeMap U)).fst).map Subtype.val = ρ.fst.restrict U := by
  rw [←fst_map_fibers_of_measurable _ Subtype.val measurable_subtype_coe Prod.snd measurable_snd]
  change ((ρ.comap (baseSubtypeMap U)).map (baseSubtypeMap U)).fst = _
  rw [map_comap_baseSubtype ρ U hU,restricted_conditional_marginal ρ hU MeasurableSet.univ]
  simp only [measure_univ]
  exact MeasureTheory.withDensity_one

theorem conditional_comap_baseSubtype [StandardBorelSpace β] [Nonempty β]
    (ρ : Measure (α × β)) [IsFiniteMeasure ρ] (U : Set α) (hU : MeasurableSet U) :
    ∀ᵐ a ∂(ρ.comap (baseSubtypeMap U)).fst,
      (ρ.comap (baseSubtypeMap U)).condKernel a = ρ.condKernel a.val := by
  have H₁ := conditional_map_fibers_embedding (ρ.comap (baseSubtypeMap U))
    Subtype.val (MeasurableEmbedding.subtype_coe hU) Prod.snd measurable_snd
  have he : (ρ.comap (baseSubtypeMap U)).map (fun z => (z.1.val,Prod.snd z)) =
      ρ.restrict (U ×ˢ univ) := map_comap_baseSubtype ρ U hU
  have H₂ : ∀ᵐ a ∂ρ.fst.restrict U,
      (ρ.restrict (U ×ˢ univ)).condKernel a = ρ.condKernel a := by
    filter_upwards [restricted_conditional_kernel ρ hU MeasurableSet.univ] with a ha
    simpa only [measure_univ,one_smul,Measure.restrict_univ] using ha
  rw [←fst_map_comap_baseSubtype ρ U hU] at H₂
  have H₂' := ae_of_ae_map measurable_subtype_coe.aemeasurable H₂
  filter_upwards [H₁,H₂'] with a ha hb
  simp only [he] at ha
  exact (Measure.map_id (μ := (ρ.comap (baseSubtypeMap U)).condKernel a)).symm.trans
    (ha.symm.trans hb)

end PrimeDegreePackets


namespace PrimeDegreePackets
variable {n : ℕ} {i j k l : Fin n} {hij : i ≠ j}

lemma rootSliceOverlap_isOpen (γ : G n) :
    IsOpen {s : RootSlice i j k | (γ * s.val).1 l i ≠ 0} := by
  apply isOpen_ne_fun _ continuous_const
  have hc : Continuous (fun s : RootSlice i j k =>
      ((γ * s.val) : Matrix (Fin n) (Fin n) ℝ)) :=
    Matrix.SpecialLinearGroup.isClosedEmbedding_val.continuous.comp
      (show Continuous (fun s : RootSlice i j k => γ * s.val) from
        continuous_const.mul continuous_subtype_val)
  exact (continuous_apply i).comp ((continuous_apply l).comp hc)

abbrev rootOverlapParam (hij : i ≠ j) (γ : G n) : RootSliceOverlap i j k l γ × ℝ → X n :=
  fun z => rootQuotientParametrization hij (z.1.val,z.2)

namespace RootBox

abbrev overlapDomain (A : RootBox hij k) (γ : G n) (l : Fin n) :
    Set (RootSliceOverlap i j k l γ × ℝ) :=
  baseSubtypeMap {s : RootSlice i j k | (γ * s.val).1 l i ≠ 0} ⁻¹' A.domain

def overlapMeasure (A : RootBox hij k) (γ : G n) (l : Fin n) (μ : Measure (X n)) :
    Measure (RootSliceOverlap i j k l γ × ℝ) :=
  (A.coordinateMeasure μ).comap (baseSubtypeMap {s : RootSlice i j k | (γ * s.val).1 l i ≠ 0})

instance overlapMeasure_finite (A : RootBox hij k) (γ : G n) (l : Fin n)
    (μ : Measure (X n)) [IsFiniteMeasure μ] : IsFiniteMeasure (A.overlapMeasure γ l μ) := by
  unfold overlapMeasure
  infer_instance

lemma overlapDomain_open (A : RootBox hij k) (γ : G n) (l : Fin n) :
    IsOpen (A.overlapDomain γ l) :=
  (A.transverse_open.prod A.time_open).preimage
    ((continuous_subtype_val.comp continuous_fst).prodMk continuous_snd)

lemma overlapMeasure_apply (A : RootBox hij k) (γ : G n) (l : Fin n)
    (μ : Measure (X n)) {S : Set (RootSliceOverlap i j k l γ × ℝ)} (hS : MeasurableSet S) :
    A.overlapMeasure γ l μ S =
      μ (rootOverlapParam hij γ '' (S ∩ A.overlapDomain γ l)) := by
  let U := {s : RootSlice i j k | (γ * s.val).1 l i ≠ 0}
  have he := baseSubtypeMap_embedding (β := ℝ) U (rootSliceOverlap_isOpen γ).measurableSet
  rw [overlapMeasure,he.comap_apply,A.coordinateMeasure_apply μ (he.measurableSet_image.mpr hS)]
  congr 1
  ext x
  constructor
  · rintro ⟨z,⟨⟨w,hw,rfl⟩,hd⟩,rfl⟩
    exact ⟨w,⟨hw,hd⟩,rfl⟩
  · rintro ⟨w,⟨hw,hd⟩,rfl⟩
    exact ⟨baseSubtypeMap U w,⟨⟨w,hw,rfl⟩,hd⟩,rfl⟩

lemma overlapMeasure_conditional (A : RootBox hij k) (γ : G n) (l : Fin n)
    (μ : Measure (X n)) [IsFiniteMeasure μ] :
    ∀ᵐ s ∂(A.overlapMeasure γ l μ).fst,
      (A.overlapMeasure γ l μ).condKernel s = A.conditionalKernel μ s.val :=
  conditional_comap_baseSubtype (A.coordinateMeasure μ) _ (rootSliceOverlap_isOpen γ).measurableSet

 

theorem overlapMeasure_transition (A : RootBox hij k) (B : RootBox hij l)
    (γ : G n) (hγ : γ ∈ integralGroup n) (μ : Measure (X n)) :
    ((A.overlapMeasure γ l μ).restrict
      ((rootTransitionCoordinates hij γ) ⁻¹' B.overlapDomain γ⁻¹ k)).map
        (rootTransitionCoordinates hij γ) =
      (B.overlapMeasure γ⁻¹ k μ).restrict
        (rootTransitionCoordinates hij γ '' A.overlapDomain γ l) := by
  let E := rootTransitionCoordinates (k := k) (l := l) hij γ
  ext S hS
  rw [Measure.map_apply E.measurable hS,Measure.restrict_apply (E.measurable hS),
    A.overlapMeasure_apply γ l μ ((E.measurable hS).inter
      (E.measurable (B.overlapDomain_open γ⁻¹ k).measurableSet)),
    Measure.restrict_apply hS,B.overlapMeasure_apply γ⁻¹ k μ
      (hS.inter (E.measurableEmbedding.measurableSet_image.mpr
        (A.overlapDomain_open γ l).measurableSet))]
  congr 1
  ext x
  constructor
  · rintro ⟨z,⟨⟨hzS,hzB⟩,hzA⟩,rfl⟩
    exact ⟨E z,⟨⟨hzS,⟨z,hzA,rfl⟩⟩,hzB⟩,rootTransitionCoordinates_param hij γ hγ z⟩
  · rintro ⟨w,⟨⟨hwS,z,hzA,rfl⟩,hzB⟩,rfl⟩
    exact ⟨z,⟨⟨hwS,hzB⟩,hzA⟩,(rootTransitionCoordinates_param hij γ hγ z).symm⟩

end RootBox
end PrimeDegreePackets


namespace PrimeDegreePackets
variable {α β γ δ : Type*} [MeasurableSpace α] [MeasurableSpace β]
  [MeasurableSpace γ] [MeasurableSpace δ]

lemma conditional_restrict_normalized [StandardBorelSpace β] [Nonempty β]
    (ρ : Measure (α × β)) [IsFiniteMeasure ρ] (T : Set (α × β)) (hT : MeasurableSet T) :
    ∀ᵐ a ∂(ρ.restrict T).fst,
      ρ.condKernel a (Prod.mk a ⁻¹' T) ≠ 0 ∧
      (ρ.restrict T).condKernel a =
        (anchorNormalize (ρ.condKernel a) (Prod.mk a ⁻¹' T)).restrict (Prod.mk a ⁻¹' T) := by
  let w := fun a => ρ.condKernel a (Prod.mk a ⁻¹' T)
  have hw : Measurable w := Kernel.measurable_kernel_prodMk_left hT
  have hp : ∀ᵐ a ∂(ρ.restrict T).fst, w a ≠ 0 := by
    rw [conditional_restrict_marginal ρ T hT]
    exact (ae_withDensity_iff hw).mpr (ae_of_all _ fun _ h => h)
  have H : ∀ᵐ a ∂(ρ.restrict T).fst,
      w a • (ρ.restrict T).condKernel a = (ρ.condKernel a).restrict (Prod.mk a ⁻¹' T) := by
    rw [conditional_restrict_marginal ρ T hT]
    exact (withDensity_absolutelyContinuous ρ.fst w).ae_le (conditional_restrict_fibers ρ T hT)
  filter_upwards [hp,H] with a hpa ha
  refine ⟨hpa,?_⟩
  have he := congrArg (fun ν : Measure β => (w a)⁻¹ • ν) ha
  rw [smul_smul,ENNReal.inv_mul_cancel hpa (measure_ne_top _ _),one_smul] at he
  simpa only [anchorNormalize,Measure.restrict_smul] using he

 

theorem conditional_overlap_normalized [StandardBorelSpace β] [Nonempty β]
    [StandardBorelSpace δ] [Nonempty δ]
    (ρ : Measure (α × β)) [IsFiniteMeasure ρ]
    (σ : Measure (γ × δ)) [IsFiniteMeasure σ]
    (T : Set (α × β)) (hT : MeasurableSet T)
    (W : Set (γ × δ)) (hW : MeasurableSet W)
    (e : α ≃ᵐ γ) (F : α × β → δ) (hF : Measurable F)
    (he : (ρ.restrict T).map (fun z => (e z.1,F z)) = σ.restrict W) :
    ∀ᵐ a ∂(ρ.restrict T).fst,
      ρ.condKernel a (Prod.mk a ⁻¹' T) ≠ 0 ∧
      σ.condKernel (e a) (Prod.mk (e a) ⁻¹' W) ≠ 0 ∧
      ((anchorNormalize (ρ.condKernel a) (Prod.mk a ⁻¹' T)).restrict (Prod.mk a ⁻¹' T)).map
        (fun b => F (a,b)) =
      (anchorNormalize (σ.condKernel (e a)) (Prod.mk (e a) ⁻¹' W)).restrict (Prod.mk (e a) ⁻¹' W) := by
  have Hρ := conditional_restrict_normalized ρ T hT
  have Hσ := conditional_restrict_normalized σ W hW
  have hm := congrArg Measure.fst he
  rw [fst_map_fibers _ e F hF] at hm
  rw [←hm] at Hσ
  have Hσ' := ae_of_ae_map e.measurable.aemeasurable Hσ
  have Hcov := conditional_map_fibers (ρ.restrict T) e F hF
  filter_upwards [Hρ,Hσ',Hcov] with a ha hb hc
  simp only [he] at hc
  refine ⟨ha.1,hb.1,?_⟩
  rw [←ha.2,←hb.2]
  exact hc.symm

end PrimeDegreePackets


namespace PrimeDegreePackets.RootBox
variable {n : ℕ} {i j k l : Fin n} {hij : i ≠ j}

theorem overlap_conditional_projective (A : RootBox hij k) (B : RootBox hij l)
    (γ : G n) (hγ : γ ∈ integralGroup n) (μ : Measure (X n)) [IsFiniteMeasure μ] :
    let E := rootTransitionCoordinates (k := k) (l := l) hij γ
    let T := E ⁻¹' B.overlapDomain γ⁻¹ k
    let W := E '' A.overlapDomain γ l
    ∀ᵐ s ∂((A.overlapMeasure γ l μ).restrict T).fst,
      A.conditionalKernel μ s.val (Prod.mk s ⁻¹' T) ≠ 0 ∧
      B.conditionalKernel μ (rootTransitionSlice hij γ s).val
        (Prod.mk (rootTransitionSlice hij γ s) ⁻¹' W) ≠ 0 ∧
      ((anchorNormalize (A.conditionalKernel μ s.val) (Prod.mk s ⁻¹' T)).restrict
        (Prod.mk s ⁻¹' T)).map (Homeomorph.addRight (rootTransitionTime γ s)) =
      (anchorNormalize (B.conditionalKernel μ (rootTransitionSlice hij γ s).val)
        (Prod.mk (rootTransitionSlice hij γ s) ⁻¹' W)).restrict
        (Prod.mk (rootTransitionSlice hij γ s) ⁻¹' W) := by
  intro E T W
  let e := (rootSliceTransition (k := k) (l := l) hij γ).toMeasurableEquiv
  let F : RootSliceOverlap i j k l γ × ℝ → ℝ := fun z => z.2 + rootTransitionTime γ z.1
  have hF : Measurable F := measurable_snd.add
    ((continuous_rootTransitionTime γ).measurable.comp measurable_fst)
  have H := conditional_overlap_normalized (A.overlapMeasure γ l μ) (B.overlapMeasure γ⁻¹ k μ)
    T (E.measurable (B.overlapDomain_open γ⁻¹ k).measurableSet)
    W (E.measurableEmbedding.measurableSet_image.mpr (A.overlapDomain_open γ l).measurableSet)
    e F hF (A.overlapMeasure_transition B γ hγ μ)
  have HA : ∀ᵐ s ∂((A.overlapMeasure γ l μ).restrict T).fst,
      (A.overlapMeasure γ l μ).condKernel s = A.conditionalKernel μ s.val :=
    (Measure.absolutelyContinuous_of_le (Measure.fst_mono Measure.restrict_le_self)).ae_le
      (A.overlapMeasure_conditional γ l μ)
  have HB : ∀ᵐ t ∂((B.overlapMeasure γ⁻¹ k μ).restrict W).fst,
      (B.overlapMeasure γ⁻¹ k μ).condKernel t = B.conditionalKernel μ t.val :=
    (Measure.absolutelyContinuous_of_le (Measure.fst_mono Measure.restrict_le_self)).ae_le
      (B.overlapMeasure_conditional γ⁻¹ k μ)
  have hm := congrArg Measure.fst (A.overlapMeasure_transition B γ hγ μ)
  change (((A.overlapMeasure γ l μ).restrict T).map (fun z => (e z.1,F z))).fst = _ at hm
  rw [fst_map_fibers _ e F hF] at hm
  rw [←hm] at HB
  have HB' := ae_of_ae_map e.measurable.aemeasurable HB
  filter_upwards [H,HA,HB'] with s hs ha hb
  rw [ha,hb] at hs
  exact hs

end PrimeDegreePackets.RootBox


namespace PrimeDegreePackets

lemma fst_restrict_base {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]
    (ρ : Measure (α × β)) {U : Set α} (hU : MeasurableSet U) :
    (ρ.restrict (Prod.fst ⁻¹' U)).fst = ρ.fst.restrict U := by
  exact (Measure.restrict_map measurable_fst hU).symm

namespace RootBox
variable {n : ℕ} {i j k l : Fin n} {hij : i ≠ j}

abbrev transitionOverlapMeasure (A : RootBox hij k) (B : RootBox hij l)
    (γ : G n) (μ : Measure (X n)) : Measure (RootSliceOverlap i j k l γ × ℝ) :=
  (A.overlapMeasure γ l μ).restrict
    ((rootTransitionCoordinates hij γ) ⁻¹' B.overlapDomain γ⁻¹ k)

lemma transitionOverlapMeasure_apply (A : RootBox hij k) (B : RootBox hij l)
    (γ : G n) (μ : Measure (X n)) {S : Set (RootSliceOverlap i j k l γ × ℝ)}
    (hS : MeasurableSet S) :
    A.transitionOverlapMeasure B γ μ S = μ (rootOverlapParam hij γ ''
      ((S ∩ (rootTransitionCoordinates hij γ) ⁻¹' B.overlapDomain γ⁻¹ k) ∩ A.overlapDomain γ l)) := by
  rw [transitionOverlapMeasure,Measure.restrict_apply hS,A.overlapMeasure_apply γ l μ
    (hS.inter ((rootTransitionCoordinates hij γ).measurable (B.overlapDomain_open γ⁻¹ k).measurableSet))]

 

lemma transitionOverlapMeasure_restrict_le (A D : RootBox hij k) (B F : RootBox hij l)
    (hAD : A.time ⊆ D.time) (hBF : B.time ⊆ F.time)
    (γ : G n) (μ : Measure (X n)) :
    (A.transitionOverlapMeasure B γ μ).restrict (Prod.fst ⁻¹'
      {s | s.val ∈ D.transverse ∧ (rootTransitionSlice hij γ s).val ∈ F.transverse}) ≤
      D.transitionOverlapMeasure F γ μ := by
  let U := {s : RootSliceOverlap i j k l γ |
    s.val ∈ D.transverse ∧ (rootTransitionSlice hij γ s).val ∈ F.transverse}
  have hU : MeasurableSet U :=
    (measurable_subtype_coe D.transverse_open.measurableSet).inter
      ((continuous_rootTransitionSlice hij γ).measurable
        (measurable_subtype_coe F.transverse_open.measurableSet))
  apply Measure.le_iff.mpr
  intro S hS
  have hSU : MeasurableSet (S ∩ Prod.fst ⁻¹' U) := hS.inter (measurable_fst hU)
  rw [Measure.restrict_apply hS,transitionOverlapMeasure_apply _ _ _ _ hSU,
    transitionOverlapMeasure_apply _ _ _ _ hS]
  apply measure_mono
  apply Set.image_mono
  rintro z ⟨⟨⟨hzS,hzD,hzF⟩,hzB⟩,hzA⟩
  exact ⟨⟨hzS,⟨hzF,hBF hzB.2⟩⟩,⟨hzD,hAD hzA.2⟩⟩

lemma transition_base_ae_of_ae (A D : RootBox hij k) (B F : RootBox hij l)
    (hAD : A.time ⊆ D.time) (hBF : B.time ⊆ F.time)
    (γ : G n) (μ : Measure (X n)) {P : RootSliceOverlap i j k l γ → Prop}
    (hP : ∀ᵐ s ∂(D.transitionOverlapMeasure F γ μ).fst, P s) :
    ∀ᵐ s ∂(A.transitionOverlapMeasure B γ μ).fst,
      s.val ∈ D.transverse → (rootTransitionSlice hij γ s).val ∈ F.transverse → P s := by
  let U := {s : RootSliceOverlap i j k l γ |
    s.val ∈ D.transverse ∧ (rootTransitionSlice hij γ s).val ∈ F.transverse}
  have hU : MeasurableSet U :=
    (measurable_subtype_coe D.transverse_open.measurableSet).inter
      ((continuous_rootTransitionSlice hij γ).measurable
        (measurable_subtype_coe F.transverse_open.measurableSet))
  have H := (Measure.absolutelyContinuous_of_le
    (Measure.fst_mono (A.transitionOverlapMeasure_restrict_le D B F hAD hBF γ μ))).ae_le hP
  rw [fst_restrict_base _ hU] at H
  filter_upwards [(ae_restrict_iff' hU).mp H] with s hs
  exact fun hD hF => hs ⟨hD,hF⟩

lemma transition_base_ae_source (A : RootBox hij k) (B : RootBox hij l)
    (γ : G n) (μ : Measure (X n)) [IsFiniteMeasure μ]
    {P : RootSlice i j k → Prop} (hP : ∀ᵐ s ∂(A.coordinateMeasure μ).fst, P s) :
    ∀ᵐ s ∂(A.transitionOverlapMeasure B γ μ).fst, P s.val := by
  let U := {s : RootSlice i j k | (γ*s.val).1 l i ≠ 0}
  have H := (Measure.absolutelyContinuous_of_le (Measure.restrict_le_self (s := U))).ae_le hP
  rw [←fst_map_comap_baseSubtype (A.coordinateMeasure μ) U
    (rootSliceOverlap_isOpen γ).measurableSet] at H
  exact (Measure.absolutelyContinuous_of_le (Measure.fst_mono Measure.restrict_le_self)).ae_le
    (ae_of_ae_map measurable_subtype_coe.aemeasurable H)

lemma transition_base_ae_target (A : RootBox hij k) (B : RootBox hij l)
    (γ : G n) (hγ : γ ∈ integralGroup n) (μ : Measure (X n)) [IsFiniteMeasure μ]
    {P : RootSlice i j l → Prop} (hP : ∀ᵐ s ∂(B.coordinateMeasure μ).fst, P s) :
    ∀ᵐ s ∂(A.transitionOverlapMeasure B γ μ).fst, P (rootTransitionSlice hij γ s).val := by
  let U := {s : RootSlice i j l | (γ⁻¹*s.val).1 k i ≠ 0}
  have H := (Measure.absolutelyContinuous_of_le (Measure.restrict_le_self (s := U))).ae_le hP
  rw [←fst_map_comap_baseSubtype (B.coordinateMeasure μ) U
    (rootSliceOverlap_isOpen γ⁻¹).measurableSet] at H
  have H' := ae_of_ae_map measurable_subtype_coe.aemeasurable H
  have H'' := (Measure.absolutelyContinuous_of_le (Measure.fst_mono
    (Measure.restrict_le_self (s := rootTransitionCoordinates hij γ '' A.overlapDomain γ l)))).ae_le H'
  change ∀ᵐ s ∂((B.overlapMeasure γ⁻¹ k μ).restrict
    (rootTransitionCoordinates hij γ '' A.overlapDomain γ l)).fst, P s.val at H''
  rw [←A.overlapMeasure_transition B γ hγ μ] at H''
  have hm := fst_map_fibers (A.transitionOverlapMeasure B γ μ)
    (rootSliceTransition hij γ).toMeasurableEquiv
    (fun z => z.2 + rootTransitionTime γ z.1)
    (measurable_snd.add ((continuous_rootTransitionTime γ).measurable.comp measurable_fst))
  change ((A.transitionOverlapMeasure B γ μ).map (rootTransitionCoordinates hij γ)).fst = _ at hm
  rw [hm] at H''
  exact ae_of_ae_map (rootSliceTransition hij γ).measurable.aemeasurable H''

end RootBox
end PrimeDegreePackets


namespace PrimeDegreePackets
variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]

lemma anchorNormalize_map (ν : Measure α) (e : α ≃ᵐ β) {J : Set α}
    (hJ : MeasurableSet J) :
    (anchorNormalize ν J).map e = anchorNormalize (ν.map e) (e '' J) := by
  unfold anchorNormalize
  rw [Measure.map_smul _ e.measurable.aemeasurable,Measure.map_apply e.measurable
    (e.measurableEmbedding.measurableSet_image.mpr hJ),e.preimage_image]

lemma anchorNormalize_congr_restriction (ν p : Measure α) {D J : Set α}
    (hJ : MeasurableSet J) (hJD : J ⊆ D)
    (c : ℝ≥0∞) (hc0 : c ≠ 0) (hcT : c ≠ ∞)
    (he : ν.restrict D = c • p) :
    (anchorNormalize ν J).restrict D = anchorNormalize p J := by
  rw [←anchorNormalize_restrict_comm ν hJ hJD,he,anchorNormalize_smul _ _ _ hc0 hcT]

lemma anchorNormalize_reanchor_map (p : Measure α) (q : Measure β)
    (e : α ≃ᵐ β) {V : Set α} {W : Set β} {J : Set α}
    (hJ : MeasurableSet J) (hJV : J ⊆ V) (hJW : e '' J ⊆ W)
    (hpV0 : p V ≠ 0) (hpVT : p V ≠ ∞) (hqW0 : q W ≠ 0) (hqWT : q W ≠ ∞)
    (he : ((anchorNormalize p V).restrict V).map e = (anchorNormalize q W).restrict W) :
    ((anchorNormalize p J).restrict V).map e = (anchorNormalize q (e '' J)).restrict W := by
  have H := congrArg (fun ρ : Measure β => anchorNormalize ρ (e '' J)) he
  rw [←anchorNormalize_map _ e hJ,anchorNormalize_restrict_comm _ hJ hJV,
    anchorNormalize_twice _ _ _ hpV0 hpVT,
    anchorNormalize_restrict_comm _ (e.measurableEmbedding.measurableSet_image.mpr hJ) hJW,
    anchorNormalize_twice _ _ _ hqW0 hqWT] at H
  exact H

 

theorem projective_extensions_overlap
    (ν p : Measure α) (η q : Measure β) (e : α ≃ᵐ β)
    {D V J : Set α} {E W : Set β}
    (hD : MeasurableSet D) (hE : MeasurableSet E)
    (hJ : MeasurableSet J) (hJD : J ⊆ D) (hJV : J ⊆ V)
    (hJE : e '' J ⊆ E) (hJW : e '' J ⊆ W)
    (c d : ℝ≥0∞) (hc0 : c ≠ 0) (hcT : c ≠ ∞) (hd0 : d ≠ 0) (hdT : d ≠ ∞)
    (hν : ν.restrict D = c • p) (hη : η.restrict E = d • q)
    (hpV0 : p V ≠ 0) (hpVT : p V ≠ ∞) (hqW0 : q W ≠ 0) (hqWT : q W ≠ ∞)
    (he : ((anchorNormalize p V).restrict V).map e = (anchorNormalize q W).restrict W) :
    ((anchorNormalize ν J).restrict (V ∩ D)).map e =
      (anchorNormalize η (e '' J)).restrict (W ∩ E) := by
  have Hν := anchorNormalize_congr_restriction ν p hJ hJD c hc0 hcT hν
  have Hη := anchorNormalize_congr_restriction η q
    (e.measurableEmbedding.measurableSet_image.mpr hJ) hJE d hd0 hdT hη
  have H := anchorNormalize_reanchor_map p q e hJ hJV hJW hpV0 hpVT hqW0 hqWT he
  rw [←Hν,←Hη] at H
  simpa only [Measure.restrict_restrict' hD,Measure.restrict_restrict' hE] using H

end PrimeDegreePackets
end
end

end OAI