Download data/lean/OAI/MathematicalPhysics/NavierStokes/Material/Decoder.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.72 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/NavierStokes/Material/Decoder.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/MathematicalPhysics/NavierStokes/Material/Decoder.lean
-
curl -L -o Decoder.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/NavierStokes/Material/Decoder.lean
8.72 kB
| import OAI.MathematicalPhysics.NavierStokes.Material.History | |
| namespace OAI | |
| namespace Alternating.Memory | |
| open scoped Topology | |
| noncomputable def periodicDecoder (a b x : β) : β := | |
| Int.fract x - Real.smoothTransition ((Int.fract x - a) / (b - a)) | |
| theorem periodicDecoder_periodic (a b : β) : Function.Periodic (periodicDecoder a b) 1 := by | |
| intro x | |
| simp only [periodicDecoder, Int.fract_add_one] | |
| theorem periodicDecoder_on_unit {a b x : β} (hx : x β Set.Ico 0 1) : | |
| periodicDecoder a b x = x - Real.smoothTransition ((x - a) / (b - a)) := by | |
| simp only [periodicDecoder, Int.fract_eq_self.2 hx] | |
| theorem periodicDecoder_on_safe {a b m : β} (hab : a < b) (hbm : b < 1) (hma : m < a) | |
| {x : β} (hx : x β Set.Icc 0 m) : periodicDecoder a b x = x := by | |
| rw [periodicDecoder_on_unit β¨hx.1, by linarith [hx.2]β©, | |
| Real.smoothTransition.zero_of_nonpos (div_nonpos_of_nonpos_of_nonneg | |
| (by linarith [hx.2]) (by linarith)), sub_zero] | |
| theorem periodicDecoder_near_zero {a b : β} (ha : 0 < a) (hab : a < b) (hb : b < 1) | |
| {x : β} (hx : x β Set.Ioo (b - 1) a) : periodicDecoder a b x = x := by | |
| have hba : 0 < b - a := sub_pos.2 hab | |
| by_cases hx0 : 0 β€ x | |
| Β· rw [periodicDecoder_on_unit β¨hx0, hx.2.trans (hab.trans hb)β©, | |
| Real.smoothTransition.zero_of_nonpos | |
| (div_nonpos_of_nonpos_of_nonneg (sub_nonpos.2 hx.2.le) hba.le), sub_zero] | |
| Β· have hneg : x < 0 := lt_of_not_ge hx0 | |
| have hfloor : βxβ = (-1 : β€) := Int.floor_eq_iff.2 β¨by norm_num; linarith [hx.1], by simpaβ© | |
| have hfract : Int.fract x = x + 1 := by simp [Int.fract, hfloor] | |
| have hstep : 1 β€ (x + 1 - a) / (b - a) := (le_div_iffβ hba).2 (by linarith [hx.1]) | |
| simp [periodicDecoder, hfract, Real.smoothTransition.one_of_one_le hstep] | |
| theorem periodicDecoder_smooth {a b : β} (ha : 0 < a) (hab : a < b) (hb : b < 1) : | |
| ContDiff β (β€ : ββ) (periodicDecoder a b) := by | |
| apply contDiff_iff_contDiffAt.2 | |
| intro x | |
| let k : β€ := βxβ | |
| by_cases hx : x = (k : β) | |
| Β· have hlocal : periodicDecoder a b =αΆ [π x] (fun y : β => y - (k : β)) := by | |
| filter_upwards [Ioo_mem_nhds (a := (k : β) + b - 1) (b := (k : β) + a) | |
| (by rw [hx]; linarith) (by rw [hx]; linarith)] with y hy | |
| have hi := ((periodicDecoder_periodic a b).int_mul (-k)) y | |
| have heq : periodicDecoder a b y = periodicDecoder a b (y - k) := by | |
| simpa [sub_eq_add_neg] using hi.symm | |
| rw [heq] | |
| exact periodicDecoder_near_zero ha hab hb β¨by linarith [hy.1], by linarith [hy.2]β© | |
| exact (contDiffAt_id.sub contDiffAt_const).congr_of_eventuallyEq hlocal | |
| Β· have hlow : (k : β) < x := (Int.floor_le x).lt_of_ne (Ne.symm hx) | |
| have hupp : x < (k : β) + 1 := Int.lt_floor_add_one x | |
| have hlocal : periodicDecoder a b =αΆ [π x] | |
| (fun y : β => (y - k) - Real.smoothTransition (((y - k) - a) / (b - a))) := by | |
| filter_upwards [Ioo_mem_nhds hlow hupp] with y hy | |
| have hfloor : βyβ = k := Int.floor_eq_iff.2 β¨hy.1.le, hy.2β© | |
| simp only [periodicDecoder, Int.fract, hfloor] | |
| apply ContDiffAt.congr_of_eventuallyEq (hg := hlocal) | |
| apply (show ContDiff β (β€ : ββ) | |
| (fun y : β => (y - k) - Real.smoothTransition (((y - k) - a) / (b - a))) from ?_).contDiffAt | |
| fun_prop | |
| theorem periodic_iteratedDeriv {P : β β β} (hP : Function.Periodic P 1) (n : β) : | |
| Function.Periodic (iteratedDeriv n P) 1 := by | |
| have heq : (fun x => P (x + 1)) = P := funext hP | |
| have h := iteratedDeriv_comp_add_const n P 1 | |
| rw [heq] at h | |
| exact fun x => (congr_fun h x).symm | |
| theorem periodicDecoder_derivatives_bounded {a b : β} | |
| (ha : 0 < a) (hab : a < b) (hb : b < 1) (n : β) : | |
| β M : β, 0 < M β§ β x : β, |iteratedDeriv n (periodicDecoder a b) x| β€ M := by | |
| have hp := periodic_iteratedDeriv (periodicDecoder_periodic a b) n | |
| have hc := (periodicDecoder_smooth ha hab hb).continuous_iteratedDeriv n (by exact_mod_cast (le_top : (n : ββ) β€ β€)) | |
| obtain β¨M, hM, hboundβ© := | |
| (hp.isBounded_of_continuous (by norm_num : (1 : β) β 0) hc).exists_pos_norm_le | |
| exact β¨M, hM, fun x => by simpa using hbound _ β¨x, rflβ©β© | |
| end Alternating.Memory | |
| namespace Alternating.Memory | |
| open scoped BigOperators | |
| open Finset | |
| noncomputable def safeDecoder (b : β) : β β β := | |
| periodicDecoder ((2 * tailBound b + 1) / 3) ((tailBound b + 2) / 3) | |
| theorem safeDecoder_smooth {b : β} (hb : 2 β€ b) : | |
| ContDiff β (β€ : ββ) (safeDecoder b) := by | |
| have hm0 := tailBound_nonneg hb | |
| have hm1 := tailBound_lt_one hb | |
| exact periodicDecoder_smooth (by linarith) (by linarith) (by linarith) | |
| theorem safeDecoder_periodic (b : β) : Function.Periodic (safeDecoder b) 1 := | |
| periodicDecoder_periodic _ _ | |
| theorem safeDecoder_on_safe {b : β} (hb : 2 β€ b) {x : β} | |
| (hx : x β Set.Icc 0 (tailBound b)) : safeDecoder b x = x := by | |
| have hm1 := tailBound_lt_one hb | |
| exact periodicDecoder_on_safe (by linarith) (by linarith) (by linarith) hx | |
| theorem safeDecoder_derivatives_bounded {b : β} (hb : 2 β€ b) (n : β) : | |
| β M : β, 0 < M β§ β x : β, |iteratedDeriv n (safeDecoder b) x| β€ M := by | |
| have hm0 := tailBound_nonneg hb | |
| have hm1 := tailBound_lt_one hb | |
| exact periodicDecoder_derivatives_bounded (by linarith) (by linarith) (by linarith) n | |
| theorem safe_read_exact {b N : β} (hb : 2 β€ b) (C : β n, Block b (width N n)) (n : β) : | |
| safeDecoder b ((b : β) ^ scale N n * donor b N C n) = (C n).code β§ | |
| safeDecoder b ((b : β) ^ (scale N n + 1 + width N n) * donor b N C n) = (C n).rightCode β§ | |
| safeDecoder b ((b : β) ^ (scale N n + 1) * donor b N C n) - | |
| (b : β)β»ΒΉ ^ width N n * | |
| safeDecoder b ((b : β) ^ (scale N n + 1 + width N n) * donor b N C n) = (C n).leftCode := | |
| read_exact hb C (safeDecoder_periodic b) (fun _ hx => safeDecoder_on_safe hb hx) n | |
| theorem history_nonneg {b N : β} (hb : 0 < b) | |
| (C : β n, Block b (width N n)) (parity n : β) : | |
| 0 β€ history b N C parity n := by | |
| apply sum_nonneg | |
| intro j _hj | |
| exact mul_nonneg (epsilon_nonneg hb N j) (C j).code_nonneg | |
| theorem history_le {b N : β} (hb : 2 β€ b) | |
| (C : β n, Block b (width N n)) (parity n : β) : | |
| history b N C parity n β€ β j β range (n + 1), epsilon b N j := by | |
| calc | |
| history b N C parity n β€ | |
| β j β (range (n + 1)).filter (fun j => j % 2 = parity), epsilon b N j := by | |
| apply sum_le_sum | |
| intro j _hj | |
| apply mul_le_of_le_one_right (epsilon_nonneg (by omega) N j) | |
| exact ((C j).code_le hb).trans (tailBound_lt_one hb).le | |
| _ β€ β j β range (n + 1), epsilon b N j := by | |
| apply sum_le_sum_of_subset_of_nonneg (filter_subset _ _) | |
| intro j _hj _ | |
| exact epsilon_nonneg (by omega) N j | |
| theorem history_small {b N : β} (hb : 4 β€ b) | |
| (C : β n, Block b (width N n)) (parity n : β) : | |
| history b N C parity n < 1 / 4 := | |
| ((history_le (by omega) C parity n).trans (epsilon_sum_range_le (by omega) N (n + 1))).trans_lt | |
| (initial_epsilon_small hb N) | |
| theorem history_succ {b N : β} (C : β n, Block b (width N n)) (parity n : β) : | |
| history b N C parity (n + 1) = history b N C parity n + | |
| if (n + 1) % 2 = parity then epsilon b N (n + 1) * (C (n + 1)).code else 0 := by | |
| simp only [history] | |
| rw [range_add_one, filter_insert] | |
| by_cases h : (n + 1) % 2 = parity | |
| Β· simp [h, add_comm] | |
| Β· simp [h] | |
| theorem alternating_histories_step {b N : β} (C : β n, Block b (width N n)) (n : β) : | |
| history b N C (n % 2) (n + 1) = donor b N C n β§ | |
| history b N C ((n + 1) % 2) (n + 1) = history b N C ((n + 1) % 2) n + | |
| epsilon b N (n + 1) * (C (n + 1)).code := by | |
| have hparity : (n + 1) % 2 β n % 2 := by omega | |
| simp [history_succ, hparity, donor] | |
| theorem history_interpolation_mem {b N : β} (hb : 4 β€ b) | |
| (C : β n, Block b (width N n)) (parity n : β) {u : β} (hu : u β Set.Icc 0 1) : | |
| (1 - u) * history b N C parity n + u * history b N C parity (n + 1) β | |
| Set.Ico 0 (1 / 4 : β) := by | |
| have ha0 := history_nonneg (by omega : 0 < b) C parity n | |
| have hb0 := history_nonneg (by omega : 0 < b) C parity (n + 1) | |
| have ha1 := history_small hb C parity n | |
| have hb1 := history_small hb C parity (n + 1) | |
| refine β¨add_nonneg (mul_nonneg (by linarith [hu.2]) ha0) (mul_nonneg hu.1 hb0), ?_β© | |
| have h : (1 - u) * ((1 / 4 : β) - history b N C parity n) + | |
| u * ((1 / 4 : β) - history b N C parity (n + 1)) > 0 := by | |
| rcases hu.1.eq_or_lt with h | h | |
| Β· rw [β h] | |
| simp | |
| linarith | |
| Β· exact add_pos_of_nonneg_of_pos | |
| (mul_nonneg (by linarith [hu.2]) (by linarith)) (mul_pos h (by linarith)) | |
| linarith | |
| end Alternating.Memory | |
| end OAI | |