import OAI.Analysis.C0Absorption.Weights namespace OAI open Set Filter Topology open scoped NNReal BigOperators ZeroAtInfty open NormedSpace namespace C0Absorption noncomputable section open Set Filter Topology open scoped NNReal BigOperators ZeroAtInfty def boundedAngle (J : ℕ) (u : ℝ) (j : ℕ) : ℝ := if j=0 then Real.pi/2 else if J simp [thetaLog,h] theorem thetaLog_nonneg (J j : ℕ) (u : ℝ) : 0 ≤ thetaLog J u j := by rw [thetaLog_mul] apply mul_nonneg · exact Real.sin_nonneg_of_nonneg_of_le_pi (boundedAngle_range J j u).1 ((boundedAngle_range J j u).2.trans (by linarith [Real.pi_pos])) · exact Real.cos_nonneg_of_neg_pi_div_two_le_of_le (by linarith [(boundedAngle_range J (j+1) u).1,Real.pi_pos]) (boundedAngle_range J (j+1) u).2 theorem thetaLog_le_one (J j : ℕ) (u : ℝ) : thetaLog J u j ≤ 1 := by rcases boundedAngle_dichotomy J j u with h|h · simpa only [thetaLog,h,Real.cos_zero,add_sub_cancel_right] using Real.sin_le_one (boundedAngle J u j) · simpa only [thetaLog,h,Real.sin_pi_div_two,add_sub_cancel_left] using Real.cos_le_one (boundedAngle J u (j+1)) theorem thetaLog_sq (J j : ℕ) (u : ℝ) : thetaLog J u j^2= Real.sin (boundedAngle J u j)^2-Real.sin (boundedAngle J u (j+1))^2 := by rcases boundedAngle_dichotomy J j u with h|h · simp [thetaLog,h] · have hs := Real.sin_sq_add_cos_sq (boundedAngle J u (j+1)) simp only [thetaLog,h,Real.sin_pi_div_two,one_pow] nlinarith theorem sum_range_differences (f : ℕ → ℝ) (n : ℕ) : ∑ j ∈ Finset.range n, (f j-f (j+1))=f 0-f n := by induction n with | zero => simp | succ n ih => rw [Finset.sum_range_succ,ih]; ring theorem thetaLog_squares (J : ℕ) (u : ℝ) : ∑ j : Fin (J+1), thetaLog J u j^2=1 := by simp_rw [thetaLog_sq] rw [Fin.sum_univ_eq_sum_range (fun j => Real.sin (boundedAngle J u j)^2-Real.sin (boundedAngle J u (j+1))^2),sum_range_differences] simp theorem transitionAngle_unique (u : ℝ) : Set.Subsingleton {j | transitionAngle j u ≠ 0 ∧ transitionAngle j u ≠ Real.pi/2} := by intro i hi j hj by_contra hij have mem (k : ℕ) (hk : transitionAngle k u ≠ 0 ∧ transitionAngle k u ≠ Real.pi/2) : u ∈ transitionInterval k := by constructor · by_contra hn exact hk.2 (transitionAngle_full k (by linarith)) · by_contra hn exact hk.1 (transitionAngle_zero k (by linarith)) exact Set.disjoint_left.mp (transitionInterval_disjoint hij) (mem i hi) (mem j hj) theorem thetaLog_sum_formula (J : ℕ) (u : ℝ) : (∑ j : Fin (J+1),thetaLog J u j)=1+ ∑ j : Fin J, (Real.sin (transitionAngle (j+1) u)+Real.cos (transitionAngle (j+1) u)-1) := by rw [Fin.sum_univ_eq_sum_range (thetaLog J u),Fin.sum_univ_eq_sum_range (fun j => Real.sin (transitionAngle (j+1) u)+Real.cos (transitionAngle (j+1) u)-1)] simp only [thetaLog,Finset.sum_sub_distrib,Finset.sum_add_distrib,Finset.sum_const, Finset.card_range,nsmul_eq_mul,mul_one] rw [Finset.sum_range_succ' (fun j => Real.sin (boundedAngle J u j)), Finset.sum_range_succ (fun j => Real.cos (boundedAngle J u (j+1)))] simp only [boundedAngle_zero,boundedAngle_last,Real.sin_pi_div_two,Real.cos_zero] have hs : (∑ j ∈ Finset.range J,Real.sin (boundedAngle J u (j+1)))= ∑ j ∈ Finset.range J,Real.sin (transitionAngle (j+1) u) := by apply Finset.sum_congr rfl intro j hj rw [boundedAngle_inner (by omega) (by have := Finset.mem_range.mp hj; omega)] have hc : (∑ j ∈ Finset.range J,Real.cos (boundedAngle J u (j+1)))= ∑ j ∈ Finset.range J,Real.cos (transitionAngle (j+1) u) := by apply Finset.sum_congr rfl intro j hj rw [boundedAngle_inner (by omega) (by have := Finset.mem_range.mp hj; omega)] rw [hs,hc] push_cast ring theorem thetaLog_sum_le (J : ℕ) (u : ℝ) : (∑ j : Fin (J+1),thetaLog J u j) ≤ 2 := by classical rw [thetaLog_sum_formula] let f (j : Fin J) := Real.sin (transitionAngle (j+1) u)+Real.cos (transitionAngle (j+1) u)-1 have hz (j : Fin J) (hj : transitionAngle (j+1) u=0 ∨ transitionAngle (j+1) u=Real.pi/2) : f j=0 := by rcases hj with h|h <;> simp [f,h] suffices (∑ j,f j) ≤ 1 by linarith by_cases h : ∃ j : Fin J, transitionAngle (j+1) u≠0 ∧ transitionAngle (j+1) u≠Real.pi/2 · obtain ⟨j,hj⟩ := h rw [Finset.sum_eq_single j] · dsimp [f] linarith [Real.sin_le_one (transitionAngle (j+1) u),Real.cos_le_one (transitionAngle (j+1) u)] · intro k _ hkj apply hz by_contra hh push Not at hh exact hkj (Fin.ext (by have he := transitionAngle_unique u hh hj; omega)) · simp · have hh (j : Fin J) : f j=0 := by apply hz have hn := not_exists.mp h j tauto simp only [hh,Finset.sum_const_zero,zero_le_one] theorem boundedAngle_difference_sum (J : ℕ) (u v : ℝ) : (∑ j : Fin (J+1), (|boundedAngle J u j-boundedAngle J v j|+ |boundedAngle J u (j+1)-boundedAngle J v (j+1)|)) = 2*∑ j : Fin J, |transitionAngle (j+1) u-transitionAngle (j+1) v| := by simp only [Finset.sum_add_distrib] rw [Fin.sum_univ_eq_sum_range (fun j => |boundedAngle J u j-boundedAngle J v j|), Fin.sum_univ_eq_sum_range (fun j => |boundedAngle J u (j+1)-boundedAngle J v (j+1)|), Fin.sum_univ_eq_sum_range (fun j => |transitionAngle (j+1) u-transitionAngle (j+1) v|), Finset.sum_range_succ' (fun j => |boundedAngle J u j-boundedAngle J v j|), Finset.sum_range_succ (fun j => |boundedAngle J u (j+1)-boundedAngle J v (j+1)|)] simp only [boundedAngle_zero,boundedAngle_last,sub_self,abs_zero,add_zero] have hh : (∑ j ∈ Finset.range J,|boundedAngle J u (j+1)-boundedAngle J v (j+1)|)= ∑ j ∈ Finset.range J,|transitionAngle (j+1) u-transitionAngle (j+1) v| := by apply Finset.sum_congr rfl intro j hj rw [boundedAngle_inner (by omega) (by have := Finset.mem_range.mp hj; omega), boundedAngle_inner (by omega) (by have := Finset.mem_range.mp hj; omega)] rw [hh] ring theorem thetaLog_distance (J : ℕ) (u v : ℝ) : (∑ j : Fin (J+1), |thetaLog J u j-thetaLog J v j|) ≤ (Real.pi/scheduleH)*dist u v := by calc _ ≤ ∑ j : Fin (J+1), (|boundedAngle J u j-boundedAngle J v j|+ |boundedAngle J u (j+1)-boundedAngle J v (j+1)|) := by apply Finset.sum_le_sum intro j _ have he : thetaLog J u j-thetaLog J v j = (Real.sin (boundedAngle J u j)-Real.sin (boundedAngle J v j))+ (Real.cos (boundedAngle J u (j+1))-Real.cos (boundedAngle J v (j+1))) := by unfold thetaLog; ring rw [he] refine (abs_add_le _ _).trans (add_le_add ?_ ?_) · simpa only [NNReal.coe_one,one_mul,Real.dist_eq] using Real.lipschitzWith_sin.dist_le_mul (boundedAngle J u j) (boundedAngle J v j) · simpa only [NNReal.coe_one,one_mul,Real.dist_eq] using Real.lipschitzWith_cos.dist_le_mul (boundedAngle J u (j+1)) (boundedAngle J v (j+1)) _ = 2*∑ j : Fin J,|transitionAngle (j+1) u-transitionAngle (j+1) v| := boundedAngle_difference_sum J u v _ ≤ 2*(angleSpeed*dist u v) := mul_le_mul_of_nonneg_left (angle_sum_distance J u v) (by norm_num) _ = (Real.pi/scheduleH)*dist u v := by change 2*(Real.pi/(2*scheduleH)*dist u v)=_; ring end end C0Absorption namespace C0Absorption noncomputable section open Set Filter Topology open scoped NNReal BigOperators ZeroAtInfty def theta (J : ℕ) (r : ℝ) (j : ℕ) : ℝ := if r≤0 then if j=J then 1 else 0 else thetaLog J (Real.log r) j theorem theta_nonneg (J j : ℕ) (r : ℝ) : 0 ≤ theta J r j := by unfold theta split_ifs <;> first | exact thetaLog_nonneg J j _ | norm_num theorem theta_le_one (J j : ℕ) (r : ℝ) : theta J r j ≤ 1 := by unfold theta split_ifs <;> first | exact thetaLog_le_one J j _ | norm_num theorem theta_squares (J : ℕ) (r : ℝ) : (∑ j : Fin (J+1),theta J r j^2)=1 := by classical by_cases hr : r≤0 · simp only [theta,hr,↓reduceIte,ite_pow,one_pow,zero_pow (two_ne_zero)] have he (j : Fin (J+1)) : (j.val=J) ↔ j=Fin.last J := by simp only [Fin.ext_iff,Fin.val_last] simp only [he,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte] · simp only [theta,hr,↓reduceIte] exact thetaLog_squares J _ theorem theta_sum_le (J : ℕ) (r : ℝ) : (∑ j : Fin (J+1),theta J r j) ≤ 2 := by classical by_cases hr : r≤0 · simp only [theta,hr,↓reduceIte] have he (j : Fin (J+1)) : (j.val=J) ↔ j=Fin.last J := by simp only [Fin.ext_iff,Fin.val_last] simp only [he,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte] norm_num · simp only [theta,hr,↓reduceIte] exact thetaLog_sum_le J _ theorem log_radius_lower {r : ℝ} (hr : 0 boundedAngle J u j) := by unfold boundedAngle split_ifs · exact continuous_const · exact continuous_const · exact (transitionAngle_lipschitz j).continuous theorem thetaLog_continuous (J j : ℕ) : Continuous (fun u => thetaLog J u j) := ((Real.continuous_sin.comp (boundedAngle_continuous J j)).add (Real.continuous_cos.comp (boundedAngle_continuous J (j+1)))).sub continuous_const theorem theta_continuous (J j : ℕ) : Continuous (fun r => theta J r j) := by rw [continuous_iff_continuousAt] intro r by_cases hr : 0