Download lean/OAI/MathematicalPhysics/NavierStokes/VelocityDetection/ChartRouting.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
theoremcenter_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 Ts : ℝ) :
(center a TSS σ k l s 0∈Icc (0:ℝ) xmax) ∧
(center a TSS σ k l s 1∈Icc lo hi) :=by
proof · 26
lines
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 T1 s)*S*k+theta a T1 s*S*l ∧
(1-theta a T1 s)*S*k+theta a T1 s*S*l ≤ xmax
havehp : 0≤1 - theta a T1 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 T0 s)*S+
(theta a T0 s-theta a T2 s)*privateRow S k+theta a T2 s*σ*S∧
-(1-theta a T0 s)*S+
(theta a T0 s-theta a T2 s)*privateRow S k+theta a T2 s*σ*S≤ hi
havehp : 0≤1-theta a T0 s :=by linarith [(ht 0).2]
havehq : 0≤ theta a T0 s-theta a T2 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).1have 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
theorempath_bounds (Nn : ℕ) (c : A.Instruction n) (hn : n < N) (s : ℝ) :
path AN n c s 0∈Icc (1/4:ℝ) (1/4+1/1024) ∧
path AN n c s 1∈Icc (1/16:ℝ) (1/2) :=by
proof · 21
lines
have hk := scaled_address AN (A.source n c)
((A.source_count n c).trans (count_mono A.K_nonnegA.D_ge_one (by omega)))
have hl := scaled_address AN (A.target n c)
((A.target_count n c).trans (count_mono A.K_nonnegA.D_ge_one (by omega)))
have hS := scale_pos ANhave hsmall := scale_small ANhavehheight : targetHeight AN n c ∈Icc (-(7/16):ℝ) 0:=by
unfold targetHeight
split_ifs <;> constructor <;> linarith
have hh := center_in_rectangle hS.le
(show scale AN * (A.source n c:ℝ) ≤ (1/1024:ℝ) by nlinarith)
(show scale AN * (A.target n c:ℝ) ≤ (1/1024:ℝ) by nlinarith)
(show privateRow (scale AN) (A.source n c) ∈Icc (-(7/16):ℝ) 0by
dsimp [privateRow]; constructor <;> nlinarith [Nat.cast_nonneg (α :=ℝ) (A.source n c)])
(show -scale AN∈Icc (-(7/16):ℝ) 0by constructor <;> linarith)
(show targetHeight AN n c / scale AN * scale AN∈Icc (-(7/16):ℝ) 0by
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]⟩⟩
theoremnonterminal_bounds (Nn : ℕ) (c : A.Instruction n) (hn : n < N)
(hc : A.sign n c = -1) (s : ℝ) :
(1/2-1/1024:ℝ) ≤ path AN n c s 1:=by
proof · 17
lines
have hk := scaled_address AN (A.source n c)
((A.source_count n c).trans (count_mono A.K_nonnegA.D_ge_one (by omega)))
have hl := scaled_address AN (A.target n c)
((A.target_count n c).trans (count_mono A.K_nonnegA.D_ge_one (by omega)))
have hS := scale_pos ANhave hsmall := scale_small ANhavehe : targetHeight AN n c = -scale AN:=by norm_num [targetHeight,hc]
have hh := center_in_rectangle hS.le
(show scale AN * (A.source n c:ℝ) ≤ (1/1024:ℝ) by nlinarith)
(show scale AN * (A.target n c:ℝ) ≤ (1/1024:ℝ) by nlinarith)
(show privateRow (scale AN) (A.source n c) ∈Icc (-(1/1024):ℝ) 0by
dsimp [privateRow]; constructor <;> nlinarith [Nat.cast_nonneg (α :=ℝ) (A.source n c)])
(show -scale AN∈Icc (-(1/1024):ℝ) 0by constructor <;> linarith)
(show targetHeight AN n c / scale AN * scale AN∈Icc (-(1/1024):ℝ) 0by
rw [div_mul_cancel₀ _ (ne_of_gt hS),he]; constructor <;> linarith) (n:ℝ) 1 s
change _ ≤1/2+center _ _ _ _ _ _ _ s 1
linarith [hh.2.1]
unfold stage
apply ContDiff.sum
intro c _
exact TranslationGates.contDiff_movingField _ (contDiff_path AN n c)
((contDiff_infty_iff_deriv.mp (contDiff_path AN n c)).2)
theoremstage_divergence (Nn : ℕ) (s : ℝ) (X : Coord2) :
divergence (stage AN n) s X = 0:=by
proof · 9
lines
unfold stage
rw [divergence_sum]
· apply Finset.sum_eq_zero
intro c _
exact TranslationGates.divergence_field (radius AN) (path AN n c s)
(deriv (path AN n c) s) X
· intro c _ s
exact TranslationGates.contDiff_field (radius AN) (path AN n c s)
(deriv (path AN n c) s)
theorempaths_separated (Nn : ℕ) (c d : A.Instruction n) (hcd : c ≠ d) (s : ℝ) :
∃i : Fin2, 16*radius AN≤ |path AN n c s i - path AN n d s i| :=by
proof · 5
lines
obtain ⟨i,hi⟩ :=CenterPaths.separated (scale_pos AN).le le_rfl (n:ℝ) 1
(targetHeight AN n c / scale AN) (targetHeight AN n d / scale AN) 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₀ _ (bynorm_num : (16:ℝ) ≠0)] using hi
theoremstage_plateau (Nn : ℕ) (c : A.Instruction n) (s : ℝ) (X : Coord2)
(hX : ∀ i, |X i - path AN n c s i| ≤ radius AN) :
stage AN n s X = deriv (path AN n c) s :=by
proof · 3
lines
exact TranslationGates.array_plateau (radius_pos AN)
(fun c => path AN n c s) (fun c => deriv (path AN n c) s)
(fun c _ d _ h => paths_separated AN n c d h s) (Finset.mem_univ c) X hX
theoremstage_support (Nn : ℕ) (hn : n < N) (s : ℝ) (X : Coord2)
(hX : stage AN n s X≠0) : X∈ chartSet :=by
proof · 7
lines
unfold stage at hX
obtain ⟨c,_,hc⟩ :=Finset.exists_ne_zero_of_sum_ne_zero hX
apply path_neighborhood AN n c hn s X
intro i
apply le_of_lt
by_contra hi
exact hc (TranslationGates.field_zero_outside (radius_pos AN) _ _ _ ⟨i,not_lt.mp hi⟩)
theoremprefix_divergence (N : ℕ) (s : ℝ) (X : Coord2) :
divergence (finiteField AN) s X = 0:=by
proof · 7
lines
unfold finiteField
rw [divergence_sum]
· apply Finset.sum_eq_zero
intro n _
exact stage_divergence AN n s X
· intro n _ t
exact contDiff_slice (contDiff_stage AN n) t
theoremprefix_eq_stage (Nn : ℕ) (hn : n < N) {s : ℝ} (hs : s ∈Icc (n:ℝ) (n+1))
(X : Coord2) : finiteField AN s X = stage AN n s X:=by
proof · 11
lines
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 AN k _ Xhavehh : (k:ℝ)+1≤ n :=by exact_mod_cast h
exact hh.trans hs.1
· apply stage_zero_before AN k _ Xhavehh : (n:ℝ)+1≤ k :=by exact_mod_cast h
exact hs.2.trans hh
· exact fun h => (h (Finset.mem_range.mpr hn)).elim
apply HasCompactSupport.of_support_subset_isCompact (isCompact_Icc.prod compact_chartSet)
intro q hq
refine ⟨⟨?_,?_⟩,prefix_support AN q.1 q.2 hq⟩
· exact (lt_of_not_ge (fun h => hq (prefix_zero_before AN h q.2))).le
· exact (lt_of_not_ge (fun h => hq (prefix_zero_after AN h q.2))).le
apply contDiff_extend (C:=1) (contDiff_prefix AN)
intro s X hX i
have hi := chartSet_interior (prefix_support AN s X hX) i
rw [abs_of_pos hi.1]
exact hi.2.le
theoremperiodicPrefix_plateau (Nn : ℕ) (c : A.Instruction n) (hn : n < N)
{s : ℝ} (hs : s ∈Icc (n:ℝ) (n+1)) (X : Coord2)
(hX : ∀ i, |X i - path AN n c s i| ≤ radius AN) :
periodicPrefix AN s X = deriv (path AN n c) s :=by
proof · 5
lines
have hK := path_neighborhood AN n c hn s X
(fun i => (hX i).trans (by linarith [radius_pos AN]))
rw [periodicPrefix_chart AN s (fun i => ⟨(chartSet_interior hK i).1.le,
(chartSet_interior hK i).2.le⟩),prefix_eq_stage AN n hn hs X]
exact stage_plateau AN n c s X hX