Download data/lean/OAI/Probability/RadialTransition/BoxEnsembles.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/RadialTransition/BoxEnsembles.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/RadialTransition/BoxEnsembles.lean
-
curl -L -o BoxEnsembles.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/RadialTransition/BoxEnsembles.lean
10.2 kB
| import OAI.Probability.RadialTransition.DeletedInteractions | |
| namespace OAI | |
| noncomputable section | |
| open MeasureTheory Set Filter Function | |
| open scoped ContDiff NNReal BigOperators ENNReal | |
| namespace RadialTransition | |
| def halfCube (L : β) : Set Position := {x | β k, 0 β€ x k β§ x k < L} | |
| lemma measurableSet_halfCube (L : β) : MeasurableSet (halfCube L) := by | |
| have he : halfCube L = β k : Fin 3, {x : Position | 0 β€ x k β§ x k < L} := by | |
| ext x; simp only [halfCube, mem_ofPred_eq, mem_iInter] | |
| rw [he] | |
| apply MeasurableSet.iInter | |
| intro k | |
| exact (isClosed_le continuous_const (PiLp.continuous_apply 2 (fun _ : Fin 3 => β) k)).measurableSet.inter | |
| (isOpen_lt (PiLp.continuous_apply 2 (fun _ : Fin 3 => β) k) continuous_const).measurableSet | |
| lemma halfCube_ae_cube (L : β) : halfCube L =α΅[volume] cube L := by | |
| have hh := Measure.univ_pi_Ico_ae_eq_Icc (ΞΌ := fun _ : Fin 3 => (volume : Measure β)) | |
| (f := fun _ => (0:β)) (g := fun _ => L) | |
| have hp := (PiLp.volume_preserving_ofLp (Fin 3)).quasiMeasurePreserving.ae hh | |
| filter_upwards [hp] with x hx | |
| apply propext | |
| change (β k, 0 β€ x k β§ x k < L) β (β k, 0 β€ x k β§ x k β€ L) | |
| have hx' := eq_iff_iff.mp hx | |
| simpa only [Set.pi, Set.Ico, Set.Icc, Membership.mem, Set.Mem, Set.ofPred, Set.univ, Set.mem_univ, true_implies, forall_const, Pi.le_def, forall_and] using hx' | |
| lemma restrict_halfCube (L : β) : volume.restrict (halfCube L) = volume.restrict (cube L) := | |
| Measure.restrict_congr_set (halfCube_ae_cube L) | |
| abbrev GridIndex (q : β) := Fin 3 β Fin q | |
| def gridEmbed {q : β} (i : GridIndex q) : Cell := fun k => (i k : β€) | |
| lemma gridEmbed_injective (q : β) : Function.Injective (@gridEmbed q) := by | |
| intro i j h | |
| funext k | |
| apply Fin.ext | |
| have hh : (i k : β€) = (j k : β€) := congrFun h k | |
| exact_mod_cast hh | |
| lemma halfCube_grid_cover (q : β) (x : Position) (hx : x β halfCube ((q:β)/4)) : | |
| β i : GridIndex q, cellOf x = gridEmbed i := by | |
| have hh (k : Fin 3) : 0 β€ cellOf x k β§ cellOf x k < (q:β€) := by | |
| constructor | |
| Β· exact Int.floor_nonneg.mpr (by nlinarith [(hx k).1]) | |
| Β· apply Int.floor_lt.mpr | |
| exact_mod_cast (show 4*x k < (q:β) by linarith [(hx k).2]) | |
| let i : GridIndex q := fun k => β¨(cellOf x k).toNat, by have := hh k; omegaβ© | |
| refine β¨i, ?_β© | |
| funext k | |
| simp only [gridEmbed, i] | |
| exact (Int.toNat_of_nonneg (hh k).1).symm | |
| lemma gridEmbed_mem_halfCube_iff {q : β} (i : GridIndex q) (x : Position) | |
| (hx : cellOf x = gridEmbed i) : x β halfCube ((q:β)/4) := by | |
| intro k | |
| have hl := Int.floor_le (4*x k) | |
| have hu := Int.lt_floor_add_one (4*x k) | |
| have he : β4*x kβ = (i k : β€) := congrFun hx k | |
| rw [he] at hl hu | |
| have hi : (i k : β) + 1 β€ (q:β) := by exact_mod_cast (i k).isLt | |
| have hin : 0 β€ (i k : β) := by positivity | |
| constructor <;> push_cast at * <;> linarith | |
| lemma halfCube_eq_gridUnion (q : β) : | |
| halfCube ((q:β)/4) = β i : GridIndex q, gridRegion (gridEmbed i) := by | |
| ext x | |
| simp only [mem_iUnion, gridRegion, mem_ofPred_eq] | |
| exact β¨halfCube_grid_cover q x, fun β¨i,hiβ© => gridEmbed_mem_halfCube_iff i x hiβ© | |
| lemma volume_halfCube (L : β) : volume (halfCube L) = ENNReal.ofReal L ^ 3 := by | |
| rw [measure_congr (halfCube_ae_cube L), volume_cube] | |
| def macroOf (q : β) (k : Cell) : Cell := fun d => k d / (q:β€) | |
| def blockEmbed {m q : β} (i : GridIndex m) (j : GridIndex q) : GridIndex (m*q) := | |
| fun d => β¨(i d : β)*q+(j d : β), by | |
| calc | |
| _ < (i d : β)*q+q := Nat.add_lt_add_left (j d).isLt _ | |
| _ = ((i d : β)+1)*q := by ring | |
| _ β€ m*q := Nat.mul_le_mul_right q (Nat.succ_le_of_lt (i d).isLt)β© | |
| lemma blockEmbed_macro {m q : β} (hq : 0 < q) (i : GridIndex m) (j : GridIndex q) : | |
| macroOf q (gridEmbed (blockEmbed i j)) = gridEmbed i := by | |
| funext d | |
| simp only [macroOf, gridEmbed, blockEmbed] | |
| have hj := (j d).isLt | |
| have hq' : (0:β€) < q := by exact_mod_cast hq | |
| have hj' : (0:β€) β€ (j d : β) β§ (j d : β€) < q := by exact_mod_cast (show 0 β€ (j d:β) β§ (j d:β) < q from β¨Nat.zero_le _, hjβ©) | |
| push_cast | |
| rw [Int.add_ediv_of_dvd_left (dvd_mul_left _ _), | |
| Int.mul_ediv_cancel _ (ne_of_gt hq'), Int.ediv_eq_zero_of_lt hj'.1 hj'.2, add_zero] | |
| lemma blockEmbed_injective {m q : β} (hq : 0 < q) : | |
| Function.Injective (fun p : GridIndex m Γ GridIndex q => blockEmbed p.1 p.2) := by | |
| intro p r h | |
| have hi : p.1 = r.1 := gridEmbed_injective m (by | |
| have := congrArg (fun k => macroOf q (gridEmbed k)) h | |
| simpa only [blockEmbed_macro hq] using this) | |
| apply Prod.ext hi | |
| funext d | |
| apply Fin.ext | |
| have hh := congrArg (fun k : GridIndex (m*q) => (k d : β)) h | |
| simp only [blockEmbed, hi] at hh | |
| omega | |
| lemma blockEmbed_surjective {m q : β} (hq : 0 < q) : | |
| Function.Surjective (fun p : GridIndex m Γ GridIndex q => blockEmbed p.1 p.2) := by | |
| intro k | |
| let i : GridIndex m := fun d => β¨(k d : β)/q, Nat.div_lt_of_lt_mul (by simpa only [Nat.mul_comm m q] using (k d).isLt)β© | |
| let j : GridIndex q := fun d => β¨(k d : β)%q, Nat.mod_lt _ hqβ© | |
| refine β¨(i,j), ?_β© | |
| funext d | |
| apply Fin.ext | |
| simpa only [blockEmbed, i, j, Nat.mul_comm] using Nat.div_add_mod (k d : β) q | |
| def boundaryCoord (q D : β) : Finset (Fin q) := | |
| Finset.univ.filter (fun a => (a:β) < D β¨ q-D β€ (a:β)) | |
| lemma card_boundaryCoord (q D : β) : (boundaryCoord q D).card β€ 2*D := by | |
| let lo := Finset.univ.filter (fun a : Fin q => (a:β) < D) | |
| let hi := Finset.univ.filter (fun a : Fin q => q-D β€ (a:β)) | |
| have hlo : lo.card β€ D := by | |
| calc | |
| _ β€ (Finset.range D).card := Finset.card_le_card_of_injOn Fin.val | |
| (by intro a ha; exact Finset.mem_range.mpr (Finset.mem_filter.mp ha).2) | |
| (fun a _ b _ h => Fin.ext h) | |
| _ = D := Finset.card_range D | |
| have hhi : hi.card β€ D := by | |
| calc | |
| _ β€ (Finset.range D).card := Finset.card_le_card_of_injOn (fun a : Fin q => q-1-(a:β)) | |
| (by intro a ha; have hh := (Finset.mem_filter.mp ha).2; have := a.isLt; apply Finset.mem_range.mpr; change q-1-(a:β) < D; omega) | |
| (by intro a ha b hb h; apply Fin.ext; have := a.isLt; have := b.isLt; change q-1-(a:β) = q-1-(b:β) at h; omega) | |
| _ = D := Finset.card_range D | |
| have he : boundaryCoord q D = lo βͺ hi := by | |
| ext a; simp only [boundaryCoord, lo, hi, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_union] | |
| rw [he] | |
| exact le_trans (Finset.card_union_le lo hi) (by omega) | |
| def boundarySlice (q D : β) (d : Fin 3) : Finset (GridIndex q) := | |
| Fintype.piFinset (fun k => if k = d then boundaryCoord q D else Finset.univ) | |
| def boundaryGrid (q D : β) : Finset (GridIndex q) := | |
| Finset.univ.biUnion (boundarySlice q D) | |
| lemma mem_boundaryGrid {q D : β} {j : GridIndex q} : | |
| j β boundaryGrid q D β β d, (j d:β) < D β¨ q-D β€ (j d:β) := by | |
| simp only [boundaryGrid, Finset.mem_biUnion, Finset.mem_univ, true_and, | |
| boundarySlice, Fintype.mem_piFinset] | |
| constructor | |
| Β· rintro β¨d,hdβ© | |
| refine β¨d, ?_β© | |
| have h := hd d | |
| simpa only [ite_true, boundaryCoord, Finset.mem_filter, Finset.mem_univ, true_and] using h | |
| Β· rintro β¨d,hdβ© | |
| refine β¨d, ?_β© | |
| intro k | |
| split_ifs with h | |
| Β· subst k | |
| exact Finset.mem_filter.mpr β¨Finset.mem_univ _, hdβ© | |
| Β· exact Finset.mem_univ _ | |
| lemma card_boundaryGrid (q D : β) : (boundaryGrid q D).card β€ 6*D*q^2 := by | |
| have hs (d : Fin 3) : (boundarySlice q D d).card = (boundaryCoord q D).card*q^2 := by | |
| rw [boundarySlice, Fintype.card_piFinset] | |
| fin_cases d <;> simp [Fin.prod_univ_three] <;> ring | |
| calc | |
| _ β€ β d : Fin 3, (boundarySlice q D d).card := Finset.card_biUnion_le | |
| _ = 3*((boundaryCoord q D).card*q^2) := by simp only [hs, Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] | |
| _ β€ 3*(2*D*q^2) := Nat.mul_le_mul_left _ (Nat.mul_le_mul_right _ (card_boundaryCoord q D)) | |
| _ = _ := by ring | |
| lemma inner_block_macro {m q D : β} (hq : 0 < q) (i : GridIndex m) (j : GridIndex q) | |
| (hj : j β boundaryGrid q D) {k : Cell} | |
| (hk : β d, |k d-gridEmbed (blockEmbed i j) d| β€ (D:β€)) : | |
| macroOf q k = gridEmbed i := by | |
| have hj' : β d, D β€ (j d:β) β§ (j d:β)+D < q := by | |
| have hh := mt mem_boundaryGrid.mpr hj | |
| intro d | |
| have hn : Β¬ ((j d:β) < D β¨ q-D β€ (j d:β)) := fun h => hh β¨d,hβ© | |
| omega | |
| funext d | |
| apply (Int.ediv_eq_iff_of_pos (by exact_mod_cast hq)).mpr | |
| have hkd := abs_le.mp (hk d) | |
| have hlow : (D:β€) β€ (j d:β€) := by exact_mod_cast (hj' d).1 | |
| have hupp : (j d:β€)+(D:β€) < (q:β€) := by exact_mod_cast (hj' d).2 | |
| change -(D:β€) β€ k d-((i d:β)*q+(j d:β):β) β§ k d-((i d:β)*q+(j d:β):β) β€ (D:β€) at hkd | |
| push_cast at hkd | |
| change (i d:β€)*(q:β€) β€ k d β§ k d < (i d:β€)*(q:β€)+(q:β€) | |
| constructor <;> omega | |
| lemma sum_blockGrid {m q : β} (hq : 0 < q) (F : GridIndex (m*q) β β) : | |
| β k, F k = β i : GridIndex m, β j : GridIndex q, F (blockEmbed i j) := by | |
| have hh := Fintype.sum_equiv (Equiv.ofBijective _ β¨blockEmbed_injective (m := m) hq, blockEmbed_surjective hqβ©) | |
| (fun p => F (blockEmbed p.1 p.2)) F (fun _ => rfl) | |
| rw [Fintype.sum_prod_type] at hh | |
| exact hh.symm | |
| lemma grid_sum_boundary_bound {m q D : β} (hq : 0 < q) {C : β} (hC : 0 β€ C) | |
| (F : GridIndex (m*q) β β) | |
| (hF : β k, F k β€ C) | |
| (hzero : β i j, j β boundaryGrid q D β F (blockEmbed i j) = 0) : | |
| β k, F k β€ (m:β)^3*(6*D*q^2)*C := by | |
| rw [sum_blockGrid hq] | |
| have hsum (i : GridIndex m) : β j : GridIndex q, F (blockEmbed i j) β€ (6*D*q^2:β)*C := by | |
| calc | |
| _ = β j β boundaryGrid q D, F (blockEmbed i j) := | |
| (Finset.sum_subset (Finset.subset_univ _) (fun j _ hj => hzero i j hj)).symm | |
| _ β€ β _j β boundaryGrid q D, C := Finset.sum_le_sum (fun j _ => hF _) | |
| _ = ((boundaryGrid q D).card:β)*C := by simp | |
| _ β€ (6*D*q^2:β)*C := mul_le_mul_of_nonneg_right (by exact_mod_cast card_boundaryGrid q D) hC | |
| calc | |
| _ β€ β _i : GridIndex m, (6*D*q^2:β)*C := Finset.sum_le_sum (fun i _ => hsum i) | |
| _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_fin]; push_cast; ring | |
| end RadialTransition | |
| end | |
| end OAI | |