Lean / Reader
Lean readerCubeSpectrum.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports CubeSpectrum.Entries, CubeSpectrum.Certificates, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import CubeSpectrum.Entriesimport CubeSpectrum.Certificatesimport Mathlib.Topology.Order.IntermediateValueimport Mathlib.Topology.Instances.Real.Lemmasnamespace CubeSpectrumnoncomputable sectiondef top : (n : ℕ) → Cube n| 0 => ()| n+1 => (true, top n)lemma weight_top (n : ℕ) (s : Cube n) : weight n s = n ↔ s = top n := byinduction n with| zero => cases s; simp [top, weight]| succ n ih =>obtain ⟨b,s⟩ := shave h := weight_le n scases b <;> simp [weight, top, ih, show weight n s ≠ n+1 by omega]theorem nonparity_positive {u : ℝ} (lo : 0 < u) (hi : u < 1)(s : Cube 8) (hs : s ≠ top 8) : 0 < eigen 8 (kernel u) s := byhave h := weight_le 8 shave hn := mt (weight_top 8 s).mp hshave : weight 8 s = 0 ∨ weight 8 s = 1 ∨ weight 8 s = 2 ∨ weight 8 s = 3 ∨weight 8 s = 4 ∨ weight 8 s = 5 ∨ weight 8 s = 6 ∨ weight 8 s = 7 := by omegarcases this with h|h|h|h|h|h|h|h· rw [eigen, h]; exact positive0 lo hi· rw [eigen, h]; exact positive1 lo hi· rw [eigen, h]; exact positive2 lo hi· rw [eigen, h]; exact positive3 lo hi· rw [eigen, h]; exact positive4 lo hi· rw [eigen, h]; exact positive5 lo hi· rw [eigen, h]; exact positive6 lo hi· rw [eigen, h]; exact positive7 lo hitheorem parity_formula {u : ℝ} (lo : 0 < u) (hi : u < 1) :eigen 8 (kernel u) (top 8) = (505774080 * u^8 * (1-u^2) / common u) * cubic (u^2) := byhave h := cleared8 lo hihave ht : weight 8 (top 8) = 8 := (weight_top ..).2 rflsimp only [eigen, ht, Nat.sub_self]rw [div_mul_eq_mul_div, eq_div_iff (common_pos lo hi).ne', mul_comm]exact hlemma parity_factor_pos {u : ℝ} (lo : 0 < u) (hi : u < 1) :0 < 505774080 * u^8 * (1-u^2) / common u := byhave := common_pos lo hihave : 0 < 1-u^2 := by nlinarith [mul_pos lo (sub_pos.mpr hi)]positivitylemma onto (n) : Function.Surjective (W n) := byintro wrefine ⟨fun s => W n w s / 2^n, ?_⟩funext xchange (∑ s, character n x s * (W n w s / 2^n)) = w xsimp_rw [← mul_div_assoc]simp only [div_eq_mul_inv]rw [← Finset.sum_mul]change W n (W n w) x * (2^n)⁻¹ = w xrw [twice]; field_simplemma W_zero (n) : W n 0 = 0 := by funext x; simp [W]def spike (s : Cube 8) (x : Cube 8) : ℝ := by classical exact if x=s then 1 else 0lemma form_spike (u : ℝ) (s : Cube 8) :form 8 (kernel u) (W 8 (spike s)) = 256 * eigen 8 (kernel u) s := byrw [diagonal]simp [spike, ite_pow, mul_ite]<;> norm_numdef PSD (u : ℝ) := ∀ w, 0 ≤ form 8 (kernel u) wdef PD (u : ℝ) := ∀ w, w ≠ 0 → 0 < form 8 (kernel u) wlemma all_nonneg {u : ℝ} (lo : 0 < u) (hi : u < 1) (h : 0 ≤ cubic (u^2))(s : Cube 8) : 0 ≤ eigen 8 (kernel u) s := byby_cases hs : s = top 8· rw [hs, parity_formula lo hi]; exact mul_nonneg (parity_factor_pos lo hi).le h· exact (nonparity_positive lo hi s hs).letheorem psd_iff {u : ℝ} (lo : 0 < u) (hi : u < 1) : PSD u ↔ 0 ≤ cubic (u^2) := byconstructor· intro hhave b := h (W 8 (spike (top 8)))rw [form_spike, parity_formula lo hi] at bexact nonneg_of_mul_nonneg_right (nonneg_of_mul_nonneg_right b (by norm_num)) (parity_factor_pos lo hi)· intro h wobtain ⟨a,rfl⟩ := onto 8 wrw [diagonal]exact mul_nonneg (by norm_num) (Finset.sum_nonneg fun s _ => mul_nonneg (all_nonneg lo hi h s) (sq_nonneg _))theorem pd_iff {u : ℝ} (lo : 0 < u) (hi : u < 1) : PD u ↔ 0 < cubic (u^2) := byconstructor· intro hhave nz : W 8 (spike (top 8)) ≠ 0 := byintro hehave H := twice 8 (spike (top 8)) (top 8)rw [he,W_zero] at Hnorm_num [spike] at Hhave H := h _ nzrw [form_spike, parity_formula lo hi] at Hexact pos_of_mul_pos_right (pos_of_mul_pos_right H (by norm_num)) (parity_factor_pos lo hi).le· intro h w hwobtain ⟨a,rfl⟩ := onto 8 whave ex : ∃ s, a s ≠ 0 := byby_contra! Hzexact hw ((congrArg (W 8) (show a=0 from funext Hz)).trans (W_zero 8))obtain ⟨t,ht⟩ := exrw [diagonal]apply mul_pos (by norm_num)apply Finset.sum_pos' (fun s _ => mul_nonneg (all_nonneg lo hi h.le s) (sq_nonneg _))refine ⟨t, Finset.mem_univ _, mul_pos ?_ (sq_pos_of_ne_zero ht)⟩by_cases he : t = top 8· rw [he, parity_formula lo hi]; exact mul_pos (parity_factor_pos lo hi) h· exact nonparity_positive lo hi t hetheorem boundary_null {u : ℝ} (lo : 0 < u) (hi : u < 1) (h : cubic (u^2)=0)(a : Cube 8 → ℝ) :form 8 (kernel u) (W 8 a) = 0 ↔ ∀ s, s ≠ top 8 → a s = 0 := byrw [diagonal, mul_eq_zero]simp only [pow_ne_zero 8 (by norm_num : (2:ℝ) ≠ 0), false_or]rw [Finset.sum_eq_zero_iff_of_nonneg (fun s _ => mul_nonneg (all_nonneg lo hi h.ge s) (sq_nonneg _))]constructor· intro H s hshave he := H s (Finset.mem_univ _)rcases mul_eq_zero.mp he with he|he· exact ((nonparity_positive lo hi s hs).ne' he).elim· simpa using he· intro H s _by_cases hs : s = top 8· simp [hs, parity_formula lo hi, h]· simp [H s hs]lemma cubic_mono : StrictMonoOn cubic (Set.Icc (0:ℝ) 1) := byintro x hx y hy hxyhave H : 0 < 4*(y^2+y*x+x^2) + 791-190*(y+x) := bynlinarith [sq_nonneg y, sq_nonneg x, mul_nonneg hy.1 hx.1, hx.2,hy.2]unfold cubicnlinarith only [mul_pos (sub_pos.mpr hxy) H]theorem unique_crossing : ∃! z : ℝ, z ∈ Set.Ioo (0:ℝ) 1 ∧ cubic z = 0 := byhave hc : Continuous cubic := by unfold cubic; fun_propobtain ⟨z,hz,he⟩ := intermediate_value_Icc (by norm_num : (0:ℝ) ≤ 1) hc.continuousOn(show (0:ℝ) ∈ Set.Icc (cubic 0) (cubic 1) by constructor <;> norm_num [cubic])have h0 : z ≠ 0 := by rintro rfl; norm_num [cubic] at hehave h1 : z ≠ 1 := by rintro rfl; norm_num [cubic] at herefine ⟨z, ⟨⟨lt_of_le_of_ne hz.1 h0.symm, lt_of_le_of_ne hz.2 h1⟩, he⟩, ?_⟩intro y hyexact cubic_mono.injOn ⟨hy.1.1.le,hy.1.2.le⟩ hz (hy.2.trans he.symm)theorem radius_threshold {z r : ℝ} (hz : z ∈ Set.Ioo (0:ℝ) 1) (root : cubic z = 0)(lo : 0 < r) (hi : r < 1) :(PSD (r^2) ↔ z ≤ r^4) ∧ (PD (r^2) ↔ z < r^4) := byhave hu : r^2 < 1 := by nlinarith [mul_pos lo (sub_pos.mpr hi)]have hr : r^4 ∈ Set.Icc (0:ℝ) 1 := byconstructor· positivity· nlinarith [mul_pos (sq_pos_of_pos lo) (sub_pos.mpr hu)]have hz' : z ∈ Set.Icc (0:ℝ) 1 := ⟨hz.1.le,hz.2.le⟩rw [psd_iff (sq_pos_of_pos lo) hu, pd_iff (sq_pos_of_pos lo) hu,show (r^2)^2 = r^4 by ring, ← root]exact ⟨cubic_mono.le_iff_le hz' hr, cubic_mono.lt_iff_lt hz' hr⟩endend CubeSpectrum