Download data/lean/OAI/NumberTheory/PiExponent/Approximation/Arithmetic.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/NumberTheory/PiExponent/Approximation/Arithmetic.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/NumberTheory/PiExponent/Approximation/Arithmetic.lean
-
curl -L -o Arithmetic.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/NumberTheory/PiExponent/Approximation/Arithmetic.lean
15.4 kB
| import Mathlib.Algebra.Polynomial.Eval.Subring | |
| import Mathlib.LinearAlgebra.Matrix.Determinant.Basic | |
| import Mathlib.NumberTheory.Chebyshev | |
| import Mathlib.NumberTheory.Zsqrtd.GaussianInt | |
| import Mathlib.RingTheory.PowerSeries.Log | |
| import Mathlib.RingTheory.PowerSeries.Trunc | |
| import Mathlib.Tactic | |
| namespace OAI | |
| namespace PiExponent.Arithmetic | |
| noncomputable def lcmConstant : β := Real.log 4 + 4 | |
| theorem lcmConstant_pos : 0 < lcmConstant := by | |
| have h : 0 < Real.log (4 : β) := Real.log_pos (by norm_num) | |
| dsimp [lcmConstant] | |
| linarith | |
| theorem log_lcmUpto_le (n : β) : | |
| Real.log (Nat.lcmUpto n : β) β€ lcmConstant * n := by | |
| rw [β Chebyshev.psi_eq_log_lcmUpto] | |
| exact Chebyshev.psi_le_const_mul_self (by positivity) | |
| theorem gaussian_norm_one_le (z : GaussianInt) (hz : z β 0) : | |
| 1 β€ β(z : β)β := by | |
| have hi : (1 : β€) β€ z.norm := (GaussianInt.norm_pos.mpr hz) | |
| have hr : (1 : β) β€ (z.norm : β) := by exact_mod_cast hi | |
| rw [GaussianInt.intCast_real_norm, Complex.normSq_eq_norm_sq] at hr | |
| have hn : 0 β€ β(z : β)β := norm_nonneg _ | |
| nlinarith | |
| theorem gaussian_det_norm_one_le {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| (A : Matrix ΞΉ ΞΉ GaussianInt) (hA : A.det β 0) : | |
| 1 β€ β(A.map GaussianInt.toComplex).detβ := by | |
| change 1 β€ β(GaussianInt.toComplex.mapMatrix A).detβ | |
| rw [β RingHom.map_det] | |
| exact gaussian_norm_one_le A.det hA | |
| theorem det_row_column_scale {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| (A : Matrix ΞΉ ΞΉ β) (r c : ΞΉ β β) : | |
| Matrix.det (fun i j => r i * (c j * A i j)) = | |
| (β i, r i) * (β j, c j) * A.det := by | |
| calc | |
| _ = (β i, r i) * (Matrix.of fun i j => c j * A i j).det := | |
| Matrix.det_mul_column r (Matrix.of fun i j => c j * A i j) | |
| _ = _ := by rw [Matrix.det_mul_row c A]; ring | |
| theorem cleared_det_norm_bound {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| (A : Matrix ΞΉ ΞΉ β) (B : Matrix ΞΉ ΞΉ GaussianInt) | |
| (r c : ΞΉ β β) (hr : β i, 0 < r i) (hc : β i, 0 < c i) | |
| (hA : A.det β 0) | |
| (hB : B.map GaussianInt.toComplex = fun i j => (r i : β) * ((c j : β) * A i j)) : | |
| 1 β€ (β i, r i) * (β j, c j) * βA.detβ := by | |
| have hd : (B.map GaussianInt.toComplex).det = | |
| (β i, (r i : β)) * (β j, (c j : β)) * A.det := by | |
| rw [hB, det_row_column_scale] | |
| have hn : B.det β 0 := by | |
| intro he | |
| have hz : (B.map GaussianInt.toComplex).det = 0 := by | |
| change (GaussianInt.toComplex.mapMatrix B).det = 0 | |
| rw [β RingHom.map_det, he, map_zero] | |
| rw [hd] at hz | |
| have hr' : (β i, (r i : β)) β 0 := Finset.prod_ne_zero_iff.mpr (by | |
| intro i hi | |
| exact_mod_cast (hr i).ne') | |
| have hc' : (β j, (c j : β)) β 0 := Finset.prod_ne_zero_iff.mpr (by | |
| intro j hj | |
| exact_mod_cast (hc j).ne') | |
| exact mul_ne_zero (mul_ne_zero hr' hc') hA hz | |
| have h := gaussian_det_norm_one_le B hn | |
| rw [hd, norm_mul, norm_mul, norm_prod, norm_prod] at h | |
| simpa only [Complex.norm_real, Real.norm_eq_abs, abs_of_pos (hr _), | |
| abs_of_pos (hc _)] using h | |
| theorem cleared_det_log_bound {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| (A : Matrix ΞΉ ΞΉ β) (B : Matrix ΞΉ ΞΉ GaussianInt) | |
| (r c : ΞΉ β β) (hr : β i, 0 < r i) (hc : β i, 0 < c i) | |
| (hA : A.det β 0) | |
| (hB : B.map GaussianInt.toComplex = fun i j => (r i : β) * ((c j : β) * A i j)) : | |
| -(β i, Real.log (r i)) - β j, Real.log (c j) β€ Real.log βA.detβ := by | |
| have hrp : 0 < β i, r i := Finset.prod_pos (by intro i hi; exact hr i) | |
| have hcp : 0 < β i, c i := Finset.prod_pos (by intro i hi; exact hc i) | |
| have hn : 0 < βA.detβ := norm_pos_iff.mpr hA | |
| have h := Real.log_nonneg (cleared_det_norm_bound A B r c hr hc hA hB) | |
| rw [Real.log_mul (mul_pos hrp hcp).ne' hn.ne', Real.log_mul hrp.ne' hcp.ne', | |
| Real.log_prod (by intro i hi; exact (hr i).ne'), | |
| Real.log_prod (by intro i hi; exact (hc i).ne')] at h | |
| linarith | |
| theorem log_lcm_power_product_le {ΞΉ : Type*} (s : Finset ΞΉ) (T e : ΞΉ β β) : | |
| Real.log (β i β s, (Nat.lcmUpto (T i) : β) ^ e i) β€ | |
| lcmConstant * β i β s, (e i : β) * T i := by | |
| rw [Real.log_prod (by intro i hi; exact pow_ne_zero _ (by exact_mod_cast Nat.lcmUpto_ne_zero (T i)))] | |
| simp_rw [Real.log_pow] | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| have h := mul_le_mul_of_nonneg_left (log_lcmUpto_le (T i)) (Nat.cast_nonneg (e i) : (0 : β) β€ e i) | |
| nlinarith only [h] | |
| theorem log_lcm_floor_product_le {ΞΉ : Type*} (s : Finset ΞΉ) | |
| (T : ΞΉ β β) (w : ΞΉ β β) (H : β) (hH : 0 β€ H) (hw : β i β s, 0 < w i) : | |
| Real.log (β i β s, (Nat.lcmUpto (T i) : β) ^ βH / w iββ) β€ | |
| H * lcmConstant * β i β s, (T i : β) / w i := by | |
| calc | |
| _ β€ lcmConstant * β i β s, (βH / w iββ : β) * T i := | |
| log_lcm_power_product_le s T _ | |
| _ β€ lcmConstant * β i β s, (H / w i) * T i := by | |
| apply mul_le_mul_of_nonneg_left _ lcmConstant_pos.le | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg (T i)) | |
| exact Nat.floor_le (div_nonneg hH (hw i hi).le) | |
| _ = _ := by | |
| rw [Finset.mul_sum, Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro i hi | |
| ring | |
| theorem sum_ceil_truncation_div_le {ΞΉ : Type*} (s : Finset ΞΉ) | |
| (w : ΞΉ β β) (F v : β) (hF : 0 β€ F) (hv : 0 < v) (hw : β i β s, 0 < w i) : | |
| (β i β s, (βF * w i / vββ : β) / w i) β€ | |
| F * s.card / v + β i β s, 1 / w i := by | |
| calc | |
| _ β€ β i β s, (F * w i / v + 1) / w i := by | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| apply div_le_div_of_nonneg_right _ (hw i hi).le | |
| exact (Nat.ceil_lt_add_one (div_nonneg (mul_nonneg hF (hw i hi).le) hv.le)).le | |
| _ = β i β s, (F / v + 1 / w i) := by | |
| apply Finset.sum_congr rfl | |
| intro i hi | |
| field_simp [(hw i hi).ne', hv.ne'] | |
| _ = _ := by rw [Finset.sum_add_distrib, Finset.sum_const]; simp; ring | |
| theorem truncation_denominator_log_le {ΞΉ : Type*} (s : Finset ΞΉ) | |
| (w : ΞΉ β β) (F v H : β) (hF : 0 β€ F) (hv : 0 < v) (hH : 0 < H) | |
| (hw : β i β s, 0 < w i) : | |
| Real.log (β i β s, | |
| (Nat.lcmUpto (βF * w i / vββ) : β) ^ βH / w iββ) / H β€ | |
| lcmConstant * F * s.card / v + lcmConstant * β i β s, 1 / w i := by | |
| apply (div_le_iffβ hH).mpr | |
| calc | |
| _ β€ H * lcmConstant * β i β s, (βF * w i / vββ : β) / w i := | |
| log_lcm_floor_product_le s _ w H hH.le hw | |
| _ β€ H * lcmConstant * (F * s.card / v + β i β s, 1 / w i) := by | |
| exact mul_le_mul_of_nonneg_left (sum_ceil_truncation_div_le s w F v hF hv hw) | |
| (mul_pos hH lcmConstant_pos).le | |
| _ = _ := by ring | |
| theorem dvd_lcmUpto_of_pos_le {k T : β} (hk : 0 < k) (hkT : k β€ T) : | |
| k β£ Nat.lcmUpto T := by | |
| exact Finset.dvd_lcm (f := id) (Finset.mem_Icc.mpr β¨hk, hkTβ©) | |
| theorem lcm_mul_log_coeff_gaussian (T k : β) (hk : k β€ T) : | |
| (Nat.lcmUpto T : β) * PowerSeries.coeff k (PowerSeries.log β) β | |
| GaussianInt.toComplex.range := by | |
| by_cases hk0 : k = 0 | |
| Β· simp [hk0] | |
| obtain β¨m, hmβ© := dvd_lcmUpto_of_pos_le (Nat.pos_of_ne_zero hk0) hk | |
| refine β¨((-1 : GaussianInt) ^ (k + 1)) * (m : GaussianInt), ?_β© | |
| rw [PowerSeries.coeff_log, ite_eq_right hk0, hm] | |
| have hkC : (k : β) β 0 := by exact_mod_cast hk0 | |
| simp only [map_mul, map_pow, map_neg, map_one, map_natCast, map_divβ, Nat.cast_mul] | |
| field_simp | |
| theorem cleared_log_trunc_mem (T : β) : | |
| Polynomial.C (Nat.lcmUpto T : β) * PowerSeries.trunc T (PowerSeries.log β) β | |
| (Polynomial.mapRingHom GaussianInt.toComplex).range := by | |
| apply (Polynomial.mem_map_range GaussianInt.toComplex).mpr | |
| intro k | |
| rw [Polynomial.coeff_C_mul, PowerSeries.coeff_trunc] | |
| split_ifs with hk | |
| Β· exact lcm_mul_log_coeff_gaussian T k hk.le | |
| Β· simp | |
| theorem exists_cleared_log_trunc (T : β) : | |
| β P : Polynomial GaussianInt, | |
| P.map GaussianInt.toComplex = | |
| Polynomial.C (Nat.lcmUpto T : β) * PowerSeries.trunc T (PowerSeries.log β) := | |
| cleared_log_trunc_mem T | |
| theorem gaussian_C_mem (z : GaussianInt) : | |
| Polynomial.C (z : β) β (Polynomial.mapRingHom GaussianInt.toComplex).range := by | |
| exact β¨Polynomial.C z, by simpβ© | |
| theorem cleared_shifted_log_trunc_mem (T q : β) (z : GaussianInt) : | |
| Polynomial.C (Nat.lcmUpto T : β) * | |
| (Polynomial.C (z : β) + Polynomial.C (q : β) * | |
| PowerSeries.trunc T (PowerSeries.log β)) β | |
| (Polynomial.mapRingHom GaussianInt.toComplex).range := by | |
| let S := (Polynomial.mapRingHom GaussianInt.toComplex).range | |
| have hL : Polynomial.C (Nat.lcmUpto T : β) β S := by | |
| simp | |
| have hq : Polynomial.C (q : β) β S := by | |
| simp | |
| have hlog := cleared_log_trunc_mem T | |
| have h := S.add_mem (S.mul_mem hL (gaussian_C_mem z)) (S.mul_mem hq hlog) | |
| convert h using 1 | |
| ring | |
| theorem cleared_polynomial_power_mem (L e d : β) (f : Polynomial β) (hd : d β€ e) | |
| (hf : Polynomial.C (L : β) * f β (Polynomial.mapRingHom GaussianInt.toComplex).range) : | |
| Polynomial.C ((L : β) ^ e) * f ^ d β | |
| (Polynomial.mapRingHom GaussianInt.toComplex).range := by | |
| let S := (Polynomial.mapRingHom GaussianInt.toComplex).range | |
| have hL : Polynomial.C (L : β) β S := by | |
| simp | |
| have h := S.mul_mem (S.pow_mem hL (e - d)) (S.pow_mem hf d) | |
| have he : e = (e - d) + d := (Nat.sub_add_cancel hd).symm | |
| rw [he, map_pow, pow_add] | |
| simpa only [mul_pow, mul_assoc] using h | |
| theorem cleared_polynomial_product_mem {ΞΉ : Type*} (s : Finset ΞΉ) | |
| (L e d : ΞΉ β β) (f : ΞΉ β Polynomial β) (hd : β i β s, d i β€ e i) | |
| (hf : β i β s, Polynomial.C (L i : β) * f i β | |
| (Polynomial.mapRingHom GaussianInt.toComplex).range) : | |
| Polynomial.C (β i β s, (L i : β) ^ e i) * (β i β s, f i ^ d i) β | |
| (Polynomial.mapRingHom GaussianInt.toComplex).range := by | |
| let S := (Polynomial.mapRingHom GaussianInt.toComplex).range | |
| have h := S.prod_mem (fun i hi => cleared_polynomial_power_mem (L i) (e i) (d i) | |
| (f i) (hd i hi) (hf i hi)) | |
| simpa only [β Finset.prod_mul_distrib, map_prod] using h | |
| theorem common_denominator_coeff_gaussian {ΞΉ : Type*} (s : Finset ΞΉ) | |
| (L e d : ΞΉ β β) (f : ΞΉ β Polynomial β) (P : Polynomial GaussianInt) | |
| (hd : β i β s, d i β€ e i) | |
| (hf : β i β s, Polynomial.C (L i : β) * f i β | |
| (Polynomial.mapRingHom GaussianInt.toComplex).range) (k : β) : | |
| (β i β s, (L i : β) ^ e i) * | |
| (P.map GaussianInt.toComplex * β i β s, f i ^ d i).coeff k β | |
| GaussianInt.toComplex.range := by | |
| let S := (Polynomial.mapRingHom GaussianInt.toComplex).range | |
| have hP : P.map GaussianInt.toComplex β S := β¨P, rflβ© | |
| have h := S.mul_mem hP (cleared_polynomial_product_mem s L e d f hd hf) | |
| have he : P.map GaussianInt.toComplex * | |
| (Polynomial.C (β i β s, (L i : β) ^ e i) * β i β s, f i ^ d i) = | |
| Polynomial.C (β i β s, (L i : β) ^ e i) * | |
| (P.map GaussianInt.toComplex * β i β s, f i ^ d i) := by ring | |
| rw [he] at h | |
| have hc := (Polynomial.mem_map_range GaussianInt.toComplex).mp h k | |
| simpa only [Polynomial.coeff_C_mul] using hc | |
| theorem cleared_det_log_bound_of_entries {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| (A : Matrix ΞΉ ΞΉ β) (r c : ΞΉ β β) (hr : β i, 0 < r i) (hc : β i, 0 < c i) | |
| (hA : A.det β 0) | |
| (hentries : β i j, (r i : β) * ((c j : β) * A i j) β GaussianInt.toComplex.range) : | |
| -(β i, Real.log (r i)) - β j, Real.log (c j) β€ Real.log βA.detβ := by | |
| classical | |
| choose B hB using hentries | |
| apply cleared_det_log_bound A B r c hr hc hA | |
| ext i j | |
| exact hB i j | |
| theorem cleared_det_log_bound_with_denominator {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| (A : Matrix ΞΉ ΞΉ β) (r c : ΞΉ β β) (D : β) | |
| (hD : 0 < D) (hr : β i, 0 < r i) (hc : β i, 0 < c i) (hA : A.det β 0) | |
| (hentries : β i j, (D : β) * (r i : β) * ((c j : β) * A i j) β | |
| GaussianInt.toComplex.range) : | |
| -(Fintype.card ΞΉ : β) * Real.log D - (β i, Real.log (r i)) - | |
| β j, Real.log (c j) β€ Real.log βA.detβ := by | |
| have h := cleared_det_log_bound_of_entries A (fun i => D * r i) c | |
| (fun i => mul_pos hD (hr i)) hc hA (by simpa using hentries) | |
| simp_rw [Real.log_mul hD.ne' (hr _).ne'] at h | |
| rw [Finset.sum_add_distrib, Finset.sum_const] at h | |
| simp only [Finset.card_univ, nsmul_eq_mul] at h | |
| linarith | |
| theorem shifted_truncation_product_coeff_gaussian {ΞΉ : Type*} (s : Finset ΞΉ) | |
| (T q e d : ΞΉ β β) (z : ΞΉ β GaussianInt) (P : Polynomial GaussianInt) | |
| (hd : β i β s, d i β€ e i) (k : β) : | |
| (β i β s, (Nat.lcmUpto (T i) : β) ^ e i) * | |
| (P.map GaussianInt.toComplex * β i β s, | |
| (Polynomial.C (z i : β) + Polynomial.C (q i : β) * | |
| PowerSeries.trunc (T i) (PowerSeries.log β)) ^ d i).coeff k β | |
| GaussianInt.toComplex.range := by | |
| exact common_denominator_coeff_gaussian s (fun i => Nat.lcmUpto (T i)) e d _ P hd | |
| (fun i hi => cleared_shifted_log_trunc_mem (T i) (q i) (z i)) k | |
| theorem column_log_cost_le {ΞΉ : Type*} (s : Finset ΞΉ) (a q : ΞΉ β β) : | |
| (β i β s, (a i : β) * Real.log (q i)) β€ | |
| β i β s, (a i : β) * (βReal.log (q i)ββ : β) := by | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| exact mul_le_mul_of_nonneg_left (Nat.le_ceil _) (Nat.cast_nonneg _) | |
| theorem sum_exponents_le_weight_div {ΞΉ : Type*} (s : Finset ΞΉ) | |
| (a : ΞΉ β β) (w : ΞΉ β β) (wmin : β) (hmin : 0 < wmin) | |
| (hw : β i β s, wmin β€ w i) : | |
| (β i β s, (a i : β)) β€ (β i β s, (a i : β) * w i) / wmin := by | |
| apply (le_div_iffβ hmin).mpr | |
| rw [Finset.sum_mul] | |
| exact Finset.sum_le_sum (fun i hi => mul_le_mul_of_nonneg_left (hw i hi) (Nat.cast_nonneg _)) | |
| theorem row_log_cost_lower {ΞΉ : Type*} (s : Finset ΞΉ) | |
| (a q : ΞΉ β β) (wmin U : β) (hmin : 0 < wmin) | |
| (hw : β i β s, wmin β€ (βReal.log (q i)ββ : β)) | |
| (hbudget : (β i β s, (a i : β) * (βReal.log (q i)ββ : β)) β€ U) : | |
| (β i β s, (a i : β) * (βReal.log (q i)ββ : β)) - U / wmin β€ | |
| β i β s, (a i : β) * Real.log (q i) := by | |
| have hsum := sum_exponents_le_weight_div s a (fun i => (βReal.log (q i)ββ : β)) | |
| wmin hmin hw | |
| have hsumU : (β i β s, (a i : β)) β€ U / wmin := | |
| hsum.trans (div_le_div_of_nonneg_right hbudget hmin.le) | |
| have hceil : (β i β s, (a i : β) * (βReal.log (q i)ββ : β)) β€ | |
| (β i β s, (a i : β) * Real.log (q i)) + β i β s, (a i : β) := by | |
| rw [β Finset.sum_add_distrib] | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| have h := mul_le_mul_of_nonneg_left | |
| (Nat.ceil_lt_add_one (Real.log_natCast_nonneg (q i))).le (Nat.cast_nonneg (a i) : (0 : β) β€ a i) | |
| nlinarith only [h] | |
| linarith | |
| theorem normalized_arithmetic_bound (M H b E Ξ΄ logD columnCost rowCost logAbsDet : β) | |
| (hM : 0 < M) (hH : 0 < H) | |
| (hclear : -M * logD - columnCost + rowCost β€ logAbsDet) | |
| (hden : logD β€ H * E) | |
| (hcol : columnCost β€ M * H) | |
| (hrow : M * H * b - M * H * Ξ΄ β€ rowCost) : | |
| -(1 - b) - (E + Ξ΄) β€ logAbsDet / (M * H) := by | |
| apply (le_div_iffβ (mul_pos hM hH)).mpr | |
| have hd := mul_le_mul_of_nonneg_left hden hM.le | |
| nlinarith only [hclear, hd, hcol, hrow] | |
| end PiExponent.Arithmetic | |
| end OAI | |