introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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