Download lean/OAI/Probability/ContinuumTransition/BoxTiling.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 10.7 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Probability/ContinuumTransition/BoxTiling.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Probability/ContinuumTransition/BoxTiling.lean
-
curl -L -o BoxTiling.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Probability/ContinuumTransition/BoxTiling.lean
10.7 kB
| import OAI.Probability.ContinuumTransition.SpatialProducts | |
| namespace OAI | |
| section | |
| open scoped Topology BigOperators ENNReal | |
| open Filter MeasureTheory Set | |
| namespace ContinuumTemperature | |
| noncomputable def tileCenter (ℓ L : ℝ) {k : ℕ} (i : Fin 3 → Fin k) : Space := | |
| WithLp.toLp 2 (fun j => (ℓ+2)*((i j : ℝ)+1/2)-L/2) | |
| noncomputable def tileBox (ℓ L : ℝ) {k : ℕ} (i : Fin 3 → Fin k) : Set Space := | |
| (fun x => x + tileCenter ℓ L i) '' cube ℓ | |
| theorem isCompact_tileBox (ℓ L : ℝ) {k : ℕ} (i : Fin 3 → Fin k) : | |
| IsCompact (tileBox ℓ L i) := | |
| (isCompact_cube ℓ).image (continuous_id.add continuous_const) | |
| theorem tileBox_subset {ℓ L : ℝ} {k : ℕ} (hℓ : 0 ≤ ℓ) | |
| (hk : (k : ℝ)*(ℓ+2) ≤ L) (i : Fin 3 → Fin k) : tileBox ℓ L i ⊆ cube L := by | |
| rintro x ⟨y, hy, rfl⟩ j | |
| have hyj := hy j | |
| have hij : (i j : ℝ)+1 ≤ k := by exact_mod_cast (i j).isLt | |
| have h0 : (0 : ℝ) ≤ (i j : ℝ) := Nat.cast_nonneg _ | |
| change y j + ((ℓ+2)*((i j : ℝ)+1/2)-L/2) ∈ Icc (-L/2) (L/2) | |
| constructor <;> nlinarith [hyj.1, hyj.2] | |
| theorem tileBox_separation {ℓ L : ℝ} {k : ℕ} (hℓ : 0 ≤ ℓ) | |
| {i j : Fin 3 → Fin k} (hij : i ≠ j) {x y : Space} | |
| (hx : x ∈ tileBox ℓ L i) (hy : y ∈ tileBox ℓ L j) : 2 ≤ ‖x-y‖ := by | |
| obtain ⟨a, ha, rfl⟩ := hx | |
| obtain ⟨b, hb, rfl⟩ := hy | |
| obtain ⟨r, hr⟩ : ∃ r, i r ≠ j r := by | |
| by_contra! h | |
| exact hij (funext h) | |
| have har := ha r | |
| have hbr := hb r | |
| have hnorm : |(a+tileCenter ℓ L i) r - (b+tileCenter ℓ L j) r| ≤ | |
| ‖(a+tileCenter ℓ L i)-(b+tileCenter ℓ L j)‖ := by | |
| simpa only [PiLp.sub_apply, Real.norm_eq_abs] using | |
| PiLp.norm_apply_le ((a+tileCenter ℓ L i)-(b+tileCenter ℓ L j)) r | |
| change |a r + ((ℓ+2)*((i r : ℝ)+1/2)-L/2) - | |
| (b r + ((ℓ+2)*((j r : ℝ)+1/2)-L/2))| ≤ | |
| ‖(a+tileCenter ℓ L i)-(b+tileCenter ℓ L j)‖ at hnorm | |
| rw [abs_le] at hnorm | |
| rcases lt_or_gt_of_ne hr with h | h | |
| · have hh : (i r : ℝ)+1 ≤ (j r : ℝ) := by exact_mod_cast h | |
| have hmul := mul_le_mul_of_nonneg_left hh (by linarith : 0 ≤ ℓ+2) | |
| nlinarith [har.1, har.2, hbr.1, hbr.2] | |
| · have hh : (j r : ℝ)+1 ≤ (i r : ℝ) := by exact_mod_cast h | |
| have hmul := mul_le_mul_of_nonneg_left hh (by linarith : 0 ≤ ℓ+2) | |
| nlinarith [har.1, har.2, hbr.1, hbr.2] | |
| theorem tileBox_pairwiseDisjoint {ℓ L : ℝ} {k : ℕ} (hℓ : 0 ≤ ℓ) : | |
| Pairwise (fun i j : Fin 3 → Fin k => Disjoint (tileBox ℓ L i) (tileBox ℓ L j)) := by | |
| intro i j hij | |
| apply Set.disjoint_left.mpr | |
| intro x hx hy | |
| have hh := tileBox_separation hℓ hij hx hy | |
| simp only [sub_self, norm_zero] at hh | |
| norm_num at hh | |
| theorem partition_tiling_lower {φ : ℝ → ℝ} (hφ : Measurable (radialPotential φ)) | |
| {β B ℓ L : ℝ} (hβ : 0 ≤ β) (hℓ : 0 ≤ ℓ) (hL : 0 ≤ L) | |
| (hstable : ∀ (N : ℕ) (x : Fin N → Space), | |
| ((-B * (N : ℝ) : ℝ) : EReal) ≤ energy φ x) | |
| (hsign : ∀ r, 1 ≤ r → φ r ≤ 0) | |
| (n : (Fin 3 → Fin ⌊L/(ℓ+2)⌋₊) → ℕ) : | |
| (∏ i, partition φ β ℓ (n i)) ≤ partition φ β L (∑ i, n i) := by | |
| classical | |
| have hden : 0 < ℓ+2 := by linarith | |
| have hk : (⌊L/(ℓ+2)⌋₊ : ℝ)*(ℓ+2) ≤ L := by | |
| apply (le_div_iff₀ hden).mp | |
| exact Nat.floor_le (div_nonneg hL hden.le) | |
| have hh := setPartition_product_lower hφ hβ hstable (tileBox ℓ L) n Finset.univ | |
| (fun i _ => (isCompact_tileBox ℓ L i).measurableSet) | |
| (fun i _ j _ hij => tileBox_pairwiseDisjoint hℓ hij) | |
| (fun i _ j _ hij a ha b hb => hsign _ (le_trans (by norm_num) | |
| (tileBox_separation hℓ hij ha hb))) | |
| (isCompact_cube L).measure_lt_top.ne (fun i _ => tileBox_subset hℓ hk i) | |
| have hv (i : Fin 3 → Fin ⌊L/(ℓ+2)⌋₊) : | |
| setPartition φ β (tileBox ℓ L i) (n i) = partition φ β ℓ (n i) := by | |
| rw [tileBox, setPartition_translate, setPartition, generalPartition_eq_partition] | |
| simp_rw [hv] at hh | |
| simpa only [setPartition, generalPartition_eq_partition] using hh | |
| theorem exists_concentrated_counts (K H N : ℕ) (hN : N ≤ K*H) : | |
| ∃ r : Fin K → ℕ, (∑ i, r i) = N ∧ (∀ i, r i ≤ H) ∧ | |
| (∑ i, if r i = 0 then 0 else 1) * H ≤ N+H := by | |
| induction K generalizing N with | |
| | zero => | |
| have hzero : N = 0 := by omega | |
| subst N | |
| exact ⟨Fin.elim0, by simp, (fun i => Fin.elim0 i), by simp⟩ | |
| | succ K ih => | |
| by_cases hh : N ≤ H | |
| · refine ⟨Fin.cons N (fun _ => 0), ?_, ?_, ?_⟩ | |
| · simp [Fin.sum_univ_succ] | |
| · intro i | |
| refine Fin.cases hh (fun _ => Nat.zero_le _) i | |
| · simp only [Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ, ite_true, Finset.sum_const_zero, | |
| add_zero] | |
| split_ifs <;> omega | |
| · have hHK : N-H ≤ K*H := by | |
| rw [Nat.succ_mul] at hN | |
| omega | |
| obtain ⟨r, hr, hbound, hc⟩ := ih (N-H) hHK | |
| have hH : 0 < H := by | |
| by_contra hzero | |
| have hz : H = 0 := by omega | |
| simp only [hz, Nat.mul_zero, Nat.le_zero] at hN | |
| omega | |
| refine ⟨Fin.cons H r, ?_, ?_, ?_⟩ | |
| · simp only [Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ, hr] | |
| omega | |
| · intro i | |
| exact Fin.cases (le_refl H) hbound i | |
| · simp only [Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ, ite_eq_right hH.ne'] | |
| have hsub := Nat.sub_add_cancel (show H ≤ N by omega) | |
| nlinarith | |
| theorem exists_adjusted_counts (K b H N : ℕ) (hb : 0 < b) (hH : 2*b ≤ H) | |
| (hN : N ≤ K*H) : | |
| ∃ r : Fin K → ℕ, (∑ i, r i) = N ∧ (∀ i, r i ≤ H) ∧ | |
| ((∑ i, if r i = b then 0 else 1 : ℕ) : ℝ) * b ≤ | |
| |(N : ℝ) - (K : ℝ)*b| + H := by | |
| have hbH : b ≤ H := by omega | |
| by_cases hNb : K*b ≤ N | |
| · have hdel : N-K*b ≤ K*(H-b) := by | |
| rw [Nat.mul_sub_left_distrib] | |
| omega | |
| obtain ⟨d, hsum, hbound, hc⟩ := exists_concentrated_counts K (H-b) (N-K*b) hdel | |
| refine ⟨fun i => b+d i, ?_, ?_, ?_⟩ | |
| · simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, | |
| Fintype.card_fin, smul_eq_mul, hsum] | |
| omega | |
| · intro i | |
| change b+d i ≤ H | |
| have hh := hbound i | |
| omega | |
| · have heq : (∑ i, if b+d i = b then 0 else 1 : ℕ) = | |
| ∑ i, if d i = 0 then 0 else 1 := by | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| simp only [Nat.add_eq_left] | |
| rw [heq] | |
| have hineq : (∑ i, if d i = 0 then 0 else 1) * b ≤ (N-K*b)+H := by | |
| have hh := Nat.mul_le_mul_left (∑ i, if d i = 0 then 0 else 1) (show b ≤ H-b by omega) | |
| omega | |
| have hsub : ((N-K*b : ℕ) : ℝ) = (N : ℝ)-(K : ℝ)*b := by | |
| rw [Nat.cast_sub hNb, Nat.cast_mul] | |
| have hsgn : 0 ≤ (N : ℝ)-(K : ℝ)*b := by | |
| have hh : (K : ℝ)*b ≤ (N : ℝ) := by exact_mod_cast hNb | |
| linarith | |
| rw [abs_of_nonneg hsgn] | |
| have hh : ((∑ i, if d i = 0 then 0 else 1 : ℕ) : ℝ)*b ≤ ((N-K*b : ℕ) : ℝ)+H := by | |
| exact_mod_cast hineq | |
| rwa [hsub] at hh | |
| · have hNb' : N ≤ K*b := by omega | |
| obtain ⟨d, hsum, hbound, hc⟩ := exists_concentrated_counts K b (K*b-N) (Nat.sub_le _ _) | |
| refine ⟨fun i => b-d i, ?_, ?_, ?_⟩ | |
| · have hh : (∑ i : Fin K, (b - d i)) + (∑ i : Fin K, d i) = K*b := by | |
| rw [← Finset.sum_add_distrib] | |
| simp only [Nat.sub_add_cancel (hbound _), Finset.sum_const, Finset.card_univ, | |
| Fintype.card_fin, smul_eq_mul] | |
| change (∑ i : Fin K, (b - d i)) = N | |
| rw [hsum] at hh | |
| omega | |
| · intro i | |
| exact (Nat.sub_le b _).trans hbH | |
| · have heq : (∑ i, if b-d i = b then 0 else 1 : ℕ) = | |
| ∑ i, if d i = 0 then 0 else 1 := by | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| have hh : b-d i = b ↔ d i = 0 := by omega | |
| simp only [hh] | |
| rw [heq] | |
| have hineq : (∑ i, if d i = 0 then 0 else 1) * b ≤ (K*b-N)+H := by omega | |
| have hsub : ((K*b-N : ℕ) : ℝ) = (K : ℝ)*b-N := by | |
| rw [Nat.cast_sub hNb', Nat.cast_mul] | |
| have hsgn : (N : ℝ)-(K : ℝ)*b ≤ 0 := by | |
| have hh : (N : ℝ) ≤ (K : ℝ)*b := by exact_mod_cast hNb' | |
| linarith | |
| rw [abs_of_nonpos hsgn] | |
| have hh : ((∑ i, if d i = 0 then 0 else 1 : ℕ) : ℝ)*b ≤ ((K*b-N : ℕ) : ℝ)+H := by | |
| exact_mod_cast hineq | |
| rw [hsub] at hh | |
| linarith | |
| noncomputable def tileCount (ℓ L : ℝ) : ℕ := ⌊L/(ℓ+2)⌋₊ ^ 3 | |
| theorem sum_baseline_le {K b H : ℕ} {r : Fin K → ℕ} {a : ℕ → ℝ} {M : ℝ} | |
| (hr : ∀ i, r i ≤ H) (ha : ∀ n, n ≤ H → a n ≤ M) (hb : -M ≤ a b) : | |
| ∑ i, a (r i) ≤ K*a b + 2*M*(∑ i, if r i = b then 0 else 1 : ℕ) := by | |
| classical | |
| calc | |
| ∑ i, a (r i) ≤ ∑ i, (a b + 2*M*(if r i = b then 0 else 1 : ℕ)) := by | |
| apply Finset.sum_le_sum | |
| intro i _ | |
| by_cases hh : r i = b | |
| · simp [hh] | |
| · simp only [ite_eq_right hh, Nat.cast_one, mul_one] | |
| linarith [ha (r i) (hr i)] | |
| _ = _ := by | |
| rw [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, | |
| nsmul_eq_mul, ← Finset.mul_sum, Nat.cast_sum] | |
| theorem adjusted_box_comparison (a : ℝ → ℕ → ℝ) {ℓ L M : ℝ} {b H N : ℕ} | |
| (hℓ : 0 < ℓ) (hL : 0 < L) (hM : 0 ≤ M) (hb : 0 < b) (hH : 2*b ≤ H) | |
| (hN : N ≤ tileCount ℓ L * H) | |
| (hbox : ∀ r : Fin (tileCount ℓ L) → ℕ, (∑ i, r i) = N → | |
| a L N ≤ ℓ^3/L^3 * ∑ i, a ℓ (r i)) | |
| (hbound : ∀ n, n ≤ H → a ℓ n ≤ M) (hbase : -M ≤ a ℓ b) : | |
| a L N ≤ ((tileCount ℓ L : ℝ)/L^3)*ℓ^3*a ℓ b + | |
| (2*M*ℓ^3/(b : ℝ)) * (|(N : ℝ)/L^3 - ((tileCount ℓ L : ℝ)/L^3)*b| + H/L^3) := by | |
| classical | |
| obtain ⟨r, hr, hcounts, hchange⟩ := exists_adjusted_counts (tileCount ℓ L) b H N hb hH hN | |
| have hs := sum_baseline_le hcounts hbound hbase | |
| have hm : 0 ≤ ℓ^3/L^3 := div_nonneg (pow_nonneg hℓ.le _) (pow_nonneg hL.le _) | |
| have hbR : (0 : ℝ) < b := by exact_mod_cast hb | |
| have hc : (∑ i, if r i = b then 0 else 1 : ℕ) ≤ | |
| (|(N : ℝ) - (tileCount ℓ L : ℝ)*b|+H)/(b : ℝ) := | |
| (le_div_iff₀ hbR).2 hchange | |
| calc | |
| a L N ≤ ℓ^3/L^3 * ∑ i, a ℓ (r i) := hbox r hr | |
| _ ≤ ℓ^3/L^3 * ((tileCount ℓ L : ℝ)*a ℓ b + | |
| 2*M*((|(N : ℝ)-(tileCount ℓ L : ℝ)*b|+H)/(b : ℝ))) := by | |
| apply mul_le_mul_of_nonneg_left _ hm | |
| exact hs.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_left hc (show 0 ≤ 2*M by positivity))) | |
| _ = _ := by | |
| have heq : (N : ℝ)/L^3 - ((tileCount ℓ L : ℝ)/L^3)*b = | |
| ((N : ℝ)-(tileCount ℓ L : ℝ)*b)/L^3 := by ring | |
| rw [heq, abs_div, abs_of_pos (pow_pos hL 3)] | |
| ring | |
| end ContinuumTemperature | |
| end | |
| end OAI | |