import Mathlib import OAI.Analysis.Conductivity.Branching.FiniteEndingRegularity import OAI.Analysis.Conductivity.Branching.AlignedEndingData import OAI.Analysis.Conductivity.Geometry.RegularPatchLinear namespace OAI noncomputable section namespace ScalarConductivity open Real Set Filter Topology MeasureTheory Matrix open scoped Matrix.Norms.Elementwise def permutedDilationEquiv (e : Equiv.Perm (Fin 3)) {k : ℝ} (hk : k≠0) : Coord3 ≃L[ℝ] Coord3 := (ContinuousLinearEquiv.piCongrLeft ℝ (fun _ : Fin 3 => ℝ) e.symm).trans (LinearEquiv.smulOfNeZero ℝ Coord3 k hk).toContinuousLinearEquiv lemma permutedDilationEquiv_apply (e : Equiv.Perm (Fin 3)) {k : ℝ} (hk : k≠0) (x : Coord3) : permutedDilationEquiv e hk x=permutedDilation e k x := by ext i simp [permutedDilationEquiv,permutedDilation,ContinuousLinearEquiv.piCongrLeft, Homeomorph.piCongrLeft,Equiv.piCongrLeft] def axialPairScaling {k : ℝ} (hk : k≠0) : (Fin 2 → ℝ) ≃L[ℝ] (Fin 2 → ℝ) := ContinuousLinearEquiv.piCongrRight (fun i : Fin 2 => (LinearEquiv.smulOfNeZero ℝ ℝ (if i=0 then k⁻¹ else 1) (by split_ifs <;> simp_all)).toContinuousLinearEquiv) lemma axialPairScaling_apply {k : ℝ} (hk : k≠0) (v : Fin 2 → ℝ) (i : Fin 2) : axialPairScaling hk v i=(if i=0 then k⁻¹ else 1)*v i := rfl lemma alignedEnding_axialPair {lam k J L K : ℝ} (hk : k≠0) (x : Coord3) : axialPairScaling hk (axialPair (finiteEndingValue (lam/k) J L K) (permutedDilationEquiv angularAxisSwap hk x))=axialPair (alignedEndingValue lam k J L K) x := by ext i fin_cases i <;> simp [axialPairScaling_apply,permutedDilationEquiv_apply,axialPair, permutedDilation,angularAxisSwap_apply,alignedEndingValue,hk] def alignedEndingSymmetricTensor (lam k J L K : ℝ) (x : Coord3) : Symmetric3 := ⟨alignedEndingTensor lam k J L K x,alignedEndingTensor_symm lam k J L K x⟩ lemma RegularPatch.alignedEnding {lam k J L K : ℝ} (hk : k≠0) {O : Set Coord3} (h : RegularPatch (axialPair (finiteEndingValue (lam/k) J L K)) (finiteEndingSymmetricTensor (lam/k) J L K) O) : RegularPatch (axialPair (alignedEndingValue lam k J L K)) (alignedEndingSymmetricTensor lam k J L K) ((permutedDilationEquiv angularAxisSwap hk) ⁻¹' O) := by let P := permutedDilationEquiv angularAxisSwap hk let Q := axialPairScaling hk have he : (fun x => Q (axialPair (finiteEndingValue (lam/k) J L K) (P x)))= axialPair (alignedEndingValue lam k J L K) := funext (alignedEnding_axialPair hk) refine ⟨h.1.preimage P.continuous,?_,?_,?_⟩ · rw [←he] exact Q.contDiff.contDiffOn.comp (h.2.1.comp P.contDiff.contDiffOn (fun _ hx => hx)) (fun _ _ => mem_univ _) · apply contDiffOn_pi.mpr; intro i apply contDiffOn_pi.mpr; intro j have hh := h.2.2.1.comp P.contDiff.contDiffOn (fun _ hx => hx) have hi := (contDiff_apply ℝ (Fin 3 → ℝ) (angularAxisSwap i)).contDiffOn.comp hh (fun _ _ => mem_univ _) have hj := (contDiff_apply ℝ ℝ (angularAxisSwap j)).contDiffOn.comp hi (fun _ _ => mem_univ _) change ContDiffOn ℝ (↑(⊤:ℕ∞)) (fun x => finiteEndingTensor (lam/k) J L K (P x) (angularAxisSwap i) (angularAxisSwap j)) (P ⁻¹' O) at hj convert hj using 1 funext x simp only [alignedEndingSymmetricTensor,alignedEndingTensor, P,permutedDilationEquiv_apply] · rw [←he] exact TwoFieldRankRegular.linearCoordinates h.1 h.2.1 h.2.2.2 P Q theorem alignedEnding_regularRegion_ae {lam k J L K : ℝ} (hk : k≠0) (hL : 0 ![x 0,delayedEndingValue lam k J L K 7 x]) := by apply contDiff_pi.mpr intro i fin_cases i · exact contDiff_apply ℝ ℝ 0 · exact delayedEndingValue_C2 hJ hL hK apply contDiff_axial_paste hu hv (continuous_apply 0) (δ:=1/4) (by norm_num) intro x hx rw [he x (by linarith [hx.1]),delayedEndingValue_initial hk hJ x (by linarith [hx.2])] lemma matchedEndingPair_periodic {u : Coord3 → Fin 2 → ℝ} (hu : AngularPeriodic (2*Real.pi) u) (lam J L K : ℝ) (k : ℤ) : AngularPeriodic (2*Real.pi) (matchedEndingPair u lam k J L K) := by intro n x have ht : (x+angularShift (2*Real.pi) n) 0=x 0 := by simp [angularShift] simp only [matchedEndingPair,ht,hu n x,delayedEndingValue_periodic _ _ _ _ _ _ n x] lemma matchedEndingPair_terminal {u : Coord3 → Fin 2 → ℝ} {lam k J L K : ℝ} (hJ : 0