import Mathlib import OAI.Analysis.Conductivity.Fourier.RectangularTorusInverse import OAI.Analysis.Conductivity.Geometry.BoxEnergyPoincare namespace OAI noncomputable section namespace ScalarConductivity open Set MeasureTheory lemma sourceCollarPiece_radial_pos (i j : Fin 4) {x : Fin 3 → ℝ} (hr : 0≤ sourceCollarRadius j (x 0) (x 2)) (ha : |x 1|≤1) : sourceRadial (sourceCollarPiece i j x)=sourceCollarRadius j (x 0) (x 2) := by have hL : 0 linarith lemma sourceExtendedBox_injOn (i j : Fin 4) {l r : ℝ} (hl : -(1:ℝ)/100≤l) (hr : r≤1/100) : InjOn (sourceCollarPiece i j) (sourceExtendedBox l r) := by have hi (x : Fin 3 → ℝ) (hx : x∈sourceExtendedBox l r) : sourceCollarInverse i j (sourceCollarPiece i j x)=x := by obtain ⟨ht,ha,hb⟩ := mem_sourceExtendedBox.mp hx exact sourceCollarInverse_left_pos i j (lt_of_lt_of_le (by norm_num : (0:ℝ)<1/50) (sourceCollarRadius_extended j ⟨hl.trans ht.1,ht.2.trans hr⟩ hb).1) (by linarith [ht.2]) ha hb intro x hx y hy he apply_fun sourceCollarInverse i j at he rwa [hi x hx,hi y hy] at he lemma sourceExtended_jacobian_lower (i j : Fin 4) {l r : ℝ} (hl : -(1:ℝ)/100≤l) (hr : r≤1/100) {x : Fin 3 → ℝ} (hx : x∈sourceExtendedBox l r) : (1:ℝ)/100≤abs ((sourceCollarDerivative i j x).det) := by obtain ⟨ht,ha,hb⟩ := mem_sourceExtendedBox.mp hx have ht' : x 0∈Icc (-(1:ℝ)/100) (1/100) := ⟨hl.trans ht.1,ht.2.trans hr⟩ have hR := (sourceCollarRadius_extended j ht' hb).1 rw [sourceCollarDerivative_det] have he : -sourceLength*sourceCollarRadius j (x 0) (x 2)*sourceRadialWidth*(1-x 0)= -(sourceLength*sourceCollarRadius j (x 0) (x 2)*sourceRadialWidth*(1-x 0)) := by ring rw [he,abs_neg,abs_of_nonneg (by have : 0≤ sourceCollarRadius j (x 0) (x 2) := by linarith have : 0≤1-x 0 := by linarith [ht'.2] norm_num [sourceLength,sourceRadialWidth,sourceHole]; positivity)] have hh := mul_le_mul hR (show (99:ℝ)/100≤1-x 0 by linarith [ht'.2]) (by norm_num : (0:ℝ)≤99/100) (by linarith : 0≤ sourceCollarRadius j (x 0) (x 2)) norm_num [sourceLength,sourceRadialWidth,sourceHole] nlinarith theorem sourceExtended_integral {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] (i j : Fin 4) {l r : ℝ} (hl : -(1:ℝ)/100≤l) (hr : r≤1/100) (g : (Fin 3 → ℝ) → F) : (∫ y in sourceCollarPiece i j '' sourceExtendedBox l r,g y)= ∫ x in sourceExtendedBox l r,abs ((sourceCollarDerivative i j x).det) • g (sourceCollarPiece i j x) := by exact integral_image_eq_integral_abs_det_fderiv_smul volume measurableSet_Icc (fun x _ => (sourceCollarPiece_hasFDeriv i j x).hasFDerivWithinAt) (sourceExtendedBox_injOn i j hl hr) g lemma squareFace_abs_le (i : Fin 4) {a : ℝ} (ha : |a|≤1) (k : Fin 2) : |squareFace i a k|≤1 := by fin_cases k · exact (le_max_left _ _).trans (squareFace_max i ha).le · exact (le_max_right _ _).trans (squareFace_max i ha).le lemma sourceRadius_trim_bounds (j : Fin 4) {t b : ℝ} (ht : centralThickness≤t ∧ t≤2*centralThickness) (hb : |b|≤1) : centralInnerY≤ sourceCollarRadius j t b ∧ sourceCollarRadius j t b≤centralOuterY := by have hq := squareFace_abs_le j hb 0 have hqt : |(1-t)*squareFace j b 0|≤1-centralThickness := by have ht0 : 0≤1-t := by norm_num [centralThickness] at ht; linarith rw [abs_mul,abs_of_nonneg ht0] have hh := mul_le_mul_of_nonneg_left hq ht0 linarith [ht.1] have hh := abs_le.mp hqt dsimp [sourceCollarRadius,centralInnerY,centralOuterY,sourceRadialCenter,sourceRadialWidth,sourceHole,centralThickness] at * constructor <;> linarith def sourcePairCoordinates (y : Fin 3 → ℝ) : Box3 := ((y 0,y 1),y 2) lemma sourceParentCollar_parent (i j : Fin 4) {x : Fin 3 → ℝ} (hx : x∈sourceExtendedBox centralThickness (2*centralThickness)) : centralParentFootprint (sourcePairCoordinates (sourceCollarPiece i j x)).1 ∧ |(sourcePairCoordinates (sourceCollarPiece i j x)).2|≤centralHeight := by obtain ⟨ht,ha,hb⟩ := mem_sourceExtendedBox.mp hx have hr := sourceRadius_trim_bounds j ht hb have hr0 : 0≤ sourceCollarRadius j (x 0) (x 2) := by have hh : 0 apply Or.inl · norm_num [centralChildOuterX,sourceScale,sourceRadialWidth,sourceHole,centralThickness,sourceOffset] at * linarith · norm_num [centralChildOuterX,sourceScale,sourceRadialWidth,sourceHole,centralThickness,sourceOffset] at * linarith · have he : |(sourceCollarPiece i 0 x) 1|=sourceCollarRadius 0 (x 0) (x 2) := by simp only [sourceCollarPiece,Matrix.cons_val_one,Matrix.cons_val_zero,abs_mul,abs_of_nonneg hr0] rw [←h.1,hm,mul_one] have hh : centralChildOuterY≤|(sourceCollarPiece i 0 x) 1| := by rw [he] norm_num [centralChildOuterY,sourceScale,sourceLength,sourceRadialWidth,sourceHole,centralThickness] linarith exact ⟨Or.inr (Or.inl hh),Or.inr (Or.inl hh)⟩ · left simp only [sourceCollarPiece,Matrix.cons_val_two,squareFace,squareFaceBase,squareFaceDirection, Pi.add_apply,Pi.smul_apply,smul_eq_mul] norm_num [centralChildHeight,sourceScale,centralThickness] at ht ⊢ linarith [le_abs_self (1-x 0),neg_le_abs (x 0-1)] · right change 0≤ sourceCollarRadius 2 (x 0) (x 2) at hr0 have hsmall : sourceCollarRadius 2 (x 0) (x 2)≤(31:ℝ)/1000 := by change sourceRadialCenter+sourceRadialWidth*(1-x 0)*((-1:ℝ)+x 2*0)≤31/1000 norm_num [sourceRadialCenter,sourceRadialWidth,sourceHole,centralThickness] at ht ⊢ linarith have hq := squareFace_abs_le i ha 0 have hsmall' : |(sourceCollarPiece i 2 x) 0|≤(1:ℝ)/20 := by simp only [sourceCollarPiece,Matrix.cons_val_zero,abs_mul,abs_of_pos hL,abs_of_nonneg hr0] norm_num [sourceLength] nlinarith have hlow1 := abs_sub_le sourceOffset ((sourceCollarPiece i 2 x) 0) have hlow2 := abs_sub_le (-sourceOffset) ((sourceCollarPiece i 2 x) 0) have htri1 := abs_add_le (sourceOffset-(sourceCollarPiece i 2 x) 0) ((sourceCollarPiece i 2 x) 0) have htri2 := abs_add_le (-sourceOffset-(sourceCollarPiece i 2 x) 0) ((sourceCollarPiece i 2 x) 0) simp only [sub_add_cancel,abs_sub_comm sourceOffset,abs_sub_comm (-sourceOffset)] at htri1 htri2 have hc1 : centralChildOuterX≤|(sourceCollarPiece i 2 x) 0-sourceOffset| := by norm_num [centralChildOuterX,sourceScale,sourceRadialWidth,sourceHole,centralThickness,sourceOffset] at * linarith have hc2 : centralChildOuterX≤|(sourceCollarPiece i 2 x) 0+sourceOffset| := by norm_num [centralChildOuterX,sourceScale,sourceRadialWidth,sourceHole,centralThickness,sourceOffset] at * linarith exact ⟨Or.inl (by simpa using hc1),Or.inl (by simpa using hc2)⟩ · left simp only [sourceCollarPiece,Matrix.cons_val_two,squareFace,squareFaceBase,squareFaceDirection, Pi.add_apply,Pi.smul_apply,smul_eq_mul] norm_num [centralChildHeight,sourceScale,centralThickness] at ht ⊢ linarith [le_abs_self (1-x 0),neg_le_abs (x 0-1)] theorem sourceParentCollar_central (i j : Fin 4) {x : Fin 3 → ℝ} (hx : x∈sourceExtendedBox centralThickness (2*centralThickness)) : sourcePairCoordinates (sourceCollarPiece i j x)∈centralClosed := ⟨(sourceParentCollar_parent i j hx).1,(sourceParentCollar_parent i j hx).2, sourceParentCollar_avoids i j hx⟩ end ScalarConductivity end end OAI