import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Topology.UniformSpace.UniformConvergence /-! # Assembling smooth limits on an open exhaustion Local smooth limits of the same sequence agree on overlaps. Their germs therefore define one smooth limit, and compact containment transfers uniform convergence of every derivative to the whole domain. This is the fixed-coordinate assembly in Morgan-Tian Theorem 12.5, p. 297. -/ set_option autoImplicit false open Set Filter open scoped ContDiff Topology /-- Compatible local smooth limits on an open exhaustion assemble into one smooth limit with compact-uniform derivative convergence (Theorem 12.5, p. 297, fixed-coordinate assembly). -/ theorem exists_contDiffOn_limit_of_open_exhaustion {๐•œ : Type*} [NontriviallyNormedField ๐•œ] {ฮน E F : Type*} [NormedAddCommGroup E] [NormedSpace ๐•œ E] [NormedAddCommGroup F] [NormedSpace ๐•œ F] {ฮฉ : Set E} {U : ฮน โ†’ Set E} (hU : โˆ€ i, IsOpen (U i)) (hsub : โˆ€ i, U i โІ ฮฉ) (hcover : โˆ€ x โˆˆ ฮฉ, โˆƒ i, x โˆˆ U i) (hcompact : โˆ€ K, IsCompact K โ†’ K โІ ฮฉ โ†’ โˆƒ i, K โІ U i) {f : โ„• โ†’ E โ†’ F} {g : ฮน โ†’ E โ†’ F} (hg : โˆ€ i, ContDiffOn ๐•œ โˆž (g i) (U i)) (hconv : โˆ€ i m K, IsCompact K โ†’ K โІ U i โ†’ TendstoUniformlyOn (fun k => iteratedFDeriv ๐•œ m (f k)) (iteratedFDeriv ๐•œ m (g i)) atTop K) : โˆƒ G : E โ†’ F, ContDiffOn ๐•œ โˆž G ฮฉ โˆง โˆ€ m K, IsCompact K โ†’ K โІ ฮฉ โ†’ TendstoUniformlyOn (fun k => iteratedFDeriv ๐•œ m (f k)) (iteratedFDeriv ๐•œ m G) atTop K := by classical have hpoint (i : ฮน) {x : E} (hx : x โˆˆ U i) : Tendsto (fun k => f k x) atTop (๐“ (g i x)) := by have hev := ContinuousMultilinearMap.uniformContinuous_eval_const (๐•œ := ๐•œ) (F := F) (0 : Fin 0 โ†’ E) have h := hev.comp_tendstoUniformlyOn (hconv i 0 {x} isCompact_singleton (singleton_subset_iff.mpr hx)) simpa only [Function.comp_def, iteratedFDeriv_zero_apply] using h.tendsto_at (mem_singleton x) have hcompat (i j : ฮน) {x : E} (hi : x โˆˆ U i) (hj : x โˆˆ U j) : g i x = g j x := tendsto_nhds_unique (hpoint i hi) (hpoint j hj) let G : E โ†’ F := fun x => if hx : x โˆˆ ฮฉ then g (hcover x hx).choose x else 0 have heq (i : ฮน) : EqOn G (g i) (U i) := by intro x hx have hxฮฉ := hsub i hx simp only [G, dif_pos hxฮฉ] exact hcompat _ i (hcover x hxฮฉ).choose_spec hx have hgerm (i : ฮน) {x : E} (hx : x โˆˆ U i) : G =แถ [๐“ x] g i := by filter_upwards [(hU i).mem_nhds hx] with y hy exact heq i hy refine โŸจG, ?_, ?_โŸฉ ยท intro x hx obtain โŸจi, hiโŸฉ := hcover x hx exact (((hg i).contDiffAt ((hU i).mem_nhds hi)).congr_of_eventuallyEq (hgerm i hi)).contDiffWithinAt ยท intro m K hK hKฮฉ obtain โŸจi, hKiโŸฉ := hcompact K hK hKฮฉ apply (hconv i m K hK hKi).congr_right intro x hx exact ((hgerm i (hKi hx)).iteratedFDeriv (๐•œ := ๐•œ) m).eq_of_nhds.symm