Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/yang/blob/main/proofs/DyadicExp.lean # yang This project has not described itself yet. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `yang / proofs / DyadicExp.lean` 99 lines · 3727 bytes Raw Blame History 1 import Mathlib.Analysis.SpecialFunctions.Exp 2 import Mathlib.Tactic 3 4 namespace YangMills.DyadicExp 5 6 def q : ℤ := `268435456` 7 8 /-- Downward-rounded positive squaring on the OM-2 dyadic grid. -/ 9 def squareDown : ℕ → ℤ → ℤ 10 | 0, v => v 11 | n+1, v => let w := squareDown n v; w*w/q 12 13 def expLo (x : ℤ) := squareDown 12 (q + x/4096) 14 def ceilDiv (n d : ℤ) := -((-n)/d) 15 def expHi (x : ℤ) := ceilDiv (q*q) (expLo (-x)) 16 17 private theorem floor_spec (a b : ℤ) (hb : 0 < b) : 18 ((a/b : ℤ) : ℝ) ≤ (a : ℝ)/(b:ℝ) := by 19 apply (le_div_iff₀ (by exact_mod_cast hb)).2 20 exact_mod_cast Int.ediv_mul_le a (ne_of_gt hb) 21 22 private theorem ceil_spec (a b : ℤ) (hb : 0 < b) : 23 (a : ℝ)/(b : ℝ) ≤ (ceilDiv a b : ℝ) := by 24 unfold ceilDiv 25 push_cast 26 have := floor_spec (-a) b hb 27 push_cast at this 28 rw [neg_div] at this 29 linarith 30 31 private theorem squares_le {v : ℤ} {b : ℝ} (hv : 0 ≤ v) (hb : (v:ℝ) / q ≤ b) 32 (n : ℕ) : 0 ≤ squareDown n v ∧ (squareDown n v : ℝ)/q ≤ b^(2^n) := by 33 induction n with 34 | zero => simpa [squareDown] using And.intro hv hb 35 | succ n ih => 36 let w := squareDown n v 37 have hw : 0 ≤ w := ih.1 38 refine ⟨Int.ediv_nonneg (mul_nonneg hw hw) (by decide), ?_⟩ 39 have hh := floor_spec (w*w) q (by decide) 40 push_cast at hh 41 have hpow := pow_le_pow_left₀ (show 0 ≤ (w:ℝ)/q by unfold q; positivity) ih.2 2 42 rw [pow_succ 2, pow_mul] 43 change ((w*w/q : ℤ):ℝ)/q ≤ _ 44 calc _ ≤ ((w:ℝ)/q)^2 := by dsimp [q] at hh ⊢; linarith 45 _ ≤ _ := hpow 46 47 theorem expLo_sound {x : ℤ} (hx : -(2*q) ≤ x) : 48 (expLo x : ℝ)/q ≤ Real.exp ((x:ℝ)/q) := by 49 have hf := floor_spec x 4096 (by decide) 50 have hv : 0 ≤ q + x/4096 := by dsimp [q] at *; omega 51 have hp := Real.add_one_le_exp ((x:ℝ)/(q*4096)) 52 have hbase : ((q+x/4096 : ℤ):ℝ)/q ≤ Real.exp ((x:ℝ)/(q*4096)) := by 53 push_cast 54 dsimp [q] at *; linarith 55 have hh := (squares_le hv hbase 12).2 56 rw [← Real.exp_nat_mul] at hh 57 convert hh using 2 <;> norm_num [expLo, q] 58 ring 59 60 private theorem squareDown_mono {v w : ℤ} (hv : 0 ≤ v) (hvw : v ≤ w) (n : ℕ) : 61 0 ≤ squareDown n v ∧ squareDown n v ≤ squareDown n w := by 62 induction n with 63 | zero => exact ⟨hv,hvw⟩ 64 | succ n ih => 65 have hw := ih.1.trans ih.2 66 exact ⟨Int.ediv_nonneg (mul_nonneg ih.1 ih.1) (by decide), 67 Int.ediv_le_ediv (by decide) (mul_le_mul ih.2 ih.2 ih.1 hw)⟩ 68 69 theorem expLo_floor {x : ℤ} (hx : -(2*q) ≤ x) : q / 8 ≤ expLo x := by 70 have hv : 0 ≤ q + (-(2*q))/4096 := by decide 71 have hh : q + (-(2*q))/4096 ≤ q + x/4096 := 72 add_le_add_right (Int.ediv_le_ediv (by decide) hx) q 73 exact (show q / 8 ≤ expLo (-(2*q)) by decide).trans (squareDown_mono hv hh 12).2 74 75 theorem expLo_pos {x : ℤ} (hx : -(2*q) ≤ x) : 0 < expLo x := 76 (show 0 < q / 8 by decide).trans_le (expLo_floor hx) 77 78 theorem expHi_sound {x : ℤ} (hx : x ≤ 2*q) : 79 Real.exp ((x:ℝ)/q) ≤ (expHi x : ℝ)/q := by 80 have hd := expLo_pos (x := -x) (by omega) 81 have hl := expLo_sound (x := -x) (by omega) 82 push_cast at hl 83 rw [neg_div, Real.exp_neg] at hl 84 have he := (le_div_iff₀ (Real.exp_pos ((x:ℝ)/q))).mp (by simpa [one_div] using hl : 85 (expLo (-x) : ℝ)/q ≤ 1/Real.exp ((x:ℝ)/q)) 86 have hden : 0 < (expLo (-x) : ℝ) := by exact_mod_cast hd 87 have hu := ceil_spec (q*q) (expLo (-x)) hd 88 push_cast at hu 89 have hinv : Real.exp ((x:ℝ)/q) ≤ (q:ℝ)/(expLo (-x):ℝ) := by 90 apply (le_div_iff₀ hden).2 91 dsimp [q] at he ⊢; linarith 92 apply hinv.trans 93 apply (le_div_iff₀ (show (0:ℝ)