@lapxo/obligations 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.md +42 -3
  2. package/TARGET.bound +147 -4
  3. package/contracts/extension-lineage-participation.json +30 -0
  4. package/contracts/m0-allocation.json +6 -0
  5. package/contracts/m0-binomial-bridge.json +6 -0
  6. package/contracts/m0-diagonal-conditional.json +15 -0
  7. package/contracts/m0-finite-grid.json +6 -0
  8. package/contracts/m0-keff-interval.json +27 -0
  9. package/contracts/m0-limit-diag.json +6 -0
  10. package/contracts/m0-limit-offdiag.json +6 -0
  11. package/contracts/m0-moment-identification.json +42 -0
  12. package/contracts/m0-pair-coincidence.json +6 -0
  13. package/contracts/m1-diagonal-regions.json +45 -0
  14. package/contracts/m1-generator-binomial.json +26 -0
  15. package/contracts/m1-offdiag-limit.json +42 -0
  16. package/contracts/m1-subcauses.json +66 -0
  17. package/contracts/model-collapse-1a.json +16 -0
  18. package/contracts/projection-chain.json +20 -0
  19. package/docs/contracts/experiment1a-public-attribution.md +1 -0
  20. package/docs/contracts/extension-lineage-participation.md +13 -0
  21. package/docs/contracts/installation-046-inputs.md +1 -0
  22. package/docs/contracts/m0-allocation.md +1 -0
  23. package/docs/contracts/m0-binomial-bridge.md +1 -0
  24. package/docs/contracts/m0-diagonal-lindeberg.md +1 -0
  25. package/docs/contracts/m0-diagonal-moments.md +1 -0
  26. package/docs/contracts/m0-diagonal-symmetric.md +1 -0
  27. package/docs/contracts/m0-diagonal-threshold.md +1 -0
  28. package/docs/contracts/m0-finite-grid.md +1 -0
  29. package/docs/contracts/m0-keff-floor-refutation.md +1 -0
  30. package/docs/contracts/m0-keff-interval.md +1 -0
  31. package/docs/contracts/m0-limit-diag.md +1 -0
  32. package/docs/contracts/m0-limit-offdiag.md +1 -0
  33. package/docs/contracts/m0-moment-identification.md +1 -0
  34. package/docs/contracts/m0-pair-coincidence.md +1 -0
  35. package/docs/contracts/m0-refuted-inverses.md +1 -0
  36. package/docs/contracts/m0-wf-floor-refutation.md +1 -0
  37. package/docs/contracts/m1-diagonal-regions.md +1 -0
  38. package/docs/contracts/m1-generator-binomial.md +1 -0
  39. package/docs/contracts/m1-offdiag-limit.md +1 -0
  40. package/docs/contracts/model-collapse-1a.md +11 -0
  41. package/docs/contracts/projection-chain.md +1 -0
  42. package/docs/proofs/floor-limit-diag.proof.json +29 -0
  43. package/package.json +1 -1
  44. package/proofs/definitions-046/declaration.json +11 -0
  45. package/proofs/experiment1a-046/declaration.json +11 -0
  46. package/proofs/m0-045/Obligations045/ConsensusGrid.lean +72 -0
  47. package/proofs/m0-045/Obligations045/M0Coincidence.lean +39 -0
  48. package/proofs/m0-045/Obligations045/M0Diagonal.lean +18 -0
  49. package/proofs/m0-045/Obligations045/M0Limit.lean +134 -0
  50. package/proofs/m0-045/Obligations045/M0Offdiag.lean +171 -0
  51. package/proofs/m0-045/Obligations045.lean +5 -0
  52. package/proofs/m0-045/lake-manifest.json +116 -0
  53. package/proofs/m0-045/lakefile.toml +9 -0
  54. package/proofs/m0-045/lean-toolchain +1 -0
  55. package/proofs/m0-046/BridgeNegatives.lean +23 -0
  56. package/proofs/m0-046/M0Bridge.lean +300 -0
  57. package/proofs/m0-046/Obligations045/ConsensusGrid.lean +72 -0
  58. package/proofs/m0-046/Obligations045/M0Coincidence.lean +39 -0
  59. package/proofs/m0-046/Obligations045/M0Diagonal.lean +18 -0
  60. package/proofs/m0-046/Obligations045/M0Limit.lean +134 -0
  61. package/proofs/m0-046/Obligations045/M0Offdiag.lean +171 -0
  62. package/proofs/m0-046/Obligations045.lean +5 -0
  63. package/proofs/m0-046/lake-manifest.json +116 -0
  64. package/proofs/m0-046/lakefile.toml +14 -0
  65. package/proofs/m0-046/lean-toolchain +1 -0
  66. package/proofs/m0-046-diagonal/BridgeNegatives.lean +23 -0
  67. package/proofs/m0-046-diagonal/M0Bridge.lean +300 -0
  68. package/proofs/m0-046-diagonal/M0Diagonal046.lean +235 -0
  69. package/proofs/m0-046-diagonal/M0Lindeberg046.lean +92 -0
  70. package/proofs/m0-046-diagonal/M0Moments046.lean +295 -0
  71. package/proofs/m0-046-diagonal/M0Threshold046.lean +278 -0
  72. package/proofs/m0-046-diagonal/Obligations045/ConsensusGrid.lean +72 -0
  73. package/proofs/m0-046-diagonal/Obligations045/M0Coincidence.lean +39 -0
  74. package/proofs/m0-046-diagonal/Obligations045/M0Diagonal.lean +18 -0
  75. package/proofs/m0-046-diagonal/Obligations045/M0Limit.lean +134 -0
  76. package/proofs/m0-046-diagonal/Obligations045/M0Offdiag.lean +171 -0
  77. package/proofs/m0-046-diagonal/Obligations045.lean +5 -0
  78. package/proofs/m0-046-diagonal/lake-manifest.json +116 -0
  79. package/proofs/m0-046-diagonal/lakefile.toml +26 -0
  80. package/proofs/m0-046-diagonal/lean-toolchain +1 -0
  81. package/proofs/m0-046-identification/M0Identification046.lean +209 -0
  82. package/proofs/m0-046-identification/Obligations045/M0Coincidence.lean +39 -0
  83. package/proofs/m0-046-identification/lake-manifest.json +116 -0
  84. package/proofs/m0-046-identification/lakefile.toml +12 -0
  85. package/proofs/m0-046-identification/lean-toolchain +1 -0
  86. package/proofs/m0-046-uncertainty/BridgeNegatives.lean +23 -0
  87. package/proofs/m0-046-uncertainty/M0BlockCoverage046.lean +163 -0
  88. package/proofs/m0-046-uncertainty/M0Bridge.lean +300 -0
  89. package/proofs/m0-046-uncertainty/M0Diagonal046.lean +235 -0
  90. package/proofs/m0-046-uncertainty/M0FiniteDiscord046.lean +207 -0
  91. package/proofs/m0-046-uncertainty/M0Interval046.lean +82 -0
  92. package/proofs/m0-046-uncertainty/M0Lindeberg046.lean +92 -0
  93. package/proofs/m0-046-uncertainty/M0Moments046.lean +295 -0
  94. package/proofs/m0-046-uncertainty/M0Threshold046.lean +278 -0
  95. package/proofs/m0-046-uncertainty/Obligations045/ConsensusGrid.lean +72 -0
  96. package/proofs/m0-046-uncertainty/Obligations045/M0Coincidence.lean +39 -0
  97. package/proofs/m0-046-uncertainty/Obligations045/M0Diagonal.lean +18 -0
  98. package/proofs/m0-046-uncertainty/Obligations045/M0Limit.lean +134 -0
  99. package/proofs/m0-046-uncertainty/Obligations045/M0Offdiag.lean +171 -0
  100. package/proofs/m0-046-uncertainty/Obligations045.lean +5 -0
  101. package/proofs/m0-046-uncertainty/lake-manifest.json +116 -0
  102. package/proofs/m0-046-uncertainty/lakefile.toml +35 -0
  103. package/proofs/m0-046-uncertainty/lean-toolchain +1 -0
  104. package/proofs/m1-046-bridge/M0Bridge.lean +300 -0
  105. package/proofs/m1-046-bridge/M1Bridge046.lean +359 -0
  106. package/proofs/m1-046-bridge/Obligations045/M0Limit.lean +134 -0
  107. package/proofs/m1-046-bridge/Obligations045/M0Offdiag.lean +171 -0
  108. package/proofs/m1-046-bridge/lake-manifest.json +116 -0
  109. package/proofs/m1-046-bridge/lakefile.toml +29 -0
  110. package/proofs/m1-046-bridge/lean-toolchain +1 -0
  111. package/proofs/m1-046-diagonal/M0Bridge.lean +300 -0
  112. package/proofs/m1-046-diagonal/M0Diagonal046.lean +235 -0
  113. package/proofs/m1-046-diagonal/M0Lindeberg046.lean +92 -0
  114. package/proofs/m1-046-diagonal/M0Moments046.lean +295 -0
  115. package/proofs/m1-046-diagonal/M0Threshold046.lean +278 -0
  116. package/proofs/m1-046-diagonal/M1Bridge046.lean +359 -0
  117. package/proofs/m1-046-diagonal/M1Diagonal046.lean +334 -0
  118. package/proofs/m1-046-diagonal/M1Offdiag046.lean +270 -0
  119. package/proofs/m1-046-diagonal/Obligations045/M0Limit.lean +134 -0
  120. package/proofs/m1-046-diagonal/Obligations045/M0Offdiag.lean +171 -0
  121. package/proofs/m1-046-diagonal/lake-manifest.json +116 -0
  122. package/proofs/m1-046-diagonal/lakefile.toml +35 -0
  123. package/proofs/m1-046-diagonal/lean-toolchain +1 -0
  124. package/proofs/m1-046-offdiag/M0Bridge.lean +300 -0
  125. package/proofs/m1-046-offdiag/M0Diagonal046.lean +235 -0
  126. package/proofs/m1-046-offdiag/M0Moments046.lean +295 -0
  127. package/proofs/m1-046-offdiag/M1Bridge046.lean +359 -0
  128. package/proofs/m1-046-offdiag/M1Offdiag046.lean +270 -0
  129. package/proofs/m1-046-offdiag/Obligations045/M0Limit.lean +134 -0
  130. package/proofs/m1-046-offdiag/Obligations045/M0Offdiag.lean +171 -0
  131. package/proofs/m1-046-offdiag/lake-manifest.json +116 -0
  132. package/proofs/m1-046-offdiag/lakefile.toml +32 -0
  133. package/proofs/m1-046-offdiag/lean-toolchain +1 -0
  134. package/proofs/projection-chain.md +11 -0
  135. package/protocols/model-collapse-1a.json +108 -0
  136. package/receipts.bound +684 -208
  137. package/samples/laws/definitions/no/sample.json +26 -0
  138. package/samples/laws/definitions/yes/sample.json +12 -0
  139. package/samples/laws/experiment1a/no/sample.json +16 -0
  140. package/samples/laws/experiment1a/yes/sample.json +8 -0
  141. package/samples/laws/m0-allocation/no/sample.json +5 -0
  142. package/samples/laws/m0-allocation/yes/sample.json +7 -0
  143. package/samples/laws/m0-binomial-bridge/no/pairwise-is-not-joint.json +59 -0
  144. package/samples/laws/m0-binomial-bridge/no/sample.json +13 -0
  145. package/samples/laws/m0-binomial-bridge/yes/sample.json +16 -0
  146. package/samples/laws/m0-binomial-bridge/yes/small-binomial-table.json +100 -0
  147. package/samples/laws/m0-diagonal-conditional/no/sample.json +5 -0
  148. package/samples/laws/m0-diagonal-conditional/yes/sample.json +7 -0
  149. package/samples/laws/m0-finite-grid/no/sample.json +5 -0
  150. package/samples/laws/m0-finite-grid/yes/sample.json +7 -0
  151. package/samples/laws/m0-keff-interval/no/sample.json +215 -0
  152. package/samples/laws/m0-keff-interval/yes/api-rows.json +2002 -0
  153. package/samples/laws/m0-keff-interval/yes/sample.json +70 -0
  154. package/samples/laws/m0-limit-diag/no/sample.json +5 -0
  155. package/samples/laws/m0-limit-diag/yes/sample.json +7 -0
  156. package/samples/laws/m0-limit-offdiag/no/sample.json +5 -0
  157. package/samples/laws/m0-limit-offdiag/yes/sample.json +7 -0
  158. package/samples/laws/m0-moment-identification/no/sample.json +47 -0
  159. package/samples/laws/m0-moment-identification/yes/sample.json +97 -0
  160. package/samples/laws/m0-pair-coincidence/no/sample.json +5 -0
  161. package/samples/laws/m0-pair-coincidence/yes/sample.json +7 -0
  162. package/samples/laws/m1-diagonal-regions/no/sample.json +44 -0
  163. package/samples/laws/m1-diagonal-regions/yes/sample.json +45 -0
  164. package/samples/laws/m1-generator-binomial/no/sample.json +21 -0
  165. package/samples/laws/m1-generator-binomial/yes/sample.json +290 -0
  166. package/samples/laws/m1-offdiag-limit/no/sample.json +17 -0
  167. package/samples/laws/m1-offdiag-limit/yes/sample.json +87 -0
  168. package/samples/laws/projection-chain/no/sample.json +26 -0
  169. package/samples/laws/projection-chain/yes/sample.json +25 -0
  170. package/samples/no/installed-artifact.json +2 -2
  171. package/samples/yes/installed-artifact.json +2 -2
  172. package/src/laws/laws.bound +146 -0
  173. package/vectors/laws/a7-t90.json +72 -0
  174. package/vectors/laws/a9-t99.json +110 -0
  175. package/vectors/laws/definitions.native-capture.json +326 -0
  176. package/vectors/laws/definitions.native.json +82 -0
  177. package/vectors/laws/experiment1a-protocol.native-capture.json +391 -0
  178. package/vectors/laws/experiment1a-protocol.native.json +64 -0
  179. package/vectors/laws/experiment1a-public-input.native-capture.json +224 -0
  180. package/vectors/laws/m0-allocation.lean.json +150 -0
  181. package/vectors/laws/m0-allocation.native.json +104 -0
  182. package/vectors/laws/m0-binomial-bridge.lean.json +185 -0
  183. package/vectors/laws/m0-diagonal-lindeberg.lean.json +167 -0
  184. package/vectors/laws/m0-diagonal-moments.lean.json +185 -0
  185. package/vectors/laws/m0-diagonal-symmetric.lean.json +188 -0
  186. package/vectors/laws/m0-diagonal-threshold.lean.json +199 -0
  187. package/vectors/laws/m0-finite-grid.lean.json +144 -0
  188. package/vectors/laws/m0-finite-grid.native.json +104 -0
  189. package/vectors/laws/m0-identification.lean.json +136 -0
  190. package/vectors/laws/m0-identification.native-capture.json +230 -0
  191. package/vectors/laws/m0-keff-interval.json +569 -0
  192. package/vectors/laws/m0-limit-diag.lean.json +141 -0
  193. package/vectors/laws/m0-limit-diag.native.json +108 -0
  194. package/vectors/laws/m0-limit-offdiag.lean.json +143 -0
  195. package/vectors/laws/m0-limit-offdiag.native.json +104 -0
  196. package/vectors/laws/m0-pair-coincidence.lean.json +139 -0
  197. package/vectors/laws/m0-pair-coincidence.native.json +104 -0
  198. package/vectors/laws/m0-uncertainty-blocks.lean.json +201 -0
  199. package/vectors/laws/m0-uncertainty-finite-discord.lean.json +194 -0
  200. package/vectors/laws/m0-uncertainty-interval.lean.json +189 -0
  201. package/vectors/laws/m0-uncertainty.native-capture.json +651 -0
  202. package/vectors/laws/m1-diagonal-partial.lean.json +192 -0
  203. package/vectors/laws/m1-diagonal-partial.native-capture.json +275 -0
  204. package/vectors/laws/m1-generator-binomial.lean.json +162 -0
  205. package/vectors/laws/m1-generator-binomial.native-capture.json +245 -0
  206. package/vectors/laws/m1-offdiag-limit.lean.json +166 -0
  207. package/vectors/laws/m1-offdiag-limit.native-capture.json +260 -0
  208. package/vectors/laws/model-collapse-1a.json +12 -0
  209. package/vectors/laws/projection-chain.json +61 -0
  210. package/vectors/laws/projection-chain.native-capture.json +311 -0
  211. package/vectors/laws/projection-chain.native.json +56 -0
  212. package/vectors/measures/installed-artifact.cli.json +6 -6
@@ -0,0 +1,334 @@
1
+ import M1Offdiag046
2
+ import M0Lindeberg046
3
+ import M0Threshold046
4
+
5
+ open scoped BigOperators
6
+ open Filter Topology MeasureTheory ProbabilityTheory
7
+ noncomputable section
8
+ open Classical Obligations046.M1Bridge Obligations046.M1Offdiag Obligations046.Bridge
9
+ namespace Obligations046.M1Diagonal
10
+
11
+ def fresh (M : Model) : ℝ := (1-M.base.c)*(1-M.c2)
12
+ def varianceLower (M : Model) : ℝ := (fresh M)^2*M.base.p*(1-M.base.p)
13
+
14
+ theorem fresh_pos (M : Model) : 0 < fresh M :=
15
+ mul_pos (by linarith [M.base.c_lt_one]) (by linarith [M.c2_lt_one])
16
+
17
+ theorem variance_lower_pos (M : Model) : 0 < varianceLower M := by
18
+ unfold varianceLower
19
+ exact mul_pos (mul_pos (sq_pos_of_pos (fresh_pos M)) (by linarith [M.base.p_half]))
20
+ (by linarith [M.base.p_lt_one])
21
+
22
+ theorem fresh_probability_bounds (M : Model) (A : Ancestors M) (B : Leaves M)
23
+ (i : Fin M.base.K) :
24
+ fresh M*M.base.p ≤ q M A B i ∧ fresh M*(1-M.base.p) ≤ 1-q M A B i := by
25
+ let a := M.base.c
26
+ let b := (1-M.base.c)*M.c2
27
+ let d := fresh M
28
+ have ha : 0 ≤ a := M.base.c_nonneg
29
+ have hb : 0 ≤ b := mul_nonneg (by linarith [M.base.c_lt_one]) M.c2_nonneg
30
+ have hd : 0 ≤ d := (fresh_pos M).le
31
+ have hs : a+b+d=1 := by dsimp [a,b,d,fresh]; ring
32
+ change d*M.base.p ≤ a*(if A (M.parent i) then 1 else 0)+
33
+ b*(if B i then 1 else 0)+d*M.base.p ∧
34
+ d*(1-M.base.p) ≤ 1-(a*(if A (M.parent i) then 1 else 0)+
35
+ b*(if B i then 1 else 0)+d*M.base.p)
36
+ cases A (M.parent i) <;> cases B i <;> simp only [Bool.false_eq_true, ite_false, ite_true,
37
+ mul_zero, mul_one, zero_add, add_zero] <;> constructor <;> nlinarith
38
+
39
+ theorem bernoulli_variance_lower (M : Model) (A : Ancestors M) (B : Leaves M)
40
+ (i : Fin M.base.K) : varianceLower M ≤ q M A B i*(1-q M A B i) := by
41
+ have h := fresh_probability_bounds M A B i
42
+ have hp : 0 ≤ fresh M*M.base.p := mul_nonneg (fresh_pos M).le (by linarith [M.base.p_half])
43
+ have hmul := mul_le_mul h.1 h.2
44
+ (mul_nonneg (fresh_pos M).le (by linarith [M.base.p_lt_one])) (q_bounds M A B i).1
45
+ unfold varianceLower
46
+ nlinarith only [hmul]
47
+
48
+ theorem finite_variance_lower (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) :
49
+ (N:ℝ)*varianceLower M ≤ variance M A B N := by
50
+ have hsum : ∑ i : Fin M.base.K, (sizes M N i:ℝ) = (N:ℝ) := by
51
+ exact_mod_cast (by simpa only [Fin.sum_univ_eq_sum_range] using
52
+ Obligations045.M0.allocation_sum M.base N)
53
+ calc
54
+ _ = ∑ i : Fin M.base.K, (sizes M N i:ℝ)*varianceLower M := by
55
+ rw [← Finset.sum_mul, hsum]
56
+ _ ≤ _ := by
57
+ apply Finset.sum_le_sum
58
+ intro i _
59
+ simpa only [mul_assoc] using mul_le_mul_of_nonneg_left
60
+ (bernoulli_variance_lower M A B i) (Nat.cast_nonneg (sizes M N i))
61
+
62
+ theorem variance_atTop (M : Model) (A : Ancestors M) (B : Leaves M) :
63
+ Tendsto (variance M A B) atTop atTop := by
64
+ apply tendsto_atTop_mono (fun N => finite_variance_lower M A B N)
65
+ exact tendsto_natCast_atTop_atTop.atTop_mul_const (variance_lower_pos M)
66
+
67
+ theorem mean_rounding_bound (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) :
68
+ |mean M A B N-(N:ℝ)*score M A B| ≤ (M.base.K:ℝ) := by
69
+ have heq : mean M A B N-(N:ℝ)*score M A B =
70
+ ∑ i : Fin M.base.K, ((sizes M N i:ℝ)-(N:ℝ)*M.base.w i)*q M A B i := by
71
+ simp only [mean, score, Finset.mul_sum, ← Finset.sum_sub_distrib]
72
+ apply Finset.sum_congr rfl
73
+ intro i _
74
+ ring
75
+ rw [heq]
76
+ calc
77
+ _ ≤ ∑ i : Fin M.base.K, |((sizes M N i:ℝ)-(N:ℝ)*M.base.w i)*q M A B i| :=
78
+ Finset.abs_sum_le_sum_abs _ _
79
+ _ ≤ ∑ _i : Fin M.base.K, (1:ℝ) := by
80
+ apply Finset.sum_le_sum
81
+ intro i _
82
+ rw [abs_mul, abs_of_nonneg (q_bounds M A B i).1]
83
+ have hdis : |(sizes M N i:ℝ)-(N:ℝ)*M.base.w i| ≤ 1 :=
84
+ abs_le.mpr ⟨(Obligations045.M0.allocation_discrepancy M.base N i).1.le,
85
+ (Obligations045.M0.allocation_discrepancy M.base N i).2.le⟩
86
+ exact (mul_le_mul_of_nonneg_right hdis (q_bounds M A B i).1).trans
87
+ (by simpa using (q_bounds M A B i).2)
88
+ _ = _ := by simp
89
+
90
+ theorem diagonal_drift_squared_limit (M : Model) (A : Ancestors M) (B : Leaves M)
91
+ (hdiag : score M A B=(1:ℝ)/2) :
92
+ Tendsto (fun N : ℕ => (mean M A B N-(N:ℝ)/2)^2/variance M A B N)
93
+ atTop (𝓝 0) := by
94
+ have hupper : Tendsto (fun N : ℕ => (M.base.K:ℝ)^2/variance M A B N) atTop (𝓝 0) :=
95
+ tendsto_const_nhds.div_atTop (variance_atTop M A B)
96
+ apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hupper
97
+ · filter_upwards [(variance_atTop M A B).eventually (eventually_ge_atTop 1)] with N hN
98
+ exact div_nonneg (sq_nonneg _) (by linarith)
99
+ · filter_upwards [(variance_atTop M A B).eventually (eventually_ge_atTop 1)] with N hN
100
+ apply div_le_div_of_nonneg_right _ (by linarith)
101
+ have habs := mean_rounding_bound M A B N
102
+ rw [hdiag, mul_one_div] at habs
103
+ nlinarith [sq_abs (mean M A B N-(N:ℝ)/2), abs_nonneg (mean M A B N-(N:ℝ)/2)]
104
+
105
+ def sigma (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) : ℝ :=
106
+ Real.sqrt (variance M A B N)
107
+ def threshold (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) : ℝ :=
108
+ ((N:ℝ)/2-mean M A B N)/sigma M A B N
109
+
110
+ theorem sigma_pos (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) (hN : 0<N) :
111
+ 0 < sigma M A B N := by
112
+ apply Real.sqrt_pos.2
113
+ exact lt_of_lt_of_le (mul_pos (by exact_mod_cast hN) (variance_lower_pos M))
114
+ (finite_variance_lower M A B N)
115
+
116
+ theorem threshold_limit (M : Model) (A : Ancestors M) (B : Leaves M)
117
+ (hdiag : score M A B=(1:ℝ)/2) : Tendsto (threshold M A B) atTop (𝓝 0) := by
118
+ have h := (diagonal_drift_squared_limit M A B hdiag).sqrt
119
+ apply (tendsto_zero_iff_norm_tendsto_zero).mpr
120
+ simpa only [threshold, sigma, Real.norm_eq_abs, abs_div,
121
+ abs_of_nonneg (Real.sqrt_nonneg _), abs_sub_comm,
122
+ Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, Real.sqrt_zero] using h
123
+
124
+ def lindebergRatio (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) (eps : ℝ) : ℝ :=
125
+ (∑ i : Fin M.base.K, (sizes M N i:ℝ)*Obligations046.Lindeberg.bernoulliTail
126
+ (q M A B i) (eps^2*variance M A B N))/variance M A B N
127
+
128
+ theorem lindeberg_eventually_zero (M : Model) (A : Ancestors M) (B : Leaves M)
129
+ (eps : ℝ) (he : 0<eps) : ∀ᶠ N in atTop, lindebergRatio M A B N eps=0 := by
130
+ have hv := (variance_atTop M A B).eventually (eventually_ge_atTop (1/eps^2))
131
+ filter_upwards [hv] with N hN
132
+ have hc : 1 ≤ eps^2*variance M A B N := by
133
+ simpa only [mul_comm] using (div_le_iff₀ (sq_pos_of_pos he)).mp hN
134
+ have hz (i : Fin M.base.K) := Obligations046.Lindeberg.bernoulli_tail_zero
135
+ (q M A B i) _ (q_bounds M A B i).1 (q_bounds M A B i).2 hc
136
+ simp only [lindebergRatio, hz, mul_zero, Finset.sum_const_zero, zero_div]
137
+
138
+ theorem lindeberg_limit (M : Model) (A : Ancestors M) (B : Leaves M)
139
+ (eps : ℝ) (he : 0<eps) :
140
+ Tendsto (fun N => lindebergRatio M A B N eps) atTop (𝓝 0) := by
141
+ have hEq : (fun N => lindebergRatio M A B N eps) =ᶠ[atTop] (fun _ => 0) :=
142
+ lindeberg_eventually_zero M A B eps he
143
+ exact tendsto_const_nhds.congr' hEq.symm
144
+
145
+ /-- Genuine diagonal region: exact at everyN, without any CLT assumption. -/
146
+ theorem unbiased_conditional_exact (M : Model) (A : Ancestors M) (B : Leaves M)
147
+ (hunbiased : ∀ i, q M A B i=(1:ℝ)/2) (N : ℕ) :
148
+ binomialError M N A B=(1:ℝ)/2 := by
149
+ let f : World (sizes M N) → ℝ := fun x =>
150
+ jointMass (sizes M N) (fun _ => (1/2:ℝ)) x * Obligations045.M0.fairLoss (correctCount x) N
151
+ have hq : q M A B=(fun _ => (1:ℝ)/2) := funext hunbiased
152
+ have hrep : binomialError M N A B=∑ x, f x := by
153
+ rw [conditional_member_error]
154
+ simp only [f, weights, hq]
155
+ have hsym : ∑ x, f (Obligations046.Diagonal.complement x)=∑ x, f x :=
156
+ Fintype.sum_bijective Obligations046.Diagonal.complement
157
+ ⟨fun x y h => by simpa only [Obligations046.Diagonal.complement_involutive]
158
+ using congrArg Obligations046.Diagonal.complement h,
159
+ fun x => ⟨Obligations046.Diagonal.complement x,
160
+ Obligations046.Diagonal.complement_involutive x⟩⟩ _ _ (fun _ => rfl)
161
+ have hpair : ∀ x, f (Obligations046.Diagonal.complement x)+f x=
162
+ jointMass (sizes M N) (fun _ => (1/2:ℝ)) x := by
163
+ intro x
164
+ simp only [f, Obligations046.Diagonal.unbiased_joint_complement, ← mul_add]
165
+ rw [Obligations046.Diagonal.fair_loss_reflection _ _ _
166
+ (Obligations046.Diagonal.count_complement M.base N x), mul_one]
167
+ have htotal : (∑ x, f (Obligations046.Diagonal.complement x))+(∑ x, f x)=1 := by
168
+ rw [← Finset.sum_add_distrib]
169
+ simp only [hpair]
170
+ exact jointMass_sum _ _
171
+ rw [hrep]
172
+ linarith
173
+
174
+ theorem unbiased_score (M : Model) (A : Ancestors M) (B : Leaves M)
175
+ (hunbiased : ∀ i, q M A B i=(1:ℝ)/2) : score M A B=(1:ℝ)/2 := by
176
+ have hs : ∑ i : Fin M.base.K, M.base.w i=1 := by
177
+ simpa only [Fin.sum_univ_eq_sum_range] using M.base.weights_sum
178
+ simp only [score, hunbiased, ← Finset.sum_mul, hs, one_mul]
179
+
180
+ theorem conditional_limit_offdiag_or_unbiased (M : Model) (A : Ancestors M) (B : Leaves M)
181
+ (hregion : score M A B ≠ (1:ℝ)/2 ∨ ∀ i, q M A B i=(1:ℝ)/2) :
182
+ Tendsto (fun N => binomialError M N A B) atTop
183
+ (𝓝 (Obligations045.M0.limitingLoss (score M A B))) := by
184
+ rcases hregion with h | h
185
+ · exact conditional_offdiag_limit M A B h
186
+ · rw [unbiased_score M A B h]
187
+ norm_num [Obligations045.M0.limitingLoss]
188
+ simpa only [unbiased_conditional_exact M A B h] using
189
+ (tendsto_const_nhds : Tendsto (fun _ : ℕ => (1:ℝ)/2) atTop (𝓝 ((1:ℝ)/2)))
190
+
191
+ /-- Full mixture may contain genuinely diagonal states, provided every such state
192
+ is in the proved unbiased subdomain. Heterogeneous diagonal is NOT assumed solved. -/
193
+ theorem implementation_limit_offdiag_or_unbiased (M : Model)
194
+ (hregions : ∀ (A : Ancestors M) (B : Leaves M),
195
+ score M A B ≠ (1:ℝ)/2 ∨ ∀ i, q M A B i=(1:ℝ)/2) :
196
+ Tendsto (implementationError M) atTop (𝓝 (thresholdFunctional M)) := by
197
+ unfold implementationError thresholdFunctional
198
+ apply tendsto_finset_sum
199
+ intro A _
200
+ apply tendsto_finset_sum
201
+ intro B _
202
+ exact tendsto_const_nhds.mul (conditional_limit_offdiag_or_unbiased M A B (hregions A B))
203
+
204
+ theorem generator_limit_offdiag_or_unbiased (M : Model)
205
+ (hregions : ∀ (A : Ancestors M) (B : Leaves M),
206
+ score M A B ≠ (1:ℝ)/2 ∨ ∀ i, q M A B i=(1:ℝ)/2) :
207
+ Tendsto (fun N : ℕ => ∫ x, Obligations045.M0.fairLoss
208
+ (∑ i, (primitiveCounts M N x.1.1 x.1.2 x.2 i:ℕ)) N ∂(fullLaw M N).toMeasure)
209
+ atTop (𝓝 (thresholdFunctional M)) := by
210
+ simpa only [full_generator_error_bridge] using implementation_limit_offdiag_or_unbiased M hregions
211
+
212
+ /-- Finite CDF under the declared conditional product-member law. -/
213
+ def cdf (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) (z : ℝ) : ℝ :=
214
+ ∑ x : members M N, weights M A B N x*
215
+ (if ((correctCount x:ℝ)-mean M A B N)/sigma M A B N ≤ z then (1:ℝ) else 0)
216
+
217
+ def primitiveCdf (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) (z : ℝ) : ℝ :=
218
+ ∫ x, (if (((∑ i, (primitiveCounts M N A B x i:ℕ)):ℝ)-mean M A B N)/sigma M A B N ≤ z
219
+ then (1:ℝ) else 0) ∂(primitiveLaw M N).toMeasure
220
+
221
+ theorem primitive_cdf_eq (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) (z : ℝ) :
222
+ primitiveCdf M A B N z=cdf M A B N z := by
223
+ let f : (∀ i : Fin M.base.K, Fin (sizes M N i+1)) → ℝ := fun k =>
224
+ if (((∑ i, (k i:ℕ)):ℝ)-mean M A B N)/sigma M A B N ≤ z then 1 else 0
225
+ change (∫ x, f (primitiveCounts M N A B x) ∂(primitiveLaw M N).toMeasure)=_
226
+ rw [primitive_law_count_expectation M N A B f]
227
+ symm
228
+ simpa only [cdf, weights, correctCount, count, f, Nat.cast_sum] using
229
+ joint_count_pushforward (sizes M N) (q M A B) f
230
+
231
+ theorem lower_cut (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) (hN : 0<N)
232
+ (z : ℝ) (hz : z<threshold M A B N) : cdf M A B N z ≤ binomialError M N A B := by
233
+ rw [conditional_member_error]
234
+ apply Finset.sum_le_sum
235
+ intro x _
236
+ exact mul_le_mul_of_nonneg_left
237
+ (Obligations046.Threshold.lower_cut_pointwise _ _ _ _ _ (sigma_pos M A B N hN) hz)
238
+ (weights_nonneg M A B N x)
239
+
240
+ theorem upper_cut (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) (hN : 0<N)
241
+ (z : ℝ) (hz : threshold M A B N<z) : binomialError M N A B ≤ cdf M A B N z := by
242
+ rw [conditional_member_error]
243
+ apply Finset.sum_le_sum
244
+ intro x _
245
+ exact mul_le_mul_of_nonneg_left
246
+ (Obligations046.Threshold.upper_cut_pointwise _ _ _ _ _ (sigma_pos M A B N hN) hz)
247
+ (weights_nonneg M A B N x)
248
+
249
+ /-- CONDITIONAL transfer only. The fixed-cut CDF limit hCLT is an explicit
250
+ unpaid hypothesis; Lindeberg vanishing is not silently used as a CLT theorem. -/
251
+ theorem diagonal_transfer_of_fixed_cut_limits (M : Model) (A : Ancestors M) (B : Leaves M)
252
+ (hdiag : score M A B=(1:ℝ)/2) (F : ℝ→ℝ) (hF : ContinuousAt F 0)
253
+ (hCLT : ∀ z, Tendsto (fun N => primitiveCdf M A B N z) atTop (𝓝 (F z))) :
254
+ Tendsto (fun N => binomialError M N A B) atTop (𝓝 (F 0)) := by
255
+ apply Obligations046.Threshold.moving_cut_sandwich (cdf M A B) F (threshold M A B)
256
+ (fun N => binomialError M N A B) hF
257
+ (fun z => by simpa only [primitive_cdf_eq] using hCLT z) (threshold_limit M A B hdiag)
258
+ · filter_upwards [eventually_ge_atTop 1] with N hN
259
+ exact lower_cut M A B N (by omega)
260
+ · filter_upwards [eventually_ge_atTop 1] with N hN
261
+ exact upper_cut M A B N (by omega)
262
+
263
+ /-- A two-level model with a genuine positive-mass diagonal latent state. -/
264
+ def exampleModel : Model where
265
+ base := {
266
+ K := 1
267
+ K_pos := by norm_num
268
+ p := 3/4
269
+ c := 1/5
270
+ p_half := by norm_num
271
+ p_lt_one := by norm_num
272
+ c_nonneg := by norm_num
273
+ c_lt_one := by norm_num
274
+ w := fun _ => 1
275
+ w_nonneg := fun _ => by norm_num
276
+ weights_sum := by norm_num [Finset.sum_range_succ] }
277
+ ancestors := 1
278
+ parent := fun _ => 0
279
+ c2 := 1/6
280
+ c2_nonneg := by norm_num
281
+ c2_lt_one := by norm_num
282
+
283
+ /-- All four latent states: one unbiased diagonal, three off-diagonal. -/
284
+ theorem example_regions (A : Ancestors exampleModel) (B : Leaves exampleModel) :
285
+ score exampleModel A B ≠ (1:ℝ)/2 ∨ ∀ i, q exampleModel A B i=(1:ℝ)/2 := by
286
+ change (∑ i : Fin 1, (1:ℝ)*success (3/4) (1/5) (1/6) (A (0:Fin 1)) (B i)) ≠ 1/2 ∨
287
+ ∀ i : Fin 1, success (3/4) (1/5) (1/6) (A (0:Fin 1)) (B i)=1/2
288
+ cases ha : A (0:Fin 1) <;> cases hb : B (0:Fin 1)
289
+ · right
290
+ intro i
291
+ have hi : i=(0:Fin 1) := Fin.eq_zero i
292
+ subst i
293
+ norm_num [success, ha, hb]
294
+ all_goals
295
+ left
296
+ norm_num [success, Fin.sum_univ_succ, ha, hb]
297
+
298
+ theorem example_generator_limit :
299
+ Tendsto (fun N : ℕ => ∫ x, Obligations045.M0.fairLoss
300
+ (∑ i, (primitiveCounts exampleModel N x.1.1 x.1.2 x.2 i:ℕ)) N
301
+ ∂(fullLaw exampleModel N).toMeasure) atTop (𝓝 (thresholdFunctional exampleModel)) :=
302
+ generator_limit_offdiag_or_unbiased exampleModel example_regions
303
+
304
+ /-- Enumerate functions on one named origin, without a finite-grid assumption on probabilities. -/
305
+ theorem sum_one_bit (f : (Fin 1→Bool)→ℝ) :
306
+ (∑ a : Fin 1→Bool, f a)=f (fun _ => false)+f (fun _ => true) := by
307
+ have hbij : Function.Bijective (fun a : Fin 1→Bool => a 0) := by
308
+ constructor
309
+ · intro a b hab
310
+ funext i
311
+ rw [Fin.eq_zero i]
312
+ exact hab
313
+ · intro b
314
+ exact ⟨fun _ => b, rfl⟩
315
+ have h := Fintype.sum_bijective (fun a : Fin 1→Bool => a 0) hbij f
316
+ (fun b => f (fun _ => b)) (fun a => congrArg f (funext (fun i => congrArg a (Fin.eq_zero i))))
317
+ simpa only [Fintype.sum_bool, add_comm] using h
318
+
319
+ theorem example_threshold_exact : thresholdFunctional exampleModel=(1:ℝ)/32 := by
320
+ change (∑ A : Fin 1→Bool, ∑ B : Fin 1→Bool,
321
+ ((∏ g : Fin 1, bernMass (3/4) (A g))*(∏ i : Fin 1, bernMass (3/4) (B i)))*
322
+ Obligations045.M0.limitingLoss (∑ i : Fin 1,
323
+ (1:ℝ)*success (3/4) (1/5) (1/6) (A (0:Fin 1)) (B i))) = 1/32
324
+ rw [sum_one_bit]
325
+ simp only [sum_one_bit]
326
+ norm_num [Fin.sum_univ_succ, Fin.prod_univ_succ, bernMass, success, Obligations045.M0.limitingLoss]
327
+
328
+ theorem example_generator_limit_exact :
329
+ Tendsto (fun N : ℕ => ∫ x, Obligations045.M0.fairLoss
330
+ (∑ i, (primitiveCounts exampleModel N x.1.1 x.1.2 x.2 i:ℕ)) N
331
+ ∂(fullLaw exampleModel N).toMeasure) atTop (𝓝 ((1:ℝ)/32)) := by
332
+ simpa only [example_threshold_exact] using example_generator_limit
333
+
334
+ end Obligations046.M1Diagonal
@@ -0,0 +1,270 @@
1
+ import M1Bridge046
2
+ import M0Moments046
3
+
4
+ open scoped BigOperators
5
+ open Filter Topology MeasureTheory ProbabilityTheory
6
+ noncomputable section
7
+ open Classical Obligations046.M1Bridge Obligations046.Bridge
8
+ namespace Obligations046.M1Offdiag
9
+
10
+ /-- Actual finite conditional mean and variance; no convergence premise. -/
11
+ def mean (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) : ℝ :=
12
+ ∑ i : Fin M.base.K, (sizes M N i : ℝ)*q M A B i
13
+ def variance (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) : ℝ :=
14
+ ∑ i : Fin M.base.K, (sizes M N i : ℝ)*q M A B i*(1-q M A B i)
15
+ def score (M : Model) (A : Ancestors M) (B : Leaves M) : ℝ :=
16
+ ∑ i : Fin M.base.K, M.base.w i*q M A B i
17
+
18
+ theorem q_bounds (M : Model) (A : Ancestors M) (B : Leaves M) (i : Fin M.base.K) :
19
+ 0 ≤ q M A B i ∧ q M A B i ≤ 1 := by
20
+ have hn (e : Fin 4) : 0 ≤ branchMass M.base.p M.base.c M.c2 e :=
21
+ branch_nonneg _ _ _ (by linarith [M.base.p_half]) M.base.p_lt_one.le
22
+ M.base.c_nonneg M.base.c_lt_one.le M.c2_nonneg M.c2_lt_one.le e
23
+ have ht : 0 ≤ ∑ e : Fin 4, if branchBit (A (M.parent i)) (B i) e = true
24
+ then branchMass M.base.p M.base.c M.c2 e else 0 := by
25
+ apply Finset.sum_nonneg
26
+ intro e _
27
+ split_ifs
28
+ · exact hn e
29
+ · exact le_rfl
30
+ have hf : 0 ≤ ∑ e : Fin 4, if branchBit (A (M.parent i)) (B i) e = false
31
+ then branchMass M.base.p M.base.c M.c2 e else 0 := by
32
+ apply Finset.sum_nonneg
33
+ intro e _
34
+ split_ifs
35
+ · exact hn e
36
+ · exact le_rfl
37
+ rw [branch_bit_fiber] at ht hf
38
+ change 0 ≤ q M A B i at ht
39
+ change 0 ≤ 1-q M A B i at hf
40
+ exact ⟨ht, by linarith⟩
41
+
42
+ theorem mean_ratio_limit (M : Model) (A : Ancestors M) (B : Leaves M) :
43
+ Tendsto (fun N : ℕ => mean M A B N/(N:ℝ)) atTop (𝓝 (score M A B)) := by
44
+ have h := tendsto_finset_sum Finset.univ (fun (i : Fin M.base.K) _ =>
45
+ (Obligations045.M0.allocation_ratio M.base i).mul_const (q M A B i))
46
+ convert h using 1
47
+ funext N
48
+ simp only [mean, score, Finset.sum_div, div_mul_eq_mul_div]
49
+
50
+ theorem variance_le (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) :
51
+ variance M A B N ≤ (N:ℝ)/4 := by
52
+ have hs : ∑ i : Fin M.base.K, (sizes M N i : ℝ) = (N:ℝ) := by
53
+ exact_mod_cast (by simpa only [Fin.sum_univ_eq_sum_range] using
54
+ Obligations045.M0.allocation_sum M.base N)
55
+ calc
56
+ _ ≤ ∑ i : Fin M.base.K, (sizes M N i : ℝ)*(1/4) := by
57
+ apply Finset.sum_le_sum
58
+ intro i _
59
+ have h : q M A B i*(1-q M A B i) ≤ 1/4 := by
60
+ nlinarith [sq_nonneg (q M A B i-1/2)]
61
+ simpa only [mul_assoc] using mul_le_mul_of_nonneg_left h (Nat.cast_nonneg (sizes M N i))
62
+ _ = _ := by rw [← Finset.sum_mul, hs]; ring
63
+
64
+ /-- Off-diagonal loss is locally constant; only a squared deviation can change it. -/
65
+ theorem loss_left_bound (x m eps : ℝ) (he : 0 < eps) (hm : m+eps ≤ 1/2) :
66
+ |Obligations045.M0.limitingLoss x-1| ≤ (x-m)^2/eps^2 := by
67
+ by_cases hx : x < (1:ℝ)/2
68
+ · simp only [Obligations045.M0.limitingLoss, if_pos hx, sub_self, abs_zero]
69
+ positivity
70
+ · have hx' : (1:ℝ)/2 ≤ x := le_of_not_gt hx
71
+ have hd : eps^2 ≤ (x-m)^2 := by
72
+ nlinarith [sq_nonneg (x-m-eps)]
73
+ have hu : (1:ℝ) ≤ (x-m)^2/eps^2 := by
74
+ exact (le_div_iff₀ (sq_pos_of_pos he)).mpr (by simpa using hd)
75
+ have hb : |Obligations045.M0.limitingLoss x-1| ≤ 1 := by
76
+ unfold Obligations045.M0.limitingLoss
77
+ split_ifs <;> norm_num [abs_div]
78
+ exact hb.trans hu
79
+
80
+ theorem loss_right_bound (x m eps : ℝ) (he : 0 < eps) (hm : 1/2 ≤ m-eps) :
81
+ |Obligations045.M0.limitingLoss x| ≤ (x-m)^2/eps^2 := by
82
+ by_cases hx : (1:ℝ)/2 < x
83
+ · have hn : ¬ x < (1:ℝ)/2 := not_lt.mpr hx.le
84
+ simp only [Obligations045.M0.limitingLoss, if_neg hn, if_neg (Ne.symm hx.ne), abs_zero]
85
+ positivity
86
+ · have hx' : x ≤ (1:ℝ)/2 := le_of_not_gt hx
87
+ have hd : eps^2 ≤ (x-m)^2 := by
88
+ nlinarith [sq_nonneg (m-x-eps)]
89
+ have hu : (1:ℝ) ≤ (x-m)^2/eps^2 := by
90
+ exact (le_div_iff₀ (sq_pos_of_pos he)).mpr (by simpa using hd)
91
+ have hb : |Obligations045.M0.limitingLoss x| ≤ 1 := by
92
+ unfold Obligations045.M0.limitingLoss
93
+ split_ifs <;> norm_num [abs_div]
94
+ exact hb.trans hu
95
+
96
+ abbrev members (M : Model) (N : ℕ) := World (sizes M N)
97
+ def weights (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ)
98
+ (x : members M N) := jointMass (sizes M N) (q M A B) x
99
+
100
+ theorem weights_nonneg (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ)
101
+ (x : members M N) : 0 ≤ weights M A B N x := by
102
+ unfold weights jointMass
103
+ exact Finset.prod_nonneg (fun i _ => mass_nonneg _ (q_bounds M A B i).1
104
+ (q_bounds M A B i).2 (x i))
105
+
106
+ theorem weights_sum (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) :
107
+ ∑ x : members M N, weights M A B N x = 1 := jointMass_sum _ _
108
+
109
+ theorem conditional_member_error (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) :
110
+ binomialError M N A B = ∑ x : members M N, weights M A B N x*
111
+ Obligations045.M0.fairLoss (correctCount x) N := by
112
+ symm
113
+ simpa only [weights, binomialError, correctCount, count] using
114
+ joint_count_pushforward (sizes M N) (q M A B)
115
+ (fun k => Obligations045.M0.fairLoss (∑ i, (k i : ℕ)) N)
116
+
117
+ theorem centered_second (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ) :
118
+ (∑ x : members M N, weights M A B N x*((correctCount x:ℝ)-mean M A B N)^2) =
119
+ variance M A B N := by
120
+ have h := Obligations046.Moments.member_total_centered_second (sizes M N) (q M A B)
121
+ (fun i => (q_bounds M A B i).1) (fun i => (q_bounds M A B i).2)
122
+ rw [memberLaw_expectation] at h
123
+ exact h
124
+
125
+ /-- A direct finite Chebyshev bound. The test function is bounded POINTWISE; no
126
+ independence between pair scores, ambient process, CLT or limit is assumed. -/
127
+ theorem conditional_gap_bound (M : Model) (A : Ancestors M) (B : Leaves M) (N : ℕ)
128
+ (hN : 0 < N) (eps target : ℝ) (he : 0 < eps)
129
+ (hpoint : ∀ x : ℝ, |Obligations045.M0.limitingLoss x-target| ≤
130
+ (x-mean M A B N/(N:ℝ))^2/eps^2) :
131
+ |binomialError M N A B-target| ≤ 1/(4*(N:ℝ)*eps^2) := by
132
+ have hn : (0:ℝ) < N := by exact_mod_cast hN
133
+ have hd : 0 < (N:ℝ)^2*eps^2 := by positivity
134
+ have hnorm := weights_sum M A B N
135
+ have hrew : binomialError M N A B-target =
136
+ ∑ x : members M N, weights M A B N x*(Obligations045.M0.fairLoss (correctCount x) N-target) := by
137
+ rw [conditional_member_error]
138
+ simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hnorm, one_mul]
139
+ rw [hrew]
140
+ calc
141
+ _ ≤ ∑ x : members M N, |weights M A B N x*
142
+ (Obligations045.M0.fairLoss (correctCount x) N-target)| := Finset.abs_sum_le_sum_abs _ _
143
+ _ = ∑ x : members M N, weights M A B N x*
144
+ |Obligations045.M0.fairLoss (correctCount x) N-target| := by
145
+ apply Finset.sum_congr rfl
146
+ intro x _
147
+ rw [abs_mul, abs_of_nonneg (weights_nonneg M A B N x)]
148
+ _ ≤ ∑ x : members M N, weights M A B N x*
149
+ (((correctCount x:ℝ)-mean M A B N)^2/((N:ℝ)^2*eps^2)) := by
150
+ apply Finset.sum_le_sum
151
+ intro x _
152
+ apply mul_le_mul_of_nonneg_left _ (weights_nonneg M A B N x)
153
+ rw [fair_loss_average_bridge _ _ hN]
154
+ have h := hpoint ((correctCount x:ℝ)/(N:ℝ))
155
+ convert h using 1
156
+ field_simp
157
+ _ = variance M A B N/((N:ℝ)^2*eps^2) := by
158
+ simp_rw [← mul_div_assoc]
159
+ rw [← Finset.sum_div, centered_second]
160
+ _ ≤ ((N:ℝ)/4)/((N:ℝ)^2*eps^2) :=
161
+ div_le_div_of_nonneg_right (variance_le M A B N) hd.le
162
+ _ = _ := by field_simp; ring
163
+
164
+ /-- This positive O(1/N) bound tends to zero with epsilon FIXED. -/
165
+ theorem tail_bound_limit (eps : ℝ) :
166
+ Tendsto (fun N : ℕ => 1/(4*(N:ℝ)*eps^2)) atTop (𝓝 0) := by
167
+ have h : Tendsto (fun N : ℕ => (1:ℝ)/(N:ℝ)) atTop (𝓝 0) :=
168
+ tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop
169
+ have heq : (fun N : ℕ => 1/(4*(N:ℝ)*eps^2)) =
170
+ (fun N : ℕ => ((1:ℝ)/(N:ℝ))/(4*eps^2)) := by funext N; ring
171
+ rw [heq]
172
+ simpa using h.div_const (4*eps^2)
173
+
174
+ /-- New finite M1 conditional probability limit, derived from quota convergence
175
+ and the finite generator/binomial law; no convergence premise or ambient iid oracle. -/
176
+ theorem conditional_offdiag_limit (M : Model) (A : Ancestors M) (B : Leaves M)
177
+ (hoff : score M A B ≠ (1:ℝ)/2) :
178
+ Tendsto (fun N : ℕ => binomialError M N A B) atTop
179
+ (𝓝 (Obligations045.M0.limitingLoss (score M A B))) := by
180
+ by_cases hs : score M A B < (1:ℝ)/2
181
+ · let eps : ℝ := (1/2-score M A B)/2
182
+ have he : 0 < eps := by dsimp [eps]; linarith
183
+ have hm : ∀ᶠ N in atTop, mean M A B N/(N:ℝ)+eps ≤ (1:ℝ)/2 := by
184
+ have h := (mean_ratio_limit M A B).eventually
185
+ (Iio_mem_nhds (show score M A B < (1:ℝ)/2-eps by dsimp [eps]; linarith))
186
+ filter_upwards [h] with N hN
187
+ linarith
188
+ have hb : ∀ᶠ N in atTop, |binomialError M N A B-1| ≤ 1/(4*(N:ℝ)*eps^2) := by
189
+ filter_upwards [hm, eventually_ge_atTop 1] with N hm hN
190
+ exact conditional_gap_bound M A B N (by omega) eps 1 he
191
+ (fun x => loss_left_bound x _ eps he hm)
192
+ have h := squeeze_zero' (Eventually.of_forall (fun N => abs_nonneg (binomialError M N A B-1))) hb
193
+ (tail_bound_limit eps)
194
+ rw [Obligations045.M0.limitingLoss, if_pos hs]
195
+ exact (tendsto_iff_norm_sub_tendsto_zero).mpr (by simpa only [Real.norm_eq_abs] using h)
196
+ · have hs' : (1:ℝ)/2 < score M A B := lt_of_le_of_ne (le_of_not_gt hs) (Ne.symm hoff)
197
+ let eps : ℝ := (score M A B-1/2)/2
198
+ have he : 0 < eps := by dsimp [eps]; linarith
199
+ have hm : ∀ᶠ N in atTop, (1:ℝ)/2 ≤ mean M A B N/(N:ℝ)-eps := by
200
+ have h := (mean_ratio_limit M A B).eventually
201
+ (Ioi_mem_nhds (show (1:ℝ)/2+eps < score M A B by dsimp [eps]; linarith))
202
+ filter_upwards [h] with N hN
203
+ linarith
204
+ have hb : ∀ᶠ N in atTop, |binomialError M N A B| ≤ 1/(4*(N:ℝ)*eps^2) := by
205
+ filter_upwards [hm, eventually_ge_atTop 1] with N hm hN
206
+ simpa only [sub_zero] using conditional_gap_bound M A B N (by omega) eps 0 he
207
+ (fun x => by simpa only [sub_zero] using loss_right_bound x _ eps he hm)
208
+ have h := squeeze_zero' (Eventually.of_forall (fun N => abs_nonneg (binomialError M N A B))) hb
209
+ (tail_bound_limit eps)
210
+ rw [Obligations045.M0.limitingLoss, if_neg hs, if_neg hoff]
211
+ exact (tendsto_iff_norm_sub_tendsto_zero).mpr (by simpa only [Real.norm_eq_abs, sub_zero] using h)
212
+
213
+ def thresholdFunctional (M : Model) : ℝ :=
214
+ ∑ A : Ancestors M, ∑ B : Leaves M,
215
+ latentMass M A B * Obligations045.M0.limitingLoss (score M A B)
216
+
217
+ /-- All latent configurations are positive mass forp in(1/2,1). No diagonal
218
+ configuration is silently discarded or called a fork. -/
219
+ theorem implementation_offdiag_limit (M : Model)
220
+ (hoff : ∀ (A : Ancestors M) (B : Leaves M), score M A B ≠ (1:ℝ)/2) :
221
+ Tendsto (implementationError M) atTop (𝓝 (thresholdFunctional M)) := by
222
+ unfold implementationError thresholdFunctional
223
+ apply tendsto_finset_sum
224
+ intro A _
225
+ apply tendsto_finset_sum
226
+ intro B _
227
+ exact tendsto_const_nhds.mul (conditional_offdiag_limit M A B (hoff A B))
228
+
229
+ /-- Limit of the ACTUAL full generator probabilities via the admitted exact bridge. -/
230
+ theorem generator_offdiag_limit (M : Model)
231
+ (hoff : ∀ (A : Ancestors M) (B : Leaves M), score M A B ≠ (1:ℝ)/2) :
232
+ Tendsto (fun N : ℕ => ∫ x, Obligations045.M0.fairLoss
233
+ (∑ i, (primitiveCounts M N x.1.1 x.1.2 x.2 i : ℕ)) N ∂(fullLaw M N).toMeasure)
234
+ atTop (𝓝 (thresholdFunctional M)) := by
235
+ simpa only [full_generator_error_bridge] using implementation_offdiag_limit M hoff
236
+
237
+ /-- The existing exact shared-parent example: genuinely nonzero rates on both levels. -/
238
+ def exampleModel : Model where
239
+ base := {
240
+ K := 2
241
+ K_pos := by norm_num
242
+ p := 2/3
243
+ c := 1/2
244
+ p_half := by norm_num
245
+ p_lt_one := by norm_num
246
+ c_nonneg := by norm_num
247
+ c_lt_one := by norm_num
248
+ w := fun _ => 1/2
249
+ w_nonneg := fun _ => by norm_num
250
+ weights_sum := by norm_num [Finset.sum_range_succ] }
251
+ ancestors := 1
252
+ parent := fun _ => 0
253
+ c2 := 1/2
254
+ c2_nonneg := by norm_num
255
+ c2_lt_one := by norm_num
256
+
257
+ theorem example_offdiag (A : Ancestors exampleModel) (B : Leaves exampleModel) :
258
+ score exampleModel A B ≠ (1:ℝ)/2 := by
259
+ change (∑ i : Fin 2, (1/2:ℝ)*success (2/3) (1/2) (1/2) (A (0:Fin 1)) (B i)) ≠ 1/2
260
+ cases ha : A (0:Fin 1) <;> cases hb : B (0:Fin 2) <;> cases hc : B (1:Fin 2) <;>
261
+ norm_num [success, Fin.sum_univ_succ, ha, hb, hc]
262
+
263
+ theorem example_generator_limit :
264
+ Tendsto (fun N : ℕ => ∫ x, Obligations045.M0.fairLoss
265
+ (∑ i, (primitiveCounts exampleModel N x.1.1 x.1.2 x.2 i : ℕ)) N
266
+ ∂(fullLaw exampleModel N).toMeasure)
267
+ atTop (𝓝 (thresholdFunctional exampleModel)) :=
268
+ generator_offdiag_limit exampleModel example_offdiag
269
+
270
+ end Obligations046.M1Offdiag