Download data/lean/OAI/Combinatorics/ContingencyTables/Dense/DenseGrid.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.67 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ContingencyTables/Dense/DenseGrid.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/ContingencyTables/Dense/DenseGrid.lean
-
curl -L -o DenseGrid.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ContingencyTables/Dense/DenseGrid.lean
8.67 kB
| import OAI.Combinatorics.ContingencyTables.Dense.DenseRegularity | |
| import OAI.Combinatorics.ContingencyTables.Dense.GridConductance | |
| namespace OAI | |
| /-! | |
| # Conductance geometry for the actual dense penalty | |
| The free table coordinates are reindexed by `Fin q`. The bin and cut-tube | |
| density comparisons below follow from the actual margins and integer | |
| widths. Thus the weighted cut theorem has no assumed penalty regularity | |
| or bin comparison when used for the dense completion sampler. | |
| -/ | |
| namespace ContingencyTables.GridBoundary | |
| open MeasureTheory | |
| open scoped BigOperators | |
| noncomputable section | |
| variable {I J : Type*} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] | |
| variable {q : β} | |
| def realCorner {K : β} (a : Grid (I := Fin q) K) : Fin q β β := | |
| fun j => (corner a j : β) | |
| def denseGridPenalty (R : Option I β β) (P : Option J β β) (d : β) | |
| (e : I Γ J β Fin q) (x : Fin q β β) : β := | |
| DenseAffine.densePenalty R P d (fun p => x (e p)) | |
| theorem denseGridPenalty_continuous (R : Option I β β) (P : Option J β β) | |
| (d : β) (e : I Γ J β Fin q) : Continuous (denseGridPenalty R P d e) := by | |
| exact (DenseAffine.densePenalty_continuous R P d).comp | |
| (continuous_pi fun p => continuous_apply (e p)) | |
| theorem denseGridPenalty_convex (R : Option I β β) (P : Option J β β) | |
| (d : β) (e : I Γ J β Fin q) : | |
| ConvexOn β Set.univ (denseGridPenalty R P d e) := by | |
| refine β¨convex_univ, ?_β© | |
| intro x _ y _ a b ha hb hab | |
| exact (DenseAffine.densePenalty_convex R P d Set.univ convex_univ).2 | |
| (Set.mem_univ _) (Set.mem_univ _) ha hb hab | |
| theorem denseGridPenalty_change (R : Option I β β) (P : Option J β β) | |
| (d : β) (hd : 14 β€ d) (hR : β i, d ^ 12 β€ R i) (hP : β j, d ^ 12 β€ P j) | |
| (hRmax : β i, R (some i) β€ R none) (hPmax : β j, P (some j) β€ P none) | |
| (hfree : Fintype.card (I Γ J) β€ d) (e : I Γ J β Fin q) | |
| (x y : Fin q β β) (r : β) (hr : 0 β€ r) (hxy : β j, |x j - y j| β€ r) : | |
| |(d : β) ^ 4 * denseGridPenalty R P d e x - | |
| (d : β) ^ 4 * denseGridPenalty R P d e y| β€ r := | |
| DenseAffine.densePenalty_scaled_change R P d hd hR hP hRmax hPmax hfree | |
| _ _ r hr (fun p => hxy (e p)) | |
| private theorem closedBin_distance {K : β} (a : Grid (I := Fin q) K) | |
| (x : Fin q β β) (hx : ClosedBin (corner a) x) : | |
| β j, |x j - realCorner a j| β€ 1 := by | |
| intro j | |
| change |x j - (corner a j : β)| β€ 1 | |
| apply abs_le.mpr | |
| constructor <;> linarith [(hx j).1, (hx j).2] | |
| private theorem tube_distances {K : β} {Q : (Fin q β β€) β Prop} | |
| (edge : CutEdge K Q) (r : β) (_hr : 0 β€ r) (x : Fin q β β) | |
| (hx : x β edgeTube edge r) : | |
| (β j, |x j - realCorner edge.val.1 j| β€ 1 + r) β§ | |
| (β j, |x j - realCorner edge.val.2.1 j| β€ 1 + r) := by | |
| have hcoord (j : Fin q) := hx j (Set.mem_univ j) | |
| constructor | |
| Β· intro j | |
| have h := hcoord j | |
| dsimp [tubeLower, tubeUpper] at h | |
| change |x j - (corner edge.val.1 j : β)| β€ 1 + r | |
| by_cases hj : j = edge.val.2.2 | |
| Β· subst j | |
| simp only [ite_true] at h | |
| apply abs_le.mpr | |
| constructor <;> linarith [h.1, h.2] | |
| Β· simp only [ite_eq_right hj] at h | |
| apply abs_le.mpr | |
| constructor <;> linarith [h.1, h.2] | |
| Β· intro j | |
| have h := hcoord j | |
| dsimp [tubeLower, tubeUpper] at h | |
| change |x j - (corner edge.val.2.1 j : β)| β€ 1 + r | |
| by_cases hj : j = edge.val.2.2 | |
| Β· have hadj : (corner edge.val.2.1 j : β) = | |
| (corner edge.val.1 j : β) + 1 := by | |
| simpa only [hj, Int.cast_add, Int.cast_one] using | |
| congrArg (fun z : β€ => (z : β)) edge.property.1.1 | |
| simp only [ite_eq_left hj] at h | |
| rw [hadj] | |
| apply abs_le.mpr | |
| constructor <;> linarith [h.1, h.2] | |
| Β· have heq : corner edge.val.2.1 j = corner edge.val.1 j := | |
| congrArg Subtype.val (edge.property.1.2 j hj) | |
| simp only [ite_eq_right hj] at h | |
| rw [heq] | |
| apply abs_le.mpr | |
| constructor <;> linarith [h.1, h.2] | |
| theorem denseGrid_bin_comparison (R : Option I β β) (P : Option J β β) | |
| (d : β) (hd : 14 β€ d) (hR : β i, d ^ 12 β€ R i) (hP : β j, d ^ 12 β€ P j) | |
| (hRmax : β i, R (some i) β€ R none) (hPmax : β j, P (some j) β€ P none) | |
| (hfree : Fintype.card (I Γ J) β€ d) (e : I Γ J β Fin q) | |
| {K : β} (a : Grid (I := Fin q) K) (x : Fin q β β) | |
| (hx : ClosedBin (corner a) x) : | |
| DenseWeights.binWeight ((d : β) ^ 4) (denseGridPenalty R P d e) (realCorner a) / 4 β€ | |
| DenseWeights.density ((d : β) ^ 4) (denseGridPenalty R P d e) x β§ | |
| DenseWeights.density ((d : β) ^ 4) (denseGridPenalty R P d e) x β€ | |
| 2 * DenseWeights.binWeight ((d : β) ^ 4) (denseGridPenalty R P d e) (realCorner a) := | |
| DenseWeights.bin_density_comparison _ _ _ _ | |
| (denseGridPenalty_change R P d hd hR hP hRmax hPmax hfree e x _ 1 | |
| (by norm_num) (closedBin_distance a x hx)) | |
| theorem denseGrid_tube_comparison (R : Option I β β) (P : Option J β β) | |
| (d : β) (hd : 14 β€ d) (hR : β i, d ^ 12 β€ R i) (hP : β j, d ^ 12 β€ P j) | |
| (hRmax : β i, R (some i) β€ R none) (hPmax : β j, P (some j) β€ P none) | |
| (hfree : Fintype.card (I Γ J) β€ d) (e : I Γ J β Fin q) | |
| {K : β} {Q : (Fin q β β€) β Prop} (edge : CutEdge K Q) (r : β) | |
| (hr : 0 β€ r) (hrβ : r β€ 1) (x : Fin q β β) (hx : x β edgeTube edge r) : | |
| DenseWeights.density ((d : β) ^ 4) (denseGridPenalty R P d e) x β€ | |
| 4 * min | |
| (DenseWeights.binWeight ((d : β) ^ 4) (denseGridPenalty R P d e) (realCorner edge.val.1)) | |
| (DenseWeights.binWeight ((d : β) ^ 4) (denseGridPenalty R P d e) (realCorner edge.val.2.1)) := by | |
| obtain β¨hlo, hhiβ© := tube_distances edge r hr x hx | |
| rw [mul_min_of_nonneg _ _ (by norm_num : (0 : β) β€ 4)] | |
| apply le_min | |
| Β· apply DenseWeights.tube_density_comparison | |
| exact (denseGridPenalty_change R P d hd hR hP hRmax hPmax hfree e x _ (1 + r) | |
| (by positivity) hlo).trans (by linarith) | |
| Β· apply DenseWeights.tube_density_comparison | |
| exact (denseGridPenalty_change R P d hd hR hP hRmax hPmax hfree e x _ (1 + r) | |
| (by positivity) hhi).trans (by linarith) | |
| /-- Actual dyadic dense weights satisfy the interpolation cut bound, | |
| conditionally only on the published finite-box integral inequality. -/ | |
| theorem denseGrid_weighted_cut (R : Option I β β) (P : Option J β β) | |
| (d : β) (hd : 14 β€ d) (hR : β i, d ^ 12 β€ R i) (hP : β j, d ^ 12 β€ P j) | |
| (hRmax : β i, R (some i) β€ R none) (hPmax : β j, P (some j) β€ P none) | |
| (hfree : Fintype.card (I Γ J) β€ d) (e : I Γ J β Fin q) | |
| (hPL : PublishedInputs.FiniteBoxPrekopaLeindler q) | |
| {K : β} (Q : (Fin q β β€) β Prop) (t : β) (ht : 0 < t) (htβ : t < 1) | |
| (hr : t * K β€ 1 / 4) (hsize : (q - 1 : β) * (2 * (t * K)) β€ (1 / 2 : β)) | |
| (hSmass : 0 < β« x in selectedBins K Q, | |
| DenseWeights.density ((d : β) ^ 4) (denseGridPenalty R P d e) x) | |
| (hcut : 2 * (β« x in selectedBins K Q, | |
| DenseWeights.density ((d : β) ^ 4) (denseGridPenalty R P d e) x) β€ | |
| β« x in {x | Cube K x}, | |
| DenseWeights.density ((d : β) ^ 4) (denseGridPenalty R P d e) x) : | |
| (((2 : β) ^ t - 1) / 16) * | |
| (β a : Selected K Q, DenseWeights.binWeight ((d : β) ^ 4) | |
| (denseGridPenalty R P d e) (realCorner a.val)) β€ | |
| β edge : CutEdge K Q, min | |
| (DenseWeights.binWeight ((d : β) ^ 4) (denseGridPenalty R P d e) (realCorner edge.val.1)) | |
| (DenseWeights.binWeight ((d : β) ^ 4) (denseGridPenalty R P d e) (realCorner edge.val.2.1)) := by | |
| apply weighted_cut_of_interpolation hPL Q t ht htβ hr hsize | |
| (DenseWeights.density ((d : β) ^ 4) (denseGridPenalty R P d e)) | |
| (fun a => DenseWeights.binWeight ((d : β) ^ 4) (denseGridPenalty R P d e) (realCorner a)) | |
| Β· intro a | |
| exact (DenseWeights.binWeight_pos _ _ _).le | |
| Β· exact (DenseWeights.density_continuous _ _ (denseGridPenalty_continuous R P d e)).continuousOn | |
| Β· intro x _ | |
| exact DenseWeights.density_pos _ _ _ | |
| Β· intro x _ y _ s hs hsβ | |
| exact DenseWeights.density_logConcave _ (by positivity) _ Set.univ | |
| (denseGridPenalty_convex R P d e) x (Set.mem_univ _) y (Set.mem_univ _) s hs hsβ | |
| Β· intro a x hx | |
| exact (denseGrid_bin_comparison R P d hd hR hP hRmax hPmax hfree e a x | |
| (fun j => β¨(hx j).1.le, (hx j).2.leβ©)).1 | |
| Β· intro edge x hx | |
| exact denseGrid_tube_comparison R P d hd hR hP hRmax hPmax hfree e edge (t * K) | |
| (mul_nonneg ht.le (Nat.cast_nonneg _)) (by linarith) x hx.1 | |
| Β· exact hSmass | |
| Β· exact hcut | |
| end | |
| end ContingencyTables.GridBoundary | |
| end OAI | |