@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,295 @@
1
+ import M0Diagonal046
2
+ import Mathlib.Probability.Variance
3
+ open scoped BigOperators
4
+ open Filter Topology MeasureTheory
5
+ noncomputable section
6
+ open Classical Obligations045.M0 Obligations046.Bridge Obligations046.Diagonal
7
+ namespace Obligations046.Moments
8
+
9
+ /-- Finite binomial expectation; no asymptotic certificate. -/
10
+ def binExpect (p : ℝ) (n : ℕ) (f : ℕ → ℝ) : ℝ :=
11
+ ∑ k ∈ Finset.range (n+1), (n.choose k : ℝ)*p^k*(1-p)^(n-k)*f k
12
+
13
+ theorem binExpect_one (p : ℝ) (n : ℕ) : binExpect p n (fun _ => 1) = 1 := by
14
+ unfold binExpect
15
+ simp only [mul_one]
16
+ calc
17
+ _ = (p+(1-p))^n := by
18
+ rw [add_pow]
19
+ apply Finset.sum_congr rfl
20
+ intro k _
21
+ ring
22
+ _ = 1 := by simp
23
+
24
+ theorem binExpect_succ (p : ℝ) (n : ℕ) (f : ℕ → ℝ) :
25
+ binExpect p (n+1) f =
26
+ (1-p)*binExpect p n f + p*binExpect p n (fun k => f (k+1)) := by
27
+ have h := Finset.sum_choose_succ_mul (fun k j => p^k*(1-p)^j*f k) n
28
+ unfold binExpect
29
+ simp only [Nat.add_assoc] at h ⊢
30
+ calc
31
+ _ = (∑ k ∈ Finset.range (n+1), (n.choose k:ℝ)*(p^k*(1-p)^(n+1-k)*f k)) +
32
+ ∑ k ∈ Finset.range (n+1), (n.choose k:ℝ)*(p^(k+1)*(1-p)^(n-k)*f (k+1)) := by
33
+ convert h using 1
34
+ apply Finset.sum_congr rfl
35
+ intro k _
36
+ ring
37
+ _ = _ := by
38
+ rw [Finset.mul_sum, Finset.mul_sum]
39
+ congr 1
40
+ · apply Finset.sum_congr rfl
41
+ intro k hk
42
+ have hk' : k ≤ n := by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hk
43
+ rw [show n+1-k = (n-k)+1 by omega, pow_succ]
44
+ ring
45
+ · apply Finset.sum_congr rfl
46
+ intro k _
47
+ rw [pow_succ]
48
+ ring
49
+
50
+ theorem binExpect_add (p : ℝ) (n : ℕ) (f g : ℕ → ℝ) :
51
+ binExpect p n (fun k => f k+g k) = binExpect p n f + binExpect p n g := by
52
+ simp [binExpect, mul_add, Finset.sum_add_distrib]
53
+
54
+ theorem binExpect_mul_const (p : ℝ) (n : ℕ) (f : ℕ → ℝ) (r : ℝ) :
55
+ binExpect p n (fun k => f k*r) = binExpect p n f*r := by
56
+ simp only [binExpect, ← mul_assoc, Finset.sum_mul]
57
+
58
+ theorem binExpect_const (p r : ℝ) (n : ℕ) : binExpect p n (fun _ => r) = r := by
59
+ simpa only [one_mul, binExpect_one] using binExpect_mul_const p n (fun _ => 1) r
60
+
61
+ theorem binExpect_mean (p : ℝ) (n : ℕ) : binExpect p n (fun k => (k:ℝ)) = (n:ℝ)*p := by
62
+ induction n with
63
+ | zero => simp [binExpect]
64
+ | succ n ih =>
65
+ rw [binExpect_succ]
66
+ have hshift : binExpect p n (fun k => ((k+1:ℕ):ℝ)) = (n:ℝ)*p+1 := by
67
+ simp only [Nat.cast_add, Nat.cast_one]
68
+ rw [binExpect_add, ih, binExpect_const]
69
+ rw [hshift, ih]
70
+ push_cast
71
+ ring
72
+
73
+ theorem binExpect_second (p : ℝ) (n : ℕ) :
74
+ binExpect p n (fun k => (k:ℝ)^2) = (n:ℝ)*p*(1-p)+((n:ℝ)*p)^2 := by
75
+ induction n with
76
+ | zero => simp [binExpect]
77
+ | succ n ih =>
78
+ rw [binExpect_succ, ih]
79
+ have heq : (fun k : ℕ => ((k+1:ℕ):ℝ)^2) =
80
+ (fun k : ℕ => ((k:ℝ)^2 + (k:ℝ)*2) + 1) := by funext k; push_cast; ring
81
+ rw [heq, binExpect_add, binExpect_add, binExpect_mul_const,
82
+ binExpect_mean, binExpect_const, ih]
83
+ push_cast
84
+ ring
85
+
86
+ /-- Finite pushforward of a scalar observable, without an asserted moment. -/
87
+ theorem finite_pushforward {S T : Type*} [Fintype S] [Fintype T] [DecidableEq T]
88
+ (m : S → ℝ) (c : S → T) (f : T → ℝ) :
89
+ (∑ x, m x*f (c x)) = ∑ y, (∑ x, if c x=y then m x else 0)*f y := by
90
+ symm
91
+ simp_rw [Finset.sum_mul]
92
+ rw [Finset.sum_comm]
93
+ apply Finset.sum_congr rfl
94
+ intro x _
95
+ simp_rw [ite_mul, zero_mul]
96
+ simp
97
+
98
+ theorem mass_card_expect (p : ℝ) (n : ℕ) (f : ℕ → ℝ) :
99
+ (∑ x : Finset (Fin n), mass p x*f x.card) = binExpect p n f := by
100
+ calc
101
+ _ = ∑ k : Fin (n+1), binMass p n k*f k := by
102
+ simpa only [count_fiber_mass] using
103
+ finite_pushforward (mass p) (@count n) (fun k => f (k:ℕ))
104
+ _ = binExpect p n f := by
105
+ simp only [binMass, binExpect]
106
+ exact Fin.sum_univ_eq_sum_range
107
+ (fun k : ℕ => (n.choose k:ℝ)*p^k*(1-p)^(n-k)*f k) (n+1)
108
+
109
+ section ProductMoments
110
+ variable {ι : Type*} [Fintype ι] [DecidableEq ι]
111
+ {S : ι → Type*} [∀ i, Fintype (S i)]
112
+
113
+ def expect (m : ∀ i, S i → ℝ) (f : (∀ i, S i) → ℝ) : ℝ :=
114
+ ∑ x, (∏ i, m i (x i))*f x
115
+
116
+ theorem expect_product (m : ∀ i, S i → ℝ) (f : ∀ i, S i → ℝ) :
117
+ expect m (fun x => ∏ i, f i (x i)) = ∏ i, ∑ s, m i s*f i s := by
118
+ simp only [expect, ← Finset.prod_mul_distrib, Fintype.prod_sum]
119
+
120
+ theorem expect_coordinate (m : ∀ i, S i → ℝ) (hm : ∀ i, ∑ s, m i s = 1)
121
+ (f : ∀ i, S i → ℝ) (j : ι) :
122
+ expect m (fun x => f j (x j)) = ∑ s, m j s*f j s := by
123
+ calc
124
+ _ = expect m (fun x => ∏ i, if i=j then f i (x i) else 1) := by simp
125
+ _ = ∏ i, ∑ s, m i s * (if i=j then f i s else 1) := expect_product m (fun i s => if i=j then f i s else 1)
126
+ _ = ∏ i, if i=j then (∑ s, m i s*f i s) else 1 := by
127
+ apply Finset.prod_congr rfl
128
+ intro i _
129
+ by_cases h : i=j <;> simp [h, hm]
130
+ _ = _ := by simp
131
+
132
+ theorem expect_sum {κ : Type*} [Fintype κ] (m : ∀ i, S i → ℝ)
133
+ (f : κ → (∀ i, S i) → ℝ) :
134
+ expect m (fun x => ∑ j, f j x) = ∑ j, expect m (f j) := by
135
+ simp only [expect, Finset.mul_sum]
136
+ rw [Finset.sum_comm]
137
+
138
+ theorem expect_cross_centered (m : ∀ i, S i → ℝ)
139
+ (f : ∀ i, S i → ℝ) (hf : ∀ i, ∑ s, m i s*f i s = 0)
140
+ (i j : ι) (hne : i≠j) :
141
+ expect m (fun x => f i (x i)*f j (x j)) = 0 := by
142
+ calc
143
+ _ = expect m (fun x => ∏ k, if k=i then f k (x k) else if k=j then f k (x k) else 1) := by
144
+ congr 1
145
+ funext x
146
+ rw [Finset.prod_eq_mul_prod_diff_singleton (Finset.mem_univ i)]
147
+ simp only [ite_true]
148
+ congr 1
149
+ symm
150
+ calc
151
+ _ = ∏ k ∈ Finset.univ \ {i}, if k=j then f k (x k) else 1 := by
152
+ apply Finset.prod_congr rfl
153
+ intro k hk
154
+ have hki : k≠i := by simpa using (Finset.mem_sdiff.mp hk).2
155
+ simp only [if_neg hki]
156
+ _ = f j (x j) := by simp [Finset.prod_ite_eq', Ne.symm hne]
157
+ _ = ∏ k, ∑ s, m k s*(if k=i then f k s else if k=j then f k s else 1) :=
158
+ expect_product m (fun k s => if k=i then f k s else if k=j then f k s else 1)
159
+ _ = 0 := Finset.prod_eq_zero (Finset.mem_univ i) (by simpa using hf i)
160
+
161
+ theorem expect_centered_square (m : ∀ i, S i → ℝ)
162
+ (hm : ∀ i, ∑ s, m i s = 1)
163
+ (f : ∀ i, S i → ℝ) (hf : ∀ i, ∑ s, m i s*f i s = 0) :
164
+ expect m (fun x => (∑ i, f i (x i))^2) =
165
+ ∑ i, ∑ s, m i s*(f i s)^2 := by
166
+ simp_rw [pow_two, Fintype.sum_mul_sum, expect_sum]
167
+ apply Finset.sum_congr rfl
168
+ intro i _
169
+ have hc : ∀ j, expect m (fun x => f i (x i)*f j (x j)) =
170
+ if j=i then (∑ s, m i s*(f i s*f i s)) else 0 := by
171
+ intro j
172
+ by_cases h : j=i
173
+ · subst j
174
+ simp only [ite_true]
175
+ exact expect_coordinate m hm (fun k s => f k s*f k s) i
176
+ · rw [if_neg h]
177
+ exact expect_cross_centered m f hf i j (Ne.symm h)
178
+ simp_rw [hc]
179
+ simp
180
+
181
+ end ProductMoments
182
+
183
+ theorem mass_card_mean (p : ℝ) (n : ℕ) :
184
+ (∑ x : Finset (Fin n), mass p x*(x.card:ℝ)) = (n:ℝ)*p := by
185
+ rw [mass_card_expect, binExpect_mean]
186
+
187
+ theorem mass_card_second (p : ℝ) (n : ℕ) :
188
+ (∑ x : Finset (Fin n), mass p x*(x.card:ℝ)^2) =
189
+ (n:ℝ)*p*(1-p)+((n:ℝ)*p)^2 := by
190
+ calc
191
+ _ = binExpect p n (fun k => (k:ℝ)^2) := mass_card_expect _ _ _
192
+ _ = _ := binExpect_second p n
193
+
194
+ theorem mass_centered_mean (p : ℝ) (n : ℕ) :
195
+ (∑ x : Finset (Fin n), mass p x*((x.card:ℝ)-(n:ℝ)*p)) = 0 := by
196
+ simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul]
197
+ rw [mass_card_mean, mass_sum]
198
+ ring
199
+
200
+ theorem mass_centered_second (p : ℝ) (n : ℕ) :
201
+ (∑ x : Finset (Fin n), mass p x*((x.card:ℝ)-(n:ℝ)*p)^2) =
202
+ (n:ℝ)*p*(1-p) := by
203
+ calc
204
+ _ = (∑ x : Finset (Fin n), mass p x*(x.card:ℝ)^2) -
205
+ (∑ x : Finset (Fin n), mass p x*(x.card:ℝ))*(2*((n:ℝ)*p)) +
206
+ (∑ x : Finset (Fin n), mass p x)*((n:ℝ)*p)^2 := by
207
+ rw [Finset.sum_mul, Finset.sum_mul, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib]
208
+ apply Finset.sum_congr rfl
209
+ intro x _
210
+ ring
211
+ _ = _ := by rw [mass_card_second, mass_card_mean, mass_sum]; ring
212
+
213
+ section ActualMoments
214
+ variable {ι : Type*} [Fintype ι] [DecidableEq ι]
215
+
216
+ theorem member_total_mean (n : ι → ℕ) (p : ι → ℝ)
217
+ (hp : ∀ i, 0 ≤ p i) (hp1 : ∀ i, p i ≤ 1) :
218
+ (∫ x, (correctCount x:ℝ) ∂(memberLaw n p hp hp1).toMeasure) =
219
+ ∑ i, (n i:ℝ)*p i := by
220
+ rw [memberLaw_expectation]
221
+ change expect (fun i => mass (p i)) (fun x => (correctCount x:ℝ)) = _
222
+ have he : (fun x : World n => (correctCount x:ℝ)) =
223
+ (fun x => ∑ i, ((x i).card:ℝ)) := by funext x; simp [correctCount]
224
+ rw [he, expect_sum]
225
+ apply Finset.sum_congr rfl
226
+ intro i _
227
+ rw [expect_coordinate _ (fun j => mass_sum (p j) (n j))
228
+ (fun j (s : Finset (Fin (n j))) => (s.card:ℝ)), mass_card_mean]
229
+
230
+ theorem member_total_centered_second (n : ι → ℕ) (p : ι → ℝ)
231
+ (hp : ∀ i, 0 ≤ p i) (hp1 : ∀ i, p i ≤ 1) :
232
+ (∫ x, ((correctCount x:ℝ) - ∑ i, (n i:ℝ)*p i)^2
233
+ ∂(memberLaw n p hp hp1).toMeasure) =
234
+ ∑ i, (n i:ℝ)*p i*(1-p i) := by
235
+ rw [memberLaw_expectation]
236
+ change expect (fun i => mass (p i))
237
+ (fun x => ((correctCount x:ℝ) - ∑ i, (n i:ℝ)*p i)^2) = _
238
+ have he : (fun x : World n => ((correctCount x:ℝ) - ∑ i, (n i:ℝ)*p i)^2) =
239
+ (fun x => (∑ i, (((x i).card:ℝ)-(n i:ℝ)*p i))^2) := by
240
+ funext x
241
+ simp only [correctCount, Nat.cast_sum, Finset.sum_sub_distrib]
242
+ rw [he, expect_centered_square _ (fun j => mass_sum (p j) (n j))
243
+ (fun j (s : Finset (Fin (n j))) => (s.card:ℝ)-(n j:ℝ)*p j)
244
+ (fun j => mass_centered_mean (p j) (n j))]
245
+ apply Finset.sum_congr rfl
246
+ intro i _
247
+ exact mass_centered_second (p i) (n i)
248
+
249
+ end ActualMoments
250
+
251
+ theorem model_mean (M : Domain) (a : Fin M.K → Bool) (N : ℕ) :
252
+ (∫ x, (correctCount x:ℝ) ∂(modelLaw M N a).toMeasure) = mean M a N := by
253
+ exact member_total_mean _ _ _ _
254
+
255
+ theorem model_centered_second (M : Domain) (a : Fin M.K → Bool) (N : ℕ) :
256
+ (∫ x, ((correctCount x:ℝ)-mean M a N)^2 ∂(modelLaw M N a).toMeasure) =
257
+ Obligations046.Diagonal.variance M a N := by
258
+ simpa only [mean, Obligations046.Diagonal.variance, mul_assoc] using
259
+ member_total_centered_second (sizes M N) (fun i => q M (a i))
260
+ (fun i => (q_pos M (a i)).le) (fun i => (q_lt_one M (a i)).le)
261
+
262
+ theorem model_variance (M : Domain) (a : Fin M.K → Bool) (N : ℕ) :
263
+ ProbabilityTheory.variance (fun x => (correctCount x:ℝ)) (modelLaw M N a).toMeasure =
264
+ Obligations046.Diagonal.variance M a N := by
265
+ rw [ProbabilityTheory.variance_eq_integral (measurable_of_finite _).aemeasurable,
266
+ model_mean]
267
+ exact model_centered_second M a N
268
+
269
+ /-- The asymptotic variance statements now refer to the actual admitted probability law. -/
270
+ theorem model_variance_rate_limit (M : Domain) (a : Fin M.K → Bool) :
271
+ Tendsto (fun N : ℕ =>
272
+ ProbabilityTheory.variance (fun x => (correctCount x:ℝ)) (modelLaw M N a).toMeasure /
273
+ (N:ℝ)) atTop (𝓝 (varianceRate M a)) := by
274
+ simpa only [model_variance] using variance_rate_limit M a
275
+
276
+ theorem model_variance_atTop (M : Domain) (a : Fin M.K → Bool) :
277
+ Tendsto (fun N : ℕ =>
278
+ ProbabilityTheory.variance (fun x => (correctCount x:ℝ)) (modelLaw M N a).toMeasure)
279
+ atTop atTop := by
280
+ simpa only [model_variance] using variance_atTop M a
281
+
282
+ /-- Counterexample to replacing the joint product law by matching individual marginals.
283
+ Two perfectly correlated Bernoulli(3/4) members have variance 3/4, not 3/8. -/
284
+ theorem correlated_pair_second :
285
+ (∑ b : Bool, (if b then (3:ℝ)/4 else 1/4)*
286
+ ((if b then (2:ℝ) else 0)-3/2)^2) = 3/4 := by
287
+ norm_num [Fintype.sum_bool]
288
+
289
+ theorem correlated_pair_not_independent_variance :
290
+ (∑ b : Bool, (if b then (3:ℝ)/4 else 1/4)*
291
+ ((if b then (2:ℝ) else 0)-3/2)^2) ≠ 2*((3:ℝ)/4)*(1-3/4) := by
292
+ rw [correlated_pair_second]
293
+ norm_num
294
+
295
+ end Obligations046.Moments
@@ -0,0 +1,359 @@
1
+ import M0Bridge
2
+
3
+ open scoped BigOperators
4
+ open MeasureTheory ProbabilityTheory
5
+ noncomputable section
6
+ open Classical
7
+ namespace Obligations046.M1Bridge
8
+ open Obligations046.Bridge
9
+
10
+ /-- Four EXCLUSIVE outcomes of the sequential ancestor-first generator.
11
+ Fresh success/failure are distinct elementary outcomes, not a count-law premise. -/
12
+ def branchMass (p c1 c2 : ℝ) (e : Fin 4) : ℝ :=
13
+ if e = 0 then c1 else if e = 1 then (1-c1)*c2
14
+ else if e = 2 then (1-c1)*(1-c2)*p else (1-c1)*(1-c2)*(1-p)
15
+ def branchBit (A B : Bool) (e : Fin 4) : Bool :=
16
+ if e = 0 then A else if e = 1 then B else decide (e = 2)
17
+ def success (p c1 c2 : ℝ) (A B : Bool) : ℝ :=
18
+ c1*(if A then 1 else 0)+(1-c1)*c2*(if B then 1 else 0)+(1-c1)*(1-c2)*p
19
+
20
+ theorem branch_normalized (p c1 c2 : ℝ) : ∑ e : Fin 4, branchMass p c1 c2 e = 1 := by
21
+ simp [Fin.sum_univ_succ, branchMass]
22
+ ring
23
+
24
+ theorem branch_nonneg (p c1 c2 : ℝ) (hp : 0 ≤ p) (hp1 : p ≤ 1)
25
+ (hc1 : 0 ≤ c1) (hc1' : c1 ≤ 1) (hc2 : 0 ≤ c2) (hc2' : c2 ≤ 1)
26
+ (e : Fin 4) : 0 ≤ branchMass p c1 c2 e := by
27
+ have h1 : 0 ≤ 1-c1 := sub_nonneg.mpr hc1'
28
+ have h2 : 0 ≤ 1-c2 := sub_nonneg.mpr hc2'
29
+ have h3 : 0 ≤ 1-p := sub_nonneg.mpr hp1
30
+ unfold branchMass
31
+ split_ifs <;> positivity
32
+
33
+ theorem branch_bit_fiber (p c1 c2 : ℝ) (A B z : Bool) :
34
+ (∑ e : Fin 4, if branchBit A B e = z then branchMass p c1 c2 e else 0) =
35
+ if z then success p c1 c2 A B else 1-success p c1 c2 A B := by
36
+ cases A <;> cases B <;> cases z <;>
37
+ simp [Fin.sum_univ_succ, branchBit, branchMass, success] <;> ring
38
+
39
+ /-- Bijection between raw named binary member outcomes and subsets, independent of probabilities. -/
40
+ def subsetBits (n : ℕ) : Finset (Fin n) ≃ (Fin n → Bool) where
41
+ toFun s j := decide (j ∈ s)
42
+ invFun z := Finset.univ.filter (fun j => z j)
43
+ left_inv s := by ext j; simp
44
+ right_inv z := by funext j; simp
45
+
46
+ def memberSubset {n : ℕ} (A B : Bool) (x : Fin n → Fin 4) : Finset (Fin n) :=
47
+ Finset.univ.filter (fun j => branchBit A B (x j))
48
+
49
+ theorem selector_to_member (p c1 c2 : ℝ) (A B : Bool) (n : ℕ)
50
+ (f : Finset (Fin n) → ℝ) :
51
+ (∑ x : Fin n → Fin 4, (∏ j, branchMass p c1 c2 (x j))*f (memberSubset A B x)) =
52
+ ∑ s : Finset (Fin n), mass (success p c1 c2 A B) s*f s := by
53
+ have h := product_pushforward (fun (_j : Fin n) e => branchMass p c1 c2 e)
54
+ (fun _ e => branchBit A B e) (fun z => f ((subsetBits n).symm z))
55
+ simp only [branch_bit_fiber] at h
56
+ change _ = _ at h
57
+ calc
58
+ _ = ∑ z : Fin n → Bool,
59
+ (∏ j, if z j then success p c1 c2 A B else 1-success p c1 c2 A B)*
60
+ f ((subsetBits n).symm z) := by simpa [memberSubset, subsetBits] using h
61
+ _ = ∑ s : Finset (Fin n), mass (success p c1 c2 A B) s*f s := by
62
+ rw [← (subsetBits n).sum_comp]
63
+ apply Finset.sum_congr rfl
64
+ intro s _
65
+ simp only [Equiv.symm_apply_apply]
66
+ rw [mass_eq_individual_product]
67
+ simp [subsetBits]
68
+
69
+ /-- Push forward literal independent selectors to every joint lineage COUNT event. -/
70
+ theorem selector_count_fiber (p c1 c2 : ℝ) (A B : Bool) (n : ℕ) (k : Fin (n+1)) :
71
+ (∑ x : Fin n → Fin 4,
72
+ if count (memberSubset A B x) = k then ∏ j, branchMass p c1 c2 (x j) else 0) =
73
+ binMass (success p c1 c2 A B) n k := by
74
+ have h := selector_to_member p c1 c2 A B n (fun s => if count s = k then 1 else 0)
75
+ simpa only [mul_ite, mul_one, mul_zero, count_fiber_mass] using h
76
+
77
+ /-- p and weights/quota domain are exactly the existing M0 domain; c is c1 here.
78
+ The additional conditional child rate and named parent map are new model parameters. -/
79
+ structure Model where
80
+ base : Obligations045.M0.Domain
81
+ ancestors : ℕ
82
+ parent : Fin base.K → Fin ancestors
83
+ c2 : ℝ
84
+ c2_nonneg : 0 ≤ c2
85
+ c2_lt_one : c2 < 1
86
+
87
+ abbrev sizes (M : Model) (N : ℕ) (i : Fin M.base.K) :=
88
+ Obligations045.M0.allocation M.base.w N i
89
+ abbrev Ancestors (M : Model) := Fin M.ancestors → Bool
90
+ abbrev Leaves (M : Model) := Fin M.base.K → Bool
91
+ abbrev Raw (M : Model) (N : ℕ) := ∀ i : Fin M.base.K, Fin (sizes M N i) → Fin 4
92
+
93
+ def q (M : Model) (A : Ancestors M) (B : Leaves M) (i : Fin M.base.K) : ℝ :=
94
+ success M.base.p M.base.c M.c2 (A (M.parent i)) (B i)
95
+ def rawMass (M : Model) (N : ℕ) (x : Raw M N) : ℝ :=
96
+ ∏ i, ∏ j, branchMass M.base.p M.base.c M.c2 (x i j)
97
+ def counts (M : Model) (N : ℕ) (A : Ancestors M) (B : Leaves M) (x : Raw M N) :=
98
+ fun i => count (memberSubset (A (M.parent i)) (B i) (x i))
99
+
100
+ theorem rawMass_normalized (M : Model) (N : ℕ) : ∑ x : Raw M N, rawMass M N x = 1 := by
101
+ calc
102
+ _ = ∏ i : Fin M.base.K, ∑ x : Fin (sizes M N i) → Fin 4,
103
+ ∏ j, branchMass M.base.p M.base.c M.c2 (x j) :=
104
+ (Fintype.prod_sum (fun i (x : Fin (sizes M N i) → Fin 4) =>
105
+ ∏ j, branchMass M.base.p M.base.c M.c2 (x j))).symm
106
+ _ = 1 := by
107
+ apply Finset.prod_eq_one
108
+ intro i _
109
+ rw [← Fintype.prod_sum (fun (_j : Fin (sizes M N i)) e => branchMass M.base.p M.base.c M.c2 e)]
110
+ simp only [branch_normalized, Finset.prod_const_one]
111
+
112
+ theorem rawMass_nonneg (M : Model) (N : ℕ) (x : Raw M N) : 0 ≤ rawMass M N x := by
113
+ apply Finset.prod_nonneg
114
+ intro i _
115
+ apply Finset.prod_nonneg
116
+ intro j _
117
+ exact branch_nonneg _ _ _ (by linarith [M.base.p_half]) M.base.p_lt_one.le
118
+ M.base.c_nonneg M.base.c_lt_one.le M.c2_nonneg M.c2_lt_one.le _
119
+
120
+ /-- Full finite expectation bridge: no binomial count premise, limit premise or CLT. -/
121
+ theorem generator_to_binomial (M : Model) (N : ℕ) (A : Ancestors M) (B : Leaves M)
122
+ (f : (∀ i : Fin M.base.K, Fin (sizes M N i+1)) → ℝ) :
123
+ (∑ x : Raw M N, rawMass M N x*f (counts M N A B x)) =
124
+ ∑ k : ∀ i : Fin M.base.K, Fin (sizes M N i+1),
125
+ (∏ i, binMass (q M A B i) (sizes M N i) (k i))*f k := by
126
+ have h := product_pushforward
127
+ (fun i (x : Fin (sizes M N i) → Fin 4) => ∏ j, branchMass M.base.p M.base.c M.c2 (x j))
128
+ (fun i x => count (memberSubset (A (M.parent i)) (B i) x)) f
129
+ simpa only [selector_count_fiber, q, rawMass, counts] using h
130
+
131
+ def rawError (M : Model) (N : ℕ) (A : Ancestors M) (B : Leaves M) : ℝ :=
132
+ ∑ x : Raw M N, rawMass M N x *
133
+ Obligations045.M0.fairLoss (∑ i, (counts M N A B x i : ℕ)) N
134
+
135
+ def binomialError (M : Model) (N : ℕ) (A : Ancestors M) (B : Leaves M) : ℝ :=
136
+ ∑ k : ∀ i : Fin M.base.K, Fin (sizes M N i+1),
137
+ (∏ i, binMass (q M A B i) (sizes M N i) (k i))*
138
+ Obligations045.M0.fairLoss (∑ i, (k i : ℕ)) N
139
+
140
+ theorem conditional_error_bridge (M : Model) (N : ℕ) (A : Ancestors M) (B : Leaves M) :
141
+ rawError M N A B = binomialError M N A B :=
142
+ by
143
+ simpa only [rawError, binomialError] using generator_to_binomial M N A B
144
+ (fun k => Obligations045.M0.fairLoss (∑ i, (k i : ℕ)) N)
145
+
146
+ /-- Primitive jointly independent ancestor-selector, child-selector and fresh-vote bits.
147
+ Unused primitive draws are retained in the world and summed out, not conditioned away. -/
148
+ abbrev Primitive := Bool × Bool × Bool
149
+ def bernMass (r : ℝ) (b : Bool) : ℝ := if b then r else 1-r
150
+ def primitiveMass (p c1 c2 : ℝ) (t : Primitive) : ℝ :=
151
+ bernMass c1 t.1 * bernMass c2 t.2.1 * bernMass p t.2.2
152
+ def primitiveBranch (t : Primitive) : Fin 4 :=
153
+ if t.1 then 0 else if t.2.1 then 1 else if t.2.2 then 2 else 3
154
+
155
+ theorem primitive_branch_fiber (p c1 c2 : ℝ) (e : Fin 4) :
156
+ (∑ t : Primitive, if primitiveBranch t = e then primitiveMass p c1 c2 t else 0) =
157
+ branchMass p c1 c2 e := by
158
+ fin_cases e <;>
159
+ simp [Fintype.sum_prod_type, Fintype.sum_bool, primitiveBranch, primitiveMass, bernMass, branchMass] <;> ring
160
+
161
+ theorem primitive_normalized (p c1 c2 : ℝ) : ∑ t : Primitive, primitiveMass p c1 c2 t = 1 := by
162
+ simp [Fintype.sum_prod_type, Fintype.sum_bool, primitiveMass, bernMass]
163
+ ring
164
+
165
+ theorem primitive_output_is_sequential (A B : Bool) (t : Primitive) :
166
+ branchBit A B (primitiveBranch t) =
167
+ if t.1 then A else if t.2.1 then B else t.2.2 := by
168
+ rcases t with ⟨u,v,f⟩
169
+ cases u <;> cases v <;> cases f <;> rfl
170
+
171
+ theorem primitive_member_pushforward (p c1 c2 : ℝ) (n : ℕ)
172
+ (f : (Fin n → Fin 4) → ℝ) :
173
+ (∑ t : Fin n → Primitive, (∏ j, primitiveMass p c1 c2 (t j))*
174
+ f (fun j => primitiveBranch (t j))) =
175
+ ∑ x : Fin n → Fin 4, (∏ j, branchMass p c1 c2 (x j))*f x := by
176
+ simpa only [primitive_branch_fiber] using product_pushforward
177
+ (fun (_j : Fin n) t => primitiveMass p c1 c2 t) (fun _ => primitiveBranch) f
178
+
179
+ theorem primitive_count_fiber (p c1 c2 : ℝ) (A B : Bool) (n : ℕ) (k : Fin (n+1)) :
180
+ (∑ t : Fin n → Primitive,
181
+ if count (memberSubset A B (fun j => primitiveBranch (t j))) = k
182
+ then ∏ j, primitiveMass p c1 c2 (t j) else 0) =
183
+ binMass (success p c1 c2 A B) n k := by
184
+ have h := primitive_member_pushforward p c1 c2 n
185
+ (fun x => if count (memberSubset A B x) = k then 1 else 0)
186
+ simpa only [mul_ite, mul_one, mul_zero, selector_count_fiber] using h
187
+
188
+ abbrev PrimitiveWorld (M : Model) (N : ℕ) :=
189
+ ∀ i : Fin M.base.K, Fin (sizes M N i) → Primitive
190
+ def primitiveJointMass (M : Model) (N : ℕ) (x : PrimitiveWorld M N) : ℝ :=
191
+ ∏ i, ∏ j, primitiveMass M.base.p M.base.c M.c2 (x i j)
192
+ def primitiveCounts (M : Model) (N : ℕ) (A : Ancestors M) (B : Leaves M)
193
+ (x : PrimitiveWorld M N) :=
194
+ fun i => count (memberSubset (A (M.parent i)) (B i) (fun j => primitiveBranch (x i j)))
195
+
196
+ /-- The main bridge begins with the THREE INDEPENDENT PRIMITIVE BITS per named member,
197
+ not assumed Bernoulli output bits or an assumed binomial count distribution. -/
198
+ theorem primitive_generator_to_binomial (M : Model) (N : ℕ) (A : Ancestors M) (B : Leaves M)
199
+ (f : (∀ i : Fin M.base.K, Fin (sizes M N i+1)) → ℝ) :
200
+ (∑ x : PrimitiveWorld M N, primitiveJointMass M N x*f (primitiveCounts M N A B x)) =
201
+ ∑ k : ∀ i : Fin M.base.K, Fin (sizes M N i+1),
202
+ (∏ i, binMass (q M A B i) (sizes M N i) (k i))*f k := by
203
+ have h := product_pushforward
204
+ (fun i (x : Fin (sizes M N i) → Primitive) => ∏ j, primitiveMass M.base.p M.base.c M.c2 (x j))
205
+ (fun i x => count (memberSubset (A (M.parent i)) (B i) (fun j => primitiveBranch (x j)))) f
206
+ simpa only [primitive_count_fiber, primitiveJointMass, primitiveCounts, q] using h
207
+
208
+ theorem bern_nonneg (r : ℝ) (hr : 0 ≤ r) (hr1 : r ≤ 1) (b : Bool) :
209
+ 0 ≤ bernMass r b := by
210
+ cases b <;> simp only [bernMass, Bool.false_eq_true, ite_false, ite_true]
211
+ · exact sub_nonneg.mpr hr1
212
+ · exact hr
213
+
214
+ theorem primitive_joint_nonneg (M : Model) (N : ℕ) (x : PrimitiveWorld M N) :
215
+ 0 ≤ primitiveJointMass M N x := by
216
+ apply Finset.prod_nonneg
217
+ intro i _
218
+ apply Finset.prod_nonneg
219
+ intro j _
220
+ exact mul_nonneg
221
+ (mul_nonneg (bern_nonneg _ M.base.c_nonneg M.base.c_lt_one.le _)
222
+ (bern_nonneg _ M.c2_nonneg M.c2_lt_one.le _))
223
+ (bern_nonneg _ (by linarith [M.base.p_half]) M.base.p_lt_one.le _)
224
+
225
+ theorem primitive_joint_normalized (M : Model) (N : ℕ) :
226
+ ∑ x : PrimitiveWorld M N, primitiveJointMass M N x = 1 := by
227
+ calc
228
+ _ = ∏ i : Fin M.base.K, ∑ x : Fin (sizes M N i) → Primitive,
229
+ ∏ j, primitiveMass M.base.p M.base.c M.c2 (x j) :=
230
+ (Fintype.prod_sum (fun i (x : Fin (sizes M N i) → Primitive) =>
231
+ ∏ j, primitiveMass M.base.p M.base.c M.c2 (x j))).symm
232
+ _ = 1 := by
233
+ apply Finset.prod_eq_one
234
+ intro i _
235
+ rw [← Fintype.prod_sum (fun (_j : Fin (sizes M N i)) t => primitiveMass M.base.p M.base.c M.c2 t)]
236
+ simp only [primitive_normalized, Finset.prod_const_one]
237
+
238
+ instance primitiveMeasurableSpace (M : Model) (N : ℕ) :
239
+ MeasurableSpace (PrimitiveWorld M N) := ⊤
240
+ instance primitiveDiscreteMeasurable (M : Model) (N : ℕ) :
241
+ DiscreteMeasurableSpace (PrimitiveWorld M N) := ⟨fun _ => trivial⟩
242
+
243
+ /-- Genuine finite PMF on independent primitive bits; no binomial premise. -/
244
+ def primitiveLaw (M : Model) (N : ℕ) : PMF (PrimitiveWorld M N) :=
245
+ PMF.ofFintype (fun x => ENNReal.ofReal (primitiveJointMass M N x)) (by
246
+ rw [← ENNReal.ofReal_sum_of_nonneg]
247
+ · simp [primitive_joint_normalized]
248
+ · intro x _
249
+ exact primitive_joint_nonneg M N x)
250
+
251
+ theorem primitive_law_count_expectation (M : Model) (N : ℕ)
252
+ (A : Ancestors M) (B : Leaves M)
253
+ (f : (∀ i : Fin M.base.K, Fin (sizes M N i+1)) → ℝ) :
254
+ (∫ x, f (primitiveCounts M N A B x) ∂(primitiveLaw M N).toMeasure) =
255
+ ∑ k : ∀ i : Fin M.base.K, Fin (sizes M N i+1),
256
+ (∏ i, binMass (q M A B i) (sizes M N i) (k i))*f k := by
257
+ rw [PMF.integral_eq_sum]
258
+ calc
259
+ _ = ∑ x : PrimitiveWorld M N,
260
+ primitiveJointMass M N x*f (primitiveCounts M N A B x) := by
261
+ apply Finset.sum_congr rfl
262
+ intro x _
263
+ simp only [primitiveLaw, PMF.ofFintype_apply, smul_eq_mul]
264
+ rw [ENNReal.toReal_ofReal (primitive_joint_nonneg M N x)]
265
+ _ = _ := primitive_generator_to_binomial M N A B f
266
+
267
+ theorem primitive_law_count_probability (M : Model) (N : ℕ)
268
+ (A : Ancestors M) (B : Leaves M) (k : ∀ i : Fin M.base.K, Fin (sizes M N i+1)) :
269
+ (∫ x, if primitiveCounts M N A B x = k then (1:ℝ) else 0
270
+ ∂(primitiveLaw M N).toMeasure) = ∏ i, binMass (q M A B i) (sizes M N i) (k i) := by
271
+ simpa using primitive_law_count_expectation M N A B (fun z => if z = k then (1:ℝ) else 0)
272
+
273
+ theorem primitive_law_error_bridge (M : Model) (N : ℕ) (A : Ancestors M) (B : Leaves M) :
274
+ (∫ x, Obligations045.M0.fairLoss (∑ i, (primitiveCounts M N A B x i : ℕ)) N
275
+ ∂(primitiveLaw M N).toMeasure) = binomialError M N A B :=
276
+ by
277
+ simpa only [binomialError] using primitive_law_count_expectation M N A B
278
+ (fun k => Obligations045.M0.fairLoss (∑ i, (k i : ℕ)) N)
279
+
280
+ def latentMass (M : Model) (A : Ancestors M) (B : Leaves M) : ℝ :=
281
+ (∏ g, bernMass M.base.p (A g))*(∏ i, bernMass M.base.p (B i))
282
+
283
+ theorem latent_normalized (M : Model) :
284
+ ∑ A : Ancestors M, ∑ B : Leaves M, latentMass M A B = 1 := by
285
+ have ha : (∑ A : Ancestors M, ∏ g, bernMass M.base.p (A g)) = 1 := by
286
+ rw [← Fintype.prod_sum]
287
+ simp [Fintype.sum_bool, bernMass]
288
+ have hb : (∑ B : Leaves M, ∏ i, bernMass M.base.p (B i)) = 1 := by
289
+ rw [← Fintype.prod_sum]
290
+ simp [Fintype.sum_bool, bernMass]
291
+ simp only [latentMass, ← Finset.mul_sum, hb, mul_one, ha]
292
+
293
+ theorem mixture_error_bridge (M : Model) (N : ℕ) :
294
+ (∑ A : Ancestors M, ∑ B : Leaves M, latentMass M A B *
295
+ ∫ x, Obligations045.M0.fairLoss (∑ i, (primitiveCounts M N A B x i : ℕ)) N
296
+ ∂(primitiveLaw M N).toMeasure) =
297
+ ∑ A : Ancestors M, ∑ B : Leaves M, latentMass M A B * binomialError M N A B := by
298
+ simp only [primitive_law_error_bridge]
299
+
300
+ /-- Pure algebraic reduction only; no new limit or uncertainty certificate. -/
301
+ theorem zero_ancestor_reduction (M : Model) (A : Ancestors M) (B : Leaves M)
302
+ (hc : M.base.c = 0) (i : Fin M.base.K) :
303
+ q M A B i = (1-M.c2)*M.base.p + if B i then M.c2 else 0 := by
304
+ cases h : B i <;> simp [q, success, hc, h, add_comm]
305
+
306
+ theorem latent_nonneg (M : Model) (A : Ancestors M) (B : Leaves M) :
307
+ 0 ≤ latentMass M A B := by
308
+ apply mul_nonneg <;> apply Finset.prod_nonneg <;> intro i _ <;>
309
+ exact bern_nonneg _ (by linarith [M.base.p_half]) M.base.p_lt_one.le _
310
+
311
+ abbrev FullWorld (M : Model) (N : ℕ) := (Ancestors M × Leaves M) × PrimitiveWorld M N
312
+ def fullMass (M : Model) (N : ℕ) (x : FullWorld M N) : ℝ :=
313
+ latentMass M x.1.1 x.1.2 * primitiveJointMass M N x.2
314
+
315
+ theorem fullMass_nonneg (M : Model) (N : ℕ) (x : FullWorld M N) : 0 ≤ fullMass M N x :=
316
+ mul_nonneg (latent_nonneg M _ _) (primitive_joint_nonneg M N _)
317
+
318
+ theorem fullMass_normalized (M : Model) (N : ℕ) : ∑ x : FullWorld M N, fullMass M N x = 1 := by
319
+ simp only [Fintype.sum_prod_type, fullMass, ← Finset.mul_sum,
320
+ primitive_joint_normalized, mul_one, latent_normalized]
321
+
322
+ instance fullMeasurableSpace (M : Model) (N : ℕ) : MeasurableSpace (FullWorld M N) := ⊤
323
+ instance fullDiscreteMeasurable (M : Model) (N : ℕ) :
324
+ DiscreteMeasurableSpace (FullWorld M N) := ⟨fun _ => trivial⟩
325
+
326
+ /-- The COMPLETE finite generative law includes jointly independent latent bits
327
+ and all independent selector/fresh primitive draws. -/
328
+ def fullLaw (M : Model) (N : ℕ) : PMF (FullWorld M N) :=
329
+ PMF.ofFintype (fun x => ENNReal.ofReal (fullMass M N x)) (by
330
+ rw [← ENNReal.ofReal_sum_of_nonneg]
331
+ · simp [fullMass_normalized]
332
+ · intro x _
333
+ exact fullMass_nonneg M N x)
334
+
335
+ def implementationError (M : Model) (N : ℕ) : ℝ :=
336
+ ∑ A : Ancestors M, ∑ B : Leaves M, latentMass M A B * binomialError M N A B
337
+
338
+ /-- Complete generator–implementation bridge for every finiteN. No count distribution,
339
+ error convergence, causal identification or oracle-free calibration is assumed. -/
340
+ theorem full_generator_error_bridge (M : Model) (N : ℕ) :
341
+ (∫ x, Obligations045.M0.fairLoss
342
+ (∑ i, (primitiveCounts M N x.1.1 x.1.2 x.2 i : ℕ)) N ∂(fullLaw M N).toMeasure) =
343
+ implementationError M N := by
344
+ rw [PMF.integral_eq_sum]
345
+ have hp (x : FullWorld M N) : ((fullLaw M N) x).toReal = fullMass M N x := by
346
+ simp only [fullLaw, PMF.ofFintype_apply]
347
+ exact ENNReal.toReal_ofReal (fullMass_nonneg M N x)
348
+ simp_rw [smul_eq_mul, hp]
349
+ simp only [Fintype.sum_prod_type, implementationError, fullMass, mul_assoc]
350
+ apply Finset.sum_congr rfl
351
+ intro A _
352
+ apply Finset.sum_congr rfl
353
+ intro B _
354
+ rw [← Finset.mul_sum]
355
+ congr 1
356
+ simpa only [binomialError] using primitive_generator_to_binomial M N A B
357
+ (fun k => Obligations045.M0.fairLoss (∑ i, (k i : ℕ)) N)
358
+
359
+ end Obligations046.M1Bridge