Download data/lean/OAI/MathematicalPhysics/NavierStokes/VelocityDetection/ChartRouting.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.6 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/NavierStokes/VelocityDetection/ChartRouting.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/MathematicalPhysics/NavierStokes/VelocityDetection/ChartRouting.lean
-
curl -L -o ChartRouting.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/NavierStokes/VelocityDetection/ChartRouting.lean
15.6 kB
| import OAI.MathematicalPhysics.NavierStokes.VelocityDetection.HistoryRouting | |
| import OAI.MathematicalPhysics.NavierStokes.VelocityDetection.Periodization | |
| namespace OAI | |
| noncomputable section | |
| namespace VelocityDetection.ChartRouting | |
| open Set Function Filter MeasureTheory | |
| open scoped Topology ContDiff BigOperators | |
| open Expanding CenterPaths SpatialCalculus | |
| variable (A : RoutingData) | |
| def scale (N : β) : β := (1024 * (count A.K A.D (N+1) + 4))β»ΒΉ | |
| theorem scale_pos (N : β) : 0 < scale A N := by | |
| have hd : 0 β€ count A.K A.D (N+1) := by | |
| unfold count | |
| exact mul_nonneg A.K_nonneg (pow_nonneg (by linarith [A.D_ge_one]) _) | |
| unfold scale | |
| positivity | |
| theorem scale_small (N : β) : scale A N β€ (1/4096 : β) := by | |
| have hd : 0 β€ count A.K A.D (N+1) := by | |
| unfold count | |
| exact mul_nonneg A.K_nonneg (pow_nonneg (by linarith [A.D_ge_one]) _) | |
| change (1024 * (count A.K A.D (N+1) + 4))β»ΒΉ β€ _ | |
| have hp : 0 < 1024 * (count A.K A.D (N+1) + 4) := by positivity | |
| rw [inv_eq_one_div] | |
| apply (div_le_iffβ hp).mpr | |
| nlinarith | |
| theorem scaled_address (N k : β) (hk : (k:β) β€ count A.K A.D (N+1)) : | |
| scale A N * ((k:β)+2) β€ (1/1024 : β) := by | |
| have hh : scale A N * (count A.K A.D (N+1)+4) = (1/1024:β) := by | |
| unfold scale | |
| have hp : 0 < count A.K A.D (N+1)+4 := by | |
| have hd : 0 β€ count A.K A.D (N+1) := by | |
| unfold count | |
| exact mul_nonneg A.K_nonneg (pow_nonneg (by linarith [A.D_ge_one]) _) | |
| linarith | |
| field_simp | |
| rw [β hh] | |
| exact mul_le_mul_of_nonneg_left (by linarith) (scale_pos A N).le | |
| def origin : Coord 2 := ![1/4,1/2] | |
| def targetHeight (N n : β) (c : A.Instruction n) : β := | |
| if A.sign n c = 1 then -(7/16:β) else -scale A N | |
| def path (N n : β) (c : A.Instruction n) (s : β) : Coord 2 := | |
| origin + center (n:β) 1 (scale A N) (scale A N) | |
| (targetHeight A N n c / scale A N) (A.source n c) (A.target n c) s | |
| @[fun_prop] theorem contDiff_path (N n : β) (c : A.Instruction n) : | |
| ContDiff β β (path A N n c) := by unfold path; fun_prop | |
| theorem path_source (N n : β) (c : A.Instruction n) {s : β} (hs : s β€ n) : | |
| path A N n c s = origin + ![scale A N * A.source n c,-scale A N] := by | |
| unfold path | |
| rw [center_source_collar] | |
| norm_num only [div_one] | |
| linarith | |
| theorem path_target (N n : β) (c : A.Instruction n) {s : β} (hs : n+1 β€ s) : | |
| path A N n c s = origin + ![scale A N * A.target n c,targetHeight A N n c] := by | |
| unfold path | |
| rw [center_target_collar] | |
| Β· rw [div_mul_cancelβ _ (ne_of_gt (scale_pos A N))] | |
| Β· norm_num only [div_one] | |
| linarith | |
| theorem velocity_source (N n : β) (c : A.Instruction n) {s : β} (hs : s β€ n) : | |
| deriv (path A N n c) s = 0 := by | |
| unfold path | |
| rw [deriv_const_add] | |
| Β· exact velocity_source_collar _ _ (by norm_num only [div_one]; linarith) | |
| theorem velocity_target (N n : β) (c : A.Instruction n) {s : β} (hs : n+1 β€ s) : | |
| deriv (path A N n c) s = 0 := by | |
| unfold path | |
| rw [deriv_const_add] | |
| Β· exact velocity_target_collar _ _ (by norm_num only [div_one]; linarith) | |
| theorem theta_order (a T s : β) : theta a T 2 s β€ theta a T 0 s := by | |
| unfold theta ramp | |
| exact Real.smoothTransition.monotone (by norm_num only [Nat.cast_ofNat, Nat.cast_zero]; linarith) | |
| theorem center_in_rectangle {S Ο lo hi xmax : β} {k l : β} | |
| (hS0 : 0 β€ S) (hk : S * k β€ xmax) (hl : S * l β€ xmax) | |
| (hrow : privateRow S k β Icc lo hi) (hsource : -S β Icc lo hi) | |
| (htarget : Ο*S β Icc lo hi) (a T s : β) : | |
| (center a T S S Ο k l s 0 β Icc (0:β) xmax) β§ | |
| (center a T S S Ο k l s 1 β Icc lo hi) := by | |
| have ht (j : β) : theta a T j s β Icc (0:β) 1 := | |
| β¨ramp_nonneg _, ramp_le_one _β© | |
| have hm := theta_order a T s | |
| constructor | |
| Β· change 0 β€ (1-theta a T 1 s)*S*k+theta a T 1 s*S*l β§ | |
| (1-theta a T 1 s)*S*k+theta a T 1 s*S*l β€ xmax | |
| have hp : 0 β€ 1 - theta a T 1 s := by linarith [(ht 1).2] | |
| constructor | |
| Β· exact add_nonneg (mul_nonneg (mul_nonneg hp hS0) (Nat.cast_nonneg _)) | |
| (mul_nonneg (mul_nonneg (ht 1).1 hS0) (Nat.cast_nonneg _)) | |
| Β· have hβ := mul_le_mul_of_nonneg_left hk hp | |
| have hβ := mul_le_mul_of_nonneg_left hl (ht 1).1 | |
| nlinarith | |
| Β· change lo β€ -(1-theta a T 0 s)*S+ | |
| (theta a T 0 s-theta a T 2 s)*privateRow S k+theta a T 2 s*Ο*S β§ | |
| -(1-theta a T 0 s)*S+ | |
| (theta a T 0 s-theta a T 2 s)*privateRow S k+theta a T 2 s*Ο*S β€ hi | |
| have hp : 0 β€ 1-theta a T 0 s := by linarith [(ht 0).2] | |
| have hq : 0 β€ theta a T 0 s-theta a T 2 s := sub_nonneg.mpr hm | |
| have hβ := mul_le_mul_of_nonneg_left hsource.1 hp | |
| have hβ := mul_le_mul_of_nonneg_left hrow.1 hq | |
| have hβ := mul_le_mul_of_nonneg_left htarget.1 (ht 2).1 | |
| have hβ := mul_le_mul_of_nonneg_left hsource.2 hp | |
| have hβ := mul_le_mul_of_nonneg_left hrow.2 hq | |
| have hβ := mul_le_mul_of_nonneg_left htarget.2 (ht 2).1 | |
| constructor <;> nlinarith | |
| theorem path_bounds (N n : β) (c : A.Instruction n) (hn : n < N) (s : β) : | |
| path A N n c s 0 β Icc (1/4:β) (1/4+1/1024) β§ | |
| path A N n c s 1 β Icc (1/16:β) (1/2) := by | |
| have hk := scaled_address A N (A.source n c) | |
| ((A.source_count n c).trans (count_mono A.K_nonneg A.D_ge_one (by omega))) | |
| have hl := scaled_address A N (A.target n c) | |
| ((A.target_count n c).trans (count_mono A.K_nonneg A.D_ge_one (by omega))) | |
| have hS := scale_pos A N | |
| have hsmall := scale_small A N | |
| have hheight : targetHeight A N n c β Icc (-(7/16):β) 0 := by | |
| unfold targetHeight | |
| split_ifs <;> constructor <;> linarith | |
| have hh := center_in_rectangle hS.le | |
| (show scale A N * (A.source n c:β) β€ (1/1024:β) by nlinarith) | |
| (show scale A N * (A.target n c:β) β€ (1/1024:β) by nlinarith) | |
| (show privateRow (scale A N) (A.source n c) β Icc (-(7/16):β) 0 by | |
| dsimp [privateRow]; constructor <;> nlinarith [Nat.cast_nonneg (Ξ± := β) (A.source n c)]) | |
| (show -scale A N β Icc (-(7/16):β) 0 by constructor <;> linarith) | |
| (show targetHeight A N n c / scale A N * scale A N β Icc (-(7/16):β) 0 by | |
| rwa [div_mul_cancelβ _ (ne_of_gt hS)]) (n:β) 1 s | |
| change 1/4+center _ _ _ _ _ _ _ s 0 β Icc _ _ β§ | |
| 1/2+center _ _ _ _ _ _ _ s 1 β Icc _ _ | |
| exact β¨β¨by linarith [hh.1.1],by linarith [hh.1.2]β©, | |
| β¨by linarith [hh.2.1],by linarith [hh.2.2]β©β© | |
| theorem nonterminal_bounds (N n : β) (c : A.Instruction n) (hn : n < N) | |
| (hc : A.sign n c = -1) (s : β) : | |
| (1/2-1/1024:β) β€ path A N n c s 1 := by | |
| have hk := scaled_address A N (A.source n c) | |
| ((A.source_count n c).trans (count_mono A.K_nonneg A.D_ge_one (by omega))) | |
| have hl := scaled_address A N (A.target n c) | |
| ((A.target_count n c).trans (count_mono A.K_nonneg A.D_ge_one (by omega))) | |
| have hS := scale_pos A N | |
| have hsmall := scale_small A N | |
| have he : targetHeight A N n c = -scale A N := by norm_num [targetHeight,hc] | |
| have hh := center_in_rectangle hS.le | |
| (show scale A N * (A.source n c:β) β€ (1/1024:β) by nlinarith) | |
| (show scale A N * (A.target n c:β) β€ (1/1024:β) by nlinarith) | |
| (show privateRow (scale A N) (A.source n c) β Icc (-(1/1024):β) 0 by | |
| dsimp [privateRow]; constructor <;> nlinarith [Nat.cast_nonneg (Ξ± := β) (A.source n c)]) | |
| (show -scale A N β Icc (-(1/1024):β) 0 by constructor <;> linarith) | |
| (show targetHeight A N n c / scale A N * scale A N β Icc (-(1/1024):β) 0 by | |
| rw [div_mul_cancelβ _ (ne_of_gt hS),he]; constructor <;> linarith) (n:β) 1 s | |
| change _ β€ 1/2+center _ _ _ _ _ _ _ s 1 | |
| linarith [hh.2.1] | |
| def radius (N : β) : β := scale A N / 16 | |
| theorem radius_pos (N : β) : 0 < radius A N := div_pos (scale_pos A N) (by norm_num) | |
| def stage (N n : β) : VectorField 2 := fun s X => | |
| β c : A.Instruction n, TranslationGates.field (radius A N) | |
| (path A N n c s) (deriv (path A N n c) s) X | |
| @[fun_prop] theorem contDiff_stage (N n : β) : ContDiff β β (uncurry (stage A N n)) := by | |
| unfold stage | |
| apply ContDiff.sum | |
| intro c _ | |
| exact TranslationGates.contDiff_movingField _ (contDiff_path A N n c) | |
| ((contDiff_infty_iff_deriv.mp (contDiff_path A N n c)).2) | |
| theorem stage_zero_before (N n : β) {s : β} (hs : s β€ n) (X : Coord 2) : | |
| stage A N n s X = 0 := by | |
| unfold stage | |
| apply Finset.sum_eq_zero | |
| intro c _ | |
| rw [velocity_source A N n c hs,TranslationGates.field_zero_velocity] | |
| theorem stage_zero_after (N n : β) {s : β} (hs : n+1 β€ s) (X : Coord 2) : | |
| stage A N n s X = 0 := by | |
| unfold stage | |
| apply Finset.sum_eq_zero | |
| intro c _ | |
| rw [velocity_target A N n c hs,TranslationGates.field_zero_velocity] | |
| theorem stage_divergence (N n : β) (s : β) (X : Coord 2) : | |
| divergence (stage A N n) s X = 0 := by | |
| unfold stage | |
| rw [divergence_sum] | |
| Β· apply Finset.sum_eq_zero | |
| intro c _ | |
| exact TranslationGates.divergence_field (radius A N) (path A N n c s) | |
| (deriv (path A N n c) s) X | |
| Β· intro c _ s | |
| exact TranslationGates.contDiff_field (radius A N) (path A N n c s) | |
| (deriv (path A N n c) s) | |
| theorem paths_separated (N n : β) (c d : A.Instruction n) (hcd : c β d) (s : β) : | |
| β i : Fin 2, 16*radius A N β€ |path A N n c s i - path A N n d s i| := by | |
| obtain β¨i,hiβ© := CenterPaths.separated (scale_pos A N).le le_rfl (n:β) 1 | |
| (targetHeight A N n c / scale A N) (targetHeight A N n d / scale A N) s | |
| ((A.source_injective n).ne hcd) ((A.target_injective n).ne hcd) | |
| refine β¨i,?_β© | |
| simpa only [path,Pi.add_apply,add_sub_add_left_eq_sub,radius,mul_div_cancelβ _ (by norm_num : (16:β) β 0)] using hi | |
| theorem stage_plateau (N n : β) (c : A.Instruction n) (s : β) (X : Coord 2) | |
| (hX : β i, |X i - path A N n c s i| β€ radius A N) : | |
| stage A N n s X = deriv (path A N n c) s := by | |
| exact TranslationGates.array_plateau (radius_pos A N) | |
| (fun c => path A N n c s) (fun c => deriv (path A N n c) s) | |
| (fun c _ d _ h => paths_separated A N n c d h s) (Finset.mem_univ c) X hX | |
| end VelocityDetection.ChartRouting | |
| end | |
| noncomputable section | |
| namespace VelocityDetection.ChartRouting | |
| open Set Function Filter MeasureTheory | |
| open scoped Topology ContDiff BigOperators | |
| open Expanding CenterPaths SpatialCalculus Periodization | |
| variable (A : RoutingData) | |
| def chartSet : Set (Coord 2) := Icc ![1/8,1/32] ![3/8,3/4] | |
| theorem compact_chartSet : IsCompact chartSet := isCompact_Icc | |
| theorem chartSet_interior {X : Coord 2} (hX : X β chartSet) : | |
| β i, X i β Ioo (0:β) 1 := by | |
| intro i | |
| fin_cases i | |
| Β· have hβ := hX.1 (0 : Fin 2) | |
| have hβ := hX.2 (0 : Fin 2) | |
| norm_num only [Matrix.cons_val_zero] at hβ hβ | |
| change 0 < X 0 β§ X 0 < 1 | |
| constructor <;> linarith | |
| Β· have hβ := hX.1 (1 : Fin 2) | |
| have hβ := hX.2 (1 : Fin 2) | |
| norm_num only [Matrix.cons_val_one, Matrix.cons_val_zero] at hβ hβ | |
| change 0 < X 1 β§ X 1 < 1 | |
| constructor <;> linarith | |
| theorem path_neighborhood (N n : β) (c : A.Instruction n) (hn : n < N) | |
| (s : β) (X : Coord 2) (hX : β i, |X i-path A N n c s i| β€ 3*radius A N) : | |
| X β chartSet := by | |
| have hb := path_bounds A N n c hn s | |
| have hR : 3*radius A N β€ (3/65536:β) := by | |
| unfold radius | |
| linarith [scale_small A N] | |
| have hx := abs_le.mp (hX 0) | |
| have hy := abs_le.mp (hX 1) | |
| constructor <;> intro i <;> fin_cases i | |
| Β· change (1/8:β) β€ X 0 | |
| linarith [hb.1.1] | |
| Β· change (1/32:β) β€ X 1 | |
| linarith [hb.2.1] | |
| Β· change X 0 β€ (3/8:β) | |
| linarith [hb.1.2] | |
| Β· change X 1 β€ (3/4:β) | |
| linarith [hb.2.2] | |
| theorem stage_support (N n : β) (hn : n < N) (s : β) (X : Coord 2) | |
| (hX : stage A N n s X β 0) : X β chartSet := by | |
| unfold stage at hX | |
| obtain β¨c,_,hcβ© := Finset.exists_ne_zero_of_sum_ne_zero hX | |
| apply path_neighborhood A N n c hn s X | |
| intro i | |
| apply le_of_lt | |
| by_contra hi | |
| exact hc (TranslationGates.field_zero_outside (radius_pos A N) _ _ _ β¨i,not_lt.mp hiβ©) | |
| def finiteField (N : β) : VectorField 2 := fun s X => β n β Finset.range N, stage A N n s X | |
| @[fun_prop] theorem contDiff_prefix (N : β) : ContDiff β β (uncurry (finiteField A N)) := by | |
| unfold finiteField | |
| exact ContDiff.sum (fun n _ => contDiff_stage A N n) | |
| theorem prefix_divergence (N : β) (s : β) (X : Coord 2) : | |
| divergence (finiteField A N) s X = 0 := by | |
| unfold finiteField | |
| rw [divergence_sum] | |
| Β· apply Finset.sum_eq_zero | |
| intro n _ | |
| exact stage_divergence A N n s X | |
| Β· intro n _ t | |
| exact contDiff_slice (contDiff_stage A N n) t | |
| theorem prefix_support (N : β) (s : β) (X : Coord 2) (hX : finiteField A N s X β 0) : | |
| X β chartSet := by | |
| unfold finiteField at hX | |
| obtain β¨n,hn,hβ© := Finset.exists_ne_zero_of_sum_ne_zero hX | |
| exact stage_support A N n (Finset.mem_range.mp hn) s X h | |
| theorem prefix_zero_before (N : β) {s : β} (hs : s β€ 0) (X : Coord 2) : | |
| finiteField A N s X = 0 := by | |
| unfold finiteField | |
| apply Finset.sum_eq_zero | |
| intro n _ | |
| exact stage_zero_before A N n (hs.trans (Nat.cast_nonneg _)) X | |
| theorem prefix_zero_after (N : β) {s : β} (hs : N β€ s) (X : Coord 2) : | |
| finiteField A N s X = 0 := by | |
| unfold finiteField | |
| apply Finset.sum_eq_zero | |
| intro n hn | |
| apply stage_zero_after A N n _ X | |
| have h : (n:β)+1 β€ N := by exact_mod_cast Finset.mem_range.mp hn | |
| exact h.trans hs | |
| theorem prefix_eq_stage (N n : β) (hn : n < N) {s : β} (hs : s β Icc (n:β) (n+1)) | |
| (X : Coord 2) : finiteField A N s X = stage A N n s X := by | |
| unfold finiteField | |
| apply Finset.sum_eq_single n | |
| Β· intro k _ hkn | |
| rcases lt_or_gt_of_ne hkn with h | h | |
| Β· apply stage_zero_after A N k _ X | |
| have hh : (k:β)+1 β€ n := by exact_mod_cast h | |
| exact hh.trans hs.1 | |
| Β· apply stage_zero_before A N k _ X | |
| have hh : (n:β)+1 β€ k := by exact_mod_cast h | |
| exact hs.2.trans hh | |
| Β· exact fun h => (h (Finset.mem_range.mpr hn)).elim | |
| theorem compactSupport_prefix (N : β) : HasCompactSupport (uncurry (finiteField A N)) := by | |
| apply HasCompactSupport.of_support_subset_isCompact (isCompact_Icc.prod compact_chartSet) | |
| intro q hq | |
| refine β¨β¨?_,?_β©,prefix_support A N q.1 q.2 hqβ© | |
| Β· exact (lt_of_not_ge (fun h => hq (prefix_zero_before A N h q.2))).le | |
| Β· exact (lt_of_not_ge (fun h => hq (prefix_zero_after A N h q.2))).le | |
| def periodicPrefix (N : β) : VectorField 2 := Periodization.extend (finiteField A N) | |
| @[fun_prop] theorem contDiff_periodicPrefix (N : β) : | |
| ContDiff β β (uncurry (periodicPrefix A N)) := by | |
| apply contDiff_extend (C := 1) (contDiff_prefix A N) | |
| intro s X hX i | |
| have hi := chartSet_interior (prefix_support A N s X hX) i | |
| rw [abs_of_pos hi.1] | |
| exact hi.2.le | |
| theorem periodic_periodicPrefix (N : β) (s : β) : | |
| FactorsThrough (periodicPrefix A N s) PeriodicSpace.cover := periodic_extend _ _ | |
| theorem periodicPrefix_chart (N : β) (s : β) {X : Coord 2} | |
| (hX : β i, X i β Icc (0:β) 1) : periodicPrefix A N s X = finiteField A N s X := by | |
| apply extend_eq_chart _ s hX | |
| intro t Y hY | |
| exact chartSet_interior (prefix_support A N t Y hY) | |
| theorem periodicPrefix_plateau (N n : β) (c : A.Instruction n) (hn : n < N) | |
| {s : β} (hs : s β Icc (n:β) (n+1)) (X : Coord 2) | |
| (hX : β i, |X i - path A N n c s i| β€ radius A N) : | |
| periodicPrefix A N s X = deriv (path A N n c) s := by | |
| have hK := path_neighborhood A N n c hn s X | |
| (fun i => (hX i).trans (by linarith [radius_pos A N])) | |
| rw [periodicPrefix_chart A N s (fun i => β¨(chartSet_interior hK i).1.le, | |
| (chartSet_interior hK i).2.leβ©),prefix_eq_stage A N n hn hs X] | |
| exact stage_plateau A N n c s X hX | |
| end VelocityDetection.ChartRouting | |
| end | |
| end OAI | |