source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/LinearAlgebra/Dimension/ErdosKaplansky.lean
import Mathlib.Algebra.Field.Opposite import Mathlib.LinearAlgebra.Basis.VectorSpace import Mathlib.LinearAlgebra.Dimension.Constructions import Mathlib.SetTheory.Cardinal.Subfield /-! # Erdős-Kaplansky theorem * `rank_dual_eq_card_dual_of_aleph0_le_rank`: The **Erdős-Kaplansky Theorem** which says that the dimension of an infinite-dimensional dual space over a division ring has dimension equal to its cardinality. -/ noncomputable section universe u v variable {K : Type u} open Cardinal section Cardinal variable (K) variable [DivisionRing K] /-- Key lemma towards the Erdős-Kaplansky theorem from https://mathoverflow.net/a/168624 -/ theorem max_aleph0_card_le_rank_fun_nat : max ℵ₀ #K ≤ Module.rank K (ℕ → K) := by have aleph0_le : ℵ₀ ≤ Module.rank K (ℕ → K) := (rank_finsupp_self K ℕ).symm.trans_le (Finsupp.lcoeFun.rank_le_of_injective <| by exact DFunLike.coe_injective) refine max_le aleph0_le ?_ obtain card_K | card_K := le_or_gt #K ℵ₀ · exact card_K.trans aleph0_le by_contra! obtain ⟨⟨ιK, bK⟩⟩ := Module.Free.exists_basis (R := K) (M := ℕ → K) let L := Subfield.closure (Set.range (fun i : ιK × ℕ ↦ bK i.1 i.2)) have hLK : #L < #K := by refine (Subfield.cardinalMk_closure_le_max _).trans_lt (max_lt_iff.mpr ⟨mk_range_le.trans_lt ?_, card_K⟩) rwa [mk_prod, ← aleph0, lift_uzero, bK.mk_eq_rank'', mul_aleph0_eq aleph0_le] letI := Module.compHom K (RingHom.op L.subtype) obtain ⟨⟨ιL, bL⟩⟩ := Module.Free.exists_basis (R := Lᵐᵒᵖ) (M := K) have card_ιL : ℵ₀ ≤ #ιL := by contrapose! hLK haveI := @Fintype.ofFinite _ (lt_aleph0_iff_finite.mp hLK) rw [bL.repr.toEquiv.cardinal_eq, mk_finsupp_of_fintype, ← MulOpposite.opEquiv.cardinal_eq] at card_K ⊢ apply power_nat_le contrapose! card_K exact (power_lt_aleph0 card_K <| nat_lt_aleph0 _).le obtain ⟨e⟩ := lift_mk_le'.mp (card_ιL.trans_eq (lift_uzero #ιL).symm) have rep_e := bK.linearCombination_repr (bL ∘ e) rw [Finsupp.linearCombination_apply, Finsupp.sum] at rep_e set c := bK.repr (bL ∘ e) set s := c.support let f i (j : s) : L := ⟨bK j i, Subfield.subset_closure ⟨(j, i), rfl⟩⟩ have : ¬LinearIndependent Lᵐᵒᵖ f := fun h ↦ by have := h.cardinal_lift_le_rank rw [lift_uzero, (LinearEquiv.piCongrRight fun _ ↦ MulOpposite.opLinearEquiv Lᵐᵒᵖ).rank_eq, rank_fun'] at this exact (nat_lt_aleph0 _).not_ge this obtain ⟨t, g, eq0, i, hi, hgi⟩ := not_linearIndependent_iff.mp this refine hgi (linearIndependent_iff'.mp (bL.linearIndependent.comp e e.injective) t g ?_ i hi) clear_value c s simp_rw [← rep_e, Finset.sum_apply, Pi.smul_apply, Finset.smul_sum] rw [Finset.sum_comm] refine Finset.sum_eq_zero fun i hi ↦ ?_ replace eq0 := congr_arg L.subtype (congr_fun eq0 ⟨i, hi⟩) rw [Finset.sum_apply, map_sum] at eq0 have : SMulCommClass Lᵐᵒᵖ K K := ⟨fun _ _ _ ↦ mul_assoc _ _ _⟩ simp_rw [smul_comm _ (c i), ← Finset.smul_sum] erw [eq0, smul_zero] variable {K} open Function in theorem rank_fun_infinite {ι : Type v} [hι : Infinite ι] : Module.rank K (ι → K) = #(ι → K) := by obtain ⟨⟨ιK, bK⟩⟩ := Module.Free.exists_basis (R := K) (M := ι → K) obtain ⟨e⟩ := lift_mk_le'.mp ((aleph0_le_mk_iff.mpr hι).trans_eq (lift_uzero #ι).symm) have := LinearMap.lift_rank_le_of_injective _ <| LinearMap.funLeft_injective_of_surjective K K _ (invFun_surjective e.injective) rw [lift_umax.{u,v}, lift_id'.{u,v}] at this have key := (lift_le.{v}.mpr <| max_aleph0_card_le_rank_fun_nat K).trans this rw [lift_max, lift_aleph0, max_le_iff] at key haveI : Infinite ιK := by rw [← aleph0_le_mk_iff, bK.mk_eq_rank'']; exact key.1 rw [bK.repr.toEquiv.cardinal_eq, mk_finsupp_lift_of_infinite, lift_umax.{u,v}, lift_id'.{u,v}, bK.mk_eq_rank'', eq_comm, max_eq_left] exact key.2 /-- The **Erdős-Kaplansky Theorem**: the dual of an infinite-dimensional vector space over a division ring has dimension equal to its cardinality. -/ theorem rank_dual_eq_card_dual_of_aleph0_le_rank' {V : Type*} [AddCommGroup V] [Module K V] (h : ℵ₀ ≤ Module.rank K V) : Module.rank Kᵐᵒᵖ (V →ₗ[K] K) = #(V →ₗ[K] K) := by obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V) rw [← b.mk_eq_rank'', aleph0_le_mk_iff] at h have e := (b.constr Kᵐᵒᵖ (M' := K)).symm.trans (LinearEquiv.piCongrRight fun _ ↦ MulOpposite.opLinearEquiv Kᵐᵒᵖ) rw [e.rank_eq, e.toEquiv.cardinal_eq] apply rank_fun_infinite /-- The **Erdős-Kaplansky Theorem** over a field. -/ theorem rank_dual_eq_card_dual_of_aleph0_le_rank {K V} [Field K] [AddCommGroup V] [Module K V] (h : ℵ₀ ≤ Module.rank K V) : Module.rank K (V →ₗ[K] K) = #(V →ₗ[K] K) := by obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V) rw [← b.mk_eq_rank'', aleph0_le_mk_iff] at h have e := (b.constr K (M' := K)).symm rw [e.rank_eq, e.toEquiv.cardinal_eq] apply rank_fun_infinite theorem lift_rank_lt_rank_dual' {V : Type v} [AddCommGroup V] [Module K V] (h : ℵ₀ ≤ Module.rank K V) : Cardinal.lift.{u} (Module.rank K V) < Module.rank Kᵐᵒᵖ (V →ₗ[K] K) := by obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V) rw [← b.mk_eq_rank'', rank_dual_eq_card_dual_of_aleph0_le_rank' h, ← (b.constr ℕ (M' := K)).toEquiv.cardinal_eq, mk_arrow] apply cantor' erw [nat_lt_lift_iff, one_lt_iff_nontrivial] infer_instance theorem lift_rank_lt_rank_dual {K : Type u} {V : Type v} [Field K] [AddCommGroup V] [Module K V] (h : ℵ₀ ≤ Module.rank K V) : Cardinal.lift.{u} (Module.rank K V) < Module.rank K (V →ₗ[K] K) := by rw [rank_dual_eq_card_dual_of_aleph0_le_rank h, ← rank_dual_eq_card_dual_of_aleph0_le_rank' h] exact lift_rank_lt_rank_dual' h theorem rank_lt_rank_dual' {V : Type u} [AddCommGroup V] [Module K V] (h : ℵ₀ ≤ Module.rank K V) : Module.rank K V < Module.rank Kᵐᵒᵖ (V →ₗ[K] K) := by convert lift_rank_lt_rank_dual' h; rw [lift_id] theorem rank_lt_rank_dual {K V : Type u} [Field K] [AddCommGroup V] [Module K V] (h : ℵ₀ ≤ Module.rank K V) : Module.rank K V < Module.rank K (V →ₗ[K] K) := by convert lift_rank_lt_rank_dual h; rw [lift_id] end Cardinal
.lake/packages/mathlib/Mathlib/LinearAlgebra/Dimension/Torsion/Finite.lean
import Mathlib.Algebra.Module.Torsion.Basic import Mathlib.LinearAlgebra.Dimension.Finite /-! # Results relating rank and torsion. -/ variable {R M : Type*} [CommRing R] [IsDomain R] [AddCommGroup M] [Module R M] lemma rank_eq_zero_iff_isTorsion : Module.rank R M = 0 ↔ Module.IsTorsion R M := by rw [Module.IsTorsion, rank_eq_zero_iff] simp [mem_nonZeroDivisors_iff_ne_zero] /-- The `StrongRankCondition` is automatic. See `commRing_strongRankCondition`. -/ theorem Module.finrank_eq_zero_iff_isTorsion [StrongRankCondition R] [Module.Finite R M] : finrank R M = 0 ↔ Module.IsTorsion R M := by rw [← rank_eq_zero_iff_isTorsion (R := R), ← finrank_eq_rank] norm_cast
.lake/packages/mathlib/Mathlib/LinearAlgebra/Dimension/Torsion/Basic.lean
import Mathlib.Algebra.Module.Torsion.Basic import Mathlib.LinearAlgebra.Dimension.Constructions import Mathlib.LinearAlgebra.Dimension.Subsingleton /-! # Rank and torsion ## Main statements - `rank_quotient_eq_of_le_torsion` : `rank M/N = rank M` if `N ≤ torsion M`. -/ open Submodule theorem rank_quotient_eq_of_le_torsion {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {M' : Submodule R M} (hN : M' ≤ torsion R M) : Module.rank R (M ⧸ M') = Module.rank R M := (rank_quotient_le M').antisymm <| by nontriviality R rw [Module.rank] refine ciSup_le fun ⟨s, hs⟩ ↦ LinearIndependent.cardinal_le_rank (v := (M'.mkQ ·)) ?_ rw [LinearIndepOn, linearIndependent_iff'] at hs simp_rw [linearIndependent_iff', ← map_smul, ← map_sum, mkQ_apply, Quotient.mk_eq_zero] intro t g hg i hi obtain ⟨r, hg⟩ := hN hg simp_rw [Finset.smul_sum, Submonoid.smul_def, smul_smul] at hg exact r.prop.2 _ (mul_comm (g i) r ▸ hs t _ hg i hi)
.lake/packages/mathlib/Mathlib/LinearAlgebra/FiniteDimensional/Lemmas.lean
import Mathlib.LinearAlgebra.Dimension.DivisionRing import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition import Mathlib.LinearAlgebra.FiniteDimensional.Basic import Mathlib.Tactic.IntervalCases /-! # Finite-dimensional vector spaces This file contains some further development of finite-dimensional vector spaces, their dimensions, and linear maps on such spaces. Definitions are in `Mathlib/LinearAlgebra/FiniteDimensional/Defs.lean` and results that require fewer imports are in `Mathlib/LinearAlgebra/FiniteDimensional/Basic.lean`. -/ assert_not_exists Monoid.exponent Module.IsTorsion universe u v v' open Cardinal Submodule Module Function variable {K : Type u} {V : Type v} namespace Submodule open IsNoetherian Module section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] /-- The dimension of a strict submodule is strictly bounded by the dimension of the ambient space. See also `Submodule.length_lt`. -/ theorem finrank_lt [FiniteDimensional K V] {s : Submodule K V} (h : s ≠ ⊤) : finrank K s < finrank K V := by rw [← s.finrank_quotient_add_finrank, add_comm] exact Nat.lt_add_of_pos_right (finrank_pos_iff.mpr (Quotient.nontrivial_of_lt_top _ h.lt_top)) /-- The sum of the dimensions of s + t and s ∩ t is the sum of the dimensions of s and t -/ theorem finrank_sup_add_finrank_inf_eq (s t : Submodule K V) [FiniteDimensional K s] [FiniteDimensional K t] : finrank K ↑(s ⊔ t) + finrank K ↑(s ⊓ t) = finrank K ↑s + finrank K ↑t := by have key : Module.rank K ↑(s ⊔ t) + Module.rank K ↑(s ⊓ t) = Module.rank K s + Module.rank K t := rank_sup_add_rank_inf_eq s t repeat rw [← finrank_eq_rank] at key norm_cast at key theorem finrank_add_le_finrank_add_finrank (s t : Submodule K V) [FiniteDimensional K s] [FiniteDimensional K t] : finrank K (s ⊔ t : Submodule K V) ≤ finrank K s + finrank K t := by rw [← finrank_sup_add_finrank_inf_eq] exact self_le_add_right _ _ theorem finrank_add_finrank_le_of_disjoint [FiniteDimensional K V] {s t : Submodule K V} (hdisjoint : Disjoint s t) : finrank K s + finrank K t ≤ finrank K V := by rw [← Submodule.finrank_sup_add_finrank_inf_eq s t, hdisjoint.eq_bot, finrank_bot, add_zero] exact Submodule.finrank_le _ theorem eq_top_of_disjoint [FiniteDimensional K V] (s t : Submodule K V) (hdim : finrank K V ≤ finrank K s + finrank K t) (hdisjoint : Disjoint s t) : s ⊔ t = ⊤ := by have h_finrank_inf : finrank K ↑(s ⊓ t) = 0 := by rw [disjoint_iff_inf_le, le_bot_iff] at hdisjoint rw [hdisjoint, finrank_bot] apply eq_top_of_finrank_eq replace hdim : finrank K V = finrank K s + finrank K t := le_antisymm hdim (finrank_add_finrank_le_of_disjoint hdisjoint) rw [hdim] convert s.finrank_sup_add_finrank_inf_eq t rw [h_finrank_inf] rfl theorem isCompl_iff_disjoint [FiniteDimensional K V] (s t : Submodule K V) (hdim : finrank K V ≤ finrank K s + finrank K t) : IsCompl s t ↔ Disjoint s t := ⟨fun h ↦ h.1, fun h ↦ ⟨h, codisjoint_iff.mpr <| eq_top_of_disjoint s t hdim h⟩⟩ end DivisionRing end Submodule namespace FiniteDimensional section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] variable [FiniteDimensional K V] [FiniteDimensional K V₂] /-- Given isomorphic subspaces `p q` of vector spaces `V` and `V₁` respectively, `p.quotient` is isomorphic to `q.quotient`. -/ noncomputable def LinearEquiv.quotEquivOfEquiv {p : Subspace K V} {q : Subspace K V₂} (f₁ : p ≃ₗ[K] q) (f₂ : V ≃ₗ[K] V₂) : (V ⧸ p) ≃ₗ[K] V₂ ⧸ q := LinearEquiv.ofFinrankEq _ _ (by rw [← @add_right_cancel_iff _ _ _ (finrank K p), Submodule.finrank_quotient_add_finrank, LinearEquiv.finrank_eq f₁, Submodule.finrank_quotient_add_finrank, LinearEquiv.finrank_eq f₂]) -- TODO: generalize to the case where one of `p` and `q` is finite-dimensional. /-- Given the subspaces `p q`, if `p.quotient ≃ₗ[K] q`, then `q.quotient ≃ₗ[K] p` -/ noncomputable def LinearEquiv.quotEquivOfQuotEquiv {p q : Subspace K V} (f : (V ⧸ p) ≃ₗ[K] q) : (V ⧸ q) ≃ₗ[K] p := LinearEquiv.ofFinrankEq _ _ <| by rw [← add_right_cancel_iff, Submodule.finrank_quotient_add_finrank, ← LinearEquiv.finrank_eq f, add_comm, Submodule.finrank_quotient_add_finrank] end DivisionRing end FiniteDimensional namespace LinearMap open Module section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] /-- rank-nullity theorem : the dimensions of the kernel and the range of a linear map add up to the dimension of the source space. -/ theorem finrank_range_add_finrank_ker [FiniteDimensional K V] (f : V →ₗ[K] V₂) : finrank K (LinearMap.range f) + finrank K (LinearMap.ker f) = finrank K V := by rw [← f.quotKerEquivRange.finrank_eq] exact Submodule.finrank_quotient_add_finrank _ lemma ker_ne_bot_of_finrank_lt [FiniteDimensional K V] [FiniteDimensional K V₂] {f : V →ₗ[K] V₂} (h : finrank K V₂ < finrank K V) : LinearMap.ker f ≠ ⊥ := by have h₁ := f.finrank_range_add_finrank_ker have h₂ : finrank K (LinearMap.range f) ≤ finrank K V₂ := (LinearMap.range f).finrank_le suffices 0 < finrank K (LinearMap.ker f) from Submodule.one_le_finrank_iff.mp this cutsat end DivisionRing end LinearMap open Module namespace LinearMap variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] theorem injective_iff_surjective_of_finrank_eq_finrank [FiniteDimensional K V] [FiniteDimensional K V₂] (H : finrank K V = finrank K V₂) {f : V →ₗ[K] V₂} : Function.Injective f ↔ Function.Surjective f := by have := finrank_range_add_finrank_ker f rw [← ker_eq_bot, ← range_eq_top]; refine ⟨fun h => ?_, fun h => ?_⟩ · rw [h, finrank_bot, add_zero, H] at this exact eq_top_of_finrank_eq this · rw [h, finrank_top, H] at this exact Submodule.finrank_eq_zero.1 (add_right_injective _ this) theorem ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank [FiniteDimensional K V] [FiniteDimensional K V₂] (H : finrank K V = finrank K V₂) {f : V →ₗ[K] V₂} : LinearMap.ker f = ⊥ ↔ LinearMap.range f = ⊤ := by rw [range_eq_top, ker_eq_bot, injective_iff_surjective_of_finrank_eq_finrank H] /-- Given a linear map `f` between two vector spaces with the same dimension, if `ker f = ⊥` then `linearEquivOfInjective` is the induced isomorphism between the two vector spaces. -/ noncomputable def linearEquivOfInjective [FiniteDimensional K V] [FiniteDimensional K V₂] (f : V →ₗ[K] V₂) (hf : Injective f) (hdim : finrank K V = finrank K V₂) : V ≃ₗ[K] V₂ := LinearEquiv.ofBijective f ⟨hf, (LinearMap.injective_iff_surjective_of_finrank_eq_finrank hdim).mp hf⟩ @[simp] theorem linearEquivOfInjective_apply [FiniteDimensional K V] [FiniteDimensional K V₂] {f : V →ₗ[K] V₂} (hf : Injective f) (hdim : finrank K V = finrank K V₂) (x : V) : f.linearEquivOfInjective hf hdim x = f x := rfl end LinearMap namespace Submodule section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] theorem finrank_lt_finrank_of_lt {s t : Submodule K V} [FiniteDimensional K t] (hst : s < t) : finrank K s < finrank K t := (comapSubtypeEquivOfLe hst.le).finrank_eq.symm.trans_lt <| finrank_lt <| by simp [not_le_of_gt hst] theorem finrank_strictMono [FiniteDimensional K V] : StrictMono fun s : Submodule K V => finrank K s := fun _ _ => finrank_lt_finrank_of_lt theorem finrank_add_eq_of_isCompl [FiniteDimensional K V] {U W : Submodule K V} (h : IsCompl U W) : finrank K U + finrank K W = finrank K V := by rw [← finrank_sup_add_finrank_inf_eq, h.codisjoint.eq_top, h.disjoint.eq_bot, finrank_bot, add_zero] exact finrank_top _ _ end DivisionRing end Submodule section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] section Basis theorem LinearIndependent.span_eq_top_of_card_eq_finrank' {ι : Type*} [Fintype ι] [FiniteDimensional K V] {b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) : span K (Set.range b) = ⊤ := by by_contra ne_top rw [← finrank_span_eq_card lin_ind] at card_eq exact ne_of_lt (Submodule.finrank_lt ne_top) card_eq theorem LinearIndependent.span_eq_top_of_card_eq_finrank {ι : Type*} [Nonempty ι] [Fintype ι] {b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) : span K (Set.range b) = ⊤ := have : FiniteDimensional K V := .of_finrank_pos <| card_eq ▸ Fintype.card_pos lin_ind.span_eq_top_of_card_eq_finrank' card_eq /-- A linear independent family of `finrank K V` vectors forms a basis. -/ @[simps! repr_apply] noncomputable def basisOfLinearIndependentOfCardEqFinrank {ι : Type*} [Nonempty ι] [Fintype ι] {b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) : Basis ι K V := Basis.mk lin_ind <| (lin_ind.span_eq_top_of_card_eq_finrank card_eq).ge @[simp] theorem coe_basisOfLinearIndependentOfCardEqFinrank {ι : Type*} [Nonempty ι] [Fintype ι] {b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) : ⇑(basisOfLinearIndependentOfCardEqFinrank lin_ind card_eq) = b := Basis.coe_mk _ _ /-- In a vector space `ι → K`, a linear independent family indexed by `ι` is a basis. -/ noncomputable def basisOfPiSpaceOfLinearIndependent {ι : Type*} [Fintype ι] [Decidable (Nonempty ι)] {b : ι → (ι → K)} (hb : LinearIndependent K b) : Basis ι K (ι → K) := if hι : Nonempty ι then basisOfLinearIndependentOfCardEqFinrank hb (Module.finrank_fintype_fun_eq_card K).symm else have : IsEmpty ι := not_nonempty_iff.mp hι Basis.empty _ open Classical in @[simp] theorem coe_basisOfPiSpaceOfLinearIndependent {ι : Type*} [Fintype ι] {b : ι → (ι → K)} (hb : LinearIndependent K b) : ⇑(basisOfPiSpaceOfLinearIndependent hb) = b := by by_cases hι : Nonempty ι · simp [hι, basisOfPiSpaceOfLinearIndependent] · rw [basisOfPiSpaceOfLinearIndependent, dif_neg hι] ext i exact ((not_nonempty_iff.mp hι).false i).elim /-- A linear independent finset of `finrank K V` vectors forms a basis. -/ @[simps! repr_apply] noncomputable def finsetBasisOfLinearIndependentOfCardEqFinrank {s : Finset V} (hs : s.Nonempty) (lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.card = finrank K V) : Basis s K V := @basisOfLinearIndependentOfCardEqFinrank _ _ _ _ _ _ ⟨(⟨hs.choose, hs.choose_spec⟩ : s)⟩ _ _ lin_ind (_root_.trans (Fintype.card_coe _) card_eq) @[simp] theorem coe_finsetBasisOfLinearIndependentOfCardEqFinrank {s : Finset V} (hs : s.Nonempty) (lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.card = finrank K V) : ⇑(finsetBasisOfLinearIndependentOfCardEqFinrank hs lin_ind card_eq) = ((↑) : s → V) := by simp [finsetBasisOfLinearIndependentOfCardEqFinrank] /-- A linear independent set of `finrank K V` vectors forms a basis. -/ @[simps! repr_apply] noncomputable def setBasisOfLinearIndependentOfCardEqFinrank {s : Set V} [Nonempty s] [Fintype s] (lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.toFinset.card = finrank K V) : Basis s K V := basisOfLinearIndependentOfCardEqFinrank lin_ind (_root_.trans s.toFinset_card.symm card_eq) @[simp] theorem coe_setBasisOfLinearIndependentOfCardEqFinrank {s : Set V} [Nonempty s] [Fintype s] (lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.toFinset.card = finrank K V) : ⇑(setBasisOfLinearIndependentOfCardEqFinrank lin_ind card_eq) = ((↑) : s → V) := by simp [setBasisOfLinearIndependentOfCardEqFinrank] end Basis /-! We now give characterisations of `finrank K V = 1` and `finrank K V ≤ 1`. -/ section finrank_eq_one /-- Any `K`-algebra module that is 1-dimensional over `K` is simple. -/ theorem is_simple_module_of_finrank_eq_one {A} [Semiring A] [Module A V] [SMul K A] [IsScalarTower K A V] (h : finrank K V = 1) : IsSimpleOrder (Submodule A V) := by haveI := nontrivial_of_finrank_eq_succ h refine ⟨fun S => or_iff_not_imp_left.2 fun hn => ?_⟩ rw [← restrictScalars_inj K] at hn ⊢ haveI : FiniteDimensional _ _ := .of_finrank_eq_succ h refine eq_top_of_finrank_eq ((Submodule.finrank_le _).antisymm ?_) simpa only [h, finrank_bot] using Submodule.finrank_strictMono (Ne.bot_lt hn) end finrank_eq_one end DivisionRing section SubalgebraRank open Module variable {F E : Type*} [Field F] [Ring E] [Algebra F E] theorem Subalgebra.isSimpleOrder_of_finrank (hr : finrank F E = 2) : IsSimpleOrder (Subalgebra F E) := let i := nontrivial_of_finrank_pos (zero_lt_two.trans_eq hr.symm) { toNontrivial := ⟨⟨⊥, ⊤, fun h => by cases hr.symm.trans (Subalgebra.bot_eq_top_iff_finrank_eq_one.1 h)⟩⟩ eq_bot_or_eq_top := by intro S haveI : FiniteDimensional F E := .of_finrank_eq_succ hr haveI : FiniteDimensional F S := FiniteDimensional.finiteDimensional_submodule (Subalgebra.toSubmodule S) have : finrank F S ≤ 2 := hr ▸ S.toSubmodule.finrank_le have : 0 < finrank F S := finrank_pos_iff.mpr inferInstance interval_cases h : finrank F { x // x ∈ S } · left exact Subalgebra.eq_bot_of_finrank_one h · right rw [← hr] at h rw [← Algebra.toSubmodule_eq_top] exact eq_top_of_finrank_eq h } end SubalgebraRank namespace Module namespace End variable [DivisionRing K] [AddCommGroup V] [Module K V] theorem exists_ker_pow_eq_ker_pow_succ [FiniteDimensional K V] (f : End K V) : ∃ k : ℕ, k ≤ finrank K V ∧ LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ) := by classical by_contra h_contra simp_rw [not_exists, not_and] at h_contra have h_le_ker_pow : ∀ n : ℕ, n ≤ (finrank K V).succ → n ≤ finrank K (LinearMap.ker (f ^ n)) := by intro n hn induction n with | zero => exact zero_le (finrank _ _) | succ n ih => have h_ker_lt_ker : LinearMap.ker (f ^ n) < LinearMap.ker (f ^ n.succ) := by refine lt_of_le_of_ne ?_ (h_contra n (Nat.le_of_succ_le_succ hn)) rw [pow_succ'] apply LinearMap.ker_le_ker_comp have h_finrank_lt_finrank : finrank K (LinearMap.ker (f ^ n)) < finrank K (LinearMap.ker (f ^ n.succ)) := by apply Submodule.finrank_lt_finrank_of_lt h_ker_lt_ker calc n.succ ≤ (finrank K ↑(LinearMap.ker (f ^ n))).succ := Nat.succ_le_succ (ih (Nat.le_of_succ_le hn)) _ ≤ finrank K ↑(LinearMap.ker (f ^ n.succ)) := Nat.succ_le_of_lt h_finrank_lt_finrank have h_any_n_lt : ∀ n, n ≤ (finrank K V).succ → n ≤ finrank K V := fun n hn => (h_le_ker_pow n hn).trans (Submodule.finrank_le _) exact Nat.not_succ_le_self _ (h_any_n_lt (finrank K V).succ (finrank K V).succ.le_refl) theorem ker_pow_eq_ker_pow_finrank_of_le [FiniteDimensional K V] {f : End K V} {m : ℕ} (hm : finrank K V ≤ m) : LinearMap.ker (f ^ m) = LinearMap.ker (f ^ finrank K V) := by obtain ⟨k, h_k_le, hk⟩ : ∃ k, k ≤ finrank K V ∧ LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ) := exists_ker_pow_eq_ker_pow_succ f calc LinearMap.ker (f ^ m) = LinearMap.ker (f ^ (k + (m - k))) := by rw [add_tsub_cancel_of_le (h_k_le.trans hm)] _ = LinearMap.ker (f ^ k) := by rw [ker_pow_constant hk _] _ = LinearMap.ker (f ^ (k + (finrank K V - k))) := ker_pow_constant hk (finrank K V - k) _ = LinearMap.ker (f ^ finrank K V) := by rw [add_tsub_cancel_of_le h_k_le] theorem ker_pow_le_ker_pow_finrank [FiniteDimensional K V] (f : End K V) (m : ℕ) : LinearMap.ker (f ^ m) ≤ LinearMap.ker (f ^ finrank K V) := by by_cases! h_cases : m < finrank K V · rw [← add_tsub_cancel_of_le h_cases.le, add_comm, pow_add] apply LinearMap.ker_le_ker_comp · rw [ker_pow_eq_ker_pow_finrank_of_le h_cases] end End end Module
.lake/packages/mathlib/Mathlib/LinearAlgebra/FiniteDimensional/Basic.lean
import Mathlib.Algebra.Module.Projective import Mathlib.LinearAlgebra.Dimension.Finite import Mathlib.LinearAlgebra.FiniteDimensional.Defs /-! # Finite-dimensional vector spaces Basic properties of finite-dimensional vector spaces, of their dimensions, and of linear maps on such spaces. ## Main definitions Preservation of finite-dimensionality and formulas for the dimension are given for - submodules (`FiniteDimensional.finiteDimensional_submodule`) - quotients (for the dimension of a quotient, see `Submodule.finrank_quotient_add_finrank` in `Mathlib/LinearAlgebra/FiniteDimensional.lean`) - linear equivs, in `LinearEquiv.finiteDimensional` Basic properties of linear maps of a finite-dimensional vector space are given. Notably, the equivalence of injectivity and surjectivity is proved in `LinearMap.injective_iff_surjective`, and the equivalence between left-inverse and right-inverse in `LinearMap.mul_eq_one_comm` and `LinearMap.comp_eq_id_comm`. ## Implementation notes You should not assume that there has been any effort to state lemmas as generally as possible. Plenty of the results hold for general fg modules or Noetherian modules, and they can be found in `Mathlib/LinearAlgebra/FreeModule/Finite/Rank.lean` and `Mathlib/RingTheory/Noetherian.lean`. -/ universe u v v' w open Cardinal Function IsNoetherian Module Submodule variable {K : Type u} {V : Type v} namespace FiniteDimensional section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] theorem _root_.LinearIndependent.lt_aleph0_of_finiteDimensional {ι : Type w} [FiniteDimensional K V] {v : ι → V} (h : LinearIndependent K v) : #ι < ℵ₀ := h.lt_aleph0_of_finite /-- If a submodule has maximal dimension in a finite-dimensional space, then it is equal to the whole space. -/ theorem _root_.Submodule.eq_top_of_finrank_eq [FiniteDimensional K V] {S : Submodule K V} (h : finrank K S = finrank K V) : S = ⊤ := by set bS := Basis.ofVectorSpace K S with bS_eq have : LinearIndepOn K id (Subtype.val '' Basis.ofVectorSpaceIndex K S) := by simpa [bS] using bS.linearIndependent.linearIndepOn_id.image (f := Submodule.subtype S) (by simp) set b := Basis.extend this with b_eq letI i1 : Fintype (this.extend _) := (LinearIndependent.set_finite_of_isNoetherian (by simpa [b] using b.linearIndependent)).fintype letI i2 : Fintype (((↑) : S → V) '' Basis.ofVectorSpaceIndex K S) := (LinearIndependent.set_finite_of_isNoetherian this).fintype letI i3 : Fintype (Basis.ofVectorSpaceIndex K S) := (LinearIndependent.set_finite_of_isNoetherian (by simpa [bS] using bS.linearIndependent)).fintype have : (↑) '' Basis.ofVectorSpaceIndex K S = this.extend (Set.subset_univ _) := Set.eq_of_subset_of_card_le (this.subset_extend _) (by rw [Set.card_image_of_injective _ Subtype.coe_injective, ← finrank_eq_card_basis bS, ← finrank_eq_card_basis b, h]) rw [← b.span_eq, b_eq, Basis.coe_extend, Subtype.range_coe, ← this, ← Submodule.coe_subtype, span_image] have := bS.span_eq rw [bS_eq, Basis.coe_ofVectorSpace, Subtype.range_coe] at this rw [this, Submodule.map_top (Submodule.subtype S), range_subtype] section open Finset variable {L : Type*} [Field L] [LinearOrder L] [IsStrictOrderedRing L] variable {W : Type v} [AddCommGroup W] [Module L W] /-- A slight strengthening of `exists_nontrivial_relation_sum_zero_of_rank_succ_lt_card` available when working over an ordered field: we can ensure a positive coefficient, not just a nonzero coefficient. -/ theorem exists_relation_sum_zero_pos_coefficient_of_finrank_succ_lt_card [FiniteDimensional L W] {t : Finset W} (h : finrank L W + 1 < t.card) : ∃ f : W → L, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, 0 < f x := by obtain ⟨f, sum, total, nonzero⟩ := Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card h exact ⟨f, sum, total, exists_pos_of_sum_zero_of_exists_nonzero f total nonzero⟩ end /-- In a vector space with dimension 1, each set {v} is a basis for `v ≠ 0`. -/ @[simps repr_apply] noncomputable def basisSingleton (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0) : Basis ι K V := let b := Module.basisUnique ι h have h : b.repr v default ≠ 0 := mt Module.basisUnique_repr_eq_zero_iff.mp hv Basis.ofRepr { toFun := fun w => Finsupp.single default (b.repr w default / b.repr v default) invFun := fun f => f default • v map_add' := by simp [add_div] map_smul' := by simp [mul_div] left_inv := fun w => by apply_fun b.repr using b.repr.toEquiv.injective apply_fun Equiv.finsuppUnique simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same, smul_eq_mul, Pi.smul_apply, Equiv.finsuppUnique_apply] exact div_mul_cancel₀ _ h right_inv := fun f => by ext simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same, RingHom.id_apply, smul_eq_mul, Pi.smul_apply] exact mul_div_cancel_right₀ _ h } @[simp] theorem basisSingleton_apply (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0) (i : ι) : basisSingleton ι h v hv i = v := by cases Unique.uniq ‹Unique ι› i simp [basisSingleton] @[simp] theorem range_basisSingleton (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0) : Set.range (basisSingleton ι h v hv) = {v} := by rw [Set.range_unique, basisSingleton_apply] end DivisionRing end FiniteDimensional section ZeroRank variable [DivisionRing K] [AddCommGroup V] [Module K V] theorem FiniteDimensional.of_rank_eq_nat {n : ℕ} (h : Module.rank K V = n) : FiniteDimensional K V := Module.finite_of_rank_eq_nat h theorem FiniteDimensional.of_rank_eq_zero (h : Module.rank K V = 0) : FiniteDimensional K V := Module.finite_of_rank_eq_zero h theorem FiniteDimensional.of_rank_eq_one (h : Module.rank K V = 1) : FiniteDimensional K V := Module.finite_of_rank_eq_one h variable (K V) instance finiteDimensional_bot : FiniteDimensional K (⊥ : Submodule K V) := .of_rank_eq_zero <| by simp variable {K V} end ZeroRank namespace Submodule open IsNoetherian Module section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] /-- A submodule contained in a finite-dimensional submodule is finite-dimensional. -/ theorem finiteDimensional_of_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (h : S₁ ≤ S₂) : FiniteDimensional K S₁ := (isNoetherian_of_le h).finite /-- The inf of two submodules, the first finite-dimensional, is finite-dimensional. -/ instance finiteDimensional_inf_left (S₁ S₂ : Submodule K V) [FiniteDimensional K S₁] : FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) := finiteDimensional_of_le inf_le_left /-- The inf of two submodules, the second finite-dimensional, is finite-dimensional. -/ instance finiteDimensional_inf_right (S₁ S₂ : Submodule K V) [FiniteDimensional K S₂] : FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) := finiteDimensional_of_le inf_le_right /-- The sup of two finite-dimensional submodules is finite-dimensional. -/ instance finiteDimensional_sup (S₁ S₂ : Submodule K V) [h₁ : FiniteDimensional K S₁] [h₂ : FiniteDimensional K S₂] : FiniteDimensional K (S₁ ⊔ S₂ : Submodule K V) := by unfold FiniteDimensional at * rw [finite_def] at * exact (fg_top _).2 (((fg_top S₁).1 h₁).sup ((fg_top S₂).1 h₂)) /-- The submodule generated by a finite supremum of finite-dimensional submodules is finite-dimensional. Note that strictly this only needs `∀ i ∈ s, FiniteDimensional K (S i)`, but that doesn't work well with typeclass search. -/ instance finiteDimensional_finset_sup {ι : Type*} (s : Finset ι) (S : ι → Submodule K V) [∀ i, FiniteDimensional K (S i)] : FiniteDimensional K (s.sup S : Submodule K V) := by refine @Finset.sup_induction _ _ _ _ s S (fun i => FiniteDimensional K ↑i) (finiteDimensional_bot K V) ?_ fun i _ => by infer_instance intro S₁ hS₁ S₂ hS₂ exact Submodule.finiteDimensional_sup S₁ S₂ /-- The submodule generated by a supremum of finite-dimensional submodules, indexed by a finite sort is finite-dimensional. -/ instance finiteDimensional_iSup {ι : Sort*} [Finite ι] (S : ι → Submodule K V) [∀ i, FiniteDimensional K (S i)] : FiniteDimensional K ↑(⨆ i, S i) := by cases nonempty_fintype (PLift ι) rw [← iSup_plift_down, ← Finset.sup_univ_eq_iSup] exact Submodule.finiteDimensional_finset_sup _ _ end DivisionRing end Submodule section variable [DivisionRing K] [AddCommGroup V] [Module K V] instance finiteDimensional_finsupp {ι : Type*} [Finite ι] [FiniteDimensional K V] : FiniteDimensional K (ι →₀ V) := Module.Finite.finsupp end namespace Submodule variable [DivisionRing K] [AddCommGroup V] [Module K V] /-- If a submodule is contained in a finite-dimensional submodule with the same or smaller dimension, they are equal. -/ theorem eq_of_le_of_finrank_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂) (hd : finrank K S₂ ≤ finrank K S₁) : S₁ = S₂ := by rw [← LinearEquiv.finrank_eq (Submodule.comapSubtypeEquivOfLe hle)] at hd exact le_antisymm hle (Submodule.comap_subtype_eq_top.1 (eq_top_of_finrank_eq (le_antisymm (comap (Submodule.subtype S₂) S₁).finrank_le hd))) /-- If a submodule is contained in a finite-dimensional submodule with the same dimension, they are equal. -/ theorem eq_of_le_of_finrank_eq {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂) (hd : finrank K S₁ = finrank K S₂) : S₁ = S₂ := eq_of_le_of_finrank_le hle hd.ge end Submodule namespace Subalgebra variable {K L : Type*} [Field K] [Ring L] [Algebra K L] {F E : Subalgebra K L} [hfin : FiniteDimensional K E] /-- If a subalgebra is contained in a finite-dimensional subalgebra with the same or smaller dimension, they are equal. -/ theorem eq_of_le_of_finrank_le (h_le : F ≤ E) (h_finrank : finrank K E ≤ finrank K F) : F = E := haveI : Module.Finite K (Subalgebra.toSubmodule E) := hfin toSubmodule_injective <| Submodule.eq_of_le_of_finrank_le h_le h_finrank /-- If a subalgebra is contained in a finite-dimensional subalgebra with the same dimension, they are equal. -/ theorem eq_of_le_of_finrank_eq (h_le : F ≤ E) (h_finrank : finrank K F = finrank K E) : F = E := eq_of_le_of_finrank_le h_le h_finrank.ge end Subalgebra namespace LinearMap open Module section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] /-- On a finite-dimensional space, an injective linear map is surjective. -/ theorem surjective_of_injective [FiniteDimensional K V] {f : V →ₗ[K] V} (hinj : Injective f) : Surjective f := by have h := rank_range_of_injective _ hinj rw [← finrank_eq_rank, ← finrank_eq_rank, Nat.cast_inj] at h exact range_eq_top.1 (eq_top_of_finrank_eq h) /-- The image under an onto linear map of a finite-dimensional space is also finite-dimensional. -/ theorem finiteDimensional_of_surjective [FiniteDimensional K V] (f : V →ₗ[K] V₂) (hf : LinearMap.range f = ⊤) : FiniteDimensional K V₂ := Module.Finite.of_surjective f <| range_eq_top.1 hf /-- The range of a linear map defined on a finite-dimensional space is also finite-dimensional. -/ instance finiteDimensional_range [FiniteDimensional K V] (f : V →ₗ[K] V₂) : FiniteDimensional K (LinearMap.range f) := Module.Finite.range f /-- On a finite-dimensional space, a linear map is injective if and only if it is surjective. -/ theorem injective_iff_surjective [FiniteDimensional K V] {f : V →ₗ[K] V} : Injective f ↔ Surjective f := ⟨surjective_of_injective, fun hsurj => let ⟨g, hg⟩ := f.exists_rightInverse_of_surjective (range_eq_top.2 hsurj) have : Function.RightInverse g f := LinearMap.ext_iff.1 hg (leftInverse_of_surjective_of_rightInverse (surjective_of_injective this.injective) this).injective⟩ lemma injOn_iff_surjOn {p : Submodule K V} [FiniteDimensional K p] {f : V →ₗ[K] V} (h : ∀ x ∈ p, f x ∈ p) : Set.InjOn f p ↔ Set.SurjOn f p p := by rw [Set.injOn_iff_injective, ← Set.MapsTo.restrict_surjective_iff h] change Injective (f.domRestrict p) ↔ Surjective (f.restrict h) simp [disjoint_iff, ← injective_iff_surjective] theorem ker_eq_bot_iff_range_eq_top [FiniteDimensional K V] {f : V →ₗ[K] V} : LinearMap.ker f = ⊥ ↔ LinearMap.range f = ⊤ := by rw [range_eq_top, ker_eq_bot, injective_iff_surjective] /-- In a finite-dimensional space, if linear maps are inverse to each other on one side then they are also inverse to each other on the other side. -/ theorem mul_eq_one_of_mul_eq_one [FiniteDimensional K V] {f g : V →ₗ[K] V} (hfg : f * g = 1) : g * f = 1 := by have ginj : Injective g := HasLeftInverse.injective ⟨f, fun x => show (f * g) x = (1 : V →ₗ[K] V) x by rw [hfg]⟩ let ⟨i, hi⟩ := g.exists_rightInverse_of_surjective (range_eq_top.2 (injective_iff_surjective.1 ginj)) have : f * (g * i) = f * 1 := congr_arg _ hi rw [← mul_assoc, hfg, one_mul, mul_one] at this; rwa [← this] /-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if they are inverse to each other on the other side. -/ theorem mul_eq_one_comm [FiniteDimensional K V] {f g : V →ₗ[K] V} : f * g = 1 ↔ g * f = 1 := ⟨mul_eq_one_of_mul_eq_one, mul_eq_one_of_mul_eq_one⟩ /-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if they are inverse to each other on the other side. -/ theorem comp_eq_id_comm [FiniteDimensional K V] {f g : V →ₗ[K] V} : f.comp g = id ↔ g.comp f = id := mul_eq_one_comm theorem comap_eq_sup_ker_of_disjoint {p : Submodule K V} [FiniteDimensional K p] {f : V →ₗ[K] V} (h : ∀ x ∈ p, f x ∈ p) (h' : Disjoint p (ker f)) : p.comap f = p ⊔ ker f := by refine le_antisymm (fun x hx ↦ ?_) (sup_le_iff.mpr ⟨h, ker_le_comap _⟩) obtain ⟨⟨y, hy⟩, hxy⟩ := surjective_of_injective ((injective_restrict_iff_disjoint h).mpr h') ⟨f x, hx⟩ replace hxy : f y = f x := by simpa [Subtype.ext_iff] using hxy exact Submodule.mem_sup.mpr ⟨y, hy, x - y, by simp [hxy], add_sub_cancel y x⟩ theorem ker_comp_eq_of_commute_of_disjoint_ker [FiniteDimensional K V] {f g : V →ₗ[K] V} (h : Commute f g) (h' : Disjoint (ker f) (ker g)) : ker (f ∘ₗ g) = ker f ⊔ ker g := by suffices ∀ x, f x = 0 → f (g x) = 0 by rw [ker_comp, comap_eq_sup_ker_of_disjoint _ h']; simpa intro x hx rw [← comp_apply, ← Module.End.mul_eq_comp, h.eq, Module.End.mul_apply, hx, map_zero] theorem ker_noncommProd_eq_of_supIndep_ker [FiniteDimensional K V] {ι : Type*} {f : ι → V →ₗ[K] V} (s : Finset ι) (comm) (h : s.SupIndep fun i ↦ ker (f i)) : ker (s.noncommProd f comm) = ⨆ i ∈ s, ker (f i) := by classical induction s using Finset.induction_on with | empty => simp [Module.End.one_eq_id] | insert i s hi ih => replace ih : ker (Finset.noncommProd s f <| Set.Pairwise.mono (s.subset_insert i) comm) = ⨆ x ∈ s, ker (f x) := ih _ (h.subset (s.subset_insert i)) rw [Finset.noncommProd_insert_of_notMem _ _ _ _ hi, Module.End.mul_eq_comp, ker_comp_eq_of_commute_of_disjoint_ker] · simp_rw [Finset.mem_insert_coe, iSup_insert, Finset.mem_coe, ih] · exact s.noncommProd_commute _ _ _ fun j hj ↦ comm (s.mem_insert_self i) (Finset.mem_insert_of_mem hj) (by aesop) · replace h := Finset.supIndep_iff_disjoint_erase.mp h i (s.mem_insert_self i) simpa [ih, hi, Finset.sup_eq_iSup] using h end DivisionRing end LinearMap namespace LinearEquiv open Module variable [DivisionRing K] [AddCommGroup V] [Module K V] variable [FiniteDimensional K V] /-- The linear equivalence corresponding to an injective endomorphism. -/ noncomputable def ofInjectiveEndo (f : V →ₗ[K] V) (h_inj : Injective f) : V ≃ₗ[K] V := LinearEquiv.ofBijective f ⟨h_inj, LinearMap.injective_iff_surjective.mp h_inj⟩ @[simp] theorem coe_ofInjectiveEndo (f : V →ₗ[K] V) (h_inj : Injective f) : ⇑(ofInjectiveEndo f h_inj) = f := rfl @[simp] theorem ofInjectiveEndo_right_inv (f : V →ₗ[K] V) (h_inj : Injective f) : f * (ofInjectiveEndo f h_inj).symm = 1 := LinearMap.ext <| (ofInjectiveEndo f h_inj).apply_symm_apply @[simp] theorem ofInjectiveEndo_left_inv (f : V →ₗ[K] V) (h_inj : Injective f) : ((ofInjectiveEndo f h_inj).symm : V →ₗ[K] V) * f = 1 := LinearMap.ext <| (ofInjectiveEndo f h_inj).symm_apply_apply variable {V' : Type*} [AddCommGroup V'] [Module K V'] [FiniteDimensional K V'] omit [FiniteDimensional K V] /-- An injective linear map between finite-dimensional modules of equal rank is a linear equivalence. Unlike `LinearEquiv.ofFinrankEq` (which creates an *abstract* linear equivalence from `V` to `V'`), this lemma improves a *given* injective linear map to a linear equivalence. -/ noncomputable def ofInjectiveOfFinrankEq (f : V →ₗ[K] V') (hinj : Function.Injective f) (hrank : Module.finrank K V = Module.finrank K V') : V ≃ₗ[K] V' := haveI : LinearMap.range f = ⊤ := Submodule.eq_top_of_finrank_eq ((LinearMap.finrank_range_of_inj hinj).trans hrank) (ofInjective f hinj).trans (ofTop (LinearMap.range f) this) @[simp] lemma coe_ofInjectiveOfFinrankEq (f : V →ₗ[K] V') (hinj : Function.Injective f) (hrank : Module.finrank K V = Module.finrank K V') : (ofInjectiveOfFinrankEq f hinj hrank).toLinearMap = f := rfl end LinearEquiv namespace LinearMap variable [DivisionRing K] [AddCommGroup V] [Module K V] theorem isUnit_iff_ker_eq_bot [FiniteDimensional K V] (f : V →ₗ[K] V) : IsUnit f ↔ (LinearMap.ker f) = ⊥ := by constructor · rintro ⟨u, rfl⟩ exact LinearMap.ker_eq_bot_of_inverse u.inv_mul · intro h_inj rw [ker_eq_bot] at h_inj exact ⟨⟨f, (LinearEquiv.ofInjectiveEndo f h_inj).symm.toLinearMap, LinearEquiv.ofInjectiveEndo_right_inv f h_inj, LinearEquiv.ofInjectiveEndo_left_inv f h_inj⟩, rfl⟩ theorem isUnit_iff_range_eq_top [FiniteDimensional K V] (f : V →ₗ[K] V) : IsUnit f ↔ (LinearMap.range f) = ⊤ := by rw [isUnit_iff_ker_eq_bot, ker_eq_bot_iff_range_eq_top] end LinearMap open FiniteDimensional Module section variable [DivisionRing K] [AddCommGroup V] [Module K V] theorem finrank_zero_iff_forall_zero [FiniteDimensional K V] : finrank K V = 0 ↔ ∀ x : V, x = 0 := Module.finrank_zero_iff.trans (subsingleton_iff_forall_eq 0) /-- If `ι` is an empty type and `V` is zero-dimensional, there is a unique `ι`-indexed basis. -/ noncomputable def basisOfFinrankZero [FiniteDimensional K V] {ι : Type*} [IsEmpty ι] (hV : finrank K V = 0) : Basis ι K V := haveI : Subsingleton V := finrank_zero_iff.1 hV Basis.empty _ end section lemma FiniteDimensional.exists_mul_eq_one (F : Type*) {K : Type*} [Field F] [Ring K] [IsDomain K] [Algebra F K] [FiniteDimensional F K] {x : K} (H : x ≠ 0) : ∃ y, x * y = 1 := by have : Function.Surjective (LinearMap.mulLeft F x) := LinearMap.injective_iff_surjective.1 fun y z => ((mul_right_inj' H).1 : x * y = x * z → y = z) exact this 1 /-- A domain that is module-finite as an algebra over a field is a division ring. -/ noncomputable def divisionRingOfFiniteDimensional (F K : Type*) [Field F] [Ring K] [IsDomain K] [Algebra F K] [FiniteDimensional F K] : DivisionRing K where __ := ‹IsDomain K› inv x := letI := Classical.decEq K if H : x = 0 then 0 else Classical.choose <| FiniteDimensional.exists_mul_eq_one F H mul_inv_cancel x hx := show x * dite _ (h := _) _ _ = _ by rw [dif_neg hx] exact (Classical.choose_spec (FiniteDimensional.exists_mul_eq_one F hx) :) inv_zero := dif_pos rfl nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl lemma FiniteDimensional.isUnit (F : Type*) {K : Type*} [Field F] [Ring K] [IsDomain K] [Algebra F K] [FiniteDimensional F K] {x : K} (H : x ≠ 0) : IsUnit x := let _ := divisionRingOfFiniteDimensional F K; H.isUnit /-- An integral domain that is module-finite as an algebra over a field is a field. -/ noncomputable def fieldOfFiniteDimensional (F K : Type*) [Field F] [h : CommRing K] [IsDomain K] [Algebra F K] [FiniteDimensional F K] : Field K := { divisionRingOfFiniteDimensional F K with toCommRing := h } end section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] section Span open Submodule theorem finrank_span_singleton {v : V} (hv : v ≠ 0) : finrank K (K ∙ v) = 1 := by apply le_antisymm · exact finrank_span_le_card ({v} : Set V) · rw [Nat.succ_le_iff, finrank_pos_iff] use ⟨v, mem_span_singleton_self v⟩, 0 apply Subtype.coe_ne_coe.mp simp [hv] /-- In a one-dimensional space, any vector is a multiple of any nonzero vector -/ lemma exists_smul_eq_of_finrank_eq_one (h : finrank K V = 1) {x : V} (hx : x ≠ 0) (y : V) : ∃ (c : K), c • x = y := by have : Submodule.span K {x} = ⊤ := by have : FiniteDimensional K V := .of_finrank_eq_succ h apply eq_top_of_finrank_eq rw [h] exact finrank_span_singleton hx have : y ∈ Submodule.span K {x} := by rw [this]; exact mem_top exact mem_span_singleton.1 this theorem Set.finrank_mono [FiniteDimensional K V] {s t : Set V} (h : s ⊆ t) : s.finrank K ≤ t.finrank K := Submodule.finrank_mono (span_mono h) end Span /-! We now give characterisations of `finrank K V = 1` and `finrank K V ≤ 1`. -/ section finrank_eq_one /-- A vector space with a nonzero vector `v` has dimension 1 iff `v` spans. -/ theorem finrank_eq_one_iff_of_nonzero (v : V) (nz : v ≠ 0) : finrank K V = 1 ↔ span K ({v} : Set V) = ⊤ where mp h := by simpa using (basisSingleton Unit h v nz).span_eq mpr s := finrank_eq_card_basis <| .mk (.of_subsingleton (v := ![v]) 0 nz) <| by simp [← s] /-- A module with a nonzero vector `v` has dimension 1 iff every vector is a multiple of `v`. -/ theorem finrank_eq_one_iff_of_nonzero' (v : V) (nz : v ≠ 0) : finrank K V = 1 ↔ ∀ w : V, ∃ c : K, c • v = w := by rw [finrank_eq_one_iff_of_nonzero v nz] apply span_singleton_eq_top_iff -- We use the `LinearMap.CompatibleSMul` typeclass here, to encompass two situations: -- * `A = K` -- * `[Field K] [Algebra K A] [IsScalarTower K A V] [IsScalarTower K A W]` theorem surjective_of_nonzero_of_finrank_eq_one {W A : Type*} [Semiring A] [Module A V] [AddCommGroup W] [Module K W] [Module A W] [LinearMap.CompatibleSMul V W K A] (h : finrank K W = 1) {f : V →ₗ[A] W} (w : f ≠ 0) : Surjective f := by change Surjective (f.restrictScalars K) obtain ⟨v, n⟩ := DFunLike.ne_iff.mp w intro z obtain ⟨c, rfl⟩ := (finrank_eq_one_iff_of_nonzero' (f v) n).mp h z exact ⟨c • v, by simp⟩ end finrank_eq_one end DivisionRing section SubalgebraRank open Module variable {F E : Type*} [Field F] [Ring E] [Algebra F E] /-- A `Subalgebra` is `FiniteDimensional` iff it is `FiniteDimensional` as a submodule. -/ theorem Subalgebra.finiteDimensional_toSubmodule {S : Subalgebra F E} : FiniteDimensional F (Subalgebra.toSubmodule S) ↔ FiniteDimensional F S := Iff.rfl alias ⟨FiniteDimensional.of_subalgebra_toSubmodule, FiniteDimensional.subalgebra_toSubmodule⟩ := Subalgebra.finiteDimensional_toSubmodule instance FiniteDimensional.finiteDimensional_subalgebra [FiniteDimensional F E] (S : Subalgebra F E) : FiniteDimensional F S := FiniteDimensional.of_subalgebra_toSubmodule inferInstance end SubalgebraRank namespace Module namespace End variable [DivisionRing K] [AddCommGroup V] [Module K V] theorem ker_pow_constant {f : End K V} {k : ℕ} (h : LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ)) : ∀ m, LinearMap.ker (f ^ k) = LinearMap.ker (f ^ (k + m)) | 0 => by simp | m + 1 => by apply le_antisymm · rw [add_comm, pow_add] apply LinearMap.ker_le_ker_comp · rw [ker_pow_constant h m, add_comm m 1, ← add_assoc, pow_add, pow_add f k m, Module.End.mul_eq_comp, Module.End.mul_eq_comp, LinearMap.ker_comp, LinearMap.ker_comp, h, Nat.add_one] end End end Module
.lake/packages/mathlib/Mathlib/LinearAlgebra/FiniteDimensional/Defs.lean
import Mathlib.LinearAlgebra.Basis.VectorSpace import Mathlib.LinearAlgebra.Dimension.Free import Mathlib.RingTheory.SimpleRing.Basic /-! # Finite-dimensional vector spaces This file defines finite-dimensional vector spaces and shows our definition is equivalent to alternative definitions. ## Main definitions Assume `V` is a vector space over a division ring `K`. There are (at least) three equivalent definitions of finite-dimensionality of `V`: - it admits a finite basis. - it is finitely generated. - it is Noetherian, i.e., every subspace is finitely generated. We introduce a typeclass `FiniteDimensional K V` capturing this property. For ease of transfer of proof, it is defined using the second point of view, i.e., as `Module.Finite`. However, we prove that all these points of view are equivalent, with the following lemmas (in the namespace `FiniteDimensional`): - `Module.finBasis` and `Module.finBasisOfFinrankEq` are bases for finite-dimensional vector spaces, where the index type is `Fin` (in `Mathlib/LinearAlgebra/Dimension/Free.lean`) - `fintypeBasisIndex` states that a finite-dimensional vector space has a finite basis - `Module.Basis.finiteDimensional_of_finite` states that the existence of a basis indexed by a finite type implies finite-dimensionality - `of_finite_basis` states that the existence of a basis indexed by a finite set implies finite-dimensionality - `of_finrank_pos` states that a nonzero `finrank` (implying non-infinite dimension) implies finite-dimensionality - `IsNoetherian.iff_fg` states that the space is finite-dimensional if and only if it is Noetherian (in `Mathlib/FieldTheory/Finiteness.lean`) We make use of `finrank`, the dimension of a finite-dimensional space, returning a `Nat`, as opposed to `Module.rank`, which returns a `Cardinal`. When the space has infinite dimension, its `finrank` is by convention set to `0`. `finrank` is not defined using `FiniteDimensional`. For basic results that do not need the `FiniteDimensional` class, import `Mathlib/LinearAlgebra/Finrank.lean`. Preservation of finite-dimensionality and formulas for the dimension are given for - submodules (`FiniteDimensional.finiteDimensional_submodule`) - linear equivs, in `LinearEquiv.finiteDimensional` ## Implementation notes You should not assume that there has been any effort to state lemmas as generally as possible. Plenty of the results hold for general fg modules or Noetherian modules, and they can be found in `Mathlib/LinearAlgebra/FreeModule/Finite/Rank.lean` and `Mathlib/RingTheory/Noetherian.lean`. -/ assert_not_exists Module.Projective Subalgebra universe u v v' w open Cardinal Module Submodule /-- `FiniteDimensional` vector spaces are defined to be finite modules. Use `Module.Basis.finiteDimensional_of_finite` to prove finite dimension from another definition. -/ abbrev FiniteDimensional (K V : Type*) [DivisionRing K] [AddCommGroup V] [Module K V] := Module.Finite K V variable {K : Type u} {V : Type v} namespace FiniteDimensional variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] /-- If the codomain of an injective linear map is finite dimensional, the domain must be as well. -/ theorem of_injective (f : V →ₗ[K] V₂) (w : Function.Injective f) [FiniteDimensional K V₂] : FiniteDimensional K V := Module.Finite.of_injective f w /-- If the domain of a surjective linear map is finite dimensional, the codomain must be as well. -/ theorem of_surjective (f : V →ₗ[K] V₂) (w : Function.Surjective f) [FiniteDimensional K V] : FiniteDimensional K V₂ := Module.Finite.of_surjective f w variable (K V) instance finiteDimensional_pi {ι : Type*} [Finite ι] : FiniteDimensional K (ι → K) := Finite.pi instance finiteDimensional_pi' {ι : Type*} [Finite ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module K (M i)] [∀ i, FiniteDimensional K (M i)] : FiniteDimensional K (∀ i, M i) := Finite.pi variable {K V} /-- If a vector space has a finite basis, then it is finite-dimensional. -/ theorem _root_.Module.Basis.finiteDimensional_of_finite {ι : Type w} [Finite ι] (h : Basis ι K V) : FiniteDimensional K V := Module.Finite.of_basis h @[deprecated (since := "2025-11-12")] alias of_fintype_basis := Module.Basis.finiteDimensional_of_finite /-- If a vector space is `FiniteDimensional`, all bases are indexed by a finite type -/ noncomputable def fintypeBasisIndex {ι : Type*} [FiniteDimensional K V] (b : Basis ι K V) : Fintype ι := @Fintype.ofFinite _ (Module.Finite.finite_basis b) /-- If a vector space is `FiniteDimensional`, `Basis.ofVectorSpace` is indexed by a finite type. -/ noncomputable instance [FiniteDimensional K V] : Fintype (Basis.ofVectorSpaceIndex K V) := fintypeBasisIndex (Basis.ofVectorSpace K V) /-- If a vector space has a basis indexed by elements of a finite set, then it is finite-dimensional. -/ theorem of_finite_basis {ι : Type w} {s : Set ι} (h : Basis s K V) (hs : Set.Finite s) : FiniteDimensional K V := haveI := hs.fintype h.finiteDimensional_of_finite /-- A subspace of a finite-dimensional space is also finite-dimensional. This is a shortcut instance to simplify inference in the presence of `[FiniteDimensional K V]`. -/ instance finiteDimensional_submodule [FiniteDimensional K V] (S : Submodule K V) : FiniteDimensional K S := by infer_instance /-- A quotient of a finite-dimensional space is also finite-dimensional. -/ instance finiteDimensional_quotient [FiniteDimensional K V] (S : Submodule K V) : FiniteDimensional K (V ⧸ S) := Module.Finite.quotient K S theorem of_finrank_pos (h : 0 < finrank K V) : FiniteDimensional K V := Module.finite_of_finrank_pos h theorem of_finrank_eq_succ {n : ℕ} (hn : finrank K V = n.succ) : FiniteDimensional K V := Module.finite_of_finrank_eq_succ hn /-- We can infer `FiniteDimensional K V` in the presence of `[Fact (finrank K V = n + 1)]`. Use `have : FiniteDimensional K V := .of_fact_finrank_eq_succ` when needed. This is not an instance because `n` cannot be inferred. -/ theorem of_fact_finrank_eq_succ (n : ℕ) [hn : Fact (finrank K V = n + 1)] : FiniteDimensional K V := of_finrank_eq_succ hn.out end FiniteDimensional namespace Module variable (K V) variable [DivisionRing K] [AddCommGroup V] [Module K V] /-- In a finite-dimensional space, its dimension (seen as a cardinal) coincides with its `finrank`. This is a copy of `finrank_eq_rank _ _` which creates easier typeclass searches. -/ theorem finrank_eq_rank' [FiniteDimensional K V] : (finrank K V : Cardinal.{v}) = Module.rank K V := finrank_eq_rank _ _ variable {K V} theorem finrank_of_infinite_dimensional (h : ¬FiniteDimensional K V) : finrank K V = 0 := Module.finrank_of_not_finite h theorem finiteDimensional_iff_of_rank_eq_nsmul {W} [AddCommGroup W] [Module K W] {n : ℕ} (hn : n ≠ 0) (hVW : Module.rank K V = n • Module.rank K W) : FiniteDimensional K V ↔ FiniteDimensional K W := Module.finite_iff_of_rank_eq_nsmul hn hVW /-- If a vector space is finite-dimensional, then the cardinality of any basis is equal to its `finrank`. -/ theorem finrank_eq_card_basis' [FiniteDimensional K V] {ι : Type w} (h : Basis ι K V) : (finrank K V : Cardinal.{w}) = #ι := Module.mk_finrank_eq_card_basis h end Module namespace FiniteDimensional section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] variable (K) instance finiteDimensional_self : FiniteDimensional K K := inferInstance /-- The submodule generated by a finite set is finite-dimensional. -/ theorem span_of_finite {A : Set V} (hA : Set.Finite A) : FiniteDimensional K (Submodule.span K A) := Module.Finite.span_of_finite K hA /-- The submodule generated by a single element is finite-dimensional. -/ instance span_singleton (x : V) : FiniteDimensional K (K ∙ x) := Module.Finite.span_singleton K x /-- The submodule generated by a finset is finite-dimensional. -/ instance span_finset (s : Finset V) : FiniteDimensional K (span K (s : Set V)) := Module.Finite.span_finset K s /-- Pushforwards of finite-dimensional submodules are finite-dimensional. -/ instance (f : V →ₗ[K] V₂) (p : Submodule K V) [FiniteDimensional K p] : FiniteDimensional K (p.map f) := Module.Finite.map _ _ end DivisionRing section Tower variable (F K A : Type*) [DivisionRing F] [DivisionRing K] [AddCommGroup A] variable [Module F K] [Module K A] [Module F A] [IsScalarTower F K A] theorem trans [FiniteDimensional F K] [FiniteDimensional K A] : FiniteDimensional F A := Module.Finite.trans K A end Tower end FiniteDimensional namespace Submodule section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] /-- A submodule is finitely generated if and only if it is finite-dimensional -/ theorem fg_iff_finiteDimensional (s : Submodule K V) : s.FG ↔ FiniteDimensional K s := (fg_top s).symm.trans Module.finite_def.symm end DivisionRing end Submodule namespace LinearEquiv variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂] [Module K V₂] /-- Finite dimensionality is preserved under linear equivalence. -/ protected theorem finiteDimensional (f : V ≃ₗ[K] V₂) [FiniteDimensional K V] : FiniteDimensional K V₂ := Module.Finite.equiv f end LinearEquiv
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/Stalks.lean
import Mathlib.Geometry.RingedSpace.PresheafedSpace import Mathlib.CategoryTheory.Limits.Final import Mathlib.Topology.Sheaves.Stalks /-! # Stalks for presheafed spaces This file lifts constructions of stalks and pushforwards of stalks to work with the category of presheafed spaces. Additionally, we prove that restriction of presheafed spaces does not change the stalks. -/ noncomputable section universe v u v' u' open Opposite CategoryTheory CategoryTheory.Category CategoryTheory.Functor CategoryTheory.Limits AlgebraicGeometry TopologicalSpace Topology variable {C : Type u} [Category.{v} C] [HasColimits C] attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opens open TopCat.Presheaf namespace AlgebraicGeometry.PresheafedSpace /-- A morphism of presheafed spaces induces a morphism of stalks. -/ def Hom.stalkMap {X Y : PresheafedSpace.{_, _, v} C} (α : Hom X Y) (x : X) : Y.presheaf.stalk (α.base x) ⟶ X.presheaf.stalk x := (stalkFunctor C (α.base x)).map α.c ≫ X.presheaf.stalkPushforward C α.base x @[elementwise, reassoc] theorem stalkMap_germ {X Y : PresheafedSpace.{_, _, v} C} (α : X ⟶ Y) (U : Opens Y) (x : X) (hx : α x ∈ U) : Y.presheaf.germ U (α x) hx ≫ α.stalkMap x = α.c.app (op U) ≫ X.presheaf.germ ((Opens.map α.base).obj U) x hx := by rw [Hom.stalkMap, stalkFunctor_map_germ_assoc, stalkPushforward_germ] section Restrict /-- For an open embedding `f : U ⟶ X` and a point `x : U`, we get an isomorphism between the stalk of `X` at `f x` and the stalk of the restriction of `X` along `f` at `x`. -/ def restrictStalkIso {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (x : U) : (X.restrict h).presheaf.stalk x ≅ X.presheaf.stalk (f x) := haveI := initial_of_adjunction (h.isOpenMap.adjunctionNhds x) Final.colimitIso (h.isOpenMap.functorNhds x).op ((OpenNhds.inclusion (f x)).op ⋙ X.presheaf) -- As a left adjoint, the functor `h.is_open_map.functor_nhds x` is initial. -- Typeclass resolution knows that the opposite of an initial functor is final. The result -- follows from the general fact that postcomposing with a final functor doesn't change colimits. -- We intentionally leave `simp` off this lemma and those generated by `elementwise` and `reassoc`, -- as the simpNF linter claims they never apply. @[elementwise, reassoc] theorem restrictStalkIso_hom_eq_germ {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (V : Opens U) (x : U) (hx : x ∈ V) : (X.restrict h).presheaf.germ _ x hx ≫ (restrictStalkIso X h x).hom = X.presheaf.germ (h.isOpenMap.functor.obj V) (f x) ⟨x, hx, rfl⟩ := colimit.ι_pre ((OpenNhds.inclusion (f x)).op ⋙ X.presheaf) (h.isOpenMap.functorNhds x).op (op ⟨V, hx⟩) -- We intentionally leave `simp` off the lemmas generated by `elementwise` and `reassoc`, -- as the simpNF linter claims they never apply. @[simp, elementwise, reassoc] theorem restrictStalkIso_inv_eq_germ {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (V : Opens U) (x : U) (hx : x ∈ V) : X.presheaf.germ (h.isOpenMap.functor.obj V) (f x) ⟨x, hx, rfl⟩ ≫ (restrictStalkIso X h x).inv = (X.restrict h).presheaf.germ _ x hx := by rw [← restrictStalkIso_hom_eq_germ, Category.assoc, Iso.hom_inv_id, Category.comp_id] theorem restrictStalkIso_inv_eq_ofRestrict {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (x : U) : (X.restrictStalkIso h x).inv = (X.ofRestrict h).stalkMap x := by -- We can't use `ext` here because it would call `stalk_hom_ext` instead. refine colimit.hom_ext fun V => ?_ induction V with | op V => ?_ let i : (h.isOpenMap.functorNhds x).obj ((OpenNhds.map f x).obj V) ⟶ V := homOfLE (Set.image_preimage_subset f _) erw [Iso.comp_inv_eq, colimit.ι_map_assoc, colimit.ι_map_assoc, colimit.ι_pre] simp_rw [Category.assoc] erw [colimit.ι_pre ((OpenNhds.inclusion (f x)).op ⋙ X.presheaf) (h.isOpenMap.functorNhds x).op] erw [← X.presheaf.map_comp_assoc] exact (colimit.w ((OpenNhds.inclusion (f x)).op ⋙ X.presheaf) i.op).symm instance ofRestrict_stalkMap_isIso {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (x : U) : IsIso ((X.ofRestrict h).stalkMap x) := by rw [← restrictStalkIso_inv_eq_ofRestrict]; infer_instance end Restrict namespace stalkMap @[simp] theorem id (X : PresheafedSpace.{_, _, v} C) (x : X) : (𝟙 X : X ⟶ X).stalkMap x = 𝟙 (X.presheaf.stalk x) := by dsimp [Hom.stalkMap] simp only [stalkPushforward.id] rw [← map_comp] convert (stalkFunctor C x).map_id X.presheaf ext simp only [id_c, id_comp, Pushforward.id_hom_app] rfl @[simp] theorem comp {X Y Z : PresheafedSpace.{_, _, v} C} (α : X ⟶ Y) (β : Y ⟶ Z) (x : X) : (α ≫ β).stalkMap x = (β.stalkMap (α.base x) : Z.presheaf.stalk (β.base (α.base x)) ⟶ Y.presheaf.stalk (α.base x)) ≫ (α.stalkMap x : Y.presheaf.stalk (α.base x) ⟶ X.presheaf.stalk x) := by dsimp [Hom.stalkMap, stalkFunctor, stalkPushforward] -- We can't use `ext` here due to https://github.com/leanprover/std4/pull/159 apply colimit.hom_ext rintro ⟨U, hU⟩ simp /-- If `α = β` and `x = x'`, we would like to say that `stalk_map α x = stalk_map β x'`. Unfortunately, this equality is not well-formed, as their types are not _definitionally_ the same. To get a proper congruence lemma, we therefore have to introduce these `eqToHom` arrows on either side of the equality. -/ theorem congr {X Y : PresheafedSpace.{_, _, v} C} (α β : X ⟶ Y) (h₁ : α = β) (x x' : X) (h₂ : x = x') : α.stalkMap x ≫ eqToHom (show X.presheaf.stalk x = X.presheaf.stalk x' by rw [h₂]) = eqToHom (show Y.presheaf.stalk (α.base x) = Y.presheaf.stalk (β.base x') by rw [h₁, h₂]) ≫ β.stalkMap x' := by ext substs h₁ h₂ simp theorem congr_hom {X Y : PresheafedSpace.{_, _, v} C} (α β : X ⟶ Y) (h : α = β) (x : X) : α.stalkMap x = eqToHom (show Y.presheaf.stalk (α.base x) = Y.presheaf.stalk (β.base x) by rw [h]) ≫ β.stalkMap x := by rw [← stalkMap.congr α β h x x rfl, eqToHom_refl, Category.comp_id] theorem congr_point {X Y : PresheafedSpace.{_, _, v} C} (α : X ⟶ Y) (x x' : X) (h : x = x') : α.stalkMap x ≫ eqToHom (show X.presheaf.stalk x = X.presheaf.stalk x' by rw [h]) = eqToHom (show Y.presheaf.stalk (α.base x) = Y.presheaf.stalk (α.base x') by rw [h]) ≫ α.stalkMap x' := by rw [stalkMap.congr α α rfl x x' h] instance isIso {X Y : PresheafedSpace.{_, _, v} C} (α : X ⟶ Y) [IsIso α] (x : X) : IsIso (α.stalkMap x) where out := by let β : Y ⟶ X := CategoryTheory.inv α have h_eq : (α ≫ β).base x = x := by rw [IsIso.hom_inv_id α, id_base, TopCat.id_app] -- Intuitively, the inverse of the stalk map of `α` at `x` should just be the stalk map of `β` -- at `α x`. Unfortunately, we have a problem with dependent type theory here: Because `x` -- is not *definitionally* equal to `β (α x)`, the map `stalk_map β (α x)` has not the correct -- type for an inverse. -- To get a proper inverse, we need to compose with the `eqToHom` arrow -- `X.stalk x ⟶ X.stalk ((α ≫ β).base x)`. refine ⟨eqToHom (show X.presheaf.stalk x = X.presheaf.stalk ((α ≫ β).base x) by rw [h_eq]) ≫ (β.stalkMap (α.base x) :), ?_, ?_⟩ · rw [← Category.assoc, congr_point α x ((α ≫ β).base x) h_eq.symm, Category.assoc] erw [← stalkMap.comp β α (α.base x)] rw [congr_hom _ _ (IsIso.inv_hom_id α), stalkMap.id, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp] · rw [Category.assoc, ← stalkMap.comp, congr_hom _ _ (IsIso.hom_inv_id α), stalkMap.id, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp] /-- An isomorphism between presheafed spaces induces an isomorphism of stalks. -/ def stalkIso {X Y : PresheafedSpace.{_, _, v} C} (α : X ≅ Y) (x : X) : Y.presheaf.stalk (α.hom.base x) ≅ X.presheaf.stalk x := asIso (α.hom.stalkMap x) @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkSpecializes_stalkMap {X Y : PresheafedSpace.{_, _, v} C} (f : X ⟶ Y) {x y : X} (h : x ⤳ y) : Y.presheaf.stalkSpecializes (f.base.hom.map_specializes h) ≫ f.stalkMap x = f.stalkMap y ≫ X.presheaf.stalkSpecializes h := by -- Porting note: the original one liner `dsimp [stalkMap]; simp [stalkMap]` doesn't work, -- I had to uglify this dsimp [stalkSpecializes, Hom.stalkMap, stalkFunctor, stalkPushforward] -- We can't use `ext` here due to https://github.com/leanprover/std4/pull/159 refine colimit.hom_ext fun j => ?_ induction j with | op j => ?_ dsimp simp only [colimit.ι_desc_assoc, ι_colimMap_assoc, whiskerLeft_app, whiskerRight_app, NatTrans.id_app, colimit.ι_pre, assoc, colimit.pre_desc, colimit.map_desc, colimit.ι_desc, Cocones.precompose_obj_ι, Cocone.whisker_ι, NatTrans.comp_app] tauto end stalkMap end AlgebraicGeometry.PresheafedSpace
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/SheafedSpace.lean
import Mathlib.Geometry.RingedSpace.PresheafedSpace.HasColimits import Mathlib.Geometry.RingedSpace.Stalks import Mathlib.Topology.Sheaves.Functors /-! # Sheafed spaces Introduces the category of topological spaces equipped with a sheaf (taking values in an arbitrary target category `C`.) We further describe how to apply functors and natural transformations to the values of the presheaves. -/ open CategoryTheory TopCat TopologicalSpace Opposite CategoryTheory.Limits CategoryTheory.Category CategoryTheory.Functor Topology universe u v w' w variable (C : Type u) [Category.{v} C] -- We could enable the following line: -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opposite -- but may need -- https://github.com/leanprover-community/aesop/issues/59 namespace AlgebraicGeometry /-- A `SheafedSpace C` is a topological space equipped with a sheaf of `C`s. -/ structure SheafedSpace extends PresheafedSpace C where /-- A sheafed space is a presheafed space which happens to be a sheaf. -/ IsSheaf : presheaf.IsSheaf variable {C} namespace SheafedSpace instance coeCarrier : CoeOut (SheafedSpace C) TopCat where coe X := X.carrier instance coeSort : CoeSort (SheafedSpace C) Type* where coe X := X.1 /-- Extract the `sheaf C (X : Top)` from a `SheafedSpace C`. -/ def sheaf (X : SheafedSpace C) : Sheaf C (X : TopCat) := ⟨X.presheaf, X.IsSheaf⟩ /-- Not `@[simp]` since it already reduces to `carrier = carrier`. -/ theorem mk_coe (carrier) (presheaf) (h) : (({ carrier presheaf IsSheaf := h } : SheafedSpace C) : TopCat) = carrier := rfl instance (X : SheafedSpace C) : TopologicalSpace X := X.carrier.str /-- The trivial `unit`-valued sheaf on any topological space. -/ def unit (X : TopCat) : SheafedSpace (Discrete Unit) := { @PresheafedSpace.const (Discrete Unit) _ X ⟨⟨⟩⟩ with IsSheaf := Presheaf.isSheaf_unit _ } instance : Inhabited (SheafedSpace (Discrete Unit)) := ⟨unit (TopCat.of PEmpty)⟩ instance : Category (SheafedSpace C) := show Category (InducedCategory (PresheafedSpace C) SheafedSpace.toPresheafedSpace) by infer_instance @[ext (iff := false)] theorem ext {X Y : SheafedSpace C} (α β : X ⟶ Y) (w : α.base = β.base) (h : α.c ≫ whiskerRight (eqToHom (by rw [w])) _ = β.c) : α = β := PresheafedSpace.ext α β w h /-- Constructor for isomorphisms in the category `SheafedSpace C`. -/ @[simps] def isoMk {X Y : SheafedSpace C} (e : X.toPresheafedSpace ≅ Y.toPresheafedSpace) : X ≅ Y where hom := e.hom inv := e.inv hom_inv_id := e.hom_inv_id inv_hom_id := e.inv_hom_id /-- Forgetting the sheaf condition is a functor from `SheafedSpace C` to `PresheafedSpace C`. -/ @[simps! obj map] def forgetToPresheafedSpace : SheafedSpace C ⥤ PresheafedSpace C := inducedFunctor _ -- The `Full, Faithful` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance forgetToPresheafedSpace_full : (forgetToPresheafedSpace (C := C)).Full where map_surjective f := ⟨f, rfl⟩ instance forgetToPresheafedSpace_faithful : (forgetToPresheafedSpace (C := C)).Faithful where instance is_presheafedSpace_iso {X Y : SheafedSpace C} (f : X ⟶ Y) [IsIso f] : @IsIso (PresheafedSpace C) _ _ _ f := SheafedSpace.forgetToPresheafedSpace.map_isIso f section attribute [local simp] id comp @[simp] theorem id_base (X : SheafedSpace C) : (𝟙 X : X ⟶ X).base = 𝟙 (X : TopCat) := rfl theorem id_c (X : SheafedSpace C) : (𝟙 X : X ⟶ X).c = eqToHom (Presheaf.Pushforward.id_eq X.presheaf).symm := rfl @[simp] theorem id_c_app (X : SheafedSpace C) (U) : (𝟙 X : X ⟶ X).c.app U = 𝟙 _ := rfl @[simp] theorem comp_base {X Y Z : SheafedSpace C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).base = f.base ≫ g.base := rfl @[simp] theorem comp_c_app {X Y Z : SheafedSpace C} (α : X ⟶ Y) (β : Y ⟶ Z) (U) : (α ≫ β).c.app U = β.c.app U ≫ α.c.app (op ((Opens.map β.base).obj (unop U))) := rfl theorem comp_c_app' {X Y Z : SheafedSpace C} (α : X ⟶ Y) (β : Y ⟶ Z) (U) : (α ≫ β).c.app (op U) = β.c.app (op U) ≫ α.c.app (op ((Opens.map β.base).obj U)) := rfl theorem congr_app {X Y : SheafedSpace C} {α β : X ⟶ Y} (h : α = β) (U) : α.c.app U = β.c.app U ≫ X.presheaf.map (eqToHom (by subst h; rfl)) := PresheafedSpace.congr_app h U variable (C) /-- The forgetful functor from `SheafedSpace` to `Top`. -/ def forget : SheafedSpace C ⥤ TopCat where obj X := (X : TopCat) map {_ _} f := f.base end open TopCat.Presheaf /-- The restriction of a sheafed space along an open embedding into the space. -/ def restrict {U : TopCat} (X : SheafedSpace C) {f : U ⟶ (X : TopCat)} (h : IsOpenEmbedding f) : SheafedSpace C := { X.toPresheafedSpace.restrict h with IsSheaf := isSheaf_of_isOpenEmbedding h X.IsSheaf } /-- The map from the restriction of a presheafed space. -/ @[simps!] def ofRestrict {U : TopCat} (X : SheafedSpace C) {f : U ⟶ (X : TopCat)} (h : IsOpenEmbedding f) : X.restrict h ⟶ X := X.toPresheafedSpace.ofRestrict h /-- The restriction of a sheafed space `X` to the top subspace is isomorphic to `X` itself. -/ @[simps! hom inv] def restrictTopIso (X : SheafedSpace C) : X.restrict (Opens.isOpenEmbedding ⊤) ≅ X := isoMk (X.toPresheafedSpace.restrictTopIso) /-- The global sections, notated Gamma. -/ def Γ : (SheafedSpace C)ᵒᵖ ⥤ C := forgetToPresheafedSpace.op ⋙ PresheafedSpace.Γ theorem Γ_def : (Γ : _ ⥤ C) = forgetToPresheafedSpace.op ⋙ PresheafedSpace.Γ := rfl @[simp] theorem Γ_obj (X : (SheafedSpace C)ᵒᵖ) : Γ.obj X = (unop X).presheaf.obj (op ⊤) := rfl theorem Γ_obj_op (X : SheafedSpace C) : Γ.obj (op X) = X.presheaf.obj (op ⊤) := rfl @[simp] theorem Γ_map {X Y : (SheafedSpace C)ᵒᵖ} (f : X ⟶ Y) : Γ.map f = f.unop.c.app (op ⊤) := rfl theorem Γ_map_op {X Y : SheafedSpace C} (f : X ⟶ Y) : Γ.map f.op = f.c.app (op ⊤) := rfl noncomputable instance (J : Type w) [Category.{w'} J] [Small.{v} J] [HasLimitsOfShape Jᵒᵖ C] : CreatesColimitsOfShape J (forgetToPresheafedSpace : SheafedSpace.{_, _, v} C ⥤ _) := ⟨fun {K} => createsColimitOfFullyFaithfulOfIso ⟨(PresheafedSpace.colimitCocone (K ⋙ forgetToPresheafedSpace)).pt, limit_isSheaf _ fun j ↦ Sheaf.pushforward_sheaf_of_sheaf _ (K.obj (unop j)).2⟩ (colimit.isoColimitCocone ⟨_, PresheafedSpace.colimitCoconeIsColimit _⟩).symm⟩ noncomputable instance [HasLimits C] : CreatesColimits (forgetToPresheafedSpace : SheafedSpace C ⥤ _) where instance (J : Type w) [Category.{w'} J] [Small.{v} J] [HasLimitsOfShape Jᵒᵖ C] : HasColimitsOfShape J (SheafedSpace.{_, _, v} C) := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape forgetToPresheafedSpace instance [HasLimits C] : HasColimits.{v} (SheafedSpace C) where instance (J : Type w) [Category.{w'} J] [Small.{v} J] [HasLimitsOfShape Jᵒᵖ C] : PreservesColimitsOfShape J (forget.{_, _, v} C) := Limits.comp_preservesColimitsOfShape forgetToPresheafedSpace (PresheafedSpace.forget C) noncomputable instance [HasLimits C] : PreservesColimits (forget.{_, _, v} C) where section ConcreteCategory variable {FC : C → C → Type*} {CC : C → Type v} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [instCC : ConcreteCategory.{v} C FC] [HasColimits C] [HasLimits C] variable [PreservesLimits (CategoryTheory.forget C)] variable [PreservesFilteredColimits (CategoryTheory.forget C)] variable [(CategoryTheory.forget C).ReflectsIsomorphisms] attribute [local ext] DFunLike.ext in include instCC in lemma hom_stalk_ext {X Y : SheafedSpace C} (f g : X ⟶ Y) (h : f.base = g.base) (h' : ∀ x, f.stalkMap x = (Y.presheaf.stalkCongr (h ▸ rfl)).hom ≫ g.stalkMap x) : f = g := by obtain ⟨f, fc⟩ := f obtain ⟨g, gc⟩ := g obtain rfl : f = g := h congr ext U s refine section_ext X.sheaf _ _ _ fun x hx ↦ show X.presheaf.germ _ x _ _ = X.presheaf.germ _ x _ _ from ?_ erw [← PresheafedSpace.stalkMap_germ_apply ⟨f, fc⟩, ← PresheafedSpace.stalkMap_germ_apply ⟨f, gc⟩] simp [h'] attribute [local ext] DFunLike.ext in include instCC in lemma mono_of_base_injective_of_stalk_epi {X Y : SheafedSpace C} (f : X ⟶ Y) (h₁ : Function.Injective f.base) (h₂ : ∀ x, Epi (f.stalkMap x)) : Mono f := by constructor intro Z ⟨g, gc⟩ ⟨h, hc⟩ e obtain rfl : g = h := ConcreteCategory.hom_ext _ _ fun x ↦ h₁ congr(($e).base x) refine SheafedSpace.hom_stalk_ext ⟨g, gc⟩ ⟨g, hc⟩ rfl fun x ↦ ?_ rw [← cancel_epi (f.stalkMap (g x)), stalkCongr_hom, stalkSpecializes_refl, Category.id_comp, ← PresheafedSpace.stalkMap.comp ⟨g, gc⟩ f, ← PresheafedSpace.stalkMap.comp ⟨g, hc⟩ f] congr 1 attribute [local ext] DFunLike.ext in include instCC in lemma epi_of_base_surjective_of_stalk_mono {X Y : SheafedSpace C} (f : X ⟶ Y) (h₁ : Function.Surjective f.base) (h₂ : ∀ x, Mono (f.stalkMap x)) : Epi f := by constructor intro Z ⟨g, gc⟩ ⟨h, hc⟩ e obtain rfl : g = h := ConcreteCategory.hom_ext _ _ fun y ↦ by rw [← (h₁ y).choose_spec] simpa using congr(($e).base.hom (h₁ y).choose) refine SheafedSpace.hom_stalk_ext ⟨g, gc⟩ ⟨g, hc⟩ rfl fun y ↦ ?_ rw [← (h₁ y).choose_spec, ← cancel_mono (f.stalkMap (h₁ y).choose), stalkCongr_hom, stalkSpecializes_refl, Category.id_comp, ← PresheafedSpace.stalkMap.comp f ⟨g, gc⟩, ← PresheafedSpace.stalkMap.comp f ⟨g, hc⟩] congr 1 end ConcreteCategory end SheafedSpace end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/OpenImmersion.lean
import Mathlib.Topology.Category.TopCat.Limits.Pullbacks import Mathlib.Geometry.RingedSpace.LocallyRingedSpace /-! # Open immersions of structured spaces We say that a morphism of presheafed spaces `f : X ⟶ Y` is an open immersion if the underlying map of spaces is an open embedding `f : X ⟶ U ⊆ Y`, and the sheaf map `Y(V) ⟶ f _* X(V)` is an iso for each `V ⊆ U`. Abbreviations are also provided for `SheafedSpace`, `LocallyRingedSpace` and `Scheme`. ## Main definitions * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion`: the `Prop`-valued typeclass asserting that a PresheafedSpace hom `f` is an open_immersion. * `AlgebraicGeometry.IsOpenImmersion`: the `Prop`-valued typeclass asserting that a Scheme morphism `f` is an open_immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.isoRestrict`: The source of an open immersion is isomorphic to the restriction of the target onto the image. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.lift`: Any morphism whose range is contained in an open immersion factors through the open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.toSheafedSpace`: If `f : X ⟶ Y` is an open immersion of presheafed spaces, and `Y` is a sheafed space, then `X` is also a sheafed space. The morphism as morphisms of sheafed spaces is given by `toSheafedSpaceHom`. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.toLocallyRingedSpace`: If `f : X ⟶ Y` is an open immersion of presheafed spaces, and `Y` is a locally ringed space, then `X` is also a locally ringed space. The morphism as morphisms of locally ringed spaces is given by `toLocallyRingedSpaceHom`. ## Main results * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.comp`: The composition of two open immersions is an open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.ofIso`: An iso is an open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.to_iso`: A surjective open immersion is an isomorphism. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.stalk_iso`: An open immersion induces an isomorphism on stalks. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.hasPullback_of_left`: If `f` is an open immersion, then the pullback `(f, g)` exists (and the forgetful functor to `TopCat` preserves it). * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.pullbackSndOfLeft`: Open immersions are stable under pullbacks. * `AlgebraicGeometry.SheafedSpace.IsOpenImmersion.of_stalk_iso`: An (topological) open embedding between two sheafed spaces is an open immersion if all the stalk maps are isomorphisms. -/ open TopologicalSpace CategoryTheory Opposite Topology open CategoryTheory.Limits namespace AlgebraicGeometry universe w v v₁ v₂ u variable {C : Type u} [Category.{v} C] /-- An open immersion of PresheafedSpaces is an open embedding `f : X ⟶ U ⊆ Y` of the underlying spaces, such that the sheaf map `Y(V) ⟶ f _* X(V)` is an iso for each `V ⊆ U`. -/ class PresheafedSpace.IsOpenImmersion {X Y : PresheafedSpace C} (f : X ⟶ Y) : Prop where /-- the underlying continuous map of underlying spaces from the source to an open subset of the target. -/ base_open : IsOpenEmbedding f.base /-- the underlying sheaf morphism is an isomorphism on each open subset -/ c_iso : ∀ U : Opens X, IsIso (f.c.app (op (base_open.isOpenMap.functor.obj U))) /-- A morphism of SheafedSpaces is an open immersion if it is an open immersion as a morphism of PresheafedSpaces -/ abbrev SheafedSpace.IsOpenImmersion {X Y : SheafedSpace C} (f : X ⟶ Y) : Prop := PresheafedSpace.IsOpenImmersion f /-- A morphism of LocallyRingedSpaces is an open immersion if it is an open immersion as a morphism of SheafedSpaces -/ abbrev LocallyRingedSpace.IsOpenImmersion {X Y : LocallyRingedSpace} (f : X ⟶ Y) : Prop := SheafedSpace.IsOpenImmersion f.1 namespace PresheafedSpace.IsOpenImmersion open PresheafedSpace local notation "IsOpenImmersion" => PresheafedSpace.IsOpenImmersion attribute [instance] IsOpenImmersion.c_iso section variable {X Y : PresheafedSpace C} (f : X ⟶ Y) [H : IsOpenImmersion f] /-- The functor `Opens X ⥤ Opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev opensFunctor := H.base_open.isOpenMap.functor /-- An open immersion `f : X ⟶ Y` induces an isomorphism `X ≅ Y|_{f(X)}`. -/ @[simps! hom_c_app] noncomputable def isoRestrict : X ≅ Y.restrict H.base_open := PresheafedSpace.isoOfComponents (Iso.refl _) <| by symm fapply NatIso.ofComponents · intro U refine asIso (f.c.app (op (opensFunctor f |>.obj (unop U)))) ≪≫ X.presheaf.mapIso (eqToIso ?_) induction U with | op U => ?_ cases U dsimp only [IsOpenMap.functor, Functor.op, Opens.map] congr 2 erw [Set.preimage_image_eq _ H.base_open.injective] rfl · intro U V i dsimp simp only [NatTrans.naturality_assoc, TopCat.Presheaf.pushforward_obj_obj, TopCat.Presheaf.pushforward_obj_map, Quiver.Hom.unop_op, Category.assoc] rw [← X.presheaf.map_comp, ← X.presheaf.map_comp] congr 1 @[reassoc (attr := simp)] theorem isoRestrict_hom_ofRestrict : (isoRestrict f).hom ≫ Y.ofRestrict _ = f := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ rfl <| NatTrans.ext <| funext fun x => ?_ simp only [eqToHom_refl, Functor.whiskerRight_id'] erw [Category.comp_id, comp_c_app, f.c.naturality_assoc, ← X.presheaf.map_comp] trans f.c.app x ≫ X.presheaf.map (𝟙 _) · congr 1 · simp @[reassoc (attr := simp)] theorem isoRestrict_inv_ofRestrict : (isoRestrict f).inv ≫ f = Y.ofRestrict _ := by rw [Iso.inv_comp_eq, isoRestrict_hom_ofRestrict] instance mono : Mono f := by rw [← H.isoRestrict_hom_ofRestrict]; apply mono_comp lemma c_iso' {V : Opens Y} (U : Opens X) (h : V = (opensFunctor f).obj U) : IsIso (f.c.app (Opposite.op V)) := by subst h infer_instance /-- The composition of two open immersions is an open immersion. -/ instance comp {Z : PresheafedSpace C} (g : Y ⟶ Z) [hg : IsOpenImmersion g] : IsOpenImmersion (f ≫ g) where base_open := hg.base_open.comp H.base_open c_iso U := by generalize_proofs h dsimp only [AlgebraicGeometry.PresheafedSpace.comp_c_app, unop_op, Functor.op, comp_base, Opens.map_comp_obj] apply IsIso.comp_isIso' · exact c_iso' g ((opensFunctor f).obj U) (by ext; simp) · apply c_iso' f U ext1 dsimp only [Opens.map_coe, IsOpenMap.coe_functor_obj, comp_base, TopCat.coe_comp] rw [Set.image_comp, Set.preimage_image_eq _ hg.base_open.injective] /-- For an open immersion `f : X ⟶ Y` and an open set `U ⊆ X`, we have the map `X(U) ⟶ Y(U)`. -/ noncomputable def invApp (U : Opens X) : X.presheaf.obj (op U) ⟶ Y.presheaf.obj (op (opensFunctor f |>.obj U)) := X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) ≫ inv (f.c.app (op (opensFunctor f |>.obj U))) @[simp, reassoc] theorem inv_naturality {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) : X.presheaf.map i ≫ H.invApp _ (unop V) = invApp f (unop U) ≫ Y.presheaf.map (opensFunctor f |>.op.map i) := by simp only [invApp, ← Category.assoc] rw [IsIso.comp_inv_eq] simp only [Functor.op_obj, op_unop, ← X.presheaf.map_comp, Functor.op_map, Category.assoc, NatTrans.naturality, Quiver.Hom.unop_op, IsIso.inv_hom_id_assoc, TopCat.Presheaf.pushforward_obj_map] congr 1 instance (U : Opens X) : IsIso (invApp f U) := by delta invApp; infer_instance theorem inv_invApp (U : Opens X) : inv (H.invApp _ U) = f.c.app (op (opensFunctor f |>.obj U)) ≫ X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := by rw [← cancel_epi (H.invApp _ U), IsIso.hom_inv_id] delta invApp simp [← Functor.map_comp] @[simp, reassoc, elementwise] theorem invApp_app (U : Opens X) : invApp f U ≫ f.c.app (op (opensFunctor f |>.obj U)) = X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := by rw [invApp, Category.assoc, IsIso.inv_hom_id, Category.comp_id] @[simp, reassoc] theorem app_invApp (U : Opens Y) : f.c.app (op U) ≫ H.invApp _ ((Opens.map f.base).obj U) = Y.presheaf.map ((homOfLE (Set.image_preimage_subset f.base U.1)).op : op U ⟶ op (opensFunctor f |>.obj ((Opens.map f.base).obj U))) := by erw [← Category.assoc]; rw [IsIso.comp_inv_eq, f.c.naturality]; congr /-- A variant of `app_inv_app` that gives an `eqToHom` instead of `homOfLe`. -/ @[reassoc] theorem app_inv_app' (U : Opens Y) (hU : (U : Set Y) ⊆ Set.range f.base) : f.c.app (op U) ≫ invApp f ((Opens.map f.base).obj U) = Y.presheaf.map (eqToHom (le_antisymm (Set.image_preimage_subset f.base U.1) <| (Set.image_preimage_eq_inter_range (f := f.base) (t := U.1)).symm ▸ Set.subset_inter_iff.mpr ⟨fun _ h => h, hU⟩)).op := by simp only [TopCat.Presheaf.pushforward_obj_obj, app_invApp, Opens.carrier_eq_coe, homOfLE_leOfHom, eqToHom_op] tauto /-- An isomorphism is an open immersion. -/ instance ofIso {X Y : PresheafedSpace C} (H : X ≅ Y) : IsOpenImmersion H.hom where base_open := (TopCat.homeoOfIso ((forget C).mapIso H)).isOpenEmbedding -- Porting note: `inferInstance` will fail if Lean is not told that `H.hom.c` is iso c_iso _ := letI : IsIso H.hom.c := inferInstance; inferInstance instance (priority := 100) ofIsIso {X Y : PresheafedSpace C} (f : X ⟶ Y) [IsIso f] : IsOpenImmersion f := AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.ofIso (asIso f) instance ofRestrict {X : TopCat} (Y : PresheafedSpace C) {f : X ⟶ Y.carrier} (hf : IsOpenEmbedding f) : IsOpenImmersion (Y.ofRestrict hf) where base_open := hf c_iso U := by dsimp have : (Opens.map f).obj (hf.isOpenMap.functor.obj U) = U := by ext1 exact Set.preimage_image_eq _ hf.injective convert_to IsIso (Y.presheaf.map (𝟙 _)) · congr · -- Porting note: was `apply Subsingleton.helim; rw [this]` -- See https://github.com/leanprover/lean4/issues/2273 congr · simp only congr apply Subsingleton.helim rw [this] · infer_instance @[elementwise, simp] theorem ofRestrict_invApp {C : Type*} [Category C] (X : PresheafedSpace C) {Y : TopCat} {f : Y ⟶ TopCat.of X.carrier} (h : IsOpenEmbedding f) (U : Opens (X.restrict h).carrier) : (PresheafedSpace.IsOpenImmersion.ofRestrict X h).invApp _ U = 𝟙 _ := by delta invApp rw [IsIso.comp_inv_eq, Category.id_comp] change X.presheaf.map _ = X.presheaf.map _ congr 1 /-- An open immersion is an iso if the underlying continuous map is epi. -/ theorem to_iso [h' : Epi f.base] : IsIso f := by have : ∀ (U : (Opens Y)ᵒᵖ), IsIso (f.c.app U) := by intro U have : U = op (opensFunctor f |>.obj ((Opens.map f.base).obj (unop U))) := by induction U with | op U => ?_ cases U dsimp only [Functor.op, Opens.map] congr exact (Set.image_preimage_eq _ ((TopCat.epi_iff_surjective _).mp h')).symm convert H.c_iso (Opens.map f.base |>.obj <| unop U) have : IsIso f.c := NatIso.isIso_of_isIso_app _ apply (config := { allowSynthFailures := true }) isIso_of_components let t : X ≃ₜ Y := H.base_open.isEmbedding.toHomeomorph.trans { toFun := Subtype.val invFun := fun x => ⟨x, by rw [Set.range_eq_univ.mpr ((TopCat.epi_iff_surjective _).mp h')]; trivial⟩ } exact (TopCat.isoOfHomeo t).isIso_hom instance stalk_iso [HasColimits C] (x : X) : IsIso (f.stalkMap x) := by rw [← H.isoRestrict_hom_ofRestrict, PresheafedSpace.stalkMap.comp] infer_instance end noncomputable section Pullback variable {X Y Z : PresheafedSpace C} (f : X ⟶ Z) [hf : IsOpenImmersion f] (g : Y ⟶ Z) /-- (Implementation.) The projection map when constructing the pullback along an open immersion. -/ def pullbackConeOfLeftFst : Y.restrict (TopCat.snd_isOpenEmbedding_of_left hf.base_open g.base) ⟶ X where base := pullback.fst _ _ c := { app := fun U => hf.invApp _ (unop U) ≫ g.c.app (op (hf.base_open.isOpenMap.functor.obj (unop U))) ≫ Y.presheaf.map (eqToHom (by simp only [IsOpenMap.functor, op_inj_iff, Opens.map, Functor.op_obj] apply LE.le.antisymm · rintro _ ⟨_, h₁, h₂⟩ use (TopCat.pullbackIsoProdSubtype _ _).inv ⟨⟨_, _⟩, h₂⟩ -- Porting note: used to be `simpa using h₁` simp only [restrict_carrier, Opens.coe_mk, Set.mem_preimage, SetLike.mem_coe] -- The next `rw` can't be done by `simp`, but `restrict_carrier` can't be used -- by `rw`. rw [TopCat.pullbackIsoProdSubtype_inv_fst_apply, TopCat.pullbackIsoProdSubtype_inv_snd_apply] simpa using h₁ · rintro _ ⟨x, h₁, rfl⟩ exact ⟨_, h₁, CategoryTheory.congr_fun pullback.condition x⟩)) naturality := by intro U V i induction U induction V -- Note: this doesn't fire in `simp` because of reduction of the term via structure eta -- before discrimination tree key generation rw [inv_naturality_assoc] dsimp simp only [NatTrans.naturality_assoc, TopCat.Presheaf.pushforward_obj_map, Quiver.Hom.unop_op, ← Functor.map_comp, Category.assoc] rfl } theorem pullback_cone_of_left_condition : pullbackConeOfLeftFst f g ≫ f = Y.ofRestrict _ ≫ g := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ ?_ <| NatTrans.ext <| funext fun U => ?_ · simpa using pullback.condition · induction U -- Porting note: `NatTrans.comp_app` is not picked up by `dsimp` -- Perhaps see : https://github.com/leanprover-community/mathlib4/issues/5026 rw [NatTrans.comp_app] dsimp only [comp_c_app, unop_op, Functor.whiskerRight_app, pullbackConeOfLeftFst] -- simp only [ofRestrict_c_app, NatTrans.comp_app] simp only [app_invApp_assoc, eqToHom_app, Category.assoc, NatTrans.naturality_assoc] erw [← Y.presheaf.map_comp, ← Y.presheaf.map_comp] congr 1 /-- We construct the pullback along an open immersion via restricting along the pullback of the maps of underlying spaces (which is also an open embedding). -/ def pullbackConeOfLeft : PullbackCone f g := PullbackCone.mk (pullbackConeOfLeftFst f g) (Y.ofRestrict _) (pullback_cone_of_left_condition f g) variable (s : PullbackCone f g) /-- (Implementation.) Any cone over `cospan f g` indeed factors through the constructed cone. -/ def pullbackConeOfLeftLift : s.pt ⟶ (pullbackConeOfLeft f g).pt where base := pullback.lift s.fst.base s.snd.base (congr_arg (fun x => PresheafedSpace.Hom.base x) s.condition) c := { app := fun U => s.snd.c.app _ ≫ s.pt.presheaf.map (eqToHom (by dsimp only [Opens.map, IsOpenMap.functor, Functor.op] congr 2 let s' : PullbackCone f.base g.base := PullbackCone.mk s.fst.base s.snd.base (congr_arg Hom.base s.condition) have : _ = s.snd.base := limit.lift_π s' WalkingCospan.right conv_lhs => rw [← this] dsimp [s'] rw [Function.comp_def, ← Set.preimage_preimage] rw [Set.preimage_image_eq _ (TopCat.snd_isOpenEmbedding_of_left hf.base_open g.base).injective] rfl)) naturality := fun U V i => by erw [s.snd.c.naturality_assoc] rw [Category.assoc] erw [← s.pt.presheaf.map_comp, ← s.pt.presheaf.map_comp] congr 1 } -- this lemma is not a `simp` lemma, because it is an implementation detail theorem pullbackConeOfLeftLift_fst : pullbackConeOfLeftLift f g s ≫ (pullbackConeOfLeft f g).fst = s.fst := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ ?_ <| NatTrans.ext <| funext fun x => ?_ · change pullback.lift _ _ _ ≫ pullback.fst _ _ = _ simp · induction x with | op x => ?_ change ((_ ≫ _) ≫ _ ≫ _) ≫ _ = _ simp_rw [Category.assoc] erw [← s.pt.presheaf.map_comp] erw [s.snd.c.naturality_assoc] have := congr_app s.condition (op (opensFunctor f |>.obj x)) dsimp only [comp_c_app, unop_op] at this rw [← IsIso.comp_inv_eq] at this replace this := reassoc_of% this erw [← this, hf.invApp_app_assoc, s.fst.c.naturality_assoc] simp [eqToHom_map] -- this lemma is not a `simp` lemma, because it is an implementation detail theorem pullbackConeOfLeftLift_snd : pullbackConeOfLeftLift f g s ≫ (pullbackConeOfLeft f g).snd = s.snd := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ ?_ <| NatTrans.ext <| funext fun x => ?_ · change pullback.lift _ _ _ ≫ pullback.snd _ _ = _ simp · change (_ ≫ _ ≫ _) ≫ _ = _ simp_rw [Category.assoc] erw [s.snd.c.naturality_assoc] erw [← s.pt.presheaf.map_comp, ← s.pt.presheaf.map_comp] trans s.snd.c.app x ≫ s.pt.presheaf.map (𝟙 _) · congr 1 · simp instance pullbackConeSndIsOpenImmersion : IsOpenImmersion (pullbackConeOfLeft f g).snd := by erw [CategoryTheory.Limits.PullbackCone.mk_snd] infer_instance /-- The constructed pullback cone is indeed the pullback. -/ def pullbackConeOfLeftIsLimit : IsLimit (pullbackConeOfLeft f g) := by apply PullbackCone.isLimitAux' intro s use pullbackConeOfLeftLift f g s use pullbackConeOfLeftLift_fst f g s use pullbackConeOfLeftLift_snd f g s intro m _ h₂ rw [← cancel_mono (pullbackConeOfLeft f g).snd] exact h₂.trans (pullbackConeOfLeftLift_snd f g s).symm instance hasPullback_of_left : HasPullback f g := ⟨⟨⟨_, pullbackConeOfLeftIsLimit f g⟩⟩⟩ instance hasPullback_of_right : HasPullback g f := hasPullback_symmetry f g /-- Open immersions are stable under base-change. -/ instance pullbackSndOfLeft : IsOpenImmersion (pullback.snd f g) := by delta pullback.snd rw [← limit.isoLimitCone_hom_π ⟨_, pullbackConeOfLeftIsLimit f g⟩ WalkingCospan.right] infer_instance /-- Open immersions are stable under base-change. -/ instance pullbackFstOfRight : IsOpenImmersion (pullback.fst g f) := by rw [← pullbackSymmetry_hom_comp_snd] infer_instance instance pullbackToBaseIsOpenImmersion [IsOpenImmersion g] : IsOpenImmersion (limit.π (cospan f g) WalkingCospan.one) := by rw [← limit.w (cospan f g) WalkingCospan.Hom.inl, cospan_map_inl] infer_instance instance forget_preservesLimitsOfLeft : PreservesLimit (cospan f g) (forget C) := preservesLimit_of_preserves_limit_cone (pullbackConeOfLeftIsLimit f g) (by apply (IsLimit.postcomposeHomEquiv (diagramIsoCospan _) _).toFun refine (IsLimit.equivIsoLimit ?_).toFun (limit.isLimit (cospan f.base g.base)) fapply Cones.ext · exact Iso.refl _ change ∀ j, _ = 𝟙 _ ≫ _ ≫ _ simp_rw [Category.id_comp] rintro (_ | _ | _) <;> symm · simp only [limit.cone_x, Functor.const_obj_obj, cospan_one, Functor.comp_obj, forget_obj, Functor.mapCone_pt, Functor.mapCone_π_app, PullbackCone.condition_one, forget_map, comp_base, cospan_left, cospan_right, Functor.comp_map, cospan_map_inl, cospan_map_inr, diagramIsoCospan_hom_app, PullbackCone.fst_limit_cone] tauto · exact Category.comp_id _ · exact Category.comp_id _) instance forget_preservesLimitsOfRight : PreservesLimit (cospan g f) (forget C) := preservesPullback_symmetry (forget C) f g theorem pullback_snd_isIso_of_range_subset (H : Set.range g.base ⊆ Set.range f.base) : IsIso (pullback.snd f g) := by haveI := TopCat.snd_iso_of_left_embedding_range_subset hf.base_open.isEmbedding g.base H have : IsIso (pullback.snd f g).base := by delta pullback.snd rw [← limit.isoLimitCone_hom_π ⟨_, pullbackConeOfLeftIsLimit f g⟩ WalkingCospan.right] change IsIso (_ ≫ pullback.snd _ _) infer_instance apply to_iso /-- The universal property of open immersions: For an open immersion `f : X ⟶ Z`, given any morphism of schemes `g : Y ⟶ Z` whose topological image is contained in the image of `f`, we can lift this morphism to a unique `Y ⟶ X` that commutes with these maps. -/ def lift (H : Set.range g.base ⊆ Set.range f.base) : Y ⟶ X := haveI := pullback_snd_isIso_of_range_subset f g H inv (pullback.snd f g) ≫ pullback.fst _ _ @[simp, reassoc] theorem lift_fac (H : Set.range g.base ⊆ Set.range f.base) : lift f g H ≫ f = g := by erw [Category.assoc]; rw [IsIso.inv_comp_eq]; exact pullback.condition theorem lift_uniq (H : Set.range g.base ⊆ Set.range f.base) (l : Y ⟶ X) (hl : l ≫ f = g) : l = lift f g H := by rw [← cancel_mono f, hl, lift_fac] /-- Two open immersions with equal range is isomorphic. -/ @[simps] def isoOfRangeEq [IsOpenImmersion g] (e : Set.range f.base = Set.range g.base) : X ≅ Y where hom := lift g f (le_of_eq e) inv := lift f g (le_of_eq e.symm) hom_inv_id := by rw [← cancel_mono f]; simp inv_hom_id := by rw [← cancel_mono g]; simp end Pullback open CategoryTheory.Limits.WalkingCospan section ToSheafedSpace variable {X : PresheafedSpace C} (Y : SheafedSpace C) /-- If `X ⟶ Y` is an open immersion, and `Y` is a SheafedSpace, then so is `X`. -/ def toSheafedSpace (f : X ⟶ Y.toPresheafedSpace) [H : IsOpenImmersion f] : SheafedSpace C where IsSheaf := by apply TopCat.Presheaf.isSheaf_of_iso (sheafIsoOfIso (isoRestrict f).symm).symm apply TopCat.Sheaf.pushforward_sheaf_of_sheaf exact (Y.restrict H.base_open).IsSheaf toPresheafedSpace := X variable (f : X ⟶ Y.toPresheafedSpace) [H : IsOpenImmersion f] @[simp] theorem toSheafedSpace_toPresheafedSpace : (toSheafedSpace Y f).toPresheafedSpace = X := rfl /-- If `X ⟶ Y` is an open immersion of PresheafedSpaces, and `Y` is a SheafedSpace, we can upgrade it into a morphism of SheafedSpaces. -/ def toSheafedSpaceHom : toSheafedSpace Y f ⟶ Y := f @[simp] theorem toSheafedSpaceHom_base : (toSheafedSpaceHom Y f).base = f.base := rfl @[simp] theorem toSheafedSpaceHom_c : (toSheafedSpaceHom Y f).c = f.c := rfl instance toSheafedSpace_isOpenImmersion : SheafedSpace.IsOpenImmersion (toSheafedSpaceHom Y f) := H @[simp] theorem sheafedSpace_toSheafedSpace {X Y : SheafedSpace C} (f : X ⟶ Y) [IsOpenImmersion f] : toSheafedSpace Y f = X := by cases X; rfl end ToSheafedSpace section ToLocallyRingedSpace variable {X : PresheafedSpace CommRingCat} (Y : LocallyRingedSpace) variable (f : X ⟶ Y.toPresheafedSpace) [H : IsOpenImmersion f] /-- If `X ⟶ Y` is an open immersion, and `Y` is a LocallyRingedSpace, then so is `X`. -/ def toLocallyRingedSpace : LocallyRingedSpace where toSheafedSpace := toSheafedSpace Y.toSheafedSpace f isLocalRing x := haveI : IsLocalRing (Y.presheaf.stalk (f.base x)) := Y.isLocalRing _ (asIso (f.stalkMap x)).commRingCatIsoToRingEquiv.isLocalRing @[simp] theorem toLocallyRingedSpace_toSheafedSpace : (toLocallyRingedSpace Y f).toSheafedSpace = toSheafedSpace Y.1 f := rfl /-- If `X ⟶ Y` is an open immersion of PresheafedSpaces, and `Y` is a LocallyRingedSpace, we can upgrade it into a morphism of LocallyRingedSpace. -/ def toLocallyRingedSpaceHom : toLocallyRingedSpace Y f ⟶ Y := ⟨f, fun _ => inferInstance⟩ @[simp] theorem toLocallyRingedSpaceHom_val : (toLocallyRingedSpaceHom Y f).toShHom = f := rfl instance toLocallyRingedSpace_isOpenImmersion : LocallyRingedSpace.IsOpenImmersion (toLocallyRingedSpaceHom Y f) := H @[simp] theorem locallyRingedSpace_toLocallyRingedSpace {X Y : LocallyRingedSpace} (f : X ⟶ Y) [LocallyRingedSpace.IsOpenImmersion f] : toLocallyRingedSpace Y f.1 = X := rfl end ToLocallyRingedSpace theorem isIso_of_subset {X Y : PresheafedSpace C} (f : X ⟶ Y) [H : PresheafedSpace.IsOpenImmersion f] (U : Opens Y.carrier) (hU : (U : Set Y.carrier) ⊆ Set.range f.base) : IsIso (f.c.app <| op U) := by have : U = H.base_open.isOpenMap.functor.obj ((Opens.map f.base).obj U) := by ext1 exact (Set.inter_eq_left.mpr hU).symm.trans Set.image_preimage_eq_inter_range.symm convert H.c_iso ((Opens.map f.base).obj U) end PresheafedSpace.IsOpenImmersion namespace SheafedSpace.IsOpenImmersion instance (priority := 100) of_isIso {X Y : SheafedSpace C} (f : X ⟶ Y) [IsIso f] : SheafedSpace.IsOpenImmersion f := @PresheafedSpace.IsOpenImmersion.ofIsIso _ _ _ _ f (SheafedSpace.forgetToPresheafedSpace.map_isIso _) instance comp {X Y Z : SheafedSpace C} (f : X ⟶ Y) (g : Y ⟶ Z) [SheafedSpace.IsOpenImmersion f] [SheafedSpace.IsOpenImmersion g] : SheafedSpace.IsOpenImmersion (f ≫ g) := PresheafedSpace.IsOpenImmersion.comp f g noncomputable section Pullback variable {X Y Z : SheafedSpace C} (f : X ⟶ Z) (g : Y ⟶ Z) variable [H : SheafedSpace.IsOpenImmersion f] /-- This is often wrapped in parentheses to distinguish with the forgetful functor. -/ local notation "forget" => SheafedSpace.forgetToPresheafedSpace open CategoryTheory.Limits.WalkingCospan instance : Mono f := (forget).mono_of_mono_map (show @Mono (PresheafedSpace C) _ _ _ f by infer_instance) instance forgetMapIsOpenImmersion : PresheafedSpace.IsOpenImmersion ((forget).map f) := ⟨H.base_open, H.c_iso⟩ instance hasLimit_cospan_forget_of_left : HasLimit (cospan f g ⋙ forget) := by have : HasLimit (cospan ((cospan f g ⋙ forget).map Hom.inl) ((cospan f g ⋙ forget).map Hom.inr)) := by change HasLimit (cospan ((forget).map f) ((forget).map g)) infer_instance apply hasLimit_of_iso (diagramIsoCospan _).symm instance hasLimit_cospan_forget_of_left' : HasLimit (cospan ((cospan f g ⋙ forget).map Hom.inl) ((cospan f g ⋙ forget).map Hom.inr)) := show HasLimit (cospan ((forget).map f) ((forget).map g)) from inferInstance instance hasLimit_cospan_forget_of_right : HasLimit (cospan g f ⋙ forget) := by have : HasLimit (cospan ((cospan g f ⋙ forget).map Hom.inl) ((cospan g f ⋙ forget).map Hom.inr)) := by change HasLimit (cospan ((forget).map g) ((forget).map f)) infer_instance apply hasLimit_of_iso (diagramIsoCospan _).symm instance hasLimit_cospan_forget_of_right' : HasLimit (cospan ((cospan g f ⋙ forget).map Hom.inl) ((cospan g f ⋙ forget).map Hom.inr)) := show HasLimit (cospan ((forget).map g) ((forget).map f)) from inferInstance instance forgetCreatesPullbackOfLeft : CreatesLimit (cospan f g) forget := createsLimitOfFullyFaithfulOfIso (PresheafedSpace.IsOpenImmersion.toSheafedSpace Y (@pullback.snd (PresheafedSpace C) _ _ _ _ f g _)) (eqToIso (show pullback _ _ = pullback _ _ by congr) ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _).symm) instance forgetCreatesPullbackOfRight : CreatesLimit (cospan g f) forget := createsLimitOfFullyFaithfulOfIso (PresheafedSpace.IsOpenImmersion.toSheafedSpace Y (@pullback.fst (PresheafedSpace C) _ _ _ _ g f _)) (eqToIso (show pullback _ _ = pullback _ _ by congr) ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _).symm) instance sheafedSpace_forgetPreserves_of_left : PreservesLimit (cospan f g) (SheafedSpace.forget C) := @Limits.comp_preservesLimit _ _ _ _ _ _ (cospan f g) _ _ forget (PresheafedSpace.forget C) inferInstance <| by have : PreservesLimit (cospan ((cospan f g ⋙ forget).map Hom.inl) ((cospan f g ⋙ forget).map Hom.inr)) (PresheafedSpace.forget C) := by dsimp infer_instance apply preservesLimit_of_iso_diagram _ (diagramIsoCospan _).symm instance sheafedSpace_forgetPreserves_of_right : PreservesLimit (cospan g f) (SheafedSpace.forget C) := preservesPullback_symmetry _ _ _ instance sheafedSpace_hasPullback_of_left : HasPullback f g := hasLimit_of_created (cospan f g) forget instance sheafedSpace_hasPullback_of_right : HasPullback g f := hasLimit_of_created (cospan g f) forget /-- Open immersions are stable under base-change. -/ instance sheafedSpace_pullback_snd_of_left : SheafedSpace.IsOpenImmersion (pullback.snd f g) := by delta pullback.snd have : _ = limit.π (cospan f g) right := preservesLimitIso_hom_π forget (cospan f g) right rw [← this] have := HasLimit.isoOfNatIso_hom_π (diagramIsoCospan (cospan f g ⋙ forget)) right erw [Category.comp_id] at this rw [← this] dsimp infer_instance instance sheafedSpace_pullback_fst_of_right : SheafedSpace.IsOpenImmersion (pullback.fst g f) := by delta pullback.fst have : _ = limit.π (cospan g f) left := preservesLimitIso_hom_π forget (cospan g f) left rw [← this] have := HasLimit.isoOfNatIso_hom_π (diagramIsoCospan (cospan g f ⋙ forget)) left erw [Category.comp_id] at this rw [← this] dsimp infer_instance instance sheafedSpace_pullback_to_base_isOpenImmersion [SheafedSpace.IsOpenImmersion g] : SheafedSpace.IsOpenImmersion (limit.π (cospan f g) one : pullback f g ⟶ Z) := by rw [← limit.w (cospan f g) Hom.inl, cospan_map_inl] infer_instance end Pullback section OfStalkIso variable [HasLimits C] [HasColimits C] {FC : C → C → Type*} {CC : C → Type v} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [instCC : ConcreteCategory.{v} C FC] variable [(CategoryTheory.forget C).ReflectsIsomorphisms] [PreservesLimits (CategoryTheory.forget C)] variable [PreservesFilteredColimits (CategoryTheory.forget C)] include instCC in /-- Suppose `X Y : SheafedSpace C`, where `C` is a concrete category, whose forgetful functor reflects isomorphisms, preserves limits and filtered colimits. Then a morphism `X ⟶ Y` that is a topological open embedding is an open immersion iff every stalk map is an iso. -/ theorem of_stalk_iso {X Y : SheafedSpace C} (f : X ⟶ Y) (hf : IsOpenEmbedding f.base) [H : ∀ x : X.1, IsIso (f.stalkMap x)] : SheafedSpace.IsOpenImmersion f := { base_open := hf c_iso := fun U => by apply (config := {allowSynthFailures := true}) TopCat.Presheaf.app_isIso_of_stalkFunctor_map_iso (show Y.sheaf ⟶ (TopCat.Sheaf.pushforward _ f.base).obj X.sheaf from ⟨f.c⟩) rintro ⟨_, y, hy, rfl⟩ specialize H y delta PresheafedSpace.Hom.stalkMap at H haveI H' := TopCat.Presheaf.stalkPushforward.stalkPushforward_iso_of_isInducing C hf.toIsInducing X.presheaf y have := IsIso.comp_isIso' H (@IsIso.inv_isIso _ _ _ _ _ H') rwa [Category.assoc, IsIso.hom_inv_id, Category.comp_id] at this } end OfStalkIso section variable {X Y : SheafedSpace C} (f : X ⟶ Y) [H : IsOpenImmersion f] /-- The functor `Opens X ⥤ Opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev opensFunctor : Opens X ⥤ Opens Y := H.base_open.isOpenMap.functor /-- An open immersion `f : X ⟶ Y` induces an isomorphism `X ≅ Y|_{f(X)}`. -/ @[simps! hom_c_app] noncomputable def isoRestrict : X ≅ Y.restrict H.base_open := SheafedSpace.isoMk <| PresheafedSpace.IsOpenImmersion.isoRestrict f @[reassoc (attr := simp)] theorem isoRestrict_hom_ofRestrict : (isoRestrict f).hom ≫ Y.ofRestrict _ = f := PresheafedSpace.IsOpenImmersion.isoRestrict_hom_ofRestrict f @[reassoc (attr := simp)] theorem isoRestrict_inv_ofRestrict : (isoRestrict f).inv ≫ f = Y.ofRestrict _ := PresheafedSpace.IsOpenImmersion.isoRestrict_inv_ofRestrict f /-- For an open immersion `f : X ⟶ Y` and an open set `U ⊆ X`, we have the map `X(U) ⟶ Y(U)`. -/ noncomputable def invApp (U : Opens X) : X.presheaf.obj (op U) ⟶ Y.presheaf.obj (op (opensFunctor f |>.obj U)) := PresheafedSpace.IsOpenImmersion.invApp f U @[reassoc (attr := simp)] theorem inv_naturality {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) : X.presheaf.map i ≫ H.invApp _ (unop V) = H.invApp _ (unop U) ≫ Y.presheaf.map (opensFunctor f |>.op.map i) := PresheafedSpace.IsOpenImmersion.inv_naturality f i instance (U : Opens X) : IsIso (H.invApp _ U) := by delta invApp; infer_instance theorem inv_invApp (U : Opens X) : inv (H.invApp _ U) = f.c.app (op (opensFunctor f |>.obj U)) ≫ X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := PresheafedSpace.IsOpenImmersion.inv_invApp f U @[reassoc (attr := simp)] theorem invApp_app (U : Opens X) : H.invApp _ U ≫ f.c.app (op (opensFunctor f |>.obj U)) = X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := PresheafedSpace.IsOpenImmersion.invApp_app f U attribute [elementwise] invApp_app @[reassoc (attr := simp)] theorem app_invApp (U : Opens Y) : f.c.app (op U) ≫ H.invApp _ ((Opens.map f.base).obj U) = Y.presheaf.map ((homOfLE (Set.image_preimage_subset f.base U.1)).op : op U ⟶ op (opensFunctor f |>.obj ((Opens.map f.base).obj U))) := PresheafedSpace.IsOpenImmersion.app_invApp f U /-- A variant of `app_inv_app` that gives an `eqToHom` instead of `homOfLe`. -/ @[reassoc] theorem app_inv_app' (U : Opens Y) (hU : (U : Set Y) ⊆ Set.range f.base) : f.c.app (op U) ≫ invApp f ((Opens.map f.base).obj U) = Y.presheaf.map (eqToHom <| le_antisymm (Set.image_preimage_subset f.base U.1) <| (Set.image_preimage_eq_inter_range (f := f.base) (t := U.1)).symm ▸ Set.subset_inter_iff.mpr ⟨fun _ h => h, hU⟩).op := PresheafedSpace.IsOpenImmersion.app_invApp f U instance ofRestrict {X : TopCat} (Y : SheafedSpace C) {f : X ⟶ Y.carrier} (hf : IsOpenEmbedding f) : IsOpenImmersion (Y.ofRestrict hf) := PresheafedSpace.IsOpenImmersion.ofRestrict _ hf @[elementwise, simp] theorem ofRestrict_invApp {C : Type*} [Category C] (X : SheafedSpace C) {Y : TopCat} {f : Y ⟶ TopCat.of X.carrier} (h : IsOpenEmbedding f) (U : Opens (X.restrict h).carrier) : (SheafedSpace.IsOpenImmersion.ofRestrict X h).invApp _ U = 𝟙 _ := PresheafedSpace.IsOpenImmersion.ofRestrict_invApp _ h U /-- An open immersion is an iso if the underlying continuous map is epi. -/ theorem to_iso [h' : Epi f.base] : IsIso f := by haveI : IsIso (forgetToPresheafedSpace.map f) := PresheafedSpace.IsOpenImmersion.to_iso f apply isIso_of_reflects_iso _ (SheafedSpace.forgetToPresheafedSpace) instance stalk_iso [HasColimits C] (x : X) : IsIso (f.stalkMap x) := PresheafedSpace.IsOpenImmersion.stalk_iso f x end section Prod -- here `ι` should have same universe level as morphism of `C`, so needs explicit universe level variable [HasLimits C] {ι : Type v} (F : Discrete ι ⥤ SheafedSpace.{_, v, v} C) [HasColimit F] (i : Discrete ι) theorem sigma_ι_isOpenEmbedding : IsOpenEmbedding (colimit.ι F i).base := by rw [← show _ = (colimit.ι F i).base from ι_preservesColimitIso_inv (SheafedSpace.forget C) F i] have : _ = _ ≫ colimit.ι (Discrete.functor ((F ⋙ SheafedSpace.forget C).obj ∘ Discrete.mk)) i := HasColimit.isoOfNatIso_ι_hom Discrete.natIsoFunctor i rw [← Iso.eq_comp_inv] at this rw [this] have : colimit.ι _ _ ≫ _ = _ := TopCat.sigmaIsoSigma_hom_ι.{v, v} ((F ⋙ SheafedSpace.forget C).obj ∘ Discrete.mk) i.as rw [← Iso.eq_comp_inv] at this cases i rw [this, ← Category.assoc] simp_rw [TopCat.isOpenEmbedding_iff_comp_isIso] -- Porting note: `simp_rw` can't use `TopCat.isOpenEmbedding_iff_isIso_comp`. -- See https://github.com/leanprover-community/mathlib4/issues/5026 rw [TopCat.isOpenEmbedding_iff_isIso_comp] exact .sigmaMk theorem image_preimage_is_empty (j : Discrete ι) (h : i ≠ j) (U : Opens (F.obj i)) : (Opens.map (colimit.ι (F ⋙ SheafedSpace.forgetToPresheafedSpace) j).base).obj ((Opens.map (preservesColimitIso SheafedSpace.forgetToPresheafedSpace F).inv.base).obj ((sigma_ι_isOpenEmbedding F i).isOpenMap.functor.obj U)) = ⊥ := by ext x apply iff_false_intro rintro ⟨y, hy, eq⟩ replace eq := ConcreteCategory.congr_arg (preservesColimitIso (SheafedSpace.forget C) F ≪≫ HasColimit.isoOfNatIso Discrete.natIsoFunctor ≪≫ TopCat.sigmaIsoSigma.{v, v} _).hom eq simp_rw [CategoryTheory.Iso.trans_hom, ← TopCat.comp_app, ← PresheafedSpace.comp_base] at eq rw [ι_preservesColimitIso_inv] at eq change ((SheafedSpace.forget C).map (colimit.ι F i) ≫ _) y = ((SheafedSpace.forget C).map (colimit.ι F j) ≫ _) x at eq cases i; cases j rw [ι_preservesColimitIso_hom_assoc, ι_preservesColimitIso_hom_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, TopCat.sigmaIsoSigma_hom_ι, TopCat.sigmaIsoSigma_hom_ι] at eq exact h (congr_arg Discrete.mk (congr_arg Sigma.fst eq)) instance sigma_ι_isOpenImmersion_aux [HasStrictTerminalObjects C] : SheafedSpace.IsOpenImmersion (colimit.ι F i) where base_open := sigma_ι_isOpenEmbedding F i c_iso U := by have e : colimit.ι F i = _ := (ι_preservesColimitIso_inv SheafedSpace.forgetToPresheafedSpace F i).symm have H : IsOpenEmbedding (colimit.ι (F ⋙ SheafedSpace.forgetToPresheafedSpace) i ≫ (preservesColimitIso SheafedSpace.forgetToPresheafedSpace F).inv).base := e ▸ sigma_ι_isOpenEmbedding F i suffices IsIso <| (colimit.ι (F ⋙ SheafedSpace.forgetToPresheafedSpace) i ≫ (preservesColimitIso SheafedSpace.forgetToPresheafedSpace F).inv).c.app <| op (H.isOpenMap.functor.obj U) by convert this rw [PresheafedSpace.comp_c_app, ← PresheafedSpace.colimitPresheafObjIsoComponentwiseLimit_hom_π] -- Porting note: this instance created manually to make the `inferInstance` below work have inst1 : IsIso (preservesColimitIso forgetToPresheafedSpace F).inv.c := inferInstance rsuffices : IsIso (limit.π (PresheafedSpace.componentwiseDiagram (F ⋙ SheafedSpace.forgetToPresheafedSpace) ((Opens.map (preservesColimitIso SheafedSpace.forgetToPresheafedSpace F).inv.base).obj (unop <| op <| H.isOpenMap.functor.obj U))) (op i)) · infer_instance apply limit_π_isIso_of_is_strict_terminal intro j hj induction j with | op j => ?_ dsimp convert (F.obj j).sheaf.isTerminalOfEmpty using 3 convert image_preimage_is_empty F i j (fun h => hj (congr_arg op h.symm)) U using 6 exact (congr_arg PresheafedSpace.Hom.base e).symm instance sigma_ι_isOpenImmersion {ι : Type w} [Small.{v} ι] (F : Discrete ι ⥤ SheafedSpace.{_, v, v} C) [HasColimit F] (i : Discrete ι) [HasStrictTerminalObjects C] : SheafedSpace.IsOpenImmersion (colimit.ι F i) := by obtain ⟨ι', ⟨e⟩⟩ := Small.equiv_small (α := ι) let f : Discrete ι' ≌ Discrete ι := Discrete.equivalence e.symm have : colimit.ι F i = (colimit.ι F i ≫ (HasColimit.isoOfEquivalence f (Iso.refl _)).inv) ≫ (HasColimit.isoOfEquivalence f (Iso.refl _)).hom := by simp rw [this, HasColimit.isoOfEquivalence_inv_π] infer_instance end Prod end SheafedSpace.IsOpenImmersion namespace LocallyRingedSpace.IsOpenImmersion instance (X : LocallyRingedSpace) {U : TopCat} (f : U ⟶ X.toTopCat) (hf : IsOpenEmbedding f) : LocallyRingedSpace.IsOpenImmersion (X.ofRestrict hf) := PresheafedSpace.IsOpenImmersion.ofRestrict X.toPresheafedSpace hf noncomputable section Pullback variable {X Y Z : LocallyRingedSpace} (f : X ⟶ Z) (g : Y ⟶ Z) variable [H : LocallyRingedSpace.IsOpenImmersion f] instance (priority := 100) of_isIso [IsIso g] : LocallyRingedSpace.IsOpenImmersion g := @PresheafedSpace.IsOpenImmersion.ofIsIso _ _ _ _ g.1 ⟨⟨(inv g).1, by erw [← LocallyRingedSpace.comp_toShHom]; rw [IsIso.hom_inv_id] erw [← LocallyRingedSpace.comp_toShHom]; rw [IsIso.inv_hom_id]; constructor <;> rfl⟩⟩ instance comp (g : Z ⟶ Y) [LocallyRingedSpace.IsOpenImmersion g] : LocallyRingedSpace.IsOpenImmersion (f ≫ g) := PresheafedSpace.IsOpenImmersion.comp f.1 g.1 instance mono : Mono f := LocallyRingedSpace.forgetToSheafedSpace.mono_of_mono_map (show Mono f.toShHom by infer_instance) instance : SheafedSpace.IsOpenImmersion (LocallyRingedSpace.forgetToSheafedSpace.map f) := H /-- An explicit pullback cone over `cospan f g` if `f` is an open immersion. -/ def pullbackConeOfLeft : PullbackCone f g := by refine PullbackCone.mk ?_ (Y.ofRestrict (TopCat.snd_isOpenEmbedding_of_left H.base_open g.base)) ?_ · use PresheafedSpace.IsOpenImmersion.pullbackConeOfLeftFst f.1 g.1 intro x have := PresheafedSpace.stalkMap.congr_hom _ _ (PresheafedSpace.IsOpenImmersion.pullback_cone_of_left_condition f.1 g.1) x rw [PresheafedSpace.stalkMap.comp, PresheafedSpace.stalkMap.comp] at this rw [← IsIso.eq_inv_comp] at this rw [this] dsimp infer_instance · exact LocallyRingedSpace.Hom.ext' (PresheafedSpace.IsOpenImmersion.pullback_cone_of_left_condition _ _) instance : LocallyRingedSpace.IsOpenImmersion (pullbackConeOfLeft f g).snd := show PresheafedSpace.IsOpenImmersion (Y.toPresheafedSpace.ofRestrict _) by infer_instance /-- The constructed `pullbackConeOfLeft` is indeed limiting. -/ def pullbackConeOfLeftIsLimit : IsLimit (pullbackConeOfLeft f g) := PullbackCone.isLimitAux' _ fun s => by refine ⟨LocallyRingedSpace.Hom.mk (PresheafedSpace.IsOpenImmersion.pullbackConeOfLeftLift f.1 g.1 (PullbackCone.mk _ _ (congr_arg LocallyRingedSpace.Hom.toShHom s.condition))) ?_, LocallyRingedSpace.Hom.ext' (PresheafedSpace.IsOpenImmersion.pullbackConeOfLeftLift_fst f.1 g.1 _), LocallyRingedSpace.Hom.ext' (PresheafedSpace.IsOpenImmersion.pullbackConeOfLeftLift_snd f.1 g.1 _), ?_⟩ · intro x have := PresheafedSpace.stalkMap.congr_hom _ _ (PresheafedSpace.IsOpenImmersion.pullbackConeOfLeftLift_snd f.1 g.1 (PullbackCone.mk s.fst.1 s.snd.1 (congr_arg LocallyRingedSpace.Hom.toShHom s.condition))) x change _ = _ ≫ s.snd.1.stalkMap x at this rw [PresheafedSpace.stalkMap.comp, ← IsIso.eq_inv_comp] at this rw [this] infer_instance · intro m _ h₂ rw [← cancel_mono (pullbackConeOfLeft f g).snd] exact h₂.trans <| LocallyRingedSpace.Hom.ext' (PresheafedSpace.IsOpenImmersion.pullbackConeOfLeftLift_snd f.1 g.1 <| PullbackCone.mk s.fst.1 s.snd.1 <| congr_arg LocallyRingedSpace.Hom.toShHom s.condition).symm instance hasPullback_of_left : HasPullback f g := ⟨⟨⟨_, pullbackConeOfLeftIsLimit f g⟩⟩⟩ instance hasPullback_of_right : HasPullback g f := hasPullback_symmetry f g /-- Open immersions are stable under base-change. -/ instance pullback_snd_of_left : LocallyRingedSpace.IsOpenImmersion (pullback.snd f g) := by delta pullback.snd rw [← limit.isoLimitCone_hom_π ⟨_, pullbackConeOfLeftIsLimit f g⟩ WalkingCospan.right] infer_instance /-- Open immersions are stable under base-change. -/ instance pullback_fst_of_right : LocallyRingedSpace.IsOpenImmersion (pullback.fst g f) := by rw [← pullbackSymmetry_hom_comp_snd] infer_instance instance pullback_to_base_isOpenImmersion [LocallyRingedSpace.IsOpenImmersion g] : LocallyRingedSpace.IsOpenImmersion (limit.π (cospan f g) WalkingCospan.one) := by rw [← limit.w (cospan f g) WalkingCospan.Hom.inl, cospan_map_inl] infer_instance instance forget_preservesPullbackOfLeft : PreservesLimit (cospan f g) LocallyRingedSpace.forgetToSheafedSpace := preservesLimit_of_preserves_limit_cone (pullbackConeOfLeftIsLimit f g) <| by apply (isLimitMapConePullbackConeEquiv _ _).symm.toFun apply isLimitOfIsLimitPullbackConeMap SheafedSpace.forgetToPresheafedSpace exact PresheafedSpace.IsOpenImmersion.pullbackConeOfLeftIsLimit f.1 g.1 instance forgetToPresheafedSpace_preservesPullback_of_left : PreservesLimit (cospan f g) (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) := preservesLimit_of_preserves_limit_cone (pullbackConeOfLeftIsLimit f g) <| by apply (isLimitMapConePullbackConeEquiv _ _).symm.toFun exact PresheafedSpace.IsOpenImmersion.pullbackConeOfLeftIsLimit f.1 g.1 instance forgetToPresheafedSpacePreservesOpenImmersion : PresheafedSpace.IsOpenImmersion ((LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace).map f) := H instance forgetToTop_preservesPullback_of_left : PreservesLimit (cospan f g) (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget _) := by change PreservesLimit _ <| (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) ⋙ PresheafedSpace.forget _ -- Porting note: was `apply (config := { instances := False }) ...` -- See https://github.com/leanprover/lean4/issues/2273 have : PreservesLimit (cospan ((cospan f g ⋙ forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace).map WalkingCospan.Hom.inl) ((cospan f g ⋙ forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace).map WalkingCospan.Hom.inr)) (PresheafedSpace.forget CommRingCat) := by dsimp; infer_instance have : PreservesLimit (cospan f g ⋙ forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) (PresheafedSpace.forget CommRingCat) := by apply preservesLimit_of_iso_diagram _ (diagramIsoCospan _).symm apply Limits.comp_preservesLimit instance forget_reflectsPullback_of_left : ReflectsLimit (cospan f g) LocallyRingedSpace.forgetToSheafedSpace := reflectsLimit_of_reflectsIsomorphisms _ _ instance forget_preservesPullback_of_right : PreservesLimit (cospan g f) LocallyRingedSpace.forgetToSheafedSpace := preservesPullback_symmetry _ _ _ instance forgetToPresheafedSpace_preservesPullback_of_right : PreservesLimit (cospan g f) (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) := preservesPullback_symmetry _ _ _ instance forget_reflectsPullback_of_right : ReflectsLimit (cospan g f) LocallyRingedSpace.forgetToSheafedSpace := reflectsLimit_of_reflectsIsomorphisms _ _ instance forgetToPresheafedSpace_reflectsPullback_of_left : ReflectsLimit (cospan f g) (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) := reflectsLimit_of_reflectsIsomorphisms _ _ instance forgetToPresheafedSpace_reflectsPullback_of_right : ReflectsLimit (cospan g f) (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) := reflectsLimit_of_reflectsIsomorphisms _ _ theorem pullback_snd_isIso_of_range_subset (H' : Set.range g.base ⊆ Set.range f.base) : IsIso (pullback.snd f g) := by apply (config := {allowSynthFailures := true}) Functor.ReflectsIsomorphisms.reflects (F := LocallyRingedSpace.forgetToSheafedSpace) apply (config := {allowSynthFailures := true}) Functor.ReflectsIsomorphisms.reflects (F := SheafedSpace.forgetToPresheafedSpace) erw [← PreservesPullback.iso_hom_snd (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) f g] -- Porting note: was `inferInstance` exact IsIso.comp_isIso' inferInstance <| PresheafedSpace.IsOpenImmersion.pullback_snd_isIso_of_range_subset _ _ H' /-- The universal property of open immersions: For an open immersion `f : X ⟶ Z`, given any morphism of schemes `g : Y ⟶ Z` whose topological image is contained in the image of `f`, we can lift this morphism to a unique `Y ⟶ X` that commutes with these maps. -/ def lift (H' : Set.range g.base ⊆ Set.range f.base) : Y ⟶ X := have := pullback_snd_isIso_of_range_subset f g H' inv (pullback.snd f g) ≫ pullback.fst _ _ @[simp, reassoc] theorem lift_fac (H' : Set.range g.base ⊆ Set.range f.base) : lift f g H' ≫ f = g := by erw [Category.assoc]; rw [IsIso.inv_comp_eq]; exact pullback.condition theorem lift_uniq (H' : Set.range g.base ⊆ Set.range f.base) (l : Y ⟶ X) (hl : l ≫ f = g) : l = lift f g H' := by rw [← cancel_mono f, hl, lift_fac] theorem lift_range (H' : Set.range g.base ⊆ Set.range f.base) : Set.range (lift f g H').base = f.base ⁻¹' Set.range g.base := by have := pullback_snd_isIso_of_range_subset f g H' dsimp only [lift] have : _ = (pullback.fst f g).base := PreservesPullback.iso_hom_fst (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget _) f g rw [LocallyRingedSpace.comp_base, ← this, ← Category.assoc, TopCat.coe_comp, Set.range_comp, Set.range_eq_univ.mpr, Set.image_univ] · rw [TopCat.pullback_fst_range] ext constructor · rintro ⟨y, eq⟩; exact ⟨y, eq.symm⟩ · rintro ⟨y, eq⟩; exact ⟨y, eq.symm⟩ · rw [← TopCat.epi_iff_surjective, show (inv (pullback.snd f g)).base = _ from (LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget _).map_inv _] infer_instance end Pullback /-- An open immersion is isomorphic to the induced open subscheme on its image. -/ noncomputable def isoRestrict {X Y : LocallyRingedSpace} (f : X ⟶ Y) [H : LocallyRingedSpace.IsOpenImmersion f] : X ≅ Y.restrict H.base_open := LocallyRingedSpace.isoOfSheafedSpaceIso <| SheafedSpace.forgetToPresheafedSpace.preimageIso <| PresheafedSpace.IsOpenImmersion.isoRestrict f.1 /-- The functor `Opens X ⥤ Opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev opensFunctor {X Y : LocallyRingedSpace} (f : X ⟶ Y) [H : LocallyRingedSpace.IsOpenImmersion f] : Opens X ⥤ Opens Y := H.base_open.isOpenMap.functor section OfStalkIso /-- Suppose `X Y : SheafedSpace C`, where `C` is a concrete category, whose forgetful functor reflects isomorphisms, preserves limits and filtered colimits. Then a morphism `X ⟶ Y` that is a topological open embedding is an open immersion iff every stalk map is an iso. -/ theorem of_stalk_iso {X Y : LocallyRingedSpace} (f : X ⟶ Y) (hf : IsOpenEmbedding f.base) [stalk_iso : ∀ x : X.1, IsIso (f.stalkMap x)] : LocallyRingedSpace.IsOpenImmersion f := SheafedSpace.IsOpenImmersion.of_stalk_iso _ hf (H := stalk_iso) end OfStalkIso section variable {X Y : LocallyRingedSpace} (f : X ⟶ Y) [H : IsOpenImmersion f] @[reassoc (attr := simp)] theorem isoRestrict_hom_ofRestrict : (isoRestrict f).hom ≫ Y.ofRestrict _ = f := by ext1 dsimp [isoRestrict, isoOfSheafedSpaceIso] apply SheafedSpace.forgetToPresheafedSpace.map_injective rw [Functor.map_comp, SheafedSpace.forgetToPresheafedSpace.map_preimage] exact SheafedSpace.IsOpenImmersion.isoRestrict_hom_ofRestrict f.1 @[reassoc (attr := simp)] theorem isoRestrict_inv_ofRestrict : (isoRestrict f).inv ≫ f = Y.ofRestrict _ := by simp only [← isoRestrict_hom_ofRestrict f, Iso.inv_hom_id_assoc] /-- For an open immersion `f : X ⟶ Y` and an open set `U ⊆ X`, we have the map `X(U) ⟶ Y(U)`. -/ noncomputable def invApp (U : Opens X) : X.presheaf.obj (op U) ⟶ Y.presheaf.obj (op (opensFunctor f |>.obj U)) := PresheafedSpace.IsOpenImmersion.invApp f.1 U @[reassoc (attr := simp)] theorem inv_naturality {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) : X.presheaf.map i ≫ H.invApp _ (unop V) = H.invApp _ (unop U) ≫ Y.presheaf.map (opensFunctor f |>.op.map i) := PresheafedSpace.IsOpenImmersion.inv_naturality f.1 i instance (U : Opens X) : IsIso (H.invApp _ U) := by delta invApp; infer_instance theorem inv_invApp (U : Opens X) : inv (H.invApp _ U) = f.c.app (op (opensFunctor f |>.obj U)) ≫ X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := PresheafedSpace.IsOpenImmersion.inv_invApp f.1 U @[reassoc (attr := simp)] theorem invApp_app (U : Opens X) : H.invApp _ U ≫ f.c.app (op (opensFunctor f |>.obj U)) = X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := PresheafedSpace.IsOpenImmersion.invApp_app f.1 U attribute [elementwise nosimp] invApp_app @[reassoc (attr := simp)] theorem app_invApp (U : Opens Y) : f.c.app (op U) ≫ H.invApp _ ((Opens.map f.base).obj U) = Y.presheaf.map ((homOfLE (Set.image_preimage_subset f.base U.1)).op : op U ⟶ op (opensFunctor f |>.obj ((Opens.map f.base).obj U))) := PresheafedSpace.IsOpenImmersion.app_invApp f.1 U /-- A variant of `app_inv_app` that gives an `eqToHom` instead of `homOfLe`. -/ @[reassoc] theorem app_inv_app' (U : Opens Y) (hU : (U : Set Y) ⊆ Set.range f.base) : f.c.app (op U) ≫ H.invApp _ ((Opens.map f.base).obj U) = Y.presheaf.map (eqToHom <| le_antisymm (Set.image_preimage_subset f.base U.1) <| (Set.image_preimage_eq_inter_range (f := f.base) (t := U.1)).symm ▸ Set.subset_inter_iff.mpr ⟨fun _ h => h, hU⟩).op := PresheafedSpace.IsOpenImmersion.app_invApp f.1 U instance ofRestrict {X : TopCat} (Y : LocallyRingedSpace) {f : X ⟶ Y.carrier} (hf : IsOpenEmbedding f) : IsOpenImmersion (Y.ofRestrict hf) := PresheafedSpace.IsOpenImmersion.ofRestrict _ hf @[elementwise, simp] theorem ofRestrict_invApp (X : LocallyRingedSpace) {Y : TopCat} {f : Y ⟶ TopCat.of X.carrier} (h : IsOpenEmbedding f) (U : Opens (X.restrict h).carrier) : (LocallyRingedSpace.IsOpenImmersion.ofRestrict X h).invApp _ U = 𝟙 _ := PresheafedSpace.IsOpenImmersion.ofRestrict_invApp _ h U instance stalk_iso (x : X) : IsIso (f.stalkMap x) := PresheafedSpace.IsOpenImmersion.stalk_iso f.1 x theorem to_iso [h' : Epi f.base] : IsIso f := by suffices IsIso (LocallyRingedSpace.forgetToSheafedSpace.map f) from isIso_of_reflects_iso _ LocallyRingedSpace.forgetToSheafedSpace exact SheafedSpace.IsOpenImmersion.to_iso f.1 end end LocallyRingedSpace.IsOpenImmersion end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/LocallyRingedSpace.lean
import Mathlib.Algebra.Category.Ring.Constructions import Mathlib.Geometry.RingedSpace.Basic import Mathlib.Geometry.RingedSpace.Stalks import Mathlib.RingTheory.Nilpotent.Defs /-! # The category of locally ringed spaces We define (bundled) locally ringed spaces (as `SheafedSpace CommRing` along with the fact that the stalks are local rings), and morphisms between these (morphisms in `SheafedSpace` with `IsLocalHom` on the stalk maps). -/ -- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737 universe u open CategoryTheory open TopCat open TopologicalSpace Topology open Opposite open CategoryTheory.Category CategoryTheory.Functor namespace AlgebraicGeometry /-- A `LocallyRingedSpace` is a topological space equipped with a sheaf of commutative rings such that all the stalks are local rings. A morphism of locally ringed spaces is a morphism of ringed spaces such that the morphisms induced on stalks are local ring homomorphisms. -/ structure LocallyRingedSpace extends SheafedSpace CommRingCat.{u} where /-- Stalks of a locally ringed space are local rings. -/ isLocalRing : ∀ x, IsLocalRing (presheaf.stalk x) attribute [instance] LocallyRingedSpace.isLocalRing namespace LocallyRingedSpace variable (X : LocallyRingedSpace.{u}) /-- An alias for `toSheafedSpace`, where the result type is a `RingedSpace`. This allows us to use dot-notation for the `RingedSpace` namespace. -/ abbrev toRingedSpace : RingedSpace := X.toSheafedSpace /-- The underlying topological space of a locally ringed space. -/ def toTopCat : TopCat := X.1.carrier instance : CoeSort LocallyRingedSpace (Type u) := ⟨fun X : LocallyRingedSpace => (X.toTopCat : Type _)⟩ instance (x : X) : IsLocalRing (X.presheaf.stalk x) := X.isLocalRing x -- PROJECT: how about a typeclass "HasStructureSheaf" to mediate the 𝒪 notation, rather -- than defining it over and over for `PresheafedSpace`, `LocallyRingedSpace`, `Scheme`, etc. /-- The structure sheaf of a locally ringed space. -/ def 𝒪 : Sheaf CommRingCat X.toTopCat := X.sheaf /-- A morphism of locally ringed spaces is a morphism of ringed spaces such that the morphisms induced on stalks are local ring homomorphisms. -/ @[ext] structure Hom (X Y : LocallyRingedSpace.{u}) : Type _ extends X.toPresheafedSpace.Hom Y.toPresheafedSpace where /-- the underlying morphism induces a local ring homomorphism on stalks -/ prop : ∀ x, IsLocalHom (toHom.stalkMap x).hom /-- A morphism of locally ringed spaces as a morphism of sheafed spaces. -/ abbrev Hom.toShHom {X Y : LocallyRingedSpace.{u}} (f : X.Hom Y) : X.toSheafedSpace ⟶ Y.toSheafedSpace := f.1 @[simp, nolint simpVarHead] lemma Hom.toShHom_mk {X Y : LocallyRingedSpace.{u}} (f : X.toPresheafedSpace.Hom Y.toPresheafedSpace) (hf) : Hom.toShHom ⟨f, hf⟩ = f := rfl instance : Quiver LocallyRingedSpace := ⟨Hom⟩ @[ext] lemma Hom.ext' {X Y : LocallyRingedSpace.{u}} {f g : X ⟶ Y} (h : f.toShHom = g.toShHom) : f = g := by cases f; cases g; congr /-- See Note [custom simps projection] -/ def Hom.Simps.toShHom {X Y : LocallyRingedSpace.{u}} (f : X.Hom Y) : X.toSheafedSpace ⟶ Y.toSheafedSpace := f.toShHom initialize_simps_projections Hom (toHom → toShHom) /-- A morphism of locally ringed spaces `f : X ⟶ Y` induces a local ring homomorphism from `Y.stalk (f x)` to `X.stalk x` for any `x : X`. -/ noncomputable def Hom.stalkMap {X Y : LocallyRingedSpace.{u}} (f : Hom X Y) (x : X) : Y.presheaf.stalk (f.1.1 x) ⟶ X.presheaf.stalk x := f.toShHom.stalkMap x @[instance] theorem isLocalHomStalkMap {X Y : LocallyRingedSpace.{u}} (f : X ⟶ Y) (x : X) : IsLocalHom (f.stalkMap x).hom := f.2 x @[instance] theorem isLocalHomValStalkMap {X Y : LocallyRingedSpace.{u}} (f : X ⟶ Y) (x : X) : IsLocalHom (f.toShHom.stalkMap x).hom := f.2 x /-- The identity morphism on a locally ringed space. -/ @[simps! toShHom] def id (X : LocallyRingedSpace.{u}) : Hom X X := ⟨𝟙 X.toSheafedSpace, fun x => by dsimp; erw [PresheafedSpace.stalkMap.id]; infer_instance⟩ instance (X : LocallyRingedSpace.{u}) : Inhabited (Hom X X) := ⟨id X⟩ /-- Composition of morphisms of locally ringed spaces. -/ def comp {X Y Z : LocallyRingedSpace.{u}} (f : Hom X Y) (g : Hom Y Z) : Hom X Z := ⟨f.toShHom ≫ g.toShHom, fun x => by dsimp erw [PresheafedSpace.stalkMap.comp] infer_instance⟩ /-- The category of locally ringed spaces. -/ instance : Category LocallyRingedSpace.{u} where Hom := Hom id := id comp {_ _ _} f g := comp f g comp_id {X Y} f := Hom.ext' <| by simp [comp] id_comp {X Y} f := Hom.ext' <| by simp [comp] assoc {_ _ _ _} f g h := Hom.ext' <| by simp [comp] /-- The forgetful functor from `LocallyRingedSpace` to `SheafedSpace CommRing`. -/ @[simps] def forgetToSheafedSpace : LocallyRingedSpace.{u} ⥤ SheafedSpace CommRingCat.{u} where obj X := X.toSheafedSpace map {_ _} f := f.1 /-- The canonical map `X ⟶ Spec Γ(X, ⊤)`. This is the unit of the `Γ-Spec` adjunction. -/ instance : forgetToSheafedSpace.Faithful where map_injective {_ _} _ _ h := Hom.ext' h /-- The forgetful functor from `LocallyRingedSpace` to `Top`. -/ @[simps!] def forgetToTop : LocallyRingedSpace.{u} ⥤ TopCat.{u} := forgetToSheafedSpace ⋙ SheafedSpace.forget _ @[simp] theorem comp_toShHom {X Y Z : LocallyRingedSpace.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).toShHom = f.toShHom ≫ g.toShHom := rfl /-- A variant of `id_toShHom'` that works with `𝟙 X` instead of `id X`. -/ @[simp] theorem id_toShHom' (X : LocallyRingedSpace.{u}) : Hom.toShHom (𝟙 X) = 𝟙 X.toSheafedSpace := rfl theorem comp_base {X Y Z : LocallyRingedSpace.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).base = f.base ≫ g.base := rfl theorem comp_c {X Y Z : LocallyRingedSpace.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).c = g.c ≫ (Presheaf.pushforward _ g.base).map f.c := rfl theorem comp_c_app {X Y Z : LocallyRingedSpace.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) (U : (Opens Z)ᵒᵖ) : (f ≫ g).c.app U = g.c.app U ≫ f.c.app (op <| (Opens.map g.base).obj U.unop) := rfl /-- Given two locally ringed spaces `X` and `Y`, an isomorphism between `X` and `Y` as _sheafed_ spaces can be lifted to a morphism `X ⟶ Y` as locally ringed spaces. See also `isoOfSheafedSpaceIso`. -/ @[simps! toShHom] def homOfSheafedSpaceHomOfIsIso {X Y : LocallyRingedSpace.{u}} (f : X.toSheafedSpace ⟶ Y.toSheafedSpace) [IsIso f] : X ⟶ Y := Hom.mk f fun _ => -- Here we need to see that the stalk maps are really local ring homomorphisms. -- This can be solved by type class inference, because stalk maps of isomorphisms -- are isomorphisms and isomorphisms are local ring homomorphisms. inferInstance /-- Given two locally ringed spaces `X` and `Y`, an isomorphism between `X` and `Y` as _sheafed_ spaces can be lifted to an isomorphism `X ⟶ Y` as locally ringed spaces. This is related to the property that the functor `forgetToSheafedSpace` reflects isomorphisms. In fact, it is slightly stronger as we do not require `f` to come from a morphism between _locally_ ringed spaces. -/ def isoOfSheafedSpaceIso {X Y : LocallyRingedSpace.{u}} (f : X.toSheafedSpace ≅ Y.toSheafedSpace) : X ≅ Y where hom := homOfSheafedSpaceHomOfIsIso f.hom inv := homOfSheafedSpaceHomOfIsIso f.inv hom_inv_id := Hom.ext' f.hom_inv_id inv_hom_id := Hom.ext' f.inv_hom_id instance : forgetToSheafedSpace.ReflectsIsomorphisms where reflects {_ _} f i := { out := ⟨homOfSheafedSpaceHomOfIsIso (CategoryTheory.inv (forgetToSheafedSpace.map f)), Hom.ext' (IsIso.hom_inv_id (I := i)), Hom.ext' (IsIso.inv_hom_id (I := i))⟩ } instance is_sheafedSpace_iso {X Y : LocallyRingedSpace.{u}} (f : X ⟶ Y) [IsIso f] : IsIso f.toShHom := LocallyRingedSpace.forgetToSheafedSpace.map_isIso f /-- The restriction of a locally ringed space along an open embedding. -/ @[simps!] def restrict {U : TopCat} (X : LocallyRingedSpace.{u}) {f : U ⟶ X.toTopCat} (h : IsOpenEmbedding f) : LocallyRingedSpace where isLocalRing := by intro x -- We show that the stalk of the restriction is isomorphic to the original stalk, apply @RingEquiv.isLocalRing _ _ _ (X.isLocalRing (f x)) exact (X.restrictStalkIso h x).symm.commRingCatIsoToRingEquiv toSheafedSpace := X.toSheafedSpace.restrict h /-- The canonical map from the restriction to the subspace. -/ def ofRestrict {U : TopCat} (X : LocallyRingedSpace.{u}) {f : U ⟶ X.toTopCat} (h : IsOpenEmbedding f) : X.restrict h ⟶ X := ⟨X.toPresheafedSpace.ofRestrict h, fun _ => inferInstance⟩ /-- The restriction of a locally ringed space `X` to the top subspace is isomorphic to `X` itself. -/ def restrictTopIso (X : LocallyRingedSpace.{u}) : X.restrict (Opens.isOpenEmbedding ⊤) ≅ X := isoOfSheafedSpaceIso X.toSheafedSpace.restrictTopIso /-- The global sections, notated Gamma. -/ def Γ : LocallyRingedSpace.{u}ᵒᵖ ⥤ CommRingCat.{u} := forgetToSheafedSpace.op ⋙ SheafedSpace.Γ theorem Γ_def : Γ = forgetToSheafedSpace.op ⋙ SheafedSpace.Γ := rfl @[simp] theorem Γ_obj (X : LocallyRingedSpace.{u}ᵒᵖ) : Γ.obj X = X.unop.presheaf.obj (op ⊤) := rfl theorem Γ_obj_op (X : LocallyRingedSpace.{u}) : Γ.obj (op X) = X.presheaf.obj (op ⊤) := rfl @[simp] theorem Γ_map {X Y : LocallyRingedSpace.{u}ᵒᵖ} (f : X ⟶ Y) : Γ.map f = f.unop.c.app (op ⊤) := rfl theorem Γ_map_op {X Y : LocallyRingedSpace.{u}} (f : X ⟶ Y) : Γ.map f.op = f.c.app (op ⊤) := rfl /-- The empty locally ringed space. -/ def empty : LocallyRingedSpace.{u} where carrier := TopCat.of PEmpty presheaf := (CategoryTheory.Functor.const _).obj (CommRingCat.of PUnit) IsSheaf := Presheaf.isSheaf_of_isTerminal _ CommRingCat.punitIsTerminal isLocalRing x := PEmpty.elim x instance : EmptyCollection LocallyRingedSpace.{u} := ⟨LocallyRingedSpace.empty⟩ /-- The canonical map from the empty locally ringed space. -/ def emptyTo (X : LocallyRingedSpace.{u}) : ∅ ⟶ X := ⟨⟨ofHom ⟨fun x => PEmpty.elim x, by fun_prop⟩, { app := fun U => CommRingCat.ofHom <| by refine ⟨⟨⟨0, ?_⟩, ?_⟩, ?_, ?_⟩ <;> intros <;> rfl }⟩, fun x => PEmpty.elim x⟩ noncomputable instance {X : LocallyRingedSpace.{u}} : Unique (∅ ⟶ X) where default := LocallyRingedSpace.emptyTo X uniq f := by ext ⟨⟩ x; cat_disch /-- The empty space is initial in `LocallyRingedSpace`. -/ noncomputable def emptyIsInitial : Limits.IsInitial (∅ : LocallyRingedSpace.{u}) := Limits.IsInitial.ofUnique _ -- This actually holds for all ringed spaces with nontrivial stalks. theorem basicOpen_zero (X : LocallyRingedSpace.{u}) (U : Opens X.carrier) : X.toRingedSpace.basicOpen (0 : X.presheaf.obj <| op U) = ⊥ := by ext x simp only [RingedSpace.basicOpen, Opens.coe_mk, Set.mem_setOf_eq, Opens.coe_bot, Set.mem_empty_iff_false, iff_false, not_exists] intro hx rw [map_zero, isUnit_zero_iff] change (0 : X.presheaf.stalk x) ≠ (1 : X.presheaf.stalk x) exact zero_ne_one @[simp] lemma basicOpen_eq_bot_of_isNilpotent (X : LocallyRingedSpace.{u}) (U : Opens X.carrier) (f : (X.presheaf.obj <| op U)) (hf : IsNilpotent f) : X.toRingedSpace.basicOpen f = ⊥ := by obtain ⟨n, hn⟩ := hf cases n.eq_zero_or_pos with | inr h => rw [← X.toRingedSpace.basicOpen_pow f n h, hn] simp [basicOpen_zero] | inl h => rw [h, pow_zero] at hn simp [eq_zero_of_zero_eq_one hn.symm f, basicOpen_zero] instance component_nontrivial (X : LocallyRingedSpace.{u}) (U : Opens X.carrier) [hU : Nonempty U] : Nontrivial (X.presheaf.obj <| op U) := (X.presheaf.germ _ _ hU.some.2).hom.domain_nontrivial @[simp] lemma iso_hom_base_inv_base {X Y : LocallyRingedSpace.{u}} (e : X ≅ Y) : e.hom.base ≫ e.inv.base = 𝟙 _ := by rw [← SheafedSpace.comp_base, ← LocallyRingedSpace.comp_toShHom] simp @[simp] lemma iso_hom_base_inv_base_apply {X Y : LocallyRingedSpace.{u}} (e : X ≅ Y) (x : X) : (e.inv.base (e.hom.base x)) = x := by change (e.hom.base ≫ e.inv.base) x = 𝟙 X.toPresheafedSpace x simp @[simp] lemma iso_inv_base_hom_base {X Y : LocallyRingedSpace.{u}} (e : X ≅ Y) : e.inv.base ≫ e.hom.base = 𝟙 _ := by rw [← SheafedSpace.comp_base, ← LocallyRingedSpace.comp_toShHom] simp @[simp] lemma iso_inv_base_hom_base_apply {X Y : LocallyRingedSpace.{u}} (e : X ≅ Y) (y : Y) : (e.hom.base (e.inv.base y)) = y := by change (e.inv.base ≫ e.hom.base) y = 𝟙 Y.toPresheafedSpace y simp section Stalks variable {X Y Z : LocallyRingedSpace.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) @[simp] lemma stalkMap_id (X : LocallyRingedSpace.{u}) (x : X) : (𝟙 X : X ⟶ X).stalkMap x = 𝟙 (X.presheaf.stalk x) := PresheafedSpace.stalkMap.id _ x lemma stalkMap_comp (x : X) : (f ≫ g : X ⟶ Z).stalkMap x = g.stalkMap (f.base x) ≫ f.stalkMap x := PresheafedSpace.stalkMap.comp f.toShHom g.toShHom x @[reassoc] lemma stalkSpecializes_stalkMap (x x' : X) (h : x ⤳ x') : Y.presheaf.stalkSpecializes (f.base.hom.map_specializes h) ≫ f.stalkMap x = f.stalkMap x' ≫ X.presheaf.stalkSpecializes h := PresheafedSpace.stalkMap.stalkSpecializes_stalkMap f.toShHom h lemma stalkSpecializes_stalkMap_apply (x x' : X) (h : x ⤳ x') (y) : f.stalkMap x (Y.presheaf.stalkSpecializes (f.base.hom.map_specializes h) y) = (X.presheaf.stalkSpecializes h (f.stalkMap x' y)) := DFunLike.congr_fun (CommRingCat.hom_ext_iff.mp (stalkSpecializes_stalkMap f x x' h)) y @[reassoc] lemma stalkMap_congr (f g : X ⟶ Y) (hfg : f = g) (x x' : X) (hxx' : x = x') : f.stalkMap x ≫ X.presheaf.stalkSpecializes (specializes_of_eq hxx'.symm) = Y.presheaf.stalkSpecializes (specializes_of_eq <| hfg ▸ hxx' ▸ rfl) ≫ g.stalkMap x' := by subst hfg subst hxx' simp @[reassoc] lemma stalkMap_congr_hom (f g : X ⟶ Y) (hfg : f = g) (x : X) : f.stalkMap x = Y.presheaf.stalkSpecializes (specializes_of_eq <| hfg ▸ rfl) ≫ g.stalkMap x := by subst hfg simp @[reassoc] lemma stalkMap_congr_point {X Y : LocallyRingedSpace.{u}} (f : X ⟶ Y) (x x' : X) (hxx' : x = x') : f.stalkMap x ≫ X.presheaf.stalkSpecializes (specializes_of_eq hxx'.symm) = Y.presheaf.stalkSpecializes (specializes_of_eq <| hxx' ▸ rfl) ≫ f.stalkMap x' := by subst hxx' simp @[reassoc (attr := simp)] lemma stalkMap_hom_inv (e : X ≅ Y) (y : Y) : e.hom.stalkMap (e.inv.base y) ≫ e.inv.stalkMap y = Y.presheaf.stalkSpecializes (specializes_of_eq <| by simp) := by rw [← stalkMap_comp, LocallyRingedSpace.stalkMap_congr_hom (e.inv ≫ e.hom) (𝟙 _) (by simp)] simp @[simp] lemma stalkMap_hom_inv_apply (e : X ≅ Y) (y : Y) (z) : e.inv.stalkMap y (e.hom.stalkMap (e.inv.base y) z) = Y.presheaf.stalkSpecializes (specializes_of_eq <| by simp) z := DFunLike.congr_fun (CommRingCat.hom_ext_iff.mp (stalkMap_hom_inv e y)) z @[reassoc (attr := simp)] lemma stalkMap_inv_hom (e : X ≅ Y) (x : X) : e.inv.stalkMap (e.hom.base x) ≫ e.hom.stalkMap x = X.presheaf.stalkSpecializes (specializes_of_eq <| by simp) := by rw [← stalkMap_comp, LocallyRingedSpace.stalkMap_congr_hom (e.hom ≫ e.inv) (𝟙 _) (by simp)] simp @[simp] lemma stalkMap_inv_hom_apply (e : X ≅ Y) (x : X) (y) : e.hom.stalkMap x (e.inv.stalkMap (e.hom.base x) y) = X.presheaf.stalkSpecializes (specializes_of_eq <| by simp) y := DFunLike.congr_fun (CommRingCat.hom_ext_iff.mp (stalkMap_inv_hom e x)) y @[reassoc (attr := simp)] lemma stalkMap_germ (U : Opens Y) (x : X) (hx : f.base x ∈ U) : Y.presheaf.germ U (f.base x) hx ≫ f.stalkMap x = f.c.app (op U) ≫ X.presheaf.germ ((Opens.map f.base).obj U) x hx := PresheafedSpace.stalkMap_germ f.toShHom U x hx lemma stalkMap_germ_apply (U : Opens Y) (x : X) (hx : f.base x ∈ U) (y) : f.stalkMap x (Y.presheaf.germ U (f.base x) hx y) = X.presheaf.germ ((Opens.map f.base).obj U) x hx (f.c.app (op U) y) := PresheafedSpace.stalkMap_germ_apply f.toShHom U x hx y theorem preimage_basicOpen {X Y : LocallyRingedSpace.{u}} (f : X ⟶ Y) {U : Opens Y} (s : Y.presheaf.obj (op U)) : (Opens.map f.base).obj (Y.toRingedSpace.basicOpen s) = @RingedSpace.basicOpen X.toRingedSpace ((Opens.map f.base).obj U) (f.c.app _ s) := by ext x constructor · rintro ⟨hxU, hx⟩ rw [SetLike.mem_coe, X.toRingedSpace.mem_basicOpen _ _ hxU] delta toRingedSpace rw [← stalkMap_germ_apply] exact (f.stalkMap _).hom.isUnit_map hx · rintro ⟨hxU, hx⟩ simp only [Opens.map_coe, Set.mem_preimage, SetLike.mem_coe, toRingedSpace] at hx ⊢ rw [RingedSpace.mem_basicOpen _ s (f.base x) hxU] rw [← stalkMap_germ_apply] at hx exact (isUnit_map_iff (f.toShHom.stalkMap _).hom _).mp hx variable {U : TopCat} (X : LocallyRingedSpace.{u}) {f : U ⟶ X.toTopCat} (h : IsOpenEmbedding f) (V : Opens U) (x : U) (hx : x ∈ V) /-- For an open embedding `f : U ⟶ X` and a point `x : U`, we get an isomorphism between the stalk of `X` at `f x` and the stalk of the restriction of `X` along `f` at `x`. -/ noncomputable def restrictStalkIso : (X.restrict h).presheaf.stalk x ≅ X.presheaf.stalk (f x) := X.toPresheafedSpace.restrictStalkIso h x @[reassoc (attr := simp)] lemma restrictStalkIso_hom_eq_germ : (X.restrict h).presheaf.germ _ x hx ≫ (X.restrictStalkIso h x).hom = X.presheaf.germ (h.isOpenMap.functor.obj V) (f x) ⟨x, hx, rfl⟩ := PresheafedSpace.restrictStalkIso_hom_eq_germ X.toPresheafedSpace h V x hx lemma restrictStalkIso_hom_eq_germ_apply (y) : (X.restrictStalkIso h x).hom ((X.restrict h).presheaf.germ _ x hx y) = X.presheaf.germ (h.isOpenMap.functor.obj V) (f x) ⟨x, hx, rfl⟩ y := PresheafedSpace.restrictStalkIso_hom_eq_germ_apply X.toPresheafedSpace h V x hx y @[reassoc (attr := simp)] lemma restrictStalkIso_inv_eq_germ : X.presheaf.germ (h.isOpenMap.functor.obj V) (f x) ⟨x, hx, rfl⟩ ≫ (X.restrictStalkIso h x).inv = (X.restrict h).presheaf.germ _ x hx := PresheafedSpace.restrictStalkIso_inv_eq_germ X.toPresheafedSpace h V x hx lemma restrictStalkIso_inv_eq_germ_apply (y) : (X.restrictStalkIso h x).inv (X.presheaf.germ (h.isOpenMap.functor.obj V) (f x) ⟨x, hx, rfl⟩ y) = (X.restrict h).presheaf.germ _ x hx y := PresheafedSpace.restrictStalkIso_inv_eq_germ_apply X.toPresheafedSpace h V x hx y lemma restrictStalkIso_inv_eq_ofRestrict : (X.restrictStalkIso h x).inv = (X.ofRestrict h).stalkMap x := PresheafedSpace.restrictStalkIso_inv_eq_ofRestrict X.toPresheafedSpace h x instance ofRestrict_stalkMap_isIso : IsIso ((X.ofRestrict h).stalkMap x) := PresheafedSpace.ofRestrict_stalkMap_isIso X.toPresheafedSpace h x end Stalks end LocallyRingedSpace end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/Basic.lean
import Mathlib.Algebra.Category.Ring.Colimits import Mathlib.Algebra.Category.Ring.FilteredColimits import Mathlib.Algebra.Category.Ring.Limits import Mathlib.Algebra.Order.Group.Nat import Mathlib.Geometry.RingedSpace.SheafedSpace import Mathlib.Topology.Sheaves.Stalks /-! # Ringed spaces We introduce the category of ringed spaces, as an alias for `SheafedSpace CommRingCat`. The facts collected in this file are typically stated for locally ringed spaces, but never actually make use of the locality of stalks. See for instance <https://stacks.math.columbia.edu/tag/01HZ>. -/ universe v u open CategoryTheory open TopologicalSpace open Opposite open TopCat open TopCat.Presheaf namespace AlgebraicGeometry /-- The type of Ringed spaces, as an abbreviation for `SheafedSpace CommRingCat`. -/ @[nolint checkUnivs] -- The universes appear together in the type, but separately in the value. abbrev RingedSpace : Type max (u+1) (v+1) := SheafedSpace.{v+1, v, u} CommRingCat.{v} namespace RingedSpace open SheafedSpace @[simp] lemma res_zero {X : RingedSpace.{u}} {U V : TopologicalSpace.Opens X} (hUV : U ≤ V) : (0 : X.presheaf.obj (op V)) |_ U = (0 : X.presheaf.obj (op U)) := RingHom.map_zero _ variable (X : RingedSpace) instance : CoeSort RingedSpace Type* where coe X := X.carrier /-- If the germ of a section `f` is zero in the stalk at `x`, then `f` is zero on some neighbourhood around `x`. -/ lemma exists_res_eq_zero_of_germ_eq_zero (U : Opens X) (f : X.presheaf.obj (op U)) (x : U) (h : X.presheaf.germ U x.val x.property f = 0) : ∃ (V : Opens X) (i : V ⟶ U) (_ : x.1 ∈ V), X.presheaf.map i.op f = 0 := by have h1 : X.presheaf.germ U x.val x.property f = X.presheaf.germ U x.val x.property 0 := by simpa obtain ⟨V, hv, i, _, (hv4 : (X.presheaf.map i.op) f = (X.presheaf.map _) 0)⟩ := TopCat.Presheaf.germ_eq X.presheaf x.1 x.2 x.2 f 0 h1 use V, i, hv simpa using hv4 /-- If the germ of a section `f` is a unit in the stalk at `x`, then `f` must be a unit on some small neighborhood around `x`. -/ theorem isUnit_res_of_isUnit_germ (U : Opens X) (f : X.presheaf.obj (op U)) (x : X) (hx : x ∈ U) (h : IsUnit (X.presheaf.germ U x hx f)) : ∃ (V : Opens X) (i : V ⟶ U) (_ : x ∈ V), IsUnit (X.presheaf.map i.op f) := by obtain ⟨g', heq⟩ := h.exists_right_inv obtain ⟨V, hxV, g, rfl⟩ := X.presheaf.germ_exist x g' let W := U ⊓ V have hxW : x ∈ W := ⟨hx, hxV⟩ replace heq : (X.presheaf.germ _ x hxW) ((X.presheaf.map (U.infLELeft V).op) f * (X.presheaf.map (U.infLERight V).op) g) = (X.presheaf.germ _ x hxW) 1 := by rwa [map_mul, map_one, X.presheaf.germ_res_apply (Opens.infLELeft U V) x hxW f, X.presheaf.germ_res_apply (Opens.infLERight U V) x hxW g] obtain ⟨W', hxW', i₁, i₂, heq'⟩ := X.presheaf.germ_eq x hxW hxW _ _ heq use W', i₁ ≫ Opens.infLELeft U V, hxW' simp only [map_mul, map_one] at heq' simpa using .of_mul_eq_one _ heq' /-- If a section `f` is a unit in each stalk, `f` must be a unit. -/ theorem isUnit_of_isUnit_germ (U : Opens X) (f : X.presheaf.obj (op U)) (h : ∀ (x) (hx : x ∈ U), IsUnit (X.presheaf.germ U x hx f)) : IsUnit f := by -- We pick a cover of `U` by open sets `V x`, such that `f` is a unit on each `V x`. choose V iVU m h_unit using fun x : U => X.isUnit_res_of_isUnit_germ U f x x.2 (h x.1 x.2) have hcover : U ≤ iSup V := by intro x hxU simp only [Opens.coe_iSup, Set.mem_iUnion, SetLike.mem_coe, Subtype.exists] tauto -- Let `g x` denote the inverse of `f` in `U x`. choose g hg using fun x : U => IsUnit.exists_right_inv (h_unit x) have ic : IsCompatible (sheaf X).val V g := by intro x y apply section_ext X.sheaf (V x ⊓ V y) rintro z ⟨hzVx, hzVy⟩ rw [germ_res_apply, germ_res_apply] apply (h z ((iVU x).le hzVx)).mul_right_inj.mp rw [← germ_res_apply X.presheaf (iVU x) z hzVx f] -- Porting note: change was not necessary in Lean3 change X.presheaf.germ _ z hzVx _ * (X.presheaf.germ _ z hzVx _) = X.presheaf.germ _ z hzVx _ * X.presheaf.germ _ z hzVy (g y) rw [← RingHom.map_mul, hg x, germ_res_apply X.presheaf _ _ _ f, ← germ_res_apply X.presheaf (iVU y) z hzVy f, ← RingHom.map_mul, (hg y), RingHom.map_one, RingHom.map_one] -- We claim that these local inverses glue together to a global inverse of `f`. obtain ⟨gl, gl_spec, -⟩ : -- We need to rephrase the result from `HasForget` to `CommRingCat`. ∃ gl : X.presheaf.obj (op U), (∀ i, ((sheaf X).val.map (iVU i).op) gl = g i) ∧ _ := X.sheaf.existsUnique_gluing' V U iVU hcover g ic refine .of_mul_eq_one gl <| X.sheaf.eq_of_locally_eq' V U iVU hcover _ _ fun i ↦ ?_ -- We need to rephrase the goal from `HasForget` to `CommRingCat`. change ((sheaf X).val.map (iVU i).op).hom (f * gl) = ((sheaf X).val.map (iVU i).op) 1 rw [RingHom.map_one, RingHom.map_mul, gl_spec] exact hg i /-- The basic open of a section `f` is the set of all points `x`, such that the germ of `f` at `x` is a unit. -/ def basicOpen {U : Opens X} (f : X.presheaf.obj (op U)) : Opens X where carrier := { x : X | ∃ (hx : x ∈ U), IsUnit (X.presheaf.germ U x hx f) } is_open' := by rw [isOpen_iff_forall_mem_open] rintro x ⟨hxU, hx⟩ obtain ⟨V, i, hxV, hf⟩ := X.isUnit_res_of_isUnit_germ U f x hxU hx use V.1 refine ⟨?_, V.2, hxV⟩ intro y hy use i.le hy convert RingHom.isUnit_map (X.presheaf.germ _ y hy).hom hf exact (X.presheaf.germ_res_apply i y hy f).symm theorem mem_basicOpen {U : Opens X} (f : X.presheaf.obj (op U)) (x : X) (hx : x ∈ U) : x ∈ X.basicOpen f ↔ IsUnit (X.presheaf.germ U x hx f) := ⟨Exists.choose_spec, (⟨hx, ·⟩)⟩ /-- A variant of `mem_basicOpen` with bundled `x : U`. -/ @[simp] theorem mem_basicOpen' {U : Opens X} (f : X.presheaf.obj (op U)) (x : U) : ↑x ∈ X.basicOpen f ↔ IsUnit (X.presheaf.germ U x.1 x.2 f) := mem_basicOpen X f x.1 x.2 @[simp] theorem mem_top_basicOpen (f : X.presheaf.obj (op ⊤)) (x : X) : x ∈ X.basicOpen f ↔ IsUnit (X.presheaf.Γgerm x f) := mem_basicOpen X f x .intro theorem basicOpen_le {U : Opens X} (f : X.presheaf.obj (op U)) : X.basicOpen f ≤ U := by rintro x ⟨h, _⟩; exact h /-- The restriction of a section `f` to the basic open of `f` is a unit. -/ theorem isUnit_res_basicOpen {U : Opens X} (f : X.presheaf.obj (op U)) : IsUnit (X.presheaf.map (@homOfLE (Opens X) _ _ _ (X.basicOpen_le f)).op f) := by apply isUnit_of_isUnit_germ rintro x ⟨hxU, hx⟩ convert hx exact X.presheaf.germ_res_apply _ _ _ _ @[simp] theorem basicOpen_res {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) (f : X.presheaf.obj U) : @basicOpen X (unop V) (X.presheaf.map i f) = unop V ⊓ @basicOpen X (unop U) f := by ext x; constructor · rintro ⟨hxV, hx⟩ rw [germ_res_apply' X.presheaf] at hx exact ⟨hxV, i.unop.le hxV, hx⟩ · rintro ⟨hxV, _, hx⟩ refine ⟨hxV, ?_⟩ rw [germ_res_apply' X.presheaf] exact hx /-- High priority: This should fire before `basicOpen_res`. -/ @[simp (high)] theorem basicOpen_res_eq {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) [IsIso i] (f : X.presheaf.obj U) : @basicOpen X (unop V) (X.presheaf.map i f) = @RingedSpace.basicOpen X (unop U) f := by apply le_antisymm · rw [X.basicOpen_res i f]; exact inf_le_right · have := X.basicOpen_res (inv i) (X.presheaf.map i f) rw [← CommRingCat.comp_apply, ← X.presheaf.map_comp, IsIso.hom_inv_id, X.presheaf.map_id, CommRingCat.id_apply] at this rw [this] exact inf_le_right @[simp] theorem basicOpen_mul {U : Opens X} (f g : X.presheaf.obj (op U)) : X.basicOpen (f * g) = X.basicOpen f ⊓ X.basicOpen g := by ext x by_cases hx : x ∈ U · simp [mem_basicOpen (hx := hx)] · simp [mt (basicOpen_le X _ ·) hx] @[simp] lemma basicOpen_pow {U : Opens X} (f : X.presheaf.obj (op U)) (n : ℕ) (h : 0 < n) : X.basicOpen (f ^ n) = X.basicOpen f := by obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le' h induction k with | zero => simp | succ n hn => rw [pow_add]; simp_all theorem basicOpen_of_isUnit {U : Opens X} {f : X.presheaf.obj (op U)} (hf : IsUnit f) : X.basicOpen f = U := by apply le_antisymm · exact X.basicOpen_le f intro x hx rw [SetLike.mem_coe, X.mem_basicOpen f x hx] exact RingHom.isUnit_map _ hf /-- The zero locus of a set of sections `s` over an open set `U` is the closed set consisting of the complement of `U` and of all points of `U`, where all elements of `f` vanish. -/ def zeroLocus {U : Opens X} (s : Set (X.presheaf.obj (op U))) : Set X := ⋂ f ∈ s, (X.basicOpen f)ᶜ lemma zeroLocus_isClosed {U : Opens X} (s : Set (X.presheaf.obj (op U))) : IsClosed (X.zeroLocus s) := by apply isClosed_biInter intro i _ simp only [isClosed_compl_iff] exact Opens.isOpen (X.basicOpen i) lemma zeroLocus_singleton {U : Opens X} (f : X.presheaf.obj (op U)) : X.zeroLocus {f} = (X.basicOpen f).carrierᶜ := by simp [zeroLocus] @[simp] lemma zeroLocus_empty_eq_univ {U : Opens X} : X.zeroLocus (∅ : Set (X.presheaf.obj (op U))) = Set.univ := by simp [zeroLocus] @[simp] lemma mem_zeroLocus_iff {U : Opens X} (s : Set (X.presheaf.obj (op U))) (x : X) : x ∈ X.zeroLocus s ↔ ∀ f ∈ s, x ∉ X.basicOpen f := by simp [zeroLocus] end RingedSpace end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/PresheafedSpace.lean
import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Elementwise import Mathlib.Topology.Sheaves.Presheaf /-! # Presheafed spaces Introduces the category of topological spaces equipped with a presheaf (taking values in an arbitrary target category `C`.) We further describe how to apply functors and natural transformations to the values of the presheaves. -/ open Opposite CategoryTheory CategoryTheory.Category CategoryTheory.Functor TopCat TopologicalSpace Topology variable (C : Type*) [Category C] -- We could enable: -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opens -- although it doesn't appear to help in this file, in any case. -- We could enable: -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opposite -- but this would probably require https://github.com/leanprover-community/aesop/issues/59 -- In any case, it doesn't seem to help in this file. namespace AlgebraicGeometry /-- A `PresheafedSpace C` is a topological space equipped with a presheaf of `C`s. -/ structure PresheafedSpace where carrier : TopCat protected presheaf : carrier.Presheaf C variable {C} namespace PresheafedSpace instance coeCarrier : CoeOut (PresheafedSpace C) TopCat where coe X := X.carrier attribute [coe] PresheafedSpace.carrier instance : CoeSort (PresheafedSpace C) Type* where coe X := X.carrier instance (X : PresheafedSpace C) : TopologicalSpace X := X.carrier.str /-- The constant presheaf on `X` with value `Z`. -/ def const (X : TopCat) (Z : C) : PresheafedSpace C where carrier := X presheaf := (Functor.const _).obj Z instance [Inhabited C] : Inhabited (PresheafedSpace C) := ⟨const (TopCat.of PEmpty) default⟩ /-- A morphism between presheafed spaces `X` and `Y` consists of a continuous map `f` between the underlying topological spaces, and a (note: contravariant!) map from the presheaf on `Y` to the pushforward of the presheaf on `X` via `f`. -/ structure Hom (X Y : PresheafedSpace C) where base : (X : TopCat) ⟶ (Y : TopCat) c : Y.presheaf ⟶ base _* X.presheaf @[ext (iff := false)] theorem Hom.ext {X Y : PresheafedSpace C} (α β : Hom X Y) (w : α.base = β.base) (h : α.c ≫ whiskerRight (eqToHom (by rw [w])) _ = β.c) : α = β := by rcases α with ⟨base, c⟩ rcases β with ⟨base', c'⟩ dsimp at w subst w dsimp at h erw [whiskerRight_id', comp_id] at h subst h rfl -- TODO including `injections` would make tidy work earlier. theorem hext {X Y : PresheafedSpace C} (α β : Hom X Y) (w : α.base = β.base) (h : α.c ≍ β.c) : α = β := by cases α cases β congr /-- The identity morphism of a `PresheafedSpace`. -/ def id (X : PresheafedSpace C) : Hom X X where base := 𝟙 (X : TopCat) c := 𝟙 _ instance homInhabited (X : PresheafedSpace C) : Inhabited (Hom X X) := ⟨id X⟩ /-- Composition of morphisms of `PresheafedSpace`s. -/ def comp {X Y Z : PresheafedSpace C} (α : Hom X Y) (β : Hom Y Z) : Hom X Z where base := α.base ≫ β.base c := β.c ≫ (Presheaf.pushforward _ β.base).map α.c theorem comp_c {X Y Z : PresheafedSpace C} (α : Hom X Y) (β : Hom Y Z) : (comp α β).c = β.c ≫ (Presheaf.pushforward _ β.base).map α.c := rfl variable (C) section attribute [local simp] id comp /-- The category of PresheafedSpaces. Morphisms are pairs, a continuous map and a presheaf map from the presheaf on the target to the pushforward of the presheaf on the source. -/ instance categoryOfPresheafedSpaces : Category (PresheafedSpace C) where Hom := Hom id := id comp := comp variable {C} /-- Cast `Hom X Y` as an arrow `X ⟶ Y` of presheaves. -/ abbrev Hom.toPshHom {X Y : PresheafedSpace C} (f : Hom X Y) : X ⟶ Y := f @[ext (iff := false)] theorem ext {X Y : PresheafedSpace C} (α β : X ⟶ Y) (w : α.base = β.base) (h : α.c ≫ whiskerRight (eqToHom (by rw [w])) _ = β.c) : α = β := Hom.ext α β w h end variable {C} attribute [local simp] eqToHom_map @[simp] theorem id_base (X : PresheafedSpace C) : (𝟙 X : X ⟶ X).base = 𝟙 (X : TopCat) := rfl theorem id_c (X : PresheafedSpace C) : (𝟙 X : X ⟶ X).c = 𝟙 X.presheaf := rfl @[simp] theorem id_c_app (X : PresheafedSpace C) (U) : (𝟙 X : X ⟶ X).c.app U = X.presheaf.map (𝟙 U) := by rw [id_c, map_id] rfl @[simp] theorem comp_base {X Y Z : PresheafedSpace C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).base = f.base ≫ g.base := rfl instance (X Y : PresheafedSpace C) : CoeFun (X ⟶ Y) fun _ => (↑X → ↑Y) := ⟨fun f => f.base⟩ /-! Note that we don't include a `ConcreteCategory` instance, since equality of morphisms `X ⟶ Y` does not follow from equality of their coercions `X → Y`. -/ -- The `reassoc` attribute was added despite the LHS not being a composition of two homs, -- for the reasons explained in the docstring. -- As there is no composition in the LHS it is purposely `@[reassoc, simp]` rather -- than `@[reassoc (attr := simp)]` /-- Sometimes rewriting with `comp_c_app` doesn't work because of dependent type issues. In that case, `erw comp_c_app_assoc` might make progress. The lemma `comp_c_app_assoc` is also better suited for rewrites in the opposite direction. -/ @[reassoc, simp] theorem comp_c_app {X Y Z : PresheafedSpace C} (α : X ⟶ Y) (β : Y ⟶ Z) (U) : (α ≫ β).c.app U = β.c.app U ≫ α.c.app (op ((Opens.map β.base).obj (unop U))) := rfl theorem congr_app {X Y : PresheafedSpace C} {α β : X ⟶ Y} (h : α = β) (U) : α.c.app U = β.c.app U ≫ X.presheaf.map (eqToHom (by subst h; rfl)) := by subst h simp section variable (C) /-- The forgetful functor from `PresheafedSpace` to `TopCat`. -/ @[simps] def forget : PresheafedSpace C ⥤ TopCat where obj X := (X : TopCat) map f := f.base end section Iso variable {X Y : PresheafedSpace C} /-- An isomorphism of `PresheafedSpace`s is a homeomorphism of the underlying space, and a natural transformation between the sheaves. -/ @[simps hom inv] def isoOfComponents (H : X.1 ≅ Y.1) (α : H.hom _* X.2 ≅ Y.2) : X ≅ Y where hom := { base := H.hom c := α.inv } inv := { base := H.inv c := Presheaf.toPushforwardOfIso H α.hom } hom_inv_id := by ext <;> simp inv_hom_id := by ext · dsimp exact H.inv_hom_id_apply _ dsimp simp only [Presheaf.toPushforwardOfIso_app, assoc, ← α.hom.naturality] simp only [eqToHom_map, eqToHom_app, eqToHom_trans_assoc, eqToHom_refl, id_comp] apply Iso.inv_hom_id_app /-- Isomorphic `PresheafedSpace`s have naturally isomorphic presheaves. -/ @[simps] def sheafIsoOfIso (H : X ≅ Y) : Y.2 ≅ H.hom.base _* X.2 where hom := H.hom.c inv := Presheaf.pushforwardToOfIso ((forget _).mapIso H).symm H.inv.c hom_inv_id := by ext U rw [NatTrans.comp_app] simpa using congr_arg (fun f => f ≫ eqToHom _) (congr_app H.inv_hom_id (op U)) inv_hom_id := by ext U dsimp rw [NatTrans.id_app] simp only [Presheaf.pushforwardToOfIso_app, Iso.symm_inv, mapIso_hom, forget_map, Iso.symm_hom, mapIso_inv, eqToHom_map, assoc] have eq₁ := congr_app H.hom_inv_id (op ((Opens.map H.hom.base).obj U)) have eq₂ := H.hom.c.naturality (eqToHom (congr_obj (congr_arg Opens.map ((forget C).congr_map H.inv_hom_id.symm)) U)).op rw [id_c, NatTrans.id_app, id_comp, eqToHom_map, comp_c_app] at eq₁ rw [eqToHom_op, eqToHom_map] at eq₂ erw [eq₂, reassoc_of% eq₁] simp instance base_isIso_of_iso (f : X ⟶ Y) [IsIso f] : IsIso f.base := ((forget _).mapIso (asIso f)).isIso_hom instance c_isIso_of_iso (f : X ⟶ Y) [IsIso f] : IsIso f.c := (sheafIsoOfIso (asIso f)).isIso_hom /-- This could be used in conjunction with `CategoryTheory.NatIso.isIso_of_isIso_app`. -/ theorem isIso_of_components (f : X ⟶ Y) [IsIso f.base] [IsIso f.c] : IsIso f := (isoOfComponents (asIso f.base) (asIso f.c).symm).isIso_hom end Iso section Restrict /-- The restriction of a presheafed space along an open embedding into the space. -/ @[simps] def restrict {U : TopCat} (X : PresheafedSpace C) {f : U ⟶ (X : TopCat)} (h : IsOpenEmbedding f) : PresheafedSpace C where carrier := U presheaf := h.isOpenMap.functor.op ⋙ X.presheaf /-- The map from the restriction of a presheafed space. -/ @[simps] def ofRestrict {U : TopCat} (X : PresheafedSpace C) {f : U ⟶ (X : TopCat)} (h : IsOpenEmbedding f) : X.restrict h ⟶ X where base := f c := { app := fun V => X.presheaf.map (h.isOpenMap.adjunction.counit.app V.unop).op naturality := fun U V f => show _ = _ ≫ X.presheaf.map _ by rw [← map_comp, ← map_comp] rfl } instance ofRestrict_mono {U : TopCat} (X : PresheafedSpace C) (f : U ⟶ X.1) (hf : IsOpenEmbedding f) : Mono (X.ofRestrict hf) := by haveI : Mono f := (TopCat.mono_iff_injective _).mpr hf.injective constructor intro Z g₁ g₂ eq ext1 · have := congr_arg PresheafedSpace.Hom.base eq simp only [PresheafedSpace.comp_base, PresheafedSpace.ofRestrict_base] at this rw [cancel_mono] at this exact this · ext V have hV : (Opens.map (X.ofRestrict hf).base).obj (hf.isOpenMap.functor.obj V) = V := by ext1 exact Set.preimage_image_eq _ hf.injective haveI : IsIso (hf.isOpenMap.adjunction.counit.app (unop (op (hf.isOpenMap.functor.obj V)))) := NatIso.isIso_app_of_isIso (whiskerLeft hf.isOpenMap.functor hf.isOpenMap.adjunction.counit) V have := PresheafedSpace.congr_app eq (op (hf.isOpenMap.functor.obj V)) rw [PresheafedSpace.comp_c_app, PresheafedSpace.comp_c_app, PresheafedSpace.ofRestrict_c_app, Category.assoc, cancel_epi] at this have h : _ ≫ _ = _ ≫ _ ≫ _ := congr_arg (fun f => (X.restrict hf).presheaf.map (eqToHom hV).op ≫ f) this simp only [g₁.c.naturality, g₂.c.naturality_assoc] at h simp only [eqToHom_op, eqToHom_map, eqToHom_trans, ← IsIso.comp_inv_eq, inv_eqToHom, Category.assoc] at h simpa using h theorem restrict_top_presheaf (X : PresheafedSpace C) : (X.restrict (Opens.isOpenEmbedding ⊤)).presheaf = (Opens.inclusionTopIso X.carrier).inv _* X.presheaf := by dsimp rw [Opens.inclusion'_top_functor X.carrier] rfl theorem ofRestrict_top_c (X : PresheafedSpace C) : (X.ofRestrict (Opens.isOpenEmbedding ⊤)).c = eqToHom (by rw [restrict_top_presheaf, ← Presheaf.Pushforward.comp_eq] tauto) := by /- another approach would be to prove the left-hand side is a natural isomorphism, but I encountered a universe issue when `apply NatIso.isIso_of_isIso_app`. -/ ext dsimp [ofRestrict] erw [eqToHom_map, eqToHom_app] simp /-- The map to the restriction of a presheafed space along the canonical inclusion from the top subspace. -/ @[simps] def toRestrictTop (X : PresheafedSpace C) : X ⟶ X.restrict (Opens.isOpenEmbedding ⊤) where base := (Opens.inclusionTopIso X.carrier).inv c := eqToHom (restrict_top_presheaf X) /-- The isomorphism from the restriction to the top subspace. -/ @[simps] def restrictTopIso (X : PresheafedSpace C) : X.restrict (Opens.isOpenEmbedding ⊤) ≅ X where hom := X.ofRestrict _ inv := X.toRestrictTop hom_inv_id := by ext · rfl · erw [comp_c, toRestrictTop_c, whiskerRight_id', comp_id, ofRestrict_top_c, eqToHom_map, eqToHom_trans, eqToHom_refl] rfl inv_hom_id := by ext · rfl · erw [comp_c, ofRestrict_top_c, toRestrictTop_c, eqToHom_map, whiskerRight_id', comp_id, eqToHom_trans, eqToHom_refl] rfl end Restrict /-- The global sections, notated Gamma. -/ @[simps] def Γ : (PresheafedSpace C)ᵒᵖ ⥤ C where obj X := (unop X).presheaf.obj (op ⊤) map f := f.unop.c.app (op ⊤) theorem Γ_obj_op (X : PresheafedSpace C) : Γ.obj (op X) = X.presheaf.obj (op ⊤) := rfl theorem Γ_map_op {X Y : PresheafedSpace C} (f : X ⟶ Y) : Γ.map f.op = f.c.app (op ⊤) := rfl end PresheafedSpace end AlgebraicGeometry open AlgebraicGeometry AlgebraicGeometry.PresheafedSpace variable {C} namespace CategoryTheory variable {D : Type*} [Category D] namespace Functor /-- We can apply a functor `F : C ⥤ D` to the values of the presheaf in any `PresheafedSpace C`, giving a functor `PresheafedSpace C ⥤ PresheafedSpace D` -/ def mapPresheaf (F : C ⥤ D) : PresheafedSpace C ⥤ PresheafedSpace D where obj X := { carrier := X.carrier presheaf := X.presheaf ⋙ F } map f := { base := f.base c := whiskerRight f.c F } -- Porting note: these proofs were automatic in mathlib3 map_id X := by ext <;> cat_disch map_comp f g := by ext <;> cat_disch @[simp] theorem mapPresheaf_obj_X (F : C ⥤ D) (X : PresheafedSpace C) : (F.mapPresheaf.obj X : TopCat) = (X : TopCat) := rfl @[simp] theorem mapPresheaf_obj_presheaf (F : C ⥤ D) (X : PresheafedSpace C) : (F.mapPresheaf.obj X).presheaf = X.presheaf ⋙ F := rfl @[simp] theorem mapPresheaf_map_f (F : C ⥤ D) {X Y : PresheafedSpace C} (f : X ⟶ Y) : (F.mapPresheaf.map f).base = f.base := rfl @[simp] theorem mapPresheaf_map_c (F : C ⥤ D) {X Y : PresheafedSpace C} (f : X ⟶ Y) : (F.mapPresheaf.map f).c = whiskerRight f.c F := rfl end Functor namespace NatTrans /-- A natural transformation induces a natural transformation between the `map_presheaf` functors. -/ def onPresheaf {F G : C ⥤ D} (α : F ⟶ G) : G.mapPresheaf ⟶ F.mapPresheaf where app X := { base := 𝟙 _ c := whiskerLeft X.presheaf α ≫ eqToHom (Presheaf.Pushforward.id_eq _).symm } -- TODO Assemble the last two constructions into a functor -- `(C ⥤ D) ⥤ (PresheafedSpace C ⥤ PresheafedSpace D)` end NatTrans end CategoryTheory
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/PresheafedSpace/HasColimits.lean
import Mathlib.Geometry.RingedSpace.PresheafedSpace import Mathlib.Topology.Category.TopCat.Limits.Basic import Mathlib.Topology.Sheaves.Limits import Mathlib.CategoryTheory.ConcreteCategory.Elementwise /-! # `PresheafedSpace C` has colimits. If `C` has limits, then the category `PresheafedSpace C` has colimits, and the forgetful functor to `TopCat` preserves these colimits. When restricted to a diagram where the underlying continuous maps are open embeddings, this says that we can glue presheafed spaces. Given a diagram `F : J ⥤ PresheafedSpace C`, we first build the colimit of the underlying topological spaces, as `colimit (F ⋙ PresheafedSpace.forget C)`. Call that colimit space `X`. Our strategy is to push each of the presheaves `F.obj j` forward along the continuous map `colimit.ι (F ⋙ PresheafedSpace.forget C) j` to `X`. Since pushforward is functorial, we obtain a diagram `J ⥤ (presheaf C X)ᵒᵖ` of presheaves on a single space `X`. (Note that the arrows now point the other direction, because this is the way `PresheafedSpace C` is set up.) The limit of this diagram then constitutes the colimit presheaf. -/ noncomputable section universe v' u' v u open CategoryTheory Opposite CategoryTheory.Category CategoryTheory.Functor CategoryTheory.Limits TopCat TopCat.Presheaf TopologicalSpace variable {J : Type u'} [Category.{v'} J] {C : Type u} [Category.{v} C] namespace AlgebraicGeometry namespace PresheafedSpace attribute [local simp] eqToHom_map -- We could enable the following attribute: -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opens -- although it doesn't appear to help in this file, in any case. @[simp] theorem map_id_c_app (F : J ⥤ PresheafedSpace.{_, _, v} C) (j) (U) : (F.map (𝟙 j)).c.app U = (Pushforward.id (F.obj j).presheaf).inv.app U ≫ (pushforwardEq (by simp) (F.obj j).presheaf).hom.app U := by simp [PresheafedSpace.congr_app (F.map_id j)] @[simp] theorem map_comp_c_app (F : J ⥤ PresheafedSpace.{_, _, v} C) {j₁ j₂ j₃} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃) (U) : (F.map (f ≫ g)).c.app U = (F.map g).c.app U ≫ ((pushforward C (F.map g).base).map (F.map f).c).app U ≫ (pushforwardEq (congr_arg Hom.base (F.map_comp f g).symm) _).hom.app U := by simp [PresheafedSpace.congr_app (F.map_comp f g)] /-- Given a diagram of `PresheafedSpace C`s, its colimit is computed by pushing the sheaves onto the colimit of the underlying spaces, and taking componentwise limit. This is the componentwise diagram for an open set `U` of the colimit of the underlying spaces. -/ @[simps] def componentwiseDiagram (F : J ⥤ PresheafedSpace.{_, _, v} C) [HasColimit F] (U : Opens (Limits.colimit F).carrier) : Jᵒᵖ ⥤ C where obj j := (F.obj (unop j)).presheaf.obj (op ((Opens.map (colimit.ι F (unop j)).base).obj U)) map {j k} f := (F.map f.unop).c.app _ ≫ (F.obj (unop k)).presheaf.map (eqToHom (by rw [← colimit.w F f.unop, comp_base]; rfl)) map_comp {i j k} f g := by simp only [assoc, CategoryTheory.NatTrans.naturality_assoc] simp variable [HasColimitsOfShape J TopCat.{v}] /-- Given a diagram of presheafed spaces, we can push all the presheaves forward to the colimit `X` of the underlying topological spaces, obtaining a diagram in `(Presheaf C X)ᵒᵖ`. -/ @[simps] def pushforwardDiagramToColimit (F : J ⥤ PresheafedSpace.{_, _, v} C) : J ⥤ (Presheaf C (colimit (F ⋙ PresheafedSpace.forget C)))ᵒᵖ where obj j := op (colimit.ι (F ⋙ PresheafedSpace.forget C) j _* (F.obj j).presheaf) map {j j'} f := ((pushforward C (colimit.ι (F ⋙ PresheafedSpace.forget C) j')).map (F.map f).c ≫ (Pushforward.comp ((F ⋙ PresheafedSpace.forget C).map f) (colimit.ι (F ⋙ PresheafedSpace.forget C) j') (F.obj j).presheaf).inv ≫ (pushforwardEq (colimit.w (F ⋙ PresheafedSpace.forget C) f) (F.obj j).presheaf).hom).op map_id j := by apply (opEquiv _ _).injective refine NatTrans.ext (funext fun U => ?_) induction U with | op U => simp [opEquiv] rfl map_comp {j₁ j₂ j₃} f g := by apply (opEquiv _ _).injective refine NatTrans.ext (funext fun U => ?_) dsimp [opEquiv] have : op ((Opens.map (F.map g).base).obj ((Opens.map (colimit.ι (F ⋙ forget C) j₃)).obj U.unop)) = op ((Opens.map (colimit.ι (F ⋙ PresheafedSpace.forget C) j₂)).obj (unop U)) := by apply unop_injective rw [← Opens.map_comp_obj] congr exact colimit.w (F ⋙ PresheafedSpace.forget C) g simp only [map_comp_c_app, pushforward_obj_obj, pushforward_map_app, comp_base, pushforwardEq_hom_app, op_obj, Opens.map_comp_obj, id_comp, assoc, eqToHom_map_comp, NatTrans.naturality_assoc, pushforward_obj_map, eqToHom_unop] simp [NatTrans.congr (α := (F.map f).c) this] variable [∀ X : TopCat.{v}, HasLimitsOfShape Jᵒᵖ (X.Presheaf C)] /-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.instHasColimits`. -/ def colimit (F : J ⥤ PresheafedSpace.{_, _, v} C) : PresheafedSpace C where carrier := Limits.colimit (F ⋙ PresheafedSpace.forget C) presheaf := limit (pushforwardDiagramToColimit F).leftOp @[simp] theorem colimit_carrier (F : J ⥤ PresheafedSpace.{_, _, v} C) : (colimit F).carrier = Limits.colimit (F ⋙ PresheafedSpace.forget C) := rfl @[simp] theorem colimit_presheaf (F : J ⥤ PresheafedSpace.{_, _, v} C) : (colimit F).presheaf = limit (pushforwardDiagramToColimit F).leftOp := rfl /-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.instHasColimits`. -/ @[simps] def colimitCocone (F : J ⥤ PresheafedSpace.{_, _, v} C) : Cocone F where pt := colimit F ι := { app := fun j => { base := colimit.ι (F ⋙ PresheafedSpace.forget C) j c := limit.π _ (op j) } naturality := fun {j j'} f => by ext1 · ext x exact colimit.w_apply (F ⋙ PresheafedSpace.forget C) f x · ext ⟨U, hU⟩ dsimp [-Presheaf.comp_app] rw [PresheafedSpace.id_c_app, map_id] erw [id_comp] rw [NatTrans.comp_app, PresheafedSpace.comp_c_app, whiskerRight_app, eqToHom_app, ← congr_arg NatTrans.app (limit.w (pushforwardDiagramToColimit F).leftOp f.op), NatTrans.comp_app, Functor.leftOp_map, pushforwardDiagramToColimit_map] simp } variable [HasLimitsOfShape Jᵒᵖ C] namespace ColimitCoconeIsColimit /-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.colimitCoconeIsColimit`. -/ def descCApp (F : J ⥤ PresheafedSpace.{_, _, v} C) (s : Cocone F) (U : (Opens s.pt.carrier)ᵒᵖ) : s.pt.presheaf.obj U ⟶ (colimit.desc (F ⋙ PresheafedSpace.forget C) ((PresheafedSpace.forget C).mapCocone s) _* limit (pushforwardDiagramToColimit F).leftOp).obj U := by refine limit.lift _ { pt := s.pt.presheaf.obj U π := { app := fun j => ?_ naturality := fun j j' f => ?_ } } ≫ (limitObjIsoLimitCompEvaluation _ _).inv -- We still need to construct the `app` and `naturality'` fields omitted above. · refine (s.ι.app (unop j)).c.app U ≫ (F.obj (unop j)).presheaf.map (eqToHom ?_) dsimp rw [← Opens.map_comp_obj] simp · dsimp rw [PresheafedSpace.congr_app (s.w f.unop).symm U] have w := Functor.congr_obj (congr_arg Opens.map (colimit.ι_desc ((PresheafedSpace.forget C).mapCocone s) (unop j))) (unop U) simp only [Opens.map_comp_obj_unop] at w replace w := congr_arg op w have w' := NatTrans.congr (F.map f.unop).c w rw [w'] simp theorem desc_c_naturality (F : J ⥤ PresheafedSpace.{_, _, v} C) (s : Cocone F) {U V : (Opens s.pt.carrier)ᵒᵖ} (i : U ⟶ V) : s.pt.presheaf.map i ≫ descCApp F s V = descCApp F s U ≫ (colimit.desc (F ⋙ forget C) ((forget C).mapCocone s) _* (colimitCocone F).pt.presheaf).map i := by dsimp [descCApp] refine limit_obj_ext (fun j => ?_) have w := Functor.congr_hom (congr_arg Opens.map (colimit.ι_desc ((PresheafedSpace.forget C).mapCocone s) (unop j))) i.unop simp only [Opens.map_comp_map] at w simp [congr_arg Quiver.Hom.op w] /-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.colimitCoconeIsColimit`. -/ def desc (F : J ⥤ PresheafedSpace.{_, _, v} C) (s : Cocone F) : colimit F ⟶ s.pt where base := colimit.desc (F ⋙ PresheafedSpace.forget C) ((PresheafedSpace.forget C).mapCocone s) c := { app := fun U => descCApp F s U naturality := fun _ _ i => desc_c_naturality F s i } theorem desc_fac (F : J ⥤ PresheafedSpace.{_, _, v} C) (s : Cocone F) (j : J) : (colimitCocone F).ι.app j ≫ desc F s = s.ι.app j := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): the original proof is just -- `ext <;> dsimp [desc, descCApp] <;> simpa`, -- but this has to be expanded a bit ext U · simp [desc] · simp only [op_obj, desc, descCApp, Presheaf.comp_app, comp_c_app, colimitCocone_ι_app_c, assoc] rw [limitObjIsoLimitCompEvaluation_inv_π_app_assoc] simp end ColimitCoconeIsColimit open ColimitCoconeIsColimit /-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.instHasColimits`. -/ def colimitCoconeIsColimit (F : J ⥤ PresheafedSpace.{_, _, v} C) : IsColimit (colimitCocone F) where desc s := desc F s fac s := desc_fac F s uniq s m w := by -- We need to use the identity on the continuous maps twice, so we prepare that first: have t : m.base = colimit.desc (F ⋙ PresheafedSpace.forget C) ((PresheafedSpace.forget C).mapCocone s) := by dsimp -- `colimit.hom_ext` used to be automatically applied by `ext` before https://github.com/leanprover-community/mathlib4/pull/21302 apply colimit.hom_ext fun j => ?_ ext rw [colimit.ι_desc, mapCocone_ι_app, ← w j] simp ext : 1 · exact t · refine NatTrans.ext (funext fun U => limit_obj_ext fun j => ?_) simp [desc, descCApp, PresheafedSpace.congr_app (w (unop j)).symm U, NatTrans.congr (limit.π (pushforwardDiagramToColimit F).leftOp j) (congr_arg op (Functor.congr_obj (congr_arg Opens.map t) (unop U)))] instance : HasColimitsOfShape J (PresheafedSpace.{_, _, v} C) where has_colimit F := ⟨colimitCocone F, colimitCoconeIsColimit F⟩ instance : PreservesColimitsOfShape J (PresheafedSpace.forget.{u, v, v} C) := ⟨fun {F} => preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit F) <| by apply IsColimit.ofIsoColimit (colimit.isColimit _) fapply Cocones.ext · rfl · simp⟩ /-- When `C` has limits, the category of presheafed spaces with values in `C` itself has colimits. -/ instance instHasColimits [HasLimits C] : HasColimits (PresheafedSpace.{_, _, v} C) := ⟨fun {_ _} => ⟨fun {F} => ⟨colimitCocone F, colimitCoconeIsColimit F⟩⟩⟩ /-- The underlying topological space of a colimit of presheafed spaces is the colimit of the underlying topological spaces. -/ instance forget_preservesColimits [HasLimits C] : PreservesColimits (PresheafedSpace.forget.{_, _, v} C) where preservesColimitsOfShape {J 𝒥} := { preservesColimit := fun {F} => preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit F) (IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (Iso.refl _))) } /-- The components of the colimit of a diagram of `PresheafedSpace C` is obtained via taking componentwise limits. -/ def colimitPresheafObjIsoComponentwiseLimit (F : J ⥤ PresheafedSpace.{_, _, v} C) [HasColimit F] (U : Opens (Limits.colimit F).carrier) : (Limits.colimit F).presheaf.obj (op U) ≅ limit (componentwiseDiagram F U) := by refine ((sheafIsoOfIso (colimit.isoColimitCocone ⟨_, colimitCoconeIsColimit F⟩).symm).app (op U)).trans ?_ refine (limitObjIsoLimitCompEvaluation _ _).trans (Limits.lim.mapIso ?_) fapply NatIso.ofComponents · intro X refine (F.obj (unop X)).presheaf.mapIso (eqToIso ?_) simp only [Functor.op_obj, op_inj_iff, Opens.map_coe, SetLike.ext'_iff, Set.preimage_preimage] refine congr_arg (Set.preimage · U.1) (funext fun x => ?_) erw [← TopCat.comp_app] congr exact ι_preservesColimitIso_inv (forget C) F (unop X) · intro X Y f change ((F.map f.unop).c.app _ ≫ _ ≫ _) ≫ (F.obj (unop Y)).presheaf.map _ = _ ≫ _ rw [TopCat.Presheaf.Pushforward.comp_inv_app] erw [Category.id_comp] rw [Category.assoc] erw [← (F.obj (unop Y)).presheaf.map_comp, (F.map f.unop).c.naturality_assoc, ← (F.obj (unop Y)).presheaf.map_comp] rfl @[simp] theorem colimitPresheafObjIsoComponentwiseLimit_inv_ι_app (F : J ⥤ PresheafedSpace.{_, _, v} C) (U : Opens (Limits.colimit F).carrier) (j : J) : (colimitPresheafObjIsoComponentwiseLimit F U).inv ≫ (colimit.ι F j).c.app (op U) = limit.π _ (op j) := by delta colimitPresheafObjIsoComponentwiseLimit rw [Iso.trans_inv, Iso.trans_inv, Iso.app_inv, sheafIsoOfIso_inv, pushforwardToOfIso_app, congr_app (Iso.symm_inv _)] dsimp rw [map_id, comp_id, assoc, assoc, assoc, NatTrans.naturality, ← comp_c_app_assoc, congr_app (colimit.isoColimitCocone_ι_hom _ _), assoc] erw [limitObjIsoLimitCompEvaluation_inv_π_app_assoc, limMap_π_assoc] simp @[simp] theorem colimitPresheafObjIsoComponentwiseLimit_hom_π (F : J ⥤ PresheafedSpace.{_, _, v} C) (U : Opens (Limits.colimit F).carrier) (j : J) : (colimitPresheafObjIsoComponentwiseLimit F U).hom ≫ limit.π _ (op j) = (colimit.ι F j).c.app (op U) := by rw [← Iso.eq_inv_comp, colimitPresheafObjIsoComponentwiseLimit_inv_ι_app] end PresheafedSpace end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/PresheafedSpace/Gluing.lean
import Mathlib.Topology.Gluing import Mathlib.Geometry.RingedSpace.OpenImmersion import Mathlib.Geometry.RingedSpace.LocallyRingedSpace.HasColimits /-! # Gluing structured spaces Given a family of gluing data of structured spaces (presheafed spaces, sheafed spaces, or locally ringed spaces), we may glue them together. The construction should be "sealed" and considered as a black box, while only using the API provided. ## Main definitions * `AlgebraicGeometry.PresheafedSpace.GlueData`: A structure containing the family of gluing data. * `CategoryTheory.GlueData.glued`: The glued presheafed space. This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API can be used. * `CategoryTheory.GlueData.ι`: The immersion `ι i : U i ⟶ glued` for each `i : J`. ## Main results * `AlgebraicGeometry.PresheafedSpace.GlueData.ιIsOpenImmersion`: The map `ι i : U i ⟶ glued` is an open immersion for each `i : J`. * `AlgebraicGeometry.PresheafedSpace.GlueData.ι_jointly_surjective` : The underlying maps of `ι i : U i ⟶ glued` are jointly surjective. * `AlgebraicGeometry.PresheafedSpace.GlueData.vPullbackConeIsLimit` : `V i j` is the pullback (intersection) of `U i` and `U j` over the glued space. Analogous results are also provided for `SheafedSpace` and `LocallyRingedSpace`. ## Implementation details Almost the whole file is dedicated to showing that `ι i` is an open immersion. The fact that this is an open embedding of topological spaces follows from `Mathlib/Topology/Gluing.lean`, and it remains to construct `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_X, ι i '' U)` for each `U ⊆ U i`. Since `Γ(𝒪_X, ι i '' U)` is the limit of `diagram_over_open`, the components of the structure sheaves of the spaces in the gluing diagram, we need to construct a map `ιInvApp_π_app : Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_V, U_V)` for each `V` in the gluing diagram. We will refer to ![this diagram](https://i.imgur.com/P0phrwr.png) in the following docstrings. The `X` is the glued space, and the dotted arrow is a partial inverse guaranteed by the fact that it is an open immersion. The map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{U_j}, _)` is given by the composition of the red arrows, and the map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{V_{jk}}, _)` is given by the composition of the blue arrows. To lift this into a map from `Γ(𝒪_X, ι i '' U)`, we also need to show that these commute with the maps in the diagram (the green arrows), which is just a lengthy diagram-chasing. -/ noncomputable section open TopologicalSpace CategoryTheory Opposite Topology open CategoryTheory.Limits AlgebraicGeometry.PresheafedSpace open AlgebraicGeometry.PresheafedSpace.IsOpenImmersion open CategoryTheory.GlueData namespace AlgebraicGeometry universe v u variable (C : Type u) [Category.{v} C] namespace PresheafedSpace /-- A family of gluing data consists of 1. An index type `J` 2. A presheafed space `U i` for each `i : J`. 3. A presheafed space `V i j` for each `i j : J`. (Note that this is `J × J → PresheafedSpace C` rather than `J → J → PresheafedSpace C` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the spaces `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subspaces of the glued space. -/ structure GlueData extends CategoryTheory.GlueData (PresheafedSpace.{u, v, v} C) where f_open : ∀ i j, IsOpenImmersion (f i j) attribute [instance] GlueData.f_open namespace GlueData variable {C} variable (D : GlueData.{v, u} C) local notation "𝖣" => D.toGlueData local notation "π₁ " i ", " j ", " k => pullback.fst (D.f i j) (D.f i k) local notation "π₂ " i ", " j ", " k => pullback.snd (D.f i j) (D.f i k) set_option quotPrecheck false local notation "π₁⁻¹ " i ", " j ", " k => (PresheafedSpace.IsOpenImmersion.pullbackFstOfRight (D.f i j) (D.f i k)).invApp set_option quotPrecheck false local notation "π₂⁻¹ " i ", " j ", " k => (PresheafedSpace.IsOpenImmersion.pullbackSndOfLeft (D.f i j) (D.f i k)).invApp /-- The glue data of topological spaces associated to a family of glue data of PresheafedSpaces. -/ abbrev toTopGlueData : TopCat.GlueData := { f_open := fun i j => (D.f_open i j).base_open toGlueData := 𝖣.mapGlueData (forget C) } theorem ι_isOpenEmbedding [HasLimits C] (i : D.J) : IsOpenEmbedding (𝖣.ι i).base := by rw [← show _ = (𝖣.ι i).base from 𝖣.ι_gluedIso_inv (PresheafedSpace.forget _) _, TopCat.coe_comp] exact (TopCat.homeoOfIso (𝖣.gluedIso (PresheafedSpace.forget _)).symm).isOpenEmbedding.comp (D.toTopGlueData.ι_isOpenEmbedding i) theorem pullback_base (i j k : D.J) (S : Set (D.V (i, j)).carrier) : (π₂ i, j, k) '' ((π₁ i, j, k) ⁻¹' S) = D.f i k ⁻¹' (D.f i j '' S) := by have eq₁ : _ = (π₁ i, j, k).base := PreservesPullback.iso_hom_fst (forget C) _ _ have eq₂ : _ = (π₂ i, j, k).base := PreservesPullback.iso_hom_snd (forget C) _ _ rw [← eq₁, ← eq₂, TopCat.coe_comp, Set.image_comp, TopCat.coe_comp, Set.preimage_comp, Set.image_preimage_eq] · simp only [forget_obj, forget_map, TopCat.pullback_snd_image_fst_preimage] rw [← TopCat.epi_iff_surjective] infer_instance /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/0GiBUh6.png) commute. -/ @[simp, reassoc] theorem f_invApp_f_app (i j k : D.J) (U : Opens (D.V (i, j)).carrier) : (D.f_open i j).invApp _ U ≫ (D.f i k).c.app _ = (π₁ i, j, k).c.app (op U) ≫ (π₂⁻¹ i, j, k) (unop _) ≫ (D.V _).presheaf.map (eqToHom (by delta IsOpenImmersion.opensFunctor dsimp only [Functor.op, IsOpenMap.functor, Opens.map, unop_op] congr apply pullback_base)) := by have := PresheafedSpace.congr_app (@pullback.condition _ _ _ _ _ (D.f i j) (D.f i k) _) dsimp only [comp_c_app] at this rw [← cancel_epi (inv ((D.f_open i j).invApp _ U)), IsIso.inv_hom_id_assoc, IsOpenImmersion.inv_invApp] simp_rw [Category.assoc] erw [(π₁ i, j, k).c.naturality_assoc, reassoc_of% this, ← Functor.map_comp_assoc, IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.app_invApp_assoc, ← (D.V (i, k)).presheaf.map_comp, ← (D.V (i, k)).presheaf.map_comp] convert (Category.comp_id _).symm erw [(D.V (i, k)).presheaf.map_id] rfl /-- We can prove the `eq` along with the lemma. Thus this is bundled together here, and the lemma itself is separated below. -/ theorem snd_invApp_t_app' (i j k : D.J) (U : Opens (pullback (D.f i j) (D.f i k)).carrier) : ∃ eq, (π₂⁻¹ i, j, k) U ≫ (D.t k i).c.app _ ≫ (D.V (k, i)).presheaf.map (eqToHom eq) = (D.t' k i j).c.app _ ≫ (π₁⁻¹ k, j, i) (unop _) := by fconstructor -- Porting note: I don't know what the magic was in Lean3 proof, it just skipped the proof of `eq` · delta IsOpenImmersion.opensFunctor dsimp only [Functor.op, Opens.map, IsOpenMap.functor, unop_op, Opens.coe_mk] congr 2 have := (𝖣.t_fac k i j).symm rw [← IsIso.inv_comp_eq] at this replace this := (congr_arg ((PresheafedSpace.Hom.base ·)) this).symm replace this := congr_arg (TopCat.Hom.hom ·) this replace this := congr_arg (ContinuousMap.toFun ·) this dsimp at this rw [this, Set.image_comp, Set.image_comp, Set.preimage_image_eq] swap · refine Function.HasLeftInverse.injective ⟨(D.t i k).base, fun x => ?_⟩ rw [← ConcreteCategory.comp_apply, ← comp_base, D.t_inv, id_base, ConcreteCategory.id_apply] refine congr_arg (_ '' ·) ?_ refine congr_fun ?_ _ refine Set.image_eq_preimage_of_inverse ?_ ?_ · intro x rw [← ConcreteCategory.comp_apply, ← comp_base, IsIso.inv_hom_id, id_base, ConcreteCategory.id_apply] · intro x rw [← ConcreteCategory.comp_apply, ← comp_base, IsIso.hom_inv_id, id_base, ConcreteCategory.id_apply] · rw [← IsIso.eq_inv_comp, IsOpenImmersion.inv_invApp, Category.assoc, (D.t' k i j).c.naturality_assoc] simp_rw [← Category.assoc] dsimp rw [← comp_c_app, congr_app (D.t_fac k i j), comp_c_app] dsimp simp_rw [Category.assoc] rw [IsOpenImmersion.inv_naturality, IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.app_inv_app'_assoc] · simp_rw [← (𝖣.V (k, i)).presheaf.map_comp]; rfl rintro x ⟨y, -, eq⟩ replace eq := ConcreteCategory.congr_arg (𝖣.t i k).base eq change ((π₂ i, j, k) ≫ D.t i k).base y = (D.t k i ≫ D.t i k).base x at eq rw [𝖣.t_inv, id_base, TopCat.id_app] at eq subst eq use (inv (D.t' k i j)).base y change (inv (D.t' k i j) ≫ π₁ k, i, j).base y = _ congr 3 rw [IsIso.inv_comp_eq, 𝖣.t_fac_assoc, 𝖣.t_inv, Category.comp_id] /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/q6X1GJ9.png) commute. -/ @[simp, reassoc] theorem snd_invApp_t_app (i j k : D.J) (U : Opens (pullback (D.f i j) (D.f i k)).carrier) : (π₂⁻¹ i, j, k) U ≫ (D.t k i).c.app _ = (D.t' k i j).c.app _ ≫ (π₁⁻¹ k, j, i) (unop _) ≫ (D.V (k, i)).presheaf.map (eqToHom (D.snd_invApp_t_app' i j k U).choose.symm) := by have e := (D.snd_invApp_t_app' i j k U).choose_spec replace e := reassoc_of% e rw [← e] simp [eqToHom_map] variable [HasLimits C] theorem ι_image_preimage_eq (i j : D.J) (U : Opens (D.U i).carrier) : (Opens.map (𝖣.ι j).base).obj ((D.ι_isOpenEmbedding i).isOpenMap.functor.obj U) = (opensFunctor (D.f j i)).obj ((Opens.map (𝖣.t j i).base).obj ((Opens.map (𝖣.f i j).base).obj U)) := by ext1 dsimp only [Opens.map_coe, IsOpenMap.coe_functor_obj] rw [← show _ = (𝖣.ι i).base from 𝖣.ι_gluedIso_inv (PresheafedSpace.forget _) i, ← show _ = (𝖣.ι j).base from 𝖣.ι_gluedIso_inv (PresheafedSpace.forget _) j] rw [TopCat.coe_comp, TopCat.coe_comp, Set.image_comp, Set.preimage_comp, Set.preimage_image_eq] · refine Eq.trans (D.toTopGlueData.preimage_image_eq_image' _ _ _) ?_ dsimp rw [Set.image_comp] refine congr_arg (_ '' ·) ?_ rw [Set.eq_preimage_iff_image_eq, ← Set.image_comp] swap · exact CategoryTheory.ConcreteCategory.bijective_of_isIso (C := TopCat) _ change (D.t i j ≫ D.t j i).base '' _ = _ rw [𝖣.t_inv] simp · rw [← TopCat.mono_iff_injective] infer_instance /-- (Implementation). The map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{U_j}, 𝖣.ι j ⁻¹' (𝖣.ι i '' U))` -/ def opensImagePreimageMap (i j : D.J) (U : Opens (D.U i).carrier) : (D.U i).presheaf.obj (op U) ⟶ (D.U j).presheaf.obj (op <| (Opens.map (𝖣.ι j).base).obj ((D.ι_isOpenEmbedding i).isOpenMap.functor.obj U)) := (D.f i j).c.app (op U) ≫ (D.t j i).c.app _ ≫ (D.f_open j i).invApp _ (unop _) ≫ (𝖣.U j).presheaf.map (eqToHom (D.ι_image_preimage_eq i j U)).op theorem opensImagePreimageMap_app' (i j k : D.J) (U : Opens (D.U i).carrier) : ∃ eq, D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eqToHom eq) := by constructor · delta opensImagePreimageMap simp_rw [Category.assoc] rw [(D.f j k).c.naturality, f_invApp_f_app_assoc] · erw [← (D.V (j, k)).presheaf.map_comp] · simp_rw [← Category.assoc] erw [← comp_c_app, ← comp_c_app] · simp_rw [Category.assoc] dsimp only [Functor.op, unop_op, Quiver.Hom.unop_op] rw [eqToHom_map (Opens.map _), eqToHom_op, eqToHom_trans] congr /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/mBzV1Rx.png) commute. -/ theorem opensImagePreimageMap_app (i j k : D.J) (U : Opens (D.U i).carrier) : D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eqToHom (opensImagePreimageMap_app' D i j k U).choose) := (opensImagePreimageMap_app' D i j k U).choose_spec -- This is proved separately since `reassoc` somehow timeouts. theorem opensImagePreimageMap_app_assoc (i j k : D.J) (U : Opens (D.U i).carrier) {X' : C} (f' : _ ⟶ X') : D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ ≫ f' = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eqToHom (opensImagePreimageMap_app' D i j k U).choose) ≫ f' := by simpa only [Category.assoc] using congr_arg (· ≫ f') (opensImagePreimageMap_app D i j k U) /-- (Implementation) Given an open subset of one of the spaces `U ⊆ Uᵢ`, the sheaf component of the image `ι '' U` in the glued space is the limit of this diagram. -/ abbrev diagramOverOpen {i : D.J} (U : Opens (D.U i).carrier) : (WalkingMultispan (.prod D.J))ᵒᵖ ⥤ C := componentwiseDiagram 𝖣.diagram.multispan ((D.ι_isOpenEmbedding i).isOpenMap.functor.obj U) /-- (Implementation) The projection from the limit of `diagram_over_open` to a component of `D.U j`. -/ abbrev diagramOverOpenπ {i : D.J} (U : Opens (D.U i).carrier) (j : D.J) := limit.π (D.diagramOverOpen U) (op (WalkingMultispan.right j)) /-- (Implementation) We construct the map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_V, U_V)` for each `V` in the gluing diagram. We will lift these maps into `ιInvApp`. -/ def ιInvAppπApp {i : D.J} (U : Opens (D.U i).carrier) (j) : (𝖣.U i).presheaf.obj (op U) ⟶ (D.diagramOverOpen U).obj (op j) := by rcases j with (⟨j, k⟩ | j) · refine D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ ≫ (D.V (j, k)).presheaf.map (eqToHom ?_) rw [Functor.op_obj] congr 1; ext1 dsimp only [Functor.op_obj, Opens.map_coe, unop_op, IsOpenMap.coe_functor_obj] rw [Set.preimage_preimage] change (D.f j k ≫ 𝖣.ι j).base ⁻¹' _ = _ congr 4 exact colimit.w 𝖣.diagram.multispan (WalkingMultispan.Hom.fst (j, k)) · exact D.opensImagePreimageMap i j U /-- (Implementation) The natural map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_X, 𝖣.ι i '' U)`. This forms the inverse of `(𝖣.ι i).c.app (op U)`. -/ def ιInvApp {i : D.J} (U : Opens (D.U i).carrier) : (D.U i).presheaf.obj (op U) ⟶ limit (D.diagramOverOpen U) := limit.lift (D.diagramOverOpen U) { pt := (D.U i).presheaf.obj (op U) π := { app := fun j => D.ιInvAppπApp U (unop j) naturality := fun {X Y} f' => by induction X with | op X => ?_ induction Y with | op Y => ?_ let f : Y ⟶ X := f'.unop; have : f' = f.op := rfl; clear_value f; subst this rcases f with (_ | ⟨j, k⟩ | ⟨j, k⟩) · simp · simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.id_comp] congr 1 simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.id_comp] -- It remains to show that the blue is equal to red + green in the original diagram. -- The proof strategy is illustrated in ![this diagram](https://i.imgur.com/mBzV1Rx.png) -- where we prove red = pink = light-blue = green = blue. change D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ ≫ (D.V (j, k)).presheaf.map (eqToHom _) = D.opensImagePreimageMap _ _ _ ≫ ((D.f k j).c.app _ ≫ (D.t j k).c.app _) ≫ (D.V (j, k)).presheaf.map (eqToHom _) rw [opensImagePreimageMap_app_assoc] simp_rw [Category.assoc] rw [opensImagePreimageMap_app_assoc, (D.t j k).c.naturality_assoc, snd_invApp_t_app_assoc, ← PresheafedSpace.comp_c_app_assoc] -- light-blue = green is relatively easy since the part that differs does not involve -- partial inverses. have : D.t' j k i ≫ (π₁ k, i, j) ≫ D.t k i ≫ 𝖣.f i k = (pullbackSymmetry _ _).hom ≫ (π₁ j, i, k) ≫ D.t j i ≫ D.f i j := by rw [← 𝖣.t_fac_assoc, 𝖣.t'_comp_eq_pullbackSymmetry_assoc, pullbackSymmetry_hom_comp_snd_assoc, pullback.condition, 𝖣.t_fac_assoc] rw [congr_app this, PresheafedSpace.comp_c_app_assoc (pullbackSymmetry _ _).hom] simp_rw [Category.assoc] congr 1 rw [← IsIso.eq_inv_comp, IsOpenImmersion.inv_invApp, Category.assoc, NatTrans.naturality_assoc] simp_rw [Functor.op_obj] rw [← PresheafedSpace.comp_c_app_assoc, congr_app (pullbackSymmetry_hom_comp_snd _ _)] simp_rw [Category.assoc, Functor.op_obj, comp_base, Opens.map_comp_obj, TopCat.Presheaf.pushforward_obj_map] rw [IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.app_invApp_assoc] repeat rw [← (D.V (j, k)).presheaf.map_comp] rfl } } /-- `ιInvApp` is the left inverse of `D.ι i` on `U`. -/ theorem ιInvApp_π {i : D.J} (U : Opens (D.U i).carrier) : ∃ eq, D.ιInvApp U ≫ D.diagramOverOpenπ U i = (D.U i).presheaf.map (eqToHom eq) := by fconstructor -- Porting note: I don't know what the magic was in Lean3 proof, it just skipped the proof of `eq` · congr; ext1; change _ = _ ⁻¹' (_ '' _); ext1 x simp only [SetLike.mem_coe, unop_op, Set.mem_preimage, Set.mem_image] refine ⟨fun h => ⟨_, h, rfl⟩, ?_⟩ rintro ⟨y, h1, h2⟩ convert h1 using 1 delta ι Multicoequalizer.π at h2 apply_fun (D.ι _).base · exact h2.symm · have := D.ι_gluedIso_inv (PresheafedSpace.forget _) i dsimp at this rw [← this, TopCat.coe_comp] refine Function.Injective.comp ?_ (TopCat.GlueData.ι_injective D.toTopGlueData i) rw [← TopCat.mono_iff_injective] infer_instance delta ιInvApp rw [limit.lift_π] change D.opensImagePreimageMap i i U = _ dsimp [opensImagePreimageMap] rw [congr_app (D.t_id _), id_c_app, ← Functor.map_comp] erw [IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.app_inv_app'_assoc] · simp only [eqToHom_op, ← Functor.map_comp] rfl · rw [Set.range_eq_univ.mpr _] · simp · rw [← TopCat.epi_iff_surjective] infer_instance /-- The `eqToHom` given by `ιInvApp_π`. -/ abbrev ιInvAppπEqMap {i : D.J} (U : Opens (D.U i).carrier) := (D.U i).presheaf.map (eqToIso (D.ιInvApp_π U).choose).inv /-- `ιInvApp` is the right inverse of `D.ι i` on `U`. -/ theorem π_ιInvApp_π (i j : D.J) (U : Opens (D.U i).carrier) : D.diagramOverOpenπ U i ≫ D.ιInvAppπEqMap U ≫ D.ιInvApp U ≫ D.diagramOverOpenπ U j = D.diagramOverOpenπ U j := by rw [← @cancel_mono (f := (componentwiseDiagram 𝖣.diagram.multispan _).map (Quiver.Hom.op (WalkingMultispan.Hom.snd (i, j))) ≫ 𝟙 _) ..] · simp_rw [Category.assoc] rw [limit.w_assoc] erw [limit.lift_π_assoc] rw [Category.comp_id, Category.comp_id] change _ ≫ _ ≫ (_ ≫ _) ≫ _ = _ rw [congr_app (D.t_id _), id_c_app] simp_rw [Category.assoc] rw [← Functor.map_comp_assoc] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): change `rw` to `erw` erw [IsOpenImmersion.inv_naturality_assoc] erw [IsOpenImmersion.app_invApp_assoc] iterate 3 rw [← Functor.map_comp_assoc] rw [NatTrans.naturality_assoc] erw [← (D.V (i, j)).presheaf.map_comp] convert limit.w (componentwiseDiagram 𝖣.diagram.multispan _) (Quiver.Hom.op (WalkingMultispan.Hom.fst (i, j))) · rw [Category.comp_id] apply (config := { allowSynthFailures := true }) mono_comp change Mono ((_ ≫ D.f j i).c.app _) rw [comp_c_app] apply (config := { allowSynthFailures := true }) mono_comp · erw [D.ι_image_preimage_eq i j U] infer_instance · have : IsIso (D.t i j).c := by apply c_isIso_of_iso infer_instance /-- `ιInvApp` is the inverse of `D.ι i` on `U`. -/ theorem π_ιInvApp_eq_id (i : D.J) (U : Opens (D.U i).carrier) : D.diagramOverOpenπ U i ≫ D.ιInvAppπEqMap U ≫ D.ιInvApp U = 𝟙 _ := by ext j induction j with | op j => ?_ rcases j with (⟨j, k⟩ | ⟨j⟩) · rw [← limit.w (componentwiseDiagram 𝖣.diagram.multispan _) (Quiver.Hom.op (WalkingMultispan.Hom.fst (j, k))), ← Category.assoc, Category.id_comp] congr 1 simp_rw [Category.assoc] apply π_ιInvApp_π · simp_rw [Category.assoc] rw [Category.id_comp] apply π_ιInvApp_π instance componentwise_diagram_π_isIso (i : D.J) (U : Opens (D.U i).carrier) : IsIso (D.diagramOverOpenπ U i) := by use D.ιInvAppπEqMap U ≫ D.ιInvApp U constructor · apply π_ιInvApp_eq_id · rw [Category.assoc, (D.ιInvApp_π _).choose_spec] exact Iso.inv_hom_id ((D.U i).presheaf.mapIso (eqToIso _)) instance ιIsOpenImmersion (i : D.J) : IsOpenImmersion (𝖣.ι i) where base_open := D.ι_isOpenEmbedding i c_iso U := by erw [← colimitPresheafObjIsoComponentwiseLimit_hom_π]; infer_instance /-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`. Vᵢⱼ ⟶ Uᵢ | | ↓ ↓ Uⱼ ⟶ X -/ def vPullbackConeIsLimit (i j : D.J) : IsLimit (𝖣.vPullbackCone i j) := PullbackCone.isLimitAux' _ fun s => by refine ⟨?_, ?_, ?_, ?_⟩ · refine PresheafedSpace.IsOpenImmersion.lift (D.f i j) s.fst ?_ erw [← D.toTopGlueData.preimage_range j i] have : s.fst.base ≫ D.toTopGlueData.ι i = s.snd.base ≫ D.toTopGlueData.ι j := by rw [← 𝖣.ι_gluedIso_hom (PresheafedSpace.forget _) _, ← 𝖣.ι_gluedIso_hom (PresheafedSpace.forget _) _] have := congr_arg PresheafedSpace.Hom.base s.condition rw [comp_base, comp_base] at this replace this := reassoc_of% this exact this _ simp only [mapGlueData_U, forget_obj] rw [← Set.image_subset_iff, ← Set.image_univ, ← Set.image_comp, Set.image_univ, ← TopCat.coe_comp, this, TopCat.coe_comp, ← Set.image_univ, Set.image_comp] exact Set.image_subset_range _ _ · apply IsOpenImmersion.lift_fac · rw [← cancel_mono (𝖣.ι j), Category.assoc, ← (𝖣.vPullbackCone i j).condition] conv_rhs => rw [← s.condition] erw [IsOpenImmersion.lift_fac_assoc] · intro m e₁ _ rw [← cancel_mono (D.f i j)] simp only [lift_fac] tauto theorem ι_jointly_surjective (x : 𝖣.glued) : ∃ (i : D.J) (y : D.U i), (𝖣.ι i).base y = x := 𝖣.ι_jointly_surjective (PresheafedSpace.forget _ ⋙ CategoryTheory.forget TopCat) x end GlueData end PresheafedSpace namespace SheafedSpace /-- A family of gluing data consists of 1. An index type `J` 2. A sheafed space `U i` for each `i : J`. 3. A sheafed space `V i j` for each `i j : J`. (Note that this is `J × J → SheafedSpace C` rather than `J → J → SheafedSpace C` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the spaces `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subspaces of the glued space. -/ structure GlueData extends CategoryTheory.GlueData (SheafedSpace.{u, v, v} C) where f_open : ∀ i j, SheafedSpace.IsOpenImmersion (f i j) attribute [instance] GlueData.f_open namespace GlueData variable {C} variable (D : GlueData C) local notation "𝖣" => D.toGlueData /-- The glue data of presheafed spaces associated to a family of glue data of sheafed spaces. -/ abbrev toPresheafedSpaceGlueData : PresheafedSpace.GlueData C := { f_open := D.f_open toGlueData := 𝖣.mapGlueData forgetToPresheafedSpace } variable [HasLimits C] /-- The gluing as sheafed spaces is isomorphic to the gluing as presheafed spaces. -/ abbrev isoPresheafedSpace : 𝖣.glued.toPresheafedSpace ≅ D.toPresheafedSpaceGlueData.toGlueData.glued := 𝖣.gluedIso forgetToPresheafedSpace theorem ι_isoPresheafedSpace_inv (i : D.J) : D.toPresheafedSpaceGlueData.toGlueData.ι i ≫ D.isoPresheafedSpace.inv = 𝖣.ι i := 𝖣.ι_gluedIso_inv _ _ instance ιIsOpenImmersion (i : D.J) : IsOpenImmersion (𝖣.ι i) := by rw [← D.ι_isoPresheafedSpace_inv] have := D.toPresheafedSpaceGlueData.ιIsOpenImmersion i infer_instance theorem ι_jointly_surjective (x : 𝖣.glued) : ∃ (i : D.J) (y : D.U i), (𝖣.ι i).base y = x := 𝖣.ι_jointly_surjective (SheafedSpace.forget _ ⋙ CategoryTheory.forget TopCat) x /-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`. Vᵢⱼ ⟶ Uᵢ | | ↓ ↓ Uⱼ ⟶ X -/ def vPullbackConeIsLimit (i j : D.J) : IsLimit (𝖣.vPullbackCone i j) := 𝖣.vPullbackConeIsLimitOfMap forgetToPresheafedSpace i j (D.toPresheafedSpaceGlueData.vPullbackConeIsLimit _ _) end GlueData end SheafedSpace namespace LocallyRingedSpace /-- A family of gluing data consists of 1. An index type `J` 2. A locally ringed space `U i` for each `i : J`. 3. A locally ringed space `V i j` for each `i j : J`. (Note that this is `J × J → LocallyRingedSpace` rather than `J → J → LocallyRingedSpace` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the spaces `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subspaces of the glued space. -/ structure GlueData extends CategoryTheory.GlueData LocallyRingedSpace where f_open : ∀ i j, LocallyRingedSpace.IsOpenImmersion (f i j) attribute [instance] GlueData.f_open namespace GlueData variable (D : GlueData.{u}) local notation "𝖣" => D.toGlueData /-- The glue data of ringed spaces associated to a family of glue data of locally ringed spaces. -/ abbrev toSheafedSpaceGlueData : SheafedSpace.GlueData CommRingCat := { f_open := D.f_open toGlueData := 𝖣.mapGlueData forgetToSheafedSpace } /-- The gluing as locally ringed spaces is isomorphic to the gluing as ringed spaces. -/ abbrev isoSheafedSpace : 𝖣.glued.toSheafedSpace ≅ D.toSheafedSpaceGlueData.toGlueData.glued := 𝖣.gluedIso forgetToSheafedSpace theorem ι_isoSheafedSpace_inv (i : D.J) : D.toSheafedSpaceGlueData.toGlueData.ι i ≫ D.isoSheafedSpace.inv = (𝖣.ι i).1 := 𝖣.ι_gluedIso_inv forgetToSheafedSpace i instance ι_isOpenImmersion (i : D.J) : IsOpenImmersion (𝖣.ι i) := by delta IsOpenImmersion; rw [← D.ι_isoSheafedSpace_inv] apply (config := { allowSynthFailures := true }) PresheafedSpace.IsOpenImmersion.comp -- Porting note: this was automatic exact (D.toSheafedSpaceGlueData).ιIsOpenImmersion i instance (i j k : D.J) : PreservesLimit (cospan (𝖣.f i j) (𝖣.f i k)) forgetToSheafedSpace := inferInstance theorem ι_jointly_surjective (x : 𝖣.glued) : ∃ (i : D.J) (y : D.U i), (𝖣.ι i).base y = x := 𝖣.ι_jointly_surjective ((LocallyRingedSpace.forgetToSheafedSpace.{u} ⋙ SheafedSpace.forget CommRingCat.{u}) ⋙ forget TopCat.{u}) x /-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`. ``` Vᵢⱼ ⟶ Uᵢ | | ↓ ↓ Uⱼ ⟶ X ``` -/ def vPullbackConeIsLimit (i j : D.J) : IsLimit (𝖣.vPullbackCone i j) := 𝖣.vPullbackConeIsLimitOfMap forgetToSheafedSpace i j (D.toSheafedSpaceGlueData.vPullbackConeIsLimit _ _) end GlueData end LocallyRingedSpace end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/LocallyRingedSpace/HasColimits.lean
import Mathlib.Geometry.RingedSpace.LocallyRingedSpace import Mathlib.Algebra.Category.Ring.Constructions import Mathlib.Geometry.RingedSpace.OpenImmersion import Mathlib.CategoryTheory.Limits.Types.Coequalizers import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers /-! # Colimits of LocallyRingedSpace We construct the explicit coproducts and coequalizers of `LocallyRingedSpace`. It then follows that `LocallyRingedSpace` has all colimits, and `forgetToSheafedSpace` preserves them. -/ namespace AlgebraicGeometry universe w' w v u open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace attribute [local instance] Opposite.small namespace SheafedSpace variable {C : Type u} [Category.{v} C] variable {J : Type w} [Category.{w'} J] [Small.{v} J] (F : J ⥤ SheafedSpace.{_, _, v} C) theorem isColimit_exists_rep [HasLimitsOfShape Jᵒᵖ C] {c : Cocone F} (hc : IsColimit c) (x : c.pt) : ∃ (i : J) (y : F.obj i), (c.ι.app i).base y = x := Concrete.isColimit_exists_rep (F ⋙ forget C) (isColimitOfPreserves (forget C) hc) x -- Porting note: argument `C` of colimit need to be made explicit, otherwise we get universe issues theorem colimit_exists_rep [HasLimitsOfShape Jᵒᵖ C] (x : colimit (C := SheafedSpace C) F) : ∃ (i : J) (y : F.obj i), (colimit.ι F i).base y = x := Concrete.isColimit_exists_rep (F ⋙ SheafedSpace.forget C) (isColimitOfPreserves (SheafedSpace.forget _) (colimit.isColimit F)) x instance [HasLimits C] {X Y : SheafedSpace C} (f g : X ⟶ Y) : Epi (coequalizer.π f g).base := by rw [← show _ = (coequalizer.π f g).base from ι_comp_coequalizerComparison f g (SheafedSpace.forget C), ← PreservesCoequalizer.iso_hom] apply epi_comp end SheafedSpace namespace LocallyRingedSpace section HasCoproducts variable {ι : Type v} [Small.{u} ι] (F : Discrete ι ⥤ LocallyRingedSpace.{u}) /-- The explicit coproduct for `F : discrete ι ⥤ LocallyRingedSpace`. -/ noncomputable def coproduct : LocallyRingedSpace where toSheafedSpace := colimit (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) (F ⋙ forgetToSheafedSpace) isLocalRing x := by obtain ⟨i, y, ⟨⟩⟩ := SheafedSpace.colimit_exists_rep (F ⋙ forgetToSheafedSpace) x haveI : IsLocalRing (((F ⋙ forgetToSheafedSpace).obj i).presheaf.stalk y) := (F.obj i).isLocalRing _ exact (asIso ((colimit.ι (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) (F ⋙ forgetToSheafedSpace) i :).stalkMap y)).symm.commRingCatIsoToRingEquiv.isLocalRing /-- The explicit coproduct cofan for `F : discrete ι ⥤ LocallyRingedSpace`. -/ noncomputable def coproductCofan : Cocone F where pt := coproduct F ι := { app := fun j => ⟨colimit.ι (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) (F ⋙ forgetToSheafedSpace) j, inferInstance⟩ naturality := fun ⟨j⟩ ⟨j'⟩ ⟨⟨(f : j = j')⟩⟩ => by subst f; simp } /-- The explicit coproduct cofan constructed in `coproductCofan` is indeed a colimit. -/ noncomputable def coproductCofanIsColimit : IsColimit (coproductCofan F) where desc s := ⟨colimit.desc (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) (F ⋙ forgetToSheafedSpace) (forgetToSheafedSpace.mapCocone s), by intro x obtain ⟨i, y, ⟨⟩⟩ := SheafedSpace.colimit_exists_rep (F ⋙ forgetToSheafedSpace) x have := PresheafedSpace.stalkMap.comp (colimit.ι (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) (F ⋙ forgetToSheafedSpace) i) (colimit.desc (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) (F ⋙ forgetToSheafedSpace) (forgetToSheafedSpace.mapCocone s)) y rw [← IsIso.comp_inv_eq] at this erw [← this, PresheafedSpace.stalkMap.congr_hom _ _ (colimit.ι_desc (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) (forgetToSheafedSpace.mapCocone s) i :)] haveI : IsLocalHom (((forgetToSheafedSpace.mapCocone s).ι.app i).stalkMap y).hom := (s.ι.app i).2 y infer_instance⟩ fac _ _ := LocallyRingedSpace.Hom.ext' (colimit.ι_desc (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) _ _) uniq s f h := LocallyRingedSpace.Hom.ext' (IsColimit.uniq _ (forgetToSheafedSpace.mapCocone s) f.toShHom fun j => congr_arg LocallyRingedSpace.Hom.toShHom (h j)) instance : HasColimitsOfShape (Discrete ι) LocallyRingedSpace.{u} := ⟨fun F => ⟨⟨⟨_, coproductCofanIsColimit F⟩⟩⟩⟩ noncomputable instance : PreservesColimitsOfShape (Discrete.{v} ι) forgetToSheafedSpace.{u} := ⟨fun {G} => preservesColimit_of_preserves_colimit_cocone (coproductCofanIsColimit G) ((colimit.isColimit (C := SheafedSpace.{u+1, u, u} CommRingCat.{u}) _).ofIsoColimit (Cocones.ext (Iso.refl _) fun _ => Category.comp_id _))⟩ end HasCoproducts section HasCoequalizer variable {X Y : LocallyRingedSpace.{v}} (f g : X ⟶ Y) namespace HasCoequalizer @[instance] theorem coequalizer_π_app_isLocalHom (U : TopologicalSpace.Opens (coequalizer f.toShHom g.toShHom).carrier) : IsLocalHom ((coequalizer.π f.toShHom g.toShHom :).c.app (op U)).hom := by have := ι_comp_coequalizerComparison f.toShHom g.toShHom SheafedSpace.forgetToPresheafedSpace rw [← PreservesCoequalizer.iso_hom] at this erw [SheafedSpace.congr_app this.symm (op U)] rw [PresheafedSpace.comp_c_app, ← PresheafedSpace.colimitPresheafObjIsoComponentwiseLimit_hom_π] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10754): this instance has to be manually added haveI : IsIso (PreservesCoequalizer.iso SheafedSpace.forgetToPresheafedSpace f.toShHom g.toShHom).hom.c := inferInstance -- Had to add this instance too. have := CommRingCat.equalizer_ι_isLocalHom' (PresheafedSpace.componentwiseDiagram _ ((Opens.map (PreservesCoequalizer.iso SheafedSpace.forgetToPresheafedSpace (Hom.toShHom f) (Hom.toShHom g)).hom.base).obj (unop (op U)))) infer_instance /-! We roughly follow the construction given in [MR0302656]. Given a pair `f, g : X ⟶ Y` of morphisms of locally ringed spaces, we want to show that the stalk map of `π = coequalizer.π f g` (as sheafed space homs) is a local ring hom. It then follows that `coequalizer f g` is indeed a locally ringed space, and `coequalizer.π f g` is a morphism of locally ringed space. Given a germ `⟨U, s⟩` of `x : coequalizer f g` such that `π꙳ x : Y` is invertible, we ought to show that `⟨U, s⟩` is invertible. That is, there exists an open set `U' ⊆ U` containing `x` such that the restriction of `s` onto `U'` is invertible. This `U'` is given by `π '' V`, where `V` is the basic open set of `π⋆x`. Since `f ⁻¹' V = Y.basic_open (f ≫ π)꙳ x = Y.basic_open (g ≫ π)꙳ x = g ⁻¹' V`, we have `π ⁻¹' (π '' V) = V` (as the underlying set map is merely the set-theoretic coequalizer). This shows that `π '' V` is indeed open, and `s` is invertible on `π '' V` as the components of `π꙳` are local ring homs. -/ variable (U : Opens (coequalizer f.toShHom g.toShHom).carrier) variable (s : (coequalizer f.toShHom g.toShHom).presheaf.obj (op U)) /-- (Implementation). The basic open set of the section `π꙳ s`. -/ noncomputable def imageBasicOpen : Opens Y := Y.toRingedSpace.basicOpen (show Y.presheaf.obj (op (unop _)) from ((coequalizer.π f.toShHom g.toShHom).c.app (op U)) s) theorem imageBasicOpen_image_preimage : (coequalizer.π f.toShHom g.toShHom).base ⁻¹' ((coequalizer.π f.toShHom g.toShHom).base '' (imageBasicOpen f g U s).1) = (imageBasicOpen f g U s).1 := by fapply Types.coequalizer_preimage_image_eq_of_preimage_eq f.base -- Porting note: Type of `g.base` needs to be explicit (g.base : X.carrier.1 ⟶ Y.carrier.1) · ext simp_rw [types_comp_apply, ← TopCat.comp_app, ← PresheafedSpace.comp_base] congr 3 exact coequalizer.condition f.toShHom g.toShHom · apply isColimitCoforkMapOfIsColimit (forget TopCat) apply isColimitCoforkMapOfIsColimit (SheafedSpace.forget _) exact coequalizerIsCoequalizer f.toShHom g.toShHom · suffices (TopologicalSpace.Opens.map f.base).obj (imageBasicOpen f g U s) = (TopologicalSpace.Opens.map g.base).obj (imageBasicOpen f g U s) by injection this delta imageBasicOpen rw [preimage_basicOpen f, preimage_basicOpen g] dsimp only [Functor.op, unop_op] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): change `rw` to `erw` erw [← CommRingCat.comp_apply, ← SheafedSpace.comp_c_app', ← CommRingCat.comp_apply, ← SheafedSpace.comp_c_app', SheafedSpace.congr_app (coequalizer.condition f.toShHom g.toShHom), CommRingCat.comp_apply, X.toRingedSpace.basicOpen_res] apply inf_eq_right.mpr refine (RingedSpace.basicOpen_le _ _).trans ?_ rw [coequalizer.condition f.toShHom g.toShHom] theorem imageBasicOpen_image_open : IsOpen ((coequalizer.π f.toShHom g.toShHom).base '' (imageBasicOpen f g U s).1) := by rw [← (TopCat.homeoOfIso (PreservesCoequalizer.iso (SheafedSpace.forget _) f.toShHom g.toShHom)).isOpen_preimage, TopCat.coequalizer_isOpen_iff, ← Set.preimage_comp] erw [← TopCat.coe_comp] rw [PreservesCoequalizer.iso_hom, ι_comp_coequalizerComparison] dsimp only [SheafedSpace.forget] rw [imageBasicOpen_image_preimage] exact (imageBasicOpen f g U s).2 @[instance] theorem coequalizer_π_stalk_isLocalHom (x : Y) : IsLocalHom ((coequalizer.π f.toShHom g.toShHom :).stalkMap x).hom := by constructor rintro a ha rcases TopCat.Presheaf.germ_exist _ _ a with ⟨U, hU, s, rfl⟩ rw [-- Manually apply `elementwise_of%` to generate a `ConcreteCategory` lemma elementwise_of% PresheafedSpace.stalkMap_germ (coequalizer.π (C := SheafedSpace _) f.toShHom g.toShHom) U _ hU] at ha let V := imageBasicOpen f g U s have hV : (coequalizer.π f.toShHom g.toShHom).base ⁻¹' ((coequalizer.π f.toShHom g.toShHom).base '' V.1) = V.1 := imageBasicOpen_image_preimage f g U s have hV' : V = ⟨(coequalizer.π f.toShHom g.toShHom).base ⁻¹' ((coequalizer.π f.toShHom g.toShHom).base '' V.1), hV.symm ▸ V.2⟩ := SetLike.ext' hV.symm have V_open : IsOpen ((coequalizer.π f.toShHom g.toShHom).base '' V.1) := imageBasicOpen_image_open f g U s have VleU : ⟨(coequalizer.π f.toShHom g.toShHom).base '' V.1, V_open⟩ ≤ U := Set.image_subset_iff.mpr (Y.toRingedSpace.basicOpen_le _) have hxV : x ∈ V := ⟨hU, ha⟩ rw [← (coequalizer f.toShHom g.toShHom).presheaf.germ_res_apply (homOfLE VleU) _ (@Set.mem_image_of_mem _ _ (coequalizer.π f.toShHom g.toShHom).base x V.1 hxV) s] apply RingHom.isUnit_map rw [← isUnit_map_iff ((coequalizer.π f.toShHom g.toShHom :).c.app _).hom, ← CommRingCat.comp_apply, NatTrans.naturality, CommRingCat.comp_apply, ← isUnit_map_iff (Y.presheaf.map (eqToHom hV').op).hom] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): change `rw` to `erw` erw [← CommRingCat.comp_apply, ← CommRingCat.comp_apply, ← Y.presheaf.map_comp] convert @RingedSpace.isUnit_res_basicOpen Y.toRingedSpace (unop _) (((coequalizer.π f.toShHom g.toShHom).c.app (op U)) s) end HasCoequalizer /-- The coequalizer of two locally ringed spaces in the category of sheafed spaces is a locally ringed space. -/ noncomputable def coequalizer : LocallyRingedSpace where toSheafedSpace := Limits.coequalizer f.toShHom g.toShHom isLocalRing x := by obtain ⟨y, rfl⟩ := (TopCat.epi_iff_surjective (coequalizer.π f.toShHom g.toShHom).base).mp inferInstance x exact ((coequalizer.π f.toShHom g.toShHom :).stalkMap y).hom.domain_isLocalRing /-- The explicit coequalizer cofork of locally ringed spaces. -/ noncomputable def coequalizerCofork : Cofork f g := @Cofork.ofπ _ _ _ _ f g (coequalizer f g) ⟨coequalizer.π f.toShHom g.toShHom, -- Porting note: this used to be automatic HasCoequalizer.coequalizer_π_stalk_isLocalHom _ _⟩ (LocallyRingedSpace.Hom.ext' (coequalizer.condition f.toShHom g.toShHom)) theorem isLocalHom_stalkMap_congr {X Y : RingedSpace} (f g : X ⟶ Y) (H : f = g) (x) (h : IsLocalHom (f.stalkMap x).hom) : IsLocalHom (g.stalkMap x).hom := by rw [PresheafedSpace.stalkMap.congr_hom _ _ H.symm x]; infer_instance /-- The cofork constructed in `coequalizerCofork` is indeed a colimit cocone. -/ noncomputable def coequalizerCoforkIsColimit : IsColimit (coequalizerCofork f g) := by apply Cofork.IsColimit.mk' intro s have e : f.toShHom ≫ s.π.toShHom = g.toShHom ≫ s.π.toShHom := by injection s.condition refine ⟨⟨coequalizer.desc s.π.toShHom e, ?_⟩, ?_⟩ · intro x rcases (TopCat.epi_iff_surjective (coequalizer.π f.toShHom g.toShHom).base).mp inferInstance x with ⟨y, rfl⟩ -- Porting note: was `apply isLocalHom_of_comp _ (PresheafedSpace.stalkMap ...)`, this -- used to allow you to provide the proof that `... ≫ ...` is a local ring homomorphism later, -- but this is no longer possible set h := _ change IsLocalHom h suffices _ : IsLocalHom (((coequalizerCofork f g).π.1.stalkMap _).hom.comp h) by apply isLocalHom_of_comp _ ((coequalizerCofork f g).π.1.stalkMap _).hom rw [← CommRingCat.hom_ofHom h, ← CommRingCat.hom_comp] erw [← PresheafedSpace.stalkMap.comp] apply isLocalHom_stalkMap_congr _ _ (coequalizer.π_desc s.π.toShHom e).symm y infer_instance constructor · exact LocallyRingedSpace.Hom.ext' (coequalizer.π_desc _ _) intro m h replace h : (coequalizerCofork f g).π.toShHom ≫ m.1 = s.π.toShHom := by rw [← h]; rfl apply LocallyRingedSpace.Hom.ext' apply (colimit.isColimit (parallelPair f.toShHom g.toShHom)).uniq (Cofork.ofπ s.π.toShHom e) m.1 rintro ⟨⟩ · rw [← (colimit.cocone (parallelPair f.toShHom g.toShHom)).w WalkingParallelPairHom.left, Category.assoc] change _ ≫ _ ≫ _ = _ ≫ _ congr · exact h instance : HasCoequalizer f g := ⟨⟨⟨_, coequalizerCoforkIsColimit f g⟩⟩⟩ instance : HasCoequalizers LocallyRingedSpace := hasCoequalizers_of_hasColimit_parallelPair _ noncomputable instance preservesCoequalizer : PreservesColimitsOfShape WalkingParallelPair forgetToSheafedSpace.{v} := ⟨fun {F} => by -- Porting note: was `apply preservesColimitOfIsoDiagram ...` and the proof that preservation -- of colimit is provided later suffices PreservesColimit (parallelPair (F.map WalkingParallelPairHom.left) (F.map WalkingParallelPairHom.right)) forgetToSheafedSpace from preservesColimit_of_iso_diagram _ (diagramIsoParallelPair F).symm apply preservesColimit_of_preserves_colimit_cocone (coequalizerCoforkIsColimit _ _) apply (isColimitMapCoconeCoforkEquiv _ _).symm _ dsimp only [forgetToSheafedSpace] exact coequalizerIsCoequalizer _ _⟩ end HasCoequalizer instance : HasColimits LocallyRingedSpace := has_colimits_of_hasCoequalizers_and_coproducts noncomputable instance preservesColimits_forgetToSheafedSpace : PreservesColimits LocallyRingedSpace.forgetToSheafedSpace.{u} := preservesColimits_of_preservesCoequalizers_and_coproducts _ end LocallyRingedSpace end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/Geometry/RingedSpace/LocallyRingedSpace/ResidueField.lean
import Mathlib.Geometry.RingedSpace.LocallyRingedSpace import Mathlib.RingTheory.LocalRing.ResidueField.Basic /-! # Residue fields of points Any point `x` of a locally ringed space `X` comes with a natural residue field, namely the residue field of the stalk at `x`. Moreover, for every open subset of `X` containing `x`, we have a canonical evaluation map from `Γ(X, U)` to the residue field of `X` at `x`. ## Main definitions The following are in the `AlgebraicGeometry.LocallyRingedSpace` namespace: - `residueField`: the residue field of the stalk at `x`. - `evaluation`: for open subsets `U` of `X` containing `x`, the evaluation map from sections over `U` to the residue field at `x`. - `evaluationMap`: a morphism of locally ringed spaces induces a morphism, i.e. extension, of residue fields. -/ universe u open CategoryTheory TopologicalSpace Opposite noncomputable section namespace AlgebraicGeometry.LocallyRingedSpace variable (X : LocallyRingedSpace.{u}) {U : Opens X} /-- The residue field of `X` at a point `x` is the residue field of the stalk of `X` at `x`. -/ def residueField (x : X) : CommRingCat := CommRingCat.of <| IsLocalRing.ResidueField (X.presheaf.stalk x) instance (x : X) : Field (X.residueField x) := inferInstanceAs <| Field (IsLocalRing.ResidueField (X.presheaf.stalk x)) /-- If `U` is an open of `X` containing `x`, we have a canonical ring map from the sections over `U` to the residue field of `x`. If we interpret sections over `U` as functions of `X` defined on `U`, then this ring map corresponds to evaluation at `x`. -/ def evaluation (x : U) : X.presheaf.obj (op U) ⟶ X.residueField x := -- TODO: make a new definition wrapping -- `CommRingCat.ofHom (IsLocalRing.residue (X.presheaf.stalk _))`? X.presheaf.germ U x.1 x.2 ≫ CommRingCat.ofHom (IsLocalRing.residue (X.presheaf.stalk _)) /-- The global evaluation map from `Γ(X, ⊤)` to the residue field at `x`. -/ def Γevaluation (x : X) : X.presheaf.obj (op ⊤) ⟶ X.residueField x := X.evaluation ⟨x, show x ∈ ⊤ from trivial⟩ @[simp] lemma evaluation_eq_zero_iff_notMem_basicOpen (x : U) (f : X.presheaf.obj (op U)) : X.evaluation x f = 0 ↔ x.val ∉ X.toRingedSpace.basicOpen f := by rw [X.toRingedSpace.mem_basicOpen f x.1 x.2, ← not_iff_not, not_not] exact (IsLocalRing.residue_ne_zero_iff_isUnit _) @[deprecated (since := "2025-05-23")] alias evaluation_eq_zero_iff_not_mem_basicOpen := evaluation_eq_zero_iff_notMem_basicOpen lemma evaluation_ne_zero_iff_mem_basicOpen (x : U) (f : X.presheaf.obj (op U)) : X.evaluation x f ≠ 0 ↔ x.val ∈ X.toRingedSpace.basicOpen f := by simp lemma basicOpen_eq_bot_iff_forall_evaluation_eq_zero (f : X.presheaf.obj (op U)) : X.toRingedSpace.basicOpen f = ⊥ ↔ ∀ (x : U), X.evaluation x f = 0 := by simp only [evaluation_eq_zero_iff_notMem_basicOpen, Subtype.forall] exact ⟨fun h ↦ h ▸ fun a _ hc ↦ hc, fun h ↦ eq_bot_iff.mpr <| fun a ha ↦ h a (X.toRingedSpace.basicOpen_le f ha) ha⟩ @[simp] lemma Γevaluation_eq_zero_iff_notMem_basicOpen (x : X) (f : X.presheaf.obj (op ⊤)) : X.Γevaluation x f = 0 ↔ x ∉ X.toRingedSpace.basicOpen f := evaluation_eq_zero_iff_notMem_basicOpen X ⟨x, show x ∈ ⊤ by trivial⟩ f @[deprecated (since := "2025-05-23")] alias Γevaluation_eq_zero_iff_not_mem_basicOpen := Γevaluation_eq_zero_iff_notMem_basicOpen lemma Γevaluation_ne_zero_iff_mem_basicOpen (x : X) (f : X.presheaf.obj (op ⊤)) : X.Γevaluation x f ≠ 0 ↔ x ∈ X.toRingedSpace.basicOpen f := evaluation_ne_zero_iff_mem_basicOpen X ⟨x, show x ∈ ⊤ by trivial⟩ f variable {X Y : LocallyRingedSpace.{u}} (f : X ⟶ Y) (x : X) /-- If `X ⟶ Y` is a morphism of locally ringed spaces and `x` a point of `X`, we obtain a morphism of residue fields in the other direction. -/ def residueFieldMap (x : X) : Y.residueField (f.base x) ⟶ X.residueField x := CommRingCat.ofHom (IsLocalRing.ResidueField.map (f.stalkMap x).hom) lemma residue_comp_residueFieldMap_eq_stalkMap_comp_residue (x : X) : CommRingCat.ofHom (IsLocalRing.residue (Y.presheaf.stalk (f.base x))) ≫ residueFieldMap f x = f.stalkMap x ≫ CommRingCat.ofHom (IsLocalRing.residue (X.presheaf.stalk x)) := by simp [residueFieldMap] rfl @[simp] lemma residueFieldMap_id (x : X) : residueFieldMap (𝟙 X) x = 𝟙 (X.residueField x) := by ext : 1 simp only [id_toShHom', SheafedSpace.id_base, TopCat.coe_id, id_eq, residueFieldMap, stalkMap_id] apply IsLocalRing.ResidueField.map_id @[simp] lemma residueFieldMap_comp {Z : LocallyRingedSpace.{u}} (g : Y ⟶ Z) (x : X) : residueFieldMap (f ≫ g) x = residueFieldMap g (f.base x) ≫ residueFieldMap f x := by ext : 1 simp only [comp_toShHom, SheafedSpace.comp_base, residueFieldMap, CommRingCat.hom_comp, TopCat.comp_app] simp_rw [stalkMap_comp] apply IsLocalRing.ResidueField.map_comp (Hom.stalkMap g (f.base x)).hom (Hom.stalkMap f x).hom @[reassoc] lemma evaluation_naturality {V : Opens Y} (x : (Opens.map f.base).obj V) : Y.evaluation ⟨f.base x, x.property⟩ ≫ residueFieldMap f x.val = f.c.app (op V) ≫ X.evaluation x := by dsimp only [LocallyRingedSpace.evaluation, LocallyRingedSpace.residueFieldMap] rw [Category.assoc] ext a simp only [CommRingCat.comp_apply] erw [IsLocalRing.ResidueField.map_residue] rw [LocallyRingedSpace.stalkMap_germ_apply] rfl lemma evaluation_naturality_apply {V : Opens Y} (x : (Opens.map f.base).obj V) (a : Y.presheaf.obj (op V)) : residueFieldMap f x.val (Y.evaluation ⟨f.base x, x.property⟩ a) = X.evaluation x (f.c.app (op V) a) := by simpa using congrFun (congrArg (DFunLike.coe ∘ CommRingCat.Hom.hom) <| evaluation_naturality f x) a @[reassoc] lemma Γevaluation_naturality (x : X) : Y.Γevaluation (f.base x) ≫ residueFieldMap f x = f.c.app (op ⊤) ≫ X.Γevaluation x := evaluation_naturality f ⟨x, by simp only [Opens.map_top]; trivial⟩ lemma Γevaluation_naturality_apply (x : X) (a : Y.presheaf.obj (op ⊤)) : residueFieldMap f x (Y.Γevaluation (f.base x) a) = X.Γevaluation x (f.c.app (op ⊤) a) := evaluation_naturality_apply f ⟨x, by simp only [Opens.map_top]; trivial⟩ a end LocallyRingedSpace end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/Geometry/Group/README.md
# Geometric group theory This subfolder is destined to contain the formalisation of geometric group theory. Geometric group theory is the study of finitely generated groups through their actions on geometric spaces. ## Topics The geometric group theory topics currently covered are: * Growth of groups
.lake/packages/mathlib/Mathlib/Geometry/Group/Growth/LinearLowerBound.lean
import Mathlib.Algebra.Group.Action.Pointwise.Finset import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.Data.Nat.SuccPred /-! # Linear lower bound on the growth of a generating set This file proves that the growth of a set generating an infinite group is at least linear. -/ open Subgroup open scoped Pointwise namespace Finset variable {G : Type*} [Group G] [DecidableEq G] {X : Finset G} {n : ℕ} @[to_additive] lemma pow_ssubset_pow_succ_of_pow_ne_closure (hX₁ : (1 : G) ∈ X) (hX : X.Nontrivial) (hXclosure : (X ^ n : Set G) ≠ closure (X : Set G)) : X ^ n ⊂ X ^ (n + 1) := by obtain rfl | hn := eq_or_ne n 0 · simpa [ssubset_iff_subset_not_subset, hX₁, -Finset.subset_singleton_iff] using hX.not_subset_singleton refine (pow_subset_pow_right hX₁ <| n.le_add_right _).ssubset_of_ne ?_ contrapose! hXclosure with hXn rw [← closure_pow (mod_cast hX₁) hn] wlog hn₁ : n = 1 · simp +contextual only [pow_one] at this replace hXn d : X ^ (n + d) = X ^ n := by induction d with | zero => rw [add_zero] | succ d hd => rw [pow_add, pow_one] at hXn rw [← add_assoc, pow_add, pow_one, hd, ← hXn] exact mod_cast this (one_mem_pow hX₁) (hX.pow hn) one_ne_zero (by simp [hXn, ← pow_mul, mul_two]) (by simp) subst hn₁ simp only [ne_eq, one_ne_zero, not_false_eq_true, Nat.reduceAdd, pow_one] at * let Xgp : Subgroup G := { carrier := X mul_mem' := fun {x y} hx hy ↦ by norm_cast at * simpa [← hXn, ← sq] using mul_mem_mul hx hy one_mem' := hX₁ inv_mem' := fun {x} hx ↦ by norm_cast at * have : x • X ⊆ X := by simpa [← hXn, add_assoc, ← sq] using smul_finset_subset_mul (t := X) hx have : x • X = X := eq_of_subset_of_card_le this (card_smul_finset ..).ge rw [← eq_inv_smul_iff] at this rw [this] simpa [mem_inv_smul_finset_iff] } exact subset_closure.antisymm <| (closure_le Xgp).2 subset_rfl @[to_additive] lemma pow_right_strictMonoOn (hX₁ : 1 ∈ X) (hX : X.Nontrivial) : StrictMonoOn (fun n ↦ X ^ n) {n | (X ^ (n - 1) : Set G) ≠ closure (X : Set G)} := by refine strictMonoOn_of_lt_add_one ⟨?_⟩ fun n _ _ hn ↦ pow_ssubset_pow_succ_of_pow_ne_closure hX₁ hX hn rintro - - n hn m ⟨-, hmn⟩ hm apply hn obtain rfl | hm₀ := m.eq_zero_or_pos · simp [eq_comm (a := (1 : Set _)), coe_set_eq_one, -Set.subset_singleton_iff, hX.coe.not_subset_singleton] at hm · calc (X : Set G) ^ (n - 1) _ = X ^ (n - m) * X ^ (m - 1) := by rw [← pow_add]; congr 1; cutsat _ = closure (X : Set G) := by rw [hm, Set.pow_mul_subgroupClosure hX.nonempty.to_set] @[to_additive] lemma pow_right_strictMono (hX₁ : 1 ∈ X) (hXclosure : (closure (X : Set G) : Set G).Infinite) : StrictMono fun n ↦ X ^ n := by obtain rfl | hX := eq_singleton_or_nontrivial hX₁ · simp [closure_singleton_one] at hXclosure have h n : (X ^ (n - 1) : Set G) ≠ closure (X : Set G) := fun h ↦ by simp [← h, ← coe_pow] at hXclosure simpa [h] using pow_right_strictMonoOn hX₁ hX /-- The growth of a set generating an infinite group is at least linear. -/ @[to_additive /-- The growth of a set generating an infinite group is at least linear. -/] lemma add_one_le_card_pow (hX₁ : 1 ∈ X) (hXclosure : (closure (X : Set G) : Set G).Infinite) : ∀ n, n + 1 ≤ #(X ^ n) | 0 => by simp | n + 1 => (add_one_le_card_pow hX₁ hXclosure _).trans_lt <| card_lt_card <| pow_right_strictMono hX₁ (by simp [hXclosure]) n.lt_succ_self end Finset
.lake/packages/mathlib/Mathlib/Geometry/Group/Growth/README.md
# Growth of groups This subfolder is destined to contain results about the growth of groups. If $G$ is a finitely generated group, say $G = \langle S\rangle$ for some finite symmetric set $S$, then the growth of $G$ is defined to be the function $n \mapsto |S^n|$ where $S^n$ denotes pointwise multiplication of $n$ copies of $S$. Up to scaling, the growth does not depend on the symmetric generating set $S$. ## Topics The results on growth of groups currently covered are: * The growth of a group is at least linear * The growth of a group $G$ is roughly the growth of a normal subgroup $H \le G$ times the growth of $G / H$.
.lake/packages/mathlib/Mathlib/Geometry/Group/Growth/QuotientInter.lean
import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.GroupTheory.QuotientGroup.Defs import Mathlib.Algebra.Group.Pointwise.Finset.Basic /-! # Growth in the quotient and intersection with a subgroup For a group `G` and a subgroup `H ≤ G`, this file gives upper and lower bounds on the growth of a finset by its growth in `H` and `G ⧸ H`. -/ open Finset Function open scoped Pointwise namespace Finset variable {G : Type*} [Group G] [DecidableEq G] {H : Subgroup G} [DecidablePred (· ∈ H)] [H.Normal] {A : Finset G} {m n : ℕ} @[to_additive] lemma card_pow_quotient_mul_pow_inter_subgroup_le : #((A ^ m).image <| QuotientGroup.mk' H) * #{x ∈ A ^ n | x ∈ H} ≤ #(A ^ (m + n)) := by set π := QuotientGroup.mk' H let φ := invFunOn π (A ^ m) have hφ : Set.InjOn φ (π '' (A ^ m)) := invFunOn_injOn_image .. have hφA {a} (ha : a ∈ π '' (A ^ m)) : φ a ∈ A ^ m := by have := invFunOn_mem (by simpa using ha) norm_cast at this simpa using this have hπφ {a} (ha : a ∈ π '' (A ^ m)) : π (φ a) = a := invFunOn_eq (by simpa using ha) calc #((A ^ m).image π) * #{x ∈ A ^ n | x ∈ H} _ = #(((A ^ m).image π).image φ) * #{x ∈ A ^ n | x ∈ H} := by rw [Finset.card_image_of_injOn (f := φ) (mod_cast hφ)] _ ≤ #(((A ^ m).image π).image φ * {x ∈ A ^ n | x ∈ H}) := by rw [Finset.card_mul_iff.2] simp only [Set.InjOn, coe_image, coe_pow, coe_filter, Set.mem_prod, Set.mem_image, exists_exists_and_eq_and, Set.mem_setOf_eq, and_imp, forall_exists_index, Prod.forall, Prod.mk.injEq] rintro _ a₁ b₁ hb₁ rfl - ha₁ _ a₂ b₂ hb₂ rfl - ha₂ hab have hπa₁ : π a₁ = 1 := (QuotientGroup.eq_one_iff _).2 ha₁ have hπa₂ : π a₂ = 1 := (QuotientGroup.eq_one_iff _).2 ha₂ have hπb : π b₁ = π b₂ := by simpa [hπφ, Set.mem_image_of_mem π, hb₁, hb₂, hπa₁, hπa₂] using congr(π $hab) simp_all _ ≤ #(A ^ (m + n)) := by gcongr simp only [mul_subset_iff, mem_image, exists_exists_and_eq_and, Finset.mem_filter, and_imp, forall_exists_index, forall_apply_eq_imp_iff₂, pow_add] rintro a ha b hb - exact mul_mem_mul (hφA <| Set.mem_image_of_mem _ <| mod_cast ha) hb @[to_additive] lemma le_card_quotient_mul_sq_inter_subgroup (hAsymm : A⁻¹ = A) : #A ≤ #(A.image <| QuotientGroup.mk' H) * #{x ∈ A ^ 2 | x ∈ H} := by classical set π := QuotientGroup.mk' H rw [card_eq_sum_card_image π] refine sum_le_card_nsmul _ _ _ <| forall_mem_image.2 fun a ha ↦ ?_ calc #{a' ∈ A | π a' = π a} _ ≤ #({a' ∈ A | π a' = π a}⁻¹ * {a' ∈ A | π a' = π a}) := card_le_card_mul_left ⟨a⁻¹, by simpa⟩ _ ≤ #{x ∈ A⁻¹ * A | x ∈ H} := by gcongr simp only [mul_subset_iff, mem_inv', map_inv, mem_filter, and_imp] rintro x hx hxa y hy hya refine ⟨mul_mem_mul (by simpa) hy, (QuotientGroup.eq_one_iff _).1 (?_ : π _ = _)⟩ simp [hya, ← hxa] _ = #{x ∈ A ^ 2 | x ∈ H} := by simp [hAsymm, sq] end Finset
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/SignedDist.lean
import Mathlib.Geometry.Euclidean.Projection import Mathlib.Analysis.NormedSpace.Normalize /-! # Signed distance to an affine subspace in a Euclidean space. This file defines the signed distance between two points, in the direction of a given a vector, and the signed distance between an affine subspace and a point, in the direction of a given reference point. ## Main definitions * `signedDist` is the signed distance between two points * `AffineSubspace.signedInfDist` is the signed distance between an affine subspace and a point. * `Affine.Simplex.signedInfDist` is the signed distance between a face of a simplex and a point. In the case of a triangle, these distances are trilinear coordinates. ## References * https://en.wikipedia.org/wiki/Trilinear_coordinates -/ open EuclideanGeometry NormedSpace open scoped RealInnerProductSpace variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] section signedDist /-- Auxiliary definition for `signedDist`. It is the underlying linear map of `signedDist`. -/ private noncomputable def signedDistLinear (v : V) : V →ₗ[ℝ] P →ᴬ[ℝ] ℝ where toFun w := .const ℝ P ⟪-normalize v, w⟫ map_add' x y := by ext; simp [inner_add_right] map_smul' r x := by ext; simp [inner_smul_right] private lemma signedDistLinear_apply (v w : V) : signedDistLinear v w = .const ℝ P ⟪-normalize v, w⟫ := rfl /-- The signed distance between two points `p` and `q`, in the direction of a reference vector `v`. It is the size of `q - p` in the direction of `v`. In the degenerate case `v = 0`, it returns `0`. TODO: once we have a topology on `P →ᴬ[ℝ] ℝ`, the type should be `P →ᴬ[ℝ] P →ᴬ[ℝ] ℝ`. -/ noncomputable def signedDist (v : V) : P →ᵃ[ℝ] P →ᴬ[ℝ] ℝ where toFun p := (innerSL ℝ (normalize v)).toContinuousAffineMap.comp (ContinuousAffineMap.id ℝ P -ᵥ .const ℝ P p) linear := signedDistLinear v map_vadd' p v' := by ext q rw [signedDistLinear_apply] simp [vsub_vadd_eq_vsub_sub, inner_sub_right, ← sub_eq_neg_add] variable (v w : V) (p q r : P) -- Lemmas about the definition of `signedDist` lemma signedDist_apply : signedDist v p = (innerSL ℝ (normalize v)).toContinuousAffineMap.comp (ContinuousAffineMap.id ℝ P -ᵥ .const ℝ P p) := rfl lemma signedDist_apply_apply : signedDist v p q = ⟪normalize v, q -ᵥ p⟫ := rfl lemma signedDist_apply_linear : (signedDist v p).linear = innerₗ V (normalize v) := by change (innerₗ V (normalize v)).comp (LinearMap.id - 0) = _ simp lemma signedDist_apply_linear_apply : (signedDist v p).linear w = ⟪normalize v, w⟫ := by simp [signedDist_apply_linear] lemma signedDist_linear_apply : (signedDist v).linear w = .const ℝ P ⟪-normalize v, w⟫ := rfl lemma signedDist_linear_apply_apply : (signedDist v).linear w p = ⟪-normalize v, w⟫ := rfl -- Lemmas about the vector argument of `signedDist` lemma signedDist_smul (r : ℝ) : signedDist (r • v) p q = SignType.sign r * signedDist v p q := by simp only [signedDist_apply_apply] rw [normalize_smul, real_inner_smul_left] lemma signedDist_smul_of_pos {r : ℝ} (h : 0 < r) : signedDist (r • v) p q = signedDist v p q := by simp [signedDist_smul, h] lemma signedDist_smul_of_neg {r : ℝ} (h : r < 0) : signedDist (r • v) p q = -signedDist v p q := by simp [signedDist_smul, h] @[simp] lemma signedDist_zero : signedDist 0 p q = 0 := by simpa using signedDist_smul 0 p q 0 @[simp] lemma signedDist_neg : signedDist (-v) p q = -signedDist v p q := by simpa using signedDist_smul v p q (-1) lemma signedDist_congr (h : ∃ r > (0 : ℝ), r • v = w) : signedDist (P := P) v = signedDist w := by obtain ⟨r, _, _⟩ := h ext p q simpa [*] using (signedDist_smul v p q r).symm -- Lemmas about permuting the point arguments of `signedDist`, analogous to lemmas about `dist` @[simp] lemma signedDist_self : signedDist v p p = 0 := by simp [signedDist_apply_apply] @[simp] lemma signedDist_anticomm : -signedDist v p q = signedDist v q p := by simp [signedDist_apply_apply, ← inner_neg_right] @[simp] lemma signedDist_triangle : signedDist v p q + signedDist v q r = signedDist v p r := by simp only [signedDist_apply_apply] rw [add_comm, ← inner_add_right, vsub_add_vsub_cancel] @[simp] lemma signedDist_triangle_left : signedDist v p q - signedDist v p r = signedDist v r q := by rw [sub_eq_iff_eq_add', signedDist_triangle] @[simp] lemma signedDist_triangle_right : signedDist v p r - signedDist v q r = signedDist v p q := by rw [sub_eq_iff_eq_add, signedDist_triangle] -- Lemmas about offsetting the point arguments of `signedDist` (with `+ᵥ` or `-ᵥ`) lemma signedDist_vadd_left : signedDist v (w +ᵥ p) q = -⟪normalize v, w⟫ + signedDist v p q := by simp [signedDist_linear_apply_apply] lemma signedDist_vadd_right : signedDist v p (w +ᵥ q) = ⟪normalize v, w⟫ + signedDist v p q := by simp [signedDist_apply_linear_apply] -- TODO: find a better name for these 2 lemmas lemma signedDist_vadd_left_swap : signedDist v (w +ᵥ p) q = signedDist v p (-w +ᵥ q) := by rw [signedDist_vadd_left, signedDist_vadd_right, inner_neg_right] lemma signedDist_vadd_right_swap : signedDist v p (w +ᵥ q) = signedDist v (-w +ᵥ p) q := by rw [signedDist_vadd_left_swap, neg_neg] lemma signedDist_vadd_vadd : signedDist v (w +ᵥ p) (w +ᵥ q) = signedDist v p q := by rw [signedDist_vadd_left_swap, neg_vadd_vadd] variable {v p q} in lemma signedDist_left_congr (h : ⟪v, p -ᵥ q⟫ = 0) : signedDist v p = signedDist v q := by ext r simpa [NormedSpace.normalize, real_inner_smul_left, h] using signedDist_vadd_left v (p -ᵥ q) q r variable {v q r} in lemma signedDist_right_congr (h : ⟪v, q -ᵥ r⟫ = 0) : signedDist v p q = signedDist v p r := by simpa [NormedSpace.normalize, real_inner_smul_left, h] using signedDist_vadd_right v (q -ᵥ r) p r variable {v p q} in lemma signedDist_eq_zero_of_orthogonal (h : ⟪v, q -ᵥ p⟫ = 0) : signedDist v p q = 0 := by simpa using signedDist_right_congr p h -- Lemmas relating `signedDist` to `dist` lemma abs_signedDist_le_dist : |signedDist v p q| ≤ dist p q := by rw [signedDist_apply_apply] by_cases h : v = 0 · simp [h] · grw [abs_real_inner_le_norm] simp [norm_normalize h, dist_eq_norm_vsub'] lemma signedDist_le_dist : signedDist v p q ≤ dist p q := le_trans (le_abs_self _) (abs_signedDist_le_dist _ _ _) lemma abs_signedDist_eq_dist_iff_vsub_mem_span : |signedDist v p q| = dist p q ↔ q -ᵥ p ∈ ℝ ∙ v := by rw [Submodule.mem_span_singleton] rw [signedDist_apply_apply, dist_eq_norm_vsub', NormedSpace.normalize, real_inner_smul_left, abs_mul, abs_inv, abs_norm] by_cases h : v = 0 · simp [h, eq_comm (a := (0 : ℝ)), eq_comm (a := (0 : V))] rw [inv_mul_eq_iff_eq_mul₀ (by positivity)] rw [← Real.norm_eq_abs, ((norm_inner_eq_norm_tfae ℝ v (q -ᵥ p)).out 0 2:)] simp [h, eq_comm] open NNReal in lemma signedDist_eq_dist_iff_vsub_mem_span : signedDist v p q = dist p q ↔ q -ᵥ p ∈ ℝ≥0 ∙ v := by rw [Submodule.mem_span_singleton] rw [signedDist_apply_apply, dist_eq_norm_vsub', NormedSpace.normalize, real_inner_smul_left] by_cases h : v = 0 · simp [h, eq_comm (a := (0 : ℝ)), eq_comm (a := (0 : V))] rw [inv_mul_eq_iff_eq_mul₀ (by positivity)] rw [inner_eq_norm_mul_iff_real] simp only [smul_def] refine ⟨fun h => ?_, fun ⟨c, h⟩ => ?_⟩ · simp only [NNReal.exists, coe_mk, exists_prop] use ‖v‖⁻¹ * ‖q -ᵥ p‖ constructor · positivity · rw [← smul_smul, h, smul_smul, inv_mul_cancel₀ (by positivity), one_smul] · rw [← h, norm_smul, smul_smul, mul_comm] simp @[simp] lemma signedDist_vsub_self : signedDist (q -ᵥ p) p q = dist p q := by rw [signedDist_eq_dist_iff_vsub_mem_span] apply Submodule.mem_span_singleton_self @[simp] lemma signedDist_vsub_self_rev : signedDist (p -ᵥ q) p q = -dist p q := by rw [← neg_eq_iff_eq_neg, ← signedDist_neg, neg_vsub_eq_vsub_rev] apply signedDist_vsub_self end signedDist namespace AffineSubspace variable (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p q : P) /-- The signed distance between `s` and a point, in the direction of the reference point `p`. This is expected to be used when `p` does not lie in `s` (in the degenerate case where `p` lies in `s`, this yields 0) and when the point at which the distance is evaluated lies in the affine span of `s` and `p` (any component of the distance orthogonal to that span is disregarded). -/ noncomputable def signedInfDist : P →ᴬ[ℝ] ℝ := signedDist (p -ᵥ orthogonalProjection s p) (Classical.ofNonempty : s) lemma signedInfDist_def : s.signedInfDist p = signedDist (p -ᵥ orthogonalProjection s p) ↑(Classical.ofNonempty : s) := rfl variable {s p q} in lemma signedInfDist_eq_signedDist_of_mem (h : q ∈ s) : s.signedInfDist p = signedDist (p -ᵥ orthogonalProjection s p) q := by apply signedDist_left_congr apply s.direction.inner_left_of_mem_orthogonal · exact vsub_mem_direction (SetLike.coe_mem _) h · exact vsub_orthogonalProjection_mem_direction_orthogonal s p lemma signedInfDist_eq_signedDist_orthogonalProjection {x : P} : s.signedInfDist p x = signedDist (p -ᵥ orthogonalProjection s p) ↑(orthogonalProjection s x) x := by rw [signedInfDist_eq_signedDist_of_mem (orthogonalProjection_mem x)] @[simp] lemma signedInfDist_apply_self : s.signedInfDist p p = ‖p -ᵥ orthogonalProjection s p‖ := by rw [signedInfDist_eq_signedDist_orthogonalProjection, signedDist_vsub_self, dist_eq_norm_vsub'] variable {s} in @[simp] lemma signedInfDist_apply_of_mem {x : P} (hx : x ∈ s) : s.signedInfDist p x = 0 := by simp [signedInfDist_eq_signedDist_orthogonalProjection, orthogonalProjection_eq_self_iff.2 hx] variable {s p} in @[simp] lemma signedInfDist_eq_const_of_mem (h : p ∈ s) : s.signedInfDist p = AffineMap.const ℝ P (0 : ℝ) := by ext x simp [signedInfDist_def, orthogonalProjection_eq_self_iff.2 h] variable {s p} in lemma abs_signedInfDist_eq_dist_of_mem_affineSpan_insert {x : P} (h : x ∈ affineSpan ℝ (insert p s)) : |s.signedInfDist p x| = dist x (orthogonalProjection s x) := by rw [mem_affineSpan_insert_iff (orthogonalProjection s p).property] at h rcases h with ⟨r, p₀, hp₀, rfl⟩ simp [hp₀, dist_eq_norm_vsub, orthogonalProjection_eq_self_iff.2 hp₀, orthogonalProjection_vsub_orthogonalProjection, norm_smul, abs_mul] lemma signedInfDist_singleton : (affineSpan ℝ ({q} : Set P)).signedInfDist p = signedDist (p -ᵥ q) q := by simpa using signedInfDist_eq_signedDist_of_mem (mem_affineSpan ℝ (Set.mem_singleton q)) end AffineSubspace namespace Affine namespace Simplex variable {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) /-- The signed distance between the face of `s` excluding point `i` of that simplex and a point, in the direction of the reference point `i`. This is expected to be used when the point at which the distance is evaluated lies in the affine span of the simplex (any component of the distance orthogonal to that span is disregarded). In the case of a triangle, these distances are trilinear coordinates; in a tetrahedron, they are quadriplanar coordinates. -/ noncomputable def signedInfDist : P →ᴬ[ℝ] ℝ := AffineSubspace.signedInfDist (affineSpan ℝ (s.points '' {i}ᶜ)) (s.points i) lemma signedInfDist_apply_self : s.signedInfDist i (s.points i) = ‖s.points i -ᵥ (s.faceOpposite i).orthogonalProjectionSpan (s.points i)‖ := (AffineSubspace.signedInfDist_apply_self _ _).trans <| by simp [orthogonalProjectionSpan] variable {i} in lemma signedInfDist_apply_of_ne {j : Fin (n + 1)} (h : j ≠ i) : s.signedInfDist i (s.points j) = 0 := AffineSubspace.signedInfDist_apply_of_mem _ (s.mem_affineSpan_image_iff.2 h) lemma signedInfDist_affineCombination {w : Fin (n + 1) → ℝ} (h : ∑ i, w i = 1) : s.signedInfDist i (Finset.univ.affineCombination ℝ s.points w) = w i * ‖s.points i -ᵥ (s.faceOpposite i).orthogonalProjectionSpan (s.points i)‖ := by rw [← ContinuousAffineMap.coe_toAffineMap, Finset.map_affineCombination _ _ _ h, Finset.univ.affineCombination_apply_eq_lineMap_sum w ((s.signedInfDist i).toAffineMap ∘ s.points) 0 ‖s.points i -ᵥ (s.faceOpposite i).orthogonalProjectionSpan (s.points i)‖ {i} h] · simp [AffineMap.lineMap_apply] · simp [signedInfDist_apply_self] · simp only [Finset.mem_sdiff, Finset.mem_univ, Finset.mem_singleton, true_and, Function.comp_apply] intro j hj exact s.signedInfDist_apply_of_ne hj variable {s} in lemma abs_signedInfDist_eq_dist_of_mem_affineSpan_range {p : P} (h : p ∈ affineSpan ℝ (Set.range s.points)) : |s.signedInfDist i p| = dist p ((s.faceOpposite i).orthogonalProjectionSpan p) := by rw [signedInfDist, AffineSubspace.abs_signedInfDist_eq_dist_of_mem_affineSpan_insert, orthogonalProjectionSpan] · simp_rw [range_faceOpposite_points] rw [affineSpan_insert_affineSpan] convert h exact Set.insert_image_compl_eq_range s.points i end Simplex end Affine
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Altitude.lean
import Mathlib.Geometry.Euclidean.Projection import Mathlib.Analysis.InnerProductSpace.Projection.FiniteDimensional import Mathlib.Analysis.InnerProductSpace.Affine /-! # Altitudes of a simplex This file defines the altitudes of a simplex and their feet. ## Main definitions * `altitude` is the line that passes through a vertex of a simplex and is orthogonal to the opposite face. * `altitudeFoot` is the orthogonal projection of a vertex of a simplex onto the opposite face. * `height` is the distance between a vertex of a simplex and its `altitudeFoot`. ## References * <https://en.wikipedia.org/wiki/Altitude_(triangle)> -/ noncomputable section namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- An altitude of a simplex is the line that passes through a vertex and is orthogonal to the opposite face. -/ def altitude {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : AffineSubspace ℝ P := mk' (s.points i) (affineSpan ℝ (s.points '' {i}ᶜ)).directionᗮ ⊓ affineSpan ℝ (Set.range s.points) /-- The definition of an altitude. -/ theorem altitude_def {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.altitude i = mk' (s.points i) (affineSpan ℝ (s.points '' {i}ᶜ)).directionᗮ ⊓ affineSpan ℝ (Set.range s.points) := rfl /-- A vertex lies in the corresponding altitude. -/ theorem mem_altitude {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i ∈ s.altitude i := (mem_inf_iff _ _ _).2 ⟨self_mem_mk' _ _, mem_affineSpan ℝ (Set.mem_range_self _)⟩ /-- The direction of an altitude. -/ theorem direction_altitude {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : (s.altitude i).direction = (vectorSpan ℝ (s.points '' {i}ᶜ))ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by rw [altitude_def, direction_inf_of_mem (self_mem_mk' (s.points i) _) (mem_affineSpan ℝ (Set.mem_range_self _)), direction_mk', direction_affineSpan, direction_affineSpan] /-- The vector span of the opposite face lies in the direction orthogonal to an altitude. -/ theorem vectorSpan_isOrtho_altitude_direction {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : vectorSpan ℝ (s.points '' {i}ᶜ) ⟂ (s.altitude i).direction := by rw [direction_altitude] exact (Submodule.isOrtho_orthogonal_right _).mono_right inf_le_left open Module /-- An altitude is finite-dimensional. -/ instance finiteDimensional_direction_altitude {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : FiniteDimensional ℝ (s.altitude i).direction := by rw [direction_altitude] infer_instance /-- An altitude is one-dimensional (i.e., a line). -/ @[simp] theorem finrank_direction_altitude {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : finrank ℝ (s.altitude i).direction = 1 := by rw [direction_altitude] have h := Submodule.finrank_add_inf_finrank_orthogonal (vectorSpan_mono ℝ (Set.image_subset_range s.points {i}ᶜ)) have hn : (n - 1) + 1 = n := by have := NeZero.ne n cases n <;> omega have hc : #({i}ᶜ) = (n - 1) + 1 := by rw [card_compl, card_singleton, Fintype.card_fin, hn, add_tsub_cancel_right] refine add_left_cancel (_root_.trans h ?_) classical rw [s.independent.finrank_vectorSpan (Fintype.card_fin _), ← Finset.coe_singleton, ← Finset.coe_compl, ← Finset.coe_image, s.independent.finrank_vectorSpan_image_finset hc, hn] /-- A line through a vertex is the altitude through that vertex if and only if it is orthogonal to the opposite face. -/ theorem affineSpan_pair_eq_altitude_iff {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) (p : P) : line[ℝ, p, s.points i] = s.altitude i ↔ p ≠ s.points i ∧ p ∈ affineSpan ℝ (Set.range s.points) ∧ p -ᵥ s.points i ∈ (affineSpan ℝ (s.points '' {i}ᶜ)).directionᗮ := by rw [eq_iff_direction_eq_of_mem (mem_affineSpan ℝ (Set.mem_insert_of_mem _ (Set.mem_singleton _))) (s.mem_altitude _), ← vsub_right_mem_direction_iff_mem (mem_affineSpan ℝ (Set.mem_range_self i)) p, direction_affineSpan, direction_affineSpan, direction_affineSpan] constructor · intro h constructor · intro heq rw [heq, Set.pair_eq_singleton, vectorSpan_singleton] at h have hd : finrank ℝ (s.altitude i).direction = 0 := by rw [← h, finrank_bot] simp at hd · rw [← Submodule.mem_inf, _root_.inf_comm, ← direction_altitude, ← h] exact vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_singleton _)) · rintro ⟨hne, h⟩ rw [← Submodule.mem_inf, _root_.inf_comm, ← direction_altitude] at h rw [vectorSpan_eq_span_vsub_set_left_ne ℝ (Set.mem_insert _ _), Set.insert_diff_of_mem _ (Set.mem_singleton _), Set.diff_singleton_eq_self fun h => hne (Set.mem_singleton_iff.1 h), Set.image_singleton] refine Submodule.eq_of_le_of_finrank_eq ?_ ?_ · rw [Submodule.span_le] simpa using h · rw [finrank_direction_altitude, finrank_span_set_eq_card] · simp · exact .singleton <| by simpa using hne /-- The foot of an altitude is the orthogonal projection of a vertex of a simplex onto the opposite face. -/ def altitudeFoot {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : P := (s.faceOpposite i).orthogonalProjectionSpan (s.points i) @[simp] lemma ne_altitudeFoot {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i ≠ s.altitudeFoot i := by intro h rw [eq_comm, altitudeFoot, orthogonalProjectionSpan, orthogonalProjection_eq_self_iff] at h simp at h @[simp] lemma altitudeFoot_mem_affineSpan_image_compl {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.altitudeFoot i ∈ affineSpan ℝ (s.points '' {i}ᶜ) := by rw [← range_faceOpposite_points] exact orthogonalProjection_mem _ lemma altitudeFoot_mem_affineSpan_faceOpposite {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.altitudeFoot i ∈ affineSpan ℝ (Set.range (s.faceOpposite i).points) := orthogonalProjection_mem _ lemma altitudeFoot_mem_affineSpan {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.altitudeFoot i ∈ affineSpan ℝ (Set.range s.points) := by refine SetLike.le_def.1 (affineSpan_mono _ ?_) (s.altitudeFoot_mem_affineSpan_faceOpposite _) simp lemma affineSpan_pair_altitudeFoot_eq_altitude {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : line[ℝ, s.altitudeFoot i, s.points i] = s.altitude i := by rw [affineSpan_pair_eq_altitude_iff] refine ⟨(s.ne_altitudeFoot i).symm, s.altitudeFoot_mem_affineSpan _, ?_⟩ rw [altitudeFoot, orthogonalProjectionSpan] simp_rw [range_faceOpposite_points] exact orthogonalProjection_vsub_mem_direction_orthogonal _ _ lemma altitudeFoot_mem_altitude {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.altitudeFoot i ∈ s.altitude i := by rw [← affineSpan_pair_altitudeFoot_eq_altitude] exact left_mem_affineSpan_pair _ _ _ /-- The height of a vertex of a simplex is the distance between it and the foot of the altitude from that vertex. -/ def height {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : ℝ := dist (s.points i) (s.altitudeFoot i) @[simp] lemma height_pos {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : 0 < s.height i := by simp [height] open Qq Mathlib.Meta.Positivity in /-- Extension for the `positivity` tactic: the height of a simplex is always positive. -/ @[positivity height _ _] def evalHeight : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(@height $V $P $i1 $i2 $i3 $i4 $n $hn $s $i) => assertInstancesCommute return .positive q(height_pos $s $i) | _, _, _ => throwError "not Simplex.height" example {n : ℕ} [NeZero n] (s : Simplex ℝ P n) (i : Fin (n + 1)) : 0 < s.height i := by positivity open scoped RealInnerProductSpace variable {n : ℕ} (s : Simplex ℝ P n) /-- The inner product of an edge from `j` to `i` and the vector from the foot of `i` to `i` is the square of the height. -/ lemma inner_vsub_vsub_altitudeFoot_eq_height_sq [NeZero n] {i j : Fin (n + 1)} (h : i ≠ j) : ⟪s.points i -ᵥ s.points j, s.points i -ᵥ s.altitudeFoot i⟫ = s.height i ^ 2 := by suffices ⟪s.points j -ᵥ s.altitudeFoot i, s.points i -ᵥ s.altitudeFoot i⟫ = 0 by rwa [height, inner_vsub_vsub_left_eq_dist_sq_right_iff, inner_vsub_left_eq_zero_symm] refine Submodule.inner_right_of_mem_orthogonal (K := vectorSpan ℝ (s.points '' {i}ᶜ)) (vsub_mem_vectorSpan_of_mem_affineSpan_of_mem_affineSpan (s.mem_affineSpan_image_iff.2 h.symm) (altitudeFoot_mem_affineSpan_image_compl _ _)) ?_ rw [← direction_affineSpan, ← range_faceOpposite_points] exact vsub_orthogonalProjection_mem_direction_orthogonal _ _ variable [Nat.AtLeastTwo n] /-- The inner product of two distinct altitudes has absolute value strictly less than the product of their lengths. Equivalently, neither vector is a multiple of the other; the angle between them is not 0 or π. -/ lemma abs_inner_vsub_altitudeFoot_lt_mul {i j : Fin (n + 1)} (hij : i ≠ j) : |⟪s.points i -ᵥ s.altitudeFoot i, s.points j -ᵥ s.altitudeFoot j⟫| < s.height i * s.height j := by apply lt_of_le_of_ne · convert abs_real_inner_le_norm _ _ using 1 simp only [dist_eq_norm_vsub, height] · simp_rw [height, dist_eq_norm_vsub] rw [← Real.norm_eq_abs, ne_eq, norm_inner_eq_norm_iff (by simp) (by simp)] rintro ⟨r, hr, h⟩ suffices s.points j -ᵥ s.altitudeFoot j = 0 by simp at this rw [← Submodule.mem_bot ℝ, ← Submodule.inf_orthogonal_eq_bot (vectorSpan ℝ (Set.range s.points))] refine ⟨vsub_mem_vectorSpan_of_mem_affineSpan_of_mem_affineSpan (mem_affineSpan _ (Set.mem_range_self _)) ?_, ?_⟩ · refine SetLike.le_def.1 (affineSpan_mono _ ?_) (Subtype.property _) simp · rw [SetLike.mem_coe] have hk : ∃ k, k ≠ i ∧ k ≠ j := Fin.exists_ne_and_ne_of_two_lt i j (by linarith only [Nat.AtLeastTwo.one_lt (n := n)]) have hs : vectorSpan ℝ (Set.range s.points) = vectorSpan ℝ (Set.range (s.faceOpposite i).points) ⊔ vectorSpan ℝ (Set.range (s.faceOpposite j).points) := by rcases hk with ⟨k, hki, hkj⟩ have hki' : s.points k ∈ Set.range (s.faceOpposite i).points := by rw [range_faceOpposite_points] exact Set.mem_image_of_mem _ hki have hkj' : s.points k ∈ Set.range (s.faceOpposite j).points := by rw [range_faceOpposite_points] exact Set.mem_image_of_mem _ hkj have hs : Set.range s.points = Set.range (s.faceOpposite i).points ∪ Set.range (s.faceOpposite j).points := by simp only [range_faceOpposite_points, ← Set.image_union] simp_rw [← Set.image_univ, ← Set.compl_inter] rw [Set.inter_singleton_eq_empty.mpr ?_, Set.compl_empty] simpa using hij.symm convert AffineSubspace.vectorSpan_union_of_mem_of_mem ℝ hki' hkj' rw [hs, ← Submodule.inf_orthogonal, Submodule.mem_inf] refine ⟨?_, ?_⟩ · rw [h, ← direction_affineSpan] exact Submodule.smul_mem _ _ (vsub_orthogonalProjection_mem_direction_orthogonal _ _) · rw [← direction_affineSpan] exact vsub_orthogonalProjection_mem_direction_orthogonal _ _ /-- The inner product of two altitudes has value strictly greater than the negated product of their lengths. -/ lemma neg_mul_lt_inner_vsub_altitudeFoot (i j : Fin (n + 1)) : -(s.height i * s.height j) < ⟪s.points i -ᵥ s.altitudeFoot i, s.points j -ᵥ s.altitudeFoot j⟫ := by obtain rfl | hij := eq_or_ne i j · rw [real_inner_self_eq_norm_sq] refine lt_of_lt_of_le (b := 0) ?_ ?_ · rw [neg_lt_zero] positivity · positivity rw [neg_lt] refine lt_of_abs_lt ?_ rw [abs_neg] exact abs_inner_vsub_altitudeFoot_lt_mul s hij lemma abs_inner_vsub_altitudeFoot_div_lt_one {i j : Fin (n + 1)} (hij : i ≠ j) : |⟪s.points i -ᵥ s.altitudeFoot i, s.points j -ᵥ s.altitudeFoot j⟫ / (s.height i * s.height j)| < 1 := by rw [abs_div, div_lt_one (by simp [height])] nth_rw 2 [abs_eq_self.2] · exact abs_inner_vsub_altitudeFoot_lt_mul _ hij · simp only [height] positivity lemma neg_one_lt_inner_vsub_altitudeFoot_div (s : Simplex ℝ P n) (i j : Fin (n + 1)) : -1 < ⟪s.points i -ᵥ s.altitudeFoot i, s.points j -ᵥ s.altitudeFoot j⟫ / (s.height i * s.height j) := by rw [neg_lt, neg_div', div_lt_one (by simp [height]), neg_lt] exact neg_mul_lt_inner_vsub_altitudeFoot _ _ _ end Simplex end Affine
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Triangle.lean
import Mathlib.Analysis.Normed.Affine.AddTorsor import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine import Mathlib.Tactic.IntervalCases /-! # Triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) triangles in real inner product spaces and Euclidean affine spaces. More specialized results, and results developed for simplices in general rather than just for triangles, are in separate files. Definitions and results that make sense in more general affine spaces rather than just in the Euclidean case go under `LinearAlgebra.AffineSpace`. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Law_of_cosines * https://en.wikipedia.org/wiki/Pons_asinorum * https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle * https://en.wikipedia.org/wiki/Law_of_sines -/ noncomputable section open scoped CharZero Real RealInnerProductSpace namespace InnerProductGeometry /-! ### Geometrical results on triangles in real inner product spaces This section develops some results on (possibly degenerate) triangles in real inner product spaces, where those definitions and results can most conveniently be developed in terms of vectors and then used to deduce corresponding results for Euclidean affine spaces. -/ variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- **Law of cosines** (cosine rule), vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (x y : V) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - 2 * ‖x‖ * ‖y‖ * Real.cos (angle x y) := by rw [show 2 * ‖x‖ * ‖y‖ * Real.cos (angle x y) = 2 * (Real.cos (angle x y) * (‖x‖ * ‖y‖)) by ring, cos_angle_mul_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, real_inner_sub_sub_self, sub_add_eq_add_sub] /-- **Law of sines** (sine rule), vector angle form. -/ theorem sin_angle_mul_norm_eq_sin_angle_mul_norm (x y : V) : Real.sin (angle x y) * ‖x‖ = Real.sin (angle y (x - y)) * ‖x - y‖ := by obtain rfl | hy := eq_or_ne y 0 · simp obtain rfl | hx := eq_or_ne x 0 · simp [angle_neg_right, angle_self hy] obtain rfl | hxy := eq_or_ne x y · simp [angle_self hx] have h_sin (x y : V) (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x y) = √(⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫) / (‖x‖ * ‖y‖) := by simp [field, mul_assoc, sin_angle_mul_norm_mul_norm] rw [h_sin x y hx hy, h_sin y (x - y) hy (sub_ne_zero_of_ne hxy)] simp only [inner_sub_left, inner_sub_right, real_inner_comm x y] have hsub : x - y ≠ 0 := sub_ne_zero_of_ne hxy field_simp ring_nf /-- A variant of the law of sines, (two given sides are nonzero), vector angle form. -/ theorem sin_angle_div_norm_eq_sin_angle_div_norm (x y : V) (hx : x ≠ 0) (hxy : x - y ≠ 0) : Real.sin (angle x y) / ‖x - y‖ = Real.sin (angle y (x - y)) / ‖x‖ := by simp [field, sin_angle_mul_norm_eq_sin_angle_mul_norm x y] /-- **Pons asinorum**, vector angle form. -/ theorem angle_sub_eq_angle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : angle x (x - y) = angle y (y - x) := by refine Real.injOn_cos ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ?_ rw [cos_angle, cos_angle, h, ← neg_sub, norm_neg, neg_sub, inner_sub_right, inner_sub_right, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, h, real_inner_comm x y] /-- **Converse of pons asinorum**, vector angle form. -/ theorem norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi {x y : V} (h : angle x (x - y) = angle y (y - x)) (hpi : angle x y ≠ π) : ‖x‖ = ‖y‖ := by replace h := Real.arccos_injOn (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x (x - y))) (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one y (y - x))) h by_cases hxy : x = y · rw [hxy] · rw [← norm_neg (y - x), neg_sub, mul_comm, mul_comm ‖y‖, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev, mul_inv_rev, ← mul_assoc, ← mul_assoc] at h replace h := mul_right_cancel₀ (inv_ne_zero fun hz => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 hz))) h rw [inner_sub_right, inner_sub_right, real_inner_comm x y, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, mul_sub_right_distrib, mul_sub_right_distrib, mul_self_mul_inv, mul_self_mul_inv, sub_eq_sub_iff_sub_eq_sub, ← mul_sub_left_distrib] at h by_cases hx0 : x = 0 · rw [hx0, norm_zero, inner_zero_left, zero_mul, zero_sub, neg_eq_zero] at h rw [hx0, norm_zero, h] · by_cases hy0 : y = 0 · rw [hy0, norm_zero, inner_zero_right, zero_mul, sub_zero] at h rw [hy0, norm_zero, h] · rw [inv_sub_inv (fun hz => hx0 (norm_eq_zero.1 hz)) fun hz => hy0 (norm_eq_zero.1 hz), ← neg_sub, ← mul_div_assoc, mul_comm, mul_div_assoc, ← mul_neg_one] at h symm by_contra hyx replace h := (mul_left_cancel₀ (sub_ne_zero_of_ne hyx) h).symm rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, ← angle_eq_pi_iff] at h exact hpi h /-- The cosine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ private theorem cos_angle_eq_cos_angle_add_add_angle_add {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.cos (angle x y) = Real.cos (angle x (x + y) + angle y (y + x)) := by rcases eq_or_ne x (-y) with (rfl | hxy) · simp [hy] · rw [Real.cos_add, cos_angle, cos_angle, cos_angle, sin_angle_add hx (by grind), sin_angle_add hy (by grind), mul_comm ⟪y, y⟫ ⟪x, x⟫, real_inner_comm x y, add_comm y x] have : x + y ≠ 0 := by grind simp only [field] -- non-recursive `field_simp` rw [Real.sq_sqrt (sub_nonneg_of_le (real_inner_mul_inner_self_le x y))] simp only [← real_inner_self_eq_norm_sq, inner_add_right, inner_add_left, real_inner_comm] ring /-- The sine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ private theorem sin_angle_eq_sin_angle_add_add_angle_add {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x y) = Real.sin (angle x (x + y) + angle y (y + x)) := by rcases eq_or_ne x (-y) with (rfl | hxy) · simp [hy] · rw [Real.sin_add, cos_angle, cos_angle, sin_angle_add hx (by grind), sin_angle_add hy (by grind), sin_angle hx hy, add_comm y x] have : x + y ≠ 0 := by grind simp only [field] -- non-recursive `field_simp` simp only [← real_inner_self_eq_norm_sq, inner_add_right, inner_add_left, real_inner_comm] ring_nf /-- In a paralellogram, the two parts of the inner angle add to the inner angle, vector angle form. -/ theorem angle_eq_angle_add_add_angle_add (x : V) {y : V} (hy : y ≠ 0) : angle x y = angle x (x + y) + angle y (x + y) := by rcases eq_or_ne x 0 with (rfl | hx) · simp [hy] have h := Real.Angle.cos_sin_inj (cos_angle_eq_cos_angle_add_add_angle_add hx hy) (sin_angle_eq_sin_angle_add_add_angle_add hx hy) rw [add_comm y x] at h obtain ⟨_, ⟨n, rfl⟩, h⟩ := (QuotientAddGroup.mk'_eq_mk' _).mp h simp only at h have : -1 < n := by replace h := h.ge contrapose! h grw [h, neg_smul, one_smul, angle_le_pi, ← angle_nonneg, ← angle_nonneg] linear_combination Real.pi_pos have : n < 1 := by replace h := h.le by_contra! hn grw [← hn, one_smul, ← angle_nonneg x y, zero_add, two_mul] at h have h' := h.trans_eq (add_comm _ _) grw [angle_le_pi] at h' h rw [add_le_add_iff_left, (angle_le_pi _ _).ge_iff_eq, angle_comm, angle_eq_pi_iff] at h' h obtain ⟨hxy, r₁, r₁_pos, hr₁⟩ := h' obtain ⟨-, r₂, r₂_pos, hr₂⟩ := h have : (r₁ + r₂ - 1) • (x + y) = 0 := by rw [sub_smul, add_smul, one_smul, ← hr₁, ← hr₂, sub_eq_zero] cases eq_zero_or_eq_zero_of_smul_eq_zero this · linarith · contradiction obtain rfl : n = 0 := by cutsat simpa using h /-- The sum of the angles of a possibly degenerate triangle (where one of the two given sides is nonzero), vector angle form. -/ theorem angle_add_angle_sub_add_angle_sub_eq_pi (x : V) {y : V} (hy : y ≠ 0) : angle x y + angle x (x - y) + angle y (y - x) = π := by have h := angle_eq_angle_add_add_angle_add (x - y) hy rw [sub_add_cancel] at h rw [← neg_sub x y, angle_neg_right] simp only [angle_comm] at h ⊢ linear_combination -h end InnerProductGeometry namespace EuclideanGeometry /-! ### Geometrical results on triangles in Euclidean affine spaces This section develops some geometrical definitions and results on (possibly degenerate) triangles in Euclidean affine spaces. -/ open InnerProductGeometry open scoped EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- **Law of cosines** (cosine rule), angle-at-point form. -/ theorem dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle (p₁ p₂ p₃ : P) : dist p₁ p₃ * dist p₁ p₃ = dist p₁ p₂ * dist p₁ p₂ + dist p₃ p₂ * dist p₃ p₂ - 2 * dist p₁ p₂ * dist p₃ p₂ * Real.cos (∠ p₁ p₂ p₃) := by rw [dist_eq_norm_vsub V p₁ p₃, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₃ p₂] unfold angle convert norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (p₁ -ᵥ p₂ : V) (p₃ -ᵥ p₂ : V) · exact (vsub_sub_vsub_cancel_right p₁ p₃ p₂).symm · exact (vsub_sub_vsub_cancel_right p₁ p₃ p₂).symm alias law_cos := dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle /-- **Law of sines** (sine rule), angle-at-point form. -/ theorem sin_angle_mul_dist_eq_sin_angle_mul_dist (p₁ p₂ p₃ : P) : Real.sin (∠ p₁ p₂ p₃) * dist p₂ p₃ = Real.sin (∠ p₃ p₁ p₂) * dist p₃ p₁ := by simp only [dist_comm p₂ p₃, angle] rw [dist_eq_norm_vsub V p₃ p₂, dist_eq_norm_vsub V p₃ p₁, InnerProductGeometry.angle_comm, sin_angle_mul_norm_eq_sin_angle_mul_norm, vsub_sub_vsub_cancel_right, mul_eq_mul_right_iff] left rw [InnerProductGeometry.angle_comm, ← neg_vsub_eq_vsub_rev p₁ p₂, angle_neg_right, Real.sin_pi_sub] alias law_sin := sin_angle_mul_dist_eq_sin_angle_mul_dist -- see https://github.com/leanprover-community/mathlib4/issues/29041 set_option linter.unusedSimpArgs false in /-- A variant of the law of sines, angle-at-point form. -/ theorem sin_angle_div_dist_eq_sin_angle_div_dist {p₁ p₂ p₃ : P} (h23 : p₂ ≠ p₃) (h31 : p₃ ≠ p₁) : Real.sin (∠ p₁ p₂ p₃) / dist p₃ p₁ = Real.sin (∠ p₃ p₁ p₂) / dist p₂ p₃ := by simp [field, dist_ne_zero.mpr h23, dist_ne_zero.mpr h31, mul_comm (dist ..)] exact law_sin _ _ _ /-- A variant of the law of sines, requiring that the points not be collinear. -/ theorem dist_eq_dist_mul_sin_angle_div_sin_angle {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) : dist p₁ p₂ = dist p₃ p₁ * Real.sin (∠ p₂ p₃ p₁) / Real.sin (∠ p₁ p₂ p₃) := by have sin_gt_zero : 0 < Real.sin (∠ p₁ p₂ p₃) := sin_pos_of_not_collinear h field_simp rw [mul_comm, mul_comm (dist p₃ p₁), law_sin] /-- **Isosceles Triangle Theorem**: Pons asinorum, angle-at-point form. -/ theorem angle_eq_angle_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : ∠ p₁ p₂ p₃ = ∠ p₁ p₃ p₂ := by rw [dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃] at h unfold angle convert angle_sub_eq_angle_sub_rev_of_norm_eq h · exact (vsub_sub_vsub_cancel_left p₃ p₂ p₁).symm · exact (vsub_sub_vsub_cancel_left p₂ p₃ p₁).symm /-- Converse of pons asinorum, angle-at-point form. -/ theorem dist_eq_of_angle_eq_angle_of_angle_ne_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = ∠ p₁ p₃ p₂) (hpi : ∠ p₂ p₁ p₃ ≠ π) : dist p₁ p₂ = dist p₁ p₃ := by unfold angle at h hpi rw [dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃] rw [← angle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hpi rw [← vsub_sub_vsub_cancel_left p₃ p₂ p₁, ← vsub_sub_vsub_cancel_left p₂ p₃ p₁] at h exact norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi h hpi /-- The **sum of the angles of a triangle** (possibly degenerate, where two given vertices are distinct), angle-at-point. -/ theorem angle_add_angle_add_angle_eq_pi {p₁ p₂ : P} (p₃ : P) (h : p₂ ≠ p₁) : ∠ p₁ p₂ p₃ + ∠ p₂ p₃ p₁ + ∠ p₃ p₁ p₂ = π := by rw [add_assoc, add_comm, add_comm (∠ p₂ p₃ p₁), angle_comm p₂ p₃ p₁] unfold angle rw [← angle_neg_neg (p₁ -ᵥ p₃), ← angle_neg_neg (p₁ -ᵥ p₂), neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, ← vsub_sub_vsub_cancel_right p₃ p₂ p₁, ← vsub_sub_vsub_cancel_right p₂ p₃ p₁] exact angle_add_angle_sub_add_angle_sub_eq_pi _ fun he => h (vsub_eq_zero_iff_eq.1 he) /-- The **sum of the angles of a triangle** (possibly degenerate, where the triangle is a line), oriented angles at point. -/ theorem oangle_add_oangle_add_oangle_eq_pi [Module.Oriented ℝ V (Fin 2)] [Fact (Module.finrank ℝ V = 2)] {p₁ p₂ p₃ : P} (h21 : p₂ ≠ p₁) (h32 : p₃ ≠ p₂) (h13 : p₁ ≠ p₃) : ∡ p₁ p₂ p₃ + ∡ p₂ p₃ p₁ + ∡ p₃ p₁ p₂ = π := by simpa only [neg_vsub_eq_vsub_rev] using positiveOrientation.oangle_add_cyc3_neg_left (vsub_ne_zero.mpr h21) (vsub_ne_zero.mpr h32) (vsub_ne_zero.mpr h13) /-- Given a triangle `ABC` with `A ≠ B` and `A ≠ C` and a point `P` on `BC`, `∠ B A P + ∠ P A C = ∠ B A C`. -/ lemma angle_add_of_ne_of_ne {a b c p : P} (hb : a ≠ b) (hc : a ≠ c) (hp : Wbtw ℝ b p c) : ∠ b a p + ∠ p a c = ∠ b a c := by by_cases pb : p = b; · simpa [pb] using angle_self_of_ne hb.symm by_cases pc : p = c; · simpa [pc] using angle_self_of_ne hc.symm have ea := angle_add_angle_add_angle_eq_pi c hb have eb := angle_add_angle_add_angle_eq_pi p hb have ec := angle_add_angle_add_angle_eq_pi p hc.symm replace hp : ∠ b p c = π := angle_eq_pi_iff_sbtw.mpr ⟨hp, pb, pc⟩ have hp' : ∠ c p b = π := by rwa [angle_comm] at hp rw [angle_comm p b a, angle_eq_angle_of_angle_eq_pi a hp, angle_comm a b c] at eb rw [angle_eq_angle_of_angle_eq_pi a hp', angle_comm c p a] at ec have ep := angle_add_angle_eq_pi_of_angle_eq_pi a hp linarith only [ea, eb, ec, ep] /-- **Stewart's Theorem**. -/ theorem dist_sq_mul_dist_add_dist_sq_mul_dist (a b c p : P) (h : ∠ b p c = π) : dist a b ^ 2 * dist c p + dist a c ^ 2 * dist b p = dist b c * (dist a p ^ 2 + dist b p * dist c p) := by rw [pow_two, pow_two, law_cos a p b, law_cos a p c, eq_sub_of_add_eq (angle_add_angle_eq_pi_of_angle_eq_pi a h), Real.cos_pi_sub, dist_eq_add_dist_of_angle_eq_pi h] ring /-- **Apollonius's Theorem**. -/ theorem dist_sq_add_dist_sq_eq_two_mul_dist_midpoint_sq_add_half_dist_sq (a b c : P) : dist a b ^ 2 + dist a c ^ 2 = 2 * (dist a (midpoint ℝ b c) ^ 2 + (dist b c / 2) ^ 2) := by by_cases hbc : b = c · simp [hbc, midpoint_self, dist_self, two_mul] · let m := midpoint ℝ b c have : dist b c ≠ 0 := (dist_pos.mpr hbc).ne' have hm := dist_sq_mul_dist_add_dist_sq_mul_dist a b c m (angle_midpoint_eq_pi b c hbc) simp only [m, dist_left_midpoint, dist_right_midpoint, Real.norm_two] at hm calc dist a b ^ 2 + dist a c ^ 2 = 2 / dist b c * (dist a b ^ 2 * ((2 : ℝ)⁻¹ * dist b c) + dist a c ^ 2 * (2⁻¹ * dist b c)) := by field _ = 2 * (dist a (midpoint ℝ b c) ^ 2 + (dist b c / 2) ^ 2) := by rw [hm] field theorem dist_mul_of_eq_angle_of_dist_mul (a b c a' b' c' : P) (r : ℝ) (h : ∠ a' b' c' = ∠ a b c) (hab : dist a' b' = r * dist a b) (hcb : dist c' b' = r * dist c b) : dist a' c' = r * dist a c := by have h' : dist a' c' ^ 2 = (r * dist a c) ^ 2 := calc dist a' c' ^ 2 = dist a' b' ^ 2 + dist c' b' ^ 2 - 2 * dist a' b' * dist c' b' * Real.cos (∠ a' b' c') := by simp [pow_two, law_cos a' b' c'] _ = r ^ 2 * (dist a b ^ 2 + dist c b ^ 2 - 2 * dist a b * dist c b * Real.cos (∠ a b c)) := by rw [h, hab, hcb]; ring _ = (r * dist a c) ^ 2 := by simp [pow_two, ← law_cos a b c]; ring by_cases hab₁ : a = b · have hab'₁ : a' = b' := by rw [← dist_eq_zero, hab, dist_eq_zero.mpr hab₁, mul_zero r] rw [hab₁, hab'₁, dist_comm b' c', dist_comm b c, hcb] · have h1 : 0 ≤ r * dist a b := by rw [← hab]; exact dist_nonneg have h2 : 0 ≤ r := nonneg_of_mul_nonneg_left h1 (dist_pos.mpr hab₁) exact (sq_eq_sq₀ dist_nonneg (mul_nonneg h2 dist_nonneg)).mp h' /-- In a triangle, the smaller angle is opposite the smaller side. -/ theorem dist_lt_of_angle_lt {a b c : P} (h : ¬Collinear ℝ ({a, b, c} : Set P)) : ∠ a c b < ∠ a b c → dist a b < dist a c := by have hsin := law_sin c b a rw [dist_comm b a, angle_comm c b a] at hsin have hac : dist a c > 0 := dist_pos.mpr (ne₁₃_of_not_collinear h) have hsinabc : Real.sin (∠ a b c) ≥ 0 := by apply Real.sin_nonneg_of_mem_Icc simp [angle_nonneg, angle_le_pi] intro h1 by_cases! h2 : ∠ a b c ≤ π / 2 · have h3 : Real.sin (∠ a c b) < Real.sin (∠ a b c) := by exact Real.sin_lt_sin_of_lt_of_le_pi_div_two (by linarith [angle_nonneg a c b]) h2 h1 by_contra! w have h4 : Real.sin (∠ a c b) * dist a c < Real.sin (∠ a b c) * dist a b := by exact mul_lt_mul h3 w hac hsinabc linarith · by_contra! w have h3 : Real.sin (∠ a b c) ≤ Real.sin (∠ a c b) := by by_contra! w1 have h4 : Real.sin (∠ a c b) * dist a c < Real.sin (∠ a b c) * dist a b := by exact mul_lt_mul w1 w hac hsinabc linarith rw [← Real.sin_pi_sub (∠ a b c)] at h3 have h5 : π - ∠ a b c < π / 2 := by linarith have h6 : π - ∠ a b c ≤ ∠ a c b := by by_contra! w1 have := Real.sin_lt_sin_of_lt_of_le_pi_div_two (by linarith [angle_nonneg a c b]) h5.le w1 linarith have h7 := angle_add_angle_add_angle_eq_pi c (ne₁₂_of_not_collinear h).symm rw [angle_comm b c a] at h7 have h8 : ∠ c a b > 0 := by rw [angle_comm] rw [show ({a, b, c} : Set P) = {b, a, c} by exact Set.insert_comm a b {c}] at h exact angle_pos_of_not_collinear h linarith theorem angle_lt_iff_dist_lt {a b c : P} (h : ¬Collinear ℝ ({a, b, c} : Set P)) : ∠ a c b < ∠ a b c ↔ dist a b < dist a c := by constructor case mp => exact dist_lt_of_angle_lt h case mpr => intro h1 by_contra! w rcases w.eq_or_lt with h2 | h3 · have h4 : dist a b = dist a c := by apply dist_eq_of_angle_eq_angle_of_angle_ne_pi h2 rw [show ({a, b, c} : Set P) = {b, a, c} by exact Set.insert_comm a b {c}] at h linarith [angle_lt_pi_of_not_collinear h] linarith · rw [show ({a, b, c} : Set P) = {a, c, b} by grind] at h have h5 := dist_lt_of_angle_lt h h3 linarith theorem angle_le_iff_dist_le {a b c : P} (h : ¬Collinear ℝ ({a, b, c} : Set P)) : ∠ a c b ≤ ∠ a b c ↔ dist a b ≤ dist a c := by rw [show ({a, b, c} : Set P) = {a, c, b} by grind] at h simpa using (angle_lt_iff_dist_lt h).not end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Circumcenter.lean
import Mathlib.Geometry.Euclidean.Projection import Mathlib.Geometry.Euclidean.Sphere.Basic import Mathlib.LinearAlgebra.AffineSpace.Simplex.Centroid import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.DeriveFintype /-! # Circumcenter and circumradius This file proves some lemmas on points equidistant from a set of points, and defines the circumradius and circumcenter of a simplex. There are also some definitions for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. ## Main definitions * `circumcenter` and `circumradius` are the circumcenter and circumradius of a simplex. ## References * https://en.wikipedia.org/wiki/Circumscribed_circle -/ noncomputable section open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] open AffineSubspace /-- The induction step for the existence and uniqueness of the circumcenter. Given a nonempty set of points in a nonempty affine subspace whose direction is complete, such that there is a unique (circumcenter, circumradius) pair for those points in that subspace, and a point `p` not in that subspace, there is a unique (circumcenter, circumradius) pair for the set with `p` added, in the span of the subspace with `p` added. -/ theorem existsUnique_dist_eq_of_insert {s : AffineSubspace ℝ P} [s.direction.HasOrthogonalProjection] {ps : Set P} (hnps : ps.Nonempty) {p : P} (hps : ps ⊆ s) (hp : p ∉ s) (hu : ∃! cs : Sphere P, cs.center ∈ s ∧ ps ⊆ (cs : Set P)) : ∃! cs₂ : Sphere P, cs₂.center ∈ affineSpan ℝ (insert p (s : Set P)) ∧ insert p ps ⊆ (cs₂ : Set P) := by haveI : Nonempty s := Set.Nonempty.to_subtype (hnps.mono hps) rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩ simp only at hcc hcr hcccru let x := dist cc (orthogonalProjection s p) let y := dist p (orthogonalProjection s p) have hy0 : y ≠ 0 := dist_orthogonalProjection_ne_zero_of_notMem hp let ycc₂ := (x * x + y * y - cr * cr) / (2 * y) let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonalProjection s p : V) +ᵥ cc let cr₂ := √(cr * cr + ycc₂ * ycc₂) use ⟨cc₂, cr₂⟩ simp -zeta -proj only have hpo : p = (1 : ℝ) • (p -ᵥ orthogonalProjection s p : V) +ᵥ (orthogonalProjection s p : P) := by simp constructor · constructor · refine vadd_mem_of_mem_direction ?_ (mem_affineSpan ℝ (Set.mem_insert_of_mem _ hcc)) rw [direction_affineSpan] exact Submodule.smul_mem _ _ (vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (orthogonalProjection_mem _))) · intro p₁ hp₁ rw [Sphere.mem_coe, mem_sphere, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] rcases hp₁ with hp₁ | hp₁ · rw [hp₁, hpo, dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), ← dist_eq_norm_vsub V p, dist_comm _ cc] simp only [ycc₂] field · rw [dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp₁), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc, Subtype.coe_mk, dist_of_mem_subset_mk_sphere hp₁ hcr, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V, Real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg, div_mul_cancel₀ _ hy0, abs_mul_abs_self] · rintro ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩ simp only at hcc₃ hcr₃ obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ : ∃ r : ℝ, ∃ p0 ∈ s, cc₃ = r • (p -ᵥ ↑((orthogonalProjection s) p)) +ᵥ p0 := by rwa [mem_affineSpan_insert_iff (orthogonalProjection_mem p)] at hcc₃ have hcr₃' : ∃ r, ∀ p₁ ∈ ps, dist p₁ cc₃ = r := ⟨cr₃, fun p₁ hp₁ => dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp₁) hcr₃⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq hps cc₃, hcc₃'', orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃'] at hcr₃' obtain ⟨cr₃', hcr₃'⟩ := hcr₃' have hu := hcccru ⟨cc₃', cr₃'⟩ simp only at hu replace hu := hu ⟨hcc₃', hcr₃'⟩ cases hu have hcr₃val : cr₃ = √(cr * cr + t₃ * y * (t₃ * y)) := by obtain ⟨p0, hp0⟩ := hnps have h' : ↑(⟨cc, hcc₃'⟩ : s) = cc := rfl rw [← dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp0) hcr₃, hcc₃'', ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)), dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp0), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃', h', dist_of_mem_subset_mk_sphere hp0 hcr, dist_eq_norm_vsub V _ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V p, Real.norm_eq_abs, ← mul_assoc, mul_comm _ |t₃|, ← mul_assoc, abs_mul_abs_self] ring replace hcr₃ := dist_of_mem_subset_mk_sphere (Set.mem_insert _ _) hcr₃ rw [hpo, hcc₃'', hcr₃val, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc₃' _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), dist_comm, ← dist_eq_norm_vsub V p, Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃ change x * x + _ * (y * y) = _ at hcr₃ rw [show x * x + (1 - t₃) * (1 - t₃) * (y * y) = x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y) by ring, add_left_inj] at hcr₃ have ht₃ : t₃ = ycc₂ / y := by simp [ycc₂, ← hcr₃, hy0] subst ht₃ change cc₃ = cc₂ at hcc₃'' congr rw [hcr₃val] congr 2 field /-- Given a finite nonempty affinely independent family of points, there is a unique (circumcenter, circumradius) pair for those points in the affine subspace they span. -/ theorem _root_.AffineIndependent.existsUnique_dist_eq {ι : Type*} [hne : Nonempty ι] [Finite ι] {p : ι → P} (ha : AffineIndependent ℝ p) : ∃! cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range p) ∧ Set.range p ⊆ (cs : Set P) := by cases nonempty_fintype ι induction hn : Fintype.card ι generalizing ι with | zero => exfalso have h := Fintype.card_pos_iff.2 hne cutsat | succ m hm => rcases m with - | m · rw [Fintype.card_eq_one_iff] at hn obtain ⟨i, hi⟩ := hn haveI : Unique ι := ⟨⟨i⟩, hi⟩ use ⟨p i, 0⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] constructor · simp_rw [hi default, Set.singleton_subset_iff] exact ⟨⟨⟩, by simp only [Metric.sphere_zero, Set.mem_singleton_iff]⟩ · rintro ⟨cc, cr⟩ rintro ⟨rfl, hdist⟩ replace hdist : 0 = cr := by simpa using hdist rw [hi default, hdist] · have i := hne.some let ι2 := { x // x ≠ i } classical have hc : Fintype.card ι2 = m + 1 := by rw [Fintype.card_of_subtype {x | x ≠ i}] · rw [Finset.filter_not, Finset.filter_eq' _ i, if_pos (Finset.mem_univ _), Finset.card_sdiff, Finset.card_univ, hn] simp · simp haveI : Nonempty ι2 := Fintype.card_pos_iff.1 (hc.symm ▸ Nat.zero_lt_succ _) have ha2 : AffineIndependent ℝ fun i2 : ι2 => p i2 := ha.subtype _ replace hm := hm ha2 _ hc have hr : Set.range p = insert (p i) (Set.range fun i2 : ι2 => p i2) := by change _ = insert _ (Set.range fun i2 : { x | x ≠ i } => p i2) rw [← Set.image_eq_range, ← Set.image_univ, ← Set.image_insert_eq] congr with j simp [Classical.em] rw [hr, ← affineSpan_insert_affineSpan] refine existsUnique_dist_eq_of_insert (Set.range_nonempty _) (subset_affineSpan ℝ _) ?_ hm convert ha.notMem_affineSpan_diff i Set.univ change (Set.range fun i2 : { x | x ≠ i } => p i2) = _ rw [← Set.image_eq_range] congr 1 with j simp end EuclideanGeometry namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The circumsphere of a simplex. -/ def circumsphere {n : ℕ} (s : Simplex ℝ P n) : Sphere P := s.independent.existsUnique_dist_eq.choose /-- The property satisfied by the circumsphere. -/ theorem circumsphere_unique_dist_eq {n : ℕ} (s : Simplex ℝ P n) : (s.circumsphere.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ s.circumsphere) ∧ ∀ cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ cs → cs = s.circumsphere := s.independent.existsUnique_dist_eq.choose_spec /-- The circumcenter of a simplex. -/ def circumcenter {n : ℕ} (s : Simplex ℝ P n) : P := s.circumsphere.center /-- The circumradius of a simplex. -/ def circumradius {n : ℕ} (s : Simplex ℝ P n) : ℝ := s.circumsphere.radius /-- The center of the circumsphere is the circumcenter. -/ @[simp] theorem circumsphere_center {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.center = s.circumcenter := rfl /-- The radius of the circumsphere is the circumradius. -/ @[simp] theorem circumsphere_radius {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.radius = s.circumradius := rfl /-- The circumcenter lies in the affine span. -/ theorem circumcenter_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter ∈ affineSpan ℝ (Set.range s.points) := s.circumsphere_unique_dist_eq.1.1 /-- All points have distance from the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : dist (s.points i) s.circumcenter = s.circumradius := dist_of_mem_subset_sphere (Set.mem_range_self _) s.circumsphere_unique_dist_eq.1.2 /-- All points lie in the circumsphere. -/ theorem mem_circumsphere {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i ∈ s.circumsphere := s.dist_circumcenter_eq_circumradius i /-- All points have distance to the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius' {n : ℕ} (s : Simplex ℝ P n) : ∀ i, dist s.circumcenter (s.points i) = s.circumradius := by intro i rw [dist_comm] exact dist_circumcenter_eq_circumradius _ _ /-- Given a point in the affine span from which all the points are equidistant, that point is the circumcenter. -/ theorem eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : p = s.circumcenter := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, subset_sphere (s := ⟨p, r⟩), Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h exact h.1 /-- Given a point in the affine span from which all the points are equidistant, that distance is the circumradius. -/ theorem eq_circumradius_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : r = s.circumradius := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, subset_sphere (s := ⟨p, r⟩), Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h exact h.2 /-- The circumradius is non-negative. -/ theorem circumradius_nonneg {n : ℕ} (s : Simplex ℝ P n) : 0 ≤ s.circumradius := s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg /-- The circumradius of a simplex with at least two points is positive. -/ theorem circumradius_pos {n : ℕ} (s : Simplex ℝ P (n + 1)) : 0 < s.circumradius := by refine lt_of_le_of_ne s.circumradius_nonneg ?_ intro h have hr := s.dist_circumcenter_eq_circumradius simp_rw [← h, dist_eq_zero] at hr have h01 := s.independent.injective.ne (by simp : (0 : Fin (n + 2)) ≠ 1) simp [hr] at h01 /-- The circumcenter of a 0-simplex equals its unique point. -/ theorem circumcenter_eq_point (s : Simplex ℝ P 0) (i : Fin 1) : s.circumcenter = s.points i := by have h := s.circumcenter_mem_affineSpan have : Unique (Fin 1) := ⟨⟨0, by decide⟩, fun a => by simp only [Fin.eq_zero]⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] at h rw [h] congr simp only [eq_iff_true_of_subsingleton] /-- The circumcenter of a 1-simplex equals its centroid. -/ theorem circumcenter_eq_centroid (s : Simplex ℝ P 1) : s.circumcenter = Finset.univ.centroid ℝ s.points := by have hr : Set.Pairwise Set.univ fun i j : Fin 2 => dist (s.points i) (Finset.univ.centroid ℝ s.points) = dist (s.points j) (Finset.univ.centroid ℝ s.points) := by intro i hi j hj hij rw [Finset.centroid_pair_fin, dist_eq_norm_vsub V (s.points i), dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, ← one_smul ℝ (s.points i -ᵥ s.points 0), ← one_smul ℝ (s.points j -ᵥ s.points 0)] fin_cases i <;> fin_cases j <;> simp [-one_smul, ← sub_smul] <;> norm_num rw [Set.pairwise_eq_iff_exists_eq] at hr obtain ⟨r, hr⟩ := hr exact (s.eq_circumcenter_of_dist_eq (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (Finset.card_fin 2)) fun i => hr i (Set.mem_univ _)).symm /-- Reindexing a simplex along an `Equiv` of index types does not change the circumsphere. -/ @[simp] theorem circumsphere_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumsphere = s.circumsphere := by refine s.circumsphere_unique_dist_eq.2 _ ⟨?_, ?_⟩ <;> rw [← s.reindex_range_points e] · exact (s.reindex e).circumsphere_unique_dist_eq.1.1 · exact (s.reindex e).circumsphere_unique_dist_eq.1.2 /-- Reindexing a simplex along an `Equiv` of index types does not change the circumcenter. -/ @[simp] theorem circumcenter_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumcenter = s.circumcenter := by simp_rw [circumcenter, circumsphere_reindex] /-- Reindexing a simplex along an `Equiv` of index types does not change the circumradius. -/ @[simp] theorem circumradius_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumradius = s.circumradius := by simp_rw [circumradius, circumsphere_reindex] theorem dist_circumcenter_sq_eq_sq_sub_circumradius {n : ℕ} {r : ℝ} (s : Simplex ℝ P n) {p₁ : P} (h₁ : ∀ i : Fin (n + 1), dist (s.points i) p₁ = r) (h₁' : ↑(s.orthogonalProjectionSpan p₁) = s.circumcenter) (h : s.points 0 ∈ affineSpan ℝ (Set.range s.points)) : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := by rw [dist_comm, ← h₁ 0, s.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₁ h] simp only [h₁', dist_comm p₁, add_sub_cancel_left, Simplex.dist_circumcenter_eq_circumradius] /-- If there exists a distance that a point has from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hr : ∃ r, ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := by change ∃ r : ℝ, ∀ i, (fun x => dist x p = r) (s.points i) at hr have hr : ∃ (r : ℝ), ∀ (a : P), a ∈ Set.range (fun (i : Fin (n + 1)) => s.points i) → dist a p = r := by obtain ⟨r, hr⟩ := hr use r refine Set.forall_mem_range.mpr ?_ exact hr rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq (subset_affineSpan ℝ _) p] at hr obtain ⟨r, hr⟩ := hr exact s.eq_circumcenter_of_dist_eq (orthogonalProjection_mem p) fun i => hr _ (Set.mem_range_self i) /-- If a point has the same distance from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := s.orthogonalProjection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩ /-- The orthogonal projection of the circumcenter onto a face is the circumcenter of that face. -/ theorem orthogonalProjection_circumcenter {n : ℕ} (s : Simplex ℝ P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) : ↑((s.face h).orthogonalProjectionSpan s.circumcenter) = (s.face h).circumcenter := haveI hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r := by use s.circumradius simp [face_points] orthogonalProjection_eq_circumcenter_of_exists_dist_eq _ hr /-- Two simplices with the same points have the same circumcenter. -/ theorem circumcenter_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.circumcenter = s₂.circumcenter := by have hs : s₁.circumcenter ∈ affineSpan ℝ (Set.range s₂.points) := h ▸ s₁.circumcenter_mem_affineSpan have hr : ∀ i, dist (s₂.points i) s₁.circumcenter = s₁.circumradius := by intro i have hi : s₂.points i ∈ Set.range s₂.points := Set.mem_range_self _ rw [← h, Set.mem_range] at hi rcases hi with ⟨j, hj⟩ rw [← hj, s₁.dist_circumcenter_eq_circumradius j] exact s₂.eq_circumcenter_of_dist_eq hs hr /-- An index type for the vertices of a simplex plus its circumcenter. This is for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. (An equivalent form sometimes used in the literature is placing the circumcenter at the origin and working with vectors for the vertices.) -/ inductive PointsWithCircumcenterIndex (n : ℕ) | pointIndex : Fin (n + 1) → PointsWithCircumcenterIndex n | circumcenterIndex : PointsWithCircumcenterIndex n deriving Fintype open PointsWithCircumcenterIndex instance pointsWithCircumcenterIndexInhabited (n : ℕ) : Inhabited (PointsWithCircumcenterIndex n) := ⟨circumcenterIndex⟩ /-- `pointIndex` as an embedding. -/ def pointIndexEmbedding (n : ℕ) : Fin (n + 1) ↪ PointsWithCircumcenterIndex n := ⟨fun i => pointIndex i, fun _ _ h => by injection h⟩ /-- The sum of a function over `PointsWithCircumcenterIndex`. -/ theorem sum_pointsWithCircumcenter {α : Type*} [AddCommMonoid α] {n : ℕ} (f : PointsWithCircumcenterIndex n → α) : ∑ i, f i = (∑ i : Fin (n + 1), f (pointIndex i)) + f circumcenterIndex := by classical have h : univ = insert circumcenterIndex (univ.map (pointIndexEmbedding n)) := by ext x refine ⟨fun h => ?_, fun _ => mem_univ _⟩ obtain i | - := x · exact mem_insert_of_mem (mem_map_of_mem _ (mem_univ i)) · exact mem_insert_self _ _ change _ = (∑ i, f (pointIndexEmbedding n i)) + _ rw [add_comm, h, ← sum_map, sum_insert] simp_rw [Finset.mem_map, not_exists] rintro x ⟨_, h⟩ injection h /-- The vertices of a simplex plus its circumcenter. -/ def pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) : PointsWithCircumcenterIndex n → P | pointIndex i => s.points i | circumcenterIndex => s.circumcenter /-- `pointsWithCircumcenter`, applied to a `pointIndex` value, equals `points` applied to that value. -/ @[simp] theorem pointsWithCircumcenter_point {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.pointsWithCircumcenter (pointIndex i) = s.points i := rfl /-- `pointsWithCircumcenter`, applied to `circumcenterIndex`, equals the circumcenter. -/ @[simp] theorem pointsWithCircumcenter_eq_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.pointsWithCircumcenter circumcenterIndex = s.circumcenter := rfl /-- The weights for a single vertex of a simplex, in terms of `pointsWithCircumcenter`. -/ def pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : PointsWithCircumcenterIndex n → ℝ | pointIndex j => if j = i then 1 else 0 | circumcenterIndex => 0 /-- `point_weights_with_circumcenter` sums to 1. -/ @[simp] theorem sum_pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : ∑ j, pointWeightsWithCircumcenter i j = 1 := by classical convert sum_ite_eq' univ (pointIndex i) (Function.const _ (1 : ℝ)) with j · cases j <;> simp [pointWeightsWithCircumcenter] · simp /-- A single vertex, in terms of `pointsWithCircumcenter`. -/ theorem point_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (pointWeightsWithCircumcenter i) := by rw [← pointsWithCircumcenter_point] symm refine affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) (by simp [pointWeightsWithCircumcenter]) ?_ intro i hi hn cases i · have h : _ ≠ i := fun h => hn (h ▸ rfl) simp [pointWeightsWithCircumcenter, h] · rfl /-- The weights for the centroid of some vertices of a simplex, in terms of `pointsWithCircumcenter`. -/ def centroidWeightsWithCircumcenter {n : ℕ} (fs : Finset (Fin (n + 1))) : PointsWithCircumcenterIndex n → ℝ | pointIndex i => if i ∈ fs then (#fs : ℝ)⁻¹ else 0 | circumcenterIndex => 0 /-- `centroidWeightsWithCircumcenter` sums to 1, if the `Finset` is nonempty. -/ @[simp] theorem sum_centroidWeightsWithCircumcenter {n : ℕ} {fs : Finset (Fin (n + 1))} (h : fs.Nonempty) : ∑ i, centroidWeightsWithCircumcenter fs i = 1 := by simp_rw [sum_pointsWithCircumcenter, centroidWeightsWithCircumcenter, add_zero, ← fs.sum_centroidWeights_eq_one_of_nonempty ℝ h, ← sum_indicator_subset _ fs.subset_univ] rcongr /-- The centroid of some vertices of a simplex, in terms of `pointsWithCircumcenter`. -/ theorem centroid_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) (fs : Finset (Fin (n + 1))) : fs.centroid ℝ s.points = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (centroidWeightsWithCircumcenter fs) := by simp_rw [centroid_def, affineCombination_apply, weightedVSubOfPoint_apply, sum_pointsWithCircumcenter, centroidWeightsWithCircumcenter, pointsWithCircumcenter_point, zero_smul, add_zero, centroidWeights, ← sum_indicator_subset_of_eq_zero (Function.const (Fin (n + 1)) (#fs : ℝ)⁻¹) (fun i wi => wi • (s.points i -ᵥ Classical.choice AddTorsor.nonempty)) fs.subset_univ fun _ => zero_smul ℝ _, Set.indicator_apply] congr /-- The weights for the circumcenter of a simplex, in terms of `pointsWithCircumcenter`. -/ def circumcenterWeightsWithCircumcenter (n : ℕ) : PointsWithCircumcenterIndex n → ℝ | pointIndex _ => 0 | circumcenterIndex => 1 /-- `circumcenterWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_circumcenterWeightsWithCircumcenter (n : ℕ) : ∑ i, circumcenterWeightsWithCircumcenter n i = 1 := by classical convert sum_ite_eq' univ circumcenterIndex (Function.const _ (1 : ℝ)) with j · cases j <;> simp [circumcenterWeightsWithCircumcenter] · simp /-- The circumcenter of a simplex, in terms of `pointsWithCircumcenter`. -/ theorem circumcenter_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (circumcenterWeightsWithCircumcenter n) := by rw [← pointsWithCircumcenter_eq_circumcenter] symm refine affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) rfl ?_ rintro ⟨i⟩ _ hn <;> tauto /-- The weights for the reflection of the circumcenter in an edge of a simplex. This definition is only valid with `i₁ ≠ i₂`. -/ def reflectionCircumcenterWeightsWithCircumcenter {n : ℕ} (i₁ i₂ : Fin (n + 1)) : PointsWithCircumcenterIndex n → ℝ | pointIndex i => if i = i₁ ∨ i = i₂ then 1 else 0 | circumcenterIndex => -1 /-- `reflectionCircumcenterWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_reflectionCircumcenterWeightsWithCircumcenter {n : ℕ} {i₁ i₂ : Fin (n + 1)} (h : i₁ ≠ i₂) : ∑ i, reflectionCircumcenterWeightsWithCircumcenter i₁ i₂ i = 1 := by simp_rw [sum_pointsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter, sum_ite, sum_const, filter_or, filter_eq'] rw [card_union_of_disjoint] · norm_num · simpa only [if_true, mem_univ, disjoint_singleton] using h /-- The reflection of the circumcenter of a simplex in an edge, in terms of `pointsWithCircumcenter`. -/ theorem reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) {i₁ i₂ : Fin (n + 1)} (h : i₁ ≠ i₂) : reflection (affineSpan ℝ (s.points '' {i₁, i₂})) s.circumcenter = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (reflectionCircumcenterWeightsWithCircumcenter i₁ i₂) := by have hc : #{i₁, i₂} = 2 := by simp [h] -- Making the next line a separate definition helps the elaborator: set W : AffineSubspace ℝ P := affineSpan ℝ (s.points '' {i₁, i₂}) have h_faces : (orthogonalProjection W s.circumcenter : P) = ↑((s.face hc).orthogonalProjectionSpan s.circumcenter) := by apply eq_orthogonalProjection_of_eq_subspace simp [W] rw [EuclideanGeometry.reflection_apply, h_faces, s.orthogonalProjection_circumcenter hc, circumcenter_eq_centroid, s.face_centroid_eq_centroid hc, centroid_eq_affineCombination_of_pointsWithCircumcenter, circumcenter_eq_affineCombination_of_pointsWithCircumcenter, ← @vsub_eq_zero_iff_eq V, affineCombination_vsub, weightedVSub_vadd_affineCombination, affineCombination_vsub, weightedVSub_apply, sum_pointsWithCircumcenter] simp_rw [Pi.sub_apply, Pi.add_apply, Pi.sub_apply, sub_smul, add_smul, sub_smul, centroidWeightsWithCircumcenter, circumcenterWeightsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter, ite_smul, zero_smul, sub_zero, apply_ite₂ (· + ·), add_zero, ← add_smul, hc, zero_sub, neg_smul, sub_self, add_zero] convert sum_const_zero norm_num end Simplex end Affine namespace EuclideanGeometry open Affine AffineSubspace Module variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- Given a nonempty affine subspace, whose direction is complete, that contains a set of points, those points are cospherical if and only if they are equidistant from some point in that subspace. -/ theorem cospherical_iff_exists_mem_of_complete {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] [s.direction.HasOrthogonalProjection] : Cospherical ps ↔ ∃ center ∈ s, ∃ radius : ℝ, ∀ p ∈ ps, dist p center = radius := by constructor · rintro ⟨c, hcr⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq h c] at hcr exact ⟨orthogonalProjection s c, orthogonalProjection_mem _, hcr⟩ · exact fun ⟨c, _, hd⟩ => ⟨c, hd⟩ /-- Given a nonempty affine subspace, whose direction is finite-dimensional, that contains a set of points, those points are cospherical if and only if they are equidistant from some point in that subspace. -/ theorem cospherical_iff_exists_mem_of_finiteDimensional {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] [FiniteDimensional ℝ s.direction] : Cospherical ps ↔ ∃ center ∈ s, ∃ radius : ℝ, ∀ p ∈ ps, dist p center = radius := cospherical_iff_exists_mem_of_complete h /-- All n-simplices among cospherical points in an n-dimensional subspace have the same circumradius. -/ theorem exists_circumradius_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) : ∃ r : ℝ, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumradius = r := by rw [cospherical_iff_exists_mem_of_finiteDimensional h] at hc rcases hc with ⟨c, hc, r, hcr⟩ use r intro sx hsxps have hsx : affineSpan ℝ (Set.range sx.points) = s := by refine sx.independent.affineSpan_eq_of_le_of_card_eq_finrank_add_one (affineSpan_le_of_subset_coe (hsxps.trans h)) ?_ simp [hd] have hc : c ∈ affineSpan ℝ (Set.range sx.points) := hsx.symm ▸ hc exact (sx.eq_circumradius_of_dist_eq hc fun i => hcr (sx.points i) (hsxps (Set.mem_range_self i))).symm /-- Two n-simplices among cospherical points in an n-dimensional subspace have the same circumradius. -/ theorem circumradius_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumradius = sx₂.circumradius := by rcases exists_circumradius_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] /-- All n-simplices among cospherical points in n-space have the same circumradius. -/ theorem exists_circumradius_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) : ∃ r : ℝ, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumradius = r := by haveI : Nonempty (⊤ : AffineSubspace ℝ P) := Set.univ.nonempty rw [← finrank_top, ← direction_top ℝ V P] at hd refine exists_circumradius_eq_of_cospherical_subset ?_ hd hc exact Set.subset_univ _ /-- Two n-simplices among cospherical points in n-space have the same circumradius. -/ theorem circumradius_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumradius = sx₂.circumradius := by rcases exists_circumradius_eq_of_cospherical hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] /-- All n-simplices among cospherical points in an n-dimensional subspace have the same circumcenter. -/ theorem exists_circumcenter_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) : ∃ c : P, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumcenter = c := by rw [cospherical_iff_exists_mem_of_finiteDimensional h] at hc rcases hc with ⟨c, hc, r, hcr⟩ use c intro sx hsxps have hsx : affineSpan ℝ (Set.range sx.points) = s := by refine sx.independent.affineSpan_eq_of_le_of_card_eq_finrank_add_one (affineSpan_le_of_subset_coe (hsxps.trans h)) ?_ simp [hd] have hc : c ∈ affineSpan ℝ (Set.range sx.points) := hsx.symm ▸ hc exact (sx.eq_circumcenter_of_dist_eq hc fun i => hcr (sx.points i) (hsxps (Set.mem_range_self i))).symm /-- Two n-simplices among cospherical points in an n-dimensional subspace have the same circumcenter. -/ theorem circumcenter_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumcenter = sx₂.circumcenter := by rcases exists_circumcenter_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] /-- All n-simplices among cospherical points in n-space have the same circumcenter. -/ theorem exists_circumcenter_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) : ∃ c : P, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumcenter = c := by haveI : Nonempty (⊤ : AffineSubspace ℝ P) := Set.univ.nonempty rw [← finrank_top, ← direction_top ℝ V P] at hd refine exists_circumcenter_eq_of_cospherical_subset ?_ hd hc exact Set.subset_univ _ /-- Two n-simplices among cospherical points in n-space have the same circumcenter. -/ theorem circumcenter_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumcenter = sx₂.circumcenter := by rcases exists_circumcenter_eq_of_cospherical hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] /-- All n-simplices among cospherical points in an n-dimensional subspace have the same circumsphere. -/ theorem exists_circumsphere_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) : ∃ c : Sphere P, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumsphere = c := by obtain ⟨r, hr⟩ := exists_circumradius_eq_of_cospherical_subset h hd hc obtain ⟨c, hc⟩ := exists_circumcenter_eq_of_cospherical_subset h hd hc exact ⟨⟨c, r⟩, fun sx hsx => Sphere.ext (hc sx hsx) (hr sx hsx)⟩ /-- Two n-simplices among cospherical points in an n-dimensional subspace have the same circumsphere. -/ theorem circumsphere_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumsphere = sx₂.circumsphere := by rcases exists_circumsphere_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] /-- All n-simplices among cospherical points in n-space have the same circumsphere. -/ theorem exists_circumsphere_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) : ∃ c : Sphere P, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumsphere = c := by haveI : Nonempty (⊤ : AffineSubspace ℝ P) := Set.univ.nonempty rw [← finrank_top, ← direction_top ℝ V P] at hd refine exists_circumsphere_eq_of_cospherical_subset ?_ hd hc exact Set.subset_univ _ /-- Two n-simplices among cospherical points in n-space have the same circumsphere. -/ theorem circumsphere_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumsphere = sx₂.circumsphere := by rcases exists_circumsphere_eq_of_cospherical hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] /-- Suppose all distances from `p₁` and `p₂` to the points of a simplex are equal, and that `p₁` and `p₂` lie in the affine span of `p` with the vertices of that simplex. Then `p₁` and `p₂` are equal or reflections of each other in the affine span of the vertices of the simplex. -/ theorem eq_or_eq_reflection_of_dist_eq {n : ℕ} {s : Simplex ℝ P n} {p p₁ p₂ : P} {r : ℝ} (hp₁ : p₁ ∈ affineSpan ℝ (insert p (Set.range s.points))) (hp₂ : p₂ ∈ affineSpan ℝ (insert p (Set.range s.points))) (h₁ : ∀ i, dist (s.points i) p₁ = r) (h₂ : ∀ i, dist (s.points i) p₂ = r) : p₁ = p₂ ∨ p₁ = reflection (affineSpan ℝ (Set.range s.points)) p₂ := by set span_s := affineSpan ℝ (Set.range s.points) have h₁' := s.orthogonalProjection_eq_circumcenter_of_dist_eq h₁ have h₂' := s.orthogonalProjection_eq_circumcenter_of_dist_eq h₂ rw [← affineSpan_insert_affineSpan, mem_affineSpan_insert_iff (orthogonalProjection_mem p)] at hp₁ hp₂ obtain ⟨r₁, p₁o, hp₁o, hp₁⟩ := hp₁ obtain ⟨r₂, p₂o, hp₂o, hp₂⟩ := hp₂ obtain rfl : ↑(s.orthogonalProjectionSpan p₁) = p₁o := by subst hp₁ exact s.coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection hp₁o rw [h₁'] at hp₁ obtain rfl : ↑(s.orthogonalProjectionSpan p₂) = p₂o := by subst hp₂ exact s.coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection hp₂o rw [h₂'] at hp₂ have h : s.points 0 ∈ span_s := mem_affineSpan ℝ (Set.mem_range_self _) have hd₁ : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := s.dist_circumcenter_sq_eq_sq_sub_circumradius h₁ h₁' h have hd₂ : dist p₂ s.circumcenter * dist p₂ s.circumcenter = r * r - s.circumradius * s.circumradius := s.dist_circumcenter_sq_eq_sq_sub_circumradius h₂ h₂' h rw [← hd₂, hp₁, hp₂, dist_eq_norm_vsub V _ s.circumcenter, dist_eq_norm_vsub V _ s.circumcenter, vadd_vsub, vadd_vsub, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, real_inner_smul_left, real_inner_smul_left, real_inner_smul_right, real_inner_smul_right, ← mul_assoc, ← mul_assoc] at hd₁ by_cases hp : p = s.orthogonalProjectionSpan p · rw [Simplex.orthogonalProjectionSpan] at hp rw [hp₁, hp₂, ← hp] simp only [true_or, smul_zero, vsub_self] · have hz : ⟪p -ᵥ orthogonalProjection span_s p, p -ᵥ orthogonalProjection span_s p⟫ ≠ 0 := by simpa only [Ne, vsub_eq_zero_iff_eq, inner_self_eq_zero] using hp rw [mul_left_inj' hz, mul_self_eq_mul_self_iff] at hd₁ rw [hp₁, hp₂] rcases hd₁ with hd₁ | hd₁ · left rw [hd₁] · right rw [hd₁, reflection_vadd_smul_vsub_orthogonalProjection p r₂ s.circumcenter_mem_affineSpan, neg_smul] end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Simplex.lean
import Mathlib.Analysis.Normed.Affine.Simplex import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine /-! # Simplices in Euclidean spaces. This file defines properties of simplices in a Euclidean space. ## Main definitions * `Affine.Simplex.AcuteAngled` -/ namespace Affine open EuclideanGeometry open scoped Real variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] namespace Simplex variable {m n : ℕ} lemma Equilateral.angle_eq_pi_div_three {s : Simplex ℝ P n} (he : s.Equilateral) {i₁ i₂ i₃ : Fin (n + 1)} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : ∠ (s.points i₁) (s.points i₂) (s.points i₃) = π / 3 := by rcases he with ⟨r, hr⟩ rw [angle, InnerProductGeometry.angle, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] refine Real.arccos_eq_of_eq_cos (by linarith [Real.pi_nonneg]) (by linarith [Real.pi_nonneg]) ?_ simp only [vsub_sub_vsub_cancel_right, ← dist_eq_norm_vsub, hr _ _ h₁₂, hr _ _ h₁₃, hr _ _ h₂₃.symm, Real.cos_pi_div_three] have hr0 : r ≠ 0 := by rintro rfl replace hr := hr _ _ h₁₂ rw [dist_eq_zero] at hr exact h₁₂ (s.independent.injective hr) field /-- The property of all angles of a simplex being acute. -/ def AcuteAngled (s : Simplex ℝ P n) : Prop := ∀ i₁ i₂ i₃ : Fin (n + 1), i₁ ≠ i₂ → i₁ ≠ i₃ → i₂ ≠ i₃ → ∠ (s.points i₁) (s.points i₂) (s.points i₃) < π / 2 @[simp] lemma acuteAngled_reindex_iff {s : Simplex ℝ P m} (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).AcuteAngled ↔ s.AcuteAngled := by refine ⟨fun h {i₁ i₂ i₃} h₁₂ h₁₃ h₂₃ ↦ ?_, fun h {i₁ i₂ i₃} h₁₂ h₁₃ h₂₃ ↦ ?_⟩ · convert h (i₁ := e i₁) (i₂ := e i₂) (i₃ := e i₃) ?_ ?_ ?_ using 1 <;> simp [*] · convert h (i₁ := e.symm i₁) (i₂ := e.symm i₂) (i₃ := e.symm i₃) ?_ ?_ ?_ using 1 <;> simp [*] lemma Equilateral.acuteAngled {s : Simplex ℝ P n} (he : s.Equilateral) : s.AcuteAngled := by intro i₁ i₂ i₃ h₁₂ h₁₃ h₂₃ rw [he.angle_eq_pi_div_three h₁₂ h₁₃ h₂₃] linarith [Real.pi_pos] end Simplex namespace Triangle lemma acuteAngled_iff_angle_lt {t : Triangle ℝ P} : t.AcuteAngled ↔ ∠ (t.points 0) (t.points 1) (t.points 2) < π / 2 ∧ ∠ (t.points 1) (t.points 2) (t.points 0) < π / 2 ∧ ∠ (t.points 2) (t.points 0) (t.points 1) < π / 2 := by refine ⟨fun h ↦ ⟨h _ _ _ (by decide) (by decide) (by decide), h _ _ _ (by decide) (by decide) (by decide), h _ _ _ (by decide) (by decide) (by decide)⟩, fun ⟨h012, h120, h201⟩ ↦ ?_⟩ have h210 := angle_comm (t.points 0) _ _ ▸ h012 have h021 := angle_comm (t.points 1) _ _ ▸ h120 have h102 := angle_comm (t.points 2) _ _ ▸ h201 intro i₁ i₂ i₃ h₁₂ h₁₃ h₂₃ fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃ <;> simp [*] at * end Triangle end Affine
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/MongePoint.lean
import Mathlib.Geometry.Euclidean.Altitude import Mathlib.Geometry.Euclidean.Circumcenter /-! # Monge point and orthocenter This file defines the orthocenter of a triangle, via its n-dimensional generalization, the Monge point of a simplex. ## Main definitions * `mongePoint` is the Monge point of a simplex, defined in terms of its position on the Euler line and then shown to be the point of concurrence of the Monge planes. * `mongePlane` is a Monge plane of an (n+2)-simplex, which is the (n+1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an n-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). * `orthocenter` is defined, for the case of a triangle, to be the same as its Monge point, then shown to be the point of concurrence of the altitudes. * `OrthocentricSystem` is a predicate on sets of points that says whether they are four points, one of which is the orthocenter of the other three (in which case various other properties hold, including that each is the orthocenter of the other three). ## References * <https://en.wikipedia.org/wiki/Monge_point> * <https://en.wikipedia.org/wiki/Orthocentric_system> * Małgorzata Buba-Brzozowa, [The Monge Point and the 3(n+1) Point Sphere of an n-Simplex](https://pdfs.semanticscholar.org/6f8b/0f623459c76dac2e49255737f8f0f4725d16.pdf) -/ noncomputable section open scoped RealInnerProductSpace namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry PointsWithCircumcenterIndex variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The Monge point of a simplex (in 2 or more dimensions) is a generalization of the orthocenter of a triangle. It is defined to be the intersection of the Monge planes, where a Monge plane is the (n-1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an (n-2)-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). The circumcenter O, centroid G and Monge point M are collinear in that order on the Euler line, with OG : GM = (n-1): 2. Here, we use that ratio to define the Monge point (so resulting in a point that equals the centroid in 0 or 1 dimensions), and then show in subsequent lemmas that the point so defined lies in the Monge planes and is their unique point of intersection. -/ def mongePoint {n : ℕ} (s : Simplex ℝ P n) : P := (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter /-- The position of the Monge point in relation to the circumcenter and centroid. -/ theorem mongePoint_eq_smul_vsub_vadd_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint = (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter := rfl /-- **Sylvester's theorem**: The position of the Monge point relative to the circumcenter via the sum of vectors to the vertices. -/ theorem smul_mongePoint_vsub_circumcenter_eq_sum_vsub {n : ℕ} (s : Simplex ℝ P (n + 2)) : (n + 1) • (s.mongePoint -ᵥ s.circumcenter) = ∑ i, (s.points i -ᵥ s.circumcenter) := by rw [mongePoint_eq_smul_vsub_vadd_circumcenter, vadd_vsub, ← smul_assoc] simp only [Nat.cast_add, Nat.cast_ofNat, Nat.cast_one, Nat.add_one_sub_one, nsmul_eq_mul] field_simp have h : Invertible (n + 2 + 1 : ℝ) := by norm_cast; apply invertibleOfPos rw [smul_eq_iff_eq_invOf_smul, smul_sum] unfold Finset.centroid rw [← Finset.sum_smul_vsub_const_eq_affineCombination_vsub _ _ _ _ (by simp)] simp only [centroidWeights_apply, card_univ, Fintype.card_fin, Nat.cast_add, Nat.cast_ofNat, Nat.cast_one, invOf_eq_inv] /-- The Monge point lies in the affine span. -/ theorem mongePoint_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint ∈ affineSpan ℝ (Set.range s.points) := smul_vsub_vadd_mem _ _ (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (card_fin (n + 1))) s.circumcenter_mem_affineSpan s.circumcenter_mem_affineSpan /-- Two simplices with the same points have the same Monge point. -/ theorem mongePoint_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.mongePoint = s₂.mongePoint := by simp_rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_of_range_eq h, circumcenter_eq_of_range_eq h] /-- The weights for the Monge point of an (n+2)-simplex, in terms of `pointsWithCircumcenter`. -/ def mongePointWeightsWithCircumcenter (n : ℕ) : PointsWithCircumcenterIndex (n + 2) → ℝ | pointIndex _ => ((n + 1 : ℕ) : ℝ)⁻¹ | circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ) /-- `mongePointWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_mongePointWeightsWithCircumcenter (n : ℕ) : ∑ i, mongePointWeightsWithCircumcenter n i = 1 := by simp_rw [sum_pointsWithCircumcenter, mongePointWeightsWithCircumcenter, sum_const, card_fin, nsmul_eq_mul] simp [field] ring /-- The Monge point of an (n+2)-simplex, in terms of `pointsWithCircumcenter`. -/ theorem mongePoint_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P (n + 2)) : s.mongePoint = (univ : Finset (PointsWithCircumcenterIndex (n + 2))).affineCombination ℝ s.pointsWithCircumcenter (mongePointWeightsWithCircumcenter n) := by rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_affineCombination_of_pointsWithCircumcenter, circumcenter_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub, ← LinearMap.map_smul, weightedVSub_vadd_affineCombination] congr with i rw [Pi.add_apply, Pi.smul_apply, smul_eq_mul, Pi.sub_apply] cases i <;> simp_rw [centroidWeightsWithCircumcenter, circumcenterWeightsWithCircumcenter, mongePointWeightsWithCircumcenter] <;> rw [add_tsub_assoc_of_le (by decide : 1 ≤ 2), (by decide : 2 - 1 = 1)] · rw [if_pos (mem_univ _), card_fin] field · simp [field] ring /-- The weights for the Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, in terms of `pointsWithCircumcenter`. This definition is only valid when `i₁ ≠ i₂`. -/ def mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} (i₁ i₂ : Fin (n + 3)) : PointsWithCircumcenterIndex (n + 2) → ℝ | pointIndex i => if i = i₁ ∨ i = i₂ then ((n + 1 : ℕ) : ℝ)⁻¹ else 0 | circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ) /-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` is the result of subtracting `centroidWeightsWithCircumcenter` from `mongePointWeightsWithCircumcenter`. -/ theorem mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub {n : ℕ} {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ = mongePointWeightsWithCircumcenter n - centroidWeightsWithCircumcenter {i₁, i₂}ᶜ := by ext i obtain i | i := i · rw [Pi.sub_apply, mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter, mongePointVSubFaceCentroidWeightsWithCircumcenter] have hu : #{i₁, i₂}ᶜ = n + 1 := by simp [card_compl, Fintype.card_fin, h] rw [hu] by_cases hi : i = i₁ ∨ i = i₂ <;> simp [compl_eq_univ_sdiff, hi] · simp [mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter, mongePointVSubFaceCentroidWeightsWithCircumcenter] /-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` sums to 0. -/ @[simp] theorem sum_mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : ∑ i, mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ i = 0 := by rw [mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h] simp_rw [Pi.sub_apply, sum_sub_distrib, sum_mongePointWeightsWithCircumcenter] rw [sum_centroidWeightsWithCircumcenter, sub_self] simp [← card_pos, card_compl, h] /-- The Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, in terms of `pointsWithCircumcenter`. -/ theorem mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points = (univ : Finset (PointsWithCircumcenterIndex (n + 2))).weightedVSub s.pointsWithCircumcenter (mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂) := by simp_rw [mongePoint_eq_affineCombination_of_pointsWithCircumcenter, centroid_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub, mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h] /-- The Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, is orthogonal to the difference of the two vertices not in that face. -/ theorem inner_mongePoint_vsub_face_centroid_vsub {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : ⟪s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points, s.points i₁ -ᵥ s.points i₂⟫ = 0 := by by_cases h : i₁ = i₂ · simp [h] simp_rw [mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter s h, point_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub] have hs : ∑ i, (pointWeightsWithCircumcenter i₁ - pointWeightsWithCircumcenter i₂) i = 0 := by simp rw [inner_weightedVSub _ (sum_mongePointVSubFaceCentroidWeightsWithCircumcenter h) _ hs, sum_pointsWithCircumcenter, pointsWithCircumcenter_eq_circumcenter] simp only [mongePointVSubFaceCentroidWeightsWithCircumcenter, pointsWithCircumcenter_point] let fs : Finset (Fin (n + 3)) := {i₁, i₂} have hfs : ∀ i : Fin (n + 3), i ∉ fs → i ≠ i₁ ∧ i ≠ i₂ := by intro i hi constructor <;> · intro hj; simp [fs, ← hj] at hi rw [← sum_subset fs.subset_univ _] · simp_rw [sum_pointsWithCircumcenter, pointsWithCircumcenter_eq_circumcenter, pointsWithCircumcenter_point, Pi.sub_apply, pointWeightsWithCircumcenter] rw [← sum_subset fs.subset_univ _] · simp_rw [fs, sum_insert (notMem_singleton.2 h), sum_singleton] repeat rw [← sum_subset fs.subset_univ _] · simp_rw [fs, sum_insert (notMem_singleton.2 h), sum_singleton] simp [h, Ne.symm h, dist_comm (s.points i₁)] all_goals intro i _ hi; simp [hfs i hi] · intro i _ hi simp [hfs i hi] · intro i _ hi simp [hfs i hi] /-- A Monge plane of an (n+2)-simplex is the (n+1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an n-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). This definition is only intended to be used when `i₁ ≠ i₂`. -/ def mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : AffineSubspace ℝ P := mk' (({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points) (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ affineSpan ℝ (Set.range s.points) /-- The definition of a Monge plane. -/ theorem mongePlane_def {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : s.mongePlane i₁ i₂ = mk' (({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points) (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ affineSpan ℝ (Set.range s.points) := rfl /-- The Monge plane associated with vertices `i₁` and `i₂` equals that associated with `i₂` and `i₁`. -/ theorem mongePlane_comm {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : s.mongePlane i₁ i₂ = s.mongePlane i₂ i₁ := by simp_rw [mongePlane_def] congr 3 · congr 1 exact pair_comm _ _ · ext simp_rw [Submodule.mem_span_singleton] constructor all_goals rintro ⟨r, rfl⟩; use -r; rw [neg_smul, ← smul_neg, neg_vsub_eq_vsub_rev] /-- The Monge point lies in the Monge planes. -/ theorem mongePoint_mem_mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : s.mongePoint ∈ s.mongePlane i₁ i₂ := by rw [mongePlane_def, mem_inf_iff, ← vsub_right_mem_direction_iff_mem (self_mem_mk' _ _), direction_mk', Submodule.mem_orthogonal'] refine ⟨?_, s.mongePoint_mem_affineSpan⟩ intro v hv rcases Submodule.mem_span_singleton.mp hv with ⟨r, rfl⟩ rw [inner_smul_right, s.inner_mongePoint_vsub_face_centroid_vsub, mul_zero] /-- The direction of a Monge plane. -/ theorem direction_mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : (s.mongePlane i₁ i₂).direction = (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by rw [mongePlane_def, direction_inf_of_mem_inf s.mongePoint_mem_mongePlane, direction_mk', direction_affineSpan] /-- The Monge point is the only point in all the Monge planes from any one vertex. -/ theorem eq_mongePoint_of_forall_mem_mongePlane {n : ℕ} {s : Simplex ℝ P (n + 2)} {i₁ : Fin (n + 3)} {p : P} (h : ∀ i₂, i₁ ≠ i₂ → p ∈ s.mongePlane i₁ i₂) : p = s.mongePoint := by rw [← @vsub_eq_zero_iff_eq V] have h' : ∀ i₂, i₁ ≠ i₂ → p -ᵥ s.mongePoint ∈ (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by intro i₂ hne rw [← s.direction_mongePlane, vsub_right_mem_direction_iff_mem s.mongePoint_mem_mongePlane] exact h i₂ hne have hi : p -ᵥ s.mongePoint ∈ ⨅ i₂ : { i // i₁ ≠ i }, (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ := by rw [Submodule.mem_iInf] exact fun i => (Submodule.mem_inf.1 (h' i i.property)).1 rw [Submodule.iInf_orthogonal, ← Submodule.span_iUnion] at hi have hu : ⋃ i : { i // i₁ ≠ i }, ({s.points i₁ -ᵥ s.points i} : Set V) = (s.points i₁ -ᵥ ·) '' (s.points '' (Set.univ \ {i₁})) := by rw [Set.image_image] ext x simp_rw [Set.mem_iUnion, Set.mem_image, Set.mem_singleton_iff, Set.mem_diff_singleton] constructor · rintro ⟨i, rfl⟩ use i, ⟨Set.mem_univ _, i.property.symm⟩ · rintro ⟨i, ⟨-, hi⟩, rfl⟩ use ⟨i, hi.symm⟩ rw [hu, ← vectorSpan_image_eq_span_vsub_set_left_ne ℝ _ (Set.mem_univ _), Set.image_univ] at hi have hv : p -ᵥ s.mongePoint ∈ vectorSpan ℝ (Set.range s.points) := by let s₁ : Finset (Fin (n + 3)) := univ.erase i₁ obtain ⟨i₂, h₂⟩ := card_pos.1 (show 0 < #s₁ by simp [s₁, card_erase_of_mem]) have h₁₂ : i₁ ≠ i₂ := (ne_of_mem_erase h₂).symm exact (Submodule.mem_inf.1 (h' i₂ h₁₂)).2 exact Submodule.disjoint_def.1 (vectorSpan ℝ (Set.range s.points)).orthogonal_disjoint _ hv hi end Simplex namespace Triangle open EuclideanGeometry Finset Simplex AffineSubspace Module variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The orthocenter of a triangle is the intersection of its altitudes. It is defined here as the 2-dimensional case of the Monge point. -/ def orthocenter (t : Triangle ℝ P) : P := t.mongePoint /-- The orthocenter equals the Monge point. -/ theorem orthocenter_eq_mongePoint (t : Triangle ℝ P) : t.orthocenter = t.mongePoint := rfl /-- The position of the orthocenter in relation to the circumcenter and centroid. -/ theorem orthocenter_eq_smul_vsub_vadd_circumcenter (t : Triangle ℝ P) : t.orthocenter = (3 : ℝ) • ((univ : Finset (Fin 3)).centroid ℝ t.points -ᵥ t.circumcenter : V) +ᵥ t.circumcenter := by rw [orthocenter_eq_mongePoint, mongePoint_eq_smul_vsub_vadd_circumcenter] simp /-- **Sylvester's theorem**, specialized to triangles. -/ theorem orthocenter_vsub_circumcenter_eq_sum_vsub (t : Triangle ℝ P) : t.orthocenter -ᵥ t.circumcenter = ∑ i, (t.points i -ᵥ t.circumcenter) := by rw [← t.smul_mongePoint_vsub_circumcenter_eq_sum_vsub, zero_add, one_smul, orthocenter_eq_mongePoint] /-- The orthocenter lies in the affine span. -/ theorem orthocenter_mem_affineSpan (t : Triangle ℝ P) : t.orthocenter ∈ affineSpan ℝ (Set.range t.points) := t.mongePoint_mem_affineSpan /-- Two triangles with the same points have the same orthocenter. -/ theorem orthocenter_eq_of_range_eq {t₁ t₂ : Triangle ℝ P} (h : Set.range t₁.points = Set.range t₂.points) : t₁.orthocenter = t₂.orthocenter := mongePoint_eq_of_range_eq h /-- In the case of a triangle, altitudes are the same thing as Monge planes. -/ theorem altitude_eq_mongePlane (t : Triangle ℝ P) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : t.altitude i₁ = t.mongePlane i₂ i₃ := by have hs : ({i₂, i₃}ᶜ : Finset (Fin 3)) = {i₁} := by decide +revert have he : ({i₁}ᶜ : Set (Fin 3)) = {i₂, i₃} := by ext; decide +revert rw [mongePlane_def, altitude_def, direction_affineSpan, hs, he, centroid_singleton, vectorSpan_image_eq_span_vsub_set_left_ne ℝ _ (Set.mem_insert i₂ _)] simp [h₂₃] /-- The orthocenter lies in the altitudes. -/ theorem orthocenter_mem_altitude (t : Triangle ℝ P) {i₁ : Fin 3} : t.orthocenter ∈ t.altitude i₁ := by obtain ⟨i₂, i₃, h₁₂, h₂₃, h₁₃⟩ : ∃ i₂ i₃, i₁ ≠ i₂ ∧ i₂ ≠ i₃ ∧ i₁ ≠ i₃ := by decide +revert rw [orthocenter_eq_mongePoint, t.altitude_eq_mongePlane h₁₂ h₁₃ h₂₃] exact t.mongePoint_mem_mongePlane /-- The orthocenter is the only point lying in any two of the altitudes. -/ theorem eq_orthocenter_of_forall_mem_altitude {t : Triangle ℝ P} {i₁ i₂ : Fin 3} {p : P} (h₁₂ : i₁ ≠ i₂) (h₁ : p ∈ t.altitude i₁) (h₂ : p ∈ t.altitude i₂) : p = t.orthocenter := by obtain ⟨i₃, h₂₃, h₁₃⟩ : ∃ i₃, i₂ ≠ i₃ ∧ i₁ ≠ i₃ := by clear h₁ h₂ decide +revert rw [t.altitude_eq_mongePlane h₁₃ h₁₂ h₂₃.symm] at h₁ rw [t.altitude_eq_mongePlane h₂₃ h₁₂.symm h₁₃.symm] at h₂ rw [orthocenter_eq_mongePoint] have ha : ∀ i, i₃ ≠ i → p ∈ t.mongePlane i₃ i := by intro i hi obtain rfl | rfl : i₁ = i ∨ i₂ = i := by cutsat all_goals assumption exact eq_mongePoint_of_forall_mem_mongePlane ha /-- The distance from the orthocenter to the reflection of the circumcenter in a side equals the circumradius. -/ theorem dist_orthocenter_reflection_circumcenter (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) : dist t.orthocenter (reflection (affineSpan ℝ (t.points '' {i₁, i₂})) t.circumcenter) = t.circumradius := by rw [← mul_self_inj_of_nonneg dist_nonneg t.circumradius_nonneg, t.reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter h, t.orthocenter_eq_mongePoint, mongePoint_eq_affineCombination_of_pointsWithCircumcenter, dist_affineCombination t.pointsWithCircumcenter (sum_mongePointWeightsWithCircumcenter _) (sum_reflectionCircumcenterWeightsWithCircumcenter h)] simp_rw [sum_pointsWithCircumcenter, Pi.sub_apply, mongePointWeightsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter] have hu : ({i₁, i₂} : Finset (Fin 3)) ⊆ univ := subset_univ _ obtain ⟨i₃, hi₃, hi₃₁, hi₃₂⟩ : ∃ i₃, univ \ ({i₁, i₂} : Finset (Fin 3)) = {i₃} ∧ i₃ ≠ i₁ ∧ i₃ ≠ i₂ := by decide +revert simp_rw [← sum_sdiff hu, hi₃] norm_num [hi₃₁, hi₃₂] /-- The distance from the orthocenter to the reflection of the circumcenter in a side equals the circumradius, variant using a `Finset`. -/ theorem dist_orthocenter_reflection_circumcenter_finset (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) : dist t.orthocenter (reflection (affineSpan ℝ (t.points '' ↑({i₁, i₂} : Finset (Fin 3)))) t.circumcenter) = t.circumradius := by simp only [coe_insert, coe_singleton] exact dist_orthocenter_reflection_circumcenter _ h /-- The distance from the circumcenter to the reflection of the orthocenter in a side equals the circumradius. -/ theorem dist_circumcenter_reflection_orthocenter (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) : dist t.circumcenter (reflection (affineSpan ℝ (t.points '' {i₁, i₂})) t.orthocenter) = t.circumradius := by rw [EuclideanGeometry.dist_reflection, dist_comm, dist_orthocenter_reflection_circumcenter t h] /-- The distance from the circumcenter to the reflection of the orthocenter in a side equals the circumradius, variant using a `Finset`. -/ theorem dist_circumcenter_reflection_orthocenter_finset (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) : dist t.circumcenter (reflection (affineSpan ℝ (t.points '' ↑({i₁, i₂} : Finset (Fin 3)))) t.orthocenter) = t.circumradius := by simp only [coe_insert, coe_singleton] exact dist_circumcenter_reflection_orthocenter _ h /-- The affine span of the orthocenter and a vertex is contained in the altitude. -/ theorem affineSpan_orthocenter_point_le_altitude (t : Triangle ℝ P) (i : Fin 3) : line[ℝ, t.orthocenter, t.points i] ≤ t.altitude i := by refine affineSpan_le_of_subset_coe ?_ rw [Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨t.orthocenter_mem_altitude, t.mem_altitude i⟩ /-- Suppose we are given a triangle `t₁`, and replace one of its vertices by its orthocenter, yielding triangle `t₂` (with vertices not necessarily listed in the same order). Then an altitude of `t₂` from a vertex that was not replaced is the corresponding side of `t₁`. -/ theorem altitude_replace_orthocenter_eq_affineSpan {t₁ t₂ : Triangle ℝ P} {i₁ i₂ i₃ j₁ j₂ j₃ : Fin 3} (hi₁₂ : i₁ ≠ i₂) (hi₁₃ : i₁ ≠ i₃) (hi₂₃ : i₂ ≠ i₃) (hj₁₂ : j₁ ≠ j₂) (hj₁₃ : j₁ ≠ j₃) (hj₂₃ : j₂ ≠ j₃) (h₁ : t₂.points j₁ = t₁.orthocenter) (h₂ : t₂.points j₂ = t₁.points i₂) (h₃ : t₂.points j₃ = t₁.points i₃) : t₂.altitude j₂ = line[ℝ, t₁.points i₁, t₁.points i₂] := by symm rw [← h₂, t₂.affineSpan_pair_eq_altitude_iff] rw [h₂] use t₁.independent.injective.ne hi₁₂ have he : affineSpan ℝ (Set.range t₂.points) = affineSpan ℝ (Set.range t₁.points) := by refine ext_of_direction_eq ?_ ⟨t₁.points i₃, mem_affineSpan ℝ ⟨j₃, h₃⟩, mem_affineSpan ℝ (Set.mem_range_self _)⟩ refine Submodule.eq_of_le_of_finrank_eq (direction_le (affineSpan_le_of_subset_coe ?_)) ?_ · have hu : (Set.univ : Set (Fin 3)) = {j₁, j₂, j₃} := by clear h₁ h₂ h₃ ext decide +revert rw [← Set.image_univ, hu, Set.image_insert_eq, Set.image_insert_eq, Set.image_singleton, h₁, h₂, h₃, Set.insert_subset_iff, Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨t₁.orthocenter_mem_affineSpan, mem_affineSpan ℝ (Set.mem_range_self _), mem_affineSpan ℝ (Set.mem_range_self _)⟩ · rw [direction_affineSpan, direction_affineSpan, t₁.independent.finrank_vectorSpan (Fintype.card_fin _), t₂.independent.finrank_vectorSpan (Fintype.card_fin _)] rw [he] use mem_affineSpan ℝ (Set.mem_range_self _) have hu : ({j₂}ᶜ : Set _) = {j₁, j₃} := by clear h₁ h₂ h₃ ext decide +revert rw [hu, Set.image_insert_eq, Set.image_singleton, h₁, h₃] have hle : (t₁.altitude i₃).directionᗮ ≤ line[ℝ, t₁.orthocenter, t₁.points i₃].directionᗮ := Submodule.orthogonal_le (direction_le (affineSpan_orthocenter_point_le_altitude _ _)) refine hle ((t₁.vectorSpan_isOrtho_altitude_direction i₃) ?_) have hui : ({i₃}ᶜ : Set _) = {i₁, i₂} := by clear hle h₂ h₃ ext decide +revert rw [hui, Set.image_insert_eq, Set.image_singleton] exact vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_singleton _)) /-- Suppose we are given a triangle `t₁`, and replace one of its vertices by its orthocenter, yielding triangle `t₂` (with vertices not necessarily listed in the same order). Then the orthocenter of `t₂` is the vertex of `t₁` that was replaced. -/ theorem orthocenter_replace_orthocenter_eq_point {t₁ t₂ : Triangle ℝ P} {i₁ i₂ i₃ j₁ j₂ j₃ : Fin 3} (hi₁₂ : i₁ ≠ i₂) (hi₁₃ : i₁ ≠ i₃) (hi₂₃ : i₂ ≠ i₃) (hj₁₂ : j₁ ≠ j₂) (hj₁₃ : j₁ ≠ j₃) (hj₂₃ : j₂ ≠ j₃) (h₁ : t₂.points j₁ = t₁.orthocenter) (h₂ : t₂.points j₂ = t₁.points i₂) (h₃ : t₂.points j₃ = t₁.points i₃) : t₂.orthocenter = t₁.points i₁ := by refine (Triangle.eq_orthocenter_of_forall_mem_altitude hj₂₃ ?_ ?_).symm · rw [altitude_replace_orthocenter_eq_affineSpan hi₁₂ hi₁₃ hi₂₃ hj₁₂ hj₁₃ hj₂₃ h₁ h₂ h₃] exact mem_affineSpan ℝ (Set.mem_insert _ _) · rw [altitude_replace_orthocenter_eq_affineSpan hi₁₃ hi₁₂ hi₂₃.symm hj₁₃ hj₁₂ hj₂₃.symm h₁ h₃ h₂] exact mem_affineSpan ℝ (Set.mem_insert _ _) end Triangle end Affine namespace EuclideanGeometry open Affine AffineSubspace Module variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- Four points form an orthocentric system if they consist of the vertices of a triangle and its orthocenter. -/ def OrthocentricSystem (s : Set P) : Prop := ∃ t : Triangle ℝ P, t.orthocenter ∉ Set.range t.points ∧ s = insert t.orthocenter (Set.range t.points) /-- This is an auxiliary lemma giving information about the relation of two triangles in an orthocentric system; it abstracts some reasoning, with no geometric content, that is common to some other lemmas. Suppose the orthocentric system is generated by triangle `t`, and we are given three points `p` in the orthocentric system. Then either we can find indices `i₁`, `i₂` and `i₃` for `p` such that `p i₁` is the orthocenter of `t` and `p i₂` and `p i₃` are points `j₂` and `j₃` of `t`, or `p` has the same points as `t`. -/ theorem exists_of_range_subset_orthocentricSystem {t : Triangle ℝ P} (ho : t.orthocenter ∉ Set.range t.points) {p : Fin 3 → P} (hps : Set.range p ⊆ insert t.orthocenter (Set.range t.points)) (hpi : Function.Injective p) : (∃ i₁ i₂ i₃ j₂ j₃ : Fin 3, i₁ ≠ i₂ ∧ i₁ ≠ i₃ ∧ i₂ ≠ i₃ ∧ (∀ i : Fin 3, i = i₁ ∨ i = i₂ ∨ i = i₃) ∧ p i₁ = t.orthocenter ∧ j₂ ≠ j₃ ∧ t.points j₂ = p i₂ ∧ t.points j₃ = p i₃) ∨ Set.range p = Set.range t.points := by by_cases h : t.orthocenter ∈ Set.range p · left rcases h with ⟨i₁, h₁⟩ obtain ⟨i₂, i₃, h₁₂, h₁₃, h₂₃, h₁₂₃⟩ : ∃ i₂ i₃ : Fin 3, i₁ ≠ i₂ ∧ i₁ ≠ i₃ ∧ i₂ ≠ i₃ ∧ ∀ i : Fin 3, i = i₁ ∨ i = i₂ ∨ i = i₃ := by clear h₁ decide +revert have h : ∀ i, i₁ ≠ i → ∃ j : Fin 3, t.points j = p i := by intro i hi replace hps := Set.mem_of_mem_insert_of_ne (Set.mem_of_mem_of_subset (Set.mem_range_self i) hps) (h₁ ▸ hpi.ne hi.symm) exact hps rcases h i₂ h₁₂ with ⟨j₂, h₂⟩ rcases h i₃ h₁₃ with ⟨j₃, h₃⟩ have hj₂₃ : j₂ ≠ j₃ := by intro he rw [he, h₃] at h₂ exact h₂₃.symm (hpi h₂) exact ⟨i₁, i₂, i₃, j₂, j₃, h₁₂, h₁₃, h₂₃, h₁₂₃, h₁, hj₂₃, h₂, h₃⟩ · right have hs := Set.subset_diff_singleton hps h rw [Set.insert_diff_self_of_notMem ho] at hs classical refine Set.eq_of_subset_of_card_le hs ?_ rw [Set.card_range_of_injective hpi, Set.card_range_of_injective t.independent.injective] /-- For any three points in an orthocentric system generated by triangle `t`, there is a point in the subspace spanned by the triangle from which the distance of all those three points equals the circumradius. -/ theorem exists_dist_eq_circumradius_of_subset_insert_orthocenter {t : Triangle ℝ P} (ho : t.orthocenter ∉ Set.range t.points) {p : Fin 3 → P} (hps : Set.range p ⊆ insert t.orthocenter (Set.range t.points)) (hpi : Function.Injective p) : ∃ c ∈ affineSpan ℝ (Set.range t.points), ∀ p₁ ∈ Set.range p, dist p₁ c = t.circumradius := by rcases exists_of_range_subset_orthocentricSystem ho hps hpi with (⟨i₁, i₂, i₃, j₂, j₃, _, _, _, h₁₂₃, h₁, hj₂₃, h₂, h₃⟩ | hs) · use reflection (affineSpan ℝ (t.points '' {j₂, j₃})) t.circumcenter, reflection_mem_of_le_of_mem (affineSpan_mono ℝ (Set.image_subset_range _ _)) t.circumcenter_mem_affineSpan intro p₁ hp₁ rcases hp₁ with ⟨i, rfl⟩ have h₁₂₃ := h₁₂₃ i repeat' rcases h₁₂₃ with h₁₂₃ | h₁₂₃ · convert Triangle.dist_orthocenter_reflection_circumcenter t hj₂₃ · rw [← h₂, dist_reflection_eq_of_mem _ (mem_affineSpan ℝ (Set.mem_image_of_mem _ (Set.mem_insert _ _)))] exact t.dist_circumcenter_eq_circumradius _ · rw [← h₃, dist_reflection_eq_of_mem _ (mem_affineSpan ℝ (Set.mem_image_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _))))] exact t.dist_circumcenter_eq_circumradius _ · use t.circumcenter, t.circumcenter_mem_affineSpan intro p₁ hp₁ rw [hs] at hp₁ rcases hp₁ with ⟨i, rfl⟩ exact t.dist_circumcenter_eq_circumradius _ /-- Any three points in an orthocentric system are affinely independent. -/ theorem OrthocentricSystem.affineIndependent {s : Set P} (ho : OrthocentricSystem s) {p : Fin 3 → P} (hps : Set.range p ⊆ s) (hpi : Function.Injective p) : AffineIndependent ℝ p := by rcases ho with ⟨t, hto, hst⟩ rw [hst] at hps rcases exists_dist_eq_circumradius_of_subset_insert_orthocenter hto hps hpi with ⟨c, _, hc⟩ exact Cospherical.affineIndependent ⟨c, t.circumradius, hc⟩ Set.Subset.rfl hpi /-- Any three points in an orthocentric system span the same subspace as the whole orthocentric system. -/ theorem affineSpan_of_orthocentricSystem {s : Set P} (ho : OrthocentricSystem s) {p : Fin 3 → P} (hps : Set.range p ⊆ s) (hpi : Function.Injective p) : affineSpan ℝ (Set.range p) = affineSpan ℝ s := by have ha := ho.affineIndependent hps hpi rcases ho with ⟨t, _, hts⟩ have hs : affineSpan ℝ s = affineSpan ℝ (Set.range t.points) := by rw [hts, affineSpan_insert_eq_affineSpan ℝ t.orthocenter_mem_affineSpan] refine ext_of_direction_eq ?_ ⟨p 0, mem_affineSpan ℝ (Set.mem_range_self _), mem_affineSpan ℝ (hps (Set.mem_range_self _))⟩ have hfd : FiniteDimensional ℝ (affineSpan ℝ s).direction := by rw [hs]; infer_instance refine Submodule.eq_of_le_of_finrank_eq (direction_le (affineSpan_mono ℝ hps)) ?_ rw [hs, direction_affineSpan, direction_affineSpan, ha.finrank_vectorSpan (Fintype.card_fin _), t.independent.finrank_vectorSpan (Fintype.card_fin _)] /-- All triangles in an orthocentric system have the same circumradius. -/ theorem OrthocentricSystem.exists_circumradius_eq {s : Set P} (ho : OrthocentricSystem s) : ∃ r : ℝ, ∀ t : Triangle ℝ P, Set.range t.points ⊆ s → t.circumradius = r := by rcases ho with ⟨t, hto, hts⟩ use t.circumradius intro t₂ ht₂ have ht₂s := ht₂ rw [hts] at ht₂ rcases exists_dist_eq_circumradius_of_subset_insert_orthocenter hto ht₂ t₂.independent.injective with ⟨c, hc, h⟩ rw [Set.forall_mem_range] at h have hs : Set.range t.points ⊆ s := by rw [hts] exact Set.subset_insert _ _ rw [affineSpan_of_orthocentricSystem ⟨t, hto, hts⟩ hs t.independent.injective, ← affineSpan_of_orthocentricSystem ⟨t, hto, hts⟩ ht₂s t₂.independent.injective] at hc exact (t₂.eq_circumradius_of_dist_eq hc h).symm /-- Given any triangle in an orthocentric system, the fourth point is its orthocenter. -/ theorem OrthocentricSystem.eq_insert_orthocenter {s : Set P} (ho : OrthocentricSystem s) {t : Triangle ℝ P} (ht : Set.range t.points ⊆ s) : s = insert t.orthocenter (Set.range t.points) := by rcases ho with ⟨t₀, ht₀o, ht₀s⟩ rw [ht₀s] at ht rcases exists_of_range_subset_orthocentricSystem ht₀o ht t.independent.injective with (⟨i₁, i₂, i₃, j₂, j₃, h₁₂, h₁₃, h₂₃, h₁₂₃, h₁, hj₂₃, h₂, h₃⟩ | hs) · obtain ⟨j₁, hj₁₂, hj₁₃, hj₁₂₃⟩ : ∃ j₁ : Fin 3, j₁ ≠ j₂ ∧ j₁ ≠ j₃ ∧ ∀ j : Fin 3, j = j₁ ∨ j = j₂ ∨ j = j₃ := by clear h₂ h₃ decide +revert suffices h : t₀.points j₁ = t.orthocenter by have hui : (Set.univ : Set (Fin 3)) = {i₁, i₂, i₃} := by ext x; simpa using h₁₂₃ x have huj : (Set.univ : Set (Fin 3)) = {j₁, j₂, j₃} := by ext x; simpa using hj₁₂₃ x rw [← h, ht₀s, ← Set.image_univ, huj, ← Set.image_univ, hui] simp_rw [Set.image_insert_eq, Set.image_singleton, h₁, ← h₂, ← h₃] rw [Set.insert_comm] exact (Triangle.orthocenter_replace_orthocenter_eq_point hj₁₂ hj₁₃ hj₂₃ h₁₂ h₁₃ h₂₃ h₁ h₂.symm h₃.symm).symm · rw [hs] convert ht₀s using 2 exact Triangle.orthocenter_eq_of_range_eq hs end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Basic.lean
import Mathlib.Geometry.Euclidean.PerpBisector import Mathlib.Algebra.QuadraticDiscriminant /-! # Euclidean spaces This file makes some definitions and proves very basic geometrical results about real inner product spaces and Euclidean affine spaces. Results about real inner product spaces that involve the norm and inner product but not angles generally go in `Analysis.NormedSpace.InnerProduct`. Results with longer proofs or more geometrical content generally go in separate files. ## Implementation notes To declare `P` as the type of points in a Euclidean affine space with `V` as the type of vectors, use `[NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P]`. This works better with `outParam` to make `V` implicit in most cases than having a separate type alias for Euclidean affine spaces. Rather than requiring Euclidean affine spaces to be finite-dimensional (as in the definition on Wikipedia), this is specified only for those theorems that need it. ## References * https://en.wikipedia.org/wiki/Euclidean_space -/ noncomputable section open RealInnerProductSpace namespace EuclideanGeometry /-! ### Geometrical results on Euclidean affine spaces This section develops some geometrical definitions and results on Euclidean affine spaces. -/ variable {V : Type*} {P : Type*} variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] /-- The inner product of two vectors given with `weightedVSub`, in terms of the pairwise distances. -/ theorem inner_weightedVSub {ι₁ : Type*} {s₁ : Finset ι₁} {w₁ : ι₁ → ℝ} (p₁ : ι₁ → P) (h₁ : ∑ i ∈ s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : Finset ι₂} {w₂ : ι₂ → ℝ} (p₂ : ι₂ → P) (h₂ : ∑ i ∈ s₂, w₂ i = 0) : ⟪s₁.weightedVSub p₁ w₁, s₂.weightedVSub p₂ w₂⟫ = (-∑ i₁ ∈ s₁, ∑ i₂ ∈ s₂, w₁ i₁ * w₂ i₂ * (dist (p₁ i₁) (p₂ i₂) * dist (p₁ i₁) (p₂ i₂))) / 2 := by rw [Finset.weightedVSub_apply, Finset.weightedVSub_apply, inner_sum_smul_sum_smul_of_sum_eq_zero _ h₁ _ h₂] simp_rw [vsub_sub_vsub_cancel_right] rcongr (i₁ i₂) <;> rw [dist_eq_norm_vsub V (p₁ i₁) (p₂ i₂)] /-- The distance between two points given with `affineCombination`, in terms of the pairwise distances between the points in that combination. -/ theorem dist_affineCombination {ι : Type*} {s : Finset ι} {w₁ w₂ : ι → ℝ} (p : ι → P) (h₁ : ∑ i ∈ s, w₁ i = 1) (h₂ : ∑ i ∈ s, w₂ i = 1) : by have a₁ := s.affineCombination ℝ p w₁ have a₂ := s.affineCombination ℝ p w₂ exact dist a₁ a₂ * dist a₁ a₂ = (-∑ i₁ ∈ s, ∑ i₂ ∈ s, (w₁ - w₂) i₁ * (w₁ - w₂) i₂ * (dist (p i₁) (p i₂) * dist (p i₁) (p i₂))) / 2 := by dsimp only rw [dist_eq_norm_vsub V (s.affineCombination ℝ p w₁) (s.affineCombination ℝ p w₂), ← @inner_self_eq_norm_mul_norm ℝ, Finset.affineCombination_vsub] have h : (∑ i ∈ s, (w₁ - w₂) i) = 0 := by simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, h₁, h₂, sub_self] exact inner_weightedVSub p h p h /-- The squared distance between points on a line (expressed as a multiple of a fixed vector added to a point) and another point, expressed as a quadratic. -/ theorem dist_smul_vadd_sq (r : ℝ) (v : V) (p₁ p₂ : P) : dist (r • v +ᵥ p₁) p₂ * dist (r • v +ᵥ p₁) p₂ = ⟪v, v⟫ * r * r + 2 * ⟪v, p₁ -ᵥ p₂⟫ * r + ⟪p₁ -ᵥ p₂, p₁ -ᵥ p₂⟫ := by rw [dist_eq_norm_vsub V _ p₂, ← real_inner_self_eq_norm_mul_norm, vadd_vsub_assoc, real_inner_add_add_self, real_inner_smul_left, real_inner_smul_left, real_inner_smul_right] ring /-- The condition for two points on a line to be equidistant from another point. -/ theorem dist_smul_vadd_eq_dist {v : V} (p₁ p₂ : P) (hv : v ≠ 0) (r : ℝ) : dist (r • v +ᵥ p₁) p₂ = dist p₁ p₂ ↔ r = 0 ∨ r = -2 * ⟪v, p₁ -ᵥ p₂⟫ / ⟪v, v⟫ := by conv_lhs => rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_smul_vadd_sq, mul_assoc, ← sub_eq_zero, add_sub_assoc, dist_eq_norm_vsub V p₁ p₂, ← real_inner_self_eq_norm_mul_norm, sub_self] have hvi : ⟪v, v⟫ ≠ 0 := by simpa using hv have hd : discrim ⟪v, v⟫ (2 * ⟪v, p₁ -ᵥ p₂⟫) 0 = 2 * ⟪v, p₁ -ᵥ p₂⟫ * (2 * ⟪v, p₁ -ᵥ p₂⟫) := by rw [discrim] ring rw [quadratic_eq_zero_iff hvi hd, neg_add_cancel, zero_div, neg_mul_eq_neg_mul, ← mul_sub_right_distrib, sub_eq_add_neg, ← mul_two, mul_assoc, mul_div_assoc, mul_div_mul_left, mul_div_assoc] simp open AffineSubspace Module /-- Distances `r₁` `r₂` of `p` from two different points `c₁` `c₂` determine at most two points `p₁` `p₂` in a two-dimensional subspace containing those points (two circles intersect in at most two points). -/ theorem eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two {s : AffineSubspace ℝ P} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = 2) {c₁ c₂ p₁ p₂ p : P} (hc₁s : c₁ ∈ s) (hc₂s : c₂ ∈ s) (hp₁s : p₁ ∈ s) (hp₂s : p₂ ∈ s) (hps : p ∈ s) {r₁ r₂ : ℝ} (hc : c₁ ≠ c₂) (hp : p₁ ≠ p₂) (hp₁c₁ : dist p₁ c₁ = r₁) (hp₂c₁ : dist p₂ c₁ = r₁) (hpc₁ : dist p c₁ = r₁) (hp₁c₂ : dist p₁ c₂ = r₂) (hp₂c₂ : dist p₂ c₂ = r₂) (hpc₂ : dist p c₂ = r₂) : p = p₁ ∨ p = p₂ := by have ho : ⟪c₂ -ᵥ c₁, p₂ -ᵥ p₁⟫ = 0 := inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hp₂c₁.symm) (hp₁c₂.trans hp₂c₂.symm) have hop : ⟪c₂ -ᵥ c₁, p -ᵥ p₁⟫ = 0 := inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hpc₁.symm) (hp₁c₂.trans hpc₂.symm) let b : Fin 2 → V := ![c₂ -ᵥ c₁, p₂ -ᵥ p₁] have hb : LinearIndependent ℝ b := by refine linearIndependent_of_ne_zero_of_inner_eq_zero ?_ ?_ · intro i fin_cases i <;> simp [b, hc.symm, hp.symm] · intro i j hij fin_cases i <;> fin_cases j <;> try exact False.elim (hij rfl) · exact ho · rw [real_inner_comm] exact ho have hbs : Submodule.span ℝ (Set.range b) = s.direction := by refine Submodule.eq_of_le_of_finrank_eq ?_ ?_ · rw [Submodule.span_le, Set.range_subset_iff] intro i fin_cases i · exact vsub_mem_direction hc₂s hc₁s · exact vsub_mem_direction hp₂s hp₁s · rw [finrank_span_eq_card hb, Fintype.card_fin, hd] have hv : ∀ v ∈ s.direction, ∃ t₁ t₂ : ℝ, v = t₁ • (c₂ -ᵥ c₁) + t₂ • (p₂ -ᵥ p₁) := by intro v hv have hr : Set.range b = {c₂ -ᵥ c₁, p₂ -ᵥ p₁} := by have hu : (Finset.univ : Finset (Fin 2)) = {0, 1} := by decide classical rw [← Fintype.coe_image_univ, hu] simp [b] rw [← hbs, hr, Submodule.mem_span_insert] at hv rcases hv with ⟨t₁, v', hv', hv⟩ rw [Submodule.mem_span_singleton] at hv' rcases hv' with ⟨t₂, rfl⟩ exact ⟨t₁, t₂, hv⟩ rcases hv (p -ᵥ p₁) (vsub_mem_direction hps hp₁s) with ⟨t₁, t₂, hpt⟩ simp only [hpt, inner_add_right, inner_smul_right, ho, mul_zero, add_zero, mul_eq_zero, inner_self_eq_zero, vsub_eq_zero_iff_eq, hc.symm, or_false] at hop rw [hop, zero_smul, zero_add, ← eq_vadd_iff_vsub_eq] at hpt subst hpt have hp' : (p₂ -ᵥ p₁ : V) ≠ 0 := by simp [hp.symm] have hp₂ : dist ((1 : ℝ) • (p₂ -ᵥ p₁) +ᵥ p₁) c₁ = r₁ := by simp [hp₂c₁] rw [← hp₁c₁, dist_smul_vadd_eq_dist _ _ hp'] at hpc₁ hp₂ simp only [one_ne_zero, false_or] at hp₂ rw [hp₂.symm] at hpc₁ rcases hpc₁ with hpc₁ | hpc₁ <;> simp [hpc₁] /-- Distances `r₁` `r₂` of `p` from two different points `c₁` `c₂` determine at most two points `p₁` `p₂` in two-dimensional space (two circles intersect in at most two points). -/ theorem eq_of_dist_eq_of_dist_eq_of_finrank_eq_two [FiniteDimensional ℝ V] (hd : finrank ℝ V = 2) {c₁ c₂ p₁ p₂ p : P} {r₁ r₂ : ℝ} (hc : c₁ ≠ c₂) (hp : p₁ ≠ p₂) (hp₁c₁ : dist p₁ c₁ = r₁) (hp₂c₁ : dist p₂ c₁ = r₁) (hpc₁ : dist p c₁ = r₁) (hp₁c₂ : dist p₁ c₂ = r₂) (hp₂c₂ : dist p₂ c₂ = r₂) (hpc₂ : dist p c₂ = r₂) : p = p₁ ∨ p = p₂ := haveI hd' : finrank ℝ (⊤ : AffineSubspace ℝ P).direction = 2 := by rw [direction_top, finrank_top] exact hd eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two hd' (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) hc hp hp₁c₁ hp₂c₁ hpc₁ hp₁c₂ hp₂c₂ hpc₂ end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Incenter.lean
import Mathlib.Geometry.Euclidean.Altitude import Mathlib.Geometry.Euclidean.SignedDist import Mathlib.Geometry.Euclidean.Sphere.Tangent import Mathlib.Tactic.Positivity.Finset import Mathlib.Topology.Instances.Sign /-! # Incenters and excenters of simplices. This file defines the insphere and exspheres of a simplex (tangent to the faces of the simplex), and the center and radius of such spheres. ## Main definitions * `Affine.Simplex.ExcenterExists` says whether an excenter exists with a given set of indices (that determine, up to negating all the signs, which vertices of the simplex lie on the same side of the opposite face as the excenter and which lie on the opposite side of that face). * `Affine.Simplex.excenterWeights` are the weights of the excenter with the given set of indices, if it exists, as an affine combination of the vertices. * `Affine.Simplex.exsphere` is the exsphere with the given set of indices, if it exists, with shorthands: * `Affine.Simplex.excenter` for the center of this sphere * `Affine.Simplex.exradius` for the radius of this sphere * `Affine.Simplex.insphere` is the insphere, with shorthands: * `Affine.Simplex.incenter` for the center of this sphere * `Affine.Simplex.inradius` for the radius of this sphere ## References * https://en.wikipedia.org/wiki/Incircle_and_excircles * https://en.wikipedia.org/wiki/Incenter -/ open EuclideanGeometry open scoped Finset RealInnerProductSpace variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] noncomputable section namespace Affine namespace Simplex variable {n : ℕ} [NeZero n] (s : Simplex ℝ P n) /-- The unnormalized weights of the vertices in an affine combination that gives an excenter with signs determined by the given set of indices (for the empty set, this is the incenter; for a singleton set, this is the excenter opposite a vertex). An excenter with those signs exists if and only if the sum of these weights is nonzero (so the normalized weights sum to 1). -/ def excenterWeightsUnnorm (signs : Finset (Fin (n + 1))) (i : Fin (n + 1)) : ℝ := (if i ∈ signs then -1 else 1) * (s.height i)⁻¹ @[simp] lemma excenterWeightsUnnorm_empty_apply (i : Fin (n + 1)) : s.excenterWeightsUnnorm ∅ i = (s.height i)⁻¹ := one_mul _ lemma excenterWeightsUnnorm_ne_zero (signs : Finset (Fin (n + 1))) (i : Fin (n + 1)) : s.excenterWeightsUnnorm signs i ≠ 0 := by rw [excenterWeightsUnnorm] refine mul_ne_zero ?_ ?_ · grind · simp [(s.height_pos i).ne'] /-- Whether an excenter exists with a given choice of signs. -/ def ExcenterExists (signs : Finset (Fin (n + 1))) : Prop := ∑ i, s.excenterWeightsUnnorm signs i ≠ 0 /-- The normalized weights of the vertices in an affine combination that gives an excenter with signs determined by the given set of indices. An excenter with those signs exists if and only if the sum of these weights is 1. -/ def excenterWeights (signs : Finset (Fin (n + 1))) : Fin (n + 1) → ℝ := (∑ i, s.excenterWeightsUnnorm signs i)⁻¹ • s.excenterWeightsUnnorm signs variable {s} in lemma ExcenterExists.excenterWeights_ne_zero {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i : Fin (n + 1)) : s.excenterWeights signs i ≠ 0 := by rw [excenterWeights] refine mul_ne_zero ?_ (s.excenterWeightsUnnorm_ne_zero _ _) rw [ExcenterExists] at h simp [h] @[simp] lemma excenterWeightsUnnorm_compl (signs : Finset (Fin (n + 1))) : s.excenterWeightsUnnorm signsᶜ = -s.excenterWeightsUnnorm signs := by ext i by_cases h : i ∈ signs <;> simp [excenterWeightsUnnorm, h] @[simp] lemma excenterWeights_compl (signs : Finset (Fin (n + 1))) : s.excenterWeights signsᶜ = s.excenterWeights signs := by simp [excenterWeights, inv_neg] @[simp] lemma excenterExists_compl {signs : Finset (Fin (n + 1))} : s.ExcenterExists signsᶜ ↔ s.ExcenterExists signs := by simp [ExcenterExists] lemma sum_excenterWeights (signs : Finset (Fin (n + 1))) [Decidable (s.ExcenterExists signs)] : ∑ i, s.excenterWeights signs i = if s.ExcenterExists signs then 1 else 0 := by simp_rw [ExcenterExists, excenterWeights] split_ifs with h · simp [← Finset.mul_sum, h] · simp only [ne_eq, not_not] at h simp [h] @[simp] lemma sum_excenterWeights_eq_one_iff {signs : Finset (Fin (n + 1))} : ∑ i, s.excenterWeights signs i = 1 ↔ s.ExcenterExists signs := by classical simp [sum_excenterWeights] alias ⟨_, ExcenterExists.sum_excenterWeights_eq_one⟩ := sum_excenterWeights_eq_one_iff lemma sum_excenterWeightsUnnorm_empty_pos : 0 < ∑ i, s.excenterWeightsUnnorm ∅ i := by simp_rw [excenterWeightsUnnorm_empty_apply] positivity lemma excenterWeights_empty_pos (i : Fin (n + 1)) : 0 < s.excenterWeights ∅ i := by simp only [excenterWeights, excenterWeightsUnnorm_empty_apply, Pi.smul_apply, smul_eq_mul] positivity @[simp] lemma sign_excenterWeights_empty (i : Fin (n + 1)) : SignType.sign (s.excenterWeights ∅ i) = 1 := by rw [sign_eq_one_iff] exact s.excenterWeights_empty_pos i /-- The existence of the incenter, expressed in terms of `ExcenterExists`. -/ @[simp] lemma excenterExists_empty : s.ExcenterExists ∅ := s.sum_excenterWeightsUnnorm_empty_pos.ne' lemma sum_inv_height_sq_smul_vsub_eq_zero : ∑ i, (s.height i)⁻¹ ^ 2 • (s.points i -ᵥ s.altitudeFoot i) = 0 := by suffices ∀ i, i ≠ 0 → ∑ j, ⟪s.points i -ᵥ s.points 0, (s.height j)⁻¹ ^ 2 • (s.points j -ᵥ s.altitudeFoot j)⟫ = 0 by rw [← Submodule.mem_bot ℝ, ← Submodule.inf_orthogonal_eq_bot (vectorSpan ℝ (Set.range s.points))] refine ⟨Submodule.sum_smul_mem _ _ fun i hi ↦ vsub_mem_vectorSpan_of_mem_affineSpan_of_mem_affineSpan (mem_affineSpan _ (Set.mem_range_self _)) (altitudeFoot_mem_affineSpan _ _), ?_⟩ rw [vectorSpan_range_eq_span_range_vsub_right_ne _ _ 0, Submodule.span_range_eq_iSup, ← Submodule.iInf_orthogonal, Submodule.coe_iInf, Set.mem_iInter] intro i rcases i with ⟨i, hi⟩ simpa only [SetLike.mem_coe, Submodule.mem_orthogonal_singleton_iff_inner_right, inner_sum] using this i hi intro i hi rw [← Finset.add_sum_erase _ _ (Finset.mem_univ 0), ← Finset.add_sum_erase _ _ (Finset.mem_erase.2 ⟨hi, Finset.mem_univ _⟩), ← add_assoc] convert add_zero _ · convert Finset.sum_const_zero with j hj rw [real_inner_smul_right] convert mul_zero _ rw [← Submodule.mem_orthogonal_singleton_iff_inner_right] refine SetLike.le_def.1 (Submodule.orthogonal_le ?_) (vsub_orthogonalProjection_mem_direction_orthogonal _ _) rw [Submodule.span_singleton_le_iff_mem, direction_affineSpan] simp only [Finset.mem_erase, Finset.mem_univ, and_true] at hj refine vsub_mem_vectorSpan _ ?_ ?_ <;> simp only [range_faceOpposite_points, Set.mem_image] · exact ⟨i, hj.1.symm, rfl⟩ · exact ⟨0, hj.2.symm, rfl⟩ · rw [inner_smul_right, inner_smul_right, inner_vsub_vsub_altitudeFoot_eq_height_sq _ hi, ← neg_vsub_eq_vsub_rev, inner_neg_left, inner_vsub_vsub_altitudeFoot_eq_height_sq _ hi.symm, mul_neg, inv_pow] simp [height] /-- The inverse of the distance from one vertex to the opposite face, expressed as a sum of multiples of that quantity for the other vertices. The multipliers, expressed here in terms of inner products, are equal to the cosines of angles between faces (informally, the inverse distances are proportional to the volumes of the faces and this is equivalent to expressing the volume of a face as the sum of the signed volumes of projections of the other faces onto that face). -/ lemma inv_height_eq_sum_mul_inv_dist (i : Fin (n + 1)) : (s.height i)⁻¹ = ∑ j ∈ {k | k ≠ i}, -(⟪s.points i -ᵥ s.altitudeFoot i, s.points j -ᵥ s.altitudeFoot j⟫ / (s.height i * s.height j)) * (s.height j)⁻¹ := by rw [← sub_eq_zero] simp_rw [neg_mul] rw [Finset.sum_neg_distrib, sub_neg_eq_add, Finset.filter_ne', Finset.sum_erase_eq_sub (Finset.mem_univ _), real_inner_self_eq_norm_mul_norm, ← dist_eq_norm_vsub] simp only [height, ne_eq, mul_eq_zero, dist_eq_zero, ne_altitudeFoot, or_self, not_false_eq_true, div_self, one_mul, add_sub_cancel] have h := s.sum_inv_height_sq_smul_vsub_eq_zero apply_fun fun v ↦ (s.height i)⁻¹ * ⟪s.points i -ᵥ s.altitudeFoot i, v⟫ at h rw [inner_sum, Finset.mul_sum] at h simp only [inner_zero_right, mul_zero, inner_smul_right, height] at h convert h using 2 with j ring /-- The inverse of the distance from one vertex to the opposite face is less than the sum of that quantity for the other vertices. This implies the existence of the excenter opposite that vertex; it also implies that the image of the incenter under a homothety with scale factor 2 about a vertex lies outside the simplex. -/ lemma inv_height_lt_sum_inv_height [Nat.AtLeastTwo n] (i : Fin (n + 1)) : (s.height i)⁻¹ < ∑ j ∈ {k | k ≠ i}, (s.height j)⁻¹ := by rw [inv_height_eq_sum_mul_inv_dist] refine Finset.sum_lt_sum_of_nonempty ?_ ?_ · rw [Finset.filter_ne', ← Finset.card_ne_zero] simp only [Finset.mem_univ, Finset.card_erase_of_mem, Finset.card_univ, Fintype.card_fin, add_tsub_cancel_right] exact NeZero.ne _ · rintro j hj refine mul_lt_of_lt_one_left ?_ ?_ · simp [height_pos] · rw [neg_lt] exact neg_one_lt_inner_vsub_altitudeFoot_div _ _ _ lemma sum_excenterWeightsUnnorm_singleton_pos [Nat.AtLeastTwo n] (i : Fin (n + 1)) : 0 < ∑ j, s.excenterWeightsUnnorm {i} j := by rw [← Finset.sum_add_sum_compl {i}, Finset.sum_singleton] nth_rw 1 [excenterWeightsUnnorm] simp only [Finset.mem_singleton, ↓reduceIte, neg_mul, one_mul, lt_neg_add_iff_add_lt, add_zero] convert s.inv_height_lt_sum_inv_height i using 2 with j h · ext j simp · rw [Finset.mem_filter_univ] at h simp [excenterWeightsUnnorm, h] lemma sign_excenterWeights_singleton_neg [Nat.AtLeastTwo n] (i : Fin (n + 1)) : SignType.sign (s.excenterWeights {i} i) = -1 := by simp_rw [excenterWeights, Pi.smul_apply, smul_eq_mul, sign_mul] convert one_mul _ · rw [sign_eq_one_iff, inv_pos] exact s.sum_excenterWeightsUnnorm_singleton_pos i · simp [excenterWeightsUnnorm] lemma sign_excenterWeights_singleton_pos [Nat.AtLeastTwo n] {i j : Fin (n + 1)} (h : i ≠ j) : SignType.sign (s.excenterWeights {i} j) = 1 := by simp_rw [excenterWeights, Pi.smul_apply, smul_eq_mul, sign_mul] convert one_mul _ · rw [sign_eq_one_iff, inv_pos] exact s.sum_excenterWeightsUnnorm_singleton_pos i · simp [excenterWeightsUnnorm, h.symm] /-- The existence of the excenter opposite a vertex (in two or more dimensions), expressed in terms of `ExcenterExists`. -/ lemma excenterExists_singleton [Nat.AtLeastTwo n] (i : Fin (n + 1)) : s.ExcenterExists {i} := (s.sum_excenterWeightsUnnorm_singleton_pos i).ne' /-- The exsphere with signs determined by the given set of indices (for the empty set, this is the insphere; for a singleton set, this is the exsphere opposite a vertex). This is only meaningful if `s.ExcenterExists`; otherwise, it is a sphere of radius zero at some arbitrary point. -/ def exsphere (signs : Finset (Fin (n + 1))) : Sphere P where center := Finset.univ.affineCombination ℝ s.points (s.excenterWeights signs) radius := |(∑ i, s.excenterWeightsUnnorm signs i)⁻¹| /-- The insphere of a simplex. -/ def insphere : Sphere P := s.exsphere ∅ /-- The excenter with signs determined by the given set of indices (for the empty set, this is the incenter; for a singleton set, this is the excenter opposite a vertex). This is only meaningful if `s.ExcenterExists signs`; otherwise, it is some arbitrary point. -/ def excenter (signs : Finset (Fin (n + 1))) : P := (s.exsphere signs).center /-- The incenter of a simplex. -/ def incenter : P := (s.exsphere ∅).center /-- The distance between an excenter and a face of the simplex (zero if no such excenter exists). -/ def exradius (signs : Finset (Fin (n + 1))) : ℝ := (s.exsphere signs).radius /-- The distance between the incenter and a face of the simplex. -/ def inradius : ℝ := (s.exsphere ∅).radius @[simp] lemma exsphere_center (signs : Finset (Fin (n + 1))) : (s.exsphere signs).center = s.excenter signs := rfl @[simp] lemma exsphere_radius (signs : Finset (Fin (n + 1))) : (s.exsphere signs).radius = s.exradius signs := rfl @[simp] lemma insphere_center : s.insphere.center = s.incenter := rfl @[simp] lemma insphere_radius : s.insphere.radius = s.inradius := rfl @[simp] lemma exsphere_empty : s.exsphere ∅ = s.insphere := rfl @[simp] lemma excenter_empty : s.excenter ∅ = s.incenter := rfl @[simp] lemma exradius_empty : s.exradius ∅ = s.inradius := rfl @[simp] lemma exsphere_compl (signs : Finset (Fin (n + 1))) : s.exsphere signsᶜ = s.exsphere signs := by simp [exsphere, excenterWeights_compl, excenterWeightsUnnorm_compl, Pi.neg_apply] @[simp] lemma excenter_compl (signs : Finset (Fin (n + 1))) : s.excenter signsᶜ = s.excenter signs := by simp_rw [excenter, exsphere_compl] @[simp] lemma exradius_compl (signs : Finset (Fin (n + 1))) : s.exradius signsᶜ = s.exradius signs := by simp_rw [exradius, exsphere_compl] @[simp] lemma exsphere_univ : s.exsphere Finset.univ = s.insphere := by rw [← Finset.compl_empty, exsphere_compl, insphere] @[simp] lemma excenter_univ : s.excenter Finset.univ = s.incenter := by rw [excenter, exsphere_univ, insphere_center] @[simp] lemma exradius_univ : s.exradius Finset.univ = s.inradius := by rw [exradius, exsphere_univ, insphere_radius] lemma excenter_eq_affineCombination (signs : Finset (Fin (n + 1))) : s.excenter signs = Finset.univ.affineCombination ℝ s.points (s.excenterWeights signs) := rfl lemma exradius_eq_abs_inv_sum (signs : Finset (Fin (n + 1))) : s.exradius signs = |(∑ i, s.excenterWeightsUnnorm signs i)⁻¹| := rfl lemma incenter_eq_affineCombination : s.incenter = Finset.univ.affineCombination ℝ s.points (s.excenterWeights ∅) := rfl lemma inradius_eq_abs_inv_sum : s.inradius = |(∑ i, s.excenterWeightsUnnorm ∅ i)⁻¹| := rfl lemma exradius_nonneg (signs : Finset (Fin (n + 1))) : 0 ≤ s.exradius signs := abs_nonneg _ variable {s} in lemma ExcenterExists.exradius_pos {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) : 0 < s.exradius signs := abs_pos.2 (inv_ne_zero h) lemma inradius_pos : 0 < s.inradius := s.excenterExists_empty.exradius_pos lemma exradius_singleton_pos [Nat.AtLeastTwo n] (i : Fin (n + 1)) : 0 < s.exradius {i} := (s.excenterExists_singleton i).exradius_pos variable {s} in lemma ExcenterExists.excenter_mem_affineSpan_range {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) : s.excenter signs ∈ affineSpan ℝ (Set.range s.points) := affineCombination_mem_affineSpan h.sum_excenterWeights_eq_one _ lemma incenter_mem_affineSpan_range : s.incenter ∈ affineSpan ℝ (Set.range s.points) := s.excenterExists_empty.excenter_mem_affineSpan_range lemma incenter_mem_interior : s.incenter ∈ s.interior := by have h := s.excenterExists_empty.sum_excenterWeights_eq_one rw [incenter_eq_affineCombination, s.affineCombination_mem_interior_iff h] intro i refine ⟨s.excenterWeights_empty_pos i, ?_⟩ by_contra! hp obtain ⟨j, hj⟩ := exists_ne i rw [← Finset.sum_add_sum_compl {j, i}, Finset.sum_pair hj] at h revert h apply ne_of_gt nth_rw 2 [add_comm] grw [hp] rw [add_assoc, lt_add_iff_pos_right] exact add_pos_of_pos_of_nonneg (s.excenterWeights_empty_pos j) (Finset.sum_nonneg fun k _ ↦ (s.excenterWeights_empty_pos k).le) lemma excenter_singleton_mem_affineSpan_range [Nat.AtLeastTwo n] (i : Fin (n + 1)) : s.excenter {i} ∈ affineSpan ℝ (Set.range s.points) := (s.excenterExists_singleton i).excenter_mem_affineSpan_range variable {s} in lemma ExcenterExists.signedInfDist_excenter_eq_mul_sum_inv {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i : Fin (n + 1)) : s.signedInfDist i (s.excenter signs) = (if i ∈ signs then -1 else 1) * (∑ j, s.excenterWeightsUnnorm signs j)⁻¹ := by simp_rw [excenter_eq_affineCombination, signedInfDist_affineCombination _ _ h.sum_excenterWeights_eq_one, excenterWeights, Pi.smul_apply, ← dist_eq_norm_vsub, excenterWeightsUnnorm] rw [← altitudeFoot, ← height] simp [(s.height_pos i).ne'] variable {s} in lemma ExcenterExists.sign_signedInfDist_excenter {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i : Fin (n + 1)) : SignType.sign (s.signedInfDist i (s.excenter signs)) = SignType.sign (s.excenterWeights signs i) := by rw [excenter_eq_affineCombination, signedInfDist_affineCombination _ _ h.sum_excenterWeights_eq_one, sign_mul] convert mul_one _ rw [sign_eq_one_iff, ← dist_eq_norm_vsub] exact s.height_pos _ lemma sign_signedInfDist_incenter (i : Fin (n + 1)) : SignType.sign (s.signedInfDist i s.incenter) = 1 := by convert s.excenterExists_empty.sign_signedInfDist_excenter i simp variable {s} in lemma ExcenterExists.affineCombination_eq_excenter_iff {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) {w : Fin (n + 1) → ℝ} (hw : ∑ j, w j = 1) : Finset.univ.affineCombination ℝ s.points w = s.excenter signs ↔ w = s.excenterWeights signs := by constructor · simp_rw [excenter, exsphere] exact fun he ↦ (affineIndependent_iff_eq_of_fintype_affineCombination_eq ℝ s.points).1 s.independent _ _ hw h.sum_excenterWeights_eq_one he · rintro rfl rw [excenter, exsphere] variable {s} in lemma ExcenterExists.excenter_ne_point {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i : Fin (n + 1)) : s.excenter signs ≠ s.points i := by intro he rw [eq_comm, ← Finset.univ.affineCombination_affineCombinationSingleWeights ℝ s.points (Finset.mem_univ _), h.affineCombination_eq_excenter_iff (Finset.univ.sum_affineCombinationSingleWeights ℝ (Finset.mem_univ _))] at he obtain ⟨j, hij⟩ : ∃ j, j ≠ i := exists_ne i have he' : Finset.affineCombinationSingleWeights ℝ i j = s.excenterWeights signs j := by rw [he] simp only [ne_eq, hij, not_false_eq_true, Finset.affineCombinationSingleWeights_apply_of_ne] at he' exact h.excenterWeights_ne_zero _ he'.symm lemma incenter_ne_point (i : Fin (n + 1)) : s.incenter ≠ s.points i := s.excenterExists_empty.excenter_ne_point i variable {s} in lemma ExcenterExists.excenterWeights_eq_excenterWeights_iff {signs₁ signs₂ : Finset (Fin (n + 1))} (h₁ : s.ExcenterExists signs₁) (h₂ : s.ExcenterExists signs₂) : s.excenterWeights signs₁ = s.excenterWeights signs₂ ↔ signs₁ = signs₂ ∨ signs₁ = signs₂ᶜ := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · have hi : ∀ i, SignType.sign (s.excenterWeights signs₁ i) = SignType.sign (s.excenterWeights signs₂ i) := by simp [h] simp_rw [excenterWeights, Pi.smul_apply, smul_eq_mul, sign_mul] at hi have hn₁ : ∑ i, s.excenterWeightsUnnorm signs₁ i ≠ 0 := h₁ have hn₂ : ∑ i, s.excenterWeightsUnnorm signs₂ i ≠ 0 := h₂ rcases sign_eq_sign_or_eq_neg (inv_ne_zero hn₁) (inv_ne_zero hn₂) with hs | hs · simp only [hs, mul_eq_mul_left_iff, sign_eq_zero_iff, inv_eq_zero, hn₂, or_false] at hi simp only [excenterWeightsUnnorm, sign_mul, inv_pos, height_pos, sign_pos, mul_one] at hi left ext i replace hi := hi i split_ifs at hi <;> simp_all · simp_rw [hs, neg_mul, ← mul_neg, mul_eq_mul_left_iff] at hi simp only [sign_eq_zero_iff, inv_eq_zero, hn₂, or_false] at hi simp only [excenterWeightsUnnorm, sign_mul, inv_pos, height_pos, sign_pos, mul_one] at hi right ext i replace hi := hi i split_ifs at hi <;> simp_all · rcases h with rfl | rfl · rfl · simp variable {s} in lemma ExcenterExists.excenter_eq_excenter_iff {signs₁ signs₂ : Finset (Fin (n + 1))} (h₁ : s.ExcenterExists signs₁) (h₂ : s.ExcenterExists signs₂) : s.excenter signs₁ = s.excenter signs₂ ↔ signs₁ = signs₂ ∨ signs₁ = signs₂ᶜ := by rw [excenter_eq_affineCombination, h₂.affineCombination_eq_excenter_iff (s.sum_excenterWeights_eq_one_iff.2 h₁)] exact h₁.excenterWeights_eq_excenterWeights_iff h₂ variable {s} in lemma ExcenterExists.excenter_eq_incenter_iff {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) : s.excenter signs = s.incenter ↔ signs = ∅ ∨ signs = Finset.univ := by rw [incenter, ← excenter, h.excenter_eq_excenter_iff s.excenterExists_empty] simp lemma excenter_singleton_ne_incenter [Nat.AtLeastTwo n] (i : Fin (n + 1)) : s.excenter {i} ≠ s.incenter := by intro h rw [(s.excenterExists_singleton i).excenter_eq_incenter_iff] at h simp at h lemma excenter_singleton_injective [Nat.AtLeastTwo n] : Function.Injective fun i ↦ s.excenter {i} := by intro i j hij dsimp only at hij rw [(s.excenterExists_singleton i).excenter_eq_excenter_iff (s.excenterExists_singleton j)] at hij rcases hij with hij | hij · simpa using hij · have : 2 ≤ n := Nat.AtLeastTwo.prop obtain ⟨k, hki, hkj⟩ : ∃ k, k ≠ i ∧ k ≠ j := Fin.exists_ne_and_ne_of_two_lt i j (by cutsat) rw [Finset.ext_iff] at hij replace hij := hij k simp_all /-- A touchpoint is where an exsphere of a simplex is tangent to one of the faces. -/ def touchpoint (signs : Finset (Fin (n + 1))) (i : Fin (n + 1)) : P := (s.faceOpposite i).orthogonalProjectionSpan (s.excenter signs) lemma touchpoint_mem_affineSpan (signs : Finset (Fin (n + 1))) (i : Fin (n + 1)) : s.touchpoint signs i ∈ affineSpan ℝ (Set.range (s.faceOpposite i).points) := orthogonalProjection_mem _ /-- A weaker version of `touchpoint_mem_affineSpan`. -/ lemma touchpoint_mem_affineSpan_simplex (signs : Finset (Fin (n + 1))) (i : Fin (n + 1)) : s.touchpoint signs i ∈ affineSpan ℝ (Set.range s.points) := by refine SetLike.le_def.1 (affineSpan_mono _ ?_) (s.touchpoint_mem_affineSpan signs i) simp lemma touchpoint_eq_point_rev (s : Simplex ℝ P 1) (signs : Finset (Fin 2)) (i : Fin 2) : s.touchpoint signs i = s.points i.rev := s.orthogonalProjectionSpan_faceOpposite_eq_point_rev _ _ variable {s} in /-- The signed distance between the excenter and its projection in the plane of each face is the exradius. -/ lemma ExcenterExists.signedInfDist_excenter {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i : Fin (n + 1)) : s.signedInfDist i (s.excenter signs) = (if i ∈ signs then -1 else 1) * SignType.sign (∑ j, s.excenterWeightsUnnorm signs j) * (s.exradius signs) := by rw [h.signedInfDist_excenter_eq_mul_sum_inv, mul_assoc, exradius_eq_abs_inv_sum] congr rw [← mul_eq_one_iff_inv_eq₀ h, ← mul_assoc, self_mul_sign, ← abs_mul, mul_inv_cancel₀ h, abs_one] /-- The signed distance between the incenter and its projection in the plane of each face is the inradius. In other words, the incenter is _internally_ tangent to the faces. -/ lemma signedInfDist_incenter (i : Fin (n + 1)) : s.signedInfDist i s.incenter = s.inradius := by rw [incenter, exsphere_center, s.excenterExists_empty.signedInfDist_excenter] simp (discharger := positivity) variable {s} in /-- The distance between the excenter and its projection in the plane of each face is the exradius. -/ lemma ExcenterExists.dist_excenter {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i : Fin (n + 1)) : dist (s.excenter signs) (s.touchpoint signs i) = s.exradius signs := by rw [touchpoint, ← abs_signedInfDist_eq_dist_of_mem_affineSpan_range i h.excenter_mem_affineSpan_range, h.signedInfDist_excenter, abs_mul, abs_mul, abs_of_nonneg (s.exradius_nonneg signs)] simp only [abs_ite, abs_neg, abs_one, ite_self, one_mul] rcases lt_trichotomy 0 (∑ i, s.excenterWeightsUnnorm signs i) with h' | h' | h' · simp [h'] · simp [h h'.symm] · simp [h'] /-- The distance between the incenter and its projection in the plane of each face is the inradius. -/ lemma dist_incenter (i : Fin (n + 1)) : dist s.incenter (s.touchpoint ∅ i) = s.inradius := s.excenterExists_empty.dist_excenter _ variable {s} in /-- An excenter is equidistant to any two of its touchpoints. -/ lemma ExcenterExists.dist_excenter_eq_dist_excenter {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i₁ i₂ : Fin (n + 1)) : dist (s.excenter signs) (s.touchpoint signs i₁) = dist (s.excenter signs) (s.touchpoint signs i₂) := by simp_rw [h.dist_excenter] /-- The incenter is equidistant to any two of its touchpoints. -/ lemma dist_incenter_eq_dist_incenter (i₁ i₂ : Fin (n + 1)) : dist s.incenter (s.touchpoint ∅ i₁) = dist s.incenter (s.touchpoint ∅ i₂) := s.excenterExists_empty.dist_excenter_eq_dist_excenter _ _ variable {s} in lemma ExcenterExists.touchpoint_mem_exsphere {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i : Fin (n + 1)) : s.touchpoint signs i ∈ s.exsphere signs := mem_sphere'.2 (h.dist_excenter i) lemma touchpoint_mem_insphere (i : Fin (n + 1)) : s.touchpoint ∅ i ∈ s.insphere := s.excenterExists_empty.touchpoint_mem_exsphere _ variable {s} in lemma ExcenterExists.isTangentAt_touchpoint {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i : Fin (n + 1)) : (s.exsphere signs).IsTangentAt (s.touchpoint signs i) (affineSpan ℝ (Set.range (s.faceOpposite i).points)) := by rw [touchpoint, orthogonalProjectionSpan, excenter, ← EuclideanGeometry.Sphere.dist_orthogonalProjection_eq_radius_iff_isTangentAt, ← orthogonalProjectionSpan, ← excenter, ← exradius, ← touchpoint, h.dist_excenter] lemma isTangentAt_insphere_touchpoint (i : Fin (n + 1)) : s.insphere.IsTangentAt (s.touchpoint ∅ i) (affineSpan ℝ (Set.range (s.faceOpposite i).points)) := s.excenterExists_empty.isTangentAt_touchpoint i variable {s} in lemma eq_touchpoint_of_isTangentAt_exsphere {signs : Finset (Fin (n + 1))} {i : Fin (n + 1)} {p : P} (ht : (s.exsphere signs).IsTangentAt p (affineSpan ℝ (Set.range (s.faceOpposite i).points))) : p = s.touchpoint signs i := by rw [ht.eq_orthogonalProjection, touchpoint, orthogonalProjectionSpan, excenter] variable {s} in lemma ExcenterExists.isTangentAt_exsphere_iff_eq_touchpoint {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) {i : Fin (n + 1)} {p : P} : (s.exsphere signs).IsTangentAt p (affineSpan ℝ (Set.range (s.faceOpposite i).points)) ↔ p = s.touchpoint signs i := by refine ⟨eq_touchpoint_of_isTangentAt_exsphere, ?_⟩ rintro rfl exact h.isTangentAt_touchpoint i variable {s} in lemma isTangentAt_insphere_iff_eq_touchpoint {i : Fin (n + 1)} {p : P} : s.insphere.IsTangentAt p (affineSpan ℝ (Set.range (s.faceOpposite i).points)) ↔ p = s.touchpoint ∅ i := s.excenterExists_empty.isTangentAt_exsphere_iff_eq_touchpoint lemma exists_forall_signedInfDist_eq_iff_excenterExists_and_eq_excenter {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {signs : Finset (Fin (n + 1))} : (∃ r : ℝ, ∀ i, s.signedInfDist i p = (if i ∈ signs then -1 else 1) * r) ↔ s.ExcenterExists signs ∧ p = s.excenter signs := by refine ⟨?_, ?_⟩ · rintro ⟨r, h⟩ obtain ⟨w, h1, rfl⟩ := eq_affineCombination_of_mem_affineSpan_of_fintype hp have h' : ∀ i, w i * ‖s.points i -ᵥ s.altitudeFoot i‖ = (if i ∈ signs then -1 else 1) * r := by intro i rw [altitudeFoot, ← s.signedInfDist_affineCombination i h1] exact h i simp_rw [← dist_eq_norm_vsub] at h' have h'' : ∀ i, w i = r * s.excenterWeightsUnnorm signs i := by simp_rw [excenterWeightsUnnorm] intro i replace h' := h' i rw [← height, ← eq_div_iff (s.height_pos i).ne'] at h' rw [h', mul_comm, div_eq_mul_inv, mul_assoc, height, altitudeFoot, orthogonalProjectionSpan] have hw : w = s.excenterWeights signs := by simp_rw [h'', ← Finset.mul_sum] at h1 ext j rw [h'', eq_inv_of_mul_eq_one_left h1] simp [excenterWeights] subst hw exact ⟨s.sum_excenterWeights_eq_one_iff.1 h1, rfl⟩ · rintro ⟨h, rfl⟩ refine ⟨SignType.sign (∑ j, s.excenterWeightsUnnorm signs j) * (s.exradius signs), fun i ↦ ?_⟩ rw [h.signedInfDist_excenter] simp lemma exists_forall_signedInfDist_eq_iff_eq_incenter {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) : (∃ r : ℝ, ∀ i, s.signedInfDist i p = r) ↔ p = s.incenter := by convert s.exists_forall_signedInfDist_eq_iff_excenterExists_and_eq_excenter hp (signs := ∅) · simp · simp [excenterExists_empty] lemma exists_forall_dist_eq_iff_exists_excenterExists_and_eq_excenter {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) : (∃ r : ℝ, ∀ i, dist p ((s.faceOpposite i).orthogonalProjectionSpan p) = r) ↔ ∃ signs, s.ExcenterExists signs ∧ p = s.excenter signs := by simp_rw [← abs_signedInfDist_eq_dist_of_mem_affineSpan_range _ hp] refine ⟨?_, ?_⟩ · rintro ⟨r, h⟩ have h' : ∀ i, s.signedInfDist i p = r ∨ s.signedInfDist i p = -r := fun i ↦ eq_or_eq_neg_of_abs_eq (h i) refine ⟨{i ∈ (Finset.univ : Finset (Fin (n + 1))) | s.signedInfDist i p = -r}, ?_⟩ apply (s.exists_forall_signedInfDist_eq_iff_excenterExists_and_eq_excenter hp).1 refine ⟨r, ?_⟩ grind [Finset.mem_filter_univ] · rintro ⟨signs, h⟩ replace h := (s.exists_forall_signedInfDist_eq_iff_excenterExists_and_eq_excenter hp).2 h rcases h with ⟨r, h⟩ refine ⟨|r|, ?_⟩ simp [h, abs_ite] variable {s} in lemma ExcenterExists.touchpoint_injective {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) : Function.Injective (s.touchpoint signs) := by intro i j hij by_contra hne by_cases hn1 : n = 1 · subst hn1 rw [s.touchpoint_eq_point_rev signs i, s.touchpoint_eq_point_rev signs j] at hij apply s.independent.injective.ne hne convert hij.symm <;> clear hij <;> decide +revert · suffices s.excenter signs -ᵥ s.touchpoint signs i ∈ (vectorSpan ℝ (Set.range s.points))ᗮ by have h' : s.excenter signs -ᵥ s.touchpoint signs i ∈ (vectorSpan ℝ (Set.range s.points)) := by rw [← direction_affineSpan] exact AffineSubspace.vsub_mem_direction h.excenter_mem_affineSpan_range (s.touchpoint_mem_affineSpan_simplex _ _) have h0 : s.excenter signs -ᵥ s.touchpoint signs i = 0 := by rw [← Submodule.mem_bot ℝ, ← Submodule.inf_orthogonal_eq_bot (vectorSpan ℝ (Set.range s.points))] exact ⟨h', this⟩ rw [← norm_eq_zero, ← dist_eq_norm_vsub, h.dist_excenter] at h0 exact h.exradius_pos.ne' h0 obtain ⟨k, hki, hkj⟩ : ∃ k, k ≠ i ∧ k ≠ j := Fin.exists_ne_and_ne_of_two_lt i j (by cutsat) have hu : Set.range s.points = Set.range (s.faceOpposite i).points ∪ Set.range (s.faceOpposite j).points := by simp only [range_faceOpposite_points, ← Set.image_union, ← Set.compl_inter] convert Set.image_univ.symm simp [Ne.symm hne] rw [hu, range_faceOpposite_points, range_faceOpposite_points, AffineSubspace.vectorSpan_union_of_mem_of_mem ℝ (p := s.points k) (Set.mem_image_of_mem _ (by simp [hki])) (Set.mem_image_of_mem _ (by simp [hkj])), ← Submodule.inf_orthogonal] refine ⟨?_, ?_⟩ · rw [← direction_affineSpan, ← range_faceOpposite_points] exact vsub_orthogonalProjection_mem_direction_orthogonal _ _ · rw [hij, ← direction_affineSpan, ← range_faceOpposite_points] exact vsub_orthogonalProjection_mem_direction_orthogonal _ _ lemma touchpoint_empty_injective : Function.Injective (s.touchpoint ∅) := s.excenterExists_empty.touchpoint_injective variable {s} in lemma ExcenterExists.touchpoint_notMem_affineSpan_of_ne {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) {i j : Fin (n + 1)} (hne : i ≠ j) : s.touchpoint signs i ∉ affineSpan ℝ (Set.range (s.faceOpposite j).points) := fun hm ↦ h.touchpoint_injective.ne hne ((h.isTangentAt_touchpoint j).eq_of_mem_of_mem (h.touchpoint_mem_exsphere i) hm) lemma touchpoint_empty_notMem_affineSpan_of_ne {i j : Fin (n + 1)} (hne : i ≠ j) : s.touchpoint ∅ i ∉ affineSpan ℝ (Set.range (s.faceOpposite j).points) := s.excenterExists_empty.touchpoint_notMem_affineSpan_of_ne hne variable {s} in lemma ExcenterExists.sign_signedInfDist_lineMap_excenter_touchpoint {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) {i j : Fin (n + 1)} (hne : i ≠ j) {r : ℝ} (hr : r ∈ Set.Icc 0 1) : SignType.sign (s.signedInfDist j (AffineMap.lineMap (s.excenter signs) (s.touchpoint signs i) r)) = SignType.sign (s.signedInfDist j (s.excenter signs)) := by have hc : ContinuousOn (fun (t : ℝ) ↦ SignType.sign (s.signedInfDist j (AffineMap.lineMap (s.excenter signs) (s.touchpoint signs i) t))) (Set.Icc 0 1) := by refine continuousOn_of_forall_continuousAt fun t ht ↦ ((continuousAt_sign_of_ne_zero ?_).comp (((s.signedInfDist j).cont.comp ?_).continuousAt)) · intro h0 rw [← abs_eq_zero, abs_signedInfDist_eq_dist_of_mem_affineSpan_range] at h0 · rw [orthogonalProjectionSpan, dist_orthogonalProjection_eq_zero_iff] at h0 by_cases ht1 : t = 1 · subst ht1 rw [AffineMap.lineMap_apply_one] at h0 exact h.touchpoint_notMem_affineSpan_of_ne hne h0 · refine (h.isTangentAt_touchpoint j).isTangent.notMem_of_dist_lt ?_ h0 simp only [exsphere_center, dist_lineMap_left, Real.norm_eq_abs, h.dist_excenter, exsphere_radius, h.exradius_pos, mul_lt_iff_lt_one_left] rw [abs_lt] rcases ht with ⟨ht0, ht1'⟩ exact ⟨by linarith, ht1'.lt_of_ne ht1⟩ · exact AffineMap.lineMap_mem _ h.excenter_mem_affineSpan_range (s.touchpoint_mem_affineSpan_simplex _ _) · rw [← ContinuousAffineMap.lineMap_toAffineMap] exact ContinuousAffineMap.cont _ refine ((isConnected_Icc zero_le_one).image _ hc).isPreconnected.subsingleton (Set.mem_image_of_mem _ hr) ?_ convert Set.mem_image_of_mem _ (Set.left_mem_Icc.2 (zero_le_one' ℝ)) simp lemma sign_signedInfDist_lineMap_incenter_touchpoint {i j : Fin (n + 1)} (hne : i ≠ j) {r : ℝ} (hr : r ∈ Set.Icc 0 1) : SignType.sign (s.signedInfDist j (AffineMap.lineMap s.incenter (s.touchpoint ∅ i) r)) = SignType.sign (s.signedInfDist j s.incenter) := s.excenterExists_empty.sign_signedInfDist_lineMap_excenter_touchpoint hne hr variable {s} in lemma ExcenterExists.sign_signedInfDist_touchpoint {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) {i j : Fin (n + 1)} (hne : i ≠ j) : SignType.sign (s.signedInfDist j (s.touchpoint signs i)) = SignType.sign (s.signedInfDist j (s.excenter signs)) := by rw [← h.sign_signedInfDist_lineMap_excenter_touchpoint hne (r := 1) ⟨zero_le_one, le_rfl⟩] simp lemma sign_signedInfDist_touchpoint_empty {i j : Fin (n + 1)} (hne : i ≠ j) : SignType.sign (s.signedInfDist j (s.touchpoint ∅ i)) = SignType.sign (s.signedInfDist j s.incenter) := s.excenterExists_empty.sign_signedInfDist_touchpoint hne /-- The unique weights of the vertices in an affine combination equal to the given touchpoint. -/ def touchpointWeights (signs : Finset (Fin (n + 1))) (i : Fin (n + 1)) : Fin (n + 1) → ℝ := (eq_affineCombination_of_mem_affineSpan_of_fintype (s.touchpoint_mem_affineSpan_simplex signs i)).choose @[simp] lemma sum_touchpointWeights (signs : Finset (Fin (n + 1))) (i : Fin (n + 1)) : ∑ j, s.touchpointWeights signs i j = 1 := (eq_affineCombination_of_mem_affineSpan_of_fintype (s.touchpoint_mem_affineSpan_simplex signs i)).choose_spec.1 @[simp] lemma affineCombination_touchpointWeights (signs : Finset (Fin (n + 1))) (i : Fin (n + 1)) : Finset.univ.affineCombination ℝ s.points (s.touchpointWeights signs i) = s.touchpoint signs i := (eq_affineCombination_of_mem_affineSpan_of_fintype (s.touchpoint_mem_affineSpan_simplex signs i)).choose_spec.2.symm variable {s} in @[simp] lemma affineCombination_eq_touchpoint_iff {signs : Finset (Fin (n + 1))} {i : Fin (n + 1)} {w : Fin (n + 1) → ℝ} (hw : ∑ j, w j = 1) : Finset.univ.affineCombination ℝ s.points w = s.touchpoint signs i ↔ w = s.touchpointWeights signs i := by constructor · rw [← s.affineCombination_touchpointWeights] exact fun h ↦ (affineIndependent_iff_eq_of_fintype_affineCombination_eq ℝ s.points).1 s.independent _ _ hw (s.sum_touchpointWeights _ _) h · rintro rfl simp variable {s} in lemma ExcenterExists.sign_touchpointWeights {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) {i j : Fin (n + 1)} (hne : i ≠ j) : SignType.sign (s.touchpointWeights signs i j) = SignType.sign (s.excenterWeights signs j) := by have hs := h.sign_signedInfDist_touchpoint hne rw [← s.affineCombination_touchpointWeights signs i, h.sign_signedInfDist_excenter, s.signedInfDist_affineCombination j (by simp)] at hs rw [← hs, sign_mul] convert (mul_one _).symm rw [sign_eq_one_iff, ← dist_eq_norm_vsub] exact s.height_pos _ lemma sign_touchpointWeights_empty {i j : Fin (n + 1)} (hne : i ≠ j) : SignType.sign (s.touchpointWeights ∅ i j) = 1 := by rw [s.excenterExists_empty.sign_touchpointWeights hne] simp variable {s} in @[simp] lemma touchpointWeights_eq_zero {signs : Finset (Fin (n + 1))} (i : Fin (n + 1)) : s.touchpointWeights signs i i = 0 := by refine s.independent.eq_zero_of_affineCombination_mem_affineSpan (s.sum_touchpointWeights signs i) ?_ (Finset.mem_univ _) (Set.notMem_compl_iff.2 (Set.mem_singleton _)) rw [s.affineCombination_touchpointWeights] convert s.touchpoint_mem_affineSpan _ _ simp lemma touchpointWeights_empty_pos {i j : Fin (n + 1)} (hne : i ≠ j) : 0 < s.touchpointWeights ∅ i j := by simpa [sign_eq_one_iff] using s.sign_touchpointWeights_empty hne attribute [local instance] Nat.AtLeastTwo.neZero_sub_one lemma touchpoint_empty_mem_interior_faceOpposite [Nat.AtLeastTwo n] (i : Fin (n + 1)) : s.touchpoint ∅ i ∈ (s.faceOpposite i).interior := by rw [faceOpposite, ← affineCombination_touchpointWeights, s.affineCombination_mem_interior_face_iff_pos _ (s.sum_touchpointWeights _ _)] simp only [Finset.mem_compl, Finset.mem_singleton, Decidable.not_not, forall_eq, touchpointWeights_eq_zero, and_true] intro j hj exact s.touchpointWeights_empty_pos (Ne.symm hj) lemma sign_touchpointWeights_singleton_pos [Nat.AtLeastTwo n] {i j : Fin (n + 1)} (hne : i ≠ j) : SignType.sign (s.touchpointWeights {i} i j) = 1 := by rw [(s.excenterExists_singleton i).sign_touchpointWeights hne, s.sign_excenterWeights_singleton_pos hne] lemma touchpointWeights_singleton_pos [Nat.AtLeastTwo n] {i j : Fin (n + 1)} (hne : i ≠ j) : 0 < s.touchpointWeights {i} i j := by simpa [sign_eq_one_iff] using s.sign_touchpointWeights_singleton_pos hne lemma touchpoint_singleton_mem_interior_faceOpposite [Nat.AtLeastTwo n] (i : Fin (n + 1)) : s.touchpoint {i} i ∈ (s.faceOpposite i).interior := by rw [faceOpposite, ← affineCombination_touchpointWeights, s.affineCombination_mem_interior_face_iff_pos _ (s.sum_touchpointWeights _ _)] simp only [Finset.mem_compl, Finset.mem_singleton, Decidable.not_not, forall_eq, touchpointWeights_eq_zero, and_true] intro j hj exact s.touchpointWeights_singleton_pos (Ne.symm hj) lemma sign_touchpointWeights_singleton_neg [Nat.AtLeastTwo n] {i j : Fin (n + 1)} (hne : i ≠ j) : SignType.sign (s.touchpointWeights {i} j i) = -1 := by rw [(s.excenterExists_singleton i).sign_touchpointWeights hne.symm, s.sign_excenterWeights_singleton_neg] lemma touchpointWeights_singleton_neg [Nat.AtLeastTwo n] {i j : Fin (n + 1)} (hne : i ≠ j) : s.touchpointWeights {i} j i < 0 := by simpa [sign_eq_neg_one_iff] using s.sign_touchpointWeights_singleton_neg hne variable {s} in lemma ExcenterExists.touchpoint_ne_point [Nat.AtLeastTwo n] {signs : Finset (Fin (n + 1))} (h : s.ExcenterExists signs) (i j : Fin (n + 1)) : s.touchpoint signs i ≠ s.points j := by intro he rw [eq_comm, ← Finset.univ.affineCombination_affineCombinationSingleWeights ℝ s.points (Finset.mem_univ _), affineCombination_eq_touchpoint_iff (Finset.univ.sum_affineCombinationSingleWeights ℝ (Finset.mem_univ _))] at he have : 1 < n := Nat.AtLeastTwo.one_lt obtain ⟨k, hki, hkj⟩ : ∃ k, k ≠ i ∧ k ≠ j := Fin.exists_ne_and_ne_of_two_lt i j (by cutsat) have he' : Finset.affineCombinationSingleWeights ℝ j k = s.touchpointWeights signs i k := by rw [he] simp only [ne_eq, hkj, not_false_eq_true, Finset.affineCombinationSingleWeights_apply_of_ne] at he' rw [eq_comm] at he' apply_fun SignType.sign at he' rw [h.sign_touchpointWeights hki.symm, excenterWeights] at he' have h' := h rw [ExcenterExists] at h' simp only [Pi.smul_apply, smul_eq_mul, sign_zero, sign_eq_zero_iff, mul_eq_zero, inv_eq_zero, h', false_or] at he' rw [excenterWeightsUnnorm] at he' by_cases hk : k ∈ signs <;> simp [hk, (s.height_pos k).ne'] at he' lemma touchpoint_empty_ne_point [Nat.AtLeastTwo n] (i j : Fin (n + 1)) : s.touchpoint ∅ i ≠ s.points j := s.excenterExists_empty.touchpoint_ne_point i j end Simplex namespace Triangle variable (t : Triangle ℝ P) /-- All excenters exist for a triangle. -/ lemma excenterExists (signs : Finset (Fin 3)) : t.ExcenterExists signs := by have h : signs = ∅ ∨ signs = ∅ᶜ ∨ ∃ i, signs = {i} ∨ signs = {i}ᶜ := by decide +revert rcases h with rfl | rfl | ⟨i, rfl | rfl⟩ · exact t.excenterExists_empty · rw [Simplex.excenterExists_compl] exact t.excenterExists_empty · exact t.excenterExists_singleton _ · rw [Simplex.excenterExists_compl] exact t.excenterExists_singleton _ /-- An excenter of a triangle is either the incenter or the excenter opposite a vertex. -/ lemma excenter_eq_incenter_or_excenter_singleton (signs : Finset (Fin 3)) : t.excenter signs = t.incenter ∨ ∃ i, t.excenter signs = t.excenter {i} := by have h : signs = ∅ ∨ signs = Finset.univ ∨ ∃ i, signs = {i} ∨ signs = {i}ᶜ := by decide +revert rcases h with rfl | rfl | ⟨i, rfl | rfl⟩ · exact .inl rfl · exact .inl t.excenter_univ · exact .inr ⟨i, rfl⟩ · refine .inr ⟨i, ?_⟩ rw [t.excenter_compl] /-- An excenter of a triangle is either the incenter or the excenter opposite one of three enumerated different vertices. This is intended for when it is known a point is an excenter and it is to be proved which excenter it is by elimination of the other cases. -/ lemma excenter_eq_incenter_or_excenter_singleton_of_ne (signs : Finset (Fin 3)) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : t.excenter signs = t.incenter ∨ t.excenter signs = t.excenter {i₁} ∨ t.excenter signs = t.excenter {i₂} ∨ t.excenter signs = t.excenter {i₃} := by rcases t.excenter_eq_incenter_or_excenter_singleton signs with h | ⟨i, h⟩ · exact .inl h · refine .inr ?_ rw [h] have : i = i₁ ∨ i = i₂ ∨ i = i₃ := by clear h; decide +revert grind lemma sbtw_touchpoint_empty {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : Sbtw ℝ (t.points i₁) (t.touchpoint ∅ i₂) (t.points i₃) := by rw [← t.mem_interior_face_iff_sbtw h₁₃] convert t.touchpoint_empty_mem_interior_faceOpposite i₂ rw [Affine.Simplex.faceOpposite] convert rfl using 2 decide +revert lemma sbtw_touchpoint_singleton {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : Sbtw ℝ (t.points i₁) (t.touchpoint {i₂} i₂) (t.points i₃) := by rw [← t.mem_interior_face_iff_sbtw h₁₃] convert t.touchpoint_singleton_mem_interior_faceOpposite i₂ rw [Affine.Simplex.faceOpposite] convert rfl using 2 decide +revert lemma touchpoint_singleton_sbtw {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : Sbtw ℝ (t.touchpoint {i₁} i₂) (t.points i₃) (t.points i₁) := by rw [← Affine.Simplex.affineCombination_touchpointWeights] have hw := t.sum_touchpointWeights {i₁} i₂ rw [(by clear hw; decide +revert : (Finset.univ : Finset (Fin 3)) = {i₁, i₂, i₃})] at hw simp only [Nat.reduceAdd, Finset.mem_insert, h₁₂, Finset.mem_singleton, h₁₃, or_self, not_false_eq_true, Finset.sum_insert, h₂₃, Simplex.touchpointWeights_eq_zero, Finset.sum_singleton, zero_add] at hw have h : t.touchpointWeights {i₁} i₂ = Finset.affineCombinationLineMapWeights i₁ i₃ (t.touchpointWeights {i₁} i₂ i₃) := by ext i have h : i = i₁ ∨ i = i₂ ∨ i = i₃ := by clear hw; decide +revert rcases h with rfl | rfl | rfl · rw [Finset.affineCombinationLineMapWeights_apply_left h₁₃] simp [← hw] · simp [h₁₂.symm, h₂₃] · simp [h₁₃] rw [h, Finset.univ.affineCombination_affineCombinationLineMapWeights _ (Finset.mem_univ _) (Finset.mem_univ _), sbtw_iff_right_ne_and_left_mem_image_Ioi] simp [t.independent.injective.ne h₁₃, ← hw, t.touchpointWeights_singleton_neg h₁₂] end Triangle end Affine
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/PerpBisector.lean
import Mathlib.Analysis.InnerProductSpace.Orthogonal import Mathlib.Analysis.Normed.Group.AddTorsor /-! # Perpendicular bisector of a segment We define `AffineSubspace.perpBisector p₁ p₂` to be the perpendicular bisector of the segment `[p₁, p₂]`, as a bundled affine subspace. We also prove that a point belongs to the perpendicular bisector if and only if it is equidistant from `p₁` and `p₂`, as well as a few linear equations that define this subspace. ## Keywords euclidean geometry, perpendicular, perpendicular bisector, line segment bisector, equidistant -/ open Set open scoped RealInnerProductSpace variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] noncomputable section namespace AffineSubspace variable {c p₁ p₂ : P} /-- Perpendicular bisector of a segment in a Euclidean affine space. -/ def perpBisector (p₁ p₂ : P) : AffineSubspace ℝ P := mk' (midpoint ℝ p₁ p₂) (LinearMap.ker (innerₛₗ ℝ (p₂ -ᵥ p₁))) /-- A point `c` belongs the perpendicular bisector of `[p₁, p₂]` iff `p₂ -ᵥ p₁` is orthogonal to `c -ᵥ midpoint ℝ p₁ p₂`. -/ theorem mem_perpBisector_iff_inner_eq_zero' : c ∈ perpBisector p₁ p₂ ↔ ⟪p₂ -ᵥ p₁, c -ᵥ midpoint ℝ p₁ p₂⟫ = 0 := Iff.rfl /-- A point `c` belongs the perpendicular bisector of `[p₁, p₂]` iff `c -ᵥ midpoint ℝ p₁ p₂` is orthogonal to `p₂ -ᵥ p₁`. -/ theorem mem_perpBisector_iff_inner_eq_zero : c ∈ perpBisector p₁ p₂ ↔ ⟪c -ᵥ midpoint ℝ p₁ p₂, p₂ -ᵥ p₁⟫ = 0 := inner_eq_zero_symm theorem mem_perpBisector_iff_inner_pointReflection_vsub_eq_zero : c ∈ perpBisector p₁ p₂ ↔ ⟪Equiv.pointReflection c p₁ -ᵥ p₂, p₂ -ᵥ p₁⟫ = 0 := by rw [mem_perpBisector_iff_inner_eq_zero, Equiv.pointReflection_apply, vsub_midpoint, invOf_eq_inv, ← smul_add, real_inner_smul_left, vadd_vsub_assoc] simp theorem mem_perpBisector_pointReflection_iff_inner_eq_zero : c ∈ perpBisector p₁ (Equiv.pointReflection p₂ p₁) ↔ ⟪c -ᵥ p₂, p₁ -ᵥ p₂⟫ = 0 := by rw [mem_perpBisector_iff_inner_eq_zero, midpoint_pointReflection_right, Equiv.pointReflection_apply, vadd_vsub_assoc, inner_add_right, add_self_eq_zero, ← neg_eq_zero, ← inner_neg_right, neg_vsub_eq_vsub_rev] theorem midpoint_mem_perpBisector (p₁ p₂ : P) : midpoint ℝ p₁ p₂ ∈ perpBisector p₁ p₂ := by simp [mem_perpBisector_iff_inner_eq_zero] theorem perpBisector_nonempty : (perpBisector p₁ p₂ : Set P).Nonempty := ⟨_, midpoint_mem_perpBisector _ _⟩ @[simp] theorem direction_perpBisector (p₁ p₂ : P) : (perpBisector p₁ p₂).direction = (ℝ ∙ (p₂ -ᵥ p₁))ᗮ := by rw [perpBisector, direction_mk'] ext x exact Submodule.mem_orthogonal_singleton_iff_inner_right.symm theorem mem_perpBisector_iff_inner_eq_inner : c ∈ perpBisector p₁ p₂ ↔ ⟪c -ᵥ p₁, p₂ -ᵥ p₁⟫ = ⟪c -ᵥ p₂, p₁ -ᵥ p₂⟫ := by rw [Iff.comm, mem_perpBisector_iff_inner_eq_zero, ← add_neg_eq_zero, ← inner_neg_right, neg_vsub_eq_vsub_rev, ← inner_add_left, vsub_midpoint, invOf_eq_inv, ← smul_add, real_inner_smul_left]; simp theorem mem_perpBisector_iff_inner_eq : c ∈ perpBisector p₁ p₂ ↔ ⟪c -ᵥ p₁, p₂ -ᵥ p₁⟫ = (dist p₁ p₂) ^ 2 / 2 := by rw [mem_perpBisector_iff_inner_eq_zero, ← vsub_sub_vsub_cancel_right _ _ p₁, inner_sub_left, sub_eq_zero, midpoint_vsub_left, invOf_eq_inv, real_inner_smul_left, real_inner_self_eq_norm_sq, dist_eq_norm_vsub' V, div_eq_inv_mul] theorem mem_perpBisector_iff_dist_eq : c ∈ perpBisector p₁ p₂ ↔ dist c p₁ = dist c p₂ := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← real_inner_add_sub_eq_zero_iff, vsub_sub_vsub_cancel_left, inner_add_left, add_eq_zero_iff_eq_neg, ← inner_neg_right, neg_vsub_eq_vsub_rev, mem_perpBisector_iff_inner_eq_inner] theorem mem_perpBisector_iff_dist_eq' : c ∈ perpBisector p₁ p₂ ↔ dist p₁ c = dist p₂ c := by simp only [mem_perpBisector_iff_dist_eq, dist_comm] theorem perpBisector_comm (p₁ p₂ : P) : perpBisector p₁ p₂ = perpBisector p₂ p₁ := by ext c; simp only [mem_perpBisector_iff_dist_eq, eq_comm] @[simp] theorem right_mem_perpBisector : p₂ ∈ perpBisector p₁ p₂ ↔ p₁ = p₂ := by simpa [mem_perpBisector_iff_inner_eq_inner] using eq_comm @[simp] theorem left_mem_perpBisector : p₁ ∈ perpBisector p₁ p₂ ↔ p₁ = p₂ := by rw [perpBisector_comm, right_mem_perpBisector, eq_comm] @[simp] theorem perpBisector_self (p : P) : perpBisector p p = ⊤ := top_unique fun _ ↦ by simp [mem_perpBisector_iff_inner_eq_inner] @[simp] theorem perpBisector_eq_top : perpBisector p₁ p₂ = ⊤ ↔ p₁ = p₂ := by refine ⟨fun h ↦ ?_, fun h ↦ h ▸ perpBisector_self _⟩ rw [← left_mem_perpBisector, h] trivial @[simp] theorem perpBisector_ne_bot : perpBisector p₁ p₂ ≠ ⊥ := by rw [← nonempty_iff_ne_bot]; exact perpBisector_nonempty end AffineSubspace open AffineSubspace namespace EuclideanGeometry /-- Suppose that `c₁` is equidistant from `p₁` and `p₂`, and the same applies to `c₂`. Then the vector between `c₁` and `c₂` is orthogonal to that between `p₁` and `p₂`. (In two dimensions, this says that the diagonals of a kite are orthogonal.) -/ theorem inner_vsub_vsub_of_dist_eq_of_dist_eq {c₁ c₂ p₁ p₂ : P} (hc₁ : dist p₁ c₁ = dist p₂ c₁) (hc₂ : dist p₁ c₂ = dist p₂ c₂) : ⟪c₂ -ᵥ c₁, p₂ -ᵥ p₁⟫ = 0 := by rw [← Submodule.mem_orthogonal_singleton_iff_inner_left, ← direction_perpBisector] apply vsub_mem_direction <;> rwa [mem_perpBisector_iff_dist_eq'] end EuclideanGeometry variable {V' P' : Type*} [NormedAddCommGroup V'] [InnerProductSpace ℝ V'] [MetricSpace P'] variable [NormedAddTorsor V' P'] theorem Isometry.preimage_perpBisector {f : P → P'} (h : Isometry f) (p₁ p₂ : P) : f ⁻¹' (perpBisector (f p₁) (f p₂)) = perpBisector p₁ p₂ := by ext x; simp [mem_perpBisector_iff_dist_eq, h.dist_eq] theorem Isometry.mapsTo_perpBisector {f : P → P'} (h : Isometry f) (p₁ p₂ : P) : MapsTo f (perpBisector p₁ p₂) (perpBisector (f p₁) (f p₂)) := (h.preimage_perpBisector p₁ p₂).ge
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Projection.lean
import Mathlib.Analysis.InnerProductSpace.Projection.Submodule import Mathlib.Analysis.InnerProductSpace.Projection.Reflection import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Topology.Algebra.ContinuousAffineMap /-! # Orthogonal projection in Euclidean affine spaces This file defines orthogonal projection onto an affine subspace in a Euclidean affine space, and reflection of a point in an affine subspace. ## Main definitions * `EuclideanGeometry.orthogonalProjection` is the orthogonal projection of a point onto an affine subspace. * `EuclideanGeometry.reflection` is the reflection of a point in an affine subspace. -/ noncomputable section open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] open AffineSubspace Module /-- The orthogonal projection of a point onto a nonempty affine subspace, whose direction is complete, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonalProjection` and should not be used once that is defined. -/ def orthogonalProjectionFn (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : P := Classical.choose <| inter_eq_singleton_of_nonempty_of_isCompl (nonempty_subtype.mp ‹_›) (mk'_nonempty p s.directionᗮ) (by rw [direction_mk' p s.directionᗮ] exact Submodule.isCompl_orthogonal_of_hasOrthogonalProjection) /-- The intersection of the subspace and the orthogonal subspace through the given point is the `orthogonalProjectionFn` of that point onto the subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem inter_eq_singleton_orthogonalProjectionFn {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : (s : Set P) ∩ mk' p s.directionᗮ = {orthogonalProjectionFn s p} := Classical.choose_spec <| inter_eq_singleton_of_nonempty_of_isCompl (nonempty_subtype.mp ‹_›) (mk'_nonempty p s.directionᗮ) (by rw [direction_mk' p s.directionᗮ] exact Submodule.isCompl_orthogonal_of_hasOrthogonalProjection) /-- The `orthogonalProjectionFn` lies in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : orthogonalProjectionFn s p ∈ s := by rw [← mem_coe, ← Set.singleton_subset_iff, ← inter_eq_singleton_orthogonalProjectionFn] exact Set.inter_subset_left /-- The `orthogonalProjectionFn` lies in the orthogonal subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem_orthogonal {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : orthogonalProjectionFn s p ∈ mk' p s.directionᗮ := by rw [← mem_coe, ← Set.singleton_subset_iff, ← inter_eq_singleton_orthogonalProjectionFn] exact Set.inter_subset_right /-- Subtracting `p` from its `orthogonalProjectionFn` produces a result in the orthogonal direction. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_vsub_mem_direction_orthogonal {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : orthogonalProjectionFn s p -ᵥ p ∈ s.directionᗮ := direction_mk' p s.directionᗮ ▸ vsub_mem_direction (orthogonalProjectionFn_mem_orthogonal p) (self_mem_mk' _ _) /-- Auxiliary definition for setting up the orthogonal projection. This one is a bundled affine map; the final `orthogonalProjection` is a continuous affine map. -/ nonrec def orthogonalProjectionAux (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] : P →ᵃ[ℝ] s where toFun p := ⟨orthogonalProjectionFn s p, orthogonalProjectionFn_mem p⟩ linear := s.direction.orthogonalProjection map_vadd' p v := by have hs : s.direction.starProjection v +ᵥ orthogonalProjectionFn s p ∈ s := vadd_mem_of_mem_direction (s.direction.orthogonalProjection v).2 (orthogonalProjectionFn_mem p) have ho : s.direction.starProjection v +ᵥ orthogonalProjectionFn s p ∈ mk' (v +ᵥ p) s.directionᗮ := by rw [← vsub_right_mem_direction_iff_mem (self_mem_mk' _ _) _, direction_mk', vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_comm, add_sub_assoc] refine Submodule.add_mem _ (orthogonalProjectionFn_vsub_mem_direction_orthogonal p) ?_ rw [Submodule.mem_orthogonal'] intro w hw rw [← neg_sub, inner_neg_left, Submodule.starProjection_inner_eq_zero _ w hw, neg_zero] have hm : (s.direction.orthogonalProjection v : V) +ᵥ orthogonalProjectionFn s p ∈ ({orthogonalProjectionFn s (v +ᵥ p)} : Set P) := by rw [← inter_eq_singleton_orthogonalProjectionFn (v +ᵥ p)] exact Set.mem_inter hs ho rw [Set.mem_singleton_iff] at hm ext exact hm.symm /-- The orthogonal projection of a point onto a nonempty affine subspace, whose direction is complete. The corresponding linear map (mapping a vector to the difference between the projections of two points whose difference is that vector) is the `orthogonalProjection` for real inner product spaces, onto the direction of the affine subspace being projected onto. -/ nonrec def orthogonalProjection (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] : P →ᴬ[ℝ] s where __ := orthogonalProjectionAux s cont := AffineMap.continuous_linear_iff.1 s.direction.orthogonalProjection.cont @[simp] theorem orthogonalProjectionFn_eq {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : orthogonalProjectionFn s p = orthogonalProjection s p := rfl /-- Since both instance arguments are propositions, allow `simp` to rewrite them alongside the `s` argument. Note that without the coercion to `P`, the LHS and RHS would have different types. -/ @[congr] theorem orthogonalProjection_congr {s₁ s₂ : AffineSubspace ℝ P} {p₁ p₂ : P} [Nonempty s₁] [s₁.direction.HasOrthogonalProjection] (h : s₁ = s₂) (hp : p₁ = p₂) : letI : Nonempty s₂ := h ▸ ‹_› letI : s₂.direction.HasOrthogonalProjection := h ▸ ‹_› (orthogonalProjection s₁ p₁ : P) = (orthogonalProjection s₂ p₂ : P) := by subst h hp rfl /-- The linear map corresponding to `orthogonalProjection`. -/ @[simp] theorem orthogonalProjection_linear {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] : (orthogonalProjection s).linear = s.direction.orthogonalProjection := rfl /-- The continuous linear map corresponding to `orthogonalProjection`. -/ @[simp] theorem orthogonalProjection_contLinear {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] : (orthogonalProjection s).contLinear = s.direction.orthogonalProjection := rfl /-- The intersection of the subspace and the orthogonal subspace through the given point is the `orthogonalProjection` of that point onto the subspace. -/ theorem inter_eq_singleton_orthogonalProjection {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : (s : Set P) ∩ mk' p s.directionᗮ = {↑(orthogonalProjection s p)} := by rw [← orthogonalProjectionFn_eq] exact inter_eq_singleton_orthogonalProjectionFn p /-- The `orthogonalProjection` lies in the given subspace. -/ theorem orthogonalProjection_mem {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : ↑(orthogonalProjection s p) ∈ s := (orthogonalProjection s p).2 /-- The `orthogonalProjection` lies in the orthogonal subspace. -/ theorem orthogonalProjection_mem_orthogonal (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : ↑(orthogonalProjection s p) ∈ mk' p s.directionᗮ := orthogonalProjectionFn_mem_orthogonal p /-- Subtracting a point in the given subspace from the `orthogonalProjection` produces a result in the direction of the given subspace. -/ theorem orthogonalProjection_vsub_mem_direction {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p₁ : P} (p₂ : P) (hp₁ : p₁ ∈ s) : ↑(orthogonalProjection s p₂ -ᵥ ⟨p₁, hp₁⟩ : s.direction) ∈ s.direction := (orthogonalProjection s p₂ -ᵥ ⟨p₁, hp₁⟩ : s.direction).2 /-- Subtracting the `orthogonalProjection` from a point in the given subspace produces a result in the direction of the given subspace. -/ theorem vsub_orthogonalProjection_mem_direction {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p₁ : P} (p₂ : P) (hp₁ : p₁ ∈ s) : ↑((⟨p₁, hp₁⟩ : s) -ᵥ orthogonalProjection s p₂ : s.direction) ∈ s.direction := ((⟨p₁, hp₁⟩ : s) -ᵥ orthogonalProjection s p₂ : s.direction).2 /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ theorem orthogonalProjection_eq_self_iff {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p : P} : ↑(orthogonalProjection s p) = p ↔ p ∈ s := by constructor · exact fun h => h ▸ orthogonalProjection_mem p · intro h have hp : p ∈ (s : Set P) ∩ mk' p s.directionᗮ := ⟨h, self_mem_mk' p _⟩ rw [inter_eq_singleton_orthogonalProjection p] at hp symm exact hp @[simp] theorem orthogonalProjection_mem_subspace_eq_self {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : s) : orthogonalProjection s p = p := by ext rw [orthogonalProjection_eq_self_iff] exact p.2 /-- Orthogonal projection is idempotent. -/ theorem orthogonalProjection_orthogonalProjection (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : orthogonalProjection s (orthogonalProjection s p) = orthogonalProjection s p := orthogonalProjection_mem_subspace_eq_self ((orthogonalProjection s) p) theorem eq_orthogonalProjection_of_eq_subspace {s s' : AffineSubspace ℝ P} [Nonempty s] [Nonempty s'] [s.direction.HasOrthogonalProjection] [s'.direction.HasOrthogonalProjection] (h : s = s') (p : P) : (orthogonalProjection s p : P) = (orthogonalProjection s' p : P) := by subst h rfl @[simp] lemma orthogonalProjection_affineSpan_singleton (p₁ p₂ : P) : orthogonalProjection (affineSpan ℝ {p₁}) p₂ = p₁ := by have h := SetLike.coe_mem (orthogonalProjection (affineSpan ℝ {p₁}) p₂) rwa [mem_affineSpan_singleton] at h /-- The distance to a point's orthogonal projection is 0 iff it lies in the subspace. -/ theorem dist_orthogonalProjection_eq_zero_iff {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p : P} : dist p (orthogonalProjection s p) = 0 ↔ p ∈ s := by rw [dist_comm, dist_eq_zero, orthogonalProjection_eq_self_iff] /-- The distance between a point and its orthogonal projection is nonzero if it does not lie in the subspace. -/ theorem dist_orthogonalProjection_ne_zero_of_notMem {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p : P} (hp : p ∉ s) : dist p (orthogonalProjection s p) ≠ 0 := mt dist_orthogonalProjection_eq_zero_iff.mp hp @[deprecated (since := "2025-05-23")] alias dist_orthogonalProjection_ne_zero_of_not_mem := dist_orthogonalProjection_ne_zero_of_notMem /-- Subtracting `p` from its `orthogonalProjection` produces a result in the orthogonal direction. -/ theorem orthogonalProjection_vsub_mem_direction_orthogonal (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : (orthogonalProjection s p : P) -ᵥ p ∈ s.directionᗮ := orthogonalProjectionFn_vsub_mem_direction_orthogonal p /-- Subtracting the `orthogonalProjection` from `p` produces a result in the orthogonal direction. -/ theorem vsub_orthogonalProjection_mem_direction_orthogonal (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : p -ᵥ orthogonalProjection s p ∈ s.directionᗮ := direction_mk' p s.directionᗮ ▸ vsub_mem_direction (self_mem_mk' _ _) (orthogonalProjection_mem_orthogonal s p) /-- Subtracting the `orthogonalProjection` from `p` produces a result in the kernel of the linear part of the orthogonal projection. -/ theorem orthogonalProjection_vsub_orthogonalProjection (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : s.direction.orthogonalProjection (p -ᵥ orthogonalProjection s p) = 0 := by apply Submodule.orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero intro c hc rw [← neg_vsub_eq_vsub_rev, inner_neg_right, orthogonalProjection_vsub_mem_direction_orthogonal s p c hc, neg_zero] /-- The characteristic property of the orthogonal projection, for a point given in the underlying space. This form is typically more convenient to use than `inter_eq_singleton_orthogonalProjection`. -/ lemma coe_orthogonalProjection_eq_iff_mem {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p q : P} : orthogonalProjection s p = q ↔ q ∈ s ∧ p -ᵥ q ∈ s.directionᗮ := by constructor · rintro rfl exact ⟨orthogonalProjection_mem _, vsub_orthogonalProjection_mem_direction_orthogonal _ _⟩ · rintro ⟨hqs, hpq⟩ have hq : q ∈ mk' p s.directionᗮ := by rwa [mem_mk', ← neg_mem_iff, neg_vsub_eq_vsub_rev] suffices q ∈ ({(orthogonalProjection s p : P)} : Set P) by simpa [eq_comm] using this rw [← inter_eq_singleton_orthogonalProjection] simp only [Set.mem_inter_iff, SetLike.mem_coe] exact ⟨hqs, hq⟩ /-- The characteristic property of the orthogonal projection, for a point given in the relevant subspace. This form is typically more convenient to use than `inter_eq_singleton_orthogonalProjection`. -/ lemma orthogonalProjection_eq_iff_mem {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p : P} {q : s} : orthogonalProjection s p = q ↔ p -ᵥ q ∈ s.directionᗮ := by simpa using coe_orthogonalProjection_eq_iff_mem (s := s) (p := p) (q := (q : P)) /-- A condition for two points to have the same orthogonal projection onto a given subspace. -/ lemma orthogonalProjection_eq_orthogonalProjection_iff_vsub_mem {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p q : P} : orthogonalProjection s p = orthogonalProjection s q ↔ p -ᵥ q ∈ s.directionᗮ := by rw [orthogonalProjection_eq_iff_mem, ← s.directionᗮ.add_mem_iff_left (x := p -ᵥ q) (vsub_orthogonalProjection_mem_direction_orthogonal s q)] simp /-- If the orthogonal projections of a point onto two subspaces are equal, so is the projection onto their supremum. -/ lemma orthogonalProjection_sup_of_orthogonalProjection_eq {s₁ s₂ : AffineSubspace ℝ P} [Nonempty s₁] [Nonempty s₂] [s₁.direction.HasOrthogonalProjection] [s₂.direction.HasOrthogonalProjection] {p : P} (h : (orthogonalProjection s₁ p : P) = orthogonalProjection s₂ p) [(s₁ ⊔ s₂).direction.HasOrthogonalProjection] : (orthogonalProjection (s₁ ⊔ s₂) p : P) = orthogonalProjection s₁ p := by rw [coe_orthogonalProjection_eq_iff_mem] refine ⟨SetLike.le_def.1 le_sup_left (orthogonalProjection_mem _), ?_⟩ rw [direction_sup_eq_sup_direction (orthogonalProjection_mem p) (h ▸ orthogonalProjection_mem p), ← Submodule.inf_orthogonal] exact ⟨vsub_orthogonalProjection_mem_direction_orthogonal _ _, h ▸ vsub_orthogonalProjection_mem_direction_orthogonal _ _⟩ /-- Adding a vector to a point in the given subspace, then taking the orthogonal projection, produces the original point if the vector was in the orthogonal direction. -/ theorem orthogonalProjection_vadd_eq_self {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p : P} (hp : p ∈ s) {v : V} (hv : v ∈ s.directionᗮ) : orthogonalProjection s (v +ᵥ p) = ⟨p, hp⟩ := by have h := vsub_orthogonalProjection_mem_direction_orthogonal s (v +ᵥ p) rw [vadd_vsub_assoc, Submodule.add_mem_iff_right _ hv] at h refine (eq_of_vsub_eq_zero ?_).symm ext refine Submodule.disjoint_def.1 s.direction.orthogonal_disjoint _ ?_ h exact (_ : s.direction).2 /-- Adding a vector to a point in the given subspace, then taking the orthogonal projection, produces the original point if the vector is a multiple of the result of subtracting a point's orthogonal projection from that point. -/ theorem orthogonalProjection_vadd_smul_vsub_orthogonalProjection {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p₁ : P} (p₂ : P) (r : ℝ) (hp : p₁ ∈ s) : orthogonalProjection s (r • (p₂ -ᵥ orthogonalProjection s p₂ : V) +ᵥ p₁) = ⟨p₁, hp⟩ := orthogonalProjection_vadd_eq_self hp (Submodule.smul_mem _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s _)) lemma orthogonalProjection_orthogonalProjection_of_le {s₁ s₂ : AffineSubspace ℝ P} [Nonempty s₁] [Nonempty s₂] [s₁.direction.HasOrthogonalProjection] [s₂.direction.HasOrthogonalProjection] (h : s₁ ≤ s₂) (p : P) : orthogonalProjection s₁ (orthogonalProjection s₂ p) = orthogonalProjection s₁ p := by rw [orthogonalProjection_eq_orthogonalProjection_iff_vsub_mem] exact SetLike.le_def.1 (Submodule.orthogonal_le (direction_le h)) (orthogonalProjection_vsub_mem_direction_orthogonal _ _) /-- The square of the distance from a point in `s` to `p₂` equals the sum of the squares of the distances of the two points to the `orthogonalProjection`. -/ theorem dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p₁ : P} (p₂ : P) (hp₁ : p₁ ∈ s) : dist p₁ p₂ * dist p₁ p₂ = dist p₁ (orthogonalProjection s p₂) * dist p₁ (orthogonalProjection s p₂) + dist p₂ (orthogonalProjection s p₂) * dist p₂ (orthogonalProjection s p₂) := by rw [dist_comm p₂ _, dist_eq_norm_vsub V p₁ _, dist_eq_norm_vsub V p₁ _, dist_eq_norm_vsub V _ p₂, ← vsub_add_vsub_cancel p₁ (orthogonalProjection s p₂) p₂, norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact Submodule.inner_right_of_mem_orthogonal (vsub_orthogonalProjection_mem_direction p₂ hp₁) (orthogonalProjection_vsub_mem_direction_orthogonal s p₂) /-- The distance between a point and its orthogonal projection to a subspace equals the distance to that subspace as given by `Metric.infDist`. This is not a `simp` lemma since the simplest form depends on the context (if any calculations are to be done with the distance, the version with the orthogonal projection gives access to more lemmas about orthogonal projections that may be useful). -/ lemma dist_orthogonalProjection_eq_infDist (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : dist p (orthogonalProjection s p) = Metric.infDist p s := by refine le_antisymm ?_ (Metric.infDist_le_dist_of_mem (orthogonalProjection_mem _)) rw [Metric.infDist_eq_iInf] refine le_ciInf fun x ↦ le_of_sq_le_sq ?_ dist_nonneg rw [dist_comm _ (x : P)] simp_rw [pow_two, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p x.property] simp [mul_self_nonneg] /-- The nonnegative distance between a point and its orthogonal projection to a subspace equals the distance to that subspace as given by `Metric.infNndist`. This is not a `simp` lemma since the simplest form depends on the context (if any calculations are to be done with the distance, the version with the orthogonal projection gives access to more lemmas about orthogonal projections that may be useful). -/ lemma dist_orthogonalProjection_eq_infNndist (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : nndist p (orthogonalProjection s p) = Metric.infNndist p s := by rw [← NNReal.coe_inj] simp [dist_orthogonalProjection_eq_infDist] /-- The square of the distance between two points constructed by adding multiples of the same orthogonal vector to points in the same subspace. -/ theorem dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd {s : AffineSubspace ℝ P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (r₁ r₂ : ℝ) {v : V} (hv : v ∈ s.directionᗮ) : dist (r₁ • v +ᵥ p₁) (r₂ • v +ᵥ p₂) * dist (r₁ • v +ᵥ p₁) (r₂ • v +ᵥ p₂) = dist p₁ p₂ * dist p₁ p₂ + (r₁ - r₂) * (r₁ - r₂) * (‖v‖ * ‖v‖) := calc dist (r₁ • v +ᵥ p₁) (r₂ • v +ᵥ p₂) * dist (r₁ • v +ᵥ p₁) (r₂ • v +ᵥ p₂) = ‖p₁ -ᵥ p₂ + (r₁ - r₂) • v‖ * ‖p₁ -ᵥ p₂ + (r₁ - r₂) • v‖ := by rw [dist_eq_norm_vsub V (r₁ • v +ᵥ p₁), vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, sub_smul, add_comm, add_sub_assoc] _ = ‖p₁ -ᵥ p₂‖ * ‖p₁ -ᵥ p₂‖ + ‖(r₁ - r₂) • v‖ * ‖(r₁ - r₂) • v‖ := (norm_add_sq_eq_norm_sq_add_norm_sq_real (Submodule.inner_right_of_mem_orthogonal (vsub_mem_direction hp₁ hp₂) (Submodule.smul_mem _ _ hv))) _ = ‖(p₁ -ᵥ p₂ : V)‖ * ‖(p₁ -ᵥ p₂ : V)‖ + |r₁ - r₂| * |r₁ - r₂| * ‖v‖ * ‖v‖ := by rw [norm_smul, Real.norm_eq_abs] ring _ = dist p₁ p₂ * dist p₁ p₂ + (r₁ - r₂) * (r₁ - r₂) * (‖v‖ * ‖v‖) := by rw [dist_eq_norm_vsub V p₁, abs_mul_abs_self, mul_assoc] /-- `p` is equidistant from two points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p₁ p₂ : P} (p₃ : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) : dist p₁ p₃ = dist p₂ p₃ ↔ dist p₁ (orthogonalProjection s p₃) = dist p₂ (orthogonalProjection s p₃) := by rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, ← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₃ hp₁, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₃ hp₂] simp /-- `p` is equidistant from a set of points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_set_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {ps : Set P} (hps : ps ⊆ s) (p : P) : (Set.Pairwise ps fun p₁ p₂ => dist p₁ p = dist p₂ p) ↔ Set.Pairwise ps fun p₁ p₂ => dist p₁ (orthogonalProjection s p) = dist p₂ (orthogonalProjection s p) := ⟨fun h _ hp₁ _ hp₂ hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp₁) (hps hp₂)).1 (h hp₁ hp₂ hne), fun h _ hp₁ _ hp₂ hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp₁) (hps hp₂)).2 (h hp₁ hp₂ hne)⟩ /-- There exists `r` such that `p` has distance `r` from all the points of a set of points in `s` if and only if there exists (possibly different) `r` such that its `orthogonalProjection` has that distance from all the points in that set. -/ theorem exists_dist_eq_iff_exists_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {ps : Set P} (hps : ps ⊆ s) (p : P) : (∃ r, ∀ p₁ ∈ ps, dist p₁ p = r) ↔ ∃ r, ∀ p₁ ∈ ps, dist p₁ ↑(orthogonalProjection s p) = r := by have h := dist_set_eq_iff_dist_orthogonalProjection_eq hps p simp_rw [Set.pairwise_eq_iff_exists_eq] at h exact h /-- Reflection in an affine subspace, which is expected to be nonempty and complete. The word "reflection" is sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes more generally to cover operations such as reflection in a point. The definition here, of reflection in an affine subspace, is a more general sense of the word that includes both those common cases. -/ def reflection (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] : P ≃ᵃⁱ[ℝ] P := AffineIsometryEquiv.mk' (fun p => (↑(orthogonalProjection s p) -ᵥ p) +ᵥ (orthogonalProjection s p : P)) s.direction.reflection (↑(Classical.arbitrary s)) (by intro p let v := p -ᵥ ↑(Classical.arbitrary s) let a : V := s.direction.orthogonalProjection v let b : P := ↑(Classical.arbitrary s) have key : ((a +ᵥ b) -ᵥ (v +ᵥ b)) +ᵥ (a +ᵥ b) = (a + a - v) +ᵥ (b -ᵥ b) +ᵥ b := by rw [← add_vadd, vsub_vadd_eq_vsub_sub, vsub_vadd, vadd_vsub] congr 1 abel dsimp only rwa [Submodule.reflection_apply, (vsub_vadd p b).symm, ContinuousAffineMap.map_vadd, orthogonalProjection_contLinear, vadd_vsub, orthogonalProjection_mem_subspace_eq_self, two_smul]) /-- The result of reflecting. -/ theorem reflection_apply (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : reflection s p = (↑(orthogonalProjection s p) -ᵥ p) +ᵥ (orthogonalProjection s p : P) := rfl theorem eq_reflection_of_eq_subspace {s s' : AffineSubspace ℝ P} [Nonempty s] [Nonempty s'] [s.direction.HasOrthogonalProjection] [s'.direction.HasOrthogonalProjection] (h : s = s') (p : P) : (reflection s p : P) = (reflection s' p : P) := by subst h rfl /-- Reflecting twice in the same subspace. -/ @[simp] theorem reflection_reflection (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : reflection s (reflection s p) = p := by have : ∀ a : s, ∀ b : V, s.direction.orthogonalProjection b = 0 → reflection s (reflection s (b +ᵥ (a : P))) = b +ᵥ (a : P) := by intro _ _ h simp [reflection] rw [← vsub_vadd p (orthogonalProjection s p)] exact this (orthogonalProjection s p) _ (orthogonalProjection_vsub_orthogonalProjection s p) /-- Reflection is its own inverse. -/ @[simp] theorem reflection_symm (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] : (reflection s).symm = reflection s := by ext rw [← (reflection s).injective.eq_iff] simp /-- Reflection is involutive. -/ theorem reflection_involutive (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] : Function.Involutive (reflection s) := reflection_reflection s /-- A point is its own reflection if and only if it is in the subspace. -/ theorem reflection_eq_self_iff {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] (p : P) : reflection s p = p ↔ p ∈ s := by rw [← orthogonalProjection_eq_self_iff, reflection_apply] constructor · intro h rw [← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, ← two_smul ℝ (↑(orthogonalProjection s p) -ᵥ p), smul_eq_zero] at h norm_num at h exact h · intro h simp [h] /-- Reflecting a point in two subspaces produces the same result if and only if the point has the same orthogonal projection in each of those subspaces. -/ theorem reflection_eq_iff_orthogonalProjection_eq (s₁ s₂ : AffineSubspace ℝ P) [Nonempty s₁] [Nonempty s₂] [s₁.direction.HasOrthogonalProjection] [s₂.direction.HasOrthogonalProjection] (p : P) : reflection s₁ p = reflection s₂ p ↔ (orthogonalProjection s₁ p : P) = orthogonalProjection s₂ p := by rw [reflection_apply, reflection_apply] constructor · intro h rw [← @vsub_eq_zero_iff_eq V, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_comm, add_sub_assoc, vsub_sub_vsub_cancel_right, ← two_smul ℝ ((orthogonalProjection s₁ p : P) -ᵥ orthogonalProjection s₂ p), smul_eq_zero] at h norm_num at h exact h · intro h rw [h] /-- The distance between `p₁` and the reflection of `p₂` equals that between the reflection of `p₁` and `p₂`. -/ theorem dist_reflection (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] (p₁ p₂ : P) : dist p₁ (reflection s p₂) = dist (reflection s p₁) p₂ := by conv_lhs => rw [← reflection_reflection s p₁] exact (reflection s).dist_map _ _ /-- A point in the subspace is equidistant from another point and its reflection. -/ theorem dist_reflection_eq_of_mem (s : AffineSubspace ℝ P) [Nonempty s] [s.direction.HasOrthogonalProjection] {p₁ : P} (hp₁ : p₁ ∈ s) (p₂ : P) : dist p₁ (reflection s p₂) = dist p₁ p₂ := by rw [← reflection_eq_self_iff p₁] at hp₁ convert (reflection s).dist_map p₁ p₂ rw [hp₁] /-- The reflection of a point in a subspace is contained in any larger subspace containing both the point and the subspace reflected in. -/ theorem reflection_mem_of_le_of_mem {s₁ s₂ : AffineSubspace ℝ P} [Nonempty s₁] [s₁.direction.HasOrthogonalProjection] (hle : s₁ ≤ s₂) {p : P} (hp : p ∈ s₂) : reflection s₁ p ∈ s₂ := by rw [reflection_apply] have ho : ↑(orthogonalProjection s₁ p) ∈ s₂ := hle (orthogonalProjection_mem p) exact vadd_mem_of_mem_direction (vsub_mem_direction ho hp) ho /-- Reflecting an orthogonal vector plus a point in the subspace produces the negation of that vector plus the point. -/ theorem reflection_orthogonal_vadd {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p : P} (hp : p ∈ s) {v : V} (hv : v ∈ s.directionᗮ) : reflection s (v +ᵥ p) = -v +ᵥ p := by rw [reflection_apply, orthogonalProjection_vadd_eq_self hp hv, vsub_vadd_eq_vsub_sub] simp /-- Reflecting a vector plus a point in the subspace produces the negation of that vector plus the point if the vector is a multiple of the result of subtracting a point's orthogonal projection from that point. -/ theorem reflection_vadd_smul_vsub_orthogonalProjection {s : AffineSubspace ℝ P} [Nonempty s] [s.direction.HasOrthogonalProjection] {p₁ : P} (p₂ : P) (r : ℝ) (hp₁ : p₁ ∈ s) : reflection s (r • (p₂ -ᵥ orthogonalProjection s p₂) +ᵥ p₁) = -(r • (p₂ -ᵥ orthogonalProjection s p₂)) +ᵥ p₁ := reflection_orthogonal_vadd hp₁ (Submodule.smul_mem _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s _)) end EuclideanGeometry namespace Affine namespace Simplex open EuclideanGeometry variable {V : Type*} {P : Type*} variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] /-- The orthogonal projection of a point `p` onto the hyperplane spanned by the simplex's points. -/ def orthogonalProjectionSpan {n : ℕ} (s : Simplex ℝ P n) : P →ᴬ[ℝ] affineSpan ℝ (Set.range s.points) := orthogonalProjection (affineSpan ℝ (Set.range s.points)) lemma orthogonalProjectionSpan_congr {m n : ℕ} {s₁ : Simplex ℝ P m} {s₂ : Simplex ℝ P n} {p₁ p₂ : P} (h : Set.range s₁.points = Set.range s₂.points) (hp : p₁ = p₂) : (s₁.orthogonalProjectionSpan p₁ : P) = s₂.orthogonalProjectionSpan p₂ := orthogonalProjection_congr (by rw [h]) hp @[simp] lemma orthogonalProjectionSpan_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) (p : P) : ((s.reindex e).orthogonalProjectionSpan p : P) = s.orthogonalProjectionSpan p := orthogonalProjectionSpan_congr (s.reindex_range_points e) rfl /-- Adding a vector to a point in the given subspace, then taking the orthogonal projection, produces the original point if the vector is a multiple of the result of subtracting a point's orthogonal projection from that point. -/ theorem orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} (s : Simplex ℝ P n) {p₁ : P} (p₂ : P) (r : ℝ) (hp : p₁ ∈ affineSpan ℝ (Set.range s.points)) : s.orthogonalProjectionSpan (r • (p₂ -ᵥ s.orthogonalProjectionSpan p₂ : V) +ᵥ p₁) = ⟨p₁, hp⟩ := EuclideanGeometry.orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ theorem coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} {r₁ : ℝ} (s : Simplex ℝ P n) {p p₁o : P} (hp₁o : p₁o ∈ affineSpan ℝ (Set.range s.points)) : ↑(s.orthogonalProjectionSpan (r₁ • (p -ᵥ ↑(s.orthogonalProjectionSpan p)) +ᵥ p₁o)) = p₁o := congrArg ((↑) : _ → P) (orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ hp₁o) theorem dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq {n : ℕ} (s : Simplex ℝ P n) {p₁ : P} (p₂ : P) (hp₁ : p₁ ∈ affineSpan ℝ (Set.range s.points)) : dist p₁ p₂ * dist p₁ p₂ = dist p₁ (s.orthogonalProjectionSpan p₂) * dist p₁ (s.orthogonalProjectionSpan p₂) + dist p₂ (s.orthogonalProjectionSpan p₂) * dist p₂ (s.orthogonalProjectionSpan p₂) := by rw [PseudoMetricSpace.dist_comm p₂ _, dist_eq_norm_vsub V p₁ _, dist_eq_norm_vsub V p₁ _, dist_eq_norm_vsub V _ p₂, ← vsub_add_vsub_cancel p₁ (s.orthogonalProjectionSpan p₂) p₂, norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact Submodule.inner_right_of_mem_orthogonal (vsub_orthogonalProjection_mem_direction p₂ hp₁) (orthogonalProjection_vsub_mem_direction_orthogonal _ p₂) @[simp] lemma orthogonalProjectionSpan_eq_point (s : Simplex ℝ P 0) (p : P) : s.orthogonalProjectionSpan p = s.points 0 := by rw [orthogonalProjectionSpan] convert orthogonalProjection_affineSpan_singleton _ _ simp [Fin.fin_one_eq_zero] lemma orthogonalProjectionSpan_faceOpposite_eq_point_rev (s : Simplex ℝ P 1) (i : Fin 2) (p : P) : (s.faceOpposite i).orthogonalProjectionSpan p = s.points i.rev := by simp [faceOpposite_point_eq_point_rev] end Simplex end Affine
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Congruence.lean
import Mathlib.Topology.MetricSpace.Congruence import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine import Mathlib.Geometry.Euclidean.Triangle /-! # Triangle congruence This file proves the classical triangle congruence criteria for (possibly degenerate) triangles in real inner product spaces and Euclidean affine spaces. We prove SSS, SAS ASA, and AAS congruence. ## Implementation notes Side–Side–Side (SSS) congruence is proved using the definition of `Congruent`. Side–Angle–Side (SAS) congruence is proved via the law of cosines. Angle–Side–Angle (ASA) congruence is reduced to SAS using the law of sines. Angle–Angle–Side (AAS) congruence uses the fact that the sum of the angles in a triangle equals π, then reduces to ASA. ## References * https://en.wikipedia.org/wiki/Congruence_(geometry) -/ open scoped Congruent namespace EuclideanGeometry variable {ι V₁ V₂ P₁ P₂ : Type*} [NormedAddCommGroup V₁] [NormedAddCommGroup V₂] [InnerProductSpace ℝ V₁] [InnerProductSpace ℝ V₂] [MetricSpace P₁] [MetricSpace P₂] [NormedAddTorsor V₁ P₁] [NormedAddTorsor V₂ P₂] {v₁ : ι → P₁} {v₂ : ι → P₂} {a b c : P₁} {a' b' c' : P₂} lemma triangle_congruent_iff_dist_eq {t₁ : Fin 3 → P₁} {t₂ : Fin 3 → P₂} : t₁ ≅ t₂ ↔ ∀ (i j : Fin 3), dist (t₁ i) (t₁ j) = dist (t₂ i) (t₂ j) := congruent_iff_dist_eq /-- **Side–Side–Side (SSS) congruence** If all three corresponding sides of two triangles are equal, then the triangles are congruent. This holds even if the triangles are degenerate. -/ theorem side_side_side (hd₁ : dist a b = dist a' b') (hd₂ : dist b c = dist b' c') (hd₃ : dist c a = dist c' a') : ![a, b, c] ≅ ![a', b', c'] := by rw [triangle_congruent_iff_dist_eq] intro i j fin_cases i <;> fin_cases j <;> simp_all [dist_comm] /-- **Side–Angle–Side (SAS) congruence** If two triangles have two sides and the included angle equal, then the triangles are congruent. This holds even if the triangles are degenerate. -/ theorem side_angle_side (h : ∠ a b c = ∠ a' b' c') (hd₁ : dist a b = dist a' b') (hd₂ : dist b c = dist b' c') : ![a, b, c] ≅ ![a', b', c'] := by apply side_side_side hd₁ hd₂ rw [dist_comm, dist_comm c' a', ← sq_eq_sq₀ (by positivity) (by positivity), pow_two, pow_two, EuclideanGeometry.law_cos a b c, EuclideanGeometry.law_cos a' b' c'] simp [h, hd₁, hd₂, dist_comm] /-- **Angle–Side–Angle (ASA) congruence** If two triangles have two equal angles and the included side equal, then the triangles are congruent. We require that one of the triangles is non-degenerate, the non-collinearity of the other is then implied by the given equalities. -/ theorem angle_side_angle (h : ¬Collinear ℝ {a, b, c}) (ha₁ : ∠ a b c = ∠ a' b' c') (hd : dist b c = dist b' c') (ha₂ : ∠ b c a = ∠ b' c' a') : ![a, b, c] ≅ ![a', b', c'] := by have h' : ¬Collinear ℝ {a', b', c'} := by grind only [collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi, angle_self_right, angle_self_left, dist_eq_zero, Set.insert_comm, Set.pair_comm] have ha₃ := angle_add_angle_add_angle_eq_pi b (ne₁₃_of_not_collinear h) have ha₃' := angle_add_angle_add_angle_eq_pi b' (ne₁₃_of_not_collinear h') simp only [← ha₃', ha₁, ha₂, angle_comm b' c' a', add_right_cancel_iff] at ha₃ have h_bac : ¬Collinear ℝ {b, a, c} := by simpa [Set.insert_comm] using h have h_bac' : ¬Collinear ℝ {b', a', c'} := by simpa [Set.insert_comm] using h' have dist_ab_eq : dist a b = dist a' b' := by rw [dist_comm a b, dist_comm a' b', dist_eq_dist_mul_sin_angle_div_sin_angle h_bac, dist_eq_dist_mul_sin_angle_div_sin_angle h_bac', dist_comm c b, dist_comm c' b', hd, angle_comm, ha₂, angle_comm b' c' a', angle_comm b a c, ha₃, angle_comm b' a' c'] exact side_angle_side ha₁ dist_ab_eq hd /-- **Angle–Angle–Side (AAS) congruence** If two triangles have two equal angles and a non-included side equal, then the triangles are congruent. We require that one of the triangles is non-degenerate, the non-collinearity of the other is then implied by the given equalities. -/ theorem angle_angle_side (h : ¬Collinear ℝ {a, b, c}) (ha₁ : ∠ a b c = ∠ a' b' c') (ha₂ : ∠ b c a = ∠ b' c' a') (hd : dist c a = dist c' a') : ![a, b, c] ≅ ![a', b', c'] := by have ha₃ := angle_add_angle_add_angle_eq_pi b (ne₁₃_of_not_collinear h) have h' : ¬Collinear ℝ {a', b', c'} := by grind only [collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi, angle_self_right, angle_self_left, dist_eq_zero, Set.insert_comm, Set.pair_comm] have ha₃' := angle_add_angle_add_angle_eq_pi b' (ne₁₃_of_not_collinear h') simp only [← ha₃', ha₁, ha₂, angle_comm b' c' a', add_right_cancel_iff] at ha₃ have h_bca : ¬Collinear ℝ {b, c, a} := by rwa [Set.insert_comm, Set.pair_comm] at h have h1 := angle_side_angle h_bca ha₂ hd ha₃ exact angle_side_angle h ha₁ (h1.dist_eq 0 1) ha₂ include V₁ V₂ /-- Corresponding angles are equal for congruent triangles. -/ theorem angle_eq_of_congruent (h : v₁ ≅ v₂) (i j k : ι) : ∠ (v₁ i) (v₁ j) (v₁ k) = ∠ (v₂ i) (v₂ j) (v₂ k) := by unfold EuclideanGeometry.angle unfold InnerProductGeometry.angle simp_rw [real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two, vsub_sub_vsub_cancel_right, ← dist_eq_norm_vsub, h.dist_eq] end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Inversion/ImageHyperplane.lean
import Mathlib.Geometry.Euclidean.Inversion.Basic import Mathlib.Geometry.Euclidean.PerpBisector /-! # Image of a hyperplane under inversion In this file we prove that the inversion with center `c` and radius `R ≠ 0` maps a sphere passing through the center to a hyperplane, and vice versa. More precisely, it maps a sphere with center `y ≠ c` and radius `dist y c` to the hyperplane `AffineSubspace.perpBisector c (EuclideanGeometry.inversion c R y)`. The exact statements are a little more complicated because `EuclideanGeometry.inversion c R` sends the center to itself, not to a point at infinity. We also prove that the inversion sends an affine subspace passing through the center to itself. ## Keywords inversion -/ open Metric Function AffineMap Set AffineSubspace open scoped Topology variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] {c x y : P} {R : ℝ} namespace EuclideanGeometry -- see https://github.com/leanprover-community/mathlib4/issues/29041 set_option linter.unusedSimpArgs false in /-- The inversion with center `c` and radius `R` maps a sphere passing through the center to a hyperplane. -/ theorem inversion_mem_perpBisector_inversion_iff (hR : R ≠ 0) (hx : x ≠ c) (hy : y ≠ c) : inversion c R x ∈ perpBisector c (inversion c R y) ↔ dist x y = dist y c := by rw [mem_perpBisector_iff_dist_eq, dist_inversion_inversion hx hy, dist_inversion_center] simp [field, eq_comm, ↓hx, ↓hy] /-- The inversion with center `c` and radius `R` maps a sphere passing through the center to a hyperplane. -/ theorem inversion_mem_perpBisector_inversion_iff' (hR : R ≠ 0) (hy : y ≠ c) : inversion c R x ∈ perpBisector c (inversion c R y) ↔ dist x y = dist y c ∧ x ≠ c := by rcases eq_or_ne x c with rfl | hx · simp [*] · simp [inversion_mem_perpBisector_inversion_iff hR hx hy, hx] theorem preimage_inversion_perpBisector_inversion (hR : R ≠ 0) (hy : y ≠ c) : inversion c R ⁻¹' perpBisector c (inversion c R y) = sphere y (dist y c) \ {c} := Set.ext fun _ ↦ inversion_mem_perpBisector_inversion_iff' hR hy theorem preimage_inversion_perpBisector (hR : R ≠ 0) (hy : y ≠ c) : inversion c R ⁻¹' perpBisector c y = sphere (inversion c R y) (R ^ 2 / dist y c) \ {c} := by rw [← dist_inversion_center, ← preimage_inversion_perpBisector_inversion hR, inversion_inversion] <;> simp [*] theorem image_inversion_perpBisector (hR : R ≠ 0) (hy : y ≠ c) : inversion c R '' perpBisector c y = sphere (inversion c R y) (R ^ 2 / dist y c) \ {c} := by rw [image_eq_preimage_of_inverse (inversion_involutive _ hR) (inversion_involutive _ hR), preimage_inversion_perpBisector hR hy] theorem preimage_inversion_sphere_dist_center (hR : R ≠ 0) (hy : y ≠ c) : inversion c R ⁻¹' sphere y (dist y c) = insert c (perpBisector c (inversion c R y) : Set P) := by ext x rcases eq_or_ne x c with rfl | hx; · simp [dist_comm] rw [mem_preimage, mem_sphere, ← inversion_mem_perpBisector_inversion_iff hR] <;> simp [*] theorem image_inversion_sphere_dist_center (hR : R ≠ 0) (hy : y ≠ c) : inversion c R '' sphere y (dist y c) = insert c (perpBisector c (inversion c R y) : Set P) := by rw [image_eq_preimage_of_inverse (inversion_involutive _ hR) (inversion_involutive _ hR), preimage_inversion_sphere_dist_center hR hy] /-- Inversion sends an affine subspace passing through the center to itself. -/ theorem mapsTo_inversion_affineSubspace_of_mem {p : AffineSubspace ℝ P} (hp : c ∈ p) : MapsTo (inversion c R) p p := fun _ ↦ AffineMap.lineMap_mem _ hp /-- Inversion sends an affine subspace passing through the center to itself. -/ theorem image_inversion_affineSubspace_of_mem {p : AffineSubspace ℝ P} (hR : R ≠ 0) (hp : c ∈ p) : inversion c R '' p = p := (mapsTo_inversion_affineSubspace_of_mem hp).image_subset.antisymm fun x hx ↦ ⟨inversion c R x, mapsTo_inversion_affineSubspace_of_mem hp hx, inversion_inversion _ hR _⟩ end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Inversion/Calculus.lean
import Mathlib.Geometry.Euclidean.Inversion.Basic import Mathlib.Analysis.InnerProductSpace.Calculus import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Tactic.AdaptationNote /-! # Derivative of the inversion In this file we prove a formula for the derivative of `EuclideanGeometry.inversion c R`. ## Implementation notes Since `fderiv` and related definitions do not work for affine spaces, we deal with an inner product space in this file. ## Keywords inversion, derivative -/ open Metric Function AffineMap Set AffineSubspace open scoped Topology RealInnerProductSpace variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [InnerProductSpace ℝ F] open EuclideanGeometry section DotNotation variable {c x : E → F} {R : E → ℝ} {s : Set E} {a : E} {n : ℕ∞} protected theorem ContDiffWithinAt.inversion (hc : ContDiffWithinAt ℝ n c s a) (hR : ContDiffWithinAt ℝ n R s a) (hx : ContDiffWithinAt ℝ n x s a) (hne : x a ≠ c a) : ContDiffWithinAt ℝ n (fun a ↦ inversion (c a) (R a) (x a)) s a := (((hR.div (hx.dist ℝ hc hne) (dist_ne_zero.2 hne)).pow _).smul (hx.sub hc)).add hc protected theorem ContDiffOn.inversion (hc : ContDiffOn ℝ n c s) (hR : ContDiffOn ℝ n R s) (hx : ContDiffOn ℝ n x s) (hne : ∀ a ∈ s, x a ≠ c a) : ContDiffOn ℝ n (fun a ↦ inversion (c a) (R a) (x a)) s := fun a ha ↦ (hc a ha).inversion (hR a ha) (hx a ha) (hne a ha) protected nonrec theorem ContDiffAt.inversion (hc : ContDiffAt ℝ n c a) (hR : ContDiffAt ℝ n R a) (hx : ContDiffAt ℝ n x a) (hne : x a ≠ c a) : ContDiffAt ℝ n (fun a ↦ inversion (c a) (R a) (x a)) a := hc.inversion hR hx hne protected nonrec theorem ContDiff.inversion (hc : ContDiff ℝ n c) (hR : ContDiff ℝ n R) (hx : ContDiff ℝ n x) (hne : ∀ a, x a ≠ c a) : ContDiff ℝ n (fun a ↦ inversion (c a) (R a) (x a)) := contDiff_iff_contDiffAt.2 fun a ↦ hc.contDiffAt.inversion hR.contDiffAt hx.contDiffAt (hne a) protected theorem DifferentiableWithinAt.inversion (hc : DifferentiableWithinAt ℝ c s a) (hR : DifferentiableWithinAt ℝ R s a) (hx : DifferentiableWithinAt ℝ x s a) (hne : x a ≠ c a) : DifferentiableWithinAt ℝ (fun a ↦ inversion (c a) (R a) (x a)) s a := -- TODO: Use `.div` https://github.com/leanprover-community/mathlib4/issues/5870 (((hR.mul <| (hx.dist ℝ hc hne).inv (dist_ne_zero.2 hne)).pow _).smul (hx.sub hc)).add hc protected theorem DifferentiableOn.inversion (hc : DifferentiableOn ℝ c s) (hR : DifferentiableOn ℝ R s) (hx : DifferentiableOn ℝ x s) (hne : ∀ a ∈ s, x a ≠ c a) : DifferentiableOn ℝ (fun a ↦ inversion (c a) (R a) (x a)) s := fun a ha ↦ (hc a ha).inversion (hR a ha) (hx a ha) (hne a ha) protected theorem DifferentiableAt.inversion (hc : DifferentiableAt ℝ c a) (hR : DifferentiableAt ℝ R a) (hx : DifferentiableAt ℝ x a) (hne : x a ≠ c a) : DifferentiableAt ℝ (fun a ↦ inversion (c a) (R a) (x a)) a := by rw [← differentiableWithinAt_univ] at * exact hc.inversion hR hx hne protected theorem Differentiable.inversion (hc : Differentiable ℝ c) (hR : Differentiable ℝ R) (hx : Differentiable ℝ x) (hne : ∀ a, x a ≠ c a) : Differentiable ℝ (fun a ↦ inversion (c a) (R a) (x a)) := fun a ↦ (hc a).inversion (hR a) (hx a) (hne a) end DotNotation namespace EuclideanGeometry variable {c x : F} {R : ℝ} /-- Formula for the Fréchet derivative of `EuclideanGeometry.inversion c R`. -/ theorem hasFDerivAt_inversion (hx : x ≠ c) : HasFDerivAt (inversion c R) ((R / dist x c) ^ 2 • ((ℝ ∙ (x - c))ᗮ.reflection : F →L[ℝ] F)) x := by rcases add_left_surjective c x with ⟨x, rfl⟩ have : HasFDerivAt (inversion c R) (?_ : F →L[ℝ] F) (c + x) := by simp +unfoldPartialApp only [inversion] simp_rw [dist_eq_norm, div_pow, div_eq_mul_inv] have A := (hasFDerivAt_id (𝕜 := ℝ) (c + x)).sub_const c have B := ((hasDerivAt_inv <| by simpa using hx).comp_hasFDerivAt _ A.norm_sq).const_mul (R ^ 2) exact (B.smul A).add_const c refine this.congr_fderiv (LinearMap.ext_on_codisjoint (Submodule.isCompl_orthogonal_of_hasOrthogonalProjection (K := ℝ ∙ x)).codisjoint (LinearMap.eqOn_span' ?_) fun y hy ↦ ?_) · have : ((‖x‖ ^ 2) ^ 2)⁻¹ * (‖x‖ ^ 2) = (‖x‖ ^ 2)⁻¹ := by rw [← div_eq_inv_mul, sq (‖x‖ ^ 2), div_self_mul_self'] simp [Submodule.reflection_orthogonalComplement_singleton_eq_neg, two_mul, this, div_eq_mul_inv, mul_add, add_smul, mul_pow] · simp [Submodule.mem_orthogonal_singleton_iff_inner_right.1 hy, Submodule.reflection_mem_subspace_eq_self hy, div_eq_mul_inv, mul_pow] end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Inversion/Basic.lean
import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Tactic.AdaptationNote /-! # Inversion in an affine space In this file we define inversion in a sphere in an affine space. This map sends each point `x` to the point `y` such that `y -ᵥ c = (R / dist x c) ^ 2 • (x -ᵥ c)`, where `c` and `R` are the center and the radius the sphere. In many applications, it is convenient to assume that the inversions swaps the center and the point at infinity. In order to stay in the original affine space, we define the map so that it sends center to itself. Currently, we prove only a few basic lemmas needed to prove Ptolemy's inequality, see `EuclideanGeometry.mul_dist_le_mul_dist_add_mul_dist`. -/ noncomputable section open Metric Function AffineMap Set AffineSubspace open scoped Topology variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] namespace EuclideanGeometry variable {c x y : P} {R : ℝ} /-- Inversion in a sphere in an affine space. This map sends each point `x` to the point `y` such that `y -ᵥ c = (R / dist x c) ^ 2 • (x -ᵥ c)`, where `c` and `R` are the center and the radius the sphere. -/ def inversion (c : P) (R : ℝ) (x : P) : P := (R / dist x c) ^ 2 • (x -ᵥ c) +ᵥ c theorem inversion_def : inversion = fun (c : P) (R : ℝ) (x : P) => (R / dist x c) ^ 2 • (x -ᵥ c) +ᵥ c := rfl /-! ### Basic properties In this section we prove that `EuclideanGeometry.inversion c R` is involutive and preserves the sphere `Metric.sphere c R`. We also prove that the distance to the center of the image of `x` under this inversion is given by `R ^ 2 / dist x c`. -/ theorem inversion_eq_lineMap (c : P) (R : ℝ) (x : P) : inversion c R x = lineMap c x ((R / dist x c) ^ 2) := rfl theorem inversion_vsub_center (c : P) (R : ℝ) (x : P) : inversion c R x -ᵥ c = (R / dist x c) ^ 2 • (x -ᵥ c) := vadd_vsub _ _ @[simp] theorem inversion_self (c : P) (R : ℝ) : inversion c R c = c := by simp [inversion] @[simp] theorem inversion_zero_radius (c x : P) : inversion c 0 x = c := by simp [inversion] theorem inversion_mul (c : P) (a R : ℝ) (x : P) : inversion c (a * R) x = homothety c (a ^ 2) (inversion c R x) := by simp only [inversion_eq_lineMap, ← homothety_eq_lineMap, ← homothety_mul_apply, mul_div_assoc, mul_pow] @[simp] theorem inversion_dist_center (c x : P) : inversion c (dist x c) x = x := by rcases eq_or_ne x c with (rfl | hne) · apply inversion_self · rw [inversion, div_self, one_pow, one_smul, vsub_vadd] rwa [dist_ne_zero] @[simp] theorem inversion_dist_center' (c x : P) : inversion c (dist c x) x = x := by rw [dist_comm, inversion_dist_center] theorem inversion_of_mem_sphere (h : x ∈ Metric.sphere c R) : inversion c R x = x := h.out ▸ inversion_dist_center c x /-- Distance from the image of a point under inversion to the center. This formula accidentally works for `x = c`. -/ theorem dist_inversion_center (c x : P) (R : ℝ) : dist (inversion c R x) c = R ^ 2 / dist x c := by rcases eq_or_ne x c with (rfl | hx) · simp have : dist x c ≠ 0 := dist_ne_zero.2 hx simp only [inversion] field_simp simp only [sq, dist_vadd_left, norm_smul, norm_div, norm_mul, Real.norm_eq_abs, abs_mul_abs_self, abs_dist, ← dist_eq_norm_vsub] field /-- Distance from the center of an inversion to the image of a point under the inversion. This formula accidentally works for `x = c`. -/ theorem dist_center_inversion (c x : P) (R : ℝ) : dist c (inversion c R x) = R ^ 2 / dist c x := by rw [dist_comm c, dist_comm c, dist_inversion_center] @[simp] theorem inversion_inversion (c : P) {R : ℝ} (hR : R ≠ 0) (x : P) : inversion c R (inversion c R x) = x := by rcases eq_or_ne x c with (rfl | hne) · rw [inversion_self, inversion_self] · rw [inversion, dist_inversion_center, inversion_vsub_center, smul_smul, ← mul_pow, div_mul_div_comm, div_mul_cancel₀ _ (dist_ne_zero.2 hne), ← sq, div_self, one_pow, one_smul, vsub_vadd] exact pow_ne_zero _ hR theorem inversion_involutive (c : P) {R : ℝ} (hR : R ≠ 0) : Involutive (inversion c R) := inversion_inversion c hR theorem inversion_surjective (c : P) {R : ℝ} (hR : R ≠ 0) : Surjective (inversion c R) := (inversion_involutive c hR).surjective theorem inversion_injective (c : P) {R : ℝ} (hR : R ≠ 0) : Injective (inversion c R) := (inversion_involutive c hR).injective theorem inversion_bijective (c : P) {R : ℝ} (hR : R ≠ 0) : Bijective (inversion c R) := (inversion_involutive c hR).bijective theorem inversion_eq_center (hR : R ≠ 0) : inversion c R x = c ↔ x = c := (inversion_injective c hR).eq_iff' <| inversion_self _ _ @[simp] theorem inversion_eq_center' : inversion c R x = c ↔ x = c ∨ R = 0 := by by_cases hR : R = 0 <;> simp [inversion_eq_center, hR] theorem center_eq_inversion (hR : R ≠ 0) : c = inversion c R x ↔ x = c := eq_comm.trans (inversion_eq_center hR) @[simp] theorem center_eq_inversion' : c = inversion c R x ↔ x = c ∨ R = 0 := eq_comm.trans inversion_eq_center' /-! ### Similarity of triangles If inversion with center `O` sends `A` to `A'` and `B` to `B'`, then the triangle `OB'A'` is similar to the triangle `OAB` with coefficient `R ^ 2 / (|OA|*|OB|)` and the triangle `OA'B` is similar to the triangle `OAB'` with coefficient `|OB|/|OA|`. We formulate these statements in terms of ratios of the lengths of their sides. -/ /-- Distance between the images of two points under an inversion. -/ theorem dist_inversion_inversion (hx : x ≠ c) (hy : y ≠ c) (R : ℝ) : dist (inversion c R x) (inversion c R y) = R ^ 2 / (dist x c * dist y c) * dist x y := by dsimp only [inversion] simp_rw [dist_vadd_cancel_right, dist_eq_norm_vsub V _ c] simpa only [dist_vsub_cancel_right] using dist_div_norm_sq_smul (vsub_ne_zero.2 hx) (vsub_ne_zero.2 hy) R theorem dist_inversion_mul_dist_center_eq (hx : x ≠ c) (hy : y ≠ c) : dist (inversion c R x) y * dist x c = dist x (inversion c R y) * dist y c := by rcases eq_or_ne R 0 with rfl | hR; · simp [dist_comm, mul_comm] have hy' : inversion c R y ≠ c := by simp [*] conv in dist _ y => rw [← inversion_inversion c hR y] rw [dist_inversion_inversion hx hy', dist_inversion_center] field [dist_ne_zero.2 hx] /-! ### Ptolemy's inequality -/ include V in /-- **Ptolemy's inequality**: in a quadrangle `ABCD`, `|AC| * |BD| ≤ |AB| * |CD| + |BC| * |AD|`. If `ABCD` is a convex cyclic polygon, then this inequality becomes an equality, see `EuclideanGeometry.mul_dist_add_mul_dist_eq_mul_dist_of_cospherical`. -/ theorem mul_dist_le_mul_dist_add_mul_dist (a b c d : P) : dist a c * dist b d ≤ dist a b * dist c d + dist b c * dist a d := by -- If one of the points `b`, `c`, `d` is equal to `a`, then the inequality is trivial. rcases eq_or_ne b a with (rfl | hb) · rw [dist_self, zero_mul, zero_add] rcases eq_or_ne c a with (rfl | hc) · rw [dist_self, zero_mul] positivity rcases eq_or_ne d a with (rfl | hd) · rw [dist_self, mul_zero, add_zero, dist_comm d, dist_comm d, mul_comm] /- Otherwise, we apply the triangle inequality to `EuclideanGeometry.inversion a 1 b`, `EuclideanGeometry.inversion a 1 c`, and `EuclideanGeometry.inversion a 1 d`. -/ have H := dist_triangle (inversion a 1 b) (inversion a 1 c) (inversion a 1 d) rw [dist_inversion_inversion hb hd, dist_inversion_inversion hb hc, dist_inversion_inversion hc hd, one_pow] at H rw [← dist_pos] at hb hc hd rw [← div_le_div_iff_of_pos_right (mul_pos hb (mul_pos hc hd))] convert H using 1 <;> simp [field, dist_comm a]; ring end EuclideanGeometry open EuclideanGeometry /-! ### Continuity of inversion -/ protected theorem Filter.Tendsto.inversion {α : Type*} {x c : P} {R : ℝ} {l : Filter α} {fc fx : α → P} {fR : α → ℝ} (hc : Tendsto fc l (𝓝 c)) (hR : Tendsto fR l (𝓝 R)) (hx : Tendsto fx l (𝓝 x)) (hne : x ≠ c) : Tendsto (fun a ↦ inversion (fc a) (fR a) (fx a)) l (𝓝 (inversion c R x)) := (((hR.div (hx.dist hc) <| dist_ne_zero.2 hne).pow 2).smul (hx.vsub hc)).vadd hc variable {X : Type*} [TopologicalSpace X] {c x : X → P} {R : X → ℝ} {a₀ : X} {s : Set X} protected nonrec theorem ContinuousWithinAt.inversion (hc : ContinuousWithinAt c s a₀) (hR : ContinuousWithinAt R s a₀) (hx : ContinuousWithinAt x s a₀) (hne : x a₀ ≠ c a₀) : ContinuousWithinAt (fun a ↦ inversion (c a) (R a) (x a)) s a₀ := hc.inversion hR hx hne protected nonrec theorem ContinuousAt.inversion (hc : ContinuousAt c a₀) (hR : ContinuousAt R a₀) (hx : ContinuousAt x a₀) (hne : x a₀ ≠ c a₀) : ContinuousAt (fun a ↦ inversion (c a) (R a) (x a)) a₀ := hc.inversion hR hx hne protected theorem ContinuousOn.inversion (hc : ContinuousOn c s) (hR : ContinuousOn R s) (hx : ContinuousOn x s) (hne : ∀ a ∈ s, x a ≠ c a) : ContinuousOn (fun a ↦ inversion (c a) (R a) (x a)) s := fun a ha ↦ (hc a ha).inversion (hR a ha) (hx a ha) (hne a ha) protected theorem Continuous.inversion (hc : Continuous c) (hR : Continuous R) (hx : Continuous x) (hne : ∀ a, x a ≠ c a) : Continuous (fun a ↦ inversion (c a) (R a) (x a)) := continuous_iff_continuousAt.2 fun _ ↦ hc.continuousAt.inversion hR.continuousAt hx.continuousAt (hne _)
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Sphere.lean
import Mathlib.Geometry.Euclidean.Angle.Oriented.RightAngle import Mathlib.Geometry.Euclidean.Circumcenter import Mathlib.Geometry.Euclidean.Sphere.Tangent /-! # Angles in circles and sphere. This file proves results about angles in circles and spheres. -/ noncomputable section open Module Complex open scoped EuclideanGeometry Real RealInnerProductSpace ComplexConjugate namespace Orientation variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] variable [Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2)) /-- Angle at center of a circle equals twice angle at circumference, oriented vector angle form. -/ theorem oangle_eq_two_zsmul_oangle_sub_of_norm_eq {x y z : V} (hxyne : x ≠ y) (hxzne : x ≠ z) (hxy : ‖x‖ = ‖y‖) (hxz : ‖x‖ = ‖z‖) : o.oangle y z = (2 : ℤ) • o.oangle (y - x) (z - x) := by have hy : y ≠ 0 := by rintro rfl rw [norm_zero, norm_eq_zero] at hxy exact hxyne hxy have hx : x ≠ 0 := norm_ne_zero_iff.1 (hxy.symm ▸ norm_ne_zero_iff.2 hy) have hz : z ≠ 0 := norm_ne_zero_iff.1 (hxz ▸ norm_ne_zero_iff.2 hx) calc o.oangle y z = o.oangle x z - o.oangle x y := (o.oangle_sub_left hx hy hz).symm _ = π - (2 : ℤ) • o.oangle (x - z) x - (π - (2 : ℤ) • o.oangle (x - y) x) := by rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxzne.symm hxz.symm, o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxyne.symm hxy.symm] _ = (2 : ℤ) • (o.oangle (x - y) x - o.oangle (x - z) x) := by abel _ = (2 : ℤ) • o.oangle (x - y) (x - z) := by rw [o.oangle_sub_right (sub_ne_zero_of_ne hxyne) (sub_ne_zero_of_ne hxzne) hx] _ = (2 : ℤ) • o.oangle (y - x) (z - x) := by rw [← oangle_neg_neg, neg_sub, neg_sub] /-- Angle at center of a circle equals twice angle at circumference, oriented vector angle form with radius specified. -/ theorem oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real {x y z : V} (hxyne : x ≠ y) (hxzne : x ≠ z) {r : ℝ} (hx : ‖x‖ = r) (hy : ‖y‖ = r) (hz : ‖z‖ = r) : o.oangle y z = (2 : ℤ) • o.oangle (y - x) (z - x) := o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq hxyne hxzne (hy.symm ▸ hx) (hz.symm ▸ hx) /-- Oriented vector angle version of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result), represented here as equality of twice the angles. -/ theorem two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq {x₁ x₂ y z : V} (hx₁yne : x₁ ≠ y) (hx₁zne : x₁ ≠ z) (hx₂yne : x₂ ≠ y) (hx₂zne : x₂ ≠ z) {r : ℝ} (hx₁ : ‖x₁‖ = r) (hx₂ : ‖x₂‖ = r) (hy : ‖y‖ = r) (hz : ‖z‖ = r) : (2 : ℤ) • o.oangle (y - x₁) (z - x₁) = (2 : ℤ) • o.oangle (y - x₂) (z - x₂) := o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx₁yne hx₁zne hx₁ hy hz ▸ o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx₂yne hx₂zne hx₂ hy hz end Orientation namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] namespace Sphere open Real InnerProductSpace InnerProductGeometry /-- **Thales' theorem**: The angle inscribed in a semicircle is a right angle. -/ theorem angle_eq_pi_div_two_iff_mem_sphere_of_isDiameter {p₁ p₂ p₃ : P} {s : Sphere P} (hd : s.IsDiameter p₁ p₃) : ∠ p₁ p₂ p₃ = π / 2 ↔ p₂ ∈ s := by rw [mem_sphere', EuclideanGeometry.angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two] let o := s.center have h_center : o = midpoint ℝ p₁ p₃ := hd.midpoint_eq_center.symm rw [← vsub_add_vsub_cancel p₁ o p₂, ← vsub_add_vsub_cancel p₃ o p₂, inner_add_left, inner_add_right, inner_add_right] have h_opp : p₁ -ᵥ o = -(p₃ -ᵥ o) := by rw [h_center, left_vsub_midpoint, right_vsub_midpoint, ← smul_neg, neg_vsub_eq_vsub_rev] rw [h_opp, inner_neg_left, inner_neg_left, real_inner_comm (p₃ -ᵥ o) (o -ᵥ p₂)] ring_nf rw [neg_add_eq_zero, real_inner_self_eq_norm_sq, ← dist_eq_norm_vsub, real_inner_self_eq_norm_sq, ← dist_eq_norm_vsub, sq_eq_sq₀ dist_nonneg dist_nonneg, mem_sphere.mp hd.right_mem] exact eq_comm /-- **Thales' theorem**: For three distinct points, the angle at the second point is a right angle if and only if the second point lies on the sphere having the first and third points as diameter endpoints. -/ theorem angle_eq_pi_div_two_iff_mem_sphere_ofDiameter {p₁ p₂ p₃ : P} : ∠ p₁ p₂ p₃ = π / 2 ↔ p₂ ∈ Sphere.ofDiameter p₁ p₃ := angle_eq_pi_div_two_iff_mem_sphere_of_isDiameter (Sphere.isDiameter_ofDiameter p₁ p₃) alias thales_theorem := angle_eq_pi_div_two_iff_mem_sphere_of_isDiameter /-- For a tangent line to a sphere, the angle between the line and the radius at the tangent point equals `π / 2`. -/ theorem IsTangentAt.angle_eq_pi_div_two {s : Sphere P} {p q : P} {as : AffineSubspace ℝ P} (h : s.IsTangentAt p as) (hq_mem : q ∈ as) : ∠ q p s.center = π / 2 := by have h1 := IsTangentAt.inner_left_eq_zero_of_mem h hq_mem rw [inner_eq_zero_iff_angle_eq_pi_div_two] at h1 rw [angle, ← neg_vsub_eq_vsub_rev _ s.center, angle_neg_right, h1] linarith /-- If the angle between the line `p q` and the radius at `p` equals `π / 2`, then the line `p q` is tangent to the sphere at `p`. -/ theorem IsTangentAt_of_angle_eq_pi_div_two {s : Sphere P} {p q : P} (h : ∠ q p s.center = π / 2) (hp : p ∈ s) : s.IsTangentAt p line[ℝ, p, q] := by have hp_mem := left_mem_affineSpan_pair ℝ p q refine ⟨hp, hp_mem, ?_⟩ have h_ortho : ⟪q -ᵥ p, p -ᵥ s.center⟫ = 0 := by rwa [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, ← neg_vsub_eq_vsub_rev p s.center, inner_neg_right, neg_eq_zero] at h have hq : q ∈ s.orthRadius p := by simp [Sphere.mem_orthRadius_iff_inner_left, h_ortho] rw [affineSpan_le] have hp : p ∈ s.orthRadius p := by simp [Sphere.self_mem_orthRadius] simp_rw [Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨hp, hq⟩ /-- A line through `p` is tangent to the sphere at `p` if and only if the angle between the line and the radius at `p` equals `π / 2`. -/ theorem IsTangentAt_iff_angle_eq_pi_div_two {s : Sphere P} {p q : P} (hp : p ∈ s) : s.IsTangentAt p line[ℝ, p, q] ↔ ∠ q p s.center = π / 2 := by exact ⟨fun h ↦ IsTangentAt.angle_eq_pi_div_two h (right_mem_affineSpan_pair ℝ p q), fun h ↦ IsTangentAt_of_angle_eq_pi_div_two h hp⟩ end Sphere variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] local notation "o" => Module.Oriented.positiveOrientation namespace Sphere /-- Angle at center of a circle equals twice angle at circumference, oriented angle version. -/ theorem oangle_center_eq_two_zsmul_oangle {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₃ : p₂ ≠ p₃) : ∡ p₁ s.center p₃ = (2 : ℤ) • ∡ p₁ p₂ p₃ := by rw [mem_sphere, @dist_eq_norm_vsub V] at hp₁ hp₂ hp₃ rw [oangle, oangle, o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real _ _ hp₂ hp₁ hp₃] <;> simp [hp₂p₁, hp₂p₃] /-- Oriented angle version of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result), represented here as equality of twice the angles. -/ theorem two_zsmul_oangle_eq {s : Sphere P} {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₄ : p₄ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₄ : p₂ ≠ p₄) (hp₃p₁ : p₃ ≠ p₁) (hp₃p₄ : p₃ ≠ p₄) : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄ := by rw [mem_sphere, @dist_eq_norm_vsub V] at hp₁ hp₂ hp₃ hp₄ rw [oangle, oangle, ← vsub_sub_vsub_cancel_right p₁ p₂ s.center, ← vsub_sub_vsub_cancel_right p₄ p₂ s.center, o.two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq _ _ _ _ hp₂ hp₃ hp₁ hp₄] <;> simp [hp₂p₁, hp₂p₄, hp₃p₁, hp₃p₄] end Sphere /-- Oriented angle version of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result), represented here as equality of twice the angles. -/ theorem Cospherical.two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ : P} (h : Cospherical ({p₁, p₂, p₃, p₄} : Set P)) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₄ : p₂ ≠ p₄) (hp₃p₁ : p₃ ≠ p₁) (hp₃p₄ : p₃ ≠ p₄) : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄ := by obtain ⟨s, hs⟩ := cospherical_iff_exists_sphere.1 h simp_rw [Set.insert_subset_iff, Set.singleton_subset_iff, Sphere.mem_coe] at hs exact Sphere.two_zsmul_oangle_eq hs.1 hs.2.1 hs.2.2.1 hs.2.2.2 hp₂p₁ hp₂p₄ hp₃p₁ hp₃p₄ namespace Sphere /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented angle-at-point form where the apex is given as the center of a circle. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_center_left {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : ∡ p₁ s.center p₂ = π - (2 : ℤ) • ∡ s.center p₂ p₁ := by rw [oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq h.symm (dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)] /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented angle-at-point form where the apex is given as the center of a circle. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_center_right {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : ∡ p₁ s.center p₂ = π - (2 : ℤ) • ∡ p₂ p₁ s.center := by rw [oangle_eq_pi_sub_two_zsmul_oangle_center_left hp₁ hp₂ h, oangle_eq_oangle_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)] /-- Twice a base angle of an isosceles triangle with apex at the center of a circle, plus twice the angle at the apex of a triangle with the same base but apex on the circle, equals `π`. -/ theorem two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₃ : p₂ ≠ p₃) (hp₁p₃ : p₁ ≠ p₃) : (2 : ℤ) • ∡ p₃ p₁ s.center + (2 : ℤ) • ∡ p₁ p₂ p₃ = π := by rw [← oangle_center_eq_two_zsmul_oangle hp₁ hp₂ hp₃ hp₂p₁ hp₂p₃, oangle_eq_pi_sub_two_zsmul_oangle_center_right hp₁ hp₃ hp₁p₃, add_sub_cancel] /-- A base angle of an isosceles triangle with apex at the center of a circle is acute. -/ theorem abs_oangle_center_left_toReal_lt_pi_div_two {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) : |(∡ s.center p₂ p₁).toReal| < π / 2 := abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁) /-- A base angle of an isosceles triangle with apex at the center of a circle is acute. -/ theorem abs_oangle_center_right_toReal_lt_pi_div_two {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) : |(∡ p₂ p₁ s.center).toReal| < π / 2 := abs_oangle_left_toReal_lt_pi_div_two_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁) /-- Given two points on a circle, the center of that circle may be expressed explicitly as a multiple (by half the tangent of the angle between the chord and the radius at one of those points) of a `π / 2` rotation of the vector between those points, plus the midpoint of those points. -/ theorem tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : (Real.Angle.tan (∡ p₂ p₁ s.center) / 2) • o.rotation (π / 2 : ℝ) (p₂ -ᵥ p₁) +ᵥ midpoint ℝ p₁ p₂ = s.center := by obtain ⟨r, hr⟩ := (dist_eq_iff_eq_smul_rotation_pi_div_two_vadd_midpoint h).1 (dist_center_eq_dist_center_of_mem_sphere hp₁ hp₂) rw [← hr, ← oangle_midpoint_rev_left, oangle, vadd_vsub_assoc] nth_rw 1 [show p₂ -ᵥ p₁ = (2 : ℝ) • (midpoint ℝ p₁ p₂ -ᵥ p₁) by simp] rw [map_smul, smul_smul, add_comm, o.tan_oangle_add_right_smul_rotation_pi_div_two, mul_div_cancel_right₀ _ (two_ne_zero' ℝ)] simpa using h.symm /-- Given three points on a circle, the center of that circle may be expressed explicitly as a multiple (by half the inverse of the tangent of the angle at one of those points) of a `π / 2` rotation of the vector between the other two points, plus the midpoint of those points. -/ theorem inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₁p₂ : p₁ ≠ p₂) (hp₁p₃ : p₁ ≠ p₃) (hp₂p₃ : p₂ ≠ p₃) : ((Real.Angle.tan (∡ p₁ p₂ p₃))⁻¹ / 2) • o.rotation (π / 2 : ℝ) (p₃ -ᵥ p₁) +ᵥ midpoint ℝ p₁ p₃ = s.center := by convert tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center hp₁ hp₃ hp₁p₃ convert (Real.Angle.tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi _).symm rw [add_comm, two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi hp₁ hp₂ hp₃ hp₁p₂.symm hp₂p₃ hp₁p₃] /-- Given two points on a circle, the radius of that circle may be expressed explicitly as half the distance between those two points divided by the cosine of the angle between the chord and the radius at one of those points. -/ theorem dist_div_cos_oangle_center_div_two_eq_radius {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : dist p₁ p₂ / Real.Angle.cos (∡ p₂ p₁ s.center) / 2 = s.radius := by rw [div_right_comm, div_eq_mul_inv _ (2 : ℝ), mul_comm, show (2 : ℝ)⁻¹ * dist p₁ p₂ = dist p₁ (midpoint ℝ p₁ p₂) by simp, ← mem_sphere.1 hp₁, ← tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center hp₁ hp₂ h, ← oangle_midpoint_rev_left, oangle, vadd_vsub_assoc, show p₂ -ᵥ p₁ = (2 : ℝ) • (midpoint ℝ p₁ p₂ -ᵥ p₁) by simp, map_smul, smul_smul, div_mul_cancel₀ _ (two_ne_zero' ℝ), @dist_eq_norm_vsub' V, @dist_eq_norm_vsub' V, vadd_vsub_assoc, add_comm, o.oangle_add_right_smul_rotation_pi_div_two, Real.Angle.cos_coe, Real.cos_arctan] · norm_cast rw [one_div, div_inv_eq_mul, ← mul_self_inj (by positivity) (by positivity), norm_add_sq_eq_norm_sq_add_norm_sq_real (o.inner_smul_rotation_pi_div_two_right _ _), ← mul_assoc, mul_comm, mul_comm _ (√_), ← mul_assoc, ← mul_assoc, Real.mul_self_sqrt (by positivity), norm_smul, LinearIsometryEquiv.norm_map] conv_rhs => rw [← mul_assoc, mul_comm _ ‖Real.Angle.tan _‖, ← mul_assoc, Real.norm_eq_abs, abs_mul_abs_self] ring · simpa using h.symm /-- Given two points on a circle, twice the radius of that circle may be expressed explicitly as the distance between those two points divided by the cosine of the angle between the chord and the radius at one of those points. -/ theorem dist_div_cos_oangle_center_eq_two_mul_radius {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : dist p₁ p₂ / Real.Angle.cos (∡ p₂ p₁ s.center) = 2 * s.radius := by rw [← dist_div_cos_oangle_center_div_two_eq_radius hp₁ hp₂ h, mul_div_cancel₀ _ (two_ne_zero' ℝ)] /-- Given three points on a circle, the radius of that circle may be expressed explicitly as half the distance between two of those points divided by the absolute value of the sine of the angle at the third point (a version of the law of sines or sine rule). -/ theorem dist_div_sin_oangle_div_two_eq_radius {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₁p₂ : p₁ ≠ p₂) (hp₁p₃ : p₁ ≠ p₃) (hp₂p₃ : p₂ ≠ p₃) : dist p₁ p₃ / |Real.Angle.sin (∡ p₁ p₂ p₃)| / 2 = s.radius := by convert dist_div_cos_oangle_center_div_two_eq_radius hp₁ hp₃ hp₁p₃ rw [← Real.Angle.abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi (two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi hp₁ hp₂ hp₃ hp₁p₂.symm hp₂p₃ hp₁p₃), abs_of_nonneg (Real.Angle.cos_nonneg_iff_abs_toReal_le_pi_div_two.2 _)] exact (abs_oangle_center_right_toReal_lt_pi_div_two hp₁ hp₃).le /-- Given three points on a circle, twice the radius of that circle may be expressed explicitly as the distance between two of those points divided by the absolute value of the sine of the angle at the third point (a version of the law of sines or sine rule). -/ theorem dist_div_sin_oangle_eq_two_mul_radius {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₁p₂ : p₁ ≠ p₂) (hp₁p₃ : p₁ ≠ p₃) (hp₂p₃ : p₂ ≠ p₃) : dist p₁ p₃ / |Real.Angle.sin (∡ p₁ p₂ p₃)| = 2 * s.radius := by rw [← dist_div_sin_oangle_div_two_eq_radius hp₁ hp₂ hp₃ hp₁p₂ hp₁p₃ hp₂p₃, mul_div_cancel₀ _ (two_ne_zero' ℝ)] end Sphere end EuclideanGeometry namespace Affine namespace Triangle open EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] local notation "o" => Module.Oriented.positiveOrientation /-- The circumcenter of a triangle may be expressed explicitly as a multiple (by half the inverse of the tangent of the angle at one of the vertices) of a `π / 2` rotation of the vector between the other two vertices, plus the midpoint of those vertices. -/ theorem inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_circumcenter (t : Triangle ℝ P) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : ((Real.Angle.tan (∡ (t.points i₁) (t.points i₂) (t.points i₃)))⁻¹ / 2) • o.rotation (π / 2 : ℝ) (t.points i₃ -ᵥ t.points i₁) +ᵥ midpoint ℝ (t.points i₁) (t.points i₃) = t.circumcenter := Sphere.inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center (t.mem_circumsphere _) (t.mem_circumsphere _) (t.mem_circumsphere _) (t.independent.injective.ne h₁₂) (t.independent.injective.ne h₁₃) (t.independent.injective.ne h₂₃) /-- The circumradius of a triangle may be expressed explicitly as half the length of a side divided by the absolute value of the sine of the angle at the third point (a version of the law of sines or sine rule). -/ theorem dist_div_sin_oangle_div_two_eq_circumradius (t : Triangle ℝ P) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : dist (t.points i₁) (t.points i₃) / |Real.Angle.sin (∡ (t.points i₁) (t.points i₂) (t.points i₃))| / 2 = t.circumradius := Sphere.dist_div_sin_oangle_div_two_eq_radius (t.mem_circumsphere _) (t.mem_circumsphere _) (t.mem_circumsphere _) (t.independent.injective.ne h₁₂) (t.independent.injective.ne h₁₃) (t.independent.injective.ne h₂₃) /-- Twice the circumradius of a triangle may be expressed explicitly as the length of a side divided by the absolute value of the sine of the angle at the third point (a version of the law of sines or sine rule). -/ theorem dist_div_sin_oangle_eq_two_mul_circumradius (t : Triangle ℝ P) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : dist (t.points i₁) (t.points i₃) / |Real.Angle.sin (∡ (t.points i₁) (t.points i₂) (t.points i₃))| = 2 * t.circumradius := Sphere.dist_div_sin_oangle_eq_two_mul_radius (t.mem_circumsphere _) (t.mem_circumsphere _) (t.mem_circumsphere _) (t.independent.injective.ne h₁₂) (t.independent.injective.ne h₁₃) (t.independent.injective.ne h₂₃) /-- The circumsphere of a triangle may be expressed explicitly in terms of two points and the angle at the third point. -/ theorem circumsphere_eq_of_dist_of_oangle (t : Triangle ℝ P) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : t.circumsphere = ⟨((Real.Angle.tan (∡ (t.points i₁) (t.points i₂) (t.points i₃)))⁻¹ / 2) • o.rotation (π / 2 : ℝ) (t.points i₃ -ᵥ t.points i₁) +ᵥ midpoint ℝ (t.points i₁) (t.points i₃), dist (t.points i₁) (t.points i₃) / |Real.Angle.sin (∡ (t.points i₁) (t.points i₂) (t.points i₃))| / 2⟩ := t.circumsphere.ext (t.inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_circumcenter h₁₂ h₁₃ h₂₃).symm (t.dist_div_sin_oangle_div_two_eq_circumradius h₁₂ h₁₃ h₂₃).symm /-- If two triangles have two points the same, and twice the angle at the third point the same, they have the same circumsphere. -/ theorem circumsphere_eq_circumsphere_of_eq_of_eq_of_two_zsmul_oangle_eq {t₁ t₂ : Triangle ℝ P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) (h₁ : t₁.points i₁ = t₂.points i₁) (h₃ : t₁.points i₃ = t₂.points i₃) (h₂ : (2 : ℤ) • ∡ (t₁.points i₁) (t₁.points i₂) (t₁.points i₃) = (2 : ℤ) • ∡ (t₂.points i₁) (t₂.points i₂) (t₂.points i₃)) : t₁.circumsphere = t₂.circumsphere := by rw [t₁.circumsphere_eq_of_dist_of_oangle h₁₂ h₁₃ h₂₃, t₂.circumsphere_eq_of_dist_of_oangle h₁₂ h₁₃ h₂₃, Real.Angle.tan_eq_of_two_zsmul_eq h₂, Real.Angle.abs_sin_eq_of_two_zsmul_eq h₂, h₁, h₃] /-- Given a triangle, and a fourth point such that twice the angle between two points of the triangle at that fourth point equals twice the third angle of the triangle, the fourth point lies in the circumsphere of the triangle. -/ theorem mem_circumsphere_of_two_zsmul_oangle_eq {t : Triangle ℝ P} {p : P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) (h : (2 : ℤ) • ∡ (t.points i₁) p (t.points i₃) = (2 : ℤ) • ∡ (t.points i₁) (t.points i₂) (t.points i₃)) : p ∈ t.circumsphere := by let t'p : Fin 3 → P := Function.update t.points i₂ p have h₁ : t'p i₁ = t.points i₁ := by simp [t'p, h₁₂] have h₂ : t'p i₂ = p := by simp [t'p] have h₃ : t'p i₃ = t.points i₃ := by simp [t'p, h₂₃.symm] have ha : AffineIndependent ℝ t'p := by rw [affineIndependent_iff_not_collinear_of_ne h₁₂ h₁₃ h₂₃, h₁, h₂, h₃, collinear_iff_of_two_zsmul_oangle_eq h, ← affineIndependent_iff_not_collinear_of_ne h₁₂ h₁₃ h₂₃] exact t.independent let t' : Triangle ℝ P := ⟨t'p, ha⟩ have h₁' : t'.points i₁ = t.points i₁ := h₁ have h₂' : t'.points i₂ = p := h₂ have h₃' : t'.points i₃ = t.points i₃ := h₃ have h' : (2 : ℤ) • ∡ (t'.points i₁) (t'.points i₂) (t'.points i₃) = (2 : ℤ) • ∡ (t.points i₁) (t.points i₂) (t.points i₃) := by rwa [h₁', h₂', h₃'] rw [← circumsphere_eq_circumsphere_of_eq_of_eq_of_two_zsmul_oangle_eq h₁₂ h₁₃ h₂₃ h₁' h₃' h', ← h₂'] exact Simplex.mem_circumsphere _ _ end Triangle end Affine namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] local notation "o" => Module.Oriented.positiveOrientation /-- Converse of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π. -/ theorem cospherical_of_two_zsmul_oangle_eq_of_not_collinear {p₁ p₂ p₃ p₄ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄) (hn : ¬Collinear ℝ ({p₁, p₂, p₄} : Set P)) : Cospherical ({p₁, p₂, p₃, p₄} : Set P) := by have hn' : ¬Collinear ℝ ({p₁, p₃, p₄} : Set P) := by rwa [← collinear_iff_of_two_zsmul_oangle_eq h] let t₁ : Affine.Triangle ℝ P := ⟨![p₁, p₂, p₄], affineIndependent_iff_not_collinear_set.2 hn⟩ let t₂ : Affine.Triangle ℝ P := ⟨![p₁, p₃, p₄], affineIndependent_iff_not_collinear_set.2 hn'⟩ rw [cospherical_iff_exists_sphere] refine ⟨t₂.circumsphere, ?_⟩ simp_rw [Set.insert_subset_iff, Set.singleton_subset_iff] refine ⟨t₂.mem_circumsphere 0, ?_, t₂.mem_circumsphere 1, t₂.mem_circumsphere 2⟩ rw [Affine.Triangle.circumsphere_eq_circumsphere_of_eq_of_eq_of_two_zsmul_oangle_eq (by decide : (0 : Fin 3) ≠ 1) (by decide : (0 : Fin 3) ≠ 2) (by decide) (show t₂.points 0 = t₁.points 0 from rfl) rfl h.symm] exact t₁.mem_circumsphere 1 /-- Converse of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π, with a "concyclic" conclusion. -/ theorem concyclic_of_two_zsmul_oangle_eq_of_not_collinear {p₁ p₂ p₃ p₄ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄) (hn : ¬Collinear ℝ ({p₁, p₂, p₄} : Set P)) : Concyclic ({p₁, p₂, p₃, p₄} : Set P) := ⟨cospherical_of_two_zsmul_oangle_eq_of_not_collinear h hn, coplanar_of_fact_finrank_eq_two _⟩ /-- Converse of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π, with a "cospherical or collinear" conclusion. -/ theorem cospherical_or_collinear_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄) : Cospherical ({p₁, p₂, p₃, p₄} : Set P) ∨ Collinear ℝ ({p₁, p₂, p₃, p₄} : Set P) := by by_cases hc : Collinear ℝ ({p₁, p₂, p₄} : Set P) · by_cases he : p₁ = p₄ · rw [he, Set.insert_eq_self.2 (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)))] by_cases hl : Collinear ℝ ({p₂, p₃, p₄} : Set P); · exact Or.inr hl rw [or_iff_left hl] let t : Affine.Triangle ℝ P := ⟨![p₂, p₃, p₄], affineIndependent_iff_not_collinear_set.2 hl⟩ rw [cospherical_iff_exists_sphere] refine ⟨t.circumsphere, ?_⟩ simp_rw [Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨t.mem_circumsphere 0, t.mem_circumsphere 1, t.mem_circumsphere 2⟩ have hc' : Collinear ℝ ({p₁, p₃, p₄} : Set P) := by rwa [← collinear_iff_of_two_zsmul_oangle_eq h] refine Or.inr ?_ rw [Set.insert_comm p₁ p₂] at hc rwa [Set.insert_comm p₁ p₂, hc'.collinear_insert_iff_of_ne (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _))) he] · exact Or.inl (cospherical_of_two_zsmul_oangle_eq_of_not_collinear h hc) /-- Converse of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π, with a "concyclic or collinear" conclusion. -/ theorem concyclic_or_collinear_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄) : Concyclic ({p₁, p₂, p₃, p₄} : Set P) ∨ Collinear ℝ ({p₁, p₂, p₃, p₄} : Set P) := by rcases cospherical_or_collinear_of_two_zsmul_oangle_eq h with (hc | hc) · exact Or.inl ⟨hc, coplanar_of_fact_finrank_eq_two _⟩ · exact Or.inr hc end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Bisector.lean
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.Projection import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle import Mathlib.Geometry.Euclidean.Projection /-! # Angle bisectors. This file proves lemmas relating to bisecting angles. -/ namespace EuclideanGeometry variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] /-- Auxiliary lemma for the degenerate case of `dist_orthogonalProjection_eq_iff_angle_eq` where `p` lies in `s₁`. -/ private lemma dist_orthogonalProjection_eq_iff_angle_eq_aux₁ {p p' : P} {s₁ s₂ : AffineSubspace ℝ P} [s₁.direction.HasOrthogonalProjection] [s₂.direction.HasOrthogonalProjection] (hp' : p' ∈ s₁ ⊓ s₂) (h' : p ∈ s₁) : haveI : Nonempty s₁ := ⟨p', hp'.1⟩ haveI : Nonempty s₂ := ⟨p', hp'.2⟩ dist p (orthogonalProjection s₁ p) = dist p (orthogonalProjection s₂ p) ↔ ∠ p p' (orthogonalProjection s₁ p) = ∠ p p' (orthogonalProjection s₂ p) := by have : Nonempty s₁ := ⟨p', hp'.1⟩ have : Nonempty s₂ := ⟨p', hp'.2⟩ refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [orthogonalProjection_eq_self_iff.2 h'] at h ⊢ rw [dist_self, zero_eq_dist, eq_comm, orthogonalProjection_eq_self_iff] at h rw [orthogonalProjection_eq_self_iff.2 h] · rw [orthogonalProjection_eq_self_iff.2 h'] at h ⊢ rw [dist_self, zero_eq_dist, eq_comm, orthogonalProjection_eq_self_iff] by_cases hpp' : p = p' · subst hpp' exact hp'.2 · by_contra hn rw [angle_self_of_ne hpp', angle_comm, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_self_orthogonalProjection p hp'.2), Real.zero_eq_arcsin_iff, div_eq_zero_iff] at h · simp only [dist_eq_zero, hpp', or_false] at h rw [eq_comm] at h simp [orthogonalProjection_eq_self_iff, hn] at h · exact .inl (Ne.symm (orthogonalProjection_eq_self_iff.symm.not.1 hn)) /-- Auxiliary lemma for the degenerate case of `dist_orthogonalProjection_eq_iff_angle_eq` where `p` lies in `s₁` or `s₂`. -/ private lemma dist_orthogonalProjection_eq_iff_angle_eq_aux {p p' : P} {s₁ s₂ : AffineSubspace ℝ P} [s₁.direction.HasOrthogonalProjection] [s₂.direction.HasOrthogonalProjection] (hp' : p' ∈ s₁ ⊓ s₂) (h' : p ∈ s₁ ∨ p ∈ s₂) : haveI : Nonempty s₁ := ⟨p', hp'.1⟩ haveI : Nonempty s₂ := ⟨p', hp'.2⟩ dist p (orthogonalProjection s₁ p) = dist p (orthogonalProjection s₂ p) ↔ ∠ p p' (orthogonalProjection s₁ p) = ∠ p p' (orthogonalProjection s₂ p) := by have : Nonempty s₁ := ⟨p', hp'.1⟩ have : Nonempty s₂ := ⟨p', hp'.2⟩ rcases h' with h' | h' · exact dist_orthogonalProjection_eq_iff_angle_eq_aux₁ hp' h' · nth_rw 1 [eq_comm] nth_rw 2 [eq_comm] rw [inf_comm] at hp' exact dist_orthogonalProjection_eq_iff_angle_eq_aux₁ hp' h' /-- A point `p` is equidistant to two affine subspaces if and only if the angles at a point `p'` in their intersection between `p` and its orthogonal projections onto the subspaces are equal. -/ lemma dist_orthogonalProjection_eq_iff_angle_eq {p p' : P} {s₁ s₂ : AffineSubspace ℝ P} [s₁.direction.HasOrthogonalProjection] [s₂.direction.HasOrthogonalProjection] (hp' : p' ∈ s₁ ⊓ s₂) : haveI : Nonempty s₁ := ⟨p', hp'.1⟩ haveI : Nonempty s₂ := ⟨p', hp'.2⟩ dist p (orthogonalProjection s₁ p) = dist p (orthogonalProjection s₂ p) ↔ ∠ p p' (orthogonalProjection s₁ p) = ∠ p p' (orthogonalProjection s₂ p) := by have : Nonempty s₁ := ⟨p', hp'.1⟩ have : Nonempty s₂ := ⟨p', hp'.2⟩ by_cases h' : p ∈ s₁ ∨ p ∈ s₂ · exact dist_orthogonalProjection_eq_iff_angle_eq_aux hp' h' rw [not_or] at h' rw [angle_comm, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_self_orthogonalProjection p hp'.1) (.inl (Ne.symm (orthogonalProjection_eq_self_iff.symm.not.1 h'.1))), angle_comm, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_self_orthogonalProjection p hp'.2) (.inl (Ne.symm (orthogonalProjection_eq_self_iff.symm.not.1 h'.2)))] · refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [h] · have hp : p ≠ p' := by rintro rfl exact h'.1 hp'.1 have hpd : 0 < dist p p' := dist_pos.2 hp rw [Real.arcsin_inj (le_trans (by norm_num : (-1 : ℝ) ≤ 0) (by positivity)) ((div_le_one hpd).2 ?_) (le_trans (by norm_num : (-1 : ℝ) ≤ 0) (by positivity)) ((div_le_one hpd).2 ?_)] at h · rwa [div_left_inj' hpd.ne'] at h · rw [dist_orthogonalProjection_eq_infDist] exact Metric.infDist_le_dist_of_mem (SetLike.mem_coe.1 hp'.1) · rw [dist_orthogonalProjection_eq_infDist] exact Metric.infDist_le_dist_of_mem (SetLike.mem_coe.1 hp'.2) section Oriented open Module variable [Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two -- See https://github.com/leanprover/lean4/issues/11182 for why hypotheses are after the colon. /-- A point `p` is equidistant to two affine subspaces (typically lines, for this version of the lemma) if the oriented angles at a point `p'` in their intersection between `p` and its orthogonal projections onto the subspaces are equal. -/ lemma dist_orthogonalProjection_eq_of_oangle_eq {p p' : P} {s₁ s₂ : AffineSubspace ℝ P} (hp' : p' ∈ s₁ ⊓ s₂) : haveI : Nonempty s₁ := ⟨p', hp'.1⟩ haveI : Nonempty s₂ := ⟨p', hp'.2⟩ orthogonalProjection s₁ p ≠ p' → orthogonalProjection s₂ p ≠ p' → ∡ (orthogonalProjection s₁ p : P) p' p = ∡ p p' (orthogonalProjection s₂ p) → dist p (orthogonalProjection s₁ p) = dist p (orthogonalProjection s₂ p) := by intro hp₁ hp₂ h rw [dist_orthogonalProjection_eq_iff_angle_eq hp', angle_comm, angle_eq_iff_oangle_eq_or_wbtw hp₁ hp₂] exact .inl h -- See https://github.com/leanprover/lean4/issues/11182 for why hypotheses are after the colon. /-- The oriented angles at a point `p'` in their intersection between `p` and its orthogonal projections onto two affine subspaces (typically lines, for this version of the lemma) are equal if `p` is equidistant to the two subspaces. -/ lemma oangle_eq_of_dist_orthogonalProjection_eq {p p' : P} {s₁ s₂ : AffineSubspace ℝ P} (hp' : p' ∈ s₁ ⊓ s₂) : haveI : Nonempty s₁ := ⟨p', hp'.1⟩ haveI : Nonempty s₂ := ⟨p', hp'.2⟩ (orthogonalProjection s₁ p : P) ≠ orthogonalProjection s₂ p → dist p (orthogonalProjection s₁ p) = dist p (orthogonalProjection s₂ p) → ∡ (orthogonalProjection s₁ p : P) p' p = ∡ p p' (orthogonalProjection s₂ p) := by intro hne h haveI : Nonempty s₁ := ⟨p', hp'.1⟩ haveI : Nonempty s₂ := ⟨p', hp'.2⟩ haveI : Nonempty (s₁ ⊓ s₂ : AffineSubspace ℝ P) := ⟨p', hp'⟩ have hp₁ : orthogonalProjection s₁ p ≠ p' := by intro hp rw [hp, ← sq_eq_sq₀ dist_nonneg dist_nonneg, pow_two, pow_two, dist_comm p p', dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p hp'.2, add_eq_right, mul_eq_zero, dist_eq_zero, or_self] at h grind have hp₂ : orthogonalProjection s₂ p ≠ p' := by intro hp rw [hp, ← sq_eq_sq₀ dist_nonneg dist_nonneg, pow_two, pow_two, dist_comm p p', dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p hp'.1, right_eq_add, mul_eq_zero, dist_eq_zero, or_self] at h grind have hc : ¬ Collinear ℝ {p', (orthogonalProjection s₁ p : P), (orthogonalProjection s₂ p : P)} := by intro hc have h₁ : (orthogonalProjection s₁ p : P) ∈ line[ℝ, p', (orthogonalProjection s₂ p : P)] := hc.mem_affineSpan_of_mem_of_ne (by grind) (by grind) (by grind) (by grind) have h₁' : (orthogonalProjection s₁ p : P) ∈ s₁ ⊓ s₂ := ⟨orthogonalProjection_mem _, SetLike.le_def.1 (affineSpan_pair_le_of_mem_of_mem hp'.2 (orthogonalProjection_mem _)) h₁⟩ have h₁'' : (orthogonalProjection s₁ p : P) = (orthogonalProjection (s₁ ⊓ s₂) p : P) := by rw [← orthogonalProjection_orthogonalProjection_of_le inf_le_left, eq_comm, orthogonalProjection_eq_self_iff] grind have h₂ : (orthogonalProjection s₂ p : P) ∈ line[ℝ, p', (orthogonalProjection s₁ p : P)] := hc.mem_affineSpan_of_mem_of_ne (by grind) (by grind) (by grind) (by grind) have h₂' : (orthogonalProjection s₂ p : P) ∈ s₁ ⊓ s₂ := ⟨SetLike.le_def.1 (affineSpan_pair_le_of_mem_of_mem hp'.1 (orthogonalProjection_mem _)) h₂, orthogonalProjection_mem _⟩ have h₂'' : (orthogonalProjection s₂ p : P) = (orthogonalProjection (s₁ ⊓ s₂) p : P) := by rw [← orthogonalProjection_orthogonalProjection_of_le inf_le_right, eq_comm, orthogonalProjection_eq_self_iff] grind apply hne rw [h₁'', h₂''] rw [dist_orthogonalProjection_eq_iff_angle_eq hp', angle_comm, angle_eq_iff_oangle_eq_or_wbtw hp₁ hp₂] at h rcases h with h | h | h · exact h · exfalso exact hc h.collinear · exfalso have h' := h.collinear rw [Set.pair_comm] at h' exact hc h' -- See https://github.com/leanprover/lean4/issues/11182 for why hypotheses are after the colon. /-- A point `p` is equidistant to two affine subspaces (typically lines, for this version of the lemma) if and only if the oriented angles at a point `p'` in their intersection between `p` and its orthogonal projections onto the subspaces are equal. -/ lemma dist_orthogonalProjection_eq_iff_oangle_eq {p p' : P} {s₁ s₂ : AffineSubspace ℝ P} (hp' : p' ∈ s₁ ⊓ s₂) : haveI : Nonempty s₁ := ⟨p', hp'.1⟩ haveI : Nonempty s₂ := ⟨p', hp'.2⟩ (orthogonalProjection s₁ p : P) ≠ orthogonalProjection s₂ p → orthogonalProjection s₁ p ≠ p' → orthogonalProjection s₂ p ≠ p' → (dist p (orthogonalProjection s₁ p) = dist p (orthogonalProjection s₂ p) ↔ ∡ (orthogonalProjection s₁ p : P) p' p = ∡ p p' (orthogonalProjection s₂ p)) := fun hne hp₁ hp₂ ↦ ⟨oangle_eq_of_dist_orthogonalProjection_eq hp' hne, dist_orthogonalProjection_eq_of_oangle_eq hp' hp₁ hp₂⟩ end Oriented end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes, angles modulo `π` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `π` can be represented modulo `2 * π` as equalities of `(2 : ℤ) • θ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "ω" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) /-- Oriented angles are continuous when the vectors involved are nonzero. -/ @[fun_prop] theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ · exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π)) apply arg_ofReal_of_nonneg positivity /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by rintro rfl; simp at h /-- If the angle between two vectors is `π`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] /-- Negating the first vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle (-x) y = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the second vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x (-y) = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_left hx hy] /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_right hx hy] /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] /-- The angle between the negation of a nonzero vector and that vector is `π`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by simp [oangle_neg_left, hx] /-- The angle between a nonzero vector and its negation is `π`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by simp [oangle_neg_right, hx] /-- Twice the angle between the negation of a vector and that vector is 0. -/ theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Twice the angle between a vector and its negation is 0. -/ theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel] /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel] /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r • x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r • y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) : o.oangle (r₁ • x) (r₂ • x) = 0 := by rcases hr₁.lt_or_eq with (h | h) · simp [h, hr₂] · simp [h.symm] /-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_gt with (h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_gt with (h | h) <;> simp [h] /-- Twice the angle between a multiple of a vector and that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by rcases lt_or_ge r 0 with (h | h) <;> simp [h] /-- Twice the angle between a vector and a multiple of that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by rcases lt_or_ge r 0 with (h | h) <;> simp [h] /-- Twice the angle between two multiples of a vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} : (2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h] /-- If the spans of two vectors are equal, twice angles with those vectors on the left are equal. -/ theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) : (2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two vectors are equal, twice angles with those vectors on the right are equal. -/ theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two pairs of vectors are equal, twice angles between those vectors are equal. -/ theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x) (hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz] /-- The oriented angle between two vectors is zero if and only if the angle with the vectors swapped is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by rw [oangle_rev, neg_eq_zero] /-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/ theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero, Complex.arg_eq_zero_iff] simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y /-- The oriented angle between two vectors is `π` if and only if the angle with the vectors swapped is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi] /-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is on the same ray as the negation of the second. -/ theorem oangle_eq_pi_iff_sameRay_neg {x y : V} : o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by rw [← o.oangle_eq_zero_iff_sameRay] constructor · intro h by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h refine ⟨hx, hy, ?_⟩ rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi] · rintro ⟨hx, hy, h⟩ rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h /-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are not linearly independent. -/ theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg, sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent] /-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero or the second is a multiple of the first. -/ theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ x = 0 ∨ ∃ r : ℝ, y = r • x := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (h | ⟨-, -, h⟩) · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx exact Or.inr ⟨r, rfl⟩ · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx refine Or.inr ⟨-r, ?_⟩ simp [hy] · rcases h with (rfl | ⟨r, rfl⟩); · simp by_cases hx : x = 0; · simp [hx] rcases lt_trichotomy r 0 with (hr | hr | hr) · rw [← neg_smul] exact Or.inr ⟨hx, smul_ne_zero hr.ne hx, SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩ · simp [hr] · exact Or.inl (SameRay.sameRay_pos_smul_right x hr) /-- The oriented angle between two vectors is not zero or `π` if and only if those two vectors are linearly independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} : o.oangle x y ≠ 0 ∧ o.oangle x y ≠ π ↔ LinearIndependent ℝ ![x, y] := by rw [← not_or, ← not_iff_not, Classical.not_not, oangle_eq_zero_or_eq_pi_iff_not_linearIndependent] /-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/ theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ ‖x‖ = ‖y‖ ∧ o.oangle x y = 0 := by rw [oangle_eq_zero_iff_sameRay] constructor · rintro rfl simp; rfl · rcases eq_or_ne y 0 with (rfl | hy) · simp rintro ⟨h₁, h₂⟩ obtain ⟨r, hr, rfl⟩ := h₂.exists_nonneg_right hy have : ‖y‖ ≠ 0 := by simpa using hy obtain rfl : r = 1 := by apply mul_right_cancel₀ this simpa [norm_smul, abs_of_nonneg hr] using h₁ simp /-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/ theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : x = y ↔ o.oangle x y = 0 := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩ /-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/ theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ ‖x‖ = ‖y‖ := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩ /-- Given three nonzero vectors, the angle between the first and the second plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z = o.oangle x z := by simp_rw [oangle] rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z] · congr 1 exact mod_cast Complex.arg_real_mul _ (by positivity : 0 < ‖y‖ ^ 2) · exact o.kahler_ne_zero hx hy · exact o.kahler_ne_zero hy hz /-- Given three nonzero vectors, the angle between the second and the third plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle x y = o.oangle y z := by rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/ theorem oangle_add_cyc3 {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = π := by rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx, show o.oangle x y + π + (o.oangle y z + π) + (o.oangle z x + π) = o.oangle x y + o.oangle y z + o.oangle z x + (π + π + π : Real.Angle) by abel, o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = π := by simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz] /-- Pons asinorum, oriented vector angle form. -/ theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h] /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented vector angle form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x ≠ y) (h : ‖x‖ = ‖y‖) : o.oangle y x = π - (2 : ℤ) • o.oangle (y - x) y := by rw [two_zsmul] nth_rw 1 [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] rw [eq_sub_iff_add_eq, ← oangle_neg_neg, ← add_assoc] have hy : y ≠ 0 := by rintro rfl rw [norm_zero, norm_eq_zero] at h exact hn h have hx : x ≠ 0 := norm_ne_zero_iff.1 (h.symm ▸ norm_ne_zero_iff.2 hy) convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1 simp /-- The angle between two vectors, with respect to an orientation given by `Orientation.map` with a linear isometric equivalence, equals the angle between those two vectors, transformed by the inverse of that equivalence, with respect to the original orientation. -/ @[simp] theorem oangle_map (x y : V') (f : V ≃ₗᵢ[ℝ] V') : (Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by simp [oangle, o.kahler_map] @[simp] protected theorem _root_.Complex.oangle (w z : ℂ) : Complex.orientation.oangle w z = Complex.arg (conj w * z) := by simp [oangle, mul_comm z] /-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem oangle_map_complex (f : V ≃ₗᵢ[ℝ] ℂ) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) : o.oangle x y = Complex.arg (conj (f x) * f y) := by rw [← Complex.oangle, ← hf, o.oangle_map] iterate 2 rw [LinearIsometryEquiv.symm_apply_apply] /-- Negating the orientation negates the value of `oangle`. -/ theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by simp [oangle] /-- The inner product of two vectors is the product of the norms and the cosine of the oriented angle between the vectors. -/ theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) : ⟪x, y⟫ = ‖x‖ * ‖y‖ * Real.Angle.cos (o.oangle x y) := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.norm_kahler] · simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im] simp [field] · exact o.kahler_ne_zero hx hy /-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by the product of the norms. -/ theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.Angle.cos (o.oangle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := by rw [o.inner_eq_norm_mul_norm_mul_cos_oangle] field /-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle] /-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x y = InnerProductGeometry.angle x y ∨ o.oangle x y = -InnerProductGeometry.angle x y := Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy /-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle, converted to a real. -/ theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by have h0 := InnerProductGeometry.angle_nonneg x y have hpi := InnerProductGeometry.angle_le_pi x y rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h) · rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff] exact ⟨h0, hpi⟩ · rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff] exact ⟨h0, hpi⟩ /-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is zero or the unoriented angle is 0 or π. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V} (h : (o.oangle x y).sign = 0) : x = 0 ∨ y = 0 ∨ InnerProductGeometry.angle x y = 0 ∨ InnerProductGeometry.angle x y = π := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [o.angle_eq_abs_oangle_toReal hx hy] rw [Real.Angle.sign_eq_zero_iff] at h rcases h with (h | h) <;> simp [h, Real.pi_pos.le] /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V} (h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by by_cases! h0 : (w = 0 ∨ x = 0) ∨ y = 0 ∨ z = 0 · have hs' : (o.oangle w x).sign = 0 ∧ (o.oangle y z).sign = 0 := by rcases h0 with ((rfl | rfl) | rfl | rfl) · simpa using hs.symm · simpa using hs.symm · simpa using hs · simpa using hs rcases hs' with ⟨hswx, hsyz⟩ have h' : InnerProductGeometry.angle w x = π / 2 ∧ InnerProductGeometry.angle y z = π / 2 := by rcases h0 with ((rfl | rfl) | rfl | rfl) · simpa using h.symm · simpa using h.symm · simpa using h · simpa using h rcases h' with ⟨hwx, hyz⟩ have hpi : π / 2 ≠ π := by intro hpi rw [div_eq_iff, eq_comm, ← sub_eq_zero, mul_two, add_sub_cancel_right] at hpi · exact Real.pi_pos.ne.symm hpi · exact two_ne_zero have h0wx : w = 0 ∨ x = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0' have h0yz : y = 0 ∨ z = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0' rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz] · rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs] rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2, o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h /-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/ theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w ≠ 0) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔ o.oangle w x = o.oangle y z := by refine ⟨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_⟩ rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h] /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are negations of each other, then the oriented angles are negations of each other (even in degenerate cases). -/ lemma oangle_eq_neg_of_angle_eq_of_sign_eq_neg {w x y z : V} (h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z) (hs : (o.oangle w x).sign = -(o.oangle y z).sign) : o.oangle w x = -o.oangle y z := by rw [← oangle_rev] rw [← Real.Angle.sign_neg, ← oangle_rev] at hs nth_rw 2 [InnerProductGeometry.angle_comm] at h exact o.oangle_eq_of_angle_eq_of_sign_eq h hs /-- If the signs of two oriented angles between nonzero vectors are negations of each other, the oriented angles are negations of each other if and only if the unoriented angles are equal. -/ lemma angle_eq_iff_oangle_eq_neg_of_sign_eq_neg {w x y z : V} (hw : w ≠ 0) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) (hs : (o.oangle w x).sign = -(o.oangle y z).sign) : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔ o.oangle w x = -o.oangle y z := by rw [← oangle_rev] rw [← Real.Angle.sign_neg, ← oangle_rev] at hs nth_rw 2 [InnerProductGeometry.angle_comm] exact o.angle_eq_iff_oangle_eq_of_sign_eq hw hx hz hy hs /-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/ theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : o.oangle x y = InnerProductGeometry.angle x y := by by_cases hx : x = 0; · simp [hx] at h by_cases hy : y = 0; · simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_ intro hxy rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) /-- The oriented angle between two vectors equals minus the unoriented angle if the sign is negative. -/ theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : o.oangle x y = -InnerProductGeometry.angle x y := by by_cases hx : x = 0; · simp [hx] at h by_cases hy : y = 0; · simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_ intro hxy rw [hxy, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) /-- The oriented angle between two nonzero vectors is zero if and only if the unoriented angle is zero. -/ theorem oangle_eq_zero_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x y = 0 ↔ InnerProductGeometry.angle x y = 0 := by refine ⟨fun h => ?_, fun h => ?_⟩ · simpa [o.angle_eq_abs_oangle_toReal hx hy] · have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy rw [h] at ha simpa using ha /-- The oriented angle between two vectors is `π` if and only if the unoriented angle is `π`. -/ theorem oangle_eq_pi_iff_angle_eq_pi {x y : V} : o.oangle x y = π ↔ InnerProductGeometry.angle x y = π := by by_cases hx : x = 0 · simp [hx, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, Real.pi_ne_zero] by_cases hy : y = 0 · simp [hy, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, Real.pi_ne_zero] refine ⟨fun h => ?_, fun h => ?_⟩ · rw [o.angle_eq_abs_oangle_toReal hx hy, h] simp [Real.pi_pos.le] · have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy rw [h] at ha simpa using ha /-- One of two vectors is zero or the oriented angle between them is plus or minus `π / 2` if and only if the inner product of those vectors is zero. -/ theorem eq_zero_or_oangle_eq_iff_inner_eq_zero {x y : V} : x = 0 ∨ y = 0 ∨ o.oangle x y = (π / 2 : ℝ) ∨ o.oangle x y = (-π / 2 : ℝ) ↔ ⟪x, y⟫ = 0 := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two, or_iff_right hx, or_iff_right hy] refine ⟨fun h => ?_, fun h => ?_⟩ · rwa [o.angle_eq_abs_oangle_toReal hx hy, Real.Angle.abs_toReal_eq_pi_div_two_iff] · convert o.oangle_eq_angle_or_eq_neg_angle hx hy using 2 <;> rw [h] simp only [neg_div, Real.Angle.coe_neg] /-- If the oriented angle between two vectors is `π / 2`, the inner product of those vectors is zero. -/ theorem inner_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : ⟪x, y⟫ = 0 := o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inl h /-- If the oriented angle between two vectors is `π / 2`, the inner product of those vectors (reversed) is zero. -/ theorem inner_rev_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : ⟪y, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_pi_div_two h] /-- If the oriented angle between two vectors is `-π / 2`, the inner product of those vectors is zero. -/ theorem inner_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : ⟪x, y⟫ = 0 := o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inr h /-- If the oriented angle between two vectors is `-π / 2`, the inner product of those vectors (reversed) is zero. -/ theorem inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : ⟪y, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h] /-- Negating the first vector passed to `oangle` negates the sign of the angle. -/ @[simp] theorem oangle_sign_neg_left (x y : V) : (o.oangle (-x) y).sign = -(o.oangle x y).sign := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [o.oangle_neg_left hx hy, Real.Angle.sign_add_pi] /-- Negating the second vector passed to `oangle` negates the sign of the angle. -/ @[simp] theorem oangle_sign_neg_right (x y : V) : (o.oangle x (-y)).sign = -(o.oangle x y).sign := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [o.oangle_neg_right hx hy, Real.Angle.sign_add_pi] /-- Multiplying the first vector passed to `oangle` by a real multiplies the sign of the angle by the sign of the real. -/ @[simp] theorem oangle_sign_smul_left (x y : V) (r : ℝ) : (o.oangle (r • x) y).sign = SignType.sign r * (o.oangle x y).sign := by rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a real multiplies the sign of the angle by the sign of the real. -/ @[simp] theorem oangle_sign_smul_right (x y : V) (r : ℝ) : (o.oangle x (r • y)).sign = SignType.sign r * (o.oangle x y).sign := by rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h] /-- Auxiliary lemma for the proof of `oangle_sign_smul_add_right`; not intended to be used outside of that proof. -/ theorem oangle_smul_add_right_eq_zero_or_eq_pi_iff {x y : V} (r : ℝ) : o.oangle x (r • x + y) = 0 ∨ o.oangle x (r • x + y) = π ↔ o.oangle x y = 0 ∨ o.oangle x y = π := by simp_rw [oangle_eq_zero_or_eq_pi_iff_not_linearIndependent, Fintype.not_linearIndependent_iff, Fin.sum_univ_two, Fin.exists_fin_two] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ⟨m, h, hm⟩ change m 0 • x + m 1 • (r • x + y) = 0 at h refine ⟨![m 0 + m 1 * r, m 1], ?_⟩ change (m 0 + m 1 * r) • x + m 1 • y = 0 ∧ (m 0 + m 1 * r ≠ 0 ∨ m 1 ≠ 0) rw [smul_add, smul_smul, ← add_assoc, ← add_smul] at h refine ⟨h, not_and_or.1 fun h0 => ?_⟩ obtain ⟨h0, h1⟩ := h0 rw [h1] at h0 hm rw [zero_mul, add_zero] at h0 simp [h0] at hm · rcases h with ⟨m, h, hm⟩ change m 0 • x + m 1 • y = 0 at h refine ⟨![m 0 - m 1 * r, m 1], ?_⟩ change (m 0 - m 1 * r) • x + m 1 • (r • x + y) = 0 ∧ (m 0 - m 1 * r ≠ 0 ∨ m 1 ≠ 0) rw [sub_smul, smul_add, smul_smul, ← add_assoc, sub_add_cancel] refine ⟨h, not_and_or.1 fun h0 => ?_⟩ obtain ⟨h0, h1⟩ := h0 rw [h1] at h0 hm rw [zero_mul, sub_zero] at h0 simp [h0] at hm /-- Adding a multiple of the first vector passed to `oangle` to the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_smul_add_right (x y : V) (r : ℝ) : (o.oangle x (r • x + y)).sign = (o.oangle x y).sign := by by_cases h : o.oangle x y = 0 ∨ o.oangle x y = π · rwa [Real.Angle.sign_eq_zero_iff.2 h, Real.Angle.sign_eq_zero_iff, oangle_smul_add_right_eq_zero_or_eq_pi_iff] have h' : ∀ r' : ℝ, o.oangle x (r' • x + y) ≠ 0 ∧ o.oangle x (r' • x + y) ≠ π := by intro r' rwa [← o.oangle_smul_add_right_eq_zero_or_eq_pi_iff r', not_or] at h let s : Set (V × V) := (fun r' : ℝ => (x, r' • x + y)) '' Set.univ have hc : IsConnected s := isConnected_univ.image _ (by fun_prop) have hf : ContinuousOn (fun z : V × V => o.oangle z.1 z.2) s := by refine continuousOn_of_forall_continuousAt fun z hz => o.continuousAt_oangle ?_ ?_ all_goals simp_rw [s, Set.mem_image] at hz obtain ⟨r', -, rfl⟩ := hz simp only intro hz · simpa [hz] using (h' 0).1 · simpa [hz] using (h' r').1 have hs : ∀ z : V × V, z ∈ s → o.oangle z.1 z.2 ≠ 0 ∧ o.oangle z.1 z.2 ≠ π := by grind have hx : (x, y) ∈ s := by convert Set.mem_image_of_mem (fun r' : ℝ => (x, r' • x + y)) (Set.mem_univ 0) simp have hy : (x, r • x + y) ∈ s := Set.mem_image_of_mem _ (Set.mem_univ _) convert Real.Angle.sign_eq_of_continuousOn hc hf hs hx hy /-- Adding a multiple of the second vector passed to `oangle` to the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_smul_left (x y : V) (r : ℝ) : (o.oangle (x + r • y) y).sign = (o.oangle x y).sign := by simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm x, oangle_sign_smul_add_right] /-- Subtracting a multiple of the first vector passed to `oangle` from the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_smul_right (x y : V) (r : ℝ) : (o.oangle x (y - r • x)).sign = (o.oangle x y).sign := by rw [sub_eq_add_neg, ← neg_smul, add_comm, oangle_sign_smul_add_right] /-- Subtracting a multiple of the second vector passed to `oangle` from the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_smul_left (x y : V) (r : ℝ) : (o.oangle (x - r • y) y).sign = (o.oangle x y).sign := by rw [sub_eq_add_neg, ← neg_smul, oangle_sign_add_smul_left] /-- Adding the first vector passed to `oangle` to the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_right (x y : V) : (o.oangle x (x + y)).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_smul_add_right x y 1, one_smul] /-- Adding the second vector passed to `oangle` to the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_left (x y : V) : (o.oangle (x + y) y).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_add_smul_left x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_right (x y : V) : (o.oangle x (y - x)).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_sub_smul_right x y 1, one_smul] /-- Subtracting the second vector passed to `oangle` from the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_left (x y : V) : (o.oangle (x - y) y).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_sub_smul_left x y 1, one_smul] /-- Subtracting the second vector passed to `oangle` from a multiple of the first vector negates the sign of the angle. -/ @[simp] theorem oangle_sign_smul_sub_right (x y : V) (r : ℝ) : (o.oangle x (r • x - y)).sign = -(o.oangle x y).sign := by rw [← oangle_sign_neg_right, sub_eq_add_neg, oangle_sign_smul_add_right] /-- Subtracting the first vector passed to `oangle` from a multiple of the second vector negates the sign of the angle. -/ @[simp] theorem oangle_sign_smul_sub_left (x y : V) (r : ℝ) : (o.oangle (r • y - x) y).sign = -(o.oangle x y).sign := by rw [← oangle_sign_neg_left, sub_eq_neg_add, oangle_sign_add_smul_left] /-- Subtracting the second vector passed to `oangle` from the first vector negates the sign of the angle. -/ theorem oangle_sign_sub_right_eq_neg (x y : V) : (o.oangle x (x - y)).sign = -(o.oangle x y).sign := by rw [← o.oangle_sign_smul_sub_right x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector negates the sign of the angle. -/ theorem oangle_sign_sub_left_eq_neg (x y : V) : (o.oangle (y - x) y).sign = -(o.oangle x y).sign := by rw [← o.oangle_sign_smul_sub_left x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector then swapping the vectors does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_right_swap (x y : V) : (o.oangle y (y - x)).sign = (o.oangle x y).sign := by rw [oangle_sign_sub_right_eq_neg, o.oangle_rev y x, Real.Angle.sign_neg] /-- Subtracting the second vector passed to `oangle` from the first vector then swapping the vectors does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_left_swap (x y : V) : (o.oangle (x - y) x).sign = (o.oangle x y).sign := by rw [oangle_sign_sub_left_eq_neg, o.oangle_rev y x, Real.Angle.sign_neg] /-- The sign of the angle between a vector, and a linear combination of that vector with a second vector, is the sign of the factor by which the second vector is multiplied in that combination multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_right (x y : V) (r₁ r₂ : ℝ) : (o.oangle x (r₁ • x + r₂ • y)).sign = SignType.sign r₂ * (o.oangle x y).sign := by simp /-- The sign of the angle between a linear combination of two vectors and the second vector is the sign of the factor by which the first vector is multiplied in that combination multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_left (x y : V) (r₁ r₂ : ℝ) : (o.oangle (r₁ • x + r₂ • y) y).sign = SignType.sign r₁ * (o.oangle x y).sign := by simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm (r₁ • x), oangle_sign_smul_add_smul_right, mul_neg] /-- The sign of the angle between two linear combinations of two vectors is the sign of the determinant of the factors in those combinations multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_smul_add_smul (x y : V) (r₁ r₂ r₃ r₄ : ℝ) : (o.oangle (r₁ • x + r₂ • y) (r₃ • x + r₄ • y)).sign = SignType.sign (r₁ * r₄ - r₂ * r₃) * (o.oangle x y).sign := by by_cases hr₁ : r₁ = 0 · rw [hr₁, zero_smul, zero_mul, zero_add, zero_sub, Left.sign_neg, oangle_sign_smul_left, add_comm, oangle_sign_smul_add_smul_right, oangle_rev, Real.Angle.sign_neg, sign_mul, mul_neg, mul_neg, neg_mul, mul_assoc] · rw [← o.oangle_sign_smul_add_right (r₁ • x + r₂ • y) (r₃ • x + r₄ • y) (-r₃ / r₁), smul_add, smul_smul, smul_smul, div_mul_cancel₀ _ hr₁, neg_smul, ← add_assoc, add_comm (-(r₃ • x)), ← sub_eq_add_neg, sub_add_cancel, ← add_smul, oangle_sign_smul_right, oangle_sign_smul_add_smul_left, ← mul_assoc, ← sign_mul, add_mul, mul_assoc, mul_comm r₂ r₁, ← mul_assoc, div_mul_cancel₀ _ hr₁, add_comm, neg_mul, ← sub_eq_add_neg, mul_comm r₄, mul_comm r₃] /-- A base angle of an isosceles triangle is acute, oriented vector angle form. -/ theorem abs_oangle_sub_left_toReal_lt_pi_div_two {x y : V} (h : ‖x‖ = ‖y‖) : |(o.oangle (y - x) y).toReal| < π / 2 := by by_cases hn : x = y; · simp [hn, Real.pi_pos] have hs : ((2 : ℤ) • o.oangle (y - x) y).sign = (o.oangle (y - x) y).sign := by conv_rhs => rw [oangle_sign_sub_left_swap] rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hn h, Real.Angle.sign_pi_sub] rw [Real.Angle.sign_two_zsmul_eq_sign_iff] at hs rcases hs with (hs | hs) · rw [oangle_eq_pi_iff_oangle_rev_eq_pi, oangle_eq_pi_iff_sameRay_neg, neg_sub] at hs rcases hs with ⟨hy, -, hr⟩ rw [← exists_nonneg_left_iff_sameRay hy] at hr rcases hr with ⟨r, hr0, hr⟩ rw [eq_sub_iff_add_eq] at hr nth_rw 2 [← one_smul ℝ y] at hr rw [← add_smul] at hr rw [← hr, norm_smul, Real.norm_eq_abs, abs_of_pos (Left.add_pos_of_nonneg_of_pos hr0 one_pos), mul_left_eq_self₀, or_iff_left (norm_ne_zero_iff.2 hy), add_eq_right] at h rw [h, zero_add, one_smul] at hr exact False.elim (hn hr.symm) · exact hs /-- A base angle of an isosceles triangle is acute, oriented vector angle form. -/ theorem abs_oangle_sub_right_toReal_lt_pi_div_two {x y : V} (h : ‖x‖ = ‖y‖) : |(o.oangle x (x - y)).toReal| < π / 2 := (o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h).symm ▸ o.abs_oangle_sub_left_toReal_lt_pi_div_two h /-- `y` has equal unoriented angles to `x` and `z` if and only if it has equal oriented angles (bisects the angle) or `x` and `z` are on the same ray. -/ lemma angle_eq_iff_oangle_eq_or_sameRay {x y z : V} (hx : x ≠ 0) (hz : z ≠ 0) : InnerProductGeometry.angle x y = InnerProductGeometry.angle y z ↔ o.oangle x y = o.oangle y z ∨ SameRay ℝ x z := by by_cases hy : y = 0 · simp [hy] by_cases hr : SameRay ℝ x z · obtain ⟨r, hrp, rfl⟩ := hr.exists_pos_left hx hz simp [hr, hrp, InnerProductGeometry.angle_comm] simp only [hr, or_false] by_cases hs : (o.oangle x y).sign = (o.oangle y z).sign · rw [o.angle_eq_iff_oangle_eq_of_sign_eq hx hy hy hz hs] · have hn : o.oangle x y ≠ o.oangle y z := by grind simp only [hn, iff_false] intro he apply hr by_cases hs' : (o.oangle x y).sign = -(o.oangle y z).sign · rw [o.angle_eq_iff_oangle_eq_neg_of_sign_eq_neg hx hy hy hz hs'] at he rw [← o.oangle_eq_zero_iff_sameRay, ← o.oangle_add hx hy hz] simp [he] · have h0 : (o.oangle x y).sign = 0 ∨ (o.oangle y z).sign = 0 := by revert hs hs' generalize (o.oangle x y).sign = sxy generalize (o.oangle y z).sign = syz decide +revert have h0' : InnerProductGeometry.angle y z = 0 ∨ InnerProductGeometry.angle y z = π := by rcases h0 with h0 | h0 <;> simpa [*] using o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero h0 rcases h0' with h0' | h0' · rw [h0'] at he obtain ⟨-, r, hr0, rfl⟩ := InnerProductGeometry.angle_eq_zero_iff.1 h0' obtain ⟨-, r', hr'0, rfl⟩ := InnerProductGeometry.angle_eq_zero_iff.1 he simp_all · rw [h0'] at he obtain ⟨-, r, hr0, rfl⟩ := InnerProductGeometry.angle_eq_pi_iff.1 h0' obtain ⟨-, r', hr'0, rfl⟩ := InnerProductGeometry.angle_eq_pi_iff.1 he simp_all end Orientation
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle /-! # Oriented angles in right-angled triangles. This file proves basic geometric results about distances and oriented angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace Orientation open Module variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2)) /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)] /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle x (x + y)) = ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle (x + y) y) = ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle x (x + y)) = ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle (x + y) y) = ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two h /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle x (x + y)) = ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle (x + y) y) = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two h /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = Real.arccos (‖y‖ / ‖y - x‖) := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem oangle_sub_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = Real.arccos (‖x‖ / ‖x - y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two h /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = Real.arcsin (‖x‖ / ‖y - x‖) := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_sub_eq_arcsin_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem oangle_sub_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = Real.arcsin (‖y‖ / ‖x - y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two h /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = Real.arctan (‖x‖ / ‖y‖) := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_sub_eq_arctan_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (o.right_ne_zero_of_oangle_eq_pi_div_two h)] /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem oangle_sub_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = Real.arctan (‖y‖ / ‖x‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two h /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle y (y - x)) = ‖y‖ / ‖y - x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x - y) x) = ‖x‖ / ‖x - y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).cos_oangle_sub_right_of_oangle_eq_pi_div_two h /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle y (y - x)) = ‖x‖ / ‖y - x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x - y) x) = ‖y‖ / ‖x - y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).sin_oangle_sub_right_of_oangle_eq_pi_div_two h /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle y (y - x)) = ‖x‖ / ‖y‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x - y) x) = ‖y‖ / ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).tan_oangle_sub_right_of_oangle_eq_pi_div_two h /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ theorem cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle y (y - x)) * ‖y - x‖ = ‖y‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ theorem cos_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x - y) x) * ‖x - y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ theorem sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle y (y - x)) * ‖y - x‖ = ‖x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ theorem sin_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x - y) x) * ‖x - y‖ = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ theorem tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle y (y - x)) * ‖y‖ = ‖x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ theorem tan_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x - y) x) * ‖x‖ = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle y (y - x)) = ‖y - x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.norm_div_cos_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle (x - y) x) = ‖x - y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two h /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle y (y - x)) = ‖y - x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.norm_div_sin_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle (x - y) x) = ‖x - y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two h /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ theorem norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle y (y - x)) = ‖y‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.norm_div_tan_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ theorem norm_div_tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle (x - y) x) = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two h /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`. -/ theorem oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle x (x + r • o.rotation (π / 2 : ℝ) x) = Real.arctan r := by rcases lt_trichotomy r 0 with (hr | rfl | hr) · have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = -(π / 2 : ℝ) := by rw [o.oangle_smul_right_of_neg _ _ hr, o.oangle_neg_right h, o.oangle_rotation_self_right h, ← sub_eq_zero, add_comm, sub_neg_eq_add, ← Real.Angle.coe_add, ← Real.Angle.coe_add, add_assoc, add_halves, ← two_mul, Real.Angle.coe_two_pi] simpa using h rw [← neg_inj, ← oangle_neg_orientation_eq_neg, neg_neg] at ha rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, oangle_rev, (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul, LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one, Real.norm_eq_abs, abs_of_neg hr, Real.arctan_neg, Real.Angle.coe_neg, neg_neg] · rw [zero_smul, add_zero, oangle_self, Real.arctan_zero, Real.Angle.coe_zero] · have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = (π / 2 : ℝ) := by rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right h] rw [o.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul, LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one, Real.norm_eq_abs, abs_of_pos hr] /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`. -/ theorem oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x) = Real.arctan r⁻¹ := by by_cases hr : r = 0; · simp [hr] rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, ← neg_neg ((π / 2 : ℝ) : Real.Angle), ← rotation_neg_orientation_eq_neg, add_comm] have hx : x = r⁻¹ • (-o).rotation (π / 2 : ℝ) (r • (-o).rotation (-(π / 2 : ℝ)) x) := by simp [hr] nth_rw 3 [hx] refine (-o).oangle_add_right_smul_rotation_pi_div_two ?_ _ simp [hr, h] /-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a rotation of another by `π / 2`. -/ theorem tan_oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : Real.Angle.tan (o.oangle x (x + r • o.rotation (π / 2 : ℝ) x)) = r := by rw [o.oangle_add_right_smul_rotation_pi_div_two h, Real.Angle.tan_coe, Real.tan_arctan] /-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a rotation of another by `π / 2`. -/ theorem tan_oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : Real.Angle.tan (o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x)) = r⁻¹ := by rw [o.oangle_add_left_smul_rotation_pi_div_two h, Real.Angle.tan_coe, Real.tan_arctan] /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`, version subtracting vectors. -/ theorem oangle_sub_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x - x) = Real.arctan r⁻¹ := by by_cases hr : r = 0; · simp [hr] have hx : -x = r⁻¹ • o.rotation (π / 2 : ℝ) (r • o.rotation (π / 2 : ℝ) x) := by simp [hr, ← Real.Angle.coe_add] rw [sub_eq_add_neg, hx, o.oangle_add_right_smul_rotation_pi_div_two] simpa [hr] using h /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`, version subtracting vectors. -/ theorem oangle_sub_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (x - r • o.rotation (π / 2 : ℝ) x) x = Real.arctan r := by by_cases hr : r = 0; · simp [hr] have hx : x = r⁻¹ • o.rotation (π / 2 : ℝ) (-(r • o.rotation (π / 2 : ℝ) x)) := by simp [hr, ← Real.Angle.coe_add] rw [sub_eq_add_neg, add_comm] nth_rw 3 [hx] nth_rw 2 [hx] rw [o.oangle_add_left_smul_rotation_pi_div_two, inv_inv] simpa [hr] using h end Orientation namespace EuclideanGeometry open Module variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_right_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = Real.arccos (dist p₃ p₂ / dist p₁ p₃) := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arccos_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_left_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = Real.arccos (dist p₁ p₂ / dist p₁ p₃) := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arccos_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h), dist_comm p₁ p₃] /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_right_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = Real.arcsin (dist p₁ p₂ / dist p₁ p₃) := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inl (left_ne_of_oangle_eq_pi_div_two h))] /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_left_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = Real.arcsin (dist p₃ p₂ / dist p₁ p₃) := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inr (left_ne_of_oangle_eq_pi_div_two h)), dist_comm p₁ p₃] /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_right_eq_arctan_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = Real.arctan (dist p₁ p₂ / dist p₃ p₂) := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arctan_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (right_ne_of_oangle_eq_pi_div_two h)] /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_left_eq_arctan_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = Real.arctan (dist p₃ p₂ / dist p₁ p₂) := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arctan_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (left_ne_of_oangle_eq_pi_div_two h)] /-- An oriented angle in a right-angled triangle (even a degenerate one) has absolute value less than `π / 2`. The right-angled property is expressed using unoriented angles to cover either orientation of right-angled triangles and include degenerate cases. -/ lemma abs_oangle_toReal_lt_pi_div_two_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : |(∡ p₂ p₃ p₁).toReal| < π / 2 := by by_cases hp₂ : p₂ = p₃ · simp [hp₂, Real.pi_pos] by_cases hp₁ : p₁ = p₃ · simp [hp₁, Real.pi_pos] rw [← angle_eq_abs_oangle_toReal hp₂ hp₁] exact angle_lt_pi_div_two_of_angle_eq_pi_div_two h (Ne.symm hp₂) /-- Two oriented angles in right-angled triangles are equal if twice those angles are equal. -/ lemma oangle_eq_oangle_of_two_zsmul_eq_of_angle_eq_pi_div_two {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₂ p₃ p₁ = (2 : ℤ) • ∡ p₅ p₆ p₄) (h₁₂₃ : ∠ p₁ p₂ p₃ = π / 2) (h₄₅₆ : ∠ p₄ p₅ p₆ = π / 2) : ∡ p₂ p₃ p₁ = ∡ p₅ p₆ p₄ := by rwa [Real.Angle.two_zsmul_eq_iff_eq_of_abs_toReal_lt_pi_div_two (abs_oangle_toReal_lt_pi_div_two_of_angle_eq_pi_div_two h₁₂₃) (abs_oangle_toReal_lt_pi_div_two_of_angle_eq_pi_div_two h₄₅₆)] at h /-- Two oriented angles in oppositely-oriented right-angled triangles are equal if twice those angles are equal. -/ lemma oangle_eq_oangle_rev_of_two_zsmul_eq_of_angle_eq_pi_div_two {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₂ p₃ p₁ = (2 : ℤ) • ∡ p₄ p₆ p₅) (h₁₂₃ : ∠ p₁ p₂ p₃ = π / 2) (h₄₅₆ : ∠ p₄ p₅ p₆ = π / 2) : ∡ p₂ p₃ p₁ = ∡ p₄ p₆ p₅ := by refine (Real.Angle.two_zsmul_eq_iff_eq_of_abs_toReal_lt_pi_div_two (abs_oangle_toReal_lt_pi_div_two_of_angle_eq_pi_div_two h₁₂₃) ?_).1 h rw [oangle_rev] suffices |(∡ p₅ p₆ p₄).toReal| < π / 2 by convert this using 1 nth_rw 2 [← abs_neg] congr rw [Real.Angle.toReal_neg_eq_neg_toReal_iff] intro hc simp only [hc, Real.Angle.toReal_pi, abs_of_pos Real.pi_pos] at this linarith [Real.pi_pos] exact abs_oangle_toReal_lt_pi_div_two_of_angle_eq_pi_div_two h₄₅₆ /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₂ p₃ p₁) = dist p₃ p₂ / dist p₁ p₃ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, cos_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₃ p₁ p₂) = dist p₁ p₂ / dist p₁ p₃ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.cos_coe, cos_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h), dist_comm p₁ p₃] /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₂ p₃ p₁) = dist p₁ p₂ / dist p₁ p₃ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, sin_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inl (left_ne_of_oangle_eq_pi_div_two h))] /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₃ p₁ p₂) = dist p₃ p₂ / dist p₁ p₃ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.sin_coe, sin_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inr (left_ne_of_oangle_eq_pi_div_two h)), dist_comm p₁ p₃] /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.tan (∡ p₂ p₃ p₁) = dist p₁ p₂ / dist p₃ p₂ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, tan_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.tan (∡ p₃ p₁ p₂) = dist p₃ p₂ / dist p₁ p₂ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.tan_coe, tan_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)] /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₂ p₃ p₁) * dist p₁ p₃ = dist p₃ p₂ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, cos_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₃ p₁ p₂) * dist p₁ p₃ = dist p₁ p₂ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.cos_coe, dist_comm p₁ p₃, cos_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)] /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₂ p₃ p₁) * dist p₁ p₃ = dist p₁ p₂ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, sin_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₃ p₁ p₂) * dist p₁ p₃ = dist p₃ p₂ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.sin_coe, dist_comm p₁ p₃, sin_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)] /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.tan (∡ p₂ p₃ p₁) * dist p₃ p₂ = dist p₁ p₂ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, tan_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inr (right_ne_of_oangle_eq_pi_div_two h))] /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.tan (∡ p₃ p₁ p₂) * dist p₁ p₂ = dist p₃ p₂ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.tan_coe, tan_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inr (left_ne_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem dist_div_cos_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₃ p₂ / Real.Angle.cos (∡ p₂ p₃ p₁) = dist p₁ p₃ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, dist_div_cos_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inr (right_ne_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem dist_div_cos_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₁ p₂ / Real.Angle.cos (∡ p₃ p₁ p₂) = dist p₁ p₃ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.cos_coe, dist_comm p₁ p₃, dist_div_cos_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inr (left_ne_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem dist_div_sin_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₁ p₂ / Real.Angle.sin (∡ p₂ p₃ p₁) = dist p₁ p₃ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, dist_div_sin_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inl (left_ne_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem dist_div_sin_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₃ p₂ / Real.Angle.sin (∡ p₃ p₁ p₂) = dist p₁ p₃ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.sin_coe, dist_comm p₁ p₃, dist_div_sin_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inl (right_ne_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem dist_div_tan_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₁ p₂ / Real.Angle.tan (∡ p₂ p₃ p₁) = dist p₃ p₂ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, dist_div_tan_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inl (left_ne_of_oangle_eq_pi_div_two h))] /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem dist_div_tan_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₃ p₂ / Real.Angle.tan (∡ p₃ p₁ p₂) = dist p₁ p₂ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.tan_coe, dist_div_tan_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inl (right_ne_of_oangle_eq_pi_div_two h))] end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Oriented/Projection.lean
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.Projection /-! # Oriented angles and orthogonal projection. This file proves lemmas relating to oriented angles involving orthogonal projections. -/ namespace EuclideanGeometry open Module open scoped Real variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] lemma oangle_self_orthogonalProjection (p : P) {p' : P} {s : AffineSubspace ℝ P} [s.direction.HasOrthogonalProjection] (hp : p ∉ s) (h : p' ∈ s) (hp' : haveI : Nonempty s := ⟨p', h⟩; p' ≠ orthogonalProjection s p) : haveI : Nonempty s := ⟨p', h⟩ ∡ p (orthogonalProjection s p) p' = (π / 2 : ℝ) ∨ ∡ p (orthogonalProjection s p) p' = (-π / 2 : ℝ) := by haveI : Nonempty s := ⟨p', h⟩ have hpne : p ≠ orthogonalProjection s p := Ne.symm (orthogonalProjection_eq_self_iff.not.2 hp) have ha := oangle_eq_angle_or_eq_neg_angle hpne hp' rw [angle_self_orthogonalProjection p h] at ha rwa [neg_div] lemma oangle_orthogonalProjection_self (p : P) {p' : P} {s : AffineSubspace ℝ P} [s.direction.HasOrthogonalProjection] (hp : p ∉ s) (h : p' ∈ s) (hp' : haveI : Nonempty s := ⟨p', h⟩; p' ≠ orthogonalProjection s p) : haveI : Nonempty s := ⟨p', h⟩ ∡ p' (orthogonalProjection s p) p = (π / 2 : ℝ) ∨ ∡ p' (orthogonalProjection s p) p = (-π / 2 : ℝ) := by rw [oangle_rev, neg_eq_iff_eq_neg, neg_eq_iff_eq_neg, or_comm, ← Real.Angle.coe_neg, neg_div, neg_neg, ← Real.Angle.coe_neg, ← neg_div] exact oangle_self_orthogonalProjection p hp h hp' lemma two_zsmul_oangle_self_orthogonalProjection (p : P) {p' : P} {s : AffineSubspace ℝ P} [s.direction.HasOrthogonalProjection] (hp : p ∉ s) (h : p' ∈ s) (hp' : haveI : Nonempty s := ⟨p', h⟩; p' ≠ orthogonalProjection s p) : haveI : Nonempty s := ⟨p', h⟩ (2 : ℤ) • ∡ p (orthogonalProjection s p) p' = π := by rw [Real.Angle.two_zsmul_eq_pi_iff] exact oangle_self_orthogonalProjection p hp h hp' lemma two_zsmul_oangle_orthogonalProjection_self (p : P) {p' : P} {s : AffineSubspace ℝ P} [s.direction.HasOrthogonalProjection] (hp : p ∉ s) (h : p' ∈ s) (hp' : haveI : Nonempty s := ⟨p', h⟩; p' ≠ orthogonalProjection s p) : haveI : Nonempty s := ⟨p', h⟩ (2 : ℤ) • ∡ p' (orthogonalProjection s p) p = π := by rw [Real.Angle.two_zsmul_eq_pi_iff] exact oangle_orthogonalProjection_self p hp h hp' end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean
import Mathlib.Analysis.Convex.Side import Mathlib.Geometry.Euclidean.Angle.Oriented.Rotation import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine /-! # Oriented angles. This file defines oriented angles in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.oangle`, with notation `∡`, is the oriented angle determined by three points. -/ noncomputable section open Module Complex open scoped Affine EuclideanGeometry Real RealInnerProductSpace ComplexConjugate namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] /-- A fixed choice of positive orientation of Euclidean space `ℝ²` -/ abbrev o := @Module.Oriented.positiveOrientation /-- The oriented angle at `p₂` between the line segments to `p₁` and `p₃`, modulo `2 * π`. If either of those points equals `p₂`, this is 0. See `EuclideanGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (p₁ p₂ p₃ : P) : Real.Angle := o.oangle (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) @[inherit_doc] scoped notation "∡" => EuclideanGeometry.oangle /-- Oriented angles are continuous when neither end point equals the middle point. -/ theorem continuousAt_oangle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) : ContinuousAt (fun y : P × P × P => ∡ y.1 y.2.1 y.2.2) x := by unfold oangle fun_prop (disch := simp [*]) /-- The angle ∡AAB at a point. -/ @[simp] theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle] /-- The angle ∡ABB at a point. -/ @[simp] theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle] /-- The angle ∡ABA at a point. -/ @[simp] theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 := o.oangle_self _ /-- If the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.left_ne_zero_of_oangle_ne_zero h /-- If the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₃ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.right_ne_zero_of_oangle_ne_zero h /-- If the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₃ := by rw [← (vsub_left_injective p₂).ne_iff]; exact o.ne_of_oangle_ne_zero h /-- If the angle between three points is `π`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the sign of the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is positive, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is positive, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is positive, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- Reversing the order of the points passed to `oangle` negates the angle. -/ theorem oangle_rev (p₁ p₂ p₃ : P) : ∡ p₃ p₂ p₁ = -∡ p₁ p₂ p₃ := o.oangle_rev _ _ /-- Adding an angle to that with the order of the points reversed results in 0. -/ @[simp] theorem oangle_add_oangle_rev (p₁ p₂ p₃ : P) : ∡ p₁ p₂ p₃ + ∡ p₃ p₂ p₁ = 0 := o.oangle_add_oangle_rev _ _ /-- An oriented angle is zero if and only if the angle with the order of the points reversed is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ ∡ p₃ p₂ p₁ = 0 := o.oangle_eq_zero_iff_oangle_rev_eq_zero /-- An oriented angle is `π` if and only if the angle with the order of the points reversed is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∡ p₃ p₂ p₁ = π := o.oangle_eq_pi_iff_oangle_rev_eq_pi /-- A homothety with a nonzero scale factor preserves angles. -/ @[simp] lemma oangle_homothety (p p₁ p₂ p₃ : P) {r : ℝ} (h : r ≠ 0) : ∡ (AffineMap.homothety p r p₁) (AffineMap.homothety p r p₂) (AffineMap.homothety p r p₃) = ∡ p₁ p₂ p₃ := by simp_rw [oangle, ← AffineMap.linearMap_vsub, AffineMap.homothety_linear, LinearMap.smul_apply, LinearMap.id_coe, id_eq] rcases h.lt_or_gt with hlt | hlt <;> simp [hlt, -neg_vsub_eq_vsub_rev] /-- An oriented angle is not zero or `π` if and only if the three points are affinely independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_affineIndependent {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ ≠ 0 ∧ ∡ p₁ p₂ p₃ ≠ π ↔ AffineIndependent ℝ ![p₁, p₂, p₃] := by rw [oangle, o.oangle_ne_zero_and_ne_pi_iff_linearIndependent, affineIndependent_iff_linearIndependent_vsub ℝ _ (1 : Fin 3), ← linearIndependent_equiv (finSuccAboveEquiv (1 : Fin 3))] convert Iff.rfl ext i fin_cases i <;> rfl /-- An oriented angle is zero or `π` if and only if the three points are collinear. -/ theorem oangle_eq_zero_or_eq_pi_iff_collinear {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ∨ ∡ p₁ p₂ p₃ = π ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [← not_iff_not, not_or, oangle_ne_zero_and_ne_pi_iff_affineIndependent, affineIndependent_iff_not_collinear_set] /-- An oriented angle has a sign zero if and only if the three points are collinear. -/ theorem oangle_sign_eq_zero_iff_collinear {p₁ p₂ p₃ : P} : (∡ p₁ p₂ p₃).sign = 0 ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [Real.Angle.sign_eq_zero_iff, oangle_eq_zero_or_eq_pi_iff_collinear] /-- If twice the oriented angles between two triples of points are equal, one triple is affinely independent if and only if the other is. -/ theorem affineIndependent_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) : AffineIndependent ℝ ![p₁, p₂, p₃] ↔ AffineIndependent ℝ ![p₄, p₅, p₆] := by simp_rw [← oangle_ne_zero_and_ne_pi_iff_affineIndependent, ← Real.Angle.two_zsmul_ne_zero_iff, h] /-- If twice the oriented angles between two triples of points are equal, one triple is collinear if and only if the other is. -/ theorem collinear_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) : Collinear ℝ ({p₁, p₂, p₃} : Set P) ↔ Collinear ℝ ({p₄, p₅, p₆} : Set P) := by simp_rw [← oangle_eq_zero_or_eq_pi_iff_collinear, ← Real.Angle.two_zsmul_eq_zero_iff, h] /-- If corresponding pairs of points in two angles have the same vector span, twice those angles are equal. -/ theorem two_zsmul_oangle_of_vectorSpan_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h₁₂₄₅ : vectorSpan ℝ ({p₁, p₂} : Set P) = vectorSpan ℝ ({p₄, p₅} : Set P)) (h₃₂₆₅ : vectorSpan ℝ ({p₃, p₂} : Set P) = vectorSpan ℝ ({p₆, p₅} : Set P)) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by simp_rw [vectorSpan_pair] at h₁₂₄₅ h₃₂₆₅ exact o.two_zsmul_oangle_of_span_eq_of_span_eq h₁₂₄₅ h₃₂₆₅ /-- If the lines determined by corresponding pairs of points in two angles are parallel, twice those angles are equal. -/ theorem two_zsmul_oangle_of_parallel {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h₁₂₄₅ : line[ℝ, p₁, p₂] ∥ line[ℝ, p₄, p₅]) (h₃₂₆₅ : line[ℝ, p₃, p₂] ∥ line[ℝ, p₆, p₅]) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by rw [AffineSubspace.affineSpan_pair_parallel_iff_vectorSpan_eq] at h₁₂₄₅ h₃₂₆₅ exact two_zsmul_oangle_of_vectorSpan_eq h₁₂₄₅ h₃₂₆₅ /-- Given three points not equal to `p`, the angle between the first and the second at `p` plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₂ + ∡ p₂ p p₃ = ∡ p₁ p p₃ := o.oangle_add (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the second and the third at `p` plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₂ p p₃ + ∡ p₁ p p₂ = ∡ p₁ p p₃ := o.oangle_add_swap (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the first and the third at `p` minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₃ - ∡ p₁ p p₂ = ∡ p₂ p p₃ := o.oangle_sub_left (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the first and the third at `p` minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₃ - ∡ p₂ p p₃ = ∡ p₁ p p₂ := o.oangle_sub_right (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, adding the angles between them at `p` in cyclic order results in 0. -/ theorem oangle_add_cyc3 {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₂ + ∡ p₂ p p₃ + ∡ p₃ p p₁ = 0 := by simp [*] /-- Pons asinorum, oriented angle-at-point form. -/ theorem oangle_eq_oangle_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₁ p₂ p₃ = ∡ p₂ p₃ p₁ := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁, ← vsub_sub_vsub_cancel_left p₂ p₃ p₁, o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented angle-at-point form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq {p₁ p₂ p₃ : P} (hn : p₂ ≠ p₃) (h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₃ p₁ p₂ = π - (2 : ℤ) • ∡ p₁ p₂ p₃ := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, oangle] convert o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq _ h using 1 · rw [← neg_vsub_eq_vsub_rev p₁ p₃, ← neg_vsub_eq_vsub_rev p₁ p₂, o.oangle_neg_neg] · rw [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]; simp · simpa using hn /-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/ theorem abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : |(∡ p₁ p₂ p₃).toReal| < π / 2 := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁] exact o.abs_oangle_sub_right_toReal_lt_pi_div_two h /-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/ theorem abs_oangle_left_toReal_lt_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : |(∡ p₂ p₃ p₁).toReal| < π / 2 := oangle_eq_oangle_of_dist_eq h ▸ abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq h /-- The cosine of the oriented angle at `p` between two points not equal to `p` equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : Real.Angle.cos (∡ p₁ p p₂) = Real.cos (∠ p₁ p p₂) := o.cos_oangle_eq_cos_angle (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The oriented angle at `p` between two points not equal to `p` is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∡ p₁ p p₂ = ∠ p₁ p p₂ ∨ ∡ p₁ p p₂ = -∠ p₁ p p₂ := o.oangle_eq_angle_or_eq_neg_angle (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The unoriented angle at `p` between two points not equal to `p` is the absolute value of the oriented angle. -/ theorem angle_eq_abs_oangle_toReal {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∠ p₁ p p₂ = |(∡ p₁ p p₂).toReal| := o.angle_eq_abs_oangle_toReal (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- If the sign of the oriented angle at `p` between two points is zero, either one of the points equals `p` or the unoriented angle is 0 or π. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {p p₁ p₂ : P} (h : (∡ p₁ p p₂).sign = 0) : p₁ = p ∨ p₂ = p ∨ ∠ p₁ p p₂ = 0 ∨ ∠ p₁ p p₂ = π := by convert o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero h <;> simp /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆) (hs : (∡ p₁ p₂ p₃).sign = (∡ p₄ p₅ p₆).sign) : ∡ p₁ p₂ p₃ = ∡ p₄ p₅ p₆ := o.oangle_eq_of_angle_eq_of_sign_eq h hs /-- If the signs of two nondegenerate oriented angles between points are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/ theorem angle_eq_iff_oangle_eq_of_sign_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (hp₁ : p₁ ≠ p₂) (hp₃ : p₃ ≠ p₂) (hp₄ : p₄ ≠ p₅) (hp₆ : p₆ ≠ p₅) (hs : (∡ p₁ p₂ p₃).sign = (∡ p₄ p₅ p₆).sign) : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆ ↔ ∡ p₁ p₂ p₃ = ∡ p₄ p₅ p₆ := o.angle_eq_iff_oangle_eq_of_sign_eq (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₃) (vsub_ne_zero.2 hp₄) (vsub_ne_zero.2 hp₆) hs /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are negations of each other, then the oriented angles are negations of each other (even in degenerate cases). -/ lemma oangle_eq_neg_of_angle_eq_of_sign_eq_neg {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆) (hs : (∡ p₁ p₂ p₃).sign = -(∡ p₄ p₅ p₆).sign) : ∡ p₁ p₂ p₃ = -∡ p₄ p₅ p₆ := o.oangle_eq_neg_of_angle_eq_of_sign_eq_neg h hs /-- If the signs of two nondegenerate oriented angles between points are negations of each other, the oriented angles are negations of each other if and only if the unoriented angles are equal. -/ lemma angle_eq_iff_oangle_eq_neg_of_sign_eq_neg {p₁ p₂ p₃ p₄ p₅ p₆ : P} (hp₁ : p₁ ≠ p₂) (hp₃ : p₃ ≠ p₂) (hp₄ : p₄ ≠ p₅) (hp₆ : p₆ ≠ p₅) (hs : (∡ p₁ p₂ p₃).sign = -(∡ p₄ p₅ p₆).sign) : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆ ↔ ∡ p₁ p₂ p₃ = -∡ p₄ p₅ p₆ := o.angle_eq_iff_oangle_eq_neg_of_sign_eq_neg (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₃) (vsub_ne_zero.2 hp₄) (vsub_ne_zero.2 hp₆) hs /-- The oriented angle between three points equals the unoriented angle if the sign is positive. -/ theorem oangle_eq_angle_of_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : ∡ p₁ p₂ p₃ = ∠ p₁ p₂ p₃ := o.oangle_eq_angle_of_sign_eq_one h /-- The oriented angle between three points equals minus the unoriented angle if the sign is negative. -/ theorem oangle_eq_neg_angle_of_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : ∡ p₁ p₂ p₃ = -∠ p₁ p₂ p₃ := o.oangle_eq_neg_angle_of_sign_eq_neg_one h /-- The unoriented angle at `p` between two points not equal to `p` is zero if and only if the unoriented angle is zero. -/ theorem oangle_eq_zero_iff_angle_eq_zero {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∡ p₁ p p₂ = 0 ↔ ∠ p₁ p p₂ = 0 := o.oangle_eq_zero_iff_angle_eq_zero (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The oriented angle between three points is `π` if and only if the unoriented angle is `π`. -/ theorem oangle_eq_pi_iff_angle_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∠ p₁ p₂ p₃ = π := o.oangle_eq_pi_iff_angle_eq_pi /-- If the oriented angle between three points is `π / 2`, so is the unoriented angle. -/ theorem angle_eq_pi_div_two_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∠ p₁ p₂ p₃ = π / 2 := by rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two] exact o.inner_eq_zero_of_oangle_eq_pi_div_two h /-- If the oriented angle between three points is `π / 2`, so is the unoriented angle (reversed). -/ theorem angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∠ p₃ p₂ p₁ = π / 2 := by rw [angle_comm] exact angle_eq_pi_div_two_of_oangle_eq_pi_div_two h /-- If the oriented angle between three points is `-π / 2`, the unoriented angle is `π / 2`. -/ theorem angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(-π / 2)) : ∠ p₁ p₂ p₃ = π / 2 := by rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two] exact o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h /-- If the oriented angle between three points is `-π / 2`, the unoriented angle (reversed) is `π / 2`. -/ theorem angle_rev_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(-π / 2)) : ∠ p₃ p₂ p₁ = π / 2 := by rw [angle_comm] exact angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two h /-- Swapping the first and second points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₁₂_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₂ p₁ p₃).sign := by rw [eq_comm, oangle, oangle, ← o.oangle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, ← vsub_sub_vsub_cancel_left p₁ p₃ p₂, ← neg_vsub_eq_vsub_rev p₃ p₂, sub_eq_add_neg, neg_vsub_eq_vsub_rev p₂ p₁, add_comm, ← @neg_one_smul ℝ] nth_rw 2 [← one_smul ℝ (p₁ -ᵥ p₂)] rw [o.oangle_sign_smul_add_smul_right] simp /-- Swapping the first and third points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₁₃_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₃ p₂ p₁).sign := by rw [oangle_rev, Real.Angle.sign_neg, neg_neg] /-- Swapping the second and third points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₂₃_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₁ p₃ p₂).sign := by rw [oangle_swap₁₃_sign, ← oangle_swap₁₂_sign, oangle_swap₁₃_sign] /-- Rotating the points in an oriented angle does not change the sign of that angle. -/ theorem oangle_rotate_sign (p₁ p₂ p₃ : P) : (∡ p₂ p₃ p₁).sign = (∡ p₁ p₂ p₃).sign := by rw [← oangle_swap₁₂_sign, oangle_swap₁₃_sign] /-- The oriented angle between three points is π if and only if the second point is strictly between the other two. -/ theorem oangle_eq_pi_iff_sbtw {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ Sbtw ℝ p₁ p₂ p₃ := by rw [oangle_eq_pi_iff_angle_eq_pi, angle_eq_pi_iff_sbtw] /-- If the second of three points is strictly between the other two, the oriented angle at that point is π. -/ theorem _root_.Sbtw.oangle₁₂₃_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₂ p₃ = π := oangle_eq_pi_iff_sbtw.2 h /-- If the second of three points is strictly between the other two, the oriented angle at that point (reversed) is π. -/ theorem _root_.Sbtw.oangle₃₂₁_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₂ p₁ = π := by rw [oangle_eq_pi_iff_oangle_rev_eq_pi, ← h.oangle₁₂₃_eq_pi] /-- If the second of three points is weakly between the other two, the oriented angle at the first point is zero. -/ theorem _root_.Wbtw.oangle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₁ p₃ = 0 := by by_cases hp₂p₁ : p₂ = p₁; · simp [hp₂p₁] by_cases hp₃p₁ : p₃ = p₁; · simp [hp₃p₁] rw [oangle_eq_zero_iff_angle_eq_zero hp₂p₁ hp₃p₁] exact h.angle₂₁₃_eq_zero_of_ne hp₂p₁ /-- If the second of three points is strictly between the other two, the oriented angle at the first point is zero. -/ theorem _root_.Sbtw.oangle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₁ p₃ = 0 := h.wbtw.oangle₂₁₃_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the first point (reversed) is zero. -/ theorem _root_.Wbtw.oangle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₁ p₂ = 0 := by rw [oangle_eq_zero_iff_oangle_rev_eq_zero, h.oangle₂₁₃_eq_zero] /-- If the second of three points is strictly between the other two, the oriented angle at the first point (reversed) is zero. -/ theorem _root_.Sbtw.oangle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₁ p₂ = 0 := h.wbtw.oangle₃₁₂_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the third point is zero. -/ theorem _root_.Wbtw.oangle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₃ p₁ = 0 := h.symm.oangle₂₁₃_eq_zero /-- If the second of three points is strictly between the other two, the oriented angle at the third point is zero. -/ theorem _root_.Sbtw.oangle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₃ p₁ = 0 := h.wbtw.oangle₂₃₁_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the third point (reversed) is zero. -/ theorem _root_.Wbtw.oangle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₃ p₂ = 0 := h.symm.oangle₃₁₂_eq_zero /-- If the second of three points is strictly between the other two, the oriented angle at the third point (reversed) is zero. -/ theorem _root_.Sbtw.oangle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₃ p₂ = 0 := h.wbtw.oangle₁₃₂_eq_zero /-- The oriented angle between three points is zero if and only if one of the first and third points is weakly between the other two. -/ theorem oangle_eq_zero_iff_wbtw {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ Wbtw ℝ p₂ p₁ p₃ ∨ Wbtw ℝ p₂ p₃ p₁ := by by_cases hp₁p₂ : p₁ = p₂; · simp [hp₁p₂] by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂] rw [oangle_eq_zero_iff_angle_eq_zero hp₁p₂ hp₃p₂, angle_eq_zero_iff_ne_and_wbtw] simp [hp₁p₂, hp₃p₂] /-- An oriented angle is unchanged by replacing the first point by one weakly further away on the same ray. -/ theorem _root_.Wbtw.oangle_eq_left {p₁ p₁' p₂ p₃ : P} (h : Wbtw ℝ p₂ p₁ p₁') (hp₁p₂ : p₁ ≠ p₂) : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ := by by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂] by_cases hp₁'p₂ : p₁' = p₂; · rw [hp₁'p₂, wbtw_self_iff] at h; exact False.elim (hp₁p₂ h) rw [← oangle_add hp₁'p₂ hp₁p₂ hp₃p₂, h.oangle₃₁₂_eq_zero, zero_add] /-- An oriented angle is unchanged by replacing the first point by one strictly further away on the same ray. -/ theorem _root_.Sbtw.oangle_eq_left {p₁ p₁' p₂ p₃ : P} (h : Sbtw ℝ p₂ p₁ p₁') : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ := h.wbtw.oangle_eq_left h.ne_left /-- An oriented angle is unchanged by replacing the third point by one weakly further away on the same ray. -/ theorem _root_.Wbtw.oangle_eq_right {p₁ p₂ p₃ p₃' : P} (h : Wbtw ℝ p₂ p₃ p₃') (hp₃p₂ : p₃ ≠ p₂) : ∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' := by rw [oangle_rev, h.oangle_eq_left hp₃p₂, ← oangle_rev] /-- An oriented angle is unchanged by replacing the third point by one strictly further away on the same ray. -/ theorem _root_.Sbtw.oangle_eq_right {p₁ p₂ p₃ p₃' : P} (h : Sbtw ℝ p₂ p₃ p₃') : ∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' := h.wbtw.oangle_eq_right h.ne_left /-- An oriented angle is unchanged by replacing the first point with the midpoint of the segment between it and the second point. -/ @[simp] theorem oangle_midpoint_left (p₁ p₂ p₃ : P) : ∡ (midpoint ℝ p₁ p₂) p₂ p₃ = ∡ p₁ p₂ p₃ := by by_cases h : p₁ = p₂; · simp [h] exact (sbtw_midpoint_of_ne ℝ h).symm.oangle_eq_left /-- An oriented angle is unchanged by replacing the first point with the midpoint of the segment between the second point and that point. -/ @[simp] theorem oangle_midpoint_rev_left (p₁ p₂ p₃ : P) : ∡ (midpoint ℝ p₂ p₁) p₂ p₃ = ∡ p₁ p₂ p₃ := by rw [midpoint_comm, oangle_midpoint_left] /-- An oriented angle is unchanged by replacing the third point with the midpoint of the segment between it and the second point. -/ @[simp] theorem oangle_midpoint_right (p₁ p₂ p₃ : P) : ∡ p₁ p₂ (midpoint ℝ p₃ p₂) = ∡ p₁ p₂ p₃ := by by_cases h : p₃ = p₂; · simp [h] exact (sbtw_midpoint_of_ne ℝ h).symm.oangle_eq_right /-- An oriented angle is unchanged by replacing the third point with the midpoint of the segment between the second point and that point. -/ @[simp] theorem oangle_midpoint_rev_right (p₁ p₂ p₃ : P) : ∡ p₁ p₂ (midpoint ℝ p₂ p₃) = ∡ p₁ p₂ p₃ := by rw [midpoint_comm, oangle_midpoint_right] /-- Replacing the first point by one on the same line but the opposite ray adds π to the oriented angle. -/ theorem _root_.Sbtw.oangle_eq_add_pi_left {p₁ p₁' p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₁') (hp₃p₂ : p₃ ≠ p₂) : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ + π := by rw [← h.oangle₁₂₃_eq_pi, oangle_add_swap h.left_ne h.right_ne hp₃p₂] /-- Replacing the third point by one on the same line but the opposite ray adds π to the oriented angle. -/ theorem _root_.Sbtw.oangle_eq_add_pi_right {p₁ p₂ p₃ p₃' : P} (h : Sbtw ℝ p₃ p₂ p₃') (hp₁p₂ : p₁ ≠ p₂) : ∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' + π := by rw [← h.oangle₃₂₁_eq_pi, oangle_add hp₁p₂ h.right_ne h.left_ne] /-- Replacing both the first and third points by ones on the same lines but the opposite rays does not change the oriented angle (vertically opposite angles). -/ theorem _root_.Sbtw.oangle_eq_left_right {p₁ p₁' p₂ p₃ p₃' : P} (h₁ : Sbtw ℝ p₁ p₂ p₁') (h₃ : Sbtw ℝ p₃ p₂ p₃') : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃' := by rw [h₁.oangle_eq_add_pi_left h₃.left_ne, h₃.oangle_eq_add_pi_right h₁.right_ne, add_assoc, Real.Angle.coe_pi_add_coe_pi, add_zero] /-- Replacing the first point by one on the same line does not change twice the oriented angle. -/ theorem _root_.Collinear.two_zsmul_oangle_eq_left {p₁ p₁' p₂ p₃ : P} (h : Collinear ℝ ({p₁, p₂, p₁'} : Set P)) (hp₁p₂ : p₁ ≠ p₂) (hp₁'p₂ : p₁' ≠ p₂) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₁' p₂ p₃ := by by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂] rcases h.wbtw_or_wbtw_or_wbtw with (hw | hw | hw) · have hw' : Sbtw ℝ p₁ p₂ p₁' := ⟨hw, hp₁p₂.symm, hp₁'p₂.symm⟩ rw [hw'.oangle_eq_add_pi_left hp₃p₂, smul_add, Real.Angle.two_zsmul_coe_pi, add_zero] · rw [hw.oangle_eq_left hp₁'p₂] · rw [hw.symm.oangle_eq_left hp₁p₂] /-- Replacing the third point by one on the same line does not change twice the oriented angle. -/ theorem _root_.Collinear.two_zsmul_oangle_eq_right {p₁ p₂ p₃ p₃' : P} (h : Collinear ℝ ({p₃, p₂, p₃'} : Set P)) (hp₃p₂ : p₃ ≠ p₂) (hp₃'p₂ : p₃' ≠ p₂) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₁ p₂ p₃' := by rw [oangle_rev, smul_neg, h.two_zsmul_oangle_eq_left hp₃p₂ hp₃'p₂, ← smul_neg, ← oangle_rev] /-- Two different points are equidistant from a third point if and only if that third point equals some multiple of a `π / 2` rotation of the vector between those points, plus the midpoint of those points. -/ theorem dist_eq_iff_eq_smul_rotation_pi_div_two_vadd_midpoint {p₁ p₂ p : P} (h : p₁ ≠ p₂) : dist p₁ p = dist p₂ p ↔ ∃ r : ℝ, r • o.rotation (π / 2 : ℝ) (p₂ -ᵥ p₁) +ᵥ midpoint ℝ p₁ p₂ = p := by refine ⟨fun hd => ?_, fun hr => ?_⟩ · have hi : ⟪p₂ -ᵥ p₁, p -ᵥ midpoint ℝ p₁ p₂⟫ = 0 := by rw [@dist_eq_norm_vsub' V, @dist_eq_norm_vsub' V, ← mul_self_inj (norm_nonneg _) (norm_nonneg _), ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm] at hd simp_rw [vsub_midpoint, ← vsub_sub_vsub_cancel_left p₂ p₁ p, inner_sub_left, inner_add_right, inner_smul_right, hd, real_inner_comm (p -ᵥ p₁)] abel rw [@Orientation.inner_eq_zero_iff_eq_zero_or_eq_smul_rotation_pi_div_two V _ _ _ o, or_iff_right (vsub_ne_zero.2 h.symm)] at hi rcases hi with ⟨r, hr⟩ rw [eq_comm, ← eq_vadd_iff_vsub_eq] at hr exact ⟨r, hr.symm⟩ · rcases hr with ⟨r, rfl⟩ simp_rw [@dist_eq_norm_vsub V, vsub_vadd_eq_vsub_sub, left_vsub_midpoint, right_vsub_midpoint, invOf_eq_inv, ← neg_vsub_eq_vsub_rev p₂ p₁, ← mul_self_inj (norm_nonneg _) (norm_nonneg _), ← real_inner_self_eq_norm_mul_norm, inner_sub_sub_self] simp [-neg_vsub_eq_vsub_rev] open AffineSubspace /-- Given two pairs of distinct points on the same line, such that the vectors between those pairs of points are on the same ray (oriented in the same direction on that line), and a fifth point, the angles at the fifth point between each of those two pairs of points have the same sign. -/ theorem _root_.Collinear.oangle_sign_of_sameRay_vsub {p₁ p₂ p₃ p₄ : P} (p₅ : P) (hp₁p₂ : p₁ ≠ p₂) (hp₃p₄ : p₃ ≠ p₄) (hc : Collinear ℝ ({p₁, p₂, p₃, p₄} : Set P)) (hr : SameRay ℝ (p₂ -ᵥ p₁) (p₄ -ᵥ p₃)) : (∡ p₁ p₅ p₂).sign = (∡ p₃ p₅ p₄).sign := by by_cases hc₅₁₂ : Collinear ℝ ({p₅, p₁, p₂} : Set P) · have hc₅₁₂₃₄ : Collinear ℝ ({p₅, p₁, p₂, p₃, p₄} : Set P) := (hc.collinear_insert_iff_of_ne (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_insert _ _)) hp₁p₂).2 hc₅₁₂ have hc₅₃₄ : Collinear ℝ ({p₅, p₃, p₄} : Set P) := (hc.collinear_insert_iff_of_ne (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert _ _))) (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)))) hp₃p₄).1 hc₅₁₂₃₄ rw [Set.insert_comm] at hc₅₁₂ hc₅₃₄ have hs₁₅₂ := oangle_eq_zero_or_eq_pi_iff_collinear.2 hc₅₁₂ have hs₃₅₄ := oangle_eq_zero_or_eq_pi_iff_collinear.2 hc₅₃₄ rw [← Real.Angle.sign_eq_zero_iff] at hs₁₅₂ hs₃₅₄ rw [hs₁₅₂, hs₃₅₄] · let s : Set (P × P × P) := (fun x : line[ℝ, p₁, p₂] × V => (x.1, p₅, x.2 +ᵥ (x.1 : P))) '' Set.univ ×ˢ {v | SameRay ℝ (p₂ -ᵥ p₁) v ∧ v ≠ 0} have hco : IsConnected s := haveI : ConnectedSpace line[ℝ, p₁, p₂] := AddTorsor.connectedSpace _ _ (isConnected_univ.prod (isConnected_setOf_sameRay_and_ne_zero (vsub_ne_zero.2 hp₁p₂.symm))).image _ (by fun_prop) have hf : ContinuousOn (fun p : P × P × P => ∡ p.1 p.2.1 p.2.2) s := by refine continuousOn_of_forall_continuousAt fun p hp => continuousAt_oangle ?_ ?_ all_goals simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_univ, true_and, Prod.ext_iff] at hp obtain ⟨q₁, q₅, q₂⟩ := p dsimp only at hp ⊢ obtain ⟨⟨⟨q, hq⟩, v⟩, hv, rfl, rfl, rfl⟩ := hp dsimp only [Subtype.coe_mk, Set.mem_setOf] at hv ⊢ obtain ⟨hvr, -⟩ := hv rintro rfl refine hc₅₁₂ ((collinear_insert_iff_of_mem_affineSpan ?_).2 (collinear_pair _ _ _)) · exact hq · refine vadd_mem_of_mem_direction ?_ hq rw [← exists_nonneg_left_iff_sameRay (vsub_ne_zero.2 hp₁p₂.symm)] at hvr obtain ⟨r, -, rfl⟩ := hvr rw [direction_affineSpan] exact smul_vsub_rev_mem_vectorSpan_pair _ _ _ have hsp : ∀ p : P × P × P, p ∈ s → ∡ p.1 p.2.1 p.2.2 ≠ 0 ∧ ∡ p.1 p.2.1 p.2.2 ≠ π := by intro p hp simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and, Prod.ext_iff] at hp obtain ⟨q₁, q₅, q₂⟩ := p dsimp only at hp ⊢ obtain ⟨⟨⟨q, hq⟩, v⟩, hv, rfl, rfl, rfl⟩ := hp dsimp only [Subtype.coe_mk, Set.mem_setOf] at hv ⊢ obtain ⟨hvr, hv0⟩ := hv rw [← exists_nonneg_left_iff_sameRay (vsub_ne_zero.2 hp₁p₂.symm)] at hvr obtain ⟨r, -, rfl⟩ := hvr change q ∈ line[ℝ, p₁, p₂] at hq rw [oangle_ne_zero_and_ne_pi_iff_affineIndependent] refine affineIndependent_of_ne_of_mem_of_notMem_of_mem ?_ hq (fun h => hc₅₁₂ ((collinear_insert_iff_of_mem_affineSpan h).2 (collinear_pair _ _ _))) ?_ · rwa [← @vsub_ne_zero V, vsub_vadd_eq_vsub_sub, vsub_self, zero_sub, neg_ne_zero] · refine vadd_mem_of_mem_direction ?_ hq rw [direction_affineSpan] exact smul_vsub_rev_mem_vectorSpan_pair _ _ _ have hp₁p₂s : (p₁, p₅, p₂) ∈ s := by simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and, Prod.ext_iff] refine ⟨⟨⟨p₁, left_mem_affineSpan_pair ℝ _ _⟩, p₂ -ᵥ p₁⟩, ⟨SameRay.rfl, vsub_ne_zero.2 hp₁p₂.symm⟩, ?_⟩ simp have hp₃p₄s : (p₃, p₅, p₄) ∈ s := by simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and, Prod.ext_iff] refine ⟨⟨⟨p₃, hc.mem_affineSpan_of_mem_of_ne (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_insert _ _)) (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert _ _))) hp₁p₂⟩, p₄ -ᵥ p₃⟩, ⟨hr, vsub_ne_zero.2 hp₃p₄.symm⟩, ?_⟩ simp convert Real.Angle.sign_eq_of_continuousOn hco hf hsp hp₃p₄s hp₁p₂s /-- Given three points in strict order on the same line, and a fourth point, the angles at the fourth point between the first and second or second and third points have the same sign. -/ theorem _root_.Sbtw.oangle_sign_eq {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) : (∡ p₁ p₄ p₂).sign = (∡ p₂ p₄ p₃).sign := haveI hc : Collinear ℝ ({p₁, p₂, p₂, p₃} : Set P) := by simpa using h.wbtw.collinear hc.oangle_sign_of_sameRay_vsub _ h.left_ne h.ne_right h.wbtw.sameRay_vsub /-- Given three points in weak order on the same line, with the first not equal to the second, and a fourth point, the angles at the fourth point between the first and second or first and third points have the same sign. -/ theorem _root_.Wbtw.oangle_sign_eq_of_ne_left {p₁ p₂ p₃ : P} (p₄ : P) (h : Wbtw ℝ p₁ p₂ p₃) (hne : p₁ ≠ p₂) : (∡ p₁ p₄ p₂).sign = (∡ p₁ p₄ p₃).sign := haveI hc : Collinear ℝ ({p₁, p₂, p₁, p₃} : Set P) := by simpa [Set.insert_comm p₂] using h.collinear hc.oangle_sign_of_sameRay_vsub _ hne (h.left_ne_right_of_ne_left hne.symm) h.sameRay_vsub_left /-- Given three points in strict order on the same line, and a fourth point, the angles at the fourth point between the first and second or first and third points have the same sign. -/ theorem _root_.Sbtw.oangle_sign_eq_left {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) : (∡ p₁ p₄ p₂).sign = (∡ p₁ p₄ p₃).sign := h.wbtw.oangle_sign_eq_of_ne_left _ h.left_ne /-- Given three points in weak order on the same line, with the second not equal to the third, and a fourth point, the angles at the fourth point between the second and third or first and third points have the same sign. -/ theorem _root_.Wbtw.oangle_sign_eq_of_ne_right {p₁ p₂ p₃ : P} (p₄ : P) (h : Wbtw ℝ p₁ p₂ p₃) (hne : p₂ ≠ p₃) : (∡ p₂ p₄ p₃).sign = (∡ p₁ p₄ p₃).sign := by simp_rw [oangle_rev p₃, Real.Angle.sign_neg, h.symm.oangle_sign_eq_of_ne_left _ hne.symm] /-- Given three points in strict order on the same line, and a fourth point, the angles at the fourth point between the second and third or first and third points have the same sign. -/ theorem _root_.Sbtw.oangle_sign_eq_right {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) : (∡ p₂ p₄ p₃).sign = (∡ p₁ p₄ p₃).sign := h.wbtw.oangle_sign_eq_of_ne_right _ h.ne_right /-- Given two points in an affine subspace, the angles between those two points at two other points on the same side of that subspace have the same sign. -/ theorem _root_.AffineSubspace.SSameSide.oangle_sign_eq {s : AffineSubspace ℝ P} {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃p₄ : s.SSameSide p₃ p₄) : (∡ p₁ p₄ p₂).sign = (∡ p₁ p₃ p₂).sign := by by_cases h : p₁ = p₂; · simp [h] let sp : Set (P × P × P) := (fun p : P => (p₁, p, p₂)) '' {p | s.SSameSide p₃ p} have hc : IsConnected sp := (isConnected_setOf_sSameSide hp₃p₄.2.1 hp₃p₄.nonempty).image _ (by fun_prop) have hf : ContinuousOn (fun p : P × P × P => ∡ p.1 p.2.1 p.2.2) sp := by refine continuousOn_of_forall_continuousAt fun p hp => continuousAt_oangle ?_ ?_ all_goals simp_rw [sp, Set.mem_image, Set.mem_setOf] at hp obtain ⟨p', hp', rfl⟩ := hp dsimp only rintro rfl · exact hp'.2.2 hp₁ · exact hp'.2.2 hp₂ have hsp : ∀ p : P × P × P, p ∈ sp → ∡ p.1 p.2.1 p.2.2 ≠ 0 ∧ ∡ p.1 p.2.1 p.2.2 ≠ π := by intro p hp simp_rw [sp, Set.mem_image, Set.mem_setOf] at hp obtain ⟨p', hp', rfl⟩ := hp dsimp only rw [oangle_ne_zero_and_ne_pi_iff_affineIndependent] exact affineIndependent_of_ne_of_mem_of_notMem_of_mem h hp₁ hp'.2.2 hp₂ have hp₃ : (p₁, p₃, p₂) ∈ sp := Set.mem_image_of_mem _ (sSameSide_self_iff.2 ⟨hp₃p₄.nonempty, hp₃p₄.2.1⟩) have hp₄ : (p₁, p₄, p₂) ∈ sp := Set.mem_image_of_mem _ hp₃p₄ convert Real.Angle.sign_eq_of_continuousOn hc hf hsp hp₃ hp₄ /-- Given two points in an affine subspace, the angles between those two points at two other points on opposite sides of that subspace have opposite signs. -/ theorem _root_.AffineSubspace.SOppSide.oangle_sign_eq_neg {s : AffineSubspace ℝ P} {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃p₄ : s.SOppSide p₃ p₄) : (∡ p₁ p₄ p₂).sign = -(∡ p₁ p₃ p₂).sign := by have hp₁p₃ : p₁ ≠ p₃ := by rintro rfl; exact hp₃p₄.left_notMem hp₁ rw [← (hp₃p₄.symm.trans (sOppSide_pointReflection hp₁ hp₃p₄.left_notMem)).oangle_sign_eq hp₁ hp₂, ← oangle_rotate_sign p₁, ← oangle_rotate_sign p₁, oangle_swap₁₃_sign, (sbtw_pointReflection_of_ne ℝ hp₁p₃).symm.oangle_sign_eq _] /-- The unoriented angles at `p₂` between `p₁` and `p₃`, and between `p₃` and `p₄`, are equal if and only if the oriented angles are equal (`p₃` lies on the angle bisector) or one of `p₁` and `p₄` is weakly between `p₂` and the other. -/ lemma angle_eq_iff_oangle_eq_or_wbtw {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ≠ p₂) (hp₄ : p₄ ≠ p₂) : ∠ p₁ p₂ p₃ = ∠ p₃ p₂ p₄ ↔ ∡ p₁ p₂ p₃ = ∡ p₃ p₂ p₄ ∨ Wbtw ℝ p₂ p₁ p₄ ∨ Wbtw ℝ p₂ p₄ p₁ := by simp_rw [angle, oangle, o.angle_eq_iff_oangle_eq_or_sameRay (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₄)] apply or_congr_right refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · obtain ⟨r, hr, he⟩ := h.exists_pos_left (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₄) rw [← vsub_vadd p₁ p₂, ← vsub_vadd p₄ p₂, ← he] nth_rw 1 4 [← one_smul ℝ (p₁ -ᵥ p₂)] exact wbtw_or_wbtw_smul_vadd_of_nonneg _ _ zero_le_one hr.le · rcases h with h | h · exact h.sameRay_vsub_left · exact h.sameRay_vsub_left.symm end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Oriented/Rotation.lean
import Mathlib.Analysis.SpecialFunctions.Complex.Circle import Mathlib.Geometry.Euclidean.Angle.Oriented.Basic /-! # Rotations by oriented angles. This file defines rotations by oriented angles in real inner product spaces. ## Main definitions * `Orientation.rotation` is the rotation by an oriented angle with respect to an orientation. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "J" => o.rightAngleRotation /-- Auxiliary construction to build a rotation by the oriented angle `θ`. -/ def rotationAux (θ : Real.Angle) : V →ₗᵢ[ℝ] V := LinearMap.isometryOfInner (Real.Angle.cos θ • LinearMap.id + Real.Angle.sin θ • (LinearIsometryEquiv.toLinearEquiv J).toLinearMap) (by intro x y simp only [RCLike.conj_to_real, id, LinearMap.smul_apply, LinearMap.add_apply, LinearMap.id_coe, LinearEquiv.coe_coe, LinearIsometryEquiv.coe_toLinearEquiv, Orientation.areaForm_rightAngleRotation_left, Orientation.inner_rightAngleRotation_left, Orientation.inner_rightAngleRotation_right, inner_add_left, inner_smul_left, inner_add_right, inner_smul_right] linear_combination ⟪x, y⟫ * θ.cos_sq_add_sin_sq) @[simp] theorem rotationAux_apply (θ : Real.Angle) (x : V) : o.rotationAux θ x = Real.Angle.cos θ • x + Real.Angle.sin θ • J x := rfl /-- A rotation by the oriented angle `θ`. -/ def rotation (θ : Real.Angle) : V ≃ₗᵢ[ℝ] V := LinearIsometryEquiv.ofLinearIsometry (o.rotationAux θ) (Real.Angle.cos θ • LinearMap.id - Real.Angle.sin θ • (LinearIsometryEquiv.toLinearEquiv J).toLinearMap) (by ext x convert congr_arg (fun t : ℝ => t • x) θ.cos_sq_add_sin_sq using 1 · simp only [o.rightAngleRotation_rightAngleRotation, o.rotationAux_apply, Function.comp_apply, id, LinearEquiv.coe_coe, LinearIsometry.coe_toLinearMap, LinearIsometryEquiv.coe_toLinearEquiv, map_smul, map_sub, LinearMap.coe_comp, LinearMap.id_coe, LinearMap.smul_apply, LinearMap.sub_apply] module · simp) (by ext x convert congr_arg (fun t : ℝ => t • x) θ.cos_sq_add_sin_sq using 1 · simp only [o.rightAngleRotation_rightAngleRotation, o.rotationAux_apply, Function.comp_apply, id, LinearEquiv.coe_coe, LinearIsometry.coe_toLinearMap, LinearIsometryEquiv.coe_toLinearEquiv, map_add, map_smul, LinearMap.coe_comp, LinearMap.id_coe, LinearMap.smul_apply, LinearMap.sub_apply] module · simp) theorem rotation_apply (θ : Real.Angle) (x : V) : o.rotation θ x = Real.Angle.cos θ • x + Real.Angle.sin θ • J x := rfl theorem rotation_symm_apply (θ : Real.Angle) (x : V) : (o.rotation θ).symm x = Real.Angle.cos θ • x - Real.Angle.sin θ • J x := rfl theorem rotation_eq_matrix_toLin (θ : Real.Angle) {x : V} (hx : x ≠ 0) : (o.rotation θ).toLinearMap = Matrix.toLin (o.basisRightAngleRotation x hx) (o.basisRightAngleRotation x hx) !![θ.cos, -θ.sin; θ.sin, θ.cos] := by apply (o.basisRightAngleRotation x hx).ext intro i fin_cases i · rw [Matrix.toLin_self] simp [rotation_apply, Fin.sum_univ_succ] · rw [Matrix.toLin_self] simp [rotation_apply, Fin.sum_univ_succ, add_comm] /-- The determinant of `rotation` (as a linear map) is equal to `1`. -/ @[simp] theorem det_rotation (θ : Real.Angle) : LinearMap.det (o.rotation θ).toLinearMap = 1 := by haveI : Nontrivial V := nontrivial_of_finrank_eq_succ (@Fact.out (finrank ℝ V = 2) _) obtain ⟨x, hx⟩ : ∃ x, x ≠ (0 : V) := exists_ne (0 : V) rw [o.rotation_eq_matrix_toLin θ hx] simpa [sq] using θ.cos_sq_add_sin_sq /-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/ @[simp] theorem linearEquiv_det_rotation (θ : Real.Angle) : LinearEquiv.det (o.rotation θ).toLinearEquiv = 1 := Units.ext <| by simpa only [LinearEquiv.coe_det, Units.val_one] using o.det_rotation θ /-- The inverse of `rotation` is rotation by the negation of the angle. -/ @[simp] theorem rotation_symm (θ : Real.Angle) : (o.rotation θ).symm = o.rotation (-θ) := by ext; simp [o.rotation_apply, o.rotation_symm_apply, sub_eq_add_neg] /-- Rotation by 0 is the identity. -/ @[simp] theorem rotation_zero : o.rotation 0 = LinearIsometryEquiv.refl ℝ V := by ext; simp [rotation] /-- Rotation by π is negation. -/ @[simp] theorem rotation_pi : o.rotation π = LinearIsometryEquiv.neg ℝ := by ext x simp [rotation] /-- Rotation by π is negation. -/ theorem rotation_pi_apply (x : V) : o.rotation π x = -x := by simp /-- Rotation by π / 2 is the "right-angle-rotation" map `J`. -/ theorem rotation_pi_div_two : o.rotation (π / 2 : ℝ) = J := by ext x simp [rotation] /-- Rotating twice is equivalent to rotating by the sum of the angles. -/ @[simp] theorem rotation_rotation (θ₁ θ₂ : Real.Angle) (x : V) : o.rotation θ₁ (o.rotation θ₂ x) = o.rotation (θ₁ + θ₂) x := by simp only [o.rotation_apply, Real.Angle.cos_add, Real.Angle.sin_add, LinearIsometryEquiv.map_add, map_smul, rightAngleRotation_rightAngleRotation] module /-- Rotating twice is equivalent to rotating by the sum of the angles. -/ @[simp] theorem rotation_trans (θ₁ θ₂ : Real.Angle) : (o.rotation θ₁).trans (o.rotation θ₂) = o.rotation (θ₂ + θ₁) := LinearIsometryEquiv.ext fun _ => by rw [← rotation_rotation, LinearIsometryEquiv.trans_apply] /-- Rotating the first of two vectors by `θ` scales their Kähler form by `cos θ - sin θ * I`. -/ @[simp] theorem kahler_rotation_left (x y : V) (θ : Real.Angle) : o.kahler (o.rotation θ x) y = conj (θ.toCircle : ℂ) * o.kahler x y := by simp only [o.rotation_apply, map_add, map_mul, LinearMap.map_smulₛₗ, RingHom.id_apply, LinearMap.add_apply, LinearMap.smul_apply, real_smul, kahler_rightAngleRotation_left, Real.Angle.coe_toCircle, Complex.conj_ofReal, conj_I] ring /-- Negating a rotation is equivalent to rotation by π plus the angle. -/ theorem neg_rotation (θ : Real.Angle) (x : V) : -o.rotation θ x = o.rotation (π + θ) x := by rw [← o.rotation_pi_apply, rotation_rotation] /-- Negating a rotation by -π / 2 is equivalent to rotation by π / 2. -/ @[simp] theorem neg_rotation_neg_pi_div_two (x : V) : -o.rotation (-π / 2 : ℝ) x = o.rotation (π / 2 : ℝ) x := by rw [neg_rotation, ← Real.Angle.coe_add, neg_div, ← sub_eq_add_neg, sub_half] /-- Negating a rotation by π / 2 is equivalent to rotation by -π / 2. -/ theorem neg_rotation_pi_div_two (x : V) : -o.rotation (π / 2 : ℝ) x = o.rotation (-π / 2 : ℝ) x := (neg_eq_iff_eq_neg.mp <| o.neg_rotation_neg_pi_div_two _).symm /-- Rotating the first of two vectors by `θ` scales their Kähler form by `cos (-θ) + sin (-θ) * I`. -/ theorem kahler_rotation_left' (x y : V) (θ : Real.Angle) : o.kahler (o.rotation θ x) y = (-θ).toCircle * o.kahler x y := by simp only [Real.Angle.toCircle_neg, Circle.coe_inv_eq_conj, kahler_rotation_left] /-- Rotating the second of two vectors by `θ` scales their Kähler form by `cos θ + sin θ * I`. -/ @[simp] theorem kahler_rotation_right (x y : V) (θ : Real.Angle) : o.kahler x (o.rotation θ y) = θ.toCircle * o.kahler x y := by simp only [o.rotation_apply, map_add, LinearMap.map_smulₛₗ, RingHom.id_apply, real_smul, kahler_rightAngleRotation_right, Real.Angle.coe_toCircle] ring /-- Rotating the first vector by `θ` subtracts `θ` from the angle between two vectors. -/ @[simp] theorem oangle_rotation_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) (θ : Real.Angle) : o.oangle (o.rotation θ x) y = o.oangle x y - θ := by simp only [oangle, o.kahler_rotation_left'] rw [Complex.arg_mul_coe_angle, Real.Angle.arg_toCircle] · abel · exact Circle.coe_ne_zero _ · exact o.kahler_ne_zero hx hy /-- Rotating the second vector by `θ` adds `θ` to the angle between two vectors. -/ @[simp] theorem oangle_rotation_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) (θ : Real.Angle) : o.oangle x (o.rotation θ y) = o.oangle x y + θ := by simp only [oangle, o.kahler_rotation_right] rw [Complex.arg_mul_coe_angle, Real.Angle.arg_toCircle] · abel · exact Circle.coe_ne_zero _ · exact o.kahler_ne_zero hx hy /-- The rotation of a vector by `θ` has an angle of `-θ` from that vector. -/ theorem oangle_rotation_self_left {x : V} (hx : x ≠ 0) (θ : Real.Angle) : o.oangle (o.rotation θ x) x = -θ := by simp [hx] /-- A vector has an angle of `θ` from the rotation of that vector by `θ`. -/ theorem oangle_rotation_self_right {x : V} (hx : x ≠ 0) (θ : Real.Angle) : o.oangle x (o.rotation θ x) = θ := by simp [hx] /-- Rotating the first vector by the angle between the two vectors results in an angle of 0. -/ @[simp] theorem oangle_rotation_oangle_left (x y : V) : o.oangle (o.rotation (o.oangle x y) x) y = 0 := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [hx, hy] /-- Rotating the first vector by the angle between the two vectors and swapping the vectors results in an angle of 0. -/ @[simp] theorem oangle_rotation_oangle_right (x y : V) : o.oangle y (o.rotation (o.oangle x y) x) = 0 := by rw [oangle_rev] simp /-- Rotating both vectors by the same angle does not change the angle between those vectors. -/ @[simp] theorem oangle_rotation (x y : V) (θ : Real.Angle) : o.oangle (o.rotation θ x) (o.rotation θ y) = o.oangle x y := by by_cases hx : x = 0 <;> by_cases hy : y = 0 <;> simp [hx, hy] /-- A rotation of a nonzero vector equals that vector if and only if the angle is zero. -/ @[simp] theorem rotation_eq_self_iff_angle_eq_zero {x : V} (hx : x ≠ 0) (θ : Real.Angle) : o.rotation θ x = x ↔ θ = 0 := by constructor · intro h rw [eq_comm] simpa [hx, h] using o.oangle_rotation_right hx hx θ · intro h simp [h] /-- A nonzero vector equals a rotation of that vector if and only if the angle is zero. -/ @[simp] theorem eq_rotation_self_iff_angle_eq_zero {x : V} (hx : x ≠ 0) (θ : Real.Angle) : x = o.rotation θ x ↔ θ = 0 := by rw [← o.rotation_eq_self_iff_angle_eq_zero hx, eq_comm] /-- A rotation of a vector equals that vector if and only if the vector or the angle is zero. -/ theorem rotation_eq_self_iff (x : V) (θ : Real.Angle) : o.rotation θ x = x ↔ x = 0 ∨ θ = 0 := by by_cases h : x = 0 <;> simp [h] /-- A vector equals a rotation of that vector if and only if the vector or the angle is zero. -/ theorem eq_rotation_self_iff (x : V) (θ : Real.Angle) : x = o.rotation θ x ↔ x = 0 ∨ θ = 0 := by rw [← rotation_eq_self_iff, eq_comm] /-- Rotating a vector by the angle to another vector gives the second vector if and only if the norms are equal. -/ @[simp] theorem rotation_oangle_eq_iff_norm_eq (x y : V) : o.rotation (o.oangle x y) x = y ↔ ‖x‖ = ‖y‖ := by constructor · intro h rw [← h, LinearIsometryEquiv.norm_map] · intro h rw [o.eq_iff_oangle_eq_zero_of_norm_eq] <;> simp [h] /-- The angle between two nonzero vectors is `θ` if and only if the second vector is the first rotated by `θ` and scaled by the ratio of the norms. -/ theorem oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) (θ : Real.Angle) : o.oangle x y = θ ↔ y = (‖y‖ / ‖x‖) • o.rotation θ x := by have hp := div_pos (norm_pos_iff.2 hy) (norm_pos_iff.2 hx) constructor · rintro rfl rw [← LinearIsometryEquiv.map_smul, ← o.oangle_smul_left_of_pos x y hp, eq_comm, rotation_oangle_eq_iff_norm_eq, norm_smul, Real.norm_of_nonneg hp.le, div_mul_cancel₀ _ (norm_ne_zero_iff.2 hx)] · intro hye rw [hye, o.oangle_smul_right_of_pos _ _ hp, o.oangle_rotation_self_right hx] /-- The angle between two nonzero vectors is `θ` if and only if the second vector is the first rotated by `θ` and scaled by a positive real. -/ theorem oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) (θ : Real.Angle) : o.oangle x y = θ ↔ ∃ r : ℝ, 0 < r ∧ y = r • o.rotation θ x := by constructor · intro h rw [o.oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy] at h exact ⟨‖y‖ / ‖x‖, div_pos (norm_pos_iff.2 hy) (norm_pos_iff.2 hx), h⟩ · rintro ⟨r, hr, rfl⟩ rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right hx] /-- The angle between two vectors is `θ` if and only if they are nonzero and the second vector is the first rotated by `θ` and scaled by the ratio of the norms, or `θ` and at least one of the vectors are zero. -/ theorem oangle_eq_iff_eq_norm_div_norm_smul_rotation_or_eq_zero {x y : V} (θ : Real.Angle) : o.oangle x y = θ ↔ x ≠ 0 ∧ y ≠ 0 ∧ y = (‖y‖ / ‖x‖) • o.rotation θ x ∨ θ = 0 ∧ (x = 0 ∨ y = 0) := by by_cases hx : x = 0 · simp [hx, eq_comm] · by_cases hy : y = 0 · simp [hy, eq_comm] · rw [o.oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy] simp [hx, hy] /-- The angle between two vectors is `θ` if and only if they are nonzero and the second vector is the first rotated by `θ` and scaled by a positive real, or `θ` and at least one of the vectors are zero. -/ theorem oangle_eq_iff_eq_pos_smul_rotation_or_eq_zero {x y : V} (θ : Real.Angle) : o.oangle x y = θ ↔ (x ≠ 0 ∧ y ≠ 0 ∧ ∃ r : ℝ, 0 < r ∧ y = r • o.rotation θ x) ∨ θ = 0 ∧ (x = 0 ∨ y = 0) := by by_cases hx : x = 0 · simp [hx, eq_comm] · by_cases hy : y = 0 · simp [hy, eq_comm] · rw [o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero hx hy] simp [hx, hy] /-- Any linear isometric equivalence in `V` with positive determinant is `rotation`. -/ theorem exists_linearIsometryEquiv_eq_of_det_pos {f : V ≃ₗᵢ[ℝ] V} (hd : 0 < LinearMap.det (f.toLinearEquiv : V →ₗ[ℝ] V)) : ∃ θ : Real.Angle, f = o.rotation θ := by haveI : Nontrivial V := nontrivial_of_finrank_eq_succ (@Fact.out (finrank ℝ V = 2) _) obtain ⟨x, hx⟩ : ∃ x, x ≠ (0 : V) := exists_ne (0 : V) use o.oangle x (f x) apply LinearIsometryEquiv.toLinearEquiv_injective apply LinearEquiv.toLinearMap_injective apply (o.basisRightAngleRotation x hx).ext intro i symm fin_cases i · simp have : o.oangle (J x) (f (J x)) = o.oangle x (f x) := by simp only [oangle, o.linearIsometryEquiv_comp_rightAngleRotation f hd, o.kahler_comp_rightAngleRotation] simp [← this] theorem rotation_map (θ : Real.Angle) (f : V ≃ₗᵢ[ℝ] V') (x : V') : (Orientation.map (Fin 2) f.toLinearEquiv o).rotation θ x = f (o.rotation θ (f.symm x)) := by simp [rotation_apply, o.rightAngleRotation_map] @[simp] protected theorem _root_.Complex.rotation (θ : Real.Angle) (z : ℂ) : Complex.orientation.rotation θ z = θ.toCircle * z := by simp only [rotation_apply, Complex.rightAngleRotation, Real.Angle.coe_toCircle, real_smul] ring /-- Rotation in an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem rotation_map_complex (θ : Real.Angle) (f : V ≃ₗᵢ[ℝ] ℂ) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x : V) : f (o.rotation θ x) = θ.toCircle * f x := by rw [← Complex.rotation, ← hf, o.rotation_map, LinearIsometryEquiv.symm_apply_apply] /-- Negating the orientation negates the angle in `rotation`. -/ theorem rotation_neg_orientation_eq_neg (θ : Real.Angle) : (-o).rotation θ = o.rotation (-θ) := LinearIsometryEquiv.ext <| by simp [rotation_apply] /-- The inner product between a `π / 2` rotation of a vector and that vector is zero. -/ @[simp] theorem inner_rotation_pi_div_two_left (x : V) : ⟪o.rotation (π / 2 : ℝ) x, x⟫ = 0 := by rw [rotation_pi_div_two, inner_rightAngleRotation_self] /-- The inner product between a vector and a `π / 2` rotation of that vector is zero. -/ @[simp] theorem inner_rotation_pi_div_two_right (x : V) : ⟪x, o.rotation (π / 2 : ℝ) x⟫ = 0 := by rw [real_inner_comm, inner_rotation_pi_div_two_left] /-- The inner product between a multiple of a `π / 2` rotation of a vector and that vector is zero. -/ @[simp] theorem inner_smul_rotation_pi_div_two_left (x : V) (r : ℝ) : ⟪r • o.rotation (π / 2 : ℝ) x, x⟫ = 0 := by rw [inner_smul_left, inner_rotation_pi_div_two_left, mul_zero] /-- The inner product between a vector and a multiple of a `π / 2` rotation of that vector is zero. -/ @[simp] theorem inner_smul_rotation_pi_div_two_right (x : V) (r : ℝ) : ⟪x, r • o.rotation (π / 2 : ℝ) x⟫ = 0 := by rw [real_inner_comm, inner_smul_rotation_pi_div_two_left] /-- The inner product between a `π / 2` rotation of a vector and a multiple of that vector is zero. -/ @[simp] theorem inner_rotation_pi_div_two_left_smul (x : V) (r : ℝ) : ⟪o.rotation (π / 2 : ℝ) x, r • x⟫ = 0 := by rw [inner_smul_right, inner_rotation_pi_div_two_left, mul_zero] /-- The inner product between a multiple of a vector and a `π / 2` rotation of that vector is zero. -/ @[simp] theorem inner_rotation_pi_div_two_right_smul (x : V) (r : ℝ) : ⟪r • x, o.rotation (π / 2 : ℝ) x⟫ = 0 := by rw [real_inner_comm, inner_rotation_pi_div_two_left_smul] /-- The inner product between a multiple of a `π / 2` rotation of a vector and a multiple of that vector is zero. -/ @[simp] theorem inner_smul_rotation_pi_div_two_smul_left (x : V) (r₁ r₂ : ℝ) : ⟪r₁ • o.rotation (π / 2 : ℝ) x, r₂ • x⟫ = 0 := by rw [inner_smul_right, inner_smul_rotation_pi_div_two_left, mul_zero] /-- The inner product between a multiple of a vector and a multiple of a `π / 2` rotation of that vector is zero. -/ @[simp] theorem inner_smul_rotation_pi_div_two_smul_right (x : V) (r₁ r₂ : ℝ) : ⟪r₂ • x, r₁ • o.rotation (π / 2 : ℝ) x⟫ = 0 := by rw [real_inner_comm, inner_smul_rotation_pi_div_two_smul_left] /-- The inner product between two vectors is zero if and only if the first vector is zero or the second is a multiple of a `π / 2` rotation of that vector. -/ theorem inner_eq_zero_iff_eq_zero_or_eq_smul_rotation_pi_div_two {x y : V} : ⟪x, y⟫ = 0 ↔ x = 0 ∨ ∃ r : ℝ, r • o.rotation (π / 2 : ℝ) x = y := by rw [← o.eq_zero_or_oangle_eq_iff_inner_eq_zero] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (rfl | rfl | h | h) · exact Or.inl rfl · exact Or.inr ⟨0, zero_smul _ _⟩ · obtain ⟨r, _, rfl⟩ := (o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero (o.left_ne_zero_of_oangle_eq_pi_div_two h) (o.right_ne_zero_of_oangle_eq_pi_div_two h) _).1 h exact Or.inr ⟨r, rfl⟩ · obtain ⟨r, _, rfl⟩ := (o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero (o.left_ne_zero_of_oangle_eq_neg_pi_div_two h) (o.right_ne_zero_of_oangle_eq_neg_pi_div_two h) _).1 h refine Or.inr ⟨-r, ?_⟩ rw [neg_smul, ← smul_neg, o.neg_rotation_pi_div_two] · rcases h with (rfl | ⟨r, rfl⟩) · exact Or.inl rfl · by_cases hx : x = 0; · exact Or.inl hx rcases lt_trichotomy r 0 with (hr | rfl | hr) · refine Or.inr (Or.inr (Or.inr ?_)) rw [o.oangle_smul_right_of_neg _ _ hr, o.neg_rotation_pi_div_two, o.oangle_rotation_self_right hx] · exact Or.inr (Or.inl (zero_smul _ _)) · refine Or.inr (Or.inr (Or.inl ?_)) rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right hx] end Orientation
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Unoriented/CrossProduct.lean
import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic import Mathlib.LinearAlgebra.CrossProduct /-! # Norm of cross-products This file proves `InnerProductGeometry.norm_withLpEquiv_crossProduct`, relating the norm of the cross-product of two real vectors with their individual norms. -/ open Matrix Real WithLp namespace InnerProductGeometry open scoped RealInnerProductSpace /-- The L2 norm of the cross product of two real vectors (of type `EuclideanSpace ℝ (Fin 3)`) equals the product of their individual norms times the sine of the angle between them. -/ lemma norm_ofLp_crossProduct (a b : EuclideanSpace ℝ (Fin 3)) : ‖toLp 2 (ofLp a ⨯₃ ofLp b)‖ = ‖a‖ * ‖b‖ * sin (angle a b) := by have := sin_angle_nonneg a b refine sq_eq_sq₀ (by positivity) (by positivity) |>.mp ?_ trans ‖a‖^2 * ‖b‖^2 - ⟪a, b⟫ ^ 2 · simp_rw [norm_sq_eq_re_inner (𝕜 := ℝ), EuclideanSpace.inner_eq_star_dotProduct, star_trivial, RCLike.re_to_real, cross_dot_cross, dotProduct_comm (ofLp b) (ofLp a), sq] · linear_combination (‖a‖ * ‖b‖) ^ 2 * (sin_sq_add_cos_sq (angle a b)).symm + congrArg (· ^ 2) (cos_angle_mul_norm_mul_norm a b) @[deprecated norm_ofLp_crossProduct (since := "2025-05-04")] theorem norm_withLpEquiv_crossProduct (a b : EuclideanSpace ℝ (Fin 3)) : ‖(WithLp.equiv 2 (Fin 3 → ℝ)).symm (WithLp.equiv _ _ a ⨯₃ WithLp.equiv _ _ b)‖ = ‖a‖ * ‖b‖ * sin (angle a b) := norm_ofLp_crossProduct .. /-- The L2 norm of the cross product of two real vectors (of type `Fin 3 → R`) equals the product of their individual L2 norms times the sine of the angle between them. -/ lemma norm_toLp_symm_crossProduct (a b : Fin 3 → ℝ) : ‖toLp 2 (a ⨯₃ b)‖ = ‖toLp 2 a‖ * ‖toLp 2 b‖ * sin (angle (toLp 2 a) (toLp 2 b)) := by simp [← norm_ofLp_crossProduct (toLp 2 a) (toLp 2 b)] /-- The L2 norm of the cross product of two real vectors (of type `Fin 3 → R`) equals the product of their individual L2 norms times the sine of the angle between them. -/ @[deprecated norm_toLp_symm_crossProduct (since := "2025-05-04")] theorem norm_withLpEquiv_symm_crossProduct (a b : Fin 3 → ℝ) : ‖(WithLp.equiv 2 (Fin 3 → ℝ)).symm (a ⨯₃ b)‖ = ‖(WithLp.equiv 2 (Fin 3 → ℝ)).symm a‖ * ‖(WithLp.equiv 2 (Fin 3 → ℝ)).symm b‖ * sin (angle ((WithLp.equiv 2 (Fin 3 → ℝ)).symm a) ((WithLp.equiv 2 (Fin 3 → ℝ)).symm b)) := norm_toLp_symm_crossProduct .. end InnerProductGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Unoriented/Basic.lean
import Mathlib.Analysis.InnerProductSpace.Subspace import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse /-! # Angles between vectors This file defines unoriented angles in real inner product spaces. ## Main definitions * `InnerProductGeometry.angle` is the undirected angle between two vectors. ## TODO Prove the triangle inequality for the angle. -/ assert_not_exists HasFDerivAt ConformalAt noncomputable section open Real Set open Real open RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] {x y : V} /-- The undirected angle between two vectors. If either vector is 0, this is π/2. See `Orientation.oangle` for the corresponding oriented angle definition. -/ def angle (x y : V) : ℝ := Real.arccos (⟪x, y⟫ / (‖x‖ * ‖y‖)) theorem continuousAt_angle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => angle y.1 y.2) x := by unfold angle fun_prop (disch := simp [*]) theorem angle_smul_smul {c : ℝ} (hc : c ≠ 0) (x y : V) : angle (c • x) (c • y) = angle x y := by have : c * c ≠ 0 := mul_ne_zero hc hc rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs, mul_mul_mul_comm _ ‖x‖, abs_mul_abs_self, ← mul_assoc c c, mul_div_mul_left _ _ this] @[simp] theorem _root_.LinearIsometry.angle_map {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F] [InnerProductSpace ℝ E] [InnerProductSpace ℝ F] (f : E →ₗᵢ[ℝ] F) (u v : E) : angle (f u) (f v) = angle u v := by rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map] @[simp, norm_cast] theorem _root_.Submodule.angle_coe {s : Submodule ℝ V} (x y : s) : angle (x : V) (y : V) = angle x y := s.subtypeₗᵢ.angle_map x y /-- The cosine of the angle between two vectors. -/ theorem cos_angle (x y : V) : Real.cos (angle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1 (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2 /-- The angle between two vectors does not depend on their order. -/ theorem angle_comm (x y : V) : angle x y = angle y x := by unfold angle rw [real_inner_comm, mul_comm] /-- The angle between the negation of two vectors. -/ @[simp] theorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y := by unfold angle rw [inner_neg_neg, norm_neg, norm_neg] /-- The angle between two vectors is nonnegative. -/ theorem angle_nonneg (x y : V) : 0 ≤ angle x y := Real.arccos_nonneg _ /-- The angle between two vectors is at most π. -/ theorem angle_le_pi (x y : V) : angle x y ≤ π := Real.arccos_le_pi _ /-- The sine of the angle between two vectors is nonnegative. -/ theorem sin_angle_nonneg (x y : V) : 0 ≤ sin (angle x y) := sin_nonneg_of_nonneg_of_le_pi (angle_nonneg x y) (angle_le_pi x y) /-- The angle between a vector and the negation of another vector. -/ theorem angle_neg_right (x y : V) : angle x (-y) = π - angle x y := by unfold angle rw [← Real.arccos_neg, norm_neg, inner_neg_right, neg_div] /-- The angle between the negation of a vector and another vector. -/ theorem angle_neg_left (x y : V) : angle (-x) y = π - angle x y := by rw [← angle_neg_neg, neg_neg, angle_neg_right] proof_wanted angle_triangle (x y z : V) : angle x z ≤ angle x y + angle y z /-- The angle between the zero vector and a vector. -/ @[simp] theorem angle_zero_left (x : V) : angle 0 x = π / 2 := by unfold angle rw [inner_zero_left, zero_div, Real.arccos_zero] /-- The angle between a vector and the zero vector. -/ @[simp] theorem angle_zero_right (x : V) : angle x 0 = π / 2 := by unfold angle rw [inner_zero_right, zero_div, Real.arccos_zero] /-- The angle between a nonzero vector and itself. -/ @[simp] theorem angle_self {x : V} (hx : x ≠ 0) : angle x x = 0 := by unfold angle rw [← real_inner_self_eq_norm_mul_norm, div_self (inner_self_ne_zero.2 hx : ⟪x, x⟫ ≠ 0), Real.arccos_one] /-- The angle between a nonzero vector and its negation. -/ @[simp] theorem angle_self_neg_of_nonzero {x : V} (hx : x ≠ 0) : angle x (-x) = π := by rw [angle_neg_right, angle_self hx, sub_zero] /-- The angle between the negation of a nonzero vector and that vector. -/ @[simp] theorem angle_neg_self_of_nonzero {x : V} (hx : x ≠ 0) : angle (-x) x = π := by rw [angle_comm, angle_self_neg_of_nonzero hx] /-- The angle between a vector and a positive multiple of a vector. -/ @[simp] theorem angle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : angle x (r • y) = angle x y := by unfold angle rw [inner_smul_right, norm_smul, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), ← mul_assoc, mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)] /-- The angle between a positive multiple of a vector and a vector. -/ @[simp] theorem angle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : angle (r • x) y = angle x y := by rw [angle_comm, angle_smul_right_of_pos y x hr, angle_comm] /-- The angle between a vector and a negative multiple of a vector. -/ @[simp] theorem angle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : angle x (r • y) = angle x (-y) := by rw [← neg_neg r, neg_smul, angle_neg_right, angle_smul_right_of_pos x y (neg_pos_of_neg hr), angle_neg_right] /-- The angle between a negative multiple of a vector and a vector. -/ @[simp] theorem angle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : angle (r • x) y = angle (-x) y := by rw [angle_comm, angle_smul_right_of_neg y x hr, angle_comm] /-- The cosine of the angle between two vectors, multiplied by the product of their norms. -/ theorem cos_angle_mul_norm_mul_norm (x y : V) : Real.cos (angle x y) * (‖x‖ * ‖y‖) = ⟪x, y⟫ := by rw [cos_angle, div_mul_cancel_of_imp] simp +contextual [or_imp] /-- The sine of the angle between two vectors, multiplied by the product of their norms. -/ theorem sin_angle_mul_norm_mul_norm (x y : V) : Real.sin (angle x y) * (‖x‖ * ‖y‖) = √(⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫) := by unfold angle rw [Real.sin_arccos] nth_rw 2 [← Real.sqrt_sq (mul_nonneg (norm_nonneg x) (norm_nonneg y))] rw [← Real.sqrt_mul' _ (by positivity), sq] rcases eq_or_ne x 0 with (rfl | hx); · simp rcases eq_or_ne y 0 with (rfl | hy); · simp simp only [real_inner_self_eq_norm_mul_norm] field_simp /-- The sine of the angle between two vectors. -/ theorem sin_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x y) = √(⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫) / (‖x‖ * ‖y‖) := by rw [← sin_angle_mul_norm_mul_norm] field /-- The sine of the angle between `x` and `x + y`. -/ theorem sin_angle_add {x y : V} (hx : x ≠ 0) (hy : x + y ≠ 0) : Real.sin (angle x (x + y)) = √(⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫) / (‖x‖ * ‖x + y‖) := by rw [sin_angle hx hy] field_simp simp only [inner_add_left, inner_add_right, real_inner_comm] ring_nf /-- The angle between two vectors is zero if and only if they are nonzero and one is a positive multiple of the other. -/ theorem angle_eq_zero_iff {x y : V} : angle x y = 0 ↔ x ≠ 0 ∧ ∃ r : ℝ, 0 < r ∧ y = r • x := by rw [angle, ← real_inner_div_norm_mul_norm_eq_one_iff, Real.arccos_eq_zero, LE.le.ge_iff_eq', eq_comm] exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2 /-- The angle between two vectors is π if and only if they are nonzero and one is a negative multiple of the other. -/ theorem angle_eq_pi_iff {x y : V} : angle x y = π ↔ x ≠ 0 ∧ ∃ r : ℝ, r < 0 ∧ y = r • x := by rw [angle, ← real_inner_div_norm_mul_norm_eq_neg_one_iff, Real.arccos_eq_pi, LE.le.ge_iff_eq'] exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1 /-- If the angle between two vectors is π, the angles between those vectors and a third vector add to π. -/ theorem angle_add_angle_eq_pi_of_angle_eq_pi {x y : V} (z : V) (h : angle x y = π) : angle x z + angle y z = π := by rcases angle_eq_pi_iff.1 h with ⟨_, ⟨r, ⟨hr, rfl⟩⟩⟩ rw [angle_smul_left_of_neg x z hr, angle_neg_left, add_sub_cancel] /-- Two vectors have inner product 0 if and only if the angle between them is π/2. -/ theorem inner_eq_zero_iff_angle_eq_pi_div_two (x y : V) : ⟪x, y⟫ = 0 ↔ angle x y = π / 2 := Iff.symm <| by simp +contextual [angle, or_imp] /-- If the angle between two vectors is π, the inner product equals the negative product of the norms. -/ theorem inner_eq_neg_mul_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ⟪x, y⟫ = -(‖x‖ * ‖y‖) := by simp [← cos_angle_mul_norm_mul_norm, h] /-- If the angle between two vectors is 0, the inner product equals the product of the norms. -/ theorem inner_eq_mul_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ⟪x, y⟫ = ‖x‖ * ‖y‖ := by simp [← cos_angle_mul_norm_mul_norm, h] /-- The inner product of two non-zero vectors equals the negative product of their norms if and only if the angle between the two vectors is π. -/ theorem inner_eq_neg_mul_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ⟪x, y⟫ = -(‖x‖ * ‖y‖) ↔ angle x y = π := by refine ⟨fun h => ?_, inner_eq_neg_mul_norm_of_angle_eq_pi⟩ have h₁ : ‖x‖ * ‖y‖ ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne' rw [angle, h, neg_div, div_self h₁, Real.arccos_neg_one] /-- The inner product of two non-zero vectors equals the product of their norms if and only if the angle between the two vectors is 0. -/ theorem inner_eq_mul_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ⟪x, y⟫ = ‖x‖ * ‖y‖ ↔ angle x y = 0 := by refine ⟨fun h => ?_, inner_eq_mul_norm_of_angle_eq_zero⟩ have h₁ : ‖x‖ * ‖y‖ ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne' rw [angle, h, div_self h₁, Real.arccos_one] /-- If the angle between two vectors is π, the norm of their difference equals the sum of their norms. -/ theorem norm_sub_eq_add_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ‖x - y‖ = ‖x‖ + ‖y‖ := by rw [← sq_eq_sq₀ (norm_nonneg (x - y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)), norm_sub_pow_two_real, inner_eq_neg_mul_norm_of_angle_eq_pi h] ring /-- If the angle between two vectors is 0, the norm of their sum equals the sum of their norms. -/ theorem norm_add_eq_add_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ‖x + y‖ = ‖x‖ + ‖y‖ := by rw [← sq_eq_sq₀ (norm_nonneg (x + y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)), norm_add_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h] ring /-- If the angle between two vectors is 0, the norm of their difference equals the absolute value of the difference of their norms. -/ theorem norm_sub_eq_abs_sub_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ‖x - y‖ = |‖x‖ - ‖y‖| := by rw [← sq_eq_sq₀ (norm_nonneg (x - y)) (abs_nonneg (‖x‖ - ‖y‖)), norm_sub_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h, sq_abs (‖x‖ - ‖y‖)] ring /-- The norm of the difference of two non-zero vectors equals the sum of their norms if and only the angle between the two vectors is π. -/ theorem norm_sub_eq_add_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ‖x - y‖ = ‖x‖ + ‖y‖ ↔ angle x y = π := by refine ⟨fun h => ?_, norm_sub_eq_add_norm_of_angle_eq_pi⟩ rw [← inner_eq_neg_mul_norm_iff_angle_eq_pi hx hy] obtain ⟨hxy₁, hxy₂⟩ := norm_nonneg (x - y), add_nonneg (norm_nonneg x) (norm_nonneg y) rw [← sq_eq_sq₀ hxy₁ hxy₂, norm_sub_pow_two_real] at h calc ⟪x, y⟫ = (‖x‖ ^ 2 + ‖y‖ ^ 2 - (‖x‖ + ‖y‖) ^ 2) / 2 := by linarith _ = -(‖x‖ * ‖y‖) := by ring /-- The norm of the sum of two non-zero vectors equals the sum of their norms if and only the angle between the two vectors is 0. -/ theorem norm_add_eq_add_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ‖x + y‖ = ‖x‖ + ‖y‖ ↔ angle x y = 0 := by refine ⟨fun h => ?_, norm_add_eq_add_norm_of_angle_eq_zero⟩ rw [← inner_eq_mul_norm_iff_angle_eq_zero hx hy] obtain ⟨hxy₁, hxy₂⟩ := norm_nonneg (x + y), add_nonneg (norm_nonneg x) (norm_nonneg y) rw [← sq_eq_sq₀ hxy₁ hxy₂, norm_add_pow_two_real] at h calc ⟪x, y⟫ = ((‖x‖ + ‖y‖) ^ 2 - ‖x‖ ^ 2 - ‖y‖ ^ 2) / 2 := by linarith _ = ‖x‖ * ‖y‖ := by ring /-- The norm of the difference of two non-zero vectors equals the absolute value of the difference of their norms if and only the angle between the two vectors is 0. -/ theorem norm_sub_eq_abs_sub_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ‖x - y‖ = |‖x‖ - ‖y‖| ↔ angle x y = 0 := by refine ⟨fun h => ?_, norm_sub_eq_abs_sub_norm_of_angle_eq_zero⟩ rw [← inner_eq_mul_norm_iff_angle_eq_zero hx hy] have h1 : ‖x - y‖ ^ 2 = (‖x‖ - ‖y‖) ^ 2 := by rw [h] exact sq_abs (‖x‖ - ‖y‖) rw [norm_sub_pow_two_real] at h1 calc ⟪x, y⟫ = ((‖x‖ + ‖y‖) ^ 2 - ‖x‖ ^ 2 - ‖y‖ ^ 2) / 2 := by linarith _ = ‖x‖ * ‖y‖ := by ring /-- The norm of the sum of two vectors equals the norm of their difference if and only if the angle between them is π/2. -/ theorem norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (x y : V) : ‖x + y‖ = ‖x - y‖ ↔ angle x y = π / 2 := by rw [← sq_eq_sq₀ (norm_nonneg (x + y)) (norm_nonneg (x - y)), ← inner_eq_zero_iff_angle_eq_pi_div_two x y, norm_add_pow_two_real, norm_sub_pow_two_real] constructor <;> intro h <;> linarith /-- The cosine of the angle between two vectors is 1 if and only if the angle is 0. -/ theorem cos_eq_one_iff_angle_eq_zero : cos (angle x y) = 1 ↔ angle x y = 0 := by rw [← cos_zero] exact injOn_cos.eq_iff ⟨angle_nonneg x y, angle_le_pi x y⟩ (left_mem_Icc.2 pi_pos.le) /-- The cosine of the angle between two vectors is 0 if and only if the angle is π / 2. -/ theorem cos_eq_zero_iff_angle_eq_pi_div_two : cos (angle x y) = 0 ↔ angle x y = π / 2 := by rw [← cos_pi_div_two] apply injOn_cos.eq_iff ⟨angle_nonneg x y, angle_le_pi x y⟩ constructor <;> linarith [pi_pos] /-- The cosine of the angle between two vectors is -1 if and only if the angle is π. -/ theorem cos_eq_neg_one_iff_angle_eq_pi : cos (angle x y) = -1 ↔ angle x y = π := by rw [← cos_pi] exact injOn_cos.eq_iff ⟨angle_nonneg x y, angle_le_pi x y⟩ (right_mem_Icc.2 pi_pos.le) /-- The sine of the angle between two vectors is 0 if and only if the angle is 0 or π. -/ theorem sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi : sin (angle x y) = 0 ↔ angle x y = 0 ∨ angle x y = π := by rw [sin_eq_zero_iff_cos_eq, cos_eq_one_iff_angle_eq_zero, cos_eq_neg_one_iff_angle_eq_pi] /-- The sine of the angle between two vectors is 1 if and only if the angle is π / 2. -/ theorem sin_eq_one_iff_angle_eq_pi_div_two : sin (angle x y) = 1 ↔ angle x y = π / 2 := by refine ⟨fun h => ?_, fun h => by rw [h, sin_pi_div_two]⟩ rw [← cos_eq_zero_iff_angle_eq_pi_div_two, ← abs_eq_zero, abs_cos_eq_sqrt_one_sub_sin_sq, h] simp end InnerProductGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Unoriented/RightAngle.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Arctan import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine /-! # Right-angled triangles This file proves basic geometric results about distances and angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Pythagorean_theorem -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- Pythagorean theorem, if-and-only-if vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by rw [norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y /-- Pythagorean theorem, vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by rw [norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y /-- Pythagorean theorem, subtracting vectors, vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem angle_add_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by rw [angle, inner_add_right, h, add_zero, real_inner_self_eq_norm_mul_norm] by_cases hx : ‖x‖ = 0; · simp [hx] rw [div_mul_eq_div_div, mul_self_div_self] /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem angle_add_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : angle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by have hxy : ‖x + y‖ ^ 2 ≠ 0 := by rw [pow_two, norm_add_sq_eq_norm_sq_add_norm_sq_real h, ne_comm] refine ne_of_lt ?_ rcases h0 with (h0 | h0) · exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) · exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_eq_arcsin (div_nonneg (norm_nonneg _) (norm_nonneg _)), div_pow, one_sub_div hxy] nth_rw 1 [pow_two] rw [norm_add_sq_eq_norm_sq_add_norm_sq_real h, pow_two, add_sub_cancel_left, ← pow_two, ← div_pow, Real.sqrt_sq (div_nonneg (norm_nonneg _) (norm_nonneg _))] /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem angle_add_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by rw [angle_add_eq_arcsin_of_inner_eq_zero h (Or.inl h0), Real.arctan_eq_arcsin, ← div_mul_eq_div_div, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] nth_rw 3 [← Real.sqrt_sq (norm_nonneg x)] rw_mod_cast [← Real.sqrt_mul (sq_nonneg _), div_pow, pow_two, pow_two, mul_add, mul_one, mul_div, mul_comm (‖x‖ * ‖x‖), ← mul_div, div_self (mul_self_pos.2 (norm_ne_zero_iff.2 h0)).ne', mul_one] /-- An angle in a non-degenerate right-angled triangle is positive. -/ theorem angle_add_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : 0 < angle x (x + y) := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_pos, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] by_cases hx : x = 0; · simp [hx] rw [div_lt_one (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 hx)) (mul_self_nonneg _))), Real.lt_sqrt (norm_nonneg _), pow_two] simpa [hx] using h0 /-- An angle in a right-angled triangle is at most `π / 2`. -/ theorem angle_add_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x + y) ≤ π / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_le_pi_div_two] exact div_nonneg (norm_nonneg _) (norm_nonneg _) /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`. -/ theorem angle_add_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x + y) < π / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_lt_pi_div_two, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] exact div_pos (norm_pos_iff.2 h0) (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _))) /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x + y)) = ‖x‖ / ‖x + y‖ := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.cos_arccos (le_trans (by simp) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_le₀ _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_right (mul_self_nonneg _) /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : Real.sin (angle x (x + y)) = ‖y‖ / ‖x + y‖ := by rw [angle_add_eq_arcsin_of_inner_eq_zero h h0, Real.sin_arcsin (le_trans (by simp) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_le₀ _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_left (mul_self_nonneg _) /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.tan (angle x (x + y)) = ‖y‖ / ‖x‖ := by by_cases h0 : x = 0; · simp [h0] rw [angle_add_eq_arctan_of_inner_eq_zero h h0, Real.tan_arctan] /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x + y)) * ‖x + y‖ = ‖x‖ := by rw [cos_angle_add_of_inner_eq_zero h] by_cases hxy : ‖x + y‖ = 0 · have h' := norm_add_sq_eq_norm_sq_add_norm_sq_real h rw [hxy, zero_mul, eq_comm, add_eq_zero_iff_of_nonneg (mul_self_nonneg ‖x‖) (mul_self_nonneg ‖y‖), mul_self_eq_zero] at h' simp [h'.1] · exact div_mul_cancel₀ _ hxy /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.sin (angle x (x + y)) * ‖x + y‖ = ‖y‖ := by by_cases h0 : x = 0 ∧ y = 0; · simp [h0] rw [not_and_or] at h0 rw [sin_angle_add_of_inner_eq_zero h h0, div_mul_cancel₀] rw [← mul_self_ne_zero, norm_add_sq_eq_norm_sq_add_norm_sq_real h] refine (ne_of_lt ?_).symm rcases h0 with (h0 | h0) · exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) · exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : Real.tan (angle x (x + y)) * ‖x‖ = ‖y‖ := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) <;> simp [h0] /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : ‖x‖ / Real.cos (angle x (x + y)) = ‖x + y‖ := by rw [cos_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) · rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] · simp [h0] /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.sin (angle x (x + y)) = ‖x + y‖ := by rcases h0 with (h0 | h0); · simp [h0] rw [sin_angle_add_of_inner_eq_zero h (Or.inr h0), div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.tan (angle x (x + y)) = ‖x‖ := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) · simp [h0] · rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem angle_sub_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x - y) = Real.arccos (‖x‖ / ‖x - y‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arccos_of_inner_eq_zero h] /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem angle_sub_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : angle x (x - y) = Real.arcsin (‖y‖ / ‖x - y‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, angle_add_eq_arcsin_of_inner_eq_zero h h0, norm_neg] /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem angle_sub_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x - y) = Real.arctan (‖y‖ / ‖x‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arctan_of_inner_eq_zero h h0, norm_neg] /-- An angle in a non-degenerate right-angled triangle is positive, version subtracting vectors. -/ theorem angle_sub_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : 0 < angle x (x - y) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg] exact angle_add_pos_of_inner_eq_zero h h0 /-- An angle in a right-angled triangle is at most `π / 2`, version subtracting vectors. -/ theorem angle_sub_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x - y) ≤ π / 2 := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_le_pi_div_two_of_inner_eq_zero h /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`, version subtracting vectors. -/ theorem angle_sub_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x - y) < π / 2 := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_lt_pi_div_two_of_inner_eq_zero h h0 /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem cos_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x - y)) = ‖x‖ / ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, cos_angle_add_of_inner_eq_zero h] /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem sin_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : Real.sin (angle x (x - y)) = ‖y‖ / ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, sin_angle_add_of_inner_eq_zero h h0, norm_neg] /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem tan_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.tan (angle x (x - y)) = ‖y‖ / ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, tan_angle_add_of_inner_eq_zero h, norm_neg] /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ theorem cos_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x - y)) * ‖x - y‖ = ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, cos_angle_add_mul_norm_of_inner_eq_zero h] /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ theorem sin_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.sin (angle x (x - y)) * ‖x - y‖ = ‖y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, sin_angle_add_mul_norm_of_inner_eq_zero h, norm_neg] /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ theorem tan_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : Real.tan (angle x (x - y)) * ‖x‖ = ‖y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_eq_zero] at h0 rw [sub_eq_add_neg, tan_angle_add_mul_norm_of_inner_eq_zero h h0, norm_neg] /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_cos_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : ‖x‖ / Real.cos (angle x (x - y)) = ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_eq_zero] at h0 rw [sub_eq_add_neg, norm_div_cos_angle_add_of_inner_eq_zero h h0] /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_sin_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.sin (angle x (x - y)) = ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg, ← norm_neg, norm_div_sin_angle_add_of_inner_eq_zero h h0] /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ theorem norm_div_tan_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.tan (angle x (x - y)) = ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg, ← norm_neg, norm_div_tan_angle_add_of_inner_eq_zero h h0] end InnerProductGeometry namespace EuclideanGeometry open InnerProductGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- **Pythagorean theorem**, if-and-only-if angle-at-point form. -/ theorem dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two (p₁ p₂ p₃ : P) : dist p₁ p₃ * dist p₁ p₃ = dist p₁ p₂ * dist p₁ p₂ + dist p₃ p₂ * dist p₃ p₂ ↔ ∠ p₁ p₂ p₃ = π / 2 := by erw [dist_comm p₃ p₂, dist_eq_norm_vsub V p₁ p₃, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₂ p₃, ← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two, vsub_sub_vsub_cancel_right p₁, ← neg_vsub_eq_vsub_rev p₂ p₃, norm_neg] /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem angle_eq_arccos_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : ∠ p₂ p₃ p₁ = Real.arccos (dist p₃ p₂ / dist p₁ p₃) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arccos_of_inner_eq_zero h] /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem angle_eq_arcsin_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ ≠ p₂) : ∠ p₂ p₃ p₁ = Real.arcsin (dist p₁ p₂ / dist p₁ p₃) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, @ne_comm _ p₃, ← @vsub_ne_zero V _ _ _ p₂, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arcsin_of_inner_eq_zero h h0] /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem angle_eq_arctan_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₃ ≠ p₂) : ∠ p₂ p₃ p₁ = Real.arctan (dist p₁ p₂ / dist p₃ p₂) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arctan_of_inner_eq_zero h h0] /-- An angle in a non-degenerate right-angled triangle is positive. -/ theorem angle_pos_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ = p₂) : 0 < ∠ p₂ p₃ p₁ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, eq_comm, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_pos_of_inner_eq_zero h h0 /-- An angle in a right-angled triangle is at most `π / 2`. -/ theorem angle_le_pi_div_two_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : ∠ p₂ p₃ p₁ ≤ π / 2 := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_le_pi_div_two_of_inner_eq_zero h /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`. -/ theorem angle_lt_pi_div_two_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₃ ≠ p₂) : ∠ p₂ p₃ p₁ < π / 2 := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V] at h0 rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_lt_pi_div_two_of_inner_eq_zero h h0 /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.cos (∠ p₂ p₃ p₁) = dist p₃ p₂ / dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, cos_angle_add_of_inner_eq_zero h] /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ ≠ p₂) : Real.sin (∠ p₂ p₃ p₁) = dist p₁ p₂ / dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, @ne_comm _ p₃, ← @vsub_ne_zero V _ _ _ p₂, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, sin_angle_add_of_inner_eq_zero h h0] /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.tan (∠ p₂ p₃ p₁) = dist p₁ p₂ / dist p₃ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, tan_angle_add_of_inner_eq_zero h] /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.cos (∠ p₂ p₃ p₁) * dist p₁ p₃ = dist p₃ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, cos_angle_add_mul_norm_of_inner_eq_zero h] /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.sin (∠ p₂ p₃ p₁) * dist p₁ p₃ = dist p₁ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, sin_angle_add_mul_norm_of_inner_eq_zero h] /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ = p₂ ∨ p₃ ≠ p₂) : Real.tan (∠ p₂ p₃ p₁) * dist p₃ p₂ = dist p₁ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, tan_angle_add_mul_norm_of_inner_eq_zero h h0] /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem dist_div_cos_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ = p₂ ∨ p₃ ≠ p₂) : dist p₃ p₂ / Real.cos (∠ p₂ p₃ p₁) = dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, norm_div_cos_angle_add_of_inner_eq_zero h h0] /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem dist_div_sin_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ = p₂) : dist p₁ p₂ / Real.sin (∠ p₂ p₃ p₁) = dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [eq_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, norm_div_sin_angle_add_of_inner_eq_zero h h0] /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem dist_div_tan_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ = p₂) : dist p₁ p₂ / Real.tan (∠ p₂ p₃ p₁) = dist p₃ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [eq_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, norm_div_tan_angle_add_of_inner_eq_zero h h0] end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Unoriented/Conformal.lean
import Mathlib.Analysis.Calculus.Conformal.NormedSpace import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Angles and conformal maps This file proves that conformal maps preserve angles. -/ namespace InnerProductGeometry variable {E F : Type*} variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace ℝ E] [InnerProductSpace ℝ F] theorem IsConformalMap.preserves_angle {f' : E →L[ℝ] F} (h : IsConformalMap f') (u v : E) : angle (f' u) (f' v) = angle u v := by obtain ⟨c, hc, li, rfl⟩ := h exact (angle_smul_smul hc _ _).trans (li.angle_map _ _) /-- If a real differentiable map `f` is conformal at a point `x`, then it preserves the angles at that point. -/ theorem ConformalAt.preserves_angle {f : E → F} {x : E} {f' : E →L[ℝ] F} (h : HasFDerivAt f f' x) (H : ConformalAt f x) (u v : E) : angle (f' u) (f' v) = angle u v := let ⟨_, h₁, c⟩ := H h₁.unique h ▸ IsConformalMap.preserves_angle c u v end InnerProductGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Unoriented/Projection.lean
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine import Mathlib.Geometry.Euclidean.Projection /-! # Angles and orthogonal projection. This file proves lemmas relating to angles involving orthogonal projections. -/ namespace EuclideanGeometry variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] open scoped Real @[simp] lemma angle_self_orthogonalProjection (p : P) {p' : P} {s : AffineSubspace ℝ P} [s.direction.HasOrthogonalProjection] (h : p' ∈ s) : haveI : Nonempty s := ⟨p', h⟩ ∠ p (orthogonalProjection s p) p' = π / 2 := by haveI : Nonempty s := ⟨p', h⟩ rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two] exact Submodule.inner_left_of_mem_orthogonal (K := s.direction) (AffineSubspace.vsub_mem_direction h (orthogonalProjection_mem _)) (vsub_orthogonalProjection_mem_direction_orthogonal _ _) @[simp] lemma angle_orthogonalProjection_self (p : P) {p' : P} {s : AffineSubspace ℝ P} [s.direction.HasOrthogonalProjection] (h : p' ∈ s) : haveI : Nonempty s := ⟨p', h⟩ ∠ p' (orthogonalProjection s p) p = π / 2 := by rw [angle_comm, angle_self_orthogonalProjection p h] end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Angle/Unoriented/Affine.lean
import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic import Mathlib.Analysis.Normed.Affine.Isometry /-! # Angles between points This file defines unoriented angles in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.angle`, with notation `∠`, is the undirected angle determined by three points. ## TODO Prove the triangle inequality for the angle. -/ noncomputable section open Real RealInnerProductSpace namespace EuclideanGeometry open InnerProductGeometry variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] {p p₀ : P} /-- The undirected angle at `p₂` between the line segments to `p₁` and `p₃`. If either of those points equals `p₂`, this is π/2. Use `open scoped EuclideanGeometry` to access the `∠ p₁ p₂ p₃` notation. -/ nonrec def angle (p₁ p₂ p₃ : P) : ℝ := angle (p₁ -ᵥ p₂ : V) (p₃ -ᵥ p₂) @[inherit_doc] scoped notation "∠" => EuclideanGeometry.angle theorem continuousAt_angle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) : ContinuousAt (fun y : P × P × P => ∠ y.1 y.2.1 y.2.2) x := by let f : P × P × P → V × V := fun y => (y.1 -ᵥ y.2.1, y.2.2 -ᵥ y.2.1) have hf1 : (f x).1 ≠ 0 := by simp [f, hx12] have hf2 : (f x).2 ≠ 0 := by simp [f, hx32] exact (InnerProductGeometry.continuousAt_angle hf1 hf2).comp (by fun_prop) @[simp] theorem _root_.AffineIsometry.angle_map {V₂ P₂ : Type*} [NormedAddCommGroup V₂] [InnerProductSpace ℝ V₂] [MetricSpace P₂] [NormedAddTorsor V₂ P₂] (f : P →ᵃⁱ[ℝ] P₂) (p₁ p₂ p₃ : P) : ∠ (f p₁) (f p₂) (f p₃) = ∠ p₁ p₂ p₃ := by simp_rw [angle, ← AffineIsometry.map_vsub, LinearIsometry.angle_map] @[simp, norm_cast] theorem _root_.AffineSubspace.angle_coe {s : AffineSubspace ℝ P} (p₁ p₂ p₃ : s) : haveI : Nonempty s := ⟨p₁⟩ ∠ (p₁ : P) (p₂ : P) (p₃ : P) = ∠ p₁ p₂ p₃ := haveI : Nonempty s := ⟨p₁⟩ s.subtypeₐᵢ.angle_map p₁ p₂ p₃ /-- A homothety with a nonzero scale factor preserves angles. -/ @[simp] lemma angle_homothety (p p₁ p₂ p₃ : P) {r : ℝ} (h : r ≠ 0) : ∠ (AffineMap.homothety p r p₁) (AffineMap.homothety p r p₂) (AffineMap.homothety p r p₃) = ∠ p₁ p₂ p₃ := by simp_rw [angle, ← AffineMap.linearMap_vsub, AffineMap.homothety_linear, LinearMap.smul_apply, LinearMap.id_coe, id_eq] rcases h.lt_or_gt with hlt | hlt <;> simp [hlt, -neg_vsub_eq_vsub_rev] /-- Angles are translation invariant -/ @[simp] theorem angle_const_vadd (v : V) (p₁ p₂ p₃ : P) : ∠ (v +ᵥ p₁) (v +ᵥ p₂) (v +ᵥ p₃) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.constVAdd ℝ P v).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_vadd_const (v₁ v₂ v₃ : V) (p : P) : ∠ (v₁ +ᵥ p) (v₂ +ᵥ p) (v₃ +ᵥ p) = ∠ v₁ v₂ v₃ := (AffineIsometryEquiv.vaddConst ℝ p).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_const_vsub (p p₁ p₂ p₃ : P) : ∠ (p -ᵥ p₁) (p -ᵥ p₂) (p -ᵥ p₃) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.constVSub ℝ p).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_vsub_const (p₁ p₂ p₃ p : P) : ∠ (p₁ -ᵥ p) (p₂ -ᵥ p) (p₃ -ᵥ p) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.vaddConst ℝ p).symm.toAffineIsometry.angle_map _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_add_const (v₁ v₂ v₃ : V) (v : V) : ∠ (v₁ + v) (v₂ + v) (v₃ + v) = ∠ v₁ v₂ v₃ := angle_vadd_const _ _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_const_add (v : V) (v₁ v₂ v₃ : V) : ∠ (v + v₁) (v + v₂) (v + v₃) = ∠ v₁ v₂ v₃ := angle_const_vadd _ _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_sub_const (v₁ v₂ v₃ : V) (v : V) : ∠ (v₁ - v) (v₂ - v) (v₃ - v) = ∠ v₁ v₂ v₃ := by simpa only [vsub_eq_sub] using angle_vsub_const v₁ v₂ v₃ v /-- Angles in a vector space are invariant to inversion -/ @[simp] theorem angle_const_sub (v : V) (v₁ v₂ v₃ : V) : ∠ (v - v₁) (v - v₂) (v - v₃) = ∠ v₁ v₂ v₃ := by simpa only [vsub_eq_sub] using angle_const_vsub v v₁ v₂ v₃ /-- Angles in a vector space are invariant to inversion -/ @[simp] theorem angle_neg (v₁ v₂ v₃ : V) : ∠ (-v₁) (-v₂) (-v₃) = ∠ v₁ v₂ v₃ := by simpa only [zero_sub] using angle_const_sub 0 v₁ v₂ v₃ /-- The angle at a point does not depend on the order of the other two points. -/ nonrec theorem angle_comm (p₁ p₂ p₃ : P) : ∠ p₁ p₂ p₃ = ∠ p₃ p₂ p₁ := angle_comm _ _ /-- The angle at a point is nonnegative. -/ nonrec theorem angle_nonneg (p₁ p₂ p₃ : P) : 0 ≤ ∠ p₁ p₂ p₃ := angle_nonneg _ _ /-- The angle at a point is at most π. -/ nonrec theorem angle_le_pi (p₁ p₂ p₃ : P) : ∠ p₁ p₂ p₃ ≤ π := angle_le_pi _ _ /-- The angle ∠AAB at a point is always `π / 2`. -/ @[simp] lemma angle_self_left (p₀ p : P) : ∠ p₀ p₀ p = π / 2 := by unfold angle rw [vsub_self] exact angle_zero_left _ /-- The angle ∠ABB at a point is always `π / 2`. -/ @[simp] lemma angle_self_right (p₀ p : P) : ∠ p p₀ p₀ = π / 2 := by rw [angle_comm, angle_self_left] /-- The angle ∠ABA at a point is `0`, unless `A = B`. -/ theorem angle_self_of_ne (h : p ≠ p₀) : ∠ p p₀ p = 0 := angle_self <| vsub_ne_zero.2 h /-- If the angle ∠ABC at a point is π, the angle ∠BAC is 0. -/ theorem angle_eq_zero_of_angle_eq_pi_left {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : ∠ p₂ p₁ p₃ = 0 := by unfold angle at h rw [angle_eq_pi_iff] at h rcases h with ⟨hp₁p₂, ⟨r, ⟨hr, hpr⟩⟩⟩ unfold angle rw [angle_eq_zero_iff] rw [← neg_vsub_eq_vsub_rev, neg_ne_zero] at hp₁p₂ use hp₁p₂, -r + 1, add_pos (neg_pos_of_neg hr) zero_lt_one rw [add_smul, ← neg_vsub_eq_vsub_rev p₁ p₂, smul_neg] simp [← hpr] /-- If the angle ∠ABC at a point is π, the angle ∠BCA is 0. -/ theorem angle_eq_zero_of_angle_eq_pi_right {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : ∠ p₂ p₃ p₁ = 0 := by rw [angle_comm] at h exact angle_eq_zero_of_angle_eq_pi_left h /-- If ∠BCD = π, then ∠ABC = ∠ABD. -/ theorem angle_eq_angle_of_angle_eq_pi (p₁ : P) {p₂ p₃ p₄ : P} (h : ∠ p₂ p₃ p₄ = π) : ∠ p₁ p₂ p₃ = ∠ p₁ p₂ p₄ := by unfold angle at * rcases angle_eq_pi_iff.1 h with ⟨_, ⟨r, ⟨hr, hpr⟩⟩⟩ rw [eq_comm] convert angle_smul_right_of_pos (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) (add_pos (neg_pos_of_neg hr) zero_lt_one) rw [add_smul, ← neg_vsub_eq_vsub_rev p₂ p₃, smul_neg, neg_smul, ← hpr] simp /-- If ∠BCD = π, then ∠ACB + ∠ACD = π. -/ nonrec theorem angle_add_angle_eq_pi_of_angle_eq_pi (p₁ : P) {p₂ p₃ p₄ : P} (h : ∠ p₂ p₃ p₄ = π) : ∠ p₁ p₃ p₂ + ∠ p₁ p₃ p₄ = π := by unfold angle at h rw [angle_comm p₁ p₃ p₂, angle_comm p₁ p₃ p₄] unfold angle exact angle_add_angle_eq_pi_of_angle_eq_pi _ h /-- **Vertical Angles Theorem**: angles opposite each other, formed by two intersecting straight lines, are equal. -/ theorem angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi {p₁ p₂ p₃ p₄ p₅ : P} (hapc : ∠ p₁ p₅ p₃ = π) (hbpd : ∠ p₂ p₅ p₄ = π) : ∠ p₁ p₅ p₂ = ∠ p₃ p₅ p₄ := by linarith [angle_add_angle_eq_pi_of_angle_eq_pi p₁ hbpd, angle_comm p₄ p₅ p₁, angle_add_angle_eq_pi_of_angle_eq_pi p₄ hapc, angle_comm p₄ p₅ p₃] /-- If ∠ABC = π then dist A B ≠ 0. -/ theorem left_dist_ne_zero_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₁ p₂ ≠ 0 := by by_contra heq rw [dist_eq_zero] at heq rw [heq, angle_self_left] at h exact Real.pi_ne_zero (by linarith) /-- If ∠ABC = π then dist C B ≠ 0. -/ theorem right_dist_ne_zero_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₃ p₂ ≠ 0 := left_dist_ne_zero_of_angle_eq_pi <| (angle_comm _ _ _).trans h /-- If ∠ABC = π, then (dist A C) = (dist A B) + (dist B C). -/ theorem dist_eq_add_dist_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₁ p₃ = dist p₁ p₂ + dist p₃ p₂ := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_add_norm_of_angle_eq_pi h /-- If A ≠ B and C ≠ B then ∠ABC = π if and only if (dist A C) = (dist A B) + (dist B C). -/ theorem dist_eq_add_dist_iff_angle_eq_pi {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₃p₂ : p₃ ≠ p₂) : dist p₁ p₃ = dist p₁ p₂ + dist p₃ p₂ ↔ ∠ p₁ p₂ p₃ = π := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_add_norm_iff_angle_eq_pi (fun he => hp₁p₂ (vsub_eq_zero_iff_eq.1 he)) fun he => hp₃p₂ (vsub_eq_zero_iff_eq.1 he) /-- If ∠ABC = 0, then (dist A C) = abs ((dist A B) - (dist B C)). -/ theorem dist_eq_abs_sub_dist_of_angle_eq_zero {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = 0) : dist p₁ p₃ = |dist p₁ p₂ - dist p₃ p₂| := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_abs_sub_norm_of_angle_eq_zero h /-- If A ≠ B and C ≠ B then ∠ABC = 0 if and only if (dist A C) = abs ((dist A B) - (dist B C)). -/ theorem dist_eq_abs_sub_dist_iff_angle_eq_zero {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₃p₂ : p₃ ≠ p₂) : dist p₁ p₃ = |dist p₁ p₂ - dist p₃ p₂| ↔ ∠ p₁ p₂ p₃ = 0 := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_abs_sub_norm_iff_angle_eq_zero (fun he => hp₁p₂ (vsub_eq_zero_iff_eq.1 he)) fun he => hp₃p₂ (vsub_eq_zero_iff_eq.1 he) /-- If M is the midpoint of the segment AB, then ∠AMB = π. -/ theorem angle_midpoint_eq_pi (p₁ p₂ : P) (hp₁p₂ : p₁ ≠ p₂) : ∠ p₁ (midpoint ℝ p₁ p₂) p₂ = π := by simp only [angle, left_vsub_midpoint, invOf_eq_inv, right_vsub_midpoint, inv_pos, zero_lt_two, angle_smul_right_of_pos, angle_smul_left_of_pos] rw [← neg_vsub_eq_vsub_rev p₁ p₂] apply angle_self_neg_of_nonzero simpa only [ne_eq, vsub_eq_zero_iff_eq] /-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B then ∠CMA = π / 2. -/ theorem angle_left_midpoint_eq_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₃ p₁ = dist p₃ p₂) : ∠ p₃ (midpoint ℝ p₁ p₂) p₁ = π / 2 := by let m : P := midpoint ℝ p₁ p₂ have h1 : p₃ -ᵥ p₁ = p₃ -ᵥ m - (p₁ -ᵥ m) := (vsub_sub_vsub_cancel_right p₃ p₁ m).symm have h2 : p₃ -ᵥ p₂ = p₃ -ᵥ m + (p₁ -ᵥ m) := by rw [left_vsub_midpoint, ← midpoint_vsub_right, vsub_add_vsub_cancel] rw [dist_eq_norm_vsub V p₃ p₁, dist_eq_norm_vsub V p₃ p₂, h1, h2] at h exact (norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (p₃ -ᵥ m) (p₁ -ᵥ m)).mp h.symm /-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B then ∠CMB = π / 2. -/ theorem angle_right_midpoint_eq_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₃ p₁ = dist p₃ p₂) : ∠ p₃ (midpoint ℝ p₁ p₂) p₂ = π / 2 := by rw [midpoint_comm p₁ p₂, angle_left_midpoint_eq_pi_div_two_of_dist_eq h.symm] /-- If the second of three points is strictly between the other two, the angle at that point is π. -/ theorem _root_.Sbtw.angle₁₂₃_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₁ p₂ p₃ = π := by rw [angle, angle_eq_pi_iff] rcases h with ⟨⟨r, ⟨hr0, hr1⟩, hp₂⟩, hp₂p₁, hp₂p₃⟩ refine ⟨vsub_ne_zero.2 hp₂p₁.symm, -(1 - r) / r, ?_⟩ have hr0' : r ≠ 0 := by rintro rfl rw [← hp₂] at hp₂p₁ simp at hp₂p₁ have hr1' : r ≠ 1 := by rintro rfl rw [← hp₂] at hp₂p₃ simp at hp₂p₃ replace hr0 := hr0.lt_of_ne hr0'.symm replace hr1 := hr1.lt_of_ne hr1' refine ⟨div_neg_of_neg_of_pos (Left.neg_neg_iff.2 (sub_pos.2 hr1)) hr0, ?_⟩ rw [← hp₂, AffineMap.lineMap_apply, vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, vsub_self, zero_sub, smul_neg, smul_smul, div_mul_cancel₀ _ hr0', neg_smul, neg_neg, sub_eq_iff_eq_add, ← add_smul, sub_add_cancel, one_smul] /-- If the second of three points is strictly between the other two, the angle at that point (reversed) is π. -/ theorem _root_.Sbtw.angle₃₂₁_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₃ p₂ p₁ = π := by rw [← h.angle₁₂₃_eq_pi, angle_comm] /-- The angle between three points is π if and only if the second point is strictly between the other two. -/ theorem angle_eq_pi_iff_sbtw {p₁ p₂ p₃ : P} : ∠ p₁ p₂ p₃ = π ↔ Sbtw ℝ p₁ p₂ p₃ := by refine ⟨?_, fun h => h.angle₁₂₃_eq_pi⟩ rw [angle, angle_eq_pi_iff] rintro ⟨hp₁p₂, r, hr, hp₃p₂⟩ refine ⟨⟨1 / (1 - r), ⟨div_nonneg zero_le_one (sub_nonneg.2 (hr.le.trans zero_le_one)), (div_le_one (sub_pos.2 (hr.trans zero_lt_one))).2 ((le_sub_self_iff 1).2 hr.le)⟩, ?_⟩, (vsub_ne_zero.1 hp₁p₂).symm, ?_⟩ · rw [← eq_vadd_iff_vsub_eq] at hp₃p₂ rw [AffineMap.lineMap_apply, hp₃p₂, vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev p₂ p₁, smul_neg, ← neg_smul, smul_add, smul_smul, ← add_smul, eq_comm, eq_vadd_iff_vsub_eq] convert (one_smul ℝ (p₂ -ᵥ p₁)).symm field [(sub_pos.2 (hr.trans zero_lt_one)).ne.symm] · rw [ne_comm, ← @vsub_ne_zero V, hp₃p₂, smul_ne_zero_iff] exact ⟨hr.ne, hp₁p₂⟩ /-- If the second of three points is weakly between the other two, and not equal to the first, the angle at the first point is zero. -/ theorem _root_.Wbtw.angle₂₁₃_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₁ : p₂ ≠ p₁) : ∠ p₂ p₁ p₃ = 0 := by rw [angle, angle_eq_zero_iff] rcases h with ⟨r, ⟨hr0, hr1⟩, rfl⟩ have hr0' : r ≠ 0 := by rintro rfl simp at hp₂p₁ replace hr0 := hr0.lt_of_ne hr0'.symm refine ⟨vsub_ne_zero.2 hp₂p₁, r⁻¹, inv_pos.2 hr0, ?_⟩ rw [AffineMap.lineMap_apply, vadd_vsub_assoc, vsub_self, add_zero, smul_smul, inv_mul_cancel₀ hr0', one_smul] /-- If the second of three points is strictly between the other two, the angle at the first point is zero. -/ theorem _root_.Sbtw.angle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₂ p₁ p₃ = 0 := h.wbtw.angle₂₁₃_eq_zero_of_ne h.ne_left /-- If the second of three points is weakly between the other two, and not equal to the first, the angle at the first point (reversed) is zero. -/ theorem _root_.Wbtw.angle₃₁₂_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₁ : p₂ ≠ p₁) : ∠ p₃ p₁ p₂ = 0 := by rw [← h.angle₂₁₃_eq_zero_of_ne hp₂p₁, angle_comm] /-- If the second of three points is strictly between the other two, the angle at the first point (reversed) is zero. -/ theorem _root_.Sbtw.angle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₃ p₁ p₂ = 0 := h.wbtw.angle₃₁₂_eq_zero_of_ne h.ne_left /-- If the second of three points is weakly between the other two, and not equal to the third, the angle at the third point is zero. -/ theorem _root_.Wbtw.angle₂₃₁_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₃ : p₂ ≠ p₃) : ∠ p₂ p₃ p₁ = 0 := h.symm.angle₂₁₃_eq_zero_of_ne hp₂p₃ /-- If the second of three points is strictly between the other two, the angle at the third point is zero. -/ theorem _root_.Sbtw.angle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₂ p₃ p₁ = 0 := h.wbtw.angle₂₃₁_eq_zero_of_ne h.ne_right /-- If the second of three points is weakly between the other two, and not equal to the third, the angle at the third point (reversed) is zero. -/ theorem _root_.Wbtw.angle₁₃₂_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₃ : p₂ ≠ p₃) : ∠ p₁ p₃ p₂ = 0 := h.symm.angle₃₁₂_eq_zero_of_ne hp₂p₃ /-- If the second of three points is strictly between the other two, the angle at the third point (reversed) is zero. -/ theorem _root_.Sbtw.angle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₁ p₃ p₂ = 0 := h.wbtw.angle₁₃₂_eq_zero_of_ne h.ne_right /-- The angle between three points is zero if and only if one of the first and third points is weakly between the other two, and not equal to the second. -/ theorem angle_eq_zero_iff_ne_and_wbtw {p₁ p₂ p₃ : P} : ∠ p₁ p₂ p₃ = 0 ↔ p₁ ≠ p₂ ∧ Wbtw ℝ p₂ p₁ p₃ ∨ p₃ ≠ p₂ ∧ Wbtw ℝ p₂ p₃ p₁ := by constructor · rw [angle, angle_eq_zero_iff] rintro ⟨hp₁p₂, r, hr0, hp₃p₂⟩ rcases le_or_gt 1 r with (hr1 | hr1) · refine Or.inl ⟨vsub_ne_zero.1 hp₁p₂, r⁻¹, ⟨(inv_pos.2 hr0).le, inv_le_one_of_one_le₀ hr1⟩, ?_⟩ rw [AffineMap.lineMap_apply, hp₃p₂, smul_smul, inv_mul_cancel₀ hr0.ne.symm, one_smul, vsub_vadd] · refine Or.inr ⟨?_, r, ⟨hr0.le, hr1.le⟩, ?_⟩ · rw [← @vsub_ne_zero V, hp₃p₂, smul_ne_zero_iff] exact ⟨hr0.ne.symm, hp₁p₂⟩ · rw [AffineMap.lineMap_apply, ← hp₃p₂, vsub_vadd] · rintro (⟨hp₁p₂, h⟩ | ⟨hp₃p₂, h⟩) · exact h.angle₂₁₃_eq_zero_of_ne hp₁p₂ · exact h.angle₃₁₂_eq_zero_of_ne hp₃p₂ /-- The angle between three points is zero if and only if one of the first and third points is strictly between the other two, or those two points are equal but not equal to the second. -/ theorem angle_eq_zero_iff_eq_and_ne_or_sbtw {p₁ p₂ p₃ : P} : ∠ p₁ p₂ p₃ = 0 ↔ p₁ = p₃ ∧ p₁ ≠ p₂ ∨ Sbtw ℝ p₂ p₁ p₃ ∨ Sbtw ℝ p₂ p₃ p₁ := by rw [angle_eq_zero_iff_ne_and_wbtw] by_cases hp₁p₂ : p₁ = p₂; · simp [hp₁p₂] by_cases hp₁p₃ : p₁ = p₃; · simp [hp₁p₃] by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂] simp [hp₁p₂, hp₁p₃, Ne.symm hp₁p₃, Sbtw, hp₃p₂] /-- Three points are collinear if and only if the first or third point equals the second or the angle between them is 0 or π. -/ theorem collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi {p₁ p₂ p₃ : P} : Collinear ℝ ({p₁, p₂, p₃} : Set P) ↔ p₁ = p₂ ∨ p₃ = p₂ ∨ ∠ p₁ p₂ p₃ = 0 ∨ ∠ p₁ p₂ p₃ = π := by refine ⟨fun h => ?_, fun h => ?_⟩ · replace h := h.wbtw_or_wbtw_or_wbtw by_cases h₁₂ : p₁ = p₂ · exact Or.inl h₁₂ by_cases h₃₂ : p₃ = p₂ · exact Or.inr (Or.inl h₃₂) rw [or_iff_right h₁₂, or_iff_right h₃₂] rcases h with (h | h | h) · exact Or.inr (angle_eq_pi_iff_sbtw.2 ⟨h, Ne.symm h₁₂, Ne.symm h₃₂⟩) · exact Or.inl (h.angle₃₁₂_eq_zero_of_ne h₃₂) · exact Or.inl (h.angle₂₃₁_eq_zero_of_ne h₁₂) · rcases h with (rfl | rfl | h | h) · simpa using collinear_pair ℝ p₁ p₃ · simpa using collinear_pair ℝ p₁ p₃ · rw [angle_eq_zero_iff_ne_and_wbtw] at h rcases h with (⟨-, h⟩ | ⟨-, h⟩) · rw [Set.insert_comm] exact h.collinear · rw [Set.insert_comm, Set.pair_comm] exact h.collinear · rw [angle_eq_pi_iff_sbtw] at h exact h.wbtw.collinear /-- If the angle between three points is 0, they are collinear. -/ theorem collinear_of_angle_eq_zero {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = 0) : Collinear ℝ ({p₁, p₂, p₃} : Set P) := collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi.2 <| Or.inr <| Or.inr <| Or.inl h /-- If the angle between three points is π, they are collinear. -/ theorem collinear_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : Collinear ℝ ({p₁, p₂, p₃} : Set P) := collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi.2 <| Or.inr <| Or.inr <| Or.inr h /-- If three points are not collinear, the angle between them is nonzero. -/ theorem angle_ne_zero_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) : ∠ p₁ p₂ p₃ ≠ 0 := mt collinear_of_angle_eq_zero h /-- If three points are not collinear, the angle between them is not π. -/ theorem angle_ne_pi_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) : ∠ p₁ p₂ p₃ ≠ π := mt collinear_of_angle_eq_pi h /-- If three points are not collinear, the angle between them is positive. -/ theorem angle_pos_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) : 0 < ∠ p₁ p₂ p₃ := (angle_nonneg _ _ _).lt_of_ne (angle_ne_zero_of_not_collinear h).symm /-- If three points are not collinear, the angle between them is less than π. -/ theorem angle_lt_pi_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) : ∠ p₁ p₂ p₃ < π := (angle_le_pi _ _ _).lt_of_ne <| angle_ne_pi_of_not_collinear h /-- The cosine of the angle between three points is 1 if and only if the angle is 0. -/ nonrec theorem cos_eq_one_iff_angle_eq_zero {p₁ p₂ p₃ : P} : Real.cos (∠ p₁ p₂ p₃) = 1 ↔ ∠ p₁ p₂ p₃ = 0 := cos_eq_one_iff_angle_eq_zero /-- The cosine of the angle between three points is 0 if and only if the angle is π / 2. -/ nonrec theorem cos_eq_zero_iff_angle_eq_pi_div_two {p₁ p₂ p₃ : P} : Real.cos (∠ p₁ p₂ p₃) = 0 ↔ ∠ p₁ p₂ p₃ = π / 2 := cos_eq_zero_iff_angle_eq_pi_div_two /-- The cosine of the angle between three points is -1 if and only if the angle is π. -/ nonrec theorem cos_eq_neg_one_iff_angle_eq_pi {p₁ p₂ p₃ : P} : Real.cos (∠ p₁ p₂ p₃) = -1 ↔ ∠ p₁ p₂ p₃ = π := cos_eq_neg_one_iff_angle_eq_pi /-- The sine of the angle between three points is 0 if and only if the angle is 0 or π. -/ nonrec theorem sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi {p₁ p₂ p₃ : P} : Real.sin (∠ p₁ p₂ p₃) = 0 ↔ ∠ p₁ p₂ p₃ = 0 ∨ ∠ p₁ p₂ p₃ = π := sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi /-- The sine of the angle between three points is 1 if and only if the angle is π / 2. -/ nonrec theorem sin_eq_one_iff_angle_eq_pi_div_two {p₁ p₂ p₃ : P} : Real.sin (∠ p₁ p₂ p₃) = 1 ↔ ∠ p₁ p₂ p₃ = π / 2 := sin_eq_one_iff_angle_eq_pi_div_two /-- Three points are collinear if and only if the first or third point equals the second or the sine of the angle between three points is zero. -/ theorem collinear_iff_eq_or_eq_or_sin_eq_zero {p₁ p₂ p₃ : P} : Collinear ℝ ({p₁, p₂, p₃} : Set P) ↔ p₁ = p₂ ∨ p₃ = p₂ ∨ Real.sin (∠ p₁ p₂ p₃) = 0 := by rw [sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi, collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi] /-- If three points are not collinear, the sine of the angle between them is positive. -/ theorem sin_pos_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) : 0 < Real.sin (∠ p₁ p₂ p₃) := Real.sin_pos_of_pos_of_lt_pi (angle_pos_of_not_collinear h) (angle_lt_pi_of_not_collinear h) /-- If three points are not collinear, the sine of the angle between them is nonzero. -/ theorem sin_ne_zero_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) : Real.sin (∠ p₁ p₂ p₃) ≠ 0 := ne_of_gt (sin_pos_of_not_collinear h) /-- If the sine of the angle between three points is 0, they are collinear. -/ theorem collinear_of_sin_eq_zero {p₁ p₂ p₃ : P} (h : Real.sin (∠ p₁ p₂ p₃) = 0) : Collinear ℝ ({p₁, p₂, p₃} : Set P) := by revert h contrapose exact sin_ne_zero_of_not_collinear end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Sphere/SecondInter.lean
import Mathlib.Geometry.Euclidean.Sphere.Basic /-! # Second intersection of a sphere and a line This file defines and proves basic results about the second intersection of a sphere with a line through a point on that sphere. ## Main definitions * `EuclideanGeometry.Sphere.secondInter` is the second intersection of a sphere with a line through a point on that sphere. -/ noncomputable section open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The second intersection of a sphere with a line through a point on that sphere; that point if it is the only point of intersection of the line with the sphere. The intended use of this definition is when `p ∈ s`; the definition does not use `s.radius`, so in general it returns the second intersection with the sphere through `p` and with center `s.center`. -/ def Sphere.secondInter (s : Sphere P) (p : P) (v : V) : P := (-2 * ⟪v, p -ᵥ s.center⟫ / ⟪v, v⟫) • v +ᵥ p /-- The distance between `secondInter` and the center equals the distance between the original point and the center. -/ @[simp] theorem Sphere.secondInter_dist (s : Sphere P) (p : P) (v : V) : dist (s.secondInter p v) s.center = dist p s.center := by rw [Sphere.secondInter] by_cases hv : v = 0; · simp [hv] rw [dist_smul_vadd_eq_dist _ _ hv] exact Or.inr rfl /-- The point given by `secondInter` lies on the sphere. -/ @[simp] theorem Sphere.secondInter_mem {s : Sphere P} {p : P} (v : V) : s.secondInter p v ∈ s ↔ p ∈ s := by simp_rw [mem_sphere, Sphere.secondInter_dist] variable (V) in /-- If the vector is zero, `secondInter` gives the original point. -/ @[simp] theorem Sphere.secondInter_zero (s : Sphere P) (p : P) : s.secondInter p (0 : V) = p := by simp [Sphere.secondInter] /-- The point given by `secondInter` equals the original point if and only if the line is orthogonal to the radius vector. -/ theorem Sphere.secondInter_eq_self_iff {s : Sphere P} {p : P} {v : V} : s.secondInter p v = p ↔ ⟪v, p -ᵥ s.center⟫ = 0 := by refine ⟨fun hp => ?_, fun hp => ?_⟩ · by_cases hv : v = 0 · simp [hv] rwa [Sphere.secondInter, eq_comm, eq_vadd_iff_vsub_eq, vsub_self, eq_comm, smul_eq_zero, or_iff_left hv, div_eq_zero_iff, inner_self_eq_zero, or_iff_left hv, mul_eq_zero, or_iff_right (by simp : (-2 : ℝ) ≠ 0)] at hp · rw [Sphere.secondInter, hp, mul_zero, zero_div, zero_smul, zero_vadd] /-- A point on a line through a point on a sphere equals that point or `secondInter`. -/ theorem Sphere.eq_or_eq_secondInter_of_mem_mk'_span_singleton_iff_mem {s : Sphere P} {p : P} (hp : p ∈ s) {v : V} {p' : P} (hp' : p' ∈ AffineSubspace.mk' p (ℝ ∙ v)) : p' = p ∨ p' = s.secondInter p v ↔ p' ∈ s := by refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (h | h) · rwa [h] · rwa [h, Sphere.secondInter_mem] · rw [AffineSubspace.mem_mk', Submodule.mem_span_singleton] at hp' rcases hp' with ⟨r, hr⟩ rw [eq_comm, ← eq_vadd_iff_vsub_eq] at hr subst hr by_cases hv : v = 0 · simp [hv] rw [Sphere.secondInter] rw [mem_sphere] at h hp rw [← hp, dist_smul_vadd_eq_dist _ _ hv] at h rcases h with (h | h) <;> simp [h] /-- A point on a line through a point on a sphere and a second point equals that point or `secondInter`. -/ lemma Sphere.eq_or_eq_secondInter_iff_mem_of_mem_affineSpan_pair {s : Sphere P} {p q : P} (hp : p ∈ s) {p' : P} (hp' : p' ∈ line[ℝ, p, q]) : p' = p ∨ p' = s.secondInter p (q -ᵥ p) ↔ p' ∈ s := by convert s.eq_or_eq_secondInter_of_mem_mk'_span_singleton_iff_mem hp ?_ convert hp' rw [AffineSubspace.eq_iff_direction_eq_of_mem (AffineSubspace.self_mem_mk' p _) (left_mem_affineSpan_pair _ _ _)] simp [direction_affineSpan, vectorSpan_pair_rev] /-- `secondInter` is unchanged by multiplying the vector by a nonzero real. -/ @[simp] theorem Sphere.secondInter_smul (s : Sphere P) (p : P) (v : V) {r : ℝ} (hr : r ≠ 0) : s.secondInter p (r • v) = s.secondInter p v := by simp_rw [Sphere.secondInter, real_inner_smul_left, inner_smul_right, smul_smul, div_mul_eq_div_div] rw [mul_comm, ← mul_div_assoc, ← mul_div_assoc, mul_div_cancel_left₀ _ hr, mul_comm, mul_assoc, mul_div_cancel_left₀ _ hr, mul_comm] /-- `secondInter` is unchanged by negating the vector. -/ @[simp] theorem Sphere.secondInter_neg (s : Sphere P) (p : P) (v : V) : s.secondInter p (-v) = s.secondInter p v := by rw [← neg_one_smul ℝ v, s.secondInter_smul p v (by simp : (-1 : ℝ) ≠ 0)] /-- Applying `secondInter` twice returns the original point. -/ @[simp] theorem Sphere.secondInter_secondInter (s : Sphere P) (p : P) (v : V) : s.secondInter (s.secondInter p v) v = p := by by_cases hv : v = 0; · simp [hv] have hv' : ⟪v, v⟫ ≠ 0 := inner_self_ne_zero.2 hv simp only [Sphere.secondInter, vadd_vsub_assoc, vadd_vadd, inner_add_right, inner_smul_right, div_mul_cancel₀ _ hv'] rw [← @vsub_eq_zero_iff_eq V, vadd_vsub, ← add_smul, ← add_div] convert zero_smul ℝ _ convert zero_div (G₀ := ℝ) _ ring /-- If the vector passed to `secondInter` is given by a subtraction involving the point in `secondInter`, the result of `secondInter` may be expressed using `lineMap`. -/ theorem Sphere.secondInter_eq_lineMap (s : Sphere P) (p p' : P) : s.secondInter p (p' -ᵥ p) = AffineMap.lineMap p p' (-2 * ⟪p' -ᵥ p, p -ᵥ s.center⟫ / ⟪p' -ᵥ p, p' -ᵥ p⟫) := rfl /-- If the vector passed to `secondInter` is given by a subtraction involving the point in `secondInter`, the result lies in the span of the two points. -/ theorem Sphere.secondInter_vsub_mem_affineSpan (s : Sphere P) (p₁ p₂ : P) : s.secondInter p₁ (p₂ -ᵥ p₁) ∈ line[ℝ, p₁, p₂] := smul_vsub_vadd_mem_affineSpan_pair _ _ _ /-- If the vector passed to `secondInter` is given by a subtraction involving the point in `secondInter`, the three points are collinear. -/ theorem Sphere.secondInter_collinear (s : Sphere P) (p p' : P) : Collinear ℝ ({p, p', s.secondInter p (p' -ᵥ p)} : Set P) := by rw [Set.pair_comm, Set.insert_comm] exact (collinear_insert_iff_of_mem_affineSpan (s.secondInter_vsub_mem_affineSpan _ _)).2 (collinear_pair ℝ _ _) /-- If the vector passed to `secondInter` is given by a subtraction involving the point in `secondInter`, and the second point is not outside the sphere, the second point is weakly between the first point and the result of `secondInter`. -/ theorem Sphere.wbtw_secondInter {s : Sphere P} {p p' : P} (hp : p ∈ s) (hp' : dist p' s.center ≤ s.radius) : Wbtw ℝ p p' (s.secondInter p (p' -ᵥ p)) := by by_cases h : p' = p; · simp [h] refine wbtw_of_collinear_of_dist_center_le_radius (s.secondInter_collinear p p') hp hp' ((Sphere.secondInter_mem _).2 hp) ?_ intro he rw [eq_comm, Sphere.secondInter_eq_self_iff, ← neg_neg (p' -ᵥ p), inner_neg_left, neg_vsub_eq_vsub_rev, neg_eq_zero, eq_comm] at he exact ((inner_pos_or_eq_of_dist_le_radius hp hp').resolve_right (Ne.symm h)).ne he /-- If the vector passed to `secondInter` is given by a subtraction involving the point in `secondInter`, and the second point is inside the sphere, the second point is strictly between the first point and the result of `secondInter`. -/ theorem Sphere.sbtw_secondInter {s : Sphere P} {p p' : P} (hp : p ∈ s) (hp' : dist p' s.center < s.radius) : Sbtw ℝ p p' (s.secondInter p (p' -ᵥ p)) := by refine ⟨Sphere.wbtw_secondInter hp hp'.le, ?_, ?_⟩ · rintro rfl rw [mem_sphere] at hp simp [hp] at hp' · rintro h rw [h, mem_sphere.1 ((Sphere.secondInter_mem _).2 hp)] at hp' exact lt_irrefl _ hp' end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Sphere/Basic.lean
import Mathlib.Analysis.Convex.StrictConvexBetween import Mathlib.Analysis.InnerProductSpace.Convex import Mathlib.Analysis.Normed.Affine.Convex import Mathlib.Geometry.Euclidean.Basic /-! # Spheres This file defines and proves basic results about spheres and cospherical sets of points in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.Sphere` bundles a `center` and a `radius`. * `EuclideanGeometry.Sphere.IsDiameter` is the property of two points being the two endpoints of a diameter of a sphere. * `EuclideanGeometry.Sphere.ofDiameter` constructs the sphere on a given diameter. * `EuclideanGeometry.Cospherical` is the property of a set of points being equidistant from some point. * `EuclideanGeometry.Concyclic` is the property of a set of points being cospherical and coplanar. -/ noncomputable section open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} (P : Type*) open Module /-- A `Sphere P` bundles a `center` and `radius`. This definition does not require the radius to be positive; that should be given as a hypothesis to lemmas that require it. -/ @[ext] structure Sphere [MetricSpace P] where /-- center of this sphere -/ center : P /-- radius of the sphere; not required to be positive -/ radius : ℝ variable {P} section MetricSpace variable [MetricSpace P] instance [Nonempty P] : Nonempty (Sphere P) := ⟨⟨Classical.arbitrary P, 0⟩⟩ instance : Coe (Sphere P) (Set P) := ⟨fun s => Metric.sphere s.center s.radius⟩ instance : Membership P (Sphere P) := ⟨fun s p => p ∈ (s : Set P)⟩ theorem Sphere.mk_center (c : P) (r : ℝ) : (⟨c, r⟩ : Sphere P).center = c := rfl theorem Sphere.mk_radius (c : P) (r : ℝ) : (⟨c, r⟩ : Sphere P).radius = r := rfl @[simp] theorem Sphere.mk_center_radius (s : Sphere P) : (⟨s.center, s.radius⟩ : Sphere P) = s := by ext <;> rfl @[simp] theorem Sphere.coe_mk (c : P) (r : ℝ) : ↑(⟨c, r⟩ : Sphere P) = Metric.sphere c r := rfl -- simp-normal form is `Sphere.mem_coe'` theorem Sphere.mem_coe {p : P} {s : Sphere P} : p ∈ (s : Set P) ↔ p ∈ s := Iff.rfl @[simp] theorem Sphere.mem_coe' {p : P} {s : Sphere P} : dist p s.center = s.radius ↔ p ∈ s := Iff.rfl theorem mem_sphere {p : P} {s : Sphere P} : p ∈ s ↔ dist p s.center = s.radius := Iff.rfl theorem mem_sphere' {p : P} {s : Sphere P} : p ∈ s ↔ dist s.center p = s.radius := Metric.mem_sphere' theorem subset_sphere {ps : Set P} {s : Sphere P} : ps ⊆ s ↔ ∀ p ∈ ps, p ∈ s := Iff.rfl theorem dist_of_mem_subset_sphere {p : P} {ps : Set P} {s : Sphere P} (hp : p ∈ ps) (hps : ps ⊆ (s : Set P)) : dist p s.center = s.radius := mem_sphere.1 (Sphere.mem_coe.1 (Set.mem_of_mem_of_subset hp hps)) theorem dist_of_mem_subset_mk_sphere {p c : P} {ps : Set P} {r : ℝ} (hp : p ∈ ps) (hps : ps ⊆ ↑(⟨c, r⟩ : Sphere P)) : dist p c = r := dist_of_mem_subset_sphere hp hps theorem Sphere.ne_iff {s₁ s₂ : Sphere P} : s₁ ≠ s₂ ↔ s₁.center ≠ s₂.center ∨ s₁.radius ≠ s₂.radius := by rw [← not_and_or, ← Sphere.ext_iff] theorem Sphere.center_eq_iff_eq_of_mem {s₁ s₂ : Sphere P} {p : P} (hs₁ : p ∈ s₁) (hs₂ : p ∈ s₂) : s₁.center = s₂.center ↔ s₁ = s₂ := by refine ⟨fun h => Sphere.ext h ?_, fun h => h ▸ rfl⟩ rw [mem_sphere] at hs₁ hs₂ rw [← hs₁, ← hs₂, h] theorem Sphere.center_ne_iff_ne_of_mem {s₁ s₂ : Sphere P} {p : P} (hs₁ : p ∈ s₁) (hs₂ : p ∈ s₂) : s₁.center ≠ s₂.center ↔ s₁ ≠ s₂ := (Sphere.center_eq_iff_eq_of_mem hs₁ hs₂).not theorem dist_center_eq_dist_center_of_mem_sphere {p₁ p₂ : P} {s : Sphere P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) : dist p₁ s.center = dist p₂ s.center := by rw [mem_sphere.1 hp₁, mem_sphere.1 hp₂] theorem dist_center_eq_dist_center_of_mem_sphere' {p₁ p₂ : P} {s : Sphere P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) : dist s.center p₁ = dist s.center p₂ := by rw [mem_sphere'.1 hp₁, mem_sphere'.1 hp₂] lemma Sphere.radius_nonneg_of_mem {s : Sphere P} {p : P} (h : p ∈ s) : 0 ≤ s.radius := Metric.nonneg_of_mem_sphere h @[simp] lemma Sphere.center_mem_iff {s : Sphere P} : s.center ∈ s ↔ s.radius = 0 := by simp [mem_sphere, eq_comm] /-- A set of points is cospherical if they are equidistant from some point. In two dimensions, this is the same thing as being concyclic. -/ def Cospherical (ps : Set P) : Prop := ∃ (center : P) (radius : ℝ), ∀ p ∈ ps, dist p center = radius /-- The definition of `Cospherical`. -/ theorem cospherical_def (ps : Set P) : Cospherical ps ↔ ∃ (center : P) (radius : ℝ), ∀ p ∈ ps, dist p center = radius := Iff.rfl /-- A set of points is cospherical if and only if they lie in some sphere. -/ theorem cospherical_iff_exists_sphere {ps : Set P} : Cospherical ps ↔ ∃ s : Sphere P, ps ⊆ (s : Set P) := by refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ⟨c, r, h⟩ exact ⟨⟨c, r⟩, h⟩ · rcases h with ⟨s, h⟩ exact ⟨s.center, s.radius, h⟩ /-- The set of points in a sphere is cospherical. -/ theorem Sphere.cospherical (s : Sphere P) : Cospherical (s : Set P) := cospherical_iff_exists_sphere.2 ⟨s, Set.Subset.rfl⟩ /-- A subset of a cospherical set is cospherical. -/ theorem Cospherical.subset {ps₁ ps₂ : Set P} (hs : ps₁ ⊆ ps₂) (hc : Cospherical ps₂) : Cospherical ps₁ := by rcases hc with ⟨c, r, hcr⟩ exact ⟨c, r, fun p hp => hcr p (hs hp)⟩ /-- The empty set is cospherical. -/ theorem cospherical_empty [Nonempty P] : Cospherical (∅ : Set P) := let ⟨p⟩ := ‹Nonempty P› ⟨p, 0, fun _ => False.elim⟩ /-- A single point is cospherical. -/ theorem cospherical_singleton (p : P) : Cospherical ({p} : Set P) := by use p simp end MetricSpace section NormedSpace variable [NormedAddCommGroup V] [NormedSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] lemma Sphere.nonempty_iff [Nontrivial V] {s : Sphere P} : (s : Set P).Nonempty ↔ 0 ≤ s.radius := by refine ⟨fun ⟨p, hp⟩ ↦ radius_nonneg_of_mem hp, fun h ↦ ?_⟩ obtain ⟨v, hv⟩ := (NormedSpace.sphere_nonempty (x := (0 : V)) (r := s.radius)).2 h refine ⟨v +ᵥ s.center, ?_⟩ simpa [mem_sphere] using hv include V in /-- Two points are cospherical. -/ theorem cospherical_pair (p₁ p₂ : P) : Cospherical ({p₁, p₂} : Set P) := ⟨midpoint ℝ p₁ p₂, ‖(2 : ℝ)‖⁻¹ * dist p₁ p₂, by rintro p (rfl | rfl | _) · rw [dist_comm, dist_midpoint_left (𝕜 := ℝ)] · rw [dist_comm, dist_midpoint_right (𝕜 := ℝ)]⟩ /-- A set of points is concyclic if it is cospherical and coplanar. (Most results are stated directly in terms of `Cospherical` instead of using `Concyclic`.) -/ structure Concyclic (ps : Set P) : Prop where Cospherical : Cospherical ps Coplanar : Coplanar ℝ ps /-- A subset of a concyclic set is concyclic. -/ theorem Concyclic.subset {ps₁ ps₂ : Set P} (hs : ps₁ ⊆ ps₂) (h : Concyclic ps₂) : Concyclic ps₁ := ⟨h.1.subset hs, h.2.subset hs⟩ /-- The empty set is concyclic. -/ theorem concyclic_empty : Concyclic (∅ : Set P) := ⟨cospherical_empty, coplanar_empty ℝ P⟩ /-- A single point is concyclic. -/ theorem concyclic_singleton (p : P) : Concyclic ({p} : Set P) := ⟨cospherical_singleton p, coplanar_singleton ℝ p⟩ /-- Two points are concyclic. -/ theorem concyclic_pair (p₁ p₂ : P) : Concyclic ({p₁, p₂} : Set P) := ⟨cospherical_pair p₁ p₂, coplanar_pair ℝ p₁ p₂⟩ namespace Sphere /-- `s.IsDiameter p₁ p₂` says that `p₁` and `p₂` are the two endpoints of a diameter of `s`. -/ structure IsDiameter (s : Sphere P) (p₁ p₂ : P) : Prop where left_mem : p₁ ∈ s midpoint_eq_center : midpoint ℝ p₁ p₂ = s.center variable {s : Sphere P} {p₁ p₂ p₃ : P} lemma IsDiameter.right_mem (h : s.IsDiameter p₁ p₂) : p₂ ∈ s := by rw [mem_sphere, ← mem_sphere.1 h.left_mem, ← h.midpoint_eq_center, dist_left_midpoint_eq_dist_right_midpoint] protected lemma IsDiameter.symm (h : s.IsDiameter p₁ p₂) : s.IsDiameter p₂ p₁ := ⟨h.right_mem, midpoint_comm (R := ℝ) p₁ p₂ ▸ h.midpoint_eq_center⟩ lemma isDiameter_comm : s.IsDiameter p₁ p₂ ↔ s.IsDiameter p₂ p₁ := ⟨IsDiameter.symm, IsDiameter.symm⟩ lemma isDiameter_iff_left_mem_and_midpoint_eq_center : s.IsDiameter p₁ p₂ ↔ p₁ ∈ s ∧ midpoint ℝ p₁ p₂ = s.center := ⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩ lemma isDiameter_iff_right_mem_and_midpoint_eq_center : s.IsDiameter p₁ p₂ ↔ p₂ ∈ s ∧ midpoint ℝ p₁ p₂ = s.center := ⟨fun h ↦ ⟨h.right_mem, h.2⟩, fun h ↦ IsDiameter.symm ⟨h.1, midpoint_comm (R := ℝ) p₁ p₂ ▸ h.2⟩⟩ lemma IsDiameter.pointReflection_center_left (h : s.IsDiameter p₁ p₂) : Equiv.pointReflection s.center p₁ = p₂ := by rw [← h.midpoint_eq_center, Equiv.pointReflection_midpoint_left] lemma IsDiameter.pointReflection_center_right (h : s.IsDiameter p₁ p₂) : Equiv.pointReflection s.center p₂ = p₁ := by rw [← h.midpoint_eq_center, Equiv.pointReflection_midpoint_right] lemma isDiameter_iff_left_mem_and_pointReflection_center_left : s.IsDiameter p₁ p₂ ↔ p₁ ∈ s ∧ Equiv.pointReflection s.center p₁ = p₂ := ⟨fun h ↦ ⟨h.1, h.pointReflection_center_left⟩, fun h ↦ ⟨h.1, by simp [← h.2]⟩⟩ lemma isDiameter_iff_right_mem_and_pointReflection_center_right : s.IsDiameter p₁ p₂ ↔ p₂ ∈ s ∧ Equiv.pointReflection s.center p₂ = p₁ := by rw [isDiameter_comm, isDiameter_iff_left_mem_and_pointReflection_center_left] lemma IsDiameter.right_eq_of_isDiameter (h₁₂ : s.IsDiameter p₁ p₂) (h₁₃ : s.IsDiameter p₁ p₃) : p₂ = p₃ := by rw [← h₁₂.pointReflection_center_left, ← h₁₃.pointReflection_center_left] lemma IsDiameter.left_eq_of_isDiameter (h₁₃ : s.IsDiameter p₁ p₃) (h₂₃ : s.IsDiameter p₂ p₃) : p₁ = p₂ := by rw [← h₁₃.pointReflection_center_right, ← h₂₃.pointReflection_center_right] lemma IsDiameter.dist_left_right (h : s.IsDiameter p₁ p₂) : dist p₁ p₂ = 2 * s.radius := by rw [← mem_sphere.1 h.left_mem, ← h.midpoint_eq_center, dist_left_midpoint] simp lemma IsDiameter.dist_left_right_div_two (h : s.IsDiameter p₁ p₂) : (dist p₁ p₂) / 2 = s.radius := by simp [h.dist_left_right] lemma IsDiameter.left_eq_right_iff (h : s.IsDiameter p₁ p₂) : p₁ = p₂ ↔ s.radius = 0 := by rw [← dist_eq_zero, h.dist_left_right] simp lemma IsDiameter.left_ne_right_iff_radius_ne_zero (h : s.IsDiameter p₁ p₂) : p₁ ≠ p₂ ↔ s.radius ≠ 0 := h.left_eq_right_iff.not lemma IsDiameter.left_ne_right_iff_radius_pos (h : s.IsDiameter p₁ p₂) : p₁ ≠ p₂ ↔ 0 < s.radius := by rw [h.left_ne_right_iff_radius_ne_zero, lt_iff_le_and_ne] simp [radius_nonneg_of_mem h.left_mem, eq_comm] protected lemma IsDiameter.wbtw (h : s.IsDiameter p₁ p₂) : Wbtw ℝ p₁ s.center p₂ := by rw [← h.midpoint_eq_center] exact wbtw_midpoint _ _ _ protected lemma IsDiameter.sbtw (h : s.IsDiameter p₁ p₂) (hr : s.radius ≠ 0) : Sbtw ℝ p₁ s.center p₂ := by rw [← h.midpoint_eq_center] exact sbtw_midpoint_of_ne _ (h.left_ne_right_iff_radius_ne_zero.2 hr) /-- Construct the sphere with the given diameter. -/ protected def ofDiameter (p₁ p₂ : P) : Sphere P := ⟨midpoint ℝ p₁ p₂, (dist p₁ p₂) / 2⟩ lemma isDiameter_ofDiameter (p₁ p₂ : P) : (Sphere.ofDiameter p₁ p₂).IsDiameter p₁ p₂ := ⟨by simp [Sphere.ofDiameter, mem_sphere, inv_mul_eq_div], rfl⟩ lemma IsDiameter.ofDiameter_eq (h : s.IsDiameter p₁ p₂) : .ofDiameter p₁ p₂ = s := by ext · simp [Sphere.ofDiameter, h.midpoint_eq_center] · simp [Sphere.ofDiameter, ← h.dist_left_right_div_two] lemma isDiameter_iff_ofDiameter_eq : s.IsDiameter p₁ p₂ ↔ .ofDiameter p₁ p₂ = s := ⟨IsDiameter.ofDiameter_eq, by rintro rfl; exact isDiameter_ofDiameter _ _⟩ end Sphere end NormedSpace section EuclideanSpace variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- Any three points in a cospherical set are affinely independent. -/ theorem Cospherical.affineIndependent {s : Set P} (hs : Cospherical s) {p : Fin 3 → P} (hps : Set.range p ⊆ s) (hpi : Function.Injective p) : AffineIndependent ℝ p := by rw [affineIndependent_iff_not_collinear] intro hc rw [collinear_iff_of_mem (Set.mem_range_self (0 : Fin 3))] at hc rcases hc with ⟨v, hv⟩ rw [Set.forall_mem_range] at hv have hv0 : v ≠ 0 := by intro h have he : p 1 = p 0 := by simpa [h] using hv 1 exact (by decide : (1 : Fin 3) ≠ 0) (hpi he) rcases hs with ⟨c, r, hs⟩ have hs' := fun i => hs (p i) (Set.mem_of_mem_of_subset (Set.mem_range_self _) hps) choose f hf using hv have hsd : ∀ i, dist (f i • v +ᵥ p 0) c = r := by intro i rw [← hf] exact hs' i have hf0 : f 0 = 0 := by have hf0' := hf 0 rw [eq_comm, ← @vsub_eq_zero_iff_eq V, vadd_vsub, smul_eq_zero] at hf0' simpa [hv0] using hf0' have hfi : Function.Injective f := by intro i j h have hi := hf i rw [h, ← hf j] at hi exact hpi hi simp_rw [← hsd 0, hf0, zero_smul, zero_vadd, dist_smul_vadd_eq_dist (p 0) c hv0] at hsd have hfn0 : ∀ i, i ≠ 0 → f i ≠ 0 := fun i => (hfi.ne_iff' hf0).2 have hfn0' : ∀ i, i ≠ 0 → f i = -2 * ⟪v, p 0 -ᵥ c⟫ / ⟪v, v⟫ := by intro i hi have hsdi := hsd i simpa [hfn0, hi] using hsdi have hf12 : f 1 = f 2 := by rw [hfn0' 1 (by decide), hfn0' 2 (by decide)] exact (by decide : (1 : Fin 3) ≠ 2) (hfi hf12) /-- Any three points in a cospherical set are affinely independent. -/ theorem Cospherical.affineIndependent_of_mem_of_ne {s : Set P} (hs : Cospherical s) {p₁ p₂ p₃ : P} (h₁ : p₁ ∈ s) (h₂ : p₂ ∈ s) (h₃ : p₃ ∈ s) (h₁₂ : p₁ ≠ p₂) (h₁₃ : p₁ ≠ p₃) (h₂₃ : p₂ ≠ p₃) : AffineIndependent ℝ ![p₁, p₂, p₃] := by refine hs.affineIndependent ?_ ?_ · simp [h₁, h₂, h₃, Set.insert_subset_iff] · erw [Fin.cons_injective_iff, Fin.cons_injective_iff] simp [h₁₂, h₁₃, h₂₃, Function.Injective, eq_iff_true_of_subsingleton] /-- The three points of a cospherical set are affinely independent. -/ theorem Cospherical.affineIndependent_of_ne {p₁ p₂ p₃ : P} (hs : Cospherical ({p₁, p₂, p₃} : Set P)) (h₁₂ : p₁ ≠ p₂) (h₁₃ : p₁ ≠ p₃) (h₂₃ : p₂ ≠ p₃) : AffineIndependent ℝ ![p₁, p₂, p₃] := hs.affineIndependent_of_mem_of_ne (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_insert _ _)) (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _))) h₁₂ h₁₃ h₂₃ /-- Suppose that `p₁` and `p₂` lie in spheres `s₁` and `s₂`. Then the vector between the centers of those spheres is orthogonal to that between `p₁` and `p₂`; this is a version of `inner_vsub_vsub_of_dist_eq_of_dist_eq` for bundled spheres. (In two dimensions, this says that the diagonals of a kite are orthogonal.) -/ theorem inner_vsub_vsub_of_mem_sphere_of_mem_sphere {p₁ p₂ : P} {s₁ s₂ : Sphere P} (hp₁s₁ : p₁ ∈ s₁) (hp₂s₁ : p₂ ∈ s₁) (hp₁s₂ : p₁ ∈ s₂) (hp₂s₂ : p₂ ∈ s₂) : ⟪s₂.center -ᵥ s₁.center, p₂ -ᵥ p₁⟫ = 0 := inner_vsub_vsub_of_dist_eq_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere hp₁s₁ hp₂s₁) (dist_center_eq_dist_center_of_mem_sphere hp₁s₂ hp₂s₂) /-- Two spheres intersect in at most two points in a two-dimensional subspace containing their centers; this is a version of `eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two` for bundled spheres. -/ theorem eq_of_mem_sphere_of_mem_sphere_of_mem_of_finrank_eq_two {s : AffineSubspace ℝ P} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = 2) {s₁ s₂ : Sphere P} {p₁ p₂ p : P} (hs₁ : s₁.center ∈ s) (hs₂ : s₂.center ∈ s) (hp₁s : p₁ ∈ s) (hp₂s : p₂ ∈ s) (hps : p ∈ s) (hs : s₁ ≠ s₂) (hp : p₁ ≠ p₂) (hp₁s₁ : p₁ ∈ s₁) (hp₂s₁ : p₂ ∈ s₁) (hps₁ : p ∈ s₁) (hp₁s₂ : p₁ ∈ s₂) (hp₂s₂ : p₂ ∈ s₂) (hps₂ : p ∈ s₂) : p = p₁ ∨ p = p₂ := eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two hd hs₁ hs₂ hp₁s hp₂s hps ((Sphere.center_ne_iff_ne_of_mem hps₁ hps₂).2 hs) hp hp₁s₁ hp₂s₁ hps₁ hp₁s₂ hp₂s₂ hps₂ /-- Two spheres intersect in at most two points in two-dimensional space; this is a version of `eq_of_dist_eq_of_dist_eq_of_finrank_eq_two` for bundled spheres. -/ theorem eq_of_mem_sphere_of_mem_sphere_of_finrank_eq_two [FiniteDimensional ℝ V] (hd : finrank ℝ V = 2) {s₁ s₂ : Sphere P} {p₁ p₂ p : P} (hs : s₁ ≠ s₂) (hp : p₁ ≠ p₂) (hp₁s₁ : p₁ ∈ s₁) (hp₂s₁ : p₂ ∈ s₁) (hps₁ : p ∈ s₁) (hp₁s₂ : p₁ ∈ s₂) (hp₂s₂ : p₂ ∈ s₂) (hps₂ : p ∈ s₂) : p = p₁ ∨ p = p₂ := eq_of_dist_eq_of_dist_eq_of_finrank_eq_two hd ((Sphere.center_ne_iff_ne_of_mem hps₁ hps₂).2 hs) hp hp₁s₁ hp₂s₁ hps₁ hp₁s₂ hp₂s₂ hps₂ /-- Given a point on a sphere and a point not outside it, the inner product between the difference of those points and the radius vector is positive unless the points are equal. -/ theorem inner_pos_or_eq_of_dist_le_radius {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : dist p₂ s.center ≤ s.radius) : 0 < ⟪p₁ -ᵥ p₂, p₁ -ᵥ s.center⟫ ∨ p₁ = p₂ := by by_cases h : p₁ = p₂; · exact Or.inr h refine Or.inl ?_ rw [mem_sphere] at hp₁ rw [← vsub_sub_vsub_cancel_right p₁ p₂ s.center, inner_sub_left, real_inner_self_eq_norm_mul_norm, sub_pos] refine lt_of_le_of_ne ((real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right ?_ (norm_nonneg _))) ?_ · rwa [← dist_eq_norm_vsub, ← dist_eq_norm_vsub, hp₁] · rcases hp₂.lt_or_eq with (hp₂' | hp₂') · refine ((real_inner_le_norm _ _).trans_lt (mul_lt_mul_of_pos_right ?_ ?_)).ne · rwa [← hp₁, @dist_eq_norm_vsub V, @dist_eq_norm_vsub V] at hp₂' · rw [norm_pos_iff, vsub_ne_zero] rintro rfl rw [← hp₁] at hp₂' refine (dist_nonneg.not_gt : ¬dist p₂ s.center < 0) ?_ simpa using hp₂' · rw [← hp₁, @dist_eq_norm_vsub V, @dist_eq_norm_vsub V] at hp₂' nth_rw 1 [← hp₂'] rw [Ne, inner_eq_norm_mul_iff_real, hp₂', ← sub_eq_zero, ← smul_sub, vsub_sub_vsub_cancel_right, ← Ne, smul_ne_zero_iff, vsub_ne_zero, and_iff_left (Ne.symm h), norm_ne_zero_iff, vsub_ne_zero] rintro rfl refine h (Eq.symm ?_) simpa using hp₂' /-- Given a point on a sphere and a point not outside it, the inner product between the difference of those points and the radius vector is nonnegative. -/ theorem inner_nonneg_of_dist_le_radius {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : dist p₂ s.center ≤ s.radius) : 0 ≤ ⟪p₁ -ᵥ p₂, p₁ -ᵥ s.center⟫ := by rcases inner_pos_or_eq_of_dist_le_radius hp₁ hp₂ with (h | rfl) · exact h.le · simp /-- Given a point on a sphere and a point inside it, the inner product between the difference of those points and the radius vector is positive. -/ theorem inner_pos_of_dist_lt_radius {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : dist p₂ s.center < s.radius) : 0 < ⟪p₁ -ᵥ p₂, p₁ -ᵥ s.center⟫ := by by_cases h : p₁ = p₂ · rw [h, mem_sphere] at hp₁ exact False.elim (hp₂.ne hp₁) exact (inner_pos_or_eq_of_dist_le_radius hp₁ hp₂.le).resolve_right h /-- Given three collinear points, two on a sphere and one not outside it, the one not outside it is weakly between the other two points. -/ theorem wbtw_of_collinear_of_dist_center_le_radius {s : Sphere P} {p₁ p₂ p₃ : P} (h : Collinear ℝ ({p₁, p₂, p₃} : Set P)) (hp₁ : p₁ ∈ s) (hp₂ : dist p₂ s.center ≤ s.radius) (hp₃ : p₃ ∈ s) (hp₁p₃ : p₁ ≠ p₃) : Wbtw ℝ p₁ p₂ p₃ := h.wbtw_of_dist_eq_of_dist_le hp₁ hp₂ hp₃ hp₁p₃ /-- Given three collinear points, two on a sphere and one inside it, the one inside it is strictly between the other two points. -/ theorem sbtw_of_collinear_of_dist_center_lt_radius {s : Sphere P} {p₁ p₂ p₃ : P} (h : Collinear ℝ ({p₁, p₂, p₃} : Set P)) (hp₁ : p₁ ∈ s) (hp₂ : dist p₂ s.center < s.radius) (hp₃ : p₃ ∈ s) (hp₁p₃ : p₁ ≠ p₃) : Sbtw ℝ p₁ p₂ p₃ := h.sbtw_of_dist_eq_of_dist_lt hp₁ hp₂ hp₃ hp₁p₃ namespace Sphere variable {s : Sphere P} {p₁ p₂ : P} lemma isDiameter_iff_mem_and_mem_and_dist : s.IsDiameter p₁ p₂ ↔ p₁ ∈ s ∧ p₂ ∈ s ∧ dist p₁ p₂ = 2 * s.radius := by refine ⟨fun h ↦ ⟨h.left_mem, h.right_mem, h.dist_left_right⟩, fun ⟨h₁, h₂, hr⟩ ↦ ⟨h₁, ?_⟩⟩ rw [midpoint_eq_iff, AffineEquiv.pointReflection_apply, eq_comm, eq_vadd_iff_vsub_eq] apply eq_of_norm_eq_of_norm_add_eq · simp_rw [← dist_eq_norm_vsub, mem_sphere'.1 h₁, mem_sphere.1 h₂] · simp_rw [vsub_add_vsub_cancel, ← dist_eq_norm_vsub, mem_sphere'.1 h₁, mem_sphere.1 h₂] rw [dist_comm, hr, two_mul] lemma isDiameter_iff_mem_and_mem_and_wbtw : s.IsDiameter p₁ p₂ ↔ p₁ ∈ s ∧ p₂ ∈ s ∧ Wbtw ℝ p₁ s.center p₂:= by refine ⟨fun h ↦ ⟨h.left_mem, h.right_mem, h.wbtw⟩, fun ⟨h₁, h₂, hr⟩ ↦ ?_⟩ have hd := hr.dist_add_dist rw [mem_sphere.1 h₁, mem_sphere'.1 h₂, ← two_mul, eq_comm] at hd exact isDiameter_iff_mem_and_mem_and_dist.2 ⟨h₁, h₂, hd⟩ end Sphere end EuclideanSpace end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Sphere/Tangent.lean
import Mathlib.Geometry.Euclidean.Projection import Mathlib.Geometry.Euclidean.Sphere.Basic /-! # Tangency for spheres. This file defines notions of spheres being tangent to affine subspaces and other spheres. ## Main definitions * `EuclideanGeometry.Sphere.orthRadius`: the affine subspace orthogonal to the radius vector at a point (the tangent space, if that point lies in the sphere). * `EuclideanGeometry.Sphere.IsTangentAt`: the property of an affine subspace being tangent to a sphere at a given point. * `EuclideanGeometry.Sphere.IsTangent`: the property of an affine subspace being tangent to a sphere at some point. * `EuclideanGeometry.Sphere.tangentSet`: the set of all maximal tangent spaces to a given sphere. * `EuclideanGeometry.Sphere.tangentsFrom`: the set of all maximal tangent spaces to a given sphere and containing a given point. * `EuclideanGeometry.Sphere.commonTangents`: the set of all maximal common tangent spaces to two given spheres. * `EuclideanGeometry.Sphere.commonIntTangents`: the set of all maximal common internal tangent spaces to two given spheres. * `EuclideanGeometry.Sphere.commonExtTangents`: the set of all maximal common external tangent spaces to two given spheres. * `EuclideanGeometry.Sphere.IsExtTangentAt`: the property of two spheres being externally tangent at a given point. * `EuclideanGeometry.Sphere.IsIntTangentAt`: the property of two spheres being internally tangent at a given point. * `EuclideanGeometry.Sphere.IsExtTangent`: the property of two spheres being externally tangent. * `EuclideanGeometry.Sphere.IsIntTangent`: the property of two spheres being internally tangent. -/ namespace EuclideanGeometry namespace Sphere open AffineSubspace RealInnerProductSpace variable {V P : Type*} variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The affine subspace orthogonal to the radius vector of the sphere `s` at the point `p` (in the typical cases, `p` lies in `s` and this is the tangent space). -/ def orthRadius (s : Sphere P) (p : P) : AffineSubspace ℝ P := .mk' p (ℝ ∙ (p -ᵥ s.center))ᗮ lemma self_mem_orthRadius (s : Sphere P) (p : P) : p ∈ s.orthRadius p := self_mem_mk' _ _ lemma mem_orthRadius_iff_inner_left {s : Sphere P} {p x : P} : x ∈ s.orthRadius p ↔ ⟪x -ᵥ p, p -ᵥ s.center⟫ = 0 := by rw [orthRadius, mem_mk', Submodule.mem_orthogonal_singleton_iff_inner_left] lemma mem_orthRadius_iff_inner_right {s : Sphere P} {p x : P} : x ∈ s.orthRadius p ↔ ⟪p -ᵥ s.center, x -ᵥ p⟫ = 0 := by rw [mem_orthRadius_iff_inner_left, inner_eq_zero_symm] @[simp] lemma direction_orthRadius (s : Sphere P) (p : P) : (s.orthRadius p).direction = (ℝ ∙ (p -ᵥ s.center))ᗮ := by rw [orthRadius, direction_mk'] @[simp] lemma orthRadius_center (s : Sphere P) : s.orthRadius s.center = ⊤ := by simp [orthRadius] @[simp] lemma center_mem_orthRadius_iff {s : Sphere P} {p : P} : s.center ∈ s.orthRadius p ↔ p = s.center := by rw [mem_orthRadius_iff_inner_left, ← neg_vsub_eq_vsub_rev, inner_neg_left] simp lemma orthRadius_le_orthRadius_iff {s : Sphere P} {p q : P} : s.orthRadius p ≤ s.orthRadius q ↔ p = q ∨ q = s.center := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · have h' := direction_le h simp only [direction_orthRadius] at h' have h'' := Submodule.orthogonal_le h' simp only [Submodule.orthogonal_orthogonal, Submodule.span_singleton_le_iff_mem, Submodule.mem_span_singleton] at h'' rcases h'' with ⟨r, hr⟩ have hp : p ∈ s.orthRadius q := h (s.self_mem_orthRadius p) rw [mem_orthRadius_iff_inner_left, ← vsub_sub_vsub_cancel_right p q s.center, ← hr, inner_sub_left, real_inner_smul_left, real_inner_smul_right, ← mul_assoc, ← sub_mul, mul_eq_zero] at hp rcases hp with hp | hp · nth_rw 1 [← one_mul r] at hp rw [← sub_mul, mul_eq_zero] at hp rcases hp with hp | rfl · rw [sub_eq_zero] at hp rw [← hp, one_smul, vsub_left_cancel_iff] at hr exact .inl hr · rw [zero_smul, eq_comm, vsub_eq_zero_iff_eq] at hr exact .inr hr · simp only [inner_self_eq_zero, vsub_eq_zero_iff_eq] at hp rw [hp, vsub_self, smul_zero, eq_comm, vsub_eq_zero_iff_eq] at hr exact .inr hr · rcases h with rfl | rfl <;> simp @[simp] lemma orthRadius_eq_orthRadius_iff {s : Sphere P} {p q : P} : s.orthRadius p = s.orthRadius q ↔ p = q := by refine ⟨fun h ↦ ?_, fun h ↦ h ▸ rfl⟩ have hpq := orthRadius_le_orthRadius_iff.1 h.le have hqp := orthRadius_le_orthRadius_iff.1 h.symm.le grind /-- The affine subspace `as` is tangent to the sphere `s` at the point `p`. -/ structure IsTangentAt (s : Sphere P) (p : P) (as : AffineSubspace ℝ P) : Prop where mem_sphere : p ∈ s mem_space : p ∈ as le_orthRadius : as ≤ s.orthRadius p @[simp] lemma isTangentAt_orthRadius_iff_mem {s : Sphere P} {p : P} : s.IsTangentAt p (s.orthRadius p) ↔ p ∈ s := ⟨fun h ↦ h.mem_sphere, fun h ↦ ⟨h, self_mem_orthRadius _ _, le_rfl⟩⟩ lemma IsTangentAt.inner_left_eq_zero_of_mem {s : Sphere P} {p : P} {as : AffineSubspace ℝ P} (h : s.IsTangentAt p as) {x : P} (hx : x ∈ as) : ⟪x -ᵥ p, p -ᵥ s.center⟫ = 0 := mem_orthRadius_iff_inner_left.1 (h.le_orthRadius hx) lemma IsTangentAt.inner_right_eq_zero_of_mem {s : Sphere P} {p : P} {as : AffineSubspace ℝ P} (h : s.IsTangentAt p as) {x : P} (hx : x ∈ as) : ⟪p -ᵥ s.center, x -ᵥ p⟫ = 0 := mem_orthRadius_iff_inner_right.1 (h.le_orthRadius hx) lemma IsTangentAt.eq_of_isTangentAt {s : Sphere P} {p q : P} {as : AffineSubspace ℝ P} (hp : s.IsTangentAt p as) (hq : s.IsTangentAt q as) : p = q := by have hqp := hp.inner_left_eq_zero_of_mem hq.mem_space have hpq := hq.inner_left_eq_zero_of_mem hp.mem_space rw [← neg_vsub_eq_vsub_rev, inner_neg_left, neg_eq_zero, ← hpq, ← sub_eq_zero, ← inner_sub_right, vsub_sub_vsub_cancel_right] at hqp simpa using hqp lemma isTangentAt_center_iff {s : Sphere P} {as : AffineSubspace ℝ P} : s.IsTangentAt s.center as ↔ s.radius = 0 ∧ s.center ∈ as := by refine ⟨?_, ?_⟩ · rintro ⟨hr, hm, -⟩ rw [center_mem_iff] at hr exact ⟨hr, hm⟩ · rintro ⟨hr, hm⟩ refine ⟨?_, hm, ?_⟩ · rw [center_mem_iff, hr] · simp lemma IsTangentAt.dist_sq_eq_of_mem {s : Sphere P} {p q : P} {as : AffineSubspace ℝ P} (h : s.IsTangentAt p as) (hq : q ∈ as) : (dist q s.center) ^ 2 = s.radius ^ 2 + (dist q p) ^ 2 := by rw [← h.mem_sphere] simp_rw [dist_eq_norm_vsub, pow_two] rw [← vsub_add_vsub_cancel q p s.center] conv_rhs => rw [add_comm] rw [norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact h.inner_left_eq_zero_of_mem hq lemma IsTangentAt.mem_and_mem_iff_eq {s : Sphere P} {p q : P} {as : AffineSubspace ℝ P} (h : s.IsTangentAt p as) : (q ∈ s ∧ q ∈ as) ↔ q = p := by refine ⟨fun ⟨hs, has⟩ ↦ ?_, ?_⟩ · have hd := h.dist_sq_eq_of_mem has rw [hs] at hd simpa using hd · rintro rfl exact ⟨h.mem_sphere, h.mem_space⟩ lemma IsTangentAt.eq_of_mem_of_mem {s : Sphere P} {p q : P} {as : AffineSubspace ℝ P} (h : s.IsTangentAt p as) (hs : q ∈ s) (has : q ∈ as) : q = p := h.mem_and_mem_iff_eq.1 ⟨hs, has⟩ /-- If two tangent lines to a sphere pass through the same point `q`, then the distances from `q` to the tangent points are equal. -/ lemma IsTangentAt.dist_eq_of_mem_of_mem {s : Sphere P} {p₁ p₂ q : P} {as₁ as₂ : AffineSubspace ℝ P} (h₁ : s.IsTangentAt p₁ as₁) (h₂ : s.IsTangentAt p₂ as₂) (hq_mem₁ : q ∈ as₁) (hq_mem₂ : q ∈ as₂) : dist q p₁ = dist q p₂ := by have h1 := dist_sq_eq_of_mem h₁ hq_mem₁ have h2 := dist_sq_eq_of_mem h₂ hq_mem₂ rwa [h1, add_left_cancel_iff, sq_eq_sq₀ dist_nonneg dist_nonneg] at h2 /-- The affine subspace `as` is tangent to the sphere `s` at some point. -/ def IsTangent (s : Sphere P) (as : AffineSubspace ℝ P) : Prop := ∃ p, s.IsTangentAt p as lemma IsTangentAt.isTangent {s : Sphere P} {p : P} {as : AffineSubspace ℝ P} (h : s.IsTangentAt p as) : s.IsTangent as := ⟨p, h⟩ @[simp] lemma isTangent_orthRadius_iff_mem {s : Sphere P} {p : P} : s.IsTangent (s.orthRadius p) ↔ p ∈ s := by refine ⟨?_, fun h ↦ (isTangentAt_orthRadius_iff_mem.2 h).isTangent⟩ rintro ⟨q, hs, hsp, hle⟩ rw [orthRadius_le_orthRadius_iff] at hle rcases hle with rfl | rfl · exact hs · rw [center_mem_orthRadius_iff] at hsp rwa [← hsp] at hs lemma IsTangent.radius_le_dist_center {s : Sphere P} {as : AffineSubspace ℝ P} (h : s.IsTangent as) {p : P} (hp : p ∈ as) : s.radius ≤ dist p s.center := by obtain ⟨x, h⟩ := h refine le_of_sq_le_sq ?_ dist_nonneg rw [h.dist_sq_eq_of_mem hp, le_add_iff_nonneg_right] exact sq_nonneg _ lemma IsTangent.notMem_of_dist_lt {s : Sphere P} {as : AffineSubspace ℝ P} (h : s.IsTangent as) {p : P} (hp : dist p s.center < s.radius) : p ∉ as := by contrapose! hp exact h.radius_le_dist_center hp lemma IsTangent.infDist_eq_radius {s : Sphere P} {as : AffineSubspace ℝ P} (h : s.IsTangent as) : Metric.infDist s.center as = s.radius := by obtain ⟨p, h⟩ := h refine le_antisymm ?_ ?_ · convert Metric.infDist_le_dist_of_mem h.mem_space rw [mem_sphere'.1 h.mem_sphere] · rw [Metric.infDist_eq_iInf] have : Nonempty as := ⟨⟨p, h.mem_space⟩⟩ refine le_ciInf fun x ↦ ?_ rw [dist_comm] exact h.isTangent.radius_le_dist_center x.property lemma dist_orthogonalProjection_eq_radius_iff_isTangentAt {s : Sphere P} {as : AffineSubspace ℝ P} [Nonempty as] [as.direction.HasOrthogonalProjection] : dist s.center (orthogonalProjection as s.center) = s.radius ↔ s.IsTangentAt (orthogonalProjection as s.center) as := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · refine ⟨?_, orthogonalProjection_mem _, fun p hp ↦ ?_⟩ · rwa [mem_sphere'] · rw [SetLike.mem_coe, mem_orthRadius_iff_inner_left] exact orthogonalProjection_vsub_mem_direction_orthogonal as s.center _ (vsub_orthogonalProjection_mem_direction s.center hp) · rw [dist_orthogonalProjection_eq_infDist, h.isTangent.infDist_eq_radius] lemma dist_orthogonalProjection_eq_radius_iff_isTangent {s : Sphere P} {as : AffineSubspace ℝ P} [Nonempty as] [as.direction.HasOrthogonalProjection] : dist s.center (orthogonalProjection as s.center) = s.radius ↔ s.IsTangent as := by refine ⟨fun h ↦ (dist_orthogonalProjection_eq_radius_iff_isTangentAt.1 h).isTangent, fun h ↦ ?_⟩ rw [dist_orthogonalProjection_eq_infDist, h.infDist_eq_radius] lemma infDist_eq_radius_iff_isTangent {s : Sphere P} {as : AffineSubspace ℝ P} [Nonempty as] [as.direction.HasOrthogonalProjection] : Metric.infDist s.center as = s.radius ↔ s.IsTangent as := by rw [← dist_orthogonalProjection_eq_infDist, dist_orthogonalProjection_eq_radius_iff_isTangent] lemma isTangent_iff_isTangentAt_orthogonalProjection {s : Sphere P} {as : AffineSubspace ℝ P} [Nonempty as] [as.direction.HasOrthogonalProjection] : s.IsTangent as ↔ s.IsTangentAt (orthogonalProjection as s.center) as := by rw [← dist_orthogonalProjection_eq_radius_iff_isTangent, dist_orthogonalProjection_eq_radius_iff_isTangentAt] alias ⟨IsTangent.isTangentAt, _⟩ := isTangent_iff_isTangentAt_orthogonalProjection lemma IsTangentAt.eq_orthogonalProjection {s : Sphere P} {p : P} {as : AffineSubspace ℝ P} [Nonempty as] [as.direction.HasOrthogonalProjection] (h : s.IsTangentAt p as) : p = orthogonalProjection as s.center := by refine h.eq_of_isTangentAt ?_ have h' := h.isTangent rwa [isTangent_iff_isTangentAt_orthogonalProjection] at h' /-- The set of all maximal tangent spaces to the sphere `s`. -/ def tangentSet (s : Sphere P) : Set (AffineSubspace ℝ P) := s.orthRadius '' s lemma mem_tangentSet_iff {as : AffineSubspace ℝ P} {s : Sphere P} : as ∈ s.tangentSet ↔ ∃ p, p ∈ s ∧ s.orthRadius p = as := Iff.rfl lemma isTangent_of_mem_tangentSet {as : AffineSubspace ℝ P} {s : Sphere P} (h : as ∈ s.tangentSet) : s.IsTangent as := by rcases h with ⟨p, hps, rfl⟩ exact isTangent_orthRadius_iff_mem.2 hps /-- The set of all maximal tangent spaces to the sphere `s` containing the point `p`. -/ def tangentsFrom (s : Sphere P) (p : P) : Set (AffineSubspace ℝ P) := {as ∈ s.tangentSet | p ∈ as} lemma mem_tangentsFrom_iff {as : AffineSubspace ℝ P} {s : Sphere P} {p : P} : as ∈ s.tangentsFrom p ↔ as ∈ s.tangentSet ∧ p ∈ as := Iff.rfl lemma mem_tangentSet_of_mem_tangentsFrom {as : AffineSubspace ℝ P} {s : Sphere P} {p : P} (h : as ∈ s.tangentsFrom p) : as ∈ s.tangentSet := h.1 lemma mem_of_mem_tangentsFrom {as : AffineSubspace ℝ P} {s : Sphere P} {p : P} (h : as ∈ s.tangentsFrom p) : p ∈ as := h.2 lemma isTangent_of_mem_tangentsFrom {as : AffineSubspace ℝ P} {s : Sphere P} {p : P} (h : as ∈ s.tangentsFrom p) : s.IsTangent as := isTangent_of_mem_tangentSet h.1 /-- The set of all maximal common tangent spaces to the spheres `s₁` and `s₂`. -/ def commonTangents (s₁ s₂ : Sphere P) : Set (AffineSubspace ℝ P) := s₁.tangentSet ∩ s₂.tangentSet lemma mem_commonTangents_iff {as : AffineSubspace ℝ P} {s₁ s₂ : Sphere P} : as ∈ s₁.commonTangents s₂ ↔ as ∈ s₁.tangentSet ∧ as ∈ s₂.tangentSet := Iff.rfl lemma commonTangents_comm (s₁ s₂ : Sphere P) : s₁.commonTangents s₂ = s₂.commonTangents s₁ := Set.inter_comm _ _ /-- The set of all maximal common internal tangent spaces to the spheres `s₁` and `s₂`: tangent spaces containing a point weakly between the centers of the spheres. -/ def commonIntTangents (s₁ s₂ : Sphere P) : Set (AffineSubspace ℝ P) := {as ∈ s₁.commonTangents s₂ | ∃ p ∈ as, Wbtw ℝ s₁.center p s₂.center} /-- The set of all maximal common external tangent spaces to the spheres `s₁` and `s₂`: tangent spaces not containing a point strictly between the centers of the spheres. (In the degenerate case where the two spheres are the same sphere with radius 0, the space is considered both an internal and an external common tangent.) -/ def commonExtTangents (s₁ s₂ : Sphere P) : Set (AffineSubspace ℝ P) := {as ∈ s₁.commonTangents s₂ | ∀ p ∈ as, ¬Sbtw ℝ s₁.center p s₂.center} lemma mem_commonIntTangents_iff {as : AffineSubspace ℝ P} {s₁ s₂ : Sphere P} : as ∈ s₁.commonIntTangents s₂ ↔ as ∈ s₁.commonTangents s₂ ∧ ∃ p ∈ as, Wbtw ℝ s₁.center p s₂.center := Iff.rfl lemma mem_commonExtTangents_iff {as : AffineSubspace ℝ P} {s₁ s₂ : Sphere P} : as ∈ s₁.commonExtTangents s₂ ↔ as ∈ s₁.commonTangents s₂ ∧ ∀ p ∈ as, ¬Sbtw ℝ s₁.center p s₂.center := Iff.rfl @[simp] lemma commonIntTangents_union_commonExtTangents (s₁ s₂ : Sphere P) : s₁.commonIntTangents s₂ ∪ s₁.commonExtTangents s₂ = s₁.commonTangents s₂ := by ext as rw [Set.mem_union, mem_commonIntTangents_iff, mem_commonExtTangents_iff, ← and_or_left, and_iff_left_iff_imp] rintro - by_cases! h : ∃ p ∈ as, Wbtw ℝ s₁.center p s₂.center · exact .inl h · refine .inr ?_ rintro p hp exact mt Sbtw.wbtw (h p hp) /-- The spheres `s₁` and `s₂` are externally tangent at the point `p`. -/ structure IsExtTangentAt (s₁ s₂ : Sphere P) (p : P) : Prop where mem_left : p ∈ s₁ mem_right : p ∈ s₂ wbtw : Wbtw ℝ s₁.center p s₂.center lemma IsExtTangentAt.symm {s₁ s₂ : Sphere P} {p : P} (h : s₁.IsExtTangentAt s₂ p) : s₂.IsExtTangentAt s₁ p where mem_left := h.mem_right mem_right := h.mem_left wbtw := h.wbtw.symm lemma isExtTangentAt_comm {s₁ s₂ : Sphere P} {p : P} : s₁.IsExtTangentAt s₂ p ↔ s₂.IsExtTangentAt s₁ p := ⟨IsExtTangentAt.symm, IsExtTangentAt.symm⟩ lemma isExtTangentAt_center_iff {s₁ s₂ : Sphere P} : s₁.IsExtTangentAt s₂ s₁.center ↔ s₁.radius = 0 ∧ s₁.center ∈ s₂ := by refine ⟨?_, ?_⟩ · rintro ⟨h₁, h₂, -⟩ rw [center_mem_iff] at h₁ exact ⟨h₁, h₂⟩ · rintro ⟨hr, hc⟩ refine ⟨?_, hc, ?_⟩ · rw [center_mem_iff, hr] · simp /-- The sphere `s₁` is internally tangent to the sphere `s₂` at the point `p` (that is, `s₁` lies inside `s₂` and is tangent to it at that point). This includes the degenerate case where the spheres are the same. -/ structure IsIntTangentAt (s₁ s₂ : Sphere P) (p : P) : Prop where mem_left : p ∈ s₁ mem_right : p ∈ s₂ wbtw : Wbtw ℝ s₂.center s₁.center p lemma isIntTangentAt_center_iff {s₁ s₂ : Sphere P} : s₁.IsIntTangentAt s₂ s₁.center ↔ s₁.radius = 0 ∧ s₁.center ∈ s₂ := by refine ⟨?_, ?_⟩ · rintro ⟨h₁, h₂, -⟩ rw [center_mem_iff] at h₁ exact ⟨h₁, h₂⟩ · rintro ⟨hr, hc⟩ refine ⟨?_, hc, ?_⟩ · rw [center_mem_iff, hr] · simp @[simp] lemma isIntTangentAt_self_iff_mem {s : Sphere P} {p : P} : s.IsIntTangentAt s p ↔ p ∈ s := ⟨fun ⟨h, _, _⟩ ↦ h, fun h ↦ ⟨h, h, by simp⟩⟩ /-- The spheres `s₁` and `s₂` are externally tangent at some point. -/ def IsExtTangent (s₁ s₂ : Sphere P) : Prop := ∃ p, s₁.IsExtTangentAt s₂ p lemma IsExtTangent.symm {s₁ s₂ : Sphere P} (h : s₁.IsExtTangent s₂) : s₂.IsExtTangent s₁ := by rcases h with ⟨p, hp⟩ exact ⟨p, hp.symm⟩ lemma isExtTangent_comm {s₁ s₂ : Sphere P} : s₁.IsExtTangent s₂ ↔ s₂.IsExtTangent s₁ := ⟨IsExtTangent.symm, IsExtTangent.symm⟩ /-- The sphere `s₁` is internally tangent to the sphere `s₂` at some point. -/ def IsIntTangent (s₁ s₂ : Sphere P) : Prop := ∃ p, s₁.IsIntTangentAt s₂ p lemma IsExtTangentAt.isExtTangent {s₁ s₂ : Sphere P} {p : P} (h : s₁.IsExtTangentAt s₂ p) : s₁.IsExtTangent s₂ := ⟨p, h⟩ lemma IsIntTangentAt.isIntTangent {s₁ s₂ : Sphere P} {p : P} (h : s₁.IsIntTangentAt s₂ p) : s₁.IsIntTangent s₂ := ⟨p, h⟩ @[simp] lemma isIntTangent_self_iff [Nontrivial V] {s : Sphere P} : s.IsIntTangent s ↔ 0 ≤ s.radius := by simp_rw [IsIntTangent, isIntTangentAt_self_iff_mem] rw [← nonempty_iff] simp [Set.Nonempty] lemma IsExtTangent.dist_center {s₁ s₂ : Sphere P} (h : s₁.IsExtTangent s₂) : dist s₁.center s₂.center = s₁.radius + s₂.radius := by rcases h with ⟨p, h₁, h₂, h⟩ rw [← dist_add_dist_eq_iff] at h rw [← h, mem_sphere'.1 h₁, h₂] lemma IsIntTangent.dist_center {s₁ s₂ : Sphere P} (h : s₁.IsIntTangent s₂) : dist s₁.center s₂.center = s₂.radius - s₁.radius := by rcases h with ⟨p, h₁, h₂, h⟩ rw [← dist_add_dist_eq_iff, mem_sphere'.1 h₁, mem_sphere'.1 h₂] at h simp [← h, dist_comm] lemma isExtTangent_iff_dist_center {s₁ s₂ : Sphere P} : s₁.IsExtTangent s₂ ↔ dist s₁.center s₂.center = s₁.radius + s₂.radius ∧ 0 ≤ s₁.radius ∧ 0 ≤ s₂.radius := by refine ⟨fun h ↦ ⟨h.dist_center, ?_⟩, ?_⟩ · rcases h with ⟨p, h₁, h₂, h⟩ exact ⟨radius_nonneg_of_mem h₁, radius_nonneg_of_mem h₂⟩ · rintro ⟨h, h₁, h₂⟩ refine ⟨AffineMap.lineMap s₁.center s₂.center (s₁.radius / (s₁.radius + s₂.radius)), ?_⟩ by_cases h0 : s₁.radius + s₂.radius = 0 · simp only [h0, div_zero, AffineMap.lineMap_apply_zero, isExtTangentAt_center_iff, mem_sphere] exact ⟨by linarith, by linarith⟩ · refine ⟨?_, ?_, ?_⟩ · simp only [mem_sphere, dist_lineMap_left, norm_div, Real.norm_eq_abs, h, abs_of_nonneg h₁, abs_of_nonneg (add_nonneg h₁ h₂)] field · simp only [mem_sphere, dist_lineMap_right, Real.norm_eq_abs, h] rw [one_sub_div h0, add_sub_cancel_left, abs_div, abs_of_nonneg h₂, abs_of_nonneg (add_nonneg h₁ h₂)] field · simp only [wbtw_lineMap_iff] refine .inr ⟨?_, ?_⟩ · positivity · rw [div_le_one (by positivity)] linarith lemma isIntTangent_iff_dist_center [Nontrivial V] {s₁ s₂ : Sphere P} : s₁.IsIntTangent s₂ ↔ dist s₁.center s₂.center = s₂.radius - s₁.radius ∧ 0 ≤ s₁.radius ∧ 0 ≤ s₂.radius := by refine ⟨fun h ↦ ⟨h.dist_center, ?_⟩, ?_⟩ · rcases h with ⟨p, h₁, h₂, h⟩ exact ⟨radius_nonneg_of_mem h₁, radius_nonneg_of_mem h₂⟩ · rintro ⟨h, h₁, h₂⟩ by_cases h0 : s₁.center = s₂.center · rw [h0, dist_self, eq_comm, sub_eq_zero, eq_comm] at h have hs : s₁ = s₂ := by ext <;> assumption simp [hs, h₂] · rw [dist_comm] at h have ha : |s₂.radius - s₁.radius| = s₂.radius - s₁.radius := by refine abs_of_nonneg ?_ rw [← h] exact dist_nonneg have hr0 : s₂.radius - s₁.radius ≠ 0 := by intro hr0 rw [hr0, dist_eq_zero] at h exact h0 h.symm refine ⟨AffineMap.lineMap s₂.center s₁.center (s₂.radius / (s₂.radius - s₁.radius)), ?_, ?_, ?_⟩ · simp only [mem_sphere, dist_lineMap_right, Real.norm_eq_abs, h, one_sub_div hr0, abs_div, sub_sub_cancel_left, abs_neg, abs_of_nonneg h₁, ha] field · simp only [mem_sphere, dist_lineMap_left, norm_div, Real.norm_eq_abs, h, ha, abs_of_nonneg h₂] field · rw [wbtw_iff_left_eq_or_right_mem_image_Ici] simp only [Ne.symm h0, Set.mem_image, Set.mem_Ici, AffineMap.lineMap_eq_lineMap_iff, false_or, exists_eq_right] rw [one_le_div] · linarith · rw [← h] simp [Ne.symm h0] end Sphere end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Sphere/Power.lean
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine import Mathlib.Geometry.Euclidean.Sphere.Basic import Mathlib.Geometry.Euclidean.Sphere.Tangent /-! # Power of a point (intersecting chords and secants) This file proves basic geometrical results about power of a point (intersecting chords and secants) in spheres in real inner product spaces and Euclidean affine spaces. ## Main definitions * `Sphere.power`: The power of a point with respect to a sphere. ## Main theorems * `mul_dist_eq_mul_dist_of_cospherical_of_angle_eq_pi`: Intersecting Chords Theorem (Freek No. 55). * `mul_dist_eq_mul_dist_of_cospherical_of_angle_eq_zero`: Intersecting Secants Theorem. * `Sphere.mul_dist_eq_abs_power`: The product of distances equals the absolute value of power. * `Sphere.dist_sq_eq_mul_dist_of_tangent_and_secant`: Tangent-Secant Theorem. -/ open Real open EuclideanGeometry RealInnerProductSpace Real variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] namespace InnerProductGeometry /-! ### Geometrical results on spheres in real inner product spaces This section develops some results on spheres in real inner product spaces, which are used to deduce corresponding results for Euclidean affine spaces. -/ theorem mul_norm_eq_abs_sub_sq_norm {x y z : V} (h₁ : ∃ k : ℝ, x = k • y) (h₃ : ‖z - y‖ = ‖z + y‖) : ‖x - y‖ * ‖x + y‖ = |‖z + y‖ ^ 2 - ‖z - x‖ ^ 2| := by obtain ⟨r, hr⟩ := h₁ have hzy : ⟪z, y⟫ = 0 := by rwa [inner_eq_zero_iff_angle_eq_pi_div_two, ← norm_add_eq_norm_sub_iff_angle_eq_pi_div_two, eq_comm] have hzx : ⟪z, x⟫ = 0 := by rw [hr, inner_smul_right, hzy, mul_zero] calc ‖x - y‖ * ‖x + y‖ = ‖(r - 1) • y‖ * ‖(r + 1) • y‖ := by simp [sub_smul, add_smul, hr] _ = ‖r - 1‖ * ‖y‖ * (‖r + 1‖ * ‖y‖) := by simp_rw [norm_smul] _ = ‖r - 1‖ * ‖r + 1‖ * ‖y‖ ^ 2 := by ring _ = |(r - 1) * (r + 1) * ‖y‖ ^ 2| := by simp [abs_mul] _ = |r ^ 2 * ‖y‖ ^ 2 - ‖y‖ ^ 2| := by ring_nf _ = |‖x‖ ^ 2 - ‖y‖ ^ 2| := by simp [hr, norm_smul, mul_pow, sq_abs] _ = |‖z + y‖ ^ 2 - ‖z - x‖ ^ 2| := by simp [norm_add_sq_real, norm_sub_sq_real, hzy, hzx, abs_sub_comm] end InnerProductGeometry namespace EuclideanGeometry /-! ### Geometrical results on spheres in Euclidean affine spaces This section develops some results on spheres in Euclidean affine spaces. -/ open InnerProductGeometry EuclideanGeometry variable {P : Type*} [MetricSpace P] [NormedAddTorsor V P] /-- If `P` is a point on the line `AB` and `Q` is equidistant from `A` and `B`, then `AP * BP = abs (BQ ^ 2 - PQ ^ 2)`. -/ theorem mul_dist_eq_abs_sub_sq_dist {a b p q : P} (hp : p ∈ line[ℝ, a, b]) (hq : dist a q = dist b q) : dist a p * dist b p = |dist b q ^ 2 - dist p q ^ 2| := by let m : P := midpoint ℝ a b have h1 := vsub_sub_vsub_cancel_left a p m have h1' := vsub_sub_vsub_cancel_left p a m have h2 := vsub_sub_vsub_cancel_left p q m have h3 := vsub_sub_vsub_cancel_left a q m have h : ∀ r, b -ᵥ r = m -ᵥ r + (m -ᵥ a) := fun r => by rw [midpoint_vsub_left, ← right_vsub_midpoint, add_comm, vsub_add_vsub_cancel] iterate 4 rw [dist_eq_norm_vsub V] rw [← h1, ← h2, h, h] rw [dist_eq_norm_vsub V a q, dist_eq_norm_vsub V b q, ← h3, h] at hq refine mul_norm_eq_abs_sub_sq_norm ?_ hq -- TODO: factor this out as a separate lemma? · rw [← vsub_vadd p a, vadd_left_mem_affineSpan_pair] at hp rcases hp with ⟨r, hr⟩ rw [h, ← h1', eq_sub_iff_add_eq, ← eq_sub_iff_add_eq'] at hr rw [hr] use 1 - r * 2 match_scalars ring /-- If `A`, `B`, `C`, `D` are cospherical and `P` is on both lines `AB` and `CD`, then `AP * BP = CP * DP`. -/ theorem mul_dist_eq_mul_dist_of_cospherical {a b c d p : P} (h : Cospherical ({a, b, c, d} : Set P)) (hapb : p ∈ line[ℝ, a, b]) (hcpd : p ∈ line[ℝ, c, d]) : dist a p * dist b p = dist c p * dist d p := by obtain ⟨q, r, h'⟩ := (cospherical_def {a, b, c, d}).mp h obtain ⟨ha, hb, hc, hd⟩ := h' a (by simp), h' b (by simp), h' c (by simp), h' d (by simp) rw [← hd] at hc rw [← hb] at ha rw [mul_dist_eq_abs_sub_sq_dist hapb ha, hb, mul_dist_eq_abs_sub_sq_dist hcpd hc, hd] /-- **Intersecting Chords Theorem**. -/ theorem mul_dist_eq_mul_dist_of_cospherical_of_angle_eq_pi {a b c d p : P} (h : Cospherical ({a, b, c, d} : Set P)) (hapb : ∠ a p b = π) (hcpd : ∠ c p d = π) : dist a p * dist b p = dist c p * dist d p := by rw [EuclideanGeometry.angle_eq_pi_iff_sbtw] at hapb hcpd exact mul_dist_eq_mul_dist_of_cospherical h hapb.wbtw.mem_affineSpan hcpd.wbtw.mem_affineSpan /-- **Intersecting Secants Theorem**. -/ theorem mul_dist_eq_mul_dist_of_cospherical_of_angle_eq_zero {a b c d p : P} (h : Cospherical ({a, b, c, d} : Set P)) (hab : a ≠ b) (hcd : c ≠ d) (hapb : ∠ a p b = 0) (hcpd : ∠ c p d = 0) : dist a p * dist b p = dist c p * dist d p := by apply collinear_of_angle_eq_zero at hapb apply collinear_of_angle_eq_zero at hcpd exact mul_dist_eq_mul_dist_of_cospherical h (hapb.mem_affineSpan_of_mem_of_ne (by simp) (by simp) (by simp) hab) (hcpd.mem_affineSpan_of_mem_of_ne (by simp) (by simp) (by simp) hcd) namespace Sphere /-- The power of a point with respect to a sphere. For a point and a sphere, this is defined as the square of the distance from the point to the center minus the square of the radius. This value is positive if the point is outside the sphere, negative if inside, and zero if on the sphere. -/ def power (s : Sphere P) (p : P) : ℝ := dist p s.center ^ 2 - s.radius ^ 2 /-- A point lies on the sphere if and only if its power with respect to the sphere is zero. -/ theorem power_eq_zero_iff_mem_sphere {s : Sphere P} {p : P} (hr : 0 ≤ s.radius) : s.power p = 0 ↔ p ∈ s := by rw [power, mem_sphere, sub_eq_zero, pow_left_inj₀ dist_nonneg hr two_ne_zero] /-- The power of a point is positive if and only if the point lies outside the sphere. -/ theorem power_pos_iff_radius_lt_dist_center {s : Sphere P} {p : P} (hr : 0 ≤ s.radius) : 0 < s.power p ↔ s.radius < dist p s.center := by rw [power, sub_pos, pow_lt_pow_iff_left₀ hr dist_nonneg two_ne_zero] /-- The power of a point is negative if and only if the point lies inside the sphere. -/ theorem power_neg_iff_dist_center_lt_radius {s : Sphere P} {p : P} (hr : 0 ≤ s.radius) : s.power p < 0 ↔ dist p s.center < s.radius := by rw [power, sub_neg, pow_lt_pow_iff_left₀ dist_nonneg hr two_ne_zero] /-- The power of a point is nonnegative if and only if the point lies outside or on the sphere. -/ theorem power_nonneg_iff_radius_le_dist_center {s : Sphere P} {p : P} (hr : 0 ≤ s.radius) : 0 ≤ s.power p ↔ s.radius ≤ dist p s.center := by rw [power, sub_nonneg, pow_le_pow_iff_left₀ hr dist_nonneg two_ne_zero] /-- The power of a point is nonpositive if and only if the point lies inside or on the sphere. -/ theorem power_nonpos_iff_dist_center_le_radius {s : Sphere P} {p : P} (hr : 0 ≤ s.radius) : s.power p ≤ 0 ↔ dist p s.center ≤ s.radius := by rw [power, sub_nonpos, pow_le_pow_iff_left₀ dist_nonneg hr two_ne_zero] /-- For any point, the product of distances to two intersection points on a line through the point equals the absolute value of the power of the point. -/ theorem mul_dist_eq_abs_power {s : Sphere P} {p a b : P} (hp : p ∈ line[ℝ, a, b]) (ha : a ∈ s) (hb : b ∈ s) : dist p a * dist p b = |s.power p| := by have hq : dist a s.center = dist b s.center := by rw [mem_sphere.mp ha, mem_sphere.mp hb] rw [dist_comm p a, dist_comm p b, mul_dist_eq_abs_sub_sq_dist hp hq, mem_sphere.mp hb, power, abs_sub_comm] /-- For a point on the sphere, the product of distances to two other intersection points on a line through the point is zero. -/ theorem mul_dist_eq_zero_of_mem_sphere {s : Sphere P} {p a b : P} (hp : p ∈ line[ℝ, a, b]) (ha : a ∈ s) (hb : b ∈ s) (hp_on : p ∈ s) : dist p a * dist p b = 0 := by have hq : dist a s.center = dist b s.center := by rw [mem_sphere.mp ha, mem_sphere.mp hb] rw [dist_comm p a, dist_comm p b, mul_dist_eq_abs_sub_sq_dist hp hq, mem_sphere.mp hb, mem_sphere.mp hp_on, sub_self, abs_zero] /-- For a point outside or on the sphere, the product of distances to two intersection points on a line through the point equals the power of the point. -/ theorem mul_dist_eq_power_of_radius_le_dist_center {s : Sphere P} {p a b : P} (hr : 0 ≤ s.radius) (hp : p ∈ line[ℝ, a, b]) (ha : a ∈ s) (hb : b ∈ s) (hle : s.radius ≤ dist p s.center) : dist p a * dist p b = s.power p := by rw [mul_dist_eq_abs_power hp ha hb, abs_of_nonneg <| (power_nonneg_iff_radius_le_dist_center hr).mpr hle] /-- For a point inside or on the sphere, the product of distances to two intersection points on a line through the point equals the negative of the power of the point. -/ theorem mul_dist_eq_neg_power_of_dist_center_le_radius {s : Sphere P} {p a b : P} (hr : 0 ≤ s.radius) (hp : p ∈ line[ℝ, a, b]) (ha : a ∈ s) (hb : b ∈ s) (hle : dist p s.center ≤ s.radius) : dist p a * dist p b = -s.power p := by rw [mul_dist_eq_abs_power hp ha hb, abs_of_nonpos <| (power_nonpos_iff_dist_center_le_radius hr).mpr hle] /-- **Tangent-Secant Theorem**. The square of the tangent length equals the product of secant segment lengths. -/ theorem dist_sq_eq_mul_dist_of_tangent_and_secant {a b t p : P} {s : Sphere P} (ha : a ∈ s) (hb : b ∈ s) (hp : p ∈ line[ℝ, a, b]) (h_tangent : s.IsTangentAt t (line[ℝ, p, t])) : dist p t ^ 2 = dist p a * dist p b := by have hr := radius_nonneg_of_mem ha have radius_le_dist := h_tangent.isTangent.radius_le_dist_center (left_mem_affineSpan_pair ℝ p t) rw [mul_dist_eq_power_of_radius_le_dist_center hr hp ha hb radius_le_dist, Sphere.power, h_tangent.dist_sq_eq_of_mem (left_mem_affineSpan_pair ℝ p t)] ring end Sphere end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Euclidean/Sphere/Ptolemy.lean
import Mathlib.Geometry.Euclidean.Sphere.Power import Mathlib.Geometry.Euclidean.Triangle /-! # Ptolemy's theorem This file proves Ptolemy's theorem on the lengths of the diagonals and sides of a cyclic quadrilateral. ## Main theorems * `mul_dist_add_mul_dist_eq_mul_dist_of_cospherical`: Ptolemy’s Theorem (Freek No. 95). TODO: The current statement of Ptolemy’s theorem works around the lack of a "cyclic polygon" concept in mathlib, which is what the theorem statement would naturally use (or two such concepts, since both a strict version, where all vertices must be distinct, and a weak version, where consecutive vertices may be equal, would be useful; Ptolemy's theorem should then use the weak one). An API needs to be built around that concept, which would include: - strict cyclic implies weak cyclic, - weak cyclic and consecutive points distinct implies strict cyclic, - weak/strict cyclic implies weak/strict cyclic for any subsequence, - any three points on a sphere are weakly or strictly cyclic according to whether they are distinct, - any number of points on a sphere intersected with a two-dimensional affine subspace are cyclic in some order, - a list of points is cyclic if and only if its reversal is, - a list of points is cyclic if and only if any cyclic permutation is, while other permutations are not when the points are distinct, - a point P where the diagonals of a cyclic polygon cross exists (and is unique) with weak/strict betweenness depending on weak/strict cyclicity, - four points on a sphere with such a point P are cyclic in the appropriate order, and so on. -/ open Real open scoped EuclideanGeometry RealInnerProductSpace Real namespace EuclideanGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] variable {P : Type*} [MetricSpace P] [NormedAddTorsor V P] /-- **Ptolemy’s Theorem**. -/ theorem mul_dist_add_mul_dist_eq_mul_dist_of_cospherical {a b c d p : P} (h : Cospherical ({a, b, c, d} : Set P)) (hapc : ∠ a p c = π) (hbpd : ∠ b p d = π) : dist a b * dist c d + dist b c * dist d a = dist a c * dist b d := by have h' : Cospherical ({a, c, b, d} : Set P) := by rwa [Set.insert_comm c b {d}] have hmul := mul_dist_eq_mul_dist_of_cospherical_of_angle_eq_pi h' hapc hbpd have hbp := left_dist_ne_zero_of_angle_eq_pi hbpd have h₁ : dist c d = dist c p / dist b p * dist a b := by rw [dist_mul_of_eq_angle_of_dist_mul b p a c p d, dist_comm a b] · rw [angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi hbpd hapc, angle_comm] all_goals simp [field, mul_comm, hmul] have h₂ : dist d a = dist a p / dist b p * dist b c := by rw [dist_mul_of_eq_angle_of_dist_mul c p b d p a, dist_comm c b] · rwa [angle_comm, angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi]; rwa [angle_comm] all_goals simp [field, mul_comm, hmul] have h₃ : dist d p = dist a p * dist c p / dist b p := by simp [field, hmul] have h₄ : ∀ x y : ℝ, x * (y * x) = x * x * y := fun x y => by rw [mul_left_comm, mul_comm] simp [field, h₁, h₂, dist_eq_add_dist_of_angle_eq_pi hbpd, h₃, dist_comm a b, h₄, ← sq, dist_sq_mul_dist_add_dist_sq_mul_dist b, hapc] end EuclideanGeometry
.lake/packages/mathlib/Mathlib/Geometry/Convex/README.md
# Convex geometry This subfolder is destined to contain convexity results that do not require a norm nor an inner product. See the `Mathlib.Analysis.Convex` folder for the results that need a norm or an inner product. ## Topics The topics currently covered are: * Cones
.lake/packages/mathlib/Mathlib/Geometry/Convex/Cone/TensorProduct.lean
import Mathlib.Geometry.Convex.Cone.Dual import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # Tensor products of cones Given ordered modules `M` and `N`, there are in general several distinct possible orderings of the tensor product module `M ⊗ N`. Since the ordering of an ordered module can be represented by its cone of nonnegative elements, there are likewise multiple ways to construct a cone in `M ⊗ N` from cones in `M` and `N`. Such constructions are referred to as tensor products of cones. "Sufficiently nice" candidates for tensor products of cones are bounded by the minimal and maximal tensor products. These products are generally distinct but coincide in special cases. We define the minimal and maximal tensor products of pointed cones: * `minTensorProduct C₁ C₂`: all conical combinations of elementary tensor products `x ⊗ₜ y` with `x ∈ C₁` and `y ∈ C₂`. * `maxTensorProduct C₁ C₂`: the dual cone of the minimal tensor product of the dual cones. ## Main results * `minTensorProduct_le_maxTensorProduct`: the minimal tensor product is less than or equal to the maximal tensor product ## Notation * no special notation defined * x, y, z are elements of the (original) cones * φ, ψ are elements of the dual cones ## References * [Aubrun et al. *Entangleability of cones*][aubrunEntangleabilityCones2021] -/ open TensorProduct Module variable {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] variable {G : Type*} [AddCommGroup G] [Module R G] variable {H : Type*} [AddCommGroup H] [Module R H] namespace PointedCone /-- The minimal tensor product of two cones is given by all conical combinations of elementary tensor products `x ⊗ₜ y` with `x ∈ C₁` and `y ∈ C₂`. -/ noncomputable def minTensorProduct (C₁ : PointedCone R G) (C₂ : PointedCone R H) : PointedCone R (G ⊗[R] H) := .span R (.image2 (· ⊗ₜ[R] ·) C₁ C₂) /-- The maximal tensor product of two cones is the dual (pointed cone) of the minimal tensor product of the dual cones. -/ noncomputable def maxTensorProduct (C₁ : PointedCone R G) (C₂ : PointedCone R H) : PointedCone R (G ⊗[R] H) := .dual (dualDistrib R G H) (minTensorProduct (.dual (dualPairing R G).flip C₁) (.dual (dualPairing R H).flip C₂)) /-- Characterization of the maximal tensor product: `z` lies in `maxTensorProduct C₁ C₂` iff all pairings with elementary dual tensors are nonnegative. -/ @[simp] theorem mem_maxTensorProduct {C₁ : PointedCone R G} {C₂ : PointedCone R H} {z : G ⊗[R] H} : z ∈ maxTensorProduct (R := R) C₁ C₂ ↔ ∀ φ ∈ PointedCone.dual (dualPairing R G).flip C₁, ∀ ψ ∈ PointedCone.dual (dualPairing R H).flip C₂, 0 ≤ dualDistrib R G H (φ ⊗ₜ[R] ψ) z := by simp only [maxTensorProduct, minTensorProduct, dual_span, mem_dual, Set.forall_mem_image2] rfl /-- Elementary tensors are members of the maximal tensor product. -/ theorem tmul_mem_maxTensorProduct {x y} {C₁ : PointedCone R G} {C₂ : PointedCone R H} (hx : x ∈ C₁) (hy : y ∈ C₂) : x ⊗ₜ[R] y ∈ maxTensorProduct C₁ C₂ := by simp only [mem_maxTensorProduct, dualDistrib_apply] exact fun φ hφ ψ hψ => mul_nonneg (hφ hx) (hψ hy) /-- Elementary tensors are members of the minimal tensor product. -/ theorem tmul_mem_minTensorProduct {x y} {C₁ : PointedCone R G} {C₂ : PointedCone R H} (hx : x ∈ C₁) (hy : y ∈ C₂) : x ⊗ₜ[R] y ∈ minTensorProduct C₁ C₂ := Submodule.subset_span (Set.mem_image2_of_mem hx hy) /-- The maximal tensor product contains the set of all elementary tensors. -/ theorem tmul_subset_maxTensorProduct (C₁ : PointedCone R G) (C₂ : PointedCone R H) : .image2 (· ⊗ₜ[R] ·) C₁ C₂ ⊆ (maxTensorProduct C₁ C₂ : Set (G ⊗[R] H)) := fun _ ⟨_, hx, _, hy, hz⟩ => hz ▸ tmul_mem_maxTensorProduct hx hy /-- The minimal tensor product contains the set of all elementary tensors. -/ theorem tmul_subset_minTensorProduct (C₁ : PointedCone R G) (C₂ : PointedCone R H) : .image2 (· ⊗ₜ[R] ·) C₁ C₂ ⊆ (minTensorProduct C₁ C₂ : Set (G ⊗[R] H)) := fun _ ⟨_, hx, _, hy, hz⟩ => hz ▸ tmul_mem_minTensorProduct hx hy /-- The minimal tensor product is less than or equal to the maximal tensor product. -/ theorem minTensorProduct_le_maxTensorProduct (C₁ : PointedCone R G) (C₂ : PointedCone R H) : minTensorProduct C₁ C₂ ≤ maxTensorProduct C₁ C₂ := by exact Submodule.span_le.mpr (tmul_subset_maxTensorProduct C₁ C₂) end PointedCone
.lake/packages/mathlib/Mathlib/Geometry/Convex/Cone/Basic.lean
import Mathlib.Analysis.Convex.Hull /-! # Convex cones In an `R`-module `M`, we define a convex cone as a set `s` such that `a • x + b • y ∈ s` whenever `x, y ∈ s` and `a, b > 0`. We prove that convex cones form a `CompleteLattice`, and define their images (`ConvexCone.map`) and preimages (`ConvexCone.comap`) under linear maps. We define pointed, blunt, flat and salient cones, and prove the correspondence between convex cones and ordered modules. We define `Convex.toCone` to be the minimal cone that includes a given convex set. ## Main statements In `Mathlib/Analysis/Convex/Cone/Extension.lean` we prove the M. Riesz extension theorem and a form of the Hahn-Banach theorem. In `Mathlib/Analysis/Convex/Cone/Dual.lean` we prove a variant of the hyperplane separation theorem. ## Implementation notes While `Convex R` is a predicate on sets, `ConvexCone R M` is a bundled convex cone. ## References * https://en.wikipedia.org/wiki/Convex_cone * [Stephen P. Boyd and Lieven Vandenberghe, *Convex Optimization*][boydVandenberghe2004] * [Emo Welzl and Bernd Gärtner, *Cone Programming*][welzl_garter] -/ assert_not_exists TopologicalSpace Real Cardinal open Set LinearMap Pointwise variable {𝕜 R G M N O : Type*} /-! ### Definition of `ConvexCone` and basic properties -/ section Definitions variable [Semiring R] [PartialOrder R] variable (R M) in /-- A convex cone is a subset `s` of an `R`-module such that `a • x + b • y ∈ s` whenever `a, b > 0` and `x, y ∈ s`. -/ structure ConvexCone [AddCommMonoid M] [SMul R M] where /-- The **carrier set** underlying this cone: the set of points contained in it -/ carrier : Set M smul_mem' : ∀ ⦃c : R⦄, 0 < c → ∀ ⦃x : M⦄, x ∈ carrier → c • x ∈ carrier add_mem' : ∀ ⦃x⦄ (_ : x ∈ carrier) ⦃y⦄ (_ : y ∈ carrier), x + y ∈ carrier end Definitions namespace ConvexCone section OrderedSemiring variable [Semiring R] [PartialOrder R] [AddCommMonoid M] section SMul variable [SMul R M] {C C₁ C₂ : ConvexCone R M} {s : Set M} {c : R} {x : M} instance : SetLike (ConvexCone R M) M where coe := carrier coe_injective' C₁ C₂ h := by cases C₁; congr! @[simp, norm_cast] lemma coe_mk (s : Set M) (h₁ h₂) : ↑(mk (R := R) s h₁ h₂) = s := rfl @[simp] lemma mem_mk {h₁ h₂} : x ∈ mk (R := R) s h₁ h₂ ↔ x ∈ s := .rfl /-- Two `ConvexCone`s are equal if they have the same elements. -/ @[ext] theorem ext (h : ∀ x, x ∈ C₁ ↔ x ∈ C₂) : C₁ = C₂ := SetLike.ext h variable (C) in @[aesop 90% (rule_sets := [SetLike])] protected lemma smul_mem (hc : 0 < c) (hx : x ∈ C) : c • x ∈ C := C.smul_mem' hc hx variable (C) in protected lemma add_mem ⦃x⦄ (hx : x ∈ C) ⦃y⦄ (hy : y ∈ C) : x + y ∈ C := C.add_mem' hx hy instance : AddMemClass (ConvexCone R M) M where add_mem ha hb := add_mem' _ ha hb /-- Copy of a convex cone with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ @[simps] protected def copy (C : ConvexCone R M) (s : Set M) (hs : s = C) : ConvexCone R M where carrier := s add_mem' := hs.symm ▸ C.add_mem' smul_mem' := by simpa [hs] using C.smul_mem' lemma copy_eq (C : ConvexCone R M) (s : Set M) (hs) : C.copy s hs = C := SetLike.coe_injective hs instance : InfSet (ConvexCone R M) where sInf S := ⟨⋂ C ∈ S, C, fun _r hr _x hx ↦ mem_biInter fun C hC ↦ C.smul_mem hr <| mem_iInter₂.1 hx C hC, fun _ hx _ hy ↦ mem_biInter fun C hC ↦ add_mem (mem_iInter₂.1 hx C hC) (mem_iInter₂.1 hy C hC)⟩ @[simp, norm_cast] lemma coe_sInf (S : Set (ConvexCone R M)) : ↑(sInf S) = ⋂ C ∈ S, (C : Set M) := rfl @[simp] lemma mem_sInf {S : Set (ConvexCone R M)} : x ∈ sInf S ↔ ∀ C ∈ S, x ∈ C := mem_iInter₂ @[simp, norm_cast] theorem coe_iInf {ι : Sort*} (f : ι → ConvexCone R M) : ↑(iInf f) = ⋂ i, (f i : Set M) := by simp [iInf] @[simp] lemma mem_iInf {ι : Sort*} {f : ι → ConvexCone R M} : x ∈ iInf f ↔ ∀ i, x ∈ f i := mem_iInter₂.trans <| by simp instance : CompleteSemilatticeInf (ConvexCone R M) where sInf_le C C hC := by rw [← SetLike.coe_subset_coe, coe_sInf]; exact biInter_subset_of_mem hC le_sInf C C hC := by rw [← SetLike.coe_subset_coe, coe_sInf]; exact subset_iInter₂ hC variable (R s) in /-- The cone hull of a set. The smallest convex cone containing that set. -/ def hull : ConvexCone R M := sInf {C : ConvexCone R M | s ⊆ C} lemma subset_hull : s ⊆ hull R s := by simp [hull] lemma hull_min (hsC : s ⊆ C) : hull R s ≤ C := sInf_le hsC lemma hull_le_iff : hull R s ≤ C ↔ s ⊆ C := ⟨subset_hull.trans, hull_min⟩ lemma gc_hull_coe : GaloisConnection (hull R : Set M → ConvexCone R M) (↑) := fun _C _s ↦ hull_le_iff /-- Galois insertion between `ConvexCone` and `SetLike.coe`. -/ protected def gi : GaloisInsertion (hull R : Set M → ConvexCone R M) (↑) where gc := gc_hull_coe le_l_u _ := subset_hull choice s hs := (hull R s).copy s <| subset_hull.antisymm hs choice_eq _ _ := copy_eq _ _ _ instance : Bot (ConvexCone R M) := ⟨⟨∅, fun _ _ _ => False.elim, fun _ => False.elim⟩⟩ @[simp] lemma notMem_bot : x ∉ (⊥ : ConvexCone R M) := id @[deprecated notMem_bot (since := "2025-06-11")] theorem mem_bot (x : M) : (x ∈ (⊥ : ConvexCone R M)) = False := rfl @[simp, norm_cast] lemma coe_bot : ↑(⊥ : ConvexCone R M) = (∅ : Set M) := rfl @[simp, norm_cast] lemma coe_eq_empty : (C : Set M) = ∅ ↔ C = ⊥ := by rw [← coe_bot (R := R)]; norm_cast instance : CompleteLattice (ConvexCone R M) where bot := ⊥ bot_le _ := empty_subset _ __ := instCompleteSemilatticeInf __ := ConvexCone.gi.liftCompleteLattice variable (C₁ C₂) in @[simp, norm_cast] lemma coe_inf : (C₁ ⊓ C₂) = (C₁ ∩ C₂ : Set M) := rfl @[simp] lemma mem_inf : x ∈ C₁ ⊓ C₂ ↔ x ∈ C₁ ∧ x ∈ C₂ := .rfl @[simp] lemma mem_top : x ∈ (⊤ : ConvexCone R M) := mem_univ x @[simp, norm_cast] lemma coe_top : ↑(⊤ : ConvexCone R M) = (univ : Set M) := rfl @[simp, norm_cast] lemma disjoint_coe : Disjoint (C₁ : Set M) C₂ ↔ Disjoint C₁ C₂ := by simp [disjoint_iff, ← coe_inf] instance : Inhabited (ConvexCone R M) := ⟨⊥⟩ end SMul section Module variable [Module R M] (C : ConvexCone R M) protected theorem convex : Convex R (C : Set M) := convex_iff_forall_pos.2 fun _ hx _ hy _ _ ha hb _ ↦ add_mem (C.smul_mem ha hx) (C.smul_mem hb hy) end Module section Maps variable [AddCommMonoid N] [AddCommMonoid O] variable [Module R M] [Module R N] [Module R O] /-- The image of a convex cone under a `R`-linear map is a convex cone. -/ def map (f : M →ₗ[R] N) (C : ConvexCone R M) : ConvexCone R N where carrier := f '' C smul_mem' := fun c hc _ ⟨x, hx, hy⟩ => hy ▸ f.map_smul c x ▸ mem_image_of_mem f (C.smul_mem hc hx) add_mem' := fun _ ⟨x₁, hx₁, hy₁⟩ _ ⟨x₂, hx₂, hy₂⟩ => hy₁ ▸ hy₂ ▸ f.map_add x₁ x₂ ▸ mem_image_of_mem f (add_mem hx₁ hx₂) @[simp, norm_cast] theorem coe_map (C : ConvexCone R M) (f : M →ₗ[R] N) : (C.map f : Set N) = f '' C := rfl @[simp] theorem mem_map {f : M →ₗ[R] N} {C : ConvexCone R M} {y : N} : y ∈ C.map f ↔ ∃ x ∈ C, f x = y := Set.mem_image f C y theorem map_map (g : N →ₗ[R] O) (f : M →ₗ[R] N) (C : ConvexCone R M) : (C.map f).map g = C.map (g.comp f) := SetLike.coe_injective <| image_image g f C @[simp] theorem map_id (C : ConvexCone R M) : C.map LinearMap.id = C := SetLike.coe_injective <| image_id _ /-- The preimage of a convex cone under a `R`-linear map is a convex cone. -/ def comap (f : M →ₗ[R] N) (C : ConvexCone R N) : ConvexCone R M where carrier := f ⁻¹' C smul_mem' c hc x hx := by rw [mem_preimage, f.map_smul c] exact C.smul_mem hc hx add_mem' x hx y hy := by rw [mem_preimage, f.map_add] exact add_mem hx hy @[simp] theorem coe_comap (f : M →ₗ[R] N) (C : ConvexCone R N) : (C.comap f : Set M) = f ⁻¹' C := rfl @[simp] theorem comap_id (C : ConvexCone R M) : C.comap LinearMap.id = C := rfl theorem comap_comap (g : N →ₗ[R] O) (f : M →ₗ[R] N) (C : ConvexCone R O) : (C.comap g).comap f = C.comap (g.comp f) := rfl @[simp] theorem mem_comap {f : M →ₗ[R] N} {C : ConvexCone R N} {x : M} : x ∈ C.comap f ↔ f x ∈ C := Iff.rfl end Maps end OrderedSemiring section LinearOrderedField variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] section MulAction variable [AddCommMonoid M] variable [MulAction 𝕜 M] (C : ConvexCone 𝕜 M) theorem smul_mem_iff {c : 𝕜} (hc : 0 < c) {x : M} : c • x ∈ C ↔ x ∈ C := ⟨fun h => inv_smul_smul₀ hc.ne' x ▸ C.smul_mem (inv_pos.2 hc) h, C.smul_mem hc⟩ end MulAction end LinearOrderedField /-! ### Convex cones with extra properties -/ section OrderedSemiring variable [Semiring R] [PartialOrder R] section AddCommMonoid variable [AddCommMonoid M] [SMul R M] {C C₁ C₂ : ConvexCone R M} /-- A convex cone is pointed if it includes `0`. -/ def Pointed (C : ConvexCone R M) : Prop := (0 : M) ∈ C /-- A convex cone is blunt if it doesn't include `0`. -/ def Blunt (C : ConvexCone R M) : Prop := (0 : M) ∉ C lemma blunt_iff_not_pointed : C.Blunt ↔ ¬ C.Pointed := .rfl lemma pointed_iff_not_blunt : C.Pointed ↔ ¬ C.Blunt := by simp [Blunt, Pointed] theorem Pointed.mono (h : C₁ ≤ C₂) : C₁.Pointed → C₂.Pointed := @h _ theorem Blunt.anti (h : C₂ ≤ C₁) : C₁.Blunt → C₂.Blunt := (· ∘ @h 0) end AddCommMonoid section AddCommGroup variable [AddCommGroup G] [SMul R G] {C C₁ C₂ : ConvexCone R G} /-- A convex cone is flat if it contains some nonzero vector `x` and its opposite `-x`. -/ def Flat (C : ConvexCone R G) : Prop := ∃ x ∈ C, x ≠ (0 : G) ∧ -x ∈ C /-- A convex cone is salient if it doesn't include `x` and `-x` for any nonzero `x`. -/ def Salient (C : ConvexCone R G) : Prop := ∀ x ∈ C, x ≠ (0 : G) → -x ∉ C theorem salient_iff_not_flat : C.Salient ↔ ¬ C.Flat := by simp [Salient, Flat] theorem Flat.mono (h : C₁ ≤ C₂) : C₁.Flat → C₂.Flat | ⟨x, hxS, hx, hnxS⟩ => ⟨x, h hxS, hx, h hnxS⟩ theorem Salient.anti (h : C₂ ≤ C₁) : C₁.Salient → C₂.Salient := fun hS x hxT hx hnT => hS x (h hxT) hx (h hnT) /-- A flat cone is always pointed (contains `0`). -/ theorem Flat.pointed (hC : C.Flat) : C.Pointed := by obtain ⟨x, hx, _, hxneg⟩ := hC rw [Pointed, ← add_neg_cancel x] exact add_mem hx hxneg /-- A blunt cone (one not containing `0`) is always salient. -/ theorem Blunt.salient : C.Blunt → C.Salient := by rw [salient_iff_not_flat, blunt_iff_not_pointed] exact mt Flat.pointed /-- A pointed convex cone defines a preorder. -/ def toPreorder (C : ConvexCone R G) (h₁ : C.Pointed) : Preorder G where le x y := y - x ∈ C le_refl x := by rw [sub_self x]; exact h₁ le_trans x y z xy zy := by simpa using add_mem zy xy /-- A pointed and salient cone defines a partial order. -/ def toPartialOrder (C : ConvexCone R G) (h₁ : C.Pointed) (h₂ : C.Salient) : PartialOrder G := { toPreorder C h₁ with le_antisymm := by intro a b ab ba by_contra h have h' : b - a ≠ 0 := fun h'' => h (eq_of_sub_eq_zero h'').symm have H := h₂ (b - a) ab h' rw [neg_sub b a] at H exact H ba } /-- A pointed and salient cone defines an `IsOrderedAddMonoid`. -/ lemma to_isOrderedAddMonoid (C : ConvexCone R G) (h₁ : C.Pointed) (h₂ : C.Salient) : let _ := toPartialOrder C h₁ h₂ IsOrderedAddMonoid G := let _ := toPartialOrder C h₁ h₂ { add_le_add_left := by intro a b hab c change c + b - (c + a) ∈ C rw [add_sub_add_left_eq_sub] exact hab } @[deprecated (since := "2025-06-11")] alias toIsOrderedAddMonoid := to_isOrderedAddMonoid end AddCommGroup section Module variable [AddCommMonoid M] [Module R M] {C₁ C₂ : ConvexCone R M} {x : M} instance : Zero (ConvexCone R M) := ⟨⟨0, fun _ _ => by simp, fun _ => by simp⟩⟩ @[simp] lemma mem_zero : x ∈ (0 : ConvexCone R M) ↔ x = 0 := .rfl @[simp, norm_cast] lemma coe_zero : ((0 : ConvexCone R M) : Set M) = 0 := rfl theorem pointed_zero : (0 : ConvexCone R M).Pointed := by rw [Pointed, mem_zero] instance instAdd : Add (ConvexCone R M) where add C₁ C₂ := { carrier := C₁ + C₂ smul_mem' := by rintro c hc _ ⟨x, hx, y, hy, rfl⟩ rw [smul_add] use c • x, C₁.smul_mem hc hx, c • y, C₂.smul_mem hc hy add_mem' := by rintro _ ⟨x₁, hx₁, x₂, hx₂, rfl⟩ y ⟨y₁, hy₁, y₂, hy₂, rfl⟩ exact ⟨x₁ + y₁, add_mem hx₁ hy₁, x₂ + y₂, add_mem hx₂ hy₂, add_add_add_comm ..⟩ } @[simp, norm_cast] lemma coe_add (C₁ C₂ : ConvexCone R M) : ↑(C₁ + C₂) = (C₁ + C₂ : Set M) := rfl @[simp] lemma mem_add : x ∈ C₁ + C₂ ↔ ∃ y ∈ C₁, ∃ z ∈ C₂, y + z = x := .rfl instance instAddZeroClass : AddZeroClass (ConvexCone R M) where zero_add _ := by ext; simp add_zero _ := by ext; simp instance instAddCommSemigroup : AddCommSemigroup (ConvexCone R M) where add_assoc _ _ _ := SetLike.coe_injective <| add_assoc _ _ _ add_comm _ _ := SetLike.coe_injective <| add_comm _ _ end Module end OrderedSemiring section Field variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup M] [Module 𝕜 M] {C : ConvexCone 𝕜 M} {s : Set M} {x : M} /-- The cone hull of a convex set is simply the union of the open halflines through that set. -/ lemma mem_hull_of_convex (hs : Convex 𝕜 s) : x ∈ hull 𝕜 s ↔ ∃ r : 𝕜, 0 < r ∧ x ∈ r • s where mp hx := hull_min (C := { carrier := {y | ∃ r : 𝕜, 0 < r ∧ y ∈ r • s} smul_mem' := by intro r₁ hr₁ y ⟨r₂, hr₂, hy⟩ refine ⟨r₁ * r₂, mul_pos hr₁ hr₂, ?_⟩ rw [mul_smul] exact smul_mem_smul_set hy add_mem' := by rintro y₁ ⟨r₁, hr₁, hy₁⟩ y₂ ⟨r₂, hr₂, hy₂⟩ refine ⟨r₁ + r₂, add_pos hr₁ hr₂, ?_⟩ rw [hs.add_smul hr₁.le hr₂.le] exact add_mem_add hy₁ hy₂ }) (fun y hy ↦ ⟨1, by simpa⟩) hx mpr := by rintro ⟨r, hr, y, hy, rfl⟩; exact (hull 𝕜 s).smul_mem hr <| subset_hull hy /-- The cone hull of a convex set is simply the union of the open halflines through that set. -/ lemma coe_hull_of_convex (hs : Convex 𝕜 s) : hull 𝕜 s = {x | ∃ r : 𝕜, 0 < r ∧ x ∈ r • s} := by ext; exact mem_hull_of_convex hs lemma disjoint_hull_left_of_convex (hs : Convex 𝕜 s) : Disjoint (hull 𝕜 s) C ↔ Disjoint s C where mp := by rw [← disjoint_coe]; exact .mono_left subset_hull mpr := by simp_rw [← disjoint_coe, disjoint_left, SetLike.mem_coe, mem_hull_of_convex hs] rintro hsC _ ⟨r, hr, y, hy, rfl⟩ exact (C.smul_mem_iff hr).not.mpr (hsC hy) lemma disjoint_hull_right_of_convex (hs : Convex 𝕜 s) : Disjoint C (hull 𝕜 s) ↔ Disjoint ↑C s := by rw [disjoint_comm, disjoint_hull_left_of_convex hs, disjoint_comm] end Field end ConvexCone namespace Submodule /-! ### Submodules are cones -/ section OrderedSemiring variable [Semiring R] [PartialOrder R] section AddCommMonoid variable [AddCommMonoid M] [Module R M] {C C₁ C₂ : Submodule R M} {x : M} /-- Every submodule is trivially a convex cone. -/ def toConvexCone (C : Submodule R M) : ConvexCone R M where carrier := C smul_mem' c _ _ hx := C.smul_mem c hx add_mem' _ hx _ hy := C.add_mem hx hy @[simp] lemma coe_toConvexCone (C : Submodule R M) : C.toConvexCone = (C : Set M) := rfl @[simp] lemma mem_toConvexCone : x ∈ C.toConvexCone ↔ x ∈ C := .rfl @[simp] lemma toConvexCone_le_toConvexCone : C₁.toConvexCone ≤ C₂.toConvexCone ↔ C₁ ≤ C₂ := .rfl @[deprecated (since := "2025-06-11")] alias toConvexCone_le_iff := toConvexCone_le_toConvexCone @[simp] lemma toConvexCone_bot : (⊥ : Submodule R M).toConvexCone = 0 := rfl @[simp] lemma toConvexCone_top : (⊤ : Submodule R M).toConvexCone = ⊤ := rfl @[simp] lemma toConvexCone_inf (C₁ C₂ : Submodule R M) : (C₁ ⊓ C₂).toConvexCone = C₁.toConvexCone ⊓ C₂.toConvexCone := rfl @[simp] lemma pointed_toConvexCone (C : Submodule R M) : C.toConvexCone.Pointed := C.zero_mem @[deprecated (since := "2025-06-11")] alias toConvexCone_pointed := pointed_toConvexCone end AddCommMonoid end OrderedSemiring end Submodule /-! ### Positive cone of an ordered module -/ namespace ConvexCone section PositiveCone variable [Semiring R] [PartialOrder R] [AddCommMonoid M] [PartialOrder M] [IsOrderedAddMonoid M] [Module R M] [PosSMulMono R M] {x : M} variable (R M) in /-- The positive cone is the convex cone formed by the set of nonnegative elements in an ordered module. -/ def positive : ConvexCone R M where carrier := Set.Ici 0 smul_mem' _ hc _ (hx : _ ≤ _) := smul_nonneg hc.le hx add_mem' _ (hx : _ ≤ _) _ (hy : _ ≤ _) := add_nonneg hx hy @[simp] lemma mem_positive : x ∈ positive R M ↔ 0 ≤ x := .rfl variable (R M) in @[simp] theorem coe_positive : ↑(positive R M) = Set.Ici (0 : M) := rfl /-- The positive cone of an ordered module is always salient. -/ lemma salient_positive {G : Type*} [AddCommGroup G] [PartialOrder G] [IsOrderedAddMonoid G] [Module R G] [PosSMulMono R G] : Salient (positive R G) := fun x hx_nonneg hx_ne_zero hx_nonpos ↦ lt_irrefl (0 : G) <| by simpa using add_pos_of_nonneg_of_pos hx_nonpos <| hx_nonneg.lt_of_ne' hx_ne_zero /-- The positive cone of an ordered module is always pointed. -/ theorem pointed_positive : Pointed (positive R M) := le_refl 0 end PositiveCone section StrictlyPositiveCone variable [Semiring R] [PartialOrder R] [AddCommGroup M] [PartialOrder M] [IsOrderedAddMonoid M] [Module R M] [PosSMulStrictMono R M] {x : M} variable (R M) in /-- The cone of strictly positive elements. Note that this naming diverges from the mathlib convention of `pos` and `nonneg` due to "positive cone" (`ConvexCone.positive`) being established terminology for the non-negative elements. -/ def strictlyPositive : ConvexCone R M where carrier := Set.Ioi 0 smul_mem' _ hc _ (hx : _ < _) := smul_pos hc hx add_mem' _ hx _ hy := add_pos hx hy @[simp] lemma mem_strictlyPositive : x ∈ strictlyPositive R M ↔ 0 < x := .rfl variable (R M) in @[simp] theorem coe_strictlyPositive : ↑(strictlyPositive R M) = Set.Ioi (0 : M) := rfl lemma strictlyPositive_le_positive : strictlyPositive R M ≤ positive R M := fun _ => le_of_lt @[deprecated (since := "2025-05-29")] alias positive_le_strictlyPositive := strictlyPositive_le_positive /-- The strictly positive cone of an ordered module is always salient. -/ theorem salient_strictlyPositive : Salient (strictlyPositive R M) := salient_positive.anti strictlyPositive_le_positive /-- The strictly positive cone of an ordered module is always blunt. -/ theorem blunt_strictlyPositive : Blunt (strictlyPositive R M) := lt_irrefl 0 end StrictlyPositiveCone end ConvexCone /-! ### Cone over a convex set -/ section ConeFromConvex variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup M] [Module 𝕜 M] namespace Convex /-- The set of vectors proportional to those in a convex set forms a convex cone. -/ def toCone (s : Set M) (hs : Convex 𝕜 s) : ConvexCone 𝕜 M := by apply ConvexCone.mk (⋃ (c : 𝕜) (_ : 0 < c), c • s) <;> simp only [mem_iUnion, mem_smul_set] · rintro c c_pos _ ⟨c', c'_pos, x, hx, rfl⟩ exact ⟨c * c', mul_pos c_pos c'_pos, x, hx, (smul_smul _ _ _).symm⟩ · rintro _ ⟨cx, cx_pos, x, hx, rfl⟩ _ ⟨cy, cy_pos, y, hy, rfl⟩ have : 0 < cx + cy := add_pos cx_pos cy_pos refine ⟨_, this, _, convex_iff_div.1 hs hx hy cx_pos.le cy_pos.le this, ?_⟩ simp only [smul_add, smul_smul, mul_div_assoc', mul_div_cancel_left₀ _ this.ne'] variable {s : Set M} (hs : Convex 𝕜 s) {x : M} theorem mem_toCone : x ∈ hs.toCone s ↔ ∃ c : 𝕜, 0 < c ∧ ∃ y ∈ s, c • y = x := by simp only [toCone, ConvexCone.mem_mk, mem_iUnion, mem_smul_set, eq_comm, exists_prop] theorem mem_toCone' : x ∈ hs.toCone s ↔ ∃ c : 𝕜, 0 < c ∧ c • x ∈ s := by refine hs.mem_toCone.trans ⟨?_, ?_⟩ · rintro ⟨c, hc, y, hy, rfl⟩ exact ⟨c⁻¹, inv_pos.2 hc, by rwa [smul_smul, inv_mul_cancel₀ hc.ne', one_smul]⟩ · rintro ⟨c, hc, hcx⟩ exact ⟨c⁻¹, inv_pos.2 hc, _, hcx, by rw [smul_smul, inv_mul_cancel₀ hc.ne', one_smul]⟩ theorem subset_toCone : s ⊆ hs.toCone s := fun x hx => hs.mem_toCone'.2 ⟨1, zero_lt_one, by rwa [one_smul]⟩ /-- `hs.toCone s` is the least cone that includes `s`. -/ theorem toCone_isLeast : IsLeast { t : ConvexCone 𝕜 M | s ⊆ t } (hs.toCone s) := by refine ⟨hs.subset_toCone, fun t ht x hx => ?_⟩ rcases hs.mem_toCone.1 hx with ⟨c, hc, y, hy, rfl⟩ exact t.smul_mem hc (ht hy) theorem toCone_eq_sInf : hs.toCone s = sInf { t : ConvexCone 𝕜 M | s ⊆ t } := hs.toCone_isLeast.isGLB.sInf_eq.symm end Convex theorem convexHull_toCone_isLeast (s : Set M) : IsLeast { t : ConvexCone 𝕜 M | s ⊆ t } ((convex_convexHull 𝕜 s).toCone _) := by convert (convex_convexHull 𝕜 s).toCone_isLeast using 1 ext t exact ⟨fun h => convexHull_min h t.convex, (subset_convexHull 𝕜 s).trans⟩ theorem convexHull_toCone_eq_sInf (s : Set M) : (convex_convexHull 𝕜 s).toCone _ = sInf { t : ConvexCone 𝕜 M | s ⊆ t } := Eq.symm <| IsGLB.sInf_eq <| IsLeast.isGLB <| convexHull_toCone_isLeast s end ConeFromConvex
.lake/packages/mathlib/Mathlib/Geometry/Convex/Cone/README.md
# Algebraic theory of convex cones This subfolder is destined to contain results about convex cones that do not require a topology, a norm nor an inner product. See the `Mathlib.Analysis.Convex.Cone` folder for the topological results. ## Topics The convex cone topics currently covered are: * Convex cones * Pointed cones * Dual cone along a bilinear pairing
.lake/packages/mathlib/Mathlib/Geometry/Convex/Cone/Pointed.lean
import Mathlib.Algebra.Order.Nonneg.Module import Mathlib.Geometry.Convex.Cone.Basic /-! # Pointed cones A *pointed cone* is defined to be a submodule of a module where the scalars are restricted to be nonnegative. This is equivalent to saying that, as a set, a pointed cone is a convex cone which contains `0`. This is a bundled version of `ConvexCone.Pointed`. We choose the submodule definition as it allows us to use the `Module` API to work with convex cones. -/ assert_not_exists TopologicalSpace Real Cardinal variable {R E F G : Type*} local notation3 "R≥0" => {c : R // 0 ≤ c} /-- A pointed cone is a submodule of a module with scalars restricted to being nonnegative. -/ abbrev PointedCone (R E) [Semiring R] [PartialOrder R] [IsOrderedRing R] [AddCommMonoid E] [Module R E] := Submodule {c : R // 0 ≤ c} E namespace PointedCone open Function section Definitions variable [Semiring R] [PartialOrder R] [IsOrderedRing R] [AddCommMonoid E] [Module R E] {C C₁ C₂ : PointedCone R E} {x : E} {r : R} /-- Every pointed cone is a convex cone. -/ @[coe] def toConvexCone (C : PointedCone R E) : ConvexCone R E where carrier := C smul_mem' c hc _ hx := C.smul_mem ⟨c, le_of_lt hc⟩ hx add_mem' _ hx _ hy := C.add_mem hx hy instance : Coe (PointedCone R E) (ConvexCone R E) where coe := toConvexCone theorem toConvexCone_injective : Injective ((↑) : PointedCone R E → ConvexCone R E) := fun _ _ => by simp [toConvexCone] @[simp] theorem pointed_toConvexCone (C : PointedCone R E) : (C : ConvexCone R E).Pointed := by simp [toConvexCone, ConvexCone.Pointed] @[simp] lemma mem_toConvexCone : x ∈ C.toConvexCone ↔ x ∈ C := .rfl @[ext] lemma ext (h : ∀ x, x ∈ C₁ ↔ x ∈ C₂) : C₁ = C₂ := SetLike.ext h lemma convex (C : PointedCone R E) : Convex R (C : Set E) := C.toConvexCone.convex instance instZero (C : PointedCone R E) : Zero C := ⟨0, C.zero_mem⟩ nonrec lemma smul_mem (C : PointedCone R E) (hr : 0 ≤ r) (hx : x ∈ C) : r • x ∈ C := C.smul_mem ⟨r, hr⟩ hx /-- The `PointedCone` constructed from a pointed `ConvexCone`. -/ def _root_.ConvexCone.toPointedCone (C : ConvexCone R E) (hC : C.Pointed) : PointedCone R E where carrier := C add_mem' hx hy := C.add_mem hx hy zero_mem' := hC smul_mem' := fun ⟨c, hc⟩ x hx => by simp_rw [SetLike.mem_coe] rcases eq_or_lt_of_le hc with hzero | hpos · unfold ConvexCone.Pointed at hC convert hC simp [← hzero] · apply ConvexCone.smul_mem · convert hpos · exact hx @[simp] lemma _root_.ConvexCone.mem_toPointedCone {C : ConvexCone R E} (hC : C.Pointed) (x : E) : x ∈ C.toPointedCone hC ↔ x ∈ C := Iff.rfl @[simp, norm_cast] lemma _root_.ConvexCone.coe_toPointedCone (C : ConvexCone R E) (hC : C.Pointed) : C.toPointedCone hC = C := rfl @[simp] lemma _root_.ConvexCone.toPointedCone_top : (⊤ : ConvexCone R E).toPointedCone trivial = ⊤ := rfl instance canLift : CanLift (ConvexCone R E) (PointedCone R E) (↑) ConvexCone.Pointed where prf C hC := ⟨C.toPointedCone hC, rfl⟩ /-- Construct a pointed cone from closure under two-element conical combinations. I.e., a nonempty set closed under two-element conical combinations is a pointed cone. -/ def ofConeComb (C : Set E) (nonempty : C.Nonempty) (coneComb : ∀ x ∈ C, ∀ y ∈ C, ∀ a : R, 0 ≤ a → ∀ b : R, 0 ≤ b → a • x + b • y ∈ C) : PointedCone R E := .ofLinearComb C nonempty fun x hx y hy ⟨a, ha⟩ ⟨b, hb⟩ => coneComb x hx y hy a ha b hb variable (R) in /-- The span of a set `s` is the smallest pointed cone that contains `s`. Pointed cones being defined as submodules over nonnegative scalars, this is exactly the submodule span of `s` w.r.t. nonnegative scalars. -/ abbrev span (s : Set E) : PointedCone R E := Submodule.span R≥0 s lemma subset_span {s : Set E} : s ⊆ PointedCone.span R s := Submodule.subset_span /-- Elements of the cone hull are expressible as conical combination of elements from s. -/ lemma mem_span_set {s : Set E} : x ∈ span R s ↔ ∃ c : E →₀ R, ↑c.support ⊆ s ∧ (∀ y, 0 ≤ c y) ∧ c.sum (fun m r => r • m) = x := by rw [Submodule.mem_span_set] constructor · rintro ⟨c, hc, rfl⟩ exact ⟨⟨c.support, Subtype.val ∘ c, by simp [← Subtype.val_inj]⟩, hc, fun y ↦ (c y).2, rfl⟩ · rintro ⟨c, hc, hc₀, rfl⟩ exact ⟨⟨c.support, fun y ↦ ⟨c y, hc₀ _⟩, by simp⟩, hc, rfl⟩ end Definitions section Maps variable [Semiring R] [PartialOrder R] [IsOrderedRing R] variable [AddCommMonoid E] [Module R E] variable [AddCommMonoid F] [Module R F] variable [AddCommMonoid G] [Module R G] /-! ## Maps between pointed cones There is already a definition of maps between submodules, `Submodule.map`. In our case, these maps are induced from linear maps between the ambient modules that are linear over nonnegative scalars. Such maps are unlikely to be of any use in practice. So, we construct some API to define maps between pointed cones induced from linear maps between the ambient modules that are linear over *all* scalars. -/ /-- The image of a pointed cone under an `R`-linear map is a pointed cone. -/ def map (f : E →ₗ[R] F) (C : PointedCone R E) : PointedCone R F := Submodule.map (f : E →ₗ[R≥0] F) C @[simp, norm_cast] theorem toConvexCone_map (C : PointedCone R E) (f : E →ₗ[R] F) : (C.map f : ConvexCone R F) = (C : ConvexCone R E).map f := rfl @[simp, norm_cast] theorem coe_map (C : PointedCone R E) (f : E →ₗ[R] F) : (C.map f : Set F) = f '' C := rfl @[simp] theorem mem_map {f : E →ₗ[R] F} {C : PointedCone R E} {y : F} : y ∈ C.map f ↔ ∃ x ∈ C, f x = y := Iff.rfl theorem map_map (g : F →ₗ[R] G) (f : E →ₗ[R] F) (C : PointedCone R E) : (C.map f).map g = C.map (g.comp f) := SetLike.coe_injective <| Set.image_image g f C @[simp] theorem map_id (C : PointedCone R E) : C.map LinearMap.id = C := SetLike.coe_injective <| Set.image_id _ /-- The preimage of a pointed cone under an `R`-linear map is a pointed cone. -/ def comap (f : E →ₗ[R] F) (C : PointedCone R F) : PointedCone R E := Submodule.comap (f : E →ₗ[R≥0] F) C @[simp, norm_cast] theorem coe_comap (f : E →ₗ[R] F) (C : PointedCone R F) : (C.comap f : Set E) = f ⁻¹' C := rfl @[simp] theorem comap_id (C : PointedCone R E) : C.comap LinearMap.id = C := rfl theorem comap_comap (g : F →ₗ[R] G) (f : E →ₗ[R] F) (C : PointedCone R G) : (C.comap g).comap f = C.comap (g.comp f) := rfl @[simp] theorem mem_comap {f : E →ₗ[R] F} {C : PointedCone R F} {x : E} : x ∈ C.comap f ↔ f x ∈ C := Iff.rfl end Maps section PositiveCone variable (R E) variable [Semiring R] [PartialOrder R] [IsOrderedRing R] variable [AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module R E] [PosSMulMono R E] /-- The positive cone is the pointed cone formed by the set of nonnegative elements in an ordered module. -/ def positive : PointedCone R E := (ConvexCone.positive R E).toPointedCone ConvexCone.pointed_positive @[simp] theorem mem_positive {x : E} : x ∈ positive R E ↔ 0 ≤ x := Iff.rfl @[simp, norm_cast] theorem toConvexCone_positive : ↑(positive R E) = ConvexCone.positive R E := rfl end PositiveCone section OrderedAddCommGroup variable [Ring R] [PartialOrder R] [IsOrderedRing R] [AddCommGroup E] [PartialOrder E] [IsOrderedAddMonoid E] [Module R E] /-- Constructs an ordered module given an ordered group, a cone, and a proof that the order relation is the one defined by the cone. -/ lemma to_isOrderedModule (C : PointedCone R E) (h : ∀ x y : E, x ≤ y ↔ y - x ∈ C) : IsOrderedModule R E := .of_smul_nonneg <| by simp +contextual [h, C.smul_mem] end OrderedAddCommGroup end PointedCone
.lake/packages/mathlib/Mathlib/Geometry/Convex/Cone/Dual.lean
import Mathlib.Algebra.Module.Submodule.Pointwise import Mathlib.Geometry.Convex.Cone.Pointed /-! # The algebraic dual of a cone Given a bilinear pairing `p` between two `R`-modules `M` and `N` and a set `s` in `M`, we define `PointedCone.dual p s` to be the pointed cone in `N` consisting of all points `y` such that `0 ≤ p x y` for all `x ∈ s`. When the pairing is perfect, this gives us the algebraic dual of a cone. This is developed here. When the pairing is continuous and perfect (as a continuous pairing), this gives us the topological dual instead. See `Mathlib/Analysis/Convex/Cone/Dual.lean` for that case. ## Implementation notes We do not provide a `ConvexCone`-valued version of `PointedCone.dual` since the dual cone of any set always contains `0`, i.e. is a pointed cone. Furthermore, the strict version `{y | ∀ x ∈ s, 0 < p x y}` is a candidate to the name `ConvexCone.dual`. ## TODO Deduce from `dual_flip_dual_dual_flip` that polyhedral cones are invariant under taking double duals -/ assert_not_exists TopologicalSpace Real Cardinal open Function LinearMap Pointwise Set namespace PointedCone variable {R M N : Type*} [CommRing R] [PartialOrder R] [IsOrderedRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {p : M →ₗ[R] N →ₗ[R] R} {s t : Set M} {y : N} local notation3 "R≥0" => {c : R // 0 ≤ c} variable (p s) in /-- The dual cone of a set `s` with respect to a bilinear pairing `p` is the cone consisting of all points `y` such that for all points `x ∈ s` we have `0 ≤ p x y`. -/ def dual (s : Set M) : PointedCone R N where carrier := {y | ∀ ⦃x⦄, x ∈ s → 0 ≤ p x y} zero_mem' := by simp add_mem' {u v} hu hv x hx := by rw [map_add]; exact add_nonneg (hu hx) (hv hx) smul_mem' c y hy x hx := by rw [← Nonneg.coe_smul, map_smul]; exact mul_nonneg c.2 (hy hx) @[simp] lemma mem_dual : y ∈ dual p s ↔ ∀ ⦃x⦄, x ∈ s → 0 ≤ p x y := .rfl @[simp] lemma dual_empty : dual p ∅ = ⊤ := by ext; simp @[simp] lemma dual_zero : dual p 0 = ⊤ := by ext; simp lemma dual_univ (hp : Injective p.flip) : dual p univ = 0 := by refine le_antisymm (fun y hy ↦ (_root_.map_eq_zero_iff p.flip hp).1 ?_) (by simp) ext x exact (hy <| mem_univ x).antisymm' <| by simpa using hy <| mem_univ (-x) @[gcongr] lemma dual_le_dual (h : t ⊆ s) : dual p s ≤ dual p t := fun _y hy _x hx ↦ hy (h hx) /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `p x`. -/ lemma dual_singleton (x : M) : dual p {x} = (positive R R).comap (p x) := by ext; simp lemma dual_union (s t : Set M) : dual p (s ∪ t) = dual p s ⊓ dual p t := by aesop lemma dual_insert (x : M) (s : Set M) : dual p (insert x s) = dual p {x} ⊓ dual p s := by rw [insert_eq, dual_union] lemma dual_iUnion {ι : Sort*} (f : ι → Set M) : dual p (⋃ i, f i) = ⨅ i, dual p (f i) := by ext; simp [forall_swap (α := M)] lemma dual_sUnion (S : Set (Set M)) : dual p (⋃₀ S) = sInf (dual p '' S) := by ext; simp [forall_swap (α := M)] /-- The dual cone of `s` equals the intersection of dual cones of the points in `s`. -/ lemma dual_eq_iInter_dual_singleton (s : Set M) : dual p s = ⋂ i : s, (dual p {i.val} : Set N) := by ext; simp /-- Any set is a subset of its double dual cone. -/ lemma subset_dual_dual : s ⊆ dual p.flip (dual p s) := fun _x hx _y hy ↦ hy hx variable (s) in @[simp] lemma dual_dual_flip_dual : dual p (dual p.flip (dual p s)) = dual p s := le_antisymm (dual_le_dual subset_dual_dual) subset_dual_dual @[simp] lemma dual_flip_dual_dual_flip (s : Set N) : dual p.flip (dual p (dual p.flip s)) = dual p.flip s := dual_dual_flip_dual _ @[simp] lemma dual_span (s : Set M) : dual p (span R s) = dual p s := by refine le_antisymm (dual_le_dual Submodule.subset_span) (fun x hx y hy => ?_) induction hy using Submodule.span_induction with | mem _y h => exact hx h | zero => simp | add y z _hy _hz hy hz => rw [map_add, add_apply]; exact add_nonneg hy hz | smul t y _hy hy => rw [map_smul_of_tower, Nonneg.mk_smul, smul_apply]; exact mul_nonneg t.2 hy end PointedCone
.lake/packages/mathlib/Mathlib/Geometry/Manifold/ContMDiffMFDeriv.lean
import Mathlib.Geometry.Manifold.MFDeriv.Tangent import Mathlib.Geometry.Manifold.ContMDiffMap import Mathlib.Geometry.Manifold.VectorBundle.Hom /-! ### Interactions between differentiability, smoothness and manifold derivatives We give the relation between `MDifferentiable`, `ContMDiff`, `mfderiv`, `tangentMap` and related notions. ## Main statements * `ContMDiffOn.contMDiffOn_tangentMapWithin` states that the bundled derivative of a `Cⁿ` function in a domain is `Cᵐ` when `m + 1 ≤ n`. * `ContMDiff.contMDiff_tangentMap` states that the bundled derivative of a `Cⁿ` function is `Cᵐ` when `m + 1 ≤ n`. -/ open Set Function Filter ChartedSpace IsManifold Bundle open scoped Topology Manifold Bundle /-! ### Definition of `C^n` functions between manifolds -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {m n : WithTop ℕ∞} -- declare a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- declare a charted space `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] -- declare a `C^n` manifold `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] [Js : IsManifold J 1 N] -- declare a charted space `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] -- declare functions, sets {f : M → M'} {s : Set M} /-! ### The derivative of a `C^(n+1)` function is `C^n` -/ section mfderiv variable [Is : IsManifold I 1 M] [I's : IsManifold I' 1 M'] /-- The function that sends `x` to the `y`-derivative of `f (x, y)` at `g (x)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `(x₀, g(x₀))` for `n ≥ m + 1` and `g` is `C^m` at `x₀`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. Version within a set. -/ protected theorem ContMDiffWithinAt.mfderivWithin {x₀ : N} {f : N → M → M'} {g : N → M} {t : Set N} {u : Set M} (hf : ContMDiffWithinAt (J.prod I) I' n (Function.uncurry f) (t ×ˢ u) (x₀, g x₀)) (hg : ContMDiffWithinAt J I m g t x₀) (hx₀ : x₀ ∈ t) (hu : MapsTo g t u) (hmn : m + 1 ≤ n) (h'u : UniqueMDiffOn I u) : ContMDiffWithinAt J 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' g (fun x => f x (g x)) (fun x => mfderivWithin I I' (f x) u (g x)) x₀) t x₀ := by -- first localize the result to a smaller set, to make sure everything happens in chart domains let t' := t ∩ g ⁻¹' ((extChartAt I (g x₀)).source) have ht't : t' ⊆ t := inter_subset_left suffices ContMDiffWithinAt J 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' g (fun x ↦ f x (g x)) (fun x ↦ mfderivWithin I I' (f x) u (g x)) x₀) t' x₀ by apply ContMDiffWithinAt.mono_of_mem_nhdsWithin this apply inter_mem self_mem_nhdsWithin exact hg.continuousWithinAt.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds (g x₀)) -- register a few basic facts that maps send suitable neighborhoods to suitable neighborhoods, -- by continuity have hx₀gx₀ : (x₀, g x₀) ∈ t ×ˢ u := by simp [hx₀, hu hx₀] have h4f : ContinuousWithinAt (fun x => f x (g x)) t x₀ := by change ContinuousWithinAt ((Function.uncurry f) ∘ (fun x ↦ (x, g x))) t x₀ refine ContinuousWithinAt.comp hf.continuousWithinAt ?_ (fun y hy ↦ by simp [hy, hu hy]) exact (continuousWithinAt_id.prodMk hg.continuousWithinAt) have h4f := h4f.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds (I := I') (f x₀ (g x₀))) have h3f := (contMDiffWithinAt_iff_contMDiffWithinAt_nhdsWithin (by simp)).mp (hf.of_le <| (self_le_add_left 1 m).trans hmn) simp only [hx₀gx₀, insert_eq_of_mem] at h3f have h2f : ∀ᶠ x₂ in 𝓝[t] x₀, ContMDiffWithinAt I I' 1 (f x₂) u (g x₂) := by have : MapsTo (fun x ↦ (x, g x)) t (t ×ˢ u) := fun y hy ↦ by simp [hy, hu hy] filter_upwards [((continuousWithinAt_id.prodMk hg.continuousWithinAt) |>.tendsto_nhdsWithin this).eventually h3f, self_mem_nhdsWithin] with x hx h'x apply hx.comp (g x) (contMDiffWithinAt_const.prodMk contMDiffWithinAt_id) exact fun y hy ↦ by simp [h'x, hy] have h2g : g ⁻¹' (extChartAt I (g x₀)).source ∈ 𝓝[t] x₀ := hg.continuousWithinAt.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds (g x₀)) -- key point: the derivative of `f` composed with extended charts, at the point `g x` read in the -- chart, is `C^n` in the vector space sense. This follows from `ContDiffWithinAt.fderivWithin`, -- which is the vector space analogue of the result we are proving. have : ContDiffWithinAt 𝕜 m (fun x ↦ fderivWithin 𝕜 (extChartAt I' (f x₀ (g x₀)) ∘ f ((extChartAt J x₀).symm x) ∘ (extChartAt I (g x₀)).symm) ((extChartAt I (g x₀)).target ∩ (extChartAt I (g x₀)).symm ⁻¹' u) (extChartAt I (g x₀) (g ((extChartAt J x₀).symm x)))) ((extChartAt J x₀).symm ⁻¹' t' ∩ range J) (extChartAt J x₀ x₀) := by have hf' := hf.mono (prod_mono_left ht't) have hg' := hg.mono (show t' ⊆ t from inter_subset_left) rw [contMDiffWithinAt_iff] at hf' hg' simp_rw [Function.comp_def, uncurry, extChartAt_prod, PartialEquiv.prod_coe_symm, ModelWithCorners.range_prod] at hf' ⊢ apply ContDiffWithinAt.fderivWithin _ _ _ (show (m : WithTop ℕ∞) + 1 ≤ n from mod_cast hmn ) · simp [hx₀, t'] · apply inter_subset_left.trans rw [preimage_subset_iff] intro a ha refine ⟨PartialEquiv.map_source _ (inter_subset_right ha :), ?_⟩ rw [mem_preimage, PartialEquiv.left_inv (extChartAt I (g x₀))] · exact hu (inter_subset_left ha) · exact (inter_subset_right ha :) · have : ((fun p ↦ ((extChartAt J x₀).symm p.1, (extChartAt I (g x₀)).symm p.2)) ⁻¹' t' ×ˢ u ∩ range J ×ˢ (extChartAt I (g x₀)).target) ⊆ ((fun p ↦ ((extChartAt J x₀).symm p.1, (extChartAt I (g x₀)).symm p.2)) ⁻¹' t' ×ˢ u ∩ range J ×ˢ range I) := by apply inter_subset_inter_right exact Set.prod_mono_right (extChartAt_target_subset_range (g x₀)) convert hf'.2.mono this · ext y; simp; tauto · simp · exact hg'.2 · exact UniqueMDiffOn.uniqueDiffOn_target_inter h'u (g x₀) -- reformulate the previous point as `C^n` in the manifold sense (but still for a map between -- vector spaces) have : ContMDiffWithinAt J 𝓘(𝕜, E →L[𝕜] E') m (fun x => fderivWithin 𝕜 (extChartAt I' (f x₀ (g x₀)) ∘ f x ∘ (extChartAt I (g x₀)).symm) ((extChartAt I (g x₀)).target ∩ (extChartAt I (g x₀)).symm ⁻¹' u) (extChartAt I (g x₀) (g x))) t' x₀ := by simp_rw [contMDiffWithinAt_iff_source (x := x₀), contMDiffWithinAt_iff_contDiffWithinAt, Function.comp_def] exact this -- finally, argue that the map we control in the previous point coincides locally with the map we -- want to prove the regularity of, so regularity of the latter follows from regularity of the -- former. apply this.congr_of_eventuallyEq_of_mem _ (by simp [t', hx₀]) apply nhdsWithin_mono _ ht't filter_upwards [h2f, h4f, h2g, self_mem_nhdsWithin] with x hx h'x h2 hxt have h1 : g x ∈ u := hu hxt have h3 : UniqueMDiffWithinAt 𝓘(𝕜, E) ((extChartAt I (g x₀)).target ∩ (extChartAt I (g x₀)).symm ⁻¹' u) ((extChartAt I (g x₀)) (g x)) := by apply UniqueDiffWithinAt.uniqueMDiffWithinAt apply UniqueMDiffOn.uniqueDiffOn_target_inter h'u refine ⟨PartialEquiv.map_source _ h2, ?_⟩ rwa [mem_preimage, PartialEquiv.left_inv _ h2] have A : mfderivWithin 𝓘(𝕜, E) I ((extChartAt I (g x₀)).symm) (range I) ((extChartAt I (g x₀)) (g x)) = mfderivWithin 𝓘(𝕜, E) I ((extChartAt I (g x₀)).symm) ((extChartAt I (g x₀)).target ∩ (extChartAt I (g x₀)).symm ⁻¹' u) ((extChartAt I (g x₀)) (g x)) := by apply (MDifferentiableWithinAt.mfderivWithin_mono _ h3 _).symm · apply mdifferentiableWithinAt_extChartAt_symm exact PartialEquiv.map_source (extChartAt I (g x₀)) h2 · exact inter_subset_left.trans (extChartAt_target_subset_range (g x₀)) rw [inTangentCoordinates_eq_mfderiv_comp, A, ← mfderivWithin_comp_of_eq, ← mfderiv_comp_mfderivWithin_of_eq] · exact mfderivWithin_eq_fderivWithin · exact mdifferentiableAt_extChartAt (by simpa using h'x) · apply MDifferentiableWithinAt.comp (I' := I) (u := u) _ _ _ inter_subset_right · convert hx.mdifferentiableWithinAt le_rfl exact PartialEquiv.left_inv (extChartAt I (g x₀)) h2 · apply (mdifferentiableWithinAt_extChartAt_symm _).mono · exact inter_subset_left.trans (extChartAt_target_subset_range (g x₀)) · exact PartialEquiv.map_source (extChartAt I (g x₀)) h2 · exact h3 · simp only [Function.comp_def, PartialEquiv.left_inv (extChartAt I (g x₀)) h2] · exact hx.mdifferentiableWithinAt le_rfl · apply (mdifferentiableWithinAt_extChartAt_symm _).mono · exact inter_subset_left.trans (extChartAt_target_subset_range (g x₀)) · exact PartialEquiv.map_source (extChartAt I (g x₀)) h2 · exact inter_subset_right · exact h3 · exact PartialEquiv.left_inv (extChartAt I (g x₀)) h2 · simpa using h2 · simpa using h'x /-- The derivative `D_yf(y)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `x₀` for some `n ≥ m + 1`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. This is a special case of `ContMDiffWithinAt.mfderivWithin` where `f` does not contain any parameters and `g = id`. -/ theorem ContMDiffWithinAt.mfderivWithin_const {x₀ : M} {f : M → M'} (hf : ContMDiffWithinAt I I' n f s x₀) (hmn : m + 1 ≤ n) (hx : x₀ ∈ s) (hs : UniqueMDiffOn I s) : ContMDiffWithinAt I 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' id f (mfderivWithin I I' f s) x₀) s x₀ := by have : ContMDiffWithinAt (I.prod I) I' n (fun x : M × M => f x.2) (s ×ˢ s) (x₀, x₀) := ContMDiffWithinAt.comp (x₀, x₀) hf contMDiffWithinAt_snd mapsTo_snd_prod exact this.mfderivWithin contMDiffWithinAt_id hx (mapsTo_id _) hmn hs /-- The function that sends `x` to the `y`-derivative of `f(x,y)` at `g(x)` applied to `g₂(x)` is `C^n` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^(n+1)` at `(x₀, g(x₀))` and `g` is `C^n` at `x₀`. We have to insert a coordinate change from `x₀` to `g₁(x)` to make the derivative sensible. This is similar to `ContMDiffWithinAt.mfderivWithin`, but where the continuous linear map is applied to a (variable) vector. -/ theorem ContMDiffWithinAt.mfderivWithin_apply {x₀ : N'} {f : N → M → M'} {g : N → M} {g₁ : N' → N} {g₂ : N' → E} {t : Set N} {u : Set M} {v : Set N'} (hf : ContMDiffWithinAt (J.prod I) I' n (Function.uncurry f) (t ×ˢ u) (g₁ x₀, g (g₁ x₀))) (hg : ContMDiffWithinAt J I m g t (g₁ x₀)) (hg₁ : ContMDiffWithinAt J' J m g₁ v x₀) (hg₂ : ContMDiffWithinAt J' 𝓘(𝕜, E) m g₂ v x₀) (hmn : m + 1 ≤ n) (h'g₁ : MapsTo g₁ v t) (hg₁x₀ : g₁ x₀ ∈ t) (h'g : MapsTo g t u) (hu : UniqueMDiffOn I u) : ContMDiffWithinAt J' 𝓘(𝕜, E') m (fun x => (inTangentCoordinates I I' g (fun x => f x (g x)) (fun x => mfderivWithin I I' (f x) u (g x)) (g₁ x₀) (g₁ x)) (g₂ x)) v x₀ := ((hf.mfderivWithin hg hg₁x₀ h'g hmn hu).comp_of_eq hg₁ h'g₁ rfl).clm_apply hg₂ /-- The function that sends `x` to the `y`-derivative of `f (x, y)` at `g (x)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `(x₀, g(x₀))` for `n ≥ m + 1` and `g` is `C^m` at `x₀`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. This result is used to show that maps into the 1-jet bundle and cotangent bundle are `C^n`. `ContMDiffAt.mfderiv_const` is a special case of this. -/ protected theorem ContMDiffAt.mfderiv {x₀ : N} (f : N → M → M') (g : N → M) (hf : ContMDiffAt (J.prod I) I' n (Function.uncurry f) (x₀, g x₀)) (hg : ContMDiffAt J I m g x₀) (hmn : m + 1 ≤ n) : ContMDiffAt J 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' g (fun x ↦ f x (g x)) (fun x ↦ mfderiv I I' (f x) (g x)) x₀) x₀ := by rw [← contMDiffWithinAt_univ] at hf hg ⊢ rw [← univ_prod_univ] at hf simp_rw [← mfderivWithin_univ] exact ContMDiffWithinAt.mfderivWithin hf hg (mem_univ _) (mapsTo_univ _ _) hmn uniqueMDiffOn_univ /-- The derivative `D_yf(y)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `x₀` for some `n ≥ m + 1`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. This is a special case of `ContMDiffAt.mfderiv` where `f` does not contain any parameters and `g = id`. -/ theorem ContMDiffAt.mfderiv_const {x₀ : M} {f : M → M'} (hf : ContMDiffAt I I' n f x₀) (hmn : m + 1 ≤ n) : ContMDiffAt I 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' id f (mfderiv I I' f) x₀) x₀ := haveI : ContMDiffAt (I.prod I) I' n (fun x : M × M => f x.2) (x₀, x₀) := ContMDiffAt.comp (x₀, x₀) hf contMDiffAt_snd this.mfderiv (fun _ => f) id contMDiffAt_id hmn /-- The function that sends `x` to the `y`-derivative of `f(x,y)` at `g(x)` applied to `g₂(x)` is `C^n` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^(n+1)` at `(x₀, g(x₀))` and `g` is `C^n` at `x₀`. We have to insert a coordinate change from `x₀` to `g₁(x)` to make the derivative sensible. This is similar to `ContMDiffAt.mfderiv`, but where the continuous linear map is applied to a (variable) vector. -/ theorem ContMDiffAt.mfderiv_apply {x₀ : N'} (f : N → M → M') (g : N → M) (g₁ : N' → N) (g₂ : N' → E) (hf : ContMDiffAt (J.prod I) I' n (Function.uncurry f) (g₁ x₀, g (g₁ x₀))) (hg : ContMDiffAt J I m g (g₁ x₀)) (hg₁ : ContMDiffAt J' J m g₁ x₀) (hg₂ : ContMDiffAt J' 𝓘(𝕜, E) m g₂ x₀) (hmn : m + 1 ≤ n) : ContMDiffAt J' 𝓘(𝕜, E') m (fun x => inTangentCoordinates I I' g (fun x => f x (g x)) (fun x => mfderiv I I' (f x) (g x)) (g₁ x₀) (g₁ x) (g₂ x)) x₀ := ((hf.mfderiv f g hg hmn).comp_of_eq hg₁ rfl).clm_apply hg₂ end mfderiv /-! ### The tangent map of a `C^(n+1)` function is `C^n` -/ section tangentMap variable [Is : IsManifold I 1 M] [I's : IsManifold I' 1 M'] /-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/ theorem ContMDiffOn.contMDiffOn_tangentMapWithin (hf : ContMDiffOn I I' n f s) (hmn : m + 1 ≤ n) (hs : UniqueMDiffOn I s) : ContMDiffOn I.tangent I'.tangent m (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := by intro x₀ hx₀ let s' : Set (TangentBundle I M) := (π E (TangentSpace I) ⁻¹' s) let b₁ : TangentBundle I M → M := fun p ↦ p.1 let v : Π (y : TangentBundle I M), TangentSpace I (b₁ y) := fun y ↦ y.2 have hv : ContMDiffWithinAt I.tangent I.tangent m (fun y ↦ (v y : TangentBundle I M)) s' x₀ := contMDiffWithinAt_id let b₂ : TangentBundle I M → M' := f ∘ b₁ have hb₂ : ContMDiffWithinAt I.tangent I' m b₂ s' x₀ := ((hf (b₁ x₀) hx₀).of_le (le_self_add.trans hmn)).comp _ (contMDiffWithinAt_proj (TangentSpace I)) (fun x h ↦ h) let ϕ : Π (y : TangentBundle I M), TangentSpace I (b₁ y) →L[𝕜] TangentSpace I' (b₂ y) := fun y ↦ mfderivWithin I I' f s (b₁ y) have hϕ : ContMDiffWithinAt I.tangent 𝓘(𝕜, E →L[𝕜] E') m (fun y ↦ ContinuousLinearMap.inCoordinates E (TangentSpace I (M := M)) E' (TangentSpace I' (M := M')) (b₁ x₀) (b₁ y) (b₂ x₀) (b₂ y) (ϕ y)) s' x₀ := by have A : ContMDiffWithinAt I 𝓘(𝕜, E →L[𝕜] E') m (fun y ↦ ContinuousLinearMap.inCoordinates E (TangentSpace I (M := M)) E' (TangentSpace I' (M := M')) (b₁ x₀) y (b₂ x₀) (f y) (mfderivWithin I I' f s y)) s (b₁ x₀) := ContMDiffWithinAt.mfderivWithin_const (hf _ hx₀) hmn hx₀ hs exact A.comp _ (contMDiffWithinAt_proj (TangentSpace I)) (fun x h ↦ h) exact ContMDiffWithinAt.clm_apply_of_inCoordinates hϕ hv hb₂ /-- If a function is `C^n` on a domain with unique derivatives, with `1 ≤ n`, then its bundled derivative is continuous there. -/ theorem ContMDiffOn.continuousOn_tangentMapWithin (hf : ContMDiffOn I I' n f s) (hmn : 1 ≤ n) (hs : UniqueMDiffOn I s) : ContinuousOn (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := by have : ContMDiffOn I.tangent I'.tangent 0 (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := hf.contMDiffOn_tangentMapWithin hmn hs exact this.continuousOn /-- If a function is `C^n`, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/ theorem ContMDiff.contMDiff_tangentMap (hf : ContMDiff I I' n f) (hmn : m + 1 ≤ n) : ContMDiff I.tangent I'.tangent m (tangentMap I I' f) := by rw [← contMDiffOn_univ] at hf ⊢ convert hf.contMDiffOn_tangentMapWithin hmn uniqueMDiffOn_univ rw [tangentMapWithin_univ] /-- If a function is `C^n`, with `1 ≤ n`, then its bundled derivative is continuous. -/ theorem ContMDiff.continuous_tangentMap (hf : ContMDiff I I' n f) (hmn : 1 ≤ n) : Continuous (tangentMap I I' f) := by rw [← contMDiffOn_univ] at hf rw [← continuousOn_univ] convert hf.continuousOn_tangentMapWithin hmn uniqueMDiffOn_univ rw [tangentMapWithin_univ] end tangentMap namespace TangentBundle open Bundle /-- The derivative of the zero section of the tangent bundle maps `⟨x, v⟩` to `⟨⟨x, 0⟩, ⟨v, 0⟩⟩`. Note that, as currently framed, this is a statement in coordinates, thus reliant on the choice of the coordinate system we use on the tangent bundle. However, the result itself is coordinate-dependent only to the extent that the coordinates determine a splitting of the tangent bundle. Moreover, there is a canonical splitting at each point of the zero section (since there is a canonical horizontal space there, the tangent space to the zero section, in addition to the canonical vertical space which is the kernel of the derivative of the projection), and this canonical splitting is also the one that comes from the coordinates on the tangent bundle in our definitions. So this statement is not as crazy as it may seem. TODO define splittings of vector bundles; state this result invariantly. -/ theorem tangentMap_tangentBundle_pure [Is : IsManifold I 1 M] (p : TangentBundle I M) : tangentMap I I.tangent (zeroSection E (TangentSpace I)) p = ⟨⟨p.proj, 0⟩, ⟨p.2, 0⟩⟩ := by rcases p with ⟨x, v⟩ have N : I.symm ⁻¹' (chartAt H x).target ∈ 𝓝 (I ((chartAt H x) x)) := by apply IsOpen.mem_nhds · apply (OpenPartialHomeomorph.open_target _).preimage I.continuous_invFun · simp only [mfld_simps] have A : MDifferentiableAt I I.tangent (fun x => @TotalSpace.mk M E (TangentSpace I) x 0) x := haveI : ContMDiff I (I.prod 𝓘(𝕜, E)) ⊤ (zeroSection E (TangentSpace I : M → Type _)) := Bundle.contMDiff_zeroSection 𝕜 (TangentSpace I : M → Type _) this.mdifferentiableAt le_top have B : fderivWithin 𝕜 (fun x' : E ↦ (x', (0 : E))) (Set.range I) (I ((chartAt H x) x)) v = (v, 0) := by rw [fderivWithin_eq_fderiv, DifferentiableAt.fderiv_prodMk] · simp · exact differentiableAt_fun_id · exact differentiableAt_const _ · exact ModelWithCorners.uniqueDiffWithinAt_image I · exact differentiableAt_id.prodMk (differentiableAt_const _) simp +unfoldPartialApp only [Bundle.zeroSection, tangentMap, mfderiv, A, if_pos, chartAt, FiberBundle.chartedSpace_chartAt, TangentBundle.trivializationAt_apply, Function.comp_def, ContinuousLinearMap.map_zero, mfld_simps] rw [← fderivWithin_inter N] at B rw [← fderivWithin_inter N, ← B] congr 1 refine fderivWithin_congr (fun y hy => ?_) ?_ · simp only [mfld_simps] at hy simp only [hy, mfld_simps] · simp only [mfld_simps] end TangentBundle namespace ContMDiffMap -- These helpers for dot notation have been moved here from -- `Mathlib/Geometry/Manifold/ContMDiffMap.lean` to avoid needing to import this file there. -- (However as a consequence we import `Mathlib/Geometry/Manifold/ContMDiffMap.lean` here now.) -- They could be moved to another file (perhaps a new file) if desired. open scoped Manifold ContDiff protected theorem mdifferentiable' (f : C^n⟮I, M; I', M'⟯) (hn : 1 ≤ n) : MDifferentiable I I' f := f.contMDiff.mdifferentiable hn protected theorem mdifferentiable (f : C^∞⟮I, M; I', M'⟯) : MDifferentiable I I' f := f.contMDiff.mdifferentiable (mod_cast le_top) protected theorem mdifferentiableAt (f : C^∞⟮I, M; I', M'⟯) {x} : MDifferentiableAt I I' f x := f.mdifferentiable x end ContMDiffMap section EquivTangentBundleProd variable (I I' M M') in /-- The tangent bundle of a product is canonically isomorphic to the product of the tangent bundles. -/ @[simps] def equivTangentBundleProd : TangentBundle (I.prod I') (M × M') ≃ (TangentBundle I M) × (TangentBundle I' M') where toFun p := (⟨p.1.1, p.2.1⟩, ⟨p.1.2, p.2.2⟩) invFun p := ⟨(p.1.1, p.2.1), (p.1.2, p.2.2)⟩ lemma equivTangentBundleProd_eq_tangentMap_prod_tangentMap : equivTangentBundleProd I M I' M' = fun (p : TangentBundle (I.prod I') (M × M')) ↦ (tangentMap (I.prod I') I Prod.fst p, tangentMap (I.prod I') I' Prod.snd p) := by simp only [tangentMap_prodFst, tangentMap_prodSnd]; rfl variable [IsManifold I 1 M] [IsManifold I' 1 M'] /-- The canonical equivalence between the tangent bundle of a product and the product of tangent bundles is smooth. -/ lemma contMDiff_equivTangentBundleProd : ContMDiff (I.prod I').tangent (I.tangent.prod I'.tangent) n (equivTangentBundleProd I M I' M') := by rw [equivTangentBundleProd_eq_tangentMap_prod_tangentMap] exact (contMDiff_fst.contMDiff_tangentMap le_rfl).prodMk (contMDiff_snd.contMDiff_tangentMap le_rfl) /-- The canonical equivalence between the product of tangent bundles and the tangent bundle of a product is smooth. -/ lemma contMDiff_equivTangentBundleProd_symm : ContMDiff (I.tangent.prod I'.tangent) (I.prod I').tangent n (equivTangentBundleProd I M I' M').symm := by /- Contrary to what one might expect, this proof is nontrivial. It is not a formalization issue: even on paper, I don't have a simple proof of the statement. The reason is that there is no nice functorial expression for the map from `TM × T'M` to `T (M × M')`, so I need to come back to the definition and break things into pieces. The argument goes as follows. Since we're looking at a map into a vector bundle whose basis map is smooth, it suffices to check the smoothness of the second component, in a chart. It lands in a product vector space `E × E'`, so it suffices to check that the composition with each projection to `E` and `E'` is smooth. We notice that the composition of this map with the first projection coincides with the projection `TM × TM' → TM` read in the target chart, which is smooth, so we're done. The issue is with checking differentiability everywhere (to justify that the derivative of a product is the product of the derivatives), and writing down things. -/ rintro ⟨a, b⟩ have U w w' : UniqueDiffWithinAt 𝕜 (Set.range (Prod.map I I')) (I w, I' w') := by simp only [range_prodMap] apply UniqueDiffWithinAt.prod · exact ModelWithCorners.uniqueDiffWithinAt_image I · exact ModelWithCorners.uniqueDiffWithinAt_image I' rw [contMDiffAt_totalSpace] simp only [equivTangentBundleProd, TangentBundle.trivializationAt_apply, mfld_simps, Equiv.coe_fn_symm_mk] refine ⟨?_, (contMDiffAt_prod_module_iff _).2 ⟨?_, ?_⟩⟩ · exact ContMDiffAt.prodMap (contMDiffAt_proj (TangentSpace I)) (contMDiffAt_proj (TangentSpace I')) · /- check that the composition with the first projection in the target chart is smooth. For this, we check that it coincides locally with the projection `pM : TM × TM' → TM` read in the target chart, which is obviously smooth. -/ have smooth_pM : ContMDiffAt (I.tangent.prod I'.tangent) I.tangent n Prod.fst (a, b) := contMDiffAt_fst apply (contMDiffAt_totalSpace.1 smooth_pM).2.congr_of_eventuallyEq filter_upwards [chart_source_mem_nhds (ModelProd (ModelProd H E) (ModelProd H' E')) (a, b)] with p hp -- now we have to check that the original map coincides locally with `pM` read in target chart. simp only [prodChartedSpace_chartAt, OpenPartialHomeomorph.prod_toPartialEquiv, PartialEquiv.prod_source, Set.mem_prod, TangentBundle.mem_chart_source_iff] at hp let φ (x : E) := I ((chartAt H a.proj) ((chartAt H p.1.proj).symm (I.symm x))) have D0 : DifferentiableWithinAt 𝕜 φ (Set.range I) (I ((chartAt H p.1.proj) p.1.proj)) := by apply ContDiffWithinAt.differentiableWithinAt (n := 1) _ le_rfl apply contDiffWithinAt_ext_coord_change simp [hp.1] have D (w : TangentBundle I' M') : DifferentiableWithinAt 𝕜 (φ ∘ (Prod.fst : E × E' → E)) (Set.range (Prod.map ↑I ↑I')) (I ((chartAt H p.1.proj) p.1.proj), I' ((chartAt H' w.proj) w.proj)) := DifferentiableWithinAt.comp (t := Set.range I) _ (by exact D0) differentiableWithinAt_fst (by simp [mapsTo_fst_prod]) simp only [comp_def, comp_apply] rw [DifferentiableWithinAt.fderivWithin_prodMk (by exact D _) ?_ (U _ _)]; swap · let φ' (x : E') := I' ((chartAt H' b.proj) ((chartAt H' p.2.proj).symm (I'.symm x))) have D0' : DifferentiableWithinAt 𝕜 φ' (Set.range I') (I' ((chartAt H' p.2.proj) p.2.proj)) := by apply ContDiffWithinAt.differentiableWithinAt (n := 1) _ le_rfl apply contDiffWithinAt_ext_coord_change simp [hp.2] have D' : DifferentiableWithinAt 𝕜 (φ' ∘ Prod.snd) (Set.range (Prod.map I I')) (I ((chartAt H p.1.proj) p.1.proj), I' ((chartAt H' p.2.proj) p.2.proj)) := DifferentiableWithinAt.comp (t := Set.range I') _ (by exact D0') differentiableWithinAt_snd (by simp [mapsTo_snd_prod]) exact D' simp only [TangentBundle.trivializationAt_apply, mfld_simps] change fderivWithin 𝕜 (φ ∘ Prod.fst) _ _ _ = fderivWithin 𝕜 φ _ _ _ rw [range_prodMap] at U rw [fderivWithin_comp _ (by exact D0) differentiableWithinAt_fst mapsTo_fst_prod (U _ _)] simp [fderivWithin_fst, U] · /- check that the composition with the second projection in the target chart is smooth. For this, we check that it coincides locally with the projection `pM' : TM × TM' → TM'` read in the target chart, which is obviously smooth. -/ have smooth_pM' : ContMDiffAt (I.tangent.prod I'.tangent) I'.tangent n Prod.snd (a, b) := contMDiffAt_snd apply (contMDiffAt_totalSpace.1 smooth_pM').2.congr_of_eventuallyEq filter_upwards [chart_source_mem_nhds (ModelProd (ModelProd H E) (ModelProd H' E')) (a, b)] with p hp -- now we have to check that the original map coincides locally with `pM'` read in target chart. simp only [prodChartedSpace_chartAt, OpenPartialHomeomorph.prod_toPartialEquiv, PartialEquiv.prod_source, Set.mem_prod, TangentBundle.mem_chart_source_iff] at hp let φ (x : E') := I' ((chartAt H' b.proj) ((chartAt H' p.2.proj).symm (I'.symm x))) have D0 : DifferentiableWithinAt 𝕜 φ (Set.range I') (I' ((chartAt H' p.2.proj) p.2.proj)) := by apply ContDiffWithinAt.differentiableWithinAt _ le_rfl apply contDiffWithinAt_ext_coord_change simp [hp.2] have D (w : TangentBundle I M) : DifferentiableWithinAt 𝕜 (φ ∘ (Prod.snd : E × E' → E')) (Set.range (Prod.map ↑I ↑I')) (I ((chartAt H w.proj) w.proj), I' ((chartAt H' p.2.proj) p.2.proj)) := DifferentiableWithinAt.comp (t := Set.range I') _ (by exact D0) differentiableWithinAt_snd (by simp [mapsTo_snd_prod]) simp only [comp_def, comp_apply] rw [DifferentiableWithinAt.fderivWithin_prodMk ?_ (by exact D _) (U _ _)]; swap · let φ' (x : E) := I ((chartAt H a.proj) ((chartAt H p.1.proj).symm (I.symm x))) have D0' : DifferentiableWithinAt 𝕜 φ' (Set.range I) (I ((chartAt H p.1.proj) p.1.proj)) := by apply ContDiffWithinAt.differentiableWithinAt _ le_rfl apply contDiffWithinAt_ext_coord_change simp [hp.1] have D' : DifferentiableWithinAt 𝕜 (φ' ∘ Prod.fst) (Set.range (Prod.map I I')) (I ((chartAt H p.1.proj) p.1.proj), I' ((chartAt H' p.2.proj) p.2.proj)) := DifferentiableWithinAt.comp (t := Set.range I) _ (by exact D0') differentiableWithinAt_fst (by simp [mapsTo_fst_prod]) exact D' simp only [TangentBundle.trivializationAt_apply, mfld_simps] change fderivWithin 𝕜 (φ ∘ Prod.snd) _ _ _ = fderivWithin 𝕜 φ _ _ _ rw [range_prodMap] at U rw [fderivWithin_comp _ (by exact D0) differentiableWithinAt_snd mapsTo_snd_prod (U _ _)] simp [fderivWithin_snd, U] end EquivTangentBundleProd
.lake/packages/mathlib/Mathlib/Geometry/Manifold/ChartedSpace.lean
import Mathlib.Topology.OpenPartialHomeomorph import Mathlib.Topology.Connected.LocPathConnected /-! # Charted spaces A smooth manifold is a topological space `M` locally modelled on a Euclidean space (or a Euclidean half-space for manifolds with boundaries, or an infinite-dimensional vector space for more general notions of manifolds), i.e., the manifold is covered by open subsets on which there are local homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth maps. In this file, we introduce a general framework describing these notions, where the model space is an arbitrary topological space. We avoid the word *manifold*, which should be reserved for the situation where the model space is a (subset of a) vector space, and use the terminology *charted space* instead. If the changes of charts satisfy some additional property (for instance if they are smooth), then `M` inherits additional structure (it makes sense to talk about smooth manifolds). There are therefore two different ingredients in a charted space: * the set of charts, which is data * the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop. We separate these two parts in the definition: the charted space structure is just the set of charts, and then the different smoothness requirements (smooth manifold, orientable manifold, contact manifold, and so on) are additional properties of these charts. These properties are formalized through the notion of structure groupoid, i.e., a set of open partial homeomorphisms stable under composition and inverse, to which the change of coordinates should belong. ## Main definitions * `StructureGroupoid H` : a subset of open partial homeomorphisms of `H` stable under composition, inverse and restriction (ex: partial diffeomorphisms). * `continuousGroupoid H` : the groupoid of all open partial homeomorphisms of `H`. * `ChartedSpace H M` : charted space structure on `M` modelled on `H`, given by an atlas of open partial homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class. * `HasGroupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space modelled on `H`, require that all coordinate changes belong to `G`. This is a type class. * `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted space structure, i.e., the set of charts. * `G.maximalAtlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a structure groupoid, one can consider all the open partial homeomorphisms from `M` to `H` such that changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the maximal atlas (for the groupoid `G`). * `Structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category. As a basic example, we give the instance `instance chartedSpaceSelf (H : Type*) [TopologicalSpace H] : ChartedSpace H H` saying that a topological space is a charted space over itself, with the identity as unique chart. This charted space structure is compatible with any groupoid. Additional useful definitions: * `Pregroupoid H` : a subset of partial maps of `H` stable under composition and restriction, but not inverse (ex: smooth maps) * `Pregroupoid.groupoid` : construct a groupoid from a pregroupoid, by requiring that a map and its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps) * `chartAt H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on `H`. * `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid. * `G.compatible_of_mem_maximalAtlas he he'` states that, for any two charts `e` and `e'` in the maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the `G` if `M` admits `G` as a structure groupoid. * `ChartedSpaceCore.toChartedSpace`: consider a space without a topology, but endowed with a set of charts (which are partial equivs) for which the change of coordinates are partial homeos. Then one can construct a topology on the space for which the charts become partial homeos, defining a genuine charted space structure. ## Implementation notes The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the definition is only that, read in charts, the structomorphism locally belongs to the groupoid under consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas). A consequence is that the invariance under structomorphisms of properties defined in terms of the atlas is not obvious in general, and could require some work in theory (amounting to the fact that these properties only depend on the maximal atlas, for instance). In practice, this does not create any real difficulty. We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the model space is a half space. Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and sometimes as spaces with an atlas from which a topology is deduced. We use the former approach: otherwise, there would be an instance from manifolds to topological spaces, which means that any instance search for topological spaces would try to find manifold structures involving a yet unknown model space, leading to problems. However, we also introduce the latter approach, through a structure `ChartedSpaceCore` making it possible to construct a topology out of a set of partial equivs with compatibility conditions (but we do not register it as an instance). In the definition of a charted space, the model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`. ## Notation In the scope `Manifold`, we denote the composition of open partial homeomorphisms with `≫ₕ`, and the composition of partial equivs with `≫`. -/ noncomputable section open TopologicalSpace Topology universe u variable {H : Type u} {H' : Type*} {M : Type*} {M' : Type*} {M'' : Type*} /- Notational shortcut for the composition of open partial homeomorphisms and partial equivs, i.e., `OpenPartialHomeomorph.trans` and `PartialEquiv.trans`. Note that, as is usual for equivs, the composition is from left to right, hence the direction of the arrow. -/ @[inherit_doc] scoped[Manifold] infixr:100 " ≫ₕ " => OpenPartialHomeomorph.trans @[inherit_doc] scoped[Manifold] infixr:100 " ≫ " => PartialEquiv.trans open Set OpenPartialHomeomorph Manifold /-! ### Structure groupoids -/ section Groupoid /-! One could add to the definition of a structure groupoid the fact that the restriction of an element of the groupoid to any open set still belongs to the groupoid. (This is in Kobayashi-Nomizu.) I am not sure I want this, for instance on `H × E` where `E` is a vector space, and the groupoid is made of functions respecting the fibers and linear in the fibers (so that a charted space over this groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always defined on sets of the form `s × E`. There is a typeclass `ClosedUnderRestriction` for groupoids which have the restriction property. The only nontrivial requirement is locality: if an open partial homeomorphism belongs to the groupoid around each point in its domain of definition, then it belongs to the groupoid. Without this requirement, the composition of structomorphisms does not have to be a structomorphism. Note that this implies that an open partial homeomorphism with empty source belongs to any structure groupoid, as it trivially satisfies this condition. There is also a technical point, related to the fact that an open partial homeomorphism is by definition a global map which is a homeomorphism when restricted to its source subset (and its values outside of the source are not relevant). Therefore, we also require that being a member of the groupoid only depends on the values on the source. We use primes in the structure names as we will reformulate them below (without primes) using a `Membership` instance, writing `e ∈ G` instead of `e ∈ G.members`. -/ /-- A structure groupoid is a set of open partial homeomorphisms of a topological space stable under composition and inverse. They appear in the definition of the smoothness class of a manifold. -/ structure StructureGroupoid (H : Type u) [TopologicalSpace H] where /-- Members of the structure groupoid are open partial homeomorphisms. -/ members : Set (OpenPartialHomeomorph H H) /-- Structure groupoids are stable under composition. -/ trans' : ∀ e e' : OpenPartialHomeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members /-- Structure groupoids are stable under inverse. -/ symm' : ∀ e : OpenPartialHomeomorph H H, e ∈ members → e.symm ∈ members /-- The identity morphism lies in the structure groupoid. -/ id_mem' : OpenPartialHomeomorph.refl H ∈ members /-- Let `e` be an open partial homeomorphism. If for every `x ∈ e.source`, the restriction of e to some open set around `x` lies in the groupoid, then `e` lies in the groupoid. -/ locality' : ∀ e : OpenPartialHomeomorph H H, (∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ members) → e ∈ members /-- Membership in a structure groupoid respects the equivalence of open partial homeomorphisms. -/ mem_of_eqOnSource' : ∀ e e' : OpenPartialHomeomorph H H, e ∈ members → e' ≈ e → e' ∈ members variable [TopologicalSpace H] instance : Membership (OpenPartialHomeomorph H H) (StructureGroupoid H) := ⟨fun (G : StructureGroupoid H) (e : OpenPartialHomeomorph H H) ↦ e ∈ G.members⟩ instance (H : Type u) [TopologicalSpace H] : SetLike (StructureGroupoid H) (OpenPartialHomeomorph H H) where coe s := s.members coe_injective' N O h := by cases N; cases O; congr instance : Min (StructureGroupoid H) := ⟨fun G G' => StructureGroupoid.mk (members := G.members ∩ G'.members) (trans' := fun e e' he he' => ⟨G.trans' e e' he.left he'.left, G'.trans' e e' he.right he'.right⟩) (symm' := fun e he => ⟨G.symm' e he.left, G'.symm' e he.right⟩) (id_mem' := ⟨G.id_mem', G'.id_mem'⟩) (locality' := by intro e hx apply (mem_inter_iff e G.members G'.members).mpr refine And.intro (G.locality' e ?_) (G'.locality' e ?_) all_goals intro x hex rcases hx x hex with ⟨s, hs⟩ use s refine And.intro hs.left (And.intro hs.right.left ?_) · exact hs.right.right.left · exact hs.right.right.right) (mem_of_eqOnSource' := fun e e' he hee' => ⟨G.mem_of_eqOnSource' e e' he.left hee', G'.mem_of_eqOnSource' e e' he.right hee'⟩)⟩ instance : InfSet (StructureGroupoid H) := ⟨fun S => StructureGroupoid.mk (members := ⋂ s ∈ S, s.members) (trans' := by simp only [mem_iInter] intro e e' he he' i hi exact i.trans' e e' (he i hi) (he' i hi)) (symm' := by simp only [mem_iInter] intro e he i hi exact i.symm' e (he i hi)) (id_mem' := by simp only [mem_iInter] intro i _ exact i.id_mem') (locality' := by simp only [mem_iInter] intro e he i hi refine i.locality' e ?_ intro x hex rcases he x hex with ⟨s, hs⟩ exact ⟨s, ⟨hs.left, ⟨hs.right.left, hs.right.right i hi⟩⟩⟩) (mem_of_eqOnSource' := by simp only [mem_iInter] intro e e' he he'e exact fun i hi => i.mem_of_eqOnSource' e e' (he i hi) he'e)⟩ theorem StructureGroupoid.trans (G : StructureGroupoid H) {e e' : OpenPartialHomeomorph H H} (he : e ∈ G) (he' : e' ∈ G) : e ≫ₕ e' ∈ G := G.trans' e e' he he' theorem StructureGroupoid.symm (G : StructureGroupoid H) {e : OpenPartialHomeomorph H H} (he : e ∈ G) : e.symm ∈ G := G.symm' e he theorem StructureGroupoid.id_mem (G : StructureGroupoid H) : OpenPartialHomeomorph.refl H ∈ G := G.id_mem' theorem StructureGroupoid.locality (G : StructureGroupoid H) {e : OpenPartialHomeomorph H H} (h : ∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ G) : e ∈ G := G.locality' e h theorem StructureGroupoid.mem_of_eqOnSource (G : StructureGroupoid H) {e e' : OpenPartialHomeomorph H H} (he : e ∈ G) (h : e' ≈ e) : e' ∈ G := G.mem_of_eqOnSource' e e' he h theorem StructureGroupoid.mem_iff_of_eqOnSource {G : StructureGroupoid H} {e e' : OpenPartialHomeomorph H H} (h : e ≈ e') : e ∈ G ↔ e' ∈ G := ⟨fun he ↦ G.mem_of_eqOnSource he (Setoid.symm h), fun he' ↦ G.mem_of_eqOnSource he' h⟩ /-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid. -/ instance StructureGroupoid.partialOrder : PartialOrder (StructureGroupoid H) := PartialOrder.lift StructureGroupoid.members fun a b h ↦ by cases a cases b dsimp at h induction h rfl theorem StructureGroupoid.le_iff {G₁ G₂ : StructureGroupoid H} : G₁ ≤ G₂ ↔ ∀ e, e ∈ G₁ → e ∈ G₂ := Iff.rfl /-- The trivial groupoid, containing only the identity (and maps with empty source, as this is necessary from the definition). -/ def idGroupoid (H : Type u) [TopologicalSpace H] : StructureGroupoid H where members := {OpenPartialHomeomorph.refl H} ∪ { e : OpenPartialHomeomorph H H | e.source = ∅ } trans' e e' he he' := by rcases he with he | he · simpa only [mem_singleton_iff.1 he, refl_trans] · have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _ rw [he] at this have : e ≫ₕ e' ∈ { e : OpenPartialHomeomorph H H | e.source = ∅ } := eq_bot_iff.2 this exact (mem_union _ _ _).2 (Or.inr this) symm' e he := by rcases (mem_union _ _ _).1 he with E | E · simp [mem_singleton_iff.mp E] · right simpa only [e.toPartialEquiv.image_source_eq_target.symm, mfld_simps] using E id_mem' := mem_union_left _ rfl locality' e he := by rcases e.source.eq_empty_or_nonempty with h | h · right exact h · left rcases h with ⟨x, hx⟩ rcases he x hx with ⟨s, open_s, xs, hs⟩ have x's : x ∈ (e.restr s).source := by rw [restr_source, open_s.interior_eq] exact ⟨hx, xs⟩ rcases hs with hs | hs · replace hs : OpenPartialHomeomorph.restr e s = OpenPartialHomeomorph.refl H := by simpa only using hs have : (e.restr s).source = univ := by rw [hs] simp have : e.toPartialEquiv.source ∩ interior s = univ := this have : univ ⊆ interior s := by rw [← this] exact inter_subset_right have : s = univ := by rwa [open_s.interior_eq, univ_subset_iff] at this simpa only [this, restr_univ] using hs · exfalso rw [mem_setOf_eq] at hs rwa [hs] at x's mem_of_eqOnSource' e e' he he'e := by rcases he with he | he · left have : e = e' := by refine eq_of_eqOnSource_univ (Setoid.symm he'e) ?_ ?_ <;> rw [Set.mem_singleton_iff.1 he] <;> rfl rwa [← this] · right have he : e.toPartialEquiv.source = ∅ := he rwa [Set.mem_setOf_eq, EqOnSource.source_eq he'e] /-- Every structure groupoid contains the identity groupoid. -/ instance instStructureGroupoidOrderBot : OrderBot (StructureGroupoid H) where bot := idGroupoid H bot_le := by intro u f hf have hf : f ∈ {OpenPartialHomeomorph.refl H} ∪ { e : OpenPartialHomeomorph H H | e.source = ∅ } := hf simp only [singleton_union, mem_setOf_eq, mem_insert_iff] at hf rcases hf with hf | hf · rw [hf] apply u.id_mem · apply u.locality intro x hx rw [hf, mem_empty_iff_false] at hx exact hx.elim instance : Inhabited (StructureGroupoid H) := ⟨idGroupoid H⟩ /-- To construct a groupoid, one may consider classes of open partial homeomorphisms such that both the function and its inverse have some property. If this property is stable under composition, one gets a groupoid. `Pregroupoid` bundles the properties needed for this construction, with the groupoid of smooth functions with smooth inverses as an application. -/ structure Pregroupoid (H : Type*) [TopologicalSpace H] where /-- Property describing membership in this groupoid: the pregroupoid "contains" all functions `H → H` having the pregroupoid property on some `s : Set H` -/ property : (H → H) → Set H → Prop /-- The pregroupoid property is stable under composition -/ comp : ∀ {f g u v}, property f u → property g v → IsOpen u → IsOpen v → IsOpen (u ∩ f ⁻¹' v) → property (g ∘ f) (u ∩ f ⁻¹' v) /-- Pregroupoids contain the identity map (on `univ`) -/ id_mem : property id univ /-- The pregroupoid property is "local", in the sense that `f` has the pregroupoid property on `u` iff its restriction to each open subset of `u` has it -/ locality : ∀ {f u}, IsOpen u → (∀ x ∈ u, ∃ v, IsOpen v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u /-- If `f = g` on `u` and `property f u`, then `property g u` -/ congr : ∀ {f g : H → H} {u}, IsOpen u → (∀ x ∈ u, g x = f x) → property f u → property g u /-- Construct a groupoid of partial homeos for which the map and its inverse have some property, from a pregroupoid asserting that this property is stable under composition. -/ def Pregroupoid.groupoid (PG : Pregroupoid H) : StructureGroupoid H where members := { e : OpenPartialHomeomorph H H | PG.property e e.source ∧ PG.property e.symm e.target } trans' e e' he he' := by constructor · apply PG.comp he.1 he'.1 e.open_source e'.open_source apply e.continuousOn_toFun.isOpen_inter_preimage e.open_source e'.open_source · apply PG.comp he'.2 he.2 e'.open_target e.open_target apply e'.continuousOn_invFun.isOpen_inter_preimage e'.open_target e.open_target symm' _ he := ⟨he.2, he.1⟩ id_mem' := ⟨PG.id_mem, PG.id_mem⟩ locality' e he := by constructor · refine PG.locality e.open_source fun x xu ↦ ?_ rcases he x xu with ⟨s, s_open, xs, hs⟩ refine ⟨s, s_open, xs, ?_⟩ convert hs.1 using 1 dsimp [OpenPartialHomeomorph.restr] rw [s_open.interior_eq] · refine PG.locality e.open_target fun x xu ↦ ?_ rcases he (e.symm x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩ refine ⟨e.target ∩ e.symm ⁻¹' s, ?_, ⟨xu, xs⟩, ?_⟩ · exact ContinuousOn.isOpen_inter_preimage e.continuousOn_invFun e.open_target s_open · rw [← inter_assoc, inter_self] convert hs.2 using 1 dsimp [OpenPartialHomeomorph.restr] rw [s_open.interior_eq] mem_of_eqOnSource' e e' he ee' := by constructor · apply PG.congr e'.open_source ee'.2 simp only [ee'.1, he.1] · have A := EqOnSource.symm' ee' apply PG.congr e'.symm.open_source A.2 convert he.2 using 1 rw [A.1, symm_toPartialEquiv, PartialEquiv.symm_source] theorem mem_groupoid_of_pregroupoid {PG : Pregroupoid H} {e : OpenPartialHomeomorph H H} : e ∈ PG.groupoid ↔ PG.property e e.source ∧ PG.property e.symm e.target := Iff.rfl theorem groupoid_of_pregroupoid_le (PG₁ PG₂ : Pregroupoid H) (h : ∀ f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid := by refine StructureGroupoid.le_iff.2 fun e he ↦ ?_ rw [mem_groupoid_of_pregroupoid] at he ⊢ exact ⟨h _ _ he.1, h _ _ he.2⟩ theorem mem_pregroupoid_of_eqOnSource (PG : Pregroupoid H) {e e' : OpenPartialHomeomorph H H} (he' : e ≈ e') (he : PG.property e e.source) : PG.property e' e'.source := by rw [← he'.1] exact PG.congr e.open_source he'.eqOn.symm he /-- The pregroupoid of all partial maps on a topological space `H`. -/ abbrev continuousPregroupoid (H : Type*) [TopologicalSpace H] : Pregroupoid H where property _ _ := True comp _ _ _ _ _ := trivial id_mem := trivial locality _ _ := trivial congr _ _ _ := trivial instance (H : Type*) [TopologicalSpace H] : Inhabited (Pregroupoid H) := ⟨continuousPregroupoid H⟩ /-- The groupoid of all open partial homeomorphisms on a topological space `H`. -/ def continuousGroupoid (H : Type*) [TopologicalSpace H] : StructureGroupoid H := Pregroupoid.groupoid (continuousPregroupoid H) /-- Every structure groupoid is contained in the groupoid of all open partial homeomorphisms. -/ instance instStructureGroupoidOrderTop : OrderTop (StructureGroupoid H) where top := continuousGroupoid H le_top _ _ _ := ⟨trivial, trivial⟩ instance : CompleteLattice (StructureGroupoid H) := { SetLike.instPartialOrder, completeLatticeOfInf _ (by exact fun s => ⟨fun S Ss F hF => mem_iInter₂.mp hF S Ss, fun T Tl F fT => mem_iInter₂.mpr (fun i his => Tl his fT)⟩) with le := (· ≤ ·) lt := (· < ·) bot := instStructureGroupoidOrderBot.bot bot_le := instStructureGroupoidOrderBot.bot_le top := instStructureGroupoidOrderTop.top le_top := instStructureGroupoidOrderTop.le_top inf := (· ⊓ ·) le_inf := fun _ _ _ h₁₂ h₁₃ _ hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩ inf_le_left := fun _ _ _ ↦ And.left inf_le_right := fun _ _ _ ↦ And.right } /-- A groupoid is closed under restriction if it contains all restrictions of its element local homeomorphisms to open subsets of the source. -/ class ClosedUnderRestriction (G : StructureGroupoid H) : Prop where closedUnderRestriction : ∀ {e : OpenPartialHomeomorph H H}, e ∈ G → ∀ s : Set H, IsOpen s → e.restr s ∈ G theorem closedUnderRestriction' {G : StructureGroupoid H} [ClosedUnderRestriction G] {e : OpenPartialHomeomorph H H} (he : e ∈ G) {s : Set H} (hs : IsOpen s) : e.restr s ∈ G := ClosedUnderRestriction.closedUnderRestriction he s hs /-- The trivial restriction-closed groupoid, containing only open partial homeomorphisms equivalent to the restriction of the identity to the various open subsets. -/ def idRestrGroupoid : StructureGroupoid H where members := { e | ∃ (s : Set H) (h : IsOpen s), e ≈ OpenPartialHomeomorph.ofSet s h } trans' := by rintro e e' ⟨s, hs, hse⟩ ⟨s', hs', hse'⟩ refine ⟨s ∩ s', hs.inter hs', ?_⟩ have := OpenPartialHomeomorph.EqOnSource.trans' hse hse' rwa [OpenPartialHomeomorph.ofSet_trans_ofSet] at this symm' := by rintro e ⟨s, hs, hse⟩ refine ⟨s, hs, ?_⟩ rw [← ofSet_symm] exact OpenPartialHomeomorph.EqOnSource.symm' hse id_mem' := ⟨univ, isOpen_univ, by simp only [mfld_simps, refl]⟩ locality' := by intro e h refine ⟨e.source, e.open_source, by simp only [mfld_simps], ?_⟩ intro x hx rcases h x hx with ⟨s, hs, hxs, s', hs', hes'⟩ have hes : x ∈ (e.restr s).source := by rw [e.restr_source] refine ⟨hx, ?_⟩ rw [hs.interior_eq] exact hxs simpa only [mfld_simps] using OpenPartialHomeomorph.EqOnSource.eqOn hes' hes mem_of_eqOnSource' := by rintro e e' ⟨s, hs, hse⟩ hee' exact ⟨s, hs, Setoid.trans hee' hse⟩ theorem idRestrGroupoid_mem {s : Set H} (hs : IsOpen s) : ofSet s hs ∈ @idRestrGroupoid H _ := ⟨s, hs, refl _⟩ /-- The trivial restriction-closed groupoid is indeed `ClosedUnderRestriction`. -/ instance closedUnderRestriction_idRestrGroupoid : ClosedUnderRestriction (@idRestrGroupoid H _) := ⟨by rintro e ⟨s', hs', he⟩ s hs use s' ∩ s, hs'.inter hs refine Setoid.trans (OpenPartialHomeomorph.EqOnSource.restr he s) ?_ exact ⟨by simp only [hs.interior_eq, mfld_simps], by simp only [mfld_simps, eqOn_refl]⟩⟩ /-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed groupoid. -/ theorem closedUnderRestriction_iff_id_le (G : StructureGroupoid H) : ClosedUnderRestriction G ↔ idRestrGroupoid ≤ G := by constructor · intro _i rw [StructureGroupoid.le_iff] rintro e ⟨s, hs, hes⟩ refine G.mem_of_eqOnSource ?_ hes convert closedUnderRestriction' G.id_mem hs ext <;> simp [hs.interior_eq] · intro h constructor intro e he s hs rw [← ofSet_trans (e : OpenPartialHomeomorph H H) hs] refine G.trans ?_ he apply StructureGroupoid.le_iff.mp h exact idRestrGroupoid_mem hs /-- The groupoid of all open partial homeomorphisms on a topological space `H` is closed under restriction. -/ instance : ClosedUnderRestriction (continuousGroupoid H) := (closedUnderRestriction_iff_id_le _).mpr le_top end Groupoid /-! ### Charted spaces -/ /-- A charted space is a topological space endowed with an atlas, i.e., a set of local homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts cover the whole space. We express the covering property by choosing for each `x` a member `chartAt x` of the atlas containing `x` in its source: in the smooth case, this is convenient to construct the tangent bundle in an efficient way. The model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen sometimes as a real manifold over `ℝ^(2n)`. -/ @[ext] class ChartedSpace (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] where /-- The atlas of charts in the `ChartedSpace`. -/ protected atlas : Set (OpenPartialHomeomorph M H) /-- The preferred chart at each point in the charted space. -/ protected chartAt : M → OpenPartialHomeomorph M H protected mem_chart_source : ∀ x, x ∈ (chartAt x).source protected chart_mem_atlas : ∀ x, chartAt x ∈ atlas /-- The atlas of charts in a `ChartedSpace`. -/ abbrev atlas (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [ChartedSpace H M] : Set (OpenPartialHomeomorph M H) := ChartedSpace.atlas /-- The preferred chart at a point `x` in a charted space `M`. -/ abbrev chartAt (H : Type*) [TopologicalSpace H] {M : Type*} [TopologicalSpace M] [ChartedSpace H M] (x : M) : OpenPartialHomeomorph M H := ChartedSpace.chartAt x @[simp, mfld_simps] lemma mem_chart_source (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] (x : M) : x ∈ (chartAt H x).source := ChartedSpace.mem_chart_source x @[simp, mfld_simps] lemma chart_mem_atlas (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] (x : M) : chartAt H x ∈ atlas H M := ChartedSpace.chart_mem_atlas x lemma nonempty_of_chartedSpace {H : Type*} {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] (x : M) : Nonempty H := ⟨chartAt H x x⟩ lemma isEmpty_of_chartedSpace (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] [IsEmpty H] : IsEmpty M := by rcases isEmpty_or_nonempty M with hM | ⟨⟨x⟩⟩ · exact hM · exact (IsEmpty.false (chartAt H x x)).elim section ChartedSpace section variable (H) [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] theorem mem_chart_target (x : M) : chartAt H x x ∈ (chartAt H x).target := (chartAt H x).map_source (mem_chart_source _ _) theorem chart_source_mem_nhds (x : M) : (chartAt H x).source ∈ 𝓝 x := (chartAt H x).open_source.mem_nhds <| mem_chart_source H x theorem chart_target_mem_nhds (x : M) : (chartAt H x).target ∈ 𝓝 (chartAt H x x) := (chartAt H x).open_target.mem_nhds <| mem_chart_target H x variable (M) in @[simp] theorem iUnion_source_chartAt : (⋃ x : M, (chartAt H x).source) = (univ : Set M) := eq_univ_iff_forall.mpr fun x ↦ mem_iUnion.mpr ⟨x, mem_chart_source H x⟩ theorem ChartedSpace.isOpen_iff (s : Set M) : IsOpen s ↔ ∀ x : M, IsOpen <| chartAt H x '' ((chartAt H x).source ∩ s) := by rw [isOpen_iff_of_cover (fun i ↦ (chartAt H i).open_source) (iUnion_source_chartAt H M)] simp only [(chartAt H _).isOpen_image_iff_of_subset_source inter_subset_left] /-- `achart H x` is the chart at `x`, considered as an element of the atlas. Especially useful for working with `BasicContMDiffVectorBundleCore`. -/ def achart (x : M) : atlas H M := ⟨chartAt H x, chart_mem_atlas H x⟩ theorem achart_def (x : M) : achart H x = ⟨chartAt H x, chart_mem_atlas H x⟩ := rfl @[simp, mfld_simps] theorem coe_achart (x : M) : (achart H x : OpenPartialHomeomorph M H) = chartAt H x := rfl @[simp, mfld_simps] theorem achart_val (x : M) : (achart H x).1 = chartAt H x := rfl theorem mem_achart_source (x : M) : x ∈ (achart H x).1.source := mem_chart_source H x open TopologicalSpace theorem ChartedSpace.secondCountable_of_countable_cover [SecondCountableTopology H] {s : Set M} (hs : ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ) (hsc : s.Countable) : SecondCountableTopology M := by haveI : ∀ x : M, SecondCountableTopology (chartAt H x).source := fun x ↦ (chartAt (H := H) x).secondCountableTopology_source haveI := hsc.toEncodable rw [biUnion_eq_iUnion] at hs exact secondCountableTopology_of_countable_cover (fun x : s ↦ (chartAt H (x : M)).open_source) hs variable (M) theorem ChartedSpace.secondCountable_of_sigmaCompact [SecondCountableTopology H] [SigmaCompactSpace M] : SecondCountableTopology M := by obtain ⟨s, hsc, hsU⟩ : ∃ s, Set.Countable s ∧ ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ := countable_cover_nhds_of_sigmaCompact fun x : M ↦ chart_source_mem_nhds H x exact ChartedSpace.secondCountable_of_countable_cover H hsU hsc /-- If a topological space admits an atlas with locally compact charts, then the space itself is locally compact. -/ theorem ChartedSpace.locallyCompactSpace [LocallyCompactSpace H] : LocallyCompactSpace M := by have : ∀ x : M, (𝓝 x).HasBasis (fun s ↦ s ∈ 𝓝 (chartAt H x x) ∧ IsCompact s ∧ s ⊆ (chartAt H x).target) fun s ↦ (chartAt H x).symm '' s := fun x ↦ by rw [← (chartAt H x).symm_map_nhds_eq (mem_chart_source H x)] exact ((compact_basis_nhds (chartAt H x x)).hasBasis_self_subset (chart_target_mem_nhds H x)).map _ refine .of_hasBasis this ?_ rintro x s ⟨_, h₂, h₃⟩ exact h₂.image_of_continuousOn ((chartAt H x).continuousOn_symm.mono h₃) /-- If a topological space admits an atlas with locally connected charts, then the space itself is locally connected. -/ theorem ChartedSpace.locallyConnectedSpace [LocallyConnectedSpace H] : LocallyConnectedSpace M := by let e : M → OpenPartialHomeomorph M H := chartAt H refine locallyConnectedSpace_of_connected_bases (fun x s ↦ (e x).symm '' s) (fun x s ↦ (IsOpen s ∧ e x x ∈ s ∧ IsConnected s) ∧ s ⊆ (e x).target) ?_ ?_ · intro x simpa only [e, OpenPartialHomeomorph.symm_map_nhds_eq, mem_chart_source] using ((LocallyConnectedSpace.open_connected_basis (e x x)).restrict_subset ((e x).open_target.mem_nhds (mem_chart_target H x))).map (e x).symm · rintro x s ⟨⟨-, -, hsconn⟩, hssubset⟩ exact hsconn.isPreconnected.image _ ((e x).continuousOn_symm.mono hssubset) /-- If a topological space `M` admits an atlas with locally path-connected charts, then `M` itself is locally path-connected. -/ theorem ChartedSpace.locPathConnectedSpace [LocPathConnectedSpace H] : LocPathConnectedSpace M := by refine ⟨fun x ↦ ⟨fun s ↦ ⟨fun hs ↦ ?_, fun ⟨u, hu⟩ ↦ Filter.mem_of_superset hu.1.1 hu.2⟩⟩⟩ let e := chartAt H x let t := s ∩ e.source have ht : t ∈ 𝓝 x := Filter.inter_mem hs (chart_source_mem_nhds _ _) refine ⟨e.symm '' pathComponentIn (e '' t) (e x), ⟨?_, ?_⟩, (?_ : _ ⊆ t).trans inter_subset_left⟩ · nth_rewrite 1 [← e.left_inv (mem_chart_source _ _)] apply e.symm.image_mem_nhds (by simp [e]) exact pathComponentIn_mem_nhds <| e.image_mem_nhds (mem_chart_source _ _) ht · refine (isPathConnected_pathComponentIn <| mem_image_of_mem e (mem_of_mem_nhds ht)).image' ?_ refine e.continuousOn_symm.mono <| subset_trans ?_ e.map_source'' exact (pathComponentIn_mono <| image_mono inter_subset_right).trans pathComponentIn_subset · exact (image_mono pathComponentIn_subset).trans (PartialEquiv.symm_image_image_of_subset_source _ inter_subset_right).subset /-- If `M` is modelled on `H'` and `H'` is itself modelled on `H`, then we can consider `M` as being modelled on `H`. -/ def ChartedSpace.comp (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] (M : Type*) [TopologicalSpace M] [ChartedSpace H H'] [ChartedSpace H' M] : ChartedSpace H M where atlas := image2 OpenPartialHomeomorph.trans (atlas H' M) (atlas H H') chartAt p := (chartAt H' p).trans (chartAt H (chartAt H' p p)) mem_chart_source p := by simp only [mfld_simps] chart_mem_atlas p := ⟨chartAt _ p, chart_mem_atlas _ p, chartAt _ _, chart_mem_atlas _ _, rfl⟩ theorem chartAt_comp (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] {M : Type*} [TopologicalSpace M] [ChartedSpace H H'] [ChartedSpace H' M] (x : M) : (letI := ChartedSpace.comp H H' M; chartAt H x) = chartAt H' x ≫ₕ chartAt H (chartAt H' x x) := rfl /-- A charted space over a T1 space is T1. Note that this is *not* true for T2 (for instance for the real line with a double origin). -/ theorem ChartedSpace.t1Space [T1Space H] : T1Space M := by apply t1Space_iff_exists_open.2 (fun x y hxy ↦ ?_) by_cases hy : y ∈ (chartAt H x).source · refine ⟨(chartAt H x).source ∩ (chartAt H x)⁻¹' ({chartAt H x y}ᶜ), ?_, ?_, by simp⟩ · exact OpenPartialHomeomorph.isOpen_inter_preimage _ isOpen_compl_singleton · simp only [preimage_compl, mem_inter_iff, mem_chart_source, mem_compl_iff, mem_preimage, mem_singleton_iff, true_and] exact (chartAt H x).injOn.ne (ChartedSpace.mem_chart_source x) hy hxy · exact ⟨(chartAt H x).source, (chartAt H x).open_source, ChartedSpace.mem_chart_source x, hy⟩ /-- A charted space over a discrete space is discrete. -/ theorem ChartedSpace.discreteTopology [DiscreteTopology H] : DiscreteTopology M := by apply discreteTopology_iff_isOpen_singleton.2 (fun x ↦ ?_) have : IsOpen ((chartAt H x).source ∩ (chartAt H x) ⁻¹' {chartAt H x x}) := isOpen_inter_preimage _ (isOpen_discrete _) convert this refine Subset.antisymm (by simp) ?_ simp only [subset_singleton_iff, mem_inter_iff, mem_preimage, mem_singleton_iff, and_imp] intro y hy h'y exact (chartAt H x).injOn hy (mem_chart_source _ x) h'y end section Constructions /-- An empty type is a charted space over any topological space. -/ def ChartedSpace.empty (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [IsEmpty M] : ChartedSpace H M where atlas := ∅ chartAt x := (IsEmpty.false x).elim mem_chart_source x := (IsEmpty.false x).elim chart_mem_atlas x := (IsEmpty.false x).elim /-- Any space is a `ChartedSpace` modelled over itself, by just using the identity chart. -/ instance chartedSpaceSelf (H : Type*) [TopologicalSpace H] : ChartedSpace H H where atlas := {OpenPartialHomeomorph.refl H} chartAt _ := OpenPartialHomeomorph.refl H mem_chart_source x := mem_univ x chart_mem_atlas _ := mem_singleton _ /-- In the trivial `ChartedSpace` structure of a space modelled over itself through the identity, the atlas members are just the identity. -/ @[simp, mfld_simps] theorem chartedSpaceSelf_atlas {H : Type*} [TopologicalSpace H] {e : OpenPartialHomeomorph H H} : e ∈ atlas H H ↔ e = OpenPartialHomeomorph.refl H := Iff.rfl /-- In the model space, `chartAt` is always the identity. -/ theorem chartAt_self_eq {H : Type*} [TopologicalSpace H] {x : H} : chartAt H x = OpenPartialHomeomorph.refl H := rfl /-- Any discrete space is a charted space over a singleton set. We keep this as a definition (not an instance) to avoid instance search trying to search for `DiscreteTopology` or `Unique` instances. -/ def ChartedSpace.of_discreteTopology [TopologicalSpace M] [TopologicalSpace H] [DiscreteTopology M] [h : Unique H] : ChartedSpace H M where atlas := letI f := fun x : M ↦ OpenPartialHomeomorph.const (isOpen_discrete {x}) (isOpen_discrete {h.default}) Set.image f univ chartAt x := OpenPartialHomeomorph.const (isOpen_discrete {x}) (isOpen_discrete {h.default}) mem_chart_source x := by simp chart_mem_atlas x := by simp /-- A chart on the discrete space is the constant chart. -/ @[simp, mfld_simps] lemma chartedSpace_of_discreteTopology_chartAt [TopologicalSpace M] [TopologicalSpace H] [DiscreteTopology M] [h : Unique H] {x : M} : haveI := ChartedSpace.of_discreteTopology (M := M) (H := H) chartAt H x = OpenPartialHomeomorph.const (isOpen_discrete {x}) (isOpen_discrete {h.default}) := rfl section Products library_note2 «Manifold type tags» /-- For technical reasons we introduce two type tags: * `ModelProd H H'` is the same as `H × H'`; * `ModelPi H` is the same as `∀ i, H i`, where `H : ι → Type*` and `ι` is a finite type. In both cases the reason is the same, so we explain it only in the case of the product. A charted space `M` with model `H` is a set of charts from `M` to `H` covering the space. Every space is registered as a charted space over itself, using the only chart `id`, in `chartedSpaceSelf`. You can also define a product of charted space `M` and `M'` (with model space `H × H'`) by taking the products of the charts. Now, on `H × H'`, there are two charted space structures with model space `H × H'` itself, the one coming from `chartedSpaceSelf`, and the one coming from the product of the two `chartedSpaceSelf` on each component. They are equal, but not defeq (because the product of `id` and `id` is not defeq to `id`), which is bad as we know. This expedient of renaming `H × H'` solves this problem. -/ /-- Same thing as `H × H'`. We introduce it for technical reasons, see note [Manifold type tags]. -/ def ModelProd (H : Type*) (H' : Type*) := H × H' /-- Same thing as `∀ i, H i`. We introduce it for technical reasons, see note [Manifold type tags]. -/ def ModelPi {ι : Type*} (H : ι → Type*) := ∀ i, H i section instance modelProdInhabited [Inhabited H] [Inhabited H'] : Inhabited (ModelProd H H') := instInhabitedProd instance (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] : TopologicalSpace (ModelProd H H') := instTopologicalSpaceProd -- Next lemma shows up often when dealing with derivatives, so we register it as simp lemma. @[simp, mfld_simps] theorem modelProd_range_prod_id {H : Type*} {H' : Type*} {α : Type*} (f : H → α) : (range fun p : ModelProd H H' ↦ (f p.1, p.2)) = range f ×ˢ (univ : Set H') := by rw [prod_range_univ_eq] rfl end section variable {ι : Type*} {Hi : ι → Type*} instance modelPiInhabited [∀ i, Inhabited (Hi i)] : Inhabited (ModelPi Hi) := Pi.instInhabited instance [∀ i, TopologicalSpace (Hi i)] : TopologicalSpace (ModelPi Hi) := Pi.topologicalSpace end /-- The product of two charted spaces is naturally a charted space, with the canonical construction of the atlas of product maps. -/ instance prodChartedSpace (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [ChartedSpace H M] (H' : Type*) [TopologicalSpace H'] (M' : Type*) [TopologicalSpace M'] [ChartedSpace H' M'] : ChartedSpace (ModelProd H H') (M × M') where atlas := image2 OpenPartialHomeomorph.prod (atlas H M) (atlas H' M') chartAt x := (chartAt H x.1).prod (chartAt H' x.2) mem_chart_source x := ⟨mem_chart_source H x.1, mem_chart_source H' x.2⟩ chart_mem_atlas x := mem_image2_of_mem (chart_mem_atlas H x.1) (chart_mem_atlas H' x.2) section prodChartedSpace @[ext] theorem ModelProd.ext {x y : ModelProd H H'} (h₁ : x.1 = y.1) (h₂ : x.2 = y.2) : x = y := Prod.ext h₁ h₂ variable [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] [TopologicalSpace H'] [TopologicalSpace M'] [ChartedSpace H' M'] {x : M × M'} @[simp, mfld_simps] theorem prodChartedSpace_chartAt : chartAt (ModelProd H H') x = (chartAt H x.fst).prod (chartAt H' x.snd) := rfl theorem chartedSpaceSelf_prod : prodChartedSpace H H H' H' = chartedSpaceSelf (H × H') := by ext1 · simp [atlas, ChartedSpace.atlas] · ext1 simp only [prodChartedSpace_chartAt, chartAt_self_eq, refl_prod_refl] rfl end prodChartedSpace /-- The product of a finite family of charted spaces is naturally a charted space, with the canonical construction of the atlas of finite product maps. -/ instance piChartedSpace {ι : Type*} [Finite ι] (H : ι → Type*) [∀ i, TopologicalSpace (H i)] (M : ι → Type*) [∀ i, TopologicalSpace (M i)] [∀ i, ChartedSpace (H i) (M i)] : ChartedSpace (ModelPi H) (∀ i, M i) where atlas := OpenPartialHomeomorph.pi '' Set.pi univ fun _ ↦ atlas (H _) (M _) chartAt f := OpenPartialHomeomorph.pi fun i ↦ chartAt (H i) (f i) mem_chart_source f i _ := mem_chart_source (H i) (f i) chart_mem_atlas f := mem_image_of_mem _ fun i _ ↦ chart_mem_atlas (H i) (f i) @[simp, mfld_simps] theorem piChartedSpace_chartAt {ι : Type*} [Finite ι] (H : ι → Type*) [∀ i, TopologicalSpace (H i)] (M : ι → Type*) [∀ i, TopologicalSpace (M i)] [∀ i, ChartedSpace (H i) (M i)] (f : ∀ i, M i) : chartAt (H := ModelPi H) f = OpenPartialHomeomorph.pi fun i ↦ chartAt (H i) (f i) := rfl end Products section sum variable [TopologicalSpace H] [TopologicalSpace M] [TopologicalSpace M'] [cm : ChartedSpace H M] [cm' : ChartedSpace H M'] /-- The disjoint union of two charted spaces modelled on a non-empty space `H` is a charted space over `H`. -/ def ChartedSpace.sum_of_nonempty [Nonempty H] : ChartedSpace H (M ⊕ M') where atlas := ((fun e ↦ e.lift_openEmbedding IsOpenEmbedding.inl) '' cm.atlas) ∪ ((fun e ↦ e.lift_openEmbedding IsOpenEmbedding.inr) '' cm'.atlas) -- At `x : M`, the chart is the chart in `M`; at `x' ∈ M'`, it is the chart in `M'`. chartAt := Sum.elim (fun x ↦ (cm.chartAt x).lift_openEmbedding IsOpenEmbedding.inl) (fun x ↦ (cm'.chartAt x).lift_openEmbedding IsOpenEmbedding.inr) mem_chart_source p := by cases p with | inl x => rw [Sum.elim_inl, lift_openEmbedding_source, ← OpenPartialHomeomorph.lift_openEmbedding_source _ IsOpenEmbedding.inl] use x, cm.mem_chart_source x | inr x => rw [Sum.elim_inr, lift_openEmbedding_source, ← OpenPartialHomeomorph.lift_openEmbedding_source _ IsOpenEmbedding.inr] use x, cm'.mem_chart_source x chart_mem_atlas p := by cases p with | inl x => rw [Sum.elim_inl] left use ChartedSpace.chartAt x, cm.chart_mem_atlas x | inr x => rw [Sum.elim_inr] right use ChartedSpace.chartAt x, cm'.chart_mem_atlas x open scoped Classical in instance ChartedSpace.sum : ChartedSpace H (M ⊕ M') := by by_cases! h : Nonempty H · exact ChartedSpace.sum_of_nonempty have : IsEmpty M := isEmpty_of_chartedSpace H have : IsEmpty M' := isEmpty_of_chartedSpace H exact empty H (M ⊕ M') lemma ChartedSpace.sum_chartAt_inl (x : M) : haveI : Nonempty H := nonempty_of_chartedSpace x chartAt H (Sum.inl x) = (chartAt H x).lift_openEmbedding (X' := M ⊕ M') IsOpenEmbedding.inl := by simp only [chartAt, sum, nonempty_of_chartedSpace x, ↓reduceDIte] rfl lemma ChartedSpace.sum_chartAt_inr (x' : M') : haveI : Nonempty H := nonempty_of_chartedSpace x' chartAt H (Sum.inr x') = (chartAt H x').lift_openEmbedding (X' := M ⊕ M') IsOpenEmbedding.inr := by simp only [chartAt, sum, nonempty_of_chartedSpace x', ↓reduceDIte] rfl @[simp, mfld_simps] lemma sum_chartAt_inl_apply {x y : M} : (chartAt H (.inl x : M ⊕ M')) (Sum.inl y) = (chartAt H x) y := by haveI : Nonempty H := nonempty_of_chartedSpace x rw [ChartedSpace.sum_chartAt_inl] exact OpenPartialHomeomorph.lift_openEmbedding_apply _ _ @[simp, mfld_simps] lemma sum_chartAt_inr_apply {x y : M'} : (chartAt H (.inr x : M ⊕ M')) (Sum.inr y) = (chartAt H x) y := by haveI : Nonempty H := nonempty_of_chartedSpace x rw [ChartedSpace.sum_chartAt_inr] exact OpenPartialHomeomorph.lift_openEmbedding_apply _ _ lemma ChartedSpace.mem_atlas_sum [h : Nonempty H] {e : OpenPartialHomeomorph (M ⊕ M') H} (he : e ∈ atlas H (M ⊕ M')) : (∃ f : OpenPartialHomeomorph M H, f ∈ (atlas H M) ∧ e = (f.lift_openEmbedding IsOpenEmbedding.inl)) ∨ (∃ f' : OpenPartialHomeomorph M' H, f' ∈ (atlas H M') ∧ e = (f'.lift_openEmbedding IsOpenEmbedding.inr)) := by simp only [atlas, sum, h, ↓reduceDIte] at he obtain (⟨x, hx, hxe⟩ | ⟨x, hx, hxe⟩) := he · rw [← hxe]; left; use x · rw [← hxe]; right; use x end sum end Constructions end ChartedSpace /-! ### Constructing a topology from an atlas -/ /-- Sometimes, one may want to construct a charted space structure on a space which does not yet have a topological structure, where the topology would come from the charts. For this, one needs charts that are only partial equivalences, and continuity properties for their composition. This is formalised in `ChartedSpaceCore`. -/ structure ChartedSpaceCore (H : Type*) [TopologicalSpace H] (M : Type*) where /-- An atlas of charts, which are only `PartialEquiv`s -/ atlas : Set (PartialEquiv M H) /-- The preferred chart at each point -/ chartAt : M → PartialEquiv M H mem_chart_source : ∀ x, x ∈ (chartAt x).source chart_mem_atlas : ∀ x, chartAt x ∈ atlas open_source : ∀ e e' : PartialEquiv M H, e ∈ atlas → e' ∈ atlas → IsOpen (e.symm.trans e').source continuousOn_toFun : ∀ e e' : PartialEquiv M H, e ∈ atlas → e' ∈ atlas → ContinuousOn (e.symm.trans e') (e.symm.trans e').source namespace ChartedSpaceCore variable [TopologicalSpace H] (c : ChartedSpaceCore H M) {e : PartialEquiv M H} /-- Topology generated by a set of charts on a Type. -/ protected def toTopologicalSpace : TopologicalSpace M := TopologicalSpace.generateFrom <| ⋃ (e : PartialEquiv M H) (_ : e ∈ c.atlas) (s : Set H) (_ : IsOpen s), {e ⁻¹' s ∩ e.source} theorem open_source' (he : e ∈ c.atlas) : IsOpen[c.toTopologicalSpace] e.source := by apply TopologicalSpace.GenerateOpen.basic simp only [exists_prop, mem_iUnion, mem_singleton_iff] refine ⟨e, he, univ, isOpen_univ, ?_⟩ simp only [Set.univ_inter, Set.preimage_univ] theorem open_target (he : e ∈ c.atlas) : IsOpen e.target := by have E : e.target ∩ e.symm ⁻¹' e.source = e.target := Subset.antisymm inter_subset_left fun x hx ↦ ⟨hx, PartialEquiv.target_subset_preimage_source _ hx⟩ simpa [PartialEquiv.trans_source, E] using c.open_source e e he he /-- An element of the atlas in a charted space without topology becomes an open partial homeomorphism for the topology constructed from this atlas. The `OpenPartialHomeomorph` version is given in this definition. -/ protected def openPartialHomeomorph (e : PartialEquiv M H) (he : e ∈ c.atlas) : @OpenPartialHomeomorph M H c.toTopologicalSpace _ := { __ := c.toTopologicalSpace __ := e open_source := by convert c.open_source' he open_target := by convert c.open_target he continuousOn_toFun := by letI : TopologicalSpace M := c.toTopologicalSpace rw [continuousOn_open_iff (c.open_source' he)] intro s s_open rw [inter_comm] apply TopologicalSpace.GenerateOpen.basic simp only [exists_prop, mem_iUnion, mem_singleton_iff] exact ⟨e, he, ⟨s, s_open, rfl⟩⟩ continuousOn_invFun := by letI : TopologicalSpace M := c.toTopologicalSpace apply continuousOn_isOpen_of_generateFrom intro t ht simp only [exists_prop, mem_iUnion, mem_singleton_iff] at ht rcases ht with ⟨e', e'_atlas, s, s_open, ts⟩ rw [ts] let f := e.symm.trans e' have : IsOpen (f ⁻¹' s ∩ f.source) := by simpa [f, inter_comm] using (continuousOn_open_iff (c.open_source e e' he e'_atlas)).1 (c.continuousOn_toFun e e' he e'_atlas) s s_open have A : e' ∘ e.symm ⁻¹' s ∩ (e.target ∩ e.symm ⁻¹' e'.source) = e.target ∩ (e' ∘ e.symm ⁻¹' s ∩ e.symm ⁻¹' e'.source) := by rw [← inter_assoc, ← inter_assoc] congr 1 exact inter_comm _ _ simpa [f, PartialEquiv.trans_source, preimage_inter, preimage_comp.symm, A] using this } @[deprecated (since := "2025-08-29")] alias partialHomeomorph := ChartedSpaceCore.openPartialHomeomorph /-- Given a charted space without topology, endow it with a genuine charted space structure with respect to the topology constructed from the atlas. -/ def toChartedSpace : @ChartedSpace H _ M c.toTopologicalSpace := { __ := c.toTopologicalSpace atlas := ⋃ (e : PartialEquiv M H) (he : e ∈ c.atlas), {c.openPartialHomeomorph e he} chartAt := fun x ↦ c.openPartialHomeomorph (c.chartAt x) (c.chart_mem_atlas x) mem_chart_source := fun x ↦ c.mem_chart_source x chart_mem_atlas := fun x ↦ by simp only [mem_iUnion, mem_singleton_iff] exact ⟨c.chartAt x, c.chart_mem_atlas x, rfl⟩} end ChartedSpaceCore /-! ### Charted space with a given structure groupoid -/ section HasGroupoid variable [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] /-- A charted space has an atlas in a groupoid `G` if the change of coordinates belong to the groupoid. -/ class HasGroupoid {H : Type*} [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [ChartedSpace H M] (G : StructureGroupoid H) : Prop where compatible : ∀ {e e' : OpenPartialHomeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M → e.symm ≫ₕ e' ∈ G /-- Reformulate in the `StructureGroupoid` namespace the compatibility condition of charts in a charted space admitting a structure groupoid, to make it more easily accessible with dot notation. -/ theorem StructureGroupoid.compatible {H : Type*} [TopologicalSpace H] (G : StructureGroupoid H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [HasGroupoid M G] {e e' : OpenPartialHomeomorph M H} (he : e ∈ atlas H M) (he' : e' ∈ atlas H M) : e.symm ≫ₕ e' ∈ G := HasGroupoid.compatible he he' theorem hasGroupoid_of_le {G₁ G₂ : StructureGroupoid H} (h : HasGroupoid M G₁) (hle : G₁ ≤ G₂) : HasGroupoid M G₂ := ⟨fun he he' ↦ hle (h.compatible he he')⟩ theorem hasGroupoid_inf_iff {G₁ G₂ : StructureGroupoid H} : HasGroupoid M (G₁ ⊓ G₂) ↔ HasGroupoid M G₁ ∧ HasGroupoid M G₂ := ⟨(fun h ↦ ⟨hasGroupoid_of_le h inf_le_left, hasGroupoid_of_le h inf_le_right⟩), fun ⟨h1, h2⟩ ↦ { compatible := fun he he' ↦ ⟨h1.compatible he he', h2.compatible he he'⟩ }⟩ theorem hasGroupoid_of_pregroupoid (PG : Pregroupoid H) (h : ∀ {e e' : OpenPartialHomeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M → PG.property (e.symm ≫ₕ e') (e.symm ≫ₕ e').source) : HasGroupoid M PG.groupoid := ⟨fun he he' ↦ mem_groupoid_of_pregroupoid.mpr ⟨h he he', h he' he⟩⟩ /-- The trivial charted space structure on the model space is compatible with any groupoid. -/ instance hasGroupoid_model_space (H : Type*) [TopologicalSpace H] (G : StructureGroupoid H) : HasGroupoid H G where compatible {e e'} he he' := by rw [chartedSpaceSelf_atlas] at he he' simp [he, he', StructureGroupoid.id_mem] /-- Any charted space structure is compatible with the groupoid of all open partial homeomorphisms. -/ instance hasGroupoid_continuousGroupoid : HasGroupoid M (continuousGroupoid H) := by refine ⟨fun _ _ ↦ ?_⟩ rw [continuousGroupoid, mem_groupoid_of_pregroupoid] simp only [and_self_iff] /-- If `G` is closed under restriction, the transition function between the restriction of two charts `e` and `e'` lies in `G`. -/ theorem StructureGroupoid.trans_restricted {e e' : OpenPartialHomeomorph M H} {G : StructureGroupoid H} (he : e ∈ atlas H M) (he' : e' ∈ atlas H M) [HasGroupoid M G] [ClosedUnderRestriction G] {s : Opens M} (hs : Nonempty s) : (e.subtypeRestr hs).symm ≫ₕ e'.subtypeRestr hs ∈ G := G.mem_of_eqOnSource (closedUnderRestriction' (G.compatible he he') (e.isOpen_inter_preimage_symm s.2)) (e.subtypeRestr_symm_trans_subtypeRestr hs e') section MaximalAtlas variable (G : StructureGroupoid H) variable (M) in /-- Given a charted space admitting a structure groupoid, the maximal atlas associated to this structure groupoid is the set of all charts that are compatible with the atlas, i.e., such that changing coordinates with an atlas member gives an element of the groupoid. -/ def StructureGroupoid.maximalAtlas : Set (OpenPartialHomeomorph M H) := { e | ∀ e' ∈ atlas H M, e.symm ≫ₕ e' ∈ G ∧ e'.symm ≫ₕ e ∈ G } /-- The elements of the atlas belong to the maximal atlas for any structure groupoid. -/ theorem StructureGroupoid.subset_maximalAtlas [HasGroupoid M G] : atlas H M ⊆ G.maximalAtlas M := fun _ he _ he' ↦ ⟨G.compatible he he', G.compatible he' he⟩ theorem StructureGroupoid.chart_mem_maximalAtlas [HasGroupoid M G] (x : M) : chartAt H x ∈ G.maximalAtlas M := G.subset_maximalAtlas (chart_mem_atlas H x) variable {G} theorem mem_maximalAtlas_iff {e : OpenPartialHomeomorph M H} : e ∈ G.maximalAtlas M ↔ ∀ e' ∈ atlas H M, e.symm ≫ₕ e' ∈ G ∧ e'.symm ≫ₕ e ∈ G := Iff.rfl /-- Changing coordinates between two elements of the maximal atlas gives rise to an element of the structure groupoid. -/ theorem StructureGroupoid.compatible_of_mem_maximalAtlas {e e' : OpenPartialHomeomorph M H} (he : e ∈ G.maximalAtlas M) (he' : e' ∈ G.maximalAtlas M) : e.symm ≫ₕ e' ∈ G := by refine G.locality fun x hx ↦ ?_ set f := chartAt (H := H) (e.symm x) let s := e.target ∩ e.symm ⁻¹' f.source have hs : IsOpen s := by apply e.symm.continuousOn_toFun.isOpen_inter_preimage <;> apply open_source have xs : x ∈ s := by simp only [s, f, mem_inter_iff, mem_preimage, mem_chart_source, and_true] exact ((mem_inter_iff _ _ _).1 hx).1 refine ⟨s, hs, xs, ?_⟩ have A : e.symm ≫ₕ f ∈ G := (mem_maximalAtlas_iff.1 he f (chart_mem_atlas _ _)).1 have B : f.symm ≫ₕ e' ∈ G := (mem_maximalAtlas_iff.1 he' f (chart_mem_atlas _ _)).2 have C : (e.symm ≫ₕ f) ≫ₕ f.symm ≫ₕ e' ∈ G := G.trans A B have D : (e.symm ≫ₕ f) ≫ₕ f.symm ≫ₕ e' ≈ (e.symm ≫ₕ e').restr s := calc (e.symm ≫ₕ f) ≫ₕ f.symm ≫ₕ e' = e.symm ≫ₕ (f ≫ₕ f.symm) ≫ₕ e' := by simp only [trans_assoc] _ ≈ e.symm ≫ₕ ofSet f.source f.open_source ≫ₕ e' := EqOnSource.trans' (refl _) (EqOnSource.trans' (self_trans_symm _) (refl _)) _ ≈ (e.symm ≫ₕ ofSet f.source f.open_source) ≫ₕ e' := by rw [trans_assoc] _ ≈ e.symm.restr s ≫ₕ e' := by rw [trans_of_set']; apply refl _ ≈ (e.symm ≫ₕ e').restr s := by rw [restr_trans] exact G.mem_of_eqOnSource C (Setoid.symm D) open OpenPartialHomeomorph in /-- The maximal atlas of a structure groupoid is stable under equivalence. -/ lemma StructureGroupoid.mem_maximalAtlas_of_eqOnSource {e e' : OpenPartialHomeomorph M H} (h : e' ≈ e) (he : e ∈ G.maximalAtlas M) : e' ∈ G.maximalAtlas M := by intro e'' he'' obtain ⟨l, r⟩ := mem_maximalAtlas_iff.mp he e'' he'' exact ⟨G.mem_of_eqOnSource l (EqOnSource.trans' (EqOnSource.symm' h) (e''.eqOnSource_refl)), G.mem_of_eqOnSource r (EqOnSource.trans' (e''.symm).eqOnSource_refl h)⟩ variable (G) /-- In the model space, the identity is in any maximal atlas. -/ theorem StructureGroupoid.id_mem_maximalAtlas : OpenPartialHomeomorph.refl H ∈ G.maximalAtlas H := G.subset_maximalAtlas <| by simp /-- In the model space, any element of the groupoid is in the maximal atlas. -/ theorem StructureGroupoid.mem_maximalAtlas_of_mem_groupoid {f : OpenPartialHomeomorph H H} (hf : f ∈ G) : f ∈ G.maximalAtlas H := by rintro e (rfl : e = OpenPartialHomeomorph.refl H) exact ⟨G.trans (G.symm hf) G.id_mem, G.trans (G.symm G.id_mem) hf⟩ theorem StructureGroupoid.maximalAtlas_mono {G G' : StructureGroupoid H} (h : G ≤ G') : G.maximalAtlas M ⊆ G'.maximalAtlas M := fun _ he e' he' ↦ ⟨h (he e' he').1, h (he e' he').2⟩ private theorem restr_mem_maximalAtlas_aux1 [ClosedUnderRestriction G] {e e' : OpenPartialHomeomorph M H} (he : e ∈ G.maximalAtlas M) (he' : e' ∈ atlas H M) {s : Set M} (hs : IsOpen s) : (e.restr s).symm ≫ₕ e' ∈ G := by have hs'' : IsOpen (e '' (e.source ∩ s)) := by rw [isOpen_image_iff_of_subset_source _ inter_subset_left] exact e.open_source.inter hs have : (e.restr (e.source ∩ s)).symm ≫ₕ e' ∈ G := by apply G.mem_of_eqOnSource (closedUnderRestriction' (he e' he').1 hs'') exact e.restr_symm_trans (e.open_source.inter hs) hs'' inter_subset_left refine G.mem_of_eqOnSource this ?_ exact EqOnSource.trans' (Setoid.symm e.restr_inter_source).symm' (eqOnSource_refl e') private theorem restr_mem_maximalAtlas_aux2 [ClosedUnderRestriction G] {e e' : OpenPartialHomeomorph M H} (he : e ∈ G.maximalAtlas M) (he' : e' ∈ atlas H M) {s : Set M} (hs : IsOpen s) : e'.symm ≫ₕ e.restr s ∈ G := by have hs'' : IsOpen (e' '' (e'.source ∩ s)) := by rw [isOpen_image_iff_of_subset_source e' inter_subset_left] exact e'.open_source.inter hs have ht : IsOpen (e'.target ∩ e'.symm ⁻¹' s) := by rw [← image_source_inter_eq'] exact isOpen_image_source_inter e' hs exact G.mem_of_eqOnSource (closedUnderRestriction' (he e' he').2 ht) (e.symm_trans_restr e' hs) /-- If a structure groupoid `G` is closed under restriction, for any chart `e` in the maximal atlas, the restriction `e.restr s` to an open set `s` is also in the maximal atlas. -/ theorem restr_mem_maximalAtlas [ClosedUnderRestriction G] {e : OpenPartialHomeomorph M H} (he : e ∈ G.maximalAtlas M) {s : Set M} (hs : IsOpen s) : e.restr s ∈ G.maximalAtlas M := fun _e' he' ↦ ⟨restr_mem_maximalAtlas_aux1 G he he' hs, restr_mem_maximalAtlas_aux2 G he he' hs⟩ end MaximalAtlas section Singleton variable {α : Type*} [TopologicalSpace α] namespace OpenPartialHomeomorph variable (e : OpenPartialHomeomorph α H) /-- If a single open partial homeomorphism `e` from a space `α` into `H` has source covering the whole space `α`, then that open partial homeomorphism induces an `H`-charted space structure on `α`. (This condition is equivalent to `e` being an open embedding of `α` into `H`; see `IsOpenEmbedding.singletonChartedSpace`.) -/ def singletonChartedSpace (h : e.source = Set.univ) : ChartedSpace H α where atlas := {e} chartAt _ := e mem_chart_source _ := by rw [h]; apply mem_univ chart_mem_atlas _ := by tauto @[simp, mfld_simps] theorem singletonChartedSpace_chartAt_eq (h : e.source = Set.univ) {x : α} : @chartAt H _ α _ (e.singletonChartedSpace h) x = e := rfl theorem singletonChartedSpace_chartAt_source (h : e.source = Set.univ) {x : α} : (@chartAt H _ α _ (e.singletonChartedSpace h) x).source = Set.univ := h theorem singletonChartedSpace_mem_atlas_eq (h : e.source = Set.univ) (e' : OpenPartialHomeomorph α H) (h' : e' ∈ (e.singletonChartedSpace h).atlas) : e' = e := h' /-- Given an open partial homeomorphism `e` from a space `α` into `H`, if its source covers the whole space `α`, then the induced charted space structure on `α` is `HasGroupoid G` for any structure groupoid `G` which is closed under restrictions. -/ theorem singleton_hasGroupoid (h : e.source = Set.univ) (G : StructureGroupoid H) [ClosedUnderRestriction G] : @HasGroupoid _ _ _ _ (e.singletonChartedSpace h) G := { __ := e.singletonChartedSpace h compatible := by intro e' e'' he' he'' rw [e.singletonChartedSpace_mem_atlas_eq h e' he', e.singletonChartedSpace_mem_atlas_eq h e'' he''] refine G.mem_of_eqOnSource ?_ e.symm_trans_self have hle : idRestrGroupoid ≤ G := (closedUnderRestriction_iff_id_le G).mp (by assumption) exact StructureGroupoid.le_iff.mp hle _ (idRestrGroupoid_mem _) } end OpenPartialHomeomorph namespace Topology.IsOpenEmbedding variable [Nonempty α] /-- An open embedding of `α` into `H` induces an `H`-charted space structure on `α`. See `OpenPartialHomeomorph.singletonChartedSpace`. -/ def singletonChartedSpace {f : α → H} (h : IsOpenEmbedding f) : ChartedSpace H α := (h.toOpenPartialHomeomorph f).singletonChartedSpace (toOpenPartialHomeomorph_source _ _) theorem singletonChartedSpace_chartAt_eq {f : α → H} (h : IsOpenEmbedding f) {x : α} : ⇑(@chartAt H _ α _ h.singletonChartedSpace x) = f := rfl theorem singleton_hasGroupoid {f : α → H} (h : IsOpenEmbedding f) (G : StructureGroupoid H) [ClosedUnderRestriction G] : @HasGroupoid _ _ _ _ h.singletonChartedSpace G := (h.toOpenPartialHomeomorph f).singleton_hasGroupoid (toOpenPartialHomeomorph_source _ _) G end Topology.IsOpenEmbedding end Singleton namespace TopologicalSpace.Opens open TopologicalSpace variable (G : StructureGroupoid H) [HasGroupoid M G] variable (s : Opens M) /-- An open subset of a charted space is naturally a charted space. -/ protected instance instChartedSpace : ChartedSpace H s where atlas := ⋃ x : s, {(chartAt H x.1).subtypeRestr ⟨x⟩} chartAt x := (chartAt H x.1).subtypeRestr ⟨x⟩ mem_chart_source x := ⟨trivial, mem_chart_source H x.1⟩ chart_mem_atlas x := by simp only [mem_iUnion, mem_singleton_iff] use x /-- If `s` is a non-empty open subset of `M`, every chart of `s` is the restriction of some chart on `M`. -/ lemma chart_eq {s : Opens M} (hs : Nonempty s) {e : OpenPartialHomeomorph s H} (he : e ∈ atlas H s) : ∃ x : s, e = (chartAt H (x : M)).subtypeRestr hs := by rcases he with ⟨xset, ⟨x, hx⟩, he⟩ exact ⟨x, mem_singleton_iff.mp (by convert he)⟩ /-- If `t` is a non-empty open subset of `H`, every chart of `t` is the restriction of some chart on `H`. -/ -- XXX: can I unify this with `chart_eq`? lemma chart_eq' {t : Opens H} (ht : Nonempty t) {e' : OpenPartialHomeomorph t H} (he' : e' ∈ atlas H t) : ∃ x : t, e' = (chartAt H ↑x).subtypeRestr ht := chart_eq ht he' /-- If a groupoid `G` is `ClosedUnderRestriction`, then an open subset of a space which is `HasGroupoid G` is naturally `HasGroupoid G`. -/ protected instance instHasGroupoid [ClosedUnderRestriction G] : HasGroupoid s G where compatible := by rintro e e' ⟨_, ⟨x, hc⟩, he⟩ ⟨_, ⟨x', hc'⟩, he'⟩ rw [hc.symm, mem_singleton_iff] at he rw [hc'.symm, mem_singleton_iff] at he' rw [he, he'] refine G.mem_of_eqOnSource ?_ (subtypeRestr_symm_trans_subtypeRestr (s := s) _ (chartAt H x) (chartAt H x')) apply closedUnderRestriction' · exact G.compatible (chart_mem_atlas _ _) (chart_mem_atlas _ _) · exact isOpen_inter_preimage_symm (chartAt _ _) s.2 theorem chartAt_subtype_val_symm_eventuallyEq (U : Opens M) {x : U} : (chartAt H x.val).symm =ᶠ[𝓝 (chartAt H x.val x.val)] Subtype.val ∘ (chartAt H x).symm := by set e := chartAt H x.val have heUx_nhds : (e.subtypeRestr ⟨x⟩).target ∈ 𝓝 (e x) := by apply (e.subtypeRestr ⟨x⟩).open_target.mem_nhds exact e.map_subtype_source ⟨x⟩ (mem_chart_source _ _) exact Filter.eventuallyEq_of_mem heUx_nhds (e.subtypeRestr_symm_eqOn ⟨x⟩) theorem chartAt_inclusion_symm_eventuallyEq {U V : Opens M} (hUV : U ≤ V) {x : U} : (chartAt H (Opens.inclusion hUV x)).symm =ᶠ[𝓝 (chartAt H (Opens.inclusion hUV x) (Set.inclusion hUV x))] Opens.inclusion hUV ∘ (chartAt H x).symm := by set e := chartAt H (x : M) have heUx_nhds : (e.subtypeRestr ⟨x⟩).target ∈ 𝓝 (e x) := by apply (e.subtypeRestr ⟨x⟩).open_target.mem_nhds exact e.map_subtype_source ⟨x⟩ (mem_chart_source _ _) exact Filter.eventuallyEq_of_mem heUx_nhds <| e.subtypeRestr_symm_eqOn_of_le ⟨x⟩ ⟨Opens.inclusion hUV x⟩ hUV end TopologicalSpace.Opens /-- Restricting a chart of `M` to an open subset `s` yields a chart in the maximal atlas of `s`. NB. We cannot deduce membership in `atlas H s` in general: by definition, this atlas contains precisely the restriction of each preferred chart at `x ∈ s` --- whereas `atlas H M` can contain more charts than these. -/ lemma StructureGroupoid.subtypeRestr_mem_maximalAtlas {e : OpenPartialHomeomorph M H} (he : e ∈ atlas H M) {s : Opens M} (hs : Nonempty s) {G : StructureGroupoid H} [HasGroupoid M G] [ClosedUnderRestriction G] : e.subtypeRestr hs ∈ G.maximalAtlas s := by intro e' he' -- `e'` is the restriction of some chart of `M` at `x`, obtain ⟨x, this⟩ := Opens.chart_eq hs he' rw [this] -- The transition functions between the unrestricted charts lie in the groupoid, -- the transition functions of the restriction are the restriction of the transition function. exact ⟨G.trans_restricted he (chart_mem_atlas H (x : M)) hs, G.trans_restricted (chart_mem_atlas H (x : M)) he hs⟩ @[deprecated (since := "2025-08-17")] alias StructureGroupoid.restriction_in_maximalAtlas := StructureGroupoid.subtypeRestr_mem_maximalAtlas /-! ### Structomorphisms -/ /-- A `G`-diffeomorphism between two charted spaces is a homeomorphism which, when read in the charts, belongs to `G`. We avoid the word diffeomorph as it is too related to the smooth category, and use structomorph instead. -/ structure Structomorph (G : StructureGroupoid H) (M : Type*) (M' : Type*) [TopologicalSpace M] [TopologicalSpace M'] [ChartedSpace H M] [ChartedSpace H M'] extends Homeomorph M M' where mem_groupoid : ∀ c : OpenPartialHomeomorph M H, ∀ c' : OpenPartialHomeomorph M' H, c ∈ atlas H M → c' ∈ atlas H M' → c.symm ≫ₕ toHomeomorph.toOpenPartialHomeomorph ≫ₕ c' ∈ G variable [TopologicalSpace M'] [TopologicalSpace M''] {G : StructureGroupoid H} [ChartedSpace H M'] [ChartedSpace H M''] /-- The identity is a diffeomorphism of any charted space, for any groupoid. -/ def Structomorph.refl (M : Type*) [TopologicalSpace M] [ChartedSpace H M] [HasGroupoid M G] : Structomorph G M M := { Homeomorph.refl M with mem_groupoid := fun c c' hc hc' ↦ by change OpenPartialHomeomorph.symm c ≫ₕ OpenPartialHomeomorph.refl M ≫ₕ c' ∈ G rw [OpenPartialHomeomorph.refl_trans] exact G.compatible hc hc' } /-- The inverse of a structomorphism is a structomorphism. -/ def Structomorph.symm (e : Structomorph G M M') : Structomorph G M' M := { e.toHomeomorph.symm with mem_groupoid := by intro c c' hc hc' have : (c'.symm ≫ₕ e.toHomeomorph.toOpenPartialHomeomorph ≫ₕ c).symm ∈ G := G.symm (e.mem_groupoid c' c hc' hc) rwa [trans_symm_eq_symm_trans_symm, trans_symm_eq_symm_trans_symm, symm_symm, trans_assoc] at this } /-- The composition of structomorphisms is a structomorphism. -/ def Structomorph.trans (e : Structomorph G M M') (e' : Structomorph G M' M'') : Structomorph G M M'' := { Homeomorph.trans e.toHomeomorph e'.toHomeomorph with mem_groupoid := by /- Let c and c' be two charts in M and M''. We want to show that e' ∘ e is smooth in these charts, around any point x. For this, let y = e (c⁻¹ x), and consider a chart g around y. Then g ∘ e ∘ c⁻¹ and c' ∘ e' ∘ g⁻¹ are both smooth as e and e' are structomorphisms, so their composition is smooth, and it coincides with c' ∘ e' ∘ e ∘ c⁻¹ around x. -/ intro c c' hc hc' refine G.locality fun x hx ↦ ?_ let f₁ := e.toHomeomorph.toOpenPartialHomeomorph let f₂ := e'.toHomeomorph.toOpenPartialHomeomorph let f := (e.toHomeomorph.trans e'.toHomeomorph).toOpenPartialHomeomorph have feq : f = f₁ ≫ₕ f₂ := Homeomorph.trans_toOpenPartialHomeomorph _ _ -- define the atlas g around y let y := (c.symm ≫ₕ f₁) x let g := chartAt (H := H) y have hg₁ := chart_mem_atlas (H := H) y have hg₂ := mem_chart_source (H := H) y let s := (c.symm ≫ₕ f₁).source ∩ c.symm ≫ₕ f₁ ⁻¹' g.source have open_s : IsOpen s := by apply (c.symm ≫ₕ f₁).continuousOn_toFun.isOpen_inter_preimage <;> apply open_source have : x ∈ s := by constructor · simp only [f₁, trans_source, preimage_univ, inter_univ, Homeomorph.toOpenPartialHomeomorph_source] rw [trans_source] at hx exact hx.1 · exact hg₂ refine ⟨s, open_s, this, ?_⟩ let F₁ := (c.symm ≫ₕ f₁ ≫ₕ g) ≫ₕ g.symm ≫ₕ f₂ ≫ₕ c' have A : F₁ ∈ G := G.trans (e.mem_groupoid c g hc hg₁) (e'.mem_groupoid g c' hg₁ hc') let F₂ := (c.symm ≫ₕ f ≫ₕ c').restr s have : F₁ ≈ F₂ := calc F₁ ≈ c.symm ≫ₕ f₁ ≫ₕ (g ≫ₕ g.symm) ≫ₕ f₂ ≫ₕ c' := by simp only [F₁, trans_assoc, _root_.refl] _ ≈ c.symm ≫ₕ f₁ ≫ₕ ofSet g.source g.open_source ≫ₕ f₂ ≫ₕ c' := EqOnSource.trans' (_root_.refl _) (EqOnSource.trans' (_root_.refl _) (EqOnSource.trans' (self_trans_symm g) (_root_.refl _))) _ ≈ ((c.symm ≫ₕ f₁) ≫ₕ ofSet g.source g.open_source) ≫ₕ f₂ ≫ₕ c' := by simp only [trans_assoc, _root_.refl] _ ≈ (c.symm ≫ₕ f₁).restr s ≫ₕ f₂ ≫ₕ c' := by rw [trans_of_set'] _ ≈ ((c.symm ≫ₕ f₁) ≫ₕ f₂ ≫ₕ c').restr s := by rw [restr_trans] _ ≈ (c.symm ≫ₕ (f₁ ≫ₕ f₂) ≫ₕ c').restr s := by simp only [trans_assoc, _root_.refl] _ ≈ F₂ := by simp only [F₂, feq, _root_.refl] have : F₂ ∈ G := G.mem_of_eqOnSource A (Setoid.symm this) exact this } /-- Restricting a chart to its source `s ⊆ M` yields a chart in the maximal atlas of `s`. -/ theorem StructureGroupoid.restriction_mem_maximalAtlas_subtype {e : OpenPartialHomeomorph M H} (he : e ∈ atlas H M) (hs : Nonempty e.source) [HasGroupoid M G] [ClosedUnderRestriction G] : let s := { carrier := e.source, is_open' := e.open_source : Opens M } let t := { carrier := e.target, is_open' := e.open_target : Opens H } ∀ c' ∈ atlas H t, e.toHomeomorphSourceTarget.toOpenPartialHomeomorph ≫ₕ c' ∈ G.maximalAtlas s := by intro s t c' hc' have : Nonempty t := nonempty_coe_sort.mpr (e.mapsTo.nonempty (nonempty_coe_sort.mp hs)) obtain ⟨x, hc'⟩ := Opens.chart_eq this hc' -- As H has only one chart, `chartAt H x` is the identity: i.e., `c'` is the inclusion. rw [hc', (chartAt_self_eq)] -- Our expression equals this chart, at least on its source. rw [OpenPartialHomeomorph.subtypeRestr_def, OpenPartialHomeomorph.trans_refl] let goal := e.toHomeomorphSourceTarget.toOpenPartialHomeomorph ≫ₕ (t.openPartialHomeomorphSubtypeCoe this) have : goal ≈ e.subtypeRestr (s := s) hs := (goal.eqOnSource_iff (e.subtypeRestr (s := s) hs)).mpr ⟨by simp only [trans_toPartialEquiv, PartialEquiv.trans_source, Homeomorph.toOpenPartialHomeomorph_source, toFun_eq_coe, Homeomorph.toOpenPartialHomeomorph_apply, Opens.openPartialHomeomorphSubtypeCoe_source, preimage_univ, inter_self, subtypeRestr_source, goal, s] exact Subtype.coe_preimage_self _ |>.symm, by intro _ _; rfl⟩ exact G.mem_maximalAtlas_of_eqOnSource (M := s) this (G.subtypeRestr_mem_maximalAtlas he hs) /-- Each chart of a charted space is a structomorphism between its source and target. -/ def OpenPartialHomeomorph.toStructomorph {e : OpenPartialHomeomorph M H} (he : e ∈ atlas H M) [HasGroupoid M G] [ClosedUnderRestriction G] : let s : Opens M := { carrier := e.source, is_open' := e.open_source } let t : Opens H := { carrier := e.target, is_open' := e.open_target } Structomorph G s t := by intro s t by_cases! h : Nonempty e.source · exact { e.toHomeomorphSourceTarget with mem_groupoid := -- The atlas of H on itself has only one chart, hence c' is the inclusion. -- Then, compatibility of `G` *almost* yields our claim --- except that `e` is a chart -- on `M` and `c` is one on `s`: we need to show that restricting `e` to `s` and composing -- with `c'` yields a chart in the maximal atlas of `s`. fun c c' hc hc' ↦ G.compatible_of_mem_maximalAtlas (G.subset_maximalAtlas hc) (G.restriction_mem_maximalAtlas_subtype he h c' hc') } · have : IsEmpty t := isEmpty_coe_sort.mpr (by convert e.image_source_eq_target ▸ image_eq_empty.mpr (isEmpty_coe_sort.mp h)) exact { Homeomorph.empty with -- `c'` cannot exist: it would be the restriction of `chartAt H x` at some `x ∈ t`. mem_groupoid := fun _ c' _ ⟨_, ⟨x, _⟩, _⟩ ↦ (this.false x).elim } end HasGroupoid set_option linter.style.longFile 1700
.lake/packages/mathlib/Mathlib/Geometry/Manifold/ContMDiffMap.lean
import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace /-! # `C^n` bundled maps In this file we define the type `ContMDiffMap` of `n` times continuously differentiable bundled maps. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H : Type*} [TopologicalSpace H] {H' : Type*} [TopologicalSpace H'] {I : ModelWithCorners 𝕜 E H} {I' : ModelWithCorners 𝕜 E' H'} (M : Type*) [TopologicalSpace M] [ChartedSpace H M] (M' : Type*) [TopologicalSpace M'] [ChartedSpace H' M'] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] -- declare a manifold `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] (n : WithTop ℕ∞) variable (I I') in /-- Bundled `n` times continuously differentiable maps, denoted as `C^n(I, M; I', M')` and `C^n(I, M; k)` (when the target is a normed space `k` with the trivial model) in the `Manifold` namespace. -/ def ContMDiffMap := { f : M → M' // ContMDiff I I' n f } @[inherit_doc] scoped[Manifold] notation "C^" n "⟮" I ", " M "; " I' ", " M' "⟯" => ContMDiffMap I I' M M' n @[inherit_doc] scoped[Manifold] notation "C^" n "⟮" I ", " M "; " k "⟯" => ContMDiffMap I (modelWithCornersSelf k k) M k n open scoped Manifold ContDiff namespace ContMDiffMap variable {M} {M'} {n} instance instFunLike : FunLike C^n⟮I, M; I', M'⟯ M M' where coe := Subtype.val coe_injective' := Subtype.coe_injective protected theorem contMDiff (f : C^n⟮I, M; I', M'⟯) : ContMDiff I I' n f := f.prop attribute [to_additive_ignore_args 21] ContMDiffMap ContMDiffMap.instFunLike variable {f g : C^n⟮I, M; I', M'⟯} @[simp] theorem coeFn_mk (f : M → M') (hf : ContMDiff I I' n f) : DFunLike.coe (F := C^n⟮I, M; I', M'⟯) ⟨f, hf⟩ = f := rfl theorem coe_injective ⦃f g : C^n⟮I, M; I', M'⟯⦄ (h : (f : M → M') = g) : f = g := DFunLike.ext' h @[ext] theorem ext (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h instance : ContinuousMapClass C^n⟮I, M; I', M'⟯ M M' where map_continuous f := f.contMDiff.continuous /-- The identity as a `C^n` map. -/ nonrec def id : C^n⟮I, M; I, M⟯ := ⟨id, contMDiff_id⟩ /-- The composition of `C^n` maps, as a `C^n` map. -/ def comp (f : C^n⟮I', M'; I'', M''⟯) (g : C^n⟮I, M; I', M'⟯) : C^n⟮I, M; I'', M''⟯ where val a := f (g a) property := f.contMDiff.comp g.contMDiff @[simp] theorem comp_apply (f : C^n⟮I', M'; I'', M''⟯) (g : C^n⟮I, M; I', M'⟯) (x : M) : f.comp g x = f (g x) := rfl instance [Inhabited M'] : Inhabited C^n⟮I, M; I', M'⟯ := ⟨⟨fun _ => default, contMDiff_const⟩⟩ /-- Constant map as a `C^n` map -/ def const (y : M') : C^n⟮I, M; I', M'⟯ := ⟨fun _ => y, contMDiff_const⟩ /-- The first projection of a product, as a `C^n` map. -/ def fst : C^n⟮I.prod I', M × M'; I, M⟯ := ⟨Prod.fst, contMDiff_fst⟩ /-- The second projection of a product, as a `C^n` map. -/ def snd : C^n⟮I.prod I', M × M'; I', M'⟯ := ⟨Prod.snd, contMDiff_snd⟩ /-- Given two `C^n` maps `f` and `g`, this is the `C^n` map `x ↦ (f x, g x)`. -/ def prodMk (f : C^n⟮J, N; I, M⟯) (g : C^n⟮J, N; I', M'⟯) : C^n⟮J, N; I.prod I', M × M'⟯ := ⟨fun x => (f x, g x), f.2.prodMk g.2⟩ end ContMDiffMap instance ContinuousLinearMap.hasCoeToContMDiffMap : Coe (E →L[𝕜] E') C^n⟮𝓘(𝕜, E), E; 𝓘(𝕜, E'), E'⟯ := ⟨fun f => ⟨f, f.contMDiff⟩⟩
.lake/packages/mathlib/Mathlib/Geometry/Manifold/BumpFunction.lean
import Mathlib.Analysis.Calculus.BumpFunction.FiniteDimension import Mathlib.Geometry.Manifold.ContMDiff.Atlas import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace import Mathlib.Topology.MetricSpace.ProperSpace.Lemmas /-! # Smooth bump functions on a smooth manifold In this file we define `SmoothBumpFunction I c` to be a bundled smooth "bump" function centered at `c`. It is a structure that consists of two real numbers `0 < rIn < rOut` with small enough `rOut`. We define a coercion to function for this type, and for `f : SmoothBumpFunction I c`, the function `⇑f` written in the extended chart at `c` has the following properties: * `f x = 1` in the closed ball of radius `f.rIn` centered at `c`; * `f x = 0` outside of the ball of radius `f.rOut` centered at `c`; * `0 ≤ f x ≤ 1` for all `x`. The actual statements involve (pre)images under `extChartAt I f` and are given as lemmas in the `SmoothBumpFunction` namespace. ## Tags manifold, smooth bump function -/ universe uE uF uH uM variable {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] open Function Filter Module Set Metric open scoped Topology Manifold ContDiff noncomputable section /-! ### Smooth bump function In this section we define a structure for a bundled smooth bump function and prove its properties. -/ variable (I) in /-- Given a smooth manifold modelled on a finite-dimensional space `E`, `f : SmoothBumpFunction I M` is a smooth function on `M` such that in the extended chart `e` at `f.c`: * `f x = 1` in the closed ball of radius `f.rIn` centered at `f.c`; * `f x = 0` outside of the ball of radius `f.rOut` centered at `f.c`; * `0 ≤ f x ≤ 1` for all `x`. The structure contains data required to construct a function with these properties. The function is available as `⇑f` or `f x`. Formal statements of the properties listed above involve some (pre)images under `extChartAt I f.c` and are given as lemmas in the `SmoothBumpFunction` namespace. -/ structure SmoothBumpFunction (c : M) extends ContDiffBump (extChartAt I c c) where closedBall_subset : closedBall (extChartAt I c c) rOut ∩ range I ⊆ (extChartAt I c).target namespace SmoothBumpFunction section FiniteDimensional variable [FiniteDimensional ℝ E] variable {c : M} (f : SmoothBumpFunction I c) {x : M} /-- The function defined by `f : SmoothBumpFunction c`. Use automatic coercion to function instead. -/ @[coe] def toFun : M → ℝ := indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c) instance : CoeFun (SmoothBumpFunction I c) fun _ => M → ℝ := ⟨toFun⟩ theorem coe_def : ⇑f = indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c) := rfl end FiniteDimensional variable {c : M} (f : SmoothBumpFunction I c) {x : M} theorem rOut_pos : 0 < f.rOut := f.toContDiffBump.rOut_pos theorem ball_subset : ball (extChartAt I c c) f.rOut ∩ range I ⊆ (extChartAt I c).target := Subset.trans (inter_subset_inter_left _ ball_subset_closedBall) f.closedBall_subset theorem ball_inter_range_eq_ball_inter_target : ball (extChartAt I c c) f.rOut ∩ range I = ball (extChartAt I c c) f.rOut ∩ (extChartAt I c).target := (subset_inter inter_subset_left f.ball_subset).antisymm <| inter_subset_inter_right _ <| extChartAt_target_subset_range _ section FiniteDimensional variable [FiniteDimensional ℝ E] theorem eqOn_source : EqOn f (f.toContDiffBump ∘ extChartAt I c) (chartAt H c).source := eqOn_indicator theorem eventuallyEq_of_mem_source (hx : x ∈ (chartAt H c).source) : f =ᶠ[𝓝 x] f.toContDiffBump ∘ extChartAt I c := f.eqOn_source.eventuallyEq_of_mem <| (chartAt H c).open_source.mem_nhds hx theorem one_of_dist_le (hs : x ∈ (chartAt H c).source) (hd : dist (extChartAt I c x) (extChartAt I c c) ≤ f.rIn) : f x = 1 := by simp only [f.eqOn_source hs, (· ∘ ·), f.one_of_mem_closedBall hd] theorem support_eq_inter_preimage : support f = (chartAt H c).source ∩ extChartAt I c ⁻¹' ball (extChartAt I c c) f.rOut := by rw [coe_def, support_indicator, support_comp_eq_preimage, ← extChartAt_source I, ← (extChartAt I c).symm_image_target_inter_eq', ← (extChartAt I c).symm_image_target_inter_eq', f.support_eq] theorem isOpen_support : IsOpen (support f) := by rw [support_eq_inter_preimage] exact isOpen_extChartAt_preimage c isOpen_ball theorem support_eq_symm_image : support f = (extChartAt I c).symm '' (ball (extChartAt I c c) f.rOut ∩ range I) := by rw [f.support_eq_inter_preimage, ← extChartAt_source I, ← (extChartAt I c).symm_image_target_inter_eq', inter_comm, ball_inter_range_eq_ball_inter_target] theorem support_subset_source : support f ⊆ (chartAt H c).source := by rw [f.support_eq_inter_preimage, ← extChartAt_source I]; exact inter_subset_left theorem image_eq_inter_preimage_of_subset_support {s : Set M} (hs : s ⊆ support f) : extChartAt I c '' s = closedBall (extChartAt I c c) f.rOut ∩ range I ∩ (extChartAt I c).symm ⁻¹' s := by rw [support_eq_inter_preimage, subset_inter_iff, ← extChartAt_source I, ← image_subset_iff] at hs obtain ⟨hse, hsf⟩ := hs apply Subset.antisymm · refine subset_inter (subset_inter (hsf.trans ball_subset_closedBall) ?_) ?_ · rintro _ ⟨x, -, rfl⟩; exact mem_range_self _ · rw [(extChartAt I c).image_eq_target_inter_inv_preimage hse] exact inter_subset_right · refine Subset.trans (inter_subset_inter_left _ f.closedBall_subset) ?_ rw [(extChartAt I c).image_eq_target_inter_inv_preimage hse] theorem mem_Icc : f x ∈ Icc (0 : ℝ) 1 := by have : f x = 0 ∨ f x = _ := indicator_eq_zero_or_self _ _ _ rcases this with h | h <;> rw [h] exacts [left_mem_Icc.2 zero_le_one, ⟨f.nonneg, f.le_one⟩] theorem nonneg : 0 ≤ f x := f.mem_Icc.1 theorem le_one : f x ≤ 1 := f.mem_Icc.2 theorem eventuallyEq_one_of_dist_lt (hs : x ∈ (chartAt H c).source) (hd : dist (extChartAt I c x) (extChartAt I c c) < f.rIn) : f =ᶠ[𝓝 x] 1 := by filter_upwards [IsOpen.mem_nhds (isOpen_extChartAt_preimage c isOpen_ball) ⟨hs, hd⟩] rintro z ⟨hzs, hzd⟩ exact f.one_of_dist_le hzs <| le_of_lt hzd theorem eventuallyEq_one : f =ᶠ[𝓝 c] 1 := f.eventuallyEq_one_of_dist_lt (mem_chart_source _ _) <| by rw [dist_self]; exact f.rIn_pos @[simp] theorem eq_one : f c = 1 := f.eventuallyEq_one.eq_of_nhds theorem support_mem_nhds : support f ∈ 𝓝 c := f.eventuallyEq_one.mono fun x hx => by rw [hx]; exact one_ne_zero theorem tsupport_mem_nhds : tsupport f ∈ 𝓝 c := mem_of_superset f.support_mem_nhds subset_closure theorem c_mem_support : c ∈ support f := mem_of_mem_nhds f.support_mem_nhds theorem nonempty_support : (support f).Nonempty := ⟨c, f.c_mem_support⟩ theorem isCompact_symm_image_closedBall : IsCompact ((extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I)) := ((isCompact_closedBall _ _).inter_right I.isClosed_range).image_of_continuousOn <| (continuousOn_extChartAt_symm _).mono f.closedBall_subset end FiniteDimensional /-- Given a smooth bump function `f : SmoothBumpFunction I c`, the closed ball of radius `f.R` is known to include the support of `f`. These closed balls (in the model normed space `E`) intersected with `Set.range I` form a basis of `𝓝[range I] (extChartAt I c c)`. -/ theorem nhdsWithin_range_basis : (𝓝[range I] extChartAt I c c).HasBasis (fun _ : SmoothBumpFunction I c => True) fun f => closedBall (extChartAt I c c) f.rOut ∩ range I := by refine ((nhdsWithin_hasBasis nhds_basis_closedBall _).restrict_subset (extChartAt_target_mem_nhdsWithin _)).to_hasBasis' ?_ ?_ · rintro R ⟨hR0, hsub⟩ exact ⟨⟨⟨R / 2, R, half_pos hR0, half_lt_self hR0⟩, hsub⟩, trivial, Subset.rfl⟩ · exact fun f _ => inter_mem (mem_nhdsWithin_of_mem_nhds <| closedBall_mem_nhds _ f.rOut_pos) self_mem_nhdsWithin variable [FiniteDimensional ℝ E] theorem isClosed_image_of_isClosed {s : Set M} (hsc : IsClosed s) (hs : s ⊆ support f) : IsClosed (extChartAt I c '' s) := by rw [f.image_eq_inter_preimage_of_subset_support hs] refine ContinuousOn.preimage_isClosed_of_isClosed ((continuousOn_extChartAt_symm _).mono f.closedBall_subset) ?_ hsc exact IsClosed.inter isClosed_closedBall I.isClosed_range /-- If `f` is a smooth bump function and `s` closed subset of the support of `f` (i.e., of the open ball of radius `f.rOut`), then there exists `0 < r < f.rOut` such that `s` is a subset of the open ball of radius `r`. Formally, `s ⊆ e.source ∩ e ⁻¹' (ball (e c) r)`, where `e = extChartAt I c`. -/ theorem exists_r_pos_lt_subset_ball {s : Set M} (hsc : IsClosed s) (hs : s ⊆ support f) : ∃ r ∈ Ioo 0 f.rOut, s ⊆ (chartAt H c).source ∩ extChartAt I c ⁻¹' ball (extChartAt I c c) r := by set e := extChartAt I c have : IsClosed (e '' s) := f.isClosed_image_of_isClosed hsc hs rw [support_eq_inter_preimage, subset_inter_iff, ← image_subset_iff] at hs rcases exists_pos_lt_subset_ball f.rOut_pos this hs.2 with ⟨r, hrR, hr⟩ exact ⟨r, hrR, subset_inter hs.1 (image_subset_iff.1 hr)⟩ /-- Replace `rIn` with another value in the interval `(0, f.rOut)`. -/ @[simps rOut rIn] def updateRIn (r : ℝ) (hr : r ∈ Ioo 0 f.rOut) : SmoothBumpFunction I c := ⟨⟨r, f.rOut, hr.1, hr.2⟩, f.closedBall_subset⟩ @[simp] theorem support_updateRIn {r : ℝ} (hr : r ∈ Ioo 0 f.rOut) : support (f.updateRIn r hr) = support f := by simp only [support_eq_inter_preimage, updateRIn_rOut] instance : Nonempty (SmoothBumpFunction I c) := nhdsWithin_range_basis.nonempty variable [T2Space M] theorem isClosed_symm_image_closedBall : IsClosed ((extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I)) := f.isCompact_symm_image_closedBall.isClosed theorem tsupport_subset_symm_image_closedBall : tsupport f ⊆ (extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I) := by rw [tsupport, support_eq_symm_image] exact closure_minimal (image_mono <| inter_subset_inter_left _ ball_subset_closedBall) f.isClosed_symm_image_closedBall theorem tsupport_subset_extChartAt_source : tsupport f ⊆ (extChartAt I c).source := calc tsupport f ⊆ (extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I) := f.tsupport_subset_symm_image_closedBall _ ⊆ (extChartAt I c).symm '' (extChartAt I c).target := image_mono f.closedBall_subset _ = (extChartAt I c).source := (extChartAt I c).symm_image_target_eq_source theorem tsupport_subset_chartAt_source : tsupport f ⊆ (chartAt H c).source := by simpa only [extChartAt_source] using f.tsupport_subset_extChartAt_source protected theorem hasCompactSupport : HasCompactSupport f := f.isCompact_symm_image_closedBall.of_isClosed_subset isClosed_closure f.tsupport_subset_symm_image_closedBall variable (c) in /-- The closures of supports of smooth bump functions centered at `c` form a basis of `𝓝 c`. In other words, each of these closures is a neighborhood of `c` and each neighborhood of `c` includes `tsupport f` for some `f : SmoothBumpFunction I c`. -/ theorem nhds_basis_tsupport : (𝓝 c).HasBasis (fun _ : SmoothBumpFunction I c => True) fun f => tsupport f := by have : (𝓝 c).HasBasis (fun _ : SmoothBumpFunction I c => True) fun f => (extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I) := by rw [← map_extChartAt_symm_nhdsWithin_range (I := I) c] exact nhdsWithin_range_basis.map _ exact this.to_hasBasis' (fun f _ => ⟨f, trivial, f.tsupport_subset_symm_image_closedBall⟩) fun f _ => f.tsupport_mem_nhds /-- Given `s ∈ 𝓝 c`, the supports of smooth bump functions `f : SmoothBumpFunction I c` such that `tsupport f ⊆ s` form a basis of `𝓝 c`. In other words, each of these supports is a neighborhood of `c` and each neighborhood of `c` includes `support f` for some `f : SmoothBumpFunction I c` such that `tsupport f ⊆ s`. -/ theorem nhds_basis_support {s : Set M} (hs : s ∈ 𝓝 c) : (𝓝 c).HasBasis (fun f : SmoothBumpFunction I c => tsupport f ⊆ s) fun f => support f := ((nhds_basis_tsupport c).restrict_subset hs).to_hasBasis' (fun f hf => ⟨f, hf.2, subset_closure⟩) fun f _ => f.support_mem_nhds variable [IsManifold I ∞ M] /-- A smooth bump function is infinitely smooth. -/ protected theorem contMDiff : ContMDiff I 𝓘(ℝ) ∞ f := by refine contMDiff_of_tsupport fun x hx => ?_ have : x ∈ (chartAt H c).source := f.tsupport_subset_chartAt_source hx refine ContMDiffAt.congr_of_eventuallyEq ?_ <| f.eqOn_source.eventuallyEq_of_mem <| (chartAt H c).open_source.mem_nhds this exact f.contDiffAt.contMDiffAt.comp _ (contMDiffAt_extChartAt' this) protected theorem contMDiffAt {x} : ContMDiffAt I 𝓘(ℝ) ∞ f x := f.contMDiff.contMDiffAt protected theorem continuous : Continuous f := f.contMDiff.continuous /-- If `f : SmoothBumpFunction I c` is a smooth bump function and `g : M → G` is a function smooth on the source of the chart at `c`, then `f • g` is smooth on the whole manifold. -/ theorem contMDiff_smul {G} [NormedAddCommGroup G] [NormedSpace ℝ G] {g : M → G} (hg : ContMDiffOn I 𝓘(ℝ, G) ∞ g (chartAt H c).source) : ContMDiff I 𝓘(ℝ, G) ∞ fun x => f x • g x := by refine contMDiff_of_tsupport fun x hx => ?_ -- Porting note: was a more readable `calc` -- calc -- x ∈ tsupport fun x => f x • g x := hx -- _ ⊆ tsupport f := tsupport_smul_subset_left _ _ -- _ ⊆ (chart_at _ c).source := f.tsupport_subset_chartAt_source have : x ∈ (chartAt H c).source := f.tsupport_subset_chartAt_source <| tsupport_smul_subset_left _ _ hx exact f.contMDiffAt.smul ((hg _ this).contMDiffAt <| (chartAt _ _).open_source.mem_nhds this) end SmoothBumpFunction
.lake/packages/mathlib/Mathlib/Geometry/Manifold/GroupLieAlgebra.lean
import Mathlib.Algebra.Lie.Basic import Mathlib.Geometry.Manifold.Algebra.LieGroup import Mathlib.Geometry.Manifold.VectorField.LieBracket /-! # The Lie algebra of a Lie group Given a Lie group, we define `GroupLieAlgebra I G` as its tangent space at the identity, and we endow it with a Lie bracket, as follows. Given two vectors `v, w : GroupLieAlgebra I G`, consider the associated left-invariant vector fields `mulInvariantVectorField v` (given at a point `g` by the image of `v` under the derivative of left-multiplication by `g`) and `mulInvariantVectorField w`. Then take their Lie bracket at the identity: this is by definition the bracket of `v` and `w`. Due to general properties of the Lie bracket of vector fields, this gives a Lie algebra structure on `GroupLieAlgebra I G`. Note that one can also define a Lie algebra on the space of left-invariant derivations on `C^∞` functions (see `LeftInvariantDerivation.instLieAlgebra`). For finite-dimensional `C^∞` real manifolds, this space of derivations can be canonically identified with the tangent space, and we recover the same Lie algebra structure (TODO: prove this). In other smoothness classes or on other fields, this identification is not always true, though, so the derivations point of view does not work in these settings. Therefore, the point of view in the current file is more general, and should be favored when possible. The standing assumption in this file is that the group is `C^n` for `n = minSmoothness 𝕜 3`, i.e., it is `C^3` over `ℝ` or `ℂ`, and analytic otherwise. -/ noncomputable section section LieGroup open Bundle Filter Function Set open scoped Manifold variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {I : ModelWithCorners 𝕜 E H} {G : Type*} [TopologicalSpace G] [ChartedSpace H G] [Group G] variable (I G) in /-- The Lie algebra of a Lie group, i.e., its tangent space at the identity. We use the word `GroupLieAlgebra` instead of `LieAlgebra` as the latter is taken as a generic class. -/ @[to_additive /-- The Lie algebra of an additive Lie group, i.e., its tangent space at zero. We use the word `AddGroupLieAlgebra` instead of `LieAlgebra` as the latter is taken as a generic class. -/] abbrev GroupLieAlgebra : Type _ := TangentSpace I (1 : G) /-- The invariant vector field associated to a vector `v` in the Lie algebra. At a point `g`, it is given by the image of `v` under left-multiplication by `g`. -/ @[to_additive /-- The invariant vector field associated to a vector `v` in the Lie algebra. At a point `g`, it is given by the image of `v` under left-addition by `g`. -/] noncomputable def mulInvariantVectorField (v : GroupLieAlgebra I G) (g : G) : TangentSpace I g := mfderiv I I (g * ·) (1 : G) v @[to_additive] lemma mulInvariantVectorField_add (v w : GroupLieAlgebra I G) : mulInvariantVectorField (v + w) = mulInvariantVectorField v + mulInvariantVectorField w := by ext g simp [mulInvariantVectorField] /- `to_additive` fails on the next lemma, as it tries to additivize `smul` while it shouldn't. Therefore, we state and prove by hand the additive version. -/ lemma addInvariantVectorField_smul {G : Type*} [TopologicalSpace G] [ChartedSpace H G] [AddGroup G] (c : 𝕜) (v : AddGroupLieAlgebra I G) : addInvariantVectorField (c • v) = c • addInvariantVectorField v := by ext g simp [addInvariantVectorField] lemma mulInvariantVectorField_smul (c : 𝕜) (v : GroupLieAlgebra I G) : mulInvariantVectorField (c • v) = c • mulInvariantVectorField v := by ext g simp [mulInvariantVectorField] open VectorField /-- The Lie bracket of two vectors `v` and `w` in the Lie algebra of a Lie group is obtained by taking the Lie bracket of the associated invariant vector fields, at the identity. -/ @[to_additive /-- The Lie bracket of two vectors `v` and `w` in the Lie algebra of an additive Lie group is obtained by taking the Lie bracket of the associated invariant vector fields, at zero. -/] noncomputable instance : Bracket (GroupLieAlgebra I G) (GroupLieAlgebra I G) where bracket v w := mlieBracket I (mulInvariantVectorField v) (mulInvariantVectorField w) (1 : G) @[to_additive] lemma GroupLieAlgebra.bracket_def (v w : GroupLieAlgebra I G) : ⁅v, w⁆ = mlieBracket I (mulInvariantVectorField v) (mulInvariantVectorField w) (1 : G) := rfl variable [LieGroup I (minSmoothness 𝕜 3) G] @[to_additive (attr := simp)] lemma inverse_mfderiv_mul_left {g h : G} : (mfderiv I I (fun b ↦ g * b) h).inverse = mfderiv I I (fun b ↦ g⁻¹ * b) (g * h) := by have M : 1 ≤ minSmoothness 𝕜 3 := le_trans (by simp) le_minSmoothness have A : mfderiv I I ((fun x ↦ g⁻¹ * x) ∘ (fun x ↦ g * x)) h = ContinuousLinearMap.id _ _ := by have : (fun x ↦ g⁻¹ * x) ∘ (fun x ↦ g * x) = id := by ext x; simp rw [this, id_eq, mfderiv_id] rw [mfderiv_comp (I' := I) _ (contMDiff_mul_left.contMDiffAt.mdifferentiableAt M) (contMDiff_mul_left.contMDiffAt.mdifferentiableAt M)] at A have A' : mfderiv I I ((fun x ↦ g * x) ∘ (fun x ↦ g⁻¹ * x)) (g * h) = ContinuousLinearMap.id _ _ := by have : (fun x ↦ g * x) ∘ (fun x ↦ g⁻¹ * x) = id := by ext x; simp rw [this, id_eq, mfderiv_id] rw [mfderiv_comp (I' := I) _ (contMDiff_mul_left.contMDiffAt.mdifferentiableAt M) (contMDiff_mul_left.contMDiffAt.mdifferentiableAt M), inv_mul_cancel_left g h] at A' exact ContinuousLinearMap.inverse_eq A' A /-- Invariant vector fields are invariant under pullbacks. -/ @[to_additive /-- Invariant vector fields are invariant under pullbacks. -/] lemma mpullback_mulInvariantVectorField (g : G) (v : GroupLieAlgebra I G) : mpullback I I (g * ·) (mulInvariantVectorField v) = mulInvariantVectorField v := by have M : 1 ≤ minSmoothness 𝕜 3 := le_trans (by simp) le_minSmoothness ext h simp only [mpullback, inverse_mfderiv_mul_left, mulInvariantVectorField] have D : (fun x ↦ h * x) = (fun b ↦ g⁻¹ * b) ∘ (fun x ↦ g * h * x) := by ext x; simp only [comp_apply]; group rw [D, mfderiv_comp (I' := I)] · congr 2 simp · exact contMDiff_mul_left.contMDiffAt.mdifferentiableAt M · exact contMDiff_mul_left.contMDiffAt.mdifferentiableAt M @[to_additive] lemma mulInvariantVectorField_eq_mpullback (g : G) (V : Π (g : G), TangentSpace I g) : mulInvariantVectorField (V 1) g = mpullback I I (g ⁻¹ * ·) V g := by have A : 1 = g⁻¹ * g := by simp simp only [mulInvariantVectorField, mpullback, inverse_mfderiv_mul_left] congr simp @[to_additive] theorem contMDiff_mulInvariantVectorField (v : GroupLieAlgebra I G) : ContMDiff I I.tangent (minSmoothness 𝕜 2) (fun (g : G) ↦ (mulInvariantVectorField v g : TangentBundle I G)) := by /- We will write the desired map as a composition of obviously smooth maps. The derivative of the product `P : (g, h) ↦ g * h` is given by `DP (g, h) ⬝ (u, v) = DL_g v + DR_h u`, where `L_g` and `R_h` are respectively left and right multiplication by `g` and `h`. As `P` is smooth, so is `DP`. Consider the map `F₁ : M → T (M × M)` mapping `g` to `(0, v) ∈ T_(g, e) (M × M)`. Then the composition of `DP` with `F₁` maps `g` to `DL_g v ∈ T_g M`, thanks to the above formula. This is the desired invariant vector field. Since both `DP` and `F₁` are smooth, their composition is smooth as desired. There is a small abuse of notation in the above argument, where we have identified `T (M × M)` and `TM × TM`. In the formal proof, we need to introduce this identification, called `F₂` below, which is also already known to be smooth. -/ have M : 1 ≤ minSmoothness 𝕜 3 := le_trans (by simp) le_minSmoothness have A : minSmoothness 𝕜 2 + 1 = minSmoothness 𝕜 3 := by rw [← minSmoothness_add] norm_num let fg : G → TangentBundle I G := fun g ↦ TotalSpace.mk' E g 0 have sfg : ContMDiff I I.tangent (minSmoothness 𝕜 2) fg := contMDiff_zeroSection _ _ let fv : G → TangentBundle I G := fun _ ↦ TotalSpace.mk' E 1 v have sfv : ContMDiff I I.tangent (minSmoothness 𝕜 2) fv := contMDiff_const let F₁ : G → (TangentBundle I G × TangentBundle I G) := fun g ↦ (fg g, fv g) have S₁ : ContMDiff I (I.tangent.prod I.tangent) (minSmoothness 𝕜 2) F₁ := ContMDiff.prodMk sfg sfv let F₂ : (TangentBundle I G × TangentBundle I G) → TangentBundle (I.prod I) (G × G) := (equivTangentBundleProd I G I G).symm have S₂ : ContMDiff (I.tangent.prod I.tangent) (I.prod I).tangent (minSmoothness 𝕜 2) F₂ := contMDiff_equivTangentBundleProd_symm let F₃ : TangentBundle (I.prod I) (G × G) → TangentBundle I G := tangentMap (I.prod I) I (fun (p : G × G) ↦ p.1 * p.2) have S₃ : ContMDiff (I.prod I).tangent I.tangent (minSmoothness 𝕜 2) F₃ := by apply ContMDiff.contMDiff_tangentMap _ (m := minSmoothness 𝕜 2) le_rfl rw [A] exact contMDiff_mul I (minSmoothness 𝕜 3) let S := (S₃.comp S₂).comp S₁ convert S with g · simp [F₁, F₂, F₃, fg, fv] · simp only [comp_apply, tangentMap, F₃, F₂, F₁, fg, fv] rw [mfderiv_prod_eq_add_apply ((contMDiff_mul I (minSmoothness 𝕜 3)).mdifferentiableAt M)] simp [mulInvariantVectorField] @[to_additive] theorem contMDiffAt_mulInvariantVectorField (v : GroupLieAlgebra I G) {g : G} : ContMDiffAt I I.tangent (minSmoothness 𝕜 2) (fun (g : G) ↦ (mulInvariantVectorField v g : TangentBundle I G)) g := (contMDiff_mulInvariantVectorField v).contMDiffAt @[to_additive] theorem mdifferentiable_mulInvariantVectorField (v : GroupLieAlgebra I G) : MDifferentiable I I.tangent (fun (g : G) ↦ (mulInvariantVectorField v g : TangentBundle I G)) := (contMDiff_mulInvariantVectorField v).mdifferentiable (le_trans (by simp) le_minSmoothness) @[to_additive] theorem mdifferentiableAt_mulInvariantVectorField (v : GroupLieAlgebra I G) {g : G} : MDifferentiableAt I I.tangent (fun (g : G) ↦ (mulInvariantVectorField v g : TangentBundle I G)) g := (contMDiffAt_mulInvariantVectorField v).mdifferentiableAt (le_trans (by simp) le_minSmoothness) open VectorField variable [CompleteSpace E] /-- The invariant vector field associated to the value at the identity of the Lie bracket of two invariant vector fields, is everywhere the Lie bracket of the invariant vector fields. -/ @[to_additive /-- The invariant vector field associated to the value at zero of the Lie bracket of two invariant vector fields, is everywhere the Lie bracket of the invariant vector fields. -/] lemma mulInvariantVector_mlieBracket (v w : GroupLieAlgebra I G) : mulInvariantVectorField (mlieBracket I (mulInvariantVectorField v) (mulInvariantVectorField w) 1) = mlieBracket I (mulInvariantVectorField v) (mulInvariantVectorField w) := by ext g rw [mulInvariantVectorField_eq_mpullback, mpullback_mlieBracket (n := minSmoothness 𝕜 3), mpullback_mulInvariantVectorField, mpullback_mulInvariantVectorField] · exact mdifferentiableAt_mulInvariantVectorField _ · exact mdifferentiableAt_mulInvariantVectorField _ · exact contMDiffAt_mul_left · exact minSmoothness_monotone (by norm_cast) /-- The tangent space at the identity of a Lie group is a Lie ring, for the bracket given by the Lie bracket of invariant vector fields. -/ @[to_additive /-- The tangent space at the identity of an additive Lie group is a Lie ring, for the bracket given by the Lie bracket of invariant vector fields. -/] noncomputable instance : LieRing (GroupLieAlgebra I G) where add_lie u v w := by simp only [GroupLieAlgebra.bracket_def, mulInvariantVectorField_add] rw [mlieBracket_add_left] · exact mdifferentiableAt_mulInvariantVectorField _ · exact mdifferentiableAt_mulInvariantVectorField _ lie_add u v w := by simp only [GroupLieAlgebra.bracket_def, mulInvariantVectorField_add] rw [mlieBracket_add_right] · exact mdifferentiableAt_mulInvariantVectorField _ · exact mdifferentiableAt_mulInvariantVectorField _ lie_self v := by simp [GroupLieAlgebra.bracket_def] leibniz_lie u v w := by simp only [GroupLieAlgebra.bracket_def, mulInvariantVector_mlieBracket] apply leibniz_identity_mlieBracket_apply <;> exact contMDiff_mulInvariantVectorField _ _ /- `to_additive` fails on the next instance, as it tries to additivize `smul` while it shouldn't. Therefore, we state and prove by hand the additive version. -/ /-- The tangent space at the identity of an additive Lie group is a Lie algebra, for the bracket given by the Lie bracket of invariant vector fields. -/ noncomputable instance instLieAlgebraAddGroupLieAlgebra {G : Type*} [TopologicalSpace G] [ChartedSpace H G] [AddGroup G] [LieAddGroup I (minSmoothness 𝕜 3) G] : LieAlgebra 𝕜 (AddGroupLieAlgebra I G) where lie_smul c v w := by simp only [AddGroupLieAlgebra.bracket_def, addInvariantVectorField_smul] rw [mlieBracket_const_smul_right] exact mdifferentiableAt_addInvariantVectorField _ /-- The tangent space at the identity of a Lie group is a Lie algebra, for the bracket given by the Lie bracket of invariant vector fields. -/ noncomputable instance instLieAlgebraGroupLieAlgebra : LieAlgebra 𝕜 (GroupLieAlgebra I G) where lie_smul c v w := by simp only [GroupLieAlgebra.bracket_def, mulInvariantVectorField_smul] rw [mlieBracket_const_smul_right] exact mdifferentiableAt_mulInvariantVectorField _ end LieGroup
.lake/packages/mathlib/Mathlib/Geometry/Manifold/ConformalGroupoid.lean
import Mathlib.Analysis.Calculus.Conformal.NormedSpace import Mathlib.Geometry.Manifold.ChartedSpace /-! # Conformal Groupoid In this file we define the groupoid of conformal maps on normed spaces. ## Main definitions * `conformalGroupoid`: the groupoid of conformal open partial homeomorphisms. ## Tags conformal, groupoid -/ variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] /-- The pregroupoid of conformal maps. -/ def conformalPregroupoid : Pregroupoid X where property f u := ∀ x, x ∈ u → ConformalAt f x comp {f _} _ _ hf hg _ _ _ x hx := (hg (f x) hx.2).comp x (hf x hx.1) id_mem x _ := conformalAt_id x locality _ h x hx := let ⟨_, _, h₂, h₃⟩ := h x hx h₃ x ⟨hx, h₂⟩ congr hu h hf x hx := (hf x hx).congr hx hu h /-- The groupoid of conformal maps. -/ def conformalGroupoid : StructureGroupoid X := conformalPregroupoid.groupoid
.lake/packages/mathlib/Mathlib/Geometry/Manifold/Metrizable.lean
import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.Geometry.Manifold.IsManifold.Basic import Mathlib.Topology.Compactness.Paracompact import Mathlib.Topology.Metrizable.Urysohn /-! # Metrizability of a σ-compact manifold In this file we show that a σ-compact Hausdorff topological manifold over a finite-dimensional real vector space is metrizable. -/ open TopologicalSpace /-- A σ-compact Hausdorff topological manifold over a finite-dimensional real vector space is metrizable. -/ theorem Manifold.metrizableSpace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners ℝ E H) (M : Type*) [TopologicalSpace M] [ChartedSpace H M] [SigmaCompactSpace M] [T2Space M] : MetrizableSpace M := by haveI := I.locallyCompactSpace; haveI := ChartedSpace.locallyCompactSpace H M haveI := I.secondCountableTopology haveI := ChartedSpace.secondCountable_of_sigmaCompact H M exact metrizableSpace_of_t3_secondCountable M
.lake/packages/mathlib/Mathlib/Geometry/Manifold/Bordism.lean
import Mathlib.Geometry.Manifold.Instances.Real /-! ## (Unoriented) bordism theory This file defines the beginnings of unoriented bordism theory. We define singular manifolds, the building blocks of unoriented bordism groups. Future pull requests will define bordisms and the bordism groups of a topological space, and prove these are abelian groups. The basic notion of bordism theory is that of a bordism between smooth manifolds. Two compact smooth `n`-dimensional manifolds `M` and `N` are **bordant** if there exists a smooth **bordism** between them: this is a compact `n+1`-dimensional manifold `W` whose boundary is (diffeomorphic to) the disjoint union `M ⊕ N`. Being bordant is an equivalence relation (transitivity follows from the collar neighbourhood theorem). The set of equivalence classes has an abelian group structure, with the group operation given as disjoint union of manifolds, and is called the `n`-th (unoriented) bordism group. This construction can be generalised one step further, to produce an extraordinary homology theory. Given a topological space `X`, a **singular manifold** on `X` is a closed smooth manifold `M` together with a continuous map `M → F`. (The word *singular* does not refer to singularities, but is by analogy to singular chains in the definition of singular homology.) Given two `n`-dimensional singular manifolds `s` and `t`, an (oriented) bordism between `s` and `t` is a compact smooth `n+1`-dimensional manifold `W` whose boundary is (diffeomorphic to) the disjoint union of `s` and `t`, together with a map `W → X` which restricts to the maps on `s` and `t`. We call `s` and `t` bordant if there exists a bordism between them: again, this defines an equivalence relation. The `n`-th bordism group of `X` is the set of bordism classes of `n`-dimensional singular manifolds on `X`. If `X` is a single point, this recovers the bordism groups from the preceding paragraph. These absolute bordism groups can be generalised further to relative bordism groups, for each topological pair `(X, A)`; in fact, these define an extra-ordinary homology theory. ## Main definitions - **SingularManifold X k I**: a singular manifold on a topological space `X`, is a pair `(M, f)` of a closed `C^k`-manifold `M` modelled on `I` together with a continuous map `M → X`. We don't assume `M` to be modelled on `ℝⁿ`, but add the model topological space `H`, the vector space `E` and the model with corners `I` as type parameters. If we wish to emphasize the model, with will speak of a singular `I`-manifold. To define a disjoint unions of singular manifolds, we require their domains to be manifolds over the same model with corners: this is why we make the model explicit. ## Main results - `SingularManifold.map`: a map `X → Y` of topological spaces induces a map between the spaces of singular manifolds. This will be used to define functoriality of bordism groups. - `SingularManifold.comap`: if `(N, f)` is a singular manifold on `X` and `φ : M → N` is continuous, the `comap` of `(N, f)` and `φ` is the induced singular manifold `(M, f ∘ φ)` on `X`. - `SingularManifold.empty`: the empty set `M`, viewed as a manifold, as a singular manifold over any space `X`. - `SingularManifold.toPUnit`: a smooth manifold induces a singular manifold on the one-point space. - `SingularManifold.prod`: the product of a singular `I`-manifold and a singular `J`-manifold on the one-point space, is a singular `I.prod J`-manifold on the one-point space. - `SingularManifold.sum`: the disjoint union of two singular `I`-manifolds is a singular `I`-manifold. ## Implementation notes * We choose a bundled design for singular manifolds (and also for bordisms): to construct the group structure on the set of bordism classes, having that be a type is useful. * The underlying model with corners is a type parameter, as defining a disjoint union of singular manifolds requires their domains to be manifolds over the same model with corners. Thus, either we restrict to manifolds modelled over `𝓡n` (which we prefer not to), or the model must be a type parameter. * Having `SingularManifold` contain the type `M` as explicit structure field is not ideal, as this adds a universe parameter to the structure. However, this is the best solution we found: we generally cannot have `M` live in the same universe as `X` (a common case is `X` being `PUnit`), and determining the universe of `M` from the universes of `E` and `H` would make `SingularManifold.map` painful to state (as that would require `ULift`ing `M`). ## TODO - define bordisms and prove basic constructions (e.g. reflexivity, symmetry, transitivity) and operations (e.g. disjoint union, sum with the empty set) - define the bordism relation and prove it is an equivalence relation - define the unoriented bordism group (the set of bordism classes) and prove it is an abelian group - for bordisms on a one-point space, define multiplication and prove the bordism ring structure - define relative bordism groups (generalising the previous three points) - prove that relative unoriented bordism groups define an extraordinary homology theory ## Tags singular manifold, bordism, bordism group -/ open scoped Manifold open Module Set suppress_compilation /-- A **singular manifold** on a topological space `X` is a pair `(M, f)` of a closed `C^k`-manifold `M` modelled on `I` together with a continuous map `M → X`. If we wish to emphasize the model, with will speak of a singular `I`-manifold. In practice, one commonly wants to take `k=∞` (as then e.g. the intersection form is a powerful tool to compute bordism groups; for the definition, this makes no difference.) This is parametrised on the universe `M` lives in; ensure `u` is the first universe argument. -/ structure SingularManifold.{u} (X : Type*) [TopologicalSpace X] (k : WithTop ℕ∞) {E H : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [TopologicalSpace H] (I : ModelWithCorners ℝ E H) where /-- The manifold `M` of a singular `n`-manifold `(M, f)` -/ M : Type u /-- The manifold `M` is a topological space. -/ [topSpaceM : TopologicalSpace M] /-- The manifold `M` is a charted space over `H`. -/ [chartedSpace : ChartedSpace H M] /-- `M` is a `C^k` manifold. -/ [isManifold : IsManifold I k M] [compactSpace : CompactSpace M] [boundaryless : BoundarylessManifold I M] /-- The underlying map `M → X` of a singular `n`-manifold `(M, f)` on `X` -/ f : M → X hf : Continuous f namespace SingularManifold variable {X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] {k : WithTop ℕ∞} {E H M : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [TopologicalSpace H] {I : ModelWithCorners ℝ E H} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I k M] [CompactSpace M] [BoundarylessManifold I M] instance {s : SingularManifold X k I} : TopologicalSpace s.M := s.topSpaceM instance {s : SingularManifold X k I} : ChartedSpace H s.M := s.chartedSpace instance {s : SingularManifold X k I} : IsManifold I k s.M := s.isManifold instance {s : SingularManifold X k I} : CompactSpace s.M := s.compactSpace instance {s : SingularManifold X k I} : BoundarylessManifold I s.M := s.boundaryless /-- A map of topological spaces induces a corresponding map of singular manifolds. -/ -- This is part of proving functoriality of the bordism groups. def map.{u} {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {k : WithTop ℕ∞} {E H : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [TopologicalSpace H] {I : ModelWithCorners ℝ E H} (s : SingularManifold.{u} X k I) {φ : X → Y} (hφ : Continuous φ) : SingularManifold.{u} Y k I where M := s.M f := φ ∘ s.f hf := hφ.comp s.hf @[simp, mfld_simps] lemma map_f (s : SingularManifold X k I) {φ : X → Y} (hφ : Continuous φ) : (s.map hφ).f = φ ∘ s.f := rfl @[simp, mfld_simps] lemma map_M (s : SingularManifold X k I) {φ : X → Y} (hφ : Continuous φ) : (s.map hφ).M = s.M := rfl lemma map_comp (s : SingularManifold X k I) {φ : X → Y} {ψ : Y → Z} (hφ : Continuous φ) (hψ : Continuous ψ) : ((s.map hφ).map hψ).f = (ψ ∘ φ) ∘ s.f := by simp [Function.comp_def] variable {E' H' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [TopologicalSpace H'] variable (M I) in /-- If `M` is a closed `C^k` manifold, it is a singular manifold over itself. -/ noncomputable def refl : SingularManifold M k I where M := M f := id hf := continuous_id /-- If `(N, f)` is a singular manifold on `X` and `M` another `C^k` manifold, a continuous map `φ : M → N` induces a singular manifold structure `(M, f ∘ φ)` on `X`. -/ noncomputable def comap (s : SingularManifold X k I) {φ : M → s.M} (hφ : Continuous φ) : SingularManifold X k I where M := M f := s.f ∘ φ hf := s.hf.comp hφ @[simp, mfld_simps] lemma comap_M (s : SingularManifold X k I) {φ : M → s.M} (hφ : Continuous φ) : (s.comap hφ).M = M := by rfl @[simp, mfld_simps] lemma comap_f (s : SingularManifold X k I) {φ : M → s.M} (hφ : Continuous φ) : (s.comap hφ).f = s.f ∘ φ := rfl variable (X) in /-- The canonical singular manifold associated to the empty set (seen as a smooth manifold) -/ def empty.{u} (M : Type u) [TopologicalSpace M] [ChartedSpace H M] (I : ModelWithCorners ℝ E H) [IsManifold I k M] [IsEmpty M] : SingularManifold X k I where M := M f x := (IsEmpty.false x).elim hf := by rw [continuous_iff_continuousAt] exact fun x ↦ (IsEmpty.false x).elim omit [CompactSpace M] [BoundarylessManifold I M] in @[simp, mfld_simps] lemma empty_M [IsEmpty M] : (empty X M I (k := k)).M = M := rfl instance [IsEmpty M] : IsEmpty (SingularManifold.empty X M I (k := k)).M := by unfold SingularManifold.empty infer_instance variable (M I) in /-- A smooth manifold induces a singular manifold on the one-point space. -/ def toPUnit : SingularManifold PUnit k I where M := M f := fun _ ↦ PUnit.unit hf := continuous_const variable {I' : ModelWithCorners ℝ E' H'} [FiniteDimensional ℝ E'] /-- The product of a singular `I`- and a singular `J`-manifold into a one-point space is a singular `I.prod J`-manifold. This construction is used to prove that the bordism group of `PUnit` is a graded commutative ring. NB. This definition as written makes sense more generally, for `SingularManifold X k I` whenever `X` is a topological (additive) group. However, this would not be the correct definition if `X` is not `(P)Unit`: the bordism ring can be defined for every `C^k` manifold `X`, but the product of two singular manifolds `(M, f)` and `(N, g)` is the fibre product of `M` and `N` w.r.t. `f` and `g`, with its induced map into `X`. (If `f` and `g` intersect transversely, this fibre product is a smooth manifold, of dimension `dim M + dim N - dim X`. Otherwise, the transversality theorem proves that `f` (or `g`) admits an arbitrarily small perturbation `f'` so `f'` and `g` are transverse. One can prove that different perturbations yield bordant manifolds.) -/ def prod (s : SingularManifold PUnit k I) (t : SingularManifold PUnit k I') : SingularManifold PUnit k (I.prod I') where M := s.M × t.M f := fun _ ↦ PUnit.unit hf := continuous_const variable (s t : SingularManifold X k I) /-- The disjoint union of two singular `I`-manifolds on `X` is a singular `I`-manifold on `X`. -/ def sum (s t : SingularManifold X k I) : SingularManifold X k I where M := s.M ⊕ t.M f := Sum.elim s.f t.f hf := s.hf.sumElim t.hf @[simp, mfld_simps] lemma sum_M (s t : SingularManifold X k I) : (s.sum t).M = (s.M ⊕ t.M) := rfl @[simp, mfld_simps] lemma sum_f (s t : SingularManifold X k I) : (s.sum t).f = Sum.elim s.f t.f := rfl end SingularManifold
.lake/packages/mathlib/Mathlib/Geometry/Manifold/WhitneyEmbedding.lean
import Mathlib.FieldTheory.Finiteness import Mathlib.Geometry.Manifold.Diffeomorph import Mathlib.Geometry.Manifold.Instances.Real import Mathlib.Geometry.Manifold.PartitionOfUnity /-! # Whitney embedding theorem In this file we prove a version of the Whitney embedding theorem: for any compact real manifold `M`, for sufficiently large `n` there exists a smooth embedding `M → ℝ^n`. ## TODO * Prove the weak Whitney embedding theorem: any `σ`-compact smooth `m`-dimensional manifold can be embedded into `ℝ^(2m+1)`. This requires a version of Sard's theorem: for a locally Lipschitz continuous map `f : ℝ^m → ℝ^n`, `m < n`, the range has Hausdorff dimension at most `m`, hence it has measure zero. ## Tags partition of unity, smooth bump function, whitney theorem -/ universe uι uE uH uM open Function Filter Module Set Topology open scoped Manifold ContDiff variable {ι : Type uι} {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I ∞ M] noncomputable section namespace SmoothBumpCovering /-! ### Whitney embedding theorem In this section we prove a version of the Whitney embedding theorem: for any compact real manifold `M`, for sufficiently large `n` there exists a smooth embedding `M → ℝ^n`. -/ variable [T2Space M] [Fintype ι] {s : Set M} (f : SmoothBumpCovering ι I M s) /-- Smooth embedding of `M` into `(E × ℝ) ^ ι`. -/ def embeddingPiTangent : C^∞⟮I, M; 𝓘(ℝ, ι → E × ℝ), ι → E × ℝ⟯ where val x i := (f i x • extChartAt I (f.c i) x, f i x) property := contMDiff_pi_space.2 fun i => ((f i).contMDiff_smul contMDiffOn_extChartAt).prodMk_space (f i).contMDiff @[local simp] theorem embeddingPiTangent_coe : ⇑f.embeddingPiTangent = fun x i => (f i x • extChartAt I (f.c i) x, f i x) := rfl theorem embeddingPiTangent_injOn : InjOn f.embeddingPiTangent s := by intro x hx y _ h simp only [embeddingPiTangent_coe, funext_iff] at h obtain ⟨h₁, h₂⟩ := Prod.mk_inj.1 (h (f.ind x hx)) rw [f.apply_ind x hx] at h₂ rw [← h₂, f.apply_ind x hx, one_smul, one_smul] at h₁ have := f.mem_extChartAt_source_of_eq_one h₂.symm exact (extChartAt I (f.c _)).injOn (f.mem_extChartAt_ind_source x hx) this h₁ theorem embeddingPiTangent_injective (f : SmoothBumpCovering ι I M) : Injective f.embeddingPiTangent := injOn_univ.1 f.embeddingPiTangent_injOn theorem comp_embeddingPiTangent_mfderiv (x : M) (hx : x ∈ s) : ((ContinuousLinearMap.fst ℝ E ℝ).comp (@ContinuousLinearMap.proj ℝ _ ι (fun _ => E × ℝ) _ _ (fun _ => inferInstance) (f.ind x hx))).comp (mfderiv I 𝓘(ℝ, ι → E × ℝ) f.embeddingPiTangent x) = mfderiv I I (chartAt H (f.c (f.ind x hx))) x := by set L := (ContinuousLinearMap.fst ℝ E ℝ).comp (@ContinuousLinearMap.proj ℝ _ ι (fun _ => E × ℝ) _ _ (fun _ => inferInstance) (f.ind x hx)) have := L.hasMFDerivAt.comp x (f.embeddingPiTangent.contMDiff.mdifferentiableAt (mod_cast le_top)).hasMFDerivAt convert hasMFDerivAt_unique this _ refine (hasMFDerivAt_extChartAt (f.mem_chartAt_ind_source x hx)).congr_of_eventuallyEq ?_ refine (f.eventuallyEq_one x hx).mono fun y hy => ?_ simp only [L, embeddingPiTangent_coe, ContinuousLinearMap.coe_comp', (· ∘ ·), ContinuousLinearMap.coe_fst', ContinuousLinearMap.proj_apply] rw [hy, Pi.one_apply, one_smul] theorem embeddingPiTangent_ker_mfderiv (x : M) (hx : x ∈ s) : LinearMap.ker (mfderiv I 𝓘(ℝ, ι → E × ℝ) f.embeddingPiTangent x) = ⊥ := by apply bot_unique rw [← (mdifferentiable_chart (f.c (f.ind x hx))).ker_mfderiv_eq_bot (f.mem_chartAt_ind_source x hx), ← comp_embeddingPiTangent_mfderiv] exact LinearMap.ker_le_ker_comp _ _ theorem embeddingPiTangent_injective_mfderiv (x : M) (hx : x ∈ s) : Injective (mfderiv I 𝓘(ℝ, ι → E × ℝ) f.embeddingPiTangent x) := LinearMap.ker_eq_bot.1 (f.embeddingPiTangent_ker_mfderiv x hx) /-- Baby version of the **Whitney weak embedding theorem**: if `M` admits a finite covering by supports of bump functions, then for some `n` it can be immersed into the `n`-dimensional Euclidean space. -/ theorem exists_immersion_euclidean {ι : Type*} [Finite ι] (f : SmoothBumpCovering ι I M) : ∃ (n : ℕ) (e : M → EuclideanSpace ℝ (Fin n)), ContMDiff I (𝓡 n) ∞ e ∧ Injective e ∧ ∀ x : M, Injective (mfderiv I (𝓡 n) e x) := by cases nonempty_fintype ι set F := EuclideanSpace ℝ (Fin <| finrank ℝ (ι → E × ℝ)) letI : IsNoetherian ℝ (E × ℝ) := IsNoetherian.iff_fg.2 inferInstance letI : FiniteDimensional ℝ (ι → E × ℝ) := IsNoetherian.iff_fg.1 inferInstance set eEF : (ι → E × ℝ) ≃L[ℝ] F := ContinuousLinearEquiv.ofFinrankEq finrank_euclideanSpace_fin.symm refine ⟨_, eEF ∘ f.embeddingPiTangent, eEF.toDiffeomorph.contMDiff.comp f.embeddingPiTangent.contMDiff, eEF.injective.comp f.embeddingPiTangent_injective, fun x => ?_⟩ rw [mfderiv_comp _ eEF.differentiableAt.mdifferentiableAt (f.embeddingPiTangent.contMDiff.mdifferentiableAt (mod_cast le_top)), eEF.mfderiv_eq] exact eEF.injective.comp (f.embeddingPiTangent_injective_mfderiv _ trivial) end SmoothBumpCovering /-- Baby version of the Whitney weak embedding theorem: if `M` admits a finite covering by supports of bump functions, then for some `n` it can be embedded into the `n`-dimensional Euclidean space. -/ theorem exists_embedding_euclidean_of_compact [T2Space M] [CompactSpace M] : ∃ (n : ℕ) (e : M → EuclideanSpace ℝ (Fin n)), ContMDiff I (𝓡 n) ∞ e ∧ IsClosedEmbedding e ∧ ∀ x : M, Injective (mfderiv I (𝓡 n) e x) := by rcases SmoothBumpCovering.exists_isSubordinate I isClosed_univ fun (x : M) _ => univ_mem with ⟨ι, f, -⟩ haveI := f.fintype rcases f.exists_immersion_euclidean with ⟨n, e, hsmooth, hinj, hinj_mfderiv⟩ exact ⟨n, e, hsmooth, hsmooth.continuous.isClosedEmbedding hinj, hinj_mfderiv⟩
.lake/packages/mathlib/Mathlib/Geometry/Manifold/DerivationBundle.lean
import Mathlib.Geometry.Manifold.Algebra.SmoothFunctions import Mathlib.RingTheory.Derivation.Basic /-! # Derivation bundle In this file we define the derivations at a point of a manifold on the algebra of smooth functions. Moreover, we define the differential of a function in terms of derivations. The content of this file is not meant to be regarded as an alternative definition to the current tangent bundle but rather as a purely algebraic theory that provides a purely algebraic definition of the Lie algebra for a Lie group. This theory coincides with the usual tangent bundle in the case of finite-dimensional `C^∞` real manifolds, but not in the general case. -/ variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) (M : Type*) [TopologicalSpace M] [ChartedSpace H M] (n : WithTop ℕ∞) open scoped Manifold ContDiff -- the following two instances prevent poorly understood type class inference timeout problems instance smoothFunctionsAlgebra : Algebra 𝕜 C^∞⟮I, M; 𝕜⟯ := by infer_instance instance smooth_functions_tower : IsScalarTower 𝕜 C^∞⟮I, M; 𝕜⟯ C^∞⟮I, M; 𝕜⟯ := by infer_instance /-- Type synonym, introduced to put a different `SMul` action on `C^n⟮I, M; 𝕜⟯` which is defined as `f • r = f(x) * r`. Denoted as `C^n⟮I, M; 𝕜⟯⟨x⟩` within the `Derivation` namespace. -/ @[nolint unusedArguments] def PointedContMDiffMap (_ : M) := C^n⟮I, M; 𝕜⟯ @[inherit_doc] scoped[Derivation] notation "C^" n "⟮" I ", " M "; " 𝕜 "⟯⟨" x "⟩" => PointedContMDiffMap 𝕜 I M n x variable {𝕜 M} namespace PointedContMDiffMap open scoped Derivation instance instFunLike {x : M} : FunLike C^∞⟮I, M; 𝕜⟯⟨x⟩ M 𝕜 := ContMDiffMap.instFunLike instance {x : M} : CommRing C^∞⟮I, M; 𝕜⟯⟨x⟩ := ContMDiffMap.commRing instance {x : M} : Algebra 𝕜 C^∞⟮I, M; 𝕜⟯⟨x⟩ := ContMDiffMap.algebra instance {x : M} : Inhabited C^∞⟮I, M; 𝕜⟯⟨x⟩ := ⟨0⟩ instance {x : M} : Algebra C^∞⟮I, M; 𝕜⟯⟨x⟩ C^∞⟮I, M; 𝕜⟯ := Algebra.id C^∞⟮I, M; 𝕜⟯ instance {x : M} : IsScalarTower 𝕜 C^∞⟮I, M; 𝕜⟯⟨x⟩ C^∞⟮I, M; 𝕜⟯ := IsScalarTower.right variable {I} /-- `ContMDiffMap.evalRingHom` gives rise to an algebra structure of `C^∞⟮I, M; 𝕜⟯` on `𝕜`. -/ instance evalAlgebra {x : M} : Algebra C^∞⟮I, M; 𝕜⟯⟨x⟩ 𝕜 := (ContMDiffMap.evalRingHom x : C^∞⟮I, M; 𝕜⟯⟨x⟩ →+* 𝕜).toAlgebra /-- With the `evalAlgebra` algebra structure evaluation is actually an algebra morphism. -/ def eval (x : M) : C^∞⟮I, M; 𝕜⟯ →ₐ[C^∞⟮I, M; 𝕜⟯⟨x⟩] 𝕜 := Algebra.ofId C^∞⟮I, M; 𝕜⟯⟨x⟩ 𝕜 theorem smul_def (x : M) (f : C^∞⟮I, M; 𝕜⟯⟨x⟩) (k : 𝕜) : f • k = f x * k := rfl instance (x : M) : IsScalarTower 𝕜 C^∞⟮I, M; 𝕜⟯⟨x⟩ 𝕜 where smul_assoc k f h := by rw [smul_def, smul_def, ContMDiffMap.coe_smul, Pi.smul_apply, smul_eq_mul, smul_eq_mul, mul_assoc] end PointedContMDiffMap open scoped Derivation /-- The derivations at a point of a manifold. Some regard this as a possible definition of the tangent space, as this coincides with the usual tangent space for finite-dimensional `C^∞` real manifolds. The identification is not true in general, though. -/ abbrev PointDerivation (x : M) := Derivation 𝕜 C^∞⟮I, M; 𝕜⟯⟨x⟩ 𝕜 section open scoped Derivation variable (X : Derivation 𝕜 C^∞⟮I, M; 𝕜⟯ C^∞⟮I, M; 𝕜⟯) (f : C^∞⟮I, M; 𝕜⟯) /-- Evaluation at a point gives rise to a `C^∞⟮I, M; 𝕜⟯`-linear map between `C^∞⟮I, M; 𝕜⟯` and `𝕜`. -/ def ContMDiffFunction.evalAt (x : M) : C^∞⟮I, M; 𝕜⟯ →ₗ[C^∞⟮I, M; 𝕜⟯⟨x⟩] 𝕜 := (PointedContMDiffMap.eval x).toLinearMap namespace Derivation variable {I} /-- The evaluation at a point as a linear map. -/ def evalAt (x : M) : Derivation 𝕜 C^∞⟮I, M; 𝕜⟯ C^∞⟮I, M; 𝕜⟯ →ₗ[𝕜] PointDerivation I x := (ContMDiffFunction.evalAt I x).compDer theorem evalAt_apply (x : M) : evalAt x X f = (X f) x := rfl end Derivation variable {I} {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] /-- The heterogeneous differential as a linear map, denoted as `𝒅ₕ` within the `Manifold` namespace. Instead of taking a function as an argument, this differential takes `h : f x = y`. It is particularly handy for situations where the points at which it has to be evaluated are equal but not definitionally equal. -/ def hfdifferential {f : C^∞⟮I, M; I', M'⟯} {x : M} {y : M'} (h : f x = y) : PointDerivation I x →ₗ[𝕜] PointDerivation I' y where toFun v := Derivation.mk' { toFun := fun g => v (g.comp f) map_add' := fun g g' => by rw [ContMDiffMap.add_comp, Derivation.map_add] map_smul' := fun k g => by dsimp; rw [ContMDiffMap.smul_comp, Derivation.map_smul, smul_eq_mul] } fun g g' => by dsimp rw [ContMDiffMap.mul_comp, Derivation.leibniz, PointedContMDiffMap.smul_def, ContMDiffMap.comp_apply, PointedContMDiffMap.smul_def, ContMDiffMap.comp_apply, h] norm_cast map_smul' _ _ := rfl map_add' _ _ := rfl /-- The homogeneous differential as a linear map, denoted as `𝒅` within the `Manifold` namespace. -/ def fdifferential (f : C^∞⟮I, M; I', M'⟯) (x : M) : PointDerivation I x →ₗ[𝕜] PointDerivation I' (f x) := hfdifferential (rfl : f x = f x) -- Standard notation for the differential. The abbreviation is `MId`. @[inherit_doc] scoped[Manifold] notation "𝒅" => fdifferential -- Standard notation for the differential. The abbreviation is `MId`. @[inherit_doc] scoped[Manifold] notation "𝒅ₕ" => hfdifferential @[simp] theorem fdifferential_apply (f : C^∞⟮I, M; I', M'⟯) {x : M} (v : PointDerivation I x) (g : C^∞⟮I', M'; 𝕜⟯) : 𝒅 f x v g = v (g.comp f) := rfl @[simp] theorem hfdifferential_apply {f : C^∞⟮I, M; I', M'⟯} {x : M} {y : M'} (h : f x = y) (v : PointDerivation I x) (g : C^∞⟮I', M'; 𝕜⟯) : 𝒅ₕ h v g = 𝒅 f x v g := rfl variable {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] @[simp] theorem fdifferential_comp (g : C^∞⟮I', M'; I'', M''⟯) (f : C^∞⟮I, M; I', M'⟯) (x : M) : 𝒅 (g.comp f) x = (𝒅 g (f x)).comp (𝒅 f x) := rfl end
.lake/packages/mathlib/Mathlib/Geometry/Manifold/Notation.lean
import Mathlib.Geometry.Manifold.ContMDiff.Defs import Mathlib.Geometry.Manifold.MFDeriv.Defs /-! # Elaborators for differential geometry This file defines custom elaborators for differential geometry to allow for more compact notation. We introduce a class of elaborators for handling differentiability on manifolds, and the elaborator `T%` for converting dependent sections of fibre bundles into non-dependent functions into the total space. All of these elaborators are scoped to the `Manifold` namespace. ## Differentiability on manifolds We provide compact notation for differentiability and continuous differentiability on manifolds, including inference of the model with corners. | Notation | Elaborates to | |--------------------------|-------------------------------------| | `MDiff f` | `MDifferentiable I J f` | | `MDiffAt f x` | `MDifferentiableAt I J f x` | | `MDiff[u] f` | `MDifferentiableOn I J f u` | | `MDiffAt[u] f x` | `MDifferentiableWithinAt I J f u x` | | `CMDiff n f` | `ContMDiff I J n f` | | `CMDiffAt n f x` | `ContMDiffAt I J n f x` | | `CMDiff[u] n f` | `ContMDiffOn I J n f u` | | `CMDiffAt[u] n f x` | `ContMDiffWithinAt I J n f u x` | | `mfderiv[u] f x` | `mfderivWithin I J f u x` | | `mfderiv% f x` | `mfderiv I J f x` | | `HasMFDerivAt[s] f x f'` | `HasMFDerivWithinAt I J f s x f'` | | `HasMFDerivAt% f x f'` | `HasMFDerivAt I J f x f'` | In each of these cases, the models with corners are inferred from the domain and codomain of `f`. The search for models with corners uses the local context and is (almost) only based on expression structure, hence hopefully fast enough to always run. This has no dedicated support for product manifolds (or product vector spaces) yet; adding this is left for future changes. (It would need to make a choice between e.g. the trivial model with corners on a product `E × F` and the product of the trivial models on `E` and `F`). In these settings, the elaborators should be avoided (for now). ## `T%` Secondly, this file adds an elaborator `T%` to ease working with sections in a fibre bundle, which converts a section `s : Π x : M, V x` to a non-dependent function into the total space of the bundle. ```lean -- omitted: let `V` be a fibre bundle over `M` variable {σ : Π x : M, V x} in #check T% σ -- `(fun x ↦ TotalSpace.mk' F x (σ x)) : M → TotalSpace F V` -- Note how the name of the bound variable `x` is preserved. variable {σ : (x : E) → Trivial E E' x} in #check T% σ -- `(fun x ↦ TotalSpace.mk' E' x (σ x)) : E → TotalSpace E' (Trivial E E')` variable {s : E → E'} in #check T% s -- `(fun a ↦ TotalSpace.mk' E' a (s a)) : E → TotalSpace E' (Trivial E E')` ``` --- These elaborators can be combined: `CMDiffAt[u] n (T% s) x` **Warning.** These elaborators are a proof of concept; the implementation should be considered a prototype. Don't rewrite all of mathlib to use it just yet. Notable limitations include the following. ## TODO - extend the elaborators to guess models with corners on product manifolds (this has to make a guess, hence cannot always be correct: but it could make the guess that is correct 90% of the time). For products of vector spaces `E × F`, this could print a warning about making a choice between the model in `E × F` and the product of the models on `E` and `F`. - better error messages (as needed), with tests - further testing and fixing of edge cases (with tests) - add delaborators for these elaborators -/ open scoped Bundle Manifold ContDiff open Lean Meta Elab Tactic open Mathlib.Tactic open Qq namespace Manifold.Elab /- Note: these functions are convenient in this file, and may be convenient elsewhere, but their precise behavior should be considered before adding them to the meta API. -/ /-- Finds the first local instance of class `c` for which `p inst type` produces `some a`. Instantiates mvars in and runs `whnfR` on `type` before passing it to `p`. (Does not validate that `c` resolves to a class.) -/ private def findSomeLocalInstanceOf? (c : Name) {α} (p : Expr → Expr → MetaM (Option α)) : MetaM (Option α) := do (← getLocalInstances).findSomeM? fun inst ↦ do if inst.className == c then let type ← whnfR <| ← instantiateMVars <| ← inferType inst.fvar p inst.fvar type else return none /-- Finds the most recent local declaration for which `p fvar type` produces `some a`. Skips implementation details; instantiates mvars in and runs `whnfR` on `type` before providing it to `p`. -/ private def findSomeLocalHyp? {α} (p : Expr → Expr → MetaM (Option α)) : MetaM (Option α) := do (← getLCtx).findDeclRevM? fun decl ↦ do if decl.isImplementationDetail then return none let type ← whnfR <| ← instantiateMVars decl.type p decl.toExpr type end Elab open Elab in /-- Elaborator for sections in a fibre bundle: converts a section `s : Π x : M, V x` as a dependent function to a non-dependent function into the total space. This handles the cases of - sections of a trivial bundle - vector fields on a manifold (i.e., sections of the tangent bundle) - sections of an explicit fibre bundle - turning a bare function `E → E'` into a section of the trivial bundle `Bundle.Trivial E E'` This elaborator searches the local context for suitable hypotheses for the above cases by matching on the expression structure, avoiding `isDefEq`. Therefore, it is (hopefully) fast enough to always run. -/ -- TODO: document how this elaborator works, any gotchas, etc. -- TODO: factor out `MetaM` component for reuse scoped elab:max "T% " t:term:arg : term => do let e ← Term.elabTerm t none let etype ← whnf <| ← instantiateMVars <| ← inferType e match etype with | .forallE x base tgt _ => withLocalDeclD x base fun x ↦ do let tgtHasLooseBVars := tgt.hasLooseBVars let tgt := tgt.instantiate1 x -- Note: we do not run `whnfR` on `tgt` because `Bundle.Trivial` is reducible. match_expr tgt with | Bundle.Trivial E E' _ => trace[Elab.DiffGeo.TotalSpaceMk] "`{e}` is a section of `Bundle.Trivial {E} {E'}`" -- Note: we allow `isDefEq` here because any mvar assignments should persist. if ← withReducible (isDefEq E base) then let body ← mkAppM ``Bundle.TotalSpace.mk' #[E', x, e.app x] mkLambdaFVars #[x] body else return e | TangentSpace _k _ E _ _ _H _ _I M _ _ _x => trace[Elab.DiffGeo.TotalSpaceMk] "`{e}` is a vector field on `{M}`" let body ← mkAppM ``Bundle.TotalSpace.mk' #[E, x, e.app x] mkLambdaFVars #[x] body | _ => match (← instantiateMVars tgt).cleanupAnnotations with | .app V _ => trace[Elab.DiffGeo.TotalSpaceMk] "Section of a bundle as a dependent function" let f? ← findSomeLocalInstanceOf? `FiberBundle fun _ declType ↦ /- Note: we do not use `match_expr` here since that would require importing `Mathlib.Topology.FiberBundle.Basic` to resolve `FiberBundle`. -/ match declType with | mkApp7 (.const `FiberBundle _) _ F _ _ E _ _ => do if ← withReducible (pureIsDefEq E V) then let body ← mkAppM ``Bundle.TotalSpace.mk' #[F, x, e.app x] some <$> mkLambdaFVars #[x] body else return none | _ => return none return f?.getD e | tgt => trace[Elab.DiffGeo.TotalSpaceMk] "Section of a trivial bundle as a non-dependent function" -- TODO: can `tgt` depend on `x` in a way that is not a function application? -- Check that `x` is not a bound variable in `tgt`! if tgtHasLooseBVars then throwError "Attempted to fall back to creating a section of the trivial bundle out of \ (`{e}` : `{etype}`) as a non-dependent function, but return type `{tgt}` depends on the bound variable (`{x}` : `{base}`).\n\ Hint: applying the `T%` elaborator twice makes no sense." let trivBundle ← mkAppOptM ``Bundle.Trivial #[base, tgt] let body ← mkAppOptM ``Bundle.TotalSpace.mk' #[base, trivBundle, tgt, x, e.app x] mkLambdaFVars #[x] body | _ => return e namespace Elab /-- Try a strategy `x : TermElabM` which either successfully produces some `Expr` or fails. On failure in `x`, exceptions are caught, traced (`trace.Elab.DiffGeo.MDiff`), and `none` is successfully returned. We run `x` with `errToSorry == false` to convert elaboration errors into exceptions, and under `withSynthesize` in order to force typeclass synthesis errors to appear and be caught. Trace messages produced during the execution of `x` are wrapped in a collapsible trace node titled with `strategyDescr` and an indicator of success. -/ private def tryStrategy (strategyDescr : MessageData) (x : TermElabM Expr) : TermElabM (Option Expr) := do let s ← saveState try withTraceNode `Elab.DiffGeo.MDiff (fun e => pure m!"{e.emoji} {strategyDescr}") do let e ← try Term.withoutErrToSorry <| Term.withSynthesize x /- Catch the exception so that we can trace it, then throw it again to inform `withTraceNode` of the result. -/ catch ex => trace[Elab.DiffGeo.MDiff] "Failed with error:\n{ex.toMessageData}" throw ex trace[Elab.DiffGeo.MDiff] "Found model: `{e}`" return e catch _ => -- Restore infotrees to prevent any stale hovers, code actions, etc. -- Note that this does not break tracing, which saves each trace message's context. s.restore true return none /-- Try to find a `ModelWithCorners` instance on a type (represented by an expression `e`), using the local context to infer the appropriate instance. This supports the following cases: - the model with corners on the total space of a vector bundle - the model with corners on the tangent space of a manifold - a model with corners on a manifold, or on its underlying model space - a closed interval of real numbers - the complex upper half plane - a space of continuous k-linear maps - the trivial model `𝓘(𝕜, E)` on a normed space - if the above are not found, try to find a `NontriviallyNormedField` instance on the type of `e`, and if successful, return `𝓘(𝕜)`. Further cases can be added as necessary. Return an expression describing the found model with corners. `baseInfo` is only used for the first case, a model with corners on the total space of the vector bundle. In this case, it contains a pair of expressions `(e, i)` describing the type of the base and the model with corners on the base: these are required to construct the right model with corners. Note that the matching on `e` does not see through reducibility (e.g. we distinguish the `abbrev` `TangentBundle` from its definition), so `whnfR` should not be run on `e` prior to calling `findModel` on it. This implementation is not maximally robust yet. -/ -- TODO: better error messages when all strategies fail -- TODO: consider lowering monad to `MetaM` def findModel (e : Expr) (baseInfo : Option (Expr × Expr) := none) : TermElabM Expr := do trace[Elab.DiffGeo.MDiff] "Finding a model for: {e}" if let some m ← tryStrategy m!"TotalSpace" fromTotalSpace then return m if let some m ← tryStrategy m!"TangentBundle" fromTangentBundle then return m if let some m ← tryStrategy m!"NormedSpace" fromNormedSpace then return m if let some m ← tryStrategy m!"Manifold" fromManifold then return m if let some m ← tryStrategy m!"ContinuousLinearMap" fromCLM then return m if let some m ← tryStrategy m!"RealInterval" fromRealInterval then return m if let some m ← tryStrategy m!"UpperHalfPlane" fromUpperHalfPlane then return m if let some m ← tryStrategy m!"NormedField" fromNormedField then return m throwError "Could not find a model with corners for `{e}`" where /- Note that errors thrown in the following are caught by `tryStrategy` and converted to trace messages. -/ /-- Attempt to find a model from a `TotalSpace` first by attempting to use any provided `baseInfo`, then by seeing if it is the total space of a tangent bundle. -/ fromTotalSpace : TermElabM Expr := do match_expr e with | Bundle.TotalSpace _ F V => do if let some m ← tryStrategy m!"From base info" (fromTotalSpace.fromBaseInfo F) then return m if let some m ← tryStrategy m!"TangentSpace" (fromTotalSpace.tangentSpace V) then return m throwError "Having a TotalSpace as source is not yet supported" | _ => throwError "`{e}` is not a `Bundle.TotalSpace`." /-- Attempt to use the provided `baseInfo` to find a model. -/ fromTotalSpace.fromBaseInfo (F : Expr) : TermElabM Expr := do if let some (src, srcI) := baseInfo then trace[Elab.DiffGeo.MDiff] "Using base info `{src}`, `{srcI}`" let some K ← findSomeLocalInstanceOf? ``NormedSpace fun _ type ↦ do match_expr type with | NormedSpace K E _ _ => if ← withReducible (pureIsDefEq E F) then trace[Elab.DiffGeo.MDiff] "`{F}` is a normed field over `{K}`"; return some K else return none | _ => return none | throwError "Couldn't find a `NormedSpace` structure on `{F}` among local instances." let kT : Term ← Term.exprToSyntax K let srcIT : Term ← Term.exprToSyntax srcI let FT : Term ← Term.exprToSyntax F let iTerm : Term ← ``(ModelWithCorners.prod $srcIT 𝓘($kT, $FT)) Term.elabTerm iTerm none else throwError "No `baseInfo` provided" /-- Attempt to find a model from the total space of a tangent bundle. -/ fromTotalSpace.tangentSpace (V : Expr) : TermElabM Expr := do match_expr V with | TangentSpace _k _ _E _ _ _H _ I M _ _ => do trace[Elab.DiffGeo.MDiff] "`{V}` is the total space of the `TangentBundle` of `{M}`" let srcIT : Term ← Term.exprToSyntax I let resTerm : Term ← ``(ModelWithCorners.prod $srcIT (ModelWithCorners.tangent $srcIT)) Term.elabTerm resTerm none | _ => throwError "`{V}` is not a `TangentSpace`" /-- Attempt to find a model on a `TangentBundle` -/ fromTangentBundle : TermElabM Expr := do match_expr e with | TangentBundle _k _ _E _ _ _H _ I M _ _ => do trace[Elab.DiffGeo.MDiff] "`{e}` is a `TangentBundle` over model `{I}` on `{M}`" let srcIT : Term ← Term.exprToSyntax I let resTerm : Term ← ``(ModelWithCorners.tangent $srcIT) Term.elabTerm resTerm none | _ => throwError "`{e}` is not a `TangentBundle`" /-- Attempt to find the trivial model on a normed space. -/ fromNormedSpace : TermElabM Expr := do let some (inst, K) ← findSomeLocalInstanceOf? ``NormedSpace fun inst type ↦ do match_expr type with | NormedSpace K E _ _ => if ← withReducible (pureIsDefEq E e) then return some (inst, K) else return none | _ => return none | throwError "Couldn't find a `NormedSpace` structure on `{e}` among local instances." trace[Elab.DiffGeo.MDiff] "`{e}` is a normed space over the field `{K}`" mkAppOptM ``modelWithCornersSelf #[K, none, e, none, inst] /-- Attempt to find a model with corners on a manifold, or on the charted space of a manifold. -/ fromManifold : TermElabM Expr := do -- Return an expression for a type `H` (if any) such that `e` is a ChartedSpace over `H`, -- or `e` is `H` itself. let some H ← findSomeLocalInstanceOf? ``ChartedSpace fun inst type ↦ do trace[Elab.DiffGeo.MDiff] "considering instance of type `{type}`" match_expr type with | ChartedSpace H _ M _ => if ← withReducible (pureIsDefEq M e) then trace[Elab.DiffGeo.MDiff] "`{e}` is a charted space over `{H}` via `{inst}`" return some H else if ← withReducible (pureIsDefEq H e) then trace[Elab.DiffGeo.MDiff] "`{e}` is the charted space of `{M}` via `{inst}`" return some H else return none | _ => return none | throwError "Couldn't find a `ChartedSpace` structure on `{e}` among local instances, \ and `{e}` is not the charted space of some type in the local context either." let some m ← findSomeLocalHyp? fun fvar type ↦ do match_expr type with | ModelWithCorners _ _ _ _ _ H' _ => do if ← withReducible (pureIsDefEq H' H) then return some fvar else return none | _ => return none | throwError "Couldn't find a `ModelWithCorners` with model space `{H}` in the local context." return m /-- Attempt to find a model with corners on a space of continuous linear maps -/ -- Note that (continuous) linear equivalences are not an abelian group, so are not a model with -- corners as a normed space. Merely linear maps are not a normed space either. fromCLM : TermElabM Expr := do match_expr e with | ContinuousLinearMap k S _ _ _σ _E _ _ _F _ _ _ _ => trace[Elab.DiffGeo.MDiff] "`{e}` is a space of continuous linear maps" -- If `S` were a copy of `k` with a non-standard topology or smooth structure -- (such as, imposed deliberately through a type synonym), we do not want to infer -- the standard model with corners. -- Therefore, we only check definitional equality at reducible transparency. if ← withReducible <| isDefEq k S then -- TODO: check if σ is actually the identity! let eK : Term ← Term.exprToSyntax k let eT : Term ← Term.exprToSyntax e let iTerm : Term ← ``(𝓘($eK, $eT)) Term.elabTerm iTerm none else throwError "Coefficients `{k}` and `{S}` of `{e}` are not reducibly definitionally equal" | _ => throwError "`{e}` is not a space of continuous linear maps" /-- Attempt to find a model with corners on a closed interval of real numbers -/ fromRealInterval : TermElabM Expr := do let some e := (← instantiateMVars e).cleanupAnnotations.coeTypeSet? | throwError "`{e}` is not a coercion of a set to a type" -- We don't use `match_expr` here to avoid importing `Set.Icc`. -- Note that `modelWithCornersEuclideanHalfSpace` is also not imported. match e with | mkApp4 (.const `Set.Icc _) α _ _x _y => -- If `S` were a copy of `k` with a non-standard topology or smooth structure -- (such as, imposed deliberately through a type synonym), we do not want to infer -- the standard model with corners. -- Therefore, we only check definitional equality at reducible transparency. if ← withReducible <| isDefEq α q(ℝ) then -- We need not check if `x < y` is a fact in the local context: Lean will verify this -- itself when trying to synthesize a ChartedSpace instance. mkAppOptM `modelWithCornersEuclideanHalfSpace #[q(1 : ℕ), none] else throwError "`{e}` is a closed interval of type `{α}`, \ which is not reducibly definitionally equal to ℝ" | _ => throwError "`{e}` is not a closed real interval" /-- Attempt to find a model with corners on the upper half plane in complex space -/ fromUpperHalfPlane : TermElabM Expr := do -- We don't use `match_expr` to avoid importing `UpperHalfPlane`. if (← instantiateMVars e).cleanupAnnotations.isConstOf `UpperHalfPlane then let c ← Term.exprToSyntax (mkConst `Complex) Term.elabTerm (← `(𝓘($c))) none else throwError "`{e}` is not the complex upper half plane" /-- Attempt to find a model with corners from a normed field. We attempt to find a global instance here. -/ fromNormedField : TermElabM Expr := do let eT : Term ← Term.exprToSyntax e let iTerm : Term ← ``(𝓘($eT, $eT)) Term.elabTerm iTerm none /-- If the type of `e` is a non-dependent function between spaces `src` and `tgt`, try to find a model with corners on both `src` and `tgt`. If successful, return both models. We pass `e` instead of just its type for better diagnostics. If `es` is `some`, we verify that `src` and the type of `es` are definitionally equal. -/ def findModels (e : Expr) (es : Option Expr) : TermElabM (Expr × Expr) := do let etype ← whnf <| ← instantiateMVars <| ← inferType e match etype with | .forallE _ src tgt _ => if tgt.hasLooseBVars then -- TODO: try `T%` here, and if it works, add an interactive suggestion to use it throwError "Term `{e}` is a dependent function, of type `{etype}`\nHint: you can use \ the `T%` elaborator to convert a dependent function to a non-dependent one" let srcI ← findModel src if let some es := es then let estype ← inferType es /- Note: we use `isDefEq` here since persistent metavariable assignments in `src` and `estype` are acceptable. TODO: consider attempting to coerce `es` to a `Set`. -/ if !(← isDefEq estype <| ← mkAppM ``Set #[src]) then throwError "The domain `{src}` of `{e}` is not definitionally equal to the carrier type of \ the set `{es}` : `{estype}`" let tgtI ← findModel tgt (src, srcI) return (srcI, tgtI) | _ => throwError "Expected{indentD e}\nof type{indentD etype}\nto be a function" end Elab open Elab /-- `MDiffAt[s] f x` elaborates to `MDifferentiableWithinAt I J f s x`, trying to determine `I` and `J` from the local context. The argument `x` can be omitted. -/ scoped elab:max "MDiffAt[" s:term "]" ppSpace f:term:arg : term => do let es ← Term.elabTerm s none let ef ← ensureIsFunction <| ← Term.elabTerm f none let (srcI, tgtI) ← findModels ef es mkAppM ``MDifferentiableWithinAt #[srcI, tgtI, ef, es] /-- `MDiffAt f x` elaborates to `MDifferentiableAt I J f x`, trying to determine `I` and `J` from the local context. The argument `x` can be omitted. -/ scoped elab:max "MDiffAt" ppSpace t:term:arg : term => do let e ← ensureIsFunction <| ← Term.elabTerm t none let (srcI, tgtI) ← findModels e none mkAppM ``MDifferentiableAt #[srcI, tgtI, e] -- An alternate implementation for `MDiffAt`. -- /-- `MDiffAt2 f x` elaborates to `MDifferentiableAt I J f x`, -- trying to determine `I` and `J` from the local context. -- The argument `x` can be omitted. -/ -- scoped elab:max "MDiffAt2" ppSpace t:term:arg : term => do -- let e ← Term.elabTerm t none -- let etype ← whnfR <| ← instantiateMVars <| ← inferType e -- forallBoundedTelescope etype (some 1) fun src tgt ↦ do -- if let some src := src[0]? then -- let srcI ← findModel (← inferType src) -- if Lean.Expr.occurs src tgt then -- throwErrorAt t "Term `{e}` is a dependent function, of type `{etype}`\n\ -- Hint: you can use the `T%` elaborator to convert a dependent function \ -- to a non-dependent one" -- let tgtI ← findModel tgt (src, srcI) -- mkAppM ``MDifferentiableAt #[srcI, tgtI, e] -- else -- throwErrorAt t "Expected{indentD e}\nof type{indentD etype}\nto be a function" /-- `MDiff[s] f` elaborates to `MDifferentiableOn I J f s`, trying to determine `I` and `J` from the local context. -/ scoped elab:max "MDiff[" s:term "]" ppSpace t:term:arg : term => do let es ← Term.elabTerm s none let et ← ensureIsFunction <| ← Term.elabTerm t none let (srcI, tgtI) ← findModels et es mkAppM ``MDifferentiableOn #[srcI, tgtI, et, es] /-- `MDiff f` elaborates to `MDifferentiable I J f`, trying to determine `I` and `J` from the local context. -/ scoped elab:max "MDiff" ppSpace t:term:arg : term => do let e ← ensureIsFunction <| ← Term.elabTerm t none let (srcI, tgtI) ← findModels e none mkAppM ``MDifferentiable #[srcI, tgtI, e] -- We ensure the type of `n` before checking `f` is a function to provide better error messages -- in case e.g. `f` and `n` are swapped. -- TODO: provide better error messages if just `n` is forgotten (say, by making `n` optional in -- the parser and erroring later in the elaborator); currently, this yields just a parser error. /-- `CMDiffAt[s] n f x` elaborates to `ContMDiffWithinAt I J n f s x`, trying to determine `I` and `J` from the local context. `n` is coerced to `WithTop ℕ∞` if necessary (so passing a `ℕ`, `∞` or `ω` are all supported). The argument `x` can be omitted. -/ scoped elab:max "CMDiffAt[" s:term "]" ppSpace nt:term:arg ppSpace f:term:arg : term => do let es ← Term.elabTerm s none let ne ← Term.elabTermEnsuringType nt q(WithTop ℕ∞) let ef ← ensureIsFunction <| ← Term.elabTerm f none let (srcI, tgtI) ← findModels ef es mkAppM ``ContMDiffWithinAt #[srcI, tgtI, ne, ef, es] /-- `CMDiffAt n f x` elaborates to `ContMDiffAt I J n f x` trying to determine `I` and `J` from the local context. `n` is coerced to `WithTop ℕ∞` if necessary (so passing a `ℕ`, `∞` or `ω` are all supported). The argument `x` can be omitted. -/ scoped elab:max "CMDiffAt" ppSpace nt:term:arg ppSpace t:term:arg : term => do let e ← ensureIsFunction <| ← Term.elabTerm t none let ne ← Term.elabTermEnsuringType nt q(WithTop ℕ∞) let (srcI, tgtI) ← findModels e none mkAppM ``ContMDiffAt #[srcI, tgtI, ne, e] /-- `CMDiff[s] n f` elaborates to `ContMDiffOn I J n f s`, trying to determine `I` and `J` from the local context. `n` is coerced to `WithTop ℕ∞` if necessary (so passing a `ℕ`, `∞` or `ω` are all supported). -/ scoped elab:max "CMDiff[" s:term "]" ppSpace nt:term:arg ppSpace f:term:arg : term => do let es ← Term.elabTerm s none let ne ← Term.elabTermEnsuringType nt q(WithTop ℕ∞) let ef ← ensureIsFunction <| ← Term.elabTerm f none let (srcI, tgtI) ← findModels ef es mkAppM ``ContMDiffOn #[srcI, tgtI, ne, ef, es] /-- `CMDiff n f` elaborates to `ContMDiff I J n f`, trying to determine `I` and `J` from the local context. `n` is coerced to `WithTop ℕ∞` if necessary (so passing a `ℕ`, `∞` or `ω` are all supported). -/ scoped elab:max "CMDiff" ppSpace nt:term:arg ppSpace f:term:arg : term => do let ne ← Term.elabTermEnsuringType nt q(WithTop ℕ∞) let e ← ensureIsFunction <| ← Term.elabTerm f none let (srcI, tgtI) ← findModels e none mkAppM ``ContMDiff #[srcI, tgtI, ne, e] /-- `mfderiv[u] f x` elaborates to `mfderivWithin I J f u x`, trying to determine `I` and `J` from the local context. -/ scoped elab:max "mfderiv[" s:term "]" ppSpace t:term:arg : term => do let es ← Term.elabTerm s none let e ← ensureIsFunction <| ← Term.elabTerm t none let (srcI, tgtI) ← findModels e es mkAppM ``mfderivWithin #[srcI, tgtI, e, es] /-- `mfderiv% f x` elaborates to `mfderiv I J f x`, trying to determine `I` and `J` from the local context. -/ scoped elab:max "mfderiv%" ppSpace t:term:arg : term => do let e ← ensureIsFunction <| ← Term.elabTerm t none let (srcI, tgtI) ← findModels e none mkAppM ``mfderiv #[srcI, tgtI, e] /-- `HasMFDerivAt[s] f x f'` elaborates to `HasMFDerivWithinAt I J f s x f'`, trying to determine `I` and `J` from the local context. -/ scoped elab:max "HasMFDerivAt[" s:term "]" ppSpace f:term:arg ppSpace x:term:arg ppSpace f':term:arg : term => do let es ← Term.elabTerm s none let ef ← ensureIsFunction <|← Term.elabTerm f none let ex ← Term.elabTerm x none let ef' ← Term.elabTerm f' none let (srcI, tgtI) ← findModels ef es mkAppM ``HasMFDerivWithinAt #[srcI, tgtI, ef, es, ex, ef'] /-- `HasMFDerivAt% f x f'` elaborates to `HasMFDerivAt I J f x f'`, trying to determine `I` and `J` from the local context. -/ scoped elab:max "HasMFDerivAt%" ppSpace f:term:arg ppSpace x:term:arg ppSpace f':term:arg : term => do let ef ← ensureIsFunction <|← Term.elabTerm f none let ex ← Term.elabTerm x none let ef' ← Term.elabTerm f' none let (srcI, tgtI) ← findModels ef none mkAppM ``HasMFDerivAt #[srcI, tgtI, ef, ex, ef'] end Manifold section trace /-! ### Trace classes Note that the overall `Elab` trace class does not inherit the trace classes defined in this section, since they provide verbose information. -/ /-- Trace class for differential geometry elaborators. Setting this to `true` traces elaboration for the `T%` elaborator (`trace.Elab.DiffGeo.TotalSpaceMk`) and the family of `MDiff`-like elaborators (`trace.Elab.DiffGeo.MDiff`). -/ initialize registerTraceClass `Elab.DiffGeo /-- Trace class for the `T%` elaborator, which converts a section of a vector bundle as a dependent function to a non-dependent function into the total space. -/ initialize registerTraceClass `Elab.DiffGeo.TotalSpaceMk (inherited := true) /-- Trace class for the `MDiff` elaborator and friends, which infer a model with corners on the domain (resp. codomain) of the map in question. -/ initialize registerTraceClass `Elab.DiffGeo.MDiff (inherited := true) end trace
.lake/packages/mathlib/Mathlib/Geometry/Manifold/Diffeomorph.lean
import Mathlib.Geometry.Manifold.ContMDiffMap import Mathlib.Geometry.Manifold.MFDeriv.UniqueDifferential /-! # Diffeomorphisms This file implements diffeomorphisms. ## Definitions * `Diffeomorph I I' M M' n`: `n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I'; we do not introduce a separate definition for the case `n = ∞` or `n = ω`; we use notation instead. * `Diffeomorph.toHomeomorph`: reinterpret a diffeomorphism as a homeomorphism. * `ContinuousLinearEquiv.toDiffeomorph`: reinterpret a continuous equivalence as a diffeomorphism. * `ModelWithCorners.transContinuousLinearEquiv`: compose a given `ModelWithCorners` with a continuous linear equiv between the old and the new target spaces. Useful, e.g, to turn any finite-dimensional manifold into a manifold modelled on a Euclidean space. * `Diffeomorph.toTransContinuousLinearEquiv`: the identity diffeomorphism between `M` with model `I` and `M` with model `I.transContinuousLinearEquiv e`. This file also provides diffeomorphisms related to products and disjoint unions. * `Diffeomorph.prodCongr`: the product of two diffeomorphisms * `Diffeomorph.prodComm`: `M × N` is diffeomorphic to `N × M` * `Diffeomorph.prodAssoc`: `(M × N) × N'` is diffeomorphic to `M × (N × N')` * `Diffeomorph.sumCongr`: the disjoint union of two diffeomorphisms * `Diffeomorph.sumComm`: `M ⊕ M'` is diffeomorphic to `M' × M` * `Diffeomorph.sumAssoc`: `(M ⊕ N) ⊕ P` is diffeomorphic to `M ⊕ (N ⊕ P)` * `Diffeomorph.sumEmpty`: `M ⊕ ∅` is diffeomorphic to `M` ## Notation * `M ≃ₘ^n⟮I, I'⟯ M'` := `Diffeomorph I J M N n` * `M ≃ₘ⟮I, I'⟯ M'` := `Diffeomorph I J M N ∞` * `E ≃ₘ^n[𝕜] E'` := `E ≃ₘ^n⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'` * `E ≃ₘ[𝕜] E'` := `E ≃ₘ⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'` ## Implementation notes This notion of diffeomorphism is needed although there is already a notion of structomorphism because structomorphisms do not allow the model spaces `H` and `H'` of the two manifolds to be different, i.e. for a structomorphism one has to impose `H = H'` which is often not the case in practice. ## Keywords diffeomorphism, manifold -/ open scoped Manifold Topology ContDiff open Function Set variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {H : Type*} [TopologicalSpace H] {H' : Type*} [TopologicalSpace H'] {G : Type*} [TopologicalSpace G] {G' : Type*} [TopologicalSpace G'] {I : ModelWithCorners 𝕜 E H} {I' : ModelWithCorners 𝕜 E' H'} {J : ModelWithCorners 𝕜 F G} {J' : ModelWithCorners 𝕜 F G'} variable {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {N : Type*} [TopologicalSpace N] [ChartedSpace G N] {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] {n : WithTop ℕ∞} section Defs variable (I I' M M' n) /-- `n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to `I` and `I'`, denoted as `M ≃ₘ^n⟮I, I'⟯ M'` (in the `Manifold` namespace). -/ structure Diffeomorph extends M ≃ M' where protected contMDiff_toFun : ContMDiff I I' n toEquiv protected contMDiff_invFun : ContMDiff I' I n toEquiv.symm end Defs @[inherit_doc] scoped[Manifold] notation M " ≃ₘ^" n:1000 "⟮" I ", " J "⟯ " N => Diffeomorph I J M N n /-- Infinitely differentiable diffeomorphism between `M` and `M'` with respect to `I` and `I'`. -/ scoped[Manifold] notation M " ≃ₘ⟮" I ", " J "⟯ " N => Diffeomorph I J M N ∞ -- Porting note: this notation is broken because `n[𝕜]` gets parsed as `getElem` /-- `n`-times continuously differentiable diffeomorphism between `E` and `E'`. -/ scoped[Manifold] notation E " ≃ₘ^" n:1000 "[" 𝕜 "] " E' => Diffeomorph 𝓘(𝕜, E) 𝓘(𝕜, E') E E' n /-- Infinitely differentiable diffeomorphism between `E` and `E'`. -/ scoped[Manifold] notation3 E " ≃ₘ[" 𝕜 "] " E' => Diffeomorph 𝓘(𝕜, E) 𝓘(𝕜, E') E E' ∞ namespace Diffeomorph theorem toEquiv_injective : Injective (Diffeomorph.toEquiv : (M ≃ₘ^n⟮I, I'⟯ M') → M ≃ M') | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl instance : EquivLike (M ≃ₘ^n⟮I, I'⟯ M') M M' where coe Φ := Φ.toEquiv inv Φ := Φ.toEquiv.symm left_inv Φ := Φ.left_inv right_inv Φ := Φ.right_inv coe_injective' _ _ h _ := toEquiv_injective <| DFunLike.ext' h /-- Interpret a diffeomorphism as a `ContMDiffMap`. -/ @[coe] def toContMDiffMap (Φ : M ≃ₘ^n⟮I, I'⟯ M') : C^n⟮I, M; I', M'⟯ := ⟨Φ, Φ.contMDiff_toFun⟩ instance : Coe (M ≃ₘ^n⟮I, I'⟯ M') C^n⟮I, M; I', M'⟯ := ⟨toContMDiffMap⟩ @[continuity] protected theorem continuous (h : M ≃ₘ^n⟮I, I'⟯ M') : Continuous h := h.contMDiff_toFun.continuous protected theorem contMDiff (h : M ≃ₘ^n⟮I, I'⟯ M') : ContMDiff I I' n h := h.contMDiff_toFun protected theorem contMDiffAt (h : M ≃ₘ^n⟮I, I'⟯ M') {x} : ContMDiffAt I I' n h x := h.contMDiff.contMDiffAt protected theorem contMDiffWithinAt (h : M ≃ₘ^n⟮I, I'⟯ M') {s x} : ContMDiffWithinAt I I' n h s x := h.contMDiffAt.contMDiffWithinAt protected theorem contDiff (h : E ≃ₘ^n⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E') : ContDiff 𝕜 n h := h.contMDiff.contDiff protected theorem mdifferentiable (h : M ≃ₘ^n⟮I, I'⟯ M') (hn : 1 ≤ n) : MDifferentiable I I' h := h.contMDiff.mdifferentiable hn protected theorem mdifferentiableOn (h : M ≃ₘ^n⟮I, I'⟯ M') (s : Set M) (hn : 1 ≤ n) : MDifferentiableOn I I' h s := (h.mdifferentiable hn).mdifferentiableOn @[simp] theorem coe_toEquiv (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑h.toEquiv = h := rfl @[simp, norm_cast] theorem coe_coe (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑(h : C^n⟮I, M; I', M'⟯) = h := rfl @[simp] theorem toEquiv_inj {h h' : M ≃ₘ^n⟮I, I'⟯ M'} : h.toEquiv = h'.toEquiv ↔ h = h' := toEquiv_injective.eq_iff /-- Coercion to function `fun h : M ≃ₘ^n⟮I, I'⟯ M' ↦ (h : M → M')` is injective. -/ theorem coeFn_injective : Injective ((↑) : (M ≃ₘ^n⟮I, I'⟯ M') → (M → M')) := DFunLike.coe_injective @[ext] theorem ext {h h' : M ≃ₘ^n⟮I, I'⟯ M'} (Heq : ∀ x, h x = h' x) : h = h' := coeFn_injective <| funext Heq instance : ContinuousMapClass (M ≃ₘ⟮I, J⟯ N) M N where map_continuous f := f.continuous section variable (M I n) /-- Identity map as a diffeomorphism. -/ protected def refl : M ≃ₘ^n⟮I, I⟯ M where contMDiff_toFun := contMDiff_id contMDiff_invFun := contMDiff_id toEquiv := Equiv.refl M @[simp] theorem refl_toEquiv : (Diffeomorph.refl I M n).toEquiv = Equiv.refl _ := rfl @[simp] theorem coe_refl : ⇑(Diffeomorph.refl I M n) = id := rfl end /-- Composition of two diffeomorphisms. -/ @[trans] protected def trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : M ≃ₘ^n⟮I, J⟯ N where contMDiff_toFun := h₂.contMDiff.comp h₁.contMDiff contMDiff_invFun := h₁.contMDiff_invFun.comp h₂.contMDiff_invFun toEquiv := h₁.toEquiv.trans h₂.toEquiv @[simp] theorem trans_refl (h : M ≃ₘ^n⟮I, I'⟯ M') : h.trans (Diffeomorph.refl I' M' n) = h := ext fun _ => rfl @[simp] theorem refl_trans (h : M ≃ₘ^n⟮I, I'⟯ M') : (Diffeomorph.refl I M n).trans h = h := ext fun _ => rfl @[simp] theorem coe_trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : ⇑(h₁.trans h₂) = h₂ ∘ h₁ := rfl /-- Inverse of a diffeomorphism. -/ @[symm] protected def symm (h : M ≃ₘ^n⟮I, J⟯ N) : N ≃ₘ^n⟮J, I⟯ M where contMDiff_toFun := h.contMDiff_invFun contMDiff_invFun := h.contMDiff_toFun toEquiv := h.toEquiv.symm @[simp] theorem apply_symm_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : N) : h (h.symm x) = x := h.toEquiv.apply_symm_apply x @[simp] theorem symm_apply_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : M) : h.symm (h x) = x := h.toEquiv.symm_apply_apply x @[simp] theorem symm_refl : (Diffeomorph.refl I M n).symm = Diffeomorph.refl I M n := ext fun _ => rfl @[simp] theorem self_trans_symm (h : M ≃ₘ^n⟮I, J⟯ N) : h.trans h.symm = Diffeomorph.refl I M n := ext h.symm_apply_apply @[simp] theorem symm_trans_self (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.trans h = Diffeomorph.refl J N n := ext h.apply_symm_apply @[simp] theorem symm_trans' (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : (h₁.trans h₂).symm = h₂.symm.trans h₁.symm := rfl @[simp] theorem symm_toEquiv (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.toEquiv = h.toEquiv.symm := rfl @[simp, mfld_simps] theorem toEquiv_coe_symm (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.toEquiv.symm = h.symm := rfl theorem image_eq_preimage_symm (h : M ≃ₘ^n⟮I, J⟯ N) (s : Set M) : h '' s = h.symm ⁻¹' s := h.toEquiv.image_eq_preimage_symm s theorem symm_image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : Set N) : h.symm '' s = h ⁻¹' s := h.symm.image_eq_preimage_symm s @[simp, mfld_simps] nonrec theorem range_comp {α} (h : M ≃ₘ^n⟮I, J⟯ N) (f : α → M) : range (h ∘ f) = h.symm ⁻¹' range f := by rw [range_comp, image_eq_preimage_symm] @[simp] theorem image_symm_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : Set N) : h '' (h.symm '' s) = s := h.toEquiv.image_symm_image s @[simp] theorem symm_image_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : Set M) : h.symm '' (h '' s) = s := h.toEquiv.symm_image_image s /-- A diffeomorphism is a homeomorphism. -/ def toHomeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : M ≃ₜ N := ⟨h.toEquiv, h.continuous, h.symm.continuous⟩ @[simp] theorem toHomeomorph_toEquiv (h : M ≃ₘ^n⟮I, J⟯ N) : h.toHomeomorph.toEquiv = h.toEquiv := rfl @[simp] theorem symm_toHomeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.toHomeomorph = h.toHomeomorph.symm := rfl @[simp] theorem coe_toHomeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.toHomeomorph = h := rfl @[simp] theorem coe_toHomeomorph_symm (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.toHomeomorph.symm = h.symm := rfl @[simp] theorem contMDiffWithinAt_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {s x} (hm : m ≤ n) : ContMDiffWithinAt I I' m (f ∘ h) s x ↔ ContMDiffWithinAt J I' m f (h.symm ⁻¹' s) (h x) := by constructor · intro Hfh rw [← h.symm_apply_apply x] at Hfh simpa only [Function.comp_def, h.apply_symm_apply] using Hfh.comp (h x) (h.symm.contMDiffWithinAt.of_le hm) (mapsTo_preimage _ _) · rw [← h.image_eq_preimage_symm] exact fun hf => hf.comp x (h.contMDiffWithinAt.of_le hm) (mapsTo_image _ _) @[simp] theorem contMDiffOn_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {s} (hm : m ≤ n) : ContMDiffOn I I' m (f ∘ h) s ↔ ContMDiffOn J I' m f (h.symm ⁻¹' s) := h.toEquiv.forall_congr fun {_} => by simp only [hm, coe_toEquiv, h.symm_apply_apply, contMDiffWithinAt_comp_diffeomorph_iff, mem_preimage] @[simp] theorem contMDiffAt_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {x} (hm : m ≤ n) : ContMDiffAt I I' m (f ∘ h) x ↔ ContMDiffAt J I' m f (h x) := h.contMDiffWithinAt_comp_diffeomorph_iff hm @[simp] theorem contMDiff_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} (hm : m ≤ n) : ContMDiff I I' m (f ∘ h) ↔ ContMDiff J I' m f := h.toEquiv.forall_congr fun _ ↦ h.contMDiffAt_comp_diffeomorph_iff hm @[simp] theorem contMDiffWithinAt_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {s x} : ContMDiffWithinAt I' J m (h ∘ f) s x ↔ ContMDiffWithinAt I' I m f s x := ⟨fun Hhf => by simpa only [Function.comp_def, h.symm_apply_apply] using (h.symm.contMDiffAt.of_le hm).comp_contMDiffWithinAt _ Hhf, fun Hf => (h.contMDiffAt.of_le hm).comp_contMDiffWithinAt _ Hf⟩ @[simp] theorem contMDiffAt_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {x} : ContMDiffAt I' J m (h ∘ f) x ↔ ContMDiffAt I' I m f x := h.contMDiffWithinAt_diffeomorph_comp_iff hm @[simp] theorem contMDiffOn_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {s} : ContMDiffOn I' J m (h ∘ f) s ↔ ContMDiffOn I' I m f s := forall₂_congr fun _ _ => h.contMDiffWithinAt_diffeomorph_comp_iff hm @[simp] theorem contMDiff_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) : ContMDiff I' J m (h ∘ f) ↔ ContMDiff I' I m f := forall_congr' fun _ => h.contMDiffWithinAt_diffeomorph_comp_iff hm theorem toOpenPartialHomeomorph_mdifferentiable (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) : h.toHomeomorph.toOpenPartialHomeomorph.MDifferentiable I J := ⟨h.mdifferentiableOn _ hn, h.symm.mdifferentiableOn _ hn⟩ @[deprecated (since := "2025-08-29")] alias toPartialHomeomorph_mdifferentiable := toOpenPartialHomeomorph_mdifferentiable theorem uniqueMDiffOn_image_aux (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : Set M} (hs : UniqueMDiffOn I s) : UniqueMDiffOn J (h '' s) := by convert hs.uniqueMDiffOn_preimage (h.toOpenPartialHomeomorph_mdifferentiable hn) simp [h.image_eq_preimage_symm] @[simp] theorem uniqueMDiffOn_image (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : Set M} : UniqueMDiffOn J (h '' s) ↔ UniqueMDiffOn I s := ⟨fun hs => h.symm_image_image s ▸ h.symm.uniqueMDiffOn_image_aux hn hs, h.uniqueMDiffOn_image_aux hn⟩ @[simp] theorem uniqueMDiffOn_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : Set N} : UniqueMDiffOn I (h ⁻¹' s) ↔ UniqueMDiffOn J s := h.symm_image_eq_preimage s ▸ h.symm.uniqueMDiffOn_image hn @[simp] theorem uniqueDiffOn_image (h : E ≃ₘ^n⟮𝓘(𝕜, E), 𝓘(𝕜, F)⟯ F) (hn : 1 ≤ n) {s : Set E} : UniqueDiffOn 𝕜 (h '' s) ↔ UniqueDiffOn 𝕜 s := by simp only [← uniqueMDiffOn_iff_uniqueDiffOn, uniqueMDiffOn_image, hn] @[simp] theorem uniqueDiffOn_preimage (h : E ≃ₘ^n⟮𝓘(𝕜, E), 𝓘(𝕜, F)⟯ F) (hn : 1 ≤ n) {s : Set F} : UniqueDiffOn 𝕜 (h ⁻¹' s) ↔ UniqueDiffOn 𝕜 s := h.symm_image_eq_preimage s ▸ h.symm.uniqueDiffOn_image hn end Diffeomorph namespace ContinuousLinearEquiv variable (e : E ≃L[𝕜] E') /-- A continuous linear equivalence between normed spaces is a diffeomorphism. -/ def toDiffeomorph : E ≃ₘ[𝕜] E' where contMDiff_toFun := e.contDiff.contMDiff contMDiff_invFun := e.symm.contDiff.contMDiff toEquiv := e.toLinearEquiv.toEquiv @[simp] theorem coe_toDiffeomorph : ⇑e.toDiffeomorph = e := rfl @[simp] theorem symm_toDiffeomorph : e.symm.toDiffeomorph = e.toDiffeomorph.symm := rfl @[simp] theorem coe_toDiffeomorph_symm : ⇑e.toDiffeomorph.symm = e.symm := rfl end ContinuousLinearEquiv namespace ModelWithCorners variable (I) (e : E ≃L[𝕜] E') /-- Apply a continuous linear equivalence to the model vector space. -/ def transContinuousLinearEquiv : ModelWithCorners 𝕜 E' H where toPartialEquiv := I.toPartialEquiv.trans e.toEquiv.toPartialEquiv source_eq := by simp convex_range' := by split_ifs with h · simp only [PartialEquiv.coe_trans, Equiv.toPartialEquiv_apply, LinearEquiv.coe_toEquiv, ContinuousLinearEquiv.coe_toLinearEquiv, toPartialEquiv_coe] rw [range_comp] letI := h.rclike letI := NormedSpace.restrictScalars ℝ 𝕜 E letI := NormedSpace.restrictScalars ℝ 𝕜 E' let eR : E →L[ℝ] E' := ContinuousLinearMap.restrictScalars ℝ (e : E →L[𝕜] E') change Convex ℝ (⇑eR '' range ↑I) apply I.convex_range.linear_image · simp [range_eq_univ_of_not_isRCLikeNormedField I h, range_comp] nonempty_interior' := by simp only [PartialEquiv.coe_trans, Equiv.toPartialEquiv_apply, LinearEquiv.coe_toEquiv, ContinuousLinearEquiv.coe_toLinearEquiv, toPartialEquiv_coe, range_comp, ContinuousLinearEquiv.image_eq_preimage_symm] apply Nonempty.mono (preimage_interior_subset_interior_preimage e.symm.continuous) rw [← ContinuousLinearEquiv.image_eq_preimage_symm] simpa using I.nonempty_interior continuous_toFun := e.continuous.comp I.continuous continuous_invFun := I.continuous_symm.comp e.symm.continuous @[deprecated (since := "2025-06-12")] alias transDiffeomorph := transContinuousLinearEquiv @[simp, mfld_simps] theorem coe_transContinuousLinearEquiv : ⇑(I.transContinuousLinearEquiv e) = e ∘ I := rfl @[deprecated (since := "2025-06-12")] alias coe_transDiffeomorph := coe_transContinuousLinearEquiv @[simp, mfld_simps] theorem coe_transContinuousLinearEquiv_symm : ⇑(I.transContinuousLinearEquiv e).symm = I.symm ∘ e.symm := rfl @[deprecated (since := "2025-06-12")] alias coe_transDiffeomorph_symm := coe_transContinuousLinearEquiv_symm theorem transContinuousLinearEquiv_range : range (I.transContinuousLinearEquiv e) = e '' range I := range_comp e I @[deprecated (since := "2025-06-12")] alias transDiffeomorph_range := transContinuousLinearEquiv_range theorem coe_extChartAt_transContinuousLinearEquiv (x : M) : ⇑(extChartAt (I.transContinuousLinearEquiv e) x) = e ∘ extChartAt I x := rfl @[deprecated (since := "2025-06-12")] alias coe_extChartAt_transDiffeomorph := coe_extChartAt_transContinuousLinearEquiv theorem coe_extChartAt_transContinuousLinearEquiv_symm (x : M) : ⇑(extChartAt (I.transContinuousLinearEquiv e) x).symm = (extChartAt I x).symm ∘ e.symm := rfl @[deprecated (since := "2025-06-12")] alias coe_extChartAt_transDiffeomorph_symm := coe_extChartAt_transContinuousLinearEquiv_symm theorem extChartAt_transContinuousLinearEquiv_target (x : M) : (extChartAt (I.transContinuousLinearEquiv e) x).target = e.symm ⁻¹' (extChartAt I x).target := by simp only [range_comp, preimage_preimage, ContinuousLinearEquiv.image_eq_preimage_symm, mfld_simps, ← comp_def] @[deprecated (since := "2025-06-12")] alias extChartAt_transDiffeomorph_target := extChartAt_transContinuousLinearEquiv_target end ModelWithCorners namespace ContinuousLinearEquiv variable (e : E ≃L[𝕜] F) instance instIsManifoldtransContinuousLinearEquiv [IsManifold I n M] : IsManifold (I.transContinuousLinearEquiv e) n M := by refine isManifold_of_contDiffOn (I.transContinuousLinearEquiv e) n M fun e₁ e₂ h₁ h₂ => ?_ refine e.contDiff.comp_contDiffOn (((contDiffGroupoid n I).compatible h₁ h₂).1.comp e.symm.contDiff.contDiffOn ?_) simp [preimage_comp, range_comp, mapsTo_iff_subset_preimage, ContinuousLinearEquiv.image_eq_preimage_symm] variable (I M) /-- The identity diffeomorphism between a manifold with model `I` and the same manifold with model `I.trans_diffeomorph e`. -/ def toTransContinuousLinearEquiv (e : E ≃L[𝕜] F) : M ≃ₘ^n⟮I, I.transContinuousLinearEquiv e⟯ M where toEquiv := Equiv.refl M contMDiff_toFun x := by refine contMDiffWithinAt_iff'.2 ⟨continuousWithinAt_id, ?_⟩ refine e.contDiff.contDiffWithinAt.congr_of_mem (fun y hy ↦ ?_) ?_ · simp only [Equiv.coe_refl, id, (· ∘ ·), I.coe_extChartAt_transContinuousLinearEquiv, (extChartAt I x).right_inv hy.1] · exact ⟨(extChartAt I x).map_source (mem_extChartAt_source x), trivial, by simp only [mfld_simps]⟩ contMDiff_invFun x := by refine contMDiffWithinAt_iff'.2 ⟨continuousWithinAt_id, ?_⟩ refine e.symm.contDiff.contDiffWithinAt.congr_of_mem (fun y hy => ?_) ?_ · simp only [mem_inter_iff, I.extChartAt_transContinuousLinearEquiv_target] at hy simp only [Equiv.coe_refl, Equiv.refl_symm, id, (· ∘ ·), I.coe_extChartAt_transContinuousLinearEquiv_symm, (extChartAt I x).right_inv hy.1] exact ⟨(extChartAt _ x).map_source (mem_extChartAt_source x), trivial, by simp only [e.symm_apply_apply, Equiv.refl_symm, Equiv.coe_refl, mfld_simps]⟩ @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.toTransDiffeomorph := toTransContinuousLinearEquiv variable {I M} @[simp] theorem contMDiffWithinAt_transContinuousLinearEquiv_right {f : M' → M} {x s} : ContMDiffWithinAt I' (I.transContinuousLinearEquiv e) n f s x ↔ ContMDiffWithinAt I' I n f s x := (toTransContinuousLinearEquiv I M e).contMDiffWithinAt_diffeomorph_comp_iff le_rfl @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.contMDiffWithinAt_transDiffeomorph_right := contMDiffWithinAt_transContinuousLinearEquiv_right @[simp] theorem contMDiffAt_transContinuousLinearEquiv_right {f : M' → M} {x} : ContMDiffAt I' (I.transContinuousLinearEquiv e) n f x ↔ ContMDiffAt I' I n f x := (toTransContinuousLinearEquiv I M e).contMDiffAt_diffeomorph_comp_iff le_rfl @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.contMDiffAt_transDiffeomorph_right := contMDiffAt_transContinuousLinearEquiv_right @[simp] theorem contMDiffOn_transContinuousLinearEquiv_right {f : M' → M} {s} : ContMDiffOn I' (I.transContinuousLinearEquiv e) n f s ↔ ContMDiffOn I' I n f s := (toTransContinuousLinearEquiv I M e).contMDiffOn_diffeomorph_comp_iff le_rfl @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.contMDiffOn_transDiffeomorph_right := contMDiffOn_transContinuousLinearEquiv_right @[simp] theorem contMDiff_transContinuousLinearEquiv_right {f : M' → M} : ContMDiff I' (I.transContinuousLinearEquiv e) n f ↔ ContMDiff I' I n f := (toTransContinuousLinearEquiv I M e).contMDiff_diffeomorph_comp_iff le_rfl @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.contMDiff_transDiffeomorph_right := contMDiff_transContinuousLinearEquiv_right @[simp] theorem contMDiffWithinAt_transContinuousLinearEquiv_left {f : M → M'} {x s} : ContMDiffWithinAt (I.transContinuousLinearEquiv e) I' n f s x ↔ ContMDiffWithinAt I I' n f s x := ((toTransContinuousLinearEquiv I M e).contMDiffWithinAt_comp_diffeomorph_iff le_rfl).symm @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.contMDiffWithinAt_transDiffeomorph_left := contMDiffWithinAt_transContinuousLinearEquiv_left @[simp] theorem contMDiffAt_transContinuousLinearEquiv_left {f : M → M'} {x} : ContMDiffAt (I.transContinuousLinearEquiv e) I' n f x ↔ ContMDiffAt I I' n f x := ((toTransContinuousLinearEquiv I M e).contMDiffAt_comp_diffeomorph_iff le_rfl).symm @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.contMDiffAt_transDiffeomorph_left := contMDiffAt_transContinuousLinearEquiv_left @[simp] theorem contMDiffOn_transContinuousLinearEquiv_left {f : M → M'} {s} : ContMDiffOn (I.transContinuousLinearEquiv e) I' n f s ↔ ContMDiffOn I I' n f s := ((toTransContinuousLinearEquiv I M e).contMDiffOn_comp_diffeomorph_iff le_rfl).symm @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.contMDiffOn_transDiffeomorph_left := contMDiffOn_transContinuousLinearEquiv_left @[simp] theorem contMDiff_transContinuousLinearEquiv_left {f : M → M'} : ContMDiff (I.transContinuousLinearEquiv e) I' n f ↔ ContMDiff I I' n f := ((toTransContinuousLinearEquiv I M e).contMDiff_comp_diffeomorph_iff le_rfl).symm @[deprecated (since := "2025-06-12")] alias _root_.Diffeomorph.contMDiff_transDiffeomorph_left := contMDiff_transContinuousLinearEquiv_left end ContinuousLinearEquiv namespace Diffeomorph section Constructions section Product /-- Product of two diffeomorphisms. -/ def prodCongr (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : (M × N) ≃ₘ^n⟮I.prod J, I'.prod J'⟯ M' × N' where contMDiff_toFun := (h₁.contMDiff.comp contMDiff_fst).prodMk (h₂.contMDiff.comp contMDiff_snd) contMDiff_invFun := (h₁.symm.contMDiff.comp contMDiff_fst).prodMk (h₂.symm.contMDiff.comp contMDiff_snd) toEquiv := h₁.toEquiv.prodCongr h₂.toEquiv @[simp] theorem prodCongr_symm (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : (h₁.prodCongr h₂).symm = h₁.symm.prodCongr h₂.symm := rfl @[simp] theorem coe_prodCongr (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : ⇑(h₁.prodCongr h₂) = Prod.map h₁ h₂ := rfl section variable (I J J' M N N' n) /-- `M × N` is diffeomorphic to `N × M`. -/ def prodComm : (M × N) ≃ₘ^n⟮I.prod J, J.prod I⟯ N × M where contMDiff_toFun := contMDiff_snd.prodMk contMDiff_fst contMDiff_invFun := contMDiff_snd.prodMk contMDiff_fst toEquiv := Equiv.prodComm M N @[simp] theorem prodComm_symm : (prodComm I J M N n).symm = prodComm J I N M n := rfl @[simp] theorem coe_prodComm : ⇑(prodComm I J M N n) = Prod.swap := rfl /-- `(M × N) × N'` is diffeomorphic to `M × (N × N')`. -/ def prodAssoc : ((M × N) × N') ≃ₘ^n⟮(I.prod J).prod J', I.prod (J.prod J')⟯ M × N × N' where contMDiff_toFun := (contMDiff_fst.comp contMDiff_fst).prodMk ((contMDiff_snd.comp contMDiff_fst).prodMk contMDiff_snd) contMDiff_invFun := (contMDiff_fst.prodMk (contMDiff_fst.comp contMDiff_snd)).prodMk (contMDiff_snd.comp contMDiff_snd) toEquiv := Equiv.prodAssoc M N N' end end Product section disjointUnion variable {M' : Type*} [TopologicalSpace M'] [ChartedSpace H M'] {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H M''] {N J : Type*} [TopologicalSpace N] [ChartedSpace H N] {J : ModelWithCorners 𝕜 E' H} {N' : Type*} [TopologicalSpace N'] [ChartedSpace H N'] /-- The sum of two diffeomorphisms: this is `Sum.map` as a diffeomorphism. -/ def sumCongr (φ : Diffeomorph I J M N n) (ψ : Diffeomorph I J M' N' n) : Diffeomorph I J (M ⊕ M') (N ⊕ N') n where toEquiv := Equiv.sumCongr φ.toEquiv ψ.toEquiv contMDiff_toFun := ContMDiff.sumMap φ.contMDiff_toFun ψ.contMDiff_toFun contMDiff_invFun := ContMDiff.sumMap φ.contMDiff_invFun ψ.contMDiff_invFun lemma sumCongr_symm_symm (φ : Diffeomorph I J M N n) (ψ : Diffeomorph I J M' N' n) : sumCongr φ.symm ψ.symm = (sumCongr φ ψ).symm := rfl @[simp, mfld_simps] lemma sumCongr_coe (φ : Diffeomorph I J M N n) (ψ : Diffeomorph I J M' N' n) : sumCongr φ ψ = Sum.map φ ψ := rfl lemma sumCongr_inl (φ : Diffeomorph I J M N n) (ψ : Diffeomorph I J M' N' n) : (sumCongr φ ψ) ∘ Sum.inl = Sum.inl ∘ φ := rfl lemma sumCongr_inr (φ : Diffeomorph I J M N n) (ψ : Diffeomorph I J M' N' n) : (sumCongr φ ψ) ∘ Sum.inr = Sum.inr ∘ ψ := rfl variable (I M M' n) in /-- The canonical diffeomorphism `M ⊕ M' → M' ⊕ M`: this is `Sum.swap` as a diffeomorphism -/ def sumComm : Diffeomorph I I (M ⊕ M') (M' ⊕ M) n where toEquiv := Equiv.sumComm M M' contMDiff_toFun := ContMDiff.swap contMDiff_invFun := ContMDiff.swap @[simp, mfld_simps] theorem sumComm_coe : (Diffeomorph.sumComm I M n M' : (M ⊕ M') → (M' ⊕ M)) = Sum.swap := rfl @[simp, mfld_simps] theorem sumComm_symm : (Diffeomorph.sumComm I M n M').symm = Diffeomorph.sumComm I M' n M := rfl variable (I M M' n) in lemma sumComm_inl : (Diffeomorph.sumComm I M n M') ∘ Sum.inl = Sum.inr := by ext exact Sum.swap_inl variable (I M M' n) in lemma sumComm_inr : (Diffeomorph.sumComm I M n M') ∘ Sum.inr = Sum.inl := by ext exact Sum.swap_inr variable (I M M' M'' n) in /-- The canonical diffeomorphism `(M ⊕ N) ⊕ P → M ⊕ (N ⊕ P)` -/ def sumAssoc : Diffeomorph I I ((M ⊕ M') ⊕ M'') (M ⊕ (M' ⊕ M'')) n where toEquiv := Equiv.sumAssoc M M' M'' contMDiff_toFun := by apply ContMDiff.sumElim · exact contMDiff_id.sumMap ContMDiff.inl · exact ContMDiff.inr.comp ContMDiff.inr contMDiff_invFun := by apply ContMDiff.sumElim · exact ContMDiff.inl.comp ContMDiff.inl · exact ContMDiff.inr.sumMap contMDiff_id @[simp] theorem sumAssoc_coe : (sumAssoc I M n M' M'' : (M ⊕ M') ⊕ M'' → M ⊕ (M' ⊕ M'')) = Equiv.sumAssoc M M' M'' := rfl variable (I M n) in /-- The canonical diffeomorphism `M ⊕ ∅ → M` -/ def sumEmpty [IsEmpty M'] : Diffeomorph I I (M ⊕ M') M n where toEquiv := Equiv.sumEmpty M M' contMDiff_toFun := contMDiff_id.sumElim fun x ↦ (IsEmpty.false x).elim contMDiff_invFun := ContMDiff.inl @[simp, mfld_simps] theorem sumEmpty_toEquiv [IsEmpty M'] : (sumEmpty I M n).toEquiv = Equiv.sumEmpty M M' := rfl @[simp, mfld_simps] lemma sumEmpty_apply_inl [IsEmpty M'] (x : M) : (sumEmpty I M (M' := M') n) (Sum.inl x) = x := rfl /-- The unique diffeomorphism between two empty types -/ protected def empty [IsEmpty M] [IsEmpty M'] : Diffeomorph I I M M' n where __ := Equiv.equivOfIsEmpty M M' contMDiff_toFun x := (IsEmpty.false x).elim contMDiff_invFun x := (IsEmpty.false x).elim end disjointUnion end Constructions end Diffeomorph
.lake/packages/mathlib/Mathlib/Geometry/Manifold/LocalDiffeomorph.lean
import Mathlib.Geometry.Manifold.Diffeomorph import Mathlib.Topology.IsLocalHomeomorph /-! # Local diffeomorphisms between manifolds In this file, we define `C^n` local diffeomorphisms between manifolds. A `C^n` map `f : M → N` is a **local diffeomorphism at `x`** iff there are neighbourhoods `s` and `t` of `x` and `f x`, respectively, such that `f` restricts to a diffeomorphism between `s` and `t`. `f` is called a **local diffeomorphism on `s`** iff it is a local diffeomorphism at every `x ∈ s`, and a **local diffeomorphism** iff it is a local diffeomorphism on `univ`. ## Main definitions * `IsLocalDiffeomorphAt I J n f x`: `f` is a `C^n` local diffeomorphism at `x` * `IsLocalDiffeomorphOn I J n f s`: `f` is a `C^n` local diffeomorphism on `s` * `IsLocalDiffeomorph I J n f`: `f` is a `C^n` local diffeomorphism ## Main results * Each of `Diffeomorph`, `IsLocalDiffeomorph`, `IsLocalDiffeomorphOn` and `IsLocalDiffeomorphAt` implies the next condition. * `IsLocalDiffeomorph.isLocalHomeomorph`: a local diffeomorphism is a local homeomorphism, and similarly for a local diffeomorphism on `s`. * `IsLocalDiffeomorph.isOpen_range`: the image of a local diffeomorphism is open * `IsLocalDiffeomorph.diffeomorph_of_bijective`: a bijective local diffeomorphism is a diffeomorphism * `Diffeomorph.mfderivToContinuousLinearEquiv`: each differential of a `C^n` diffeomorphism (`n ≥ 1`) is a linear equivalence. * `LocalDiffeomorphAt.mfderivToContinuousLinearEquiv`: if `f` is a local diffeomorphism at `x`, the differential `mfderiv I J n f x` is a continuous linear equivalence. * `LocalDiffeomorph.mfderivToContinuousLinearEquiv`: if `f` is a local diffeomorphism, each differential `mfderiv I J n f x` is a continuous linear equivalence. ## TODO * an injective local diffeomorphism is a diffeomorphism to its image * if `f` is `C^n` at `x` and `mfderiv I J n f x` is a linear isomorphism, `f` is a local diffeomorphism at `x` (using the inverse function theorem). ## Implementation notes This notion of diffeomorphism is needed although there is already a notion of local structomorphism because structomorphisms do not allow the model spaces `H` and `H'` of the two manifolds to be different, i.e. for a structomorphism one has to impose `H = H'` which is often not the case in practice. ## Tags local diffeomorphism, manifold -/ open Manifold Set TopologicalSpace variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {H : Type*} [TopologicalSpace H] {G : Type*} [TopologicalSpace G] (I : ModelWithCorners 𝕜 E H) (J : ModelWithCorners 𝕜 F G) (M : Type*) [TopologicalSpace M] [ChartedSpace H M] (N : Type*) [TopologicalSpace N] [ChartedSpace G N] (n : WithTop ℕ∞) section PartialDiffeomorph /-- A partial diffeomorphism on `s` is a function `f : M → N` such that `f` restricts to a diffeomorphism `s → t` between open subsets of `M` and `N`, respectively. This is an auxiliary definition and should not be used outside of this file. -/ structure PartialDiffeomorph extends PartialEquiv M N where open_source : IsOpen source open_target : IsOpen target contMDiffOn_toFun : ContMDiffOn I J n toFun source contMDiffOn_invFun : ContMDiffOn J I n invFun target /-- Coercion of a `PartialDiffeomorph` to function. Note that a `PartialDiffeomorph` is not `DFunLike` (like `OpenPartialHomeomorph`), as `toFun` doesn't determine `invFun` outside of `target`. -/ instance : CoeFun (PartialDiffeomorph I J M N n) fun _ => M → N := ⟨fun Φ => Φ.toFun⟩ variable {I J M N n} /-- A diffeomorphism is a partial diffeomorphism. -/ def Diffeomorph.toPartialDiffeomorph (h : Diffeomorph I J M N n) : PartialDiffeomorph I J M N n where toPartialEquiv := h.toHomeomorph.toPartialEquiv open_source := isOpen_univ open_target := isOpen_univ contMDiffOn_toFun x _ := h.contMDiff_toFun x contMDiffOn_invFun _ _ := h.symm.contMDiffWithinAt -- Add the very basic API we need. namespace PartialDiffeomorph variable (Φ : PartialDiffeomorph I J M N n) /-- A partial diffeomorphism is also a local homeomorphism. -/ def toOpenPartialHomeomorph : OpenPartialHomeomorph M N where toPartialEquiv := Φ.toPartialEquiv open_source := Φ.open_source open_target := Φ.open_target continuousOn_toFun := Φ.contMDiffOn_toFun.continuousOn continuousOn_invFun := Φ.contMDiffOn_invFun.continuousOn @[deprecated (since := "2025-08-29")] alias toPartialHomeomorph := toOpenPartialHomeomorph /-- The inverse of a local diffeomorphism. -/ protected def symm : PartialDiffeomorph J I N M n where toPartialEquiv := Φ.toPartialEquiv.symm open_source := Φ.open_target open_target := Φ.open_source contMDiffOn_toFun := Φ.contMDiffOn_invFun contMDiffOn_invFun := Φ.contMDiffOn_toFun protected theorem contMDiffOn : ContMDiffOn I J n Φ Φ.source := Φ.contMDiffOn_toFun protected theorem mdifferentiableOn (hn : 1 ≤ n) : MDifferentiableOn I J Φ Φ.source := (Φ.contMDiffOn).mdifferentiableOn hn protected theorem mdifferentiableAt (hn : 1 ≤ n) {x : M} (hx : x ∈ Φ.source) : MDifferentiableAt I J Φ x := (Φ.mdifferentiableOn hn x hx).mdifferentiableAt (Φ.open_source.mem_nhds hx) /- We could add lots of additional API (following `Diffeomorph` and `OpenPartialHomeomorph`), such as * further continuity and differentiability lemmas * refl and trans instances; lemmas between them. As this declaration is meant for internal use only, we keep it simple. -/ end PartialDiffeomorph end PartialDiffeomorph variable {M N} /-- `f : M → N` is called a **`C^n` local diffeomorphism at *x*** iff there exist open sets `U ∋ x` and `V ∋ f x` and a diffeomorphism `Φ : U → V` such that `f = Φ` on `U`. -/ def IsLocalDiffeomorphAt (f : M → N) (x : M) : Prop := ∃ Φ : PartialDiffeomorph I J M N n, x ∈ Φ.source ∧ EqOn f Φ Φ.source lemma PartialDiffeomorph.isLocalDiffeomorphAt (φ : PartialDiffeomorph I J M N n) {x : M} (hx : x ∈ φ.source) : IsLocalDiffeomorphAt I J n φ x := ⟨φ, hx, Set.eqOn_refl _ _⟩ namespace IsLocalDiffeomorphAt variable {f : M → N} {x : M} variable {I I' J n} /-- An arbitrary choice of local inverse of `f` near `x`. -/ noncomputable def localInverse (hf : IsLocalDiffeomorphAt I J n f x) : PartialDiffeomorph J I N M n := (Classical.choose hf).symm lemma localInverse_open_source (hf : IsLocalDiffeomorphAt I J n f x) : IsOpen hf.localInverse.source := PartialDiffeomorph.open_source _ lemma localInverse_mem_source (hf : IsLocalDiffeomorphAt I J n f x) : f x ∈ hf.localInverse.source := by rw [(hf.choose_spec.2 hf.choose_spec.1)] exact (Classical.choose hf).map_source hf.choose_spec.1 lemma localInverse_mem_target (hf : IsLocalDiffeomorphAt I J n f x) : x ∈ hf.localInverse.target := hf.choose_spec.1 lemma contmdiffOn_localInverse (hf : IsLocalDiffeomorphAt I J n f x) : ContMDiffOn J I n hf.localInverse hf.localInverse.source := hf.localInverse.contMDiffOn_toFun lemma localInverse_right_inv (hf : IsLocalDiffeomorphAt I J n f x) {y : N} (hy : y ∈ hf.localInverse.source) : f (hf.localInverse y) = y := by have : hf.localInverse y ∈ hf.choose.source := by rw [← hf.choose.symm_target] exact hf.choose.symm.map_source hy rw [hf.choose_spec.2 this] exact hf.choose.right_inv hy lemma localInverse_eqOn_right (hf : IsLocalDiffeomorphAt I J n f x) : EqOn (f ∘ hf.localInverse) id hf.localInverse.source := fun _y hy ↦ hf.localInverse_right_inv hy lemma localInverse_eventuallyEq_right (hf : IsLocalDiffeomorphAt I J n f x) : f ∘ hf.localInverse =ᶠ[nhds (f x)] id := Filter.eventuallyEq_of_mem (hf.localInverse.open_source.mem_nhds hf.localInverse_mem_source) hf.localInverse_eqOn_right lemma localInverse_left_inv (hf : IsLocalDiffeomorphAt I J n f x) {x' : M} (hx' : x' ∈ hf.localInverse.target) : hf.localInverse (f x') = x' := by rw [hf.choose_spec.2 (hf.choose.symm_target ▸ hx')] exact hf.choose.left_inv hx' lemma localInverse_eqOn_left (hf : IsLocalDiffeomorphAt I J n f x) : EqOn (hf.localInverse ∘ f) id hf.localInverse.target := fun _ hx ↦ hf.localInverse_left_inv hx lemma localInverse_eventuallyEq_left (hf : IsLocalDiffeomorphAt I J n f x) : hf.localInverse ∘ f =ᶠ[nhds x] id := Filter.eventuallyEq_of_mem (hf.localInverse.open_target.mem_nhds hf.localInverse_mem_target) hf.localInverse_eqOn_left lemma localInverse_isLocalDiffeomorphAt (hf : IsLocalDiffeomorphAt I J n f x) : IsLocalDiffeomorphAt J I n (hf.localInverse) (f x) := hf.localInverse.isLocalDiffeomorphAt _ _ _ hf.localInverse_mem_source lemma localInverse_contMDiffOn (hf : IsLocalDiffeomorphAt I J n f x) : ContMDiffOn J I n hf.localInverse hf.localInverse.source := hf.localInverse.contMDiffOn_toFun lemma localInverse_contMDiffAt (hf : IsLocalDiffeomorphAt I J n f x) : ContMDiffAt J I n hf.localInverse (f x) := hf.localInverse_contMDiffOn.contMDiffAt (hf.localInverse.open_source.mem_nhds hf.localInverse_mem_source) lemma localInverse_mdifferentiableAt (hf : IsLocalDiffeomorphAt I J n f x) (hn : 1 ≤ n) : MDifferentiableAt J I hf.localInverse (f x) := hf.localInverse_contMDiffAt.mdifferentiableAt hn end IsLocalDiffeomorphAt /-- `f : M → N` is called a **`C^n` local diffeomorphism on *s*** iff it is a local diffeomorphism at each `x : s`. -/ def IsLocalDiffeomorphOn (f : M → N) (s : Set M) : Prop := ∀ x : s, IsLocalDiffeomorphAt I J n f x /-- `f : M → N` is a **`C^n` local diffeomorphism** iff it is a local diffeomorphism at each `x ∈ M`. -/ def IsLocalDiffeomorph (f : M → N) : Prop := ∀ x : M, IsLocalDiffeomorphAt I J n f x variable {I J n} in lemma isLocalDiffeomorphOn_iff {f : M → N} (s : Set M) : IsLocalDiffeomorphOn I J n f s ↔ ∀ x : s, IsLocalDiffeomorphAt I J n f x := by rfl variable {I J n} in lemma isLocalDiffeomorph_iff {f : M → N} : IsLocalDiffeomorph I J n f ↔ ∀ x : M, IsLocalDiffeomorphAt I J n f x := by rfl variable {I J n} in theorem isLocalDiffeomorph_iff_isLocalDiffeomorphOn_univ {f : M → N} : IsLocalDiffeomorph I J n f ↔ IsLocalDiffeomorphOn I J n f Set.univ := ⟨fun hf x ↦ hf x, fun hf x ↦ hf ⟨x, trivial⟩⟩ variable {I J n} in lemma IsLocalDiffeomorph.isLocalDiffeomorphOn {f : M → N} (hf : IsLocalDiffeomorph I J n f) (s : Set M) : IsLocalDiffeomorphOn I J n f s := fun x ↦ hf x /-! ### Basic properties of local diffeomorphisms -/ section Basic variable {f : M → N} {s : Set M} {x : M} variable {I J n} /-- A `C^n` local diffeomorphism at `x` is `C^n` differentiable at `x`. -/ lemma IsLocalDiffeomorphAt.contMDiffAt (hf : IsLocalDiffeomorphAt I J n f x) : ContMDiffAt I J n f x := by choose Φ hx heq using hf -- In fact, even `ContMDiffOn I J n f Φ.source`. exact ((Φ.contMDiffOn_toFun).congr heq).contMDiffAt (Φ.open_source.mem_nhds hx) /-- A local diffeomorphism at `x` is differentiable at `x`. -/ lemma IsLocalDiffeomorphAt.mdifferentiableAt (hf : IsLocalDiffeomorphAt I J n f x) (hn : 1 ≤ n) : MDifferentiableAt I J f x := hf.contMDiffAt.mdifferentiableAt hn /-- A `C^n` local diffeomorphism on `s` is `C^n` on `s`. -/ lemma IsLocalDiffeomorphOn.contMDiffOn (hf : IsLocalDiffeomorphOn I J n f s) : ContMDiffOn I J n f s := fun x hx ↦ (hf ⟨x, hx⟩).contMDiffAt.contMDiffWithinAt /-- A local diffeomorphism on `s` is differentiable on `s`. -/ lemma IsLocalDiffeomorphOn.mdifferentiableOn (hf : IsLocalDiffeomorphOn I J n f s) (hn : 1 ≤ n) : MDifferentiableOn I J f s := hf.contMDiffOn.mdifferentiableOn hn /-- A `C^n` local diffeomorphism is `C^n`. -/ lemma IsLocalDiffeomorph.contMDiff (hf : IsLocalDiffeomorph I J n f) : ContMDiff I J n f := fun x ↦ (hf x).contMDiffAt /-- A `C^n` local diffeomorphism is differentiable. -/ lemma IsLocalDiffeomorph.mdifferentiable (hf : IsLocalDiffeomorph I J n f) (hn : 1 ≤ n) : MDifferentiable I J f := fun x ↦ (hf x).mdifferentiableAt hn /-- A `C^n` diffeomorphism is a local diffeomorphism. -/ lemma Diffeomorph.isLocalDiffeomorph (Φ : M ≃ₘ^n⟮I, J⟯ N) : IsLocalDiffeomorph I J n Φ := fun _x ↦ ⟨Φ.toPartialDiffeomorph, by trivial, eqOn_refl Φ _⟩ -- FUTURE: if useful, also add "a `PartialDiffeomorph` is a local diffeomorphism on its source" /-- A local diffeomorphism on `s` is a local homeomorphism on `s`. -/ theorem IsLocalDiffeomorphOn.isLocalHomeomorphOn {s : Set M} (hf : IsLocalDiffeomorphOn I J n f s) : IsLocalHomeomorphOn f s := by apply IsLocalHomeomorphOn.mk intro x hx choose U hyp using hf ⟨x, hx⟩ exact ⟨U.toOpenPartialHomeomorph, hyp⟩ /-- A local diffeomorphism is a local homeomorphism. -/ theorem IsLocalDiffeomorph.isLocalHomeomorph (hf : IsLocalDiffeomorph I J n f) : IsLocalHomeomorph f := by rw [isLocalHomeomorph_iff_isLocalHomeomorphOn_univ] rw [isLocalDiffeomorph_iff_isLocalDiffeomorphOn_univ] at hf exact hf.isLocalHomeomorphOn /-- A local diffeomorphism is an open map. -/ lemma IsLocalDiffeomorph.isOpenMap (hf : IsLocalDiffeomorph I J n f) : IsOpenMap f := (hf.isLocalHomeomorph).isOpenMap /-- A local diffeomorphism has open range. -/ lemma IsLocalDiffeomorph.isOpen_range (hf : IsLocalDiffeomorph I J n f) : IsOpen (range f) := (hf.isOpenMap).isOpen_range /-- The image of a local diffeomorphism is open. -/ def IsLocalDiffeomorph.image (hf : IsLocalDiffeomorph I J n f) : Opens N := ⟨range f, hf.isOpen_range⟩ lemma IsLocalDiffeomorph.image_coe (hf : IsLocalDiffeomorph I J n f) : hf.image.1 = range f := rfl -- TODO: this result holds more generally for (local) structomorphisms -- This argument implies a `LocalDiffeomorphOn f s` for `s` open is a `PartialDiffeomorph` /-- A bijective local diffeomorphism is a diffeomorphism. -/ noncomputable def IsLocalDiffeomorph.diffeomorph_of_bijective (hf : IsLocalDiffeomorph I J n f) (hf' : Function.Bijective f) : Diffeomorph I J M N n := by -- Choose a right inverse `g` of `f`. choose g hgInverse using (Function.bijective_iff_has_inverse).mp hf' -- Choose diffeomorphisms φ_x which coincide which `f` near `x`. choose Φ hyp using (fun x ↦ hf x) -- Two such diffeomorphisms (and their inverses!) coincide on their sources: -- they're both inverses to g. In fact, the latter suffices for our proof. -- have (x y) : EqOn (Φ x).symm (Φ y).symm ((Φ x).target ∩ (Φ y).target) := sorry have aux (x) : EqOn g (Φ x).symm (Φ x).target := eqOn_of_leftInvOn_of_rightInvOn (fun x' _ ↦ hgInverse.1 x') (LeftInvOn.congr_left ((Φ x).toOpenPartialHomeomorph).rightInvOn ((Φ x).toOpenPartialHomeomorph).symm_mapsTo (hyp x).2.symm) (fun _y hy ↦ (Φ x).map_target hy) exact { toFun := f invFun := g left_inv := hgInverse.1 right_inv := hgInverse.2 contMDiff_toFun := hf.contMDiff contMDiff_invFun := by intro y let x := g y obtain ⟨hx, hfx⟩ := hyp x apply ((Φ x).symm.contMDiffOn.congr (aux x)).contMDiffAt (((Φ x).open_target).mem_nhds ?_) have : y = (Φ x) x := ((hgInverse.2 y).congr (hfx hx)).mp rfl exact this ▸ (Φ x).map_source hx } end Basic section Differential variable {f : M → N} {s : Set M} {x : M} variable {I I' J n} /-- If `f` is a `C^n` local diffeomorphism at `x`, for `n ≥ 1`, the differential `df_x` is a linear equivalence. -/ noncomputable def IsLocalDiffeomorphAt.mfderivToContinuousLinearEquiv (hf : IsLocalDiffeomorphAt I J n f x) (hn : 1 ≤ n) : TangentSpace I x ≃L[𝕜] TangentSpace J (f x) where toFun := mfderiv I J f x invFun := mfderiv J I hf.localInverse (f x) left_inv := by apply ContinuousLinearMap.leftInverse_of_comp rw [← mfderiv_id, ← hf.localInverse_eventuallyEq_left.mfderiv_eq] exact (mfderiv_comp _ (hf.localInverse_mdifferentiableAt hn) (hf.mdifferentiableAt hn)).symm right_inv := by apply ContinuousLinearMap.rightInverse_of_comp rw [← mfderiv_id, ← hf.localInverse_eventuallyEq_right.mfderiv_eq] -- We need to rewrite the base point hf.localInverse (f x) = x twice, -- in the differentiability hypothesis and for applying the chain rule. have hf' : MDifferentiableAt I J f (hf.localInverse (f x)) := by rw [hf.localInverse_left_inv hf.localInverse_mem_target] exact hf.mdifferentiableAt hn rw [mfderiv_comp _ hf' (hf.localInverse_mdifferentiableAt hn), hf.localInverse_left_inv hf.localInverse_mem_target] continuous_toFun := (mfderiv I J f x).cont continuous_invFun := (mfderiv J I hf.localInverse (f x)).cont map_add' := fun x_1 y ↦ ContinuousLinearMap.map_add _ x_1 y map_smul' := by intros; simp @[simp, mfld_simps] lemma IsLocalDiffeomorphAt.mfderivToContinuousLinearEquiv_coe (hf : IsLocalDiffeomorphAt I J n f x) (hn : 1 ≤ n) : hf.mfderivToContinuousLinearEquiv hn = mfderiv I J f x := rfl /-- Each differential of a `C^n` diffeomorphism of Banach manifolds (`n ≥ 1`) is a linear equivalence. -/ noncomputable def Diffeomorph.mfderivToContinuousLinearEquiv (Φ : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) (x : M) : TangentSpace I x ≃L[𝕜] TangentSpace J (Φ x) := (Φ.isLocalDiffeomorph x).mfderivToContinuousLinearEquiv hn lemma Diffeomorph.mfderivToContinuousLinearEquiv_coe (Φ : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) : Φ.mfderivToContinuousLinearEquiv hn x = mfderiv I J Φ x := by rfl /-- If `f` is a `C^n` local diffeomorphism of Banach manifolds (`n ≥ 1`), each differential is a linear equivalence. -/ noncomputable def IsLocalDiffeomorph.mfderivToContinuousLinearEquiv (hf : IsLocalDiffeomorph I J n f) (hn : 1 ≤ n) (x : M) : TangentSpace I x ≃L[𝕜] TangentSpace J (f x) := (hf x).mfderivToContinuousLinearEquiv hn lemma IsLocalDiffeomorph.mfderivToContinuousLinearEquiv_coe (hf : IsLocalDiffeomorph I J n f) (hn : 1 ≤ n) (x : M) : hf.mfderivToContinuousLinearEquiv hn x = mfderiv I J f x := (hf x).mfderivToContinuousLinearEquiv_coe hn end Differential
.lake/packages/mathlib/Mathlib/Geometry/Manifold/Complex.lean
import Mathlib.Analysis.Complex.AbsMax import Mathlib.Analysis.LocallyConvex.WithSeminorms import Mathlib.Geometry.Manifold.MFDeriv.Basic import Mathlib.Topology.LocallyConstant.Basic /-! # Holomorphic functions on complex manifolds Thanks to the rigidity of complex-differentiability compared to real-differentiability, there are many results about complex manifolds with no analogue for manifolds over a general normed field. For now, this file contains just two (closely related) such results: ## Main results * `MDifferentiable.isLocallyConstant`: A complex-differentiable function on a compact complex manifold is locally constant. * `MDifferentiable.exists_eq_const_of_compactSpace`: A complex-differentiable function on a compact preconnected complex manifold is constant. ## TODO There is a whole theory to develop here. Maybe a next step would be to develop a theory of holomorphic vector/line bundles, including: * the finite-dimensionality of the space of sections of a holomorphic vector bundle * Siegel's theorem: for any `n + 1` formal ratios `g 0 / h 0`, `g 1 / h 1`, .... `g n / h n` of sections of a fixed line bundle `L` over a complex `n`-manifold, there exists a polynomial relationship `P (g 0 / h 0, g 1 / h 1, .... g n / h n) = 0` Another direction would be to develop the relationship with sheaf theory, building the sheaves of holomorphic and meromorphic functions on a complex manifold and proving algebraic results about the stalks, such as the Weierstrass preparation theorem. -/ open scoped Manifold Topology Filter open Function Set Filter Complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℂ F] variable {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℂ E H} [I.Boundaryless] variable {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I 1 M] /-- **Maximum modulus principle**: if `f : M → F` is complex differentiable in a neighborhood of `c` and the norm `‖f z‖` has a local maximum at `c`, then `‖f z‖` is locally constant in a neighborhood of `c`. This is a manifold version of `Complex.norm_eventually_eq_of_isLocalMax`. -/ theorem Complex.norm_eventually_eq_of_mdifferentiableAt_of_isLocalMax {f : M → F} {c : M} (hd : ∀ᶠ z in 𝓝 c, MDifferentiableAt I 𝓘(ℂ, F) f z) (hc : IsLocalMax (norm ∘ f) c) : ∀ᶠ y in 𝓝 c, ‖f y‖ = ‖f c‖ := by set e := extChartAt I c have hI : range I = univ := ModelWithCorners.Boundaryless.range_eq_univ have H₁ : 𝓝[range I] (e c) = 𝓝 (e c) := by rw [hI, nhdsWithin_univ] have H₂ : map e.symm (𝓝 (e c)) = 𝓝 c := by rw [← map_extChartAt_symm_nhdsWithin_range (I := I) c, H₁] rw [← H₂, eventually_map] replace hd : ∀ᶠ y in 𝓝 (e c), DifferentiableAt ℂ (f ∘ e.symm) y := by have : e.target ∈ 𝓝 (e c) := H₁ ▸ extChartAt_target_mem_nhdsWithin c filter_upwards [this, Tendsto.eventually H₂.le hd] with y hyt hy₂ have hys : e.symm y ∈ (chartAt H c).source := by rw [← extChartAt_source I c] exact (extChartAt I c).map_target hyt have hfy : f (e.symm y) ∈ (chartAt F (0 : F)).source := mem_univ _ rw [mdifferentiableAt_iff_of_mem_source hys hfy, hI, differentiableWithinAt_univ, e.right_inv hyt] at hy₂ exact hy₂.2 convert norm_eventually_eq_of_isLocalMax hd _ · exact congr_arg f (extChartAt_to_inv _).symm · simpa only [e, IsLocalMax, IsMaxFilter, ← H₂, (· ∘ ·), extChartAt_to_inv] using hc /-! ### Functions holomorphic on a set -/ namespace MDifferentiableOn /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U`. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `‖f x‖ = ‖f c‖` for all `x ∈ U`. -/ theorem norm_eqOn_of_isPreconnected_of_isMaxOn {f : M → F} {U : Set M} {c : M} (hd : MDifferentiableOn I 𝓘(ℂ, F) f U) (hc : IsPreconnected U) (ho : IsOpen U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn (norm ∘ f) (const M ‖f c‖) U := by set V := {z ∈ U | ‖f z‖ = ‖f c‖} suffices U ⊆ V from fun x hx ↦ (this hx).2 have hVo : IsOpen V := by refine isOpen_iff_mem_nhds.2 fun x hx ↦ inter_mem (ho.mem_nhds hx.1) ?_ replace hm : IsLocalMax (‖f ·‖) x := mem_of_superset (ho.mem_nhds hx.1) fun z hz ↦ (hm hz).out.trans_eq hx.2.symm replace hd : ∀ᶠ y in 𝓝 x, MDifferentiableAt I 𝓘(ℂ, F) f y := (eventually_mem_nhds_iff.2 (ho.mem_nhds hx.1)).mono fun z ↦ hd.mdifferentiableAt exact (Complex.norm_eventually_eq_of_mdifferentiableAt_of_isLocalMax hd hm).mono fun _ ↦ (Eq.trans · hx.2) have hVne : (U ∩ V).Nonempty := ⟨c, hcU, hcU, rfl⟩ set W := U ∩ {z | ‖f z‖ = ‖f c‖}ᶜ have hWo : IsOpen W := hd.continuousOn.norm.isOpen_inter_preimage ho isOpen_ne have hdVW : Disjoint V W := disjoint_compl_right.mono inf_le_right inf_le_right have hUVW : U ⊆ V ∪ W := fun x hx => (eq_or_ne ‖f x‖ ‖f c‖).imp (.intro hx) (.intro hx) exact hc.subset_left_of_subset_union hVo hWo hdVW hUVW hVne /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U`. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `f x = f c` for all `x ∈ U`. TODO: change assumption from `IsMaxOn` to `IsLocalMax`. -/ theorem eqOn_of_isPreconnected_of_isMaxOn_norm [StrictConvexSpace ℝ F] {f : M → F} {U : Set M} {c : M} (hd : MDifferentiableOn I 𝓘(ℂ, F) f U) (hc : IsPreconnected U) (ho : IsOpen U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn f (const M (f c)) U := fun x hx => have H₁ : ‖f x‖ = ‖f c‖ := hd.norm_eqOn_of_isPreconnected_of_isMaxOn hc ho hcU hm hx -- TODO: Add `MDifferentiableOn.add` etc; does it mean importing `Manifold.Algebra.Monoid`? have hd' : MDifferentiableOn I 𝓘(ℂ, F) (f · + f c) U := fun x hx ↦ ⟨(hd x hx).1.add continuousWithinAt_const, (hd x hx).2.add_const _⟩ have H₂ : ‖f x + f c‖ = ‖f c + f c‖ := hd'.norm_eqOn_of_isPreconnected_of_isMaxOn hc ho hcU hm.norm_add_self hx eq_of_norm_eq_of_norm_add_eq H₁ <| by simp only [H₂, SameRay.rfl.norm_add, H₁, Function.const] /-- If a function `f : M → F` from a complex manifold to a complex normed space is holomorphic on a (pre)connected compact open set, then it is a constant on this set. -/ theorem apply_eq_of_isPreconnected_isCompact_isOpen {f : M → F} {U : Set M} {a b : M} (hd : MDifferentiableOn I 𝓘(ℂ, F) f U) (hpc : IsPreconnected U) (hc : IsCompact U) (ho : IsOpen U) (ha : a ∈ U) (hb : b ∈ U) : f a = f b := by refine ?_ -- Subtract `f b` to avoid the assumption `[StrictConvexSpace ℝ F]` wlog hb₀ : f b = 0 generalizing f · have hd' : MDifferentiableOn I 𝓘(ℂ, F) (f · - f b) U := fun x hx ↦ ⟨(hd x hx).1.sub continuousWithinAt_const, (hd x hx).2.sub_const _⟩ simpa [sub_eq_zero] using this hd' (sub_self _) rcases hc.exists_isMaxOn ⟨a, ha⟩ hd.continuousOn.norm with ⟨c, hcU, hc⟩ have : ∀ x ∈ U, ‖f x‖ = ‖f c‖ := norm_eqOn_of_isPreconnected_of_isMaxOn hd hpc ho hcU hc rw [hb₀, ← norm_eq_zero, this a ha, ← this b hb, hb₀, norm_zero] end MDifferentiableOn /-! ### Functions holomorphic on the whole manifold Lemmas in this section were generalized from `𝓘(ℂ, E)` to an unspecified boundaryless model so that it works, e.g., on a product of two manifolds without a boundary. This can break `apply MDifferentiable.apply_eq_of_compactSpace`, use `apply MDifferentiable.apply_eq_of_compactSpace (I := I)` instead or dot notation on an existing `MDifferentiable` hypothesis. -/ namespace MDifferentiable variable [CompactSpace M] /-- A holomorphic function on a compact complex manifold is locally constant. -/ protected theorem isLocallyConstant {f : M → F} (hf : MDifferentiable I 𝓘(ℂ, F) f) : IsLocallyConstant f := haveI : LocallyConnectedSpace H := I.toHomeomorph.locallyConnectedSpace haveI : LocallyConnectedSpace M := ChartedSpace.locallyConnectedSpace H M IsLocallyConstant.of_constant_on_preconnected_clopens fun _ hpc hclo _a ha _b hb ↦ hf.mdifferentiableOn.apply_eq_of_isPreconnected_isCompact_isOpen hpc hclo.isClosed.isCompact hclo.isOpen hb ha /-- A holomorphic function on a compact connected complex manifold is constant. -/ theorem apply_eq_of_compactSpace [PreconnectedSpace M] {f : M → F} (hf : MDifferentiable I 𝓘(ℂ, F) f) (a b : M) : f a = f b := hf.isLocallyConstant.apply_eq_of_preconnectedSpace _ _ /-- A holomorphic function on a compact connected complex manifold is the constant function `f ≡ v`, for some value `v`. -/ theorem exists_eq_const_of_compactSpace [PreconnectedSpace M] {f : M → F} (hf : MDifferentiable I 𝓘(ℂ, F) f) : ∃ v : F, f = Function.const M v := hf.isLocallyConstant.exists_eq_const end MDifferentiable
.lake/packages/mathlib/Mathlib/Geometry/Manifold/PoincareConjecture.lean
import Mathlib.AlgebraicTopology.FundamentalGroupoid.SimplyConnected import Mathlib.Geometry.Manifold.Diffeomorph import Mathlib.Geometry.Manifold.Instances.Sphere import Mathlib.Topology.Homotopy.Equiv import Mathlib.Util.Superscript /-! # Statement of the generalized Poincaré conjecture https://en.wikipedia.org/wiki/Generalized_Poincar%C3%A9_conjecture The mathlib notation `≃ₕ` stands for a homotopy equivalence, `≃ₜ` stands for a homeomorphism, and `≃ₘ⟮𝓡 n, 𝓡 n⟯` stands for a diffeomorphism, where `𝓡 n` is the `n`-dimensional Euclidean space viewed as a model space. -/ open scoped Manifold ContDiff open Metric (sphere) local macro:max "ℝ" noWs n:superscript(term) : term => `(EuclideanSpace ℝ (Fin $(⟨n.raw[0]⟩))) local macro:max "𝕊"n:superscript(term) : term => `(sphere (0 : EuclideanSpace ℝ (Fin ($(⟨n.raw[0]⟩) + 1))) 1) variable (M : Type*) [TopologicalSpace M] open ContinuousMap /-- The generalized topological Poincaré conjecture. - For n = 2 it follows from the classification of surfaces. - For n ≥ 5 it was proven by Stephen Smale in 1961 assuming M admits a smooth structure; Newman (1966) and Connell (1967) proved it without the condition. - For n = 4 it was proven by Michael Freedman in 1982. - For n = 3 it was proven by Grigori Perelman in 2003. -/ proof_wanted ContinuousMap.HomotopyEquiv.nonempty_homeomorph_sphere [T2Space M] (n : ℕ) [ChartedSpace ℝⁿ M] : M ≃ₕ 𝕊ⁿ → Nonempty (M ≃ₜ 𝕊ⁿ) /-- The 3-dimensional topological Poincaré conjecture (proven by Perelman) -/ proof_wanted SimplyConnectedSpace.nonempty_homeomorph_sphere_three [T2Space M] [ChartedSpace ℝ³ M] [SimplyConnectedSpace M] [CompactSpace M] : Nonempty (M ≃ₜ 𝕊³) /-- The 3-dimensional smooth Poincaré conjecture (proven by Perelman) -/ proof_wanted SimplyConnectedSpace.nonempty_diffeomorph_sphere_three [T2Space M] [ChartedSpace ℝ³ M] [IsManifold (𝓡 3) ∞ M] [SimplyConnectedSpace M] [CompactSpace M] : Nonempty (M ≃ₘ⟮𝓡 3, 𝓡 3⟯ 𝕊³) /-- The smooth Poincaré conjecture; true for n = 1, 2, 3, 5, 6, 12, 56, and 61, open for n = 4, and it is conjectured that there are no other n > 4 for which it is true (Conjecture 1.17, https://annals.math.princeton.edu/2017/186-2/p03). -/ def ContinuousMap.HomotopyEquiv.NonemptyDiffeomorphSphere (n : ℕ) : Prop := ∀ (_ : ChartedSpace ℝⁿ M) (_ : IsManifold (𝓡 n) ∞ M), M ≃ₕ 𝕊ⁿ → Nonempty (M ≃ₘ⟮𝓡 n, 𝓡 n⟯ 𝕊ⁿ) /-- The existence of an exotic 7-sphere (due to John Milnor) -/ proof_wanted exists_homeomorph_isEmpty_diffeomorph_sphere_seven : ∃ (M : Type) (_ : TopologicalSpace M) (_ : ChartedSpace ℝ⁷ M) (_ : IsManifold (𝓡 7) ∞ M) (_homeo : M ≃ₜ 𝕊⁷), IsEmpty (M ≃ₘ⟮𝓡 7, 𝓡 7⟯ 𝕊⁷) /-- The existence of a small exotic ℝ⁴, i.e. an open subset of ℝ⁴ that is homeomorphic but not diffeomorphic to ℝ⁴. See https://en.wikipedia.org/wiki/Exotic_R4. -/ proof_wanted exists_open_nonempty_homeomorph_isEmpty_diffeomorph_euclideanSpace_four : ∃ M : TopologicalSpace.Opens ℝ⁴, Nonempty (M ≃ₜ ℝ⁴) ∧ IsEmpty (M ≃ₘ⟮𝓡 4, 𝓡 4⟯ ℝ⁴)
.lake/packages/mathlib/Mathlib/Geometry/Manifold/PartitionOfUnity.lean
import Mathlib.Geometry.Manifold.Algebra.Structures import Mathlib.Geometry.Manifold.BumpFunction import Mathlib.Geometry.Manifold.VectorBundle.SmoothSection import Mathlib.Topology.MetricSpace.PartitionOfUnity import Mathlib.Topology.ShrinkingLemma /-! # Smooth partition of unity In this file we define two structures, `SmoothBumpCovering` and `SmoothPartitionOfUnity`. Both structures describe coverings of a set by a locally finite family of supports of smooth functions with some additional properties. The former structure is mostly useful as an intermediate step in the construction of a smooth partition of unity but some proofs that traditionally deal with a partition of unity can use a `SmoothBumpCovering` as well. Given a real manifold `M` and its subset `s`, a `SmoothBumpCovering ι I M s` is a collection of `SmoothBumpFunction`s `f i` indexed by `i : ι` such that * the center of each `f i` belongs to `s`; * the family of sets `support (f i)` is locally finite; * for each `x ∈ s`, there exists `i : ι` such that `f i =ᶠ[𝓝 x] 1`. In the same settings, a `SmoothPartitionOfUnity ι I M s` is a collection of smooth nonnegative functions `f i : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯`, `i : ι`, such that * the family of sets `support (f i)` is locally finite; * for each `x ∈ s`, the sum `∑ᶠ i, f i x` equals one; * for each `x`, the sum `∑ᶠ i, f i x` is less than or equal to one. We say that `f : SmoothBumpCovering ι I M s` is *subordinate* to a map `U : M → Set M` if for each index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than being subordinate to an open covering of `M`, because we make no assumption about the way `U x` depends on `x`. We prove that on a smooth finite-dimensional real manifold with `σ`-compact Hausdorff topology, for any `U : M → Set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `SmoothBumpCovering ι I M s` subordinate to `U`. Then we use this fact to prove a similar statement about smooth partitions of unity, see `SmoothPartitionOfUnity.exists_isSubordinate`. Finally, we use existence of a partition of unity to prove lemma `exists_smooth_forall_mem_convex_of_local` that allows us to construct a globally defined smooth function from local functions. ## TODO * Build a framework for to transfer local definitions to global using partition of unity and use it to define, e.g., the integral of a differential form over a manifold. Lemma `exists_smooth_forall_mem_convex_of_local` is a first step in this direction. ## Tags smooth bump function, partition of unity -/ universe uι uE uH uM uF open Bundle Function Filter Module Set open scoped Topology Manifold ContDiff noncomputable section variable {ι : Type uι} {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace ℝ F] {H : Type uH} [TopologicalSpace H] (I : ModelWithCorners ℝ E H) {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] /-! ### Covering by supports of smooth bump functions In this section we define `SmoothBumpCovering ι I M s` to be a collection of `SmoothBumpFunction`s such that their supports is a locally finite family of sets and for each `x ∈ s` some function `f i` from the collection is equal to `1` in a neighborhood of `x`. A covering of this type is useful to construct a smooth partition of unity and can be used instead of a partition of unity in some proofs. We prove that on a smooth finite-dimensional real manifold with `σ`-compact Hausdorff topology, for any `U : M → Set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `SmoothBumpCovering ι I M s` subordinate to `U`. -/ variable (ι M) /-- We say that a collection of `SmoothBumpFunction`s is a `SmoothBumpCovering` of a set `s` if * `(f i).c ∈ s` for all `i`; * the family `fun i ↦ support (f i)` is locally finite; * for each point `x ∈ s` there exists `i` such that `f i =ᶠ[𝓝 x] 1`; in other words, `x` belongs to the interior of `{y | f i y = 1}`; If `M` is a finite-dimensional real manifold which is a `σ`-compact Hausdorff topological space, then for every covering `U : M → Set M`, `∀ x, U x ∈ 𝓝 x`, there exists a `SmoothBumpCovering` subordinate to `U`, see `SmoothBumpCovering.exists_isSubordinate`. This covering can be used, e.g., to construct a partition of unity and to prove the weak Whitney embedding theorem. -/ structure SmoothBumpCovering [FiniteDimensional ℝ E] (s : Set M := univ) where /-- The center point of each bump in the smooth covering. -/ c : ι → M /-- A smooth bump function around `c i`. -/ toFun : ∀ i, SmoothBumpFunction I (c i) /-- All the bump functions in the covering are centered at points in `s`. -/ c_mem' : ∀ i, c i ∈ s /-- Around each point, there are only finitely many nonzero bump functions in the family. -/ locallyFinite' : LocallyFinite fun i => support (toFun i) /-- Around each point in `s`, one of the bump functions is equal to `1`. -/ eventuallyEq_one' : ∀ x ∈ s, ∃ i, toFun i =ᶠ[𝓝 x] 1 /-- We say that a collection of functions form a smooth partition of unity on a set `s` if * all functions are infinitely smooth and nonnegative; * the family `fun i ↦ support (f i)` is locally finite; * for all `x ∈ s` the sum `∑ᶠ i, f i x` equals one; * for all `x`, the sum `∑ᶠ i, f i x` is less than or equal to one. -/ structure SmoothPartitionOfUnity (s : Set M := univ) where /-- The family of functions forming the partition of unity. -/ toFun : ι → C^∞⟮I, M; 𝓘(ℝ), ℝ⟯ /-- Around each point, there are only finitely many nonzero functions in the family. -/ locallyFinite' : LocallyFinite fun i => support (toFun i) /-- All the functions in the partition of unity are nonnegative. -/ nonneg' : ∀ i x, 0 ≤ toFun i x /-- The functions in the partition of unity add up to `1` at any point of `s`. -/ sum_eq_one' : ∀ x ∈ s, ∑ᶠ i, toFun i x = 1 /-- The functions in the partition of unity add up to at most `1` everywhere. -/ sum_le_one' : ∀ x, ∑ᶠ i, toFun i x ≤ 1 variable {ι I M} namespace SmoothPartitionOfUnity variable {s : Set M} (f : SmoothPartitionOfUnity ι I M s) {n : ℕ∞} instance {s : Set M} : FunLike (SmoothPartitionOfUnity ι I M s) ι C^∞⟮I, M; 𝓘(ℝ), ℝ⟯ where coe := toFun coe_injective' f g h := by cases f; cases g; congr protected theorem locallyFinite : LocallyFinite fun i => support (f i) := f.locallyFinite' theorem nonneg (i : ι) (x : M) : 0 ≤ f i x := f.nonneg' i x theorem sum_eq_one {x} (hx : x ∈ s) : ∑ᶠ i, f i x = 1 := f.sum_eq_one' x hx theorem exists_pos_of_mem {x} (hx : x ∈ s) : ∃ i, 0 < f i x := by by_contra! h have H : ∀ i, f i x = 0 := fun i ↦ le_antisymm (h i) (f.nonneg i x) have := f.sum_eq_one hx simp_rw [H] at this simpa theorem sum_le_one (x : M) : ∑ᶠ i, f i x ≤ 1 := f.sum_le_one' x /-- Reinterpret a smooth partition of unity as a continuous partition of unity. -/ @[simps] def toPartitionOfUnity : PartitionOfUnity ι M s := { f with toFun := fun i => f i } theorem contMDiff_sum : ContMDiff I 𝓘(ℝ) ∞ fun x => ∑ᶠ i, f i x := contMDiff_finsum (fun i => (f i).contMDiff) f.locallyFinite theorem le_one (i : ι) (x : M) : f i x ≤ 1 := f.toPartitionOfUnity.le_one i x theorem sum_nonneg (x : M) : 0 ≤ ∑ᶠ i, f i x := f.toPartitionOfUnity.sum_nonneg x theorem finsum_smul_mem_convex {g : ι → M → F} {t : Set F} {x : M} (hx : x ∈ s) (hg : ∀ i, f i x ≠ 0 → g i x ∈ t) (ht : Convex ℝ t) : ∑ᶠ i, f i x • g i x ∈ t := ht.finsum_mem (fun _ => f.nonneg _ _) (f.sum_eq_one hx) hg theorem contMDiff_smul {g : M → F} {i} (hg : ∀ x ∈ tsupport (f i), ContMDiffAt I 𝓘(ℝ, F) n g x) : ContMDiff I 𝓘(ℝ, F) n fun x => f i x • g x := contMDiff_of_tsupport fun x hx => ((f i).contMDiff.contMDiffAt.of_le (mod_cast le_top)).smul <| hg x <| tsupport_smul_subset_left _ _ hx /-- If `f` is a smooth partition of unity on a set `s : Set M` and `g : ι → M → F` is a family of functions such that `g i` is $C^n$ smooth at every point of the topological support of `f i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is smooth on the whole manifold. -/ theorem contMDiff_finsum_smul {g : ι → M → F} (hg : ∀ (i), ∀ x ∈ tsupport (f i), ContMDiffAt I 𝓘(ℝ, F) n (g i) x) : ContMDiff I 𝓘(ℝ, F) n fun x => ∑ᶠ i, f i x • g i x := (contMDiff_finsum fun i => f.contMDiff_smul (hg i)) <| f.locallyFinite.subset fun _ => support_smul_subset_left _ _ theorem contMDiffAt_finsum {x₀ : M} {g : ι → M → F} (hφ : ∀ i, x₀ ∈ tsupport (f i) → ContMDiffAt I 𝓘(ℝ, F) n (g i) x₀) : ContMDiffAt I 𝓘(ℝ, F) n (fun x ↦ ∑ᶠ i, f i x • g i x) x₀ := by refine _root_.contMDiffAt_finsum (f.locallyFinite.smul_left _) fun i ↦ ?_ by_cases hx : x₀ ∈ tsupport (f i) · exact ContMDiffAt.smul ((f i).contMDiff.of_le (mod_cast le_top)).contMDiffAt (hφ i hx) · exact contMDiffAt_of_notMem (compl_subset_compl.mpr (tsupport_smul_subset_left (f i) (g i)) hx) n theorem contDiffAt_finsum {s : Set E} (f : SmoothPartitionOfUnity ι 𝓘(ℝ, E) E s) {x₀ : E} {g : ι → E → F} (hφ : ∀ i, x₀ ∈ tsupport (f i) → ContDiffAt ℝ n (g i) x₀) : ContDiffAt ℝ n (fun x ↦ ∑ᶠ i, f i x • g i x) x₀ := by simp only [← contMDiffAt_iff_contDiffAt] at * exact f.contMDiffAt_finsum hφ section finsupport variable {s : Set M} (ρ : SmoothPartitionOfUnity ι I M s) (x₀ : M) /-- The support of a smooth partition of unity at a point `x₀` as a `Finset`. This is the set of `i : ι` such that `x₀ ∈ support f i`, i.e. `f i ≠ x₀`. -/ def finsupport : Finset ι := ρ.toPartitionOfUnity.finsupport x₀ @[simp] theorem mem_finsupport {i : ι} : i ∈ ρ.finsupport x₀ ↔ i ∈ support fun i ↦ ρ i x₀ := ρ.toPartitionOfUnity.mem_finsupport x₀ @[simp] theorem coe_finsupport : (ρ.finsupport x₀ : Set ι) = support fun i ↦ ρ i x₀ := ρ.toPartitionOfUnity.coe_finsupport x₀ theorem sum_finsupport (hx₀ : x₀ ∈ s) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ = 1 := ρ.toPartitionOfUnity.sum_finsupport hx₀ theorem sum_finsupport' (hx₀ : x₀ ∈ s) {I : Finset ι} (hI : ρ.finsupport x₀ ⊆ I) : ∑ i ∈ I, ρ i x₀ = 1 := ρ.toPartitionOfUnity.sum_finsupport' hx₀ hI theorem sum_finsupport_smul_eq_finsum {A : Type*} [AddCommGroup A] [Module ℝ A] (φ : ι → M → A) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ • φ i x₀ = ∑ᶠ i, ρ i x₀ • φ i x₀ := ρ.toPartitionOfUnity.sum_finsupport_smul_eq_finsum φ end finsupport section fintsupport -- smooth partitions of unity have locally finite `tsupport` variable {s : Set M} (ρ : SmoothPartitionOfUnity ι I M s) (x₀ : M) /-- The `tsupport`s of a smooth partition of unity are locally finite. -/ theorem finite_tsupport : {i | x₀ ∈ tsupport (ρ i)}.Finite := ρ.toPartitionOfUnity.finite_tsupport _ /-- The tsupport of a partition of unity at a point `x₀` as a `Finset`. This is the set of `i : ι` such that `x₀ ∈ tsupport f i`. -/ def fintsupport (x : M) : Finset ι := (ρ.finite_tsupport x).toFinset theorem mem_fintsupport_iff (i : ι) : i ∈ ρ.fintsupport x₀ ↔ x₀ ∈ tsupport (ρ i) := Finite.mem_toFinset _ theorem eventually_fintsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.fintsupport y ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.eventually_fintsupport_subset _ theorem finsupport_subset_fintsupport : ρ.finsupport x₀ ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.finsupport_subset_fintsupport x₀ theorem eventually_finsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.finsupport y ⊆ ρ.fintsupport x₀ := ρ.toPartitionOfUnity.eventually_finsupport_subset x₀ end fintsupport section IsSubordinate /-- A smooth partition of unity `f i` is subordinate to a family of sets `U i` indexed by the same type if for each `i` the closure of the support of `f i` is a subset of `U i`. -/ def IsSubordinate (f : SmoothPartitionOfUnity ι I M s) (U : ι → Set M) := ∀ i, tsupport (f i) ⊆ U i variable {f} variable {U : ι → Set M} @[simp] theorem isSubordinate_toPartitionOfUnity : f.toPartitionOfUnity.IsSubordinate U ↔ f.IsSubordinate U := Iff.rfl alias ⟨_, IsSubordinate.toPartitionOfUnity⟩ := isSubordinate_toPartitionOfUnity /-- If `f` is a smooth partition of unity on a set `s : Set M` subordinate to a family of open sets `U : ι → Set M` and `g : ι → M → F` is a family of functions such that `g i` is $C^n$ smooth on `U i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is $C^n$ smooth on the whole manifold. -/ theorem IsSubordinate.contMDiff_finsum_smul {g : ι → M → F} (hf : f.IsSubordinate U) (ho : ∀ i, IsOpen (U i)) (hg : ∀ i, ContMDiffOn I 𝓘(ℝ, F) n (g i) (U i)) : ContMDiff I 𝓘(ℝ, F) n fun x => ∑ᶠ i, f i x • g i x := f.contMDiff_finsum_smul fun i _ hx => (hg i).contMDiffAt <| (ho i).mem_nhds (hf i hx) end IsSubordinate end SmoothPartitionOfUnity namespace BumpCovering -- Repeat variables to drop `[FiniteDimensional ℝ E]` and `[IsManifold I ∞ M]` theorem contMDiff_toPartitionOfUnity {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M] [ChartedSpace H M] {s : Set M} (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) (i : ι) : ContMDiff I 𝓘(ℝ) ∞ (f.toPartitionOfUnity i) := (hf i).mul <| (contMDiff_finprod_cond fun j _ => contMDiff_const.sub (hf j)) <| by simp only [mulSupport_one_sub] exact f.locallyFinite variable {s : Set M} /-- A `BumpCovering` such that all functions in this covering are smooth generates a smooth partition of unity. In our formalization, not every `f : BumpCovering ι M s` with smooth functions `f i` is a `SmoothBumpCovering`; instead, a `SmoothBumpCovering` is a covering by supports of `SmoothBumpFunction`s. So, we define `BumpCovering.toSmoothPartitionOfUnity`, then reuse it in `SmoothBumpCovering.toSmoothPartitionOfUnity`. -/ def toSmoothPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : SmoothPartitionOfUnity ι I M s := { f.toPartitionOfUnity with toFun := fun i => ⟨f.toPartitionOfUnity i, f.contMDiff_toPartitionOfUnity hf i⟩ } @[simp] theorem toSmoothPartitionOfUnity_toPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : (f.toSmoothPartitionOfUnity hf).toPartitionOfUnity = f.toPartitionOfUnity := rfl @[simp] theorem coe_toSmoothPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) (i : ι) : ⇑(f.toSmoothPartitionOfUnity hf i) = f.toPartitionOfUnity i := rfl theorem IsSubordinate.toSmoothPartitionOfUnity {f : BumpCovering ι M s} {U : ι → Set M} (h : f.IsSubordinate U) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) : (f.toSmoothPartitionOfUnity hf).IsSubordinate U := h.toPartitionOfUnity end BumpCovering namespace SmoothBumpCovering variable [FiniteDimensional ℝ E] variable {s : Set M} {U : M → Set M} (fs : SmoothBumpCovering ι I M s) instance : CoeFun (SmoothBumpCovering ι I M s) fun x => ∀ i : ι, SmoothBumpFunction I (x.c i) := ⟨toFun⟩ /-- We say that `f : SmoothBumpCovering ι I M s` is *subordinate* to a map `U : M → Set M` if for each index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than being subordinate to an open covering of `M`, because we make no assumption about the way `U x` depends on `x`. -/ def IsSubordinate {s : Set M} (f : SmoothBumpCovering ι I M s) (U : M → Set M) := ∀ i, tsupport (f i) ⊆ U (f.c i) theorem IsSubordinate.support_subset {fs : SmoothBumpCovering ι I M s} {U : M → Set M} (h : fs.IsSubordinate U) (i : ι) : support (fs i) ⊆ U (fs.c i) := Subset.trans subset_closure (h i) variable (I) in /-- Let `M` be a smooth manifold modelled on a finite-dimensional real vector space. Suppose also that `M` is a Hausdorff `σ`-compact topological space. Let `s` be a closed set in `M` and `U : M → Set M` be a collection of sets such that `U x ∈ 𝓝 x` for every `x ∈ s`. Then there exists a smooth bump covering of `s` that is subordinate to `U`. -/ theorem exists_isSubordinate [T2Space M] [SigmaCompactSpace M] (hs : IsClosed s) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ (ι : Type uM) (f : SmoothBumpCovering ι I M s), f.IsSubordinate U := by -- First we deduce some missing instances haveI : LocallyCompactSpace H := I.locallyCompactSpace haveI : LocallyCompactSpace M := ChartedSpace.locallyCompactSpace H M -- Next we choose a covering by supports of smooth bump functions have hB := fun x hx => SmoothBumpFunction.nhds_basis_support (I := I) (hU x hx) rcases refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set hs hB with ⟨ι, c, f, hf, hsub', hfin⟩ choose hcs hfU using hf -- Then we use the shrinking lemma to get a covering by smaller open rcases exists_subset_iUnion_closed_subset hs (fun i => (f i).isOpen_support) (fun x _ => hfin.point_finite x) hsub' with ⟨V, hsV, hVc, hVf⟩ choose r hrR hr using fun i => (f i).exists_r_pos_lt_subset_ball (hVc i) (hVf i) refine ⟨ι, ⟨c, fun i => (f i).updateRIn (r i) (hrR i), hcs, ?_, fun x hx => ?_⟩, fun i => ?_⟩ · simpa only [SmoothBumpFunction.support_updateRIn] · refine (mem_iUnion.1 <| hsV hx).imp fun i hi => ?_ exact ((f i).updateRIn _ _).eventuallyEq_one_of_dist_lt ((f i).support_subset_source <| hVf _ hi) (hr i hi).2 · simpa only [SmoothBumpFunction.support_updateRIn, tsupport] using hfU i protected theorem locallyFinite : LocallyFinite fun i => support (fs i) := fs.locallyFinite' protected theorem point_finite (x : M) : {i | fs i x ≠ 0}.Finite := fs.locallyFinite.point_finite x /-- Index of a bump function such that `fs i =ᶠ[𝓝 x] 1`. -/ def ind (x : M) (hx : x ∈ s) : ι := (fs.eventuallyEq_one' x hx).choose theorem eventuallyEq_one (x : M) (hx : x ∈ s) : fs (fs.ind x hx) =ᶠ[𝓝 x] 1 := (fs.eventuallyEq_one' x hx).choose_spec theorem apply_ind (x : M) (hx : x ∈ s) : fs (fs.ind x hx) x = 1 := (fs.eventuallyEq_one x hx).eq_of_nhds theorem mem_support_ind (x : M) (hx : x ∈ s) : x ∈ support (fs <| fs.ind x hx) := by simp [fs.apply_ind x hx] theorem mem_chartAt_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) : x ∈ (chartAt H (fs.c i)).source := (fs i).support_subset_source <| by simp [h] theorem mem_extChartAt_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) : x ∈ (extChartAt I (fs.c i)).source := by rw [extChartAt_source]; exact fs.mem_chartAt_source_of_eq_one h theorem mem_chartAt_ind_source (x : M) (hx : x ∈ s) : x ∈ (chartAt H (fs.c (fs.ind x hx))).source := fs.mem_chartAt_source_of_eq_one (fs.apply_ind x hx) theorem mem_extChartAt_ind_source (x : M) (hx : x ∈ s) : x ∈ (extChartAt I (fs.c (fs.ind x hx))).source := fs.mem_extChartAt_source_of_eq_one (fs.apply_ind x hx) /-- The index type of a `SmoothBumpCovering` of a compact manifold is finite. -/ protected def fintype [CompactSpace M] : Fintype ι := fs.locallyFinite.fintypeOfCompact fun i => (fs i).nonempty_support variable [T2Space M] variable [IsManifold I ∞ M] /-- Reinterpret a `SmoothBumpCovering` as a continuous `BumpCovering`. Note that not every `f : BumpCovering ι M s` with smooth functions `f i` is a `SmoothBumpCovering`. -/ def toBumpCovering : BumpCovering ι M s where toFun i := ⟨fs i, (fs i).continuous⟩ locallyFinite' := fs.locallyFinite nonneg' i _ := (fs i).nonneg le_one' i _ := (fs i).le_one eventuallyEq_one' := fs.eventuallyEq_one' @[simp] theorem isSubordinate_toBumpCovering {f : SmoothBumpCovering ι I M s} {U : M → Set M} : (f.toBumpCovering.IsSubordinate fun i => U (f.c i)) ↔ f.IsSubordinate U := Iff.rfl alias ⟨_, IsSubordinate.toBumpCovering⟩ := isSubordinate_toBumpCovering /-- Every `SmoothBumpCovering` defines a smooth partition of unity. -/ def toSmoothPartitionOfUnity : SmoothPartitionOfUnity ι I M s := fs.toBumpCovering.toSmoothPartitionOfUnity fun i => (fs i).contMDiff theorem toSmoothPartitionOfUnity_apply (i : ι) (x : M) : fs.toSmoothPartitionOfUnity i x = fs i x * ∏ᶠ (j) (_ : WellOrderingRel j i), (1 - fs j x) := rfl open Classical in theorem toSmoothPartitionOfUnity_eq_mul_prod (i : ι) (x : M) (t : Finset ι) (ht : ∀ j, WellOrderingRel j i → fs j x ≠ 0 → j ∈ t) : fs.toSmoothPartitionOfUnity i x = fs i x * ∏ j ∈ t with WellOrderingRel j i, (1 - fs j x) := fs.toBumpCovering.toPartitionOfUnity_eq_mul_prod i x t ht open Classical in theorem exists_finset_toSmoothPartitionOfUnity_eventuallyEq (i : ι) (x : M) : ∃ t : Finset ι, fs.toSmoothPartitionOfUnity i =ᶠ[𝓝 x] fs i * ∏ j ∈ t with WellOrderingRel j i, ((1 : M → ℝ) - fs j) := by simpa using fs.toBumpCovering.exists_finset_toPartitionOfUnity_eventuallyEq i x theorem toSmoothPartitionOfUnity_zero_of_zero {i : ι} {x : M} (h : fs i x = 0) : fs.toSmoothPartitionOfUnity i x = 0 := fs.toBumpCovering.toPartitionOfUnity_zero_of_zero h theorem support_toSmoothPartitionOfUnity_subset (i : ι) : support (fs.toSmoothPartitionOfUnity i) ⊆ support (fs i) := fs.toBumpCovering.support_toPartitionOfUnity_subset i theorem IsSubordinate.toSmoothPartitionOfUnity {f : SmoothBumpCovering ι I M s} {U : M → Set M} (h : f.IsSubordinate U) : f.toSmoothPartitionOfUnity.IsSubordinate fun i => U (f.c i) := h.toBumpCovering.toPartitionOfUnity theorem sum_toSmoothPartitionOfUnity_eq (x : M) : ∑ᶠ i, fs.toSmoothPartitionOfUnity i x = 1 - ∏ᶠ i, (1 - fs i x) := fs.toBumpCovering.sum_toPartitionOfUnity_eq x end SmoothBumpCovering variable (I) variable [FiniteDimensional ℝ E] variable [IsManifold I ∞ M] /-- Given two disjoint closed sets `s, t` in a Hausdorff σ-compact finite-dimensional manifold, there exists an infinitely smooth function that is equal to `0` on `s` and to `1` on `t`. See also `exists_msmooth_zero_iff_one_iff_of_isClosed`, which ensures additionally that `f` is equal to `0` exactly on `s` and to `1` exactly on `t`. -/ theorem exists_smooth_zero_one_of_isClosed [T2Space M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc 0 1 := by have : ∀ x ∈ t, sᶜ ∈ 𝓝 x := fun x hx => hs.isOpen_compl.mem_nhds (disjoint_right.1 hd hx) rcases SmoothBumpCovering.exists_isSubordinate I ht this with ⟨ι, f, hf⟩ set g := f.toSmoothPartitionOfUnity refine ⟨⟨_, g.contMDiff_sum⟩, fun x hx => ?_, fun x => g.sum_eq_one, fun x => ⟨g.sum_nonneg x, g.sum_le_one x⟩⟩ suffices ∀ i, g i x = 0 by simp only [this, ContMDiffMap.coeFn_mk, finsum_zero, Pi.zero_apply] refine fun i => f.toSmoothPartitionOfUnity_zero_of_zero ?_ exact notMem_support.1 (subset_compl_comm.1 (hf.support_subset i) hx) /-- Given two disjoint closed sets `s, t` in a Hausdorff normal σ-compact finite-dimensional manifold `M`, there exists a smooth function `f : M → [0,1]` that vanishes in a neighbourhood of `s` and is equal to `1` in a neighbourhood of `t`. -/ theorem exists_smooth_zero_one_nhds_of_isClosed [T2Space M] [NormalSpace M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, (∀ᶠ x in 𝓝ˢ s, f x = 0) ∧ (∀ᶠ x in 𝓝ˢ t, f x = 1) ∧ ∀ x, f x ∈ Icc 0 1 := by obtain ⟨u, u_op, hsu, hut⟩ := normal_exists_closure_subset hs ht.isOpen_compl (subset_compl_iff_disjoint_left.mpr hd.symm) obtain ⟨v, v_op, htv, hvu⟩ := normal_exists_closure_subset ht isClosed_closure.isOpen_compl (subset_compl_comm.mp hut) obtain ⟨f, hfu, hfv, hf⟩ := exists_smooth_zero_one_of_isClosed I isClosed_closure isClosed_closure (subset_compl_iff_disjoint_left.mp hvu) refine ⟨f, ?_, ?_, hf⟩ · exact eventually_of_mem (mem_of_superset (u_op.mem_nhdsSet.mpr hsu) subset_closure) hfu · exact eventually_of_mem (mem_of_superset (v_op.mem_nhdsSet.mpr htv) subset_closure) hfv /-- Given two sets `s, t` in a Hausdorff normal σ-compact finite-dimensional manifold `M` with `s` open and `s ⊆ interior t`, there is a smooth function `f : M → [0,1]` which is equal to `s` in a neighbourhood of `s` and has support contained in `t`. -/ theorem exists_smooth_one_nhds_of_subset_interior [T2Space M] [NormalSpace M] [SigmaCompactSpace M] {s t : Set M} (hs : IsClosed s) (hd : s ⊆ interior t) : ∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, (∀ᶠ x in 𝓝ˢ s, f x = 1) ∧ (∀ x ∉ t, f x = 0) ∧ ∀ x, f x ∈ Icc 0 1 := by rcases exists_smooth_zero_one_nhds_of_isClosed I isOpen_interior.isClosed_compl hs (by rwa [← subset_compl_iff_disjoint_left, compl_compl]) with ⟨f, h0, h1, hf⟩ refine ⟨f, h1, fun x hx ↦ ?_, hf⟩ exact h0.self_of_nhdsSet _ fun hx' ↦ hx <| interior_subset hx' namespace SmoothPartitionOfUnity /-- A `SmoothPartitionOfUnity` that consists of a single function, uniformly equal to one, defined as an example for `Inhabited` instance. -/ def single (i : ι) (s : Set M) : SmoothPartitionOfUnity ι I M s := (BumpCovering.single i s).toSmoothPartitionOfUnity fun j => by classical rcases eq_or_ne j i with (rfl | h) · simp only [contMDiff_one, ContinuousMap.coe_one, BumpCovering.coe_single, Pi.single_eq_same] · simp only [contMDiff_zero, BumpCovering.coe_single, Pi.single_eq_of_ne h, ContinuousMap.coe_zero] instance [Inhabited ι] (s : Set M) : Inhabited (SmoothPartitionOfUnity ι I M s) := ⟨single I default s⟩ variable [T2Space M] [SigmaCompactSpace M] /-- If `X` is a paracompact normal topological space and `U` is an open covering of a closed set `s`, then there exists a `SmoothPartitionOfUnity ι M s` that is subordinate to `U`. -/ theorem exists_isSubordinate {s : Set M} (hs : IsClosed s) (U : ι → Set M) (ho : ∀ i, IsOpen (U i)) (hU : s ⊆ ⋃ i, U i) : ∃ f : SmoothPartitionOfUnity ι I M s, f.IsSubordinate U := by haveI : LocallyCompactSpace H := I.locallyCompactSpace haveI : LocallyCompactSpace M := ChartedSpace.locallyCompactSpace H M -- porting note(https://github.com/leanprover-community/batteries/issues/116): -- split `rcases` into `have` + `rcases` have := BumpCovering.exists_isSubordinate_of_prop (ContMDiff I 𝓘(ℝ) ∞) ?_ hs U ho hU · rcases this with ⟨f, hf, hfU⟩ exact ⟨f.toSmoothPartitionOfUnity hf, hfU.toSmoothPartitionOfUnity hf⟩ · intro s t hs ht hd rcases exists_smooth_zero_one_of_isClosed I hs ht hd with ⟨f, hf⟩ exact ⟨f, f.contMDiff, hf⟩ theorem exists_isSubordinate_chartAt_source_of_isClosed {s : Set M} (hs : IsClosed s) : ∃ f : SmoothPartitionOfUnity s I M s, f.IsSubordinate (fun x ↦ (chartAt H (x : M)).source) := by apply exists_isSubordinate _ hs _ (fun i ↦ (chartAt H _).open_source) (fun x hx ↦ ?_) exact mem_iUnion_of_mem ⟨x, hx⟩ (mem_chart_source H x) variable (M) theorem exists_isSubordinate_chartAt_source : ∃ f : SmoothPartitionOfUnity M I M univ, f.IsSubordinate (fun x ↦ (chartAt H x).source) := by apply exists_isSubordinate _ isClosed_univ _ (fun i ↦ (chartAt H _).open_source) (fun x _ ↦ ?_) exact mem_iUnion_of_mem x (mem_chart_source H x) end SmoothPartitionOfUnity variable [SigmaCompactSpace M] [T2Space M] {t : M → Set F} {n : ℕ∞} /-- Let `V` be a vector bundle over a σ-compact Hausdorff finite-dimensional topological manifold `M`. Let `t : M → Set (V x)` be a family of convex sets in the fibers of `V`. Suppose that for each point `x₀ : M` there exists a neighborhood `U_x₀` of `x₀` and a local section `s_loc : M → V x` such that `s_loc` is $C^n$ smooth on `U_x₀` (when viewed as a map to the total space of the bundle) and `s_loc y ∈ t y` for all `y ∈ U_x₀`. Then there exists a global $C^n$ smooth section `s : Cₛ^n⟮I_M; F_fiber, V⟯` such that `s x ∈ t x` for all `x : M`. -/ theorem exists_contMDiffOn_section_forall_mem_convex_of_local {F_fiber : Type*} [NormedAddCommGroup F_fiber] [NormedSpace ℝ F_fiber] (V : M → Type*) [∀ x, AddCommGroup (V x)] [∀ x, TopologicalSpace (V x)] [∀ x, Module ℝ (V x)] [TopologicalSpace (TotalSpace F_fiber V)] [FiberBundle F_fiber V] [VectorBundle ℝ F_fiber V] (t : ∀ x, Set (V x)) (ht_conv : ∀ x, Convex ℝ (t x)) (Hloc : ∀ x₀ : M, ∃ U_x₀ ∈ 𝓝 x₀, ∃ (s_loc : (x : M) → V x), (ContMDiffOn I (I.prod 𝓘(ℝ, F_fiber)) n (fun x ↦ TotalSpace.mk' F_fiber x (s_loc x)) U_x₀) ∧ (∀ y ∈ U_x₀, s_loc y ∈ t y)) : ∃ s : Cₛ^n⟮I; F_fiber, V⟯, ∀ x : M, s x ∈ t x := by choose W h_nhds s_loc s_smooth h_mem_t using Hloc -- Construct an open cover from the interiors of the given neighborhoods. let U (x : M) : Set M := interior (W x) have hU_covers_univ : univ ⊆ ⋃ x, U x := by intro x_pt _ simp only [mem_iUnion] exact ⟨x_pt, mem_interior_iff_mem_nhds.mpr (h_nhds x_pt)⟩ -- Obtain a smooth partition of unity subordinate to this open cover. obtain ⟨ρ, hρU⟩ : ∃ ρ : SmoothPartitionOfUnity M I M univ, ρ.IsSubordinate U := SmoothPartitionOfUnity.exists_isSubordinate I isClosed_univ U (fun x ↦ isOpen_interior) hU_covers_univ -- Define the global section `s` by taking a weighted sum of the local sections. let s x : V x := ∑ᶠ j, (ρ j x) • s_loc j x -- Prove that `s`, when viewed as a map to the total space, is smooth. have (j : M) : ContMDiff I (I.prod 𝓘(ℝ, F_fiber)) n (fun x ↦ TotalSpace.mk' F_fiber x ((ρ j x) • (s_loc j x))) := by refine ContMDiffOn.smul_section_of_tsupport ?_ isOpen_interior (hρU j) ((s_smooth j).mono interior_subset) exact ((ρ j).contMDiff).of_le (sup_eq_left.mp rfl) |>.contMDiffOn have hs : ContMDiff I (I.prod 𝓘(ℝ, F_fiber)) n (fun x ↦ TotalSpace.mk' F_fiber x (s x)) := by apply ContMDiff.finsum_section_of_locallyFinite ?_ this -- Future: can grind do this? apply ρ.locallyFinite.subset fun i x hx ↦ ?_ rw [support] rw [mem_setOf_eq] at hx ⊢ exact left_ne_zero_of_smul hx -- Construct the smooth section and prove it lies in the convex sets `t x`. refine ⟨⟨s, hs⟩, fun x ↦ ?_⟩ apply (ht_conv x).finsum_mem (ρ.nonneg · x) (ρ.sum_eq_one (mem_univ x)) intro j h_ρjx_ne_zero have h_x_in_tsupport_ρj : x ∈ tsupport (ρ j) := subset_closure (mem_support.mpr h_ρjx_ne_zero) have h_x_in_Umap_j : x ∈ W j := interior_subset (hρU j h_x_in_tsupport_ρj) exact h_mem_t j x h_x_in_Umap_j /-- Let `V` be a vector bundle over a σ-compact Hausdorff finite-dimensional topological manifold `M`. Let `t : M → Set (V x)` be a family of convex sets in the fibers of `V`. Suppose that for each point `x₀ : M` there exists a neighborhood `U_x₀` of `x₀` and a local section `s_loc : M → V x` such that `s_loc` is $C^∞$ smooth on `U_x₀` (when viewed as a map to the total space of the bundle) and `s_loc y ∈ t y` for all `y ∈ U_x₀`. Then there exists a global smooth section `s : Cₛ^∞⟮I_M; F_fiber, V⟯` such that `s x ∈ t x` for all `x : M`. -/ theorem exists_smooth_section_forall_mem_convex_of_local {F_fiber : Type*} [NormedAddCommGroup F_fiber] [NormedSpace ℝ F_fiber] (V : M → Type*) [∀ x, NormedAddCommGroup (V x)] [∀ x, Module ℝ (V x)] [TopologicalSpace (TotalSpace F_fiber V)] [FiberBundle F_fiber V] [VectorBundle ℝ F_fiber V] (t : ∀ x, Set (V x)) (ht_conv : ∀ x, Convex ℝ (t x)) (Hloc : ∀ x₀ : M, ∃ U_x₀ ∈ 𝓝 x₀, ∃ (s_loc : (x : M) → V x), (ContMDiffOn I (I.prod 𝓘(ℝ, F_fiber)) ∞ (fun x ↦ TotalSpace.mk' F_fiber x (s_loc x)) U_x₀) ∧ (∀ y ∈ U_x₀, s_loc y ∈ t y)) : ∃ s : Cₛ^∞⟮I; F_fiber, V⟯, ∀ x : M, s x ∈ t x := exists_contMDiffOn_section_forall_mem_convex_of_local I V t ht_conv Hloc /-- Let `M` be a σ-compact Hausdorff finite-dimensional topological manifold. Let `t : M → Set F` be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood `U ∈ 𝓝 x` and a function `g : M → F` such that `g` is $C^n$ smooth on `U` and `g y ∈ t y` for all `y ∈ U`. Then there exists a $C^n$ smooth function `g : C^n⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`. This is a special case of `exists_contMDiffOn_section_forall_mem_convex_of_local` where `V` is the trivial bundle. See also `exists_smooth_forall_mem_convex_of_local` and `exists_smooth_forall_mem_convex_of_local_const`. -/ theorem exists_contMDiffOn_forall_mem_convex_of_local (ht : ∀ x, Convex ℝ (t x)) (Hloc : ∀ x : M, ∃ U ∈ 𝓝 x, ∃ g : M → F, ContMDiffOn I 𝓘(ℝ, F) n g U ∧ ∀ y ∈ U, g y ∈ t y) : ∃ g : C^n⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x := let ⟨s, hs⟩ := exists_contMDiffOn_section_forall_mem_convex_of_local I (fun _ ↦ F) t ht (fun x₀ ↦ let ⟨U, hU, g, hgs, hgt⟩ := Hloc x₀ ⟨U, hU, g, fun y hy ↦ Bundle.contMDiffWithinAt_section |>.mpr <| hgs y hy, hgt⟩) ⟨⟨s, (Bundle.contMDiffAt_section _ |>.mp <| s.contMDiff ·)⟩, hs⟩ /-- Let `M` be a σ-compact Hausdorff finite-dimensional topological manifold. Let `t : M → Set F` be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood `U ∈ 𝓝 x` and a function `g : M → F` such that `g` is smooth on `U` and `g y ∈ t y` for all `y ∈ U`. Then there exists a smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`. This is a special case of `exists_smooth_section_forall_mem_convex_of_local` where `V` is the trivial bundle. See also `exists_contMDiffOn_forall_mem_convex_of_local` and `exists_smooth_forall_mem_convex_of_local_const`. -/ theorem exists_smooth_forall_mem_convex_of_local (ht : ∀ x, Convex ℝ (t x)) (Hloc : ∀ x : M, ∃ U ∈ 𝓝 x, ∃ g : M → F, ContMDiffOn I 𝓘(ℝ, F) ∞ g U ∧ ∀ y ∈ U, g y ∈ t y) : ∃ g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x := exists_contMDiffOn_forall_mem_convex_of_local I ht Hloc /-- Let `M` be a σ-compact Hausdorff finite-dimensional topological manifold. Let `t : M → Set F` be a family of convex sets. Suppose that for each point `x : M` there exists a vector `c : F` such that for all `y` in a neighborhood of `x` we have `c ∈ t y`. Then there exists a smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`. See also `exists_contMDiffOn_forall_mem_convex_of_local` and `exists_smooth_forall_mem_convex_of_local`. -/ theorem exists_smooth_forall_mem_convex_of_local_const (ht : ∀ x, Convex ℝ (t x)) (Hloc : ∀ x : M, ∃ c : F, ∀ᶠ y in 𝓝 x, c ∈ t y) : ∃ g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x := exists_smooth_forall_mem_convex_of_local I ht fun x => let ⟨c, hc⟩ := Hloc x ⟨_, hc, fun _ => c, contMDiffOn_const, fun _ => id⟩ /-- Let `M` be a smooth σ-compact manifold with extended distance. Let `K : ι → Set M` be a locally finite family of closed sets, let `U : ι → Set M` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive smooth function `δ : M → ℝ≥0` such that for any `i` and `x ∈ K i`, we have `EMetric.closedBall x (δ x) ⊆ U i`. -/ theorem Emetric.exists_smooth_forall_closedBall_subset {M} [EMetricSpace M] [ChartedSpace H M] [IsManifold I ∞ M] [SigmaCompactSpace M] {K : ι → Set M} {U : ι → Set M} (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C^∞⟮I, M; 𝓘(ℝ, ℝ), ℝ⟯, (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, EMetric.closedBall x (ENNReal.ofReal (δ x)) ⊆ U i := by simpa only [mem_inter_iff, forall_and, mem_preimage, mem_iInter, @forall_swap ι M] using exists_smooth_forall_mem_convex_of_local_const I EMetric.exists_forall_closedBall_subset_aux₂ (EMetric.exists_forall_closedBall_subset_aux₁ hK hU hKU hfin) /-- Let `M` be a smooth σ-compact manifold with a metric. Let `K : ι → Set M` be a locally finite family of closed sets, let `U : ι → Set M` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive smooth function `δ : M → ℝ≥0` such that for any `i` and `x ∈ K i`, we have `Metric.closedBall x (δ x) ⊆ U i`. -/ theorem Metric.exists_smooth_forall_closedBall_subset {M} [MetricSpace M] [ChartedSpace H M] [IsManifold I ∞ M] [SigmaCompactSpace M] {K : ι → Set M} {U : ι → Set M} (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C^∞⟮I, M; 𝓘(ℝ, ℝ), ℝ⟯, (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, Metric.closedBall x (δ x) ⊆ U i := by rcases Emetric.exists_smooth_forall_closedBall_subset I hK hU hKU hfin with ⟨δ, hδ0, hδ⟩ refine ⟨δ, hδ0, fun i x hx => ?_⟩ rw [← Metric.emetric_closedBall (hδ0 _).le] exact hδ i x hx lemma IsOpen.exists_msmooth_support_eq_aux {s : Set H} (hs : IsOpen s) : ∃ f : H → ℝ, f.support = s ∧ ContMDiff I 𝓘(ℝ) ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 := by have h's : IsOpen (I.symm ⁻¹' s) := I.continuous_symm.isOpen_preimage _ hs rcases h's.exists_smooth_support_eq with ⟨f, f_supp, f_diff, f_range⟩ refine ⟨f ∘ I, ?_, ?_, ?_⟩ · rw [support_comp_eq_preimage, f_supp, ← preimage_comp] simp only [ModelWithCorners.symm_comp_self, preimage_id_eq, id_eq] · exact f_diff.comp_contMDiff contMDiff_model · exact Subset.trans (range_comp_subset_range _ _) f_range /-- Given an open set in a finite-dimensional real manifold, there exists a nonnegative smooth function with support equal to `s`. -/ theorem IsOpen.exists_msmooth_support_eq {s : Set M} (hs : IsOpen s) : ∃ f : M → ℝ, f.support = s ∧ ContMDiff I 𝓘(ℝ) ∞ f ∧ ∀ x, 0 ≤ f x := by rcases SmoothPartitionOfUnity.exists_isSubordinate_chartAt_source I M with ⟨f, hf⟩ have A : ∀ (c : M), ∃ g : H → ℝ, g.support = (chartAt H c).target ∩ (chartAt H c).symm ⁻¹' s ∧ ContMDiff I 𝓘(ℝ) ∞ g ∧ Set.range g ⊆ Set.Icc 0 1 := by intro i apply IsOpen.exists_msmooth_support_eq_aux exact OpenPartialHomeomorph.isOpen_inter_preimage_symm _ hs choose g g_supp g_diff hg using A have h'g : ∀ c x, 0 ≤ g c x := fun c x ↦ (hg c (mem_range_self (f := g c) x)).1 have h''g : ∀ c x, 0 ≤ f c x * g c (chartAt H c x) := fun c x ↦ mul_nonneg (f.nonneg c x) (h'g c _) refine ⟨fun x ↦ ∑ᶠ c, f c x * g c (chartAt H c x), ?_, ?_, ?_⟩ · refine support_eq_iff.2 ⟨fun x hx ↦ ?_, fun x hx ↦ ?_⟩ · apply ne_of_gt have B : ∃ c, 0 < f c x * g c (chartAt H c x) := by obtain ⟨c, hc⟩ : ∃ c, 0 < f c x := f.exists_pos_of_mem (mem_univ x) refine ⟨c, mul_pos hc ?_⟩ apply lt_of_le_of_ne (h'g _ _) (Ne.symm _) rw [← mem_support, g_supp, ← mem_preimage, preimage_inter] have Hx : x ∈ tsupport (f c) := subset_tsupport _ (ne_of_gt hc) simp [(chartAt H c).left_inv (hf c Hx), hx, (chartAt H c).map_source (hf c Hx)] apply finsum_pos' (fun c ↦ h''g c x) B apply (f.locallyFinite.point_finite x).subset apply compl_subset_compl.2 rintro c (hc : f c x = 0) simpa only [mul_eq_zero] using Or.inl hc · apply finsum_eq_zero_of_forall_eq_zero intro c by_cases Hx : x ∈ tsupport (f c) · suffices g c (chartAt H c x) = 0 by simp only [this, mul_zero] rw [← notMem_support, g_supp, ← mem_preimage, preimage_inter] contrapose! hx simp only [mem_inter_iff, mem_preimage, (chartAt H c).left_inv (hf c Hx)] at hx exact hx.2 · have : x ∉ support (f c) := by contrapose! Hx; exact subset_tsupport _ Hx rw [notMem_support] at this simp [this] · apply SmoothPartitionOfUnity.contMDiff_finsum_smul intro c x hx apply (g_diff c (chartAt H c x)).comp exact contMDiffAt_of_mem_maximalAtlas (IsManifold.chart_mem_maximalAtlas _) (hf c hx) · intro x apply finsum_nonneg (fun c ↦ h''g c x) /-- Given an open set `s` containing a closed set `t` in a finite-dimensional real manifold, there exists a smooth function with support equal to `s`, taking values in `[0,1]`, and equal to `1` exactly on `t`. -/ theorem exists_msmooth_support_eq_eq_one_iff {s t : Set M} (hs : IsOpen s) (ht : IsClosed t) (h : t ⊆ s) : ∃ f : M → ℝ, ContMDiff I 𝓘(ℝ) ∞ f ∧ range f ⊆ Icc 0 1 ∧ support f = s ∧ (∀ x, x ∈ t ↔ f x = 1) := by /- Take `f` with support equal to `s`, and `g` with support equal to `tᶜ`. Then `f / (f + g)` satisfies the conclusion of the theorem. -/ rcases hs.exists_msmooth_support_eq I with ⟨f, f_supp, f_diff, f_pos⟩ rcases ht.isOpen_compl.exists_msmooth_support_eq I with ⟨g, g_supp, g_diff, g_pos⟩ have A : ∀ x, 0 < f x + g x := by intro x by_cases xs : x ∈ support f · have : 0 < f x := lt_of_le_of_ne (f_pos x) (Ne.symm xs) linarith [g_pos x] · have : 0 < g x := by classical apply lt_of_le_of_ne (g_pos x) (Ne.symm ?_) rw [← mem_support, g_supp] contrapose! xs exact h.trans f_supp.symm.subset (by simpa using xs) linarith [f_pos x] refine ⟨fun x ↦ f x / (f x + g x), ?_, ?_, ?_, ?_⟩ -- show that `f / (f + g)` is smooth · exact f_diff.div₀ (f_diff.add g_diff) (fun x ↦ ne_of_gt (A x)) -- show that the range is included in `[0, 1]` · refine range_subset_iff.2 (fun x ↦ ⟨div_nonneg (f_pos x) (A x).le, ?_⟩) apply div_le_one_of_le₀ _ (A x).le simpa only [le_add_iff_nonneg_right] using g_pos x -- show that the support is `s` · have B : support (fun x ↦ f x + g x) = univ := eq_univ_of_forall (fun x ↦ (A x).ne') simp only [support_div, f_supp, B, inter_univ] -- show that the function equals one exactly on `t` · intro x simp [div_eq_one_iff_eq (A x).ne', left_eq_add, ← notMem_support, g_supp] /-- Given two disjoint closed sets `s, t` in a Hausdorff σ-compact finite-dimensional manifold, there exists an infinitely smooth function that is equal to `0` exactly on `s` and to `1` exactly on `t`. See also `exists_smooth_zero_one_of_isClosed` for a slightly weaker version. -/ theorem exists_msmooth_zero_iff_one_iff_of_isClosed {s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : M → ℝ, ContMDiff I 𝓘(ℝ) ∞ f ∧ range f ⊆ Icc 0 1 ∧ (∀ x, x ∈ s ↔ f x = 0) ∧ (∀ x, x ∈ t ↔ f x = 1) := by rcases exists_msmooth_support_eq_eq_one_iff I hs.isOpen_compl ht hd.subset_compl_left with ⟨f, f_diff, f_range, fs, ft⟩ refine ⟨f, f_diff, f_range, ?_, ft⟩ simp [← notMem_support, fs]
.lake/packages/mathlib/Mathlib/Geometry/Manifold/LocalInvariantProperties.lean
import Mathlib.Geometry.Manifold.ChartedSpace /-! # Local properties invariant under a groupoid We study properties of a triple `(g, s, x)` where `g` is a function between two spaces `H` and `H'`, `s` is a subset of `H` and `x` is a point of `H`. Our goal is to register how such a property should behave to make sense in charted spaces modelled on `H` and `H'`. The main examples we have in mind are the properties "`g` is differentiable at `x` within `s`", or "`g` is smooth at `x` within `s`". We want to develop general results that, when applied in these specific situations, say that the notion of smooth function in a manifold behaves well under restriction, intersection, is local, and so on. ## Main definitions * `LocalInvariantProp G G' P` says that a property `P` of a triple `(g, s, x)` is local, and invariant under composition by elements of the groupoids `G` and `G'` of `H` and `H'` respectively. * `ChartedSpace.LiftPropWithinAt` (resp. `LiftPropAt`, `LiftPropOn` and `LiftProp`): given a property `P` of `(g, s, x)` where `g : H → H'`, define the corresponding property for functions `M → M'` where `M` and `M'` are charted spaces modelled respectively on `H` and `H'`. We define these properties within a set at a point, or at a point, or on a set, or in the whole space. This lifting process (obtained by restricting to suitable chart domains) can always be done, but it only behaves well under locality and invariance assumptions. Given `hG : LocalInvariantProp G G' P`, we deduce many properties of the lifted property on the charted spaces. For instance, `hG.liftPropWithinAt_inter` says that `P g s x` is equivalent to `P g (s ∩ t) x` whenever `t` is a neighborhood of `x`. ## Implementation notes We do not use dot notation for properties of the lifted property. For instance, we have `hG.liftPropWithinAt_congr` saying that if `LiftPropWithinAt P g s x` holds, and `g` and `g'` coincide on `s`, then `LiftPropWithinAt P g' s x` holds. We can't call it `LiftPropWithinAt.congr` as it is in the namespace associated to `LocalInvariantProp`, not in the one for `LiftPropWithinAt`. -/ noncomputable section open Set Filter TopologicalSpace open scoped Manifold Topology variable {H M H' M' X : Type*} variable [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] variable [TopologicalSpace H'] [TopologicalSpace M'] [ChartedSpace H' M'] variable [TopologicalSpace X] namespace StructureGroupoid variable (G : StructureGroupoid H) (G' : StructureGroupoid H') /-- Structure recording good behavior of a property of a triple `(f, s, x)` where `f` is a function, `s` a set and `x` a point. Good behavior here means locality and invariance under given groupoids (both in the source and in the target). Given such a good behavior, the lift of this property to charted spaces admitting these groupoids will inherit the good behavior. -/ structure LocalInvariantProp (P : (H → H') → Set H → H → Prop) : Prop where is_local : ∀ {s x u} {f : H → H'}, IsOpen u → x ∈ u → (P f s x ↔ P f (s ∩ u) x) right_invariance' : ∀ {s x f} {e : OpenPartialHomeomorph H H}, e ∈ G → x ∈ e.source → P f s x → P (f ∘ e.symm) (e.symm ⁻¹' s) (e x) congr_of_forall : ∀ {s x} {f g : H → H'}, (∀ y ∈ s, f y = g y) → f x = g x → P f s x → P g s x left_invariance' : ∀ {s x f} {e' : OpenPartialHomeomorph H' H'}, e' ∈ G' → s ⊆ f ⁻¹' e'.source → f x ∈ e'.source → P f s x → P (e' ∘ f) s x variable {G G'} {P : (H → H') → Set H → H → Prop} variable (hG : G.LocalInvariantProp G' P) include hG namespace LocalInvariantProp theorem congr_set {s t : Set H} {x : H} {f : H → H'} (hu : s =ᶠ[𝓝 x] t) : P f s x ↔ P f t x := by obtain ⟨o, host, ho, hxo⟩ := mem_nhds_iff.mp hu.mem_iff simp_rw [subset_def, mem_setOf, ← and_congr_left_iff, ← mem_inter_iff, ← Set.ext_iff] at host rw [hG.is_local ho hxo, host, ← hG.is_local ho hxo] theorem is_local_nhds {s u : Set H} {x : H} {f : H → H'} (hu : u ∈ 𝓝[s] x) : P f s x ↔ P f (s ∩ u) x := hG.congr_set <| mem_nhdsWithin_iff_eventuallyEq.mp hu theorem congr_iff_nhdsWithin {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) : P f s x ↔ P g s x := by simp_rw [hG.is_local_nhds h1] exact ⟨hG.congr_of_forall (fun y hy ↦ hy.2) h2, hG.congr_of_forall (fun y hy ↦ hy.2.symm) h2.symm⟩ theorem congr_nhdsWithin {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) (hP : P f s x) : P g s x := (hG.congr_iff_nhdsWithin h1 h2).mp hP theorem congr_nhdsWithin' {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) (hP : P g s x) : P f s x := (hG.congr_iff_nhdsWithin h1 h2).mpr hP theorem congr_iff {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) : P f s x ↔ P g s x := hG.congr_iff_nhdsWithin (mem_nhdsWithin_of_mem_nhds h) (mem_of_mem_nhds h :) theorem congr {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P f s x) : P g s x := (hG.congr_iff h).mp hP theorem congr' {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P g s x) : P f s x := hG.congr h.symm hP theorem left_invariance {s : Set H} {x : H} {f : H → H'} {e' : OpenPartialHomeomorph H' H'} (he' : e' ∈ G') (hfs : ContinuousWithinAt f s x) (hxe' : f x ∈ e'.source) : P (e' ∘ f) s x ↔ P f s x := by have h2f := hfs.preimage_mem_nhdsWithin (e'.open_source.mem_nhds hxe') have h3f := ((e'.continuousAt hxe').comp_continuousWithinAt hfs).preimage_mem_nhdsWithin <| e'.symm.open_source.mem_nhds <| e'.mapsTo hxe' constructor · intro h rw [hG.is_local_nhds h3f] at h have h2 := hG.left_invariance' (G'.symm he') inter_subset_right (e'.mapsTo hxe') h rw [← hG.is_local_nhds h3f] at h2 refine hG.congr_nhdsWithin ?_ (e'.left_inv hxe') h2 exact eventually_of_mem h2f fun x' ↦ e'.left_inv · simp_rw [hG.is_local_nhds h2f] exact hG.left_invariance' he' inter_subset_right hxe' theorem right_invariance {s : Set H} {x : H} {f : H → H'} {e : OpenPartialHomeomorph H H} (he : e ∈ G) (hxe : x ∈ e.source) : P (f ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P f s x := by refine ⟨fun h ↦ ?_, hG.right_invariance' he hxe⟩ have := hG.right_invariance' (G.symm he) (e.mapsTo hxe) h rw [e.symm_symm, e.left_inv hxe] at this refine hG.congr ?_ ((hG.congr_set ?_).mp this) · refine eventually_of_mem (e.open_source.mem_nhds hxe) fun x' hx' ↦ ?_ simp_rw [Function.comp_apply, e.left_inv hx'] · rw [eventuallyEq_set] refine eventually_of_mem (e.open_source.mem_nhds hxe) fun x' hx' ↦ ?_ simp_rw [mem_preimage, e.left_inv hx'] end LocalInvariantProp end StructureGroupoid namespace ChartedSpace /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property in a charted space, by requiring that it holds at the preferred chart at this point. (When the property is local and invariant, it will in fact hold using any chart, see `liftPropWithinAt_indep_chart`). We require continuity in the lifted property, as otherwise one single chart might fail to capture the behavior of the function. -/ @[mk_iff liftPropWithinAt_iff'] structure LiftPropWithinAt (P : (H → H') → Set H → H → Prop) (f : M → M') (s : Set M) (x : M) : Prop where continuousWithinAt : ContinuousWithinAt f s x prop : P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) ((chartAt H x).symm ⁻¹' s) (chartAt H x x) /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property of functions on sets in a charted space, by requiring that it holds around each point of the set, in the preferred charts. -/ def LiftPropOn (P : (H → H') → Set H → H → Prop) (f : M → M') (s : Set M) := ∀ x ∈ s, LiftPropWithinAt P f s x /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property of a function at a point in a charted space, by requiring that it holds in the preferred chart. -/ def LiftPropAt (P : (H → H') → Set H → H → Prop) (f : M → M') (x : M) := LiftPropWithinAt P f univ x theorem liftPropAt_iff {P : (H → H') → Set H → H → Prop} {f : M → M'} {x : M} : LiftPropAt P f x ↔ ContinuousAt f x ∧ P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) univ (chartAt H x x) := by rw [LiftPropAt, liftPropWithinAt_iff', continuousWithinAt_univ, preimage_univ] /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property of a function in a charted space, by requiring that it holds in the preferred chart around every point. -/ def LiftProp (P : (H → H') → Set H → H → Prop) (f : M → M') := ∀ x, LiftPropAt P f x theorem liftProp_iff {P : (H → H') → Set H → H → Prop} {f : M → M'} : LiftProp P f ↔ Continuous f ∧ ∀ x, P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) univ (chartAt H x x) := by simp_rw [LiftProp, liftPropAt_iff, forall_and, continuous_iff_continuousAt] end ChartedSpace open ChartedSpace namespace StructureGroupoid variable {G : StructureGroupoid H} {G' : StructureGroupoid H'} {e e' : OpenPartialHomeomorph M H} {f f' : OpenPartialHomeomorph M' H'} {P : (H → H') → Set H → H → Prop} {g g' : M → M'} {s t : Set M} {x : M} {Q : (H → H) → Set H → H → Prop} theorem liftPropWithinAt_univ : LiftPropWithinAt P g univ x ↔ LiftPropAt P g x := Iff.rfl theorem liftPropOn_univ : LiftPropOn P g univ ↔ LiftProp P g := by simp [LiftPropOn, LiftProp, LiftPropAt] theorem liftPropWithinAt_self {f : H → H'} {s : Set H} {x : H} : LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P f s x := liftPropWithinAt_iff' .. theorem liftPropWithinAt_self_source {f : H → M'} {s : Set H} {x : H} : LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P (chartAt H' (f x) ∘ f) s x := liftPropWithinAt_iff' .. theorem liftPropWithinAt_self_target {f : M → H'} : LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P (f ∘ (chartAt H x).symm) ((chartAt H x).symm ⁻¹' s) (chartAt H x x) := liftPropWithinAt_iff' .. namespace LocalInvariantProp section variable (hG : G.LocalInvariantProp G' P) include hG /-- `LiftPropWithinAt P f s x` is equivalent to a definition where we restrict the set we are considering to the domain of the charts at `x` and `f x`. -/ theorem liftPropWithinAt_iff {f : M → M'} : LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) ((chartAt H x).target ∩ (chartAt H x).symm ⁻¹' (s ∩ f ⁻¹' (chartAt H' (f x)).source)) (chartAt H x x) := by rw [liftPropWithinAt_iff'] refine and_congr_right fun hf ↦ hG.congr_set ?_ exact OpenPartialHomeomorph.preimage_eventuallyEq_target_inter_preimage_inter hf (mem_chart_source H x) (chart_source_mem_nhds H' (f x)) theorem liftPropWithinAt_indep_chart_source_aux (g : M → H') (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (he' : e' ∈ G.maximalAtlas M) (xe' : x ∈ e'.source) : P (g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (g ∘ e'.symm) (e'.symm ⁻¹' s) (e' x) := by rw [← hG.right_invariance (compatible_of_mem_maximalAtlas he he')] swap; · simp only [xe, xe', mfld_simps] simp_rw [OpenPartialHomeomorph.trans_apply, e.left_inv xe] rw [hG.congr_iff] · refine hG.congr_set ?_ refine (eventually_of_mem ?_ fun y (hy : y ∈ e'.symm ⁻¹' e.source) ↦ ?_).set_eq · refine (e'.symm.continuousAt <| e'.mapsTo xe').preimage_mem_nhds (e.open_source.mem_nhds ?_) simp_rw [e'.left_inv xe', xe] simp_rw [mem_preimage, OpenPartialHomeomorph.coe_trans_symm, OpenPartialHomeomorph.symm_symm, Function.comp_apply, e.left_inv hy] · refine ((e'.eventually_nhds' _ xe').mpr <| e.eventually_left_inverse xe).mono fun y hy ↦ ?_ simp only [mfld_simps] rw [hy] theorem liftPropWithinAt_indep_chart_target_aux2 (g : H → M') {x : H} {s : Set H} (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) (hf' : f' ∈ G'.maximalAtlas M') (xf' : g x ∈ f'.source) (hgs : ContinuousWithinAt g s x) : P (f ∘ g) s x ↔ P (f' ∘ g) s x := by have hcont : ContinuousWithinAt (f ∘ g) s x := (f.continuousAt xf).comp_continuousWithinAt hgs rw [← hG.left_invariance (compatible_of_mem_maximalAtlas hf hf') hcont (by simp only [xf, xf', mfld_simps])] refine hG.congr_iff_nhdsWithin ?_ (by simp only [xf, mfld_simps]) exact (hgs.eventually <| f.eventually_left_inverse xf).mono fun y ↦ congr_arg f' theorem liftPropWithinAt_indep_chart_target_aux {g : X → M'} {e : OpenPartialHomeomorph X H} {x : X} {s : Set X} (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) (hf' : f' ∈ G'.maximalAtlas M') (xf' : g x ∈ f'.source) (hgs : ContinuousWithinAt g s x) : P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (f' ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by rw [← e.left_inv xe] at xf xf' hgs refine hG.liftPropWithinAt_indep_chart_target_aux2 (g ∘ e.symm) hf xf hf' xf' ?_ exact hgs.comp (e.symm.continuousAt <| e.mapsTo xe).continuousWithinAt Subset.rfl /-- If a property of a germ of function `g` on a pointed set `(s, x)` is invariant under the structure groupoid (by composition in the source space and in the target space), then expressing it in charted spaces does not depend on the element of the maximal atlas one uses both in the source and in the target manifolds, provided they are defined around `x` and `g x` respectively, and provided `g` is continuous within `s` at `x` (otherwise, the local behavior of `g` at `x` cannot be captured with a chart in the target). -/ theorem liftPropWithinAt_indep_chart_aux (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (he' : e' ∈ G.maximalAtlas M) (xe' : x ∈ e'.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) (hf' : f' ∈ G'.maximalAtlas M') (xf' : g x ∈ f'.source) (hgs : ContinuousWithinAt g s x) : P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (f' ∘ g ∘ e'.symm) (e'.symm ⁻¹' s) (e' x) := by rw [← Function.comp_assoc, hG.liftPropWithinAt_indep_chart_source_aux (f ∘ g) he xe he' xe', Function.comp_assoc, hG.liftPropWithinAt_indep_chart_target_aux xe' hf xf hf' xf' hgs] theorem liftPropWithinAt_indep_chart [HasGroupoid M G] [HasGroupoid M' G'] (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) : LiftPropWithinAt P g s x ↔ ContinuousWithinAt g s x ∧ P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by simp only [liftPropWithinAt_iff'] exact and_congr_right <| hG.liftPropWithinAt_indep_chart_aux (chart_mem_maximalAtlas _ _) (mem_chart_source _ _) he xe (chart_mem_maximalAtlas _ _) (mem_chart_source _ _) hf xf /-- A version of `liftPropWithinAt_indep_chart`, only for the source. -/ theorem liftPropWithinAt_indep_chart_source [HasGroupoid M G] (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) : LiftPropWithinAt P g s x ↔ LiftPropWithinAt P (g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by rw [liftPropWithinAt_self_source, liftPropWithinAt_iff', e.symm.continuousWithinAt_iff_continuousWithinAt_comp_right xe, e.symm_symm] refine and_congr Iff.rfl ?_ rw [Function.comp_apply, e.left_inv xe, ← Function.comp_assoc, hG.liftPropWithinAt_indep_chart_source_aux (chartAt _ (g x) ∘ g) (chart_mem_maximalAtlas G x) (mem_chart_source _ x) he xe, Function.comp_assoc] /-- A version of `liftPropWithinAt_indep_chart`, only for the target. -/ theorem liftPropWithinAt_indep_chart_target [HasGroupoid M' G'] (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) : LiftPropWithinAt P g s x ↔ ContinuousWithinAt g s x ∧ LiftPropWithinAt P (f ∘ g) s x := by rw [liftPropWithinAt_self_target, liftPropWithinAt_iff', and_congr_right_iff] intro hg simp_rw [(f.continuousAt xf).comp_continuousWithinAt hg, true_and] exact hG.liftPropWithinAt_indep_chart_target_aux (mem_chart_source _ _) (chart_mem_maximalAtlas _ _) (mem_chart_source _ _) hf xf hg /-- A version of `liftPropWithinAt_indep_chart`, that uses `LiftPropWithinAt` on both sides. -/ theorem liftPropWithinAt_indep_chart' [HasGroupoid M G] [HasGroupoid M' G'] (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) : LiftPropWithinAt P g s x ↔ ContinuousWithinAt g s x ∧ LiftPropWithinAt P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by rw [hG.liftPropWithinAt_indep_chart he xe hf xf, liftPropWithinAt_self, and_left_comm, Iff.comm, and_iff_right_iff_imp] intro h have h1 := (e.symm.continuousWithinAt_iff_continuousWithinAt_comp_right xe).mp h.1 have : ContinuousAt f ((g ∘ e.symm) (e x)) := by simp_rw [Function.comp, e.left_inv xe, f.continuousAt xf] exact this.comp_continuousWithinAt h1 theorem liftPropOn_indep_chart [HasGroupoid M G] [HasGroupoid M' G'] (he : e ∈ G.maximalAtlas M) (hf : f ∈ G'.maximalAtlas M') (h : LiftPropOn P g s) {y : H} (hy : y ∈ e.target ∩ e.symm ⁻¹' (s ∩ g ⁻¹' f.source)) : P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) y := by convert ((hG.liftPropWithinAt_indep_chart he (e.symm_mapsTo hy.1) hf hy.2.2).1 (h _ hy.2.1)).2 rw [e.right_inv hy.1] theorem liftPropWithinAt_inter' (ht : t ∈ 𝓝[s] x) : LiftPropWithinAt P g (s ∩ t) x ↔ LiftPropWithinAt P g s x := by rw [liftPropWithinAt_iff', liftPropWithinAt_iff', continuousWithinAt_inter' ht, hG.congr_set] simp_rw [eventuallyEq_set, mem_preimage, (chartAt _ x).eventually_nhds' (fun x ↦ x ∈ s ∩ t ↔ x ∈ s) (mem_chart_source _ x)] exact (mem_nhdsWithin_iff_eventuallyEq.mp ht).symm.mem_iff theorem liftPropWithinAt_inter (ht : t ∈ 𝓝 x) : LiftPropWithinAt P g (s ∩ t) x ↔ LiftPropWithinAt P g s x := hG.liftPropWithinAt_inter' (mem_nhdsWithin_of_mem_nhds ht) theorem liftPropWithinAt_congr_set (hu : s =ᶠ[𝓝 x] t) : LiftPropWithinAt P g s x ↔ LiftPropWithinAt P g t x := by rw [← hG.liftPropWithinAt_inter (s := s) hu, ← hG.liftPropWithinAt_inter (s := t) hu, ← eq_iff_iff] congr 1 aesop theorem liftPropAt_of_liftPropWithinAt (h : LiftPropWithinAt P g s x) (hs : s ∈ 𝓝 x) : LiftPropAt P g x := by rwa [← univ_inter s, hG.liftPropWithinAt_inter hs] at h theorem liftPropWithinAt_of_liftPropAt_of_mem_nhds (h : LiftPropAt P g x) (hs : s ∈ 𝓝 x) : LiftPropWithinAt P g s x := by rwa [← univ_inter s, hG.liftPropWithinAt_inter hs] theorem liftPropOn_of_locally_liftPropOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ LiftPropOn P g (s ∩ u)) : LiftPropOn P g s := by intro x hx rcases h x hx with ⟨u, u_open, xu, hu⟩ have := hu x ⟨hx, xu⟩ rwa [hG.liftPropWithinAt_inter] at this exact u_open.mem_nhds xu theorem liftProp_of_locally_liftPropOn (h : ∀ x, ∃ u, IsOpen u ∧ x ∈ u ∧ LiftPropOn P g u) : LiftProp P g := by rw [← liftPropOn_univ] refine hG.liftPropOn_of_locally_liftPropOn fun x _ ↦ ?_ simp [h x] theorem liftPropWithinAt_congr_of_eventuallyEq (h : LiftPropWithinAt P g s x) (h₁ : g' =ᶠ[𝓝[s] x] g) (hx : g' x = g x) : LiftPropWithinAt P g' s x := by refine ⟨h.1.congr_of_eventuallyEq h₁ hx, ?_⟩ refine hG.congr_nhdsWithin' ?_ (by simp_rw [Function.comp_apply, (chartAt H x).left_inv (mem_chart_source H x), hx]) h.2 simp_rw [EventuallyEq, Function.comp_apply] rw [(chartAt H x).eventually_nhdsWithin' (fun y ↦ chartAt H' (g' x) (g' y) = chartAt H' (g x) (g y)) (mem_chart_source H x)] exact h₁.mono fun y hy ↦ by rw [hx, hy] theorem liftPropWithinAt_congr_of_eventuallyEq_of_mem (h : LiftPropWithinAt P g s x) (h₁ : g' =ᶠ[𝓝[s] x] g) (h₂ : x ∈ s) : LiftPropWithinAt P g' s x := liftPropWithinAt_congr_of_eventuallyEq hG h h₁ (mem_of_mem_nhdsWithin h₂ h₁ :) theorem liftPropWithinAt_congr_iff_of_eventuallyEq (h₁ : g' =ᶠ[𝓝[s] x] g) (hx : g' x = g x) : LiftPropWithinAt P g' s x ↔ LiftPropWithinAt P g s x := ⟨fun h ↦ hG.liftPropWithinAt_congr_of_eventuallyEq h h₁.symm hx.symm, fun h ↦ hG.liftPropWithinAt_congr_of_eventuallyEq h h₁ hx⟩ theorem liftPropWithinAt_congr_iff (h₁ : ∀ y ∈ s, g' y = g y) (hx : g' x = g x) : LiftPropWithinAt P g' s x ↔ LiftPropWithinAt P g s x := hG.liftPropWithinAt_congr_iff_of_eventuallyEq (eventually_nhdsWithin_of_forall h₁) hx theorem liftPropWithinAt_congr_iff_of_mem (h₁ : ∀ y ∈ s, g' y = g y) (hx : x ∈ s) : LiftPropWithinAt P g' s x ↔ LiftPropWithinAt P g s x := hG.liftPropWithinAt_congr_iff_of_eventuallyEq (eventually_nhdsWithin_of_forall h₁) (h₁ _ hx) theorem liftPropWithinAt_congr (h : LiftPropWithinAt P g s x) (h₁ : ∀ y ∈ s, g' y = g y) (hx : g' x = g x) : LiftPropWithinAt P g' s x := (hG.liftPropWithinAt_congr_iff h₁ hx).mpr h theorem liftPropWithinAt_congr_of_mem (h : LiftPropWithinAt P g s x) (h₁ : ∀ y ∈ s, g' y = g y) (hx : x ∈ s) : LiftPropWithinAt P g' s x := (hG.liftPropWithinAt_congr_iff h₁ (h₁ _ hx)).mpr h theorem liftPropAt_congr_iff_of_eventuallyEq (h₁ : g' =ᶠ[𝓝 x] g) : LiftPropAt P g' x ↔ LiftPropAt P g x := hG.liftPropWithinAt_congr_iff_of_eventuallyEq (by simp_rw [nhdsWithin_univ, h₁]) h₁.eq_of_nhds theorem liftPropAt_congr_of_eventuallyEq (h : LiftPropAt P g x) (h₁ : g' =ᶠ[𝓝 x] g) : LiftPropAt P g' x := (hG.liftPropAt_congr_iff_of_eventuallyEq h₁).mpr h theorem liftPropOn_congr (h : LiftPropOn P g s) (h₁ : ∀ y ∈ s, g' y = g y) : LiftPropOn P g' s := fun x hx ↦ hG.liftPropWithinAt_congr (h x hx) h₁ (h₁ x hx) theorem liftPropOn_congr_iff (h₁ : ∀ y ∈ s, g' y = g y) : LiftPropOn P g' s ↔ LiftPropOn P g s := ⟨fun h ↦ hG.liftPropOn_congr h fun y hy ↦ (h₁ y hy).symm, fun h ↦ hG.liftPropOn_congr h h₁⟩ end theorem liftPropWithinAt_mono_of_mem_nhdsWithin (mono_of_mem_nhdsWithin : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, s ∈ 𝓝[t] x → P f s x → P f t x) (h : LiftPropWithinAt P g s x) (hst : s ∈ 𝓝[t] x) : LiftPropWithinAt P g t x := by simp only [liftPropWithinAt_iff'] at h ⊢ refine ⟨h.1.mono_of_mem_nhdsWithin hst, mono_of_mem_nhdsWithin ?_ h.2⟩ simp_rw [← mem_map, (chartAt H x).symm.map_nhdsWithin_preimage_eq (mem_chart_target H x), (chartAt H x).left_inv (mem_chart_source H x), hst] theorem liftPropWithinAt_mono (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : LiftPropWithinAt P g s x) (hts : t ⊆ s) : LiftPropWithinAt P g t x := by refine ⟨h.1.mono hts, mono (fun y hy ↦ ?_) h.2⟩ simp only [mfld_simps] at hy simp only [hy, hts _, mfld_simps] theorem liftPropWithinAt_of_liftPropAt (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : LiftPropAt P g x) : LiftPropWithinAt P g s x := by rw [← liftPropWithinAt_univ] at h exact liftPropWithinAt_mono mono h (subset_univ _) theorem liftPropOn_mono (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : LiftPropOn P g t) (hst : s ⊆ t) : LiftPropOn P g s := fun x hx ↦ liftPropWithinAt_mono mono (h x (hst hx)) hst theorem liftPropOn_of_liftProp (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : LiftProp P g) : LiftPropOn P g s := by rw [← liftPropOn_univ] at h exact liftPropOn_mono mono h (subset_univ _) theorem liftPropAt_of_mem_maximalAtlas [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximalAtlas M G) (hx : x ∈ e.source) : LiftPropAt Q e x := by simp_rw [LiftPropAt, hG.liftPropWithinAt_indep_chart he hx G.id_mem_maximalAtlas (mem_univ _), (e.continuousAt hx).continuousWithinAt, true_and] exact hG.congr' (e.eventually_right_inverse' hx) (hQ _) theorem liftPropOn_of_mem_maximalAtlas [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximalAtlas M G) : LiftPropOn Q e e.source := by intro x hx apply hG.liftPropWithinAt_of_liftPropAt_of_mem_nhds (hG.liftPropAt_of_mem_maximalAtlas hQ he hx) exact e.open_source.mem_nhds hx theorem liftPropAt_symm_of_mem_maximalAtlas [HasGroupoid M G] {x : H} (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximalAtlas M G) (hx : x ∈ e.target) : LiftPropAt Q e.symm x := by suffices h : Q (e ∘ e.symm) univ x by have : e.symm x ∈ e.source := by simp only [hx, mfld_simps] rw [LiftPropAt, hG.liftPropWithinAt_indep_chart G.id_mem_maximalAtlas (mem_univ _) he this] refine ⟨(e.symm.continuousAt hx).continuousWithinAt, ?_⟩ simp only [h, mfld_simps] exact hG.congr' (e.eventually_right_inverse hx) (hQ x) theorem liftPropOn_symm_of_mem_maximalAtlas [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximalAtlas M G) : LiftPropOn Q e.symm e.target := by intro x hx apply hG.liftPropWithinAt_of_liftPropAt_of_mem_nhds (hG.liftPropAt_symm_of_mem_maximalAtlas hQ he hx) exact e.open_target.mem_nhds hx theorem liftPropAt_chart [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) : LiftPropAt Q (chartAt (H := H) x) x := hG.liftPropAt_of_mem_maximalAtlas hQ (chart_mem_maximalAtlas G x) (mem_chart_source H x) theorem liftPropOn_chart [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) : LiftPropOn Q (chartAt (H := H) x) (chartAt (H := H) x).source := hG.liftPropOn_of_mem_maximalAtlas hQ (chart_mem_maximalAtlas G x) theorem liftPropAt_chart_symm [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) : LiftPropAt Q (chartAt (H := H) x).symm ((chartAt H x) x) := hG.liftPropAt_symm_of_mem_maximalAtlas hQ (chart_mem_maximalAtlas G x) (by simp) theorem liftPropOn_chart_symm [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) : LiftPropOn Q (chartAt (H := H) x).symm (chartAt H x).target := hG.liftPropOn_symm_of_mem_maximalAtlas hQ (chart_mem_maximalAtlas G x) theorem liftPropAt_of_mem_groupoid (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) {f : OpenPartialHomeomorph H H} (hf : f ∈ G) {x : H} (hx : x ∈ f.source) : LiftPropAt Q f x := liftPropAt_of_mem_maximalAtlas hG hQ (G.mem_maximalAtlas_of_mem_groupoid hf) hx theorem liftPropOn_of_mem_groupoid (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) {f : OpenPartialHomeomorph H H} (hf : f ∈ G) : LiftPropOn Q f f.source := liftPropOn_of_mem_maximalAtlas hG hQ (G.mem_maximalAtlas_of_mem_groupoid hf) theorem liftProp_id (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) : LiftProp Q (id : M → M) := by simp_rw [liftProp_iff, continuous_id, true_and] exact fun x ↦ hG.congr' ((chartAt H x).eventually_right_inverse <| mem_chart_target H x) (hQ _) theorem liftPropAt_iff_comp_subtype_val (hG : LocalInvariantProp G G' P) {U : Opens M} (f : M → M') (x : U) : LiftPropAt P f x ↔ LiftPropAt P (f ∘ Subtype.val) x := by simp only [LiftPropAt, liftPropWithinAt_iff'] congrm ?_ ∧ ?_ · simp_rw [continuousWithinAt_univ, U.isOpenEmbedding'.continuousAt_iff] · apply hG.congr_iff exact (U.chartAt_subtype_val_symm_eventuallyEq).fun_comp (chartAt H' (f x) ∘ f) theorem liftPropAt_iff_comp_inclusion (hG : LocalInvariantProp G G' P) {U V : Opens M} (hUV : U ≤ V) (f : V → M') (x : U) : LiftPropAt P f (Set.inclusion hUV x) ↔ LiftPropAt P (f ∘ Set.inclusion hUV : U → M') x := by simp only [LiftPropAt, liftPropWithinAt_iff'] congrm ?_ ∧ ?_ · simp_rw [continuousWithinAt_univ, (TopologicalSpace.Opens.isOpenEmbedding_of_le hUV).continuousAt_iff] · apply hG.congr_iff exact (TopologicalSpace.Opens.chartAt_inclusion_symm_eventuallyEq hUV).fun_comp (chartAt H' (f (Set.inclusion hUV x)) ∘ f) theorem liftProp_subtype_val {Q : (H → H) → Set H → H → Prop} (hG : LocalInvariantProp G G Q) (hQ : ∀ y, Q id univ y) (U : Opens M) : LiftProp Q (Subtype.val : U → M) := by intro x change LiftPropAt Q (id ∘ Subtype.val) x rw [← hG.liftPropAt_iff_comp_subtype_val] apply hG.liftProp_id hQ theorem liftProp_inclusion {Q : (H → H) → Set H → H → Prop} (hG : LocalInvariantProp G G Q) (hQ : ∀ y, Q id univ y) {U V : Opens M} (hUV : U ≤ V) : LiftProp Q (Opens.inclusion hUV : U → V) := by intro x change LiftPropAt Q (id ∘ Opens.inclusion hUV) x rw [← hG.liftPropAt_iff_comp_inclusion hUV] apply hG.liftProp_id hQ end LocalInvariantProp section LocalStructomorph variable (G) open OpenPartialHomeomorph /-- A function from a model space `H` to itself is a local structomorphism, with respect to a structure groupoid `G` for `H`, relative to a set `s` in `H`, if for all points `x` in the set, the function agrees with a `G`-structomorphism on `s` in a neighbourhood of `x`. -/ def IsLocalStructomorphWithinAt (f : H → H) (s : Set H) (x : H) : Prop := x ∈ s → ∃ e : OpenPartialHomeomorph H H, e ∈ G ∧ EqOn f e.toFun (s ∩ e.source) ∧ x ∈ e.source /-- For a groupoid `G` which is `ClosedUnderRestriction`, being a local structomorphism is a local invariant property. -/ theorem isLocalStructomorphWithinAt_localInvariantProp [ClosedUnderRestriction G] : LocalInvariantProp G G (IsLocalStructomorphWithinAt G) := { is_local := by intro s x u f hu hux constructor · rintro h hx rcases h hx.1 with ⟨e, heG, hef, hex⟩ have : s ∩ u ∩ e.source ⊆ s ∩ e.source := by mfld_set_tac exact ⟨e, heG, hef.mono this, hex⟩ · rintro h hx rcases h ⟨hx, hux⟩ with ⟨e, heG, hef, hex⟩ refine ⟨e.restr (interior u), ?_, ?_, ?_⟩ · exact closedUnderRestriction' heG isOpen_interior · have : s ∩ u ∩ e.source = s ∩ (e.source ∩ u) := by mfld_set_tac simpa only [this, interior_interior, hu.interior_eq, mfld_simps] using hef · simp only [*, hu.interior_eq, mfld_simps] right_invariance' := by intro s x f e' he'G he'x h hx have hxs : x ∈ s := by simpa only [e'.left_inv he'x, mfld_simps] using hx rcases h hxs with ⟨e, heG, hef, hex⟩ refine ⟨e'.symm.trans e, G.trans (G.symm he'G) heG, ?_, ?_⟩ · intro y hy simp only [mfld_simps] at hy simp only [hef ⟨hy.1, hy.2.2⟩, mfld_simps] · simp only [hex, he'x, mfld_simps] congr_of_forall := by intro s x f g hfgs _ h hx rcases h hx with ⟨e, heG, hef, hex⟩ refine ⟨e, heG, ?_, hex⟩ intro y hy rw [← hef hy, hfgs y hy.1] left_invariance' := by intro s x f e' he'G _ hfx h hx rcases h hx with ⟨e, heG, hef, hex⟩ refine ⟨e.trans e', G.trans heG he'G, ?_, ?_⟩ · intro y hy simp only [mfld_simps] at hy simp only [hef ⟨hy.1, hy.2.1⟩, mfld_simps] · simpa only [hex, hef ⟨hx, hex⟩, mfld_simps] using hfx } /-- A slight reformulation of `IsLocalStructomorphWithinAt` when `f` is an open partial homeomorph. This gives us an `e` that is defined on a subset of `f.source`. -/ theorem _root_.OpenPartialHomeomorph.isLocalStructomorphWithinAt_iff {G : StructureGroupoid H} [ClosedUnderRestriction G] (f : OpenPartialHomeomorph H H) {s : Set H} {x : H} (hx : x ∈ f.source ∪ sᶜ) : G.IsLocalStructomorphWithinAt (⇑f) s x ↔ x ∈ s → ∃ e : OpenPartialHomeomorph H H, e ∈ G ∧ e.source ⊆ f.source ∧ EqOn f (⇑e) (s ∩ e.source) ∧ x ∈ e.source := by constructor · intro hf h2x obtain ⟨e, he, hfe, hxe⟩ := hf h2x refine ⟨e.restr f.source, closedUnderRestriction' he f.open_source, ?_, ?_, hxe, ?_⟩ · simp_rw [OpenPartialHomeomorph.restr_source] exact inter_subset_right.trans interior_subset · intro x' hx' exact hfe ⟨hx'.1, hx'.2.1⟩ · rw [f.open_source.interior_eq] exact Or.resolve_right hx (not_not.mpr h2x) · intro hf hx obtain ⟨e, he, _, hfe, hxe⟩ := hf hx exact ⟨e, he, hfe, hxe⟩ /-- A slight reformulation of `IsLocalStructomorphWithinAt` when `f` is an open partial homeomorph and the set we're considering is a superset of `f.source`. -/ theorem _root_.OpenPartialHomeomorph.isLocalStructomorphWithinAt_iff' {G : StructureGroupoid H} [ClosedUnderRestriction G] (f : OpenPartialHomeomorph H H) {s : Set H} {x : H} (hs : f.source ⊆ s) (hx : x ∈ f.source ∪ sᶜ) : G.IsLocalStructomorphWithinAt (⇑f) s x ↔ x ∈ s → ∃ e : OpenPartialHomeomorph H H, e ∈ G ∧ e.source ⊆ f.source ∧ EqOn f (⇑e) e.source ∧ x ∈ e.source := by rw [f.isLocalStructomorphWithinAt_iff hx] refine imp_congr_right fun _ ↦ exists_congr fun e ↦ and_congr_right fun _ ↦ ?_ refine and_congr_right fun h2e ↦ ?_ rw [inter_eq_right.mpr (h2e.trans hs)] /-- A slight reformulation of `IsLocalStructomorphWithinAt` when `f` is an open partial homeomorph and the set we're considering is `f.source`. -/ theorem _root_.OpenPartialHomeomorph.isLocalStructomorphWithinAt_source_iff {G : StructureGroupoid H} [ClosedUnderRestriction G] (f : OpenPartialHomeomorph H H) {x : H} : G.IsLocalStructomorphWithinAt (⇑f) f.source x ↔ x ∈ f.source → ∃ e : OpenPartialHomeomorph H H, e ∈ G ∧ e.source ⊆ f.source ∧ EqOn f (⇑e) e.source ∧ x ∈ e.source := haveI : x ∈ f.source ∪ f.sourceᶜ := by simp_rw [union_compl_self, mem_univ] f.isLocalStructomorphWithinAt_iff' Subset.rfl this variable {H₁ : Type*} [TopologicalSpace H₁] {H₂ : Type*} [TopologicalSpace H₂] {H₃ : Type*} [TopologicalSpace H₃] [ChartedSpace H₁ H₂] [ChartedSpace H₂ H₃] {G₁ : StructureGroupoid H₁} [HasGroupoid H₂ G₁] [ClosedUnderRestriction G₁] (G₂ : StructureGroupoid H₂) [HasGroupoid H₃ G₂] theorem HasGroupoid.comp (H : ∀ e ∈ G₂, LiftPropOn (IsLocalStructomorphWithinAt G₁) (e : H₂ → H₂) e.source) : @HasGroupoid H₁ _ H₃ _ (ChartedSpace.comp H₁ H₂ H₃) G₁ := let _ := ChartedSpace.comp H₁ H₂ H₃ { compatible := by rintro _ _ ⟨e, he, f, hf, rfl⟩ ⟨e', he', f', hf', rfl⟩ apply G₁.locality intro x hx simp only [mfld_simps] at hx have hxs : x ∈ f.symm ⁻¹' (e.symm ≫ₕ e').source := by simp only [hx, mfld_simps] have hxs' : x ∈ f.target ∩ f.symm ⁻¹' ((e.symm ≫ₕ e').source ∩ e.symm ≫ₕ e' ⁻¹' f'.source) := by simp only [hx, mfld_simps] obtain ⟨φ, hφG₁, hφ, hφ_dom⟩ := LocalInvariantProp.liftPropOn_indep_chart (isLocalStructomorphWithinAt_localInvariantProp G₁) (G₁.subset_maximalAtlas hf) (G₁.subset_maximalAtlas hf') (H _ (G₂.compatible he he')) hxs' hxs simp_rw [← OpenPartialHomeomorph.coe_trans, OpenPartialHomeomorph.trans_assoc] at hφ simp_rw [OpenPartialHomeomorph.trans_symm_eq_symm_trans_symm, OpenPartialHomeomorph.trans_assoc] have hs : IsOpen (f.symm ≫ₕ e.symm ≫ₕ e' ≫ₕ f').source := (f.symm ≫ₕ e.symm ≫ₕ e' ≫ₕ f').open_source refine ⟨_, hs.inter φ.open_source, ?_, ?_⟩ · simp only [hx, hφ_dom, mfld_simps] · refine G₁.mem_of_eqOnSource (closedUnderRestriction' hφG₁ hs) ?_ rw [OpenPartialHomeomorph.restr_source_inter] refine OpenPartialHomeomorph.Set.EqOn.restr_eqOn_source (hφ.mono ?_) mfld_set_tac } end LocalStructomorph end StructureGroupoid
.lake/packages/mathlib/Mathlib/Geometry/Manifold/Riemannian/Basic.lean
import Mathlib.Geometry.Manifold.MFDeriv.Atlas import Mathlib.Geometry.Manifold.Riemannian.PathELength import Mathlib.Geometry.Manifold.VectorBundle.Riemannian import Mathlib.Geometry.Manifold.VectorBundle.Tangent import Mathlib.MeasureTheory.Integral.IntervalIntegral.ContDiff /-! # Riemannian manifolds A Riemannian manifold `M` is a real manifold such that its tangent spaces are endowed with an inner product, depending smoothly on the point, and such that `M` has an emetric space structure for which the distance is the infimum of lengths of paths. We register a Prop-valued typeclass `IsRiemannianManifold I M` recording this fact, building on top of `[EMetricSpace M] [RiemannianBundle (fun (x : M) ↦ TangentSpace I x)]`. We show that an inner product vector space, with the associated canonical Riemannian metric, satisfies the predicate `IsRiemannianManifold 𝓘(ℝ, E) E`. In a general manifold with a Riemannian metric, we define the associated extended distance in the manifold, and show that it defines the same topology as the pre-existing one. Therefore, one may endow the manifold with an emetric space structure, see `EmetricSpace.ofRiemannianMetric`. By definition, it then satisfies the predicate `IsRiemannianManifold I M`. The following code block is the standard way to say "Let `M` be a `C^∞` Riemannian manifold". ``` open scoped Bundle variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type*} [EMetricSpace M] [ChartedSpace H M] [IsManifold I ∞ M] [RiemannianBundle (fun (x : M) ↦ TangentSpace I x)] [IsContMDiffRiemannianBundle I ∞ E (fun (x : M) ↦ TangentSpace I x)] [IsRiemannianManifold I M] ``` To register a `C^n` manifold for a general `n`, one should replace `[IsManifold ∞ I M]` with `[IsManifold I n M] [IsManifold I 1 M]`, where the second one is needed to ensure that the tangent bundle is well behaved (not necessary when `n` is concrete like 2 or 3 as there are automatic instances for these cases). One can require whatever regularity one wants in the `IsContMDiffRiemannianBundle` instance above, for example `[IsContMDiffRiemannianBundle I n E (fun (x : M) ↦ TangentSpace I x)]`, and one should also add `[IsContinuousRiemannianBundle E (fun (x : M) ↦ TangentSpace I x)]` (as above, Lean cannot infer the latter from the former as it cannot guess `n`). -/ open Bundle Bornology Set MeasureTheory Manifold Filter open scoped ENNReal ContDiff Topology local notation "⟪" x ", " y "⟫" => inner ℝ x y noncomputable section variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {n : WithTop ℕ∞} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] section variable [PseudoEMetricSpace M] [ChartedSpace H M] [RiemannianBundle (fun (x : M) ↦ TangentSpace I x)] variable (I M) in /-- Consider a manifold in which the tangent spaces are already endowed with an inner product, and the space is already endowed with an extended distance. We say that this is a Riemannian manifold if the distance is given by the infimum of the lengths of `C^1` paths, measured using the norm in the tangent spaces. This is a `Prop`-valued typeclass, on top of existing data. If you need to *construct* a distance using a Riemannian structure, see `EmetricSpace.ofRiemannianMetric`. -/ class IsRiemannianManifold : Prop where out (x y : M) : edist x y = riemannianEDist I x y end section /-! ### Riemannian structure on an inner product vector space We endow an inner product vector space with the canonical Riemannian metric, given by the inner product of the vector space in each of the tangent spaces, and we show that this construction satisfies the `IsRiemannianManifold 𝓘(ℝ, E) E` predicate, i.e., the extended distance between two points is the infimum of the length of paths between these points. -/ variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] variable (F) in /-- The standard Riemannian metric on a vector space with an inner product, given by this inner product on each tangent space. -/ noncomputable def riemannianMetricVectorSpace : ContMDiffRiemannianMetric 𝓘(ℝ, F) ω F (fun (x : F) ↦ TangentSpace 𝓘(ℝ, F) x) where inner x := (innerSL ℝ (E := F) : F →L[ℝ] F →L[ℝ] ℝ) symm x v w := real_inner_comm _ _ pos x v hv := real_inner_self_pos.2 hv isVonNBounded x := by change IsVonNBounded ℝ {v : F | ⟪v, v⟫ < 1} have : Metric.ball (0 : F) 1 = {v : F | ⟪v, v⟫ < 1} := by ext v simp only [Metric.mem_ball, dist_zero_right, norm_eq_sqrt_re_inner (𝕜 := ℝ), RCLike.re_to_real, Set.mem_setOf_eq] conv_lhs => rw [show (1 : ℝ) = √ 1 by simp] rw [Real.sqrt_lt_sqrt_iff] exact real_inner_self_nonneg rw [← this] exact NormedSpace.isVonNBounded_ball ℝ F 1 contMDiff := by intro x rw [contMDiffAt_section] convert contMDiffAt_const (c := innerSL ℝ) ext v w simp [hom_trivializationAt_apply, ContinuousLinearMap.inCoordinates, Trivialization.linearMapAt_apply, TangentSpace] noncomputable instance : RiemannianBundle (fun (x : F) ↦ TangentSpace 𝓘(ℝ, F) x) := ⟨(riemannianMetricVectorSpace F).toRiemannianMetric⟩ lemma norm_tangentSpace_vectorSpace {x : F} {v : TangentSpace 𝓘(ℝ, F) x} : ‖v‖ = ‖letI V : F := v; V‖ := by rw [norm_eq_sqrt_real_inner, norm_eq_sqrt_real_inner] lemma nnnorm_tangentSpace_vectorSpace {x : F} {v : TangentSpace 𝓘(ℝ, F) x} : ‖v‖₊ = ‖letI V : F := v; V‖₊ := by simp [nnnorm, norm_tangentSpace_vectorSpace] lemma enorm_tangentSpace_vectorSpace {x : F} {v : TangentSpace 𝓘(ℝ, F) x} : ‖v‖ₑ = ‖letI V : F := v; V‖ₑ := by simp [enorm, nnnorm_tangentSpace_vectorSpace] open MeasureTheory Measure lemma lintegral_fderiv_lineMap_eq_edist {x y : E} : ∫⁻ t in Icc 0 1, ‖fderivWithin ℝ (ContinuousAffineMap.lineMap (R := ℝ) x y) (Icc 0 1) t 1‖ₑ = edist x y := by have : edist x y = ∫⁻ t in Icc (0 : ℝ) 1, ‖y - x‖ₑ := by simp [edist_comm x y, edist_eq_enorm_sub] rw [this] apply setLIntegral_congr_fun measurableSet_Icc (fun z hz ↦ ?_) rw [show y - x = fderiv ℝ (ContinuousAffineMap.lineMap (R := ℝ) x y) z 1 by simp] congr exact fderivWithin_eq_fderiv (uniqueDiffOn_Icc zero_lt_one _ hz) (ContinuousAffineMap.differentiableAt _) /-- An inner product vector space is a Riemannian manifold, i.e., the distance between two points is the infimum of the lengths of paths between these points. -/ instance : IsRiemannianManifold 𝓘(ℝ, F) F := by refine ⟨fun x y ↦ le_antisymm ?_ ?_⟩ · simp only [riemannianEDist, le_iInf_iff] intro γ hγ let e : ℝ → F := γ ∘ (projIcc 0 1 zero_le_one) have D : ContDiffOn ℝ 1 e (Icc 0 1) := contMDiffOn_iff_contDiffOn.mp (hγ.comp_contMDiffOn contMDiffOn_projIcc) rw [lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc, pathELength_eq_lintegral_mfderivWithin_Icc] simp only [mfderivWithin_eq_fderivWithin, enorm_tangentSpace_vectorSpace] conv_lhs => rw [edist_comm, edist_eq_enorm_sub, show x = e 0 by simp [e], show y = e 1 by simp [e]] exact (enorm_sub_le_lintegral_derivWithin_Icc_of_contDiffOn_Icc D zero_le_one).trans_eq rfl · let γ := ContinuousAffineMap.lineMap (R := ℝ) x y have : riemannianEDist 𝓘(ℝ, F) x y ≤ pathELength 𝓘(ℝ, F) γ 0 1 := by apply riemannianEDist_le_pathELength ?_ (by simp [γ, ContinuousAffineMap.coe_lineMap_eq]) (by simp [γ, ContinuousAffineMap.coe_lineMap_eq]) zero_le_one rw [contMDiffOn_iff_contDiffOn] exact γ.contDiff.contDiffOn apply this.trans_eq rw [pathELength_eq_lintegral_mfderivWithin_Icc] simp only [mfderivWithin_eq_fderivWithin, enorm_tangentSpace_vectorSpace] exact lintegral_fderiv_lineMap_eq_edist end section /-! ### Constructing a distance from a Riemannian structure Let `M` be a real manifold with a Riemannian structure. We construct the associated distance and show that the associated topology coincides with the pre-existing topology. Therefore, one may endow `M` with an emetric space structure, called `EmetricSpace.ofRiemannianMetric`. Moreover, we show that in this case the resulting emetric space satisfies the predicate `IsRiemannianManifold I M`. Showing that the distance topology coincides with the pre-existing topology is not trivial. The two inclusions are proved respectively in `eventually_riemannianEDist_lt` and `setOf_riemannianEDist_lt_subset_nhds`. For the first one, we have to show that points which are close for the topology are at small distance. For this, we use the path between the two points which is the pullback of the segment in the extended chart, and argue that it is short because the images are close in the extended chart. For the second one, we have to show that any neighborhood of `x` contains all the points `y` with `riemannianEDist x y < c` for some `c > 0`. For this, we argue that a short path from `x` to `y` remains short in the extended chart, and therefore it doesn't have the time to exit the image of the neighborhood in the extended chart. -/ open Manifold Metric open scoped NNReal variable [RiemannianBundle (fun (x : M) ↦ TangentSpace I x)] [IsManifold I 1 M] [IsContinuousRiemannianBundle E (fun (x : M) ↦ TangentSpace I x)] /-- Register on the tangent space to a normed vector space the same `NormedAddCommGroup` structure as in the vector space. Should not be a global instance, as it does not coincide definitionally with the Riemannian structure for inner product spaces, but can be activated locally. -/ def normedAddCommGroupTangentSpaceVectorSpace (x : E) : NormedAddCommGroup (TangentSpace 𝓘(ℝ, E) x) := inferInstanceAs (NormedAddCommGroup E) attribute [local instance] normedAddCommGroupTangentSpaceVectorSpace /-- Register on the tangent space to a normed vector space the same `NormedSpace` structure as in the vector space. Should not be a global instance, as it does not coincide definitionally with the Riemannian structure for inner product spaces, but can be activated locally. -/ def normedSpaceTangentSpaceVectorSpace (x : E) : NormedSpace ℝ (TangentSpace 𝓘(ℝ, E) x) := inferInstanceAs (NormedSpace ℝ E) attribute [local instance] normedSpaceTangentSpaceVectorSpace variable (I) lemma eventually_norm_mfderiv_extChartAt_lt (x : M) : ∃ C > 0, ∀ᶠ y in 𝓝 x, ‖mfderiv I 𝓘(ℝ, E) (extChartAt I x) y‖ < C := by rcases eventually_norm_trivializationAt_lt E (fun (x : M) ↦ TangentSpace I x) x with ⟨C, C_pos, hC⟩ refine ⟨C, C_pos, ?_⟩ have hx : (chartAt H x).source ∈ 𝓝 x := chart_source_mem_nhds H x filter_upwards [hC, hx] with y hy h'y rwa [← TangentBundle.continuousLinearMapAt_trivializationAt h'y] lemma eventually_enorm_mfderiv_extChartAt_lt (x : M) : ∃ C > (0 : ℝ≥0), ∀ᶠ y in 𝓝 x, ‖mfderiv I 𝓘(ℝ, E) (extChartAt I x) y‖ₑ < C := by rcases eventually_norm_mfderiv_extChartAt_lt I x with ⟨C, C_pos, hC⟩ lift C to ℝ≥0 using C_pos.le simp only [gt_iff_lt, NNReal.coe_pos] at C_pos refine ⟨C, C_pos, ?_⟩ filter_upwards [hC] with y hy simp only [enorm, nnnorm] exact_mod_cast hy lemma eventually_norm_mfderivWithin_symm_extChartAt_comp_lt (x : M) : ∃ C > 0, ∀ᶠ y in 𝓝 x, ‖mfderivWithin 𝓘(ℝ, E) I (extChartAt I x).symm (range I) (extChartAt I x y)‖ < C := by rcases eventually_norm_symmL_trivializationAt_lt E (fun (x : M) ↦ TangentSpace I x) x with ⟨C, C_pos, hC⟩ refine ⟨C, C_pos, ?_⟩ have hx : (chartAt H x).source ∈ 𝓝 x := chart_source_mem_nhds H x filter_upwards [hC, hx] with y hy h'y rw [TangentBundle.symmL_trivializationAt h'y] at hy have A : (extChartAt I x).symm (extChartAt I x y) = y := (extChartAt I x).left_inv (by simpa using h'y) convert hy using 3 <;> congr lemma eventually_norm_mfderivWithin_symm_extChartAt_lt (x : M) : ∃ C > 0, ∀ᶠ y in 𝓝[range I] (extChartAt I x x), ‖mfderivWithin 𝓘(ℝ, E) I (extChartAt I x).symm (range I) y‖ < C := by rcases eventually_norm_mfderivWithin_symm_extChartAt_comp_lt I x with ⟨C, C_pos, hC⟩ refine ⟨C, C_pos, ?_⟩ have : 𝓝 x = 𝓝 ((extChartAt I x).symm (extChartAt I x x)) := by simp rw [this] at hC have : ContinuousAt (extChartAt I x).symm (extChartAt I x x) := continuousAt_extChartAt_symm _ filter_upwards [nhdsWithin_le_nhds (this.preimage_mem_nhds hC), extChartAt_target_mem_nhdsWithin x] with y hy h'y have : y = (extChartAt I x) ((extChartAt I x).symm y) := by simp [-extChartAt, h'y] simp only [preimage_setOf_eq, mem_setOf_eq] at hy convert hy lemma eventually_enorm_mfderivWithin_symm_extChartAt_lt (x : M) : ∃ C > (0 : ℝ≥0), ∀ᶠ y in 𝓝[range I] (extChartAt I x x), ‖mfderivWithin 𝓘(ℝ, E) I (extChartAt I x).symm (range I) y‖ₑ < C := by rcases eventually_norm_mfderivWithin_symm_extChartAt_lt I x with ⟨C, C_pos, hC⟩ lift C to ℝ≥0 using C_pos.le simp only [gt_iff_lt, NNReal.coe_pos] at C_pos refine ⟨C, C_pos, ?_⟩ filter_upwards [hC] with y hy simp only [enorm, nnnorm] exact_mod_cast hy /-- Around any point `x`, the Riemannian distance between two points is controlled by the distance in the extended chart. In other words, the extended chart is locally Lipschitz. -/ lemma eventually_riemannianEDist_le_edist_extChartAt (x : M) : ∃ C > (0 : ℝ≥0), ∀ᶠ y in 𝓝 x, riemannianEDist I x y ≤ C * edist (extChartAt I x x) (extChartAt I x y) := by /- To construct a path with controlled distance from `x` to `y`, we consider the segment from `extChartAt x x` to `extChartAt x y` in the chart, and we push it by `(extChartAt x).symm`. As the derivative of the latter is locally bounded, this only multiplies the length by a bounded amount. -/ -- first start from a bound on the derivative rcases eventually_enorm_mfderivWithin_symm_extChartAt_lt I x with ⟨C, C_pos, hC⟩ refine ⟨C, C_pos, ?_⟩ -- consider a small convex set around `extChartAt x x` where everything is controlled. obtain ⟨r, r_pos, hr⟩ : ∃ r > 0, ball (extChartAt I x x) r ∩ range I ⊆ (extChartAt I x).target ∩ {y | ‖mfderivWithin 𝓘(ℝ, E) I (extChartAt I x).symm (range I) y‖ₑ < C} := mem_nhdsWithin_iff.1 (inter_mem (extChartAt_target_mem_nhdsWithin x) hC) -- pull this set inside `M`: this is the set where we will get the estimate. have A : (extChartAt I x) ⁻¹' (ball (extChartAt I x x) r ∩ range I) ∈ 𝓝 x := by apply extChartAt_preimage_mem_nhds_of_mem_nhdsWithin (by simp) rw [inter_comm] exact inter_mem_nhdsWithin _ (ball_mem_nhds _ r_pos) -- consider `y` in this good set. Let `η` be the segment in the extended chart, and -- `γ` its composition with `(extChartAt x).symm`. filter_upwards [A, chart_source_mem_nhds H x] with y hy h'y let η := ContinuousAffineMap.lineMap (R := ℝ) (extChartAt I x x) (extChartAt I x y) set γ := (extChartAt I x).symm ∘ η -- by convexity, the whole segment between `extChartAt x x` and `extChartAt x y` is in the -- controlled set. have hη : Icc 0 1 ⊆ ⇑η ⁻¹' ((extChartAt I x).target ∩ {y | ‖mfderivWithin 𝓘(ℝ, E) I (extChartAt I x).symm (range I) y‖ₑ < C}) := by simp only [← image_subset_iff, ContinuousAffineMap.coe_lineMap_eq, ← segment_eq_image_lineMap, η] apply Subset.trans _ hr exact ((convex_ball _ _).inter I.convex_range).segment_subset (by simp [r_pos]) hy simp only [preimage_inter, subset_inter_iff] at hη have η_smooth : ContMDiffOn 𝓘(ℝ, ℝ) 𝓘(ℝ, E) 1 η (Icc 0 1) := by apply ContMDiff.contMDiffOn rw [contMDiff_iff_contDiff] exact ContinuousAffineMap.contDiff _ -- we can bound the Riemannian distance using the specific path `γ`. have : riemannianEDist I x y ≤ pathELength I γ 0 1 := by apply riemannianEDist_le_pathELength _ _ _ zero_le_one · exact (contMDiffOn_extChartAt_symm x).comp η_smooth hη.1 · simp [γ, η, ContinuousAffineMap.coe_lineMap_eq] · simp [γ, η, ContinuousAffineMap.coe_lineMap_eq, h'y] apply this.trans -- Finally, we control the length of `γ` thanks to the boundedness of the derivative of -- `(extChartAt x).symm` on the whole controlled set. rw [← lintegral_fderiv_lineMap_eq_edist, pathELength_eq_lintegral_mfderivWithin_Icc, ← lintegral_const_mul' _ _ ENNReal.coe_ne_top] apply setLIntegral_mono' measurableSet_Icc (fun t ht ↦ ?_) have : mfderivWithin 𝓘(ℝ) I γ (Icc 0 1) t = (mfderivWithin 𝓘(ℝ, E) I (extChartAt I x).symm (range I) (η t)) ∘L (mfderivWithin 𝓘(ℝ) 𝓘(ℝ, E) η (Icc 0 1) t) := by apply mfderivWithin_comp · exact mdifferentiableWithinAt_extChartAt_symm (hη.1 ht) · exact η_smooth.mdifferentiableOn le_rfl t ht · exact hη.1.trans (preimage_mono (extChartAt_target_subset_range x)) · rw [uniqueMDiffWithinAt_iff_uniqueDiffWithinAt] exact uniqueDiffOn_Icc zero_lt_one t ht have : mfderivWithin 𝓘(ℝ) I γ (Icc 0 1) t 1 = (mfderivWithin 𝓘(ℝ, E) I (extChartAt I x).symm (range I) (η t)) (mfderivWithin 𝓘(ℝ) 𝓘(ℝ, E) η (Icc 0 1) t 1) := congr($this 1) rw [this] apply (ContinuousLinearMap.le_opNorm_enorm _ _).trans gcongr · exact (hη.2 ht).le · simp only [mfderivWithin_eq_fderivWithin] exact le_of_eq rfl /-- If points are close for the topology, then their Riemannian distance is small. -/ lemma eventually_riemannianEDist_lt (x : M) {c : ℝ≥0∞} (hc : 0 < c) : ∀ᶠ y in 𝓝 x, riemannianEDist I x y < c := by rcases eventually_riemannianEDist_le_edist_extChartAt I x with ⟨C, C_pos, hC⟩ have : (extChartAt I x) ⁻¹' (EMetric.ball (extChartAt I x x) (c / C)) ∈ 𝓝 x := by apply (continuousAt_extChartAt x).preimage_mem_nhds exact EMetric.ball_mem_nhds _ (ENNReal.div_pos hc.ne' (by simp)) filter_upwards [this, hC] with y hy h'y apply h'y.trans_lt have : edist (extChartAt I x x) (extChartAt I x y) < c / C := by simpa only [mem_preimage, EMetric.mem_ball'] using hy rwa [ENNReal.lt_div_iff_mul_lt, mul_comm] at this · exact Or.inl (mod_cast C_pos.ne') · simp @[deprecated (since := "2025-09-18")] alias eventually_riemmanianEDist_lt := eventually_riemannianEDist_lt /-- Any neighborhood of `x` contains all the points which are close enough to `x` for the Riemannian distance, `ℝ≥0` version. -/ lemma setOf_riemannianEDist_lt_subset_nhds [RegularSpace M] {x : M} {s : Set M} (hs : s ∈ 𝓝 x) : ∃ c > (0 : ℝ≥0), {y | riemannianEDist I x y < c} ⊆ s := by /- Consider a closed neighborhood `u` of `x` on which the derivative of the extended chart is bounded by some `C`, contained in `s`, then an open neighborhood `v` of `x` inside `u`, and finally `r` small enough that the ball of radius `r` in the extended chart is contained in the image of `v`. We claim that points at Riemannian distance at most `r / C` of `x` are inside `u` (and therefore inside `s`). To prove this, consider a path of length at most `r / C` starting from `x`. While it stays inside `u`, then by the derivative control its image in the extended chart has length at most `r`, so it cannot exit the ball of radius `r`, which means that in the manifold it is inside `v` (which is strictly inside `u`). This means that the path will stay inside `u` for a little bit longer, by openness of `v`. Iterating this argument, it follows that the path will remain inside `u` for the whole time interval `[0, 1]`. In particular, its right endpoint is inside `u`, as desired. The formalization of this argument goes through the lemma `IsClosed.Icc_subset_of_forall_mem_nhdsGT_of_mem` which gives an induction-like principle over real intervals. -/ -- first introduce a neighborhood where the derivative of the extended chart is bounded by `C` rcases eventually_enorm_mfderiv_extChartAt_lt I x with ⟨C, C_pos, hC⟩ -- let `u` be a closed neighborhood, inside `s`, with the derivative control obtain ⟨u, u_mem, u_closed, us, hu, uc⟩ : ∃ u ∈ 𝓝 x, IsClosed u ∧ u ⊆ s ∧ u ⊆ {y | ‖mfderiv I 𝓘(ℝ, E) (extChartAt I x) y‖ₑ < C} ∧ u ⊆ (extChartAt I x).source := by have := Filter.inter_mem (Filter.inter_mem hs hC) (extChartAt_source_mem_nhds (I := I) x) rcases exists_mem_nhds_isClosed_subset this with ⟨u, u_mem, u_closed, hu⟩ simp only [subset_inter_iff] at hu exact ⟨u, u_mem, u_closed, hu.1.1, hu.1.2, hu.2⟩ have uc' : u ⊆ (chartAt H x).source := by simpa [extChartAt_source I x] using uc -- let `v` be a smaller open neighborhood, inside `u`. obtain ⟨v, ⟨v_mem, v_open⟩, hv⟩ : ∃ v, (v ∈ 𝓝 x ∧ IsOpen v) ∧ v ⊆ u := (nhds_basis_opens' x).mem_iff.1 u_mem -- let `r > 0` be small enough that, in the extended chart, the ball of radius `r` is contained -- in the image of `v`. obtain ⟨r, r_pos, hr⟩ : ∃ r > 0, ball (extChartAt I x x) r ⊆ (extChartAt I x).symm ⁻¹' v := Metric.mem_nhds_iff.1 (extChartAt_preimage_mem_nhds v_mem) lift r to ℝ≥0 using r_pos.le simp only [gt_iff_lt, NNReal.coe_pos] at r_pos -- the desired constant will be `c := r / C` refine ⟨r / C, by positivity, ?_⟩ intro y hy -- consider a path `γ` of length `< r / C` from `x` to a point `y`. We will show that `y` belongs -- to `u`. rcases exists_lt_locally_constant_of_riemannianEDist_lt hy zero_lt_one with ⟨γ, hγx, hγy, γ_smooth, hγ, -⟩ let A := γ ⁻¹' u have zero_mem : 0 ∈ A := by simpa [hγx, A] using mem_of_mem_nhds u_mem have A_closed : IsClosed (A ∩ Icc 0 1) := (u_closed.preimage γ_smooth.continuous).inter isClosed_Icc suffices Icc 0 1 ⊆ A by apply us have : 1 ∈ A := this ⟨zero_le_one, le_rfl⟩ simpa [A, hγy, us] apply A_closed.Icc_subset_of_forall_mem_nhdsGT_of_Icc_subset zero_mem rintro t₁ ⟨ht₁0, ht₁1⟩ t₁_mem suffices γ t₁ ∈ v from γ_smooth.continuous.continuousWithinAt <| mem_of_superset (v_open.mem_nhds this) hv let γ' := extChartAt I x ∘ γ have hC : ContMDiffOn 𝓘(ℝ) 𝓘(ℝ, E) 1 γ' (Icc 0 t₁) := ContMDiffOn.comp (I' := I) (t := (chartAt H x).source) contMDiffOn_extChartAt γ_smooth.contMDiffOn (fun t' ht' ↦ uc' <| t₁_mem ht') have : ‖γ' t₁ - γ' 0‖ₑ < r := by rcases ht₁0.eq_or_lt with rfl | h't' · simp [r_pos] calc ‖γ' t₁ - γ' 0‖ₑ _ ≤ ∫⁻ t' in Icc 0 t₁, ‖derivWithin γ' (Icc 0 t₁) t'‖ₑ := by apply enorm_sub_le_lintegral_derivWithin_Icc_of_contDiffOn_Icc _ ht₁0 rwa [← contMDiffOn_iff_contDiffOn] _ = ∫⁻ t' in Icc 0 t₁, ‖mfderivWithin 𝓘(ℝ) 𝓘(ℝ, E) γ' (Icc 0 t₁) t' 1‖ₑ := by simp_rw [← fderivWithin_derivWithin, mfderivWithin_eq_fderivWithin] rfl _ ≤ ∫⁻ t' in Icc 0 t₁, C * ‖mfderivWithin 𝓘(ℝ) I γ (Icc 0 t₁) t' 1‖ₑ := by apply setLIntegral_mono' measurableSet_Icc (fun t' ht' ↦ ?_) have : mfderivWithin 𝓘(ℝ) 𝓘(ℝ, E) γ' (Icc 0 t₁) t' = (mfderiv I 𝓘(ℝ, E) (extChartAt I x) (γ t')) ∘L (mfderivWithin 𝓘(ℝ) I γ (Icc 0 t₁) t') := by apply mfderiv_comp_mfderivWithin · refine mdifferentiableAt_extChartAt (uc' ?_) apply t₁_mem ht' · exact (γ_smooth.mdifferentiable le_rfl).mdifferentiableOn _ ht' · rw [uniqueMDiffWithinAt_iff_uniqueDiffWithinAt] exact uniqueDiffOn_Icc h't' _ ht' have : mfderivWithin 𝓘(ℝ) 𝓘(ℝ, E) γ' (Icc 0 t₁) t' 1 = (mfderiv I 𝓘(ℝ, E) (extChartAt I x) (γ t')) (mfderivWithin 𝓘(ℝ) I γ (Icc 0 t₁) t' 1) := congr($this 1) rw [this] apply (ContinuousLinearMap.le_opNorm_enorm _ _).trans gcongr refine (hu ?_).le apply t₁_mem ht' _ = C * pathELength I γ 0 t₁ := by rw [lintegral_const_mul' _ _ ENNReal.coe_ne_top, pathELength_eq_lintegral_mfderivWithin_Icc] _ ≤ C * pathELength I γ 0 1 := by gcongr _ < C * (r / C) := by gcongr · exact ENNReal.coe_ne_top · exact hγ.trans_eq (ENNReal.coe_div C_pos.ne') _ = r := (ENNReal.eq_div_iff (by simpa using C_pos.ne') ENNReal.coe_ne_top).mp rfl have : γ' t₁ ∈ (extChartAt I x).symm ⁻¹' v := by apply hr rw [← Metric.emetric_ball_nnreal, EMetric.mem_ball, edist_eq_enorm_sub] convert this simp [γ', hγx] convert mem_preimage.1 this simp only [Function.comp_apply, γ', (extChartAt I x).left_inv <| uc <| t₁_mem (right_mem_Icc.mpr ht₁0)] @[deprecated (since := "2025-09-18")] alias setOf_riemmanianEDist_lt_subset_nhds := setOf_riemannianEDist_lt_subset_nhds /-- Any neighborhood of `x` contains all the points which are close enough to `x` for the Riemannian distance, `ℝ≥0∞` version. -/ lemma setOf_riemannianEDist_lt_subset_nhds' [RegularSpace M] {x : M} {s : Set M} (hs : s ∈ 𝓝 x) : ∃ c > 0, {y | riemannianEDist I x y < c} ⊆ s := by rcases setOf_riemannianEDist_lt_subset_nhds I hs with ⟨c, c_pos, hc⟩ exact ⟨c, mod_cast c_pos, hc⟩ @[deprecated (since := "2025-09-18")] alias setOf_riemmanianEDist_lt_subset_nhds' := setOf_riemannianEDist_lt_subset_nhds' variable (M) in /-- The pseudoemetric space structure associated to a Riemannian metric on a manifold. Designed so that the topology is defeq to the original one. This should only be used when constructing data in specific situations. To develop the theory, one should rather assume that there is an already existing emetric space structure, which satisfies additionally the predicate `IsRiemannianManifold I M`. -/ @[reducible] def PseudoEmetricSpace.ofRiemannianMetric [RegularSpace M] : PseudoEMetricSpace M := PseudoEmetricSpace.ofEdistOfTopology (riemannianEDist I (M := M)) (fun _ ↦ riemannianEDist_self) (fun _ _ ↦ riemannianEDist_comm) (fun _ _ _ ↦ riemannianEDist_triangle) (fun x ↦ (basis_sets (𝓝 x)).to_hasBasis' (fun _ hs ↦ setOf_riemannianEDist_lt_subset_nhds' I hs) (fun _ hc ↦ eventually_riemannianEDist_lt I x hc)) /-- Given a manifold with a Riemannian metric, consider the associated Riemannian distance. Then by definition the distance is the infimum of the length of paths between the points, i.e., the manifold satisfies the `IsRiemannianManifold I M` predicate. -/ instance [RegularSpace M] : letI : PseudoEMetricSpace M := PseudoEmetricSpace.ofRiemannianMetric I M IsRiemannianManifold I M := by letI : PseudoEMetricSpace M := PseudoEmetricSpace.ofRiemannianMetric I M exact ⟨fun x y ↦ rfl⟩ variable (M) in /-- The emetric space structure associated to a Riemannian metric on a manifold. Designed so that the topology is defeq to the original one. This should only be used when constructing data in specific situations. To develop the theory, one should rather assume that there is an already existing emetric space structure, which satisfies additionally the predicate `IsRiemannianManifold I M`. -/ @[reducible] def EmetricSpace.ofRiemannianMetric [T3Space M] : EMetricSpace M := letI : PseudoEMetricSpace M := PseudoEmetricSpace.ofRiemannianMetric I M EMetricSpace.ofT0PseudoEMetricSpace M end
.lake/packages/mathlib/Mathlib/Geometry/Manifold/Riemannian/PathELength.lean
import Mathlib.Analysis.Calculus.AddTorsor.AffineMap import Mathlib.Analysis.SpecialFunctions.SmoothTransition import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace import Mathlib.Geometry.Manifold.Instances.Icc import Mathlib.MeasureTheory.Constructions.UnitInterval import Mathlib.MeasureTheory.Function.JacobianOneDim /-! # Lengths of paths in manifolds Consider a manifold in which the tangent spaces have an enormed structure. Then one defines `pathELength γ a b` as the length of the path `γ : ℝ → M` between `a` and `b`, i.e., the integral of the norm of its derivative on `Icc a b`. We give several ways to write this quantity (as an integral over `Icc`, or `Ioo`, or the subtype `Icc`, using either `mfderiv` or `mfderivWithin`). We show that this notion is invariant under reparameterization by a monotone map, in `pathELength_comp_of_monotoneOn`. We define `riemannianEDist x y` as the infimum of the length of `C^1` paths between `x` and `y`. We prove, in `exists_lt_locally_constant_of_riemannianEDist_lt`, that it is also the infimum on such path that are moreover locally constant near their endpoints. Such paths can be glued while retaining the `C^1` property. We deduce that `riemannianEDist` satisfies the triangle inequality, in `riemannianEDist_triangle`. Note that `riemannianEDist x y` could also be named `finslerEDist x y` as we do not require that the metric comes from an inner product space. However, as all the current applications in mathlib are to Riemannian spaces we stick with the simpler name. This could be changed when Finsler manifolds are studied in mathlib. -/ open Set MeasureTheory open scoped Manifold ENNReal ContDiff Topology noncomputable section variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {n : WithTop ℕ∞} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] namespace Manifold variable [∀ (x : M), ENorm (TangentSpace I x)] {a b c a' b' : ℝ} {γ γ' : ℝ → M} variable (I) in /-- The length on `Icc a b` of a path into a manifold, where the path is defined on the whole real line. We use the whole real line to avoid subtype hell in API, but this is equivalent to considering functions on the manifold with boundary `Icc a b`, see `lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc`. We use `mfderiv` instead of `mfderivWithin` in the definition as these coincide (apart from the two endpoints which have zero measure) and `mfderiv` is easier to manipulate. However, we give a lemma `pathELength_eq_integral_mfderivWithin_Icc` to rewrite with the `mfderivWithin` form. -/ irreducible_def pathELength (γ : ℝ → M) (a b : ℝ) : ℝ≥0∞ := ∫⁻ t in Icc a b, ‖mfderiv 𝓘(ℝ) I γ t 1‖ₑ lemma pathELength_eq_lintegral_mfderiv_Icc : pathELength I γ a b = ∫⁻ t in Icc a b, ‖mfderiv 𝓘(ℝ) I γ t 1‖ₑ := by simp [pathELength] lemma pathELength_eq_lintegral_mfderiv_Ioo : pathELength I γ a b = ∫⁻ t in Ioo a b, ‖mfderiv 𝓘(ℝ) I γ t 1‖ₑ := by rw [pathELength_eq_lintegral_mfderiv_Icc, restrict_Ioo_eq_restrict_Icc] lemma pathELength_eq_lintegral_mfderivWithin_Icc : pathELength I γ a b = ∫⁻ t in Icc a b, ‖mfderivWithin 𝓘(ℝ) I γ (Icc a b) t 1‖ₑ := by -- we use that the endpoints have measure 0 to rewrite on `Ioo a b`, where `mfderiv` and -- `mfderivWithin` coincide. rw [pathELength_eq_lintegral_mfderiv_Icc, ← restrict_Ioo_eq_restrict_Icc] apply setLIntegral_congr_fun measurableSet_Ioo (fun t ht ↦ ?_) rw [mfderivWithin_of_mem_nhds] exact Icc_mem_nhds ht.1 ht.2 @[simp] lemma pathELength_self : pathELength I γ a a = 0 := by simp [pathELength] lemma pathELength_congr_Ioo (h : EqOn γ γ' (Ioo a b)) : pathELength I γ a b = pathELength I γ' a b := by simp only [pathELength_eq_lintegral_mfderiv_Ioo] apply setLIntegral_congr_fun measurableSet_Ioo (fun t ht ↦ ?_) have A : γ t = γ' t := h ht congr! 2 apply Filter.EventuallyEq.mfderiv_eq filter_upwards [Ioo_mem_nhds ht.1 ht.2] with a ha using h ha lemma pathELength_congr (h : EqOn γ γ' (Icc a b)) : pathELength I γ a b = pathELength I γ' a b := pathELength_congr_Ioo (fun _ hx ↦ h ⟨hx.1.le, hx.2.le⟩) @[gcongr] lemma pathELength_mono (h : a' ≤ a) (h' : b ≤ b') : pathELength I γ a b ≤ pathELength I γ a' b' := by simpa [pathELength_eq_lintegral_mfderiv_Icc] using lintegral_mono_set (Icc_subset_Icc h h') lemma pathELength_add (h : a ≤ b) (h' : b ≤ c) : pathELength I γ a b + pathELength I γ b c = pathELength I γ a c := by symm have : Icc a c = Icc a b ∪ Ioc b c := (Icc_union_Ioc_eq_Icc h h').symm rw [pathELength, this, lintegral_union measurableSet_Ioc]; swap · exact disjoint_iff_forall_ne.mpr (fun a ha b hb ↦ (ha.2.trans_lt hb.1).ne) simp [restrict_Ioc_eq_restrict_Icc, pathELength] attribute [local instance] Measure.Subtype.measureSpace /-- Given a path `γ` defined on the manifold with boundary `[a, b]`, its length (as the integral of the norm of its manifold derivative) coincides with `pathELength` of the lift of `γ` to the real line, between `a` and `b`. -/ lemma lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc {a b : ℝ} [h : Fact (a < b)] {γ : Icc a b → M} : ∫⁻ t, ‖mfderiv (𝓡∂ 1) I γ t 1‖ₑ = pathELength I (γ ∘ (projIcc a b h.out.le)) a b := by rw [pathELength_eq_lintegral_mfderivWithin_Icc] simp_rw [← mfderivWithin_comp_projIcc_one] have : MeasurePreserving (Subtype.val : Icc a b → ℝ) volume (volume.restrict (Icc a b)) := measurePreserving_subtype_coe measurableSet_Icc rw [← MeasurePreserving.lintegral_comp_emb this (MeasurableEmbedding.subtype_coe measurableSet_Icc)] congr ext t have : t = projIcc a b h.out.le (t : ℝ) := by simp congr open MeasureTheory variable [∀ (x : M), ENormSMulClass ℝ (TangentSpace I x)] /-- The length of a path in a manifold is invariant under a monotone reparametrization. -/ lemma pathELength_comp_of_monotoneOn {f : ℝ → ℝ} (h : a ≤ b) (hf : MonotoneOn f (Icc a b)) (h'f : DifferentiableOn ℝ f (Icc a b)) (hγ : MDifferentiableOn 𝓘(ℝ) I γ (Icc (f a) (f b))) : pathELength I (γ ∘ f) a b = pathELength I γ (f a) (f b) := by rcases h.eq_or_lt with rfl | h · simp have f_im : f '' (Icc a b) = Icc (f a) (f b) := h'f.continuousOn.image_Icc_of_monotoneOn h.le hf simp only [pathELength_eq_lintegral_mfderivWithin_Icc, ← f_im] have B (t) (ht : t ∈ Icc a b) : HasDerivWithinAt f (derivWithin f (Icc a b) t) (Icc a b) t := (h'f t ht).hasDerivWithinAt rw [lintegral_image_eq_lintegral_deriv_mul_of_monotoneOn measurableSet_Icc B hf] apply setLIntegral_congr_fun measurableSet_Icc (fun t ht ↦ ?_) have : (mfderivWithin 𝓘(ℝ, ℝ) I (γ ∘ f) (Icc a b) t) = (mfderivWithin 𝓘(ℝ, ℝ) I γ (Icc (f a) (f b)) (f t)) ∘L mfderivWithin 𝓘(ℝ) 𝓘(ℝ) f (Icc a b) t := by rw [← f_im] at hγ ⊢ apply mfderivWithin_comp · apply hγ _ (mem_image_of_mem _ ht) · rw [mdifferentiableWithinAt_iff_differentiableWithinAt] exact h'f _ ht · exact subset_preimage_image _ _ · rw [uniqueMDiffWithinAt_iff_uniqueDiffWithinAt] exact uniqueDiffOn_Icc h _ ht rw [this] simp only [Function.comp_apply, ContinuousLinearMap.coe_comp'] have : mfderivWithin 𝓘(ℝ) 𝓘(ℝ) f (Icc a b) t 1 = derivWithin f (Icc a b) t • (1 : TangentSpace 𝓘(ℝ) (f t)) := by simp only [mfderivWithin_eq_fderivWithin, ← fderivWithin_derivWithin, smul_eq_mul, mul_one] rfl rw [this] have : 0 ≤ derivWithin f (Icc a b) t := hf.derivWithin_nonneg simp only [map_smul, enorm_smul, ← Real.enorm_of_nonneg this, f_im] /-- The length of a path in a manifold is invariant under an antitone reparametrization. -/ lemma pathELength_comp_of_antitoneOn {f : ℝ → ℝ} (h : a ≤ b) (hf : AntitoneOn f (Icc a b)) (h'f : DifferentiableOn ℝ f (Icc a b)) (hγ : MDifferentiableOn 𝓘(ℝ) I γ (Icc (f b) (f a))) : pathELength I (γ ∘ f) a b = pathELength I γ (f b) (f a) := by rcases h.eq_or_lt with rfl | h · simp have f_im : f '' (Icc a b) = Icc (f b) (f a) := h'f.continuousOn.image_Icc_of_antitoneOn h.le hf simp only [pathELength_eq_lintegral_mfderivWithin_Icc, ← f_im] have B (t) (ht : t ∈ Icc a b) : HasDerivWithinAt f (derivWithin f (Icc a b) t) (Icc a b) t := (h'f t ht).hasDerivWithinAt rw [lintegral_image_eq_lintegral_deriv_mul_of_antitoneOn measurableSet_Icc B hf] apply setLIntegral_congr_fun measurableSet_Icc (fun t ht ↦ ?_) have : (mfderivWithin 𝓘(ℝ, ℝ) I (γ ∘ f) (Icc a b) t) = (mfderivWithin 𝓘(ℝ, ℝ) I γ (Icc (f b) (f a)) (f t)) ∘L mfderivWithin 𝓘(ℝ) 𝓘(ℝ) f (Icc a b) t := by rw [← f_im] at hγ ⊢ apply mfderivWithin_comp · apply hγ _ (mem_image_of_mem _ ht) · rw [mdifferentiableWithinAt_iff_differentiableWithinAt] exact h'f _ ht · exact subset_preimage_image _ _ · rw [uniqueMDiffWithinAt_iff_uniqueDiffWithinAt] exact uniqueDiffOn_Icc h _ ht rw [this] simp only [Function.comp_apply, ContinuousLinearMap.coe_comp'] have : mfderivWithin 𝓘(ℝ) 𝓘(ℝ) f (Icc a b) t 1 = derivWithin f (Icc a b) t • (1 : TangentSpace 𝓘(ℝ) (f t)) := by simp only [mfderivWithin_eq_fderivWithin, ← fderivWithin_derivWithin, smul_eq_mul, mul_one] rfl rw [this] have : 0 ≤ -derivWithin f (Icc a b) t := by simp [hf.derivWithin_nonpos] simp only [map_smul, enorm_smul, f_im, ← Real.enorm_of_nonneg this, enorm_neg] section variable {x y z : M} {r : ℝ≥0∞} {a b : ℝ} variable (I) in /-- The Riemannian extended distance between two points, in a manifold where the tangent spaces have an extended norm, defined as the infimum of the lengths of `C^1` paths between the points. -/ noncomputable irreducible_def riemannianEDist (x y : M) : ℝ≥0∞ := ⨅ (γ : Path x y) (_ : ContMDiff (𝓡∂ 1) I 1 γ), ∫⁻ x, ‖mfderiv (𝓡∂ 1) I γ x 1‖ₑ /-- The Riemannian edistance is bounded above by the length of any `C^1` path from `x` to `y`. Here, we express this using a path defined on the whole real line, considered on some interval `[a, b]`. -/ lemma riemannianEDist_le_pathELength {γ : ℝ → M} (hγ : ContMDiffOn 𝓘(ℝ) I 1 γ (Icc a b)) (ha : γ a = x) (hb : γ b = y) (hab : a ≤ b) : riemannianEDist I x y ≤ pathELength I γ a b := by let η : ℝ →ᴬ[ℝ] ℝ := ContinuousAffineMap.lineMap a b have hη : ContMDiffOn 𝓘(ℝ) I 1 (γ ∘ η) (Icc 0 1) := by apply hγ.comp · rw [contMDiffOn_iff_contDiffOn] exact η.contDiff.contDiffOn · rw [← image_subset_iff, ContinuousAffineMap.coe_lineMap_eq, ← segment_eq_image_lineMap] simp [hab] let f : unitInterval → M := fun t ↦ (γ ∘ η) t have hf : ContMDiff (𝓡∂ 1) I 1 f := by rw [← contMDiffOn_comp_projIcc_iff] apply hη.congr (fun t ht ↦ ?_) simp only [Function.comp_apply, f, projIcc_of_mem, ht] let g : Path x y := by refine ⟨⟨f, hf.continuous⟩, ?_, ?_⟩ <;> simp [f, η, ContinuousAffineMap.coe_lineMap_eq, ha, hb] have A : riemannianEDist I x y ≤ ∫⁻ x, ‖mfderiv (𝓡∂ 1) I g x 1‖ₑ := by rw [riemannianEDist]; exact biInf_le _ hf apply A.trans_eq rw [lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc] have E : pathELength I (g ∘ projIcc 0 1 zero_le_one) 0 1 = pathELength I (γ ∘ η) 0 1 := by apply pathELength_congr (fun t ht ↦ ?_) simp only [Function.comp_apply, ht, projIcc_of_mem] rfl rw [E, pathELength_comp_of_monotoneOn zero_le_one _ η.differentiableOn] · simp [η, ContinuousAffineMap.coe_lineMap_eq] · simpa [η, ContinuousAffineMap.coe_lineMap_eq] using hγ.mdifferentiableOn le_rfl · apply (AffineMap.lineMap_mono hab).monotoneOn omit [∀ (x : M), ENormSMulClass ℝ (TangentSpace I x)] in /-- If some `r` is strictly larger than the Riemannian edistance between two points, there exists a path between these two points of length `< r`. Here, we get such a path on `[0, 1]`. For a more precise version giving locally constant paths around the endpoints, see `exists_lt_locally_constant_of_riemannianEDist_lt` -/ lemma exists_lt_of_riemannianEDist_lt (hr : riemannianEDist I x y < r) : ∃ γ : ℝ → M, γ 0 = x ∧ γ 1 = y ∧ ContMDiffOn 𝓘(ℝ) I 1 γ (Icc 0 1) ∧ pathELength I γ 0 1 < r := by simp only [riemannianEDist, iInf_lt_iff, exists_prop] at hr rcases hr with ⟨γ, γ_smooth, hγ⟩ refine ⟨γ ∘ (projIcc 0 1 zero_le_one), by simp, by simp, contMDiffOn_comp_projIcc_iff.2 γ_smooth, ?_⟩ rwa [← lintegral_norm_mfderiv_Icc_eq_pathELength_projIcc] /-- If some `r` is strictly larger than the Riemannian edistance between two points, there exists a path between these two points of length `< r`. Here, we get such a path on an arbitrary interval `[a, b]` with `a < b`, and moreover we ensure that the path is locally constant around `a` and `b`, which is convenient for gluing purposes. -/ lemma exists_lt_locally_constant_of_riemannianEDist_lt (hr : riemannianEDist I x y < r) (hab : a < b) : ∃ γ : ℝ → M, γ a = x ∧ γ b = y ∧ ContMDiff 𝓘(ℝ) I 1 γ ∧ pathELength I γ a b < r ∧ γ =ᶠ[𝓝 a] (fun _ ↦ x) ∧ γ =ᶠ[𝓝 b] (fun _ ↦ y) := by /- We start from a path from `x` to `y` defined on `[0, 1]` with length `< r`. Then, we reparameterize it using a smooth monotone map `η` from `[a, b]` to `[0, 1]` which is moreover locally constant around `a` and `b`. Such a map is easy to build with `Real.smoothTransition`. Note that this is a very standard construction in differential topology. TODO: refactor once we have more differential topology in Mathlib and this gets duplicated. -/ rcases exists_lt_of_riemannianEDist_lt hr with ⟨γ, hγx, hγy, γ_smooth, hγ⟩ rcases exists_between hab with ⟨a', haa', ha'b⟩ rcases exists_between ha'b with ⟨b', ha'b', hb'b⟩ let η (t : ℝ) : ℝ := Real.smoothTransition ((b' - a') ⁻¹ * (t - a')) have A (t) (ht : t < a') : η t = 0 := by simp only [η, Real.smoothTransition.zero_iff_nonpos] apply mul_nonpos_of_nonneg_of_nonpos · simpa using ha'b'.le · linarith have A' (t) (ht : t < a') : (γ ∘ η) t = x := by simp [A t ht, hγx] have B (t) (ht : b' < t) : η t = 1 := by simp only [η, Real.smoothTransition.eq_one_iff_one_le, inv_mul_eq_div] rw [one_le_div₀] <;> linarith have B' (t) (ht : b' < t) : (γ ∘ η) t = y := by simp [B t ht, hγy] refine ⟨γ ∘ η, A' _ haa', B' _ hb'b, ?_, ?_, ?_, ?_⟩ · rw [← contMDiffOn_univ] apply γ_smooth.comp · rw [contMDiffOn_univ, contMDiff_iff_contDiff] fun_prop · intro t ht exact ⟨Real.smoothTransition.nonneg _, Real.smoothTransition.le_one _⟩ · convert hγ using 1 rw [← A a haa', ← B b hb'b] apply pathELength_comp_of_monotoneOn hab.le · apply Monotone.monotoneOn apply Real.smoothTransition.monotone.comp intro t u htu dsimp only gcongr simpa only [inv_nonneg, sub_nonneg] using ha'b'.le · simp only [η] apply (ContDiff.contDiffOn _).differentiableOn le_rfl fun_prop · rw [A a haa', B b hb'b] apply γ_smooth.mdifferentiableOn le_rfl · filter_upwards [Iio_mem_nhds haa'] with t ht using A' t ht · filter_upwards [Ioi_mem_nhds hb'b] with t ht using B' t ht lemma riemannianEDist_self : riemannianEDist I x x = 0 := by apply le_antisymm _ bot_le exact (riemannianEDist_le_pathELength (γ := fun (t : ℝ) ↦ x) (a := 0) (b := 0) contMDiffOn_const rfl rfl le_rfl).trans_eq (by simp) lemma riemannianEDist_comm : riemannianEDist I x y = riemannianEDist I y x := by suffices H : ∀ x y, riemannianEDist I y x ≤ riemannianEDist I x y from le_antisymm (H y x) (H x y) intro x y apply le_of_forall_gt (fun r hr ↦ ?_) rcases exists_lt_locally_constant_of_riemannianEDist_lt hr zero_lt_one with ⟨γ, γ0, γ1, γ_smooth, hγ, -⟩ let η : ℝ → ℝ := fun t ↦ - t have h_smooth : ContMDiff 𝓘(ℝ) I 1 (γ ∘ η) := by apply γ_smooth.comp ?_ simp only [contMDiff_iff_contDiff] fun_prop have : riemannianEDist I y x ≤ pathELength I (γ ∘ η) (η 1) (η 0) := by apply riemannianEDist_le_pathELength h_smooth.contMDiffOn <;> simp [η, γ0, γ1] rw [← pathELength_comp_of_antitoneOn zero_le_one] at this; rotate_left · exact monotone_id.neg.antitoneOn _ · exact differentiableOn_neg _ · exact h_smooth.contMDiffOn.mdifferentiableOn le_rfl apply this.trans_lt convert hγ ext t simp [η] lemma riemannianEDist_triangle : riemannianEDist I x z ≤ riemannianEDist I x y + riemannianEDist I y z := by apply le_of_forall_gt (fun r hr ↦ ?_) rcases ENNReal.exists_add_lt_of_add_lt hr with ⟨u, hu, v, hv, huv⟩ rcases exists_lt_locally_constant_of_riemannianEDist_lt hu zero_lt_one with ⟨γ₁, hγ₁0, hγ₁1, hγ₁_smooth, hγ₁, -, hγ₁_const⟩ rcases exists_lt_locally_constant_of_riemannianEDist_lt hv one_lt_two with ⟨γ₂, hγ₂1, hγ₂2, hγ₂_smooth, hγ₂, hγ₂_const, -⟩ let γ := piecewise (Iic 1) γ₁ γ₂ have : riemannianEDist I x z ≤ pathELength I γ 0 2 := by apply riemannianEDist_le_pathELength · apply ContMDiff.contMDiffOn exact ContMDiff.piecewise_Iic hγ₁_smooth hγ₂_smooth (hγ₁_const.trans hγ₂_const.symm) · simp [γ, hγ₁0] · simp [γ, hγ₂2] · exact zero_le_two apply this.trans_lt (lt_trans ?_ huv) rw [← pathELength_add zero_le_one one_le_two] gcongr · convert hγ₁ using 1 apply pathELength_congr intro t ht simp [γ, ht.2] · convert hγ₂ using 1 apply pathELength_congr_Ioo intro t ht simp [γ, ht.1] end end Manifold
.lake/packages/mathlib/Mathlib/Geometry/Manifold/IntegralCurve/UniformTime.lean
import Mathlib.Geometry.Manifold.IntegralCurve.ExistUnique /-! # Uniform time lemma for the global existence of integral curves ## Main results * `exists_isMIntegralCurve_of_isMIntegralCurveOn`: If there exists `ε > 0` such that the local integral curve at each point `x : M` is defined at least on an open interval `Ioo (-ε) ε`, then every point on `M` has a global integral curve passing through it. ## Reference * [Lee, J. M. (2012). _Introduction to Smooth Manifolds_. Springer New York.][lee2012] ## Tags integral curve, vector field, global existence -/ open scoped Topology open Function Set variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I 1 M] [T2Space M] {γ γ' : ℝ → M} {v : (x : M) → TangentSpace I x} {s s' : Set ℝ} {t₀ : ℝ} /-- This is the uniqueness theorem of integral curves applied to a real-indexed family of integral curves with the same starting point. -/ lemma eqOn_of_isMIntegralCurveOn_Ioo [BoundarylessManifold I M] (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) {x : M} (γ : ℝ → ℝ → M) (hγx : ∀ a, γ a 0 = x) (hγ : ∀ a > 0, IsMIntegralCurveOn (γ a) v (Ioo (-a) a)) {a a' : ℝ} (hpos : 0 < a') (hle : a' ≤ a) : EqOn (γ a') (γ a) (Ioo (-a') a') := by apply isMIntegralCurveOn_Ioo_eqOn_of_contMDiff_boundaryless _ hv (hγ a' (by positivity)) ((hγ a (lt_of_lt_of_le hpos hle)).mono _) (by rw [hγx a, hγx a']) · rw [mem_Ioo] exact ⟨neg_lt_zero.mpr hpos, by positivity⟩ · apply Ioo_subset_Ioo <;> linarith @[deprecated (since := "2025-08-12")] alias eqOn_of_isIntegralCurveOn_Ioo := eqOn_of_isMIntegralCurveOn_Ioo /-- For a family of integral curves `γ : ℝ → ℝ → M` with the same starting point `γ 0 = x` such that each `γ a` is defined on `Ioo (-a) a`, the global curve `γ_ext := fun t ↦ γ (|t| + 1) t` agrees with each `γ a` on `Ioo (-a) a`. This will help us show that `γ_ext` is a global integral curve. -/ lemma eqOn_abs_add_one_of_isMIntegralCurveOn_Ioo [BoundarylessManifold I M] (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) {x : M} (γ : ℝ → ℝ → M) (hγx : ∀ a, γ a 0 = x) (hγ : ∀ a > 0, IsMIntegralCurveOn (γ a) v (Ioo (-a) a)) {a : ℝ} : EqOn (fun t ↦ γ (|t| + 1) t) (γ a) (Ioo (-a) a) := by intro t ht by_cases! hlt : |t| + 1 < a · exact eqOn_of_isMIntegralCurveOn_Ioo hv γ hγx hγ (by positivity) hlt.le (abs_lt.mp <| lt_add_one _) · exact eqOn_of_isMIntegralCurveOn_Ioo hv γ hγx hγ (neg_lt_self_iff.mp <| lt_trans ht.1 ht.2) hlt ht |>.symm @[deprecated (since := "2025-08-12")] alias eqOn_abs_add_one_of_isIntegralCurveOn_Ioo := eqOn_abs_add_one_of_isMIntegralCurveOn_Ioo /-- For a family of integral curves `γ : ℝ → ℝ → M` with the same starting point `γ 0 = x` such that each `γ a` is defined on `Ioo (-a) a`, the function `γ_ext := fun t ↦ γ (|t| + 1) t` is a global integral curve. -/ lemma isMIntegralCurve_abs_add_one_of_isMIntegralCurveOn_Ioo [BoundarylessManifold I M] (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) {x : M} (γ : ℝ → ℝ → M) (hγx : ∀ a, γ a 0 = x) (hγ : ∀ a > 0, IsMIntegralCurveOn (γ a) v (Ioo (-a) a)) : IsMIntegralCurve (fun t ↦ γ (|t| + 1) t) v := by intro t have ht : t ∈ Ioo (-(|t| + 1)) (|t| + 1) := by rw [mem_Ioo, ← abs_lt] exact lt_add_one _ apply HasMFDerivAt.congr_of_eventuallyEq (f := γ (|t| + 1)) · exact hγ (|t| + 1) (by positivity) _ ht |>.hasMFDerivAt (Ioo_mem_nhds ht.1 ht.2) · rw [Filter.eventuallyEq_iff_exists_mem] refine ⟨Ioo (-(|t| + 1)) (|t| + 1), ?_, eqOn_abs_add_one_of_isMIntegralCurveOn_Ioo hv γ hγx hγ⟩ have : |t| < |t| + 1 := lt_add_of_pos_right |t| zero_lt_one rw [abs_lt] at this exact Ioo_mem_nhds this.1 this.2 @[deprecated (since := "2025-08-12")] alias isIntegralCurve_abs_add_one_of_isIntegralCurveOn_Ioo := isMIntegralCurve_abs_add_one_of_isMIntegralCurveOn_Ioo /-- The existence of a global integral curve is equivalent to the existence of a family of local integral curves `γ : ℝ → ℝ → M` with the same starting point `γ 0 = x` such that each `γ a` is defined on `Ioo (-a) a`. -/ lemma exists_isMIntegralCurve_iff_exists_isMIntegralCurveOn_Ioo [BoundarylessManifold I M] (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) (x : M) : (∃ γ, γ 0 = x ∧ IsMIntegralCurve γ v) ↔ ∀ a, ∃ γ, γ 0 = x ∧ IsMIntegralCurveOn γ v (Ioo (-a) a) := by refine ⟨fun ⟨γ, h1, h2⟩ _ ↦ ⟨γ, h1, h2.isMIntegralCurveOn _⟩, fun h ↦ ?_⟩ choose γ hγx hγ using h exact ⟨fun t ↦ γ (|t| + 1) t, hγx (|0| + 1), isMIntegralCurve_abs_add_one_of_isMIntegralCurveOn_Ioo hv γ hγx (fun a _ ↦ hγ a)⟩ @[deprecated (since := "2025-08-12")] alias exists_isIntegralCurve_iff_exists_isIntegralCurveOn_Ioo := exists_isMIntegralCurve_iff_exists_isMIntegralCurveOn_Ioo /-- Let `γ` and `γ'` be integral curves defined on `Ioo a b` and `Ioo a' b'`, respectively. Then, `piecewise (Ioo a b) γ γ'` is equal to `γ` and `γ'` in their respective domains. `Set.piecewise_eqOn` shows the equality for `γ` by definition, while this lemma shows the equality for `γ'` by the uniqueness of integral curves. -/ lemma eqOn_piecewise_of_isMIntegralCurveOn_Ioo [BoundarylessManifold I M] (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) {a b a' b' : ℝ} (hγ : IsMIntegralCurveOn γ v (Ioo a b)) (hγ' : IsMIntegralCurveOn γ' v (Ioo a' b')) (ht₀ : t₀ ∈ Ioo a b ∩ Ioo a' b') (h : γ t₀ = γ' t₀) : EqOn (piecewise (Ioo a b) γ γ') γ' (Ioo a' b') := by intro t ht suffices H : EqOn γ γ' (Ioo (max a a') (min b b')) by by_cases hmem : t ∈ Ioo a b · rw [piecewise, if_pos hmem] apply H simp [ht.1, ht.2, hmem.1, hmem.2] · rw [piecewise, if_neg hmem] apply isMIntegralCurveOn_Ioo_eqOn_of_contMDiff_boundaryless _ hv (hγ.mono (Ioo_subset_Ioo (le_max_left ..) (min_le_left ..))) (hγ'.mono (Ioo_subset_Ioo (le_max_right ..) (min_le_right ..))) h exact ⟨max_lt ht₀.1.1 ht₀.2.1, lt_min ht₀.1.2 ht₀.2.2⟩ @[deprecated (since := "2025-08-12")] alias eqOn_piecewise_of_isIntegralCurveOn_Ioo := eqOn_piecewise_of_isMIntegralCurveOn_Ioo /-- The extension of an integral curve by another integral curve is an integral curve. If two integral curves are defined on overlapping open intervals, and they agree at a point in their common domain, then they can be patched together to form a longer integral curve. This is stated for manifolds without boundary for simplicity. We actually only need to assume that the images of `γ` and `γ'` lie in the interior of the manifold. TODO: Generalise to manifolds with boundary. -/ lemma isMIntegralCurveOn_piecewise [BoundarylessManifold I M] (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) {a b a' b' : ℝ} (hγ : IsMIntegralCurveOn γ v (Ioo a b)) (hγ' : IsMIntegralCurveOn γ' v (Ioo a' b')) {t₀ : ℝ} (ht₀ : t₀ ∈ Ioo a b ∩ Ioo a' b') (h : γ t₀ = γ' t₀) : IsMIntegralCurveOn (piecewise (Ioo a b) γ γ') v (Ioo a b ∪ Ioo a' b') := by intro t ht by_cases hmem : t ∈ Ioo a b · rw [piecewise, if_pos hmem] apply hγ t hmem |>.hasMFDerivAt (Ioo_mem_nhds hmem.1 hmem.2) |>.hasMFDerivWithinAt (s := Ioo a b ∪ Ioo a' b') |>.congr_of_eventuallyEq _ (by rw [piecewise, if_pos hmem]) rw [Filter.eventuallyEq_iff_exists_mem] refine ⟨Ioo a b, ?_, fun _ ht' ↦ by rw [piecewise, if_pos ht']⟩ rw [(isOpen_Ioo.union isOpen_Ioo).nhdsWithin_eq ht] exact Ioo_mem_nhds hmem.1 hmem.2 · have ht' := ht rw [mem_union, or_iff_not_imp_left] at ht rw [piecewise, if_neg hmem] apply hγ' t (ht hmem) |>.hasMFDerivAt (Ioo_mem_nhds (ht hmem).1 (ht hmem).2) |>.hasMFDerivWithinAt (s := Ioo a b ∪ Ioo a' b') |>.congr_of_eventuallyEq _ (by rw [piecewise, if_neg hmem]) rw [Filter.eventuallyEq_iff_exists_mem] refine ⟨Ioo a' b', ?_, eqOn_piecewise_of_isMIntegralCurveOn_Ioo hv hγ hγ' ht₀ h⟩ rw [(isOpen_Ioo.union isOpen_Ioo).nhdsWithin_eq ht'] exact Ioo_mem_nhds (ht hmem).1 (ht hmem).2 @[deprecated (since := "2025-08-12")] alias isIntegralCurveOn_piecewise := isMIntegralCurveOn_piecewise /-- If there exists `ε > 0` such that the local integral curve at each point `x : M` is defined at least on an open interval `Ioo (-ε) ε`, then every point on `M` has a global integral curve passing through it. See Lemma 9.15, [J.M. Lee (2012)][lee2012]. -/ lemma exists_isMIntegralCurve_of_isMIntegralCurveOn [BoundarylessManifold I M] {v : (x : M) → TangentSpace I x} (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) {ε : ℝ} (hε : 0 < ε) (h : ∀ x : M, ∃ γ : ℝ → M, γ 0 = x ∧ IsMIntegralCurveOn γ v (Ioo (-ε) ε)) (x : M) : ∃ γ : ℝ → M, γ 0 = x ∧ IsMIntegralCurve γ v := by let s := { a | ∃ γ, γ 0 = x ∧ IsMIntegralCurveOn γ v (Ioo (-a) a) } suffices hbdd : ¬BddAbove s by rw [not_bddAbove_iff] at hbdd rw [exists_isMIntegralCurve_iff_exists_isMIntegralCurveOn_Ioo hv] intro a obtain ⟨y, ⟨γ, hγ1, hγ2⟩, hlt⟩ := hbdd a exact ⟨γ, hγ1, hγ2.mono <| Ioo_subset_Ioo (neg_le_neg hlt.le) hlt.le⟩ intro hbdd set asup := sSup s with hasup -- we will obtain two integral curves, one centred at some `t₀ > 0` with -- `0 ≤ asup - ε < t₀ < asup`; let `t₀ = asup - ε / 2` -- another centred at 0 with domain up to `a ∈ S` with `t₀ < a < asup` obtain ⟨a, ha, hlt⟩ := Real.add_neg_lt_sSup (⟨ε, h x⟩ : Set.Nonempty s) (ε := - (ε / 2)) (by rw [neg_lt, neg_zero]; exact half_pos hε) rw [mem_setOf] at ha rw [← hasup, ← sub_eq_add_neg] at hlt -- integral curve defined on `Ioo (-a) a` obtain ⟨γ, h0, hγ⟩ := ha -- integral curve starting at `-(asup - ε / 2)` with radius `ε` obtain ⟨γ1_aux, h1_aux, hγ1⟩ := h (γ (-(asup - ε / 2))) rw [isMIntegralCurveOn_comp_add (dt := asup - ε / 2)] at hγ1 set γ1 := γ1_aux ∘ (· + (asup - ε / 2)) with γ1_def have heq1 : γ1 (-(asup - ε / 2)) = γ (-(asup - ε / 2)) := by simp [γ1_def, h1_aux] -- integral curve starting at `asup - ε / 2` with radius `ε` obtain ⟨γ2_aux, h2_aux, hγ2⟩ := h (γ (asup - ε / 2)) rw [isMIntegralCurveOn_comp_sub (dt := asup - ε / 2)] at hγ2 set γ2 := γ2_aux ∘ (· - (asup - ε / 2)) with γ2_def have heq2 : γ2 (asup - ε / 2) = γ (asup - ε / 2) := by simp [γ2_def, h2_aux] -- rewrite shifted Ioo as Ioo simp_rw [Set.mem_Ioo, ← sub_lt_iff_lt_add, ← lt_sub_iff_add_lt, ← Set.mem_Ioo] at hγ1 simp_rw [Set.mem_Ioo, lt_sub_iff_add_lt, sub_lt_iff_lt_add, ← Set.mem_Ioo] at hγ2 -- to help `linarith` have hεle : ε ≤ asup := le_csSup hbdd (h x) -- extend `γ` on the left by `γ1` and on the right by `γ2` set γ_ext : ℝ → M := piecewise (Ioo (-(asup + ε / 2)) a) (piecewise (Ioo (-a) a) γ γ1) γ2 with γ_ext_def have heq_ext : γ_ext 0 = x := by rw [γ_ext_def, piecewise, if_pos ⟨by linarith, by linarith⟩, piecewise, if_pos ⟨by linarith, by linarith⟩, h0] -- `asup + ε / 2` is an element of `s` greater than `asup`, a contradiction suffices hext : IsMIntegralCurveOn γ_ext v (Ioo (-(asup + ε / 2)) (asup + ε / 2)) from (not_lt.mpr <| le_csSup hbdd ⟨γ_ext, heq_ext, hext⟩) <| lt_add_of_pos_right asup (half_pos hε) apply (isMIntegralCurveOn_piecewise (t₀ := asup - ε / 2) hv _ hγ2 ⟨⟨by linarith, hlt⟩, ⟨by linarith, by linarith⟩⟩ (by rw [piecewise, if_pos ⟨by linarith, hlt⟩, ← heq2])).mono (Ioo_subset_Ioo_union_Ioo le_rfl (by linarith) (by linarith)) exact (isMIntegralCurveOn_piecewise (t₀ := -(asup - ε / 2)) hv hγ hγ1 ⟨⟨neg_lt_neg hlt, by linarith⟩, ⟨by linarith, by linarith⟩⟩ heq1.symm).mono (union_comm _ _ ▸ Ioo_subset_Ioo_union_Ioo (by linarith) (by linarith) le_rfl) @[deprecated (since := "2025-08-12")] alias exists_isIntegralCurve_of_isIntegralCurveOn := exists_isMIntegralCurve_of_isMIntegralCurveOn
.lake/packages/mathlib/Mathlib/Geometry/Manifold/IntegralCurve/Transform.lean
import Mathlib.Geometry.Manifold.IntegralCurve.Basic /-! # Translation and scaling of integral curves New integral curves may be constructed by translating or scaling the domain of an existing integral curve. This file mirrors `Mathlib/Analysis/ODE/Transform`. ## Reference * [Lee, J. M. (2012). _Introduction to Smooth Manifolds_. Springer New York.][lee2012] ## Tags integral curve, vector field -/ open Function Set variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {γ γ' : ℝ → M} {v : (x : M) → TangentSpace I x} {s s' : Set ℝ} {t₀ : ℝ} /-! ### Translation lemmas -/ section Translation lemma IsMIntegralCurveOn.comp_add (hγ : IsMIntegralCurveOn γ v s) (dt : ℝ) : IsMIntegralCurveOn (γ ∘ (· + dt)) v { t | t + dt ∈ s } := by intro t ht rw [comp_apply, ← ContinuousLinearMap.comp_id (ContinuousLinearMap.smulRight 1 (v (γ (t + dt))))] apply HasMFDerivWithinAt.comp t (hγ (t + dt) ht) _ subset_rfl refine ⟨(continuous_add_right _).continuousWithinAt, ?_⟩ simp only [mfld_simps] exact (hasFDerivWithinAt_id _ _).add_const _ @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn.comp_add := IsMIntegralCurveOn.comp_add lemma isMIntegralCurveOn_comp_add {dt : ℝ} : IsMIntegralCurveOn γ v s ↔ IsMIntegralCurveOn (γ ∘ (· + dt)) v { t | t + dt ∈ s } := by refine ⟨fun hγ ↦ hγ.comp_add _, fun hγ ↦ ?_⟩ convert hγ.comp_add (-dt) · ext t simp · simp @[deprecated (since := "2025-08-12")] alias isIntegralCurveOn_comp_add := isMIntegralCurveOn_comp_add lemma isMIntegralCurveOn_comp_sub {dt : ℝ} : IsMIntegralCurveOn γ v s ↔ IsMIntegralCurveOn (γ ∘ (· - dt)) v { t | t - dt ∈ s } := by simpa using isMIntegralCurveOn_comp_add (dt := -dt) @[deprecated (since := "2025-08-12")] alias isIntegralCurveOn_comp_sub := isMIntegralCurveOn_comp_sub lemma IsMIntegralCurveAt.comp_add (hγ : IsMIntegralCurveAt γ v t₀) (dt : ℝ) : IsMIntegralCurveAt (γ ∘ (· + dt)) v (t₀ - dt) := by rw [isMIntegralCurveAt_iff'] at * obtain ⟨ε, hε, h⟩ := hγ refine ⟨ε, hε, ?_⟩ convert h.comp_add dt rw [Metric.ball] simp_rw [Metric.mem_ball, Real.dist_eq, ← sub_add, add_sub_right_comm] @[deprecated (since := "2025-08-12")] alias IsIntegralCurveAt.comp_add := IsMIntegralCurveAt.comp_add lemma isMIntegralCurveAt_comp_add {dt : ℝ} : IsMIntegralCurveAt γ v t₀ ↔ IsMIntegralCurveAt (γ ∘ (· + dt)) v (t₀ - dt) := by refine ⟨fun hγ ↦ hγ.comp_add _, fun hγ ↦ ?_⟩ convert hγ.comp_add (-dt) · ext t simp only [Function.comp_apply, neg_add_cancel_right] · simp only [sub_neg_eq_add, sub_add_cancel] @[deprecated (since := "2025-08-12")] alias isIntegralCurveAt_comp_add := isMIntegralCurveAt_comp_add lemma isMIntegralCurveAt_comp_sub {dt : ℝ} : IsMIntegralCurveAt γ v t₀ ↔ IsMIntegralCurveAt (γ ∘ (· - dt)) v (t₀ + dt) := by simpa using isMIntegralCurveAt_comp_add (dt := -dt) @[deprecated (since := "2025-08-12")] alias isIntegralCurveAt_comp_sub := isMIntegralCurveAt_comp_sub lemma IsMIntegralCurve.comp_add (hγ : IsMIntegralCurve γ v) (dt : ℝ) : IsMIntegralCurve (γ ∘ (· + dt)) v := by rw [isMIntegralCurve_iff_isMIntegralCurveOn] at * simpa using hγ.comp_add dt @[deprecated (since := "2025-08-12")] alias IsIntegralCurve.comp_add := IsMIntegralCurve.comp_add lemma isMIntegralCurve_comp_add {dt : ℝ} : IsMIntegralCurve γ v ↔ IsMIntegralCurve (γ ∘ (· + dt)) v := by refine ⟨fun hγ ↦ hγ.comp_add _, fun hγ ↦ ?_⟩ convert hγ.comp_add (-dt) ext t simp only [Function.comp_apply, neg_add_cancel_right] @[deprecated (since := "2025-08-12")] alias isIntegralCurve_comp_add := isMIntegralCurve_comp_add lemma isMIntegralCurve_comp_sub {dt : ℝ} : IsMIntegralCurve γ v ↔ IsMIntegralCurve (γ ∘ (· - dt)) v := by simpa using isMIntegralCurve_comp_add (dt := -dt) @[deprecated (since := "2025-08-12")] alias isIntegralCurve_comp_sub := isMIntegralCurve_comp_sub end Translation /-! ### Scaling lemmas -/ section Scaling lemma IsMIntegralCurveOn.comp_mul (hγ : IsMIntegralCurveOn γ v s) (a : ℝ) : IsMIntegralCurveOn (γ ∘ (· * a)) (a • v) { t | t * a ∈ s } := by intro t ht rw [comp_apply, Pi.smul_apply, ← ContinuousLinearMap.smulRight_comp] refine HasMFDerivWithinAt.comp t (hγ (t * a) ht) ⟨(continuous_mul_right _).continuousWithinAt, ?_⟩ subset_rfl simp only [mfld_simps] exact HasFDerivWithinAt.mul_const' (hasFDerivWithinAt_id _ _) _ @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn.comp_mul := IsMIntegralCurveOn.comp_mul lemma isMIntegralCurveOn_comp_mul_ne_zero {a : ℝ} (ha : a ≠ 0) : IsMIntegralCurveOn γ v s ↔ IsMIntegralCurveOn (γ ∘ (· * a)) (a • v) { t | t * a ∈ s } := by refine ⟨fun hγ ↦ hγ.comp_mul a, fun hγ ↦ ?_⟩ convert hγ.comp_mul a⁻¹ · ext t simp only [Function.comp_apply, mul_assoc, inv_mul_eq_div, div_self ha, mul_one] · simp only [smul_smul, inv_mul_eq_div, div_self ha, one_smul] · simp only [mem_setOf_eq, mul_assoc, inv_mul_eq_div, div_self ha, mul_one, setOf_mem_eq] @[deprecated (since := "2025-08-12")] alias isIntegralCurveOn_comp_mul_ne_zero := isMIntegralCurveOn_comp_mul_ne_zero lemma IsMIntegralCurveAt.comp_mul_ne_zero (hγ : IsMIntegralCurveAt γ v t₀) {a : ℝ} (ha : a ≠ 0) : IsMIntegralCurveAt (γ ∘ (· * a)) (a • v) (t₀ / a) := by rw [isMIntegralCurveAt_iff'] at * obtain ⟨ε, hε, h⟩ := hγ refine ⟨ε / |a|, by positivity, ?_⟩ convert h.comp_mul a ext t rw [mem_setOf_eq, Metric.mem_ball, Metric.mem_ball, Real.dist_eq, Real.dist_eq, lt_div_iff₀ (abs_pos.mpr ha), ← abs_mul, sub_mul, div_mul_cancel₀ _ ha] @[deprecated (since := "2025-08-12")] alias IsIntegralCurveAt.comp_mul_ne_zero := IsMIntegralCurveAt.comp_mul_ne_zero lemma isMIntegralCurveAt_comp_mul_ne_zero {a : ℝ} (ha : a ≠ 0) : IsMIntegralCurveAt γ v t₀ ↔ IsMIntegralCurveAt (γ ∘ (· * a)) (a • v) (t₀ / a) := by refine ⟨fun hγ ↦ hγ.comp_mul_ne_zero ha, fun hγ ↦ ?_⟩ convert hγ.comp_mul_ne_zero (inv_ne_zero ha) · ext t simp only [Function.comp_apply, mul_assoc, inv_mul_eq_div, div_self ha, mul_one] · simp only [smul_smul, inv_mul_eq_div, div_self ha, one_smul] · simp only [div_inv_eq_mul, div_mul_cancel₀ _ ha] @[deprecated (since := "2025-08-12")] alias isIntegralCurveAt_comp_mul_ne_zero := isMIntegralCurveAt_comp_mul_ne_zero lemma IsMIntegralCurve.comp_mul (hγ : IsMIntegralCurve γ v) (a : ℝ) : IsMIntegralCurve (γ ∘ (· * a)) (a • v) := by rw [isMIntegralCurve_iff_isMIntegralCurveOn] at * exact hγ.comp_mul _ @[deprecated (since := "2025-08-12")] alias IsIntegralCurve.comp_mul := IsMIntegralCurve.comp_mul lemma isMIntegralCurve_comp_mul_ne_zero {a : ℝ} (ha : a ≠ 0) : IsMIntegralCurve γ v ↔ IsMIntegralCurve (γ ∘ (· * a)) (a • v) := by refine ⟨fun hγ ↦ hγ.comp_mul _, fun hγ ↦ ?_⟩ convert hγ.comp_mul a⁻¹ · ext t simp only [Function.comp_apply, mul_assoc, inv_mul_eq_div, div_self ha, mul_one] · simp only [smul_smul, inv_mul_eq_div, div_self ha, one_smul] @[deprecated (since := "2025-08-12")] alias isIntegralCurve_comp_mul_ne_zero := isMIntegralCurve_comp_mul_ne_zero /-- If the vector field `v` vanishes at `x₀`, then the constant curve at `x₀` is a global integral curve of `v`. -/ lemma isMIntegralCurve_const {x : M} (h : v x = 0) : IsMIntegralCurve (fun _ ↦ x) v := by intro t rw [h, ← ContinuousLinearMap.zero_apply (R₁ := ℝ) (R₂ := ℝ) (1 : ℝ), ContinuousLinearMap.smulRight_one_one] exact hasMFDerivAt_const .. @[deprecated (since := "2025-08-12")] alias isIntegralCurve_const := isMIntegralCurve_const end Scaling
.lake/packages/mathlib/Mathlib/Geometry/Manifold/IntegralCurve/ExistUnique.lean
import Mathlib.Analysis.ODE.Gronwall import Mathlib.Analysis.ODE.PicardLindelof import Mathlib.Geometry.Manifold.IntegralCurve.Transform import Mathlib.Geometry.Manifold.IsManifold.InteriorBoundary /-! # Existence and uniqueness of integral curves ## Main results * `exists_isMIntegralCurveAt_of_contMDiffAt_boundaryless`: Existence of local integral curves for a $C^1$ vector field. This follows from the existence theorem for solutions to ODEs (`exists_forall_hasDerivAt_Ioo_eq_of_contDiffAt`). * `isMIntegralCurveOn_Ioo_eqOn_of_contMDiff_boundaryless`: Uniqueness of local integral curves for a $C^1$ vector field. This follows from the uniqueness theorem for solutions to ODEs (`ODE_solution_unique_of_mem_set_Ioo`). This requires the manifold to be Hausdorff (`T2Space`). ## Implementation notes For the existence and uniqueness theorems, we assume that the image of the integral curve lies in the interior of the manifold. The case where the integral curve may lie on the boundary of the manifold requires special treatment, and we leave it as a TODO. We state simpler versions of the theorem for boundaryless manifolds as corollaries. ## TODO * The case where the integral curve may venture to the boundary of the manifold. See Theorem 9.34, Lee. May require submanifolds. ## Reference * [Lee, J. M. (2012). _Introduction to Smooth Manifolds_. Springer New York.][lee2012] ## Tags integral curve, vector field, local existence, uniqueness -/ open scoped Topology open Function Set variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I 1 M] {γ γ' : ℝ → M} {v : (x : M) → TangentSpace I x} {s s' : Set ℝ} (t₀ : ℝ) {x₀ : M} /-- Existence of local integral curves for a $C^1$ vector field at interior points of a `C^1` manifold. -/ theorem exists_isMIntegralCurveAt_of_contMDiffAt [CompleteSpace E] (hv : ContMDiffAt I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M)) x₀) (hx : I.IsInteriorPoint x₀) : ∃ γ : ℝ → M, γ t₀ = x₀ ∧ IsMIntegralCurveAt γ v t₀ := by -- express the differentiability of the vector field `v` in the local chart rw [contMDiffAt_iff] at hv obtain ⟨_, hv⟩ := hv -- use Picard-Lindelöf theorem to extract a solution to the ODE in the local chart obtain ⟨f, hf1, hf2⟩ := hv.contDiffAt (range_mem_nhds_isInteriorPoint hx) |>.snd.exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt₀ t₀ simp_rw [← Real.ball_eq_Ioo, ← Metric.eventually_nhds_iff_ball] at hf2 -- use continuity of `f` so that `f t` remains inside `interior (extChartAt I x₀).target` have ⟨a, ha, hf2'⟩ := Metric.eventually_nhds_iff_ball.mp hf2 have hcont := (hf2' t₀ (Metric.mem_ball_self ha)).continuousAt rw [continuousAt_def, hf1] at hcont have hnhds : f ⁻¹' (interior (extChartAt I x₀).target) ∈ 𝓝 t₀ := hcont _ (isOpen_interior.mem_nhds ((I.isInteriorPoint_iff).mp hx)) rw [← eventually_mem_nhds_iff] at hnhds -- obtain a neighbourhood `s` so that the above conditions both hold in `s` obtain ⟨s, hs, haux⟩ := (hf2.and hnhds).exists_mem -- prove that `γ := (extChartAt I x₀).symm ∘ f` is a desired integral curve refine ⟨(extChartAt I x₀).symm ∘ f, Eq.symm (by rw [Function.comp_apply, hf1, PartialEquiv.left_inv _ (mem_extChartAt_source ..)]), isMIntegralCurveAt_iff.mpr ⟨s, hs, ?_⟩⟩ intro t ht -- collect useful terms in convenient forms let xₜ : M := (extChartAt I x₀).symm (f t) -- `xₜ := γ t` have h : HasDerivAt f (x := t) <| fderivWithin ℝ (extChartAt I x₀ ∘ (extChartAt I xₜ).symm) (range I) (extChartAt I xₜ xₜ) (v xₜ) := (haux t ht).1 rw [← tangentCoordChange_def] at h have hf3 := mem_preimage.mp <| mem_of_mem_nhds (haux t ht).2 have hf3' := mem_of_mem_of_subset hf3 interior_subset have hft1 := mem_preimage.mp <| mem_of_mem_of_subset hf3' (extChartAt I x₀).target_subset_preimage_source have hft2 := mem_extChartAt_source (I := I) xₜ -- express the derivative of the integral curve in the local chart apply HasMFDerivAt.hasMFDerivWithinAt refine ⟨(continuousAt_extChartAt_symm'' hf3').comp h.continuousAt, HasDerivWithinAt.hasFDerivWithinAt ?_⟩ simp only [mfld_simps, hasDerivWithinAt_univ] change HasDerivAt ((extChartAt I xₜ ∘ (extChartAt I x₀).symm) ∘ f) (v xₜ) t -- express `v (γ t)` as `D⁻¹ D (v (γ t))`, where `D` is a change of coordinates, so we can use -- `HasFDerivAt.comp_hasDerivAt` on `h` rw [← tangentCoordChange_self (I := I) (x := xₜ) (z := xₜ) (v := v xₜ) hft2, ← tangentCoordChange_comp (x := x₀) ⟨⟨hft2, hft1⟩, hft2⟩] apply HasFDerivAt.comp_hasDerivAt _ _ h apply HasFDerivWithinAt.hasFDerivAt (s := range I) _ <| mem_nhds_iff.mpr ⟨interior (extChartAt I x₀).target, subset_trans interior_subset (extChartAt_target_subset_range ..), isOpen_interior, hf3⟩ rw [← (extChartAt I x₀).right_inv hf3'] exact hasFDerivWithinAt_tangentCoordChange ⟨hft1, hft2⟩ @[deprecated (since := "2025-08-12")] alias exists_isIntegralCurveAt_of_contMDiffAt := exists_isMIntegralCurveAt_of_contMDiffAt /-- Existence of local integral curves for a $C^1$ vector field on a `C^1` manifold without boundary. -/ lemma exists_isMIntegralCurveAt_of_contMDiffAt_boundaryless [CompleteSpace E] [BoundarylessManifold I M] (hv : ContMDiffAt I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M)) x₀) : ∃ γ : ℝ → M, γ t₀ = x₀ ∧ IsMIntegralCurveAt γ v t₀ := exists_isMIntegralCurveAt_of_contMDiffAt t₀ hv BoundarylessManifold.isInteriorPoint @[deprecated (since := "2025-08-12")] alias exists_isIntegralCurveAt_of_contMDiffAt_boundaryless := exists_isMIntegralCurveAt_of_contMDiffAt_boundaryless variable {t₀} /-- Local integral curves are unique. If a $C^1$ vector field `v` admits two local integral curves `γ γ' : ℝ → M` at `t₀` with `γ t₀ = γ' t₀`, then `γ` and `γ'` agree on some open interval containing `t₀`. -/ theorem isMIntegralCurveAt_eventuallyEq_of_contMDiffAt (hγt₀ : I.IsInteriorPoint (γ t₀)) (hv : ContMDiffAt I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M)) (γ t₀)) (hγ : IsMIntegralCurveAt γ v t₀) (hγ' : IsMIntegralCurveAt γ' v t₀) (h : γ t₀ = γ' t₀) : γ =ᶠ[𝓝 t₀] γ' := by -- first define `v'` as the vector field expressed in the local chart around `γ t₀` -- this is basically what the function looks like when `hv` is unfolded set v' : E → E := fun x ↦ tangentCoordChange I ((extChartAt I (γ t₀)).symm x) (γ t₀) ((extChartAt I (γ t₀)).symm x) (v ((extChartAt I (γ t₀)).symm x)) with hv' -- extract a set `s` on which `v'` is Lipschitz rw [contMDiffAt_iff] at hv obtain ⟨_, hv⟩ := hv obtain ⟨K, s, hs, hlip⟩ : ∃ K, ∃ s ∈ 𝓝 _, LipschitzOnWith K v' s := (hv.contDiffAt (range_mem_nhds_isInteriorPoint hγt₀)).snd.exists_lipschitzOnWith have hlip (t : ℝ) : LipschitzOnWith K ((fun _ ↦ v') t) ((fun _ ↦ s) t) := hlip -- internal lemmas to reduce code duplication have hsrc {g} (hg : IsMIntegralCurveAt g v t₀) : ∀ᶠ t in 𝓝 t₀, g ⁻¹' (extChartAt I (g t₀)).source ∈ 𝓝 t := eventually_mem_nhds_iff.mpr <| continuousAt_def.mp hg.continuousAt _ <| extChartAt_source_mem_nhds (g t₀) have hmem {g : ℝ → M} {t} (ht : g ⁻¹' (extChartAt I (g t₀)).source ∈ 𝓝 t) : g t ∈ (extChartAt I (g t₀)).source := mem_preimage.mp <| mem_of_mem_nhds ht have hdrv {g} (hg : IsMIntegralCurveAt g v t₀) (h' : γ t₀ = g t₀) : ∀ᶠ t in 𝓝 t₀, HasDerivAt ((extChartAt I (g t₀)) ∘ g) ((fun _ ↦ v') t (((extChartAt I (g t₀)) ∘ g) t)) t ∧ ((extChartAt I (g t₀)) ∘ g) t ∈ (fun _ ↦ s) t := by apply Filter.Eventually.and · apply (hsrc hg |>.and hg.eventually_hasDerivAt).mono rintro t ⟨ht1, ht2⟩ rw [hv', h'] apply ht2.congr_deriv congr <;> rw [Function.comp_apply, PartialEquiv.left_inv _ (hmem ht1)] · apply ((continuousAt_extChartAt (g t₀)).comp hg.continuousAt).preimage_mem_nhds rw [Function.comp_apply, ← h'] exact hs have heq {g} (hg : IsMIntegralCurveAt g v t₀) : g =ᶠ[𝓝 t₀] (extChartAt I (g t₀)).symm ∘ ↑(extChartAt I (g t₀)) ∘ g := by apply (hsrc hg).mono intro t ht rw [Function.comp_apply, Function.comp_apply, PartialEquiv.left_inv _ (hmem ht)] -- main proof suffices (extChartAt I (γ t₀)) ∘ γ =ᶠ[𝓝 t₀] (extChartAt I (γ' t₀)) ∘ γ' from (heq hγ).trans <| (this.fun_comp (extChartAt I (γ t₀)).symm).trans (h ▸ (heq hγ').symm) exact ODE_solution_unique_of_eventually (.of_forall hlip) (hdrv hγ rfl) (hdrv hγ' h) (by rw [Function.comp_apply, Function.comp_apply, h]) @[deprecated (since := "2025-08-12")] alias isIntegralCurveAt_eventuallyEq_of_contMDiffAt := isMIntegralCurveAt_eventuallyEq_of_contMDiffAt theorem isMIntegralCurveAt_eventuallyEq_of_contMDiffAt_boundaryless [BoundarylessManifold I M] (hv : ContMDiffAt I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M)) (γ t₀)) (hγ : IsMIntegralCurveAt γ v t₀) (hγ' : IsMIntegralCurveAt γ' v t₀) (h : γ t₀ = γ' t₀) : γ =ᶠ[𝓝 t₀] γ' := isMIntegralCurveAt_eventuallyEq_of_contMDiffAt BoundarylessManifold.isInteriorPoint hv hγ hγ' h @[deprecated (since := "2025-08-12")] alias isIntegralCurveAt_eventuallyEq_of_contMDiffAt_boundaryless := isMIntegralCurveAt_eventuallyEq_of_contMDiffAt_boundaryless variable [T2Space M] {a b : ℝ} /-- Integral curves are unique on open intervals. If a $C^1$ vector field `v` admits two integral curves `γ γ' : ℝ → M` on some open interval `Ioo a b`, and `γ t₀ = γ' t₀` for some `t ∈ Ioo a b`, then `γ` and `γ'` agree on `Ioo a b`. -/ theorem isMIntegralCurveOn_Ioo_eqOn_of_contMDiff (ht₀ : t₀ ∈ Ioo a b) (hγt : ∀ t ∈ Ioo a b, I.IsInteriorPoint (γ t)) (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) (hγ : IsMIntegralCurveOn γ v (Ioo a b)) (hγ' : IsMIntegralCurveOn γ' v (Ioo a b)) (h : γ t₀ = γ' t₀) : EqOn γ γ' (Ioo a b) := by set s := {t | γ t = γ' t} ∩ Ioo a b with hs -- since `Ioo a b` is connected, we get `s = Ioo a b` by showing that `s` is clopen in `Ioo a b` -- in the subtype topology (`s` is also non-empty by assumption) -- here we use a slightly weaker alternative theorem suffices hsub : Ioo a b ⊆ s from fun t ht ↦ mem_setOf.mp ((subset_def ▸ hsub) t ht).1 apply isPreconnected_Ioo.subset_of_closure_inter_subset (s := Ioo a b) (u := s) _ ⟨t₀, ⟨ht₀, ⟨h, ht₀⟩⟩⟩ · -- is this really the most convenient way to pass to subtype topology? -- TODO: shorten this when better API around subtype topology exists rw [hs, inter_comm, ← Subtype.image_preimage_val, inter_comm, ← Subtype.image_preimage_val, image_subset_image_iff Subtype.val_injective, preimage_setOf_eq] intro t ht rw [mem_preimage, ← closure_subtype] at ht revert ht t apply IsClosed.closure_subset (isClosed_eq _ _) · rw [continuous_iff_continuousAt] rintro ⟨_, ht⟩ apply ContinuousAt.comp _ continuousAt_subtype_val rw [Subtype.coe_mk] exact hγ.continuousWithinAt ht |>.continuousAt (Ioo_mem_nhds ht.1 ht.2) · rw [continuous_iff_continuousAt] rintro ⟨_, ht⟩ apply ContinuousAt.comp _ continuousAt_subtype_val rw [Subtype.coe_mk] exact hγ'.continuousWithinAt ht |>.continuousAt (Ioo_mem_nhds ht.1 ht.2) · rw [isOpen_iff_mem_nhds] intro t₁ ht₁ have hmem := Ioo_mem_nhds ht₁.2.1 ht₁.2.2 have heq : γ =ᶠ[𝓝 t₁] γ' := isMIntegralCurveAt_eventuallyEq_of_contMDiffAt (hγt _ ht₁.2) hv.contMDiffAt (hγ.isMIntegralCurveAt hmem) (hγ'.isMIntegralCurveAt hmem) ht₁.1 apply (heq.and hmem).mono exact fun _ ht ↦ ht @[deprecated (since := "2025-08-12")] alias isIntegralCurveOn_Ioo_eqOn_of_contMDiff := isMIntegralCurveOn_Ioo_eqOn_of_contMDiff theorem isMIntegralCurveOn_Ioo_eqOn_of_contMDiff_boundaryless [BoundarylessManifold I M] (ht₀ : t₀ ∈ Ioo a b) (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) (hγ : IsMIntegralCurveOn γ v (Ioo a b)) (hγ' : IsMIntegralCurveOn γ' v (Ioo a b)) (h : γ t₀ = γ' t₀) : EqOn γ γ' (Ioo a b) := isMIntegralCurveOn_Ioo_eqOn_of_contMDiff ht₀ (fun _ _ ↦ BoundarylessManifold.isInteriorPoint) hv hγ hγ' h @[deprecated (since := "2025-08-12")] alias isIntegralCurveOn_Ioo_eqOn_of_contMDiff_boundaryless := isMIntegralCurveOn_Ioo_eqOn_of_contMDiff_boundaryless /-- Global integral curves are unique. If a continuously differentiable vector field `v` admits two global integral curves `γ γ' : ℝ → M`, and `γ t₀ = γ' t₀` for some `t₀`, then `γ` and `γ'` are equal. -/ theorem isMIntegralCurve_eq_of_contMDiff (hγt : ∀ t, I.IsInteriorPoint (γ t)) (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) (hγ : IsMIntegralCurve γ v) (hγ' : IsMIntegralCurve γ' v) (h : γ t₀ = γ' t₀) : γ = γ' := by ext t obtain ⟨T, ht₀, ht⟩ : ∃ T, t ∈ Ioo (-T) T ∧ t₀ ∈ Ioo (-T) T := by obtain ⟨T, hT₁, hT₂⟩ := exists_abs_lt t obtain ⟨hT₂, hT₃⟩ := abs_lt.mp hT₂ obtain ⟨S, hS₁, hS₂⟩ := exists_abs_lt t₀ obtain ⟨hS₂, hS₃⟩ := abs_lt.mp hS₂ exact ⟨T + S, by constructor <;> constructor <;> linarith⟩ exact isMIntegralCurveOn_Ioo_eqOn_of_contMDiff ht (fun t _ ↦ hγt t) hv ((hγ.isMIntegralCurveOn _).mono (subset_univ _)) ((hγ'.isMIntegralCurveOn _).mono (subset_univ _)) h ht₀ @[deprecated (since := "2025-08-12")] alias isIntegralCurve_eq_of_contMDiff := isMIntegralCurve_eq_of_contMDiff theorem isMIntegralCurve_Ioo_eq_of_contMDiff_boundaryless [BoundarylessManifold I M] (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) (hγ : IsMIntegralCurve γ v) (hγ' : IsMIntegralCurve γ' v) (h : γ t₀ = γ' t₀) : γ = γ' := isMIntegralCurve_eq_of_contMDiff (fun _ ↦ BoundarylessManifold.isInteriorPoint) hv hγ hγ' h @[deprecated (since := "2025-08-12")] alias isIntegralCurve_Ioo_eq_of_contMDiff_boundaryless := isMIntegralCurve_Ioo_eq_of_contMDiff_boundaryless /-- For a global integral curve `γ`, if it crosses itself at `a b : ℝ`, then it is periodic with period `a - b`. -/ lemma IsMIntegralCurve.periodic_of_eq [BoundarylessManifold I M] (hγ : IsMIntegralCurve γ v) (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) (heq : γ a = γ b) : Periodic γ (a - b) := by intro t apply congrFun <| isMIntegralCurve_Ioo_eq_of_contMDiff_boundaryless (t₀ := b) hv (hγ.comp_add _) hγ _ rw [comp_apply, add_sub_cancel, heq] @[deprecated (since := "2025-08-12")] alias IsIntegralCurve.periodic_of_eq := IsMIntegralCurve.periodic_of_eq /-- A global integral curve is injective xor periodic with positive period. -/ lemma IsMIntegralCurve.periodic_xor_injective [BoundarylessManifold I M] (hγ : IsMIntegralCurve γ v) (hv : ContMDiff I I.tangent 1 (fun x ↦ (⟨x, v x⟩ : TangentBundle I M))) : Xor' (∃ T > 0, Periodic γ T) (Injective γ) := by rw [xor_iff_iff_not] refine ⟨fun ⟨T, hT, hf⟩ ↦ hf.not_injective (ne_of_gt hT), ?_⟩ intro h rw [Injective] at h push_neg at h obtain ⟨a, b, heq, hne⟩ := h refine ⟨|a - b|, ?_, ?_⟩ · rw [gt_iff_lt, abs_pos, sub_ne_zero] exact hne · by_cases! hab : a - b < 0 · rw [abs_of_neg hab, neg_sub] exact hγ.periodic_of_eq hv heq.symm · rw [abs_of_nonneg hab] exact hγ.periodic_of_eq hv heq @[deprecated (since := "2025-08-12")] alias IsIntegralCurve.periodic_xor_injective := IsMIntegralCurve.periodic_xor_injective
.lake/packages/mathlib/Mathlib/Geometry/Manifold/IntegralCurve/Basic.lean
import Mathlib.Geometry.Manifold.MFDeriv.Tangent /-! # Integral curves of vector fields on a manifold Let `M` be a manifold and `v : (x : M) → TangentSpace I x` be a vector field on `M`. An integral curve of `v` is a function `γ : ℝ → M` such that the derivative of `γ` at `t` equals `v (γ t)`. The integral curve may only be defined for all `t` within some subset of `ℝ`. This is the first of a series of files, organised as follows: * `Mathlib/Geometry/Manifold/IntegralCurve/Basic.lean` (this file): Basic definitions and lemmas relating them to each other and to continuity and differentiability * `Mathlib/Geometry/Manifold/IntegralCurve/Transform.lean`: Lemmas about translating or scaling the domain of an integral curve by a constant * `Mathlib/Geometry/Manifold/IntegralCurve/ExistUnique.lean`: Local existence and uniqueness theorems for integral curves ## Main definitions Let `v : M → TM` be a vector field on `M`, and let `γ : ℝ → M`. * `IsMIntegralCurve γ v`: `γ t` is tangent to `v (γ t)` for all `t : ℝ`. That is, `γ` is a global integral curve of `v`. * `IsMIntegralCurveOn γ v s`: `γ t` is tangent to `v (γ t)` for all `t ∈ s`, where `s : Set ℝ`. * `IsMIntegralCurveAt γ v t₀`: `γ t` is tangent to `v (γ t)` for all `t` in some open interval around `t₀`. That is, `γ` is a local integral curve of `v`. For `IsMIntegralCurveOn γ v s` and `IsMIntegralCurveAt γ v t₀`, even though `γ` is defined for all time, its value outside of the set `s` or a small interval around `t₀` is irrelevant and considered junk. ## TODO * Implement `IsMIntegralCurveWithinAt`. ## Reference * [Lee, J. M. (2012). _Introduction to Smooth Manifolds_. Springer New York.][lee2012] ## Tags integral curve, vector field -/ open scoped Manifold Topology open Set variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] /-- If `γ : ℝ → M` is $C^1$ on `s : Set ℝ` and `v` is a vector field on `M`, `IsMIntegralCurveOn γ v s` means `γ t` is tangent to `v (γ t)` for all `t ∈ s`. The value of `γ` outside of `s` is irrelevant and considered junk. -/ def IsMIntegralCurveOn (γ : ℝ → M) (v : (x : M) → TangentSpace I x) (s : Set ℝ) : Prop := ∀ t ∈ s, HasMFDerivWithinAt 𝓘(ℝ, ℝ) I γ s t ((1 : ℝ →L[ℝ] ℝ).smulRight <| v (γ t)) @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn := IsMIntegralCurveOn /-- If `v` is a vector field on `M` and `t₀ : ℝ`, `IsMIntegralCurveAt γ v t₀` means `γ : ℝ → M` is a local integral curve of `v` in a neighbourhood containing `t₀`. The value of `γ` outside of this interval is irrelevant and considered junk. -/ def IsMIntegralCurveAt (γ : ℝ → M) (v : (x : M) → TangentSpace I x) (t₀ : ℝ) : Prop := ∀ᶠ t in 𝓝 t₀, HasMFDerivAt 𝓘(ℝ, ℝ) I γ t ((1 : ℝ →L[ℝ] ℝ).smulRight <| v (γ t)) @[deprecated (since := "2025-08-12")] alias IsIntegralCurveAt := IsMIntegralCurveAt /-- If `v : M → TM` is a vector field on `M`, `IsMIntegralCurve γ v` means `γ : ℝ → M` is a global integral curve of `v`. That is, `γ t` is tangent to `v (γ t)` for all `t : ℝ`. -/ def IsMIntegralCurve (γ : ℝ → M) (v : (x : M) → TangentSpace I x) : Prop := ∀ t : ℝ, HasMFDerivAt 𝓘(ℝ, ℝ) I γ t ((1 : ℝ →L[ℝ] ℝ).smulRight (v (γ t))) @[deprecated (since := "2025-08-12")] alias IsIntegralCurve := IsMIntegralCurve variable {γ γ' : ℝ → M} {v : (x : M) → TangentSpace I x} {s s' : Set ℝ} {t₀ : ℝ} lemma IsMIntegralCurve.isMIntegralCurveOn (h : IsMIntegralCurve γ v) (s : Set ℝ) : IsMIntegralCurveOn γ v s := fun t _ ↦ (h t).hasMFDerivWithinAt @[deprecated (since := "2025-08-12")] alias IsIntegralCurve.isIntegralCurveOn := IsMIntegralCurve.isMIntegralCurveOn lemma isMIntegralCurve_iff_isMIntegralCurveOn : IsMIntegralCurve γ v ↔ IsMIntegralCurveOn γ v univ := ⟨fun h ↦ h.isMIntegralCurveOn _, fun h t ↦ (h t (mem_univ _)).hasMFDerivAt Filter.univ_mem⟩ @[deprecated (since := "2025-08-12")] alias isIntegralCurve_iff_isIntegralCurveOn := isMIntegralCurve_iff_isMIntegralCurveOn lemma isMIntegralCurveAt_iff : IsMIntegralCurveAt γ v t₀ ↔ ∃ s ∈ 𝓝 t₀, IsMIntegralCurveOn γ v s := by constructor · intro h rw [IsMIntegralCurveAt, Filter.eventually_iff_exists_mem] at h obtain ⟨s, hs, h⟩ := h exact ⟨s, hs, fun t ht ↦ (h t ht).hasMFDerivWithinAt⟩ · rintro ⟨s, hs, h⟩ rw [IsMIntegralCurveAt, Filter.eventually_iff_exists_mem] obtain ⟨s', h1, h2, h3⟩ := mem_nhds_iff.mp hs refine ⟨s', h2.mem_nhds h3, ?_⟩ intro t ht apply (h t (h1 ht)).hasMFDerivAt rw [mem_nhds_iff] exact ⟨s', h1, h2, ht⟩ @[deprecated (since := "2025-08-12")] alias isIntegralCurveAt_iff := isMIntegralCurveAt_iff /-- `γ` is an integral curve for `v` at `t₀` iff `γ` is an integral curve on some interval containing `t₀`. -/ lemma isMIntegralCurveAt_iff' : IsMIntegralCurveAt γ v t₀ ↔ ∃ ε > 0, IsMIntegralCurveOn γ v (Metric.ball t₀ ε) := by rw [isMIntegralCurveAt_iff] constructor · intro ⟨s, hs, h⟩ rw [Metric.mem_nhds_iff] at hs obtain ⟨ε, hε, hε'⟩ := hs refine ⟨ε, hε, fun t ht ↦ (h t (hε' ht)).mono hε'⟩ · intro ⟨ε, hε, h⟩ exact ⟨Metric.ball t₀ ε, Metric.ball_mem_nhds _ hε, h⟩ @[deprecated (since := "2025-08-12")] alias isIntegralCurveAt_iff' := isMIntegralCurveAt_iff' lemma IsMIntegralCurve.isMIntegralCurveAt (h : IsMIntegralCurve γ v) (t : ℝ) : IsMIntegralCurveAt γ v t := isMIntegralCurveAt_iff.mpr ⟨univ, Filter.univ_mem, fun t _ ↦ (h t).hasMFDerivWithinAt⟩ @[deprecated (since := "2025-08-12")] alias IsIntegralCurve.isIntegralCurveAt := IsMIntegralCurve.isMIntegralCurveAt lemma isMIntegralCurve_iff_isMIntegralCurveAt : IsMIntegralCurve γ v ↔ ∀ t : ℝ, IsMIntegralCurveAt γ v t := ⟨fun h ↦ h.isMIntegralCurveAt, fun h t ↦ by obtain ⟨s, hs, h⟩ := isMIntegralCurveAt_iff.mp (h t) exact h t (mem_of_mem_nhds hs) |>.hasMFDerivAt hs⟩ @[deprecated (since := "2025-08-12")] alias isIntegralCurve_iff_isIntegralCurveAt := isMIntegralCurve_iff_isMIntegralCurveAt lemma IsMIntegralCurveOn.mono (h : IsMIntegralCurveOn γ v s) (hs : s' ⊆ s) : IsMIntegralCurveOn γ v s' := fun t ht ↦ (h t (hs ht)).mono hs @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn.mono := IsMIntegralCurveOn.mono lemma IsMIntegralCurveAt.hasMFDerivAt (h : IsMIntegralCurveAt γ v t₀) : HasMFDerivAt 𝓘(ℝ, ℝ) I γ t₀ ((1 : ℝ →L[ℝ] ℝ).smulRight (v (γ t₀))) := have ⟨_, hs, h⟩ := isMIntegralCurveAt_iff.mp h h t₀ (mem_of_mem_nhds hs) |>.hasMFDerivAt hs @[deprecated (since := "2025-08-12")] alias IsIntegralCurveAt.hasMFDerivAt := IsMIntegralCurveAt.hasMFDerivAt lemma IsMIntegralCurveOn.isMIntegralCurveAt (h : IsMIntegralCurveOn γ v s) (hs : s ∈ 𝓝 t₀) : IsMIntegralCurveAt γ v t₀ := isMIntegralCurveAt_iff.mpr ⟨s, hs, h⟩ @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn.isIntegralCurveAt := IsMIntegralCurveOn.isMIntegralCurveAt /-- If `γ` is an integral curve at each `t ∈ s`, it is an integral curve on `s`. -/ lemma IsMIntegralCurveAt.isMIntegralCurveOn (h : ∀ t ∈ s, IsMIntegralCurveAt γ v t) : IsMIntegralCurveOn γ v s := by intro t ht apply HasMFDerivAt.hasMFDerivWithinAt obtain ⟨s', hs', h⟩ := Filter.eventually_iff_exists_mem.mp (h t ht) exact h _ (mem_of_mem_nhds hs') @[deprecated (since := "2025-08-12")] alias IsIntegralCurveAt.isIntegralCurveOn := IsMIntegralCurveAt.isMIntegralCurveOn lemma isMIntegralCurveOn_iff_isMIntegralCurveAt (hs : IsOpen s) : IsMIntegralCurveOn γ v s ↔ ∀ t ∈ s, IsMIntegralCurveAt γ v t := ⟨fun h _ ht ↦ h.isMIntegralCurveAt (hs.mem_nhds ht), IsMIntegralCurveAt.isMIntegralCurveOn⟩ @[deprecated (since := "2025-08-12")] alias isIntegralCurveOn_iff_isIntegralCurveAt := isMIntegralCurveOn_iff_isMIntegralCurveAt lemma IsMIntegralCurveOn.continuousWithinAt (hγ : IsMIntegralCurveOn γ v s) (ht : t₀ ∈ s) : ContinuousWithinAt γ s t₀ := (hγ t₀ ht).1 @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn.continuousAt := IsMIntegralCurveOn.continuousWithinAt @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn.continuousWithinAt := IsMIntegralCurveOn.continuousWithinAt lemma IsMIntegralCurveOn.continuousOn (hγ : IsMIntegralCurveOn γ v s) : ContinuousOn γ s := fun t ht ↦ (hγ t ht).continuousWithinAt @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn.continuousOn := IsMIntegralCurveOn.continuousOn lemma IsMIntegralCurveAt.continuousAt (hγ : IsMIntegralCurveAt γ v t₀) : ContinuousAt γ t₀ := have ⟨_, hs, hγ⟩ := isMIntegralCurveAt_iff.mp hγ hγ.continuousWithinAt (mem_of_mem_nhds hs) |>.continuousAt hs @[deprecated (since := "2025-08-12")] alias IsIntegralCurveAt.continuousAt := IsMIntegralCurveAt.continuousAt lemma IsMIntegralCurve.continuous (hγ : IsMIntegralCurve γ v) : Continuous γ := continuous_iff_continuousAt.mpr fun t ↦ (hγ.isMIntegralCurveAt t).continuousAt @[deprecated (since := "2025-08-12")] alias IsIntegralCurve.continuous := IsMIntegralCurve.continuous variable [IsManifold I 1 M] /-- If `γ` is an integral curve of a vector field `v`, then `γ t` is tangent to `v (γ t)` when expressed in the local chart around the initial point `γ t₀`. -/ lemma IsMIntegralCurveOn.hasDerivWithinAt (hγ : IsMIntegralCurveOn γ v s) {t : ℝ} (ht : t ∈ s) (hsrc : γ t ∈ (extChartAt I (γ t₀)).source) : HasDerivWithinAt ((extChartAt I (γ t₀)) ∘ γ) (tangentCoordChange I (γ t) (γ t₀) (γ t) (v (γ t))) s t := by -- turn `HasDerivWithinAt` into comp of `HasMFDerivWithinAt` replace hsrc := extChartAt_source I (γ t₀) ▸ hsrc rw [hasDerivWithinAt_iff_hasFDerivWithinAt, ← hasMFDerivWithinAt_iff_hasFDerivWithinAt] apply (HasMFDerivWithinAt.comp t (hasMFDerivWithinAt_extChartAt (I := I) hsrc) (hγ _ ht) (Set.subset_preimage_image _ _)).congr_mfderiv rw [ContinuousLinearMap.ext_iff] intro a rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.smulRight_apply, map_smul, ← ContinuousLinearMap.one_apply (R₁ := ℝ) a, ← ContinuousLinearMap.smulRight_apply, mfderiv_chartAt_eq_tangentCoordChange hsrc] rfl @[deprecated (since := "2025-08-12")] alias IsIntegralCurveOn.hasDerivWithinAt := IsMIntegralCurveOn.hasDerivWithinAt lemma IsMIntegralCurveAt.eventually_hasDerivAt (hγ : IsMIntegralCurveAt γ v t₀) : ∀ᶠ t in 𝓝 t₀, HasDerivAt ((extChartAt I (γ t₀)) ∘ γ) (tangentCoordChange I (γ t) (γ t₀) (γ t) (v (γ t))) t := by apply eventually_mem_nhds_iff.mpr (hγ.continuousAt.preimage_mem_nhds (extChartAt_source_mem_nhds (I := I) _)) |>.and hγ |>.mono rintro t ⟨ht1, ht2⟩ have hsrc := mem_of_mem_nhds ht1 rw [mem_preimage, extChartAt_source I (γ t₀)] at hsrc rw [hasDerivAt_iff_hasFDerivAt, ← hasMFDerivAt_iff_hasFDerivAt] apply (HasMFDerivAt.comp t (hasMFDerivAt_extChartAt (I := I) hsrc) ht2).congr_mfderiv rw [ContinuousLinearMap.ext_iff] intro a rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.smulRight_apply, map_smul, ← ContinuousLinearMap.one_apply (R₁ := ℝ) a, ← ContinuousLinearMap.smulRight_apply, mfderiv_chartAt_eq_tangentCoordChange hsrc] rfl @[deprecated (since := "2025-08-12")] alias IsIntegralCurveAt.eventually_hasDerivAt := IsMIntegralCurveAt.eventually_hasDerivAt
.lake/packages/mathlib/Mathlib/Geometry/Manifold/MFDeriv/UniqueDifferential.lean
import Mathlib.Geometry.Manifold.MFDeriv.Atlas import Mathlib.Geometry.Manifold.VectorBundle.Basic /-! # Unique derivative sets in manifolds In this file, we prove various properties of unique derivative sets in manifolds. * `image_denseRange`: suppose `f` is differentiable on `s` and its derivative at every point of `s` has dense range. If `s` has the unique differential property, then so does `f '' s`. * `uniqueMDiffOn_preimage`: the unique differential property is preserved by local diffeomorphisms * `uniqueDiffOn_target_inter`: the unique differential property is preserved by pullbacks of extended charts * `tangentBundle_proj_preimage`: if `s` has the unique differential property, its preimage under the tangent bundle projection also has -/ noncomputable section open scoped Manifold open Set /-! ### Unique derivative sets in manifolds -/ section UniqueMDiff variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H' M''] {s : Set M} {x : M} section /-- If `s` has the unique differential property at `x`, `f` is differentiable within `s` at `x` and its derivative has dense range, then `f '' s` has the unique differential property at `f x`. -/ theorem UniqueMDiffWithinAt.image_denseRange (hs : UniqueMDiffWithinAt I s x) {f : M → M'} {f' : E →L[𝕜] E'} (hf : HasMFDerivWithinAt I I' f s x f') (hd : DenseRange f') : UniqueMDiffWithinAt I' (f '' s) (f x) := by /- Rewrite in coordinates, apply `HasFDerivWithinAt.uniqueDiffWithinAt`. -/ have := hs.inter' <| hf.1 (extChartAt_source_mem_nhds (I := I') (f x)) refine (((hf.2.mono ?sub1).uniqueDiffWithinAt this hd).mono ?sub2).congr_pt ?pt case pt => simp only [mfld_simps] case sub1 => mfld_set_tac case sub2 => rintro _ ⟨y, ⟨⟨hys, hfy⟩, -⟩, rfl⟩ exact ⟨⟨_, hys, ((extChartAt I' (f x)).left_inv hfy).symm⟩, mem_range_self _⟩ /-- If `s` has the unique differential property, `f` is differentiable on `s` and its derivative at every point of `s` has dense range, then `f '' s` has the unique differential property. This version uses the `HasMFDerivWithinAt` predicate. -/ theorem UniqueMDiffOn.image_denseRange' (hs : UniqueMDiffOn I s) {f : M → M'} {f' : M → E →L[𝕜] E'} (hf : ∀ x ∈ s, HasMFDerivWithinAt I I' f s x (f' x)) (hd : ∀ x ∈ s, DenseRange (f' x)) : UniqueMDiffOn I' (f '' s) := forall_mem_image.2 fun x hx ↦ (hs x hx).image_denseRange (hf x hx) (hd x hx) /-- If `s` has the unique differential property, `f` is differentiable on `s` and its derivative at every point of `s` has dense range, then `f '' s` has the unique differential property. -/ theorem UniqueMDiffOn.image_denseRange (hs : UniqueMDiffOn I s) {f : M → M'} (hf : MDifferentiableOn I I' f s) (hd : ∀ x ∈ s, DenseRange (mfderivWithin I I' f s x)) : UniqueMDiffOn I' (f '' s) := hs.image_denseRange' (fun x hx ↦ (hf x hx).hasMFDerivWithinAt) hd protected theorem UniqueMDiffWithinAt.preimage_openPartialHomeomorph (hs : UniqueMDiffWithinAt I s x) {e : OpenPartialHomeomorph M M'} (he : e.MDifferentiable I I') (hx : x ∈ e.source) : UniqueMDiffWithinAt I' (e.target ∩ e.symm ⁻¹' s) (e x) := by rw [← e.image_source_inter_eq', inter_comm] exact (hs.inter (e.open_source.mem_nhds hx)).image_denseRange (he.mdifferentiableAt hx).hasMFDerivAt.hasMFDerivWithinAt (he.mfderiv_surjective hx).denseRange @[deprecated (since := "2025-08-29")] alias UniqueMDiffWithinAt.preimage_PartialHomeomorph := UniqueMDiffWithinAt.preimage_openPartialHomeomorph /-- If a set has the unique differential property, then its image under a local diffeomorphism also has the unique differential property. -/ theorem UniqueMDiffOn.uniqueMDiffOn_preimage (hs : UniqueMDiffOn I s) {e : OpenPartialHomeomorph M M'} (he : e.MDifferentiable I I') : UniqueMDiffOn I' (e.target ∩ e.symm ⁻¹' s) := fun _x hx ↦ e.right_inv hx.1 ▸ (hs _ hx.2).preimage_openPartialHomeomorph he (e.map_target hx.1) variable [IsManifold I 1 M] in /-- If a set in a manifold has the unique derivative property, then its pullback by any extended chart, in the vector space, also has the unique derivative property. -/ theorem UniqueMDiffOn.uniqueMDiffOn_target_inter (hs : UniqueMDiffOn I s) (x : M) : UniqueMDiffOn 𝓘(𝕜, E) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) := by -- this is just a reformulation of `UniqueMDiffOn.uniqueMDiffOn_preimage`, using as `e` -- the local chart at `x`. rw [← PartialEquiv.image_source_inter_eq', inter_comm, extChartAt_source] exact (hs.inter (chartAt H x).open_source).image_denseRange' (fun y hy ↦ hasMFDerivWithinAt_extChartAt hy.2) fun y hy ↦ ((mdifferentiable_chart _).mfderiv_surjective hy.2).denseRange variable [IsManifold I 1 M] in /-- If a set in a manifold has the unique derivative property, then its pullback by any extended chart, in the vector space, also has the unique derivative property. -/ theorem UniqueMDiffOn.uniqueDiffOn_target_inter (hs : UniqueMDiffOn I s) (x : M) : UniqueDiffOn 𝕜 ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) := (hs.uniqueMDiffOn_target_inter x).uniqueDiffOn variable [IsManifold I 1 M] in theorem UniqueMDiffOn.uniqueDiffWithinAt_range_inter (hs : UniqueMDiffOn I s) (x : M) (y : E) (hy : y ∈ (extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) : UniqueDiffWithinAt 𝕜 (range I ∩ (extChartAt I x).symm ⁻¹' s) y := by apply (hs.uniqueDiffOn_target_inter x y hy).mono apply inter_subset_inter_left _ (extChartAt_target_subset_range x) variable [IsManifold I 1 M] in /-- When considering functions between manifolds, this statement shows up often. It entails the unique differential of the pullback in extended charts of the set where the function can be read in the charts. -/ theorem UniqueMDiffOn.uniqueDiffOn_inter_preimage (hs : UniqueMDiffOn I s) (x : M) (y : M'') {f : M → M''} (hf : ContinuousOn f s) : UniqueDiffOn 𝕜 ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source)) := haveI : UniqueMDiffOn I (s ∩ f ⁻¹' (extChartAt I' y).source) := by intro z hz apply (hs z hz.1).inter' apply (hf z hz.1).preimage_mem_nhdsWithin exact (isOpen_extChartAt_source y).mem_nhds hz.2 this.uniqueDiffOn_target_inter _ end open Bundle variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {Z : M → Type*} [TopologicalSpace (TotalSpace F Z)] [∀ b, TopologicalSpace (Z b)] [FiberBundle F Z] private lemma UniqueMDiffWithinAt.bundle_preimage_aux {p : TotalSpace F Z} (hs : UniqueMDiffWithinAt I s p.proj) (h's : s ⊆ (trivializationAt F Z p.proj).baseSet) : UniqueMDiffWithinAt (I.prod 𝓘(𝕜, F)) (π F Z ⁻¹' s) p := by suffices ((extChartAt I p.proj).symm ⁻¹' s ∩ range I) ×ˢ univ ⊆ (extChartAt (I.prod 𝓘(𝕜, F)) p).symm ⁻¹' (TotalSpace.proj ⁻¹' s) ∩ range (I.prod 𝓘(𝕜, F)) by let w := (extChartAt (I.prod 𝓘(𝕜, F)) p p).2 have A : extChartAt (I.prod 𝓘(𝕜, F)) p p = (extChartAt I p.1 p.1, w) := by ext · simp [FiberBundle.chartedSpace_chartAt] · rfl simp only [UniqueMDiffWithinAt, A] at hs ⊢ exact (hs.prod (uniqueDiffWithinAt_univ (x := w))).mono this rcases p with ⟨x, v⟩ dsimp rintro ⟨z, w⟩ ⟨hz, -⟩ simp only [mem_inter_iff, mem_preimage, Function.comp_apply, mem_range] at hz simp only [FiberBundle.chartedSpace_chartAt, OpenPartialHomeomorph.coe_trans_symm, mem_inter_iff, mem_preimage, Function.comp_apply, mem_range] constructor · rw [PartialEquiv.prod_symm, PartialEquiv.refl_symm, PartialEquiv.prod_coe, ModelWithCorners.toPartialEquiv_coe_symm, PartialEquiv.refl_coe, OpenPartialHomeomorph.prod_symm, OpenPartialHomeomorph.refl_symm, OpenPartialHomeomorph.prod_apply, OpenPartialHomeomorph.refl_apply] convert hz.1 apply Trivialization.proj_symm_apply' exact h's hz.1 · rcases hz.2 with ⟨u, rfl⟩ exact ⟨(u, w), rfl⟩ /-- In a fiber bundle, the preimage under the projection of a set with unique differentials in the base has unique differentials in the bundle. -/ theorem UniqueMDiffWithinAt.bundle_preimage {p : TotalSpace F Z} (hs : UniqueMDiffWithinAt I s p.proj) : UniqueMDiffWithinAt (I.prod 𝓘(𝕜, F)) (π F Z ⁻¹' s) p := by suffices UniqueMDiffWithinAt (I.prod 𝓘(𝕜, F)) (π F Z ⁻¹' (s ∩ (trivializationAt F Z p.proj).baseSet)) p from this.mono (by simp) apply UniqueMDiffWithinAt.bundle_preimage_aux (hs.inter _) inter_subset_right exact IsOpen.mem_nhds (trivializationAt F Z p.proj).open_baseSet (FiberBundle.mem_baseSet_trivializationAt' p.proj) variable (Z) /-- In a fiber bundle, the preimage under the projection of a set with unique differentials in the base has unique differentials in the bundle. Version with a point `⟨b, x⟩`. -/ theorem UniqueMDiffWithinAt.bundle_preimage' {b : M} (hs : UniqueMDiffWithinAt I s b) (x : Z b) : UniqueMDiffWithinAt (I.prod 𝓘(𝕜, F)) (π F Z ⁻¹' s) ⟨b, x⟩ := hs.bundle_preimage (p := ⟨b, x⟩) /-- In a fiber bundle, the preimage under the projection of a set with unique differentials in the base has unique differentials in the bundle. -/ theorem UniqueMDiffOn.bundle_preimage (hs : UniqueMDiffOn I s) : UniqueMDiffOn (I.prod 𝓘(𝕜, F)) (π F Z ⁻¹' s) := fun _p hp ↦ (hs _ hp).bundle_preimage -- TODO: move me to `Mathlib/Geometry/Manifold/VectorBundle/MDifferentiable.lean` variable [∀ b, AddCommMonoid (Z b)] [∀ b, Module 𝕜 (Z b)] [VectorBundle 𝕜 F Z] theorem Trivialization.mdifferentiable [ContMDiffVectorBundle 1 F Z I] (e : Trivialization F (π F Z)) [MemTrivializationAtlas e] : e.MDifferentiable (I.prod 𝓘(𝕜, F)) (I.prod 𝓘(𝕜, F)) := ⟨e.contMDiffOn.mdifferentiableOn le_rfl, e.contMDiffOn_symm.mdifferentiableOn le_rfl⟩ end UniqueMDiff
.lake/packages/mathlib/Mathlib/Geometry/Manifold/MFDeriv/Atlas.lean
import Mathlib.Geometry.Manifold.MFDeriv.SpecificFunctions import Mathlib.Geometry.Manifold.VectorBundle.Tangent /-! # Differentiability of models with corners and (extended) charts In this file, we analyse the differentiability of charts, models with corners and extended charts. We show that * models with corners are differentiable * charts are differentiable on their source * `mdifferentiableOn_extChartAt`: `extChartAt` is differentiable on its source Suppose an open partial homeomorphism `e` is differentiable. This file shows * `OpenPartialHomeomorph.MDifferentiable.mfderiv`: its derivative is a continuous linear equivalence * `OpenPartialHomeomorph.MDifferentiable.mfderiv_bijective`: its derivative is bijective; there are also spelling with trivial kernel and full range In particular, (extended) charts have bijective differential. ## Tags charts, differentiable, bijective -/ noncomputable section open scoped Manifold ContDiff open Bundle Set Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] section ModelWithCorners namespace ModelWithCorners /- In general, the model with corner `I` is implicit in most theorems in differential geometry, but this section is about `I` as a map, not as a parameter. Therefore, we make it explicit. -/ variable (I) /-! #### Model with corners -/ protected theorem hasMFDerivAt {x} : HasMFDerivAt I 𝓘(𝕜, E) I x (ContinuousLinearMap.id _ _) := ⟨I.continuousAt, (hasFDerivWithinAt_id _ _).congr' I.rightInvOn (mem_range_self _)⟩ protected theorem hasMFDerivWithinAt {s x} : HasMFDerivWithinAt I 𝓘(𝕜, E) I s x (ContinuousLinearMap.id _ _) := I.hasMFDerivAt.hasMFDerivWithinAt protected theorem mdifferentiableWithinAt {s x} : MDifferentiableWithinAt I 𝓘(𝕜, E) I s x := I.hasMFDerivWithinAt.mdifferentiableWithinAt protected theorem mdifferentiableAt {x} : MDifferentiableAt I 𝓘(𝕜, E) I x := I.hasMFDerivAt.mdifferentiableAt protected theorem mdifferentiableOn {s} : MDifferentiableOn I 𝓘(𝕜, E) I s := fun _ _ => I.mdifferentiableWithinAt protected theorem mdifferentiable : MDifferentiable I 𝓘(𝕜, E) I := fun _ => I.mdifferentiableAt theorem hasMFDerivWithinAt_symm {x} (hx : x ∈ range I) : HasMFDerivWithinAt 𝓘(𝕜, E) I I.symm (range I) x (ContinuousLinearMap.id _ _) := ⟨I.continuousWithinAt_symm, (hasFDerivWithinAt_id _ _).congr' (fun _y hy => I.rightInvOn hy.1) ⟨hx, mem_range_self _⟩⟩ theorem mdifferentiableOn_symm : MDifferentiableOn 𝓘(𝕜, E) I I.symm (range I) := fun _x hx => (I.hasMFDerivWithinAt_symm hx).mdifferentiableWithinAt theorem mdifferentiableWithinAt_symm {z : E} (hz : z ∈ range I) : MDifferentiableWithinAt 𝓘(𝕜, E) I I.symm (range I) z := I.mdifferentiableOn_symm z hz end ModelWithCorners end ModelWithCorners section Charts variable [IsManifold I 1 M] [IsManifold I' 1 M'] [IsManifold I'' 1 M''] {e : OpenPartialHomeomorph M H} theorem mdifferentiableAt_atlas (h : e ∈ atlas H M) {x : M} (hx : x ∈ e.source) : MDifferentiableAt I I e x := by rw [mdifferentiableAt_iff] refine ⟨(e.continuousOn x hx).continuousAt (e.open_source.mem_nhds hx), ?_⟩ have mem : I ((chartAt H x : M → H) x) ∈ I.symm ⁻¹' ((chartAt H x).symm ≫ₕ e).source ∩ range I := by simp only [hx, mfld_simps] have : (chartAt H x).symm.trans e ∈ contDiffGroupoid 1 I := HasGroupoid.compatible (chart_mem_atlas H x) h have A : ContDiffOn 𝕜 1 (I ∘ (chartAt H x).symm.trans e ∘ I.symm) (I.symm ⁻¹' ((chartAt H x).symm.trans e).source ∩ range I) := this.1 have B := A.differentiableOn le_rfl (I ((chartAt H x : M → H) x)) mem simp only [mfld_simps] at B rw [inter_comm, differentiableWithinAt_inter] at B · simpa only [mfld_simps] · apply IsOpen.mem_nhds ((OpenPartialHomeomorph.open_source _).preimage I.continuous_symm) mem.1 theorem mdifferentiableOn_atlas (h : e ∈ atlas H M) : MDifferentiableOn I I e e.source := fun _x hx => (mdifferentiableAt_atlas h hx).mdifferentiableWithinAt theorem mdifferentiableAt_atlas_symm (h : e ∈ atlas H M) {x : H} (hx : x ∈ e.target) : MDifferentiableAt I I e.symm x := by rw [mdifferentiableAt_iff] refine ⟨(e.continuousOn_symm x hx).continuousAt (e.open_target.mem_nhds hx), ?_⟩ have mem : I x ∈ I.symm ⁻¹' (e.symm ≫ₕ chartAt H (e.symm x)).source ∩ range I := by simp only [hx, mfld_simps] have : e.symm.trans (chartAt H (e.symm x)) ∈ contDiffGroupoid 1 I := HasGroupoid.compatible h (chart_mem_atlas H _) have A : ContDiffOn 𝕜 1 (I ∘ e.symm.trans (chartAt H (e.symm x)) ∘ I.symm) (I.symm ⁻¹' (e.symm.trans (chartAt H (e.symm x))).source ∩ range I) := this.1 have B := A.differentiableOn le_rfl (I x) mem simp only [mfld_simps] at B rw [inter_comm, differentiableWithinAt_inter] at B · simpa only [mfld_simps] · apply IsOpen.mem_nhds ((OpenPartialHomeomorph.open_source _).preimage I.continuous_symm) mem.1 theorem mdifferentiableOn_atlas_symm (h : e ∈ atlas H M) : MDifferentiableOn I I e.symm e.target := fun _x hx => (mdifferentiableAt_atlas_symm h hx).mdifferentiableWithinAt theorem mdifferentiable_of_mem_atlas (h : e ∈ atlas H M) : e.MDifferentiable I I := ⟨mdifferentiableOn_atlas h, mdifferentiableOn_atlas_symm h⟩ theorem mdifferentiable_chart (x : M) : (chartAt H x).MDifferentiable I I := mdifferentiable_of_mem_atlas (chart_mem_atlas _ _) end Charts /-! ### Differentiable open partial homeomorphisms -/ namespace OpenPartialHomeomorph.MDifferentiable variable {e : OpenPartialHomeomorph M M'} (he : e.MDifferentiable I I') {e' : OpenPartialHomeomorph M' M''} include he nonrec theorem symm : e.symm.MDifferentiable I' I := he.symm protected theorem mdifferentiableAt {x : M} (hx : x ∈ e.source) : MDifferentiableAt I I' e x := (he.1 x hx).mdifferentiableAt (e.open_source.mem_nhds hx) theorem mdifferentiableAt_symm {x : M'} (hx : x ∈ e.target) : MDifferentiableAt I' I e.symm x := (he.2 x hx).mdifferentiableAt (e.open_target.mem_nhds hx) theorem symm_comp_deriv {x : M} (hx : x ∈ e.source) : (mfderiv I' I e.symm (e x)).comp (mfderiv I I' e x) = ContinuousLinearMap.id 𝕜 (TangentSpace I x) := by have : mfderiv I I (e.symm ∘ e) x = (mfderiv I' I e.symm (e x)).comp (mfderiv I I' e x) := mfderiv_comp x (he.mdifferentiableAt_symm (e.map_source hx)) (he.mdifferentiableAt hx) rw [← this] have : mfderiv I I (_root_.id : M → M) x = ContinuousLinearMap.id _ _ := mfderiv_id rw [← this] apply Filter.EventuallyEq.mfderiv_eq have : e.source ∈ 𝓝 x := e.open_source.mem_nhds hx exact Filter.mem_of_superset this (by mfld_set_tac) theorem comp_symm_deriv {x : M'} (hx : x ∈ e.target) : (mfderiv I I' e (e.symm x)).comp (mfderiv I' I e.symm x) = ContinuousLinearMap.id 𝕜 (TangentSpace I' x) := he.symm.symm_comp_deriv hx /-- The derivative of a differentiable open partial homeomorphism, as a continuous linear equivalence between the tangent spaces at `x` and `e x`. -/ protected def mfderiv (he : e.MDifferentiable I I') {x : M} (hx : x ∈ e.source) : TangentSpace I x ≃L[𝕜] TangentSpace I' (e x) := { mfderiv I I' e x with invFun := mfderiv I' I e.symm (e x) continuous_toFun := (mfderiv I I' e x).cont continuous_invFun := (mfderiv I' I e.symm (e x)).cont left_inv := fun y => by have : (ContinuousLinearMap.id _ _ : TangentSpace I x →L[𝕜] TangentSpace I x) y = y := rfl conv_rhs => rw [← this, ← he.symm_comp_deriv hx] rfl right_inv := fun y => by have : (ContinuousLinearMap.id 𝕜 _ : TangentSpace I' (e x) →L[𝕜] TangentSpace I' (e x)) y = y := rfl conv_rhs => rw [← this, ← he.comp_symm_deriv (e.map_source hx)] rw [e.left_inv hx] rfl } theorem mfderiv_bijective {x : M} (hx : x ∈ e.source) : Function.Bijective (mfderiv I I' e x) := (he.mfderiv hx).bijective theorem mfderiv_injective {x : M} (hx : x ∈ e.source) : Function.Injective (mfderiv I I' e x) := (he.mfderiv hx).injective theorem mfderiv_surjective {x : M} (hx : x ∈ e.source) : Function.Surjective (mfderiv I I' e x) := (he.mfderiv hx).surjective theorem ker_mfderiv_eq_bot {x : M} (hx : x ∈ e.source) : LinearMap.ker (mfderiv I I' e x) = ⊥ := (he.mfderiv hx).toLinearEquiv.ker theorem range_mfderiv_eq_top {x : M} (hx : x ∈ e.source) : LinearMap.range (mfderiv I I' e x) = ⊤ := (he.mfderiv hx).toLinearEquiv.range theorem range_mfderiv_eq_univ {x : M} (hx : x ∈ e.source) : range (mfderiv I I' e x) = univ := (he.mfderiv_surjective hx).range_eq theorem trans (he' : e'.MDifferentiable I' I'') : (e.trans e').MDifferentiable I I'' := by constructor · intro x hx simp only [mfld_simps] at hx exact ((he'.mdifferentiableAt hx.2).comp _ (he.mdifferentiableAt hx.1)).mdifferentiableWithinAt · intro x hx simp only [mfld_simps] at hx exact ((he.symm.mdifferentiableAt hx.2).comp _ (he'.symm.mdifferentiableAt hx.1)).mdifferentiableWithinAt end OpenPartialHomeomorph.MDifferentiable /-! ### Differentiability of `extChartAt` -/ section extChartAt variable [IsManifold I 1 M] {s : Set M} {x y : M} {z : E} theorem hasMFDerivAt_extChartAt (h : y ∈ (chartAt H x).source) : HasMFDerivAt I 𝓘(𝕜, E) (extChartAt I x) y (mfderiv I I (chartAt H x) y :) := I.hasMFDerivAt.comp y ((mdifferentiable_chart x).mdifferentiableAt h).hasMFDerivAt theorem hasMFDerivWithinAt_extChartAt (h : y ∈ (chartAt H x).source) : HasMFDerivWithinAt I 𝓘(𝕜, E) (extChartAt I x) s y (mfderiv I I (chartAt H x) y :) := (hasMFDerivAt_extChartAt h).hasMFDerivWithinAt theorem mdifferentiableAt_extChartAt (h : y ∈ (chartAt H x).source) : MDifferentiableAt I 𝓘(𝕜, E) (extChartAt I x) y := (hasMFDerivAt_extChartAt h).mdifferentiableAt theorem mdifferentiableOn_extChartAt : MDifferentiableOn I 𝓘(𝕜, E) (extChartAt I x) (chartAt H x).source := fun _y hy => (hasMFDerivWithinAt_extChartAt hy).mdifferentiableWithinAt theorem mdifferentiableWithinAt_extChartAt_symm (h : z ∈ (extChartAt I x).target) : MDifferentiableWithinAt 𝓘(𝕜, E) I (extChartAt I x).symm (range I) z := by have Z := I.mdifferentiableWithinAt_symm (extChartAt_target_subset_range x h) apply MDifferentiableAt.comp_mdifferentiableWithinAt (I' := I) _ _ Z apply mdifferentiableAt_atlas_symm (ChartedSpace.chart_mem_atlas x) simp only [extChartAt, OpenPartialHomeomorph.extend, PartialEquiv.trans_target, ModelWithCorners.target_eq, ModelWithCorners.toPartialEquiv_coe_symm, mem_inter_iff, mem_range, mem_preimage] at h exact h.2 theorem mdifferentiableOn_extChartAt_symm : MDifferentiableOn 𝓘(𝕜, E) I (extChartAt I x).symm (extChartAt I x).target := by intro y hy exact (mdifferentiableWithinAt_extChartAt_symm hy).mono (extChartAt_target_subset_range x) /-- The composition of the derivative of `extChartAt` with the derivative of the inverse of `extChartAt` gives the identity. Version where the basepoint belongs to `(extChartAt I x).target`. -/ lemma mfderiv_extChartAt_comp_mfderivWithin_extChartAt_symm {x : M} {y : E} (hy : y ∈ (extChartAt I x).target) : (mfderiv I 𝓘(𝕜, E) (extChartAt I x) ((extChartAt I x).symm y)) ∘L (mfderivWithin 𝓘(𝕜, E) I (extChartAt I x).symm (range I) y) = ContinuousLinearMap.id _ _ := by have U : UniqueMDiffWithinAt 𝓘(𝕜, E) (range ↑I) y := by apply I.uniqueMDiffOn exact extChartAt_target_subset_range x hy have h'y : (extChartAt I x).symm y ∈ (extChartAt I x).source := (extChartAt I x).map_target hy have h''y : (extChartAt I x).symm y ∈ (chartAt H x).source := by rwa [← extChartAt_source (I := I)] rw [← mfderiv_comp_mfderivWithin]; rotate_left · apply mdifferentiableAt_extChartAt h''y · exact mdifferentiableWithinAt_extChartAt_symm hy · exact U rw [← mfderivWithin_id U] apply Filter.EventuallyEq.mfderivWithin_eq · filter_upwards [extChartAt_target_mem_nhdsWithin_of_mem hy] with z hz simp only [Function.comp_def, PartialEquiv.right_inv (extChartAt I x) hz, id_eq] · simp only [Function.comp_def, PartialEquiv.right_inv (extChartAt I x) hy, id_eq] /-- The composition of the derivative of `extChartAt` with the derivative of the inverse of `extChartAt` gives the identity. Version where the basepoint belongs to `(extChartAt I x).source`. -/ lemma mfderiv_extChartAt_comp_mfderivWithin_extChartAt_symm' {x : M} {y : M} (hy : y ∈ (extChartAt I x).source) : (mfderiv I 𝓘(𝕜, E) (extChartAt I x) y) ∘L (mfderivWithin 𝓘(𝕜, E) I (extChartAt I x).symm (range I) (extChartAt I x y)) = ContinuousLinearMap.id _ _ := by have : y = (extChartAt I x).symm (extChartAt I x y) := ((extChartAt I x).left_inv hy).symm convert mfderiv_extChartAt_comp_mfderivWithin_extChartAt_symm ((extChartAt I x).map_source hy) /-- The composition of the derivative of the inverse of `extChartAt` with the derivative of `extChartAt` gives the identity. Version where the basepoint belongs to `(extChartAt I x).target`. -/ lemma mfderivWithin_extChartAt_symm_comp_mfderiv_extChartAt {y : E} (hy : y ∈ (extChartAt I x).target) : (mfderivWithin 𝓘(𝕜, E) I (extChartAt I x).symm (range I) y) ∘L (mfderiv I 𝓘(𝕜, E) (extChartAt I x) ((extChartAt I x).symm y)) = ContinuousLinearMap.id _ _ := by have h'y : (extChartAt I x).symm y ∈ (extChartAt I x).source := (extChartAt I x).map_target hy have h''y : (extChartAt I x).symm y ∈ (chartAt H x).source := by rwa [← extChartAt_source (I := I)] have U' : UniqueMDiffWithinAt I (extChartAt I x).source ((extChartAt I x).symm y) := (isOpen_extChartAt_source x).uniqueMDiffWithinAt h'y have : mfderiv I 𝓘(𝕜, E) (extChartAt I x) ((extChartAt I x).symm y) = mfderivWithin I 𝓘(𝕜, E) (extChartAt I x) (extChartAt I x).source ((extChartAt I x).symm y) := by rw [mfderivWithin_eq_mfderiv U'] exact mdifferentiableAt_extChartAt h''y rw [this, ← mfderivWithin_comp_of_eq]; rotate_left · exact mdifferentiableWithinAt_extChartAt_symm hy · exact (mdifferentiableAt_extChartAt h''y).mdifferentiableWithinAt · intro z hz apply extChartAt_target_subset_range x exact PartialEquiv.map_source (extChartAt I x) hz · exact U' · exact PartialEquiv.right_inv (extChartAt I x) hy rw [← mfderivWithin_id U'] apply Filter.EventuallyEq.mfderivWithin_eq · filter_upwards [extChartAt_source_mem_nhdsWithin' h'y] with z hz simp only [Function.comp_def, PartialEquiv.left_inv (extChartAt I x) hz, id_eq] · simp only [Function.comp_def, PartialEquiv.right_inv (extChartAt I x) hy, id_eq] /-- The composition of the derivative of the inverse of `extChartAt` with the derivative of `extChartAt` gives the identity. Version where the basepoint belongs to `(extChartAt I x).source`. -/ lemma mfderivWithin_extChartAt_symm_comp_mfderiv_extChartAt' {y : M} (hy : y ∈ (extChartAt I x).source) : (mfderivWithin 𝓘(𝕜, E) I (extChartAt I x).symm (range I) (extChartAt I x y)) ∘L (mfderiv I 𝓘(𝕜, E) (extChartAt I x) y) = ContinuousLinearMap.id _ _ := by have : y = (extChartAt I x).symm (extChartAt I x y) := ((extChartAt I x).left_inv hy).symm convert mfderivWithin_extChartAt_symm_comp_mfderiv_extChartAt ((extChartAt I x).map_source hy) lemma isInvertible_mfderivWithin_extChartAt_symm {y : E} (hy : y ∈ (extChartAt I x).target) : (mfderivWithin 𝓘(𝕜, E) I (extChartAt I x).symm (range I) y).IsInvertible := ContinuousLinearMap.IsInvertible.of_inverse (mfderivWithin_extChartAt_symm_comp_mfderiv_extChartAt hy) (mfderiv_extChartAt_comp_mfderivWithin_extChartAt_symm hy) lemma isInvertible_mfderiv_extChartAt {y : M} (hy : y ∈ (extChartAt I x).source) : (mfderiv I 𝓘(𝕜, E) (extChartAt I x) y).IsInvertible := by have h'y : extChartAt I x y ∈ (extChartAt I x).target := (extChartAt I x).map_source hy have Z := ContinuousLinearMap.IsInvertible.of_inverse (mfderiv_extChartAt_comp_mfderivWithin_extChartAt_symm h'y) (mfderivWithin_extChartAt_symm_comp_mfderiv_extChartAt h'y) have : (extChartAt I x).symm ((extChartAt I x) y) = y := (extChartAt I x).left_inv hy rwa [this] at Z /-- The trivialization of the tangent bundle at a point is the manifold derivative of the extended chart. Use with care as this abuses the defeq `TangentSpace 𝓘(𝕜, E) y = E` for `y : E`. -/ theorem TangentBundle.continuousLinearMapAt_trivializationAt {x₀ x : M} (hx : x ∈ (chartAt H x₀).source) : (trivializationAt E (TangentSpace I) x₀).continuousLinearMapAt 𝕜 x = mfderiv I 𝓘(𝕜, E) (extChartAt I x₀) x := by have : MDifferentiableAt I 𝓘(𝕜, E) (extChartAt I x₀) x := mdifferentiableAt_extChartAt hx simp only [extChartAt, OpenPartialHomeomorph.extend, PartialEquiv.coe_trans, ModelWithCorners.toPartialEquiv_coe, OpenPartialHomeomorph.toFun_eq_coe] at this simp [hx, mfderiv, this] /-- The inverse trivialization of the tangent bundle at a point is the manifold derivative of the inverse of the extended chart. Use with care as this abuses the defeq `TangentSpace 𝓘(𝕜, E) y = E` for `y : E`. -/ theorem TangentBundle.symmL_trivializationAt {x₀ x : M} (hx : x ∈ (chartAt H x₀).source) : (trivializationAt E (TangentSpace I) x₀).symmL 𝕜 x = mfderivWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm (range I) (extChartAt I x₀ x) := by have : MDifferentiableWithinAt 𝓘(𝕜, E) I ((chartAt H x₀).symm ∘ I.symm) (range I) (I (chartAt H x₀ x)) := by simpa using mdifferentiableWithinAt_extChartAt_symm (by simp [hx]) simp [hx, mfderivWithin, this] end extChartAt
.lake/packages/mathlib/Mathlib/Geometry/Manifold/MFDeriv/Basic.lean
import Mathlib.Analysis.Calculus.TangentCone.Prod import Mathlib.Geometry.Manifold.MFDeriv.Defs import Mathlib.Geometry.Manifold.ContMDiff.Defs /-! # Basic properties of the manifold Fréchet derivative In this file, we show various properties of the manifold Fréchet derivative, mimicking the API for Fréchet derivatives. - basic properties of unique differentiability sets - various general lemmas about the manifold Fréchet derivative - deducing differentiability from smoothness, - deriving continuity from differentiability on manifolds, - congruence lemmas for derivatives on manifolds - composition lemmas and the chain rule -/ noncomputable section assert_not_exists tangentBundleCore open scoped Topology Manifold open Set Bundle ChartedSpace section DerivativesProperties /-! ### Unique differentiability sets in manifolds -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] {f f₁ : M → M'} {x : M} {s t : Set M} {g : M' → M''} {u : Set M'} theorem uniqueMDiffWithinAt_univ : UniqueMDiffWithinAt I univ x := by unfold UniqueMDiffWithinAt simp only [preimage_univ, univ_inter] exact I.uniqueDiffOn _ (mem_range_self _) variable {I} theorem uniqueMDiffWithinAt_iff_inter_range {s : Set M} {x : M} : UniqueMDiffWithinAt I s x ↔ UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := Iff.rfl theorem uniqueMDiffWithinAt_iff {s : Set M} {x : M} : UniqueMDiffWithinAt I s x ↔ UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ (extChartAt I x).target) ((extChartAt I x) x) := by apply uniqueDiffWithinAt_congr rw [nhdsWithin_inter, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq] nonrec theorem UniqueMDiffWithinAt.mono_nhds {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x) (ht : 𝓝[s] x ≤ 𝓝[t] x) : UniqueMDiffWithinAt I t x := hs.mono_nhds <| by simpa only [← map_extChartAt_nhdsWithin] using Filter.map_mono ht theorem UniqueMDiffWithinAt.mono_of_mem_nhdsWithin {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I t x := hs.mono_nhds (nhdsWithin_le_iff.2 ht) theorem UniqueMDiffWithinAt.mono (h : UniqueMDiffWithinAt I s x) (st : s ⊆ t) : UniqueMDiffWithinAt I t x := UniqueDiffWithinAt.mono h <| inter_subset_inter (preimage_mono st) (Subset.refl _) theorem UniqueMDiffWithinAt.inter' (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.mono_of_mem_nhdsWithin (Filter.inter_mem self_mem_nhdsWithin ht) theorem UniqueMDiffWithinAt.inter (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝 x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.inter' (nhdsWithin_le_nhds ht) theorem IsOpen.uniqueMDiffWithinAt (hs : IsOpen s) (xs : x ∈ s) : UniqueMDiffWithinAt I s x := (uniqueMDiffWithinAt_univ I).mono_of_mem_nhdsWithin <| nhdsWithin_le_nhds <| hs.mem_nhds xs theorem UniqueMDiffOn.inter (hs : UniqueMDiffOn I s) (ht : IsOpen t) : UniqueMDiffOn I (s ∩ t) := fun _x hx => UniqueMDiffWithinAt.inter (hs _ hx.1) (ht.mem_nhds hx.2) theorem IsOpen.uniqueMDiffOn (hs : IsOpen s) : UniqueMDiffOn I s := fun _x hx => hs.uniqueMDiffWithinAt hx theorem uniqueMDiffOn_univ : UniqueMDiffOn I (univ : Set M) := isOpen_univ.uniqueMDiffOn nonrec theorem UniqueMDiffWithinAt.prod {x : M} {y : M'} {s t} (hs : UniqueMDiffWithinAt I s x) (ht : UniqueMDiffWithinAt I' t y) : UniqueMDiffWithinAt (I.prod I') (s ×ˢ t) (x, y) := by refine (hs.prod ht).mono ?_ rw [ModelWithCorners.range_prod, ← prod_inter_prod] rfl theorem UniqueMDiffOn.prod {s : Set M} {t : Set M'} (hs : UniqueMDiffOn I s) (ht : UniqueMDiffOn I' t) : UniqueMDiffOn (I.prod I') (s ×ˢ t) := fun x h ↦ (hs x.1 h.1).prod (ht x.2 h.2) theorem MDifferentiableWithinAt.mono (hst : s ⊆ t) (h : MDifferentiableWithinAt I I' f t x) : MDifferentiableWithinAt I I' f s x := ⟨ContinuousWithinAt.mono h.1 hst, DifferentiableWithinAt.mono h.differentiableWithinAt_writtenInExtChartAt (inter_subset_inter_left _ (preimage_mono hst))⟩ theorem mdifferentiableWithinAt_univ : MDifferentiableWithinAt I I' f univ x ↔ MDifferentiableAt I I' f x := by simp_rw [MDifferentiableWithinAt, MDifferentiableAt, ChartedSpace.LiftPropAt] theorem mdifferentiableWithinAt_inter (ht : t ∈ 𝓝 x) : MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by rw [MDifferentiableWithinAt, MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_inter ht] theorem mdifferentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) : MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by rw [MDifferentiableWithinAt, MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_inter' ht] theorem MDifferentiableAt.mdifferentiableWithinAt (h : MDifferentiableAt I I' f x) : MDifferentiableWithinAt I I' f s x := MDifferentiableWithinAt.mono (subset_univ _) (mdifferentiableWithinAt_univ.2 h) theorem MDifferentiableWithinAt.mdifferentiableAt (h : MDifferentiableWithinAt I I' f s x) (hs : s ∈ 𝓝 x) : MDifferentiableAt I I' f x := by have : s = univ ∩ s := by rw [univ_inter] rwa [this, mdifferentiableWithinAt_inter hs, mdifferentiableWithinAt_univ] at h theorem MDifferentiableOn.mono (h : MDifferentiableOn I I' f t) (st : s ⊆ t) : MDifferentiableOn I I' f s := fun x hx => (h x (st hx)).mono st @[simp] theorem mdifferentiableOn_empty : MDifferentiableOn I I' f ∅ := fun _x hx ↦ hx.elim theorem mdifferentiableOn_univ : MDifferentiableOn I I' f univ ↔ MDifferentiable I I' f := by simp only [MDifferentiableOn, mdifferentiableWithinAt_univ, mfld_simps]; rfl theorem MDifferentiableOn.mdifferentiableAt (h : MDifferentiableOn I I' f s) (hx : s ∈ 𝓝 x) : MDifferentiableAt I I' f x := (h x (mem_of_mem_nhds hx)).mdifferentiableAt hx theorem MDifferentiable.mdifferentiableOn (h : MDifferentiable I I' f) : MDifferentiableOn I I' f s := (mdifferentiableOn_univ.2 h).mono (subset_univ _) theorem mdifferentiableOn_of_locally_mdifferentiableOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ MDifferentiableOn I I' f (s ∩ u)) : MDifferentiableOn I I' f s := by intro x xs rcases h x xs with ⟨t, t_open, xt, ht⟩ exact (mdifferentiableWithinAt_inter (t_open.mem_nhds xt)).1 (ht x ⟨xs, xt⟩) theorem MDifferentiable.mdifferentiableAt (hf : MDifferentiable I I' f) : MDifferentiableAt I I' f x := hf x /-! ### Relating differentiability in a manifold and differentiability in the model space through extended charts -/ theorem mdifferentiableWithinAt_iff_target_inter {f : M → M'} {s : Set M} {x : M} : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) ((extChartAt I x) x) := by rw [mdifferentiableWithinAt_iff'] refine and_congr Iff.rfl (exists_congr fun f' => ?_) rw [inter_comm] simp only [HasFDerivWithinAt, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq] /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. -/ theorem mdifferentiableWithinAt_iff : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by simp_rw [MDifferentiableWithinAt, ChartedSpace.liftPropWithinAt_iff']; rfl /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. This form states smoothness of `f` written in such a way that the set is restricted to lie within the domain/codomain of the corresponding charts. Even though this expression is more complicated than the one in `mdifferentiableWithinAt_iff`, it is a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite using this in the goal. -/ theorem mdifferentiableWithinAt_iff_target_inter' : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' (f x)).source)) (extChartAt I x x) := by simp only [MDifferentiableWithinAt, liftPropWithinAt_iff'] exact and_congr_right fun hc => differentiableWithinAt_congr_nhds <| hc.nhdsWithin_extChartAt_symm_preimage_inter_range /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart in the target. -/ theorem mdifferentiableWithinAt_iff_target : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ MDifferentiableWithinAt I 𝓘(𝕜, E') (extChartAt I' (f x) ∘ f) s x := by simp_rw [MDifferentiableWithinAt, liftPropWithinAt_iff', ← and_assoc] have cont : ContinuousWithinAt f s x ∧ ContinuousWithinAt (extChartAt I' (f x) ∘ f) s x ↔ ContinuousWithinAt f s x := and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt simp_rw [cont, DifferentiableWithinAtProp, extChartAt, OpenPartialHomeomorph.extend, PartialEquiv.coe_trans, ModelWithCorners.toPartialEquiv_coe, OpenPartialHomeomorph.coe_coe, modelWithCornersSelf_coe, chartAt_self_eq, OpenPartialHomeomorph.refl_apply] rfl theorem mdifferentiableAt_iff_target {x : M} : MDifferentiableAt I I' f x ↔ ContinuousAt f x ∧ MDifferentiableAt I 𝓘(𝕜, E') (extChartAt I' (f x) ∘ f) x := by rw [← mdifferentiableWithinAt_univ, ← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_target, continuousWithinAt_univ] section IsManifold variable {e : OpenPartialHomeomorph M H} {e' : OpenPartialHomeomorph M' H'} open IsManifold theorem mdifferentiableWithinAt_iff_source_of_mem_maximalAtlas [IsManifold I 1 M] (he : e ∈ maximalAtlas I 1 M) (hx : x ∈ e.source) : MDifferentiableWithinAt I I' f s x ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := by have h2x := hx; rw [← e.extend_source (I := I)] at h2x simp_rw [MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart_source he hx, StructureGroupoid.liftPropWithinAt_self_source, e.extend_symm_continuousWithinAt_comp_right_iff, differentiableWithinAtProp_self_source, DifferentiableWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x] rfl theorem mdifferentiableWithinAt_iff_source_of_mem_source [IsManifold I 1 M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : MDifferentiableWithinAt I I' f s x' ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') := mdifferentiableWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx' theorem mdifferentiableAt_iff_source_of_mem_source [IsManifold I 1 M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : MDifferentiableAt I I' f x' ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := by simp_rw [← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_source_of_mem_source hx', preimage_univ, univ_inter] theorem mdifferentiableWithinAt_iff_target_of_mem_source [IsManifold I' 1 M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ MDifferentiableWithinAt I 𝓘(𝕜, E') (extChartAt I' y ∘ f) s x := by simp_rw [MDifferentiableWithinAt] rw [differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart_target (chart_mem_maximalAtlas y) hy, and_congr_right] intro hf simp_rw [StructureGroupoid.liftPropWithinAt_self_target] simp_rw [((chartAt H' y).continuousAt hy).comp_continuousWithinAt hf] rw [← extChartAt_source I'] at hy simp_rw [(continuousAt_extChartAt' hy).comp_continuousWithinAt hf] rfl theorem mdifferentiableAt_iff_target_of_mem_source [IsManifold I' 1 M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : MDifferentiableAt I I' f x ↔ ContinuousAt f x ∧ MDifferentiableAt I 𝓘(𝕜, E') (extChartAt I' y ∘ f) x := by rw [← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_target_of_mem_source hy, continuousWithinAt_univ, ← mdifferentiableWithinAt_univ] variable [IsManifold I 1 M] [IsManifold I' 1 M'] theorem mdifferentiableWithinAt_iff_of_mem_maximalAtlas {x : M} (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hx : x ∈ e.source) (hy : f x ∈ e'.source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart he hx he' hy /-- An alternative formulation of `mdifferentiableWithinAt_iff_of_mem_maximalAtlas` if the set if `s` lies in `e.source`. -/ theorem mdifferentiableWithinAt_iff_image {x : M} (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (hx : x ∈ e.source) (hy : f x ∈ e'.source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) (e.extend I x) := by rw [mdifferentiableWithinAt_iff_of_mem_maximalAtlas he he' hx hy, and_congr_right_iff] refine fun _ => differentiableWithinAt_congr_nhds ?_ simp_rw [nhdsWithin_eq_iff_eventuallyEq, e.extend_symm_preimage_inter_range_eventuallyEq hs hx] /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in any chart containing that point. -/ theorem mdifferentiableWithinAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x' ↔ ContinuousWithinAt f s x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') := mdifferentiableWithinAt_iff_of_mem_maximalAtlas (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hx hy /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in any chart containing that point. Version requiring differentiability in the target instead of `range I`. -/ theorem mdifferentiableWithinAt_iff_of_mem_source' {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x' ↔ ContinuousWithinAt f s x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source)) (extChartAt I x x') := by refine (mdifferentiableWithinAt_iff_of_mem_source hx hy).trans ?_ rw [← extChartAt_source I] at hx rw [← extChartAt_source I'] at hy rw [and_congr_right_iff] set e := extChartAt I x; set e' := extChartAt I' (f x) refine fun hc => differentiableWithinAt_congr_nhds ?_ rw [← e.image_source_inter_eq', ← map_extChartAt_nhdsWithin_eq_image' hx, ← map_extChartAt_nhdsWithin' hx, inter_comm, nhdsWithin_inter_of_mem] exact hc (extChartAt_source_mem_nhds' hy) theorem mdifferentiableAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableAt I I' f x' ↔ ContinuousAt f x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := (mdifferentiableWithinAt_iff_of_mem_source hx hy).trans <| by rw [continuousWithinAt_univ, preimage_univ, univ_inter] theorem mdifferentiableOn_iff_of_mem_maximalAtlas (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (h2s : MapsTo f s e'.source) : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ DifferentiableOn 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) := by simp_rw [ContinuousOn, DifferentiableOn, Set.forall_mem_image, ← forall_and, MDifferentiableOn] exact forall₂_congr fun x hx => mdifferentiableWithinAt_iff_image he he' hs (hs hx) (h2s hx) /-- Differentiability on a set is equivalent to differentiability in the extended charts. -/ theorem mdifferentiableOn_iff_of_mem_maximalAtlas' (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (h2s : MapsTo f s e'.source) : MDifferentiableOn I I' f s ↔ DifferentiableOn 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) := (mdifferentiableOn_iff_of_mem_maximalAtlas he he' hs h2s).trans <| and_iff_right_of_imp fun h ↦ (e.continuousOn_writtenInExtend_iff hs h2s).1 h.continuousOn /-- If the set where you want `f` to be smooth lies entirely in a single chart, and `f` maps it into a single chart, the smoothness of `f` on that set can be expressed by purely looking in these charts. Note: this lemma uses `extChartAt I x '' s` instead of `(extChartAt I x).symm ⁻¹' s` to ensure that this set lies in `(extChartAt I x).target`. -/ theorem mdifferentiableOn_iff_of_subset_source {x : M} {y : M'} (hs : s ⊆ (chartAt H x).source) (h2s : MapsTo f s (chartAt H' y).source) : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (extChartAt I x '' s) := mdifferentiableOn_iff_of_mem_maximalAtlas (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hs h2s /-- If the set where you want `f` to be smooth lies entirely in a single chart, and `f` maps it into a single chart, the smoothness of `f` on that set can be expressed by purely looking in these charts. Note: this lemma uses `extChartAt I x '' s` instead of `(extChartAt I x).symm ⁻¹' s` to ensure that this set lies in `(extChartAt I x).target`. -/ theorem mdifferentiableOn_iff_of_subset_source' {x : M} {y : M'} (hs : s ⊆ (extChartAt I x).source) (h2s : MapsTo f s (extChartAt I' y).source) : MDifferentiableOn I I' f s ↔ DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (extChartAt I x '' s) := by rw [extChartAt_source] at hs h2s exact mdifferentiableOn_iff_of_mem_maximalAtlas' (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hs h2s /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart. -/ theorem mdifferentiableOn_iff : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ ∀ (x : M) (y : M'), DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source)) := by constructor · intro h refine ⟨fun x hx => (h x hx).1, fun x y z hz => ?_⟩ simp only [mfld_simps] at hz let w := (extChartAt I x).symm z have : w ∈ s := by simp only [w, hz, mfld_simps] specialize h w this have w1 : w ∈ (chartAt H x).source := by simp only [w, hz, mfld_simps] have w2 : f w ∈ (chartAt H' y).source := by simp only [w, hz, mfld_simps] convert ((mdifferentiableWithinAt_iff_of_mem_source w1 w2).mp h).2.mono _ · simp only [w, hz, mfld_simps] · mfld_set_tac · rintro ⟨hcont, hdiff⟩ x hx refine differentiableWithinAt_localInvariantProp.liftPropWithinAt_iff.mpr ?_ refine ⟨hcont x hx, ?_⟩ dsimp [DifferentiableWithinAtProp] convert hdiff x (f x) (extChartAt I x x) (by simp only [hx, mfld_simps]) using 1 mfld_set_tac /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart in the target. -/ theorem mdifferentiableOn_iff_target : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ ∀ y : M', MDifferentiableOn I 𝓘(𝕜, E') (extChartAt I' y ∘ f) (s ∩ f ⁻¹' (extChartAt I' y).source) := by simp only [mdifferentiableOn_iff, ModelWithCorners.source_eq, chartAt_self_eq, OpenPartialHomeomorph.refl_partialEquiv, PartialEquiv.refl_trans, extChartAt, OpenPartialHomeomorph.extend, Set.preimage_univ, Set.inter_univ, and_congr_right_iff] intro h constructor · refine fun h' y => ⟨?_, fun x _ => h' x y⟩ have h'' : ContinuousOn _ univ := (ModelWithCorners.continuous I').continuousOn convert (h''.comp_inter (chartAt H' y).continuousOn_toFun).comp_inter h simp · exact fun h' x y => (h' y).2 x 0 /-- One can reformulate smoothness as continuity and smoothness in any extended chart. -/ theorem mdifferentiable_iff : MDifferentiable I I' f ↔ Continuous f ∧ ∀ (x : M) (y : M'), DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (f ⁻¹' (extChartAt I' y).source)) := by simp [← mdifferentiableOn_univ, mdifferentiableOn_iff, continuousOn_univ] /-- One can reformulate smoothness as continuity and smoothness in any extended chart in the target. -/ theorem mdifferentiable_iff_target : MDifferentiable I I' f ↔ Continuous f ∧ ∀ y : M', MDifferentiableOn I 𝓘(𝕜, E') (extChartAt I' y ∘ f) (f ⁻¹' (extChartAt I' y).source) := by rw [← mdifferentiableOn_univ, mdifferentiableOn_iff_target] simp [continuousOn_univ] end IsManifold /-! ### Deducing differentiability from smoothness -/ variable {n : WithTop ℕ∞} theorem ContMDiffWithinAt.mdifferentiableWithinAt (hf : ContMDiffWithinAt I I' n f s x) (hn : 1 ≤ n) : MDifferentiableWithinAt I I' f s x := by suffices h : MDifferentiableWithinAt I I' f (s ∩ f ⁻¹' (extChartAt I' (f x)).source) x by rwa [mdifferentiableWithinAt_inter'] at h apply hf.1.preimage_mem_nhdsWithin exact extChartAt_source_mem_nhds (f x) rw [mdifferentiableWithinAt_iff] exact ⟨hf.1.mono inter_subset_left, (hf.2.differentiableWithinAt (mod_cast hn)).mono (by mfld_set_tac)⟩ theorem ContMDiffAt.mdifferentiableAt (hf : ContMDiffAt I I' n f x) (hn : 1 ≤ n) : MDifferentiableAt I I' f x := mdifferentiableWithinAt_univ.1 <| ContMDiffWithinAt.mdifferentiableWithinAt hf hn theorem ContMDiff.mdifferentiableAt (hf : ContMDiff I I' n f) (hn : 1 ≤ n) : MDifferentiableAt I I' f x := hf.contMDiffAt.mdifferentiableAt hn theorem ContMDiff.mdifferentiableWithinAt (hf : ContMDiff I I' n f) (hn : 1 ≤ n) : MDifferentiableWithinAt I I' f s x := (hf.contMDiffAt.mdifferentiableAt hn).mdifferentiableWithinAt theorem ContMDiffOn.mdifferentiableOn (hf : ContMDiffOn I I' n f s) (hn : 1 ≤ n) : MDifferentiableOn I I' f s := fun x hx => (hf x hx).mdifferentiableWithinAt hn theorem ContMDiff.mdifferentiable (hf : ContMDiff I I' n f) (hn : 1 ≤ n) : MDifferentiable I I' f := fun x => (hf x).mdifferentiableAt hn theorem MDifferentiableOn.continuousOn (h : MDifferentiableOn I I' f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt theorem MDifferentiable.continuous (h : MDifferentiable I I' f) : Continuous f := continuous_iff_continuousAt.2 fun x => (h x).continuousAt /-! ### Deriving continuity from differentiability on manifolds -/ theorem writtenInExtChartAt_comp (h : ContinuousWithinAt f s x) : writtenInExtChartAt I I'' x (g ∘ f) =ᶠ[𝓝[(extChartAt I x).symm ⁻¹' s ∩ range I] (extChartAt I x x)] (writtenInExtChartAt I' I'' (f x) g ∘ writtenInExtChartAt I I' x f) := by apply @Filter.mem_of_superset _ _ (f ∘ (extChartAt I x).symm ⁻¹' (extChartAt I' (f x)).source) _ (extChartAt_preimage_mem_nhdsWithin (h.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds _))) mfld_set_tac variable {f' f₀' f₁' : TangentSpace I x →L[𝕜] TangentSpace I' (f x)} {g' : TangentSpace I' (f x) →L[𝕜] TangentSpace I'' (g (f x))} /-- `UniqueMDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ protected nonrec theorem UniqueMDiffWithinAt.eq (U : UniqueMDiffWithinAt I s x) (h : HasMFDerivWithinAt I I' f s x f') (h₁ : HasMFDerivWithinAt I I' f s x f₁') : f' = f₁' := by -- `by apply` because the instances can be found in the term but not in the goal. apply U.eq h.2 h₁.2 protected theorem UniqueMDiffOn.eq (U : UniqueMDiffOn I s) (hx : x ∈ s) (h : HasMFDerivWithinAt I I' f s x f') (h₁ : HasMFDerivWithinAt I I' f s x f₁') : f' = f₁' := UniqueMDiffWithinAt.eq (U _ hx) h h₁ /-! ### General lemmas on derivatives of functions between manifolds We mimic the API for functions between vector spaces -/ @[simp, mfld_simps] theorem mfderivWithin_univ : mfderivWithin I I' f univ = mfderiv I I' f := by ext x : 1 simp only [mfderivWithin, mfderiv, mfld_simps] rw [mdifferentiableWithinAt_univ] theorem mfderivWithin_zero_of_not_mdifferentiableWithinAt (h : ¬MDifferentiableWithinAt I I' f s x) : mfderivWithin I I' f s x = 0 := by simp only [mfderivWithin, h, if_neg, not_false_iff] theorem mfderiv_zero_of_not_mdifferentiableAt (h : ¬MDifferentiableAt I I' f x) : mfderiv I I' f x = 0 := by simp only [mfderiv, h, if_neg, not_false_iff] theorem mdifferentiable_of_subsingleton [Subsingleton E] : MDifferentiable I I' f := by intro x have : Subsingleton H := I.injective.subsingleton have : DiscreteTopology M := discreteTopology H M simp only [mdifferentiableAt_iff, continuous_of_discreteTopology.continuousAt, true_and] exact (hasFDerivAt_of_subsingleton _ _).differentiableAt.differentiableWithinAt theorem mdifferentiableWithinAt_of_isInvertible_mfderivWithin (hf : (mfderivWithin I I' f s x).IsInvertible) : MDifferentiableWithinAt I I' f s x := by contrapose hf rw [mfderivWithin_zero_of_not_mdifferentiableWithinAt hf] contrapose! hf rcases ContinuousLinearMap.isInvertible_zero_iff.1 hf with ⟨hE, hF⟩ have : Subsingleton E := hE exact mdifferentiable_of_subsingleton.mdifferentiableAt.mdifferentiableWithinAt theorem mdifferentiableAt_of_isInvertible_mfderiv (hf : (mfderiv I I' f x).IsInvertible) : MDifferentiableAt I I' f x := by simp only [← mdifferentiableWithinAt_univ, ← mfderivWithin_univ] at hf ⊢ exact mdifferentiableWithinAt_of_isInvertible_mfderivWithin hf theorem HasMFDerivWithinAt.mono (h : HasMFDerivWithinAt I I' f t x f') (hst : s ⊆ t) : HasMFDerivWithinAt I I' f s x f' := ⟨ContinuousWithinAt.mono h.1 hst, HasFDerivWithinAt.mono h.2 (inter_subset_inter (preimage_mono hst) (Subset.refl _))⟩ theorem HasMFDerivAt.hasMFDerivWithinAt (h : HasMFDerivAt I I' f x f') : HasMFDerivWithinAt I I' f s x f' := ⟨ContinuousAt.continuousWithinAt h.1, HasFDerivWithinAt.mono h.2 inter_subset_right⟩ theorem HasMFDerivWithinAt.mdifferentiableWithinAt (h : HasMFDerivWithinAt I I' f s x f') : MDifferentiableWithinAt I I' f s x := ⟨h.1, ⟨f', h.2⟩⟩ theorem HasMFDerivAt.mdifferentiableAt (h : HasMFDerivAt I I' f x f') : MDifferentiableAt I I' f x := by rw [mdifferentiableAt_iff] exact ⟨h.1, ⟨f', h.2⟩⟩ @[simp, mfld_simps] theorem hasMFDerivWithinAt_univ : HasMFDerivWithinAt I I' f univ x f' ↔ HasMFDerivAt I I' f x f' := by simp only [HasMFDerivWithinAt, HasMFDerivAt, continuousWithinAt_univ, mfld_simps] theorem hasMFDerivAt_unique (h₀ : HasMFDerivAt I I' f x f₀') (h₁ : HasMFDerivAt I I' f x f₁') : f₀' = f₁' := by rw [← hasMFDerivWithinAt_univ] at h₀ h₁ exact (uniqueMDiffWithinAt_univ I).eq h₀ h₁ theorem hasMFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasMFDerivWithinAt I I' f (s ∩ t) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [HasMFDerivWithinAt, HasMFDerivWithinAt, extChartAt_preimage_inter_eq, hasFDerivWithinAt_inter', continuousWithinAt_inter' h] exact extChartAt_preimage_mem_nhdsWithin h theorem hasMFDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasMFDerivWithinAt I I' f (s ∩ t) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [HasMFDerivWithinAt, HasMFDerivWithinAt, extChartAt_preimage_inter_eq, hasFDerivWithinAt_inter, continuousWithinAt_inter h] exact extChartAt_preimage_mem_nhds h theorem HasMFDerivWithinAt.union (hs : HasMFDerivWithinAt I I' f s x f') (ht : HasMFDerivWithinAt I I' f t x f') : HasMFDerivWithinAt I I' f (s ∪ t) x f' := by constructor · exact ContinuousWithinAt.union hs.1 ht.1 · convert HasFDerivWithinAt.union hs.2 ht.2 using 1 simp only [union_inter_distrib_right, preimage_union] theorem HasMFDerivWithinAt.mono_of_mem_nhdsWithin (h : HasMFDerivWithinAt I I' f s x f') (ht : s ∈ 𝓝[t] x) : HasMFDerivWithinAt I I' f t x f' := (hasMFDerivWithinAt_inter' ht).1 (h.mono inter_subset_right) theorem HasMFDerivWithinAt.hasMFDerivAt (h : HasMFDerivWithinAt I I' f s x f') (hs : s ∈ 𝓝 x) : HasMFDerivAt I I' f x f' := by rwa [← univ_inter s, hasMFDerivWithinAt_inter hs, hasMFDerivWithinAt_univ] at h theorem MDifferentiableWithinAt.hasMFDerivWithinAt (h : MDifferentiableWithinAt I I' f s x) : HasMFDerivWithinAt I I' f s x (mfderivWithin I I' f s x) := by refine ⟨h.1, ?_⟩ simp only [mfderivWithin, h, if_pos, mfld_simps] exact DifferentiableWithinAt.hasFDerivWithinAt h.2 theorem mdifferentiableWithinAt_iff_exists_hasMFDerivWithinAt : MDifferentiableWithinAt I I' f s x ↔ ∃ f', HasMFDerivWithinAt I I' f s x f' := by refine ⟨fun h ↦ ⟨mfderivWithin I I' f s x, h.hasMFDerivWithinAt⟩, ?_⟩ rintro ⟨f', hf'⟩ exact hf'.mdifferentiableWithinAt theorem MDifferentiableWithinAt.mono_of_mem_nhdsWithin (h : MDifferentiableWithinAt I I' f s x) {t : Set M} (hst : s ∈ 𝓝[t] x) : MDifferentiableWithinAt I I' f t x := (h.hasMFDerivWithinAt.mono_of_mem_nhdsWithin hst).mdifferentiableWithinAt theorem MDifferentiableWithinAt.congr_nhds (h : MDifferentiableWithinAt I I' f s x) {t : Set M} (hst : 𝓝[s] x = 𝓝[t] x) : MDifferentiableWithinAt I I' f t x := h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin theorem mdifferentiableWithinAt_congr_nhds {t : Set M} (hst : 𝓝[s] x = 𝓝[t] x) : MDifferentiableWithinAt I I' f s x ↔ MDifferentiableWithinAt I I' f t x := ⟨fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩ protected theorem MDifferentiableWithinAt.mfderivWithin (h : MDifferentiableWithinAt I I' f s x) : mfderivWithin I I' f s x = fderivWithin 𝕜 (writtenInExtChartAt I I' x f :) ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := by simp only [mfderivWithin, h, if_pos] theorem MDifferentiableAt.hasMFDerivAt (h : MDifferentiableAt I I' f x) : HasMFDerivAt I I' f x (mfderiv I I' f x) := by refine ⟨h.continuousAt, ?_⟩ simp only [mfderiv, h, if_pos, mfld_simps] exact DifferentiableWithinAt.hasFDerivWithinAt h.differentiableWithinAt_writtenInExtChartAt protected theorem MDifferentiableAt.mfderiv (h : MDifferentiableAt I I' f x) : mfderiv I I' f x = fderivWithin 𝕜 (writtenInExtChartAt I I' x f :) (range I) ((extChartAt I x) x) := by simp only [mfderiv, h, if_pos] protected theorem HasMFDerivAt.mfderiv (h : HasMFDerivAt I I' f x f') : mfderiv I I' f x = f' := (hasMFDerivAt_unique h h.mdifferentiableAt.hasMFDerivAt).symm protected theorem HasMFDerivWithinAt.mfderivWithin (h : HasMFDerivWithinAt I I' f s x f') (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I' f s x = f' := by ext rw [hxs.eq h h.mdifferentiableWithinAt.hasMFDerivWithinAt] theorem HasMFDerivWithinAt.mfderivWithin_eq_zero (h : HasMFDerivWithinAt I I' f s x 0) : mfderivWithin I I' f s x = 0 := by simp only [mfld_simps, mfderivWithin, h.mdifferentiableWithinAt, ↓reduceIte] simp only [HasMFDerivWithinAt, mfld_simps] at h rw [fderivWithin, if_pos] exact h.2 theorem MDifferentiable.mfderivWithin (h : MDifferentiableAt I I' f x) (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I' f s x = mfderiv I I' f x := by apply HasMFDerivWithinAt.mfderivWithin _ hxs exact h.hasMFDerivAt.hasMFDerivWithinAt theorem mfderivWithin_subset (st : s ⊆ t) (hs : UniqueMDiffWithinAt I s x) (h : MDifferentiableWithinAt I I' f t x) : mfderivWithin I I' f s x = mfderivWithin I I' f t x := ((MDifferentiableWithinAt.hasMFDerivWithinAt h).mono st).mfderivWithin hs theorem mfderivWithin_inter (ht : t ∈ 𝓝 x) : mfderivWithin I I' f (s ∩ t) x = mfderivWithin I I' f s x := by rw [mfderivWithin, mfderivWithin, extChartAt_preimage_inter_eq, mdifferentiableWithinAt_inter ht, fderivWithin_inter (extChartAt_preimage_mem_nhds ht)] theorem mfderivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : mfderivWithin I I' f s x = mfderiv I I' f x := by rw [← mfderivWithin_univ, ← univ_inter s, mfderivWithin_inter h] lemma mfderivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : mfderivWithin I I' f s x = mfderiv I I' f x := mfderivWithin_of_mem_nhds (hs.mem_nhds hx) theorem hasMFDerivWithinAt_insert {y : M} : HasMFDerivWithinAt I I' f (insert y s) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by have : T1Space M := I.t1Space M refine ⟨fun h => h.mono <| subset_insert y s, fun hf ↦ ?_⟩ rcases eq_or_ne x y with rfl | h · rw [HasMFDerivWithinAt] at hf ⊢ refine ⟨hf.1.insert, ?_⟩ have : (extChartAt I x).target ∈ 𝓝[(extChartAt I x).symm ⁻¹' insert x s ∩ range I] (extChartAt I x) x := nhdsWithin_mono _ inter_subset_right (extChartAt_target_mem_nhdsWithin x) rw [← hasFDerivWithinAt_inter' this] apply hf.2.insert.mono rintro z ⟨⟨hz, h2z⟩, h'z⟩ simp only [mem_inter_iff, mem_preimage, mem_insert_iff, mem_range] at hz h2z ⊢ rcases hz with xz | h'z · left have : x ∈ (extChartAt I x).source := mem_extChartAt_source x exact (((extChartAt I x).eq_symm_apply this h'z).1 xz.symm).symm · exact Or.inr ⟨h'z, h2z⟩ · apply hf.mono_of_mem_nhdsWithin ?_ simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin] alias ⟨HasMFDerivWithinAt.of_insert, HasMFDerivWithinAt.insert'⟩ := hasMFDerivWithinAt_insert protected theorem HasMFDerivWithinAt.insert (h : HasMFDerivWithinAt I I' f s x f') : HasMFDerivWithinAt I I' f (insert x s) x f' := h.insert' theorem hasMFDerivWithinAt_diff_singleton (y : M) : HasMFDerivWithinAt I I' f (s \ {y}) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [← hasMFDerivWithinAt_insert, insert_diff_singleton, hasMFDerivWithinAt_insert] theorem mfderivWithin_eq_mfderiv (hs : UniqueMDiffWithinAt I s x) (h : MDifferentiableAt I I' f x) : mfderivWithin I I' f s x = mfderiv I I' f x := by rw [← mfderivWithin_univ] exact mfderivWithin_subset (subset_univ _) hs h.mdifferentiableWithinAt theorem mdifferentiableWithinAt_insert_self : MDifferentiableWithinAt I I' f (insert x s) x ↔ MDifferentiableWithinAt I I' f s x := ⟨fun h ↦ h.mono (subset_insert x s), fun h ↦ h.hasMFDerivWithinAt.insert.mdifferentiableWithinAt⟩ theorem mdifferentiableWithinAt_insert {y : M} : MDifferentiableWithinAt I I' f (insert y s) x ↔ MDifferentiableWithinAt I I' f s x := by rcases eq_or_ne x y with (rfl | h) · exact mdifferentiableWithinAt_insert_self have : T1Space M := I.t1Space M apply mdifferentiableWithinAt_congr_nhds exact nhdsWithin_insert_of_ne h alias ⟨MDifferentiableWithinAt.of_insert, MDifferentiableWithinAt.insert'⟩ := mdifferentiableWithinAt_insert protected theorem MDifferentiableWithinAt.insert (h : MDifferentiableWithinAt I I' f s x) : MDifferentiableWithinAt I I' f (insert x s) x := h.insert' /-! ### Being differentiable on a union of open sets can be tested on each set -/ section mdifferentiableOn_union /-- If a function is differentiable on two open sets, it is also differentiable on their union. -/ lemma MDifferentiableOn.union_of_isOpen (hf : MDifferentiableOn I I' f s) (hf' : MDifferentiableOn I I' f t) (hs : IsOpen s) (ht : IsOpen t) : MDifferentiableOn I I' f (s ∪ t) := by intro x hx obtain (hx | hx) := hx · exact (hf x hx).mdifferentiableAt (hs.mem_nhds hx) |>.mdifferentiableWithinAt · exact (hf' x hx).mdifferentiableAt (ht.mem_nhds hx) |>.mdifferentiableWithinAt /-- A function is differentiable on two open sets iff it is differentiable on their union. -/ lemma mdifferentiableOn_union_iff_of_isOpen (hs : IsOpen s) (ht : IsOpen t) : MDifferentiableOn I I' f (s ∪ t) ↔ MDifferentiableOn I I' f s ∧ MDifferentiableOn I I' f t := ⟨fun h ↦ ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun ⟨hfs, hft⟩ ↦ MDifferentiableOn.union_of_isOpen hfs hft hs ht⟩ lemma mdifferentiable_of_mdifferentiableOn_union_of_isOpen (hf : MDifferentiableOn I I' f s) (hf' : MDifferentiableOn I I' f t) (hst : s ∪ t = univ) (hs : IsOpen s) (ht : IsOpen t) : MDifferentiable I I' f := by rw [← mdifferentiableOn_univ, ← hst] exact hf.union_of_isOpen hf' hs ht /-- If a function is differentiable on open sets `s i`, it is differentiable on their union. -/ lemma MDifferentiableOn.iUnion_of_isOpen {ι : Type*} {s : ι → Set M} (hf : ∀ i : ι, MDifferentiableOn I I' f (s i)) (hs : ∀ i, IsOpen (s i)) : MDifferentiableOn I I' f (⋃ i, s i) := by rintro x ⟨si, ⟨i, rfl⟩, hxsi⟩ exact (hf i).mdifferentiableAt ((hs i).mem_nhds hxsi) |>.mdifferentiableWithinAt /-- A function is differentiable on a union of open sets `s i` iff it is differentiable on each `s i`. -/ lemma mdifferentiableOn_iUnion_iff_of_isOpen {ι : Type*} {s : ι → Set M} (hs : ∀ i, IsOpen (s i)) : MDifferentiableOn I I' f (⋃ i, s i) ↔ ∀ i : ι, MDifferentiableOn I I' f (s i) := ⟨fun h i ↦ h.mono <| subset_iUnion_of_subset i fun _ a ↦ a, fun h ↦ MDifferentiableOn.iUnion_of_isOpen h hs⟩ lemma mdifferentiable_of_mdifferentiableOn_iUnion_of_isOpen {ι : Type*} {s : ι → Set M} (hf : ∀ i : ι, MDifferentiableOn I I' f (s i)) (hs : ∀ i, IsOpen (s i)) (hs' : ⋃ i, s i = univ) : MDifferentiable I I' f := by rw [← mdifferentiableOn_univ, ← hs'] exact MDifferentiableOn.iUnion_of_isOpen hf hs end mdifferentiableOn_union /-! ### Deriving continuity from differentiability on manifolds -/ theorem HasMFDerivWithinAt.continuousWithinAt (h : HasMFDerivWithinAt I I' f s x f') : ContinuousWithinAt f s x := h.1 theorem HasMFDerivAt.continuousAt (h : HasMFDerivAt I I' f x f') : ContinuousAt f x := h.1 theorem tangentMapWithin_subset {p : TangentBundle I M} (st : s ⊆ t) (hs : UniqueMDiffWithinAt I s p.1) (h : MDifferentiableWithinAt I I' f t p.1) : tangentMapWithin I I' f s p = tangentMapWithin I I' f t p := by simp only [tangentMapWithin, mfld_simps] rw [mfderivWithin_subset st hs h] theorem tangentMapWithin_univ : tangentMapWithin I I' f univ = tangentMap I I' f := by ext p : 1 simp only [tangentMapWithin, tangentMap, mfld_simps] theorem tangentMapWithin_eq_tangentMap {p : TangentBundle I M} (hs : UniqueMDiffWithinAt I s p.1) (h : MDifferentiableAt I I' f p.1) : tangentMapWithin I I' f s p = tangentMap I I' f p := by rw [← mdifferentiableWithinAt_univ] at h rw [← tangentMapWithin_univ] exact tangentMapWithin_subset (subset_univ _) hs h @[simp, mfld_simps] theorem tangentMapWithin_proj {p : TangentBundle I M} : (tangentMapWithin I I' f s p).proj = f p.proj := rfl @[simp, mfld_simps] theorem tangentMap_proj {p : TangentBundle I M} : (tangentMap I I' f p).proj = f p.proj := rfl /-- If two sets coincide locally around `x`, except maybe at a point `y`, then their preimage under `extChartAt x` coincide locally, except maybe at `extChartAt I x x`. -/ theorem preimage_extChartAt_eventuallyEq_compl_singleton (y : M) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : ((extChartAt I x).symm ⁻¹' s ∩ range I : Set E) =ᶠ[𝓝[{extChartAt I x x}ᶜ] (extChartAt I x x)] ((extChartAt I x).symm ⁻¹' t ∩ range I : Set E) := by have : T1Space M := I.t1Space M obtain ⟨u, u_mem, hu⟩ : ∃ u ∈ 𝓝 x, u ∩ {x}ᶜ ⊆ {y | (y ∈ s) = (y ∈ t)} := mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (nhdsWithin_compl_singleton_le x y h) rw [← extChartAt_to_inv (I:= I) x] at u_mem have B : (extChartAt I x).target ∪ (range I)ᶜ ∈ 𝓝 (extChartAt I x x) := by rw [← nhdsWithin_univ, ← union_compl_self (range I), nhdsWithin_union] apply Filter.union_mem_sup (extChartAt_target_mem_nhdsWithin x) self_mem_nhdsWithin apply mem_nhdsWithin_iff_exists_mem_nhds_inter.2 ⟨_, Filter.inter_mem ((continuousAt_extChartAt_symm x).preimage_mem_nhds u_mem) B, ?_⟩ rintro z ⟨hz, h'z⟩ simp only [eq_iff_iff, mem_setOf_eq] change z ∈ (extChartAt I x).symm ⁻¹' s ∩ range I ↔ z ∈ (extChartAt I x).symm ⁻¹' t ∩ range I by_cases hIz : z ∈ range I · simp [-extChartAt, hIz] at hz ⊢ rw [← eq_iff_iff] apply hu ⟨hz.1, ?_⟩ simp only [mem_compl_iff, mem_singleton_iff, ne_comm, ne_eq] at h'z ⊢ rw [(extChartAt I x).eq_symm_apply (by simp) hz.2] exact Ne.symm h'z · simp [hIz] /-! ### Congruence lemmas for derivatives on manifolds -/ /-- If two sets coincide locally, except maybe at a point, then it is equivalent to have a manifold derivative within one or the other. -/ theorem hasMFDerivWithinAt_congr_set' (y : M) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : HasMFDerivWithinAt I I' f s x f' ↔ HasMFDerivWithinAt I I' f t x f' := by have : T1Space M := I.t1Space M simp only [HasMFDerivWithinAt] refine and_congr ?_ ?_ · exact continuousWithinAt_congr_set' _ h · apply hasFDerivWithinAt_congr_set' (extChartAt I x x) exact preimage_extChartAt_eventuallyEq_compl_singleton y h theorem hasMFDerivWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) : HasMFDerivWithinAt I I' f s x f' ↔ HasMFDerivWithinAt I I' f t x f' := hasMFDerivWithinAt_congr_set' x <| h.filter_mono inf_le_left /-- If two sets coincide around a point (except possibly at a single point `y`), then it is equivalent to be differentiable within one or the other set. -/ theorem mdifferentiableWithinAt_congr_set' (y : M) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : MDifferentiableWithinAt I I' f s x ↔ MDifferentiableWithinAt I I' f t x := by simp only [mdifferentiableWithinAt_iff_exists_hasMFDerivWithinAt] exact exists_congr fun _ => hasMFDerivWithinAt_congr_set' _ h theorem mdifferentiableWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) : MDifferentiableWithinAt I I' f s x ↔ MDifferentiableWithinAt I I' f t x := by simp only [mdifferentiableWithinAt_iff_exists_hasMFDerivWithinAt] exact exists_congr fun _ => hasMFDerivWithinAt_congr_set h /-- If two sets coincide locally, except maybe at a point, then derivatives within these sets are the same. -/ theorem mfderivWithin_congr_set' (y : M) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : mfderivWithin I I' f s x = mfderivWithin I I' f t x := by by_cases hx : MDifferentiableWithinAt I I' f s x · simp only [mfderivWithin, hx, (mdifferentiableWithinAt_congr_set' y h).1 hx, ↓reduceIte] apply fderivWithin_congr_set' (extChartAt I x x) exact preimage_extChartAt_eventuallyEq_compl_singleton y h · simp [mfderivWithin, hx, ← mdifferentiableWithinAt_congr_set' y h] /-- If two sets coincide locally, then derivatives within these sets are the same. -/ theorem mfderivWithin_congr_set (h : s =ᶠ[𝓝 x] t) : mfderivWithin I I' f s x = mfderivWithin I I' f t x := mfderivWithin_congr_set' x <| h.filter_mono inf_le_left /-- If two sets coincide locally, except maybe at a point, then derivatives within these sets coincide locally. -/ theorem mfderivWithin_eventually_congr_set' (y : M) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : ∀ᶠ y in 𝓝 x, mfderivWithin I I' f s y = mfderivWithin I I' f t y := (eventually_nhds_nhdsWithin.2 h).mono fun _ => mfderivWithin_congr_set' y /-- If two sets coincide locally, then derivatives within these sets coincide locally. -/ theorem mfderivWithin_eventually_congr_set (h : s =ᶠ[𝓝 x] t) : ∀ᶠ y in 𝓝 x, mfderivWithin I I' f s y = mfderivWithin I I' f t y := mfderivWithin_eventually_congr_set' x <| h.filter_mono inf_le_left theorem HasMFDerivAt.congr_mfderiv (h : HasMFDerivAt I I' f x f') (h' : f' = f₁') : HasMFDerivAt I I' f x f₁' := h' ▸ h theorem HasMFDerivWithinAt.congr_mfderiv (h : HasMFDerivWithinAt I I' f s x f') (h' : f' = f₁') : HasMFDerivWithinAt I I' f s x f₁' := h' ▸ h theorem HasMFDerivWithinAt.congr_of_eventuallyEq (h : HasMFDerivWithinAt I I' f s x f') (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : HasMFDerivWithinAt I I' f₁ s x f' := by refine ⟨ContinuousWithinAt.congr_of_eventuallyEq h.1 h₁ hx, ?_⟩ apply HasFDerivWithinAt.congr_of_eventuallyEq h.2 · have : (extChartAt I x).symm ⁻¹' {y | f₁ y = f y} ∈ 𝓝[(extChartAt I x).symm ⁻¹' s ∩ range I] (extChartAt I x) x := extChartAt_preimage_mem_nhdsWithin h₁ apply Filter.mem_of_superset this fun y => _ simp +contextual only [hx, mfld_simps] · simp only [hx, mfld_simps] theorem HasMFDerivWithinAt.congr_mono (h : HasMFDerivWithinAt I I' f s x f') (ht : ∀ x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : HasMFDerivWithinAt I I' f₁ t x f' := (h.mono h₁).congr_of_eventuallyEq (Filter.mem_inf_of_right ht) hx theorem HasMFDerivAt.congr_of_eventuallyEq (h : HasMFDerivAt I I' f x f') (h₁ : f₁ =ᶠ[𝓝 x] f) : HasMFDerivAt I I' f₁ x f' := by rw [← hasMFDerivWithinAt_univ] at h ⊢ apply h.congr_of_eventuallyEq _ (mem_of_mem_nhds h₁ :) rwa [nhdsWithin_univ] theorem mdifferentiableWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : MDifferentiableWithinAt I I' f₁ s x ↔ MDifferentiableWithinAt I I' f s x := differentiableWithinAt_localInvariantProp.liftPropWithinAt_congr_iff h₁ hx theorem MDifferentiableWithinAt.congr_of_mem (h : MDifferentiableWithinAt I I' f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : MDifferentiableWithinAt I I' f₁ s x := differentiableWithinAt_localInvariantProp.liftPropWithinAt_congr_of_mem h h₁ hx theorem mdifferentiableWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : MDifferentiableWithinAt I I' f₁ s x ↔ MDifferentiableWithinAt I I' f s x := differentiableWithinAt_localInvariantProp.liftPropWithinAt_congr_iff_of_mem h₁ hx theorem Filter.EventuallyEq.mdifferentiablefWithinAt_iff (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : MDifferentiableWithinAt I I' f₁ s x ↔ MDifferentiableWithinAt I I' f s x := differentiableWithinAt_localInvariantProp.liftPropWithinAt_congr_iff_of_eventuallyEq h₁ hx theorem MDifferentiableWithinAt.congr_of_eventuallyEq (h : MDifferentiableWithinAt I I' f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : MDifferentiableWithinAt I I' f₁ s x := (h.hasMFDerivWithinAt.congr_of_eventuallyEq h₁ hx).mdifferentiableWithinAt theorem MDifferentiableWithinAt.congr_of_eventuallyEq_of_mem (h : MDifferentiableWithinAt I I' f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : MDifferentiableWithinAt I I' f₁ s x := h.congr_of_eventuallyEq h₁ (mem_of_mem_nhdsWithin hx h₁ :) theorem MDifferentiableWithinAt.congr_of_eventuallyEq_insert (h : MDifferentiableWithinAt I I' f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : MDifferentiableWithinAt I I' f₁ s x := (h.insert.congr_of_eventuallyEq_of_mem h₁ (mem_insert x s)).of_insert theorem Filter.EventuallyEq.mdifferentiableWithinAt_iff (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : MDifferentiableWithinAt I I' f s x ↔ MDifferentiableWithinAt I I' f₁ s x := mdifferentiablefWithinAt_iff h₁.symm hx.symm theorem MDifferentiableWithinAt.congr_mono (h : MDifferentiableWithinAt I I' f s x) (ht : ∀ x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : MDifferentiableWithinAt I I' f₁ t x := (HasMFDerivWithinAt.congr_mono h.hasMFDerivWithinAt ht hx h₁).mdifferentiableWithinAt theorem MDifferentiableWithinAt.congr (h : MDifferentiableWithinAt I I' f s x) (ht : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : MDifferentiableWithinAt I I' f₁ s x := (HasMFDerivWithinAt.congr_mono h.hasMFDerivWithinAt ht hx (Subset.refl _)).mdifferentiableWithinAt /-- Version of `MDifferentiableWithinAt.congr` where `x` need not be contained in `s`, but `f` and `f₁` are equal on a set containing both. -/ theorem MDifferentiableWithinAt.congr' (h : MDifferentiableWithinAt I I' f s x) (ht : ∀ x ∈ t, f₁ x = f x) (hst : s ⊆ t) (hxt : x ∈ t) : MDifferentiableWithinAt I I' f₁ s x := h.congr (fun _y hy ↦ ht _y (hst hy)) (ht x hxt) theorem Filter.EventuallyEq.mdifferentiableAt_iff (h₁ : f₁ =ᶠ[𝓝 x] f) : MDifferentiableAt I I' f₁ x ↔ MDifferentiableAt I I' f x := differentiableWithinAt_localInvariantProp.liftPropAt_congr_iff_of_eventuallyEq h₁ theorem MDifferentiableOn.congr (h : MDifferentiableOn I I' f s) (h₁ : ∀ y ∈ s, f₁ y = f y) : MDifferentiableOn I I' f₁ s := differentiableWithinAt_localInvariantProp.liftPropOn_congr h h₁ theorem mdifferentiableOn_congr (h₁ : ∀ y ∈ s, f₁ y = f y) : MDifferentiableOn I I' f₁ s ↔ MDifferentiableOn I I' f s := differentiableWithinAt_localInvariantProp.liftPropOn_congr_iff h₁ theorem MDifferentiableOn.congr_mono (h : MDifferentiableOn I I' f s) (h' : ∀ x ∈ t, f₁ x = f x) (h₁ : t ⊆ s) : MDifferentiableOn I I' f₁ t := fun x hx => (h x (h₁ hx)).congr_mono h' (h' x hx) h₁ theorem MDifferentiableAt.congr_of_eventuallyEq (h : MDifferentiableAt I I' f x) (hL : f₁ =ᶠ[𝓝 x] f) : MDifferentiableAt I I' f₁ x := (h.hasMFDerivAt.congr_of_eventuallyEq hL).mdifferentiableAt theorem MDifferentiableWithinAt.mfderivWithin_congr_mono (h : MDifferentiableWithinAt I I' f s x) (hs : ∀ x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : UniqueMDiffWithinAt I t x) (h₁ : t ⊆ s) : mfderivWithin I I' f₁ t x = mfderivWithin I I' f s x := (HasMFDerivWithinAt.congr_mono h.hasMFDerivWithinAt hs hx h₁).mfderivWithin hxt theorem MDifferentiableWithinAt.mfderivWithin_mono (h : MDifferentiableWithinAt I I' f s x) (hxt : UniqueMDiffWithinAt I t x) (h₁ : t ⊆ s) : mfderivWithin I I' f t x = mfderivWithin I I' f s x := h.mfderivWithin_congr_mono (fun _ _ ↦ rfl) rfl hxt h₁ theorem MDifferentiableWithinAt.mfderivWithin_mono_of_mem_nhdsWithin (h : MDifferentiableWithinAt I I' f s x) (hxt : UniqueMDiffWithinAt I t x) (h₁ : s ∈ 𝓝[t] x) : mfderivWithin I I' f t x = mfderivWithin I I' f s x := (HasMFDerivWithinAt.mono_of_mem_nhdsWithin h.hasMFDerivWithinAt h₁).mfderivWithin hxt theorem Filter.EventuallyEq.mfderivWithin_eq (hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : mfderivWithin I I' f₁ s x = mfderivWithin I I' f s x := by by_cases h : MDifferentiableWithinAt I I' f s x · unfold mfderivWithin simp only [h, (hL.mdifferentiableWithinAt_iff hx).1 h, ↓reduceIte, writtenInExtChartAt] apply Filter.EventuallyEq.fderivWithin_eq; swap · simp [hx] filter_upwards [extChartAt_preimage_mem_nhdsWithin (I := I) hL] with y hy simp only [preimage_setOf_eq, mem_setOf_eq] at hy simp [-extChartAt, hy, hx] · unfold mfderivWithin rw [if_neg h, if_neg] rwa [← hL.mdifferentiableWithinAt_iff hx] theorem Filter.EventuallyEq.mfderivWithin_eq_of_mem (hL : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : mfderivWithin I I' f₁ s x = mfderivWithin I I' f s x := hL.mfderivWithin_eq (mem_of_mem_nhdsWithin hx hL :) theorem mfderivWithin_congr (hL : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : mfderivWithin I I' f₁ s x = mfderivWithin I I' f s x := Filter.EventuallyEq.mfderivWithin_eq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin hL) hx theorem mfderivWithin_congr_of_mem (hL : ∀ x ∈ s, f₁ x = f x) (hx : x ∈ s) : mfderivWithin I I' f₁ s x = mfderivWithin I I' f s x := Filter.EventuallyEq.mfderivWithin_eq_of_mem (Filter.eventuallyEq_of_mem self_mem_nhdsWithin hL) hx theorem tangentMapWithin_congr (h : ∀ x ∈ s, f x = f₁ x) (p : TangentBundle I M) (hp : p.1 ∈ s) : tangentMapWithin I I' f s p = tangentMapWithin I I' f₁ s p := by refine TotalSpace.ext (h p.1 hp) ?_ rw [tangentMapWithin, h p.1 hp, tangentMapWithin, mfderivWithin_congr h (h _ hp)] theorem Filter.EventuallyEq.mfderiv_eq (hL : f₁ =ᶠ[𝓝 x] f) : mfderiv I I' f₁ x = mfderiv I I' f x := by have A : f₁ x = f x := (mem_of_mem_nhds hL :) rw [← mfderivWithin_univ, ← mfderivWithin_univ] rw [← nhdsWithin_univ] at hL exact hL.mfderivWithin_eq A /-- A congruence lemma for `mfderiv`, (ab)using the fact that `TangentSpace I' (f x)` is definitionally equal to `E'`. -/ theorem mfderiv_congr_point {x' : M} (h : x = x') : @Eq (E →L[𝕜] E') (mfderiv I I' f x) (mfderiv I I' f x') := by subst h; rfl /-- A congruence lemma for `mfderiv`, (ab)using the fact that `TangentSpace I' (f x)` is definitionally equal to `E'`. -/ theorem mfderiv_congr {f' : M → M'} (h : f = f') : @Eq (E →L[𝕜] E') (mfderiv I I' f x) (mfderiv I I' f' x) := by subst h; rfl /-! ### Composition lemmas -/ variable (x) theorem HasMFDerivWithinAt.comp (hg : HasMFDerivWithinAt I' I'' g u (f x) g') (hf : HasMFDerivWithinAt I I' f s x f') (hst : s ⊆ f ⁻¹' u) : HasMFDerivWithinAt I I'' (g ∘ f) s x (g'.comp f') := by refine ⟨ContinuousWithinAt.comp hg.1 hf.1 hst, ?_⟩ have A : HasFDerivWithinAt (writtenInExtChartAt I' I'' (f x) g ∘ writtenInExtChartAt I I' x f) (ContinuousLinearMap.comp g' f' : E →L[𝕜] E'') ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := by have : (extChartAt I x).symm ⁻¹' (f ⁻¹' (extChartAt I' (f x)).source) ∈ 𝓝[(extChartAt I x).symm ⁻¹' s ∩ range I] (extChartAt I x) x := extChartAt_preimage_mem_nhdsWithin (hf.1.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds _)) unfold HasMFDerivWithinAt at * rw [← hasFDerivWithinAt_inter' this, ← extChartAt_preimage_inter_eq] at hf ⊢ have : writtenInExtChartAt I I' x f ((extChartAt I x) x) = (extChartAt I' (f x)) (f x) := by simp only [mfld_simps] rw [← this] at hg apply HasFDerivWithinAt.comp ((extChartAt I x) x) hg.2 hf.2 _ intro y hy simp only [mfld_simps] at hy have : f (((chartAt H x).symm : H → M) (I.symm y)) ∈ u := hst hy.1.1 simp only [hy, this, mfld_simps] apply A.congr_of_eventuallyEq (writtenInExtChartAt_comp hf.1) simp only [mfld_simps] /-- The **chain rule for manifolds**. -/ theorem HasMFDerivAt.comp (hg : HasMFDerivAt I' I'' g (f x) g') (hf : HasMFDerivAt I I' f x f') : HasMFDerivAt I I'' (g ∘ f) x (g'.comp f') := by rw [← hasMFDerivWithinAt_univ] at * exact HasMFDerivWithinAt.comp x (hg.mono (subset_univ _)) hf subset_preimage_univ theorem HasMFDerivAt.comp_hasMFDerivWithinAt (hg : HasMFDerivAt I' I'' g (f x) g') (hf : HasMFDerivWithinAt I I' f s x f') : HasMFDerivWithinAt I I'' (g ∘ f) s x (g'.comp f') := by rw [← hasMFDerivWithinAt_univ] at * exact HasMFDerivWithinAt.comp x (hg.mono (subset_univ _)) hf subset_preimage_univ theorem MDifferentiableWithinAt.comp (hg : MDifferentiableWithinAt I' I'' g u (f x)) (hf : MDifferentiableWithinAt I I' f s x) (h : s ⊆ f ⁻¹' u) : MDifferentiableWithinAt I I'' (g ∘ f) s x := by rcases hf.2 with ⟨f', hf'⟩ have F : HasMFDerivWithinAt I I' f s x f' := ⟨hf.1, hf'⟩ rcases hg.2 with ⟨g', hg'⟩ have G : HasMFDerivWithinAt I' I'' g u (f x) g' := ⟨hg.1, hg'⟩ exact (HasMFDerivWithinAt.comp x G F h).mdifferentiableWithinAt theorem MDifferentiableWithinAt.comp_of_eq {y : M'} (hg : MDifferentiableWithinAt I' I'' g u y) (hf : MDifferentiableWithinAt I I' f s x) (h : s ⊆ f ⁻¹' u) (hy : f x = y) : MDifferentiableWithinAt I I'' (g ∘ f) s x := by subst hy; exact hg.comp _ hf h theorem MDifferentiableWithinAt.comp_of_preimage_mem_nhdsWithin (hg : MDifferentiableWithinAt I' I'' g u (f x)) (hf : MDifferentiableWithinAt I I' f s x) (h : f ⁻¹' u ∈ 𝓝[s] x) : MDifferentiableWithinAt I I'' (g ∘ f) s x := (hg.comp _ (hf.mono inter_subset_right) inter_subset_left).mono_of_mem_nhdsWithin (Filter.inter_mem h self_mem_nhdsWithin) theorem MDifferentiableWithinAt.comp_of_preimage_mem_nhdsWithin_of_eq {y : M'} (hg : MDifferentiableWithinAt I' I'' g u y) (hf : MDifferentiableWithinAt I I' f s x) (h : f ⁻¹' u ∈ 𝓝[s] x) (hy : f x = y) : MDifferentiableWithinAt I I'' (g ∘ f) s x := by subst hy; exact MDifferentiableWithinAt.comp_of_preimage_mem_nhdsWithin _ hg hf h theorem MDifferentiableAt.comp (hg : MDifferentiableAt I' I'' g (f x)) (hf : MDifferentiableAt I I' f x) : MDifferentiableAt I I'' (g ∘ f) x := (hg.hasMFDerivAt.comp x hf.hasMFDerivAt).mdifferentiableAt theorem MDifferentiableAt.comp_of_eq {y : M'} (hg : MDifferentiableAt I' I'' g y) (hf : MDifferentiableAt I I' f x) (hy : f x = y) : MDifferentiableAt I I'' (g ∘ f) x := by subst hy; exact hg.comp _ hf theorem MDifferentiableAt.comp_mdifferentiableWithinAt (hg : MDifferentiableAt I' I'' g (f x)) (hf : MDifferentiableWithinAt I I' f s x) : MDifferentiableWithinAt I I'' (g ∘ f) s x := by rw [← mdifferentiableWithinAt_univ] at hg exact hg.comp _ hf (by simp) theorem MDifferentiableAt.comp_mdifferentiableWithinAt_of_eq {y : M'} (hg : MDifferentiableAt I' I'' g y) (hf : MDifferentiableWithinAt I I' f s x) (hy : f x = y) : MDifferentiableWithinAt I I'' (g ∘ f) s x := by subst hy; exact hg.comp_mdifferentiableWithinAt _ hf theorem mfderivWithin_comp (hg : MDifferentiableWithinAt I' I'' g u (f x)) (hf : MDifferentiableWithinAt I I' f s x) (h : s ⊆ f ⁻¹' u) (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I'' (g ∘ f) s x = (mfderivWithin I' I'' g u (f x)).comp (mfderivWithin I I' f s x) := by apply HasMFDerivWithinAt.mfderivWithin _ hxs exact HasMFDerivWithinAt.comp x hg.hasMFDerivWithinAt hf.hasMFDerivWithinAt h theorem mfderivWithin_comp_of_eq {x : M} {y : M'} (hg : MDifferentiableWithinAt I' I'' g u y) (hf : MDifferentiableWithinAt I I' f s x) (h : s ⊆ f ⁻¹' u) (hxs : UniqueMDiffWithinAt I s x) (hy : f x = y) : mfderivWithin I I'' (g ∘ f) s x = (mfderivWithin I' I'' g u y).comp (mfderivWithin I I' f s x) := by subst hy; exact mfderivWithin_comp x hg hf h hxs theorem mfderivWithin_comp_of_preimage_mem_nhdsWithin (hg : MDifferentiableWithinAt I' I'' g u (f x)) (hf : MDifferentiableWithinAt I I' f s x) (h : f ⁻¹' u ∈ 𝓝[s] x) (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I'' (g ∘ f) s x = (mfderivWithin I' I'' g u (f x)).comp (mfderivWithin I I' f s x) := by have A : s ∩ f ⁻¹' u ∈ 𝓝[s] x := Filter.inter_mem self_mem_nhdsWithin h have B : mfderivWithin I I'' (g ∘ f) s x = mfderivWithin I I'' (g ∘ f) (s ∩ f ⁻¹' u) x := by apply MDifferentiableWithinAt.mfderivWithin_mono_of_mem_nhdsWithin _ hxs A exact hg.comp _ (hf.mono inter_subset_left) inter_subset_right have C : mfderivWithin I I' f s x = mfderivWithin I I' f (s ∩ f ⁻¹' u) x := MDifferentiableWithinAt.mfderivWithin_mono_of_mem_nhdsWithin (hf.mono inter_subset_left) hxs A rw [B, C] exact mfderivWithin_comp _ hg (hf.mono inter_subset_left) inter_subset_right (hxs.inter' h) theorem mfderivWithin_comp_of_preimage_mem_nhdsWithin_of_eq {y : M'} (hg : MDifferentiableWithinAt I' I'' g u y) (hf : MDifferentiableWithinAt I I' f s x) (h : f ⁻¹' u ∈ 𝓝[s] x) (hxs : UniqueMDiffWithinAt I s x) (hy : f x = y) : mfderivWithin I I'' (g ∘ f) s x = (mfderivWithin I' I'' g u y).comp (mfderivWithin I I' f s x) := by subst hy; exact mfderivWithin_comp_of_preimage_mem_nhdsWithin _ hg hf h hxs theorem mfderiv_comp_mfderivWithin (hg : MDifferentiableAt I' I'' g (f x)) (hf : MDifferentiableWithinAt I I' f s x) (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I'' (g ∘ f) s x = (mfderiv I' I'' g (f x)).comp (mfderivWithin I I' f s x) := by rw [← mfderivWithin_univ] exact mfderivWithin_comp _ hg.mdifferentiableWithinAt hf (by simp) hxs theorem mfderiv_comp_mfderivWithin_of_eq {x : M} {y : M'} (hg : MDifferentiableAt I' I'' g y) (hf : MDifferentiableWithinAt I I' f s x) (hxs : UniqueMDiffWithinAt I s x) (hy : f x = y) : mfderivWithin I I'' (g ∘ f) s x = (mfderiv I' I'' g y).comp (mfderivWithin I I' f s x) := by subst hy; exact mfderiv_comp_mfderivWithin x hg hf hxs theorem mfderiv_comp (hg : MDifferentiableAt I' I'' g (f x)) (hf : MDifferentiableAt I I' f x) : mfderiv I I'' (g ∘ f) x = (mfderiv I' I'' g (f x)).comp (mfderiv I I' f x) := by apply HasMFDerivAt.mfderiv exact HasMFDerivAt.comp x hg.hasMFDerivAt hf.hasMFDerivAt theorem mfderiv_comp_of_eq {x : M} {y : M'} (hg : MDifferentiableAt I' I'' g y) (hf : MDifferentiableAt I I' f x) (hy : f x = y) : mfderiv I I'' (g ∘ f) x = (mfderiv I' I'' g (f x)).comp (mfderiv I I' f x) := by subst hy; exact mfderiv_comp x hg hf theorem mfderiv_comp_apply (hg : MDifferentiableAt I' I'' g (f x)) (hf : MDifferentiableAt I I' f x) (v : TangentSpace I x) : mfderiv I I'' (g ∘ f) x v = (mfderiv I' I'' g (f x)) ((mfderiv I I' f x) v) := by rw [mfderiv_comp _ hg hf] rfl theorem mfderiv_comp_apply_of_eq {y : M'} (hg : MDifferentiableAt I' I'' g y) (hf : MDifferentiableAt I I' f x) (hy : f x = y) (v : TangentSpace I x) : mfderiv I I'' (g ∘ f) x v = (mfderiv I' I'' g y) ((mfderiv I I' f x) v) := by subst hy; exact mfderiv_comp_apply _ hg hf v theorem MDifferentiableOn.comp (hg : MDifferentiableOn I' I'' g u) (hf : MDifferentiableOn I I' f s) (st : s ⊆ f ⁻¹' u) : MDifferentiableOn I I'' (g ∘ f) s := fun x hx => MDifferentiableWithinAt.comp x (hg (f x) (st hx)) (hf x hx) st theorem MDifferentiable.comp_mdifferentiableOn (hg : MDifferentiable I' I'' g) (hf : MDifferentiableOn I I' f s) : MDifferentiableOn I I'' (g ∘ f) s := by rw [← mdifferentiableOn_univ] at hg exact hg.comp hf (by simp) theorem MDifferentiable.comp (hg : MDifferentiable I' I'' g) (hf : MDifferentiable I I' f) : MDifferentiable I I'' (g ∘ f) := fun x => MDifferentiableAt.comp x (hg (f x)) (hf x) theorem tangentMapWithin_comp_at (p : TangentBundle I M) (hg : MDifferentiableWithinAt I' I'' g u (f p.1)) (hf : MDifferentiableWithinAt I I' f s p.1) (h : s ⊆ f ⁻¹' u) (hps : UniqueMDiffWithinAt I s p.1) : tangentMapWithin I I'' (g ∘ f) s p = tangentMapWithin I' I'' g u (tangentMapWithin I I' f s p) := by simp only [tangentMapWithin, mfld_simps] rw [mfderivWithin_comp p.1 hg hf h hps] rfl theorem tangentMap_comp_at (p : TangentBundle I M) (hg : MDifferentiableAt I' I'' g (f p.1)) (hf : MDifferentiableAt I I' f p.1) : tangentMap I I'' (g ∘ f) p = tangentMap I' I'' g (tangentMap I I' f p) := by simp only [tangentMap, mfld_simps] rw [mfderiv_comp p.1 hg hf] rfl theorem tangentMap_comp (hg : MDifferentiable I' I'' g) (hf : MDifferentiable I I' f) : tangentMap I I'' (g ∘ f) = tangentMap I' I'' g ∘ tangentMap I I' f := by ext p : 1; exact tangentMap_comp_at _ (hg _) (hf _) end DerivativesProperties
.lake/packages/mathlib/Mathlib/Geometry/Manifold/MFDeriv/Tangent.lean
import Mathlib.Geometry.Manifold.MFDeriv.Atlas import Mathlib.Geometry.Manifold.MFDeriv.UniqueDifferential import Mathlib.Geometry.Manifold.VectorBundle.Tangent import Mathlib.Geometry.Manifold.Diffeomorph /-! # Derivatives of maps in the tangent bundle This file contains properties of derivatives which need the manifold structure of the tangent bundle. Notably, it includes formulas for the tangent maps to charts, and unique differentiability statements for subsets of the tangent bundle. -/ open Bundle Set open scoped Manifold variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I 1 M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] [IsManifold I' 1 M'] /-- The derivative of the chart at a base point is the chart of the tangent bundle, composed with the identification between the tangent bundle of the model space and the product space. -/ theorem tangentMap_chart {p q : TangentBundle I M} (h : q.1 ∈ (chartAt H p.1).source) : tangentMap I I (chartAt H p.1) q = (TotalSpace.toProd _ _).symm ((chartAt (ModelProd H E) p : TangentBundle I M → ModelProd H E) q) := by dsimp [tangentMap] rw [MDifferentiableAt.mfderiv] · rfl · exact mdifferentiableAt_atlas (chart_mem_atlas _ _) h /-- The derivative of the inverse of the chart at a base point is the inverse of the chart of the tangent bundle, composed with the identification between the tangent bundle of the model space and the product space. -/ theorem tangentMap_chart_symm {p : TangentBundle I M} {q : TangentBundle I H} (h : q.1 ∈ (chartAt H p.1).target) : tangentMap I I (chartAt H p.1).symm q = (chartAt (ModelProd H E) p).symm (TotalSpace.toProd H E q) := by dsimp only [tangentMap] rw [MDifferentiableAt.mfderiv (mdifferentiableAt_atlas_symm (chart_mem_atlas _ _) h)] simp only [TangentBundle.chartAt, tangentBundleCore, mfld_simps, (· ∘ ·)] -- `simp` fails to apply `PartialEquiv.prod_symm` with `ModelProd` congr exact ((chartAt H (TotalSpace.proj p)).right_inv h).symm lemma mfderiv_chartAt_eq_tangentCoordChange {x y : M} (hsrc : x ∈ (chartAt H y).source) : mfderiv I I (chartAt H y) x = tangentCoordChange I x y x := by have := mdifferentiableAt_atlas (I := I) (ChartedSpace.chart_mem_atlas _) hsrc simp [mfderiv, if_pos this, Function.comp_assoc] /-- The preimage under the projection from the tangent bundle of a set with unique differential in the basis also has unique differential. -/ theorem UniqueMDiffOn.tangentBundle_proj_preimage {s : Set M} (hs : UniqueMDiffOn I s) : UniqueMDiffOn I.tangent (π E (TangentSpace I) ⁻¹' s) := hs.bundle_preimage _ /-- To write a linear map between tangent spaces in coordinates amounts to precomposing and postcomposing it with derivatives of extended charts. Concrete version of `inTangentCoordinates_eq`. -/ lemma inTangentCoordinates_eq_mfderiv_comp {N : Type*} {f : N → M} {g : N → M'} {ϕ : Π x : N, TangentSpace I (f x) →L[𝕜] TangentSpace I' (g x)} {x₀ : N} {x : N} (hx : f x ∈ (chartAt H (f x₀)).source) (hy : g x ∈ (chartAt H' (g x₀)).source) : inTangentCoordinates I I' f g ϕ x₀ x = (mfderiv I' 𝓘(𝕜, E') (extChartAt I' (g x₀)) (g x)) ∘L (ϕ x) ∘L (mfderivWithin 𝓘(𝕜, E) I (extChartAt I (f x₀)).symm (range I) (extChartAt I (f x₀) (f x))) := by rw [inTangentCoordinates_eq _ _ _ hx hy, tangentBundleCore_coordChange] congr · have : MDifferentiableAt I' 𝓘(𝕜, E') (extChartAt I' (g x₀)) (g x) := mdifferentiableAt_extChartAt hy simp_all [mfderiv] · simp only [mfderivWithin, writtenInExtChartAt, modelWithCornersSelf_coe, range_id, inter_univ] rw [if_pos] · simp [Function.comp_def, OpenPartialHomeomorph.left_inv (chartAt H (f x₀)) hx] · apply mdifferentiableWithinAt_extChartAt_symm apply (extChartAt I (f x₀)).map_source simpa using hx open Bundle variable (I) in /-- The canonical identification between the tangent bundle to the model space and the product, as a diffeomorphism -/ def tangentBundleModelSpaceDiffeomorph (n : ℕ∞) : TangentBundle I H ≃ₘ^n⟮I.tangent, I.prod 𝓘(𝕜, E)⟯ ModelProd H E where __ := TotalSpace.toProd H E contMDiff_toFun := contMDiff_tangentBundleModelSpaceHomeomorph contMDiff_invFun := contMDiff_tangentBundleModelSpaceHomeomorph_symm
.lake/packages/mathlib/Mathlib/Geometry/Manifold/MFDeriv/Defs.lean
import Mathlib.Geometry.Manifold.IsManifold.ExtChartAt import Mathlib.Geometry.Manifold.LocalInvariantProperties /-! # The derivative of functions between manifolds Let `M` and `M'` be two manifolds over a field `𝕜` (with respective models with corners `I` on `(E, H)` and `I'` on `(E', H')`), and let `f : M → M'`. We define the derivative of the function at a point, within a set or along the whole space, mimicking the API for (Fréchet) derivatives. It is denoted by `mfderiv I I' f x`, where "m" stands for "manifold" and "f" for "Fréchet" (as in the usual derivative `fderiv 𝕜 f x`). ## Main definitions * `UniqueMDiffOn I s` : predicate saying that, at each point of the set `s`, a function can have at most one derivative. This technical condition is important when we define `mfderivWithin` below, as otherwise there is an arbitrary choice in the derivative, and many properties will fail (for instance the chain rule). This is analogous to `UniqueDiffOn 𝕜 s` in a vector space. Let `f` be a map between manifolds. The following definitions follow the `fderiv` API. * `mfderiv I I' f x` : the derivative of `f` at `x`, as a continuous linear map from the tangent space at `x` to the tangent space at `f x`. If the map is not differentiable, this is `0`. * `mfderivWithin I I' f s x` : the derivative of `f` at `x` within `s`, as a continuous linear map from the tangent space at `x` to the tangent space at `f x`. If the map is not differentiable within `s`, this is `0`. * `MDifferentiableAt I I' f x` : Prop expressing whether `f` is differentiable at `x`. * `MDifferentiableWithinAt 𝕜 f s x` : Prop expressing whether `f` is differentiable within `s` at `x`. * `HasMFDerivAt I I' f s x f'` : Prop expressing whether `f` has `f'` as a derivative at `x`. * `HasMFDerivWithinAt I I' f s x f'` : Prop expressing whether `f` has `f'` as a derivative within `s` at `x`. * `MDifferentiableOn I I' f s` : Prop expressing that `f` is differentiable on the set `s`. * `MDifferentiable I I' f` : Prop expressing that `f` is differentiable everywhere. * `tangentMap I I' f` : the derivative of `f`, as a map from the tangent bundle of `M` to the tangent bundle of `M'`. Various related results are proven in separate files: see - `Basic.lean` for basic properties of the `mfderiv`, mimicking the API of the Fréchet derivative, - `FDeriv.lean` for the equivalence of the manifold notions with the usual Fréchet derivative for functions between vector spaces, - `SpecificFunctions.lean` for results on the differential of the identity, constant functions, products and arithmetic operators (like addition or scalar multiplication), - `Atlas.lean` for differentiability of charts, models with corners and extended charts, - `UniqueDifferential.lean` for various properties of unique differentiability sets in manifolds. ## Implementation notes The tangent bundle is constructed using the machinery of topological fiber bundles, for which one can define bundled morphisms and construct canonically maps from the total space of one bundle to the total space of another one. One could use this mechanism to construct directly the derivative of a smooth map. However, we want to define the derivative of any map (and let it be zero if the map is not differentiable) to avoid proof arguments everywhere. This means we have to go back to the details of the definition of the total space of a fiber bundle constructed from core, to cook up a suitable definition of the derivative. It is the following: at each point, we have a preferred chart (used to identify the fiber above the point with the model vector space in fiber bundles). Then one should read the function using these preferred charts at `x` and `f x`, and take the derivative of `f` in these charts. Due to the fact that we are working in a model with corners, with an additional embedding `I` of the model space `H` in the model vector space `E`, the charts taking values in `E` are not the original charts of the manifold, but those ones composed with `I`, called extended charts. We define `writtenInExtChartAt I I' x f` for the function `f` written in the preferred extended charts. Then the manifold derivative of `f`, at `x`, is just the usual derivative of `writtenInExtChartAt I I' x f`, at the point `(extChartAt I x) x`. There is a subtlety with respect to continuity: if the function is not continuous, then the image of a small open set around `x` will not be contained in the source of the preferred chart around `f x`, which means that when reading `f` in the chart one is losing some information. To avoid this, we include continuity in the definition of differentiability (which is reasonable since with any definition, differentiability implies continuity). *Warning*: the derivative (even within a subset) is a linear map on the whole tangent space. Suppose that one is given a smooth submanifold `N`, and a function which is smooth on `N` (i.e., its restriction to the subtype `N` is smooth). Then, in the whole manifold `M`, the property `MDifferentiableOn I I' f N` holds. However, `mfderivWithin I I' f N` is not uniquely defined (what values would one choose for vectors that are transverse to `N`?), which can create issues down the road. The problem here is that knowing the value of `f` along `N` does not determine the differential of `f` in all directions. This is in contrast to the case where `N` would be an open subset, or a submanifold with boundary of maximal dimension, where this issue does not appear. The predicate `UniqueMDiffOn I N` indicates that the derivative along `N` is unique if it exists, and is an assumption in most statements requiring a form of uniqueness. On a vector space, the manifold derivative and the usual derivative are equal. This means in particular that they live on the same space, i.e., the tangent space is defeq to the original vector space. To get this property is a motivation for our definition of the tangent space as a single copy of the vector space, instead of more usual definitions such as the space of derivations, or the space of equivalence classes of smooth curves in the manifold. ## Tags derivative, manifold -/ noncomputable section open scoped Topology ContDiff open Set ChartedSpace section DerivativesDefinitions /-! ### Derivative of maps between manifolds The derivative of a map `f` between manifolds `M` and `M'` at `x` is a bounded linear map from the tangent space to `M` at `x`, to the tangent space to `M'` at `f x`. Since we defined the tangent space using one specific chart, the formula for the derivative is written in terms of this specific chart. We use the names `MDifferentiable` and `mfderiv`, where the prefix letter `m` means "manifold". -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] variable (I I') in /-- Property in the model space of a model with corners of being differentiable within at set at a point, when read in the model vector space. This property will be lifted to manifolds to define differentiable functions between manifolds. -/ def DifferentiableWithinAtProp (f : H → H') (s : Set H) (x : H) : Prop := DifferentiableWithinAt 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ Set.range I) (I x) open scoped Manifold theorem differentiableWithinAtProp_self_source {f : E → H'} {s : Set E} {x : E} : DifferentiableWithinAtProp 𝓘(𝕜, E) I' f s x ↔ DifferentiableWithinAt 𝕜 (I' ∘ f) s x := by simp_rw [DifferentiableWithinAtProp, modelWithCornersSelf_coe, range_id, inter_univ, modelWithCornersSelf_coe_symm, CompTriple.comp_eq, preimage_id_eq, id_eq] theorem DifferentiableWithinAtProp_self {f : E → E'} {s : Set E} {x : E} : DifferentiableWithinAtProp 𝓘(𝕜, E) 𝓘(𝕜, E') f s x ↔ DifferentiableWithinAt 𝕜 f s x := differentiableWithinAtProp_self_source theorem differentiableWithinAtProp_self_target {f : H → E'} {s : Set H} {x : H} : DifferentiableWithinAtProp I 𝓘(𝕜, E') f s x ↔ DifferentiableWithinAt 𝕜 (f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) := Iff.rfl /-- Being differentiable in the model space is a local property, invariant under smooth maps. Therefore, it will lift nicely to manifolds. -/ theorem differentiableWithinAt_localInvariantProp : (contDiffGroupoid 1 I).LocalInvariantProp (contDiffGroupoid 1 I') (DifferentiableWithinAtProp I I') := { is_local := by intro s x u f u_open xu have : I.symm ⁻¹' (s ∩ u) ∩ Set.range I = I.symm ⁻¹' s ∩ Set.range I ∩ I.symm ⁻¹' u := by simp only [Set.inter_right_comm, Set.preimage_inter] rw [DifferentiableWithinAtProp, DifferentiableWithinAtProp, this] symm apply differentiableWithinAt_inter have : u ∈ 𝓝 (I.symm (I x)) := by rw [ModelWithCorners.left_inv] exact u_open.mem_nhds xu apply I.continuous_symm.continuousAt this right_invariance' := by intro s x f e he hx h rw [DifferentiableWithinAtProp] at h ⊢ have : I x = (I ∘ e.symm ∘ I.symm) (I (e x)) := by simp only [hx, mfld_simps] rw [this] at h have : I (e x) ∈ I.symm ⁻¹' e.target ∩ Set.range I := by simp only [hx, mfld_simps] have := (mem_groupoid_of_pregroupoid.2 he).2.contDiffWithinAt this convert (h.comp' _ (this.differentiableWithinAt le_rfl)).mono_of_mem_nhdsWithin _ using 1 · ext y; simp only [mfld_simps] refine mem_nhdsWithin.mpr ⟨I.symm ⁻¹' e.target, e.open_target.preimage I.continuous_symm, by simp_rw [Set.mem_preimage, I.left_inv, e.mapsTo hx], ?_⟩ mfld_set_tac congr_of_forall := by intro s x f g h hx hf apply hf.congr · intro y hy simp only [mfld_simps] at hy simp only [h, hy, mfld_simps] · simp only [hx, mfld_simps] left_invariance' := by intro s x f e' he' hs hx h rw [DifferentiableWithinAtProp] at h ⊢ have A : (I' ∘ f ∘ I.symm) (I x) ∈ I'.symm ⁻¹' e'.source ∩ Set.range I' := by simp only [hx, mfld_simps] have := (mem_groupoid_of_pregroupoid.2 he').1.contDiffWithinAt A convert (this.differentiableWithinAt le_rfl).comp _ h _ · ext y; simp only [mfld_simps] · intro y hy; simp only [mfld_simps] at hy; simpa only [hy, mfld_simps] using hs hy.1 } variable (I) in /-- Predicate ensuring that, at a point and within a set, a function can have at most one derivative. This is expressed using the preferred chart at the considered point. -/ def UniqueMDiffWithinAt (s : Set M) (x : M) := UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) variable (I) in /-- Predicate ensuring that, at all points of a set, a function can have at most one derivative. -/ def UniqueMDiffOn (s : Set M) := ∀ x ∈ s, UniqueMDiffWithinAt I s x variable (I I') in /-- `MDifferentiableWithinAt I I' f s x` indicates that the function `f` between manifolds has a derivative at the point `x` within the set `s`. This is a generalization of `DifferentiableWithinAt` to manifolds. We require continuity in the definition, as otherwise points close to `x` in `s` could be sent by `f` outside of the chart domain around `f x`. Then the chart could do anything to the image points, and in particular by coincidence `writtenInExtChartAt I I' x f` could be differentiable, while this would not mean anything relevant. -/ def MDifferentiableWithinAt (f : M → M') (s : Set M) (x : M) := LiftPropWithinAt (DifferentiableWithinAtProp I I') f s x theorem mdifferentiableWithinAt_iff' (f : M → M') (s : Set M) (x : M) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f) ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := by rw [MDifferentiableWithinAt, liftPropWithinAt_iff']; rfl theorem MDifferentiableWithinAt.continuousWithinAt {f : M → M'} {s : Set M} {x : M} (hf : MDifferentiableWithinAt I I' f s x) : ContinuousWithinAt f s x := mdifferentiableWithinAt_iff' .. |>.1 hf |>.1 theorem MDifferentiableWithinAt.differentiableWithinAt_writtenInExtChartAt {f : M → M'} {s : Set M} {x : M} (hf : MDifferentiableWithinAt I I' f s x) : DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f) ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := mdifferentiableWithinAt_iff' .. |>.1 hf |>.2 variable (I I') in /-- `MDifferentiableAt I I' f x` indicates that the function `f` between manifolds has a derivative at the point `x`. This is a generalization of `DifferentiableAt` to manifolds. We require continuity in the definition, as otherwise points close to `x` could be sent by `f` outside of the chart domain around `f x`. Then the chart could do anything to the image points, and in particular by coincidence `writtenInExtChartAt I I' x f` could be differentiable, while this would not mean anything relevant. -/ def MDifferentiableAt (f : M → M') (x : M) := LiftPropAt (DifferentiableWithinAtProp I I') f x theorem mdifferentiableAt_iff (f : M → M') (x : M) : MDifferentiableAt I I' f x ↔ ContinuousAt f x ∧ DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f) (range I) ((extChartAt I x) x) := by rw [MDifferentiableAt, liftPropAt_iff] congrm _ ∧ ?_ simp [DifferentiableWithinAtProp, Set.univ_inter, Function.comp_assoc] theorem MDifferentiableAt.continuousAt {f : M → M'} {x : M} (hf : MDifferentiableAt I I' f x) : ContinuousAt f x := mdifferentiableAt_iff .. |>.1 hf |>.1 theorem MDifferentiableAt.differentiableWithinAt_writtenInExtChartAt {f : M → M'} {x : M} (hf : MDifferentiableAt I I' f x) : DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f) (range I) ((extChartAt I x) x) := mdifferentiableAt_iff .. |>.1 hf |>.2 variable (I I') in /-- `MDifferentiableOn I I' f s` indicates that the function `f` between manifolds has a derivative within `s` at all points of `s`. This is a generalization of `DifferentiableOn` to manifolds. -/ def MDifferentiableOn (f : M → M') (s : Set M) := ∀ x ∈ s, MDifferentiableWithinAt I I' f s x variable (I I') in /-- `MDifferentiable I I' f` indicates that the function `f` between manifolds has a derivative everywhere. This is a generalization of `Differentiable` to manifolds. -/ def MDifferentiable (f : M → M') := ∀ x, MDifferentiableAt I I' f x variable (I I') in /-- Prop registering if an open partial homeomorphism is a local diffeomorphism on its source -/ def OpenPartialHomeomorph.MDifferentiable (f : OpenPartialHomeomorph M M') := MDifferentiableOn I I' f f.source ∧ MDifferentiableOn I' I f.symm f.target variable (I I') in /-- `HasMFDerivWithinAt I I' f s x f'` indicates that the function `f` between manifolds has, at the point `x` and within the set `s`, the derivative `f'`. Here, `f'` is a continuous linear map from the tangent space at `x` to the tangent space at `f x`. This is a generalization of `HasFDerivWithinAt` to manifolds (as indicated by the prefix `m`). The order of arguments is changed as the type of the derivative `f'` depends on the choice of `x`. We require continuity in the definition, as otherwise points close to `x` in `s` could be sent by `f` outside of the chart domain around `f x`. Then the chart could do anything to the image points, and in particular by coincidence `writtenInExtChartAt I I' x f` could be differentiable, while this would not mean anything relevant. -/ def HasMFDerivWithinAt (f : M → M') (s : Set M) (x : M) (f' : TangentSpace I x →L[𝕜] TangentSpace I' (f x)) := ContinuousWithinAt f s x ∧ HasFDerivWithinAt (writtenInExtChartAt I I' x f : E → E') f' ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) variable (I I') in /-- `HasMFDerivAt I I' f x f'` indicates that the function `f` between manifolds has, at the point `x`, the derivative `f'`. Here, `f'` is a continuous linear map from the tangent space at `x` to the tangent space at `f x`. We require continuity in the definition, as otherwise points close to `x` in `s` could be sent by `f` outside of the chart domain around `f x`. Then the chart could do anything to the image points, and in particular by coincidence `writtenInExtChartAt I I' x f` could be differentiable, while this would not mean anything relevant. -/ def HasMFDerivAt (f : M → M') (x : M) (f' : TangentSpace I x →L[𝕜] TangentSpace I' (f x)) := ContinuousAt f x ∧ HasFDerivWithinAt (writtenInExtChartAt I I' x f : E → E') f' (range I) ((extChartAt I x) x) open Classical in variable (I I') in /-- Let `f` be a function between two manifolds. Then `mfderivWithin I I' f s x` is the derivative of `f` at `x` within `s`, as a continuous linear map from the tangent space at `x` to the tangent space at `f x`. -/ def mfderivWithin (f : M → M') (s : Set M) (x : M) : TangentSpace I x →L[𝕜] TangentSpace I' (f x) := if MDifferentiableWithinAt I I' f s x then (fderivWithin 𝕜 (writtenInExtChartAt I I' x f) ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) : _) else 0 open Classical in variable (I I') in /-- Let `f` be a function between two manifolds. Then `mfderiv I I' f x` is the derivative of `f` at `x`, as a continuous linear map from the tangent space at `x` to the tangent space at `f x`. -/ def mfderiv (f : M → M') (x : M) : TangentSpace I x →L[𝕜] TangentSpace I' (f x) := if MDifferentiableAt I I' f x then (fderivWithin 𝕜 (writtenInExtChartAt I I' x f : E → E') (range I) ((extChartAt I x) x) :) else 0 variable (I I') in /-- The derivative within a set, as a map between the tangent bundles -/ def tangentMapWithin (f : M → M') (s : Set M) : TangentBundle I M → TangentBundle I' M' := fun p => ⟨f p.1, (mfderivWithin I I' f s p.1 : TangentSpace I p.1 → TangentSpace I' (f p.1)) p.2⟩ variable (I I') in /-- The derivative, as a map between the tangent bundles -/ def tangentMap (f : M → M') : TangentBundle I M → TangentBundle I' M' := fun p => ⟨f p.1, (mfderiv I I' f p.1 : TangentSpace I p.1 → TangentSpace I' (f p.1)) p.2⟩ end DerivativesDefinitions
.lake/packages/mathlib/Mathlib/Geometry/Manifold/MFDeriv/SpecificFunctions.lean
import Mathlib.Analysis.Calculus.FDeriv.Mul import Mathlib.Geometry.Manifold.MFDeriv.FDeriv /-! # Differentiability of specific functions In this file, we establish differentiability results for - continuous linear maps and continuous linear equivalences - the identity - constant functions - products - arithmetic operations (such as addition and scalar multiplication). -/ noncomputable section open scoped Manifold open Bundle Set Topology section SpecificFunctions /-! ### Differentiability of specific functions -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- declare a charted space `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] -- declare a charted space `M''` over the pair `(E'', H'')`. {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] -- declare a charted space `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] -- declare a charted space `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] -- F₁, F₂, F₃, F₄ are normed spaces {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] {F₃ : Type*} [NormedAddCommGroup F₃] [NormedSpace 𝕜 F₃] {F₄ : Type*} [NormedAddCommGroup F₄] [NormedSpace 𝕜 F₄] namespace ContinuousLinearMap variable (f : E →L[𝕜] E') {s : Set E} {x : E} protected theorem hasMFDerivWithinAt : HasMFDerivWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x f := f.hasFDerivWithinAt.hasMFDerivWithinAt protected theorem hasMFDerivAt : HasMFDerivAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x f := f.hasFDerivAt.hasMFDerivAt protected theorem mdifferentiableWithinAt : MDifferentiableWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x := f.differentiableWithinAt.mdifferentiableWithinAt protected theorem mdifferentiableOn : MDifferentiableOn 𝓘(𝕜, E) 𝓘(𝕜, E') f s := f.differentiableOn.mdifferentiableOn protected theorem mdifferentiableAt : MDifferentiableAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x := f.differentiableAt.mdifferentiableAt protected theorem mdifferentiable : MDifferentiable 𝓘(𝕜, E) 𝓘(𝕜, E') f := f.differentiable.mdifferentiable theorem mfderiv_eq : mfderiv 𝓘(𝕜, E) 𝓘(𝕜, E') f x = f := f.hasMFDerivAt.mfderiv theorem mfderivWithin_eq (hs : UniqueMDiffWithinAt 𝓘(𝕜, E) s x) : mfderivWithin 𝓘(𝕜, E) 𝓘(𝕜, E') f s x = f := f.hasMFDerivWithinAt.mfderivWithin hs end ContinuousLinearMap namespace ContinuousLinearEquiv variable (f : E ≃L[𝕜] E') {s : Set E} {x : E} protected theorem hasMFDerivWithinAt : HasMFDerivWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x (f : E →L[𝕜] E') := f.hasFDerivWithinAt.hasMFDerivWithinAt protected theorem hasMFDerivAt : HasMFDerivAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x (f : E →L[𝕜] E') := f.hasFDerivAt.hasMFDerivAt protected theorem mdifferentiableWithinAt : MDifferentiableWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x := f.differentiableWithinAt.mdifferentiableWithinAt protected theorem mdifferentiableOn : MDifferentiableOn 𝓘(𝕜, E) 𝓘(𝕜, E') f s := f.differentiableOn.mdifferentiableOn protected theorem mdifferentiableAt : MDifferentiableAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x := f.differentiableAt.mdifferentiableAt protected theorem mdifferentiable : MDifferentiable 𝓘(𝕜, E) 𝓘(𝕜, E') f := f.differentiable.mdifferentiable theorem mfderiv_eq : mfderiv 𝓘(𝕜, E) 𝓘(𝕜, E') f x = (f : E →L[𝕜] E') := f.hasMFDerivAt.mfderiv theorem mfderivWithin_eq (hs : UniqueMDiffWithinAt 𝓘(𝕜, E) s x) : mfderivWithin 𝓘(𝕜, E) 𝓘(𝕜, E') f s x = (f : E →L[𝕜] E') := f.hasMFDerivWithinAt.mfderivWithin hs end ContinuousLinearEquiv variable {s : Set M} {x : M} section id /-! #### Identity -/ theorem hasMFDerivAt_id (x : M) : HasMFDerivAt I I (@id M) x (ContinuousLinearMap.id 𝕜 (TangentSpace I x)) := by refine ⟨continuousAt_id, ?_⟩ have : ∀ᶠ y in 𝓝[range I] (extChartAt I x) x, (extChartAt I x ∘ (extChartAt I x).symm) y = y := by apply Filter.mem_of_superset (extChartAt_target_mem_nhdsWithin x) mfld_set_tac apply HasFDerivWithinAt.congr_of_eventuallyEq (hasFDerivWithinAt_id _ _) this simp only [mfld_simps] theorem hasMFDerivWithinAt_id (s : Set M) (x : M) : HasMFDerivWithinAt I I (@id M) s x (ContinuousLinearMap.id 𝕜 (TangentSpace I x)) := (hasMFDerivAt_id x).hasMFDerivWithinAt theorem mdifferentiableAt_id : MDifferentiableAt I I (@id M) x := (hasMFDerivAt_id x).mdifferentiableAt theorem mdifferentiableWithinAt_id : MDifferentiableWithinAt I I (@id M) s x := mdifferentiableAt_id.mdifferentiableWithinAt theorem mdifferentiable_id : MDifferentiable I I (@id M) := fun _ => mdifferentiableAt_id theorem mdifferentiableOn_id : MDifferentiableOn I I (@id M) s := mdifferentiable_id.mdifferentiableOn @[simp, mfld_simps] theorem mfderiv_id : mfderiv I I (@id M) x = ContinuousLinearMap.id 𝕜 (TangentSpace I x) := HasMFDerivAt.mfderiv (hasMFDerivAt_id x) theorem mfderivWithin_id (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I (@id M) s x = ContinuousLinearMap.id 𝕜 (TangentSpace I x) := by rw [MDifferentiable.mfderivWithin mdifferentiableAt_id hxs] exact mfderiv_id @[simp, mfld_simps] theorem tangentMap_id : tangentMap I I (id : M → M) = id := by ext1 ⟨x, v⟩; simp [tangentMap] theorem tangentMapWithin_id {p : TangentBundle I M} (hs : UniqueMDiffWithinAt I s p.proj) : tangentMapWithin I I (id : M → M) s p = p := by simp only [tangentMapWithin, id] rw [mfderivWithin_id] · rcases p with ⟨⟩; rfl · exact hs end id section Const /-! #### Constants -/ variable {c : M'} theorem hasMFDerivAt_const (c : M') (x : M) : HasMFDerivAt I I' (fun _ : M => c) x (0 : TangentSpace I x →L[𝕜] TangentSpace I' c) := by refine ⟨continuous_const.continuousAt, ?_⟩ simp only [writtenInExtChartAt, Function.comp_def, hasFDerivWithinAt_const] theorem hasMFDerivWithinAt_const (c : M') (s : Set M) (x : M) : HasMFDerivWithinAt I I' (fun _ : M => c) s x (0 : TangentSpace I x →L[𝕜] TangentSpace I' c) := (hasMFDerivAt_const c x).hasMFDerivWithinAt theorem mdifferentiableAt_const : MDifferentiableAt I I' (fun _ : M => c) x := (hasMFDerivAt_const c x).mdifferentiableAt theorem mdifferentiableWithinAt_const : MDifferentiableWithinAt I I' (fun _ : M => c) s x := mdifferentiableAt_const.mdifferentiableWithinAt theorem mdifferentiable_const : MDifferentiable I I' fun _ : M => c := fun _ => mdifferentiableAt_const theorem mdifferentiableOn_const : MDifferentiableOn I I' (fun _ : M => c) s := mdifferentiable_const.mdifferentiableOn @[simp, mfld_simps] theorem mfderiv_const : mfderiv I I' (fun _ : M => c) x = (0 : TangentSpace I x →L[𝕜] TangentSpace I' c) := HasMFDerivAt.mfderiv (hasMFDerivAt_const c x) theorem mfderivWithin_const : mfderivWithin I I' (fun _ : M => c) s x = (0 : TangentSpace I x →L[𝕜] TangentSpace I' c) := (hasMFDerivWithinAt_const _ _ _).mfderivWithin_eq_zero end Const section Prod /-! ### Operations on the product of two manifolds -/ theorem MDifferentiableWithinAt.prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiableWithinAt I I' f s x) (hg : MDifferentiableWithinAt I I'' g s x) : MDifferentiableWithinAt I (I'.prod I'') (fun x => (f x, g x)) s x := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ /-- If `f` and `g` have derivatives `df` and `dg` within `s` at `x`, respectively, then `x ↦ (f x, g x)` has derivative `df.prod dg` within `s`. -/ theorem HasMFDerivWithinAt.prodMk {f : M → M'} {g : M → M''} {df : TangentSpace I x →L[𝕜] TangentSpace I' (f x)} (hf : HasMFDerivWithinAt I I' f s x df) {dg : TangentSpace I x →L[𝕜] TangentSpace I'' (g x)} (hg : HasMFDerivWithinAt I I'' g s x dg) : HasMFDerivWithinAt I (I'.prod I'') (fun y ↦ (f y, g y)) s x (df.prod dg) := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ lemma mfderivWithin_prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiableWithinAt I I' f s x) (hg : MDifferentiableWithinAt I I'' g s x) (hs : UniqueMDiffWithinAt I s x) : mfderivWithin I (I'.prod I'') (fun x => (f x, g x)) s x = (mfderivWithin I I' f s x).prod (mfderivWithin I I'' g s x) := (hf.hasMFDerivWithinAt.prodMk hg.hasMFDerivWithinAt).mfderivWithin hs lemma mfderiv_prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiableAt I I' f x) (hg : MDifferentiableAt I I'' g x) : mfderiv I (I'.prod I'') (fun x => (f x, g x)) x = (mfderiv I I' f x).prod (mfderiv I I'' g x) := by simp_rw [← mfderivWithin_univ] exact mfderivWithin_prodMk hf.mdifferentiableWithinAt hg.mdifferentiableWithinAt (uniqueMDiffWithinAt_univ I) theorem MDifferentiableAt.prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiableAt I I' f x) (hg : MDifferentiableAt I I'' g x) : MDifferentiableAt I (I'.prod I'') (fun x => (f x, g x)) x := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ /-- If `f` and `g` have derivatives `df` and `dg` at `x`, respectively, then `x ↦ (f x, g x)` has derivative `df.prod dg`. -/ theorem HasMFDerivAt.prodMk {f : M → M'} {g : M → M''} {df : TangentSpace I x →L[𝕜] TangentSpace I' (f x)} (hf : HasMFDerivAt I I' f x df) {dg : TangentSpace I x →L[𝕜] TangentSpace I'' (g x)} (hg : HasMFDerivAt I I'' g x dg) : HasMFDerivAt I (I'.prod I'') (fun y ↦ (f y, g y)) x (df.prod dg) := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ theorem MDifferentiableWithinAt.prodMk_space {f : M → E'} {g : M → E''} (hf : MDifferentiableWithinAt I 𝓘(𝕜, E') f s x) (hg : MDifferentiableWithinAt I 𝓘(𝕜, E'') g s x) : MDifferentiableWithinAt I 𝓘(𝕜, E' × E'') (fun x => (f x, g x)) s x := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ theorem MDifferentiableAt.prodMk_space {f : M → E'} {g : M → E''} (hf : MDifferentiableAt I 𝓘(𝕜, E') f x) (hg : MDifferentiableAt I 𝓘(𝕜, E'') g x) : MDifferentiableAt I 𝓘(𝕜, E' × E'') (fun x => (f x, g x)) x := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ theorem MDifferentiableOn.prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiableOn I I' f s) (hg : MDifferentiableOn I I'' g s) : MDifferentiableOn I (I'.prod I'') (fun x => (f x, g x)) s := fun x hx => (hf x hx).prodMk (hg x hx) theorem MDifferentiable.prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiable I I' f) (hg : MDifferentiable I I'' g) : MDifferentiable I (I'.prod I'') fun x => (f x, g x) := fun x => (hf x).prodMk (hg x) theorem MDifferentiableOn.prodMk_space {f : M → E'} {g : M → E''} (hf : MDifferentiableOn I 𝓘(𝕜, E') f s) (hg : MDifferentiableOn I 𝓘(𝕜, E'') g s) : MDifferentiableOn I 𝓘(𝕜, E' × E'') (fun x => (f x, g x)) s := fun x hx => (hf x hx).prodMk_space (hg x hx) theorem MDifferentiable.prodMk_space {f : M → E'} {g : M → E''} (hf : MDifferentiable I 𝓘(𝕜, E') f) (hg : MDifferentiable I 𝓘(𝕜, E'') g) : MDifferentiable I 𝓘(𝕜, E' × E'') fun x => (f x, g x) := fun x => (hf x).prodMk_space (hg x) theorem hasMFDerivAt_fst (x : M × M') : HasMFDerivAt (I.prod I') I Prod.fst x (ContinuousLinearMap.fst 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2)) := by refine ⟨continuous_fst.continuousAt, ?_⟩ have : ∀ᶠ y in 𝓝[range (I.prod I')] extChartAt (I.prod I') x x, (extChartAt I x.1 ∘ Prod.fst ∘ (extChartAt (I.prod I') x).symm) y = y.1 := by /- porting note: was apply Filter.mem_of_superset (extChartAt_target_mem_nhdsWithin (I.prod I') x) mfld_set_tac -/ filter_upwards [extChartAt_target_mem_nhdsWithin x] with y hy rw [extChartAt_prod] at hy exact (extChartAt I x.1).right_inv hy.1 apply HasFDerivWithinAt.congr_of_eventuallyEq hasFDerivWithinAt_fst this -- Porting note: next line was `simp only [mfld_simps]` exact (extChartAt I x.1).right_inv <| (extChartAt I x.1).map_source (mem_extChartAt_source _) theorem hasMFDerivWithinAt_fst (s : Set (M × M')) (x : M × M') : HasMFDerivWithinAt (I.prod I') I Prod.fst s x (ContinuousLinearMap.fst 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2)) := (hasMFDerivAt_fst x).hasMFDerivWithinAt theorem mdifferentiableAt_fst {x : M × M'} : MDifferentiableAt (I.prod I') I Prod.fst x := (hasMFDerivAt_fst x).mdifferentiableAt theorem mdifferentiableWithinAt_fst {s : Set (M × M')} {x : M × M'} : MDifferentiableWithinAt (I.prod I') I Prod.fst s x := mdifferentiableAt_fst.mdifferentiableWithinAt theorem mdifferentiable_fst : MDifferentiable (I.prod I') I (Prod.fst : M × M' → M) := fun _ => mdifferentiableAt_fst theorem mdifferentiableOn_fst {s : Set (M × M')} : MDifferentiableOn (I.prod I') I Prod.fst s := mdifferentiable_fst.mdifferentiableOn @[simp, mfld_simps] theorem mfderiv_fst {x : M × M'} : mfderiv (I.prod I') I Prod.fst x = ContinuousLinearMap.fst 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2) := (hasMFDerivAt_fst x).mfderiv theorem mfderivWithin_fst {s : Set (M × M')} {x : M × M'} (hxs : UniqueMDiffWithinAt (I.prod I') s x) : mfderivWithin (I.prod I') I Prod.fst s x = ContinuousLinearMap.fst 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2) := by rw [MDifferentiable.mfderivWithin mdifferentiableAt_fst hxs]; exact mfderiv_fst @[simp, mfld_simps] theorem tangentMap_prodFst {p : TangentBundle (I.prod I') (M × M')} : tangentMap (I.prod I') I Prod.fst p = ⟨p.proj.1, p.2.1⟩ := by simp [tangentMap]; rfl theorem tangentMapWithin_prodFst {s : Set (M × M')} {p : TangentBundle (I.prod I') (M × M')} (hs : UniqueMDiffWithinAt (I.prod I') s p.proj) : tangentMapWithin (I.prod I') I Prod.fst s p = ⟨p.proj.1, p.2.1⟩ := by simp only [tangentMapWithin] rw [mfderivWithin_fst] · rcases p with ⟨⟩; rfl · exact hs theorem hasMFDerivAt_snd (x : M × M') : HasMFDerivAt (I.prod I') I' Prod.snd x (ContinuousLinearMap.snd 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2)) := by refine ⟨continuous_snd.continuousAt, ?_⟩ have : ∀ᶠ y in 𝓝[range (I.prod I')] extChartAt (I.prod I') x x, (extChartAt I' x.2 ∘ Prod.snd ∘ (extChartAt (I.prod I') x).symm) y = y.2 := by /- porting note: was apply Filter.mem_of_superset (extChartAt_target_mem_nhdsWithin (I.prod I') x) mfld_set_tac -/ filter_upwards [extChartAt_target_mem_nhdsWithin x] with y hy rw [extChartAt_prod] at hy exact (extChartAt I' x.2).right_inv hy.2 apply HasFDerivWithinAt.congr_of_eventuallyEq hasFDerivWithinAt_snd this -- Porting note: the next line was `simp only [mfld_simps]` exact (extChartAt I' x.2).right_inv <| (extChartAt I' x.2).map_source (mem_extChartAt_source _) theorem hasMFDerivWithinAt_snd (s : Set (M × M')) (x : M × M') : HasMFDerivWithinAt (I.prod I') I' Prod.snd s x (ContinuousLinearMap.snd 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2)) := (hasMFDerivAt_snd x).hasMFDerivWithinAt theorem mdifferentiableAt_snd {x : M × M'} : MDifferentiableAt (I.prod I') I' Prod.snd x := (hasMFDerivAt_snd x).mdifferentiableAt theorem mdifferentiableWithinAt_snd {s : Set (M × M')} {x : M × M'} : MDifferentiableWithinAt (I.prod I') I' Prod.snd s x := mdifferentiableAt_snd.mdifferentiableWithinAt theorem mdifferentiable_snd : MDifferentiable (I.prod I') I' (Prod.snd : M × M' → M') := fun _ => mdifferentiableAt_snd theorem mdifferentiableOn_snd {s : Set (M × M')} : MDifferentiableOn (I.prod I') I' Prod.snd s := mdifferentiable_snd.mdifferentiableOn @[simp, mfld_simps] theorem mfderiv_snd {x : M × M'} : mfderiv (I.prod I') I' Prod.snd x = ContinuousLinearMap.snd 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2) := (hasMFDerivAt_snd x).mfderiv theorem mfderivWithin_snd {s : Set (M × M')} {x : M × M'} (hxs : UniqueMDiffWithinAt (I.prod I') s x) : mfderivWithin (I.prod I') I' Prod.snd s x = ContinuousLinearMap.snd 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2) := by rw [MDifferentiable.mfderivWithin mdifferentiableAt_snd hxs]; exact mfderiv_snd theorem MDifferentiableWithinAt.fst {f : N → M × M'} {s : Set N} {x : N} (hf : MDifferentiableWithinAt J (I.prod I') f s x) : MDifferentiableWithinAt J I (fun x => (f x).1) s x := mdifferentiableAt_fst.comp_mdifferentiableWithinAt x hf theorem MDifferentiableAt.fst {f : N → M × M'} {x : N} (hf : MDifferentiableAt J (I.prod I') f x) : MDifferentiableAt J I (fun x => (f x).1) x := mdifferentiableAt_fst.comp x hf theorem MDifferentiable.fst {f : N → M × M'} (hf : MDifferentiable J (I.prod I') f) : MDifferentiable J I fun x => (f x).1 := mdifferentiable_fst.comp hf theorem MDifferentiableWithinAt.snd {f : N → M × M'} {s : Set N} {x : N} (hf : MDifferentiableWithinAt J (I.prod I') f s x) : MDifferentiableWithinAt J I' (fun x => (f x).2) s x := mdifferentiableAt_snd.comp_mdifferentiableWithinAt x hf theorem MDifferentiableAt.snd {f : N → M × M'} {x : N} (hf : MDifferentiableAt J (I.prod I') f x) : MDifferentiableAt J I' (fun x => (f x).2) x := mdifferentiableAt_snd.comp x hf theorem MDifferentiable.snd {f : N → M × M'} (hf : MDifferentiable J (I.prod I') f) : MDifferentiable J I' fun x => (f x).2 := mdifferentiable_snd.comp hf theorem mdifferentiableWithinAt_prod_iff (f : M → M' × N') : MDifferentiableWithinAt I (I'.prod J') f s x ↔ MDifferentiableWithinAt I I' (Prod.fst ∘ f) s x ∧ MDifferentiableWithinAt I J' (Prod.snd ∘ f) s x := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prodMk h.2⟩ theorem mdifferentiableWithinAt_prod_module_iff (f : M → F₁ × F₂) : MDifferentiableWithinAt I 𝓘(𝕜, F₁ × F₂) f s x ↔ MDifferentiableWithinAt I 𝓘(𝕜, F₁) (Prod.fst ∘ f) s x ∧ MDifferentiableWithinAt I 𝓘(𝕜, F₂) (Prod.snd ∘ f) s x := by rw [modelWithCornersSelf_prod, ← chartedSpaceSelf_prod] exact mdifferentiableWithinAt_prod_iff f theorem mdifferentiableAt_prod_iff (f : M → M' × N') : MDifferentiableAt I (I'.prod J') f x ↔ MDifferentiableAt I I' (Prod.fst ∘ f) x ∧ MDifferentiableAt I J' (Prod.snd ∘ f) x := by simp_rw [← mdifferentiableWithinAt_univ]; exact mdifferentiableWithinAt_prod_iff f theorem mdifferentiableAt_prod_module_iff (f : M → F₁ × F₂) : MDifferentiableAt I 𝓘(𝕜, F₁ × F₂) f x ↔ MDifferentiableAt I 𝓘(𝕜, F₁) (Prod.fst ∘ f) x ∧ MDifferentiableAt I 𝓘(𝕜, F₂) (Prod.snd ∘ f) x := by rw [modelWithCornersSelf_prod, ← chartedSpaceSelf_prod] exact mdifferentiableAt_prod_iff f theorem mdifferentiableOn_prod_iff (f : M → M' × N') : MDifferentiableOn I (I'.prod J') f s ↔ MDifferentiableOn I I' (Prod.fst ∘ f) s ∧ MDifferentiableOn I J' (Prod.snd ∘ f) s := ⟨fun h ↦ ⟨fun x hx ↦ ((mdifferentiableWithinAt_prod_iff f).1 (h x hx)).1, fun x hx ↦ ((mdifferentiableWithinAt_prod_iff f).1 (h x hx)).2⟩, fun h x hx ↦ (mdifferentiableWithinAt_prod_iff f).2 ⟨h.1 x hx, h.2 x hx⟩⟩ theorem mdifferentiableOn_prod_module_iff (f : M → F₁ × F₂) : MDifferentiableOn I 𝓘(𝕜, F₁ × F₂) f s ↔ MDifferentiableOn I 𝓘(𝕜, F₁) (Prod.fst ∘ f) s ∧ MDifferentiableOn I 𝓘(𝕜, F₂) (Prod.snd ∘ f) s := by rw [modelWithCornersSelf_prod, ← chartedSpaceSelf_prod] exact mdifferentiableOn_prod_iff f theorem mdifferentiable_prod_iff (f : M → M' × N') : MDifferentiable I (I'.prod J') f ↔ MDifferentiable I I' (Prod.fst ∘ f) ∧ MDifferentiable I J' (Prod.snd ∘ f) := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => by convert h.1.prodMk h.2⟩ theorem mdifferentiable_prod_module_iff (f : M → F₁ × F₂) : MDifferentiable I 𝓘(𝕜, F₁ × F₂) f ↔ MDifferentiable I 𝓘(𝕜, F₁) (Prod.fst ∘ f) ∧ MDifferentiable I 𝓘(𝕜, F₂) (Prod.snd ∘ f) := by rw [modelWithCornersSelf_prod, ← chartedSpaceSelf_prod] exact mdifferentiable_prod_iff f section prodMap variable {f : M → M'} {g : N → N'} {r : Set N} {y : N} /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem MDifferentiableWithinAt.prodMap' {p : M × N} (hf : MDifferentiableWithinAt I I' f s p.1) (hg : MDifferentiableWithinAt J J' g r p.2) : MDifferentiableWithinAt (I.prod J) (I'.prod J') (Prod.map f g) (s ×ˢ r) p := (hf.comp p mdifferentiableWithinAt_fst (prod_subset_preimage_fst _ _)).prodMk <| hg.comp p mdifferentiableWithinAt_snd (prod_subset_preimage_snd _ _) theorem MDifferentiableWithinAt.prodMap (hf : MDifferentiableWithinAt I I' f s x) (hg : MDifferentiableWithinAt J J' g r y) : MDifferentiableWithinAt (I.prod J) (I'.prod J') (Prod.map f g) (s ×ˢ r) (x, y) := MDifferentiableWithinAt.prodMap' hf hg theorem MDifferentiableAt.prodMap (hf : MDifferentiableAt I I' f x) (hg : MDifferentiableAt J J' g y) : MDifferentiableAt (I.prod J) (I'.prod J') (Prod.map f g) (x, y) := by rw [← mdifferentiableWithinAt_univ] at * convert hf.prodMap hg exact univ_prod_univ.symm /-- Variant of `MDifferentiableAt.prod_map` in which the point in the product is given as `p` instead of a pair `(x, y)`. -/ theorem MDifferentiableAt.prodMap' {p : M × N} (hf : MDifferentiableAt I I' f p.1) (hg : MDifferentiableAt J J' g p.2) : MDifferentiableAt (I.prod J) (I'.prod J') (Prod.map f g) p := hf.prodMap hg theorem MDifferentiableOn.prodMap (hf : MDifferentiableOn I I' f s) (hg : MDifferentiableOn J J' g r) : MDifferentiableOn (I.prod J) (I'.prod J') (Prod.map f g) (s ×ˢ r) := (hf.comp mdifferentiableOn_fst (prod_subset_preimage_fst _ _)).prodMk <| hg.comp mdifferentiableOn_snd (prod_subset_preimage_snd _ _) theorem MDifferentiable.prodMap (hf : MDifferentiable I I' f) (hg : MDifferentiable J J' g) : MDifferentiable (I.prod J) (I'.prod J') (Prod.map f g) := fun p ↦ (hf p.1).prodMap' (hg p.2) lemma HasMFDerivWithinAt.prodMap {s : Set <| M × M'} {p : M × M'} {f : M → N} {g : M' → N'} {df : TangentSpace I p.1 →L[𝕜] TangentSpace J (f p.1)} (hf : HasMFDerivWithinAt I J f (Prod.fst '' s) p.1 df) {dg : TangentSpace I' p.2 →L[𝕜] TangentSpace J' (g p.2)} (hg : HasMFDerivWithinAt I' J' g (Prod.snd '' s) p.2 dg) : HasMFDerivWithinAt (I.prod I') (J.prod J') (Prod.map f g) s p (df.prodMap dg) := by refine ⟨hf.1.prodMap hg.1 |>.mono (by grind), ?_⟩ have better : ((extChartAt (I.prod I') p).symm ⁻¹' s ∩ range ↑(I.prod I')) ⊆ ((extChartAt I p.1).symm ⁻¹' (Prod.fst '' s) ∩ range I) ×ˢ ((extChartAt I' p.2).symm ⁻¹' (Prod.snd '' s) ∩ range I') := by simp only [mfld_simps] rw [range_prodMap, I.toPartialEquiv.prod_symm, (chartAt H p.1).toPartialEquiv.prod_symm] -- This is very tedious; a nicer proof is welcome! intro p₀ ⟨hp₀, ⟨hp₁₁, hp₁₂⟩⟩ refine ⟨⟨?_, by assumption⟩, ⟨?_, by assumption⟩⟩ · simp_all use (chartAt H' p.2).symm <| I'.symm p₀.2 · simp_all use (chartAt H p.1).symm <| I.symm p₀.1 rw [writtenInExtChart_prod] apply HasFDerivWithinAt.mono ?_ better apply HasFDerivWithinAt.prodMap exacts [hf.2.mono (fst_image_prod_subset ..), hg.2.mono (snd_image_prod_subset ..)] lemma HasMFDerivAt.prodMap {p : M × M'} {f : M → N} {g : M' → N'} {df : TangentSpace I p.1 →L[𝕜] TangentSpace J (f p.1)} (hf : HasMFDerivAt I J f p.1 df) {dg : TangentSpace I' p.2 →L[𝕜] TangentSpace J' (g p.2)} (hg : HasMFDerivAt I' J' g p.2 dg) : HasMFDerivAt (I.prod I') (J.prod J') (Prod.map f g) p ((mfderiv I J f p.1).prodMap (mfderiv I' J' g p.2)) := by simp_rw [← hasMFDerivWithinAt_univ, ← mfderivWithin_univ, ← univ_prod_univ] convert hf.hasMFDerivWithinAt.prodMap hg.hasMFDerivWithinAt · rw [mfderivWithin_univ]; exact hf.mfderiv · rw [mfderivWithin_univ]; exact hg.mfderiv -- Note: this lemma does not apply easily to an arbitrary subset `s ⊆ M × M'` as -- unique differentiability on `(Prod.fst '' s)` and `(Prod.snd '' s)` does not imply -- unique differentiability on `s`: a priori, `(Prod.fst '' s) × (Prod.fst '' s)` -- could be a strict superset of `s`. lemma mfderivWithin_prodMap {p : M × M'} {t : Set M'} {f : M → N} {g : M' → N'} (hf : MDifferentiableWithinAt I J f s p.1) (hg : MDifferentiableWithinAt I' J' g t p.2) (hs : UniqueMDiffWithinAt I s p.1) (ht : UniqueMDiffWithinAt I' t p.2) : mfderivWithin (I.prod I') (J.prod J') (Prod.map f g) (s ×ˢ t) p = (mfderivWithin I J f s p.1).prodMap (mfderivWithin I' J' g t p.2) := by have hf' : HasMFDerivWithinAt I J f (Prod.fst '' s ×ˢ t) p.1 (mfderivWithin I J f s p.1) := hf.hasMFDerivWithinAt.mono (by grind) have hg' : HasMFDerivWithinAt I' J' g (Prod.snd '' s ×ˢ t) p.2 (mfderivWithin I' J' g t p.2) := hg.hasMFDerivWithinAt.mono (by grind) exact (hf'.prodMap hg').mfderivWithin (hs.prod ht) lemma mfderiv_prodMap {p : M × M'} {f : M → N} {g : M' → N'} (hf : MDifferentiableAt I J f p.1) (hg : MDifferentiableAt I' J' g p.2) : mfderiv (I.prod I') (J.prod J') (Prod.map f g) p = (mfderiv I J f p.1).prodMap (mfderiv I' J' g p.2) := by simp_rw [← mfderivWithin_univ, ← univ_prod_univ] exact mfderivWithin_prodMap hf.mdifferentiableWithinAt hg.mdifferentiableWithinAt (uniqueMDiffWithinAt_univ I) (uniqueMDiffWithinAt_univ I') end prodMap @[simp, mfld_simps] theorem tangentMap_prodSnd {p : TangentBundle (I.prod I') (M × M')} : tangentMap (I.prod I') I' Prod.snd p = ⟨p.proj.2, p.2.2⟩ := by simp [tangentMap]; rfl theorem tangentMapWithin_prodSnd {s : Set (M × M')} {p : TangentBundle (I.prod I') (M × M')} (hs : UniqueMDiffWithinAt (I.prod I') s p.proj) : tangentMapWithin (I.prod I') I' Prod.snd s p = ⟨p.proj.2, p.2.2⟩ := by simp only [tangentMapWithin] rw [mfderivWithin_snd hs] rcases p with ⟨⟩; rfl -- Kept as an alias for discoverability. alias MDifferentiableAt.mfderiv_prod := mfderiv_prodMk theorem mfderiv_prod_left {x₀ : M} {y₀ : M'} : mfderiv I (I.prod I') (fun x => (x, y₀)) x₀ = ContinuousLinearMap.inl 𝕜 (TangentSpace I x₀) (TangentSpace I' y₀) := by refine (mdifferentiableAt_id.mfderiv_prod mdifferentiableAt_const).trans ?_ rw [mfderiv_id, mfderiv_const, ContinuousLinearMap.inl] theorem tangentMap_prod_left {p : TangentBundle I M} {y₀ : M'} : tangentMap I (I.prod I') (fun x => (x, y₀)) p = ⟨(p.1, y₀), (p.2, 0)⟩ := by simp only [tangentMap, mfderiv_prod_left, TotalSpace.mk_inj] rfl theorem mfderiv_prod_right {x₀ : M} {y₀ : M'} : mfderiv I' (I.prod I') (fun y => (x₀, y)) y₀ = ContinuousLinearMap.inr 𝕜 (TangentSpace I x₀) (TangentSpace I' y₀) := by refine (mdifferentiableAt_const.mfderiv_prod mdifferentiableAt_id).trans ?_ rw [mfderiv_id, mfderiv_const, ContinuousLinearMap.inr] theorem tangentMap_prod_right {p : TangentBundle I' M'} {x₀ : M} : tangentMap I' (I.prod I') (fun y => (x₀, y)) p = ⟨(x₀, p.1), (0, p.2)⟩ := by simp only [tangentMap, mfderiv_prod_right, TotalSpace.mk_inj] rfl /-- The total derivative of a function in two variables is the sum of the partial derivatives. Note that to state this (without casts) we need to be able to see through the definition of `TangentSpace`. -/ theorem mfderiv_prod_eq_add {f : M × M' → M''} {p : M × M'} (hf : MDifferentiableAt (I.prod I') I'' f p) : mfderiv (I.prod I') I'' f p = mfderiv (I.prod I') I'' (fun z : M × M' => f (z.1, p.2)) p + mfderiv (I.prod I') I'' (fun z : M × M' => f (p.1, z.2)) p := by erw [mfderiv_comp_of_eq hf (mdifferentiableAt_fst.prodMk mdifferentiableAt_const) rfl, mfderiv_comp_of_eq hf (mdifferentiableAt_const.prodMk mdifferentiableAt_snd) rfl, ← ContinuousLinearMap.comp_add, mdifferentiableAt_fst.mfderiv_prod mdifferentiableAt_const, mdifferentiableAt_const.mfderiv_prod mdifferentiableAt_snd, mfderiv_fst, mfderiv_snd, mfderiv_const, mfderiv_const] symm convert ContinuousLinearMap.comp_id <| mfderiv (.prod I I') I'' f (p.1, p.2) exact ContinuousLinearMap.coprod_inl_inr /-- The total derivative of a function in two variables is the sum of the partial derivatives. Note that to state this (without casts) we need to be able to see through the definition of `TangentSpace`. Version in terms of the one-variable derivatives. -/ theorem mfderiv_prod_eq_add_comp {f : M × M' → M''} {p : M × M'} (hf : MDifferentiableAt (I.prod I') I'' f p) : mfderiv (I.prod I') I'' f p = (mfderiv I I'' (fun z : M => f (z, p.2)) p.1) ∘L (id (ContinuousLinearMap.fst 𝕜 E E') : (TangentSpace (I.prod I') p) →L[𝕜] (TangentSpace I p.1)) + (mfderiv I' I'' (fun z : M' => f (p.1, z)) p.2) ∘L (id (ContinuousLinearMap.snd 𝕜 E E') : (TangentSpace (I.prod I') p) →L[𝕜] (TangentSpace I' p.2)) := by rw [mfderiv_prod_eq_add hf] congr · have : (fun z : M × M' => f (z.1, p.2)) = (fun z : M => f (z, p.2)) ∘ Prod.fst := rfl rw [this, mfderiv_comp (I' := I)] · simp only [mfderiv_fst, id_eq] rfl · exact hf.comp _ (mdifferentiableAt_id.prodMk mdifferentiableAt_const) · exact mdifferentiableAt_fst · have : (fun z : M × M' => f (p.1, z.2)) = (fun z : M' => f (p.1, z)) ∘ Prod.snd := rfl rw [this, mfderiv_comp (I' := I')] · simp only [mfderiv_snd, id_eq] rfl · exact hf.comp _ (mdifferentiableAt_const.prodMk mdifferentiableAt_id) · exact mdifferentiableAt_snd /-- The total derivative of a function in two variables is the sum of the partial derivatives. Note that to state this (without casts) we need to be able to see through the definition of `TangentSpace`. Version in terms of the one-variable derivatives. -/ theorem mfderiv_prod_eq_add_apply {f : M × M' → M''} {p : M × M'} {v : TangentSpace (I.prod I') p} (hf : MDifferentiableAt (I.prod I') I'' f p) : mfderiv (I.prod I') I'' f p v = mfderiv I I'' (fun z : M => f (z, p.2)) p.1 v.1 + mfderiv I' I'' (fun z : M' => f (p.1, z)) p.2 v.2 := by rw [mfderiv_prod_eq_add_comp hf] rfl end Prod section disjointUnion variable {M' : Type*} [TopologicalSpace M'] [ChartedSpace H M'] {p : M ⊕ M'} /-- In extended charts at `p`, `Sum.swap` looks like the identity near `p`. -/ lemma writtenInExtChartAt_sumSwap_eventuallyEq_id : writtenInExtChartAt I I p Sum.swap =ᶠ[𝓝[range I] (I <|chartAt H p p)] id := by cases p with | inl x => let t := I.symm ⁻¹' (chartAt H x).target ∩ range I have : EqOn (writtenInExtChartAt I I (Sum.inl x) (@Sum.swap M M')) id t := by intro y hy simp only [writtenInExtChartAt, extChartAt, Sum.swap_inl, ChartedSpace.sum_chartAt_inl, ChartedSpace.sum_chartAt_inr] dsimp rw [Sum.inr_injective.extend_apply, (chartAt H x).right_inv (by grind)] exact I.right_inv (by grind) apply Filter.eventually_of_mem ?_ this rw [Filter.inter_mem_iff] refine ⟨I.continuousWithinAt_symm.preimage_mem_nhdsWithin ?_, self_mem_nhdsWithin⟩ exact (chartAt H x).open_target.mem_nhds (by simp) | inr x => let t := I.symm ⁻¹' (chartAt H x).target ∩ range I have : EqOn (writtenInExtChartAt I I (Sum.inr x) (@Sum.swap M M')) id t := by intro y hy simp only [writtenInExtChartAt, extChartAt, Sum.swap_inr, ChartedSpace.sum_chartAt_inl, ChartedSpace.sum_chartAt_inr] dsimp rw [Sum.inl_injective.extend_apply, (chartAt H x).right_inv (by grind)] exact I.right_inv (by grind) apply Filter.eventually_of_mem ?_ this rw [Filter.inter_mem_iff] refine ⟨I.continuousWithinAt_symm.preimage_mem_nhdsWithin ?_, self_mem_nhdsWithin⟩ exact (chartAt H x).open_target.mem_nhds (by simp) theorem hasMFDerivAt_sumSwap : HasMFDerivAt I I (@Sum.swap M M') p (ContinuousLinearMap.id 𝕜 (TangentSpace I p)) := by refine ⟨by fun_prop, ?_⟩ apply (hasFDerivWithinAt_id _ (range I)).congr_of_eventuallyEq · exact writtenInExtChartAt_sumSwap_eventuallyEq_id · simp only [mfld_simps] cases p <;> simp @[simp] theorem mfderivWithin_sumSwap {s : Set (M ⊕ M')} (hs : UniqueMDiffWithinAt I s p) : mfderivWithin I I (@Sum.swap M M') s p = ContinuousLinearMap.id 𝕜 (TangentSpace I p) := hasMFDerivAt_sumSwap.hasMFDerivWithinAt.mfderivWithin hs @[simp] theorem mfderiv_sumSwap : mfderiv I I (@Sum.swap M M') p = ContinuousLinearMap.id 𝕜 (TangentSpace I p) := by simpa [mfderivWithin_univ] using (mfderivWithin_sumSwap (uniqueMDiffWithinAt_univ I)) variable {f : M → N} (g : M' → N') {q : M} {q' : M'} lemma writtenInExtChartAt_sumInl_eventuallyEq_id : (writtenInExtChartAt I I q (@Sum.inl M M')) =ᶠ[𝓝[Set.range I] (extChartAt I q q)] id := by have hmem : I.symm ⁻¹' (chartAt H q).target ∩ Set.range I ∈ 𝓝[Set.range I] (extChartAt I q q) := by rw [← I.image_eq (chartAt H q).target] exact (chartAt H q).extend_image_target_mem_nhds (mem_chart_source H q) filter_upwards [hmem] with y hy rcases hy with ⟨hyT, ⟨z, rfl⟩⟩ simp [writtenInExtChartAt, extChartAt, ChartedSpace.sum_chartAt_inl, Sum.inl_injective.extend_apply <| chartAt H q, (chartAt H q).right_inv (by simpa [Set.mem_preimage, I.left_inv] using hyT)] lemma writtenInExtChartAt_sumInr_eventuallyEq_id : (writtenInExtChartAt I I q' (@Sum.inr M M')) =ᶠ[𝓝[Set.range I] (extChartAt I q' q')] id := by have hmem : I.symm ⁻¹' (chartAt H q').target ∩ Set.range I ∈ 𝓝[Set.range I] (extChartAt I q' q') := by rw [← I.image_eq (chartAt H q').target] exact (chartAt H q').extend_image_target_mem_nhds (mem_chart_source H q') filter_upwards [hmem] with y hy rcases hy with ⟨hyT, ⟨z, rfl⟩⟩ simp [writtenInExtChartAt, extChartAt, ChartedSpace.sum_chartAt_inr, Sum.inr_injective.extend_apply <| chartAt H q', (chartAt H q').right_inv (by simpa [Set.mem_preimage, I.left_inv] using hyT)] theorem hasMFDerivWithinAt_inl : HasMFDerivWithinAt I I (@Sum.inl M M') s q (ContinuousLinearMap.id 𝕜 (TangentSpace I q)) := by refine ⟨by fun_prop, ?_⟩ have : (writtenInExtChartAt I I q (@Sum.inl M M')) =ᶠ[𝓝[(extChartAt I q).symm ⁻¹' s ∩ Set.range I] (extChartAt I q q)] id := writtenInExtChartAt_sumInl_eventuallyEq_id.filter_mono (nhdsWithin_mono _ (fun _y hy ↦ hy.2)) exact (hasFDerivWithinAt_id (extChartAt I q q) _).congr_of_eventuallyEq this (by simp [writtenInExtChartAt, extChartAt]) theorem hasMFDerivAt_inl : HasMFDerivAt I I (@Sum.inl M M') q (ContinuousLinearMap.id 𝕜 (TangentSpace I p)) := by simpa [HasMFDerivAt, hasMFDerivWithinAt_univ] using hasMFDerivWithinAt_inl (s := Set.univ) theorem hasMFDerivWithinAt_inr {t : Set M'} : HasMFDerivWithinAt I I (@Sum.inr M M') t q' (ContinuousLinearMap.id 𝕜 (TangentSpace I q')) := by refine ⟨by fun_prop, ?_⟩ have : (writtenInExtChartAt I I q' (@Sum.inr M M')) =ᶠ[𝓝[(extChartAt I q').symm ⁻¹' t ∩ Set.range I] (extChartAt I q' q')] id := writtenInExtChartAt_sumInr_eventuallyEq_id.filter_mono (nhdsWithin_mono _ (fun _y hy ↦ hy.2)) exact (hasFDerivWithinAt_id (extChartAt I q' q') _).congr_of_eventuallyEq this (by simp [writtenInExtChartAt, extChartAt]) theorem hasMFDerivAt_inr : HasMFDerivAt I I (@Sum.inr M M') q' (ContinuousLinearMap.id 𝕜 (TangentSpace I p)) := by simpa [HasMFDerivAt, hasMFDerivWithinAt_univ] using hasMFDerivWithinAt_inr (t := Set.univ) theorem mfderivWithin_sumInl (hU : UniqueMDiffWithinAt I s q) : mfderivWithin I I (@Sum.inl M M') s q = ContinuousLinearMap.id 𝕜 (TangentSpace I p) := (hasMFDerivWithinAt_inl).mfderivWithin hU theorem mfderiv_sumInl : mfderiv I I (@Sum.inl M M') q = ContinuousLinearMap.id 𝕜 (TangentSpace I p) := by simpa [mfderivWithin_univ] using (mfderivWithin_sumInl (uniqueMDiffWithinAt_univ I)) theorem mfderivWithin_sumInr {t : Set M'} (hU : UniqueMDiffWithinAt I t q') : mfderivWithin I I (@Sum.inr M M') t q' = ContinuousLinearMap.id 𝕜 (TangentSpace I q') := (hasMFDerivWithinAt_inr).mfderivWithin hU theorem mfderiv_sumInr : mfderiv I I (@Sum.inr M M') q' = ContinuousLinearMap.id 𝕜 (TangentSpace I q') := by simpa [mfderivWithin_univ] using (mfderivWithin_sumInr (uniqueMDiffWithinAt_univ I)) end disjointUnion section Arithmetic /-! #### Arithmetic Note that in the `HasMFDerivAt` lemmas there is an abuse of the defeq between `E'` and `TangentSpace 𝓘(𝕜, E') (f z)` (similarly for `g',F',p',q'`). In general this defeq is not canonical, but in this case (the tangent space of a vector space) it is canonical. -/ section Group variable {z : M} {f g : M → E'} {f' g' : TangentSpace I z →L[𝕜] E'} theorem HasMFDerivWithinAt.add {s : Set M} (hf : HasMFDerivWithinAt I 𝓘(𝕜, E') f s z f') (hg : HasMFDerivWithinAt I 𝓘(𝕜, E') g s z g') : HasMFDerivWithinAt I 𝓘(𝕜, E') (f + g) s z (f' + g') := ⟨hf.1.add hg.1, hf.2.add hg.2⟩ theorem HasMFDerivAt.add (hf : HasMFDerivAt I 𝓘(𝕜, E') f z f') (hg : HasMFDerivAt I 𝓘(𝕜, E') g z g') : HasMFDerivAt I 𝓘(𝕜, E') (f + g) z (f' + g') := ⟨hf.1.add hg.1, hf.2.add hg.2⟩ theorem MDifferentiableWithinAt.add {s : Set M} (hf : MDifferentiableWithinAt I 𝓘(𝕜, E') f s z) (hg : MDifferentiableWithinAt I 𝓘(𝕜, E') g s z) : MDifferentiableWithinAt I 𝓘(𝕜, E') (f + g) s z := (hf.hasMFDerivWithinAt.add hg.hasMFDerivWithinAt).mdifferentiableWithinAt theorem MDifferentiableAt.add (hf : MDifferentiableAt I 𝓘(𝕜, E') f z) (hg : MDifferentiableAt I 𝓘(𝕜, E') g z) : MDifferentiableAt I 𝓘(𝕜, E') (f + g) z := (hf.hasMFDerivAt.add hg.hasMFDerivAt).mdifferentiableAt theorem MDifferentiableOn.add {s : Set M} (hf : MDifferentiableOn I 𝓘(𝕜, E') f s) (hg : MDifferentiableOn I 𝓘(𝕜, E') g s) : MDifferentiableOn I 𝓘(𝕜, E') (f + g) s := fun x hx ↦ (hf x hx).add (hg x hx) theorem MDifferentiable.add (hf : MDifferentiable I 𝓘(𝕜, E') f) (hg : MDifferentiable I 𝓘(𝕜, E') g) : MDifferentiable I 𝓘(𝕜, E') (f + g) := fun x => (hf x).add (hg x) -- Porting note: forcing types using `by exact` theorem mfderiv_add (hf : MDifferentiableAt I 𝓘(𝕜, E') f z) (hg : MDifferentiableAt I 𝓘(𝕜, E') g z) : (by exact mfderiv I 𝓘(𝕜, E') (f + g) z : TangentSpace I z →L[𝕜] E') = (by exact mfderiv I 𝓘(𝕜, E') f z) + (by exact mfderiv I 𝓘(𝕜, E') g z) := (hf.hasMFDerivAt.add hg.hasMFDerivAt).mfderiv theorem HasMFDerivAt.const_smul (hf : HasMFDerivAt I 𝓘(𝕜, E') f z f') (s : 𝕜) : HasMFDerivAt I 𝓘(𝕜, E') (s • f) z (s • f') := ⟨hf.1.const_smul s, hf.2.const_smul s⟩ theorem MDifferentiableAt.const_smul (hf : MDifferentiableAt I 𝓘(𝕜, E') f z) (s : 𝕜) : MDifferentiableAt I 𝓘(𝕜, E') (s • f) z := (hf.hasMFDerivAt.const_smul s).mdifferentiableAt theorem MDifferentiable.const_smul (s : 𝕜) (hf : MDifferentiable I 𝓘(𝕜, E') f) : MDifferentiable I 𝓘(𝕜, E') (s • f) := fun x => (hf x).const_smul s theorem const_smul_mfderiv (hf : MDifferentiableAt I 𝓘(𝕜, E') f z) (s : 𝕜) : (mfderiv I 𝓘(𝕜, E') (s • f) z : TangentSpace I z →L[𝕜] E') = (s • mfderiv I 𝓘(𝕜, E') f z : TangentSpace I z →L[𝕜] E') := (hf.hasMFDerivAt.const_smul s).mfderiv theorem HasMFDerivWithinAt.neg {s : Set M} (hf : HasMFDerivWithinAt I 𝓘(𝕜, E') f s z f') : HasMFDerivWithinAt I 𝓘(𝕜, E') (-f) s z (-f') := ⟨hf.1.neg, hf.2.neg⟩ theorem HasMFDerivAt.neg (hf : HasMFDerivAt I 𝓘(𝕜, E') f z f') : HasMFDerivAt I 𝓘(𝕜, E') (-f) z (-f') := ⟨hf.1.neg, hf.2.neg⟩ theorem hasMFDerivAt_neg : HasMFDerivAt I 𝓘(𝕜, E') (-f) z (-f') ↔ HasMFDerivAt I 𝓘(𝕜, E') f z f' := ⟨fun hf => by convert hf.neg <;> rw [neg_neg], fun hf => hf.neg⟩ theorem MDifferentiableWithinAt.neg {s : Set M} (hf : MDifferentiableWithinAt I 𝓘(𝕜, E') f s z) : MDifferentiableWithinAt I 𝓘(𝕜, E') (-f) s z := (hf.hasMFDerivWithinAt.neg).mdifferentiableWithinAt theorem MDifferentiableAt.neg (hf : MDifferentiableAt I 𝓘(𝕜, E') f z) : MDifferentiableAt I 𝓘(𝕜, E') (-f) z := hf.hasMFDerivAt.neg.mdifferentiableAt theorem MDifferentiableOn.neg {s : Set M} (hf : MDifferentiableOn I 𝓘(𝕜, E') f s) : MDifferentiableOn I 𝓘(𝕜, E') (-f) s := fun x hx ↦ (hf x hx).neg theorem mdifferentiableAt_neg : MDifferentiableAt I 𝓘(𝕜, E') (-f) z ↔ MDifferentiableAt I 𝓘(𝕜, E') f z := ⟨fun hf => by convert hf.neg; rw [neg_neg], fun hf => hf.neg⟩ theorem MDifferentiable.neg (hf : MDifferentiable I 𝓘(𝕜, E') f) : MDifferentiable I 𝓘(𝕜, E') (-f) := fun x => (hf x).neg theorem mfderiv_neg (f : M → E') (x : M) : (mfderiv I 𝓘(𝕜, E') (-f) x : TangentSpace I x →L[𝕜] E') = (-mfderiv I 𝓘(𝕜, E') f x : TangentSpace I x →L[𝕜] E') := by simp_rw [mfderiv] by_cases hf : MDifferentiableAt I 𝓘(𝕜, E') f x · exact hf.hasMFDerivAt.neg.mfderiv · rw [if_neg hf]; rw [← mdifferentiableAt_neg] at hf; rw [if_neg hf, neg_zero] theorem HasMFDerivAt.sub (hf : HasMFDerivAt I 𝓘(𝕜, E') f z f') (hg : HasMFDerivAt I 𝓘(𝕜, E') g z g') : HasMFDerivAt I 𝓘(𝕜, E') (f - g) z (f' - g') := ⟨hf.1.sub hg.1, hf.2.sub hg.2⟩ theorem MDifferentiableAt.sub (hf : MDifferentiableAt I 𝓘(𝕜, E') f z) (hg : MDifferentiableAt I 𝓘(𝕜, E') g z) : MDifferentiableAt I 𝓘(𝕜, E') (f - g) z := (hf.hasMFDerivAt.sub hg.hasMFDerivAt).mdifferentiableAt theorem MDifferentiable.sub (hf : MDifferentiable I 𝓘(𝕜, E') f) (hg : MDifferentiable I 𝓘(𝕜, E') g) : MDifferentiable I 𝓘(𝕜, E') (f - g) := fun x => (hf x).sub (hg x) theorem mfderiv_sub (hf : MDifferentiableAt I 𝓘(𝕜, E') f z) (hg : MDifferentiableAt I 𝓘(𝕜, E') g z) : (by exact mfderiv I 𝓘(𝕜, E') (f - g) z : TangentSpace I z →L[𝕜] E') = (by exact mfderiv I 𝓘(𝕜, E') f z) - (by exact mfderiv I 𝓘(𝕜, E') g z) := (hf.hasMFDerivAt.sub hg.hasMFDerivAt).mfderiv end Group section AlgebraOverRing open scoped RightActions variable {z : M} {F' : Type*} [NormedRing F'] [NormedAlgebra 𝕜 F'] {p q : M → F'} {p' q' : TangentSpace I z →L[𝕜] F'} theorem HasMFDerivWithinAt.mul' (hp : HasMFDerivWithinAt I 𝓘(𝕜, F') p s z p') (hq : HasMFDerivWithinAt I 𝓘(𝕜, F') q s z q') : HasMFDerivWithinAt I 𝓘(𝕜, F') (p * q) s z (p z • q' + p' <• q z : E →L[𝕜] F') := ⟨hp.1.mul hq.1, by simpa only [mfld_simps] using hp.2.mul' hq.2⟩ theorem HasMFDerivAt.mul' (hp : HasMFDerivAt I 𝓘(𝕜, F') p z p') (hq : HasMFDerivAt I 𝓘(𝕜, F') q z q') : HasMFDerivAt I 𝓘(𝕜, F') (p * q) z (p z • q' + p' <• q z : E →L[𝕜] F') := hasMFDerivWithinAt_univ.mp <| hp.hasMFDerivWithinAt.mul' hq.hasMFDerivWithinAt theorem MDifferentiableWithinAt.mul (hp : MDifferentiableWithinAt I 𝓘(𝕜, F') p s z) (hq : MDifferentiableWithinAt I 𝓘(𝕜, F') q s z) : MDifferentiableWithinAt I 𝓘(𝕜, F') (p * q) s z := (hp.hasMFDerivWithinAt.mul' hq.hasMFDerivWithinAt).mdifferentiableWithinAt theorem MDifferentiableAt.mul (hp : MDifferentiableAt I 𝓘(𝕜, F') p z) (hq : MDifferentiableAt I 𝓘(𝕜, F') q z) : MDifferentiableAt I 𝓘(𝕜, F') (p * q) z := (hp.hasMFDerivAt.mul' hq.hasMFDerivAt).mdifferentiableAt theorem MDifferentiableOn.mul (hp : MDifferentiableOn I 𝓘(𝕜, F') p s) (hq : MDifferentiableOn I 𝓘(𝕜, F') q s) : MDifferentiableOn I 𝓘(𝕜, F') (p * q) s := fun x hx => (hp x hx).mul <| hq x hx theorem MDifferentiable.mul (hp : MDifferentiable I 𝓘(𝕜, F') p) (hq : MDifferentiable I 𝓘(𝕜, F') q) : MDifferentiable I 𝓘(𝕜, F') (p * q) := fun x => (hp x).mul (hq x) end AlgebraOverRing section AlgebraOverCommRing variable {z : M} {F' : Type*} [NormedCommRing F'] [NormedAlgebra 𝕜 F'] {p q : M → F'} {p' q' : TangentSpace I z →L[𝕜] F'} theorem HasMFDerivWithinAt.mul (hp : HasMFDerivWithinAt I 𝓘(𝕜, F') p s z p') (hq : HasMFDerivWithinAt I 𝓘(𝕜, F') q s z q') : HasMFDerivWithinAt I 𝓘(𝕜, F') (p * q) s z (p z • q' + q z • p' : E →L[𝕜] F') := by convert hp.mul' hq; ext _; apply mul_comm theorem HasMFDerivAt.mul (hp : HasMFDerivAt I 𝓘(𝕜, F') p z p') (hq : HasMFDerivAt I 𝓘(𝕜, F') q z q') : HasMFDerivAt I 𝓘(𝕜, F') (p * q) z (p z • q' + q z • p' : E →L[𝕜] F') := hasMFDerivWithinAt_univ.mp <| hp.hasMFDerivWithinAt.mul hq.hasMFDerivWithinAt end AlgebraOverCommRing end Arithmetic end SpecificFunctions
.lake/packages/mathlib/Mathlib/Geometry/Manifold/MFDeriv/NormedSpace.lean
import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace import Mathlib.Geometry.Manifold.MFDeriv.SpecificFunctions /-! ## Equivalence of manifold differentiability with the basic definition for functions between vector spaces The API in this file is mostly copied from `Mathlib/Geometry/Manifold/ContMDiff/NormedSpace.lean`, providing the same statements for higher smoothness. In this file, we do the same for differentiability. -/ open Set ChartedSpace IsManifold open scoped Topology Manifold variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {n : WithTop ℕ∞} -- declare a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- declare a `C^n` manifold `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] [IsManifold I' n M'] -- declare a `C^n` manifold `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] [IsManifold J n N] -- declare a `C^n` manifold `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] [IsManifold J' n N'] -- F₁, F₂, F₃, F₄ are normed spaces {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] {F₃ : Type*} [NormedAddCommGroup F₃] [NormedSpace 𝕜 F₃] {F₄ : Type*} [NormedAddCommGroup F₄] [NormedSpace 𝕜 F₄] -- declare functions, sets, points and smoothness indices {f f₁ : M → M'} {s t : Set M} {x : M} {m n : ℕ∞} section Module theorem DifferentiableWithinAt.comp_mdifferentiableWithinAt {g : F → F'} {f : M → F} {s : Set M} {t : Set F} {x : M} (hg : DifferentiableWithinAt 𝕜 g t (f x)) (hf : MDifferentiableWithinAt I 𝓘(𝕜, F) f s x) (h : MapsTo f s t) : MDifferentiableWithinAt I 𝓘(𝕜, F') (g ∘ f) s x := hg.mdifferentiableWithinAt.comp x hf h theorem DifferentiableAt.comp_mdifferentiableWithinAt {g : F → F'} {f : M → F} {s : Set M} {x : M} (hg : DifferentiableAt 𝕜 g (f x)) (hf : MDifferentiableWithinAt I 𝓘(𝕜, F) f s x) : MDifferentiableWithinAt I 𝓘(𝕜, F') (g ∘ f) s x := hg.mdifferentiableAt.comp_mdifferentiableWithinAt x hf theorem DifferentiableAt.comp_mdifferentiableAt {g : F → F'} {f : M → F} {x : M} (hg : DifferentiableAt 𝕜 g (f x)) (hf : MDifferentiableAt I 𝓘(𝕜, F) f x) : MDifferentiableAt I 𝓘(𝕜, F') (g ∘ f) x := hg.comp_mdifferentiableWithinAt hf theorem Differentiable.comp_mdifferentiableWithinAt {g : F → F'} {f : M → F} {s : Set M} {x : M} (hg : Differentiable 𝕜 g) (hf : MDifferentiableWithinAt I 𝓘(𝕜, F) f s x) : MDifferentiableWithinAt I 𝓘(𝕜, F') (g ∘ f) s x := hg.differentiableAt.comp_mdifferentiableWithinAt hf theorem Differentiable.comp_mdifferentiableAt {g : F → F'} {f : M → F} {x : M} (hg : Differentiable 𝕜 g) (hf : MDifferentiableAt I 𝓘(𝕜, F) f x) : MDifferentiableAt I 𝓘(𝕜, F') (g ∘ f) x := hg.comp_mdifferentiableWithinAt hf theorem Differentiable.comp_mdifferentiable {g : F → F'} {f : M → F} (hg : Differentiable 𝕜 g) (hf : MDifferentiable I 𝓘(𝕜, F) f) : MDifferentiable I 𝓘(𝕜, F') (g ∘ f) := fun x => hg.differentiableAt.comp_mdifferentiableAt (hf x) end Module /-! ### Linear maps between normed spaces are differentiable -/ theorem MDifferentiableWithinAt.clm_precomp {f : M → F₁ →L[𝕜] F₂} {s : Set M} {x : M} (hf : MDifferentiableWithinAt I 𝓘(𝕜, F₁ →L[𝕜] F₂) f s x) : MDifferentiableWithinAt I 𝓘(𝕜, (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) (fun y ↦ (f y).precomp F₃ : M → (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) s x := Differentiable.comp_mdifferentiableWithinAt (ContinuousLinearMap.differentiable (ContinuousLinearMap.compL 𝕜 F₁ F₂ F₃).flip) hf nonrec theorem MDifferentiableAt.clm_precomp {f : M → F₁ →L[𝕜] F₂} {x : M} (hf : MDifferentiableAt I 𝓘(𝕜, F₁ →L[𝕜] F₂) f x) : MDifferentiableAt I 𝓘(𝕜, (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) (fun y ↦ (f y).precomp F₃ : M → (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) x := Differentiable.comp_mdifferentiableAt (ContinuousLinearMap.differentiable (ContinuousLinearMap.compL 𝕜 F₁ F₂ F₃).flip) hf theorem MDifferentiableOn.clm_precomp {f : M → F₁ →L[𝕜] F₂} {s : Set M} (hf : MDifferentiableOn I 𝓘(𝕜, F₁ →L[𝕜] F₂) f s) : MDifferentiableOn I 𝓘(𝕜, (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) (fun y ↦ (f y).precomp F₃ : M → (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) s := fun x hx ↦ (hf x hx).clm_precomp theorem MDifferentiable.clm_precomp {f : M → F₁ →L[𝕜] F₂} (hf : MDifferentiable I 𝓘(𝕜, F₁ →L[𝕜] F₂) f) : MDifferentiable I 𝓘(𝕜, (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) (fun y ↦ (f y).precomp F₃ : M → (F₂ →L[𝕜] F₃) →L[𝕜] (F₁ →L[𝕜] F₃)) := fun x ↦ (hf x).clm_precomp theorem MDifferentiableWithinAt.clm_postcomp {f : M → F₂ →L[𝕜] F₃} {s : Set M} {x : M} (hf : MDifferentiableWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₃) f s x) : MDifferentiableWithinAt I 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) (fun y ↦ (f y).postcomp F₁ : M → (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) s x := Differentiable.comp_mdifferentiableWithinAt (ContinuousLinearMap.differentiable (ContinuousLinearMap.compL 𝕜 F₁ F₂ F₃)) hf theorem MDifferentiableAt.clm_postcomp {f : M → F₂ →L[𝕜] F₃} {x : M} (hf : MDifferentiableAt I 𝓘(𝕜, F₂ →L[𝕜] F₃) f x) : MDifferentiableAt I 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) (fun y ↦ (f y).postcomp F₁ : M → (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) x := Differentiable.comp_mdifferentiableAt (ContinuousLinearMap.differentiable (ContinuousLinearMap.compL 𝕜 F₁ F₂ F₃)) hf nonrec theorem MDifferentiableOn.clm_postcomp {f : M → F₂ →L[𝕜] F₃} {s : Set M} (hf : MDifferentiableOn I 𝓘(𝕜, F₂ →L[𝕜] F₃) f s) : MDifferentiableOn I 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) (fun y ↦ (f y).postcomp F₁ : M → (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) s := fun x hx ↦ (hf x hx).clm_postcomp theorem MDifferentiable.clm_postcomp {f : M → F₂ →L[𝕜] F₃} (hf : MDifferentiable I 𝓘(𝕜, F₂ →L[𝕜] F₃) f) : MDifferentiable I 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) (fun y ↦ (f y).postcomp F₁ : M → (F₁ →L[𝕜] F₂) →L[𝕜] (F₁ →L[𝕜] F₃)) := fun x ↦ (hf x).clm_postcomp theorem MDifferentiableWithinAt.clm_comp {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₁} {s : Set M} {x : M} (hg : MDifferentiableWithinAt I 𝓘(𝕜, F₁ →L[𝕜] F₃) g s x) (hf : MDifferentiableWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₁) f s x) : MDifferentiableWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₃) (fun x => (g x).comp (f x)) s x := Differentiable.comp_mdifferentiableWithinAt (g := fun x : (F₁ →L[𝕜] F₃) × (F₂ →L[𝕜] F₁) => x.1.comp x.2) (f := fun x => (g x, f x)) (differentiable_fst.clm_comp differentiable_snd) (hg.prodMk_space hf) theorem MDifferentiableAt.clm_comp {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₁} {x : M} (hg : MDifferentiableAt I 𝓘(𝕜, F₁ →L[𝕜] F₃) g x) (hf : MDifferentiableAt I 𝓘(𝕜, F₂ →L[𝕜] F₁) f x) : MDifferentiableAt I 𝓘(𝕜, F₂ →L[𝕜] F₃) (fun x => (g x).comp (f x)) x := (hg.mdifferentiableWithinAt.clm_comp hf.mdifferentiableWithinAt).mdifferentiableAt Filter.univ_mem theorem MDifferentiableOn.clm_comp {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₁} {s : Set M} (hg : MDifferentiableOn I 𝓘(𝕜, F₁ →L[𝕜] F₃) g s) (hf : MDifferentiableOn I 𝓘(𝕜, F₂ →L[𝕜] F₁) f s) : MDifferentiableOn I 𝓘(𝕜, F₂ →L[𝕜] F₃) (fun x => (g x).comp (f x)) s := fun x hx => (hg x hx).clm_comp (hf x hx) theorem MDifferentiable.clm_comp {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₁} (hg : MDifferentiable I 𝓘(𝕜, F₁ →L[𝕜] F₃) g) (hf : MDifferentiable I 𝓘(𝕜, F₂ →L[𝕜] F₁) f) : MDifferentiable I 𝓘(𝕜, F₂ →L[𝕜] F₃) fun x => (g x).comp (f x) := fun x => (hg x).clm_comp (hf x) /-- Applying a linear map to a vector is differentiable within a set. Version in vector spaces. For a version in nontrivial vector bundles, see `MDifferentiableWithinAt.clm_apply_of_inCoordinates`. -/ theorem MDifferentiableWithinAt.clm_apply {g : M → F₁ →L[𝕜] F₂} {f : M → F₁} {s : Set M} {x : M} (hg : MDifferentiableWithinAt I 𝓘(𝕜, F₁ →L[𝕜] F₂) g s x) (hf : MDifferentiableWithinAt I 𝓘(𝕜, F₁) f s x) : MDifferentiableWithinAt I 𝓘(𝕜, F₂) (fun x => g x (f x)) s x := DifferentiableWithinAt.comp_mdifferentiableWithinAt (t := univ) (g := fun x : (F₁ →L[𝕜] F₂) × F₁ => x.1 x.2) (by apply (Differentiable.differentiableAt _).differentiableWithinAt exact differentiable_fst.clm_apply differentiable_snd) (hg.prodMk_space hf) (by simp_rw [mapsTo_univ]) /-- Applying a linear map to a vector is differentiable. Version in vector spaces. For a version in nontrivial vector bundles, see `MDifferentiableAt.clm_apply_of_inCoordinates`. -/ theorem MDifferentiableAt.clm_apply {g : M → F₁ →L[𝕜] F₂} {f : M → F₁} {x : M} (hg : MDifferentiableAt I 𝓘(𝕜, F₁ →L[𝕜] F₂) g x) (hf : MDifferentiableAt I 𝓘(𝕜, F₁) f x) : MDifferentiableAt I 𝓘(𝕜, F₂) (fun x => g x (f x)) x := DifferentiableWithinAt.comp_mdifferentiableWithinAt (t := univ) (g := fun x : (F₁ →L[𝕜] F₂) × F₁ => x.1 x.2) (by apply (Differentiable.differentiableAt _).differentiableWithinAt exact differentiable_fst.clm_apply differentiable_snd) (hg.prodMk_space hf) (by simp_rw [mapsTo_univ]) theorem MDifferentiableOn.clm_apply {g : M → F₁ →L[𝕜] F₂} {f : M → F₁} {s : Set M} (hg : MDifferentiableOn I 𝓘(𝕜, F₁ →L[𝕜] F₂) g s) (hf : MDifferentiableOn I 𝓘(𝕜, F₁) f s) : MDifferentiableOn I 𝓘(𝕜, F₂) (fun x => g x (f x)) s := fun x hx => (hg x hx).clm_apply (hf x hx) theorem MDifferentiable.clm_apply {g : M → F₁ →L[𝕜] F₂} {f : M → F₁} (hg : MDifferentiable I 𝓘(𝕜, F₁ →L[𝕜] F₂) g) (hf : MDifferentiable I 𝓘(𝕜, F₁) f) : MDifferentiable I 𝓘(𝕜, F₂) fun x => g x (f x) := fun x => (hg x).clm_apply (hf x) theorem MDifferentiableWithinAt.cle_arrowCongr {f : M → F₁ ≃L[𝕜] F₂} {g : M → F₃ ≃L[𝕜] F₄} {s : Set M} {x : M} (hf : MDifferentiableWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₁) (fun x ↦ ((f x).symm : F₂ →L[𝕜] F₁)) s x) (hg : MDifferentiableWithinAt I 𝓘(𝕜, F₃ →L[𝕜] F₄) (fun x ↦ (g x : F₃ →L[𝕜] F₄)) s x) : MDifferentiableWithinAt I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) (fun y ↦ (f y).arrowCongr (g y) : M → (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) s x := show MDifferentiableWithinAt I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) (fun y ↦ (((f y).symm : F₂ →L[𝕜] F₁).precomp F₄).comp ((g y : F₃ →L[𝕜] F₄).postcomp F₁)) s x from hf.clm_precomp (F₃ := F₄) |>.clm_comp <| hg.clm_postcomp (F₁ := F₁) theorem MDifferentiableAt.cle_arrowCongr {f : M → F₁ ≃L[𝕜] F₂} {g : M → F₃ ≃L[𝕜] F₄} {x : M} (hf : MDifferentiableAt I 𝓘(𝕜, F₂ →L[𝕜] F₁) (fun x ↦ ((f x).symm : F₂ →L[𝕜] F₁)) x) (hg : MDifferentiableAt I 𝓘(𝕜, F₃ →L[𝕜] F₄) (fun x ↦ (g x : F₃ →L[𝕜] F₄)) x) : MDifferentiableAt I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) (fun y ↦ (f y).arrowCongr (g y) : M → (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) x := show MDifferentiableAt I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) (fun y ↦ (((f y).symm : F₂ →L[𝕜] F₁).precomp F₄).comp ((g y : F₃ →L[𝕜] F₄).postcomp F₁)) x from hf.clm_precomp (F₃ := F₄) |>.clm_comp <| hg.clm_postcomp (F₁ := F₁) theorem MDifferentiableOn.cle_arrowCongr {f : M → F₁ ≃L[𝕜] F₂} {g : M → F₃ ≃L[𝕜] F₄} {s : Set M} (hf : MDifferentiableOn I 𝓘(𝕜, F₂ →L[𝕜] F₁) (fun x ↦ ((f x).symm : F₂ →L[𝕜] F₁)) s) (hg : MDifferentiableOn I 𝓘(𝕜, F₃ →L[𝕜] F₄) (fun x ↦ (g x : F₃ →L[𝕜] F₄)) s) : MDifferentiableOn I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) (fun y ↦ (f y).arrowCongr (g y) : M → (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) s := fun x hx ↦ (hf x hx).cle_arrowCongr (hg x hx) theorem MDifferentiable.cle_arrowCongr {f : M → F₁ ≃L[𝕜] F₂} {g : M → F₃ ≃L[𝕜] F₄} (hf : MDifferentiable I 𝓘(𝕜, F₂ →L[𝕜] F₁) (fun x ↦ ((f x).symm : F₂ →L[𝕜] F₁))) (hg : MDifferentiable I 𝓘(𝕜, F₃ →L[𝕜] F₄) (fun x ↦ (g x : F₃ →L[𝕜] F₄))) : MDifferentiable I 𝓘(𝕜, (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) (fun y ↦ (f y).arrowCongr (g y) : M → (F₁ →L[𝕜] F₃) →L[𝕜] (F₂ →L[𝕜] F₄)) := fun x ↦ (hf x).cle_arrowCongr (hg x) theorem MDifferentiableWithinAt.clm_prodMap {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₄} {s : Set M} {x : M} (hg : MDifferentiableWithinAt I 𝓘(𝕜, F₁ →L[𝕜] F₃) g s x) (hf : MDifferentiableWithinAt I 𝓘(𝕜, F₂ →L[𝕜] F₄) f s x) : MDifferentiableWithinAt I 𝓘(𝕜, F₁ × F₂ →L[𝕜] F₃ × F₄) (fun x => (g x).prodMap (f x)) s x := Differentiable.comp_mdifferentiableWithinAt (g := fun x : (F₁ →L[𝕜] F₃) × (F₂ →L[𝕜] F₄) => x.1.prodMap x.2) (f := fun x => (g x, f x)) (ContinuousLinearMap.prodMapL 𝕜 F₁ F₃ F₂ F₄).differentiable (hg.prodMk_space hf) nonrec theorem MDifferentiableAt.clm_prodMap {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₄} {x : M} (hg : MDifferentiableAt I 𝓘(𝕜, F₁ →L[𝕜] F₃) g x) (hf : MDifferentiableAt I 𝓘(𝕜, F₂ →L[𝕜] F₄) f x) : MDifferentiableAt I 𝓘(𝕜, F₁ × F₂ →L[𝕜] F₃ × F₄) (fun x => (g x).prodMap (f x)) x := Differentiable.comp_mdifferentiableWithinAt (g := fun x : (F₁ →L[𝕜] F₃) × (F₂ →L[𝕜] F₄) => x.1.prodMap x.2) (f := fun x => (g x, f x)) (ContinuousLinearMap.prodMapL 𝕜 F₁ F₃ F₂ F₄).differentiable (hg.prodMk_space hf) theorem MDifferentiableOn.clm_prodMap {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₄} {s : Set M} (hg : MDifferentiableOn I 𝓘(𝕜, F₁ →L[𝕜] F₃) g s) (hf : MDifferentiableOn I 𝓘(𝕜, F₂ →L[𝕜] F₄) f s) : MDifferentiableOn I 𝓘(𝕜, F₁ × F₂ →L[𝕜] F₃ × F₄) (fun x => (g x).prodMap (f x)) s := fun x hx => (hg x hx).clm_prodMap (hf x hx) theorem MDifferentiable.clm_prodMap {g : M → F₁ →L[𝕜] F₃} {f : M → F₂ →L[𝕜] F₄} (hg : MDifferentiable I 𝓘(𝕜, F₁ →L[𝕜] F₃) g) (hf : MDifferentiable I 𝓘(𝕜, F₂ →L[𝕜] F₄) f) : MDifferentiable I 𝓘(𝕜, F₁ × F₂ →L[𝕜] F₃ × F₄) fun x => (g x).prodMap (f x) := fun x => (hg x).clm_prodMap (hf x) /-! ### Differentiability of scalar multiplication -/ variable {V : Type*} [NormedAddCommGroup V] [NormedSpace 𝕜 V] theorem MDifferentiableWithinAt.smul {f : M → 𝕜} {g : M → V} (hf : MDifferentiableWithinAt I 𝓘(𝕜) f s x) (hg : MDifferentiableWithinAt I 𝓘(𝕜, V) g s x) : MDifferentiableWithinAt I 𝓘(𝕜, V) (fun p => f p • g p) s x := ((contMDiff_smul.of_le le_top).mdifferentiable le_rfl _).comp_mdifferentiableWithinAt x (hf.prodMk hg) theorem MDifferentiableAt.smul {f : M → 𝕜} {g : M → V} (hf : MDifferentiableAt I 𝓘(𝕜) f x) (hg : MDifferentiableAt I 𝓘(𝕜, V) g x) : MDifferentiableAt I 𝓘(𝕜, V) (fun p => f p • g p) x := ((contMDiff_smul.of_le le_top).mdifferentiable le_rfl _).comp x (hf.prodMk hg) theorem MDifferentiableOn.smul {f : M → 𝕜} {g : M → V} (hf : MDifferentiableOn I 𝓘(𝕜) f s) (hg : MDifferentiableOn I 𝓘(𝕜, V) g s) : MDifferentiableOn I 𝓘(𝕜, V) (fun p => f p • g p) s := fun x hx => (hf x hx).smul (hg x hx) theorem MDifferentiable.smul {f : M → 𝕜} {g : M → V} (hf : MDifferentiable I 𝓘(𝕜) f) (hg : MDifferentiable I 𝓘(𝕜, V) g) : MDifferentiable I 𝓘(𝕜, V) fun p => f p • g p := fun x => (hf x).smul (hg x)
.lake/packages/mathlib/Mathlib/Geometry/Manifold/MFDeriv/FDeriv.lean
import Mathlib.Geometry.Manifold.MFDeriv.Basic /-! ### Relations between vector space derivative and manifold derivative The manifold derivative `mfderiv`, when considered on the model vector space with its trivial manifold structure, coincides with the usual Fréchet derivative `fderiv`. In this section, we prove this and related statements. -/ noncomputable section open scoped Manifold variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {f : E → E'} {s : Set E} {x : E} section MFDerivFDeriv theorem uniqueMDiffWithinAt_iff_uniqueDiffWithinAt : UniqueMDiffWithinAt 𝓘(𝕜, E) s x ↔ UniqueDiffWithinAt 𝕜 s x := by simp only [UniqueMDiffWithinAt, mfld_simps] alias ⟨UniqueMDiffWithinAt.uniqueDiffWithinAt, UniqueDiffWithinAt.uniqueMDiffWithinAt⟩ := uniqueMDiffWithinAt_iff_uniqueDiffWithinAt theorem uniqueMDiffOn_iff_uniqueDiffOn : UniqueMDiffOn 𝓘(𝕜, E) s ↔ UniqueDiffOn 𝕜 s := by simp [UniqueMDiffOn, UniqueDiffOn, uniqueMDiffWithinAt_iff_uniqueDiffWithinAt] alias ⟨UniqueMDiffOn.uniqueDiffOn, UniqueDiffOn.uniqueMDiffOn⟩ := uniqueMDiffOn_iff_uniqueDiffOn theorem ModelWithCorners.uniqueMDiffOn {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) : UniqueMDiffOn 𝓘(𝕜, E) (Set.range I) := I.uniqueDiffOn.uniqueMDiffOn @[simp, mfld_simps] theorem writtenInExtChartAt_model_space : writtenInExtChartAt 𝓘(𝕜, E) 𝓘(𝕜, E') x f = f := rfl theorem hasMFDerivWithinAt_iff_hasFDerivWithinAt {f'} : HasMFDerivWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x f' ↔ HasFDerivWithinAt f f' s x := by simpa only [HasMFDerivWithinAt, and_iff_right_iff_imp, mfld_simps] using HasFDerivWithinAt.continuousWithinAt alias ⟨HasMFDerivWithinAt.hasFDerivWithinAt, HasFDerivWithinAt.hasMFDerivWithinAt⟩ := hasMFDerivWithinAt_iff_hasFDerivWithinAt theorem hasMFDerivAt_iff_hasFDerivAt {f'} : HasMFDerivAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x f' ↔ HasFDerivAt f f' x := by rw [← hasMFDerivWithinAt_univ, hasMFDerivWithinAt_iff_hasFDerivWithinAt, hasFDerivWithinAt_univ] alias ⟨HasMFDerivAt.hasFDerivAt, HasFDerivAt.hasMFDerivAt⟩ := hasMFDerivAt_iff_hasFDerivAt /-- For maps between vector spaces, `MDifferentiableWithinAt` and `DifferentiableWithinAt` coincide -/ theorem mdifferentiableWithinAt_iff_differentiableWithinAt : MDifferentiableWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [mdifferentiableWithinAt_iff', mfld_simps] exact ⟨fun H => H.2, fun H => ⟨H.continuousWithinAt, H⟩⟩ alias ⟨MDifferentiableWithinAt.differentiableWithinAt, DifferentiableWithinAt.mdifferentiableWithinAt⟩ := mdifferentiableWithinAt_iff_differentiableWithinAt /-- For maps between vector spaces, `MDifferentiableAt` and `DifferentiableAt` coincide -/ theorem mdifferentiableAt_iff_differentiableAt : MDifferentiableAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x ↔ DifferentiableAt 𝕜 f x := by simp only [mdifferentiableAt_iff, differentiableWithinAt_univ, mfld_simps] exact ⟨fun H => H.2, fun H => ⟨H.continuousAt, H⟩⟩ alias ⟨MDifferentiableAt.differentiableAt, DifferentiableAt.mdifferentiableAt⟩ := mdifferentiableAt_iff_differentiableAt /-- For maps between vector spaces, `MDifferentiableOn` and `DifferentiableOn` coincide -/ theorem mdifferentiableOn_iff_differentiableOn : MDifferentiableOn 𝓘(𝕜, E) 𝓘(𝕜, E') f s ↔ DifferentiableOn 𝕜 f s := by simp only [MDifferentiableOn, DifferentiableOn, mdifferentiableWithinAt_iff_differentiableWithinAt] alias ⟨MDifferentiableOn.differentiableOn, DifferentiableOn.mdifferentiableOn⟩ := mdifferentiableOn_iff_differentiableOn /-- For maps between vector spaces, `MDifferentiable` and `Differentiable` coincide -/ theorem mdifferentiable_iff_differentiable : MDifferentiable 𝓘(𝕜, E) 𝓘(𝕜, E') f ↔ Differentiable 𝕜 f := by simp only [MDifferentiable, Differentiable, mdifferentiableAt_iff_differentiableAt] alias ⟨MDifferentiable.differentiable, Differentiable.mdifferentiable⟩ := mdifferentiable_iff_differentiable /-- For maps between vector spaces, `mfderivWithin` and `fderivWithin` coincide -/ @[simp] theorem mfderivWithin_eq_fderivWithin : mfderivWithin 𝓘(𝕜, E) 𝓘(𝕜, E') f s x = fderivWithin 𝕜 f s x := by by_cases h : MDifferentiableWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x · simp only [mfderivWithin, h, if_pos, mfld_simps] · simp only [mfderivWithin, h, if_neg, not_false_iff] rw [mdifferentiableWithinAt_iff_differentiableWithinAt] at h exact (fderivWithin_zero_of_not_differentiableWithinAt h).symm /-- For maps between vector spaces, `mfderiv` and `fderiv` coincide -/ @[simp] theorem mfderiv_eq_fderiv : mfderiv 𝓘(𝕜, E) 𝓘(𝕜, E') f x = fderiv 𝕜 f x := by rw [← mfderivWithin_univ, ← fderivWithin_univ] exact mfderivWithin_eq_fderivWithin end MFDerivFDeriv
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorField/LieBracket.lean
import Mathlib.Analysis.Calculus.VectorField import Mathlib.Geometry.Manifold.ContMDiffMFDeriv import Mathlib.Geometry.Manifold.MFDeriv.NormedSpace import Mathlib.Geometry.Manifold.VectorBundle.MDifferentiable import Mathlib.Geometry.Manifold.VectorField.Pullback /-! # Lie brackets of vector fields on manifolds We define the Lie bracket of two vector fields, denoted with `VectorField.mlieBracket I V W x`, as the pullback in the manifold of the corresponding notion in the model space (through `extChartAt I x`). The main results are the following: * `VectorField.mpullback_mlieBracket` states that the pullback of the Lie bracket is the Lie bracket of the pullbacks. * `VectorField.leibniz_identity_mlieBracket` is the Leibniz (or Jacobi) identity `[U, [V, W]] = [[U, V], W] + [V, [U, W]]`. -/ open Set Function Filter open scoped Topology Manifold ContDiff noncomputable section /- We work in the `VectorField` namespace because pullbacks, Lie brackets, and so on, are notions that make sense in a variety of contexts. We also prefix the notions with `m` to distinguish the manifold notions from the vector spaces notions. For instance, the Lie bracket of two vector fields in a manifold is denoted with `VectorField.mlieBracket I V W x`, where `I` is the relevant model with corners, `V W : Π (x : M), TangentSpace I x` are the vector fields, and `x : M` is the basepoint. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {H' : Type*} [TopologicalSpace H'] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {H'' : Type*} [TopologicalSpace H''] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] {f : M → M'} {s t : Set M} {x x₀ : M} namespace VectorField section LieBracket /-! ### The Lie bracket of vector fields in manifolds -/ variable {V W V₁ W₁ : Π (x : M), TangentSpace I x} variable (I I') in /-- The Lie bracket of two vector fields in a manifold, within a set. -/ def mlieBracketWithin (V W : Π (x : M), TangentSpace I x) (s : Set M) (x₀ : M) : TangentSpace I x₀ := mpullback I 𝓘(𝕜, E) (extChartAt I x₀) (lieBracketWithin 𝕜 (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm V (range I)) (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm W (range I)) ((extChartAt I x₀).symm ⁻¹' s ∩ range I)) x₀ variable (I I') in /-- The Lie bracket of two vector fields in a manifold. -/ def mlieBracket (V W : Π (x : M), TangentSpace I x) (x₀ : M) : TangentSpace I x₀ := mlieBracketWithin I V W univ x₀ lemma mlieBracketWithin_def : mlieBracketWithin I V W s = fun x₀ ↦ mpullback I 𝓘(𝕜, E) (extChartAt I x₀) (lieBracketWithin 𝕜 (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm V (range I)) (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm W (range I)) ((extChartAt I x₀).symm ⁻¹' s ∩ range I)) x₀ := rfl lemma mlieBracketWithin_apply : mlieBracketWithin I V W s x₀ = (mfderiv I 𝓘(𝕜, E) (extChartAt I x₀) x₀).inverse ((lieBracketWithin 𝕜 (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm V (range I)) (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm W (range I)) ((extChartAt I x₀).symm ⁻¹' s ∩ range I)) ((extChartAt I x₀ x₀))) := rfl lemma mlieBracketWithin_eq_lieBracketWithin {V W : Π (x : E), TangentSpace 𝓘(𝕜, E) x} {s : Set E} : mlieBracketWithin 𝓘(𝕜, E) V W s = lieBracketWithin 𝕜 V W s := by ext x simp [mlieBracketWithin_apply] /- Copy of the `lieBracket` API to manifolds -/ @[simp] lemma mlieBracketWithin_univ : mlieBracketWithin I V W univ = mlieBracket I V W := rfl lemma mlieBracketWithin_eq_zero_of_eq_zero (hV : V x = 0) (hW : W x = 0) : mlieBracketWithin I V W s x = 0 := by simp only [mlieBracketWithin, mpullback_apply] rw [lieBracketWithin_eq_zero_of_eq_zero] · simp · simp only [mpullbackWithin_apply] have : (extChartAt I x).symm ((extChartAt I x) x) = x := by simp rw [this, hV] simp · simp only [mpullbackWithin_apply] have : (extChartAt I x).symm ((extChartAt I x) x) = x := by simp rw [this, hW] simp lemma mlieBracketWithin_swap_apply : mlieBracketWithin I V W s x = - mlieBracketWithin I W V s x := by rw [mlieBracketWithin, lieBracketWithin_swap, mpullback_neg] rfl lemma mlieBracketWithin_swap : mlieBracketWithin I V W s = - mlieBracketWithin I W V s := by ext x exact mlieBracketWithin_swap_apply lemma mlieBracket_swap_apply : mlieBracket I V W x = - mlieBracket I W V x := mlieBracketWithin_swap_apply lemma mlieBracket_swap : mlieBracket I V W = - mlieBracket I W V := mlieBracketWithin_swap @[simp] lemma mlieBracketWithin_self : mlieBracketWithin I V V = 0 := by ext x; simp [mlieBracketWithin, mpullback] @[simp] lemma mlieBracket_self : mlieBracket I V V = 0 := by ext x; simp_rw [mlieBracket, mlieBracketWithin_self, Pi.zero_apply] /-- We have `[0, W] = 0` for all vector fields `W`: this depends on the junk value 0 if `W` is not differentiable. Version within a set. -/ @[simp] lemma mlieBracketWithin_zero_left : mlieBracketWithin I 0 W s = 0 := by ext x simp [mlieBracketWithin] /-- We have `[W, 0] = 0` for all vector fields `W`: this depends on the junk value 0 if `W` is not differentiable. Version within a set. -/ @[simp] lemma mlieBracketWithin_zero_right : mlieBracketWithin I W 0 s = 0 := by rw [mlieBracketWithin_swap]; simp /-- We have `[0, W] = 0` for all vector fields `W`: this depends on the junk value 0 if `W` is not differentiable. -/ @[simp] lemma mlieBracket_zero_left : mlieBracket I 0 W = 0 := by simp [← mlieBracketWithin_univ] /-- We have `[W, 0] = 0` for all vector fields `W`: this depends on the junk value 0 if `W` is not differentiable. -/ @[simp] lemma mlieBracket_zero_right : mlieBracket I W 0 = 0 := by simp [← mlieBracketWithin_univ] /-- Variant of `mlieBracketWithin_congr_set` where one requires the sets to coincide only in the complement of a point. -/ theorem mlieBracketWithin_congr_set' (y : M) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : mlieBracketWithin I V W s x = mlieBracketWithin I V W t x := by simp only [mlieBracketWithin_apply] congr 1 suffices A : ((extChartAt I x).symm ⁻¹' s ∩ range I : Set E) =ᶠ[𝓝[{(extChartAt I x) x}ᶜ] (extChartAt I x x)] ((extChartAt I x).symm ⁻¹' t ∩ range I : Set E) by apply lieBracketWithin_congr_set' _ A exact preimage_extChartAt_eventuallyEq_compl_singleton y h theorem mlieBracketWithin_congr_set (h : s =ᶠ[𝓝 x] t) : mlieBracketWithin I V W s x = mlieBracketWithin I V W t x := mlieBracketWithin_congr_set' x <| h.filter_mono inf_le_left theorem mlieBracketWithin_inter (ht : t ∈ 𝓝 x) : mlieBracketWithin I V W (s ∩ t) x = mlieBracketWithin I V W s x := by apply mlieBracketWithin_congr_set filter_upwards [ht] with y hy change (y ∈ s ∩ t) = (y ∈ s) simp_all theorem mlieBracketWithin_of_mem_nhds (h : s ∈ 𝓝 x) : mlieBracketWithin I V W s x = mlieBracket I V W x := by rw [← mlieBracketWithin_univ, ← univ_inter s, mlieBracketWithin_inter h] theorem mlieBracketWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : mlieBracketWithin I V W s x = mlieBracket I V W x := mlieBracketWithin_of_mem_nhds (hs.mem_nhds hx) /-- Variant of `mlieBracketWithin_eventually_congr_set` where one requires the sets to coincide only in the complement of a point. -/ theorem mlieBracketWithin_eventually_congr_set' (y : M) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : mlieBracketWithin I V W s =ᶠ[𝓝 x] mlieBracketWithin I V W t := (eventually_nhds_nhdsWithin.2 h).mono fun _ => mlieBracketWithin_congr_set' y theorem mlieBracketWithin_eventually_congr_set (h : s =ᶠ[𝓝 x] t) : mlieBracketWithin I V W s =ᶠ[𝓝 x] mlieBracketWithin I V W t := mlieBracketWithin_eventually_congr_set' x <| h.filter_mono inf_le_left theorem _root_.Filter.EventuallyEq.mlieBracketWithin_vectorField_eq (hV : V₁ =ᶠ[𝓝[s] x] V) (hxV : V₁ x = V x) (hW : W₁ =ᶠ[𝓝[s] x] W) (hxW : W₁ x = W x) : mlieBracketWithin I V₁ W₁ s x = mlieBracketWithin I V W s x := by simp only [mlieBracketWithin_apply] congr 1 let I1 : NormedAddCommGroup (TangentSpace 𝓘(𝕜, E) (extChartAt I x x)) := inferInstanceAs (NormedAddCommGroup E) let _I2 : NormedSpace 𝕜 (TangentSpace 𝓘(𝕜, E) (extChartAt I x x)) := inferInstanceAs (NormedSpace 𝕜 E) apply Filter.EventuallyEq.lieBracketWithin_vectorField_eq · apply nhdsWithin_mono _ inter_subset_left filter_upwards [(continuousAt_extChartAt_symm x).continuousWithinAt.preimage_mem_nhdsWithin'' hV (by simp)] with y hy simp only [mpullbackWithin_apply] congr 1 · simp only [mpullbackWithin_apply] congr 1 convert hxV <;> exact extChartAt_to_inv x · apply nhdsWithin_mono _ inter_subset_left filter_upwards [(continuousAt_extChartAt_symm x).continuousWithinAt.preimage_mem_nhdsWithin'' hW (by simp)] with y hy simp only [mpullbackWithin_apply] congr 1 · simp only [mpullbackWithin_apply] congr 1 convert hxW <;> exact extChartAt_to_inv x theorem _root_.Filter.EventuallyEq.mlieBracketWithin_vectorField_eq_of_mem (hV : V₁ =ᶠ[𝓝[s] x] V) (hW : W₁ =ᶠ[𝓝[s] x] W) (hx : x ∈ s) : mlieBracketWithin I V₁ W₁ s x = mlieBracketWithin I V W s x := hV.mlieBracketWithin_vectorField_eq (mem_of_mem_nhdsWithin hx hV :) hW (mem_of_mem_nhdsWithin hx hW :) /-- If vector fields coincide on a neighborhood of a point within a set, then the Lie brackets also coincide on a neighborhood of this point within this set. Version where one considers the Lie bracket within a subset. -/ theorem _root_.Filter.EventuallyEq.mlieBracketWithin_vectorField' (hV : V₁ =ᶠ[𝓝[s] x] V) (hW : W₁ =ᶠ[𝓝[s] x] W) (ht : t ⊆ s) : mlieBracketWithin I V₁ W₁ t =ᶠ[𝓝[s] x] mlieBracketWithin I V W t := by filter_upwards [hV, hW, eventually_eventually_nhdsWithin.2 hV, eventually_eventually_nhdsWithin.2 hW] with y hVy hWy hVy' hWy' apply Filter.EventuallyEq.mlieBracketWithin_vectorField_eq · apply nhdsWithin_mono _ ht exact hVy' · exact hVy · apply nhdsWithin_mono _ ht exact hWy' · exact hWy protected theorem _root_.Filter.EventuallyEq.mlieBracketWithin_vectorField (hV : V₁ =ᶠ[𝓝[s] x] V) (hW : W₁ =ᶠ[𝓝[s] x] W) : mlieBracketWithin I V₁ W₁ s =ᶠ[𝓝[s] x] mlieBracketWithin I V W s := hV.mlieBracketWithin_vectorField' hW Subset.rfl protected theorem _root_.Filter.EventuallyEq.mlieBracketWithin_vectorField_of_insert (hV : V₁ =ᶠ[𝓝[insert x s] x] V) (hW : W₁ =ᶠ[𝓝[insert x s] x] W) : mlieBracketWithin I V₁ W₁ s x = mlieBracketWithin I V W s x := by apply mem_of_mem_nhdsWithin (mem_insert x s) (hV.mlieBracketWithin_vectorField' hW (subset_insert x s)) theorem _root_.Filter.EventuallyEq.mlieBracketWithin_vectorField_eq_nhds (hV : V₁ =ᶠ[𝓝 x] V) (hW : W₁ =ᶠ[𝓝 x] W) : mlieBracketWithin I V₁ W₁ s x = mlieBracketWithin I V W s x := (hV.filter_mono nhdsWithin_le_nhds).mlieBracketWithin_vectorField_eq hV.self_of_nhds (hW.filter_mono nhdsWithin_le_nhds) hW.self_of_nhds theorem mlieBracketWithin_congr (hV : EqOn V₁ V s) (hVx : V₁ x = V x) (hW : EqOn W₁ W s) (hWx : W₁ x = W x) : mlieBracketWithin I V₁ W₁ s x = mlieBracketWithin I V W s x := (hV.eventuallyEq.filter_mono inf_le_right).mlieBracketWithin_vectorField_eq hVx (hW.eventuallyEq.filter_mono inf_le_right) hWx /-- Version of `mlieBracketWithin_congr` in which one assumes that the point belongs to the given set. -/ theorem mlieBracketWithin_congr' (hV : EqOn V₁ V s) (hW : EqOn W₁ W s) (hx : x ∈ s) : mlieBracketWithin I V₁ W₁ s x = mlieBracketWithin I V W s x := mlieBracketWithin_congr hV (hV hx) hW (hW hx) theorem _root_.Filter.EventuallyEq.mlieBracket_vectorField_eq (hV : V₁ =ᶠ[𝓝 x] V) (hW : W₁ =ᶠ[𝓝 x] W) : mlieBracket I V₁ W₁ x = mlieBracket I V W x := by rw [← mlieBracketWithin_univ, ← mlieBracketWithin_univ, hV.mlieBracketWithin_vectorField_eq_nhds hW] protected theorem _root_.Filter.EventuallyEq.mlieBracket_vectorField (hV : V₁ =ᶠ[𝓝 x] V) (hW : W₁ =ᶠ[𝓝 x] W) : mlieBracket I V₁ W₁ =ᶠ[𝓝 x] mlieBracket I V W := by filter_upwards [hV.eventuallyEq_nhds, hW.eventuallyEq_nhds] with y hVy hWy exact hVy.mlieBracket_vectorField_eq hWy section variable {c : 𝕜} variable [IsManifold I 2 M] [CompleteSpace E] lemma _root_.MDifferentiableWithinAt.differentiableWithinAt_mpullbackWithin_vectorField (hV : MDifferentiableWithinAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) s x) : DifferentiableWithinAt 𝕜 (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm V (range I)) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by apply MDifferentiableWithinAt.differentiableWithinAt have := MDifferentiableWithinAt.mpullbackWithin_vectorField_inter_of_eq hV (contMDiffWithinAt_extChartAt_symm_range x (mem_extChartAt_target x)) (isInvertible_mfderivWithin_extChartAt_symm (mem_extChartAt_target x)) (mem_range_self _) I.uniqueMDiffOn le_rfl (extChartAt_to_inv x).symm rw [inter_comm] exact ((contMDiff_snd_tangentBundle_modelSpace E 𝓘(𝕜, E)).contMDiffAt.mdifferentiableAt le_rfl).comp_mdifferentiableWithinAt _ this lemma mlieBracketWithin_const_smul_left (hV : MDifferentiableWithinAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) s x) (hs : UniqueMDiffWithinAt I s x) : mlieBracketWithin I (c • V) W s x = c • mlieBracketWithin I V W s x := by simp only [mlieBracketWithin_apply] rw [← ContinuousLinearMap.map_smul, mpullbackWithin_smul, lieBracketWithin_const_smul_left] · exact hV.differentiableWithinAt_mpullbackWithin_vectorField · exact uniqueMDiffWithinAt_iff_inter_range.1 hs @[deprecated (since := "2025-07-04")] alias mlieBracketWithin_smul_left := mlieBracketWithin_const_smul_left lemma mlieBracket_const_smul_left (hV : MDifferentiableAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) x) : mlieBracket I (c • V) W x = c • mlieBracket I V W x := by simp only [← mlieBracketWithin_univ] at hV ⊢ exact mlieBracketWithin_const_smul_left hV (uniqueMDiffWithinAt_univ _) @[deprecated (since := "2025-07-04")] alias mlieBracket_smul_left := mlieBracket_const_smul_left lemma mlieBracketWithin_const_smul_right (hW : MDifferentiableWithinAt I I.tangent (fun x ↦ (W x : TangentBundle I M)) s x) (hs : UniqueMDiffWithinAt I s x) : mlieBracketWithin I V (c • W) s x = c • mlieBracketWithin I V W s x := by simp only [mlieBracketWithin_apply] rw [← ContinuousLinearMap.map_smul, mpullbackWithin_smul, lieBracketWithin_const_smul_right] · exact hW.differentiableWithinAt_mpullbackWithin_vectorField · exact uniqueMDiffWithinAt_iff_inter_range.1 hs @[deprecated (since := "2025-07-04")] alias mlieBracketWithin_smul_right := mlieBracketWithin_const_smul_right lemma mlieBracket_const_smul_right (hW : MDifferentiableAt I I.tangent (fun x ↦ (W x : TangentBundle I M)) x) : mlieBracket I V (c • W) x = c • mlieBracket I V W x := by simp only [← mlieBracketWithin_univ] at hW ⊢ exact mlieBracketWithin_const_smul_right hW (uniqueMDiffWithinAt_univ _) @[deprecated (since := "2025-07-04")] alias mlieBracket_smul_right := mlieBracket_const_smul_right lemma mlieBracketWithin_add_left (hV : MDifferentiableWithinAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) s x) (hV₁ : MDifferentiableWithinAt I I.tangent (fun x ↦ (V₁ x : TangentBundle I M)) s x) (hs : UniqueMDiffWithinAt I s x) : mlieBracketWithin I (V + V₁) W s x = mlieBracketWithin I V W s x + mlieBracketWithin I V₁ W s x := by simp only [mlieBracketWithin_apply] rw [← ContinuousLinearMap.map_add, mpullbackWithin_add, lieBracketWithin_add_left] · exact hV.differentiableWithinAt_mpullbackWithin_vectorField · exact hV₁.differentiableWithinAt_mpullbackWithin_vectorField · exact uniqueMDiffWithinAt_iff_inter_range.1 hs lemma mlieBracket_add_left (hV : MDifferentiableAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) x) (hV₁ : MDifferentiableAt I I.tangent (fun x ↦ (V₁ x : TangentBundle I M)) x) : mlieBracket I (V + V₁) W x = mlieBracket I V W x + mlieBracket I V₁ W x := by simp only [← mlieBracketWithin_univ] at hV hV₁ ⊢ exact mlieBracketWithin_add_left hV hV₁ (uniqueMDiffWithinAt_univ _) lemma mlieBracketWithin_add_right (hW : MDifferentiableWithinAt I I.tangent (fun x ↦ (W x : TangentBundle I M)) s x) (hW₁ : MDifferentiableWithinAt I I.tangent (fun x ↦ (W₁ x : TangentBundle I M)) s x) (hs : UniqueMDiffWithinAt I s x) : mlieBracketWithin I V (W + W₁) s x = mlieBracketWithin I V W s x + mlieBracketWithin I V W₁ s x := by rw [mlieBracketWithin_swap, Pi.neg_apply, mlieBracketWithin_add_left hW hW₁ hs, mlieBracketWithin_swap (V := V), mlieBracketWithin_swap (V := V), Pi.neg_apply, Pi.neg_apply] abel lemma mlieBracket_add_right (hW : MDifferentiableAt I I.tangent (fun x ↦ (W x : TangentBundle I M)) x) (hW₁ : MDifferentiableAt I I.tangent (fun x ↦ (W₁ x : TangentBundle I M)) x) : mlieBracket I V (W + W₁) x = mlieBracket I V W x + mlieBracket I V W₁ x := by simp only [← mlieBracketWithin_univ] at hW hW₁ ⊢ exact mlieBracketWithin_add_right hW hW₁ (uniqueMDiffWithinAt_univ _) theorem mlieBracketWithin_of_mem_nhdsWithin (st : t ∈ 𝓝[s] x) (hs : UniqueMDiffWithinAt I s x) (hV : MDifferentiableWithinAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) t x) (hW : MDifferentiableWithinAt I I.tangent (fun x ↦ (W x : TangentBundle I M)) t x) : mlieBracketWithin I V W s x = mlieBracketWithin I V W t x := by simp only [mlieBracketWithin_apply] congr 1 rw [lieBracketWithin_of_mem_nhdsWithin] · apply Filter.inter_mem · apply nhdsWithin_mono _ inter_subset_left exact (continuousAt_extChartAt_symm x).continuousWithinAt.preimage_mem_nhdsWithin'' st (by simp) · exact nhdsWithin_mono _ inter_subset_right self_mem_nhdsWithin · exact uniqueMDiffWithinAt_iff_inter_range.1 hs · exact hV.differentiableWithinAt_mpullbackWithin_vectorField · exact hW.differentiableWithinAt_mpullbackWithin_vectorField theorem mlieBracketWithin_subset (st : s ⊆ t) (ht : UniqueMDiffWithinAt I s x) (hV : MDifferentiableWithinAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) t x) (hW : MDifferentiableWithinAt I I.tangent (fun x ↦ (W x : TangentBundle I M)) t x) : mlieBracketWithin I V W s x = mlieBracketWithin I V W t x := mlieBracketWithin_of_mem_nhdsWithin (nhdsWithin_mono _ st self_mem_nhdsWithin) ht hV hW theorem mlieBracketWithin_eq_mlieBracket (hs : UniqueMDiffWithinAt I s x) (hV : MDifferentiableAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) x) (hW : MDifferentiableAt I I.tangent (fun x ↦ (W x : TangentBundle I M)) x) : mlieBracketWithin I V W s x = mlieBracket I V W x := by simp only [← mlieBracketWithin_univ, ← mdifferentiableWithinAt_univ] at hV hW ⊢ exact mlieBracketWithin_subset (subset_univ _) hs hV hW theorem _root_.DifferentiableWithinAt.mlieBracketWithin_congr_mono (hV : MDifferentiableWithinAt I I.tangent (fun x ↦ (V x : TangentBundle I M)) s x) (hVs : EqOn V₁ V t) (hVx : V₁ x = V x) (hW : MDifferentiableWithinAt I I.tangent (fun x ↦ (W x : TangentBundle I M)) s x) (hWs : EqOn W₁ W t) (hWx : W₁ x = W x) (hxt : UniqueMDiffWithinAt I t x) (h₁ : t ⊆ s) : mlieBracketWithin I V₁ W₁ t x = mlieBracketWithin I V W s x := by rw [mlieBracketWithin_congr hVs hVx hWs hWx] exact mlieBracketWithin_subset h₁ hxt hV hW end section Invariance_IsSymmSndFDerivWithinAt variable [IsManifold I 2 M] [IsManifold I' 2 M'] [CompleteSpace E] /- The Lie bracket of vector fields on manifolds is well defined, i.e., it is invariant under diffeomorphisms. Auxiliary version where one assumes that all relevant sets are contained in chart domains. -/ private lemma mpullbackWithin_mlieBracketWithin_aux [CompleteSpace E'] {f : M → M'} {V W : Π (x : M'), TangentSpace I' x} {x₀ : M} {s : Set M} {t : Set M'} (hV : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (V x : TangentBundle I' M')) t (f x₀)) (hW : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (W x : TangentBundle I' M')) t (f x₀)) (hu : UniqueMDiffOn I s) (hf : ContMDiffOn I I' 2 f s) (hx₀ : x₀ ∈ s) (ht : t ⊆ (extChartAt I' (f x₀)).source) (hst : MapsTo f s t) (hsymm : IsSymmSndFDerivWithinAt 𝕜 ((extChartAt I' (f x₀)) ∘ f ∘ (extChartAt I x₀).symm) ((extChartAt I x₀).symm ⁻¹' s ∩ range I) (extChartAt I x₀ x₀)) : mpullbackWithin I I' f (mlieBracketWithin I' V W t) s x₀ = mlieBracketWithin I (mpullbackWithin I I' f V s) (mpullbackWithin I I' f W s) s x₀ := by have A : (extChartAt I x₀).symm (extChartAt I x₀ x₀) = x₀ := by simp have A' : x₀ = (extChartAt I x₀).symm (extChartAt I x₀ x₀) := by simp have h'f : MDifferentiableWithinAt I I' f s x₀ := (hf x₀ hx₀).mdifferentiableWithinAt one_le_two simp only [mlieBracketWithin_apply, mpullbackWithin_apply] -- first, rewrite the pullback of the Lie bracket as a pullback in `E` under the map -- `F = extChartAt I' (f x₀) ∘ f ∘ (extChartAt I x₀).symm` of a Lie bracket computed in `E'`, -- of two vector fields `V'` and `W'`. rw [← ContinuousLinearMap.IsInvertible.inverse_comp_apply_of_left (isInvertible_mfderiv_extChartAt (mem_extChartAt_source (f x₀)))] rw [← mfderiv_comp_mfderivWithin _ (mdifferentiableAt_extChartAt (ChartedSpace.mem_chart_source (f x₀))) h'f (hu x₀ hx₀)] rw [eq_comm, (isInvertible_mfderiv_extChartAt (mem_extChartAt_source x₀)).inverse_apply_eq] have : (mfderivWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm (range I) (extChartAt I x₀ x₀)).inverse = mfderiv I 𝓘(𝕜, E) (extChartAt I x₀) x₀ := by apply ContinuousLinearMap.inverse_eq · convert mfderivWithin_extChartAt_symm_comp_mfderiv_extChartAt (I := I) (x := x₀) (y := extChartAt I x₀ x₀) (by simp) · convert mfderiv_extChartAt_comp_mfderivWithin_extChartAt_symm (I := I) (x := x₀) (y := extChartAt I x₀ x₀) (by simp) rw [← this, ← ContinuousLinearMap.IsInvertible.inverse_comp_apply_of_right]; swap · exact isInvertible_mfderivWithin_extChartAt_symm (mem_extChartAt_target x₀) have : mfderivWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm (range I) (extChartAt I x₀ x₀) = mfderivWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm ((extChartAt I x₀).symm ⁻¹' s ∩ range I) (extChartAt I x₀ x₀) := (MDifferentiableWithinAt.mfderivWithin_mono (mdifferentiableWithinAt_extChartAt_symm (mem_extChartAt_target x₀)) (UniqueDiffWithinAt.uniqueMDiffWithinAt (hu x₀ hx₀)) inter_subset_right).symm rw [this]; clear this rw [← mfderivWithin_comp_of_eq]; rotate_left · apply MDifferentiableAt.comp_mdifferentiableWithinAt (I' := I') _ _ h'f exact mdifferentiableAt_extChartAt (ChartedSpace.mem_chart_source (f x₀)) · exact (mdifferentiableWithinAt_extChartAt_symm (mem_extChartAt_target x₀)).mono inter_subset_right · exact inter_subset_left · exact UniqueDiffWithinAt.uniqueMDiffWithinAt (hu x₀ hx₀) · simp set V' := mpullbackWithin 𝓘(𝕜, E') I' (extChartAt I' (f x₀)).symm V (range I') with hV' set W' := mpullbackWithin 𝓘(𝕜, E') I' (extChartAt I' (f x₀)).symm W (range I') with hW' set F := ((extChartAt I' (f x₀)) ∘ f) ∘ ↑(extChartAt I x₀).symm with hF have hFx₀ : extChartAt I' (f x₀) (f x₀) = F (extChartAt I x₀ x₀) := by simp [F] rw [hFx₀, ← mpullbackWithin_apply] -- second rewrite, the Lie bracket of the pullback as the Lie bracket of the pullback of the -- vector fields `V'` and `W'` in `E'`. have P (Y : (x : M') → TangentSpace I' x) : (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x₀).symm (mpullbackWithin I I' f Y s) (range I)) =ᶠ[𝓝[(extChartAt I x₀).symm ⁻¹' s ∩ range I] (extChartAt I x₀ x₀)] mpullbackWithin 𝓘(𝕜, E) 𝓘(𝕜, E') F (mpullbackWithin 𝓘(𝕜, E') I' ((extChartAt I' (f x₀)).symm) Y (range I')) ((extChartAt I x₀).symm ⁻¹' s ∩ range I) := by have : (extChartAt I x₀).target ∈ 𝓝[(extChartAt I x₀).symm ⁻¹' s ∩ range I] (extChartAt I x₀ x₀) := nhdsWithin_mono _ inter_subset_right (extChartAt_target_mem_nhdsWithin x₀) filter_upwards [self_mem_nhdsWithin, this] with y hy h'''y have h'y : f ((extChartAt I x₀).symm y) ∈ (extChartAt I' (f x₀)).source := ht (hst hy.1) have h''y : f ((extChartAt I x₀).symm y) ∈ (chartAt H' (f x₀)).source := by simpa using h'y have huy : UniqueMDiffWithinAt 𝓘(𝕜, E) ((extChartAt I x₀).symm ⁻¹' s ∩ range I) y := by apply UniqueDiffWithinAt.uniqueMDiffWithinAt rw [inter_comm] apply hu.uniqueDiffWithinAt_range_inter exact ⟨h'''y, hy.1⟩ simp only [mpullbackWithin_apply, hF, comp_apply] rw [mfderivWithin_comp (I' := I) (u := s)]; rotate_left · apply (mdifferentiableAt_extChartAt h''y).comp_mdifferentiableWithinAt (I' := I') exact (hf _ hy.1).mdifferentiableWithinAt one_le_two · exact (mdifferentiableWithinAt_extChartAt_symm h'''y).mono inter_subset_right · exact inter_subset_left · exact huy rw [mfderiv_comp_mfderivWithin (I' := I')]; rotate_left · exact mdifferentiableAt_extChartAt h''y · exact (hf _ hy.1).mdifferentiableWithinAt one_le_two · exact hu _ hy.1 rw [← ContinuousLinearMap.IsInvertible.inverse_comp_apply_of_right]; swap · exact isInvertible_mfderivWithin_extChartAt_symm h'''y rw [← ContinuousLinearMap.IsInvertible.inverse_comp_apply_of_left]; swap · exact isInvertible_mfderivWithin_extChartAt_symm (PartialEquiv.map_source _ h'y) have : f ((extChartAt I x₀).symm y) = (extChartAt I' (f x₀)).symm ((extChartAt I' (f x₀)) (f ((extChartAt I x₀).symm y))) := (PartialEquiv.left_inv (extChartAt I' (f x₀)) h'y).symm congr 2 have : (mfderivWithin 𝓘(𝕜, E') I' ((extChartAt I' (f x₀)).symm) (range I') (extChartAt I' (f x₀) (f ((extChartAt I x₀).symm y)))) ∘L (mfderiv I' 𝓘(𝕜, E') (↑(extChartAt I' (f x₀))) (f ((extChartAt I x₀).symm y))) = ContinuousLinearMap.id _ _ := by convert mfderivWithin_extChartAt_symm_comp_mfderiv_extChartAt ((PartialEquiv.map_source _ h'y)) simp only [← ContinuousLinearMap.comp_assoc, this, ContinuousLinearMap.id_comp] congr 1 exact ((mdifferentiableWithinAt_extChartAt_symm h'''y).mfderivWithin_mono huy inter_subset_right).symm rw [Filter.EventuallyEq.lieBracketWithin_vectorField_eq_of_mem (P V) (P W) (by simp [hx₀]), ← hV', ← hW'] simp only [mpullbackWithin_eq_pullbackWithin] -- finally, use the fact that for `C^2` maps between vector spaces with symmetric second -- derivative, the pullback and the Lie bracket commute. rw [pullbackWithin_lieBracketWithin_of_isSymmSndFDerivWithinAt_of_eventuallyEq (u := (extChartAt I x₀).symm ⁻¹' s ∩ (extChartAt I x₀).target)] · exact hsymm · rw [hF, comp_assoc] apply ContMDiffWithinAt.contDiffWithinAt apply ContMDiffAt.comp_contMDiffWithinAt (I' := I') · exact contMDiffAt_extChartAt' (by simp) apply ContMDiffWithinAt.comp_of_eq (I' := I) (hf _ hx₀) _ _ A · exact (contMDiffWithinAt_extChartAt_symm_range _ (mem_extChartAt_target x₀)).mono inter_subset_right · exact (mapsTo_preimage _ _).mono_left inter_subset_left · rw [← hFx₀] exact hV.differentiableWithinAt_mpullbackWithin_vectorField · rw [← hFx₀] exact hW.differentiableWithinAt_mpullbackWithin_vectorField · rw [inter_comm] exact UniqueMDiffOn.uniqueDiffOn_target_inter hu x₀ · simp [hx₀] · intro z hz simp only [comp_apply, mem_inter_iff, mem_preimage, mem_range, F] refine ⟨?_, mem_range_self _⟩ convert hst hz.1 exact PartialEquiv.left_inv (extChartAt I' (f x₀)) (ht (hst hz.1)) · rw [← nhdsWithin_eq_iff_eventuallyEq] apply le_antisymm · exact nhdsWithin_mono _ (inter_subset_inter_right _ (extChartAt_target_subset_range x₀)) · rw [nhdsWithin_le_iff, nhdsWithin_inter] exact Filter.inter_mem_inf self_mem_nhdsWithin (extChartAt_target_mem_nhdsWithin x₀) /- The Lie bracket of vector fields on manifolds is well defined, i.e., it is invariant under diffeomorphisms. -/ lemma mpullbackWithin_mlieBracketWithin_of_isSymmSndFDerivWithinAt {f : M → M'} {V W : Π (x : M'), TangentSpace I' x} {x₀ : M} {s : Set M} {t : Set M'} (hV : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (V x : TangentBundle I' M')) t (f x₀)) (hW : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (W x : TangentBundle I' M')) t (f x₀)) (hu : UniqueMDiffOn I s) (hf : ContMDiffWithinAt I I' 2 f s x₀) (hx₀ : x₀ ∈ s) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) (hsymm : IsSymmSndFDerivWithinAt 𝕜 ((extChartAt I' (f x₀)) ∘ f ∘ (extChartAt I x₀).symm) ((extChartAt I x₀).symm ⁻¹' s ∩ range I) (extChartAt I x₀ x₀)) : mpullbackWithin I I' f (mlieBracketWithin I' V W t) s x₀ = mlieBracketWithin I (mpullbackWithin I I' f V s) (mpullbackWithin I I' f W s) s x₀ := by have A : (extChartAt I x₀).symm (extChartAt I x₀ x₀) = x₀ := by simp by_cases hfi : (mfderivWithin I I' f s x₀).IsInvertible; swap · simp only [mlieBracketWithin_apply, mpullbackWithin_apply, ContinuousLinearMap.inverse_of_not_isInvertible hfi, ContinuousLinearMap.zero_apply] rw [lieBracketWithin_eq_zero_of_eq_zero] · simp [-extChartAt] · simp only [mpullbackWithin_apply] rw [A, ContinuousLinearMap.inverse_of_not_isInvertible hfi] simp [-extChartAt] · simp only [mpullbackWithin_apply] rw [A, ContinuousLinearMap.inverse_of_not_isInvertible hfi] simp [-extChartAt] -- Now, interesting case where the derivative of `f` is invertible have : CompleteSpace E' := by rcases hfi with ⟨M, -⟩ let M' : E ≃L[𝕜] E' := M exact (completeSpace_congr (e := M'.toEquiv) M'.isUniformEmbedding).1 (by assumption) -- choose a small open set `v` around `x₀` where `f` is `C^2` obtain ⟨u, u_open, x₀u, ut, maps_u, u_smooth⟩ : ∃ u, IsOpen u ∧ x₀ ∈ u ∧ s ∩ u ⊆ f ⁻¹' t ∧ s ∩ u ⊆ f ⁻¹' (extChartAt I' (f x₀)).source ∧ ContMDiffOn I I' 2 f (s ∩ u) := by obtain ⟨u, u_open, x₀u, hu⟩ : ∃ u, IsOpen u ∧ x₀ ∈ u ∧ ContMDiffOn I I' 2 f (insert x₀ s ∩ u) := hf.contMDiffOn' le_rfl (by simp) have : f ⁻¹' (extChartAt I' (f x₀)).source ∈ 𝓝[s] x₀ := hf.continuousWithinAt.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds (f x₀)) rcases mem_nhdsWithin.1 (Filter.inter_mem hst this) with ⟨w, w_open, x₀w, hw⟩ refine ⟨u ∩ w, u_open.inter w_open, by simp [x₀u, x₀w], ?_, ?_, ?_⟩ · apply Subset.trans _ (hw.trans inter_subset_left) exact fun y hy ↦ ⟨hy.2.2, hy.1⟩ · apply Subset.trans _ (hw.trans inter_subset_right) exact fun y hy ↦ ⟨hy.2.2, hy.1⟩ · apply hu.mono exact fun y hy ↦ ⟨subset_insert _ _ hy.1, hy.2.1⟩ have u_mem : u ∈ 𝓝 x₀ := u_open.mem_nhds x₀u -- apply the auxiliary version to `s ∩ u` set s' := s ∩ u with hs' have s'_eq : s' =ᶠ[𝓝 x₀] s := by filter_upwards [u_mem] with y hy change (y ∈ s ∩ u) = (y ∈ s) simp [hy] set t' := t ∩ (extChartAt I' (f x₀)).source with ht' calc mpullbackWithin I I' f (mlieBracketWithin I' V W t) s x₀ _ = mpullbackWithin I I' f (mlieBracketWithin I' V W t) s' x₀ := by simp only [mpullbackWithin, hs', mfderivWithin_inter u_mem] _ = mpullbackWithin I I' f (mlieBracketWithin I' V W t') s' x₀ := by simp only [mpullbackWithin, ht', mlieBracketWithin_inter (extChartAt_source_mem_nhds (f x₀))] _ = mlieBracketWithin I (mpullbackWithin I I' f V s') (mpullbackWithin I I' f W s') s' x₀ := by apply mpullbackWithin_mlieBracketWithin_aux (t := t') (hV.mono inter_subset_left) (hW.mono inter_subset_left) (hu.inter u_open) u_smooth ⟨hx₀, x₀u⟩ inter_subset_right (fun y hy ↦ ⟨ut hy, maps_u hy⟩) apply hsymm.congr_set have : (extChartAt I x₀).symm ⁻¹' u ∈ 𝓝 (extChartAt I x₀ x₀) := by apply (continuousAt_extChartAt_symm x₀).preimage_mem_nhds apply u_open.mem_nhds (by simpa using x₀u) filter_upwards [this] with y hy change (y ∈ (extChartAt I x₀).symm ⁻¹' s ∩ range I) = (y ∈ (extChartAt I x₀).symm ⁻¹' (s ∩ u) ∩ range I) simp [-extChartAt, hy] _ = mlieBracketWithin I (mpullbackWithin I I' f V s') (mpullbackWithin I I' f W s') s x₀ := by simp only [hs', mlieBracketWithin_inter u_mem] _ = mlieBracketWithin I (mpullbackWithin I I' f V s) (mpullbackWithin I I' f W s) s x₀ := by apply Filter.EventuallyEq.mlieBracketWithin_vectorField_eq_of_mem _ _ hx₀ · apply nhdsWithin_le_nhds filter_upwards [mfderivWithin_eventually_congr_set (I := I) (I' := I') (f := f) s'_eq] with y hy using by simp [mpullbackWithin, hy] · apply nhdsWithin_le_nhds filter_upwards [mfderivWithin_eventually_congr_set (I := I) (I' := I') (f := f) s'_eq] with y hy using by simp [mpullbackWithin, hy] end Invariance_IsSymmSndFDerivWithinAt section Invariance variable [IsManifold I (minSmoothness 𝕜 2) M] [IsManifold I' (minSmoothness 𝕜 2) M'] [CompleteSpace E] {n : WithTop ℕ∞} /-- The pullback commutes with the Lie bracket of vector fields on manifolds. Version where one assumes that the map is smooth on a larger set `u` (so that the condition `x₀ ∈ closure (interior u)`, needed to guarantee the symmetry of the second derivative, becomes easier to check.) -/ lemma mpullbackWithin_mlieBracketWithin' {f : M → M'} {V W : Π (x : M'), TangentSpace I' x} {x₀ : M} {s u : Set M} {t : Set M'} (hV : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (V x : TangentBundle I' M')) t (f x₀)) (hW : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (W x : TangentBundle I' M')) t (f x₀)) (hs : UniqueMDiffOn I s) (hu : UniqueMDiffOn I u) (hf : ContMDiffWithinAt I I' n f u x₀) (hx₀ : x₀ ∈ s) (hn : minSmoothness 𝕜 2 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) (h'x₀ : x₀ ∈ closure (interior u)) (hsu : s ⊆ u) : mpullbackWithin I I' f (mlieBracketWithin I' V W t) s x₀ = mlieBracketWithin I (mpullbackWithin I I' f V s) (mpullbackWithin I I' f W s) s x₀ := by have B : ContDiffWithinAt 𝕜 n ((extChartAt I' (f x₀)) ∘ f ∘ (extChartAt I x₀).symm) ((extChartAt I x₀).symm ⁻¹' u ∩ (extChartAt I x₀).target) (extChartAt I x₀ x₀) := by apply (contMDiffWithinAt_iff.1 hf).2.congr_set exact EventuallyEq.inter (by rfl) extChartAt_target_eventuallyEq.symm apply mpullbackWithin_mlieBracketWithin_of_isSymmSndFDerivWithinAt hV hW hs ((hf.mono hsu).of_le (le_minSmoothness.trans hn)) hx₀ hst have : ((extChartAt I x₀).symm ⁻¹' s ∩ (extChartAt I x₀).target : Set E) =ᶠ[𝓝 (extChartAt I x₀ x₀)] ((extChartAt I x₀).symm ⁻¹' s ∩ range I : Set E) := EventuallyEq.inter (by rfl) extChartAt_target_eventuallyEq apply IsSymmSndFDerivWithinAt.congr_set _ this have : IsSymmSndFDerivWithinAt 𝕜 ((extChartAt I' (f x₀)) ∘ f ∘ (extChartAt I x₀).symm) ((extChartAt I x₀).symm ⁻¹' u ∩ (extChartAt I x₀).target) (extChartAt I x₀ x₀) := by apply ContDiffWithinAt.isSymmSndFDerivWithinAt (n := minSmoothness 𝕜 2) _ le_rfl · rw [inter_comm] exact UniqueMDiffOn.uniqueDiffOn_target_inter hu x₀ · apply extChartAt_mem_closure_interior h'x₀ (mem_extChartAt_source x₀) · simp [hsu hx₀] · exact B.of_le hn apply IsSymmSndFDerivWithinAt.mono_of_mem_nhdsWithin this · apply mem_of_superset self_mem_nhdsWithin (inter_subset_inter_left _ (preimage_mono hsu)) · exact (B.of_le hn).of_le le_minSmoothness · rw [inter_comm] exact UniqueMDiffOn.uniqueDiffOn_target_inter hs x₀ · rw [inter_comm] exact UniqueMDiffOn.uniqueDiffOn_target_inter hu x₀ · simp [hx₀] /-- The pullback commutes with the Lie bracket of vector fields on manifolds. -/ lemma mpullbackWithin_mlieBracketWithin {f : M → M'} {V W : Π (x : M'), TangentSpace I' x} {x₀ : M} {s : Set M} {t : Set M'} (hV : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (V x : TangentBundle I' M')) t (f x₀)) (hW : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (W x : TangentBundle I' M')) t (f x₀)) (hu : UniqueMDiffOn I s) (hf : ContMDiffWithinAt I I' n f s x₀) (hx₀ : x₀ ∈ s) (hn : minSmoothness 𝕜 2 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) (h'x₀ : x₀ ∈ closure (interior s)) : mpullbackWithin I I' f (mlieBracketWithin I' V W t) s x₀ = mlieBracketWithin I (mpullbackWithin I I' f V s) (mpullbackWithin I I' f W s) s x₀ := mpullbackWithin_mlieBracketWithin' hV hW hu hu hf hx₀ hn hst h'x₀ Subset.rfl /-- The pullback commutes with the Lie bracket of vector fields on manifolds. -/ lemma mpullback_mlieBracketWithin {f : M → M'} {V W : Π (x : M'), TangentSpace I' x} {x₀ : M} {s : Set M} {t : Set M'} (hV : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (V x : TangentBundle I' M')) t (f x₀)) (hW : MDifferentiableWithinAt I' I'.tangent (fun x ↦ (W x : TangentBundle I' M')) t (f x₀)) (hu : UniqueMDiffOn I s) (hf : ContMDiffAt I I' n f x₀) (hx₀ : x₀ ∈ s) (hn : minSmoothness 𝕜 2 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) : mpullback I I' f (mlieBracketWithin I' V W t) x₀ = mlieBracketWithin I (mpullback I I' f V) (mpullback I I' f W) s x₀ := by have : mpullback I I' f (mlieBracketWithin I' V W t) x₀ = mpullbackWithin I I' f (mlieBracketWithin I' V W t) s x₀ := by simp only [mpullback, mpullbackWithin] congr apply (mfderivWithin_eq_mfderiv (hu _ hx₀) _).symm exact hf.mdifferentiableAt (one_le_two.trans (le_minSmoothness.trans hn)) rw [this, mpullbackWithin_mlieBracketWithin' hV hW hu uniqueMDiffOn_univ hf.contMDiffWithinAt hx₀ hn hst (by simp) (subset_univ _)] apply Filter.EventuallyEq.mlieBracketWithin_vectorField_of_insert · rw [insert_eq_of_mem hx₀] filter_upwards [nhdsWithin_le_nhds ((contMDiffAt_iff_contMDiffAt_nhds (by simp)).1 (hf.of_le (le_minSmoothness.trans hn))), self_mem_nhdsWithin] with y hy h'y simp only [mpullback, mpullbackWithin] congr apply mfderivWithin_eq_mfderiv (hu _ h'y) exact hy.mdifferentiableAt one_le_two · rw [insert_eq_of_mem hx₀] filter_upwards [nhdsWithin_le_nhds ((contMDiffAt_iff_contMDiffAt_nhds (by simp)).1 (hf.of_le (le_minSmoothness.trans hn))), self_mem_nhdsWithin] with y hy h'y simp only [mpullback, mpullbackWithin] congr apply mfderivWithin_eq_mfderiv (hu _ h'y) exact hy.mdifferentiableAt one_le_two lemma mpullback_mlieBracket {f : M → M'} {V W : Π (x : M'), TangentSpace I' x} {x₀ : M} (hV : MDifferentiableAt I' I'.tangent (fun x ↦ (V x : TangentBundle I' M')) (f x₀)) (hW : MDifferentiableAt I' I'.tangent (fun x ↦ (W x : TangentBundle I' M')) (f x₀)) (hf : ContMDiffAt I I' n f x₀) (hn : minSmoothness 𝕜 2 ≤ n) : mpullback I I' f (mlieBracket I' V W) x₀ = mlieBracket I (mpullback I I' f V) (mpullback I I' f W) x₀ := by simp only [← mlieBracketWithin_univ, ← mdifferentiableWithinAt_univ] at hV hW ⊢ exact mpullback_mlieBracketWithin hV hW uniqueMDiffOn_univ hf (mem_univ _) hn (by simp) /-- If two vector fields are `C^n` with `n ≥ m + 1`, then their Lie bracket is `C^m`. -/ protected lemma _root_.ContMDiffWithinAt.mlieBracketWithin_vectorField [IsManifold I (n + 1) M] {m : WithTop ℕ∞} {U V : Π (x : M), TangentSpace I x} {s : Set M} {x : M} (hU : ContMDiffWithinAt I I.tangent n (fun x ↦ (U x : TangentBundle I M)) s x) (hV : ContMDiffWithinAt I I.tangent n (fun x ↦ (V x : TangentBundle I M)) s x) (hs : UniqueMDiffOn I s) (hx : x ∈ s) (hmn : minSmoothness 𝕜 (m + 1) ≤ n) : ContMDiffWithinAt I I.tangent m (fun x ↦ (mlieBracketWithin I U V s x : TangentBundle I M)) s x := by /- The statement is not obvious, since at different points the Lie bracket is defined using different charts. However, since we know that the Lie bracket is invariant under diffeos, we can use a single chart to prove the statement. Let `U'` and `V'` denote the pullbacks of `U` and `V` in the chart around `x`. Then the Lie bracket there is smooth (as it coincides with the vector space Lie bracket, given by an explicit formula). Pulling back this Lie bracket in `M` gives locally a smooth function, which coincides with the initial Lie bracket by invariance under diffeos. -/ have min2 : minSmoothness 𝕜 2 ≤ n + 1 := by grw [← hmn, ← minSmoothness_add, add_assoc] exact minSmoothness_monotone le_add_self apply contMDiffWithinAt_iff_le_ne_infty.2 (fun m' hm' h'm' ↦ ?_) have hn : 1 ≤ m' + 1 := le_add_self have hm'n : m' + 1 ≤ n := by grw [hm', ← hmn, ← le_minSmoothness] have pre_mem : (extChartAt I x) ⁻¹' ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) ∈ 𝓝[s] x := by filter_upwards [self_mem_nhdsWithin, nhdsWithin_le_nhds (extChartAt_source_mem_nhds (I := I) x)] with y hy h'y exact ⟨(extChartAt I x).map_source h'y, by simpa only [mem_preimage, (extChartAt I x).left_inv h'y] using hy⟩ let U' := mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm U (range I) let V' := mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm V (range I) have A : ContDiffWithinAt 𝕜 m' (lieBracketWithin 𝕜 U' V' ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x x) := ContDiffWithinAt.lieBracketWithin_vectorField (contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt.1 (contMDiffWithinAt_mpullbackWithin_extChartAt_symm hU hs hx le_rfl)) (contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt.1 (contMDiffWithinAt_mpullbackWithin_extChartAt_symm hV hs hx le_rfl)) (hs.uniqueDiffOn_target_inter x) hm'n (by simp [hx]) have B : ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent m' (fun y ↦ (mlieBracketWithin 𝓘(𝕜, E) U' V' ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) y : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x x) := by rw [← mlieBracketWithin_eq_lieBracketWithin] at A exact contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt.2 A have C : ContMDiffWithinAt I I.tangent m' (fun y ↦ (mpullback I 𝓘(𝕜, E) (extChartAt I x) ((mlieBracketWithin 𝓘(𝕜, E) U' V' ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s))) y : TangentBundle I M)) s x := ContMDiffWithinAt.mpullback_vectorField_of_mem_nhdsWithin_of_eq B (n := m' + 1) contMDiffAt_extChartAt (isInvertible_mfderiv_extChartAt (mem_extChartAt_source x)) le_rfl pre_mem rfl apply C.congr_of_eventuallyEq_of_mem _ hx filter_upwards [eventually_eventually_nhdsWithin.2 pre_mem, eventually_eventually_nhdsWithin.2 (eventuallyEq_mpullback_mpullbackWithin_extChartAt U), eventually_eventually_nhdsWithin.2 (eventuallyEq_mpullback_mpullbackWithin_extChartAt V), eventually_contMDiffWithinAt_mpullbackWithin_extChartAt_symm (hU.of_le hm'n) hs hx (by gcongr) (by simp [h'm']), eventually_contMDiffWithinAt_mpullbackWithin_extChartAt_symm (hV.of_le hm'n) hs hx (by gcongr) (by simp [h'm']), nhdsWithin_le_nhds (chart_source_mem_nhds H x), self_mem_nhdsWithin] with y hy hyU hyV h'yU h'yV hy_chart hys simp only [Bundle.TotalSpace.mk_inj] rw [mpullback_mlieBracketWithin (h'yU.mdifferentiableWithinAt hn) (h'yV.mdifferentiableWithinAt hn) hs (contMDiffAt_extChartAt' hy_chart) hys min2 hy] exact Filter.EventuallyEq.mlieBracketWithin_vectorField_eq_of_mem hyU hyV hys /-- If two vector fields are `C^n` with `n ≥ m + 1`, then their Lie bracket is `C^m`. -/ lemma _root_.ContMDiffAt.mlieBracket_vectorField {m n : ℕ∞} [IsManifold I (n + 1) M] {U V : Π (x : M), TangentSpace I x} {x : M} (hU : ContMDiffAt I I.tangent n (fun x ↦ (U x : TangentBundle I M)) x) (hV : ContMDiffAt I I.tangent n (fun x ↦ (V x : TangentBundle I M)) x) (hmn : minSmoothness 𝕜 (m + 1) ≤ n) : ContMDiffAt I I.tangent m (fun x ↦ (mlieBracket I U V x : TangentBundle I M)) x := by simp only [← contMDiffWithinAt_univ, ← mlieBracketWithin_univ] at hU hV ⊢ exact hU.mlieBracketWithin_vectorField hV uniqueMDiffOn_univ (mem_univ _) hmn /-- If two vector fields are `C^n` with `n ≥ m + 1`, then their Lie bracket is `C^m`. -/ lemma _root_.ContMDiffOn.mlieBracketWithin_vectorField {m n : ℕ∞} [IsManifold I (n + 1) M] {U V : Π (x : M), TangentSpace I x} (hU : ContMDiffOn I I.tangent n (fun x ↦ (U x : TangentBundle I M)) s) (hV : ContMDiffOn I I.tangent n (fun x ↦ (V x : TangentBundle I M)) s) (hs : UniqueMDiffOn I s) (hmn : minSmoothness 𝕜 (m + 1) ≤ n) : ContMDiffOn I I.tangent m (fun x ↦ (mlieBracketWithin I U V s x : TangentBundle I M)) s := fun x hx ↦ (hU x hx).mlieBracketWithin_vectorField (hV x hx) hs hx hmn /-- If two vector fields are `C^n` with `n ≥ m + 1`, then their Lie bracket is `C^m`. -/ lemma _root_.ContDiff.mlieBracket_vectorField {m n : ℕ∞} [IsManifold I (n + 1) M] {U V : Π (x : M), TangentSpace I x} (hU : ContMDiff I I.tangent n (fun x ↦ (U x : TangentBundle I M))) (hV : ContMDiff I I.tangent n (fun x ↦ (V x : TangentBundle I M))) (hmn : minSmoothness 𝕜 (m + 1) ≤ n) : ContMDiff I I.tangent m (fun x ↦ (mlieBracket I U V x : TangentBundle I M)) := by simp only [← contMDiffOn_univ] at hU hV ⊢ exact hU.mlieBracketWithin_vectorField hV uniqueMDiffOn_univ hmn end Invariance section Leibniz variable [IsManifold I (minSmoothness 𝕜 3) M] [CompleteSpace E] /-- The Lie bracket of vector fields in manifolds satisfies the Leibniz identity `[U, [V, W]] = [[U, V], W] + [V, [U, W]]` (also called Jacobi identity). -/ theorem leibniz_identity_mlieBracketWithin_apply {U V W : Π (x : M), TangentSpace I x} {s : Set M} {x : M} (hs : UniqueMDiffOn I s) (h's : x ∈ closure (interior s)) (hx : x ∈ s) (hU : ContMDiffWithinAt I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (U x : TangentBundle I M)) s x) (hV : ContMDiffWithinAt I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (V x : TangentBundle I M)) s x) (hW : ContMDiffWithinAt I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (W x : TangentBundle I M)) s x) : mlieBracketWithin I U (mlieBracketWithin I V W s) s x = mlieBracketWithin I (mlieBracketWithin I U V s) W s x + mlieBracketWithin I V (mlieBracketWithin I U W s) s x := by have A : minSmoothness 𝕜 2 + 1 ≤ minSmoothness 𝕜 3 := by simp only [← minSmoothness_add] exact le_rfl have s_inter_mem : s ∩ (extChartAt I x).source ∈ 𝓝[s] x := inter_mem self_mem_nhdsWithin (nhdsWithin_le_nhds (extChartAt_source_mem_nhds x)) have pre_mem : (extChartAt I x) ⁻¹' ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) ∈ 𝓝[s] x := by filter_upwards [s_inter_mem] with y hy exact ⟨(extChartAt I x).map_source hy.2, by simpa only [mem_preimage, (extChartAt I x).left_inv hy.2] using hy.1⟩ -- write everything as pullbacks of vector fields in `E` (denoted with primes), for which -- the identity can be checked via direct calculation. let U' := mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm U (range I) let V' := mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm V (range I) let W' := mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm W (range I) -- register basic facts on the pullbacks in the vector space have J0U : ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent (minSmoothness 𝕜 2) (fun y ↦ (U' y : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x x) := contMDiffWithinAt_mpullbackWithin_extChartAt_symm hU hs hx A have J0V : ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent (minSmoothness 𝕜 2) (fun y ↦ (V' y : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x x) := contMDiffWithinAt_mpullbackWithin_extChartAt_symm hV hs hx A have J0W : ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent (minSmoothness 𝕜 2) (fun y ↦ (W' y : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x x) := contMDiffWithinAt_mpullbackWithin_extChartAt_symm hW hs hx A have J1U : ∀ᶠ y in 𝓝[s] x, ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent (minSmoothness 𝕜 2) (fun y ↦ (U' y : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x y) := eventually_contMDiffWithinAt_mpullbackWithin_extChartAt_symm hU hs hx A (by simp) have J1V : ∀ᶠ y in 𝓝[s] x, ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent (minSmoothness 𝕜 2) (fun y ↦ (V' y : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x y) := eventually_contMDiffWithinAt_mpullbackWithin_extChartAt_symm hV hs hx A (by simp) have J1W : ∀ᶠ y in 𝓝[s] x, ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent (minSmoothness 𝕜 2) (fun y ↦ (W' y : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x y) := eventually_contMDiffWithinAt_mpullbackWithin_extChartAt_symm hW hs hx A (by simp) have JU : U =ᶠ[𝓝[s] x] mpullback I 𝓘(𝕜, E) (extChartAt I x) U' := eventuallyEq_mpullback_mpullbackWithin_extChartAt U have JV : V =ᶠ[𝓝[s] x] mpullback I 𝓘(𝕜, E) (extChartAt I x) V' := eventuallyEq_mpullback_mpullbackWithin_extChartAt V have JW : W =ᶠ[𝓝[s] x] mpullback I 𝓘(𝕜, E) (extChartAt I x) W' := eventuallyEq_mpullback_mpullbackWithin_extChartAt W rw [JU.mlieBracketWithin_vectorField_eq_of_mem (JV.mlieBracketWithin_vectorField JW) hx, (JU.mlieBracketWithin_vectorField JV).mlieBracketWithin_vectorField_eq_of_mem JW hx, JV.mlieBracketWithin_vectorField_eq_of_mem (JU.mlieBracketWithin_vectorField JW) hx] /- Rewrite the first term as a pullback-/ have : ∀ᶠ y in 𝓝[s] x, mlieBracketWithin I (mpullback I 𝓘(𝕜, E) (extChartAt I x) V') (mpullback I 𝓘(𝕜, E) (extChartAt I x) W') s y = mpullback I 𝓘(𝕜, E) (extChartAt I x) (mlieBracketWithin 𝓘(𝕜, E) V' W' ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s)) y := by filter_upwards [eventually_eventually_nhdsWithin.2 pre_mem, J1V, J1W, nhdsWithin_le_nhds (chart_source_mem_nhds H x), self_mem_nhdsWithin] with y hy hyV hyW h'y ys symm exact mpullback_mlieBracketWithin (n := minSmoothness 𝕜 2) (hyV.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) (hyW.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) hs (contMDiffAt_extChartAt' h'y) ys le_rfl hy rw [Filter.EventuallyEq.mlieBracketWithin_vectorField_eq_of_mem EventuallyEq.rfl this hx, ← mpullback_mlieBracketWithin (J0U.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) _ hs contMDiffAt_extChartAt hx le_rfl pre_mem]; swap · apply ContMDiffWithinAt.mdifferentiableWithinAt _ le_rfl apply J0V.mlieBracketWithin_vectorField J0W (m := 1) · exact hs.uniqueMDiffOn_target_inter x · exact ⟨mem_extChartAt_target x, by simp [hx]⟩ · exact le_rfl /- Rewrite the second term as a pullback-/ have : ∀ᶠ y in 𝓝[s] x, mlieBracketWithin I (mpullback I 𝓘(𝕜, E) (extChartAt I x) U') (mpullback I 𝓘(𝕜, E) (extChartAt I x) V') s y = mpullback I 𝓘(𝕜, E) (extChartAt I x) (mlieBracketWithin 𝓘(𝕜, E) U' V' ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s)) y := by filter_upwards [eventually_eventually_nhdsWithin.2 pre_mem, J1U, J1V, nhdsWithin_le_nhds (chart_source_mem_nhds H x), self_mem_nhdsWithin] with y hy hyU hyV h'y ys symm exact mpullback_mlieBracketWithin (n := minSmoothness 𝕜 2) (hyU.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) (hyV.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) hs (contMDiffAt_extChartAt' h'y) ys le_rfl hy rw [Filter.EventuallyEq.mlieBracketWithin_vectorField_eq_of_mem this EventuallyEq.rfl hx, ← mpullback_mlieBracketWithin _ (J0W.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) hs contMDiffAt_extChartAt hx le_rfl pre_mem]; swap · apply ContMDiffWithinAt.mdifferentiableWithinAt _ le_rfl apply J0U.mlieBracketWithin_vectorField J0V (m := 1) · exact hs.uniqueMDiffOn_target_inter x · exact ⟨mem_extChartAt_target x, by simp [hx]⟩ · exact le_rfl /- Rewrite the third term as a pullback-/ have : ∀ᶠ y in 𝓝[s] x, mlieBracketWithin I (mpullback I 𝓘(𝕜, E) (extChartAt I x) U') (mpullback I 𝓘(𝕜, E) (extChartAt I x) W') s y = mpullback I 𝓘(𝕜, E) (extChartAt I x) (mlieBracketWithin 𝓘(𝕜, E) U' W' ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s)) y := by filter_upwards [eventually_eventually_nhdsWithin.2 pre_mem, J1U, J1W, nhdsWithin_le_nhds (chart_source_mem_nhds H x), self_mem_nhdsWithin] with y hy hyU hyW h'y ys symm exact mpullback_mlieBracketWithin (n := minSmoothness 𝕜 2) (hyU.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) (hyW.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) hs (contMDiffAt_extChartAt' h'y) ys le_rfl hy rw [Filter.EventuallyEq.mlieBracketWithin_vectorField_eq_of_mem EventuallyEq.rfl this hx, ← mpullback_mlieBracketWithin (J0V.mdifferentiableWithinAt (one_le_two.trans le_minSmoothness)) _ hs contMDiffAt_extChartAt hx le_rfl pre_mem]; swap · apply ContMDiffWithinAt.mdifferentiableWithinAt _ le_rfl apply J0U.mlieBracketWithin_vectorField J0W (m := 1) · exact hs.uniqueMDiffOn_target_inter x · exact ⟨mem_extChartAt_target x, by simp [hx]⟩ · exact le_rfl /- Now that everything is in pullback form, use the leibniz identity in the vector space -/ rw [← mpullback_add_apply, mpullback_apply, mpullback_apply] congr 1 simp_rw [mlieBracketWithin_eq_lieBracketWithin] apply leibniz_identity_lieBracketWithin (E := E) le_rfl · exact hs.uniqueDiffOn_target_inter x · rw [inter_comm] exact extChartAt_mem_closure_interior h's (mem_extChartAt_source x) · exact ⟨mem_extChartAt_target x, by simp [hx]⟩ · exact contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt.mp J0U · exact contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt.mp J0V · exact contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt.mp J0W /-- The Lie bracket of vector fields in manifolds satisfies the Leibniz identity `[U, [V, W]] = [[U, V], W] + [V, [U, W]]` (also called Jacobi identity). -/ lemma leibniz_identity_mlieBracket_apply {U V W : Π (x : M), TangentSpace I x} {x : M} (hU : ContMDiffAt I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (U x : TangentBundle I M)) x) (hV : ContMDiffAt I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (V x : TangentBundle I M)) x) (hW : ContMDiffAt I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (W x : TangentBundle I M)) x) : mlieBracket I U (mlieBracket I V W) x = mlieBracket I (mlieBracket I U V) W x + mlieBracket I V (mlieBracket I U W) x := by simp only [← mlieBracketWithin_univ, ← contMDiffWithinAt_univ] at hU hV hW ⊢ exact leibniz_identity_mlieBracketWithin_apply uniqueMDiffOn_univ (by simp) (mem_univ _) hU hV hW /-- The Lie bracket of vector fields in manifolds satisfies the Leibniz identity `[U, [V, W]] = [[U, V], W] + [V, [U, W]]` (also called Jacobi identity). -/ lemma leibniz_identity_mlieBracket {U V W : Π (x : M), TangentSpace I x} (hU : ContMDiff I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (U x : TangentBundle I M))) (hV : ContMDiff I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (V x : TangentBundle I M))) (hW : ContMDiff I I.tangent (minSmoothness 𝕜 2) (fun x ↦ (W x : TangentBundle I M))) : mlieBracket I U (mlieBracket I V W) = mlieBracket I (mlieBracket I U V) W + mlieBracket I V (mlieBracket I U W) := by ext x exact leibniz_identity_mlieBracket_apply (hU x) (hV x) (hW x) end Leibniz end LieBracket end VectorField
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorField/Pullback.lean
import Mathlib.Analysis.Calculus.VectorField import Mathlib.Geometry.Manifold.ContMDiffMFDeriv import Mathlib.Geometry.Manifold.MFDeriv.NormedSpace import Mathlib.Geometry.Manifold.VectorBundle.MDifferentiable /-! # Vector fields in manifolds We study functions of the form `V : Π (x : M) → TangentSpace I x` on a manifold, i.e., vector fields. We define the pullback of a vector field under a map, as `VectorField.mpullback I I' f V x := (mfderiv I I' f x).inverse (V (f x))` (together with the same notion within a set). Note that the pullback uses the junk-value pattern: if the derivative of the map is not invertible, then pullback is given the junk value zero. See `Mathlib/Geometry/Manifold/VectorField/LieBracket.lean` for the Lie bracket of two vector fields. These definitions are given in the `VectorField` namespace because pullbacks, Lie brackets, and so on, are notions that make sense in a variety of contexts. We also prefix the notions with `m` to distinguish the manifold notions from the vector space notions. For notions that come naturally in other namespaces for dot notation, we specify `vectorField` in the name to lift ambiguities. For instance, the fact that the Lie bracket of two smooth vector fields is smooth is `ContMDiffAt.mlieBracket_vectorField`. Note that a smoothness assumption for a vector field is written by seeing the vector field as a function from `M` to its tangent bundle through a coercion, as in: `MDifferentiableWithinAt I I.tangent (fun y ↦ (V y : TangentBundle I M)) s x`. -/ open Set Function Filter open scoped Topology Manifold ContDiff noncomputable section /- We work in the `VectorField` namespace because pullbacks, Lie brackets, and so on, are notions that make sense in a variety of contexts. We also prefix the notions with `m` to distinguish the manifold notions from the vector spaces notions. For instance, the Lie bracket of two vector fields in a manifold is denoted with `VectorField.mlieBracket I V W x`, where `I` is the relevant model with corners, `V W : Π (x : M), TangentSpace I x` are the vector fields, and `x : M` is the basepoint. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {H' : Type*} [TopologicalSpace H'] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {H'' : Type*} [TopologicalSpace H''] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] {f : M → M'} {s t : Set M} {x x₀ : M} instance {n : ℕ} [n.AtLeastTwo] [IsManifold I (minSmoothness 𝕜 (ofNat(n))) M] : IsManifold I (ofNat(n)) M := IsManifold.of_le (n := minSmoothness 𝕜 n) le_minSmoothness instance [IsManifold I (minSmoothness 𝕜 1) M] : IsManifold I 1 M := IsManifold.of_le (n := minSmoothness 𝕜 1) le_minSmoothness instance [IsManifold I (minSmoothness 𝕜 3) M] : IsManifold I (minSmoothness 𝕜 2) M := IsManifold.of_le (n := minSmoothness 𝕜 3) (minSmoothness_monotone (by norm_cast)) instance [IsManifold I (minSmoothness 𝕜 2) M] : IsManifold I (minSmoothness 𝕜 1) M := IsManifold.of_le (n := minSmoothness 𝕜 2) (minSmoothness_monotone (by norm_cast)) namespace VectorField section Pullback /-! ### Pullback of vector fields in manifolds -/ open ContinuousLinearMap variable {V W V₁ W₁ : Π (x : M'), TangentSpace I' x} variable {c : 𝕜} {m n : WithTop ℕ∞} {t : Set M'} {y₀ : M'} variable (I I') in /-- The pullback of a vector field under a map between manifolds, within a set `s`. If the derivative of the map within `s` is not invertible, then pullback is given the junk value zero. -/ def mpullbackWithin (f : M → M') (V : Π (x : M'), TangentSpace I' x) (s : Set M) (x : M) : TangentSpace I x := (mfderivWithin I I' f s x).inverse (V (f x)) variable (I I') in /-- The pullback of a vector field under a map between manifolds. If the derivative of the map is not invertible, then pullback is given the junk value zero. -/ def mpullback (f : M → M') (V : Π (x : M'), TangentSpace I' x) (x : M) : TangentSpace I x := (mfderiv I I' f x).inverse (V (f x)) lemma mpullbackWithin_apply : mpullbackWithin I I' f V s x = (mfderivWithin I I' f s x).inverse (V (f x)) := rfl lemma mpullbackWithin_smul_apply : mpullbackWithin I I' f (c • V) s x = c • mpullbackWithin I I' f V s x := by simp [mpullbackWithin_apply] lemma mpullbackWithin_smul : mpullbackWithin I I' f (c • V) s = c • mpullbackWithin I I' f V s := by ext x simp [mpullbackWithin_apply] lemma mpullbackWithin_add_apply : mpullbackWithin I I' f (V + V₁) s x = mpullbackWithin I I' f V s x + mpullbackWithin I I' f V₁ s x := by simp [mpullbackWithin_apply] lemma mpullbackWithin_add : mpullbackWithin I I' f (V + V₁) s = mpullbackWithin I I' f V s + mpullbackWithin I I' f V₁ s := by ext x simp [mpullbackWithin_apply] @[simp] lemma mpullbackWithin_zero : mpullbackWithin I I' f 0 s = 0 := by ext x simp [mpullbackWithin_apply] lemma mpullbackWithin_neg_apply : mpullbackWithin I I' f (-V) s x = - mpullbackWithin I I' f V s x := by simp [mpullbackWithin_apply] lemma mpullbackWithin_neg : mpullbackWithin I I' f (-V) s = - mpullbackWithin I I' f V s := by ext x simp [mpullbackWithin_apply] lemma mpullbackWithin_id {V : Π (x : M), TangentSpace I x} (h : UniqueMDiffWithinAt I s x) : mpullbackWithin I I id V s x = V x := by simp [mpullbackWithin_apply, mfderivWithin_id h] lemma mpullback_apply : mpullback I I' f V x = (mfderiv I I' f x).inverse (V (f x)) := rfl lemma mpullback_smul_apply : mpullback I I' f (c • V) x = c • mpullback I I' f V x := by simp [mpullback] lemma mpullback_smul : mpullback I I' f (c • V) = c • mpullback I I' f V := by ext x simp [mpullback_apply] lemma mpullback_add_apply : mpullback I I' f (V + V₁) x = mpullback I I' f V x + mpullback I I' f V₁ x := by simp [mpullback_apply] lemma mpullback_add : mpullback I I' f (V + V₁) = mpullback I I' f V + mpullback I I' f V₁ := by ext x simp [mpullback_apply] lemma mpullback_neg_apply : mpullback I I' f (-V) x = - mpullback I I' f V x := by simp [mpullback_apply] lemma mpullback_neg : mpullback I I' f (-V) = - mpullback I I' f V := by ext x simp [mpullback_apply] @[simp] lemma mpullbackWithin_univ : mpullbackWithin I I' f V univ = mpullback I I' f V := by ext x simp [mpullback_apply, mpullbackWithin_apply] @[simp] lemma mpullback_zero : mpullback I I' f 0 = 0 := by simp [← mpullbackWithin_univ] lemma mpullbackWithin_eq_pullbackWithin {f : E → E'} {V : E' → E'} {s : Set E} : mpullbackWithin 𝓘(𝕜, E) 𝓘(𝕜, E') f V s = pullbackWithin 𝕜 f V s := by ext x simp only [mpullbackWithin, mfderivWithin_eq_fderivWithin, pullbackWithin] rfl lemma mpullback_eq_pullback {f : E → E'} {V : E' → E'} : mpullback 𝓘(𝕜, E) 𝓘(𝕜, E') f V = pullback 𝕜 f V := by simp only [← mpullbackWithin_univ, ← pullbackWithin_univ, mpullbackWithin_eq_pullbackWithin] @[simp] lemma mpullback_id {V : Π (x : M), TangentSpace I x} : mpullback I I id V = V := by ext x simp [mpullback] lemma mpullbackWithin_comp_of_left {g : M' → M''} {f : M → M'} {V : Π (x : M''), TangentSpace I'' x} {s : Set M} {t : Set M'} {x₀ : M} (hf : MDifferentiableWithinAt I I' f s x₀) (h : Set.MapsTo f s t) (hu : UniqueMDiffWithinAt I s x₀) (hg' : (mfderivWithin I' I'' g t (f x₀)).IsInvertible) : mpullbackWithin I I'' (g ∘ f) V s x₀ = mpullbackWithin I I' f (mpullbackWithin I' I'' g V t) s x₀ := by simp only [mpullbackWithin] have hg : MDifferentiableWithinAt I' I'' g t (f x₀) := mdifferentiableWithinAt_of_isInvertible_mfderivWithin hg' rw [mfderivWithin_comp _ hg hf h hu, Function.comp_apply, IsInvertible.inverse_comp_apply_of_left hg'] lemma mpullbackWithin_comp_of_right {g : M' → M''} {f : M → M'} {V : Π (x : M''), TangentSpace I'' x} {s : Set M} {t : Set M'} {x₀ : M} (hg : MDifferentiableWithinAt I' I'' g t (f x₀)) (h : Set.MapsTo f s t) (hu : UniqueMDiffWithinAt I s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) : mpullbackWithin I I'' (g ∘ f) V s x₀ = mpullbackWithin I I' f (mpullbackWithin I' I'' g V t) s x₀ := by simp only [mpullbackWithin] have hf : MDifferentiableWithinAt I I' f s x₀ := mdifferentiableWithinAt_of_isInvertible_mfderivWithin hf' rw [mfderivWithin_comp _ hg hf h hu, IsInvertible.inverse_comp_apply_of_right hf', Function.comp_apply] /-! ### Regularity of pullback of vector fields In this paragraph, we assume that the model space is complete, to ensure that the set of invertible linear maps is open and that inversion is a smooth map there. Otherwise, the pullback of vector fields could behave wildly, even at points where the derivative of the map is invertible. -/ section MDifferentiability variable [IsManifold I 2 M] [IsManifold I' 2 M'] [CompleteSpace E] /-- The pullback of a differentiable vector field by a `C^n` function with `2 ≤ n` is differentiable. Version within a set at a point. -/ protected lemma _root_.MDifferentiableWithinAt.mpullbackWithin_vectorField_inter (hV : MDifferentiableWithinAt I' I'.tangent (fun (y : M') ↦ (V y : TangentBundle I' M')) t (f x₀)) (hf : ContMDiffWithinAt I I' n f s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : 2 ≤ n) : MDifferentiableWithinAt I I.tangent (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) (s ∩ f ⁻¹' t) x₀ := by /- We want to apply the theorem `MDifferentiableWithinAt.clm_apply_of_inCoordinates`, stating that applying linear maps to vector fields gives a smooth result when the linear map and the vector field are smooth. This theorem is general, we will apply it to `b₁ = f`, `b₂ = id`, `v = V ∘ f`, `ϕ = fun x ↦ (mfderivWithin I I' f s x).inverse` -/ let b₁ := f let b₂ : M → M := id let v : Π (x : M), TangentSpace I' (f x) := V ∘ f let ϕ : Π (x : M), TangentSpace I' (f x) →L[𝕜] TangentSpace I x := fun x ↦ (mfderivWithin I I' f s x).inverse have hv : MDifferentiableWithinAt I I'.tangent (fun x ↦ (v x : TangentBundle I' M')) (s ∩ f ⁻¹' t) x₀ := by apply hV.comp x₀ ((hf.mdifferentiableWithinAt (one_le_two.trans hmn)).mono inter_subset_left) exact MapsTo.mono_left (mapsTo_preimage _ _) inter_subset_right /- The only nontrivial fact, from which the conclusion follows, is that `ϕ` depends smoothly on `x`. -/ suffices hϕ : MDifferentiableWithinAt I 𝓘(𝕜, E' →L[𝕜] E) (fun (x : M) ↦ ContinuousLinearMap.inCoordinates E' (TangentSpace I' (M := M')) E (TangentSpace I (M := M)) (b₁ x₀) (b₁ x) (b₂ x₀) (b₂ x) (ϕ x)) s x₀ from MDifferentiableWithinAt.clm_apply_of_inCoordinates (hϕ.mono inter_subset_left) hv mdifferentiableWithinAt_id /- To prove that `ϕ` depends smoothly on `x`, we use that the derivative depends smoothly on `x` (this is `ContMDiffWithinAt.mfderivWithin_const`), and that taking the inverse is a smooth operation at an invertible map. -/ -- the derivative in coordinates depends smoothly on the point have : MDifferentiableWithinAt I 𝓘(𝕜, E →L[𝕜] E') (fun (x : M) ↦ ContinuousLinearMap.inCoordinates E (TangentSpace I (M := M)) E' (TangentSpace I' (M := M')) x₀ x (f x₀) (f x) (mfderivWithin I I' f s x)) s x₀ := ((hf.of_le hmn).mfderivWithin_const le_rfl hx₀ hs).mdifferentiableWithinAt le_rfl -- therefore, its inverse in coordinates also depends smoothly on the point have : MDifferentiableWithinAt I 𝓘(𝕜, E' →L[𝕜] E) (ContinuousLinearMap.inverse ∘ (fun (x : M) ↦ ContinuousLinearMap.inCoordinates E (TangentSpace I (M := M)) E' (TangentSpace I' (M := M')) x₀ x (f x₀) (f x) (mfderivWithin I I' f s x))) s x₀ := by apply MDifferentiableAt.comp_mdifferentiableWithinAt _ _ this apply ContMDiffAt.mdifferentiableAt _ le_rfl apply ContDiffAt.contMDiffAt apply IsInvertible.contDiffAt_map_inverse rw [inCoordinates_eq (FiberBundle.mem_baseSet_trivializationAt' x₀) (FiberBundle.mem_baseSet_trivializationAt' (f x₀))] exact isInvertible_equiv.comp (hf'.comp isInvertible_equiv) -- the inverse in coordinates coincides with the in-coordinate version of the inverse, -- therefore the previous point gives the conclusion apply this.congr_of_eventuallyEq_of_mem _ hx₀ have A : (trivializationAt E (TangentSpace I) x₀).baseSet ∈ 𝓝[s] x₀ := by apply nhdsWithin_le_nhds apply (trivializationAt _ _ _).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' _ have B : f ⁻¹' (trivializationAt E' (TangentSpace I') (f x₀)).baseSet ∈ 𝓝[s] x₀ := by apply hf.continuousWithinAt.preimage_mem_nhdsWithin apply (trivializationAt _ _ _).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' _ filter_upwards [A, B] with x hx h'x simp only [Function.comp_apply] rw [inCoordinates_eq hx h'x, inCoordinates_eq h'x (by exact hx)] simp only [inverse_equiv_comp, inverse_comp_equiv, ContinuousLinearEquiv.symm_symm, ϕ] rfl lemma _root_.MDifferentiableWithinAt.mpullbackWithin_vectorField_inter_of_eq (hV : MDifferentiableWithinAt I' I'.tangent (fun (y : M') ↦ (V y : TangentBundle I' M')) t y₀) (hf : ContMDiffWithinAt I I' n f s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : 2 ≤ n) (h : y₀ = f x₀) : MDifferentiableWithinAt I I.tangent (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) (s ∩ f⁻¹' t) x₀ := by subst h exact hV.mpullbackWithin_vectorField_inter hf hf' hx₀ hs hmn /-- The pullback of a differentiable vector field by a `C^n` function with `2 ≤ n` is differentiable. Version on a set. -/ protected lemma _root_.MDifferentiableOn.mpullbackWithin_vectorField_inter (hV : MDifferentiableOn I' I'.tangent (fun (y : M') ↦ (V y : TangentBundle I' M')) t) (hf : ContMDiffOn I I' n f s) (hf' : ∀ x ∈ s ∩ f ⁻¹' t, (mfderivWithin I I' f s x).IsInvertible) (hs : UniqueMDiffOn I s) (hmn : 2 ≤ n) : MDifferentiableOn I I.tangent (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) (s ∩ f ⁻¹' t) := fun _ hx₀ ↦ MDifferentiableWithinAt.mpullbackWithin_vectorField_inter (hV _ hx₀.2) (hf _ hx₀.1) (hf' _ hx₀) hx₀.1 hs hmn /-- The pullback of a differentiable vector field by a `C^n` function with `2 ≤ n` is differentiable. Version within a set at a point, but with full pullback. -/ protected lemma _root_.MDifferentiableWithinAt.mpullback_vectorField_preimage (hV : MDifferentiableWithinAt I' I'.tangent (fun (y : M') ↦ (V y : TangentBundle I' M')) t (f x₀)) (hf : ContMDiffAt I I' n f x₀) (hf' : (mfderiv I I' f x₀).IsInvertible) (hmn : 2 ≤ n) : MDifferentiableWithinAt I I.tangent (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) (f ⁻¹' t) x₀ := by simp only [← contMDiffWithinAt_univ, ← mfderivWithin_univ, ← mpullbackWithin_univ] at hV hf hf' ⊢ simpa using hV.mpullbackWithin_vectorField_inter hf hf' (mem_univ _) uniqueMDiffOn_univ hmn /-- The pullback of a differentiable vector field by a `C^n` function with `2 ≤ n` is differentiable. Version within a set at a point, but with full pullback. -/ protected lemma _root_.MDifferentiableWithinAt.mpullback_vectorField_preimage_of_eq (hV : MDifferentiableWithinAt I' I'.tangent (fun (y : M') ↦ (V y : TangentBundle I' M')) t y₀) (hf : ContMDiffAt I I' n f x₀) (hf' : (mfderiv I I' f x₀).IsInvertible) (hmn : 2 ≤ n) (hy₀ : y₀ = f x₀) : MDifferentiableWithinAt I I.tangent (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) (f ⁻¹' t) x₀ := by subst hy₀ exact hV.mpullback_vectorField_preimage hf hf' hmn /-- The pullback of a differentiable vector field by a `C^n` function with `2 ≤ n` is differentiable. Version on a set, but with full pullback -/ protected lemma _root_.MDifferentiableOn.mpullback_vectorField_preimage (hV : MDifferentiableOn I' I'.tangent (fun (y : M') ↦ (V y : TangentBundle I' M')) t) (hf : ContMDiff I I' n f) (hf' : ∀ x ∈ f ⁻¹' t, (mfderiv I I' f x).IsInvertible) (hmn : 2 ≤ n) : MDifferentiableOn I I.tangent (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) (f ⁻¹' t) := fun x₀ hx₀ ↦ MDifferentiableWithinAt.mpullback_vectorField_preimage (hV _ hx₀) (hf x₀) (hf' _ hx₀) hmn /-- The pullback of a differentiable vector field by a `C^n` function with `2 ≤ n` is differentiable. Version at a point. -/ protected lemma _root_.MDifferentiableAt.mpullback_vectorField (hV : MDifferentiableAt I' I'.tangent (fun (y : M') ↦ (V y : TangentBundle I' M')) (f x₀)) (hf : ContMDiffAt I I' n f x₀) (hf' : (mfderiv I I' f x₀).IsInvertible) (hmn : 2 ≤ n) : MDifferentiableAt I I.tangent (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) x₀ := by simpa using MDifferentiableWithinAt.mpullback_vectorField_preimage hV hf hf' hmn /-- The pullback of a differentiable vector field by a `C^n` function with `2 ≤ n` is differentiable. -/ protected lemma _root_.MDifferentiable.mpullback_vectorField (hV : MDifferentiable I' I'.tangent (fun (y : M') ↦ (V y : TangentBundle I' M'))) (hf : ContMDiff I I' n f) (hf' : ∀ x, (mfderiv I I' f x).IsInvertible) (hmn : 2 ≤ n) : MDifferentiable I I.tangent (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) := fun x ↦ MDifferentiableAt.mpullback_vectorField (hV (f x)) (hf x) (hf' x) hmn end MDifferentiability section ContMDiff variable [CompleteSpace E] [IsManifold I 1 M] [IsManifold I' 1 M'] /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and `m + 1 ≤ n` is `C^m`. Version within a set at a point. -/ protected lemma _root_.ContMDiffWithinAt.mpullbackWithin_vectorField_inter (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t (f x₀)) (hf : ContMDiffWithinAt I I' n f s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) (s ∩ f ⁻¹' t) x₀ := by /- We want to apply the theorem `ContMDiffWithinAt.clm_apply_of_inCoordinates`, stating that applying linear maps to vector fields gives a smooth result when the linear map and the vector field are smooth. This theorem is general, we will apply it to `b₁ = f`, `b₂ = id`, `v = V ∘ f`, `ϕ = fun x ↦ (mfderivWithin I I' f s x).inverse` -/ let b₁ := f let b₂ : M → M := id let v : Π (x : M), TangentSpace I' (f x) := V ∘ f let ϕ : Π (x : M), TangentSpace I' (f x) →L[𝕜] TangentSpace I x := fun x ↦ (mfderivWithin I I' f s x).inverse have hv : ContMDiffWithinAt I I'.tangent m (fun x ↦ (v x : TangentBundle I' M')) (s ∩ f ⁻¹' t) x₀ := by apply hV.comp x₀ ((hf.of_le (le_trans (le_self_add) hmn)).mono inter_subset_left) exact MapsTo.mono_left (mapsTo_preimage _ _) inter_subset_right /- The only nontrivial fact, from which the conclusion follows, is that `ϕ` depends smoothly on `x`. -/ suffices hϕ : ContMDiffWithinAt I 𝓘(𝕜, E' →L[𝕜] E) m (fun (x : M) ↦ ContinuousLinearMap.inCoordinates E' (TangentSpace I' (M := M')) E (TangentSpace I (M := M)) (b₁ x₀) (b₁ x) (b₂ x₀) (b₂ x) (ϕ x)) s x₀ from ContMDiffWithinAt.clm_apply_of_inCoordinates (hϕ.mono inter_subset_left) hv contMDiffWithinAt_id /- To prove that `ϕ` depends smoothly on `x`, we use that the derivative depends smoothly on `x` (this is `ContMDiffWithinAt.mfderivWithin_const`), and that taking the inverse is a smooth operation at an invertible map. -/ -- the derivative in coordinates depends smoothly on the point have : ContMDiffWithinAt I 𝓘(𝕜, E →L[𝕜] E') m (fun (x : M) ↦ ContinuousLinearMap.inCoordinates E (TangentSpace I (M := M)) E' (TangentSpace I' (M := M')) x₀ x (f x₀) (f x) (mfderivWithin I I' f s x)) s x₀ := hf.mfderivWithin_const hmn hx₀ hs -- therefore, its inverse in coordinates also depends smoothly on the point have : ContMDiffWithinAt I 𝓘(𝕜, E' →L[𝕜] E) m (ContinuousLinearMap.inverse ∘ (fun (x : M) ↦ ContinuousLinearMap.inCoordinates E (TangentSpace I (M := M)) E' (TangentSpace I' (M := M')) x₀ x (f x₀) (f x) (mfderivWithin I I' f s x))) s x₀ := by apply ContMDiffAt.comp_contMDiffWithinAt _ _ this apply ContDiffAt.contMDiffAt apply IsInvertible.contDiffAt_map_inverse rw [inCoordinates_eq (FiberBundle.mem_baseSet_trivializationAt' x₀) (FiberBundle.mem_baseSet_trivializationAt' (f x₀))] exact isInvertible_equiv.comp (hf'.comp isInvertible_equiv) -- the inverse in coordinates coincides with the in-coordinate version of the inverse, -- therefore the previous point gives the conclusion apply this.congr_of_eventuallyEq_of_mem _ hx₀ have A : (trivializationAt E (TangentSpace I) x₀).baseSet ∈ 𝓝[s] x₀ := by apply nhdsWithin_le_nhds apply (trivializationAt _ _ _).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' _ have B : f ⁻¹' (trivializationAt E' (TangentSpace I') (f x₀)).baseSet ∈ 𝓝[s] x₀ := by apply hf.continuousWithinAt.preimage_mem_nhdsWithin apply (trivializationAt _ _ _).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' _ filter_upwards [A, B] with x hx h'x simp only [Function.comp_apply] rw [inCoordinates_eq hx h'x, inCoordinates_eq h'x (by exact hx)] simp only [inverse_equiv_comp, inverse_comp_equiv, ContinuousLinearEquiv.symm_symm, ϕ] rfl lemma _root_.ContMDiffWithinAt.mpullbackWithin_vectorField_inter_of_eq (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t y₀) (hf : ContMDiffWithinAt I I' n f s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) (h : f x₀ = y₀) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) (s ∩ f⁻¹' t) x₀ := by subst h exact ContMDiffWithinAt.mpullbackWithin_vectorField_inter hV hf hf' hx₀ hs hmn /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point. -/ protected lemma _root_.ContMDiffWithinAt.mpullbackWithin_vectorField_of_mem (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t (f x₀)) (hf : ContMDiffWithinAt I I' n f s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) s x₀ := by apply (ContMDiffWithinAt.mpullbackWithin_vectorField_inter hV hf hf' hx₀ hs hmn).mono_of_mem_nhdsWithin exact Filter.inter_mem self_mem_nhdsWithin hst /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point. -/ protected lemma _root_.ContMDiffWithinAt.mpullbackWithin_vectorField_of_mem_of_eq (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t y₀) (hf : ContMDiffWithinAt I I' n f s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) (hy₀ : f x₀ = y₀) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) s x₀ := by subst hy₀ exact ContMDiffWithinAt.mpullbackWithin_vectorField_of_mem hV hf hf' hx₀ hs hmn hst /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point. -/ protected lemma _root_.ContMDiffWithinAt.mpullbackWithin_vectorField (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t (f x₀)) (hf : ContMDiffWithinAt I I' n f s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) (hst : MapsTo f s t) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) s x₀ := ContMDiffWithinAt.mpullbackWithin_vectorField_of_mem hV hf hf' hx₀ hs hmn hst.preimage_mem_nhdsWithin /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point. -/ protected lemma _root_.ContMDiffWithinAt.mpullbackWithin_vectorField_of_eq (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t y₀) (hf : ContMDiffWithinAt I I' n f s x₀) (hf' : (mfderivWithin I I' f s x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) (hst : MapsTo f s t) (h : f x₀ = y₀) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) s x₀ := by subst h exact ContMDiffWithinAt.mpullbackWithin_vectorField hV hf hf' hx₀ hs hmn hst /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point, with a set used for the pullback possibly larger. -/ protected lemma _root_.ContMDiffWithinAt.mpullbackWithin_vectorField' {u : Set M} (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t (f x₀)) (hf : ContMDiffWithinAt I I' n f u x₀) (hf' : (mfderivWithin I I' f u x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) (hu : s ⊆ u) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V u y : TangentBundle I M)) s x₀ := by have hn : (1 : ℕ) ≤ n := le_trans le_add_self hmn have hh : (mfderivWithin I I' f s x₀).IsInvertible := by convert hf' using 1 exact (hf.mdifferentiableWithinAt hn).mfderivWithin_mono (hs _ hx₀) hu apply (hV.mpullbackWithin_vectorField_of_mem (hf.mono hu) hh hx₀ hs hmn hst).congr_of_eventuallyEq_of_mem _ hx₀ have Y := (contMDiffWithinAt_iff_contMDiffWithinAt_nhdsWithin (by simp)).1 (hf.of_le hn) simp_rw [insert_eq_of_mem (hu hx₀)] at Y filter_upwards [self_mem_nhdsWithin, nhdsWithin_mono _ hu Y] with y hy h'y simp only [mpullbackWithin, Bundle.TotalSpace.mk_inj] rw [MDifferentiableWithinAt.mfderivWithin_mono (h'y.mdifferentiableWithinAt le_rfl) (hs _ hy) hu] /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point, with a set used for the pullback possibly larger. -/ protected lemma _root_.ContMDiffWithinAt.mpullbackWithin_vectorField_of_eq' {u : Set M} (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t y₀) (hf : ContMDiffWithinAt I I' n f u x₀) (hf' : (mfderivWithin I I' f u x₀).IsInvertible) (hx₀ : x₀ ∈ s) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) (hu : s ⊆ u) (hy₀ : f x₀ = y₀) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V u y : TangentBundle I M)) s x₀ := by subst hy₀ exact ContMDiffWithinAt.mpullbackWithin_vectorField' hV hf hf' hx₀ hs hmn hst hu /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version on a set. -/ protected lemma _root_.ContMDiffOn.mpullbackWithin_vectorField_inter (hV : ContMDiffOn I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t) (hf : ContMDiffOn I I' n f s) (hf' : ∀ x ∈ s ∩ f ⁻¹' t, (mfderivWithin I I' f s x).IsInvertible) (hs : UniqueMDiffOn I s) (hmn : m + 1 ≤ n) : ContMDiffOn I I.tangent m (fun (y : M) ↦ (mpullbackWithin I I' f V s y : TangentBundle I M)) (s ∩ f ⁻¹' t) := fun _ hx₀ ↦ ContMDiffWithinAt.mpullbackWithin_vectorField_inter (hV _ hx₀.2) (hf _ hx₀.1) (hf' _ hx₀) hx₀.1 hs hmn /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point, but with full pullback. -/ protected lemma _root_.ContMDiffWithinAt.mpullback_vectorField_preimage (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t (f x₀)) (hf : ContMDiffAt I I' n f x₀) (hf' : (mfderiv I I' f x₀).IsInvertible) (hmn : m + 1 ≤ n) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) (f ⁻¹' t) x₀ := by simp only [← contMDiffWithinAt_univ, ← mfderivWithin_univ, ← mpullbackWithin_univ] at hV hf hf' ⊢ simpa using hV.mpullbackWithin_vectorField_inter hf hf' (mem_univ _) uniqueMDiffOn_univ hmn /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point, but with full pullback. -/ protected lemma _root_.ContMDiffWithinAt.mpullback_vectorField_preimage_of_eq (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t y₀) (hf : ContMDiffAt I I' n f x₀) (hf' : (mfderiv I I' f x₀).IsInvertible) (hmn : m + 1 ≤ n) (hy₀ : y₀ = f x₀) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) (f ⁻¹' t) x₀ := by subst hy₀ exact ContMDiffWithinAt.mpullback_vectorField_preimage hV hf hf' hmn /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point, but with full pullback. -/ protected lemma _root_.ContMDiffWithinAt.mpullback_vectorField_of_mem_nhdsWithin (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t (f x₀)) (hf : ContMDiffAt I I' n f x₀) (hf' : (mfderiv I I' f x₀).IsInvertible) (hmn : m + 1 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) s x₀ := (ContMDiffWithinAt.mpullback_vectorField_preimage hV hf hf' hmn).mono_of_mem_nhdsWithin hst /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version within a set at a point, but with full pullback. -/ protected lemma _root_.ContMDiffWithinAt.mpullback_vectorField_of_mem_nhdsWithin_of_eq (hV : ContMDiffWithinAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t y₀) (hf : ContMDiffAt I I' n f x₀) (hf' : (mfderiv I I' f x₀).IsInvertible) (hmn : m + 1 ≤ n) (hst : f ⁻¹' t ∈ 𝓝[s] x₀) (hy₀ : y₀ = f x₀) : ContMDiffWithinAt I I.tangent m (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) s x₀ := by subst hy₀ exact ContMDiffWithinAt.mpullback_vectorField_of_mem_nhdsWithin hV hf hf' hmn hst /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version on a set, but with full pullback -/ protected lemma _root_.ContMDiffOn.mpullback_vectorField_preimage (hV : ContMDiffOn I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) t) (hf : ContMDiff I I' n f) (hf' : ∀ x ∈ f ⁻¹' t, (mfderiv I I' f x).IsInvertible) (hmn : m + 1 ≤ n) : ContMDiffOn I I.tangent m (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) (f ⁻¹' t) := fun x₀ hx₀ ↦ ContMDiffWithinAt.mpullback_vectorField_preimage (hV _ hx₀) (hf x₀) (hf' _ hx₀) hmn /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. Version at a point. -/ protected lemma _root_.ContMDiffAt.mpullback_vectorField_preimage (hV : ContMDiffAt I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M')) (f x₀)) (hf : ContMDiffAt I I' n f x₀) (hf' : (mfderiv I I' f x₀).IsInvertible) (hmn : m + 1 ≤ n) : ContMDiffAt I I.tangent m (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) x₀ := by simp only [← contMDiffWithinAt_univ] at hV hf hf' ⊢ simpa using ContMDiffWithinAt.mpullback_vectorField_preimage hV hf hf' hmn /-- The pullback of a `C^m` vector field by a `C^n` function with invertible derivative and with `m + 1 ≤ n` is `C^m`. -/ protected lemma _root_.ContMDiff.mpullback_vectorField (hV : ContMDiff I' I'.tangent m (fun (y : M') ↦ (V y : TangentBundle I' M'))) (hf : ContMDiff I I' n f) (hf' : ∀ x, (mfderiv I I' f x).IsInvertible) (hmn : m + 1 ≤ n) : ContMDiff I I.tangent m (fun (y : M) ↦ (mpullback I I' f V y : TangentBundle I M)) := fun x ↦ ContMDiffAt.mpullback_vectorField_preimage (hV (f x)) (hf x) (hf' x) hmn lemma contMDiffWithinAt_mpullbackWithin_extChartAt_symm {V : Π (x : M), TangentSpace I x} (hV : ContMDiffWithinAt I I.tangent m (fun x ↦ (V x : TangentBundle I M)) s x) (hs : UniqueMDiffOn I s) (hx : x ∈ s) (hmn : m + 1 ≤ n) : ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent m (fun y ↦ (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm V (range I) y : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x x) := ContMDiffWithinAt.mpullbackWithin_vectorField_of_eq' hV (contMDiffWithinAt_extChartAt_symm_range_self (n := n) x) (isInvertible_mfderivWithin_extChartAt_symm (mem_extChartAt_target x)) (by simp [hx]) (UniqueMDiffOn.uniqueMDiffOn_target_inter hs x) hmn ((mapsTo_preimage _ _).mono_left inter_subset_right).preimage_mem_nhdsWithin (Subset.trans inter_subset_left (extChartAt_target_subset_range x)) (extChartAt_to_inv x) lemma eventually_contMDiffWithinAt_mpullbackWithin_extChartAt_symm {V : Π (x : M), TangentSpace I x} (hV : ContMDiffWithinAt I I.tangent m (fun x ↦ (V x : TangentBundle I M)) s x) (hs : UniqueMDiffOn I s) (hx : x ∈ s) (hmn : m + 1 ≤ n) (hm : m ≠ ∞) : ∀ᶠ y in 𝓝[s] x, ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent m (fun z ↦ (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm V (range I) z : TangentBundle 𝓘(𝕜, E) E)) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) (extChartAt I x y) := by have T := nhdsWithin_mono _ (subset_insert _ _) ((contMDiffWithinAt_iff_contMDiffWithinAt_nhdsWithin hm).1 (contMDiffWithinAt_mpullbackWithin_extChartAt_symm hV hs hx hmn)) have A := (continuousAt_extChartAt (I := I) x).continuousWithinAt.preimage_mem_nhdsWithin'' T rfl apply (nhdsWithin_le_iff.2 _) A filter_upwards [self_mem_nhdsWithin, nhdsWithin_le_nhds (extChartAt_source_mem_nhds (I := I) x)] with y hy h'y simp only [mfld_simps] at hy h'y simp [hy, h'y] omit [CompleteSpace E] in lemma eventuallyEq_mpullback_mpullbackWithin_extChartAt (V : Π (x : M), TangentSpace I x) : V =ᶠ[𝓝[s] x] mpullback I 𝓘(𝕜, E) (extChartAt I x) (mpullbackWithin 𝓘(𝕜, E) I (extChartAt I x).symm V (range I)) := by apply nhdsWithin_le_nhds filter_upwards [extChartAt_source_mem_nhds (I := I) x] with y hy have A : (extChartAt I x).symm (extChartAt I x y) = y := (extChartAt I x).left_inv hy rw [mpullback_apply, mpullbackWithin_apply, ← (isInvertible_mfderiv_extChartAt hy).inverse_comp_apply_of_right, mfderivWithin_extChartAt_symm_comp_mfderiv_extChartAt' hy, A] simp only [ContinuousLinearMap.inverse_id, ContinuousLinearMap.coe_id', id_eq] end ContMDiff end Pullback end VectorField
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/MDifferentiable.lean
import Mathlib.Geometry.Manifold.VectorBundle.Basic import Mathlib.Geometry.Manifold.MFDeriv.NormedSpace import Mathlib.Geometry.Manifold.MFDeriv.SpecificFunctions /-! # Differentiability of functions in vector bundles -/ open Bundle Set OpenPartialHomeomorph ContinuousLinearMap Pretrivialization Filter open scoped Manifold Bundle Topology section variable {𝕜 B B' F M : Type*} {E : B → Type*} variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] (IB : ModelWithCorners 𝕜 EB HB) (E' : B → Type*) [∀ x, Zero (E' x)] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] {n : ℕ∞} variable [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E] /-- Characterization of differentiable functions into a vector bundle. Version at a point within a set -/ theorem mdifferentiableWithinAt_totalSpace (f : M → TotalSpace F E) {s : Set M} {x₀ : M} : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F)) f s x₀ ↔ MDifferentiableWithinAt IM IB (fun x => (f x).proj) s x₀ ∧ MDifferentiableWithinAt IM 𝓘(𝕜, F) (fun x ↦ (trivializationAt F E (f x₀).proj (f x)).2) s x₀ := by simp +singlePass only [mdifferentiableWithinAt_iff_target] rw [and_and_and_comm, ← FiberBundle.continuousWithinAt_totalSpace, and_congr_right_iff] intro hf simp_rw [modelWithCornersSelf_prod, FiberBundle.extChartAt, Function.comp_def, PartialEquiv.trans_apply, PartialEquiv.prod_coe, PartialEquiv.refl_coe, extChartAt_self_apply, modelWithCornersSelf_coe, Function.id_def, ← chartedSpaceSelf_prod] refine (mdifferentiableWithinAt_prod_iff _).trans (and_congr ?_ Iff.rfl) have h1 : (fun x => (f x).proj) ⁻¹' (trivializationAt F E (f x₀).proj).baseSet ∈ 𝓝[s] x₀ := ((FiberBundle.continuous_proj F E).continuousWithinAt.comp hf (mapsTo_image f s)) ((Trivialization.open_baseSet _).mem_nhds (mem_baseSet_trivializationAt F E _)) refine EventuallyEq.mdifferentiableWithinAt_iff (eventually_of_mem h1 fun x hx => ?_) ?_ · simp_rw [Function.comp, OpenPartialHomeomorph.coe_coe, Trivialization.coe_coe] rw [Trivialization.coe_fst'] exact hx · simp only [mfld_simps] /-- Characterization of differentiable functions into a vector bundle. Version at a point -/ theorem mdifferentiableAt_totalSpace (f : M → TotalSpace F E) {x₀ : M} : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F)) f x₀ ↔ MDifferentiableAt IM IB (fun x => (f x).proj) x₀ ∧ MDifferentiableAt IM 𝓘(𝕜, F) (fun x ↦ (trivializationAt F E (f x₀).proj (f x)).2) x₀ := by simpa [← mdifferentiableWithinAt_univ] using mdifferentiableWithinAt_totalSpace _ f /-- Characterization of differentiable sections of a vector bundle at a point within a set in terms of the preferred trivialization at that point. -/ theorem mdifferentiableWithinAt_section (s : Π b, E b) {u : Set B} {b₀ : B} : MDifferentiableWithinAt IB (IB.prod 𝓘(𝕜, F)) (fun b ↦ TotalSpace.mk' F b (s b)) u b₀ ↔ MDifferentiableWithinAt IB 𝓘(𝕜, F) (fun b ↦ (trivializationAt F E b₀ (s b)).2) u b₀ := by rw [mdifferentiableWithinAt_totalSpace] change MDifferentiableWithinAt _ _ id _ _ ∧ _ ↔ _ simp [mdifferentiableWithinAt_id] /-- Characterization of differentiable sections of a vector bundle at a point within a set in terms of the preferred trivialization at that point. -/ theorem mdifferentiableAt_section (s : Π b, E b) {b₀ : B} : MDifferentiableAt IB (IB.prod 𝓘(𝕜, F)) (fun b ↦ TotalSpace.mk' F b (s b)) b₀ ↔ MDifferentiableAt IB 𝓘(𝕜, F) (fun b ↦ (trivializationAt F E b₀ (s b)).2) b₀ := by simpa [← mdifferentiableWithinAt_univ] using mdifferentiableWithinAt_section _ _ namespace Bundle variable (E) {IB} theorem mdifferentiable_proj : MDifferentiable (IB.prod 𝓘(𝕜, F)) IB (π F E) := fun x ↦ by have : MDifferentiableAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) id x := mdifferentiableAt_id rw [mdifferentiableAt_totalSpace] at this exact this.1 theorem mdifferentiableOn_proj {s : Set (TotalSpace F E)} : MDifferentiableOn (IB.prod 𝓘(𝕜, F)) IB (π F E) s := (mdifferentiable_proj E).mdifferentiableOn theorem mdifferentiableAt_proj {p : TotalSpace F E} : MDifferentiableAt (IB.prod 𝓘(𝕜, F)) IB (π F E) p := (mdifferentiable_proj E).mdifferentiableAt theorem mdifferentiableWithinAt_proj {s : Set (TotalSpace F E)} {p : TotalSpace F E} : MDifferentiableWithinAt (IB.prod 𝓘(𝕜, F)) IB (π F E) s p := (mdifferentiableAt_proj E).mdifferentiableWithinAt variable (𝕜) [∀ x, AddCommMonoid (E x)] variable [∀ x, Module 𝕜 (E x)] [VectorBundle 𝕜 F E] theorem mdifferentiable_zeroSection : MDifferentiable IB (IB.prod 𝓘(𝕜, F)) (zeroSection F E) := by intro x unfold zeroSection rw [mdifferentiableAt_section] apply (mdifferentiableAt_const (c := 0)).congr_of_eventuallyEq filter_upwards [(trivializationAt F E x).open_baseSet.mem_nhds (mem_baseSet_trivializationAt F E x)] with y hy using congr_arg Prod.snd <| (trivializationAt F E x).zeroSection 𝕜 hy theorem mdifferentiableOn_zeroSection {t : Set B} : MDifferentiableOn IB (IB.prod 𝓘(𝕜, F)) (zeroSection F E) t := (mdifferentiable_zeroSection _ _).mdifferentiableOn theorem mdifferentiableAt_zeroSection {x : B} : MDifferentiableAt IB (IB.prod 𝓘(𝕜, F)) (zeroSection F E) x := (mdifferentiable_zeroSection _ _).mdifferentiableAt theorem mdifferentiableWithinAt_zeroSection {t : Set B} {x : B} : MDifferentiableWithinAt IB (IB.prod 𝓘(𝕜, F)) (zeroSection F E) t x := (mdifferentiable_zeroSection _ _ x).mdifferentiableWithinAt end Bundle section coordChange variable [(x : B) → AddCommMonoid (E x)] [(x : B) → Module 𝕜 (E x)] variable (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'] [VectorBundle 𝕜 F E] [ContMDiffVectorBundle 1 F E IB] variable {IB} theorem mdifferentiableOn_coordChangeL : MDifferentiableOn IB 𝓘(𝕜, F →L[𝕜] F) (fun b : B ↦ (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) (e.baseSet ∩ e'.baseSet) := (contMDiffOn_coordChangeL e e').mdifferentiableOn le_rfl theorem mdifferentiableOn_symm_coordChangeL : MDifferentiableOn IB 𝓘(𝕜, F →L[𝕜] F) (fun b : B ↦ ((e.coordChangeL 𝕜 e' b).symm : F →L[𝕜] F)) (e.baseSet ∩ e'.baseSet) := (contMDiffOn_symm_coordChangeL e e').mdifferentiableOn le_rfl variable {e e'} theorem mdifferentiableAt_coordChangeL {x : B} (h : x ∈ e.baseSet) (h' : x ∈ e'.baseSet) : MDifferentiableAt IB 𝓘(𝕜, F →L[𝕜] F) (fun b : B ↦ (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) x := (contMDiffAt_coordChangeL h h').mdifferentiableAt le_rfl variable {s : Set M} {f : M → B} {g : M → F} {x : M} protected theorem MDifferentiableWithinAt.coordChangeL (hf : MDifferentiableWithinAt IM IB f s x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : MDifferentiableWithinAt IM 𝓘(𝕜, F →L[𝕜] F) (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) s x := (mdifferentiableAt_coordChangeL he he').comp_mdifferentiableWithinAt _ hf protected theorem MDifferentiableAt.coordChangeL (hf : MDifferentiableAt IM IB f x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : MDifferentiableAt IM 𝓘(𝕜, F →L[𝕜] F) (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) x := MDifferentiableWithinAt.coordChangeL hf he he' protected theorem MDifferentiableOn.coordChangeL (hf : MDifferentiableOn IM IB f s) (he : MapsTo f s e.baseSet) (he' : MapsTo f s e'.baseSet) : MDifferentiableOn IM 𝓘(𝕜, F →L[𝕜] F) (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) s := fun x hx ↦ (hf x hx).coordChangeL (he hx) (he' hx) protected theorem MDifferentiable.coordChangeL (hf : MDifferentiable IM IB f) (he : ∀ x, f x ∈ e.baseSet) (he' : ∀ x, f x ∈ e'.baseSet) : MDifferentiable IM 𝓘(𝕜, F →L[𝕜] F) (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) := fun x ↦ (hf x).coordChangeL (he x) (he' x) protected theorem MDifferentiableWithinAt.coordChange (hf : MDifferentiableWithinAt IM IB f s x) (hg : MDifferentiableWithinAt IM 𝓘(𝕜, F) g s x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : MDifferentiableWithinAt IM 𝓘(𝕜, F) (fun y ↦ e.coordChange e' (f y) (g y)) s x := by refine ((hf.coordChangeL he he').clm_apply hg).congr_of_eventuallyEq ?_ ?_ · have : e.baseSet ∩ e'.baseSet ∈ 𝓝 (f x) := (e.open_baseSet.inter e'.open_baseSet).mem_nhds ⟨he, he'⟩ filter_upwards [hf.continuousWithinAt this] with y hy exact (Trivialization.coordChangeL_apply' e e' hy (g y)).symm · exact (Trivialization.coordChangeL_apply' e e' ⟨he, he'⟩ (g x)).symm protected theorem MDifferentiableAt.coordChange (hf : MDifferentiableAt IM IB f x) (hg : MDifferentiableAt IM 𝓘(𝕜, F) g x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : MDifferentiableAt IM 𝓘(𝕜, F) (fun y ↦ e.coordChange e' (f y) (g y)) x := MDifferentiableWithinAt.coordChange hf hg he he' protected theorem MDifferentiableOn.coordChange (hf : MDifferentiableOn IM IB f s) (hg : MDifferentiableOn IM 𝓘(𝕜, F) g s) (he : MapsTo f s e.baseSet) (he' : MapsTo f s e'.baseSet) : MDifferentiableOn IM 𝓘(𝕜, F) (fun y ↦ e.coordChange e' (f y) (g y)) s := fun x hx ↦ (hf x hx).coordChange (hg x hx) (he hx) (he' hx) protected theorem MDifferentiable.coordChange (hf : MDifferentiable IM IB f) (hg : MDifferentiable IM 𝓘(𝕜, F) g) (he : ∀ x, f x ∈ e.baseSet) (he' : ∀ x, f x ∈ e'.baseSet) : MDifferentiable IM 𝓘(𝕜, F) (fun y ↦ e.coordChange e' (f y) (g y)) := fun x ↦ (hf x).coordChange (hg x) (he x) (he' x) end coordChange variable [(x : B) → AddCommMonoid (E x)] [(x : B) → Module 𝕜 (E x)] [VectorBundle 𝕜 F E] [ContMDiffVectorBundle 1 F E IB] lemma MDifferentiableWithinAt.change_section_trivialization {e : Trivialization F TotalSpace.proj} [MemTrivializationAtlas e] {e' : Trivialization F TotalSpace.proj} [MemTrivializationAtlas e'] {f : M → TotalSpace F E} {s : Set M} {x₀ : M} (hf : MDifferentiableWithinAt IM IB (π F E ∘ f) s x₀) (he'f : MDifferentiableWithinAt IM 𝓘(𝕜, F) (fun x ↦ (e (f x)).2) s x₀) (he : f x₀ ∈ e.source) (he' : f x₀ ∈ e'.source) : MDifferentiableWithinAt IM 𝓘(𝕜, F) (fun x ↦ (e' (f x)).2) s x₀ := by rw [Trivialization.mem_source] at he he' refine (hf.coordChange he'f he he').congr_of_eventuallyEq ?_ ?_ · filter_upwards [hf.continuousWithinAt (e.open_baseSet.mem_nhds he)] with y hy rw [Function.comp_apply, e.coordChange_apply_snd e' hy] · rw [Function.comp_apply, e.coordChange_apply_snd _ he] theorem Trivialization.mdifferentiableWithinAt_snd_comp_iff₂ {e e' : Trivialization F TotalSpace.proj} [MemTrivializationAtlas e] [MemTrivializationAtlas e'] {f : M → TotalSpace F E} {s : Set M} {x₀ : M} (hex₀ : f x₀ ∈ e.source) (he'x₀ : f x₀ ∈ e'.source) (hf : MDifferentiableWithinAt IM IB (π F E ∘ f) s x₀) : MDifferentiableWithinAt IM 𝓘(𝕜, F) (fun x ↦ (e (f x)).2) s x₀ ↔ MDifferentiableWithinAt IM 𝓘(𝕜, F) (fun x ↦ (e' (f x)).2) s x₀ := ⟨(hf.change_section_trivialization IB · hex₀ he'x₀), (hf.change_section_trivialization IB · he'x₀ hex₀)⟩ variable (e e') theorem Trivialization.mdifferentiableAt_snd_comp_iff₂ {e e' : Trivialization F TotalSpace.proj} [MemTrivializationAtlas e] [MemTrivializationAtlas e'] {f : M → TotalSpace F E} {x₀ : M} (he : f x₀ ∈ e.source) (he' : f x₀ ∈ e'.source) (hf : MDifferentiableAt IM IB (fun x ↦ (f x).proj) x₀) : MDifferentiableAt IM 𝓘(𝕜, F) (fun x ↦ (e (f x)).2) x₀ ↔ MDifferentiableAt IM 𝓘(𝕜, F) (fun x ↦ (e' (f x)).2) x₀ := by simpa [← mdifferentiableWithinAt_univ] using e.mdifferentiableWithinAt_snd_comp_iff₂ IB he he' hf /-- Characterization of differentiable functions into a vector bundle in terms of any trivialization. Version at a point within at set. -/ theorem Trivialization.mdifferentiableWithinAt_totalSpace_iff (e : Trivialization F (TotalSpace.proj : TotalSpace F E → B)) [MemTrivializationAtlas e] (f : M → TotalSpace F E) {s : Set M} {x₀ : M} (he : f x₀ ∈ e.source) : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F)) f s x₀ ↔ MDifferentiableWithinAt IM IB (fun x => (f x).proj) s x₀ ∧ MDifferentiableWithinAt IM 𝓘(𝕜, F) (fun x ↦ (e (f x)).2) s x₀ := by rw [mdifferentiableWithinAt_totalSpace] apply and_congr_right intro hf rw [Trivialization.mdifferentiableWithinAt_snd_comp_iff₂ IB (FiberBundle.mem_trivializationAt_proj_source) he hf] /-- Characterization of differentiable functions into a vector bundle in terms of any trivialization. Version at a point. -/ theorem Trivialization.mdifferentiableAt_totalSpace_iff (e : Trivialization F (TotalSpace.proj : TotalSpace F E → B)) [MemTrivializationAtlas e] (f : M → TotalSpace F E) {x₀ : M} (he : f x₀ ∈ e.source) : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F)) f x₀ ↔ MDifferentiableAt IM IB (fun x => (f x).proj) x₀ ∧ MDifferentiableAt IM 𝓘(𝕜, F) (fun x ↦ (e (f x)).2) x₀ := by rw [mdifferentiableAt_totalSpace] apply and_congr_right intro hf rw [Trivialization.mdifferentiableAt_snd_comp_iff₂ IB (FiberBundle.mem_trivializationAt_proj_source) he hf] /-- Characterization of differentiable functions into a vector bundle in terms of any trivialization. Version at a point within at set. -/ theorem Trivialization.mdifferentiableWithinAt_section_iff (e : Trivialization F (TotalSpace.proj : TotalSpace F E → B)) [MemTrivializationAtlas e] (s : Π b : B, E b) {u : Set B} {b₀ : B} (hex₀ : b₀ ∈ e.baseSet) : MDifferentiableWithinAt IB (IB.prod 𝓘(𝕜, F)) (fun b ↦ TotalSpace.mk' F b (s b)) u b₀ ↔ MDifferentiableWithinAt IB 𝓘(𝕜, F) (fun x ↦ (e (s x)).2) u b₀ := by rw [e.mdifferentiableWithinAt_totalSpace_iff IB] · change MDifferentiableWithinAt IB IB id u b₀ ∧ _ ↔ _ simp [mdifferentiableWithinAt_id] exact (coe_mem_source e).mpr hex₀ /-- Characterization of differentiable functions into a vector bundle in terms of any trivialization. Version at a point. -/ theorem Trivialization.mdifferentiableAt_section_iff (e : Trivialization F (TotalSpace.proj : TotalSpace F E → B)) [MemTrivializationAtlas e] (s : Π b : B, E b) {b₀ : B} (hex₀ : b₀ ∈ e.baseSet) : MDifferentiableAt IB (IB.prod 𝓘(𝕜, F)) (fun b ↦ TotalSpace.mk' F b (s b)) b₀ ↔ MDifferentiableAt IB 𝓘(𝕜, F) (fun x ↦ (e (s x)).2) b₀ := by simpa [← mdifferentiableWithinAt_univ] using e.mdifferentiableWithinAt_section_iff IB s hex₀ variable {IB} in /-- Differentiability of a section on `s` can be determined using any trivialisation whose `baseSet` contains `s`. -/ theorem Trivialization.mdifferentiableOn_section_iff {s : ∀ x, E x} {a : Set B} (e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)) [MemTrivializationAtlas e] (ha : IsOpen a) (ha' : a ⊆ e.baseSet) : MDifferentiableOn IB (IB.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) a ↔ MDifferentiableOn IB 𝓘(𝕜, F) (fun x ↦ (e ⟨x, s x⟩).2) a := by refine ⟨fun h x hx ↦ ?_, fun h x hx ↦ ?_⟩ <;> have := (h x hx).mdifferentiableAt <| ha.mem_nhds hx · exact ((e.mdifferentiableAt_section_iff _ _ (ha' hx)).mp this).mdifferentiableWithinAt · exact ((e.mdifferentiableAt_section_iff _ _ (ha' hx)).mpr this).mdifferentiableWithinAt variable {IB} in /-- For any trivialization `e`, the differentiability of a section on `e.baseSet` can be determined using `e`. -/ theorem Trivialization.mdifferentiableOn_section_baseSet_iff {s : ∀ x, E x} (e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)) [MemTrivializationAtlas e] : MDifferentiableOn IB (IB.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) e.baseSet ↔ MDifferentiableOn IB 𝓘(𝕜, F) (fun x ↦ (e ⟨x, s x⟩).2) e.baseSet := e.mdifferentiableOn_section_iff e.open_baseSet subset_rfl end section operations variable {𝕜 B B' F M : Type*} {E : B → Type*} variable -- Let `E` be a fiber bundle with base `B` and fiber `F` (a vector space over `𝕜`) [TopologicalSpace B] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] [NormedAddCommGroup F] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 F] [FiberBundle F E] -- Moreover let `E` be a vector bundle [(x : B) → AddCommGroup (E x)] [(x : B) → Module 𝕜 (E x)] [VectorBundle 𝕜 F E] -- Let the base `B` be charted over a fixed model space `HB` {HB : Type*} [TopologicalSpace HB] [ChartedSpace HB B] -- Moreover let `HB` be modelled on a normed space `EB` so that `B` (and hence `E`) have -- differentiable structures {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {I : ModelWithCorners 𝕜 EB HB} variable {f : B → 𝕜} {a : 𝕜} {s t : Π x : B, E x} {u : Set B} {x₀ : B} lemma mdifferentiableWithinAt_add_section (hs : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) (ht : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t x)) u x₀) : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x ((s + t) x)) u x₀ := by rw [mdifferentiableWithinAt_section] at hs ht ⊢ set e := trivializationAt F E x₀ refine (hs.add ht).congr_of_eventuallyEq ?_ ?_ · apply eventually_of_mem (U := e.baseSet) · exact mem_nhdsWithin_of_mem_nhds <| (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F E x₀) · exact fun x hx ↦ (e.linear 𝕜 hx).1 .. · exact (e.linear 𝕜 (FiberBundle.mem_baseSet_trivializationAt' x₀)).1 .. lemma mdifferentiableAt_add_section (hs : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) x₀) (ht : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t x)) x₀) : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x ((s + t) x)) x₀ := by rw [← mdifferentiableWithinAt_univ] at hs ht ⊢ apply mdifferentiableWithinAt_add_section hs ht lemma mdifferentiableOn_add_section (hs : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u) (ht : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t x)) u) : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x ((s + t) x)) u := fun x₀ hx₀ ↦ mdifferentiableWithinAt_add_section (hs x₀ hx₀) (ht x₀ hx₀) lemma mdifferentiable_add_section (hs : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x))) (ht : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t x))) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x ((s + t) x)) := fun x₀ ↦ mdifferentiableAt_add_section (hs x₀) (ht x₀) lemma mdifferentiableWithinAt_neg_section (hs : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (- s x)) u x₀ := by rw [mdifferentiableWithinAt_section] at hs ⊢ set e := trivializationAt F E x₀ refine hs.neg.congr_of_eventuallyEq ?_ ?_ · apply eventually_of_mem (U := e.baseSet) · exact mem_nhdsWithin_of_mem_nhds <| (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F E x₀) · exact fun x hx ↦ (e.linear 𝕜 hx).map_neg .. · exact (e.linear 𝕜 (FiberBundle.mem_baseSet_trivializationAt' x₀)).map_neg .. lemma mdifferentiableAt_neg_section (hs : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) x₀) : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (- s x)) x₀ := by rw [← mdifferentiableWithinAt_univ] at hs ⊢ exact mdifferentiableWithinAt_neg_section hs lemma mdifferentiableOn_neg_section (hs : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u) : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (-s x)) u := fun x₀ hx₀ ↦ mdifferentiableWithinAt_neg_section (hs x₀ hx₀) lemma mdifferentiable_neg_section (hs : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x))) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (-s x)) := fun x₀ ↦ mdifferentiableAt_neg_section (hs x₀) lemma mdifferentiableWithinAt_sub_section (hs : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) (ht : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t x)) u x₀) : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x ((s - t) x)) u x₀ := by rw [sub_eq_add_neg] apply mdifferentiableWithinAt_add_section hs <| mdifferentiableWithinAt_neg_section ht lemma mdifferentiableAt_sub_section (hs : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) x₀) (ht : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t x)) x₀) : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x ((s - t) x)) x₀ := by rw [sub_eq_add_neg] apply mdifferentiableAt_add_section hs <| mdifferentiableAt_neg_section ht lemma mDifferentiableOn_sub_section (hs : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u) (ht : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t x)) u) : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x ((s - t) x)) u := fun x₀ hx₀ ↦ mdifferentiableWithinAt_sub_section (hs x₀ hx₀) (ht x₀ hx₀) lemma mdifferentiable_sub_section (hs : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x))) (ht : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t x))) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x ((s - t) x)) := fun x₀ ↦ mdifferentiableAt_sub_section (hs x₀) (ht x₀) lemma MDifferentiableWithinAt.smul_section (hf : MDifferentiableWithinAt I 𝓘(𝕜) f u x₀) (hs : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (f x • s x)) u x₀ := by rw [mdifferentiableWithinAt_section] at hs ⊢ set e := trivializationAt F E x₀ refine (hf.smul hs).congr_of_eventuallyEq ?_ ?_ · apply eventually_of_mem (U := e.baseSet) · exact mem_nhdsWithin_of_mem_nhds <| (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F E x₀) · exact fun x hx ↦ (e.linear 𝕜 hx).2 .. · apply (e.linear 𝕜 (FiberBundle.mem_baseSet_trivializationAt' x₀)).2 lemma MDifferentiableAt.smul_section (hf : MDifferentiableAt I 𝓘(𝕜) f x₀) (hs : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) x₀) : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (f x • s x)) x₀ := by rw [← mdifferentiableWithinAt_univ] at hs ⊢ exact .smul_section hf hs lemma MDifferentiableOn.smul_section (hf : MDifferentiableOn I 𝓘(𝕜) f u) (hs : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u) : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (f x • s x)) u := fun x₀ hx₀ ↦ .smul_section (hf x₀ hx₀) (hs x₀ hx₀) lemma mdifferentiable_smul_section (hf : MDifferentiable I 𝓘(𝕜) f) (hs : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x))) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (f x • s x)) := fun x₀ ↦ (hf x₀).smul_section (hs x₀) lemma mdifferentiableWithinAt_smul_const_section (hs : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (a • s x)) u x₀ := .smul_section mdifferentiableWithinAt_const hs lemma MDifferentiableAt.smul_const_section (hs : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) x₀) : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (a • s x)) x₀ := .smul_section mdifferentiableAt_const hs lemma MDifferentiableOn.smul_const_section (hs : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u) : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (a • s x)) u := .smul_section mdifferentiableOn_const hs lemma mdifferentiable_smul_const_section (hs : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x))) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (a • s x)) := fun x₀ ↦ (hs x₀).smul_const_section lemma MDifferentiableWithinAt.sum_section {ι : Type*} {s : Finset ι} {t : ι → (x : B) → E x} (hs : ∀ i, MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) u x₀) : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) u x₀ := by classical induction s using Finset.induction_on with | empty => simpa using (contMDiffWithinAt_zeroSection 𝕜 E).mdifferentiableWithinAt le_rfl | insert i s hi h => simpa [Finset.sum_insert hi] using mdifferentiableWithinAt_add_section (hs i) h lemma MDifferentiableAt.sum_section {ι : Type*} {s : Finset ι} {t : ι → (x : B) → E x} {x₀ : B} (hs : ∀ i, MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) x₀) : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) x₀ := by simp_rw [← mdifferentiableWithinAt_univ] at hs ⊢ exact MDifferentiableWithinAt.sum_section hs lemma MDifferentiableOn.sum_section {ι : Type*} {s : Finset ι} {t : ι → (x : B) → E x} (hs : ∀ i, MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) u) : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) u := fun x₀ hx₀ ↦ .sum_section fun i ↦ hs i x₀ hx₀ lemma MDifferentiable.sum_section {ι : Type*} {s : Finset ι} {t : ι → (x : B) → E x} (hs : ∀ i, MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x))) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) := fun x₀ ↦ .sum_section fun i ↦ (hs i) x₀ /-- The scalar product `ψ • s` of a differentiable function `ψ : M → 𝕜` and a section `s` of a vector bundle `V → M` is differentiable once `s` is differentiable on an open set containing `tsupport ψ`. See `ContMDiffOn.smul_section_of_tsupport` for the analogous result about `C^n` sections. -/ lemma MDifferentiableOn.smul_section_of_tsupport {s : Π (x : B), E x} {ψ : B → 𝕜} (hψ : MDifferentiableOn I 𝓘(𝕜) ψ u) (ht : IsOpen u) (ht' : tsupport ψ ⊆ u) (hs : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (s x)) u) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (ψ x • s x)) := by apply mdifferentiable_of_mdifferentiableOn_union_of_isOpen (hψ.smul_section hs) ?_ ?_ ht (isOpen_compl_iff.mpr <| isClosed_tsupport ψ) · apply ((mdifferentiable_zeroSection _ _).mdifferentiableOn (s := (tsupport ψ)ᶜ)).congr intro y hy simp [image_eq_zero_of_notMem_tsupport hy, zeroSection] · exact Set.compl_subset_iff_union.mp <| Set.compl_subset_compl.mpr ht' variable {ι : Type*} {t : ι → (x : B) → E x} open Function /-- The sum of a locally finite collection of sections is differentiable if each section is. Version at a point within a set. -/ lemma MDifferentiableWithinAt.sum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : B | t i x ≠ 0}) (ht' : ∀ i, MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) u x₀) : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑' i, (t i x))) u x₀ := by obtain ⟨u', hu', hfin⟩ := ht x₀ -- All sections `t i` but a finite set `s` vanish near `x₀`: choose a neighbourhood `u` of `x₀` -- and a finite set `s` of sections which don't vanish. let s := {i | ((fun i ↦ {x | t i x ≠ 0}) i ∩ u').Nonempty} have := hfin.fintype have : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) (u ∩ u') x₀ := MDifferentiableWithinAt.sum_section fun i ↦ ((ht' i).mono inter_subset_left) apply (mdifferentiableWithinAt_inter hu').mp apply this.congr' (fun y hy ↦ ?_) inter_subset_right (mem_of_mem_nhds hu') rw [TotalSpace.mk_inj, tsum_eq_sum'] refine support_subset_iff'.mpr fun i hi ↦ ?_ by_contra! h have : i ∈ s.toFinset := by refine Set.mem_toFinset.mpr ?_ simp only [s, ne_eq, Set.mem_setOf_eq] use y simp [h, hy] exact hi this /-- The sum of a locally finite collection of sections is differentiable at `x` if each section is. -/ lemma MDifferentiableAt.sum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : B | t i x ≠ 0}) (ht' : ∀ i, MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) x₀) : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑' i, (t i x))) x₀ := by simp_rw [← mdifferentiableWithinAt_univ] at ht' ⊢ exact .sum_section_of_locallyFinite ht ht' /-- The sum of a locally finite collection of sections is differentiable on a set `u` if each section is. -/ lemma MDifferentiableOn.sum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : B | t i x ≠ 0}) (ht' : ∀ i, MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) u) : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑' i, (t i x))) u := fun x hx ↦ .sum_section_of_locallyFinite ht (ht' · x hx) /-- The sum of a locally finite collection of sections is differentiable if each section is. -/ lemma MDifferentiable.sum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : B | t i x ≠ 0}) (ht' : ∀ i, MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x))) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑' i, (t i x))) := fun x ↦ .sum_section_of_locallyFinite ht fun i ↦ ht' i x lemma MDifferentiableWithinAt.finsum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : B | t i x ≠ 0}) (ht' : ∀ i, MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) u x₀) : MDifferentiableWithinAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ᶠ i, t i x)) u x₀ := by apply (MDifferentiableWithinAt.sum_section_of_locallyFinite ht ht').congr' (t := Set.univ) (fun y hy ↦ ?_) (by grind) trivial choose U hu hfin using ht y have : {x | t x y ≠ 0} ⊆ {i | ((fun i ↦ {x | t i x ≠ 0}) i ∩ U).Nonempty} := by intro x hx rw [Set.mem_setOf] at hx ⊢ use y simpa using ⟨hx, mem_of_mem_nhds hu⟩ rw [tsum_eq_finsum (hfin.subset this)] lemma MDifferentiableAt.finsum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : B | t i x ≠ 0}) (ht' : ∀ i, MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) x₀) : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ᶠ i, t i x)) x₀ := by simp_rw [← mdifferentiableWithinAt_univ] at ht' ⊢ exact .finsum_section_of_locallyFinite ht ht' lemma MDifferentiableOn.finsum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : B | t i x ≠ 0}) (ht' : ∀ i, MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x)) u) : MDifferentiableOn I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ᶠ i, t i x)) u := fun x hx ↦ .finsum_section_of_locallyFinite ht fun i ↦ ht' i x hx lemma MDifferentiable.finsum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : B | t i x ≠ 0}) (ht' : ∀ i, MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (t i x))) : MDifferentiable I (I.prod 𝓘(𝕜, F)) (fun x ↦ TotalSpace.mk' F x (∑ᶠ i, t i x)) := fun x ↦ .finsum_section_of_locallyFinite ht fun i ↦ ht' i x end operations section /- Declare two manifolds `B₁` and `B₂` (with models `IB₁ : HB₁ → EB₁` and `IB₂ : HB₂ → EB₂`), and two vector bundles `E₁` and `E₂` respectively over `B₁` and `B₂` (with model fibers `F₁` and `F₂`). Also a third manifold `M`, which will be the source of all our maps. -/ variable {𝕜 F₁ F₂ B₁ B₂ M : Type*} {E₁ : B₁ → Type*} {E₂ : B₂ → Type*} [NontriviallyNormedField 𝕜] [∀ x, AddCommGroup (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] [TopologicalSpace (TotalSpace F₁ E₁)] [∀ x, TopologicalSpace (E₁ x)] [∀ x, AddCommGroup (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] [TopologicalSpace (TotalSpace F₂ E₂)] [∀ x, TopologicalSpace (E₂ x)] {EB₁ : Type*} [NormedAddCommGroup EB₁] [NormedSpace 𝕜 EB₁] {HB₁ : Type*} [TopologicalSpace HB₁] {IB₁ : ModelWithCorners 𝕜 EB₁ HB₁} [TopologicalSpace B₁] [ChartedSpace HB₁ B₁] {EB₂ : Type*} [NormedAddCommGroup EB₂] [NormedSpace 𝕜 EB₂] {HB₂ : Type*} [TopologicalSpace HB₂] {IB₂ : ModelWithCorners 𝕜 EB₂ HB₂} [TopologicalSpace B₂] [ChartedSpace HB₂ B₂] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] {n : ℕ∞} [FiberBundle F₁ E₁] [VectorBundle 𝕜 F₁ E₁] [FiberBundle F₂ E₂] [VectorBundle 𝕜 F₂ E₂] {b₁ : M → B₁} {b₂ : M → B₂} {m₀ : M} {ϕ : Π (m : M), E₁ (b₁ m) →L[𝕜] E₂ (b₂ m)} {v : Π (m : M), E₁ (b₁ m)} {s : Set M} /-- Consider a differentiable map `v : M → E₁` to a vector bundle, over a basemap `b₁ : M → B₁`, and another basemap `b₂ : M → B₂`. Given linear maps `ϕ m : E₁ (b₁ m) → E₂ (b₂ m)` depending differentiably on `m`, one can apply `ϕ m` to `g m`, and the resulting map is differentiable. Note that the differentiability of `ϕ` cannot be always be stated as differentiability of a map into a manifold, as the pullback bundles `b₁ *ᵖ E₁` and `b₂ *ᵖ E₂` only make sense when `b₁` and `b₂` are globally smooth, but we want to apply this lemma with only local information. Therefore, we formulate it using differentiability of `ϕ` read in coordinates. Version for `MDifferentiableWithinAt`. We also give a version for `MDifferentiableAt`, but no version for `MDifferentiableOn` or `MDifferentiable` as our assumption, written in coordinates, only makes sense around a point. -/ lemma MDifferentiableWithinAt.clm_apply_of_inCoordinates (hϕ : MDifferentiableWithinAt IM 𝓘(𝕜, F₁ →L[𝕜] F₂) (fun m ↦ inCoordinates F₁ E₁ F₂ E₂ (b₁ m₀) (b₁ m) (b₂ m₀) (b₂ m) (ϕ m)) s m₀) (hv : MDifferentiableWithinAt IM (IB₁.prod 𝓘(𝕜, F₁)) (fun m ↦ (v m : TotalSpace F₁ E₁)) s m₀) (hb₂ : MDifferentiableWithinAt IM IB₂ b₂ s m₀) : MDifferentiableWithinAt IM (IB₂.prod 𝓘(𝕜, F₂)) (fun m ↦ (ϕ m (v m) : TotalSpace F₂ E₂)) s m₀ := by rw [mdifferentiableWithinAt_totalSpace] at hv ⊢ refine ⟨hb₂, ?_⟩ apply (MDifferentiableWithinAt.clm_apply hϕ hv.2).congr_of_eventuallyEq_insert have A : ∀ᶠ m in 𝓝[insert m₀ s] m₀, b₁ m ∈ (trivializationAt F₁ E₁ (b₁ m₀)).baseSet := by apply hv.1.insert.continuousWithinAt apply (trivializationAt F₁ E₁ (b₁ m₀)).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' (b₁ m₀) have A' : ∀ᶠ m in 𝓝[insert m₀ s] m₀, b₂ m ∈ (trivializationAt F₂ E₂ (b₂ m₀)).baseSet := by apply hb₂.insert.continuousWithinAt apply (trivializationAt F₂ E₂ (b₂ m₀)).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' (b₂ m₀) filter_upwards [A, A'] with m hm h'm rw [inCoordinates_eq hm h'm] simp only [coe_comp', ContinuousLinearEquiv.coe_coe, Trivialization.continuousLinearEquivAt_apply, Trivialization.continuousLinearEquivAt_symm_apply, Function.comp_apply] congr rw [Trivialization.symm_apply_apply_mk (trivializationAt F₁ E₁ (b₁ m₀)) hm (v m)] /-- Consider a differentiable map `v : M → E₁` to a vector bundle, over a basemap `b₁ : M → B₁`, and another basemap `b₂ : M → B₂`. Given linear maps `ϕ m : E₁ (b₁ m) → E₂ (b₂ m)` depending differentiably on `m`, one can apply `ϕ m` to `g m`, and the resulting map is differentiable. Note that the differentiability of `ϕ` cannot be always be stated as differentiability of a map into a manifold, as the pullback bundles `b₁ *ᵖ E₁` and `b₂ *ᵖ E₂` only make sense when `b₁` and `b₂` are globally smooth, but we want to apply this lemma with only local information. Therefore, we formulate it using differentiability of `ϕ` read in coordinates. Version for `MDifferentiableAt`. We also give a version for `MDifferentiableWithinAt`, but no version for `MDifferentiableOn` or `MDifferentiable` as our assumption, written in coordinates, only makes sense around a point. -/ lemma MDifferentiableAt.clm_apply_of_inCoordinates (hϕ : MDifferentiableAt IM 𝓘(𝕜, F₁ →L[𝕜] F₂) (fun m ↦ inCoordinates F₁ E₁ F₂ E₂ (b₁ m₀) (b₁ m) (b₂ m₀) (b₂ m) (ϕ m)) m₀) (hv : MDifferentiableAt IM (IB₁.prod 𝓘(𝕜, F₁)) (fun m ↦ (v m : TotalSpace F₁ E₁)) m₀) (hb₂ : MDifferentiableAt IM IB₂ b₂ m₀) : MDifferentiableAt IM (IB₂.prod 𝓘(𝕜, F₂)) (fun m ↦ (ϕ m (v m) : TotalSpace F₂ E₂)) m₀ := by rw [← mdifferentiableWithinAt_univ] at hϕ hv hb₂ ⊢ exact MDifferentiableWithinAt.clm_apply_of_inCoordinates hϕ hv hb₂ end
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/Riemannian.lean
import Mathlib.Geometry.Manifold.VectorBundle.Hom import Mathlib.Geometry.Manifold.VectorBundle.MDifferentiable import Mathlib.Topology.VectorBundle.Riemannian /-! # Riemannian vector bundles Given a vector bundle over a manifold whose fibers are all endowed with a scalar product, we say that this bundle is Riemannian if the scalar product depends smoothly on the base point. We introduce a typeclass `[IsContMDiffRiemannianBundle IB n F E]` registering this property. Under this assumption, we show that the scalar product of two smooth maps into the same fibers of the bundle is a smooth function. If the fibers of a bundle `E` have a preexisting topology (like the tangent bundle), one cannot assume additionally `[∀ b, InnerProductSpace ℝ (E b)]` as this would create diamonds. Instead, use `[RiemannianBundle E]`, which endows the fibers with a scalar product while ensuring that there is no diamond (for this, the `Bundle` scope should be open). We provide a constructor for `[RiemannianBundle E]` from a smooth family of metrics, which registers automatically `[IsContMDiffRiemannianBundle IB n F E]`. The following code block is the standard way to say "Let `E` be a smooth vector bundle equipped with a `C^n` Riemannian structure over a `C^n` manifold `B`": ``` variable {EB : Type*} [NormedAddCommGroup EB] [NormedSpace ℝ EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners ℝ EB HB} {n : WithTop ℕ∞} {B : Type*} [TopologicalSpace B] [ChartedSpace HB B] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {E : B → Type*} [TopologicalSpace (TotalSpace F E)] [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℝ (E x)] [FiberBundle F E] [VectorBundle ℝ F E] [IsManifold IB n B] [ContMDiffVectorBundle n F E IB] [IsContMDiffRiemannianBundle IB n F E] ``` -/ open Manifold Bundle ContinuousLinearMap ENat Bornology open scoped ContDiff Topology section variable {EB : Type*} [NormedAddCommGroup EB] [NormedSpace ℝ EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners ℝ EB HB} {n n' : WithTop ℕ∞} {B : Type*} [TopologicalSpace B] [ChartedSpace HB B] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {E : B → Type*} [TopologicalSpace (TotalSpace F E)] [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℝ (E x)] [FiberBundle F E] [VectorBundle ℝ F E] local notation "⟪" x ", " y "⟫" => inner ℝ x y variable (IB n F E) in /-- Consider a real vector bundle in which each fiber is endowed with a scalar product. We that the bundle is Riemannian if the scalar product depends smoothly on the base point. This assumption is spelled `IsContMDiffRiemannianBundle IB n F E` where `IB` is the model space of the base, `n` is the smoothness, `F` is the model fiber, and `E : B → Type*` is the bundle. -/ class IsContMDiffRiemannianBundle : Prop where exists_contMDiff : ∃ g : Π (x : B), E x →L[ℝ] E x →L[ℝ] ℝ, ContMDiff IB (IB.prod 𝓘(ℝ, F →L[ℝ] F →L[ℝ] ℝ)) n (fun b ↦ TotalSpace.mk' (F →L[ℝ] F →L[ℝ] ℝ) b (g b)) ∧ ∀ (x : B) (v w : E x), ⟪v, w⟫ = g x v w lemma IsContMDiffRiemannianBundle.of_le [h : IsContMDiffRiemannianBundle IB n F E] (h' : n' ≤ n) : IsContMDiffRiemannianBundle IB n' F E := by rcases h.exists_contMDiff with ⟨g, g_smooth, hg⟩ exact ⟨g, g_smooth.of_le h', hg⟩ instance {a : WithTop ℕ∞} [IsContMDiffRiemannianBundle IB ∞ F E] [h : LEInfty a] : IsContMDiffRiemannianBundle IB a F E := IsContMDiffRiemannianBundle.of_le h.out instance {a : WithTop ℕ∞} [IsContMDiffRiemannianBundle IB ω F E] : IsContMDiffRiemannianBundle IB a F E := IsContMDiffRiemannianBundle.of_le le_top instance [IsContMDiffRiemannianBundle IB 1 F E] : IsContMDiffRiemannianBundle IB 0 F E := IsContMDiffRiemannianBundle.of_le zero_le_one instance [IsContMDiffRiemannianBundle IB 2 F E] : IsContMDiffRiemannianBundle IB 1 F E := IsContMDiffRiemannianBundle.of_le one_le_two instance [IsContMDiffRiemannianBundle IB 3 F E] : IsContMDiffRiemannianBundle IB 2 F E := IsContMDiffRiemannianBundle.of_le (n := 3) (by norm_cast) section Trivial variable {F₁ : Type*} [NormedAddCommGroup F₁] [InnerProductSpace ℝ F₁] /-- A trivial vector bundle, in which the model fiber has a scalar product, is a Riemannian bundle. -/ instance : IsContMDiffRiemannianBundle IB n F₁ (Bundle.Trivial B F₁) := by refine ⟨fun x ↦ innerSL ℝ, fun x ↦ ?_, fun x v w ↦ rfl⟩ simp only [contMDiffAt_section] convert contMDiffAt_const (c := innerSL ℝ) ext v w simp [hom_trivializationAt_apply, inCoordinates, Trivialization.linearMapAt_apply] end Trivial section ContMDiff variable {EM : Type*} [NormedAddCommGroup EM] [NormedSpace ℝ EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners ℝ EM HM} {M : Type*} [TopologicalSpace M] [ChartedSpace HM M] [h : IsContMDiffRiemannianBundle IB n F E] {b : M → B} {v w : ∀ x, E (b x)} {s : Set M} {x : M} /-- Given two smooth maps into the same fibers of a Riemannian bundle, their scalar product is smooth. -/ lemma ContMDiffWithinAt.inner_bundle (hv : ContMDiffWithinAt IM (IB.prod 𝓘(ℝ, F)) n (fun m ↦ (v m : TotalSpace F E)) s x) (hw : ContMDiffWithinAt IM (IB.prod 𝓘(ℝ, F)) n (fun m ↦ (w m : TotalSpace F E)) s x) : ContMDiffWithinAt IM 𝓘(ℝ) n (fun m ↦ ⟪v m, w m⟫) s x := by rcases h.exists_contMDiff with ⟨g, g_smooth, hg⟩ have hb : ContMDiffWithinAt IM IB n b s x := by simp only [contMDiffWithinAt_totalSpace] at hv exact hv.1 simp only [hg] have : ContMDiffWithinAt IM (IB.prod 𝓘(ℝ)) n (fun m ↦ TotalSpace.mk' ℝ (E := Bundle.Trivial B ℝ) (b m) (g (b m) (v m) (w m))) s x := by apply ContMDiffWithinAt.clm_bundle_apply₂ (F₁ := F) (F₂ := F) · exact ContMDiffAt.comp_contMDiffWithinAt x g_smooth.contMDiffAt hb · exact hv · exact hw simp only [contMDiffWithinAt_totalSpace] at this exact this.2 /-- Given two smooth maps into the same fibers of a Riemannian bundle, their scalar product is smooth. -/ lemma ContMDiffAt.inner_bundle (hv : ContMDiffAt IM (IB.prod 𝓘(ℝ, F)) n (fun m ↦ (v m : TotalSpace F E)) x) (hw : ContMDiffAt IM (IB.prod 𝓘(ℝ, F)) n (fun m ↦ (w m : TotalSpace F E)) x) : ContMDiffAt IM 𝓘(ℝ) n (fun b ↦ ⟪v b, w b⟫) x := ContMDiffWithinAt.inner_bundle hv hw /-- Given two smooth maps into the same fibers of a Riemannian bundle, their scalar product is smooth. -/ lemma ContMDiffOn.inner_bundle (hv : ContMDiffOn IM (IB.prod 𝓘(ℝ, F)) n (fun m ↦ (v m : TotalSpace F E)) s) (hw : ContMDiffOn IM (IB.prod 𝓘(ℝ, F)) n (fun m ↦ (w m : TotalSpace F E)) s) : ContMDiffOn IM 𝓘(ℝ) n (fun b ↦ ⟪v b, w b⟫) s := fun x hx ↦ (hv x hx).inner_bundle (hw x hx) /-- Given two smooth maps into the same fibers of a Riemannian bundle, their scalar product is smooth. -/ lemma ContMDiff.inner_bundle (hv : ContMDiff IM (IB.prod 𝓘(ℝ, F)) n (fun m ↦ (v m : TotalSpace F E))) (hw : ContMDiff IM (IB.prod 𝓘(ℝ, F)) n (fun m ↦ (w m : TotalSpace F E))) : ContMDiff IM 𝓘(ℝ) n (fun b ↦ ⟪v b, w b⟫) := fun x ↦ (hv x).inner_bundle (hw x) end ContMDiff section MDifferentiable variable {EM : Type*} [NormedAddCommGroup EM] [NormedSpace ℝ EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners ℝ EM HM} {M : Type*} [TopologicalSpace M] [ChartedSpace HM M] [h : IsContMDiffRiemannianBundle IB 1 F E] {b : M → B} {v w : ∀ x, E (b x)} {s : Set M} {x : M} /-- Given two differentiable maps into the same fibers of a Riemannian bundle, their scalar product is differentiable. -/ lemma MDifferentiableWithinAt.inner_bundle (hv : MDifferentiableWithinAt IM (IB.prod 𝓘(ℝ, F)) (fun m ↦ (v m : TotalSpace F E)) s x) (hw : MDifferentiableWithinAt IM (IB.prod 𝓘(ℝ, F)) (fun m ↦ (w m : TotalSpace F E)) s x) : MDifferentiableWithinAt IM 𝓘(ℝ) (fun m ↦ ⟪v m, w m⟫) s x := by rcases h.exists_contMDiff with ⟨g, g_smooth, hg⟩ have hb : MDifferentiableWithinAt IM IB b s x := by simp only [mdifferentiableWithinAt_totalSpace] at hv exact hv.1 simp only [hg] have : MDifferentiableWithinAt IM (IB.prod 𝓘(ℝ)) (fun m ↦ TotalSpace.mk' ℝ (E := Bundle.Trivial B ℝ) (b m) (g (b m) (v m) (w m))) s x := by apply MDifferentiableWithinAt.clm_bundle_apply₂ (F₁ := F) (F₂ := F) · exact MDifferentiableAt.comp_mdifferentiableWithinAt x (g_smooth.mdifferentiableAt le_rfl) hb · exact hv · exact hw simp only [mdifferentiableWithinAt_totalSpace] at this exact this.2 /-- Given two differentiable maps into the same fibers of a Riemannian bundle, their scalar product is differentiable. -/ lemma MDifferentiableAt.inner_bundle (hv : MDifferentiableAt IM (IB.prod 𝓘(ℝ, F)) (fun m ↦ (v m : TotalSpace F E)) x) (hw : MDifferentiableAt IM (IB.prod 𝓘(ℝ, F)) (fun m ↦ (w m : TotalSpace F E)) x) : MDifferentiableAt IM 𝓘(ℝ) (fun b ↦ ⟪v b, w b⟫) x := MDifferentiableWithinAt.inner_bundle hv hw /-- Given two differentiable maps into the same fibers of a Riemannian bundle, their scalar product is differentiable. -/ lemma MDifferentiableOn.inner_bundle (hv : MDifferentiableOn IM (IB.prod 𝓘(ℝ, F)) (fun m ↦ (v m : TotalSpace F E)) s) (hw : MDifferentiableOn IM (IB.prod 𝓘(ℝ, F)) (fun m ↦ (w m : TotalSpace F E)) s) : MDifferentiableOn IM 𝓘(ℝ) (fun b ↦ ⟪v b, w b⟫) s := fun x hx ↦ (hv x hx).inner_bundle (hw x hx) /-- Given two differentiable maps into the same fibers of a Riemannian bundle, their scalar product is differentiable. -/ lemma MDifferentiable.inner_bundle (hv : MDifferentiable IM (IB.prod 𝓘(ℝ, F)) (fun m ↦ (v m : TotalSpace F E))) (hw : MDifferentiable IM (IB.prod 𝓘(ℝ, F)) (fun m ↦ (w m : TotalSpace F E))) : MDifferentiable IM 𝓘(ℝ) (fun b ↦ ⟪v b, w b⟫) := fun x ↦ (hv x).inner_bundle (hw x) end MDifferentiable end namespace Bundle section Construction variable {EB : Type*} [NormedAddCommGroup EB] [NormedSpace ℝ EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners ℝ EB HB} {n n' : WithTop ℕ∞} {B : Type*} [TopologicalSpace B] [ChartedSpace HB B] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {E : B → Type*} [TopologicalSpace (TotalSpace F E)] [∀ b, TopologicalSpace (E b)] [∀ b, AddCommGroup (E b)] [∀ b, Module ℝ (E b)] [∀ b, IsTopologicalAddGroup (E b)] [∀ b, ContinuousConstSMul ℝ (E b)] [FiberBundle F E] [VectorBundle ℝ F E] variable (IB n F E) in /-- A family of inner product space structures on the fibers of a fiber bundle, defining the same topology as the already existing one, and varying continuously with the base point. See also `ContinuousRiemannianMetric` for a continuous version. This structure is used through `RiemannianBundle` for typeclass inference, to register the inner product space structure on the fibers without creating diamonds. -/ structure ContMDiffRiemannianMetric where /-- The scalar product along the fibers of the bundle. -/ inner (b : B) : E b →L[ℝ] E b →L[ℝ] ℝ symm (b : B) (v w : E b) : inner b v w = inner b w v pos (b : B) (v : E b) (hv : v ≠ 0) : 0 < inner b v v isVonNBounded (b : B) : IsVonNBounded ℝ {v : E b | inner b v v < 1} contMDiff : ContMDiff IB (IB.prod 𝓘(ℝ, F →L[ℝ] F →L[ℝ] ℝ)) n (fun b ↦ TotalSpace.mk' (F →L[ℝ] F →L[ℝ] ℝ) b (inner b)) /-- A smooth Riemannian metric defines in particular a continuous Riemannian metric. -/ def ContMDiffRiemannianMetric.toContinuousRiemannianMetric (g : ContMDiffRiemannianMetric IB n F E) : ContinuousRiemannianMetric F E := { g with continuous := g.contMDiff.continuous } /-- A smooth Riemannian metric defines in particular a Riemannian metric. -/ def ContMDiffRiemannianMetric.toRiemannianMetric (g : ContMDiffRiemannianMetric IB n F E) : RiemannianMetric E := g.toContinuousRiemannianMetric.toRiemannianMetric instance (g : ContMDiffRiemannianMetric IB n F E) : letI : RiemannianBundle E := ⟨g.toRiemannianMetric⟩ IsContMDiffRiemannianBundle IB n F E := letI : RiemannianBundle E := ⟨g.toRiemannianMetric⟩ ⟨g.inner, g.contMDiff, fun _ _ _ ↦ rfl⟩ end Construction end Bundle
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/LocalFrame.lean
import Mathlib.Geometry.Manifold.Algebra.Monoid import Mathlib.Geometry.Manifold.Notation import Mathlib.Geometry.Manifold.VectorBundle.MDifferentiable import Mathlib.Geometry.Manifold.VectorBundle.SmoothSection /-! # Local frames in a vector bundle Let `V → M` be a finite rank smooth vector bundle with standard fiber `F`. A family of sections `s i` of `V → M` is called a **C^k local frame** on a set `U ⊆ M` iff each section `s i` is `C^k` on `U`, and the section values `s i x` form a basis for each `x ∈ U`. We define a predicate `IsLocalFrame` for a collection of sections to be a local frame on a set, and define basic notions (such as the coefficients of a section w.r.t. a local frame, and checking the smoothness of `t` via its coefficients in a local frame). In future work, given a basis `b` for `F` and a local trivialisation `e` for `V`, we will construct a **smooth local frame** on `V` w.r.t. `e` and `b`, i.e. a collection of sections `sᵢ` of `V` which is smooth on `e.baseSet` such that `{sᵢ x}` is a basis of `V x` for each `x ∈ e.baseSet`. Any section `s` of `e` can be uniquely written as `s = ∑ i, f^i sᵢ` near `x`, and `s` is smooth at `x` iff the functions `f^i` are. In this file, we prove the latter statement for finite-rank bundles (with coefficients in a complete field). In `OrthonormalFrame.lean`, we will prove the same for real vector bundles of any rank which admit a `C^n` bundle metric. This includes bundles of finite rank, modelled on a Hilbert space or on a Banach space which has smooth partitions of unity. We will use this to construct local extensions of a vector to a section which is smooth on the trivialisation domain. ## Main definitions and results * `IsLocalFrameOn`: a family of sections `s i` of `V → M` is called a **C^k local frame** on a set `U ⊆ M` iff each section `s i` is `C^k` on `U`, and the section values `s i x` form a basis for each `x ∈ U` Suppose `{sᵢ}` is a local frame on `U`, and `hs : IsLocalFrameOn s U`. * `IsLocalFrameOn.toBasisAt hs`: for each `x ∈ U`, the vectors `sᵢ x` form a basis of `F` * `IsLocalFrameOn.coeff hs` describes the coefficient of sections of `V` w.r.t. `{sᵢ}`. `hs.coeff i` is a linear map from sections of `V` to functions `M → 𝕜`. * `IsLocalFrameOn.eventually_eq_sum_coeff_smul hs`: for a local frame `{sᵢ}` near `x`, for each section `t` we have `t = ∑ i, (hs.coeff i t) • sᵢ`. * `IsLocalFrameOn.coeff_sum_eq hs t hx` proves that `t x = ∑ i, (hs.coeff i t) x • sᵢ x`, provided that `hx : x ∈ U`. * `IsLocalFrameOn.coeff_congr hs`: the coefficient `hs.coeff i` of `t` in the local frame `{sᵢ}` only depends on `t` at `x`. * `IsLocalFrameOn.eq_iff_coeff hs`: two sections `t` and `t'` are equal at `x` if and only if their coefficients at `x` w.r.t. `{sᵢ}` agree. * `IsLocalFrameOn.contMDiffOn_of_coeff hs`: a section `t` is `C^k` on `U` if each coefficient `hs.coeff i t` is `C^k` on `U` * `IsLocalFrameOn.contMDiffAt_of_coeff hs`: a section `t` is `C^k` at `x ∈ U` if all of its frame coefficients are * `IsLocalFrameOn.contMDiffOn_off_coeff hs`: a section `t` is `C^k` on an open set `t ⊆ U` ff all of its frame coefficients are * `MDifferentiable` versions of the above three statements ## TODO * `IsLocalFrameOn.contMDiffOn_coeff hs`: if `t` is a `C^k` section, each coefficient `hs.coeff i t` is `C^k` on `U` * `IsLocalFrameOn.contMDiffAt_iff_coeff hs`: a section `t` is `C^k` at `x ∈ U` iff all of its frame coefficients are * `IsLocalFrameOn.contMDiffOn_iff_coeff hs`: a section `t` is `C^k` on an open set `t ⊆ U` iff all of its frame coefficients are * a `MDifferentiable` version of each of these ## Implementation notes Local frames use the junk value pattern: they are defined on all of `M`, but their value is only meaningful on the set on which they are a local frame. ## Tags vector bundle, local frame, smoothness -/ open Bundle Filter Function Topology Module open scoped Bundle Manifold ContDiff variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I 0 M] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- `F` model fiber (n : WithTop ℕ∞) {V : M → Type*} [TopologicalSpace (TotalSpace F V)] [∀ x, AddCommGroup (V x)] [∀ x, Module 𝕜 (V x)] [∀ x : M, TopologicalSpace (V x)] [FiberBundle F V] [VectorBundle 𝕜 F V] [ContMDiffVectorBundle n F V I] -- `V` vector bundle noncomputable section section IsLocalFrame omit [IsManifold I 0 M] [VectorBundle 𝕜 F V] variable {ι : Type*} {s s' : ι → (x : M) → V x} {u u' : Set M} {x : M} {n : WithTop ℕ∞} variable (I F n) in /-- A family of sections `s i` of `V → M` is called a **C^k local frame** on a set `U ⊆ M` iff - the section values `s i x` form a basis for each `x ∈ U`, - each section `s i` is `C^k` on `U`. -/ structure IsLocalFrameOn (s : ι → (x : M) → V x) (u : Set M) where linearIndependent {x : M} (hx : x ∈ u) : LinearIndependent 𝕜 (s · x) generating {x : M} (hx : x ∈ u) : ⊤ ≤ Submodule.span 𝕜 (Set.range (s · x)) contMDiffOn (i : ι) : CMDiff[u] n (T% (s i)) namespace IsLocalFrameOn /-- If `s = s'` on `u` and `s i` is a local frame on `u`, then so is `s'`. -/ lemma congr (hs : IsLocalFrameOn I F n s u) (hs' : ∀ i, ∀ x, x ∈ u → s i x = s' i x) : IsLocalFrameOn I F n s' u where linearIndependent := by intro x hx have := hs.linearIndependent hx simp_all generating := by intro x hx have := hs.generating hx simp_all contMDiffOn i := (hs.contMDiffOn i).congr (by simp +contextual [hs']) lemma mono (hs : IsLocalFrameOn I F n s u) (hu'u : u' ⊆ u) : IsLocalFrameOn I F n s u' where linearIndependent := by intro x hx exact hs.linearIndependent (hu'u hx) generating := by intro x hx exact hs.generating (hu'u hx) contMDiffOn i := (hs.contMDiffOn i).mono hu'u lemma contMDiffAt (hs : IsLocalFrameOn I F n s u) (hu : IsOpen u) (hx : x ∈ u) (i : ι) : CMDiffAt n (T% (s i)) x := (hs.contMDiffOn i).contMDiffAt <| hu.mem_nhds hx /-- Given a local frame `{s i}` on `U ∋ x`, returns the basis `{s i}` of `V x` -/ def toBasisAt (hs : IsLocalFrameOn I F n s u) (hx : x ∈ u) : Basis ι 𝕜 (V x) := Basis.mk (hs.linearIndependent hx) (hs.generating hx) @[simp] lemma toBasisAt_coe (hs : IsLocalFrameOn I F n s u) (hx : x ∈ u) (i : ι) : toBasisAt hs hx i = s i x := by simpa only [toBasisAt] using Basis.mk_apply (hs.linearIndependent hx) (hs.generating hx) i open scoped Classical in /-- Coefficients of a section `s` of `V` w.r.t. a local frame `{s i}` on `u`. Outside of `u`, this returns the junk value 0. -/ def coeff (hs : IsLocalFrameOn I F n s u) (i : ι) : (Π x : M, V x) →ₗ[𝕜] M → 𝕜 where toFun s x := if hx : x ∈ u then (hs.toBasisAt hx).repr (s x) i else 0 map_add' s s' := by ext x by_cases hx : x ∈ u <;> simp [hx] map_smul' c s := by ext x by_cases hx : x ∈ u <;> simp [hx] variable {x : M} @[simp] lemma coeff_apply_of_notMem (hs : IsLocalFrameOn I F n s u) (hx : x ∉ u) (t : Π x : M, V x) (i : ι) : hs.coeff i t x = 0 := by simp [coeff, hx] @[simp] lemma coeff_apply_of_mem (hs : IsLocalFrameOn I F n s u) (hx : x ∈ u) (t : Π x : M, V x) (i : ι) : hs.coeff i t x = (hs.toBasisAt hx).repr (t x) i := by simp [coeff, hx] -- TODO: add uniqueness of the decomposition; follows from the IsBasis property in the definition lemma coeff_sum_eq [Fintype ι] (hs : IsLocalFrameOn I F n s u) (t : Π x : M, V x) (hx : x ∈ u) : t x = ∑ i, (hs.coeff i t x) • (s i x) := by simpa [coeff, hx] using (Basis.sum_repr (hs.toBasisAt hx) (t x)).symm /-- A local frame locally spans the space of sections for `V`: for each local frame `s i` on an open set `u` around `x`, we have `t = ∑ i, (hs.coeff i t) • (s i x)` near `x`. -/ lemma eventually_eq_sum_coeff_smul [Fintype ι] (hs : IsLocalFrameOn I F n s u) (t : Π x : M, V x) (hu'' : u ∈ 𝓝 x) : ∀ᶠ x' in 𝓝 x, t x' = ∑ i, (hs.coeff i t x') • (s i x') := eventually_of_mem hu'' fun _ hx ↦ hs.coeff_sum_eq _ hx variable {t t' : Π x : M, V x} /-- The coefficients of `t` in a local frame at `x` only depend on `t` at `x`. -/ lemma coeff_congr (hs : IsLocalFrameOn I F n s u) (htt' : t x = t' x) (i : ι) : hs.coeff i t x = hs.coeff i t' x := by by_cases hxe : x ∈ u · simp [coeff, hxe] congr · simp [coeff, hxe] /-- If `s` and `s'` are local frames which are equal at `x`, a section `t` has equal frame coefficients in them. -/ lemma coeff_eq_of_eq (hs : IsLocalFrameOn I F n s u) (hs' : IsLocalFrameOn I F n s' u) (hss' : ∀ i, s i x = s' i x) {t : Π x : M, V x} (i : ι) : hs.coeff i t x = hs'.coeff i t x := by by_cases hxe : x ∈ u · simp [coeff, hxe] simp_all [toBasisAt] · simp [coeff, hxe] /-- Two sections `s` and `t` are equal at `x` if and only if their coefficients w.r.t. some local frame at `x` agree. -/ lemma eq_iff_coeff [Fintype ι] (hs : IsLocalFrameOn I F n s u) (hx : x ∈ u) : t x = t' x ↔ ∀ i, hs.coeff i t x = hs.coeff i t' x := ⟨fun h i ↦ hs.coeff_congr h i, fun h ↦ by simp +contextual [h, hs.coeff_sum_eq t hx, hs.coeff_sum_eq t' hx]⟩ lemma coeff_apply_zero_at (hs : IsLocalFrameOn I F n s u) (ht : t x = 0) (i : ι) : hs.coeff i t x = 0 := by simp [hs.coeff_congr (t' := 0) ht] variable (hs : IsLocalFrameOn I F n s u) [VectorBundle 𝕜 F V] /-- Given a local frame `s i ` on `u`, if a section `t` has `C^k` coefficients on `u` w.r.t. `s i`, then `t` is `C^n` on `u`. -/ lemma contMDiffOn_of_coeff [Fintype ι] (h : ∀ i, CMDiff[u] n (hs.coeff i t)) : CMDiff[u] n (T% t) := by have this (i) : CMDiff[u] n (T% (hs.coeff i t • s i)) := (h i).smul_section (hs.contMDiffOn i) have almost : CMDiff[u] n (T% (fun x ↦ ∑ i, (hs.coeff i t) x • s i x)) := .sum_section fun i _ ↦ this i apply almost.congr intro y hy simp [hs.coeff_sum_eq t hy] /-- Given a local frame `s i` on a neighbourhood `u` of `x`, if a section `t` has `C^k` coefficients at `x` w.r.t. `s i`, then `t` is `C^n` at `x`. -/ lemma contMDiffAt_of_coeff [Fintype ι] (h : ∀ i, CMDiffAt n (hs.coeff i t) x) (hu : u ∈ 𝓝 x) : CMDiffAt n (T% t) x := by have almost : CMDiffAt n (T% (fun x ↦ ∑ i, (hs.coeff i t) x • s i x)) x := .sum_section (fun i _ ↦ (h i).smul_section <| (hs.contMDiffOn i).contMDiffAt hu) exact almost.congr_of_eventuallyEq <| (hs.eventually_eq_sum_coeff_smul t hu).mono (by simp) /-- Given a local frame `s i` on an open set `u` containing `x`, if a section `t` has `C^k` coefficients at `x ∈ u` w.r.t. `s i`, then `t` is `C^n` at `x`. -/ lemma contMDiffAt_of_coeff_aux [Fintype ι] (h : ∀ i, CMDiffAt n (hs.coeff i t) x) (hu : IsOpen u) (hx : x ∈ u) : CMDiffAt n (T% t) x := hs.contMDiffAt_of_coeff h (hu.mem_nhds hx) section variable (hs : IsLocalFrameOn I F 1 s u) /-- Given a local frame `s i ` on `u`, if a section `t` has differentiable coefficients on `u` w.r.t. `s i`, then `t` is differentiable on `u`. -/ lemma mdifferentiableOn_of_coeff [Fintype ι] (h : ∀ i, MDiff[u] (hs.coeff i t)) : MDiff[u] (T% t) := by have this (i) : MDiff[u] (T% (hs.coeff i t • s i)) := (h i).smul_section ((hs.contMDiffOn i).mdifferentiableOn le_rfl) have almost : MDiff[u] (T% (fun x ↦ ∑ i, (hs.coeff i t) x • s i x)) := .sum_section (fun i _ hx ↦ this i _ hx) apply almost.congr intro y hy simp [hs.coeff_sum_eq t hy] /-- Given a local frame `s i` on a neighbourhood `u` of `x`, if a section `t` has differentiable coefficients at `x` w.r.t. `s i`, then `t` is differentiable at `x`. -/ lemma mdifferentiableAt_of_coeff [Fintype ι] (h : ∀ i, MDiffAt (hs.coeff i t) x) (hu : u ∈ 𝓝 x) : MDiffAt (T% t) x := by have almost : MDiffAt (T% (fun x ↦ ∑ i, (hs.coeff i t) x • s i x)) x := .sum_section (fun i ↦ (h i).smul_section <| ((hs.contMDiffOn i).mdifferentiableOn le_rfl).mdifferentiableAt hu) exact almost.congr_of_eventuallyEq <| (hs.eventually_eq_sum_coeff_smul t hu).mono (by simp) /-- Given a local frame `s i` on open set `u` containing `x`, if a section `t` has differentiable coefficients at `x ∈ u` w.r.t. `s i`, then `t` is differentiable at `x`. -/ lemma mdifferentiableAt_of_coeff_aux [Fintype ι] (h : ∀ i, MDiffAt (hs.coeff i t) x) (hu : IsOpen u) (hx : x ∈ u) : MDiffAt (T% t) x := hs.mdifferentiableAt_of_coeff h (hu.mem_nhds hx) end end IsLocalFrameOn end IsLocalFrame
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/Basic.lean
import Mathlib.Geometry.Manifold.ContMDiff.Atlas import Mathlib.Geometry.Manifold.VectorBundle.FiberwiseLinear import Mathlib.Topology.VectorBundle.Constructions /-! # `C^n` vector bundles This file defines `C^n` vector bundles over a manifold. Let `E` be a topological vector bundle, with model fiber `F` and base space `B`. We consider `E` as carrying a charted space structure given by its trivializations -- these are charts to `B × F`. Then, by "composition", if `B` is itself a charted space over `H` (e.g. a smooth manifold), then `E` is also a charted space over `H × F`. Now, we define `ContMDiffVectorBundle` as the `Prop` of having `C^n` transition functions. Recall the structure groupoid `contMDiffFiberwiseLinear` on `B × F` consisting of `C^n`, fiberwise linear open partial homeomorphisms. We show that our definition of "`C^n` vector bundle" implies `HasGroupoid` for this groupoid, and show (by a "composition" of `HasGroupoid` instances) that this means that a `C^n` vector bundle is a `C^n` manifold. Since `ContMDiffVectorBundle` is a mixin, it should be easy to make variants and for many such variants to coexist -- vector bundles can be `C^n` vector bundles over several different base fields, etc. ## Main definitions and constructions * `FiberBundle.chartedSpace`: A fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `B × F`. * `FiberBundle.chartedSpace'`: Let `B` be a charted space modelled on `HB`. Then a fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `HB.prod F`. * `ContMDiffVectorBundle`: Mixin class stating that a (topological) `VectorBundle` is `C^n`, in the sense of having `C^n` transition functions, where the smoothness index `n` belongs to `WithTop ℕ∞`. * `ContMDiffFiberwiseLinear.hasGroupoid`: For a `C^n` vector bundle `E` over `B` with fiber modelled on `F`, the change-of-co-ordinates between two trivializations `e`, `e'` for `E`, considered as charts to `B × F`, is `C^n` and fiberwise linear, in the sense of belonging to the structure groupoid `contMDiffFiberwiseLinear`. * `Bundle.TotalSpace.isManifold`: A `C^n` vector bundle is naturally a `C^n` manifold. * `VectorBundleCore.instContMDiffVectorBundle`: If a (topological) `VectorBundleCore` is `C^n`, in the sense of having `C^n` transition functions (cf. `VectorBundleCore.IsContMDiff`), then the vector bundle constructed from it is a `C^n` vector bundle. * `VectorPrebundle.contMDiffVectorBundle`: If a `VectorPrebundle` is `C^n`, in the sense of having `C^n` transition functions (cf. `VectorPrebundle.IsContMDiff`), then the vector bundle constructed from it is a `C^n` vector bundle. * `Bundle.Prod.contMDiffVectorBundle`: The direct sum of two `C^n` vector bundles is a `C^n` vector bundle. -/ assert_not_exists mfderiv open Bundle Set OpenPartialHomeomorph open Function (id_def) open Filter open scoped Manifold Bundle Topology ContDiff variable {n : WithTop ℕ∞} {𝕜 B B' F M : Type*} {E : B → Type*} /-! ### Charted space structure on a fiber bundle -/ section variable [TopologicalSpace F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {HB : Type*} [TopologicalSpace HB] [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E] /-- A fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `B × F`. -/ instance FiberBundle.chartedSpace' : ChartedSpace (B × F) (TotalSpace F E) where atlas := (fun e : Trivialization F (π F E) => e.toOpenPartialHomeomorph) '' trivializationAtlas F E chartAt x := (trivializationAt F E x.proj).toOpenPartialHomeomorph mem_chart_source x := (trivializationAt F E x.proj).mem_source.mpr (mem_baseSet_trivializationAt F E x.proj) chart_mem_atlas _ := mem_image_of_mem _ (trivialization_mem_atlas F E _) theorem FiberBundle.chartedSpace'_chartAt (x : TotalSpace F E) : chartAt (B × F) x = (trivializationAt F E x.proj).toOpenPartialHomeomorph := rfl /- Porting note: In Lean 3, the next instance was inside a section with locally reducible `ModelProd` and it used `ModelProd B F` as the intermediate space. Using `B × F` in the middle gives the same instance. -/ --attribute [local reducible] ModelProd /-- Let `B` be a charted space modelled on `HB`. Then a fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `HB.prod F`. -/ instance FiberBundle.chartedSpace : ChartedSpace (ModelProd HB F) (TotalSpace F E) := ChartedSpace.comp _ (B × F) _ theorem FiberBundle.chartedSpace_chartAt (x : TotalSpace F E) : chartAt (ModelProd HB F) x = (trivializationAt F E x.proj).toOpenPartialHomeomorph ≫ₕ (chartAt HB x.proj).prod (OpenPartialHomeomorph.refl F) := by dsimp only [chartAt_comp, prodChartedSpace_chartAt, FiberBundle.chartedSpace'_chartAt, chartAt_self_eq] rw [Trivialization.coe_coe, Trivialization.coe_fst' _ (mem_baseSet_trivializationAt F E x.proj)] theorem FiberBundle.chartedSpace_chartAt_symm_fst (x : TotalSpace F E) (y : ModelProd HB F) (hy : y ∈ (chartAt (ModelProd HB F) x).target) : ((chartAt (ModelProd HB F) x).symm y).proj = (chartAt HB x.proj).symm y.1 := by simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] at hy ⊢ exact (trivializationAt F E x.proj).proj_symm_apply hy.2 end section variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners 𝕜 EB HB} (E' : B → Type*) [∀ x, Zero (E' x)] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] variable [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E] protected theorem FiberBundle.extChartAt (x : TotalSpace F E) : extChartAt (IB.prod 𝓘(𝕜, F)) x = (trivializationAt F E x.proj).toPartialEquiv ≫ (extChartAt IB x.proj).prod (PartialEquiv.refl F) := by simp_rw [extChartAt, FiberBundle.chartedSpace_chartAt, extend] simp only [PartialEquiv.trans_assoc, mfld_simps] -- Porting note: should not be needed rw [PartialEquiv.prod_trans, PartialEquiv.refl_trans] protected theorem FiberBundle.extChartAt_target (x : TotalSpace F E) : (extChartAt (IB.prod 𝓘(𝕜, F)) x).target = ((extChartAt IB x.proj).target ∩ (extChartAt IB x.proj).symm ⁻¹' (trivializationAt F E x.proj).baseSet) ×ˢ univ := by rw [FiberBundle.extChartAt, PartialEquiv.trans_target, Trivialization.target_eq, inter_prod] rfl theorem FiberBundle.writtenInExtChartAt_trivializationAt {x : TotalSpace F E} {y} (hy : y ∈ (extChartAt (IB.prod 𝓘(𝕜, F)) x).target) : writtenInExtChartAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) x (trivializationAt F E x.proj) y = y := writtenInExtChartAt_chartAt_comp _ hy theorem FiberBundle.writtenInExtChartAt_trivializationAt_symm {x : TotalSpace F E} {y} (hy : y ∈ (extChartAt (IB.prod 𝓘(𝕜, F)) x).target) : writtenInExtChartAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) (trivializationAt F E x.proj x) (trivializationAt F E x.proj).toOpenPartialHomeomorph.symm y = y := writtenInExtChartAt_chartAt_symm_comp _ hy /-! ### Regularity of maps in/out fiber bundles Note: For these results we don't need that the bundle is a `C^n` vector bundle, or even a vector bundle at all, just that it is a fiber bundle over a charted base space. -/ namespace Bundle /-- Characterization of `C^n` functions into a vector bundle. Version at a point within a set. -/ theorem contMDiffWithinAt_totalSpace {f : M → TotalSpace F E} {s : Set M} {x₀ : M} : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F)) n f s x₀ ↔ ContMDiffWithinAt IM IB n (fun x => (f x).proj) s x₀ ∧ ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E (f x₀).proj (f x)).2) s x₀ := by simp +singlePass only [contMDiffWithinAt_iff_target] rw [and_and_and_comm, ← FiberBundle.continuousWithinAt_totalSpace, and_congr_right_iff] intro hf simp_rw [modelWithCornersSelf_prod, FiberBundle.extChartAt, Function.comp_def, PartialEquiv.trans_apply, PartialEquiv.prod_coe, PartialEquiv.refl_coe, extChartAt_self_apply, modelWithCornersSelf_coe, Function.id_def, ← chartedSpaceSelf_prod] refine (contMDiffWithinAt_prod_iff _).trans (and_congr ?_ Iff.rfl) have h1 : (fun x => (f x).proj) ⁻¹' (trivializationAt F E (f x₀).proj).baseSet ∈ 𝓝[s] x₀ := ((FiberBundle.continuous_proj F E).continuousWithinAt.comp hf (mapsTo_image f s)) ((Trivialization.open_baseSet _).mem_nhds (mem_baseSet_trivializationAt F E _)) refine EventuallyEq.contMDiffWithinAt_iff (eventually_of_mem h1 fun x hx => ?_) ?_ · simp_rw [Function.comp, OpenPartialHomeomorph.coe_coe, Trivialization.coe_coe] rw [Trivialization.coe_fst'] exact hx · simp only [mfld_simps] /-- Characterization of `C^n` functions into a vector bundle. Version at a point. -/ theorem contMDiffAt_totalSpace {f : M → TotalSpace F E} {x₀ : M} : ContMDiffAt IM (IB.prod 𝓘(𝕜, F)) n f x₀ ↔ ContMDiffAt IM IB n (fun x ↦ (f x).proj) x₀ ∧ ContMDiffAt IM 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E (f x₀).proj (f x)).2) x₀ := by simp_rw [← contMDiffWithinAt_univ]; exact contMDiffWithinAt_totalSpace /-- Characterization of `C^n` sections within a set at a point of a vector bundle. -/ theorem contMDiffWithinAt_section {s : ∀ x, E x} {a : Set B} {x₀ : B} : ContMDiffWithinAt IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) a x₀ ↔ ContMDiffWithinAt IB 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E x₀ ⟨x, s x⟩).2) a x₀ := by simp_rw [contMDiffWithinAt_totalSpace, and_iff_right_iff_imp]; intro; exact contMDiffWithinAt_id /-- Characterization of `C^n` sections of a vector bundle. -/ theorem contMDiffAt_section {s : ∀ x, E x} (x₀ : B) : ContMDiffAt IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀ ↔ ContMDiffAt IB 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E x₀ ⟨x, s x⟩).2) x₀ := by simp_rw [contMDiffAt_totalSpace, and_iff_right_iff_imp]; intro; exact contMDiffAt_id variable (E) theorem contMDiff_proj : ContMDiff (IB.prod 𝓘(𝕜, F)) IB n (π F E) := fun x ↦ by have : ContMDiffAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n id x := contMDiffAt_id rw [contMDiffAt_totalSpace] at this exact this.1 theorem contMDiffOn_proj {s : Set (TotalSpace F E)} : ContMDiffOn (IB.prod 𝓘(𝕜, F)) IB n (π F E) s := (contMDiff_proj E).contMDiffOn theorem contMDiffAt_proj {p : TotalSpace F E} : ContMDiffAt (IB.prod 𝓘(𝕜, F)) IB n (π F E) p := (contMDiff_proj E).contMDiffAt theorem contMDiffWithinAt_proj {s : Set (TotalSpace F E)} {p : TotalSpace F E} : ContMDiffWithinAt (IB.prod 𝓘(𝕜, F)) IB n (π F E) s p := (contMDiffAt_proj E).contMDiffWithinAt variable (𝕜) [∀ x, AddCommMonoid (E x)] variable [∀ x, Module 𝕜 (E x)] [VectorBundle 𝕜 F E] theorem contMDiff_zeroSection : ContMDiff IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) := by intro x unfold zeroSection rw [contMDiffAt_section] apply (contMDiffAt_const (c := 0)).congr_of_eventuallyEq filter_upwards [(trivializationAt F E x).open_baseSet.mem_nhds (mem_baseSet_trivializationAt F E x)] with y hy using congr_arg Prod.snd <| (trivializationAt F E x).zeroSection 𝕜 hy theorem contMDiffOn_zeroSection {t : Set B} : ContMDiffOn IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) t := (contMDiff_zeroSection _ _).contMDiffOn theorem contMDiffAt_zeroSection {x : B} : ContMDiffAt IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) x := (contMDiff_zeroSection _ _).contMDiffAt theorem contMDiffWithinAt_zeroSection {t : Set B} {x : B} : ContMDiffWithinAt IB (IB.prod 𝓘(𝕜, F)) n (zeroSection F E) t x := (contMDiff_zeroSection _ _ x).contMDiffWithinAt end Bundle end /-! ### `C^n` vector bundles -/ variable [NontriviallyNormedField 𝕜] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners 𝕜 EB HB} [TopologicalSpace B] [ChartedSpace HB B] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] [∀ x, AddCommMonoid (E x)] [∀ x, Module 𝕜 (E x)] [NormedAddCommGroup F] [NormedSpace 𝕜 F] section WithTopology variable [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] (F E) variable [FiberBundle F E] [VectorBundle 𝕜 F E] variable (n IB) in /-- When `B` is a manifold with respect to a model `IB` and `E` is a topological vector bundle over `B` with fibers isomorphic to `F`, then `ContMDiffVectorBundle n F E IB` registers that the bundle is `C^n`, in the sense of having `C^n` transition functions. This is a mixin, not carrying any new data. -/ class ContMDiffVectorBundle : Prop where protected contMDiffOn_coordChangeL : ∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'], ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) (e.baseSet ∩ e'.baseSet) variable {F E} in protected theorem ContMDiffVectorBundle.of_le {m n : WithTop ℕ∞} (hmn : m ≤ n) [h : ContMDiffVectorBundle n F E IB] : ContMDiffVectorBundle m F E IB := ⟨fun e e' _ _ ↦ (h.contMDiffOn_coordChangeL e e').of_le hmn⟩ instance {a : WithTop ℕ∞} [ContMDiffVectorBundle ∞ F E IB] [h : ENat.LEInfty a] : ContMDiffVectorBundle a F E IB := ContMDiffVectorBundle.of_le h.out instance {a : WithTop ℕ∞} [ContMDiffVectorBundle ω F E IB] : ContMDiffVectorBundle a F E IB := ContMDiffVectorBundle.of_le le_top instance [ContMDiffVectorBundle 2 F E IB] : ContMDiffVectorBundle 1 F E IB := ContMDiffVectorBundle.of_le one_le_two instance : ContMDiffVectorBundle 0 F E IB := by constructor intro e e' he he' rw [contMDiffOn_zero_iff] exact VectorBundle.continuousOn_coordChange' e e' variable [ContMDiffVectorBundle n F E IB] section ContMDiffCoordChange variable {F E} variable (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'] theorem contMDiffOn_coordChangeL : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) (e.baseSet ∩ e'.baseSet) := ContMDiffVectorBundle.contMDiffOn_coordChangeL e e' theorem contMDiffOn_symm_coordChangeL : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => ((e.coordChangeL 𝕜 e' b).symm : F →L[𝕜] F)) (e.baseSet ∩ e'.baseSet) := by rw [inter_comm] refine (ContMDiffVectorBundle.contMDiffOn_coordChangeL e' e).congr fun b hb ↦ ?_ rw [e.symm_coordChangeL e' hb] variable {e e'} theorem contMDiffAt_coordChangeL {x : B} (h : x ∈ e.baseSet) (h' : x ∈ e'.baseSet) : ContMDiffAt IB 𝓘(𝕜, F →L[𝕜] F) n (fun b : B => (e.coordChangeL 𝕜 e' b : F →L[𝕜] F)) x := (contMDiffOn_coordChangeL e e').contMDiffAt <| (e.open_baseSet.inter e'.open_baseSet).mem_nhds ⟨h, h'⟩ variable {s : Set M} {f : M → B} {g : M → F} {x : M} protected theorem ContMDiffWithinAt.coordChangeL (hf : ContMDiffWithinAt IM IB n f s x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : ContMDiffWithinAt IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) s x := (contMDiffAt_coordChangeL he he').comp_contMDiffWithinAt _ hf protected nonrec theorem ContMDiffAt.coordChangeL (hf : ContMDiffAt IM IB n f x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : ContMDiffAt IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) x := hf.coordChangeL he he' protected theorem ContMDiffOn.coordChangeL (hf : ContMDiffOn IM IB n f s) (he : MapsTo f s e.baseSet) (he' : MapsTo f s e'.baseSet) : ContMDiffOn IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) s := fun x hx ↦ (hf x hx).coordChangeL (he hx) (he' hx) protected theorem ContMDiff.coordChangeL (hf : ContMDiff IM IB n f) (he : ∀ x, f x ∈ e.baseSet) (he' : ∀ x, f x ∈ e'.baseSet) : ContMDiff IM 𝓘(𝕜, F →L[𝕜] F) n (fun y ↦ (e.coordChangeL 𝕜 e' (f y) : F →L[𝕜] F)) := fun x ↦ (hf x).coordChangeL (he x) (he' x) protected theorem ContMDiffWithinAt.coordChange (hf : ContMDiffWithinAt IM IB n f s x) (hg : ContMDiffWithinAt IM 𝓘(𝕜, F) n g s x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) s x := by refine ((hf.coordChangeL he he').clm_apply hg).congr_of_eventuallyEq ?_ ?_ · have : e.baseSet ∩ e'.baseSet ∈ 𝓝 (f x) := (e.open_baseSet.inter e'.open_baseSet).mem_nhds ⟨he, he'⟩ filter_upwards [hf.continuousWithinAt this] with y hy exact (Trivialization.coordChangeL_apply' e e' hy (g y)).symm · exact (Trivialization.coordChangeL_apply' e e' ⟨he, he'⟩ (g x)).symm protected nonrec theorem ContMDiffAt.coordChange (hf : ContMDiffAt IM IB n f x) (hg : ContMDiffAt IM 𝓘(𝕜, F) n g x) (he : f x ∈ e.baseSet) (he' : f x ∈ e'.baseSet) : ContMDiffAt IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) x := hf.coordChange hg he he' protected theorem ContMDiffOn.coordChange (hf : ContMDiffOn IM IB n f s) (hg : ContMDiffOn IM 𝓘(𝕜, F) n g s) (he : MapsTo f s e.baseSet) (he' : MapsTo f s e'.baseSet) : ContMDiffOn IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) s := fun x hx ↦ (hf x hx).coordChange (hg x hx) (he hx) (he' hx) protected theorem ContMDiff.coordChange (hf : ContMDiff IM IB n f) (hg : ContMDiff IM 𝓘(𝕜, F) n g) (he : ∀ x, f x ∈ e.baseSet) (he' : ∀ x, f x ∈ e'.baseSet) : ContMDiff IM 𝓘(𝕜, F) n (fun y ↦ e.coordChange e' (f y) (g y)) := fun x ↦ (hf x).coordChange (hg x) (he x) (he' x) variable (e e') variable (IB) in theorem Trivialization.contMDiffOn_symm_trans : ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n (e.toOpenPartialHomeomorph.symm ≫ₕ e'.toOpenPartialHomeomorph) (e.target ∩ e'.target) := by have Hmaps : MapsTo Prod.fst (e.target ∩ e'.target) (e.baseSet ∩ e'.baseSet) := fun x hx ↦ ⟨e.mem_target.1 hx.1, e'.mem_target.1 hx.2⟩ rw [mapsTo_inter] at Hmaps -- TODO: drop `congr` https://github.com/leanprover-community/mathlib4/issues/5473 refine (contMDiffOn_fst.prodMk (contMDiffOn_fst.coordChange contMDiffOn_snd Hmaps.1 Hmaps.2)).congr ?_ rintro ⟨b, x⟩ hb refine Prod.ext ?_ rfl have : (e.toOpenPartialHomeomorph.symm (b, x)).1 ∈ e'.baseSet := by simp_all only [Trivialization.mem_target, mfld_simps] exact (e'.coe_fst' this).trans (e.proj_symm_apply hb.1) variable {e e'} theorem ContMDiffWithinAt.change_section_trivialization {f : M → TotalSpace F E} (hp : ContMDiffWithinAt IM IB n (π F E ∘ f) s x) (hf : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e (f y)).2) s x) (he : f x ∈ e.source) (he' : f x ∈ e'.source) : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e' (f y)).2) s x := by rw [Trivialization.mem_source] at he he' refine (hp.coordChange hf he he').congr_of_eventuallyEq ?_ ?_ · filter_upwards [hp.continuousWithinAt (e.open_baseSet.mem_nhds he)] with y hy rw [Function.comp_apply, e.coordChange_apply_snd _ hy] · rw [Function.comp_apply, e.coordChange_apply_snd _ he] theorem Trivialization.contMDiffWithinAt_snd_comp_iff₂ {f : M → TotalSpace F E} (hp : ContMDiffWithinAt IM IB n (π F E ∘ f) s x) (he : f x ∈ e.source) (he' : f x ∈ e'.source) : ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e (f y)).2) s x ↔ ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun y ↦ (e' (f y)).2) s x := ⟨(hp.change_section_trivialization · he he'), (hp.change_section_trivialization · he' he)⟩ end ContMDiffCoordChange variable [IsManifold IB n B] in /-- For a `C^n` vector bundle `E` over `B` with fiber modelled on `F`, the change-of-co-ordinates between two trivializations `e`, `e'` for `E`, considered as charts to `B × F`, is `C^n` and fiberwise linear. -/ instance ContMDiffFiberwiseLinear.hasGroupoid : HasGroupoid (TotalSpace F E) (contMDiffFiberwiseLinear B F IB n) where compatible := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ haveI : MemTrivializationAtlas e := ⟨he⟩ haveI : MemTrivializationAtlas e' := ⟨he'⟩ rw [mem_contMDiffFiberwiseLinear_iff] refine ⟨_, _, e.open_baseSet.inter e'.open_baseSet, contMDiffOn_coordChangeL e e', contMDiffOn_symm_coordChangeL e e', ?_⟩ refine OpenPartialHomeomorph.eqOnSourceSetoid.symm ⟨?_, ?_⟩ · simp only [FiberwiseLinear.openPartialHomeomorph, trans_toPartialEquiv, symm_toPartialEquiv, e.symm_trans_source_eq e'] · rintro ⟨b, v⟩ hb exact (e.apply_symm_apply_eq_coordChangeL e' hb.1 v).symm variable [IsManifold IB n B] in /-- A `C^n` vector bundle `E` is naturally a `C^n` manifold. -/ instance Bundle.TotalSpace.isManifold : IsManifold (IB.prod 𝓘(𝕜, F)) n (TotalSpace F E) := by refine { StructureGroupoid.HasGroupoid.comp (contMDiffFiberwiseLinear B F IB n) ?_ with } intro e he rw [mem_contMDiffFiberwiseLinear_iff] at he obtain ⟨φ, U, hU, hφ, h2φ, heφ⟩ := he rw [isLocalStructomorphOn_contDiffGroupoid_iff] refine ⟨ContMDiffOn.congr ?_ (EqOnSource.eqOn heφ), ContMDiffOn.congr ?_ (EqOnSource.eqOn (EqOnSource.symm' heφ))⟩ · rw [EqOnSource.source_eq heφ] apply contMDiffOn_fst.prodMk exact (hφ.comp contMDiffOn_fst <| prod_subset_preimage_fst _ _).clm_apply contMDiffOn_snd · rw [EqOnSource.target_eq heφ] apply contMDiffOn_fst.prodMk exact (h2φ.comp contMDiffOn_fst <| prod_subset_preimage_fst _ _).clm_apply contMDiffOn_snd section variable {F E} variable {e e' : Trivialization F (π F E)} [MemTrivializationAtlas e] [MemTrivializationAtlas e'] theorem Trivialization.contMDiffWithinAt_iff {f : M → TotalSpace F E} {s : Set M} {x₀ : M} (he : f x₀ ∈ e.source) : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F)) n f s x₀ ↔ ContMDiffWithinAt IM IB n (fun x => (f x).proj) s x₀ ∧ ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun x ↦ (e (f x)).2) s x₀ := contMDiffWithinAt_totalSpace.trans <| and_congr_right fun h ↦ Trivialization.contMDiffWithinAt_snd_comp_iff₂ h FiberBundle.mem_trivializationAt_proj_source he theorem Trivialization.contMDiffAt_iff {f : M → TotalSpace F E} {x₀ : M} (he : f x₀ ∈ e.source) : ContMDiffAt IM (IB.prod 𝓘(𝕜, F)) n f x₀ ↔ ContMDiffAt IM IB n (fun x => (f x).proj) x₀ ∧ ContMDiffAt IM 𝓘(𝕜, F) n (fun x ↦ (e (f x)).2) x₀ := e.contMDiffWithinAt_iff he theorem Trivialization.contMDiffOn_iff {f : M → TotalSpace F E} {s : Set M} (he : MapsTo f s e.source) : ContMDiffOn IM (IB.prod 𝓘(𝕜, F)) n f s ↔ ContMDiffOn IM IB n (fun x => (f x).proj) s ∧ ContMDiffOn IM 𝓘(𝕜, F) n (fun x ↦ (e (f x)).2) s := by simp only [ContMDiffOn, ← forall_and] exact forall₂_congr fun x hx ↦ e.contMDiffWithinAt_iff (he hx) theorem Trivialization.contMDiff_iff {f : M → TotalSpace F E} (he : ∀ x, f x ∈ e.source) : ContMDiff IM (IB.prod 𝓘(𝕜, F)) n f ↔ ContMDiff IM IB n (fun x => (f x).proj) ∧ ContMDiff IM 𝓘(𝕜, F) n (fun x ↦ (e (f x)).2) := (forall_congr' fun x ↦ e.contMDiffAt_iff (he x)).trans forall_and theorem Trivialization.contMDiffOn (e : Trivialization F (π F E)) [MemTrivializationAtlas e] : ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n e e.source := by have : ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n id e.source := contMDiffOn_id rw [e.contMDiffOn_iff (mapsTo_id _)] at this exact (this.1.prodMk this.2).congr fun x hx ↦ (e.mk_proj_snd hx).symm theorem Trivialization.contMDiffOn_symm (e : Trivialization F (π F E)) [MemTrivializationAtlas e] : ContMDiffOn (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) n e.toOpenPartialHomeomorph.symm e.target := by rw [e.contMDiffOn_iff e.toOpenPartialHomeomorph.symm_mapsTo] refine ⟨contMDiffOn_fst.congr fun x hx ↦ e.proj_symm_apply hx, contMDiffOn_snd.congr fun x hx ↦ ?_⟩ rw [e.apply_symm_apply hx] /-- Smoothness of a `C^n` section at `x₀` within a set `a` can be determined using any trivialisation whose `baseSet` contains `x₀`. -/ theorem Trivialization.contMDiffWithinAt_section {s : ∀ x, E x} (a : Set B) {x₀ : B} {e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)} [MemTrivializationAtlas e] (hx₀ : x₀ ∈ e.baseSet) : ContMDiffWithinAt IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) a x₀ ↔ ContMDiffWithinAt IB 𝓘(𝕜, F) n (fun x ↦ (e ⟨x, s x⟩).2) a x₀ := by rw [e.contMDiffWithinAt_iff] · change ContMDiffWithinAt IB IB n id a x₀ ∧ _ ↔ _ simp [contMDiffWithinAt_id] · rwa [mem_source] /-- Smoothness of a `C^n` section at `x₀` can be determined using any trivialisation whose `baseSet` contains `x₀`. -/ theorem Trivialization.contMDiffAt_section_iff {s : ∀ x, E x} {x₀ : B} (e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)) [MemTrivializationAtlas e] (hx₀ : x₀ ∈ e.baseSet) : ContMDiffAt IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀ ↔ ContMDiffAt IB 𝓘(𝕜, F) n (fun x ↦ (e ⟨x, s x⟩).2) x₀ := by simp_rw [← contMDiffWithinAt_univ] exact e.contMDiffWithinAt_section univ hx₀ @[deprecated (since := "2025-09-15")] alias contMDiffAt_section_of_mem_baseSet := Trivialization.contMDiffAt_section_iff /-- Smoothness of a `C^n` section on `s` can be determined using any trivialisation whose `baseSet` contains `s`. -/ theorem Trivialization.contMDiffOn_section_iff {s : ∀ x, E x} {a : Set B} (e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)) [MemTrivializationAtlas e] (ha : IsOpen a) (ha' : a ⊆ e.baseSet) : ContMDiffOn IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) a ↔ ContMDiffOn IB 𝓘(𝕜, F) n (fun x ↦ (e ⟨x, s x⟩).2) a := by refine ⟨fun h x hx ↦ ?_, fun h x hx ↦ ?_⟩ <;> have := (h x hx).contMDiffAt <| ha.mem_nhds hx · exact ((e.contMDiffAt_section_iff (ha' hx)).mp this).contMDiffWithinAt · exact ((e.contMDiffAt_section_iff (ha' hx)).mpr this).contMDiffWithinAt @[deprecated (since := "2025-09-15")] alias contMDiffOn_section_of_mem_baseSet := Trivialization.contMDiffOn_section_iff /-- For any trivialization `e`, the smoothness of a `C^n` section on `e.baseSet` can be determined using `e`. -/ theorem Trivialization.contMDiffOn_section_baseSet_iff {s : ∀ x, E x} (e : Trivialization F (Bundle.TotalSpace.proj : Bundle.TotalSpace F E → B)) [MemTrivializationAtlas e] : ContMDiffOn IB (IB.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) e.baseSet ↔ ContMDiffOn IB 𝓘(𝕜, F) n (fun x ↦ (e ⟨x, s x⟩).2) e.baseSet := e.contMDiffOn_section_iff e.open_baseSet subset_rfl @[deprecated (since := "2025-09-15")] alias contMDiffOn_section_of_mem_baseSet₀ := Trivialization.contMDiffOn_section_baseSet_iff end /-! ### Core construction for `C^n` vector bundles -/ namespace VectorBundleCore variable {F} variable {ι : Type*} (Z : VectorBundleCore 𝕜 B F ι) /-- Mixin for a `VectorBundleCore` stating that transition functions are `C^n`. -/ class IsContMDiff (IB : ModelWithCorners 𝕜 EB HB) (n : WithTop ℕ∞) : Prop where contMDiffOn_coordChange : ∀ i j, ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (Z.coordChange i j) (Z.baseSet i ∩ Z.baseSet j) theorem contMDiffOn_coordChange (IB : ModelWithCorners 𝕜 EB HB) [h : Z.IsContMDiff IB n] (i j : ι) : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (Z.coordChange i j) (Z.baseSet i ∩ Z.baseSet j) := h.1 i j variable [Z.IsContMDiff IB n] /-- If a `VectorBundleCore` has the `IsContMDiff` mixin, then the vector bundle constructed from it is a `C^n` vector bundle. -/ instance instContMDiffVectorBundle : ContMDiffVectorBundle n F Z.Fiber IB where contMDiffOn_coordChangeL := by rintro - - ⟨i, rfl⟩ ⟨i', rfl⟩ refine (Z.contMDiffOn_coordChange IB i i').congr fun b hb ↦ ?_ ext v exact Z.localTriv_coordChange_eq i i' hb v end VectorBundleCore /-! ### The trivial `C^n` vector bundle -/ /-- A trivial vector bundle over a manifold is a `C^n` vector bundle. -/ instance Bundle.Trivial.contMDiffVectorBundle : ContMDiffVectorBundle n F (Bundle.Trivial B F) IB where contMDiffOn_coordChangeL := by intro e e' he he' obtain rfl := Bundle.Trivial.eq_trivialization B F e obtain rfl := Bundle.Trivial.eq_trivialization B F e' simp_rw [Bundle.Trivial.trivialization.coordChangeL] exact contMDiff_const.contMDiffOn /-! ### Direct sums of `C^n` vector bundles -/ section Prod variable (F₁ : Type*) [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] (E₁ : B → Type*) [TopologicalSpace (TotalSpace F₁ E₁)] [∀ x, AddCommMonoid (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] variable (F₂ : Type*) [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] (E₂ : B → Type*) [TopologicalSpace (TotalSpace F₂ E₂)] [∀ x, AddCommMonoid (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] variable [∀ x : B, TopologicalSpace (E₁ x)] [∀ x : B, TopologicalSpace (E₂ x)] [FiberBundle F₁ E₁] [FiberBundle F₂ E₂] [VectorBundle 𝕜 F₁ E₁] [VectorBundle 𝕜 F₂ E₂] [ContMDiffVectorBundle n F₁ E₁ IB] [ContMDiffVectorBundle n F₂ E₂ IB] variable [IsManifold IB n B] /-- The direct sum of two `C^n` vector bundles over the same base is a `C^n` vector bundle. -/ instance Bundle.Prod.contMDiffVectorBundle : ContMDiffVectorBundle n (F₁ × F₂) (E₁ ×ᵇ E₂) IB where contMDiffOn_coordChangeL := by rintro _ _ ⟨e₁, e₂, i₁, i₂, rfl⟩ ⟨e₁', e₂', i₁', i₂', rfl⟩ refine ContMDiffOn.congr ?_ (e₁.coordChangeL_prod 𝕜 e₁' e₂ e₂') refine ContMDiffOn.clm_prodMap ?_ ?_ · refine (contMDiffOn_coordChangeL e₁ e₁').mono ?_ simp only [Trivialization.prod_baseSet, mfld_simps] mfld_set_tac · refine (contMDiffOn_coordChangeL e₂ e₂').mono ?_ simp only [Trivialization.prod_baseSet, mfld_simps] mfld_set_tac end Prod end WithTopology /-! ### Prebundle construction for `C^n` vector bundles -/ namespace VectorPrebundle variable [∀ x, TopologicalSpace (E x)] variable (IB) in /-- Mixin for a `VectorPrebundle` stating that coordinate changes are `C^n`. -/ class IsContMDiff (a : VectorPrebundle 𝕜 F E) (n : WithTop ℕ∞) : Prop where exists_contMDiffCoordChange : ∀ᵉ (e ∈ a.pretrivializationAtlas) (e' ∈ a.pretrivializationAtlas), ∃ f : B → F →L[𝕜] F, ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n f (e.baseSet ∩ e'.baseSet) ∧ ∀ (b : B) (_ : b ∈ e.baseSet ∩ e'.baseSet) (v : F), f b v = (e' ⟨b, e.symm b v⟩).2 variable (a : VectorPrebundle 𝕜 F E) [ha : a.IsContMDiff IB n] {e e' : Pretrivialization F (π F E)} variable (IB n) in /-- A randomly chosen coordinate change on a `VectorPrebundle` satisfying `IsContMDiff`, given by the field `exists_coordChange`. Note that `a.contMDiffCoordChange` need not be the same as `a.coordChange`. -/ noncomputable def contMDiffCoordChange (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) (b : B) : F →L[𝕜] F := Classical.choose (ha.exists_contMDiffCoordChange e he e' he') b theorem contMDiffOn_contMDiffCoordChange (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (a.contMDiffCoordChange n IB he he') (e.baseSet ∩ e'.baseSet) := (Classical.choose_spec (ha.exists_contMDiffCoordChange e he e' he')).1 theorem contMDiffCoordChange_apply (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : a.contMDiffCoordChange n IB he he' b v = (e' ⟨b, e.symm b v⟩).2 := (Classical.choose_spec (ha.exists_contMDiffCoordChange e he e' he')).2 b hb v theorem mk_contMDiffCoordChange (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : (b, a.contMDiffCoordChange n IB he he' b v) = e' ⟨b, e.symm b v⟩ := by ext · rw [e.mk_symm hb.1 v, e'.coe_fst', e.proj_symm_apply' hb.1] rw [e.proj_symm_apply' hb.1]; exact hb.2 · exact a.contMDiffCoordChange_apply he he' hb v variable (IB) in /-- Make a `ContMDiffVectorBundle` from a `ContMDiffVectorPrebundle`. -/ theorem contMDiffVectorBundle : @ContMDiffVectorBundle n _ _ F E _ _ _ _ _ _ IB _ _ _ _ _ _ a.totalSpaceTopology _ a.toFiberBundle a.toVectorBundle := letI := a.totalSpaceTopology; letI := a.toFiberBundle; letI := a.toVectorBundle { contMDiffOn_coordChangeL := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ refine (a.contMDiffOn_contMDiffCoordChange he he').congr ?_ intro b hb ext v rw [a.contMDiffCoordChange_apply he he' hb v, ContinuousLinearEquiv.coe_coe, Trivialization.coordChangeL_apply] exacts [rfl, hb] } end VectorPrebundle
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/Tangent.lean
import Mathlib.Geometry.Manifold.VectorBundle.Basic /-! # Tangent bundles This file defines the tangent bundle as a `C^n` vector bundle. Let `M` be a manifold with model `I` on `(E, H)`. The tangent space `TangentSpace I (x : M)` has already been defined as a type synonym for `E`, and the tangent bundle `TangentBundle I M` as an abbrev of `Bundle.TotalSpace E (TangentSpace I : M → Type _)`. In this file, when `M` is `C^1`, we construct a vector bundle structure on `TangentBundle I M` using the `VectorBundleCore` construction indexed by the charts of `M` with fibers `E`. Given two charts `i, j : OpenPartialHomeomorph M H`, the coordinate change between `i` and `j` at a point `x : M` is the derivative of the composite ``` I.symm i.symm j I E -----> H -----> M --> H --> E ``` within the set `range I ⊆ E` at `I (i x) : E`. This defines a vector bundle `TangentBundle` with fibers `TangentSpace`. ## Main definitions and results * `tangentBundleCore I M` is the vector bundle core for the tangent bundle over `M`. * When `M` is a `C^{n+1}` manifold, `TangentBundle I M` has a `C^n` vector bundle structure over `M`. In particular, it is a topological space, a vector bundle, a fiber bundle, and a `C^n` manifold. -/ open Bundle Set IsManifold OpenPartialHomeomorph ContinuousLinearMap open scoped Manifold Topology Bundle ContDiff noncomputable section section General variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {n : WithTop ℕ∞} {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] /-- Auxiliary lemma for tangent spaces: the derivative of a coordinate change between two charts is `C^n` on its source. -/ theorem contDiffOn_fderiv_coord_change [IsManifold I (n + 1) M] (i j : atlas H M) : ContDiffOn 𝕜 n (fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I)) ((i.1.extend I).symm ≫ j.1.extend I).source := by have h : ((i.1.extend I).symm ≫ j.1.extend I).source ⊆ range I := by rw [i.1.extend_coord_change_source]; apply image_subset_range intro x hx refine (ContDiffWithinAt.fderivWithin_right ?_ I.uniqueDiffOn le_rfl <| h hx).mono h refine (OpenPartialHomeomorph.contDiffOn_extend_coord_change (subset_maximalAtlas j.2) (subset_maximalAtlas i.2) x hx).mono_of_mem_nhdsWithin ?_ exact i.1.extend_coord_change_source_mem_nhdsWithin j.1 hx open IsManifold variable [IsManifold I 1 M] [IsManifold I' 1 M'] variable (I M) in /-- Let `M` be a `C^1` manifold with model `I` on `(E, H)`. Then `tangentBundleCore I M` is the vector bundle core for the tangent bundle over `M`. It is indexed by the atlas of `M`, with fiber `E` and its change of coordinates from the chart `i` to the chart `j` at point `x : M` is the derivative of the composite ``` I.symm i.symm j I E -----> H -----> M --> H --> E ``` within the set `range I ⊆ E` at `I (i x) : E`. -/ @[simps indexAt coordChange] def tangentBundleCore : VectorBundleCore 𝕜 M E (atlas H M) where baseSet i := i.1.source isOpen_baseSet i := i.1.open_source indexAt := achart H mem_baseSet_at := mem_chart_source H coordChange i j x := fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I) (i.1.extend I x) coordChange_self i x hx v := by rw [Filter.EventuallyEq.fderivWithin_eq, fderivWithin_id', ContinuousLinearMap.id_apply] · exact I.uniqueDiffWithinAt_image · filter_upwards [i.1.extend_target_mem_nhdsWithin hx] with y hy exact (i.1.extend I).right_inv hy · simp_rw [Function.comp_apply, i.1.extend_left_inv hx] continuousOn_coordChange i j := by have : IsManifold I (0 + 1) M := by simpa refine (contDiffOn_fderiv_coord_change (n := 0) i j).continuousOn.comp (i.1.continuousOn_extend.mono ?_) ?_ · rw [i.1.extend_source]; exact inter_subset_left simp_rw [← i.1.extend_image_source_inter, mapsTo_image] coordChange_comp := by have : IsManifold I (0 + 1) M := by simpa rintro i j k x ⟨⟨hxi, hxj⟩, hxk⟩ v rw [fderivWithin_fderivWithin, Filter.EventuallyEq.fderivWithin_eq] · have := i.1.extend_preimage_mem_nhds (I := I) hxi (j.1.extend_source_mem_nhds (I := I) hxj) filter_upwards [nhdsWithin_le_nhds this] with y hy simp_rw [Function.comp_apply, (j.1.extend I).left_inv hy] · simp_rw [Function.comp_apply, i.1.extend_left_inv hxi, j.1.extend_left_inv hxj] · exact (contDiffWithinAt_extend_coord_change' (subset_maximalAtlas k.2) (subset_maximalAtlas j.2) hxk hxj).differentiableWithinAt le_rfl · exact (contDiffWithinAt_extend_coord_change' (subset_maximalAtlas j.2) (subset_maximalAtlas i.2) hxj hxi).differentiableWithinAt le_rfl · intro x _; exact mem_range_self _ · exact I.uniqueDiffWithinAt_image · rw [Function.comp_apply, i.1.extend_left_inv hxi] /-- `simp`-normal form is `tangentBundleCore_localTriv_baseSet`. -/ theorem tangentBundleCore_baseSet (i) : (tangentBundleCore I M).baseSet i = i.1.source := rfl @[simp] theorem tangentBundleCore_localTriv_baseSet (i) : ((tangentBundleCore I M).localTriv i).baseSet = i.1.source := rfl theorem tangentBundleCore_coordChange_achart (x x' z : M) : (tangentBundleCore I M).coordChange (achart H x) (achart H x') z = fderivWithin 𝕜 (extChartAt I x' ∘ (extChartAt I x).symm) (range I) (extChartAt I x z) := rfl section tangentCoordChange variable (I) in /-- In a manifold `M`, given two preferred charts indexed by `x y : M`, `tangentCoordChange I x y` is the family of derivatives of the corresponding change-of-coordinates map. It takes junk values outside the intersection of the sources of the two charts. Note that this definition takes advantage of the fact that `tangentBundleCore` has the same base sets as the preferred charts of the base manifold. -/ abbrev tangentCoordChange (x y : M) : M → E →L[𝕜] E := (tangentBundleCore I M).coordChange (achart H x) (achart H y) lemma tangentCoordChange_def {x y z : M} : tangentCoordChange I x y z = fderivWithin 𝕜 (extChartAt I y ∘ (extChartAt I x).symm) (range I) (extChartAt I x z) := rfl lemma tangentCoordChange_self {x z : M} {v : E} (h : z ∈ (extChartAt I x).source) : tangentCoordChange I x x z v = v := by apply (tangentBundleCore I M).coordChange_self rw [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] exact h lemma tangentCoordChange_comp {w x y z : M} {v : E} (h : z ∈ (extChartAt I w).source ∩ (extChartAt I x).source ∩ (extChartAt I y).source) : tangentCoordChange I x y z (tangentCoordChange I w x z v) = tangentCoordChange I w y z v := by apply (tangentBundleCore I M).coordChange_comp simp only [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] exact h lemma hasFDerivWithinAt_tangentCoordChange {x y z : M} (h : z ∈ (extChartAt I x).source ∩ (extChartAt I y).source) : HasFDerivWithinAt ((extChartAt I y) ∘ (extChartAt I x).symm) (tangentCoordChange I x y z) (range I) (extChartAt I x z) := have h' : extChartAt I x z ∈ ((extChartAt I x).symm ≫ (extChartAt I y)).source := by rw [PartialEquiv.trans_source'', PartialEquiv.symm_symm, PartialEquiv.symm_target] exact mem_image_of_mem _ h ((contDiffWithinAt_ext_coord_change y x h').differentiableWithinAt le_rfl).hasFDerivWithinAt lemma continuousOn_tangentCoordChange (x y : M) : ContinuousOn (tangentCoordChange I x y) ((extChartAt I x).source ∩ (extChartAt I y).source) := by convert (tangentBundleCore I M).continuousOn_coordChange (achart H x) (achart H y) <;> simp only [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] end tangentCoordChange local notation "TM" => TangentBundle I M section TangentBundleInstances instance : TopologicalSpace TM := (tangentBundleCore I M).toTopologicalSpace instance TangentSpace.fiberBundle : FiberBundle E (TangentSpace I : M → Type _) := (tangentBundleCore I M).fiberBundle instance TangentSpace.vectorBundle : VectorBundle 𝕜 E (TangentSpace I : M → Type _) := (tangentBundleCore I M).vectorBundle namespace TangentBundle protected theorem chartAt (p : TM) : chartAt (ModelProd H E) p = ((tangentBundleCore I M).toFiberBundleCore.localTriv (achart H p.1)).toOpenPartialHomeomorph ≫ₕ (chartAt H p.1).prod (OpenPartialHomeomorph.refl E) := rfl theorem chartAt_toPartialEquiv (p : TM) : (chartAt (ModelProd H E) p).toPartialEquiv = (tangentBundleCore I M).toFiberBundleCore.localTrivAsPartialEquiv (achart H p.1) ≫ (chartAt H p.1).toPartialEquiv.prod (PartialEquiv.refl E) := rfl theorem trivializationAt_eq_localTriv (x : M) : trivializationAt E (TangentSpace I) x = (tangentBundleCore I M).toFiberBundleCore.localTriv (achart H x) := rfl @[simp, mfld_simps] theorem trivializationAt_source (x : M) : (trivializationAt E (TangentSpace I) x).source = π E (TangentSpace I) ⁻¹' (chartAt H x).source := rfl @[simp, mfld_simps] theorem trivializationAt_target (x : M) : (trivializationAt E (TangentSpace I) x).target = (chartAt H x).source ×ˢ univ := rfl @[simp, mfld_simps] theorem trivializationAt_baseSet (x : M) : (trivializationAt E (TangentSpace I) x).baseSet = (chartAt H x).source := rfl theorem trivializationAt_apply (x : M) (z : TM) : trivializationAt E (TangentSpace I) x z = (z.1, fderivWithin 𝕜 ((chartAt H x).extend I ∘ ((chartAt H z.1).extend I).symm) (range I) ((chartAt H z.1).extend I z.1) z.2) := rfl @[simp, mfld_simps] theorem trivializationAt_fst (x : M) (z : TM) : (trivializationAt E (TangentSpace I) x z).1 = z.1 := rfl @[simp, mfld_simps] theorem mem_chart_source_iff (p q : TM) : p ∈ (chartAt (ModelProd H E) q).source ↔ p.1 ∈ (chartAt H q.1).source := by simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] @[simp, mfld_simps] theorem mem_chart_target_iff (p : H × E) (q : TM) : p ∈ (chartAt (ModelProd H E) q).target ↔ p.1 ∈ (chartAt H q.1).target := by /- porting note: was simp +contextual only [FiberBundle.chartedSpace_chartAt, and_iff_left_iff_imp, mfld_simps] -/ simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] rw [PartialEquiv.prod_symm] simp +contextual only [and_iff_left_iff_imp, mfld_simps] @[simp, mfld_simps] theorem coe_chartAt_fst (p q : TM) : ((chartAt (ModelProd H E) q) p).1 = chartAt H q.1 p.1 := rfl @[simp, mfld_simps] theorem coe_chartAt_symm_fst (p : H × E) (q : TM) : ((chartAt (ModelProd H E) q).symm p).1 = ((chartAt H q.1).symm : H → M) p.1 := rfl /-- The trivialization of the tangent space can be expressed in terms of the tangent bundle core. To write it as the manifold derivative of `extChartAt`, see `TangentBundle.continuousLinearMapAt_trivializationAt`. Use with care as it abuses the defeq `TangentSpace I b = E`. -/ theorem continuousLinearMapAt_trivializationAt_eq_core {b₀ b : M} (hb : b ∈ (chartAt H b₀).source) : (trivializationAt E (TangentSpace I) b₀).continuousLinearMapAt 𝕜 b = (tangentBundleCore I M).coordChange (achart H b) (achart H b₀) b := by simp [hb] @[deprecated (since := "2025-07-03")] alias trivializationAt_continuousLinearMapAt := continuousLinearMapAt_trivializationAt_eq_core /-- The inverse trivialization of the tangent space can be expressed in terms of the tangent bundle core. To write it as the manifold derivative of `(extChartAt I b₀).symm`, see `TangentBundle.symmL_trivializationAt`. Use with care as it abuses the defeq `TangentSpace I b = E`. -/ theorem symmL_trivializationAt_eq_core {b₀ b : M} (hb : b ∈ (chartAt H b₀).source) : (trivializationAt E (TangentSpace I) b₀).symmL 𝕜 b = (tangentBundleCore I M).coordChange (achart H b₀) (achart H b) b := by simp [hb] @[deprecated (since := "2025-07-03")] alias trivializationAt_symmL := symmL_trivializationAt_eq_core /-! The lemmas below have high priority because `simp` simplifies the LHS to `.id _ _`; we prefer `1` as the simp-normal form. -/ @[simp high, mfld_simps] theorem coordChange_model_space (b b' x : F) : (tangentBundleCore 𝓘(𝕜, F) F).coordChange (achart F b) (achart F b') x = 1 := by simpa only [tangentBundleCore_coordChange, mfld_simps] using fderivWithin_id uniqueDiffWithinAt_univ @[simp high, mfld_simps] theorem symmL_model_space (b b' : F) : (trivializationAt F (TangentSpace 𝓘(𝕜, F)) b).symmL 𝕜 b' = (1 : F →L[𝕜] F) := by rw [TangentBundle.symmL_trivializationAt_eq_core, coordChange_model_space] apply mem_univ @[simp high, mfld_simps] theorem continuousLinearMapAt_model_space (b b' : F) : (trivializationAt F (TangentSpace 𝓘(𝕜, F)) b).continuousLinearMapAt 𝕜 b' = (1 : F →L[𝕜] F) := by rw [TangentBundle.continuousLinearMapAt_trivializationAt_eq_core, coordChange_model_space] apply mem_univ end TangentBundle omit [IsManifold I 1 M] in lemma tangentBundleCore.isContMDiff [h : IsManifold I (n + 1) M] : haveI : IsManifold I 1 M := .of_le (n := n + 1) le_add_self (tangentBundleCore I M).IsContMDiff I n := by have : IsManifold I n M := .of_le (n := n + 1) (le_self_add) refine ⟨fun i j => ?_⟩ rw [contMDiffOn_iff_source_of_mem_maximalAtlas (subset_maximalAtlas i.2), contMDiffOn_iff_contDiffOn] · refine ((contDiffOn_fderiv_coord_change (I := I) i j).congr fun x hx => ?_).mono ?_ · rw [PartialEquiv.trans_source'] at hx simp_rw [Function.comp_apply, tangentBundleCore_coordChange, (i.1.extend I).right_inv hx.1] · exact (i.1.extend_image_source_inter j.1).subset · apply inter_subset_left omit [IsManifold I 1 M] in lemma TangentBundle.contMDiffVectorBundle [h : IsManifold I (n + 1) M] : haveI : IsManifold I 1 M := .of_le (n := n + 1) le_add_self ContMDiffVectorBundle n E (TangentSpace I : M → Type _) I := by have : IsManifold I 1 M := .of_le (n := n + 1) le_add_self have : (tangentBundleCore I M).IsContMDiff I n := tangentBundleCore.isContMDiff exact (tangentBundleCore I M).instContMDiffVectorBundle omit [IsManifold I 1 M] in instance [h : IsManifold I ∞ M] : ContMDiffVectorBundle ∞ E (TangentSpace I : M → Type _) I := by have : IsManifold I (∞ + 1) M := h exact TangentBundle.contMDiffVectorBundle omit [IsManifold I 1 M] in instance [IsManifold I ω M] : ContMDiffVectorBundle ω E (TangentSpace I : M → Type _) I := TangentBundle.contMDiffVectorBundle omit [IsManifold I 1 M] in instance [h : IsManifold I 2 M] : ContMDiffVectorBundle 1 E (TangentSpace I : M → Type _) I := by have : IsManifold I (1 + 1) M := h exact TangentBundle.contMDiffVectorBundle end TangentBundleInstances /-! ## The tangent bundle to the model space -/ @[simp, mfld_simps] theorem trivializationAt_model_space_apply (p : TangentBundle I H) (x : H) : trivializationAt E (TangentSpace I) x p = (p.1, p.2) := by simp only [TangentBundle.trivializationAt_apply] have : fderivWithin 𝕜 (↑I ∘ ↑I.symm) (range I) (I p.proj) = fderivWithin 𝕜 id (range I) (I p.proj) := fderivWithin_congr' (fun y hy ↦ by simp [hy]) (mem_range_self p.proj) simp [this, fderivWithin_id (ModelWithCorners.uniqueDiffWithinAt_image I)] /-- In the tangent bundle to the model space, the charts are just the canonical identification between a product type and a sigma type, a.k.a. `TotalSpace.toProd`. -/ @[simp, mfld_simps] theorem tangentBundle_model_space_chartAt (p : TangentBundle I H) : (chartAt (ModelProd H E) p).toPartialEquiv = (TotalSpace.toProd H E).toPartialEquiv := by ext x : 1 · ext; · rfl exact (tangentBundleCore I H).coordChange_self (achart _ x.1) x.1 (mem_achart_source H x.1) x.2 · ext; · rfl apply heq_of_eq exact (tangentBundleCore I H).coordChange_self (achart _ x.1) x.1 (mem_achart_source H x.1) x.2 simp_rw [TangentBundle.chartAt, FiberBundleCore.localTriv, FiberBundleCore.localTrivAsPartialEquiv, VectorBundleCore.toFiberBundleCore_baseSet, tangentBundleCore_baseSet] simp only [mfld_simps] @[simp, mfld_simps] theorem tangentBundle_model_space_coe_chartAt (p : TangentBundle I H) : ⇑(chartAt (ModelProd H E) p) = TotalSpace.toProd H E := by rw [← OpenPartialHomeomorph.coe_coe, tangentBundle_model_space_chartAt]; rfl @[simp, mfld_simps] theorem tangentBundle_model_space_coe_chartAt_symm (p : TangentBundle I H) : ((chartAt (ModelProd H E) p).symm : ModelProd H E → TangentBundle I H) = (TotalSpace.toProd H E).symm := by rw [← OpenPartialHomeomorph.coe_coe, OpenPartialHomeomorph.symm_toPartialEquiv, tangentBundle_model_space_chartAt]; rfl theorem tangentBundleCore_coordChange_model_space (x x' z : H) : (tangentBundleCore I H).coordChange (achart H x) (achart H x') z = ContinuousLinearMap.id 𝕜 E := by ext v; exact (tangentBundleCore I H).coordChange_self (achart _ z) z (mem_univ _) v variable (I) in /-- The canonical identification between the tangent bundle to the model space and the product, as a homeomorphism. For the diffeomorphism version, see `tangentBundleModelSpaceDiffeomorph`. -/ def tangentBundleModelSpaceHomeomorph : TangentBundle I H ≃ₜ ModelProd H E := { TotalSpace.toProd H E with continuous_toFun := by let p : TangentBundle I H := ⟨I.symm (0 : E), (0 : E)⟩ have : Continuous (chartAt (ModelProd H E) p) := by rw [← continuousOn_univ] convert (chartAt (ModelProd H E) p).continuousOn simp only [TangentSpace.fiberBundle, mfld_simps] simpa only [mfld_simps] using this continuous_invFun := by let p : TangentBundle I H := ⟨I.symm (0 : E), (0 : E)⟩ have : Continuous (chartAt (ModelProd H E) p).symm := by rw [← continuousOn_univ] convert (chartAt (ModelProd H E) p).symm.continuousOn simp only [mfld_simps] simpa only [mfld_simps] using this } @[simp, mfld_simps] theorem tangentBundleModelSpaceHomeomorph_coe : (tangentBundleModelSpaceHomeomorph I : TangentBundle I H → ModelProd H E) = TotalSpace.toProd H E := rfl @[simp, mfld_simps] theorem tangentBundleModelSpaceHomeomorph_coe_symm : ((tangentBundleModelSpaceHomeomorph I).symm : ModelProd H E → TangentBundle I H) = (TotalSpace.toProd H E).symm := rfl theorem contMDiff_tangentBundleModelSpaceHomeomorph : ContMDiff I.tangent (I.prod 𝓘(𝕜, E)) n (tangentBundleModelSpaceHomeomorph I : TangentBundle I H → ModelProd H E) := by apply contMDiff_iff.2 ⟨Homeomorph.continuous _, fun x y ↦ ?_⟩ apply contDiffOn_id.congr simp only [mfld_simps, mem_range, TotalSpace.toProd, Equiv.coe_fn_symm_mk, forall_exists_index, Prod.forall, Prod.mk.injEq] rintro a b x rfl simp [PartialEquiv.prod] theorem contMDiff_tangentBundleModelSpaceHomeomorph_symm : ContMDiff (I.prod 𝓘(𝕜, E)) I.tangent n ((tangentBundleModelSpaceHomeomorph I).symm : ModelProd H E → TangentBundle I H) := by apply contMDiff_iff.2 ⟨Homeomorph.continuous _, fun x y ↦ ?_⟩ apply contDiffOn_id.congr simp only [mfld_simps, mem_range, TotalSpace.toProd, Equiv.coe_fn_symm_mk, forall_exists_index, Prod.forall, Prod.mk.injEq] rintro a b x rfl simpa [PartialEquiv.prod] using ⟨rfl, rfl⟩ variable (H I) in /-- In the tangent bundle to the model space, the second projection is `C^n`. -/ lemma contMDiff_snd_tangentBundle_modelSpace : ContMDiff I.tangent 𝓘(𝕜, E) n (fun (p : TangentBundle I H) ↦ p.2) := by change ContMDiff I.tangent 𝓘(𝕜, E) n ((id Prod.snd : ModelProd H E → E) ∘ (tangentBundleModelSpaceHomeomorph I)) apply ContMDiff.comp (I' := I.prod 𝓘(𝕜, E)) · convert contMDiff_snd rw [chartedSpaceSelf_prod] rfl · exact contMDiff_tangentBundleModelSpaceHomeomorph /-- A vector field on a vector space is `C^n` in the manifold sense iff it is `C^n` in the vector space sense. -/ lemma contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt {V : Π (x : E), TangentSpace 𝓘(𝕜, E) x} {s : Set E} {x : E} : ContMDiffWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent n (fun x ↦ (V x : TangentBundle 𝓘(𝕜, E) E)) s x ↔ ContDiffWithinAt 𝕜 n V s x := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · exact ContMDiffWithinAt.contDiffWithinAt <| (contMDiff_snd_tangentBundle_modelSpace E 𝓘(𝕜, E)).contMDiffAt.comp_contMDiffWithinAt _ h · apply Bundle.contMDiffWithinAt_totalSpace.2 refine ⟨contMDiffWithinAt_id, ?_⟩ convert h.contMDiffWithinAt with y simp /-- A vector field on a vector space is `C^n` in the manifold sense iff it is `C^n` in the vector space sense. -/ lemma contMDiffAt_vectorSpace_iff_contDiffAt {V : Π (x : E), TangentSpace 𝓘(𝕜, E) x} {x : E} : ContMDiffAt 𝓘(𝕜, E) 𝓘(𝕜, E).tangent n (fun x ↦ (V x : TangentBundle 𝓘(𝕜, E) E)) x ↔ ContDiffAt 𝕜 n V x := by simp only [← contMDiffWithinAt_univ, ← contDiffWithinAt_univ, contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt] /-- A vector field on a vector space is `C^n` in the manifold sense iff it is `C^n` in the vector space sense. -/ lemma contMDiffOn_vectorSpace_iff_contDiffOn {V : Π (x : E), TangentSpace 𝓘(𝕜, E) x} {s : Set E} : ContMDiffOn 𝓘(𝕜, E) 𝓘(𝕜, E).tangent n (fun x ↦ (V x : TangentBundle 𝓘(𝕜, E) E)) s ↔ ContDiffOn 𝕜 n V s := by simp only [ContMDiffOn, ContDiffOn, contMDiffWithinAt_vectorSpace_iff_contDiffWithinAt ] /-- A vector field on a vector space is `C^n` in the manifold sense iff it is `C^n` in the vector space sense. -/ lemma contMDiff_vectorSpace_iff_contDiff {V : Π (x : E), TangentSpace 𝓘(𝕜, E) x} : ContMDiff 𝓘(𝕜, E) 𝓘(𝕜, E).tangent n (fun x ↦ (V x : TangentBundle 𝓘(𝕜, E) E)) ↔ ContDiff 𝕜 n V := by simp only [← contMDiffOn_univ, ← contDiffOn_univ, contMDiffOn_vectorSpace_iff_contDiffOn] section inTangentCoordinates variable {N : Type*} /-- The map `inCoordinates` for the tangent bundle is trivial on the model spaces -/ theorem inCoordinates_tangent_bundle_core_model_space (x₀ x : H) (y₀ y : H') (ϕ : E →L[𝕜] E') : inCoordinates E (TangentSpace I) E' (TangentSpace I') x₀ x y₀ y ϕ = ϕ := by erw [VectorBundleCore.inCoordinates_eq] <;> try trivial simp_rw [tangentBundleCore_indexAt, tangentBundleCore_coordChange_model_space, ContinuousLinearMap.id_comp, ContinuousLinearMap.comp_id] variable (I I') in /-- When `ϕ x` is a continuous linear map that changes vectors in charts around `f x` to vectors in charts around `g x`, `inTangentCoordinates I I' f g ϕ x₀ x` is a coordinate change of this continuous linear map that makes sense from charts around `f x₀` to charts around `g x₀` by composing it with appropriate coordinate changes. Note that the type of `ϕ` is more accurately `Π x : N, TangentSpace I (f x) →L[𝕜] TangentSpace I' (g x)`. We are unfolding `TangentSpace` in this type so that Lean recognizes that the type of `ϕ` doesn't actually depend on `f` or `g`. This is the underlying function of the trivializations of the hom of (pullbacks of) tangent spaces. -/ def inTangentCoordinates (f : N → M) (g : N → M') (ϕ : N → E →L[𝕜] E') : N → N → E →L[𝕜] E' := fun x₀ x => inCoordinates E (TangentSpace I) E' (TangentSpace I') (f x₀) (f x) (g x₀) (g x) (ϕ x) theorem inTangentCoordinates_model_space (f : N → H) (g : N → H') (ϕ : N → E →L[𝕜] E') (x₀ : N) : inTangentCoordinates I I' f g ϕ x₀ = ϕ := by simp +unfoldPartialApp only [inTangentCoordinates, inCoordinates_tangent_bundle_core_model_space] /-- To write a linear map between tangent spaces in coordinates amounts to precomposing and postcomposing it with suitable coordinate changes. For a concrete version expressing the change of coordinates as derivatives of extended charts, see `inTangentCoordinates_eq_mfderiv_comp`. -/ theorem inTangentCoordinates_eq (f : N → M) (g : N → M') (ϕ : N → E →L[𝕜] E') {x₀ x : N} (hx : f x ∈ (chartAt H (f x₀)).source) (hy : g x ∈ (chartAt H' (g x₀)).source) : inTangentCoordinates I I' f g ϕ x₀ x = (tangentBundleCore I' M').coordChange (achart H' (g x)) (achart H' (g x₀)) (g x) ∘L ϕ x ∘L (tangentBundleCore I M).coordChange (achart H (f x₀)) (achart H (f x)) (f x) := (tangentBundleCore I M).inCoordinates_eq (tangentBundleCore I' M') (ϕ x) hx hy end inTangentCoordinates end General
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/Pullback.lean
import Mathlib.Geometry.Manifold.ContMDiffMap import Mathlib.Geometry.Manifold.VectorBundle.Basic /-! # Pullbacks of `C^n` vector bundles This file defines pullbacks of `C^n` vector bundles over a manifold. ## Main definitions * `ContMDiffVectorBundle.pullback`: For a `C^n` vector bundle `E` over a manifold `B` and a `C^n` map `f : B' → B`, the pullback vector bundle `f *ᵖ E` is a `C^n` vector bundle. -/ open Bundle Set open scoped Manifold variable {𝕜 B B' : Type*} (F : Type*) (E : B → Type*) {n : WithTop ℕ∞} variable [NontriviallyNormedField 𝕜] [∀ x, AddCommMonoid (E x)] [∀ x, Module 𝕜 (E x)] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners 𝕜 EB HB} [TopologicalSpace B] [ChartedSpace HB B] {EB' : Type*} [NormedAddCommGroup EB'] [NormedSpace 𝕜 EB'] {HB' : Type*} [TopologicalSpace HB'] (IB' : ModelWithCorners 𝕜 EB' HB') [TopologicalSpace B'] [ChartedSpace HB' B'] [FiberBundle F E] [VectorBundle 𝕜 F E] [ContMDiffVectorBundle n F E IB] (f : ContMDiffMap IB' IB B' B n) /-- For a `C^n` vector bundle `E` over a manifold `B` and a `C^n` map `f : B' → B`, the pullback vector bundle `f *ᵖ E` is a `C^n` vector bundle. -/ instance ContMDiffVectorBundle.pullback : ContMDiffVectorBundle n F (f *ᵖ E) IB' where contMDiffOn_coordChangeL := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ refine ((contMDiffOn_coordChangeL e e').comp f.contMDiff.contMDiffOn fun b hb => hb).congr ?_ rintro b (hb : f b ∈ e.baseSet ∩ e'.baseSet); ext v change ((e.pullback f).coordChangeL 𝕜 (e'.pullback f) b) v = (e.coordChangeL 𝕜 e' (f b)) v rw [e.coordChangeL_apply e' hb, (e.pullback f).coordChangeL_apply' _] exacts [rfl, hb]
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/SmoothSection.lean
import Mathlib.Geometry.Manifold.Algebra.LieGroup import Mathlib.Geometry.Manifold.MFDeriv.Basic import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Geometry.Manifold.VectorBundle.Basic /-! # `C^n` sections In this file we define the type `ContMDiffSection` of `n` times continuously differentiable sections of a vector bundle over a manifold `M` and prove that it's a module over the base field. In passing, we prove that binary and finite sums, differences and scalar products of `C^n` sections are `C^n`. -/ open Bundle Filter Function open scoped Bundle Manifold ContDiff variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- `F` model fiber (n : WithTop ℕ∞) (V : M → Type*) [TopologicalSpace (TotalSpace F V)] -- `V` vector bundle [∀ x : M, TopologicalSpace (V x)] [FiberBundle F V] -- Binary and finite sums, negative, differences and scalar products of smooth sections are smooth section operations -- Let V be a vector bundle variable [∀ x, AddCommGroup (V x)] [∀ x, Module 𝕜 (V x)] [VectorBundle 𝕜 F V] variable {I F n V} variable {f : M → 𝕜} {a : 𝕜} {s t : Π x : M, V x} {u : Set M} {x₀ : M} lemma ContMDiffWithinAt.add_section (hs : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) (ht : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t x)) u x₀) : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x ((s + t) x)) u x₀ := by rw [contMDiffWithinAt_section] at hs ht ⊢ set e := trivializationAt F V x₀ refine (hs.add ht).congr_of_eventuallyEq ?_ ?_ · apply eventually_of_mem (U := e.baseSet) · exact mem_nhdsWithin_of_mem_nhds <| (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F V x₀) · intro x hx apply (e.linear 𝕜 hx).1 · apply (e.linear 𝕜 (FiberBundle.mem_baseSet_trivializationAt' x₀)).1 lemma ContMDiffAt.add_section (hs : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀) (ht : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t x)) x₀) : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x ((s + t) x)) x₀ := by rw [← contMDiffWithinAt_univ] at hs ⊢ exact hs.add_section ht lemma ContMDiffOn.add_section (hs : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u) (ht : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t x)) u) : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x ((s + t) x)) u := fun x₀ hx₀ ↦ (hs x₀ hx₀).add_section (ht x₀ hx₀) lemma ContMDiff.add_section (hs : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x))) (ht : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t x))) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x ((s + t) x)) := fun x₀ ↦ (hs x₀).add_section (ht x₀) lemma ContMDiffWithinAt.neg_section (hs : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (-s x)) u x₀ := by rw [contMDiffWithinAt_section] at hs ⊢ set e := trivializationAt F V x₀ refine hs.neg.congr_of_eventuallyEq ?_ ?_ · apply eventually_of_mem (U := e.baseSet) · exact mem_nhdsWithin_of_mem_nhds <| (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F V x₀) · intro x hx apply (e.linear 𝕜 hx).map_neg · apply (e.linear 𝕜 (FiberBundle.mem_baseSet_trivializationAt' x₀)).map_neg lemma ContMDiffAt.neg_section (hs : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀) : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (-s x)) x₀ := by rw [← contMDiffWithinAt_univ] at hs ⊢ exact hs.neg_section lemma ContMDiffOn.neg_section (hs : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u) : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (-s x)) u := fun x₀ hx₀ ↦ (hs x₀ hx₀).neg_section lemma ContMDiff.neg_section (hs : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x))) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (-s x)) := fun x₀ ↦ (hs x₀).neg_section lemma ContMDiffWithinAt.sub_section (hs : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) (ht : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t x)) u x₀) : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x ((s - t) x)) u x₀ := by rw [sub_eq_add_neg] exact hs.add_section ht.neg_section lemma ContMDiffAt.sub_section (hs : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀) (ht : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t x)) x₀) : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x ((s - t) x)) x₀ := by rw [sub_eq_add_neg] apply hs.add_section ht.neg_section lemma ContMDiffOn.sub_section (hs : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u) (ht : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t x)) u) : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x ((s - t) x)) u := fun x₀ hx₀ ↦ (hs x₀ hx₀).sub_section (ht x₀ hx₀) lemma ContMDiff.sub_section (hs : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x))) (ht : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t x))) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x ((s - t) x)) := fun x₀ ↦ (hs x₀).sub_section (ht x₀) lemma ContMDiffWithinAt.smul_section (hf : ContMDiffWithinAt I 𝓘(𝕜) n f u x₀) (hs : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (f x • s x)) u x₀ := by rw [contMDiffWithinAt_section] at hs ⊢ set e := trivializationAt F V x₀ refine (hf.smul hs).congr_of_eventuallyEq ?_ ?_ · apply eventually_of_mem (U := e.baseSet) · exact mem_nhdsWithin_of_mem_nhds <| (e.open_baseSet.mem_nhds <| mem_baseSet_trivializationAt F V x₀) · intro x hx apply (e.linear 𝕜 hx).2 · apply (e.linear 𝕜 (FiberBundle.mem_baseSet_trivializationAt' x₀)).2 lemma ContMDiffAt.smul_section (hf : ContMDiffAt I 𝓘(𝕜) n f x₀) (hs : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀) : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (f x • s x)) x₀ := by rw [← contMDiffWithinAt_univ] at hs ⊢ exact .smul_section hf hs lemma ContMDiffOn.smul_section (hf : ContMDiffOn I 𝓘(𝕜) n f u) (hs : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u) : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (f x • s x)) u := fun x₀ hx₀ ↦ (hf x₀ hx₀).smul_section (hs x₀ hx₀) lemma ContMDiff.smul_section (hf : ContMDiff I 𝓘(𝕜) n f) (hs : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x))) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (f x • s x)) := fun x₀ ↦ (hf x₀).smul_section (hs x₀) lemma ContMDiffWithinAt.const_smul_section (hs : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u x₀) : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (a • s x)) u x₀ := contMDiffWithinAt_const.smul_section hs lemma ContMDiffAt.const_smul_section (hs : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) x₀) : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (a • s x)) x₀ := contMDiffAt_const.smul_section hs lemma ContMDiffOn.const_smul_section (hs : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u) : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (a • s x)) u := contMDiffOn_const.smul_section hs lemma ContMDiff.const_smul_section (hs : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x))) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (a • s x)) := fun x₀ ↦ (hs x₀).const_smul_section variable {ι : Type*} {t : ι → (x : M) → V x} lemma ContMDiffWithinAt.sum_section {s : Finset ι} (hs : ∀ i ∈ s, ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) u x₀) : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) u x₀ := by classical induction s using Finset.induction_on with | empty => simpa only [Finset.sum_empty] using contMDiffWithinAt_zeroSection .. | insert i s hi h => simp only [Finset.sum_insert hi] apply (hs _ (s.mem_insert_self i)).add_section exact h fun i a ↦ hs _ (s.mem_insert_of_mem a) lemma ContMDiffAt.sum_section {s : Finset ι} {x₀ : M} (hs : ∀ i ∈ s, ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) x₀) : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) x₀ := by simp_rw [← contMDiffWithinAt_univ] at hs ⊢ exact .sum_section hs lemma ContMDiffOn.sum_section {s : Finset ι} (hs : ∀ i ∈ s, ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) u) : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) u := fun x₀ hx₀ ↦ .sum_section fun i hi ↦ hs i hi x₀ hx₀ lemma ContMDiff.sum_section {s : Finset ι} (hs : ∀ i ∈ s, ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x))) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) := fun x₀ ↦ .sum_section fun i hi ↦ (hs i hi) x₀ /-- The scalar product `ψ • s` of a `C^k` function `ψ : M → 𝕜` and a section `s` of a vector bundle `V → M` is `C^k` once `s` is `C^k` on an open set containing `tsupport ψ`. This is a vector bundle analogue of `contMDiff_of_tsupport`. -/ lemma ContMDiffOn.smul_section_of_tsupport {s : Π (x : M), V x} {ψ : M → 𝕜} (hψ : ContMDiffOn I 𝓘(𝕜) n ψ u) (ht : IsOpen u) (ht' : tsupport ψ ⊆ u) (hs : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (s x)) u) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (ψ x • s x)) := by apply contMDiff_of_contMDiffOn_union_of_isOpen (hψ.smul_section hs) ?_ ?_ ht (isOpen_compl_iff.mpr <| isClosed_tsupport ψ) · apply ((contMDiff_zeroSection _ _).contMDiffOn (s := (tsupport ψ)ᶜ)).congr intro y hy simp [image_eq_zero_of_notMem_tsupport hy, zeroSection] · exact Set.compl_subset_iff_union.mp <| Set.compl_subset_compl.mpr ht' /-- The sum of a locally finite collection of sections is `C^k` iff each section is. Version at a point within a set. -/ lemma ContMDiffWithinAt.sum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : M | t i x ≠ 0}) (ht' : ∀ i, ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) u x₀) : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑' i, (t i x))) u x₀ := by obtain ⟨u', hu', hfin⟩ := ht x₀ -- All sections `t i` but a finite set `s` vanish near `x₀`: choose a neighbourhood `u` of `x₀` -- and a finite set `s` of sections which don't vanish. let s := {i | ((fun i ↦ {x | t i x ≠ 0}) i ∩ u').Nonempty} have := hfin.fintype have : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ i ∈ s, (t i x))) (u ∩ u') x₀ := ContMDiffWithinAt.sum_section fun i hi ↦ ((ht' i).mono Set.inter_subset_left) apply (contMDiffWithinAt_inter hu').mp apply this.congr fun y hy ↦ ?_ · rw [TotalSpace.mk_inj, tsum_eq_sum'] refine support_subset_iff'.mpr fun i hi ↦ ?_ by_contra! h have : i ∈ s.toFinset := by refine Set.mem_toFinset.mpr ?_ simp only [s, ne_eq, Set.mem_setOf_eq] use x₀ simpa using ⟨h, mem_of_mem_nhds hu'⟩ exact hi this rw [TotalSpace.mk_inj, tsum_eq_sum'] refine support_subset_iff'.mpr fun i hi ↦ ?_ by_contra! h have : i ∈ s.toFinset := by refine Set.mem_toFinset.mpr ?_ simp only [s, ne_eq, Set.mem_setOf_eq] use y simpa using ⟨h, Set.mem_of_mem_inter_right hy⟩ exact hi this /-- The sum of a locally finite collection of sections is `C^k` at `x` iff each section is. -/ lemma ContMDiffAt.sum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : M | t i x ≠ 0}) (ht' : ∀ i, ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) x₀) : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑' i, (t i x))) x₀ := by simp_rw [← contMDiffWithinAt_univ] at ht' ⊢ exact .sum_section_of_locallyFinite ht ht' /-- The sum of a locally finite collection of sections is `C^k` on a set `u` iff each section is. -/ lemma ContMDiffOn.sum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : M | t i x ≠ 0}) (ht' : ∀ i, ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) u) : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑' i, (t i x))) u := fun x hx ↦ .sum_section_of_locallyFinite ht (ht' · x hx) /-- The sum of a locally finite collection of sections is `C^k` iff each section is. -/ lemma ContMDiff.sum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : M | t i x ≠ 0}) (ht' : ∀ i, ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x))) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑' i, (t i x))) := fun x ↦ .sum_section_of_locallyFinite ht fun i ↦ ht' i x -- Future: the next four lemmas can presumably be generalised, but some hypotheses on the supports -- of the sections `t i` are necessary. lemma ContMDiffWithinAt.finsum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : M | t i x ≠ 0}) (ht' : ∀ i, ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) u x₀) : ContMDiffWithinAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ᶠ i, t i x)) u x₀ := by apply (ContMDiffWithinAt.sum_section_of_locallyFinite ht ht').congr' (t := Set.univ) (fun y hy ↦ ?_) (by grind) trivial rw [← tsum_eq_finsum (L := SummationFilter.unconditional ι)] choose U hu hfin using ht y have : {x | t x y ≠ 0} ⊆ {i | ((fun i ↦ {x | t i x ≠ 0}) i ∩ U).Nonempty} := by intro x hx rw [Set.mem_setOf] at hx ⊢ use y simpa using ⟨hx, mem_of_mem_nhds hu⟩ exact Set.Finite.subset hfin this lemma ContMDiffAt.finsum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : M | t i x ≠ 0}) (ht' : ∀ i, ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) x₀) : ContMDiffAt I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ᶠ i, t i x)) x₀ := by simp_rw [← contMDiffWithinAt_univ] at ht' ⊢ exact ContMDiffWithinAt.finsum_section_of_locallyFinite ht ht' lemma ContMDiffOn.finsum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : M | t i x ≠ 0}) (ht' : ∀ i, ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x)) u) : ContMDiffOn I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ᶠ i, t i x)) u := fun x hx ↦ ContMDiffWithinAt.finsum_section_of_locallyFinite ht fun i ↦ ht' i x hx lemma ContMDiff.finsum_section_of_locallyFinite (ht : LocallyFinite fun i ↦ {x : M | t i x ≠ 0}) (ht' : ∀ i, ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (t i x))) : ContMDiff I (I.prod 𝓘(𝕜, F)) n (fun x ↦ TotalSpace.mk' F x (∑ᶠ i, t i x)) := fun x ↦ ContMDiffAt.finsum_section_of_locallyFinite ht fun i ↦ ht' i x end operations /-- Bundled `n` times continuously differentiable sections of a vector bundle. Denoted as `Cₛ^n⟮I; F, V⟯` within the `Manifold` namespace. -/ structure ContMDiffSection where /-- the underlying function of this section -/ protected toFun : ∀ x, V x /-- proof that this section is `C^n` -/ protected contMDiff_toFun : ContMDiff I (I.prod 𝓘(𝕜, F)) n fun x ↦ TotalSpace.mk' F x (toFun x) @[inherit_doc] scoped[Manifold] notation "Cₛ^" n "⟮" I "; " F ", " V "⟯" => ContMDiffSection I F n V namespace ContMDiffSection variable {I} {n} {F} {V} instance : DFunLike Cₛ^n⟮I; F, V⟯ M V where coe := ContMDiffSection.toFun coe_injective' := by rintro ⟨⟩ ⟨⟩ h; congr variable {s t : Cₛ^n⟮I; F, V⟯} @[simp] theorem coeFn_mk (s : ∀ x, V x) (hs : ContMDiff I (I.prod 𝓘(𝕜, F)) n fun x => TotalSpace.mk x (s x)) : (mk s hs : ∀ x, V x) = s := rfl protected theorem contMDiff (s : Cₛ^n⟮I; F, V⟯) : ContMDiff I (I.prod 𝓘(𝕜, F)) n fun x => TotalSpace.mk' F x (s x : V x) := s.contMDiff_toFun theorem coe_inj ⦃s t : Cₛ^n⟮I; F, V⟯⦄ (h : (s : ∀ x, V x) = t) : s = t := DFunLike.ext' h theorem coe_injective : Injective ((↑) : Cₛ^n⟮I; F, V⟯ → ∀ x, V x) := coe_inj @[ext] theorem ext (h : ∀ x, s x = t x) : s = t := DFunLike.ext _ _ h section variable [∀ x, AddCommGroup (V x)] [∀ x, Module 𝕜 (V x)] [VectorBundle 𝕜 F V] instance instAdd : Add Cₛ^n⟮I; F, V⟯ := ⟨fun s t ↦ ⟨s + t, s.contMDiff.add_section t.contMDiff⟩⟩ @[simp] theorem coe_add (s t : Cₛ^n⟮I; F, V⟯) : ⇑(s + t) = ⇑s + t := rfl instance instSub : Sub Cₛ^n⟮I; F, V⟯ := ⟨fun s t ↦ ⟨s - t, s.contMDiff.sub_section t.contMDiff⟩⟩ @[simp] theorem coe_sub (s t : Cₛ^n⟮I; F, V⟯) : ⇑(s - t) = s - t := rfl instance instZero : Zero Cₛ^n⟮I; F, V⟯ := ⟨⟨fun _ => 0, (contMDiff_zeroSection 𝕜 V).of_le le_top⟩⟩ instance inhabited : Inhabited Cₛ^n⟮I; F, V⟯ := ⟨0⟩ @[simp] theorem coe_zero : ⇑(0 : Cₛ^n⟮I; F, V⟯) = 0 := rfl instance instNeg : Neg Cₛ^n⟮I; F, V⟯ := ⟨fun s ↦ ⟨-s, s.contMDiff.neg_section⟩⟩ @[simp] theorem coe_neg (s : Cₛ^n⟮I; F, V⟯) : ⇑(-s : Cₛ^n⟮I; F, V⟯) = -s := rfl instance instNSMul : SMul ℕ Cₛ^n⟮I; F, V⟯ := ⟨nsmulRec⟩ @[simp] theorem coe_nsmul (s : Cₛ^n⟮I; F, V⟯) (k : ℕ) : ⇑(k • s : Cₛ^n⟮I; F, V⟯) = k • ⇑s := by induction k with | zero => simp_rw [zero_smul]; rfl | succ k ih => simp_rw [succ_nsmul, ← ih]; rfl instance instZSMul : SMul ℤ Cₛ^n⟮I; F, V⟯ := ⟨zsmulRec⟩ @[simp] theorem coe_zsmul (s : Cₛ^n⟮I; F, V⟯) (z : ℤ) : ⇑(z • s : Cₛ^n⟮I; F, V⟯) = z • ⇑s := by rcases z with n | n · refine (coe_nsmul s n).trans ?_ simp only [Int.ofNat_eq_coe, natCast_zsmul] · refine (congr_arg Neg.neg (coe_nsmul s (n + 1))).trans ?_ simp only [negSucc_zsmul] instance instAddCommGroup : AddCommGroup Cₛ^n⟮I; F, V⟯ := coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub coe_nsmul coe_zsmul instance instSMul : SMul 𝕜 Cₛ^n⟮I; F, V⟯ := ⟨fun c s ↦ ⟨c • ⇑s, s.contMDiff.const_smul_section⟩⟩ @[simp] theorem coe_smul (r : 𝕜) (s : Cₛ^n⟮I; F, V⟯) : ⇑(r • s : Cₛ^n⟮I; F, V⟯) = r • ⇑s := rfl variable (I F V n) in /-- The additive morphism from `C^n` sections to dependent maps. -/ def coeAddHom : Cₛ^n⟮I; F, V⟯ →+ ∀ x, V x where toFun := (↑) map_zero' := coe_zero map_add' := coe_add @[simp] theorem coeAddHom_apply (s : Cₛ^n⟮I; F, V⟯) : coeAddHom I F n V s = s := rfl instance instModule : Module 𝕜 Cₛ^n⟮I; F, V⟯ := coe_injective.module 𝕜 (coeAddHom I F n V) coe_smul end protected theorem mdifferentiable' (s : Cₛ^n⟮I; F, V⟯) (hn : 1 ≤ n) : MDifferentiable I (I.prod 𝓘(𝕜, F)) fun x => TotalSpace.mk' F x (s x : V x) := s.contMDiff.mdifferentiable hn protected theorem mdifferentiable (s : Cₛ^∞⟮I; F, V⟯) : MDifferentiable I (I.prod 𝓘(𝕜, F)) fun x => TotalSpace.mk' F x (s x : V x) := s.contMDiff.mdifferentiable (mod_cast le_top) protected theorem mdifferentiableAt (s : Cₛ^∞⟮I; F, V⟯) {x} : MDifferentiableAt I (I.prod 𝓘(𝕜, F)) (fun x => TotalSpace.mk' F x (s x : V x)) x := s.mdifferentiable x end ContMDiffSection
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/Hom.lean
import Mathlib.Geometry.Manifold.VectorBundle.Basic import Mathlib.Topology.VectorBundle.Hom import Mathlib.Geometry.Manifold.VectorBundle.MDifferentiable /-! # Homs of `C^n` vector bundles over the same base space Here we show that the bundle of continuous linear maps is a `C^n` vector bundle. We also show that applying a smooth family of linear maps to a smooth family of vectors gives a smooth result, in several versions. Note that we only do this for bundles of linear maps, not for bundles of arbitrary semilinear maps. Indeed, semilinear maps are typically not smooth. For instance, complex conjugation is not `ℂ`-differentiable. -/ noncomputable section open Bundle Set OpenPartialHomeomorph ContinuousLinearMap Pretrivialization open scoped Manifold Bundle Topology section variable {𝕜 B F₁ F₂ M : Type*} {n : WithTop ℕ∞} {E₁ : B → Type*} {E₂ : B → Type*} [NontriviallyNormedField 𝕜] [∀ x, AddCommGroup (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] [TopologicalSpace (TotalSpace F₁ E₁)] [∀ x, TopologicalSpace (E₁ x)] [∀ x, AddCommGroup (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] [TopologicalSpace (TotalSpace F₂ E₂)] [∀ x, TopologicalSpace (E₂ x)] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners 𝕜 EB HB} [TopologicalSpace B] [ChartedSpace HB B] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] [FiberBundle F₁ E₁] [VectorBundle 𝕜 F₁ E₁] [FiberBundle F₂ E₂] [VectorBundle 𝕜 F₂ E₂] {e₁ e₁' : Trivialization F₁ (π F₁ E₁)} {e₂ e₂' : Trivialization F₂ (π F₂ E₂)} local notation "LE₁E₂" => TotalSpace (F₁ →L[𝕜] F₂) (fun (b : B) ↦ E₁ b →L[𝕜] E₂ b) section theorem contMDiffOn_continuousLinearMapCoordChange [ContMDiffVectorBundle n F₁ E₁ IB] [ContMDiffVectorBundle n F₂ E₂ IB] [MemTrivializationAtlas e₁] [MemTrivializationAtlas e₁'] [MemTrivializationAtlas e₂] [MemTrivializationAtlas e₂'] : ContMDiffOn IB 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] F₁ →L[𝕜] F₂) n (continuousLinearMapCoordChange (RingHom.id 𝕜) e₁ e₁' e₂ e₂') (e₁.baseSet ∩ e₂.baseSet ∩ (e₁'.baseSet ∩ e₂'.baseSet)) := by have h₁ := contMDiffOn_coordChangeL (IB := IB) e₁' e₁ (n := n) have h₂ := contMDiffOn_coordChangeL (IB := IB) e₂ e₂' (n := n) refine (h₁.mono ?_).cle_arrowCongr (h₂.mono ?_) <;> mfld_set_tac variable [∀ x, IsTopologicalAddGroup (E₂ x)] [∀ x, ContinuousSMul 𝕜 (E₂ x)] theorem hom_chart (y₀ y : LE₁E₂) : chartAt (ModelProd HB (F₁ →L[𝕜] F₂)) y₀ y = (chartAt HB y₀.1 y.1, inCoordinates F₁ E₁ F₂ E₂ y₀.1 y.1 y₀.1 y.1 y.2) := by rw [FiberBundle.chartedSpace_chartAt, trans_apply, OpenPartialHomeomorph.prod_apply, Trivialization.coe_coe, OpenPartialHomeomorph.refl_apply, Function.id_def, hom_trivializationAt_apply] theorem contMDiffWithinAt_hom_bundle (f : M → LE₁E₂) {s : Set M} {x₀ : M} : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) n f s x₀ ↔ ContMDiffWithinAt IM IB n (fun x ↦ (f x).1) s x₀ ∧ ContMDiffWithinAt IM 𝓘(𝕜, F₁ →L[𝕜] F₂) n (fun x ↦ inCoordinates F₁ E₁ F₂ E₂ (f x₀).1 (f x).1 (f x₀).1 (f x).1 (f x).2) s x₀ := contMDiffWithinAt_totalSpace theorem contMDiffAt_hom_bundle (f : M → LE₁E₂) {x₀ : M} : ContMDiffAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) n f x₀ ↔ ContMDiffAt IM IB n (fun x ↦ (f x).1) x₀ ∧ ContMDiffAt IM 𝓘(𝕜, F₁ →L[𝕜] F₂) n (fun x ↦ inCoordinates F₁ E₁ F₂ E₂ (f x₀).1 (f x).1 (f x₀).1 (f x).1 (f x).2) x₀ := contMDiffAt_totalSpace end section theorem mdifferentiableOn_continuousLinearMapCoordChange [ContMDiffVectorBundle 1 F₁ E₁ IB] [ContMDiffVectorBundle 1 F₂ E₂ IB] [MemTrivializationAtlas e₁] [MemTrivializationAtlas e₁'] [MemTrivializationAtlas e₂] [MemTrivializationAtlas e₂'] : MDifferentiableOn IB 𝓘(𝕜, (F₁ →L[𝕜] F₂) →L[𝕜] F₁ →L[𝕜] F₂) (continuousLinearMapCoordChange (RingHom.id 𝕜) e₁ e₁' e₂ e₂') (e₁.baseSet ∩ e₂.baseSet ∩ (e₁'.baseSet ∩ e₂'.baseSet)) := by have h₁ := contMDiffOn_coordChangeL (IB := IB) e₁' e₁ (n := 1) |>.mdifferentiableOn le_rfl have h₂ := contMDiffOn_coordChangeL (IB := IB) e₂ e₂' (n := 1) |>.mdifferentiableOn le_rfl refine (h₁.mono ?_).cle_arrowCongr (h₂.mono ?_) <;> mfld_set_tac variable [∀ x, IsTopologicalAddGroup (E₂ x)] [∀ x, ContinuousSMul 𝕜 (E₂ x)] theorem mdifferentiableWithinAt_hom_bundle (f : M → LE₁E₂) {s : Set M} {x₀ : M} : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) f s x₀ ↔ MDifferentiableWithinAt IM IB (fun x ↦ (f x).1) s x₀ ∧ MDifferentiableWithinAt IM 𝓘(𝕜, F₁ →L[𝕜] F₂) (fun x ↦ inCoordinates F₁ E₁ F₂ E₂ (f x₀).1 (f x).1 (f x₀).1 (f x).1 (f x).2) s x₀ := mdifferentiableWithinAt_totalSpace IB .. theorem mdifferentiableAt_hom_bundle (f : M → LE₁E₂) {x₀ : M} : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) f x₀ ↔ MDifferentiableAt IM IB (fun x ↦ (f x).1) x₀ ∧ MDifferentiableAt IM 𝓘(𝕜, F₁ →L[𝕜] F₂) (fun x ↦ inCoordinates F₁ E₁ F₂ E₂ (f x₀).1 (f x).1 (f x₀).1 (f x).1 (f x).2) x₀ := mdifferentiableAt_totalSpace .. end variable [∀ x, IsTopologicalAddGroup (E₂ x)] [∀ x, ContinuousSMul 𝕜 (E₂ x)] [ContMDiffVectorBundle n F₁ E₁ IB] [ContMDiffVectorBundle n F₂ E₂ IB] instance Bundle.ContinuousLinearMap.vectorPrebundle.isContMDiff : (Bundle.ContinuousLinearMap.vectorPrebundle (RingHom.id 𝕜) F₁ E₁ F₂ E₂).IsContMDiff IB n where exists_contMDiffCoordChange := by rintro _ ⟨e₁, e₂, he₁, he₂, rfl⟩ _ ⟨e₁', e₂', he₁', he₂', rfl⟩ exact ⟨continuousLinearMapCoordChange (RingHom.id 𝕜) e₁ e₁' e₂ e₂', contMDiffOn_continuousLinearMapCoordChange, continuousLinearMapCoordChange_apply (RingHom.id 𝕜) e₁ e₁' e₂ e₂'⟩ instance ContMDiffVectorBundle.continuousLinearMap : ContMDiffVectorBundle n (F₁ →L[𝕜] F₂) ((fun (b : B) ↦ E₁ b →L[𝕜] E₂ b)) IB := (Bundle.ContinuousLinearMap.vectorPrebundle (RingHom.id 𝕜) F₁ E₁ F₂ E₂).contMDiffVectorBundle IB end section /- Declare two manifolds `B₁` and `B₂` (with models `IB₁ : HB₁ → EB₁` and `IB₂ : HB₂ → EB₂`), and two vector bundles `E₁` and `E₂` respectively over `B₁` and `B₂` (with model fibers `F₁` and `F₂`). Also a third manifold `M`, which will be the source of all our maps. -/ variable {𝕜 F₁ F₂ B₁ B₂ M : Type*} {E₁ : B₁ → Type*} {E₂ : B₂ → Type*} [NontriviallyNormedField 𝕜] [∀ x, AddCommGroup (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] [TopologicalSpace (TotalSpace F₁ E₁)] [∀ x, TopologicalSpace (E₁ x)] [∀ x, AddCommGroup (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] [TopologicalSpace (TotalSpace F₂ E₂)] [∀ x, TopologicalSpace (E₂ x)] {EB₁ : Type*} [NormedAddCommGroup EB₁] [NormedSpace 𝕜 EB₁] {HB₁ : Type*} [TopologicalSpace HB₁] {IB₁ : ModelWithCorners 𝕜 EB₁ HB₁} [TopologicalSpace B₁] [ChartedSpace HB₁ B₁] {EB₂ : Type*} [NormedAddCommGroup EB₂] [NormedSpace 𝕜 EB₂] {HB₂ : Type*} [TopologicalSpace HB₂] {IB₂ : ModelWithCorners 𝕜 EB₂ HB₂} [TopologicalSpace B₂] [ChartedSpace HB₂ B₂] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] {n : WithTop ℕ∞} [FiberBundle F₁ E₁] [VectorBundle 𝕜 F₁ E₁] [FiberBundle F₂ E₂] [VectorBundle 𝕜 F₂ E₂] {b₁ : M → B₁} {b₂ : M → B₂} {m₀ : M} {ϕ : Π (m : M), E₁ (b₁ m) →L[𝕜] E₂ (b₂ m)} {v : Π (m : M), E₁ (b₁ m)} {s : Set M} /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a base map `b₁ : M → B₁`, and another base map `b₂ : M → B₂`. Given linear maps `ϕ m : E₁ (b₁ m) → E₂ (b₂ m)` depending smoothly on `m`, one can apply `ϕ m` to `g m`, and the resulting map is `C^n`. Note that the smoothness of `ϕ` cannot be always be stated as smoothness of a map into a manifold, as the pullback bundles `b₁ *ᵖ E₁` and `b₂ *ᵖ E₂` are smooth manifolds only when `b₁` and `b₂` are globally smooth, but we want to apply this lemma with only local information. Therefore, we formulate it using smoothness of `ϕ` read in coordinates. Version for `ContMDiffWithinAt`. We also give a version for `ContMDiffAt`, but no version for `ContMDiffOn` or `ContMDiff` as our assumption, written in coordinates, only makes sense around a point. For a version with `B₁ = B₂` and `b₁ = b₂`, in which smoothness can be expressed without `inCoordinates`, see `ContMDiffWithinAt.clm_bundle_apply` -/ lemma ContMDiffWithinAt.clm_apply_of_inCoordinates (hϕ : ContMDiffWithinAt IM 𝓘(𝕜, F₁ →L[𝕜] F₂) n (fun m ↦ inCoordinates F₁ E₁ F₂ E₂ (b₁ m₀) (b₁ m) (b₂ m₀) (b₂ m) (ϕ m)) s m₀) (hv : ContMDiffWithinAt IM (IB₁.prod 𝓘(𝕜, F₁)) n (fun m ↦ (v m : TotalSpace F₁ E₁)) s m₀) (hb₂ : ContMDiffWithinAt IM IB₂ n b₂ s m₀) : ContMDiffWithinAt IM (IB₂.prod 𝓘(𝕜, F₂)) n (fun m ↦ (ϕ m (v m) : TotalSpace F₂ E₂)) s m₀ := by rw [← contMDiffWithinAt_insert_self] at hϕ hv hb₂ ⊢ rw [contMDiffWithinAt_totalSpace] at hv ⊢ refine ⟨hb₂, ?_⟩ apply (ContMDiffWithinAt.clm_apply hϕ hv.2).congr_of_eventuallyEq_of_mem ?_ (mem_insert m₀ s) have A : ∀ᶠ m in 𝓝[insert m₀ s] m₀, b₁ m ∈ (trivializationAt F₁ E₁ (b₁ m₀)).baseSet := by apply hv.1.continuousWithinAt apply (trivializationAt F₁ E₁ (b₁ m₀)).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' (b₁ m₀) have A' : ∀ᶠ m in 𝓝[insert m₀ s] m₀, b₂ m ∈ (trivializationAt F₂ E₂ (b₂ m₀)).baseSet := by apply hb₂.continuousWithinAt apply (trivializationAt F₂ E₂ (b₂ m₀)).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' (b₂ m₀) filter_upwards [A, A'] with m hm h'm rw [inCoordinates_eq hm h'm] simp only [coe_comp', ContinuousLinearEquiv.coe_coe, Trivialization.continuousLinearEquivAt_apply, Trivialization.continuousLinearEquivAt_symm_apply, Function.comp_apply] congr rw [Trivialization.symm_apply_apply_mk (trivializationAt F₁ E₁ (b₁ m₀)) hm (v m)] /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a base map `b₁ : M → B₁`, and another base map `b₂ : M → B₂`. Given linear maps `ϕ m : E₁ (b₁ m) → E₂ (b₂ m)` depending smoothly on `m`, one can apply `ϕ m` to `g m`, and the resulting map is `C^n`. Note that the smoothness of `ϕ` cannot be always be stated as smoothness of a map into a manifold, as the pullback bundles `b₁ *ᵖ E₁` and `b₂ *ᵖ E₂` are smooth manifolds only when `b₁` and `b₂` are globally smooth, but we want to apply this lemma with only local information. Therefore, we formulate it using smoothness of `ϕ` read in coordinates. Version for `ContMDiffAt`. We also give a version for `ContMDiffWithinAt`, but no version for `ContMDiffOn` or `ContMDiff` as our assumption, written in coordinates, only makes sense around a point. For a version with `B₁ = B₂` and `b₁ = b₂`, in which smoothness can be expressed without `inCoordinates`, see `ContMDiffAt.clm_bundle_apply` -/ lemma ContMDiffAt.clm_apply_of_inCoordinates (hϕ : ContMDiffAt IM 𝓘(𝕜, F₁ →L[𝕜] F₂) n (fun m ↦ inCoordinates F₁ E₁ F₂ E₂ (b₁ m₀) (b₁ m) (b₂ m₀) (b₂ m) (ϕ m)) m₀) (hv : ContMDiffAt IM (IB₁.prod 𝓘(𝕜, F₁)) n (fun m ↦ (v m : TotalSpace F₁ E₁)) m₀) (hb₂ : ContMDiffAt IM IB₂ n b₂ m₀) : ContMDiffAt IM (IB₂.prod 𝓘(𝕜, F₂)) n (fun m ↦ (ϕ m (v m) : TotalSpace F₂ E₂)) m₀ := by rw [← contMDiffWithinAt_univ] at hϕ hv hb₂ ⊢ exact ContMDiffWithinAt.clm_apply_of_inCoordinates hϕ hv hb₂ end section /- Declare a manifold `B` (with model `IB : HB → EB`), and three vector bundles `E₁`, `E₂` and `E₃` over `B` (with model fibers `F₁`, `F₂` and `F₃`). Also a second manifold `M`, which will be the source of all our maps. -/ variable {𝕜 B F₁ F₂ F₃ M : Type*} [NontriviallyNormedField 𝕜] {n : WithTop ℕ∞} {E₁ : B → Type*} [∀ x, AddCommGroup (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] [TopologicalSpace (TotalSpace F₁ E₁)] [∀ x, TopologicalSpace (E₁ x)] {E₂ : B → Type*} [∀ x, AddCommGroup (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] [TopologicalSpace (TotalSpace F₂ E₂)] [∀ x, TopologicalSpace (E₂ x)] {E₃ : B → Type*} [∀ x, AddCommGroup (E₃ x)] [∀ x, Module 𝕜 (E₃ x)] [NormedAddCommGroup F₃] [NormedSpace 𝕜 F₃] [TopologicalSpace (TotalSpace F₃ E₃)] [∀ x, TopologicalSpace (E₃ x)] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] {IB : ModelWithCorners 𝕜 EB HB} [TopologicalSpace B] [ChartedSpace HB B] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] [FiberBundle F₁ E₁] [VectorBundle 𝕜 F₁ E₁] [FiberBundle F₂ E₂] [VectorBundle 𝕜 F₂ E₂] [FiberBundle F₃ E₃] [VectorBundle 𝕜 F₃ E₃] {b : M → B} {v : ∀ x, E₁ (b x)} {s : Set M} {x : M} section OneVariable variable [∀ x, IsTopologicalAddGroup (E₂ x)] [∀ x, ContinuousSMul 𝕜 (E₂ x)] {ϕ : ∀ x, (E₁ (b x) →L[𝕜] E₂ (b x))} /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a base map `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is `C^n`. We give here a version of this statement within a set at a point. -/ lemma ContMDiffWithinAt.clm_bundle_apply (hϕ : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) n (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) s x) (hv : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F₁)) n (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s x) : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F₂)) n (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) s x := by simp only [contMDiffWithinAt_hom_bundle] at hϕ exact hϕ.2.clm_apply_of_inCoordinates hv hϕ.1 /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a base map `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is `C^n`. We give here a version of this statement at a point. -/ lemma ContMDiffAt.clm_bundle_apply (hϕ : ContMDiffAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) n (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) x) (hv : ContMDiffAt IM (IB.prod 𝓘(𝕜, F₁)) n (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) x) : ContMDiffAt IM (IB.prod 𝓘(𝕜, F₂)) n (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) x := ContMDiffWithinAt.clm_bundle_apply hϕ hv /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a base map `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is `C^n`. We give here a version of this statement on a set. -/ lemma ContMDiffOn.clm_bundle_apply (hϕ : ContMDiffOn IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) n (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) s) (hv : ContMDiffOn IM (IB.prod 𝓘(𝕜, F₁)) n (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s) : ContMDiffOn IM (IB.prod 𝓘(𝕜, F₂)) n (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) s := fun x hx ↦ (hϕ x hx).clm_bundle_apply (hv x hx) /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a base map `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is `C^n`. -/ lemma ContMDiff.clm_bundle_apply (hϕ : ContMDiff IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) n (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m))) (hv : ContMDiff IM (IB.prod 𝓘(𝕜, F₁)) n (fun m ↦ TotalSpace.mk' F₁ (b m) (v m))) : ContMDiff IM (IB.prod 𝓘(𝕜, F₂)) n (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) := fun x ↦ (hϕ x).clm_bundle_apply (hv x) end OneVariable section OneVariable' variable [∀ x, IsTopologicalAddGroup (E₂ x)] [∀ x, ContinuousSMul 𝕜 (E₂ x)] {ϕ : ∀ x, (E₁ (b x) →L[𝕜] E₂ (b x))} /-- Consider a differentiable map `v : M → E₁` to a vector bundle, over a base map `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is differentiable. We give here a version of this statement within a set at a point. -/ lemma MDifferentiableWithinAt.clm_bundle_apply (hϕ : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) s x) (hv : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F₁)) (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s x) : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F₂)) (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) s x := by simp only [mdifferentiableWithinAt_hom_bundle] at hϕ exact hϕ.2.clm_apply_of_inCoordinates hv hϕ.1 /-- Consider a differentiable map `v : M → E₁` to a vector bundle, over a base map `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is differentiable. We give here a version of this statement at a point. -/ lemma MDifferentiableAt.clm_bundle_apply (hϕ : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) x) (hv : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F₁)) (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) x) : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F₂)) (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) x := MDifferentiableWithinAt.clm_bundle_apply hϕ hv /-- Consider a differentiable map `v : M → E₁` to a vector bundle, over a base map `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is differentiable. We give here a version of this statement on a set. -/ lemma MDifferentiableOn.clm_bundle_apply (hϕ : MDifferentiableOn IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) s) (hv : MDifferentiableOn IM (IB.prod 𝓘(𝕜, F₁)) (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s) : MDifferentiableOn IM (IB.prod 𝓘(𝕜, F₂)) (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) s := fun x hx ↦ (hϕ x hx).clm_bundle_apply (hv x hx) /-- Consider a differentiable map `v : M → E₁` to a vector bundle, over a base map `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is differentiable. -/ lemma MDifferentiable.clm_bundle_apply (hϕ : MDifferentiable IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂)) (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m))) (hv : MDifferentiable IM (IB.prod 𝓘(𝕜, F₁)) (fun m ↦ TotalSpace.mk' F₁ (b m) (v m))) : MDifferentiable IM (IB.prod 𝓘(𝕜, F₂)) (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) := fun x ↦ (hϕ x).clm_bundle_apply (hv x) end OneVariable' section TwoVariables variable [∀ x, IsTopologicalAddGroup (E₃ x)] [∀ x, ContinuousSMul 𝕜 (E₃ x)] {ψ : ∀ x, (E₁ (b x) →L[𝕜] E₂ (b x) →L[𝕜] E₃ (b x))} {w : ∀ x, E₂ (b x)} /-- Consider `C^n` maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a base map `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is `C^n`. We give here a version of this statement within a set at a point. -/ lemma ContMDiffWithinAt.clm_bundle_apply₂ (hψ : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂ →L[𝕜] F₃)) n (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) s x) (hv : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F₁)) n (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s x) (hw : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F₂)) n (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) s x) : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F₃)) n (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) s x := hψ.clm_bundle_apply hv |>.clm_bundle_apply hw /-- Consider `C^n` maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a base map `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is `C^n`. We give here a version of this statement at a point. -/ lemma ContMDiffAt.clm_bundle_apply₂ (hψ : ContMDiffAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂ →L[𝕜] F₃)) n (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) x) (hv : ContMDiffAt IM (IB.prod 𝓘(𝕜, F₁)) n (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) x) (hw : ContMDiffAt IM (IB.prod 𝓘(𝕜, F₂)) n (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) x) : ContMDiffAt IM (IB.prod 𝓘(𝕜, F₃)) n (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) x := ContMDiffWithinAt.clm_bundle_apply₂ hψ hv hw /-- Consider `C^n` maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a base map `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is `C^n`. We give here a version of this statement on a set. -/ lemma ContMDiffOn.clm_bundle_apply₂ (hψ : ContMDiffOn IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂ →L[𝕜] F₃)) n (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) s) (hv : ContMDiffOn IM (IB.prod 𝓘(𝕜, F₁)) n (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s) (hw : ContMDiffOn IM (IB.prod 𝓘(𝕜, F₂)) n (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) s) : ContMDiffOn IM (IB.prod 𝓘(𝕜, F₃)) n (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) s := fun x hx ↦ (hψ x hx).clm_bundle_apply₂ (hv x hx) (hw x hx) /-- Consider `C^n` maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a base map `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is `C^n`. -/ lemma ContMDiff.clm_bundle_apply₂ (hψ : ContMDiff IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂ →L[𝕜] F₃)) n (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m))) (hv : ContMDiff IM (IB.prod 𝓘(𝕜, F₁)) n (fun m ↦ TotalSpace.mk' F₁ (b m) (v m))) (hw : ContMDiff IM (IB.prod 𝓘(𝕜, F₂)) n (fun m ↦ TotalSpace.mk' F₂ (b m) (w m))) : ContMDiff IM (IB.prod 𝓘(𝕜, F₃)) n (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) := fun x ↦ (hψ x).clm_bundle_apply₂ (hv x) (hw x) end TwoVariables section TwoVariables' variable [∀ x, IsTopologicalAddGroup (E₃ x)] [∀ x, ContinuousSMul 𝕜 (E₃ x)] {ψ : ∀ x, (E₁ (b x) →L[𝕜] E₂ (b x) →L[𝕜] E₃ (b x))} {w : ∀ x, E₂ (b x)} /-- Consider differentiable maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a base map `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is differentiable. We give here a version of this statement within a set at a point. -/ lemma MDifferentiableWithinAt.clm_bundle_apply₂ (hψ : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂ →L[𝕜] F₃)) (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) s x) (hv : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F₁)) (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s x) (hw : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F₂)) (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) s x) : MDifferentiableWithinAt IM (IB.prod 𝓘(𝕜, F₃)) (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) s x := hψ.clm_bundle_apply hv |>.clm_bundle_apply hw /-- Consider differentiable maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a base map `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is differentiable. We give here a version of this statement at a point. -/ lemma MDifferentiableAt.clm_bundle_apply₂ (hψ : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂ →L[𝕜] F₃)) (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) x) (hv : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F₁)) (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) x) (hw : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F₂)) (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) x) : MDifferentiableAt IM (IB.prod 𝓘(𝕜, F₃)) (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) x := MDifferentiableWithinAt.clm_bundle_apply₂ hψ hv hw /-- Consider differentiable maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a base map `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is differentiable. We give here a version of this statement on a set. -/ lemma MDifferentiableOn.clm_bundle_apply₂ (hψ : MDifferentiableOn IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂ →L[𝕜] F₃)) (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) s) (hv : MDifferentiableOn IM (IB.prod 𝓘(𝕜, F₁)) (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s) (hw : MDifferentiableOn IM (IB.prod 𝓘(𝕜, F₂)) (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) s) : MDifferentiableOn IM (IB.prod 𝓘(𝕜, F₃)) (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) s := fun x hx ↦ (hψ x hx).clm_bundle_apply₂ (hv x hx) (hw x hx) /-- Consider differentiable maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a base map `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is differentiable. -/ lemma MDifferentiable.clm_bundle_apply₂ (hψ : MDifferentiable IM (IB.prod 𝓘(𝕜, F₁ →L[𝕜] F₂ →L[𝕜] F₃)) (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m))) (hv : MDifferentiable IM (IB.prod 𝓘(𝕜, F₁)) (fun m ↦ TotalSpace.mk' F₁ (b m) (v m))) (hw : MDifferentiable IM (IB.prod 𝓘(𝕜, F₂)) (fun m ↦ TotalSpace.mk' F₂ (b m) (w m))) : MDifferentiable IM (IB.prod 𝓘(𝕜, F₃)) (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) := fun x ↦ (hψ x).clm_bundle_apply₂ (hv x) (hw x) end TwoVariables' end
.lake/packages/mathlib/Mathlib/Geometry/Manifold/VectorBundle/FiberwiseLinear.lean
import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace /-! # The groupoid of `C^n`, fiberwise-linear maps This file contains preliminaries for the definition of a `C^n` vector bundle: an associated `StructureGroupoid`, the groupoid of `contMDiffFiberwiseLinear` functions. -/ noncomputable section open Set TopologicalSpace open scoped Manifold Topology /-! ### The groupoid of `C^n`, fiberwise-linear maps -/ variable {𝕜 B F : Type*} [TopologicalSpace B] variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] namespace FiberwiseLinear variable {φ φ' : B → F ≃L[𝕜] F} {U U' : Set B} /-- For `B` a topological space and `F` a `𝕜`-normed space, a map from `U : Set B` to `F ≃L[𝕜] F` determines an open partial homeomorphism from `B × F` to itself by its action fiberwise. -/ def openPartialHomeomorph (φ : B → F ≃L[𝕜] F) (hU : IsOpen U) (hφ : ContinuousOn (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContinuousOn (fun x => (φ x).symm : B → F →L[𝕜] F) U) : OpenPartialHomeomorph (B × F) (B × F) where toFun x := (x.1, φ x.1 x.2) invFun x := (x.1, (φ x.1).symm x.2) source := U ×ˢ univ target := U ×ˢ univ map_source' _x hx := mk_mem_prod hx.1 (mem_univ _) map_target' _x hx := mk_mem_prod hx.1 (mem_univ _) left_inv' _ _ := Prod.ext rfl (ContinuousLinearEquiv.symm_apply_apply _ _) right_inv' _ _ := Prod.ext rfl (ContinuousLinearEquiv.apply_symm_apply _ _) open_source := hU.prod isOpen_univ open_target := hU.prod isOpen_univ continuousOn_toFun := have : ContinuousOn (fun p : B × F => ((φ p.1 : F →L[𝕜] F), p.2)) (U ×ˢ univ) := hφ.prodMap continuousOn_id continuousOn_fst.prodMk (isBoundedBilinearMap_apply.continuous.comp_continuousOn this) continuousOn_invFun := have : ContinuousOn (fun p : B × F => (((φ p.1).symm : F →L[𝕜] F), p.2)) (U ×ˢ univ) := h2φ.prodMap continuousOn_id continuousOn_fst.prodMk (isBoundedBilinearMap_apply.continuous.comp_continuousOn this) @[deprecated (since := "2025-08-29")] alias PartialHomeomorph := openPartialHomeomorph /-- Compute the composition of two open partial homeomorphisms induced by fiberwise linear equivalences. -/ theorem trans_openPartialHomeomorph_apply (hU : IsOpen U) (hφ : ContinuousOn (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContinuousOn (fun x => (φ x).symm : B → F →L[𝕜] F) U) (hU' : IsOpen U') (hφ' : ContinuousOn (fun x => φ' x : B → F →L[𝕜] F) U') (h2φ' : ContinuousOn (fun x => (φ' x).symm : B → F →L[𝕜] F) U') (b : B) (v : F) : (FiberwiseLinear.openPartialHomeomorph φ hU hφ h2φ ≫ₕ FiberwiseLinear.openPartialHomeomorph φ' hU' hφ' h2φ') ⟨b, v⟩ = ⟨b, φ' b (φ b v)⟩ := rfl @[deprecated (since := "2025-08-29")] alias trans_PartialHomeomorph_apply := trans_openPartialHomeomorph_apply /-- Compute the source of the composition of two open partial homeomorphisms induced by fiberwise linear equivalences. -/ theorem source_trans_openPartialHomeomorph (hU : IsOpen U) (hφ : ContinuousOn (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContinuousOn (fun x => (φ x).symm : B → F →L[𝕜] F) U) (hU' : IsOpen U') (hφ' : ContinuousOn (fun x => φ' x : B → F →L[𝕜] F) U') (h2φ' : ContinuousOn (fun x => (φ' x).symm : B → F →L[𝕜] F) U') : (FiberwiseLinear.openPartialHomeomorph φ hU hφ h2φ ≫ₕ FiberwiseLinear.openPartialHomeomorph φ' hU' hφ' h2φ').source = (U ∩ U') ×ˢ univ := by dsimp only [FiberwiseLinear.openPartialHomeomorph]; mfld_set_tac @[deprecated (since := "2025-08-29")] alias source_trans_PartialHomeomorph := source_trans_openPartialHomeomorph /-- Compute the target of the composition of two open partial homeomorphisms induced by fiberwise linear equivalences. -/ theorem target_trans_openPartialHomeomorph (hU : IsOpen U) (hφ : ContinuousOn (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContinuousOn (fun x => (φ x).symm : B → F →L[𝕜] F) U) (hU' : IsOpen U') (hφ' : ContinuousOn (fun x => φ' x : B → F →L[𝕜] F) U') (h2φ' : ContinuousOn (fun x => (φ' x).symm : B → F →L[𝕜] F) U') : (FiberwiseLinear.openPartialHomeomorph φ hU hφ h2φ ≫ₕ FiberwiseLinear.openPartialHomeomorph φ' hU' hφ' h2φ').target = (U ∩ U') ×ˢ univ := by dsimp only [FiberwiseLinear.openPartialHomeomorph]; mfld_set_tac @[deprecated (since := "2025-08-29")] alias target_trans_PartialHomeomorph := target_trans_openPartialHomeomorph end FiberwiseLinear variable {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] [ChartedSpace HB B] {IB : ModelWithCorners 𝕜 EB HB} /-- Let `e` be an open partial homeomorphism of `B × F`. Suppose that at every point `p` in the source of `e`, there is some neighbourhood `s` of `p` on which `e` is equal to a bi-`C^n` fiberwise linear open partial homeomorphism. Then the source of `e` is of the form `U ×ˢ univ`, for some set `U` in `B`, and, at any point `x` in `U`, admits a neighbourhood `u` of `x` such that `e` is equal on `u ×ˢ univ` to some bi-`C^n` fiberwise linear open partial homeomorphism. -/ theorem ContMDiffFiberwiseLinear.locality_aux₁ (n : WithTop ℕ∞) (e : OpenPartialHomeomorph (B × F) (B × F)) (h : ∀ p ∈ e.source, ∃ s : Set (B × F), IsOpen s ∧ p ∈ s ∧ ∃ (φ : B → F ≃L[𝕜] F) (u : Set B) (hu : IsOpen u) (hφ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => (φ x : F →L[𝕜] F)) u) (h2φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => ((φ x).symm : F →L[𝕜] F)) u), (e.restr s).EqOnSource (FiberwiseLinear.openPartialHomeomorph φ hu hφ.continuousOn h2φ.continuousOn)) : ∃ U : Set B, e.source = U ×ˢ univ ∧ ∀ x ∈ U, ∃ (φ : B → F ≃L[𝕜] F) (u : Set B) (hu : IsOpen u) (_huU : u ⊆ U) (_hux : x ∈ u), ∃ (hφ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => (φ x : F →L[𝕜] F)) u) (h2φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => ((φ x).symm : F →L[𝕜] F)) u), (e.restr (u ×ˢ univ)).EqOnSource (FiberwiseLinear.openPartialHomeomorph φ hu hφ.continuousOn h2φ.continuousOn) := by rw [SetCoe.forall'] at h choose s hs hsp φ u hu hφ h2φ heφ using h have hesu : ∀ p : e.source, e.source ∩ s p = u p ×ˢ univ := by intro p rw [← e.restr_source' (s _) (hs _)] exact (heφ p).1 have hu' : ∀ p : e.source, (p : B × F).fst ∈ u p := by intro p have : (p : B × F) ∈ e.source ∩ s p := ⟨p.prop, hsp p⟩ simpa only [hesu, mem_prod, mem_univ, and_true] using this have heu : ∀ p : e.source, ∀ q : B × F, q.fst ∈ u p → q ∈ e.source := by intro p q hq have : q ∈ u p ×ˢ (univ : Set F) := ⟨hq, trivial⟩ rw [← hesu p] at this exact this.1 have he : e.source = (Prod.fst '' e.source) ×ˢ (univ : Set F) := by apply HasSubset.Subset.antisymm · intro p hp exact ⟨⟨p, hp, rfl⟩, trivial⟩ · rintro ⟨x, v⟩ ⟨⟨p, hp, rfl : p.fst = x⟩, -⟩ exact heu ⟨p, hp⟩ (p.fst, v) (hu' ⟨p, hp⟩) refine ⟨Prod.fst '' e.source, he, ?_⟩ rintro x ⟨p, hp, rfl⟩ refine ⟨φ ⟨p, hp⟩, u ⟨p, hp⟩, hu ⟨p, hp⟩, ?_, hu' _, hφ ⟨p, hp⟩, h2φ ⟨p, hp⟩, ?_⟩ · intro y hy; exact ⟨(y, 0), heu ⟨p, hp⟩ ⟨_, _⟩ hy, rfl⟩ · rw [← hesu, e.restr_source_inter]; exact heφ ⟨p, hp⟩ /-- Let `e` be an open partial homeomorphism of `B × F` whose source is `U ×ˢ univ`, for some set `U` in `B`, and which, at any point `x` in `U`, admits a neighbourhood `u` of `x` such that `e` is equal on `u ×ˢ univ` to some bi-`C^n` fiberwise linear open partial homeomorphism. Then `e` itself is equal to some bi-`C^n` fiberwise linear open partial homeomorphism. This is the key mathematical point of the `locality` condition in the construction of the `StructureGroupoid` of bi-`C^n` fiberwise linear open partial homeomorphisms. The proof is by gluing together the various bi-`C^n` fiberwise linear open partial homeomorphism which exist locally. The `U` in the conclusion is the same `U` as in the hypothesis. We state it like this, because this is exactly what we need for `contMDiffFiberwiseLinear`. -/ theorem ContMDiffFiberwiseLinear.locality_aux₂ (n : WithTop ℕ∞) (e : OpenPartialHomeomorph (B × F) (B × F)) (U : Set B) (hU : e.source = U ×ˢ univ) (h : ∀ x ∈ U, ∃ (φ : B → F ≃L[𝕜] F) (u : Set B) (hu : IsOpen u) (_hUu : u ⊆ U) (_hux : x ∈ u) (hφ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => (φ x : F →L[𝕜] F)) u) (h2φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => ((φ x).symm : F →L[𝕜] F)) u), (e.restr (u ×ˢ univ)).EqOnSource (FiberwiseLinear.openPartialHomeomorph φ hu hφ.continuousOn h2φ.continuousOn)) : ∃ (Φ : B → F ≃L[𝕜] F) (U : Set B) (hU₀ : IsOpen U) (hΦ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => (Φ x : F →L[𝕜] F)) U) (h2Φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => ((Φ x).symm : F →L[𝕜] F)) U), e.EqOnSource (FiberwiseLinear.openPartialHomeomorph Φ hU₀ hΦ.continuousOn h2Φ.continuousOn) := by classical rw [SetCoe.forall'] at h choose! φ u hu hUu hux hφ h2φ heφ using h have heuφ : ∀ x : U, EqOn e (fun q => (q.1, φ x q.1 q.2)) (u x ×ˢ univ) := fun x p hp ↦ by refine (heφ x).2 ?_ rw [(heφ x).1] exact hp have huφ : ∀ (x x' : U) (y : B), y ∈ u x → y ∈ u x' → φ x y = φ x' y := fun p p' y hyp hyp' ↦ by ext v have h1 : e (y, v) = (y, φ p y v) := heuφ _ ⟨(id hyp : (y, v).fst ∈ u p), trivial⟩ have h2 : e (y, v) = (y, φ p' y v) := heuφ _ ⟨(id hyp' : (y, v).fst ∈ u p'), trivial⟩ exact congr_arg Prod.snd (h1.symm.trans h2) have hUu' : U = ⋃ i, u i := by ext x rw [mem_iUnion] refine ⟨fun h => ⟨⟨x, h⟩, hux _⟩, ?_⟩ rintro ⟨x, hx⟩ exact hUu x hx have hU' : IsOpen U := by rw [hUu'] apply isOpen_iUnion hu let Φ₀ : U → F ≃L[𝕜] F := iUnionLift u (fun x => φ x ∘ (↑)) huφ U hUu'.le let Φ : B → F ≃L[𝕜] F := fun y => if hy : y ∈ U then Φ₀ ⟨y, hy⟩ else ContinuousLinearEquiv.refl 𝕜 F have hΦ : ∀ (y) (hy : y ∈ U), Φ y = Φ₀ ⟨y, hy⟩ := fun y hy => dif_pos hy have hΦφ : ∀ x : U, ∀ y ∈ u x, Φ y = φ x y := by intro x y hyu refine (hΦ y (hUu x hyu)).trans ?_ exact iUnionLift_mk ⟨y, hyu⟩ _ have hΦ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun y => (Φ y : F →L[𝕜] F)) U := by apply contMDiffOn_of_locally_contMDiffOn intro x hx refine ⟨u ⟨x, hx⟩, hu ⟨x, hx⟩, hux _, ?_⟩ refine (ContMDiffOn.congr (hφ ⟨x, hx⟩) ?_).mono inter_subset_right intro y hy rw [hΦφ ⟨x, hx⟩ y hy] have h2Φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun y => ((Φ y).symm : F →L[𝕜] F)) U := by apply contMDiffOn_of_locally_contMDiffOn intro x hx refine ⟨u ⟨x, hx⟩, hu ⟨x, hx⟩, hux _, ?_⟩ refine (ContMDiffOn.congr (h2φ ⟨x, hx⟩) ?_).mono inter_subset_right intro y hy rw [hΦφ ⟨x, hx⟩ y hy] refine ⟨Φ, U, hU', hΦ, h2Φ, hU, fun p hp => ?_⟩ rw [hU] at hp rw [heuφ ⟨p.fst, hp.1⟩ ⟨hux _, hp.2⟩] congrm (_, ?_) rw [hΦφ] apply hux -- Having this private lemma speeds up `simp` calls below a lot. -- TODO: understand why and fix the underlying issue (relatedly, the `simp` calls -- in `contMDiffFiberwiseLinear` are quite slow, even with this change) private theorem mem_aux {e : OpenPartialHomeomorph (B × F) (B × F)} {n : WithTop ℕ∞} : (e ∈ ⋃ (φ : B → F ≃L[𝕜] F) (U : Set B) (hU : IsOpen U) (hφ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => (φ x).symm : B → F →L[𝕜] F) U), {e | e.EqOnSource (FiberwiseLinear.openPartialHomeomorph φ hU hφ.continuousOn h2φ.continuousOn)}) ↔ ∃ (φ : B → F ≃L[𝕜] F) (U : Set B) (hU : IsOpen U) (hφ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => (φ x).symm : B → F →L[𝕜] F) U), e.EqOnSource (FiberwiseLinear.openPartialHomeomorph φ hU hφ.continuousOn h2φ.continuousOn) := by simp only [mem_iUnion, mem_setOf_eq] variable (F B IB) /-- For `B` a manifold and `F` a normed space, the groupoid on `B × F` consisting of local homeomorphisms which are bi-`C^n` and fiberwise linear, and induce the identity on `B`. When a (topological) vector bundle is `C^n`, then the composition of charts associated to the vector bundle belong to this groupoid. -/ def contMDiffFiberwiseLinear (n : WithTop ℕ∞) : StructureGroupoid (B × F) where members := ⋃ (φ : B → F ≃L[𝕜] F) (U : Set B) (hU : IsOpen U) (hφ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => (φ x).symm : B → F →L[𝕜] F) U), {e | e.EqOnSource (FiberwiseLinear.openPartialHomeomorph φ hU hφ.continuousOn h2φ.continuousOn)} trans' := by simp only [mem_aux] rintro e e' ⟨φ, U, hU, hφ, h2φ, heφ⟩ ⟨φ', U', hU', hφ', h2φ', heφ'⟩ refine ⟨fun b => (φ b).trans (φ' b), _, hU.inter hU', ?_, ?_, Setoid.trans (OpenPartialHomeomorph.EqOnSource.trans' heφ heφ') ⟨?_, ?_⟩⟩ · change ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x : B => (φ' x).toContinuousLinearMap ∘L (φ x).toContinuousLinearMap) (U ∩ U') exact (hφ'.mono inter_subset_right).clm_comp (hφ.mono inter_subset_left) · change ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x : B => (φ x).symm.toContinuousLinearMap ∘L (φ' x).symm.toContinuousLinearMap) (U ∩ U') exact (h2φ.mono inter_subset_left).clm_comp (h2φ'.mono inter_subset_right) · apply FiberwiseLinear.source_trans_openPartialHomeomorph · rintro ⟨b, v⟩ -; apply FiberwiseLinear.trans_openPartialHomeomorph_apply symm' e := by simp only [mem_aux] rintro ⟨φ, U, hU, hφ, h2φ, heφ⟩ refine ⟨fun b => (φ b).symm, U, hU, h2φ, ?_, OpenPartialHomeomorph.EqOnSource.symm' heφ⟩ simp_rw [ContinuousLinearEquiv.symm_symm] exact hφ id_mem' := by simp_rw [mem_aux] refine ⟨fun _ ↦ ContinuousLinearEquiv.refl 𝕜 F, univ, isOpen_univ, contMDiffOn_const, contMDiffOn_const, ⟨?_, fun b _hb ↦ rfl⟩⟩ simp only [FiberwiseLinear.openPartialHomeomorph, OpenPartialHomeomorph.refl_partialEquiv, PartialEquiv.refl_source, univ_prod_univ] locality' := by -- the hard work has been extracted to `locality_aux₁` and `locality_aux₂` simp only [mem_aux] intro e he obtain ⟨U, hU, h⟩ := ContMDiffFiberwiseLinear.locality_aux₁ n e he exact ContMDiffFiberwiseLinear.locality_aux₂ n e U hU h mem_of_eqOnSource' := by simp only [mem_aux] rintro e e' ⟨φ, U, hU, hφ, h2φ, heφ⟩ hee' exact ⟨φ, U, hU, hφ, h2φ, Setoid.trans hee' heφ⟩ @[simp] theorem mem_contMDiffFiberwiseLinear_iff {n : WithTop ℕ∞} (e : OpenPartialHomeomorph (B × F) (B × F)) : e ∈ contMDiffFiberwiseLinear B F IB n ↔ ∃ (φ : B → F ≃L[𝕜] F) (U : Set B) (hU : IsOpen U) (hφ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContMDiffOn IB 𝓘(𝕜, F →L[𝕜] F) n (fun x => (φ x).symm : B → F →L[𝕜] F) U), e.EqOnSource (FiberwiseLinear.openPartialHomeomorph φ hU hφ.continuousOn h2φ.continuousOn) := mem_aux