roseking commited on
Commit
a2ee19a
·
verified ·
1 Parent(s): dd14c26

Add lean source and binary files (part 126)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. lean/OAI/Probability/MatroidSecretary/Secretary/SourcePrefixLaw.lean +108 -0
  2. lean/OAI/Probability/MatroidSecretary/Secretary/Specification.lean +18 -0
  3. lean/OAI/Probability/MatroidSecretary/Secretary/TableLaw.lean +60 -0
  4. lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernel.lean +127 -0
  5. lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernelModel.lean +39 -0
  6. lean/OAI/Probability/MatroidSecretary/Selection/AssignedSafe.lean +137 -0
  7. lean/OAI/Probability/MatroidSecretary/Selection/AveragedSafeExact.lean +119 -0
  8. lean/OAI/Probability/MatroidSecretary/Selection/CandidateContract.lean +89 -0
  9. lean/OAI/Probability/MatroidSecretary/Selection/CandidateContracts.lean +77 -0
  10. lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecification.lean +53 -0
  11. lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecificationTheorems.lean +88 -0
  12. lean/OAI/Probability/MatroidSecretary/Selection/FeasibilityContract.lean +123 -0
  13. lean/OAI/Probability/MatroidSecretary/Selection/FeasibilitySpec.lean +31 -0
  14. lean/OAI/Probability/MatroidSecretary/Selection/GreedyExecution.lean +90 -0
  15. lean/OAI/Probability/MatroidSecretary/Selection/LayerImplementation.lean +71 -0
  16. lean/OAI/Probability/MatroidSecretary/Selection/SafeSpecification.lean +26 -0
  17. lean/OAI/Probability/MatroidSecretary/Transport/AdversarialMinimum.lean +94 -0
  18. lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulation.lean +391 -0
  19. lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulationModel.lean +130 -0
  20. lean/OAI/Probability/MatroidSecretary/Transport/InformationRestriction.lean +128 -0
  21. lean/OAI/Probability/MatroidSecretary/Transport/SimulationInformation.lean +116 -0
  22. lean/OAI/Probability/MatroidSecretary/Transport/StrongOneSample.lean +59 -0
  23. lean/OAI/Probability/MatroidSecretary/Transport/TransferContract.lean +95 -0
  24. lean/OAI/Probability/MatroidSecretary/Transport/TransferContracts.lean +106 -0
  25. lean/OAI/Probability/MatroidSecretary/Transport/TransferSpecification.lean +28 -0
  26. lean/OAI/Probability/MatroidSecretary/Weights/DegenerateCases.lean +124 -0
  27. lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawModel.lean +39 -0
  28. lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawTheorems.lean +170 -0
  29. lean/OAI/Probability/MatroidSecretary/Weights/OptimumIntegrability.lean +90 -0
  30. lean/OAI/Probability/MatroidSecretary/Weights/ZeroBenchmark.lean +134 -0
  31. lean/OAI/Probability/MemoryPrecision/AmbientGram.lean +664 -0
  32. lean/OAI/Probability/MemoryPrecision/BallAverages.lean +142 -0
  33. lean/OAI/Probability/MemoryPrecision/CoefficientStep.lean +81 -0
  34. lean/OAI/Probability/MemoryPrecision/CubeArithmetic.lean +93 -0
  35. lean/OAI/Probability/MemoryPrecision/CubeBlock.lean +165 -0
  36. lean/OAI/Probability/MemoryPrecision/CubeCaps.lean +142 -0
  37. lean/OAI/Probability/MemoryPrecision/CubeContinuation.lean +123 -0
  38. lean/OAI/Probability/MemoryPrecision/CubeExperiment.lean +103 -0
  39. lean/OAI/Probability/MemoryPrecision/CubeGeometry.lean +279 -0
  40. lean/OAI/Probability/MemoryPrecision/CubeSuccess.lean +85 -0
  41. lean/OAI/Probability/MemoryPrecision/DensityPassage.lean +313 -0
  42. lean/OAI/Probability/MemoryPrecision/DensityUniqueness.lean +95 -0
  43. lean/OAI/Probability/MemoryPrecision/EllipsoidSuccess.lean +111 -0
  44. lean/OAI/Probability/MemoryPrecision/FiberDensity.lean +111 -0
  45. lean/OAI/Probability/MemoryPrecision/FiniteDensity.lean +281 -0
  46. lean/OAI/Probability/MemoryPrecision/GaussianConvolution.lean +114 -0
  47. lean/OAI/Probability/MemoryPrecision/JointL1.lean +185 -0
  48. lean/OAI/Probability/MemoryPrecision/KernelAdmissibility.lean +48 -0
  49. lean/OAI/Probability/MemoryPrecision/KernelCaps.lean +119 -0
  50. lean/OAI/Probability/MemoryPrecision/KernelCube.lean +124 -0
lean/OAI/Probability/MatroidSecretary/Secretary/SourcePrefixLaw.lean ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidSecretary.Secretary.PrefixObservationModel
2
+ import OAI.Probability.MatroidSecretary.Secretary.SourceMask
3
+ import OAI.Probability.MatroidSecretary.Secretary.Prefix
4
+ import OAI.Probability.MatroidSecretary.Secretary.BinomialMixture
5
+ import Mathlib.MeasureTheory.Integral.Prod
6
+
7
+ namespace OAI
8
+
9
+ /-!
10
+ # The concrete source observation law after a uniform random prefix
11
+
12
+ The initially sampled source seed determines the branch and prefix length.
13
+ An independent uniform permutation supplies the actual observed prefix.
14
+ Averaging the length, rather than conditioning on the complete initial seed,
15
+ recovers the full joint law of the branch and sacrificed source mask.
16
+
17
+ This is the actual source-law input to conditional-table reconstruction in
18
+ `sections/secretary.tex`, equations `eq:secretary-prefix-mask` and its following
19
+ kernel argument (SHA256
20
+ `3554fe0f7296782edf63cc7f1305c377e7a7b9d8f8948b9510ea4ad02a702d63`).
21
+ It does not assume a caller-given source transport law.
22
+ -/
23
+
24
+ namespace MatroidProphet.Secretary
25
+
26
+ open MeasureTheory Finset
27
+
28
+ /-- A predrawn Bernoulli mask supplies only the length; the independent random
29
+ prefix has the original product-mask law after averaging that length. -/
30
+ theorem predrawn_mask_prefix_integral {n : ℕ} (p : ℝ)
31
+ (f : Finset (Fin n) → ℝ) :
32
+ bitsExpectation (fun _ : Fin n => p) univ (fun B =>
33
+ ∫ σ : ArrivalOrder n,
34
+ f (univ.filter fun e : Fin n => (σ.symm e).val < B.card)
35
+ ∂(PMF.uniformOfFintype (ArrivalOrder n)).toMeasure) =
36
+ bitsExpectation (fun _ : Fin n => p) univ f := by
37
+ have hB (B : Finset (Fin n)) :
38
+ (∫ σ : ArrivalOrder n,
39
+ f (univ.filter fun e : Fin n => (σ.symm e).val < B.card)
40
+ ∂(PMF.uniformOfFintype (ArrivalOrder n)).toMeasure) =
41
+ (∑ S ∈ (univ : Finset (Fin n)).powersetCard B.card, f S) /
42
+ Nat.choose n B.card :=
43
+ integral_uniform_prefix (by simpa using Finset.card_le_univ B) f
44
+ simp_rw [hB]
45
+ simpa only [Finset.card_univ, Fintype.card_fin, div_eq_mul_inv, mul_comm] using
46
+ SecretaryBinomialMixture.predrawn_card_uniform_subset p (univ : Finset (Fin n)) f
47
+
48
+ /-- Exact test-function identity for the manuscript's concrete full source seed.
49
+ The branch, prefix length and every unused source coin are sampled before the
50
+ independent uniform permutation. -/
51
+ theorem integral_source_random_prefix {n : ℕ} (M : Matroid (Fin n))
52
+ (hE : M.E = Set.univ) (f : Bool → Finset (Fin n) → ℝ) :
53
+ (∫ r, ∫ σ : ArrivalOrder n,
54
+ f (mainBranch r)
55
+ (univ.filter fun e : Fin n =>
56
+ (σ.symm e).val < ((completeHiddenRule M hE).mask r).card)
57
+ ∂(PMF.uniformOfFintype (ArrivalOrder n)).toMeasure ∂sourceSeedLaw n) =
58
+ ∫ r, f (mainBranch r) ((completeHiddenRule M hE).mask r) ∂sourceSeedLaw n := by
59
+ rw [integral_source_branch_mask M hE (fun j B =>
60
+ ∫ σ : ArrivalOrder n,
61
+ f j (univ.filter fun e : Fin n => (σ.symm e).val < B.card)
62
+ ∂(PMF.uniformOfFintype (ArrivalOrder n)).toMeasure)]
63
+ rw [integral_source_branch_mask M hE f]
64
+ simp_rw [predrawn_mask_prefix_integral]
65
+
66
+ /-- The full branch/prefix pushforward equals the branch/sacrificed-mask law of
67
+ our concrete source algorithm. This is the exact input used by the finite
68
+ conditional-table reconstruction, including empty and full prefixes. -/
69
+ theorem source_random_prefix_joint_law {n : ℕ} (M : Matroid (Fin n))
70
+ (hE : M.E = Set.univ) :
71
+ ((sourceSeedLaw n).prod
72
+ (PMF.uniformOfFintype (ArrivalOrder n)).toMeasure).map
73
+ (fun z : Seed (mainSeedBits n) × ArrivalOrder n =>
74
+ (mainBranch z.1, orderPrefix z.2 ((completeHiddenRule M hE).mask z.1).card)) =
75
+ (sourceSeedLaw n).map
76
+ (fun r => (mainBranch r, (completeHiddenRule M hE).mask r)) := by
77
+ classical
78
+ let index : Seed (mainSeedBits n) × ArrivalOrder n → Bool × Finset (Fin n) :=
79
+ fun z => (mainBranch z.1, orderPrefix z.2 ((completeHiddenRule M hE).mask z.1).card)
80
+ let obs : Seed (mainSeedBits n) → Bool × Finset (Fin n) :=
81
+ fun r => (mainBranch r, (completeHiddenRule M hE).mask r)
82
+ let μ := (sourceSeedLaw n).prod (PMF.uniformOfFintype (ArrivalOrder n)).toMeasure
83
+ have htest (f : Bool × Finset (Fin n) → ℝ) :
84
+ (∫ z, f (index z) ∂μ) = ∫ r, f (obs r) ∂sourceSeedLaw n := by
85
+ rw [integral_prod _ Integrable.of_finite]
86
+ simpa only [index, obs, orderPrefix] using
87
+ integral_source_random_prefix M hE (fun j P => f (j, P))
88
+ change μ.map index = (sourceSeedLaw n).map obs
89
+ apply Measure.ext_of_singleton
90
+ intro b
91
+ have hreal : (μ.map index).real {b} = ((sourceSeedLaw n).map obs).real {b} := by
92
+ rw [← integral_indicator_one (measurableSet_singleton b),
93
+ ← integral_indicator_one (measurableSet_singleton b)]
94
+ rw [integral_map_of_stronglyMeasurable (measurable_of_countable index)
95
+ (measurable_of_countable _).stronglyMeasurable,
96
+ integral_map_of_stronglyMeasurable (measurable_of_countable obs)
97
+ (measurable_of_countable _).stronglyMeasurable]
98
+ exact htest _
99
+ calc
100
+ μ.map index {b} = ENNReal.ofReal ((μ.map index).real {b}) :=
101
+ (ofReal_measureReal).symm
102
+ _ = ENNReal.ofReal (((sourceSeedLaw n).map obs).real {b}) :=
103
+ congrArg ENNReal.ofReal hreal
104
+ _ = (sourceSeedLaw n).map obs {b} := ofReal_measureReal
105
+
106
+ end MatroidProphet.Secretary
107
+
108
+ end OAI
lean/OAI/Probability/MatroidSecretary/Secretary/Specification.lean ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidSecretary.Secretary.ProbabilityModel
2
+ import Mathlib.Probability.Independence.Basic
3
+ import Mathlib.MeasureTheory.Integral.Bochner.Basic
4
+
5
+ /-!
6
+ # Independent specification of the full-seed secretary endpoint
7
+
8
+ The rule and its finite initial seed law are chosen before the fixed vector
9
+ of weights and before the probability space or adversary. The initial
10
+ uniform order is independent of the complete seed. Only its ordered prefix
11
+ is preserved in the actual execution; the suffix may depend on all available
12
+ information, and even on additional randomization carried by the ambient
13
+ space. No independence assumption is made on the executed order.
14
+
15
+ Finite seed types suffice for the manuscript construction: all conditional
16
+ reconstruction tables can be sampled in advance. `Fin q` is just an
17
+ enumeration of this finite seed space, with its arbitrary probability law.
18
+ -/
lean/OAI/Probability/MatroidSecretary/Secretary/TableLaw.lean ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib.MeasureTheory.Integral.Pi
2
+ import Mathlib.MeasureTheory.Integral.Prod
3
+ import Mathlib.MeasureTheory.Integral.Bochner.SumMeasure
4
+
5
+ namespace OAI
6
+
7
+ /-!
8
+ # Precommitted finite conditional-randomness tables
9
+
10
+ The secretary construction draws all conditional random choices before the
11
+ random arrival permutation. A table indexed by every possible branch/prefix
12
+ pair does this without concealing later randomness. Its law is the ordinary
13
+ finite product measure `Measure.pi κ`. Evaluating the table after an independent
14
+ prefix experiment has exactly the corresponding conditional law.
15
+
16
+ These lemmas concern only this sampling construction, not the source theorem's
17
+ competitive guarantee. In particular an application must separately prove the
18
+ prefix law and the concrete source conditional-kernel laws.
19
+ -/
20
+
21
+ namespace MatroidProphet.Secretary
22
+
23
+ open MeasureTheory
24
+ open scoped BigOperators
25
+
26
+ variable {ι α Ω : Type*} [Fintype ι] [Fintype α] [Fintype Ω]
27
+ [MeasurableSpace α] [MeasurableSingletonClass α]
28
+ [MeasurableSpace Ω] [MeasurableSingletonClass Ω]
29
+
30
+ /-- All conditional samples can be drawn initially and independently. Evaluating
31
+ one coordinate after an independent finite experiment has the prescribed law. -/
32
+ theorem integral_precommittedTable
33
+ (κ : ι → Measure α) [∀ i, IsProbabilityMeasure (κ i)]
34
+ (μ : Measure Ω) [IsFiniteMeasure μ] (index : Ω → ι) (f : ι → α → ℝ) :
35
+ (∫ z : Ω × (ι → α), f (index z.1) (z.2 (index z.1))
36
+ ∂μ.prod (Measure.pi κ)) =
37
+ ∫ ω, ∫ r, f (index ω) r ∂κ (index ω) ∂μ := by
38
+ rw [integral_prod _ Integrable.of_finite]
39
+ apply integral_congr_ae
40
+ exact ae_of_all _ fun ω => by
41
+ exact integral_comp_eval (μ := κ) (i := index ω)
42
+ (f := f (index ω))
43
+ (measurable_of_countable (f (index ω))).aestronglyMeasurable
44
+
45
+ /-- The same identity with the independent experiment explicitly summed. It
46
+ retains the complete table, including all coordinates unused in this run. -/
47
+ theorem integral_precommittedTable_eq_sum
48
+ (κ : ι → Measure α) [∀ i, IsProbabilityMeasure (κ i)]
49
+ (μ : Measure Ω) [IsFiniteMeasure μ] (index : Ω → ι) (f : ι → α → ℝ) :
50
+ (∫ z : Ω × (ι → α), f (index z.1) (z.2 (index z.1))
51
+ ∂μ.prod (Measure.pi κ)) =
52
+ ∑ ω, μ.real {ω} * (∫ r, f (index ω) r ∂κ (index ω)) := by
53
+ rw [integral_precommittedTable]
54
+ simpa only [smul_eq_mul, measureReal_def] using
55
+ (integral_fintype (μ := μ)
56
+ (f := fun ω => ∫ r, f (index ω) r ∂κ (index ω)) Integrable.of_finite)
57
+
58
+ end MatroidProphet.Secretary
59
+
60
+ end OAI
lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernel.lean ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import OAI.Probability.MatroidSecretary.Secretary.TripleKernelModel
3
+ import Mathlib.Algebra.BigOperators.Finprod
4
+ import Mathlib.Probability.ProbabilityMassFunction.Constructions
5
+ import Mathlib.Tactic
6
+
7
+ namespace OAI
8
+
9
+ /-! Explicit normalized one-label reconstruction kernel from secretary.tex,
10
+ lines 64--81. These are finite identities, including the zero-mask case. -/
11
+
12
+ namespace MatroidProphet.Secretary
13
+
14
+ open Finset
15
+
16
+ lemma tripleWeight_sum (t : ℝ) : (∑ x : MaskTriple, tripleWeight t x) = 1 := by
17
+ simp [MaskTriple, Fintype.sum_prod_type, tripleWeight]
18
+ ring
19
+
20
+ lemma tripleWeight_nonneg {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1)
21
+ (x : MaskTriple) : 0 ≤ tripleWeight t x := by
22
+ rcases x with ⟨h,d,c⟩
23
+ cases d <;> cases c <;> norm_num [tripleWeight] <;> linarith
24
+
25
+ lemma tripleWeight_zero (t : ℝ) :
26
+ tripleWeight t (false, false, false) = 3 / 8 * (1-t) := by
27
+ norm_num [tripleWeight]
28
+
29
+ lemma mainRevealRate_eq_source :
30
+ mainRevealRate = (5 : ℝ) / 8 + 3 * ((2 : ℝ)^143)⁻¹ := by
31
+ norm_num [mainRevealRate, thinningRate]
32
+
33
+ lemma mainRevealRate_pos : 0 < mainRevealRate := by
34
+ norm_num [mainRevealRate, thinningRate]
35
+
36
+ lemma mainRevealRate_lt_one : mainRevealRate < 1 := by
37
+ norm_num [mainRevealRate, thinningRate]
38
+
39
+ lemma mainRevealRate_complement :
40
+ 1 - mainRevealRate = tripleWeight thinningRate (false, false, false) := by
41
+ simp [mainRevealRate, tripleWeight]
42
+ ring
43
+
44
+ lemma tripleRevealed_eq_false (x : MaskTriple) :
45
+ tripleRevealed x = false ↔ x = (false, false, false) := by
46
+ rcases x with ⟨h,d,c⟩
47
+ cases h <;> cases d <;> cases c <;> decide
48
+
49
+ lemma conditionalTripleWeight_nonneg (b : Bool) (x : MaskTriple) :
50
+ 0 ≤ conditionalTripleWeight b x := by
51
+ have ht0 : 0 ≤ thinningRate := constants_positive.2.2.1.le
52
+ have ht1 : thinningRate ≤ 1 := by norm_num [thinningRate]
53
+ unfold conditionalTripleWeight
54
+ split_ifs
55
+ · exact div_nonneg (tripleWeight_nonneg ht0 ht1 x) mainRevealRate_pos.le
56
+ · norm_num
57
+ · norm_num
58
+ · norm_num
59
+
60
+ lemma conditionalTripleWeight_sum (b : Bool) :
61
+ (∑ x : MaskTriple, conditionalTripleWeight b x) = 1 := by
62
+ cases b
63
+ · simp [conditionalTripleWeight]
64
+ · simp [MaskTriple, Fintype.sum_prod_type,
65
+ conditionalTripleWeight, tripleRevealed, tripleWeight]
66
+ field_simp [ne_of_gt mainRevealRate_pos]
67
+ simp [mainRevealRate]
68
+ ring
69
+
70
+ lemma conditionalTripleWeight_support (b : Bool) (x : MaskTriple)
71
+ (h : tripleRevealed x ≠ b) : conditionalTripleWeight b x = 0 := by
72
+ rcases x with ⟨x,y,z⟩
73
+ cases b <;> cases x <;> cases y <;> cases z <;>
74
+ simp_all [conditionalTripleWeight, tripleRevealed]
75
+
76
+ /-- Multiplying the explicit conditional kernel by the observed-bit law
77
+ recovers the original joint law, not just a marginal event probability. -/
78
+ lemma conditionalTripleWeight_joint (b : Bool) (x : MaskTriple) :
79
+ revealBitWeight b * conditionalTripleWeight b x =
80
+ if tripleRevealed x = b then tripleWeight thinningRate x else 0 := by
81
+ rcases x with ⟨x,y,z⟩
82
+ cases b <;> cases x <;> cases y <;> cases z <;>
83
+ simp [revealBitWeight, conditionalTripleWeight, tripleRevealed,
84
+ mainRevealRate_complement] <;>
85
+ field_simp [ne_of_gt mainRevealRate_pos]
86
+
87
+ lemma conditionalTripleWeight_reconstruct (x : MaskTriple) :
88
+ (∑ b : Bool, revealBitWeight b * conditionalTripleWeight b x) =
89
+ tripleWeight thinningRate x := by
90
+ simp only [conditionalTripleWeight_joint, Fintype.sum_bool]
91
+ cases h : tripleRevealed x <;> simp
92
+
93
+ lemma revealBitWeight_pos (b : Bool) : 0 < revealBitWeight b := by
94
+ cases b
95
+ · exact sub_pos.mpr mainRevealRate_lt_one
96
+ · exact mainRevealRate_pos
97
+
98
+ lemma revealBitWeight_sum : (∑ b : Bool, revealBitWeight b) = 1 := by
99
+ simp [revealBitWeight]
100
+
101
+ lemma tripleWeight_source_pos (x : MaskTriple) :
102
+ 0 < tripleWeight thinningRate x := by
103
+ rcases x with ⟨h,d,c⟩
104
+ cases d <;> cases c <;> norm_num [tripleWeight, thinningRate]
105
+
106
+ /-- Exactly seven triples are compatible with an observed label. -/
107
+ lemma card_revealed_triples :
108
+ Fintype.card {x : MaskTriple // tripleRevealed x = true} = 7 := by decide
109
+
110
+ lemma conditionalTripleWeight_pos_iff (b : Bool) (x : MaskTriple) :
111
+ 0 < conditionalTripleWeight b x ↔ tripleRevealed x = b := by
112
+ constructor
113
+ · intro hx
114
+ by_contra h
115
+ rw [conditionalTripleWeight_support b x h] at hx
116
+ exact (lt_irrefl (0 : ℝ)) hx
117
+ · intro hx
118
+ have h := conditionalTripleWeight_joint b x
119
+ rw [ite_eq_left hx] at h
120
+ have hp : 0 < revealBitWeight b * conditionalTripleWeight b x := by
121
+ rw [h]
122
+ exact tripleWeight_source_pos x
123
+ exact (mul_pos_iff_of_pos_left (revealBitWeight_pos b)).mp hp
124
+
125
+ end MatroidProphet.Secretary
126
+
127
+ end OAI
lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernelModel.lean ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import Mathlib.Data.Fintype.Prod
3
+
4
+ namespace OAI
5
+
6
+ /-! Concrete one-label conditional kernel for the secretary reconstruction.
7
+ The boolean records membership in the sacrificed observation mask, not branch choice.
8
+ The three coordinates are the original H, D, C coins; the T coin is not sacrificed.
9
+ -/
10
+
11
+ namespace MatroidProphet.Secretary
12
+
13
+ abbrev MaskTriple := Bool × Bool × Bool
14
+
15
+ /-- Whether at least one of the three observation coins is set. -/
16
+ def tripleRevealed (x : MaskTriple) : Bool := x.1 || x.2.1 || x.2.2
17
+
18
+ /-- The independent H,D,C law at one label, retaining the thinning parameter. -/
19
+ noncomputable def tripleWeight (t : ℝ) (x : MaskTriple) : ℝ :=
20
+ (1 / 2) * (if x.2.1 then 1 / 4 else 3 / 4) *
21
+ (if x.2.2 then t else 1 - t)
22
+
23
+ /-- Probability that a label is sacrificed in the main branch. -/
24
+ noncomputable def mainRevealRate : ℝ := 5 / 8 + 3 * thinningRate / 8
25
+
26
+ /-- The source specifies all seven nonzero triple masses divided by the reveal rate.
27
+ Outside the observation set the triple is deterministically zero. -/
28
+ noncomputable def conditionalTripleWeight (revealed : Bool) (x : MaskTriple) : ℝ :=
29
+ if revealed then
30
+ if tripleRevealed x then tripleWeight thinningRate x / mainRevealRate else 0
31
+ else if x = (false, false, false) then 1 else 0
32
+
33
+ /-- Probability of a prescribed observation-mask membership bit. -/
34
+ noncomputable def revealBitWeight (revealed : Bool) : ℝ :=
35
+ if revealed then mainRevealRate else 1 - mainRevealRate
36
+
37
+ end MatroidProphet.Secretary
38
+
39
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/AssignedSafe.lean ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import OAI.Probability.MatroidSecretary.Selection.SafeSpecification
3
+
4
+ namespace OAI
5
+
6
+ namespace MatroidProphet
7
+
8
+ open Finset
9
+ variable {α : Type*} [Fintype α] [DecidableEq α]
10
+
11
+ /-- The stronger half-loss estimate explicitly obtained in the source proof.
12
+ The named lemma then enlarges the loss from `|D_h|/(2κ)` to `|D_h|/κ`. -/
13
+ theorem safeSampleCount_half_loss
14
+ (M : Matroid α) (hE : M.E = Set.univ)
15
+ (κ : ℕ) (hκ : 0 < κ) (D : ℕ → Set α) (G : ℕ → Finset α)
16
+ (hG : Pairwise (fun i j => Disjoint (G i) (G j)))
17
+ (q : α → ℝ) (hq0 : ∀ e, 0 ≤ q e) (hq1 : ∀ e, q e ≤ 1)
18
+ (h : ℕ) (I : Finset α) (hI : M.Indep (I : Set α)) :
19
+ (((2 : ℝ) ^ 12)⁻¹) / 4 * I.card - (D h).ncard / (2 * (κ : ℝ)) ≤
20
+ bitsExpectation q univ (fun C => bitsExpectation q univ (fun T =>
21
+ fairParityExpectation (safeSampleCount M hE κ D G h I C T))) := by
22
+ have hpre := safeCountBeforeParity_lower M hE κ hκ D G hG q hq0 hq1 h I hI
23
+ have heq : bitsExpectation q univ (fun C => bitsExpectation q univ (fun T =>
24
+ fairParityExpectation (safeSampleCount M hE κ D G h I C T))) =
25
+ bitsExpectation q univ (fun C =>
26
+ bitsExpectation q univ (safeCountBeforeParity M hE κ D G h I C)) / 2 := by
27
+ simp only [safeSampleCount_fair_parity, div_eq_mul_inv]
28
+ simp_rw [bitsExpectation_mul_right]
29
+ rw [heq]
30
+ have hloss : ((D h).ncard : ℝ) / (2 * (κ : ℝ)) =
31
+ ((D h).ncard : ℝ) / (κ : ℝ) / 2 := by ring
32
+ rw [hloss]
33
+ linarith
34
+
35
+ end MatroidProphet
36
+
37
+ namespace MatroidProphet.MainAlgorithm
38
+
39
+ open Finset
40
+ variable {n : ℕ}
41
+ attribute [local instance] Classical.propDecidable
42
+
43
+ /-- The fixed-density safety estimate with the exact density-sample loss. -/
44
+ theorem listedSafeStatistic_exact_density
45
+ (M : Matroid (Fin n)) (hE : M.E = Set.univ)
46
+ (κ : ℕ) (hκ : 0 < κ) (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
47
+ (Y : Set (Fin n)) (hY : Y ⊆ (trueGroup M d s i : Set (Fin n)))
48
+ (hI : M.Indep Y) (q : Fin n → ℝ)
49
+ (hq0 : ∀ e, 0 ≤ q e) (hq1 : ∀ e, q e ≤ 1) :
50
+ exitThreshold / 4 * ((d.D : Set (Fin n)) ∩ Y).ncard -
51
+ (d.D ∩ trueGroup M d s i).card / (κ : ℝ) ≤
52
+ bitsExpectation q univ (fun C => bitsExpectation q univ (fun T =>
53
+ fairParityExpectation (fun p =>
54
+ (listedSafeStatistic M hE κ (withMasks d d.D C T) s i Y
55
+ (boolParity p) : ℝ)))) := by
56
+ by_cases hi : i ∈ groups M d s
57
+ · have hsafe := safeLayerStatistic_lower M hE κ hκ (groupMask M d s d.D)
58
+ (groupGround M d s) (groupGround_disjoint M d s) q hq0 hq1
59
+ ((groups M d s).idxOf i) (trueGroup M d s i : Set (Fin n))
60
+ ((d.D : Set (Fin n)) ∩ Y) (Set.inter_subset_right.trans hY)
61
+ (hI.subset Set.inter_subset_right)
62
+ rw [groupMask_at_key M d s d.D _ i (groups_get?_idxOf M d s i hi),
63
+ Set.ncard_coe_finset] at hsafe
64
+ simpa only [listedSafeStatistic_guards M hE κ d s i Y,
65
+ hi, exitThreshold] using hsafe
66
+ · have hempty := unlisted_density_inter_empty M d s i hi Y hY
67
+ have hzero (C T : Finset (Fin n)) (p : Bool) :
68
+ listedSafeStatistic M hE κ (withMasks d d.D C T) s i Y
69
+ (boolParity p) = 0 := by
70
+ change (if i ∈ groups M d s then _ else 0) = 0
71
+ rw [ite_eq_right hi]
72
+ simp only [hempty, Set.ncard_empty, Nat.cast_zero, mul_zero, zero_sub,
73
+ hzero, fairParityExpectation, zero_add, zero_div, bitsExpectation_const]
74
+ exact neg_nonpos.mpr (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))
75
+
76
+ /-- Restricting the comparison set to this true group does not change its
77
+ safe-label statistic. This permits the source's global independent set `Y`. -/
78
+ theorem listedSafeStatistic_inter_trueGroup
79
+ (M : Matroid (Fin n)) (hE : M.E = Set.univ) (κ : ℕ)
80
+ (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
81
+ (Y : Set (Fin n)) (ε : Fin 2) :
82
+ listedSafeStatistic M hE κ d s i
83
+ (Y ∩ (trueGroup M d s i : Set (Fin n))) ε =
84
+ listedSafeStatistic M hE κ d s i Y ε := by
85
+ unfold listedSafeStatistic
86
+ split_ifs
87
+ · unfold safeLayerStatistic
88
+ apply sum_congr rfl
89
+ intro b _
90
+ congr 1
91
+ ext e
92
+ simp only [safeLayerSet, Set.mem_sdiff, Set.mem_inter_iff]
93
+ constructor
94
+ · rintro ⟨⟨⟨heD, heY, _⟩, heL⟩, heN⟩
95
+ exact ⟨⟨⟨heD, heY⟩, heL⟩, heN⟩
96
+ · rintro ⟨⟨⟨heD, heY⟩, heL⟩, heN⟩
97
+ exact ⟨⟨⟨heD, heY, heL.1⟩, heL⟩, heN⟩
98
+ · rfl
99
+
100
+ /-- Source `lem:safe`, specialized to the manuscript's literal density
101
+ threshold and thinning rate, for the global independent comparison set.
102
+ It also covers an unlisted group, whose safe count is defined to be zero. -/
103
+ theorem safe_sampled_labels
104
+ (M : Matroid (Fin n)) (hE : M.E = Set.univ)
105
+ (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
106
+ (Y : Set (Fin n)) (hI : M.Indep Y) :
107
+ exitThreshold / 4 *
108
+ ((d.D : Set (Fin n)) ∩ (Y ∩ (trueGroup M d s i : Set (Fin n)))).ncard -
109
+ (d.D ∩ trueGroup M d s i).card / densityThreshold ≤
110
+ bitsExpectation (fun _ => thinningRate) univ (fun C =>
111
+ bitsExpectation (fun _ => thinningRate) univ (fun T =>
112
+ fairParityExpectation (fun p =>
113
+ (listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i Y
114
+ (boolParity p) : ℝ)))) := by
115
+ have hs := listedSafeStatistic_exact_density M hE (2 ^ 100) (by positivity)
116
+ d s i (Y ∩ (trueGroup M d s i : Set (Fin n))) Set.inter_subset_right
117
+ (hI.subset Set.inter_subset_left) (fun _ => thinningRate)
118
+ (fun _ => constants_positive.2.2.1.le)
119
+ (fun _ => by norm_num [thinningRate])
120
+ have heq (C T : Finset (Fin n)) (p : Bool) :
121
+ listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i
122
+ (Y ∩ (trueGroup M d s i : Set (Fin n))) (boolParity p) =
123
+ listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i Y
124
+ (boolParity p) := by
125
+ simpa only [trueGroup_withMasks] using
126
+ listedSafeStatistic_inter_trueGroup M hE (2 ^ 100)
127
+ (withMasks d d.D C T) s i Y (boolParity p)
128
+ simpa only [Nat.cast_pow, Nat.cast_ofNat, densityThreshold, heq] using hs
129
+
130
+ /-- Proof of the independently stated complete safe-label claim. -/
131
+ theorem safe_sampled_labels_claim : SafeSampleClaim := by
132
+ intro n M hE d s i Y hI
133
+ exact safe_sampled_labels M hE d s i Y hI
134
+
135
+ end MatroidProphet.MainAlgorithm
136
+
137
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/AveragedSafeExact.lean ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidSecretary.Selection.AssignedSafe
2
+
3
+ namespace OAI
4
+
5
+ /-!
6
+ # The exact density-averaged safety loss
7
+
8
+ This retains the first, sharper inequality in `eq:averaged-safe-count`
9
+ (`sections/transfer.tex`, line 330). The density mask is averaged only after
10
+ the exact conditional loss has been bounded by `|D ∩ U_i| / κ`. The previous
11
+ endpoint route weakened this to `|U_i| / κ` before averaging, which suffices
12
+ there but does not state the displayed `|U_i| / (4κ)` estimate.
13
+
14
+ The statistic remains zero on unlisted outcomes. No conditioning on listing,
15
+ focal density bits, or an arrival order is introduced.
16
+ -/
17
+
18
+ namespace MatroidProphet.MainAlgorithm
19
+
20
+ open Finset
21
+
22
+ variable {n : ℕ}
23
+
24
+ /-- Literal first inequality of `eq:averaged-safe-count`, for a fixed true
25
+ group and any independent comparison subset of that group. -/
26
+ theorem listedSafeStatistic_averaged_exact
27
+ (M : Matroid (Fin n)) (hE : M.E = Set.univ)
28
+ (κ : ℕ) (hκ : 0 < κ) (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
29
+ (Y : Set (Fin n)) (hY : Y ⊆ (trueGroup M d s i : Set (Fin n)))
30
+ (hI : M.Indep Y) (q : Fin n → ℝ)
31
+ (hq0 : ∀ e, 0 ≤ q e) (hq1 : ∀ e, q e ≤ 1) :
32
+ retainedFraction * Y.ncard - (trueGroup M d s i).card / (4 * (κ : ℝ)) ≤
33
+ tripleMaskExpectation (fun _ => (1 : ℝ) / 4) q q univ (fun D C T =>
34
+ fairParityExpectation (fun p =>
35
+ (listedSafeStatistic M hE κ (withMasks d D C T) s i Y
36
+ (boolParity p) : ℝ))) := by
37
+ classical
38
+ have hfixed (D : Finset (Fin n)) :
39
+ exitThreshold / 4 * ((D : Set (Fin n)) ∩ Y).ncard -
40
+ (D ∩ trueGroup M d s i).card / (κ : ℝ) ≤
41
+ bitsExpectation q univ (fun C => bitsExpectation q univ (fun T =>
42
+ fairParityExpectation (fun p =>
43
+ (listedSafeStatistic M hE κ (withMasks d D C T) s i Y
44
+ (boolParity p) : ℝ)))) :=
45
+ listedSafeStatistic_exact_density M hE κ hκ (withMasks d D ∅ ∅)
46
+ s i Y hY hI q hq0 hq1
47
+ have hmean := bitsExpectation_mono (fun _ : Fin n => (1 : ℝ) / 4)
48
+ (by intro e; norm_num) (by intro e; norm_num) univ (fun D _ => hfixed D)
49
+ have hcardY : bitsExpectation (fun _ : Fin n => (1 : ℝ) / 4) univ
50
+ (fun D => (((D : Set (Fin n)) ∩ Y).ncard : ℝ)) = Y.ncard / 4 := by
51
+ have hset (D : Finset (Fin n)) : (D : Set (Fin n)) ∩ Y =
52
+ ((Y.toFinset ∩ D : Finset (Fin n)) : Set (Fin n)) := by
53
+ ext e
54
+ simp only [Set.mem_inter_iff, Finset.mem_coe, mem_inter, Set.mem_toFinset]
55
+ exact and_comm
56
+ simp only [hset, Set.ncard_coe_finset]
57
+ rw [bitsExpectation_card_inter (fun _ : Fin n => (1 : ℝ) / 4)
58
+ univ Y.toFinset (subset_univ _)]
59
+ simp only [sum_const, nsmul_eq_mul, ← Set.ncard_eq_toFinset_card']
60
+ ring
61
+ have hcardU : bitsExpectation (fun _ : Fin n => (1 : ℝ) / 4) univ
62
+ (fun D => ((D ∩ trueGroup M d s i).card : ℝ)) =
63
+ (trueGroup M d s i).card / 4 := by
64
+ simpa [Finset.inter_comm, div_eq_mul_inv] using
65
+ bitsExpectation_card_inter (fun _ : Fin n => (1 : ℝ) / 4)
66
+ univ (trueGroup M d s i) (subset_univ _)
67
+ have heq : bitsExpectation (fun _ : Fin n => (1 : ℝ) / 4) univ
68
+ (fun D => exitThreshold / 4 * ((D : Set (Fin n)) ∩ Y).ncard -
69
+ (D ∩ trueGroup M d s i).card / (κ : ℝ)) =
70
+ retainedFraction * Y.ncard - (trueGroup M d s i).card / (4 * (κ : ℝ)) := by
71
+ calc
72
+ _ = bitsExpectation (fun _ : Fin n => (1 : ℝ) / 4) univ
73
+ (fun D => exitThreshold / 4 * ((D : Set (Fin n)) ∩ Y).ncard +
74
+ (-(κ : ℝ)⁻¹) * (D ∩ trueGroup M d s i).card) := by
75
+ apply bitsExpectation_congr
76
+ intro D _
77
+ ring
78
+ _ = exitThreshold / 4 * (Y.ncard / 4) +
79
+ (-(κ : ℝ)⁻¹) * ((trueGroup M d s i).card / 4) := by
80
+ rw [bitsExpectation_add, bitsExpectation_mul_const,
81
+ bitsExpectation_mul_const, hcardY, hcardU]
82
+ _ = _ := by
83
+ norm_num [exitThreshold, retainedFraction]
84
+ ring
85
+ rw [heq] at hmean
86
+ exact hmean
87
+
88
+ /-- Source specialization for its global independent comparison set `Y`.
89
+ The intersection appearing here is exactly the source's `Y_i`; all statistics
90
+ are those of the actual density-dependent listed groups. -/
91
+ theorem averaged_safe_sampled_labels
92
+ (M : Matroid (Fin n)) (hE : M.E = Set.univ)
93
+ (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
94
+ (Y : Set (Fin n)) (hI : M.Indep Y) :
95
+ retainedFraction * (Y ∩ (trueGroup M d s i : Set (Fin n))).ncard -
96
+ (trueGroup M d s i).card / (4 * densityThreshold) ≤
97
+ tripleMaskExpectation (fun _ => (1 : ℝ) / 4)
98
+ (fun _ => thinningRate) (fun _ => thinningRate) univ (fun D C T =>
99
+ fairParityExpectation (fun p =>
100
+ (listedSafeStatistic M hE (2 ^ 100) (withMasks d D C T) s i Y
101
+ (boolParity p) : ℝ))) := by
102
+ have hs := listedSafeStatistic_averaged_exact M hE (2 ^ 100) (by positivity)
103
+ d s i (Y ∩ (trueGroup M d s i : Set (Fin n))) Set.inter_subset_right
104
+ (hI.subset Set.inter_subset_left) (fun _ => thinningRate)
105
+ (fun _ => constants_positive.2.2.1.le)
106
+ (fun _ => by norm_num [thinningRate])
107
+ have heq (D C T : Finset (Fin n)) (p : Bool) :
108
+ listedSafeStatistic M hE (2 ^ 100) (withMasks d D C T) s i
109
+ (Y ∩ (trueGroup M d s i : Set (Fin n))) (boolParity p) =
110
+ listedSafeStatistic M hE (2 ^ 100) (withMasks d D C T) s i Y
111
+ (boolParity p) := by
112
+ simpa only [trueGroup_withMasks] using
113
+ listedSafeStatistic_inter_trueGroup M hE (2 ^ 100)
114
+ (withMasks d D C T) s i Y (boolParity p)
115
+ simpa only [Nat.cast_pow, Nat.cast_ofNat, densityThreshold, heq] using hs
116
+
117
+ end MatroidProphet.MainAlgorithm
118
+
119
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/CandidateContract.lean ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ namespace MatroidProphet.SourceContracts
6
+
7
+ open Finset Set MainAlgorithm
8
+
9
+ /-- Positive rounding does not remove a positive weight or create one at zero. -/
10
+ theorem roundedWeight_pos_iff {B x : ℝ} (hB : 0 < B) :
11
+ 0 < roundedWeight B x ↔ 0 < x := by
12
+ unfold roundedWeight roundedLevel
13
+ by_cases hx : 0 < x
14
+ · rw [ite_eq_left hx, levelWeight]
15
+ exact iff_of_true (zpow_pos hB _) hx
16
+ · rw [ite_eq_right hx, levelWeight]
17
+ exact iff_of_false (lt_irrefl 0) hx
18
+
19
+ /-- The actual candidate test is exactly `eq:candidates`, with higher rounded
20
+ levels taking priority and the original fixed label order breaking ties. -/
21
+ theorem mem_candidateLabels_iff {n : ℕ} (M : Matroid (Fin n))
22
+ (w : Weights n) (B : ℝ) (H : Finset (Fin n)) (e : Fin n) :
23
+ e ∈ candidateLabels M (fun f => roundedLevel B (w f)) H ↔
24
+ 0 < w e ∧ e ∉ H ∧
25
+ e ∉ M.closure {f | f ∈ H ∧
26
+ higher f (roundedLevel B (w f)) e (roundedLevel B (w e))} := by
27
+ classical
28
+ have hpos : roundedLevel B (w e) ≠ none ↔ 0 < w e := by
29
+ simp [roundedLevel]
30
+ constructor
31
+ · intro hcandidate
32
+ obtain ⟨hlevel, houtside, hclosure⟩ := (Finset.mem_filter.mp hcandidate).2
33
+ exact ⟨hpos.mp hlevel, houtside, hclosure⟩
34
+ · rintro ⟨hpositive, houtside, hclosure⟩
35
+ exact Finset.mem_filter.mpr
36
+ ⟨Finset.mem_univ _, hpos.mpr hpositive, houtside, hclosure⟩
37
+
38
+ /-- The same test in the source's literal `u_e > 0` notation. -/
39
+ theorem mem_candidateLabels_iff_rounded {n : ℕ} (M : Matroid (Fin n))
40
+ (w : Weights n) {B : ℝ} (hB : 0 < B) (H : Finset (Fin n)) (e : Fin n) :
41
+ e ∈ candidateLabels M (fun f => roundedLevel B (w f)) H ↔
42
+ 0 < roundedWeight B (w e) ∧ e ∉ H ∧
43
+ e ∉ M.closure {f | f ∈ H ∧
44
+ higher f (roundedLevel B (w f)) e (roundedLevel B (w e))} := by
45
+ rw [roundedWeight_pos_iff hB]
46
+ exact mem_candidateLabels_iff M w B H e
47
+
48
+ /-- Candidates cannot be loops, including when loops have positive weights. -/
49
+ theorem candidateLabels_nonloop {n : ℕ} (M : Matroid (Fin n))
50
+ (a : Fin n → Option ℤ) (H : Finset (Fin n)) (e : Fin n)
51
+ (he : e ∈ candidateLabels M a H) : e ∉ M.closure ∅ := by
52
+ classical
53
+ exact candidate_not_mem_closure_empty M ⟨H, ∅, ∅, ∅, false⟩ a e (a e)
54
+ (Finset.mem_filter.mp he).2
55
+
56
+ /-- Both deterministic assertions and both expectation assertions in `lem:filter`.
57
+ The assumptions include no positive-rank, nonempty-ground, or no-ties condition. -/
58
+ theorem candidate_mass {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ)
59
+ (w : Weights n) (_hw : ∀ e, 0 ≤ w e) {B : ℝ} (hB : 1 < B) :
60
+ (∀ H : Finset (Fin n),
61
+ M.Indep ((positiveGreedy M (fun e => roundedLevel B (w e)) \ H :
62
+ Finset (Fin n)) : Set (Fin n)) ∧
63
+ positiveGreedy M (fun e => roundedLevel B (w e)) \ H ⊆
64
+ candidateLabels M (fun e => roundedLevel B (w e)) H) ∧
65
+ bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ
66
+ (fun H => ∑ e ∈ positiveGreedy M (fun e => roundedLevel B (w e)) \ H,
67
+ roundedWeight B (w e)) = optimum M (fun e => roundedWeight B (w e)) / 2 ∧
68
+ bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ
69
+ (fun H => ∑ e ∈ candidateLabels M (fun e => roundedLevel B (w e)) H,
70
+ roundedWeight B (w e)) ≤ optimum M (fun e => roundedWeight B (w e)) := by
71
+ refine ⟨?_, expectation_positiveGreedy_survivors M hE w hB,
72
+ expectation_candidateLabels_le_optimum M hE w B⟩
73
+ intro H
74
+ exact ⟨positiveGreedy_survivors_indep M hE _ H,
75
+ positiveGreedy_survivors_subset M _ H⟩
76
+
77
+ /-- The two-sided optimum rounding estimate `eq:rounding`, including zero weights. -/
78
+ theorem optimum_rounding {n : ℕ} (M : Matroid (Fin n))
79
+ (w : Weights n) (hw : ∀ e, 0 ≤ w e) {B : ℝ} (hB : 1 < B) :
80
+ optimum M w / B ≤ optimum M (fun e => roundedWeight B (w e)) ∧
81
+ optimum M (fun e => roundedWeight B (w e)) ≤ optimum M w := by
82
+ constructor
83
+ · apply (div_le_iff₀ (zero_lt_one.trans hB)).2
84
+ simpa only [mul_comm] using optimum_rounding_bound M B hB w hw
85
+ · exact optimum_mono M _ w (fun e => roundedWeight_le hB (hw e))
86
+
87
+ end MatroidProphet.SourceContracts
88
+
89
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/CandidateContracts.lean ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ /-!
6
+ Source-facing contracts for the candidate filter (setup.tex, Lemma `lem:filter`).
7
+ The sets below are the actual rounded-priority greedy survivors and candidate
8
+ labels, not arbitrary sets satisfying a desired inequality. The fair-mask law
9
+ is the concrete product law `bitsExpectation` on the entire labeled ground set.
10
+ -/
11
+
12
+ namespace MatroidProphet.CandidateContracts
13
+
14
+ open Finset MainAlgorithm
15
+
16
+ /-- The full candidate-mass contract, including pointwise independence and
17
+ containment for every mask. No positivity premise is needed here because the
18
+ rounding map itself discards nonpositive coordinates. -/
19
+ theorem candidate_mass {n : ℕ} (M : Matroid (Fin n))
20
+ (hE : M.E = Set.univ) (w : Weights n) :
21
+ let a := fun e => roundedLevel weightBase (w e)
22
+ let Y := fun H => positiveGreedy M a \ H
23
+ let U := candidateLabels M a
24
+ (∀ H, M.Indep (Y H : Set (Fin n)) ∧ Y H ⊆ U H) ∧
25
+ bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ
26
+ (fun H => ∑ e ∈ Y H, roundedWeight weightBase (w e)) =
27
+ optimum M (fun e => roundedWeight weightBase (w e)) / 2 ∧
28
+ bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ
29
+ (fun H => ∑ e ∈ U H, roundedWeight weightBase (w e)) ≤
30
+ optimum M (fun e => roundedWeight weightBase (w e)) := by
31
+ dsimp only
32
+ refine ⟨?_, ?_, ?_⟩
33
+ · intro H
34
+ exact ⟨positiveGreedy_survivors_indep M hE _ H,
35
+ positiveGreedy_survivors_subset M _ H⟩
36
+ · exact expectation_positiveGreedy_survivors M hE w (by norm_num [weightBase])
37
+ · exact expectation_candidateLabels_le_optimum M hE w weightBase
38
+
39
+ /-- Both inequalities of the source's rounding bound, together with an actual
40
+ independent positive-priority greedy maximizer. This includes zero weights,
41
+ loops, ties, the empty ground set, and rank zero. -/
42
+ theorem rounding_and_greedy {n : ℕ} (M : Matroid (Fin n))
43
+ (hE : M.E = Set.univ) (w : Weights n) (hw : ∀ e, 0 ≤ w e) :
44
+ let u := fun e => roundedWeight weightBase (w e)
45
+ let I := positiveGreedy M (fun e => roundedLevel weightBase (w e))
46
+ optimum M w / weightBase ≤ optimum M u ∧
47
+ optimum M u ≤ optimum M w ∧
48
+ M.Indep (I : Set (Fin n)) ∧
49
+ (∑ e ∈ I, u e) = optimum M u := by
50
+ dsimp only
51
+ have hB : (1 : ℝ) < weightBase := by norm_num [weightBase]
52
+ refine ⟨?_, ?_, positiveGreedy_indep M hE _, ?_⟩
53
+ · apply (div_le_iff₀ (zero_lt_one.trans hB)).2
54
+ simpa only [mul_comm] using optimum_rounding_bound M weightBase hB w hw
55
+ · exact optimum_mono M _ w (fun e => roundedWeight_le hB (hw e))
56
+ · change (∑ e ∈ positiveGreedy M (fun e => roundedLevel weightBase (w e)),
57
+ levelWeight weightBase (roundedLevel weightBase (w e))) = _
58
+ rw [sum_positiveGreedy]
59
+ exact Priority.rounded_greedy_optimal M hE w hB
60
+
61
+ /-- The actual candidate predicate never includes a loop or a nonpositive label.
62
+ This is a pointwise statement for every mask, not only almost surely. -/
63
+ theorem candidate_positive_nonloop {n : ℕ} (M : Matroid (Fin n))
64
+ (w : Weights n) (H : Finset (Fin n)) (e : Fin n)
65
+ (he : e ∈ candidateLabels M (fun f => roundedLevel weightBase (w f)) H) :
66
+ 0 < w e ∧ e ∉ H ∧ e ∉ M.closure ∅ := by
67
+ classical
68
+ have hc : candidate M ⟨H, ∅, ∅, ∅, false⟩
69
+ (fun f => roundedLevel weightBase (w f)) e (roundedLevel weightBase (w e)) :=
70
+ (Finset.mem_filter.mp he).2
71
+ refine ⟨?_, hc.2.1, candidate_not_mem_closure_empty M _ _ _ _ hc⟩
72
+ by_contra hn
73
+ exact hc.1 (by simp [roundedLevel, hn])
74
+
75
+ end MatroidProphet.CandidateContracts
76
+
77
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecification.lean ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib.Combinatorics.Matroid.Closure
2
+ import OAI.Probability.MatroidProphet.Main
3
+
4
+ namespace OAI
5
+
6
+ namespace MatroidProphet.CandidateSpecification
7
+
8
+ open Finset
9
+
10
+ /-- Strict rounded-weight priority, including the fixed label tie-breaking rule. -/
11
+ def higher {n : ℕ} (f : Fin n) (a : Option ℤ) (e : Fin n) (b : Option ℤ) : Prop :=
12
+ match a, b with
13
+ | some i, some j => j < i ∨ j = i ∧ f < e
14
+ | some _, none => True
15
+ | _, _ => False
16
+
17
+ /-- Source candidate set: positive, unobserved, and not spanned by higher-priority
18
+ observed labels. The full candidate set is analytical, not given to the algorithm. -/
19
+ noncomputable def candidates {n : ℕ} (M : Matroid (Fin n))
20
+ (a : Fin n → Option ℤ) (H : Finset (Fin n)) : Finset (Fin n) := by
21
+ classical
22
+ exact Finset.univ.filter fun e => a e ≠ none ∧ e ∉ H ∧
23
+ e ∉ M.closure {f | f ∈ H ∧ higher f (a f) e (a e)}
24
+
25
+ /-- Positive priority-greedy on the entire ground set, characterized by failure
26
+ of the strictly higher-priority labels to span the current label. -/
27
+ noncomputable def greedy {n : ℕ} (M : Matroid (Fin n))
28
+ (a : Fin n → Option ℤ) : Finset (Fin n) := by
29
+ classical
30
+ exact Finset.univ.filter fun e => a e ≠ none ∧
31
+ e ∉ M.closure {f | higher f (a f) e (a e)}
32
+
33
+ /-- The source comparison independent set after sacrificing the fair mask. -/
34
+ noncomputable def survivors {n : ℕ} (M : Matroid (Fin n))
35
+ (a : Fin n → Option ℤ) (H : Finset (Fin n)) : Finset (Fin n) :=
36
+ greedy M a \ H
37
+
38
+ /-- The complete mathematical assertion of Lemma `lem:filter`, stated solely
39
+ using the concrete source definitions and the finite independent fair-mask law. -/
40
+ def CandidateMass : Prop :=
41
+ ∀ (n : ℕ) (M : Matroid (Fin n)), M.E = Set.univ → ∀ w : Weights n,
42
+ let a := fun e => roundedLevel weightBase (w e)
43
+ let u := fun e => roundedWeight weightBase (w e)
44
+ (∀ H, M.Indep (survivors M a H : Set (Fin n)) ∧
45
+ survivors M a H ⊆ candidates M a H) ∧
46
+ bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ
47
+ (fun H => ∑ e ∈ survivors M a H, u e) = optimum M u / 2 ∧
48
+ bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ
49
+ (fun H => ∑ e ∈ candidates M a H, u e) ≤ optimum M u
50
+
51
+ end MatroidProphet.CandidateSpecification
52
+
53
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecificationTheorems.lean ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidSecretary.Selection.CandidateSpecification
2
+ import OAI.Probability.MatroidSecretary.Selection.CandidateContracts
3
+
4
+ namespace OAI
5
+
6
+ /-! Correspondence of the independent source definitions with the implemented
7
+ candidate filter and positive priority-greedy, followed by the source contract. -/
8
+
9
+ namespace MatroidProphet.CandidateSpecification
10
+
11
+ open Finset
12
+
13
+ lemma higher_eq_main {n : ℕ} (f : Fin n) (a : Option ℤ)
14
+ (e : Fin n) (b : Option ℤ) :
15
+ higher f a e b ↔ MainAlgorithm.higher f a e b := Iff.rfl
16
+
17
+ lemma candidates_eq_main {n : ℕ} (M : Matroid (Fin n))
18
+ (a : Fin n → Option ℤ) (H : Finset (Fin n)) :
19
+ candidates M a H = MainAlgorithm.candidateLabels M a H := by
20
+ classical
21
+ rw [MainAlgorithm.candidateLabels, MainAlgorithm.candidateSet_eq_filter]
22
+ ext element
23
+ by_cases hpositive : a element = none
24
+ · simp [candidates, hpositive]
25
+ · have hprior : {label | label ∈ H ∧ higher label (a label) element (a element)} =
26
+ Candidates.prior (Priority.time a) H element := by
27
+ ext label
28
+ simp only [Candidates.prior, Set.mem_ofPred_eq, higher_eq_main,
29
+ Priority.main_higher_iff_time a label element hpositive]
30
+ simp [candidates, Candidates.candidates, hpositive, hprior]
31
+
32
+ lemma greedy_eq_main {n : ℕ} (M : Matroid (Fin n))
33
+ (a : Fin n → Option ℤ) : greedy M a = MainAlgorithm.positiveGreedy M a := by
34
+ classical
35
+ ext e
36
+ by_cases ha : a e = none
37
+ · simp [greedy, MainAlgorithm.positiveGreedy, ha]
38
+ · have hp : {f | higher f (a f) e (a e)} =
39
+ Candidates.prior (Priority.time a) Finset.univ e := by
40
+ ext f
41
+ simp only [Candidates.prior, Finset.mem_univ, true_and,
42
+ Set.mem_ofPred_eq, higher_eq_main, Priority.main_higher_iff_time a f e ha]
43
+ simp [greedy, MainAlgorithm.positiveGreedy, Candidates.greedy, ha, hp]
44
+
45
+ lemma survivors_eq_main {n : ℕ} (M : Matroid (Fin n))
46
+ (a : Fin n → Option ℤ) (H : Finset (Fin n)) :
47
+ survivors M a H = MainAlgorithm.positiveGreedy M a \ H := by
48
+ rw [survivors, greedy_eq_main]
49
+
50
+
51
+
52
+ theorem candidateMass : CandidateMass := by
53
+ intro n M hE w
54
+ simpa only [survivors_eq_main, candidates_eq_main] using
55
+ CandidateContracts.candidate_mass M hE w
56
+
57
+ /-- Candidate membership uses only the focal key and keys on the revealed mask,
58
+ never another unobserved label's key. -/
59
+ lemma candidate_membership_congr {n : ℕ} (M : Matroid (Fin n))
60
+ (a a' : Fin n → Option ℤ) (H : Finset (Fin n)) (e : Fin n)
61
+ (he : a e = a' e) (hH : ∀ f ∈ H, a f = a' f) :
62
+ e ∈ candidates M a H ↔ e ∈ candidates M a' H := by
63
+ classical
64
+ have hp : {f | f ∈ H ∧ higher f (a f) e (a e)} =
65
+ {f | f ∈ H ∧ higher f (a' f) e (a' e)} := by
66
+ ext f
67
+ by_cases hf : f ∈ H
68
+ · simp [hf, he, hH f hf]
69
+ · simp [hf]
70
+ simp only [candidates, Finset.mem_filter, Finset.mem_univ, true_and]
71
+ rw [hp, he]
72
+
73
+ /-- The source greedy definition really attains rounded OPT, with the source's
74
+ rounding comparison on both sides. This verifies the ancillary input `I*` rather
75
+ than assuming its optimality. -/
76
+ theorem source_rounding_and_greedy {n : ℕ} (M : Matroid (Fin n))
77
+ (hE : M.E = Set.univ) (w : Weights n) (hw : ∀ e, 0 ≤ w e) :
78
+ let u := fun e => roundedWeight weightBase (w e)
79
+ let I := greedy M (fun e => roundedLevel weightBase (w e))
80
+ optimum M w / weightBase ≤ optimum M u ∧
81
+ optimum M u ≤ optimum M w ∧
82
+ M.Indep (I : Set (Fin n)) ∧
83
+ (∑ e ∈ I, u e) = optimum M u := by
84
+ simpa only [greedy_eq_main] using CandidateContracts.rounding_and_greedy M hE w hw
85
+
86
+ end MatroidProphet.CandidateSpecification
87
+
88
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/FeasibilityContract.lean ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import OAI.Probability.MatroidSecretary.Accounting.MainFeasibilityContract
3
+ import OAI.Probability.MatroidSecretary.Selection.FeasibilitySpec
4
+ import OAI.Probability.MatroidSecretary.Selection.GreedyExecution
5
+
6
+ namespace OAI
7
+
8
+ /-! Complete source contract for `algorithm.tex`, `lem:feasibility` (lines
9
+ 179--183; source SHA256 b702fa1da832d3cbebcf5a70f0b0e9505b3423e2ed9884c22fe4194ba4974fbe).
10
+ The actual main rule is used, not an abstract feasible-rule hypothesis. -/
11
+
12
+ namespace MatroidProphet
13
+ namespace FeasibilityContract
14
+ open Set Finset MeasureTheory
15
+
16
+ /-- Hidden observations depend only on the initially sacrificed coordinates. -/
17
+ theorem observed_eq_of_eq_on_mask {n bits : ℕ} (A : HiddenRule n bits)
18
+ (r : Seed bits) (w w' : Weights n)
19
+ (h : ∀ e ∈ A.mask r, w e = w' e) :
20
+ observed A r w = observed A r w' := by
21
+ classical
22
+ funext e
23
+ by_cases he : e ∈ A.mask r
24
+ · simp only [observed, ite_eq_left he, h e he]
25
+ · simp only [observed, ite_eq_right he]
26
+
27
+ /-- Hidden execution is nonanticipating: equal initial observations and equal
28
+ revealed histories force equal current decisions, irrespective of future data. -/
29
+ theorem hidden_decision_congr {n bits : ℕ} (A : HiddenRule n bits)
30
+ (r : Seed bits) (w w' : Weights n) (π π' : ArrivalOrder n) (k : Fin n)
31
+ (hmask : ∀ e ∈ A.mask r, w e = w' e)
32
+ (hhist : history w π k = history w' π' k) :
33
+ decisionAt A.core r (observed A r w) w π k =
34
+ decisionAt A.core r (observed A r w') w' π' k := by
35
+ rw [observed_eq_of_eq_on_mask A r w w' hmask]
36
+ exact decisionAt_congr A.core r (observed A r w') w w' π π' k hhist
37
+
38
+ /-- Sacrificing the fixed mask preserves irrevocability. -/
39
+ theorem hiddenAcceptedThrough_mono {n bits : ℕ} (A : HiddenRule n bits)
40
+ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n)
41
+ {t t' : ℕ} (h : t ≤ t') :
42
+ hiddenAcceptedThrough A r w π t ⊆ hiddenAcceptedThrough A r w π t' := by
43
+ intro e he
44
+ obtain ⟨he, hm⟩ := Finset.mem_sdiff.mp he
45
+ exact Finset.mem_sdiff.mpr
46
+ ⟨acceptedThrough_mono A.core r (observed A r w) w π h he, hm⟩
47
+
48
+ /-- No sacrificed observation label is ever accepted. -/
49
+ theorem hiddenAcceptedThrough_disjoint_mask {n bits : ℕ} (A : HiddenRule n bits)
50
+ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) (t : ℕ) :
51
+ Disjoint (hiddenAcceptedThrough A r w π t) (A.mask r) := by
52
+ apply Finset.disjoint_left.mpr
53
+ intro e he hm
54
+ exact (Finset.mem_sdiff.mp he).2 hm
55
+
56
+ /-- All parts of the manuscript's feasibility and information contract for the
57
+ actual layered main algorithm. Empty ground sets, loops, zero weights, ties,
58
+ and empty group lists remain within the quantified input domain. -/
59
+ theorem main_rule {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ) :
60
+ (∀ (w : Weights n), (∀ e, 0 ≤ w e) →
61
+ ∀ (r : Seed (mainSeedBits n)) (π : ArrivalOrder n) (t : ℕ),
62
+ M.Indep (hiddenAcceptedThrough (MainAlgorithm.hidden M hE) r w π t : Set (Fin n))) ∧
63
+ (∀ k, Measurable
64
+ (fun x : Seed (mainSeedBits n) × (Weights n × History n k) =>
65
+ (MainAlgorithm.core M hE).decide k x.1 x.2.1 x.2.2)) ∧
66
+ (∀ (r : Seed (mainSeedBits n)) (w w' : Weights n)
67
+ (π π' : ArrivalOrder n) (k : Fin n),
68
+ (∀ e ∈ (MainAlgorithm.hidden M hE).mask r, w e = w' e) →
69
+ history w π k = history w' π' k →
70
+ decisionAt (MainAlgorithm.core M hE) r
71
+ (observed (MainAlgorithm.hidden M hE) r w) w π k =
72
+ decisionAt (MainAlgorithm.core M hE) r
73
+ (observed (MainAlgorithm.hidden M hE) r w') w' π' k) ∧
74
+ (∀ (r : Seed (mainSeedBits n)) (w : Weights n) (π : ArrivalOrder n)
75
+ (t t' : ℕ), t ≤ t' →
76
+ hiddenAcceptedThrough (MainAlgorithm.hidden M hE) r w π t ⊆
77
+ hiddenAcceptedThrough (MainAlgorithm.hidden M hE) r w π t') ∧
78
+ (∀ (r : Seed (mainSeedBits n)) (w : Weights n) (π : ArrivalOrder n) (t : ℕ),
79
+ Disjoint (hiddenAcceptedThrough (MainAlgorithm.hidden M hE) r w π t)
80
+ ((mainMasks r).H ∪ (mainMasks r).D ∪ (mainMasks r).C)) := by
81
+ refine ⟨MainAlgorithm.hidden_feasible M hE, ?_, ?_, ?_, ?_⟩
82
+ · exact (MainAlgorithm.core M hE).measurable_decide
83
+ · exact hidden_decision_congr (MainAlgorithm.hidden M hE)
84
+ · intro r w π t t' ht
85
+ exact hiddenAcceptedThrough_mono (MainAlgorithm.hidden M hE) r w π ht
86
+ · exact hiddenAcceptedThrough_disjoint_mask (MainAlgorithm.hidden M hE)
87
+
88
+ /-- The empty listed-group case cannot assign any arriving label to a layer. -/
89
+ theorem assign_none_of_groups_nil {n : ℕ} (M : Matroid (Fin n))
90
+ (hE : M.E = Set.univ) (d : MainMasks n) (seen : Fin n → Option ℤ)
91
+ (hg : MainAlgorithm.groups M d seen = []) (e : Fin n) (w : Option ℤ) :
92
+ MainAlgorithm.assign M hE d seen e w = none := by
93
+ classical
94
+ cases w with
95
+ | none => rfl
96
+ | some i =>
97
+ have hn : ¬ MainAlgorithm.eligible M hE d seen e i := by
98
+ intro he
99
+ simpa [hg] using he.2.2.1
100
+ simp [MainAlgorithm.assign, hn]
101
+
102
+ /-- Zero weights do not enter a logarithm and are assigned no layer. -/
103
+ theorem assign_zero {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ)
104
+ (d : MainMasks n) (seen : Fin n → Option ℤ) (e : Fin n) :
105
+ MainAlgorithm.assign M hE d seen e (roundedLevel weightBase 0) = none := by
106
+ simp [roundedLevel, MainAlgorithm.assign]
107
+
108
+ /-- A loop can never pass the actual candidate test, regardless of priorities. -/
109
+ theorem not_candidate_of_loop {n : ℕ} (M : Matroid (Fin n)) (d : MainMasks n)
110
+ (seen : Fin n → Option ℤ) (e : Fin n) (w : Option ℤ)
111
+ (he : e ∈ M.closure ∅) : ¬ MainAlgorithm.candidate M d seen e w := by
112
+ intro hc
113
+ exact hc.2.2 (M.closure_subset_closure (Set.empty_subset _) he)
114
+
115
+ /-- The complete required `lem:feasibility` contract, for the concrete source rule. -/
116
+ theorem source_main_feasibility {n : ℕ} (M : Matroid (Fin n))
117
+ (hE : M.E = Set.univ) : MainRuleFeasibility M (MainAlgorithm.hidden M hE) :=
118
+ MainAlgorithm.source_feasibility_contract M hE
119
+
120
+ end FeasibilityContract
121
+ end MatroidProphet
122
+
123
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/FeasibilitySpec.lean ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ namespace MatroidProphet
6
+ open Set Finset MeasureTheory
7
+
8
+ /-- Core and hidden prefix feasibility, measurability after masking the initial
9
+ observations, complete accepted-set nonanticipation, irrevocability, and literal
10
+ rejection of sacrificed labels. The mask depends only on the initial seed by
11
+ the type of `HiddenRule`; no weight-dependent mask is allowed. -/
12
+ def MainRuleFeasibility {n bits : ℕ} (M : Matroid (Fin n))
13
+ (A : HiddenRule n bits) : Prop :=
14
+ Feasible M A.core ∧
15
+ (∀ k, Measurable (fun x : Seed bits × (Weights n × History n k) =>
16
+ A.core.decide k x.1 (observed A x.1 x.2.1) x.2.2)) ∧
17
+ (∀ (w : Weights n), (∀ e, 0 ≤ w e) →
18
+ ∀ (r : Seed bits) (π : ArrivalOrder n) (t : ℕ),
19
+ M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n))) ∧
20
+ (∀ (r : Seed bits) (w w' : Weights n) (π π' : ArrivalOrder n) (t : ℕ),
21
+ (∀ e ∈ A.mask r, w e = w' e) →
22
+ (∀ j : Fin n, j.val < t → (π j, w (π j)) = (π' j, w' (π' j))) →
23
+ hiddenAcceptedThrough A r w π t = hiddenAcceptedThrough A r w' π' t) ∧
24
+ (∀ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n),
25
+ Monotone (hiddenAcceptedThrough A r w π)) ∧
26
+ (∀ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) (t : ℕ),
27
+ Disjoint (hiddenAcceptedThrough A r w π t) (A.mask r))
28
+
29
+ end MatroidProphet
30
+
31
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/GreedyExecution.lean ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ /-! Exact agreement between the source's previous-accepted-label test and the
6
+ concrete implementation's previous-eligible-label test. No arrival-order
7
+ assumption beyond the explicit arrival times is used in span preservation. -/
8
+
9
+ namespace MatroidProphet
10
+ open Set Finset
11
+
12
+ variable {α : Type*} [DecidableEq α]
13
+
14
+ /-- Rejected earlier eligible labels do not change the span of a layer prefix. -/
15
+ theorem layerGreedy_closure_prior (M : Matroid α) (E : Finset α)
16
+ (base : ℤ → Set α) (layer : α → ℤ) (time : α → ℕ)
17
+ (hE : M.E = Set.univ) (b : ℤ) (k : ℕ) :
18
+ M.closure (base b ∪ layerPrior E layer time b k) =
19
+ M.closure (base b ∪
20
+ layerPrior (layerGreedy M E base layer time) layer time b k) := by
21
+ apply Set.Subset.antisymm
22
+ · apply M.closure_subset_closure_of_subset_closure
23
+ rintro e (he | ⟨he, hb, ht⟩)
24
+ · exact M.mem_closure_of_mem' (Or.inl he) (by simp [hE])
25
+ · have hs := layerGreedy_spans_prefix M E base layer time hE e he
26
+ apply M.closure_subset_closure ?_ hs
27
+ rintro f (hf | ⟨hf, hfb, hft⟩)
28
+ · exact Or.inl (by simpa [hb] using hf)
29
+ · exact Or.inr ⟨hf, hfb.trans hb, hft.trans_lt ht⟩
30
+ · apply M.closure_subset_closure
31
+ rintro e (he | ⟨he, hb, ht⟩)
32
+ · exact Or.inl he
33
+ · exact Or.inr ⟨layerGreedy_subset M E base layer time he, hb, ht⟩
34
+
35
+ /-- The online decision can be implemented using only earlier accepted labels
36
+ of the same layer, exactly as in step 3 of the manuscript algorithm. -/
37
+ theorem layerGreedy_mem_iff_previous_accepted (M : Matroid α) (E : Finset α)
38
+ (base : ℤ → Set α) (layer : α → ℤ) (time : α → ℕ)
39
+ (hE : M.E = Set.univ) (e : α) :
40
+ e ∈ layerGreedy M E base layer time ↔
41
+ e ∈ E ∧ e ∉ M.closure (base (layer e) ∪
42
+ layerPrior (layerGreedy M E base layer time) layer time (layer e) (time e)) := by
43
+ classical
44
+ conv_lhs => unfold layerGreedy
45
+ rw [Finset.mem_filter]
46
+ rw [layerGreedy_closure_prior M E base layer time hE]
47
+
48
+ omit [DecidableEq α] in
49
+ /-- On a finite ground set the source's rank-one test is precisely nonmembership
50
+ in the closure, including rank-zero and loop cases. -/
51
+ theorem conditionalRank_singleton_eq_one_iff [Fintype α] (M : Matroid α)
52
+ (hE : M.E = Set.univ) (P : Set α) (e : α) :
53
+ conditionalRank M {e} P = 1 ↔ e ∉ M.closure P := by
54
+ by_cases he : e ∈ M.closure P
55
+ · rw [Pivots.conditionalRank_singleton_of_mem_closure M P he]
56
+ simp [he]
57
+ · rw [Pivots.conditionalRank_singleton_of_notMem_closure M P (by simp [hE]) he]
58
+ simp [he]
59
+
60
+ /-- Exact rank form of the source's accept/reject condition. -/
61
+ theorem layerGreedy_mem_iff_rank_previous_accepted [Fintype α]
62
+ (M : Matroid α) (E : Finset α) (base : ℤ → Set α)
63
+ (layer : α → ℤ) (time : α → ℕ) (hE : M.E = Set.univ) (e : α) :
64
+ e ∈ layerGreedy M E base layer time ↔
65
+ e ∈ E ∧ conditionalRank M {e} (base (layer e) ∪
66
+ layerPrior (layerGreedy M E base layer time) layer time (layer e) (time e)) = 1 := by
67
+ rw [layerGreedy_mem_iff_previous_accepted M E base layer time hE,
68
+ conditionalRank_singleton_eq_one_iff M hE]
69
+
70
+ /-- The concrete history-based online decision agrees with the rank test on
71
+ previously accepted labels in the current layer. -/
72
+ theorem layerKeyDecision_eq_rank_previous_accepted {n : ℕ} {K : Type*}
73
+ (M : Matroid (Fin n)) (hE : M.E = Set.univ) (base : ℤ → Set (Fin n))
74
+ (assign : Fin n → K → Option ℤ) (v : Fin n → K)
75
+ (π : ArrivalOrder n) (k : Fin n) :
76
+ layerKeyDecision M base assign k (keyHistory v π k) = true ↔
77
+ π k ∈ assignedEligible assign v ∧
78
+ conditionalRank M {π k} (base (assignedLayer assign v (π k)) ∪
79
+ layerPrior
80
+ (layerGreedy M (assignedEligible assign v) base (assignedLayer assign v)
81
+ (fun e => (π.symm e).val))
82
+ (assignedLayer assign v) (fun e => (π.symm e).val)
83
+ (assignedLayer assign v (π k)) k.val) = 1 := by
84
+ rw [layerKeyDecision_eq_greedy,
85
+ layerGreedy_mem_iff_rank_previous_accepted M _ _ _ _ hE]
86
+ simp only [Equiv.symm_apply_apply]
87
+
88
+ end MatroidProphet
89
+
90
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/LayerImplementation.lean ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ /-!
6
+ # The layer rule is the source's accepted-prefix greedy rule
7
+
8
+ The implementation tests the span of all previous eligible labels. The source
9
+ algorithm tests the span of the previous accepted labels. Prefix span preservation
10
+ makes these tests exactly equal, not merely comparable in final reward.
11
+ -/
12
+
13
+ namespace MatroidProphet
14
+ open Set Finset
15
+
16
+ lemma layerGreedy_closure_prefix {α : Type*} [DecidableEq α]
17
+ (M : Matroid α) (E : Finset α) (base : ℤ → Set α)
18
+ (layer : α → ℤ) (time : α → ℕ) (hE : M.E = Set.univ) (b : ℤ) (k : ℕ) :
19
+ M.closure (base b ∪ layerPrior E layer time b k) =
20
+ M.closure (base b ∪
21
+ {e | e ∈ layerGreedy M E base layer time ∧ layer e = b ∧ time e < k}) := by
22
+ apply Set.Subset.antisymm
23
+ · apply M.closure_subset_closure_of_subset_closure
24
+ rintro e (he | ⟨he, hb, ht⟩)
25
+ · exact M.mem_closure_of_mem' (Or.inl he) (by simp [hE])
26
+ · have hs := layerGreedy_spans_prefix M E base layer time hE e he
27
+ apply M.closure_subset_closure _ hs
28
+ rintro f (hf | ⟨hf, hfb, hft⟩)
29
+ · exact Or.inl (by simpa only [hb] using hf)
30
+ · exact Or.inr ⟨hf, hfb.trans hb, hft.trans_lt ht⟩
31
+ · apply M.closure_subset_closure
32
+ rintro e (he | ⟨he, hb, ht⟩)
33
+ · exact Or.inl he
34
+ · exact Or.inr ⟨layerGreedy_subset M E base layer time he, hb, ht⟩
35
+
36
+ /-- The actual layer acceptance test may use only its earlier accepted labels. -/
37
+ theorem layerGreedy_mem_iff_accepted_prefix {α : Type*} [DecidableEq α]
38
+ (M : Matroid α) (E : Finset α) (base : ℤ → Set α)
39
+ (layer : α → ℤ) (time : α → ℕ) (hE : M.E = Set.univ) (e : α) :
40
+ e ∈ layerGreedy M E base layer time ↔
41
+ e ∈ E ∧ e ∉ M.closure (base (layer e) ∪
42
+ {f | f ∈ layerGreedy M E base layer time ∧
43
+ layer f = layer e ∧ time f < time e}) := by
44
+ classical
45
+ rw [show e ∈ layerGreedy M E base layer time ↔ e ∈ E ∧
46
+ e ∉ M.closure (base (layer e) ∪ layerPrior E layer time (layer e) (time e)) from
47
+ Finset.mem_filter]
48
+ rw [layerGreedy_closure_prefix M E base layer time hE]
49
+
50
+ /-- Exact conditional-rank form of the source test at an arrival. -/
51
+ theorem layerGreedy_mem_iff_rank_one {α : Type*} [Fintype α] [DecidableEq α]
52
+ (M : Matroid α) (E : Finset α) (base : ℤ → Set α)
53
+ (layer : α → ℤ) (time : α → ℕ) (hE : M.E = Set.univ) (e : α) :
54
+ e ∈ layerGreedy M E base layer time ↔
55
+ e ∈ E ∧ conditionalRank M {e} (base (layer e) ∪
56
+ {f | f ∈ layerGreedy M E base layer time ∧
57
+ layer f = layer e ∧ time f < time e}) = 1 := by
58
+ rw [layerGreedy_mem_iff_accepted_prefix M E base layer time hE]
59
+ constructor
60
+ · rintro ⟨he, hne⟩
61
+ exact ⟨he, Pivots.conditionalRank_singleton_of_notMem_closure M _
62
+ (by simp [hE]) hne⟩
63
+ · rintro ⟨he, hr⟩
64
+ refine ⟨he, ?_⟩
65
+ intro hmem
66
+ have hz := Pivots.conditionalRank_singleton_of_mem_closure M _ hmem
67
+ omega
68
+
69
+ end MatroidProphet
70
+
71
+ end OAI
lean/OAI/Probability/MatroidSecretary/Selection/SafeSpecification.lean ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ namespace MatroidProphet
6
+
7
+ open MainAlgorithm
8
+
9
+ /-- The source safety guarantee, including the literal constants, all listed
10
+ groups, global independent comparison set, and the harmless unlisted zero case. -/
11
+ def SafeSampleClaim : Prop :=
12
+ ∀ (n : ℕ) (M : Matroid (Fin n)) (hE : M.E = Set.univ)
13
+ (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
14
+ (Y : Set (Fin n)), M.Indep Y →
15
+ exitThreshold / 4 *
16
+ ((d.D : Set (Fin n)) ∩ (Y ∩ (trueGroup M d s i : Set (Fin n)))).ncard -
17
+ (d.D ∩ trueGroup M d s i).card / densityThreshold ≤
18
+ bitsExpectation (fun _ => thinningRate) Finset.univ (fun C =>
19
+ bitsExpectation (fun _ => thinningRate) Finset.univ (fun T =>
20
+ fairParityExpectation (fun p =>
21
+ (listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i Y
22
+ (boolParity p) : ℝ))))
23
+
24
+ end MatroidProphet
25
+
26
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/AdversarialMinimum.lean ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import Mathlib.MeasureTheory.Integral.Bochner.Basic
3
+
4
+ namespace OAI
5
+
6
+ open MeasureTheory
7
+
8
+ namespace MatroidProphet
9
+
10
+ /-- For a fixed vector, arbitrary measurable seed-dependent orders give an
11
+ integrable reward under every finite measure. No feasibility or sign assumption
12
+ is needed, since the seed and order spaces are finite. -/
13
+ lemma integrable_hiddenReward_randomOrder {n bits : ℕ} (A : HiddenRule n bits)
14
+ (w : Weights n) {Ω : Type*} [MeasurableSpace Ω]
15
+ (μ : Measure Ω) [IsFiniteMeasure μ]
16
+ (R : Ω → Seed bits) (π : Ω → ArrivalOrder n)
17
+ (hR : Measurable R) (hπ : Measurable π) :
18
+ Integrable (fun ω => hiddenReward A (R ω) w (π ω)) μ := by
19
+ let f : Seed bits × ArrivalOrder n → ℝ := fun x => hiddenReward A x.1 w x.2
20
+ have hf : Measurable f := measurable_of_finite f
21
+ have hpair : Measurable (fun ω => (R ω, π ω)) := hR.prodMk hπ
22
+ exact (integrable_map_measure hf.aestronglyMeasurable hpair.aemeasurable).1
23
+ (Integrable.of_finite (f := f))
24
+
25
+ /-- The seedwise minimum is integrable after any measurable finite-seed map. -/
26
+ lemma integrable_hiddenWorstReward_comp {n bits : ℕ} (A : HiddenRule n bits)
27
+ (w : Weights n) {Ω : Type*} [MeasurableSpace Ω]
28
+ (μ : Measure Ω) [IsFiniteMeasure μ]
29
+ (R : Ω → Seed bits) (hR : Measurable R) :
30
+ Integrable (fun ω => hiddenWorstReward A w (R ω)) μ := by
31
+ have hf : Measurable (hiddenWorstReward A w) := measurable_of_finite _
32
+ exact (integrable_map_measure hf.aestronglyMeasurable hR.aemeasurable).1
33
+ (Integrable.of_finite (f := hiddenWorstReward A w))
34
+
35
+ /-- A reconstructed seed's correct marginal transports the expected minimum to
36
+ any measurable full-information order. The order need not be independent of the
37
+ seed, and the ambient space may carry arbitrarily much additional information. -/
38
+ theorem hiddenWorstReward_integral_le_randomOrder {n bits : ℕ}
39
+ (A : HiddenRule n bits) (w : Weights n)
40
+ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ]
41
+ (ν : Measure (Seed bits)) (R : Ω → Seed bits) (π : Ω → ArrivalOrder n)
42
+ (hR : Measurable R) (hπ : Measurable π) (hRlaw : μ.map R = ν) :
43
+ (∫ r, hiddenWorstReward A w r ∂ν) ≤
44
+ ∫ ω, hiddenReward A (R ω) w (π ω) ∂μ := by
45
+ have hf : Measurable (hiddenWorstReward A w) := measurable_of_finite _
46
+ rw [← hRlaw, integral_map_of_stronglyMeasurable hR hf.stronglyMeasurable]
47
+ apply integral_mono
48
+ (integrable_hiddenWorstReward_comp A w μ R hR)
49
+ (integrable_hiddenReward_randomOrder A w μ R π hR hπ)
50
+ intro ω
51
+ exact hiddenWorstReward_le A w (R ω) (π ω)
52
+
53
+ /-- A pointwise accepted-reward identity may be replaced by an almost-everywhere
54
+ identity. This is useful when a reconstruction kernel has zero-mass seed outcomes. -/
55
+ theorem hiddenWorstReward_integral_le_replayed {n bits : ℕ}
56
+ (A : HiddenRule n bits) (w : Weights n)
57
+ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ]
58
+ (ν : Measure (Seed bits)) (R : Ω → Seed bits) (π : Ω → ArrivalOrder n)
59
+ (hR : Measurable R) (hπ : Measurable π) (hRlaw : μ.map R = ν)
60
+ (payoff : Ω → ℝ)
61
+ (hreplay : payoff =ᵐ[μ] fun ω => hiddenReward A (R ω) w (π ω)) :
62
+ Integrable payoff μ ∧ (∫ r, hiddenWorstReward A w r ∂ν) ≤ ∫ ω, payoff ω ∂μ := by
63
+ refine ⟨(integrable_hiddenReward_randomOrder A w μ R π hR hπ).congr hreplay.symm, ?_⟩
64
+ rw [integral_congr_ae hreplay]
65
+ exact hiddenWorstReward_integral_le_randomOrder A w μ ν R π hR hπ hRlaw
66
+
67
+ /-- There is a measurable adversary attaining the minimum separately at every
68
+ seed. Thus the minimum used above is genuinely inside expectation, not the
69
+ minimum of fixed-order expected rewards. -/
70
+ lemma exists_measurable_worstOrder {n bits : ℕ} (A : HiddenRule n bits)
71
+ (w : Weights n) :
72
+ ∃ π : Seed bits → ArrivalOrder n, Measurable π ∧
73
+ ∀ r, hiddenReward A r w (π r) = hiddenWorstReward A w r := by
74
+ classical
75
+ have hex (r : Seed bits) :
76
+ ∃ π : ArrivalOrder n, hiddenReward A r w π = hiddenWorstReward A w r := by
77
+ obtain ⟨π, _, hπ⟩ := Finset.exists_mem_eq_inf'
78
+ (s := (Finset.univ : Finset (ArrivalOrder n))) Finset.univ_nonempty
79
+ (hiddenReward A r w)
80
+ exact ⟨π, hπ.symm⟩
81
+ choose π hπ using hex
82
+ exact ⟨π, measurable_of_finite π, hπ⟩
83
+
84
+ /-- The lower bound is sharp among measurable full-seed order policies. -/
85
+ lemma exists_order_integral_eq_hiddenWorstReward {n bits : ℕ}
86
+ (A : HiddenRule n bits) (w : Weights n) (ν : Measure (Seed bits)) :
87
+ ∃ π : Seed bits → ArrivalOrder n, Measurable π ∧
88
+ (∫ r, hiddenReward A r w (π r) ∂ν) = ∫ r, hiddenWorstReward A w r ∂ν := by
89
+ obtain ⟨π, hπ, heq⟩ := exists_measurable_worstOrder A w
90
+ exact ⟨π, hπ, integral_congr_ae (ae_of_all _ heq)⟩
91
+
92
+ end MatroidProphet
93
+
94
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulation.lean ADDED
@@ -0,0 +1,391 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidSecretary.Transport.GeneralSimulationModel
2
+ import OAI.Probability.MatroidProphet.Main
3
+ import Mathlib.MeasureTheory.Integral.Prod
4
+
5
+ namespace OAI
6
+
7
+ /-! One-sample simulation for an arbitrary measurable complete seed. -/
8
+
9
+ namespace MatroidProphet.General
10
+
11
+ open MeasureTheory ProbabilityTheory
12
+
13
+ variable {n : ℕ} {R : Type*} [MeasurableSpace R]
14
+
15
+ lemma measurable_mask_membership :
16
+ MeasurableSet {x : Finset (Fin n) × Fin n | x.2 ∈ x.1} :=
17
+ (Set.toFinite _).measurableSet
18
+
19
+ lemma measurable_observed (A : HiddenRule n R) :
20
+ Measurable (fun x : R × Weights n => observed A x.1 x.2) := by
21
+ classical
22
+ apply Measurable.of_eval
23
+ intro e
24
+ have hm : MeasurableSet {x : R × Weights n | e ∈ A.mask x.1} :=
25
+ (measurableSet_mem_finset e).preimage (A.measurable_mask.comp measurable_fst)
26
+ exact Measurable.ite hm ((measurable_pi_apply e).comp measurable_snd) measurable_const
27
+
28
+ lemma measurable_simulationHistory (A : HiddenRule n R) (k : Fin n) :
29
+ Measurable (fun x : R × (Weights n × History n k) =>
30
+ simulationHistory A x.1 x.2.1 x.2.2) := by
31
+ classical
32
+ apply Measurable.of_eval
33
+ intro j
34
+ have hh : Measurable (fun x : R × (Weights n × History n k) => x.2.2 j) :=
35
+ (measurable_pi_apply j).comp (measurable_snd.comp measurable_snd)
36
+ have hm : MeasurableSet {x : R × (Weights n × History n k) |
37
+ (x.2.2 j).1 ∈ A.mask x.1} :=
38
+ measurable_mask_membership.preimage
39
+ ((A.measurable_mask.comp measurable_fst).prodMk (measurable_fst.comp hh))
40
+ exact (measurable_fst.comp hh).prodMk (Measurable.ite hm
41
+ (MatroidProphet.measurable_weight_eval.comp
42
+ ((measurable_fst.comp measurable_snd).prodMk (measurable_fst.comp hh)))
43
+ (measurable_snd.comp hh))
44
+
45
+ lemma measurable_simulationDecision (A : HiddenRule n R) (k : Fin n) :
46
+ Measurable (fun x : R × (Weights n × History n k) =>
47
+ simulationDecision A k x.1 x.2.1 x.2.2) := by
48
+ classical
49
+ have hc : Measurable (fun x : R × (Weights n × History n k) =>
50
+ (x.2.2 ⟨k.val, Nat.lt_succ_self _⟩).1) :=
51
+ measurable_fst.comp ((measurable_pi_apply
52
+ (⟨k.val, Nat.lt_succ_self _⟩ : Fin (k.val + 1))).comp
53
+ (measurable_snd.comp measurable_snd))
54
+ have hm : MeasurableSet {x : R × (Weights n × History n k) |
55
+ (x.2.2 ⟨k.val, Nat.lt_succ_self _⟩).1 ∈ A.mask x.1} :=
56
+ measurable_mask_membership.preimage
57
+ ((A.measurable_mask.comp measurable_fst).prodMk hc)
58
+ exact Measurable.ite hm measurable_const
59
+ ((A.core.measurable_decide k).comp (measurable_fst.prodMk
60
+ (((measurable_observed A).comp
61
+ (measurable_fst.prodMk (measurable_fst.comp measurable_snd))).prodMk
62
+ (measurable_simulationHistory A k))))
63
+
64
+ noncomputable def sampleSimulation (A : HiddenRule n R) : OnlineRule n R where
65
+ decide := simulationDecision A
66
+ measurable_decide := measurable_simulationDecision A
67
+
68
+ lemma observed_glue (A : HiddenRule n R) (r : R) (s v : Weights n) :
69
+ observed A r (glue (A.mask r) s v) = observed A r s := by
70
+ classical
71
+ funext e
72
+ by_cases he : e ∈ A.mask r <;> simp [observed, glue, he]
73
+
74
+ lemma simulationHistory_eq (A : HiddenRule n R) (r : R)
75
+ (s v : Weights n) (π : ArrivalOrder n) (k : Fin n) :
76
+ simulationHistory A r s (history v π k) = history (glue (A.mask r) s v) π k := rfl
77
+
78
+ theorem sampleSimulation_acceptedThrough (A : HiddenRule n R) (r : R)
79
+ (s v : Weights n) (π : ArrivalOrder n) (t : ℕ) :
80
+ acceptedThrough (sampleSimulation A) r s v π t =
81
+ hiddenAcceptedThrough A r (glue (A.mask r) s v) π t := by
82
+ classical
83
+ ext e
84
+ by_cases he : e ∈ A.mask r <;>
85
+ simp [acceptedThrough, hiddenAcceptedThrough, decisionAt, sampleSimulation,
86
+ simulationDecision, history, prefixIndex, simulationHistory_eq, observed_glue, he]
87
+
88
+ theorem sampleSimulation_reward (A : HiddenRule n R) (r : R)
89
+ (s v : Weights n) (π : ArrivalOrder n) :
90
+ reward (sampleSimulation A) r s v π = hiddenReward A r (glue (A.mask r) s v) π := by
91
+ classical
92
+ unfold reward hiddenReward
93
+ rw [sampleSimulation_acceptedThrough]
94
+ apply Finset.sum_congr rfl
95
+ intro e he
96
+ have he' : e ∉ A.mask r := (Finset.mem_sdiff.mp he).2
97
+ simp [glue, he']
98
+
99
+ theorem sampleSimulation_feasible (M : Matroid (Fin n)) (A : HiddenRule n R)
100
+ (hA : HiddenFeasible M A) : Feasible M (sampleSimulation A) := by
101
+ intro r s v π t hs hv
102
+ rw [sampleSimulation_acceptedThrough]
103
+ apply hA
104
+ intro e
105
+ classical
106
+ by_cases he : e ∈ A.mask r
107
+ · simpa [glue, he] using hs e
108
+ · simpa [glue, he] using hv e
109
+
110
+ lemma reward_nonneg (A : OnlineRule n R) (r : R) (s v : Weights n)
111
+ (π : ArrivalOrder n) (hv : ∀ e, 0 ≤ v e) : 0 ≤ reward A r s v π :=
112
+ Finset.sum_nonneg fun e _ => hv e
113
+
114
+ lemma reward_le_optimum (M : Matroid (Fin n)) (A : OnlineRule n R)
115
+ (hA : Feasible M A) (r : R) (s v : Weights n) (π : ArrivalOrder n)
116
+ (hs : ∀ e, 0 ≤ s e) (hv : ∀ e, 0 ≤ v e) :
117
+ reward A r s v π ≤ optimum M v :=
118
+ sum_le_optimum M v _ (hA r s v π n hs hv)
119
+
120
+ lemma hiddenWorstReward_le (A : HiddenRule n R) (w : Weights n)
121
+ (r : R) (π : ArrivalOrder n) :
122
+ hiddenWorstReward A w r ≤ hiddenReward A r w π := by
123
+ classical
124
+ exact Finset.inf'_le (hiddenReward A r w) (Finset.mem_univ π)
125
+
126
+ lemma hiddenWorstReward_nonneg (A : HiddenRule n R) (w : Weights n)
127
+ (hw : ∀ e, 0 ≤ w e) (r : R) : 0 ≤ hiddenWorstReward A w r := by
128
+ classical
129
+ apply Finset.le_inf'
130
+ intro π _
131
+ exact Finset.sum_nonneg fun e _ => hw e
132
+
133
+ lemma hiddenWorstReward_le_optimum (M : Matroid (Fin n)) (A : HiddenRule n R)
134
+ (hA : HiddenFeasible M A) (w : Weights n) (hw : ∀ e, 0 ≤ w e) (r : R) :
135
+ hiddenWorstReward A w r ≤ optimum M w := by
136
+ apply (hiddenWorstReward_le A w r (Equiv.refl _)).trans
137
+ exact sum_le_optimum M w _ (hA w hw r (Equiv.refl _) n)
138
+
139
+ lemma measurable_decisionAt {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R)
140
+ (π : ArrivalOrder n) (k : Fin n) :
141
+ Measurable (fun x : R × (Weights n × Weights n) =>
142
+ decisionAt A x.1 x.2.1 x.2.2 π k) :=
143
+ (A.measurable_decide k).comp
144
+ (measurable_fst.prodMk ((measurable_fst.comp measurable_snd).prodMk
145
+ ((measurable_history π k).comp (measurable_snd.comp measurable_snd))))
146
+
147
+ lemma reward_eq_sum {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R) (r : R)
148
+ (s v : Weights n) (π : ArrivalOrder n) :
149
+ reward A r s v π =
150
+ ∑ e : Fin n, if decisionAt A r s v π (π.symm e) = true then v e else 0 := by
151
+ classical
152
+ unfold reward acceptedThrough
153
+ rw [Finset.sum_filter]
154
+ apply Finset.sum_congr rfl
155
+ intro e _
156
+ simp only [(π.symm e).isLt, true_and]
157
+
158
+ lemma measurable_reward_fixed_order {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R)
159
+ (π : ArrivalOrder n) :
160
+ Measurable (fun x : R × (Weights n × Weights n) =>
161
+ reward A x.1 x.2.1 x.2.2 π) := by
162
+ classical
163
+ simp_rw [reward_eq_sum]
164
+ apply Finset.measurable_sum
165
+ intro e _
166
+ have hd := measurable_decisionAt A π (π.symm e)
167
+ have ht : MeasurableSet {x : R × (Weights n × Weights n) |
168
+ decisionAt A x.1 x.2.1 x.2.2 π (π.symm e) = true} :=
169
+ hd (measurableSet_singleton true)
170
+ exact Measurable.ite ht
171
+ ((measurable_pi_apply e).comp (measurable_snd.comp measurable_snd)) measurable_const
172
+
173
+ /-- The realized reward remains measurable for arbitrary measurable adversarial permutations. -/
174
+ theorem measurable_reward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R) :
175
+ Measurable (fun x : ArrivalOrder n × (R × (Weights n × Weights n)) =>
176
+ reward A x.2.1 x.2.2.1 x.2.2.2 x.1) :=
177
+ measurable_from_prod_countable_right (measurable_reward_fixed_order A)
178
+
179
+ @[simp] lemma glue_self (mask : Finset (Fin n)) (w : Weights n) :
180
+ glue mask w w = w := by
181
+ classical
182
+ funext e
183
+ simp [glue]
184
+
185
+ lemma measurable_hiddenReward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : HiddenRule n R) (π : ArrivalOrder n) :
186
+ Measurable (fun x : R × Weights n => hiddenReward A x.1 x.2 π) := by
187
+ have hm := (measurable_reward_fixed_order (sampleSimulation A) π).comp
188
+ (measurable_fst.prodMk (measurable_snd.prodMk measurable_snd))
189
+ simpa only [Function.comp_def, sampleSimulation_reward, glue_self] using hm
190
+
191
+ lemma measurable_hiddenWorstReward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : HiddenRule n R) :
192
+ Measurable (fun x : R × Weights n => hiddenWorstReward A x.2 x.1) := by
193
+ classical
194
+ have hm : Measurable ((Finset.univ : Finset (ArrivalOrder n)).inf'
195
+ Finset.univ_nonempty (fun π (x : R × Weights n) => hiddenReward A x.1 x.2 π)) :=
196
+ Finset.inf'_induction Finset.univ_nonempty _
197
+ (fun _ hf _ hg => hf.inf hg) (fun π _ => measurable_hiddenReward A π)
198
+ convert hm using 1
199
+ ext x
200
+ simp only [hiddenWorstReward, Finset.inf'_apply]
201
+
202
+ lemma measurable_glue (mask : Finset (Fin n)) :
203
+ Measurable (fun x : Weights n × Weights n => glue mask x.1 x.2) :=
204
+ MatroidProphet.measurable_glue mask
205
+
206
+ lemma measurable_glue_seed (mask : R → Finset (Fin n)) (hmask : Measurable mask) :
207
+ Measurable (fun x : R × (Weights n × Weights n) => glue (mask x.1) x.2.1 x.2.2) := by
208
+ have h : Measurable (fun x : Finset (Fin n) × (Weights n × Weights n) =>
209
+ glue x.1 x.2.1 x.2.2) :=
210
+ measurable_from_prod_countable_right measurable_glue
211
+ exact h.comp ((hmask.comp measurable_fst).prodMk measurable_snd)
212
+
213
+ theorem glue_fixed_law {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)
214
+ (S V : Ω → Weights n) (hS : Measurable S) (hV : Measurable V)
215
+ (hi : iIndepFun (pairedCoordinates S V) μ)
216
+ (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e))
217
+ (mask : Finset (Fin n)) :
218
+ μ.map (fun ω => glue mask (S ω) (V ω)) = μ.map V :=
219
+ MatroidProphet.glue_fixed_law μ S V hS hV hi hlaw mask
220
+
221
+ /-- Joint gluing law with an arbitrary measurable complete seed; in particular,
222
+ the observation mask may depend on all of that seed. -/
223
+ theorem glue_seed_joint_law {Ω : Type*} [MeasurableSpace Ω]
224
+ (μ : Measure Ω) [IsProbabilityMeasure μ]
225
+ (ν : Measure R) [IsProbabilityMeasure ν]
226
+ (S V : Ω → Weights n) (seed : Ω → R)
227
+ (hS : Measurable S) (hV : Measurable V) (hseedM : Measurable seed)
228
+ (hi : iIndepFun (pairedCoordinates S V) μ)
229
+ (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e))
230
+ (hseed : IndepFun (fun ω => (S ω, V ω)) seed μ)
231
+ (hseedLaw : μ.map seed = ν) (mask : R → Finset (Fin n)) (hmask : Measurable mask) :
232
+ MeasurePreserving (fun ω => (seed ω, glue (mask (seed ω)) (S ω) (V ω)))
233
+ μ (ν.prod (μ.map V)) := by
234
+ have hfiber (r : R) :
235
+ (μ.map (fun ω => (S ω, V ω))).map (fun d => glue (mask r) d.1 d.2) = μ.map V := by
236
+ rw [Measure.map_map (measurable_glue (mask r)) (hS.prodMk hV)]
237
+ exact glue_fixed_law μ S V hS hV hi hlaw (mask r)
238
+ have hstart : MeasurePreserving (fun ω => (seed ω, (S ω, V ω))) μ
239
+ (ν.prod (μ.map (fun ω => (S ω, V ω)))) := by
240
+ refine ⟨hseedM.prodMk (hS.prodMk hV), ?_⟩
241
+ rw [hseed.symm.map_prod_eq_prod_map_map hseedM.aemeasurable
242
+ (hS.prodMk hV).aemeasurable, hseedLaw]
243
+ have hend := (MeasurePreserving.id ν).skew_product
244
+ (g := fun (r : R) (d : Weights n × Weights n) => glue (mask r) d.1 d.2)
245
+ (measurable_glue_seed mask hmask) (ae_of_all _ hfiber)
246
+ exact hend.comp hstart
247
+
248
+ /-- Nonnegativity of a finite vector is a Borel condition. -/
249
+ lemma measurableSet_nonnegative (n : ℕ) :
250
+ MeasurableSet {w : Weights n | ∀ e, 0 ≤ w e} := by
251
+ simp only [Set.ofPred_forall]
252
+ exact MeasurableSet.iInter fun e => measurableSet_le measurable_const (measurable_pi_apply e)
253
+
254
+ lemma integrable_hidden_product {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n)) (A : HiddenRule n Ξ)
255
+ (ν : Measure (Ξ)) [IsProbabilityMeasure ν] (ρ : Measure (Weights n)) [SFinite ρ]
256
+ (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
257
+ ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ),
258
+ M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n)))
259
+ (hNN : ∀ᵐ w ∂ρ, ∀ e, 0 ≤ w e) (hopt : Integrable (optimum M) ρ) :
260
+ Integrable (fun x : Ξ × Weights n => hiddenWorstReward A x.2 x.1)
261
+ (ν.prod ρ) := by
262
+ apply (hopt.comp_snd ν).mono' (measurable_hiddenWorstReward A).aestronglyMeasurable
263
+ filter_upwards [(Measure.quasiMeasurePreserving_snd (μ := ν) (ν := ρ)).ae hNN] with x hx
264
+ rw [Real.norm_eq_abs, abs_of_nonneg (hiddenWorstReward_nonneg A x.2 hx x.1)]
265
+ exact hiddenWorstReward_le_optimum M A hA x.2 hx x.1
266
+
267
+ lemma hidden_product_integral_bound {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n))
268
+ (A : HiddenRule n Ξ) (ν : Measure (Ξ)) [IsProbabilityMeasure ν]
269
+ (ρ : Measure (Weights n)) [IsProbabilityMeasure ρ] (c : ℝ)
270
+ (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
271
+ ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ),
272
+ M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n)))
273
+ (hNN : ∀ᵐ w ∂ρ, ∀ e, 0 ≤ w e) (hopt : Integrable (optimum M) ρ)
274
+ (hbound : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
275
+ c * optimum M w ≤ ∫ r, hiddenWorstReward A w r ∂ν) :
276
+ c * (∫ w, optimum M w ∂ρ) ≤
277
+ ∫ x : Ξ × Weights n, hiddenWorstReward A x.2 x.1 ∂ν.prod ρ := by
278
+ have hip := integrable_hidden_product M A ν ρ hA hNN hopt
279
+ rw [← integral_const_mul]
280
+ calc
281
+ _ ≤ ∫ w, ∫ r, hiddenWorstReward A w r ∂ν ∂ρ := by
282
+ apply integral_mono_ae (hopt.const_mul c) hip.integral_prod_right
283
+ filter_upwards [hNN] with w hw
284
+ exact hbound w hw
285
+ _ = _ := (integral_prod_symm _ hip).symm
286
+
287
+ lemma integrable_feasible_reward {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n))
288
+ (A : OnlineRule n Ξ) (hA : Feasible M A)
289
+ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)
290
+ (S V : Ω → Weights n) (R : Ω → Ξ) (π : Ω → ArrivalOrder n)
291
+ (hS : Measurable S) (hV : Measurable V) (hR : Measurable R) (hπ : Measurable π)
292
+ (hSN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e)
293
+ (hopt : Integrable (fun ω => optimum M (V ω)) μ) :
294
+ Integrable (fun ω => reward A (R ω) (S ω) (V ω) (π ω)) μ := by
295
+ have hrm := (measurable_reward A).comp (hπ.prodMk (hR.prodMk (hS.prodMk hV)))
296
+ apply hopt.mono' hrm.aestronglyMeasurable
297
+ filter_upwards [hSN, hVN] with ω hs hv
298
+ change ‖reward A (R ω) (S ω) (V ω) (π ω)‖ ≤ optimum M (V ω)
299
+ rw [Real.norm_eq_abs, abs_of_nonneg (reward_nonneg A (R ω) (S ω) (V ω) (π ω) hv)]
300
+ exact reward_le_optimum M A hA (R ω) (S ω) (V ω) (π ω) hs hv
301
+
302
+ /-- The full one-sample integration step preserves the expected minimum over all orders. -/
303
+ theorem oneSample_of_hidden {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n)) (A : HiddenRule n Ξ)
304
+ (ν : Measure (Ξ)) [IsProbabilityMeasure ν] (c : ℝ)
305
+ (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
306
+ ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ),
307
+ M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n)))
308
+ (hbound : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
309
+ c * optimum M w ≤ ∫ r, hiddenWorstReward A w r ∂ν)
310
+ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]
311
+ (S V : Ω → Weights n) (R : Ω → Ξ)
312
+ (hS : Measurable S) (hV : Measurable V) (hR : Measurable R)
313
+ (hSN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e)
314
+ (hi : iIndepFun (pairedCoordinates S V) μ)
315
+ (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e))
316
+ (hseed : IndepFun (fun ω => (S ω, V ω)) R μ)
317
+ (hRlaw : μ.map R = ν)
318
+ (hopt : Integrable (fun ω => optimum M (V ω)) μ)
319
+ (π : Ω → ArrivalOrder n) (hπ : Measurable π) :
320
+ Integrable (fun ω => reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω)) μ ∧
321
+ c * (∫ ω, optimum M (V ω) ∂μ) ≤
322
+ ∫ ω, reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω) ∂μ := by
323
+ have hj := glue_seed_joint_law μ ν S V R hS hV hR hi hlaw hseed hRlaw A.mask A.measurable_mask
324
+ have hoptLaw : Integrable (optimum M) (μ.map V) :=
325
+ (integrable_map_measure (measurable_optimum M).aestronglyMeasurable hV.aemeasurable).2 hopt
326
+ have hNNLaw : ∀ᵐ w ∂μ.map V, ∀ e, 0 ≤ w e :=
327
+ (ae_map_iff hV.aemeasurable (measurableSet_nonnegative n)).2 hVN
328
+ have hip := integrable_hidden_product M A ν (μ.map V) hA hNNLaw hoptLaw
329
+ have him := hj.integrable_comp_of_integrable hip
330
+ have hri := integrable_feasible_reward M (sampleSimulation A)
331
+ (sampleSimulation_feasible M A hA) μ S V R π hS hV hR hπ hSN hVN hopt
332
+ have hb := hidden_product_integral_bound M A ν (μ.map V) c hA hNNLaw hoptLaw hbound
333
+ have hoptEq := integral_map_of_stronglyMeasurable (μ := μ) hV
334
+ (measurable_optimum M).stronglyMeasurable
335
+ have hminEq := integral_map_of_stronglyMeasurable (μ := μ) hj.measurable
336
+ (measurable_hiddenWorstReward A).stronglyMeasurable
337
+ rw [hj.map_eq] at hminEq
338
+ rw [hoptEq, hminEq] at hb
339
+ refine ⟨hri, hb.trans (integral_mono_ae him hri (ae_of_all _ ?_))⟩
340
+ intro ω
341
+ change hiddenWorstReward A (glue (A.mask (R ω)) (S ω) (V ω)) (R ω) ≤
342
+ reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω)
343
+ rw [sampleSimulation_reward]
344
+ exact hiddenWorstReward_le A _ (R ω) (π ω)
345
+
346
+ /-- The manuscript's simulation lemma without any finite-seed restriction. -/
347
+ theorem simulation_contract.{u, v} : SimulationContract.{u, v} := by
348
+ intro n R mR M A ν hν c hA hbound
349
+ let := hν
350
+ refine ⟨sampleSimulation A, ?_, sampleSimulation_feasible M A hA,
351
+ sampleSimulation_acceptedThrough A, sampleSimulation_reward A, ?_⟩
352
+ · intro k r s h
353
+ rfl
354
+ · intro Ω mΩ μ hμ S V seed hS hV hseedM hSN hVN hi hlaw hseed hseedLaw hopt π hπ
355
+ exact ⟨glue_seed_joint_law μ ν S V seed hS hV hseedM hi hlaw hseed hseedLaw
356
+ A.mask A.measurable_mask,
357
+ oneSample_of_hidden M A ν c hA hbound μ S V seed hS hV hseedM hSN hVN
358
+ hi hlaw hseed hseedLaw hopt π hπ⟩
359
+
360
+ /-- The concrete finite-seed information model is a special case, with exactly
361
+ the same decisions rather than an unrelated replacement rule. -/
362
+ def OnlineRule.ofFinite {bits : ℕ} (A : MatroidProphet.OnlineRule n bits) :
363
+ OnlineRule n (Seed bits) where
364
+ decide := A.decide
365
+ measurable_decide := A.measurable_decide
366
+
367
+ def HiddenRule.ofFinite {bits : ℕ} (A : MatroidProphet.HiddenRule n bits) :
368
+ HiddenRule n (Seed bits) where
369
+ mask := A.mask
370
+ measurable_mask := measurable_of_countable A.mask
371
+ core := OnlineRule.ofFinite A.core
372
+
373
+ @[simp] lemma acceptedThrough_ofFinite {bits : ℕ}
374
+ (A : MatroidProphet.OnlineRule n bits) (r : Seed bits) (s v : Weights n)
375
+ (π : ArrivalOrder n) (t : ℕ) :
376
+ acceptedThrough (OnlineRule.ofFinite A) r s v π t =
377
+ MatroidProphet.acceptedThrough A r s v π t := rfl
378
+
379
+ @[simp] lemma hiddenAcceptedThrough_ofFinite {bits : ℕ}
380
+ (A : MatroidProphet.HiddenRule n bits) (r : Seed bits) (w : Weights n)
381
+ (π : ArrivalOrder n) (t : ℕ) :
382
+ hiddenAcceptedThrough (HiddenRule.ofFinite A) r w π t =
383
+ MatroidProphet.hiddenAcceptedThrough A r w π t := rfl
384
+
385
+ @[simp] lemma hiddenWorstReward_ofFinite {bits : ℕ}
386
+ (A : MatroidProphet.HiddenRule n bits) (w : Weights n) (r : Seed bits) :
387
+ hiddenWorstReward (HiddenRule.ofFinite A) w r = MatroidProphet.hiddenWorstReward A w r := rfl
388
+
389
+ end MatroidProphet.General
390
+
391
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulationModel.lean ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import Mathlib.Probability.Independence.Basic
3
+ import Mathlib.MeasureTheory.Integral.Bochner.Basic
4
+
5
+ namespace OAI
6
+
7
+ namespace MatroidProphet.General
8
+
9
+ open MeasureTheory ProbabilityTheory
10
+
11
+ /-- A decision uses only the entire initial seed, the initially observed vector,
12
+ and the label/value history through the current arrival. -/
13
+ structure OnlineRule (n : ℕ) (R : Type*) [MeasurableSpace R] where
14
+ decide : (k : Fin n) → R → Weights n → History n k → Bool
15
+ measurable_decide : ∀ k, Measurable
16
+ (fun x : R × (Weights n × History n k) => decide k x.1 x.2.1 x.2.2)
17
+
18
+ def decisionAt {n : ℕ} {R : Type*} [MeasurableSpace R]
19
+ (A : OnlineRule n R) (r : R) (s v : Weights n)
20
+ (π : ArrivalOrder n) (k : Fin n) : Bool :=
21
+ A.decide k r s (history v π k)
22
+
23
+ noncomputable def acceptedThrough {n : ℕ} {R : Type*} [MeasurableSpace R]
24
+ (A : OnlineRule n R) (r : R) (s v : Weights n)
25
+ (π : ArrivalOrder n) (t : ℕ) : Finset (Fin n) := by
26
+ classical
27
+ exact Finset.univ.filter fun e =>
28
+ (π.symm e).val < t ∧ decisionAt A r s v π (π.symm e) = true
29
+
30
+ noncomputable def reward {n : ℕ} {R : Type*} [MeasurableSpace R]
31
+ (A : OnlineRule n R) (r : R) (s v : Weights n) (π : ArrivalOrder n) : ℝ :=
32
+ ∑ e ∈ acceptedThrough A r s v π n, v e
33
+
34
+ def Feasible {n : ℕ} {R : Type*} [MeasurableSpace R]
35
+ (M : Matroid (Fin n)) (A : OnlineRule n R) : Prop :=
36
+ ∀ (r : R) (s v : Weights n) (π : ArrivalOrder n) (t : ℕ),
37
+ (∀ e, 0 ≤ s e) → (∀ e, 0 ≤ v e) →
38
+ M.Indep (acceptedThrough A r s v π t : Set (Fin n))
39
+
40
+ /-- The observation mask is a measurable function of the seed alone. -/
41
+ structure HiddenRule (n : ℕ) (R : Type*) [MeasurableSpace R] where
42
+ mask : R → Finset (Fin n)
43
+ measurable_mask : Measurable mask
44
+ core : OnlineRule n R
45
+
46
+ noncomputable def observed {n : ℕ} {R : Type*} [MeasurableSpace R]
47
+ (A : HiddenRule n R) (r : R) (w : Weights n) : Weights n := by
48
+ classical
49
+ exact fun e => if e ∈ A.mask r then w e else 0
50
+
51
+ noncomputable def hiddenAcceptedThrough {n : ℕ} {R : Type*} [MeasurableSpace R]
52
+ (A : HiddenRule n R) (r : R) (w : Weights n)
53
+ (π : ArrivalOrder n) (t : ℕ) : Finset (Fin n) :=
54
+ acceptedThrough A.core r (observed A r w) w π t \ A.mask r
55
+
56
+ noncomputable def hiddenReward {n : ℕ} {R : Type*} [MeasurableSpace R]
57
+ (A : HiddenRule n R) (r : R) (w : Weights n) (π : ArrivalOrder n) : ℝ :=
58
+ ∑ e ∈ hiddenAcceptedThrough A r w π n, w e
59
+
60
+ noncomputable def hiddenWorstReward {n : ℕ} {R : Type*} [MeasurableSpace R]
61
+ (A : HiddenRule n R) (w : Weights n) (r : R) : ℝ := by
62
+ classical
63
+ exact Finset.univ.inf' Finset.univ_nonempty (hiddenReward A r w)
64
+
65
+ def HiddenFeasible {n : ℕ} {R : Type*} [MeasurableSpace R]
66
+ (M : Matroid (Fin n)) (A : HiddenRule n R) : Prop :=
67
+ ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
68
+ ∀ (r : R) (π : ArrivalOrder n) (t : ℕ),
69
+ M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n))
70
+
71
+ /-- Sample values on the sacrificed mask, and realized values elsewhere. -/
72
+ noncomputable def glue {n : ℕ} (mask : Finset (Fin n)) (s v : Weights n) : Weights n := by
73
+ classical
74
+ exact fun e => if e ∈ mask then s e else v e
75
+
76
+ noncomputable def simulationHistory {n : ℕ} {R : Type*} [MeasurableSpace R]
77
+ (A : HiddenRule n R) (r : R) (s : Weights n)
78
+ {k : Fin n} (h : History n k) : History n k := by
79
+ classical
80
+ exact fun j => ((h j).1, if (h j).1 ∈ A.mask r then s (h j).1 else (h j).2)
81
+
82
+
83
+
84
+ noncomputable def simulationDecision {n : ℕ} {R : Type*} [MeasurableSpace R]
85
+ (A : HiddenRule n R) (k : Fin n) (r : R) (s : Weights n)
86
+ (h : History n k) : Bool := by
87
+ classical
88
+ exact if (h ⟨k.val, Nat.lt_succ_self _⟩).1 ∈ A.mask r then false
89
+ else A.core.decide k r (observed A r s) (simulationHistory A r s h)
90
+
91
+ /-- Full source contract for `lem:simulation`, with arbitrary measurable seed
92
+ and probability spaces. The simulator is constructed before the distributions
93
+ and adversary are supplied. Its decision function is specified concretely;
94
+ the conjunction includes exact execution, feasibility, the seed/glued-vector
95
+ joint law, integrability, and preservation of the same competitive ratio. -/
96
+ def SimulationContract.{u, v} : Prop :=
97
+ ∀ (n : ℕ) (R : Type v) [MeasurableSpace R]
98
+ (M : Matroid (Fin n)) (A : HiddenRule n R)
99
+ (ν : Measure R), IsProbabilityMeasure ν →
100
+ ∀ (c : ℝ), HiddenFeasible M A →
101
+ (∀ (w : Weights n), (∀ e, 0 ≤ w e) →
102
+ c * optimum M w ≤ ∫ r, hiddenWorstReward A w r ∂ν) →
103
+ ∃ B : OnlineRule n R,
104
+ (∀ (k : Fin n) (r : R) (s : Weights n) (h : History n k),
105
+ B.decide k r s h = simulationDecision A k r s h) ∧
106
+ Feasible M B ∧
107
+ (∀ (r : R) (s v : Weights n) (π : ArrivalOrder n) (t : ℕ),
108
+ acceptedThrough B r s v π t =
109
+ hiddenAcceptedThrough A r (glue (A.mask r) s v) π t) ∧
110
+ (∀ (r : R) (s v : Weights n) (π : ArrivalOrder n),
111
+ reward B r s v π = hiddenReward A r (glue (A.mask r) s v) π) ∧
112
+ ∀ {Ω : Type u} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]
113
+ (S V : Ω → Weights n) (seed : Ω → R),
114
+ Measurable S → Measurable V → Measurable seed →
115
+ (∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) →
116
+ (∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) →
117
+ iIndepFun (pairedCoordinates S V) μ →
118
+ (∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e)) →
119
+ IndepFun (fun ω => (S ω, V ω)) seed μ → μ.map seed = ν →
120
+ Integrable (fun ω => optimum M (V ω)) μ →
121
+ ∀ (π : Ω → ArrivalOrder n), Measurable π →
122
+ MeasurePreserving (fun ω => (seed ω, glue (A.mask (seed ω)) (S ω) (V ω)))
123
+ μ (ν.prod (μ.map V)) ∧
124
+ Integrable (fun ω => reward B (seed ω) (S ω) (V ω) (π ω)) μ ∧
125
+ c * (∫ ω, optimum M (V ω) ∂μ) ≤
126
+ ∫ ω, reward B (seed ω) (S ω) (V ω) (π ω) ∂μ
127
+
128
+ end MatroidProphet.General
129
+
130
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/InformationRestriction.lean ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ /-!
6
+ # Explicit information restrictions for hidden-vector rules
7
+
8
+ These lemmas formalize the no-future-information and irrevocability clauses of
9
+ `sections/algorithm.tex`, Lemma `lem:feasibility`. They use only the concrete
10
+ history and acceptance definitions; no correctness hypothesis for an algorithm
11
+ is introduced.
12
+ -/
13
+
14
+ namespace MatroidProphet
15
+
16
+ open Finset
17
+
18
+ lemma observed_eq_of_eq_on_mask {n bits : ℕ} (A : HiddenRule n bits)
19
+ (r : Seed bits) (w w' : Weights n)
20
+ (h : ∀ e ∈ A.mask r, w e = w' e) :
21
+ observed A r w = observed A r w' := by
22
+ classical
23
+ funext e
24
+ by_cases he : e ∈ A.mask r
25
+ · simp only [observed, ite_eq_left he, h e he]
26
+ · simp only [observed, ite_eq_right he]
27
+
28
+ lemma history_eq_of_agree_before {n : ℕ} (v v' : Weights n)
29
+ (π π' : ArrivalOrder n) (t : ℕ)
30
+ (h : ∀ j : Fin n, j.val < t → (π j, v (π j)) = (π' j, v' (π' j)))
31
+ (k : Fin n) (hk : k.val < t) :
32
+ history v π k = history v' π' k := by
33
+ funext j
34
+ exact h (prefixIndex k j) (by dsimp [prefixIndex]; omega)
35
+
36
+ /-- Equal available label/value pairs give the same accepted set through a prefix.
37
+ The two complete arrival orders and all later values may be different. -/
38
+ theorem acceptedThrough_eq_of_agree_before {n bits : ℕ} (A : OnlineRule n bits)
39
+ (r : Seed bits) (s v v' : Weights n) (π π' : ArrivalOrder n) (t : ℕ)
40
+ (h : ∀ j : Fin n, j.val < t → (π j, v (π j)) = (π' j, v' (π' j))) :
41
+ acceptedThrough A r s v π t = acceptedThrough A r s v' π' t := by
42
+ classical
43
+ have subset (v₁ v₂ : Weights n) (ρ₁ ρ₂ : ArrivalOrder n)
44
+ (hρ : ∀ j : Fin n, j.val < t →
45
+ (ρ₁ j, v₁ (ρ₁ j)) = (ρ₂ j, v₂ (ρ₂ j))) :
46
+ acceptedThrough A r s v₁ ρ₁ t ⊆ acceptedThrough A r s v₂ ρ₂ t := by
47
+ intro e he
48
+ have hmem := (Finset.mem_filter.mp he).2
49
+ have hl := congrArg Prod.fst (hρ (ρ₁.symm e) hmem.1)
50
+ have hidx : ρ₂.symm e = ρ₁.symm e := by
51
+ apply ρ₂.injective
52
+ simpa only [Equiv.apply_symm_apply] using hl
53
+ apply Finset.mem_filter.mpr
54
+ refine ⟨Finset.mem_univ e, ?_, ?_⟩
55
+ · simpa only [hidx] using hmem.1
56
+ · rw [hidx]
57
+ rw [← decisionAt_congr A r s v₁ v₂ ρ₁ ρ₂ (ρ₁.symm e)
58
+ (history_eq_of_agree_before v₁ v₂ ρ₁ ρ₂ t hρ _ hmem.1)]
59
+ exact hmem.2
60
+ exact Finset.Subset.antisymm (subset v v' π π' h)
61
+ (subset v' v π' π (fun j hj => (h j hj).symm))
62
+
63
+ /-- A hidden-vector execution depends only on its revealed coordinates and the
64
+ actual arrival history, never on the unobserved future values or future order. -/
65
+ theorem hiddenAcceptedThrough_eq_of_same_information {n bits : ℕ}
66
+ (A : HiddenRule n bits) (r : Seed bits) (w w' : Weights n)
67
+ (π π' : ArrivalOrder n) (t : ℕ)
68
+ (hmask : ∀ e ∈ A.mask r, w e = w' e)
69
+ (hhist : ∀ j : Fin n, j.val < t →
70
+ (π j, w (π j)) = (π' j, w' (π' j))) :
71
+ hiddenAcceptedThrough A r w π t = hiddenAcceptedThrough A r w' π' t := by
72
+ unfold hiddenAcceptedThrough
73
+ rw [observed_eq_of_eq_on_mask A r w w' hmask]
74
+ rw [acceptedThrough_eq_of_agree_before A.core r (observed A r w') w w' π π' t hhist]
75
+
76
+ /-- Hidden-vector acceptances cannot be revoked. -/
77
+ theorem hiddenAcceptedThrough_monotone {n bits : ℕ} (A : HiddenRule n bits)
78
+ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) :
79
+ Monotone (hiddenAcceptedThrough A r w π) := by
80
+ intro t t' htt' e he
81
+ have hm := Finset.mem_sdiff.mp he
82
+ exact Finset.mem_sdiff.mpr
83
+ ⟨acceptedThrough_mono A.core r (observed A r w) w π htt' hm.1, hm.2⟩
84
+
85
+ /-- Sacrifice is literal rejection, not merely exclusion from the reward sum. -/
86
+ theorem hiddenAcceptedThrough_disjoint_mask {n bits : ℕ} (A : HiddenRule n bits)
87
+ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) (t : ℕ) :
88
+ Disjoint (hiddenAcceptedThrough A r w π t) (A.mask r) := by
89
+ exact Finset.sdiff_disjoint
90
+
91
+ /-- Every accepted hidden-vector label has actually arrived. -/
92
+ theorem hiddenAcceptedThrough_arrived {n bits : ℕ} (A : HiddenRule n bits)
93
+ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) (t : ℕ)
94
+ (e : Fin n) (he : e ∈ hiddenAcceptedThrough A r w π t) :
95
+ (π.symm e).val < t :=
96
+ acceptedThrough_arrived A.core r (observed A r w) w π t e
97
+ (Finset.mem_sdiff.mp he).1
98
+
99
+ /-- The observation operation is jointly measurable in the complete initial seed
100
+ and the hidden vector, despite an arbitrary seed-dependent mask. -/
101
+ lemma measurable_observed_seed {n bits : ℕ} (A : HiddenRule n bits) :
102
+ Measurable (fun x : Seed bits × Weights n => observed A x.1 x.2) := by
103
+ classical
104
+ apply measurable_from_prod_countable_right
105
+ intro r
106
+ apply Measurable.of_eval
107
+ intro e
108
+ by_cases he : e ∈ A.mask r
109
+ · simpa only [observed, ite_eq_left he] using
110
+ (measurable_pi_apply e : Measurable (fun w : Weights n => w e))
111
+ · simpa only [observed, ite_eq_right he] using
112
+ (measurable_const : Measurable (fun _ : Weights n => (0 : ℝ)))
113
+
114
+ /-- With observations substituted, the actual core decision remains measurable. -/
115
+ lemma measurable_hidden_core_decide {n bits : ℕ} (A : HiddenRule n bits)
116
+ (k : Fin n) :
117
+ Measurable (fun x : Seed bits × (Weights n × History n k) =>
118
+ A.core.decide k x.1 (observed A x.1 x.2.1) x.2.2) := by
119
+ apply measurable_from_prod_countable_right
120
+ intro r
121
+ exact (A.core.measurable_decide k).comp
122
+ (measurable_const.prodMk
123
+ (((measurable_observed_seed A).comp
124
+ (measurable_const.prodMk measurable_fst)).prodMk measurable_snd))
125
+
126
+ end MatroidProphet
127
+
128
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/SimulationInformation.lean ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ /-!
6
+ # Information restrictions of the one-sample simulation
7
+
8
+ These pointwise statements make explicit the information restrictions used in
9
+ `sections/setup.tex`, Lemma `lem:simulation`: unused samples and online values
10
+ of sacrificed labels cannot affect the execution. The final two replay
11
+ identities also support the prefix/suffix construction in `sections/secretary.tex`.
12
+ No independence, positivity, or feasibility assumptions are needed for these
13
+ deterministic identities.
14
+ -/
15
+
16
+ namespace MatroidProphet
17
+
18
+ lemma simulationObserved_eq_of_eq_on_mask {n bits : ℕ} (A : HiddenRule n bits)
19
+ (r : Seed bits) (s s' : Weights n)
20
+ (hs : ∀ e ∈ A.mask r, s e = s' e) :
21
+ observed A r s = observed A r s' := by
22
+ classical
23
+ funext e
24
+ by_cases he : e ∈ A.mask r
25
+ · simp [observed, he, hs e he]
26
+ · simp [observed, he]
27
+
28
+ lemma simulationHistory_eq_of_eq_on_mask {n bits : ℕ} (A : HiddenRule n bits)
29
+ (r : Seed bits) (s s' : Weights n) {k : Fin n} (h : History n k)
30
+ (hs : ∀ e ∈ A.mask r, s e = s' e) :
31
+ simulationHistory A r s h = simulationHistory A r s' h := by
32
+ classical
33
+ funext j
34
+ by_cases he : (h j).1 ∈ A.mask r
35
+ · simp [simulationHistory, he, hs _ he]
36
+ · simp [simulationHistory, he]
37
+
38
+ /-- The simulator's current decision ignores every sample outside its mask. -/
39
+ theorem sampleSimulation_decide_eq_of_eq_on_mask {n bits : ℕ}
40
+ (A : HiddenRule n bits) (r : Seed bits) (s s' : Weights n)
41
+ (k : Fin n) (h : History n k)
42
+ (hs : ∀ e ∈ A.mask r, s e = s' e) :
43
+ (sampleSimulation A).decide k r s h =
44
+ (sampleSimulation A).decide k r s' h := by
45
+ classical
46
+ simp only [sampleSimulation]
47
+ rw [simulationObserved_eq_of_eq_on_mask A r s s' hs,
48
+ simulationHistory_eq_of_eq_on_mask A r s s' h hs]
49
+
50
+ lemma glue_eq_of_eq_on_regions {n : ℕ} (mask : Finset (Fin n))
51
+ (s s' v v' : Weights n)
52
+ (hs : ∀ e ∈ mask, s e = s' e)
53
+ (hv : ∀ e ∉ mask, v e = v' e) :
54
+ glue mask s v = glue mask s' v' := by
55
+ classical
56
+ funext e
57
+ by_cases he : e ∈ mask
58
+ · simp [glue, he, hs e he]
59
+ · simp [glue, he, hv e he]
60
+
61
+ /-- Neither unused samples nor sacrificed online values change any accepted prefix. -/
62
+ theorem sampleSimulation_acceptedThrough_noninterference {n bits : ℕ}
63
+ (A : HiddenRule n bits) (r : Seed bits) (s s' v v' : Weights n)
64
+ (π : ArrivalOrder n) (t : ℕ)
65
+ (hs : ∀ e ∈ A.mask r, s e = s' e)
66
+ (hv : ∀ e ∉ A.mask r, v e = v' e) :
67
+ acceptedThrough (sampleSimulation A) r s v π t =
68
+ acceptedThrough (sampleSimulation A) r s' v' π t := by
69
+ rw [sampleSimulation_acceptedThrough, sampleSimulation_acceptedThrough,
70
+ glue_eq_of_eq_on_regions (A.mask r) s s' v v' hs hv]
71
+
72
+ /-- The same information invariance holds for the reward in actual online values. -/
73
+ theorem sampleSimulation_reward_noninterference {n bits : ℕ}
74
+ (A : HiddenRule n bits) (r : Seed bits) (s s' v v' : Weights n)
75
+ (π : ArrivalOrder n)
76
+ (hs : ∀ e ∈ A.mask r, s e = s' e)
77
+ (hv : ∀ e ∉ A.mask r, v e = v' e) :
78
+ reward (sampleSimulation A) r s v π =
79
+ reward (sampleSimulation A) r s' v' π := by
80
+ rw [sampleSimulation_reward, sampleSimulation_reward,
81
+ glue_eq_of_eq_on_regions (A.mask r) s s' v v' hs hv]
82
+
83
+ /-- A sacrificed label is rejected at every prefix, irrespective of its value. -/
84
+ theorem sampleSimulation_rejects_mask {n bits : ℕ} (A : HiddenRule n bits)
85
+ (r : Seed bits) (s v : Weights n) (π : ArrivalOrder n) (t : ℕ)
86
+ (e : Fin n) (he : e ∈ A.mask r) :
87
+ e ∉ acceptedThrough (sampleSimulation A) r s v π t := by
88
+ rw [sampleSimulation_acceptedThrough]
89
+ exact fun h => (Finset.mem_sdiff.mp h).2 he
90
+
91
+ lemma glue_observed_left {n bits : ℕ} (A : HiddenRule n bits)
92
+ (r : Seed bits) (w : Weights n) :
93
+ glue (A.mask r) (observed A r w) w = w := by
94
+ classical
95
+ funext e
96
+ by_cases he : e ∈ A.mask r <;> simp [glue, observed, he]
97
+
98
+ /-- Replaying the full arrived history after supplying only the observed mask
99
+ agrees exactly with the hidden rule, at every prefix including zero. -/
100
+ theorem sampleSimulation_replay_acceptedThrough {n bits : ℕ}
101
+ (A : HiddenRule n bits) (r : Seed bits) (w : Weights n)
102
+ (π : ArrivalOrder n) (t : ℕ) :
103
+ acceptedThrough (sampleSimulation A) r (observed A r w) w π t =
104
+ hiddenAcceptedThrough A r w π t := by
105
+ rw [sampleSimulation_acceptedThrough, glue_observed_left]
106
+
107
+ /-- The replay identity preserves the actual reward without a numerical loss. -/
108
+ theorem sampleSimulation_replay_reward {n bits : ℕ}
109
+ (A : HiddenRule n bits) (r : Seed bits) (w : Weights n)
110
+ (π : ArrivalOrder n) :
111
+ reward (sampleSimulation A) r (observed A r w) w π = hiddenReward A r w π := by
112
+ rw [sampleSimulation_reward, glue_observed_left]
113
+
114
+ end MatroidProphet
115
+
116
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/StrongOneSample.lean ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ /-!
6
+ # The stronger constant for the concrete one-sample rule
7
+
8
+ The introduction explicitly records the stronger `2⁻²⁹³` constant proved in
9
+ accounting.tex. The root endpoint uses its announced `2⁻³¹⁰` constant. This
10
+ supporting theorem exposes the stronger claim for the actual constructed rule,
11
+ without changing the endpoint or imposing moments on individual loop values.
12
+
13
+ The rule and initial seed law below depend only on the known labeled matroid.
14
+ The probability space, matching input laws, and full-seed-aware adversary are
15
+ supplied afterwards. Feasibility is pointwise at every prefix and the reward
16
+ estimate uses only integrability of the actual offline optimum.
17
+ -/
18
+
19
+ namespace MatroidProphet
20
+
21
+ open MeasureTheory ProbabilityTheory
22
+
23
+ /-- The actual simulated source rule is feasible before any laws are chosen. -/
24
+ theorem source_one_sample_feasible {n : ℕ} (M : Matroid (Fin n))
25
+ (hE : M.E = Set.univ) :
26
+ Feasible M (sampleSimulation (completeHiddenRule M hE)) :=
27
+ sampleSimulation_feasible M (completeHiddenRule M hE)
28
+ (completeHiddenRule_feasible M hE)
29
+
30
+ /-- The source construction attains the stronger constant advertised after
31
+ `thm:main`, even when the order sees the complete initial seed. This is a
32
+ consequence for the concrete rule, not a premise asserting its performance. -/
33
+ theorem source_one_sample_strong {n : ℕ} (M : Matroid (Fin n))
34
+ (hE : M.E = Set.univ)
35
+ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]
36
+ (S V : Ω → Weights n) (R : Ω → Seed (mainSeedBits n))
37
+ (hS : Measurable S) (hV : Measurable V) (hR : Measurable R)
38
+ (hSN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e)
39
+ (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e)
40
+ (hi : iIndepFun (pairedCoordinates S V) μ)
41
+ (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e))
42
+ (hseed : IndepFun (fun ω => (S ω, V ω)) R μ)
43
+ (hRlaw : μ.map R = sourceSeedLaw n)
44
+ (hopt : Integrable (fun ω => optimum M (V ω)) μ)
45
+ (π : Ω → ArrivalOrder n) (hπ : Measurable π) :
46
+ Integrable (fun ω =>
47
+ reward (sampleSimulation (completeHiddenRule M hE))
48
+ (R ω) (S ω) (V ω) (π ω)) μ ∧
49
+ ((2 : ℝ) ^ 293)⁻¹ * (∫ ω, optimum M (V ω) ∂μ) ≤
50
+ ∫ ω, reward (sampleSimulation (completeHiddenRule M hE))
51
+ (R ω) (S ω) (V ω) (π ω) ∂μ :=
52
+ oneSample_of_hidden M (completeHiddenRule M hE) (sourceSeedLaw n)
53
+ (((2 : ℝ) ^ 293)⁻¹) (completeHiddenRule_feasible M hE)
54
+ (complete_hidden_guarantee M hE) μ S V R hS hV hR hSN hVN
55
+ hi hlaw hseed hRlaw hopt π hπ
56
+
57
+ end MatroidProphet
58
+
59
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/TransferContract.lean ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import OAI.Probability.MatroidSecretary.Transport.TransferSpecification
3
+
4
+ namespace OAI
5
+
6
+ /-!
7
+ # Source-facing sample-to-rank transfer
8
+
9
+ Source: `sections/transfer.tex`, `lem:transfer` / `eq:rank-transfer`.
10
+ The comparison set is the actual priority-greedy survivor group; its independence
11
+ and containment are proved, not supplied as extra assumptions. `mainMean` fixes
12
+ only H and averages the density, guard, test, and parity coins. `trueZ` uses zero
13
+ on unlisted outcomes, so the expectation is not conditioned on listing.
14
+ -/
15
+
16
+ namespace MatroidProphet.SourceProof
17
+
18
+ open Finset MainAlgorithm
19
+
20
+ /-- Conditional averaging depends on the fixed filter mask only. All other
21
+ fields of the initial record are overwritten by independent product samples. -/
22
+ lemma mainMean_filter_congr {n : ℕ} (d d' : MainMasks n)
23
+ (hH : d.H = d'.H) (f : MainMasks n → ℝ) : mainMean d f = mainMean d' f := by
24
+ rcases d with ⟨H, D, C, T, p⟩
25
+ rcases d' with ⟨H', D', C', T', p'⟩
26
+ change H = H' at hH
27
+ subst H'
28
+ rfl
29
+
30
+ /-- The unlisted branch is included in the product average with zero statistic. -/
31
+ lemma trueZ_unlisted {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ)
32
+ (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
33
+ (hi : i ∉ groups M d s) : trueZ M hE d s i = 0 := by
34
+ classical
35
+ simp only [trueZ, ite_eq_right hi]
36
+
37
+ /-- In particular, a true group missed by the discovery sample contributes zero;
38
+ no positivity or listing assumption is imposed on the individual outcomes. -/
39
+ lemma trueZ_zero_of_no_discovery {n : ℕ} (M : Matroid (Fin n))
40
+ (hE : M.E = Set.univ) (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ)
41
+ (hmiss : d.D ∩ trueGroup M d s i = ∅) : trueZ M hE d s i = 0 := by
42
+ apply trueZ_unlisted
43
+ intro hi
44
+ obtain ⟨e, heD, heU⟩ := (mem_listed_iff M d s i).mp ((mem_groups M d s i).mp hi)
45
+ have he : e ∈ d.D ∩ trueGroup M d s i := mem_inter.mpr ⟨heD, heU⟩
46
+ rw [hmiss] at he
47
+ exact notMem_empty e he
48
+
49
+ /-- The source transfer at arbitrary rounded-level keys. This stronger helper
50
+ also covers the `none` keys representing zero/nonpositive weights. -/
51
+ theorem transfer_keys {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ)
52
+ (s : Fin n → Option ℤ) (H : Finset (Fin n)) (i : ℤ) :
53
+ let d : MainMasks n := ⟨H, ∅, ∅, ∅, false⟩
54
+ let U := trueGroup M d s i
55
+ let Y := (positiveGreedy M s \ H).filter (fun e => s e = some i)
56
+ densityThreshold ≤ (U.card : ℝ) →
57
+ ((((2 : ℝ)^16)⁻¹ * Y.card - ((2 : ℝ)^23)⁻¹ * U.card) / (2 : ℝ)^100) ≤
58
+ mainMean d (fun d' => (trueZ M hE d' s i : ℝ)) := by
59
+ classical
60
+ dsimp only
61
+ intro hn
62
+ let d : MainMasks n := ⟨H, ∅, ∅, ∅, false⟩
63
+ let Y := (positiveGreedy M s \ H).filter (fun e => s e = some i)
64
+ have hY : (Y : Set (Fin n)) ⊆ (trueGroup M d s i : Set (Fin n)) := by
65
+ intro e he
66
+ rw [trueGroup_eq_candidate_filter]
67
+ rcases mem_filter.mp he with ⟨heG, hei⟩
68
+ exact mem_filter.mpr ⟨positiveGreedy_survivors_subset M s H heG, hei⟩
69
+ have hI : M.Indep (Y : Set (Fin n)) :=
70
+ (positiveGreedy_survivors_indep M hE s H).subset
71
+ (fun _ he => (mem_filter.mp he).1)
72
+ have h := mainMean_trueZ_lower M hE d s i (Y : Set (Fin n)) hY hI hn
73
+ simpa only [Set.ncard_coe_finset, retainedFraction, densityThreshold, d, Y] using h
74
+
75
+ /-- `lem:transfer` for the manuscript's actual rounded nonnegative weights,
76
+ with literal constants gamma = 2^-16 and kappa = 2^100. -/
77
+ theorem transfer {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ)
78
+ (w : Weights n) (_hw : ∀ e, 0 ≤ w e) (H : Finset (Fin n)) (i : ℤ) :
79
+ let s : Fin n → Option ℤ := fun e => roundedLevel weightBase (w e)
80
+ let d : MainMasks n := ⟨H, ∅, ∅, ∅, false⟩
81
+ let U := trueGroup M d s i
82
+ let Y := (positiveGreedy M s \ H).filter (fun e => s e = some i)
83
+ densityThreshold ≤ (U.card : ℝ) →
84
+ ((((2 : ℝ)^16)⁻¹ * Y.card - ((2 : ℝ)^23)⁻¹ * U.card) / (2 : ℝ)^100) ≤
85
+ mainMean d (fun d' => (trueZ M hE d' s i : ℝ)) :=
86
+ transfer_keys M hE (fun e => roundedLevel weightBase (w e)) H i
87
+
88
+ /-- Thin proof alias for the independent root-target specification. -/
89
+ theorem transfer_claim : TransferClaim := by
90
+ intro n M hE w hw H i
91
+ exact transfer M hE w hw H i
92
+
93
+ end MatroidProphet.SourceProof
94
+
95
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/TransferContracts.lean ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ namespace MatroidProphet
6
+ namespace TransferContracts
7
+
8
+ open Finset Set Pivots MainAlgorithm
9
+
10
+ section Pivots
11
+
12
+ variable {α : Type*} {r q n : ℕ}
13
+
14
+ /-- An injectively timed sequence determines one recorded pivot-mark vector. -/
15
+ lemma recordsPivots_unique (M : Matroid α) (label : Occurrence r q → α)
16
+ (test : Fin n → α) (time : Occurrence r q → ℕ)
17
+ (htime : Function.Injective time) (oldMark : Fin r → Bool)
18
+ (movableMark : Fin q → Bool) {t u : Finset (Fin n)}
19
+ (ht : RecordsPivots M label test time oldMark movableMark t)
20
+ (hu : RecordsPivots M label test time oldMark movableMark u) : t = u := by
21
+ ext f
22
+ obtain ⟨o, ho, hto⟩ := ht f
23
+ obtain ⟨p, hp, hup⟩ := hu f
24
+ have hop := pivot_unique M label time htime ho hp
25
+ subst p
26
+ exact hto.symm.trans hup
27
+
28
+ variable [Fintype α]
29
+
30
+ /-- Complete marked-pivot contract: arbitrary repeated/redundant old labels,
31
+ all placements/orders/marks of at most `s` movable occurrences, and the exact
32
+ binomial bound. Source old-spanning/nonloop assumptions ensure every permitted
33
+ interleaving actually contributes exactly one vector. No positivity assumption
34
+ on `s`, `q`, `r`, or `n` is imposed. -/
35
+ theorem marked_pivot_contract (M : Matroid α) (b : ℕ → α) (a : Fin q → α)
36
+ (test : Fin n → α) (oldMark : Fin r → Bool) (s : ℕ) (hqs : q ≤ s)
37
+ (hground : ∀ o : Occurrence r q, occurrenceLabel b a o ∈ M.E)
38
+ (holdspan : M.closure (oldPrefix b r) = M.E)
39
+ (htest : ∀ f, test f ∈ M.E ∧ test f ∉ M.closure ∅) :
40
+ (markedPivotPatterns M b a test oldMark).card ≤
41
+ 4 ^ s * ∑ k ∈ Finset.Iic s, n.choose k ∧
42
+ ∀ (time : Occurrence r q → ℕ), OldOrdered time → Function.Injective time →
43
+ ∀ movableMark : Fin q → Bool,
44
+ ∃! t, t ∈ markedPivotPatterns M b a test oldMark ∧
45
+ RecordsPivots M (occurrenceLabel b a) test time oldMark movableMark t := by
46
+ refine ⟨card_markedPivotPatterns_le M b a test oldMark s hqs hground, ?_⟩
47
+ intro time horder htime movableMark
48
+ obtain ⟨t, htmem, ht⟩ := recorded_pattern_exists_of_old_spanning M b a test oldMark
49
+ holdspan htest time horder htime movableMark
50
+ refine ⟨t, ⟨htmem, ht⟩, ?_⟩
51
+ intro u hu
52
+ exact recordsPivots_unique M (occurrenceLabel b a) test time htime oldMark movableMark hu.2 ht
53
+
54
+ end Pivots
55
+
56
+ section Transfer
57
+
58
+ variable {n : ℕ}
59
+
60
+ /-- The independent comparison group is constructed by priority greedy and
61
+ fair-mask deletion, exactly as in the manuscript (`Y_i = (I* \ H) ∩ U_i`). -/
62
+ lemma comparison_group_indep_subset (M : Matroid (Fin n)) (hE : M.E = Set.univ)
63
+ (d : MainMasks n) (a : Fin n → Option ℤ) (i : ℤ) :
64
+ let Y := (positiveGreedy M a \ d.H).filter (fun e => a e = some i)
65
+ M.Indep (Y : Set (Fin n)) ∧ (Y : Set (Fin n)) ⊆ (trueGroup M d a i : Set (Fin n)) := by
66
+ classical
67
+ dsimp only
68
+ constructor
69
+ · exact (positiveGreedy_survivors_indep M hE a d.H).subset (Finset.filter_subset _ _)
70
+ · intro e he
71
+ obtain ⟨heY, hei⟩ := Finset.mem_filter.mp he
72
+ apply (mem_trueGroup M d a i e).mpr
73
+ refine ⟨?_, hei⟩
74
+ exact (Finset.mem_filter.mp (positiveGreedy_survivors_subset M a d.H heY)).2
75
+
76
+ /-- Full sample-to-rank inequality for the actual rounded weight vector.
77
+ `withMasks` averages all density, guard and test bits while fixing `H`;
78
+ `fairParityExpectation` averages parity. `listedRankStatistic` is explicitly
79
+ zero on the unlisted branch. Thus there is no conditioning on listing and no
80
+ independence assumption about the selected residual. -/
81
+ theorem sample_to_rank_contract (M : Matroid (Fin n)) (hE : M.E = Set.univ)
82
+ (w : Weights n) (d : MainMasks n) (i : ℤ)
83
+ (hn : densityThreshold ≤
84
+ ((trueGroup M d (fun e => roundedLevel weightBase (w e)) i).card : ℝ)) :
85
+ let a := fun e => roundedLevel weightBase (w e)
86
+ let Y := (positiveGreedy M a \ d.H).filter (fun e => a e = some i)
87
+ (retainedFraction * (Y.card : ℝ) - ((2 : ℝ) ^ 23)⁻¹ *
88
+ (trueGroup M d a i).card) / densityThreshold ≤
89
+ tripleMaskExpectation (fun _ => (1 : ℝ) / 4)
90
+ (fun _ => thinningRate) (fun _ => thinningRate) Finset.univ
91
+ (fun D C T => fairParityExpectation (fun p =>
92
+ (listedRankStatistic M hE (2 ^ 100) (withMasks d D C T) a i
93
+ (boolParity p) : ℝ))) := by
94
+ classical
95
+ let a := fun e => roundedLevel weightBase (w e)
96
+ let Y := (positiveGreedy M a \ d.H).filter (fun e => a e = some i)
97
+ have hY := comparison_group_indep_subset M hE d a i
98
+ have h := listedRankStatistic_lower M hE d a i (Y : Set (Fin n)) hY.2 hY.1 hn
99
+ simpa only [Set.ncard_coe_finset] using h
100
+
101
+ end Transfer
102
+
103
+ end TransferContracts
104
+ end MatroidProphet
105
+
106
+ end OAI
lean/OAI/Probability/MatroidSecretary/Transport/TransferSpecification.lean ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+
3
+ namespace OAI
4
+
5
+ /-! Independent specification of source `lem:transfer` / `eq:rank-transfer`.
6
+ The fixed filter mask is arbitrary. Every remaining product coordinate and parity
7
+ is averaged, and the actual nominal rank statistic is zero when unlisted. -/
8
+
9
+ namespace MatroidProphet
10
+
11
+ open Finset MainAlgorithm
12
+
13
+ /-- Full sample-to-rank contract for the actual rounded greedy survivor groups. -/
14
+ def TransferClaim : Prop :=
15
+ ∀ (n : ℕ) (M : Matroid (Fin n)) (hE : M.E = Set.univ)
16
+ (w : Weights n), (∀ e, 0 ≤ w e) →
17
+ ∀ (H : Finset (Fin n)) (i : ℤ),
18
+ let s : Fin n → Option ℤ := fun e => roundedLevel weightBase (w e)
19
+ let d : MainMasks n := ⟨H, ∅, ∅, ∅, false⟩
20
+ let U := trueGroup M d s i
21
+ let Y := (positiveGreedy M s \ H).filter (fun e => s e = some i)
22
+ densityThreshold ≤ (U.card : ℝ) →
23
+ ((((2 : ℝ)^16)⁻¹ * Y.card - ((2 : ℝ)^23)⁻¹ * U.card) / (2 : ℝ)^100) ≤
24
+ mainMean d (fun d' => (trueZ M hE d' s i : ℝ))
25
+
26
+ end MatroidProphet
27
+
28
+ end OAI
lean/OAI/Probability/MatroidSecretary/Weights/DegenerateCases.lean ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import Mathlib.Combinatorics.Matroid.Loop
3
+
4
+ namespace OAI
5
+
6
+ /-!
7
+ # Degenerate inputs and loop coordinates
8
+
9
+ These lemmas concern the actual optimum and online execution, not a surrogate
10
+ benchmark. They make explicit the empty-ground, all-loop, zero-optimum and
11
+ fully-sacrificed cases admitted by setup.tex and secretary.tex. In particular,
12
+ no moment or boundedness hypothesis on a loop coordinate is needed for OPT.
13
+ -/
14
+
15
+ namespace MatroidProphet.DegenerateCases
16
+
17
+ open Finset
18
+
19
+ /-- Offline optimization is unaffected by any change in loop coordinates. -/
20
+ theorem optimum_congr_on_nonloops {n : ℕ} (M : Matroid (Fin n))
21
+ (v w : Weights n) (h : ∀ e, M.IsNonloop e → v e = w e) :
22
+ optimum M v = optimum M w := by
23
+ classical
24
+ unfold optimum
25
+ congr 1
26
+ funext I
27
+ split_ifs with hI
28
+ · apply Finset.sum_congr rfl
29
+ intro e he
30
+ exact h e (hI.isNonloop_of_mem he)
31
+ · rfl
32
+
33
+ /-- Zero weights have zero optimum, without a full-ground assumption. -/
34
+ theorem optimum_zero {n : ℕ} (M : Matroid (Fin n)) :
35
+ optimum M (fun _ => 0) = 0 := by
36
+ classical
37
+ unfold optimum
38
+ simp
39
+
40
+ /-- If every nonloop has zero weight, arbitrary loop weights do not affect OPT. -/
41
+ theorem optimum_eq_zero_of_nonloops_zero {n : ℕ} (M : Matroid (Fin n))
42
+ (w : Weights n) (hw : ∀ e, M.IsNonloop e → w e = 0) :
43
+ optimum M w = 0 := by
44
+ rw [optimum_congr_on_nonloops M w (fun _ => 0) hw, optimum_zero]
45
+
46
+ /-- The all-loop case includes arbitrarily large and arbitrary-sign loop weights. -/
47
+ theorem optimum_eq_zero_of_all_loops {n : ℕ} (M : Matroid (Fin n))
48
+ (hM : ∀ e, M.IsLoop e) (w : Weights n) : optimum M w = 0 := by
49
+ apply optimum_eq_zero_of_nonloops_zero
50
+ intro e he
51
+ exact False.elim (he.not_isLoop (hM e))
52
+
53
+ /-- No labels is a valid input, and its actual offline optimum is zero. -/
54
+ theorem optimum_empty (M : Matroid (Fin 0)) (w : Weights 0) :
55
+ optimum M w = 0 := by
56
+ apply optimum_eq_zero_of_nonloops_zero
57
+ intro e
58
+ exact Fin.elim0 e
59
+
60
+ /-- A nonloop singleton is one of the sets in the optimization benchmark. -/
61
+ theorem nonloop_weight_le_optimum {n : ℕ} (M : Matroid (Fin n))
62
+ (w : Weights n) (e : Fin n) (he : M.IsNonloop e) :
63
+ w e ≤ optimum M w := by
64
+ simpa using sum_le_optimum M w {e} (by simpa using he.indep)
65
+
66
+ /-- On nonnegative vectors, OPT vanishes exactly when every nonloop weight does. -/
67
+ theorem optimum_eq_zero_iff {n : ℕ} (M : Matroid (Fin n))
68
+ (w : Weights n) (hw : ∀ e, 0 ≤ w e) :
69
+ optimum M w = 0 ↔ ∀ e, M.IsNonloop e → w e = 0 := by
70
+ constructor
71
+ · intro h e he
72
+ exact le_antisymm (h ▸ nonloop_weight_le_optimum M w e he) (hw e)
73
+ · exact optimum_eq_zero_of_nonloops_zero M w
74
+
75
+ /-- Every feasible rule has exactly zero reward on a zero-OPT input. -/
76
+ theorem reward_eq_zero_of_optimum_eq_zero {n bits : ℕ}
77
+ (M : Matroid (Fin n)) (A : OnlineRule n bits) (hA : Feasible M A)
78
+ (r : Seed bits) (s v : Weights n) (π : ArrivalOrder n)
79
+ (hs : ∀ e, 0 ≤ s e) (hv : ∀ e, 0 ≤ v e) (hopt : optimum M v = 0) :
80
+ reward A r s v π = 0 := by
81
+ apply le_antisymm
82
+ · simpa only [hopt] using reward_le_optimum M A hA r s v π hs hv
83
+ · exact reward_nonneg A r s v π hv
84
+
85
+ /-- Running past the finite final arrival does not create any further decisions. -/
86
+ theorem acceptedThrough_stabilizes {n bits : ℕ} (A : OnlineRule n bits)
87
+ (r : Seed bits) (s v : Weights n) (π : ArrivalOrder n)
88
+ (t : ℕ) (ht : n ≤ t) :
89
+ acceptedThrough A r s v π t = accepted A r s v π := by
90
+ classical
91
+ ext e
92
+ have he : (π.symm e).val < t := lt_of_lt_of_le (π.symm e).isLt ht
93
+ simp [accepted, acceptedThrough, he]
94
+
95
+ /-- The empty prefix never accepts anything, regardless of the rule. -/
96
+ theorem acceptedThrough_zero {n bits : ℕ} (A : OnlineRule n bits)
97
+ (r : Seed bits) (s v : Weights n) (π : ArrivalOrder n) :
98
+ acceptedThrough A r s v π 0 = ∅ := by
99
+ classical
100
+ simp [acceptedThrough]
101
+
102
+ /-- Fully revealed hidden-vector inputs are fully sacrificed, at every prefix. -/
103
+ theorem hiddenAcceptedThrough_eq_empty_of_full_mask {n bits : ℕ}
104
+ (A : HiddenRule n bits) (r : Seed bits) (hmask : A.mask r = Finset.univ)
105
+ (w : Weights n) (π : ArrivalOrder n) (t : ℕ) :
106
+ hiddenAcceptedThrough A r w π t = ∅ := by
107
+ simp [hiddenAcceptedThrough, hmask]
108
+
109
+ /-- Full sacrifice gives zero reward for every order, including the empty order. -/
110
+ theorem hiddenReward_eq_zero_of_full_mask {n bits : ℕ}
111
+ (A : HiddenRule n bits) (r : Seed bits) (hmask : A.mask r = Finset.univ)
112
+ (w : Weights n) (π : ArrivalOrder n) : hiddenReward A r w π = 0 := by
113
+ simp [hiddenReward, hiddenAcceptedThrough_eq_empty_of_full_mask A r hmask]
114
+
115
+ /-- The seed-wise adversarial minimum also vanishes under full sacrifice. -/
116
+ theorem hiddenWorstReward_eq_zero_of_full_mask {n bits : ℕ}
117
+ (A : HiddenRule n bits) (r : Seed bits) (hmask : A.mask r = Finset.univ)
118
+ (w : Weights n) : hiddenWorstReward A w r = 0 := by
119
+ classical
120
+ simp [hiddenWorstReward, hiddenReward_eq_zero_of_full_mask A r hmask]
121
+
122
+ end MatroidProphet.DegenerateCases
123
+
124
+ end OAI
lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawModel.lean ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib.Probability.ProbabilityMassFunction.Integrals
2
+
3
+ namespace OAI
4
+
5
+ namespace MatroidProphet.FiniteLaw
6
+
7
+ open MeasureTheory
8
+ open scoped BigOperators
9
+
10
+ noncomputable def weightPMF {α : Type*} [Fintype α] (p : α → ℝ)
11
+ (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) : PMF α :=
12
+ PMF.ofFintype (fun a => ENNReal.ofReal (p a)) (by
13
+ rw [← ENNReal.ofReal_sum_of_nonneg (fun a _ => hp a), hp1]
14
+ exact ENNReal.ofReal_one)
15
+
16
+ noncomputable def weightMeasure {α : Type*} [Fintype α] [MeasurableSpace α]
17
+ (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) : Measure α :=
18
+ (weightPMF p hp hp1).toMeasure
19
+
20
+ noncomputable def kernelJointPMF {α β : Type*} [Fintype α] [Fintype β]
21
+ (m : β → ℝ) (k : β → α → ℝ)
22
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
23
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) : PMF (β × α) :=
24
+ weightPMF (fun ba => m ba.1 * k ba.1 ba.2)
25
+ (fun ba => mul_nonneg (hm ba.1) (hk ba.1 ba.2)) (by
26
+ rw [Fintype.sum_prod_type]
27
+ simp_rw [← Finset.mul_sum, hk1, mul_one]
28
+ exact hm1)
29
+
30
+ noncomputable def kernelJointMeasure {α β : Type*} [Fintype α] [Fintype β]
31
+ [MeasurableSpace α] [MeasurableSpace β]
32
+ (m : β → ℝ) (k : β → α → ℝ)
33
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
34
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) : Measure (β × α) :=
35
+ (kernelJointPMF m k hm hm1 hk hk1).toMeasure
36
+
37
+ end MatroidProphet.FiniteLaw
38
+
39
+ end OAI
lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawTheorems.lean ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidSecretary.Weights.FiniteWeightLawModel
2
+
3
+ namespace OAI
4
+
5
+ /-!
6
+ Finite conditional-kernel bridge for the secretary transport. The algebraic
7
+ fiber identity is a hypothesis of these reusable lemmas, not a substitute for
8
+ proving that identity for the manuscript's actual source-seed law.
9
+ -/
10
+
11
+ namespace MatroidProphet.FiniteLaw
12
+
13
+ open MeasureTheory
14
+ open scoped BigOperators Classical
15
+
16
+ variable {α β : Type*} [Fintype α] [Fintype β]
17
+
18
+ @[simp] theorem weightPMF_apply (p : α → ℝ) (hp : ∀ a, 0 ≤ p a)
19
+ (hp1 : ∑ a, p a = 1) (a : α) :
20
+ weightPMF p hp hp1 a = ENNReal.ofReal (p a) := rfl
21
+
22
+ instance weightMeasure_probability [MeasurableSpace α]
23
+ (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) :
24
+ IsProbabilityMeasure (weightMeasure p hp hp1) := by
25
+ unfold weightMeasure
26
+ infer_instance
27
+
28
+ theorem weightMeasure_singleton [MeasurableSpace α] [MeasurableSingletonClass α]
29
+ (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) (a : α) :
30
+ weightMeasure p hp hp1 {a} = ENNReal.ofReal (p a) := by
31
+ exact PMF.toMeasure_apply_singleton _ a (MeasurableSet.singleton a)
32
+
33
+ theorem integral_weightMeasure [MeasurableSpace α] [MeasurableSingletonClass α]
34
+ (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) (f : α → ℝ) :
35
+ (∫ a, f a ∂weightMeasure p hp hp1) = ∑ a, p a * f a := by
36
+ rw [weightMeasure, PMF.integral_eq_sum]
37
+ simp only [weightPMF_apply, ENNReal.toReal_ofReal (hp _), smul_eq_mul]
38
+
39
+ theorem sum_real_singleton [MeasurableSpace α] [MeasurableSingletonClass α]
40
+ (μ : Measure α) [IsProbabilityMeasure μ] :
41
+ (∑ a, μ.real {a}) = 1 := by
42
+ simp
43
+
44
+ /-- No finite-law assumption is added: every probability measure on a finite
45
+ discrete space is exactly the measure of its real singleton weights. -/
46
+ theorem weightMeasure_real_singleton [MeasurableSpace α] [MeasurableSingletonClass α]
47
+ (μ : Measure α) [IsProbabilityMeasure μ] :
48
+ weightMeasure (fun a => μ.real {a}) (fun _ => measureReal_nonneg)
49
+ (sum_real_singleton μ) = μ := by
50
+ apply Measure.ext_of_singleton
51
+ intro a
52
+ rw [weightMeasure_singleton, measureReal_def]
53
+ exact ENNReal.ofReal_toReal (measure_ne_top μ {a})
54
+
55
+ omit [Fintype β] in
56
+ theorem map_real_singleton
57
+ [MeasurableSpace α] [MeasurableSingletonClass α]
58
+ [MeasurableSpace β] [MeasurableSingletonClass β]
59
+ (μ : Measure α) [IsProbabilityMeasure μ] (obs : α → β) (b : β) :
60
+ (μ.map obs).real {b} = ∑ a, if obs a = b then μ.real {a} else 0 := by
61
+ classical
62
+ have hs : ((Finset.univ.filter fun a => obs a = b : Finset α) : Set α) =
63
+ obs ⁻¹' {b} := by
64
+ ext a
65
+ simp
66
+ rw [← Finset.sum_filter, sum_measureReal_singleton, hs]
67
+ simp only [measureReal_def,
68
+ Measure.map_apply (measurable_of_countable obs) (MeasurableSet.singleton b)]
69
+
70
+ @[simp] theorem kernelJointPMF_apply
71
+ (m : β → ℝ) (k : β → α → ℝ)
72
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
73
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1)
74
+ (b : β) (a : α) :
75
+ kernelJointPMF m k hm hm1 hk hk1 (b, a) = ENNReal.ofReal (m b * k b a) := rfl
76
+
77
+ instance kernelJointMeasure_probability [MeasurableSpace α] [MeasurableSpace β]
78
+ (m : β → ℝ) (k : β → α → ℝ)
79
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
80
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) :
81
+ IsProbabilityMeasure (kernelJointMeasure m k hm hm1 hk hk1) := by
82
+ unfold kernelJointMeasure
83
+ infer_instance
84
+
85
+ theorem integral_kernelJointMeasure
86
+ [MeasurableSpace α] [MeasurableSingletonClass α]
87
+ [MeasurableSpace β] [MeasurableSingletonClass β]
88
+ (m : β → ℝ) (k : β → α → ℝ)
89
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
90
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1)
91
+ (f : β × α → ℝ) :
92
+ (∫ ba, f ba ∂kernelJointMeasure m k hm hm1 hk hk1) =
93
+ ∫ b, ∫ a, f (b, a) ∂weightMeasure (k b) (hk b) (hk1 b)
94
+ ∂weightMeasure m hm hm1 := by
95
+ rw [kernelJointMeasure, kernelJointPMF]
96
+ change (∫ ba, f ba ∂weightMeasure _ _ _) = _
97
+ rw [integral_weightMeasure, Fintype.sum_prod_type, integral_weightMeasure]
98
+ simp_rw [integral_weightMeasure, Finset.mul_sum, mul_assoc]
99
+
100
+ theorem kernelJointPMF_eq_map
101
+ (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1)
102
+ (obs : α → β) (m : β → ℝ) (k : β → α → ℝ)
103
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
104
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1)
105
+ (hjoint : ∀ b a, m b * k b a = if obs a = b then p a else 0) :
106
+ kernelJointPMF m k hm hm1 hk hk1 =
107
+ (weightPMF p hp hp1).map (fun a => (obs a, a)) := by
108
+ classical
109
+ ext ba : 1
110
+ obtain ⟨b, a⟩ := ba
111
+ rw [kernelJointPMF_apply, hjoint]
112
+ simp only [PMF.map_apply, tsum_fintype, Prod.mk.injEq, weightPMF_apply]
113
+ rw [Finset.sum_eq_single a]
114
+ · by_cases h : obs a = b
115
+ · simp [h]
116
+ · have h' : b ≠ obs a := Ne.symm h
117
+ simp [h, h']
118
+ · intro a' _ hne
119
+ simp [Ne.symm hne]
120
+ · simp
121
+
122
+ theorem kernelJointMeasure_eq_map
123
+ [MeasurableSpace α] [MeasurableSingletonClass α]
124
+ [MeasurableSpace β] [MeasurableSingletonClass β]
125
+ (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1)
126
+ (obs : α → β) (m : β → ℝ) (k : β → α → ℝ)
127
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
128
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1)
129
+ (hjoint : ∀ b a, m b * k b a = if obs a = b then p a else 0) :
130
+ kernelJointMeasure m k hm hm1 hk hk1 =
131
+ (weightMeasure p hp hp1).map (fun a => (obs a, a)) := by
132
+ rw [kernelJointMeasure, kernelJointPMF_eq_map p hp hp1 obs m k hm hm1 hk hk1 hjoint]
133
+ exact (PMF.toMeasure_map (fun a => (obs a, a)) (weightPMF p hp hp1)
134
+ (measurable_of_countable _)).symm
135
+
136
+ /-- The joint law transports every statistic of the observation and full seed,
137
+ not merely statistics of the sacrificed mask. -/
138
+ theorem integral_reconstruction
139
+ [MeasurableSpace α] [MeasurableSingletonClass α]
140
+ [MeasurableSpace β] [MeasurableSingletonClass β]
141
+ (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1)
142
+ (obs : α → β) (m : β → ℝ) (k : β → α → ℝ)
143
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
144
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1)
145
+ (hjoint : ∀ b a, m b * k b a = if obs a = b then p a else 0)
146
+ (f : β × α → ℝ) :
147
+ (∫ b, ∫ a, f (b, a) ∂weightMeasure (k b) (hk b) (hk1 b)
148
+ ∂weightMeasure m hm hm1) =
149
+ ∫ a, f (obs a, a) ∂weightMeasure p hp hp1 := by
150
+ rw [← integral_kernelJointMeasure m k hm hm1 hk hk1 f,
151
+ kernelJointMeasure_eq_map p hp hp1 obs m k hm hm1 hk hk1 hjoint]
152
+ exact integral_map_of_stronglyMeasurable (measurable_of_countable _)
153
+ (measurable_of_countable f).stronglyMeasurable
154
+
155
+ /-- Every positive-mass reconstructed joint outcome has exactly its advertised
156
+ observation. Zero-mass fibers are not silently ruled out. -/
157
+ theorem observation_eq_of_joint_support
158
+ (p : α → ℝ) (obs : α → β) (m : β → ℝ) (k : β → α → ℝ)
159
+ (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1)
160
+ (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1)
161
+ (hjoint : ∀ b a, m b * k b a = if obs a = b then p a else 0)
162
+ (b : β) (a : α)
163
+ (ha : (b, a) ∈ (kernelJointPMF m k hm hm1 hk hk1).support) : obs a = b := by
164
+ rw [PMF.mem_support_iff, kernelJointPMF_apply, hjoint] at ha
165
+ by_contra h
166
+ exact ha (by simp [h])
167
+
168
+ end MatroidProphet.FiniteLaw
169
+
170
+ end OAI
lean/OAI/Probability/MatroidSecretary/Weights/OptimumIntegrability.lean ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidSecretary.Weights.DegenerateCases
2
+ import OAI.Probability.MatroidProphet.Main
3
+ import Mathlib.MeasureTheory.Integral.Bochner.Basic
4
+
5
+ namespace OAI
6
+
7
+ /-!
8
+ # The exact finite-moment requirement
9
+
10
+ For a finite matroid and nonnegative measurable weights, integrability of the
11
+ actual offline optimum is equivalent to integrability of the nonloop
12
+ coordinates. No loop-coordinate moments are imposed. This is a supporting
13
+ scope check for introduction.tex, Theorem `thm:main`, and setup.tex's
14
+ one-sample simulation argument; it does not replace its competitive claim.
15
+ -/
16
+
17
+ namespace MatroidProphet.DegenerateCases
18
+
19
+ open MeasureTheory Classical
20
+ open scoped BigOperators
21
+
22
+ /-- Only nonloops can contribute to a feasible sum. -/
23
+ theorem optimum_le_sum_nonloops {n : ℕ} (M : Matroid (Fin n))
24
+ (w : Weights n) (hw : ∀ e, 0 ≤ w e) :
25
+ optimum M w ≤ ∑ e : Fin n, if M.IsNonloop e then w e else 0 := by
26
+ classical
27
+ have hn (e : Fin n) : 0 ≤ if M.IsNonloop e then w e else 0 := by
28
+ split_ifs
29
+ · exact hw e
30
+ · exact le_rfl
31
+ apply optimum_le_of_independent_bound M w _ (Finset.sum_nonneg fun e _ => hn e)
32
+ intro I hI
33
+ calc
34
+ (∑ e ∈ I, w e) = ∑ e ∈ I, if M.IsNonloop e then w e else 0 := by
35
+ apply Finset.sum_congr rfl
36
+ intro e he
37
+ simp [hI.isNonloop_of_mem he]
38
+ _ ≤ ∑ e : Fin n, if M.IsNonloop e then w e else 0 := by
39
+ exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ I)
40
+ (fun e _ _ => hn e)
41
+
42
+ /-- Nonloop moments follow from the assumed finite offline optimum moment. -/
43
+ theorem integrable_nonloop_of_integrable_optimum {n : ℕ}
44
+ (M : Matroid (Fin n)) {Ω : Type*} [MeasurableSpace Ω]
45
+ (μ : Measure Ω) (V : Ω → Weights n) (hV : Measurable V)
46
+ (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e)
47
+ (hopt : Integrable (fun ω => optimum M (V ω)) μ)
48
+ (e : Fin n) (he : M.IsNonloop e) : Integrable (fun ω => V ω e) μ := by
49
+ apply hopt.mono' ((measurable_pi_apply e).comp hV).aestronglyMeasurable
50
+ filter_upwards [hVN] with ω hω
51
+ change ‖V ω e‖ ≤ optimum M (V ω)
52
+ rw [Real.norm_eq_abs, abs_of_nonneg (hω e)]
53
+ exact nonloop_weight_le_optimum M (V ω) e he
54
+
55
+ /-- Conversely, finite moments only on the nonloops suffice for finite E[OPT]. -/
56
+ theorem integrable_optimum_of_integrable_nonloops {n : ℕ}
57
+ (M : Matroid (Fin n)) {Ω : Type*} [MeasurableSpace Ω]
58
+ (μ : Measure Ω) (V : Ω → Weights n) (hV : Measurable V)
59
+ (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e)
60
+ (hmom : ∀ e, M.IsNonloop e → Integrable (fun ω => V ω e) μ) :
61
+ Integrable (fun ω => optimum M (V ω)) μ := by
62
+ classical
63
+ have hsum : Integrable (fun ω =>
64
+ ∑ e : Fin n, if M.IsNonloop e then V ω e else 0) μ := by
65
+ apply integrable_finsetSum
66
+ intro e _
67
+ by_cases he : M.IsNonloop e
68
+ · simpa only [ite_eq_left he] using hmom e he
69
+ · simp only [ite_eq_right he]
70
+ exact integrable_zero _ _ _
71
+ apply hsum.mono' ((measurable_optimum M).comp hV).aestronglyMeasurable
72
+ filter_upwards [hVN] with ω hω
73
+ change ‖optimum M (V ω)‖ ≤ ∑ e : Fin n, if M.IsNonloop e then V ω e else 0
74
+ rw [Real.norm_eq_abs, abs_of_nonneg (optimum_nonneg M (V ω))]
75
+ exact optimum_le_sum_nonloops M (V ω) hω
76
+
77
+ /-- An exact criterion: loop moments are deliberately absent on the right. -/
78
+ theorem integrable_optimum_iff {n : ℕ} (M : Matroid (Fin n))
79
+ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)
80
+ (V : Ω → Weights n) (hV : Measurable V)
81
+ (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) :
82
+ Integrable (fun ω => optimum M (V ω)) μ ↔
83
+ ∀ e, M.IsNonloop e → Integrable (fun ω => V ω e) μ := by
84
+ constructor
85
+ · exact integrable_nonloop_of_integrable_optimum M μ V hV hVN
86
+ · exact integrable_optimum_of_integrable_nonloops M μ V hV hVN
87
+
88
+ end MatroidProphet.DegenerateCases
89
+
90
+ end OAI
lean/OAI/Probability/MatroidSecretary/Weights/ZeroBenchmark.lean ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Probability.MatroidProphet.Main
2
+ import Mathlib.MeasureTheory.Integral.Bochner.Basic
3
+
4
+ namespace OAI
5
+
6
+ namespace MatroidProphet.ZeroBenchmark
7
+
8
+ open MeasureTheory Finset
9
+ open scoped Classical
10
+
11
+ /-- Only singleton-independent labels can affect the offline optimum.
12
+ No sign or integrability assumption is necessary for this identity. -/
13
+ theorem optimum_congr_on_singletons {n : ℕ} (M : Matroid (Fin n))
14
+ (w v : Weights n)
15
+ (h : ∀ e, M.Indep ({e} : Set (Fin n)) → w e = v e) :
16
+ optimum M w = optimum M v := by
17
+ classical
18
+ unfold optimum
19
+ apply Finset.sup'_congr Finset.univ_nonempty rfl
20
+ intro I _
21
+ by_cases hI : M.Indep (I : Set (Fin n))
22
+ · simp only [ite_eq_left hI]
23
+ apply Finset.sum_congr rfl
24
+ intro e he
25
+ exact h e (hI.subset (Set.singleton_subset_iff.mpr he))
26
+ · simp only [ite_eq_right hI]
27
+
28
+ /-- The zero-weight benchmark is zero, also for empty or rank-zero matroids. -/
29
+ @[simp] theorem optimum_zero {n : ℕ} (M : Matroid (Fin n)) :
30
+ optimum M (fun _ => 0) = 0 := by
31
+ classical
32
+ simp [optimum]
33
+
34
+ /-- On nonnegative inputs, a zero benchmark is exactly the condition that
35
+ every label that could be accepted on its own has zero weight. -/
36
+ theorem optimum_eq_zero_iff {n : ℕ} (M : Matroid (Fin n))
37
+ (w : Weights n) (hw : ∀ e, 0 ≤ w e) :
38
+ optimum M w = 0 ↔ ∀ e, M.Indep ({e} : Set (Fin n)) → w e = 0 := by
39
+ constructor
40
+ · intro h e he
41
+ have hb := sum_le_optimum M w {e} (by simpa using he)
42
+ simp only [Finset.sum_singleton, h] at hb
43
+ exact le_antisymm hb (hw e)
44
+ · intro h
45
+ rw [optimum_congr_on_singletons M w (fun _ => 0) h]
46
+ exact optimum_zero M
47
+
48
+ /-- Replacing all loop coordinates by zero never changes the objective.
49
+ Here ground-set outsiders, if any, are also harmless. -/
50
+ theorem optimum_ignore_infeasible_coordinates {n : ℕ} (M : Matroid (Fin n))
51
+ (w : Weights n) :
52
+ optimum M (fun e => if M.Indep ({e} : Set (Fin n)) then w e else 0) =
53
+ optimum M w := by
54
+ classical
55
+ apply optimum_congr_on_singletons
56
+ intro e he
57
+ simp only [ite_eq_left he]
58
+
59
+ /-- Rank-zero behavior needs no bound at all on the values of its labels. -/
60
+ theorem optimum_eq_zero_of_no_independent_singleton {n : ℕ}
61
+ (M : Matroid (Fin n))
62
+ (hM : ∀ e, ¬ M.Indep ({e} : Set (Fin n))) (w : Weights n) :
63
+ optimum M w = 0 := by
64
+ rw [optimum_congr_on_singletons M w (fun _ => 0) (fun e he => (hM e he).elim)]
65
+ exact optimum_zero M
66
+
67
+ /-- The empty instance has the zero benchmark without a positive-size premise. -/
68
+ @[simp] theorem optimum_empty (M : Matroid (Fin 0)) (w : Weights 0) :
69
+ optimum M w = 0 := by
70
+ apply optimum_eq_zero_of_no_independent_singleton
71
+ intro e
72
+ exact Fin.elim0 e
73
+
74
+ /-- Every feasible realized hidden reward vanishes when the benchmark does. -/
75
+ theorem hiddenReward_eq_zero {n bits : ℕ} (M : Matroid (Fin n))
76
+ (A : HiddenRule n bits) (r : Seed bits) (w : Weights n)
77
+ (π : ArrivalOrder n) (hw : ∀ e, 0 ≤ w e)
78
+ (hA : M.Indep (hiddenAcceptedThrough A r w π n : Set (Fin n)))
79
+ (hopt : optimum M w = 0) : hiddenReward A r w π = 0 := by
80
+ apply le_antisymm
81
+ · exact (sum_le_optimum M w _ hA).trans_eq hopt
82
+ · exact Finset.sum_nonneg fun e _ => hw e
83
+
84
+ /-- The zero-benchmark conclusion also holds for the minimum taken separately
85
+ at each complete seed, before any expectation. -/
86
+ theorem hiddenWorstReward_eq_zero {n bits : ℕ} (M : Matroid (Fin n))
87
+ (A : HiddenRule n bits) (w : Weights n) (hw : ∀ e, 0 ≤ w e)
88
+ (hA : ∀ r π, M.Indep (hiddenAcceptedThrough A r w π n : Set (Fin n)))
89
+ (hopt : optimum M w = 0) (r : Seed bits) :
90
+ hiddenWorstReward A w r = 0 := by
91
+ apply le_antisymm
92
+ · exact (hiddenWorstReward_le A w r (Equiv.refl _)).trans_eq
93
+ (hiddenReward_eq_zero M A r w (Equiv.refl _) hw (hA r _) hopt)
94
+ · exact hiddenWorstReward_nonneg A w hw r
95
+
96
+ /-- No probability-law or moment premise is needed in the zero case. -/
97
+ theorem integral_hiddenWorstReward_eq_zero {n bits : ℕ} (M : Matroid (Fin n))
98
+ (A : HiddenRule n bits) (w : Weights n) (hw : ∀ e, 0 ≤ w e)
99
+ (hA : ∀ r π, M.Indep (hiddenAcceptedThrough A r w π n : Set (Fin n)))
100
+ (hopt : optimum M w = 0) (ν : Measure (Seed bits)) :
101
+ (∫ r, hiddenWorstReward A w r ∂ν) = 0 := by
102
+ simp only [hiddenWorstReward_eq_zero M A w hw hA hopt]
103
+ exact integral_zero _ _
104
+
105
+ /-- Even completely unrestricted loop coordinates cannot create a moment
106
+ requirement when the usable coordinates vanish almost everywhere. -/
107
+ theorem integrable_optimum_of_usable_coordinates_zero {n : ℕ}
108
+ (M : Matroid (Fin n)) {Ω : Type*} [MeasurableSpace Ω]
109
+ (μ : Measure Ω) (V : Ω → Weights n)
110
+ (hV : ∀ᵐ ω ∂μ, ∀ e, M.Indep ({e} : Set (Fin n)) → V ω e = 0) :
111
+ Integrable (fun ω => optimum M (V ω)) μ := by
112
+ apply (integrable_zero Ω ℝ μ).congr
113
+ filter_upwards [hV] with ω hω
114
+ symm
115
+ rw [optimum_congr_on_singletons M (V ω) (fun _ => 0) hω]
116
+ exact optimum_zero M
117
+
118
+
119
+ theorem integral_optimum_of_usable_coordinates_zero {n : ℕ}
120
+ (M : Matroid (Fin n)) {Ω : Type*} [MeasurableSpace Ω]
121
+ (μ : Measure Ω) (V : Ω → Weights n)
122
+ (hV : ∀ᵐ ω ∂μ, ∀ e, M.Indep ({e} : Set (Fin n)) → V ω e = 0) :
123
+ (∫ ω, optimum M (V ω) ∂μ) = 0 := by
124
+ calc
125
+ (∫ ω, optimum M (V ω) ∂μ) = ∫ _ : Ω, (0 : ℝ) ∂μ := by
126
+ apply integral_congr_ae
127
+ filter_upwards [hV] with ω hω
128
+ rw [optimum_congr_on_singletons M (V ω) (fun _ => 0) hω]
129
+ exact optimum_zero M
130
+ _ = 0 := integral_zero _ _
131
+
132
+ end MatroidProphet.ZeroBenchmark
133
+
134
+ end OAI
lean/OAI/Probability/MemoryPrecision/AmbientGram.lean ADDED
@@ -0,0 +1,664 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+
4
+ namespace OAI
5
+
6
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
7
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
8
+
9
+ noncomputable section
10
+ universe u v
11
+
12
+
13
+
14
+ open MeasureTheory Set Filter EuclideanGeometry
15
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
16
+ namespace MemoryPrecision
17
+
18
+ abbrev Space (d : ℕ) := EuclideanSpace ℝ (Fin d)
19
+
20
+ def J (β : ℝ) (m j : ℕ) : ℝ :=
21
+ let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast
22
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
23
+ let three : ℝ := @OfNat.ofNat ℝ 3 (@instOfNatAtLeastTwo ℝ 3 Real.commRing.toNatCast
24
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 1)))
25
+ 1 + three^j * two^β * (m : ℝ) / (β - (j : ℝ) - (m : ℝ))
26
+
27
+ def AmbientBallBound {d : ℕ} (μ : Measure (Space d)) (H β : ℝ) : Prop :=
28
+ ∀ x : Space d, ∀ r : ℝ, 0 < r →
29
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H * r^β)
30
+
31
+ def InverseGram {d p : ℕ} (m : ℕ) (v : Space d × (Fin (p-1) → Space d)) : ℝ≥0∞ :=
32
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
33
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
34
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
35
+ letI : AddCommGroup (Space d) := WithLp.instAddCommGroup exponent (Fin d → ℝ)
36
+ letI : Inner ℝ (Space d) := @InnerProductSpace.toInner ℝ (Space d) _
37
+ (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ))
38
+ (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))
39
+ ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ (fun i => v.2 i - v.1)).det)⁻¹ ^ m)
40
+
41
+ lemma sharp_inverse_unit {X : Type*} [MeasurableSpace X]
42
+ (μ : Measure X) (f : X → ℝ) (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x)
43
+ {m a C : ℝ} (hm : 0 < m) (ha : m < a) (hC : 0 ≤ C)
44
+ (htube : ∀ t : ℝ, 0 < t → t ≤ 1 →
45
+ μ {x | f x ≤ t} ≤ ENNReal.ofReal (C * t^a)) :
46
+ (∫⁻ x, ENNReal.ofReal (f x ^ (-m)) ∂μ) ≤
47
+ μ univ + ENNReal.ofReal (C * m / (a-m)) := by
48
+ have htail (t : ℝ) (ht : 1 < t) :
49
+ μ {x | t < f x ^ (-m)} ≤ ENNReal.ofReal (C * t ^ (-a/m)) := by
50
+ have ht0 : 0 < t := by linarith
51
+ have hr0 : 0 < t ^ ((-m)⁻¹) := Real.rpow_pos_of_pos ht0 _
52
+ have hr1 : t ^ ((-m)⁻¹) ≤ 1 := by
53
+ calc
54
+ _ ≤ t ^ (0 : ℝ) := Real.rpow_le_rpow_of_exponent_le ht.le (inv_nonpos.mpr (by linarith))
55
+ _ = 1 := Real.rpow_zero _
56
+ have hsub : {x | t < f x ^ (-m)} ⊆ {x | f x ≤ t ^ ((-m)⁻¹)} := by
57
+ intro x hx
58
+ have hfx : 0 < f x := by
59
+ by_contra h
60
+ have heq : f x = 0 := le_antisymm (le_of_not_gt h) (hf0 x)
61
+ simp only [mem_ofPred_eq, heq, Real.zero_rpow (neg_ne_zero.mpr hm.ne')] at hx
62
+ linarith
63
+ exact ((Real.lt_rpow_inv_iff_of_neg hfx ht0 (by linarith)).2 hx).le
64
+ calc
65
+ _ ≤ μ {x | f x ≤ t ^ ((-m)⁻¹)} := measure_mono hsub
66
+ _ ≤ ENNReal.ofReal (C * (t ^ ((-m)⁻¹)) ^ a) := htube _ hr0 hr1
67
+ _ = _ := by
68
+ rw [← Real.rpow_mul ht0.le]
69
+ congr 2
70
+ ring_nf
71
+ have hb : -a/m < -1 := by
72
+ rw [div_lt_iff₀ hm]
73
+ linarith
74
+ have hint : IntegrableOn (fun t : ℝ => C * t ^ (-a/m)) (Ioi 1) :=
75
+ (integrableOn_Ioi_rpow_of_lt hb (by norm_num)).const_mul C
76
+ have hnn : 0 ≤ᵐ[volume.restrict (Ioi (1:ℝ))] (fun t : ℝ => C * t ^ (-a/m)) := by
77
+ filter_upwards [ae_restrict_mem (μ := (volume : Measure ℝ)) measurableSet_Ioi] with t ht
78
+ exact mul_nonneg hC (Real.rpow_nonneg (by have ht' : (1:ℝ) < t := ht; linarith : 0 ≤ t) _)
79
+ have htailint : (∫⁻ t in Ioi (1:ℝ), ENNReal.ofReal (C * t ^ (-a/m))) =
80
+ ENNReal.ofReal (C * m / (a-m)) := by
81
+ rw [← ofReal_integral_eq_lintegral_ofReal hint hnn, integral_const_mul,
82
+ integral_Ioi_rpow_of_lt hb (by norm_num), Real.one_rpow]
83
+ congr 1
84
+ field_simp [hm.ne', show a - m ≠ 0 by linarith, show -a + m ≠ 0 by linarith]
85
+ ring
86
+ have hsplit : Ioi (0:ℝ) = Ioc 0 1 ∪ Ioi 1 := by
87
+ ext t
88
+ simp only [mem_Ioi, mem_union, mem_Ioc]
89
+ constructor
90
+ · intro ht
91
+ by_cases h : t ≤ 1
92
+ · exact Or.inl ⟨ht,h⟩
93
+ · exact Or.inr (lt_of_not_ge h)
94
+ · rintro (⟨ht,_⟩ | ht) <;> linarith
95
+ rw [lintegral_eq_lintegral_meas_lt μ
96
+ (Filter.Eventually.of_forall fun x => Real.rpow_nonneg (hf0 x) _) (hf.pow_const _).aemeasurable,
97
+ hsplit]
98
+ apply (lintegral_union_le _ _ _).trans
99
+ apply add_le_add
100
+ · calc
101
+ _ ≤ ∫⁻ _t in Ioc (0:ℝ) 1, μ univ := lintegral_mono fun t => measure_mono (subset_univ _)
102
+ _ = μ univ := by simp [Real.volume_Ioc]
103
+ · calc
104
+ _ ≤ ∫⁻ t in Ioi (1:ℝ), ENNReal.ofReal (C * t ^ (-a/m)) := by
105
+ apply lintegral_mono_ae
106
+ filter_upwards [ae_restrict_mem (μ := (volume : Measure ℝ)) measurableSet_Ioi] with t ht
107
+ exact htail t ht
108
+ _ = _ := htailint
109
+
110
+ lemma ae_pos_of_power_tube {X : Type*} [MeasurableSpace X]
111
+ (μ : Measure X) (f : X → ℝ) {a C : ℝ} (ha : 0 < a)
112
+ (htube : ∀ t : ℝ, 0 < t → t ≤ 1 →
113
+ μ {x | f x ≤ t} ≤ ENNReal.ofReal (C * t^a)) : ∀ᵐ x ∂μ, 0 < f x := by
114
+ have hb (n : ℕ) : μ {x | f x ≤ 0} ≤ ENNReal.ofReal (C * ((1/2 : ℝ)^n)^a) := by
115
+ calc
116
+ μ {x | f x ≤ 0} ≤ μ {x | f x ≤ (1/2 : ℝ)^n} :=
117
+ measure_mono fun x hx => (show f x ≤ 0 from hx).trans (by positivity)
118
+ _ ≤ _ := htube _ (by positivity) (pow_le_one₀ (by norm_num) (by norm_num))
119
+ have hlim : Tendsto (fun n : ℕ => ENNReal.ofReal (C * ((1/2 : ℝ)^n)^a)) atTop (𝓝 (0:ℝ≥0∞)) := by
120
+ have h := (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : (0:ℝ) ≤ 1/2)
121
+ (by norm_num : (1/2:ℝ) < 1)).rpow_const_nhds_zero ha
122
+ simpa using ENNReal.tendsto_ofReal (tendsto_const_nhds.mul h)
123
+ have hz := le_antisymm (ge_of_tendsto' hlim hb) (bot_le : (0:ℝ≥0∞) ≤ μ {x | f x ≤ 0})
124
+ simpa only [ae_iff, not_lt] using hz
125
+
126
+ lemma sharp_inverse_scaled {X : Type*} [MeasurableSpace X]
127
+ (μ : Measure X) (f : X → ℝ) (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x)
128
+ {m a B C R : ℝ} (hm : 0 < m) (ha : m < a)
129
+ (hB : 0 ≤ B) (hC : 0 ≤ C) (hR : 0 < R)
130
+ (hmass : μ univ ≤ ENNReal.ofReal B)
131
+ (htube : ∀ t : ℝ, 0 < t → t ≤ 1 →
132
+ μ {x | f x ≤ R*t} ≤ ENNReal.ofReal (C * t^a)) :
133
+ (∀ᵐ x ∂μ, 0 < f x) ∧
134
+ (∫⁻ x, (ENNReal.ofReal (f x)) ^ (-m) ∂μ) ≤
135
+ ENNReal.ofReal ((B + C*m/(a-m)) * R^(-m)) := by
136
+ have hg0 (x : X) : 0 ≤ f x / R := div_nonneg (hf0 x) hR.le
137
+ have hg : Measurable (fun x => f x / R) := hf.div_const R
138
+ have hgtube (t : ℝ) (ht : 0 < t) (ht1 : t ≤ 1) :
139
+ μ {x | f x / R ≤ t} ≤ ENNReal.ofReal (C*t^a) := by
140
+ have heq : {x | f x / R ≤ t} = {x | f x ≤ R*t} := by
141
+ ext x
142
+ simp only [mem_ofPred_eq, div_le_iff₀ hR, mul_comm]
143
+ rw [heq]
144
+ exact htube t ht ht1
145
+ have hgp := ae_pos_of_power_tube μ (fun x => f x / R) (hm.trans ha) hgtube
146
+ have hfp : ∀ᵐ x ∂μ, 0 < f x := by
147
+ filter_upwards [hgp] with x hx
148
+ exact (div_pos_iff_of_pos_right hR).mp hx
149
+ refine ⟨hfp, ?_⟩
150
+ have hi := sharp_inverse_unit μ (fun x => f x/R) hg hg0 hm ha hC hgtube
151
+ have hcpos : 0 < R^(-m) := Real.rpow_pos_of_pos hR _
152
+ calc
153
+ _ = ∫⁻ x, ENNReal.ofReal (R^(-m)) * ENNReal.ofReal ((f x/R)^(-m)) ∂μ := by
154
+ apply lintegral_congr_ae
155
+ filter_upwards [hfp] with x hx
156
+ rw [ENNReal.ofReal_rpow_of_pos hx, ← ENNReal.ofReal_mul hcpos.le,
157
+ Real.div_rpow hx.le hR.le]
158
+ congr 1
159
+ exact (mul_div_cancel₀ _ hcpos.ne').symm
160
+ _ = ENNReal.ofReal (R^(-m)) * (∫⁻ x, ENNReal.ofReal ((f x/R)^(-m)) ∂μ) :=
161
+ lintegral_const_mul _ (hg.pow_const _).ennreal_ofReal
162
+ _ ≤ ENNReal.ofReal (R^(-m)) *
163
+ (ENNReal.ofReal B + ENNReal.ofReal (C*m/(a-m))) :=
164
+ mul_le_mul' le_rfl (hi.trans (add_le_add hmass le_rfl))
165
+ _ = _ := by
166
+ rw [← ENNReal.ofReal_add hB (by positivity), ← ENNReal.ofReal_mul hcpos.le]
167
+ congr 1
168
+ ring
169
+
170
+ section Geometry
171
+ variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
172
+ [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
173
+
174
+ lemma affine_tube_cover_radius (L : AffineSubspace ℝ E) [Nonempty L]
175
+ (z : E) {R t : ℝ} (hR : 0 < R) (ht : 0 < t) (htR : t ≤ R) :
176
+ ∃ s : Finset L.direction,
177
+ (s.card : ℝ) ≤ (3*R/t)^Module.finrank ℝ L.direction ∧
178
+ ∀ x : E, dist x z ≤ R → Metric.infDist x L ≤ t →
179
+ ∃ y ∈ s, dist x (R • (y:E) + (orthogonalProjection L z : E)) ≤ 2*t := by
180
+ classical
181
+ have hr : 0 < t/R := div_pos ht hR
182
+ have hr1 : t/R ≤ 1 := (div_le_one hR).2 htR
183
+ obtain ⟨s, _, hcard, hnet⟩ := NoiselessRegression.exists_unit_ball_net
184
+ (E := L.direction) hr hr1
185
+ refine ⟨s, ?_, ?_⟩
186
+ · convert hcard using 1
187
+ congr 1
188
+ field_simp
189
+ · intro x hx hdist
190
+ let v : L.direction := L.direction.orthogonalProjectionOnto (x-z)
191
+ have hv : ‖v‖ ≤ R := by
192
+ apply (L.direction.norm_orthogonalProjectionOnto_apply_le (x-z)).trans
193
+ simpa only [dist_eq_norm] using hx
194
+ have hvnorm : ‖R⁻¹ • v‖ ≤ 1 := by
195
+ rw [norm_smul, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr hR)]
196
+ calc
197
+ _ ≤ R⁻¹ * R := mul_le_mul_of_nonneg_left hv (inv_nonneg.mpr hR.le)
198
+ _ = 1 := inv_mul_cancel₀ hR.ne'
199
+ obtain ⟨y, hy, hclose⟩ := hnet (R⁻¹ • v) hvnorm
200
+ refine ⟨y, hy, ?_⟩
201
+ have hscaled : dist (v:E) (R • (y:E)) ≤ t := by
202
+ have heq : (v:E) = R • (R⁻¹ • (v:E)) := by simp [smul_smul, hR.ne']
203
+ rw [heq, dist_smul₀, Real.norm_eq_abs, abs_of_pos hR]
204
+ calc
205
+ _ ≤ R * (t/R) := mul_le_mul_of_nonneg_left hclose hR.le
206
+ _ = t := mul_div_cancel₀ _ hR.ne'
207
+ have hproj : (orthogonalProjection L x : E) =
208
+ (v:E) + (orthogonalProjection L z : E) := by
209
+ have h := (orthogonalProjection L).map_vadd z (x-z)
210
+ simpa only [vadd_eq_add, sub_add_cancel, orthogonalProjection_contLinear,
211
+ AffineSubspace.coe_vadd] using congrArg (fun q : L => (q:E)) h
212
+ have hpd : dist (orthogonalProjection L x : E)
213
+ (R • (y:E) + (orthogonalProjection L z : E)) ≤ t := by
214
+ rw [hproj, dist_add_right]
215
+ exact hscaled
216
+ have hxp : dist x (orthogonalProjection L x : E) ≤ t := by
217
+ rwa [dist_orthogonalProjection_eq_infDist]
218
+ calc
219
+ _ ≤ dist x (orthogonalProjection L x : E) +
220
+ dist (orthogonalProjection L x : E) (R • (y:E) + (orthogonalProjection L z : E)) :=
221
+ dist_triangle _ _ _
222
+ _ ≤ t+t := add_le_add hxp hpd
223
+ _ = 2*t := by ring
224
+
225
+ end Geometry
226
+
227
+ section AmbientMoments
228
+ variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
229
+ [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
230
+
231
+ lemma ambient_tube_radius_factors (j : ℕ) (β : ℝ) {R t : ℝ} (ht : 0 < t) :
232
+ (3*R/t)^j * (2*t)^β = (3:ℝ)^j * (2:ℝ)^β * R^j * t^(β-(j:ℝ)) := by
233
+ rw [div_pow, mul_pow, Real.mul_rpow (by norm_num) ht.le,
234
+ Real.rpow_sub_natCast ht.ne']
235
+ ring
236
+
237
+ lemma ambient_tube {μ : Measure E} {H β R : ℝ} {z : E}
238
+ (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
239
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
240
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β))
241
+ (L : AffineSubspace ℝ E) [Nonempty L] {t : ℝ} (ht : 0 < t) (htR : t ≤ R) :
242
+ μ {x | Metric.infDist x L ≤ t} ≤ ENNReal.ofReal
243
+ ((3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H *
244
+ R^Module.finrank ℝ L.direction * t^(β-(Module.finrank ℝ L.direction:ℝ))) := by
245
+ classical
246
+ obtain ⟨s, hcard, hcover⟩ := affine_tube_cover_radius L z hR ht htR
247
+ let c : L.direction → E := fun y => R • (y:E) + (orthogonalProjection L z : E)
248
+ have hsub : {x | Metric.infDist x L ≤ t} ≤ᵐ[μ]
249
+ ⋃ y ∈ s, Metric.closedBall (c y) (2*t) := by
250
+ filter_upwards [μ.support_mem_ae] with x hx
251
+ intro hxL
252
+ have hxR : dist x z ≤ R := hsupport hx
253
+ obtain ⟨y, hy, hxy⟩ := hcover x hxR hxL
254
+ exact mem_iUnion₂.mpr ⟨y, hy, hxy⟩
255
+ calc
256
+ _ ≤ μ (⋃ y ∈ s, Metric.closedBall (c y) (2*t)) := measure_mono_ae hsub
257
+ _ ≤ ∑ y ∈ s, μ (Metric.closedBall (c y) (2*t)) := measure_biUnion_finset_le _ _
258
+ _ ≤ ∑ _y ∈ s, ENNReal.ofReal (H*(2*t)^β) :=
259
+ Finset.sum_le_sum fun y _ => hball (c y) _ (by positivity)
260
+ _ = (s.card : ℝ≥0∞) * ENNReal.ofReal (H*(2*t)^β) := by simp
261
+ _ ≤ ENNReal.ofReal ((3*R/t)^Module.finrank ℝ L.direction) *
262
+ ENNReal.ofReal (H*(2*t)^β) := by
263
+ gcongr
264
+ exact_mod_cast ENNReal.ofReal_le_ofReal hcard
265
+ _ = _ := by
266
+ rw [← ENNReal.ofReal_mul (by positivity)]
267
+ congr 1
268
+ calc
269
+ _ = H * ((3*R/t)^Module.finrank ℝ L.direction * (2*t)^β) := by ring
270
+ _ = _ := by rw [ambient_tube_radius_factors _ _ ht]; ring
271
+
272
+ omit [BorelSpace E] in
273
+ lemma ambient_mass_bound {μ : Measure E} {H β R : ℝ} {z : E}
274
+ (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
275
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
276
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) :
277
+ μ univ ≤ ENNReal.ofReal (H * R^β) := by
278
+ calc
279
+ _ ≤ μ (Metric.closedBall z R) := by
280
+ apply measure_mono_ae
281
+ filter_upwards [μ.support_mem_ae] with x hx
282
+ intro _
283
+ exact hsupport hx
284
+ _ ≤ _ := hball z R hR
285
+
286
+ lemma ambient_tube_scaled {μ : Measure E} {H β R : ℝ} {z : E}
287
+ (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
288
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
289
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β))
290
+ (L : AffineSubspace ℝ E) [Nonempty L] {t : ℝ} (ht : 0 < t) (ht1 : t ≤ 1) :
291
+ μ {x | Metric.infDist x L ≤ R*t} ≤ ENNReal.ofReal
292
+ (((3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H * R^β) *
293
+ t^(β-(Module.finrank ℝ L.direction:ℝ))) := by
294
+ refine (ambient_tube hR hsupport hball L (mul_pos hR ht)
295
+ (by nlinarith)).trans_eq ?_
296
+ congr 1
297
+ rw [Real.mul_rpow hR.le ht.le]
298
+ have heq : R^Module.finrank ℝ L.direction * R^(β-(Module.finrank ℝ L.direction:ℝ)) = R^β := by
299
+ rw [← Real.rpow_natCast, ← Real.rpow_add hR]
300
+ congr 1
301
+ ring
302
+ calc
303
+ _ = ((3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H) *
304
+ (R^Module.finrank ℝ L.direction * R^(β-(Module.finrank ℝ L.direction:ℝ))) *
305
+ t^(β-(Module.finrank ℝ L.direction:ℝ)) := by ring
306
+ _ = _ := by rw [heq]
307
+
308
+ lemma ambient_inverse_moment {μ : Measure E} {H β R : ℝ} {z : E}
309
+ (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
310
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
311
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β))
312
+ (L : AffineSubspace ℝ E) [Nonempty L] {m : ℕ} (hm : 0 < m)
313
+ (hgap : (Module.finrank ℝ L.direction:ℝ) + (m:ℝ) < β) :
314
+ (∀ᵐ x ∂μ, 0 < Metric.infDist x L) ∧
315
+ (∫⁻ x, (ENNReal.ofReal (Metric.infDist x L)) ^ (-(m:ℝ)) ∂μ) ≤
316
+ ENNReal.ofReal (J β m (Module.finrank ℝ L.direction) * H * R^(β-(m:ℝ))) := by
317
+ have hm' : (0:ℝ) < m := by exact_mod_cast hm
318
+ have hi := sharp_inverse_scaled μ (fun x => Metric.infDist x L)
319
+ (Metric.continuous_infDist_pt _).measurable (fun _ => Metric.infDist_nonneg)
320
+ hm' (show (m:ℝ) < β-(Module.finrank ℝ L.direction:ℝ) by linarith)
321
+ (show 0 ≤ H*R^β by positivity)
322
+ (show 0 ≤ (3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H * R^β by positivity)
323
+ hR (ambient_mass_bound hR hsupport hball)
324
+ (fun t ht ht1 => ambient_tube_scaled hR hsupport hball L ht ht1)
325
+ refine ⟨hi.1, hi.2.trans_eq ?_⟩
326
+ congr 1
327
+ have heq : H*R^β + ((3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H * R^β) *
328
+ (m:ℝ)/(β-(Module.finrank ℝ L.direction:ℝ)-(m:ℝ)) =
329
+ J β m (Module.finrank ℝ L.direction) * H * R^β := by
330
+ unfold J
331
+ ring
332
+ rw [heq, mul_assoc, ← Real.rpow_add hR]
333
+ congr 2
334
+
335
+ end AmbientMoments
336
+
337
+ lemma J_pos {β : ℝ} {m j : ℕ} (hgap : (j:ℝ)+(m:ℝ)<β) : 0 < J β m j := by
338
+ unfold J
339
+ have hd : 0 < β-(j:ℝ)-(m:ℝ) := by linarith
340
+ positivity
341
+
342
+ lemma J_mono {β : ℝ} {m j k : ℕ} (hjk : j ≤ k)
343
+ (hgap : (k:ℝ)+(m:ℝ)<β) : J β m j ≤ J β m k := by
344
+ have hjk' : (j:ℝ) ≤ k := by exact_mod_cast hjk
345
+ unfold J
346
+ apply add_le_add le_rfl
347
+ apply div_le_div₀
348
+ · positivity
349
+ · gcongr
350
+ norm_num
351
+ · linarith
352
+ · linarith
353
+
354
+ section ReplicaExact
355
+ variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
356
+ [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
357
+ open NoiselessRegression InnerProductSpace
358
+
359
+ lemma ambient_inverse_moment_le {μ : Measure E} {H β R : ℝ} {z : E}
360
+ (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
361
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
362
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β))
363
+ (L : AffineSubspace ℝ E) [Nonempty L] {m k : ℕ} (hm : 0 < m)
364
+ (hdim : Module.finrank ℝ L.direction ≤ k) (hgap : (k:ℝ)+(m:ℝ)<β) :
365
+ (∫⁻ x, ENNReal.ofReal ((Metric.infDist x L)⁻¹ ^ m) ∂μ) ≤
366
+ ENNReal.ofReal (J β m k * H * R^(β-(m:ℝ))) := by
367
+ have hdim' : (Module.finrank ℝ L.direction:ℝ) ≤ k := by exact_mod_cast hdim
368
+ obtain ⟨ha, hi⟩ := ambient_inverse_moment hH hR hsupport hball L hm (by linarith)
369
+ calc
370
+ _ = ∫⁻ x, (ENNReal.ofReal (Metric.infDist x L)) ^ (-(m:ℝ)) ∂μ := by
371
+ apply lintegral_congr_ae
372
+ filter_upwards [ha] with x hx
373
+ rw [ENNReal.ofReal_rpow_of_pos hx, Real.rpow_neg hx.le, Real.rpow_natCast, inv_pow]
374
+ _ ≤ ENNReal.ofReal (J β m (Module.finrank ℝ L.direction) * H * R^(β-(m:ℝ))) := hi
375
+ _ ≤ _ := by
376
+ apply ENNReal.ofReal_le_ofReal
377
+ gcongr
378
+ exact J_mono hdim hgap
379
+
380
+ lemma replica_integral_exact {μ : Measure E} [IsFiniteMeasure μ] {H β R : ℝ} {z : E}
381
+ (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
382
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
383
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β))
384
+ {m : ℕ} (hm : 0 < m) (p : E) (n : ℕ)
385
+ (hgap : (n:ℝ)+(m:ℝ)-1<β) :
386
+ (∫⁻ v : Fin n → E, replicaWeight m p v ∂Measure.pi (fun _ => μ)) ≤
387
+ ∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ))) := by
388
+ induction n with
389
+ | zero => simp [replicaWeight]
390
+ | succ n ih =>
391
+ have hngap : (n:ℝ)+(m:ℝ)<β := by push_cast at hgap; linarith
392
+ have hinner (v : Fin n → E) :
393
+ (∫⁻ x, replicaWeight m p (Fin.snoc v x) ∂μ) ≤
394
+ replicaWeight m p v * ENNReal.ofReal (J β m n * H * R^(β-(m:ℝ))) := by
395
+ simp_rw [replicaWeight_snoc]
396
+ rw [lintegral_const_mul _ (by fun_prop)]
397
+ apply mul_le_mul' le_rfl
398
+ apply ambient_inverse_moment_le hH hR hsupport hball _ hm _ hngap
399
+ rw [AffineSubspace.direction_mk']
400
+ simpa only [Fintype.card_fin, Set.finrank] using
401
+ finrank_range_le_card (R := ℝ) (fun i : Fin n => v i - p)
402
+ calc
403
+ _ = ∫⁻ v : Fin n → E, ∫⁻ x, replicaWeight m p (Fin.snoc v x) ∂μ
404
+ ∂Measure.pi (fun _ => μ) := lintegral_pi_snoc μ _ (measurable_replicaWeight m p (n+1))
405
+ _ ≤ ∫⁻ v : Fin n → E, replicaWeight m p v *
406
+ ENNReal.ofReal (J β m n * H * R^(β-(m:ℝ))) ∂Measure.pi (fun _ => μ) :=
407
+ lintegral_mono hinner
408
+ _ = (∫⁻ v : Fin n → E, replicaWeight m p v ∂Measure.pi (fun _ => μ)) *
409
+ ENNReal.ofReal (J β m n * H * R^(β-(m:ℝ))) :=
410
+ lintegral_mul_const _ (measurable_replicaWeight m p n)
411
+ _ ≤ (∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ)))) *
412
+ ENNReal.ofReal (J β m n * H * R^(β-(m:ℝ))) :=
413
+ mul_le_mul' (ih (by linarith)) le_rfl
414
+ _ = _ := by rw [Fin.prod_univ_castSucc]; rfl
415
+
416
+ lemma ae_replica_nondegenerate_exact {μ : Measure E} [IsFiniteMeasure μ] {H β R : ℝ} {z : E}
417
+ (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
418
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
419
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β))
420
+ {m : ℕ} (hm : 0 < m) (p : E) (n : ℕ)
421
+ (hgap : (n:ℝ)+(m:ℝ)-1<β) :
422
+ ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => μ),
423
+ ∀ i, gramSchmidt ℝ (fun j => v j-p) i ≠ 0 := by
424
+ induction n with
425
+ | zero => exact Filter.Eventually.of_forall fun _ i => Fin.elim0 i
426
+ | succ n ih =>
427
+ rw [ae_pi_snoc μ (measurableSet_gramSchmidt_ne_zero p (n+1))]
428
+ have hngap : (n:ℝ)+(m:ℝ)<β := by push_cast at hgap; linarith
429
+ filter_upwards [ih (by linarith)] with v hv
430
+ let L := AffineSubspace.mk' p (Submodule.span ℝ (Set.range (fun i : Fin n => v i-p)))
431
+ have hdim : (Module.finrank ℝ L.direction:ℝ) ≤ n := by
432
+ dsimp [L]
433
+ rw [AffineSubspace.direction_mk']
434
+ have hh := finrank_range_le_card (R := ℝ) (fun i : Fin n => v i-p)
435
+ simp only [Fintype.card_fin, Set.finrank] at hh
436
+ exact_mod_cast hh
437
+ have ha := (ambient_inverse_moment hH hR hsupport hball L hm (by linarith)).1
438
+ filter_upwards [ha] with x hx
439
+ intro i
440
+ induction i using Fin.lastCases with
441
+ | last =>
442
+ apply norm_ne_zero_iff.mp
443
+ rw [norm_gramSchmidt_sub_eq_affine_infDist, image_Iio_last]
444
+ simp only [Fin.snoc_castSucc, Fin.snoc_last]
445
+ exact hx.ne'
446
+ | cast j => simpa only [gramSchmidt_castSucc, Fin.snoc_castSucc] using hv j
447
+
448
+ lemma measurable_joint_replicaWeight (m n : ℕ) :
449
+ Measurable (fun v : E × (Fin n → E) => replicaWeight m v.1 v.2) := by
450
+ have hs : Measurable (fun v : E × (Fin n → E) => fun j => v.2 j-v.1) := by fun_prop
451
+ exact Finset.measurable_prod _ fun i _ =>
452
+ (((measurable_gramSchmidt i).comp hs).norm.inv.pow_const m).ennreal_ofReal
453
+
454
+ lemma ae_joint_replica_independent {μ : Measure E} [IsFiniteMeasure μ] {H β R : ℝ} {z : E}
455
+ (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
456
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
457
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β))
458
+ {m : ℕ} (hm : 0 < m) (n : ℕ)
459
+ (hgap : (n:ℝ)+(m:ℝ)-1<β) :
460
+ ∀ᵐ v : E × (Fin n → E) ∂μ.prod (Measure.pi (fun _ => μ)),
461
+ LinearIndependent ℝ (fun j => v.2 j-v.1) := by
462
+ have hmeas : MeasurableSet {v : E × (Fin n → E) |
463
+ ∀ i, gramSchmidt ℝ (fun j => v.2 j-v.1) i ≠ 0} := by
464
+ rw [Set.ofPred_forall]
465
+ apply MeasurableSet.iInter
466
+ intro i
467
+ have h := (measurable_gramSchmidt i).comp
468
+ (show Measurable (fun v : E × (Fin n → E) => fun j => v.2 j-v.1) by fun_prop)
469
+ exact (measurableSet_eq_fun h measurable_const).compl
470
+ have ha : ∀ᵐ v : E × (Fin n → E) ∂μ.prod (Measure.pi (fun _ => μ)),
471
+ ∀ i, gramSchmidt ℝ (fun j => v.2 j-v.1) i ≠ 0 := by
472
+ rw [Measure.ae_prod_iff_ae_ae hmeas]
473
+ exact Filter.Eventually.of_forall fun p =>
474
+ ae_replica_nondegenerate_exact hH hR hsupport hball hm p n hgap
475
+ filter_upwards [ha] with v hv
476
+ apply Matrix.linearIndependent_of_det_gram_ne_zero
477
+ rw [det_gram_eq_prod_gramSchmidt]
478
+ exact Finset.prod_ne_zero_iff.mpr fun i _ => pow_ne_zero _ (norm_ne_zero_iff.mpr (hv i))
479
+
480
+ lemma joint_replica_integral_exact {μ : Measure E} [IsFiniteMeasure μ] {H β R : ℝ} {z : E}
481
+ (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R)
482
+ (hball : ∀ x : E, ∀ r : ℝ, 0 < r →
483
+ μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β))
484
+ {m : ℕ} (hm : 0 < m) (n : ℕ)
485
+ (hgap : (n:ℝ)+(m:ℝ)-1<β) :
486
+ (∫⁻ v : E × (Fin n → E), replicaWeight m v.1 v.2
487
+ ∂μ.prod (Measure.pi (fun _ => μ))) ≤
488
+ ENNReal.ofReal (H^(n+1) * R^(β*(n+1:ℕ)-(m:ℝ)*(n:ℝ)) *
489
+ ∏ j : Fin n, J β m j) := by
490
+ have hJ (j : Fin n) : 0 < J β m j := by
491
+ apply J_pos
492
+ have hj : (j:ℝ)+1 ≤ n := by exact_mod_cast Nat.succ_le_of_lt j.isLt
493
+ linarith
494
+ have hfac (j : Fin n) : 0 ≤ J β m j * H * R^(β-(m:ℝ)) := by
495
+ exact le_of_lt (mul_pos (mul_pos (hJ j) hH) (Real.rpow_pos_of_pos hR _))
496
+ calc
497
+ _ = ∫⁻ p, ∫⁻ v : Fin n → E, replicaWeight m p v
498
+ ∂Measure.pi (fun _ => μ) ∂μ :=
499
+ lintegral_prod _ (measurable_joint_replicaWeight m n).aemeasurable
500
+ _ ≤ ∫⁻ _p, ∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ))) ∂μ :=
501
+ lintegral_mono fun p => replica_integral_exact hH hR hsupport hball hm p n hgap
502
+ _ = (∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ)))) * μ univ :=
503
+ lintegral_const _
504
+ _ ≤ (∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ)))) *
505
+ ENNReal.ofReal (H*R^β) := mul_le_mul' le_rfl (ambient_mass_bound hR hsupport hball)
506
+ _ = _ := by
507
+ rw [← ENNReal.ofReal_prod_of_nonneg (fun j _ => hfac j),
508
+ ← ENNReal.ofReal_mul (Finset.prod_nonneg fun j _ => hfac j)]
509
+ congr 1
510
+ simp only [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin]
511
+ rw [← Real.rpow_mul_natCast hR.le]
512
+ have heq : R^((β-(m:ℝ))*(n:ℝ)) * R^β =
513
+ R^(β*(n+1:ℕ)-(m:ℝ)*(n:ℝ)) := by
514
+ rw [← Real.rpow_add hR]
515
+ congr 1
516
+ push_cast
517
+ ring
518
+ calc
519
+ _ = (H^n*H) * (R^((β-(m:ℝ))*(n:ℝ)) * R^β) * ∏ j : Fin n, J β m j := by ring
520
+ _ = _ := by rw [← pow_succ, heq]
521
+
522
+ end ReplicaExact
523
+
524
+ lemma specialized_J_bound (d m p : ℕ) (hd : 16 ≤ d) (hp : p=d/8)
525
+ (_ : 1 ≤ m) (hmp : m ≤ p) (β : ℝ)
526
+ (hβlo : ((d:ℝ)-1)/2 ≤ β) (hβhi : β ≤ (d:ℝ)/2) :
527
+ ∀ j : ℕ, j ≤ p-2 →
528
+ ((d:ℝ)-1)/2 - 2*(p:ℝ) + 2 ≤ β-(j:ℝ)-(m:ℝ) ∧
529
+ (d:ℝ)/4 + 3/2 ≤ ((d:ℝ)-1)/2 - 2*(p:ℝ) + 2 ∧
530
+ J β m j ≤ (7:ℝ)^d := by
531
+ have hp2 : 2 ≤ p := by omega
532
+ have hp8 : p*8 ≤ d := by rw [hp]; exact Nat.div_mul_le_self d 8
533
+ have hp8' : (p:ℝ)*8 ≤ d := by exact_mod_cast hp8
534
+ have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd
535
+ have hm' : (m:ℝ) ≤ p := by exact_mod_cast hmp
536
+ intro j hj
537
+ have hj' : (j:ℝ)+2 ≤ p := by exact_mod_cast (show j+2 ≤ p by omega)
538
+ have hmargin : ((d:ℝ)-1)/2-2*(p:ℝ)+2 ≤ β-(j:ℝ)-(m:ℝ) := by linarith
539
+ have hdim : (d:ℝ)/4+3/2 ≤ ((d:ℝ)-1)/2-2*(p:ℝ)+2 := by linarith
540
+ refine ⟨hmargin, hdim, ?_⟩
541
+ have hgap : 0 < β-(j:ℝ)-(m:ℝ) := by linarith
542
+ have hquot : (m:ℝ)/(β-(j:ℝ)-(m:ℝ)) ≤ 1 := by
543
+ rw [div_le_one hgap]
544
+ linarith
545
+ have h3 : (3:ℝ)^j ≤ (3:ℝ)^d := by
546
+ apply pow_le_pow_right₀ (by norm_num)
547
+ omega
548
+ have h2 : (2:ℝ)^β ≤ (2:ℝ)^d := by
549
+ rw [← Real.rpow_natCast]
550
+ apply Real.rpow_le_rpow_of_exponent_le (by norm_num)
551
+ linarith
552
+ calc
553
+ J β m j = 1 + (3:ℝ)^j * (2:ℝ)^β * ((m:ℝ)/(β-(j:ℝ)-(m:ℝ))) := by unfold J; ring
554
+ _ ≤ 1 + (3:ℝ)^j * (2:ℝ)^β * 1 := by gcongr
555
+ _ ≤ 1 + (3:ℝ)^d * (2:ℝ)^d := by rw [mul_one]; gcongr
556
+ _ = 1 + (6:ℝ)^d := by rw [← mul_pow]; norm_num
557
+ _ ≤ (7:ℝ)^d := by
558
+ simpa only [one_pow, show (1:ℝ)+6=7 by norm_num] using pow_add_pow_le (show (0:ℝ) ≤ 1 by norm_num)
559
+ (show (0:ℝ) ≤ 6 by norm_num) (show d ≠ 0 by omega)
560
+
561
+ lemma specialized_gram_product_bound (d m p : ℕ) (hd : 16 ≤ d) (hp : p=d/8)
562
+ (hm : 1 ≤ m) (hmp : m ≤ p) (β : ℝ)
563
+ (hβlo : ((d:ℝ)-1)/2 ≤ β) (hβhi : β ≤ (d:ℝ)/2)
564
+ (H R : ℝ) (hH : 0 < H) (hR : 0 < R) :
565
+ H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) * (∏ j : Fin (p-1), J β m j) ≤
566
+ (7:ℝ)^(d*(p-1)) * H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) := by
567
+ have hp2 : 2 ≤ p := by omega
568
+ have hs := specialized_J_bound d m p hd hp hm hmp β hβlo hβhi
569
+ have hprod : (∏ j : Fin (p-1), J β m j) ≤ (7:ℝ)^(d*(p-1)) := by
570
+ calc
571
+ _ ≤ ∏ _j : Fin (p-1), (7:ℝ)^d := by
572
+ apply Finset.prod_le_prod₀
573
+ · intro j _
574
+ apply (J_pos ?_).le
575
+ have hh := hs j (by have := j.isLt; omega)
576
+ have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd
577
+ linarith [hh.1, hh.2.1]
578
+ · intro j _
579
+ exact (hs j (by have := j.isLt; omega)).2.2
580
+ _ = _ := by simp [← pow_mul]
581
+ calc
582
+ _ ≤ H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) * (7:ℝ)^(d*(p-1)) := by gcongr
583
+ _ = _ := by ring
584
+
585
+ def AmbientGramStatement : Prop :=
586
+ let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast
587
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
588
+ let three : ℝ := @OfNat.ofNat ℝ 3 (@instOfNatAtLeastTwo ℝ 3 Real.commRing.toNatCast
589
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 1)))
590
+ let four : ℝ := @OfNat.ofNat ℝ 4 (@instOfNatAtLeastTwo ℝ 4 Real.commRing.toNatCast
591
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 2)))
592
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
593
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
594
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
595
+ (∀ (d m p : ℕ),
596
+ letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ)
597
+ letI : PseudoMetricSpace (Space d) :=
598
+ PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ)
599
+ letI : AddCommGroup (Space d) := WithLp.instAddCommGroup exponent (Fin d → ℝ)
600
+ letI : Module ℝ (Space d) := WithLp.instModule (p := exponent) (K := ℝ) (V := Fin d → ℝ)
601
+ 1 ≤ d → 1 ≤ m → 2 ≤ p →
602
+ ∀ β R H : ℝ, (m : ℝ) + (p : ℝ) - two < β → 0 < R → 0 < H →
603
+ ∀ (μ : Measure (Space d)), IsFiniteMeasure μ →
604
+ ∀ z : Space d, μ.support ⊆ Metric.closedBall z R →
605
+ AmbientBallBound μ H β →
606
+ (∀ (j : ℕ), j ≤ p-2 → ∀ L : AffineSubspace ℝ (Space d),
607
+ Nonempty L → Module.finrank ℝ L.direction = j →
608
+ (∀ t : ℝ, 0 < t → t ≤ R →
609
+ μ {s | Metric.infDist s L ≤ t} ≤
610
+ ENNReal.ofReal (three^j * two^β * H * R^j * t^(β-(j:ℝ)))) ∧
611
+ (∫⁻ s, (ENNReal.ofReal (Metric.infDist s L)) ^ (-(m:ℝ)) ∂μ) ≤
612
+ ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ)))) ∧
613
+ (∀ᵐ v : Space d × (Fin (p-1) → Space d)
614
+ ∂μ.prod (Measure.pi (fun _ : Fin (p-1) => μ)),
615
+ LinearIndependent ℝ (fun i => v.2 i - v.1)) ∧
616
+ (∫⁻ v : Space d × (Fin (p-1) → Space d), InverseGram m v
617
+ ∂μ.prod (Measure.pi (fun _ : Fin (p-1) => μ))) ≤
618
+ ENNReal.ofReal (H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) *
619
+ ∏ j : Fin (p-1), J β m j)) ∧
620
+ (∃ C : ℝ, 1 ≤ C ∧ ∀ (d m p : ℕ), 16 ≤ d → p = d/8 →
621
+ 1 ≤ m → m ≤ p → ∀ β : ℝ, ((d:ℝ)-1)/two ≤ β → β ≤ (d:ℝ)/two →
622
+ (∀ j : ℕ, j ≤ p-2 →
623
+ ((d:ℝ)-1)/two - two*(p:ℝ) + two ≤ β-(j:ℝ)-(m:ℝ) ∧
624
+ (d:ℝ)/four + three/two ≤ ((d:ℝ)-1)/two - two*(p:ℝ) + two ∧
625
+ J β m j ≤ C^d) ∧
626
+ (∀ H R : ℝ, 0 < H → 0 < R →
627
+ H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) * (∏ j : Fin (p-1), J β m j) ≤
628
+ C^(d*(p-1)) * H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ))))
629
+
630
+ theorem ambient_gram : AmbientGramStatement := by
631
+ constructor
632
+ · intro d m p _hd hm hp β R H hβ hR hH μ hfin z hsupport hball
633
+ let : IsFiniteMeasure μ := hfin
634
+ have hm0 : 0 < m := by omega
635
+ have hp1 : 1 ≤ p := by omega
636
+ have hgap : ((p-1:ℕ):ℝ)+(m:ℝ)-1<β := by
637
+ rw [Nat.cast_sub hp1]
638
+ push_cast
639
+ linarith
640
+ refine ⟨?_, ?_, ?_⟩
641
+ · intro j hj L hnonempty hdim
642
+ let : Nonempty L := hnonempty
643
+ have hj' : (j:ℝ)+2 ≤ p := by exact_mod_cast (show j+2 ≤ p by omega)
644
+ constructor
645
+ · intro t ht htR
646
+ simpa only [hdim] using ambient_tube hR hsupport hball L ht htR
647
+ · have hi := (ambient_inverse_moment hH hR hsupport hball L hm0
648
+ (by rw [hdim]; linarith)).2
649
+ simpa only [hdim] using hi
650
+ · exact ae_joint_replica_independent hH hR hsupport hball hm0 (p-1) hgap
651
+ · have hi := joint_replica_integral_exact hH hR hsupport hball hm0 (p-1) hgap
652
+ simpa only [NoiselessRegression.replicaWeight_eq_det, InverseGram,
653
+ Nat.sub_add_cancel hp1] using hi
654
+ · refine ⟨7, by norm_num, ?_⟩
655
+ intro d m p hd hp hm hmp β hβlo hβhi
656
+ exact ⟨specialized_J_bound d m p hd hp hm hmp β hβlo hβhi,
657
+ specialized_gram_product_bound d m p hd hp hm hmp β hβlo hβhi⟩
658
+
659
+ end MemoryPrecision
660
+
661
+
662
+ end
663
+
664
+ end OAI
lean/OAI/Probability/MemoryPrecision/BallAverages.lean ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.RadialMixture
4
+
5
+ namespace OAI
6
+
7
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
8
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
9
+
10
+ noncomputable section
11
+ universe u v
12
+
13
+ open MeasureTheory ProbabilityTheory Set Filter
14
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
15
+ namespace MemoryPrecision
16
+ open NoiselessRegression
17
+
18
+ lemma gaussianKernel_scale (m : ℕ) {δ : ℝ} (hδ : 0 < δ) (y : Space m) :
19
+ GaussianKernel m δ (δ • y) = δ⁻¹ ^ m * GaussianKernel m 1 y := by
20
+ have he (a : ℝ) : gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (δ*a) =
21
+ δ⁻¹ * gaussianPDFReal 0 1 a := by
22
+ have h := gaussianPDFReal_inv_mul (μ := 0) (v := 1) hδ.ne' (δ*a)
23
+ simp only [inv_mul_cancel_left₀ hδ.ne', mul_zero, mul_one, abs_of_pos hδ] at h
24
+ rw [h]
25
+ field_simp
26
+ rfl
27
+ unfold GaussianKernel
28
+ simp only [PiLp.smul_apply, smul_eq_mul, one_pow]
29
+ simp_rw [he]
30
+ simp only [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin]
31
+ rfl
32
+
33
+ lemma radialMixture_scale (m : ℕ) {δ : ℝ} (hδ : 0 < δ) (r : ℝ) :
34
+ RadialMixture m δ (δ*r) = δ⁻¹ * RadialMixture m 1 r := by
35
+ unfold RadialMixture
36
+ rw [mul_smul, gaussianKernel_scale m hδ]
37
+ simp only [one_pow, div_one, mul_pow, inv_pow]
38
+ field_simp
39
+
40
+ def BallAverage {m : ℕ} (ν : Measure (Space m)) (y : Space m) (r : ℝ) : ℝ :=
41
+ (ν (Metric.ball y r)).toReal / (UnitBallVolume m * r^m)
42
+
43
+ lemma ballAverage_measurable {m : ℕ} (ν : Measure (Space m)) (y : Space m) :
44
+ Measurable (BallAverage ν y) := by
45
+ have h : Monotone (fun r : ℝ => ν (Metric.ball y r)) := fun r t h =>
46
+ measure_mono (Metric.ball_subset_ball h)
47
+ exact h.measurable.ennreal_toReal.div (by fun_prop)
48
+
49
+ lemma ballAverage_nonneg {m : ℕ} (ν : Measure (Space m)) (y : Space m) {r : ℝ}
50
+ (hr : 0 < r) : 0 ≤ BallAverage ν y r := by
51
+ exact div_nonneg ENNReal.toReal_nonneg (mul_nonneg (unitBallVolume_pos m).le
52
+ (pow_nonneg hr.le _))
53
+
54
+ lemma ac_ball_eq_closedBall {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m))
55
+ (hν : ν ≪ volume) (y : Space m) (r : ℝ) :
56
+ ν (Metric.ball y r) = ν (Metric.closedBall y r) := by
57
+ have : NeZero m := ⟨by omega⟩
58
+ apply measure_eq_measure_of_null_sdiff Metric.ball_subset_closedBall
59
+ rw [Metric.closedBall_sdiff_ball]
60
+ exact hν (Measure.addHaar_sphere volume y r)
61
+
62
+ lemma ae_tendsto_ballAverage {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m))
63
+ [IsFiniteMeasure ν] (hν : ν ≪ volume) :
64
+ ∀ᵐ y ∂(volume : Measure (Space m)), Tendsto (BallAverage ν y)
65
+ (𝓝[>] (0:ℝ)) (𝓝 ((ν.rnDeriv volume y).toReal)) := by
66
+ have : NeZero m := ⟨by omega⟩
67
+ filter_upwards [Besicovitch.ae_tendsto_rnDeriv ν volume, ν.rnDeriv_lt_top volume] with y hy hyfin
68
+ have ht := (ENNReal.continuousAt_toReal hyfin.ne).tendsto.comp hy
69
+ apply ht.congr'
70
+ filter_upwards [self_mem_nhdsWithin] with r hr
71
+ unfold BallAverage
72
+ simp only [Function.comp_apply]
73
+ rw [ENNReal.toReal_div, Measure.addHaar_closedBall_eq_addHaar_ball volume y r,
74
+ ← ac_ball_eq_closedBall hm ν hν y r, volume_ball_eq m hm y hr,
75
+ ENNReal.toReal_ofReal (mul_nonneg (unitBallVolume_pos m).le (pow_nonneg hr.le _))]
76
+
77
+ lemma ballAverage_bounded {m : ℕ} (ν : Measure (Space m)) [IsFiniteMeasure ν]
78
+ (y : Space m) {f : ℝ} (hf : 0 ≤ f)
79
+ (ht : Tendsto (BallAverage ν y) (𝓝[>] (0:ℝ)) (𝓝 f)) :
80
+ ∃ B : ℝ, 0 ≤ B ∧ ∀ r : ℝ, 0 < r → ‖BallAverage ν y r‖ ≤ B := by
81
+ rcases Metric.tendsto_nhdsWithin_nhds.mp ht 1 zero_lt_one with ⟨b,hb,hnear⟩
82
+ let C : ℝ := max (f+1) ((ν Set.univ).toReal / (UnitBallVolume m * b^m))
83
+ refine ⟨C, le_trans (by linarith : 0 ≤ f+1) (le_max_left _ _), ?_⟩
84
+ intro r hr
85
+ rw [Real.norm_eq_abs, abs_of_nonneg (ballAverage_nonneg ν y hr)]
86
+ by_cases h : r < b
87
+ · have he := hnear hr (by simpa [Real.dist_eq, abs_of_pos hr] using h)
88
+ have he' : BallAverage ν y r < f+1 := by
89
+ rw [Real.dist_eq] at he
90
+ have := (abs_lt.mp he).2
91
+ linarith
92
+ exact he'.le.trans (le_max_left _ _)
93
+ · apply le_trans ?_ (le_max_right _ _)
94
+ unfold BallAverage
95
+ have hvol : 0 < UnitBallVolume m := unitBallVolume_pos m
96
+ apply div_le_div₀ (by positivity) ?_ (by positivity) ?_
97
+ · exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) (measure_ne_top _ _)).mpr
98
+ (measure_mono (Set.subset_univ _))
99
+ · exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ hb.le (le_of_not_gt h) _)
100
+ (unitBallVolume_pos m).le
101
+
102
+ lemma tendsto_radial_average {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m)) [IsFiniteMeasure ν]
103
+ (y : Space m) {f : ℝ} (hf : 0 ≤ f)
104
+ (ht : Tendsto (BallAverage ν y) (𝓝[>] (0:ℝ)) (𝓝 f)) :
105
+ Tendsto (fun δ : ℝ => ∫ r in Ioi 0, RadialMixture m 1 r * BallAverage ν y (δ*r))
106
+ (𝓝[>] (0:ℝ)) (𝓝 f) := by
107
+ obtain ⟨B,hB,hbound⟩ := ballAverage_bounded ν y hf ht
108
+ have hw : IntegrableOn (RadialMixture m 1) (Ioi 0) :=
109
+ integrable_of_integral_eq_one (radialMixture_integral m hm zero_lt_one)
110
+ have hl := tendsto_integral_filter_of_dominated_convergence
111
+ (μ := volume.restrict (Ioi 0)) (l := 𝓝[>] (0:ℝ))
112
+ (F := fun δ r => RadialMixture m 1 r * BallAverage ν y (δ*r))
113
+ (f := fun r => RadialMixture m 1 r * f)
114
+ (fun r => RadialMixture m 1 r * B)
115
+ (Eventually.of_forall (fun δ =>
116
+ ((radialMixture_measurable m 1).mul ((ballAverage_measurable ν y).comp
117
+ (by fun_prop))).aestronglyMeasurable))
118
+ (show ∀ᶠ δ in 𝓝[>] (0:ℝ), ∀ᵐ r ∂volume.restrict (Ioi 0),
119
+ ‖RadialMixture m 1 r * BallAverage ν y (δ*r)‖ ≤ RadialMixture m 1 r * B from by
120
+ filter_upwards [self_mem_nhdsWithin] with δ hδ
121
+ filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr
122
+ rw [norm_mul, Real.norm_eq_abs, abs_of_nonneg (radialMixture_nonneg m 1 hr)]
123
+ exact mul_le_mul_of_nonneg_left (hbound _ (mul_pos hδ hr)) (radialMixture_nonneg m 1 hr))
124
+ (hw.mul_const B) (show ∀ᵐ r ∂volume.restrict (Ioi 0),
125
+ Tendsto (fun δ => RadialMixture m 1 r * BallAverage ν y (δ*r))
126
+ (𝓝[>] (0:ℝ)) (𝓝 (RadialMixture m 1 r * f)) from by
127
+ filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr
128
+ apply Tendsto.const_mul
129
+ apply ht.comp
130
+ apply tendsto_nhdsWithin_iff.mpr
131
+ refine ⟨?_, ?_⟩
132
+ · simpa using ((continuous_id.mul_const r).tendsto (0:ℝ)).mono_left nhdsWithin_le_nhds
133
+ · filter_upwards [self_mem_nhdsWithin] with δ hδ
134
+ change 0 < δ*r
135
+ exact mul_pos hδ hr)
136
+ simpa only [integral_mul_const, radialMixture_integral m hm zero_lt_one, one_mul] using hl
137
+ end MemoryPrecision
138
+
139
+
140
+ end
141
+
142
+ end OAI
lean/OAI/Probability/MemoryPrecision/CoefficientStep.lean ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.KernelModel
4
+ import OAI.Probability.MemoryPrecision.WeightedImage
5
+ import OAI.Probability.MemoryPrecision.WeightedSelection
6
+
7
+ namespace OAI
8
+
9
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
10
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
11
+
12
+ noncomputable section
13
+ universe u v
14
+
15
+
16
+ open MeasureTheory ProbabilityTheory Set Filter
17
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
18
+ namespace MemoryPrecision
19
+ abbrev Sphere (d : ℕ) := Metric.sphere (0 : Space d) 1
20
+ def SpherePrior (d : ℕ) : Measure (Sphere d) :=
21
+ MemoryPrecision.Kernel.UniformSphere d
22
+
23
+ def SphereBallBound {d : ℕ} (h : Sphere d → ℝ≥0∞) (H α : ℝ) : Prop :=
24
+ ∀ z : Space d, ∀ r : ℝ, 0 < r →
25
+ (∫⁻ s in {s : Sphere d | dist s.val z ≤ r}, h s ∂SpherePrior d) ≤
26
+ ENNReal.ofReal (H * r^α)
27
+ def SphereBlock {d m N : ℕ} (h : Fin N → Sphere d → ℝ≥0∞)
28
+ (g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞)
29
+ (s : Sphere d) : ℝ≥0∞ :=
30
+ WeightedBlock Subtype.val h g s
31
+ def CoefficientStepStatement : Prop :=
32
+ let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast
33
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
34
+ ∃ C : ℝ, 1 ≤ C ∧ ∀ d m N : ℕ, 16 ≤ d →
35
+ 1 ≤ m → m ≤ d/8 → 1 ≤ N →
36
+ ∀ α H : ℝ, ((d:ℝ)-1)/two ≤ α → α ≤ (d:ℝ)/two → 0 < H →
37
+ ∀ h : Fin N → Sphere d → ℝ≥0∞,
38
+ (∀ w, Measurable (h w)) → (∀ w s, h w s ≤ 1) →
39
+ (∀ w, SphereBallBound (h w) H α) →
40
+ ∀ g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞,
41
+ (∀ w, Measurable (g w)) → (∀ x, ∑ w, g w x ≤ 1) →
42
+ SphereBallBound (SphereBlock h g) (C^d * (N:ℝ)^(1/((d/8:ℕ):ℝ)) * H) α
43
+
44
+ theorem coefficient_step : CoefficientStepStatement := by
45
+ refine ⟨1344, by norm_num, ?_⟩
46
+ intro d m N hd hm hmp hN α H hαlo hαhi hH h hh hh1 hb g hg hgsum z r hr
47
+ have : NeZero d := ⟨by omega⟩
48
+ have : IsProbabilityMeasure (SpherePrior d) :=
49
+ (show IsProbabilityMeasure (NoiselessRegression.sphereLaw (E := Space d)) from inferInstance)
50
+ let ν (w : Fin N) := ((SpherePrior d).withDensity (h w)).map Subtype.val
51
+ let (w : Fin N) : IsFiniteMeasure (ν w) :=
52
+ weighted_image_finite (SpherePrior d) Subtype.val (h w) (hh1 w)
53
+ have hν (w) : AmbientBallBound (ν w) H α := by
54
+ intro x ρ hρ
55
+ rw [show ν w = ((SpherePrior d).withDensity (h w)).map Subtype.val from rfl,
56
+ weighted_image_ball _ measurable_subtype_coe]
57
+ exact hb w x ρ hρ
58
+ have hp : 2 ≤ d/8 := by omega
59
+ have hmd : m ≤ d := hmp.trans (Nat.div_le_self _ _)
60
+ have hgap : (m:ℝ)+((d/8:ℕ):ℝ)-2 < α := by
61
+ have hm' : (m:ℝ) ≤ (d/8:ℕ) := by exact_mod_cast hmp
62
+ have hp' : ((d/8:ℕ):ℝ)*8 ≤ d := by exact_mod_cast Nat.div_mul_le_self d 8
63
+ have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd
64
+ linarith
65
+ have hJ := fun j hj => (specialized_J_bound d m (d/8) hd rfl hm hmp α hαlo hαhi j hj).2.2
66
+ have hsel := localized_weighted_selection ν hp hm hmd (by norm_num : (1:ℝ) ≤ 7)
67
+ hH hgap hJ hν g hg hgsum z hr
68
+ have he := weightedBlock_mass_identity (SpherePrior d) measurable_subtype_coe hh hh1 hg
69
+ (show MeasurableSet (Metric.closedBall z r) from Metric.isClosed_closedBall.measurableSet)
70
+ change (∫⁻ s in Subtype.val ⁻¹' Metric.closedBall z r,
71
+ WeightedBlock Subtype.val h g s ∂SpherePrior d) ≤ _
72
+ rw [he]
73
+ convert hsel using 1
74
+ norm_num [ν, mul_assoc]
75
+
76
+ end MemoryPrecision
77
+
78
+
79
+ end
80
+
81
+ end OAI
lean/OAI/Probability/MemoryPrecision/CubeArithmetic.lean ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.CubeContinuation
4
+
5
+ namespace OAI
6
+
7
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
8
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
9
+
10
+ noncomputable section
11
+ universe u v
12
+
13
+
14
+ open MeasureTheory ProbabilityTheory Set Filter
15
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
16
+ namespace MemoryPrecision
17
+
18
+ lemma cube_memory_ratio {d M : ℕ} (hd : 16 ≤ d) (hM : M ≤ d^2) :
19
+ (M:ℝ) / (((d/2)/4:ℕ):ℝ) ≤ 72 * (d/2:ℕ) := by
20
+ have hd3 : d ≤ 3*(d/2) := by omega
21
+ have hn8 : d/2 ≤ 8*((d/2)/4) := by omega
22
+ have hm : M ≤ (72*(d/2))*((d/2)/4) := by
23
+ calc
24
+ M ≤ d^2 := hM
25
+ _ ≤ (3*(d/2))^2 := Nat.pow_le_pow_left hd3 2
26
+ _ = 9*(d/2)*(d/2) := by ring
27
+ _ ≤ 9*(d/2)*(8*((d/2)/4)) := Nat.mul_le_mul_left _ hn8
28
+ _ = _ := by ring
29
+ apply (div_le_iff₀ (by exact_mod_cast (show 0 < (d/2)/4 by omega))).2
30
+ exact_mod_cast hm
31
+
32
+ lemma cube_memory_factor {d M : ℕ} (hd : 16 ≤ d) (hM : M ≤ d^2) :
33
+ ((2^M:ℕ):ℝ)^(1/(((d/2)/4:ℕ):ℝ)) ≤ ((2:ℝ)^72)^(d/2) := by
34
+ have he : ((2^M:ℕ):ℝ)^(1/(((d/2)/4:ℕ):ℝ)) =
35
+ (2:ℝ)^((M:ℝ)/(((d/2)/4:ℕ):ℝ)) := by
36
+ rw [Nat.cast_pow, Nat.cast_ofNat, ← Real.rpow_natCast,
37
+ ← Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2)]
38
+ congr 1
39
+ ring
40
+ rw [he, ← pow_mul, ← Real.rpow_natCast]
41
+ apply Real.rpow_le_rpow_of_exponent_le (by norm_num : (1:ℝ) ≤ 2)
42
+ simpa using cube_memory_ratio hd hM
43
+
44
+ lemma cube_stopping_factor {d : ℕ} (hd : 16 ≤ d) (T : ℕ) :
45
+ (T+1:ℝ) ≤ ((2:ℝ)^(d/2))^BlockCount T ((d/2)/4) := by
46
+ have hT := blockCount_mul_ge T (by omega : 0 < (d/2)/4)
47
+ have hp : (d/2)/4 ≤ d/2 := Nat.div_le_self _ _
48
+ have hTn : T ≤ (d/2) * BlockCount T ((d/2)/4) := by nlinarith
49
+ have htwo : (T+1:ℕ) ≤ 2^T := Nat.lt_two_pow_self
50
+ have hpow : (2:ℝ)^T ≤ 2^((d/2) * BlockCount T ((d/2)/4)) :=
51
+ pow_le_pow_right₀ (by norm_num) hTn
52
+ rw [pow_mul] at hpow
53
+ exact (by exact_mod_cast htwo : (T+1:ℝ) ≤ (2:ℝ)^T).trans hpow
54
+
55
+ def CubeSuccessConstant : ℝ := max 12 (2*CubeStepConstant*2^72)
56
+ lemma cubeSuccessConstant_twelve : 12 ≤ CubeSuccessConstant := le_max_left _ _
57
+ lemma cubeSuccessConstant_one : 1 ≤ CubeSuccessConstant :=
58
+ (by norm_num : (1:ℝ) ≤ 12).trans cubeSuccessConstant_twelve
59
+ lemma cubeSuccessConstant_exp : Real.exp 1 ≤ CubeSuccessConstant :=
60
+ Real.exp_one_lt_three.le.trans ((by norm_num : (3:ℝ) ≤ 12).trans cubeSuccessConstant_twelve)
61
+ lemma cubeSuccessConstant_pos : 0 < CubeSuccessConstant :=
62
+ lt_of_lt_of_le zero_lt_one cubeSuccessConstant_one
63
+
64
+ lemma cube_whole_factor {d M : ℕ} (hd : 16 ≤ d) (hM : M ≤ d^2) (T : ℕ) :
65
+ (T+1:ℝ) * ((12:ℝ)^(d/2) * CubeStep d (2^M) ^ BlockCount T ((d/2)/4)) ≤
66
+ CubeSuccessConstant^((d/2)*(BlockCount T ((d/2)/4)+1)) := by
67
+ have hC := cubeStepConstant_pos
68
+ have hD := cubeSuccessConstant_pos
69
+ have hS := cubeStep_pos d (show 1 ≤ 2^M by exact one_le_pow₀ (by norm_num))
70
+ have hmem := cube_memory_factor hd hM
71
+ have hstep : (2:ℝ)^(d/2) * CubeStep d (2^M) ≤ CubeSuccessConstant^(d/2) := by
72
+ calc
73
+ _ ≤ 2^(d/2) * (CubeStepConstant^(d/2) * ((2:ℝ)^72)^(d/2)) :=
74
+ mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hmem (by positivity)) (by positivity)
75
+ _ = (2*CubeStepConstant*2^72)^(d/2) := by simp only [mul_pow]; ring
76
+ _ ≤ _ := pow_le_pow_left₀ (by positivity) (le_max_right _ _) _
77
+ calc
78
+ _ = 12^(d/2) * ((T+1:ℝ) * CubeStep d (2^M) ^ BlockCount T ((d/2)/4)) := by ring
79
+ _ ≤ 12^(d/2) * (((2:ℝ)^(d/2))^BlockCount T ((d/2)/4) *
80
+ CubeStep d (2^M) ^ BlockCount T ((d/2)/4)) :=
81
+ mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right (cube_stopping_factor hd T) (by positivity))
82
+ (by positivity)
83
+ _ = 12^(d/2) * ((2:ℝ)^(d/2) * CubeStep d (2^M))^BlockCount T ((d/2)/4) := by rw [mul_pow]
84
+ _ ≤ CubeSuccessConstant^(d/2) * (CubeSuccessConstant^(d/2))^BlockCount T ((d/2)/4) :=
85
+ mul_le_mul (pow_le_pow_left₀ (by norm_num) cubeSuccessConstant_twelve _)
86
+ (pow_le_pow_left₀ (by positivity) hstep _) (by positivity) (by positivity)
87
+ _ = _ := by rw [pow_mul, pow_succ]; ring
88
+ end MemoryPrecision
89
+
90
+
91
+ end
92
+
93
+ end OAI
lean/OAI/Probability/MemoryPrecision/CubeBlock.lean ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.CubeGeometry
4
+ import OAI.Probability.MemoryPrecision.WeightedImage
5
+ import OAI.Probability.MemoryPrecision.WeightedSelection
6
+
7
+ namespace OAI
8
+
9
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
10
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
11
+
12
+ noncomputable section
13
+ universe u v
14
+
15
+
16
+ open MeasureTheory ProbabilityTheory Set Filter
17
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
18
+ namespace MemoryPrecision
19
+ open NoiselessRegression
20
+
21
+ lemma cube_J_bound {d k : ℕ} (hd : 16 ≤ d) (hk : k ≤ (d/2)/4) :
22
+ ∀ j : ℕ, j ≤ (d/2)/4-2 → J (3*(d/2:ℕ)/4:ℝ) k j ≤ (7:ℝ)^d := by
23
+ have hp2 : 2 ≤ (d/2)/4 := by omega
24
+ have hn4 : (((d/2)/4:ℕ):ℝ)*4 ≤ (d/2:ℕ) := by exact_mod_cast Nat.div_mul_le_self (d/2) 4
25
+ have hn : ((d/2:ℕ):ℝ) ≤ d := by exact_mod_cast Nat.div_le_self d 2
26
+ have hm : (k:ℝ) ≤ ((d/2)/4:ℕ) := by exact_mod_cast hk
27
+ intro j hj
28
+ have hj' : (j:ℝ)+2 ≤ ((d/2)/4:ℕ) := by exact_mod_cast (show j+2 ≤ (d/2)/4 by omega)
29
+ have hgap : 0 < (3*(d/2:ℕ)/4:ℝ)-(j:ℝ)-(k:ℝ) := by linarith
30
+ have hquot : (k:ℝ)/((3*(d/2:ℕ)/4:ℝ)-(j:ℝ)-(k:ℝ)) ≤ 1 := by
31
+ rw [div_le_one hgap]
32
+ linarith
33
+ have h3 : (3:ℝ)^j ≤ (3:ℝ)^d := pow_le_pow_right₀ (by norm_num) (by omega)
34
+ have h2 : (2:ℝ)^(3*(d/2:ℕ)/4:ℝ) ≤ (2:ℝ)^d := by
35
+ rw [← Real.rpow_natCast]
36
+ apply Real.rpow_le_rpow_of_exponent_le (by norm_num)
37
+ linarith
38
+ calc
39
+ J (3*(d/2:ℕ)/4:ℝ) k j = 1+(3:ℝ)^j*(2:ℝ)^(3*(d/2:ℕ)/4:ℝ)*
40
+ ((k:ℝ)/((3*(d/2:ℕ)/4:ℝ)-(j:ℝ)-(k:ℝ))) := by unfold J; ring
41
+ _ ≤ 1+(3:ℝ)^j*(2:ℝ)^(3*(d/2:ℕ)/4:ℝ)*1 := by gcongr
42
+ _ ≤ 1+(3:ℝ)^d*(2:ℝ)^d := by rw [mul_one]; gcongr
43
+ _ = 1+(6:ℝ)^d := by rw [← mul_pow]; norm_num
44
+ _ ≤ (7:ℝ)^d := by
45
+ simpa only [one_pow, show (1:ℝ)+6=7 by norm_num] using
46
+ pow_add_pow_le (show (0:ℝ) ≤ 1 by norm_num) (show (0:ℝ) ≤ 6 by norm_num) (show d ≠ 0 by omega)
47
+
48
+ lemma cube_weighted_ambient {d : ℕ} (hd : 2 ≤ d) {f : Cube d → ℝ≥0∞}
49
+ {L : ℝ} (hf : CubeLocal f L) :
50
+ AmbientBallBound (((CubeLaw d).withDensity f).map (CubeEmbedding d)) L (3*(d/2:ℕ)/4:ℝ) := by
51
+ intro x r hr
52
+ rw [weighted_image_ball _ (cubeEmbedding_measurable d)]
53
+ apply (lintegral_mono_set (show {u | dist (CubeEmbedding d u) x ≤ r} ⊆
54
+ CubeBall d (Real.sqrt (d/2:ℕ) • cubeProject d x) r from ?_)).trans
55
+ (hf _ _ hr)
56
+ intro u hu
57
+ exact (cubeProject_parameter_dist hd u x).trans
58
+ (mul_le_mul_of_nonneg_left hu (Real.sqrt_nonneg _))
59
+
60
+ lemma cubeBall_embedding_subset {d : ℕ} (hd : 2 ≤ d) (z : Space (d/2)) {r : ℝ}
61
+ (u₀ : Cube d) (hu₀ : u₀ ∈ CubeBall d z r) :
62
+ CubeBall d z r ⊆ CubeEmbedding d ⁻¹' Metric.closedBall (CubeEmbedding d u₀) (4*r) := by
63
+ have hs : 0 < Real.sqrt (d/2:ℕ) := Real.sqrt_pos.2 (by exact_mod_cast (show 0 < d/2 by omega))
64
+ intro u hu
65
+ have hu' : dist u.val z ≤ Real.sqrt (d/2:ℕ)*r := hu
66
+ have hu₀' : dist u₀.val z ≤ Real.sqrt (d/2:ℕ)*r := hu₀
67
+ have hab : dist u.val u₀.val ≤ 2*Real.sqrt (d/2:ℕ)*r := by
68
+ have := dist_triangle u.val z u₀.val
69
+ rw [dist_comm z u₀.val] at this
70
+ linarith
71
+ apply (cubeEmbedding_dist hd u u₀).trans
72
+ calc
73
+ _ ≤ 2/Real.sqrt (d/2:ℕ)*(2*Real.sqrt (d/2:ℕ)*r) :=
74
+ mul_le_mul_of_nonneg_left hab (by positivity)
75
+ _ = 4*r := by field_simp [ne_of_gt hs]; ring
76
+
77
+ lemma weightedBlock_le_sum {X : Type*} {d m N : ℕ}
78
+ (ι : X → Space d) (f : Fin N → X → ℝ≥0∞)
79
+ {g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞}
80
+ (hg : ∀ x, ∑ w, g w x ≤ 1) (x : X) : WeightedBlock ι f g x ≤ ∑ w, f w x := by
81
+ unfold WeightedBlock
82
+ calc
83
+ _ ≤ ∫⁻ _A : Fin m → Space d, (∑ w, f w x) ∂Measure.pi (fun _ => stdGaussian (Space d)) := by
84
+ apply lintegral_mono
85
+ intro A
86
+ apply Finset.sum_le_sum
87
+ intro w _
88
+ exact mul_le_of_le_one_left' ((Finset.single_le_sum (fun _ _ => zero_le) (Finset.mem_univ w)).trans (hg _))
89
+ _ = _ := by simp
90
+
91
+ def CubeBlockConstant : ℝ := 4*1344^3
92
+ lemma cubeBlockConstant_one : 1 ≤ CubeBlockConstant := by norm_num [CubeBlockConstant]
93
+
94
+ lemma cube_constant_scale {d : ℕ} (hd : 2 ≤ d) {r : ℝ} (hr : 0 < r) :
95
+ (1344:ℝ)^d * (4*r)^(3*(d/2:ℕ)/4:ℝ) ≤ CubeBlockConstant^(d/2) * r^(3*(d/2:ℕ)/4:ℝ) := by
96
+ rw [Real.mul_rpow (by norm_num) hr.le]
97
+ have hp : (1344:ℝ)^d ≤ (1344^3:ℝ)^(d/2) := by
98
+ rw [← pow_mul]
99
+ apply pow_le_pow_right₀ (by norm_num)
100
+ omega
101
+ have h4 : (4:ℝ)^(3*(d/2:ℕ)/4:ℝ) ≤ (4:ℝ)^(d/2) := by
102
+ rw [← Real.rpow_natCast]
103
+ apply Real.rpow_le_rpow_of_exponent_le (by norm_num)
104
+ have := Nat.cast_nonneg (α := ℝ) (d/2)
105
+ linarith
106
+ calc
107
+ _ = ((1344:ℝ)^d*(4:ℝ)^(3*(d/2:ℕ)/4:ℝ))*r^(3*(d/2:ℕ)/4:ℝ) := by ring
108
+ _ ≤ ((1344^3:ℝ)^(d/2)*(4:ℝ)^(d/2))*r^(3*(d/2:ℕ)/4:��) := by gcongr
109
+ _ = _ := by rw [← mul_pow]; congr 2; norm_num [CubeBlockConstant]
110
+
111
+ def CubeBlockStatement : Prop :=
112
+ ∃ C : ℝ, 1 ≤ C ∧ ∀ d k N : ℕ, 16 ≤ d → 1 ≤ k → k ≤ (d/2)/4 → 1 ≤ N →
113
+ ∀ L : ℝ, 0 ≤ L → ∀ f : Fin N → Cube d → ℝ≥0∞,
114
+ (∀ v, Measurable (f v)) → (∀ v u, f v u ≤ 1) → (∀ v, CubeLocal (f v) L) →
115
+ ∀ g : Fin N → ((Fin k → Space d) × (Fin k → ℝ)) → ℝ≥0∞,
116
+ (∀ v, Measurable (g v)) → (∀ x, ∑ v, g v x ≤ 1) →
117
+ CubeLocal (WeightedBlock (CubeEmbedding d) f g)
118
+ (C^(d/2) * (N:ℝ)^(1/(((d/2)/4:ℕ):ℝ)) * L)
119
+ theorem cube_block : CubeBlockStatement := by
120
+ refine ⟨CubeBlockConstant, cubeBlockConstant_one, ?_⟩
121
+ intro d k N hd hk hkp hN L hL f hf hf1 hloc g hg hgs z r hr
122
+ by_cases hL0 : L = 0
123
+ · simp only [hL0, mul_zero, zero_mul, ENNReal.ofReal_zero]
124
+ calc
125
+ _ ≤ ∫⁻ u in CubeBall d z r, ∑ w, f w u ∂CubeLaw d :=
126
+ lintegral_mono (weightedBlock_le_sum _ _ hgs)
127
+ _ = ∑ w, ∫⁻ u in CubeBall d z r, f w u ∂CubeLaw d :=
128
+ lintegral_finsetSum _ (fun w _ => hf w)
129
+ _ ≤ ∑ _w : Fin N, ENNReal.ofReal (L*r^(3*(d/2:ℕ)/4:ℝ)) :=
130
+ Finset.sum_le_sum (fun w _ => hloc w z r hr)
131
+ _ = 0 := by simp [hL0]
132
+ have hLpos : 0 < L := lt_of_le_of_ne hL (Ne.symm hL0)
133
+ by_cases hempty : CubeBall d z r = ∅
134
+ · simp [hempty]
135
+ obtain ⟨u₀,hu₀⟩ := Set.nonempty_iff_ne_empty.mpr hempty
136
+ let ν (w : Fin N) := ((CubeLaw d).withDensity (f w)).map (CubeEmbedding d)
137
+ let (w : Fin N) : IsFiniteMeasure (ν w) := weighted_image_finite (CubeLaw d) (CubeEmbedding d) (f w) (hf1 w)
138
+ have hν w : AmbientBallBound (ν w) L (3*(d/2:ℕ)/4:ℝ) := cube_weighted_ambient (by omega) (hloc w)
139
+ have hp : 2 ≤ (d/2)/4 := by omega
140
+ have hkd : k ≤ d := by omega
141
+ have hgap : (k:ℝ)+(((d/2)/4:ℕ):ℝ)-2 < (3*(d/2:ℕ)/4:ℝ) := by
142
+ have hp' : (((d/2)/4:ℕ):ℝ)*4 ≤ (d/2:ℕ) := by exact_mod_cast Nat.div_mul_le_self (d/2) 4
143
+ have hk' : (k:ℝ) ≤ ((d/2)/4:ℕ) := by exact_mod_cast hkp
144
+ have hn' : (8:ℝ) ≤ (d/2:ℕ) := by exact_mod_cast (show 8 ≤ d/2 by omega)
145
+ linarith
146
+ have hsel := localized_weighted_selection ν hp hk hkd (by norm_num : (1:ℝ) ≤ 7)
147
+ hLpos hgap (cube_J_bound hd hkp) hν g hg hgs (CubeEmbedding d u₀) (by positivity : 0 < 4*r)
148
+ have he := weightedBlock_mass_identity (CubeLaw d) (cubeEmbedding_measurable d) hf hf1 hg
149
+ (show MeasurableSet (Metric.closedBall (CubeEmbedding d u₀) (4*r)) from Metric.isClosed_closedBall.measurableSet)
150
+ apply (lintegral_mono_set (cubeBall_embedding_subset (by omega) z u₀ hu₀)).trans
151
+ rw [he]
152
+ apply hsel.trans (ENNReal.ofReal_le_ofReal ?_)
153
+ have hscale := cube_constant_scale (d := d) (by omega) hr
154
+ norm_num only [show (7:ℝ)*192=1344 by norm_num]
155
+ calc
156
+ _ = ((1344:ℝ)^d*(4*r)^(3*(d/2:ℕ)/4:ℝ))*((N:ℝ)^(1/(((d/2)/4:ℕ):ℝ))*L) := by ring
157
+ _ ≤ (CubeBlockConstant^(d/2)*r^(3*(d/2:ℕ)/4:ℝ))*((N:ℝ)^(1/(((d/2)/4:ℕ):ℝ))*L) :=
158
+ mul_le_mul_of_nonneg_right hscale (by positivity)
159
+ _ = _ := by ring
160
+ end MemoryPrecision
161
+
162
+
163
+ end
164
+
165
+ end OAI
lean/OAI/Probability/MemoryPrecision/CubeCaps.lean ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.CubeGeometry
4
+
5
+ namespace OAI
6
+
7
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
8
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
9
+
10
+ noncomputable section
11
+ universe u v
12
+
13
+
14
+ open MeasureTheory ProbabilityTheory Set Filter
15
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
16
+ namespace MemoryPrecision
17
+ open NoiselessRegression
18
+
19
+ lemma coordinate_ball_root_volume (n : ℕ) :
20
+ volume (coordinateBall n (Real.sqrt n)) ≤ ENNReal.ofReal ((12:ℝ)^n) := by
21
+ have hpoint (x : Fin n → ℝ) :
22
+ (coordinateBall n (Real.sqrt n)).indicator (fun _ => (1:ℝ≥0∞)) x ≤
23
+ ENNReal.ofReal (Real.exp n) * ∏ i, ENNReal.ofReal (Real.exp (-(x i)^2/4)) := by
24
+ by_cases hx : x ∈ coordinateBall n (Real.sqrt n)
25
+ · rw [Set.indicator_of_mem hx, ← ENNReal.ofReal_prod_of_nonneg (fun i _ => Real.exp_nonneg _),
26
+ ← ENNReal.ofReal_mul (Real.exp_nonneg _), ← Real.exp_sum, ← Real.exp_add]
27
+ have hs : (∑ i, (x i)^2) ≤ n := by
28
+ have hp := pow_le_pow_left₀ (norm_nonneg _) hx 2
29
+ change coordinateNorm x ^ 2 ≤ (Real.sqrt (n:ℝ)) ^ 2 at hp
30
+ rw [coordinateNorm_sq, Real.sq_sqrt (by positivity)] at hp
31
+ exact hp
32
+ have he : 1 ≤ Real.exp ((n:ℝ) + ∑ i, -(x i)^2/4) := by
33
+ apply Real.one_le_exp_iff.mpr
34
+ rw [← Finset.sum_div, Finset.sum_neg_distrib]
35
+ have hn : (0:ℝ) ≤ n := Nat.cast_nonneg n
36
+ linarith
37
+ exact_mod_cast (ENNReal.ofReal_le_ofReal he)
38
+ · rw [Set.indicator_of_notMem hx]
39
+ exact zero_le
40
+ calc
41
+ volume (coordinateBall n (Real.sqrt n)) =
42
+ ∫⁻ x : Fin n → ℝ, (coordinateBall n (Real.sqrt n)).indicator (fun _ => (1:ℝ≥0∞)) x := by
43
+ rw [lintegral_indicator_const (measurableSet_coordinateBall _ _), one_mul]
44
+ _ ≤ ∫⁻ x : Fin n → ℝ, ENNReal.ofReal (Real.exp n) *
45
+ ∏ i, ENNReal.ofReal (Real.exp (-(x i)^2/4)) := lintegral_mono hpoint
46
+ _ = ENNReal.ofReal (Real.exp n) *
47
+ (∫⁻ z : ℝ, ENNReal.ofReal (Real.exp (-(z^2)/4)))^n := by
48
+ rw [lintegral_const_mul _ (by fun_prop), volume_pi,
49
+ lintegral_fin_prod volume n (fun _ => fun z : ℝ => ENNReal.ofReal (Real.exp (-(z^2)/4))) (fun _ => by fun_prop)]
50
+ simp
51
+ _ ≤ ENNReal.ofReal (Real.exp n) * (4:ℝ≥0∞)^n := by
52
+ gcongr
53
+ exact lintegral_quarterGaussian_le
54
+ _ ≤ ENNReal.ofReal ((12:ℝ)^n) := by
55
+ have he : Real.exp (n:ℝ) ≤ (3:ℝ)^n := by
56
+ rw [← mul_one (n:ℝ), Real.exp_nat_mul]
57
+ exact pow_le_pow_left₀ (Real.exp_nonneg _) Real.exp_one_lt_three.le n
58
+ calc
59
+ _ ≤ ENNReal.ofReal ((3:ℝ)^n) * (4:ℝ≥0∞)^n := mul_le_mul' (ENNReal.ofReal_le_ofReal he) le_rfl
60
+ _ = _ := by rw [ENNReal.ofReal_pow (by norm_num), ← mul_pow]; norm_num
61
+
62
+ lemma cube_scaled_ball_volume (n : ℕ) (z : Space n) {r : ℝ} (hr : 0 < r) :
63
+ volume (Metric.closedBall z (Real.sqrt n*r)) ≤ ENNReal.ofReal ((12:ℝ)^n*r^n) := by
64
+ rw [Measure.addHaar_closedBall_center]
65
+ have he : (WithLp.toLp 2 : (Fin n → ℝ) → Space n) ⁻¹' Metric.closedBall 0 (Real.sqrt n*r) =
66
+ coordinateBall n (r*Real.sqrt n) := by
67
+ ext x
68
+ simp [Metric.mem_closedBall, dist_zero_right, coordinateBall, coordinateNorm, mul_comm]
69
+ rw [← (PiLp.volume_preserving_toLp (Fin n)).measure_preimage (show NullMeasurableSet (Metric.closedBall (0:Space n) (Real.sqrt n*r)) volume from Metric.isClosed_closedBall.measurableSet.nullMeasurableSet), he,
70
+ volume_coordinateBall_smul n r (Real.sqrt n) hr]
71
+ calc
72
+ _ ≤ ENNReal.ofReal (r^n) * ENNReal.ofReal ((12:ℝ)^n) :=
73
+ mul_le_mul' le_rfl (coordinate_ball_root_volume n)
74
+ _ = _ := by rw [← ENNReal.ofReal_mul (by positivity)]; congr 1; ring
75
+
76
+ lemma cubeBall_volume (d : ℕ) (z : Space (d/2)) {r : ℝ} (hr : 0 < r) :
77
+ CubeLaw d (CubeBall d z r) ≤ ENNReal.ofReal ((12:ℝ)^(d/2)*r^(d/2)) := by
78
+ rw [CubeLaw, comap_subtype_coe_apply (cubeSet_measurable _)]
79
+ apply (measure_mono (show Subtype.val '' CubeBall d z r ⊆ Metric.closedBall z (Real.sqrt (d/2:ℕ)*r) from ?_)).trans
80
+ (cube_scaled_ball_volume (d/2) z hr)
81
+ rintro _ ⟨u,hu,rfl⟩
82
+ exact hu
83
+
84
+ lemma cube_cap_local {d : ℕ} (hd : 2 ≤ d) (y : Space d) {ε : ℝ} (hε : 0 < ε) :
85
+ CubeLocal (fun u => capWeight y ε (CubeEmbedding d u))
86
+ ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ)) := by
87
+ intro z r hr
88
+ let A : Set (Cube d) := CubeEmbedding d ⁻¹' Metric.closedBall y ε
89
+ have hA : MeasurableSet A := Metric.isClosed_closedBall.measurableSet.preimage (cubeEmbedding_measurable d)
90
+ have hint : (∫⁻ u in CubeBall d z r, capWeight y ε (CubeEmbedding d u) ∂CubeLaw d) =
91
+ CubeLaw d (A ∩ CubeBall d z r) := by
92
+ change (∫⁻ u in CubeBall d z r, A.indicator (fun _ => (1:ℝ≥0∞)) u ∂CubeLaw d) = _
93
+ rw [lintegral_indicator_const hA, one_mul, Measure.restrict_apply hA]
94
+ rw [hint]
95
+ have hεball : A ⊆ CubeBall d (Real.sqrt (d/2:ℕ) • cubeProject d y) ε := by
96
+ intro u hu
97
+ exact (cubeProject_parameter_dist hd u y).trans
98
+ (mul_le_mul_of_nonneg_left hu (Real.sqrt_nonneg _))
99
+ have hs : (0:ℝ) ≤ (d/2:ℕ)/4 := by positivity
100
+ have ht : (0:ℝ) ≤ 3*(d/2:ℕ)/4 := by positivity
101
+ have he (t : ℝ) (ht : 0 < t) : t^(d/2) = t^((d/2:ℕ)/4:ℝ)*t^(3*(d/2:ℕ)/4:ℝ) := by
102
+ rw [← Real.rpow_add ht, show ((d/2:ℕ)/4:ℝ)+(3*(d/2:ℕ)/4:ℝ) = (d/2:ℕ) by ring, Real.rpow_natCast]
103
+ by_cases hh : r ≤ ε
104
+ · apply ((measure_mono Set.inter_subset_right).trans (cubeBall_volume d z hr)).trans
105
+ apply ENNReal.ofReal_le_ofReal
106
+ rw [he r hr, ← mul_assoc]
107
+ gcongr
108
+ · apply ((measure_mono (Set.inter_subset_left.trans hεball)).trans
109
+ (cubeBall_volume d (Real.sqrt (d/2:ℕ) • cubeProject d y) hε)).trans
110
+ apply ENNReal.ofReal_le_ofReal
111
+ rw [he ε hε, ← mul_assoc]
112
+ gcongr
113
+ exact le_of_not_ge hh
114
+
115
+ lemma cubeBall_univ (d : ℕ) : CubeBall d 0 1 = Set.univ := by
116
+ ext u
117
+ simp only [Set.mem_univ, iff_true]
118
+ change dist u.val 0 ≤ Real.sqrt (d/2:ℕ)*1
119
+ rw [dist_zero_right, mul_one]
120
+ apply nonneg_le_nonneg_of_sq_le_sq (Real.sqrt_nonneg _)
121
+ simp only [← pow_two]
122
+ rw [Real.sq_sqrt (by positivity), EuclideanSpace.norm_sq_eq]
123
+ calc
124
+ _ ≤ ∑ _i : Fin (d/2), (1:ℝ) := by
125
+ apply Finset.sum_le_sum
126
+ intro i _
127
+ have h := u.property i
128
+ have hab := abs_le.mp h
129
+ simp only [Real.norm_eq_abs, sq_abs]
130
+ nlinarith
131
+ _ = _ := by simp
132
+
133
+ lemma cube_mass_bound {d : ℕ} {f : Cube d → ℝ≥0∞} {L : ℝ} (h : CubeLocal f L) :
134
+ (∫⁻ u, f u ∂CubeLaw d) ≤ ENNReal.ofReal L := by
135
+ simpa [cubeBall_univ] using h 0 1 zero_lt_one
136
+
137
+ end MemoryPrecision
138
+
139
+
140
+ end
141
+
142
+ end OAI
lean/OAI/Probability/MemoryPrecision/CubeContinuation.lean ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.CubeBlock
4
+ import OAI.Probability.MemoryPrecision.CubeCaps
5
+ import OAI.Probability.MemoryPrecision.RealContinuation
6
+
7
+ namespace OAI
8
+
9
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
10
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
11
+
12
+ noncomputable section
13
+ universe u v
14
+
15
+
16
+ open MeasureTheory ProbabilityTheory Set Filter
17
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
18
+ namespace MemoryPrecision
19
+ open NoiselessRegression
20
+ def CubeStepConstant : ℝ := Classical.choose cube_block
21
+ lemma cubeStepConstant_one : 1 ≤ CubeStepConstant := (Classical.choose_spec cube_block).1
22
+ lemma cubeStepConstant_pos : 0 < CubeStepConstant := lt_of_lt_of_le zero_lt_one cubeStepConstant_one
23
+
24
+ def CubeStep (d N : ℕ) : ℝ := CubeStepConstant^(d/2) * (N:ℝ)^(1/(((d/2)/4:ℕ):ℝ))
25
+ lemma cubeStep_one (d : ℕ) {N : ℕ} (hN : 1 ≤ N) : 1 ≤ CubeStep d N := by
26
+ apply one_le_mul_of_one_le_of_one_le
27
+ · exact one_le_pow₀ cubeStepConstant_one
28
+ · exact Real.one_le_rpow (by exact_mod_cast hN) (by positivity)
29
+ lemma cubeStep_pos (d : ℕ) {N : ℕ} (hN : 1 ≤ N) : 0 < CubeStep d N :=
30
+ lt_of_lt_of_le zero_lt_one (cubeStep_one d hN)
31
+
32
+ lemma cube_deterministic_step {d m N : ℕ} (hd : 16 ≤ d) (hm : 1 ≤ m)
33
+ (hmp : m ≤ (d/2)/4) (hN : 1 ≤ N) {H : ℝ} (hH : 0 < H)
34
+ (h : Fin N → Space d → ℝ≥0∞) (hh : ∀ w, Measurable (h w))
35
+ (hh1 : ∀ w s, h w s ≤ 1)
36
+ (hb : ∀ w, CubeLocal (fun u => h w (CubeEmbedding d u)) H)
37
+ (φ : ((Fin m → Space d) × (Fin m → ℝ)) → Fin N) (hφ : Measurable φ) :
38
+ CubeLocal (fun u => blockValue h φ (CubeEmbedding d u)) (CubeStep d N * H) := by
39
+ classical
40
+ let g (w : Fin N) (x : (Fin m → Space d) × (Fin m → ℝ)) : ℝ≥0∞ :=
41
+ if φ x = w then 1 else 0
42
+ have hg (w) : Measurable (g w) := by
43
+ exact Measurable.ite (measurableSet_eq_fun hφ measurable_const) measurable_const measurable_const
44
+ have hg1 (x) : ∑ w, g w x ≤ 1 := by simp [g]
45
+ have hb' := (Classical.choose_spec cube_block).2 d m N hd hm hmp hN H hH.le
46
+ (fun w u => h w (CubeEmbedding d u)) (fun w => (hh w).comp (cubeEmbedding_measurable d))
47
+ (fun w u => hh1 w (CubeEmbedding d u)) hb g hg hg1
48
+ convert hb' using 1
49
+ · funext u
50
+ unfold blockValue WeightedBlock
51
+ congr 1
52
+ funext A
53
+ simp [g]
54
+ · rfl
55
+
56
+ lemma CubeLocal.mono {d : ℕ} {h : Cube d → ℝ≥0∞} {H K : ℝ}
57
+ (hh : CubeLocal h H) (hHK : H ≤ K) : CubeLocal h K := by
58
+ intro z r hr
59
+ exact (hh z r hr).trans (ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_right hHK (by positivity)))
60
+
61
+ lemma cube_continuation_mass {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N)
62
+ {δ : ℕ → Fin N → (Space d × ℝ) → Fin N}
63
+ {w : ℕ → Fin N → Space d → ℝ≥0∞}
64
+ (hδ : ∀ n j, Measurable (δ n j)) (hw : ∀ n j, Measurable (w n j))
65
+ (hw1 : ∀ n j s, w n j s ≤ 1) {H : ℝ} (hH : 0 < H)
66
+ (hlocal : ∀ n j, CubeLocal (fun s => w n j (CubeEmbedding d s)) H)
67
+ (b k : ℕ) (hk : k ≤ b*((d/2)/4)) (n : ℕ) (j : Fin N) :
68
+ CubeLocal (fun s => continuation δ w n k j (CubeEmbedding d s))
69
+ (H * CubeStep d N ^ b) := by
70
+ have hp : 0 < (d/2)/4 := by omega
71
+ have hK := cubeStep_one d hN
72
+ have hK0 := cubeStep_pos d hN
73
+ induction b generalizing k n j with
74
+ | zero =>
75
+ have : k = 0 := by omega
76
+ subst k
77
+ simpa [continuation] using hlocal n j
78
+ | succ b ih =>
79
+ by_cases hk0 : k = 0
80
+ · subst k
81
+ apply (hlocal n j).mono
82
+ simpa [continuation] using le_mul_of_one_le_right hH.le (one_le_pow₀ hK)
83
+ · let m := min k ((d/2)/4)
84
+ have hm : 1 ≤ m := by dsimp [m]; omega
85
+ have hmp : m ≤ (d/2)/4 := min_le_right _ _
86
+ have hmk : m ≤ k := min_le_left _ _
87
+ have hk' : k-m ≤ b*((d/2)/4) := by
88
+ dsimp [m]
89
+ rw [Nat.succ_mul] at hk
90
+ omega
91
+ have hb := cube_deterministic_step hd hm hmp hN
92
+ (mul_pos hH (pow_pos hK0 b))
93
+ (fun a => continuation δ w (n+m) (k-m) a)
94
+ (fun a => measurable_continuation hδ hw _ _ a)
95
+ (fun a s => continuation_le_one hw1 _ _ a s)
96
+ (fun a => ih (k-m) hk' (n+m) a) (streamRoute δ n m j)
97
+ (measurable_streamRoute hδ n m j)
98
+ have he : (fun s : Cube d => continuation δ w n k j (CubeEmbedding d s)) =
99
+ (fun s : Cube d => blockValue (fun a => continuation δ w (n+m) (k-m) a)
100
+ (streamRoute δ n m j) (CubeEmbedding d s)) := by
101
+ funext s
102
+ simpa [Nat.add_sub_of_le hmk] using continuation_unroll hδ n m (k-m) j (CubeEmbedding d s)
103
+ rw [he]
104
+ convert hb using 1
105
+ rw [pow_succ]; ring
106
+
107
+ lemma cube_continuation_cap_integral {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N)
108
+ {δ : ℕ → Fin N → (Space d × ℝ) → Fin N} (hδ : ∀ n j, Measurable (δ n j))
109
+ (y : ℕ → Fin N → Space d) {ε : ℝ} (hε : 0 < ε) (n k : ℕ) (j : Fin N) :
110
+ (∫⁻ u, continuation δ (fun n j => capWeight (y n j) ε) n k j (CubeEmbedding d u) ∂CubeLaw d) ≤
111
+ ENNReal.ofReal ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * CubeStep d N ^ BlockCount k ((d/2)/4)) := by
112
+ apply cube_mass_bound
113
+ apply cube_continuation_mass hd hN hδ (fun n j => measurable_capWeight _ _)
114
+ (fun n j s => capWeight_le_one _ _ _) (by positivity)
115
+ (fun n j => cube_cap_local (by omega) (y n j) hε)
116
+ simpa [mul_comm] using blockCount_mul_ge k (by omega : 0 < (d/2)/4)
117
+
118
+ end MemoryPrecision
119
+
120
+
121
+ end
122
+
123
+ end OAI
lean/OAI/Probability/MemoryPrecision/CubeExperiment.lean ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.CubeCaps
4
+ import OAI.Probability.MemoryPrecision.PriorMeasurability
5
+
6
+ namespace OAI
7
+
8
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
9
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
10
+
11
+ noncomputable section
12
+ universe u v
13
+
14
+
15
+ open MeasureTheory ProbabilityTheory Set Filter
16
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
17
+ namespace MemoryPrecision
18
+ open NoiselessRegression
19
+
20
+ def CubeSphere {d : ℕ} (hd : 2 ≤ d) (u : Cube d) : UnitSphere d :=
21
+ ⟨CubeEmbedding d u, by simpa [Metric.mem_sphere, dist_zero_right] using cubeEmbedding_norm hd u⟩
22
+ lemma cubeSphere_measurable {d : ℕ} (hd : 2 ≤ d) : Measurable (CubeSphere hd) :=
23
+ (cubeEmbedding_measurable d).subtype_mk
24
+
25
+ def CubeSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
26
+ (L : Learner d M T Ω) (ρ : Measure Ω) (hd : 2 ≤ d) (ε : ℝ) : ℝ≥0∞ :=
27
+ ((CubeLaw d).prod (ρ.prod (sampleLaw d T)))
28
+ {z | Learner.angularError (CubeSphere hd z.1)
29
+ (L.estimate (CubeSphere hd z.1) z.2.1 z.2.2) ≤ ε}
30
+ def CubeAmbient (d : ℕ) : Measure (Space d) := (CubeLaw d).map (CubeEmbedding d)
31
+ instance (d : ℕ) : IsProbabilityMeasure (CubeAmbient d) :=
32
+ inferInstanceAs (IsProbabilityMeasure ((CubeLaw d).map (CubeEmbedding d)))
33
+
34
+ lemma cubeAmbient_support {d : ℕ} (hd : 2 ≤ d) : (CubeAmbient d).support ⊆ Metric.closedBall 0 1 := by
35
+ apply Measure.support_subset_of_isClosed Metric.isClosed_closedBall
36
+ rw [mem_ae_iff, CubeAmbient, Measure.map_apply (cubeEmbedding_measurable d)
37
+ Metric.isClosed_closedBall.measurableSet.compl]
38
+ have he : CubeEmbedding d ⁻¹' (Metric.closedBall (0:Space d) 1)ᶜ = ∅ := by
39
+ ext u
40
+ simp [cubeEmbedding_norm hd, Metric.mem_closedBall, dist_zero_right]
41
+ rw [he, measure_empty]
42
+
43
+ lemma cubeAmbient_polynomial {d : ℕ} (hd : 2 ≤ d) :
44
+ PolynomialMass (CubeAmbient d) (d/2) (ENNReal.ofReal ((12:ℝ)^(d/2))) := by
45
+ intro x r hr
46
+ rw [CubeAmbient, Measure.map_apply (cubeEmbedding_measurable d) Metric.isClosed_closedBall.measurableSet]
47
+ have hsub : CubeEmbedding d ⁻¹' Metric.closedBall x r ⊆
48
+ CubeBall d (Real.sqrt (d/2:ℕ) • cubeProject d x) r := by
49
+ intro u hu
50
+ exact (cubeProject_parameter_dist hd u x).trans
51
+ (mul_le_mul_of_nonneg_left hu (Real.sqrt_nonneg _))
52
+ exact ((measure_mono hsub).trans (cubeBall_volume d _ hr)).trans_eq (ENNReal.ofReal_mul (by positivity))
53
+
54
+ lemma cube_observation_quasi {d : ℕ} (hd : 16 ≤ d) :
55
+ Measure.QuasiMeasurePreserving
56
+ (fun z : Cube d × Space d => (z.2,⟪CubeEmbedding d z.1,z.2⟫))
57
+ ((CubeLaw d).prod (stdGaussian (Space d))) (observationReference d) := by
58
+ have hac : projectionLaw (CubeAmbient d) 1 ≪ matrixLabelReference (E := Space d) 1 := by
59
+ apply projectionLaw_absolutelyContinuous (cubeAmbient_polynomial (by omega : 2 ≤ d))
60
+ (C := ENNReal.ofReal ((12:ℝ)^(d/2))) (n := 1)
61
+ · positivity
62
+ · exact ENNReal.ofReal_ne_top
63
+ · exact cubeAmbient_support (by omega)
64
+ · omega
65
+ · omega
66
+ have hp : Measure.QuasiMeasurePreserving
67
+ (fun z : (Fin 1 → Space d) × Space d => (z.1,fun j => ⟪z.2,z.1 j⟫))
68
+ ((Measure.pi (fun _ : Fin 1 => stdGaussian (Space d))).prod (CubeAmbient d))
69
+ (matrixLabelReference (E := Space d) 1) := ⟨by fun_prop,hac⟩
70
+ have h1 := ((measurePreserving_funUnique (stdGaussian (Space d)) (Fin 1)).symm
71
+ (MeasurableEquiv.funUnique (Fin 1) (Space d))).prod
72
+ ((cubeEmbedding_measurable d).measurePreserving (CubeLaw d))
73
+ have h2 := (measurePreserving_funUnique (stdGaussian (Space d)) (Fin 1)).prod
74
+ (volume_preserving_funUnique (Fin 1) ℝ)
75
+ have h3 := h2.quasiMeasurePreserving.comp (hp.comp (h1.quasiMeasurePreserving.comp
76
+ Measure.measurePreserving_swap.quasiMeasurePreserving))
77
+ convert h3 using 1
78
+ · ext z <;> simp [MeasurableEquiv.funUnique]
79
+ · rfl
80
+
81
+ lemma cube_sample_observation_quasi {d T : ℕ} (hd : 16 ≤ d) (i : Fin T) :
82
+ Measure.QuasiMeasurePreserving
83
+ (fun z : Cube d × Samples d T => (z.2 i,⟪CubeEmbedding d z.1,z.2 i⟫))
84
+ ((CubeLaw d).prod (sampleLaw d T)) (observationReference d) := by
85
+ exact (cube_observation_quasi hd).comp
86
+ ((MeasurePreserving.id (CubeLaw d)).prod
87
+ (measurePreserving_eval (fun _ : Fin T => stdGaussian (Space d)) i)).quasiMeasurePreserving
88
+
89
+ lemma cube_estimate_aemeasurable {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
90
+ (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ]
91
+ (hL : L.Admissible ρ) (hd : 16 ≤ d) :
92
+ AEMeasurable (fun z : Cube d × (Ω × Samples d T) =>
93
+ L.estimate (CubeSphere (by omega) z.1) z.2.1 z.2.2)
94
+ ((CubeLaw d).prod (ρ.prod (sampleLaw d T))) :=
95
+ prior_estimate_aemeasurable (CubeLaw d) ρ (CubeSphere (by omega)) L hL
96
+ (cube_sample_observation_quasi hd)
97
+
98
+ end MemoryPrecision
99
+
100
+
101
+ end
102
+
103
+ end OAI
lean/OAI/Probability/MemoryPrecision/CubeGeometry.lean ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.AmbientGram
4
+
5
+ namespace OAI
6
+
7
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
8
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
9
+
10
+ noncomputable section
11
+ universe u v
12
+
13
+
14
+ open MeasureTheory ProbabilityTheory Set Filter
15
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
16
+ namespace MemoryPrecision
17
+ open NoiselessRegression
18
+ abbrev CubeSet (n : ℕ) : Set (EuclideanSpace ℝ (Fin n)) :=
19
+ fun (point : EuclideanSpace ℝ (Fin n)) => ∀ index : Fin n,
20
+ @LE.le ℝ Real.instLE
21
+ (@abs ℝ Real.lattice Real.instAddGroup
22
+ (@WithLp.ofLp
23
+ (@OfNat.ofNat ℝ≥0∞ 2
24
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
25
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))))
26
+ (Fin n → ℝ) point index))
27
+ (@HDiv.hDiv ℝ ℝ ℝ (@instHDiv ℝ Real.instDivInvMonoid.toDiv)
28
+ (@OfNat.ofNat ℝ 1 (@One.toOfNat1 ℝ Real.instOne))
29
+ (@OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast
30
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))))
31
+ abbrev Cube (d : ℕ) := CubeSet (d/2)
32
+ def CubeLaw (d : ℕ) : Measure (Cube d) :=
33
+ (volume : Measure (Space (d/2))).comap Subtype.val
34
+ lemma cube_second_coordinate_lt (d : ℕ) (index : Fin d)
35
+ (lower : ¬index.val < d/2) (upper : index.val < 2*(d/2)) :
36
+ index.val - d/2 < d/2 := by omega
37
+
38
+ def cubeRaw (d : ℕ) (u : Space (d/2)) : Space d :=
39
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
40
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
41
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
42
+ @HSMul.hSMul ℝ (Space d) (Space d)
43
+ (@instHSMul ℝ (Space d) (WithLp.instSMul exponent ℝ (Fin d → ℝ)))
44
+ (Real.sqrt (d/2:ℕ))⁻¹ (WithLp.toLp exponent (fun index : Fin d =>
45
+ if lower : index.val < d/2 then
46
+ @WithLp.ofLp exponent (Fin (d/2) → ℝ) u ⟨index.val, lower⟩
47
+ else if upper : index.val < 2*(d/2) then
48
+ Real.sqrt (1-(@WithLp.ofLp exponent (Fin (d/2) → ℝ) u
49
+ ⟨index.val-d/2, cube_second_coordinate_lt d index lower upper⟩)^2)
50
+ else 0))
51
+ def CubeEmbedding (d : ℕ) (u : Cube d) : Space d := cubeRaw d u.val
52
+ def CubeBall (d : ℕ) (z : Space (d/2)) (r : ℝ) : Set (Cube d) :=
53
+ {u | dist u.val z ≤ Real.sqrt (d/2:ℕ) * r}
54
+ def CubeLocal {d : ℕ} (f : Cube d → ℝ≥0∞) (L : ℝ) : Prop :=
55
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
56
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
57
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
58
+ let cubeMeasurable := @Subtype.instMeasurableSpace (Space (d/2)) (CubeSet (d/2))
59
+ (@WithLp.measurableSpace exponent (Fin (d/2) → ℝ) inferInstance)
60
+ ∀ z : Space (d/2), ∀ r : ℝ, 0 < r →
61
+ @MeasureTheory.lintegral (Cube d) cubeMeasurable
62
+ (@Measure.restrict (Cube d) cubeMeasurable (CubeLaw d) (CubeBall d z r)) f ≤
63
+ ENNReal.ofReal (L * r^(
64
+ (@OfNat.ofNat ℝ 3 (@instOfNatAtLeastTwo ℝ 3 Real.commRing.toNatCast
65
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 1)))) * (d/2:ℕ) /
66
+ (@OfNat.ofNat ℝ 4 (@instOfNatAtLeastTwo ℝ 4 Real.commRing.toNatCast
67
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 2)))) : ℝ))
68
+
69
+ lemma cubeSet_closed (n : ℕ) : IsClosed (CubeSet n) := by
70
+ change IsClosed {u : Space n | ∀ i, |u i| ≤ 1/2}
71
+ simp only [Set.ofPred_forall]
72
+ exact isClosed_iInter (fun i => isClosed_le (by fun_prop) continuous_const)
73
+
74
+ lemma cubeSet_measurable (n : ℕ) : MeasurableSet (CubeSet n) :=
75
+ (cubeSet_closed n).measurableSet
76
+
77
+ lemma cubeLaw_probability (d : ℕ) : IsProbabilityMeasure (CubeLaw d) := by
78
+ constructor
79
+ rw [CubeLaw, comap_subtype_coe_apply (cubeSet_measurable _), Set.image_univ,
80
+ Subtype.range_coe]
81
+ have he : CubeSet (d/2) = WithLp.ofLp ⁻¹' (Set.univ.pi (fun _ : Fin (d/2) => Icc (-1/2:ℝ) (1/2))) := by
82
+ ext u
83
+ change (∀ i, |u i| ≤ (1/2 : ℝ)) ↔ _
84
+ simp only [Set.mem_preimage, Set.mem_univ_pi, Set.mem_Icc, abs_le]
85
+ norm_num
86
+ rw [he, (PiLp.volume_preserving_ofLp (Fin (d/2))).measure_preimage (by measurability)]
87
+ rw [volume_pi, Measure.pi_pi]
88
+ norm_num [Real.volume_Icc]
89
+
90
+ instance (d : ℕ) : IsProbabilityMeasure (CubeLaw d) := cubeLaw_probability d
91
+
92
+ lemma cubeBall_measurable (d : ℕ) (z : Space (d/2)) (r : ℝ) : MeasurableSet (CubeBall d z r) := by
93
+ exact measurableSet_le (by fun_prop) measurable_const
94
+
95
+ lemma cubeRaw_continuous (d : ℕ) : Continuous (cubeRaw d) := by
96
+ unfold cubeRaw
97
+ refine Continuous.const_smul (c := (Real.sqrt (d/2:ℕ))⁻¹) ?_
98
+ apply (PiLp.continuous_toLp 2 (fun _ : Fin d => ℝ)).comp
99
+ apply continuous_pi
100
+ intro i
101
+ dsimp
102
+ split_ifs <;> fun_prop
103
+
104
+ lemma cubeEmbedding_continuous (d : ℕ) : Continuous (CubeEmbedding d) :=
105
+ (cubeRaw_continuous d).comp continuous_subtype_val
106
+
107
+ lemma cubeEmbedding_measurable (d : ℕ) : Measurable (CubeEmbedding d) :=
108
+ (cubeEmbedding_continuous d).measurable
109
+
110
+ lemma sum_fin_split {n d : ℕ} (hn : n ≤ d) (f : Fin d → ℝ) :
111
+ (∑ i, f i) = (∑ i : Fin n, f ⟨i.val,by omega⟩) +
112
+ ∑ i : Fin (d-n), f ⟨n+i.val,by omega⟩ := by
113
+ let e : Fin (n+(d-n)) ≃ Fin d := finCongr (Nat.add_sub_of_le hn)
114
+ calc
115
+ _ = ∑ i : Fin (n+(d-n)), f (e i) := (Equiv.sum_comp e f).symm
116
+ _ = _ := by rw [Fin.sum_univ_add]; rfl
117
+
118
+ def cubeCoords (d : ℕ) (u : Space (d/2)) : Space d :=
119
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
120
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
121
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
122
+ WithLp.toLp exponent (fun index : Fin d =>
123
+ if lower : index.val < d/2 then
124
+ @WithLp.ofLp exponent (Fin (d/2) → ℝ) u ⟨index.val, lower⟩
125
+ else if upper : index.val < 2*(d/2) then
126
+ Real.sqrt (1-(@WithLp.ofLp exponent (Fin (d/2) → ℝ) u
127
+ ⟨index.val-d/2, cube_second_coordinate_lt d index lower upper⟩)^2)
128
+ else 0)
129
+
130
+ lemma cubeCoords_first (d : ℕ) (u : Space (d/2)) (i : Fin (d/2)) :
131
+ cubeCoords d u ⟨i.val,by omega⟩ = u i := by
132
+ simp [cubeCoords, i.isLt]
133
+
134
+ lemma cubeCoords_second (d : ℕ) (u : Space (d/2)) (i : Fin (d/2)) :
135
+ cubeCoords d u ⟨d/2+i.val,by omega⟩ = Real.sqrt (1-u i^2) := by
136
+ simp [cubeCoords, show ¬d/2+i.val < d/2 by omega, show d/2+i.val < 2*(d/2) by omega]
137
+
138
+ lemma cubeCoords_tail (d : ℕ) (u : Space (d/2)) (i : Fin d) (hi : 2*(d/2) ≤ i.val) :
139
+ cubeCoords d u i = 0 := by
140
+ simp [cubeCoords, show ¬i.val < d/2 by omega, show ¬i.val < 2*(d/2) by omega]
141
+
142
+ lemma cubeCoords_sum (d : ℕ) (u : Space (d/2)) (f : ℝ → ℝ) (hf : f 0 = 0) :
143
+ (∑ i : Fin d, f (cubeCoords d u i)) =
144
+ (∑ i : Fin (d/2), f (u i)) + ∑ i : Fin (d/2), f (Real.sqrt (1-u i^2)) := by
145
+ rw [sum_fin_split (show d/2 ≤ d by omega)]
146
+ simp_rw [cubeCoords_first]
147
+ rw [sum_fin_split (show d/2 ≤ d-d/2 by omega)]
148
+ congr 1
149
+ have h1 : (∑ i : Fin (d/2), f (cubeCoords d u ⟨d/2+i.val,by omega⟩)) =
150
+ ∑ i : Fin (d/2), f (Real.sqrt (1-u i^2)) := by simp_rw [cubeCoords_second]
151
+ rw [h1]
152
+ have h0 : (∑ i : Fin (d-d/2-d/2), f (cubeCoords d u ⟨d/2+(d/2+i.val),by omega⟩)) = 0 := by
153
+ apply Finset.sum_eq_zero
154
+ intro i _
155
+ rw [cubeCoords_tail d u _ (show 2*(d/2) ≤ d/2+(d/2+i.val) by omega), hf]
156
+ rw [h0, add_zero]
157
+
158
+ lemma cube_coordinate_square_le {d : ℕ} (u : Cube d) (i : Fin (d/2)) : u.val i^2 ≤ 1/4 := by
159
+ have hu : -(1/2 : ℝ) ≤ u.val i ∧ u.val i ≤ 1/2 := abs_le.mp (u.property i)
160
+ nlinarith [sq_nonneg (u.val i-1/2), sq_nonneg (u.val i+1/2)]
161
+
162
+ lemma cubeEmbedding_norm {d : ℕ} (hd : 2 ≤ d) (u : Cube d) :
163
+ @Norm.norm (Space d) (PiLp.instNorm
164
+ (p := @OfNat.ofNat ℝ≥0∞ 2
165
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
166
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (β := fun _ : Fin d => ℝ))
167
+ (CubeEmbedding d u) = (1 : ℝ) := by
168
+ have hs : ‖cubeCoords d u.val‖^2 = (d/2:ℕ) := by
169
+ rw [EuclideanSpace.real_norm_sq_eq, cubeCoords_sum d u.val (fun x => x^2) (by norm_num)]
170
+ have he (i : Fin (d/2)) : Real.sqrt (1-u.val i^2)^2 = 1-u.val i^2 :=
171
+ Real.sq_sqrt (by have := cube_coordinate_square_le u i; linarith)
172
+ simp_rw [he]
173
+ rw [← Finset.sum_add_distrib]
174
+ simp
175
+ have hn : 0 < (d/2:ℕ) := by omega
176
+ have hr : 0 < Real.sqrt (d/2:ℕ) := Real.sqrt_pos.2 (by exact_mod_cast hn)
177
+ have hnorm : ‖cubeCoords d u.val‖ = Real.sqrt (d/2:ℕ) := by
178
+ rw [← Real.sqrt_sq (norm_nonneg _), hs]
179
+ change ‖(Real.sqrt (d/2:ℕ))⁻¹ • cubeCoords d u.val‖ = 1
180
+ rw [norm_smul, Real.norm_eq_abs, abs_inv, abs_of_pos hr, hnorm, inv_mul_cancel₀ hr.ne']
181
+
182
+ lemma sqrt_pair_lipschitz {a b : ℝ} (ha : |a| ≤ 1/2) (hb : |b| ≤ 1/2) :
183
+ |Real.sqrt (1-a^2) - Real.sqrt (1-b^2)| ≤ |a-b| := by
184
+ have ha2 : a^2 ≤ 1/4 := by rcases abs_le.mp ha with ⟨ha₁,ha₂⟩; nlinarith
185
+ have hb2 : b^2 ≤ 1/4 := by rcases abs_le.mp hb with ⟨hb₁,hb₂⟩; nlinarith
186
+ have hsa := Real.sq_sqrt (show 0 ≤ 1-a^2 by linarith)
187
+ have hsb := Real.sq_sqrt (show 0 ≤ 1-b^2 by linarith)
188
+ have has : 1/2 ≤ Real.sqrt (1-a^2) := by nlinarith [Real.sqrt_nonneg (1-a^2)]
189
+ have hbs : 1/2 ≤ Real.sqrt (1-b^2) := by nlinarith [Real.sqrt_nonneg (1-b^2)]
190
+ have hab : |a+b| ≤ 1 := (abs_add_le a b).trans (by linarith)
191
+ have he : (Real.sqrt (1-a^2)-Real.sqrt (1-b^2)) *
192
+ (Real.sqrt (1-a^2)+Real.sqrt (1-b^2)) = -(a-b)*(a+b) := by nlinarith
193
+ calc
194
+ _ ≤ |Real.sqrt (1-a^2)-Real.sqrt (1-b^2)| *
195
+ |Real.sqrt (1-a^2)+Real.sqrt (1-b^2)| := by
196
+ apply le_mul_of_one_le_right (abs_nonneg _)
197
+ rw [abs_of_nonneg (by positivity)]
198
+ linarith
199
+ _ = |a-b| * |a+b| := by rw [← abs_mul, he, abs_mul, abs_neg]
200
+ _ ≤ |a-b| := mul_le_of_le_one_right (abs_nonneg _) hab
201
+
202
+ private lemma cubeCoords_sub_norm (d : ℕ) (u v : Cube d) :
203
+ ‖cubeCoords d u.val - cubeCoords d v.val‖ ≤ 2 * ‖u.val-v.val‖ := by
204
+ have hs : ‖cubeCoords d u.val - cubeCoords d v.val‖^2 =
205
+ (∑ i : Fin (d/2), (u.val i-v.val i)^2) +
206
+ ∑ i : Fin (d/2), (Real.sqrt (1-u.val i^2)-Real.sqrt (1-v.val i^2))^2 := by
207
+ rw [EuclideanSpace.real_norm_sq_eq, sum_fin_split (show d/2 ≤ d by omega)]
208
+ simp only [PiLp.sub_apply, cubeCoords_first]
209
+ rw [sum_fin_split (show d/2 ≤ d-d/2 by omega)]
210
+ simp only [cubeCoords_second]
211
+ have hz : (∑ i : Fin (d-d/2-d/2),
212
+ (cubeCoords d u.val ⟨d/2+(d/2+i.val),by omega⟩ -
213
+ cubeCoords d v.val ⟨d/2+(d/2+i.val),by omega⟩)^2) = 0 := by
214
+ apply Finset.sum_eq_zero
215
+ intro i _
216
+ rw [cubeCoords_tail d u.val _ (show 2*(d/2) ≤ d/2+(d/2+i.val) by omega),
217
+ cubeCoords_tail d v.val _ (show 2*(d/2) ≤ d/2+(d/2+i.val) by omega)]
218
+ norm_num
219
+ rw [hz, add_zero]
220
+ have hsq : (∑ i : Fin (d/2), (Real.sqrt (1-u.val i^2)-Real.sqrt (1-v.val i^2))^2) ≤
221
+ ∑ i : Fin (d/2), (u.val i-v.val i)^2 := by
222
+ apply Finset.sum_le_sum
223
+ intro i _
224
+ exact (sq_le_sq).2 (sqrt_pair_lipschitz (u.property i) (v.property i))
225
+ have hv : ‖u.val-v.val‖^2 = ∑ i : Fin (d/2), (u.val i-v.val i)^2 := by
226
+ simp [EuclideanSpace.real_norm_sq_eq]
227
+ nlinarith [norm_nonneg (cubeCoords d u.val-cubeCoords d v.val), norm_nonneg (u.val-v.val)]
228
+
229
+ lemma cubeEmbedding_dist {d : ℕ} (hd : 2 ≤ d) (u v : Cube d) :
230
+ dist (CubeEmbedding d u) (CubeEmbedding d v) ≤
231
+ 2 / Real.sqrt (d/2:ℕ) * dist u.val v.val := by
232
+ have hr : 0 < Real.sqrt (d/2:ℕ) := Real.sqrt_pos.2 (by exact_mod_cast (show 0 < d/2 by omega))
233
+ change dist ((Real.sqrt (d/2:ℕ))⁻¹ • cubeCoords d u.val)
234
+ ((Real.sqrt (d/2:ℕ))⁻¹ • cubeCoords d v.val) ≤ _
235
+ rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_inv, abs_of_pos hr, dist_eq_norm]
236
+ calc
237
+ _ ≤ (Real.sqrt (d/2:ℕ))⁻¹ * (2*‖u.val-v.val‖) :=
238
+ mul_le_mul_of_nonneg_left (cubeCoords_sub_norm d u v) (inv_nonneg.mpr hr.le)
239
+ _ = _ := by ring
240
+
241
+ def cubeProject (d : ℕ) (x : Space d) : Space (d/2) :=
242
+ WithLp.toLp 2 (fun i : Fin (d/2) => x ⟨i.val,by omega⟩)
243
+
244
+ lemma cubeProject_continuous (d : ℕ) : Continuous (cubeProject d) := by
245
+ unfold cubeProject
246
+ fun_prop
247
+
248
+ lemma cubeProject_norm (d : ℕ) (x : Space d) : ‖cubeProject d x‖ ≤ ‖x‖ := by
249
+ have h : ‖cubeProject d x‖^2 ≤ ‖x‖^2 := by
250
+ rw [EuclideanSpace.real_norm_sq_eq, EuclideanSpace.real_norm_sq_eq,
251
+ sum_fin_split (show d/2 ≤ d by omega)]
252
+ change (∑ i : Fin (d/2), x ⟨i.val,by omega⟩^2) ≤ _
253
+ exact le_add_of_nonneg_right (Finset.sum_nonneg (fun _ _ => sq_nonneg _))
254
+ nlinarith [norm_nonneg (cubeProject d x), norm_nonneg x]
255
+
256
+ lemma cubeProject_sub (d : ℕ) (x y : Space d) : cubeProject d (x-y) = cubeProject d x-cubeProject d y := by
257
+ ext i
258
+ rfl
259
+
260
+ lemma cubeProject_embedding (d : ℕ) (u : Cube d) :
261
+ cubeProject d (CubeEmbedding d u) = (Real.sqrt (d/2:ℕ))⁻¹ • u.val := by
262
+ ext i
263
+ simp [cubeProject, CubeEmbedding, cubeRaw]
264
+
265
+ lemma cubeProject_parameter_dist {d : ℕ} (hd : 2 ≤ d) (u : Cube d) (x : Space d) :
266
+ dist u.val (Real.sqrt (d/2:ℕ) • cubeProject d x) ≤
267
+ Real.sqrt (d/2:ℕ) * dist (CubeEmbedding d u) x := by
268
+ have hr : 0 < Real.sqrt (d/2:ℕ) := Real.sqrt_pos.2 (by exact_mod_cast (show 0 < d/2 by omega))
269
+ have he : u.val - Real.sqrt (d/2:ℕ) • cubeProject d x =
270
+ Real.sqrt (d/2:ℕ) • cubeProject d (CubeEmbedding d u-x) := by
271
+ rw [cubeProject_sub, cubeProject_embedding, smul_sub, smul_smul, mul_inv_cancel₀ hr.ne', one_smul]
272
+ rw [dist_eq_norm, he, norm_smul, Real.norm_eq_abs, abs_of_pos hr, dist_eq_norm]
273
+ exact mul_le_mul_of_nonneg_left (cubeProject_norm d _) hr.le
274
+ end MemoryPrecision
275
+
276
+
277
+ end
278
+
279
+ end OAI
lean/OAI/Probability/MemoryPrecision/CubeSuccess.lean ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.CubeArithmetic
4
+ import OAI.Probability.MemoryPrecision.KernelCube
5
+ import OAI.Probability.MemoryPrecision.Precision
6
+
7
+ namespace OAI
8
+
9
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
10
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
11
+
12
+ noncomputable section
13
+ universe u v
14
+
15
+
16
+ open MeasureTheory ProbabilityTheory Set Filter
17
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
18
+ namespace MemoryPrecision.Kernel
19
+ open MemoryPrecision NoiselessRegression Policy
20
+
21
+ lemma source_cube_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
22
+ (L : Ω → Policy d M T) (ρ : Measure Ω) [IsProbabilityMeasure ρ]
23
+ (hd : 16 ≤ d) (hL : Admissible L ρ (CubePrior (by omega)))
24
+ (hM : M ≤ d^2) {ε : ℝ} (hε : 0 < ε) :
25
+ Success L ρ (CubePrior (by omega)) ε ≤ min 1 (ENNReal.ofReal
26
+ (CubeSuccessConstant^((d/2)*(BlockCount T ((d/2)/4)+1)) * ε^((d/2:ℕ)/4:ℝ))) := by
27
+ refine le_min (Policy.success_le_one L ρ (CubePrior (by omega)) ε) ?_
28
+ have hb := (Policy.success_le_chord L ρ (CubePrior (by omega)) ε).trans
29
+ (Policy.source_cube_chord_bound L ρ hd hL hε)
30
+ have he : (T+1:ℝ≥0∞) * ENNReal.ofReal
31
+ ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4)) =
32
+ ENNReal.ofReal ((T+1:ℝ) *
33
+ ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4))) := by
34
+ rw [ENNReal.ofReal_mul (by positivity : (0:ℝ) ≤ T+1)]
35
+ congr 1
36
+ simp [ENNReal.ofReal_add]
37
+ rw [he] at hb
38
+ apply hb.trans (ENNReal.ofReal_le_ofReal ?_)
39
+ calc
40
+ _ = ((T+1:ℝ) * ((12:ℝ)^(d/2) * CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4))) *
41
+ ε^((d/2:ℕ)/4:ℝ) := by ring
42
+ _ ≤ _ := mul_le_mul_of_nonneg_right (cube_whole_factor hd hM T) (by positivity)
43
+
44
+ lemma cubePrior_dimension {d₀ d : ℕ} (hd₀ : 16 ≤ d₀) (hd : d₀ ≤ d) : 2 ≤ d :=
45
+ Nat.le_trans (by decide : 2 ≤ 16) (Nat.le_trans hd₀ hd)
46
+
47
+ def CubeSuccessEstimate {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
48
+ (D : ℝ) (hd : 2 ≤ d) (ε : ℝ) (K : Ω → Policy d M T) (ρ : Measure Ω) : Prop :=
49
+ Policy.Success K ρ (CubePrior hd) ε ≤ min 1 (ENNReal.ofReal
50
+ (D^((d/2)*(MemoryPrecision.Kernel.BlockCount T ((d/2)/4)+1)) * ε^((d/2:ℕ)/4:ℝ)))
51
+
52
+ def PointwisePrecisionEstimate {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
53
+ (c ε : ℝ) (K : Ω → Policy d M T) (ρ : Measure Ω) : Prop :=
54
+ (∀ signal : MemoryPrecision.Kernel.Sphere d,
55
+ (@OfNat.ofNat ℝ≥0∞ 2
56
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) /
57
+ (@OfNat.ofNat ℝ≥0∞ 3
58
+ (@instOfNatAtLeastTwo ℝ≥0∞ 3 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) ≤
59
+ Policy.FixedSuccess K ρ ε signal) → c*(d:ℝ)*Real.log (1/ε) ≤ (T:ℝ)
60
+
61
+ abbrev SourceCubeStatement : Prop :=
62
+ ∃ D : ℝ, Real.exp 1 ≤ D ∧ ∃ d₀ : ℕ, ∃ hd₀ : 16 ≤ d₀, ∃ c : ℝ, 0 < c ∧
63
+ ∀ d M T : ℕ, ∀ hd : d₀ ≤ d, M ≤ d^2 → ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 →
64
+ ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ →
65
+ ∀ K : Ω → MemoryPrecision.Kernel.Policy d M T, Policy.ModelAdmissible.{u} K ρ →
66
+ CubeSuccessEstimate.{u} D (cubePrior_dimension hd₀ hd) ε K ρ ∧
67
+ PointwisePrecisionEstimate.{u} c ε K ρ
68
+
69
+ theorem source_cube_success : SourceCubeStatement := by
70
+ refine ⟨CubeSuccessConstant,cubeSuccessConstant_exp,32,by norm_num,
71
+ 1/(8+20*StreamConstant*(1+1)),by have := streamConstant_pos; positivity,?_⟩
72
+ intro d M T hd hM ε hε hε1 Ω _ ρ hρ L hL
73
+ have : IsProbabilityMeasure ρ := hρ
74
+ let : NeZero d := ⟨by omega⟩
75
+ refine ⟨source_cube_bound L ρ (by omega) (hL _ inferInstance) hM hε, ?_⟩
76
+ intro hs
77
+ apply Policy.source_precision L ρ hd (hL _ inferInstance) (by norm_num : (0:ℝ) < 1)
78
+ (by exact_mod_cast (by simpa using hM : M ≤ 1*d^2)) hε hε1
79
+ exact Policy.source_uniform_of_pointwise L ρ (by omega) (hL _ inferInstance) ε hs
80
+ end MemoryPrecision.Kernel
81
+
82
+
83
+ end
84
+
85
+ end OAI
lean/OAI/Probability/MemoryPrecision/DensityPassage.lean ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+
4
+ namespace OAI
5
+
6
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
7
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
8
+
9
+ noncomputable section
10
+ universe u v
11
+
12
+
13
+ open MeasureTheory ProbabilityTheory Set Filter
14
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
15
+ namespace MemoryPrecision
16
+ open NoiselessRegression
17
+
18
+ section FiberSmoothing
19
+ variable {Ω Y : Type*} [MeasurableSpace Ω] [NormedAddCommGroup Y]
20
+ [MeasurableSpace Y] [BorelSpace Y] [SecondCountableTopology Y]
21
+ (γ : Measure Ω) (τ : Measure Y) [SigmaFinite τ]
22
+
23
+ def fiberSmoothing (F : Ω × Y → ℝ≥0∞) (ρ : Y → ℝ≥0∞) (z : Ω × Y) : ℝ≥0∞ :=
24
+ ∫⁻ b, ρ (z.2 - b) * F (z.1, b) ∂τ
25
+
26
+ @[fun_prop] lemma measurable_fiberSmoothing {F : Ω × Y → ℝ≥0∞} {ρ : Y → ℝ≥0∞}
27
+ (hF : Measurable F) (hρ : Measurable ρ) :
28
+ Measurable (fiberSmoothing τ F ρ) := by
29
+ unfold fiberSmoothing
30
+ exact Measurable.lintegral_prod_right (by fun_prop)
31
+
32
+ lemma lintegral_fiberSmoothing_test {F : Ω × Y → ℝ≥0∞} {ρ : Y → ℝ≥0∞}
33
+ (hF : Measurable F) (hρ : Measurable ρ) (f : Ω × Y → ℝ≥0∞) (hf : Measurable f) :
34
+ (∫⁻ z, fiberSmoothing τ F ρ z * f z ∂γ.prod τ) =
35
+ ∫⁻ z, (∫⁻ y, ρ (y - z.2) * f (z.1, y) ∂τ) ∂(γ.prod τ).withDensity F := by
36
+ have hK : Measurable (fun z : Ω × Y => ∫⁻ y, ρ (y-z.2) * f (z.1,y) ∂τ) :=
37
+ Measurable.lintegral_prod_right (by fun_prop)
38
+ rw [lintegral_withDensity_eq_lintegral_mul _ hF hK]
39
+ simp only [Pi.mul_apply]
40
+ rw [lintegral_prod (fun z => fiberSmoothing τ F ρ z * f z)
41
+ ((measurable_fiberSmoothing τ hF hρ).mul hf).aemeasurable,
42
+ lintegral_prod (fun z => F z * ∫⁻ y, ρ (y-z.2) * f (z.1,y) ∂τ)
43
+ (hF.mul hK).aemeasurable]
44
+ apply lintegral_congr
45
+ intro A
46
+ dsimp only [fiberSmoothing]
47
+ have hmul (y : Y) : (∫⁻ b, ρ (y-b) * F (A,b) ∂τ) * f (A,y) =
48
+ ∫⁻ b, (ρ (y-b) * F (A,b)) * f (A,y) ∂τ :=
49
+ (lintegral_mul_const _ (by fun_prop)).symm
50
+ simp_rw [hmul]
51
+ rw [lintegral_lintegral_swap (by fun_prop)]
52
+ apply lintegral_congr
53
+ intro b
54
+ rw [← lintegral_const_mul _ (by fun_prop : Measurable (fun y => ρ (y-b) * f (A,y)))]
55
+ apply lintegral_congr
56
+ intro y
57
+ ring
58
+ end FiberSmoothing
59
+
60
+ section ProjectionSmoothing
61
+ variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
62
+ [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
63
+
64
+ local instance density_reference_sigmaFinite (m : ℕ) :
65
+ SigmaFinite (matrixLabelReference (E := E) m) := by
66
+ unfold matrixLabelReference
67
+ infer_instance
68
+
69
+ lemma lintegral_projectionSmoothing_test (ν : Measure E) [SigmaFinite ν]
70
+ (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (m : ℕ)
71
+ (f : (Fin m → E) × (Fin m → ℝ) → ℝ≥0∞) (hf : Measurable f) :
72
+ (∫⁻ z, projectionSmoothing ν φ m z * f z ∂matrixLabelReference m) =
73
+ ∫⁻ z, (∫⁻ y : Fin m → ℝ, (∏ j, φ (y j - z.2 j)) * f (z.1, y))
74
+ ∂projectionLaw ν m := by
75
+ have hK : Measurable (fun z : (Fin m → E) × (Fin m → ℝ) =>
76
+ ∫⁻ y : Fin m → ℝ, (∏ j, φ (y j-z.2 j)) * f (z.1,y)) :=
77
+ Measurable.lintegral_prod_right (by fun_prop)
78
+ rw [projectionLaw, lintegral_map hK (by fun_prop), matrixLabelReference,
79
+ lintegral_prod (fun z => projectionSmoothing ν φ m z * f z)
80
+ ((measurable_projectionSmoothing ν φ hφ m).mul hf).aemeasurable,
81
+ lintegral_prod _ (by fun_prop)]
82
+ apply lintegral_congr
83
+ intro A
84
+ dsimp only [projectionSmoothing]
85
+ have hmul (y : Fin m → ℝ) : (∫⁻ t : E, ∏ j, φ (y j-⟪t,A j⟫) ∂ν) * f (A,y) =
86
+ ∫⁻ t : E, (∏ j, φ (y j-⟪t,A j⟫)) * f (A,y) ∂ν :=
87
+ (lintegral_mul_const _ (by fun_prop)).symm
88
+ simp_rw [hmul]
89
+ rw [lintegral_lintegral_swap (by fun_prop)]
90
+
91
+ lemma projectionSmoothing_ae_eq_fiberSmoothing (ν : Measure E) [SigmaFinite ν]
92
+ (m : ℕ) (F : (Fin m → E) × (Fin m → ℝ) → ℝ≥0∞) (hF : Measurable F)
93
+ (hden : (matrixLabelReference m).withDensity F = projectionLaw ν m)
94
+ (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) :
95
+ projectionSmoothing ν φ m =ᵐ[matrixLabelReference m]
96
+ fiberSmoothing volume F (fun y : Fin m → ℝ => ∏ j, φ (y j)) := by
97
+ apply (withDensity_eq_iff_of_sigmaFinite
98
+ (measurable_projectionSmoothing ν φ hφ m).aemeasurable
99
+ (measurable_fiberSmoothing volume hF (by fun_prop)).aemeasurable).mp
100
+ apply Measure.ext_of_lintegral
101
+ intro f hf
102
+ rw [lintegral_withDensity_eq_lintegral_mul _
103
+ (measurable_projectionSmoothing ν φ hφ m) hf,
104
+ lintegral_withDensity_eq_lintegral_mul _
105
+ (measurable_fiberSmoothing volume hF (by fun_prop)) hf]
106
+ simp only [Pi.mul_apply]
107
+ rw [lintegral_projectionSmoothing_test ν φ hφ m f hf]
108
+ change _ = ∫⁻ z, fiberSmoothing volume F (fun y : Fin m → ℝ => ∏ j, φ (y j)) z * f z
109
+ ∂(Measure.pi (fun _ : Fin m => stdGaussian E)).prod volume
110
+ rw [lintegral_fiberSmoothing_test _ volume hF (by fun_prop) f hf]
111
+
112
+ unfold matrixLabelReference at hden
113
+ rw [hden]
114
+ rfl
115
+ end ProjectionSmoothing
116
+
117
+ def boxScalar (δ : ℝ) (t : ℝ) : ℝ≥0∞ :=
118
+ (ENNReal.ofReal (2*δ))⁻¹ * (Icc (-δ) δ).indicator 1 t
119
+
120
+ @[fun_prop] lemma measurable_boxScalar (δ : ℝ) : Measurable (boxScalar δ) := by
121
+ exact measurable_const.mul (measurable_const.indicator measurableSet_Icc)
122
+
123
+ lemma lintegral_boxScalar {δ : ℝ} (hδ : 0 < δ) : ∫⁻ t, boxScalar δ t = 1 := by
124
+ unfold boxScalar
125
+ rw [lintegral_const_mul _ (show Measurable ((Icc (-δ) δ).indicator (1 : ℝ → ℝ≥0∞)) from
126
+ measurable_one.indicator measurableSet_Icc), lintegral_indicator measurableSet_Icc]
127
+ simp only [Pi.one_apply, lintegral_const, one_mul, Measure.restrict_apply_univ,
128
+ Real.volume_Icc, sub_neg_eq_add]
129
+ rw [← two_mul]
130
+ exact ENNReal.inv_mul_cancel (ENNReal.ofReal_ne_zero_iff.mpr (by positivity)) ENNReal.ofReal_ne_top
131
+
132
+ lemma box_product_eq (m : ℕ) {δ : ℝ} (hδ : 0 < δ) (y : Fin m → ℝ) :
133
+ (∏ j, boxScalar δ (y j)) =
134
+ ((volume : Measure (Fin m → ℝ)) (Metric.closedBall 0 δ))⁻¹ *
135
+ (Metric.closedBall 0 δ).indicator 1 y := by
136
+ have hv : (volume : Measure (Fin m → ℝ)) (Metric.closedBall 0 δ) =
137
+ (ENNReal.ofReal (2*δ))^m := by
138
+ rw [volume_pi, closedBall_pi _ hδ.le, Measure.pi_pi]
139
+ simp [Real.closedBall_eq_Icc, ← two_mul]
140
+ rw [hv]
141
+ simp only [boxScalar, Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin,
142
+ ENNReal.inv_pow]
143
+ congr 1
144
+ by_cases hy : y ∈ Metric.closedBall (0 : Fin m → ℝ) δ
145
+ · rw [Set.indicator_of_mem hy]
146
+ have hy' : ∀ j, y j ∈ Icc (-δ) δ := by
147
+ intro j
148
+ rw [closedBall_pi _ hδ.le] at hy
149
+ simpa [Real.closedBall_eq_Icc] using hy j (mem_univ j)
150
+ simp [hy']
151
+ · rw [Set.indicator_of_notMem hy]
152
+ have hy' : ∃ j, y j ∉ Icc (-δ) δ := by
153
+ by_contra h
154
+ apply hy
155
+ rw [closedBall_pi _ hδ.le]
156
+ intro j _
157
+ have hh := not_not.mp (not_exists.mp h j)
158
+ simpa [Real.closedBall_eq_Icc] using hh
159
+ obtain ⟨j,hj⟩ := hy'
160
+ exact Finset.prod_eq_zero (Finset.mem_univ j) (Set.indicator_of_notMem hj _)
161
+
162
+ section Differentiation
163
+ variable {Ω : Type*} [MeasurableSpace Ω]
164
+
165
+ lemma fiberSmoothing_box_eq_average (m : ℕ)
166
+ (F : Ω × (Fin m → ℝ) → ℝ≥0∞) (hF : Measurable F)
167
+ {δ : ℝ} (hδ : 0 < δ) (A : Ω) (y : Fin m → ℝ) :
168
+ fiberSmoothing volume F (fun x : Fin m → ℝ => ∏ j, boxScalar δ (x j)) (A,y) =
169
+ (∫⁻ b in Metric.closedBall y δ, F (A,b)) /
170
+ (volume : Measure (Fin m → ℝ)) (Metric.closedBall y δ) := by
171
+ unfold fiberSmoothing
172
+ simp_rw [box_product_eq m hδ]
173
+ have he (b : Fin m → ℝ) :
174
+ (Metric.closedBall (0 : Fin m → ℝ) δ).indicator (1 : (Fin m → ℝ) → ℝ≥0∞) (y-b) * F (A,b) =
175
+ (Metric.closedBall y δ).indicator (fun b => F (A,b)) b := by
176
+ have hb : y-b ∈ Metric.closedBall (0 : Fin m → ℝ) δ ↔ b ∈ Metric.closedBall y δ := by
177
+ simp [Metric.mem_closedBall, dist_eq_norm, norm_sub_rev]
178
+ by_cases h : b ∈ Metric.closedBall y δ
179
+ · rw [Set.indicator_of_mem (hb.mpr h), Set.indicator_of_mem h]; simp
180
+ · rw [Set.indicator_of_notMem (mt hb.mp h), Set.indicator_of_notMem h]; simp
181
+ simp_rw [mul_assoc, he]
182
+ rw [lintegral_const_mul _ (show Measurable ((Metric.closedBall y δ).indicator
183
+ (fun b => F (A,b))) from (hF.comp (measurable_const.prodMk measurable_id)).indicator
184
+ Metric.isClosed_closedBall.measurableSet), lintegral_indicator Metric.isClosed_closedBall.measurableSet,
185
+ div_eq_mul_inv, Measure.addHaar_closedBall_center volume y δ, mul_comm]
186
+
187
+ lemma ae_tendsto_fiberSmoothing_box (γ : Measure Ω) [SigmaFinite γ] (m : ℕ)
188
+ (F : Ω × (Fin m → ℝ) → ℝ≥0∞) (hF : Measurable F)
189
+ (hfin : (∫⁻ z, F z ∂γ.prod volume) ≠ ∞) :
190
+ ∀ᵐ z ∂γ.prod volume,
191
+ Tendsto (fun k : ℕ => fiberSmoothing volume F
192
+ (fun x : Fin m → ℝ => ∏ j, boxScalar (1 / ((k:ℝ)+1)) (x j)) z)
193
+ atTop (𝓝 (F z)) := by
194
+ have hmeas (k : ℕ) : Measurable (fiberSmoothing volume F
195
+ (fun x : Fin m → ℝ => ∏ j, boxScalar (1 / ((k:ℝ)+1)) (x j))) :=
196
+ measurable_fiberSmoothing volume hF (by fun_prop)
197
+ rw [Measure.ae_prod_iff_ae_ae (measurableSet_tendsto_fun hmeas hF)]
198
+ have hinner : (∫⁻ A, ∫⁻ y : Fin m → ℝ, F (A,y) ∂volume ∂γ) ≠ ∞ := by
199
+ rwa [← lintegral_prod _ hF.aemeasurable]
200
+ filter_upwards [ae_lt_top (Measurable.lintegral_prod_right
201
+ (show Measurable (fun z : Ω × (Fin m → ℝ) => F (z.1,z.2)) from hF)) hinner] with A hA
202
+ have hFA : Measurable (fun y : Fin m → ℝ => F (A,y)) :=
203
+ hF.comp (measurable_const.prodMk measurable_id)
204
+ filter_upwards [(Besicovitch.vitaliFamily (volume : Measure (Fin m → ℝ))).ae_tendsto_lintegral_div
205
+ hFA.aemeasurable hA.ne] with y hy
206
+ have hδ : Tendsto (fun k : ℕ => 1 / ((k:ℝ)+1)) atTop (𝓝[>] (0:ℝ)) :=
207
+ tendsto_nhdsWithin_iff.mpr ⟨tendsto_one_div_add_atTop_nhds_zero_nat,
208
+ Filter.Eventually.of_forall (fun k => by change 0 < 1 / ((k:ℝ)+1); positivity)⟩
209
+ convert (hy.comp (Besicovitch.tendsto_filterAt volume y)).comp hδ using 1
210
+ ext k
211
+ exact fiberSmoothing_box_eq_average m F hF (by positivity) A y
212
+ end Differentiation
213
+
214
+ section MomentPassage
215
+ variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
216
+ [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
217
+ local instance passage_reference_sigmaFinite (m : ℕ) :
218
+ SigmaFinite (matrixLabelReference (E := E) m) := by
219
+ unfold matrixLabelReference
220
+ infer_instance
221
+ local instance passage_projection_finite (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) :
222
+ IsFiniteMeasure (projectionLaw ν m) := by
223
+ unfold projectionLaw
224
+ infer_instance
225
+
226
+ lemma projectionLaw_set_bound_of_moment (ν : Measure E) [IsFiniteMeasure ν]
227
+ (m n : ℕ) (hn : 1 ≤ n) (C : ℝ≥0∞) (hC : C ≠ ∞)
228
+ (hbound : ∀ φ : ℝ → ℝ≥0∞, Measurable φ → (∫⁻ x, φ x = 1) →
229
+ (∫⁻ Ay, projectionSmoothing ν φ m Ay ^ (n+1) ∂matrixLabelReference m) ≤ C)
230
+ (S : Set ((Fin m → E) × (Fin m → ℝ))) :
231
+ projectionLaw ν m S ≤ C^(1 / ((n : ℝ) + 1)) *
232
+ (matrixLabelReference (E := E) m S)^(1 - 1 / ((n : ℝ) + 1)) := by
233
+ have hp : 1 < (n : ℝ) + 1 := by exact_mod_cast (by omega : 1 < n + 1)
234
+ have hα : 0 < 1 - 1 / ((n : ℝ) + 1) := by
235
+ exact sub_pos.mpr ((div_lt_one (by positivity)).mpr hp)
236
+ have := matrixLabelReference_outerRegular (E := E) m
237
+ apply measure_apply_le_of_isOpen _ _ (ENNReal.rpow_ne_top_of_nonneg (by positivity) hC) hα
238
+ intro U hU
239
+ rw [← gaussianCoupling_map_noisyObservation_zero ν m]
240
+ apply map_apply_open_le_of_tendsto (gaussianCoupling ν m)
241
+ (matrixLabelReference (E := E) m) (noisyObservation m 0)
242
+ (fun k => noisyObservation m (1 / ((k : ℝ) + 1)))
243
+ (measurable_noisyObservation m 0) (fun k => measurable_noisyObservation m _)
244
+ (tendsto_noisyObservation m) _ _ (U := U) (hU := hU)
245
+ intro k V hV
246
+ have hδ : (1 / ((k : ℝ) + 1)) ≠ 0 := by positivity
247
+ rw [gaussianCoupling_map_noisyObservation ν m _ hδ]
248
+ apply withDensity_apply_le_moment _ _
249
+ (measurable_projectionSmoothing _ _ (measurable_gaussianPDF _ _) _) hp _ _ hV.measurableSet
250
+ have hv : (NNReal.mk ((1 / ((k : ℝ) + 1)) ^ 2)
251
+ (sq_nonneg (1 / ((k : ℝ) + 1)))) ≠ 0 := by
252
+ rw [← NNReal.coe_ne_zero]
253
+ exact pow_ne_zero 2 hδ
254
+ simpa only [← ENNReal.rpow_natCast, Nat.cast_add, Nat.cast_one] using
255
+ hbound (gaussianPDF 0 (NNReal.mk ((1 / ((k : ℝ) + 1)) ^ 2)
256
+ (sq_nonneg (1 / ((k : ℝ) + 1))))) (measurable_gaussianPDF _ _)
257
+ (lintegral_gaussianPDF_eq_one _ hv)
258
+
259
+ lemma projectionLaw_ac_of_moment (ν : Measure E) [IsFiniteMeasure ν]
260
+ (m n : ℕ) (hn : 1 ≤ n) (C : ℝ≥0∞) (hC : C ≠ ∞)
261
+ (hbound : ∀ φ : ℝ → ℝ≥0∞, Measurable φ → (∫⁻ x, φ x = 1) →
262
+ (∫⁻ Ay, projectionSmoothing ν φ m Ay ^ (n+1) ∂matrixLabelReference m) ≤ C) :
263
+ projectionLaw ν m ≪ matrixLabelReference m := by
264
+ intro S hS
265
+ have hh := projectionLaw_set_bound_of_moment ν m n hn C hC hbound S
266
+ have hα : 0 < 1 - 1 / ((n : ℝ) + 1) := by
267
+ have hn' : (1:ℝ) ≤ n := by exact_mod_cast hn
268
+ exact sub_pos.mpr ((div_lt_one (by positivity)).mpr (by linarith))
269
+ rw [hS, ENNReal.zero_rpow_of_pos hα, mul_zero] at hh
270
+ exact le_zero_iff.mp hh
271
+
272
+ lemma projectionLaw_rnDeriv_moment (ν : Measure E) [IsFiniteMeasure ν]
273
+ (m n : ℕ) (hn : 1 ≤ n) (C : ℝ≥0∞) (hC : C ≠ ∞)
274
+ (hbound : ∀ φ : ℝ → ℝ≥0∞, Measurable φ → (∫⁻ x, φ x = 1) →
275
+ (∫⁻ Ay, projectionSmoothing ν φ m Ay ^ (n+1) ∂matrixLabelReference m) ≤ C) :
276
+ (∫⁻ Ay, ((projectionLaw ν m).rnDeriv (matrixLabelReference m) Ay)^(n+1)
277
+ ∂matrixLabelReference m) ≤ C := by
278
+ let F := (projectionLaw ν m).rnDeriv (matrixLabelReference m)
279
+ have hF : Measurable F := Measure.measurable_rnDeriv _ _
280
+ have hden : (matrixLabelReference m).withDensity F = projectionLaw ν m :=
281
+ Measure.withDensity_rnDeriv_eq _ _ (projectionLaw_ac_of_moment ν m n hn C hC hbound)
282
+ let f : ℕ → ((Fin m → E) × (Fin m → ℝ)) → ℝ≥0∞ := fun k =>
283
+ projectionSmoothing ν (boxScalar (1/((k:ℝ)+1))) m
284
+ have hf (k : ℕ) : Measurable (f k) :=
285
+ measurable_projectionSmoothing ν _ (measurable_boxScalar _) m
286
+ have heq (k : ℕ) : f k =ᵐ[matrixLabelReference m]
287
+ fiberSmoothing volume F (fun y : Fin m → ℝ => ∏ j, boxScalar (1/((k:ℝ)+1)) (y j)) :=
288
+ projectionSmoothing_ae_eq_fiberSmoothing ν m F hF hden _ (measurable_boxScalar _)
289
+ have ht : ∀ᵐ Ay ∂matrixLabelReference m, Tendsto (fun k => f k Ay) atTop (𝓝 (F Ay)) := by
290
+ filter_upwards [ae_all_iff.mpr heq,
291
+ ae_tendsto_fiberSmoothing_box (Measure.pi (fun _ : Fin m => stdGaussian E)) m F hF
292
+ (Measure.lintegral_rnDeriv_lt_top (projectionLaw ν m) (matrixLabelReference m)).ne]
293
+ with Ay he ht
294
+ exact ht.congr (fun k => (he k).symm)
295
+ calc
296
+ _ = ∫⁻ Ay, atTop.liminf (fun k => (f k Ay)^(n+1)) ∂matrixLabelReference m := by
297
+ apply lintegral_congr_ae
298
+ filter_upwards [ht] with Ay hAy
299
+ exact (((ENNReal.continuous_pow (n+1)).tendsto _ |>.comp hAy).liminf_eq).symm
300
+ _ ≤ atTop.liminf (fun k => ∫⁻ Ay, (f k Ay)^(n+1) ∂matrixLabelReference m) :=
301
+ lintegral_liminf_le (fun k => (hf k).pow_const _)
302
+ _ ≤ C := by
303
+ apply liminf_le_of_frequently_le (hu_le := by isBoundedDefault)
304
+ exact (Filter.Eventually.of_forall (fun k =>
305
+ hbound _ (measurable_boxScalar _) (lintegral_boxScalar (by positivity)))).frequently
306
+ end MomentPassage
307
+
308
+ end MemoryPrecision
309
+
310
+
311
+ end
312
+
313
+ end OAI
lean/OAI/Probability/MemoryPrecision/DensityUniqueness.lean ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.FiberDensity
4
+
5
+ namespace OAI
6
+
7
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
8
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
9
+
10
+ noncomputable section
11
+ universe u v
12
+
13
+ open MeasureTheory ProbabilityTheory Set Filter
14
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
15
+ namespace MemoryPrecision
16
+ open NoiselessRegression
17
+
18
+ lemma piGaussianConvolution_withDensity {m : ℕ} (F : (Fin m → ℝ) → ℝ≥0∞)
19
+ (hF : Measurable F) (δ : ℝ) (y : Fin m → ℝ) :
20
+ PiGaussianConvolution (volume.withDensity F) δ y =
21
+ (∫⁻ x, (∏ j, gaussianPDF 0 ⟨δ^2,sq_nonneg δ⟩ (y j-x j)) * F x).toReal := by
22
+ unfold PiGaussianConvolution
23
+ rw [integral_eq_lintegral_of_nonneg_ae
24
+ (Eventually.of_forall (fun x => Finset.prod_nonneg (fun j _ => gaussianPDFReal_nonneg _ _ _)))
25
+ ((show Continuous (fun x : Fin m → ℝ => ∏ j,
26
+ gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (y j-x j)) from
27
+ by unfold gaussianPDFReal; fun_prop).aestronglyMeasurable),
28
+ lintegral_withDensity_eq_lintegral_mul _ hF (by fun_prop)]
29
+ congr 1
30
+ apply lintegral_congr
31
+ intro x
32
+ simp only [Pi.mul_apply, gaussianPDF]
33
+ rw [ENNReal.ofReal_prod_of_nonneg (fun j _ =>
34
+ gaussianPDFReal_nonneg 0 ⟨δ^2,sq_nonneg δ⟩ (y j-x j)), mul_comm]
35
+
36
+ lemma ae_tendsto_fiberGaussian {Ω : Type*} [MeasurableSpace Ω] (γ : Measure Ω)
37
+ [SigmaFinite γ] {m : ℕ} (hm : 1 ≤ m)
38
+ (F : Ω × (Fin m → ℝ) → ℝ≥0∞) (hF : Measurable F)
39
+ (hfin : (∫⁻ z, F z ∂γ.prod volume) ≠ ∞) :
40
+ ∀ᵐ z ∂γ.prod volume, Tendsto
41
+ (fun i : ℕ => (fiberSmoothing volume F
42
+ (fun y : Fin m → ℝ => ∏ j, gaussianPDF 0
43
+ ⟨(1/(i:ℝ))^2,sq_nonneg _⟩ (y j)) z).toReal)
44
+ atTop (𝓝 (F z).toReal) := by
45
+ have hmeas (i : ℕ) : Measurable (fun z => (fiberSmoothing volume F
46
+ (fun y : Fin m → ℝ => ∏ j, gaussianPDF 0
47
+ ⟨(1/(i:ℝ))^2,sq_nonneg _⟩ (y j)) z).toReal) :=
48
+ (measurable_fiberSmoothing volume hF (by fun_prop)).ennreal_toReal
49
+ rw [Measure.ae_prod_iff_ae_ae (measurableSet_tendsto_fun hmeas hF.ennreal_toReal)]
50
+ have hinner : (∫⁻ A, ∫⁻ y : Fin m → ℝ, F (A,y) ∂volume ∂γ) ≠ ∞ := by
51
+ rwa [← lintegral_prod _ hF.aemeasurable]
52
+ filter_upwards [ae_lt_top (Measurable.lintegral_prod_right
53
+ (show Measurable (fun z : Ω × (Fin m → ℝ) => F (z.1,z.2)) from hF)) hinner] with A hA
54
+ let ν : Measure (Fin m → ℝ) := volume.withDensity (fun y => F (A,y))
55
+ have hFA : Measurable (fun y : Fin m → ℝ => F (A,y)) :=
56
+ hF.comp (measurable_const.prodMk measurable_id)
57
+ let : IsFiniteMeasure ν := isFiniteMeasure_withDensity hA.ne
58
+ have hac : ν ≪ volume := withDensity_absolutelyContinuous _ _
59
+ have hRN := Measure.rnDeriv_withDensity volume hFA
60
+ filter_upwards [ae_tendsto_piGaussianConvolution hm ν hac, hRN] with y hy hyRN
61
+ rw [hyRN] at hy
62
+ convert hy.comp reciprocal_nat_tendsto using 1
63
+ ext i
64
+ exact (piGaussianConvolution_withDensity (fun y => F (A,y)) hFA _ y).symm
65
+
66
+ lemma pointwiseDensity_ae_eq {d m : ℕ} (hm : 1 ≤ m) (μ : Measure (Space d))
67
+ [IsFiniteMeasure μ] (F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ)
68
+ (hFm : Measurable F) (hF0 : ∀ x, 0 ≤ F x)
69
+ (hden : (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) =
70
+ ProjectionLaw μ m) :
71
+ PointwiseDensity μ m =ᵐ[MatrixLabelReference d m] F := by
72
+ have hfin : (∫⁻ z, ENNReal.ofReal (F z) ∂MatrixLabelReference d m) ≠ ∞ := by
73
+ have he := congrArg (fun ν => ν Set.univ) hden
74
+ rw [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] at he
75
+ rw [he]
76
+ let : IsFiniteMeasure (ProjectionLaw μ m) := by unfold ProjectionLaw; infer_instance
77
+ exact measure_ne_top _ _
78
+ have ht := ae_tendsto_fiberGaussian
79
+ (Measure.pi (fun _ : Fin m => stdGaussian (Space d))) hm
80
+ (fun x => ENNReal.ofReal (F x)) hFm.ennreal_ofReal hfin
81
+ have he (i : ℕ) := projectionSmoothing_ae_eq_fiberSmoothing μ m
82
+ (fun x => ENNReal.ofReal (F x)) hFm.ennreal_ofReal hden
83
+ (gaussianPDF 0 ⟨(1/(i:ℝ))^2,sq_nonneg _⟩) (measurable_gaussianPDF _ _)
84
+ filter_upwards [ht, ae_all_iff.mpr he] with x hx hxe
85
+ apply PointwiseDensity_eq_of_tendsto
86
+ rw [ENNReal.toReal_ofReal (hF0 x)] at hx
87
+ convert hx using 1
88
+ ext i
89
+ rw [GaussianRegularization_eq_toReal μ m _, hxe i]
90
+ end MemoryPrecision
91
+
92
+
93
+ end
94
+
95
+ end OAI
lean/OAI/Probability/MemoryPrecision/EllipsoidSuccess.lean ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.SuccessArithmetic
4
+ import OAI.Probability.MemoryPrecision.ZeroHorizon
5
+
6
+ namespace OAI
7
+
8
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
9
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
10
+
11
+ noncomputable section
12
+ universe u v
13
+
14
+
15
+ open MeasureTheory ProbabilityTheory Set Filter
16
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
17
+ namespace MemoryPrecision
18
+ open NoiselessRegression
19
+
20
+ lemma chord_real_coefficient {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
21
+ (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ]
22
+ (hL : L.Admissible ρ) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε)
23
+ {α : ℝ} (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) :
24
+ uniformChordSuccess L ρ ε ≤ ENNReal.ofReal
25
+ ((T+1:ℝ) * ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d (2^M)^BlockCount T (d/8))) := by
26
+ apply (chord_real_bound L ρ hL hd hε hαlo hαhi).trans_eq
27
+ rw [ENNReal.ofReal_mul (by positivity : (0:ℝ) ≤ T+1)]
28
+ congr 1
29
+ simp [ENNReal.ofReal_add]
30
+
31
+ lemma chord_half_sphere_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
32
+ (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ]
33
+ (hL : L.Admissible ρ) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1/10) :
34
+ uniformChordSuccess L ρ ε ≤ ENNReal.ofReal
35
+ (4^d * ε^(((d:ℝ)-1)/2) *
36
+ (SuccessConstant^d * (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^BlockCount T (d/8)) := by
37
+ by_cases hT : T = 0
38
+ · subst T
39
+ simp only [blockCount_zero, pow_zero, mul_one]
40
+ exact (chord_zero_bound L ρ hL (by omega) hε).trans
41
+ (ENNReal.ofReal_le_ofReal (terminal_angular_zero_bound hd hε hε1))
42
+ · have hb := chord_real_coefficient L ρ hL hd hε (le_refl (((d:ℝ)-1)/2)) (by linarith)
43
+ have he : (d:ℝ)-1-((d:ℝ)-1)/2 = ((d:ℝ)-1)/2 := by ring
44
+ rw [he] at hb
45
+ apply hb.trans (ENNReal.ofReal_le_ofReal ?_)
46
+ have hN : 1 ≤ 2^M := one_le_pow₀ (by norm_num)
47
+ have hNK : 2^M ≤ (d/8+2)*2^M := by
48
+ simp
49
+ have hs := stopping_step_bound_three hd hN hNK (by omega : 0 < T)
50
+ calc
51
+ _ = (4^d * ε^(((d:ℝ)-1)/2)) * (3*((T+1:ℝ)*RealStep d (2^M)^BlockCount T (d/8))) := by ring
52
+ _ ≤ _ := mul_le_mul_of_nonneg_left hs (by positivity)
53
+
54
+ lemma chord_half_ambient_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
55
+ (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ]
56
+ (hL : L.Admissible ρ) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) :
57
+ uniformChordSuccess L ρ ε ≤ ENNReal.ofReal
58
+ (12^d * ε^((d:ℝ)/2-1) *
59
+ (SuccessConstant^d * (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^BlockCount T (d/8)) := by
60
+ have hb := chord_real_coefficient L ρ hL hd hε (by linarith : ((d:ℝ)-1)/2 ≤ (d:ℝ)/2) le_rfl
61
+ have he : (d:ℝ)-1-(d:ℝ)/2 = (d:ℝ)/2-1 := by ring
62
+ rw [he] at hb
63
+ apply hb.trans (ENNReal.ofReal_le_ofReal ?_)
64
+ have hN : 1 ≤ 2^M := one_le_pow₀ (by norm_num)
65
+ have hNK : 2^M ≤ (2*(d/8)+4)*2^M := by
66
+ simp
67
+ have hR := realStep_pos d hN
68
+ have hs := stopping_step_bound hd hN hNK T
69
+ have hSp := stepConstant_pos
70
+ have hK : 2*StepConstant ≤ SuccessConstant := by dsimp [SuccessConstant]; linarith
71
+ have hroot : 0 ≤ (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)) := by positivity
72
+ have hbase := mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (by positivity : 0 ≤ 2*StepConstant) hK d) hroot
73
+ have hpow := pow_le_pow_left₀ (by positivity : 0 ≤ (2*StepConstant)^d *
74
+ (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ))) hbase (BlockCount T (d/8))
75
+ calc
76
+ _ = ((3*4^d:ℝ)*ε^((d:ℝ)/2-1))*((T+1:ℝ)*RealStep d (2^M)^BlockCount T (d/8)) := by ring
77
+ _ ≤ _ := mul_le_mul
78
+ (mul_le_mul_of_nonneg_right (cap_constant_le (by omega : 1 ≤ d)) (by positivity))
79
+ (hs.trans hpow) (by positivity) (by positivity)
80
+
81
+ def EllipsoidSuccessStatement : Prop :=
82
+ ∃ C C₀ : ℝ, 1 ≤ C ∧ 1 ≤ C₀ ∧
83
+ ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 →
84
+ ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ →
85
+ ∀ L : Learner d M T Ω, L.Admissible ρ →
86
+ L.uniformSuccess ρ ε ≤ min 1 (ENNReal.ofReal
87
+ (4^d * ε^(((d:ℝ)-1)/2) *
88
+ (C^d * (((d/8+2)*2^M : ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^(BlockCount T (d/8)))) ∧
89
+ uniformChordSuccess L ρ ε ≤ min 1 (ENNReal.ofReal
90
+ (C₀^d * ε^((d:ℝ)/2-1) *
91
+ (C^d * (((2*(d/8)+4)*2^M : ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^(BlockCount T (d/8)))) ∧
92
+ {z : UnitSphere d × (Ω × Samples d T) |
93
+ Learner.angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} ⊆
94
+ {z | dist (L.estimate z.1 z.2.1 z.2.2).val z.1.val ≤ ε}
95
+
96
+ theorem ellipsoid_success : EllipsoidSuccessStatement := by
97
+ refine ⟨SuccessConstant, 12, successConstant_one, by norm_num, ?_⟩
98
+ intro d M T hd ε hε hε1 Ω _ ρ hρ L hL
99
+ have : IsProbabilityMeasure ρ := hρ
100
+ let : NeZero d := ⟨by omega⟩
101
+ refine ⟨le_min ?_ ?_, le_min ?_ ?_, angular_event_subset_chord L ε⟩
102
+ · exact prob_le_one
103
+ · exact (angular_le_chord L ρ ε).trans (chord_half_sphere_bound L ρ hL hd hε hε1)
104
+ · exact prob_le_one
105
+ · exact chord_half_ambient_bound L ρ hL hd hε
106
+ end MemoryPrecision
107
+
108
+
109
+ end
110
+
111
+ end OAI
lean/OAI/Probability/MemoryPrecision/FiberDensity.lean ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.GaussianConvolution
4
+ import OAI.Probability.MemoryPrecision.PointwiseDensity
5
+ import OAI.Probability.MemoryPrecision.SphericalProjection
6
+
7
+ namespace OAI
8
+
9
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
10
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
11
+
12
+ noncomputable section
13
+ universe u v
14
+
15
+ open MeasureTheory ProbabilityTheory Set Filter
16
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
17
+ namespace MemoryPrecision
18
+ open NoiselessRegression
19
+
20
+ def PiGaussianConvolution {m : ℕ} (ν : Measure (Fin m → ℝ)) (δ : ℝ) (y : Fin m → ℝ) : ℝ :=
21
+ ∫ x, ∏ j, gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (y j - x j) ∂ν
22
+
23
+ lemma piGaussianConvolution_eq {m : ℕ} (ν : Measure (Fin m → ℝ)) (δ : ℝ) (y : Fin m → ℝ) :
24
+ PiGaussianConvolution ν δ y =
25
+ GaussianConvolution (ν.map (WithLp.toLp 2)) δ (WithLp.toLp 2 y) := by
26
+ unfold GaussianConvolution
27
+ rw [integral_map (WithLp.measurable_toLp 2 (Fin m → ℝ)).aemeasurable
28
+ ((show Continuous (fun x : Space m => GaussianKernel m δ (WithLp.toLp 2 y - x)) from
29
+ (gaussianKernel_continuous m δ).comp (continuous_const.sub continuous_id)).aestronglyMeasurable)]
30
+ rfl
31
+
32
+ lemma ae_tendsto_piGaussianConvolution {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Fin m → ℝ))
33
+ [IsFiniteMeasure ν] (hν : ν ≪ volume) :
34
+ ∀ᵐ y ∂(volume : Measure (Fin m → ℝ)), Tendsto (fun δ : ℝ => PiGaussianConvolution ν δ y)
35
+ (𝓝[>] (0:ℝ)) (𝓝 ((ν.rnDeriv volume y).toReal)) := by
36
+ let e := MeasurableEquiv.toLp 2 (Fin m → ℝ)
37
+ have hp : MeasurePreserving e volume volume := PiLp.volume_preserving_toLp (Fin m)
38
+ have hac : ν.map e ≪ volume := by
39
+ rw [← hp.map_eq]
40
+ exact hν.map e.measurable
41
+ have ht := ae_tendsto_gaussianConvolution hm (ν.map e) hac
42
+ have ht' : ∀ᵐ y ∂(volume : Measure (Fin m → ℝ)),
43
+ Tendsto (fun δ : ℝ => GaussianConvolution (ν.map e) δ (e y))
44
+ (𝓝[>] (0:ℝ)) (𝓝 (((ν.map e).rnDeriv volume (e y)).toReal)) := by
45
+ have ht0 : ∀ᵐ y ∂(volume.map e),
46
+ Tendsto (fun δ : ℝ => GaussianConvolution (ν.map e) δ y)
47
+ (𝓝[>] (0:ℝ)) (𝓝 (((ν.map e).rnDeriv volume y).toReal)) := by
48
+ rwa [hp.map_eq]
49
+ exact e.measurableEmbedding.ae_map_iff.mp ht0
50
+ have hRN := e.measurableEmbedding.rnDeriv_map ν volume
51
+ rw [hp.map_eq] at hRN
52
+ filter_upwards [ht', hRN] with y hy hyRN
53
+ rw [hyRN] at hy
54
+ simpa only [piGaussianConvolution_eq, e, MeasurableEquiv.coe_toLp] using hy
55
+
56
+ lemma GaussianRegularization_eq_convolution {d m : ℕ} (μ : Measure (Space d))
57
+ (A : Fin m → Space d) (δ : ℝ) (y : Fin m → ℝ) :
58
+ GaussianRegularization μ m δ (A,y) =
59
+ PiGaussianConvolution (μ.map (fun s => fun j => ⟪s,A j⟫)) δ y := by
60
+ unfold PiGaussianConvolution
61
+ rw [integral_map (by fun_prop)
62
+ (((show Continuous (fun x : Fin m → ℝ => ∏ j,
63
+ gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (y j - x j)) from
64
+ by unfold gaussianPDFReal; fun_prop)).aestronglyMeasurable)]
65
+ rfl
66
+
67
+ lemma ae_tendsto_GaussianRegularization {d m : ℕ} (hm : 1 ≤ m) (μ : Measure (Space d))
68
+ [IsFiniteMeasure μ] (A : Fin m → Space d)
69
+ (hA : μ.map (fun s => fun j => ⟪s,A j⟫) ≪ (volume : Measure (Fin m → ℝ))) :
70
+ ∀ᵐ y ∂(volume : Measure (Fin m → ℝ)), Tendsto
71
+ (fun δ : ℝ => GaussianRegularization μ m δ (A,y)) (𝓝[>] (0:ℝ))
72
+ (𝓝 (((μ.map (fun s => fun j => ⟪s,A j⟫)).rnDeriv volume y).toReal)) := by
73
+ simpa only [GaussianRegularization_eq_convolution] using
74
+ ae_tendsto_piGaussianConvolution hm (μ.map (fun s => fun j => ⟪s,A j⟫)) hA
75
+
76
+ lemma reciprocal_nat_tendsto :
77
+ Tendsto (fun i : ℕ => 1/(i:ℝ)) atTop (𝓝[>] (0:ℝ)) := by
78
+ refine tendsto_nhdsWithin_iff.mpr ⟨tendsto_one_div_atTop_nhds_zero_nat, ?_⟩
79
+ filter_upwards [eventually_gt_atTop (0:ℕ)] with i hi
80
+ change 0 < 1/(i:ℝ)
81
+ positivity
82
+
83
+ lemma pointwiseDensity_fiber {d m : ℕ} (hm : 1 ≤ m) (μ : Measure (Space d))
84
+ [IsFiniteMeasure μ] (A : Fin m → Space d)
85
+ (hA : μ.map (fun s => fun j => ⟪s,A j⟫) ≪ (volume : Measure (Fin m → ℝ))) :
86
+ (volume : Measure (Fin m → ℝ)).withDensity
87
+ (fun y => ENNReal.ofReal (PointwiseDensity μ m (A,y))) =
88
+ μ.map (fun s => fun j => ⟪s,A j⟫) := by
89
+ let ν := μ.map (fun s => fun j => ⟪s,A j⟫)
90
+ have he : (fun y => ENNReal.ofReal (PointwiseDensity μ m (A,y))) =ᵐ[volume]
91
+ ν.rnDeriv volume := by
92
+ filter_upwards [ae_tendsto_GaussianRegularization hm μ A hA, ν.rnDeriv_lt_top volume]
93
+ with y hy hyfin
94
+ rw [PointwiseDensity_eq_of_tendsto μ (A,y) (hy.comp reciprocal_nat_tendsto)]
95
+ exact ENNReal.ofReal_toReal hyfin.ne
96
+ rw [withDensity_congr_ae he]
97
+ exact Measure.withDensity_rnDeriv_eq _ _ hA
98
+
99
+ lemma pointwiseDensity_fullRank {d m : ℕ} (hd : 2 ≤ d) (hm : 1 ≤ m) (hmd : m < d)
100
+ (μ : Measure (Space d)) [IsFiniteMeasure μ] (hμ : μ ≪ UniformSphere d)
101
+ (A : Fin m → Space d) (hA : LinearIndependent ℝ A) :
102
+ (volume : Measure (Fin m → ℝ)).withDensity
103
+ (fun y => ENNReal.ofReal (PointwiseDensity μ m (A,y))) =
104
+ μ.map (fun s => fun j => ⟪s,A j⟫) :=
105
+ pointwiseDensity_fiber hm μ A (spherical_projection_ac hd hmd A hA μ hμ)
106
+ end MemoryPrecision
107
+
108
+
109
+ end
110
+
111
+ end OAI
lean/OAI/Probability/MemoryPrecision/FiniteDensity.lean ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.DensityPassage
4
+ import OAI.Probability.MemoryPrecision.SharpGaussian
5
+
6
+ namespace OAI
7
+
8
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
9
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
10
+
11
+ noncomputable section
12
+ universe u v
13
+
14
+
15
+ open MeasureTheory ProbabilityTheory Set Filter
16
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
17
+ namespace MemoryPrecision
18
+ open NoiselessRegression
19
+
20
+ def MatrixLabelReference (d m : ℕ) : @Measure ((Fin m → Space d) × (Fin m → ℝ))
21
+ (@MeasurableSpace.prod (Fin m → Space d) (Fin m → ℝ)
22
+ (@MeasurableSpace.pi (Fin m) (fun _ => Space d)
23
+ (fun _ => WithLp.measurableSpace
24
+ (@OfNat.ofNat ℝ≥0∞ 2
25
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
26
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ)))
27
+ inferInstance) :=
28
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
29
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
30
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
31
+ let euclideanMeasurable := WithLp.measurableSpace exponent (Fin d → ℝ)
32
+ let rowMeasurable := @MeasurableSpace.pi (Fin m) (fun _ => Space d)
33
+ (fun _ => euclideanMeasurable)
34
+ let rowLaw := @Measure.pi (Fin m) (fun _ => Space d) inferInstance
35
+ (fun _ => euclideanMeasurable)
36
+ (fun _ => @stdGaussian (Space d)
37
+ (PiLp.normedAddCommGroup exponent (fun _ : Fin d => ℝ))
38
+ (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))
39
+ inferInstance euclideanMeasurable)
40
+ @Measure.prod _ _ rowMeasurable inferInstance rowLaw volume
41
+
42
+ def ProjectionLaw {d : ℕ}
43
+ (μ : @Measure (Space d)
44
+ (WithLp.measurableSpace
45
+ (@OfNat.ofNat ℝ≥0∞ 2
46
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
47
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ)))
48
+ (m : ℕ) : @Measure ((Fin m → Space d) × (Fin m → ℝ))
49
+ (@MeasurableSpace.prod (Fin m → Space d) (Fin m → ℝ)
50
+ (@MeasurableSpace.pi (Fin m) (fun _ => Space d)
51
+ (fun _ => WithLp.measurableSpace
52
+ (@OfNat.ofNat ℝ≥0∞ 2
53
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
54
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ)))
55
+ inferInstance) :=
56
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
57
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
58
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
59
+ let euclideanMeasurable := WithLp.measurableSpace exponent (Fin d → ℝ)
60
+ let rowMeasurable := @MeasurableSpace.pi (Fin m) (fun _ => Space d)
61
+ (fun _ => euclideanMeasurable)
62
+ let rowLaw := @Measure.pi (Fin m) (fun _ => Space d) inferInstance
63
+ (fun _ => euclideanMeasurable)
64
+ (fun _ => @stdGaussian (Space d)
65
+ (PiLp.normedAddCommGroup exponent (fun _ : Fin d => ℝ))
66
+ (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))
67
+ inferInstance euclideanMeasurable)
68
+ @Measure.map ((Fin m → Space d) × Space d) ((Fin m → Space d) × (Fin m → ℝ))
69
+ (@MeasurableSpace.prod _ _ rowMeasurable euclideanMeasurable)
70
+ (@MeasurableSpace.prod _ _ rowMeasurable inferInstance)
71
+ (fun pair => (pair.1, fun index => @inner ℝ (Space d)
72
+ (@InnerProductSpace.toInner ℝ (Space d) _
73
+ (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ))
74
+ (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ)))
75
+ pair.2 (pair.1 index)))
76
+ (@Measure.prod _ _ rowMeasurable euclideanMeasurable rowLaw μ)
77
+ def ProjectedEllipsoid {d m : ℕ} (z : Space d) (R : ℝ) :
78
+ Set ((Fin m → Space d) × (Fin m → ℝ)) :=
79
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
80
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
81
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
82
+ let euclideanInner := @InnerProductSpace.toInner ℝ (Space d) _
83
+ (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ))
84
+ (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))
85
+ {pair | ∃ displacement ∈ @Metric.closedBall (Space d)
86
+ (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ))
87
+ (WithLp.toLp exponent (fun _ => (0 : ℝ))) R,
88
+ pair.2 = fun index => @inner ℝ (Space d) euclideanInner z (pair.1 index) +
89
+ @inner ℝ (Space d) euclideanInner displacement (pair.1 index)}
90
+ def ProjectionNormScale (m p : ℕ) (H β R : ℝ) : ℝ :=
91
+ let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast
92
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
93
+ (two * Real.pi) ^ (-(m : ℝ) * ((p : ℝ)-1) / (two*(p : ℝ))) * H *
94
+ R ^ (β - (m : ℝ)*(1-1/(p : ℝ))) *
95
+ (∏ j ∈ Finset.range (p-1), J β m j) ^ (1/(p : ℝ))
96
+
97
+ lemma isClosed_projectedEllipsoid {d m : ℕ} (z : Space d) (R : ℝ) :
98
+ IsClosed (ProjectedEllipsoid (m := m) z R) := by
99
+ let K := Metric.closedBall (0 : Space d) R
100
+ have hK : IsCompact K := isCompact_closedBall _ _
101
+ let : CompactSpace K := isCompact_iff_compactSpace.mp hK
102
+ let D : Set (((Fin m → Space d) × (Fin m → ℝ)) × K) :=
103
+ {w | w.1.2 = fun j => ⟪z, w.1.1 j⟫ + ⟪(w.2 : Space d), w.1.1 j⟫}
104
+ have hD : IsClosed D := isClosed_eq (by fun_prop) (by fun_prop)
105
+ have he : ProjectedEllipsoid (m := m) z R = Prod.fst '' D := by
106
+ ext Ay
107
+ constructor
108
+ · rintro ⟨v, hv, he⟩
109
+ exact ⟨(Ay, ⟨v,hv⟩), he, rfl⟩
110
+ · rintro ⟨⟨Ay,v⟩, hv, rfl⟩
111
+ exact ⟨v, v.property, hv⟩
112
+ rw [he]
113
+ exact isClosedMap_fst_of_compactSpace D hD
114
+
115
+ lemma projectionLaw_ellipsoid_compl {d m : ℕ} (μ : Measure (Space d)) [IsFiniteMeasure μ]
116
+ {z : Space d} {R : ℝ} (hsupport : μ.support ⊆ Metric.closedBall z R) :
117
+ projectionLaw μ m (ProjectedEllipsoid z R)ᶜ = 0 := by
118
+ rw [projectionLaw, Measure.map_apply (by fun_prop)
119
+ (isClosed_projectedEllipsoid z R).measurableSet.compl]
120
+ apply measure_mono_null (t := Set.univ ×ˢ μ.supportᶜ)
121
+ · rintro ⟨A,s⟩ hs
122
+ refine ⟨mem_univ _, ?_⟩
123
+ intro hss
124
+ apply hs
125
+ refine ⟨s-z, ?_, ?_⟩
126
+ · change dist (s - z) (0 : Space d) ≤ R
127
+ simpa [Metric.mem_closedBall, dist_eq_norm] using hsupport hss
128
+ · ext j
129
+ simp [inner_sub_left]
130
+ · rw [Measure.prod_prod]
131
+ simp [μ.measure_compl_support]
132
+
133
+ lemma projectionNormScale_pos {m p : ℕ} {H β R : ℝ} (hp : 2 ≤ p) (hH : 0 < H)
134
+ (hR : 0 < R) (hgap : (m:ℝ)+(p:ℝ)-2 < β) :
135
+ 0 < ProjectionNormScale m p H β R := by
136
+ have hJ : 0 < ∏ j ∈ Finset.range (p-1), J β m j := by
137
+ apply Finset.prod_pos
138
+ intro j hj
139
+ apply J_pos
140
+ have hj' : j+2 ≤ p := by have := Finset.mem_range.mp hj; omega
141
+ have hj'' : (j:ℝ)+2 ≤ p := by exact_mod_cast hj'
142
+ linarith
143
+ unfold ProjectionNormScale
144
+ positivity
145
+
146
+ lemma moment_root_eq_scale {m p : ℕ} {H β R : ℝ} (hp : 2 ≤ p) (hH : 0 < H)
147
+ (hR : 0 < R) (hgap : (m:ℝ)+(p:ℝ)-2 < β) :
148
+ (gaussianPeak ^ ((p-1)*m) * ENNReal.ofReal
149
+ (H^p * R^(β*(p:ℝ)-(m:ℝ)*((p-1:ℕ):ℝ)) * ∏ j : Fin (p-1), J β m j)) ^ (1/(p:ℝ)) =
150
+ ENNReal.ofReal (ProjectionNormScale m p H β R) := by
151
+ have hp0 : (p:ℝ) ≠ 0 := by exact_mod_cast (by omega : p ≠ 0)
152
+ have hp1 : 1 ≤ p := by omega
153
+ have hprod : 0 < ∏ j : Fin (p-1), J β m j := by
154
+ apply Finset.prod_pos
155
+ intro j _
156
+ apply J_pos
157
+ have hj : (j:ℝ)+2 ≤ p := by exact_mod_cast (show (j:ℕ)+2 ≤ p by have := j.isLt; omega)
158
+ linarith
159
+ have hpi : 0 < 2 * Real.pi := by positivity
160
+ rw [ENNReal.mul_rpow_of_nonneg _ _ (by positivity), gaussianPeak,
161
+ ← ENNReal.ofReal_pow (by positivity), ENNReal.ofReal_rpow_of_pos (by positivity),
162
+ ENNReal.ofReal_rpow_of_pos (by positivity), ← ENNReal.ofReal_mul (by positivity)]
163
+ congr 1
164
+ rw [Real.mul_rpow (by positivity : 0 ≤ H^p * R^(β*p-m*((p-1:ℕ):ℝ))) hprod.le,
165
+ Real.mul_rpow (by positivity : 0 ≤ H^p) (by positivity),
166
+ ← Real.rpow_natCast_mul hH.le, mul_one_div_cancel hp0, Real.rpow_one,
167
+ ← Real.rpow_mul hR.le,
168
+ ← Real.rpow_natCast_mul (by positivity : 0 ≤ (Real.sqrt (2*Real.pi))⁻¹),
169
+ Real.inv_rpow (by positivity), Real.sqrt_eq_rpow, ← Real.rpow_mul hpi.le,
170
+ ← Real.rpow_neg hpi.le]
171
+ have he1 : -(1/2 * (((p-1:ℕ):ℝ)*(m:ℝ) * (1/(p:ℝ)))) =
172
+ -(m:ℝ)*((p:ℝ)-1)/(2*(p:ℝ)) := by rw [Nat.cast_sub hp1]; push_cast; ring
173
+ have he2 : (β*(p:ℝ)-(m:ℝ)*((p-1:ℕ):ℝ)) * (1/(p:ℝ)) =
174
+ β-(m:ℝ)*(1-1/(p:ℝ)) := by rw [Nat.cast_sub hp1]; push_cast; field_simp
175
+ simp only [Nat.cast_mul] at *
176
+ rw [he1, he2, Fin.prod_univ_eq_prod_range]
177
+ unfold ProjectionNormScale
178
+ ring
179
+
180
+ local instance final_reference_sigmaFinite (d m : ℕ) :
181
+ SigmaFinite (matrixLabelReference (E := Space d) m) := by
182
+ unfold matrixLabelReference
183
+ infer_instance
184
+ local instance final_projection_finite {d : ℕ} (μ : Measure (Space d)) [IsFiniteMeasure μ] (m : ℕ) :
185
+ IsFiniteMeasure (projectionLaw μ m) := by
186
+ unfold projectionLaw
187
+ infer_instance
188
+
189
+ lemma exact_finite_density (d m p : ℕ) (hp : 2 ≤ p) (hm : 1 ≤ m)
190
+ (β H R : ℝ) (hgap : (m:ℝ)+(p:ℝ)-2 < β) (hH : 0 < H) (hR : 0 < R)
191
+ (z : Space d) (μ : Measure (Space d)) [IsFiniteMeasure μ]
192
+ (hsupport : μ.support ⊆ Metric.closedBall z R) (hball : AmbientBallBound μ H β) :
193
+ ∃ F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ,
194
+ Measurable F ∧ (∀ x, 0 ≤ F x) ∧
195
+ (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) =
196
+ ProjectionLaw μ m ∧
197
+ (∀ᵐ x ∂MatrixLabelReference d m, x ∉ ProjectedEllipsoid z R → F x = 0) ∧
198
+ eLpNorm F (p : ℝ≥0∞) (MatrixLabelReference d m) ≤
199
+ ENNReal.ofReal (ProjectionNormScale m p H β R) := by
200
+ let C := gaussianPeak ^ ((p-1)*m) * ENNReal.ofReal
201
+ (H^p * R^(β*(p:ℝ)-(m:ℝ)*((p-1:ℕ):ℝ)) * ∏ j : Fin (p-1), J β m j)
202
+ have hC : C ≠ ∞ := by unfold C gaussianPeak; finiteness
203
+ have hp1 : p-1+1 = p := by omega
204
+ have hmom : ∀ φ : ℝ → ℝ≥0∞, Measurable φ → (∫⁻ x, φ x = 1) →
205
+ (∫⁻ Ay, projectionSmoothing μ φ m Ay ^ (p-1+1) ∂matrixLabelReference m) ≤ C := by
206
+ intro φ hφ hφ1
207
+ have hg : ((p-1:ℕ):ℝ)+(m:ℝ)-1 < β := by
208
+ rw [Nat.cast_sub (by omega : 1 ≤ p)]
209
+ push_cast
210
+ linarith
211
+ simpa only [hp1] using sharp_projectionSmoothing_moment hH hR hsupport hball φ hφ hφ1 hm (p-1) hg
212
+ have hac := projectionLaw_ac_of_moment μ m (p-1) (by omega) C hC hmom
213
+ let G := (projectionLaw μ m).rnDeriv (matrixLabelReference m)
214
+ have hG : Measurable G := Measure.measurable_rnDeriv _ _
215
+ have hden : (matrixLabelReference m).withDensity G = projectionLaw μ m :=
216
+ Measure.withDensity_rnDeriv_eq _ _ hac
217
+ have hGtop : ∀ᵐ x ∂matrixLabelReference m, G x ≠ ∞ := Measure.rnDeriv_ne_top _ _
218
+ have hGmom : (∫⁻ x, G x^p ∂matrixLabelReference m) ≤ C := by
219
+ simpa only [hp1] using projectionLaw_rnDeriv_moment μ m (p-1) (by omega) C hC hmom
220
+ let F := fun x => (G x).toReal
221
+ have hFG : (fun x => ENNReal.ofReal (F x)) =ᵐ[matrixLabelReference m] G := by
222
+ filter_upwards [hGtop] with x hx
223
+ exact ENNReal.ofReal_toReal hx
224
+ refine ⟨F, hG.ennreal_toReal, fun _ => ENNReal.toReal_nonneg, ?_, ?_, ?_⟩
225
+ · change (matrixLabelReference m).withDensity _ = projectionLaw μ m
226
+ rw [withDensity_congr_ae hFG, hden]
227
+ · have hnull := projectionLaw_ellipsoid_compl μ hsupport (m := m)
228
+ rw [← hden, withDensity_apply _ (isClosed_projectedEllipsoid z R).measurableSet.compl] at hnull
229
+ have hz := (lintegral_eq_zero_iff' hG.aemeasurable).mp hnull
230
+ change ∀ᵐ x ∂(matrixLabelReference m).restrict (ProjectedEllipsoid z R)ᶜ, G x = 0 at hz
231
+ rw [ae_restrict_iff' (isClosed_projectedEllipsoid z R).measurableSet.compl] at hz
232
+ filter_upwards [hz] with x hx hnot
233
+ dsimp [F]
234
+ rw [hx hnot]
235
+ rfl
236
+ · change eLpNorm F (p:ℝ≥0∞) (matrixLabelReference m) ≤ _
237
+ rw [eLpNorm_eq_lintegral_rpow_enorm_toReal (by exact_mod_cast (by omega : p ≠ 0))
238
+ (by finiteness) hG.ennreal_toReal.aestronglyMeasurable]
239
+ simp only [ENNReal.toReal_natCast]
240
+ have he : (fun x => ‖F x‖ₑ ^ (p:ℝ)) =ᵐ[matrixLabelReference m] (fun x => G x^p) := by
241
+ filter_upwards [hFG] with x hx
242
+ rw [Real.enorm_eq_ofReal ENNReal.toReal_nonneg, hx, ENNReal.rpow_natCast]
243
+ rw [lintegral_congr_ae he]
244
+ exact (ENNReal.rpow_le_rpow hGmom (by positivity)).trans_eq
245
+ (moment_root_eq_scale hp hH hR hgap)
246
+
247
+ def FiniteDensityStatement : Prop :=
248
+ let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast
249
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
250
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
251
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
252
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
253
+ ∀ d m p : ℕ,
254
+ letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ)
255
+ 1 ≤ d → 1 ≤ m → 2 ≤ p →
256
+ ∀ β H R : ℝ, (m : ℝ)+(p : ℝ)-two < β → 0 < H → 0 < R →
257
+ ∀ z : Space d, ∀ μ : Measure (Space d), IsFiniteMeasure μ →
258
+ @Measure.support (Space d)
259
+ (PiLp.topologicalSpace (p := exponent) (β := fun _ : Fin d => ℝ))
260
+ (WithLp.measurableSpace exponent (Fin d → ℝ)) μ ⊆
261
+ @Metric.closedBall (Space d)
262
+ (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ)) z R →
263
+ AmbientBallBound μ H β →
264
+ ∃ F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ,
265
+ Measurable F ∧ (∀ x, 0 ≤ F x) ∧
266
+ (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) =
267
+ ProjectionLaw μ m ∧
268
+ (∀ᵐ x ∂MatrixLabelReference d m, x ∉ ProjectedEllipsoid z R → F x = 0) ∧
269
+ eLpNorm F (p : ℝ≥0∞) (MatrixLabelReference d m) ≤
270
+ ENNReal.ofReal (ProjectionNormScale m p H β R)
271
+
272
+ theorem finite_density : FiniteDensityStatement := by
273
+ intro d m p _ hm hp β H R hgap hH hR z μ hμ hs hb
274
+ let := hμ
275
+ exact exact_finite_density d m p hp hm β H R hgap hH hR z μ hs hb
276
+ end MemoryPrecision
277
+
278
+
279
+ end
280
+
281
+ end OAI
lean/OAI/Probability/MemoryPrecision/GaussianConvolution.lean ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.BallAverages
4
+
5
+ namespace OAI
6
+
7
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
8
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
9
+
10
+ noncomputable section
11
+ universe u v
12
+
13
+ open MeasureTheory ProbabilityTheory Set Filter
14
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
15
+ namespace MemoryPrecision
16
+ open NoiselessRegression
17
+
18
+ lemma gaussianKernel_translated_ball_mixture (m : ℕ) (hm : 1 ≤ m) {δ : ℝ} (hδ : 0 < δ)
19
+ (y x : Space m) :
20
+ ENNReal.ofReal (GaussianKernel m δ (y-x)) =
21
+ ∫⁻ r in Ioi 0, (Metric.ball y r).indicator
22
+ (fun _ => ENNReal.ofReal ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m))) x := by
23
+ rw [gaussianKernel_ball_mixture m hm hδ]
24
+ apply lintegral_congr
25
+ intro r
26
+ have he : y-x ∈ Metric.ball (0 : Space m) r ↔ x ∈ Metric.ball y r := by
27
+ simp only [Metric.mem_ball, dist_eq_norm, sub_zero, norm_sub_rev]
28
+ by_cases hx : x ∈ Metric.ball y r
29
+ · rw [Set.indicator_of_mem (he.mpr hx), Set.indicator_of_mem hx]
30
+ · rw [Set.indicator_of_notMem (mt he.mp hx), Set.indicator_of_notMem hx]
31
+
32
+ def GaussianConvolution {m : ℕ} (ν : Measure (Space m)) (δ : ℝ) (y : Space m) : ℝ :=
33
+ ∫ x, GaussianKernel m δ (y-x) ∂ν
34
+
35
+ lemma gaussianConvolution_shell {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m))
36
+ [IsFiniteMeasure ν] {δ : ℝ} (hδ : 0 < δ) (y : Space m) :
37
+ GaussianConvolution ν δ y = ∫ r in Ioi 0,
38
+ ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m)) * (ν (Metric.ball y r)).toReal := by
39
+ have hk : Measurable (GaussianKernel m δ) := (gaussianKernel_continuous m δ).measurable
40
+ have hmeas : Measurable (fun z : Space m × ℝ =>
41
+ (Metric.ball y z.2).indicator
42
+ (fun _ => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) z.1) := by
43
+ have he : (fun z : Space m × ℝ => (Metric.ball y z.2).indicator
44
+ (fun _ => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) z.1) =
45
+ {z : Space m × ℝ | dist z.1 y < z.2}.indicator
46
+ (fun z => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) := by
47
+ ext z
48
+ by_cases hz : z.1 ∈ Metric.ball y z.2
49
+ · rw [Set.indicator_of_mem hz, Set.indicator_of_mem
50
+ (show z ∈ {z : Space m × ℝ | dist z.1 y < z.2} from hz)]
51
+ · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem
52
+ (show z ∉ {z : Space m × ℝ | dist z.1 y < z.2} from hz)]
53
+ rw [he]
54
+ exact (by fun_prop : Measurable (fun z : Space m × ℝ =>
55
+ ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m)))).indicator
56
+ (measurableSet_lt (by fun_prop) (by fun_prop))
57
+ unfold GaussianConvolution
58
+ rw [integral_eq_lintegral_of_nonneg_ae
59
+ (Eventually.of_forall (fun _ => gaussianKernel_nonneg m δ _))
60
+ ((hk.comp (by fun_prop)).aestronglyMeasurable)]
61
+ simp_rw [gaussianKernel_translated_ball_mixture m hm hδ y]
62
+ rw [lintegral_lintegral_swap hmeas.aemeasurable]
63
+ simp_rw [lintegral_indicator Metric.isOpen_ball.measurableSet, setLIntegral_const]
64
+ have hmass : Measurable (fun r : ℝ => (ν (Metric.ball y r)).toReal) :=
65
+ (show Monotone (fun r : ℝ => ν (Metric.ball y r)) from
66
+ fun a b h => measure_mono (Metric.ball_subset_ball h)).measurable.ennreal_toReal
67
+ rw [integral_eq_lintegral_of_nonneg_ae
68
+ ((ae_restrict_mem measurableSet_Ioi).mono (fun r hr =>
69
+ mul_nonneg (mul_nonneg (div_nonneg hr.le (sq_nonneg δ)) (gaussianKernel_nonneg m δ _))
70
+ ENNReal.toReal_nonneg)) (by fun_prop)]
71
+ congr 1
72
+ apply lintegral_congr_ae
73
+ filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr
74
+ rw [ENNReal.ofReal_mul (mul_nonneg (div_nonneg hr.le (sq_nonneg δ))
75
+ (gaussianKernel_nonneg m δ _)), ENNReal.ofReal_toReal (measure_ne_top _ _)]
76
+
77
+ lemma gaussianConvolution_mixture {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m))
78
+ [IsFiniteMeasure ν] {δ : ℝ} (hδ : 0 < δ) (y : Space m) :
79
+ GaussianConvolution ν δ y = ∫ r in Ioi 0, RadialMixture m δ r * BallAverage ν y r := by
80
+ rw [gaussianConvolution_shell hm ν hδ y]
81
+ apply integral_congr_ae
82
+ filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr
83
+ have hr0 : 0 < r := hr
84
+ unfold RadialMixture BallAverage
85
+ field_simp [(unitBallVolume_pos m).ne', hr0.ne']
86
+
87
+ lemma gaussianConvolution_scaled_mixture {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m))
88
+ [IsFiniteMeasure ν] {δ : ℝ} (hδ : 0 < δ) (y : Space m) :
89
+ GaussianConvolution ν δ y = ∫ r in Ioi 0, RadialMixture m 1 r * BallAverage ν y (δ*r) := by
90
+ rw [gaussianConvolution_mixture hm ν hδ y]
91
+ have he := integral_comp_mul_left_Ioi'
92
+ (fun r => RadialMixture m δ r * BallAverage ν y r) 0 hδ
93
+ simp only [mul_zero, smul_eq_mul] at he
94
+ rw [← he, ← integral_const_mul]
95
+ apply integral_congr_ae
96
+ exact Eventually.of_forall (fun radius => by
97
+ dsimp only
98
+ rw [radialMixture_scale m hδ]
99
+ field_simp [hδ.ne'])
100
+
101
+ lemma ae_tendsto_gaussianConvolution {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m))
102
+ [IsFiniteMeasure ν] (hν : ν ≪ volume) :
103
+ ∀ᵐ y ∂(volume : Measure (Space m)), Tendsto (fun δ : ℝ => GaussianConvolution ν δ y)
104
+ (𝓝[>] (0:ℝ)) (𝓝 ((ν.rnDeriv volume y).toReal)) := by
105
+ filter_upwards [ae_tendsto_ballAverage hm ν hν] with y hy
106
+ apply (tendsto_radial_average hm ν y ENNReal.toReal_nonneg hy).congr'
107
+ filter_upwards [self_mem_nhdsWithin] with δ hδ
108
+ exact (gaussianConvolution_scaled_mixture hm ν hδ y).symm
109
+ end MemoryPrecision
110
+
111
+
112
+ end
113
+
114
+ end OAI
lean/OAI/Probability/MemoryPrecision/JointL1.lean ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.FiniteDensity
4
+ import OAI.Probability.MemoryPrecision.KernelModel
5
+ import OAI.Probability.MemoryPrecision.LabelTranslations
6
+
7
+ namespace OAI
8
+
9
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
10
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
11
+
12
+ noncomputable section
13
+ universe u v
14
+
15
+ open MeasureTheory ProbabilityTheory Set Filter
16
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
17
+ namespace MemoryPrecision
18
+ open NoiselessRegression
19
+ def UniformSphere (d : ℕ) : @Measure (Space d)
20
+ (WithLp.measurableSpace
21
+ (@OfNat.ofNat ℝ≥0∞ 2
22
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
23
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ)) :=
24
+ let euclideanMeasurable := WithLp.measurableSpace
25
+ (@OfNat.ofNat ℝ≥0∞ 2
26
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
27
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ)
28
+ @Measure.map (Kernel.Sphere d) (Space d)
29
+ (MeasurableSpace.comap Subtype.val euclideanMeasurable) euclideanMeasurable
30
+ Subtype.val (Kernel.UniformSphere d)
31
+
32
+ def GaussianRegularization {d : ℕ}
33
+ (μ : @Measure (Space d)
34
+ (WithLp.measurableSpace
35
+ (@OfNat.ofNat ℝ≥0∞ 2
36
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
37
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ)))
38
+ (m : ℕ) (δ : ℝ)
39
+ (Ay : (Fin m → Space d) × (Fin m → ℝ)) : ℝ :=
40
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
41
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
42
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
43
+ letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ)
44
+ ∫ signal, ∏ index, gaussianPDFReal 0 ⟨δ^2, sq_nonneg δ⟩
45
+ (Ay.2 index - @inner ℝ (Space d)
46
+ (@InnerProductSpace.toInner ℝ (Space d) _
47
+ (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ))
48
+ (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ)))
49
+ signal (Ay.1 index)) ∂μ
50
+
51
+ lemma gaussianPDF_zero_sub_comm (v : ℝ≥0) (a b : ℝ) :
52
+ gaussianPDF 0 v (a-b) = gaussianPDF 0 v (b-a) := by
53
+ simp only [gaussianPDF, gaussianPDFReal, sub_zero]
54
+ congr 4
55
+ ring
56
+
57
+ lemma GaussianRegularization_eq_toReal {d : ℕ} (μ : Measure (Space d))
58
+ [IsFiniteMeasure μ] (m : ℕ) (δ : ℝ)
59
+ (x : (Fin m → Space d) × (Fin m → ℝ)) :
60
+ GaussianRegularization μ m δ x =
61
+ (projectionSmoothing μ (gaussianPDF 0 ⟨δ^2,sq_nonneg δ⟩) m x).toReal := by
62
+ let v : ℝ≥0 := ⟨δ^2,sq_nonneg δ⟩
63
+ change (∫ s, ∏ j, gaussianPDFReal 0 v (x.2 j - ⟪s,x.1 j⟫) ∂μ) = _
64
+ have hn : ∀ s : Space d, 0 ≤ ∏ j, gaussianPDFReal 0 v (x.2 j - ⟪s,x.1 j⟫) :=
65
+ fun s => Finset.prod_nonneg (fun _ _ => gaussianPDFReal_nonneg _ _ _)
66
+ have hm : Measurable (fun s : Space d => ∏ j, gaussianPDFReal 0 v (x.2 j - ⟪s,x.1 j⟫)) := by
67
+ fun_prop
68
+ rw [integral_eq_lintegral_of_nonneg_ae (Eventually.of_forall hn) hm.aestronglyMeasurable]
69
+ unfold projectionSmoothing
70
+ congr 1
71
+ apply lintegral_congr
72
+ intro s
73
+ rw [ENNReal.ofReal_prod_of_nonneg (fun _ _ => gaussianPDFReal_nonneg _ _ _)]
74
+ rfl
75
+
76
+ lemma GaussianRegularization_ae_eq_average {d : ℕ} (μ : Measure (Space d))
77
+ [IsFiniteMeasure μ] (m : ℕ)
78
+ (F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ)
79
+ (hF : Measurable F) (hF0 : ∀ x, 0 ≤ F x)
80
+ (hden : (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) =
81
+ ProjectionLaw μ m) (δ : ℝ) (hδ : δ ≠ 0) :
82
+ GaussianRegularization μ m δ =ᵐ[MatrixLabelReference d m]
83
+ averageTranslate (Measure.pi (fun _ : Fin m => gaussianReal 0 1)) δ F := by
84
+ have he := projectionSmoothing_ae_eq_fiberSmoothing μ m
85
+ (fun x => ENNReal.ofReal (F x)) hF.ennreal_ofReal hden
86
+ (gaussianPDF 0 ⟨δ^2,sq_nonneg δ⟩) (measurable_gaussianPDF _ _)
87
+ filter_upwards [he] with x hx
88
+ rw [GaussianRegularization_eq_toReal, hx]
89
+ unfold averageTranslate
90
+ rw [integral_eq_lintegral_of_nonneg_ae (Eventually.of_forall (fun u => hF0 _))
91
+ ((hF.comp (by fun_prop)).aestronglyMeasurable)]
92
+ congr 1
93
+ change fiberSmoothing volume (fun x => ENNReal.ofReal (F x))
94
+ (fun y : Fin m → ℝ => ∏ j, gaussianPDF 0 _ (y j)) x =
95
+ ∫⁻ u : Fin m → ℝ, ENNReal.ofReal (F (x.1,fun j => x.2 j + δ * u j))
96
+ ∂Measure.pi (fun _ => gaussianReal 0 1)
97
+ rw [lintegral_gaussian_shift_scale m δ hδ x.2 (fun y => ENNReal.ofReal (F (x.1,y)))
98
+ (by fun_prop)]
99
+ apply lintegral_congr
100
+ intro y
101
+ congr 1
102
+ apply Finset.prod_congr rfl
103
+ intro j _
104
+ exact gaussianPDF_zero_sub_comm _ _ _
105
+
106
+ lemma memLp_density_of_finite {X : Type*} [MeasurableSpace X]
107
+ (ν₀ η : Measure X) [IsFiniteMeasure η] {F : X → ℝ}
108
+ (hFm : Measurable F) (hF0 : ∀ x, 0 ≤ F x)
109
+ (hden : ν₀.withDensity (fun x => ENNReal.ofReal (F x)) = η) :
110
+ MemLp F 1 ν₀ := by
111
+ rw [memLp_iff, eLpNorm_one_eq_lintegral_enorm hFm.aestronglyMeasurable]
112
+ have he : (fun x => ‖F x‖ₑ) = (fun x => ENNReal.ofReal (F x)) := by
113
+ funext x
114
+ exact Real.enorm_eq_ofReal (hF0 x)
115
+ rw [he]
116
+ have he2 := congrArg (fun ν : Measure X => ν Set.univ) hden
117
+ rw [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] at he2
118
+ rw [he2]
119
+ exact measure_lt_top _ _
120
+
121
+ lemma density_ae_unique_real {X : Type*} [MeasurableSpace X]
122
+ (ν₀ : Measure X) [SigmaFinite ν₀] {F G : X → ℝ}
123
+ (hFm : Measurable F) (hF0 : ∀ x, 0 ≤ F x)
124
+ (hGm : Measurable G) (hG0 : ∀ x, 0 ≤ G x)
125
+ (hden : ν₀.withDensity (fun x => ENNReal.ofReal (F x)) =
126
+ ν₀.withDensity (fun x => ENNReal.ofReal (G x))) : F =ᵐ[ν₀] G := by
127
+ have he := (withDensity_eq_iff_of_sigmaFinite hFm.ennreal_ofReal.aemeasurable
128
+ hGm.ennreal_ofReal.aemeasurable).mp hden
129
+ filter_upwards [he] with x hx
130
+ exact (ENNReal.ofReal_eq_ofReal_iff (hF0 x) (hG0 x)).mp hx
131
+
132
+ def JointL1Statement : Prop :=
133
+ let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast
134
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
135
+ let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2
136
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast
137
+ (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))
138
+ ∀ d m p : ℕ,
139
+ letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ)
140
+ 2 ≤ d → 1 ≤ m → m < d → 2 ≤ p →
141
+ ∀ β H R : ℝ, (m : ℝ)+(p : ℝ)-two < β → 0 < H → 0 < R →
142
+ ∀ z : Space d, ∀ μ : Measure (Space d), IsFiniteMeasure μ →
143
+ @Measure.support (Space d)
144
+ (PiLp.topologicalSpace (p := exponent) (β := fun _ : Fin d => ℝ))
145
+ (WithLp.measurableSpace exponent (Fin d → ℝ)) μ ⊆
146
+ @Metric.closedBall (Space d)
147
+ (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ)) z R →
148
+ AmbientBallBound μ H β →
149
+ μ ≪ UniformSphere d →
150
+ ∀ F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ,
151
+ Measurable F → (∀ x, 0 ≤ F x) →
152
+ (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) =
153
+ ProjectionLaw μ m →
154
+ Tendsto (fun δ => eLpNorm (fun Ay => GaussianRegularization μ m δ Ay - F Ay)
155
+ 1 (MatrixLabelReference d m)) (𝓝[Set.Ioi 0] 0) (𝓝 0) ∧
156
+ eLpNorm F (p : ℝ≥0∞) (MatrixLabelReference d m) ≤
157
+ ENNReal.ofReal (ProjectionNormScale m p H β R)
158
+ theorem joint_l1 : JointL1Statement := by
159
+ intro d m p hd hm hmd hp β H R hgap hH hR z μ hμ hs hb hac F hFm hF0 hden
160
+ have : IsFiniteMeasure μ := hμ
161
+ have : IsFiniteMeasure (ProjectionLaw μ m) := by unfold ProjectionLaw; infer_instance
162
+ have : SigmaFinite (MatrixLabelReference d m) := by unfold MatrixLabelReference; infer_instance
163
+ have hF := memLp_density_of_finite (MatrixLabelReference d m) (ProjectionLaw μ m) hFm hF0 hden
164
+ constructor
165
+ · have ht := tendsto_eLpNorm_averageTranslate_sub
166
+ (Measure.pi (fun _ : Fin m => stdGaussian (Space d)))
167
+ (volume : Measure (Fin m → ℝ))
168
+ (Measure.pi (fun _ : Fin m => gaussianReal 0 1)) hFm hF
169
+ apply (ht.mono_left nhdsWithin_le_nhds).congr'
170
+ filter_upwards [self_mem_nhdsWithin] with δ hδ
171
+ apply eLpNorm_congr_ae
172
+ filter_upwards [GaussianRegularization_ae_eq_average μ m F hFm hF0 hden δ
173
+ (ne_of_gt hδ)] with x hx
174
+ exact congrArg (fun t => t - F x) hx.symm
175
+ · obtain ⟨G,hGm,hG0,hGden,hGs,hGnorm⟩ :=
176
+ exact_finite_density d m p hp hm β H R hgap hH hR z μ hs hb
177
+ have he := density_ae_unique_real (MatrixLabelReference d m) hFm hF0 hGm hG0
178
+ (hden.trans hGden.symm)
179
+ exact (eLpNorm_congr_ae he).symm ▸ hGnorm
180
+ end MemoryPrecision
181
+
182
+
183
+ end
184
+
185
+ end OAI
lean/OAI/Probability/MemoryPrecision/KernelAdmissibility.lean ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.CoefficientStep
4
+
5
+ namespace OAI
6
+
7
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
8
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
9
+
10
+ noncomputable section
11
+ universe u v
12
+
13
+
14
+ open MeasureTheory ProbabilityTheory Set Filter
15
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
16
+ namespace MemoryPrecision.Kernel
17
+ namespace Policy
18
+
19
+ def ModelAdmissible {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
20
+ (K : Ω → Policy d M T) (ρ : Measure Ω) : Prop :=
21
+ ∀ π : Measure (Sphere d), IsProbabilityMeasure π → Admissible K ρ π
22
+
23
+ def FixedSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
24
+ (K : Ω → Policy d M T) (ρ : Measure Ω) (ε : ℝ) (s : Sphere d) : ℝ≥0∞ :=
25
+ let rowMeasurable := @MeasurableSpace.pi (Fin T) (fun _ => Vector d)
26
+ (fun _ => @WithLp.measurableSpace
27
+ (@OfNat.ofNat ℝ≥0∞ 2
28
+ (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance))
29
+ (Fin d → ℝ) inferInstance)
30
+ @lintegral (Ω × Rows d T)
31
+ (@Prod.instMeasurableSpace Ω (Rows d T) inferInstance rowMeasurable)
32
+ (@Measure.prod Ω (Rows d T) inferInstance rowMeasurable ρ (RowLaw d T))
33
+ (fun z => experiment K (angleTest ε) (s,z))
34
+
35
+ lemma modelAdmissible_of_measurable {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω]
36
+ (K : Ω → Policy d M T) (ρ : Measure Ω)
37
+ (hc : ∀ᵐ ω ∂ρ, (K ω).Completed)
38
+ (hm : ∀ f : Sphere d × Sphere d → ℝ≥0∞, Measurable f → (∀ x, f x ≤ 1) →
39
+ Measurable (experiment K f)) : ModelAdmissible K ρ := by
40
+ intro π hπ
41
+ exact ⟨hc, fun f hf h1 => (hm f hf h1).aemeasurable⟩
42
+ end Policy
43
+ end MemoryPrecision.Kernel
44
+
45
+
46
+ end
47
+
48
+ end OAI
lean/OAI/Probability/MemoryPrecision/KernelCaps.lean ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.CubeExperiment
4
+ import OAI.Probability.MemoryPrecision.KernelEvaluation
5
+ import OAI.Probability.MemoryPrecision.SphereCaps
6
+
7
+ namespace OAI
8
+
9
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
10
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
11
+
12
+ noncomputable section
13
+ universe u v
14
+
15
+
16
+ open MeasureTheory ProbabilityTheory Set Filter
17
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
18
+ namespace MemoryPrecision.Kernel
19
+ open MemoryPrecision NoiselessRegression
20
+ instance {d : ℕ} [NeZero d] : IsProbabilityMeasure (UniformSphere d) :=
21
+ (show IsProbabilityMeasure (NoiselessRegression.sphereLaw (E := Vector d)) from inferInstance)
22
+ instance (d T : ℕ) : IsProbabilityMeasure (RowLaw d T) := by unfold RowLaw; infer_instance
23
+
24
+ namespace Policy
25
+ variable {d M T : ℕ} (K : Policy d M T)
26
+
27
+ lemma chordTest_eq_cap (ε : ℝ) (s v : MemoryPrecision.Kernel.Sphere d) :
28
+ chordTest ε (s,v) = capWeight v.val ε s.val := by
29
+ classical
30
+ change (if dist v.val s.val ≤ ε then 1 else 0) =
31
+ (if dist s.val v.val ≤ ε then 1 else 0)
32
+ rw [dist_comm]
33
+
34
+ lemma output_chord_sphere_local (hd : 1 ≤ d) {ε α : ℝ} (hε : 0 < ε)
35
+ (hα : 0 ≤ α) (hαn : α ≤ (d:ℝ)-1) (t : ℕ) (j : MemoryPrecision.Kernel.State M) :
36
+ SphereBallBound (K.outputTest (chordTest ε) t j)
37
+ ((3*4^d:ℝ)*ε^((d:ℝ)-1-α)) α := by
38
+ have : NeZero d := ⟨by omega⟩
39
+ intro z r hr
40
+ change (∫⁻ s in {s : MemoryPrecision.Kernel.Sphere d | dist s.val z ≤ r},
41
+ ∫⁻ v, chordTest ε (s,v) ∂K.output t j ∂UniformSphere d) ≤ _
42
+ have hm : Measurable (Function.uncurry (fun s v : MemoryPrecision.Kernel.Sphere d => chordTest ε (s,v))) :=
43
+ measurable_chordTest ε
44
+ rw [lintegral_lintegral_swap hm.aemeasurable]
45
+ have hb (v : MemoryPrecision.Kernel.Sphere d) := sphere_cap_real_mass hd v.val hε hα hαn z r hr
46
+ simp_rw [chordTest_eq_cap]
47
+ exact (lintegral_mono hb).trans_eq (by simp)
48
+
49
+ lemma output_chord_cube_local (hd : 2 ≤ d) {ε : ℝ} (hε : 0 < ε)
50
+ (t : ℕ) (j : MemoryPrecision.Kernel.State M) :
51
+ CubeLocal (fun u => K.outputTest (chordTest ε) t j (CubeSphere hd u))
52
+ ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ)) := by
53
+ intro z r hr
54
+ change (∫⁻ u in CubeBall d z r, ∫⁻ v, chordTest ε (CubeSphere hd u,v)
55
+ ∂K.output t j ∂CubeLaw d) ≤ _
56
+ have hf : Measurable (Function.uncurry (fun (u : Cube d) (v : MemoryPrecision.Kernel.Sphere d) =>
57
+ chordTest ε (CubeSphere hd u,v))) :=
58
+ (measurable_chordTest ε).comp ((cubeSphere_measurable hd).comp measurable_fst |>.prodMk measurable_snd)
59
+ rw [lintegral_lintegral_swap hf.aemeasurable]
60
+ simp_rw [chordTest_eq_cap]
61
+ change (∫⁻ v : MemoryPrecision.Kernel.Sphere d, ∫⁻ u in CubeBall d z r,
62
+ capWeight v.val ε (CubeEmbedding d u) ∂CubeLaw d ∂K.output t j) ≤ _
63
+ have hb (v : MemoryPrecision.Kernel.Sphere d) := cube_cap_local hd v.val hε z r hr
64
+ exact (lintegral_mono hb).trans_eq (by simp)
65
+
66
+ lemma output_chord_sphere_total (hd : 1 ≤ d) {ε : ℝ} (hε : 0 < ε)
67
+ (t : ℕ) (j : MemoryPrecision.Kernel.State M) :
68
+ (∫⁻ s, K.outputTest (chordTest ε) t j s ∂UniformSphere d) ≤
69
+ ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1)) := by
70
+ have h := sphere_mass_bound (K.output_chord_sphere_local hd hε (α := 0) le_rfl (by
71
+ have hd' : (1:ℝ) ≤ d := by exact_mod_cast hd
72
+ linarith) t j)
73
+ have hn : ((d-1:ℕ):ℝ) = (d:ℝ)-1 := by rw [Nat.cast_sub hd, Nat.cast_one]
74
+ simpa only [UniformSphere, SpherePrior,sub_zero, ← hn, Real.rpow_natCast] using h
75
+
76
+ lemma angleTest_le_chordTest (ε : ℝ) (x : MemoryPrecision.Kernel.Sphere d × MemoryPrecision.Kernel.Sphere d) :
77
+ angleTest ε x ≤ chordTest ε x := by
78
+ classical
79
+ by_cases ha : Real.arccos ⟪x.2.val,x.1.val⟫ ≤ ε
80
+ · have hc : dist x.2.val x.1.val ≤ ε := (chord_le_arccos x.2 x.1).trans ha
81
+ simp [angleTest, chordTest, ha, hc]
82
+ · simp [angleTest, ha]
83
+
84
+ lemma eval_mono {X : Type*} {w v : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞}
85
+ (h : ∀ n j s, w n j s ≤ v n j s) (n k : ℕ) (j : MemoryPrecision.Kernel.State M)
86
+ (s : X) (obs : Observations d k) : K.eval w n k j s obs ≤ K.eval v n k j s obs := by
87
+ induction k generalizing n j with
88
+ | zero => exact h n j s
89
+ | succ k ih =>
90
+ apply Finset.sum_le_sum
91
+ intro a _
92
+ apply mul_le_mul' le_rfl
93
+ split
94
+ · exact h _ _ _
95
+ · exact ih _ _ _
96
+
97
+ lemma pathValue_mono {X : Type*} {w v : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞}
98
+ (h : ∀ n j s, w n j s ≤ v n j s) (s : X) (obs : Observations d T) :
99
+ K.pathValue w s obs ≤ K.pathValue v s obs := by
100
+ apply Finset.sum_le_sum
101
+ intro a _
102
+ apply mul_le_mul' le_rfl
103
+ split
104
+ · exact h _ _ _
105
+ · exact K.eval_mono h _ _ _ _ _
106
+
107
+ lemma success_le_chord {Ω : Type*} [MeasurableSpace Ω] (L : Ω → Policy d M T)
108
+ (ρ : Measure Ω) (π : Measure (MemoryPrecision.Kernel.Sphere d)) (�� : ℝ) :
109
+ Success L ρ π ε ≤ ChordSuccess L ρ π ε := by
110
+ apply lintegral_mono
111
+ intro z
112
+ exact (L z.2.1).pathValue_mono (fun n j s => lintegral_mono (fun v => angleTest_le_chordTest ε (s,v))) _ _
113
+ end Policy
114
+ end MemoryPrecision.Kernel
115
+
116
+
117
+ end
118
+
119
+ end OAI
lean/OAI/Probability/MemoryPrecision/KernelCube.lean ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import OAI.Probability.GaussianRegression.Main
3
+ import OAI.Probability.MemoryPrecision.KernelCaps
4
+ import OAI.Probability.MemoryPrecision.KernelIntegral
5
+ import OAI.Probability.MemoryPrecision.KernelVersion
6
+ import OAI.Probability.MemoryPrecision.SeedAverage
7
+ import OAI.Probability.MemoryPrecision.StochasticMass
8
+
9
+ namespace OAI
10
+
11
+ open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
12
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
13
+
14
+ noncomputable section
15
+ universe u v
16
+
17
+
18
+ open MeasureTheory ProbabilityTheory Set Filter
19
+ open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
20
+ namespace MemoryPrecision.Kernel
21
+ open MemoryPrecision NoiselessRegression
22
+
23
+ def CubePrior {d : ℕ} (hd : 2 ≤ d) : Measure (MemoryPrecision.Kernel.Sphere d) :=
24
+ (CubeLaw d).map (CubeSphere hd)
25
+ instance {d : ℕ} (hd : 2 ≤ d) : IsProbabilityMeasure (CubePrior hd) := by
26
+ unfold CubePrior
27
+ infer_instance
28
+
29
+ lemma cubeSphere_preserving {d : ℕ} (hd : 2 ≤ d) :
30
+ MeasurePreserving (CubeSphere hd) (CubeLaw d) (CubePrior hd) :=
31
+ ⟨cubeSphere_measurable hd, rfl⟩
32
+
33
+ namespace Policy
34
+ variable {d M T : ℕ} (K : Policy d M T)
35
+
36
+ lemma eval_comp {X Y : Type*} (w : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞) (ι : Y → X)
37
+ (n k : ℕ) (j : MemoryPrecision.Kernel.State M) (s : Y) (obs : Observations d k) :
38
+ K.eval w n k j (ι s) obs = K.eval (fun n j s => w n j (ι s)) n k j s obs := by
39
+ induction k generalizing n j with
40
+ | zero => rfl
41
+ | succ k ih =>
42
+ simp only [eval]
43
+ apply Finset.sum_congr rfl
44
+ intro a _
45
+ rw [ih]
46
+ lemma pathValue_comp {X Y : Type*} (w : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞) (ι : Y → X)
47
+ (s : Y) (obs : Observations d T) :
48
+ K.pathValue w (ι s) obs = K.pathValue (fun n j s => w n j (ι s)) s obs := by
49
+ simp only [pathValue, K.eval_comp w ι]
50
+
51
+ lemma borel_cube_bound (hK : K.Borel) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) :
52
+ (∫⁻ z : Cube d × Rows d T,
53
+ K.pathValue (K.outputTest (chordTest ε)) (CubeSphere (d := d) (by omega) z.1)
54
+ (records (CubeSphere (d := d) (by omega) z.1) z.2)
55
+ ∂(CubeLaw d).prod (RowLaw d T)) ≤
56
+ (T+1:ℝ≥0∞)*ENNReal.ofReal ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) *
57
+ CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4)) := by
58
+ have hm₁ : Measurable (fun z : Cube d × Rows d T =>
59
+ (CubeSphere (d := d) (by omega) z.1,z.2)) :=
60
+ ((cubeSphere_measurable (d := d) (by omega)).comp measurable_fst).prodMk measurable_snd
61
+ have hm₀ := K.experiment_fixed_measurable (f := chordTest (d := d) ε) hK (measurable_chordTest ε)
62
+ have hm := hm₀.comp hm₁
63
+ have hprod := lintegral_prod (μ := CubeLaw d) (ν := RowLaw d T) _ hm.aemeasurable
64
+ simp only [Function.comp_apply] at hprod
65
+ rw [hprod]
66
+ simp_rw [K.pathValue_comp _ (CubeSphere (d := d) (by omega))]
67
+ apply K.integral_pathValue_bound (fun n j u => K.outputTest (chordTest ε) n j (CubeSphere (d := d) (by omega) u))
68
+ (CubeEmbedding d) hK
69
+ (fun n j => (K.outputTest_measurable (measurable_chordTest ε) n j).comp (cubeSphere_measurable (d := d) (by omega)))
70
+ (cubeEmbedding_measurable d) (CubeLaw d)
71
+ intro r hr j
72
+ apply cube_mass_bound
73
+ exact stoch_cube_mass hd (show 1 ≤ 2^M from one_le_pow₀ (by norm_num))
74
+ (K.marginal_measurable hK) (fun n j obs => (K.marginal_sum n j obs).le)
75
+ (fun n j => (K.outputTest_measurable (measurable_chordTest ε) n j).comp (cubeSphere_measurable (d := d) (by omega)))
76
+ (fun n j u => K.outputTest_le_one (chordTest_le_one ε) n j (CubeSphere (d := d) (by omega) u))
77
+ (by positivity) (K.output_chord_cube_local (by omega) hε)
78
+ (MemoryPrecision.BlockCount T ((d/2)/4)) r
79
+ (hr.trans (blockCount_mul_ge T (by omega))) 0 j
80
+
81
+ lemma completed_cube_bound (hK : K.Completed) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) :
82
+ (∫⁻ z : Cube d × Rows d T,
83
+ K.pathValue (K.outputTest (chordTest ε)) (CubeSphere (d := d) (by omega) z.1)
84
+ (records (CubeSphere (d := d) (by omega) z.1) z.2)
85
+ ∂(CubeLaw d).prod (RowLaw d T)) ≤
86
+ (T+1:ℝ≥0∞)*ENNReal.ofReal ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) *
87
+ CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4)) := by
88
+ have he := K.version_pathValue_ae ((CubeLaw d).prod (RowLaw d T)) hK
89
+ (fun z : Cube d × Rows d T => CubeSphere (d := d) (by omega) z.1)
90
+ (fun z : Cube d × Rows d T => records (CubeSphere (d := d) (by omega) z.1) z.2)
91
+ (fun i => show Measure.QuasiMeasurePreserving _ _ _ from cube_sample_observation_quasi hd i)
92
+ (chordTest ε)
93
+ rw [← lintegral_congr_ae he]
94
+ exact (K.version hK).borel_cube_bound (K.version_borel hK) hd hε
95
+
96
+ lemma source_cube_chord_bound {Ω : Type u} [MeasurableSpace Ω] (L : Ω → Policy d M T)
97
+ (ρ : Measure Ω) [IsProbabilityMeasure ρ] (hd : 16 ≤ d)
98
+ (hL : Admissible L ρ (CubePrior (by omega))) {ε : ℝ} (hε : 0 < ε) :
99
+ ChordSuccess L ρ (CubePrior (by omega)) ε ≤
100
+ (T+1:ℝ≥0∞)*ENNReal.ofReal ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) *
101
+ CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4)) := by
102
+ have hp := (cubeSphere_preserving (by omega : 2 ≤ d)).prod
103
+ (MeasurePreserving.id (ρ.prod (RowLaw d T)))
104
+ have hf := hL.experiment (chordTest ε) (measurable_chordTest ε) (chordTest_le_one ε)
105
+ have he : (∫⁻ z : Cube d × (Ω × Rows d T),
106
+ experiment L (chordTest ε) (CubeSphere (d := d) (by omega) z.1,z.2)
107
+ ∂(CubeLaw d).prod (ρ.prod (RowLaw d T))) = ChordSuccess L ρ (CubePrior (by omega)) ε := by
108
+ calc
109
+ _ = ∫⁻ z, experiment L (chordTest ε) z ∂((CubeLaw d).prod (ρ.prod (RowLaw d T))).map
110
+ (Prod.map (CubeSphere (d := d) (by omega)) id) :=
111
+ (lintegral_map' (by simpa only [hp.map_eq] using hf) hp.measurable.aemeasurable).symm
112
+ _ = _ := by rw [hp.map_eq]; rfl
113
+ rw [← he]
114
+ apply seed_average_bound (CubeLaw d) (RowLaw d T) ρ
115
+ (hf.comp_quasiMeasurePreserving hp.quasiMeasurePreserving)
116
+ filter_upwards [hL.completed] with ω hω
117
+ exact (L ω).completed_cube_bound hω hd hε
118
+ end Policy
119
+ end MemoryPrecision.Kernel
120
+
121
+
122
+ end
123
+
124
+ end OAI