@lapxo/obligations 0.4.5 → 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.
- package/README.md +42 -3
- package/TARGET.bound +148 -42
- package/contracts/extension-lineage-participation.json +30 -0
- package/contracts/m0-binomial-bridge.json +6 -0
- package/contracts/m0-diagonal-conditional.json +15 -0
- package/contracts/m0-keff-interval.json +27 -0
- package/contracts/m0-moment-identification.json +42 -0
- package/contracts/m1-diagonal-regions.json +45 -0
- package/contracts/m1-generator-binomial.json +26 -0
- package/contracts/m1-offdiag-limit.json +42 -0
- package/contracts/m1-subcauses.json +66 -0
- package/contracts/model-collapse-1a.json +16 -0
- package/contracts/projection-chain.json +20 -0
- package/docs/contracts/experiment1a-public-attribution.md +1 -0
- package/docs/contracts/extension-lineage-participation.md +13 -0
- package/docs/contracts/installation-046-inputs.md +1 -0
- package/docs/contracts/m0-binomial-bridge.md +1 -0
- package/docs/contracts/m0-diagonal-lindeberg.md +1 -0
- package/docs/contracts/m0-diagonal-moments.md +1 -0
- package/docs/contracts/m0-diagonal-symmetric.md +1 -0
- package/docs/contracts/m0-diagonal-threshold.md +1 -0
- package/docs/contracts/m0-keff-floor-refutation.md +1 -0
- package/docs/contracts/m0-keff-interval.md +1 -0
- package/docs/contracts/m0-moment-identification.md +1 -0
- package/docs/contracts/m0-refuted-inverses.md +1 -0
- package/docs/contracts/m0-wf-floor-refutation.md +1 -0
- package/docs/contracts/m1-diagonal-regions.md +1 -0
- package/docs/contracts/m1-generator-binomial.md +1 -0
- package/docs/contracts/m1-offdiag-limit.md +1 -0
- package/docs/contracts/model-collapse-1a.md +11 -0
- package/docs/contracts/projection-chain.md +1 -0
- package/package.json +1 -1
- package/proofs/definitions-046/declaration.json +11 -0
- package/proofs/experiment1a-046/declaration.json +11 -0
- package/proofs/m0-046/BridgeNegatives.lean +23 -0
- package/proofs/m0-046/M0Bridge.lean +300 -0
- package/proofs/m0-046/Obligations045/ConsensusGrid.lean +72 -0
- package/proofs/m0-046/Obligations045/M0Coincidence.lean +39 -0
- package/proofs/m0-046/Obligations045/M0Diagonal.lean +18 -0
- package/proofs/m0-046/Obligations045/M0Limit.lean +134 -0
- package/proofs/m0-046/Obligations045/M0Offdiag.lean +171 -0
- package/proofs/m0-046/Obligations045.lean +5 -0
- package/proofs/m0-046/lake-manifest.json +116 -0
- package/proofs/m0-046/lakefile.toml +14 -0
- package/proofs/m0-046/lean-toolchain +1 -0
- package/proofs/m0-046-diagonal/BridgeNegatives.lean +23 -0
- package/proofs/m0-046-diagonal/M0Bridge.lean +300 -0
- package/proofs/m0-046-diagonal/M0Diagonal046.lean +235 -0
- package/proofs/m0-046-diagonal/M0Lindeberg046.lean +92 -0
- package/proofs/m0-046-diagonal/M0Moments046.lean +295 -0
- package/proofs/m0-046-diagonal/M0Threshold046.lean +278 -0
- package/proofs/m0-046-diagonal/Obligations045/ConsensusGrid.lean +72 -0
- package/proofs/m0-046-diagonal/Obligations045/M0Coincidence.lean +39 -0
- package/proofs/m0-046-diagonal/Obligations045/M0Diagonal.lean +18 -0
- package/proofs/m0-046-diagonal/Obligations045/M0Limit.lean +134 -0
- package/proofs/m0-046-diagonal/Obligations045/M0Offdiag.lean +171 -0
- package/proofs/m0-046-diagonal/Obligations045.lean +5 -0
- package/proofs/m0-046-diagonal/lake-manifest.json +116 -0
- package/proofs/m0-046-diagonal/lakefile.toml +26 -0
- package/proofs/m0-046-diagonal/lean-toolchain +1 -0
- package/proofs/m0-046-identification/M0Identification046.lean +209 -0
- package/proofs/m0-046-identification/Obligations045/M0Coincidence.lean +39 -0
- package/proofs/m0-046-identification/lake-manifest.json +116 -0
- package/proofs/m0-046-identification/lakefile.toml +12 -0
- package/proofs/m0-046-identification/lean-toolchain +1 -0
- package/proofs/m0-046-uncertainty/BridgeNegatives.lean +23 -0
- package/proofs/m0-046-uncertainty/M0BlockCoverage046.lean +163 -0
- package/proofs/m0-046-uncertainty/M0Bridge.lean +300 -0
- package/proofs/m0-046-uncertainty/M0Diagonal046.lean +235 -0
- package/proofs/m0-046-uncertainty/M0FiniteDiscord046.lean +207 -0
- package/proofs/m0-046-uncertainty/M0Interval046.lean +82 -0
- package/proofs/m0-046-uncertainty/M0Lindeberg046.lean +92 -0
- package/proofs/m0-046-uncertainty/M0Moments046.lean +295 -0
- package/proofs/m0-046-uncertainty/M0Threshold046.lean +278 -0
- package/proofs/m0-046-uncertainty/Obligations045/ConsensusGrid.lean +72 -0
- package/proofs/m0-046-uncertainty/Obligations045/M0Coincidence.lean +39 -0
- package/proofs/m0-046-uncertainty/Obligations045/M0Diagonal.lean +18 -0
- package/proofs/m0-046-uncertainty/Obligations045/M0Limit.lean +134 -0
- package/proofs/m0-046-uncertainty/Obligations045/M0Offdiag.lean +171 -0
- package/proofs/m0-046-uncertainty/Obligations045.lean +5 -0
- package/proofs/m0-046-uncertainty/lake-manifest.json +116 -0
- package/proofs/m0-046-uncertainty/lakefile.toml +35 -0
- package/proofs/m0-046-uncertainty/lean-toolchain +1 -0
- package/proofs/m1-046-bridge/M0Bridge.lean +300 -0
- package/proofs/m1-046-bridge/M1Bridge046.lean +359 -0
- package/proofs/m1-046-bridge/Obligations045/M0Limit.lean +134 -0
- package/proofs/m1-046-bridge/Obligations045/M0Offdiag.lean +171 -0
- package/proofs/m1-046-bridge/lake-manifest.json +116 -0
- package/proofs/m1-046-bridge/lakefile.toml +29 -0
- package/proofs/m1-046-bridge/lean-toolchain +1 -0
- package/proofs/m1-046-diagonal/M0Bridge.lean +300 -0
- package/proofs/m1-046-diagonal/M0Diagonal046.lean +235 -0
- package/proofs/m1-046-diagonal/M0Lindeberg046.lean +92 -0
- package/proofs/m1-046-diagonal/M0Moments046.lean +295 -0
- package/proofs/m1-046-diagonal/M0Threshold046.lean +278 -0
- package/proofs/m1-046-diagonal/M1Bridge046.lean +359 -0
- package/proofs/m1-046-diagonal/M1Diagonal046.lean +334 -0
- package/proofs/m1-046-diagonal/M1Offdiag046.lean +270 -0
- package/proofs/m1-046-diagonal/Obligations045/M0Limit.lean +134 -0
- package/proofs/m1-046-diagonal/Obligations045/M0Offdiag.lean +171 -0
- package/proofs/m1-046-diagonal/lake-manifest.json +116 -0
- package/proofs/m1-046-diagonal/lakefile.toml +35 -0
- package/proofs/m1-046-diagonal/lean-toolchain +1 -0
- package/proofs/m1-046-offdiag/M0Bridge.lean +300 -0
- package/proofs/m1-046-offdiag/M0Diagonal046.lean +235 -0
- package/proofs/m1-046-offdiag/M0Moments046.lean +295 -0
- package/proofs/m1-046-offdiag/M1Bridge046.lean +359 -0
- package/proofs/m1-046-offdiag/M1Offdiag046.lean +270 -0
- package/proofs/m1-046-offdiag/Obligations045/M0Limit.lean +134 -0
- package/proofs/m1-046-offdiag/Obligations045/M0Offdiag.lean +171 -0
- package/proofs/m1-046-offdiag/lake-manifest.json +116 -0
- package/proofs/m1-046-offdiag/lakefile.toml +32 -0
- package/proofs/m1-046-offdiag/lean-toolchain +1 -0
- package/proofs/projection-chain.md +11 -0
- package/protocols/model-collapse-1a.json +108 -0
- package/receipts.bound +578 -210
- package/samples/laws/definitions/no/sample.json +26 -0
- package/samples/laws/definitions/yes/sample.json +12 -0
- package/samples/laws/experiment1a/no/sample.json +16 -0
- package/samples/laws/experiment1a/yes/sample.json +8 -0
- package/samples/laws/m0-binomial-bridge/no/pairwise-is-not-joint.json +59 -0
- package/samples/laws/m0-binomial-bridge/no/sample.json +13 -0
- package/samples/laws/m0-binomial-bridge/yes/sample.json +16 -0
- package/samples/laws/m0-binomial-bridge/yes/small-binomial-table.json +100 -0
- package/samples/laws/m0-diagonal-conditional/no/sample.json +5 -0
- package/samples/laws/m0-diagonal-conditional/yes/sample.json +7 -0
- package/samples/laws/m0-keff-interval/no/sample.json +215 -0
- package/samples/laws/m0-keff-interval/yes/api-rows.json +2002 -0
- package/samples/laws/m0-keff-interval/yes/sample.json +70 -0
- package/samples/laws/m0-moment-identification/no/sample.json +47 -0
- package/samples/laws/m0-moment-identification/yes/sample.json +97 -0
- package/samples/laws/m1-diagonal-regions/no/sample.json +44 -0
- package/samples/laws/m1-diagonal-regions/yes/sample.json +45 -0
- package/samples/laws/m1-generator-binomial/no/sample.json +21 -0
- package/samples/laws/m1-generator-binomial/yes/sample.json +290 -0
- package/samples/laws/m1-offdiag-limit/no/sample.json +17 -0
- package/samples/laws/m1-offdiag-limit/yes/sample.json +87 -0
- package/samples/laws/projection-chain/no/sample.json +26 -0
- package/samples/laws/projection-chain/yes/sample.json +25 -0
- package/samples/no/installed-artifact.json +2 -2
- package/samples/yes/installed-artifact.json +2 -2
- package/src/laws/laws.bound +146 -0
- package/vectors/laws/a7-t90.json +72 -0
- package/vectors/laws/a9-t99.json +110 -0
- package/vectors/laws/definitions.native-capture.json +326 -0
- package/vectors/laws/definitions.native.json +82 -0
- package/vectors/laws/experiment1a-protocol.native-capture.json +391 -0
- package/vectors/laws/experiment1a-protocol.native.json +64 -0
- package/vectors/laws/experiment1a-public-input.native-capture.json +224 -0
- package/vectors/laws/m0-binomial-bridge.lean.json +185 -0
- package/vectors/laws/m0-diagonal-lindeberg.lean.json +167 -0
- package/vectors/laws/m0-diagonal-moments.lean.json +185 -0
- package/vectors/laws/m0-diagonal-symmetric.lean.json +188 -0
- package/vectors/laws/m0-diagonal-threshold.lean.json +199 -0
- package/vectors/laws/m0-identification.lean.json +136 -0
- package/vectors/laws/m0-identification.native-capture.json +230 -0
- package/vectors/laws/m0-keff-interval.json +569 -0
- package/vectors/laws/m0-uncertainty-blocks.lean.json +201 -0
- package/vectors/laws/m0-uncertainty-finite-discord.lean.json +194 -0
- package/vectors/laws/m0-uncertainty-interval.lean.json +189 -0
- package/vectors/laws/m0-uncertainty.native-capture.json +651 -0
- package/vectors/laws/m1-diagonal-partial.lean.json +192 -0
- package/vectors/laws/m1-diagonal-partial.native-capture.json +275 -0
- package/vectors/laws/m1-generator-binomial.lean.json +162 -0
- package/vectors/laws/m1-generator-binomial.native-capture.json +245 -0
- package/vectors/laws/m1-offdiag-limit.lean.json +166 -0
- package/vectors/laws/m1-offdiag-limit.native-capture.json +260 -0
- package/vectors/laws/model-collapse-1a.json +12 -0
- package/vectors/laws/projection-chain.json +61 -0
- package/vectors/laws/projection-chain.native-capture.json +311 -0
- package/vectors/laws/projection-chain.native.json +56 -0
- package/vectors/measures/installed-artifact.cli.json +6 -6
- package/CHANGELOG.md +0 -10
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import M0Bridge
|
|
2
|
+
import Lean.Elab.Tactic.Omega
|
|
3
|
+
open scoped BigOperators
|
|
4
|
+
open Filter Topology
|
|
5
|
+
noncomputable section
|
|
6
|
+
open Classical Obligations045.M0
|
|
7
|
+
namespace Obligations046.Diagonal
|
|
8
|
+
|
|
9
|
+
/-- Deterministic mean and Bernoulli variance of the declared product law.
|
|
10
|
+
The probabilistic CLT is not an assumption of either definition. -/
|
|
11
|
+
def mean (M : Domain) (a : Fin M.K → Bool) (N : ℕ) : ℝ :=
|
|
12
|
+
∑ i : Fin M.K, (allocation M.w N i : ℝ) * q M (a i)
|
|
13
|
+
def variance (M : Domain) (a : Fin M.K → Bool) (N : ℕ) : ℝ :=
|
|
14
|
+
∑ i : Fin M.K, (allocation M.w N i : ℝ) * (q M (a i) * (1-q M (a i)))
|
|
15
|
+
def varianceRate (M : Domain) (a : Fin M.K → Bool) : ℝ :=
|
|
16
|
+
∑ i : Fin M.K, M.w i * (q M (a i) * (1-q M (a i)))
|
|
17
|
+
def varianceLower (M : Domain) : ℝ := (1-M.c)^2 * M.p * (1-M.p)
|
|
18
|
+
|
|
19
|
+
theorem weights_fin_sum (M : Domain) : ∑ i : Fin M.K, M.w i = 1 := by
|
|
20
|
+
simpa only [Fin.sum_univ_eq_sum_range] using M.weights_sum
|
|
21
|
+
|
|
22
|
+
theorem variance_lower_pos (M : Domain) : 0 < varianceLower M := by
|
|
23
|
+
have hp : 0 < M.p := by linarith [M.p_half]
|
|
24
|
+
unfold varianceLower
|
|
25
|
+
exact mul_pos (mul_pos (sq_pos_of_pos (by linarith [M.c_lt_one])) hp)
|
|
26
|
+
(by linarith [M.p_lt_one])
|
|
27
|
+
|
|
28
|
+
theorem bernoulli_variance_lower (M : Domain) (b : Bool) :
|
|
29
|
+
varianceLower M ≤ q M b * (1-q M b) := by
|
|
30
|
+
have hc : 0 ≤ 1-M.c := by linarith [M.c_lt_one]
|
|
31
|
+
have hp : 0 ≤ M.p := by linarith [M.p_half]
|
|
32
|
+
have hprod : 0 ≤ (1-M.c)*M.p := mul_nonneg hc hp
|
|
33
|
+
have hprod' : 0 ≤ (1-M.c)*(1-M.p) := mul_nonneg hc (by linarith [M.p_lt_one])
|
|
34
|
+
cases b <;> simp only [q, Bool.false_eq_true, ite_false, add_zero, ite_true]
|
|
35
|
+
· unfold varianceLower
|
|
36
|
+
nlinarith [mul_nonneg hprod M.c_nonneg]
|
|
37
|
+
· unfold varianceLower
|
|
38
|
+
nlinarith [mul_nonneg hprod' M.c_nonneg]
|
|
39
|
+
|
|
40
|
+
theorem variance_rate_pos (M : Domain) (a : Fin M.K → Bool) :
|
|
41
|
+
0 < varianceRate M a := by
|
|
42
|
+
have h : varianceLower M ≤ varianceRate M a := by
|
|
43
|
+
calc
|
|
44
|
+
varianceLower M = ∑ i : Fin M.K, M.w i * varianceLower M := by
|
|
45
|
+
rw [← Finset.sum_mul, weights_fin_sum, one_mul]
|
|
46
|
+
_ ≤ varianceRate M a := Finset.sum_le_sum (fun i _ =>
|
|
47
|
+
mul_le_mul_of_nonneg_left (bernoulli_variance_lower M (a i)) (M.w_nonneg i))
|
|
48
|
+
exact lt_of_lt_of_le (variance_lower_pos M) h
|
|
49
|
+
|
|
50
|
+
theorem finite_variance_lower (M : Domain) (a : Fin M.K → Bool) (N : ℕ) :
|
|
51
|
+
(N:ℝ)*varianceLower M ≤ variance M a N := by
|
|
52
|
+
have hsum : ∑ i : Fin M.K, (allocation M.w N i : ℝ) = (N:ℝ) := by
|
|
53
|
+
exact_mod_cast (by simpa only [Fin.sum_univ_eq_sum_range] using allocation_sum M N)
|
|
54
|
+
calc
|
|
55
|
+
(N:ℝ)*varianceLower M = ∑ i : Fin M.K,
|
|
56
|
+
(allocation M.w N i : ℝ)*varianceLower M := by rw [← Finset.sum_mul, hsum]
|
|
57
|
+
_ ≤ variance M a N := Finset.sum_le_sum (fun i _ =>
|
|
58
|
+
mul_le_mul_of_nonneg_left (bernoulli_variance_lower M (a i)) (by positivity))
|
|
59
|
+
|
|
60
|
+
theorem mean_rounding_bound (M : Domain) (a : Fin M.K → Bool) (N : ℕ) :
|
|
61
|
+
|mean M a N - (N:ℝ)*score M a| ≤ (M.K:ℝ) := by
|
|
62
|
+
have heq : mean M a N - (N:ℝ)*score M a =
|
|
63
|
+
∑ i : Fin M.K, ((allocation M.w N i : ℝ)-(N:ℝ)*M.w i)*q M (a i) := by
|
|
64
|
+
simp only [mean, score, Finset.mul_sum, ← Finset.sum_sub_distrib]
|
|
65
|
+
apply Finset.sum_congr rfl
|
|
66
|
+
intro i _
|
|
67
|
+
ring
|
|
68
|
+
rw [heq]
|
|
69
|
+
calc
|
|
70
|
+
_ ≤ ∑ i : Fin M.K, |((allocation M.w N i : ℝ)-(N:ℝ)*M.w i)*q M (a i)| :=
|
|
71
|
+
Finset.abs_sum_le_sum_abs _ _
|
|
72
|
+
_ ≤ ∑ _i : Fin M.K, (1:ℝ) := by
|
|
73
|
+
apply Finset.sum_le_sum
|
|
74
|
+
intro i _
|
|
75
|
+
rw [abs_mul, abs_of_pos (q_pos M (a i))]
|
|
76
|
+
have hdis : |(allocation M.w N i : ℝ)-(N:ℝ)*M.w i| ≤ 1 :=
|
|
77
|
+
abs_le.mpr ⟨le_of_lt (allocation_discrepancy M N i).1,
|
|
78
|
+
le_of_lt (allocation_discrepancy M N i).2⟩
|
|
79
|
+
exact (mul_le_mul_of_nonneg_right hdis (le_of_lt (q_pos M (a i)))).trans
|
|
80
|
+
(by simpa using le_of_lt (q_lt_one M (a i)))
|
|
81
|
+
_ = (M.K:ℝ) := by simp
|
|
82
|
+
|
|
83
|
+
theorem diagonal_mean_bound (M : Domain) (a : Fin M.K → Bool)
|
|
84
|
+
(hdiag : score M a = (1:ℝ)/2) (N : ℕ) :
|
|
85
|
+
|mean M a N - (N:ℝ)/2| ≤ (M.K:ℝ) := by
|
|
86
|
+
simpa only [hdiag, mul_one_div] using mean_rounding_bound M a N
|
|
87
|
+
|
|
88
|
+
theorem variance_rate_limit (M : Domain) (a : Fin M.K → Bool) :
|
|
89
|
+
Tendsto (fun N : ℕ => variance M a N / (N:ℝ)) atTop (𝓝 (varianceRate M a)) := by
|
|
90
|
+
have h := tendsto_finset_sum Finset.univ (fun (i : Fin M.K) _ =>
|
|
91
|
+
(allocation_ratio M i).mul_const (q M (a i)*(1-q M (a i))))
|
|
92
|
+
convert h using 1
|
|
93
|
+
funext N
|
|
94
|
+
simp only [variance, Finset.sum_div, div_mul_eq_mul_div]
|
|
95
|
+
|
|
96
|
+
/-- Variance really diverges for this fixed domain, including zero-weight lineages. -/
|
|
97
|
+
theorem variance_atTop (M : Domain) (a : Fin M.K → Bool) :
|
|
98
|
+
Tendsto (variance M a) atTop atTop := by
|
|
99
|
+
apply tendsto_atTop_mono (fun N => finite_variance_lower M a N)
|
|
100
|
+
exact tendsto_natCast_atTop_atTop.atTop_mul_const (variance_lower_pos M)
|
|
101
|
+
|
|
102
|
+
/-- On the diagonal the bounded quota drift is negligible compared with variance.
|
|
103
|
+
This is a CLT prerequisite, not a CLT or a probability-tail certificate. -/
|
|
104
|
+
theorem diagonal_drift_squared_limit (M : Domain) (a : Fin M.K → Bool)
|
|
105
|
+
(hdiag : score M a = (1:ℝ)/2) :
|
|
106
|
+
Tendsto (fun N : ℕ => (mean M a N - (N:ℝ)/2)^2 / variance M a N)
|
|
107
|
+
atTop (𝓝 0) := by
|
|
108
|
+
have hupper : Tendsto (fun N : ℕ => (M.K:ℝ)^2 / variance M a N)
|
|
109
|
+
atTop (𝓝 0) := tendsto_const_nhds.div_atTop (variance_atTop M a)
|
|
110
|
+
apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hupper
|
|
111
|
+
· filter_upwards [(variance_atTop M a).eventually (eventually_ge_atTop 1)] with N hN
|
|
112
|
+
exact div_nonneg (sq_nonneg _) (by linarith)
|
|
113
|
+
· filter_upwards [(variance_atTop M a).eventually (eventually_ge_atTop 1)] with N hN
|
|
114
|
+
apply div_le_div_of_nonneg_right _ (by linarith)
|
|
115
|
+
have habs := diagonal_mean_bound M a hdiag N
|
|
116
|
+
nlinarith [sq_abs (mean M a N - (N:ℝ)/2), abs_nonneg (mean M a N - (N:ℝ)/2)]
|
|
117
|
+
|
|
118
|
+
open Obligations046.Bridge
|
|
119
|
+
|
|
120
|
+
def complement {ι : Type*} [Fintype ι] {n : ι → ℕ} (x : World n) : World n :=
|
|
121
|
+
fun i => (x i)ᶜ
|
|
122
|
+
|
|
123
|
+
theorem complement_involutive {ι : Type*} [Fintype ι] {n : ι → ℕ} (x : World n) :
|
|
124
|
+
complement (complement x) = x := by funext i; simp [complement]
|
|
125
|
+
|
|
126
|
+
theorem unbiased_mass_complement (n : ℕ) (x : Finset (Fin n)) :
|
|
127
|
+
mass (1/2 : ℝ) xᶜ = mass (1/2 : ℝ) x := by
|
|
128
|
+
have hx : x.card ≤ n := by simpa using x.card_le_univ
|
|
129
|
+
simp only [mass, Finset.card_compl, Fintype.card_fin]
|
|
130
|
+
norm_num
|
|
131
|
+
rw [Nat.sub_sub_self hx, mul_comm]
|
|
132
|
+
|
|
133
|
+
theorem unbiased_joint_complement {ι : Type*} [Fintype ι] (n : ι → ℕ)
|
|
134
|
+
(x : World n) :
|
|
135
|
+
jointMass n (fun _ => (1/2 : ℝ)) (complement x) =
|
|
136
|
+
jointMass n (fun _ => (1/2 : ℝ)) x := by
|
|
137
|
+
apply Finset.prod_congr rfl
|
|
138
|
+
intro i _
|
|
139
|
+
exact unbiased_mass_complement (n i) (x i)
|
|
140
|
+
|
|
141
|
+
theorem count_complement (M : Domain) (N : ℕ) (x : World (sizes M N)) :
|
|
142
|
+
correctCount (complement x) + correctCount x = N := by
|
|
143
|
+
have hsum : ∑ i : Fin M.K, sizes M N i = N := by
|
|
144
|
+
simpa only [Fin.sum_univ_eq_sum_range] using allocation_sum M N
|
|
145
|
+
unfold correctCount
|
|
146
|
+
rw [← Finset.sum_add_distrib]
|
|
147
|
+
convert hsum using 1
|
|
148
|
+
apply Finset.sum_congr rfl
|
|
149
|
+
intro i _
|
|
150
|
+
simp only [complement, Finset.card_compl, Fintype.card_fin]
|
|
151
|
+
exact Nat.sub_add_cancel (by simpa using (x i).card_le_univ)
|
|
152
|
+
|
|
153
|
+
theorem fair_loss_reflection (b d N : ℕ) (h : b+d=N) :
|
|
154
|
+
fairLoss b N + fairLoss d N = 1 := by
|
|
155
|
+
unfold fairLoss
|
|
156
|
+
split_ifs <;> norm_num <;> omega
|
|
157
|
+
|
|
158
|
+
/-- Genuine diagonal subdomain, exact for every N (even N=0).
|
|
159
|
+
It is not asserted for arbitrary diagonal scores with unequal q_i. -/
|
|
160
|
+
theorem unbiased_conditional_exact (M : Domain) (a : Fin M.K → Bool)
|
|
161
|
+
(hunbiased : ∀ i, q M (a i) = (1:ℝ)/2) (N : ℕ) :
|
|
162
|
+
conditionalError M N a = (1:ℝ)/2 := by
|
|
163
|
+
let f : World (sizes M N) → ℝ := fun x =>
|
|
164
|
+
jointMass (sizes M N) (fun _ => (1/2:ℝ)) x * fairLoss (correctCount x) N
|
|
165
|
+
have hrep : conditionalError M N a = ∑ x, f x := by
|
|
166
|
+
rw [← conditional_error_representation, modelLaw, memberLaw_expectation]
|
|
167
|
+
simp only [f, hunbiased]
|
|
168
|
+
have hsym : ∑ x, f (complement x) = ∑ x, f x :=
|
|
169
|
+
Fintype.sum_bijective complement
|
|
170
|
+
⟨fun x y h => by simpa only [complement_involutive] using congrArg complement h,
|
|
171
|
+
fun x => ⟨complement x, complement_involutive x⟩⟩ _ _ (fun _ => rfl)
|
|
172
|
+
have hpair : ∀ x, f (complement x) + f x =
|
|
173
|
+
jointMass (sizes M N) (fun _ => (1/2:ℝ)) x := by
|
|
174
|
+
intro x
|
|
175
|
+
simp only [f, unbiased_joint_complement, ← mul_add]
|
|
176
|
+
rw [fair_loss_reflection _ _ _ (count_complement M N x), mul_one]
|
|
177
|
+
have htotal : (∑ x, f (complement x)) + (∑ x, f x) = 1 := by
|
|
178
|
+
rw [← Finset.sum_add_distrib]
|
|
179
|
+
simp only [hpair]
|
|
180
|
+
exact jointMass_sum _ _
|
|
181
|
+
rw [hrep]
|
|
182
|
+
linarith
|
|
183
|
+
|
|
184
|
+
theorem floor_limit_diag_unbiased (M : Domain) (a : Fin M.K → Bool)
|
|
185
|
+
(hunbiased : ∀ i, q M (a i) = (1:ℝ)/2) :
|
|
186
|
+
Tendsto (fun N => conditionalError M N a) atTop (𝓝 ((1:ℝ)/2)) := by
|
|
187
|
+
simpa only [unbiased_conditional_exact M a hunbiased] using
|
|
188
|
+
(tendsto_const_nhds : Tendsto (fun _ : ℕ => (1:ℝ)/2) atTop (𝓝 ((1:ℝ)/2)))
|
|
189
|
+
|
|
190
|
+
/-- c=1 lies outside Domain: cumulative-floor quotas alone do not preserve ties.
|
|
191
|
+
With two equal-weight deterministic lineages (false,true), odd sizes favor true. -/
|
|
192
|
+
theorem deterministic_quota_even (m : ℕ) :
|
|
193
|
+
fairLoss ((2*m) - (2*m)/2) (2*m) = (1:ℝ)/2 := by
|
|
194
|
+
have h : (2*m)/2 = m := by omega
|
|
195
|
+
rw [h]
|
|
196
|
+
have hsub : 2*m-m = m := by omega
|
|
197
|
+
rw [hsub]
|
|
198
|
+
simp [fairLoss, Nat.not_lt.mpr (le_refl (2*m))]
|
|
199
|
+
|
|
200
|
+
theorem deterministic_quota_odd (m : ℕ) :
|
|
201
|
+
fairLoss ((2*m+1) - (2*m+1)/2) (2*m+1) = 0 := by
|
|
202
|
+
have h : (2*m+1)/2 = m := by omega
|
|
203
|
+
rw [h]
|
|
204
|
+
have hl : ¬ 2*(2*m+1-m) < 2*m+1 := by omega
|
|
205
|
+
have he : ¬ 2*(2*m+1-m) = 2*m+1 := by omega
|
|
206
|
+
simp only [fairLoss, if_neg hl, if_neg he]
|
|
207
|
+
|
|
208
|
+
/-- A legal heterogeneous diagonal; score=1/2 does not imply every q_i=1/2. -/
|
|
209
|
+
def heterogeneous : Domain where
|
|
210
|
+
K := 2
|
|
211
|
+
K_pos := by norm_num
|
|
212
|
+
p := 3/4
|
|
213
|
+
c := 1/2
|
|
214
|
+
p_half := by norm_num
|
|
215
|
+
p_lt_one := by norm_num
|
|
216
|
+
c_nonneg := by norm_num
|
|
217
|
+
c_lt_one := by norm_num
|
|
218
|
+
w := fun i => if i=0 then 3/4 else if i=1 then 1/4 else 0
|
|
219
|
+
w_nonneg := by intro i; split_ifs <;> norm_num
|
|
220
|
+
weights_sum := by norm_num [Finset.sum_range_succ]
|
|
221
|
+
|
|
222
|
+
def heterogeneousA : Fin 2 → Bool := fun i => i.val == 1
|
|
223
|
+
|
|
224
|
+
theorem heterogeneous_diagonal : score heterogeneous heterogeneousA = (1:ℝ)/2 := by
|
|
225
|
+
change (∑ i : Fin 2, (if (i:ℕ)=0 then (3:ℝ)/4 else if (i:ℕ)=1 then 1/4 else 0) *
|
|
226
|
+
((1-(1:ℝ)/2)*(3/4) + if (i:ℕ)==1 then (1:ℝ)/2 else 0)) = 1/2
|
|
227
|
+
norm_num [Fin.sum_univ_succ]
|
|
228
|
+
|
|
229
|
+
theorem heterogeneous_not_unbiased :
|
|
230
|
+
¬ (∀ i, q heterogeneous (heterogeneousA i) = (1:ℝ)/2) := by
|
|
231
|
+
intro h
|
|
232
|
+
have h0 := h ⟨0, by norm_num [heterogeneous]⟩
|
|
233
|
+
norm_num [q, heterogeneous, heterogeneousA] at h0
|
|
234
|
+
|
|
235
|
+
end Obligations046.Diagonal
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import M0Moments046
|
|
2
|
+
import Mathlib.Data.Real.Sqrt
|
|
3
|
+
open scoped BigOperators
|
|
4
|
+
open Filter Topology MeasureTheory
|
|
5
|
+
noncomputable section
|
|
6
|
+
open Classical Obligations045.M0 Obligations046.Bridge Obligations046.Diagonal
|
|
7
|
+
namespace Obligations046.Lindeberg
|
|
8
|
+
|
|
9
|
+
/-- The exact truncated centered second moment of one Bernoulli member.
|
|
10
|
+
Squared cutoff is ε² times the total variance; ε>0 is required below. -/
|
|
11
|
+
def bernoulliTail (q cutoff : ℝ) : ℝ :=
|
|
12
|
+
q*(if cutoff < (1-q)^2 then (1-q)^2 else 0) +
|
|
13
|
+
(1-q)*(if cutoff < q^2 then q^2 else 0)
|
|
14
|
+
|
|
15
|
+
def ratio (M : Domain) (a : Fin M.K → Bool) (N : ℕ) (ε : ℝ) : ℝ :=
|
|
16
|
+
(∑ i : Fin M.K, (allocation M.w N i:ℝ) *
|
|
17
|
+
bernoulliTail (q M (a i)) (ε^2 * Obligations046.Diagonal.variance M a N)) /
|
|
18
|
+
Obligations046.Diagonal.variance M a N
|
|
19
|
+
|
|
20
|
+
theorem centered_square_le_one (q : ℝ) (hq : 0 ≤ q) (hq1 : q ≤ 1) :
|
|
21
|
+
q^2 ≤ 1 ∧ (1-q)^2 ≤ 1 := by constructor <;> nlinarith
|
|
22
|
+
|
|
23
|
+
theorem bernoulli_tail_zero (q cutoff : ℝ) (hq : 0 ≤ q) (hq1 : q ≤ 1)
|
|
24
|
+
(hc : 1 ≤ cutoff) : bernoulliTail q cutoff = 0 := by
|
|
25
|
+
have h := centered_square_le_one q hq hq1
|
|
26
|
+
simp only [bernoulliTail, if_neg (not_lt.mpr (h.2.trans hc)),
|
|
27
|
+
if_neg (not_lt.mpr (h.1.trans hc)), mul_zero, add_zero]
|
|
28
|
+
|
|
29
|
+
theorem cutoff_eventually_large (M : Domain) (a : Fin M.K → Bool)
|
|
30
|
+
(ε : ℝ) (hε : 0 < ε) :
|
|
31
|
+
∀ᶠ N : ℕ in atTop, 1 ≤ ε^2*Obligations046.Diagonal.variance M a N := by
|
|
32
|
+
have hs : 0 < ε^2 := sq_pos_of_pos hε
|
|
33
|
+
have hv := (variance_atTop M a).eventually (eventually_ge_atTop (1/ε^2))
|
|
34
|
+
filter_upwards [hv] with N hN
|
|
35
|
+
simpa only [mul_comm] using (div_le_iff₀ hs).mp hN
|
|
36
|
+
|
|
37
|
+
theorem lindeberg_eventually_zero (M : Domain) (a : Fin M.K → Bool)
|
|
38
|
+
(ε : ℝ) (hε : 0 < ε) :
|
|
39
|
+
∀ᶠ N : ℕ in atTop, ratio M a N ε = 0 := by
|
|
40
|
+
filter_upwards [cutoff_eventually_large M a ε hε] with N hN
|
|
41
|
+
have hz : ∀ i : Fin M.K,
|
|
42
|
+
bernoulliTail (q M (a i)) (ε^2*Obligations046.Diagonal.variance M a N) = 0 :=
|
|
43
|
+
fun i => bernoulli_tail_zero _ _ (q_pos M (a i)).le (q_lt_one M (a i)).le hN
|
|
44
|
+
simp only [ratio, hz, mul_zero, Finset.sum_const_zero, zero_div]
|
|
45
|
+
|
|
46
|
+
theorem lindeberg_limit (M : Domain) (a : Fin M.K → Bool)
|
|
47
|
+
(ε : ℝ) (hε : 0 < ε) :
|
|
48
|
+
Tendsto (fun N => ratio M a N ε) atTop (𝓝 0) := by
|
|
49
|
+
have he : (fun N => ratio M a N ε) =ᶠ[atTop] (fun _ => 0) :=
|
|
50
|
+
lindeberg_eventually_zero M a ε hε
|
|
51
|
+
exact tendsto_const_nhds.congr' he.symm
|
|
52
|
+
|
|
53
|
+
/-- Explicit two-atom expectation, to prevent treating the cutoff expression as a certificate. -/
|
|
54
|
+
theorem bernoulli_tail_expectation (q cutoff : ℝ) :
|
|
55
|
+
(∑ b : Bool, (if b then q else 1-q) *
|
|
56
|
+
(if cutoff < ((if b then (1:ℝ) else 0)-q)^2
|
|
57
|
+
then ((if b then (1:ℝ) else 0)-q)^2 else 0)) = bernoulliTail q cutoff := by
|
|
58
|
+
simp only [Fintype.sum_bool, Bool.false_eq_true, ite_false, zero_sub, neg_sq, ite_true,
|
|
59
|
+
bernoulliTail]
|
|
60
|
+
|
|
61
|
+
theorem bernoulli_zero_cutoff (q : ℝ) (hq : 0 < q) (hq1 : q < 1) :
|
|
62
|
+
bernoulliTail q 0 = q*(1-q) := by
|
|
63
|
+
have h1 : 0 < (1-q)^2 := sq_pos_of_pos (by linarith)
|
|
64
|
+
have h0 : 0 < q^2 := sq_pos_of_pos hq
|
|
65
|
+
rw [bernoulliTail, if_pos h1, if_pos h0]
|
|
66
|
+
ring
|
|
67
|
+
|
|
68
|
+
/-- Negative boundary: ε=0 gives ratio 1 at every positive sample size, not 0. -/
|
|
69
|
+
theorem zero_epsilon_ratio (M : Domain) (a : Fin M.K → Bool) (N : ℕ) (hN : 0 < N) :
|
|
70
|
+
ratio M a N 0 = 1 := by
|
|
71
|
+
have hv : 0 < Obligations046.Diagonal.variance M a N :=
|
|
72
|
+
lt_of_lt_of_le (mul_pos (by exact_mod_cast hN) (variance_lower_pos M))
|
|
73
|
+
(finite_variance_lower M a N)
|
|
74
|
+
have hz : ∀ i : Fin M.K, bernoulliTail (q M (a i)) 0 = q M (a i)*(1-q M (a i)) :=
|
|
75
|
+
fun i => bernoulli_zero_cutoff _ (q_pos M (a i)) (q_lt_one M (a i))
|
|
76
|
+
simp only [ratio, zero_pow (by decide : (2:ℕ)≠0), zero_mul, hz]
|
|
77
|
+
change Obligations046.Diagonal.variance M a N / Obligations046.Diagonal.variance M a N = 1
|
|
78
|
+
exact div_self hv.ne'
|
|
79
|
+
|
|
80
|
+
/-- Centering at the majority threshold or at the actual probabilistic mean differs
|
|
81
|
+
by o(standard deviation), with the published quota rule and c<1. -/
|
|
82
|
+
theorem actual_mean_standardized_drift (M : Domain) (a : Fin M.K → Bool)
|
|
83
|
+
(hdiag : score M a = (1:ℝ)/2) :
|
|
84
|
+
Tendsto (fun N : ℕ =>
|
|
85
|
+
|(∫ x, (correctCount x:ℝ) ∂(modelLaw M N a).toMeasure) - (N:ℝ)/2| /
|
|
86
|
+
Real.sqrt (ProbabilityTheory.variance (fun x => (correctCount x:ℝ))
|
|
87
|
+
(modelLaw M N a).toMeasure)) atTop (𝓝 0) := by
|
|
88
|
+
simpa only [Obligations046.Moments.model_mean, Obligations046.Moments.model_variance,
|
|
89
|
+
Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, Real.sqrt_zero] using
|
|
90
|
+
(diagonal_drift_squared_limit M a hdiag).sqrt
|
|
91
|
+
|
|
92
|
+
end Obligations046.Lindeberg
|
|
@@ -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
|